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