@wovin/core 0.0.9-RC4 → 0.0.11
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/LICENSE +661 -0
- package/dist/applog/applog-helpers.d.ts +26 -7
- package/dist/applog/applog-helpers.d.ts.map +1 -1
- package/dist/applog/applog-utils.d.ts +11 -2
- package/dist/applog/applog-utils.d.ts.map +1 -1
- package/dist/applog/datom-types.d.ts +24 -13
- package/dist/applog/datom-types.d.ts.map +1 -1
- package/dist/applog.min.js +11 -3
- package/dist/{chunk-PTGUFZ3Q.min.js → chunk-6EBQRFQC.min.js} +1 -5
- package/dist/{chunk-PTGUFZ3Q.min.js.map → chunk-6EBQRFQC.min.js.map} +1 -1
- package/dist/chunk-C75X52ZX.min.js +2314 -0
- package/dist/chunk-C75X52ZX.min.js.map +1 -0
- package/dist/chunk-DF3UOPRV.min.js +5085 -0
- package/dist/chunk-DF3UOPRV.min.js.map +1 -0
- package/dist/{chunk-XXTV6KVM.min.js → chunk-L4AYAZCN.min.js} +9 -9
- package/dist/chunk-L4AYAZCN.min.js.map +1 -0
- package/dist/chunk-QPGEBDMJ.min.js +9 -0
- package/dist/chunk-QPGEBDMJ.min.js.map +1 -0
- package/dist/chunk-TPRWMCU7.min.js +494 -0
- package/dist/chunk-TPRWMCU7.min.js.map +1 -0
- package/dist/{chunk-V5T5PE7K.min.js → chunk-UQJEOS7T.min.js} +5913 -5688
- package/dist/chunk-UQJEOS7T.min.js.map +1 -0
- package/dist/chunk-UREBOWFC.min.js +40 -0
- package/dist/chunk-UREBOWFC.min.js.map +1 -0
- package/dist/index.min.js +103 -53
- package/dist/ipfs/car.d.ts +47 -7
- package/dist/ipfs/car.d.ts.map +1 -1
- package/dist/ipfs/ipfs-utils.d.ts +18 -7
- package/dist/ipfs/ipfs-utils.d.ts.map +1 -1
- package/dist/ipfs.min.js +24 -6
- package/dist/mobx/mobx-utils.d.ts +23 -17
- package/dist/mobx/mobx-utils.d.ts.map +1 -1
- package/dist/mobx.d.ts +2 -0
- package/dist/mobx.d.ts.map +1 -0
- package/dist/mobx.min.js +141 -0
- package/dist/mobx.min.js.map +1 -0
- package/dist/pubsub/connector.d.ts +3 -1
- package/dist/pubsub/connector.d.ts.map +1 -1
- package/dist/pubsub/pub-pull.d.ts +14 -0
- package/dist/pubsub/pub-pull.d.ts.map +1 -0
- package/dist/pubsub/pub-push.d.ts +41 -0
- package/dist/pubsub/pub-push.d.ts.map +1 -0
- package/dist/pubsub/pubsub-types.d.ts +25 -1
- package/dist/pubsub/pubsub-types.d.ts.map +1 -1
- package/dist/pubsub.d.ts +2 -1
- package/dist/pubsub.d.ts.map +1 -1
- package/dist/pubsub.min.js +20 -13
- package/dist/query/basic.d.ts +40 -8
- package/dist/query/basic.d.ts.map +1 -1
- package/dist/query/divergences.d.ts.map +1 -1
- package/dist/query/types.d.ts +3 -3
- package/dist/query/types.d.ts.map +1 -1
- package/dist/query.min.js +34 -16
- package/dist/thread/basic.d.ts +24 -4
- package/dist/thread/basic.d.ts.map +1 -1
- package/dist/thread/filters.d.ts +2 -2
- package/dist/thread/filters.d.ts.map +1 -1
- package/dist/thread/mapped.d.ts +10 -3
- package/dist/thread/mapped.d.ts.map +1 -1
- package/dist/thread/utils.d.ts +16 -0
- package/dist/thread/utils.d.ts.map +1 -0
- package/dist/thread/writeable.d.ts +4 -3
- package/dist/thread/writeable.d.ts.map +1 -1
- package/dist/thread.d.ts +1 -0
- package/dist/thread.d.ts.map +1 -1
- package/dist/thread.min.js +13 -3
- package/dist/types/typescript-utils.d.ts +5 -4
- package/dist/types/typescript-utils.d.ts.map +1 -1
- package/dist/types.min.js +1 -5
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.min.js +9 -0
- package/package.json +17 -11
- package/dist/chunk-CIOF7QHW.min.js +0 -135
- package/dist/chunk-CIOF7QHW.min.js.map +0 -1
- package/dist/chunk-V5T5PE7K.min.js.map +0 -1
- package/dist/chunk-VM46JSEH.min.js +0 -1426
- package/dist/chunk-VM46JSEH.min.js.map +0 -1
- package/dist/chunk-XXTV6KVM.min.js.map +0 -1
- package/dist/chunk-YBXZNIU2.min.js +0 -4417
- package/dist/chunk-YBXZNIU2.min.js.map +0 -1
- package/dist/pubsub/publication.d.ts +0 -17
- package/dist/pubsub/publication.d.ts.map +0 -1
|
@@ -1,4417 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__export
|
|
3
|
-
} from "./chunk-KRQZ6V4Y.min.js";
|
|
4
|
-
|
|
5
|
-
// ../../../node_modules/.pnpm/@ipld+dag-json@10.1.5/node_modules/@ipld/dag-json/src/index.js
|
|
6
|
-
var src_exports = {};
|
|
7
|
-
__export(src_exports, {
|
|
8
|
-
code: () => code,
|
|
9
|
-
decode: () => decode7,
|
|
10
|
-
encode: () => encode5,
|
|
11
|
-
format: () => format2,
|
|
12
|
-
name: () => name,
|
|
13
|
-
parse: () => parse,
|
|
14
|
-
stringify: () => format2
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// ../../../node_modules/.pnpm/cborg@4.0.5/node_modules/cborg/lib/is.js
|
|
18
|
-
var typeofs = [
|
|
19
|
-
"string",
|
|
20
|
-
"number",
|
|
21
|
-
"bigint",
|
|
22
|
-
"symbol"
|
|
23
|
-
];
|
|
24
|
-
var objectTypeNames = [
|
|
25
|
-
"Function",
|
|
26
|
-
"Generator",
|
|
27
|
-
"AsyncGenerator",
|
|
28
|
-
"GeneratorFunction",
|
|
29
|
-
"AsyncGeneratorFunction",
|
|
30
|
-
"AsyncFunction",
|
|
31
|
-
"Observable",
|
|
32
|
-
"Array",
|
|
33
|
-
"Buffer",
|
|
34
|
-
"Object",
|
|
35
|
-
"RegExp",
|
|
36
|
-
"Date",
|
|
37
|
-
"Error",
|
|
38
|
-
"Map",
|
|
39
|
-
"Set",
|
|
40
|
-
"WeakMap",
|
|
41
|
-
"WeakSet",
|
|
42
|
-
"ArrayBuffer",
|
|
43
|
-
"SharedArrayBuffer",
|
|
44
|
-
"DataView",
|
|
45
|
-
"Promise",
|
|
46
|
-
"URL",
|
|
47
|
-
"HTMLElement",
|
|
48
|
-
"Int8Array",
|
|
49
|
-
"Uint8Array",
|
|
50
|
-
"Uint8ClampedArray",
|
|
51
|
-
"Int16Array",
|
|
52
|
-
"Uint16Array",
|
|
53
|
-
"Int32Array",
|
|
54
|
-
"Uint32Array",
|
|
55
|
-
"Float32Array",
|
|
56
|
-
"Float64Array",
|
|
57
|
-
"BigInt64Array",
|
|
58
|
-
"BigUint64Array"
|
|
59
|
-
];
|
|
60
|
-
function is(value) {
|
|
61
|
-
if (value === null) {
|
|
62
|
-
return "null";
|
|
63
|
-
}
|
|
64
|
-
if (value === void 0) {
|
|
65
|
-
return "undefined";
|
|
66
|
-
}
|
|
67
|
-
if (value === true || value === false) {
|
|
68
|
-
return "boolean";
|
|
69
|
-
}
|
|
70
|
-
const typeOf = typeof value;
|
|
71
|
-
if (typeofs.includes(typeOf)) {
|
|
72
|
-
return typeOf;
|
|
73
|
-
}
|
|
74
|
-
if (typeOf === "function") {
|
|
75
|
-
return "Function";
|
|
76
|
-
}
|
|
77
|
-
if (Array.isArray(value)) {
|
|
78
|
-
return "Array";
|
|
79
|
-
}
|
|
80
|
-
if (isBuffer(value)) {
|
|
81
|
-
return "Buffer";
|
|
82
|
-
}
|
|
83
|
-
const objectType = getObjectType(value);
|
|
84
|
-
if (objectType) {
|
|
85
|
-
return objectType;
|
|
86
|
-
}
|
|
87
|
-
return "Object";
|
|
88
|
-
}
|
|
89
|
-
function isBuffer(value) {
|
|
90
|
-
return value && value.constructor && value.constructor.isBuffer && value.constructor.isBuffer.call(null, value);
|
|
91
|
-
}
|
|
92
|
-
function getObjectType(value) {
|
|
93
|
-
const objectTypeName = Object.prototype.toString.call(value).slice(8, -1);
|
|
94
|
-
if (objectTypeNames.includes(objectTypeName)) {
|
|
95
|
-
return objectTypeName;
|
|
96
|
-
}
|
|
97
|
-
return void 0;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// ../../../node_modules/.pnpm/cborg@4.0.5/node_modules/cborg/lib/token.js
|
|
101
|
-
var Type = class {
|
|
102
|
-
/**
|
|
103
|
-
* @param {number} major
|
|
104
|
-
* @param {string} name
|
|
105
|
-
* @param {boolean} terminal
|
|
106
|
-
*/
|
|
107
|
-
constructor(major, name2, terminal) {
|
|
108
|
-
this.major = major;
|
|
109
|
-
this.majorEncoded = major << 5;
|
|
110
|
-
this.name = name2;
|
|
111
|
-
this.terminal = terminal;
|
|
112
|
-
}
|
|
113
|
-
/* c8 ignore next 3 */
|
|
114
|
-
toString() {
|
|
115
|
-
return `Type[${this.major}].${this.name}`;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* @param {Type} typ
|
|
119
|
-
* @returns {number}
|
|
120
|
-
*/
|
|
121
|
-
compare(typ) {
|
|
122
|
-
return this.major < typ.major ? -1 : this.major > typ.major ? 1 : 0;
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
Type.uint = new Type(0, "uint", true);
|
|
126
|
-
Type.negint = new Type(1, "negint", true);
|
|
127
|
-
Type.bytes = new Type(2, "bytes", true);
|
|
128
|
-
Type.string = new Type(3, "string", true);
|
|
129
|
-
Type.array = new Type(4, "array", false);
|
|
130
|
-
Type.map = new Type(5, "map", false);
|
|
131
|
-
Type.tag = new Type(6, "tag", false);
|
|
132
|
-
Type.float = new Type(7, "float", true);
|
|
133
|
-
Type.false = new Type(7, "false", true);
|
|
134
|
-
Type.true = new Type(7, "true", true);
|
|
135
|
-
Type.null = new Type(7, "null", true);
|
|
136
|
-
Type.undefined = new Type(7, "undefined", true);
|
|
137
|
-
Type.break = new Type(7, "break", true);
|
|
138
|
-
var Token = class {
|
|
139
|
-
/**
|
|
140
|
-
* @param {Type} type
|
|
141
|
-
* @param {any} [value]
|
|
142
|
-
* @param {number} [encodedLength]
|
|
143
|
-
*/
|
|
144
|
-
constructor(type, value, encodedLength) {
|
|
145
|
-
this.type = type;
|
|
146
|
-
this.value = value;
|
|
147
|
-
this.encodedLength = encodedLength;
|
|
148
|
-
this.encodedBytes = void 0;
|
|
149
|
-
this.byteValue = void 0;
|
|
150
|
-
}
|
|
151
|
-
/* c8 ignore next 3 */
|
|
152
|
-
toString() {
|
|
153
|
-
return `Token[${this.type}].${this.value}`;
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
// ../../../node_modules/.pnpm/cborg@4.0.5/node_modules/cborg/lib/byte-utils.js
|
|
158
|
-
var useBuffer = globalThis.process && // @ts-ignore
|
|
159
|
-
!globalThis.process.browser && // @ts-ignore
|
|
160
|
-
globalThis.Buffer && // @ts-ignore
|
|
161
|
-
typeof globalThis.Buffer.isBuffer === "function";
|
|
162
|
-
var textDecoder = new TextDecoder();
|
|
163
|
-
var textEncoder = new TextEncoder();
|
|
164
|
-
function isBuffer2(buf2) {
|
|
165
|
-
return useBuffer && globalThis.Buffer.isBuffer(buf2);
|
|
166
|
-
}
|
|
167
|
-
function asU8A(buf2) {
|
|
168
|
-
if (!(buf2 instanceof Uint8Array)) {
|
|
169
|
-
return Uint8Array.from(buf2);
|
|
170
|
-
}
|
|
171
|
-
return isBuffer2(buf2) ? new Uint8Array(buf2.buffer, buf2.byteOffset, buf2.byteLength) : buf2;
|
|
172
|
-
}
|
|
173
|
-
var toString = useBuffer ? (
|
|
174
|
-
// eslint-disable-line operator-linebreak
|
|
175
|
-
/**
|
|
176
|
-
* @param {Uint8Array} bytes
|
|
177
|
-
* @param {number} start
|
|
178
|
-
* @param {number} end
|
|
179
|
-
*/
|
|
180
|
-
(bytes2, start, end) => {
|
|
181
|
-
return end - start > 64 ? (
|
|
182
|
-
// eslint-disable-line operator-linebreak
|
|
183
|
-
// @ts-ignore
|
|
184
|
-
globalThis.Buffer.from(bytes2.subarray(start, end)).toString("utf8")
|
|
185
|
-
) : utf8Slice(bytes2, start, end);
|
|
186
|
-
}
|
|
187
|
-
) : (
|
|
188
|
-
// eslint-disable-line operator-linebreak
|
|
189
|
-
/**
|
|
190
|
-
* @param {Uint8Array} bytes
|
|
191
|
-
* @param {number} start
|
|
192
|
-
* @param {number} end
|
|
193
|
-
*/
|
|
194
|
-
(bytes2, start, end) => {
|
|
195
|
-
return end - start > 64 ? textDecoder.decode(bytes2.subarray(start, end)) : utf8Slice(bytes2, start, end);
|
|
196
|
-
}
|
|
197
|
-
);
|
|
198
|
-
var fromString = useBuffer ? (
|
|
199
|
-
// eslint-disable-line operator-linebreak
|
|
200
|
-
/**
|
|
201
|
-
* @param {string} string
|
|
202
|
-
*/
|
|
203
|
-
(string) => {
|
|
204
|
-
return string.length > 64 ? (
|
|
205
|
-
// eslint-disable-line operator-linebreak
|
|
206
|
-
// @ts-ignore
|
|
207
|
-
globalThis.Buffer.from(string)
|
|
208
|
-
) : utf8ToBytes(string);
|
|
209
|
-
}
|
|
210
|
-
) : (
|
|
211
|
-
// eslint-disable-line operator-linebreak
|
|
212
|
-
/**
|
|
213
|
-
* @param {string} string
|
|
214
|
-
*/
|
|
215
|
-
(string) => {
|
|
216
|
-
return string.length > 64 ? textEncoder.encode(string) : utf8ToBytes(string);
|
|
217
|
-
}
|
|
218
|
-
);
|
|
219
|
-
var fromArray = (arr) => {
|
|
220
|
-
return Uint8Array.from(arr);
|
|
221
|
-
};
|
|
222
|
-
var slice = useBuffer ? (
|
|
223
|
-
// eslint-disable-line operator-linebreak
|
|
224
|
-
/**
|
|
225
|
-
* @param {Uint8Array} bytes
|
|
226
|
-
* @param {number} start
|
|
227
|
-
* @param {number} end
|
|
228
|
-
*/
|
|
229
|
-
(bytes2, start, end) => {
|
|
230
|
-
if (isBuffer2(bytes2)) {
|
|
231
|
-
return new Uint8Array(bytes2.subarray(start, end));
|
|
232
|
-
}
|
|
233
|
-
return bytes2.slice(start, end);
|
|
234
|
-
}
|
|
235
|
-
) : (
|
|
236
|
-
// eslint-disable-line operator-linebreak
|
|
237
|
-
/**
|
|
238
|
-
* @param {Uint8Array} bytes
|
|
239
|
-
* @param {number} start
|
|
240
|
-
* @param {number} end
|
|
241
|
-
*/
|
|
242
|
-
(bytes2, start, end) => {
|
|
243
|
-
return bytes2.slice(start, end);
|
|
244
|
-
}
|
|
245
|
-
);
|
|
246
|
-
var concat = useBuffer ? (
|
|
247
|
-
// eslint-disable-line operator-linebreak
|
|
248
|
-
/**
|
|
249
|
-
* @param {Uint8Array[]} chunks
|
|
250
|
-
* @param {number} length
|
|
251
|
-
* @returns {Uint8Array}
|
|
252
|
-
*/
|
|
253
|
-
(chunks, length2) => {
|
|
254
|
-
chunks = chunks.map((c) => c instanceof Uint8Array ? c : (
|
|
255
|
-
// eslint-disable-line operator-linebreak
|
|
256
|
-
// @ts-ignore
|
|
257
|
-
globalThis.Buffer.from(c)
|
|
258
|
-
));
|
|
259
|
-
return asU8A(globalThis.Buffer.concat(chunks, length2));
|
|
260
|
-
}
|
|
261
|
-
) : (
|
|
262
|
-
// eslint-disable-line operator-linebreak
|
|
263
|
-
/**
|
|
264
|
-
* @param {Uint8Array[]} chunks
|
|
265
|
-
* @param {number} length
|
|
266
|
-
* @returns {Uint8Array}
|
|
267
|
-
*/
|
|
268
|
-
(chunks, length2) => {
|
|
269
|
-
const out = new Uint8Array(length2);
|
|
270
|
-
let off = 0;
|
|
271
|
-
for (let b of chunks) {
|
|
272
|
-
if (off + b.length > out.length) {
|
|
273
|
-
b = b.subarray(0, out.length - off);
|
|
274
|
-
}
|
|
275
|
-
out.set(b, off);
|
|
276
|
-
off += b.length;
|
|
277
|
-
}
|
|
278
|
-
return out;
|
|
279
|
-
}
|
|
280
|
-
);
|
|
281
|
-
var alloc = useBuffer ? (
|
|
282
|
-
// eslint-disable-line operator-linebreak
|
|
283
|
-
/**
|
|
284
|
-
* @param {number} size
|
|
285
|
-
* @returns {Uint8Array}
|
|
286
|
-
*/
|
|
287
|
-
(size) => {
|
|
288
|
-
return globalThis.Buffer.allocUnsafe(size);
|
|
289
|
-
}
|
|
290
|
-
) : (
|
|
291
|
-
// eslint-disable-line operator-linebreak
|
|
292
|
-
/**
|
|
293
|
-
* @param {number} size
|
|
294
|
-
* @returns {Uint8Array}
|
|
295
|
-
*/
|
|
296
|
-
(size) => {
|
|
297
|
-
return new Uint8Array(size);
|
|
298
|
-
}
|
|
299
|
-
);
|
|
300
|
-
function compare(b1, b2) {
|
|
301
|
-
if (isBuffer2(b1) && isBuffer2(b2)) {
|
|
302
|
-
return b1.compare(b2);
|
|
303
|
-
}
|
|
304
|
-
for (let i = 0; i < b1.length; i++) {
|
|
305
|
-
if (b1[i] === b2[i]) {
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
return b1[i] < b2[i] ? -1 : 1;
|
|
309
|
-
}
|
|
310
|
-
return 0;
|
|
311
|
-
}
|
|
312
|
-
function utf8ToBytes(str) {
|
|
313
|
-
const out = [];
|
|
314
|
-
let p = 0;
|
|
315
|
-
for (let i = 0; i < str.length; i++) {
|
|
316
|
-
let c = str.charCodeAt(i);
|
|
317
|
-
if (c < 128) {
|
|
318
|
-
out[p++] = c;
|
|
319
|
-
} else if (c < 2048) {
|
|
320
|
-
out[p++] = c >> 6 | 192;
|
|
321
|
-
out[p++] = c & 63 | 128;
|
|
322
|
-
} else if ((c & 64512) === 55296 && i + 1 < str.length && (str.charCodeAt(i + 1) & 64512) === 56320) {
|
|
323
|
-
c = 65536 + ((c & 1023) << 10) + (str.charCodeAt(++i) & 1023);
|
|
324
|
-
out[p++] = c >> 18 | 240;
|
|
325
|
-
out[p++] = c >> 12 & 63 | 128;
|
|
326
|
-
out[p++] = c >> 6 & 63 | 128;
|
|
327
|
-
out[p++] = c & 63 | 128;
|
|
328
|
-
} else {
|
|
329
|
-
out[p++] = c >> 12 | 224;
|
|
330
|
-
out[p++] = c >> 6 & 63 | 128;
|
|
331
|
-
out[p++] = c & 63 | 128;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
return out;
|
|
335
|
-
}
|
|
336
|
-
function utf8Slice(buf2, offset, end) {
|
|
337
|
-
const res = [];
|
|
338
|
-
while (offset < end) {
|
|
339
|
-
const firstByte = buf2[offset];
|
|
340
|
-
let codePoint = null;
|
|
341
|
-
let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
|
|
342
|
-
if (offset + bytesPerSequence <= end) {
|
|
343
|
-
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
344
|
-
switch (bytesPerSequence) {
|
|
345
|
-
case 1:
|
|
346
|
-
if (firstByte < 128) {
|
|
347
|
-
codePoint = firstByte;
|
|
348
|
-
}
|
|
349
|
-
break;
|
|
350
|
-
case 2:
|
|
351
|
-
secondByte = buf2[offset + 1];
|
|
352
|
-
if ((secondByte & 192) === 128) {
|
|
353
|
-
tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
|
|
354
|
-
if (tempCodePoint > 127) {
|
|
355
|
-
codePoint = tempCodePoint;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
break;
|
|
359
|
-
case 3:
|
|
360
|
-
secondByte = buf2[offset + 1];
|
|
361
|
-
thirdByte = buf2[offset + 2];
|
|
362
|
-
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
|
|
363
|
-
tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
|
|
364
|
-
if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {
|
|
365
|
-
codePoint = tempCodePoint;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
break;
|
|
369
|
-
case 4:
|
|
370
|
-
secondByte = buf2[offset + 1];
|
|
371
|
-
thirdByte = buf2[offset + 2];
|
|
372
|
-
fourthByte = buf2[offset + 3];
|
|
373
|
-
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
|
|
374
|
-
tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
|
|
375
|
-
if (tempCodePoint > 65535 && tempCodePoint < 1114112) {
|
|
376
|
-
codePoint = tempCodePoint;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
if (codePoint === null) {
|
|
382
|
-
codePoint = 65533;
|
|
383
|
-
bytesPerSequence = 1;
|
|
384
|
-
} else if (codePoint > 65535) {
|
|
385
|
-
codePoint -= 65536;
|
|
386
|
-
res.push(codePoint >>> 10 & 1023 | 55296);
|
|
387
|
-
codePoint = 56320 | codePoint & 1023;
|
|
388
|
-
}
|
|
389
|
-
res.push(codePoint);
|
|
390
|
-
offset += bytesPerSequence;
|
|
391
|
-
}
|
|
392
|
-
return decodeCodePointsArray(res);
|
|
393
|
-
}
|
|
394
|
-
var MAX_ARGUMENTS_LENGTH = 4096;
|
|
395
|
-
function decodeCodePointsArray(codePoints) {
|
|
396
|
-
const len = codePoints.length;
|
|
397
|
-
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
398
|
-
return String.fromCharCode.apply(String, codePoints);
|
|
399
|
-
}
|
|
400
|
-
let res = "";
|
|
401
|
-
let i = 0;
|
|
402
|
-
while (i < len) {
|
|
403
|
-
res += String.fromCharCode.apply(
|
|
404
|
-
String,
|
|
405
|
-
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
406
|
-
);
|
|
407
|
-
}
|
|
408
|
-
return res;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
// ../../../node_modules/.pnpm/cborg@4.0.5/node_modules/cborg/lib/bl.js
|
|
412
|
-
var defaultChunkSize = 256;
|
|
413
|
-
var Bl = class {
|
|
414
|
-
/**
|
|
415
|
-
* @param {number} [chunkSize]
|
|
416
|
-
*/
|
|
417
|
-
constructor(chunkSize = defaultChunkSize) {
|
|
418
|
-
this.chunkSize = chunkSize;
|
|
419
|
-
this.cursor = 0;
|
|
420
|
-
this.maxCursor = -1;
|
|
421
|
-
this.chunks = [];
|
|
422
|
-
this._initReuseChunk = null;
|
|
423
|
-
}
|
|
424
|
-
reset() {
|
|
425
|
-
this.cursor = 0;
|
|
426
|
-
this.maxCursor = -1;
|
|
427
|
-
if (this.chunks.length) {
|
|
428
|
-
this.chunks = [];
|
|
429
|
-
}
|
|
430
|
-
if (this._initReuseChunk !== null) {
|
|
431
|
-
this.chunks.push(this._initReuseChunk);
|
|
432
|
-
this.maxCursor = this._initReuseChunk.length - 1;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
436
|
-
* @param {Uint8Array|number[]} bytes
|
|
437
|
-
*/
|
|
438
|
-
push(bytes2) {
|
|
439
|
-
let topChunk = this.chunks[this.chunks.length - 1];
|
|
440
|
-
const newMax = this.cursor + bytes2.length;
|
|
441
|
-
if (newMax <= this.maxCursor + 1) {
|
|
442
|
-
const chunkPos = topChunk.length - (this.maxCursor - this.cursor) - 1;
|
|
443
|
-
topChunk.set(bytes2, chunkPos);
|
|
444
|
-
} else {
|
|
445
|
-
if (topChunk) {
|
|
446
|
-
const chunkPos = topChunk.length - (this.maxCursor - this.cursor) - 1;
|
|
447
|
-
if (chunkPos < topChunk.length) {
|
|
448
|
-
this.chunks[this.chunks.length - 1] = topChunk.subarray(0, chunkPos);
|
|
449
|
-
this.maxCursor = this.cursor - 1;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
if (bytes2.length < 64 && bytes2.length < this.chunkSize) {
|
|
453
|
-
topChunk = alloc(this.chunkSize);
|
|
454
|
-
this.chunks.push(topChunk);
|
|
455
|
-
this.maxCursor += topChunk.length;
|
|
456
|
-
if (this._initReuseChunk === null) {
|
|
457
|
-
this._initReuseChunk = topChunk;
|
|
458
|
-
}
|
|
459
|
-
topChunk.set(bytes2, 0);
|
|
460
|
-
} else {
|
|
461
|
-
this.chunks.push(bytes2);
|
|
462
|
-
this.maxCursor += bytes2.length;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
this.cursor += bytes2.length;
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* @param {boolean} [reset]
|
|
469
|
-
* @returns {Uint8Array}
|
|
470
|
-
*/
|
|
471
|
-
toBytes(reset = false) {
|
|
472
|
-
let byts;
|
|
473
|
-
if (this.chunks.length === 1) {
|
|
474
|
-
const chunk = this.chunks[0];
|
|
475
|
-
if (reset && this.cursor > chunk.length / 2) {
|
|
476
|
-
byts = this.cursor === chunk.length ? chunk : chunk.subarray(0, this.cursor);
|
|
477
|
-
this._initReuseChunk = null;
|
|
478
|
-
this.chunks = [];
|
|
479
|
-
} else {
|
|
480
|
-
byts = slice(chunk, 0, this.cursor);
|
|
481
|
-
}
|
|
482
|
-
} else {
|
|
483
|
-
byts = concat(this.chunks, this.cursor);
|
|
484
|
-
}
|
|
485
|
-
if (reset) {
|
|
486
|
-
this.reset();
|
|
487
|
-
}
|
|
488
|
-
return byts;
|
|
489
|
-
}
|
|
490
|
-
};
|
|
491
|
-
|
|
492
|
-
// ../../../node_modules/.pnpm/cborg@4.0.5/node_modules/cborg/lib/common.js
|
|
493
|
-
var decodeErrPrefix = "CBOR decode error:";
|
|
494
|
-
var encodeErrPrefix = "CBOR encode error:";
|
|
495
|
-
var uintMinorPrefixBytes = [];
|
|
496
|
-
uintMinorPrefixBytes[23] = 1;
|
|
497
|
-
uintMinorPrefixBytes[24] = 2;
|
|
498
|
-
uintMinorPrefixBytes[25] = 3;
|
|
499
|
-
uintMinorPrefixBytes[26] = 5;
|
|
500
|
-
uintMinorPrefixBytes[27] = 9;
|
|
501
|
-
function assertEnoughData(data, pos, need) {
|
|
502
|
-
if (data.length - pos < need) {
|
|
503
|
-
throw new Error(`${decodeErrPrefix} not enough data for type`);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
// ../../../node_modules/.pnpm/cborg@4.0.5/node_modules/cborg/lib/0uint.js
|
|
508
|
-
var uintBoundaries = [24, 256, 65536, 4294967296, BigInt("18446744073709551616")];
|
|
509
|
-
function readUint8(data, offset, options) {
|
|
510
|
-
assertEnoughData(data, offset, 1);
|
|
511
|
-
const value = data[offset];
|
|
512
|
-
if (options.strict === true && value < uintBoundaries[0]) {
|
|
513
|
-
throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`);
|
|
514
|
-
}
|
|
515
|
-
return value;
|
|
516
|
-
}
|
|
517
|
-
function readUint16(data, offset, options) {
|
|
518
|
-
assertEnoughData(data, offset, 2);
|
|
519
|
-
const value = data[offset] << 8 | data[offset + 1];
|
|
520
|
-
if (options.strict === true && value < uintBoundaries[1]) {
|
|
521
|
-
throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`);
|
|
522
|
-
}
|
|
523
|
-
return value;
|
|
524
|
-
}
|
|
525
|
-
function readUint32(data, offset, options) {
|
|
526
|
-
assertEnoughData(data, offset, 4);
|
|
527
|
-
const value = data[offset] * 16777216 + (data[offset + 1] << 16) + (data[offset + 2] << 8) + data[offset + 3];
|
|
528
|
-
if (options.strict === true && value < uintBoundaries[2]) {
|
|
529
|
-
throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`);
|
|
530
|
-
}
|
|
531
|
-
return value;
|
|
532
|
-
}
|
|
533
|
-
function readUint64(data, offset, options) {
|
|
534
|
-
assertEnoughData(data, offset, 8);
|
|
535
|
-
const hi = data[offset] * 16777216 + (data[offset + 1] << 16) + (data[offset + 2] << 8) + data[offset + 3];
|
|
536
|
-
const lo = data[offset + 4] * 16777216 + (data[offset + 5] << 16) + (data[offset + 6] << 8) + data[offset + 7];
|
|
537
|
-
const value = (BigInt(hi) << BigInt(32)) + BigInt(lo);
|
|
538
|
-
if (options.strict === true && value < uintBoundaries[3]) {
|
|
539
|
-
throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`);
|
|
540
|
-
}
|
|
541
|
-
if (value <= Number.MAX_SAFE_INTEGER) {
|
|
542
|
-
return Number(value);
|
|
543
|
-
}
|
|
544
|
-
if (options.allowBigInt === true) {
|
|
545
|
-
return value;
|
|
546
|
-
}
|
|
547
|
-
throw new Error(`${decodeErrPrefix} integers outside of the safe integer range are not supported`);
|
|
548
|
-
}
|
|
549
|
-
function decodeUint8(data, pos, _minor, options) {
|
|
550
|
-
return new Token(Type.uint, readUint8(data, pos + 1, options), 2);
|
|
551
|
-
}
|
|
552
|
-
function decodeUint16(data, pos, _minor, options) {
|
|
553
|
-
return new Token(Type.uint, readUint16(data, pos + 1, options), 3);
|
|
554
|
-
}
|
|
555
|
-
function decodeUint32(data, pos, _minor, options) {
|
|
556
|
-
return new Token(Type.uint, readUint32(data, pos + 1, options), 5);
|
|
557
|
-
}
|
|
558
|
-
function decodeUint64(data, pos, _minor, options) {
|
|
559
|
-
return new Token(Type.uint, readUint64(data, pos + 1, options), 9);
|
|
560
|
-
}
|
|
561
|
-
function encodeUint(buf2, token) {
|
|
562
|
-
return encodeUintValue(buf2, 0, token.value);
|
|
563
|
-
}
|
|
564
|
-
function encodeUintValue(buf2, major, uint) {
|
|
565
|
-
if (uint < uintBoundaries[0]) {
|
|
566
|
-
const nuint = Number(uint);
|
|
567
|
-
buf2.push([major | nuint]);
|
|
568
|
-
} else if (uint < uintBoundaries[1]) {
|
|
569
|
-
const nuint = Number(uint);
|
|
570
|
-
buf2.push([major | 24, nuint]);
|
|
571
|
-
} else if (uint < uintBoundaries[2]) {
|
|
572
|
-
const nuint = Number(uint);
|
|
573
|
-
buf2.push([major | 25, nuint >>> 8, nuint & 255]);
|
|
574
|
-
} else if (uint < uintBoundaries[3]) {
|
|
575
|
-
const nuint = Number(uint);
|
|
576
|
-
buf2.push([major | 26, nuint >>> 24 & 255, nuint >>> 16 & 255, nuint >>> 8 & 255, nuint & 255]);
|
|
577
|
-
} else {
|
|
578
|
-
const buint = BigInt(uint);
|
|
579
|
-
if (buint < uintBoundaries[4]) {
|
|
580
|
-
const set = [major | 27, 0, 0, 0, 0, 0, 0, 0];
|
|
581
|
-
let lo = Number(buint & BigInt(4294967295));
|
|
582
|
-
let hi = Number(buint >> BigInt(32) & BigInt(4294967295));
|
|
583
|
-
set[8] = lo & 255;
|
|
584
|
-
lo = lo >> 8;
|
|
585
|
-
set[7] = lo & 255;
|
|
586
|
-
lo = lo >> 8;
|
|
587
|
-
set[6] = lo & 255;
|
|
588
|
-
lo = lo >> 8;
|
|
589
|
-
set[5] = lo & 255;
|
|
590
|
-
set[4] = hi & 255;
|
|
591
|
-
hi = hi >> 8;
|
|
592
|
-
set[3] = hi & 255;
|
|
593
|
-
hi = hi >> 8;
|
|
594
|
-
set[2] = hi & 255;
|
|
595
|
-
hi = hi >> 8;
|
|
596
|
-
set[1] = hi & 255;
|
|
597
|
-
buf2.push(set);
|
|
598
|
-
} else {
|
|
599
|
-
throw new Error(`${decodeErrPrefix} encountered BigInt larger than allowable range`);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
encodeUint.encodedSize = function encodedSize(token) {
|
|
604
|
-
return encodeUintValue.encodedSize(token.value);
|
|
605
|
-
};
|
|
606
|
-
encodeUintValue.encodedSize = function encodedSize2(uint) {
|
|
607
|
-
if (uint < uintBoundaries[0]) {
|
|
608
|
-
return 1;
|
|
609
|
-
}
|
|
610
|
-
if (uint < uintBoundaries[1]) {
|
|
611
|
-
return 2;
|
|
612
|
-
}
|
|
613
|
-
if (uint < uintBoundaries[2]) {
|
|
614
|
-
return 3;
|
|
615
|
-
}
|
|
616
|
-
if (uint < uintBoundaries[3]) {
|
|
617
|
-
return 5;
|
|
618
|
-
}
|
|
619
|
-
return 9;
|
|
620
|
-
};
|
|
621
|
-
encodeUint.compareTokens = function compareTokens(tok1, tok2) {
|
|
622
|
-
return tok1.value < tok2.value ? -1 : tok1.value > tok2.value ? 1 : (
|
|
623
|
-
/* c8 ignore next */
|
|
624
|
-
0
|
|
625
|
-
);
|
|
626
|
-
};
|
|
627
|
-
|
|
628
|
-
// ../../../node_modules/.pnpm/cborg@4.0.5/node_modules/cborg/lib/1negint.js
|
|
629
|
-
function decodeNegint8(data, pos, _minor, options) {
|
|
630
|
-
return new Token(Type.negint, -1 - readUint8(data, pos + 1, options), 2);
|
|
631
|
-
}
|
|
632
|
-
function decodeNegint16(data, pos, _minor, options) {
|
|
633
|
-
return new Token(Type.negint, -1 - readUint16(data, pos + 1, options), 3);
|
|
634
|
-
}
|
|
635
|
-
function decodeNegint32(data, pos, _minor, options) {
|
|
636
|
-
return new Token(Type.negint, -1 - readUint32(data, pos + 1, options), 5);
|
|
637
|
-
}
|
|
638
|
-
var neg1b = BigInt(-1);
|
|
639
|
-
var pos1b = BigInt(1);
|
|
640
|
-
function decodeNegint64(data, pos, _minor, options) {
|
|
641
|
-
const int = readUint64(data, pos + 1, options);
|
|
642
|
-
if (typeof int !== "bigint") {
|
|
643
|
-
const value = -1 - int;
|
|
644
|
-
if (value >= Number.MIN_SAFE_INTEGER) {
|
|
645
|
-
return new Token(Type.negint, value, 9);
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
if (options.allowBigInt !== true) {
|
|
649
|
-
throw new Error(`${decodeErrPrefix} integers outside of the safe integer range are not supported`);
|
|
650
|
-
}
|
|
651
|
-
return new Token(Type.negint, neg1b - BigInt(int), 9);
|
|
652
|
-
}
|
|
653
|
-
function encodeNegint(buf2, token) {
|
|
654
|
-
const negint = token.value;
|
|
655
|
-
const unsigned = typeof negint === "bigint" ? negint * neg1b - pos1b : negint * -1 - 1;
|
|
656
|
-
encodeUintValue(buf2, token.type.majorEncoded, unsigned);
|
|
657
|
-
}
|
|
658
|
-
encodeNegint.encodedSize = function encodedSize3(token) {
|
|
659
|
-
const negint = token.value;
|
|
660
|
-
const unsigned = typeof negint === "bigint" ? negint * neg1b - pos1b : negint * -1 - 1;
|
|
661
|
-
if (unsigned < uintBoundaries[0]) {
|
|
662
|
-
return 1;
|
|
663
|
-
}
|
|
664
|
-
if (unsigned < uintBoundaries[1]) {
|
|
665
|
-
return 2;
|
|
666
|
-
}
|
|
667
|
-
if (unsigned < uintBoundaries[2]) {
|
|
668
|
-
return 3;
|
|
669
|
-
}
|
|
670
|
-
if (unsigned < uintBoundaries[3]) {
|
|
671
|
-
return 5;
|
|
672
|
-
}
|
|
673
|
-
return 9;
|
|
674
|
-
};
|
|
675
|
-
encodeNegint.compareTokens = function compareTokens2(tok1, tok2) {
|
|
676
|
-
return tok1.value < tok2.value ? 1 : tok1.value > tok2.value ? -1 : (
|
|
677
|
-
/* c8 ignore next */
|
|
678
|
-
0
|
|
679
|
-
);
|
|
680
|
-
};
|
|
681
|
-
|
|
682
|
-
// ../../../node_modules/.pnpm/cborg@4.0.5/node_modules/cborg/lib/2bytes.js
|
|
683
|
-
function toToken(data, pos, prefix, length2) {
|
|
684
|
-
assertEnoughData(data, pos, prefix + length2);
|
|
685
|
-
const buf2 = slice(data, pos + prefix, pos + prefix + length2);
|
|
686
|
-
return new Token(Type.bytes, buf2, prefix + length2);
|
|
687
|
-
}
|
|
688
|
-
function decodeBytesCompact(data, pos, minor, _options) {
|
|
689
|
-
return toToken(data, pos, 1, minor);
|
|
690
|
-
}
|
|
691
|
-
function decodeBytes8(data, pos, _minor, options) {
|
|
692
|
-
return toToken(data, pos, 2, readUint8(data, pos + 1, options));
|
|
693
|
-
}
|
|
694
|
-
function decodeBytes16(data, pos, _minor, options) {
|
|
695
|
-
return toToken(data, pos, 3, readUint16(data, pos + 1, options));
|
|
696
|
-
}
|
|
697
|
-
function decodeBytes32(data, pos, _minor, options) {
|
|
698
|
-
return toToken(data, pos, 5, readUint32(data, pos + 1, options));
|
|
699
|
-
}
|
|
700
|
-
function decodeBytes64(data, pos, _minor, options) {
|
|
701
|
-
const l = readUint64(data, pos + 1, options);
|
|
702
|
-
if (typeof l === "bigint") {
|
|
703
|
-
throw new Error(`${decodeErrPrefix} 64-bit integer bytes lengths not supported`);
|
|
704
|
-
}
|
|
705
|
-
return toToken(data, pos, 9, l);
|
|
706
|
-
}
|
|
707
|
-
function tokenBytes(token) {
|
|
708
|
-
if (token.encodedBytes === void 0) {
|
|
709
|
-
token.encodedBytes = token.type === Type.string ? fromString(token.value) : token.value;
|
|
710
|
-
}
|
|
711
|
-
return token.encodedBytes;
|
|
712
|
-
}
|
|
713
|
-
function encodeBytes(buf2, token) {
|
|
714
|
-
const bytes2 = tokenBytes(token);
|
|
715
|
-
encodeUintValue(buf2, token.type.majorEncoded, bytes2.length);
|
|
716
|
-
buf2.push(bytes2);
|
|
717
|
-
}
|
|
718
|
-
encodeBytes.encodedSize = function encodedSize4(token) {
|
|
719
|
-
const bytes2 = tokenBytes(token);
|
|
720
|
-
return encodeUintValue.encodedSize(bytes2.length) + bytes2.length;
|
|
721
|
-
};
|
|
722
|
-
encodeBytes.compareTokens = function compareTokens3(tok1, tok2) {
|
|
723
|
-
return compareBytes(tokenBytes(tok1), tokenBytes(tok2));
|
|
724
|
-
};
|
|
725
|
-
function compareBytes(b1, b2) {
|
|
726
|
-
return b1.length < b2.length ? -1 : b1.length > b2.length ? 1 : compare(b1, b2);
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
// ../../../node_modules/.pnpm/cborg@4.0.5/node_modules/cborg/lib/3string.js
|
|
730
|
-
function toToken2(data, pos, prefix, length2, options) {
|
|
731
|
-
const totLength = prefix + length2;
|
|
732
|
-
assertEnoughData(data, pos, totLength);
|
|
733
|
-
const tok = new Token(Type.string, toString(data, pos + prefix, pos + totLength), totLength);
|
|
734
|
-
if (options.retainStringBytes === true) {
|
|
735
|
-
tok.byteValue = slice(data, pos + prefix, pos + totLength);
|
|
736
|
-
}
|
|
737
|
-
return tok;
|
|
738
|
-
}
|
|
739
|
-
function decodeStringCompact(data, pos, minor, options) {
|
|
740
|
-
return toToken2(data, pos, 1, minor, options);
|
|
741
|
-
}
|
|
742
|
-
function decodeString8(data, pos, _minor, options) {
|
|
743
|
-
return toToken2(data, pos, 2, readUint8(data, pos + 1, options), options);
|
|
744
|
-
}
|
|
745
|
-
function decodeString16(data, pos, _minor, options) {
|
|
746
|
-
return toToken2(data, pos, 3, readUint16(data, pos + 1, options), options);
|
|
747
|
-
}
|
|
748
|
-
function decodeString32(data, pos, _minor, options) {
|
|
749
|
-
return toToken2(data, pos, 5, readUint32(data, pos + 1, options), options);
|
|
750
|
-
}
|
|
751
|
-
function decodeString64(data, pos, _minor, options) {
|
|
752
|
-
const l = readUint64(data, pos + 1, options);
|
|
753
|
-
if (typeof l === "bigint") {
|
|
754
|
-
throw new Error(`${decodeErrPrefix} 64-bit integer string lengths not supported`);
|
|
755
|
-
}
|
|
756
|
-
return toToken2(data, pos, 9, l, options);
|
|
757
|
-
}
|
|
758
|
-
var encodeString = encodeBytes;
|
|
759
|
-
|
|
760
|
-
// ../../../node_modules/.pnpm/cborg@4.0.5/node_modules/cborg/lib/4array.js
|
|
761
|
-
function toToken3(_data, _pos, prefix, length2) {
|
|
762
|
-
return new Token(Type.array, length2, prefix);
|
|
763
|
-
}
|
|
764
|
-
function decodeArrayCompact(data, pos, minor, _options) {
|
|
765
|
-
return toToken3(data, pos, 1, minor);
|
|
766
|
-
}
|
|
767
|
-
function decodeArray8(data, pos, _minor, options) {
|
|
768
|
-
return toToken3(data, pos, 2, readUint8(data, pos + 1, options));
|
|
769
|
-
}
|
|
770
|
-
function decodeArray16(data, pos, _minor, options) {
|
|
771
|
-
return toToken3(data, pos, 3, readUint16(data, pos + 1, options));
|
|
772
|
-
}
|
|
773
|
-
function decodeArray32(data, pos, _minor, options) {
|
|
774
|
-
return toToken3(data, pos, 5, readUint32(data, pos + 1, options));
|
|
775
|
-
}
|
|
776
|
-
function decodeArray64(data, pos, _minor, options) {
|
|
777
|
-
const l = readUint64(data, pos + 1, options);
|
|
778
|
-
if (typeof l === "bigint") {
|
|
779
|
-
throw new Error(`${decodeErrPrefix} 64-bit integer array lengths not supported`);
|
|
780
|
-
}
|
|
781
|
-
return toToken3(data, pos, 9, l);
|
|
782
|
-
}
|
|
783
|
-
function decodeArrayIndefinite(data, pos, _minor, options) {
|
|
784
|
-
if (options.allowIndefinite === false) {
|
|
785
|
-
throw new Error(`${decodeErrPrefix} indefinite length items not allowed`);
|
|
786
|
-
}
|
|
787
|
-
return toToken3(data, pos, 1, Infinity);
|
|
788
|
-
}
|
|
789
|
-
function encodeArray(buf2, token) {
|
|
790
|
-
encodeUintValue(buf2, Type.array.majorEncoded, token.value);
|
|
791
|
-
}
|
|
792
|
-
encodeArray.compareTokens = encodeUint.compareTokens;
|
|
793
|
-
encodeArray.encodedSize = function encodedSize5(token) {
|
|
794
|
-
return encodeUintValue.encodedSize(token.value);
|
|
795
|
-
};
|
|
796
|
-
|
|
797
|
-
// ../../../node_modules/.pnpm/cborg@4.0.5/node_modules/cborg/lib/5map.js
|
|
798
|
-
function toToken4(_data, _pos, prefix, length2) {
|
|
799
|
-
return new Token(Type.map, length2, prefix);
|
|
800
|
-
}
|
|
801
|
-
function decodeMapCompact(data, pos, minor, _options) {
|
|
802
|
-
return toToken4(data, pos, 1, minor);
|
|
803
|
-
}
|
|
804
|
-
function decodeMap8(data, pos, _minor, options) {
|
|
805
|
-
return toToken4(data, pos, 2, readUint8(data, pos + 1, options));
|
|
806
|
-
}
|
|
807
|
-
function decodeMap16(data, pos, _minor, options) {
|
|
808
|
-
return toToken4(data, pos, 3, readUint16(data, pos + 1, options));
|
|
809
|
-
}
|
|
810
|
-
function decodeMap32(data, pos, _minor, options) {
|
|
811
|
-
return toToken4(data, pos, 5, readUint32(data, pos + 1, options));
|
|
812
|
-
}
|
|
813
|
-
function decodeMap64(data, pos, _minor, options) {
|
|
814
|
-
const l = readUint64(data, pos + 1, options);
|
|
815
|
-
if (typeof l === "bigint") {
|
|
816
|
-
throw new Error(`${decodeErrPrefix} 64-bit integer map lengths not supported`);
|
|
817
|
-
}
|
|
818
|
-
return toToken4(data, pos, 9, l);
|
|
819
|
-
}
|
|
820
|
-
function decodeMapIndefinite(data, pos, _minor, options) {
|
|
821
|
-
if (options.allowIndefinite === false) {
|
|
822
|
-
throw new Error(`${decodeErrPrefix} indefinite length items not allowed`);
|
|
823
|
-
}
|
|
824
|
-
return toToken4(data, pos, 1, Infinity);
|
|
825
|
-
}
|
|
826
|
-
function encodeMap(buf2, token) {
|
|
827
|
-
encodeUintValue(buf2, Type.map.majorEncoded, token.value);
|
|
828
|
-
}
|
|
829
|
-
encodeMap.compareTokens = encodeUint.compareTokens;
|
|
830
|
-
encodeMap.encodedSize = function encodedSize6(token) {
|
|
831
|
-
return encodeUintValue.encodedSize(token.value);
|
|
832
|
-
};
|
|
833
|
-
|
|
834
|
-
// ../../../node_modules/.pnpm/cborg@4.0.5/node_modules/cborg/lib/6tag.js
|
|
835
|
-
function decodeTagCompact(_data, _pos, minor, _options) {
|
|
836
|
-
return new Token(Type.tag, minor, 1);
|
|
837
|
-
}
|
|
838
|
-
function decodeTag8(data, pos, _minor, options) {
|
|
839
|
-
return new Token(Type.tag, readUint8(data, pos + 1, options), 2);
|
|
840
|
-
}
|
|
841
|
-
function decodeTag16(data, pos, _minor, options) {
|
|
842
|
-
return new Token(Type.tag, readUint16(data, pos + 1, options), 3);
|
|
843
|
-
}
|
|
844
|
-
function decodeTag32(data, pos, _minor, options) {
|
|
845
|
-
return new Token(Type.tag, readUint32(data, pos + 1, options), 5);
|
|
846
|
-
}
|
|
847
|
-
function decodeTag64(data, pos, _minor, options) {
|
|
848
|
-
return new Token(Type.tag, readUint64(data, pos + 1, options), 9);
|
|
849
|
-
}
|
|
850
|
-
function encodeTag(buf2, token) {
|
|
851
|
-
encodeUintValue(buf2, Type.tag.majorEncoded, token.value);
|
|
852
|
-
}
|
|
853
|
-
encodeTag.compareTokens = encodeUint.compareTokens;
|
|
854
|
-
encodeTag.encodedSize = function encodedSize7(token) {
|
|
855
|
-
return encodeUintValue.encodedSize(token.value);
|
|
856
|
-
};
|
|
857
|
-
|
|
858
|
-
// ../../../node_modules/.pnpm/cborg@4.0.5/node_modules/cborg/lib/7float.js
|
|
859
|
-
var MINOR_FALSE = 20;
|
|
860
|
-
var MINOR_TRUE = 21;
|
|
861
|
-
var MINOR_NULL = 22;
|
|
862
|
-
var MINOR_UNDEFINED = 23;
|
|
863
|
-
function decodeUndefined(_data, _pos, _minor, options) {
|
|
864
|
-
if (options.allowUndefined === false) {
|
|
865
|
-
throw new Error(`${decodeErrPrefix} undefined values are not supported`);
|
|
866
|
-
} else if (options.coerceUndefinedToNull === true) {
|
|
867
|
-
return new Token(Type.null, null, 1);
|
|
868
|
-
}
|
|
869
|
-
return new Token(Type.undefined, void 0, 1);
|
|
870
|
-
}
|
|
871
|
-
function decodeBreak(_data, _pos, _minor, options) {
|
|
872
|
-
if (options.allowIndefinite === false) {
|
|
873
|
-
throw new Error(`${decodeErrPrefix} indefinite length items not allowed`);
|
|
874
|
-
}
|
|
875
|
-
return new Token(Type.break, void 0, 1);
|
|
876
|
-
}
|
|
877
|
-
function createToken(value, bytes2, options) {
|
|
878
|
-
if (options) {
|
|
879
|
-
if (options.allowNaN === false && Number.isNaN(value)) {
|
|
880
|
-
throw new Error(`${decodeErrPrefix} NaN values are not supported`);
|
|
881
|
-
}
|
|
882
|
-
if (options.allowInfinity === false && (value === Infinity || value === -Infinity)) {
|
|
883
|
-
throw new Error(`${decodeErrPrefix} Infinity values are not supported`);
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
return new Token(Type.float, value, bytes2);
|
|
887
|
-
}
|
|
888
|
-
function decodeFloat16(data, pos, _minor, options) {
|
|
889
|
-
return createToken(readFloat16(data, pos + 1), 3, options);
|
|
890
|
-
}
|
|
891
|
-
function decodeFloat32(data, pos, _minor, options) {
|
|
892
|
-
return createToken(readFloat32(data, pos + 1), 5, options);
|
|
893
|
-
}
|
|
894
|
-
function decodeFloat64(data, pos, _minor, options) {
|
|
895
|
-
return createToken(readFloat64(data, pos + 1), 9, options);
|
|
896
|
-
}
|
|
897
|
-
function encodeFloat(buf2, token, options) {
|
|
898
|
-
const float = token.value;
|
|
899
|
-
if (float === false) {
|
|
900
|
-
buf2.push([Type.float.majorEncoded | MINOR_FALSE]);
|
|
901
|
-
} else if (float === true) {
|
|
902
|
-
buf2.push([Type.float.majorEncoded | MINOR_TRUE]);
|
|
903
|
-
} else if (float === null) {
|
|
904
|
-
buf2.push([Type.float.majorEncoded | MINOR_NULL]);
|
|
905
|
-
} else if (float === void 0) {
|
|
906
|
-
buf2.push([Type.float.majorEncoded | MINOR_UNDEFINED]);
|
|
907
|
-
} else {
|
|
908
|
-
let decoded;
|
|
909
|
-
let success = false;
|
|
910
|
-
if (!options || options.float64 !== true) {
|
|
911
|
-
encodeFloat16(float);
|
|
912
|
-
decoded = readFloat16(ui8a, 1);
|
|
913
|
-
if (float === decoded || Number.isNaN(float)) {
|
|
914
|
-
ui8a[0] = 249;
|
|
915
|
-
buf2.push(ui8a.slice(0, 3));
|
|
916
|
-
success = true;
|
|
917
|
-
} else {
|
|
918
|
-
encodeFloat32(float);
|
|
919
|
-
decoded = readFloat32(ui8a, 1);
|
|
920
|
-
if (float === decoded) {
|
|
921
|
-
ui8a[0] = 250;
|
|
922
|
-
buf2.push(ui8a.slice(0, 5));
|
|
923
|
-
success = true;
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
if (!success) {
|
|
928
|
-
encodeFloat64(float);
|
|
929
|
-
decoded = readFloat64(ui8a, 1);
|
|
930
|
-
ui8a[0] = 251;
|
|
931
|
-
buf2.push(ui8a.slice(0, 9));
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
encodeFloat.encodedSize = function encodedSize8(token, options) {
|
|
936
|
-
const float = token.value;
|
|
937
|
-
if (float === false || float === true || float === null || float === void 0) {
|
|
938
|
-
return 1;
|
|
939
|
-
}
|
|
940
|
-
if (!options || options.float64 !== true) {
|
|
941
|
-
encodeFloat16(float);
|
|
942
|
-
let decoded = readFloat16(ui8a, 1);
|
|
943
|
-
if (float === decoded || Number.isNaN(float)) {
|
|
944
|
-
return 3;
|
|
945
|
-
}
|
|
946
|
-
encodeFloat32(float);
|
|
947
|
-
decoded = readFloat32(ui8a, 1);
|
|
948
|
-
if (float === decoded) {
|
|
949
|
-
return 5;
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
return 9;
|
|
953
|
-
};
|
|
954
|
-
var buffer = new ArrayBuffer(9);
|
|
955
|
-
var dataView = new DataView(buffer, 1);
|
|
956
|
-
var ui8a = new Uint8Array(buffer, 0);
|
|
957
|
-
function encodeFloat16(inp) {
|
|
958
|
-
if (inp === Infinity) {
|
|
959
|
-
dataView.setUint16(0, 31744, false);
|
|
960
|
-
} else if (inp === -Infinity) {
|
|
961
|
-
dataView.setUint16(0, 64512, false);
|
|
962
|
-
} else if (Number.isNaN(inp)) {
|
|
963
|
-
dataView.setUint16(0, 32256, false);
|
|
964
|
-
} else {
|
|
965
|
-
dataView.setFloat32(0, inp);
|
|
966
|
-
const valu32 = dataView.getUint32(0);
|
|
967
|
-
const exponent = (valu32 & 2139095040) >> 23;
|
|
968
|
-
const mantissa = valu32 & 8388607;
|
|
969
|
-
if (exponent === 255) {
|
|
970
|
-
dataView.setUint16(0, 31744, false);
|
|
971
|
-
} else if (exponent === 0) {
|
|
972
|
-
dataView.setUint16(0, (inp & 2147483648) >> 16 | mantissa >> 13, false);
|
|
973
|
-
} else {
|
|
974
|
-
const logicalExponent = exponent - 127;
|
|
975
|
-
if (logicalExponent < -24) {
|
|
976
|
-
dataView.setUint16(0, 0);
|
|
977
|
-
} else if (logicalExponent < -14) {
|
|
978
|
-
dataView.setUint16(0, (valu32 & 2147483648) >> 16 | /* sign bit */
|
|
979
|
-
1 << 24 + logicalExponent, false);
|
|
980
|
-
} else {
|
|
981
|
-
dataView.setUint16(0, (valu32 & 2147483648) >> 16 | logicalExponent + 15 << 10 | mantissa >> 13, false);
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
function readFloat16(ui8a2, pos) {
|
|
987
|
-
if (ui8a2.length - pos < 2) {
|
|
988
|
-
throw new Error(`${decodeErrPrefix} not enough data for float16`);
|
|
989
|
-
}
|
|
990
|
-
const half = (ui8a2[pos] << 8) + ui8a2[pos + 1];
|
|
991
|
-
if (half === 31744) {
|
|
992
|
-
return Infinity;
|
|
993
|
-
}
|
|
994
|
-
if (half === 64512) {
|
|
995
|
-
return -Infinity;
|
|
996
|
-
}
|
|
997
|
-
if (half === 32256) {
|
|
998
|
-
return NaN;
|
|
999
|
-
}
|
|
1000
|
-
const exp = half >> 10 & 31;
|
|
1001
|
-
const mant = half & 1023;
|
|
1002
|
-
let val;
|
|
1003
|
-
if (exp === 0) {
|
|
1004
|
-
val = mant * 2 ** -24;
|
|
1005
|
-
} else if (exp !== 31) {
|
|
1006
|
-
val = (mant + 1024) * 2 ** (exp - 25);
|
|
1007
|
-
} else {
|
|
1008
|
-
val = mant === 0 ? Infinity : NaN;
|
|
1009
|
-
}
|
|
1010
|
-
return half & 32768 ? -val : val;
|
|
1011
|
-
}
|
|
1012
|
-
function encodeFloat32(inp) {
|
|
1013
|
-
dataView.setFloat32(0, inp, false);
|
|
1014
|
-
}
|
|
1015
|
-
function readFloat32(ui8a2, pos) {
|
|
1016
|
-
if (ui8a2.length - pos < 4) {
|
|
1017
|
-
throw new Error(`${decodeErrPrefix} not enough data for float32`);
|
|
1018
|
-
}
|
|
1019
|
-
const offset = (ui8a2.byteOffset || 0) + pos;
|
|
1020
|
-
return new DataView(ui8a2.buffer, offset, 4).getFloat32(0, false);
|
|
1021
|
-
}
|
|
1022
|
-
function encodeFloat64(inp) {
|
|
1023
|
-
dataView.setFloat64(0, inp, false);
|
|
1024
|
-
}
|
|
1025
|
-
function readFloat64(ui8a2, pos) {
|
|
1026
|
-
if (ui8a2.length - pos < 8) {
|
|
1027
|
-
throw new Error(`${decodeErrPrefix} not enough data for float64`);
|
|
1028
|
-
}
|
|
1029
|
-
const offset = (ui8a2.byteOffset || 0) + pos;
|
|
1030
|
-
return new DataView(ui8a2.buffer, offset, 8).getFloat64(0, false);
|
|
1031
|
-
}
|
|
1032
|
-
encodeFloat.compareTokens = encodeUint.compareTokens;
|
|
1033
|
-
|
|
1034
|
-
// ../../../node_modules/.pnpm/cborg@4.0.5/node_modules/cborg/lib/jump.js
|
|
1035
|
-
function invalidMinor(data, pos, minor) {
|
|
1036
|
-
throw new Error(`${decodeErrPrefix} encountered invalid minor (${minor}) for major ${data[pos] >>> 5}`);
|
|
1037
|
-
}
|
|
1038
|
-
function errorer(msg) {
|
|
1039
|
-
return () => {
|
|
1040
|
-
throw new Error(`${decodeErrPrefix} ${msg}`);
|
|
1041
|
-
};
|
|
1042
|
-
}
|
|
1043
|
-
var jump = [];
|
|
1044
|
-
for (let i = 0; i <= 23; i++) {
|
|
1045
|
-
jump[i] = invalidMinor;
|
|
1046
|
-
}
|
|
1047
|
-
jump[24] = decodeUint8;
|
|
1048
|
-
jump[25] = decodeUint16;
|
|
1049
|
-
jump[26] = decodeUint32;
|
|
1050
|
-
jump[27] = decodeUint64;
|
|
1051
|
-
jump[28] = invalidMinor;
|
|
1052
|
-
jump[29] = invalidMinor;
|
|
1053
|
-
jump[30] = invalidMinor;
|
|
1054
|
-
jump[31] = invalidMinor;
|
|
1055
|
-
for (let i = 32; i <= 55; i++) {
|
|
1056
|
-
jump[i] = invalidMinor;
|
|
1057
|
-
}
|
|
1058
|
-
jump[56] = decodeNegint8;
|
|
1059
|
-
jump[57] = decodeNegint16;
|
|
1060
|
-
jump[58] = decodeNegint32;
|
|
1061
|
-
jump[59] = decodeNegint64;
|
|
1062
|
-
jump[60] = invalidMinor;
|
|
1063
|
-
jump[61] = invalidMinor;
|
|
1064
|
-
jump[62] = invalidMinor;
|
|
1065
|
-
jump[63] = invalidMinor;
|
|
1066
|
-
for (let i = 64; i <= 87; i++) {
|
|
1067
|
-
jump[i] = decodeBytesCompact;
|
|
1068
|
-
}
|
|
1069
|
-
jump[88] = decodeBytes8;
|
|
1070
|
-
jump[89] = decodeBytes16;
|
|
1071
|
-
jump[90] = decodeBytes32;
|
|
1072
|
-
jump[91] = decodeBytes64;
|
|
1073
|
-
jump[92] = invalidMinor;
|
|
1074
|
-
jump[93] = invalidMinor;
|
|
1075
|
-
jump[94] = invalidMinor;
|
|
1076
|
-
jump[95] = errorer("indefinite length bytes/strings are not supported");
|
|
1077
|
-
for (let i = 96; i <= 119; i++) {
|
|
1078
|
-
jump[i] = decodeStringCompact;
|
|
1079
|
-
}
|
|
1080
|
-
jump[120] = decodeString8;
|
|
1081
|
-
jump[121] = decodeString16;
|
|
1082
|
-
jump[122] = decodeString32;
|
|
1083
|
-
jump[123] = decodeString64;
|
|
1084
|
-
jump[124] = invalidMinor;
|
|
1085
|
-
jump[125] = invalidMinor;
|
|
1086
|
-
jump[126] = invalidMinor;
|
|
1087
|
-
jump[127] = errorer("indefinite length bytes/strings are not supported");
|
|
1088
|
-
for (let i = 128; i <= 151; i++) {
|
|
1089
|
-
jump[i] = decodeArrayCompact;
|
|
1090
|
-
}
|
|
1091
|
-
jump[152] = decodeArray8;
|
|
1092
|
-
jump[153] = decodeArray16;
|
|
1093
|
-
jump[154] = decodeArray32;
|
|
1094
|
-
jump[155] = decodeArray64;
|
|
1095
|
-
jump[156] = invalidMinor;
|
|
1096
|
-
jump[157] = invalidMinor;
|
|
1097
|
-
jump[158] = invalidMinor;
|
|
1098
|
-
jump[159] = decodeArrayIndefinite;
|
|
1099
|
-
for (let i = 160; i <= 183; i++) {
|
|
1100
|
-
jump[i] = decodeMapCompact;
|
|
1101
|
-
}
|
|
1102
|
-
jump[184] = decodeMap8;
|
|
1103
|
-
jump[185] = decodeMap16;
|
|
1104
|
-
jump[186] = decodeMap32;
|
|
1105
|
-
jump[187] = decodeMap64;
|
|
1106
|
-
jump[188] = invalidMinor;
|
|
1107
|
-
jump[189] = invalidMinor;
|
|
1108
|
-
jump[190] = invalidMinor;
|
|
1109
|
-
jump[191] = decodeMapIndefinite;
|
|
1110
|
-
for (let i = 192; i <= 215; i++) {
|
|
1111
|
-
jump[i] = decodeTagCompact;
|
|
1112
|
-
}
|
|
1113
|
-
jump[216] = decodeTag8;
|
|
1114
|
-
jump[217] = decodeTag16;
|
|
1115
|
-
jump[218] = decodeTag32;
|
|
1116
|
-
jump[219] = decodeTag64;
|
|
1117
|
-
jump[220] = invalidMinor;
|
|
1118
|
-
jump[221] = invalidMinor;
|
|
1119
|
-
jump[222] = invalidMinor;
|
|
1120
|
-
jump[223] = invalidMinor;
|
|
1121
|
-
for (let i = 224; i <= 243; i++) {
|
|
1122
|
-
jump[i] = errorer("simple values are not supported");
|
|
1123
|
-
}
|
|
1124
|
-
jump[244] = invalidMinor;
|
|
1125
|
-
jump[245] = invalidMinor;
|
|
1126
|
-
jump[246] = invalidMinor;
|
|
1127
|
-
jump[247] = decodeUndefined;
|
|
1128
|
-
jump[248] = errorer("simple values are not supported");
|
|
1129
|
-
jump[249] = decodeFloat16;
|
|
1130
|
-
jump[250] = decodeFloat32;
|
|
1131
|
-
jump[251] = decodeFloat64;
|
|
1132
|
-
jump[252] = invalidMinor;
|
|
1133
|
-
jump[253] = invalidMinor;
|
|
1134
|
-
jump[254] = invalidMinor;
|
|
1135
|
-
jump[255] = decodeBreak;
|
|
1136
|
-
var quick = [];
|
|
1137
|
-
for (let i = 0; i < 24; i++) {
|
|
1138
|
-
quick[i] = new Token(Type.uint, i, 1);
|
|
1139
|
-
}
|
|
1140
|
-
for (let i = -1; i >= -24; i--) {
|
|
1141
|
-
quick[31 - i] = new Token(Type.negint, i, 1);
|
|
1142
|
-
}
|
|
1143
|
-
quick[64] = new Token(Type.bytes, new Uint8Array(0), 1);
|
|
1144
|
-
quick[96] = new Token(Type.string, "", 1);
|
|
1145
|
-
quick[128] = new Token(Type.array, 0, 1);
|
|
1146
|
-
quick[160] = new Token(Type.map, 0, 1);
|
|
1147
|
-
quick[244] = new Token(Type.false, false, 1);
|
|
1148
|
-
quick[245] = new Token(Type.true, true, 1);
|
|
1149
|
-
quick[246] = new Token(Type.null, null, 1);
|
|
1150
|
-
function quickEncodeToken(token) {
|
|
1151
|
-
switch (token.type) {
|
|
1152
|
-
case Type.false:
|
|
1153
|
-
return fromArray([244]);
|
|
1154
|
-
case Type.true:
|
|
1155
|
-
return fromArray([245]);
|
|
1156
|
-
case Type.null:
|
|
1157
|
-
return fromArray([246]);
|
|
1158
|
-
case Type.bytes:
|
|
1159
|
-
if (!token.value.length) {
|
|
1160
|
-
return fromArray([64]);
|
|
1161
|
-
}
|
|
1162
|
-
return;
|
|
1163
|
-
case Type.string:
|
|
1164
|
-
if (token.value === "") {
|
|
1165
|
-
return fromArray([96]);
|
|
1166
|
-
}
|
|
1167
|
-
return;
|
|
1168
|
-
case Type.array:
|
|
1169
|
-
if (token.value === 0) {
|
|
1170
|
-
return fromArray([128]);
|
|
1171
|
-
}
|
|
1172
|
-
return;
|
|
1173
|
-
case Type.map:
|
|
1174
|
-
if (token.value === 0) {
|
|
1175
|
-
return fromArray([160]);
|
|
1176
|
-
}
|
|
1177
|
-
return;
|
|
1178
|
-
case Type.uint:
|
|
1179
|
-
if (token.value < 24) {
|
|
1180
|
-
return fromArray([Number(token.value)]);
|
|
1181
|
-
}
|
|
1182
|
-
return;
|
|
1183
|
-
case Type.negint:
|
|
1184
|
-
if (token.value >= -24) {
|
|
1185
|
-
return fromArray([31 - Number(token.value)]);
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
// ../../../node_modules/.pnpm/cborg@4.0.5/node_modules/cborg/lib/encode.js
|
|
1191
|
-
var defaultEncodeOptions = {
|
|
1192
|
-
float64: false,
|
|
1193
|
-
mapSorter,
|
|
1194
|
-
quickEncodeToken
|
|
1195
|
-
};
|
|
1196
|
-
function makeCborEncoders() {
|
|
1197
|
-
const encoders = [];
|
|
1198
|
-
encoders[Type.uint.major] = encodeUint;
|
|
1199
|
-
encoders[Type.negint.major] = encodeNegint;
|
|
1200
|
-
encoders[Type.bytes.major] = encodeBytes;
|
|
1201
|
-
encoders[Type.string.major] = encodeString;
|
|
1202
|
-
encoders[Type.array.major] = encodeArray;
|
|
1203
|
-
encoders[Type.map.major] = encodeMap;
|
|
1204
|
-
encoders[Type.tag.major] = encodeTag;
|
|
1205
|
-
encoders[Type.float.major] = encodeFloat;
|
|
1206
|
-
return encoders;
|
|
1207
|
-
}
|
|
1208
|
-
var cborEncoders = makeCborEncoders();
|
|
1209
|
-
var buf = new Bl();
|
|
1210
|
-
var Ref = class _Ref {
|
|
1211
|
-
/**
|
|
1212
|
-
* @param {object|any[]} obj
|
|
1213
|
-
* @param {Reference|undefined} parent
|
|
1214
|
-
*/
|
|
1215
|
-
constructor(obj, parent) {
|
|
1216
|
-
this.obj = obj;
|
|
1217
|
-
this.parent = parent;
|
|
1218
|
-
}
|
|
1219
|
-
/**
|
|
1220
|
-
* @param {object|any[]} obj
|
|
1221
|
-
* @returns {boolean}
|
|
1222
|
-
*/
|
|
1223
|
-
includes(obj) {
|
|
1224
|
-
let p = this;
|
|
1225
|
-
do {
|
|
1226
|
-
if (p.obj === obj) {
|
|
1227
|
-
return true;
|
|
1228
|
-
}
|
|
1229
|
-
} while (p = p.parent);
|
|
1230
|
-
return false;
|
|
1231
|
-
}
|
|
1232
|
-
/**
|
|
1233
|
-
* @param {Reference|undefined} stack
|
|
1234
|
-
* @param {object|any[]} obj
|
|
1235
|
-
* @returns {Reference}
|
|
1236
|
-
*/
|
|
1237
|
-
static createCheck(stack, obj) {
|
|
1238
|
-
if (stack && stack.includes(obj)) {
|
|
1239
|
-
throw new Error(`${encodeErrPrefix} object contains circular references`);
|
|
1240
|
-
}
|
|
1241
|
-
return new _Ref(obj, stack);
|
|
1242
|
-
}
|
|
1243
|
-
};
|
|
1244
|
-
var simpleTokens = {
|
|
1245
|
-
null: new Token(Type.null, null),
|
|
1246
|
-
undefined: new Token(Type.undefined, void 0),
|
|
1247
|
-
true: new Token(Type.true, true),
|
|
1248
|
-
false: new Token(Type.false, false),
|
|
1249
|
-
emptyArray: new Token(Type.array, 0),
|
|
1250
|
-
emptyMap: new Token(Type.map, 0)
|
|
1251
|
-
};
|
|
1252
|
-
var typeEncoders = {
|
|
1253
|
-
/**
|
|
1254
|
-
* @param {any} obj
|
|
1255
|
-
* @param {string} _typ
|
|
1256
|
-
* @param {EncodeOptions} _options
|
|
1257
|
-
* @param {Reference} [_refStack]
|
|
1258
|
-
* @returns {TokenOrNestedTokens}
|
|
1259
|
-
*/
|
|
1260
|
-
number(obj, _typ, _options, _refStack) {
|
|
1261
|
-
if (!Number.isInteger(obj) || !Number.isSafeInteger(obj)) {
|
|
1262
|
-
return new Token(Type.float, obj);
|
|
1263
|
-
} else if (obj >= 0) {
|
|
1264
|
-
return new Token(Type.uint, obj);
|
|
1265
|
-
} else {
|
|
1266
|
-
return new Token(Type.negint, obj);
|
|
1267
|
-
}
|
|
1268
|
-
},
|
|
1269
|
-
/**
|
|
1270
|
-
* @param {any} obj
|
|
1271
|
-
* @param {string} _typ
|
|
1272
|
-
* @param {EncodeOptions} _options
|
|
1273
|
-
* @param {Reference} [_refStack]
|
|
1274
|
-
* @returns {TokenOrNestedTokens}
|
|
1275
|
-
*/
|
|
1276
|
-
bigint(obj, _typ, _options, _refStack) {
|
|
1277
|
-
if (obj >= BigInt(0)) {
|
|
1278
|
-
return new Token(Type.uint, obj);
|
|
1279
|
-
} else {
|
|
1280
|
-
return new Token(Type.negint, obj);
|
|
1281
|
-
}
|
|
1282
|
-
},
|
|
1283
|
-
/**
|
|
1284
|
-
* @param {any} obj
|
|
1285
|
-
* @param {string} _typ
|
|
1286
|
-
* @param {EncodeOptions} _options
|
|
1287
|
-
* @param {Reference} [_refStack]
|
|
1288
|
-
* @returns {TokenOrNestedTokens}
|
|
1289
|
-
*/
|
|
1290
|
-
Uint8Array(obj, _typ, _options, _refStack) {
|
|
1291
|
-
return new Token(Type.bytes, obj);
|
|
1292
|
-
},
|
|
1293
|
-
/**
|
|
1294
|
-
* @param {any} obj
|
|
1295
|
-
* @param {string} _typ
|
|
1296
|
-
* @param {EncodeOptions} _options
|
|
1297
|
-
* @param {Reference} [_refStack]
|
|
1298
|
-
* @returns {TokenOrNestedTokens}
|
|
1299
|
-
*/
|
|
1300
|
-
string(obj, _typ, _options, _refStack) {
|
|
1301
|
-
return new Token(Type.string, obj);
|
|
1302
|
-
},
|
|
1303
|
-
/**
|
|
1304
|
-
* @param {any} obj
|
|
1305
|
-
* @param {string} _typ
|
|
1306
|
-
* @param {EncodeOptions} _options
|
|
1307
|
-
* @param {Reference} [_refStack]
|
|
1308
|
-
* @returns {TokenOrNestedTokens}
|
|
1309
|
-
*/
|
|
1310
|
-
boolean(obj, _typ, _options, _refStack) {
|
|
1311
|
-
return obj ? simpleTokens.true : simpleTokens.false;
|
|
1312
|
-
},
|
|
1313
|
-
/**
|
|
1314
|
-
* @param {any} _obj
|
|
1315
|
-
* @param {string} _typ
|
|
1316
|
-
* @param {EncodeOptions} _options
|
|
1317
|
-
* @param {Reference} [_refStack]
|
|
1318
|
-
* @returns {TokenOrNestedTokens}
|
|
1319
|
-
*/
|
|
1320
|
-
null(_obj, _typ, _options, _refStack) {
|
|
1321
|
-
return simpleTokens.null;
|
|
1322
|
-
},
|
|
1323
|
-
/**
|
|
1324
|
-
* @param {any} _obj
|
|
1325
|
-
* @param {string} _typ
|
|
1326
|
-
* @param {EncodeOptions} _options
|
|
1327
|
-
* @param {Reference} [_refStack]
|
|
1328
|
-
* @returns {TokenOrNestedTokens}
|
|
1329
|
-
*/
|
|
1330
|
-
undefined(_obj, _typ, _options, _refStack) {
|
|
1331
|
-
return simpleTokens.undefined;
|
|
1332
|
-
},
|
|
1333
|
-
/**
|
|
1334
|
-
* @param {any} obj
|
|
1335
|
-
* @param {string} _typ
|
|
1336
|
-
* @param {EncodeOptions} _options
|
|
1337
|
-
* @param {Reference} [_refStack]
|
|
1338
|
-
* @returns {TokenOrNestedTokens}
|
|
1339
|
-
*/
|
|
1340
|
-
ArrayBuffer(obj, _typ, _options, _refStack) {
|
|
1341
|
-
return new Token(Type.bytes, new Uint8Array(obj));
|
|
1342
|
-
},
|
|
1343
|
-
/**
|
|
1344
|
-
* @param {any} obj
|
|
1345
|
-
* @param {string} _typ
|
|
1346
|
-
* @param {EncodeOptions} _options
|
|
1347
|
-
* @param {Reference} [_refStack]
|
|
1348
|
-
* @returns {TokenOrNestedTokens}
|
|
1349
|
-
*/
|
|
1350
|
-
DataView(obj, _typ, _options, _refStack) {
|
|
1351
|
-
return new Token(Type.bytes, new Uint8Array(obj.buffer, obj.byteOffset, obj.byteLength));
|
|
1352
|
-
},
|
|
1353
|
-
/**
|
|
1354
|
-
* @param {any} obj
|
|
1355
|
-
* @param {string} _typ
|
|
1356
|
-
* @param {EncodeOptions} options
|
|
1357
|
-
* @param {Reference} [refStack]
|
|
1358
|
-
* @returns {TokenOrNestedTokens}
|
|
1359
|
-
*/
|
|
1360
|
-
Array(obj, _typ, options, refStack) {
|
|
1361
|
-
if (!obj.length) {
|
|
1362
|
-
if (options.addBreakTokens === true) {
|
|
1363
|
-
return [simpleTokens.emptyArray, new Token(Type.break)];
|
|
1364
|
-
}
|
|
1365
|
-
return simpleTokens.emptyArray;
|
|
1366
|
-
}
|
|
1367
|
-
refStack = Ref.createCheck(refStack, obj);
|
|
1368
|
-
const entries = [];
|
|
1369
|
-
let i = 0;
|
|
1370
|
-
for (const e of obj) {
|
|
1371
|
-
entries[i++] = objectToTokens(e, options, refStack);
|
|
1372
|
-
}
|
|
1373
|
-
if (options.addBreakTokens) {
|
|
1374
|
-
return [new Token(Type.array, obj.length), entries, new Token(Type.break)];
|
|
1375
|
-
}
|
|
1376
|
-
return [new Token(Type.array, obj.length), entries];
|
|
1377
|
-
},
|
|
1378
|
-
/**
|
|
1379
|
-
* @param {any} obj
|
|
1380
|
-
* @param {string} typ
|
|
1381
|
-
* @param {EncodeOptions} options
|
|
1382
|
-
* @param {Reference} [refStack]
|
|
1383
|
-
* @returns {TokenOrNestedTokens}
|
|
1384
|
-
*/
|
|
1385
|
-
Object(obj, typ, options, refStack) {
|
|
1386
|
-
const isMap = typ !== "Object";
|
|
1387
|
-
const keys = isMap ? obj.keys() : Object.keys(obj);
|
|
1388
|
-
const length2 = isMap ? obj.size : keys.length;
|
|
1389
|
-
if (!length2) {
|
|
1390
|
-
if (options.addBreakTokens === true) {
|
|
1391
|
-
return [simpleTokens.emptyMap, new Token(Type.break)];
|
|
1392
|
-
}
|
|
1393
|
-
return simpleTokens.emptyMap;
|
|
1394
|
-
}
|
|
1395
|
-
refStack = Ref.createCheck(refStack, obj);
|
|
1396
|
-
const entries = [];
|
|
1397
|
-
let i = 0;
|
|
1398
|
-
for (const key of keys) {
|
|
1399
|
-
entries[i++] = [
|
|
1400
|
-
objectToTokens(key, options, refStack),
|
|
1401
|
-
objectToTokens(isMap ? obj.get(key) : obj[key], options, refStack)
|
|
1402
|
-
];
|
|
1403
|
-
}
|
|
1404
|
-
sortMapEntries(entries, options);
|
|
1405
|
-
if (options.addBreakTokens) {
|
|
1406
|
-
return [new Token(Type.map, length2), entries, new Token(Type.break)];
|
|
1407
|
-
}
|
|
1408
|
-
return [new Token(Type.map, length2), entries];
|
|
1409
|
-
}
|
|
1410
|
-
};
|
|
1411
|
-
typeEncoders.Map = typeEncoders.Object;
|
|
1412
|
-
typeEncoders.Buffer = typeEncoders.Uint8Array;
|
|
1413
|
-
for (const typ of "Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" ")) {
|
|
1414
|
-
typeEncoders[`${typ}Array`] = typeEncoders.DataView;
|
|
1415
|
-
}
|
|
1416
|
-
function objectToTokens(obj, options = {}, refStack) {
|
|
1417
|
-
const typ = is(obj);
|
|
1418
|
-
const customTypeEncoder = options && options.typeEncoders && /** @type {OptionalTypeEncoder} */
|
|
1419
|
-
options.typeEncoders[typ] || typeEncoders[typ];
|
|
1420
|
-
if (typeof customTypeEncoder === "function") {
|
|
1421
|
-
const tokens = customTypeEncoder(obj, typ, options, refStack);
|
|
1422
|
-
if (tokens != null) {
|
|
1423
|
-
return tokens;
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
const typeEncoder = typeEncoders[typ];
|
|
1427
|
-
if (!typeEncoder) {
|
|
1428
|
-
throw new Error(`${encodeErrPrefix} unsupported type: ${typ}`);
|
|
1429
|
-
}
|
|
1430
|
-
return typeEncoder(obj, typ, options, refStack);
|
|
1431
|
-
}
|
|
1432
|
-
function sortMapEntries(entries, options) {
|
|
1433
|
-
if (options.mapSorter) {
|
|
1434
|
-
entries.sort(options.mapSorter);
|
|
1435
|
-
}
|
|
1436
|
-
}
|
|
1437
|
-
function mapSorter(e1, e2) {
|
|
1438
|
-
const keyToken1 = Array.isArray(e1[0]) ? e1[0][0] : e1[0];
|
|
1439
|
-
const keyToken2 = Array.isArray(e2[0]) ? e2[0][0] : e2[0];
|
|
1440
|
-
if (keyToken1.type !== keyToken2.type) {
|
|
1441
|
-
return keyToken1.type.compare(keyToken2.type);
|
|
1442
|
-
}
|
|
1443
|
-
const major = keyToken1.type.major;
|
|
1444
|
-
const tcmp = cborEncoders[major].compareTokens(keyToken1, keyToken2);
|
|
1445
|
-
if (tcmp === 0) {
|
|
1446
|
-
console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone");
|
|
1447
|
-
}
|
|
1448
|
-
return tcmp;
|
|
1449
|
-
}
|
|
1450
|
-
function tokensToEncoded(buf2, tokens, encoders, options) {
|
|
1451
|
-
if (Array.isArray(tokens)) {
|
|
1452
|
-
for (const token of tokens) {
|
|
1453
|
-
tokensToEncoded(buf2, token, encoders, options);
|
|
1454
|
-
}
|
|
1455
|
-
} else {
|
|
1456
|
-
encoders[tokens.type.major](buf2, tokens, options);
|
|
1457
|
-
}
|
|
1458
|
-
}
|
|
1459
|
-
function encodeCustom(data, encoders, options) {
|
|
1460
|
-
const tokens = objectToTokens(data, options);
|
|
1461
|
-
if (!Array.isArray(tokens) && options.quickEncodeToken) {
|
|
1462
|
-
const quickBytes = options.quickEncodeToken(tokens);
|
|
1463
|
-
if (quickBytes) {
|
|
1464
|
-
return quickBytes;
|
|
1465
|
-
}
|
|
1466
|
-
const encoder = encoders[tokens.type.major];
|
|
1467
|
-
if (encoder.encodedSize) {
|
|
1468
|
-
const size = encoder.encodedSize(tokens, options);
|
|
1469
|
-
const buf2 = new Bl(size);
|
|
1470
|
-
encoder(buf2, tokens, options);
|
|
1471
|
-
if (buf2.chunks.length !== 1) {
|
|
1472
|
-
throw new Error(`Unexpected error: pre-calculated length for ${tokens} was wrong`);
|
|
1473
|
-
}
|
|
1474
|
-
return asU8A(buf2.chunks[0]);
|
|
1475
|
-
}
|
|
1476
|
-
}
|
|
1477
|
-
buf.reset();
|
|
1478
|
-
tokensToEncoded(buf, tokens, encoders, options);
|
|
1479
|
-
return buf.toBytes(true);
|
|
1480
|
-
}
|
|
1481
|
-
function encode(data, options) {
|
|
1482
|
-
options = Object.assign({}, defaultEncodeOptions, options);
|
|
1483
|
-
return encodeCustom(data, cborEncoders, options);
|
|
1484
|
-
}
|
|
1485
|
-
|
|
1486
|
-
// ../../../node_modules/.pnpm/cborg@4.0.5/node_modules/cborg/lib/decode.js
|
|
1487
|
-
var defaultDecodeOptions = {
|
|
1488
|
-
strict: false,
|
|
1489
|
-
allowIndefinite: true,
|
|
1490
|
-
allowUndefined: true,
|
|
1491
|
-
allowBigInt: true
|
|
1492
|
-
};
|
|
1493
|
-
var Tokeniser = class {
|
|
1494
|
-
/**
|
|
1495
|
-
* @param {Uint8Array} data
|
|
1496
|
-
* @param {DecodeOptions} options
|
|
1497
|
-
*/
|
|
1498
|
-
constructor(data, options = {}) {
|
|
1499
|
-
this._pos = 0;
|
|
1500
|
-
this.data = data;
|
|
1501
|
-
this.options = options;
|
|
1502
|
-
}
|
|
1503
|
-
pos() {
|
|
1504
|
-
return this._pos;
|
|
1505
|
-
}
|
|
1506
|
-
done() {
|
|
1507
|
-
return this._pos >= this.data.length;
|
|
1508
|
-
}
|
|
1509
|
-
next() {
|
|
1510
|
-
const byt = this.data[this._pos];
|
|
1511
|
-
let token = quick[byt];
|
|
1512
|
-
if (token === void 0) {
|
|
1513
|
-
const decoder = jump[byt];
|
|
1514
|
-
if (!decoder) {
|
|
1515
|
-
throw new Error(`${decodeErrPrefix} no decoder for major type ${byt >>> 5} (byte 0x${byt.toString(16).padStart(2, "0")})`);
|
|
1516
|
-
}
|
|
1517
|
-
const minor = byt & 31;
|
|
1518
|
-
token = decoder(this.data, this._pos, minor, this.options);
|
|
1519
|
-
}
|
|
1520
|
-
this._pos += token.encodedLength;
|
|
1521
|
-
return token;
|
|
1522
|
-
}
|
|
1523
|
-
};
|
|
1524
|
-
var DONE = Symbol.for("DONE");
|
|
1525
|
-
var BREAK = Symbol.for("BREAK");
|
|
1526
|
-
function tokenToArray(token, tokeniser, options) {
|
|
1527
|
-
const arr = [];
|
|
1528
|
-
for (let i = 0; i < token.value; i++) {
|
|
1529
|
-
const value = tokensToObject(tokeniser, options);
|
|
1530
|
-
if (value === BREAK) {
|
|
1531
|
-
if (token.value === Infinity) {
|
|
1532
|
-
break;
|
|
1533
|
-
}
|
|
1534
|
-
throw new Error(`${decodeErrPrefix} got unexpected break to lengthed array`);
|
|
1535
|
-
}
|
|
1536
|
-
if (value === DONE) {
|
|
1537
|
-
throw new Error(`${decodeErrPrefix} found array but not enough entries (got ${i}, expected ${token.value})`);
|
|
1538
|
-
}
|
|
1539
|
-
arr[i] = value;
|
|
1540
|
-
}
|
|
1541
|
-
return arr;
|
|
1542
|
-
}
|
|
1543
|
-
function tokenToMap(token, tokeniser, options) {
|
|
1544
|
-
const useMaps = options.useMaps === true;
|
|
1545
|
-
const obj = useMaps ? void 0 : {};
|
|
1546
|
-
const m = useMaps ? /* @__PURE__ */ new Map() : void 0;
|
|
1547
|
-
for (let i = 0; i < token.value; i++) {
|
|
1548
|
-
const key = tokensToObject(tokeniser, options);
|
|
1549
|
-
if (key === BREAK) {
|
|
1550
|
-
if (token.value === Infinity) {
|
|
1551
|
-
break;
|
|
1552
|
-
}
|
|
1553
|
-
throw new Error(`${decodeErrPrefix} got unexpected break to lengthed map`);
|
|
1554
|
-
}
|
|
1555
|
-
if (key === DONE) {
|
|
1556
|
-
throw new Error(`${decodeErrPrefix} found map but not enough entries (got ${i} [no key], expected ${token.value})`);
|
|
1557
|
-
}
|
|
1558
|
-
if (useMaps !== true && typeof key !== "string") {
|
|
1559
|
-
throw new Error(`${decodeErrPrefix} non-string keys not supported (got ${typeof key})`);
|
|
1560
|
-
}
|
|
1561
|
-
if (options.rejectDuplicateMapKeys === true) {
|
|
1562
|
-
if (useMaps && m.has(key) || !useMaps && key in obj) {
|
|
1563
|
-
throw new Error(`${decodeErrPrefix} found repeat map key "${key}"`);
|
|
1564
|
-
}
|
|
1565
|
-
}
|
|
1566
|
-
const value = tokensToObject(tokeniser, options);
|
|
1567
|
-
if (value === DONE) {
|
|
1568
|
-
throw new Error(`${decodeErrPrefix} found map but not enough entries (got ${i} [no value], expected ${token.value})`);
|
|
1569
|
-
}
|
|
1570
|
-
if (useMaps) {
|
|
1571
|
-
m.set(key, value);
|
|
1572
|
-
} else {
|
|
1573
|
-
obj[key] = value;
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
return useMaps ? m : obj;
|
|
1577
|
-
}
|
|
1578
|
-
function tokensToObject(tokeniser, options) {
|
|
1579
|
-
if (tokeniser.done()) {
|
|
1580
|
-
return DONE;
|
|
1581
|
-
}
|
|
1582
|
-
const token = tokeniser.next();
|
|
1583
|
-
if (token.type === Type.break) {
|
|
1584
|
-
return BREAK;
|
|
1585
|
-
}
|
|
1586
|
-
if (token.type.terminal) {
|
|
1587
|
-
return token.value;
|
|
1588
|
-
}
|
|
1589
|
-
if (token.type === Type.array) {
|
|
1590
|
-
return tokenToArray(token, tokeniser, options);
|
|
1591
|
-
}
|
|
1592
|
-
if (token.type === Type.map) {
|
|
1593
|
-
return tokenToMap(token, tokeniser, options);
|
|
1594
|
-
}
|
|
1595
|
-
if (token.type === Type.tag) {
|
|
1596
|
-
if (options.tags && typeof options.tags[token.value] === "function") {
|
|
1597
|
-
const tagged = tokensToObject(tokeniser, options);
|
|
1598
|
-
return options.tags[token.value](tagged);
|
|
1599
|
-
}
|
|
1600
|
-
throw new Error(`${decodeErrPrefix} tag not supported (${token.value})`);
|
|
1601
|
-
}
|
|
1602
|
-
throw new Error("unsupported");
|
|
1603
|
-
}
|
|
1604
|
-
function decodeFirst(data, options) {
|
|
1605
|
-
if (!(data instanceof Uint8Array)) {
|
|
1606
|
-
throw new Error(`${decodeErrPrefix} data to decode must be a Uint8Array`);
|
|
1607
|
-
}
|
|
1608
|
-
options = Object.assign({}, defaultDecodeOptions, options);
|
|
1609
|
-
const tokeniser = options.tokenizer || new Tokeniser(data, options);
|
|
1610
|
-
const decoded = tokensToObject(tokeniser, options);
|
|
1611
|
-
if (decoded === DONE) {
|
|
1612
|
-
throw new Error(`${decodeErrPrefix} did not find any content to decode`);
|
|
1613
|
-
}
|
|
1614
|
-
if (decoded === BREAK) {
|
|
1615
|
-
throw new Error(`${decodeErrPrefix} got unexpected break`);
|
|
1616
|
-
}
|
|
1617
|
-
return [decoded, data.subarray(tokeniser.pos())];
|
|
1618
|
-
}
|
|
1619
|
-
function decode(data, options) {
|
|
1620
|
-
const [decoded, remainder] = decodeFirst(data, options);
|
|
1621
|
-
if (remainder.length > 0) {
|
|
1622
|
-
throw new Error(`${decodeErrPrefix} too many terminals, data makes no sense`);
|
|
1623
|
-
}
|
|
1624
|
-
return decoded;
|
|
1625
|
-
}
|
|
1626
|
-
|
|
1627
|
-
// ../../../node_modules/.pnpm/cborg@4.0.5/node_modules/cborg/lib/json/encode.js
|
|
1628
|
-
var JSONEncoder = class extends Array {
|
|
1629
|
-
constructor() {
|
|
1630
|
-
super();
|
|
1631
|
-
this.inRecursive = [];
|
|
1632
|
-
}
|
|
1633
|
-
/**
|
|
1634
|
-
* @param {Bl} buf
|
|
1635
|
-
*/
|
|
1636
|
-
prefix(buf2) {
|
|
1637
|
-
const recurs = this.inRecursive[this.inRecursive.length - 1];
|
|
1638
|
-
if (recurs) {
|
|
1639
|
-
if (recurs.type === Type.array) {
|
|
1640
|
-
recurs.elements++;
|
|
1641
|
-
if (recurs.elements !== 1) {
|
|
1642
|
-
buf2.push([44]);
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
if (recurs.type === Type.map) {
|
|
1646
|
-
recurs.elements++;
|
|
1647
|
-
if (recurs.elements !== 1) {
|
|
1648
|
-
if (recurs.elements % 2 === 1) {
|
|
1649
|
-
buf2.push([44]);
|
|
1650
|
-
} else {
|
|
1651
|
-
buf2.push([58]);
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
/**
|
|
1658
|
-
* @param {Bl} buf
|
|
1659
|
-
* @param {Token} token
|
|
1660
|
-
*/
|
|
1661
|
-
[Type.uint.major](buf2, token) {
|
|
1662
|
-
this.prefix(buf2);
|
|
1663
|
-
const is2 = String(token.value);
|
|
1664
|
-
const isa = [];
|
|
1665
|
-
for (let i = 0; i < is2.length; i++) {
|
|
1666
|
-
isa[i] = is2.charCodeAt(i);
|
|
1667
|
-
}
|
|
1668
|
-
buf2.push(isa);
|
|
1669
|
-
}
|
|
1670
|
-
/**
|
|
1671
|
-
* @param {Bl} buf
|
|
1672
|
-
* @param {Token} token
|
|
1673
|
-
*/
|
|
1674
|
-
[Type.negint.major](buf2, token) {
|
|
1675
|
-
this[Type.uint.major](buf2, token);
|
|
1676
|
-
}
|
|
1677
|
-
/**
|
|
1678
|
-
* @param {Bl} _buf
|
|
1679
|
-
* @param {Token} _token
|
|
1680
|
-
*/
|
|
1681
|
-
[Type.bytes.major](_buf, _token) {
|
|
1682
|
-
throw new Error(`${encodeErrPrefix} unsupported type: Uint8Array`);
|
|
1683
|
-
}
|
|
1684
|
-
/**
|
|
1685
|
-
* @param {Bl} buf
|
|
1686
|
-
* @param {Token} token
|
|
1687
|
-
*/
|
|
1688
|
-
[Type.string.major](buf2, token) {
|
|
1689
|
-
this.prefix(buf2);
|
|
1690
|
-
const byts = fromString(JSON.stringify(token.value));
|
|
1691
|
-
buf2.push(byts.length > 32 ? asU8A(byts) : byts);
|
|
1692
|
-
}
|
|
1693
|
-
/**
|
|
1694
|
-
* @param {Bl} buf
|
|
1695
|
-
* @param {Token} _token
|
|
1696
|
-
*/
|
|
1697
|
-
[Type.array.major](buf2, _token) {
|
|
1698
|
-
this.prefix(buf2);
|
|
1699
|
-
this.inRecursive.push({ type: Type.array, elements: 0 });
|
|
1700
|
-
buf2.push([91]);
|
|
1701
|
-
}
|
|
1702
|
-
/**
|
|
1703
|
-
* @param {Bl} buf
|
|
1704
|
-
* @param {Token} _token
|
|
1705
|
-
*/
|
|
1706
|
-
[Type.map.major](buf2, _token) {
|
|
1707
|
-
this.prefix(buf2);
|
|
1708
|
-
this.inRecursive.push({ type: Type.map, elements: 0 });
|
|
1709
|
-
buf2.push([123]);
|
|
1710
|
-
}
|
|
1711
|
-
/**
|
|
1712
|
-
* @param {Bl} _buf
|
|
1713
|
-
* @param {Token} _token
|
|
1714
|
-
*/
|
|
1715
|
-
[Type.tag.major](_buf, _token) {
|
|
1716
|
-
}
|
|
1717
|
-
/**
|
|
1718
|
-
* @param {Bl} buf
|
|
1719
|
-
* @param {Token} token
|
|
1720
|
-
*/
|
|
1721
|
-
[Type.float.major](buf2, token) {
|
|
1722
|
-
if (token.type.name === "break") {
|
|
1723
|
-
const recurs = this.inRecursive.pop();
|
|
1724
|
-
if (recurs) {
|
|
1725
|
-
if (recurs.type === Type.array) {
|
|
1726
|
-
buf2.push([93]);
|
|
1727
|
-
} else if (recurs.type === Type.map) {
|
|
1728
|
-
buf2.push([125]);
|
|
1729
|
-
} else {
|
|
1730
|
-
throw new Error("Unexpected recursive type; this should not happen!");
|
|
1731
|
-
}
|
|
1732
|
-
return;
|
|
1733
|
-
}
|
|
1734
|
-
throw new Error("Unexpected break; this should not happen!");
|
|
1735
|
-
}
|
|
1736
|
-
if (token.value === void 0) {
|
|
1737
|
-
throw new Error(`${encodeErrPrefix} unsupported type: undefined`);
|
|
1738
|
-
}
|
|
1739
|
-
this.prefix(buf2);
|
|
1740
|
-
if (token.type.name === "true") {
|
|
1741
|
-
buf2.push([116, 114, 117, 101]);
|
|
1742
|
-
return;
|
|
1743
|
-
} else if (token.type.name === "false") {
|
|
1744
|
-
buf2.push([102, 97, 108, 115, 101]);
|
|
1745
|
-
return;
|
|
1746
|
-
} else if (token.type.name === "null") {
|
|
1747
|
-
buf2.push([110, 117, 108, 108]);
|
|
1748
|
-
return;
|
|
1749
|
-
}
|
|
1750
|
-
const is2 = String(token.value);
|
|
1751
|
-
const isa = [];
|
|
1752
|
-
let dp = false;
|
|
1753
|
-
for (let i = 0; i < is2.length; i++) {
|
|
1754
|
-
isa[i] = is2.charCodeAt(i);
|
|
1755
|
-
if (!dp && (isa[i] === 46 || isa[i] === 101 || isa[i] === 69)) {
|
|
1756
|
-
dp = true;
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
if (!dp) {
|
|
1760
|
-
isa.push(46);
|
|
1761
|
-
isa.push(48);
|
|
1762
|
-
}
|
|
1763
|
-
buf2.push(isa);
|
|
1764
|
-
}
|
|
1765
|
-
};
|
|
1766
|
-
function mapSorter2(e1, e2) {
|
|
1767
|
-
if (Array.isArray(e1[0]) || Array.isArray(e2[0])) {
|
|
1768
|
-
throw new Error(`${encodeErrPrefix} complex map keys are not supported`);
|
|
1769
|
-
}
|
|
1770
|
-
const keyToken1 = e1[0];
|
|
1771
|
-
const keyToken2 = e2[0];
|
|
1772
|
-
if (keyToken1.type !== Type.string || keyToken2.type !== Type.string) {
|
|
1773
|
-
throw new Error(`${encodeErrPrefix} non-string map keys are not supported`);
|
|
1774
|
-
}
|
|
1775
|
-
if (keyToken1 < keyToken2) {
|
|
1776
|
-
return -1;
|
|
1777
|
-
}
|
|
1778
|
-
if (keyToken1 > keyToken2) {
|
|
1779
|
-
return 1;
|
|
1780
|
-
}
|
|
1781
|
-
throw new Error(`${encodeErrPrefix} unexpected duplicate map keys, this is not supported`);
|
|
1782
|
-
}
|
|
1783
|
-
var defaultEncodeOptions2 = { addBreakTokens: true, mapSorter: mapSorter2 };
|
|
1784
|
-
function encode2(data, options) {
|
|
1785
|
-
options = Object.assign({}, defaultEncodeOptions2, options);
|
|
1786
|
-
return encodeCustom(data, new JSONEncoder(), options);
|
|
1787
|
-
}
|
|
1788
|
-
|
|
1789
|
-
// ../../../node_modules/.pnpm/cborg@4.0.5/node_modules/cborg/lib/json/decode.js
|
|
1790
|
-
var Tokenizer = class {
|
|
1791
|
-
/**
|
|
1792
|
-
* @param {Uint8Array} data
|
|
1793
|
-
* @param {DecodeOptions} options
|
|
1794
|
-
*/
|
|
1795
|
-
constructor(data, options = {}) {
|
|
1796
|
-
this._pos = 0;
|
|
1797
|
-
this.data = data;
|
|
1798
|
-
this.options = options;
|
|
1799
|
-
this.modeStack = ["value"];
|
|
1800
|
-
this.lastToken = "";
|
|
1801
|
-
}
|
|
1802
|
-
pos() {
|
|
1803
|
-
return this._pos;
|
|
1804
|
-
}
|
|
1805
|
-
/**
|
|
1806
|
-
* @returns {boolean}
|
|
1807
|
-
*/
|
|
1808
|
-
done() {
|
|
1809
|
-
return this._pos >= this.data.length;
|
|
1810
|
-
}
|
|
1811
|
-
/**
|
|
1812
|
-
* @returns {number}
|
|
1813
|
-
*/
|
|
1814
|
-
ch() {
|
|
1815
|
-
return this.data[this._pos];
|
|
1816
|
-
}
|
|
1817
|
-
/**
|
|
1818
|
-
* @returns {string}
|
|
1819
|
-
*/
|
|
1820
|
-
currentMode() {
|
|
1821
|
-
return this.modeStack[this.modeStack.length - 1];
|
|
1822
|
-
}
|
|
1823
|
-
skipWhitespace() {
|
|
1824
|
-
let c = this.ch();
|
|
1825
|
-
while (c === 32 || c === 9 || c === 13 || c === 10) {
|
|
1826
|
-
c = this.data[++this._pos];
|
|
1827
|
-
}
|
|
1828
|
-
}
|
|
1829
|
-
/**
|
|
1830
|
-
* @param {number[]} str
|
|
1831
|
-
*/
|
|
1832
|
-
expect(str) {
|
|
1833
|
-
if (this.data.length - this._pos < str.length) {
|
|
1834
|
-
throw new Error(`${decodeErrPrefix} unexpected end of input at position ${this._pos}`);
|
|
1835
|
-
}
|
|
1836
|
-
for (let i = 0; i < str.length; i++) {
|
|
1837
|
-
if (this.data[this._pos++] !== str[i]) {
|
|
1838
|
-
throw new Error(`${decodeErrPrefix} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...str)}'`);
|
|
1839
|
-
}
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1842
|
-
parseNumber() {
|
|
1843
|
-
const startPos = this._pos;
|
|
1844
|
-
let negative = false;
|
|
1845
|
-
let float = false;
|
|
1846
|
-
const swallow = (chars) => {
|
|
1847
|
-
while (!this.done()) {
|
|
1848
|
-
const ch = this.ch();
|
|
1849
|
-
if (chars.includes(ch)) {
|
|
1850
|
-
this._pos++;
|
|
1851
|
-
} else {
|
|
1852
|
-
break;
|
|
1853
|
-
}
|
|
1854
|
-
}
|
|
1855
|
-
};
|
|
1856
|
-
if (this.ch() === 45) {
|
|
1857
|
-
negative = true;
|
|
1858
|
-
this._pos++;
|
|
1859
|
-
}
|
|
1860
|
-
if (this.ch() === 48) {
|
|
1861
|
-
this._pos++;
|
|
1862
|
-
if (this.ch() === 46) {
|
|
1863
|
-
this._pos++;
|
|
1864
|
-
float = true;
|
|
1865
|
-
} else {
|
|
1866
|
-
return new Token(Type.uint, 0, this._pos - startPos);
|
|
1867
|
-
}
|
|
1868
|
-
}
|
|
1869
|
-
swallow([48, 49, 50, 51, 52, 53, 54, 55, 56, 57]);
|
|
1870
|
-
if (negative && this._pos === startPos + 1) {
|
|
1871
|
-
throw new Error(`${decodeErrPrefix} unexpected token at position ${this._pos}`);
|
|
1872
|
-
}
|
|
1873
|
-
if (!this.done() && this.ch() === 46) {
|
|
1874
|
-
if (float) {
|
|
1875
|
-
throw new Error(`${decodeErrPrefix} unexpected token at position ${this._pos}`);
|
|
1876
|
-
}
|
|
1877
|
-
float = true;
|
|
1878
|
-
this._pos++;
|
|
1879
|
-
swallow([48, 49, 50, 51, 52, 53, 54, 55, 56, 57]);
|
|
1880
|
-
}
|
|
1881
|
-
if (!this.done() && (this.ch() === 101 || this.ch() === 69)) {
|
|
1882
|
-
float = true;
|
|
1883
|
-
this._pos++;
|
|
1884
|
-
if (!this.done() && (this.ch() === 43 || this.ch() === 45)) {
|
|
1885
|
-
this._pos++;
|
|
1886
|
-
}
|
|
1887
|
-
swallow([48, 49, 50, 51, 52, 53, 54, 55, 56, 57]);
|
|
1888
|
-
}
|
|
1889
|
-
const numStr = String.fromCharCode.apply(null, this.data.subarray(startPos, this._pos));
|
|
1890
|
-
const num = parseFloat(numStr);
|
|
1891
|
-
if (float) {
|
|
1892
|
-
return new Token(Type.float, num, this._pos - startPos);
|
|
1893
|
-
}
|
|
1894
|
-
if (this.options.allowBigInt !== true || Number.isSafeInteger(num)) {
|
|
1895
|
-
return new Token(num >= 0 ? Type.uint : Type.negint, num, this._pos - startPos);
|
|
1896
|
-
}
|
|
1897
|
-
return new Token(num >= 0 ? Type.uint : Type.negint, BigInt(numStr), this._pos - startPos);
|
|
1898
|
-
}
|
|
1899
|
-
/**
|
|
1900
|
-
* @returns {Token}
|
|
1901
|
-
*/
|
|
1902
|
-
parseString() {
|
|
1903
|
-
if (this.ch() !== 34) {
|
|
1904
|
-
throw new Error(`${decodeErrPrefix} unexpected character at position ${this._pos}; this shouldn't happen`);
|
|
1905
|
-
}
|
|
1906
|
-
this._pos++;
|
|
1907
|
-
for (let i = this._pos, l = 0; i < this.data.length && l < 65536; i++, l++) {
|
|
1908
|
-
const ch = this.data[i];
|
|
1909
|
-
if (ch === 92 || ch < 32 || ch >= 128) {
|
|
1910
|
-
break;
|
|
1911
|
-
}
|
|
1912
|
-
if (ch === 34) {
|
|
1913
|
-
const str = String.fromCharCode.apply(null, this.data.subarray(this._pos, i));
|
|
1914
|
-
this._pos = i + 1;
|
|
1915
|
-
return new Token(Type.string, str, l);
|
|
1916
|
-
}
|
|
1917
|
-
}
|
|
1918
|
-
const startPos = this._pos;
|
|
1919
|
-
const chars = [];
|
|
1920
|
-
const readu4 = () => {
|
|
1921
|
-
if (this._pos + 4 >= this.data.length) {
|
|
1922
|
-
throw new Error(`${decodeErrPrefix} unexpected end of unicode escape sequence at position ${this._pos}`);
|
|
1923
|
-
}
|
|
1924
|
-
let u4 = 0;
|
|
1925
|
-
for (let i = 0; i < 4; i++) {
|
|
1926
|
-
let ch = this.ch();
|
|
1927
|
-
if (ch >= 48 && ch <= 57) {
|
|
1928
|
-
ch -= 48;
|
|
1929
|
-
} else if (ch >= 97 && ch <= 102) {
|
|
1930
|
-
ch = ch - 97 + 10;
|
|
1931
|
-
} else if (ch >= 65 && ch <= 70) {
|
|
1932
|
-
ch = ch - 65 + 10;
|
|
1933
|
-
} else {
|
|
1934
|
-
throw new Error(`${decodeErrPrefix} unexpected unicode escape character at position ${this._pos}`);
|
|
1935
|
-
}
|
|
1936
|
-
u4 = u4 * 16 + ch;
|
|
1937
|
-
this._pos++;
|
|
1938
|
-
}
|
|
1939
|
-
return u4;
|
|
1940
|
-
};
|
|
1941
|
-
const readUtf8Char = () => {
|
|
1942
|
-
const firstByte = this.ch();
|
|
1943
|
-
let codePoint = null;
|
|
1944
|
-
let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
|
|
1945
|
-
if (this._pos + bytesPerSequence > this.data.length) {
|
|
1946
|
-
throw new Error(`${decodeErrPrefix} unexpected unicode sequence at position ${this._pos}`);
|
|
1947
|
-
}
|
|
1948
|
-
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
1949
|
-
switch (bytesPerSequence) {
|
|
1950
|
-
case 1:
|
|
1951
|
-
if (firstByte < 128) {
|
|
1952
|
-
codePoint = firstByte;
|
|
1953
|
-
}
|
|
1954
|
-
break;
|
|
1955
|
-
case 2:
|
|
1956
|
-
secondByte = this.data[this._pos + 1];
|
|
1957
|
-
if ((secondByte & 192) === 128) {
|
|
1958
|
-
tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
|
|
1959
|
-
if (tempCodePoint > 127) {
|
|
1960
|
-
codePoint = tempCodePoint;
|
|
1961
|
-
}
|
|
1962
|
-
}
|
|
1963
|
-
break;
|
|
1964
|
-
case 3:
|
|
1965
|
-
secondByte = this.data[this._pos + 1];
|
|
1966
|
-
thirdByte = this.data[this._pos + 2];
|
|
1967
|
-
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
|
|
1968
|
-
tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
|
|
1969
|
-
if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {
|
|
1970
|
-
codePoint = tempCodePoint;
|
|
1971
|
-
}
|
|
1972
|
-
}
|
|
1973
|
-
break;
|
|
1974
|
-
case 4:
|
|
1975
|
-
secondByte = this.data[this._pos + 1];
|
|
1976
|
-
thirdByte = this.data[this._pos + 2];
|
|
1977
|
-
fourthByte = this.data[this._pos + 3];
|
|
1978
|
-
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
|
|
1979
|
-
tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
|
|
1980
|
-
if (tempCodePoint > 65535 && tempCodePoint < 1114112) {
|
|
1981
|
-
codePoint = tempCodePoint;
|
|
1982
|
-
}
|
|
1983
|
-
}
|
|
1984
|
-
}
|
|
1985
|
-
if (codePoint === null) {
|
|
1986
|
-
codePoint = 65533;
|
|
1987
|
-
bytesPerSequence = 1;
|
|
1988
|
-
} else if (codePoint > 65535) {
|
|
1989
|
-
codePoint -= 65536;
|
|
1990
|
-
chars.push(codePoint >>> 10 & 1023 | 55296);
|
|
1991
|
-
codePoint = 56320 | codePoint & 1023;
|
|
1992
|
-
}
|
|
1993
|
-
chars.push(codePoint);
|
|
1994
|
-
this._pos += bytesPerSequence;
|
|
1995
|
-
};
|
|
1996
|
-
while (!this.done()) {
|
|
1997
|
-
const ch = this.ch();
|
|
1998
|
-
let ch1;
|
|
1999
|
-
switch (ch) {
|
|
2000
|
-
case 92:
|
|
2001
|
-
this._pos++;
|
|
2002
|
-
if (this.done()) {
|
|
2003
|
-
throw new Error(`${decodeErrPrefix} unexpected string termination at position ${this._pos}`);
|
|
2004
|
-
}
|
|
2005
|
-
ch1 = this.ch();
|
|
2006
|
-
this._pos++;
|
|
2007
|
-
switch (ch1) {
|
|
2008
|
-
case 34:
|
|
2009
|
-
case 39:
|
|
2010
|
-
case 92:
|
|
2011
|
-
case 47:
|
|
2012
|
-
chars.push(ch1);
|
|
2013
|
-
break;
|
|
2014
|
-
case 98:
|
|
2015
|
-
chars.push(8);
|
|
2016
|
-
break;
|
|
2017
|
-
case 116:
|
|
2018
|
-
chars.push(9);
|
|
2019
|
-
break;
|
|
2020
|
-
case 110:
|
|
2021
|
-
chars.push(10);
|
|
2022
|
-
break;
|
|
2023
|
-
case 102:
|
|
2024
|
-
chars.push(12);
|
|
2025
|
-
break;
|
|
2026
|
-
case 114:
|
|
2027
|
-
chars.push(13);
|
|
2028
|
-
break;
|
|
2029
|
-
case 117:
|
|
2030
|
-
chars.push(readu4());
|
|
2031
|
-
break;
|
|
2032
|
-
default:
|
|
2033
|
-
throw new Error(`${decodeErrPrefix} unexpected string escape character at position ${this._pos}`);
|
|
2034
|
-
}
|
|
2035
|
-
break;
|
|
2036
|
-
case 34:
|
|
2037
|
-
this._pos++;
|
|
2038
|
-
return new Token(Type.string, decodeCodePointsArray(chars), this._pos - startPos);
|
|
2039
|
-
default:
|
|
2040
|
-
if (ch < 32) {
|
|
2041
|
-
throw new Error(`${decodeErrPrefix} invalid control character at position ${this._pos}`);
|
|
2042
|
-
} else if (ch < 128) {
|
|
2043
|
-
chars.push(ch);
|
|
2044
|
-
this._pos++;
|
|
2045
|
-
} else {
|
|
2046
|
-
readUtf8Char();
|
|
2047
|
-
}
|
|
2048
|
-
}
|
|
2049
|
-
}
|
|
2050
|
-
throw new Error(`${decodeErrPrefix} unexpected end of string at position ${this._pos}`);
|
|
2051
|
-
}
|
|
2052
|
-
/**
|
|
2053
|
-
* @returns {Token}
|
|
2054
|
-
*/
|
|
2055
|
-
parseValue() {
|
|
2056
|
-
switch (this.ch()) {
|
|
2057
|
-
case 123:
|
|
2058
|
-
this.modeStack.push("obj-start");
|
|
2059
|
-
this._pos++;
|
|
2060
|
-
return new Token(Type.map, Infinity, 1);
|
|
2061
|
-
case 91:
|
|
2062
|
-
this.modeStack.push("array-start");
|
|
2063
|
-
this._pos++;
|
|
2064
|
-
return new Token(Type.array, Infinity, 1);
|
|
2065
|
-
case 34: {
|
|
2066
|
-
return this.parseString();
|
|
2067
|
-
}
|
|
2068
|
-
case 110:
|
|
2069
|
-
this.expect([110, 117, 108, 108]);
|
|
2070
|
-
return new Token(Type.null, null, 4);
|
|
2071
|
-
case 102:
|
|
2072
|
-
this.expect([102, 97, 108, 115, 101]);
|
|
2073
|
-
return new Token(Type.false, false, 5);
|
|
2074
|
-
case 116:
|
|
2075
|
-
this.expect([116, 114, 117, 101]);
|
|
2076
|
-
return new Token(Type.true, true, 4);
|
|
2077
|
-
case 45:
|
|
2078
|
-
case 48:
|
|
2079
|
-
case 49:
|
|
2080
|
-
case 50:
|
|
2081
|
-
case 51:
|
|
2082
|
-
case 52:
|
|
2083
|
-
case 53:
|
|
2084
|
-
case 54:
|
|
2085
|
-
case 55:
|
|
2086
|
-
case 56:
|
|
2087
|
-
case 57:
|
|
2088
|
-
return this.parseNumber();
|
|
2089
|
-
default:
|
|
2090
|
-
throw new Error(`${decodeErrPrefix} unexpected character at position ${this._pos}`);
|
|
2091
|
-
}
|
|
2092
|
-
}
|
|
2093
|
-
/**
|
|
2094
|
-
* @returns {Token}
|
|
2095
|
-
*/
|
|
2096
|
-
next() {
|
|
2097
|
-
this.skipWhitespace();
|
|
2098
|
-
switch (this.currentMode()) {
|
|
2099
|
-
case "value":
|
|
2100
|
-
this.modeStack.pop();
|
|
2101
|
-
return this.parseValue();
|
|
2102
|
-
case "array-value": {
|
|
2103
|
-
this.modeStack.pop();
|
|
2104
|
-
if (this.ch() === 93) {
|
|
2105
|
-
this._pos++;
|
|
2106
|
-
this.skipWhitespace();
|
|
2107
|
-
return new Token(Type.break, void 0, 1);
|
|
2108
|
-
}
|
|
2109
|
-
if (this.ch() !== 44) {
|
|
2110
|
-
throw new Error(`${decodeErrPrefix} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);
|
|
2111
|
-
}
|
|
2112
|
-
this._pos++;
|
|
2113
|
-
this.modeStack.push("array-value");
|
|
2114
|
-
this.skipWhitespace();
|
|
2115
|
-
return this.parseValue();
|
|
2116
|
-
}
|
|
2117
|
-
case "array-start": {
|
|
2118
|
-
this.modeStack.pop();
|
|
2119
|
-
if (this.ch() === 93) {
|
|
2120
|
-
this._pos++;
|
|
2121
|
-
this.skipWhitespace();
|
|
2122
|
-
return new Token(Type.break, void 0, 1);
|
|
2123
|
-
}
|
|
2124
|
-
this.modeStack.push("array-value");
|
|
2125
|
-
this.skipWhitespace();
|
|
2126
|
-
return this.parseValue();
|
|
2127
|
-
}
|
|
2128
|
-
case "obj-key":
|
|
2129
|
-
if (this.ch() === 125) {
|
|
2130
|
-
this.modeStack.pop();
|
|
2131
|
-
this._pos++;
|
|
2132
|
-
this.skipWhitespace();
|
|
2133
|
-
return new Token(Type.break, void 0, 1);
|
|
2134
|
-
}
|
|
2135
|
-
if (this.ch() !== 44) {
|
|
2136
|
-
throw new Error(`${decodeErrPrefix} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);
|
|
2137
|
-
}
|
|
2138
|
-
this._pos++;
|
|
2139
|
-
this.skipWhitespace();
|
|
2140
|
-
case "obj-start": {
|
|
2141
|
-
this.modeStack.pop();
|
|
2142
|
-
if (this.ch() === 125) {
|
|
2143
|
-
this._pos++;
|
|
2144
|
-
this.skipWhitespace();
|
|
2145
|
-
return new Token(Type.break, void 0, 1);
|
|
2146
|
-
}
|
|
2147
|
-
const token = this.parseString();
|
|
2148
|
-
this.skipWhitespace();
|
|
2149
|
-
if (this.ch() !== 58) {
|
|
2150
|
-
throw new Error(`${decodeErrPrefix} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);
|
|
2151
|
-
}
|
|
2152
|
-
this._pos++;
|
|
2153
|
-
this.modeStack.push("obj-value");
|
|
2154
|
-
return token;
|
|
2155
|
-
}
|
|
2156
|
-
case "obj-value": {
|
|
2157
|
-
this.modeStack.pop();
|
|
2158
|
-
this.modeStack.push("obj-key");
|
|
2159
|
-
this.skipWhitespace();
|
|
2160
|
-
return this.parseValue();
|
|
2161
|
-
}
|
|
2162
|
-
default:
|
|
2163
|
-
throw new Error(`${decodeErrPrefix} unexpected parse state at position ${this._pos}; this shouldn't happen`);
|
|
2164
|
-
}
|
|
2165
|
-
}
|
|
2166
|
-
};
|
|
2167
|
-
function decode2(data, options) {
|
|
2168
|
-
options = Object.assign({ tokenizer: new Tokenizer(data, options) }, options);
|
|
2169
|
-
return decode(data, options);
|
|
2170
|
-
}
|
|
2171
|
-
|
|
2172
|
-
// ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/bytes.js
|
|
2173
|
-
var empty = new Uint8Array(0);
|
|
2174
|
-
var equals = (aa, bb) => {
|
|
2175
|
-
if (aa === bb)
|
|
2176
|
-
return true;
|
|
2177
|
-
if (aa.byteLength !== bb.byteLength) {
|
|
2178
|
-
return false;
|
|
2179
|
-
}
|
|
2180
|
-
for (let ii = 0; ii < aa.byteLength; ii++) {
|
|
2181
|
-
if (aa[ii] !== bb[ii]) {
|
|
2182
|
-
return false;
|
|
2183
|
-
}
|
|
2184
|
-
}
|
|
2185
|
-
return true;
|
|
2186
|
-
};
|
|
2187
|
-
var coerce = (o) => {
|
|
2188
|
-
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array")
|
|
2189
|
-
return o;
|
|
2190
|
-
if (o instanceof ArrayBuffer)
|
|
2191
|
-
return new Uint8Array(o);
|
|
2192
|
-
if (ArrayBuffer.isView(o)) {
|
|
2193
|
-
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
2194
|
-
}
|
|
2195
|
-
throw new Error("Unknown type, must be binary type");
|
|
2196
|
-
};
|
|
2197
|
-
|
|
2198
|
-
// ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/vendor/base-x.js
|
|
2199
|
-
function base(ALPHABET, name2) {
|
|
2200
|
-
if (ALPHABET.length >= 255) {
|
|
2201
|
-
throw new TypeError("Alphabet too long");
|
|
2202
|
-
}
|
|
2203
|
-
var BASE_MAP = new Uint8Array(256);
|
|
2204
|
-
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
2205
|
-
BASE_MAP[j] = 255;
|
|
2206
|
-
}
|
|
2207
|
-
for (var i = 0; i < ALPHABET.length; i++) {
|
|
2208
|
-
var x = ALPHABET.charAt(i);
|
|
2209
|
-
var xc = x.charCodeAt(0);
|
|
2210
|
-
if (BASE_MAP[xc] !== 255) {
|
|
2211
|
-
throw new TypeError(x + " is ambiguous");
|
|
2212
|
-
}
|
|
2213
|
-
BASE_MAP[xc] = i;
|
|
2214
|
-
}
|
|
2215
|
-
var BASE = ALPHABET.length;
|
|
2216
|
-
var LEADER = ALPHABET.charAt(0);
|
|
2217
|
-
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
2218
|
-
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
2219
|
-
function encode7(source) {
|
|
2220
|
-
if (source instanceof Uint8Array)
|
|
2221
|
-
;
|
|
2222
|
-
else if (ArrayBuffer.isView(source)) {
|
|
2223
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
2224
|
-
} else if (Array.isArray(source)) {
|
|
2225
|
-
source = Uint8Array.from(source);
|
|
2226
|
-
}
|
|
2227
|
-
if (!(source instanceof Uint8Array)) {
|
|
2228
|
-
throw new TypeError("Expected Uint8Array");
|
|
2229
|
-
}
|
|
2230
|
-
if (source.length === 0) {
|
|
2231
|
-
return "";
|
|
2232
|
-
}
|
|
2233
|
-
var zeroes = 0;
|
|
2234
|
-
var length2 = 0;
|
|
2235
|
-
var pbegin = 0;
|
|
2236
|
-
var pend = source.length;
|
|
2237
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
2238
|
-
pbegin++;
|
|
2239
|
-
zeroes++;
|
|
2240
|
-
}
|
|
2241
|
-
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
2242
|
-
var b58 = new Uint8Array(size);
|
|
2243
|
-
while (pbegin !== pend) {
|
|
2244
|
-
var carry = source[pbegin];
|
|
2245
|
-
var i2 = 0;
|
|
2246
|
-
for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
|
|
2247
|
-
carry += 256 * b58[it1] >>> 0;
|
|
2248
|
-
b58[it1] = carry % BASE >>> 0;
|
|
2249
|
-
carry = carry / BASE >>> 0;
|
|
2250
|
-
}
|
|
2251
|
-
if (carry !== 0) {
|
|
2252
|
-
throw new Error("Non-zero carry");
|
|
2253
|
-
}
|
|
2254
|
-
length2 = i2;
|
|
2255
|
-
pbegin++;
|
|
2256
|
-
}
|
|
2257
|
-
var it2 = size - length2;
|
|
2258
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
2259
|
-
it2++;
|
|
2260
|
-
}
|
|
2261
|
-
var str = LEADER.repeat(zeroes);
|
|
2262
|
-
for (; it2 < size; ++it2) {
|
|
2263
|
-
str += ALPHABET.charAt(b58[it2]);
|
|
2264
|
-
}
|
|
2265
|
-
return str;
|
|
2266
|
-
}
|
|
2267
|
-
function decodeUnsafe(source) {
|
|
2268
|
-
if (typeof source !== "string") {
|
|
2269
|
-
throw new TypeError("Expected String");
|
|
2270
|
-
}
|
|
2271
|
-
if (source.length === 0) {
|
|
2272
|
-
return new Uint8Array();
|
|
2273
|
-
}
|
|
2274
|
-
var psz = 0;
|
|
2275
|
-
if (source[psz] === " ") {
|
|
2276
|
-
return;
|
|
2277
|
-
}
|
|
2278
|
-
var zeroes = 0;
|
|
2279
|
-
var length2 = 0;
|
|
2280
|
-
while (source[psz] === LEADER) {
|
|
2281
|
-
zeroes++;
|
|
2282
|
-
psz++;
|
|
2283
|
-
}
|
|
2284
|
-
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
2285
|
-
var b256 = new Uint8Array(size);
|
|
2286
|
-
while (source[psz]) {
|
|
2287
|
-
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
2288
|
-
if (carry === 255) {
|
|
2289
|
-
return;
|
|
2290
|
-
}
|
|
2291
|
-
var i2 = 0;
|
|
2292
|
-
for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
|
|
2293
|
-
carry += BASE * b256[it3] >>> 0;
|
|
2294
|
-
b256[it3] = carry % 256 >>> 0;
|
|
2295
|
-
carry = carry / 256 >>> 0;
|
|
2296
|
-
}
|
|
2297
|
-
if (carry !== 0) {
|
|
2298
|
-
throw new Error("Non-zero carry");
|
|
2299
|
-
}
|
|
2300
|
-
length2 = i2;
|
|
2301
|
-
psz++;
|
|
2302
|
-
}
|
|
2303
|
-
if (source[psz] === " ") {
|
|
2304
|
-
return;
|
|
2305
|
-
}
|
|
2306
|
-
var it4 = size - length2;
|
|
2307
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
2308
|
-
it4++;
|
|
2309
|
-
}
|
|
2310
|
-
var vch = new Uint8Array(zeroes + (size - it4));
|
|
2311
|
-
var j2 = zeroes;
|
|
2312
|
-
while (it4 !== size) {
|
|
2313
|
-
vch[j2++] = b256[it4++];
|
|
2314
|
-
}
|
|
2315
|
-
return vch;
|
|
2316
|
-
}
|
|
2317
|
-
function decode8(string) {
|
|
2318
|
-
var buffer2 = decodeUnsafe(string);
|
|
2319
|
-
if (buffer2) {
|
|
2320
|
-
return buffer2;
|
|
2321
|
-
}
|
|
2322
|
-
throw new Error(`Non-${name2} character`);
|
|
2323
|
-
}
|
|
2324
|
-
return {
|
|
2325
|
-
encode: encode7,
|
|
2326
|
-
decodeUnsafe,
|
|
2327
|
-
decode: decode8
|
|
2328
|
-
};
|
|
2329
|
-
}
|
|
2330
|
-
var src = base;
|
|
2331
|
-
var _brrp__multiformats_scope_baseX = src;
|
|
2332
|
-
var base_x_default = _brrp__multiformats_scope_baseX;
|
|
2333
|
-
|
|
2334
|
-
// ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/bases/base.js
|
|
2335
|
-
var Encoder = class {
|
|
2336
|
-
/**
|
|
2337
|
-
* @param {Base} name
|
|
2338
|
-
* @param {Prefix} prefix
|
|
2339
|
-
* @param {(bytes:Uint8Array) => string} baseEncode
|
|
2340
|
-
*/
|
|
2341
|
-
constructor(name2, prefix, baseEncode) {
|
|
2342
|
-
this.name = name2;
|
|
2343
|
-
this.prefix = prefix;
|
|
2344
|
-
this.baseEncode = baseEncode;
|
|
2345
|
-
}
|
|
2346
|
-
/**
|
|
2347
|
-
* @param {Uint8Array} bytes
|
|
2348
|
-
* @returns {API.Multibase<Prefix>}
|
|
2349
|
-
*/
|
|
2350
|
-
encode(bytes2) {
|
|
2351
|
-
if (bytes2 instanceof Uint8Array) {
|
|
2352
|
-
return `${this.prefix}${this.baseEncode(bytes2)}`;
|
|
2353
|
-
} else {
|
|
2354
|
-
throw Error("Unknown type, must be binary type");
|
|
2355
|
-
}
|
|
2356
|
-
}
|
|
2357
|
-
};
|
|
2358
|
-
var Decoder = class {
|
|
2359
|
-
/**
|
|
2360
|
-
* @param {Base} name
|
|
2361
|
-
* @param {Prefix} prefix
|
|
2362
|
-
* @param {(text:string) => Uint8Array} baseDecode
|
|
2363
|
-
*/
|
|
2364
|
-
constructor(name2, prefix, baseDecode) {
|
|
2365
|
-
this.name = name2;
|
|
2366
|
-
this.prefix = prefix;
|
|
2367
|
-
if (prefix.codePointAt(0) === void 0) {
|
|
2368
|
-
throw new Error("Invalid prefix character");
|
|
2369
|
-
}
|
|
2370
|
-
this.prefixCodePoint = /** @type {number} */
|
|
2371
|
-
prefix.codePointAt(0);
|
|
2372
|
-
this.baseDecode = baseDecode;
|
|
2373
|
-
}
|
|
2374
|
-
/**
|
|
2375
|
-
* @param {string} text
|
|
2376
|
-
*/
|
|
2377
|
-
decode(text) {
|
|
2378
|
-
if (typeof text === "string") {
|
|
2379
|
-
if (text.codePointAt(0) !== this.prefixCodePoint) {
|
|
2380
|
-
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
|
|
2381
|
-
}
|
|
2382
|
-
return this.baseDecode(text.slice(this.prefix.length));
|
|
2383
|
-
} else {
|
|
2384
|
-
throw Error("Can only multibase decode strings");
|
|
2385
|
-
}
|
|
2386
|
-
}
|
|
2387
|
-
/**
|
|
2388
|
-
* @template {string} OtherPrefix
|
|
2389
|
-
* @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
|
|
2390
|
-
* @returns {ComposedDecoder<Prefix|OtherPrefix>}
|
|
2391
|
-
*/
|
|
2392
|
-
or(decoder) {
|
|
2393
|
-
return or(this, decoder);
|
|
2394
|
-
}
|
|
2395
|
-
};
|
|
2396
|
-
var ComposedDecoder = class {
|
|
2397
|
-
/**
|
|
2398
|
-
* @param {Decoders<Prefix>} decoders
|
|
2399
|
-
*/
|
|
2400
|
-
constructor(decoders) {
|
|
2401
|
-
this.decoders = decoders;
|
|
2402
|
-
}
|
|
2403
|
-
/**
|
|
2404
|
-
* @template {string} OtherPrefix
|
|
2405
|
-
* @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
|
|
2406
|
-
* @returns {ComposedDecoder<Prefix|OtherPrefix>}
|
|
2407
|
-
*/
|
|
2408
|
-
or(decoder) {
|
|
2409
|
-
return or(this, decoder);
|
|
2410
|
-
}
|
|
2411
|
-
/**
|
|
2412
|
-
* @param {string} input
|
|
2413
|
-
* @returns {Uint8Array}
|
|
2414
|
-
*/
|
|
2415
|
-
decode(input) {
|
|
2416
|
-
const prefix = (
|
|
2417
|
-
/** @type {Prefix} */
|
|
2418
|
-
input[0]
|
|
2419
|
-
);
|
|
2420
|
-
const decoder = this.decoders[prefix];
|
|
2421
|
-
if (decoder) {
|
|
2422
|
-
return decoder.decode(input);
|
|
2423
|
-
} else {
|
|
2424
|
-
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
|
|
2425
|
-
}
|
|
2426
|
-
}
|
|
2427
|
-
};
|
|
2428
|
-
var or = (left, right) => new ComposedDecoder(
|
|
2429
|
-
/** @type {Decoders<L|R>} */
|
|
2430
|
-
{
|
|
2431
|
-
...left.decoders || { [
|
|
2432
|
-
/** @type API.UnibaseDecoder<L> */
|
|
2433
|
-
left.prefix
|
|
2434
|
-
]: left },
|
|
2435
|
-
...right.decoders || { [
|
|
2436
|
-
/** @type API.UnibaseDecoder<R> */
|
|
2437
|
-
right.prefix
|
|
2438
|
-
]: right }
|
|
2439
|
-
}
|
|
2440
|
-
);
|
|
2441
|
-
var Codec = class {
|
|
2442
|
-
/**
|
|
2443
|
-
* @param {Base} name
|
|
2444
|
-
* @param {Prefix} prefix
|
|
2445
|
-
* @param {(bytes:Uint8Array) => string} baseEncode
|
|
2446
|
-
* @param {(text:string) => Uint8Array} baseDecode
|
|
2447
|
-
*/
|
|
2448
|
-
constructor(name2, prefix, baseEncode, baseDecode) {
|
|
2449
|
-
this.name = name2;
|
|
2450
|
-
this.prefix = prefix;
|
|
2451
|
-
this.baseEncode = baseEncode;
|
|
2452
|
-
this.baseDecode = baseDecode;
|
|
2453
|
-
this.encoder = new Encoder(name2, prefix, baseEncode);
|
|
2454
|
-
this.decoder = new Decoder(name2, prefix, baseDecode);
|
|
2455
|
-
}
|
|
2456
|
-
/**
|
|
2457
|
-
* @param {Uint8Array} input
|
|
2458
|
-
*/
|
|
2459
|
-
encode(input) {
|
|
2460
|
-
return this.encoder.encode(input);
|
|
2461
|
-
}
|
|
2462
|
-
/**
|
|
2463
|
-
* @param {string} input
|
|
2464
|
-
*/
|
|
2465
|
-
decode(input) {
|
|
2466
|
-
return this.decoder.decode(input);
|
|
2467
|
-
}
|
|
2468
|
-
};
|
|
2469
|
-
var from = ({ name: name2, prefix, encode: encode7, decode: decode8 }) => new Codec(name2, prefix, encode7, decode8);
|
|
2470
|
-
var baseX = ({ prefix, name: name2, alphabet }) => {
|
|
2471
|
-
const { encode: encode7, decode: decode8 } = base_x_default(alphabet, name2);
|
|
2472
|
-
return from({
|
|
2473
|
-
prefix,
|
|
2474
|
-
name: name2,
|
|
2475
|
-
encode: encode7,
|
|
2476
|
-
/**
|
|
2477
|
-
* @param {string} text
|
|
2478
|
-
*/
|
|
2479
|
-
decode: (text) => coerce(decode8(text))
|
|
2480
|
-
});
|
|
2481
|
-
};
|
|
2482
|
-
var decode3 = (string, alphabet, bitsPerChar, name2) => {
|
|
2483
|
-
const codes = {};
|
|
2484
|
-
for (let i = 0; i < alphabet.length; ++i) {
|
|
2485
|
-
codes[alphabet[i]] = i;
|
|
2486
|
-
}
|
|
2487
|
-
let end = string.length;
|
|
2488
|
-
while (string[end - 1] === "=") {
|
|
2489
|
-
--end;
|
|
2490
|
-
}
|
|
2491
|
-
const out = new Uint8Array(end * bitsPerChar / 8 | 0);
|
|
2492
|
-
let bits = 0;
|
|
2493
|
-
let buffer2 = 0;
|
|
2494
|
-
let written = 0;
|
|
2495
|
-
for (let i = 0; i < end; ++i) {
|
|
2496
|
-
const value = codes[string[i]];
|
|
2497
|
-
if (value === void 0) {
|
|
2498
|
-
throw new SyntaxError(`Non-${name2} character`);
|
|
2499
|
-
}
|
|
2500
|
-
buffer2 = buffer2 << bitsPerChar | value;
|
|
2501
|
-
bits += bitsPerChar;
|
|
2502
|
-
if (bits >= 8) {
|
|
2503
|
-
bits -= 8;
|
|
2504
|
-
out[written++] = 255 & buffer2 >> bits;
|
|
2505
|
-
}
|
|
2506
|
-
}
|
|
2507
|
-
if (bits >= bitsPerChar || 255 & buffer2 << 8 - bits) {
|
|
2508
|
-
throw new SyntaxError("Unexpected end of data");
|
|
2509
|
-
}
|
|
2510
|
-
return out;
|
|
2511
|
-
};
|
|
2512
|
-
var encode3 = (data, alphabet, bitsPerChar) => {
|
|
2513
|
-
const pad = alphabet[alphabet.length - 1] === "=";
|
|
2514
|
-
const mask = (1 << bitsPerChar) - 1;
|
|
2515
|
-
let out = "";
|
|
2516
|
-
let bits = 0;
|
|
2517
|
-
let buffer2 = 0;
|
|
2518
|
-
for (let i = 0; i < data.length; ++i) {
|
|
2519
|
-
buffer2 = buffer2 << 8 | data[i];
|
|
2520
|
-
bits += 8;
|
|
2521
|
-
while (bits > bitsPerChar) {
|
|
2522
|
-
bits -= bitsPerChar;
|
|
2523
|
-
out += alphabet[mask & buffer2 >> bits];
|
|
2524
|
-
}
|
|
2525
|
-
}
|
|
2526
|
-
if (bits) {
|
|
2527
|
-
out += alphabet[mask & buffer2 << bitsPerChar - bits];
|
|
2528
|
-
}
|
|
2529
|
-
if (pad) {
|
|
2530
|
-
while (out.length * bitsPerChar & 7) {
|
|
2531
|
-
out += "=";
|
|
2532
|
-
}
|
|
2533
|
-
}
|
|
2534
|
-
return out;
|
|
2535
|
-
};
|
|
2536
|
-
var rfc4648 = ({ name: name2, prefix, bitsPerChar, alphabet }) => {
|
|
2537
|
-
return from({
|
|
2538
|
-
prefix,
|
|
2539
|
-
name: name2,
|
|
2540
|
-
encode(input) {
|
|
2541
|
-
return encode3(input, alphabet, bitsPerChar);
|
|
2542
|
-
},
|
|
2543
|
-
decode(input) {
|
|
2544
|
-
return decode3(input, alphabet, bitsPerChar, name2);
|
|
2545
|
-
}
|
|
2546
|
-
});
|
|
2547
|
-
};
|
|
2548
|
-
|
|
2549
|
-
// ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/bases/base32.js
|
|
2550
|
-
var base32 = rfc4648({
|
|
2551
|
-
prefix: "b",
|
|
2552
|
-
name: "base32",
|
|
2553
|
-
alphabet: "abcdefghijklmnopqrstuvwxyz234567",
|
|
2554
|
-
bitsPerChar: 5
|
|
2555
|
-
});
|
|
2556
|
-
var base32upper = rfc4648({
|
|
2557
|
-
prefix: "B",
|
|
2558
|
-
name: "base32upper",
|
|
2559
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
|
2560
|
-
bitsPerChar: 5
|
|
2561
|
-
});
|
|
2562
|
-
var base32pad = rfc4648({
|
|
2563
|
-
prefix: "c",
|
|
2564
|
-
name: "base32pad",
|
|
2565
|
-
alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
|
|
2566
|
-
bitsPerChar: 5
|
|
2567
|
-
});
|
|
2568
|
-
var base32padupper = rfc4648({
|
|
2569
|
-
prefix: "C",
|
|
2570
|
-
name: "base32padupper",
|
|
2571
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
|
|
2572
|
-
bitsPerChar: 5
|
|
2573
|
-
});
|
|
2574
|
-
var base32hex = rfc4648({
|
|
2575
|
-
prefix: "v",
|
|
2576
|
-
name: "base32hex",
|
|
2577
|
-
alphabet: "0123456789abcdefghijklmnopqrstuv",
|
|
2578
|
-
bitsPerChar: 5
|
|
2579
|
-
});
|
|
2580
|
-
var base32hexupper = rfc4648({
|
|
2581
|
-
prefix: "V",
|
|
2582
|
-
name: "base32hexupper",
|
|
2583
|
-
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
|
|
2584
|
-
bitsPerChar: 5
|
|
2585
|
-
});
|
|
2586
|
-
var base32hexpad = rfc4648({
|
|
2587
|
-
prefix: "t",
|
|
2588
|
-
name: "base32hexpad",
|
|
2589
|
-
alphabet: "0123456789abcdefghijklmnopqrstuv=",
|
|
2590
|
-
bitsPerChar: 5
|
|
2591
|
-
});
|
|
2592
|
-
var base32hexpadupper = rfc4648({
|
|
2593
|
-
prefix: "T",
|
|
2594
|
-
name: "base32hexpadupper",
|
|
2595
|
-
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
|
|
2596
|
-
bitsPerChar: 5
|
|
2597
|
-
});
|
|
2598
|
-
var base32z = rfc4648({
|
|
2599
|
-
prefix: "h",
|
|
2600
|
-
name: "base32z",
|
|
2601
|
-
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
|
|
2602
|
-
bitsPerChar: 5
|
|
2603
|
-
});
|
|
2604
|
-
|
|
2605
|
-
// ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/bases/base58.js
|
|
2606
|
-
var base58btc = baseX({
|
|
2607
|
-
name: "base58btc",
|
|
2608
|
-
prefix: "z",
|
|
2609
|
-
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
2610
|
-
});
|
|
2611
|
-
var base58flickr = baseX({
|
|
2612
|
-
name: "base58flickr",
|
|
2613
|
-
prefix: "Z",
|
|
2614
|
-
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
|
2615
|
-
});
|
|
2616
|
-
|
|
2617
|
-
// ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/hashes/digest.js
|
|
2618
|
-
var digest_exports = {};
|
|
2619
|
-
__export(digest_exports, {
|
|
2620
|
-
Digest: () => Digest,
|
|
2621
|
-
create: () => create,
|
|
2622
|
-
decode: () => decode6,
|
|
2623
|
-
equals: () => equals2
|
|
2624
|
-
});
|
|
2625
|
-
|
|
2626
|
-
// ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/vendor/varint.js
|
|
2627
|
-
var encode_1 = encode4;
|
|
2628
|
-
var MSB = 128;
|
|
2629
|
-
var REST = 127;
|
|
2630
|
-
var MSBALL = ~REST;
|
|
2631
|
-
var INT = Math.pow(2, 31);
|
|
2632
|
-
function encode4(num, out, offset) {
|
|
2633
|
-
out = out || [];
|
|
2634
|
-
offset = offset || 0;
|
|
2635
|
-
var oldOffset = offset;
|
|
2636
|
-
while (num >= INT) {
|
|
2637
|
-
out[offset++] = num & 255 | MSB;
|
|
2638
|
-
num /= 128;
|
|
2639
|
-
}
|
|
2640
|
-
while (num & MSBALL) {
|
|
2641
|
-
out[offset++] = num & 255 | MSB;
|
|
2642
|
-
num >>>= 7;
|
|
2643
|
-
}
|
|
2644
|
-
out[offset] = num | 0;
|
|
2645
|
-
encode4.bytes = offset - oldOffset + 1;
|
|
2646
|
-
return out;
|
|
2647
|
-
}
|
|
2648
|
-
var decode4 = read;
|
|
2649
|
-
var MSB$1 = 128;
|
|
2650
|
-
var REST$1 = 127;
|
|
2651
|
-
function read(buf2, offset) {
|
|
2652
|
-
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf2.length;
|
|
2653
|
-
do {
|
|
2654
|
-
if (counter >= l) {
|
|
2655
|
-
read.bytes = 0;
|
|
2656
|
-
throw new RangeError("Could not decode varint");
|
|
2657
|
-
}
|
|
2658
|
-
b = buf2[counter++];
|
|
2659
|
-
res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
|
|
2660
|
-
shift += 7;
|
|
2661
|
-
} while (b >= MSB$1);
|
|
2662
|
-
read.bytes = counter - offset;
|
|
2663
|
-
return res;
|
|
2664
|
-
}
|
|
2665
|
-
var N1 = Math.pow(2, 7);
|
|
2666
|
-
var N2 = Math.pow(2, 14);
|
|
2667
|
-
var N3 = Math.pow(2, 21);
|
|
2668
|
-
var N4 = Math.pow(2, 28);
|
|
2669
|
-
var N5 = Math.pow(2, 35);
|
|
2670
|
-
var N6 = Math.pow(2, 42);
|
|
2671
|
-
var N7 = Math.pow(2, 49);
|
|
2672
|
-
var N8 = Math.pow(2, 56);
|
|
2673
|
-
var N9 = Math.pow(2, 63);
|
|
2674
|
-
var length = function(value) {
|
|
2675
|
-
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;
|
|
2676
|
-
};
|
|
2677
|
-
var varint = {
|
|
2678
|
-
encode: encode_1,
|
|
2679
|
-
decode: decode4,
|
|
2680
|
-
encodingLength: length
|
|
2681
|
-
};
|
|
2682
|
-
var _brrp_varint = varint;
|
|
2683
|
-
var varint_default = _brrp_varint;
|
|
2684
|
-
|
|
2685
|
-
// ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/varint.js
|
|
2686
|
-
var decode5 = (data, offset = 0) => {
|
|
2687
|
-
const code2 = varint_default.decode(data, offset);
|
|
2688
|
-
return [code2, varint_default.decode.bytes];
|
|
2689
|
-
};
|
|
2690
|
-
var encodeTo = (int, target, offset = 0) => {
|
|
2691
|
-
varint_default.encode(int, target, offset);
|
|
2692
|
-
return target;
|
|
2693
|
-
};
|
|
2694
|
-
var encodingLength = (int) => {
|
|
2695
|
-
return varint_default.encodingLength(int);
|
|
2696
|
-
};
|
|
2697
|
-
|
|
2698
|
-
// ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/hashes/digest.js
|
|
2699
|
-
var create = (code2, digest) => {
|
|
2700
|
-
const size = digest.byteLength;
|
|
2701
|
-
const sizeOffset = encodingLength(code2);
|
|
2702
|
-
const digestOffset = sizeOffset + encodingLength(size);
|
|
2703
|
-
const bytes2 = new Uint8Array(digestOffset + size);
|
|
2704
|
-
encodeTo(code2, bytes2, 0);
|
|
2705
|
-
encodeTo(size, bytes2, sizeOffset);
|
|
2706
|
-
bytes2.set(digest, digestOffset);
|
|
2707
|
-
return new Digest(code2, size, digest, bytes2);
|
|
2708
|
-
};
|
|
2709
|
-
var decode6 = (multihash) => {
|
|
2710
|
-
const bytes2 = coerce(multihash);
|
|
2711
|
-
const [code2, sizeOffset] = decode5(bytes2);
|
|
2712
|
-
const [size, digestOffset] = decode5(bytes2.subarray(sizeOffset));
|
|
2713
|
-
const digest = bytes2.subarray(sizeOffset + digestOffset);
|
|
2714
|
-
if (digest.byteLength !== size) {
|
|
2715
|
-
throw new Error("Incorrect length");
|
|
2716
|
-
}
|
|
2717
|
-
return new Digest(code2, size, digest, bytes2);
|
|
2718
|
-
};
|
|
2719
|
-
var equals2 = (a, b) => {
|
|
2720
|
-
if (a === b) {
|
|
2721
|
-
return true;
|
|
2722
|
-
} else {
|
|
2723
|
-
const data = (
|
|
2724
|
-
/** @type {{code?:unknown, size?:unknown, bytes?:unknown}} */
|
|
2725
|
-
b
|
|
2726
|
-
);
|
|
2727
|
-
return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
|
|
2728
|
-
}
|
|
2729
|
-
};
|
|
2730
|
-
var Digest = class {
|
|
2731
|
-
/**
|
|
2732
|
-
* Creates a multihash digest.
|
|
2733
|
-
*
|
|
2734
|
-
* @param {Code} code
|
|
2735
|
-
* @param {Size} size
|
|
2736
|
-
* @param {Uint8Array} digest
|
|
2737
|
-
* @param {Uint8Array} bytes
|
|
2738
|
-
*/
|
|
2739
|
-
constructor(code2, size, digest, bytes2) {
|
|
2740
|
-
this.code = code2;
|
|
2741
|
-
this.size = size;
|
|
2742
|
-
this.digest = digest;
|
|
2743
|
-
this.bytes = bytes2;
|
|
2744
|
-
}
|
|
2745
|
-
};
|
|
2746
|
-
|
|
2747
|
-
// ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/cid.js
|
|
2748
|
-
var format = (link, base2) => {
|
|
2749
|
-
const { bytes: bytes2, version } = link;
|
|
2750
|
-
switch (version) {
|
|
2751
|
-
case 0:
|
|
2752
|
-
return toStringV0(
|
|
2753
|
-
bytes2,
|
|
2754
|
-
baseCache(link),
|
|
2755
|
-
/** @type {API.MultibaseEncoder<"z">} */
|
|
2756
|
-
base2 || base58btc.encoder
|
|
2757
|
-
);
|
|
2758
|
-
default:
|
|
2759
|
-
return toStringV1(
|
|
2760
|
-
bytes2,
|
|
2761
|
-
baseCache(link),
|
|
2762
|
-
/** @type {API.MultibaseEncoder<Prefix>} */
|
|
2763
|
-
base2 || base32.encoder
|
|
2764
|
-
);
|
|
2765
|
-
}
|
|
2766
|
-
};
|
|
2767
|
-
var cache = /* @__PURE__ */ new WeakMap();
|
|
2768
|
-
var baseCache = (cid) => {
|
|
2769
|
-
const baseCache2 = cache.get(cid);
|
|
2770
|
-
if (baseCache2 == null) {
|
|
2771
|
-
const baseCache3 = /* @__PURE__ */ new Map();
|
|
2772
|
-
cache.set(cid, baseCache3);
|
|
2773
|
-
return baseCache3;
|
|
2774
|
-
}
|
|
2775
|
-
return baseCache2;
|
|
2776
|
-
};
|
|
2777
|
-
var CID = class _CID {
|
|
2778
|
-
/**
|
|
2779
|
-
* @param {Version} version - Version of the CID
|
|
2780
|
-
* @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
2781
|
-
* @param {API.MultihashDigest<Alg>} multihash - (Multi)hash of the of the content.
|
|
2782
|
-
* @param {Uint8Array} bytes
|
|
2783
|
-
*/
|
|
2784
|
-
constructor(version, code2, multihash, bytes2) {
|
|
2785
|
-
this.code = code2;
|
|
2786
|
-
this.version = version;
|
|
2787
|
-
this.multihash = multihash;
|
|
2788
|
-
this.bytes = bytes2;
|
|
2789
|
-
this["/"] = bytes2;
|
|
2790
|
-
}
|
|
2791
|
-
/**
|
|
2792
|
-
* Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
|
|
2793
|
-
* please either use `CID.asCID(cid)` or switch to new signalling mechanism
|
|
2794
|
-
*
|
|
2795
|
-
* @deprecated
|
|
2796
|
-
*/
|
|
2797
|
-
get asCID() {
|
|
2798
|
-
return this;
|
|
2799
|
-
}
|
|
2800
|
-
// ArrayBufferView
|
|
2801
|
-
get byteOffset() {
|
|
2802
|
-
return this.bytes.byteOffset;
|
|
2803
|
-
}
|
|
2804
|
-
// ArrayBufferView
|
|
2805
|
-
get byteLength() {
|
|
2806
|
-
return this.bytes.byteLength;
|
|
2807
|
-
}
|
|
2808
|
-
/**
|
|
2809
|
-
* @returns {CID<Data, API.DAG_PB, API.SHA_256, 0>}
|
|
2810
|
-
*/
|
|
2811
|
-
toV0() {
|
|
2812
|
-
switch (this.version) {
|
|
2813
|
-
case 0: {
|
|
2814
|
-
return (
|
|
2815
|
-
/** @type {CID<Data, API.DAG_PB, API.SHA_256, 0>} */
|
|
2816
|
-
this
|
|
2817
|
-
);
|
|
2818
|
-
}
|
|
2819
|
-
case 1: {
|
|
2820
|
-
const { code: code2, multihash } = this;
|
|
2821
|
-
if (code2 !== DAG_PB_CODE) {
|
|
2822
|
-
throw new Error("Cannot convert a non dag-pb CID to CIDv0");
|
|
2823
|
-
}
|
|
2824
|
-
if (multihash.code !== SHA_256_CODE) {
|
|
2825
|
-
throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
|
|
2826
|
-
}
|
|
2827
|
-
return (
|
|
2828
|
-
/** @type {CID<Data, API.DAG_PB, API.SHA_256, 0>} */
|
|
2829
|
-
_CID.createV0(
|
|
2830
|
-
/** @type {API.MultihashDigest<API.SHA_256>} */
|
|
2831
|
-
multihash
|
|
2832
|
-
)
|
|
2833
|
-
);
|
|
2834
|
-
}
|
|
2835
|
-
default: {
|
|
2836
|
-
throw Error(
|
|
2837
|
-
`Can not convert CID version ${this.version} to version 0. This is a bug please report`
|
|
2838
|
-
);
|
|
2839
|
-
}
|
|
2840
|
-
}
|
|
2841
|
-
}
|
|
2842
|
-
/**
|
|
2843
|
-
* @returns {CID<Data, Format, Alg, 1>}
|
|
2844
|
-
*/
|
|
2845
|
-
toV1() {
|
|
2846
|
-
switch (this.version) {
|
|
2847
|
-
case 0: {
|
|
2848
|
-
const { code: code2, digest } = this.multihash;
|
|
2849
|
-
const multihash = create(code2, digest);
|
|
2850
|
-
return (
|
|
2851
|
-
/** @type {CID<Data, Format, Alg, 1>} */
|
|
2852
|
-
_CID.createV1(this.code, multihash)
|
|
2853
|
-
);
|
|
2854
|
-
}
|
|
2855
|
-
case 1: {
|
|
2856
|
-
return (
|
|
2857
|
-
/** @type {CID<Data, Format, Alg, 1>} */
|
|
2858
|
-
this
|
|
2859
|
-
);
|
|
2860
|
-
}
|
|
2861
|
-
default: {
|
|
2862
|
-
throw Error(
|
|
2863
|
-
`Can not convert CID version ${this.version} to version 1. This is a bug please report`
|
|
2864
|
-
);
|
|
2865
|
-
}
|
|
2866
|
-
}
|
|
2867
|
-
}
|
|
2868
|
-
/**
|
|
2869
|
-
* @param {unknown} other
|
|
2870
|
-
* @returns {other is CID<Data, Format, Alg, Version>}
|
|
2871
|
-
*/
|
|
2872
|
-
equals(other) {
|
|
2873
|
-
return _CID.equals(this, other);
|
|
2874
|
-
}
|
|
2875
|
-
/**
|
|
2876
|
-
* @template {unknown} Data
|
|
2877
|
-
* @template {number} Format
|
|
2878
|
-
* @template {number} Alg
|
|
2879
|
-
* @template {API.Version} Version
|
|
2880
|
-
* @param {API.Link<Data, Format, Alg, Version>} self
|
|
2881
|
-
* @param {unknown} other
|
|
2882
|
-
* @returns {other is CID}
|
|
2883
|
-
*/
|
|
2884
|
-
static equals(self2, other) {
|
|
2885
|
-
const unknown = (
|
|
2886
|
-
/** @type {{code?:unknown, version?:unknown, multihash?:unknown}} */
|
|
2887
|
-
other
|
|
2888
|
-
);
|
|
2889
|
-
return unknown && self2.code === unknown.code && self2.version === unknown.version && equals2(self2.multihash, unknown.multihash);
|
|
2890
|
-
}
|
|
2891
|
-
/**
|
|
2892
|
-
* @param {API.MultibaseEncoder<string>} [base]
|
|
2893
|
-
* @returns {string}
|
|
2894
|
-
*/
|
|
2895
|
-
toString(base2) {
|
|
2896
|
-
return format(this, base2);
|
|
2897
|
-
}
|
|
2898
|
-
/**
|
|
2899
|
-
* @returns {API.LinkJSON<this>}
|
|
2900
|
-
*/
|
|
2901
|
-
toJSON() {
|
|
2902
|
-
return { "/": format(this) };
|
|
2903
|
-
}
|
|
2904
|
-
link() {
|
|
2905
|
-
return this;
|
|
2906
|
-
}
|
|
2907
|
-
get [Symbol.toStringTag]() {
|
|
2908
|
-
return "CID";
|
|
2909
|
-
}
|
|
2910
|
-
// Legacy
|
|
2911
|
-
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
2912
|
-
return `CID(${this.toString()})`;
|
|
2913
|
-
}
|
|
2914
|
-
/**
|
|
2915
|
-
* Takes any input `value` and returns a `CID` instance if it was
|
|
2916
|
-
* a `CID` otherwise returns `null`. If `value` is instanceof `CID`
|
|
2917
|
-
* it will return value back. If `value` is not instance of this CID
|
|
2918
|
-
* class, but is compatible CID it will return new instance of this
|
|
2919
|
-
* `CID` class. Otherwise returns null.
|
|
2920
|
-
*
|
|
2921
|
-
* This allows two different incompatible versions of CID library to
|
|
2922
|
-
* co-exist and interop as long as binary interface is compatible.
|
|
2923
|
-
*
|
|
2924
|
-
* @template {unknown} Data
|
|
2925
|
-
* @template {number} Format
|
|
2926
|
-
* @template {number} Alg
|
|
2927
|
-
* @template {API.Version} Version
|
|
2928
|
-
* @template {unknown} U
|
|
2929
|
-
* @param {API.Link<Data, Format, Alg, Version>|U} input
|
|
2930
|
-
* @returns {CID<Data, Format, Alg, Version>|null}
|
|
2931
|
-
*/
|
|
2932
|
-
static asCID(input) {
|
|
2933
|
-
if (input == null) {
|
|
2934
|
-
return null;
|
|
2935
|
-
}
|
|
2936
|
-
const value = (
|
|
2937
|
-
/** @type {any} */
|
|
2938
|
-
input
|
|
2939
|
-
);
|
|
2940
|
-
if (value instanceof _CID) {
|
|
2941
|
-
return value;
|
|
2942
|
-
} else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
|
|
2943
|
-
const { version, code: code2, multihash, bytes: bytes2 } = value;
|
|
2944
|
-
return new _CID(
|
|
2945
|
-
version,
|
|
2946
|
-
code2,
|
|
2947
|
-
/** @type {API.MultihashDigest<Alg>} */
|
|
2948
|
-
multihash,
|
|
2949
|
-
bytes2 || encodeCID(version, code2, multihash.bytes)
|
|
2950
|
-
);
|
|
2951
|
-
} else if (value[cidSymbol] === true) {
|
|
2952
|
-
const { version, multihash, code: code2 } = value;
|
|
2953
|
-
const digest = (
|
|
2954
|
-
/** @type {API.MultihashDigest<Alg>} */
|
|
2955
|
-
decode6(multihash)
|
|
2956
|
-
);
|
|
2957
|
-
return _CID.create(version, code2, digest);
|
|
2958
|
-
} else {
|
|
2959
|
-
return null;
|
|
2960
|
-
}
|
|
2961
|
-
}
|
|
2962
|
-
/**
|
|
2963
|
-
*
|
|
2964
|
-
* @template {unknown} Data
|
|
2965
|
-
* @template {number} Format
|
|
2966
|
-
* @template {number} Alg
|
|
2967
|
-
* @template {API.Version} Version
|
|
2968
|
-
* @param {Version} version - Version of the CID
|
|
2969
|
-
* @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
2970
|
-
* @param {API.MultihashDigest<Alg>} digest - (Multi)hash of the of the content.
|
|
2971
|
-
* @returns {CID<Data, Format, Alg, Version>}
|
|
2972
|
-
*/
|
|
2973
|
-
static create(version, code2, digest) {
|
|
2974
|
-
if (typeof code2 !== "number") {
|
|
2975
|
-
throw new Error("String codecs are no longer supported");
|
|
2976
|
-
}
|
|
2977
|
-
if (!(digest.bytes instanceof Uint8Array)) {
|
|
2978
|
-
throw new Error("Invalid digest");
|
|
2979
|
-
}
|
|
2980
|
-
switch (version) {
|
|
2981
|
-
case 0: {
|
|
2982
|
-
if (code2 !== DAG_PB_CODE) {
|
|
2983
|
-
throw new Error(
|
|
2984
|
-
`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`
|
|
2985
|
-
);
|
|
2986
|
-
} else {
|
|
2987
|
-
return new _CID(version, code2, digest, digest.bytes);
|
|
2988
|
-
}
|
|
2989
|
-
}
|
|
2990
|
-
case 1: {
|
|
2991
|
-
const bytes2 = encodeCID(version, code2, digest.bytes);
|
|
2992
|
-
return new _CID(version, code2, digest, bytes2);
|
|
2993
|
-
}
|
|
2994
|
-
default: {
|
|
2995
|
-
throw new Error("Invalid version");
|
|
2996
|
-
}
|
|
2997
|
-
}
|
|
2998
|
-
}
|
|
2999
|
-
/**
|
|
3000
|
-
* Simplified version of `create` for CIDv0.
|
|
3001
|
-
*
|
|
3002
|
-
* @template {unknown} [T=unknown]
|
|
3003
|
-
* @param {API.MultihashDigest<typeof SHA_256_CODE>} digest - Multihash.
|
|
3004
|
-
* @returns {CID<T, typeof DAG_PB_CODE, typeof SHA_256_CODE, 0>}
|
|
3005
|
-
*/
|
|
3006
|
-
static createV0(digest) {
|
|
3007
|
-
return _CID.create(0, DAG_PB_CODE, digest);
|
|
3008
|
-
}
|
|
3009
|
-
/**
|
|
3010
|
-
* Simplified version of `create` for CIDv1.
|
|
3011
|
-
*
|
|
3012
|
-
* @template {unknown} Data
|
|
3013
|
-
* @template {number} Code
|
|
3014
|
-
* @template {number} Alg
|
|
3015
|
-
* @param {Code} code - Content encoding format code.
|
|
3016
|
-
* @param {API.MultihashDigest<Alg>} digest - Miltihash of the content.
|
|
3017
|
-
* @returns {CID<Data, Code, Alg, 1>}
|
|
3018
|
-
*/
|
|
3019
|
-
static createV1(code2, digest) {
|
|
3020
|
-
return _CID.create(1, code2, digest);
|
|
3021
|
-
}
|
|
3022
|
-
/**
|
|
3023
|
-
* Decoded a CID from its binary representation. The byte array must contain
|
|
3024
|
-
* only the CID with no additional bytes.
|
|
3025
|
-
*
|
|
3026
|
-
* An error will be thrown if the bytes provided do not contain a valid
|
|
3027
|
-
* binary representation of a CID.
|
|
3028
|
-
*
|
|
3029
|
-
* @template {unknown} Data
|
|
3030
|
-
* @template {number} Code
|
|
3031
|
-
* @template {number} Alg
|
|
3032
|
-
* @template {API.Version} Ver
|
|
3033
|
-
* @param {API.ByteView<API.Link<Data, Code, Alg, Ver>>} bytes
|
|
3034
|
-
* @returns {CID<Data, Code, Alg, Ver>}
|
|
3035
|
-
*/
|
|
3036
|
-
static decode(bytes2) {
|
|
3037
|
-
const [cid, remainder] = _CID.decodeFirst(bytes2);
|
|
3038
|
-
if (remainder.length) {
|
|
3039
|
-
throw new Error("Incorrect length");
|
|
3040
|
-
}
|
|
3041
|
-
return cid;
|
|
3042
|
-
}
|
|
3043
|
-
/**
|
|
3044
|
-
* Decoded a CID from its binary representation at the beginning of a byte
|
|
3045
|
-
* array.
|
|
3046
|
-
*
|
|
3047
|
-
* Returns an array with the first element containing the CID and the second
|
|
3048
|
-
* element containing the remainder of the original byte array. The remainder
|
|
3049
|
-
* will be a zero-length byte array if the provided bytes only contained a
|
|
3050
|
-
* binary CID representation.
|
|
3051
|
-
*
|
|
3052
|
-
* @template {unknown} T
|
|
3053
|
-
* @template {number} C
|
|
3054
|
-
* @template {number} A
|
|
3055
|
-
* @template {API.Version} V
|
|
3056
|
-
* @param {API.ByteView<API.Link<T, C, A, V>>} bytes
|
|
3057
|
-
* @returns {[CID<T, C, A, V>, Uint8Array]}
|
|
3058
|
-
*/
|
|
3059
|
-
static decodeFirst(bytes2) {
|
|
3060
|
-
const specs = _CID.inspectBytes(bytes2);
|
|
3061
|
-
const prefixSize = specs.size - specs.multihashSize;
|
|
3062
|
-
const multihashBytes = coerce(
|
|
3063
|
-
bytes2.subarray(prefixSize, prefixSize + specs.multihashSize)
|
|
3064
|
-
);
|
|
3065
|
-
if (multihashBytes.byteLength !== specs.multihashSize) {
|
|
3066
|
-
throw new Error("Incorrect length");
|
|
3067
|
-
}
|
|
3068
|
-
const digestBytes = multihashBytes.subarray(
|
|
3069
|
-
specs.multihashSize - specs.digestSize
|
|
3070
|
-
);
|
|
3071
|
-
const digest = new Digest(
|
|
3072
|
-
specs.multihashCode,
|
|
3073
|
-
specs.digestSize,
|
|
3074
|
-
digestBytes,
|
|
3075
|
-
multihashBytes
|
|
3076
|
-
);
|
|
3077
|
-
const cid = specs.version === 0 ? _CID.createV0(
|
|
3078
|
-
/** @type {API.MultihashDigest<API.SHA_256>} */
|
|
3079
|
-
digest
|
|
3080
|
-
) : _CID.createV1(specs.codec, digest);
|
|
3081
|
-
return [
|
|
3082
|
-
/** @type {CID<T, C, A, V>} */
|
|
3083
|
-
cid,
|
|
3084
|
-
bytes2.subarray(specs.size)
|
|
3085
|
-
];
|
|
3086
|
-
}
|
|
3087
|
-
/**
|
|
3088
|
-
* Inspect the initial bytes of a CID to determine its properties.
|
|
3089
|
-
*
|
|
3090
|
-
* Involves decoding up to 4 varints. Typically this will require only 4 to 6
|
|
3091
|
-
* bytes but for larger multicodec code values and larger multihash digest
|
|
3092
|
-
* lengths these varints can be quite large. It is recommended that at least
|
|
3093
|
-
* 10 bytes be made available in the `initialBytes` argument for a complete
|
|
3094
|
-
* inspection.
|
|
3095
|
-
*
|
|
3096
|
-
* @template {unknown} T
|
|
3097
|
-
* @template {number} C
|
|
3098
|
-
* @template {number} A
|
|
3099
|
-
* @template {API.Version} V
|
|
3100
|
-
* @param {API.ByteView<API.Link<T, C, A, V>>} initialBytes
|
|
3101
|
-
* @returns {{ version:V, codec:C, multihashCode:A, digestSize:number, multihashSize:number, size:number }}
|
|
3102
|
-
*/
|
|
3103
|
-
static inspectBytes(initialBytes) {
|
|
3104
|
-
let offset = 0;
|
|
3105
|
-
const next = () => {
|
|
3106
|
-
const [i, length2] = decode5(initialBytes.subarray(offset));
|
|
3107
|
-
offset += length2;
|
|
3108
|
-
return i;
|
|
3109
|
-
};
|
|
3110
|
-
let version = (
|
|
3111
|
-
/** @type {V} */
|
|
3112
|
-
next()
|
|
3113
|
-
);
|
|
3114
|
-
let codec = (
|
|
3115
|
-
/** @type {C} */
|
|
3116
|
-
DAG_PB_CODE
|
|
3117
|
-
);
|
|
3118
|
-
if (
|
|
3119
|
-
/** @type {number} */
|
|
3120
|
-
version === 18
|
|
3121
|
-
) {
|
|
3122
|
-
version = /** @type {V} */
|
|
3123
|
-
0;
|
|
3124
|
-
offset = 0;
|
|
3125
|
-
} else {
|
|
3126
|
-
codec = /** @type {C} */
|
|
3127
|
-
next();
|
|
3128
|
-
}
|
|
3129
|
-
if (version !== 0 && version !== 1) {
|
|
3130
|
-
throw new RangeError(`Invalid CID version ${version}`);
|
|
3131
|
-
}
|
|
3132
|
-
const prefixSize = offset;
|
|
3133
|
-
const multihashCode = (
|
|
3134
|
-
/** @type {A} */
|
|
3135
|
-
next()
|
|
3136
|
-
);
|
|
3137
|
-
const digestSize = next();
|
|
3138
|
-
const size = offset + digestSize;
|
|
3139
|
-
const multihashSize = size - prefixSize;
|
|
3140
|
-
return { version, codec, multihashCode, digestSize, multihashSize, size };
|
|
3141
|
-
}
|
|
3142
|
-
/**
|
|
3143
|
-
* Takes cid in a string representation and creates an instance. If `base`
|
|
3144
|
-
* decoder is not provided will use a default from the configuration. It will
|
|
3145
|
-
* throw an error if encoding of the CID is not compatible with supplied (or
|
|
3146
|
-
* a default decoder).
|
|
3147
|
-
*
|
|
3148
|
-
* @template {string} Prefix
|
|
3149
|
-
* @template {unknown} Data
|
|
3150
|
-
* @template {number} Code
|
|
3151
|
-
* @template {number} Alg
|
|
3152
|
-
* @template {API.Version} Ver
|
|
3153
|
-
* @param {API.ToString<API.Link<Data, Code, Alg, Ver>, Prefix>} source
|
|
3154
|
-
* @param {API.MultibaseDecoder<Prefix>} [base]
|
|
3155
|
-
* @returns {CID<Data, Code, Alg, Ver>}
|
|
3156
|
-
*/
|
|
3157
|
-
static parse(source, base2) {
|
|
3158
|
-
const [prefix, bytes2] = parseCIDtoBytes(source, base2);
|
|
3159
|
-
const cid = _CID.decode(bytes2);
|
|
3160
|
-
if (cid.version === 0 && source[0] !== "Q") {
|
|
3161
|
-
throw Error("Version 0 CID string must not include multibase prefix");
|
|
3162
|
-
}
|
|
3163
|
-
baseCache(cid).set(prefix, source);
|
|
3164
|
-
return cid;
|
|
3165
|
-
}
|
|
3166
|
-
};
|
|
3167
|
-
var parseCIDtoBytes = (source, base2) => {
|
|
3168
|
-
switch (source[0]) {
|
|
3169
|
-
case "Q": {
|
|
3170
|
-
const decoder = base2 || base58btc;
|
|
3171
|
-
return [
|
|
3172
|
-
/** @type {Prefix} */
|
|
3173
|
-
base58btc.prefix,
|
|
3174
|
-
decoder.decode(`${base58btc.prefix}${source}`)
|
|
3175
|
-
];
|
|
3176
|
-
}
|
|
3177
|
-
case base58btc.prefix: {
|
|
3178
|
-
const decoder = base2 || base58btc;
|
|
3179
|
-
return [
|
|
3180
|
-
/** @type {Prefix} */
|
|
3181
|
-
base58btc.prefix,
|
|
3182
|
-
decoder.decode(source)
|
|
3183
|
-
];
|
|
3184
|
-
}
|
|
3185
|
-
case base32.prefix: {
|
|
3186
|
-
const decoder = base2 || base32;
|
|
3187
|
-
return [
|
|
3188
|
-
/** @type {Prefix} */
|
|
3189
|
-
base32.prefix,
|
|
3190
|
-
decoder.decode(source)
|
|
3191
|
-
];
|
|
3192
|
-
}
|
|
3193
|
-
default: {
|
|
3194
|
-
if (base2 == null) {
|
|
3195
|
-
throw Error(
|
|
3196
|
-
"To parse non base32 or base58btc encoded CID multibase decoder must be provided"
|
|
3197
|
-
);
|
|
3198
|
-
}
|
|
3199
|
-
return [
|
|
3200
|
-
/** @type {Prefix} */
|
|
3201
|
-
source[0],
|
|
3202
|
-
base2.decode(source)
|
|
3203
|
-
];
|
|
3204
|
-
}
|
|
3205
|
-
}
|
|
3206
|
-
};
|
|
3207
|
-
var toStringV0 = (bytes2, cache2, base2) => {
|
|
3208
|
-
const { prefix } = base2;
|
|
3209
|
-
if (prefix !== base58btc.prefix) {
|
|
3210
|
-
throw Error(`Cannot string encode V0 in ${base2.name} encoding`);
|
|
3211
|
-
}
|
|
3212
|
-
const cid = cache2.get(prefix);
|
|
3213
|
-
if (cid == null) {
|
|
3214
|
-
const cid2 = base2.encode(bytes2).slice(1);
|
|
3215
|
-
cache2.set(prefix, cid2);
|
|
3216
|
-
return cid2;
|
|
3217
|
-
} else {
|
|
3218
|
-
return cid;
|
|
3219
|
-
}
|
|
3220
|
-
};
|
|
3221
|
-
var toStringV1 = (bytes2, cache2, base2) => {
|
|
3222
|
-
const { prefix } = base2;
|
|
3223
|
-
const cid = cache2.get(prefix);
|
|
3224
|
-
if (cid == null) {
|
|
3225
|
-
const cid2 = base2.encode(bytes2);
|
|
3226
|
-
cache2.set(prefix, cid2);
|
|
3227
|
-
return cid2;
|
|
3228
|
-
} else {
|
|
3229
|
-
return cid;
|
|
3230
|
-
}
|
|
3231
|
-
};
|
|
3232
|
-
var DAG_PB_CODE = 112;
|
|
3233
|
-
var SHA_256_CODE = 18;
|
|
3234
|
-
var encodeCID = (version, code2, multihash) => {
|
|
3235
|
-
const codeOffset = encodingLength(version);
|
|
3236
|
-
const hashOffset = codeOffset + encodingLength(code2);
|
|
3237
|
-
const bytes2 = new Uint8Array(hashOffset + multihash.byteLength);
|
|
3238
|
-
encodeTo(version, bytes2, 0);
|
|
3239
|
-
encodeTo(code2, bytes2, codeOffset);
|
|
3240
|
-
bytes2.set(multihash, hashOffset);
|
|
3241
|
-
return bytes2;
|
|
3242
|
-
};
|
|
3243
|
-
var cidSymbol = Symbol.for("@ipld/js-cid/CID");
|
|
3244
|
-
|
|
3245
|
-
// ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/hashes/hasher.js
|
|
3246
|
-
var from2 = ({ name: name2, code: code2, encode: encode7 }) => new Hasher(name2, code2, encode7);
|
|
3247
|
-
var Hasher = class {
|
|
3248
|
-
/**
|
|
3249
|
-
*
|
|
3250
|
-
* @param {Name} name
|
|
3251
|
-
* @param {Code} code
|
|
3252
|
-
* @param {(input: Uint8Array) => Await<Uint8Array>} encode
|
|
3253
|
-
*/
|
|
3254
|
-
constructor(name2, code2, encode7) {
|
|
3255
|
-
this.name = name2;
|
|
3256
|
-
this.code = code2;
|
|
3257
|
-
this.encode = encode7;
|
|
3258
|
-
}
|
|
3259
|
-
/**
|
|
3260
|
-
* @param {Uint8Array} input
|
|
3261
|
-
* @returns {Await<Digest.Digest<Code, number>>}
|
|
3262
|
-
*/
|
|
3263
|
-
digest(input) {
|
|
3264
|
-
if (input instanceof Uint8Array) {
|
|
3265
|
-
const result = this.encode(input);
|
|
3266
|
-
return result instanceof Uint8Array ? create(this.code, result) : result.then((digest) => create(this.code, digest));
|
|
3267
|
-
} else {
|
|
3268
|
-
throw Error("Unknown type, must be binary type");
|
|
3269
|
-
}
|
|
3270
|
-
}
|
|
3271
|
-
};
|
|
3272
|
-
|
|
3273
|
-
// ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/bases/base64.js
|
|
3274
|
-
var base64 = rfc4648({
|
|
3275
|
-
prefix: "m",
|
|
3276
|
-
name: "base64",
|
|
3277
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
|
|
3278
|
-
bitsPerChar: 6
|
|
3279
|
-
});
|
|
3280
|
-
var base64pad = rfc4648({
|
|
3281
|
-
prefix: "M",
|
|
3282
|
-
name: "base64pad",
|
|
3283
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
|
3284
|
-
bitsPerChar: 6
|
|
3285
|
-
});
|
|
3286
|
-
var base64url = rfc4648({
|
|
3287
|
-
prefix: "u",
|
|
3288
|
-
name: "base64url",
|
|
3289
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
|
|
3290
|
-
bitsPerChar: 6
|
|
3291
|
-
});
|
|
3292
|
-
var base64urlpad = rfc4648({
|
|
3293
|
-
prefix: "U",
|
|
3294
|
-
name: "base64urlpad",
|
|
3295
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",
|
|
3296
|
-
bitsPerChar: 6
|
|
3297
|
-
});
|
|
3298
|
-
|
|
3299
|
-
// ../../../node_modules/.pnpm/@ipld+dag-json@10.1.5/node_modules/@ipld/dag-json/src/index.js
|
|
3300
|
-
function cidEncoder(obj) {
|
|
3301
|
-
if (obj.asCID !== obj && obj["/"] !== obj.bytes) {
|
|
3302
|
-
return null;
|
|
3303
|
-
}
|
|
3304
|
-
const cid = CID.asCID(obj);
|
|
3305
|
-
if (!cid) {
|
|
3306
|
-
return null;
|
|
3307
|
-
}
|
|
3308
|
-
const cidString = cid.toString();
|
|
3309
|
-
return [
|
|
3310
|
-
new Token(Type.map, Infinity, 1),
|
|
3311
|
-
new Token(Type.string, "/", 1),
|
|
3312
|
-
// key
|
|
3313
|
-
new Token(Type.string, cidString, cidString.length),
|
|
3314
|
-
// value
|
|
3315
|
-
new Token(Type.break, void 0, 1)
|
|
3316
|
-
];
|
|
3317
|
-
}
|
|
3318
|
-
function bytesEncoder(bytes2) {
|
|
3319
|
-
const bytesString = base64.encode(bytes2).slice(1);
|
|
3320
|
-
return [
|
|
3321
|
-
new Token(Type.map, Infinity, 1),
|
|
3322
|
-
new Token(Type.string, "/", 1),
|
|
3323
|
-
// key
|
|
3324
|
-
new Token(Type.map, Infinity, 1),
|
|
3325
|
-
// value
|
|
3326
|
-
new Token(Type.string, "bytes", 5),
|
|
3327
|
-
// inner key
|
|
3328
|
-
new Token(Type.string, bytesString, bytesString.length),
|
|
3329
|
-
// inner value
|
|
3330
|
-
new Token(Type.break, void 0, 1),
|
|
3331
|
-
new Token(Type.break, void 0, 1)
|
|
3332
|
-
];
|
|
3333
|
-
}
|
|
3334
|
-
function taBytesEncoder(obj) {
|
|
3335
|
-
return bytesEncoder(new Uint8Array(obj.buffer, obj.byteOffset, obj.byteLength));
|
|
3336
|
-
}
|
|
3337
|
-
function abBytesEncoder(ab) {
|
|
3338
|
-
return bytesEncoder(new Uint8Array(ab));
|
|
3339
|
-
}
|
|
3340
|
-
function undefinedEncoder() {
|
|
3341
|
-
throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded");
|
|
3342
|
-
}
|
|
3343
|
-
function numberEncoder(num) {
|
|
3344
|
-
if (Number.isNaN(num)) {
|
|
3345
|
-
throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");
|
|
3346
|
-
}
|
|
3347
|
-
if (num === Infinity || num === -Infinity) {
|
|
3348
|
-
throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");
|
|
3349
|
-
}
|
|
3350
|
-
return null;
|
|
3351
|
-
}
|
|
3352
|
-
var encodeOptions = {
|
|
3353
|
-
typeEncoders: {
|
|
3354
|
-
Object: cidEncoder,
|
|
3355
|
-
Buffer: bytesEncoder,
|
|
3356
|
-
Uint8Array: bytesEncoder,
|
|
3357
|
-
Int8Array: taBytesEncoder,
|
|
3358
|
-
Uint16Array: taBytesEncoder,
|
|
3359
|
-
Int16Array: taBytesEncoder,
|
|
3360
|
-
Uint32Array: taBytesEncoder,
|
|
3361
|
-
Int32Array: taBytesEncoder,
|
|
3362
|
-
Float32Array: taBytesEncoder,
|
|
3363
|
-
Float64Array: taBytesEncoder,
|
|
3364
|
-
Uint8ClampedArray: taBytesEncoder,
|
|
3365
|
-
BigInt64Array: taBytesEncoder,
|
|
3366
|
-
BigUint64Array: taBytesEncoder,
|
|
3367
|
-
DataView: taBytesEncoder,
|
|
3368
|
-
ArrayBuffer: abBytesEncoder,
|
|
3369
|
-
undefined: undefinedEncoder,
|
|
3370
|
-
number: numberEncoder
|
|
3371
|
-
}
|
|
3372
|
-
};
|
|
3373
|
-
var DagJsonTokenizer = class extends Tokenizer {
|
|
3374
|
-
/**
|
|
3375
|
-
* @param {Uint8Array} data
|
|
3376
|
-
* @param {object} [options]
|
|
3377
|
-
*/
|
|
3378
|
-
constructor(data, options) {
|
|
3379
|
-
super(data, options);
|
|
3380
|
-
this.tokenBuffer = [];
|
|
3381
|
-
}
|
|
3382
|
-
/**
|
|
3383
|
-
* @returns {boolean}
|
|
3384
|
-
*/
|
|
3385
|
-
done() {
|
|
3386
|
-
return this.tokenBuffer.length === 0 && super.done();
|
|
3387
|
-
}
|
|
3388
|
-
/**
|
|
3389
|
-
* @returns {Token}
|
|
3390
|
-
*/
|
|
3391
|
-
_next() {
|
|
3392
|
-
if (this.tokenBuffer.length > 0) {
|
|
3393
|
-
return this.tokenBuffer.pop();
|
|
3394
|
-
}
|
|
3395
|
-
return super.next();
|
|
3396
|
-
}
|
|
3397
|
-
/**
|
|
3398
|
-
* Implements rules outlined in https://github.com/ipld/specs/pull/356
|
|
3399
|
-
*
|
|
3400
|
-
* @returns {Token}
|
|
3401
|
-
*/
|
|
3402
|
-
next() {
|
|
3403
|
-
const token = this._next();
|
|
3404
|
-
if (token.type === Type.map) {
|
|
3405
|
-
const keyToken = this._next();
|
|
3406
|
-
if (keyToken.type === Type.string && keyToken.value === "/") {
|
|
3407
|
-
const valueToken = this._next();
|
|
3408
|
-
if (valueToken.type === Type.string) {
|
|
3409
|
-
const breakToken = this._next();
|
|
3410
|
-
if (breakToken.type !== Type.break) {
|
|
3411
|
-
throw new Error("Invalid encoded CID form");
|
|
3412
|
-
}
|
|
3413
|
-
this.tokenBuffer.push(valueToken);
|
|
3414
|
-
return new Token(Type.tag, 42, 0);
|
|
3415
|
-
}
|
|
3416
|
-
if (valueToken.type === Type.map) {
|
|
3417
|
-
const innerKeyToken = this._next();
|
|
3418
|
-
if (innerKeyToken.type === Type.string && innerKeyToken.value === "bytes") {
|
|
3419
|
-
const innerValueToken = this._next();
|
|
3420
|
-
if (innerValueToken.type === Type.string) {
|
|
3421
|
-
for (let i = 0; i < 2; i++) {
|
|
3422
|
-
const breakToken = this._next();
|
|
3423
|
-
if (breakToken.type !== Type.break) {
|
|
3424
|
-
throw new Error("Invalid encoded Bytes form");
|
|
3425
|
-
}
|
|
3426
|
-
}
|
|
3427
|
-
const bytes2 = base64.decode(`m${innerValueToken.value}`);
|
|
3428
|
-
return new Token(Type.bytes, bytes2, innerValueToken.value.length);
|
|
3429
|
-
}
|
|
3430
|
-
this.tokenBuffer.push(innerValueToken);
|
|
3431
|
-
}
|
|
3432
|
-
this.tokenBuffer.push(innerKeyToken);
|
|
3433
|
-
}
|
|
3434
|
-
this.tokenBuffer.push(valueToken);
|
|
3435
|
-
}
|
|
3436
|
-
this.tokenBuffer.push(keyToken);
|
|
3437
|
-
}
|
|
3438
|
-
return token;
|
|
3439
|
-
}
|
|
3440
|
-
};
|
|
3441
|
-
var decodeOptions = {
|
|
3442
|
-
allowIndefinite: false,
|
|
3443
|
-
allowUndefined: false,
|
|
3444
|
-
allowNaN: false,
|
|
3445
|
-
allowInfinity: false,
|
|
3446
|
-
allowBigInt: true,
|
|
3447
|
-
// this will lead to BigInt for ints outside of
|
|
3448
|
-
// safe-integer range, which may surprise users
|
|
3449
|
-
strict: true,
|
|
3450
|
-
useMaps: false,
|
|
3451
|
-
rejectDuplicateMapKeys: true,
|
|
3452
|
-
/** @type {import('cborg').TagDecoder[]} */
|
|
3453
|
-
tags: []
|
|
3454
|
-
};
|
|
3455
|
-
decodeOptions.tags[42] = CID.parse;
|
|
3456
|
-
var name = "dag-json";
|
|
3457
|
-
var code = 297;
|
|
3458
|
-
var encode5 = (node) => encode2(node, encodeOptions);
|
|
3459
|
-
var decode7 = (data) => {
|
|
3460
|
-
const options = Object.assign(decodeOptions, { tokenizer: new DagJsonTokenizer(data, decodeOptions) });
|
|
3461
|
-
return decode2(data, options);
|
|
3462
|
-
};
|
|
3463
|
-
var format2 = (node) => utf8Decoder.decode(encode5(node));
|
|
3464
|
-
var utf8Decoder = new TextDecoder();
|
|
3465
|
-
var parse = (data) => decode7(utf8Encoder.encode(data));
|
|
3466
|
-
var utf8Encoder = new TextEncoder();
|
|
3467
|
-
|
|
3468
|
-
// ../../../node_modules/.pnpm/@noble+hashes@1.3.2/node_modules/@noble/hashes/esm/_assert.js
|
|
3469
|
-
function bytes(b, ...lengths) {
|
|
3470
|
-
if (!(b instanceof Uint8Array))
|
|
3471
|
-
throw new Error("Expected Uint8Array");
|
|
3472
|
-
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
3473
|
-
throw new Error(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`);
|
|
3474
|
-
}
|
|
3475
|
-
function exists(instance, checkFinished = true) {
|
|
3476
|
-
if (instance.destroyed)
|
|
3477
|
-
throw new Error("Hash instance has been destroyed");
|
|
3478
|
-
if (checkFinished && instance.finished)
|
|
3479
|
-
throw new Error("Hash#digest() has already been called");
|
|
3480
|
-
}
|
|
3481
|
-
function output(out, instance) {
|
|
3482
|
-
bytes(out);
|
|
3483
|
-
const min = instance.outputLen;
|
|
3484
|
-
if (out.length < min) {
|
|
3485
|
-
throw new Error(`digestInto() expects output buffer of length at least ${min}`);
|
|
3486
|
-
}
|
|
3487
|
-
}
|
|
3488
|
-
|
|
3489
|
-
// ../../../node_modules/.pnpm/@noble+hashes@1.3.2/node_modules/@noble/hashes/esm/utils.js
|
|
3490
|
-
var u8a = (a) => a instanceof Uint8Array;
|
|
3491
|
-
var createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
3492
|
-
var rotr = (word, shift) => word << 32 - shift | word >>> shift;
|
|
3493
|
-
var isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
3494
|
-
if (!isLE)
|
|
3495
|
-
throw new Error("Non little-endian hardware is not supported");
|
|
3496
|
-
function utf8ToBytes2(str) {
|
|
3497
|
-
if (typeof str !== "string")
|
|
3498
|
-
throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
|
|
3499
|
-
return new Uint8Array(new TextEncoder().encode(str));
|
|
3500
|
-
}
|
|
3501
|
-
function toBytes(data) {
|
|
3502
|
-
if (typeof data === "string")
|
|
3503
|
-
data = utf8ToBytes2(data);
|
|
3504
|
-
if (!u8a(data))
|
|
3505
|
-
throw new Error(`expected Uint8Array, got ${typeof data}`);
|
|
3506
|
-
return data;
|
|
3507
|
-
}
|
|
3508
|
-
var Hash = class {
|
|
3509
|
-
// Safe version that clones internal state
|
|
3510
|
-
clone() {
|
|
3511
|
-
return this._cloneInto();
|
|
3512
|
-
}
|
|
3513
|
-
};
|
|
3514
|
-
var toStr = {}.toString;
|
|
3515
|
-
function wrapConstructor(hashCons) {
|
|
3516
|
-
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
3517
|
-
const tmp = hashCons();
|
|
3518
|
-
hashC.outputLen = tmp.outputLen;
|
|
3519
|
-
hashC.blockLen = tmp.blockLen;
|
|
3520
|
-
hashC.create = () => hashCons();
|
|
3521
|
-
return hashC;
|
|
3522
|
-
}
|
|
3523
|
-
|
|
3524
|
-
// ../../../node_modules/.pnpm/@noble+hashes@1.3.2/node_modules/@noble/hashes/esm/_sha2.js
|
|
3525
|
-
function setBigUint64(view, byteOffset, value, isLE2) {
|
|
3526
|
-
if (typeof view.setBigUint64 === "function")
|
|
3527
|
-
return view.setBigUint64(byteOffset, value, isLE2);
|
|
3528
|
-
const _32n = BigInt(32);
|
|
3529
|
-
const _u32_max = BigInt(4294967295);
|
|
3530
|
-
const wh = Number(value >> _32n & _u32_max);
|
|
3531
|
-
const wl = Number(value & _u32_max);
|
|
3532
|
-
const h = isLE2 ? 4 : 0;
|
|
3533
|
-
const l = isLE2 ? 0 : 4;
|
|
3534
|
-
view.setUint32(byteOffset + h, wh, isLE2);
|
|
3535
|
-
view.setUint32(byteOffset + l, wl, isLE2);
|
|
3536
|
-
}
|
|
3537
|
-
var SHA2 = class extends Hash {
|
|
3538
|
-
constructor(blockLen, outputLen, padOffset, isLE2) {
|
|
3539
|
-
super();
|
|
3540
|
-
this.blockLen = blockLen;
|
|
3541
|
-
this.outputLen = outputLen;
|
|
3542
|
-
this.padOffset = padOffset;
|
|
3543
|
-
this.isLE = isLE2;
|
|
3544
|
-
this.finished = false;
|
|
3545
|
-
this.length = 0;
|
|
3546
|
-
this.pos = 0;
|
|
3547
|
-
this.destroyed = false;
|
|
3548
|
-
this.buffer = new Uint8Array(blockLen);
|
|
3549
|
-
this.view = createView(this.buffer);
|
|
3550
|
-
}
|
|
3551
|
-
update(data) {
|
|
3552
|
-
exists(this);
|
|
3553
|
-
const { view, buffer: buffer2, blockLen } = this;
|
|
3554
|
-
data = toBytes(data);
|
|
3555
|
-
const len = data.length;
|
|
3556
|
-
for (let pos = 0; pos < len; ) {
|
|
3557
|
-
const take = Math.min(blockLen - this.pos, len - pos);
|
|
3558
|
-
if (take === blockLen) {
|
|
3559
|
-
const dataView2 = createView(data);
|
|
3560
|
-
for (; blockLen <= len - pos; pos += blockLen)
|
|
3561
|
-
this.process(dataView2, pos);
|
|
3562
|
-
continue;
|
|
3563
|
-
}
|
|
3564
|
-
buffer2.set(data.subarray(pos, pos + take), this.pos);
|
|
3565
|
-
this.pos += take;
|
|
3566
|
-
pos += take;
|
|
3567
|
-
if (this.pos === blockLen) {
|
|
3568
|
-
this.process(view, 0);
|
|
3569
|
-
this.pos = 0;
|
|
3570
|
-
}
|
|
3571
|
-
}
|
|
3572
|
-
this.length += data.length;
|
|
3573
|
-
this.roundClean();
|
|
3574
|
-
return this;
|
|
3575
|
-
}
|
|
3576
|
-
digestInto(out) {
|
|
3577
|
-
exists(this);
|
|
3578
|
-
output(out, this);
|
|
3579
|
-
this.finished = true;
|
|
3580
|
-
const { buffer: buffer2, view, blockLen, isLE: isLE2 } = this;
|
|
3581
|
-
let { pos } = this;
|
|
3582
|
-
buffer2[pos++] = 128;
|
|
3583
|
-
this.buffer.subarray(pos).fill(0);
|
|
3584
|
-
if (this.padOffset > blockLen - pos) {
|
|
3585
|
-
this.process(view, 0);
|
|
3586
|
-
pos = 0;
|
|
3587
|
-
}
|
|
3588
|
-
for (let i = pos; i < blockLen; i++)
|
|
3589
|
-
buffer2[i] = 0;
|
|
3590
|
-
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE2);
|
|
3591
|
-
this.process(view, 0);
|
|
3592
|
-
const oview = createView(out);
|
|
3593
|
-
const len = this.outputLen;
|
|
3594
|
-
if (len % 4)
|
|
3595
|
-
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
3596
|
-
const outLen = len / 4;
|
|
3597
|
-
const state = this.get();
|
|
3598
|
-
if (outLen > state.length)
|
|
3599
|
-
throw new Error("_sha2: outputLen bigger than state");
|
|
3600
|
-
for (let i = 0; i < outLen; i++)
|
|
3601
|
-
oview.setUint32(4 * i, state[i], isLE2);
|
|
3602
|
-
}
|
|
3603
|
-
digest() {
|
|
3604
|
-
const { buffer: buffer2, outputLen } = this;
|
|
3605
|
-
this.digestInto(buffer2);
|
|
3606
|
-
const res = buffer2.slice(0, outputLen);
|
|
3607
|
-
this.destroy();
|
|
3608
|
-
return res;
|
|
3609
|
-
}
|
|
3610
|
-
_cloneInto(to) {
|
|
3611
|
-
to || (to = new this.constructor());
|
|
3612
|
-
to.set(...this.get());
|
|
3613
|
-
const { blockLen, buffer: buffer2, length: length2, finished, destroyed, pos } = this;
|
|
3614
|
-
to.length = length2;
|
|
3615
|
-
to.pos = pos;
|
|
3616
|
-
to.finished = finished;
|
|
3617
|
-
to.destroyed = destroyed;
|
|
3618
|
-
if (length2 % blockLen)
|
|
3619
|
-
to.buffer.set(buffer2);
|
|
3620
|
-
return to;
|
|
3621
|
-
}
|
|
3622
|
-
};
|
|
3623
|
-
|
|
3624
|
-
// ../../../node_modules/.pnpm/@noble+hashes@1.3.2/node_modules/@noble/hashes/esm/sha256.js
|
|
3625
|
-
var Chi = (a, b, c) => a & b ^ ~a & c;
|
|
3626
|
-
var Maj = (a, b, c) => a & b ^ a & c ^ b & c;
|
|
3627
|
-
var SHA256_K = /* @__PURE__ */ new Uint32Array([
|
|
3628
|
-
1116352408,
|
|
3629
|
-
1899447441,
|
|
3630
|
-
3049323471,
|
|
3631
|
-
3921009573,
|
|
3632
|
-
961987163,
|
|
3633
|
-
1508970993,
|
|
3634
|
-
2453635748,
|
|
3635
|
-
2870763221,
|
|
3636
|
-
3624381080,
|
|
3637
|
-
310598401,
|
|
3638
|
-
607225278,
|
|
3639
|
-
1426881987,
|
|
3640
|
-
1925078388,
|
|
3641
|
-
2162078206,
|
|
3642
|
-
2614888103,
|
|
3643
|
-
3248222580,
|
|
3644
|
-
3835390401,
|
|
3645
|
-
4022224774,
|
|
3646
|
-
264347078,
|
|
3647
|
-
604807628,
|
|
3648
|
-
770255983,
|
|
3649
|
-
1249150122,
|
|
3650
|
-
1555081692,
|
|
3651
|
-
1996064986,
|
|
3652
|
-
2554220882,
|
|
3653
|
-
2821834349,
|
|
3654
|
-
2952996808,
|
|
3655
|
-
3210313671,
|
|
3656
|
-
3336571891,
|
|
3657
|
-
3584528711,
|
|
3658
|
-
113926993,
|
|
3659
|
-
338241895,
|
|
3660
|
-
666307205,
|
|
3661
|
-
773529912,
|
|
3662
|
-
1294757372,
|
|
3663
|
-
1396182291,
|
|
3664
|
-
1695183700,
|
|
3665
|
-
1986661051,
|
|
3666
|
-
2177026350,
|
|
3667
|
-
2456956037,
|
|
3668
|
-
2730485921,
|
|
3669
|
-
2820302411,
|
|
3670
|
-
3259730800,
|
|
3671
|
-
3345764771,
|
|
3672
|
-
3516065817,
|
|
3673
|
-
3600352804,
|
|
3674
|
-
4094571909,
|
|
3675
|
-
275423344,
|
|
3676
|
-
430227734,
|
|
3677
|
-
506948616,
|
|
3678
|
-
659060556,
|
|
3679
|
-
883997877,
|
|
3680
|
-
958139571,
|
|
3681
|
-
1322822218,
|
|
3682
|
-
1537002063,
|
|
3683
|
-
1747873779,
|
|
3684
|
-
1955562222,
|
|
3685
|
-
2024104815,
|
|
3686
|
-
2227730452,
|
|
3687
|
-
2361852424,
|
|
3688
|
-
2428436474,
|
|
3689
|
-
2756734187,
|
|
3690
|
-
3204031479,
|
|
3691
|
-
3329325298
|
|
3692
|
-
]);
|
|
3693
|
-
var IV = /* @__PURE__ */ new Uint32Array([
|
|
3694
|
-
1779033703,
|
|
3695
|
-
3144134277,
|
|
3696
|
-
1013904242,
|
|
3697
|
-
2773480762,
|
|
3698
|
-
1359893119,
|
|
3699
|
-
2600822924,
|
|
3700
|
-
528734635,
|
|
3701
|
-
1541459225
|
|
3702
|
-
]);
|
|
3703
|
-
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
3704
|
-
var SHA256 = class extends SHA2 {
|
|
3705
|
-
constructor() {
|
|
3706
|
-
super(64, 32, 8, false);
|
|
3707
|
-
this.A = IV[0] | 0;
|
|
3708
|
-
this.B = IV[1] | 0;
|
|
3709
|
-
this.C = IV[2] | 0;
|
|
3710
|
-
this.D = IV[3] | 0;
|
|
3711
|
-
this.E = IV[4] | 0;
|
|
3712
|
-
this.F = IV[5] | 0;
|
|
3713
|
-
this.G = IV[6] | 0;
|
|
3714
|
-
this.H = IV[7] | 0;
|
|
3715
|
-
}
|
|
3716
|
-
get() {
|
|
3717
|
-
const { A, B, C, D, E, F, G, H } = this;
|
|
3718
|
-
return [A, B, C, D, E, F, G, H];
|
|
3719
|
-
}
|
|
3720
|
-
// prettier-ignore
|
|
3721
|
-
set(A, B, C, D, E, F, G, H) {
|
|
3722
|
-
this.A = A | 0;
|
|
3723
|
-
this.B = B | 0;
|
|
3724
|
-
this.C = C | 0;
|
|
3725
|
-
this.D = D | 0;
|
|
3726
|
-
this.E = E | 0;
|
|
3727
|
-
this.F = F | 0;
|
|
3728
|
-
this.G = G | 0;
|
|
3729
|
-
this.H = H | 0;
|
|
3730
|
-
}
|
|
3731
|
-
process(view, offset) {
|
|
3732
|
-
for (let i = 0; i < 16; i++, offset += 4)
|
|
3733
|
-
SHA256_W[i] = view.getUint32(offset, false);
|
|
3734
|
-
for (let i = 16; i < 64; i++) {
|
|
3735
|
-
const W15 = SHA256_W[i - 15];
|
|
3736
|
-
const W2 = SHA256_W[i - 2];
|
|
3737
|
-
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
3738
|
-
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
3739
|
-
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
3740
|
-
}
|
|
3741
|
-
let { A, B, C, D, E, F, G, H } = this;
|
|
3742
|
-
for (let i = 0; i < 64; i++) {
|
|
3743
|
-
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
3744
|
-
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
3745
|
-
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
3746
|
-
const T2 = sigma0 + Maj(A, B, C) | 0;
|
|
3747
|
-
H = G;
|
|
3748
|
-
G = F;
|
|
3749
|
-
F = E;
|
|
3750
|
-
E = D + T1 | 0;
|
|
3751
|
-
D = C;
|
|
3752
|
-
C = B;
|
|
3753
|
-
B = A;
|
|
3754
|
-
A = T1 + T2 | 0;
|
|
3755
|
-
}
|
|
3756
|
-
A = A + this.A | 0;
|
|
3757
|
-
B = B + this.B | 0;
|
|
3758
|
-
C = C + this.C | 0;
|
|
3759
|
-
D = D + this.D | 0;
|
|
3760
|
-
E = E + this.E | 0;
|
|
3761
|
-
F = F + this.F | 0;
|
|
3762
|
-
G = G + this.G | 0;
|
|
3763
|
-
H = H + this.H | 0;
|
|
3764
|
-
this.set(A, B, C, D, E, F, G, H);
|
|
3765
|
-
}
|
|
3766
|
-
roundClean() {
|
|
3767
|
-
SHA256_W.fill(0);
|
|
3768
|
-
}
|
|
3769
|
-
destroy() {
|
|
3770
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
3771
|
-
this.buffer.fill(0);
|
|
3772
|
-
}
|
|
3773
|
-
};
|
|
3774
|
-
var sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
|
|
3775
|
-
|
|
3776
|
-
// ../../../node_modules/.pnpm/besonders-logger@1.0.0-RC11_3myifxmc6j23mthq5k5h6wvx4a/node_modules/besonders-logger/dist/src/index.mjs
|
|
3777
|
-
var __create = Object.create;
|
|
3778
|
-
var __defProp = Object.defineProperty;
|
|
3779
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3780
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3781
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
3782
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
3783
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3784
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
3785
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
3786
|
-
};
|
|
3787
|
-
var __copyProps = (to, from3, except, desc) => {
|
|
3788
|
-
if (from3 && typeof from3 === "object" || typeof from3 === "function") {
|
|
3789
|
-
for (let key of __getOwnPropNames(from3))
|
|
3790
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
3791
|
-
__defProp(to, key, { get: () => from3[key], enumerable: !(desc = __getOwnPropDesc(from3, key)) || desc.enumerable });
|
|
3792
|
-
}
|
|
3793
|
-
return to;
|
|
3794
|
-
};
|
|
3795
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
3796
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
3797
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
3798
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
3799
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
3800
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
3801
|
-
mod
|
|
3802
|
-
));
|
|
3803
|
-
var __publicField = (obj, key, value) => {
|
|
3804
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3805
|
-
return value;
|
|
3806
|
-
};
|
|
3807
|
-
var require_lib = __commonJS({
|
|
3808
|
-
"../../node_modules/.pnpm/browser-or-node@2.1.1/node_modules/browser-or-node/lib/index.js"(exports) {
|
|
3809
|
-
"use strict";
|
|
3810
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3811
|
-
value: true
|
|
3812
|
-
});
|
|
3813
|
-
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
|
|
3814
|
-
return typeof obj;
|
|
3815
|
-
} : function(obj) {
|
|
3816
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
3817
|
-
};
|
|
3818
|
-
var isBrowser2 = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
3819
|
-
var isNode2 = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
3820
|
-
var isWebWorker = (typeof self === "undefined" ? "undefined" : _typeof(self)) === "object" && self.constructor && self.constructor.name === "DedicatedWorkerGlobalScope";
|
|
3821
|
-
var isJsDom = typeof window !== "undefined" && window.name === "nodejs" || typeof navigator !== "undefined" && (navigator.userAgent.includes("Node.js") || navigator.userAgent.includes("jsdom"));
|
|
3822
|
-
var isDeno = typeof Deno !== "undefined" && typeof Deno.version !== "undefined" && typeof Deno.version.deno !== "undefined";
|
|
3823
|
-
exports.isBrowser = isBrowser2;
|
|
3824
|
-
exports.isWebWorker = isWebWorker;
|
|
3825
|
-
exports.isNode = isNode2;
|
|
3826
|
-
exports.isJsDom = isJsDom;
|
|
3827
|
-
exports.isDeno = isDeno;
|
|
3828
|
-
}
|
|
3829
|
-
});
|
|
3830
|
-
var require_fast_json_stable_stringify = __commonJS({
|
|
3831
|
-
"../../node_modules/.pnpm/fast-json-stable-stringify@2.1.0/node_modules/fast-json-stable-stringify/index.js"(exports, module) {
|
|
3832
|
-
"use strict";
|
|
3833
|
-
module.exports = function(data, opts) {
|
|
3834
|
-
if (!opts)
|
|
3835
|
-
opts = {};
|
|
3836
|
-
if (typeof opts === "function")
|
|
3837
|
-
opts = { cmp: opts };
|
|
3838
|
-
var cycles = typeof opts.cycles === "boolean" ? opts.cycles : false;
|
|
3839
|
-
var cmp = opts.cmp && /* @__PURE__ */ function(f) {
|
|
3840
|
-
return function(node) {
|
|
3841
|
-
return function(a, b) {
|
|
3842
|
-
var aobj = { key: a, value: node[a] };
|
|
3843
|
-
var bobj = { key: b, value: node[b] };
|
|
3844
|
-
return f(aobj, bobj);
|
|
3845
|
-
};
|
|
3846
|
-
};
|
|
3847
|
-
}(opts.cmp);
|
|
3848
|
-
var seen = [];
|
|
3849
|
-
return function stringify2(node) {
|
|
3850
|
-
if (node && node.toJSON && typeof node.toJSON === "function") {
|
|
3851
|
-
node = node.toJSON();
|
|
3852
|
-
}
|
|
3853
|
-
if (node === void 0)
|
|
3854
|
-
return;
|
|
3855
|
-
if (typeof node == "number")
|
|
3856
|
-
return isFinite(node) ? "" + node : "null";
|
|
3857
|
-
if (typeof node !== "object")
|
|
3858
|
-
return JSON.stringify(node);
|
|
3859
|
-
var i, out;
|
|
3860
|
-
if (Array.isArray(node)) {
|
|
3861
|
-
out = "[";
|
|
3862
|
-
for (i = 0; i < node.length; i++) {
|
|
3863
|
-
if (i)
|
|
3864
|
-
out += ",";
|
|
3865
|
-
out += stringify2(node[i]) || "null";
|
|
3866
|
-
}
|
|
3867
|
-
return out + "]";
|
|
3868
|
-
}
|
|
3869
|
-
if (node === null)
|
|
3870
|
-
return "null";
|
|
3871
|
-
if (seen.indexOf(node) !== -1) {
|
|
3872
|
-
if (cycles)
|
|
3873
|
-
return JSON.stringify("__cycle__");
|
|
3874
|
-
throw new TypeError("Converting circular structure to JSON");
|
|
3875
|
-
}
|
|
3876
|
-
var seenIndex = seen.push(node) - 1;
|
|
3877
|
-
var keys = Object.keys(node).sort(cmp && cmp(node));
|
|
3878
|
-
out = "";
|
|
3879
|
-
for (i = 0; i < keys.length; i++) {
|
|
3880
|
-
var key = keys[i];
|
|
3881
|
-
var value = stringify2(node[key]);
|
|
3882
|
-
if (!value)
|
|
3883
|
-
continue;
|
|
3884
|
-
if (out)
|
|
3885
|
-
out += ",";
|
|
3886
|
-
out += JSON.stringify(key) + ":" + value;
|
|
3887
|
-
}
|
|
3888
|
-
seen.splice(seenIndex, 1);
|
|
3889
|
-
return "{" + out + "}";
|
|
3890
|
-
}(data);
|
|
3891
|
-
};
|
|
3892
|
-
}
|
|
3893
|
-
});
|
|
3894
|
-
var import_browser_or_node = __toESM(require_lib(), 1);
|
|
3895
|
-
var import_fast_json_stable_stringify = __toESM(require_fast_json_stable_stringify(), 1);
|
|
3896
|
-
var TIME_PREFIX_ENABLED = false;
|
|
3897
|
-
var PERFORMANCE_PREFIX_ENABLED = false;
|
|
3898
|
-
if (import_browser_or_node.isNode) {
|
|
3899
|
-
if (process?.env?.LOGGER_TIME_PREFIX)
|
|
3900
|
-
TIME_PREFIX_ENABLED = process?.env?.LOGGER_TIME_PREFIX === "true";
|
|
3901
|
-
if (process?.env?.LOGGER_PERF_PREFIX)
|
|
3902
|
-
PERFORMANCE_PREFIX_ENABLED = process?.env?.LOGGER_PERF_PREFIX === "true";
|
|
3903
|
-
}
|
|
3904
|
-
var DEFAULT_CONFIG = Object.freeze({
|
|
3905
|
-
prefix: void 0,
|
|
3906
|
-
time: TIME_PREFIX_ENABLED,
|
|
3907
|
-
delta: PERFORMANCE_PREFIX_ENABLED,
|
|
3908
|
-
dimDebugOnServer: true,
|
|
3909
|
-
printOriginOnServer: true,
|
|
3910
|
-
serverInspectOptions: {},
|
|
3911
|
-
customFormattersOnServer: true,
|
|
3912
|
-
// Depth of stacktrace to show on server
|
|
3913
|
-
// - integer saying how many lines
|
|
3914
|
-
// - false to disable, true for all
|
|
3915
|
-
printStackLinesOnServer: false,
|
|
3916
|
-
dim: true
|
|
3917
|
-
});
|
|
3918
|
-
var StringFormatters = [
|
|
3919
|
-
// Format to string (Client console - currently not on server)
|
|
3920
|
-
// {
|
|
3921
|
-
// match: obj => obj instanceof Model,
|
|
3922
|
-
// format: m => {
|
|
3923
|
-
// const { displayName } = m
|
|
3924
|
-
// return `${m.constructor.name}#${m.ID}${displayName ? `{${displayName}}` : ''}`
|
|
3925
|
-
// },
|
|
3926
|
-
// },
|
|
3927
|
-
];
|
|
3928
|
-
var LoggerTime = class {
|
|
3929
|
-
sinceFirst = 0;
|
|
3930
|
-
sinceLast = 0;
|
|
3931
|
-
time = false;
|
|
3932
|
-
delta = false;
|
|
3933
|
-
constructor(sinceFirst, sinceLast, time, delta) {
|
|
3934
|
-
Object.assign(this, { sinceFirst, sinceLast, time, delta });
|
|
3935
|
-
}
|
|
3936
|
-
toString() {
|
|
3937
|
-
const sinceFirstNum = this.sinceFirst * 1e-3;
|
|
3938
|
-
const sinceFirst = sinceFirstNum.toFixed(sinceFirstNum < 5 ? 2 : 1);
|
|
3939
|
-
const sinceLast = this.sinceLast < 1e3 ? `${this.sinceLast.toFixed(0)}`.padStart(5, " ") : `${`${(this.sinceLast * 1e-3).toFixed(this.sinceLast < 1e4 ? 1 : 0)}`.padStart(4, " ")}s`;
|
|
3940
|
-
return `[${[this.time ? sinceFirst : null, this.delta ? sinceLast : null].join(",")}]`;
|
|
3941
|
-
}
|
|
3942
|
-
};
|
|
3943
|
-
var Style = class {
|
|
3944
|
-
constructor(style, string) {
|
|
3945
|
-
Object.assign(this, { style, string });
|
|
3946
|
-
}
|
|
3947
|
-
};
|
|
3948
|
-
var formattersEnabled = false;
|
|
3949
|
-
var _Logger = class {
|
|
3950
|
-
/**
|
|
3951
|
-
* This is a clever way to log without the extra check on each log line.
|
|
3952
|
-
* Use it like this:
|
|
3953
|
-
* ```
|
|
3954
|
-
* const { WARN, LOG, DEBUG, VERBOSE } = Logger.setup(Logger.INFO); // eslint-disable-line no-unused-vars
|
|
3955
|
-
* LOG('message', data);
|
|
3956
|
-
* DEBUG(this.collectionName, '...')
|
|
3957
|
-
* if (!VERBOSE.isDisabled) {
|
|
3958
|
-
* const verboseStuff = generateVerboseStuff(); // computationally intensive
|
|
3959
|
-
* VERBOSE('Here it is:', verboseStuff)
|
|
3960
|
-
* }
|
|
3961
|
-
* ```
|
|
3962
|
-
*
|
|
3963
|
-
* @ param {number} level See {@link LVs}
|
|
3964
|
-
* @ param {object} config see DEFAULT_CONFIG
|
|
3965
|
-
* @ typedef {Function & {isDisabled: boolean, isEnabled: boolean, ...}} LogFunc
|
|
3966
|
-
* @ returns {{LOG: LogFunc, VERBOSE: LogFunc, DEBUG: LogFunc, WARN: LogFunc, ERROR: LogFunc}}
|
|
3967
|
-
*/
|
|
3968
|
-
static setup(level = _Logger.INFO, config = {}) {
|
|
3969
|
-
config = Object.assign({}, DEFAULT_CONFIG, config);
|
|
3970
|
-
if (level > 10)
|
|
3971
|
-
console.debug("setup logger", { config });
|
|
3972
|
-
const debugLogForStub = this.wrapLog(console.debug, { ...config, dim: config.dimDebugOnServer });
|
|
3973
|
-
const stub = (...args) => {
|
|
3974
|
-
if (window?.FORCE_DISABLE_LOGLEVEL)
|
|
3975
|
-
debugLogForStub(...args);
|
|
3976
|
-
};
|
|
3977
|
-
stub.isDisabled = true;
|
|
3978
|
-
stub.isEnabled = false;
|
|
3979
|
-
const groupCollapsed = this.wrapLog(console.groupCollapsed, config);
|
|
3980
|
-
const addExtraFxs = (enabled, func) => {
|
|
3981
|
-
function group(...args) {
|
|
3982
|
-
const functionToWrap = args[args.length - 1];
|
|
3983
|
-
if (functionToWrap === stub)
|
|
3984
|
-
return functionToWrap();
|
|
3985
|
-
groupCollapsed(...args.slice(0, -1));
|
|
3986
|
-
const asyncWrapper = async () => {
|
|
3987
|
-
try {
|
|
3988
|
-
const result = functionToWrap();
|
|
3989
|
-
return result instanceof Promise ? await result : result;
|
|
3990
|
-
} finally {
|
|
3991
|
-
console.groupEnd();
|
|
3992
|
-
}
|
|
3993
|
-
};
|
|
3994
|
-
return asyncWrapper();
|
|
3995
|
-
}
|
|
3996
|
-
const realFunc = Object.assign(
|
|
3997
|
-
func.bind({}),
|
|
3998
|
-
// clone function - https://stackoverflow.com/a/6772648
|
|
3999
|
-
{
|
|
4000
|
-
isEnabled: enabled,
|
|
4001
|
-
isDisabled: !enabled,
|
|
4002
|
-
group,
|
|
4003
|
-
force: func
|
|
4004
|
-
}
|
|
4005
|
-
);
|
|
4006
|
-
if (enabled) {
|
|
4007
|
-
return realFunc;
|
|
4008
|
-
} else {
|
|
4009
|
-
return Object.assign(
|
|
4010
|
-
stub.bind({}),
|
|
4011
|
-
// clone stub function - https://stackoverflow.com/a/6772648
|
|
4012
|
-
{
|
|
4013
|
-
isEnabled: enabled,
|
|
4014
|
-
isDisabled: !enabled,
|
|
4015
|
-
group,
|
|
4016
|
-
force: realFunc
|
|
4017
|
-
}
|
|
4018
|
-
);
|
|
4019
|
-
}
|
|
4020
|
-
};
|
|
4021
|
-
const ERRFX = addExtraFxs(level >= _Logger.ERROR, this.wrapLog(console.error, config));
|
|
4022
|
-
const ERROR2 = (...params) => {
|
|
4023
|
-
ERRFX(...params);
|
|
4024
|
-
return new Error((0, import_fast_json_stable_stringify.default)(params));
|
|
4025
|
-
};
|
|
4026
|
-
return {
|
|
4027
|
-
ERROR: ERROR2,
|
|
4028
|
-
WARN: addExtraFxs(level >= _Logger.WARN, this.wrapLog(console.warn, config)),
|
|
4029
|
-
LOG: addExtraFxs(level >= _Logger.INFO, this.wrapLog(console.log, config)),
|
|
4030
|
-
DEBUG: addExtraFxs(level >= _Logger.DEBUG, this.wrapLog(console.log, { ...config, dim: config.dimDebugOnServer })),
|
|
4031
|
-
// not using console.debug as that requires dev tools verbose to be enabled
|
|
4032
|
-
VERBOSE: addExtraFxs(level >= _Logger.VERBOSE, this.wrapLog(console.debug, { ...config, dim: config.dimDebugOnServer }))
|
|
4033
|
-
};
|
|
4034
|
-
}
|
|
4035
|
-
static wrapLog(logFunc, config) {
|
|
4036
|
-
if (!import_browser_or_node.isNode) {
|
|
4037
|
-
const fixedArgs = [];
|
|
4038
|
-
if (config.time || config.delta) {
|
|
4039
|
-
const isChrome = import_browser_or_node.isBrowser && navigator.userAgent.includes("Chrome");
|
|
4040
|
-
const p = isChrome ? ["", _Logger.timeStr(!!config.time, !!config.delta)] : [];
|
|
4041
|
-
fixedArgs.push(...p);
|
|
4042
|
-
}
|
|
4043
|
-
if (config.prefix) {
|
|
4044
|
-
if (formattersEnabled)
|
|
4045
|
-
fixedArgs.push(new Style("dim", config.prefix));
|
|
4046
|
-
else
|
|
4047
|
-
fixedArgs.push(config.prefix);
|
|
4048
|
-
}
|
|
4049
|
-
return logFunc.bind(console, ...fixedArgs);
|
|
4050
|
-
} else {
|
|
4051
|
-
return logFunc.bind(console);
|
|
4052
|
-
}
|
|
4053
|
-
}
|
|
4054
|
-
// static log(msg, logPerformance = true) {
|
|
4055
|
-
// const p = this.perf();
|
|
4056
|
-
// return logPerformance ? `${p} ${msg}` : msg;
|
|
4057
|
-
// }
|
|
4058
|
-
static timeStr(time, delta, returnAsString = 0) {
|
|
4059
|
-
if (!performance.now)
|
|
4060
|
-
return void 0;
|
|
4061
|
-
const now = performance.now();
|
|
4062
|
-
if (!_Logger.firstLog) {
|
|
4063
|
-
_Logger.firstLog = now;
|
|
4064
|
-
_Logger.lastLog = now;
|
|
4065
|
-
}
|
|
4066
|
-
const p = new LoggerTime(now - _Logger.firstLog, now - _Logger.lastLog, time, delta);
|
|
4067
|
-
_Logger.lastLog = now;
|
|
4068
|
-
return returnAsString ? p.toString() : p;
|
|
4069
|
-
}
|
|
4070
|
-
// (for nodejs) ~ https://stackoverflow.com/a/47296370/1633985
|
|
4071
|
-
static getOriginFromStack(stack) {
|
|
4072
|
-
let skippedFirst = false;
|
|
4073
|
-
for (const line of stack.split("\n")) {
|
|
4074
|
-
const matches = line.match(/^\s+at\s+(.*)/);
|
|
4075
|
-
if (matches) {
|
|
4076
|
-
if (skippedFirst) {
|
|
4077
|
-
return matches[1].trim().replace(__dirname, "");
|
|
4078
|
-
}
|
|
4079
|
-
skippedFirst = true;
|
|
4080
|
-
}
|
|
4081
|
-
}
|
|
4082
|
-
}
|
|
4083
|
-
};
|
|
4084
|
-
var Logger = _Logger;
|
|
4085
|
-
__publicField(Logger, "ERROR", 2);
|
|
4086
|
-
__publicField(Logger, "WARN", 4);
|
|
4087
|
-
__publicField(Logger, "INFO", 6);
|
|
4088
|
-
__publicField(Logger, "LOG", 6);
|
|
4089
|
-
__publicField(Logger, "DEBUG", 8);
|
|
4090
|
-
__publicField(Logger, "VERBOSE", 10);
|
|
4091
|
-
__publicField(Logger, "firstLog", 0);
|
|
4092
|
-
__publicField(Logger, "lastLog", 0);
|
|
4093
|
-
if (import_browser_or_node.isBrowser) {
|
|
4094
|
-
window.devtoolsFormatters = window.devtoolsFormatters ?? [];
|
|
4095
|
-
window.devtoolsFormatters.push(
|
|
4096
|
-
{
|
|
4097
|
-
// Custom formatters
|
|
4098
|
-
header: (obj) => {
|
|
4099
|
-
if (StringFormatters && StringFormatters.length) {
|
|
4100
|
-
for (const formatter of StringFormatters) {
|
|
4101
|
-
if (formatter.match(obj))
|
|
4102
|
-
return ["span", {}, formatter.format(obj)];
|
|
4103
|
-
}
|
|
4104
|
-
}
|
|
4105
|
-
return null;
|
|
4106
|
-
},
|
|
4107
|
-
hasBody: () => true
|
|
4108
|
-
},
|
|
4109
|
-
{
|
|
4110
|
-
// Performance object //
|
|
4111
|
-
// This is a sneaky way to show performance info withouth any extra calls when logging:
|
|
4112
|
-
// LOG(`...`)
|
|
4113
|
-
// it would work without this if we would have some way to intercept the call:
|
|
4114
|
-
// L.INFO('...') - a getter on L that adds the current time as prefix
|
|
4115
|
-
// LOG('...')() - returns the log function with all argumends bound
|
|
4116
|
-
// But instead we are adding a custom formatter that replaced the placeholder object of class P with the performance info
|
|
4117
|
-
header: (obj) => {
|
|
4118
|
-
if (!(obj instanceof LoggerTime))
|
|
4119
|
-
return null;
|
|
4120
|
-
if (!formattersEnabled)
|
|
4121
|
-
formattersEnabled = true;
|
|
4122
|
-
const p = Logger.timeStr(obj.time, obj.delta);
|
|
4123
|
-
return [
|
|
4124
|
-
"span",
|
|
4125
|
-
{ style: "font-weight: light; color: grey" },
|
|
4126
|
-
p?.toString()
|
|
4127
|
-
// ['a', { href: 'vscodium://file/home/manu/dev/tamera/bookr/imports/lib/utils/Logger.js' }, 'WOW'],
|
|
4128
|
-
];
|
|
4129
|
-
},
|
|
4130
|
-
hasBody: () => false
|
|
4131
|
-
},
|
|
4132
|
-
{
|
|
4133
|
-
// Style object
|
|
4134
|
-
header: (obj) => {
|
|
4135
|
-
if (!(obj instanceof Style))
|
|
4136
|
-
return null;
|
|
4137
|
-
if (!formattersEnabled)
|
|
4138
|
-
formattersEnabled = true;
|
|
4139
|
-
return ["span", {
|
|
4140
|
-
style: "font-weight: light; color: grey; "
|
|
4141
|
-
/* font-style: italic; */
|
|
4142
|
-
}, obj.string];
|
|
4143
|
-
},
|
|
4144
|
-
hasBody: () => false
|
|
4145
|
-
}
|
|
4146
|
-
);
|
|
4147
|
-
} else if (import_browser_or_node.isNode) {
|
|
4148
|
-
}
|
|
4149
|
-
|
|
4150
|
-
// ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/block.js
|
|
4151
|
-
function readonly({ enumerable = true, configurable = false } = {}) {
|
|
4152
|
-
return { enumerable, configurable, writable: false };
|
|
4153
|
-
}
|
|
4154
|
-
function* linksWithin(path, value) {
|
|
4155
|
-
if (value != null && typeof value === "object") {
|
|
4156
|
-
if (Array.isArray(value)) {
|
|
4157
|
-
for (const [index, element] of value.entries()) {
|
|
4158
|
-
const elementPath = [...path, index];
|
|
4159
|
-
const cid = CID.asCID(element);
|
|
4160
|
-
if (cid) {
|
|
4161
|
-
yield [elementPath.join("/"), cid];
|
|
4162
|
-
} else if (typeof element === "object") {
|
|
4163
|
-
yield* links(element, elementPath);
|
|
4164
|
-
}
|
|
4165
|
-
}
|
|
4166
|
-
} else {
|
|
4167
|
-
const cid = CID.asCID(value);
|
|
4168
|
-
if (cid) {
|
|
4169
|
-
yield [path.join("/"), cid];
|
|
4170
|
-
} else {
|
|
4171
|
-
yield* links(value, path);
|
|
4172
|
-
}
|
|
4173
|
-
}
|
|
4174
|
-
}
|
|
4175
|
-
}
|
|
4176
|
-
function* links(source, base2) {
|
|
4177
|
-
if (source == null || source instanceof Uint8Array) {
|
|
4178
|
-
return;
|
|
4179
|
-
}
|
|
4180
|
-
const cid = CID.asCID(source);
|
|
4181
|
-
if (cid) {
|
|
4182
|
-
yield [base2.join("/"), cid];
|
|
4183
|
-
}
|
|
4184
|
-
for (const [key, value] of Object.entries(source)) {
|
|
4185
|
-
const path = (
|
|
4186
|
-
/** @type {[string|number, string]} */
|
|
4187
|
-
[...base2, key]
|
|
4188
|
-
);
|
|
4189
|
-
yield* linksWithin(path, value);
|
|
4190
|
-
}
|
|
4191
|
-
}
|
|
4192
|
-
function* treeWithin(path, value) {
|
|
4193
|
-
if (Array.isArray(value)) {
|
|
4194
|
-
for (const [index, element] of value.entries()) {
|
|
4195
|
-
const elementPath = [...path, index];
|
|
4196
|
-
yield elementPath.join("/");
|
|
4197
|
-
if (typeof element === "object" && !CID.asCID(element)) {
|
|
4198
|
-
yield* tree(element, elementPath);
|
|
4199
|
-
}
|
|
4200
|
-
}
|
|
4201
|
-
} else {
|
|
4202
|
-
yield* tree(value, path);
|
|
4203
|
-
}
|
|
4204
|
-
}
|
|
4205
|
-
function* tree(source, base2) {
|
|
4206
|
-
if (source == null || typeof source !== "object") {
|
|
4207
|
-
return;
|
|
4208
|
-
}
|
|
4209
|
-
for (const [key, value] of Object.entries(source)) {
|
|
4210
|
-
const path = (
|
|
4211
|
-
/** @type {[string|number, string]} */
|
|
4212
|
-
[...base2, key]
|
|
4213
|
-
);
|
|
4214
|
-
yield path.join("/");
|
|
4215
|
-
if (value != null && !(value instanceof Uint8Array) && typeof value === "object" && !CID.asCID(value)) {
|
|
4216
|
-
yield* treeWithin(path, value);
|
|
4217
|
-
}
|
|
4218
|
-
}
|
|
4219
|
-
}
|
|
4220
|
-
function get(source, path) {
|
|
4221
|
-
let node = (
|
|
4222
|
-
/** @type {Record<string, any>} */
|
|
4223
|
-
source
|
|
4224
|
-
);
|
|
4225
|
-
for (const [index, key] of path.entries()) {
|
|
4226
|
-
node = node[key];
|
|
4227
|
-
if (node == null) {
|
|
4228
|
-
throw new Error(`Object has no property at ${path.slice(0, index + 1).map((part) => `[${JSON.stringify(part)}]`).join("")}`);
|
|
4229
|
-
}
|
|
4230
|
-
const cid = CID.asCID(node);
|
|
4231
|
-
if (cid) {
|
|
4232
|
-
return { value: cid, remaining: path.slice(index + 1).join("/") };
|
|
4233
|
-
}
|
|
4234
|
-
}
|
|
4235
|
-
return { value: node };
|
|
4236
|
-
}
|
|
4237
|
-
var Block = class {
|
|
4238
|
-
/**
|
|
4239
|
-
* @param {object} options
|
|
4240
|
-
* @param {CID<T, C, A, V>} options.cid
|
|
4241
|
-
* @param {API.ByteView<T>} options.bytes
|
|
4242
|
-
* @param {T} options.value
|
|
4243
|
-
*/
|
|
4244
|
-
constructor({ cid, bytes: bytes2, value }) {
|
|
4245
|
-
if (!cid || !bytes2 || typeof value === "undefined") {
|
|
4246
|
-
throw new Error("Missing required argument");
|
|
4247
|
-
}
|
|
4248
|
-
this.cid = cid;
|
|
4249
|
-
this.bytes = bytes2;
|
|
4250
|
-
this.value = value;
|
|
4251
|
-
this.asBlock = this;
|
|
4252
|
-
Object.defineProperties(this, {
|
|
4253
|
-
cid: readonly(),
|
|
4254
|
-
bytes: readonly(),
|
|
4255
|
-
value: readonly(),
|
|
4256
|
-
asBlock: readonly()
|
|
4257
|
-
});
|
|
4258
|
-
}
|
|
4259
|
-
links() {
|
|
4260
|
-
return links(this.value, []);
|
|
4261
|
-
}
|
|
4262
|
-
tree() {
|
|
4263
|
-
return tree(this.value, []);
|
|
4264
|
-
}
|
|
4265
|
-
/**
|
|
4266
|
-
*
|
|
4267
|
-
* @param {string} [path]
|
|
4268
|
-
* @returns {API.BlockCursorView<unknown>}
|
|
4269
|
-
*/
|
|
4270
|
-
get(path = "/") {
|
|
4271
|
-
return get(this.value, path.split("/").filter(Boolean));
|
|
4272
|
-
}
|
|
4273
|
-
};
|
|
4274
|
-
async function encode6({ value, codec, hasher }) {
|
|
4275
|
-
if (typeof value === "undefined")
|
|
4276
|
-
throw new Error('Missing required argument "value"');
|
|
4277
|
-
if (!codec || !hasher)
|
|
4278
|
-
throw new Error("Missing required argument: codec or hasher");
|
|
4279
|
-
const bytes2 = codec.encode(value);
|
|
4280
|
-
const hash = await hasher.digest(bytes2);
|
|
4281
|
-
const cid = CID.create(
|
|
4282
|
-
1,
|
|
4283
|
-
codec.code,
|
|
4284
|
-
hash
|
|
4285
|
-
);
|
|
4286
|
-
return new Block({ value, bytes: bytes2, cid });
|
|
4287
|
-
}
|
|
4288
|
-
|
|
4289
|
-
// ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/bases/base36.js
|
|
4290
|
-
var base36 = baseX({
|
|
4291
|
-
prefix: "k",
|
|
4292
|
-
name: "base36",
|
|
4293
|
-
alphabet: "0123456789abcdefghijklmnopqrstuvwxyz"
|
|
4294
|
-
});
|
|
4295
|
-
var base36upper = baseX({
|
|
4296
|
-
prefix: "K",
|
|
4297
|
-
name: "base36upper",
|
|
4298
|
-
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
4299
|
-
});
|
|
4300
|
-
|
|
4301
|
-
// ../../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/hashes/sha2-browser.js
|
|
4302
|
-
var sha = (name2) => (
|
|
4303
|
-
/**
|
|
4304
|
-
* @param {Uint8Array} data
|
|
4305
|
-
*/
|
|
4306
|
-
async (data) => new Uint8Array(await crypto.subtle.digest(name2, data))
|
|
4307
|
-
);
|
|
4308
|
-
var sha2562 = from2({
|
|
4309
|
-
name: "sha2-256",
|
|
4310
|
-
code: 18,
|
|
4311
|
-
encode: sha("SHA-256")
|
|
4312
|
-
});
|
|
4313
|
-
var sha512 = from2({
|
|
4314
|
-
name: "sha2-512",
|
|
4315
|
-
code: 19,
|
|
4316
|
-
encode: sha("SHA-512")
|
|
4317
|
-
});
|
|
4318
|
-
|
|
4319
|
-
// src/ipfs/ipfs-utils.ts
|
|
4320
|
-
var { WARN, LOG, DEBUG, VERBOSE, ERROR } = Logger.setup(Logger.INFO);
|
|
4321
|
-
var MULTICODEC_IPNS_KEY = 114;
|
|
4322
|
-
function prepareForPub(log, without = ["cid"]) {
|
|
4323
|
-
const logWithout = {};
|
|
4324
|
-
for (let [key, val] of Object.entries(log)) {
|
|
4325
|
-
if (val === void 0) {
|
|
4326
|
-
WARN(`log.${key} is undefined, which is not allowed - encoding as null`, log);
|
|
4327
|
-
val = null;
|
|
4328
|
-
}
|
|
4329
|
-
if (!without.includes(key)) {
|
|
4330
|
-
logWithout[key] = val && key === "pv" ? CID.parse(val) : val;
|
|
4331
|
-
} else {
|
|
4332
|
-
VERBOSE("excluding app log", { key, val });
|
|
4333
|
-
}
|
|
4334
|
-
}
|
|
4335
|
-
return logWithout;
|
|
4336
|
-
}
|
|
4337
|
-
function encodeApplogAndGetCid(log) {
|
|
4338
|
-
return getCidSync(encodeApplog(log).bytes);
|
|
4339
|
-
}
|
|
4340
|
-
function encodeApplog(log) {
|
|
4341
|
-
return encodeBlock(prepareForPub(log));
|
|
4342
|
-
}
|
|
4343
|
-
function getCidSync(bytes2) {
|
|
4344
|
-
const hash = sha256(bytes2);
|
|
4345
|
-
const digest = digest_exports.create(sha2562.code, hash);
|
|
4346
|
-
const cid = CID.create(1, code, digest);
|
|
4347
|
-
VERBOSE(`[getCidSync]`, { bytes: bytes2, hash, digest, cid });
|
|
4348
|
-
return cid;
|
|
4349
|
-
}
|
|
4350
|
-
function encodeBlock(jsonObject) {
|
|
4351
|
-
DEBUG("[encodeBlock]", jsonObject);
|
|
4352
|
-
const byteView = encode5(jsonObject);
|
|
4353
|
-
return { bytes: byteView, cid: getCidSync(byteView) };
|
|
4354
|
-
}
|
|
4355
|
-
async function encodeBlockOriginal(jsonObject) {
|
|
4356
|
-
const encoded = await encode6({ value: jsonObject, codec: src_exports, hasher: sha2562 });
|
|
4357
|
-
const syncVariant = encodeBlock(jsonObject);
|
|
4358
|
-
if (syncVariant.cid.toString() !== encoded.cid.toString()) {
|
|
4359
|
-
ERROR(`[encodeBlockOriginal] sync cid mismatch`, { jsonObject, encoded, syncVariant });
|
|
4360
|
-
}
|
|
4361
|
-
return encoded;
|
|
4362
|
-
}
|
|
4363
|
-
function tryParseCID(cidString) {
|
|
4364
|
-
let cid = null;
|
|
4365
|
-
let errors = [];
|
|
4366
|
-
try {
|
|
4367
|
-
cid = CID.parse(cidString);
|
|
4368
|
-
} catch (err) {
|
|
4369
|
-
VERBOSE(`[retrieveThread] couldn't parse pubID with default base`);
|
|
4370
|
-
errors.push(err);
|
|
4371
|
-
}
|
|
4372
|
-
if (!cid) {
|
|
4373
|
-
try {
|
|
4374
|
-
cid = CID.parse(cidString, base36);
|
|
4375
|
-
} catch (err) {
|
|
4376
|
-
VERBOSE(`[retrieveThread] couldn't parse pubID with base36`);
|
|
4377
|
-
errors.push(err);
|
|
4378
|
-
}
|
|
4379
|
-
}
|
|
4380
|
-
return {
|
|
4381
|
-
cid,
|
|
4382
|
-
errors,
|
|
4383
|
-
isIpns: cid && cid.code === MULTICODEC_IPNS_KEY
|
|
4384
|
-
};
|
|
4385
|
-
}
|
|
4386
|
-
function toIpnsString(cid) {
|
|
4387
|
-
if (cid.code !== MULTICODEC_IPNS_KEY)
|
|
4388
|
-
throw ERROR(`Not an IPNS cid (${cid.code}):`, cid.toString());
|
|
4389
|
-
return cid.toString(base36);
|
|
4390
|
-
}
|
|
4391
|
-
|
|
4392
|
-
export {
|
|
4393
|
-
Logger,
|
|
4394
|
-
Type,
|
|
4395
|
-
Token,
|
|
4396
|
-
makeCborEncoders,
|
|
4397
|
-
encode,
|
|
4398
|
-
decode,
|
|
4399
|
-
decode6 as decode2,
|
|
4400
|
-
CID,
|
|
4401
|
-
decode7 as decode3,
|
|
4402
|
-
MULTICODEC_IPNS_KEY,
|
|
4403
|
-
prepareForPub,
|
|
4404
|
-
encodeApplogAndGetCid,
|
|
4405
|
-
encodeApplog,
|
|
4406
|
-
getCidSync,
|
|
4407
|
-
encodeBlock,
|
|
4408
|
-
encodeBlockOriginal,
|
|
4409
|
-
tryParseCID,
|
|
4410
|
-
toIpnsString
|
|
4411
|
-
};
|
|
4412
|
-
/*! Bundled license information:
|
|
4413
|
-
|
|
4414
|
-
@noble/hashes/esm/utils.js:
|
|
4415
|
-
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
4416
|
-
*/
|
|
4417
|
-
//# sourceMappingURL=chunk-YBXZNIU2.min.js.map
|