Skip to content

Commit 466d2d6

Browse files
committed
Start using some ES2015 features
* Replace `var` with `let` and `const` * Use arrow functions instead of `.bind` * Use classes where appropriate
1 parent 97a6c5f commit 466d2d6

36 files changed

+1501
-1471
lines changed

.eslintrc.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = {
44
"es2021": true
55
},
66
"globals": {
7+
"module": true,
78
"Internal": true,
89
"Module": true,
910
"chai": true,
@@ -12,6 +13,7 @@ module.exports = {
1213
"it": true,
1314
"libsignal": true,
1415
"parseInt": true,
16+
"require": true,
1517
"util": true,
1618
},
1719
"extends": "eslint:recommended",
@@ -21,5 +23,6 @@ module.exports = {
2123
},
2224
"rules": {
2325
"no-proto": "off",
24-
}
26+
"no-var": "warn",
27+
}
2528
}

Gruntfile.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var child_process = require('child_process');
2-
var util = require('util');
1+
const child_process = require('child_process');
2+
const util = require('util');
33

44
module.exports = function(grunt) {
55
'use strict';
@@ -31,9 +31,9 @@ module.exports = function(grunt) {
3131
banner: 'var Internal = Internal || {};\n\nInternal.protoText = function() {\n\tvar protoText = {};\n\n',
3232
footer: '\n\treturn protoText;\n}();',
3333
process: function(src, file) {
34-
var res = "\tprotoText['" + file + "'] = \n";
35-
var lines = src.match(/[^\r\n]+/g);
36-
for (var i in lines) {
34+
let res = "\tprotoText['" + file + "'] = \n";
35+
const lines = src.match(/[^\r\n]+/g);
36+
for (const i in lines) {
3737
res += "\t\t'" + lines[i] + "\\n' +\n";
3838
}
3939
return res + "''\t;\n";
@@ -144,10 +144,10 @@ module.exports = function(grunt) {
144144
});
145145

146146
grunt.registerMultiTask('compile', 'Compile the C libraries with emscripten.', function() {
147-
var callback = this.async();
148-
var outfile = 'build/' + this.target + '.js';
147+
const callback = this.async();
148+
const outfile = 'build/' + this.target + '.js';
149149

150-
var exported_functions = this.data.methods.map(function(name) {
150+
const exported_functions = this.data.methods.map(function(name) {
151151
return "'_" + name + "'";
152152
});
153153
const flags = [
@@ -160,11 +160,11 @@ module.exports = function(grunt) {
160160
const command = [].concat('emcc', this.data.src_files, flags).join(' ');
161161
grunt.log.writeln('Compiling via emscripten to ' + outfile);
162162

163-
var exitCode = 0;
163+
const exitCode = 0;
164164
grunt.verbose.subhead(command);
165165
grunt.verbose.writeln(util.format('Expecting exit code %d', exitCode));
166166

167-
var child = child_process.exec(command);
167+
const child = child_process.exec(command);
168168
child.stdout.on('data', function (d) { grunt.log.write(d); });
169169
child.stderr.on('data', function (d) { grunt.log.error(d); });
170170
child.on('exit', function(code) {

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ node_modules: package.json package-lock.json
1111

1212
.PHONY: eslint
1313
eslint: node_modules
14-
$(ESLINT) src/**/*.js test/**/*.js
14+
$(ESLINT) src/**/*.js test/**/*.js Gruntfile.js
1515

1616

1717
.PHONY: check

build/curve25519_concat.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,7 +1734,7 @@ var Internal = Internal || {};
17341734

17351735
// Insert some bytes into the emscripten memory and return a pointer
17361736
function _allocate(bytes) {
1737-
var address = Module._malloc(bytes.length);
1737+
const address = Module._malloc(bytes.length);
17381738
Module.HEAPU8.set(bytes, address);
17391739

17401740
return address;
@@ -1744,34 +1744,34 @@ var Internal = Internal || {};
17441744
array.set(Module.HEAPU8.subarray(address, address + length));
17451745
}
17461746

1747-
var basepoint = new Uint8Array(32);
1747+
const basepoint = new Uint8Array(32);
17481748
basepoint[0] = 9;
17491749

17501750
Internal.curve25519 = {
17511751
keyPair: function(privKey) {
1752-
var priv = new Uint8Array(privKey);
1752+
const priv = new Uint8Array(privKey);
17531753
priv[0] &= 248;
17541754
priv[31] &= 127;
17551755
priv[31] |= 64;
17561756

17571757
// Where to store the result
1758-
var publicKey_ptr = Module._malloc(32);
1758+
const publicKey_ptr = Module._malloc(32);
17591759

17601760
// Get a pointer to the private key
1761-
var privateKey_ptr = _allocate(priv);
1761+
const privateKey_ptr = _allocate(priv);
17621762

17631763
// The basepoint for generating public keys
1764-
var basepoint_ptr = _allocate(basepoint);
1764+
const basepoint_ptr = _allocate(basepoint);
17651765

17661766
// The return value is just 0, the operation is done in place
1767-
var err = Module._curve25519_donna(publicKey_ptr,
1767+
const err = Module._curve25519_donna(publicKey_ptr,
17681768
privateKey_ptr,
17691769
basepoint_ptr);
17701770
if (err) {
17711771
console.log(err);
17721772
}
17731773

1774-
var res = new Uint8Array(32);
1774+
const res = new Uint8Array(32);
17751775
_readBytes(publicKey_ptr, 32, res);
17761776

17771777
Module._free(publicKey_ptr);
@@ -1783,24 +1783,24 @@ var Internal = Internal || {};
17831783

17841784
sharedSecret: function(pubKey, privKey) {
17851785
// Where to store the result
1786-
var sharedKey_ptr = Module._malloc(32);
1786+
const sharedKey_ptr = Module._malloc(32);
17871787

17881788
// Get a pointer to our private key
1789-
var privateKey_ptr = _allocate(new Uint8Array(privKey));
1789+
const privateKey_ptr = _allocate(new Uint8Array(privKey));
17901790

17911791
// Get a pointer to their public key, the basepoint when you're
17921792
// generating a shared secret
1793-
var basepoint_ptr = _allocate(new Uint8Array(pubKey));
1793+
const basepoint_ptr = _allocate(new Uint8Array(pubKey));
17941794

17951795
// Return value is 0 here too of course
1796-
var err = Module._curve25519_donna(sharedKey_ptr,
1796+
const err = Module._curve25519_donna(sharedKey_ptr,
17971797
privateKey_ptr,
17981798
basepoint_ptr);
17991799
if (err) {
18001800
console.log(err);
18011801
}
18021802

1803-
var res = new Uint8Array(32);
1803+
const res = new Uint8Array(32);
18041804
_readBytes(sharedKey_ptr, 32, res);
18051805

18061806
Module._free(sharedKey_ptr);
@@ -1812,23 +1812,23 @@ var Internal = Internal || {};
18121812

18131813
sign: function(privKey, message) {
18141814
// Where to store the result
1815-
var signature_ptr = Module._malloc(64);
1815+
const signature_ptr = Module._malloc(64);
18161816

18171817
// Get a pointer to our private key
1818-
var privateKey_ptr = _allocate(new Uint8Array(privKey));
1818+
const privateKey_ptr = _allocate(new Uint8Array(privKey));
18191819

18201820
// Get a pointer to the message
1821-
var message_ptr = _allocate(new Uint8Array(message));
1821+
const message_ptr = _allocate(new Uint8Array(message));
18221822

1823-
var err = Module._xed25519_sign(signature_ptr,
1823+
const err = Module._xed25519_sign(signature_ptr,
18241824
privateKey_ptr,
18251825
message_ptr,
18261826
message.byteLength);
18271827
if (err) {
18281828
console.log(err);
18291829
}
18301830

1831-
var res = new Uint8Array(64);
1831+
const res = new Uint8Array(64);
18321832
_readBytes(signature_ptr, 64, res);
18331833

18341834
Module._free(signature_ptr);
@@ -1840,15 +1840,15 @@ var Internal = Internal || {};
18401840

18411841
verify: function(pubKey, message, sig) {
18421842
// Get a pointer to their public key
1843-
var publicKey_ptr = _allocate(new Uint8Array(pubKey));
1843+
const publicKey_ptr = _allocate(new Uint8Array(pubKey));
18441844

18451845
// Get a pointer to the signature
1846-
var signature_ptr = _allocate(new Uint8Array(sig));
1846+
const signature_ptr = _allocate(new Uint8Array(sig));
18471847

18481848
// Get a pointer to the message
1849-
var message_ptr = _allocate(new Uint8Array(message));
1849+
const message_ptr = _allocate(new Uint8Array(message));
18501850

1851-
var res = Module._curve25519_verify(signature_ptr,
1851+
const res = Module._curve25519_verify(signature_ptr,
18521852
publicKey_ptr,
18531853
message_ptr,
18541854
message.byteLength);

build/protobufs_concat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Internal.protobuf = (function() {
4444
return dcodeIO.ProtoBuf.loadProto(Internal.protoText['protos/' + filename]).build('textsecure');
4545
}
4646

47-
var protocolMessages = loadProtoBufs('WhisperTextProtocol.proto');
47+
const protocolMessages = loadProtoBufs('WhisperTextProtocol.proto');
4848

4949
return {
5050
WhisperMessage : protocolMessages.WhisperMessage,

dist/libsignal-protocol-worker.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,7 +1737,7 @@ var Internal = Internal || {};
17371737

17381738
// Insert some bytes into the emscripten memory and return a pointer
17391739
function _allocate(bytes) {
1740-
var address = Module._malloc(bytes.length);
1740+
const address = Module._malloc(bytes.length);
17411741
Module.HEAPU8.set(bytes, address);
17421742

17431743
return address;
@@ -1747,34 +1747,34 @@ var Internal = Internal || {};
17471747
array.set(Module.HEAPU8.subarray(address, address + length));
17481748
}
17491749

1750-
var basepoint = new Uint8Array(32);
1750+
const basepoint = new Uint8Array(32);
17511751
basepoint[0] = 9;
17521752

17531753
Internal.curve25519 = {
17541754
keyPair: function(privKey) {
1755-
var priv = new Uint8Array(privKey);
1755+
const priv = new Uint8Array(privKey);
17561756
priv[0] &= 248;
17571757
priv[31] &= 127;
17581758
priv[31] |= 64;
17591759

17601760
// Where to store the result
1761-
var publicKey_ptr = Module._malloc(32);
1761+
const publicKey_ptr = Module._malloc(32);
17621762

17631763
// Get a pointer to the private key
1764-
var privateKey_ptr = _allocate(priv);
1764+
const privateKey_ptr = _allocate(priv);
17651765

17661766
// The basepoint for generating public keys
1767-
var basepoint_ptr = _allocate(basepoint);
1767+
const basepoint_ptr = _allocate(basepoint);
17681768

17691769
// The return value is just 0, the operation is done in place
1770-
var err = Module._curve25519_donna(publicKey_ptr,
1770+
const err = Module._curve25519_donna(publicKey_ptr,
17711771
privateKey_ptr,
17721772
basepoint_ptr);
17731773
if (err) {
17741774
console.log(err);
17751775
}
17761776

1777-
var res = new Uint8Array(32);
1777+
const res = new Uint8Array(32);
17781778
_readBytes(publicKey_ptr, 32, res);
17791779

17801780
Module._free(publicKey_ptr);
@@ -1786,24 +1786,24 @@ var Internal = Internal || {};
17861786

17871787
sharedSecret: function(pubKey, privKey) {
17881788
// Where to store the result
1789-
var sharedKey_ptr = Module._malloc(32);
1789+
const sharedKey_ptr = Module._malloc(32);
17901790

17911791
// Get a pointer to our private key
1792-
var privateKey_ptr = _allocate(new Uint8Array(privKey));
1792+
const privateKey_ptr = _allocate(new Uint8Array(privKey));
17931793

17941794
// Get a pointer to their public key, the basepoint when you're
17951795
// generating a shared secret
1796-
var basepoint_ptr = _allocate(new Uint8Array(pubKey));
1796+
const basepoint_ptr = _allocate(new Uint8Array(pubKey));
17971797

17981798
// Return value is 0 here too of course
1799-
var err = Module._curve25519_donna(sharedKey_ptr,
1799+
const err = Module._curve25519_donna(sharedKey_ptr,
18001800
privateKey_ptr,
18011801
basepoint_ptr);
18021802
if (err) {
18031803
console.log(err);
18041804
}
18051805

1806-
var res = new Uint8Array(32);
1806+
const res = new Uint8Array(32);
18071807
_readBytes(sharedKey_ptr, 32, res);
18081808

18091809
Module._free(sharedKey_ptr);
@@ -1815,23 +1815,23 @@ var Internal = Internal || {};
18151815

18161816
sign: function(privKey, message) {
18171817
// Where to store the result
1818-
var signature_ptr = Module._malloc(64);
1818+
const signature_ptr = Module._malloc(64);
18191819

18201820
// Get a pointer to our private key
1821-
var privateKey_ptr = _allocate(new Uint8Array(privKey));
1821+
const privateKey_ptr = _allocate(new Uint8Array(privKey));
18221822

18231823
// Get a pointer to the message
1824-
var message_ptr = _allocate(new Uint8Array(message));
1824+
const message_ptr = _allocate(new Uint8Array(message));
18251825

1826-
var err = Module._xed25519_sign(signature_ptr,
1826+
const err = Module._xed25519_sign(signature_ptr,
18271827
privateKey_ptr,
18281828
message_ptr,
18291829
message.byteLength);
18301830
if (err) {
18311831
console.log(err);
18321832
}
18331833

1834-
var res = new Uint8Array(64);
1834+
const res = new Uint8Array(64);
18351835
_readBytes(signature_ptr, 64, res);
18361836

18371837
Module._free(signature_ptr);
@@ -1843,15 +1843,15 @@ var Internal = Internal || {};
18431843

18441844
verify: function(pubKey, message, sig) {
18451845
// Get a pointer to their public key
1846-
var publicKey_ptr = _allocate(new Uint8Array(pubKey));
1846+
const publicKey_ptr = _allocate(new Uint8Array(pubKey));
18471847

18481848
// Get a pointer to the signature
1849-
var signature_ptr = _allocate(new Uint8Array(sig));
1849+
const signature_ptr = _allocate(new Uint8Array(sig));
18501850

18511851
// Get a pointer to the message
1852-
var message_ptr = _allocate(new Uint8Array(message));
1852+
const message_ptr = _allocate(new Uint8Array(message));
18531853

1854-
var res = Module._curve25519_verify(signature_ptr,
1854+
const res = Module._curve25519_verify(signature_ptr,
18551855
publicKey_ptr,
18561856
message_ptr,
18571857
message.byteLength);

0 commit comments

Comments
 (0)