@wovin/core 0.1.25 → 0.1.27
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.
- package/dist/applog.min.js +2 -1
- package/dist/blockstore/index.d.ts +21 -0
- package/dist/blockstore/index.d.ts.map +1 -0
- package/dist/blockstore.d.ts +2 -0
- package/dist/blockstore.d.ts.map +1 -0
- package/dist/blockstore.min.js +26 -0
- package/dist/blockstore.min.js.map +1 -0
- package/dist/{chunk-ZGU3O24G.min.js → chunk-CWVWWFE3.min.js} +6 -6
- package/dist/chunk-CWVWWFE3.min.js.map +1 -0
- package/dist/{chunk-USEP3ZEM.min.js → chunk-LHD7NNK6.min.js} +2 -2
- package/dist/{chunk-ITZTLALV.min.js → chunk-MCMSRRF7.min.js} +2 -2
- package/dist/chunk-MCMSRRF7.min.js.map +1 -0
- package/dist/{chunk-SA7YLEF6.min.js → chunk-N2LOFNFT.min.js} +20 -8
- package/dist/chunk-N2LOFNFT.min.js.map +1 -0
- package/dist/{chunk-CWGXD56S.min.js → chunk-NKGFXL72.min.js} +18 -13
- package/dist/{chunk-CWGXD56S.min.js.map → chunk-NKGFXL72.min.js.map} +1 -1
- package/dist/chunk-QO2KMGDN.min.js +3771 -0
- package/dist/chunk-QO2KMGDN.min.js.map +1 -0
- package/dist/{chunk-R7EMHBM3.min.js → chunk-XWBLRTV5.min.js} +783 -4064
- package/dist/chunk-XWBLRTV5.min.js.map +1 -0
- package/dist/{chunk-HHFNRKOI.min.js → chunk-YUH56CPQ.min.js} +2 -2
- package/dist/index.min.js +16 -13
- package/dist/ipfs.min.js +5 -4
- package/dist/ipns/ipns-record.d.ts +34 -0
- package/dist/ipns/ipns-record.d.ts.map +1 -0
- package/dist/ipns.d.ts +2 -0
- package/dist/ipns.d.ts.map +1 -0
- package/dist/ipns.min.js +6419 -0
- package/dist/ipns.min.js.map +1 -0
- package/dist/pubsub/pubsub-types.d.ts +1 -1
- package/dist/pubsub/pubsub-types.d.ts.map +1 -1
- package/dist/pubsub/snap-push.d.ts +2 -2
- package/dist/pubsub/snap-push.d.ts.map +1 -1
- package/dist/pubsub.min.js +5 -4
- package/dist/query.min.js +4 -3
- package/dist/retrieve/update-thread.d.ts +8 -1
- package/dist/retrieve/update-thread.d.ts.map +1 -1
- package/dist/retrieve.min.js +9 -6
- package/dist/thread.min.js +2 -1
- package/package.json +11 -1
- package/dist/chunk-ITZTLALV.min.js.map +0 -1
- package/dist/chunk-R7EMHBM3.min.js.map +0 -1
- package/dist/chunk-SA7YLEF6.min.js.map +0 -1
- package/dist/chunk-ZGU3O24G.min.js.map +0 -1
- /package/dist/{chunk-USEP3ZEM.min.js.map → chunk-LHD7NNK6.min.js.map} +0 -0
- /package/dist/{chunk-HHFNRKOI.min.js.map → chunk-YUH56CPQ.min.js.map} +0 -0
|
@@ -0,0 +1,3771 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-PHITDXZT.min.js";
|
|
4
|
+
|
|
5
|
+
// ../../../node_modules/.pnpm/cborg@4.5.8/node_modules/cborg/lib/is.js
|
|
6
|
+
var objectTypeNames = [
|
|
7
|
+
"Object",
|
|
8
|
+
// for Object.create(null) and other non-plain objects
|
|
9
|
+
"RegExp",
|
|
10
|
+
"Date",
|
|
11
|
+
"Error",
|
|
12
|
+
"Map",
|
|
13
|
+
"Set",
|
|
14
|
+
"WeakMap",
|
|
15
|
+
"WeakSet",
|
|
16
|
+
"ArrayBuffer",
|
|
17
|
+
"SharedArrayBuffer",
|
|
18
|
+
"DataView",
|
|
19
|
+
"Promise",
|
|
20
|
+
"URL",
|
|
21
|
+
"HTMLElement",
|
|
22
|
+
"Int8Array",
|
|
23
|
+
"Uint8ClampedArray",
|
|
24
|
+
"Int16Array",
|
|
25
|
+
"Uint16Array",
|
|
26
|
+
"Int32Array",
|
|
27
|
+
"Uint32Array",
|
|
28
|
+
"Float32Array",
|
|
29
|
+
"Float64Array",
|
|
30
|
+
"BigInt64Array",
|
|
31
|
+
"BigUint64Array"
|
|
32
|
+
];
|
|
33
|
+
function is(value) {
|
|
34
|
+
if (value === null) {
|
|
35
|
+
return "null";
|
|
36
|
+
}
|
|
37
|
+
if (value === void 0) {
|
|
38
|
+
return "undefined";
|
|
39
|
+
}
|
|
40
|
+
if (value === true || value === false) {
|
|
41
|
+
return "boolean";
|
|
42
|
+
}
|
|
43
|
+
const typeOf = typeof value;
|
|
44
|
+
if (typeOf === "string" || typeOf === "number" || typeOf === "bigint" || typeOf === "symbol") {
|
|
45
|
+
return typeOf;
|
|
46
|
+
}
|
|
47
|
+
if (typeOf === "function") {
|
|
48
|
+
return "Function";
|
|
49
|
+
}
|
|
50
|
+
if (Array.isArray(value)) {
|
|
51
|
+
return "Array";
|
|
52
|
+
}
|
|
53
|
+
if (value instanceof Uint8Array) {
|
|
54
|
+
return "Uint8Array";
|
|
55
|
+
}
|
|
56
|
+
if (value.constructor === Object) {
|
|
57
|
+
return "Object";
|
|
58
|
+
}
|
|
59
|
+
const objectType = getObjectType(value);
|
|
60
|
+
if (objectType) {
|
|
61
|
+
return objectType;
|
|
62
|
+
}
|
|
63
|
+
return "Object";
|
|
64
|
+
}
|
|
65
|
+
function getObjectType(value) {
|
|
66
|
+
const objectTypeName = Object.prototype.toString.call(value).slice(8, -1);
|
|
67
|
+
if (objectTypeNames.includes(objectTypeName)) {
|
|
68
|
+
return objectTypeName;
|
|
69
|
+
}
|
|
70
|
+
return void 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ../../../node_modules/.pnpm/cborg@4.5.8/node_modules/cborg/lib/token.js
|
|
74
|
+
var Type = class {
|
|
75
|
+
/**
|
|
76
|
+
* @param {number} major
|
|
77
|
+
* @param {string} name
|
|
78
|
+
* @param {boolean} terminal
|
|
79
|
+
*/
|
|
80
|
+
constructor(major, name, terminal) {
|
|
81
|
+
this.major = major;
|
|
82
|
+
this.majorEncoded = major << 5;
|
|
83
|
+
this.name = name;
|
|
84
|
+
this.terminal = terminal;
|
|
85
|
+
}
|
|
86
|
+
/* c8 ignore next 3 */
|
|
87
|
+
toString() {
|
|
88
|
+
return `Type[${this.major}].${this.name}`;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @param {Type} typ
|
|
92
|
+
* @returns {number}
|
|
93
|
+
*/
|
|
94
|
+
compare(typ) {
|
|
95
|
+
return this.major < typ.major ? -1 : this.major > typ.major ? 1 : 0;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Check equality between two Type instances. Safe to use across different
|
|
99
|
+
* copies of the Type class (e.g., when bundlers duplicate the module).
|
|
100
|
+
* (major, name) uniquely identifies a Type; terminal is implied by these.
|
|
101
|
+
* @param {Type} a
|
|
102
|
+
* @param {Type} b
|
|
103
|
+
* @returns {boolean}
|
|
104
|
+
*/
|
|
105
|
+
static equals(a, b) {
|
|
106
|
+
return a === b || a.major === b.major && a.name === b.name;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
Type.uint = new Type(0, "uint", true);
|
|
110
|
+
Type.negint = new Type(1, "negint", true);
|
|
111
|
+
Type.bytes = new Type(2, "bytes", true);
|
|
112
|
+
Type.string = new Type(3, "string", true);
|
|
113
|
+
Type.array = new Type(4, "array", false);
|
|
114
|
+
Type.map = new Type(5, "map", false);
|
|
115
|
+
Type.tag = new Type(6, "tag", false);
|
|
116
|
+
Type.float = new Type(7, "float", true);
|
|
117
|
+
Type.false = new Type(7, "false", true);
|
|
118
|
+
Type.true = new Type(7, "true", true);
|
|
119
|
+
Type.null = new Type(7, "null", true);
|
|
120
|
+
Type.undefined = new Type(7, "undefined", true);
|
|
121
|
+
Type.break = new Type(7, "break", true);
|
|
122
|
+
var Token = class {
|
|
123
|
+
/**
|
|
124
|
+
* @param {Type} type
|
|
125
|
+
* @param {any} [value]
|
|
126
|
+
* @param {number} [encodedLength]
|
|
127
|
+
*/
|
|
128
|
+
constructor(type, value, encodedLength) {
|
|
129
|
+
this.type = type;
|
|
130
|
+
this.value = value;
|
|
131
|
+
this.encodedLength = encodedLength;
|
|
132
|
+
this.encodedBytes = void 0;
|
|
133
|
+
this.byteValue = void 0;
|
|
134
|
+
}
|
|
135
|
+
/* c8 ignore next 3 */
|
|
136
|
+
toString() {
|
|
137
|
+
return `Token[${this.type}].${this.value}`;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// ../../../node_modules/.pnpm/cborg@4.5.8/node_modules/cborg/lib/byte-utils.js
|
|
142
|
+
var useBuffer = globalThis.process && // @ts-ignore
|
|
143
|
+
!globalThis.process.browser && // @ts-ignore
|
|
144
|
+
globalThis.Buffer && // @ts-ignore
|
|
145
|
+
typeof globalThis.Buffer.isBuffer === "function";
|
|
146
|
+
var textEncoder = new TextEncoder();
|
|
147
|
+
function isBuffer(buf) {
|
|
148
|
+
return useBuffer && globalThis.Buffer.isBuffer(buf);
|
|
149
|
+
}
|
|
150
|
+
function asU8A(buf) {
|
|
151
|
+
if (!(buf instanceof Uint8Array)) {
|
|
152
|
+
return Uint8Array.from(buf);
|
|
153
|
+
}
|
|
154
|
+
return isBuffer(buf) ? new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength) : buf;
|
|
155
|
+
}
|
|
156
|
+
var FROM_STRING_THRESHOLD_BUFFER = 24;
|
|
157
|
+
var FROM_STRING_THRESHOLD_TEXTENCODER = 200;
|
|
158
|
+
var fromString = useBuffer ? (
|
|
159
|
+
// eslint-disable-line operator-linebreak
|
|
160
|
+
/**
|
|
161
|
+
* @param {string} string
|
|
162
|
+
*/
|
|
163
|
+
(string) => {
|
|
164
|
+
return string.length >= FROM_STRING_THRESHOLD_BUFFER ? (
|
|
165
|
+
// eslint-disable-line operator-linebreak
|
|
166
|
+
// @ts-ignore
|
|
167
|
+
globalThis.Buffer.from(string)
|
|
168
|
+
) : utf8ToBytes(string);
|
|
169
|
+
}
|
|
170
|
+
) : (
|
|
171
|
+
// eslint-disable-line operator-linebreak
|
|
172
|
+
/**
|
|
173
|
+
* @param {string} string
|
|
174
|
+
*/
|
|
175
|
+
(string) => {
|
|
176
|
+
return string.length >= FROM_STRING_THRESHOLD_TEXTENCODER ? textEncoder.encode(string) : utf8ToBytes(string);
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
var fromArray = (arr) => {
|
|
180
|
+
return Uint8Array.from(arr);
|
|
181
|
+
};
|
|
182
|
+
var slice = useBuffer ? (
|
|
183
|
+
// eslint-disable-line operator-linebreak
|
|
184
|
+
/**
|
|
185
|
+
* @param {Uint8Array} bytes
|
|
186
|
+
* @param {number} start
|
|
187
|
+
* @param {number} end
|
|
188
|
+
*/
|
|
189
|
+
// Buffer.slice() returns a view, not a copy, so we need special handling
|
|
190
|
+
(bytes, start, end) => {
|
|
191
|
+
if (isBuffer(bytes)) {
|
|
192
|
+
return new Uint8Array(bytes.subarray(start, end));
|
|
193
|
+
}
|
|
194
|
+
return bytes.slice(start, end);
|
|
195
|
+
}
|
|
196
|
+
) : (
|
|
197
|
+
// eslint-disable-line operator-linebreak
|
|
198
|
+
/**
|
|
199
|
+
* @param {Uint8Array} bytes
|
|
200
|
+
* @param {number} start
|
|
201
|
+
* @param {number} end
|
|
202
|
+
*/
|
|
203
|
+
(bytes, start, end) => {
|
|
204
|
+
return bytes.slice(start, end);
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
var concat = useBuffer ? (
|
|
208
|
+
// eslint-disable-line operator-linebreak
|
|
209
|
+
/**
|
|
210
|
+
* @param {Uint8Array[]} chunks
|
|
211
|
+
* @param {number} length
|
|
212
|
+
* @returns {Uint8Array}
|
|
213
|
+
*/
|
|
214
|
+
(chunks, length2) => {
|
|
215
|
+
chunks = chunks.map((c) => c instanceof Uint8Array ? c : (
|
|
216
|
+
// eslint-disable-line operator-linebreak
|
|
217
|
+
// @ts-ignore
|
|
218
|
+
globalThis.Buffer.from(c)
|
|
219
|
+
));
|
|
220
|
+
return asU8A(globalThis.Buffer.concat(chunks, length2));
|
|
221
|
+
}
|
|
222
|
+
) : (
|
|
223
|
+
// eslint-disable-line operator-linebreak
|
|
224
|
+
/**
|
|
225
|
+
* @param {Uint8Array[]} chunks
|
|
226
|
+
* @param {number} length
|
|
227
|
+
* @returns {Uint8Array}
|
|
228
|
+
*/
|
|
229
|
+
(chunks, length2) => {
|
|
230
|
+
const out = new Uint8Array(length2);
|
|
231
|
+
let off = 0;
|
|
232
|
+
for (let b of chunks) {
|
|
233
|
+
if (off + b.length > out.length) {
|
|
234
|
+
b = b.subarray(0, out.length - off);
|
|
235
|
+
}
|
|
236
|
+
out.set(b, off);
|
|
237
|
+
off += b.length;
|
|
238
|
+
}
|
|
239
|
+
return out;
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
var alloc = useBuffer ? (
|
|
243
|
+
// eslint-disable-line operator-linebreak
|
|
244
|
+
/**
|
|
245
|
+
* @param {number} size
|
|
246
|
+
* @returns {Uint8Array}
|
|
247
|
+
*/
|
|
248
|
+
(size) => {
|
|
249
|
+
return globalThis.Buffer.allocUnsafe(size);
|
|
250
|
+
}
|
|
251
|
+
) : (
|
|
252
|
+
// eslint-disable-line operator-linebreak
|
|
253
|
+
/**
|
|
254
|
+
* @param {number} size
|
|
255
|
+
* @returns {Uint8Array}
|
|
256
|
+
*/
|
|
257
|
+
(size) => {
|
|
258
|
+
return new Uint8Array(size);
|
|
259
|
+
}
|
|
260
|
+
);
|
|
261
|
+
function compare(b1, b2) {
|
|
262
|
+
if (isBuffer(b1) && isBuffer(b2)) {
|
|
263
|
+
return b1.compare(b2);
|
|
264
|
+
}
|
|
265
|
+
for (let i = 0; i < b1.length; i++) {
|
|
266
|
+
if (b1[i] === b2[i]) {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
return b1[i] < b2[i] ? -1 : 1;
|
|
270
|
+
}
|
|
271
|
+
return 0;
|
|
272
|
+
}
|
|
273
|
+
function utf8ToBytes(str) {
|
|
274
|
+
const out = [];
|
|
275
|
+
let p = 0;
|
|
276
|
+
for (let i = 0; i < str.length; i++) {
|
|
277
|
+
let c = str.charCodeAt(i);
|
|
278
|
+
if (c < 128) {
|
|
279
|
+
out[p++] = c;
|
|
280
|
+
} else if (c < 2048) {
|
|
281
|
+
out[p++] = c >> 6 | 192;
|
|
282
|
+
out[p++] = c & 63 | 128;
|
|
283
|
+
} else if ((c & 64512) === 55296 && i + 1 < str.length && (str.charCodeAt(i + 1) & 64512) === 56320) {
|
|
284
|
+
c = 65536 + ((c & 1023) << 10) + (str.charCodeAt(++i) & 1023);
|
|
285
|
+
out[p++] = c >> 18 | 240;
|
|
286
|
+
out[p++] = c >> 12 & 63 | 128;
|
|
287
|
+
out[p++] = c >> 6 & 63 | 128;
|
|
288
|
+
out[p++] = c & 63 | 128;
|
|
289
|
+
} else {
|
|
290
|
+
if (c >= 55296 && c <= 57343) {
|
|
291
|
+
c = 65533;
|
|
292
|
+
}
|
|
293
|
+
out[p++] = c >> 12 | 224;
|
|
294
|
+
out[p++] = c >> 6 & 63 | 128;
|
|
295
|
+
out[p++] = c & 63 | 128;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return out;
|
|
299
|
+
}
|
|
300
|
+
var MAX_ARGUMENTS_LENGTH = 4096;
|
|
301
|
+
function decodeCodePointsArray(codePoints) {
|
|
302
|
+
const len = codePoints.length;
|
|
303
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
304
|
+
return String.fromCharCode.apply(String, codePoints);
|
|
305
|
+
}
|
|
306
|
+
let res = "";
|
|
307
|
+
let i = 0;
|
|
308
|
+
while (i < len) {
|
|
309
|
+
res += String.fromCharCode.apply(
|
|
310
|
+
String,
|
|
311
|
+
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
return res;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// ../../../node_modules/.pnpm/cborg@4.5.8/node_modules/cborg/lib/bl.js
|
|
318
|
+
var defaultChunkSize = 256;
|
|
319
|
+
var Bl = class {
|
|
320
|
+
/**
|
|
321
|
+
* @param {number} [chunkSize]
|
|
322
|
+
*/
|
|
323
|
+
constructor(chunkSize = defaultChunkSize) {
|
|
324
|
+
this.chunkSize = chunkSize;
|
|
325
|
+
this.cursor = 0;
|
|
326
|
+
this.maxCursor = -1;
|
|
327
|
+
this.chunks = [];
|
|
328
|
+
this._initReuseChunk = null;
|
|
329
|
+
}
|
|
330
|
+
reset() {
|
|
331
|
+
this.cursor = 0;
|
|
332
|
+
this.maxCursor = -1;
|
|
333
|
+
if (this.chunks.length) {
|
|
334
|
+
this.chunks = [];
|
|
335
|
+
}
|
|
336
|
+
if (this._initReuseChunk !== null) {
|
|
337
|
+
this.chunks.push(this._initReuseChunk);
|
|
338
|
+
this.maxCursor = this._initReuseChunk.length - 1;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* @param {Uint8Array|number[]} bytes
|
|
343
|
+
*/
|
|
344
|
+
push(bytes) {
|
|
345
|
+
let topChunk = this.chunks[this.chunks.length - 1];
|
|
346
|
+
const newMax = this.cursor + bytes.length;
|
|
347
|
+
if (newMax <= this.maxCursor + 1) {
|
|
348
|
+
const chunkPos = topChunk.length - (this.maxCursor - this.cursor) - 1;
|
|
349
|
+
topChunk.set(bytes, chunkPos);
|
|
350
|
+
} else {
|
|
351
|
+
if (topChunk) {
|
|
352
|
+
const chunkPos = topChunk.length - (this.maxCursor - this.cursor) - 1;
|
|
353
|
+
if (chunkPos < topChunk.length) {
|
|
354
|
+
this.chunks[this.chunks.length - 1] = topChunk.subarray(0, chunkPos);
|
|
355
|
+
this.maxCursor = this.cursor - 1;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if (bytes.length < 64 && bytes.length < this.chunkSize) {
|
|
359
|
+
topChunk = alloc(this.chunkSize);
|
|
360
|
+
this.chunks.push(topChunk);
|
|
361
|
+
this.maxCursor += topChunk.length;
|
|
362
|
+
if (this._initReuseChunk === null) {
|
|
363
|
+
this._initReuseChunk = topChunk;
|
|
364
|
+
}
|
|
365
|
+
topChunk.set(bytes, 0);
|
|
366
|
+
} else {
|
|
367
|
+
this.chunks.push(bytes);
|
|
368
|
+
this.maxCursor += bytes.length;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
this.cursor += bytes.length;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* @param {boolean} [reset]
|
|
375
|
+
* @returns {Uint8Array}
|
|
376
|
+
*/
|
|
377
|
+
toBytes(reset = false) {
|
|
378
|
+
let byts;
|
|
379
|
+
if (this.chunks.length === 1) {
|
|
380
|
+
const chunk = this.chunks[0];
|
|
381
|
+
if (reset && this.cursor > chunk.length / 2) {
|
|
382
|
+
byts = this.cursor === chunk.length ? chunk : chunk.subarray(0, this.cursor);
|
|
383
|
+
this._initReuseChunk = null;
|
|
384
|
+
this.chunks = [];
|
|
385
|
+
} else {
|
|
386
|
+
byts = slice(chunk, 0, this.cursor);
|
|
387
|
+
}
|
|
388
|
+
} else {
|
|
389
|
+
byts = concat(this.chunks, this.cursor);
|
|
390
|
+
}
|
|
391
|
+
if (reset) {
|
|
392
|
+
this.reset();
|
|
393
|
+
}
|
|
394
|
+
return byts;
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
var U8Bl = class {
|
|
398
|
+
/**
|
|
399
|
+
* @param {Uint8Array} dest
|
|
400
|
+
*/
|
|
401
|
+
constructor(dest) {
|
|
402
|
+
this.dest = dest;
|
|
403
|
+
this.cursor = 0;
|
|
404
|
+
this.chunks = [dest];
|
|
405
|
+
}
|
|
406
|
+
reset() {
|
|
407
|
+
this.cursor = 0;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* @param {Uint8Array|number[]} bytes
|
|
411
|
+
*/
|
|
412
|
+
push(bytes) {
|
|
413
|
+
if (this.cursor + bytes.length > this.dest.length) {
|
|
414
|
+
throw new Error("write out of bounds, destination buffer is too small");
|
|
415
|
+
}
|
|
416
|
+
this.dest.set(bytes, this.cursor);
|
|
417
|
+
this.cursor += bytes.length;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* @param {boolean} [reset]
|
|
421
|
+
* @returns {Uint8Array}
|
|
422
|
+
*/
|
|
423
|
+
toBytes(reset = false) {
|
|
424
|
+
const byts = this.dest.subarray(0, this.cursor);
|
|
425
|
+
if (reset) {
|
|
426
|
+
this.reset();
|
|
427
|
+
}
|
|
428
|
+
return byts;
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
// ../../../node_modules/.pnpm/cborg@4.5.8/node_modules/cborg/lib/common.js
|
|
433
|
+
var decodeErrPrefix = "CBOR decode error:";
|
|
434
|
+
var encodeErrPrefix = "CBOR encode error:";
|
|
435
|
+
var uintMinorPrefixBytes = [];
|
|
436
|
+
uintMinorPrefixBytes[23] = 1;
|
|
437
|
+
uintMinorPrefixBytes[24] = 2;
|
|
438
|
+
uintMinorPrefixBytes[25] = 3;
|
|
439
|
+
uintMinorPrefixBytes[26] = 5;
|
|
440
|
+
uintMinorPrefixBytes[27] = 9;
|
|
441
|
+
function assertEnoughData(data, pos, need) {
|
|
442
|
+
if (data.length - pos < need) {
|
|
443
|
+
throw new Error(`${decodeErrPrefix} not enough data for type`);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// ../../../node_modules/.pnpm/cborg@4.5.8/node_modules/cborg/lib/0uint.js
|
|
448
|
+
var uintBoundaries = [24, 256, 65536, 4294967296, BigInt("18446744073709551616")];
|
|
449
|
+
function readUint8(data, offset, options) {
|
|
450
|
+
assertEnoughData(data, offset, 1);
|
|
451
|
+
const value = data[offset];
|
|
452
|
+
if (options.strict === true && value < uintBoundaries[0]) {
|
|
453
|
+
throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`);
|
|
454
|
+
}
|
|
455
|
+
return value;
|
|
456
|
+
}
|
|
457
|
+
function readUint16(data, offset, options) {
|
|
458
|
+
assertEnoughData(data, offset, 2);
|
|
459
|
+
const value = data[offset] << 8 | data[offset + 1];
|
|
460
|
+
if (options.strict === true && value < uintBoundaries[1]) {
|
|
461
|
+
throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`);
|
|
462
|
+
}
|
|
463
|
+
return value;
|
|
464
|
+
}
|
|
465
|
+
function readUint32(data, offset, options) {
|
|
466
|
+
assertEnoughData(data, offset, 4);
|
|
467
|
+
const value = data[offset] * 16777216 + (data[offset + 1] << 16) + (data[offset + 2] << 8) + data[offset + 3];
|
|
468
|
+
if (options.strict === true && value < uintBoundaries[2]) {
|
|
469
|
+
throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`);
|
|
470
|
+
}
|
|
471
|
+
return value;
|
|
472
|
+
}
|
|
473
|
+
function readUint64(data, offset, options) {
|
|
474
|
+
assertEnoughData(data, offset, 8);
|
|
475
|
+
const hi = data[offset] * 16777216 + (data[offset + 1] << 16) + (data[offset + 2] << 8) + data[offset + 3];
|
|
476
|
+
const lo = data[offset + 4] * 16777216 + (data[offset + 5] << 16) + (data[offset + 6] << 8) + data[offset + 7];
|
|
477
|
+
const value = (BigInt(hi) << BigInt(32)) + BigInt(lo);
|
|
478
|
+
if (options.strict === true && value < uintBoundaries[3]) {
|
|
479
|
+
throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`);
|
|
480
|
+
}
|
|
481
|
+
if (value <= Number.MAX_SAFE_INTEGER) {
|
|
482
|
+
return Number(value);
|
|
483
|
+
}
|
|
484
|
+
if (options.allowBigInt === true) {
|
|
485
|
+
return value;
|
|
486
|
+
}
|
|
487
|
+
throw new Error(`${decodeErrPrefix} integers outside of the safe integer range are not supported`);
|
|
488
|
+
}
|
|
489
|
+
function decodeUint8(data, pos, _minor, options) {
|
|
490
|
+
return new Token(Type.uint, readUint8(data, pos + 1, options), 2);
|
|
491
|
+
}
|
|
492
|
+
function decodeUint16(data, pos, _minor, options) {
|
|
493
|
+
return new Token(Type.uint, readUint16(data, pos + 1, options), 3);
|
|
494
|
+
}
|
|
495
|
+
function decodeUint32(data, pos, _minor, options) {
|
|
496
|
+
return new Token(Type.uint, readUint32(data, pos + 1, options), 5);
|
|
497
|
+
}
|
|
498
|
+
function decodeUint64(data, pos, _minor, options) {
|
|
499
|
+
return new Token(Type.uint, readUint64(data, pos + 1, options), 9);
|
|
500
|
+
}
|
|
501
|
+
function encodeUint(writer, token) {
|
|
502
|
+
return encodeUintValue(writer, 0, token.value);
|
|
503
|
+
}
|
|
504
|
+
function encodeUintValue(writer, major, uint) {
|
|
505
|
+
if (uint < uintBoundaries[0]) {
|
|
506
|
+
const nuint = Number(uint);
|
|
507
|
+
writer.push([major | nuint]);
|
|
508
|
+
} else if (uint < uintBoundaries[1]) {
|
|
509
|
+
const nuint = Number(uint);
|
|
510
|
+
writer.push([major | 24, nuint]);
|
|
511
|
+
} else if (uint < uintBoundaries[2]) {
|
|
512
|
+
const nuint = Number(uint);
|
|
513
|
+
writer.push([major | 25, nuint >>> 8, nuint & 255]);
|
|
514
|
+
} else if (uint < uintBoundaries[3]) {
|
|
515
|
+
const nuint = Number(uint);
|
|
516
|
+
writer.push([major | 26, nuint >>> 24 & 255, nuint >>> 16 & 255, nuint >>> 8 & 255, nuint & 255]);
|
|
517
|
+
} else {
|
|
518
|
+
const buint = BigInt(uint);
|
|
519
|
+
if (buint < uintBoundaries[4]) {
|
|
520
|
+
const set = [major | 27, 0, 0, 0, 0, 0, 0, 0];
|
|
521
|
+
let lo = Number(buint & BigInt(4294967295));
|
|
522
|
+
let hi = Number(buint >> BigInt(32) & BigInt(4294967295));
|
|
523
|
+
set[8] = lo & 255;
|
|
524
|
+
lo = lo >> 8;
|
|
525
|
+
set[7] = lo & 255;
|
|
526
|
+
lo = lo >> 8;
|
|
527
|
+
set[6] = lo & 255;
|
|
528
|
+
lo = lo >> 8;
|
|
529
|
+
set[5] = lo & 255;
|
|
530
|
+
set[4] = hi & 255;
|
|
531
|
+
hi = hi >> 8;
|
|
532
|
+
set[3] = hi & 255;
|
|
533
|
+
hi = hi >> 8;
|
|
534
|
+
set[2] = hi & 255;
|
|
535
|
+
hi = hi >> 8;
|
|
536
|
+
set[1] = hi & 255;
|
|
537
|
+
writer.push(set);
|
|
538
|
+
} else {
|
|
539
|
+
throw new Error(`${decodeErrPrefix} encountered BigInt larger than allowable range`);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
encodeUint.encodedSize = function encodedSize(token) {
|
|
544
|
+
return encodeUintValue.encodedSize(token.value);
|
|
545
|
+
};
|
|
546
|
+
encodeUintValue.encodedSize = function encodedSize2(uint) {
|
|
547
|
+
if (uint < uintBoundaries[0]) {
|
|
548
|
+
return 1;
|
|
549
|
+
}
|
|
550
|
+
if (uint < uintBoundaries[1]) {
|
|
551
|
+
return 2;
|
|
552
|
+
}
|
|
553
|
+
if (uint < uintBoundaries[2]) {
|
|
554
|
+
return 3;
|
|
555
|
+
}
|
|
556
|
+
if (uint < uintBoundaries[3]) {
|
|
557
|
+
return 5;
|
|
558
|
+
}
|
|
559
|
+
return 9;
|
|
560
|
+
};
|
|
561
|
+
encodeUint.compareTokens = function compareTokens(tok1, tok2) {
|
|
562
|
+
return tok1.value < tok2.value ? -1 : tok1.value > tok2.value ? 1 : (
|
|
563
|
+
/* c8 ignore next */
|
|
564
|
+
0
|
|
565
|
+
);
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
// ../../../node_modules/.pnpm/cborg@4.5.8/node_modules/cborg/lib/1negint.js
|
|
569
|
+
function decodeNegint8(data, pos, _minor, options) {
|
|
570
|
+
return new Token(Type.negint, -1 - readUint8(data, pos + 1, options), 2);
|
|
571
|
+
}
|
|
572
|
+
function decodeNegint16(data, pos, _minor, options) {
|
|
573
|
+
return new Token(Type.negint, -1 - readUint16(data, pos + 1, options), 3);
|
|
574
|
+
}
|
|
575
|
+
function decodeNegint32(data, pos, _minor, options) {
|
|
576
|
+
return new Token(Type.negint, -1 - readUint32(data, pos + 1, options), 5);
|
|
577
|
+
}
|
|
578
|
+
var neg1b = BigInt(-1);
|
|
579
|
+
var pos1b = BigInt(1);
|
|
580
|
+
function decodeNegint64(data, pos, _minor, options) {
|
|
581
|
+
const int = readUint64(data, pos + 1, options);
|
|
582
|
+
if (typeof int !== "bigint") {
|
|
583
|
+
const value = -1 - int;
|
|
584
|
+
if (value >= Number.MIN_SAFE_INTEGER) {
|
|
585
|
+
return new Token(Type.negint, value, 9);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
if (options.allowBigInt !== true) {
|
|
589
|
+
throw new Error(`${decodeErrPrefix} integers outside of the safe integer range are not supported`);
|
|
590
|
+
}
|
|
591
|
+
return new Token(Type.negint, neg1b - BigInt(int), 9);
|
|
592
|
+
}
|
|
593
|
+
function encodeNegint(writer, token) {
|
|
594
|
+
const negint = token.value;
|
|
595
|
+
const unsigned = typeof negint === "bigint" ? negint * neg1b - pos1b : negint * -1 - 1;
|
|
596
|
+
encodeUintValue(writer, token.type.majorEncoded, unsigned);
|
|
597
|
+
}
|
|
598
|
+
encodeNegint.encodedSize = function encodedSize3(token) {
|
|
599
|
+
const negint = token.value;
|
|
600
|
+
const unsigned = typeof negint === "bigint" ? negint * neg1b - pos1b : negint * -1 - 1;
|
|
601
|
+
if (unsigned < uintBoundaries[0]) {
|
|
602
|
+
return 1;
|
|
603
|
+
}
|
|
604
|
+
if (unsigned < uintBoundaries[1]) {
|
|
605
|
+
return 2;
|
|
606
|
+
}
|
|
607
|
+
if (unsigned < uintBoundaries[2]) {
|
|
608
|
+
return 3;
|
|
609
|
+
}
|
|
610
|
+
if (unsigned < uintBoundaries[3]) {
|
|
611
|
+
return 5;
|
|
612
|
+
}
|
|
613
|
+
return 9;
|
|
614
|
+
};
|
|
615
|
+
encodeNegint.compareTokens = function compareTokens2(tok1, tok2) {
|
|
616
|
+
return tok1.value < tok2.value ? 1 : tok1.value > tok2.value ? -1 : (
|
|
617
|
+
/* c8 ignore next */
|
|
618
|
+
0
|
|
619
|
+
);
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
// ../../../node_modules/.pnpm/cborg@4.5.8/node_modules/cborg/lib/2bytes.js
|
|
623
|
+
function toToken(data, pos, prefix, length2) {
|
|
624
|
+
assertEnoughData(data, pos, prefix + length2);
|
|
625
|
+
const buf = data.slice(pos + prefix, pos + prefix + length2);
|
|
626
|
+
return new Token(Type.bytes, buf, prefix + length2);
|
|
627
|
+
}
|
|
628
|
+
function decodeBytesCompact(data, pos, minor, _options) {
|
|
629
|
+
return toToken(data, pos, 1, minor);
|
|
630
|
+
}
|
|
631
|
+
function decodeBytes8(data, pos, _minor, options) {
|
|
632
|
+
return toToken(data, pos, 2, readUint8(data, pos + 1, options));
|
|
633
|
+
}
|
|
634
|
+
function decodeBytes16(data, pos, _minor, options) {
|
|
635
|
+
return toToken(data, pos, 3, readUint16(data, pos + 1, options));
|
|
636
|
+
}
|
|
637
|
+
function decodeBytes32(data, pos, _minor, options) {
|
|
638
|
+
return toToken(data, pos, 5, readUint32(data, pos + 1, options));
|
|
639
|
+
}
|
|
640
|
+
function decodeBytes64(data, pos, _minor, options) {
|
|
641
|
+
const l = readUint64(data, pos + 1, options);
|
|
642
|
+
if (typeof l === "bigint") {
|
|
643
|
+
throw new Error(`${decodeErrPrefix} 64-bit integer bytes lengths not supported`);
|
|
644
|
+
}
|
|
645
|
+
return toToken(data, pos, 9, l);
|
|
646
|
+
}
|
|
647
|
+
function tokenBytes(token) {
|
|
648
|
+
if (token.encodedBytes === void 0) {
|
|
649
|
+
token.encodedBytes = Type.equals(token.type, Type.string) ? fromString(token.value) : token.value;
|
|
650
|
+
}
|
|
651
|
+
return token.encodedBytes;
|
|
652
|
+
}
|
|
653
|
+
function encodeBytes(writer, token) {
|
|
654
|
+
const bytes = tokenBytes(token);
|
|
655
|
+
encodeUintValue(writer, token.type.majorEncoded, bytes.length);
|
|
656
|
+
writer.push(bytes);
|
|
657
|
+
}
|
|
658
|
+
encodeBytes.encodedSize = function encodedSize4(token) {
|
|
659
|
+
const bytes = tokenBytes(token);
|
|
660
|
+
return encodeUintValue.encodedSize(bytes.length) + bytes.length;
|
|
661
|
+
};
|
|
662
|
+
encodeBytes.compareTokens = function compareTokens3(tok1, tok2) {
|
|
663
|
+
return compareBytes(tokenBytes(tok1), tokenBytes(tok2));
|
|
664
|
+
};
|
|
665
|
+
function compareBytes(b1, b2) {
|
|
666
|
+
return b1.length < b2.length ? -1 : b1.length > b2.length ? 1 : compare(b1, b2);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
// ../../../node_modules/.pnpm/cborg@4.5.8/node_modules/cborg/lib/3string.js
|
|
670
|
+
var textDecoder = new TextDecoder();
|
|
671
|
+
var ASCII_THRESHOLD = 32;
|
|
672
|
+
function toStr(bytes, start, end) {
|
|
673
|
+
const len = end - start;
|
|
674
|
+
if (len < ASCII_THRESHOLD) {
|
|
675
|
+
let str = "";
|
|
676
|
+
for (let i = start; i < end; i++) {
|
|
677
|
+
const c = bytes[i];
|
|
678
|
+
if (c & 128) {
|
|
679
|
+
return textDecoder.decode(bytes.subarray(start, end));
|
|
680
|
+
}
|
|
681
|
+
str += String.fromCharCode(c);
|
|
682
|
+
}
|
|
683
|
+
return str;
|
|
684
|
+
}
|
|
685
|
+
return textDecoder.decode(bytes.subarray(start, end));
|
|
686
|
+
}
|
|
687
|
+
function toToken2(data, pos, prefix, length2, options) {
|
|
688
|
+
const totLength = prefix + length2;
|
|
689
|
+
assertEnoughData(data, pos, totLength);
|
|
690
|
+
const tok = new Token(Type.string, toStr(data, pos + prefix, pos + totLength), totLength);
|
|
691
|
+
if (options.retainStringBytes === true) {
|
|
692
|
+
tok.byteValue = data.slice(pos + prefix, pos + totLength);
|
|
693
|
+
}
|
|
694
|
+
return tok;
|
|
695
|
+
}
|
|
696
|
+
function decodeStringCompact(data, pos, minor, options) {
|
|
697
|
+
return toToken2(data, pos, 1, minor, options);
|
|
698
|
+
}
|
|
699
|
+
function decodeString8(data, pos, _minor, options) {
|
|
700
|
+
return toToken2(data, pos, 2, readUint8(data, pos + 1, options), options);
|
|
701
|
+
}
|
|
702
|
+
function decodeString16(data, pos, _minor, options) {
|
|
703
|
+
return toToken2(data, pos, 3, readUint16(data, pos + 1, options), options);
|
|
704
|
+
}
|
|
705
|
+
function decodeString32(data, pos, _minor, options) {
|
|
706
|
+
return toToken2(data, pos, 5, readUint32(data, pos + 1, options), options);
|
|
707
|
+
}
|
|
708
|
+
function decodeString64(data, pos, _minor, options) {
|
|
709
|
+
const l = readUint64(data, pos + 1, options);
|
|
710
|
+
if (typeof l === "bigint") {
|
|
711
|
+
throw new Error(`${decodeErrPrefix} 64-bit integer string lengths not supported`);
|
|
712
|
+
}
|
|
713
|
+
return toToken2(data, pos, 9, l, options);
|
|
714
|
+
}
|
|
715
|
+
var encodeString = encodeBytes;
|
|
716
|
+
|
|
717
|
+
// ../../../node_modules/.pnpm/cborg@4.5.8/node_modules/cborg/lib/4array.js
|
|
718
|
+
function toToken3(_data, _pos, prefix, length2) {
|
|
719
|
+
return new Token(Type.array, length2, prefix);
|
|
720
|
+
}
|
|
721
|
+
function decodeArrayCompact(data, pos, minor, _options) {
|
|
722
|
+
return toToken3(data, pos, 1, minor);
|
|
723
|
+
}
|
|
724
|
+
function decodeArray8(data, pos, _minor, options) {
|
|
725
|
+
return toToken3(data, pos, 2, readUint8(data, pos + 1, options));
|
|
726
|
+
}
|
|
727
|
+
function decodeArray16(data, pos, _minor, options) {
|
|
728
|
+
return toToken3(data, pos, 3, readUint16(data, pos + 1, options));
|
|
729
|
+
}
|
|
730
|
+
function decodeArray32(data, pos, _minor, options) {
|
|
731
|
+
return toToken3(data, pos, 5, readUint32(data, pos + 1, options));
|
|
732
|
+
}
|
|
733
|
+
function decodeArray64(data, pos, _minor, options) {
|
|
734
|
+
const l = readUint64(data, pos + 1, options);
|
|
735
|
+
if (typeof l === "bigint") {
|
|
736
|
+
throw new Error(`${decodeErrPrefix} 64-bit integer array lengths not supported`);
|
|
737
|
+
}
|
|
738
|
+
return toToken3(data, pos, 9, l);
|
|
739
|
+
}
|
|
740
|
+
function decodeArrayIndefinite(data, pos, _minor, options) {
|
|
741
|
+
if (options.allowIndefinite === false) {
|
|
742
|
+
throw new Error(`${decodeErrPrefix} indefinite length items not allowed`);
|
|
743
|
+
}
|
|
744
|
+
return toToken3(data, pos, 1, Infinity);
|
|
745
|
+
}
|
|
746
|
+
function encodeArray(writer, token) {
|
|
747
|
+
encodeUintValue(writer, Type.array.majorEncoded, token.value);
|
|
748
|
+
}
|
|
749
|
+
encodeArray.compareTokens = encodeUint.compareTokens;
|
|
750
|
+
encodeArray.encodedSize = function encodedSize5(token) {
|
|
751
|
+
return encodeUintValue.encodedSize(token.value);
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
// ../../../node_modules/.pnpm/cborg@4.5.8/node_modules/cborg/lib/5map.js
|
|
755
|
+
function toToken4(_data, _pos, prefix, length2) {
|
|
756
|
+
return new Token(Type.map, length2, prefix);
|
|
757
|
+
}
|
|
758
|
+
function decodeMapCompact(data, pos, minor, _options) {
|
|
759
|
+
return toToken4(data, pos, 1, minor);
|
|
760
|
+
}
|
|
761
|
+
function decodeMap8(data, pos, _minor, options) {
|
|
762
|
+
return toToken4(data, pos, 2, readUint8(data, pos + 1, options));
|
|
763
|
+
}
|
|
764
|
+
function decodeMap16(data, pos, _minor, options) {
|
|
765
|
+
return toToken4(data, pos, 3, readUint16(data, pos + 1, options));
|
|
766
|
+
}
|
|
767
|
+
function decodeMap32(data, pos, _minor, options) {
|
|
768
|
+
return toToken4(data, pos, 5, readUint32(data, pos + 1, options));
|
|
769
|
+
}
|
|
770
|
+
function decodeMap64(data, pos, _minor, options) {
|
|
771
|
+
const l = readUint64(data, pos + 1, options);
|
|
772
|
+
if (typeof l === "bigint") {
|
|
773
|
+
throw new Error(`${decodeErrPrefix} 64-bit integer map lengths not supported`);
|
|
774
|
+
}
|
|
775
|
+
return toToken4(data, pos, 9, l);
|
|
776
|
+
}
|
|
777
|
+
function decodeMapIndefinite(data, pos, _minor, options) {
|
|
778
|
+
if (options.allowIndefinite === false) {
|
|
779
|
+
throw new Error(`${decodeErrPrefix} indefinite length items not allowed`);
|
|
780
|
+
}
|
|
781
|
+
return toToken4(data, pos, 1, Infinity);
|
|
782
|
+
}
|
|
783
|
+
function encodeMap(writer, token) {
|
|
784
|
+
encodeUintValue(writer, Type.map.majorEncoded, token.value);
|
|
785
|
+
}
|
|
786
|
+
encodeMap.compareTokens = encodeUint.compareTokens;
|
|
787
|
+
encodeMap.encodedSize = function encodedSize6(token) {
|
|
788
|
+
return encodeUintValue.encodedSize(token.value);
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
// ../../../node_modules/.pnpm/cborg@4.5.8/node_modules/cborg/lib/6tag.js
|
|
792
|
+
function decodeTagCompact(_data, _pos, minor, _options) {
|
|
793
|
+
return new Token(Type.tag, minor, 1);
|
|
794
|
+
}
|
|
795
|
+
function decodeTag8(data, pos, _minor, options) {
|
|
796
|
+
return new Token(Type.tag, readUint8(data, pos + 1, options), 2);
|
|
797
|
+
}
|
|
798
|
+
function decodeTag16(data, pos, _minor, options) {
|
|
799
|
+
return new Token(Type.tag, readUint16(data, pos + 1, options), 3);
|
|
800
|
+
}
|
|
801
|
+
function decodeTag32(data, pos, _minor, options) {
|
|
802
|
+
return new Token(Type.tag, readUint32(data, pos + 1, options), 5);
|
|
803
|
+
}
|
|
804
|
+
function decodeTag64(data, pos, _minor, options) {
|
|
805
|
+
return new Token(Type.tag, readUint64(data, pos + 1, options), 9);
|
|
806
|
+
}
|
|
807
|
+
function encodeTag(writer, token) {
|
|
808
|
+
encodeUintValue(writer, Type.tag.majorEncoded, token.value);
|
|
809
|
+
}
|
|
810
|
+
encodeTag.compareTokens = encodeUint.compareTokens;
|
|
811
|
+
encodeTag.encodedSize = function encodedSize7(token) {
|
|
812
|
+
return encodeUintValue.encodedSize(token.value);
|
|
813
|
+
};
|
|
814
|
+
|
|
815
|
+
// ../../../node_modules/.pnpm/cborg@4.5.8/node_modules/cborg/lib/7float.js
|
|
816
|
+
var MINOR_FALSE = 20;
|
|
817
|
+
var MINOR_TRUE = 21;
|
|
818
|
+
var MINOR_NULL = 22;
|
|
819
|
+
var MINOR_UNDEFINED = 23;
|
|
820
|
+
function decodeUndefined(_data, _pos, _minor, options) {
|
|
821
|
+
if (options.allowUndefined === false) {
|
|
822
|
+
throw new Error(`${decodeErrPrefix} undefined values are not supported`);
|
|
823
|
+
} else if (options.coerceUndefinedToNull === true) {
|
|
824
|
+
return new Token(Type.null, null, 1);
|
|
825
|
+
}
|
|
826
|
+
return new Token(Type.undefined, void 0, 1);
|
|
827
|
+
}
|
|
828
|
+
function decodeBreak(_data, _pos, _minor, options) {
|
|
829
|
+
if (options.allowIndefinite === false) {
|
|
830
|
+
throw new Error(`${decodeErrPrefix} indefinite length items not allowed`);
|
|
831
|
+
}
|
|
832
|
+
return new Token(Type.break, void 0, 1);
|
|
833
|
+
}
|
|
834
|
+
function createToken(value, bytes, options) {
|
|
835
|
+
if (options) {
|
|
836
|
+
if (options.allowNaN === false && Number.isNaN(value)) {
|
|
837
|
+
throw new Error(`${decodeErrPrefix} NaN values are not supported`);
|
|
838
|
+
}
|
|
839
|
+
if (options.allowInfinity === false && (value === Infinity || value === -Infinity)) {
|
|
840
|
+
throw new Error(`${decodeErrPrefix} Infinity values are not supported`);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
return new Token(Type.float, value, bytes);
|
|
844
|
+
}
|
|
845
|
+
function decodeFloat16(data, pos, _minor, options) {
|
|
846
|
+
return createToken(readFloat16(data, pos + 1), 3, options);
|
|
847
|
+
}
|
|
848
|
+
function decodeFloat32(data, pos, _minor, options) {
|
|
849
|
+
return createToken(readFloat32(data, pos + 1), 5, options);
|
|
850
|
+
}
|
|
851
|
+
function decodeFloat64(data, pos, _minor, options) {
|
|
852
|
+
return createToken(readFloat64(data, pos + 1), 9, options);
|
|
853
|
+
}
|
|
854
|
+
function encodeFloat(writer, token, options) {
|
|
855
|
+
const float = token.value;
|
|
856
|
+
if (float === false) {
|
|
857
|
+
writer.push([Type.float.majorEncoded | MINOR_FALSE]);
|
|
858
|
+
} else if (float === true) {
|
|
859
|
+
writer.push([Type.float.majorEncoded | MINOR_TRUE]);
|
|
860
|
+
} else if (float === null) {
|
|
861
|
+
writer.push([Type.float.majorEncoded | MINOR_NULL]);
|
|
862
|
+
} else if (float === void 0) {
|
|
863
|
+
writer.push([Type.float.majorEncoded | MINOR_UNDEFINED]);
|
|
864
|
+
} else {
|
|
865
|
+
let decoded;
|
|
866
|
+
let success = false;
|
|
867
|
+
if (!options || options.float64 !== true) {
|
|
868
|
+
encodeFloat16(float);
|
|
869
|
+
decoded = readFloat16(ui8a, 1);
|
|
870
|
+
if (float === decoded || Number.isNaN(float)) {
|
|
871
|
+
ui8a[0] = 249;
|
|
872
|
+
writer.push(ui8a.slice(0, 3));
|
|
873
|
+
success = true;
|
|
874
|
+
} else {
|
|
875
|
+
encodeFloat32(float);
|
|
876
|
+
decoded = readFloat32(ui8a, 1);
|
|
877
|
+
if (float === decoded) {
|
|
878
|
+
ui8a[0] = 250;
|
|
879
|
+
writer.push(ui8a.slice(0, 5));
|
|
880
|
+
success = true;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
if (!success) {
|
|
885
|
+
encodeFloat64(float);
|
|
886
|
+
decoded = readFloat64(ui8a, 1);
|
|
887
|
+
ui8a[0] = 251;
|
|
888
|
+
writer.push(ui8a.slice(0, 9));
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
encodeFloat.encodedSize = function encodedSize8(token, options) {
|
|
893
|
+
const float = token.value;
|
|
894
|
+
if (float === false || float === true || float === null || float === void 0) {
|
|
895
|
+
return 1;
|
|
896
|
+
}
|
|
897
|
+
if (!options || options.float64 !== true) {
|
|
898
|
+
encodeFloat16(float);
|
|
899
|
+
let decoded = readFloat16(ui8a, 1);
|
|
900
|
+
if (float === decoded || Number.isNaN(float)) {
|
|
901
|
+
return 3;
|
|
902
|
+
}
|
|
903
|
+
encodeFloat32(float);
|
|
904
|
+
decoded = readFloat32(ui8a, 1);
|
|
905
|
+
if (float === decoded) {
|
|
906
|
+
return 5;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
return 9;
|
|
910
|
+
};
|
|
911
|
+
var buffer = new ArrayBuffer(9);
|
|
912
|
+
var dataView = new DataView(buffer, 1);
|
|
913
|
+
var ui8a = new Uint8Array(buffer, 0);
|
|
914
|
+
function encodeFloat16(inp) {
|
|
915
|
+
if (inp === Infinity) {
|
|
916
|
+
dataView.setUint16(0, 31744, false);
|
|
917
|
+
} else if (inp === -Infinity) {
|
|
918
|
+
dataView.setUint16(0, 64512, false);
|
|
919
|
+
} else if (Number.isNaN(inp)) {
|
|
920
|
+
dataView.setUint16(0, 32256, false);
|
|
921
|
+
} else {
|
|
922
|
+
dataView.setFloat32(0, inp);
|
|
923
|
+
const valu32 = dataView.getUint32(0);
|
|
924
|
+
const exponent = (valu32 & 2139095040) >> 23;
|
|
925
|
+
const mantissa = valu32 & 8388607;
|
|
926
|
+
if (exponent === 255) {
|
|
927
|
+
dataView.setUint16(0, 31744, false);
|
|
928
|
+
} else if (exponent === 0) {
|
|
929
|
+
dataView.setUint16(0, (inp & 2147483648) >> 16 | mantissa >> 13, false);
|
|
930
|
+
} else {
|
|
931
|
+
const logicalExponent = exponent - 127;
|
|
932
|
+
if (logicalExponent < -24) {
|
|
933
|
+
dataView.setUint16(0, 0);
|
|
934
|
+
} else if (logicalExponent < -14) {
|
|
935
|
+
dataView.setUint16(0, (valu32 & 2147483648) >> 16 | /* sign bit */
|
|
936
|
+
1 << 24 + logicalExponent, false);
|
|
937
|
+
} else {
|
|
938
|
+
dataView.setUint16(0, (valu32 & 2147483648) >> 16 | logicalExponent + 15 << 10 | mantissa >> 13, false);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
function readFloat16(ui8a2, pos) {
|
|
944
|
+
if (ui8a2.length - pos < 2) {
|
|
945
|
+
throw new Error(`${decodeErrPrefix} not enough data for float16`);
|
|
946
|
+
}
|
|
947
|
+
const half = (ui8a2[pos] << 8) + ui8a2[pos + 1];
|
|
948
|
+
if (half === 31744) {
|
|
949
|
+
return Infinity;
|
|
950
|
+
}
|
|
951
|
+
if (half === 64512) {
|
|
952
|
+
return -Infinity;
|
|
953
|
+
}
|
|
954
|
+
if (half === 32256) {
|
|
955
|
+
return NaN;
|
|
956
|
+
}
|
|
957
|
+
const exp = half >> 10 & 31;
|
|
958
|
+
const mant = half & 1023;
|
|
959
|
+
let val;
|
|
960
|
+
if (exp === 0) {
|
|
961
|
+
val = mant * 2 ** -24;
|
|
962
|
+
} else if (exp !== 31) {
|
|
963
|
+
val = (mant + 1024) * 2 ** (exp - 25);
|
|
964
|
+
} else {
|
|
965
|
+
val = mant === 0 ? Infinity : NaN;
|
|
966
|
+
}
|
|
967
|
+
return half & 32768 ? -val : val;
|
|
968
|
+
}
|
|
969
|
+
function encodeFloat32(inp) {
|
|
970
|
+
dataView.setFloat32(0, inp, false);
|
|
971
|
+
}
|
|
972
|
+
function readFloat32(ui8a2, pos) {
|
|
973
|
+
if (ui8a2.length - pos < 4) {
|
|
974
|
+
throw new Error(`${decodeErrPrefix} not enough data for float32`);
|
|
975
|
+
}
|
|
976
|
+
const offset = (ui8a2.byteOffset || 0) + pos;
|
|
977
|
+
return new DataView(ui8a2.buffer, offset, 4).getFloat32(0, false);
|
|
978
|
+
}
|
|
979
|
+
function encodeFloat64(inp) {
|
|
980
|
+
dataView.setFloat64(0, inp, false);
|
|
981
|
+
}
|
|
982
|
+
function readFloat64(ui8a2, pos) {
|
|
983
|
+
if (ui8a2.length - pos < 8) {
|
|
984
|
+
throw new Error(`${decodeErrPrefix} not enough data for float64`);
|
|
985
|
+
}
|
|
986
|
+
const offset = (ui8a2.byteOffset || 0) + pos;
|
|
987
|
+
return new DataView(ui8a2.buffer, offset, 8).getFloat64(0, false);
|
|
988
|
+
}
|
|
989
|
+
encodeFloat.compareTokens = encodeUint.compareTokens;
|
|
990
|
+
|
|
991
|
+
// ../../../node_modules/.pnpm/cborg@4.5.8/node_modules/cborg/lib/jump.js
|
|
992
|
+
function invalidMinor(data, pos, minor) {
|
|
993
|
+
throw new Error(`${decodeErrPrefix} encountered invalid minor (${minor}) for major ${data[pos] >>> 5}`);
|
|
994
|
+
}
|
|
995
|
+
function errorer(msg) {
|
|
996
|
+
return () => {
|
|
997
|
+
throw new Error(`${decodeErrPrefix} ${msg}`);
|
|
998
|
+
};
|
|
999
|
+
}
|
|
1000
|
+
var jump = [];
|
|
1001
|
+
for (let i = 0; i <= 23; i++) {
|
|
1002
|
+
jump[i] = invalidMinor;
|
|
1003
|
+
}
|
|
1004
|
+
jump[24] = decodeUint8;
|
|
1005
|
+
jump[25] = decodeUint16;
|
|
1006
|
+
jump[26] = decodeUint32;
|
|
1007
|
+
jump[27] = decodeUint64;
|
|
1008
|
+
jump[28] = invalidMinor;
|
|
1009
|
+
jump[29] = invalidMinor;
|
|
1010
|
+
jump[30] = invalidMinor;
|
|
1011
|
+
jump[31] = invalidMinor;
|
|
1012
|
+
for (let i = 32; i <= 55; i++) {
|
|
1013
|
+
jump[i] = invalidMinor;
|
|
1014
|
+
}
|
|
1015
|
+
jump[56] = decodeNegint8;
|
|
1016
|
+
jump[57] = decodeNegint16;
|
|
1017
|
+
jump[58] = decodeNegint32;
|
|
1018
|
+
jump[59] = decodeNegint64;
|
|
1019
|
+
jump[60] = invalidMinor;
|
|
1020
|
+
jump[61] = invalidMinor;
|
|
1021
|
+
jump[62] = invalidMinor;
|
|
1022
|
+
jump[63] = invalidMinor;
|
|
1023
|
+
for (let i = 64; i <= 87; i++) {
|
|
1024
|
+
jump[i] = decodeBytesCompact;
|
|
1025
|
+
}
|
|
1026
|
+
jump[88] = decodeBytes8;
|
|
1027
|
+
jump[89] = decodeBytes16;
|
|
1028
|
+
jump[90] = decodeBytes32;
|
|
1029
|
+
jump[91] = decodeBytes64;
|
|
1030
|
+
jump[92] = invalidMinor;
|
|
1031
|
+
jump[93] = invalidMinor;
|
|
1032
|
+
jump[94] = invalidMinor;
|
|
1033
|
+
jump[95] = errorer("indefinite length bytes/strings are not supported");
|
|
1034
|
+
for (let i = 96; i <= 119; i++) {
|
|
1035
|
+
jump[i] = decodeStringCompact;
|
|
1036
|
+
}
|
|
1037
|
+
jump[120] = decodeString8;
|
|
1038
|
+
jump[121] = decodeString16;
|
|
1039
|
+
jump[122] = decodeString32;
|
|
1040
|
+
jump[123] = decodeString64;
|
|
1041
|
+
jump[124] = invalidMinor;
|
|
1042
|
+
jump[125] = invalidMinor;
|
|
1043
|
+
jump[126] = invalidMinor;
|
|
1044
|
+
jump[127] = errorer("indefinite length bytes/strings are not supported");
|
|
1045
|
+
for (let i = 128; i <= 151; i++) {
|
|
1046
|
+
jump[i] = decodeArrayCompact;
|
|
1047
|
+
}
|
|
1048
|
+
jump[152] = decodeArray8;
|
|
1049
|
+
jump[153] = decodeArray16;
|
|
1050
|
+
jump[154] = decodeArray32;
|
|
1051
|
+
jump[155] = decodeArray64;
|
|
1052
|
+
jump[156] = invalidMinor;
|
|
1053
|
+
jump[157] = invalidMinor;
|
|
1054
|
+
jump[158] = invalidMinor;
|
|
1055
|
+
jump[159] = decodeArrayIndefinite;
|
|
1056
|
+
for (let i = 160; i <= 183; i++) {
|
|
1057
|
+
jump[i] = decodeMapCompact;
|
|
1058
|
+
}
|
|
1059
|
+
jump[184] = decodeMap8;
|
|
1060
|
+
jump[185] = decodeMap16;
|
|
1061
|
+
jump[186] = decodeMap32;
|
|
1062
|
+
jump[187] = decodeMap64;
|
|
1063
|
+
jump[188] = invalidMinor;
|
|
1064
|
+
jump[189] = invalidMinor;
|
|
1065
|
+
jump[190] = invalidMinor;
|
|
1066
|
+
jump[191] = decodeMapIndefinite;
|
|
1067
|
+
for (let i = 192; i <= 215; i++) {
|
|
1068
|
+
jump[i] = decodeTagCompact;
|
|
1069
|
+
}
|
|
1070
|
+
jump[216] = decodeTag8;
|
|
1071
|
+
jump[217] = decodeTag16;
|
|
1072
|
+
jump[218] = decodeTag32;
|
|
1073
|
+
jump[219] = decodeTag64;
|
|
1074
|
+
jump[220] = invalidMinor;
|
|
1075
|
+
jump[221] = invalidMinor;
|
|
1076
|
+
jump[222] = invalidMinor;
|
|
1077
|
+
jump[223] = invalidMinor;
|
|
1078
|
+
for (let i = 224; i <= 243; i++) {
|
|
1079
|
+
jump[i] = errorer("simple values are not supported");
|
|
1080
|
+
}
|
|
1081
|
+
jump[244] = invalidMinor;
|
|
1082
|
+
jump[245] = invalidMinor;
|
|
1083
|
+
jump[246] = invalidMinor;
|
|
1084
|
+
jump[247] = decodeUndefined;
|
|
1085
|
+
jump[248] = errorer("simple values are not supported");
|
|
1086
|
+
jump[249] = decodeFloat16;
|
|
1087
|
+
jump[250] = decodeFloat32;
|
|
1088
|
+
jump[251] = decodeFloat64;
|
|
1089
|
+
jump[252] = invalidMinor;
|
|
1090
|
+
jump[253] = invalidMinor;
|
|
1091
|
+
jump[254] = invalidMinor;
|
|
1092
|
+
jump[255] = decodeBreak;
|
|
1093
|
+
var quick = [];
|
|
1094
|
+
for (let i = 0; i < 24; i++) {
|
|
1095
|
+
quick[i] = new Token(Type.uint, i, 1);
|
|
1096
|
+
}
|
|
1097
|
+
for (let i = -1; i >= -24; i--) {
|
|
1098
|
+
quick[31 - i] = new Token(Type.negint, i, 1);
|
|
1099
|
+
}
|
|
1100
|
+
quick[64] = new Token(Type.bytes, new Uint8Array(0), 1);
|
|
1101
|
+
quick[96] = new Token(Type.string, "", 1);
|
|
1102
|
+
quick[128] = new Token(Type.array, 0, 1);
|
|
1103
|
+
quick[160] = new Token(Type.map, 0, 1);
|
|
1104
|
+
quick[244] = new Token(Type.false, false, 1);
|
|
1105
|
+
quick[245] = new Token(Type.true, true, 1);
|
|
1106
|
+
quick[246] = new Token(Type.null, null, 1);
|
|
1107
|
+
function quickEncodeToken(token) {
|
|
1108
|
+
switch (token.type) {
|
|
1109
|
+
case Type.false:
|
|
1110
|
+
return fromArray([244]);
|
|
1111
|
+
case Type.true:
|
|
1112
|
+
return fromArray([245]);
|
|
1113
|
+
case Type.null:
|
|
1114
|
+
return fromArray([246]);
|
|
1115
|
+
case Type.bytes:
|
|
1116
|
+
if (!token.value.length) {
|
|
1117
|
+
return fromArray([64]);
|
|
1118
|
+
}
|
|
1119
|
+
return;
|
|
1120
|
+
case Type.string:
|
|
1121
|
+
if (token.value === "") {
|
|
1122
|
+
return fromArray([96]);
|
|
1123
|
+
}
|
|
1124
|
+
return;
|
|
1125
|
+
case Type.array:
|
|
1126
|
+
if (token.value === 0) {
|
|
1127
|
+
return fromArray([128]);
|
|
1128
|
+
}
|
|
1129
|
+
return;
|
|
1130
|
+
case Type.map:
|
|
1131
|
+
if (token.value === 0) {
|
|
1132
|
+
return fromArray([160]);
|
|
1133
|
+
}
|
|
1134
|
+
return;
|
|
1135
|
+
case Type.uint:
|
|
1136
|
+
if (token.value < 24) {
|
|
1137
|
+
return fromArray([Number(token.value)]);
|
|
1138
|
+
}
|
|
1139
|
+
return;
|
|
1140
|
+
case Type.negint:
|
|
1141
|
+
if (token.value >= -24) {
|
|
1142
|
+
return fromArray([31 - Number(token.value)]);
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
// ../../../node_modules/.pnpm/cborg@4.5.8/node_modules/cborg/lib/encode.js
|
|
1148
|
+
var defaultEncodeOptions = {
|
|
1149
|
+
float64: false,
|
|
1150
|
+
mapSorter,
|
|
1151
|
+
quickEncodeToken
|
|
1152
|
+
};
|
|
1153
|
+
var rfc8949EncodeOptions = Object.freeze({
|
|
1154
|
+
float64: true,
|
|
1155
|
+
mapSorter: rfc8949MapSorter,
|
|
1156
|
+
quickEncodeToken
|
|
1157
|
+
});
|
|
1158
|
+
function makeCborEncoders() {
|
|
1159
|
+
const encoders = [];
|
|
1160
|
+
encoders[Type.uint.major] = encodeUint;
|
|
1161
|
+
encoders[Type.negint.major] = encodeNegint;
|
|
1162
|
+
encoders[Type.bytes.major] = encodeBytes;
|
|
1163
|
+
encoders[Type.string.major] = encodeString;
|
|
1164
|
+
encoders[Type.array.major] = encodeArray;
|
|
1165
|
+
encoders[Type.map.major] = encodeMap;
|
|
1166
|
+
encoders[Type.tag.major] = encodeTag;
|
|
1167
|
+
encoders[Type.float.major] = encodeFloat;
|
|
1168
|
+
return encoders;
|
|
1169
|
+
}
|
|
1170
|
+
var cborEncoders = makeCborEncoders();
|
|
1171
|
+
var defaultWriter = new Bl();
|
|
1172
|
+
var Ref = class _Ref {
|
|
1173
|
+
/**
|
|
1174
|
+
* @param {object|any[]} obj
|
|
1175
|
+
* @param {Reference|undefined} parent
|
|
1176
|
+
*/
|
|
1177
|
+
constructor(obj, parent) {
|
|
1178
|
+
this.obj = obj;
|
|
1179
|
+
this.parent = parent;
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* @param {object|any[]} obj
|
|
1183
|
+
* @returns {boolean}
|
|
1184
|
+
*/
|
|
1185
|
+
includes(obj) {
|
|
1186
|
+
let p = this;
|
|
1187
|
+
do {
|
|
1188
|
+
if (p.obj === obj) {
|
|
1189
|
+
return true;
|
|
1190
|
+
}
|
|
1191
|
+
} while (p = p.parent);
|
|
1192
|
+
return false;
|
|
1193
|
+
}
|
|
1194
|
+
/**
|
|
1195
|
+
* @param {Reference|undefined} stack
|
|
1196
|
+
* @param {object|any[]} obj
|
|
1197
|
+
* @returns {Reference}
|
|
1198
|
+
*/
|
|
1199
|
+
static createCheck(stack, obj) {
|
|
1200
|
+
if (stack && stack.includes(obj)) {
|
|
1201
|
+
throw new Error(`${encodeErrPrefix} object contains circular references`);
|
|
1202
|
+
}
|
|
1203
|
+
return new _Ref(obj, stack);
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
var simpleTokens = {
|
|
1207
|
+
null: new Token(Type.null, null),
|
|
1208
|
+
undefined: new Token(Type.undefined, void 0),
|
|
1209
|
+
true: new Token(Type.true, true),
|
|
1210
|
+
false: new Token(Type.false, false),
|
|
1211
|
+
emptyArray: new Token(Type.array, 0),
|
|
1212
|
+
emptyMap: new Token(Type.map, 0)
|
|
1213
|
+
};
|
|
1214
|
+
var typeEncoders = {
|
|
1215
|
+
/**
|
|
1216
|
+
* @param {any} obj
|
|
1217
|
+
* @param {string} _typ
|
|
1218
|
+
* @param {EncodeOptions} _options
|
|
1219
|
+
* @param {Reference} [_refStack]
|
|
1220
|
+
* @returns {TokenOrNestedTokens}
|
|
1221
|
+
*/
|
|
1222
|
+
number(obj, _typ, _options, _refStack) {
|
|
1223
|
+
if (!Number.isInteger(obj) || !Number.isSafeInteger(obj)) {
|
|
1224
|
+
return new Token(Type.float, obj);
|
|
1225
|
+
} else if (obj >= 0) {
|
|
1226
|
+
return new Token(Type.uint, obj);
|
|
1227
|
+
} else {
|
|
1228
|
+
return new Token(Type.negint, obj);
|
|
1229
|
+
}
|
|
1230
|
+
},
|
|
1231
|
+
/**
|
|
1232
|
+
* @param {any} obj
|
|
1233
|
+
* @param {string} _typ
|
|
1234
|
+
* @param {EncodeOptions} _options
|
|
1235
|
+
* @param {Reference} [_refStack]
|
|
1236
|
+
* @returns {TokenOrNestedTokens}
|
|
1237
|
+
*/
|
|
1238
|
+
bigint(obj, _typ, _options, _refStack) {
|
|
1239
|
+
if (obj >= BigInt(0)) {
|
|
1240
|
+
return new Token(Type.uint, obj);
|
|
1241
|
+
} else {
|
|
1242
|
+
return new Token(Type.negint, obj);
|
|
1243
|
+
}
|
|
1244
|
+
},
|
|
1245
|
+
/**
|
|
1246
|
+
* @param {any} obj
|
|
1247
|
+
* @param {string} _typ
|
|
1248
|
+
* @param {EncodeOptions} _options
|
|
1249
|
+
* @param {Reference} [_refStack]
|
|
1250
|
+
* @returns {TokenOrNestedTokens}
|
|
1251
|
+
*/
|
|
1252
|
+
Uint8Array(obj, _typ, _options, _refStack) {
|
|
1253
|
+
return new Token(Type.bytes, obj);
|
|
1254
|
+
},
|
|
1255
|
+
/**
|
|
1256
|
+
* @param {any} obj
|
|
1257
|
+
* @param {string} _typ
|
|
1258
|
+
* @param {EncodeOptions} _options
|
|
1259
|
+
* @param {Reference} [_refStack]
|
|
1260
|
+
* @returns {TokenOrNestedTokens}
|
|
1261
|
+
*/
|
|
1262
|
+
string(obj, _typ, _options, _refStack) {
|
|
1263
|
+
return new Token(Type.string, obj);
|
|
1264
|
+
},
|
|
1265
|
+
/**
|
|
1266
|
+
* @param {any} obj
|
|
1267
|
+
* @param {string} _typ
|
|
1268
|
+
* @param {EncodeOptions} _options
|
|
1269
|
+
* @param {Reference} [_refStack]
|
|
1270
|
+
* @returns {TokenOrNestedTokens}
|
|
1271
|
+
*/
|
|
1272
|
+
boolean(obj, _typ, _options, _refStack) {
|
|
1273
|
+
return obj ? simpleTokens.true : simpleTokens.false;
|
|
1274
|
+
},
|
|
1275
|
+
/**
|
|
1276
|
+
* @param {any} _obj
|
|
1277
|
+
* @param {string} _typ
|
|
1278
|
+
* @param {EncodeOptions} _options
|
|
1279
|
+
* @param {Reference} [_refStack]
|
|
1280
|
+
* @returns {TokenOrNestedTokens}
|
|
1281
|
+
*/
|
|
1282
|
+
null(_obj, _typ, _options, _refStack) {
|
|
1283
|
+
return simpleTokens.null;
|
|
1284
|
+
},
|
|
1285
|
+
/**
|
|
1286
|
+
* @param {any} _obj
|
|
1287
|
+
* @param {string} _typ
|
|
1288
|
+
* @param {EncodeOptions} _options
|
|
1289
|
+
* @param {Reference} [_refStack]
|
|
1290
|
+
* @returns {TokenOrNestedTokens}
|
|
1291
|
+
*/
|
|
1292
|
+
undefined(_obj, _typ, _options, _refStack) {
|
|
1293
|
+
return simpleTokens.undefined;
|
|
1294
|
+
},
|
|
1295
|
+
/**
|
|
1296
|
+
* @param {any} obj
|
|
1297
|
+
* @param {string} _typ
|
|
1298
|
+
* @param {EncodeOptions} _options
|
|
1299
|
+
* @param {Reference} [_refStack]
|
|
1300
|
+
* @returns {TokenOrNestedTokens}
|
|
1301
|
+
*/
|
|
1302
|
+
ArrayBuffer(obj, _typ, _options, _refStack) {
|
|
1303
|
+
return new Token(Type.bytes, new Uint8Array(obj));
|
|
1304
|
+
},
|
|
1305
|
+
/**
|
|
1306
|
+
* @param {any} obj
|
|
1307
|
+
* @param {string} _typ
|
|
1308
|
+
* @param {EncodeOptions} _options
|
|
1309
|
+
* @param {Reference} [_refStack]
|
|
1310
|
+
* @returns {TokenOrNestedTokens}
|
|
1311
|
+
*/
|
|
1312
|
+
DataView(obj, _typ, _options, _refStack) {
|
|
1313
|
+
return new Token(Type.bytes, new Uint8Array(obj.buffer, obj.byteOffset, obj.byteLength));
|
|
1314
|
+
},
|
|
1315
|
+
/**
|
|
1316
|
+
* @param {any} obj
|
|
1317
|
+
* @param {string} _typ
|
|
1318
|
+
* @param {EncodeOptions} options
|
|
1319
|
+
* @param {Reference} [refStack]
|
|
1320
|
+
* @returns {TokenOrNestedTokens}
|
|
1321
|
+
*/
|
|
1322
|
+
Array(obj, _typ, options, refStack) {
|
|
1323
|
+
if (!obj.length) {
|
|
1324
|
+
if (options.addBreakTokens === true) {
|
|
1325
|
+
return [simpleTokens.emptyArray, new Token(Type.break)];
|
|
1326
|
+
}
|
|
1327
|
+
return simpleTokens.emptyArray;
|
|
1328
|
+
}
|
|
1329
|
+
refStack = Ref.createCheck(refStack, obj);
|
|
1330
|
+
const entries = [];
|
|
1331
|
+
let i = 0;
|
|
1332
|
+
for (const e of obj) {
|
|
1333
|
+
entries[i++] = objectToTokens(e, options, refStack);
|
|
1334
|
+
}
|
|
1335
|
+
if (options.addBreakTokens) {
|
|
1336
|
+
return [new Token(Type.array, obj.length), entries, new Token(Type.break)];
|
|
1337
|
+
}
|
|
1338
|
+
return [new Token(Type.array, obj.length), entries];
|
|
1339
|
+
},
|
|
1340
|
+
/**
|
|
1341
|
+
* @param {any} obj
|
|
1342
|
+
* @param {string} typ
|
|
1343
|
+
* @param {EncodeOptions} options
|
|
1344
|
+
* @param {Reference} [refStack]
|
|
1345
|
+
* @returns {TokenOrNestedTokens}
|
|
1346
|
+
*/
|
|
1347
|
+
Object(obj, typ, options, refStack) {
|
|
1348
|
+
const isMap = typ !== "Object";
|
|
1349
|
+
const keys = isMap ? obj.keys() : Object.keys(obj);
|
|
1350
|
+
const maxLength = isMap ? obj.size : keys.length;
|
|
1351
|
+
let entries;
|
|
1352
|
+
if (maxLength) {
|
|
1353
|
+
entries = new Array(maxLength);
|
|
1354
|
+
refStack = Ref.createCheck(refStack, obj);
|
|
1355
|
+
const skipUndefined = !isMap && options.ignoreUndefinedProperties;
|
|
1356
|
+
let i = 0;
|
|
1357
|
+
for (const key of keys) {
|
|
1358
|
+
const value = isMap ? obj.get(key) : obj[key];
|
|
1359
|
+
if (skipUndefined && value === void 0) {
|
|
1360
|
+
continue;
|
|
1361
|
+
}
|
|
1362
|
+
entries[i++] = [
|
|
1363
|
+
objectToTokens(key, options, refStack),
|
|
1364
|
+
objectToTokens(value, options, refStack)
|
|
1365
|
+
];
|
|
1366
|
+
}
|
|
1367
|
+
if (i < maxLength) {
|
|
1368
|
+
entries.length = i;
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
if (!entries?.length) {
|
|
1372
|
+
if (options.addBreakTokens === true) {
|
|
1373
|
+
return [simpleTokens.emptyMap, new Token(Type.break)];
|
|
1374
|
+
}
|
|
1375
|
+
return simpleTokens.emptyMap;
|
|
1376
|
+
}
|
|
1377
|
+
sortMapEntries(entries, options);
|
|
1378
|
+
if (options.addBreakTokens) {
|
|
1379
|
+
return [new Token(Type.map, entries.length), entries, new Token(Type.break)];
|
|
1380
|
+
}
|
|
1381
|
+
return [new Token(Type.map, entries.length), entries];
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1384
|
+
typeEncoders.Map = typeEncoders.Object;
|
|
1385
|
+
typeEncoders.Buffer = typeEncoders.Uint8Array;
|
|
1386
|
+
for (const typ of "Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" ")) {
|
|
1387
|
+
typeEncoders[`${typ}Array`] = typeEncoders.DataView;
|
|
1388
|
+
}
|
|
1389
|
+
function objectToTokens(obj, options = {}, refStack) {
|
|
1390
|
+
const typ = is(obj);
|
|
1391
|
+
const customTypeEncoder = options && options.typeEncoders && /** @type {OptionalTypeEncoder} */
|
|
1392
|
+
options.typeEncoders[typ] || typeEncoders[typ];
|
|
1393
|
+
if (typeof customTypeEncoder === "function") {
|
|
1394
|
+
const tokens = customTypeEncoder(obj, typ, options, refStack);
|
|
1395
|
+
if (tokens != null) {
|
|
1396
|
+
return tokens;
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
const typeEncoder = typeEncoders[typ];
|
|
1400
|
+
if (!typeEncoder) {
|
|
1401
|
+
throw new Error(`${encodeErrPrefix} unsupported type: ${typ}`);
|
|
1402
|
+
}
|
|
1403
|
+
return typeEncoder(obj, typ, options, refStack);
|
|
1404
|
+
}
|
|
1405
|
+
function sortMapEntries(entries, options) {
|
|
1406
|
+
if (options.mapSorter) {
|
|
1407
|
+
entries.sort(options.mapSorter);
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
function mapSorter(e1, e2) {
|
|
1411
|
+
const keyToken1 = Array.isArray(e1[0]) ? e1[0][0] : e1[0];
|
|
1412
|
+
const keyToken2 = Array.isArray(e2[0]) ? e2[0][0] : e2[0];
|
|
1413
|
+
if (keyToken1.type !== keyToken2.type) {
|
|
1414
|
+
return keyToken1.type.compare(keyToken2.type);
|
|
1415
|
+
}
|
|
1416
|
+
const major = keyToken1.type.major;
|
|
1417
|
+
const tcmp = cborEncoders[major].compareTokens(keyToken1, keyToken2);
|
|
1418
|
+
if (tcmp === 0) {
|
|
1419
|
+
console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone");
|
|
1420
|
+
}
|
|
1421
|
+
return tcmp;
|
|
1422
|
+
}
|
|
1423
|
+
function rfc8949MapSorter(e1, e2) {
|
|
1424
|
+
if (e1[0] instanceof Token && e2[0] instanceof Token) {
|
|
1425
|
+
const t1 = (
|
|
1426
|
+
/** @type {TokenEx} */
|
|
1427
|
+
e1[0]
|
|
1428
|
+
);
|
|
1429
|
+
const t2 = (
|
|
1430
|
+
/** @type {TokenEx} */
|
|
1431
|
+
e2[0]
|
|
1432
|
+
);
|
|
1433
|
+
if (!t1._keyBytes) {
|
|
1434
|
+
t1._keyBytes = encodeRfc8949(t1.value);
|
|
1435
|
+
}
|
|
1436
|
+
if (!t2._keyBytes) {
|
|
1437
|
+
t2._keyBytes = encodeRfc8949(t2.value);
|
|
1438
|
+
}
|
|
1439
|
+
return compare(t1._keyBytes, t2._keyBytes);
|
|
1440
|
+
}
|
|
1441
|
+
throw new Error("rfc8949MapSorter: complex key types are not supported yet");
|
|
1442
|
+
}
|
|
1443
|
+
function encodeRfc8949(data) {
|
|
1444
|
+
return encodeCustom(data, cborEncoders, rfc8949EncodeOptions);
|
|
1445
|
+
}
|
|
1446
|
+
function tokensToEncoded(writer, tokens, encoders, options) {
|
|
1447
|
+
if (Array.isArray(tokens)) {
|
|
1448
|
+
for (const token of tokens) {
|
|
1449
|
+
tokensToEncoded(writer, token, encoders, options);
|
|
1450
|
+
}
|
|
1451
|
+
} else {
|
|
1452
|
+
encoders[tokens.type.major](writer, tokens, options);
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
var MAJOR_UINT = Type.uint.majorEncoded;
|
|
1456
|
+
var MAJOR_NEGINT = Type.negint.majorEncoded;
|
|
1457
|
+
var MAJOR_BYTES = Type.bytes.majorEncoded;
|
|
1458
|
+
var MAJOR_STRING = Type.string.majorEncoded;
|
|
1459
|
+
var MAJOR_ARRAY = Type.array.majorEncoded;
|
|
1460
|
+
var SIMPLE_FALSE = Type.float.majorEncoded | MINOR_FALSE;
|
|
1461
|
+
var SIMPLE_TRUE = Type.float.majorEncoded | MINOR_TRUE;
|
|
1462
|
+
var SIMPLE_NULL = Type.float.majorEncoded | MINOR_NULL;
|
|
1463
|
+
var SIMPLE_UNDEFINED = Type.float.majorEncoded | MINOR_UNDEFINED;
|
|
1464
|
+
var neg1b2 = BigInt(-1);
|
|
1465
|
+
var pos1b2 = BigInt(1);
|
|
1466
|
+
function canDirectEncode(options) {
|
|
1467
|
+
return options.addBreakTokens !== true;
|
|
1468
|
+
}
|
|
1469
|
+
function directEncode(writer, data, options, refStack) {
|
|
1470
|
+
const typ = is(data);
|
|
1471
|
+
const customEncoder = options.typeEncoders && options.typeEncoders[typ];
|
|
1472
|
+
if (customEncoder) {
|
|
1473
|
+
const tokens = customEncoder(data, typ, options, refStack);
|
|
1474
|
+
if (tokens != null) {
|
|
1475
|
+
tokensToEncoded(writer, tokens, cborEncoders, options);
|
|
1476
|
+
return;
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
switch (typ) {
|
|
1480
|
+
case "null":
|
|
1481
|
+
writer.push([SIMPLE_NULL]);
|
|
1482
|
+
return;
|
|
1483
|
+
case "undefined":
|
|
1484
|
+
writer.push([SIMPLE_UNDEFINED]);
|
|
1485
|
+
return;
|
|
1486
|
+
case "boolean":
|
|
1487
|
+
writer.push([data ? SIMPLE_TRUE : SIMPLE_FALSE]);
|
|
1488
|
+
return;
|
|
1489
|
+
case "number":
|
|
1490
|
+
if (!Number.isInteger(data) || !Number.isSafeInteger(data)) {
|
|
1491
|
+
encodeFloat(writer, new Token(Type.float, data), options);
|
|
1492
|
+
} else if (data >= 0) {
|
|
1493
|
+
encodeUintValue(writer, MAJOR_UINT, data);
|
|
1494
|
+
} else {
|
|
1495
|
+
encodeUintValue(writer, MAJOR_NEGINT, data * -1 - 1);
|
|
1496
|
+
}
|
|
1497
|
+
return;
|
|
1498
|
+
case "bigint":
|
|
1499
|
+
if (data >= BigInt(0)) {
|
|
1500
|
+
encodeUintValue(writer, MAJOR_UINT, data);
|
|
1501
|
+
} else {
|
|
1502
|
+
encodeUintValue(writer, MAJOR_NEGINT, data * neg1b2 - pos1b2);
|
|
1503
|
+
}
|
|
1504
|
+
return;
|
|
1505
|
+
case "string": {
|
|
1506
|
+
const bytes = fromString(data);
|
|
1507
|
+
encodeUintValue(writer, MAJOR_STRING, bytes.length);
|
|
1508
|
+
writer.push(bytes);
|
|
1509
|
+
return;
|
|
1510
|
+
}
|
|
1511
|
+
case "Uint8Array":
|
|
1512
|
+
encodeUintValue(writer, MAJOR_BYTES, data.length);
|
|
1513
|
+
writer.push(data);
|
|
1514
|
+
return;
|
|
1515
|
+
case "Array":
|
|
1516
|
+
if (!data.length) {
|
|
1517
|
+
writer.push([MAJOR_ARRAY]);
|
|
1518
|
+
return;
|
|
1519
|
+
}
|
|
1520
|
+
refStack = Ref.createCheck(refStack, data);
|
|
1521
|
+
encodeUintValue(writer, MAJOR_ARRAY, data.length);
|
|
1522
|
+
for (const elem of data) {
|
|
1523
|
+
directEncode(writer, elem, options, refStack);
|
|
1524
|
+
}
|
|
1525
|
+
return;
|
|
1526
|
+
case "Object":
|
|
1527
|
+
case "Map":
|
|
1528
|
+
{
|
|
1529
|
+
const tokens = typeEncoders.Object(data, typ, options, refStack);
|
|
1530
|
+
tokensToEncoded(writer, tokens, cborEncoders, options);
|
|
1531
|
+
}
|
|
1532
|
+
return;
|
|
1533
|
+
default: {
|
|
1534
|
+
const typeEncoder = typeEncoders[typ];
|
|
1535
|
+
if (!typeEncoder) {
|
|
1536
|
+
throw new Error(`${encodeErrPrefix} unsupported type: ${typ}`);
|
|
1537
|
+
}
|
|
1538
|
+
const tokens = typeEncoder(data, typ, options, refStack);
|
|
1539
|
+
tokensToEncoded(writer, tokens, cborEncoders, options);
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
function encodeCustom(data, encoders, options, destination) {
|
|
1544
|
+
const hasDest = destination instanceof Uint8Array;
|
|
1545
|
+
let writeTo = hasDest ? new U8Bl(destination) : defaultWriter;
|
|
1546
|
+
const tokens = objectToTokens(data, options);
|
|
1547
|
+
if (!Array.isArray(tokens) && options.quickEncodeToken) {
|
|
1548
|
+
const quickBytes = options.quickEncodeToken(tokens);
|
|
1549
|
+
if (quickBytes) {
|
|
1550
|
+
if (hasDest) {
|
|
1551
|
+
writeTo.push(quickBytes);
|
|
1552
|
+
return writeTo.toBytes();
|
|
1553
|
+
}
|
|
1554
|
+
return quickBytes;
|
|
1555
|
+
}
|
|
1556
|
+
const encoder = encoders[tokens.type.major];
|
|
1557
|
+
if (encoder.encodedSize) {
|
|
1558
|
+
const size = encoder.encodedSize(tokens, options);
|
|
1559
|
+
if (!hasDest) {
|
|
1560
|
+
writeTo = new Bl(size);
|
|
1561
|
+
}
|
|
1562
|
+
encoder(writeTo, tokens, options);
|
|
1563
|
+
if (writeTo.chunks.length !== 1) {
|
|
1564
|
+
throw new Error(`Unexpected error: pre-calculated length for ${tokens} was wrong`);
|
|
1565
|
+
}
|
|
1566
|
+
return hasDest ? writeTo.toBytes() : asU8A(writeTo.chunks[0]);
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
writeTo.reset();
|
|
1570
|
+
tokensToEncoded(writeTo, tokens, encoders, options);
|
|
1571
|
+
return writeTo.toBytes(true);
|
|
1572
|
+
}
|
|
1573
|
+
function encode(data, options) {
|
|
1574
|
+
options = Object.assign({}, defaultEncodeOptions, options);
|
|
1575
|
+
if (canDirectEncode(options)) {
|
|
1576
|
+
defaultWriter.reset();
|
|
1577
|
+
directEncode(defaultWriter, data, options, void 0);
|
|
1578
|
+
return defaultWriter.toBytes(true);
|
|
1579
|
+
}
|
|
1580
|
+
return encodeCustom(data, cborEncoders, options);
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
// ../../../node_modules/.pnpm/cborg@4.5.8/node_modules/cborg/lib/decode.js
|
|
1584
|
+
var defaultDecodeOptions = {
|
|
1585
|
+
strict: false,
|
|
1586
|
+
allowIndefinite: true,
|
|
1587
|
+
allowUndefined: true,
|
|
1588
|
+
allowBigInt: true
|
|
1589
|
+
};
|
|
1590
|
+
var Tokeniser = class {
|
|
1591
|
+
/**
|
|
1592
|
+
* @param {Uint8Array} data
|
|
1593
|
+
* @param {DecodeOptions} options
|
|
1594
|
+
*/
|
|
1595
|
+
constructor(data, options = {}) {
|
|
1596
|
+
this._pos = 0;
|
|
1597
|
+
this.data = data;
|
|
1598
|
+
this.options = options;
|
|
1599
|
+
}
|
|
1600
|
+
pos() {
|
|
1601
|
+
return this._pos;
|
|
1602
|
+
}
|
|
1603
|
+
done() {
|
|
1604
|
+
return this._pos >= this.data.length;
|
|
1605
|
+
}
|
|
1606
|
+
next() {
|
|
1607
|
+
const byt = this.data[this._pos];
|
|
1608
|
+
let token = quick[byt];
|
|
1609
|
+
if (token === void 0) {
|
|
1610
|
+
const decoder = jump[byt];
|
|
1611
|
+
if (!decoder) {
|
|
1612
|
+
throw new Error(`${decodeErrPrefix} no decoder for major type ${byt >>> 5} (byte 0x${byt.toString(16).padStart(2, "0")})`);
|
|
1613
|
+
}
|
|
1614
|
+
const minor = byt & 31;
|
|
1615
|
+
token = decoder(this.data, this._pos, minor, this.options);
|
|
1616
|
+
}
|
|
1617
|
+
this._pos += token.encodedLength;
|
|
1618
|
+
return token;
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1621
|
+
var DONE = Symbol.for("DONE");
|
|
1622
|
+
var BREAK = Symbol.for("BREAK");
|
|
1623
|
+
function tokenToArray(token, tokeniser, options) {
|
|
1624
|
+
const arr = [];
|
|
1625
|
+
for (let i = 0; i < token.value; i++) {
|
|
1626
|
+
const value = tokensToObject(tokeniser, options);
|
|
1627
|
+
if (value === BREAK) {
|
|
1628
|
+
if (token.value === Infinity) {
|
|
1629
|
+
break;
|
|
1630
|
+
}
|
|
1631
|
+
throw new Error(`${decodeErrPrefix} got unexpected break to lengthed array`);
|
|
1632
|
+
}
|
|
1633
|
+
if (value === DONE) {
|
|
1634
|
+
throw new Error(`${decodeErrPrefix} found array but not enough entries (got ${i}, expected ${token.value})`);
|
|
1635
|
+
}
|
|
1636
|
+
arr[i] = value;
|
|
1637
|
+
}
|
|
1638
|
+
return arr;
|
|
1639
|
+
}
|
|
1640
|
+
function tokenToMap(token, tokeniser, options) {
|
|
1641
|
+
const useMaps = options.useMaps === true;
|
|
1642
|
+
const rejectDuplicateMapKeys = options.rejectDuplicateMapKeys === true;
|
|
1643
|
+
const obj = useMaps ? void 0 : {};
|
|
1644
|
+
const m = useMaps ? /* @__PURE__ */ new Map() : void 0;
|
|
1645
|
+
for (let i = 0; i < token.value; i++) {
|
|
1646
|
+
const key = tokensToObject(tokeniser, options);
|
|
1647
|
+
if (key === BREAK) {
|
|
1648
|
+
if (token.value === Infinity) {
|
|
1649
|
+
break;
|
|
1650
|
+
}
|
|
1651
|
+
throw new Error(`${decodeErrPrefix} got unexpected break to lengthed map`);
|
|
1652
|
+
}
|
|
1653
|
+
if (key === DONE) {
|
|
1654
|
+
throw new Error(`${decodeErrPrefix} found map but not enough entries (got ${i} [no key], expected ${token.value})`);
|
|
1655
|
+
}
|
|
1656
|
+
if (!useMaps && typeof key !== "string") {
|
|
1657
|
+
throw new Error(`${decodeErrPrefix} non-string keys not supported (got ${typeof key})`);
|
|
1658
|
+
}
|
|
1659
|
+
if (rejectDuplicateMapKeys) {
|
|
1660
|
+
if (useMaps && m.has(key) || !useMaps && Object.hasOwn(obj, key)) {
|
|
1661
|
+
throw new Error(`${decodeErrPrefix} found repeat map key "${key}"`);
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
const value = tokensToObject(tokeniser, options);
|
|
1665
|
+
if (value === DONE) {
|
|
1666
|
+
throw new Error(`${decodeErrPrefix} found map but not enough entries (got ${i} [no value], expected ${token.value})`);
|
|
1667
|
+
}
|
|
1668
|
+
if (useMaps) {
|
|
1669
|
+
m.set(key, value);
|
|
1670
|
+
} else {
|
|
1671
|
+
obj[key] = value;
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
return useMaps ? m : obj;
|
|
1675
|
+
}
|
|
1676
|
+
function tokensToObject(tokeniser, options) {
|
|
1677
|
+
if (tokeniser.done()) {
|
|
1678
|
+
return DONE;
|
|
1679
|
+
}
|
|
1680
|
+
const token = tokeniser.next();
|
|
1681
|
+
if (Type.equals(token.type, Type.break)) {
|
|
1682
|
+
return BREAK;
|
|
1683
|
+
}
|
|
1684
|
+
if (token.type.terminal) {
|
|
1685
|
+
return token.value;
|
|
1686
|
+
}
|
|
1687
|
+
if (Type.equals(token.type, Type.array)) {
|
|
1688
|
+
return tokenToArray(token, tokeniser, options);
|
|
1689
|
+
}
|
|
1690
|
+
if (Type.equals(token.type, Type.map)) {
|
|
1691
|
+
return tokenToMap(token, tokeniser, options);
|
|
1692
|
+
}
|
|
1693
|
+
if (Type.equals(token.type, Type.tag)) {
|
|
1694
|
+
if (options.tags && typeof options.tags[token.value] === "function") {
|
|
1695
|
+
const tagged = tokensToObject(tokeniser, options);
|
|
1696
|
+
return options.tags[token.value](tagged);
|
|
1697
|
+
}
|
|
1698
|
+
throw new Error(`${decodeErrPrefix} tag not supported (${token.value})`);
|
|
1699
|
+
}
|
|
1700
|
+
throw new Error("unsupported");
|
|
1701
|
+
}
|
|
1702
|
+
function decodeFirst(data, options) {
|
|
1703
|
+
if (!(data instanceof Uint8Array)) {
|
|
1704
|
+
throw new Error(`${decodeErrPrefix} data to decode must be a Uint8Array`);
|
|
1705
|
+
}
|
|
1706
|
+
options = Object.assign({}, defaultDecodeOptions, options);
|
|
1707
|
+
const u8aData = asU8A(data);
|
|
1708
|
+
const tokeniser = options.tokenizer || new Tokeniser(u8aData, options);
|
|
1709
|
+
const decoded = tokensToObject(tokeniser, options);
|
|
1710
|
+
if (decoded === DONE) {
|
|
1711
|
+
throw new Error(`${decodeErrPrefix} did not find any content to decode`);
|
|
1712
|
+
}
|
|
1713
|
+
if (decoded === BREAK) {
|
|
1714
|
+
throw new Error(`${decodeErrPrefix} got unexpected break`);
|
|
1715
|
+
}
|
|
1716
|
+
return [decoded, data.subarray(tokeniser.pos())];
|
|
1717
|
+
}
|
|
1718
|
+
function decode(data, options) {
|
|
1719
|
+
const [decoded, remainder] = decodeFirst(data, options);
|
|
1720
|
+
if (remainder.length > 0) {
|
|
1721
|
+
throw new Error(`${decodeErrPrefix} too many terminals, data makes no sense`);
|
|
1722
|
+
}
|
|
1723
|
+
return decoded;
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
// ../../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/bases/base36.js
|
|
1727
|
+
var base36_exports = {};
|
|
1728
|
+
__export(base36_exports, {
|
|
1729
|
+
base36: () => base36,
|
|
1730
|
+
base36upper: () => base36upper
|
|
1731
|
+
});
|
|
1732
|
+
|
|
1733
|
+
// ../../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/bytes.js
|
|
1734
|
+
var empty = new Uint8Array(0);
|
|
1735
|
+
function equals(aa, bb) {
|
|
1736
|
+
if (aa === bb) {
|
|
1737
|
+
return true;
|
|
1738
|
+
}
|
|
1739
|
+
if (aa.byteLength !== bb.byteLength) {
|
|
1740
|
+
return false;
|
|
1741
|
+
}
|
|
1742
|
+
for (let ii = 0; ii < aa.byteLength; ii++) {
|
|
1743
|
+
if (aa[ii] !== bb[ii]) {
|
|
1744
|
+
return false;
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
return true;
|
|
1748
|
+
}
|
|
1749
|
+
function coerce(o) {
|
|
1750
|
+
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") {
|
|
1751
|
+
return o;
|
|
1752
|
+
}
|
|
1753
|
+
if (o instanceof ArrayBuffer) {
|
|
1754
|
+
return new Uint8Array(o);
|
|
1755
|
+
}
|
|
1756
|
+
if (ArrayBuffer.isView(o)) {
|
|
1757
|
+
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
1758
|
+
}
|
|
1759
|
+
throw new Error("Unknown type, must be binary type");
|
|
1760
|
+
}
|
|
1761
|
+
function fromString2(str) {
|
|
1762
|
+
return new TextEncoder().encode(str);
|
|
1763
|
+
}
|
|
1764
|
+
function toString(b) {
|
|
1765
|
+
return new TextDecoder().decode(b);
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
// ../../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/vendor/base-x.js
|
|
1769
|
+
function base(ALPHABET, name) {
|
|
1770
|
+
if (ALPHABET.length >= 255) {
|
|
1771
|
+
throw new TypeError("Alphabet too long");
|
|
1772
|
+
}
|
|
1773
|
+
var BASE_MAP = new Uint8Array(256);
|
|
1774
|
+
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
1775
|
+
BASE_MAP[j] = 255;
|
|
1776
|
+
}
|
|
1777
|
+
for (var i = 0; i < ALPHABET.length; i++) {
|
|
1778
|
+
var x = ALPHABET.charAt(i);
|
|
1779
|
+
var xc = x.charCodeAt(0);
|
|
1780
|
+
if (BASE_MAP[xc] !== 255) {
|
|
1781
|
+
throw new TypeError(x + " is ambiguous");
|
|
1782
|
+
}
|
|
1783
|
+
BASE_MAP[xc] = i;
|
|
1784
|
+
}
|
|
1785
|
+
var BASE = ALPHABET.length;
|
|
1786
|
+
var LEADER = ALPHABET.charAt(0);
|
|
1787
|
+
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
1788
|
+
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
1789
|
+
function encode5(source) {
|
|
1790
|
+
if (source instanceof Uint8Array)
|
|
1791
|
+
;
|
|
1792
|
+
else if (ArrayBuffer.isView(source)) {
|
|
1793
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
1794
|
+
} else if (Array.isArray(source)) {
|
|
1795
|
+
source = Uint8Array.from(source);
|
|
1796
|
+
}
|
|
1797
|
+
if (!(source instanceof Uint8Array)) {
|
|
1798
|
+
throw new TypeError("Expected Uint8Array");
|
|
1799
|
+
}
|
|
1800
|
+
if (source.length === 0) {
|
|
1801
|
+
return "";
|
|
1802
|
+
}
|
|
1803
|
+
var zeroes = 0;
|
|
1804
|
+
var length2 = 0;
|
|
1805
|
+
var pbegin = 0;
|
|
1806
|
+
var pend = source.length;
|
|
1807
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
1808
|
+
pbegin++;
|
|
1809
|
+
zeroes++;
|
|
1810
|
+
}
|
|
1811
|
+
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
1812
|
+
var b58 = new Uint8Array(size);
|
|
1813
|
+
while (pbegin !== pend) {
|
|
1814
|
+
var carry = source[pbegin];
|
|
1815
|
+
var i2 = 0;
|
|
1816
|
+
for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
|
|
1817
|
+
carry += 256 * b58[it1] >>> 0;
|
|
1818
|
+
b58[it1] = carry % BASE >>> 0;
|
|
1819
|
+
carry = carry / BASE >>> 0;
|
|
1820
|
+
}
|
|
1821
|
+
if (carry !== 0) {
|
|
1822
|
+
throw new Error("Non-zero carry");
|
|
1823
|
+
}
|
|
1824
|
+
length2 = i2;
|
|
1825
|
+
pbegin++;
|
|
1826
|
+
}
|
|
1827
|
+
var it2 = size - length2;
|
|
1828
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
1829
|
+
it2++;
|
|
1830
|
+
}
|
|
1831
|
+
var str = LEADER.repeat(zeroes);
|
|
1832
|
+
for (; it2 < size; ++it2) {
|
|
1833
|
+
str += ALPHABET.charAt(b58[it2]);
|
|
1834
|
+
}
|
|
1835
|
+
return str;
|
|
1836
|
+
}
|
|
1837
|
+
function decodeUnsafe(source) {
|
|
1838
|
+
if (typeof source !== "string") {
|
|
1839
|
+
throw new TypeError("Expected String");
|
|
1840
|
+
}
|
|
1841
|
+
if (source.length === 0) {
|
|
1842
|
+
return new Uint8Array();
|
|
1843
|
+
}
|
|
1844
|
+
var psz = 0;
|
|
1845
|
+
if (source[psz] === " ") {
|
|
1846
|
+
return;
|
|
1847
|
+
}
|
|
1848
|
+
var zeroes = 0;
|
|
1849
|
+
var length2 = 0;
|
|
1850
|
+
while (source[psz] === LEADER) {
|
|
1851
|
+
zeroes++;
|
|
1852
|
+
psz++;
|
|
1853
|
+
}
|
|
1854
|
+
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
1855
|
+
var b256 = new Uint8Array(size);
|
|
1856
|
+
while (source[psz]) {
|
|
1857
|
+
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
1858
|
+
if (carry === 255) {
|
|
1859
|
+
return;
|
|
1860
|
+
}
|
|
1861
|
+
var i2 = 0;
|
|
1862
|
+
for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
|
|
1863
|
+
carry += BASE * b256[it3] >>> 0;
|
|
1864
|
+
b256[it3] = carry % 256 >>> 0;
|
|
1865
|
+
carry = carry / 256 >>> 0;
|
|
1866
|
+
}
|
|
1867
|
+
if (carry !== 0) {
|
|
1868
|
+
throw new Error("Non-zero carry");
|
|
1869
|
+
}
|
|
1870
|
+
length2 = i2;
|
|
1871
|
+
psz++;
|
|
1872
|
+
}
|
|
1873
|
+
if (source[psz] === " ") {
|
|
1874
|
+
return;
|
|
1875
|
+
}
|
|
1876
|
+
var it4 = size - length2;
|
|
1877
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
1878
|
+
it4++;
|
|
1879
|
+
}
|
|
1880
|
+
var vch = new Uint8Array(zeroes + (size - it4));
|
|
1881
|
+
var j2 = zeroes;
|
|
1882
|
+
while (it4 !== size) {
|
|
1883
|
+
vch[j2++] = b256[it4++];
|
|
1884
|
+
}
|
|
1885
|
+
return vch;
|
|
1886
|
+
}
|
|
1887
|
+
function decode7(string) {
|
|
1888
|
+
var buffer2 = decodeUnsafe(string);
|
|
1889
|
+
if (buffer2) {
|
|
1890
|
+
return buffer2;
|
|
1891
|
+
}
|
|
1892
|
+
throw new Error(`Non-${name} character`);
|
|
1893
|
+
}
|
|
1894
|
+
return {
|
|
1895
|
+
encode: encode5,
|
|
1896
|
+
decodeUnsafe,
|
|
1897
|
+
decode: decode7
|
|
1898
|
+
};
|
|
1899
|
+
}
|
|
1900
|
+
var src = base;
|
|
1901
|
+
var _brrp__multiformats_scope_baseX = src;
|
|
1902
|
+
var base_x_default = _brrp__multiformats_scope_baseX;
|
|
1903
|
+
|
|
1904
|
+
// ../../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/bases/base.js
|
|
1905
|
+
var Encoder = class {
|
|
1906
|
+
name;
|
|
1907
|
+
prefix;
|
|
1908
|
+
baseEncode;
|
|
1909
|
+
constructor(name, prefix, baseEncode) {
|
|
1910
|
+
this.name = name;
|
|
1911
|
+
this.prefix = prefix;
|
|
1912
|
+
this.baseEncode = baseEncode;
|
|
1913
|
+
}
|
|
1914
|
+
encode(bytes) {
|
|
1915
|
+
if (bytes instanceof Uint8Array) {
|
|
1916
|
+
return `${this.prefix}${this.baseEncode(bytes)}`;
|
|
1917
|
+
} else {
|
|
1918
|
+
throw Error("Unknown type, must be binary type");
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
};
|
|
1922
|
+
var Decoder = class {
|
|
1923
|
+
name;
|
|
1924
|
+
prefix;
|
|
1925
|
+
baseDecode;
|
|
1926
|
+
prefixCodePoint;
|
|
1927
|
+
constructor(name, prefix, baseDecode) {
|
|
1928
|
+
this.name = name;
|
|
1929
|
+
this.prefix = prefix;
|
|
1930
|
+
const prefixCodePoint = prefix.codePointAt(0);
|
|
1931
|
+
if (prefixCodePoint === void 0) {
|
|
1932
|
+
throw new Error("Invalid prefix character");
|
|
1933
|
+
}
|
|
1934
|
+
this.prefixCodePoint = prefixCodePoint;
|
|
1935
|
+
this.baseDecode = baseDecode;
|
|
1936
|
+
}
|
|
1937
|
+
decode(text) {
|
|
1938
|
+
if (typeof text === "string") {
|
|
1939
|
+
if (text.codePointAt(0) !== this.prefixCodePoint) {
|
|
1940
|
+
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
|
|
1941
|
+
}
|
|
1942
|
+
return this.baseDecode(text.slice(this.prefix.length));
|
|
1943
|
+
} else {
|
|
1944
|
+
throw Error("Can only multibase decode strings");
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
or(decoder) {
|
|
1948
|
+
return or(this, decoder);
|
|
1949
|
+
}
|
|
1950
|
+
};
|
|
1951
|
+
var ComposedDecoder = class {
|
|
1952
|
+
decoders;
|
|
1953
|
+
constructor(decoders) {
|
|
1954
|
+
this.decoders = decoders;
|
|
1955
|
+
}
|
|
1956
|
+
or(decoder) {
|
|
1957
|
+
return or(this, decoder);
|
|
1958
|
+
}
|
|
1959
|
+
decode(input) {
|
|
1960
|
+
const prefix = input[0];
|
|
1961
|
+
const decoder = this.decoders[prefix];
|
|
1962
|
+
if (decoder != null) {
|
|
1963
|
+
return decoder.decode(input);
|
|
1964
|
+
} else {
|
|
1965
|
+
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
};
|
|
1969
|
+
function or(left, right) {
|
|
1970
|
+
return new ComposedDecoder({
|
|
1971
|
+
...left.decoders ?? { [left.prefix]: left },
|
|
1972
|
+
...right.decoders ?? { [right.prefix]: right }
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
var Codec = class {
|
|
1976
|
+
name;
|
|
1977
|
+
prefix;
|
|
1978
|
+
baseEncode;
|
|
1979
|
+
baseDecode;
|
|
1980
|
+
encoder;
|
|
1981
|
+
decoder;
|
|
1982
|
+
constructor(name, prefix, baseEncode, baseDecode) {
|
|
1983
|
+
this.name = name;
|
|
1984
|
+
this.prefix = prefix;
|
|
1985
|
+
this.baseEncode = baseEncode;
|
|
1986
|
+
this.baseDecode = baseDecode;
|
|
1987
|
+
this.encoder = new Encoder(name, prefix, baseEncode);
|
|
1988
|
+
this.decoder = new Decoder(name, prefix, baseDecode);
|
|
1989
|
+
}
|
|
1990
|
+
encode(input) {
|
|
1991
|
+
return this.encoder.encode(input);
|
|
1992
|
+
}
|
|
1993
|
+
decode(input) {
|
|
1994
|
+
return this.decoder.decode(input);
|
|
1995
|
+
}
|
|
1996
|
+
};
|
|
1997
|
+
function from({ name, prefix, encode: encode5, decode: decode7 }) {
|
|
1998
|
+
return new Codec(name, prefix, encode5, decode7);
|
|
1999
|
+
}
|
|
2000
|
+
function baseX({ name, prefix, alphabet }) {
|
|
2001
|
+
const { encode: encode5, decode: decode7 } = base_x_default(alphabet, name);
|
|
2002
|
+
return from({
|
|
2003
|
+
prefix,
|
|
2004
|
+
name,
|
|
2005
|
+
encode: encode5,
|
|
2006
|
+
decode: (text) => coerce(decode7(text))
|
|
2007
|
+
});
|
|
2008
|
+
}
|
|
2009
|
+
function decode2(string, alphabetIdx, bitsPerChar, name) {
|
|
2010
|
+
let end = string.length;
|
|
2011
|
+
while (string[end - 1] === "=") {
|
|
2012
|
+
--end;
|
|
2013
|
+
}
|
|
2014
|
+
const out = new Uint8Array(end * bitsPerChar / 8 | 0);
|
|
2015
|
+
let bits = 0;
|
|
2016
|
+
let buffer2 = 0;
|
|
2017
|
+
let written = 0;
|
|
2018
|
+
for (let i = 0; i < end; ++i) {
|
|
2019
|
+
const value = alphabetIdx[string[i]];
|
|
2020
|
+
if (value === void 0) {
|
|
2021
|
+
throw new SyntaxError(`Non-${name} character`);
|
|
2022
|
+
}
|
|
2023
|
+
buffer2 = buffer2 << bitsPerChar | value;
|
|
2024
|
+
bits += bitsPerChar;
|
|
2025
|
+
if (bits >= 8) {
|
|
2026
|
+
bits -= 8;
|
|
2027
|
+
out[written++] = 255 & buffer2 >> bits;
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
if (bits >= bitsPerChar || (255 & buffer2 << 8 - bits) !== 0) {
|
|
2031
|
+
throw new SyntaxError("Unexpected end of data");
|
|
2032
|
+
}
|
|
2033
|
+
return out;
|
|
2034
|
+
}
|
|
2035
|
+
function encode2(data, alphabet, bitsPerChar) {
|
|
2036
|
+
const pad = alphabet[alphabet.length - 1] === "=";
|
|
2037
|
+
const mask = (1 << bitsPerChar) - 1;
|
|
2038
|
+
let out = "";
|
|
2039
|
+
let bits = 0;
|
|
2040
|
+
let buffer2 = 0;
|
|
2041
|
+
for (let i = 0; i < data.length; ++i) {
|
|
2042
|
+
buffer2 = buffer2 << 8 | data[i];
|
|
2043
|
+
bits += 8;
|
|
2044
|
+
while (bits > bitsPerChar) {
|
|
2045
|
+
bits -= bitsPerChar;
|
|
2046
|
+
out += alphabet[mask & buffer2 >> bits];
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
if (bits !== 0) {
|
|
2050
|
+
out += alphabet[mask & buffer2 << bitsPerChar - bits];
|
|
2051
|
+
}
|
|
2052
|
+
if (pad) {
|
|
2053
|
+
while ((out.length * bitsPerChar & 7) !== 0) {
|
|
2054
|
+
out += "=";
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
return out;
|
|
2058
|
+
}
|
|
2059
|
+
function createAlphabetIdx(alphabet) {
|
|
2060
|
+
const alphabetIdx = {};
|
|
2061
|
+
for (let i = 0; i < alphabet.length; ++i) {
|
|
2062
|
+
alphabetIdx[alphabet[i]] = i;
|
|
2063
|
+
}
|
|
2064
|
+
return alphabetIdx;
|
|
2065
|
+
}
|
|
2066
|
+
function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
|
|
2067
|
+
const alphabetIdx = createAlphabetIdx(alphabet);
|
|
2068
|
+
return from({
|
|
2069
|
+
prefix,
|
|
2070
|
+
name,
|
|
2071
|
+
encode(input) {
|
|
2072
|
+
return encode2(input, alphabet, bitsPerChar);
|
|
2073
|
+
},
|
|
2074
|
+
decode(input) {
|
|
2075
|
+
return decode2(input, alphabetIdx, bitsPerChar, name);
|
|
2076
|
+
}
|
|
2077
|
+
});
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
// ../../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/bases/base36.js
|
|
2081
|
+
var base36 = baseX({
|
|
2082
|
+
prefix: "k",
|
|
2083
|
+
name: "base36",
|
|
2084
|
+
alphabet: "0123456789abcdefghijklmnopqrstuvwxyz"
|
|
2085
|
+
});
|
|
2086
|
+
var base36upper = baseX({
|
|
2087
|
+
prefix: "K",
|
|
2088
|
+
name: "base36upper",
|
|
2089
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
2090
|
+
});
|
|
2091
|
+
|
|
2092
|
+
// ../../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/vendor/varint.js
|
|
2093
|
+
var encode_1 = encode3;
|
|
2094
|
+
var MSB = 128;
|
|
2095
|
+
var REST = 127;
|
|
2096
|
+
var MSBALL = ~REST;
|
|
2097
|
+
var INT = Math.pow(2, 31);
|
|
2098
|
+
function encode3(num, out, offset) {
|
|
2099
|
+
out = out || [];
|
|
2100
|
+
offset = offset || 0;
|
|
2101
|
+
var oldOffset = offset;
|
|
2102
|
+
while (num >= INT) {
|
|
2103
|
+
out[offset++] = num & 255 | MSB;
|
|
2104
|
+
num /= 128;
|
|
2105
|
+
}
|
|
2106
|
+
while (num & MSBALL) {
|
|
2107
|
+
out[offset++] = num & 255 | MSB;
|
|
2108
|
+
num >>>= 7;
|
|
2109
|
+
}
|
|
2110
|
+
out[offset] = num | 0;
|
|
2111
|
+
encode3.bytes = offset - oldOffset + 1;
|
|
2112
|
+
return out;
|
|
2113
|
+
}
|
|
2114
|
+
var decode3 = read;
|
|
2115
|
+
var MSB$1 = 128;
|
|
2116
|
+
var REST$1 = 127;
|
|
2117
|
+
function read(buf, offset) {
|
|
2118
|
+
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
|
|
2119
|
+
do {
|
|
2120
|
+
if (counter >= l) {
|
|
2121
|
+
read.bytes = 0;
|
|
2122
|
+
throw new RangeError("Could not decode varint");
|
|
2123
|
+
}
|
|
2124
|
+
b = buf[counter++];
|
|
2125
|
+
res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
|
|
2126
|
+
shift += 7;
|
|
2127
|
+
} while (b >= MSB$1);
|
|
2128
|
+
read.bytes = counter - offset;
|
|
2129
|
+
return res;
|
|
2130
|
+
}
|
|
2131
|
+
var N1 = Math.pow(2, 7);
|
|
2132
|
+
var N2 = Math.pow(2, 14);
|
|
2133
|
+
var N3 = Math.pow(2, 21);
|
|
2134
|
+
var N4 = Math.pow(2, 28);
|
|
2135
|
+
var N5 = Math.pow(2, 35);
|
|
2136
|
+
var N6 = Math.pow(2, 42);
|
|
2137
|
+
var N7 = Math.pow(2, 49);
|
|
2138
|
+
var N8 = Math.pow(2, 56);
|
|
2139
|
+
var N9 = Math.pow(2, 63);
|
|
2140
|
+
var length = function(value) {
|
|
2141
|
+
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;
|
|
2142
|
+
};
|
|
2143
|
+
var varint = {
|
|
2144
|
+
encode: encode_1,
|
|
2145
|
+
decode: decode3,
|
|
2146
|
+
encodingLength: length
|
|
2147
|
+
};
|
|
2148
|
+
var _brrp_varint = varint;
|
|
2149
|
+
var varint_default = _brrp_varint;
|
|
2150
|
+
|
|
2151
|
+
// ../../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/varint.js
|
|
2152
|
+
function decode4(data, offset = 0) {
|
|
2153
|
+
const code = varint_default.decode(data, offset);
|
|
2154
|
+
return [code, varint_default.decode.bytes];
|
|
2155
|
+
}
|
|
2156
|
+
function encodeTo(int, target, offset = 0) {
|
|
2157
|
+
varint_default.encode(int, target, offset);
|
|
2158
|
+
return target;
|
|
2159
|
+
}
|
|
2160
|
+
function encodingLength(int) {
|
|
2161
|
+
return varint_default.encodingLength(int);
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
// ../../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/hashes/digest.js
|
|
2165
|
+
function create(code, digest) {
|
|
2166
|
+
const size = digest.byteLength;
|
|
2167
|
+
const sizeOffset = encodingLength(code);
|
|
2168
|
+
const digestOffset = sizeOffset + encodingLength(size);
|
|
2169
|
+
const bytes = new Uint8Array(digestOffset + size);
|
|
2170
|
+
encodeTo(code, bytes, 0);
|
|
2171
|
+
encodeTo(size, bytes, sizeOffset);
|
|
2172
|
+
bytes.set(digest, digestOffset);
|
|
2173
|
+
return new Digest(code, size, digest, bytes);
|
|
2174
|
+
}
|
|
2175
|
+
function decode5(multihash) {
|
|
2176
|
+
const bytes = coerce(multihash);
|
|
2177
|
+
const [code, sizeOffset] = decode4(bytes);
|
|
2178
|
+
const [size, digestOffset] = decode4(bytes.subarray(sizeOffset));
|
|
2179
|
+
const digest = bytes.subarray(sizeOffset + digestOffset);
|
|
2180
|
+
if (digest.byteLength !== size) {
|
|
2181
|
+
throw new Error("Incorrect length");
|
|
2182
|
+
}
|
|
2183
|
+
return new Digest(code, size, digest, bytes);
|
|
2184
|
+
}
|
|
2185
|
+
function equals2(a, b) {
|
|
2186
|
+
if (a === b) {
|
|
2187
|
+
return true;
|
|
2188
|
+
} else {
|
|
2189
|
+
const data = b;
|
|
2190
|
+
return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
var Digest = class {
|
|
2194
|
+
code;
|
|
2195
|
+
size;
|
|
2196
|
+
digest;
|
|
2197
|
+
bytes;
|
|
2198
|
+
/**
|
|
2199
|
+
* Creates a multihash digest.
|
|
2200
|
+
*/
|
|
2201
|
+
constructor(code, size, digest, bytes) {
|
|
2202
|
+
this.code = code;
|
|
2203
|
+
this.size = size;
|
|
2204
|
+
this.digest = digest;
|
|
2205
|
+
this.bytes = bytes;
|
|
2206
|
+
}
|
|
2207
|
+
};
|
|
2208
|
+
|
|
2209
|
+
// ../../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/bases/base32.js
|
|
2210
|
+
var base32_exports = {};
|
|
2211
|
+
__export(base32_exports, {
|
|
2212
|
+
base32: () => base32,
|
|
2213
|
+
base32hex: () => base32hex,
|
|
2214
|
+
base32hexpad: () => base32hexpad,
|
|
2215
|
+
base32hexpadupper: () => base32hexpadupper,
|
|
2216
|
+
base32hexupper: () => base32hexupper,
|
|
2217
|
+
base32pad: () => base32pad,
|
|
2218
|
+
base32padupper: () => base32padupper,
|
|
2219
|
+
base32upper: () => base32upper,
|
|
2220
|
+
base32z: () => base32z
|
|
2221
|
+
});
|
|
2222
|
+
var base32 = rfc4648({
|
|
2223
|
+
prefix: "b",
|
|
2224
|
+
name: "base32",
|
|
2225
|
+
alphabet: "abcdefghijklmnopqrstuvwxyz234567",
|
|
2226
|
+
bitsPerChar: 5
|
|
2227
|
+
});
|
|
2228
|
+
var base32upper = rfc4648({
|
|
2229
|
+
prefix: "B",
|
|
2230
|
+
name: "base32upper",
|
|
2231
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
|
2232
|
+
bitsPerChar: 5
|
|
2233
|
+
});
|
|
2234
|
+
var base32pad = rfc4648({
|
|
2235
|
+
prefix: "c",
|
|
2236
|
+
name: "base32pad",
|
|
2237
|
+
alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
|
|
2238
|
+
bitsPerChar: 5
|
|
2239
|
+
});
|
|
2240
|
+
var base32padupper = rfc4648({
|
|
2241
|
+
prefix: "C",
|
|
2242
|
+
name: "base32padupper",
|
|
2243
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
|
|
2244
|
+
bitsPerChar: 5
|
|
2245
|
+
});
|
|
2246
|
+
var base32hex = rfc4648({
|
|
2247
|
+
prefix: "v",
|
|
2248
|
+
name: "base32hex",
|
|
2249
|
+
alphabet: "0123456789abcdefghijklmnopqrstuv",
|
|
2250
|
+
bitsPerChar: 5
|
|
2251
|
+
});
|
|
2252
|
+
var base32hexupper = rfc4648({
|
|
2253
|
+
prefix: "V",
|
|
2254
|
+
name: "base32hexupper",
|
|
2255
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
|
|
2256
|
+
bitsPerChar: 5
|
|
2257
|
+
});
|
|
2258
|
+
var base32hexpad = rfc4648({
|
|
2259
|
+
prefix: "t",
|
|
2260
|
+
name: "base32hexpad",
|
|
2261
|
+
alphabet: "0123456789abcdefghijklmnopqrstuv=",
|
|
2262
|
+
bitsPerChar: 5
|
|
2263
|
+
});
|
|
2264
|
+
var base32hexpadupper = rfc4648({
|
|
2265
|
+
prefix: "T",
|
|
2266
|
+
name: "base32hexpadupper",
|
|
2267
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
|
|
2268
|
+
bitsPerChar: 5
|
|
2269
|
+
});
|
|
2270
|
+
var base32z = rfc4648({
|
|
2271
|
+
prefix: "h",
|
|
2272
|
+
name: "base32z",
|
|
2273
|
+
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
|
|
2274
|
+
bitsPerChar: 5
|
|
2275
|
+
});
|
|
2276
|
+
|
|
2277
|
+
// ../../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/bases/base58.js
|
|
2278
|
+
var base58_exports = {};
|
|
2279
|
+
__export(base58_exports, {
|
|
2280
|
+
base58btc: () => base58btc,
|
|
2281
|
+
base58flickr: () => base58flickr
|
|
2282
|
+
});
|
|
2283
|
+
var base58btc = baseX({
|
|
2284
|
+
name: "base58btc",
|
|
2285
|
+
prefix: "z",
|
|
2286
|
+
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
2287
|
+
});
|
|
2288
|
+
var base58flickr = baseX({
|
|
2289
|
+
name: "base58flickr",
|
|
2290
|
+
prefix: "Z",
|
|
2291
|
+
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
|
2292
|
+
});
|
|
2293
|
+
|
|
2294
|
+
// ../../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/cid.js
|
|
2295
|
+
function format(link, base3) {
|
|
2296
|
+
const { bytes, version } = link;
|
|
2297
|
+
switch (version) {
|
|
2298
|
+
case 0:
|
|
2299
|
+
return toStringV0(bytes, baseCache(link), base3 ?? base58btc.encoder);
|
|
2300
|
+
default:
|
|
2301
|
+
return toStringV1(bytes, baseCache(link), base3 ?? base32.encoder);
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
2305
|
+
function baseCache(cid) {
|
|
2306
|
+
const baseCache2 = cache.get(cid);
|
|
2307
|
+
if (baseCache2 == null) {
|
|
2308
|
+
const baseCache3 = /* @__PURE__ */ new Map();
|
|
2309
|
+
cache.set(cid, baseCache3);
|
|
2310
|
+
return baseCache3;
|
|
2311
|
+
}
|
|
2312
|
+
return baseCache2;
|
|
2313
|
+
}
|
|
2314
|
+
var CID = class _CID {
|
|
2315
|
+
code;
|
|
2316
|
+
version;
|
|
2317
|
+
multihash;
|
|
2318
|
+
bytes;
|
|
2319
|
+
"/";
|
|
2320
|
+
/**
|
|
2321
|
+
* @param version - Version of the CID
|
|
2322
|
+
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
2323
|
+
* @param multihash - (Multi)hash of the of the content.
|
|
2324
|
+
*/
|
|
2325
|
+
constructor(version, code, multihash, bytes) {
|
|
2326
|
+
this.code = code;
|
|
2327
|
+
this.version = version;
|
|
2328
|
+
this.multihash = multihash;
|
|
2329
|
+
this.bytes = bytes;
|
|
2330
|
+
this["/"] = bytes;
|
|
2331
|
+
}
|
|
2332
|
+
/**
|
|
2333
|
+
* Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
|
|
2334
|
+
* please either use `CID.asCID(cid)` or switch to new signalling mechanism
|
|
2335
|
+
*
|
|
2336
|
+
* @deprecated
|
|
2337
|
+
*/
|
|
2338
|
+
get asCID() {
|
|
2339
|
+
return this;
|
|
2340
|
+
}
|
|
2341
|
+
// ArrayBufferView
|
|
2342
|
+
get byteOffset() {
|
|
2343
|
+
return this.bytes.byteOffset;
|
|
2344
|
+
}
|
|
2345
|
+
// ArrayBufferView
|
|
2346
|
+
get byteLength() {
|
|
2347
|
+
return this.bytes.byteLength;
|
|
2348
|
+
}
|
|
2349
|
+
toV0() {
|
|
2350
|
+
switch (this.version) {
|
|
2351
|
+
case 0: {
|
|
2352
|
+
return this;
|
|
2353
|
+
}
|
|
2354
|
+
case 1: {
|
|
2355
|
+
const { code, multihash } = this;
|
|
2356
|
+
if (code !== DAG_PB_CODE) {
|
|
2357
|
+
throw new Error("Cannot convert a non dag-pb CID to CIDv0");
|
|
2358
|
+
}
|
|
2359
|
+
if (multihash.code !== SHA_256_CODE) {
|
|
2360
|
+
throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
|
|
2361
|
+
}
|
|
2362
|
+
return _CID.createV0(multihash);
|
|
2363
|
+
}
|
|
2364
|
+
default: {
|
|
2365
|
+
throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
toV1() {
|
|
2370
|
+
switch (this.version) {
|
|
2371
|
+
case 0: {
|
|
2372
|
+
const { code, digest } = this.multihash;
|
|
2373
|
+
const multihash = create(code, digest);
|
|
2374
|
+
return _CID.createV1(this.code, multihash);
|
|
2375
|
+
}
|
|
2376
|
+
case 1: {
|
|
2377
|
+
return this;
|
|
2378
|
+
}
|
|
2379
|
+
default: {
|
|
2380
|
+
throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`);
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2384
|
+
equals(other) {
|
|
2385
|
+
return _CID.equals(this, other);
|
|
2386
|
+
}
|
|
2387
|
+
static equals(self, other) {
|
|
2388
|
+
const unknown = other;
|
|
2389
|
+
return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
|
|
2390
|
+
}
|
|
2391
|
+
toString(base3) {
|
|
2392
|
+
return format(this, base3);
|
|
2393
|
+
}
|
|
2394
|
+
toJSON() {
|
|
2395
|
+
return { "/": format(this) };
|
|
2396
|
+
}
|
|
2397
|
+
link() {
|
|
2398
|
+
return this;
|
|
2399
|
+
}
|
|
2400
|
+
[Symbol.toStringTag] = "CID";
|
|
2401
|
+
// Legacy
|
|
2402
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
2403
|
+
return `CID(${this.toString()})`;
|
|
2404
|
+
}
|
|
2405
|
+
/**
|
|
2406
|
+
* Takes any input `value` and returns a `CID` instance if it was
|
|
2407
|
+
* a `CID` otherwise returns `null`. If `value` is instanceof `CID`
|
|
2408
|
+
* it will return value back. If `value` is not instance of this CID
|
|
2409
|
+
* class, but is compatible CID it will return new instance of this
|
|
2410
|
+
* `CID` class. Otherwise returns null.
|
|
2411
|
+
*
|
|
2412
|
+
* This allows two different incompatible versions of CID library to
|
|
2413
|
+
* co-exist and interop as long as binary interface is compatible.
|
|
2414
|
+
*/
|
|
2415
|
+
static asCID(input) {
|
|
2416
|
+
if (input == null) {
|
|
2417
|
+
return null;
|
|
2418
|
+
}
|
|
2419
|
+
const value = input;
|
|
2420
|
+
if (value instanceof _CID) {
|
|
2421
|
+
return value;
|
|
2422
|
+
} else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
|
|
2423
|
+
const { version, code, multihash, bytes } = value;
|
|
2424
|
+
return new _CID(version, code, multihash, bytes ?? encodeCID(version, code, multihash.bytes));
|
|
2425
|
+
} else if (value[cidSymbol] === true) {
|
|
2426
|
+
const { version, multihash, code } = value;
|
|
2427
|
+
const digest = decode5(multihash);
|
|
2428
|
+
return _CID.create(version, code, digest);
|
|
2429
|
+
} else {
|
|
2430
|
+
return null;
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
/**
|
|
2434
|
+
* @param version - Version of the CID
|
|
2435
|
+
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
2436
|
+
* @param digest - (Multi)hash of the of the content.
|
|
2437
|
+
*/
|
|
2438
|
+
static create(version, code, digest) {
|
|
2439
|
+
if (typeof code !== "number") {
|
|
2440
|
+
throw new Error("String codecs are no longer supported");
|
|
2441
|
+
}
|
|
2442
|
+
if (!(digest.bytes instanceof Uint8Array)) {
|
|
2443
|
+
throw new Error("Invalid digest");
|
|
2444
|
+
}
|
|
2445
|
+
switch (version) {
|
|
2446
|
+
case 0: {
|
|
2447
|
+
if (code !== DAG_PB_CODE) {
|
|
2448
|
+
throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
|
|
2449
|
+
} else {
|
|
2450
|
+
return new _CID(version, code, digest, digest.bytes);
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
case 1: {
|
|
2454
|
+
const bytes = encodeCID(version, code, digest.bytes);
|
|
2455
|
+
return new _CID(version, code, digest, bytes);
|
|
2456
|
+
}
|
|
2457
|
+
default: {
|
|
2458
|
+
throw new Error("Invalid version");
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
/**
|
|
2463
|
+
* Simplified version of `create` for CIDv0.
|
|
2464
|
+
*/
|
|
2465
|
+
static createV0(digest) {
|
|
2466
|
+
return _CID.create(0, DAG_PB_CODE, digest);
|
|
2467
|
+
}
|
|
2468
|
+
/**
|
|
2469
|
+
* Simplified version of `create` for CIDv1.
|
|
2470
|
+
*
|
|
2471
|
+
* @param code - Content encoding format code.
|
|
2472
|
+
* @param digest - Multihash of the content.
|
|
2473
|
+
*/
|
|
2474
|
+
static createV1(code, digest) {
|
|
2475
|
+
return _CID.create(1, code, digest);
|
|
2476
|
+
}
|
|
2477
|
+
/**
|
|
2478
|
+
* Decoded a CID from its binary representation. The byte array must contain
|
|
2479
|
+
* only the CID with no additional bytes.
|
|
2480
|
+
*
|
|
2481
|
+
* An error will be thrown if the bytes provided do not contain a valid
|
|
2482
|
+
* binary representation of a CID.
|
|
2483
|
+
*/
|
|
2484
|
+
static decode(bytes) {
|
|
2485
|
+
const [cid, remainder] = _CID.decodeFirst(bytes);
|
|
2486
|
+
if (remainder.length !== 0) {
|
|
2487
|
+
throw new Error("Incorrect length");
|
|
2488
|
+
}
|
|
2489
|
+
return cid;
|
|
2490
|
+
}
|
|
2491
|
+
/**
|
|
2492
|
+
* Decoded a CID from its binary representation at the beginning of a byte
|
|
2493
|
+
* array.
|
|
2494
|
+
*
|
|
2495
|
+
* Returns an array with the first element containing the CID and the second
|
|
2496
|
+
* element containing the remainder of the original byte array. The remainder
|
|
2497
|
+
* will be a zero-length byte array if the provided bytes only contained a
|
|
2498
|
+
* binary CID representation.
|
|
2499
|
+
*/
|
|
2500
|
+
static decodeFirst(bytes) {
|
|
2501
|
+
const specs = _CID.inspectBytes(bytes);
|
|
2502
|
+
const prefixSize = specs.size - specs.multihashSize;
|
|
2503
|
+
const multihashBytes = coerce(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
|
|
2504
|
+
if (multihashBytes.byteLength !== specs.multihashSize) {
|
|
2505
|
+
throw new Error("Incorrect length");
|
|
2506
|
+
}
|
|
2507
|
+
const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
|
|
2508
|
+
const digest = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
|
|
2509
|
+
const cid = specs.version === 0 ? _CID.createV0(digest) : _CID.createV1(specs.codec, digest);
|
|
2510
|
+
return [cid, bytes.subarray(specs.size)];
|
|
2511
|
+
}
|
|
2512
|
+
/**
|
|
2513
|
+
* Inspect the initial bytes of a CID to determine its properties.
|
|
2514
|
+
*
|
|
2515
|
+
* Involves decoding up to 4 varints. Typically this will require only 4 to 6
|
|
2516
|
+
* bytes but for larger multicodec code values and larger multihash digest
|
|
2517
|
+
* lengths these varints can be quite large. It is recommended that at least
|
|
2518
|
+
* 10 bytes be made available in the `initialBytes` argument for a complete
|
|
2519
|
+
* inspection.
|
|
2520
|
+
*/
|
|
2521
|
+
static inspectBytes(initialBytes) {
|
|
2522
|
+
let offset = 0;
|
|
2523
|
+
const next = () => {
|
|
2524
|
+
const [i, length2] = decode4(initialBytes.subarray(offset));
|
|
2525
|
+
offset += length2;
|
|
2526
|
+
return i;
|
|
2527
|
+
};
|
|
2528
|
+
let version = next();
|
|
2529
|
+
let codec = DAG_PB_CODE;
|
|
2530
|
+
if (version === 18) {
|
|
2531
|
+
version = 0;
|
|
2532
|
+
offset = 0;
|
|
2533
|
+
} else {
|
|
2534
|
+
codec = next();
|
|
2535
|
+
}
|
|
2536
|
+
if (version !== 0 && version !== 1) {
|
|
2537
|
+
throw new RangeError(`Invalid CID version ${version}`);
|
|
2538
|
+
}
|
|
2539
|
+
const prefixSize = offset;
|
|
2540
|
+
const multihashCode = next();
|
|
2541
|
+
const digestSize = next();
|
|
2542
|
+
const size = offset + digestSize;
|
|
2543
|
+
const multihashSize = size - prefixSize;
|
|
2544
|
+
return { version, codec, multihashCode, digestSize, multihashSize, size };
|
|
2545
|
+
}
|
|
2546
|
+
/**
|
|
2547
|
+
* Takes cid in a string representation and creates an instance. If `base`
|
|
2548
|
+
* decoder is not provided will use a default from the configuration. It will
|
|
2549
|
+
* throw an error if encoding of the CID is not compatible with supplied (or
|
|
2550
|
+
* a default decoder).
|
|
2551
|
+
*/
|
|
2552
|
+
static parse(source, base3) {
|
|
2553
|
+
const [prefix, bytes] = parseCIDtoBytes(source, base3);
|
|
2554
|
+
const cid = _CID.decode(bytes);
|
|
2555
|
+
if (cid.version === 0 && source[0] !== "Q") {
|
|
2556
|
+
throw Error("Version 0 CID string must not include multibase prefix");
|
|
2557
|
+
}
|
|
2558
|
+
baseCache(cid).set(prefix, source);
|
|
2559
|
+
return cid;
|
|
2560
|
+
}
|
|
2561
|
+
};
|
|
2562
|
+
function parseCIDtoBytes(source, base3) {
|
|
2563
|
+
switch (source[0]) {
|
|
2564
|
+
// CIDv0 is parsed differently
|
|
2565
|
+
case "Q": {
|
|
2566
|
+
const decoder = base3 ?? base58btc;
|
|
2567
|
+
return [
|
|
2568
|
+
base58btc.prefix,
|
|
2569
|
+
decoder.decode(`${base58btc.prefix}${source}`)
|
|
2570
|
+
];
|
|
2571
|
+
}
|
|
2572
|
+
case base58btc.prefix: {
|
|
2573
|
+
const decoder = base3 ?? base58btc;
|
|
2574
|
+
return [base58btc.prefix, decoder.decode(source)];
|
|
2575
|
+
}
|
|
2576
|
+
case base32.prefix: {
|
|
2577
|
+
const decoder = base3 ?? base32;
|
|
2578
|
+
return [base32.prefix, decoder.decode(source)];
|
|
2579
|
+
}
|
|
2580
|
+
case base36.prefix: {
|
|
2581
|
+
const decoder = base3 ?? base36;
|
|
2582
|
+
return [base36.prefix, decoder.decode(source)];
|
|
2583
|
+
}
|
|
2584
|
+
default: {
|
|
2585
|
+
if (base3 == null) {
|
|
2586
|
+
throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");
|
|
2587
|
+
}
|
|
2588
|
+
return [source[0], base3.decode(source)];
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2591
|
+
}
|
|
2592
|
+
function toStringV0(bytes, cache2, base3) {
|
|
2593
|
+
const { prefix } = base3;
|
|
2594
|
+
if (prefix !== base58btc.prefix) {
|
|
2595
|
+
throw Error(`Cannot string encode V0 in ${base3.name} encoding`);
|
|
2596
|
+
}
|
|
2597
|
+
const cid = cache2.get(prefix);
|
|
2598
|
+
if (cid == null) {
|
|
2599
|
+
const cid2 = base3.encode(bytes).slice(1);
|
|
2600
|
+
cache2.set(prefix, cid2);
|
|
2601
|
+
return cid2;
|
|
2602
|
+
} else {
|
|
2603
|
+
return cid;
|
|
2604
|
+
}
|
|
2605
|
+
}
|
|
2606
|
+
function toStringV1(bytes, cache2, base3) {
|
|
2607
|
+
const { prefix } = base3;
|
|
2608
|
+
const cid = cache2.get(prefix);
|
|
2609
|
+
if (cid == null) {
|
|
2610
|
+
const cid2 = base3.encode(bytes);
|
|
2611
|
+
cache2.set(prefix, cid2);
|
|
2612
|
+
return cid2;
|
|
2613
|
+
} else {
|
|
2614
|
+
return cid;
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
var DAG_PB_CODE = 112;
|
|
2618
|
+
var SHA_256_CODE = 18;
|
|
2619
|
+
function encodeCID(version, code, multihash) {
|
|
2620
|
+
const codeOffset = encodingLength(version);
|
|
2621
|
+
const hashOffset = codeOffset + encodingLength(code);
|
|
2622
|
+
const bytes = new Uint8Array(hashOffset + multihash.byteLength);
|
|
2623
|
+
encodeTo(version, bytes, 0);
|
|
2624
|
+
encodeTo(code, bytes, codeOffset);
|
|
2625
|
+
bytes.set(multihash, hashOffset);
|
|
2626
|
+
return bytes;
|
|
2627
|
+
}
|
|
2628
|
+
var cidSymbol = Symbol.for("@ipld/js-cid/CID");
|
|
2629
|
+
|
|
2630
|
+
// ../../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/utils.js
|
|
2631
|
+
function isBytes(a) {
|
|
2632
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
2633
|
+
}
|
|
2634
|
+
function anumber(n, title = "") {
|
|
2635
|
+
if (!Number.isSafeInteger(n) || n < 0) {
|
|
2636
|
+
const prefix = title && `"${title}" `;
|
|
2637
|
+
throw new Error(`${prefix}expected integer >= 0, got ${n}`);
|
|
2638
|
+
}
|
|
2639
|
+
}
|
|
2640
|
+
function abytes(value, length2, title = "") {
|
|
2641
|
+
const bytes = isBytes(value);
|
|
2642
|
+
const len = value?.length;
|
|
2643
|
+
const needsLen = length2 !== void 0;
|
|
2644
|
+
if (!bytes || needsLen && len !== length2) {
|
|
2645
|
+
const prefix = title && `"${title}" `;
|
|
2646
|
+
const ofLen = needsLen ? ` of length ${length2}` : "";
|
|
2647
|
+
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
2648
|
+
throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
2649
|
+
}
|
|
2650
|
+
return value;
|
|
2651
|
+
}
|
|
2652
|
+
function ahash(h) {
|
|
2653
|
+
if (typeof h !== "function" || typeof h.create !== "function")
|
|
2654
|
+
throw new Error("Hash must wrapped by utils.createHasher");
|
|
2655
|
+
anumber(h.outputLen);
|
|
2656
|
+
anumber(h.blockLen);
|
|
2657
|
+
}
|
|
2658
|
+
function aexists(instance, checkFinished = true) {
|
|
2659
|
+
if (instance.destroyed)
|
|
2660
|
+
throw new Error("Hash instance has been destroyed");
|
|
2661
|
+
if (checkFinished && instance.finished)
|
|
2662
|
+
throw new Error("Hash#digest() has already been called");
|
|
2663
|
+
}
|
|
2664
|
+
function aoutput(out, instance) {
|
|
2665
|
+
abytes(out, void 0, "digestInto() output");
|
|
2666
|
+
const min = instance.outputLen;
|
|
2667
|
+
if (out.length < min) {
|
|
2668
|
+
throw new Error('"digestInto() output" expected to be of length >=' + min);
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
function clean(...arrays) {
|
|
2672
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
2673
|
+
arrays[i].fill(0);
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
function createView(arr) {
|
|
2677
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
2678
|
+
}
|
|
2679
|
+
function rotr(word, shift) {
|
|
2680
|
+
return word << 32 - shift | word >>> shift;
|
|
2681
|
+
}
|
|
2682
|
+
var hasHexBuiltin = /* @__PURE__ */ (() => (
|
|
2683
|
+
// @ts-ignore
|
|
2684
|
+
typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
|
|
2685
|
+
))();
|
|
2686
|
+
var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
2687
|
+
function bytesToHex(bytes) {
|
|
2688
|
+
abytes(bytes);
|
|
2689
|
+
if (hasHexBuiltin)
|
|
2690
|
+
return bytes.toHex();
|
|
2691
|
+
let hex = "";
|
|
2692
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
2693
|
+
hex += hexes[bytes[i]];
|
|
2694
|
+
}
|
|
2695
|
+
return hex;
|
|
2696
|
+
}
|
|
2697
|
+
var asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
2698
|
+
function asciiToBase16(ch) {
|
|
2699
|
+
if (ch >= asciis._0 && ch <= asciis._9)
|
|
2700
|
+
return ch - asciis._0;
|
|
2701
|
+
if (ch >= asciis.A && ch <= asciis.F)
|
|
2702
|
+
return ch - (asciis.A - 10);
|
|
2703
|
+
if (ch >= asciis.a && ch <= asciis.f)
|
|
2704
|
+
return ch - (asciis.a - 10);
|
|
2705
|
+
return;
|
|
2706
|
+
}
|
|
2707
|
+
function hexToBytes(hex) {
|
|
2708
|
+
if (typeof hex !== "string")
|
|
2709
|
+
throw new Error("hex string expected, got " + typeof hex);
|
|
2710
|
+
if (hasHexBuiltin)
|
|
2711
|
+
return Uint8Array.fromHex(hex);
|
|
2712
|
+
const hl = hex.length;
|
|
2713
|
+
const al = hl / 2;
|
|
2714
|
+
if (hl % 2)
|
|
2715
|
+
throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
2716
|
+
const array = new Uint8Array(al);
|
|
2717
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
2718
|
+
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
2719
|
+
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
2720
|
+
if (n1 === void 0 || n2 === void 0) {
|
|
2721
|
+
const char = hex[hi] + hex[hi + 1];
|
|
2722
|
+
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
2723
|
+
}
|
|
2724
|
+
array[ai] = n1 * 16 + n2;
|
|
2725
|
+
}
|
|
2726
|
+
return array;
|
|
2727
|
+
}
|
|
2728
|
+
function concatBytes(...arrays) {
|
|
2729
|
+
let sum = 0;
|
|
2730
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
2731
|
+
const a = arrays[i];
|
|
2732
|
+
abytes(a);
|
|
2733
|
+
sum += a.length;
|
|
2734
|
+
}
|
|
2735
|
+
const res = new Uint8Array(sum);
|
|
2736
|
+
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
2737
|
+
const a = arrays[i];
|
|
2738
|
+
res.set(a, pad);
|
|
2739
|
+
pad += a.length;
|
|
2740
|
+
}
|
|
2741
|
+
return res;
|
|
2742
|
+
}
|
|
2743
|
+
function createHasher(hashCons, info = {}) {
|
|
2744
|
+
const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
|
|
2745
|
+
const tmp = hashCons(void 0);
|
|
2746
|
+
hashC.outputLen = tmp.outputLen;
|
|
2747
|
+
hashC.blockLen = tmp.blockLen;
|
|
2748
|
+
hashC.create = (opts) => hashCons(opts);
|
|
2749
|
+
Object.assign(hashC, info);
|
|
2750
|
+
return Object.freeze(hashC);
|
|
2751
|
+
}
|
|
2752
|
+
function randomBytes(bytesLength = 32) {
|
|
2753
|
+
const cr = typeof globalThis === "object" ? globalThis.crypto : null;
|
|
2754
|
+
if (typeof cr?.getRandomValues !== "function")
|
|
2755
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
2756
|
+
return cr.getRandomValues(new Uint8Array(bytesLength));
|
|
2757
|
+
}
|
|
2758
|
+
var oidNist = (suffix) => ({
|
|
2759
|
+
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
|
|
2760
|
+
});
|
|
2761
|
+
|
|
2762
|
+
// ../../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/_md.js
|
|
2763
|
+
function Chi(a, b, c) {
|
|
2764
|
+
return a & b ^ ~a & c;
|
|
2765
|
+
}
|
|
2766
|
+
function Maj(a, b, c) {
|
|
2767
|
+
return a & b ^ a & c ^ b & c;
|
|
2768
|
+
}
|
|
2769
|
+
var HashMD = class {
|
|
2770
|
+
blockLen;
|
|
2771
|
+
outputLen;
|
|
2772
|
+
padOffset;
|
|
2773
|
+
isLE;
|
|
2774
|
+
// For partial updates less than block size
|
|
2775
|
+
buffer;
|
|
2776
|
+
view;
|
|
2777
|
+
finished = false;
|
|
2778
|
+
length = 0;
|
|
2779
|
+
pos = 0;
|
|
2780
|
+
destroyed = false;
|
|
2781
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
2782
|
+
this.blockLen = blockLen;
|
|
2783
|
+
this.outputLen = outputLen;
|
|
2784
|
+
this.padOffset = padOffset;
|
|
2785
|
+
this.isLE = isLE;
|
|
2786
|
+
this.buffer = new Uint8Array(blockLen);
|
|
2787
|
+
this.view = createView(this.buffer);
|
|
2788
|
+
}
|
|
2789
|
+
update(data) {
|
|
2790
|
+
aexists(this);
|
|
2791
|
+
abytes(data);
|
|
2792
|
+
const { view, buffer: buffer2, blockLen } = this;
|
|
2793
|
+
const len = data.length;
|
|
2794
|
+
for (let pos = 0; pos < len; ) {
|
|
2795
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
2796
|
+
if (take === blockLen) {
|
|
2797
|
+
const dataView2 = createView(data);
|
|
2798
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
2799
|
+
this.process(dataView2, pos);
|
|
2800
|
+
continue;
|
|
2801
|
+
}
|
|
2802
|
+
buffer2.set(data.subarray(pos, pos + take), this.pos);
|
|
2803
|
+
this.pos += take;
|
|
2804
|
+
pos += take;
|
|
2805
|
+
if (this.pos === blockLen) {
|
|
2806
|
+
this.process(view, 0);
|
|
2807
|
+
this.pos = 0;
|
|
2808
|
+
}
|
|
2809
|
+
}
|
|
2810
|
+
this.length += data.length;
|
|
2811
|
+
this.roundClean();
|
|
2812
|
+
return this;
|
|
2813
|
+
}
|
|
2814
|
+
digestInto(out) {
|
|
2815
|
+
aexists(this);
|
|
2816
|
+
aoutput(out, this);
|
|
2817
|
+
this.finished = true;
|
|
2818
|
+
const { buffer: buffer2, view, blockLen, isLE } = this;
|
|
2819
|
+
let { pos } = this;
|
|
2820
|
+
buffer2[pos++] = 128;
|
|
2821
|
+
clean(this.buffer.subarray(pos));
|
|
2822
|
+
if (this.padOffset > blockLen - pos) {
|
|
2823
|
+
this.process(view, 0);
|
|
2824
|
+
pos = 0;
|
|
2825
|
+
}
|
|
2826
|
+
for (let i = pos; i < blockLen; i++)
|
|
2827
|
+
buffer2[i] = 0;
|
|
2828
|
+
view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE);
|
|
2829
|
+
this.process(view, 0);
|
|
2830
|
+
const oview = createView(out);
|
|
2831
|
+
const len = this.outputLen;
|
|
2832
|
+
if (len % 4)
|
|
2833
|
+
throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
2834
|
+
const outLen = len / 4;
|
|
2835
|
+
const state = this.get();
|
|
2836
|
+
if (outLen > state.length)
|
|
2837
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
2838
|
+
for (let i = 0; i < outLen; i++)
|
|
2839
|
+
oview.setUint32(4 * i, state[i], isLE);
|
|
2840
|
+
}
|
|
2841
|
+
digest() {
|
|
2842
|
+
const { buffer: buffer2, outputLen } = this;
|
|
2843
|
+
this.digestInto(buffer2);
|
|
2844
|
+
const res = buffer2.slice(0, outputLen);
|
|
2845
|
+
this.destroy();
|
|
2846
|
+
return res;
|
|
2847
|
+
}
|
|
2848
|
+
_cloneInto(to) {
|
|
2849
|
+
to ||= new this.constructor();
|
|
2850
|
+
to.set(...this.get());
|
|
2851
|
+
const { blockLen, buffer: buffer2, length: length2, finished, destroyed, pos } = this;
|
|
2852
|
+
to.destroyed = destroyed;
|
|
2853
|
+
to.finished = finished;
|
|
2854
|
+
to.length = length2;
|
|
2855
|
+
to.pos = pos;
|
|
2856
|
+
if (length2 % blockLen)
|
|
2857
|
+
to.buffer.set(buffer2);
|
|
2858
|
+
return to;
|
|
2859
|
+
}
|
|
2860
|
+
clone() {
|
|
2861
|
+
return this._cloneInto();
|
|
2862
|
+
}
|
|
2863
|
+
};
|
|
2864
|
+
var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
2865
|
+
1779033703,
|
|
2866
|
+
3144134277,
|
|
2867
|
+
1013904242,
|
|
2868
|
+
2773480762,
|
|
2869
|
+
1359893119,
|
|
2870
|
+
2600822924,
|
|
2871
|
+
528734635,
|
|
2872
|
+
1541459225
|
|
2873
|
+
]);
|
|
2874
|
+
var SHA512_IV = /* @__PURE__ */ Uint32Array.from([
|
|
2875
|
+
1779033703,
|
|
2876
|
+
4089235720,
|
|
2877
|
+
3144134277,
|
|
2878
|
+
2227873595,
|
|
2879
|
+
1013904242,
|
|
2880
|
+
4271175723,
|
|
2881
|
+
2773480762,
|
|
2882
|
+
1595750129,
|
|
2883
|
+
1359893119,
|
|
2884
|
+
2917565137,
|
|
2885
|
+
2600822924,
|
|
2886
|
+
725511199,
|
|
2887
|
+
528734635,
|
|
2888
|
+
4215389547,
|
|
2889
|
+
1541459225,
|
|
2890
|
+
327033209
|
|
2891
|
+
]);
|
|
2892
|
+
|
|
2893
|
+
// ../../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/_u64.js
|
|
2894
|
+
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
2895
|
+
var _32n = /* @__PURE__ */ BigInt(32);
|
|
2896
|
+
function fromBig(n, le = false) {
|
|
2897
|
+
if (le)
|
|
2898
|
+
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
2899
|
+
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
2900
|
+
}
|
|
2901
|
+
function split(lst, le = false) {
|
|
2902
|
+
const len = lst.length;
|
|
2903
|
+
let Ah = new Uint32Array(len);
|
|
2904
|
+
let Al = new Uint32Array(len);
|
|
2905
|
+
for (let i = 0; i < len; i++) {
|
|
2906
|
+
const { h, l } = fromBig(lst[i], le);
|
|
2907
|
+
[Ah[i], Al[i]] = [h, l];
|
|
2908
|
+
}
|
|
2909
|
+
return [Ah, Al];
|
|
2910
|
+
}
|
|
2911
|
+
var shrSH = (h, _l, s) => h >>> s;
|
|
2912
|
+
var shrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
2913
|
+
var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
|
|
2914
|
+
var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
2915
|
+
var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
2916
|
+
var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
2917
|
+
function add(Ah, Al, Bh, Bl2) {
|
|
2918
|
+
const l = (Al >>> 0) + (Bl2 >>> 0);
|
|
2919
|
+
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
2920
|
+
}
|
|
2921
|
+
var add3L = (Al, Bl2, Cl) => (Al >>> 0) + (Bl2 >>> 0) + (Cl >>> 0);
|
|
2922
|
+
var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
2923
|
+
var add4L = (Al, Bl2, Cl, Dl) => (Al >>> 0) + (Bl2 >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
2924
|
+
var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
2925
|
+
var add5L = (Al, Bl2, Cl, Dl, El) => (Al >>> 0) + (Bl2 >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
2926
|
+
var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
2927
|
+
|
|
2928
|
+
// ../../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/sha2.js
|
|
2929
|
+
var SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
2930
|
+
1116352408,
|
|
2931
|
+
1899447441,
|
|
2932
|
+
3049323471,
|
|
2933
|
+
3921009573,
|
|
2934
|
+
961987163,
|
|
2935
|
+
1508970993,
|
|
2936
|
+
2453635748,
|
|
2937
|
+
2870763221,
|
|
2938
|
+
3624381080,
|
|
2939
|
+
310598401,
|
|
2940
|
+
607225278,
|
|
2941
|
+
1426881987,
|
|
2942
|
+
1925078388,
|
|
2943
|
+
2162078206,
|
|
2944
|
+
2614888103,
|
|
2945
|
+
3248222580,
|
|
2946
|
+
3835390401,
|
|
2947
|
+
4022224774,
|
|
2948
|
+
264347078,
|
|
2949
|
+
604807628,
|
|
2950
|
+
770255983,
|
|
2951
|
+
1249150122,
|
|
2952
|
+
1555081692,
|
|
2953
|
+
1996064986,
|
|
2954
|
+
2554220882,
|
|
2955
|
+
2821834349,
|
|
2956
|
+
2952996808,
|
|
2957
|
+
3210313671,
|
|
2958
|
+
3336571891,
|
|
2959
|
+
3584528711,
|
|
2960
|
+
113926993,
|
|
2961
|
+
338241895,
|
|
2962
|
+
666307205,
|
|
2963
|
+
773529912,
|
|
2964
|
+
1294757372,
|
|
2965
|
+
1396182291,
|
|
2966
|
+
1695183700,
|
|
2967
|
+
1986661051,
|
|
2968
|
+
2177026350,
|
|
2969
|
+
2456956037,
|
|
2970
|
+
2730485921,
|
|
2971
|
+
2820302411,
|
|
2972
|
+
3259730800,
|
|
2973
|
+
3345764771,
|
|
2974
|
+
3516065817,
|
|
2975
|
+
3600352804,
|
|
2976
|
+
4094571909,
|
|
2977
|
+
275423344,
|
|
2978
|
+
430227734,
|
|
2979
|
+
506948616,
|
|
2980
|
+
659060556,
|
|
2981
|
+
883997877,
|
|
2982
|
+
958139571,
|
|
2983
|
+
1322822218,
|
|
2984
|
+
1537002063,
|
|
2985
|
+
1747873779,
|
|
2986
|
+
1955562222,
|
|
2987
|
+
2024104815,
|
|
2988
|
+
2227730452,
|
|
2989
|
+
2361852424,
|
|
2990
|
+
2428436474,
|
|
2991
|
+
2756734187,
|
|
2992
|
+
3204031479,
|
|
2993
|
+
3329325298
|
|
2994
|
+
]);
|
|
2995
|
+
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
2996
|
+
var SHA2_32B = class extends HashMD {
|
|
2997
|
+
constructor(outputLen) {
|
|
2998
|
+
super(64, outputLen, 8, false);
|
|
2999
|
+
}
|
|
3000
|
+
get() {
|
|
3001
|
+
const { A, B, C, D, E, F, G, H } = this;
|
|
3002
|
+
return [A, B, C, D, E, F, G, H];
|
|
3003
|
+
}
|
|
3004
|
+
// prettier-ignore
|
|
3005
|
+
set(A, B, C, D, E, F, G, H) {
|
|
3006
|
+
this.A = A | 0;
|
|
3007
|
+
this.B = B | 0;
|
|
3008
|
+
this.C = C | 0;
|
|
3009
|
+
this.D = D | 0;
|
|
3010
|
+
this.E = E | 0;
|
|
3011
|
+
this.F = F | 0;
|
|
3012
|
+
this.G = G | 0;
|
|
3013
|
+
this.H = H | 0;
|
|
3014
|
+
}
|
|
3015
|
+
process(view, offset) {
|
|
3016
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
|
3017
|
+
SHA256_W[i] = view.getUint32(offset, false);
|
|
3018
|
+
for (let i = 16; i < 64; i++) {
|
|
3019
|
+
const W15 = SHA256_W[i - 15];
|
|
3020
|
+
const W2 = SHA256_W[i - 2];
|
|
3021
|
+
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
3022
|
+
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
3023
|
+
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
3024
|
+
}
|
|
3025
|
+
let { A, B, C, D, E, F, G, H } = this;
|
|
3026
|
+
for (let i = 0; i < 64; i++) {
|
|
3027
|
+
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
3028
|
+
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
3029
|
+
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
3030
|
+
const T2 = sigma0 + Maj(A, B, C) | 0;
|
|
3031
|
+
H = G;
|
|
3032
|
+
G = F;
|
|
3033
|
+
F = E;
|
|
3034
|
+
E = D + T1 | 0;
|
|
3035
|
+
D = C;
|
|
3036
|
+
C = B;
|
|
3037
|
+
B = A;
|
|
3038
|
+
A = T1 + T2 | 0;
|
|
3039
|
+
}
|
|
3040
|
+
A = A + this.A | 0;
|
|
3041
|
+
B = B + this.B | 0;
|
|
3042
|
+
C = C + this.C | 0;
|
|
3043
|
+
D = D + this.D | 0;
|
|
3044
|
+
E = E + this.E | 0;
|
|
3045
|
+
F = F + this.F | 0;
|
|
3046
|
+
G = G + this.G | 0;
|
|
3047
|
+
H = H + this.H | 0;
|
|
3048
|
+
this.set(A, B, C, D, E, F, G, H);
|
|
3049
|
+
}
|
|
3050
|
+
roundClean() {
|
|
3051
|
+
clean(SHA256_W);
|
|
3052
|
+
}
|
|
3053
|
+
destroy() {
|
|
3054
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
3055
|
+
clean(this.buffer);
|
|
3056
|
+
}
|
|
3057
|
+
};
|
|
3058
|
+
var _SHA256 = class extends SHA2_32B {
|
|
3059
|
+
// We cannot use array here since array allows indexing by variable
|
|
3060
|
+
// which means optimizer/compiler cannot use registers.
|
|
3061
|
+
A = SHA256_IV[0] | 0;
|
|
3062
|
+
B = SHA256_IV[1] | 0;
|
|
3063
|
+
C = SHA256_IV[2] | 0;
|
|
3064
|
+
D = SHA256_IV[3] | 0;
|
|
3065
|
+
E = SHA256_IV[4] | 0;
|
|
3066
|
+
F = SHA256_IV[5] | 0;
|
|
3067
|
+
G = SHA256_IV[6] | 0;
|
|
3068
|
+
H = SHA256_IV[7] | 0;
|
|
3069
|
+
constructor() {
|
|
3070
|
+
super(32);
|
|
3071
|
+
}
|
|
3072
|
+
};
|
|
3073
|
+
var K512 = /* @__PURE__ */ (() => split([
|
|
3074
|
+
"0x428a2f98d728ae22",
|
|
3075
|
+
"0x7137449123ef65cd",
|
|
3076
|
+
"0xb5c0fbcfec4d3b2f",
|
|
3077
|
+
"0xe9b5dba58189dbbc",
|
|
3078
|
+
"0x3956c25bf348b538",
|
|
3079
|
+
"0x59f111f1b605d019",
|
|
3080
|
+
"0x923f82a4af194f9b",
|
|
3081
|
+
"0xab1c5ed5da6d8118",
|
|
3082
|
+
"0xd807aa98a3030242",
|
|
3083
|
+
"0x12835b0145706fbe",
|
|
3084
|
+
"0x243185be4ee4b28c",
|
|
3085
|
+
"0x550c7dc3d5ffb4e2",
|
|
3086
|
+
"0x72be5d74f27b896f",
|
|
3087
|
+
"0x80deb1fe3b1696b1",
|
|
3088
|
+
"0x9bdc06a725c71235",
|
|
3089
|
+
"0xc19bf174cf692694",
|
|
3090
|
+
"0xe49b69c19ef14ad2",
|
|
3091
|
+
"0xefbe4786384f25e3",
|
|
3092
|
+
"0x0fc19dc68b8cd5b5",
|
|
3093
|
+
"0x240ca1cc77ac9c65",
|
|
3094
|
+
"0x2de92c6f592b0275",
|
|
3095
|
+
"0x4a7484aa6ea6e483",
|
|
3096
|
+
"0x5cb0a9dcbd41fbd4",
|
|
3097
|
+
"0x76f988da831153b5",
|
|
3098
|
+
"0x983e5152ee66dfab",
|
|
3099
|
+
"0xa831c66d2db43210",
|
|
3100
|
+
"0xb00327c898fb213f",
|
|
3101
|
+
"0xbf597fc7beef0ee4",
|
|
3102
|
+
"0xc6e00bf33da88fc2",
|
|
3103
|
+
"0xd5a79147930aa725",
|
|
3104
|
+
"0x06ca6351e003826f",
|
|
3105
|
+
"0x142929670a0e6e70",
|
|
3106
|
+
"0x27b70a8546d22ffc",
|
|
3107
|
+
"0x2e1b21385c26c926",
|
|
3108
|
+
"0x4d2c6dfc5ac42aed",
|
|
3109
|
+
"0x53380d139d95b3df",
|
|
3110
|
+
"0x650a73548baf63de",
|
|
3111
|
+
"0x766a0abb3c77b2a8",
|
|
3112
|
+
"0x81c2c92e47edaee6",
|
|
3113
|
+
"0x92722c851482353b",
|
|
3114
|
+
"0xa2bfe8a14cf10364",
|
|
3115
|
+
"0xa81a664bbc423001",
|
|
3116
|
+
"0xc24b8b70d0f89791",
|
|
3117
|
+
"0xc76c51a30654be30",
|
|
3118
|
+
"0xd192e819d6ef5218",
|
|
3119
|
+
"0xd69906245565a910",
|
|
3120
|
+
"0xf40e35855771202a",
|
|
3121
|
+
"0x106aa07032bbd1b8",
|
|
3122
|
+
"0x19a4c116b8d2d0c8",
|
|
3123
|
+
"0x1e376c085141ab53",
|
|
3124
|
+
"0x2748774cdf8eeb99",
|
|
3125
|
+
"0x34b0bcb5e19b48a8",
|
|
3126
|
+
"0x391c0cb3c5c95a63",
|
|
3127
|
+
"0x4ed8aa4ae3418acb",
|
|
3128
|
+
"0x5b9cca4f7763e373",
|
|
3129
|
+
"0x682e6ff3d6b2b8a3",
|
|
3130
|
+
"0x748f82ee5defb2fc",
|
|
3131
|
+
"0x78a5636f43172f60",
|
|
3132
|
+
"0x84c87814a1f0ab72",
|
|
3133
|
+
"0x8cc702081a6439ec",
|
|
3134
|
+
"0x90befffa23631e28",
|
|
3135
|
+
"0xa4506cebde82bde9",
|
|
3136
|
+
"0xbef9a3f7b2c67915",
|
|
3137
|
+
"0xc67178f2e372532b",
|
|
3138
|
+
"0xca273eceea26619c",
|
|
3139
|
+
"0xd186b8c721c0c207",
|
|
3140
|
+
"0xeada7dd6cde0eb1e",
|
|
3141
|
+
"0xf57d4f7fee6ed178",
|
|
3142
|
+
"0x06f067aa72176fba",
|
|
3143
|
+
"0x0a637dc5a2c898a6",
|
|
3144
|
+
"0x113f9804bef90dae",
|
|
3145
|
+
"0x1b710b35131c471b",
|
|
3146
|
+
"0x28db77f523047d84",
|
|
3147
|
+
"0x32caab7b40c72493",
|
|
3148
|
+
"0x3c9ebe0a15c9bebc",
|
|
3149
|
+
"0x431d67c49c100d4c",
|
|
3150
|
+
"0x4cc5d4becb3e42b6",
|
|
3151
|
+
"0x597f299cfc657e2a",
|
|
3152
|
+
"0x5fcb6fab3ad6faec",
|
|
3153
|
+
"0x6c44198c4a475817"
|
|
3154
|
+
].map((n) => BigInt(n))))();
|
|
3155
|
+
var SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
|
|
3156
|
+
var SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
|
|
3157
|
+
var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
3158
|
+
var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
3159
|
+
var SHA2_64B = class extends HashMD {
|
|
3160
|
+
constructor(outputLen) {
|
|
3161
|
+
super(128, outputLen, 16, false);
|
|
3162
|
+
}
|
|
3163
|
+
// prettier-ignore
|
|
3164
|
+
get() {
|
|
3165
|
+
const { Ah, Al, Bh, Bl: Bl2, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
3166
|
+
return [Ah, Al, Bh, Bl2, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
|
|
3167
|
+
}
|
|
3168
|
+
// prettier-ignore
|
|
3169
|
+
set(Ah, Al, Bh, Bl2, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
3170
|
+
this.Ah = Ah | 0;
|
|
3171
|
+
this.Al = Al | 0;
|
|
3172
|
+
this.Bh = Bh | 0;
|
|
3173
|
+
this.Bl = Bl2 | 0;
|
|
3174
|
+
this.Ch = Ch | 0;
|
|
3175
|
+
this.Cl = Cl | 0;
|
|
3176
|
+
this.Dh = Dh | 0;
|
|
3177
|
+
this.Dl = Dl | 0;
|
|
3178
|
+
this.Eh = Eh | 0;
|
|
3179
|
+
this.El = El | 0;
|
|
3180
|
+
this.Fh = Fh | 0;
|
|
3181
|
+
this.Fl = Fl | 0;
|
|
3182
|
+
this.Gh = Gh | 0;
|
|
3183
|
+
this.Gl = Gl | 0;
|
|
3184
|
+
this.Hh = Hh | 0;
|
|
3185
|
+
this.Hl = Hl | 0;
|
|
3186
|
+
}
|
|
3187
|
+
process(view, offset) {
|
|
3188
|
+
for (let i = 0; i < 16; i++, offset += 4) {
|
|
3189
|
+
SHA512_W_H[i] = view.getUint32(offset);
|
|
3190
|
+
SHA512_W_L[i] = view.getUint32(offset += 4);
|
|
3191
|
+
}
|
|
3192
|
+
for (let i = 16; i < 80; i++) {
|
|
3193
|
+
const W15h = SHA512_W_H[i - 15] | 0;
|
|
3194
|
+
const W15l = SHA512_W_L[i - 15] | 0;
|
|
3195
|
+
const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
|
|
3196
|
+
const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
|
|
3197
|
+
const W2h = SHA512_W_H[i - 2] | 0;
|
|
3198
|
+
const W2l = SHA512_W_L[i - 2] | 0;
|
|
3199
|
+
const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
|
|
3200
|
+
const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
|
|
3201
|
+
const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
|
|
3202
|
+
const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
|
|
3203
|
+
SHA512_W_H[i] = SUMh | 0;
|
|
3204
|
+
SHA512_W_L[i] = SUMl | 0;
|
|
3205
|
+
}
|
|
3206
|
+
let { Ah, Al, Bh, Bl: Bl2, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
3207
|
+
for (let i = 0; i < 80; i++) {
|
|
3208
|
+
const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
|
|
3209
|
+
const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
|
|
3210
|
+
const CHIh = Eh & Fh ^ ~Eh & Gh;
|
|
3211
|
+
const CHIl = El & Fl ^ ~El & Gl;
|
|
3212
|
+
const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
|
|
3213
|
+
const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
|
|
3214
|
+
const T1l = T1ll | 0;
|
|
3215
|
+
const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
|
|
3216
|
+
const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
|
|
3217
|
+
const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
|
|
3218
|
+
const MAJl = Al & Bl2 ^ Al & Cl ^ Bl2 & Cl;
|
|
3219
|
+
Hh = Gh | 0;
|
|
3220
|
+
Hl = Gl | 0;
|
|
3221
|
+
Gh = Fh | 0;
|
|
3222
|
+
Gl = Fl | 0;
|
|
3223
|
+
Fh = Eh | 0;
|
|
3224
|
+
Fl = El | 0;
|
|
3225
|
+
({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
3226
|
+
Dh = Ch | 0;
|
|
3227
|
+
Dl = Cl | 0;
|
|
3228
|
+
Ch = Bh | 0;
|
|
3229
|
+
Cl = Bl2 | 0;
|
|
3230
|
+
Bh = Ah | 0;
|
|
3231
|
+
Bl2 = Al | 0;
|
|
3232
|
+
const All = add3L(T1l, sigma0l, MAJl);
|
|
3233
|
+
Ah = add3H(All, T1h, sigma0h, MAJh);
|
|
3234
|
+
Al = All | 0;
|
|
3235
|
+
}
|
|
3236
|
+
({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
3237
|
+
({ h: Bh, l: Bl2 } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl2 | 0));
|
|
3238
|
+
({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
3239
|
+
({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
3240
|
+
({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
3241
|
+
({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
3242
|
+
({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
3243
|
+
({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
3244
|
+
this.set(Ah, Al, Bh, Bl2, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
3245
|
+
}
|
|
3246
|
+
roundClean() {
|
|
3247
|
+
clean(SHA512_W_H, SHA512_W_L);
|
|
3248
|
+
}
|
|
3249
|
+
destroy() {
|
|
3250
|
+
clean(this.buffer);
|
|
3251
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
3252
|
+
}
|
|
3253
|
+
};
|
|
3254
|
+
var _SHA512 = class extends SHA2_64B {
|
|
3255
|
+
Ah = SHA512_IV[0] | 0;
|
|
3256
|
+
Al = SHA512_IV[1] | 0;
|
|
3257
|
+
Bh = SHA512_IV[2] | 0;
|
|
3258
|
+
Bl = SHA512_IV[3] | 0;
|
|
3259
|
+
Ch = SHA512_IV[4] | 0;
|
|
3260
|
+
Cl = SHA512_IV[5] | 0;
|
|
3261
|
+
Dh = SHA512_IV[6] | 0;
|
|
3262
|
+
Dl = SHA512_IV[7] | 0;
|
|
3263
|
+
Eh = SHA512_IV[8] | 0;
|
|
3264
|
+
El = SHA512_IV[9] | 0;
|
|
3265
|
+
Fh = SHA512_IV[10] | 0;
|
|
3266
|
+
Fl = SHA512_IV[11] | 0;
|
|
3267
|
+
Gh = SHA512_IV[12] | 0;
|
|
3268
|
+
Gl = SHA512_IV[13] | 0;
|
|
3269
|
+
Hh = SHA512_IV[14] | 0;
|
|
3270
|
+
Hl = SHA512_IV[15] | 0;
|
|
3271
|
+
constructor() {
|
|
3272
|
+
super(64);
|
|
3273
|
+
}
|
|
3274
|
+
};
|
|
3275
|
+
var sha256 = /* @__PURE__ */ createHasher(
|
|
3276
|
+
() => new _SHA256(),
|
|
3277
|
+
/* @__PURE__ */ oidNist(1)
|
|
3278
|
+
);
|
|
3279
|
+
var sha512 = /* @__PURE__ */ createHasher(
|
|
3280
|
+
() => new _SHA512(),
|
|
3281
|
+
/* @__PURE__ */ oidNist(3)
|
|
3282
|
+
);
|
|
3283
|
+
|
|
3284
|
+
// ../../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/bytes.js
|
|
3285
|
+
var empty2 = new Uint8Array(0);
|
|
3286
|
+
function equals3(aa, bb) {
|
|
3287
|
+
if (aa === bb) {
|
|
3288
|
+
return true;
|
|
3289
|
+
}
|
|
3290
|
+
if (aa.byteLength !== bb.byteLength) {
|
|
3291
|
+
return false;
|
|
3292
|
+
}
|
|
3293
|
+
for (let ii = 0; ii < aa.byteLength; ii++) {
|
|
3294
|
+
if (aa[ii] !== bb[ii]) {
|
|
3295
|
+
return false;
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
return true;
|
|
3299
|
+
}
|
|
3300
|
+
function coerce2(o) {
|
|
3301
|
+
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") {
|
|
3302
|
+
return o;
|
|
3303
|
+
}
|
|
3304
|
+
if (o instanceof ArrayBuffer) {
|
|
3305
|
+
return new Uint8Array(o);
|
|
3306
|
+
}
|
|
3307
|
+
if (ArrayBuffer.isView(o)) {
|
|
3308
|
+
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
3309
|
+
}
|
|
3310
|
+
throw new Error("Unknown type, must be binary type");
|
|
3311
|
+
}
|
|
3312
|
+
|
|
3313
|
+
// ../../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/vendor/base-x.js
|
|
3314
|
+
function base2(ALPHABET, name) {
|
|
3315
|
+
if (ALPHABET.length >= 255) {
|
|
3316
|
+
throw new TypeError("Alphabet too long");
|
|
3317
|
+
}
|
|
3318
|
+
var BASE_MAP = new Uint8Array(256);
|
|
3319
|
+
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
3320
|
+
BASE_MAP[j] = 255;
|
|
3321
|
+
}
|
|
3322
|
+
for (var i = 0; i < ALPHABET.length; i++) {
|
|
3323
|
+
var x = ALPHABET.charAt(i);
|
|
3324
|
+
var xc = x.charCodeAt(0);
|
|
3325
|
+
if (BASE_MAP[xc] !== 255) {
|
|
3326
|
+
throw new TypeError(x + " is ambiguous");
|
|
3327
|
+
}
|
|
3328
|
+
BASE_MAP[xc] = i;
|
|
3329
|
+
}
|
|
3330
|
+
var BASE = ALPHABET.length;
|
|
3331
|
+
var LEADER = ALPHABET.charAt(0);
|
|
3332
|
+
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
3333
|
+
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
3334
|
+
function encode5(source) {
|
|
3335
|
+
if (source instanceof Uint8Array)
|
|
3336
|
+
;
|
|
3337
|
+
else if (ArrayBuffer.isView(source)) {
|
|
3338
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
3339
|
+
} else if (Array.isArray(source)) {
|
|
3340
|
+
source = Uint8Array.from(source);
|
|
3341
|
+
}
|
|
3342
|
+
if (!(source instanceof Uint8Array)) {
|
|
3343
|
+
throw new TypeError("Expected Uint8Array");
|
|
3344
|
+
}
|
|
3345
|
+
if (source.length === 0) {
|
|
3346
|
+
return "";
|
|
3347
|
+
}
|
|
3348
|
+
var zeroes = 0;
|
|
3349
|
+
var length2 = 0;
|
|
3350
|
+
var pbegin = 0;
|
|
3351
|
+
var pend = source.length;
|
|
3352
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
3353
|
+
pbegin++;
|
|
3354
|
+
zeroes++;
|
|
3355
|
+
}
|
|
3356
|
+
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
3357
|
+
var b58 = new Uint8Array(size);
|
|
3358
|
+
while (pbegin !== pend) {
|
|
3359
|
+
var carry = source[pbegin];
|
|
3360
|
+
var i2 = 0;
|
|
3361
|
+
for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
|
|
3362
|
+
carry += 256 * b58[it1] >>> 0;
|
|
3363
|
+
b58[it1] = carry % BASE >>> 0;
|
|
3364
|
+
carry = carry / BASE >>> 0;
|
|
3365
|
+
}
|
|
3366
|
+
if (carry !== 0) {
|
|
3367
|
+
throw new Error("Non-zero carry");
|
|
3368
|
+
}
|
|
3369
|
+
length2 = i2;
|
|
3370
|
+
pbegin++;
|
|
3371
|
+
}
|
|
3372
|
+
var it2 = size - length2;
|
|
3373
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
3374
|
+
it2++;
|
|
3375
|
+
}
|
|
3376
|
+
var str = LEADER.repeat(zeroes);
|
|
3377
|
+
for (; it2 < size; ++it2) {
|
|
3378
|
+
str += ALPHABET.charAt(b58[it2]);
|
|
3379
|
+
}
|
|
3380
|
+
return str;
|
|
3381
|
+
}
|
|
3382
|
+
function decodeUnsafe(source) {
|
|
3383
|
+
if (typeof source !== "string") {
|
|
3384
|
+
throw new TypeError("Expected String");
|
|
3385
|
+
}
|
|
3386
|
+
if (source.length === 0) {
|
|
3387
|
+
return new Uint8Array();
|
|
3388
|
+
}
|
|
3389
|
+
var psz = 0;
|
|
3390
|
+
if (source[psz] === " ") {
|
|
3391
|
+
return;
|
|
3392
|
+
}
|
|
3393
|
+
var zeroes = 0;
|
|
3394
|
+
var length2 = 0;
|
|
3395
|
+
while (source[psz] === LEADER) {
|
|
3396
|
+
zeroes++;
|
|
3397
|
+
psz++;
|
|
3398
|
+
}
|
|
3399
|
+
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
3400
|
+
var b256 = new Uint8Array(size);
|
|
3401
|
+
while (source[psz]) {
|
|
3402
|
+
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
3403
|
+
if (carry === 255) {
|
|
3404
|
+
return;
|
|
3405
|
+
}
|
|
3406
|
+
var i2 = 0;
|
|
3407
|
+
for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
|
|
3408
|
+
carry += BASE * b256[it3] >>> 0;
|
|
3409
|
+
b256[it3] = carry % 256 >>> 0;
|
|
3410
|
+
carry = carry / 256 >>> 0;
|
|
3411
|
+
}
|
|
3412
|
+
if (carry !== 0) {
|
|
3413
|
+
throw new Error("Non-zero carry");
|
|
3414
|
+
}
|
|
3415
|
+
length2 = i2;
|
|
3416
|
+
psz++;
|
|
3417
|
+
}
|
|
3418
|
+
if (source[psz] === " ") {
|
|
3419
|
+
return;
|
|
3420
|
+
}
|
|
3421
|
+
var it4 = size - length2;
|
|
3422
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
3423
|
+
it4++;
|
|
3424
|
+
}
|
|
3425
|
+
var vch = new Uint8Array(zeroes + (size - it4));
|
|
3426
|
+
var j2 = zeroes;
|
|
3427
|
+
while (it4 !== size) {
|
|
3428
|
+
vch[j2++] = b256[it4++];
|
|
3429
|
+
}
|
|
3430
|
+
return vch;
|
|
3431
|
+
}
|
|
3432
|
+
function decode7(string) {
|
|
3433
|
+
var buffer2 = decodeUnsafe(string);
|
|
3434
|
+
if (buffer2) {
|
|
3435
|
+
return buffer2;
|
|
3436
|
+
}
|
|
3437
|
+
throw new Error(`Non-${name} character`);
|
|
3438
|
+
}
|
|
3439
|
+
return {
|
|
3440
|
+
encode: encode5,
|
|
3441
|
+
decodeUnsafe,
|
|
3442
|
+
decode: decode7
|
|
3443
|
+
};
|
|
3444
|
+
}
|
|
3445
|
+
var src2 = base2;
|
|
3446
|
+
var _brrp__multiformats_scope_baseX2 = src2;
|
|
3447
|
+
var base_x_default2 = _brrp__multiformats_scope_baseX2;
|
|
3448
|
+
|
|
3449
|
+
// ../../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/bases/base.js
|
|
3450
|
+
var Encoder2 = class {
|
|
3451
|
+
name;
|
|
3452
|
+
prefix;
|
|
3453
|
+
baseEncode;
|
|
3454
|
+
constructor(name, prefix, baseEncode) {
|
|
3455
|
+
this.name = name;
|
|
3456
|
+
this.prefix = prefix;
|
|
3457
|
+
this.baseEncode = baseEncode;
|
|
3458
|
+
}
|
|
3459
|
+
encode(bytes) {
|
|
3460
|
+
if (bytes instanceof Uint8Array) {
|
|
3461
|
+
return `${this.prefix}${this.baseEncode(bytes)}`;
|
|
3462
|
+
} else {
|
|
3463
|
+
throw Error("Unknown type, must be binary type");
|
|
3464
|
+
}
|
|
3465
|
+
}
|
|
3466
|
+
};
|
|
3467
|
+
var Decoder2 = class {
|
|
3468
|
+
name;
|
|
3469
|
+
prefix;
|
|
3470
|
+
baseDecode;
|
|
3471
|
+
prefixCodePoint;
|
|
3472
|
+
constructor(name, prefix, baseDecode) {
|
|
3473
|
+
this.name = name;
|
|
3474
|
+
this.prefix = prefix;
|
|
3475
|
+
const prefixCodePoint = prefix.codePointAt(0);
|
|
3476
|
+
if (prefixCodePoint === void 0) {
|
|
3477
|
+
throw new Error("Invalid prefix character");
|
|
3478
|
+
}
|
|
3479
|
+
this.prefixCodePoint = prefixCodePoint;
|
|
3480
|
+
this.baseDecode = baseDecode;
|
|
3481
|
+
}
|
|
3482
|
+
decode(text) {
|
|
3483
|
+
if (typeof text === "string") {
|
|
3484
|
+
if (text.codePointAt(0) !== this.prefixCodePoint) {
|
|
3485
|
+
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
|
|
3486
|
+
}
|
|
3487
|
+
return this.baseDecode(text.slice(this.prefix.length));
|
|
3488
|
+
} else {
|
|
3489
|
+
throw Error("Can only multibase decode strings");
|
|
3490
|
+
}
|
|
3491
|
+
}
|
|
3492
|
+
or(decoder) {
|
|
3493
|
+
return or2(this, decoder);
|
|
3494
|
+
}
|
|
3495
|
+
};
|
|
3496
|
+
var ComposedDecoder2 = class {
|
|
3497
|
+
decoders;
|
|
3498
|
+
constructor(decoders) {
|
|
3499
|
+
this.decoders = decoders;
|
|
3500
|
+
}
|
|
3501
|
+
or(decoder) {
|
|
3502
|
+
return or2(this, decoder);
|
|
3503
|
+
}
|
|
3504
|
+
decode(input) {
|
|
3505
|
+
const prefix = input[0];
|
|
3506
|
+
const decoder = this.decoders[prefix];
|
|
3507
|
+
if (decoder != null) {
|
|
3508
|
+
return decoder.decode(input);
|
|
3509
|
+
} else {
|
|
3510
|
+
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
|
|
3511
|
+
}
|
|
3512
|
+
}
|
|
3513
|
+
};
|
|
3514
|
+
function or2(left, right) {
|
|
3515
|
+
return new ComposedDecoder2({
|
|
3516
|
+
...left.decoders ?? { [left.prefix]: left },
|
|
3517
|
+
...right.decoders ?? { [right.prefix]: right }
|
|
3518
|
+
});
|
|
3519
|
+
}
|
|
3520
|
+
var Codec2 = class {
|
|
3521
|
+
name;
|
|
3522
|
+
prefix;
|
|
3523
|
+
baseEncode;
|
|
3524
|
+
baseDecode;
|
|
3525
|
+
encoder;
|
|
3526
|
+
decoder;
|
|
3527
|
+
constructor(name, prefix, baseEncode, baseDecode) {
|
|
3528
|
+
this.name = name;
|
|
3529
|
+
this.prefix = prefix;
|
|
3530
|
+
this.baseEncode = baseEncode;
|
|
3531
|
+
this.baseDecode = baseDecode;
|
|
3532
|
+
this.encoder = new Encoder2(name, prefix, baseEncode);
|
|
3533
|
+
this.decoder = new Decoder2(name, prefix, baseDecode);
|
|
3534
|
+
}
|
|
3535
|
+
encode(input) {
|
|
3536
|
+
return this.encoder.encode(input);
|
|
3537
|
+
}
|
|
3538
|
+
decode(input) {
|
|
3539
|
+
return this.decoder.decode(input);
|
|
3540
|
+
}
|
|
3541
|
+
};
|
|
3542
|
+
function from2({ name, prefix, encode: encode5, decode: decode7 }) {
|
|
3543
|
+
return new Codec2(name, prefix, encode5, decode7);
|
|
3544
|
+
}
|
|
3545
|
+
function baseX2({ name, prefix, alphabet }) {
|
|
3546
|
+
const { encode: encode5, decode: decode7 } = base_x_default2(alphabet, name);
|
|
3547
|
+
return from2({
|
|
3548
|
+
prefix,
|
|
3549
|
+
name,
|
|
3550
|
+
encode: encode5,
|
|
3551
|
+
decode: (text) => coerce2(decode7(text))
|
|
3552
|
+
});
|
|
3553
|
+
}
|
|
3554
|
+
function decode6(string, alphabetIdx, bitsPerChar, name) {
|
|
3555
|
+
let end = string.length;
|
|
3556
|
+
while (string[end - 1] === "=") {
|
|
3557
|
+
--end;
|
|
3558
|
+
}
|
|
3559
|
+
const out = new Uint8Array(end * bitsPerChar / 8 | 0);
|
|
3560
|
+
let bits = 0;
|
|
3561
|
+
let buffer2 = 0;
|
|
3562
|
+
let written = 0;
|
|
3563
|
+
for (let i = 0; i < end; ++i) {
|
|
3564
|
+
const value = alphabetIdx[string[i]];
|
|
3565
|
+
if (value === void 0) {
|
|
3566
|
+
throw new SyntaxError(`Non-${name} character`);
|
|
3567
|
+
}
|
|
3568
|
+
buffer2 = buffer2 << bitsPerChar | value;
|
|
3569
|
+
bits += bitsPerChar;
|
|
3570
|
+
if (bits >= 8) {
|
|
3571
|
+
bits -= 8;
|
|
3572
|
+
out[written++] = 255 & buffer2 >> bits;
|
|
3573
|
+
}
|
|
3574
|
+
}
|
|
3575
|
+
if (bits >= bitsPerChar || (255 & buffer2 << 8 - bits) !== 0) {
|
|
3576
|
+
throw new SyntaxError("Unexpected end of data");
|
|
3577
|
+
}
|
|
3578
|
+
return out;
|
|
3579
|
+
}
|
|
3580
|
+
function encode4(data, alphabet, bitsPerChar) {
|
|
3581
|
+
const pad = alphabet[alphabet.length - 1] === "=";
|
|
3582
|
+
const mask = (1 << bitsPerChar) - 1;
|
|
3583
|
+
let out = "";
|
|
3584
|
+
let bits = 0;
|
|
3585
|
+
let buffer2 = 0;
|
|
3586
|
+
for (let i = 0; i < data.length; ++i) {
|
|
3587
|
+
buffer2 = buffer2 << 8 | data[i];
|
|
3588
|
+
bits += 8;
|
|
3589
|
+
while (bits > bitsPerChar) {
|
|
3590
|
+
bits -= bitsPerChar;
|
|
3591
|
+
out += alphabet[mask & buffer2 >> bits];
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3594
|
+
if (bits !== 0) {
|
|
3595
|
+
out += alphabet[mask & buffer2 << bitsPerChar - bits];
|
|
3596
|
+
}
|
|
3597
|
+
if (pad) {
|
|
3598
|
+
while ((out.length * bitsPerChar & 7) !== 0) {
|
|
3599
|
+
out += "=";
|
|
3600
|
+
}
|
|
3601
|
+
}
|
|
3602
|
+
return out;
|
|
3603
|
+
}
|
|
3604
|
+
function createAlphabetIdx2(alphabet) {
|
|
3605
|
+
const alphabetIdx = {};
|
|
3606
|
+
for (let i = 0; i < alphabet.length; ++i) {
|
|
3607
|
+
alphabetIdx[alphabet[i]] = i;
|
|
3608
|
+
}
|
|
3609
|
+
return alphabetIdx;
|
|
3610
|
+
}
|
|
3611
|
+
function rfc46482({ name, prefix, bitsPerChar, alphabet }) {
|
|
3612
|
+
const alphabetIdx = createAlphabetIdx2(alphabet);
|
|
3613
|
+
return from2({
|
|
3614
|
+
prefix,
|
|
3615
|
+
name,
|
|
3616
|
+
encode(input) {
|
|
3617
|
+
return encode4(input, alphabet, bitsPerChar);
|
|
3618
|
+
},
|
|
3619
|
+
decode(input) {
|
|
3620
|
+
return decode6(input, alphabetIdx, bitsPerChar, name);
|
|
3621
|
+
}
|
|
3622
|
+
});
|
|
3623
|
+
}
|
|
3624
|
+
|
|
3625
|
+
// ../../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/bases/base36.js
|
|
3626
|
+
var base362 = baseX2({
|
|
3627
|
+
prefix: "k",
|
|
3628
|
+
name: "base36",
|
|
3629
|
+
alphabet: "0123456789abcdefghijklmnopqrstuvwxyz"
|
|
3630
|
+
});
|
|
3631
|
+
var base36upper2 = baseX2({
|
|
3632
|
+
prefix: "K",
|
|
3633
|
+
name: "base36upper",
|
|
3634
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
3635
|
+
});
|
|
3636
|
+
|
|
3637
|
+
// ../../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/hashes/hasher.js
|
|
3638
|
+
var DEFAULT_MIN_DIGEST_LENGTH = 20;
|
|
3639
|
+
function from3({ name, code, encode: encode5, minDigestLength, maxDigestLength }) {
|
|
3640
|
+
return new Hasher(name, code, encode5, minDigestLength, maxDigestLength);
|
|
3641
|
+
}
|
|
3642
|
+
var Hasher = class {
|
|
3643
|
+
name;
|
|
3644
|
+
code;
|
|
3645
|
+
encode;
|
|
3646
|
+
minDigestLength;
|
|
3647
|
+
maxDigestLength;
|
|
3648
|
+
constructor(name, code, encode5, minDigestLength, maxDigestLength) {
|
|
3649
|
+
this.name = name;
|
|
3650
|
+
this.code = code;
|
|
3651
|
+
this.encode = encode5;
|
|
3652
|
+
this.minDigestLength = minDigestLength ?? DEFAULT_MIN_DIGEST_LENGTH;
|
|
3653
|
+
this.maxDigestLength = maxDigestLength;
|
|
3654
|
+
}
|
|
3655
|
+
digest(input, options) {
|
|
3656
|
+
if (options?.truncate != null) {
|
|
3657
|
+
if (options.truncate < this.minDigestLength) {
|
|
3658
|
+
throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);
|
|
3659
|
+
}
|
|
3660
|
+
if (this.maxDigestLength != null && options.truncate > this.maxDigestLength) {
|
|
3661
|
+
throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`);
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
if (input instanceof Uint8Array) {
|
|
3665
|
+
const result = this.encode(input);
|
|
3666
|
+
if (result instanceof Uint8Array) {
|
|
3667
|
+
return createDigest(result, this.code, options?.truncate);
|
|
3668
|
+
}
|
|
3669
|
+
return result.then((digest) => createDigest(digest, this.code, options?.truncate));
|
|
3670
|
+
} else {
|
|
3671
|
+
throw Error("Unknown type, must be binary type");
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3674
|
+
};
|
|
3675
|
+
function createDigest(digest, code, truncate) {
|
|
3676
|
+
if (truncate != null && truncate !== digest.byteLength) {
|
|
3677
|
+
if (truncate > digest.byteLength) {
|
|
3678
|
+
throw new Error(`Invalid truncate option, must be less than or equal to ${digest.byteLength}`);
|
|
3679
|
+
}
|
|
3680
|
+
digest = digest.subarray(0, truncate);
|
|
3681
|
+
}
|
|
3682
|
+
return create(code, digest);
|
|
3683
|
+
}
|
|
3684
|
+
|
|
3685
|
+
// ../../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/bases/base64.js
|
|
3686
|
+
var base64_exports = {};
|
|
3687
|
+
__export(base64_exports, {
|
|
3688
|
+
base64: () => base64,
|
|
3689
|
+
base64pad: () => base64pad,
|
|
3690
|
+
base64url: () => base64url,
|
|
3691
|
+
base64urlpad: () => base64urlpad
|
|
3692
|
+
});
|
|
3693
|
+
var base64 = rfc4648({
|
|
3694
|
+
prefix: "m",
|
|
3695
|
+
name: "base64",
|
|
3696
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
|
|
3697
|
+
bitsPerChar: 6
|
|
3698
|
+
});
|
|
3699
|
+
var base64pad = rfc4648({
|
|
3700
|
+
prefix: "M",
|
|
3701
|
+
name: "base64pad",
|
|
3702
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
|
3703
|
+
bitsPerChar: 6
|
|
3704
|
+
});
|
|
3705
|
+
var base64url = rfc4648({
|
|
3706
|
+
prefix: "u",
|
|
3707
|
+
name: "base64url",
|
|
3708
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
|
|
3709
|
+
bitsPerChar: 6
|
|
3710
|
+
});
|
|
3711
|
+
var base64urlpad = rfc4648({
|
|
3712
|
+
prefix: "U",
|
|
3713
|
+
name: "base64urlpad",
|
|
3714
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",
|
|
3715
|
+
bitsPerChar: 6
|
|
3716
|
+
});
|
|
3717
|
+
|
|
3718
|
+
export {
|
|
3719
|
+
Type,
|
|
3720
|
+
Token,
|
|
3721
|
+
asU8A,
|
|
3722
|
+
fromString,
|
|
3723
|
+
decodeCodePointsArray,
|
|
3724
|
+
decodeErrPrefix,
|
|
3725
|
+
encodeErrPrefix,
|
|
3726
|
+
makeCborEncoders,
|
|
3727
|
+
encodeCustom,
|
|
3728
|
+
encode,
|
|
3729
|
+
decode,
|
|
3730
|
+
coerce,
|
|
3731
|
+
fromString2,
|
|
3732
|
+
toString,
|
|
3733
|
+
from,
|
|
3734
|
+
baseX,
|
|
3735
|
+
rfc4648,
|
|
3736
|
+
base32,
|
|
3737
|
+
base32_exports,
|
|
3738
|
+
base36,
|
|
3739
|
+
base36_exports,
|
|
3740
|
+
base58btc,
|
|
3741
|
+
base58_exports,
|
|
3742
|
+
create,
|
|
3743
|
+
decode5 as decode2,
|
|
3744
|
+
CID,
|
|
3745
|
+
from3 as from2,
|
|
3746
|
+
base64,
|
|
3747
|
+
base64_exports,
|
|
3748
|
+
isBytes,
|
|
3749
|
+
anumber,
|
|
3750
|
+
abytes,
|
|
3751
|
+
ahash,
|
|
3752
|
+
aexists,
|
|
3753
|
+
clean,
|
|
3754
|
+
bytesToHex,
|
|
3755
|
+
hexToBytes,
|
|
3756
|
+
concatBytes,
|
|
3757
|
+
randomBytes,
|
|
3758
|
+
sha256,
|
|
3759
|
+
sha512,
|
|
3760
|
+
equals3 as equals,
|
|
3761
|
+
coerce2,
|
|
3762
|
+
baseX2,
|
|
3763
|
+
rfc46482,
|
|
3764
|
+
base362
|
|
3765
|
+
};
|
|
3766
|
+
/*! Bundled license information:
|
|
3767
|
+
|
|
3768
|
+
@noble/hashes/utils.js:
|
|
3769
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
3770
|
+
*/
|
|
3771
|
+
//# sourceMappingURL=chunk-QO2KMGDN.min.js.map
|