@pkcprotocol/pkc-js 0.0.61 → 0.0.63
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/dist/browser/clients/base-client-manager.js +1 -1
- package/dist/browser/clients/base-client-manager.js.map +1 -1
- package/dist/browser/community/community-client-manager.js +1 -1
- package/dist/browser/community/community-client-manager.js.map +1 -1
- package/dist/browser/generated-version.d.ts +1 -1
- package/dist/browser/generated-version.js +1 -1
- package/dist/browser/helia/helia-for-pkc.js +22 -0
- package/dist/browser/helia/helia-for-pkc.js.map +1 -1
- package/dist/browser/helia/util.js +10 -1
- package/dist/browser/helia/util.js.map +1 -1
- package/dist/browser/pkc/pkc.js +12 -6
- package/dist/browser/pkc/pkc.js.map +1 -1
- package/dist/browser/publications/comment/comment.js +1 -1
- package/dist/browser/publications/comment/comment.js.map +1 -1
- package/dist/browser/rpc/src/index.js +42 -3
- package/dist/browser/rpc/src/index.js.map +1 -1
- package/dist/browser/runtime/browser/util.d.ts +1 -1
- package/dist/browser/runtime/browser/util.js +4 -2
- package/dist/browser/runtime/browser/util.js.map +1 -1
- package/dist/browser/runtime/node/test/mock-http-router.d.ts +15 -0
- package/dist/browser/runtime/node/test/mock-http-router.js +80 -2
- package/dist/browser/runtime/node/test/mock-http-router.js.map +1 -1
- package/dist/browser/runtime/node/util.d.ts +1 -1
- package/dist/browser/runtime/node/util.js +4 -2
- package/dist/browser/runtime/node/util.js.map +1 -1
- package/dist/browser/schema/schema.js +1 -1
- package/dist/browser/schema/schema.js.map +1 -1
- package/dist/browser/types.d.ts +1 -1
- package/dist/browser/util.d.ts +2 -2
- package/dist/browser/util.js +6 -5
- package/dist/browser/util.js.map +1 -1
- package/dist/bundled/bundle-manifest.json +378 -319
- package/dist/bundled/chunks/chunk-2rV9d50f.js +35 -0
- package/dist/bundled/chunks/{helia-for-pkc-De6c8bno.js → helia-for-pkc-C6vMsrJ-.js} +15 -6
- package/dist/bundled/chunks/{local-community-Cjt9uNmf.js → local-community-BQmiwsV4.js} +4 -3
- package/dist/bundled/chunks/{local-community-BmuSx3YO.js → local-community-BoIoFZHk.js} +1 -1
- package/dist/bundled/chunks/{node-ChsjNuK-.js → node-G40jxRL2.js} +15 -11
- package/dist/bundled/chunks/{rpc-local-community-CShi3R2S.js → rpc-local-community-D4-NEPJb.js} +23 -20
- package/dist/bundled/chunks/{schema-9inbPhRV.js → schema-SPGmy_14.js} +12670 -27579
- package/dist/bundled/chunks/src-0J9-Tmgd.js +4147 -0
- package/dist/bundled/chunks/src-4u0f92eE.js +9899 -0
- package/dist/bundled/chunks/src-BOzgM7Fp.js +800 -0
- package/dist/bundled/chunks/src-CYIMjhjK.js +48 -0
- package/dist/bundled/chunks/{util-CTdPyu-3.js → util-CJ6nXIW9.js} +7 -2
- package/dist/bundled/index.js +1 -1
- package/dist/bundled/rpc/src/index.js +31 -8
- package/dist/node/clients/base-client-manager.js +1 -1
- package/dist/node/clients/base-client-manager.js.map +1 -1
- package/dist/node/community/community-client-manager.js +1 -1
- package/dist/node/community/community-client-manager.js.map +1 -1
- package/dist/node/generated-version.d.ts +1 -1
- package/dist/node/generated-version.js +1 -1
- package/dist/node/helia/helia-for-pkc.js +22 -0
- package/dist/node/helia/helia-for-pkc.js.map +1 -1
- package/dist/node/helia/util.js +10 -1
- package/dist/node/helia/util.js.map +1 -1
- package/dist/node/pkc/pkc.js +12 -6
- package/dist/node/pkc/pkc.js.map +1 -1
- package/dist/node/publications/comment/comment.js +1 -1
- package/dist/node/publications/comment/comment.js.map +1 -1
- package/dist/node/rpc/src/index.js +42 -3
- package/dist/node/rpc/src/index.js.map +1 -1
- package/dist/node/runtime/browser/util.d.ts +1 -1
- package/dist/node/runtime/browser/util.js +4 -2
- package/dist/node/runtime/browser/util.js.map +1 -1
- package/dist/node/runtime/node/test/mock-http-router.d.ts +15 -0
- package/dist/node/runtime/node/test/mock-http-router.js +80 -2
- package/dist/node/runtime/node/test/mock-http-router.js.map +1 -1
- package/dist/node/runtime/node/util.d.ts +1 -1
- package/dist/node/runtime/node/util.js +4 -2
- package/dist/node/runtime/node/util.js.map +1 -1
- package/dist/node/schema/schema.js +1 -1
- package/dist/node/schema/schema.js.map +1 -1
- package/dist/node/types.d.ts +1 -1
- package/dist/node/util.d.ts +2 -2
- package/dist/node/util.js +6 -5
- package/dist/node/util.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,800 @@
|
|
|
1
|
+
import { n as __exportAll } from "./chunk-2rV9d50f.js";
|
|
2
|
+
import { CID } from "multiformats/cid";
|
|
3
|
+
//#region node_modules/it-first/dist/src/index.js
|
|
4
|
+
/**
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*
|
|
7
|
+
* Return the first value in an (async)iterable
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
*
|
|
11
|
+
* ```javascript
|
|
12
|
+
* import first from 'it-first'
|
|
13
|
+
*
|
|
14
|
+
* // This can also be an iterator, generator, etc
|
|
15
|
+
* const values = [0, 1, 2, 3, 4]
|
|
16
|
+
*
|
|
17
|
+
* const res = first(values)
|
|
18
|
+
*
|
|
19
|
+
* console.info(res) // 0
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Async sources must be awaited:
|
|
23
|
+
*
|
|
24
|
+
* ```javascript
|
|
25
|
+
* import first from 'it-first'
|
|
26
|
+
*
|
|
27
|
+
* const values = async function * () {
|
|
28
|
+
* yield * [0, 1, 2, 3, 4]
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* const res = await first(values())
|
|
32
|
+
*
|
|
33
|
+
* console.info(res) // 0
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
function isAsyncIterable(thing) {
|
|
37
|
+
return thing[Symbol.asyncIterator] != null;
|
|
38
|
+
}
|
|
39
|
+
function first(source) {
|
|
40
|
+
if (isAsyncIterable(source)) return (async () => {
|
|
41
|
+
for await (const entry of source) return entry;
|
|
42
|
+
})();
|
|
43
|
+
for (const entry of source) return entry;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region node_modules/@ipld/dag-pb/src/pb-decode.js
|
|
47
|
+
const textDecoder = new TextDecoder();
|
|
48
|
+
/**
|
|
49
|
+
* @typedef {import('./interface.js').RawPBLink} RawPBLink
|
|
50
|
+
*/
|
|
51
|
+
/**
|
|
52
|
+
* @typedef {import('./interface.js').RawPBNode} RawPBNode
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* @param {Uint8Array} bytes
|
|
56
|
+
* @param {number} offset
|
|
57
|
+
* @returns {[number, number]}
|
|
58
|
+
*/
|
|
59
|
+
function decodeVarint(bytes, offset) {
|
|
60
|
+
let v = 0;
|
|
61
|
+
for (let shift = 0;; shift += 7) {
|
|
62
|
+
/* c8 ignore next 3 */
|
|
63
|
+
if (shift >= 64) throw new Error("protobuf: varint overflow");
|
|
64
|
+
/* c8 ignore next 3 */
|
|
65
|
+
if (offset >= bytes.length) throw new Error("protobuf: unexpected end of data");
|
|
66
|
+
const b = bytes[offset++];
|
|
67
|
+
v += shift < 28 ? (b & 127) << shift : (b & 127) * 2 ** shift;
|
|
68
|
+
if (b < 128) break;
|
|
69
|
+
}
|
|
70
|
+
return [v, offset];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* @param {Uint8Array} bytes
|
|
74
|
+
* @param {number} offset
|
|
75
|
+
* @returns {[Uint8Array, number]}
|
|
76
|
+
*/
|
|
77
|
+
function decodeBytes(bytes, offset) {
|
|
78
|
+
let byteLen;
|
|
79
|
+
[byteLen, offset] = decodeVarint(bytes, offset);
|
|
80
|
+
const postOffset = offset + byteLen;
|
|
81
|
+
/* c8 ignore next 3 */
|
|
82
|
+
if (byteLen < 0 || postOffset < 0) throw new Error("protobuf: invalid length");
|
|
83
|
+
/* c8 ignore next 3 */
|
|
84
|
+
if (postOffset > bytes.length) throw new Error("protobuf: unexpected end of data");
|
|
85
|
+
return [bytes.subarray(offset, postOffset), postOffset];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* @param {Uint8Array} bytes
|
|
89
|
+
* @param {number} index
|
|
90
|
+
* @returns {[number, number, number]}
|
|
91
|
+
*/
|
|
92
|
+
function decodeKey(bytes, index) {
|
|
93
|
+
let wire;
|
|
94
|
+
[wire, index] = decodeVarint(bytes, index);
|
|
95
|
+
return [
|
|
96
|
+
wire & 7,
|
|
97
|
+
wire >> 3,
|
|
98
|
+
index
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @param {Uint8Array} bytes
|
|
103
|
+
* @returns {RawPBLink}
|
|
104
|
+
*/
|
|
105
|
+
function decodeLink(bytes) {
|
|
106
|
+
/** @type {RawPBLink} */
|
|
107
|
+
const link = {};
|
|
108
|
+
const l = bytes.length;
|
|
109
|
+
let index = 0;
|
|
110
|
+
while (index < l) {
|
|
111
|
+
let wireType, fieldNum;
|
|
112
|
+
[wireType, fieldNum, index] = decodeKey(bytes, index);
|
|
113
|
+
if (fieldNum === 1) {
|
|
114
|
+
if (link.Hash) throw new Error("protobuf: (PBLink) duplicate Hash section");
|
|
115
|
+
if (wireType !== 2) throw new Error(`protobuf: (PBLink) wrong wireType (${wireType}) for Hash`);
|
|
116
|
+
if (link.Name !== void 0) throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");
|
|
117
|
+
if (link.Tsize !== void 0) throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");
|
|
118
|
+
[link.Hash, index] = decodeBytes(bytes, index);
|
|
119
|
+
} else if (fieldNum === 2) {
|
|
120
|
+
if (link.Name !== void 0) throw new Error("protobuf: (PBLink) duplicate Name section");
|
|
121
|
+
if (wireType !== 2) throw new Error(`protobuf: (PBLink) wrong wireType (${wireType}) for Name`);
|
|
122
|
+
if (link.Tsize !== void 0) throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");
|
|
123
|
+
let byts;
|
|
124
|
+
[byts, index] = decodeBytes(bytes, index);
|
|
125
|
+
link.Name = textDecoder.decode(byts);
|
|
126
|
+
} else if (fieldNum === 3) {
|
|
127
|
+
if (link.Tsize !== void 0) throw new Error("protobuf: (PBLink) duplicate Tsize section");
|
|
128
|
+
if (wireType !== 0) throw new Error(`protobuf: (PBLink) wrong wireType (${wireType}) for Tsize`);
|
|
129
|
+
[link.Tsize, index] = decodeVarint(bytes, index);
|
|
130
|
+
} else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${fieldNum}`);
|
|
131
|
+
}
|
|
132
|
+
/* c8 ignore next 3 */
|
|
133
|
+
if (index > l) throw new Error("protobuf: (PBLink) unexpected end of data");
|
|
134
|
+
return link;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* @param {Uint8Array} bytes
|
|
138
|
+
* @returns {RawPBNode}
|
|
139
|
+
*/
|
|
140
|
+
function decodeNode(bytes) {
|
|
141
|
+
const l = bytes.length;
|
|
142
|
+
let index = 0;
|
|
143
|
+
/** @type {RawPBLink[]|void} */
|
|
144
|
+
let links = void 0;
|
|
145
|
+
let linksBeforeData = false;
|
|
146
|
+
/** @type {Uint8Array|void} */
|
|
147
|
+
let data = void 0;
|
|
148
|
+
while (index < l) {
|
|
149
|
+
let wireType, fieldNum;
|
|
150
|
+
[wireType, fieldNum, index] = decodeKey(bytes, index);
|
|
151
|
+
if (wireType !== 2) throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${wireType}`);
|
|
152
|
+
if (fieldNum === 1) {
|
|
153
|
+
if (data) throw new Error("protobuf: (PBNode) duplicate Data section");
|
|
154
|
+
[data, index] = decodeBytes(bytes, index);
|
|
155
|
+
if (links) linksBeforeData = true;
|
|
156
|
+
} else if (fieldNum === 2) {
|
|
157
|
+
if (linksBeforeData) throw new Error("protobuf: (PBNode) duplicate Links section");
|
|
158
|
+
else if (!links) links = [];
|
|
159
|
+
let byts;
|
|
160
|
+
[byts, index] = decodeBytes(bytes, index);
|
|
161
|
+
links.push(decodeLink(byts));
|
|
162
|
+
} else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${fieldNum}`);
|
|
163
|
+
}
|
|
164
|
+
/* c8 ignore next 3 */
|
|
165
|
+
if (index > l) throw new Error("protobuf: (PBNode) unexpected end of data");
|
|
166
|
+
/** @type {RawPBNode} */
|
|
167
|
+
const node = {};
|
|
168
|
+
if (data) node.Data = data;
|
|
169
|
+
node.Links = links || [];
|
|
170
|
+
return node;
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region node_modules/@ipld/dag-pb/src/pb-encode.js
|
|
174
|
+
const textEncoder$1 = new TextEncoder();
|
|
175
|
+
const maxInt32 = 2 ** 32;
|
|
176
|
+
const maxUInt32 = 2 ** 31;
|
|
177
|
+
/**
|
|
178
|
+
* @typedef {import('./interface.js').RawPBLink} RawPBLink
|
|
179
|
+
*/
|
|
180
|
+
/**
|
|
181
|
+
* @typedef {import('./interface.js').RawPBNode} RawPBNode
|
|
182
|
+
*/
|
|
183
|
+
/**
|
|
184
|
+
* encodeLink() is passed a slice of the parent byte array that ends where this
|
|
185
|
+
* link needs to end, so it packs to the right-most part of the passed `bytes`
|
|
186
|
+
*
|
|
187
|
+
* @param {RawPBLink} link
|
|
188
|
+
* @param {Uint8Array} bytes
|
|
189
|
+
* @returns {number}
|
|
190
|
+
*/
|
|
191
|
+
function encodeLink(link, bytes) {
|
|
192
|
+
let i = bytes.length;
|
|
193
|
+
if (typeof link.Tsize === "number") {
|
|
194
|
+
if (link.Tsize < 0) throw new Error("Tsize cannot be negative");
|
|
195
|
+
if (!Number.isSafeInteger(link.Tsize)) throw new Error("Tsize too large for encoding");
|
|
196
|
+
i = encodeVarint(bytes, i, link.Tsize) - 1;
|
|
197
|
+
bytes[i] = 24;
|
|
198
|
+
}
|
|
199
|
+
if (typeof link.Name === "string") {
|
|
200
|
+
const nameBytes = textEncoder$1.encode(link.Name);
|
|
201
|
+
i -= nameBytes.length;
|
|
202
|
+
bytes.set(nameBytes, i);
|
|
203
|
+
i = encodeVarint(bytes, i, nameBytes.length) - 1;
|
|
204
|
+
bytes[i] = 18;
|
|
205
|
+
}
|
|
206
|
+
if (link.Hash) {
|
|
207
|
+
i -= link.Hash.length;
|
|
208
|
+
bytes.set(link.Hash, i);
|
|
209
|
+
i = encodeVarint(bytes, i, link.Hash.length) - 1;
|
|
210
|
+
bytes[i] = 10;
|
|
211
|
+
}
|
|
212
|
+
return bytes.length - i;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Encodes a PBNode into a new byte array of precisely the correct size
|
|
216
|
+
*
|
|
217
|
+
* @param {RawPBNode} node
|
|
218
|
+
* @returns {Uint8Array}
|
|
219
|
+
*/
|
|
220
|
+
function encodeNode(node) {
|
|
221
|
+
const size = sizeNode(node);
|
|
222
|
+
const bytes = new Uint8Array(size);
|
|
223
|
+
let i = size;
|
|
224
|
+
if (node.Data) {
|
|
225
|
+
i -= node.Data.length;
|
|
226
|
+
bytes.set(node.Data, i);
|
|
227
|
+
i = encodeVarint(bytes, i, node.Data.length) - 1;
|
|
228
|
+
bytes[i] = 10;
|
|
229
|
+
}
|
|
230
|
+
if (node.Links) for (let index = node.Links.length - 1; index >= 0; index--) {
|
|
231
|
+
const size = encodeLink(node.Links[index], bytes.subarray(0, i));
|
|
232
|
+
i -= size;
|
|
233
|
+
i = encodeVarint(bytes, i, size) - 1;
|
|
234
|
+
bytes[i] = 18;
|
|
235
|
+
}
|
|
236
|
+
return bytes;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* work out exactly how many bytes this link takes up
|
|
240
|
+
*
|
|
241
|
+
* @param {RawPBLink} link
|
|
242
|
+
* @returns
|
|
243
|
+
*/
|
|
244
|
+
function sizeLink(link) {
|
|
245
|
+
let n = 0;
|
|
246
|
+
if (link.Hash) {
|
|
247
|
+
const l = link.Hash.length;
|
|
248
|
+
n += 1 + l + sov(l);
|
|
249
|
+
}
|
|
250
|
+
if (typeof link.Name === "string") {
|
|
251
|
+
const l = textEncoder$1.encode(link.Name).length;
|
|
252
|
+
n += 1 + l + sov(l);
|
|
253
|
+
}
|
|
254
|
+
if (typeof link.Tsize === "number") n += 1 + sov(link.Tsize);
|
|
255
|
+
return n;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Work out exactly how many bytes this node takes up
|
|
259
|
+
*
|
|
260
|
+
* @param {RawPBNode} node
|
|
261
|
+
* @returns {number}
|
|
262
|
+
*/
|
|
263
|
+
function sizeNode(node) {
|
|
264
|
+
let n = 0;
|
|
265
|
+
if (node.Data) {
|
|
266
|
+
const l = node.Data.length;
|
|
267
|
+
n += 1 + l + sov(l);
|
|
268
|
+
}
|
|
269
|
+
if (node.Links) for (const link of node.Links) {
|
|
270
|
+
const l = sizeLink(link);
|
|
271
|
+
n += 1 + l + sov(l);
|
|
272
|
+
}
|
|
273
|
+
return n;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* @param {Uint8Array} bytes
|
|
277
|
+
* @param {number} offset
|
|
278
|
+
* @param {number} v
|
|
279
|
+
* @returns {number}
|
|
280
|
+
*/
|
|
281
|
+
function encodeVarint(bytes, offset, v) {
|
|
282
|
+
offset -= sov(v);
|
|
283
|
+
const base = offset;
|
|
284
|
+
while (v >= maxUInt32) {
|
|
285
|
+
bytes[offset++] = v & 127 | 128;
|
|
286
|
+
v /= 128;
|
|
287
|
+
}
|
|
288
|
+
while (v >= 128) {
|
|
289
|
+
bytes[offset++] = v & 127 | 128;
|
|
290
|
+
v >>>= 7;
|
|
291
|
+
}
|
|
292
|
+
bytes[offset] = v;
|
|
293
|
+
return base;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* size of varint
|
|
297
|
+
*
|
|
298
|
+
* @param {number} x
|
|
299
|
+
* @returns {number}
|
|
300
|
+
*/
|
|
301
|
+
function sov(x) {
|
|
302
|
+
if (x % 2 === 0) x++;
|
|
303
|
+
return Math.floor((len64(x) + 6) / 7);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* golang math/bits, how many bits does it take to represent this integer?
|
|
307
|
+
*
|
|
308
|
+
* @param {number} x
|
|
309
|
+
* @returns {number}
|
|
310
|
+
*/
|
|
311
|
+
function len64(x) {
|
|
312
|
+
let n = 0;
|
|
313
|
+
if (x >= maxInt32) {
|
|
314
|
+
x = Math.floor(x / maxInt32);
|
|
315
|
+
n = 32;
|
|
316
|
+
}
|
|
317
|
+
if (x >= 65536) {
|
|
318
|
+
x >>>= 16;
|
|
319
|
+
n += 16;
|
|
320
|
+
}
|
|
321
|
+
if (x >= 256) {
|
|
322
|
+
x >>>= 8;
|
|
323
|
+
n += 8;
|
|
324
|
+
}
|
|
325
|
+
return n + len8tab[x];
|
|
326
|
+
}
|
|
327
|
+
const len8tab = [
|
|
328
|
+
0,
|
|
329
|
+
1,
|
|
330
|
+
2,
|
|
331
|
+
2,
|
|
332
|
+
3,
|
|
333
|
+
3,
|
|
334
|
+
3,
|
|
335
|
+
3,
|
|
336
|
+
4,
|
|
337
|
+
4,
|
|
338
|
+
4,
|
|
339
|
+
4,
|
|
340
|
+
4,
|
|
341
|
+
4,
|
|
342
|
+
4,
|
|
343
|
+
4,
|
|
344
|
+
5,
|
|
345
|
+
5,
|
|
346
|
+
5,
|
|
347
|
+
5,
|
|
348
|
+
5,
|
|
349
|
+
5,
|
|
350
|
+
5,
|
|
351
|
+
5,
|
|
352
|
+
5,
|
|
353
|
+
5,
|
|
354
|
+
5,
|
|
355
|
+
5,
|
|
356
|
+
5,
|
|
357
|
+
5,
|
|
358
|
+
5,
|
|
359
|
+
5,
|
|
360
|
+
6,
|
|
361
|
+
6,
|
|
362
|
+
6,
|
|
363
|
+
6,
|
|
364
|
+
6,
|
|
365
|
+
6,
|
|
366
|
+
6,
|
|
367
|
+
6,
|
|
368
|
+
6,
|
|
369
|
+
6,
|
|
370
|
+
6,
|
|
371
|
+
6,
|
|
372
|
+
6,
|
|
373
|
+
6,
|
|
374
|
+
6,
|
|
375
|
+
6,
|
|
376
|
+
6,
|
|
377
|
+
6,
|
|
378
|
+
6,
|
|
379
|
+
6,
|
|
380
|
+
6,
|
|
381
|
+
6,
|
|
382
|
+
6,
|
|
383
|
+
6,
|
|
384
|
+
6,
|
|
385
|
+
6,
|
|
386
|
+
6,
|
|
387
|
+
6,
|
|
388
|
+
6,
|
|
389
|
+
6,
|
|
390
|
+
6,
|
|
391
|
+
6,
|
|
392
|
+
7,
|
|
393
|
+
7,
|
|
394
|
+
7,
|
|
395
|
+
7,
|
|
396
|
+
7,
|
|
397
|
+
7,
|
|
398
|
+
7,
|
|
399
|
+
7,
|
|
400
|
+
7,
|
|
401
|
+
7,
|
|
402
|
+
7,
|
|
403
|
+
7,
|
|
404
|
+
7,
|
|
405
|
+
7,
|
|
406
|
+
7,
|
|
407
|
+
7,
|
|
408
|
+
7,
|
|
409
|
+
7,
|
|
410
|
+
7,
|
|
411
|
+
7,
|
|
412
|
+
7,
|
|
413
|
+
7,
|
|
414
|
+
7,
|
|
415
|
+
7,
|
|
416
|
+
7,
|
|
417
|
+
7,
|
|
418
|
+
7,
|
|
419
|
+
7,
|
|
420
|
+
7,
|
|
421
|
+
7,
|
|
422
|
+
7,
|
|
423
|
+
7,
|
|
424
|
+
7,
|
|
425
|
+
7,
|
|
426
|
+
7,
|
|
427
|
+
7,
|
|
428
|
+
7,
|
|
429
|
+
7,
|
|
430
|
+
7,
|
|
431
|
+
7,
|
|
432
|
+
7,
|
|
433
|
+
7,
|
|
434
|
+
7,
|
|
435
|
+
7,
|
|
436
|
+
7,
|
|
437
|
+
7,
|
|
438
|
+
7,
|
|
439
|
+
7,
|
|
440
|
+
7,
|
|
441
|
+
7,
|
|
442
|
+
7,
|
|
443
|
+
7,
|
|
444
|
+
7,
|
|
445
|
+
7,
|
|
446
|
+
7,
|
|
447
|
+
7,
|
|
448
|
+
7,
|
|
449
|
+
7,
|
|
450
|
+
7,
|
|
451
|
+
7,
|
|
452
|
+
7,
|
|
453
|
+
7,
|
|
454
|
+
7,
|
|
455
|
+
7,
|
|
456
|
+
8,
|
|
457
|
+
8,
|
|
458
|
+
8,
|
|
459
|
+
8,
|
|
460
|
+
8,
|
|
461
|
+
8,
|
|
462
|
+
8,
|
|
463
|
+
8,
|
|
464
|
+
8,
|
|
465
|
+
8,
|
|
466
|
+
8,
|
|
467
|
+
8,
|
|
468
|
+
8,
|
|
469
|
+
8,
|
|
470
|
+
8,
|
|
471
|
+
8,
|
|
472
|
+
8,
|
|
473
|
+
8,
|
|
474
|
+
8,
|
|
475
|
+
8,
|
|
476
|
+
8,
|
|
477
|
+
8,
|
|
478
|
+
8,
|
|
479
|
+
8,
|
|
480
|
+
8,
|
|
481
|
+
8,
|
|
482
|
+
8,
|
|
483
|
+
8,
|
|
484
|
+
8,
|
|
485
|
+
8,
|
|
486
|
+
8,
|
|
487
|
+
8,
|
|
488
|
+
8,
|
|
489
|
+
8,
|
|
490
|
+
8,
|
|
491
|
+
8,
|
|
492
|
+
8,
|
|
493
|
+
8,
|
|
494
|
+
8,
|
|
495
|
+
8,
|
|
496
|
+
8,
|
|
497
|
+
8,
|
|
498
|
+
8,
|
|
499
|
+
8,
|
|
500
|
+
8,
|
|
501
|
+
8,
|
|
502
|
+
8,
|
|
503
|
+
8,
|
|
504
|
+
8,
|
|
505
|
+
8,
|
|
506
|
+
8,
|
|
507
|
+
8,
|
|
508
|
+
8,
|
|
509
|
+
8,
|
|
510
|
+
8,
|
|
511
|
+
8,
|
|
512
|
+
8,
|
|
513
|
+
8,
|
|
514
|
+
8,
|
|
515
|
+
8,
|
|
516
|
+
8,
|
|
517
|
+
8,
|
|
518
|
+
8,
|
|
519
|
+
8,
|
|
520
|
+
8,
|
|
521
|
+
8,
|
|
522
|
+
8,
|
|
523
|
+
8,
|
|
524
|
+
8,
|
|
525
|
+
8,
|
|
526
|
+
8,
|
|
527
|
+
8,
|
|
528
|
+
8,
|
|
529
|
+
8,
|
|
530
|
+
8,
|
|
531
|
+
8,
|
|
532
|
+
8,
|
|
533
|
+
8,
|
|
534
|
+
8,
|
|
535
|
+
8,
|
|
536
|
+
8,
|
|
537
|
+
8,
|
|
538
|
+
8,
|
|
539
|
+
8,
|
|
540
|
+
8,
|
|
541
|
+
8,
|
|
542
|
+
8,
|
|
543
|
+
8,
|
|
544
|
+
8,
|
|
545
|
+
8,
|
|
546
|
+
8,
|
|
547
|
+
8,
|
|
548
|
+
8,
|
|
549
|
+
8,
|
|
550
|
+
8,
|
|
551
|
+
8,
|
|
552
|
+
8,
|
|
553
|
+
8,
|
|
554
|
+
8,
|
|
555
|
+
8,
|
|
556
|
+
8,
|
|
557
|
+
8,
|
|
558
|
+
8,
|
|
559
|
+
8,
|
|
560
|
+
8,
|
|
561
|
+
8,
|
|
562
|
+
8,
|
|
563
|
+
8,
|
|
564
|
+
8,
|
|
565
|
+
8,
|
|
566
|
+
8,
|
|
567
|
+
8,
|
|
568
|
+
8,
|
|
569
|
+
8,
|
|
570
|
+
8,
|
|
571
|
+
8,
|
|
572
|
+
8,
|
|
573
|
+
8,
|
|
574
|
+
8,
|
|
575
|
+
8,
|
|
576
|
+
8,
|
|
577
|
+
8,
|
|
578
|
+
8,
|
|
579
|
+
8,
|
|
580
|
+
8,
|
|
581
|
+
8,
|
|
582
|
+
8,
|
|
583
|
+
8
|
|
584
|
+
];
|
|
585
|
+
//#endregion
|
|
586
|
+
//#region node_modules/@ipld/dag-pb/src/util.js
|
|
587
|
+
/**
|
|
588
|
+
* @typedef {import('./interface.js').PBLink} PBLink
|
|
589
|
+
* @typedef {import('./interface.js').PBNode} PBNode
|
|
590
|
+
*/
|
|
591
|
+
/**
|
|
592
|
+
* @template T
|
|
593
|
+
* @typedef {import('multiformats/codecs/interface').ByteView<T>} ByteView
|
|
594
|
+
*/
|
|
595
|
+
/**
|
|
596
|
+
* @template T
|
|
597
|
+
* @typedef {import('multiformats/codecs/interface').ArrayBufferView<T>} ArrayBufferView
|
|
598
|
+
*/
|
|
599
|
+
const pbNodeProperties = ["Data", "Links"];
|
|
600
|
+
const pbLinkProperties = [
|
|
601
|
+
"Hash",
|
|
602
|
+
"Name",
|
|
603
|
+
"Tsize"
|
|
604
|
+
];
|
|
605
|
+
const textEncoder = new TextEncoder();
|
|
606
|
+
/**
|
|
607
|
+
* @param {PBLink} a
|
|
608
|
+
* @param {PBLink} b
|
|
609
|
+
* @returns {number}
|
|
610
|
+
*/
|
|
611
|
+
function linkComparator(a, b) {
|
|
612
|
+
if (a === b) return 0;
|
|
613
|
+
const abuf = a.Name ? textEncoder.encode(a.Name) : [];
|
|
614
|
+
const bbuf = b.Name ? textEncoder.encode(b.Name) : [];
|
|
615
|
+
let x = abuf.length;
|
|
616
|
+
let y = bbuf.length;
|
|
617
|
+
for (let i = 0, len = Math.min(x, y); i < len; ++i) if (abuf[i] !== bbuf[i]) {
|
|
618
|
+
x = abuf[i];
|
|
619
|
+
y = bbuf[i];
|
|
620
|
+
break;
|
|
621
|
+
}
|
|
622
|
+
return x < y ? -1 : y < x ? 1 : 0;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* @param {any} node
|
|
626
|
+
* @param {string[]} properties
|
|
627
|
+
* @returns {boolean}
|
|
628
|
+
*/
|
|
629
|
+
function hasOnlyProperties(node, properties) {
|
|
630
|
+
return !Object.keys(node).some((p) => !properties.includes(p));
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Converts a CID, or a PBLink-like object to a PBLink
|
|
634
|
+
*
|
|
635
|
+
* @param {any} link
|
|
636
|
+
* @returns {PBLink}
|
|
637
|
+
*/
|
|
638
|
+
function asLink(link) {
|
|
639
|
+
if (typeof link.asCID === "object") {
|
|
640
|
+
const Hash = CID.asCID(link);
|
|
641
|
+
if (!Hash) throw new TypeError("Invalid DAG-PB form");
|
|
642
|
+
return { Hash };
|
|
643
|
+
}
|
|
644
|
+
if (typeof link !== "object" || Array.isArray(link)) throw new TypeError("Invalid DAG-PB form");
|
|
645
|
+
const pbl = {};
|
|
646
|
+
if (link.Hash) {
|
|
647
|
+
let cid = CID.asCID(link.Hash);
|
|
648
|
+
try {
|
|
649
|
+
if (!cid) {
|
|
650
|
+
if (typeof link.Hash === "string") cid = CID.parse(link.Hash);
|
|
651
|
+
else if (link.Hash instanceof Uint8Array) cid = CID.decode(link.Hash);
|
|
652
|
+
}
|
|
653
|
+
} catch (e) {
|
|
654
|
+
throw new TypeError(`Invalid DAG-PB form: ${e.message}`);
|
|
655
|
+
}
|
|
656
|
+
if (cid) pbl.Hash = cid;
|
|
657
|
+
}
|
|
658
|
+
if (!pbl.Hash) throw new TypeError("Invalid DAG-PB form");
|
|
659
|
+
if (typeof link.Name === "string") pbl.Name = link.Name;
|
|
660
|
+
if (typeof link.Tsize === "number") pbl.Tsize = link.Tsize;
|
|
661
|
+
return pbl;
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* @param {any} node
|
|
665
|
+
* @returns {PBNode}
|
|
666
|
+
*/
|
|
667
|
+
function prepare(node) {
|
|
668
|
+
if (node instanceof Uint8Array || typeof node === "string") node = { Data: node };
|
|
669
|
+
if (typeof node !== "object" || Array.isArray(node)) throw new TypeError("Invalid DAG-PB form");
|
|
670
|
+
/** @type {PBNode} */
|
|
671
|
+
const pbn = {};
|
|
672
|
+
if (node.Data !== void 0) if (typeof node.Data === "string") pbn.Data = textEncoder.encode(node.Data);
|
|
673
|
+
else if (node.Data instanceof Uint8Array) pbn.Data = node.Data;
|
|
674
|
+
else throw new TypeError("Invalid DAG-PB form");
|
|
675
|
+
if (node.Links !== void 0) if (Array.isArray(node.Links)) {
|
|
676
|
+
pbn.Links = node.Links.map(asLink);
|
|
677
|
+
pbn.Links.sort(linkComparator);
|
|
678
|
+
} else throw new TypeError("Invalid DAG-PB form");
|
|
679
|
+
else pbn.Links = [];
|
|
680
|
+
return pbn;
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* @param {PBNode} node
|
|
684
|
+
*/
|
|
685
|
+
function validate(node) {
|
|
686
|
+
if (!node || typeof node !== "object" || Array.isArray(node) || node instanceof Uint8Array || node["/"] && node["/"] === node.bytes) throw new TypeError("Invalid DAG-PB form");
|
|
687
|
+
if (!hasOnlyProperties(node, pbNodeProperties)) throw new TypeError("Invalid DAG-PB form (extraneous properties)");
|
|
688
|
+
if (node.Data !== void 0 && !(node.Data instanceof Uint8Array)) throw new TypeError("Invalid DAG-PB form (Data must be bytes)");
|
|
689
|
+
if (!Array.isArray(node.Links)) throw new TypeError("Invalid DAG-PB form (Links must be a list)");
|
|
690
|
+
for (let i = 0; i < node.Links.length; i++) {
|
|
691
|
+
const link = node.Links[i];
|
|
692
|
+
if (!link || typeof link !== "object" || Array.isArray(link) || link instanceof Uint8Array || link["/"] && link["/"] === link.bytes) throw new TypeError("Invalid DAG-PB form (bad link)");
|
|
693
|
+
if (!hasOnlyProperties(link, pbLinkProperties)) throw new TypeError("Invalid DAG-PB form (extraneous properties on link)");
|
|
694
|
+
if (link.Hash === void 0) throw new TypeError("Invalid DAG-PB form (link must have a Hash)");
|
|
695
|
+
if (link.Hash == null || !link.Hash["/"] || link.Hash["/"] !== link.Hash.bytes) throw new TypeError("Invalid DAG-PB form (link Hash must be a CID)");
|
|
696
|
+
if (link.Name !== void 0 && typeof link.Name !== "string") throw new TypeError("Invalid DAG-PB form (link Name must be a string)");
|
|
697
|
+
if (link.Tsize !== void 0) {
|
|
698
|
+
if (typeof link.Tsize !== "number" || link.Tsize % 1 !== 0) throw new TypeError("Invalid DAG-PB form (link Tsize must be an integer)");
|
|
699
|
+
if (link.Tsize < 0) throw new TypeError("Invalid DAG-PB form (link Tsize cannot be negative)");
|
|
700
|
+
}
|
|
701
|
+
if (i > 0 && linkComparator(link, node.Links[i - 1]) === -1) throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)");
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* @param {Uint8Array} data
|
|
706
|
+
* @param {PBLink[]} [links]
|
|
707
|
+
* @returns {PBNode}
|
|
708
|
+
*/
|
|
709
|
+
function createNode(data, links = []) {
|
|
710
|
+
return prepare({
|
|
711
|
+
Data: data,
|
|
712
|
+
Links: links
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* @param {string} name
|
|
717
|
+
* @param {number} size
|
|
718
|
+
* @param {CID} cid
|
|
719
|
+
* @returns {PBLink}
|
|
720
|
+
*/
|
|
721
|
+
function createLink(name, size, cid) {
|
|
722
|
+
return asLink({
|
|
723
|
+
Hash: cid,
|
|
724
|
+
Name: name,
|
|
725
|
+
Tsize: size
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* @template T
|
|
730
|
+
* @param {ByteView<T> | ArrayBufferView<T>} buf
|
|
731
|
+
* @returns {ByteView<T>}
|
|
732
|
+
*/
|
|
733
|
+
function toByteView(buf) {
|
|
734
|
+
if (buf instanceof ArrayBuffer) return new Uint8Array(buf, 0, buf.byteLength);
|
|
735
|
+
return buf;
|
|
736
|
+
}
|
|
737
|
+
//#endregion
|
|
738
|
+
//#region node_modules/@ipld/dag-pb/src/index.js
|
|
739
|
+
var src_exports = /* @__PURE__ */ __exportAll({
|
|
740
|
+
code: () => 112,
|
|
741
|
+
createLink: () => createLink,
|
|
742
|
+
createNode: () => createNode,
|
|
743
|
+
decode: () => decode,
|
|
744
|
+
encode: () => encode,
|
|
745
|
+
name: () => name,
|
|
746
|
+
prepare: () => prepare,
|
|
747
|
+
validate: () => validate
|
|
748
|
+
});
|
|
749
|
+
/**
|
|
750
|
+
* @template T
|
|
751
|
+
* @typedef {import('multiformats/codecs/interface').ByteView<T>} ByteView
|
|
752
|
+
*/
|
|
753
|
+
/**
|
|
754
|
+
* @template T
|
|
755
|
+
* @typedef {import('multiformats/codecs/interface').ArrayBufferView<T>} ArrayBufferView
|
|
756
|
+
*/
|
|
757
|
+
/**
|
|
758
|
+
* @typedef {import('./interface.js').PBLink} PBLink
|
|
759
|
+
* @typedef {import('./interface.js').PBNode} PBNode
|
|
760
|
+
*/
|
|
761
|
+
const name = "dag-pb";
|
|
762
|
+
/**
|
|
763
|
+
* @param {PBNode} node
|
|
764
|
+
* @returns {ByteView<PBNode>}
|
|
765
|
+
*/
|
|
766
|
+
function encode(node) {
|
|
767
|
+
validate(node);
|
|
768
|
+
const pbn = {};
|
|
769
|
+
if (node.Links) pbn.Links = node.Links.map((l) => {
|
|
770
|
+
const link = {};
|
|
771
|
+
if (l.Hash) link.Hash = l.Hash.bytes;
|
|
772
|
+
if (l.Name !== void 0) link.Name = l.Name;
|
|
773
|
+
if (l.Tsize !== void 0) link.Tsize = l.Tsize;
|
|
774
|
+
return link;
|
|
775
|
+
});
|
|
776
|
+
if (node.Data) pbn.Data = node.Data;
|
|
777
|
+
return encodeNode(pbn);
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* @param {ByteView<PBNode> | ArrayBufferView<PBNode>} bytes
|
|
781
|
+
* @returns {PBNode}
|
|
782
|
+
*/
|
|
783
|
+
function decode(bytes) {
|
|
784
|
+
const pbn = decodeNode(toByteView(bytes));
|
|
785
|
+
const node = {};
|
|
786
|
+
if (pbn.Data) node.Data = pbn.Data;
|
|
787
|
+
if (pbn.Links) node.Links = pbn.Links.map((l) => {
|
|
788
|
+
const link = {};
|
|
789
|
+
try {
|
|
790
|
+
link.Hash = CID.decode(l.Hash);
|
|
791
|
+
} catch {}
|
|
792
|
+
if (!link.Hash) throw new Error("Invalid Hash field found in link, expected CID");
|
|
793
|
+
if (l.Name !== void 0) link.Name = l.Name;
|
|
794
|
+
if (l.Tsize !== void 0) link.Tsize = l.Tsize;
|
|
795
|
+
return link;
|
|
796
|
+
});
|
|
797
|
+
return node;
|
|
798
|
+
}
|
|
799
|
+
//#endregion
|
|
800
|
+
export { first as i, src_exports as n, prepare as r, encode as t };
|