@privacyresearch/libsignal-protocol-protobuf-ts
v0.0.9
Published
TypeScript encoders and decoders for Signal Protocol protocol buffer messages.
Downloads
5,022
Readme
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.