@arcblock/did-noise 0.0.0-stage → 1.30.26

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 (44) hide show
  1. package/LICENSE +13 -0
  2. package/esm/chacha20poly1305.d.mts +18 -0
  3. package/esm/chacha20poly1305.mjs +152 -0
  4. package/esm/chain-node-mesh.d.mts +79 -0
  5. package/esm/chain-node-mesh.mjs +187 -0
  6. package/esm/http-transport.d.mts +72 -0
  7. package/esm/http-transport.mjs +216 -0
  8. package/esm/index.d.mts +6 -0
  9. package/esm/index.mjs +7 -0
  10. package/esm/mesh-tunnel.d.mts +165 -0
  11. package/esm/mesh-tunnel.mjs +350 -0
  12. package/esm/noise-session.d.mts +157 -0
  13. package/esm/noise-session.mjs +491 -0
  14. package/lib/_vendor/@noble/curves/LICENSE +21 -0
  15. package/lib/_vendor/@noble/curves/abstract/curve.cjs +338 -0
  16. package/lib/_vendor/@noble/curves/abstract/edwards.cjs +542 -0
  17. package/lib/_vendor/@noble/curves/abstract/hash-to-curve.cjs +72 -0
  18. package/lib/_vendor/@noble/curves/abstract/modular.cjs +557 -0
  19. package/lib/_vendor/@noble/curves/abstract/montgomery.cjs +149 -0
  20. package/lib/_vendor/@noble/curves/ed25519.cjs +302 -0
  21. package/lib/_vendor/@noble/curves/utils.cjs +436 -0
  22. package/lib/_vendor/@noble/hashes/LICENSE +21 -0
  23. package/lib/_vendor/@noble/hashes/_blake.cjs +300 -0
  24. package/lib/_vendor/@noble/hashes/_md.cjs +194 -0
  25. package/lib/_vendor/@noble/hashes/_u64.cjs +60 -0
  26. package/lib/_vendor/@noble/hashes/blake2.cjs +291 -0
  27. package/lib/_vendor/@noble/hashes/hkdf.cjs +104 -0
  28. package/lib/_vendor/@noble/hashes/hmac.cjs +86 -0
  29. package/lib/_vendor/@noble/hashes/sha2.cjs +417 -0
  30. package/lib/_vendor/@noble/hashes/utils.cjs +422 -0
  31. package/lib/chacha20poly1305.cjs +153 -0
  32. package/lib/chacha20poly1305.d.cts +18 -0
  33. package/lib/chain-node-mesh.cjs +189 -0
  34. package/lib/chain-node-mesh.d.cts +79 -0
  35. package/lib/http-transport.cjs +219 -0
  36. package/lib/http-transport.d.cts +72 -0
  37. package/lib/index.cjs +31 -0
  38. package/lib/index.d.cts +6 -0
  39. package/lib/mesh-tunnel.cjs +354 -0
  40. package/lib/mesh-tunnel.d.cts +165 -0
  41. package/lib/noise-session.cjs +503 -0
  42. package/lib/noise-session.d.cts +157 -0
  43. package/package.json +80 -4
  44. package/README.md +0 -3
@@ -0,0 +1,300 @@
1
+ const require_utils = require('./utils.cjs');
2
+
3
+ //#region ../../node_modules/@noble/hashes/_blake.js
4
+ /**
5
+ * Internal helpers for blake hash.
6
+ * @module
7
+ */
8
+ /**
9
+ * Internal blake permutation table.
10
+ * Rows `0..9` serve BLAKE2s, rows `0..11` serve BLAKE2b with `10..11 = 0..1`, and Blake1 also
11
+ * reuses the later rows shown below. Blake1 expands rounds `10..15` as `SIGMA[i % 10]`, so rows
12
+ * `10..15` intentionally repeat rows `0..5` for the 14-round (256) and 16-round (512) variants.
13
+ */
14
+ const BSIGMA = /* @__PURE__ */ Uint8Array.from([
15
+ 0,
16
+ 1,
17
+ 2,
18
+ 3,
19
+ 4,
20
+ 5,
21
+ 6,
22
+ 7,
23
+ 8,
24
+ 9,
25
+ 10,
26
+ 11,
27
+ 12,
28
+ 13,
29
+ 14,
30
+ 15,
31
+ 14,
32
+ 10,
33
+ 4,
34
+ 8,
35
+ 9,
36
+ 15,
37
+ 13,
38
+ 6,
39
+ 1,
40
+ 12,
41
+ 0,
42
+ 2,
43
+ 11,
44
+ 7,
45
+ 5,
46
+ 3,
47
+ 11,
48
+ 8,
49
+ 12,
50
+ 0,
51
+ 5,
52
+ 2,
53
+ 15,
54
+ 13,
55
+ 10,
56
+ 14,
57
+ 3,
58
+ 6,
59
+ 7,
60
+ 1,
61
+ 9,
62
+ 4,
63
+ 7,
64
+ 9,
65
+ 3,
66
+ 1,
67
+ 13,
68
+ 12,
69
+ 11,
70
+ 14,
71
+ 2,
72
+ 6,
73
+ 5,
74
+ 10,
75
+ 4,
76
+ 0,
77
+ 15,
78
+ 8,
79
+ 9,
80
+ 0,
81
+ 5,
82
+ 7,
83
+ 2,
84
+ 4,
85
+ 10,
86
+ 15,
87
+ 14,
88
+ 1,
89
+ 11,
90
+ 12,
91
+ 6,
92
+ 8,
93
+ 3,
94
+ 13,
95
+ 2,
96
+ 12,
97
+ 6,
98
+ 10,
99
+ 0,
100
+ 11,
101
+ 8,
102
+ 3,
103
+ 4,
104
+ 13,
105
+ 7,
106
+ 5,
107
+ 15,
108
+ 14,
109
+ 1,
110
+ 9,
111
+ 12,
112
+ 5,
113
+ 1,
114
+ 15,
115
+ 14,
116
+ 13,
117
+ 4,
118
+ 10,
119
+ 0,
120
+ 7,
121
+ 6,
122
+ 3,
123
+ 9,
124
+ 2,
125
+ 8,
126
+ 11,
127
+ 13,
128
+ 11,
129
+ 7,
130
+ 14,
131
+ 12,
132
+ 1,
133
+ 3,
134
+ 9,
135
+ 5,
136
+ 0,
137
+ 15,
138
+ 4,
139
+ 8,
140
+ 6,
141
+ 2,
142
+ 10,
143
+ 6,
144
+ 15,
145
+ 14,
146
+ 9,
147
+ 11,
148
+ 3,
149
+ 0,
150
+ 8,
151
+ 12,
152
+ 2,
153
+ 13,
154
+ 7,
155
+ 1,
156
+ 4,
157
+ 10,
158
+ 5,
159
+ 10,
160
+ 2,
161
+ 8,
162
+ 4,
163
+ 7,
164
+ 6,
165
+ 1,
166
+ 5,
167
+ 15,
168
+ 11,
169
+ 9,
170
+ 14,
171
+ 3,
172
+ 12,
173
+ 13,
174
+ 0,
175
+ 0,
176
+ 1,
177
+ 2,
178
+ 3,
179
+ 4,
180
+ 5,
181
+ 6,
182
+ 7,
183
+ 8,
184
+ 9,
185
+ 10,
186
+ 11,
187
+ 12,
188
+ 13,
189
+ 14,
190
+ 15,
191
+ 14,
192
+ 10,
193
+ 4,
194
+ 8,
195
+ 9,
196
+ 15,
197
+ 13,
198
+ 6,
199
+ 1,
200
+ 12,
201
+ 0,
202
+ 2,
203
+ 11,
204
+ 7,
205
+ 5,
206
+ 3,
207
+ 11,
208
+ 8,
209
+ 12,
210
+ 0,
211
+ 5,
212
+ 2,
213
+ 15,
214
+ 13,
215
+ 10,
216
+ 14,
217
+ 3,
218
+ 6,
219
+ 7,
220
+ 1,
221
+ 9,
222
+ 4,
223
+ 7,
224
+ 9,
225
+ 3,
226
+ 1,
227
+ 13,
228
+ 12,
229
+ 11,
230
+ 14,
231
+ 2,
232
+ 6,
233
+ 5,
234
+ 10,
235
+ 4,
236
+ 0,
237
+ 15,
238
+ 8,
239
+ 9,
240
+ 0,
241
+ 5,
242
+ 7,
243
+ 2,
244
+ 4,
245
+ 10,
246
+ 15,
247
+ 14,
248
+ 1,
249
+ 11,
250
+ 12,
251
+ 6,
252
+ 8,
253
+ 3,
254
+ 13,
255
+ 2,
256
+ 12,
257
+ 6,
258
+ 10,
259
+ 0,
260
+ 11,
261
+ 8,
262
+ 3,
263
+ 4,
264
+ 13,
265
+ 7,
266
+ 5,
267
+ 15,
268
+ 14,
269
+ 1,
270
+ 9
271
+ ]);
272
+ function G1s(a, b, c, d, x) {
273
+ a = a + b + x | 0;
274
+ d = require_utils.rotr(d ^ a, 16);
275
+ c = c + d | 0;
276
+ b = require_utils.rotr(b ^ c, 12);
277
+ return {
278
+ a,
279
+ b,
280
+ c,
281
+ d
282
+ };
283
+ }
284
+ function G2s(a, b, c, d, x) {
285
+ a = a + b + x | 0;
286
+ d = require_utils.rotr(d ^ a, 8);
287
+ c = c + d | 0;
288
+ b = require_utils.rotr(b ^ c, 7);
289
+ return {
290
+ a,
291
+ b,
292
+ c,
293
+ d
294
+ };
295
+ }
296
+
297
+ //#endregion
298
+ exports.BSIGMA = BSIGMA;
299
+ exports.G1s = G1s;
300
+ exports.G2s = G2s;
@@ -0,0 +1,194 @@
1
+ const require_utils = require('./utils.cjs');
2
+
3
+ //#region ../../node_modules/@noble/hashes/_md.js
4
+ /**
5
+ * Internal Merkle-Damgard hash utils.
6
+ * @module
7
+ */
8
+ /**
9
+ * Shared 32-bit conditional boolean primitive reused by SHA-256, SHA-1, and MD5 `F`.
10
+ * Returns bits from `b` when `a` is set, otherwise from `c`.
11
+ * The XOR form is equivalent to MD5's `F(X,Y,Z) = XY v not(X)Z` because the masked terms never
12
+ * set the same bit.
13
+ * @param a - selector word
14
+ * @param b - word chosen when selector bit is set
15
+ * @param c - word chosen when selector bit is clear
16
+ * @returns Mixed 32-bit word.
17
+ * @example
18
+ * Combine three words with the shared 32-bit choice primitive.
19
+ * ```ts
20
+ * Chi(0xffffffff, 0x12345678, 0x87654321);
21
+ * ```
22
+ */
23
+ function Chi(a, b, c) {
24
+ return a & b ^ ~a & c;
25
+ }
26
+ /**
27
+ * Shared 32-bit majority primitive reused by SHA-256 and SHA-1.
28
+ * Returns bits shared by at least two inputs.
29
+ * @param a - first input word
30
+ * @param b - second input word
31
+ * @param c - third input word
32
+ * @returns Mixed 32-bit word.
33
+ * @example
34
+ * Combine three words with the shared 32-bit majority primitive.
35
+ * ```ts
36
+ * Maj(0xffffffff, 0x12345678, 0x87654321);
37
+ * ```
38
+ */
39
+ function Maj(a, b, c) {
40
+ return a & b ^ a & c ^ b & c;
41
+ }
42
+ /**
43
+ * Merkle-Damgard hash construction base class.
44
+ * Could be used to create MD5, RIPEMD, SHA1, SHA2.
45
+ * Accepts only byte-aligned `Uint8Array` input, even when the underlying spec describes bit
46
+ * strings with partial-byte tails.
47
+ * @param blockLen - internal block size in bytes
48
+ * @param outputLen - digest size in bytes
49
+ * @param padOffset - trailing length field size in bytes
50
+ * @param isLE - whether length and state words are encoded in little-endian
51
+ * @example
52
+ * Use a concrete subclass to get the shared Merkle-Damgard update/digest flow.
53
+ * ```ts
54
+ * import { _SHA1 } from '@noble/hashes/legacy.js';
55
+ * const hash = new _SHA1();
56
+ * hash.update(new Uint8Array([97, 98, 99]));
57
+ * hash.digest();
58
+ * ```
59
+ */
60
+ var HashMD = class {
61
+ blockLen;
62
+ outputLen;
63
+ canXOF = false;
64
+ padOffset;
65
+ isLE;
66
+ buffer;
67
+ view;
68
+ finished = false;
69
+ length = 0;
70
+ pos = 0;
71
+ destroyed = false;
72
+ constructor(blockLen, outputLen, padOffset, isLE) {
73
+ this.blockLen = blockLen;
74
+ this.outputLen = outputLen;
75
+ this.padOffset = padOffset;
76
+ this.isLE = isLE;
77
+ this.buffer = new Uint8Array(blockLen);
78
+ this.view = require_utils.createView(this.buffer);
79
+ }
80
+ update(data) {
81
+ require_utils.aexists(this);
82
+ require_utils.abytes(data);
83
+ const { view, buffer, blockLen } = this;
84
+ const len = data.length;
85
+ for (let pos = 0; pos < len;) {
86
+ const take = Math.min(blockLen - this.pos, len - pos);
87
+ if (take === blockLen) {
88
+ const dataView = require_utils.createView(data);
89
+ for (; blockLen <= len - pos; pos += blockLen) this.process(dataView, pos);
90
+ continue;
91
+ }
92
+ buffer.set(data.subarray(pos, pos + take), this.pos);
93
+ this.pos += take;
94
+ pos += take;
95
+ if (this.pos === blockLen) {
96
+ this.process(view, 0);
97
+ this.pos = 0;
98
+ }
99
+ }
100
+ this.length += data.length;
101
+ this.roundClean();
102
+ return this;
103
+ }
104
+ digestInto(out) {
105
+ require_utils.aexists(this);
106
+ require_utils.aoutput(out, this);
107
+ this.finished = true;
108
+ const { buffer, view, blockLen, isLE } = this;
109
+ let { pos } = this;
110
+ buffer[pos++] = 128;
111
+ require_utils.clean(this.buffer.subarray(pos));
112
+ if (this.padOffset > blockLen - pos) {
113
+ this.process(view, 0);
114
+ pos = 0;
115
+ }
116
+ for (let i = pos; i < blockLen; i++) buffer[i] = 0;
117
+ view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE);
118
+ this.process(view, 0);
119
+ const oview = require_utils.createView(out);
120
+ const len = this.outputLen;
121
+ if (len % 4) throw new Error("_sha2: outputLen must be aligned to 32bit");
122
+ const outLen = len / 4;
123
+ const state = this.get();
124
+ if (outLen > state.length) throw new Error("_sha2: outputLen bigger than state");
125
+ for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE);
126
+ }
127
+ digest() {
128
+ const { buffer, outputLen } = this;
129
+ this.digestInto(buffer);
130
+ const res = buffer.slice(0, outputLen);
131
+ this.destroy();
132
+ return res;
133
+ }
134
+ _cloneInto(to) {
135
+ to ||= new this.constructor();
136
+ to.set(...this.get());
137
+ const { blockLen, buffer, length, finished, destroyed, pos } = this;
138
+ to.destroyed = destroyed;
139
+ to.finished = finished;
140
+ to.length = length;
141
+ to.pos = pos;
142
+ if (length % blockLen) to.buffer.set(buffer);
143
+ return to;
144
+ }
145
+ clone() {
146
+ return this._cloneInto();
147
+ }
148
+ };
149
+ /**
150
+ * Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.
151
+ * Check out `test/misc/sha2-gen-iv.js` for recomputation guide.
152
+ */
153
+ /** Initial SHA256 state from RFC 6234 §6.1: the first 32 bits of the fractional parts of the
154
+ * square roots of the first eight prime numbers. Exported as a shared table; callers must treat
155
+ * it as read-only because constructors copy words from it by index. */
156
+ const SHA256_IV = /* @__PURE__ */ Uint32Array.from([
157
+ 1779033703,
158
+ 3144134277,
159
+ 1013904242,
160
+ 2773480762,
161
+ 1359893119,
162
+ 2600822924,
163
+ 528734635,
164
+ 1541459225
165
+ ]);
166
+ /** Initial SHA512 state from RFC 6234 §6.3: eight RFC 64-bit `H(0)` words stored as sixteen
167
+ * big-endian 32-bit halves. Derived from the fractional parts of the square roots of the first
168
+ * eight prime numbers. Exported as a shared table; callers must treat it as read-only because
169
+ * constructors copy halves from it by index. */
170
+ const SHA512_IV = /* @__PURE__ */ Uint32Array.from([
171
+ 1779033703,
172
+ 4089235720,
173
+ 3144134277,
174
+ 2227873595,
175
+ 1013904242,
176
+ 4271175723,
177
+ 2773480762,
178
+ 1595750129,
179
+ 1359893119,
180
+ 2917565137,
181
+ 2600822924,
182
+ 725511199,
183
+ 528734635,
184
+ 4215389547,
185
+ 1541459225,
186
+ 327033209
187
+ ]);
188
+
189
+ //#endregion
190
+ exports.Chi = Chi;
191
+ exports.HashMD = HashMD;
192
+ exports.Maj = Maj;
193
+ exports.SHA256_IV = SHA256_IV;
194
+ exports.SHA512_IV = SHA512_IV;
@@ -0,0 +1,60 @@
1
+
2
+ //#region ../../node_modules/@noble/hashes/_u64.js
3
+ const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
4
+ const _32n = /* @__PURE__ */ BigInt(32);
5
+ function fromBig(n, le = false) {
6
+ if (le) return {
7
+ h: Number(n & U32_MASK64),
8
+ l: Number(n >> _32n & U32_MASK64)
9
+ };
10
+ return {
11
+ h: Number(n >> _32n & U32_MASK64) | 0,
12
+ l: Number(n & U32_MASK64) | 0
13
+ };
14
+ }
15
+ function split(lst, le = false) {
16
+ const len = lst.length;
17
+ let Ah = new Uint32Array(len);
18
+ let Al = new Uint32Array(len);
19
+ for (let i = 0; i < len; i++) {
20
+ const { h, l } = fromBig(lst[i], le);
21
+ [Ah[i], Al[i]] = [h, l];
22
+ }
23
+ return [Ah, Al];
24
+ }
25
+ const shrSH = (h, _l, s) => h >>> s;
26
+ const shrSL = (h, l, s) => h << 32 - s | l >>> s;
27
+ const rotrSH = (h, l, s) => h >>> s | l << 32 - s;
28
+ const rotrSL = (h, l, s) => h << 32 - s | l >>> s;
29
+ const rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
30
+ const rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
31
+ function add(Ah, Al, Bh, Bl) {
32
+ const l = (Al >>> 0) + (Bl >>> 0);
33
+ return {
34
+ h: Ah + Bh + (l / 2 ** 32 | 0) | 0,
35
+ l: l | 0
36
+ };
37
+ }
38
+ const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
39
+ const add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
40
+ const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
41
+ const add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
42
+ const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
43
+ const add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
44
+
45
+ //#endregion
46
+ exports.add = add;
47
+ exports.add3H = add3H;
48
+ exports.add3L = add3L;
49
+ exports.add4H = add4H;
50
+ exports.add4L = add4L;
51
+ exports.add5H = add5H;
52
+ exports.add5L = add5L;
53
+ exports.fromBig = fromBig;
54
+ exports.rotrBH = rotrBH;
55
+ exports.rotrBL = rotrBL;
56
+ exports.rotrSH = rotrSH;
57
+ exports.rotrSL = rotrSL;
58
+ exports.shrSH = shrSH;
59
+ exports.shrSL = shrSL;
60
+ exports.split = split;