@wovin/core 0.0.9-RC4 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/dist/applog/applog-helpers.d.ts +26 -7
- package/dist/applog/applog-helpers.d.ts.map +1 -1
- package/dist/applog/applog-utils.d.ts +11 -2
- package/dist/applog/applog-utils.d.ts.map +1 -1
- package/dist/applog/datom-types.d.ts +24 -13
- package/dist/applog/datom-types.d.ts.map +1 -1
- package/dist/applog.min.js +11 -3
- package/dist/{chunk-PTGUFZ3Q.min.js → chunk-6EBQRFQC.min.js} +1 -5
- package/dist/{chunk-PTGUFZ3Q.min.js.map → chunk-6EBQRFQC.min.js.map} +1 -1
- package/dist/chunk-C75X52ZX.min.js +2314 -0
- package/dist/chunk-C75X52ZX.min.js.map +1 -0
- package/dist/chunk-DF3UOPRV.min.js +5085 -0
- package/dist/chunk-DF3UOPRV.min.js.map +1 -0
- package/dist/{chunk-XXTV6KVM.min.js → chunk-L4AYAZCN.min.js} +9 -9
- package/dist/chunk-L4AYAZCN.min.js.map +1 -0
- package/dist/chunk-QPGEBDMJ.min.js +9 -0
- package/dist/chunk-QPGEBDMJ.min.js.map +1 -0
- package/dist/chunk-TPRWMCU7.min.js +494 -0
- package/dist/chunk-TPRWMCU7.min.js.map +1 -0
- package/dist/{chunk-V5T5PE7K.min.js → chunk-UQJEOS7T.min.js} +5913 -5688
- package/dist/chunk-UQJEOS7T.min.js.map +1 -0
- package/dist/chunk-UREBOWFC.min.js +40 -0
- package/dist/chunk-UREBOWFC.min.js.map +1 -0
- package/dist/index.min.js +103 -53
- package/dist/ipfs/car.d.ts +47 -7
- package/dist/ipfs/car.d.ts.map +1 -1
- package/dist/ipfs/ipfs-utils.d.ts +18 -7
- package/dist/ipfs/ipfs-utils.d.ts.map +1 -1
- package/dist/ipfs.min.js +24 -6
- package/dist/mobx/mobx-utils.d.ts +23 -17
- package/dist/mobx/mobx-utils.d.ts.map +1 -1
- package/dist/mobx.d.ts +2 -0
- package/dist/mobx.d.ts.map +1 -0
- package/dist/mobx.min.js +141 -0
- package/dist/mobx.min.js.map +1 -0
- package/dist/pubsub/connector.d.ts +3 -1
- package/dist/pubsub/connector.d.ts.map +1 -1
- package/dist/pubsub/pub-pull.d.ts +14 -0
- package/dist/pubsub/pub-pull.d.ts.map +1 -0
- package/dist/pubsub/pub-push.d.ts +41 -0
- package/dist/pubsub/pub-push.d.ts.map +1 -0
- package/dist/pubsub/pubsub-types.d.ts +25 -1
- package/dist/pubsub/pubsub-types.d.ts.map +1 -1
- package/dist/pubsub.d.ts +2 -1
- package/dist/pubsub.d.ts.map +1 -1
- package/dist/pubsub.min.js +20 -13
- package/dist/query/basic.d.ts +40 -8
- package/dist/query/basic.d.ts.map +1 -1
- package/dist/query/divergences.d.ts.map +1 -1
- package/dist/query/types.d.ts +3 -3
- package/dist/query/types.d.ts.map +1 -1
- package/dist/query.min.js +34 -16
- package/dist/thread/basic.d.ts +24 -4
- package/dist/thread/basic.d.ts.map +1 -1
- package/dist/thread/filters.d.ts +2 -2
- package/dist/thread/filters.d.ts.map +1 -1
- package/dist/thread/mapped.d.ts +10 -3
- package/dist/thread/mapped.d.ts.map +1 -1
- package/dist/thread/utils.d.ts +16 -0
- package/dist/thread/utils.d.ts.map +1 -0
- package/dist/thread/writeable.d.ts +4 -3
- package/dist/thread/writeable.d.ts.map +1 -1
- package/dist/thread.d.ts +1 -0
- package/dist/thread.d.ts.map +1 -1
- package/dist/thread.min.js +13 -3
- package/dist/types/typescript-utils.d.ts +5 -4
- package/dist/types/typescript-utils.d.ts.map +1 -1
- package/dist/types.min.js +1 -5
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.min.js +9 -0
- package/package.json +17 -11
- package/dist/chunk-CIOF7QHW.min.js +0 -135
- package/dist/chunk-CIOF7QHW.min.js.map +0 -1
- package/dist/chunk-V5T5PE7K.min.js.map +0 -1
- package/dist/chunk-VM46JSEH.min.js +0 -1426
- package/dist/chunk-VM46JSEH.min.js.map +0 -1
- package/dist/chunk-XXTV6KVM.min.js.map +0 -1
- package/dist/chunk-YBXZNIU2.min.js +0 -4417
- package/dist/chunk-YBXZNIU2.min.js.map +0 -1
- package/dist/pubsub/publication.d.ts +0 -17
- package/dist/pubsub/publication.d.ts.map +0 -1
|
@@ -0,0 +1,2314 @@
|
|
|
1
|
+
import {
|
|
2
|
+
keepTruthy
|
|
3
|
+
} from "./chunk-QPGEBDMJ.min.js";
|
|
4
|
+
import {
|
|
5
|
+
lastWriteWins
|
|
6
|
+
} from "./chunk-TPRWMCU7.min.js";
|
|
7
|
+
import {
|
|
8
|
+
CID,
|
|
9
|
+
E,
|
|
10
|
+
Token,
|
|
11
|
+
Type,
|
|
12
|
+
areCidsEqual,
|
|
13
|
+
containsCid,
|
|
14
|
+
decode,
|
|
15
|
+
decode2,
|
|
16
|
+
decode3,
|
|
17
|
+
encode,
|
|
18
|
+
encodeBlockOriginal,
|
|
19
|
+
ensureTsPvAndFinalizeApplog,
|
|
20
|
+
getLogsFromThread,
|
|
21
|
+
makeCborEncoders,
|
|
22
|
+
prepareForPub,
|
|
23
|
+
rollingFilter,
|
|
24
|
+
src_exports,
|
|
25
|
+
wrapper_default
|
|
26
|
+
} from "./chunk-UQJEOS7T.min.js";
|
|
27
|
+
import {
|
|
28
|
+
__commonJS,
|
|
29
|
+
__toESM
|
|
30
|
+
} from "./chunk-KRQZ6V4Y.min.js";
|
|
31
|
+
|
|
32
|
+
// ../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/encode.js
|
|
33
|
+
var require_encode = __commonJS({
|
|
34
|
+
"../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/encode.js"(exports, module) {
|
|
35
|
+
"use strict";
|
|
36
|
+
module.exports = encode5;
|
|
37
|
+
var MSB2 = 128;
|
|
38
|
+
var REST2 = 127;
|
|
39
|
+
var MSBALL2 = ~REST2;
|
|
40
|
+
var INT2 = Math.pow(2, 31);
|
|
41
|
+
function encode5(num, out, offset) {
|
|
42
|
+
if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) {
|
|
43
|
+
encode5.bytes = 0;
|
|
44
|
+
throw new RangeError("Could not encode varint");
|
|
45
|
+
}
|
|
46
|
+
out = out || [];
|
|
47
|
+
offset = offset || 0;
|
|
48
|
+
var oldOffset = offset;
|
|
49
|
+
while (num >= INT2) {
|
|
50
|
+
out[offset++] = num & 255 | MSB2;
|
|
51
|
+
num /= 128;
|
|
52
|
+
}
|
|
53
|
+
while (num & MSBALL2) {
|
|
54
|
+
out[offset++] = num & 255 | MSB2;
|
|
55
|
+
num >>>= 7;
|
|
56
|
+
}
|
|
57
|
+
out[offset] = num | 0;
|
|
58
|
+
encode5.bytes = offset - oldOffset + 1;
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// ../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/decode.js
|
|
65
|
+
var require_decode = __commonJS({
|
|
66
|
+
"../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/decode.js"(exports, module) {
|
|
67
|
+
"use strict";
|
|
68
|
+
module.exports = read2;
|
|
69
|
+
var MSB2 = 128;
|
|
70
|
+
var REST2 = 127;
|
|
71
|
+
function read2(buf, offset) {
|
|
72
|
+
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
|
|
73
|
+
do {
|
|
74
|
+
if (counter >= l || shift > 49) {
|
|
75
|
+
read2.bytes = 0;
|
|
76
|
+
throw new RangeError("Could not decode varint");
|
|
77
|
+
}
|
|
78
|
+
b = buf[counter++];
|
|
79
|
+
res += shift < 28 ? (b & REST2) << shift : (b & REST2) * Math.pow(2, shift);
|
|
80
|
+
shift += 7;
|
|
81
|
+
} while (b >= MSB2);
|
|
82
|
+
read2.bytes = counter - offset;
|
|
83
|
+
return res;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// ../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/length.js
|
|
89
|
+
var require_length = __commonJS({
|
|
90
|
+
"../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/length.js"(exports, module) {
|
|
91
|
+
"use strict";
|
|
92
|
+
var N12 = Math.pow(2, 7);
|
|
93
|
+
var N22 = Math.pow(2, 14);
|
|
94
|
+
var N32 = Math.pow(2, 21);
|
|
95
|
+
var N42 = Math.pow(2, 28);
|
|
96
|
+
var N52 = Math.pow(2, 35);
|
|
97
|
+
var N62 = Math.pow(2, 42);
|
|
98
|
+
var N72 = Math.pow(2, 49);
|
|
99
|
+
var N82 = Math.pow(2, 56);
|
|
100
|
+
var N92 = Math.pow(2, 63);
|
|
101
|
+
module.exports = function(value) {
|
|
102
|
+
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;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// ../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/index.js
|
|
108
|
+
var require_varint = __commonJS({
|
|
109
|
+
"../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/index.js"(exports, module) {
|
|
110
|
+
"use strict";
|
|
111
|
+
module.exports = {
|
|
112
|
+
encode: require_encode(),
|
|
113
|
+
decode: require_decode(),
|
|
114
|
+
encodingLength: require_length()
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// ../../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/bytes.js
|
|
120
|
+
var empty = new Uint8Array(0);
|
|
121
|
+
function equals(aa, bb) {
|
|
122
|
+
if (aa === bb)
|
|
123
|
+
return true;
|
|
124
|
+
if (aa.byteLength !== bb.byteLength) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
for (let ii = 0; ii < aa.byteLength; ii++) {
|
|
128
|
+
if (aa[ii] !== bb[ii]) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
function coerce(o) {
|
|
135
|
+
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array")
|
|
136
|
+
return o;
|
|
137
|
+
if (o instanceof ArrayBuffer)
|
|
138
|
+
return new Uint8Array(o);
|
|
139
|
+
if (ArrayBuffer.isView(o)) {
|
|
140
|
+
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
141
|
+
}
|
|
142
|
+
throw new Error("Unknown type, must be binary type");
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ../../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/vendor/base-x.js
|
|
146
|
+
function base(ALPHABET, name) {
|
|
147
|
+
if (ALPHABET.length >= 255) {
|
|
148
|
+
throw new TypeError("Alphabet too long");
|
|
149
|
+
}
|
|
150
|
+
var BASE_MAP = new Uint8Array(256);
|
|
151
|
+
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
152
|
+
BASE_MAP[j] = 255;
|
|
153
|
+
}
|
|
154
|
+
for (var i = 0; i < ALPHABET.length; i++) {
|
|
155
|
+
var x = ALPHABET.charAt(i);
|
|
156
|
+
var xc = x.charCodeAt(0);
|
|
157
|
+
if (BASE_MAP[xc] !== 255) {
|
|
158
|
+
throw new TypeError(x + " is ambiguous");
|
|
159
|
+
}
|
|
160
|
+
BASE_MAP[xc] = i;
|
|
161
|
+
}
|
|
162
|
+
var BASE = ALPHABET.length;
|
|
163
|
+
var LEADER = ALPHABET.charAt(0);
|
|
164
|
+
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
165
|
+
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
166
|
+
function encode5(source) {
|
|
167
|
+
if (source instanceof Uint8Array)
|
|
168
|
+
;
|
|
169
|
+
else if (ArrayBuffer.isView(source)) {
|
|
170
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
171
|
+
} else if (Array.isArray(source)) {
|
|
172
|
+
source = Uint8Array.from(source);
|
|
173
|
+
}
|
|
174
|
+
if (!(source instanceof Uint8Array)) {
|
|
175
|
+
throw new TypeError("Expected Uint8Array");
|
|
176
|
+
}
|
|
177
|
+
if (source.length === 0) {
|
|
178
|
+
return "";
|
|
179
|
+
}
|
|
180
|
+
var zeroes = 0;
|
|
181
|
+
var length2 = 0;
|
|
182
|
+
var pbegin = 0;
|
|
183
|
+
var pend = source.length;
|
|
184
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
185
|
+
pbegin++;
|
|
186
|
+
zeroes++;
|
|
187
|
+
}
|
|
188
|
+
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
189
|
+
var b58 = new Uint8Array(size);
|
|
190
|
+
while (pbegin !== pend) {
|
|
191
|
+
var carry = source[pbegin];
|
|
192
|
+
var i2 = 0;
|
|
193
|
+
for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
|
|
194
|
+
carry += 256 * b58[it1] >>> 0;
|
|
195
|
+
b58[it1] = carry % BASE >>> 0;
|
|
196
|
+
carry = carry / BASE >>> 0;
|
|
197
|
+
}
|
|
198
|
+
if (carry !== 0) {
|
|
199
|
+
throw new Error("Non-zero carry");
|
|
200
|
+
}
|
|
201
|
+
length2 = i2;
|
|
202
|
+
pbegin++;
|
|
203
|
+
}
|
|
204
|
+
var it2 = size - length2;
|
|
205
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
206
|
+
it2++;
|
|
207
|
+
}
|
|
208
|
+
var str = LEADER.repeat(zeroes);
|
|
209
|
+
for (; it2 < size; ++it2) {
|
|
210
|
+
str += ALPHABET.charAt(b58[it2]);
|
|
211
|
+
}
|
|
212
|
+
return str;
|
|
213
|
+
}
|
|
214
|
+
function decodeUnsafe(source) {
|
|
215
|
+
if (typeof source !== "string") {
|
|
216
|
+
throw new TypeError("Expected String");
|
|
217
|
+
}
|
|
218
|
+
if (source.length === 0) {
|
|
219
|
+
return new Uint8Array();
|
|
220
|
+
}
|
|
221
|
+
var psz = 0;
|
|
222
|
+
if (source[psz] === " ") {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
var zeroes = 0;
|
|
226
|
+
var length2 = 0;
|
|
227
|
+
while (source[psz] === LEADER) {
|
|
228
|
+
zeroes++;
|
|
229
|
+
psz++;
|
|
230
|
+
}
|
|
231
|
+
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
232
|
+
var b256 = new Uint8Array(size);
|
|
233
|
+
while (source[psz]) {
|
|
234
|
+
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
235
|
+
if (carry === 255) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
var i2 = 0;
|
|
239
|
+
for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
|
|
240
|
+
carry += BASE * b256[it3] >>> 0;
|
|
241
|
+
b256[it3] = carry % 256 >>> 0;
|
|
242
|
+
carry = carry / 256 >>> 0;
|
|
243
|
+
}
|
|
244
|
+
if (carry !== 0) {
|
|
245
|
+
throw new Error("Non-zero carry");
|
|
246
|
+
}
|
|
247
|
+
length2 = i2;
|
|
248
|
+
psz++;
|
|
249
|
+
}
|
|
250
|
+
if (source[psz] === " ") {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
var it4 = size - length2;
|
|
254
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
255
|
+
it4++;
|
|
256
|
+
}
|
|
257
|
+
var vch = new Uint8Array(zeroes + (size - it4));
|
|
258
|
+
var j2 = zeroes;
|
|
259
|
+
while (it4 !== size) {
|
|
260
|
+
vch[j2++] = b256[it4++];
|
|
261
|
+
}
|
|
262
|
+
return vch;
|
|
263
|
+
}
|
|
264
|
+
function decode9(string) {
|
|
265
|
+
var buffer = decodeUnsafe(string);
|
|
266
|
+
if (buffer) {
|
|
267
|
+
return buffer;
|
|
268
|
+
}
|
|
269
|
+
throw new Error(`Non-${name} character`);
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
encode: encode5,
|
|
273
|
+
decodeUnsafe,
|
|
274
|
+
decode: decode9
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
var src = base;
|
|
278
|
+
var _brrp__multiformats_scope_baseX = src;
|
|
279
|
+
var base_x_default = _brrp__multiformats_scope_baseX;
|
|
280
|
+
|
|
281
|
+
// ../../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/bases/base.js
|
|
282
|
+
var Encoder = class {
|
|
283
|
+
name;
|
|
284
|
+
prefix;
|
|
285
|
+
baseEncode;
|
|
286
|
+
constructor(name, prefix, baseEncode) {
|
|
287
|
+
this.name = name;
|
|
288
|
+
this.prefix = prefix;
|
|
289
|
+
this.baseEncode = baseEncode;
|
|
290
|
+
}
|
|
291
|
+
encode(bytes) {
|
|
292
|
+
if (bytes instanceof Uint8Array) {
|
|
293
|
+
return `${this.prefix}${this.baseEncode(bytes)}`;
|
|
294
|
+
} else {
|
|
295
|
+
throw Error("Unknown type, must be binary type");
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
var Decoder = class {
|
|
300
|
+
name;
|
|
301
|
+
prefix;
|
|
302
|
+
baseDecode;
|
|
303
|
+
prefixCodePoint;
|
|
304
|
+
constructor(name, prefix, baseDecode) {
|
|
305
|
+
this.name = name;
|
|
306
|
+
this.prefix = prefix;
|
|
307
|
+
const prefixCodePoint = prefix.codePointAt(0);
|
|
308
|
+
if (prefixCodePoint === void 0) {
|
|
309
|
+
throw new Error("Invalid prefix character");
|
|
310
|
+
}
|
|
311
|
+
this.prefixCodePoint = prefixCodePoint;
|
|
312
|
+
this.baseDecode = baseDecode;
|
|
313
|
+
}
|
|
314
|
+
decode(text) {
|
|
315
|
+
if (typeof text === "string") {
|
|
316
|
+
if (text.codePointAt(0) !== this.prefixCodePoint) {
|
|
317
|
+
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
|
|
318
|
+
}
|
|
319
|
+
return this.baseDecode(text.slice(this.prefix.length));
|
|
320
|
+
} else {
|
|
321
|
+
throw Error("Can only multibase decode strings");
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
or(decoder) {
|
|
325
|
+
return or(this, decoder);
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
var ComposedDecoder = class {
|
|
329
|
+
decoders;
|
|
330
|
+
constructor(decoders) {
|
|
331
|
+
this.decoders = decoders;
|
|
332
|
+
}
|
|
333
|
+
or(decoder) {
|
|
334
|
+
return or(this, decoder);
|
|
335
|
+
}
|
|
336
|
+
decode(input) {
|
|
337
|
+
const prefix = input[0];
|
|
338
|
+
const decoder = this.decoders[prefix];
|
|
339
|
+
if (decoder != null) {
|
|
340
|
+
return decoder.decode(input);
|
|
341
|
+
} else {
|
|
342
|
+
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
function or(left, right) {
|
|
347
|
+
return new ComposedDecoder({
|
|
348
|
+
...left.decoders ?? { [left.prefix]: left },
|
|
349
|
+
...right.decoders ?? { [right.prefix]: right }
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
var Codec = class {
|
|
353
|
+
name;
|
|
354
|
+
prefix;
|
|
355
|
+
baseEncode;
|
|
356
|
+
baseDecode;
|
|
357
|
+
encoder;
|
|
358
|
+
decoder;
|
|
359
|
+
constructor(name, prefix, baseEncode, baseDecode) {
|
|
360
|
+
this.name = name;
|
|
361
|
+
this.prefix = prefix;
|
|
362
|
+
this.baseEncode = baseEncode;
|
|
363
|
+
this.baseDecode = baseDecode;
|
|
364
|
+
this.encoder = new Encoder(name, prefix, baseEncode);
|
|
365
|
+
this.decoder = new Decoder(name, prefix, baseDecode);
|
|
366
|
+
}
|
|
367
|
+
encode(input) {
|
|
368
|
+
return this.encoder.encode(input);
|
|
369
|
+
}
|
|
370
|
+
decode(input) {
|
|
371
|
+
return this.decoder.decode(input);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
function from({ name, prefix, encode: encode5, decode: decode9 }) {
|
|
375
|
+
return new Codec(name, prefix, encode5, decode9);
|
|
376
|
+
}
|
|
377
|
+
function baseX({ name, prefix, alphabet }) {
|
|
378
|
+
const { encode: encode5, decode: decode9 } = base_x_default(alphabet, name);
|
|
379
|
+
return from({
|
|
380
|
+
prefix,
|
|
381
|
+
name,
|
|
382
|
+
encode: encode5,
|
|
383
|
+
decode: (text) => coerce(decode9(text))
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
function decode4(string, alphabet, bitsPerChar, name) {
|
|
387
|
+
const codes = {};
|
|
388
|
+
for (let i = 0; i < alphabet.length; ++i) {
|
|
389
|
+
codes[alphabet[i]] = i;
|
|
390
|
+
}
|
|
391
|
+
let end = string.length;
|
|
392
|
+
while (string[end - 1] === "=") {
|
|
393
|
+
--end;
|
|
394
|
+
}
|
|
395
|
+
const out = new Uint8Array(end * bitsPerChar / 8 | 0);
|
|
396
|
+
let bits = 0;
|
|
397
|
+
let buffer = 0;
|
|
398
|
+
let written = 0;
|
|
399
|
+
for (let i = 0; i < end; ++i) {
|
|
400
|
+
const value = codes[string[i]];
|
|
401
|
+
if (value === void 0) {
|
|
402
|
+
throw new SyntaxError(`Non-${name} character`);
|
|
403
|
+
}
|
|
404
|
+
buffer = buffer << bitsPerChar | value;
|
|
405
|
+
bits += bitsPerChar;
|
|
406
|
+
if (bits >= 8) {
|
|
407
|
+
bits -= 8;
|
|
408
|
+
out[written++] = 255 & buffer >> bits;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (bits >= bitsPerChar || (255 & buffer << 8 - bits) !== 0) {
|
|
412
|
+
throw new SyntaxError("Unexpected end of data");
|
|
413
|
+
}
|
|
414
|
+
return out;
|
|
415
|
+
}
|
|
416
|
+
function encode2(data, alphabet, bitsPerChar) {
|
|
417
|
+
const pad = alphabet[alphabet.length - 1] === "=";
|
|
418
|
+
const mask = (1 << bitsPerChar) - 1;
|
|
419
|
+
let out = "";
|
|
420
|
+
let bits = 0;
|
|
421
|
+
let buffer = 0;
|
|
422
|
+
for (let i = 0; i < data.length; ++i) {
|
|
423
|
+
buffer = buffer << 8 | data[i];
|
|
424
|
+
bits += 8;
|
|
425
|
+
while (bits > bitsPerChar) {
|
|
426
|
+
bits -= bitsPerChar;
|
|
427
|
+
out += alphabet[mask & buffer >> bits];
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (bits !== 0) {
|
|
431
|
+
out += alphabet[mask & buffer << bitsPerChar - bits];
|
|
432
|
+
}
|
|
433
|
+
if (pad) {
|
|
434
|
+
while ((out.length * bitsPerChar & 7) !== 0) {
|
|
435
|
+
out += "=";
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return out;
|
|
439
|
+
}
|
|
440
|
+
function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
|
|
441
|
+
return from({
|
|
442
|
+
prefix,
|
|
443
|
+
name,
|
|
444
|
+
encode(input) {
|
|
445
|
+
return encode2(input, alphabet, bitsPerChar);
|
|
446
|
+
},
|
|
447
|
+
decode(input) {
|
|
448
|
+
return decode4(input, alphabet, bitsPerChar, name);
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// ../../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/bases/base32.js
|
|
454
|
+
var base32 = rfc4648({
|
|
455
|
+
prefix: "b",
|
|
456
|
+
name: "base32",
|
|
457
|
+
alphabet: "abcdefghijklmnopqrstuvwxyz234567",
|
|
458
|
+
bitsPerChar: 5
|
|
459
|
+
});
|
|
460
|
+
var base32upper = rfc4648({
|
|
461
|
+
prefix: "B",
|
|
462
|
+
name: "base32upper",
|
|
463
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
|
464
|
+
bitsPerChar: 5
|
|
465
|
+
});
|
|
466
|
+
var base32pad = rfc4648({
|
|
467
|
+
prefix: "c",
|
|
468
|
+
name: "base32pad",
|
|
469
|
+
alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
|
|
470
|
+
bitsPerChar: 5
|
|
471
|
+
});
|
|
472
|
+
var base32padupper = rfc4648({
|
|
473
|
+
prefix: "C",
|
|
474
|
+
name: "base32padupper",
|
|
475
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
|
|
476
|
+
bitsPerChar: 5
|
|
477
|
+
});
|
|
478
|
+
var base32hex = rfc4648({
|
|
479
|
+
prefix: "v",
|
|
480
|
+
name: "base32hex",
|
|
481
|
+
alphabet: "0123456789abcdefghijklmnopqrstuv",
|
|
482
|
+
bitsPerChar: 5
|
|
483
|
+
});
|
|
484
|
+
var base32hexupper = rfc4648({
|
|
485
|
+
prefix: "V",
|
|
486
|
+
name: "base32hexupper",
|
|
487
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
|
|
488
|
+
bitsPerChar: 5
|
|
489
|
+
});
|
|
490
|
+
var base32hexpad = rfc4648({
|
|
491
|
+
prefix: "t",
|
|
492
|
+
name: "base32hexpad",
|
|
493
|
+
alphabet: "0123456789abcdefghijklmnopqrstuv=",
|
|
494
|
+
bitsPerChar: 5
|
|
495
|
+
});
|
|
496
|
+
var base32hexpadupper = rfc4648({
|
|
497
|
+
prefix: "T",
|
|
498
|
+
name: "base32hexpadupper",
|
|
499
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
|
|
500
|
+
bitsPerChar: 5
|
|
501
|
+
});
|
|
502
|
+
var base32z = rfc4648({
|
|
503
|
+
prefix: "h",
|
|
504
|
+
name: "base32z",
|
|
505
|
+
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
|
|
506
|
+
bitsPerChar: 5
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
// ../../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/bases/base36.js
|
|
510
|
+
var base36 = baseX({
|
|
511
|
+
prefix: "k",
|
|
512
|
+
name: "base36",
|
|
513
|
+
alphabet: "0123456789abcdefghijklmnopqrstuvwxyz"
|
|
514
|
+
});
|
|
515
|
+
var base36upper = baseX({
|
|
516
|
+
prefix: "K",
|
|
517
|
+
name: "base36upper",
|
|
518
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
// ../../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/bases/base58.js
|
|
522
|
+
var base58btc = baseX({
|
|
523
|
+
name: "base58btc",
|
|
524
|
+
prefix: "z",
|
|
525
|
+
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
526
|
+
});
|
|
527
|
+
var base58flickr = baseX({
|
|
528
|
+
name: "base58flickr",
|
|
529
|
+
prefix: "Z",
|
|
530
|
+
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
// ../../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/vendor/varint.js
|
|
534
|
+
var encode_1 = encode3;
|
|
535
|
+
var MSB = 128;
|
|
536
|
+
var REST = 127;
|
|
537
|
+
var MSBALL = ~REST;
|
|
538
|
+
var INT = Math.pow(2, 31);
|
|
539
|
+
function encode3(num, out, offset) {
|
|
540
|
+
out = out || [];
|
|
541
|
+
offset = offset || 0;
|
|
542
|
+
var oldOffset = offset;
|
|
543
|
+
while (num >= INT) {
|
|
544
|
+
out[offset++] = num & 255 | MSB;
|
|
545
|
+
num /= 128;
|
|
546
|
+
}
|
|
547
|
+
while (num & MSBALL) {
|
|
548
|
+
out[offset++] = num & 255 | MSB;
|
|
549
|
+
num >>>= 7;
|
|
550
|
+
}
|
|
551
|
+
out[offset] = num | 0;
|
|
552
|
+
encode3.bytes = offset - oldOffset + 1;
|
|
553
|
+
return out;
|
|
554
|
+
}
|
|
555
|
+
var decode5 = read;
|
|
556
|
+
var MSB$1 = 128;
|
|
557
|
+
var REST$1 = 127;
|
|
558
|
+
function read(buf, offset) {
|
|
559
|
+
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
|
|
560
|
+
do {
|
|
561
|
+
if (counter >= l) {
|
|
562
|
+
read.bytes = 0;
|
|
563
|
+
throw new RangeError("Could not decode varint");
|
|
564
|
+
}
|
|
565
|
+
b = buf[counter++];
|
|
566
|
+
res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
|
|
567
|
+
shift += 7;
|
|
568
|
+
} while (b >= MSB$1);
|
|
569
|
+
read.bytes = counter - offset;
|
|
570
|
+
return res;
|
|
571
|
+
}
|
|
572
|
+
var N1 = Math.pow(2, 7);
|
|
573
|
+
var N2 = Math.pow(2, 14);
|
|
574
|
+
var N3 = Math.pow(2, 21);
|
|
575
|
+
var N4 = Math.pow(2, 28);
|
|
576
|
+
var N5 = Math.pow(2, 35);
|
|
577
|
+
var N6 = Math.pow(2, 42);
|
|
578
|
+
var N7 = Math.pow(2, 49);
|
|
579
|
+
var N8 = Math.pow(2, 56);
|
|
580
|
+
var N9 = Math.pow(2, 63);
|
|
581
|
+
var length = function(value) {
|
|
582
|
+
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;
|
|
583
|
+
};
|
|
584
|
+
var varint = {
|
|
585
|
+
encode: encode_1,
|
|
586
|
+
decode: decode5,
|
|
587
|
+
encodingLength: length
|
|
588
|
+
};
|
|
589
|
+
var _brrp_varint = varint;
|
|
590
|
+
var varint_default = _brrp_varint;
|
|
591
|
+
|
|
592
|
+
// ../../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/varint.js
|
|
593
|
+
function decode6(data, offset = 0) {
|
|
594
|
+
const code = varint_default.decode(data, offset);
|
|
595
|
+
return [code, varint_default.decode.bytes];
|
|
596
|
+
}
|
|
597
|
+
function encodeTo(int, target, offset = 0) {
|
|
598
|
+
varint_default.encode(int, target, offset);
|
|
599
|
+
return target;
|
|
600
|
+
}
|
|
601
|
+
function encodingLength(int) {
|
|
602
|
+
return varint_default.encodingLength(int);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// ../../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/hashes/digest.js
|
|
606
|
+
function create(code, digest) {
|
|
607
|
+
const size = digest.byteLength;
|
|
608
|
+
const sizeOffset = encodingLength(code);
|
|
609
|
+
const digestOffset = sizeOffset + encodingLength(size);
|
|
610
|
+
const bytes = new Uint8Array(digestOffset + size);
|
|
611
|
+
encodeTo(code, bytes, 0);
|
|
612
|
+
encodeTo(size, bytes, sizeOffset);
|
|
613
|
+
bytes.set(digest, digestOffset);
|
|
614
|
+
return new Digest(code, size, digest, bytes);
|
|
615
|
+
}
|
|
616
|
+
function decode7(multihash) {
|
|
617
|
+
const bytes = coerce(multihash);
|
|
618
|
+
const [code, sizeOffset] = decode6(bytes);
|
|
619
|
+
const [size, digestOffset] = decode6(bytes.subarray(sizeOffset));
|
|
620
|
+
const digest = bytes.subarray(sizeOffset + digestOffset);
|
|
621
|
+
if (digest.byteLength !== size) {
|
|
622
|
+
throw new Error("Incorrect length");
|
|
623
|
+
}
|
|
624
|
+
return new Digest(code, size, digest, bytes);
|
|
625
|
+
}
|
|
626
|
+
function equals2(a, b) {
|
|
627
|
+
if (a === b) {
|
|
628
|
+
return true;
|
|
629
|
+
} else {
|
|
630
|
+
const data = b;
|
|
631
|
+
return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
var Digest = class {
|
|
635
|
+
code;
|
|
636
|
+
size;
|
|
637
|
+
digest;
|
|
638
|
+
bytes;
|
|
639
|
+
/**
|
|
640
|
+
* Creates a multihash digest.
|
|
641
|
+
*/
|
|
642
|
+
constructor(code, size, digest, bytes) {
|
|
643
|
+
this.code = code;
|
|
644
|
+
this.size = size;
|
|
645
|
+
this.digest = digest;
|
|
646
|
+
this.bytes = bytes;
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
|
|
650
|
+
// ../../../node_modules/.pnpm/multiformats@13.3.1/node_modules/multiformats/dist/src/cid.js
|
|
651
|
+
function format(link, base2) {
|
|
652
|
+
const { bytes, version } = link;
|
|
653
|
+
switch (version) {
|
|
654
|
+
case 0:
|
|
655
|
+
return toStringV0(bytes, baseCache(link), base2 ?? base58btc.encoder);
|
|
656
|
+
default:
|
|
657
|
+
return toStringV1(bytes, baseCache(link), base2 ?? base32.encoder);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
661
|
+
function baseCache(cid) {
|
|
662
|
+
const baseCache2 = cache.get(cid);
|
|
663
|
+
if (baseCache2 == null) {
|
|
664
|
+
const baseCache3 = /* @__PURE__ */ new Map();
|
|
665
|
+
cache.set(cid, baseCache3);
|
|
666
|
+
return baseCache3;
|
|
667
|
+
}
|
|
668
|
+
return baseCache2;
|
|
669
|
+
}
|
|
670
|
+
var CID2 = class _CID {
|
|
671
|
+
code;
|
|
672
|
+
version;
|
|
673
|
+
multihash;
|
|
674
|
+
bytes;
|
|
675
|
+
"/";
|
|
676
|
+
/**
|
|
677
|
+
* @param version - Version of the CID
|
|
678
|
+
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
679
|
+
* @param multihash - (Multi)hash of the of the content.
|
|
680
|
+
*/
|
|
681
|
+
constructor(version, code, multihash, bytes) {
|
|
682
|
+
this.code = code;
|
|
683
|
+
this.version = version;
|
|
684
|
+
this.multihash = multihash;
|
|
685
|
+
this.bytes = bytes;
|
|
686
|
+
this["/"] = bytes;
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
|
|
690
|
+
* please either use `CID.asCID(cid)` or switch to new signalling mechanism
|
|
691
|
+
*
|
|
692
|
+
* @deprecated
|
|
693
|
+
*/
|
|
694
|
+
get asCID() {
|
|
695
|
+
return this;
|
|
696
|
+
}
|
|
697
|
+
// ArrayBufferView
|
|
698
|
+
get byteOffset() {
|
|
699
|
+
return this.bytes.byteOffset;
|
|
700
|
+
}
|
|
701
|
+
// ArrayBufferView
|
|
702
|
+
get byteLength() {
|
|
703
|
+
return this.bytes.byteLength;
|
|
704
|
+
}
|
|
705
|
+
toV0() {
|
|
706
|
+
switch (this.version) {
|
|
707
|
+
case 0: {
|
|
708
|
+
return this;
|
|
709
|
+
}
|
|
710
|
+
case 1: {
|
|
711
|
+
const { code, multihash } = this;
|
|
712
|
+
if (code !== DAG_PB_CODE) {
|
|
713
|
+
throw new Error("Cannot convert a non dag-pb CID to CIDv0");
|
|
714
|
+
}
|
|
715
|
+
if (multihash.code !== SHA_256_CODE) {
|
|
716
|
+
throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
|
|
717
|
+
}
|
|
718
|
+
return _CID.createV0(multihash);
|
|
719
|
+
}
|
|
720
|
+
default: {
|
|
721
|
+
throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
toV1() {
|
|
726
|
+
switch (this.version) {
|
|
727
|
+
case 0: {
|
|
728
|
+
const { code, digest } = this.multihash;
|
|
729
|
+
const multihash = create(code, digest);
|
|
730
|
+
return _CID.createV1(this.code, multihash);
|
|
731
|
+
}
|
|
732
|
+
case 1: {
|
|
733
|
+
return this;
|
|
734
|
+
}
|
|
735
|
+
default: {
|
|
736
|
+
throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
equals(other) {
|
|
741
|
+
return _CID.equals(this, other);
|
|
742
|
+
}
|
|
743
|
+
static equals(self, other) {
|
|
744
|
+
const unknown = other;
|
|
745
|
+
return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
|
|
746
|
+
}
|
|
747
|
+
toString(base2) {
|
|
748
|
+
return format(this, base2);
|
|
749
|
+
}
|
|
750
|
+
toJSON() {
|
|
751
|
+
return { "/": format(this) };
|
|
752
|
+
}
|
|
753
|
+
link() {
|
|
754
|
+
return this;
|
|
755
|
+
}
|
|
756
|
+
[Symbol.toStringTag] = "CID";
|
|
757
|
+
// Legacy
|
|
758
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
759
|
+
return `CID(${this.toString()})`;
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Takes any input `value` and returns a `CID` instance if it was
|
|
763
|
+
* a `CID` otherwise returns `null`. If `value` is instanceof `CID`
|
|
764
|
+
* it will return value back. If `value` is not instance of this CID
|
|
765
|
+
* class, but is compatible CID it will return new instance of this
|
|
766
|
+
* `CID` class. Otherwise returns null.
|
|
767
|
+
*
|
|
768
|
+
* This allows two different incompatible versions of CID library to
|
|
769
|
+
* co-exist and interop as long as binary interface is compatible.
|
|
770
|
+
*/
|
|
771
|
+
static asCID(input) {
|
|
772
|
+
if (input == null) {
|
|
773
|
+
return null;
|
|
774
|
+
}
|
|
775
|
+
const value = input;
|
|
776
|
+
if (value instanceof _CID) {
|
|
777
|
+
return value;
|
|
778
|
+
} else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
|
|
779
|
+
const { version, code, multihash, bytes } = value;
|
|
780
|
+
return new _CID(version, code, multihash, bytes ?? encodeCID(version, code, multihash.bytes));
|
|
781
|
+
} else if (value[cidSymbol] === true) {
|
|
782
|
+
const { version, multihash, code } = value;
|
|
783
|
+
const digest = decode7(multihash);
|
|
784
|
+
return _CID.create(version, code, digest);
|
|
785
|
+
} else {
|
|
786
|
+
return null;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* @param version - Version of the CID
|
|
791
|
+
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
792
|
+
* @param digest - (Multi)hash of the of the content.
|
|
793
|
+
*/
|
|
794
|
+
static create(version, code, digest) {
|
|
795
|
+
if (typeof code !== "number") {
|
|
796
|
+
throw new Error("String codecs are no longer supported");
|
|
797
|
+
}
|
|
798
|
+
if (!(digest.bytes instanceof Uint8Array)) {
|
|
799
|
+
throw new Error("Invalid digest");
|
|
800
|
+
}
|
|
801
|
+
switch (version) {
|
|
802
|
+
case 0: {
|
|
803
|
+
if (code !== DAG_PB_CODE) {
|
|
804
|
+
throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
|
|
805
|
+
} else {
|
|
806
|
+
return new _CID(version, code, digest, digest.bytes);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
case 1: {
|
|
810
|
+
const bytes = encodeCID(version, code, digest.bytes);
|
|
811
|
+
return new _CID(version, code, digest, bytes);
|
|
812
|
+
}
|
|
813
|
+
default: {
|
|
814
|
+
throw new Error("Invalid version");
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* Simplified version of `create` for CIDv0.
|
|
820
|
+
*/
|
|
821
|
+
static createV0(digest) {
|
|
822
|
+
return _CID.create(0, DAG_PB_CODE, digest);
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* Simplified version of `create` for CIDv1.
|
|
826
|
+
*
|
|
827
|
+
* @param code - Content encoding format code.
|
|
828
|
+
* @param digest - Multihash of the content.
|
|
829
|
+
*/
|
|
830
|
+
static createV1(code, digest) {
|
|
831
|
+
return _CID.create(1, code, digest);
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Decoded a CID from its binary representation. The byte array must contain
|
|
835
|
+
* only the CID with no additional bytes.
|
|
836
|
+
*
|
|
837
|
+
* An error will be thrown if the bytes provided do not contain a valid
|
|
838
|
+
* binary representation of a CID.
|
|
839
|
+
*/
|
|
840
|
+
static decode(bytes) {
|
|
841
|
+
const [cid, remainder] = _CID.decodeFirst(bytes);
|
|
842
|
+
if (remainder.length !== 0) {
|
|
843
|
+
throw new Error("Incorrect length");
|
|
844
|
+
}
|
|
845
|
+
return cid;
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* Decoded a CID from its binary representation at the beginning of a byte
|
|
849
|
+
* array.
|
|
850
|
+
*
|
|
851
|
+
* Returns an array with the first element containing the CID and the second
|
|
852
|
+
* element containing the remainder of the original byte array. The remainder
|
|
853
|
+
* will be a zero-length byte array if the provided bytes only contained a
|
|
854
|
+
* binary CID representation.
|
|
855
|
+
*/
|
|
856
|
+
static decodeFirst(bytes) {
|
|
857
|
+
const specs = _CID.inspectBytes(bytes);
|
|
858
|
+
const prefixSize = specs.size - specs.multihashSize;
|
|
859
|
+
const multihashBytes = coerce(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
|
|
860
|
+
if (multihashBytes.byteLength !== specs.multihashSize) {
|
|
861
|
+
throw new Error("Incorrect length");
|
|
862
|
+
}
|
|
863
|
+
const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
|
|
864
|
+
const digest = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
|
|
865
|
+
const cid = specs.version === 0 ? _CID.createV0(digest) : _CID.createV1(specs.codec, digest);
|
|
866
|
+
return [cid, bytes.subarray(specs.size)];
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* Inspect the initial bytes of a CID to determine its properties.
|
|
870
|
+
*
|
|
871
|
+
* Involves decoding up to 4 varints. Typically this will require only 4 to 6
|
|
872
|
+
* bytes but for larger multicodec code values and larger multihash digest
|
|
873
|
+
* lengths these varints can be quite large. It is recommended that at least
|
|
874
|
+
* 10 bytes be made available in the `initialBytes` argument for a complete
|
|
875
|
+
* inspection.
|
|
876
|
+
*/
|
|
877
|
+
static inspectBytes(initialBytes) {
|
|
878
|
+
let offset = 0;
|
|
879
|
+
const next = () => {
|
|
880
|
+
const [i, length2] = decode6(initialBytes.subarray(offset));
|
|
881
|
+
offset += length2;
|
|
882
|
+
return i;
|
|
883
|
+
};
|
|
884
|
+
let version = next();
|
|
885
|
+
let codec = DAG_PB_CODE;
|
|
886
|
+
if (version === 18) {
|
|
887
|
+
version = 0;
|
|
888
|
+
offset = 0;
|
|
889
|
+
} else {
|
|
890
|
+
codec = next();
|
|
891
|
+
}
|
|
892
|
+
if (version !== 0 && version !== 1) {
|
|
893
|
+
throw new RangeError(`Invalid CID version ${version}`);
|
|
894
|
+
}
|
|
895
|
+
const prefixSize = offset;
|
|
896
|
+
const multihashCode = next();
|
|
897
|
+
const digestSize = next();
|
|
898
|
+
const size = offset + digestSize;
|
|
899
|
+
const multihashSize = size - prefixSize;
|
|
900
|
+
return { version, codec, multihashCode, digestSize, multihashSize, size };
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* Takes cid in a string representation and creates an instance. If `base`
|
|
904
|
+
* decoder is not provided will use a default from the configuration. It will
|
|
905
|
+
* throw an error if encoding of the CID is not compatible with supplied (or
|
|
906
|
+
* a default decoder).
|
|
907
|
+
*/
|
|
908
|
+
static parse(source, base2) {
|
|
909
|
+
const [prefix, bytes] = parseCIDtoBytes(source, base2);
|
|
910
|
+
const cid = _CID.decode(bytes);
|
|
911
|
+
if (cid.version === 0 && source[0] !== "Q") {
|
|
912
|
+
throw Error("Version 0 CID string must not include multibase prefix");
|
|
913
|
+
}
|
|
914
|
+
baseCache(cid).set(prefix, source);
|
|
915
|
+
return cid;
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
function parseCIDtoBytes(source, base2) {
|
|
919
|
+
switch (source[0]) {
|
|
920
|
+
case "Q": {
|
|
921
|
+
const decoder = base2 ?? base58btc;
|
|
922
|
+
return [
|
|
923
|
+
base58btc.prefix,
|
|
924
|
+
decoder.decode(`${base58btc.prefix}${source}`)
|
|
925
|
+
];
|
|
926
|
+
}
|
|
927
|
+
case base58btc.prefix: {
|
|
928
|
+
const decoder = base2 ?? base58btc;
|
|
929
|
+
return [base58btc.prefix, decoder.decode(source)];
|
|
930
|
+
}
|
|
931
|
+
case base32.prefix: {
|
|
932
|
+
const decoder = base2 ?? base32;
|
|
933
|
+
return [base32.prefix, decoder.decode(source)];
|
|
934
|
+
}
|
|
935
|
+
case base36.prefix: {
|
|
936
|
+
const decoder = base2 ?? base36;
|
|
937
|
+
return [base36.prefix, decoder.decode(source)];
|
|
938
|
+
}
|
|
939
|
+
default: {
|
|
940
|
+
if (base2 == null) {
|
|
941
|
+
throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");
|
|
942
|
+
}
|
|
943
|
+
return [source[0], base2.decode(source)];
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
function toStringV0(bytes, cache2, base2) {
|
|
948
|
+
const { prefix } = base2;
|
|
949
|
+
if (prefix !== base58btc.prefix) {
|
|
950
|
+
throw Error(`Cannot string encode V0 in ${base2.name} encoding`);
|
|
951
|
+
}
|
|
952
|
+
const cid = cache2.get(prefix);
|
|
953
|
+
if (cid == null) {
|
|
954
|
+
const cid2 = base2.encode(bytes).slice(1);
|
|
955
|
+
cache2.set(prefix, cid2);
|
|
956
|
+
return cid2;
|
|
957
|
+
} else {
|
|
958
|
+
return cid;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
function toStringV1(bytes, cache2, base2) {
|
|
962
|
+
const { prefix } = base2;
|
|
963
|
+
const cid = cache2.get(prefix);
|
|
964
|
+
if (cid == null) {
|
|
965
|
+
const cid2 = base2.encode(bytes);
|
|
966
|
+
cache2.set(prefix, cid2);
|
|
967
|
+
return cid2;
|
|
968
|
+
} else {
|
|
969
|
+
return cid;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
var DAG_PB_CODE = 112;
|
|
973
|
+
var SHA_256_CODE = 18;
|
|
974
|
+
function encodeCID(version, code, multihash) {
|
|
975
|
+
const codeOffset = encodingLength(version);
|
|
976
|
+
const hashOffset = codeOffset + encodingLength(code);
|
|
977
|
+
const bytes = new Uint8Array(hashOffset + multihash.byteLength);
|
|
978
|
+
encodeTo(version, bytes, 0);
|
|
979
|
+
encodeTo(code, bytes, codeOffset);
|
|
980
|
+
bytes.set(multihash, hashOffset);
|
|
981
|
+
return bytes;
|
|
982
|
+
}
|
|
983
|
+
var cidSymbol = Symbol.for("@ipld/js-cid/CID");
|
|
984
|
+
|
|
985
|
+
// ../../../node_modules/.pnpm/@ipld+dag-cbor@9.1.0/node_modules/@ipld/dag-cbor/src/index.js
|
|
986
|
+
var CID_CBOR_TAG = 42;
|
|
987
|
+
function cidEncoder(obj) {
|
|
988
|
+
if (obj.asCID !== obj && obj["/"] !== obj.bytes) {
|
|
989
|
+
return null;
|
|
990
|
+
}
|
|
991
|
+
const cid = CID2.asCID(obj);
|
|
992
|
+
if (!cid) {
|
|
993
|
+
return null;
|
|
994
|
+
}
|
|
995
|
+
const bytes = new Uint8Array(cid.bytes.byteLength + 1);
|
|
996
|
+
bytes.set(cid.bytes, 1);
|
|
997
|
+
return [
|
|
998
|
+
new Token(Type.tag, CID_CBOR_TAG),
|
|
999
|
+
new Token(Type.bytes, bytes)
|
|
1000
|
+
];
|
|
1001
|
+
}
|
|
1002
|
+
function undefinedEncoder() {
|
|
1003
|
+
throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded");
|
|
1004
|
+
}
|
|
1005
|
+
function numberEncoder(num) {
|
|
1006
|
+
if (Number.isNaN(num)) {
|
|
1007
|
+
throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");
|
|
1008
|
+
}
|
|
1009
|
+
if (num === Infinity || num === -Infinity) {
|
|
1010
|
+
throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");
|
|
1011
|
+
}
|
|
1012
|
+
return null;
|
|
1013
|
+
}
|
|
1014
|
+
var _encodeOptions = {
|
|
1015
|
+
float64: true,
|
|
1016
|
+
typeEncoders: {
|
|
1017
|
+
Object: cidEncoder,
|
|
1018
|
+
undefined: undefinedEncoder,
|
|
1019
|
+
number: numberEncoder
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
var encodeOptions = {
|
|
1023
|
+
..._encodeOptions,
|
|
1024
|
+
typeEncoders: {
|
|
1025
|
+
..._encodeOptions.typeEncoders
|
|
1026
|
+
}
|
|
1027
|
+
};
|
|
1028
|
+
function cidDecoder(bytes) {
|
|
1029
|
+
if (bytes[0] !== 0) {
|
|
1030
|
+
throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");
|
|
1031
|
+
}
|
|
1032
|
+
return CID2.decode(bytes.subarray(1));
|
|
1033
|
+
}
|
|
1034
|
+
var _decodeOptions = {
|
|
1035
|
+
allowIndefinite: false,
|
|
1036
|
+
coerceUndefinedToNull: true,
|
|
1037
|
+
allowNaN: false,
|
|
1038
|
+
allowInfinity: false,
|
|
1039
|
+
allowBigInt: true,
|
|
1040
|
+
// this will lead to BigInt for ints outside of
|
|
1041
|
+
// safe-integer range, which may surprise users
|
|
1042
|
+
strict: true,
|
|
1043
|
+
useMaps: false,
|
|
1044
|
+
rejectDuplicateMapKeys: true,
|
|
1045
|
+
/** @type {import('cborg').TagDecoder[]} */
|
|
1046
|
+
tags: []
|
|
1047
|
+
};
|
|
1048
|
+
_decodeOptions.tags[CID_CBOR_TAG] = cidDecoder;
|
|
1049
|
+
var decodeOptions = {
|
|
1050
|
+
..._decodeOptions,
|
|
1051
|
+
tags: _decodeOptions.tags.slice()
|
|
1052
|
+
};
|
|
1053
|
+
var encode4 = (node) => encode(node, _encodeOptions);
|
|
1054
|
+
var decode8 = (data) => decode(data, _decodeOptions);
|
|
1055
|
+
|
|
1056
|
+
// ../../../node_modules/.pnpm/@ipld+car@5.2.6/node_modules/@ipld/car/src/decoder-common.js
|
|
1057
|
+
var import_varint2 = __toESM(require_varint(), 1);
|
|
1058
|
+
var CIDV0_BYTES = {
|
|
1059
|
+
SHA2_256: 18,
|
|
1060
|
+
LENGTH: 32,
|
|
1061
|
+
DAG_PB: 112
|
|
1062
|
+
};
|
|
1063
|
+
var V2_HEADER_LENGTH = (
|
|
1064
|
+
/* characteristics */
|
|
1065
|
+
16 + 8 + 8 + 8
|
|
1066
|
+
);
|
|
1067
|
+
function decodeVarint(bytes, seeker) {
|
|
1068
|
+
if (!bytes.length) {
|
|
1069
|
+
throw new Error("Unexpected end of data");
|
|
1070
|
+
}
|
|
1071
|
+
const i = import_varint2.default.decode(bytes);
|
|
1072
|
+
seeker.seek(
|
|
1073
|
+
/** @type {number} */
|
|
1074
|
+
import_varint2.default.decode.bytes
|
|
1075
|
+
);
|
|
1076
|
+
return i;
|
|
1077
|
+
}
|
|
1078
|
+
function decodeV2Header(bytes) {
|
|
1079
|
+
const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
1080
|
+
let offset = 0;
|
|
1081
|
+
const header = {
|
|
1082
|
+
version: 2,
|
|
1083
|
+
/** @type {[bigint, bigint]} */
|
|
1084
|
+
characteristics: [
|
|
1085
|
+
dv.getBigUint64(offset, true),
|
|
1086
|
+
dv.getBigUint64(offset += 8, true)
|
|
1087
|
+
],
|
|
1088
|
+
dataOffset: Number(dv.getBigUint64(offset += 8, true)),
|
|
1089
|
+
dataSize: Number(dv.getBigUint64(offset += 8, true)),
|
|
1090
|
+
indexOffset: Number(dv.getBigUint64(offset += 8, true))
|
|
1091
|
+
};
|
|
1092
|
+
return header;
|
|
1093
|
+
}
|
|
1094
|
+
function getMultihashLength(bytes) {
|
|
1095
|
+
import_varint2.default.decode(bytes);
|
|
1096
|
+
const codeLength = (
|
|
1097
|
+
/** @type {number} */
|
|
1098
|
+
import_varint2.default.decode.bytes
|
|
1099
|
+
);
|
|
1100
|
+
const length2 = import_varint2.default.decode(bytes.subarray(import_varint2.default.decode.bytes));
|
|
1101
|
+
const lengthLength = (
|
|
1102
|
+
/** @type {number} */
|
|
1103
|
+
import_varint2.default.decode.bytes
|
|
1104
|
+
);
|
|
1105
|
+
const mhLength = codeLength + lengthLength + length2;
|
|
1106
|
+
return mhLength;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
// ../../../node_modules/.pnpm/@ipld+car@5.2.6/node_modules/@ipld/car/src/header-validator.js
|
|
1110
|
+
var Kinds = {
|
|
1111
|
+
Null: (
|
|
1112
|
+
/** @returns {undefined|null} */
|
|
1113
|
+
(obj) => obj === null ? obj : void 0
|
|
1114
|
+
),
|
|
1115
|
+
Int: (
|
|
1116
|
+
/** @returns {undefined|number} */
|
|
1117
|
+
(obj) => Number.isInteger(obj) ? obj : void 0
|
|
1118
|
+
),
|
|
1119
|
+
Float: (
|
|
1120
|
+
/** @returns {undefined|number} */
|
|
1121
|
+
(obj) => typeof obj === "number" && Number.isFinite(obj) ? obj : void 0
|
|
1122
|
+
),
|
|
1123
|
+
String: (
|
|
1124
|
+
/** @returns {undefined|string} */
|
|
1125
|
+
(obj) => typeof obj === "string" ? obj : void 0
|
|
1126
|
+
),
|
|
1127
|
+
Bool: (
|
|
1128
|
+
/** @returns {undefined|boolean} */
|
|
1129
|
+
(obj) => typeof obj === "boolean" ? obj : void 0
|
|
1130
|
+
),
|
|
1131
|
+
Bytes: (
|
|
1132
|
+
/** @returns {undefined|Uint8Array} */
|
|
1133
|
+
(obj) => obj instanceof Uint8Array ? obj : void 0
|
|
1134
|
+
),
|
|
1135
|
+
Link: (
|
|
1136
|
+
/** @returns {undefined|object} */
|
|
1137
|
+
(obj) => obj !== null && typeof obj === "object" && obj.asCID === obj ? obj : void 0
|
|
1138
|
+
),
|
|
1139
|
+
List: (
|
|
1140
|
+
/** @returns {undefined|Array<any>} */
|
|
1141
|
+
(obj) => Array.isArray(obj) ? obj : void 0
|
|
1142
|
+
),
|
|
1143
|
+
Map: (
|
|
1144
|
+
/** @returns {undefined|object} */
|
|
1145
|
+
(obj) => obj !== null && typeof obj === "object" && obj.asCID !== obj && !Array.isArray(obj) && !(obj instanceof Uint8Array) ? obj : void 0
|
|
1146
|
+
)
|
|
1147
|
+
};
|
|
1148
|
+
var Types = {
|
|
1149
|
+
"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)": Kinds.Link,
|
|
1150
|
+
"CarV1HeaderOrV2Pragma > roots (anon)": (
|
|
1151
|
+
/** @returns {undefined|any} */
|
|
1152
|
+
(obj) => {
|
|
1153
|
+
if (Kinds.List(obj) === void 0) {
|
|
1154
|
+
return void 0;
|
|
1155
|
+
}
|
|
1156
|
+
for (let i = 0; i < obj.length; i++) {
|
|
1157
|
+
let v = obj[i];
|
|
1158
|
+
v = Types["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](v);
|
|
1159
|
+
if (v === void 0) {
|
|
1160
|
+
return void 0;
|
|
1161
|
+
}
|
|
1162
|
+
if (v !== obj[i]) {
|
|
1163
|
+
const ret = obj.slice(0, i);
|
|
1164
|
+
for (let j = i; j < obj.length; j++) {
|
|
1165
|
+
let v2 = obj[j];
|
|
1166
|
+
v2 = Types["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](v2);
|
|
1167
|
+
if (v2 === void 0) {
|
|
1168
|
+
return void 0;
|
|
1169
|
+
}
|
|
1170
|
+
ret.push(v2);
|
|
1171
|
+
}
|
|
1172
|
+
return ret;
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
return obj;
|
|
1176
|
+
}
|
|
1177
|
+
),
|
|
1178
|
+
Int: Kinds.Int,
|
|
1179
|
+
CarV1HeaderOrV2Pragma: (
|
|
1180
|
+
/** @returns {undefined|any} */
|
|
1181
|
+
(obj) => {
|
|
1182
|
+
if (Kinds.Map(obj) === void 0) {
|
|
1183
|
+
return void 0;
|
|
1184
|
+
}
|
|
1185
|
+
const entries = Object.entries(obj);
|
|
1186
|
+
let ret = obj;
|
|
1187
|
+
let requiredCount = 1;
|
|
1188
|
+
for (let i = 0; i < entries.length; i++) {
|
|
1189
|
+
const [key, value] = entries[i];
|
|
1190
|
+
switch (key) {
|
|
1191
|
+
case "roots":
|
|
1192
|
+
{
|
|
1193
|
+
const v = Types["CarV1HeaderOrV2Pragma > roots (anon)"](obj[key]);
|
|
1194
|
+
if (v === void 0) {
|
|
1195
|
+
return void 0;
|
|
1196
|
+
}
|
|
1197
|
+
if (v !== value || ret !== obj) {
|
|
1198
|
+
if (ret === obj) {
|
|
1199
|
+
ret = {};
|
|
1200
|
+
for (let j = 0; j < i; j++) {
|
|
1201
|
+
ret[entries[j][0]] = entries[j][1];
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
ret.roots = v;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
break;
|
|
1208
|
+
case "version":
|
|
1209
|
+
{
|
|
1210
|
+
requiredCount--;
|
|
1211
|
+
const v = Types.Int(obj[key]);
|
|
1212
|
+
if (v === void 0) {
|
|
1213
|
+
return void 0;
|
|
1214
|
+
}
|
|
1215
|
+
if (v !== value || ret !== obj) {
|
|
1216
|
+
if (ret === obj) {
|
|
1217
|
+
ret = {};
|
|
1218
|
+
for (let j = 0; j < i; j++) {
|
|
1219
|
+
ret[entries[j][0]] = entries[j][1];
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
ret.version = v;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
break;
|
|
1226
|
+
default:
|
|
1227
|
+
return void 0;
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
if (requiredCount > 0) {
|
|
1231
|
+
return void 0;
|
|
1232
|
+
}
|
|
1233
|
+
return ret;
|
|
1234
|
+
}
|
|
1235
|
+
)
|
|
1236
|
+
};
|
|
1237
|
+
var Reprs = {
|
|
1238
|
+
"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)": Kinds.Link,
|
|
1239
|
+
"CarV1HeaderOrV2Pragma > roots (anon)": (
|
|
1240
|
+
/** @returns {undefined|any} */
|
|
1241
|
+
(obj) => {
|
|
1242
|
+
if (Kinds.List(obj) === void 0) {
|
|
1243
|
+
return void 0;
|
|
1244
|
+
}
|
|
1245
|
+
for (let i = 0; i < obj.length; i++) {
|
|
1246
|
+
let v = obj[i];
|
|
1247
|
+
v = Reprs["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](v);
|
|
1248
|
+
if (v === void 0) {
|
|
1249
|
+
return void 0;
|
|
1250
|
+
}
|
|
1251
|
+
if (v !== obj[i]) {
|
|
1252
|
+
const ret = obj.slice(0, i);
|
|
1253
|
+
for (let j = i; j < obj.length; j++) {
|
|
1254
|
+
let v2 = obj[j];
|
|
1255
|
+
v2 = Reprs["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](v2);
|
|
1256
|
+
if (v2 === void 0) {
|
|
1257
|
+
return void 0;
|
|
1258
|
+
}
|
|
1259
|
+
ret.push(v2);
|
|
1260
|
+
}
|
|
1261
|
+
return ret;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
return obj;
|
|
1265
|
+
}
|
|
1266
|
+
),
|
|
1267
|
+
Int: Kinds.Int,
|
|
1268
|
+
CarV1HeaderOrV2Pragma: (
|
|
1269
|
+
/** @returns {undefined|any} */
|
|
1270
|
+
(obj) => {
|
|
1271
|
+
if (Kinds.Map(obj) === void 0) {
|
|
1272
|
+
return void 0;
|
|
1273
|
+
}
|
|
1274
|
+
const entries = Object.entries(obj);
|
|
1275
|
+
let ret = obj;
|
|
1276
|
+
let requiredCount = 1;
|
|
1277
|
+
for (let i = 0; i < entries.length; i++) {
|
|
1278
|
+
const [key, value] = entries[i];
|
|
1279
|
+
switch (key) {
|
|
1280
|
+
case "roots":
|
|
1281
|
+
{
|
|
1282
|
+
const v = Reprs["CarV1HeaderOrV2Pragma > roots (anon)"](value);
|
|
1283
|
+
if (v === void 0) {
|
|
1284
|
+
return void 0;
|
|
1285
|
+
}
|
|
1286
|
+
if (v !== value || ret !== obj) {
|
|
1287
|
+
if (ret === obj) {
|
|
1288
|
+
ret = {};
|
|
1289
|
+
for (let j = 0; j < i; j++) {
|
|
1290
|
+
ret[entries[j][0]] = entries[j][1];
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
ret.roots = v;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
break;
|
|
1297
|
+
case "version":
|
|
1298
|
+
{
|
|
1299
|
+
requiredCount--;
|
|
1300
|
+
const v = Reprs.Int(value);
|
|
1301
|
+
if (v === void 0) {
|
|
1302
|
+
return void 0;
|
|
1303
|
+
}
|
|
1304
|
+
if (v !== value || ret !== obj) {
|
|
1305
|
+
if (ret === obj) {
|
|
1306
|
+
ret = {};
|
|
1307
|
+
for (let j = 0; j < i; j++) {
|
|
1308
|
+
ret[entries[j][0]] = entries[j][1];
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
ret.version = v;
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
break;
|
|
1315
|
+
default:
|
|
1316
|
+
return void 0;
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
if (requiredCount > 0) {
|
|
1320
|
+
return void 0;
|
|
1321
|
+
}
|
|
1322
|
+
return ret;
|
|
1323
|
+
}
|
|
1324
|
+
)
|
|
1325
|
+
};
|
|
1326
|
+
var CarV1HeaderOrV2Pragma = {
|
|
1327
|
+
toTyped: Types.CarV1HeaderOrV2Pragma,
|
|
1328
|
+
toRepresentation: Reprs.CarV1HeaderOrV2Pragma
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1331
|
+
// ../../../node_modules/.pnpm/cborg@4.0.9/node_modules/cborg/lib/length.js
|
|
1332
|
+
var cborEncoders = makeCborEncoders();
|
|
1333
|
+
|
|
1334
|
+
// ../../../node_modules/.pnpm/@ipld+car@5.2.6/node_modules/@ipld/car/src/buffer-writer.js
|
|
1335
|
+
var import_varint3 = __toESM(require_varint(), 1);
|
|
1336
|
+
var headerPreludeTokens = [
|
|
1337
|
+
new Token(Type.map, 2),
|
|
1338
|
+
new Token(Type.string, "version"),
|
|
1339
|
+
new Token(Type.uint, 1),
|
|
1340
|
+
new Token(Type.string, "roots")
|
|
1341
|
+
];
|
|
1342
|
+
var CID_TAG = new Token(Type.tag, 42);
|
|
1343
|
+
|
|
1344
|
+
// ../../../node_modules/.pnpm/@ipld+car@5.2.6/node_modules/@ipld/car/src/decoder.js
|
|
1345
|
+
async function readHeader(reader, strictVersion) {
|
|
1346
|
+
const length2 = decodeVarint(await reader.upTo(8), reader);
|
|
1347
|
+
if (length2 === 0) {
|
|
1348
|
+
throw new Error("Invalid CAR header (zero length)");
|
|
1349
|
+
}
|
|
1350
|
+
const header = await reader.exactly(length2, true);
|
|
1351
|
+
const block = decode8(header);
|
|
1352
|
+
if (CarV1HeaderOrV2Pragma.toTyped(block) === void 0) {
|
|
1353
|
+
throw new Error("Invalid CAR header format");
|
|
1354
|
+
}
|
|
1355
|
+
if (block.version !== 1 && block.version !== 2 || strictVersion !== void 0 && block.version !== strictVersion) {
|
|
1356
|
+
throw new Error(`Invalid CAR version: ${block.version}${strictVersion !== void 0 ? ` (expected ${strictVersion})` : ""}`);
|
|
1357
|
+
}
|
|
1358
|
+
if (block.version === 1) {
|
|
1359
|
+
if (!Array.isArray(block.roots)) {
|
|
1360
|
+
throw new Error("Invalid CAR header format");
|
|
1361
|
+
}
|
|
1362
|
+
return block;
|
|
1363
|
+
}
|
|
1364
|
+
if (block.roots !== void 0) {
|
|
1365
|
+
throw new Error("Invalid CAR header format");
|
|
1366
|
+
}
|
|
1367
|
+
const v2Header = decodeV2Header(await reader.exactly(V2_HEADER_LENGTH, true));
|
|
1368
|
+
reader.seek(v2Header.dataOffset - reader.pos);
|
|
1369
|
+
const v1Header = await readHeader(reader, 1);
|
|
1370
|
+
return Object.assign(v1Header, v2Header);
|
|
1371
|
+
}
|
|
1372
|
+
async function readCid(reader) {
|
|
1373
|
+
const first = await reader.exactly(2, false);
|
|
1374
|
+
if (first[0] === CIDV0_BYTES.SHA2_256 && first[1] === CIDV0_BYTES.LENGTH) {
|
|
1375
|
+
const bytes2 = await reader.exactly(34, true);
|
|
1376
|
+
const multihash2 = decode2(bytes2);
|
|
1377
|
+
return CID.create(0, CIDV0_BYTES.DAG_PB, multihash2);
|
|
1378
|
+
}
|
|
1379
|
+
const version = decodeVarint(await reader.upTo(8), reader);
|
|
1380
|
+
if (version !== 1) {
|
|
1381
|
+
throw new Error(`Unexpected CID version (${version})`);
|
|
1382
|
+
}
|
|
1383
|
+
const codec = decodeVarint(await reader.upTo(8), reader);
|
|
1384
|
+
const bytes = await reader.exactly(getMultihashLength(await reader.upTo(8)), true);
|
|
1385
|
+
const multihash = decode2(bytes);
|
|
1386
|
+
return CID.create(version, codec, multihash);
|
|
1387
|
+
}
|
|
1388
|
+
async function readBlockHead(reader) {
|
|
1389
|
+
const start = reader.pos;
|
|
1390
|
+
let length2 = decodeVarint(await reader.upTo(8), reader);
|
|
1391
|
+
if (length2 === 0) {
|
|
1392
|
+
throw new Error("Invalid CAR section (zero length)");
|
|
1393
|
+
}
|
|
1394
|
+
length2 += reader.pos - start;
|
|
1395
|
+
const cid = await readCid(reader);
|
|
1396
|
+
const blockLength = length2 - Number(reader.pos - start);
|
|
1397
|
+
return { cid, length: length2, blockLength };
|
|
1398
|
+
}
|
|
1399
|
+
async function readBlock(reader) {
|
|
1400
|
+
const { cid, blockLength } = await readBlockHead(reader);
|
|
1401
|
+
const bytes = await reader.exactly(blockLength, true);
|
|
1402
|
+
return { bytes, cid };
|
|
1403
|
+
}
|
|
1404
|
+
async function readBlockIndex(reader) {
|
|
1405
|
+
const offset = reader.pos;
|
|
1406
|
+
const { cid, length: length2, blockLength } = await readBlockHead(reader);
|
|
1407
|
+
const index = { cid, length: length2, blockLength, offset, blockOffset: reader.pos };
|
|
1408
|
+
reader.seek(index.blockLength);
|
|
1409
|
+
return index;
|
|
1410
|
+
}
|
|
1411
|
+
function createDecoder(reader) {
|
|
1412
|
+
const headerPromise = (async () => {
|
|
1413
|
+
const header = await readHeader(reader);
|
|
1414
|
+
if (header.version === 2) {
|
|
1415
|
+
const v1length = reader.pos - header.dataOffset;
|
|
1416
|
+
reader = limitReader(reader, header.dataSize - v1length);
|
|
1417
|
+
}
|
|
1418
|
+
return header;
|
|
1419
|
+
})();
|
|
1420
|
+
return {
|
|
1421
|
+
header: () => headerPromise,
|
|
1422
|
+
async *blocks() {
|
|
1423
|
+
await headerPromise;
|
|
1424
|
+
while ((await reader.upTo(8)).length > 0) {
|
|
1425
|
+
yield await readBlock(reader);
|
|
1426
|
+
}
|
|
1427
|
+
},
|
|
1428
|
+
async *blocksIndex() {
|
|
1429
|
+
await headerPromise;
|
|
1430
|
+
while ((await reader.upTo(8)).length > 0) {
|
|
1431
|
+
yield await readBlockIndex(reader);
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
};
|
|
1435
|
+
}
|
|
1436
|
+
function bytesReader(bytes) {
|
|
1437
|
+
let pos = 0;
|
|
1438
|
+
return {
|
|
1439
|
+
async upTo(length2) {
|
|
1440
|
+
const out = bytes.subarray(pos, pos + Math.min(length2, bytes.length - pos));
|
|
1441
|
+
return out;
|
|
1442
|
+
},
|
|
1443
|
+
async exactly(length2, seek = false) {
|
|
1444
|
+
if (length2 > bytes.length - pos) {
|
|
1445
|
+
throw new Error("Unexpected end of data");
|
|
1446
|
+
}
|
|
1447
|
+
const out = bytes.subarray(pos, pos + length2);
|
|
1448
|
+
if (seek) {
|
|
1449
|
+
pos += length2;
|
|
1450
|
+
}
|
|
1451
|
+
return out;
|
|
1452
|
+
},
|
|
1453
|
+
seek(length2) {
|
|
1454
|
+
pos += length2;
|
|
1455
|
+
},
|
|
1456
|
+
get pos() {
|
|
1457
|
+
return pos;
|
|
1458
|
+
}
|
|
1459
|
+
};
|
|
1460
|
+
}
|
|
1461
|
+
function chunkReader(readChunk) {
|
|
1462
|
+
let pos = 0;
|
|
1463
|
+
let have = 0;
|
|
1464
|
+
let offset = 0;
|
|
1465
|
+
let currentChunk = new Uint8Array(0);
|
|
1466
|
+
const read2 = async (length2) => {
|
|
1467
|
+
have = currentChunk.length - offset;
|
|
1468
|
+
const bufa = [currentChunk.subarray(offset)];
|
|
1469
|
+
while (have < length2) {
|
|
1470
|
+
const chunk = await readChunk();
|
|
1471
|
+
if (chunk == null) {
|
|
1472
|
+
break;
|
|
1473
|
+
}
|
|
1474
|
+
if (have < 0) {
|
|
1475
|
+
if (chunk.length > have) {
|
|
1476
|
+
bufa.push(chunk.subarray(-have));
|
|
1477
|
+
}
|
|
1478
|
+
} else {
|
|
1479
|
+
bufa.push(chunk);
|
|
1480
|
+
}
|
|
1481
|
+
have += chunk.length;
|
|
1482
|
+
}
|
|
1483
|
+
currentChunk = new Uint8Array(bufa.reduce((p, c) => p + c.length, 0));
|
|
1484
|
+
let off = 0;
|
|
1485
|
+
for (const b of bufa) {
|
|
1486
|
+
currentChunk.set(b, off);
|
|
1487
|
+
off += b.length;
|
|
1488
|
+
}
|
|
1489
|
+
offset = 0;
|
|
1490
|
+
};
|
|
1491
|
+
return {
|
|
1492
|
+
async upTo(length2) {
|
|
1493
|
+
if (currentChunk.length - offset < length2) {
|
|
1494
|
+
await read2(length2);
|
|
1495
|
+
}
|
|
1496
|
+
return currentChunk.subarray(offset, offset + Math.min(currentChunk.length - offset, length2));
|
|
1497
|
+
},
|
|
1498
|
+
async exactly(length2, seek = false) {
|
|
1499
|
+
if (currentChunk.length - offset < length2) {
|
|
1500
|
+
await read2(length2);
|
|
1501
|
+
}
|
|
1502
|
+
if (currentChunk.length - offset < length2) {
|
|
1503
|
+
throw new Error("Unexpected end of data");
|
|
1504
|
+
}
|
|
1505
|
+
const out = currentChunk.subarray(offset, offset + length2);
|
|
1506
|
+
if (seek) {
|
|
1507
|
+
pos += length2;
|
|
1508
|
+
offset += length2;
|
|
1509
|
+
}
|
|
1510
|
+
return out;
|
|
1511
|
+
},
|
|
1512
|
+
seek(length2) {
|
|
1513
|
+
pos += length2;
|
|
1514
|
+
offset += length2;
|
|
1515
|
+
},
|
|
1516
|
+
get pos() {
|
|
1517
|
+
return pos;
|
|
1518
|
+
}
|
|
1519
|
+
};
|
|
1520
|
+
}
|
|
1521
|
+
function asyncIterableReader(asyncIterable) {
|
|
1522
|
+
const iterator = asyncIterable[Symbol.asyncIterator]();
|
|
1523
|
+
async function readChunk() {
|
|
1524
|
+
const next = await iterator.next();
|
|
1525
|
+
if (next.done) {
|
|
1526
|
+
return null;
|
|
1527
|
+
}
|
|
1528
|
+
return next.value;
|
|
1529
|
+
}
|
|
1530
|
+
return chunkReader(readChunk);
|
|
1531
|
+
}
|
|
1532
|
+
function limitReader(reader, byteLimit) {
|
|
1533
|
+
let bytesRead = 0;
|
|
1534
|
+
return {
|
|
1535
|
+
async upTo(length2) {
|
|
1536
|
+
let bytes = await reader.upTo(length2);
|
|
1537
|
+
if (bytes.length + bytesRead > byteLimit) {
|
|
1538
|
+
bytes = bytes.subarray(0, byteLimit - bytesRead);
|
|
1539
|
+
}
|
|
1540
|
+
return bytes;
|
|
1541
|
+
},
|
|
1542
|
+
async exactly(length2, seek = false) {
|
|
1543
|
+
const bytes = await reader.exactly(length2, seek);
|
|
1544
|
+
if (bytes.length + bytesRead > byteLimit) {
|
|
1545
|
+
throw new Error("Unexpected end of data");
|
|
1546
|
+
}
|
|
1547
|
+
if (seek) {
|
|
1548
|
+
bytesRead += length2;
|
|
1549
|
+
}
|
|
1550
|
+
return bytes;
|
|
1551
|
+
},
|
|
1552
|
+
seek(length2) {
|
|
1553
|
+
bytesRead += length2;
|
|
1554
|
+
reader.seek(length2);
|
|
1555
|
+
},
|
|
1556
|
+
get pos() {
|
|
1557
|
+
return reader.pos;
|
|
1558
|
+
}
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
// ../../../node_modules/.pnpm/@ipld+car@5.2.6/node_modules/@ipld/car/src/reader-browser.js
|
|
1563
|
+
var CarReader = class {
|
|
1564
|
+
/**
|
|
1565
|
+
* @constructs CarReader
|
|
1566
|
+
* @param {CarHeader|CarV2Header} header
|
|
1567
|
+
* @param {Block[]} blocks
|
|
1568
|
+
*/
|
|
1569
|
+
constructor(header, blocks) {
|
|
1570
|
+
this._header = header;
|
|
1571
|
+
this._blocks = blocks;
|
|
1572
|
+
this._keys = blocks.map((b) => b.cid.toString());
|
|
1573
|
+
}
|
|
1574
|
+
/**
|
|
1575
|
+
* @property
|
|
1576
|
+
* @memberof CarReader
|
|
1577
|
+
* @instance
|
|
1578
|
+
*/
|
|
1579
|
+
get version() {
|
|
1580
|
+
return this._header.version;
|
|
1581
|
+
}
|
|
1582
|
+
/**
|
|
1583
|
+
* Get the list of roots defined by the CAR referenced by this reader. May be
|
|
1584
|
+
* zero or more `CID`s.
|
|
1585
|
+
*
|
|
1586
|
+
* @function
|
|
1587
|
+
* @memberof CarReader
|
|
1588
|
+
* @instance
|
|
1589
|
+
* @async
|
|
1590
|
+
* @returns {Promise<CID[]>}
|
|
1591
|
+
*/
|
|
1592
|
+
async getRoots() {
|
|
1593
|
+
return this._header.roots;
|
|
1594
|
+
}
|
|
1595
|
+
/**
|
|
1596
|
+
* Check whether a given `CID` exists within the CAR referenced by this
|
|
1597
|
+
* reader.
|
|
1598
|
+
*
|
|
1599
|
+
* @function
|
|
1600
|
+
* @memberof CarReader
|
|
1601
|
+
* @instance
|
|
1602
|
+
* @async
|
|
1603
|
+
* @param {CID} key
|
|
1604
|
+
* @returns {Promise<boolean>}
|
|
1605
|
+
*/
|
|
1606
|
+
async has(key) {
|
|
1607
|
+
return this._keys.indexOf(key.toString()) > -1;
|
|
1608
|
+
}
|
|
1609
|
+
/**
|
|
1610
|
+
* Fetch a `Block` (a `{ cid:CID, bytes:Uint8Array }` pair) from the CAR
|
|
1611
|
+
* referenced by this reader matching the provided `CID`. In the case where
|
|
1612
|
+
* the provided `CID` doesn't exist within the CAR, `undefined` will be
|
|
1613
|
+
* returned.
|
|
1614
|
+
*
|
|
1615
|
+
* @function
|
|
1616
|
+
* @memberof CarReader
|
|
1617
|
+
* @instance
|
|
1618
|
+
* @async
|
|
1619
|
+
* @param {CID} key
|
|
1620
|
+
* @returns {Promise<Block | undefined>}
|
|
1621
|
+
*/
|
|
1622
|
+
async get(key) {
|
|
1623
|
+
const index = this._keys.indexOf(key.toString());
|
|
1624
|
+
return index > -1 ? this._blocks[index] : void 0;
|
|
1625
|
+
}
|
|
1626
|
+
/**
|
|
1627
|
+
* Returns a `BlockIterator` (`AsyncIterable<Block>`) that iterates over all
|
|
1628
|
+
* of the `Block`s (`{ cid:CID, bytes:Uint8Array }` pairs) contained within
|
|
1629
|
+
* the CAR referenced by this reader.
|
|
1630
|
+
*
|
|
1631
|
+
* @function
|
|
1632
|
+
* @memberof CarReader
|
|
1633
|
+
* @instance
|
|
1634
|
+
* @async
|
|
1635
|
+
* @generator
|
|
1636
|
+
* @returns {AsyncGenerator<Block>}
|
|
1637
|
+
*/
|
|
1638
|
+
async *blocks() {
|
|
1639
|
+
for (const block of this._blocks) {
|
|
1640
|
+
yield block;
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
/**
|
|
1644
|
+
* Returns a `CIDIterator` (`AsyncIterable<CID>`) that iterates over all of
|
|
1645
|
+
* the `CID`s contained within the CAR referenced by this reader.
|
|
1646
|
+
*
|
|
1647
|
+
* @function
|
|
1648
|
+
* @memberof CarReader
|
|
1649
|
+
* @instance
|
|
1650
|
+
* @async
|
|
1651
|
+
* @generator
|
|
1652
|
+
* @returns {AsyncGenerator<CID>}
|
|
1653
|
+
*/
|
|
1654
|
+
async *cids() {
|
|
1655
|
+
for (const block of this._blocks) {
|
|
1656
|
+
yield block.cid;
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
/**
|
|
1660
|
+
* Instantiate a {@link CarReader} from a `Uint8Array` blob. This performs a
|
|
1661
|
+
* decode fully in memory and maintains the decoded state in memory for full
|
|
1662
|
+
* access to the data via the `CarReader` API.
|
|
1663
|
+
*
|
|
1664
|
+
* @async
|
|
1665
|
+
* @static
|
|
1666
|
+
* @memberof CarReader
|
|
1667
|
+
* @param {Uint8Array} bytes
|
|
1668
|
+
* @returns {Promise<CarReader>}
|
|
1669
|
+
*/
|
|
1670
|
+
static async fromBytes(bytes) {
|
|
1671
|
+
if (!(bytes instanceof Uint8Array)) {
|
|
1672
|
+
throw new TypeError("fromBytes() requires a Uint8Array");
|
|
1673
|
+
}
|
|
1674
|
+
return decodeReaderComplete(bytesReader(bytes));
|
|
1675
|
+
}
|
|
1676
|
+
/**
|
|
1677
|
+
* Instantiate a {@link CarReader} from a `AsyncIterable<Uint8Array>`, such as
|
|
1678
|
+
* a [modern Node.js stream](https://nodejs.org/api/stream.html#stream_streams_compatibility_with_async_generators_and_async_iterators).
|
|
1679
|
+
* This performs a decode fully in memory and maintains the decoded state in
|
|
1680
|
+
* memory for full access to the data via the `CarReader` API.
|
|
1681
|
+
*
|
|
1682
|
+
* Care should be taken for large archives; this API may not be appropriate
|
|
1683
|
+
* where memory is a concern or the archive is potentially larger than the
|
|
1684
|
+
* amount of memory that the runtime can handle.
|
|
1685
|
+
*
|
|
1686
|
+
* @async
|
|
1687
|
+
* @static
|
|
1688
|
+
* @memberof CarReader
|
|
1689
|
+
* @param {AsyncIterable<Uint8Array>} asyncIterable
|
|
1690
|
+
* @returns {Promise<CarReader>}
|
|
1691
|
+
*/
|
|
1692
|
+
static async fromIterable(asyncIterable) {
|
|
1693
|
+
if (!asyncIterable || !(typeof asyncIterable[Symbol.asyncIterator] === "function")) {
|
|
1694
|
+
throw new TypeError("fromIterable() requires an async iterable");
|
|
1695
|
+
}
|
|
1696
|
+
return decodeReaderComplete(asyncIterableReader(asyncIterable));
|
|
1697
|
+
}
|
|
1698
|
+
};
|
|
1699
|
+
async function decodeReaderComplete(reader) {
|
|
1700
|
+
const decoder = createDecoder(reader);
|
|
1701
|
+
const header = await decoder.header();
|
|
1702
|
+
const blocks = [];
|
|
1703
|
+
for await (const block of decoder.blocks()) {
|
|
1704
|
+
blocks.push(block);
|
|
1705
|
+
}
|
|
1706
|
+
return new CarReader(header, blocks);
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
// ../../../node_modules/.pnpm/@ipld+car@5.2.6/node_modules/@ipld/car/src/encoder.js
|
|
1710
|
+
var import_varint4 = __toESM(require_varint(), 1);
|
|
1711
|
+
function createHeader(roots) {
|
|
1712
|
+
const headerBytes = encode4({ version: 1, roots });
|
|
1713
|
+
const varintBytes = import_varint4.default.encode(headerBytes.length);
|
|
1714
|
+
const header = new Uint8Array(varintBytes.length + headerBytes.length);
|
|
1715
|
+
header.set(varintBytes, 0);
|
|
1716
|
+
header.set(headerBytes, varintBytes.length);
|
|
1717
|
+
return header;
|
|
1718
|
+
}
|
|
1719
|
+
function createEncoder(writer) {
|
|
1720
|
+
return {
|
|
1721
|
+
/**
|
|
1722
|
+
* @param {CID[]} roots
|
|
1723
|
+
* @returns {Promise<void>}
|
|
1724
|
+
*/
|
|
1725
|
+
async setRoots(roots) {
|
|
1726
|
+
const bytes = createHeader(roots);
|
|
1727
|
+
await writer.write(bytes);
|
|
1728
|
+
},
|
|
1729
|
+
/**
|
|
1730
|
+
* @param {Block} block
|
|
1731
|
+
* @returns {Promise<void>}
|
|
1732
|
+
*/
|
|
1733
|
+
async writeBlock(block) {
|
|
1734
|
+
const { cid, bytes } = block;
|
|
1735
|
+
await writer.write(new Uint8Array(import_varint4.default.encode(cid.bytes.length + bytes.length)));
|
|
1736
|
+
await writer.write(cid.bytes);
|
|
1737
|
+
if (bytes.length) {
|
|
1738
|
+
await writer.write(bytes);
|
|
1739
|
+
}
|
|
1740
|
+
},
|
|
1741
|
+
/**
|
|
1742
|
+
* @returns {Promise<void>}
|
|
1743
|
+
*/
|
|
1744
|
+
async close() {
|
|
1745
|
+
await writer.end();
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
// ../../../node_modules/.pnpm/@ipld+car@5.2.6/node_modules/@ipld/car/src/iterator-channel.js
|
|
1751
|
+
function noop() {
|
|
1752
|
+
}
|
|
1753
|
+
function create2() {
|
|
1754
|
+
const chunkQueue = [];
|
|
1755
|
+
let drainer = null;
|
|
1756
|
+
let drainerResolver = noop;
|
|
1757
|
+
let ended = false;
|
|
1758
|
+
let outWait = null;
|
|
1759
|
+
let outWaitResolver = noop;
|
|
1760
|
+
const makeDrainer = () => {
|
|
1761
|
+
if (!drainer) {
|
|
1762
|
+
drainer = new Promise((resolve) => {
|
|
1763
|
+
drainerResolver = () => {
|
|
1764
|
+
drainer = null;
|
|
1765
|
+
drainerResolver = noop;
|
|
1766
|
+
resolve();
|
|
1767
|
+
};
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
return drainer;
|
|
1771
|
+
};
|
|
1772
|
+
const writer = {
|
|
1773
|
+
/**
|
|
1774
|
+
* @param {T} chunk
|
|
1775
|
+
* @returns {Promise<void>}
|
|
1776
|
+
*/
|
|
1777
|
+
write(chunk) {
|
|
1778
|
+
chunkQueue.push(chunk);
|
|
1779
|
+
const drainer2 = makeDrainer();
|
|
1780
|
+
outWaitResolver();
|
|
1781
|
+
return drainer2;
|
|
1782
|
+
},
|
|
1783
|
+
async end() {
|
|
1784
|
+
ended = true;
|
|
1785
|
+
const drainer2 = makeDrainer();
|
|
1786
|
+
outWaitResolver();
|
|
1787
|
+
await drainer2;
|
|
1788
|
+
}
|
|
1789
|
+
};
|
|
1790
|
+
const iterator = {
|
|
1791
|
+
/** @returns {Promise<IteratorResult<T>>} */
|
|
1792
|
+
async next() {
|
|
1793
|
+
const chunk = chunkQueue.shift();
|
|
1794
|
+
if (chunk) {
|
|
1795
|
+
if (chunkQueue.length === 0) {
|
|
1796
|
+
drainerResolver();
|
|
1797
|
+
}
|
|
1798
|
+
return { done: false, value: chunk };
|
|
1799
|
+
}
|
|
1800
|
+
if (ended) {
|
|
1801
|
+
drainerResolver();
|
|
1802
|
+
return { done: true, value: void 0 };
|
|
1803
|
+
}
|
|
1804
|
+
if (!outWait) {
|
|
1805
|
+
outWait = new Promise((resolve) => {
|
|
1806
|
+
outWaitResolver = () => {
|
|
1807
|
+
outWait = null;
|
|
1808
|
+
outWaitResolver = noop;
|
|
1809
|
+
return resolve(iterator.next());
|
|
1810
|
+
};
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1813
|
+
return outWait;
|
|
1814
|
+
}
|
|
1815
|
+
};
|
|
1816
|
+
return { writer, iterator };
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
// ../../../node_modules/.pnpm/@ipld+car@5.2.6/node_modules/@ipld/car/src/writer-browser.js
|
|
1820
|
+
var CarWriter = class _CarWriter {
|
|
1821
|
+
/**
|
|
1822
|
+
* @param {CID[]} roots
|
|
1823
|
+
* @param {CarEncoder} encoder
|
|
1824
|
+
*/
|
|
1825
|
+
constructor(roots, encoder) {
|
|
1826
|
+
this._encoder = encoder;
|
|
1827
|
+
this._mutex = encoder.setRoots(roots);
|
|
1828
|
+
this._ended = false;
|
|
1829
|
+
}
|
|
1830
|
+
/**
|
|
1831
|
+
* Write a `Block` (a `{ cid:CID, bytes:Uint8Array }` pair) to the archive.
|
|
1832
|
+
*
|
|
1833
|
+
* @function
|
|
1834
|
+
* @memberof CarWriter
|
|
1835
|
+
* @instance
|
|
1836
|
+
* @async
|
|
1837
|
+
* @param {Block} block - A `{ cid:CID, bytes:Uint8Array }` pair.
|
|
1838
|
+
* @returns {Promise<void>} The returned promise will only resolve once the
|
|
1839
|
+
* bytes this block generates are written to the `out` iterable.
|
|
1840
|
+
*/
|
|
1841
|
+
async put(block) {
|
|
1842
|
+
if (!(block.bytes instanceof Uint8Array) || !block.cid) {
|
|
1843
|
+
throw new TypeError("Can only write {cid, bytes} objects");
|
|
1844
|
+
}
|
|
1845
|
+
if (this._ended) {
|
|
1846
|
+
throw new Error("Already closed");
|
|
1847
|
+
}
|
|
1848
|
+
const cid = CID.asCID(block.cid);
|
|
1849
|
+
if (!cid) {
|
|
1850
|
+
throw new TypeError("Can only write {cid, bytes} objects");
|
|
1851
|
+
}
|
|
1852
|
+
this._mutex = this._mutex.then(() => this._encoder.writeBlock({ cid, bytes: block.bytes }));
|
|
1853
|
+
return this._mutex;
|
|
1854
|
+
}
|
|
1855
|
+
/**
|
|
1856
|
+
* Finalise the CAR archive and signal that the `out` iterable should end once
|
|
1857
|
+
* any remaining bytes are written.
|
|
1858
|
+
*
|
|
1859
|
+
* @function
|
|
1860
|
+
* @memberof CarWriter
|
|
1861
|
+
* @instance
|
|
1862
|
+
* @async
|
|
1863
|
+
* @returns {Promise<void>}
|
|
1864
|
+
*/
|
|
1865
|
+
async close() {
|
|
1866
|
+
if (this._ended) {
|
|
1867
|
+
throw new Error("Already closed");
|
|
1868
|
+
}
|
|
1869
|
+
await this._mutex;
|
|
1870
|
+
this._ended = true;
|
|
1871
|
+
return this._encoder.close();
|
|
1872
|
+
}
|
|
1873
|
+
/**
|
|
1874
|
+
* Create a new CAR writer "channel" which consists of a
|
|
1875
|
+
* `{ writer:CarWriter, out:AsyncIterable<Uint8Array> }` pair.
|
|
1876
|
+
*
|
|
1877
|
+
* @async
|
|
1878
|
+
* @static
|
|
1879
|
+
* @memberof CarWriter
|
|
1880
|
+
* @param {CID[] | CID | void} roots
|
|
1881
|
+
* @returns {WriterChannel} The channel takes the form of
|
|
1882
|
+
* `{ writer:CarWriter, out:AsyncIterable<Uint8Array> }`.
|
|
1883
|
+
*/
|
|
1884
|
+
static create(roots) {
|
|
1885
|
+
roots = toRoots(roots);
|
|
1886
|
+
const { encoder, iterator } = encodeWriter();
|
|
1887
|
+
const writer = new _CarWriter(roots, encoder);
|
|
1888
|
+
const out = new CarWriterOut(iterator);
|
|
1889
|
+
return { writer, out };
|
|
1890
|
+
}
|
|
1891
|
+
/**
|
|
1892
|
+
* Create a new CAR appender "channel" which consists of a
|
|
1893
|
+
* `{ writer:CarWriter, out:AsyncIterable<Uint8Array> }` pair.
|
|
1894
|
+
* This appender does not consider roots and does not produce a CAR header.
|
|
1895
|
+
* It is designed to append blocks to an _existing_ CAR archive. It is
|
|
1896
|
+
* expected that `out` will be concatenated onto the end of an existing
|
|
1897
|
+
* archive that already has a properly formatted header.
|
|
1898
|
+
*
|
|
1899
|
+
* @async
|
|
1900
|
+
* @static
|
|
1901
|
+
* @memberof CarWriter
|
|
1902
|
+
* @returns {WriterChannel} The channel takes the form of
|
|
1903
|
+
* `{ writer:CarWriter, out:AsyncIterable<Uint8Array> }`.
|
|
1904
|
+
*/
|
|
1905
|
+
static createAppender() {
|
|
1906
|
+
const { encoder, iterator } = encodeWriter();
|
|
1907
|
+
encoder.setRoots = () => Promise.resolve();
|
|
1908
|
+
const writer = new _CarWriter([], encoder);
|
|
1909
|
+
const out = new CarWriterOut(iterator);
|
|
1910
|
+
return { writer, out };
|
|
1911
|
+
}
|
|
1912
|
+
/**
|
|
1913
|
+
* Update the list of roots in the header of an existing CAR as represented
|
|
1914
|
+
* in a Uint8Array.
|
|
1915
|
+
*
|
|
1916
|
+
* This operation is an _overwrite_, the total length of the CAR will not be
|
|
1917
|
+
* modified. A rejection will occur if the new header will not be the same
|
|
1918
|
+
* length as the existing header, in which case the CAR will not be modified.
|
|
1919
|
+
* It is the responsibility of the user to ensure that the roots being
|
|
1920
|
+
* replaced encode as the same length as the new roots.
|
|
1921
|
+
*
|
|
1922
|
+
* The byte array passed in an argument will be modified and also returned
|
|
1923
|
+
* upon successful modification.
|
|
1924
|
+
*
|
|
1925
|
+
* @async
|
|
1926
|
+
* @static
|
|
1927
|
+
* @memberof CarWriter
|
|
1928
|
+
* @param {Uint8Array} bytes
|
|
1929
|
+
* @param {CID[]} roots - A new list of roots to replace the existing list in
|
|
1930
|
+
* the CAR header. The new header must take up the same number of bytes as the
|
|
1931
|
+
* existing header, so the roots should collectively be the same byte length
|
|
1932
|
+
* as the existing roots.
|
|
1933
|
+
* @returns {Promise<Uint8Array>}
|
|
1934
|
+
*/
|
|
1935
|
+
static async updateRootsInBytes(bytes, roots) {
|
|
1936
|
+
const reader = bytesReader(bytes);
|
|
1937
|
+
await readHeader(reader);
|
|
1938
|
+
const newHeader = createHeader(roots);
|
|
1939
|
+
if (Number(reader.pos) !== newHeader.length) {
|
|
1940
|
+
throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${reader.pos} bytes, new header is ${newHeader.length} bytes)`);
|
|
1941
|
+
}
|
|
1942
|
+
bytes.set(newHeader, 0);
|
|
1943
|
+
return bytes;
|
|
1944
|
+
}
|
|
1945
|
+
};
|
|
1946
|
+
var CarWriterOut = class {
|
|
1947
|
+
/**
|
|
1948
|
+
* @param {AsyncIterator<Uint8Array>} iterator
|
|
1949
|
+
*/
|
|
1950
|
+
constructor(iterator) {
|
|
1951
|
+
this._iterator = iterator;
|
|
1952
|
+
}
|
|
1953
|
+
[Symbol.asyncIterator]() {
|
|
1954
|
+
if (this._iterating) {
|
|
1955
|
+
throw new Error("Multiple iterator not supported");
|
|
1956
|
+
}
|
|
1957
|
+
this._iterating = true;
|
|
1958
|
+
return this._iterator;
|
|
1959
|
+
}
|
|
1960
|
+
};
|
|
1961
|
+
function encodeWriter() {
|
|
1962
|
+
const iw = create2();
|
|
1963
|
+
const { writer, iterator } = iw;
|
|
1964
|
+
const encoder = createEncoder(writer);
|
|
1965
|
+
return { encoder, iterator };
|
|
1966
|
+
}
|
|
1967
|
+
function toRoots(roots) {
|
|
1968
|
+
if (roots === void 0) {
|
|
1969
|
+
return [];
|
|
1970
|
+
}
|
|
1971
|
+
if (!Array.isArray(roots)) {
|
|
1972
|
+
const cid = CID.asCID(roots);
|
|
1973
|
+
if (!cid) {
|
|
1974
|
+
throw new TypeError("roots must be a single CID or an array of CIDs");
|
|
1975
|
+
}
|
|
1976
|
+
return [cid];
|
|
1977
|
+
}
|
|
1978
|
+
const _roots = [];
|
|
1979
|
+
for (const root of roots) {
|
|
1980
|
+
const _root = CID.asCID(root);
|
|
1981
|
+
if (!_root) {
|
|
1982
|
+
throw new TypeError("roots must be a single CID or an array of CIDs");
|
|
1983
|
+
}
|
|
1984
|
+
_roots.push(_root);
|
|
1985
|
+
}
|
|
1986
|
+
return _roots;
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
// src/ipfs/car.ts
|
|
1990
|
+
var { WARN, LOG, DEBUG, VERBOSE, ERROR } = E.setup(E.INFO);
|
|
1991
|
+
async function decodePubFromCar(car) {
|
|
1992
|
+
const decoded = await getBlocksOfCar(car);
|
|
1993
|
+
return await decodePubFromBlocks(decoded);
|
|
1994
|
+
}
|
|
1995
|
+
async function decodePubFromBlocks({ rootCID, blockStore }, recursionTrace = []) {
|
|
1996
|
+
if (!rootCID || !blockStore) {
|
|
1997
|
+
throw ERROR("Empty roots/blocks", { rootCID, blockStore });
|
|
1998
|
+
}
|
|
1999
|
+
const root = await getDecodedBlock(blockStore, rootCID);
|
|
2000
|
+
let pubLogsArray;
|
|
2001
|
+
let applogsCID = null;
|
|
2002
|
+
let info = null;
|
|
2003
|
+
VERBOSE(`[decodePubFromBlocks] root:`, rootCID.toString(), root, { blockStore });
|
|
2004
|
+
if (!root)
|
|
2005
|
+
throw ERROR("root not found in blockStore", { blockStore, rootCID });
|
|
2006
|
+
if (root?.info) {
|
|
2007
|
+
applogsCID = root.applogs;
|
|
2008
|
+
const applogsBlock = await getDecodedBlock(blockStore, applogsCID);
|
|
2009
|
+
pubLogsArray = await unchunkApplogsBlock(applogsBlock, blockStore);
|
|
2010
|
+
info = await getDecodedBlock(blockStore, root.info);
|
|
2011
|
+
DEBUG(`new format - infoLogs`, info.logs.map((l) => ({ [l.toString()]: l })));
|
|
2012
|
+
} else {
|
|
2013
|
+
pubLogsArray = root.applogs;
|
|
2014
|
+
}
|
|
2015
|
+
const resolveLogFromCidLink = async (cidOrLink) => {
|
|
2016
|
+
const cid = cidOrLink;
|
|
2017
|
+
const applog = await getDecodedBlock(blockStore, cid);
|
|
2018
|
+
if (!applog) {
|
|
2019
|
+
ERROR(`Could not find applog CID in pub blocks:`, cid.toString(), { cid, root, blockStore });
|
|
2020
|
+
throw new Error(`Could not find applog CID in pub blocks: ${cid.toString()}`);
|
|
2021
|
+
}
|
|
2022
|
+
if (applog.pv instanceof CID)
|
|
2023
|
+
applog.pv = applog.pv.toV1().toString();
|
|
2024
|
+
return {
|
|
2025
|
+
...applog,
|
|
2026
|
+
cid: cid.toV1().toString()
|
|
2027
|
+
};
|
|
2028
|
+
};
|
|
2029
|
+
let applogs;
|
|
2030
|
+
applogs = await Promise.all(pubLogsArray.map(resolveLogFromCidLink));
|
|
2031
|
+
if (root.prev) {
|
|
2032
|
+
if (areCidsEqual(root.prev, rootCID) || containsCid(recursionTrace, root.prev)) {
|
|
2033
|
+
throw ERROR(`[pubFromBlocks] pub chain has a loop`, { rootCID, prev: root.prev, recursionTrace });
|
|
2034
|
+
}
|
|
2035
|
+
applogs.push(...(await decodePubFromBlocks({ rootCID: root.prev, blockStore }, [...recursionTrace, rootCID])).applogs);
|
|
2036
|
+
}
|
|
2037
|
+
const result = {
|
|
2038
|
+
cid: rootCID,
|
|
2039
|
+
info: {
|
|
2040
|
+
...info,
|
|
2041
|
+
logs: await Promise.all(info.logs.map(resolveLogFromCidLink))
|
|
2042
|
+
},
|
|
2043
|
+
applogsCID,
|
|
2044
|
+
applogs
|
|
2045
|
+
};
|
|
2046
|
+
DEBUG("[decodePubFromBlocks] result:", result, { rootCID: rootCID.toString(), root, blockStore, applogs, info });
|
|
2047
|
+
return result;
|
|
2048
|
+
}
|
|
2049
|
+
async function getBlocksOfCar(car) {
|
|
2050
|
+
const rootsFromCar = await car.getRoots();
|
|
2051
|
+
const roots = rootsFromCar.map((c) => (typeof c.toV1 === "function" ? c : CID.decode(c.bytes)).toV1().toString());
|
|
2052
|
+
const blocks = /* @__PURE__ */ new Map();
|
|
2053
|
+
for await (const { cid: cidFromCarblocks, bytes } of car.blocks()) {
|
|
2054
|
+
const cid = typeof cidFromCarblocks.toV1 === "function" ? cidFromCarblocks : CID.decode(cidFromCarblocks.bytes);
|
|
2055
|
+
VERBOSE({ cidFromCarblocks, cid });
|
|
2056
|
+
blocks.set(cid.toV1().toString(), bytes);
|
|
2057
|
+
}
|
|
2058
|
+
if (roots.length !== 1) {
|
|
2059
|
+
WARN("Unexpected roots count:", roots);
|
|
2060
|
+
}
|
|
2061
|
+
return {
|
|
2062
|
+
rootCID: CID.parse(roots[0]),
|
|
2063
|
+
blockStore: {
|
|
2064
|
+
get: (cid) => blocks.get(cid.toV1().toString())
|
|
2065
|
+
}
|
|
2066
|
+
};
|
|
2067
|
+
}
|
|
2068
|
+
async function getDecodedBlock(blockStore, cid) {
|
|
2069
|
+
try {
|
|
2070
|
+
var blob = await blockStore.get(cid);
|
|
2071
|
+
if (!blob) {
|
|
2072
|
+
WARN("returning null");
|
|
2073
|
+
return null;
|
|
2074
|
+
}
|
|
2075
|
+
} catch (err) {
|
|
2076
|
+
if (err.message === "Not Found")
|
|
2077
|
+
return null;
|
|
2078
|
+
throw err;
|
|
2079
|
+
}
|
|
2080
|
+
return decode3(blob);
|
|
2081
|
+
}
|
|
2082
|
+
async function makeCarOut(roots, blocks) {
|
|
2083
|
+
const { writer, out } = CarWriter.create(Array.isArray(roots) ? roots : [roots]);
|
|
2084
|
+
VERBOSE(`Writing ${blocks.length} blocks to CAR`, { roots, blocks });
|
|
2085
|
+
blocks.forEach((b) => writer.put(b));
|
|
2086
|
+
writer.close();
|
|
2087
|
+
return out;
|
|
2088
|
+
}
|
|
2089
|
+
async function makeCarBlob(roots, blocks) {
|
|
2090
|
+
const carOut = await makeCarOut(roots, blocks);
|
|
2091
|
+
const chunks = [];
|
|
2092
|
+
for await (const chunk of carOut) {
|
|
2093
|
+
chunks.push(chunk);
|
|
2094
|
+
}
|
|
2095
|
+
const blob = new Blob(chunks);
|
|
2096
|
+
return blob;
|
|
2097
|
+
}
|
|
2098
|
+
async function carFromBlob(blob) {
|
|
2099
|
+
return CarReader.fromBytes(new Uint8Array(await blob.arrayBuffer()));
|
|
2100
|
+
}
|
|
2101
|
+
function streamReaderToIterable(bodyReader) {
|
|
2102
|
+
return async function* () {
|
|
2103
|
+
while (true) {
|
|
2104
|
+
const { done, value } = await bodyReader.read();
|
|
2105
|
+
VERBOSE(`[car] chunk`, { done, value });
|
|
2106
|
+
if (done) {
|
|
2107
|
+
break;
|
|
2108
|
+
}
|
|
2109
|
+
yield value;
|
|
2110
|
+
}
|
|
2111
|
+
}();
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2114
|
+
// src/pubsub/pub-push.ts
|
|
2115
|
+
var { WARN: WARN2, LOG: LOG2, DEBUG: DEBUG2, VERBOSE: VERBOSE2, ERROR: ERROR2 } = E.setup(E.INFO);
|
|
2116
|
+
async function preparePubForPush(agent, appThread, threadToPublish, publication, prevPubCID) {
|
|
2117
|
+
let logsToPublish = getLogsFromThread(threadToPublish);
|
|
2118
|
+
DEBUG2(`[preparePubForPush] Collected ${logsToPublish.length} logs :`, {
|
|
2119
|
+
logsToPublish,
|
|
2120
|
+
threadOrLogsCount: threadToPublish.nameAndSizeUntracked || `[${threadToPublish.length}]`
|
|
2121
|
+
});
|
|
2122
|
+
const { sharedAgents, sharedKeyMap, sharedKey, pubCounter } = publication ?? {};
|
|
2123
|
+
const getExistingOrNewLog = (thread, publication2, ag, at, vl) => {
|
|
2124
|
+
let logInQuestion = rollingFilter(lastWriteWins(thread), { en: publication2.id, at }).latestLog;
|
|
2125
|
+
if (!logInQuestion && vl !== void 0) {
|
|
2126
|
+
logInQuestion = ensureTsPvAndFinalizeApplog({ ag, en: publication2.id, at, vl }, thread);
|
|
2127
|
+
}
|
|
2128
|
+
return logInQuestion;
|
|
2129
|
+
};
|
|
2130
|
+
const pubNameLog = getExistingOrNewLog(appThread, publication, agent.ag, "pub/name", publication.name);
|
|
2131
|
+
const pubCounterLog = getExistingOrNewLog(appThread, publication, agent.ag, "pub/counter", `${agent.did}<::>${pubCounter}`);
|
|
2132
|
+
const encryptApplog = async (applog, keyToUse) => {
|
|
2133
|
+
const { log: eachLog, cid } = prepareForPub(applog);
|
|
2134
|
+
const enc = new TextEncoder();
|
|
2135
|
+
const stringified = wrapper_default(eachLog);
|
|
2136
|
+
const stringifiedEncodedAppLogPayload = enc.encode(stringified);
|
|
2137
|
+
VERBOSE2("[odd]", { eachLog, stringified, stringifiedEncodedAppLogPayload });
|
|
2138
|
+
try {
|
|
2139
|
+
const encPayload = await agent.crypto?.aes.encrypt(stringifiedEncodedAppLogPayload, keyToUse, "AES-GCM");
|
|
2140
|
+
VERBOSE2("[odd] encrypted length:", stringifiedEncodedAppLogPayload.length, { encPayload });
|
|
2141
|
+
return encPayload;
|
|
2142
|
+
} catch (err) {
|
|
2143
|
+
throw ERROR2("FAILED TO ENC payload length:", stringifiedEncodedAppLogPayload.length, { err });
|
|
2144
|
+
}
|
|
2145
|
+
};
|
|
2146
|
+
let maybeEncryptedApplogs;
|
|
2147
|
+
const encryptedApplogs = [];
|
|
2148
|
+
const agentSharedKeyLogs = [];
|
|
2149
|
+
if (sharedAgents) {
|
|
2150
|
+
if (!sharedKey || !sharedKeyMap) {
|
|
2151
|
+
throw ERROR2("sharedAgents but no Keys/Map", { sharedAgents, sharedKeyMap, sharedKey });
|
|
2152
|
+
}
|
|
2153
|
+
VERBOSE2("encrypting", { sharedAgents, sharedKeyMap });
|
|
2154
|
+
for (const [eachAgent, eachEncKey] of Array.from(sharedKeyMap.entries())) {
|
|
2155
|
+
VERBOSE2.force("adding key", { eachAgent, eachEncKey });
|
|
2156
|
+
agentSharedKeyLogs.push({
|
|
2157
|
+
ag: agent.ag,
|
|
2158
|
+
en: eachAgent,
|
|
2159
|
+
at: "pub/sharedKey",
|
|
2160
|
+
vl: eachEncKey
|
|
2161
|
+
// these are encrypted with the derived key from the local agent private and remote agent public keys
|
|
2162
|
+
});
|
|
2163
|
+
}
|
|
2164
|
+
const CIDlist = [];
|
|
2165
|
+
const pubCIDmap = {};
|
|
2166
|
+
for (const eachLog of logsToPublish) {
|
|
2167
|
+
VERBOSE2.force("[crypto] encrypting ", { eachLog, sharedKey });
|
|
2168
|
+
const encPayload = await encryptApplog(eachLog, sharedKey);
|
|
2169
|
+
DEBUG2.force("[crypto] encrypted ", { eachLog, encPayload, sharedKey });
|
|
2170
|
+
encryptedApplogs.push({ enc: encPayload });
|
|
2171
|
+
}
|
|
2172
|
+
maybeEncryptedApplogs = encryptedApplogs;
|
|
2173
|
+
} else {
|
|
2174
|
+
maybeEncryptedApplogs = logsToPublish;
|
|
2175
|
+
}
|
|
2176
|
+
DEBUG2("adding all agent info and pubAtoms", {
|
|
2177
|
+
publication,
|
|
2178
|
+
agent,
|
|
2179
|
+
logsToPublish,
|
|
2180
|
+
// threadToPublish, - very verbose
|
|
2181
|
+
agentSharedKeyLogs
|
|
2182
|
+
});
|
|
2183
|
+
const infoLogs = [
|
|
2184
|
+
...rollingFilter(lastWriteWins(appThread), {
|
|
2185
|
+
// TODO: use static filter for performance
|
|
2186
|
+
en: agent.ag,
|
|
2187
|
+
at: ["agent/ecdh", "agent/jwkd", "agent/appAgent"]
|
|
2188
|
+
}).applogs,
|
|
2189
|
+
...pubNameLog ? [pubNameLog] : [],
|
|
2190
|
+
...pubCounterLog ? [pubCounterLog] : [],
|
|
2191
|
+
...agentSharedKeyLogs
|
|
2192
|
+
];
|
|
2193
|
+
DEBUG2(`[preparePubForPush] info logs:`, infoLogs);
|
|
2194
|
+
if (!infoLogs.find(({ at }) => at === "agent/appAgent"))
|
|
2195
|
+
throw ERROR2(`[preparePubForPush] appThread missing agent/appAgent log`);
|
|
2196
|
+
const applogsToEncode = keepTruthy(maybeEncryptedApplogs);
|
|
2197
|
+
const infologsToEncode = keepTruthy(infoLogs);
|
|
2198
|
+
if (!applogsToEncode.length) {
|
|
2199
|
+
throw ERROR2("no valid applogs", { agent, maybeEncryptedApplogs, infoLogs, applogsToEncode, infologsToEncode, prevPubCID });
|
|
2200
|
+
}
|
|
2201
|
+
if (!infologsToEncode.length) {
|
|
2202
|
+
throw ERROR2("no valid infologs", { agent, maybeEncryptedApplogs, infoLogs, applogsToEncode, infologsToEncode, prevPubCID });
|
|
2203
|
+
}
|
|
2204
|
+
const encodedPub = await encodePubAsCar(agent, applogsToEncode, infologsToEncode, prevPubCID);
|
|
2205
|
+
DEBUG2("inPreparePubForPush", { encodedPub });
|
|
2206
|
+
return encodedPub;
|
|
2207
|
+
}
|
|
2208
|
+
async function encodePubAsCar(agent, applogs, infoLogs, prevPubCID) {
|
|
2209
|
+
DEBUG2(`[encodePubAsCar] encoding`, { agent, applogs, infoLogs });
|
|
2210
|
+
const { cids: infoLogCids, encodedApplogs: encodedInfoLogs } = await encodeApplogsAsIPLD(infoLogs);
|
|
2211
|
+
const { cids: applogCids, encodedApplogs } = await encodeApplogsAsIPLD(applogs);
|
|
2212
|
+
const blocks = [...encodedApplogs, ...encodedInfoLogs];
|
|
2213
|
+
const infoLogsWrap = await encodeBlockOriginal({ logs: infoLogCids });
|
|
2214
|
+
blocks.push(infoLogsWrap);
|
|
2215
|
+
const { rootCID: chunkRootCID, blocks: chunkBlocks } = await chunkApplogs(applogCids);
|
|
2216
|
+
blocks.push(...chunkBlocks);
|
|
2217
|
+
const infoSignature = await agent.sign(infoLogsWrap.cid.bytes);
|
|
2218
|
+
const applogsSignature = await agent.sign(chunkRootCID.bytes);
|
|
2219
|
+
const root = {
|
|
2220
|
+
info: infoLogsWrap.cid,
|
|
2221
|
+
applogs: chunkRootCID,
|
|
2222
|
+
infoSignature,
|
|
2223
|
+
applogsSignature,
|
|
2224
|
+
prev: prevPubCID
|
|
2225
|
+
};
|
|
2226
|
+
DEBUG2("[encodePubAsCar] encoding root", { root, logCids: applogCids, infoLogCids });
|
|
2227
|
+
const encodedRoot = await encodeBlockOriginal(root);
|
|
2228
|
+
blocks.push(encodedRoot);
|
|
2229
|
+
DEBUG2("[encodePubAsCar] => root", { encodedRoot });
|
|
2230
|
+
return {
|
|
2231
|
+
cid: encodedRoot.cid,
|
|
2232
|
+
blob: await makeCarBlob(encodedRoot.cid, blocks),
|
|
2233
|
+
// TODO: create CarBuilder (incl .encodeAndAdd({...}))
|
|
2234
|
+
blocks,
|
|
2235
|
+
infoLogCids,
|
|
2236
|
+
applogCids
|
|
2237
|
+
};
|
|
2238
|
+
}
|
|
2239
|
+
async function chunkApplogs(applogCids, size = 1e4) {
|
|
2240
|
+
if (!applogCids.length)
|
|
2241
|
+
throw ERROR2(`[chunkApplogs] called with empty array`);
|
|
2242
|
+
const chunks = [];
|
|
2243
|
+
for (let i = 0; i < applogCids.length; i += size) {
|
|
2244
|
+
const chunk = await encodeBlockOriginal({ logs: applogCids.slice(i, Math.min(i + applogCids.length, i + size)) });
|
|
2245
|
+
chunks.push(chunk);
|
|
2246
|
+
}
|
|
2247
|
+
if (chunks.length === 1)
|
|
2248
|
+
return { rootCID: chunks[0].cid, blocks: chunks };
|
|
2249
|
+
const root = await encodeBlockOriginal({ chunks: chunks.map((chunk) => chunk.cid) });
|
|
2250
|
+
const blocks = [root, ...chunks];
|
|
2251
|
+
DEBUG2(`[chunkApplogs] ${applogCids.length} logs chunked into ${chunks.length}`, { applogCids, root, blocks, chunks, dagJson: src_exports });
|
|
2252
|
+
return { rootCID: root.cid, blocks, chunks };
|
|
2253
|
+
}
|
|
2254
|
+
async function unchunkApplogsBlock(block, blockStore) {
|
|
2255
|
+
if (isPubBlockChunks(block)) {
|
|
2256
|
+
return (await Promise.all(
|
|
2257
|
+
block.chunks.map(async (chunkCid) => {
|
|
2258
|
+
const block2 = await getDecodedBlock(blockStore, chunkCid);
|
|
2259
|
+
if (!block2.logs)
|
|
2260
|
+
throw ERROR2(`Weird chunk`, block2);
|
|
2261
|
+
return block2.logs;
|
|
2262
|
+
})
|
|
2263
|
+
)).flat();
|
|
2264
|
+
} else {
|
|
2265
|
+
return block.logs;
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
function isPubBlockChunks(block) {
|
|
2269
|
+
return block.chunks;
|
|
2270
|
+
}
|
|
2271
|
+
async function encodeApplogsAsCar(applogs) {
|
|
2272
|
+
const encoded = await encodeApplogsAsIPLD(applogs);
|
|
2273
|
+
if (!encoded)
|
|
2274
|
+
throw ERROR2("invalid applogs cannot continue", { applogs, encoded });
|
|
2275
|
+
const { cids, encodedApplogs } = encoded;
|
|
2276
|
+
const root = { applogs: cids };
|
|
2277
|
+
const encodedRoot = await encodeBlockOriginal(root);
|
|
2278
|
+
DEBUG2("[encodeApplogsAsCar] encoded root", { cids, encodedRoot });
|
|
2279
|
+
return await makeCarBlob(encodedRoot.cid, [encodedRoot, ...encodedApplogs]);
|
|
2280
|
+
}
|
|
2281
|
+
async function encodeApplogsAsIPLD(applogs) {
|
|
2282
|
+
DEBUG2.force({ applogs });
|
|
2283
|
+
const validApplogs = applogs.filter((eachLog) => !!eachLog);
|
|
2284
|
+
DEBUG2.force({ validApplogs });
|
|
2285
|
+
if (!validApplogs.length)
|
|
2286
|
+
throw ERROR2("no valid applogs");
|
|
2287
|
+
const preppedLogs = validApplogs.map((log) => prepareForPub(log).log);
|
|
2288
|
+
const encodedApplogs = await Promise.all(preppedLogs.map(encodeBlockOriginal));
|
|
2289
|
+
DEBUG2.force("[encodeApplogsAsIpld] encoded applogs", { preppedLogs, encodedApplogs });
|
|
2290
|
+
const cids = encodedApplogs.map((b) => {
|
|
2291
|
+
if (!b.cid)
|
|
2292
|
+
throw ERROR2(`[publish] no cid for encoded log:`, b);
|
|
2293
|
+
return b.cid;
|
|
2294
|
+
});
|
|
2295
|
+
return { cids, encodedApplogs };
|
|
2296
|
+
}
|
|
2297
|
+
|
|
2298
|
+
export {
|
|
2299
|
+
preparePubForPush,
|
|
2300
|
+
encodePubAsCar,
|
|
2301
|
+
chunkApplogs,
|
|
2302
|
+
unchunkApplogsBlock,
|
|
2303
|
+
isPubBlockChunks,
|
|
2304
|
+
encodeApplogsAsCar,
|
|
2305
|
+
decodePubFromCar,
|
|
2306
|
+
decodePubFromBlocks,
|
|
2307
|
+
getBlocksOfCar,
|
|
2308
|
+
getDecodedBlock,
|
|
2309
|
+
makeCarOut,
|
|
2310
|
+
makeCarBlob,
|
|
2311
|
+
carFromBlob,
|
|
2312
|
+
streamReaderToIterable
|
|
2313
|
+
};
|
|
2314
|
+
//# sourceMappingURL=chunk-C75X52ZX.min.js.map
|