@waku/rln 0.1.6-10590da.0 → 0.1.6-383e0b2.0

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 (97) hide show
  1. package/bundle/_virtual/index2.js +1 -1
  2. package/bundle/_virtual/utils.js +2 -2
  3. package/bundle/_virtual/utils2.js +2 -2
  4. package/bundle/index.js +1 -2
  5. package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +1 -1
  6. package/bundle/node_modules/{js-sha3 → @ethersproject/keccak256/node_modules/js-sha3}/src/sha3.js +2 -2
  7. package/bundle/node_modules/@noble/hashes/esm/_assert.js +32 -6
  8. package/bundle/node_modules/@noble/hashes/esm/_md.js +11 -22
  9. package/bundle/node_modules/@noble/hashes/esm/_u64.js +3 -4
  10. package/bundle/node_modules/@noble/hashes/esm/sha256.js +102 -5
  11. package/bundle/node_modules/@noble/hashes/esm/sha3.js +24 -30
  12. package/bundle/node_modules/@noble/hashes/esm/utils.js +18 -69
  13. package/bundle/node_modules/bn.js/lib/bn.js +0 -1
  14. package/bundle/node_modules/ethereum-cryptography/esm/sha256.js +1 -1
  15. package/bundle/packages/rln/dist/contract/constants.js +0 -1
  16. package/bundle/packages/rln/dist/contract/rln_base_contract.js +71 -127
  17. package/bundle/packages/rln/dist/credentials_manager.js +4 -9
  18. package/bundle/packages/rln/dist/identity.js +1 -1
  19. package/bundle/packages/rln/dist/keystore/cipher.js +3 -3
  20. package/bundle/packages/rln/dist/keystore/keystore.js +1 -1
  21. package/bundle/packages/rln/dist/utils/bytes.js +2 -6
  22. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/checksum.js +3 -3
  23. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/cipher.js +4 -4
  24. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/class.js +7 -7
  25. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/functional.js +7 -7
  26. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/index.js +6 -6
  27. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/kdf.js +5 -5
  28. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/password.js +1 -1
  29. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1 -1
  30. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/schema-validation.js +2 -2
  31. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/types.js +1 -1
  32. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +3 -3
  33. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +7 -7
  34. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +3 -3
  35. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +3 -3
  36. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +3 -3
  37. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +7 -7
  38. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/_assert.js +1 -1
  39. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/_sha2.js +3 -3
  40. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/_u64.js +1 -1
  41. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/cryptoBrowser.js +1 -1
  42. package/bundle/packages/rln/node_modules/@noble/hashes/esm/_assert.js +43 -0
  43. package/bundle/packages/rln/node_modules/@noble/hashes/esm/_sha2.js +116 -0
  44. package/bundle/{node_modules → packages/rln/node_modules}/@noble/hashes/esm/hmac.js +10 -19
  45. package/bundle/{node_modules/@noble/hashes/esm/sha2.js → packages/rln/node_modules/@noble/hashes/esm/sha256.js} +50 -36
  46. package/bundle/packages/rln/node_modules/@noble/hashes/esm/utils.js +43 -0
  47. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/hmac.js +3 -3
  48. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/pbkdf2.js +4 -4
  49. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/scrypt.js +5 -5
  50. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/sha256.js +3 -3
  51. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/sha512.js +4 -4
  52. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/utils.js +2 -2
  53. package/dist/.tsbuildinfo +1 -1
  54. package/dist/contract/index.d.ts +0 -1
  55. package/dist/contract/index.js +0 -1
  56. package/dist/contract/index.js.map +1 -1
  57. package/dist/contract/rln_base_contract.d.ts +22 -32
  58. package/dist/contract/rln_base_contract.js +71 -127
  59. package/dist/contract/rln_base_contract.js.map +1 -1
  60. package/dist/contract/types.d.ts +0 -5
  61. package/dist/contract/types.js.map +1 -1
  62. package/dist/credentials_manager.js +2 -7
  63. package/dist/credentials_manager.js.map +1 -1
  64. package/dist/identity.js +1 -1
  65. package/dist/identity.js.map +1 -1
  66. package/dist/index.d.ts +1 -2
  67. package/dist/index.js +0 -1
  68. package/dist/index.js.map +1 -1
  69. package/dist/keystore/keystore.js.map +1 -1
  70. package/dist/keystore/types.d.ts +2 -2
  71. package/dist/utils/bytes.js +2 -6
  72. package/dist/utils/bytes.js.map +1 -1
  73. package/package.json +1 -1
  74. package/src/contract/index.ts +0 -1
  75. package/src/contract/rln_base_contract.ts +102 -166
  76. package/src/contract/types.ts +0 -5
  77. package/src/credentials_manager.ts +2 -9
  78. package/src/identity.ts +1 -1
  79. package/src/index.ts +1 -3
  80. package/src/keystore/keystore.ts +2 -4
  81. package/src/keystore/types.ts +2 -2
  82. package/src/utils/bytes.ts +2 -6
  83. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +0 -0
  84. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +0 -0
  85. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +0 -0
  86. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +0 -0
  87. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +0 -0
  88. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +0 -0
  89. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +0 -0
  90. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +0 -0
  91. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +0 -0
  92. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +0 -0
  93. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +0 -0
  94. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +0 -0
  95. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +0 -0
  96. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +0 -0
  97. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +0 -0
@@ -1,8 +1,8 @@
1
- import { __exports as _sha2 } from '../../../../../../_virtual/_sha2.js';
1
+ import { __exports as _sha2 } from '../../../../../_virtual/_sha2.js';
2
2
  import './_assert.js';
3
3
  import './utils.js';
4
- import { __exports as utils } from '../../../../../../_virtual/utils2.js';
5
- import { __exports as _assert } from '../../../../../../_virtual/_assert.js';
4
+ import { __exports as utils } from '../../../../../_virtual/utils.js';
5
+ import { __exports as _assert } from '../../../../../_virtual/_assert.js';
6
6
 
7
7
  Object.defineProperty(_sha2, "__esModule", { value: true });
8
8
  _sha2.SHA2 = void 0;
@@ -1,4 +1,4 @@
1
- import { __exports as _u64 } from '../../../../../../_virtual/_u64.js';
1
+ import { __exports as _u64 } from '../../../../../_virtual/_u64.js';
2
2
 
3
3
  (function (exports) {
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,4 @@
1
- import { __exports as cryptoBrowser } from '../../../../../../_virtual/cryptoBrowser.js';
1
+ import { __exports as cryptoBrowser } from '../../../../../_virtual/cryptoBrowser.js';
2
2
 
3
3
  Object.defineProperty(cryptoBrowser, "__esModule", { value: true });
4
4
  cryptoBrowser.crypto = void 0;
@@ -0,0 +1,43 @@
1
+ function number(n) {
2
+ if (!Number.isSafeInteger(n) || n < 0)
3
+ throw new Error(`Wrong positive integer: ${n}`);
4
+ }
5
+ function bool(b) {
6
+ if (typeof b !== 'boolean')
7
+ throw new Error(`Expected boolean, not ${b}`);
8
+ }
9
+ function bytes(b, ...lengths) {
10
+ if (!(b instanceof Uint8Array))
11
+ throw new TypeError('Expected Uint8Array');
12
+ if (lengths.length > 0 && !lengths.includes(b.length))
13
+ throw new TypeError(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`);
14
+ }
15
+ function hash(hash) {
16
+ if (typeof hash !== 'function' || typeof hash.create !== 'function')
17
+ throw new Error('Hash should be wrapped by utils.wrapConstructor');
18
+ number(hash.outputLen);
19
+ number(hash.blockLen);
20
+ }
21
+ function exists(instance, checkFinished = true) {
22
+ if (instance.destroyed)
23
+ throw new Error('Hash instance has been destroyed');
24
+ if (checkFinished && instance.finished)
25
+ throw new Error('Hash#digest() has already been called');
26
+ }
27
+ function output(out, instance) {
28
+ bytes(out);
29
+ const min = instance.outputLen;
30
+ if (out.length < min) {
31
+ throw new Error(`digestInto() expects output buffer of length at least ${min}`);
32
+ }
33
+ }
34
+ const assert = {
35
+ number,
36
+ bool,
37
+ bytes,
38
+ hash,
39
+ exists,
40
+ output,
41
+ };
42
+
43
+ export { bool, bytes, assert as default, exists, hash, number, output };
@@ -0,0 +1,116 @@
1
+ import assert from './_assert.js';
2
+ import { Hash, createView, toBytes } from './utils.js';
3
+
4
+ // Polyfill for Safari 14
5
+ function setBigUint64(view, byteOffset, value, isLE) {
6
+ if (typeof view.setBigUint64 === 'function')
7
+ return view.setBigUint64(byteOffset, value, isLE);
8
+ const _32n = BigInt(32);
9
+ const _u32_max = BigInt(0xffffffff);
10
+ const wh = Number((value >> _32n) & _u32_max);
11
+ const wl = Number(value & _u32_max);
12
+ const h = isLE ? 4 : 0;
13
+ const l = isLE ? 0 : 4;
14
+ view.setUint32(byteOffset + h, wh, isLE);
15
+ view.setUint32(byteOffset + l, wl, isLE);
16
+ }
17
+ // Base SHA2 class (RFC 6234)
18
+ class SHA2 extends Hash {
19
+ constructor(blockLen, outputLen, padOffset, isLE) {
20
+ super();
21
+ this.blockLen = blockLen;
22
+ this.outputLen = outputLen;
23
+ this.padOffset = padOffset;
24
+ this.isLE = isLE;
25
+ this.finished = false;
26
+ this.length = 0;
27
+ this.pos = 0;
28
+ this.destroyed = false;
29
+ this.buffer = new Uint8Array(blockLen);
30
+ this.view = createView(this.buffer);
31
+ }
32
+ update(data) {
33
+ assert.exists(this);
34
+ const { view, buffer, blockLen } = this;
35
+ data = toBytes(data);
36
+ const len = data.length;
37
+ for (let pos = 0; pos < len;) {
38
+ const take = Math.min(blockLen - this.pos, len - pos);
39
+ // Fast path: we have at least one block in input, cast it to view and process
40
+ if (take === blockLen) {
41
+ const dataView = createView(data);
42
+ for (; blockLen <= len - pos; pos += blockLen)
43
+ this.process(dataView, pos);
44
+ continue;
45
+ }
46
+ buffer.set(data.subarray(pos, pos + take), this.pos);
47
+ this.pos += take;
48
+ pos += take;
49
+ if (this.pos === blockLen) {
50
+ this.process(view, 0);
51
+ this.pos = 0;
52
+ }
53
+ }
54
+ this.length += data.length;
55
+ this.roundClean();
56
+ return this;
57
+ }
58
+ digestInto(out) {
59
+ assert.exists(this);
60
+ assert.output(out, this);
61
+ this.finished = true;
62
+ // Padding
63
+ // We can avoid allocation of buffer for padding completely if it
64
+ // was previously not allocated here. But it won't change performance.
65
+ const { buffer, view, blockLen, isLE } = this;
66
+ let { pos } = this;
67
+ // append the bit '1' to the message
68
+ buffer[pos++] = 0b10000000;
69
+ this.buffer.subarray(pos).fill(0);
70
+ // we have less than padOffset left in buffer, so we cannot put length in current block, need process it and pad again
71
+ if (this.padOffset > blockLen - pos) {
72
+ this.process(view, 0);
73
+ pos = 0;
74
+ }
75
+ // Pad until full block byte with zeros
76
+ for (let i = pos; i < blockLen; i++)
77
+ buffer[i] = 0;
78
+ // Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that
79
+ // You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
80
+ // So we just write lowest 64 bits of that value.
81
+ setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
82
+ this.process(view, 0);
83
+ const oview = createView(out);
84
+ const len = this.outputLen;
85
+ // NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT
86
+ if (len % 4)
87
+ throw new Error('_sha2: outputLen should be aligned to 32bit');
88
+ const outLen = len / 4;
89
+ const state = this.get();
90
+ if (outLen > state.length)
91
+ throw new Error('_sha2: outputLen bigger than state');
92
+ for (let i = 0; i < outLen; i++)
93
+ oview.setUint32(4 * i, state[i], isLE);
94
+ }
95
+ digest() {
96
+ const { buffer, outputLen } = this;
97
+ this.digestInto(buffer);
98
+ const res = buffer.slice(0, outputLen);
99
+ this.destroy();
100
+ return res;
101
+ }
102
+ _cloneInto(to) {
103
+ to || (to = new this.constructor());
104
+ to.set(...this.get());
105
+ const { blockLen, buffer, length, finished, destroyed, pos } = this;
106
+ to.length = length;
107
+ to.pos = pos;
108
+ to.finished = finished;
109
+ to.destroyed = destroyed;
110
+ if (length % blockLen)
111
+ to.buffer.set(buffer);
112
+ return to;
113
+ }
114
+ }
115
+
116
+ export { SHA2 };
@@ -1,19 +1,17 @@
1
- import { Hash, ahash, toBytes, clean, aexists, abytes } from './utils.js';
1
+ import assert from './_assert.js';
2
+ import { Hash, toBytes } from './utils.js';
2
3
 
3
- /**
4
- * HMAC: RFC2104 message authentication code.
5
- * @module
6
- */
4
+ // HMAC (RFC 2104)
7
5
  class HMAC extends Hash {
8
6
  constructor(hash, _key) {
9
7
  super();
10
8
  this.finished = false;
11
9
  this.destroyed = false;
12
- ahash(hash);
10
+ assert.hash(hash);
13
11
  const key = toBytes(_key);
14
12
  this.iHash = hash.create();
15
13
  if (typeof this.iHash.update !== 'function')
16
- throw new Error('Expected instance of class which extends utils.Hash');
14
+ throw new TypeError('Expected instance of class which extends utils.Hash');
17
15
  this.blockLen = this.iHash.blockLen;
18
16
  this.outputLen = this.iHash.outputLen;
19
17
  const blockLen = this.blockLen;
@@ -29,16 +27,16 @@ class HMAC extends Hash {
29
27
  for (let i = 0; i < pad.length; i++)
30
28
  pad[i] ^= 0x36 ^ 0x5c;
31
29
  this.oHash.update(pad);
32
- clean(pad);
30
+ pad.fill(0);
33
31
  }
34
32
  update(buf) {
35
- aexists(this);
33
+ assert.exists(this);
36
34
  this.iHash.update(buf);
37
35
  return this;
38
36
  }
39
37
  digestInto(out) {
40
- aexists(this);
41
- abytes(out, this.outputLen);
38
+ assert.exists(this);
39
+ assert.bytes(out, this.outputLen);
42
40
  this.finished = true;
43
41
  this.iHash.digestInto(out);
44
42
  this.oHash.update(out);
@@ -63,9 +61,6 @@ class HMAC extends Hash {
63
61
  to.iHash = iHash._cloneInto(to.iHash);
64
62
  return to;
65
63
  }
66
- clone() {
67
- return this._cloneInto();
68
- }
69
64
  destroy() {
70
65
  this.destroyed = true;
71
66
  this.oHash.destroy();
@@ -77,12 +72,8 @@ class HMAC extends Hash {
77
72
  * @param hash - function that would be used e.g. sha256
78
73
  * @param key - message key
79
74
  * @param message - message data
80
- * @example
81
- * import { hmac } from '@noble/hashes/hmac';
82
- * import { sha256 } from '@noble/hashes/sha2';
83
- * const mac1 = hmac(sha256, 'key', 'message');
84
75
  */
85
76
  const hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
86
77
  hmac.create = (hash, key) => new HMAC(hash, key);
87
78
 
88
- export { HMAC, hmac };
79
+ export { hmac };
@@ -1,19 +1,14 @@
1
- import { HashMD, SHA256_IV, Chi, Maj } from './_md.js';
2
- import { createHasher, clean, rotr } from './utils.js';
1
+ import { SHA2 } from './_sha2.js';
2
+ import { wrapConstructor, rotr } from './utils.js';
3
3
 
4
- /**
5
- * SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256.
6
- * SHA256 is the fastest hash implementable in JS, even faster than Blake3.
7
- * Check out [RFC 4634](https://datatracker.ietf.org/doc/html/rfc4634) and
8
- * [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
9
- * @module
10
- */
11
- /**
12
- * Round constants:
13
- * First 32 bits of fractional parts of the cube roots of the first 64 primes 2..311)
14
- */
4
+ // Choice: a ? b : c
5
+ const Chi = (a, b, c) => (a & b) ^ (~a & c);
6
+ // Majority function, true if any two inpust is true
7
+ const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
8
+ // Round constants:
9
+ // first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
15
10
  // prettier-ignore
16
- const SHA256_K = /* @__PURE__ */ Uint32Array.from([
11
+ const SHA256_K = new Uint32Array([
17
12
  0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
18
13
  0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
19
14
  0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
@@ -23,21 +18,27 @@ const SHA256_K = /* @__PURE__ */ Uint32Array.from([
23
18
  0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
24
19
  0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
25
20
  ]);
26
- /** Reusable temporary buffer. "W" comes straight from spec. */
27
- const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
28
- class SHA256 extends HashMD {
29
- constructor(outputLen = 32) {
30
- super(64, outputLen, 8, false);
21
+ // Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
22
+ // prettier-ignore
23
+ const IV = new Uint32Array([
24
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
25
+ ]);
26
+ // Temporary buffer, not used to store anything between runs
27
+ // Named this way because it matches specification.
28
+ const SHA256_W = new Uint32Array(64);
29
+ class SHA256 extends SHA2 {
30
+ constructor() {
31
+ super(64, 32, 8, false);
31
32
  // We cannot use array here since array allows indexing by variable
32
33
  // which means optimizer/compiler cannot use registers.
33
- this.A = SHA256_IV[0] | 0;
34
- this.B = SHA256_IV[1] | 0;
35
- this.C = SHA256_IV[2] | 0;
36
- this.D = SHA256_IV[3] | 0;
37
- this.E = SHA256_IV[4] | 0;
38
- this.F = SHA256_IV[5] | 0;
39
- this.G = SHA256_IV[6] | 0;
40
- this.H = SHA256_IV[7] | 0;
34
+ this.A = IV[0] | 0;
35
+ this.B = IV[1] | 0;
36
+ this.C = IV[2] | 0;
37
+ this.D = IV[3] | 0;
38
+ this.E = IV[4] | 0;
39
+ this.F = IV[5] | 0;
40
+ this.G = IV[6] | 0;
41
+ this.H = IV[7] | 0;
41
42
  }
42
43
  get() {
43
44
  const { A, B, C, D, E, F, G, H } = this;
@@ -93,20 +94,33 @@ class SHA256 extends HashMD {
93
94
  this.set(A, B, C, D, E, F, G, H);
94
95
  }
95
96
  roundClean() {
96
- clean(SHA256_W);
97
+ SHA256_W.fill(0);
97
98
  }
98
99
  destroy() {
99
100
  this.set(0, 0, 0, 0, 0, 0, 0, 0);
100
- clean(this.buffer);
101
+ this.buffer.fill(0);
102
+ }
103
+ }
104
+ // Constants from https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
105
+ class SHA224 extends SHA256 {
106
+ constructor() {
107
+ super();
108
+ this.A = 0xc1059ed8 | 0;
109
+ this.B = 0x367cd507 | 0;
110
+ this.C = 0x3070dd17 | 0;
111
+ this.D = 0xf70e5939 | 0;
112
+ this.E = 0xffc00b31 | 0;
113
+ this.F = 0x68581511 | 0;
114
+ this.G = 0x64f98fa7 | 0;
115
+ this.H = 0xbefa4fa4 | 0;
116
+ this.outputLen = 28;
101
117
  }
102
118
  }
103
119
  /**
104
- * SHA2-256 hash function from RFC 4634.
105
- *
106
- * It is the fastest JS hash, even faster than Blake3.
107
- * To break sha256 using birthday attack, attackers need to try 2^128 hashes.
108
- * BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
120
+ * SHA2-256 hash function
121
+ * @param message - data that would be hashed
109
122
  */
110
- const sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
123
+ const sha256 = wrapConstructor(() => new SHA256());
124
+ wrapConstructor(() => new SHA224());
111
125
 
112
- export { SHA256, sha256 };
126
+ export { sha256 };
@@ -0,0 +1,43 @@
1
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2
+ // The import here is via the package name. This is to ensure
3
+ // that exports mapping/resolution does fall into place.
4
+ // Cast array to view
5
+ const createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
6
+ // The rotate right (circular right shift) operation for uint32
7
+ const rotr = (word, shift) => (word << (32 - shift)) | (word >>> shift);
8
+ const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
9
+ // There is almost no big endian hardware, but js typed arrays uses platform specific endianness.
10
+ // So, just to be sure not to corrupt anything.
11
+ if (!isLE)
12
+ throw new Error('Non little-endian hardware is not supported');
13
+ Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0'));
14
+ function utf8ToBytes(str) {
15
+ if (typeof str !== 'string') {
16
+ throw new TypeError(`utf8ToBytes expected string, got ${typeof str}`);
17
+ }
18
+ return new TextEncoder().encode(str);
19
+ }
20
+ function toBytes(data) {
21
+ if (typeof data === 'string')
22
+ data = utf8ToBytes(data);
23
+ if (!(data instanceof Uint8Array))
24
+ throw new TypeError(`Expected input type is Uint8Array (got ${typeof data})`);
25
+ return data;
26
+ }
27
+ // For runtime check if class implements interface
28
+ class Hash {
29
+ // Safe version that clones internal state
30
+ clone() {
31
+ return this._cloneInto();
32
+ }
33
+ }
34
+ function wrapConstructor(hashConstructor) {
35
+ const hashC = (message) => hashConstructor().update(toBytes(message)).digest();
36
+ const tmp = hashConstructor();
37
+ hashC.outputLen = tmp.outputLen;
38
+ hashC.blockLen = tmp.blockLen;
39
+ hashC.create = () => hashConstructor();
40
+ return hashC;
41
+ }
42
+
43
+ export { Hash, createView, isLE, rotr, toBytes, utf8ToBytes, wrapConstructor };
@@ -1,8 +1,8 @@
1
- import { __exports as hmac } from '../../../../../../_virtual/hmac.js';
1
+ import { __exports as hmac } from '../../../../../_virtual/hmac.js';
2
2
  import './_assert.js';
3
3
  import './utils.js';
4
- import { __exports as utils } from '../../../../../../_virtual/utils2.js';
5
- import { __exports as _assert } from '../../../../../../_virtual/_assert.js';
4
+ import { __exports as utils } from '../../../../../_virtual/utils.js';
5
+ import { __exports as _assert } from '../../../../../_virtual/_assert.js';
6
6
 
7
7
  (function (exports) {
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,10 +1,10 @@
1
- import { __exports as pbkdf2$1 } from '../../../../../../_virtual/pbkdf22.js';
1
+ import { __exports as pbkdf2$1 } from '../../../../../_virtual/pbkdf22.js';
2
2
  import './_assert.js';
3
3
  import './hmac.js';
4
4
  import './utils.js';
5
- import { __exports as utils } from '../../../../../../_virtual/utils2.js';
6
- import { __exports as _assert } from '../../../../../../_virtual/_assert.js';
7
- import { __exports as hmac } from '../../../../../../_virtual/hmac.js';
5
+ import { __exports as utils } from '../../../../../_virtual/utils.js';
6
+ import { __exports as _assert } from '../../../../../_virtual/_assert.js';
7
+ import { __exports as hmac } from '../../../../../_virtual/hmac.js';
8
8
 
9
9
  Object.defineProperty(pbkdf2$1, "__esModule", { value: true });
10
10
  pbkdf2$1.pbkdf2Async = pbkdf2$1.pbkdf2 = void 0;
@@ -1,12 +1,12 @@
1
- import { __exports as scrypt$1 } from '../../../../../../_virtual/scrypt2.js';
1
+ import { __exports as scrypt$1 } from '../../../../../_virtual/scrypt2.js';
2
2
  import './_assert.js';
3
3
  import './sha256.js';
4
4
  import './pbkdf2.js';
5
5
  import './utils.js';
6
- import { __exports as utils } from '../../../../../../_virtual/utils2.js';
7
- import { __exports as _assert } from '../../../../../../_virtual/_assert.js';
8
- import { __exports as pbkdf2 } from '../../../../../../_virtual/pbkdf22.js';
9
- import { __exports as sha256 } from '../../../../../../_virtual/sha2562.js';
6
+ import { __exports as utils } from '../../../../../_virtual/utils.js';
7
+ import { __exports as _assert } from '../../../../../_virtual/_assert.js';
8
+ import { __exports as pbkdf2 } from '../../../../../_virtual/pbkdf22.js';
9
+ import { __exports as sha256 } from '../../../../../_virtual/sha2562.js';
10
10
 
11
11
  Object.defineProperty(scrypt$1, "__esModule", { value: true });
12
12
  scrypt$1.scryptAsync = scrypt$1.scrypt = void 0;
@@ -1,8 +1,8 @@
1
- import { __exports as sha256 } from '../../../../../../_virtual/sha2562.js';
1
+ import { __exports as sha256 } from '../../../../../_virtual/sha2562.js';
2
2
  import './_sha2.js';
3
3
  import './utils.js';
4
- import { __exports as _sha2 } from '../../../../../../_virtual/_sha2.js';
5
- import { __exports as utils } from '../../../../../../_virtual/utils2.js';
4
+ import { __exports as _sha2 } from '../../../../../_virtual/_sha2.js';
5
+ import { __exports as utils } from '../../../../../_virtual/utils.js';
6
6
 
7
7
  Object.defineProperty(sha256, "__esModule", { value: true });
8
8
  sha256.sha224 = sha256.sha256 = void 0;
@@ -1,10 +1,10 @@
1
- import { __exports as sha512 } from '../../../../../../_virtual/sha512.js';
1
+ import { __exports as sha512 } from '../../../../../_virtual/sha512.js';
2
2
  import './_sha2.js';
3
3
  import './_u64.js';
4
4
  import './utils.js';
5
- import { __exports as _u64 } from '../../../../../../_virtual/_u64.js';
6
- import { __exports as _sha2 } from '../../../../../../_virtual/_sha2.js';
7
- import { __exports as utils } from '../../../../../../_virtual/utils2.js';
5
+ import { __exports as _u64 } from '../../../../../_virtual/_u64.js';
6
+ import { __exports as _sha2 } from '../../../../../_virtual/_sha2.js';
7
+ import { __exports as utils } from '../../../../../_virtual/utils.js';
8
8
 
9
9
  Object.defineProperty(sha512, "__esModule", { value: true });
10
10
  sha512.sha384 = sha512.sha512_256 = sha512.sha512_224 = sha512.sha512 = sha512.SHA512 = void 0;
@@ -1,6 +1,6 @@
1
- import { __exports as utils } from '../../../../../../_virtual/utils2.js';
1
+ import { __exports as utils } from '../../../../../_virtual/utils.js';
2
2
  import './cryptoBrowser.js';
3
- import { __exports as cryptoBrowser } from '../../../../../../_virtual/cryptoBrowser.js';
3
+ import { __exports as cryptoBrowser } from '../../../../../_virtual/cryptoBrowser.js';
4
4
 
5
5
  (function (exports) {
6
6
  /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */