simple-hpke 0.0.9 → 0.1.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.
@@ -0,0 +1,1788 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name2 in all)
9
+ __defProp(target, name2, { get: all[name2], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from3, except, desc) => {
12
+ if (from3 && typeof from3 === "object" || typeof from3 === "function") {
13
+ for (let key of __getOwnPropNames(from3))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from3[key], enumerable: !(desc = __getOwnPropDesc(from3, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/constants.ts
22
+ var constants_exports = {};
23
+ __export(constants_exports, {
24
+ AEAD_ID: () => AEAD_ID,
25
+ AEAD_TAG_LENGTH: () => AEAD_TAG_LENGTH,
26
+ ENC_LENGTH: () => ENC_LENGTH,
27
+ HPKE_SUITE_ID: () => HPKE_SUITE_ID,
28
+ HPKE_V1: () => HPKE_V1,
29
+ KDF_ID: () => KDF_ID,
30
+ KEM_ID: () => KEM_ID,
31
+ KEM_SUITE_ID: () => KEM_SUITE_ID,
32
+ MODE_BASE: () => MODE_BASE,
33
+ NK: () => NK,
34
+ NN: () => NN,
35
+ NSECRET: () => NSECRET,
36
+ WRAPPED_LEN_PREFIX: () => WRAPPED_LEN_PREFIX
37
+ });
38
+ module.exports = __toCommonJS(constants_exports);
39
+
40
+ // node_modules/uint8arrays/dist/src/alloc.js
41
+ function allocUnsafe(size = 0) {
42
+ return new Uint8Array(size);
43
+ }
44
+ __name(allocUnsafe, "allocUnsafe");
45
+
46
+ // node_modules/multiformats/dist/src/bases/base10.js
47
+ var base10_exports = {};
48
+ __export(base10_exports, {
49
+ base10: () => base10
50
+ });
51
+
52
+ // node_modules/multiformats/dist/src/bytes.js
53
+ var empty = new Uint8Array(0);
54
+ function equals(aa, bb) {
55
+ if (aa === bb) {
56
+ return true;
57
+ }
58
+ if (aa.byteLength !== bb.byteLength) {
59
+ return false;
60
+ }
61
+ for (let ii = 0; ii < aa.byteLength; ii++) {
62
+ if (aa[ii] !== bb[ii]) {
63
+ return false;
64
+ }
65
+ }
66
+ return true;
67
+ }
68
+ __name(equals, "equals");
69
+ function coerce(o) {
70
+ if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") {
71
+ return o;
72
+ }
73
+ if (o instanceof ArrayBuffer) {
74
+ return new Uint8Array(o);
75
+ }
76
+ if (ArrayBuffer.isView(o)) {
77
+ return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
78
+ }
79
+ throw new Error("Unknown type, must be binary type");
80
+ }
81
+ __name(coerce, "coerce");
82
+ function fromString(str) {
83
+ return new TextEncoder().encode(str);
84
+ }
85
+ __name(fromString, "fromString");
86
+ function toString(b) {
87
+ return new TextDecoder().decode(b);
88
+ }
89
+ __name(toString, "toString");
90
+
91
+ // node_modules/multiformats/dist/src/vendor/base-x.js
92
+ function base(ALPHABET, name2) {
93
+ if (ALPHABET.length >= 255) {
94
+ throw new TypeError("Alphabet too long");
95
+ }
96
+ var BASE_MAP = new Uint8Array(256);
97
+ for (var j = 0; j < BASE_MAP.length; j++) {
98
+ BASE_MAP[j] = 255;
99
+ }
100
+ for (var i = 0; i < ALPHABET.length; i++) {
101
+ var x = ALPHABET.charAt(i);
102
+ var xc = x.charCodeAt(0);
103
+ if (BASE_MAP[xc] !== 255) {
104
+ throw new TypeError(x + " is ambiguous");
105
+ }
106
+ BASE_MAP[xc] = i;
107
+ }
108
+ var BASE = ALPHABET.length;
109
+ var LEADER = ALPHABET.charAt(0);
110
+ var FACTOR = Math.log(BASE) / Math.log(256);
111
+ var iFACTOR = Math.log(256) / Math.log(BASE);
112
+ function encode5(source) {
113
+ if (source instanceof Uint8Array)
114
+ ;
115
+ else if (ArrayBuffer.isView(source)) {
116
+ source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
117
+ } else if (Array.isArray(source)) {
118
+ source = Uint8Array.from(source);
119
+ }
120
+ if (!(source instanceof Uint8Array)) {
121
+ throw new TypeError("Expected Uint8Array");
122
+ }
123
+ if (source.length === 0) {
124
+ return "";
125
+ }
126
+ var zeroes = 0;
127
+ var length2 = 0;
128
+ var pbegin = 0;
129
+ var pend = source.length;
130
+ while (pbegin !== pend && source[pbegin] === 0) {
131
+ pbegin++;
132
+ zeroes++;
133
+ }
134
+ var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
135
+ var b58 = new Uint8Array(size);
136
+ while (pbegin !== pend) {
137
+ var carry = source[pbegin];
138
+ var i2 = 0;
139
+ for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
140
+ carry += 256 * b58[it1] >>> 0;
141
+ b58[it1] = carry % BASE >>> 0;
142
+ carry = carry / BASE >>> 0;
143
+ }
144
+ if (carry !== 0) {
145
+ throw new Error("Non-zero carry");
146
+ }
147
+ length2 = i2;
148
+ pbegin++;
149
+ }
150
+ var it2 = size - length2;
151
+ while (it2 !== size && b58[it2] === 0) {
152
+ it2++;
153
+ }
154
+ var str = LEADER.repeat(zeroes);
155
+ for (; it2 < size; ++it2) {
156
+ str += ALPHABET.charAt(b58[it2]);
157
+ }
158
+ return str;
159
+ }
160
+ __name(encode5, "encode");
161
+ function decodeUnsafe(source) {
162
+ if (typeof source !== "string") {
163
+ throw new TypeError("Expected String");
164
+ }
165
+ if (source.length === 0) {
166
+ return new Uint8Array();
167
+ }
168
+ var psz = 0;
169
+ if (source[psz] === " ") {
170
+ return;
171
+ }
172
+ var zeroes = 0;
173
+ var length2 = 0;
174
+ while (source[psz] === LEADER) {
175
+ zeroes++;
176
+ psz++;
177
+ }
178
+ var size = (source.length - psz) * FACTOR + 1 >>> 0;
179
+ var b256 = new Uint8Array(size);
180
+ while (source[psz]) {
181
+ var carry = BASE_MAP[source.charCodeAt(psz)];
182
+ if (carry === 255) {
183
+ return;
184
+ }
185
+ var i2 = 0;
186
+ for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
187
+ carry += BASE * b256[it3] >>> 0;
188
+ b256[it3] = carry % 256 >>> 0;
189
+ carry = carry / 256 >>> 0;
190
+ }
191
+ if (carry !== 0) {
192
+ throw new Error("Non-zero carry");
193
+ }
194
+ length2 = i2;
195
+ psz++;
196
+ }
197
+ if (source[psz] === " ") {
198
+ return;
199
+ }
200
+ var it4 = size - length2;
201
+ while (it4 !== size && b256[it4] === 0) {
202
+ it4++;
203
+ }
204
+ var vch = new Uint8Array(zeroes + (size - it4));
205
+ var j2 = zeroes;
206
+ while (it4 !== size) {
207
+ vch[j2++] = b256[it4++];
208
+ }
209
+ return vch;
210
+ }
211
+ __name(decodeUnsafe, "decodeUnsafe");
212
+ function decode6(string2) {
213
+ var buffer = decodeUnsafe(string2);
214
+ if (buffer) {
215
+ return buffer;
216
+ }
217
+ throw new Error(`Non-${name2} character`);
218
+ }
219
+ __name(decode6, "decode");
220
+ return {
221
+ encode: encode5,
222
+ decodeUnsafe,
223
+ decode: decode6
224
+ };
225
+ }
226
+ __name(base, "base");
227
+ var src = base;
228
+ var _brrp__multiformats_scope_baseX = src;
229
+ var base_x_default = _brrp__multiformats_scope_baseX;
230
+
231
+ // node_modules/multiformats/dist/src/bases/base.js
232
+ var Encoder = class {
233
+ static {
234
+ __name(this, "Encoder");
235
+ }
236
+ name;
237
+ prefix;
238
+ baseEncode;
239
+ constructor(name2, prefix, baseEncode) {
240
+ this.name = name2;
241
+ this.prefix = prefix;
242
+ this.baseEncode = baseEncode;
243
+ }
244
+ encode(bytes) {
245
+ if (bytes instanceof Uint8Array) {
246
+ return `${this.prefix}${this.baseEncode(bytes)}`;
247
+ } else {
248
+ throw Error("Unknown type, must be binary type");
249
+ }
250
+ }
251
+ };
252
+ var Decoder = class {
253
+ static {
254
+ __name(this, "Decoder");
255
+ }
256
+ name;
257
+ prefix;
258
+ baseDecode;
259
+ prefixCodePoint;
260
+ constructor(name2, prefix, baseDecode) {
261
+ this.name = name2;
262
+ this.prefix = prefix;
263
+ const prefixCodePoint = prefix.codePointAt(0);
264
+ if (prefixCodePoint === void 0) {
265
+ throw new Error("Invalid prefix character");
266
+ }
267
+ this.prefixCodePoint = prefixCodePoint;
268
+ this.baseDecode = baseDecode;
269
+ }
270
+ decode(text) {
271
+ if (typeof text === "string") {
272
+ if (text.codePointAt(0) !== this.prefixCodePoint) {
273
+ throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
274
+ }
275
+ return this.baseDecode(text.slice(this.prefix.length));
276
+ } else {
277
+ throw Error("Can only multibase decode strings");
278
+ }
279
+ }
280
+ or(decoder) {
281
+ return or(this, decoder);
282
+ }
283
+ };
284
+ var ComposedDecoder = class {
285
+ static {
286
+ __name(this, "ComposedDecoder");
287
+ }
288
+ decoders;
289
+ constructor(decoders) {
290
+ this.decoders = decoders;
291
+ }
292
+ or(decoder) {
293
+ return or(this, decoder);
294
+ }
295
+ decode(input) {
296
+ const prefix = input[0];
297
+ const decoder = this.decoders[prefix];
298
+ if (decoder != null) {
299
+ return decoder.decode(input);
300
+ } else {
301
+ throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
302
+ }
303
+ }
304
+ };
305
+ function or(left, right) {
306
+ return new ComposedDecoder({
307
+ ...left.decoders ?? { [left.prefix]: left },
308
+ ...right.decoders ?? { [right.prefix]: right }
309
+ });
310
+ }
311
+ __name(or, "or");
312
+ var Codec = class {
313
+ static {
314
+ __name(this, "Codec");
315
+ }
316
+ name;
317
+ prefix;
318
+ baseEncode;
319
+ baseDecode;
320
+ encoder;
321
+ decoder;
322
+ constructor(name2, prefix, baseEncode, baseDecode) {
323
+ this.name = name2;
324
+ this.prefix = prefix;
325
+ this.baseEncode = baseEncode;
326
+ this.baseDecode = baseDecode;
327
+ this.encoder = new Encoder(name2, prefix, baseEncode);
328
+ this.decoder = new Decoder(name2, prefix, baseDecode);
329
+ }
330
+ encode(input) {
331
+ return this.encoder.encode(input);
332
+ }
333
+ decode(input) {
334
+ return this.decoder.decode(input);
335
+ }
336
+ };
337
+ function from({ name: name2, prefix, encode: encode5, decode: decode6 }) {
338
+ return new Codec(name2, prefix, encode5, decode6);
339
+ }
340
+ __name(from, "from");
341
+ function baseX({ name: name2, prefix, alphabet: alphabet2 }) {
342
+ const { encode: encode5, decode: decode6 } = base_x_default(alphabet2, name2);
343
+ return from({
344
+ prefix,
345
+ name: name2,
346
+ encode: encode5,
347
+ decode: /* @__PURE__ */ __name((text) => coerce(decode6(text)), "decode")
348
+ });
349
+ }
350
+ __name(baseX, "baseX");
351
+ function decode(string2, alphabetIdx, bitsPerChar, name2) {
352
+ let end = string2.length;
353
+ while (string2[end - 1] === "=") {
354
+ --end;
355
+ }
356
+ const out = new Uint8Array(end * bitsPerChar / 8 | 0);
357
+ let bits = 0;
358
+ let buffer = 0;
359
+ let written = 0;
360
+ for (let i = 0; i < end; ++i) {
361
+ const value = alphabetIdx[string2[i]];
362
+ if (value === void 0) {
363
+ throw new SyntaxError(`Non-${name2} character`);
364
+ }
365
+ buffer = buffer << bitsPerChar | value;
366
+ bits += bitsPerChar;
367
+ if (bits >= 8) {
368
+ bits -= 8;
369
+ out[written++] = 255 & buffer >> bits;
370
+ }
371
+ }
372
+ if (bits >= bitsPerChar || (255 & buffer << 8 - bits) !== 0) {
373
+ throw new SyntaxError("Unexpected end of data");
374
+ }
375
+ return out;
376
+ }
377
+ __name(decode, "decode");
378
+ function encode(data, alphabet2, bitsPerChar) {
379
+ const pad = alphabet2[alphabet2.length - 1] === "=";
380
+ const mask = (1 << bitsPerChar) - 1;
381
+ let out = "";
382
+ let bits = 0;
383
+ let buffer = 0;
384
+ for (let i = 0; i < data.length; ++i) {
385
+ buffer = buffer << 8 | data[i];
386
+ bits += 8;
387
+ while (bits > bitsPerChar) {
388
+ bits -= bitsPerChar;
389
+ out += alphabet2[mask & buffer >> bits];
390
+ }
391
+ }
392
+ if (bits !== 0) {
393
+ out += alphabet2[mask & buffer << bitsPerChar - bits];
394
+ }
395
+ if (pad) {
396
+ while ((out.length * bitsPerChar & 7) !== 0) {
397
+ out += "=";
398
+ }
399
+ }
400
+ return out;
401
+ }
402
+ __name(encode, "encode");
403
+ function createAlphabetIdx(alphabet2) {
404
+ const alphabetIdx = {};
405
+ for (let i = 0; i < alphabet2.length; ++i) {
406
+ alphabetIdx[alphabet2[i]] = i;
407
+ }
408
+ return alphabetIdx;
409
+ }
410
+ __name(createAlphabetIdx, "createAlphabetIdx");
411
+ function rfc4648({ name: name2, prefix, bitsPerChar, alphabet: alphabet2 }) {
412
+ const alphabetIdx = createAlphabetIdx(alphabet2);
413
+ return from({
414
+ prefix,
415
+ name: name2,
416
+ encode(input) {
417
+ return encode(input, alphabet2, bitsPerChar);
418
+ },
419
+ decode(input) {
420
+ return decode(input, alphabetIdx, bitsPerChar, name2);
421
+ }
422
+ });
423
+ }
424
+ __name(rfc4648, "rfc4648");
425
+
426
+ // node_modules/multiformats/dist/src/bases/base10.js
427
+ var base10 = baseX({
428
+ prefix: "9",
429
+ name: "base10",
430
+ alphabet: "0123456789"
431
+ });
432
+
433
+ // node_modules/multiformats/dist/src/bases/base16.js
434
+ var base16_exports = {};
435
+ __export(base16_exports, {
436
+ base16: () => base16,
437
+ base16upper: () => base16upper
438
+ });
439
+ var base16 = rfc4648({
440
+ prefix: "f",
441
+ name: "base16",
442
+ alphabet: "0123456789abcdef",
443
+ bitsPerChar: 4
444
+ });
445
+ var base16upper = rfc4648({
446
+ prefix: "F",
447
+ name: "base16upper",
448
+ alphabet: "0123456789ABCDEF",
449
+ bitsPerChar: 4
450
+ });
451
+
452
+ // node_modules/multiformats/dist/src/bases/base2.js
453
+ var base2_exports = {};
454
+ __export(base2_exports, {
455
+ base2: () => base2
456
+ });
457
+ var base2 = rfc4648({
458
+ prefix: "0",
459
+ name: "base2",
460
+ alphabet: "01",
461
+ bitsPerChar: 1
462
+ });
463
+
464
+ // node_modules/multiformats/dist/src/bases/base256emoji.js
465
+ var base256emoji_exports = {};
466
+ __export(base256emoji_exports, {
467
+ base256emoji: () => base256emoji
468
+ });
469
+ 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}");
470
+ var alphabetBytesToChars = alphabet.reduce((p, c, i) => {
471
+ p[i] = c;
472
+ return p;
473
+ }, []);
474
+ var alphabetCharsToBytes = alphabet.reduce((p, c, i) => {
475
+ const codePoint = c.codePointAt(0);
476
+ if (codePoint == null) {
477
+ throw new Error(`Invalid character: ${c}`);
478
+ }
479
+ p[codePoint] = i;
480
+ return p;
481
+ }, []);
482
+ function encode2(data) {
483
+ return data.reduce((p, c) => {
484
+ p += alphabetBytesToChars[c];
485
+ return p;
486
+ }, "");
487
+ }
488
+ __name(encode2, "encode");
489
+ function decode2(str) {
490
+ const byts = [];
491
+ for (const char of str) {
492
+ const codePoint = char.codePointAt(0);
493
+ if (codePoint == null) {
494
+ throw new Error(`Invalid character: ${char}`);
495
+ }
496
+ const byt = alphabetCharsToBytes[codePoint];
497
+ if (byt == null) {
498
+ throw new Error(`Non-base256emoji character: ${char}`);
499
+ }
500
+ byts.push(byt);
501
+ }
502
+ return new Uint8Array(byts);
503
+ }
504
+ __name(decode2, "decode");
505
+ var base256emoji = from({
506
+ prefix: "\u{1F680}",
507
+ name: "base256emoji",
508
+ encode: encode2,
509
+ decode: decode2
510
+ });
511
+
512
+ // node_modules/multiformats/dist/src/bases/base32.js
513
+ var base32_exports = {};
514
+ __export(base32_exports, {
515
+ base32: () => base32,
516
+ base32hex: () => base32hex,
517
+ base32hexpad: () => base32hexpad,
518
+ base32hexpadupper: () => base32hexpadupper,
519
+ base32hexupper: () => base32hexupper,
520
+ base32pad: () => base32pad,
521
+ base32padupper: () => base32padupper,
522
+ base32upper: () => base32upper,
523
+ base32z: () => base32z
524
+ });
525
+ var base32 = rfc4648({
526
+ prefix: "b",
527
+ name: "base32",
528
+ alphabet: "abcdefghijklmnopqrstuvwxyz234567",
529
+ bitsPerChar: 5
530
+ });
531
+ var base32upper = rfc4648({
532
+ prefix: "B",
533
+ name: "base32upper",
534
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
535
+ bitsPerChar: 5
536
+ });
537
+ var base32pad = rfc4648({
538
+ prefix: "c",
539
+ name: "base32pad",
540
+ alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
541
+ bitsPerChar: 5
542
+ });
543
+ var base32padupper = rfc4648({
544
+ prefix: "C",
545
+ name: "base32padupper",
546
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
547
+ bitsPerChar: 5
548
+ });
549
+ var base32hex = rfc4648({
550
+ prefix: "v",
551
+ name: "base32hex",
552
+ alphabet: "0123456789abcdefghijklmnopqrstuv",
553
+ bitsPerChar: 5
554
+ });
555
+ var base32hexupper = rfc4648({
556
+ prefix: "V",
557
+ name: "base32hexupper",
558
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
559
+ bitsPerChar: 5
560
+ });
561
+ var base32hexpad = rfc4648({
562
+ prefix: "t",
563
+ name: "base32hexpad",
564
+ alphabet: "0123456789abcdefghijklmnopqrstuv=",
565
+ bitsPerChar: 5
566
+ });
567
+ var base32hexpadupper = rfc4648({
568
+ prefix: "T",
569
+ name: "base32hexpadupper",
570
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
571
+ bitsPerChar: 5
572
+ });
573
+ var base32z = rfc4648({
574
+ prefix: "h",
575
+ name: "base32z",
576
+ alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
577
+ bitsPerChar: 5
578
+ });
579
+
580
+ // node_modules/multiformats/dist/src/bases/base36.js
581
+ var base36_exports = {};
582
+ __export(base36_exports, {
583
+ base36: () => base36,
584
+ base36upper: () => base36upper
585
+ });
586
+ var base36 = baseX({
587
+ prefix: "k",
588
+ name: "base36",
589
+ alphabet: "0123456789abcdefghijklmnopqrstuvwxyz"
590
+ });
591
+ var base36upper = baseX({
592
+ prefix: "K",
593
+ name: "base36upper",
594
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
595
+ });
596
+
597
+ // node_modules/multiformats/dist/src/bases/base58.js
598
+ var base58_exports = {};
599
+ __export(base58_exports, {
600
+ base58btc: () => base58btc,
601
+ base58flickr: () => base58flickr
602
+ });
603
+ var base58btc = baseX({
604
+ name: "base58btc",
605
+ prefix: "z",
606
+ alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
607
+ });
608
+ var base58flickr = baseX({
609
+ name: "base58flickr",
610
+ prefix: "Z",
611
+ alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
612
+ });
613
+
614
+ // node_modules/multiformats/dist/src/bases/base64.js
615
+ var base64_exports = {};
616
+ __export(base64_exports, {
617
+ base64: () => base64,
618
+ base64pad: () => base64pad,
619
+ base64url: () => base64url,
620
+ base64urlpad: () => base64urlpad
621
+ });
622
+ var base64 = rfc4648({
623
+ prefix: "m",
624
+ name: "base64",
625
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
626
+ bitsPerChar: 6
627
+ });
628
+ var base64pad = rfc4648({
629
+ prefix: "M",
630
+ name: "base64pad",
631
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
632
+ bitsPerChar: 6
633
+ });
634
+ var base64url = rfc4648({
635
+ prefix: "u",
636
+ name: "base64url",
637
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
638
+ bitsPerChar: 6
639
+ });
640
+ var base64urlpad = rfc4648({
641
+ prefix: "U",
642
+ name: "base64urlpad",
643
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",
644
+ bitsPerChar: 6
645
+ });
646
+
647
+ // node_modules/multiformats/dist/src/bases/base8.js
648
+ var base8_exports = {};
649
+ __export(base8_exports, {
650
+ base8: () => base8
651
+ });
652
+ var base8 = rfc4648({
653
+ prefix: "7",
654
+ name: "base8",
655
+ alphabet: "01234567",
656
+ bitsPerChar: 3
657
+ });
658
+
659
+ // node_modules/multiformats/dist/src/bases/identity.js
660
+ var identity_exports = {};
661
+ __export(identity_exports, {
662
+ identity: () => identity
663
+ });
664
+ var identity = from({
665
+ prefix: "\0",
666
+ name: "identity",
667
+ encode: /* @__PURE__ */ __name((buf) => toString(buf), "encode"),
668
+ decode: /* @__PURE__ */ __name((str) => fromString(str), "decode")
669
+ });
670
+
671
+ // node_modules/multiformats/dist/src/codecs/json.js
672
+ var textEncoder = new TextEncoder();
673
+ var textDecoder = new TextDecoder();
674
+
675
+ // node_modules/multiformats/dist/src/hashes/identity.js
676
+ var identity_exports2 = {};
677
+ __export(identity_exports2, {
678
+ identity: () => identity2
679
+ });
680
+
681
+ // node_modules/multiformats/dist/src/vendor/varint.js
682
+ var encode_1 = encode3;
683
+ var MSB = 128;
684
+ var REST = 127;
685
+ var MSBALL = ~REST;
686
+ var INT = Math.pow(2, 31);
687
+ function encode3(num, out, offset) {
688
+ out = out || [];
689
+ offset = offset || 0;
690
+ var oldOffset = offset;
691
+ while (num >= INT) {
692
+ out[offset++] = num & 255 | MSB;
693
+ num /= 128;
694
+ }
695
+ while (num & MSBALL) {
696
+ out[offset++] = num & 255 | MSB;
697
+ num >>>= 7;
698
+ }
699
+ out[offset] = num | 0;
700
+ encode3.bytes = offset - oldOffset + 1;
701
+ return out;
702
+ }
703
+ __name(encode3, "encode");
704
+ var decode3 = read;
705
+ var MSB$1 = 128;
706
+ var REST$1 = 127;
707
+ function read(buf, offset) {
708
+ var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
709
+ do {
710
+ if (counter >= l) {
711
+ read.bytes = 0;
712
+ throw new RangeError("Could not decode varint");
713
+ }
714
+ b = buf[counter++];
715
+ res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
716
+ shift += 7;
717
+ } while (b >= MSB$1);
718
+ read.bytes = counter - offset;
719
+ return res;
720
+ }
721
+ __name(read, "read");
722
+ var N1 = Math.pow(2, 7);
723
+ var N2 = Math.pow(2, 14);
724
+ var N3 = Math.pow(2, 21);
725
+ var N4 = Math.pow(2, 28);
726
+ var N5 = Math.pow(2, 35);
727
+ var N6 = Math.pow(2, 42);
728
+ var N7 = Math.pow(2, 49);
729
+ var N8 = Math.pow(2, 56);
730
+ var N9 = Math.pow(2, 63);
731
+ var length = /* @__PURE__ */ __name(function(value) {
732
+ 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;
733
+ }, "length");
734
+ var varint = {
735
+ encode: encode_1,
736
+ decode: decode3,
737
+ encodingLength: length
738
+ };
739
+ var _brrp_varint = varint;
740
+ var varint_default = _brrp_varint;
741
+
742
+ // node_modules/multiformats/dist/src/varint.js
743
+ function decode4(data, offset = 0) {
744
+ const code2 = varint_default.decode(data, offset);
745
+ return [code2, varint_default.decode.bytes];
746
+ }
747
+ __name(decode4, "decode");
748
+ function encodeTo(int, target, offset = 0) {
749
+ varint_default.encode(int, target, offset);
750
+ return target;
751
+ }
752
+ __name(encodeTo, "encodeTo");
753
+ function encodingLength(int) {
754
+ return varint_default.encodingLength(int);
755
+ }
756
+ __name(encodingLength, "encodingLength");
757
+
758
+ // node_modules/multiformats/dist/src/hashes/digest.js
759
+ function create(code2, digest2) {
760
+ const size = digest2.byteLength;
761
+ const sizeOffset = encodingLength(code2);
762
+ const digestOffset = sizeOffset + encodingLength(size);
763
+ const bytes = new Uint8Array(digestOffset + size);
764
+ encodeTo(code2, bytes, 0);
765
+ encodeTo(size, bytes, sizeOffset);
766
+ bytes.set(digest2, digestOffset);
767
+ return new Digest(code2, size, digest2, bytes);
768
+ }
769
+ __name(create, "create");
770
+ function decode5(multihash) {
771
+ const bytes = coerce(multihash);
772
+ const [code2, sizeOffset] = decode4(bytes);
773
+ const [size, digestOffset] = decode4(bytes.subarray(sizeOffset));
774
+ const digest2 = bytes.subarray(sizeOffset + digestOffset);
775
+ if (digest2.byteLength !== size) {
776
+ throw new Error("Incorrect length");
777
+ }
778
+ return new Digest(code2, size, digest2, bytes);
779
+ }
780
+ __name(decode5, "decode");
781
+ function equals2(a, b) {
782
+ if (a === b) {
783
+ return true;
784
+ } else {
785
+ const data = b;
786
+ return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
787
+ }
788
+ }
789
+ __name(equals2, "equals");
790
+ var Digest = class {
791
+ static {
792
+ __name(this, "Digest");
793
+ }
794
+ code;
795
+ size;
796
+ digest;
797
+ bytes;
798
+ /**
799
+ * Creates a multihash digest.
800
+ */
801
+ constructor(code2, size, digest2, bytes) {
802
+ this.code = code2;
803
+ this.size = size;
804
+ this.digest = digest2;
805
+ this.bytes = bytes;
806
+ }
807
+ };
808
+
809
+ // node_modules/multiformats/dist/src/hashes/identity.js
810
+ var code = 0;
811
+ var name = "identity";
812
+ var encode4 = coerce;
813
+ function digest(input, options) {
814
+ if (options?.truncate != null && options.truncate !== input.byteLength) {
815
+ if (options.truncate < 0 || options.truncate > input.byteLength) {
816
+ throw new Error(`Invalid truncate option, must be less than or equal to ${input.byteLength}`);
817
+ }
818
+ input = input.subarray(0, options.truncate);
819
+ }
820
+ return create(code, encode4(input));
821
+ }
822
+ __name(digest, "digest");
823
+ var identity2 = { code, name, encode: encode4, digest };
824
+
825
+ // node_modules/multiformats/dist/src/hashes/sha2-browser.js
826
+ var sha2_browser_exports = {};
827
+ __export(sha2_browser_exports, {
828
+ sha256: () => sha256,
829
+ sha512: () => sha512
830
+ });
831
+
832
+ // node_modules/multiformats/dist/src/hashes/hasher.js
833
+ var DEFAULT_MIN_DIGEST_LENGTH = 20;
834
+ function from2({ name: name2, code: code2, encode: encode5, minDigestLength, maxDigestLength }) {
835
+ return new Hasher(name2, code2, encode5, minDigestLength, maxDigestLength);
836
+ }
837
+ __name(from2, "from");
838
+ var Hasher = class {
839
+ static {
840
+ __name(this, "Hasher");
841
+ }
842
+ name;
843
+ code;
844
+ encode;
845
+ minDigestLength;
846
+ maxDigestLength;
847
+ constructor(name2, code2, encode5, minDigestLength, maxDigestLength) {
848
+ this.name = name2;
849
+ this.code = code2;
850
+ this.encode = encode5;
851
+ this.minDigestLength = minDigestLength ?? DEFAULT_MIN_DIGEST_LENGTH;
852
+ this.maxDigestLength = maxDigestLength;
853
+ }
854
+ digest(input, options) {
855
+ if (options?.truncate != null) {
856
+ if (options.truncate < this.minDigestLength) {
857
+ throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);
858
+ }
859
+ if (this.maxDigestLength != null && options.truncate > this.maxDigestLength) {
860
+ throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`);
861
+ }
862
+ }
863
+ if (input instanceof Uint8Array) {
864
+ const result = this.encode(input);
865
+ if (result instanceof Uint8Array) {
866
+ return createDigest(result, this.code, options?.truncate);
867
+ }
868
+ return result.then((digest2) => createDigest(digest2, this.code, options?.truncate));
869
+ } else {
870
+ throw Error("Unknown type, must be binary type");
871
+ }
872
+ }
873
+ };
874
+ function createDigest(digest2, code2, truncate) {
875
+ if (truncate != null && truncate !== digest2.byteLength) {
876
+ if (truncate > digest2.byteLength) {
877
+ throw new Error(`Invalid truncate option, must be less than or equal to ${digest2.byteLength}`);
878
+ }
879
+ digest2 = digest2.subarray(0, truncate);
880
+ }
881
+ return create(code2, digest2);
882
+ }
883
+ __name(createDigest, "createDigest");
884
+
885
+ // node_modules/multiformats/dist/src/hashes/sha2-browser.js
886
+ function sha(name2) {
887
+ return async (data) => new Uint8Array(await crypto.subtle.digest(name2, data));
888
+ }
889
+ __name(sha, "sha");
890
+ var sha256 = from2({
891
+ name: "sha2-256",
892
+ code: 18,
893
+ encode: sha("SHA-256")
894
+ });
895
+ var sha512 = from2({
896
+ name: "sha2-512",
897
+ code: 19,
898
+ encode: sha("SHA-512")
899
+ });
900
+
901
+ // node_modules/multiformats/dist/src/cid.js
902
+ function format(link, base3) {
903
+ const { bytes, version } = link;
904
+ switch (version) {
905
+ case 0:
906
+ return toStringV0(bytes, baseCache(link), base3 ?? base58btc.encoder);
907
+ default:
908
+ return toStringV1(bytes, baseCache(link), base3 ?? base32.encoder);
909
+ }
910
+ }
911
+ __name(format, "format");
912
+ var cache = /* @__PURE__ */ new WeakMap();
913
+ function baseCache(cid) {
914
+ const baseCache2 = cache.get(cid);
915
+ if (baseCache2 == null) {
916
+ const baseCache3 = /* @__PURE__ */ new Map();
917
+ cache.set(cid, baseCache3);
918
+ return baseCache3;
919
+ }
920
+ return baseCache2;
921
+ }
922
+ __name(baseCache, "baseCache");
923
+ var CID = class _CID {
924
+ static {
925
+ __name(this, "CID");
926
+ }
927
+ code;
928
+ version;
929
+ multihash;
930
+ bytes;
931
+ "/";
932
+ /**
933
+ * @param version - Version of the CID
934
+ * @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
935
+ * @param multihash - (Multi)hash of the of the content.
936
+ */
937
+ constructor(version, code2, multihash, bytes) {
938
+ this.code = code2;
939
+ this.version = version;
940
+ this.multihash = multihash;
941
+ this.bytes = bytes;
942
+ this["/"] = bytes;
943
+ }
944
+ /**
945
+ * Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
946
+ * please either use `CID.asCID(cid)` or switch to new signalling mechanism
947
+ *
948
+ * @deprecated
949
+ */
950
+ get asCID() {
951
+ return this;
952
+ }
953
+ // ArrayBufferView
954
+ get byteOffset() {
955
+ return this.bytes.byteOffset;
956
+ }
957
+ // ArrayBufferView
958
+ get byteLength() {
959
+ return this.bytes.byteLength;
960
+ }
961
+ toV0() {
962
+ switch (this.version) {
963
+ case 0: {
964
+ return this;
965
+ }
966
+ case 1: {
967
+ const { code: code2, multihash } = this;
968
+ if (code2 !== DAG_PB_CODE) {
969
+ throw new Error("Cannot convert a non dag-pb CID to CIDv0");
970
+ }
971
+ if (multihash.code !== SHA_256_CODE) {
972
+ throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
973
+ }
974
+ return _CID.createV0(multihash);
975
+ }
976
+ default: {
977
+ throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
978
+ }
979
+ }
980
+ }
981
+ toV1() {
982
+ switch (this.version) {
983
+ case 0: {
984
+ const { code: code2, digest: digest2 } = this.multihash;
985
+ const multihash = create(code2, digest2);
986
+ return _CID.createV1(this.code, multihash);
987
+ }
988
+ case 1: {
989
+ return this;
990
+ }
991
+ default: {
992
+ throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`);
993
+ }
994
+ }
995
+ }
996
+ equals(other) {
997
+ return _CID.equals(this, other);
998
+ }
999
+ static equals(self, other) {
1000
+ const unknown = other;
1001
+ return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
1002
+ }
1003
+ toString(base3) {
1004
+ return format(this, base3);
1005
+ }
1006
+ toJSON() {
1007
+ return { "/": format(this) };
1008
+ }
1009
+ link() {
1010
+ return this;
1011
+ }
1012
+ [Symbol.toStringTag] = "CID";
1013
+ // Legacy
1014
+ [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
1015
+ return `CID(${this.toString()})`;
1016
+ }
1017
+ /**
1018
+ * Takes any input `value` and returns a `CID` instance if it was
1019
+ * a `CID` otherwise returns `null`. If `value` is instanceof `CID`
1020
+ * it will return value back. If `value` is not instance of this CID
1021
+ * class, but is compatible CID it will return new instance of this
1022
+ * `CID` class. Otherwise returns null.
1023
+ *
1024
+ * This allows two different incompatible versions of CID library to
1025
+ * co-exist and interop as long as binary interface is compatible.
1026
+ */
1027
+ static asCID(input) {
1028
+ if (input == null) {
1029
+ return null;
1030
+ }
1031
+ const value = input;
1032
+ if (value instanceof _CID) {
1033
+ return value;
1034
+ } else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
1035
+ const { version, code: code2, multihash, bytes } = value;
1036
+ return new _CID(version, code2, multihash, bytes ?? encodeCID(version, code2, multihash.bytes));
1037
+ } else if (value[cidSymbol] === true) {
1038
+ const { version, multihash, code: code2 } = value;
1039
+ const digest2 = decode5(multihash);
1040
+ return _CID.create(version, code2, digest2);
1041
+ } else {
1042
+ return null;
1043
+ }
1044
+ }
1045
+ /**
1046
+ * @param version - Version of the CID
1047
+ * @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
1048
+ * @param digest - (Multi)hash of the of the content.
1049
+ */
1050
+ static create(version, code2, digest2) {
1051
+ if (typeof code2 !== "number") {
1052
+ throw new Error("String codecs are no longer supported");
1053
+ }
1054
+ if (!(digest2.bytes instanceof Uint8Array)) {
1055
+ throw new Error("Invalid digest");
1056
+ }
1057
+ switch (version) {
1058
+ case 0: {
1059
+ if (code2 !== DAG_PB_CODE) {
1060
+ throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
1061
+ } else {
1062
+ return new _CID(version, code2, digest2, digest2.bytes);
1063
+ }
1064
+ }
1065
+ case 1: {
1066
+ const bytes = encodeCID(version, code2, digest2.bytes);
1067
+ return new _CID(version, code2, digest2, bytes);
1068
+ }
1069
+ default: {
1070
+ throw new Error("Invalid version");
1071
+ }
1072
+ }
1073
+ }
1074
+ /**
1075
+ * Simplified version of `create` for CIDv0.
1076
+ */
1077
+ static createV0(digest2) {
1078
+ return _CID.create(0, DAG_PB_CODE, digest2);
1079
+ }
1080
+ /**
1081
+ * Simplified version of `create` for CIDv1.
1082
+ *
1083
+ * @param code - Content encoding format code.
1084
+ * @param digest - Multihash of the content.
1085
+ */
1086
+ static createV1(code2, digest2) {
1087
+ return _CID.create(1, code2, digest2);
1088
+ }
1089
+ /**
1090
+ * Decoded a CID from its binary representation. The byte array must contain
1091
+ * only the CID with no additional bytes.
1092
+ *
1093
+ * An error will be thrown if the bytes provided do not contain a valid
1094
+ * binary representation of a CID.
1095
+ */
1096
+ static decode(bytes) {
1097
+ const [cid, remainder] = _CID.decodeFirst(bytes);
1098
+ if (remainder.length !== 0) {
1099
+ throw new Error("Incorrect length");
1100
+ }
1101
+ return cid;
1102
+ }
1103
+ /**
1104
+ * Decoded a CID from its binary representation at the beginning of a byte
1105
+ * array.
1106
+ *
1107
+ * Returns an array with the first element containing the CID and the second
1108
+ * element containing the remainder of the original byte array. The remainder
1109
+ * will be a zero-length byte array if the provided bytes only contained a
1110
+ * binary CID representation.
1111
+ */
1112
+ static decodeFirst(bytes) {
1113
+ const specs = _CID.inspectBytes(bytes);
1114
+ const prefixSize = specs.size - specs.multihashSize;
1115
+ const multihashBytes = coerce(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
1116
+ if (multihashBytes.byteLength !== specs.multihashSize) {
1117
+ throw new Error("Incorrect length");
1118
+ }
1119
+ const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
1120
+ const digest2 = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
1121
+ const cid = specs.version === 0 ? _CID.createV0(digest2) : _CID.createV1(specs.codec, digest2);
1122
+ return [cid, bytes.subarray(specs.size)];
1123
+ }
1124
+ /**
1125
+ * Inspect the initial bytes of a CID to determine its properties.
1126
+ *
1127
+ * Involves decoding up to 4 varints. Typically this will require only 4 to 6
1128
+ * bytes but for larger multicodec code values and larger multihash digest
1129
+ * lengths these varints can be quite large. It is recommended that at least
1130
+ * 10 bytes be made available in the `initialBytes` argument for a complete
1131
+ * inspection.
1132
+ */
1133
+ static inspectBytes(initialBytes) {
1134
+ let offset = 0;
1135
+ const next = /* @__PURE__ */ __name(() => {
1136
+ const [i, length2] = decode4(initialBytes.subarray(offset));
1137
+ offset += length2;
1138
+ return i;
1139
+ }, "next");
1140
+ let version = next();
1141
+ let codec = DAG_PB_CODE;
1142
+ if (version === 18) {
1143
+ version = 0;
1144
+ offset = 0;
1145
+ } else {
1146
+ codec = next();
1147
+ }
1148
+ if (version !== 0 && version !== 1) {
1149
+ throw new RangeError(`Invalid CID version ${version}`);
1150
+ }
1151
+ const prefixSize = offset;
1152
+ const multihashCode = next();
1153
+ const digestSize = next();
1154
+ const size = offset + digestSize;
1155
+ const multihashSize = size - prefixSize;
1156
+ return { version, codec, multihashCode, digestSize, multihashSize, size };
1157
+ }
1158
+ /**
1159
+ * Takes cid in a string representation and creates an instance. If `base`
1160
+ * decoder is not provided will use a default from the configuration. It will
1161
+ * throw an error if encoding of the CID is not compatible with supplied (or
1162
+ * a default decoder).
1163
+ */
1164
+ static parse(source, base3) {
1165
+ const [prefix, bytes] = parseCIDtoBytes(source, base3);
1166
+ const cid = _CID.decode(bytes);
1167
+ if (cid.version === 0 && source[0] !== "Q") {
1168
+ throw Error("Version 0 CID string must not include multibase prefix");
1169
+ }
1170
+ baseCache(cid).set(prefix, source);
1171
+ return cid;
1172
+ }
1173
+ };
1174
+ function parseCIDtoBytes(source, base3) {
1175
+ switch (source[0]) {
1176
+ // CIDv0 is parsed differently
1177
+ case "Q": {
1178
+ const decoder = base3 ?? base58btc;
1179
+ return [
1180
+ base58btc.prefix,
1181
+ decoder.decode(`${base58btc.prefix}${source}`)
1182
+ ];
1183
+ }
1184
+ case base58btc.prefix: {
1185
+ const decoder = base3 ?? base58btc;
1186
+ return [base58btc.prefix, decoder.decode(source)];
1187
+ }
1188
+ case base32.prefix: {
1189
+ const decoder = base3 ?? base32;
1190
+ return [base32.prefix, decoder.decode(source)];
1191
+ }
1192
+ case base36.prefix: {
1193
+ const decoder = base3 ?? base36;
1194
+ return [base36.prefix, decoder.decode(source)];
1195
+ }
1196
+ default: {
1197
+ if (base3 == null) {
1198
+ throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");
1199
+ }
1200
+ return [source[0], base3.decode(source)];
1201
+ }
1202
+ }
1203
+ }
1204
+ __name(parseCIDtoBytes, "parseCIDtoBytes");
1205
+ function toStringV0(bytes, cache2, base3) {
1206
+ const { prefix } = base3;
1207
+ if (prefix !== base58btc.prefix) {
1208
+ throw Error(`Cannot string encode V0 in ${base3.name} encoding`);
1209
+ }
1210
+ const cid = cache2.get(prefix);
1211
+ if (cid == null) {
1212
+ const cid2 = base3.encode(bytes).slice(1);
1213
+ cache2.set(prefix, cid2);
1214
+ return cid2;
1215
+ } else {
1216
+ return cid;
1217
+ }
1218
+ }
1219
+ __name(toStringV0, "toStringV0");
1220
+ function toStringV1(bytes, cache2, base3) {
1221
+ const { prefix } = base3;
1222
+ const cid = cache2.get(prefix);
1223
+ if (cid == null) {
1224
+ const cid2 = base3.encode(bytes);
1225
+ cache2.set(prefix, cid2);
1226
+ return cid2;
1227
+ } else {
1228
+ return cid;
1229
+ }
1230
+ }
1231
+ __name(toStringV1, "toStringV1");
1232
+ var DAG_PB_CODE = 112;
1233
+ var SHA_256_CODE = 18;
1234
+ function encodeCID(version, code2, multihash) {
1235
+ const codeOffset = encodingLength(version);
1236
+ const hashOffset = codeOffset + encodingLength(code2);
1237
+ const bytes = new Uint8Array(hashOffset + multihash.byteLength);
1238
+ encodeTo(version, bytes, 0);
1239
+ encodeTo(code2, bytes, codeOffset);
1240
+ bytes.set(multihash, hashOffset);
1241
+ return bytes;
1242
+ }
1243
+ __name(encodeCID, "encodeCID");
1244
+ var cidSymbol = /* @__PURE__ */ Symbol.for("@ipld/js-cid/CID");
1245
+
1246
+ // node_modules/multiformats/dist/src/basics.js
1247
+ var bases = { ...identity_exports, ...base2_exports, ...base8_exports, ...base10_exports, ...base16_exports, ...base32_exports, ...base36_exports, ...base58_exports, ...base64_exports, ...base256emoji_exports };
1248
+ var hashes = { ...sha2_browser_exports, ...identity_exports2 };
1249
+
1250
+ // node_modules/uint8arrays/dist/src/util/bases.js
1251
+ function createCodec(name2, prefix, encode5, decode6) {
1252
+ return {
1253
+ name: name2,
1254
+ prefix,
1255
+ encoder: {
1256
+ name: name2,
1257
+ prefix,
1258
+ encode: encode5
1259
+ },
1260
+ decoder: {
1261
+ decode: decode6
1262
+ }
1263
+ };
1264
+ }
1265
+ __name(createCodec, "createCodec");
1266
+ var string = createCodec("utf8", "u", (buf) => {
1267
+ const decoder = new TextDecoder("utf8");
1268
+ return "u" + decoder.decode(buf);
1269
+ }, (str) => {
1270
+ const encoder = new TextEncoder();
1271
+ return encoder.encode(str.substring(1));
1272
+ });
1273
+ var ascii = createCodec("ascii", "a", (buf) => {
1274
+ let string2 = "a";
1275
+ for (let i = 0; i < buf.length; i++) {
1276
+ string2 += String.fromCharCode(buf[i]);
1277
+ }
1278
+ return string2;
1279
+ }, (str) => {
1280
+ str = str.substring(1);
1281
+ const buf = allocUnsafe(str.length);
1282
+ for (let i = 0; i < str.length; i++) {
1283
+ buf[i] = str.charCodeAt(i);
1284
+ }
1285
+ return buf;
1286
+ });
1287
+ var BASES = {
1288
+ utf8: string,
1289
+ "utf-8": string,
1290
+ hex: bases.base16,
1291
+ latin1: ascii,
1292
+ ascii,
1293
+ binary: ascii,
1294
+ ...bases
1295
+ };
1296
+ var bases_default = BASES;
1297
+
1298
+ // node_modules/uint8arrays/dist/src/from-string.js
1299
+ function fromString2(string2, encoding = "utf8") {
1300
+ const base3 = bases_default[encoding];
1301
+ if (base3 == null) {
1302
+ throw new Error(`Unsupported encoding "${encoding}"`);
1303
+ }
1304
+ return base3.decoder.decode(`${base3.prefix}${string2}`);
1305
+ }
1306
+ __name(fromString2, "fromString");
1307
+
1308
+ // node_modules/uint8arrays/dist/src/to-string.js
1309
+ function toString2(array, encoding = "utf8") {
1310
+ const base3 = bases_default[encoding];
1311
+ if (base3 == null) {
1312
+ throw new Error(`Unsupported encoding "${encoding}"`);
1313
+ }
1314
+ return base3.encoder.encode(array).substring(1);
1315
+ }
1316
+ __name(toString2, "toString");
1317
+
1318
+ // src/index.ts
1319
+ var subtle = globalThis.crypto.subtle;
1320
+ async function create2(recipient, opts) {
1321
+ const { wrapped, key } = await encryptKey(recipient, null, opts);
1322
+ return { enc: wrapped, key };
1323
+ }
1324
+ __name(create2, "create");
1325
+ async function seal(recipient, aesKey, opts) {
1326
+ const { wrapped, key } = await encryptKey(recipient, aesKey, opts);
1327
+ return { enc: wrapped, key };
1328
+ }
1329
+ __name(seal, "seal");
1330
+ var open = Object.assign(openBytes, {
1331
+ raw: openRawBytes
1332
+ });
1333
+ var encrypt = Object.assign(encryptBytes, {
1334
+ asString: encryptToString
1335
+ });
1336
+ var decrypt = Object.assign(decryptBytes, {
1337
+ asString: decryptToString,
1338
+ fromString: decryptFromString
1339
+ });
1340
+ async function decryptBytes(keypair, message, opts) {
1341
+ if (message.byteLength < WRAPPED_LEN_PREFIX) {
1342
+ throw new Error("malformed message: too short");
1343
+ }
1344
+ const wrappedLen = message[0] << 8 | message[1];
1345
+ const ivStart = WRAPPED_LEN_PREFIX + wrappedLen;
1346
+ const ctStart = ivStart + NN;
1347
+ if (message.byteLength < ctStart + AEAD_TAG_LENGTH) {
1348
+ throw new Error("malformed message: too short");
1349
+ }
1350
+ const wrapped = message.slice(WRAPPED_LEN_PREFIX, ivStart);
1351
+ const iv = message.slice(ivStart, ctStart);
1352
+ const ciphertext = message.slice(ctStart);
1353
+ const keyBytes = await openRawBytes(
1354
+ keypair,
1355
+ wrapped,
1356
+ opts?.info !== void 0 ? { info: opts.info } : void 0
1357
+ );
1358
+ const key = await importAesKeyDecryptOnly(keyBytes);
1359
+ const pt = await subtle.decrypt(
1360
+ { name: "AES-GCM", iv },
1361
+ key,
1362
+ ciphertext
1363
+ );
1364
+ return new Uint8Array(pt);
1365
+ }
1366
+ __name(decryptBytes, "decryptBytes");
1367
+ async function decryptToString(keypair, message, opts) {
1368
+ const bytes = await decryptBytes(keypair, message, opts);
1369
+ return new TextDecoder().decode(bytes);
1370
+ }
1371
+ __name(decryptToString, "decryptToString");
1372
+ async function decryptFromString(keypair, message, opts) {
1373
+ const bytes = fromString2(message, "base64url");
1374
+ const plaintext = await decryptBytes(
1375
+ keypair,
1376
+ bytes,
1377
+ opts?.info !== void 0 ? { info: opts.info } : void 0
1378
+ );
1379
+ return opts?.buffer ? plaintext : new TextDecoder().decode(plaintext);
1380
+ }
1381
+ __name(decryptFromString, "decryptFromString");
1382
+ function validateKeysize(keysize) {
1383
+ if (keysize !== 128 && keysize !== 256) {
1384
+ throw new Error(
1385
+ `invalid keysize: ${keysize} (expected 128 or 256)`
1386
+ );
1387
+ }
1388
+ }
1389
+ __name(validateKeysize, "validateKeysize");
1390
+ function validateRawKeyBytes(raw) {
1391
+ if (raw.length !== 16 && raw.length !== 32) {
1392
+ throw new Error(
1393
+ `invalid aesKey length: ${raw.length} bytes (expected 16 or 32)`
1394
+ );
1395
+ }
1396
+ }
1397
+ __name(validateRawKeyBytes, "validateRawKeyBytes");
1398
+ function normalizeInfo(info) {
1399
+ if (info === void 0 || info === null) return new Uint8Array(0);
1400
+ if (typeof info === "string") return new TextEncoder().encode(info);
1401
+ return info;
1402
+ }
1403
+ __name(normalizeInfo, "normalizeInfo");
1404
+ async function exportAesKeyBytes(key) {
1405
+ if (!key.extractable) {
1406
+ throw new Error(
1407
+ "aesKey must be extractable: its raw bytes are what get sealed"
1408
+ );
1409
+ }
1410
+ return new Uint8Array(await subtle.exportKey("raw", key));
1411
+ }
1412
+ __name(exportAesKeyBytes, "exportAesKeyBytes");
1413
+ async function importAesKey(raw) {
1414
+ return subtle.importKey(
1415
+ "raw",
1416
+ raw,
1417
+ { name: "AES-GCM" },
1418
+ true,
1419
+ ["encrypt", "decrypt"]
1420
+ );
1421
+ }
1422
+ __name(importAesKey, "importAesKey");
1423
+ async function importAesKeyDecryptOnly(raw) {
1424
+ return subtle.importKey(
1425
+ "raw",
1426
+ raw,
1427
+ { name: "AES-GCM" },
1428
+ false,
1429
+ ["decrypt"]
1430
+ );
1431
+ }
1432
+ __name(importAesKeyDecryptOnly, "importAesKeyDecryptOnly");
1433
+ async function keySchedule(sharedSecret, info) {
1434
+ const empty2 = new Uint8Array(0);
1435
+ const pskIdHash = await labeledExtract(
1436
+ HPKE_SUITE_ID,
1437
+ empty2,
1438
+ "psk_id_hash",
1439
+ empty2
1440
+ );
1441
+ const infoHash = await labeledExtract(
1442
+ HPKE_SUITE_ID,
1443
+ empty2,
1444
+ "info_hash",
1445
+ info
1446
+ );
1447
+ const ksContext = concat2(new Uint8Array([MODE_BASE]), pskIdHash, infoHash);
1448
+ const secret = await labeledExtract(
1449
+ HPKE_SUITE_ID,
1450
+ sharedSecret,
1451
+ "secret",
1452
+ empty2
1453
+ );
1454
+ const key = await labeledExpand(
1455
+ HPKE_SUITE_ID,
1456
+ secret,
1457
+ "key",
1458
+ ksContext,
1459
+ NK
1460
+ );
1461
+ const baseNonce = await labeledExpand(
1462
+ HPKE_SUITE_ID,
1463
+ secret,
1464
+ "base_nonce",
1465
+ ksContext,
1466
+ NN
1467
+ );
1468
+ return { key, baseNonce };
1469
+ }
1470
+ __name(keySchedule, "keySchedule");
1471
+ async function openRawBytes(keypair, wrapped, opts) {
1472
+ if (wrapped.byteLength < ENC_LENGTH + AEAD_TAG_LENGTH) {
1473
+ throw new Error("malformed envelope: too short");
1474
+ }
1475
+ const info = normalizeInfo(opts?.info);
1476
+ const enc = wrapped.slice(0, ENC_LENGTH);
1477
+ const ciphertext = wrapped.slice(ENC_LENGTH);
1478
+ const sharedSecret = await decap(enc, keypair);
1479
+ const { key, baseNonce } = await keySchedule(sharedSecret, info);
1480
+ return aeadOpen(key, baseNonce, ciphertext);
1481
+ }
1482
+ __name(openRawBytes, "openRawBytes");
1483
+ async function openBytes(keypair, wrapped, opts) {
1484
+ const keyBytes = await openRawBytes(keypair, wrapped, opts);
1485
+ return importAesKey(keyBytes);
1486
+ }
1487
+ __name(openBytes, "openBytes");
1488
+ async function encryptKey(recipient, aesKey, opts) {
1489
+ const info = normalizeInfo(opts?.info);
1490
+ let keyBytes;
1491
+ if (aesKey instanceof Uint8Array) {
1492
+ validateRawKeyBytes(aesKey);
1493
+ keyBytes = aesKey;
1494
+ } else if (aesKey) {
1495
+ keyBytes = await exportAesKeyBytes(aesKey);
1496
+ validateRawKeyBytes(keyBytes);
1497
+ } else {
1498
+ const keysize = opts?.size ?? 256;
1499
+ validateKeysize(keysize);
1500
+ keyBytes = globalThis.crypto.getRandomValues(
1501
+ new Uint8Array(keysize / 8)
1502
+ );
1503
+ }
1504
+ const publicKey = await resolveRecipientPublicKey(recipient);
1505
+ const { sharedSecret, enc } = await encap(publicKey);
1506
+ const { key, baseNonce } = await keySchedule(sharedSecret, info);
1507
+ const ciphertext = await aeadSeal(key, baseNonce, keyBytes);
1508
+ const wrapped = concat2(enc, ciphertext);
1509
+ const aesGcmKey = await importAesKey(keyBytes);
1510
+ return { wrapped, key: aesGcmKey };
1511
+ }
1512
+ __name(encryptKey, "encryptKey");
1513
+
1514
+ // src/util.ts
1515
+ var subtle2 = globalThis.crypto.subtle;
1516
+ async function aeadSeal(key, nonce, plaintext) {
1517
+ const k = await subtle2.importKey(
1518
+ "raw",
1519
+ key,
1520
+ { name: "AES-GCM" },
1521
+ false,
1522
+ ["encrypt"]
1523
+ );
1524
+ const ct = await subtle2.encrypt(
1525
+ { name: "AES-GCM", iv: nonce },
1526
+ k,
1527
+ plaintext
1528
+ );
1529
+ return new Uint8Array(ct);
1530
+ }
1531
+ __name(aeadSeal, "aeadSeal");
1532
+ async function aeadOpen(key, nonce, ciphertext) {
1533
+ const k = await subtle2.importKey(
1534
+ "raw",
1535
+ key,
1536
+ { name: "AES-GCM" },
1537
+ false,
1538
+ ["decrypt"]
1539
+ );
1540
+ const pt = await subtle2.decrypt(
1541
+ { name: "AES-GCM", iv: nonce },
1542
+ k,
1543
+ ciphertext
1544
+ );
1545
+ return new Uint8Array(pt);
1546
+ }
1547
+ __name(aeadOpen, "aeadOpen");
1548
+ async function encryptBytes(recipient, message, aesKey, opts) {
1549
+ const plaintext = typeof message === "string" ? new TextEncoder().encode(message) : message;
1550
+ let enc;
1551
+ let key;
1552
+ if (!aesKey) {
1553
+ const keys = await create2(recipient, opts);
1554
+ enc = keys.enc;
1555
+ key = keys.key;
1556
+ } else {
1557
+ const keys = await seal(recipient, aesKey, opts);
1558
+ enc = keys.enc;
1559
+ key = keys.key;
1560
+ }
1561
+ const iv = globalThis.crypto.getRandomValues(new Uint8Array(NN));
1562
+ const ct = new Uint8Array(await subtle2.encrypt(
1563
+ { name: "AES-GCM", iv },
1564
+ key,
1565
+ plaintext
1566
+ ));
1567
+ return concat2(i2osp(enc.length, WRAPPED_LEN_PREFIX), enc, iv, ct);
1568
+ }
1569
+ __name(encryptBytes, "encryptBytes");
1570
+ async function encryptToString(recipient, message, aesKey, opts) {
1571
+ const envelope = await encryptBytes(recipient, message, aesKey, opts);
1572
+ return toString2(envelope, opts?.encoding ?? "base64url");
1573
+ }
1574
+ __name(encryptToString, "encryptToString");
1575
+ async function hmac(key, data) {
1576
+ const k = await subtle2.importKey(
1577
+ "raw",
1578
+ key,
1579
+ { name: "HMAC", hash: "SHA-256" },
1580
+ false,
1581
+ ["sign"]
1582
+ );
1583
+ return new Uint8Array(await subtle2.sign("HMAC", k, data));
1584
+ }
1585
+ __name(hmac, "hmac");
1586
+ async function extract(salt, ikm) {
1587
+ const key = salt.length === 0 ? new Uint8Array(NSECRET) : salt;
1588
+ return hmac(key, ikm);
1589
+ }
1590
+ __name(extract, "extract");
1591
+ async function expand(prk, info, length2) {
1592
+ const out = new Uint8Array(length2);
1593
+ let t = new Uint8Array(0);
1594
+ let offset = 0;
1595
+ let counter = 1;
1596
+ while (offset < length2) {
1597
+ t = await hmac(prk, concat2(t, info, i2osp(counter, 1)));
1598
+ const take = Math.min(t.length, length2 - offset);
1599
+ out.set(t.subarray(0, take), offset);
1600
+ offset += take;
1601
+ counter++;
1602
+ }
1603
+ return out;
1604
+ }
1605
+ __name(expand, "expand");
1606
+ async function labeledExtract(suiteId, salt, label, ikm) {
1607
+ const labeledIkm = concat2(
1608
+ HPKE_V1,
1609
+ suiteId,
1610
+ new TextEncoder().encode(label),
1611
+ ikm
1612
+ );
1613
+ return extract(salt, labeledIkm);
1614
+ }
1615
+ __name(labeledExtract, "labeledExtract");
1616
+ async function labeledExpand(suiteId, prk, label, info, length2) {
1617
+ const labeledInfo = concat2(
1618
+ i2osp(length2, 2),
1619
+ HPKE_V1,
1620
+ suiteId,
1621
+ new TextEncoder().encode(label),
1622
+ info
1623
+ );
1624
+ return expand(prk, labeledInfo, length2);
1625
+ }
1626
+ __name(labeledExpand, "labeledExpand");
1627
+ async function exportRawPublic(key) {
1628
+ return new Uint8Array(await subtle2.exportKey("raw", key));
1629
+ }
1630
+ __name(exportRawPublic, "exportRawPublic");
1631
+ async function importRawPublic(raw) {
1632
+ if (raw.length !== ENC_LENGTH) {
1633
+ throw new Error(
1634
+ `invalid public key length: ${raw.length} bytes (expected ${ENC_LENGTH})`
1635
+ );
1636
+ }
1637
+ return subtle2.importKey(
1638
+ "raw",
1639
+ raw,
1640
+ { name: "X25519" },
1641
+ true,
1642
+ []
1643
+ );
1644
+ }
1645
+ __name(importRawPublic, "importRawPublic");
1646
+ async function resolveRecipientPublicKey(recipient) {
1647
+ if (recipient instanceof Uint8Array) {
1648
+ return importRawPublic(recipient);
1649
+ }
1650
+ if (recipient instanceof CryptoKey) {
1651
+ if (recipient.type !== "public") {
1652
+ throw new Error("recipient CryptoKey must be a public key");
1653
+ }
1654
+ assertX25519Algorithm(recipient, "recipient CryptoKey");
1655
+ return recipient;
1656
+ }
1657
+ if (typeof recipient.publicKey === "string") {
1658
+ const { publicKey, encoding } = recipient;
1659
+ return importRawPublic(fromString2(publicKey, encoding ?? "base64url"));
1660
+ }
1661
+ const pair = recipient;
1662
+ if (pair.publicKey instanceof CryptoKey) {
1663
+ if (pair.publicKey.type !== "public") {
1664
+ throw new Error("recipient keypair publicKey must be a public key");
1665
+ }
1666
+ assertX25519Algorithm(pair.publicKey, "recipient keypair publicKey");
1667
+ return pair.publicKey;
1668
+ }
1669
+ throw new Error("unrecognized recipient key form");
1670
+ }
1671
+ __name(resolveRecipientPublicKey, "resolveRecipientPublicKey");
1672
+ function assertX25519Algorithm(key, context) {
1673
+ if (key.algorithm.name !== "X25519") {
1674
+ throw new Error(
1675
+ `${context} must be an X25519 key (got ${key.algorithm.name})`
1676
+ );
1677
+ }
1678
+ }
1679
+ __name(assertX25519Algorithm, "assertX25519Algorithm");
1680
+ async function dh(priv, pub) {
1681
+ const bits = await subtle2.deriveBits(
1682
+ { name: "X25519", public: pub },
1683
+ priv,
1684
+ 256
1685
+ );
1686
+ const bytes = new Uint8Array(bits);
1687
+ if (bytes.every((b) => b === 0)) {
1688
+ throw new Error(
1689
+ "X25519 shared secret is all-zero (small-order public key?)"
1690
+ );
1691
+ }
1692
+ return bytes;
1693
+ }
1694
+ __name(dh, "dh");
1695
+ async function extractAndExpand(dhBytes, kemContext) {
1696
+ const eaePrk = await labeledExtract(
1697
+ KEM_SUITE_ID,
1698
+ new Uint8Array(0),
1699
+ "eae_prk",
1700
+ dhBytes
1701
+ );
1702
+ return labeledExpand(
1703
+ KEM_SUITE_ID,
1704
+ eaePrk,
1705
+ "shared_secret",
1706
+ kemContext,
1707
+ NSECRET
1708
+ );
1709
+ }
1710
+ __name(extractAndExpand, "extractAndExpand");
1711
+ async function encap(pkR) {
1712
+ const eph = await subtle2.generateKey(
1713
+ { name: "X25519" },
1714
+ false,
1715
+ ["deriveBits"]
1716
+ );
1717
+ const dhBytes = await dh(eph.privateKey, pkR);
1718
+ const enc = await exportRawPublic(eph.publicKey);
1719
+ const pkRm = await exportRawPublic(pkR);
1720
+ const kemContext = concat2(enc, pkRm);
1721
+ const sharedSecret = await extractAndExpand(dhBytes, kemContext);
1722
+ return { sharedSecret, enc };
1723
+ }
1724
+ __name(encap, "encap");
1725
+ async function decap(enc, keypair) {
1726
+ if (keypair.privateKey.type !== "private") {
1727
+ throw new Error("keypair.privateKey must be a private key");
1728
+ }
1729
+ assertX25519Algorithm(keypair.privateKey, "keypair.privateKey");
1730
+ const pkE = await subtle2.importKey(
1731
+ "raw",
1732
+ enc,
1733
+ { name: "X25519" },
1734
+ false,
1735
+ []
1736
+ );
1737
+ const dhBytes = await dh(keypair.privateKey, pkE);
1738
+ const pkRm = await exportRawPublic(keypair.publicKey);
1739
+ const kemContext = concat2(enc, pkRm);
1740
+ return extractAndExpand(dhBytes, kemContext);
1741
+ }
1742
+ __name(decap, "decap");
1743
+ function i2osp(n, len) {
1744
+ const out = new Uint8Array(len);
1745
+ let v = n;
1746
+ for (let i = len - 1; i >= 0; i--) {
1747
+ out[i] = v & 255;
1748
+ v = Math.floor(v / 256);
1749
+ }
1750
+ return out;
1751
+ }
1752
+ __name(i2osp, "i2osp");
1753
+ function concat2(...arrays) {
1754
+ let total = 0;
1755
+ for (const a of arrays) total += a.length;
1756
+ const out = new Uint8Array(total);
1757
+ let offset = 0;
1758
+ for (const a of arrays) {
1759
+ out.set(a, offset);
1760
+ offset += a.length;
1761
+ }
1762
+ return out;
1763
+ }
1764
+ __name(concat2, "concat");
1765
+
1766
+ // src/constants.ts
1767
+ var KEM_ID = 32;
1768
+ var KDF_ID = 1;
1769
+ var AEAD_ID = 2;
1770
+ var NSECRET = 32;
1771
+ var NK = 32;
1772
+ var NN = 12;
1773
+ var ENC_LENGTH = 32;
1774
+ var AEAD_TAG_LENGTH = 16;
1775
+ var MODE_BASE = 0;
1776
+ var HPKE_V1 = new TextEncoder().encode("HPKE-v1");
1777
+ var WRAPPED_LEN_PREFIX = 2;
1778
+ var KEM_SUITE_ID = concat2(
1779
+ new TextEncoder().encode("KEM"),
1780
+ i2osp(KEM_ID, 2)
1781
+ );
1782
+ var HPKE_SUITE_ID = concat2(
1783
+ new TextEncoder().encode("HPKE"),
1784
+ i2osp(KEM_ID, 2),
1785
+ i2osp(KDF_ID, 2),
1786
+ i2osp(AEAD_ID, 2)
1787
+ );
1788
+ //# sourceMappingURL=constants.cjs.map