How to use the @wireapp/protocol-messaging.GenericMessage.encode function in @wireapp/protocol-messaging

To help you get started, we’ve selected a few @wireapp/protocol-messaging examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wireapp / wire-webapp / test / unit_tests / cryptography / CryptographyMapperSpec.js View on Github external
it('can map a text wrapped inside an external message', async () => {
      const plaintext = 'Test';
      const text = new Text({content: plaintext});
      const generic_message = new GenericMessage({
        [GENERIC_MESSAGE_TYPE.TEXT]: text,
        messageId: createRandomUuid(),
      });

      const encryptedAsset = await encryptAesAsset(GenericMessage.encode(generic_message).finish());
      const keyBytes = new Uint8Array(encryptedAsset.keyBytes);
      const sha256 = new Uint8Array(encryptedAsset.sha256);
      event.data.data = await arrayToBase64(encryptedAsset.cipherText);

      const external_message = new GenericMessage({
        external: new External({otrKey: keyBytes, sha256}),
        messageId: createRandomUuid(),
      });
      const event_json = await mapper.mapGenericMessage(external_message, event);

      expect(event_json.data.content).toBe(plaintext);
      expect(event_json.type).toBe(ClientEvent.CONVERSATION.MESSAGE_ADD);
      expect(event_json.id).toBe(generic_message.messageId);
    });
github wireapp / wire-webapp / test / unit_tests / cryptography / CryptographyMapperSpec.js View on Github external
it('can map a ping wrapped inside an external message', async () => {
      let external_message = undefined;

      const genericMessage = new GenericMessage({
        knock: new Knock({hotKnock: false}),
        messageId: createRandomUuid(),
      });

      const encryptedAsset = await encryptAesAsset(GenericMessage.encode(genericMessage).finish());
      const keyBytes = new Uint8Array(encryptedAsset.keyBytes);
      const sha256 = new Uint8Array(encryptedAsset.sha256);
      event.data.data = await arrayToBase64(encryptedAsset.cipherText);

      external_message = new GenericMessage({
        external: new External({otrKey: keyBytes, sha256}),
        messageId: createRandomUuid(),
      });
      const event_json = await mapper.mapGenericMessage(external_message, event);

      expect(isObject(event_json)).toBeTruthy();
      expect(event_json.type).toBe(ClientEvent.CONVERSATION.KNOCK);
      expect(event_json.conversation).toBe(event.conversation);
      expect(event_json.from).toBe(event.from);
      expect(event_json.time).toBe(event.time);
      expect(event_json.id).toBe(genericMessage.messageId);
github wireapp / wire-webapp / test / unit_tests / event / EventRepositorySpec.js View on Github external
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(),
    preKeyBundle.serialise(),
  );

  return arrayToBase64(cipherText);
}
github wireapp / wire-webapp / test / unit_tests / cryptography / CryptographyRepositorySpec.js View on Github external
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(),
      );
      const encodedCipherText = await arrayToBase64(cipherText);

      const mockedEvent = {
        data: {
          text: encodedCipherText,
        },
        from: createRandomUuid(),
        id: createRandomUuid(),
      };

      const decrypted = await TestFactory.cryptography_repository.handleEncryptedEvent(mockedEvent);

      expect(decrypted.data.content).toBe(plainText);
github wireapp / wire-webapp / src / script / cryptography / CryptographyRepository.js View on Github external
async _encryptPayloadForSession(sessionId, genericMessage, preKeyBundle) {
    try {
      const messageArray = GenericMessage.encode(genericMessage).finish();
      const cipherText = await this.cryptobox.encrypt(sessionId, messageArray, preKeyBundle);
      const cipherTextArray = await arrayToBase64(cipherText);
      return {cipherText: cipherTextArray, sessionId};
    } catch (error) {
      if (error instanceof StoreEngineError.RecordNotFoundError) {
        this.logger.log(`Session '${sessionId}' needs to get initialized...`);
        return {sessionId};
      }

      const message = `Failed encrypting '${genericMessage.content}' for session '${sessionId}': ${error.message}`;
      this.logger.warn(message, error);
      return {cipherText: CryptographyRepository.REMOTE_ENCRYPTION_FAILURE, sessionId};
    }
  }
github wireapp / wire-web-packages / packages / core / src / main / broadcast / BroadcastService.ts View on Github external
public async broadcastGenericMessage(teamId: string, genericMessage: GenericMessage): Promise {
    const plainTextArray = GenericMessage.encode(genericMessage).finish();
    const preKeyBundle = await this.getPreKeyBundle(teamId);
    const recipients = await this.cryptographyService.encrypt(plainTextArray, preKeyBundle);
    return this.sendOTRBroadcastMessage(this.apiClient.validatedClientId, recipients, plainTextArray);
  }