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