TypeScript encoders and decoders for Signal Protocol protocol buffer messages.
npm install @privacyresearch/libsignal-protocol-protobuf-tsTypeScript encoders and decoders for Signal Protocol protocol buffer messages.
To install just use your favorite package manager:
```
yarn add @privacyresearch/libsignal-protocol-protobuf-ts
Then you can import the objects as follows:
`ts`
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:
`ts`
const msg = WhisperMessage.fromJSON({})
Once it is created, set fields and call encode to create a protocol buffer message:
`ts`
// 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:
`ts
// messsageProto is a Uint8Array
const message = WhisperMessage.decode(messageProto)
// Now you can access the fields
const { counter, previousCounter, ephemeralKey, ciphertext } = message
`
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.