@privacyresearch/libsignal-protocol-protobuf-ts
TypeScript icon, indicating that this package has built-in type declarations

0.0.9 • Public • Published

Protocol Buffers for Signal Protocol TypeScript Library

TypeScript encoders and decoders for Signal Protocol protocol buffer messages.

Installation

To install just use your favorite package manager:

yarn add @privacyresearch/libsignal-protocol-protobuf-ts

Then you can import the objects as follows:

import { PreKeyWhisperMessage, WhisperMessage } from '@privacyresearch/libsignal-protocol-protobuf-ts'

Once imported, these objects can be used to create, encode, and decode protocol buffer messages. To create an empty message, use the fromJSON method as in this example:

const msg = WhisperMessage.fromJSON({})

Once it is created, set fields and call encode to create a protocol buffer message:

// Here were working with a WhisperMessage
msg.counter = 42
msg.previousCounter = 41
msg.ephemeralKey : Uint8Array = aPublicKey
const ciphertext : Uint8Array = someAESEncryptedArrayBuffer
msg.ciphertext = ciphertext
const encodedMsg = WhisperMessage.encode(msg).finish()

When receiving a protocol buffer message, use decode to turn it into a typed object:

// messsageProto is a Uint8Array
const message = WhisperMessage.decode(messageProto)

// Now you can access the fields
const { counter, previousCounter, ephemeralKey, ciphertext } = message

A note on the "Compatible" types

All of the code in src/generated/protos is generated by ts-proto, but the code in src/push-message-content-compatible.ts is slightly modified by hand. The modifications are there to provide an encoding that is consistent with the messages seen in the libsignal-protocol-javascript test suite. The difference is in the treatment of empty fields. The generated classes include empty fields as empty strings or as the number zero. The "compatible" classes omit them.

Readme

Keywords

none

Package Sidebar

Install

npm i @privacyresearch/libsignal-protocol-protobuf-ts

Weekly Downloads

277

Version

0.0.9

License

GPL-3.0-only

Unpacked Size

86.6 kB

Total Files

15

Last publish

Collaborators

  • maejohns
  • rolfe