@bitgo-beta/blake2b-wasm 3.2.1-alpha.60 → 3.2.1-alpha.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/blake2b.js +1 -3
  2. package/index.js +19 -16
  3. package/package.json +2 -2
  4. package/test.js +21 -19
package/blake2b.js CHANGED
@@ -1,8 +1,6 @@
1
1
  module.exports = loadWebAssembly;
2
2
 
3
- // turning off support for WebAssembly,
4
- // chrome 69 has issues with loading webassembly in the main thread if the module size >4k
5
- loadWebAssembly.supported = false;
3
+ loadWebAssembly.supported = true;
6
4
 
7
5
  function loadWebAssembly(opts) {
8
6
  if (!loadWebAssembly.supported) return null;
package/index.js CHANGED
@@ -1,18 +1,20 @@
1
- var assert = require('nanoassert');
2
- var wasm = require('./blake2b')();
1
+ const assert = require('nanoassert');
2
+ const wasm = require('./blake2b')();
3
3
 
4
- var head = 64;
5
- var freeList = [];
4
+ let head = 64;
5
+ const freeList = [];
6
6
 
7
7
  module.exports = Blake2b;
8
- var BYTES_MIN = (module.exports.BYTES_MIN = 16);
9
- var BYTES_MAX = (module.exports.BYTES_MAX = 64);
10
- var BYTES = (module.exports.BYTES = 32);
11
- var KEYBYTES_MIN = (module.exports.KEYBYTES_MIN = 16);
12
- var KEYBYTES_MAX = (module.exports.KEYBYTES_MAX = 64);
13
- var KEYBYTES = (module.exports.KEYBYTES = 32);
14
- var SALTBYTES = (module.exports.SALTBYTES = 16);
15
- var PERSONALBYTES = (module.exports.PERSONALBYTES = 16);
8
+ const BYTES_MIN = (module.exports.BYTES_MIN = 16);
9
+ const BYTES_MAX = (module.exports.BYTES_MAX = 64);
10
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
+ const BYTES = (module.exports.BYTES = 32);
12
+ const KEYBYTES_MIN = (module.exports.KEYBYTES_MIN = 16);
13
+ const KEYBYTES_MAX = (module.exports.KEYBYTES_MAX = 64);
14
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
15
+ const KEYBYTES = (module.exports.KEYBYTES = 32);
16
+ const SALTBYTES = (module.exports.SALTBYTES = 16);
17
+ const PERSONALBYTES = (module.exports.PERSONALBYTES = 16);
16
18
 
17
19
  function Blake2b(digestLength, key, salt, personal, noAssert) {
18
20
  if (!(this instanceof Blake2b)) return new Blake2b(digestLength, key, salt, personal, noAssert);
@@ -94,7 +96,7 @@ Blake2b.prototype.digest = function (enc) {
94
96
  }
95
97
 
96
98
  assert(enc instanceof Uint8Array && enc.length >= this.digestLength, 'input must be Uint8Array or Buffer');
97
- for (var i = 0; i < this.digestLength; i++) {
99
+ for (let i = 0; i < this.digestLength; i++) {
98
100
  enc[i] = wasm.memory[this.pointer + 128 + i];
99
101
  }
100
102
 
@@ -112,7 +114,7 @@ Blake2b.ready = function (cb) {
112
114
  if (!wasm) return cb(new Error('WebAssembly not supported'));
113
115
 
114
116
  // backwards compat, can be removed in a new major
115
- var p = new Promise(function (reject, resolve) {
117
+ const p = new Promise(function (reject, resolve) {
116
118
  wasm.onload(function (err) {
117
119
  if (err) resolve();
118
120
  else reject();
@@ -125,11 +127,12 @@ Blake2b.ready = function (cb) {
125
127
 
126
128
  Blake2b.prototype.ready = Blake2b.ready;
127
129
 
130
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
128
131
  function noop() {}
129
132
 
130
133
  function hexSlice(buf, start, len) {
131
- var str = '';
132
- for (var i = 0; i < len; i++) str += toHex(buf[start + i]);
134
+ let str = '';
135
+ for (let i = 0; i < len; i++) str += toHex(buf[start + i]);
133
136
  return str;
134
137
  }
135
138
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bitgo-beta/blake2b-wasm",
3
- "version": "3.2.1-alpha.60",
3
+ "version": "3.2.1-alpha.61",
4
4
  "description": "Blake2b implemented in WASM",
5
5
  "main": "index.js",
6
6
  "dependencies": {
@@ -30,5 +30,5 @@
30
30
  "url": "https://github.com/mafintosh/blake2b-wasm/issues"
31
31
  },
32
32
  "homepage": "https://github.com/mafintosh/blake2b-wasm",
33
- "gitHead": "79f27a85c6c9403a1d5687873f5f55b57ff000a3"
33
+ "gitHead": "13c391c7ae11a4139f0cdf528f6bc6a19f110fd9"
34
34
  }
package/test.js CHANGED
@@ -1,17 +1,15 @@
1
- var tape = require('tape');
2
- var blake2b = require('./');
3
- var vectors = require('blake2b/test-vectors.json');
1
+ const tape = require('tape');
2
+ const blake2b = require('./');
3
+ const vectors = require('../blake2b/test-vectors.json');
4
4
 
5
- var readyCalled = false;
5
+ let readyCalled = false;
6
6
  process.on('exit', function () {
7
7
  if (!readyCalled) throw new Error('ready not called');
8
8
  });
9
9
 
10
- blake2b.ready(function () {
11
- readyCalled = true;
12
-
10
+ function test(b2b) {
13
11
  tape('hello world', function (t) {
14
- var hash = blake2b()
12
+ const hash = blake2b()
15
13
  .update(Buffer.from('hello'))
16
14
  .update(Buffer.from(' '))
17
15
  .update(Buffer.from('world'))
@@ -22,7 +20,7 @@ blake2b.ready(function () {
22
20
  });
23
21
 
24
22
  tape('hello world', function (t) {
25
- var hash = blake2b(64)
23
+ const hash = blake2b(64)
26
24
  .update(Buffer.from('hello'))
27
25
  .update(Buffer.from(' '))
28
26
  .update(Buffer.from('world'))
@@ -36,14 +34,14 @@ blake2b.ready(function () {
36
34
  });
37
35
 
38
36
  tape('both at the same time', function (t) {
39
- var a = blake2b();
40
- var b = blake2b(64);
37
+ const a = blake2b();
38
+ const b = blake2b(64);
41
39
 
42
- var hash = a.update(Buffer.from('hello')).update(Buffer.from(' ')).update(Buffer.from('world')).digest('hex');
40
+ let hash = a.update(Buffer.from('hello')).update(Buffer.from(' ')).update(Buffer.from('world')).digest('hex');
43
41
 
44
42
  t.same(hash, '256c83b297114d201b30179f3f0ef0cace9783622da5974326b436178aeef610');
45
43
 
46
- var hash = b.update(Buffer.from('hello')).update(Buffer.from(' ')).update(Buffer.from('world')).digest('hex');
44
+ hash = b.update(Buffer.from('hello')).update(Buffer.from(' ')).update(Buffer.from('world')).digest('hex');
47
45
 
48
46
  t.same(
49
47
  hash,
@@ -54,11 +52,11 @@ blake2b.ready(function () {
54
52
 
55
53
  vectors.forEach(function (vector, i) {
56
54
  tape('test-vectors.json #' + i, function (t) {
57
- var key = vector.key && Buffer.from(vector.key, 'hex');
58
- var salt = vector.salt && Buffer.from(vector.salt, 'hex');
59
- var personal = vector.personal && Buffer.from(vector.personal, 'hex');
55
+ const key = vector.key && Buffer.from(vector.key, 'hex');
56
+ const salt = vector.salt && Buffer.from(vector.salt, 'hex');
57
+ const personal = vector.personal && Buffer.from(vector.personal, 'hex');
60
58
 
61
- var hash = blake2b(vector.outlen, key, salt, personal, true)
59
+ const hash = blake2b(vector.outlen, key, salt, personal, true)
62
60
  .update(Buffer.from(vector.input, 'hex'))
63
61
  .digest('hex');
64
62
 
@@ -66,12 +64,16 @@ blake2b.ready(function () {
66
64
  t.end();
67
65
  });
68
66
  });
69
- });
67
+ }
70
68
 
71
69
  tape('.ready()', function (t) {
72
- var invokeCount = 0;
70
+ let invokeCount = 0;
73
71
  blake2b
74
72
  .ready()
73
+ .then(() => {
74
+ readyCalled = true;
75
+ })
76
+ .then(test)
75
77
  .then(function () {
76
78
  invokeCount++;
77
79
  throw new Error();