Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function createEncodedCiphertext(
preKey,
text = 'Hello, World!',
receivingIdentity = TestFactory.cryptography_repository.cryptobox.identity,
) {
const bobEngine = new MemoryEngine();
await bobEngine.init('bob');
const sender = new Cryptobox(bobEngine, 1);
await sender.create();
const genericMessage = new GenericMessage({
[GENERIC_MESSAGE_TYPE.TEXT]: new Text({content: text}),
messageId: createRandomUuid(),
});
const sessionId = `from-${sender.identity.public_key.fingerprint()}-to-${preKey.key_pair.public_key.fingerprint()}`;
const preKeyBundle = Proteus.keys.PreKeyBundle.new(receivingIdentity.public_key, preKey);
const cipherText = await sender.encrypt(
sessionId,
GenericMessage.encode(genericMessage).finish(),
it('detects duplicated messages', async () => {
const database = TestFactory.storage_service.db;
const preKeys = await TestFactory.cryptography_repository.createCryptobox(database);
const alice = TestFactory.cryptography_repository.cryptobox.identity;
expect(alice).toBeDefined();
const aliceBundle = Proteus.keys.PreKeyBundle.new(alice.public_key, preKeys[0]);
const bobEngine = new MemoryEngine();
await bobEngine.init('bob');
const bob = new Cryptobox(bobEngine, 1);
await bob.create();
const plainText = 'Hello, Alice!';
const genericMessage = new GenericMessage({
[GENERIC_MESSAGE_TYPE.TEXT]: new Text({content: plainText}),
messageId: createRandomUuid(),
});
const cipherText = await bob.encrypt(
'session-with-alice',
GenericMessage.encode(genericMessage).finish(),
aliceBundle.serialise(),
case 'staging':
build.url = 'https://wire-webapp-staging.zinfra.io/login/?env=prod#login';
break;
default:
build.url = 'https://app.wire.com/';
}
content.message =
`**Travis build '${build.number}' deployed on '${commit.branch}' environment.** ᕦ( ̄ ³ ̄)ᕤ` +
`\r\n- Link: ${build.url}` +
`\r\n- Last commit from: ${commit.author}` +
`\r\n- Last commit message: ${commit.message}`;
let account = undefined;
const engine = new MemoryEngine();
engine
.init('')
.then(() => {
const client = new APIClient({
store: engine,
urls: APIClient.BACKEND.PRODUCTION,
});
account = new Account(client);
return account.listen(login);
})
.then(() => account.service.conversation.sendTextMessage(content.conversationId, content.message))
.then(() => process.exit(0))
.catch(error => {
console.error(error.stack);
return process.exit(1);
this.storeEngineProvider = async (storeName: string) => {
const engine = new MemoryEngine();
await engine.init(storeName);
return engine;
};
}
async sendMessage(): Promise {
let {conversationIds} = this.messageData;
const engine = new MemoryEngine();
await engine.init('changelog-bot');
const backendUrls = this.loginData.backend === 'staging' ? APIClient.BACKEND.STAGING : APIClient.BACKEND.PRODUCTION;
const client = new APIClient({urls: backendUrls});
const account = new Account(client, () => Promise.resolve(engine));
try {
await account.login(this.loginData);
} catch (error) {
throw new Error(JSON.stringify(error));
}
if (!conversationIds) {
const allConversations = await client.conversation.api.getAllConversations();
const groupConversations = allConversations.filter(conversation => conversation.type === 0);
async sendMessage(): Promise {
let {conversationIds} = this.messageData;
const engine = new MemoryEngine();
await engine.init('changelog-bot');
const backendUrls = this.loginData.backend === 'staging' ? APIClient.BACKEND.STAGING : APIClient.BACKEND.PRODUCTION;
const client = new APIClient({store: engine, urls: backendUrls});
const account = new Account(client);
try {
await account.login(this.loginData);
} catch (error) {
throw new Error(JSON.stringify(error));
}
if (!conversationIds) {
const allConversations = await client.conversation.api.getAllConversations();
const groupConversations = allConversations.filter(conversation => conversation.type === 0);
async function createCryptobox(storeName, amountOfPreKeys = 1) {
const engine = new MemoryEngine();
await engine.init(storeName);
return new Cryptobox(engine, amountOfPreKeys);
}
(async () => {
const login = {
clientType: ClientType.TEMPORARY,
email: process.env.WIRE_STATUS_BOT_EMAIL,
password: process.env.WIRE_STATUS_BOT_PASSWORD,
};
try {
const engine = new MemoryEngine();
await engine.init('');
const apiClient = new APIClient({store: engine, urls: APIClient.BACKEND.PRODUCTION});
const account = new Account(apiClient);
await account.login(login);
const text = message || `I am posting from ${name} v${version} (Build #${process.env.TRAVIS_BUILD_NUMBER}). 🌞`;
const payload = account.service.conversation.createText(text).build();
conversationIds.forEach(async conversationId => await account.service.conversation.send(conversationId, payload));
} catch (error) {
logger.error('Error:', error.stack);
}
})();
(async () => {
try {
const MIN_AMOUNT_PREKEYS = 5;
const engine = new MemoryEngine();
await engine.init('cache');
const store = new cryptobox.store.CryptoboxCRUDStore(engine);
const box = new cryptobox.Cryptobox(store, MIN_AMOUNT_PREKEYS);
await box.create();
const fingerprint = box.identity.public_key.fingerprint();
logger.log(`Public Fingerprint: ${fingerprint}`);
process.exit(0);
} catch (error) {
logger.log(`Self test broken: ${error.message} (${error.stack})`);
process.exit(1);
}
})();