@bitgo-beta/blake2b-wasm 3.2.1-alpha.60 → 3.2.1-alpha.62
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.
- package/blake2b.js +1 -3
- package/index.js +19 -16
- package/package.json +2 -2
- package/test.js +21 -19
package/blake2b.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
module.exports = loadWebAssembly;
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
1
|
+
const assert = require('nanoassert');
|
|
2
|
+
const wasm = require('./blake2b')();
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
let head = 64;
|
|
5
|
+
const freeList = [];
|
|
6
6
|
|
|
7
7
|
module.exports = Blake2b;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 (
|
|
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
|
-
|
|
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
|
-
|
|
132
|
-
for (
|
|
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.
|
|
3
|
+
"version": "3.2.1-alpha.62",
|
|
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": "
|
|
33
|
+
"gitHead": "21822984a59a36323b38849239362ddb639f319e"
|
|
34
34
|
}
|
package/test.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const tape = require('tape');
|
|
2
|
+
const blake2b = require('./');
|
|
3
|
+
const vectors = require('../blake2b/test-vectors.json');
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
11
|
-
readyCalled = true;
|
|
12
|
-
|
|
10
|
+
function test(b2b) {
|
|
13
11
|
tape('hello world', function (t) {
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
40
|
-
|
|
37
|
+
const a = blake2b();
|
|
38
|
+
const b = blake2b(64);
|
|
41
39
|
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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();
|