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