@atproto/crypto 0.3.0 → 0.3.1-next.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 (91) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/LICENSE.txt +1 -1
  3. package/dist/const.d.ts +1 -0
  4. package/dist/const.d.ts.map +1 -0
  5. package/dist/const.js +10 -0
  6. package/dist/const.js.map +1 -0
  7. package/dist/did.d.ts +2 -1
  8. package/dist/did.d.ts.map +1 -0
  9. package/dist/did.js +68 -0
  10. package/dist/did.js.map +1 -0
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +27 -3351
  14. package/dist/index.js.map +1 -7
  15. package/dist/multibase.d.ts +1 -0
  16. package/dist/multibase.d.ts.map +1 -0
  17. package/dist/multibase.js +76 -0
  18. package/dist/multibase.js.map +1 -0
  19. package/dist/p256/encoding.d.ts +1 -0
  20. package/dist/p256/encoding.d.ts.map +1 -0
  21. package/dist/p256/encoding.js +18 -0
  22. package/dist/p256/encoding.js.map +1 -0
  23. package/dist/p256/keypair.d.ts +3 -2
  24. package/dist/p256/keypair.d.ts.map +1 -0
  25. package/dist/p256/keypair.js +94 -0
  26. package/dist/p256/keypair.js.map +1 -0
  27. package/dist/p256/operations.d.ts +1 -0
  28. package/dist/p256/operations.d.ts.map +1 -0
  29. package/dist/p256/operations.js +41 -0
  30. package/dist/p256/operations.js.map +1 -0
  31. package/dist/p256/plugin.d.ts +1 -0
  32. package/dist/p256/plugin.d.ts.map +1 -0
  33. package/dist/p256/plugin.js +15 -0
  34. package/dist/p256/plugin.js.map +1 -0
  35. package/dist/plugins.d.ts +1 -0
  36. package/dist/plugins.d.ts.map +1 -0
  37. package/dist/plugins.js +11 -0
  38. package/dist/plugins.js.map +1 -0
  39. package/dist/random.d.ts +1 -0
  40. package/dist/random.d.ts.map +1 -0
  41. package/dist/random.js +44 -0
  42. package/dist/random.js.map +1 -0
  43. package/dist/secp256k1/encoding.d.ts +1 -0
  44. package/dist/secp256k1/encoding.d.ts.map +1 -0
  45. package/dist/secp256k1/encoding.js +18 -0
  46. package/dist/secp256k1/encoding.js.map +1 -0
  47. package/dist/secp256k1/keypair.d.ts +3 -2
  48. package/dist/secp256k1/keypair.d.ts.map +1 -0
  49. package/dist/secp256k1/keypair.js +94 -0
  50. package/dist/secp256k1/keypair.js.map +1 -0
  51. package/dist/secp256k1/operations.d.ts +1 -0
  52. package/dist/secp256k1/operations.d.ts.map +1 -0
  53. package/dist/secp256k1/operations.js +64 -0
  54. package/dist/secp256k1/operations.js.map +1 -0
  55. package/dist/secp256k1/plugin.d.ts +1 -0
  56. package/dist/secp256k1/plugin.d.ts.map +1 -0
  57. package/dist/secp256k1/plugin.js +15 -0
  58. package/dist/secp256k1/plugin.js.map +1 -0
  59. package/dist/sha.d.ts +2 -0
  60. package/dist/sha.d.ts.map +1 -0
  61. package/dist/sha.js +40 -0
  62. package/dist/sha.js.map +1 -0
  63. package/dist/types.d.ts +8 -2
  64. package/dist/types.d.ts.map +1 -0
  65. package/dist/types.js +3 -0
  66. package/dist/types.js.map +1 -0
  67. package/dist/utils.d.ts +4 -0
  68. package/dist/utils.d.ts.map +1 -0
  69. package/dist/utils.js +47 -0
  70. package/dist/utils.js.map +1 -0
  71. package/dist/verify.d.ts +1 -0
  72. package/dist/verify.d.ts.map +1 -0
  73. package/dist/verify.js +48 -0
  74. package/dist/verify.js.map +1 -0
  75. package/jest.config.js +3 -3
  76. package/package.json +8 -6
  77. package/src/did.ts +13 -35
  78. package/src/p256/keypair.ts +8 -6
  79. package/src/p256/operations.ts +8 -6
  80. package/src/p256/plugin.ts +7 -2
  81. package/src/secp256k1/keypair.ts +9 -7
  82. package/src/secp256k1/operations.ts +6 -4
  83. package/src/secp256k1/plugin.ts +7 -2
  84. package/src/sha.ts +7 -0
  85. package/src/types.ts +7 -0
  86. package/src/utils.ts +23 -0
  87. package/tests/signatures.test.ts +2 -1
  88. package/tsconfig.build.json +6 -2
  89. package/tsconfig.json +5 -7
  90. package/tsconfig.tests.json +7 -0
  91. package/build.js +0 -14
package/dist/index.js CHANGED
@@ -1,3352 +1,28 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name2 in all)
10
- __defProp(target, name2, { get: all[name2], enumerable: true });
11
- };
12
- var __copyProps = (to, from3, except, desc) => {
13
- if (from3 && typeof from3 === "object" || typeof from3 === "function") {
14
- for (let key of __getOwnPropNames(from3))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from3[key], enumerable: !(desc = __getOwnPropDesc(from3, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target, mod2));
21
- var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
22
-
23
- // src/index.ts
24
- var src_exports2 = {};
25
- __export(src_exports2, {
26
- BASE58_MULTIBASE_PREFIX: () => BASE58_MULTIBASE_PREFIX,
27
- DID_KEY_PREFIX: () => DID_KEY_PREFIX,
28
- P256Keypair: () => P256Keypair,
29
- P256_DID_PREFIX: () => P256_DID_PREFIX,
30
- P256_JWT_ALG: () => P256_JWT_ALG,
31
- SECP256K1_DID_PREFIX: () => SECP256K1_DID_PREFIX,
32
- SECP256K1_JWT_ALG: () => SECP256K1_JWT_ALG,
33
- Secp256k1Keypair: () => Secp256k1Keypair,
34
- bytesToMultibase: () => bytesToMultibase,
35
- formatDidKey: () => formatDidKey,
36
- formatMultikey: () => formatMultikey,
37
- multibaseToBytes: () => multibaseToBytes,
38
- p256Plugin: () => p256Plugin,
39
- parseDidKey: () => parseDidKey,
40
- parseMultikey: () => parseMultikey,
41
- randomBytes: () => randomBytes2,
42
- randomIntFromSeed: () => randomIntFromSeed,
43
- randomStr: () => randomStr,
44
- secp256k1Plugin: () => secp256k1Plugin,
45
- sha256: () => sha2563,
46
- verifySignature: () => verifySignature,
47
- verifySignatureUtf8: () => verifySignatureUtf8
48
- });
49
- module.exports = __toCommonJS(src_exports2);
50
-
51
- // src/const.ts
52
- var P256_DID_PREFIX = new Uint8Array([128, 36]);
53
- var SECP256K1_DID_PREFIX = new Uint8Array([231, 1]);
54
- var BASE58_MULTIBASE_PREFIX = "z";
55
- var DID_KEY_PREFIX = "did:key:";
56
- var P256_JWT_ALG = "ES256";
57
- var SECP256K1_JWT_ALG = "ES256K";
58
-
59
- // ../../node_modules/.pnpm/uint8arrays@3.0.0/node_modules/uint8arrays/esm/src/concat.js
60
- function concat(arrays, length2) {
61
- if (!length2) {
62
- length2 = arrays.reduce((acc, curr) => acc + curr.length, 0);
63
- }
64
- const output2 = new Uint8Array(length2);
65
- let offset = 0;
66
- for (const arr of arrays) {
67
- output2.set(arr, offset);
68
- offset += arr.length;
69
- }
70
- return output2;
71
- }
72
-
73
- // ../../node_modules/.pnpm/uint8arrays@3.0.0/node_modules/uint8arrays/esm/src/equals.js
74
- function equals(a, b) {
75
- if (a === b) {
76
- return true;
77
- }
78
- if (a.byteLength !== b.byteLength) {
79
- return false;
80
- }
81
- for (let i = 0; i < a.byteLength; i++) {
82
- if (a[i] !== b[i]) {
83
- return false;
84
- }
85
- }
86
- return true;
87
- }
88
-
89
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/bases/identity.js
90
- var identity_exports = {};
91
- __export(identity_exports, {
92
- identity: () => identity
93
- });
94
-
95
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/vendor/base-x.js
96
- function base(ALPHABET, name2) {
97
- if (ALPHABET.length >= 255) {
98
- throw new TypeError("Alphabet too long");
99
- }
100
- var BASE_MAP = new Uint8Array(256);
101
- for (var j = 0; j < BASE_MAP.length; j++) {
102
- BASE_MAP[j] = 255;
103
- }
104
- for (var i = 0; i < ALPHABET.length; i++) {
105
- var x = ALPHABET.charAt(i);
106
- var xc = x.charCodeAt(0);
107
- if (BASE_MAP[xc] !== 255) {
108
- throw new TypeError(x + " is ambiguous");
109
- }
110
- BASE_MAP[xc] = i;
111
- }
112
- var BASE = ALPHABET.length;
113
- var LEADER = ALPHABET.charAt(0);
114
- var FACTOR = Math.log(BASE) / Math.log(256);
115
- var iFACTOR = Math.log(256) / Math.log(BASE);
116
- function encode5(source) {
117
- if (source instanceof Uint8Array)
118
- ;
119
- else if (ArrayBuffer.isView(source)) {
120
- source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
121
- } else if (Array.isArray(source)) {
122
- source = Uint8Array.from(source);
123
- }
124
- if (!(source instanceof Uint8Array)) {
125
- throw new TypeError("Expected Uint8Array");
126
- }
127
- if (source.length === 0) {
128
- return "";
129
- }
130
- var zeroes = 0;
131
- var length2 = 0;
132
- var pbegin = 0;
133
- var pend = source.length;
134
- while (pbegin !== pend && source[pbegin] === 0) {
135
- pbegin++;
136
- zeroes++;
137
- }
138
- var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
139
- var b58 = new Uint8Array(size);
140
- while (pbegin !== pend) {
141
- var carry = source[pbegin];
142
- var i2 = 0;
143
- for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
144
- carry += 256 * b58[it1] >>> 0;
145
- b58[it1] = carry % BASE >>> 0;
146
- carry = carry / BASE >>> 0;
147
- }
148
- if (carry !== 0) {
149
- throw new Error("Non-zero carry");
150
- }
151
- length2 = i2;
152
- pbegin++;
153
- }
154
- var it2 = size - length2;
155
- while (it2 !== size && b58[it2] === 0) {
156
- it2++;
157
- }
158
- var str = LEADER.repeat(zeroes);
159
- for (; it2 < size; ++it2) {
160
- str += ALPHABET.charAt(b58[it2]);
161
- }
162
- return str;
163
- }
164
- function decodeUnsafe(source) {
165
- if (typeof source !== "string") {
166
- throw new TypeError("Expected String");
167
- }
168
- if (source.length === 0) {
169
- return new Uint8Array();
170
- }
171
- var psz = 0;
172
- if (source[psz] === " ") {
173
- return;
174
- }
175
- var zeroes = 0;
176
- var length2 = 0;
177
- while (source[psz] === LEADER) {
178
- zeroes++;
179
- psz++;
180
- }
181
- var size = (source.length - psz) * FACTOR + 1 >>> 0;
182
- var b256 = new Uint8Array(size);
183
- while (source[psz]) {
184
- var carry = BASE_MAP[source.charCodeAt(psz)];
185
- if (carry === 255) {
186
- return;
187
- }
188
- var i2 = 0;
189
- for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
190
- carry += BASE * b256[it3] >>> 0;
191
- b256[it3] = carry % 256 >>> 0;
192
- carry = carry / 256 >>> 0;
193
- }
194
- if (carry !== 0) {
195
- throw new Error("Non-zero carry");
196
- }
197
- length2 = i2;
198
- psz++;
199
- }
200
- if (source[psz] === " ") {
201
- return;
202
- }
203
- var it4 = size - length2;
204
- while (it4 !== size && b256[it4] === 0) {
205
- it4++;
206
- }
207
- var vch = new Uint8Array(zeroes + (size - it4));
208
- var j2 = zeroes;
209
- while (it4 !== size) {
210
- vch[j2++] = b256[it4++];
211
- }
212
- return vch;
213
- }
214
- function decode6(string2) {
215
- var buffer = decodeUnsafe(string2);
216
- if (buffer) {
217
- return buffer;
218
- }
219
- throw new Error(`Non-${name2} character`);
220
- }
221
- return {
222
- encode: encode5,
223
- decodeUnsafe,
224
- decode: decode6
225
- };
226
- }
227
- var src = base;
228
- var _brrp__multiformats_scope_baseX = src;
229
- var base_x_default = _brrp__multiformats_scope_baseX;
230
-
231
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/bytes.js
232
- var empty = new Uint8Array(0);
233
- var equals2 = (aa, bb) => {
234
- if (aa === bb)
235
- return true;
236
- if (aa.byteLength !== bb.byteLength) {
237
- return false;
238
- }
239
- for (let ii = 0; ii < aa.byteLength; ii++) {
240
- if (aa[ii] !== bb[ii]) {
241
- return false;
242
- }
243
- }
244
- return true;
245
- };
246
- var coerce = (o) => {
247
- if (o instanceof Uint8Array && o.constructor.name === "Uint8Array")
248
- return o;
249
- if (o instanceof ArrayBuffer)
250
- return new Uint8Array(o);
251
- if (ArrayBuffer.isView(o)) {
252
- return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
253
- }
254
- throw new Error("Unknown type, must be binary type");
255
- };
256
- var fromString = (str) => new TextEncoder().encode(str);
257
- var toString = (b) => new TextDecoder().decode(b);
258
-
259
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/bases/base.js
260
- var Encoder = class {
261
- constructor(name2, prefix, baseEncode) {
262
- this.name = name2;
263
- this.prefix = prefix;
264
- this.baseEncode = baseEncode;
265
- }
266
- encode(bytes2) {
267
- if (bytes2 instanceof Uint8Array) {
268
- return `${this.prefix}${this.baseEncode(bytes2)}`;
269
- } else {
270
- throw Error("Unknown type, must be binary type");
271
- }
272
- }
273
- };
274
- var Decoder = class {
275
- constructor(name2, prefix, baseDecode) {
276
- this.name = name2;
277
- this.prefix = prefix;
278
- if (prefix.codePointAt(0) === void 0) {
279
- throw new Error("Invalid prefix character");
280
- }
281
- this.prefixCodePoint = prefix.codePointAt(0);
282
- this.baseDecode = baseDecode;
283
- }
284
- decode(text) {
285
- if (typeof text === "string") {
286
- if (text.codePointAt(0) !== this.prefixCodePoint) {
287
- throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
288
- }
289
- return this.baseDecode(text.slice(this.prefix.length));
290
- } else {
291
- throw Error("Can only multibase decode strings");
292
- }
293
- }
294
- or(decoder) {
295
- return or(this, decoder);
296
- }
297
- };
298
- var ComposedDecoder = class {
299
- constructor(decoders) {
300
- this.decoders = decoders;
301
- }
302
- or(decoder) {
303
- return or(this, decoder);
304
- }
305
- decode(input) {
306
- const prefix = input[0];
307
- const decoder = this.decoders[prefix];
308
- if (decoder) {
309
- return decoder.decode(input);
310
- } else {
311
- throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
312
- }
313
- }
314
- };
315
- var or = (left, right) => new ComposedDecoder({
316
- ...left.decoders || { [left.prefix]: left },
317
- ...right.decoders || { [right.prefix]: right }
318
- });
319
- var Codec = class {
320
- constructor(name2, prefix, baseEncode, baseDecode) {
321
- this.name = name2;
322
- this.prefix = prefix;
323
- this.baseEncode = baseEncode;
324
- this.baseDecode = baseDecode;
325
- this.encoder = new Encoder(name2, prefix, baseEncode);
326
- this.decoder = new Decoder(name2, prefix, baseDecode);
327
- }
328
- encode(input) {
329
- return this.encoder.encode(input);
330
- }
331
- decode(input) {
332
- return this.decoder.decode(input);
333
- }
334
- };
335
- var from = ({ name: name2, prefix, encode: encode5, decode: decode6 }) => new Codec(name2, prefix, encode5, decode6);
336
- var baseX = ({ prefix, name: name2, alphabet: alphabet2 }) => {
337
- const { encode: encode5, decode: decode6 } = base_x_default(alphabet2, name2);
338
- return from({
339
- prefix,
340
- name: name2,
341
- encode: encode5,
342
- decode: (text) => coerce(decode6(text))
343
- });
344
- };
345
- var decode = (string2, alphabet2, bitsPerChar, name2) => {
346
- const codes = {};
347
- for (let i = 0; i < alphabet2.length; ++i) {
348
- codes[alphabet2[i]] = i;
349
- }
350
- let end = string2.length;
351
- while (string2[end - 1] === "=") {
352
- --end;
353
- }
354
- const out = new Uint8Array(end * bitsPerChar / 8 | 0);
355
- let bits = 0;
356
- let buffer = 0;
357
- let written = 0;
358
- for (let i = 0; i < end; ++i) {
359
- const value = codes[string2[i]];
360
- if (value === void 0) {
361
- throw new SyntaxError(`Non-${name2} character`);
362
- }
363
- buffer = buffer << bitsPerChar | value;
364
- bits += bitsPerChar;
365
- if (bits >= 8) {
366
- bits -= 8;
367
- out[written++] = 255 & buffer >> bits;
368
- }
369
- }
370
- if (bits >= bitsPerChar || 255 & buffer << 8 - bits) {
371
- throw new SyntaxError("Unexpected end of data");
372
- }
373
- return out;
374
- };
375
- var encode = (data, alphabet2, bitsPerChar) => {
376
- const pad = alphabet2[alphabet2.length - 1] === "=";
377
- const mask = (1 << bitsPerChar) - 1;
378
- let out = "";
379
- let bits = 0;
380
- let buffer = 0;
381
- for (let i = 0; i < data.length; ++i) {
382
- buffer = buffer << 8 | data[i];
383
- bits += 8;
384
- while (bits > bitsPerChar) {
385
- bits -= bitsPerChar;
386
- out += alphabet2[mask & buffer >> bits];
387
- }
388
- }
389
- if (bits) {
390
- out += alphabet2[mask & buffer << bitsPerChar - bits];
391
- }
392
- if (pad) {
393
- while (out.length * bitsPerChar & 7) {
394
- out += "=";
395
- }
396
- }
397
- return out;
398
- };
399
- var rfc4648 = ({ name: name2, prefix, bitsPerChar, alphabet: alphabet2 }) => {
400
- return from({
401
- prefix,
402
- name: name2,
403
- encode(input) {
404
- return encode(input, alphabet2, bitsPerChar);
405
- },
406
- decode(input) {
407
- return decode(input, alphabet2, bitsPerChar, name2);
408
- }
409
- });
410
- };
411
-
412
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/bases/identity.js
413
- var identity = from({
414
- prefix: "\0",
415
- name: "identity",
416
- encode: (buf) => toString(buf),
417
- decode: (str) => fromString(str)
418
- });
419
-
420
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/bases/base2.js
421
- var base2_exports = {};
422
- __export(base2_exports, {
423
- base2: () => base2
424
- });
425
- var base2 = rfc4648({
426
- prefix: "0",
427
- name: "base2",
428
- alphabet: "01",
429
- bitsPerChar: 1
430
- });
431
-
432
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/bases/base8.js
433
- var base8_exports = {};
434
- __export(base8_exports, {
435
- base8: () => base8
436
- });
437
- var base8 = rfc4648({
438
- prefix: "7",
439
- name: "base8",
440
- alphabet: "01234567",
441
- bitsPerChar: 3
442
- });
443
-
444
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/bases/base10.js
445
- var base10_exports = {};
446
- __export(base10_exports, {
447
- base10: () => base10
448
- });
449
- var base10 = baseX({
450
- prefix: "9",
451
- name: "base10",
452
- alphabet: "0123456789"
453
- });
454
-
455
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/bases/base16.js
456
- var base16_exports = {};
457
- __export(base16_exports, {
458
- base16: () => base16,
459
- base16upper: () => base16upper
460
- });
461
- var base16 = rfc4648({
462
- prefix: "f",
463
- name: "base16",
464
- alphabet: "0123456789abcdef",
465
- bitsPerChar: 4
466
- });
467
- var base16upper = rfc4648({
468
- prefix: "F",
469
- name: "base16upper",
470
- alphabet: "0123456789ABCDEF",
471
- bitsPerChar: 4
472
- });
473
-
474
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/bases/base32.js
475
- var base32_exports = {};
476
- __export(base32_exports, {
477
- base32: () => base32,
478
- base32hex: () => base32hex,
479
- base32hexpad: () => base32hexpad,
480
- base32hexpadupper: () => base32hexpadupper,
481
- base32hexupper: () => base32hexupper,
482
- base32pad: () => base32pad,
483
- base32padupper: () => base32padupper,
484
- base32upper: () => base32upper,
485
- base32z: () => base32z
486
- });
487
- var base32 = rfc4648({
488
- prefix: "b",
489
- name: "base32",
490
- alphabet: "abcdefghijklmnopqrstuvwxyz234567",
491
- bitsPerChar: 5
492
- });
493
- var base32upper = rfc4648({
494
- prefix: "B",
495
- name: "base32upper",
496
- alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
497
- bitsPerChar: 5
498
- });
499
- var base32pad = rfc4648({
500
- prefix: "c",
501
- name: "base32pad",
502
- alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
503
- bitsPerChar: 5
504
- });
505
- var base32padupper = rfc4648({
506
- prefix: "C",
507
- name: "base32padupper",
508
- alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
509
- bitsPerChar: 5
510
- });
511
- var base32hex = rfc4648({
512
- prefix: "v",
513
- name: "base32hex",
514
- alphabet: "0123456789abcdefghijklmnopqrstuv",
515
- bitsPerChar: 5
516
- });
517
- var base32hexupper = rfc4648({
518
- prefix: "V",
519
- name: "base32hexupper",
520
- alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
521
- bitsPerChar: 5
522
- });
523
- var base32hexpad = rfc4648({
524
- prefix: "t",
525
- name: "base32hexpad",
526
- alphabet: "0123456789abcdefghijklmnopqrstuv=",
527
- bitsPerChar: 5
528
- });
529
- var base32hexpadupper = rfc4648({
530
- prefix: "T",
531
- name: "base32hexpadupper",
532
- alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
533
- bitsPerChar: 5
534
- });
535
- var base32z = rfc4648({
536
- prefix: "h",
537
- name: "base32z",
538
- alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
539
- bitsPerChar: 5
540
- });
541
-
542
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/bases/base36.js
543
- var base36_exports = {};
544
- __export(base36_exports, {
545
- base36: () => base36,
546
- base36upper: () => base36upper
547
- });
548
- var base36 = baseX({
549
- prefix: "k",
550
- name: "base36",
551
- alphabet: "0123456789abcdefghijklmnopqrstuvwxyz"
552
- });
553
- var base36upper = baseX({
554
- prefix: "K",
555
- name: "base36upper",
556
- alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
557
- });
558
-
559
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/bases/base58.js
560
- var base58_exports = {};
561
- __export(base58_exports, {
562
- base58btc: () => base58btc,
563
- base58flickr: () => base58flickr
564
- });
565
- var base58btc = baseX({
566
- name: "base58btc",
567
- prefix: "z",
568
- alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
569
- });
570
- var base58flickr = baseX({
571
- name: "base58flickr",
572
- prefix: "Z",
573
- alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
574
- });
575
-
576
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/bases/base64.js
577
- var base64_exports = {};
578
- __export(base64_exports, {
579
- base64: () => base64,
580
- base64pad: () => base64pad,
581
- base64url: () => base64url,
582
- base64urlpad: () => base64urlpad
583
- });
584
- var base64 = rfc4648({
585
- prefix: "m",
586
- name: "base64",
587
- alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
588
- bitsPerChar: 6
589
- });
590
- var base64pad = rfc4648({
591
- prefix: "M",
592
- name: "base64pad",
593
- alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
594
- bitsPerChar: 6
595
- });
596
- var base64url = rfc4648({
597
- prefix: "u",
598
- name: "base64url",
599
- alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
600
- bitsPerChar: 6
601
- });
602
- var base64urlpad = rfc4648({
603
- prefix: "U",
604
- name: "base64urlpad",
605
- alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",
606
- bitsPerChar: 6
607
- });
608
-
609
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/bases/base256emoji.js
610
- var base256emoji_exports = {};
611
- __export(base256emoji_exports, {
612
- base256emoji: () => base256emoji
613
- });
614
- var alphabet = Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}");
615
- var alphabetBytesToChars = alphabet.reduce((p, c, i) => {
616
- p[i] = c;
617
- return p;
618
- }, []);
619
- var alphabetCharsToBytes = alphabet.reduce((p, c, i) => {
620
- p[c.codePointAt(0)] = i;
621
- return p;
622
- }, []);
623
- function encode2(data) {
624
- return data.reduce((p, c) => {
625
- p += alphabetBytesToChars[c];
626
- return p;
627
- }, "");
628
- }
629
- function decode2(str) {
630
- const byts = [];
631
- for (const char of str) {
632
- const byt = alphabetCharsToBytes[char.codePointAt(0)];
633
- if (byt === void 0) {
634
- throw new Error(`Non-base256emoji character: ${char}`);
635
- }
636
- byts.push(byt);
637
- }
638
- return new Uint8Array(byts);
639
- }
640
- var base256emoji = from({
641
- prefix: "\u{1F680}",
642
- name: "base256emoji",
643
- encode: encode2,
644
- decode: decode2
645
- });
646
-
647
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/hashes/sha2.js
648
- var sha2_exports = {};
649
- __export(sha2_exports, {
650
- sha256: () => sha256,
651
- sha512: () => sha512
652
- });
653
- var import_crypto = __toESM(require("crypto"), 1);
654
-
655
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/vendor/varint.js
656
- var encode_1 = encode3;
657
- var MSB = 128;
658
- var REST = 127;
659
- var MSBALL = ~REST;
660
- var INT = Math.pow(2, 31);
661
- function encode3(num, out, offset) {
662
- out = out || [];
663
- offset = offset || 0;
664
- var oldOffset = offset;
665
- while (num >= INT) {
666
- out[offset++] = num & 255 | MSB;
667
- num /= 128;
668
- }
669
- while (num & MSBALL) {
670
- out[offset++] = num & 255 | MSB;
671
- num >>>= 7;
672
- }
673
- out[offset] = num | 0;
674
- encode3.bytes = offset - oldOffset + 1;
675
- return out;
676
- }
677
- var decode3 = read;
678
- var MSB$1 = 128;
679
- var REST$1 = 127;
680
- function read(buf, offset) {
681
- var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
682
- do {
683
- if (counter >= l) {
684
- read.bytes = 0;
685
- throw new RangeError("Could not decode varint");
686
- }
687
- b = buf[counter++];
688
- res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
689
- shift += 7;
690
- } while (b >= MSB$1);
691
- read.bytes = counter - offset;
692
- return res;
693
- }
694
- var N1 = Math.pow(2, 7);
695
- var N2 = Math.pow(2, 14);
696
- var N3 = Math.pow(2, 21);
697
- var N4 = Math.pow(2, 28);
698
- var N5 = Math.pow(2, 35);
699
- var N6 = Math.pow(2, 42);
700
- var N7 = Math.pow(2, 49);
701
- var N8 = Math.pow(2, 56);
702
- var N9 = Math.pow(2, 63);
703
- var length = function(value) {
704
- return value < N1 ? 1 : value < N2 ? 2 : value < N3 ? 3 : value < N4 ? 4 : value < N5 ? 5 : value < N6 ? 6 : value < N7 ? 7 : value < N8 ? 8 : value < N9 ? 9 : 10;
705
- };
706
- var varint = {
707
- encode: encode_1,
708
- decode: decode3,
709
- encodingLength: length
710
- };
711
- var _brrp_varint = varint;
712
- var varint_default = _brrp_varint;
713
-
714
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/varint.js
715
- var decode4 = (data, offset = 0) => {
716
- const code2 = varint_default.decode(data, offset);
717
- return [
718
- code2,
719
- varint_default.decode.bytes
720
- ];
721
- };
722
- var encodeTo = (int, target, offset = 0) => {
723
- varint_default.encode(int, target, offset);
724
- return target;
725
- };
726
- var encodingLength = (int) => {
727
- return varint_default.encodingLength(int);
728
- };
729
-
730
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/hashes/digest.js
731
- var create = (code2, digest2) => {
732
- const size = digest2.byteLength;
733
- const sizeOffset = encodingLength(code2);
734
- const digestOffset = sizeOffset + encodingLength(size);
735
- const bytes2 = new Uint8Array(digestOffset + size);
736
- encodeTo(code2, bytes2, 0);
737
- encodeTo(size, bytes2, sizeOffset);
738
- bytes2.set(digest2, digestOffset);
739
- return new Digest(code2, size, digest2, bytes2);
740
- };
741
- var decode5 = (multihash) => {
742
- const bytes2 = coerce(multihash);
743
- const [code2, sizeOffset] = decode4(bytes2);
744
- const [size, digestOffset] = decode4(bytes2.subarray(sizeOffset));
745
- const digest2 = bytes2.subarray(sizeOffset + digestOffset);
746
- if (digest2.byteLength !== size) {
747
- throw new Error("Incorrect length");
748
- }
749
- return new Digest(code2, size, digest2, bytes2);
750
- };
751
- var equals3 = (a, b) => {
752
- if (a === b) {
753
- return true;
754
- } else {
755
- return a.code === b.code && a.size === b.size && equals2(a.bytes, b.bytes);
756
- }
757
- };
758
- var Digest = class {
759
- constructor(code2, size, digest2, bytes2) {
760
- this.code = code2;
761
- this.size = size;
762
- this.digest = digest2;
763
- this.bytes = bytes2;
764
- }
765
- };
766
-
767
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/hashes/hasher.js
768
- var from2 = ({ name: name2, code: code2, encode: encode5 }) => new Hasher(name2, code2, encode5);
769
- var Hasher = class {
770
- constructor(name2, code2, encode5) {
771
- this.name = name2;
772
- this.code = code2;
773
- this.encode = encode5;
774
- }
775
- digest(input) {
776
- if (input instanceof Uint8Array) {
777
- const result = this.encode(input);
778
- return result instanceof Uint8Array ? create(this.code, result) : result.then((digest2) => create(this.code, digest2));
779
- } else {
780
- throw Error("Unknown type, must be binary type");
781
- }
782
- }
783
- };
784
-
785
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/hashes/sha2.js
786
- var sha256 = from2({
787
- name: "sha2-256",
788
- code: 18,
789
- encode: (input) => coerce(import_crypto.default.createHash("sha256").update(input).digest())
790
- });
791
- var sha512 = from2({
792
- name: "sha2-512",
793
- code: 19,
794
- encode: (input) => coerce(import_crypto.default.createHash("sha512").update(input).digest())
795
- });
796
-
797
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/hashes/identity.js
798
- var identity_exports2 = {};
799
- __export(identity_exports2, {
800
- identity: () => identity2
801
- });
802
- var code = 0;
803
- var name = "identity";
804
- var encode4 = coerce;
805
- var digest = (input) => create(code, encode4(input));
806
- var identity2 = {
807
- code,
808
- name,
809
- encode: encode4,
810
- digest
811
- };
812
-
813
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/codecs/json.js
814
- var textEncoder = new TextEncoder();
815
- var textDecoder = new TextDecoder();
816
-
817
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/cid.js
818
- var CID = class {
819
- constructor(version2, code2, multihash, bytes2) {
820
- this.code = code2;
821
- this.version = version2;
822
- this.multihash = multihash;
823
- this.bytes = bytes2;
824
- this.byteOffset = bytes2.byteOffset;
825
- this.byteLength = bytes2.byteLength;
826
- this.asCID = this;
827
- this._baseCache = /* @__PURE__ */ new Map();
828
- Object.defineProperties(this, {
829
- byteOffset: hidden,
830
- byteLength: hidden,
831
- code: readonly,
832
- version: readonly,
833
- multihash: readonly,
834
- bytes: readonly,
835
- _baseCache: hidden,
836
- asCID: hidden
837
- });
838
- }
839
- toV0() {
840
- switch (this.version) {
841
- case 0: {
842
- return this;
843
- }
844
- default: {
845
- const { code: code2, multihash } = this;
846
- if (code2 !== DAG_PB_CODE) {
847
- throw new Error("Cannot convert a non dag-pb CID to CIDv0");
848
- }
849
- if (multihash.code !== SHA_256_CODE) {
850
- throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
851
- }
852
- return CID.createV0(multihash);
853
- }
854
- }
855
- }
856
- toV1() {
857
- switch (this.version) {
858
- case 0: {
859
- const { code: code2, digest: digest2 } = this.multihash;
860
- const multihash = create(code2, digest2);
861
- return CID.createV1(this.code, multihash);
862
- }
863
- case 1: {
864
- return this;
865
- }
866
- default: {
867
- throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
868
- }
869
- }
870
- }
871
- equals(other) {
872
- return other && this.code === other.code && this.version === other.version && equals3(this.multihash, other.multihash);
873
- }
874
- toString(base3) {
875
- const { bytes: bytes2, version: version2, _baseCache } = this;
876
- switch (version2) {
877
- case 0:
878
- return toStringV0(bytes2, _baseCache, base3 || base58btc.encoder);
879
- default:
880
- return toStringV1(bytes2, _baseCache, base3 || base32.encoder);
881
- }
882
- }
883
- toJSON() {
884
- return {
885
- code: this.code,
886
- version: this.version,
887
- hash: this.multihash.bytes
888
- };
889
- }
890
- get [Symbol.toStringTag]() {
891
- return "CID";
892
- }
893
- [Symbol.for("nodejs.util.inspect.custom")]() {
894
- return "CID(" + this.toString() + ")";
895
- }
896
- static isCID(value) {
897
- deprecate(/^0\.0/, IS_CID_DEPRECATION);
898
- return !!(value && (value[cidSymbol] || value.asCID === value));
899
- }
900
- get toBaseEncodedString() {
901
- throw new Error("Deprecated, use .toString()");
902
- }
903
- get codec() {
904
- throw new Error('"codec" property is deprecated, use integer "code" property instead');
905
- }
906
- get buffer() {
907
- throw new Error("Deprecated .buffer property, use .bytes to get Uint8Array instead");
908
- }
909
- get multibaseName() {
910
- throw new Error('"multibaseName" property is deprecated');
911
- }
912
- get prefix() {
913
- throw new Error('"prefix" property is deprecated');
914
- }
915
- static asCID(value) {
916
- if (value instanceof CID) {
917
- return value;
918
- } else if (value != null && value.asCID === value) {
919
- const { version: version2, code: code2, multihash, bytes: bytes2 } = value;
920
- return new CID(version2, code2, multihash, bytes2 || encodeCID(version2, code2, multihash.bytes));
921
- } else if (value != null && value[cidSymbol] === true) {
922
- const { version: version2, multihash, code: code2 } = value;
923
- const digest2 = decode5(multihash);
924
- return CID.create(version2, code2, digest2);
925
- } else {
926
- return null;
927
- }
928
- }
929
- static create(version2, code2, digest2) {
930
- if (typeof code2 !== "number") {
931
- throw new Error("String codecs are no longer supported");
932
- }
933
- switch (version2) {
934
- case 0: {
935
- if (code2 !== DAG_PB_CODE) {
936
- throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
937
- } else {
938
- return new CID(version2, code2, digest2, digest2.bytes);
939
- }
940
- }
941
- case 1: {
942
- const bytes2 = encodeCID(version2, code2, digest2.bytes);
943
- return new CID(version2, code2, digest2, bytes2);
944
- }
945
- default: {
946
- throw new Error("Invalid version");
947
- }
948
- }
949
- }
950
- static createV0(digest2) {
951
- return CID.create(0, DAG_PB_CODE, digest2);
952
- }
953
- static createV1(code2, digest2) {
954
- return CID.create(1, code2, digest2);
955
- }
956
- static decode(bytes2) {
957
- const [cid, remainder] = CID.decodeFirst(bytes2);
958
- if (remainder.length) {
959
- throw new Error("Incorrect length");
960
- }
961
- return cid;
962
- }
963
- static decodeFirst(bytes2) {
964
- const specs = CID.inspectBytes(bytes2);
965
- const prefixSize = specs.size - specs.multihashSize;
966
- const multihashBytes = coerce(bytes2.subarray(prefixSize, prefixSize + specs.multihashSize));
967
- if (multihashBytes.byteLength !== specs.multihashSize) {
968
- throw new Error("Incorrect length");
969
- }
970
- const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
971
- const digest2 = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
972
- const cid = specs.version === 0 ? CID.createV0(digest2) : CID.createV1(specs.codec, digest2);
973
- return [
974
- cid,
975
- bytes2.subarray(specs.size)
976
- ];
977
- }
978
- static inspectBytes(initialBytes) {
979
- let offset = 0;
980
- const next = () => {
981
- const [i, length2] = decode4(initialBytes.subarray(offset));
982
- offset += length2;
983
- return i;
984
- };
985
- let version2 = next();
986
- let codec = DAG_PB_CODE;
987
- if (version2 === 18) {
988
- version2 = 0;
989
- offset = 0;
990
- } else if (version2 === 1) {
991
- codec = next();
992
- }
993
- if (version2 !== 0 && version2 !== 1) {
994
- throw new RangeError(`Invalid CID version ${version2}`);
995
- }
996
- const prefixSize = offset;
997
- const multihashCode = next();
998
- const digestSize = next();
999
- const size = offset + digestSize;
1000
- const multihashSize = size - prefixSize;
1001
- return {
1002
- version: version2,
1003
- codec,
1004
- multihashCode,
1005
- digestSize,
1006
- multihashSize,
1007
- size
1008
- };
1009
- }
1010
- static parse(source, base3) {
1011
- const [prefix, bytes2] = parseCIDtoBytes(source, base3);
1012
- const cid = CID.decode(bytes2);
1013
- cid._baseCache.set(prefix, source);
1014
- return cid;
1015
- }
1016
- };
1017
- var parseCIDtoBytes = (source, base3) => {
1018
- switch (source[0]) {
1019
- case "Q": {
1020
- const decoder = base3 || base58btc;
1021
- return [
1022
- base58btc.prefix,
1023
- decoder.decode(`${base58btc.prefix}${source}`)
1024
- ];
1025
- }
1026
- case base58btc.prefix: {
1027
- const decoder = base3 || base58btc;
1028
- return [
1029
- base58btc.prefix,
1030
- decoder.decode(source)
1031
- ];
1032
- }
1033
- case base32.prefix: {
1034
- const decoder = base3 || base32;
1035
- return [
1036
- base32.prefix,
1037
- decoder.decode(source)
1038
- ];
1039
- }
1040
- default: {
1041
- if (base3 == null) {
1042
- throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");
1043
- }
1044
- return [
1045
- source[0],
1046
- base3.decode(source)
1047
- ];
1048
- }
1049
- }
1050
- };
1051
- var toStringV0 = (bytes2, cache, base3) => {
1052
- const { prefix } = base3;
1053
- if (prefix !== base58btc.prefix) {
1054
- throw Error(`Cannot string encode V0 in ${base3.name} encoding`);
1055
- }
1056
- const cid = cache.get(prefix);
1057
- if (cid == null) {
1058
- const cid2 = base3.encode(bytes2).slice(1);
1059
- cache.set(prefix, cid2);
1060
- return cid2;
1061
- } else {
1062
- return cid;
1063
- }
1064
- };
1065
- var toStringV1 = (bytes2, cache, base3) => {
1066
- const { prefix } = base3;
1067
- const cid = cache.get(prefix);
1068
- if (cid == null) {
1069
- const cid2 = base3.encode(bytes2);
1070
- cache.set(prefix, cid2);
1071
- return cid2;
1072
- } else {
1073
- return cid;
1074
- }
1075
- };
1076
- var DAG_PB_CODE = 112;
1077
- var SHA_256_CODE = 18;
1078
- var encodeCID = (version2, code2, multihash) => {
1079
- const codeOffset = encodingLength(version2);
1080
- const hashOffset = codeOffset + encodingLength(code2);
1081
- const bytes2 = new Uint8Array(hashOffset + multihash.byteLength);
1082
- encodeTo(version2, bytes2, 0);
1083
- encodeTo(code2, bytes2, codeOffset);
1084
- bytes2.set(multihash, hashOffset);
1085
- return bytes2;
1086
- };
1087
- var cidSymbol = Symbol.for("@ipld/js-cid/CID");
1088
- var readonly = {
1089
- writable: false,
1090
- configurable: false,
1091
- enumerable: true
1092
- };
1093
- var hidden = {
1094
- writable: false,
1095
- enumerable: false,
1096
- configurable: false
1097
- };
1098
- var version = "0.0.0-dev";
1099
- var deprecate = (range, message) => {
1100
- if (range.test(version)) {
1101
- console.warn(message);
1102
- } else {
1103
- throw new Error(message);
1104
- }
1105
- };
1106
- var IS_CID_DEPRECATION = `CID.isCID(v) is deprecated and will be removed in the next major release.
1107
- Following code pattern:
1108
-
1109
- if (CID.isCID(value)) {
1110
- doSomethingWithCID(value)
1111
- }
1112
-
1113
- Is replaced with:
1114
-
1115
- const cid = CID.asCID(value)
1116
- if (cid) {
1117
- // Make sure to use cid instead of value
1118
- doSomethingWithCID(cid)
1119
- }
1120
- `;
1121
-
1122
- // ../../node_modules/.pnpm/multiformats@9.9.0/node_modules/multiformats/esm/src/basics.js
1123
- var bases = {
1124
- ...identity_exports,
1125
- ...base2_exports,
1126
- ...base8_exports,
1127
- ...base10_exports,
1128
- ...base16_exports,
1129
- ...base32_exports,
1130
- ...base36_exports,
1131
- ...base58_exports,
1132
- ...base64_exports,
1133
- ...base256emoji_exports
1134
- };
1135
- var hashes = {
1136
- ...sha2_exports,
1137
- ...identity_exports2
1138
- };
1139
-
1140
- // ../../node_modules/.pnpm/uint8arrays@3.0.0/node_modules/uint8arrays/esm/src/util/bases.js
1141
- function createCodec(name2, prefix, encode5, decode6) {
1142
- return {
1143
- name: name2,
1144
- prefix,
1145
- encoder: {
1146
- name: name2,
1147
- prefix,
1148
- encode: encode5
1149
- },
1150
- decoder: { decode: decode6 }
1151
- };
1152
- }
1153
- var string = createCodec("utf8", "u", (buf) => {
1154
- const decoder = new TextDecoder("utf8");
1155
- return "u" + decoder.decode(buf);
1156
- }, (str) => {
1157
- const encoder = new TextEncoder();
1158
- return encoder.encode(str.substring(1));
1159
- });
1160
- var ascii = createCodec("ascii", "a", (buf) => {
1161
- let string2 = "a";
1162
- for (let i = 0; i < buf.length; i++) {
1163
- string2 += String.fromCharCode(buf[i]);
1164
- }
1165
- return string2;
1166
- }, (str) => {
1167
- str = str.substring(1);
1168
- const buf = new Uint8Array(str.length);
1169
- for (let i = 0; i < str.length; i++) {
1170
- buf[i] = str.charCodeAt(i);
1171
- }
1172
- return buf;
1173
- });
1174
- var BASES = {
1175
- utf8: string,
1176
- "utf-8": string,
1177
- hex: bases.base16,
1178
- latin1: ascii,
1179
- ascii,
1180
- binary: ascii,
1181
- ...bases
1182
- };
1183
- var bases_default = BASES;
1184
-
1185
- // ../../node_modules/.pnpm/uint8arrays@3.0.0/node_modules/uint8arrays/esm/src/from-string.js
1186
- function fromString2(string2, encoding = "utf8") {
1187
- const base3 = bases_default[encoding];
1188
- if (!base3) {
1189
- throw new Error(`Unsupported encoding "${encoding}"`);
1190
- }
1191
- return base3.decoder.decode(`${base3.prefix}${string2}`);
1192
- }
1193
-
1194
- // ../../node_modules/.pnpm/uint8arrays@3.0.0/node_modules/uint8arrays/esm/src/to-string.js
1195
- function toString2(array, encoding = "utf8") {
1196
- const base3 = bases_default[encoding];
1197
- if (!base3) {
1198
- throw new Error(`Unsupported encoding "${encoding}"`);
1199
- }
1200
- return base3.encoder.encode(array).substring(1);
1201
- }
1202
-
1203
- // ../../node_modules/.pnpm/@noble+hashes@1.3.1/node_modules/@noble/hashes/esm/_assert.js
1204
- function number(n) {
1205
- if (!Number.isSafeInteger(n) || n < 0)
1206
- throw new Error(`Wrong positive integer: ${n}`);
1207
- }
1208
- function bool(b) {
1209
- if (typeof b !== "boolean")
1210
- throw new Error(`Expected boolean, not ${b}`);
1211
- }
1212
- function bytes(b, ...lengths) {
1213
- if (!(b instanceof Uint8Array))
1214
- throw new Error("Expected Uint8Array");
1215
- if (lengths.length > 0 && !lengths.includes(b.length))
1216
- throw new Error(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`);
1217
- }
1218
- function hash(hash2) {
1219
- if (typeof hash2 !== "function" || typeof hash2.create !== "function")
1220
- throw new Error("Hash should be wrapped by utils.wrapConstructor");
1221
- number(hash2.outputLen);
1222
- number(hash2.blockLen);
1223
- }
1224
- function exists(instance, checkFinished = true) {
1225
- if (instance.destroyed)
1226
- throw new Error("Hash instance has been destroyed");
1227
- if (checkFinished && instance.finished)
1228
- throw new Error("Hash#digest() has already been called");
1229
- }
1230
- function output(out, instance) {
1231
- bytes(out);
1232
- const min = instance.outputLen;
1233
- if (out.length < min) {
1234
- throw new Error(`digestInto() expects output buffer of length at least ${min}`);
1235
- }
1236
- }
1237
- var assert = {
1238
- number,
1239
- bool,
1240
- bytes,
1241
- hash,
1242
- exists,
1243
- output
1244
- };
1245
- var assert_default = assert;
1246
-
1247
- // ../../node_modules/.pnpm/@noble+hashes@1.3.1/node_modules/@noble/hashes/esm/cryptoNode.js
1248
- var nc = __toESM(require("node:crypto"), 1);
1249
- var crypto2 = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : void 0;
1250
-
1251
- // ../../node_modules/.pnpm/@noble+hashes@1.3.1/node_modules/@noble/hashes/esm/utils.js
1252
- var u8a = (a) => a instanceof Uint8Array;
1253
- var createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
1254
- var rotr = (word, shift) => word << 32 - shift | word >>> shift;
1255
- var isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
1256
- if (!isLE)
1257
- throw new Error("Non little-endian hardware is not supported");
1258
- var hexes = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, "0"));
1259
- function utf8ToBytes(str) {
1260
- if (typeof str !== "string")
1261
- throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
1262
- return new Uint8Array(new TextEncoder().encode(str));
1263
- }
1264
- function toBytes(data) {
1265
- if (typeof data === "string")
1266
- data = utf8ToBytes(data);
1267
- if (!u8a(data))
1268
- throw new Error(`expected Uint8Array, got ${typeof data}`);
1269
- return data;
1270
- }
1271
- function concatBytes(...arrays) {
1272
- const r = new Uint8Array(arrays.reduce((sum, a) => sum + a.length, 0));
1273
- let pad = 0;
1274
- arrays.forEach((a) => {
1275
- if (!u8a(a))
1276
- throw new Error("Uint8Array expected");
1277
- r.set(a, pad);
1278
- pad += a.length;
1279
- });
1280
- return r;
1281
- }
1282
- var Hash = class {
1283
- clone() {
1284
- return this._cloneInto();
1285
- }
1286
- };
1287
- function wrapConstructor(hashCons) {
1288
- const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
1289
- const tmp = hashCons();
1290
- hashC.outputLen = tmp.outputLen;
1291
- hashC.blockLen = tmp.blockLen;
1292
- hashC.create = () => hashCons();
1293
- return hashC;
1294
- }
1295
- function randomBytes(bytesLength = 32) {
1296
- if (crypto2 && typeof crypto2.getRandomValues === "function") {
1297
- return crypto2.getRandomValues(new Uint8Array(bytesLength));
1298
- }
1299
- throw new Error("crypto.getRandomValues must be defined");
1300
- }
1301
-
1302
- // ../../node_modules/.pnpm/@noble+hashes@1.3.1/node_modules/@noble/hashes/esm/hmac.js
1303
- var HMAC = class extends Hash {
1304
- constructor(hash2, _key) {
1305
- super();
1306
- this.finished = false;
1307
- this.destroyed = false;
1308
- assert_default.hash(hash2);
1309
- const key = toBytes(_key);
1310
- this.iHash = hash2.create();
1311
- if (typeof this.iHash.update !== "function")
1312
- throw new Error("Expected instance of class which extends utils.Hash");
1313
- this.blockLen = this.iHash.blockLen;
1314
- this.outputLen = this.iHash.outputLen;
1315
- const blockLen = this.blockLen;
1316
- const pad = new Uint8Array(blockLen);
1317
- pad.set(key.length > blockLen ? hash2.create().update(key).digest() : key);
1318
- for (let i = 0; i < pad.length; i++)
1319
- pad[i] ^= 54;
1320
- this.iHash.update(pad);
1321
- this.oHash = hash2.create();
1322
- for (let i = 0; i < pad.length; i++)
1323
- pad[i] ^= 54 ^ 92;
1324
- this.oHash.update(pad);
1325
- pad.fill(0);
1326
- }
1327
- update(buf) {
1328
- assert_default.exists(this);
1329
- this.iHash.update(buf);
1330
- return this;
1331
- }
1332
- digestInto(out) {
1333
- assert_default.exists(this);
1334
- assert_default.bytes(out, this.outputLen);
1335
- this.finished = true;
1336
- this.iHash.digestInto(out);
1337
- this.oHash.update(out);
1338
- this.oHash.digestInto(out);
1339
- this.destroy();
1340
- }
1341
- digest() {
1342
- const out = new Uint8Array(this.oHash.outputLen);
1343
- this.digestInto(out);
1344
- return out;
1345
- }
1346
- _cloneInto(to) {
1347
- to || (to = Object.create(Object.getPrototypeOf(this), {}));
1348
- const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
1349
- to = to;
1350
- to.finished = finished;
1351
- to.destroyed = destroyed;
1352
- to.blockLen = blockLen;
1353
- to.outputLen = outputLen;
1354
- to.oHash = oHash._cloneInto(to.oHash);
1355
- to.iHash = iHash._cloneInto(to.iHash);
1356
- return to;
1357
- }
1358
- destroy() {
1359
- this.destroyed = true;
1360
- this.oHash.destroy();
1361
- this.iHash.destroy();
1362
- }
1363
- };
1364
- var hmac = (hash2, key, message) => new HMAC(hash2, key).update(message).digest();
1365
- hmac.create = (hash2, key) => new HMAC(hash2, key);
1366
-
1367
- // ../../node_modules/.pnpm/@noble+curves@1.1.0/node_modules/@noble/curves/esm/abstract/utils.js
1368
- var utils_exports = {};
1369
- __export(utils_exports, {
1370
- bitGet: () => bitGet,
1371
- bitLen: () => bitLen,
1372
- bitMask: () => bitMask,
1373
- bitSet: () => bitSet,
1374
- bytesToHex: () => bytesToHex,
1375
- bytesToNumberBE: () => bytesToNumberBE,
1376
- bytesToNumberLE: () => bytesToNumberLE,
1377
- concatBytes: () => concatBytes2,
1378
- createHmacDrbg: () => createHmacDrbg,
1379
- ensureBytes: () => ensureBytes,
1380
- equalBytes: () => equalBytes,
1381
- hexToBytes: () => hexToBytes,
1382
- hexToNumber: () => hexToNumber,
1383
- numberToBytesBE: () => numberToBytesBE,
1384
- numberToBytesLE: () => numberToBytesLE,
1385
- numberToHexUnpadded: () => numberToHexUnpadded,
1386
- numberToVarBytesBE: () => numberToVarBytesBE,
1387
- utf8ToBytes: () => utf8ToBytes2,
1388
- validateObject: () => validateObject
1389
- });
1390
- var _0n = BigInt(0);
1391
- var _1n = BigInt(1);
1392
- var _2n = BigInt(2);
1393
- var u8a2 = (a) => a instanceof Uint8Array;
1394
- var hexes2 = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, "0"));
1395
- function bytesToHex(bytes2) {
1396
- if (!u8a2(bytes2))
1397
- throw new Error("Uint8Array expected");
1398
- let hex = "";
1399
- for (let i = 0; i < bytes2.length; i++) {
1400
- hex += hexes2[bytes2[i]];
1401
- }
1402
- return hex;
1403
- }
1404
- function numberToHexUnpadded(num) {
1405
- const hex = num.toString(16);
1406
- return hex.length & 1 ? `0${hex}` : hex;
1407
- }
1408
- function hexToNumber(hex) {
1409
- if (typeof hex !== "string")
1410
- throw new Error("hex string expected, got " + typeof hex);
1411
- return BigInt(hex === "" ? "0" : `0x${hex}`);
1412
- }
1413
- function hexToBytes(hex) {
1414
- if (typeof hex !== "string")
1415
- throw new Error("hex string expected, got " + typeof hex);
1416
- const len = hex.length;
1417
- if (len % 2)
1418
- throw new Error("padded hex string expected, got unpadded hex of length " + len);
1419
- const array = new Uint8Array(len / 2);
1420
- for (let i = 0; i < array.length; i++) {
1421
- const j = i * 2;
1422
- const hexByte = hex.slice(j, j + 2);
1423
- const byte = Number.parseInt(hexByte, 16);
1424
- if (Number.isNaN(byte) || byte < 0)
1425
- throw new Error("Invalid byte sequence");
1426
- array[i] = byte;
1427
- }
1428
- return array;
1429
- }
1430
- function bytesToNumberBE(bytes2) {
1431
- return hexToNumber(bytesToHex(bytes2));
1432
- }
1433
- function bytesToNumberLE(bytes2) {
1434
- if (!u8a2(bytes2))
1435
- throw new Error("Uint8Array expected");
1436
- return hexToNumber(bytesToHex(Uint8Array.from(bytes2).reverse()));
1437
- }
1438
- function numberToBytesBE(n, len) {
1439
- return hexToBytes(n.toString(16).padStart(len * 2, "0"));
1440
- }
1441
- function numberToBytesLE(n, len) {
1442
- return numberToBytesBE(n, len).reverse();
1443
- }
1444
- function numberToVarBytesBE(n) {
1445
- return hexToBytes(numberToHexUnpadded(n));
1446
- }
1447
- function ensureBytes(title, hex, expectedLength) {
1448
- let res;
1449
- if (typeof hex === "string") {
1450
- try {
1451
- res = hexToBytes(hex);
1452
- } catch (e) {
1453
- throw new Error(`${title} must be valid hex string, got "${hex}". Cause: ${e}`);
1454
- }
1455
- } else if (u8a2(hex)) {
1456
- res = Uint8Array.from(hex);
1457
- } else {
1458
- throw new Error(`${title} must be hex string or Uint8Array`);
1459
- }
1460
- const len = res.length;
1461
- if (typeof expectedLength === "number" && len !== expectedLength)
1462
- throw new Error(`${title} expected ${expectedLength} bytes, got ${len}`);
1463
- return res;
1464
- }
1465
- function concatBytes2(...arrays) {
1466
- const r = new Uint8Array(arrays.reduce((sum, a) => sum + a.length, 0));
1467
- let pad = 0;
1468
- arrays.forEach((a) => {
1469
- if (!u8a2(a))
1470
- throw new Error("Uint8Array expected");
1471
- r.set(a, pad);
1472
- pad += a.length;
1473
- });
1474
- return r;
1475
- }
1476
- function equalBytes(b1, b2) {
1477
- if (b1.length !== b2.length)
1478
- return false;
1479
- for (let i = 0; i < b1.length; i++)
1480
- if (b1[i] !== b2[i])
1481
- return false;
1482
- return true;
1483
- }
1484
- function utf8ToBytes2(str) {
1485
- if (typeof str !== "string")
1486
- throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
1487
- return new Uint8Array(new TextEncoder().encode(str));
1488
- }
1489
- function bitLen(n) {
1490
- let len;
1491
- for (len = 0; n > _0n; n >>= _1n, len += 1)
1492
- ;
1493
- return len;
1494
- }
1495
- function bitGet(n, pos) {
1496
- return n >> BigInt(pos) & _1n;
1497
- }
1498
- var bitSet = (n, pos, value) => {
1499
- return n | (value ? _1n : _0n) << BigInt(pos);
1500
- };
1501
- var bitMask = (n) => (_2n << BigInt(n - 1)) - _1n;
1502
- var u8n = (data) => new Uint8Array(data);
1503
- var u8fr = (arr) => Uint8Array.from(arr);
1504
- function createHmacDrbg(hashLen, qByteLen, hmacFn) {
1505
- if (typeof hashLen !== "number" || hashLen < 2)
1506
- throw new Error("hashLen must be a number");
1507
- if (typeof qByteLen !== "number" || qByteLen < 2)
1508
- throw new Error("qByteLen must be a number");
1509
- if (typeof hmacFn !== "function")
1510
- throw new Error("hmacFn must be a function");
1511
- let v = u8n(hashLen);
1512
- let k = u8n(hashLen);
1513
- let i = 0;
1514
- const reset = () => {
1515
- v.fill(1);
1516
- k.fill(0);
1517
- i = 0;
1518
- };
1519
- const h = (...b) => hmacFn(k, v, ...b);
1520
- const reseed = (seed = u8n()) => {
1521
- k = h(u8fr([0]), seed);
1522
- v = h();
1523
- if (seed.length === 0)
1524
- return;
1525
- k = h(u8fr([1]), seed);
1526
- v = h();
1527
- };
1528
- const gen = () => {
1529
- if (i++ >= 1e3)
1530
- throw new Error("drbg: tried 1000 values");
1531
- let len = 0;
1532
- const out = [];
1533
- while (len < qByteLen) {
1534
- v = h();
1535
- const sl = v.slice();
1536
- out.push(sl);
1537
- len += v.length;
1538
- }
1539
- return concatBytes2(...out);
1540
- };
1541
- const genUntil = (seed, pred) => {
1542
- reset();
1543
- reseed(seed);
1544
- let res = void 0;
1545
- while (!(res = pred(gen())))
1546
- reseed();
1547
- reset();
1548
- return res;
1549
- };
1550
- return genUntil;
1551
- }
1552
- var validatorFns = {
1553
- bigint: (val) => typeof val === "bigint",
1554
- function: (val) => typeof val === "function",
1555
- boolean: (val) => typeof val === "boolean",
1556
- string: (val) => typeof val === "string",
1557
- isSafeInteger: (val) => Number.isSafeInteger(val),
1558
- array: (val) => Array.isArray(val),
1559
- field: (val, object) => object.Fp.isValid(val),
1560
- hash: (val) => typeof val === "function" && Number.isSafeInteger(val.outputLen)
1561
- };
1562
- function validateObject(object, validators, optValidators = {}) {
1563
- const checkField = (fieldName, type, isOptional) => {
1564
- const checkVal = validatorFns[type];
1565
- if (typeof checkVal !== "function")
1566
- throw new Error(`Invalid validator "${type}", expected function`);
1567
- const val = object[fieldName];
1568
- if (isOptional && val === void 0)
1569
- return;
1570
- if (!checkVal(val, object)) {
1571
- throw new Error(`Invalid param ${String(fieldName)}=${val} (${typeof val}), expected ${type}`);
1572
- }
1573
- };
1574
- for (const [fieldName, type] of Object.entries(validators))
1575
- checkField(fieldName, type, false);
1576
- for (const [fieldName, type] of Object.entries(optValidators))
1577
- checkField(fieldName, type, true);
1578
- return object;
1579
- }
1580
-
1581
- // ../../node_modules/.pnpm/@noble+curves@1.1.0/node_modules/@noble/curves/esm/abstract/modular.js
1582
- var _0n2 = BigInt(0);
1583
- var _1n2 = BigInt(1);
1584
- var _2n2 = BigInt(2);
1585
- var _3n = BigInt(3);
1586
- var _4n = BigInt(4);
1587
- var _5n = BigInt(5);
1588
- var _8n = BigInt(8);
1589
- var _9n = BigInt(9);
1590
- var _16n = BigInt(16);
1591
- function mod(a, b) {
1592
- const result = a % b;
1593
- return result >= _0n2 ? result : b + result;
1594
- }
1595
- function pow(num, power, modulo) {
1596
- if (modulo <= _0n2 || power < _0n2)
1597
- throw new Error("Expected power/modulo > 0");
1598
- if (modulo === _1n2)
1599
- return _0n2;
1600
- let res = _1n2;
1601
- while (power > _0n2) {
1602
- if (power & _1n2)
1603
- res = res * num % modulo;
1604
- num = num * num % modulo;
1605
- power >>= _1n2;
1606
- }
1607
- return res;
1608
- }
1609
- function pow2(x, power, modulo) {
1610
- let res = x;
1611
- while (power-- > _0n2) {
1612
- res *= res;
1613
- res %= modulo;
1614
- }
1615
- return res;
1616
- }
1617
- function invert(number2, modulo) {
1618
- if (number2 === _0n2 || modulo <= _0n2) {
1619
- throw new Error(`invert: expected positive integers, got n=${number2} mod=${modulo}`);
1620
- }
1621
- let a = mod(number2, modulo);
1622
- let b = modulo;
1623
- let x = _0n2, y = _1n2, u = _1n2, v = _0n2;
1624
- while (a !== _0n2) {
1625
- const q = b / a;
1626
- const r = b % a;
1627
- const m = x - u * q;
1628
- const n = y - v * q;
1629
- b = a, a = r, x = u, y = v, u = m, v = n;
1630
- }
1631
- const gcd = b;
1632
- if (gcd !== _1n2)
1633
- throw new Error("invert: does not exist");
1634
- return mod(x, modulo);
1635
- }
1636
- function tonelliShanks(P) {
1637
- const legendreC = (P - _1n2) / _2n2;
1638
- let Q, S, Z;
1639
- for (Q = P - _1n2, S = 0; Q % _2n2 === _0n2; Q /= _2n2, S++)
1640
- ;
1641
- for (Z = _2n2; Z < P && pow(Z, legendreC, P) !== P - _1n2; Z++)
1642
- ;
1643
- if (S === 1) {
1644
- const p1div4 = (P + _1n2) / _4n;
1645
- return function tonelliFast(Fp3, n) {
1646
- const root = Fp3.pow(n, p1div4);
1647
- if (!Fp3.eql(Fp3.sqr(root), n))
1648
- throw new Error("Cannot find square root");
1649
- return root;
1650
- };
1651
- }
1652
- const Q1div2 = (Q + _1n2) / _2n2;
1653
- return function tonelliSlow(Fp3, n) {
1654
- if (Fp3.pow(n, legendreC) === Fp3.neg(Fp3.ONE))
1655
- throw new Error("Cannot find square root");
1656
- let r = S;
1657
- let g = Fp3.pow(Fp3.mul(Fp3.ONE, Z), Q);
1658
- let x = Fp3.pow(n, Q1div2);
1659
- let b = Fp3.pow(n, Q);
1660
- while (!Fp3.eql(b, Fp3.ONE)) {
1661
- if (Fp3.eql(b, Fp3.ZERO))
1662
- return Fp3.ZERO;
1663
- let m = 1;
1664
- for (let t2 = Fp3.sqr(b); m < r; m++) {
1665
- if (Fp3.eql(t2, Fp3.ONE))
1666
- break;
1667
- t2 = Fp3.sqr(t2);
1668
- }
1669
- const ge = Fp3.pow(g, _1n2 << BigInt(r - m - 1));
1670
- g = Fp3.sqr(ge);
1671
- x = Fp3.mul(x, ge);
1672
- b = Fp3.mul(b, g);
1673
- r = m;
1674
- }
1675
- return x;
1676
- };
1677
- }
1678
- function FpSqrt(P) {
1679
- if (P % _4n === _3n) {
1680
- const p1div4 = (P + _1n2) / _4n;
1681
- return function sqrt3mod4(Fp3, n) {
1682
- const root = Fp3.pow(n, p1div4);
1683
- if (!Fp3.eql(Fp3.sqr(root), n))
1684
- throw new Error("Cannot find square root");
1685
- return root;
1686
- };
1687
- }
1688
- if (P % _8n === _5n) {
1689
- const c1 = (P - _5n) / _8n;
1690
- return function sqrt5mod8(Fp3, n) {
1691
- const n2 = Fp3.mul(n, _2n2);
1692
- const v = Fp3.pow(n2, c1);
1693
- const nv = Fp3.mul(n, v);
1694
- const i = Fp3.mul(Fp3.mul(nv, _2n2), v);
1695
- const root = Fp3.mul(nv, Fp3.sub(i, Fp3.ONE));
1696
- if (!Fp3.eql(Fp3.sqr(root), n))
1697
- throw new Error("Cannot find square root");
1698
- return root;
1699
- };
1700
- }
1701
- if (P % _16n === _9n) {
1702
- }
1703
- return tonelliShanks(P);
1704
- }
1705
- var FIELD_FIELDS = [
1706
- "create",
1707
- "isValid",
1708
- "is0",
1709
- "neg",
1710
- "inv",
1711
- "sqrt",
1712
- "sqr",
1713
- "eql",
1714
- "add",
1715
- "sub",
1716
- "mul",
1717
- "pow",
1718
- "div",
1719
- "addN",
1720
- "subN",
1721
- "mulN",
1722
- "sqrN"
1723
- ];
1724
- function validateField(field) {
1725
- const initial = {
1726
- ORDER: "bigint",
1727
- MASK: "bigint",
1728
- BYTES: "isSafeInteger",
1729
- BITS: "isSafeInteger"
1730
- };
1731
- const opts = FIELD_FIELDS.reduce((map, val) => {
1732
- map[val] = "function";
1733
- return map;
1734
- }, initial);
1735
- return validateObject(field, opts);
1736
- }
1737
- function FpPow(f, num, power) {
1738
- if (power < _0n2)
1739
- throw new Error("Expected power > 0");
1740
- if (power === _0n2)
1741
- return f.ONE;
1742
- if (power === _1n2)
1743
- return num;
1744
- let p = f.ONE;
1745
- let d = num;
1746
- while (power > _0n2) {
1747
- if (power & _1n2)
1748
- p = f.mul(p, d);
1749
- d = f.sqr(d);
1750
- power >>= _1n2;
1751
- }
1752
- return p;
1753
- }
1754
- function FpInvertBatch(f, nums) {
1755
- const tmp = new Array(nums.length);
1756
- const lastMultiplied = nums.reduce((acc, num, i) => {
1757
- if (f.is0(num))
1758
- return acc;
1759
- tmp[i] = acc;
1760
- return f.mul(acc, num);
1761
- }, f.ONE);
1762
- const inverted = f.inv(lastMultiplied);
1763
- nums.reduceRight((acc, num, i) => {
1764
- if (f.is0(num))
1765
- return acc;
1766
- tmp[i] = f.mul(acc, tmp[i]);
1767
- return f.mul(acc, num);
1768
- }, inverted);
1769
- return tmp;
1770
- }
1771
- function nLength(n, nBitLength) {
1772
- const _nBitLength = nBitLength !== void 0 ? nBitLength : n.toString(2).length;
1773
- const nByteLength = Math.ceil(_nBitLength / 8);
1774
- return { nBitLength: _nBitLength, nByteLength };
1775
- }
1776
- function Field(ORDER, bitLen2, isLE2 = false, redef = {}) {
1777
- if (ORDER <= _0n2)
1778
- throw new Error(`Expected Fp ORDER > 0, got ${ORDER}`);
1779
- const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, bitLen2);
1780
- if (BYTES > 2048)
1781
- throw new Error("Field lengths over 2048 bytes are not supported");
1782
- const sqrtP = FpSqrt(ORDER);
1783
- const f = Object.freeze({
1784
- ORDER,
1785
- BITS,
1786
- BYTES,
1787
- MASK: bitMask(BITS),
1788
- ZERO: _0n2,
1789
- ONE: _1n2,
1790
- create: (num) => mod(num, ORDER),
1791
- isValid: (num) => {
1792
- if (typeof num !== "bigint")
1793
- throw new Error(`Invalid field element: expected bigint, got ${typeof num}`);
1794
- return _0n2 <= num && num < ORDER;
1795
- },
1796
- is0: (num) => num === _0n2,
1797
- isOdd: (num) => (num & _1n2) === _1n2,
1798
- neg: (num) => mod(-num, ORDER),
1799
- eql: (lhs, rhs) => lhs === rhs,
1800
- sqr: (num) => mod(num * num, ORDER),
1801
- add: (lhs, rhs) => mod(lhs + rhs, ORDER),
1802
- sub: (lhs, rhs) => mod(lhs - rhs, ORDER),
1803
- mul: (lhs, rhs) => mod(lhs * rhs, ORDER),
1804
- pow: (num, power) => FpPow(f, num, power),
1805
- div: (lhs, rhs) => mod(lhs * invert(rhs, ORDER), ORDER),
1806
- sqrN: (num) => num * num,
1807
- addN: (lhs, rhs) => lhs + rhs,
1808
- subN: (lhs, rhs) => lhs - rhs,
1809
- mulN: (lhs, rhs) => lhs * rhs,
1810
- inv: (num) => invert(num, ORDER),
1811
- sqrt: redef.sqrt || ((n) => sqrtP(f, n)),
1812
- invertBatch: (lst) => FpInvertBatch(f, lst),
1813
- cmov: (a, b, c) => c ? b : a,
1814
- toBytes: (num) => isLE2 ? numberToBytesLE(num, BYTES) : numberToBytesBE(num, BYTES),
1815
- fromBytes: (bytes2) => {
1816
- if (bytes2.length !== BYTES)
1817
- throw new Error(`Fp.fromBytes: expected ${BYTES}, got ${bytes2.length}`);
1818
- return isLE2 ? bytesToNumberLE(bytes2) : bytesToNumberBE(bytes2);
1819
- }
1820
- });
1821
- return Object.freeze(f);
1822
- }
1823
- function hashToPrivateScalar(hash2, groupOrder, isLE2 = false) {
1824
- hash2 = ensureBytes("privateHash", hash2);
1825
- const hashLen = hash2.length;
1826
- const minLen = nLength(groupOrder).nByteLength + 8;
1827
- if (minLen < 24 || hashLen < minLen || hashLen > 1024)
1828
- throw new Error(`hashToPrivateScalar: expected ${minLen}-1024 bytes of input, got ${hashLen}`);
1829
- const num = isLE2 ? bytesToNumberLE(hash2) : bytesToNumberBE(hash2);
1830
- return mod(num, groupOrder - _1n2) + _1n2;
1831
- }
1832
-
1833
- // ../../node_modules/.pnpm/@noble+curves@1.1.0/node_modules/@noble/curves/esm/abstract/curve.js
1834
- var _0n3 = BigInt(0);
1835
- var _1n3 = BigInt(1);
1836
- function wNAF(c, bits) {
1837
- const constTimeNegate = (condition, item) => {
1838
- const neg = item.negate();
1839
- return condition ? neg : item;
1840
- };
1841
- const opts = (W) => {
1842
- const windows = Math.ceil(bits / W) + 1;
1843
- const windowSize = 2 ** (W - 1);
1844
- return { windows, windowSize };
1845
- };
1846
- return {
1847
- constTimeNegate,
1848
- unsafeLadder(elm, n) {
1849
- let p = c.ZERO;
1850
- let d = elm;
1851
- while (n > _0n3) {
1852
- if (n & _1n3)
1853
- p = p.add(d);
1854
- d = d.double();
1855
- n >>= _1n3;
1856
- }
1857
- return p;
1858
- },
1859
- precomputeWindow(elm, W) {
1860
- const { windows, windowSize } = opts(W);
1861
- const points = [];
1862
- let p = elm;
1863
- let base3 = p;
1864
- for (let window = 0; window < windows; window++) {
1865
- base3 = p;
1866
- points.push(base3);
1867
- for (let i = 1; i < windowSize; i++) {
1868
- base3 = base3.add(p);
1869
- points.push(base3);
1870
- }
1871
- p = base3.double();
1872
- }
1873
- return points;
1874
- },
1875
- wNAF(W, precomputes, n) {
1876
- const { windows, windowSize } = opts(W);
1877
- let p = c.ZERO;
1878
- let f = c.BASE;
1879
- const mask = BigInt(2 ** W - 1);
1880
- const maxNumber = 2 ** W;
1881
- const shiftBy = BigInt(W);
1882
- for (let window = 0; window < windows; window++) {
1883
- const offset = window * windowSize;
1884
- let wbits = Number(n & mask);
1885
- n >>= shiftBy;
1886
- if (wbits > windowSize) {
1887
- wbits -= maxNumber;
1888
- n += _1n3;
1889
- }
1890
- const offset1 = offset;
1891
- const offset2 = offset + Math.abs(wbits) - 1;
1892
- const cond1 = window % 2 !== 0;
1893
- const cond2 = wbits < 0;
1894
- if (wbits === 0) {
1895
- f = f.add(constTimeNegate(cond1, precomputes[offset1]));
1896
- } else {
1897
- p = p.add(constTimeNegate(cond2, precomputes[offset2]));
1898
- }
1899
- }
1900
- return { p, f };
1901
- },
1902
- wNAFCached(P, precomputesMap, n, transform) {
1903
- const W = P._WINDOW_SIZE || 1;
1904
- let comp = precomputesMap.get(P);
1905
- if (!comp) {
1906
- comp = this.precomputeWindow(P, W);
1907
- if (W !== 1) {
1908
- precomputesMap.set(P, transform(comp));
1909
- }
1910
- }
1911
- return this.wNAF(W, comp, n);
1912
- }
1913
- };
1914
- }
1915
- function validateBasic(curve) {
1916
- validateField(curve.Fp);
1917
- validateObject(curve, {
1918
- n: "bigint",
1919
- h: "bigint",
1920
- Gx: "field",
1921
- Gy: "field"
1922
- }, {
1923
- nBitLength: "isSafeInteger",
1924
- nByteLength: "isSafeInteger"
1925
- });
1926
- return Object.freeze({
1927
- ...nLength(curve.n, curve.nBitLength),
1928
- ...curve,
1929
- ...{ p: curve.Fp.ORDER }
1930
- });
1931
- }
1932
-
1933
- // ../../node_modules/.pnpm/@noble+curves@1.1.0/node_modules/@noble/curves/esm/abstract/weierstrass.js
1934
- function validatePointOpts(curve) {
1935
- const opts = validateBasic(curve);
1936
- validateObject(opts, {
1937
- a: "field",
1938
- b: "field"
1939
- }, {
1940
- allowedPrivateKeyLengths: "array",
1941
- wrapPrivateKey: "boolean",
1942
- isTorsionFree: "function",
1943
- clearCofactor: "function",
1944
- allowInfinityPoint: "boolean",
1945
- fromBytes: "function",
1946
- toBytes: "function"
1947
- });
1948
- const { endo, Fp: Fp3, a } = opts;
1949
- if (endo) {
1950
- if (!Fp3.eql(a, Fp3.ZERO)) {
1951
- throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");
1952
- }
1953
- if (typeof endo !== "object" || typeof endo.beta !== "bigint" || typeof endo.splitScalar !== "function") {
1954
- throw new Error("Expected endomorphism with beta: bigint and splitScalar: function");
1955
- }
1956
- }
1957
- return Object.freeze({ ...opts });
1958
- }
1959
- var { bytesToNumberBE: b2n, hexToBytes: h2b } = utils_exports;
1960
- var DER = {
1961
- Err: class DERErr extends Error {
1962
- constructor(m = "") {
1963
- super(m);
1964
- }
1965
- },
1966
- _parseInt(data) {
1967
- const { Err: E } = DER;
1968
- if (data.length < 2 || data[0] !== 2)
1969
- throw new E("Invalid signature integer tag");
1970
- const len = data[1];
1971
- const res = data.subarray(2, len + 2);
1972
- if (!len || res.length !== len)
1973
- throw new E("Invalid signature integer: wrong length");
1974
- if (res[0] & 128)
1975
- throw new E("Invalid signature integer: negative");
1976
- if (res[0] === 0 && !(res[1] & 128))
1977
- throw new E("Invalid signature integer: unnecessary leading zero");
1978
- return { d: b2n(res), l: data.subarray(len + 2) };
1979
- },
1980
- toSig(hex) {
1981
- const { Err: E } = DER;
1982
- const data = typeof hex === "string" ? h2b(hex) : hex;
1983
- if (!(data instanceof Uint8Array))
1984
- throw new Error("ui8a expected");
1985
- let l = data.length;
1986
- if (l < 2 || data[0] != 48)
1987
- throw new E("Invalid signature tag");
1988
- if (data[1] !== l - 2)
1989
- throw new E("Invalid signature: incorrect length");
1990
- const { d: r, l: sBytes } = DER._parseInt(data.subarray(2));
1991
- const { d: s, l: rBytesLeft } = DER._parseInt(sBytes);
1992
- if (rBytesLeft.length)
1993
- throw new E("Invalid signature: left bytes after parsing");
1994
- return { r, s };
1995
- },
1996
- hexFromSig(sig) {
1997
- const slice = (s2) => Number.parseInt(s2[0], 16) & 8 ? "00" + s2 : s2;
1998
- const h = (num) => {
1999
- const hex = num.toString(16);
2000
- return hex.length & 1 ? `0${hex}` : hex;
2001
- };
2002
- const s = slice(h(sig.s));
2003
- const r = slice(h(sig.r));
2004
- const shl = s.length / 2;
2005
- const rhl = r.length / 2;
2006
- const sl = h(shl);
2007
- const rl = h(rhl);
2008
- return `30${h(rhl + shl + 4)}02${rl}${r}02${sl}${s}`;
2009
- }
2010
- };
2011
- var _0n4 = BigInt(0);
2012
- var _1n4 = BigInt(1);
2013
- var _2n3 = BigInt(2);
2014
- var _3n2 = BigInt(3);
2015
- var _4n2 = BigInt(4);
2016
- function weierstrassPoints(opts) {
2017
- const CURVE = validatePointOpts(opts);
2018
- const { Fp: Fp3 } = CURVE;
2019
- const toBytes2 = CURVE.toBytes || ((c, point, isCompressed) => {
2020
- const a = point.toAffine();
2021
- return concatBytes2(Uint8Array.from([4]), Fp3.toBytes(a.x), Fp3.toBytes(a.y));
2022
- });
2023
- const fromBytes = CURVE.fromBytes || ((bytes2) => {
2024
- const tail = bytes2.subarray(1);
2025
- const x = Fp3.fromBytes(tail.subarray(0, Fp3.BYTES));
2026
- const y = Fp3.fromBytes(tail.subarray(Fp3.BYTES, 2 * Fp3.BYTES));
2027
- return { x, y };
2028
- });
2029
- function weierstrassEquation(x) {
2030
- const { a, b } = CURVE;
2031
- const x2 = Fp3.sqr(x);
2032
- const x3 = Fp3.mul(x2, x);
2033
- return Fp3.add(Fp3.add(x3, Fp3.mul(x, a)), b);
2034
- }
2035
- if (!Fp3.eql(Fp3.sqr(CURVE.Gy), weierstrassEquation(CURVE.Gx)))
2036
- throw new Error("bad generator point: equation left != right");
2037
- function isWithinCurveOrder(num) {
2038
- return typeof num === "bigint" && _0n4 < num && num < CURVE.n;
2039
- }
2040
- function assertGE(num) {
2041
- if (!isWithinCurveOrder(num))
2042
- throw new Error("Expected valid bigint: 0 < bigint < curve.n");
2043
- }
2044
- function normPrivateKeyToScalar(key) {
2045
- const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n } = CURVE;
2046
- if (lengths && typeof key !== "bigint") {
2047
- if (key instanceof Uint8Array)
2048
- key = bytesToHex(key);
2049
- if (typeof key !== "string" || !lengths.includes(key.length))
2050
- throw new Error("Invalid key");
2051
- key = key.padStart(nByteLength * 2, "0");
2052
- }
2053
- let num;
2054
- try {
2055
- num = typeof key === "bigint" ? key : bytesToNumberBE(ensureBytes("private key", key, nByteLength));
2056
- } catch (error) {
2057
- throw new Error(`private key must be ${nByteLength} bytes, hex or bigint, not ${typeof key}`);
2058
- }
2059
- if (wrapPrivateKey)
2060
- num = mod(num, n);
2061
- assertGE(num);
2062
- return num;
2063
- }
2064
- const pointPrecomputes = /* @__PURE__ */ new Map();
2065
- function assertPrjPoint(other) {
2066
- if (!(other instanceof Point2))
2067
- throw new Error("ProjectivePoint expected");
2068
- }
2069
- class Point2 {
2070
- constructor(px, py, pz) {
2071
- this.px = px;
2072
- this.py = py;
2073
- this.pz = pz;
2074
- if (px == null || !Fp3.isValid(px))
2075
- throw new Error("x required");
2076
- if (py == null || !Fp3.isValid(py))
2077
- throw new Error("y required");
2078
- if (pz == null || !Fp3.isValid(pz))
2079
- throw new Error("z required");
2080
- }
2081
- static fromAffine(p) {
2082
- const { x, y } = p || {};
2083
- if (!p || !Fp3.isValid(x) || !Fp3.isValid(y))
2084
- throw new Error("invalid affine point");
2085
- if (p instanceof Point2)
2086
- throw new Error("projective point not allowed");
2087
- const is0 = (i) => Fp3.eql(i, Fp3.ZERO);
2088
- if (is0(x) && is0(y))
2089
- return Point2.ZERO;
2090
- return new Point2(x, y, Fp3.ONE);
2091
- }
2092
- get x() {
2093
- return this.toAffine().x;
2094
- }
2095
- get y() {
2096
- return this.toAffine().y;
2097
- }
2098
- static normalizeZ(points) {
2099
- const toInv = Fp3.invertBatch(points.map((p) => p.pz));
2100
- return points.map((p, i) => p.toAffine(toInv[i])).map(Point2.fromAffine);
2101
- }
2102
- static fromHex(hex) {
2103
- const P = Point2.fromAffine(fromBytes(ensureBytes("pointHex", hex)));
2104
- P.assertValidity();
2105
- return P;
2106
- }
2107
- static fromPrivateKey(privateKey) {
2108
- return Point2.BASE.multiply(normPrivateKeyToScalar(privateKey));
2109
- }
2110
- _setWindowSize(windowSize) {
2111
- this._WINDOW_SIZE = windowSize;
2112
- pointPrecomputes.delete(this);
2113
- }
2114
- assertValidity() {
2115
- if (this.is0()) {
2116
- if (CURVE.allowInfinityPoint)
2117
- return;
2118
- throw new Error("bad point: ZERO");
2119
- }
2120
- const { x, y } = this.toAffine();
2121
- if (!Fp3.isValid(x) || !Fp3.isValid(y))
2122
- throw new Error("bad point: x or y not FE");
2123
- const left = Fp3.sqr(y);
2124
- const right = weierstrassEquation(x);
2125
- if (!Fp3.eql(left, right))
2126
- throw new Error("bad point: equation left != right");
2127
- if (!this.isTorsionFree())
2128
- throw new Error("bad point: not in prime-order subgroup");
2129
- }
2130
- hasEvenY() {
2131
- const { y } = this.toAffine();
2132
- if (Fp3.isOdd)
2133
- return !Fp3.isOdd(y);
2134
- throw new Error("Field doesn't support isOdd");
2135
- }
2136
- equals(other) {
2137
- assertPrjPoint(other);
2138
- const { px: X1, py: Y1, pz: Z1 } = this;
2139
- const { px: X2, py: Y2, pz: Z2 } = other;
2140
- const U1 = Fp3.eql(Fp3.mul(X1, Z2), Fp3.mul(X2, Z1));
2141
- const U2 = Fp3.eql(Fp3.mul(Y1, Z2), Fp3.mul(Y2, Z1));
2142
- return U1 && U2;
2143
- }
2144
- negate() {
2145
- return new Point2(this.px, Fp3.neg(this.py), this.pz);
2146
- }
2147
- double() {
2148
- const { a, b } = CURVE;
2149
- const b3 = Fp3.mul(b, _3n2);
2150
- const { px: X1, py: Y1, pz: Z1 } = this;
2151
- let X3 = Fp3.ZERO, Y3 = Fp3.ZERO, Z3 = Fp3.ZERO;
2152
- let t0 = Fp3.mul(X1, X1);
2153
- let t1 = Fp3.mul(Y1, Y1);
2154
- let t2 = Fp3.mul(Z1, Z1);
2155
- let t3 = Fp3.mul(X1, Y1);
2156
- t3 = Fp3.add(t3, t3);
2157
- Z3 = Fp3.mul(X1, Z1);
2158
- Z3 = Fp3.add(Z3, Z3);
2159
- X3 = Fp3.mul(a, Z3);
2160
- Y3 = Fp3.mul(b3, t2);
2161
- Y3 = Fp3.add(X3, Y3);
2162
- X3 = Fp3.sub(t1, Y3);
2163
- Y3 = Fp3.add(t1, Y3);
2164
- Y3 = Fp3.mul(X3, Y3);
2165
- X3 = Fp3.mul(t3, X3);
2166
- Z3 = Fp3.mul(b3, Z3);
2167
- t2 = Fp3.mul(a, t2);
2168
- t3 = Fp3.sub(t0, t2);
2169
- t3 = Fp3.mul(a, t3);
2170
- t3 = Fp3.add(t3, Z3);
2171
- Z3 = Fp3.add(t0, t0);
2172
- t0 = Fp3.add(Z3, t0);
2173
- t0 = Fp3.add(t0, t2);
2174
- t0 = Fp3.mul(t0, t3);
2175
- Y3 = Fp3.add(Y3, t0);
2176
- t2 = Fp3.mul(Y1, Z1);
2177
- t2 = Fp3.add(t2, t2);
2178
- t0 = Fp3.mul(t2, t3);
2179
- X3 = Fp3.sub(X3, t0);
2180
- Z3 = Fp3.mul(t2, t1);
2181
- Z3 = Fp3.add(Z3, Z3);
2182
- Z3 = Fp3.add(Z3, Z3);
2183
- return new Point2(X3, Y3, Z3);
2184
- }
2185
- add(other) {
2186
- assertPrjPoint(other);
2187
- const { px: X1, py: Y1, pz: Z1 } = this;
2188
- const { px: X2, py: Y2, pz: Z2 } = other;
2189
- let X3 = Fp3.ZERO, Y3 = Fp3.ZERO, Z3 = Fp3.ZERO;
2190
- const a = CURVE.a;
2191
- const b3 = Fp3.mul(CURVE.b, _3n2);
2192
- let t0 = Fp3.mul(X1, X2);
2193
- let t1 = Fp3.mul(Y1, Y2);
2194
- let t2 = Fp3.mul(Z1, Z2);
2195
- let t3 = Fp3.add(X1, Y1);
2196
- let t4 = Fp3.add(X2, Y2);
2197
- t3 = Fp3.mul(t3, t4);
2198
- t4 = Fp3.add(t0, t1);
2199
- t3 = Fp3.sub(t3, t4);
2200
- t4 = Fp3.add(X1, Z1);
2201
- let t5 = Fp3.add(X2, Z2);
2202
- t4 = Fp3.mul(t4, t5);
2203
- t5 = Fp3.add(t0, t2);
2204
- t4 = Fp3.sub(t4, t5);
2205
- t5 = Fp3.add(Y1, Z1);
2206
- X3 = Fp3.add(Y2, Z2);
2207
- t5 = Fp3.mul(t5, X3);
2208
- X3 = Fp3.add(t1, t2);
2209
- t5 = Fp3.sub(t5, X3);
2210
- Z3 = Fp3.mul(a, t4);
2211
- X3 = Fp3.mul(b3, t2);
2212
- Z3 = Fp3.add(X3, Z3);
2213
- X3 = Fp3.sub(t1, Z3);
2214
- Z3 = Fp3.add(t1, Z3);
2215
- Y3 = Fp3.mul(X3, Z3);
2216
- t1 = Fp3.add(t0, t0);
2217
- t1 = Fp3.add(t1, t0);
2218
- t2 = Fp3.mul(a, t2);
2219
- t4 = Fp3.mul(b3, t4);
2220
- t1 = Fp3.add(t1, t2);
2221
- t2 = Fp3.sub(t0, t2);
2222
- t2 = Fp3.mul(a, t2);
2223
- t4 = Fp3.add(t4, t2);
2224
- t0 = Fp3.mul(t1, t4);
2225
- Y3 = Fp3.add(Y3, t0);
2226
- t0 = Fp3.mul(t5, t4);
2227
- X3 = Fp3.mul(t3, X3);
2228
- X3 = Fp3.sub(X3, t0);
2229
- t0 = Fp3.mul(t3, t1);
2230
- Z3 = Fp3.mul(t5, Z3);
2231
- Z3 = Fp3.add(Z3, t0);
2232
- return new Point2(X3, Y3, Z3);
2233
- }
2234
- subtract(other) {
2235
- return this.add(other.negate());
2236
- }
2237
- is0() {
2238
- return this.equals(Point2.ZERO);
2239
- }
2240
- wNAF(n) {
2241
- return wnaf.wNAFCached(this, pointPrecomputes, n, (comp) => {
2242
- const toInv = Fp3.invertBatch(comp.map((p) => p.pz));
2243
- return comp.map((p, i) => p.toAffine(toInv[i])).map(Point2.fromAffine);
2244
- });
2245
- }
2246
- multiplyUnsafe(n) {
2247
- const I = Point2.ZERO;
2248
- if (n === _0n4)
2249
- return I;
2250
- assertGE(n);
2251
- if (n === _1n4)
2252
- return this;
2253
- const { endo } = CURVE;
2254
- if (!endo)
2255
- return wnaf.unsafeLadder(this, n);
2256
- let { k1neg, k1, k2neg, k2 } = endo.splitScalar(n);
2257
- let k1p = I;
2258
- let k2p = I;
2259
- let d = this;
2260
- while (k1 > _0n4 || k2 > _0n4) {
2261
- if (k1 & _1n4)
2262
- k1p = k1p.add(d);
2263
- if (k2 & _1n4)
2264
- k2p = k2p.add(d);
2265
- d = d.double();
2266
- k1 >>= _1n4;
2267
- k2 >>= _1n4;
2268
- }
2269
- if (k1neg)
2270
- k1p = k1p.negate();
2271
- if (k2neg)
2272
- k2p = k2p.negate();
2273
- k2p = new Point2(Fp3.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
2274
- return k1p.add(k2p);
2275
- }
2276
- multiply(scalar) {
2277
- assertGE(scalar);
2278
- let n = scalar;
2279
- let point, fake;
2280
- const { endo } = CURVE;
2281
- if (endo) {
2282
- const { k1neg, k1, k2neg, k2 } = endo.splitScalar(n);
2283
- let { p: k1p, f: f1p } = this.wNAF(k1);
2284
- let { p: k2p, f: f2p } = this.wNAF(k2);
2285
- k1p = wnaf.constTimeNegate(k1neg, k1p);
2286
- k2p = wnaf.constTimeNegate(k2neg, k2p);
2287
- k2p = new Point2(Fp3.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
2288
- point = k1p.add(k2p);
2289
- fake = f1p.add(f2p);
2290
- } else {
2291
- const { p, f } = this.wNAF(n);
2292
- point = p;
2293
- fake = f;
2294
- }
2295
- return Point2.normalizeZ([point, fake])[0];
2296
- }
2297
- multiplyAndAddUnsafe(Q, a, b) {
2298
- const G = Point2.BASE;
2299
- const mul = (P, a2) => a2 === _0n4 || a2 === _1n4 || !P.equals(G) ? P.multiplyUnsafe(a2) : P.multiply(a2);
2300
- const sum = mul(this, a).add(mul(Q, b));
2301
- return sum.is0() ? void 0 : sum;
2302
- }
2303
- toAffine(iz) {
2304
- const { px: x, py: y, pz: z } = this;
2305
- const is0 = this.is0();
2306
- if (iz == null)
2307
- iz = is0 ? Fp3.ONE : Fp3.inv(z);
2308
- const ax = Fp3.mul(x, iz);
2309
- const ay = Fp3.mul(y, iz);
2310
- const zz = Fp3.mul(z, iz);
2311
- if (is0)
2312
- return { x: Fp3.ZERO, y: Fp3.ZERO };
2313
- if (!Fp3.eql(zz, Fp3.ONE))
2314
- throw new Error("invZ was invalid");
2315
- return { x: ax, y: ay };
2316
- }
2317
- isTorsionFree() {
2318
- const { h: cofactor, isTorsionFree } = CURVE;
2319
- if (cofactor === _1n4)
2320
- return true;
2321
- if (isTorsionFree)
2322
- return isTorsionFree(Point2, this);
2323
- throw new Error("isTorsionFree() has not been declared for the elliptic curve");
2324
- }
2325
- clearCofactor() {
2326
- const { h: cofactor, clearCofactor } = CURVE;
2327
- if (cofactor === _1n4)
2328
- return this;
2329
- if (clearCofactor)
2330
- return clearCofactor(Point2, this);
2331
- return this.multiplyUnsafe(CURVE.h);
2332
- }
2333
- toRawBytes(isCompressed = true) {
2334
- this.assertValidity();
2335
- return toBytes2(Point2, this, isCompressed);
2336
- }
2337
- toHex(isCompressed = true) {
2338
- return bytesToHex(this.toRawBytes(isCompressed));
2339
- }
2340
- }
2341
- Point2.BASE = new Point2(CURVE.Gx, CURVE.Gy, Fp3.ONE);
2342
- Point2.ZERO = new Point2(Fp3.ZERO, Fp3.ONE, Fp3.ZERO);
2343
- const _bits = CURVE.nBitLength;
2344
- const wnaf = wNAF(Point2, CURVE.endo ? Math.ceil(_bits / 2) : _bits);
2345
- return {
2346
- CURVE,
2347
- ProjectivePoint: Point2,
2348
- normPrivateKeyToScalar,
2349
- weierstrassEquation,
2350
- isWithinCurveOrder
2351
- };
2352
- }
2353
- function validateOpts(curve) {
2354
- const opts = validateBasic(curve);
2355
- validateObject(opts, {
2356
- hash: "hash",
2357
- hmac: "function",
2358
- randomBytes: "function"
2359
- }, {
2360
- bits2int: "function",
2361
- bits2int_modN: "function",
2362
- lowS: "boolean"
2363
- });
2364
- return Object.freeze({ lowS: true, ...opts });
2365
- }
2366
- function weierstrass(curveDef) {
2367
- const CURVE = validateOpts(curveDef);
2368
- const { Fp: Fp3, n: CURVE_ORDER } = CURVE;
2369
- const compressedLen = Fp3.BYTES + 1;
2370
- const uncompressedLen = 2 * Fp3.BYTES + 1;
2371
- function isValidFieldElement(num) {
2372
- return _0n4 < num && num < Fp3.ORDER;
2373
- }
2374
- function modN(a) {
2375
- return mod(a, CURVE_ORDER);
2376
- }
2377
- function invN(a) {
2378
- return invert(a, CURVE_ORDER);
2379
- }
2380
- const { ProjectivePoint: Point2, normPrivateKeyToScalar, weierstrassEquation, isWithinCurveOrder } = weierstrassPoints({
2381
- ...CURVE,
2382
- toBytes(c, point, isCompressed) {
2383
- const a = point.toAffine();
2384
- const x = Fp3.toBytes(a.x);
2385
- const cat = concatBytes2;
2386
- if (isCompressed) {
2387
- return cat(Uint8Array.from([point.hasEvenY() ? 2 : 3]), x);
2388
- } else {
2389
- return cat(Uint8Array.from([4]), x, Fp3.toBytes(a.y));
2390
- }
2391
- },
2392
- fromBytes(bytes2) {
2393
- const len = bytes2.length;
2394
- const head = bytes2[0];
2395
- const tail = bytes2.subarray(1);
2396
- if (len === compressedLen && (head === 2 || head === 3)) {
2397
- const x = bytesToNumberBE(tail);
2398
- if (!isValidFieldElement(x))
2399
- throw new Error("Point is not on curve");
2400
- const y2 = weierstrassEquation(x);
2401
- let y = Fp3.sqrt(y2);
2402
- const isYOdd = (y & _1n4) === _1n4;
2403
- const isHeadOdd = (head & 1) === 1;
2404
- if (isHeadOdd !== isYOdd)
2405
- y = Fp3.neg(y);
2406
- return { x, y };
2407
- } else if (len === uncompressedLen && head === 4) {
2408
- const x = Fp3.fromBytes(tail.subarray(0, Fp3.BYTES));
2409
- const y = Fp3.fromBytes(tail.subarray(Fp3.BYTES, 2 * Fp3.BYTES));
2410
- return { x, y };
2411
- } else {
2412
- throw new Error(`Point of length ${len} was invalid. Expected ${compressedLen} compressed bytes or ${uncompressedLen} uncompressed bytes`);
2413
- }
2414
- }
2415
- });
2416
- const numToNByteStr = (num) => bytesToHex(numberToBytesBE(num, CURVE.nByteLength));
2417
- function isBiggerThanHalfOrder(number2) {
2418
- const HALF = CURVE_ORDER >> _1n4;
2419
- return number2 > HALF;
2420
- }
2421
- function normalizeS(s) {
2422
- return isBiggerThanHalfOrder(s) ? modN(-s) : s;
2423
- }
2424
- const slcNum = (b, from3, to) => bytesToNumberBE(b.slice(from3, to));
2425
- class Signature {
2426
- constructor(r, s, recovery) {
2427
- this.r = r;
2428
- this.s = s;
2429
- this.recovery = recovery;
2430
- this.assertValidity();
2431
- }
2432
- static fromCompact(hex) {
2433
- const l = CURVE.nByteLength;
2434
- hex = ensureBytes("compactSignature", hex, l * 2);
2435
- return new Signature(slcNum(hex, 0, l), slcNum(hex, l, 2 * l));
2436
- }
2437
- static fromDER(hex) {
2438
- const { r, s } = DER.toSig(ensureBytes("DER", hex));
2439
- return new Signature(r, s);
2440
- }
2441
- assertValidity() {
2442
- if (!isWithinCurveOrder(this.r))
2443
- throw new Error("r must be 0 < r < CURVE.n");
2444
- if (!isWithinCurveOrder(this.s))
2445
- throw new Error("s must be 0 < s < CURVE.n");
2446
- }
2447
- addRecoveryBit(recovery) {
2448
- return new Signature(this.r, this.s, recovery);
2449
- }
2450
- recoverPublicKey(msgHash) {
2451
- const { r, s, recovery: rec } = this;
2452
- const h = bits2int_modN(ensureBytes("msgHash", msgHash));
2453
- if (rec == null || ![0, 1, 2, 3].includes(rec))
2454
- throw new Error("recovery id invalid");
2455
- const radj = rec === 2 || rec === 3 ? r + CURVE.n : r;
2456
- if (radj >= Fp3.ORDER)
2457
- throw new Error("recovery id 2 or 3 invalid");
2458
- const prefix = (rec & 1) === 0 ? "02" : "03";
2459
- const R = Point2.fromHex(prefix + numToNByteStr(radj));
2460
- const ir = invN(radj);
2461
- const u1 = modN(-h * ir);
2462
- const u2 = modN(s * ir);
2463
- const Q = Point2.BASE.multiplyAndAddUnsafe(R, u1, u2);
2464
- if (!Q)
2465
- throw new Error("point at infinify");
2466
- Q.assertValidity();
2467
- return Q;
2468
- }
2469
- hasHighS() {
2470
- return isBiggerThanHalfOrder(this.s);
2471
- }
2472
- normalizeS() {
2473
- return this.hasHighS() ? new Signature(this.r, modN(-this.s), this.recovery) : this;
2474
- }
2475
- toDERRawBytes() {
2476
- return hexToBytes(this.toDERHex());
2477
- }
2478
- toDERHex() {
2479
- return DER.hexFromSig({ r: this.r, s: this.s });
2480
- }
2481
- toCompactRawBytes() {
2482
- return hexToBytes(this.toCompactHex());
2483
- }
2484
- toCompactHex() {
2485
- return numToNByteStr(this.r) + numToNByteStr(this.s);
2486
- }
2487
- }
2488
- const utils = {
2489
- isValidPrivateKey(privateKey) {
2490
- try {
2491
- normPrivateKeyToScalar(privateKey);
2492
- return true;
2493
- } catch (error) {
2494
- return false;
2495
- }
2496
- },
2497
- normPrivateKeyToScalar,
2498
- randomPrivateKey: () => {
2499
- const rand = CURVE.randomBytes(Fp3.BYTES + 8);
2500
- const num = hashToPrivateScalar(rand, CURVE_ORDER);
2501
- return numberToBytesBE(num, CURVE.nByteLength);
2502
- },
2503
- precompute(windowSize = 8, point = Point2.BASE) {
2504
- point._setWindowSize(windowSize);
2505
- point.multiply(BigInt(3));
2506
- return point;
2507
- }
2508
- };
2509
- function getPublicKey(privateKey, isCompressed = true) {
2510
- return Point2.fromPrivateKey(privateKey).toRawBytes(isCompressed);
2511
- }
2512
- function isProbPub(item) {
2513
- const arr = item instanceof Uint8Array;
2514
- const str = typeof item === "string";
2515
- const len = (arr || str) && item.length;
2516
- if (arr)
2517
- return len === compressedLen || len === uncompressedLen;
2518
- if (str)
2519
- return len === 2 * compressedLen || len === 2 * uncompressedLen;
2520
- if (item instanceof Point2)
2521
- return true;
2522
- return false;
2523
- }
2524
- function getSharedSecret(privateA, publicB, isCompressed = true) {
2525
- if (isProbPub(privateA))
2526
- throw new Error("first arg must be private key");
2527
- if (!isProbPub(publicB))
2528
- throw new Error("second arg must be public key");
2529
- const b = Point2.fromHex(publicB);
2530
- return b.multiply(normPrivateKeyToScalar(privateA)).toRawBytes(isCompressed);
2531
- }
2532
- const bits2int = CURVE.bits2int || function(bytes2) {
2533
- const num = bytesToNumberBE(bytes2);
2534
- const delta = bytes2.length * 8 - CURVE.nBitLength;
2535
- return delta > 0 ? num >> BigInt(delta) : num;
2536
- };
2537
- const bits2int_modN = CURVE.bits2int_modN || function(bytes2) {
2538
- return modN(bits2int(bytes2));
2539
- };
2540
- const ORDER_MASK = bitMask(CURVE.nBitLength);
2541
- function int2octets(num) {
2542
- if (typeof num !== "bigint")
2543
- throw new Error("bigint expected");
2544
- if (!(_0n4 <= num && num < ORDER_MASK))
2545
- throw new Error(`bigint expected < 2^${CURVE.nBitLength}`);
2546
- return numberToBytesBE(num, CURVE.nByteLength);
2547
- }
2548
- function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
2549
- if (["recovered", "canonical"].some((k) => k in opts))
2550
- throw new Error("sign() legacy options not supported");
2551
- const { hash: hash2, randomBytes: randomBytes3 } = CURVE;
2552
- let { lowS, prehash, extraEntropy: ent } = opts;
2553
- if (lowS == null)
2554
- lowS = true;
2555
- msgHash = ensureBytes("msgHash", msgHash);
2556
- if (prehash)
2557
- msgHash = ensureBytes("prehashed msgHash", hash2(msgHash));
2558
- const h1int = bits2int_modN(msgHash);
2559
- const d = normPrivateKeyToScalar(privateKey);
2560
- const seedArgs = [int2octets(d), int2octets(h1int)];
2561
- if (ent != null) {
2562
- const e = ent === true ? randomBytes3(Fp3.BYTES) : ent;
2563
- seedArgs.push(ensureBytes("extraEntropy", e, Fp3.BYTES));
2564
- }
2565
- const seed = concatBytes2(...seedArgs);
2566
- const m = h1int;
2567
- function k2sig(kBytes) {
2568
- const k = bits2int(kBytes);
2569
- if (!isWithinCurveOrder(k))
2570
- return;
2571
- const ik = invN(k);
2572
- const q = Point2.BASE.multiply(k).toAffine();
2573
- const r = modN(q.x);
2574
- if (r === _0n4)
2575
- return;
2576
- const s = modN(ik * modN(m + r * d));
2577
- if (s === _0n4)
2578
- return;
2579
- let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n4);
2580
- let normS = s;
2581
- if (lowS && isBiggerThanHalfOrder(s)) {
2582
- normS = normalizeS(s);
2583
- recovery ^= 1;
2584
- }
2585
- return new Signature(r, normS, recovery);
2586
- }
2587
- return { seed, k2sig };
2588
- }
2589
- const defaultSigOpts = { lowS: CURVE.lowS, prehash: false };
2590
- const defaultVerOpts = { lowS: CURVE.lowS, prehash: false };
2591
- function sign(msgHash, privKey, opts = defaultSigOpts) {
2592
- const { seed, k2sig } = prepSig(msgHash, privKey, opts);
2593
- const C = CURVE;
2594
- const drbg = createHmacDrbg(C.hash.outputLen, C.nByteLength, C.hmac);
2595
- return drbg(seed, k2sig);
2596
- }
2597
- Point2.BASE._setWindowSize(8);
2598
- function verify(signature, msgHash, publicKey, opts = defaultVerOpts) {
2599
- const sg = signature;
2600
- msgHash = ensureBytes("msgHash", msgHash);
2601
- publicKey = ensureBytes("publicKey", publicKey);
2602
- if ("strict" in opts)
2603
- throw new Error("options.strict was renamed to lowS");
2604
- const { lowS, prehash } = opts;
2605
- let _sig = void 0;
2606
- let P;
2607
- try {
2608
- if (typeof sg === "string" || sg instanceof Uint8Array) {
2609
- try {
2610
- _sig = Signature.fromDER(sg);
2611
- } catch (derError) {
2612
- if (!(derError instanceof DER.Err))
2613
- throw derError;
2614
- _sig = Signature.fromCompact(sg);
2615
- }
2616
- } else if (typeof sg === "object" && typeof sg.r === "bigint" && typeof sg.s === "bigint") {
2617
- const { r: r2, s: s2 } = sg;
2618
- _sig = new Signature(r2, s2);
2619
- } else {
2620
- throw new Error("PARSE");
2621
- }
2622
- P = Point2.fromHex(publicKey);
2623
- } catch (error) {
2624
- if (error.message === "PARSE")
2625
- throw new Error(`signature must be Signature instance, Uint8Array or hex string`);
2626
- return false;
2627
- }
2628
- if (lowS && _sig.hasHighS())
2629
- return false;
2630
- if (prehash)
2631
- msgHash = CURVE.hash(msgHash);
2632
- const { r, s } = _sig;
2633
- const h = bits2int_modN(msgHash);
2634
- const is = invN(s);
2635
- const u1 = modN(h * is);
2636
- const u2 = modN(r * is);
2637
- const R = Point2.BASE.multiplyAndAddUnsafe(P, u1, u2)?.toAffine();
2638
- if (!R)
2639
- return false;
2640
- const v = modN(R.x);
2641
- return v === r;
2642
- }
2643
- return {
2644
- CURVE,
2645
- getPublicKey,
2646
- getSharedSecret,
2647
- sign,
2648
- verify,
2649
- ProjectivePoint: Point2,
2650
- Signature,
2651
- utils
2652
- };
2653
- }
2654
-
2655
- // ../../node_modules/.pnpm/@noble+curves@1.1.0/node_modules/@noble/curves/esm/_shortw_utils.js
2656
- function getHash(hash2) {
2657
- return {
2658
- hash: hash2,
2659
- hmac: (key, ...msgs) => hmac(hash2, key, concatBytes(...msgs)),
2660
- randomBytes
2661
- };
2662
- }
2663
- function createCurve(curveDef, defHash) {
2664
- const create2 = (hash2) => weierstrass({ ...curveDef, ...getHash(hash2) });
2665
- return Object.freeze({ ...create2(defHash), create: create2 });
2666
- }
2667
-
2668
- // ../../node_modules/.pnpm/@noble+hashes@1.3.1/node_modules/@noble/hashes/esm/_sha2.js
2669
- function setBigUint64(view, byteOffset, value, isLE2) {
2670
- if (typeof view.setBigUint64 === "function")
2671
- return view.setBigUint64(byteOffset, value, isLE2);
2672
- const _32n = BigInt(32);
2673
- const _u32_max = BigInt(4294967295);
2674
- const wh = Number(value >> _32n & _u32_max);
2675
- const wl = Number(value & _u32_max);
2676
- const h = isLE2 ? 4 : 0;
2677
- const l = isLE2 ? 0 : 4;
2678
- view.setUint32(byteOffset + h, wh, isLE2);
2679
- view.setUint32(byteOffset + l, wl, isLE2);
2680
- }
2681
- var SHA2 = class extends Hash {
2682
- constructor(blockLen, outputLen, padOffset, isLE2) {
2683
- super();
2684
- this.blockLen = blockLen;
2685
- this.outputLen = outputLen;
2686
- this.padOffset = padOffset;
2687
- this.isLE = isLE2;
2688
- this.finished = false;
2689
- this.length = 0;
2690
- this.pos = 0;
2691
- this.destroyed = false;
2692
- this.buffer = new Uint8Array(blockLen);
2693
- this.view = createView(this.buffer);
2694
- }
2695
- update(data) {
2696
- assert_default.exists(this);
2697
- const { view, buffer, blockLen } = this;
2698
- data = toBytes(data);
2699
- const len = data.length;
2700
- for (let pos = 0; pos < len; ) {
2701
- const take = Math.min(blockLen - this.pos, len - pos);
2702
- if (take === blockLen) {
2703
- const dataView = createView(data);
2704
- for (; blockLen <= len - pos; pos += blockLen)
2705
- this.process(dataView, pos);
2706
- continue;
2707
- }
2708
- buffer.set(data.subarray(pos, pos + take), this.pos);
2709
- this.pos += take;
2710
- pos += take;
2711
- if (this.pos === blockLen) {
2712
- this.process(view, 0);
2713
- this.pos = 0;
2714
- }
2715
- }
2716
- this.length += data.length;
2717
- this.roundClean();
2718
- return this;
2719
- }
2720
- digestInto(out) {
2721
- assert_default.exists(this);
2722
- assert_default.output(out, this);
2723
- this.finished = true;
2724
- const { buffer, view, blockLen, isLE: isLE2 } = this;
2725
- let { pos } = this;
2726
- buffer[pos++] = 128;
2727
- this.buffer.subarray(pos).fill(0);
2728
- if (this.padOffset > blockLen - pos) {
2729
- this.process(view, 0);
2730
- pos = 0;
2731
- }
2732
- for (let i = pos; i < blockLen; i++)
2733
- buffer[i] = 0;
2734
- setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE2);
2735
- this.process(view, 0);
2736
- const oview = createView(out);
2737
- const len = this.outputLen;
2738
- if (len % 4)
2739
- throw new Error("_sha2: outputLen should be aligned to 32bit");
2740
- const outLen = len / 4;
2741
- const state = this.get();
2742
- if (outLen > state.length)
2743
- throw new Error("_sha2: outputLen bigger than state");
2744
- for (let i = 0; i < outLen; i++)
2745
- oview.setUint32(4 * i, state[i], isLE2);
2746
- }
2747
- digest() {
2748
- const { buffer, outputLen } = this;
2749
- this.digestInto(buffer);
2750
- const res = buffer.slice(0, outputLen);
2751
- this.destroy();
2752
- return res;
2753
- }
2754
- _cloneInto(to) {
2755
- to || (to = new this.constructor());
2756
- to.set(...this.get());
2757
- const { blockLen, buffer, length: length2, finished, destroyed, pos } = this;
2758
- to.length = length2;
2759
- to.pos = pos;
2760
- to.finished = finished;
2761
- to.destroyed = destroyed;
2762
- if (length2 % blockLen)
2763
- to.buffer.set(buffer);
2764
- return to;
2765
- }
2766
- };
2767
-
2768
- // ../../node_modules/.pnpm/@noble+hashes@1.3.1/node_modules/@noble/hashes/esm/sha256.js
2769
- var Chi = (a, b, c) => a & b ^ ~a & c;
2770
- var Maj = (a, b, c) => a & b ^ a & c ^ b & c;
2771
- var SHA256_K = new Uint32Array([
2772
- 1116352408,
2773
- 1899447441,
2774
- 3049323471,
2775
- 3921009573,
2776
- 961987163,
2777
- 1508970993,
2778
- 2453635748,
2779
- 2870763221,
2780
- 3624381080,
2781
- 310598401,
2782
- 607225278,
2783
- 1426881987,
2784
- 1925078388,
2785
- 2162078206,
2786
- 2614888103,
2787
- 3248222580,
2788
- 3835390401,
2789
- 4022224774,
2790
- 264347078,
2791
- 604807628,
2792
- 770255983,
2793
- 1249150122,
2794
- 1555081692,
2795
- 1996064986,
2796
- 2554220882,
2797
- 2821834349,
2798
- 2952996808,
2799
- 3210313671,
2800
- 3336571891,
2801
- 3584528711,
2802
- 113926993,
2803
- 338241895,
2804
- 666307205,
2805
- 773529912,
2806
- 1294757372,
2807
- 1396182291,
2808
- 1695183700,
2809
- 1986661051,
2810
- 2177026350,
2811
- 2456956037,
2812
- 2730485921,
2813
- 2820302411,
2814
- 3259730800,
2815
- 3345764771,
2816
- 3516065817,
2817
- 3600352804,
2818
- 4094571909,
2819
- 275423344,
2820
- 430227734,
2821
- 506948616,
2822
- 659060556,
2823
- 883997877,
2824
- 958139571,
2825
- 1322822218,
2826
- 1537002063,
2827
- 1747873779,
2828
- 1955562222,
2829
- 2024104815,
2830
- 2227730452,
2831
- 2361852424,
2832
- 2428436474,
2833
- 2756734187,
2834
- 3204031479,
2835
- 3329325298
2836
- ]);
2837
- var IV = new Uint32Array([
2838
- 1779033703,
2839
- 3144134277,
2840
- 1013904242,
2841
- 2773480762,
2842
- 1359893119,
2843
- 2600822924,
2844
- 528734635,
2845
- 1541459225
2846
- ]);
2847
- var SHA256_W = new Uint32Array(64);
2848
- var SHA256 = class extends SHA2 {
2849
- constructor() {
2850
- super(64, 32, 8, false);
2851
- this.A = IV[0] | 0;
2852
- this.B = IV[1] | 0;
2853
- this.C = IV[2] | 0;
2854
- this.D = IV[3] | 0;
2855
- this.E = IV[4] | 0;
2856
- this.F = IV[5] | 0;
2857
- this.G = IV[6] | 0;
2858
- this.H = IV[7] | 0;
2859
- }
2860
- get() {
2861
- const { A, B, C, D, E, F, G, H } = this;
2862
- return [A, B, C, D, E, F, G, H];
2863
- }
2864
- set(A, B, C, D, E, F, G, H) {
2865
- this.A = A | 0;
2866
- this.B = B | 0;
2867
- this.C = C | 0;
2868
- this.D = D | 0;
2869
- this.E = E | 0;
2870
- this.F = F | 0;
2871
- this.G = G | 0;
2872
- this.H = H | 0;
2873
- }
2874
- process(view, offset) {
2875
- for (let i = 0; i < 16; i++, offset += 4)
2876
- SHA256_W[i] = view.getUint32(offset, false);
2877
- for (let i = 16; i < 64; i++) {
2878
- const W15 = SHA256_W[i - 15];
2879
- const W2 = SHA256_W[i - 2];
2880
- const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
2881
- const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
2882
- SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
2883
- }
2884
- let { A, B, C, D, E, F, G, H } = this;
2885
- for (let i = 0; i < 64; i++) {
2886
- const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
2887
- const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
2888
- const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
2889
- const T2 = sigma0 + Maj(A, B, C) | 0;
2890
- H = G;
2891
- G = F;
2892
- F = E;
2893
- E = D + T1 | 0;
2894
- D = C;
2895
- C = B;
2896
- B = A;
2897
- A = T1 + T2 | 0;
2898
- }
2899
- A = A + this.A | 0;
2900
- B = B + this.B | 0;
2901
- C = C + this.C | 0;
2902
- D = D + this.D | 0;
2903
- E = E + this.E | 0;
2904
- F = F + this.F | 0;
2905
- G = G + this.G | 0;
2906
- H = H + this.H | 0;
2907
- this.set(A, B, C, D, E, F, G, H);
2908
- }
2909
- roundClean() {
2910
- SHA256_W.fill(0);
2911
- }
2912
- destroy() {
2913
- this.set(0, 0, 0, 0, 0, 0, 0, 0);
2914
- this.buffer.fill(0);
2915
- }
2916
- };
2917
- var SHA224 = class extends SHA256 {
2918
- constructor() {
2919
- super();
2920
- this.A = 3238371032 | 0;
2921
- this.B = 914150663 | 0;
2922
- this.C = 812702999 | 0;
2923
- this.D = 4144912697 | 0;
2924
- this.E = 4290775857 | 0;
2925
- this.F = 1750603025 | 0;
2926
- this.G = 1694076839 | 0;
2927
- this.H = 3204075428 | 0;
2928
- this.outputLen = 28;
2929
- }
2930
- };
2931
- var sha2562 = wrapConstructor(() => new SHA256());
2932
- var sha224 = wrapConstructor(() => new SHA224());
2933
-
2934
- // ../../node_modules/.pnpm/@noble+curves@1.1.0/node_modules/@noble/curves/esm/p256.js
2935
- var Fp = Field(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"));
2936
- var CURVE_A = Fp.create(BigInt("-3"));
2937
- var CURVE_B = BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b");
2938
- var p256 = createCurve({
2939
- a: CURVE_A,
2940
- b: CURVE_B,
2941
- Fp,
2942
- n: BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),
2943
- Gx: BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),
2944
- Gy: BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),
2945
- h: BigInt(1),
2946
- lowS: false
2947
- }, sha2562);
2948
-
2949
- // src/p256/encoding.ts
2950
- var compressPubkey = (pubkeyBytes) => {
2951
- const point = p256.ProjectivePoint.fromHex(pubkeyBytes);
2952
- return point.toRawBytes(true);
2953
- };
2954
- var decompressPubkey = (compressed) => {
2955
- if (compressed.length !== 33) {
2956
- throw new Error("Expected 33 byte compress pubkey");
2957
- }
2958
- const point = p256.ProjectivePoint.fromHex(compressed);
2959
- return point.toRawBytes(false);
2960
- };
2961
-
2962
- // ../../node_modules/.pnpm/@noble+curves@1.1.0/node_modules/@noble/curves/esm/secp256k1.js
2963
- var secp256k1P = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f");
2964
- var secp256k1N = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
2965
- var _1n5 = BigInt(1);
2966
- var _2n4 = BigInt(2);
2967
- var divNearest = (a, b) => (a + b / _2n4) / b;
2968
- function sqrtMod(y) {
2969
- const P = secp256k1P;
2970
- const _3n3 = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
2971
- const _23n = BigInt(23), _44n = BigInt(44), _88n = BigInt(88);
2972
- const b2 = y * y * y % P;
2973
- const b3 = b2 * b2 * y % P;
2974
- const b6 = pow2(b3, _3n3, P) * b3 % P;
2975
- const b9 = pow2(b6, _3n3, P) * b3 % P;
2976
- const b11 = pow2(b9, _2n4, P) * b2 % P;
2977
- const b22 = pow2(b11, _11n, P) * b11 % P;
2978
- const b44 = pow2(b22, _22n, P) * b22 % P;
2979
- const b88 = pow2(b44, _44n, P) * b44 % P;
2980
- const b176 = pow2(b88, _88n, P) * b88 % P;
2981
- const b220 = pow2(b176, _44n, P) * b44 % P;
2982
- const b223 = pow2(b220, _3n3, P) * b3 % P;
2983
- const t1 = pow2(b223, _23n, P) * b22 % P;
2984
- const t2 = pow2(t1, _6n, P) * b2 % P;
2985
- const root = pow2(t2, _2n4, P);
2986
- if (!Fp2.eql(Fp2.sqr(root), y))
2987
- throw new Error("Cannot find square root");
2988
- return root;
2989
- }
2990
- var Fp2 = Field(secp256k1P, void 0, void 0, { sqrt: sqrtMod });
2991
- var secp256k1 = createCurve({
2992
- a: BigInt(0),
2993
- b: BigInt(7),
2994
- Fp: Fp2,
2995
- n: secp256k1N,
2996
- Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
2997
- Gy: BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),
2998
- h: BigInt(1),
2999
- lowS: true,
3000
- endo: {
3001
- beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
3002
- splitScalar: (k) => {
3003
- const n = secp256k1N;
3004
- const a1 = BigInt("0x3086d221a7d46bcde86c90e49284eb15");
3005
- const b1 = -_1n5 * BigInt("0xe4437ed6010e88286f547fa90abfe4c3");
3006
- const a2 = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8");
3007
- const b2 = a1;
3008
- const POW_2_128 = BigInt("0x100000000000000000000000000000000");
3009
- const c1 = divNearest(b2 * k, n);
3010
- const c2 = divNearest(-b1 * k, n);
3011
- let k1 = mod(k - c1 * a1 - c2 * a2, n);
3012
- let k2 = mod(-c1 * b1 - c2 * b2, n);
3013
- const k1neg = k1 > POW_2_128;
3014
- const k2neg = k2 > POW_2_128;
3015
- if (k1neg)
3016
- k1 = n - k1;
3017
- if (k2neg)
3018
- k2 = n - k2;
3019
- if (k1 > POW_2_128 || k2 > POW_2_128) {
3020
- throw new Error("splitScalar: Endomorphism failed, k=" + k);
3021
- }
3022
- return { k1neg, k1, k2neg, k2 };
3023
- }
3024
- }
3025
- }, sha2562);
3026
- var _0n5 = BigInt(0);
3027
- var Point = secp256k1.ProjectivePoint;
3028
-
3029
- // src/secp256k1/encoding.ts
3030
- var compressPubkey2 = (pubkeyBytes) => {
3031
- const point = secp256k1.ProjectivePoint.fromHex(pubkeyBytes);
3032
- return point.toRawBytes(true);
3033
- };
3034
- var decompressPubkey2 = (compressed) => {
3035
- if (compressed.length !== 33) {
3036
- throw new Error("Expected 33 byte compress pubkey");
3037
- }
3038
- const point = secp256k1.ProjectivePoint.fromHex(compressed);
3039
- return point.toRawBytes(false);
3040
- };
3041
-
3042
- // src/p256/operations.ts
3043
- var verifyDidSig = async (did, data, sig, opts) => {
3044
- const { jwtAlg, keyBytes } = parseDidKey(did);
3045
- if (jwtAlg !== P256_JWT_ALG) {
3046
- throw new Error(`Not a P-256 did:key: ${did}`);
3047
- }
3048
- return verifySig(keyBytes, data, sig, opts);
3049
- };
3050
- var verifySig = async (publicKey, data, sig, opts) => {
3051
- const allowMalleable = opts?.allowMalleableSig ?? false;
3052
- const msgHash = await sha2562(data);
3053
- if (!allowMalleable && !isCompactFormat(sig)) {
3054
- return false;
3055
- }
3056
- return p256.verify(sig, msgHash, publicKey, {
3057
- lowS: !allowMalleable
3058
- });
3059
- };
3060
- var isCompactFormat = (sig) => {
3061
- try {
3062
- const parsed = p256.Signature.fromCompact(sig);
3063
- return equals(parsed.toCompactRawBytes(), sig);
3064
- } catch {
3065
- return false;
3066
- }
3067
- };
3068
-
3069
- // src/p256/plugin.ts
3070
- var p256Plugin = {
3071
- prefix: P256_DID_PREFIX,
3072
- jwtAlg: P256_JWT_ALG,
3073
- verifySignature: verifyDidSig
3074
- };
3075
- var plugin_default = p256Plugin;
3076
-
3077
- // src/secp256k1/operations.ts
3078
- var verifyDidSig2 = async (did, data, sig, opts) => {
3079
- const { jwtAlg, keyBytes } = parseDidKey(did);
3080
- if (jwtAlg !== SECP256K1_JWT_ALG) {
3081
- throw new Error(`Not a secp256k1 did:key: ${did}`);
3082
- }
3083
- return verifySig2(keyBytes, data, sig, opts);
3084
- };
3085
- var verifySig2 = async (publicKey, data, sig, opts) => {
3086
- const allowMalleable = opts?.allowMalleableSig ?? false;
3087
- const msgHash = await sha2562(data);
3088
- if (!allowMalleable && !isCompactFormat2(sig)) {
3089
- return false;
3090
- }
3091
- return secp256k1.verify(sig, msgHash, publicKey, {
3092
- lowS: !allowMalleable
3093
- });
3094
- };
3095
- var isCompactFormat2 = (sig) => {
3096
- try {
3097
- const parsed = secp256k1.Signature.fromCompact(sig);
3098
- return equals(parsed.toCompactRawBytes(), sig);
3099
- } catch {
3100
- return false;
3101
- }
3102
- };
3103
-
3104
- // src/secp256k1/plugin.ts
3105
- var secp256k1Plugin = {
3106
- prefix: SECP256K1_DID_PREFIX,
3107
- jwtAlg: SECP256K1_JWT_ALG,
3108
- verifySignature: verifyDidSig2
3109
- };
3110
- var plugin_default2 = secp256k1Plugin;
3111
-
3112
- // src/plugins.ts
3113
- var plugins = [plugin_default, plugin_default2];
3114
- var plugins_default = plugins;
3115
-
3116
- // src/did.ts
3117
- var parseMultikey = (multikey) => {
3118
- if (!multikey.startsWith(BASE58_MULTIBASE_PREFIX)) {
3119
- throw new Error(`Incorrect prefix for multikey: ${multikey}`);
3120
- }
3121
- const prefixedBytes = fromString2(multikey.slice(BASE58_MULTIBASE_PREFIX.length), "base58btc");
3122
- const plugin = plugins_default.find((p) => hasPrefix(prefixedBytes, p.prefix));
3123
- if (!plugin) {
3124
- throw new Error("Unsupported key type");
3125
- }
3126
- let keyBytes = prefixedBytes.slice(plugin.prefix.length);
3127
- if (plugin.jwtAlg === P256_JWT_ALG) {
3128
- keyBytes = decompressPubkey(keyBytes);
3129
- } else if (plugin.jwtAlg === SECP256K1_JWT_ALG) {
3130
- keyBytes = decompressPubkey2(keyBytes);
3131
- }
3132
- return {
3133
- jwtAlg: plugin.jwtAlg,
3134
- keyBytes
3135
- };
3136
- };
3137
- var formatMultikey = (jwtAlg, keyBytes) => {
3138
- const plugin = plugins_default.find((p) => p.jwtAlg === jwtAlg);
3139
- if (!plugin) {
3140
- throw new Error("Unsupported key type");
3141
- }
3142
- if (jwtAlg === P256_JWT_ALG) {
3143
- keyBytes = compressPubkey(keyBytes);
3144
- } else if (jwtAlg === SECP256K1_JWT_ALG) {
3145
- keyBytes = compressPubkey2(keyBytes);
3146
- }
3147
- const prefixedBytes = concat([plugin.prefix, keyBytes]);
3148
- return BASE58_MULTIBASE_PREFIX + toString2(prefixedBytes, "base58btc");
3149
- };
3150
- var parseDidKey = (did) => {
3151
- if (!did.startsWith(DID_KEY_PREFIX)) {
3152
- throw new Error(`Incorrect prefix for did:key: ${did}`);
3153
- }
3154
- return parseMultikey(did.slice(DID_KEY_PREFIX.length));
3155
- };
3156
- var formatDidKey = (jwtAlg, keyBytes) => {
3157
- return DID_KEY_PREFIX + formatMultikey(jwtAlg, keyBytes);
3158
- };
3159
- var hasPrefix = (bytes2, prefix) => {
3160
- return equals(prefix, bytes2.subarray(0, prefix.byteLength));
3161
- };
3162
-
3163
- // src/multibase.ts
3164
- var multibaseToBytes = (mb) => {
3165
- const base3 = mb[0];
3166
- const key = mb.slice(1);
3167
- switch (base3) {
3168
- case "f":
3169
- return fromString2(key, "base16");
3170
- case "F":
3171
- return fromString2(key, "base16upper");
3172
- case "b":
3173
- return fromString2(key, "base32");
3174
- case "B":
3175
- return fromString2(key, "base32upper");
3176
- case "z":
3177
- return fromString2(key, "base58btc");
3178
- case "m":
3179
- return fromString2(key, "base64");
3180
- case "u":
3181
- return fromString2(key, "base64url");
3182
- case "U":
3183
- return fromString2(key, "base64urlpad");
3184
- default:
3185
- throw new Error(`Unsupported multibase: :${mb}`);
3186
- }
3187
- };
3188
- var bytesToMultibase = (mb, encoding) => {
3189
- switch (encoding) {
3190
- case "base16":
3191
- return "f" + toString2(mb, encoding);
3192
- case "base16upper":
3193
- return "F" + toString2(mb, encoding);
3194
- case "base32":
3195
- return "b" + toString2(mb, encoding);
3196
- case "base32upper":
3197
- return "B" + toString2(mb, encoding);
3198
- case "base58btc":
3199
- return "z" + toString2(mb, encoding);
3200
- case "base64":
3201
- return "m" + toString2(mb, encoding);
3202
- case "base64url":
3203
- return "u" + toString2(mb, encoding);
3204
- case "base64urlpad":
3205
- return "U" + toString2(mb, encoding);
3206
- default:
3207
- throw new Error(`Unsupported multibase: :${mb}`);
3208
- }
3209
- };
3210
-
3211
- // src/sha.ts
3212
- var sha2563 = async (input) => {
3213
- const bytes2 = typeof input === "string" ? fromString2(input, "utf8") : input;
3214
- return sha2562(bytes2);
3215
- };
3216
-
3217
- // src/random.ts
3218
- var randomBytes2 = randomBytes;
3219
- var randomStr = (byteLength, encoding) => {
3220
- const bytes2 = randomBytes2(byteLength);
3221
- return toString2(bytes2, encoding);
3222
- };
3223
- var randomIntFromSeed = async (seed, high, low = 0) => {
3224
- const hash2 = await sha2563(seed);
3225
- const number2 = Buffer.from(hash2).readUintBE(0, 6);
3226
- const range = high - low;
3227
- const normalized = number2 % range;
3228
- return normalized + low;
3229
- };
3230
-
3231
- // src/verify.ts
3232
- var verifySignature = (didKey, data, sig, opts) => {
3233
- const parsed = parseDidKey(didKey);
3234
- const plugin = plugins_default.find((p) => p.jwtAlg === parsed.jwtAlg);
3235
- if (!plugin) {
3236
- throw new Error(`Unsupported signature alg: ${parsed.jwtAlg}`);
3237
- }
3238
- return plugin.verifySignature(didKey, data, sig, opts);
3239
- };
3240
- var verifySignatureUtf8 = async (didKey, data, sig, opts) => {
3241
- const dataBytes = fromString2(data, "utf8");
3242
- const sigBytes = fromString2(sig, "base64url");
3243
- return verifySignature(didKey, dataBytes, sigBytes, opts);
3244
- };
3245
-
3246
- // src/p256/keypair.ts
3247
- var P256Keypair = class {
3248
- constructor(privateKey, exportable) {
3249
- this.privateKey = privateKey;
3250
- this.exportable = exportable;
3251
- this.jwtAlg = P256_JWT_ALG;
3252
- this.publicKey = p256.getPublicKey(privateKey);
3253
- }
3254
- static async create(opts) {
3255
- const { exportable = false } = opts || {};
3256
- const privKey = p256.utils.randomPrivateKey();
3257
- return new P256Keypair(privKey, exportable);
3258
- }
3259
- static async import(privKey, opts) {
3260
- const { exportable = false } = opts || {};
3261
- const privKeyBytes = typeof privKey === "string" ? fromString2(privKey, "hex") : privKey;
3262
- return new P256Keypair(privKeyBytes, exportable);
3263
- }
3264
- publicKeyBytes() {
3265
- return this.publicKey;
3266
- }
3267
- publicKeyStr(encoding = "base64pad") {
3268
- return toString2(this.publicKey, encoding);
3269
- }
3270
- did() {
3271
- return formatDidKey(this.jwtAlg, this.publicKey);
3272
- }
3273
- async sign(msg) {
3274
- const msgHash = await sha2562(msg);
3275
- const sig = await p256.sign(msgHash, this.privateKey, { lowS: true });
3276
- return sig.toCompactRawBytes();
3277
- }
3278
- async export() {
3279
- if (!this.exportable) {
3280
- throw new Error("Private key is not exportable");
3281
- }
3282
- return this.privateKey;
3283
- }
3284
- };
3285
-
3286
- // src/secp256k1/keypair.ts
3287
- var Secp256k1Keypair = class {
3288
- constructor(privateKey, exportable) {
3289
- this.privateKey = privateKey;
3290
- this.exportable = exportable;
3291
- this.jwtAlg = SECP256K1_JWT_ALG;
3292
- this.publicKey = secp256k1.getPublicKey(privateKey);
3293
- }
3294
- static async create(opts) {
3295
- const { exportable = false } = opts || {};
3296
- const privKey = secp256k1.utils.randomPrivateKey();
3297
- return new Secp256k1Keypair(privKey, exportable);
3298
- }
3299
- static async import(privKey, opts) {
3300
- const { exportable = false } = opts || {};
3301
- const privKeyBytes = typeof privKey === "string" ? fromString2(privKey, "hex") : privKey;
3302
- return new Secp256k1Keypair(privKeyBytes, exportable);
3303
- }
3304
- publicKeyBytes() {
3305
- return this.publicKey;
3306
- }
3307
- publicKeyStr(encoding = "base64pad") {
3308
- return toString2(this.publicKey, encoding);
3309
- }
3310
- did() {
3311
- return formatDidKey(this.jwtAlg, this.publicKey);
3312
- }
3313
- async sign(msg) {
3314
- const msgHash = await sha2562(msg);
3315
- const sig = await secp256k1.sign(msgHash, this.privateKey, { lowS: true });
3316
- return sig.toCompactRawBytes();
3317
- }
3318
- async export() {
3319
- if (!this.exportable) {
3320
- throw new Error("Private key is not exportable");
3321
- }
3322
- return this.privateKey;
3323
- }
3324
- };
3325
- // Annotate the CommonJS export names for ESM import in node:
3326
- 0 && (module.exports = {
3327
- BASE58_MULTIBASE_PREFIX,
3328
- DID_KEY_PREFIX,
3329
- P256Keypair,
3330
- P256_DID_PREFIX,
3331
- P256_JWT_ALG,
3332
- SECP256K1_DID_PREFIX,
3333
- SECP256K1_JWT_ALG,
3334
- Secp256k1Keypair,
3335
- bytesToMultibase,
3336
- formatDidKey,
3337
- formatMultikey,
3338
- multibaseToBytes,
3339
- p256Plugin,
3340
- parseDidKey,
3341
- parseMultikey,
3342
- randomBytes,
3343
- randomIntFromSeed,
3344
- randomStr,
3345
- secp256k1Plugin,
3346
- sha256,
3347
- verifySignature,
3348
- verifySignatureUtf8
3349
- });
3350
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
3351
- /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
3352
- //# sourceMappingURL=index.js.map
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./const"), exports);
18
+ __exportStar(require("./did"), exports);
19
+ __exportStar(require("./multibase"), exports);
20
+ __exportStar(require("./random"), exports);
21
+ __exportStar(require("./sha"), exports);
22
+ __exportStar(require("./types"), exports);
23
+ __exportStar(require("./verify"), exports);
24
+ __exportStar(require("./p256/keypair"), exports);
25
+ __exportStar(require("./p256/plugin"), exports);
26
+ __exportStar(require("./secp256k1/keypair"), exports);
27
+ __exportStar(require("./secp256k1/plugin"), exports);
28
+ //# sourceMappingURL=index.js.map