Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static async validateMnemonicWithAccount(accountStore: string, profile: Profile, mne: Mnemonic): Promise {
try {
await panthalassaStop();
// eslint-disable-next-line no-empty
} catch (e) {
// We ignore exception, since we just need stop it in case it was started earlier.
}
const config = JSON.stringify({
encrypted_key_manager: accountStore,
enable_debugging: false,
eth_ws_endpoint: 'wss://mainnet.infura.io/_ws',
private_chat_endpoint: Config.CHAT_WSS_ENDPOINT,
private_chat_bearer_token: Config.CHAT_TOKEN,
});
try {
await panthalassaStartFromMnemonic(config, compressMnemonic(mne));
} catch (e) {
console.log(`[TEST] Panthalassa start failed: ${e.message}`);
return false;
}
return true;
}
try {
await panthalassaStop();
// eslint-disable-next-line no-empty
} catch (e) {
// We ignore exception, since we just need stop it in case it was started earlier.
}
const signedProfile = await AccountsService.signProfileStandalone(profile, accountStore, password).catch(() => {
throw new InvalidPasswordError();
});
const config = JSON.stringify({
encrypted_key_manager: accountStore,
signed_profile: signedProfile,
enable_debugging: false,
eth_ws_endpoint: networkType === 'main' ? 'wss://mainnet.infura.io/ws' : 'wss://rinkeby.infura.io/ws',
private_chat_endpoint: Config.CHAT_WSS_ENDPOINT,
private_chat_bearer_token: Config.CHAT_TOKEN,
});
try {
await panthalassaStart(config, password);
} catch (e) {
console.log(`[TEST] Panthalassa start failed: ${e.message}`);
return false;
}
try {
await ChatService.uploadProfile(signedProfile);
} catch (e) {
console.log(`[TEST] Profile upload fail: ${e.message}`);
}
return true;
static async uploadProfile(profile: string): Promise {
console.log(`[TEST] Profile upload: ${profile}`);
const URL = `${Config.CHAT_ENDPOINT}/profile`;
const result = await fetch(URL, {
body: profile,
headers: {
'content-type': 'application/json',
bearer: Config.CHAT_TOKEN,
},
method: 'PUT',
});
console.log(`[TEST] Profile upload result: ${JSON.stringify(result)}`);
if (result.ok !== true) {
return Promise.reject(new Error('Failed to upload profile'));
}
return Promise.resolve();
}
static async getProfile(publicKey: string): Promise {
const URL = `${Config.CHAT_ENDPOINT}/profile`;
return fetch(URL, {
headers: {
'content-type': 'application/json',
bearer: Config.CHAT_TOKEN,
'Cache-Control': 'no-cache, no-store, must-revalidate',
Pragma: 'no-cache',
Expires: 0,
Identity: publicKey,
},
method: 'GET',
})
.then(response => response.text())
.then(response => Profile.decode(Buffer.from(response, 'base64')))
.then(response => Profile.toObject(response, { bytes: String }));
}