@bitgo-beta/blake2b 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.
Files changed (2) hide show
  1. package/index.js +38 -36
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -1,12 +1,23 @@
1
- var assert = require('nanoassert');
2
- var b2wasm = require('@bitgo-beta/blake2b-wasm');
1
+ const assert = require('nanoassert');
2
+ const b2wasm = require('@bitgo-beta/blake2b-wasm');
3
+
4
+ const BYTES_MIN = (module.exports.BYTES_MIN = 16);
5
+ const BYTES_MAX = (module.exports.BYTES_MAX = 64);
6
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
7
+ const BYTES = (module.exports.BYTES = 32);
8
+ const KEYBYTES_MIN = (module.exports.KEYBYTES_MIN = 16);
9
+ const KEYBYTES_MAX = (module.exports.KEYBYTES_MAX = 64);
10
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
+ const KEYBYTES = (module.exports.KEYBYTES = 32);
12
+ const SALTBYTES = (module.exports.SALTBYTES = 16);
13
+ const PERSONALBYTES = (module.exports.PERSONALBYTES = 16);
3
14
 
4
15
  // 64-bit unsigned addition
5
16
  // Sets v[a,a+1] += v[b,b+1]
6
17
  // v should be a Uint32Array
7
18
  function ADD64AA(v, a, b) {
8
- var o0 = v[a] + v[b];
9
- var o1 = v[a + 1] + v[b + 1];
19
+ const o0 = v[a] + v[b];
20
+ let o1 = v[a + 1] + v[b + 1];
10
21
  if (o0 >= 0x100000000) {
11
22
  o1++;
12
23
  }
@@ -18,11 +29,11 @@ function ADD64AA(v, a, b) {
18
29
  // Sets v[a,a+1] += b
19
30
  // b0 is the low 32 bits of b, b1 represents the high 32 bits
20
31
  function ADD64AC(v, a, b0, b1) {
21
- var o0 = v[a] + b0;
32
+ let o0 = v[a] + b0;
22
33
  if (b0 < 0) {
23
34
  o0 += 0x100000000;
24
35
  }
25
- var o1 = v[a + 1] + b1;
36
+ let o1 = v[a + 1] + b1;
26
37
  if (o0 >= 0x100000000) {
27
38
  o1++;
28
39
  }
@@ -38,17 +49,17 @@ function B2B_GET32(arr, i) {
38
49
  // G Mixing function
39
50
  // The ROTRs are inlined for speed
40
51
  function B2B_G(a, b, c, d, ix, iy) {
41
- var x0 = m[ix];
42
- var x1 = m[ix + 1];
43
- var y0 = m[iy];
44
- var y1 = m[iy + 1];
52
+ const x0 = m[ix];
53
+ const x1 = m[ix + 1];
54
+ const y0 = m[iy];
55
+ const y1 = m[iy + 1];
45
56
 
46
57
  ADD64AA(v, a, b); // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s
47
58
  ADD64AC(v, a, x0, x1); // v[a, a+1] += x ... x0 is the low 32 bits of x, x1 is the high 32 bits
48
59
 
49
60
  // v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
50
- var xor0 = v[d] ^ v[a];
51
- var xor1 = v[d + 1] ^ v[a + 1];
61
+ let xor0 = v[d] ^ v[a];
62
+ let xor1 = v[d + 1] ^ v[a + 1];
52
63
  v[d] = xor1;
53
64
  v[d + 1] = xor0;
54
65
 
@@ -79,12 +90,12 @@ function B2B_G(a, b, c, d, ix, iy) {
79
90
  }
80
91
 
81
92
  // Initialization Vector
82
- var BLAKE2B_IV32 = new Uint32Array([
93
+ const BLAKE2B_IV32 = new Uint32Array([
83
94
  0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85, 0xfe94f82b, 0x3c6ef372, 0x5f1d36f1, 0xa54ff53a, 0xade682d1,
84
95
  0x510e527f, 0x2b3e6c1f, 0x9b05688c, 0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19,
85
96
  ]);
86
97
 
87
- var SIGMA8 = [
98
+ const SIGMA8 = [
88
99
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3, 11, 8, 12,
89
100
  0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4, 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8, 9, 0, 5, 7, 2, 4, 10,
90
101
  15, 14, 1, 11, 12, 6, 8, 3, 13, 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9, 12, 5, 1, 15, 14, 13, 4, 10, 0,
@@ -96,7 +107,7 @@ var SIGMA8 = [
96
107
  // These are offsets into a uint64 buffer.
97
108
  // Multiply them all by 2 to make them offsets into a uint32 buffer,
98
109
  // because this is JavaScript and we don't have uint64s
99
- var SIGMA82 = new Uint8Array(
110
+ const SIGMA82 = new Uint8Array(
100
111
  SIGMA8.map(function (x) {
101
112
  return x * 2;
102
113
  })
@@ -104,12 +115,12 @@ var SIGMA82 = new Uint8Array(
104
115
 
105
116
  // Compression function. 'last' flag indicates last block.
106
117
  // Note we're representing 16 uint64s as 32 uint32s
107
- var v = new Uint32Array(32);
108
- var m = new Uint32Array(32);
118
+ const v = new Uint32Array(32);
119
+ const m = new Uint32Array(32);
109
120
  function blake2bCompress(ctx, last) {
110
- var i = 0;
121
+ let i = 0;
111
122
 
112
- // init work variables
123
+ // init work letiables
113
124
  for (i = 0; i < 16; i++) {
114
125
  v[i] = ctx.h[i];
115
126
  v[i + 16] = BLAKE2B_IV32[i];
@@ -149,7 +160,7 @@ function blake2bCompress(ctx, last) {
149
160
  }
150
161
 
151
162
  // reusable parameter_block
152
- var parameter_block = new Uint8Array([
163
+ const parameter_block = new Uint8Array([
153
164
  0,
154
165
  0,
155
166
  0,
@@ -239,7 +250,7 @@ function Blake2b(outlen, key, salt, personal) {
239
250
  if (personal) parameter_block.set(personal, 48);
240
251
 
241
252
  // initialize hash state
242
- for (var i = 0; i < 16; i++) {
253
+ for (let i = 0; i < 16; i++) {
243
254
  this.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameter_block, i * 4);
244
255
  }
245
256
 
@@ -258,7 +269,7 @@ Blake2b.prototype.update = function (input) {
258
269
  };
259
270
 
260
271
  Blake2b.prototype.digest = function (out) {
261
- var buf = !out || out === 'binary' || out === 'hex' ? new Uint8Array(this.outlen) : out;
272
+ const buf = !out || out === 'binary' || out === 'hex' ? new Uint8Array(this.outlen) : out;
262
273
  assert(buf instanceof Uint8Array, 'out must be "binary", "hex", Uint8Array, or Buffer');
263
274
  assert(buf.length >= this.outlen, 'out must have at least outlen bytes of space');
264
275
  blake2bFinal(this, buf);
@@ -277,7 +288,7 @@ Blake2b.ready = function (cb) {
277
288
  // Updates a BLAKE2b streaming hash
278
289
  // Requires hash context and Uint8Array (byte array)
279
290
  function blake2bUpdate(ctx, input) {
280
- for (var i = 0; i < input.length; i++) {
291
+ for (let i = 0; i < input.length; i++) {
281
292
  if (ctx.c === 128) {
282
293
  // buffer full ?
283
294
  ctx.t += ctx.c; // add counters
@@ -299,15 +310,15 @@ function blake2bFinal(ctx, out) {
299
310
  }
300
311
  blake2bCompress(ctx, true); // final block flag = 1
301
312
 
302
- for (var i = 0; i < ctx.outlen; i++) {
313
+ for (let i = 0; i < ctx.outlen; i++) {
303
314
  out[i] = ctx.h[i >> 2] >> (8 * (i & 3));
304
315
  }
305
316
  return out;
306
317
  }
307
318
 
308
319
  function hexSlice(buf) {
309
- var str = '';
310
- for (var i = 0; i < buf.length; i++) str += toHex(buf[i]);
320
+ let str = '';
321
+ for (let i = 0; i < buf.length; i++) str += toHex(buf[i]);
311
322
  return str;
312
323
  }
313
324
 
@@ -316,7 +327,7 @@ function toHex(n) {
316
327
  return n.toString(16);
317
328
  }
318
329
 
319
- var Proto = Blake2b;
330
+ const Proto = Blake2b;
320
331
 
321
332
  module.exports = function createHash(outlen, key, salt, personal, noAssert) {
322
333
  if (noAssert !== true) {
@@ -353,15 +364,6 @@ module.exports.ready = function (cb) {
353
364
  module.exports.WASM_SUPPORTED = b2wasm.SUPPORTED;
354
365
  module.exports.WASM_LOADED = false;
355
366
 
356
- var BYTES_MIN = (module.exports.BYTES_MIN = 16);
357
- var BYTES_MAX = (module.exports.BYTES_MAX = 64);
358
- var BYTES = (module.exports.BYTES = 32);
359
- var KEYBYTES_MIN = (module.exports.KEYBYTES_MIN = 16);
360
- var KEYBYTES_MAX = (module.exports.KEYBYTES_MAX = 64);
361
- var KEYBYTES = (module.exports.KEYBYTES = 32);
362
- var SALTBYTES = (module.exports.SALTBYTES = 16);
363
- var PERSONALBYTES = (module.exports.PERSONALBYTES = 16);
364
-
365
367
  b2wasm.ready(function (err) {
366
368
  if (!err) {
367
369
  module.exports.WASM_LOADED = true;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@bitgo-beta/blake2b",
3
- "version": "3.2.1-alpha.60",
3
+ "version": "3.2.1-alpha.62",
4
4
  "description": "Blake2b (64-bit version) in pure JavaScript",
5
5
  "main": "index.js",
6
6
  "dependencies": {
7
- "@bitgo-beta/blake2b-wasm": "3.2.1-alpha.60",
7
+ "@bitgo-beta/blake2b-wasm": "3.2.1-alpha.62",
8
8
  "nanoassert": "^2.0.0"
9
9
  },
10
10
  "publishConfig": {
@@ -28,5 +28,5 @@
28
28
  "url": "https://github.com/emilbayes/blake2b/issues"
29
29
  },
30
30
  "homepage": "https://github.com/emilbayes/blake2b#readme",
31
- "gitHead": "79f27a85c6c9403a1d5687873f5f55b57ff000a3"
31
+ "gitHead": "21822984a59a36323b38849239362ddb639f319e"
32
32
  }