Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

Make signal-protocol compatible with JS module system #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"sub" : false,
"supernew" : false,
"validthis" : false,
"browser" : false,
"browser" : true,
"browserify" : false,
"couch" : false,
"devel" : false,
Expand All @@ -67,5 +67,8 @@
"worker" : false,
"wsh" : false,
"yui" : false,
"globals" : {}
"node" : true,
"globals" : {
"Promise" : true
}
}
73 changes: 23 additions & 50 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,35 @@ module.exports = function(grunt) {

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify: {
legacy: {
src: 'src/main_window.js',
dest: 'dist/libsignal.js'
},
test: {
src: 'test/main.js',
dest: 'build/test_main.js'
}
},
concat: {
components: {
src: [
'node_modules/long/dist/long.js',
'node_modules/bytebuffer/dist/ByteBufferAB.js',
'node_modules/protobufjs/dist/protobuf.js'
],
dest: 'build/components_concat.js',
dest: 'build/dcodeIO.js'
},
curve25519: {
src: [
'build/curve25519_compiled.js',
'src/curve25519_wrapper.js',
],
dest: 'build/curve25519_concat.js'
dest: 'build/curve25519_concat.js',
// Append this to the build for browser require compatibility
// via https://github.com/nfroidure/ttf2woff2/blob/master/jssrc/post.js
options: {
footer: "module.exports = Module;\nModule.inspect = function() { return '[Module]'; };"
}
},
protos: {
src: [
Expand Down Expand Up @@ -48,43 +62,6 @@ module.exports = function(grunt) {
dest: 'build/protobufs_concat.js'
},

worker: {
src: [
'build/curve25519_concat.js',
'src/curve25519_worker.js',
],
dest: 'dist/libsignal-protocol-worker.js',
options: {
banner: ';(function(){\nvar Internal = {};\nvar libsignal = {};\n',
footer: '\n})();'
}

},
libsignalprotocol: {
src: [
'build/curve25519_concat.js',
'src/curve25519_worker_manager.js',
'build/components_concat.js',

'src/Curve.js',
'src/crypto.js',
'src/helpers.js',
'src/KeyHelper.js',
'build/protobufs_concat.js',
'src/SessionRecord.js',
'src/SignalProtocolAddress.js',
'src/SessionBuilder.js',
'src/SessionCipher.js',
'src/SessionLock.js',
'src/NumericFingerprint.js'
],
dest: 'dist/libsignal-protocol.js',
options: {
banner: ';(function(){\nvar Internal = {};\nwindow.libsignal = {};\n',
footer: '\n})();'
}

},
test: {
src: [
'node_modules/mocha/mocha.js',
Expand All @@ -93,10 +70,7 @@ module.exports = function(grunt) {
'node_modules/blanket/dist/mocha/blanket_mocha.js',
'test/_test.js'
],
dest: 'test/test.js',
options: {
banner: 'var Internal = {};\nwindow.libsignal = {};\n'
}
dest: 'build/test_lib.js'
}
},
compile: {
Expand Down Expand Up @@ -138,10 +112,10 @@ module.exports = function(grunt) {
files: ['<%= jshint.files %>', '.jshintrc'],
tasks: ['jshint']
},
worker: {
files: ['<%= concat.worker.src %>'],
tasks: ['concat:worker']
},
// worker: {
// files: ['<%= concat.worker.src %>'],
// tasks: ['concat:worker']
// },
libsignalprotocol: {
files: ['<%= concat.libsignalprotocol.src %>'],
tasks: ['concat:libsignalprotocol']
Expand Down Expand Up @@ -224,6 +198,5 @@ module.exports = function(grunt) {
grunt.registerTask('dev', ['connect', 'watch']);
grunt.registerTask('test', ['jshint', 'jscs', 'connect', 'saucelabs-mocha']);
grunt.registerTask('default', ['concat']);
grunt.registerTask('build', ['compile', 'concat']);

grunt.registerTask('build', ['compile', 'concat', 'browserify']);
};
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,23 @@ types/interfaces, which are available in most modern browsers.

## Usage

Include `dist/libsignal-protocol.js` in your webpage.
There are two ways to use this package.

You can require with your front-end bundler of choice (e.g. browserify, webpack):

```js
var libsignal = require('libsignal-protocol')
```

Or, you can include the prebundled `dist/libsignal.js` in your HTML file.

### Install time

At install time, a libsignal client needs to generate its identity keys,
registration id, and prekeys.

```js
var libsignal = require('libsignal-protocol')
var KeyHelper = libsignal.KeyHelper;

var registrationId = KeyHelper.generateRegistrationId();
Expand Down Expand Up @@ -112,7 +121,7 @@ var store = new MySignalProtocolStore();
var address = new libsignal.SignalProtocolAddress(recipientId, deviceId);

// Instantiate a SessionBuilder for a remote recipientId + deviceId tuple.
SessionBuilder sessionBuilder = new libsignal.SessionBuilder(store, address);
var sessionBuilder = new libsignal.SessionBuilder(store, address);

// Process a prekey fetched from the server. Returns a promise that resolves
// once a session is created and saved in the store, or rejects if the
Expand Down Expand Up @@ -179,13 +188,22 @@ sessionCipher.decryptWhisperMessage(ciphertext).then(function(plaintext) {
});
```

## Building
## Contributing

To compile curve25519 from C souce files in `/native`, install
[emscripten](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html).
Theen, build all the assets with

```
grunt compile
grunt build
```

To test, you can serve the project root and navigate to localhost:[port]/test to see the Mocha tests run.
For the full CI experience, you will need an account with [Sauce Labs](https://saucelabs.com).
Get your username and API key, then set the appropriate envirionment variables to run the tests:

```sh
SAUCE_USERNAME="your-sauce-username" SAUCE_ACCESS_KEY="your-sauce-key" grunt test
```

## License
Expand Down
Loading