@ohos-ports/crypto 0.0.0-stage → 0.3.1-beta.1

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 (121) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +60 -2
  3. package/dist/bech32.d.ts +53 -0
  4. package/dist/bech32.js +187 -0
  5. package/dist/blake2b.d.ts +7 -0
  6. package/dist/blake2b.js +213 -0
  7. package/dist/bls12_318.d.ts +48 -0
  8. package/dist/bls12_318.js +268 -0
  9. package/dist/ed25519.d.ts +55 -0
  10. package/dist/ed25519.js +721 -0
  11. package/dist/hasGlobalWebCrypto.d.ts +1 -0
  12. package/dist/hasGlobalWebCrypto.js +21 -0
  13. package/dist/hmacSHA512.d.ts +6 -0
  14. package/dist/hmacSHA512.js +14 -0
  15. package/dist/index.d.ts +14 -0
  16. package/dist/index.js +30 -0
  17. package/dist/keccak.d.ts +4 -0
  18. package/dist/keccak.js +43 -0
  19. package/dist/kes/constants.d.ts +2 -0
  20. package/dist/kes/constants.js +5 -0
  21. package/dist/kes/index.d.ts +0 -0
  22. package/dist/kes/index.js +0 -0
  23. package/dist/kes/macro/sum_kes.d.ts +15 -0
  24. package/dist/kes/macro/sum_kes.js +9 -0
  25. package/dist/kes/singleKes.d.ts +0 -0
  26. package/dist/kes/singleKes.js +0 -0
  27. package/dist/noble/_assert.d.ts +23 -0
  28. package/dist/noble/_assert.js +55 -0
  29. package/dist/noble/_md.d.ts +29 -0
  30. package/dist/noble/_md.js +170 -0
  31. package/dist/noble/_shortw_utils.d.ts +61 -0
  32. package/dist/noble/_shortw_utils.js +63 -0
  33. package/dist/noble/_u64.d.ts +28 -0
  34. package/dist/noble/_u64.js +116 -0
  35. package/dist/noble/abstract/bls.d.ts +119 -0
  36. package/dist/noble/abstract/bls.js +334 -0
  37. package/dist/noble/abstract/curve.d.ts +83 -0
  38. package/dist/noble/abstract/curve.js +319 -0
  39. package/dist/noble/abstract/edwards.d.ts +85 -0
  40. package/dist/noble/abstract/edwards.js +508 -0
  41. package/dist/noble/abstract/hash-to-curve.d.ts +57 -0
  42. package/dist/noble/abstract/hash-to-curve.js +220 -0
  43. package/dist/noble/abstract/modular.d.ts +122 -0
  44. package/dist/noble/abstract/modular.js +455 -0
  45. package/dist/noble/abstract/montgomery.d.ts +28 -0
  46. package/dist/noble/abstract/montgomery.js +172 -0
  47. package/dist/noble/abstract/utils.d.ts +106 -0
  48. package/dist/noble/abstract/utils.js +442 -0
  49. package/dist/noble/bls12_381.d.ts +95 -0
  50. package/dist/noble/bls12_381.js +1434 -0
  51. package/dist/noble/crypto.d.ts +1 -0
  52. package/dist/noble/crypto.js +4 -0
  53. package/dist/noble/curves/curve.d.ts +69 -0
  54. package/dist/noble/curves/curve.js +167 -0
  55. package/dist/noble/curves/modular.d.ts +122 -0
  56. package/dist/noble/curves/modular.js +442 -0
  57. package/dist/noble/curves/utils.d.ts +93 -0
  58. package/dist/noble/curves/utils.js +385 -0
  59. package/dist/noble/curves/weierstrass.d.ts +240 -0
  60. package/dist/noble/curves/weierstrass.js +1178 -0
  61. package/dist/noble/ed25519.d.ts +100 -0
  62. package/dist/noble/ed25519.js +494 -0
  63. package/dist/noble/hmac.d.ts +25 -0
  64. package/dist/noble/hmac.js +101 -0
  65. package/dist/noble/index.d.ts +2 -0
  66. package/dist/noble/index.js +20 -0
  67. package/dist/noble/keccak.d.ts +58 -0
  68. package/dist/noble/keccak.js +289 -0
  69. package/dist/noble/ripemd_160.d.ts +20 -0
  70. package/dist/noble/ripemd_160.js +147 -0
  71. package/dist/noble/secp256k1.d.ts +98 -0
  72. package/dist/noble/secp256k1.js +309 -0
  73. package/dist/noble/sha256.d.ts +34 -0
  74. package/dist/noble/sha256.js +146 -0
  75. package/dist/noble/sha512.d.ts +66 -0
  76. package/dist/noble/sha512.js +301 -0
  77. package/dist/noble/utils.d.ts +90 -0
  78. package/dist/noble/utils.js +278 -0
  79. package/dist/ripemd_160.d.ts +1 -0
  80. package/dist/ripemd_160.js +23 -0
  81. package/dist/rust_vrf_reimpl/curves.d.ts +162 -0
  82. package/dist/rust_vrf_reimpl/curves.js +4225 -0
  83. package/dist/rust_vrf_reimpl/vrf03.d.ts +60 -0
  84. package/dist/rust_vrf_reimpl/vrf03.js +373 -0
  85. package/dist/rust_vrf_reimpl/vrf10.d.ts +73 -0
  86. package/dist/rust_vrf_reimpl/vrf10.js +468 -0
  87. package/dist/rust_vrf_reimpl/vrf10_batch.d.ts +53 -0
  88. package/dist/rust_vrf_reimpl/vrf10_batch.js +245 -0
  89. package/dist/secp256k1.d.ts +4 -0
  90. package/dist/secp256k1.js +33 -0
  91. package/dist/sha2_256.d.ts +16 -0
  92. package/dist/sha2_256.js +403 -0
  93. package/dist/sha2_512.d.ts +16 -0
  94. package/dist/sha2_512.js +256 -0
  95. package/dist/sha3.d.ts +17 -0
  96. package/dist/sha3.js +181 -0
  97. package/dist/types.d.ts +26 -0
  98. package/dist/types.js +120 -0
  99. package/dist/utils/assert.d.ts +3 -0
  100. package/dist/utils/assert.js +55 -0
  101. package/dist/utils/base32.d.ts +5 -0
  102. package/dist/utils/base32.js +52 -0
  103. package/dist/utils/bigintToBuffer.d.ts +1 -0
  104. package/dist/utils/bigintToBuffer.js +27 -0
  105. package/dist/utils/bytesToHex.d.ts +2 -0
  106. package/dist/utils/bytesToHex.js +15 -0
  107. package/dist/utils/getRandomValues.d.ts +4 -0
  108. package/dist/utils/getRandomValues.js +12 -0
  109. package/dist/utils/hexToBytes.d.ts +2 -0
  110. package/dist/utils/hexToBytes.js +14 -0
  111. package/dist/utils/index.d.ts +3 -0
  112. package/dist/utils/index.js +19 -0
  113. package/dist/utils/positiveMod.d.ts +1 -0
  114. package/dist/utils/positiveMod.js +11 -0
  115. package/dist/utils/promisifySync.d.ts +0 -0
  116. package/dist/utils/promisifySync.js +0 -0
  117. package/dist/utils/rotr32.d.ts +2 -0
  118. package/dist/utils/rotr32.js +7 -0
  119. package/dist/vrf.d.ts +74 -0
  120. package/dist/vrf.js +286 -0
  121. package/package.json +49 -4
@@ -0,0 +1,301 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }) : function(o, v) {
31
+ o["default"] = v;
32
+ });
33
+ var __importStar = (this && this.__importStar) || function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ var __read = (this && this.__read) || function (o, n) {
41
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
42
+ if (!m) return o;
43
+ var i = m.call(o), r, ar = [], e;
44
+ try {
45
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
46
+ }
47
+ catch (error) { e = { error: error }; }
48
+ finally {
49
+ try {
50
+ if (r && !r.done && (m = i["return"])) m.call(i);
51
+ }
52
+ finally { if (e) throw e.error; }
53
+ }
54
+ return ar;
55
+ };
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ exports.sha384 = exports.sha512_256 = exports.sha512_224 = exports.sha512 = exports.SHA512 = void 0;
58
+ var _md_1 = require("./_md.js");
59
+ var u64 = __importStar(require("./_u64.js"));
60
+ var utils_1 = require("./utils.js");
61
+ // Round contants (first 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409):
62
+ // prettier-ignore
63
+ var _a = __read(/* @__PURE__ */ (function () { return u64.split([
64
+ '0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',
65
+ '0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',
66
+ '0xd807aa98a3030242', '0x12835b0145706fbe', '0x243185be4ee4b28c', '0x550c7dc3d5ffb4e2',
67
+ '0x72be5d74f27b896f', '0x80deb1fe3b1696b1', '0x9bdc06a725c71235', '0xc19bf174cf692694',
68
+ '0xe49b69c19ef14ad2', '0xefbe4786384f25e3', '0x0fc19dc68b8cd5b5', '0x240ca1cc77ac9c65',
69
+ '0x2de92c6f592b0275', '0x4a7484aa6ea6e483', '0x5cb0a9dcbd41fbd4', '0x76f988da831153b5',
70
+ '0x983e5152ee66dfab', '0xa831c66d2db43210', '0xb00327c898fb213f', '0xbf597fc7beef0ee4',
71
+ '0xc6e00bf33da88fc2', '0xd5a79147930aa725', '0x06ca6351e003826f', '0x142929670a0e6e70',
72
+ '0x27b70a8546d22ffc', '0x2e1b21385c26c926', '0x4d2c6dfc5ac42aed', '0x53380d139d95b3df',
73
+ '0x650a73548baf63de', '0x766a0abb3c77b2a8', '0x81c2c92e47edaee6', '0x92722c851482353b',
74
+ '0xa2bfe8a14cf10364', '0xa81a664bbc423001', '0xc24b8b70d0f89791', '0xc76c51a30654be30',
75
+ '0xd192e819d6ef5218', '0xd69906245565a910', '0xf40e35855771202a', '0x106aa07032bbd1b8',
76
+ '0x19a4c116b8d2d0c8', '0x1e376c085141ab53', '0x2748774cdf8eeb99', '0x34b0bcb5e19b48a8',
77
+ '0x391c0cb3c5c95a63', '0x4ed8aa4ae3418acb', '0x5b9cca4f7763e373', '0x682e6ff3d6b2b8a3',
78
+ '0x748f82ee5defb2fc', '0x78a5636f43172f60', '0x84c87814a1f0ab72', '0x8cc702081a6439ec',
79
+ '0x90befffa23631e28', '0xa4506cebde82bde9', '0xbef9a3f7b2c67915', '0xc67178f2e372532b',
80
+ '0xca273eceea26619c', '0xd186b8c721c0c207', '0xeada7dd6cde0eb1e', '0xf57d4f7fee6ed178',
81
+ '0x06f067aa72176fba', '0x0a637dc5a2c898a6', '0x113f9804bef90dae', '0x1b710b35131c471b',
82
+ '0x28db77f523047d84', '0x32caab7b40c72493', '0x3c9ebe0a15c9bebc', '0x431d67c49c100d4c',
83
+ '0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'
84
+ ].map(function (n) { return BigInt(n); })); })(), 2), SHA512_Kh = _a[0], SHA512_Kl = _a[1];
85
+ // Temporary buffer, not used to store anything between runs
86
+ var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
87
+ var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
88
+ var SHA512 = /** @class */ (function (_super) {
89
+ __extends(SHA512, _super);
90
+ function SHA512() {
91
+ var _this = _super.call(this, 128, 64, 16, false) || this;
92
+ // We cannot use array here since array allows indexing by variable which means optimizer/compiler cannot use registers.
93
+ // Also looks cleaner and easier to verify with spec.
94
+ // Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
95
+ // h -- high 32 bits, l -- low 32 bits
96
+ _this.Ah = 0x6a09e667 | 0;
97
+ _this.Al = 0xf3bcc908 | 0;
98
+ _this.Bh = 0xbb67ae85 | 0;
99
+ _this.Bl = 0x84caa73b | 0;
100
+ _this.Ch = 0x3c6ef372 | 0;
101
+ _this.Cl = 0xfe94f82b | 0;
102
+ _this.Dh = 0xa54ff53a | 0;
103
+ _this.Dl = 0x5f1d36f1 | 0;
104
+ _this.Eh = 0x510e527f | 0;
105
+ _this.El = 0xade682d1 | 0;
106
+ _this.Fh = 0x9b05688c | 0;
107
+ _this.Fl = 0x2b3e6c1f | 0;
108
+ _this.Gh = 0x1f83d9ab | 0;
109
+ _this.Gl = 0xfb41bd6b | 0;
110
+ _this.Hh = 0x5be0cd19 | 0;
111
+ _this.Hl = 0x137e2179 | 0;
112
+ return _this;
113
+ }
114
+ // prettier-ignore
115
+ SHA512.prototype.get = function () {
116
+ var _a = this, Ah = _a.Ah, Al = _a.Al, Bh = _a.Bh, Bl = _a.Bl, Ch = _a.Ch, Cl = _a.Cl, Dh = _a.Dh, Dl = _a.Dl, Eh = _a.Eh, El = _a.El, Fh = _a.Fh, Fl = _a.Fl, Gh = _a.Gh, Gl = _a.Gl, Hh = _a.Hh, Hl = _a.Hl;
117
+ return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
118
+ };
119
+ // prettier-ignore
120
+ SHA512.prototype.set = function (Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
121
+ this.Ah = Ah | 0;
122
+ this.Al = Al | 0;
123
+ this.Bh = Bh | 0;
124
+ this.Bl = Bl | 0;
125
+ this.Ch = Ch | 0;
126
+ this.Cl = Cl | 0;
127
+ this.Dh = Dh | 0;
128
+ this.Dl = Dl | 0;
129
+ this.Eh = Eh | 0;
130
+ this.El = El | 0;
131
+ this.Fh = Fh | 0;
132
+ this.Fl = Fl | 0;
133
+ this.Gh = Gh | 0;
134
+ this.Gl = Gl | 0;
135
+ this.Hh = Hh | 0;
136
+ this.Hl = Hl | 0;
137
+ };
138
+ SHA512.prototype.process = function (view, offset) {
139
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
140
+ // Extend the first 16 words into the remaining 64 words w[16..79] of the message schedule array
141
+ for (var i = 0; i < 16; i++, offset += 4) {
142
+ SHA512_W_H[i] = view.getUint32(offset);
143
+ SHA512_W_L[i] = view.getUint32((offset += 4));
144
+ }
145
+ for (var i = 16; i < 80; i++) {
146
+ // s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7)
147
+ var W15h = SHA512_W_H[i - 15] | 0;
148
+ var W15l = SHA512_W_L[i - 15] | 0;
149
+ var s0h = u64.rotrSH(W15h, W15l, 1) ^ u64.rotrSH(W15h, W15l, 8) ^ u64.shrSH(W15h, W15l, 7);
150
+ var s0l = u64.rotrSL(W15h, W15l, 1) ^ u64.rotrSL(W15h, W15l, 8) ^ u64.shrSL(W15h, W15l, 7);
151
+ // s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6)
152
+ var W2h = SHA512_W_H[i - 2] | 0;
153
+ var W2l = SHA512_W_L[i - 2] | 0;
154
+ var s1h = u64.rotrSH(W2h, W2l, 19) ^ u64.rotrBH(W2h, W2l, 61) ^ u64.shrSH(W2h, W2l, 6);
155
+ var s1l = u64.rotrSL(W2h, W2l, 19) ^ u64.rotrBL(W2h, W2l, 61) ^ u64.shrSL(W2h, W2l, 6);
156
+ // SHA256_W[i] = s0 + s1 + SHA256_W[i - 7] + SHA256_W[i - 16];
157
+ var SUMl = u64.add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
158
+ var SUMh = u64.add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
159
+ SHA512_W_H[i] = SUMh | 0;
160
+ SHA512_W_L[i] = SUMl | 0;
161
+ }
162
+ var _k = this, Ah = _k.Ah, Al = _k.Al, Bh = _k.Bh, Bl = _k.Bl, Ch = _k.Ch, Cl = _k.Cl, Dh = _k.Dh, Dl = _k.Dl, Eh = _k.Eh, El = _k.El, Fh = _k.Fh, Fl = _k.Fl, Gh = _k.Gh, Gl = _k.Gl, Hh = _k.Hh, Hl = _k.Hl;
163
+ // Compression function main loop, 80 rounds
164
+ for (var i = 0; i < 80; i++) {
165
+ // S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41)
166
+ var sigma1h = u64.rotrSH(Eh, El, 14) ^ u64.rotrSH(Eh, El, 18) ^ u64.rotrBH(Eh, El, 41);
167
+ var sigma1l = u64.rotrSL(Eh, El, 14) ^ u64.rotrSL(Eh, El, 18) ^ u64.rotrBL(Eh, El, 41);
168
+ //const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
169
+ var CHIh = (Eh & Fh) ^ (~Eh & Gh);
170
+ var CHIl = (El & Fl) ^ (~El & Gl);
171
+ // T1 = H + sigma1 + Chi(E, F, G) + SHA512_K[i] + SHA512_W[i]
172
+ // prettier-ignore
173
+ var T1ll = u64.add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
174
+ var T1h = u64.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
175
+ var T1l = T1ll | 0;
176
+ // S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39)
177
+ var sigma0h = u64.rotrSH(Ah, Al, 28) ^ u64.rotrBH(Ah, Al, 34) ^ u64.rotrBH(Ah, Al, 39);
178
+ var sigma0l = u64.rotrSL(Ah, Al, 28) ^ u64.rotrBL(Ah, Al, 34) ^ u64.rotrBL(Ah, Al, 39);
179
+ var MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch);
180
+ var MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl);
181
+ Hh = Gh | 0;
182
+ Hl = Gl | 0;
183
+ Gh = Fh | 0;
184
+ Gl = Fl | 0;
185
+ Fh = Eh | 0;
186
+ Fl = El | 0;
187
+ (_a = u64.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0), Eh = _a.h, El = _a.l);
188
+ Dh = Ch | 0;
189
+ Dl = Cl | 0;
190
+ Ch = Bh | 0;
191
+ Cl = Bl | 0;
192
+ Bh = Ah | 0;
193
+ Bl = Al | 0;
194
+ var All = u64.add3L(T1l, sigma0l, MAJl);
195
+ Ah = u64.add3H(All, T1h, sigma0h, MAJh);
196
+ Al = All | 0;
197
+ }
198
+ // Add the compressed chunk to the current hash value
199
+ (_b = u64.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0), Ah = _b.h, Al = _b.l);
200
+ (_c = u64.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0), Bh = _c.h, Bl = _c.l);
201
+ (_d = u64.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0), Ch = _d.h, Cl = _d.l);
202
+ (_e = u64.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0), Dh = _e.h, Dl = _e.l);
203
+ (_f = u64.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0), Eh = _f.h, El = _f.l);
204
+ (_g = u64.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0), Fh = _g.h, Fl = _g.l);
205
+ (_h = u64.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0), Gh = _h.h, Gl = _h.l);
206
+ (_j = u64.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0), Hh = _j.h, Hl = _j.l);
207
+ this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
208
+ };
209
+ SHA512.prototype.roundClean = function () {
210
+ SHA512_W_H.fill(0);
211
+ SHA512_W_L.fill(0);
212
+ };
213
+ SHA512.prototype.destroy = function () {
214
+ this.buffer.fill(0);
215
+ this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
216
+ };
217
+ return SHA512;
218
+ }(_md_1.HashMD));
219
+ exports.SHA512 = SHA512;
220
+ var SHA512_224 = /** @class */ (function (_super) {
221
+ __extends(SHA512_224, _super);
222
+ function SHA512_224() {
223
+ var _this = _super.call(this) || this;
224
+ // h -- high 32 bits, l -- low 32 bits
225
+ _this.Ah = 0x8c3d37c8 | 0;
226
+ _this.Al = 0x19544da2 | 0;
227
+ _this.Bh = 0x73e19966 | 0;
228
+ _this.Bl = 0x89dcd4d6 | 0;
229
+ _this.Ch = 0x1dfab7ae | 0;
230
+ _this.Cl = 0x32ff9c82 | 0;
231
+ _this.Dh = 0x679dd514 | 0;
232
+ _this.Dl = 0x582f9fcf | 0;
233
+ _this.Eh = 0x0f6d2b69 | 0;
234
+ _this.El = 0x7bd44da8 | 0;
235
+ _this.Fh = 0x77e36f73 | 0;
236
+ _this.Fl = 0x04c48942 | 0;
237
+ _this.Gh = 0x3f9d85a8 | 0;
238
+ _this.Gl = 0x6a1d36c8 | 0;
239
+ _this.Hh = 0x1112e6ad | 0;
240
+ _this.Hl = 0x91d692a1 | 0;
241
+ _this.outputLen = 28;
242
+ return _this;
243
+ }
244
+ return SHA512_224;
245
+ }(SHA512));
246
+ var SHA512_256 = /** @class */ (function (_super) {
247
+ __extends(SHA512_256, _super);
248
+ function SHA512_256() {
249
+ var _this = _super.call(this) || this;
250
+ // h -- high 32 bits, l -- low 32 bits
251
+ _this.Ah = 0x22312194 | 0;
252
+ _this.Al = 0xfc2bf72c | 0;
253
+ _this.Bh = 0x9f555fa3 | 0;
254
+ _this.Bl = 0xc84c64c2 | 0;
255
+ _this.Ch = 0x2393b86b | 0;
256
+ _this.Cl = 0x6f53b151 | 0;
257
+ _this.Dh = 0x96387719 | 0;
258
+ _this.Dl = 0x5940eabd | 0;
259
+ _this.Eh = 0x96283ee2 | 0;
260
+ _this.El = 0xa88effe3 | 0;
261
+ _this.Fh = 0xbe5e1e25 | 0;
262
+ _this.Fl = 0x53863992 | 0;
263
+ _this.Gh = 0x2b0199fc | 0;
264
+ _this.Gl = 0x2c85b8aa | 0;
265
+ _this.Hh = 0x0eb72ddc | 0;
266
+ _this.Hl = 0x81c52ca2 | 0;
267
+ _this.outputLen = 32;
268
+ return _this;
269
+ }
270
+ return SHA512_256;
271
+ }(SHA512));
272
+ var SHA384 = /** @class */ (function (_super) {
273
+ __extends(SHA384, _super);
274
+ function SHA384() {
275
+ var _this = _super.call(this) || this;
276
+ // h -- high 32 bits, l -- low 32 bits
277
+ _this.Ah = 0xcbbb9d5d | 0;
278
+ _this.Al = 0xc1059ed8 | 0;
279
+ _this.Bh = 0x629a292a | 0;
280
+ _this.Bl = 0x367cd507 | 0;
281
+ _this.Ch = 0x9159015a | 0;
282
+ _this.Cl = 0x3070dd17 | 0;
283
+ _this.Dh = 0x152fecd8 | 0;
284
+ _this.Dl = 0xf70e5939 | 0;
285
+ _this.Eh = 0x67332667 | 0;
286
+ _this.El = 0xffc00b31 | 0;
287
+ _this.Fh = 0x8eb44a87 | 0;
288
+ _this.Fl = 0x68581511 | 0;
289
+ _this.Gh = 0xdb0c2e0d | 0;
290
+ _this.Gl = 0x64f98fa7 | 0;
291
+ _this.Hh = 0x47b5481d | 0;
292
+ _this.Hl = 0xbefa4fa4 | 0;
293
+ _this.outputLen = 48;
294
+ return _this;
295
+ }
296
+ return SHA384;
297
+ }(SHA512));
298
+ exports.sha512 = (0, utils_1.wrapConstructor)(function () { return new SHA512(); });
299
+ exports.sha512_224 = (0, utils_1.wrapConstructor)(function () { return new SHA512_224(); });
300
+ exports.sha512_256 = (0, utils_1.wrapConstructor)(function () { return new SHA512_256(); });
301
+ exports.sha384 = (0, utils_1.wrapConstructor)(function () { return new SHA384(); });
@@ -0,0 +1,90 @@
1
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2
+ export type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array | Uint16Array | Int16Array | Uint32Array | Int32Array;
3
+ export declare const u8: (arr: TypedArray) => Uint8Array;
4
+ export declare const u32: (arr: TypedArray) => Uint32Array;
5
+ export declare const createView: (arr: TypedArray) => DataView;
6
+ export declare const rotr: (word: number, shift: number) => number;
7
+ export declare const rotl: (word: number, shift: number) => number;
8
+ export declare const isLE: boolean;
9
+ export declare const byteSwap: (word: number) => number;
10
+ export declare const byteSwapIfBE: (n: number) => number;
11
+ export declare function byteSwap32(arr: Uint32Array): void;
12
+ /**
13
+ * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
14
+ */
15
+ export declare function bytesToHex(bytes: Uint8Array): string;
16
+ /**
17
+ * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
18
+ */
19
+ export declare function hexToBytes(hex: string): Uint8Array;
20
+ export declare const nextTick: () => Promise<void>;
21
+ export declare function asyncLoop(iters: number, tick: number, cb: (i: number) => void): Promise<void>;
22
+ export type Input = Uint8Array | string;
23
+ /**
24
+ * Normalizes (non-hex) string or Uint8Array to Uint8Array.
25
+ * Warning: when Uint8Array is passed, it would NOT get copied.
26
+ * Keep in mind for future mutable operations.
27
+ */
28
+ export declare function toBytes(data: Input): Uint8Array;
29
+ /**
30
+ * Copies several Uint8Arrays into one.
31
+ */
32
+ export declare function concatBytes(...arrays: Uint8Array[]): Uint8Array;
33
+ export declare abstract class Hash<T extends Hash<T>> {
34
+ abstract blockLen: number;
35
+ abstract outputLen: number;
36
+ abstract update(buf: Input): this;
37
+ abstract digestInto(buf: Uint8Array): void;
38
+ abstract digest(): Uint8Array;
39
+ /**
40
+ * Resets internal state. Makes Hash instance unusable.
41
+ * Reset is impossible for keyed hashes if key is consumed into state. If digest is not consumed
42
+ * by user, they will need to manually call `destroy()` when zeroing is necessary.
43
+ */
44
+ abstract destroy(): void;
45
+ /**
46
+ * Clones hash instance. Unsafe: doesn't check whether `to` is valid. Can be used as `clone()`
47
+ * when no options are passed.
48
+ * Reasons to use `_cloneInto` instead of clone: 1) performance 2) reuse instance => all internal
49
+ * buffers are overwritten => causes buffer overwrite which is used for digest in some cases.
50
+ * There are no guarantees for clean-up because it's impossible in JS.
51
+ */
52
+ abstract _cloneInto(to?: T): T;
53
+ clone(): T;
54
+ }
55
+ /**
56
+ * XOF: streaming API to read digest in chunks.
57
+ * Same as 'squeeze' in keccak/k12 and 'seek' in blake3, but more generic name.
58
+ * When hash used in XOF mode it is up to user to call '.destroy' afterwards, since we cannot
59
+ * destroy state, next call can require more bytes.
60
+ */
61
+ export type HashXOF<T extends Hash<T>> = Hash<T> & {
62
+ xof(bytes: number): Uint8Array;
63
+ xofInto(buf: Uint8Array): Uint8Array;
64
+ };
65
+ type EmptyObj = {};
66
+ export declare function checkOpts<T1 extends EmptyObj, T2 extends EmptyObj>(defaults: T1, opts?: T2): T1 & T2;
67
+ export type CHash = ReturnType<typeof wrapConstructor>;
68
+ export declare function wrapConstructor<T extends Hash<T>>(hashCons: () => Hash<T>): {
69
+ (msg: Input): Uint8Array;
70
+ outputLen: number;
71
+ blockLen: number;
72
+ create(): Hash<T>;
73
+ };
74
+ export declare function wrapConstructorWithOpts<H extends Hash<H>, T extends Object>(hashCons: (opts?: T) => Hash<H>): {
75
+ (msg: Input, opts?: T): Uint8Array;
76
+ outputLen: number;
77
+ blockLen: number;
78
+ create(opts: T): Hash<H>;
79
+ };
80
+ export declare function wrapXOFConstructorWithOpts<H extends HashXOF<H>, T extends Object>(hashCons: (opts?: T) => HashXOF<H>): {
81
+ (msg: Input, opts?: T): Uint8Array;
82
+ outputLen: number;
83
+ blockLen: number;
84
+ create(opts: T): HashXOF<H>;
85
+ };
86
+ /**
87
+ * Secure PRNG. Uses `crypto.getRandomValues`, which defers to OS.
88
+ */
89
+ export declare function randomBytes(bytesLength?: number): Uint8Array;
90
+ export {};
@@ -0,0 +1,278 @@
1
+ "use strict";
2
+ /*
3
+ THIS IMPLEMENTATION WAS TAKEN FROM `@noble/hashes`
4
+
5
+ original source: https://github.com/paulmillr/noble-hashes/blob/6ae82e75d4c354d53a488e95b1bfe9cba90bd6ff/src/utils.ts#L1
6
+
7
+ it was modified and adapted to this repository to re-use already defined stuff
8
+
9
+ the main reason for copying over and not using as dependency is because of different target in the `tsconfig.json`
10
+
11
+ `@noble/hashes` targets es2020, which tends to cause problems with some other (older) packages sometimes
12
+
13
+ this repo targets ES5+
14
+ */
15
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ var __generator = (this && this.__generator) || function (thisArg, body) {
26
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
27
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
+ function verb(n) { return function (v) { return step([n, v]); }; }
29
+ function step(op) {
30
+ if (f) throw new TypeError("Generator is already executing.");
31
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
32
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
33
+ if (y = 0, t) op = [op[0] & 2, t.value];
34
+ switch (op[0]) {
35
+ case 0: case 1: t = op; break;
36
+ case 4: _.label++; return { value: op[1], done: false };
37
+ case 5: _.label++; y = op[1]; op = [0]; continue;
38
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
+ default:
40
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
+ if (t[2]) _.ops.pop();
45
+ _.trys.pop(); continue;
46
+ }
47
+ op = body.call(thisArg, _);
48
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
+ }
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.randomBytes = exports.wrapXOFConstructorWithOpts = exports.wrapConstructorWithOpts = exports.wrapConstructor = exports.checkOpts = exports.Hash = exports.concatBytes = exports.toBytes = exports.asyncLoop = exports.nextTick = exports.hexToBytes = exports.bytesToHex = exports.byteSwap32 = exports.byteSwapIfBE = exports.byteSwap = exports.isLE = exports.rotl = exports.rotr = exports.createView = exports.u32 = exports.u8 = void 0;
54
+ var uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
55
+ var assert_1 = require("../utils/assert.js");
56
+ var crypto_1 = require("./crypto.js");
57
+ // Cast array to different type
58
+ var u8 = function (arr) { return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength); };
59
+ exports.u8 = u8;
60
+ var u32 = function (arr) {
61
+ return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
62
+ };
63
+ exports.u32 = u32;
64
+ // Cast array to view
65
+ var createView = function (arr) {
66
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
67
+ };
68
+ exports.createView = createView;
69
+ // The rotate right (circular right shift) operation for uint32
70
+ var rotr = function (word, shift) { return (word << (32 - shift)) | (word >>> shift); };
71
+ exports.rotr = rotr;
72
+ // The rotate left (circular left shift) operation for uint32
73
+ var rotl = function (word, shift) {
74
+ return (word << shift) | ((word >>> (32 - shift)) >>> 0);
75
+ };
76
+ exports.rotl = rotl;
77
+ exports.isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
78
+ // The byte swap operation for uint32
79
+ var byteSwap = function (word) {
80
+ return ((word << 24) & 0xff000000) |
81
+ ((word << 8) & 0xff0000) |
82
+ ((word >>> 8) & 0xff00) |
83
+ ((word >>> 24) & 0xff);
84
+ };
85
+ exports.byteSwap = byteSwap;
86
+ // Conditionally byte swap if on a big-endian platform
87
+ exports.byteSwapIfBE = exports.isLE ? function (n) { return n; } : function (n) { return (0, exports.byteSwap)(n); };
88
+ // In place byte swap for Uint32Array
89
+ function byteSwap32(arr) {
90
+ for (var i = 0; i < arr.length; i++) {
91
+ arr[i] = (0, exports.byteSwap)(arr[i]);
92
+ }
93
+ }
94
+ exports.byteSwap32 = byteSwap32;
95
+ // Array where index 0xf0 (240) is mapped to string 'f0'
96
+ var hexes = /* @__PURE__ */ Array.from({ length: 256 }, function (_, i) {
97
+ return i.toString(16).padStart(2, '0');
98
+ });
99
+ /**
100
+ * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
101
+ */
102
+ function bytesToHex(bytes) {
103
+ (0, assert_1.assertBytes)(bytes);
104
+ // pre-caching improves the speed 6x
105
+ var hex = '';
106
+ for (var i = 0; i < bytes.length; i++) {
107
+ hex += hexes[bytes[i]];
108
+ }
109
+ return hex;
110
+ }
111
+ exports.bytesToHex = bytesToHex;
112
+ // We use optimized technique to convert hex string to byte array
113
+ var asciis = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 };
114
+ function asciiToBase16(char) {
115
+ if (char >= asciis._0 && char <= asciis._9)
116
+ return char - asciis._0;
117
+ if (char >= asciis._A && char <= asciis._F)
118
+ return char - (asciis._A - 10);
119
+ if (char >= asciis._a && char <= asciis._f)
120
+ return char - (asciis._a - 10);
121
+ return;
122
+ }
123
+ /**
124
+ * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
125
+ */
126
+ function hexToBytes(hex) {
127
+ if (typeof hex !== 'string')
128
+ throw new Error('hex string expected, got ' + typeof hex);
129
+ var hl = hex.length;
130
+ var al = hl / 2;
131
+ if (hl % 2)
132
+ throw new Error('padded hex string expected, got unpadded hex of length ' + hl);
133
+ var array = new Uint8Array(al);
134
+ for (var ai = 0, hi = 0; ai < al; ai++, hi += 2) {
135
+ var n1 = asciiToBase16(hex.charCodeAt(hi));
136
+ var n2 = asciiToBase16(hex.charCodeAt(hi + 1));
137
+ if (n1 === undefined || n2 === undefined) {
138
+ var char = hex[hi] + hex[hi + 1];
139
+ throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
140
+ }
141
+ array[ai] = n1 * 16 + n2;
142
+ }
143
+ return array;
144
+ }
145
+ exports.hexToBytes = hexToBytes;
146
+ // There is no setImmediate in browser and setTimeout is slow.
147
+ // call of async fn will return Promise, which will be fullfiled only on
148
+ // next scheduler queue processing step and this is exactly what we need.
149
+ var nextTick = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_b) {
150
+ return [2 /*return*/];
151
+ }); }); };
152
+ exports.nextTick = nextTick;
153
+ // Returns control to thread each 'tick' ms to avoid blocking
154
+ function asyncLoop(iters, tick, cb) {
155
+ return __awaiter(this, void 0, void 0, function () {
156
+ var ts, i, diff;
157
+ return __generator(this, function (_b) {
158
+ switch (_b.label) {
159
+ case 0:
160
+ ts = Date.now();
161
+ i = 0;
162
+ _b.label = 1;
163
+ case 1:
164
+ if (!(i < iters)) return [3 /*break*/, 4];
165
+ cb(i);
166
+ diff = Date.now() - ts;
167
+ if (diff >= 0 && diff < tick)
168
+ return [3 /*break*/, 3];
169
+ return [4 /*yield*/, (0, exports.nextTick)()];
170
+ case 2:
171
+ _b.sent();
172
+ ts += diff;
173
+ _b.label = 3;
174
+ case 3:
175
+ i++;
176
+ return [3 /*break*/, 1];
177
+ case 4: return [2 /*return*/];
178
+ }
179
+ });
180
+ });
181
+ }
182
+ exports.asyncLoop = asyncLoop;
183
+ /**
184
+ * Normalizes (non-hex) string or Uint8Array to Uint8Array.
185
+ * Warning: when Uint8Array is passed, it would NOT get copied.
186
+ * Keep in mind for future mutable operations.
187
+ */
188
+ function toBytes(data) {
189
+ if (typeof data === 'string')
190
+ data = (0, uint8array_utils_1.fromUtf8)(data);
191
+ (0, assert_1.assertBytes)(data);
192
+ return data;
193
+ }
194
+ exports.toBytes = toBytes;
195
+ /**
196
+ * Copies several Uint8Arrays into one.
197
+ */
198
+ function concatBytes() {
199
+ var arrays = [];
200
+ for (var _i = 0; _i < arguments.length; _i++) {
201
+ arrays[_i] = arguments[_i];
202
+ }
203
+ var sum = 0;
204
+ for (var i = 0; i < arrays.length; i++) {
205
+ var a = arrays[i];
206
+ (0, assert_1.assertBytes)(a);
207
+ sum += a.length;
208
+ }
209
+ var res = new Uint8Array(sum);
210
+ for (var i = 0, pad = 0; i < arrays.length; i++) {
211
+ var a = arrays[i];
212
+ res.set(a, pad);
213
+ pad += a.length;
214
+ }
215
+ return res;
216
+ }
217
+ exports.concatBytes = concatBytes;
218
+ // For runtime check if class implements interface
219
+ var Hash = /** @class */ (function () {
220
+ function Hash() {
221
+ }
222
+ // Safe version that clones internal state
223
+ Hash.prototype.clone = function () {
224
+ return this._cloneInto();
225
+ };
226
+ return Hash;
227
+ }());
228
+ exports.Hash = Hash;
229
+ var toStr = {}.toString;
230
+ function checkOpts(defaults, opts) {
231
+ if (opts !== undefined && toStr.call(opts) !== '[object Object]')
232
+ throw new Error('Options should be object or undefined');
233
+ var merged = Object.assign(defaults, opts);
234
+ return merged;
235
+ }
236
+ exports.checkOpts = checkOpts;
237
+ function wrapConstructor(hashCons) {
238
+ var hashC = function (msg) { return hashCons().update(toBytes(msg)).digest(); };
239
+ var tmp = hashCons();
240
+ hashC.outputLen = tmp.outputLen;
241
+ hashC.blockLen = tmp.blockLen;
242
+ hashC.create = function () { return hashCons(); };
243
+ return hashC;
244
+ }
245
+ exports.wrapConstructor = wrapConstructor;
246
+ function wrapConstructorWithOpts(hashCons) {
247
+ var hashC = function (msg, opts) { return hashCons(opts).update(toBytes(msg)).digest(); };
248
+ var tmp = hashCons({});
249
+ hashC.outputLen = tmp.outputLen;
250
+ hashC.blockLen = tmp.blockLen;
251
+ hashC.create = function (opts) { return hashCons(opts); };
252
+ return hashC;
253
+ }
254
+ exports.wrapConstructorWithOpts = wrapConstructorWithOpts;
255
+ function wrapXOFConstructorWithOpts(hashCons) {
256
+ var hashC = function (msg, opts) { return hashCons(opts).update(toBytes(msg)).digest(); };
257
+ var tmp = hashCons({});
258
+ hashC.outputLen = tmp.outputLen;
259
+ hashC.blockLen = tmp.blockLen;
260
+ hashC.create = function (opts) { return hashCons(opts); };
261
+ return hashC;
262
+ }
263
+ exports.wrapXOFConstructorWithOpts = wrapXOFConstructorWithOpts;
264
+ /**
265
+ * Secure PRNG. Uses `crypto.getRandomValues`, which defers to OS.
266
+ */
267
+ function randomBytes(bytesLength) {
268
+ if (bytesLength === void 0) { bytesLength = 32; }
269
+ if (crypto_1.crypto && typeof crypto_1.crypto.getRandomValues === 'function') {
270
+ return crypto_1.crypto.getRandomValues(new Uint8Array(bytesLength));
271
+ }
272
+ var bytes = new Uint8Array(bytesLength);
273
+ for (var i = 0; i < bytesLength; i++) {
274
+ bytes[i] = Math.floor(Math.random() * 256);
275
+ }
276
+ return bytes;
277
+ }
278
+ exports.randomBytes = randomBytes;
@@ -0,0 +1 @@
1
+ export declare function ripemd160(input: Uint8Array | string): Uint8Array;