@waku/rln 0.1.4-d27db21.0 → 0.1.5-053bb95.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 (138) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +5 -0
  3. package/bundle/_virtual/utils.js +2 -2
  4. package/bundle/_virtual/utils2.js +2 -2
  5. package/bundle/index.js +3 -1
  6. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +1 -1
  7. package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +1 -1
  8. package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +1 -1
  9. package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +11 -11
  10. package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +1 -1
  11. package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +7 -7
  12. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +2 -2
  13. package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +2 -2
  14. package/bundle/node_modules/@ethersproject/keccak256/node_modules/js-sha3/src/sha3.js +1 -1
  15. package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +1 -1
  16. package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +1 -1
  17. package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +44 -44
  18. package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +8 -8
  19. package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +1 -1
  20. package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +1 -1
  21. package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +1 -1
  22. package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +2 -2
  23. package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +1 -0
  24. package/bundle/node_modules/@noble/hashes/esm/sha3.js +1 -1
  25. package/bundle/node_modules/bn.js/lib/bn.js +1 -1
  26. package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +6 -6
  27. package/bundle/packages/rln/dist/contract/abi.js +502 -248
  28. package/bundle/packages/rln/dist/contract/constants.js +5 -9
  29. package/bundle/packages/rln/dist/contract/errors.js +62 -0
  30. package/bundle/packages/rln/dist/contract/rln_base_contract.js +347 -0
  31. package/bundle/packages/rln/dist/contract/rln_contract.js +81 -392
  32. package/bundle/packages/rln/dist/contract/types.js +9 -0
  33. package/bundle/packages/rln/dist/create.js +1 -1
  34. package/bundle/packages/rln/dist/credentials_manager.js +215 -0
  35. package/bundle/packages/rln/dist/identity.js +8 -0
  36. package/bundle/packages/rln/dist/keystore/keystore.js +20 -28
  37. package/bundle/packages/rln/dist/rln.js +56 -166
  38. package/bundle/packages/rln/dist/zerokit.js +5 -5
  39. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/checksum.js +2 -2
  40. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/cipher.js +3 -3
  41. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/class.js +4 -4
  42. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/functional.js +4 -4
  43. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/kdf.js +4 -4
  44. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/password.js +1 -1
  45. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1 -1
  46. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation.js +1 -1
  47. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +1 -1
  48. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +1 -1
  49. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +2 -2
  50. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +1 -1
  51. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +1 -1
  52. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +3 -3
  53. package/bundle/packages/rln/node_modules/@noble/hashes/_assert.js +1 -1
  54. package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +2 -2
  55. package/bundle/packages/rln/node_modules/@noble/hashes/_u64.js +1 -1
  56. package/bundle/packages/rln/node_modules/@noble/hashes/cryptoBrowser.js +1 -1
  57. package/bundle/packages/rln/node_modules/@noble/hashes/esm/_assert.js +43 -0
  58. package/bundle/packages/rln/node_modules/@noble/hashes/esm/_sha2.js +116 -0
  59. package/bundle/packages/rln/node_modules/@noble/hashes/esm/hmac.js +79 -0
  60. package/bundle/packages/rln/node_modules/@noble/hashes/esm/sha256.js +126 -0
  61. package/bundle/packages/rln/node_modules/@noble/hashes/esm/utils.js +43 -0
  62. package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +2 -2
  63. package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +2 -2
  64. package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +3 -3
  65. package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +2 -2
  66. package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +3 -3
  67. package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +2 -2
  68. package/dist/.tsbuildinfo +1 -1
  69. package/dist/codec.test-utils.d.ts +36 -0
  70. package/dist/codec.test-utils.js +56 -0
  71. package/dist/codec.test-utils.js.map +1 -0
  72. package/dist/contract/abi.d.ts +21 -17
  73. package/dist/contract/abi.js +502 -248
  74. package/dist/contract/abi.js.map +1 -1
  75. package/dist/contract/constants.d.ts +23 -19
  76. package/dist/contract/constants.js +3 -3
  77. package/dist/contract/constants.js.map +1 -1
  78. package/dist/contract/errors.d.ts +30 -0
  79. package/dist/contract/errors.js +61 -0
  80. package/dist/contract/errors.js.map +1 -0
  81. package/dist/contract/rln_base_contract.d.ts +88 -0
  82. package/dist/contract/rln_base_contract.js +330 -0
  83. package/dist/contract/rln_base_contract.js.map +1 -0
  84. package/dist/contract/rln_contract.d.ts +19 -109
  85. package/dist/contract/rln_contract.js +80 -390
  86. package/dist/contract/rln_contract.js.map +1 -1
  87. package/dist/contract/test-setup.d.ts +26 -0
  88. package/dist/contract/test-setup.js +56 -0
  89. package/dist/contract/test-setup.js.map +1 -0
  90. package/dist/contract/test-utils.d.ts +39 -0
  91. package/dist/contract/test-utils.js +118 -0
  92. package/dist/contract/test-utils.js.map +1 -0
  93. package/dist/contract/types.d.ts +40 -0
  94. package/dist/contract/types.js +8 -0
  95. package/dist/contract/types.js.map +1 -0
  96. package/dist/create.js +1 -1
  97. package/dist/create.js.map +1 -1
  98. package/dist/credentials_manager.d.ts +44 -0
  99. package/dist/credentials_manager.js +197 -0
  100. package/dist/credentials_manager.js.map +1 -0
  101. package/dist/identity.d.ts +1 -0
  102. package/dist/identity.js +8 -0
  103. package/dist/identity.js.map +1 -1
  104. package/dist/index.d.ts +5 -2
  105. package/dist/index.js +4 -2
  106. package/dist/index.js.map +1 -1
  107. package/dist/keystore/keystore.d.ts +0 -1
  108. package/dist/keystore/keystore.js +20 -28
  109. package/dist/keystore/keystore.js.map +1 -1
  110. package/dist/keystore/types.d.ts +2 -1
  111. package/dist/rln.d.ts +9 -52
  112. package/dist/rln.js +54 -163
  113. package/dist/rln.js.map +1 -1
  114. package/dist/types.d.ts +27 -0
  115. package/dist/types.js +2 -0
  116. package/dist/types.js.map +1 -0
  117. package/dist/zerokit.d.ts +3 -3
  118. package/dist/zerokit.js +5 -5
  119. package/dist/zerokit.js.map +1 -1
  120. package/package.json +1 -1
  121. package/src/codec.test-utils.ts +80 -0
  122. package/src/contract/abi.ts +502 -248
  123. package/src/contract/constants.ts +3 -3
  124. package/src/contract/errors.ts +75 -0
  125. package/src/contract/rln_base_contract.ts +500 -0
  126. package/src/contract/rln_contract.ts +102 -619
  127. package/src/contract/test-setup.ts +86 -0
  128. package/src/contract/test-utils.ts +179 -0
  129. package/src/contract/types.ts +48 -0
  130. package/src/create.ts +1 -1
  131. package/src/credentials_manager.ts +282 -0
  132. package/src/identity.ts +9 -0
  133. package/src/index.ts +17 -2
  134. package/src/keystore/keystore.ts +32 -46
  135. package/src/keystore/types.ts +2 -1
  136. package/src/rln.ts +67 -258
  137. package/src/types.ts +31 -0
  138. package/src/zerokit.ts +3 -3
@@ -22,7 +22,7 @@ import { __exports as password } from '../../../../../../_virtual/password.js';
22
22
  });
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.decrypt = exports.verifyPassword = exports.create = exports.defaultAes128CtrModule = exports.defaultSha256Module = exports.defaultScryptModule = exports.defaultPbkdfModule = undefined;
25
+ exports.decrypt = exports.verifyPassword = exports.create = exports.defaultAes128CtrModule = exports.defaultSha256Module = exports.defaultScryptModule = exports.defaultPbkdfModule = void 0;
26
26
  const uuid_1 = require$$0;
27
27
  const kdf_1 = kdf;
28
28
  Object.defineProperty(exports, "defaultPbkdfModule", { enumerable: true, get: function () { return kdf_1.defaultPbkdfModule; } });
@@ -45,7 +45,7 @@ import { __exports as password } from '../../../../../../_virtual/password.js';
45
45
  * @param cipherMod cipher configuration module
46
46
  */
47
47
  function create(password, secret, pubkey, path, description = null, kdfMod = kdf_1.defaultPbkdfModule(), checksumMod = checksum_1.defaultSha256Module(), cipherMod = cipher_1.defaultAes128CtrModule()) {
48
- return __awaiter(this, undefined, undefined, function* () {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
49
  const encryptionKey = yield kdf_1.kdf(kdfMod, password_1.normalizePassword(password));
50
50
  const ciphertext = yield cipher_1.cipherEncrypt(cipherMod, encryptionKey.slice(0, 16), secret);
51
51
  return {
@@ -79,7 +79,7 @@ import { __exports as password } from '../../../../../../_virtual/password.js';
79
79
  * Verify the password of a keystore object
80
80
  */
81
81
  function verifyPassword(keystore, password) {
82
- return __awaiter(this, undefined, undefined, function* () {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
83
  const decryptionKey = yield kdf_1.kdf(keystore.crypto.kdf, password_1.normalizePassword(password));
84
84
  const ciphertext = utils_1.hexToBytes(keystore.crypto.cipher.message);
85
85
  return checksum_1.verifyChecksum(keystore.crypto.checksum, decryptionKey, ciphertext);
@@ -90,7 +90,7 @@ import { __exports as password } from '../../../../../../_virtual/password.js';
90
90
  * Decrypt a keystore, returns the secret key or throws on invalid password
91
91
  */
92
92
  function decrypt(keystore, password) {
93
- return __awaiter(this, undefined, undefined, function* () {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
94
  const decryptionKey = yield kdf_1.kdf(keystore.crypto.kdf, password_1.normalizePassword(password));
95
95
  const ciphertext = utils_1.hexToBytes(keystore.crypto.cipher.message);
96
96
  if (!(yield checksum_1.verifyChecksum(keystore.crypto.checksum, decryptionKey, ciphertext))) {
@@ -18,7 +18,7 @@ var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisAr
18
18
  });
19
19
  };
20
20
  Object.defineProperty(kdf$1, "__esModule", { value: true });
21
- var kdf_2 = kdf$1.kdf = kdf$1.defaultScryptModule = kdf$1.defaultPbkdfModule = undefined;
21
+ var kdf_2 = kdf$1.kdf = kdf$1.defaultScryptModule = kdf$1.defaultPbkdfModule = void 0;
22
22
  const random_1 = random;
23
23
  const pbkdf2_1 = pbkdf2;
24
24
  const scrypt_1 = scrypt;
@@ -51,7 +51,7 @@ function defaultScryptModule() {
51
51
  kdf$1.defaultScryptModule = defaultScryptModule;
52
52
  // kdf operations
53
53
  function kdf(mod, password) {
54
- return __awaiter(this, undefined, undefined, function* () {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
55
  if (mod.function === "pbkdf2") {
56
56
  return yield doPbkdf2(mod.params, password);
57
57
  }
@@ -65,12 +65,12 @@ function kdf(mod, password) {
65
65
  }
66
66
  kdf_2 = kdf$1.kdf = kdf;
67
67
  function doPbkdf2(params, password) {
68
- return __awaiter(this, undefined, undefined, function* () {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
69
  return pbkdf2_1.pbkdf2(password, utils_1.hexToBytes(params.salt), params.c, params.dklen, params.prf.slice(5));
70
70
  });
71
71
  }
72
72
  function doScrypt(params, password) {
73
- return __awaiter(this, undefined, undefined, function* () {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
74
  return scrypt_1.scrypt(password, utils_1.hexToBytes(params.salt), params.n, params.p, params.r, params.dklen);
75
75
  });
76
76
  }
@@ -2,7 +2,7 @@ import { __exports as password } from '../../../../../../_virtual/password.js';
2
2
  import { u as utilsExports } from '../node_modules/ethereum-cryptography/utils.js';
3
3
 
4
4
  Object.defineProperty(password, "__esModule", { value: true });
5
- var normalizePassword_1 = password.normalizePassword = undefined;
5
+ var normalizePassword_1 = password.normalizePassword = void 0;
6
6
  const utils_1 = utilsExports;
7
7
  function normalizePassword(password) {
8
8
  if (typeof password === "string") {
@@ -1,7 +1,7 @@
1
1
  import { __exports as schemaValidationGenerated } from '../../../../../../_virtual/schema-validation-generated.js';
2
2
 
3
3
  Object.defineProperty(schemaValidationGenerated, "__esModule", { value: true });
4
- schemaValidationGenerated.Keystore = undefined;
4
+ schemaValidationGenerated.Keystore = void 0;
5
5
  schemaValidationGenerated.Keystore = validate19;
6
6
  const pattern0 = new RegExp("^pbkdf2$", "u");
7
7
  const pattern1 = new RegExp("^hmac-sha256$", "u");
@@ -3,7 +3,7 @@ import './schema-validation-generated.js';
3
3
  import { __exports as schemaValidationGenerated } from '../../../../../../_virtual/schema-validation-generated.js';
4
4
 
5
5
  Object.defineProperty(schemaValidation, "__esModule", { value: true });
6
- schemaValidation.isValidKeystore = schemaValidation.validateKeystore = schemaValidation.schemaValidationErrors = undefined;
6
+ schemaValidation.isValidKeystore = schemaValidation.validateKeystore = schemaValidation.schemaValidationErrors = void 0;
7
7
  const schema_validation_generated_1 = schemaValidationGenerated;
8
8
  // Redeclare generated function with the proper type
9
9
  const _validateKeystore = schema_validation_generated_1.Keystore;
@@ -4,7 +4,7 @@ import { u as utilsExports } from './utils.js';
4
4
  import { __exports as cryptoBrowser } from '../../../../../../../_virtual/cryptoBrowser.js';
5
5
 
6
6
  Object.defineProperty(aes, "__esModule", { value: true });
7
- aes.decrypt = aes.encrypt = undefined;
7
+ aes.decrypt = aes.encrypt = void 0;
8
8
  const crypto_1 = cryptoBrowser;
9
9
  const utils_1 = utilsExports;
10
10
  function validateOpt(key, iv, mode) {
@@ -8,7 +8,7 @@ import { __exports as sha256 } from '../../../../../../../_virtual/sha2562.js';
8
8
  import { __exports as sha512 } from '../../../../../../../_virtual/sha512.js';
9
9
 
10
10
  Object.defineProperty(pbkdf2$1, "__esModule", { value: true });
11
- pbkdf2$1.pbkdf2Sync = pbkdf2$1.pbkdf2 = undefined;
11
+ pbkdf2$1.pbkdf2Sync = pbkdf2$1.pbkdf2 = void 0;
12
12
  const pbkdf2_1 = pbkdf2$2;
13
13
  const sha256_1 = sha256;
14
14
  const sha512_1 = sha512;
@@ -1,9 +1,9 @@
1
1
  import { __exports as random } from '../../../../../../../_virtual/random.js';
2
2
  import '../../../../@noble/hashes/utils.js';
3
- import { __exports as utils } from '../../../../../../../_virtual/utils.js';
3
+ import { __exports as utils } from '../../../../../../../_virtual/utils2.js';
4
4
 
5
5
  Object.defineProperty(random, "__esModule", { value: true });
6
- random.getRandomBytes = random.getRandomBytesSync = undefined;
6
+ random.getRandomBytes = random.getRandomBytesSync = void 0;
7
7
  const utils_1 = utils;
8
8
  function getRandomBytesSync(bytes) {
9
9
  return (0, utils_1.randomBytes)(bytes);
@@ -4,7 +4,7 @@ import { u as utilsExports } from './utils.js';
4
4
  import { __exports as scrypt$2 } from '../../../../../../../_virtual/scrypt2.js';
5
5
 
6
6
  Object.defineProperty(scrypt$1, "__esModule", { value: true });
7
- scrypt$1.scryptSync = scrypt$1.scrypt = undefined;
7
+ scrypt$1.scryptSync = scrypt$1.scrypt = void 0;
8
8
  const scrypt_1 = scrypt$2;
9
9
  const utils_1 = utilsExports;
10
10
  async function scrypt(password, salt, n, p, r, dkLen, onProgress) {
@@ -4,7 +4,7 @@ import { u as utilsExports } from './utils.js';
4
4
  import { __exports as sha256$1 } from '../../../../../../../_virtual/sha2562.js';
5
5
 
6
6
  Object.defineProperty(sha256, "__esModule", { value: true });
7
- sha256.sha256 = undefined;
7
+ sha256.sha256 = void 0;
8
8
  const sha256_1 = sha256$1;
9
9
  const utils_1 = utilsExports;
10
10
  sha256.sha256 = (0, utils_1.wrapHash)(sha256_1.sha256);
@@ -1,10 +1,10 @@
1
1
  import { commonjsGlobal } from '../../../../../../../_virtual/_commonjsHelpers.js';
2
2
  import { commonjsRequire } from '../../../../../../../_virtual/_commonjs-dynamic-modules.js';
3
- import { __module as utils } from '../../../../../../../_virtual/utils2.js';
3
+ import { __module as utils } from '../../../../../../../_virtual/utils.js';
4
4
  import '../../../../@noble/hashes/_assert.js';
5
5
  import '../../../../@noble/hashes/utils.js';
6
6
  import { __exports as _assert } from '../../../../../../../_virtual/_assert.js';
7
- import { __exports as utils$1 } from '../../../../../../../_virtual/utils.js';
7
+ import { __exports as utils$1 } from '../../../../../../../_virtual/utils2.js';
8
8
 
9
9
  utils.exports;
10
10
 
@@ -13,7 +13,7 @@ utils.exports;
13
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.crypto = exports.wrapHash = exports.equalsBytes = exports.hexToBytes = exports.bytesToUtf8 = exports.utf8ToBytes = exports.createView = exports.concatBytes = exports.toHex = exports.bytesToHex = exports.assertBytes = exports.assertBool = undefined;
16
+ exports.crypto = exports.wrapHash = exports.equalsBytes = exports.hexToBytes = exports.bytesToUtf8 = exports.utf8ToBytes = exports.createView = exports.concatBytes = exports.toHex = exports.bytesToHex = exports.assertBytes = exports.assertBool = void 0;
17
17
  // buf.toString('hex') -> toHex(buf)
18
18
  const _assert_1 = __importDefault(_assert);
19
19
  const utils_1 = utils$1;
@@ -1,7 +1,7 @@
1
1
  import { __exports as _assert } from '../../../../../_virtual/_assert.js';
2
2
 
3
3
  Object.defineProperty(_assert, "__esModule", { value: true });
4
- _assert.output = _assert.exists = _assert.hash = _assert.bytes = _assert.bool = _assert.number = undefined;
4
+ _assert.output = _assert.exists = _assert.hash = _assert.bytes = _assert.bool = _assert.number = void 0;
5
5
  function number(n) {
6
6
  if (!Number.isSafeInteger(n) || n < 0)
7
7
  throw new Error(`Wrong positive integer: ${n}`);
@@ -1,11 +1,11 @@
1
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';
4
5
  import { __exports as _assert } from '../../../../../_virtual/_assert.js';
5
- import { __exports as utils } from '../../../../../_virtual/utils.js';
6
6
 
7
7
  Object.defineProperty(_sha2, "__esModule", { value: true });
8
- _sha2.SHA2 = undefined;
8
+ _sha2.SHA2 = void 0;
9
9
  const _assert_js_1 = _assert;
10
10
  const utils_js_1 = utils;
11
11
  // Polyfill for Safari 14
@@ -2,7 +2,7 @@ import { __exports as _u64 } from '../../../../../_virtual/_u64.js';
2
2
 
3
3
  (function (exports) {
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.add = exports.toBig = exports.split = exports.fromBig = undefined;
5
+ exports.add = exports.toBig = exports.split = exports.fromBig = void 0;
6
6
  const U32_MASK64 = BigInt(2 ** 32 - 1);
7
7
  const _32n = BigInt(32);
8
8
  // We are not using BigUint64Array, because they are extremely slow as per 2022
@@ -1,7 +1,7 @@
1
1
  import { __exports as cryptoBrowser } from '../../../../../_virtual/cryptoBrowser.js';
2
2
 
3
3
  Object.defineProperty(cryptoBrowser, "__esModule", { value: true });
4
- cryptoBrowser.crypto = undefined;
4
+ cryptoBrowser.crypto = void 0;
5
5
  cryptoBrowser.crypto = {
6
6
  node: undefined,
7
7
  web: typeof self === 'object' && 'crypto' in self ? self.crypto : undefined,
@@ -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 };
@@ -0,0 +1,79 @@
1
+ import assert from './_assert.js';
2
+ import { Hash, toBytes } from './utils.js';
3
+
4
+ // HMAC (RFC 2104)
5
+ class HMAC extends Hash {
6
+ constructor(hash, _key) {
7
+ super();
8
+ this.finished = false;
9
+ this.destroyed = false;
10
+ assert.hash(hash);
11
+ const key = toBytes(_key);
12
+ this.iHash = hash.create();
13
+ if (typeof this.iHash.update !== 'function')
14
+ throw new TypeError('Expected instance of class which extends utils.Hash');
15
+ this.blockLen = this.iHash.blockLen;
16
+ this.outputLen = this.iHash.outputLen;
17
+ const blockLen = this.blockLen;
18
+ const pad = new Uint8Array(blockLen);
19
+ // blockLen can be bigger than outputLen
20
+ pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
21
+ for (let i = 0; i < pad.length; i++)
22
+ pad[i] ^= 0x36;
23
+ this.iHash.update(pad);
24
+ // By doing update (processing of first block) of outer hash here we can re-use it between multiple calls via clone
25
+ this.oHash = hash.create();
26
+ // Undo internal XOR && apply outer XOR
27
+ for (let i = 0; i < pad.length; i++)
28
+ pad[i] ^= 0x36 ^ 0x5c;
29
+ this.oHash.update(pad);
30
+ pad.fill(0);
31
+ }
32
+ update(buf) {
33
+ assert.exists(this);
34
+ this.iHash.update(buf);
35
+ return this;
36
+ }
37
+ digestInto(out) {
38
+ assert.exists(this);
39
+ assert.bytes(out, this.outputLen);
40
+ this.finished = true;
41
+ this.iHash.digestInto(out);
42
+ this.oHash.update(out);
43
+ this.oHash.digestInto(out);
44
+ this.destroy();
45
+ }
46
+ digest() {
47
+ const out = new Uint8Array(this.oHash.outputLen);
48
+ this.digestInto(out);
49
+ return out;
50
+ }
51
+ _cloneInto(to) {
52
+ // Create new instance without calling constructor since key already in state and we don't know it.
53
+ to || (to = Object.create(Object.getPrototypeOf(this), {}));
54
+ const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
55
+ to = to;
56
+ to.finished = finished;
57
+ to.destroyed = destroyed;
58
+ to.blockLen = blockLen;
59
+ to.outputLen = outputLen;
60
+ to.oHash = oHash._cloneInto(to.oHash);
61
+ to.iHash = iHash._cloneInto(to.iHash);
62
+ return to;
63
+ }
64
+ destroy() {
65
+ this.destroyed = true;
66
+ this.oHash.destroy();
67
+ this.iHash.destroy();
68
+ }
69
+ }
70
+ /**
71
+ * HMAC: RFC2104 message authentication code.
72
+ * @param hash - function that would be used e.g. sha256
73
+ * @param key - message key
74
+ * @param message - message data
75
+ */
76
+ const hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
77
+ hmac.create = (hash, key) => new HMAC(hash, key);
78
+
79
+ export { hmac };
@@ -0,0 +1,126 @@
1
+ import { SHA2 } from './_sha2.js';
2
+ import { wrapConstructor, rotr } from './utils.js';
3
+
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)
10
+ // prettier-ignore
11
+ const SHA256_K = new Uint32Array([
12
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
13
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
14
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
15
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
16
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
17
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
18
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
19
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
20
+ ]);
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);
32
+ // We cannot use array here since array allows indexing by variable
33
+ // which means optimizer/compiler cannot use registers.
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;
42
+ }
43
+ get() {
44
+ const { A, B, C, D, E, F, G, H } = this;
45
+ return [A, B, C, D, E, F, G, H];
46
+ }
47
+ // prettier-ignore
48
+ set(A, B, C, D, E, F, G, H) {
49
+ this.A = A | 0;
50
+ this.B = B | 0;
51
+ this.C = C | 0;
52
+ this.D = D | 0;
53
+ this.E = E | 0;
54
+ this.F = F | 0;
55
+ this.G = G | 0;
56
+ this.H = H | 0;
57
+ }
58
+ process(view, offset) {
59
+ // Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
60
+ for (let i = 0; i < 16; i++, offset += 4)
61
+ SHA256_W[i] = view.getUint32(offset, false);
62
+ for (let i = 16; i < 64; i++) {
63
+ const W15 = SHA256_W[i - 15];
64
+ const W2 = SHA256_W[i - 2];
65
+ const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ (W15 >>> 3);
66
+ const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ (W2 >>> 10);
67
+ SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
68
+ }
69
+ // Compression function main loop, 64 rounds
70
+ let { A, B, C, D, E, F, G, H } = this;
71
+ for (let i = 0; i < 64; i++) {
72
+ const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
73
+ const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
74
+ const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
75
+ const T2 = (sigma0 + Maj(A, B, C)) | 0;
76
+ H = G;
77
+ G = F;
78
+ F = E;
79
+ E = (D + T1) | 0;
80
+ D = C;
81
+ C = B;
82
+ B = A;
83
+ A = (T1 + T2) | 0;
84
+ }
85
+ // Add the compressed chunk to the current hash value
86
+ A = (A + this.A) | 0;
87
+ B = (B + this.B) | 0;
88
+ C = (C + this.C) | 0;
89
+ D = (D + this.D) | 0;
90
+ E = (E + this.E) | 0;
91
+ F = (F + this.F) | 0;
92
+ G = (G + this.G) | 0;
93
+ H = (H + this.H) | 0;
94
+ this.set(A, B, C, D, E, F, G, H);
95
+ }
96
+ roundClean() {
97
+ SHA256_W.fill(0);
98
+ }
99
+ destroy() {
100
+ this.set(0, 0, 0, 0, 0, 0, 0, 0);
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;
117
+ }
118
+ }
119
+ /**
120
+ * SHA2-256 hash function
121
+ * @param message - data that would be hashed
122
+ */
123
+ const sha256 = wrapConstructor(() => new SHA256());
124
+ wrapConstructor(() => new SHA224());
125
+
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,12 +1,12 @@
1
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';
4
5
  import { __exports as _assert } from '../../../../../_virtual/_assert.js';
5
- import { __exports as utils } from '../../../../../_virtual/utils.js';
6
6
 
7
7
  (function (exports) {
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.hmac = undefined;
9
+ exports.hmac = void 0;
10
10
  const _assert_js_1 = _assert;
11
11
  const utils_js_1 = utils;
12
12
  // HMAC (RFC 2104)