Coder Social home page Coder Social logo

box-of-code / libsignal-protocol-protobuf-ts Goto Github PK

View Code? Open in Web Editor NEW

This project forked from privacyresearchgroup/libsignal-protocol-protobuf-ts

0.0 0.0 0.0 368 KB

TypeScript wrapped protobufs for Signal messages

License: GNU General Public License v3.0

Shell 1.41% JavaScript 4.38% TypeScript 94.21%

libsignal-protocol-protobuf-ts's Introduction

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.

libsignal-protocol-protobuf-ts's People

Contributors

rolfeschmidt avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.