@pkcprotocol/pkc-js 0.0.87 → 0.0.89
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/README.md +1 -1
- package/dist/browser/community/schema.d.ts +10 -10
- package/dist/browser/community/schema.js +1 -1
- package/dist/browser/community/schema.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.d.ts +2 -0
- package/dist/browser/helia/helia-for-pkc.js +158 -55
- package/dist/browser/helia/helia-for-pkc.js.map +1 -1
- package/dist/browser/helia/libp2pjsClient.d.ts +1 -1
- package/dist/browser/helia/lru-blockstore.d.ts +9 -8
- package/dist/browser/helia/lru-blockstore.js.map +1 -1
- package/dist/browser/helia/types.d.ts +10 -10
- package/dist/browser/rpc/src/schema.d.ts +148 -22
- package/dist/browser/runtime/node/community/local-community/cleanup.js +31 -1
- package/dist/browser/runtime/node/community/local-community/cleanup.js.map +1 -1
- package/dist/browser/schema/schema-util.d.ts +3 -3
- package/dist/browser/schema.d.ts +8 -6
- package/dist/browser/schema.js +8 -1
- package/dist/browser/schema.js.map +1 -1
- package/dist/browser/test/test-util.d.ts +3 -3
- package/dist/browser/test/test-util.js +3 -1
- package/dist/browser/test/test-util.js.map +1 -1
- package/dist/bundled/bundle-manifest.json +165 -146
- package/dist/bundled/chunks/{helia-for-pkc-CjrfyXsA.js → helia-for-pkc-BKXOmklx.js} +101 -70
- package/dist/bundled/chunks/{local-community-DbfQyZow.js → local-community-C7tTEYDD.js} +1 -1
- package/dist/bundled/chunks/{local-community-Ba5iR3bD.js → local-community-D5fzgPCr.js} +60 -31
- package/dist/bundled/chunks/{node-gCrky-14.js → node-C9RpmtmM.js} +5 -5
- package/dist/bundled/chunks/{rpc-local-community-BYd-0Aw4.js → rpc-local-community-Dq00OHRf.js} +432 -6
- package/dist/bundled/chunks/{schema-0b9XHoqX.js → schema-bDrzx9EZ.js} +4 -4
- package/dist/bundled/chunks/{src-WLgFbUwZ.js → src-629pKfxo.js} +2731 -415
- package/dist/bundled/chunks/{src-B2CwDTfy.js → src-Dz9wtvrK.js} +18 -18
- package/dist/bundled/chunks/{util-CvgcZ9iH.js → util-DuJcVQ7Y.js} +1 -1
- package/dist/bundled/index.js +1 -1
- package/dist/bundled/rpc/src/index.js +4 -4
- package/dist/node/community/schema.d.ts +10 -10
- package/dist/node/community/schema.js +1 -1
- package/dist/node/community/schema.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.d.ts +2 -0
- package/dist/node/helia/helia-for-pkc.js +158 -55
- package/dist/node/helia/helia-for-pkc.js.map +1 -1
- package/dist/node/helia/libp2pjsClient.d.ts +1 -1
- package/dist/node/helia/lru-blockstore.d.ts +9 -8
- package/dist/node/helia/lru-blockstore.js.map +1 -1
- package/dist/node/helia/types.d.ts +10 -10
- package/dist/node/rpc/src/schema.d.ts +148 -22
- package/dist/node/runtime/node/community/local-community/cleanup.js +31 -1
- package/dist/node/runtime/node/community/local-community/cleanup.js.map +1 -1
- package/dist/node/schema/schema-util.d.ts +3 -3
- package/dist/node/schema.d.ts +8 -6
- package/dist/node/schema.js +8 -1
- package/dist/node/schema.js.map +1 -1
- package/dist/node/test/test-util.d.ts +3 -3
- package/dist/node/test/test-util.js +3 -1
- package/dist/node/test/test-util.js.map +1 -1
- package/package.json +18 -16
|
@@ -20,6 +20,2475 @@ import { logger } from "@libp2p/logger";
|
|
|
20
20
|
import https from "node:https";
|
|
21
21
|
import { multiaddrToUri } from "@multiformats/multiaddr-to-uri";
|
|
22
22
|
//#region node_modules/kubo-rpc-client/node_modules/cborg/lib/is.js
|
|
23
|
+
const objectTypeNames$2 = [
|
|
24
|
+
"Object",
|
|
25
|
+
"RegExp",
|
|
26
|
+
"Date",
|
|
27
|
+
"Error",
|
|
28
|
+
"Map",
|
|
29
|
+
"Set",
|
|
30
|
+
"WeakMap",
|
|
31
|
+
"WeakSet",
|
|
32
|
+
"ArrayBuffer",
|
|
33
|
+
"SharedArrayBuffer",
|
|
34
|
+
"DataView",
|
|
35
|
+
"Promise",
|
|
36
|
+
"URL",
|
|
37
|
+
"HTMLElement",
|
|
38
|
+
"Int8Array",
|
|
39
|
+
"Uint8ClampedArray",
|
|
40
|
+
"Int16Array",
|
|
41
|
+
"Uint16Array",
|
|
42
|
+
"Int32Array",
|
|
43
|
+
"Uint32Array",
|
|
44
|
+
"Float32Array",
|
|
45
|
+
"Float64Array",
|
|
46
|
+
"BigInt64Array",
|
|
47
|
+
"BigUint64Array",
|
|
48
|
+
"Tagged"
|
|
49
|
+
];
|
|
50
|
+
/**
|
|
51
|
+
* @param {any} value
|
|
52
|
+
* @returns {string}
|
|
53
|
+
*/
|
|
54
|
+
function is$2(value) {
|
|
55
|
+
if (value === null) return "null";
|
|
56
|
+
if (value === void 0) return "undefined";
|
|
57
|
+
if (value === true || value === false) return "boolean";
|
|
58
|
+
const typeOf = typeof value;
|
|
59
|
+
if (typeOf === "string" || typeOf === "number" || typeOf === "bigint" || typeOf === "symbol") return typeOf;
|
|
60
|
+
if (typeOf === "function") return "Function";
|
|
61
|
+
if (Array.isArray(value)) return "Array";
|
|
62
|
+
if (value instanceof Uint8Array) return "Uint8Array";
|
|
63
|
+
if (value.constructor === Object) return "Object";
|
|
64
|
+
const objectType = getObjectType$2(value);
|
|
65
|
+
if (objectType) return objectType;
|
|
66
|
+
return "Object";
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @param {any} value
|
|
70
|
+
* @returns {string|undefined}
|
|
71
|
+
*/
|
|
72
|
+
function getObjectType$2(value) {
|
|
73
|
+
const objectTypeName = Object.prototype.toString.call(value).slice(8, -1);
|
|
74
|
+
if (objectTypeNames$2.includes(objectTypeName)) return objectTypeName;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region node_modules/kubo-rpc-client/node_modules/cborg/lib/token.js
|
|
78
|
+
var Type$2 = class {
|
|
79
|
+
/**
|
|
80
|
+
* @param {number} major
|
|
81
|
+
* @param {string} name
|
|
82
|
+
* @param {boolean} terminal
|
|
83
|
+
*/
|
|
84
|
+
constructor(major, name, terminal) {
|
|
85
|
+
this.major = major;
|
|
86
|
+
this.majorEncoded = major << 5;
|
|
87
|
+
this.name = name;
|
|
88
|
+
this.terminal = terminal;
|
|
89
|
+
}
|
|
90
|
+
toString() {
|
|
91
|
+
return `Type[${this.major}].${this.name}`;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* @param {Type} typ
|
|
95
|
+
* @returns {number}
|
|
96
|
+
*/
|
|
97
|
+
compare(typ) {
|
|
98
|
+
return this.major < typ.major ? -1 : this.major > typ.major ? 1 : 0;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Check equality between two Type instances. Safe to use across different
|
|
102
|
+
* copies of the Type class (e.g., when bundlers duplicate the module).
|
|
103
|
+
* (major, name) uniquely identifies a Type; terminal is implied by these.
|
|
104
|
+
* @param {Type} a
|
|
105
|
+
* @param {Type} b
|
|
106
|
+
* @returns {boolean}
|
|
107
|
+
*/
|
|
108
|
+
static equals(a, b) {
|
|
109
|
+
return a === b || a.major === b.major && a.name === b.name;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
Type$2.uint = new Type$2(0, "uint", true);
|
|
113
|
+
Type$2.negint = new Type$2(1, "negint", true);
|
|
114
|
+
Type$2.bytes = new Type$2(2, "bytes", true);
|
|
115
|
+
Type$2.string = new Type$2(3, "string", true);
|
|
116
|
+
Type$2.array = new Type$2(4, "array", false);
|
|
117
|
+
Type$2.map = new Type$2(5, "map", false);
|
|
118
|
+
Type$2.tag = new Type$2(6, "tag", false);
|
|
119
|
+
Type$2.float = new Type$2(7, "float", true);
|
|
120
|
+
Type$2.false = new Type$2(7, "false", true);
|
|
121
|
+
Type$2.true = new Type$2(7, "true", true);
|
|
122
|
+
Type$2.null = new Type$2(7, "null", true);
|
|
123
|
+
Type$2.undefined = new Type$2(7, "undefined", true);
|
|
124
|
+
Type$2.break = new Type$2(7, "break", true);
|
|
125
|
+
var Token$2 = class {
|
|
126
|
+
/**
|
|
127
|
+
* @param {Type} type
|
|
128
|
+
* @param {any} [value]
|
|
129
|
+
* @param {number} [encodedLength]
|
|
130
|
+
*/
|
|
131
|
+
constructor(type, value, encodedLength) {
|
|
132
|
+
this.type = type;
|
|
133
|
+
this.value = value;
|
|
134
|
+
this.encodedLength = encodedLength;
|
|
135
|
+
/** @type {Uint8Array|undefined} */
|
|
136
|
+
this.encodedBytes = void 0;
|
|
137
|
+
/** @type {Uint8Array|undefined} */
|
|
138
|
+
this.byteValue = void 0;
|
|
139
|
+
}
|
|
140
|
+
toString() {
|
|
141
|
+
return `Token[${this.type}].${this.value}`;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region node_modules/kubo-rpc-client/node_modules/cborg/lib/byte-utils.js
|
|
146
|
+
const useBuffer$2 = globalThis.process && !globalThis.process.browser && globalThis.Buffer && typeof globalThis.Buffer.isBuffer === "function";
|
|
147
|
+
const textEncoder$2 = new TextEncoder();
|
|
148
|
+
/**
|
|
149
|
+
* @typedef {import('../interface.js').ByteView} ByteView
|
|
150
|
+
* @typedef {import('../interface.js').AllocatedByteView} AllocatedByteView
|
|
151
|
+
*/
|
|
152
|
+
/**
|
|
153
|
+
* @param {Uint8Array} buf
|
|
154
|
+
* @returns {boolean}
|
|
155
|
+
*/
|
|
156
|
+
function isBuffer$2(buf) {
|
|
157
|
+
return useBuffer$2 && globalThis.Buffer.isBuffer(buf);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* @param {ByteView|number[]} buf
|
|
161
|
+
* @returns {ByteView}
|
|
162
|
+
*/
|
|
163
|
+
function asU8A$2(buf) {
|
|
164
|
+
if (!(buf instanceof Uint8Array)) return Uint8Array.from(buf);
|
|
165
|
+
return isBuffer$2(buf) ? new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength) : buf;
|
|
166
|
+
}
|
|
167
|
+
const FROM_STRING_THRESHOLD_BUFFER$2 = 24;
|
|
168
|
+
const FROM_STRING_THRESHOLD_TEXTENCODER$2 = 200;
|
|
169
|
+
const fromString$3 = useBuffer$2 ? (string) => {
|
|
170
|
+
return string.length >= FROM_STRING_THRESHOLD_BUFFER$2 ? globalThis.Buffer.from(string) : utf8ToBytes$2(string);
|
|
171
|
+
} :
|
|
172
|
+
/**
|
|
173
|
+
* @param {string} string
|
|
174
|
+
*/
|
|
175
|
+
(string) => {
|
|
176
|
+
return string.length >= FROM_STRING_THRESHOLD_TEXTENCODER$2 ? textEncoder$2.encode(string) : utf8ToBytes$2(string);
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Buffer variant not fast enough for what we need
|
|
180
|
+
* @param {number[]} arr
|
|
181
|
+
* @returns {AllocatedByteView}
|
|
182
|
+
*/
|
|
183
|
+
const fromArray$2 = (arr) => {
|
|
184
|
+
return Uint8Array.from(arr);
|
|
185
|
+
};
|
|
186
|
+
const slice$2 = useBuffer$2 ? (bytes, start, end) => {
|
|
187
|
+
if (isBuffer$2(bytes)) return new Uint8Array(bytes.subarray(start, end));
|
|
188
|
+
return bytes.slice(start, end);
|
|
189
|
+
} :
|
|
190
|
+
/**
|
|
191
|
+
* @param {Uint8Array} bytes
|
|
192
|
+
* @param {number} start
|
|
193
|
+
* @param {number} end
|
|
194
|
+
*/
|
|
195
|
+
(bytes, start, end) => {
|
|
196
|
+
return bytes.slice(start, end);
|
|
197
|
+
};
|
|
198
|
+
const concat$2 = useBuffer$2 ? (chunks, length) => {
|
|
199
|
+
chunks = chunks.map((c) => c instanceof Uint8Array ? c : globalThis.Buffer.from(c));
|
|
200
|
+
return asU8A$2(globalThis.Buffer.concat(chunks, length));
|
|
201
|
+
} :
|
|
202
|
+
/**
|
|
203
|
+
* @param {ByteView[]} chunks
|
|
204
|
+
* @param {number} length
|
|
205
|
+
* @returns {AllocatedByteView}
|
|
206
|
+
*/
|
|
207
|
+
(chunks, length) => {
|
|
208
|
+
const out = new Uint8Array(length);
|
|
209
|
+
let off = 0;
|
|
210
|
+
for (let b of chunks) {
|
|
211
|
+
if (off + b.length > out.length) b = b.subarray(0, out.length - off);
|
|
212
|
+
out.set(b, off);
|
|
213
|
+
off += b.length;
|
|
214
|
+
}
|
|
215
|
+
return out;
|
|
216
|
+
};
|
|
217
|
+
const alloc$2 = useBuffer$2 ? (size) => {
|
|
218
|
+
return globalThis.Buffer.allocUnsafe(size);
|
|
219
|
+
} :
|
|
220
|
+
/**
|
|
221
|
+
* @param {number} size
|
|
222
|
+
* @returns {AllocatedByteView}
|
|
223
|
+
*/
|
|
224
|
+
(size) => {
|
|
225
|
+
return new Uint8Array(size);
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* @param {Uint8Array} b1
|
|
229
|
+
* @param {Uint8Array} b2
|
|
230
|
+
* @returns {number}
|
|
231
|
+
*/
|
|
232
|
+
function compare$2(b1, b2) {
|
|
233
|
+
if (isBuffer$2(b1) && isBuffer$2(b2)) return b1.compare(b2);
|
|
234
|
+
for (let i = 0; i < b1.length; i++) {
|
|
235
|
+
if (b1[i] === b2[i]) continue;
|
|
236
|
+
return b1[i] < b2[i] ? -1 : 1;
|
|
237
|
+
}
|
|
238
|
+
return 0;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* @param {string} str
|
|
242
|
+
* @returns {number[]}
|
|
243
|
+
*/
|
|
244
|
+
function utf8ToBytes$2(str) {
|
|
245
|
+
const out = [];
|
|
246
|
+
let p = 0;
|
|
247
|
+
for (let i = 0; i < str.length; i++) {
|
|
248
|
+
let c = str.charCodeAt(i);
|
|
249
|
+
if (c < 128) out[p++] = c;
|
|
250
|
+
else if (c < 2048) {
|
|
251
|
+
out[p++] = c >> 6 | 192;
|
|
252
|
+
out[p++] = c & 63 | 128;
|
|
253
|
+
} else if ((c & 64512) === 55296 && i + 1 < str.length && (str.charCodeAt(i + 1) & 64512) === 56320) {
|
|
254
|
+
c = 65536 + ((c & 1023) << 10) + (str.charCodeAt(++i) & 1023);
|
|
255
|
+
out[p++] = c >> 18 | 240;
|
|
256
|
+
out[p++] = c >> 12 & 63 | 128;
|
|
257
|
+
out[p++] = c >> 6 & 63 | 128;
|
|
258
|
+
out[p++] = c & 63 | 128;
|
|
259
|
+
} else {
|
|
260
|
+
if (c >= 55296 && c <= 57343) c = 65533;
|
|
261
|
+
out[p++] = c >> 12 | 224;
|
|
262
|
+
out[p++] = c >> 6 & 63 | 128;
|
|
263
|
+
out[p++] = c & 63 | 128;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return out;
|
|
267
|
+
}
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region node_modules/kubo-rpc-client/node_modules/cborg/lib/bl.js
|
|
270
|
+
/**
|
|
271
|
+
* Bl is a list of byte chunks, similar to https://github.com/rvagg/bl but for
|
|
272
|
+
* writing rather than reading.
|
|
273
|
+
* A Bl object accepts set() operations for individual bytes and copyTo() for
|
|
274
|
+
* inserting byte arrays. These write operations don't automatically increment
|
|
275
|
+
* the internal cursor so its "length" won't be changed. Instead, increment()
|
|
276
|
+
* must be called to extend its length to cover the inserted data.
|
|
277
|
+
* The toBytes() call will convert all internal memory to a single Uint8Array of
|
|
278
|
+
* the correct length, truncating any data that is stored but hasn't been
|
|
279
|
+
* included by an increment().
|
|
280
|
+
* get() can retrieve a single byte.
|
|
281
|
+
* All operations (except toBytes()) take an "offset" argument that will perform
|
|
282
|
+
* the write at the offset _from the current cursor_. For most operations this
|
|
283
|
+
* will be `0` to write at the current cursor position but it can be ahead of
|
|
284
|
+
* the current cursor. Negative offsets probably work but are untested.
|
|
285
|
+
*/
|
|
286
|
+
/**
|
|
287
|
+
* @typedef {import('../interface.js').ByteView} ByteView
|
|
288
|
+
* @typedef {import('../interface.js').AllocatedByteView} AllocatedByteView
|
|
289
|
+
*/
|
|
290
|
+
const defaultChunkSize$2 = 256;
|
|
291
|
+
var Bl$2 = class {
|
|
292
|
+
/**
|
|
293
|
+
* @param {number} [chunkSize]
|
|
294
|
+
*/
|
|
295
|
+
constructor(chunkSize = defaultChunkSize$2) {
|
|
296
|
+
this.chunkSize = chunkSize;
|
|
297
|
+
/** @type {number} */
|
|
298
|
+
this.cursor = 0;
|
|
299
|
+
/** @type {number} */
|
|
300
|
+
this.maxCursor = -1;
|
|
301
|
+
/** @type {(ByteView|number[])[]} */
|
|
302
|
+
this.chunks = [];
|
|
303
|
+
/** @type {ByteView|number[]|null} */
|
|
304
|
+
this._initReuseChunk = null;
|
|
305
|
+
}
|
|
306
|
+
reset() {
|
|
307
|
+
this.cursor = 0;
|
|
308
|
+
this.maxCursor = -1;
|
|
309
|
+
if (this.chunks.length) this.chunks = [];
|
|
310
|
+
if (this._initReuseChunk !== null) {
|
|
311
|
+
this.chunks.push(this._initReuseChunk);
|
|
312
|
+
this.maxCursor = this._initReuseChunk.length - 1;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* @param {number} byte
|
|
317
|
+
*/
|
|
318
|
+
pushByte(byte) {
|
|
319
|
+
let topChunk = this.chunks[this.chunks.length - 1];
|
|
320
|
+
if (this.cursor > this.maxCursor) {
|
|
321
|
+
topChunk = alloc$2(this.chunkSize);
|
|
322
|
+
this.chunks.push(topChunk);
|
|
323
|
+
this.maxCursor += topChunk.length;
|
|
324
|
+
if (this._initReuseChunk === null) this._initReuseChunk = topChunk;
|
|
325
|
+
}
|
|
326
|
+
const chunkPos = topChunk.length - (this.maxCursor - this.cursor) - 1;
|
|
327
|
+
topChunk[chunkPos] = byte;
|
|
328
|
+
this.cursor++;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* @param {ByteView|number[]} bytes
|
|
332
|
+
*/
|
|
333
|
+
push(bytes) {
|
|
334
|
+
let topChunk = this.chunks[this.chunks.length - 1];
|
|
335
|
+
if (this.cursor + bytes.length <= this.maxCursor + 1) {
|
|
336
|
+
const chunkPos = topChunk.length - (this.maxCursor - this.cursor) - 1;
|
|
337
|
+
topChunk.set(bytes, chunkPos);
|
|
338
|
+
} else {
|
|
339
|
+
if (topChunk) {
|
|
340
|
+
const chunkPos = topChunk.length - (this.maxCursor - this.cursor) - 1;
|
|
341
|
+
if (chunkPos < topChunk.length) {
|
|
342
|
+
this.chunks[this.chunks.length - 1] = topChunk.subarray(0, chunkPos);
|
|
343
|
+
this.maxCursor = this.cursor - 1;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (bytes.length < 64 && bytes.length < this.chunkSize) {
|
|
347
|
+
topChunk = alloc$2(this.chunkSize);
|
|
348
|
+
this.chunks.push(topChunk);
|
|
349
|
+
this.maxCursor += topChunk.length;
|
|
350
|
+
if (this._initReuseChunk === null) this._initReuseChunk = topChunk;
|
|
351
|
+
topChunk.set(bytes, 0);
|
|
352
|
+
} else {
|
|
353
|
+
this.chunks.push(bytes);
|
|
354
|
+
this.maxCursor += bytes.length;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
this.cursor += bytes.length;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* @param {boolean} [reset]
|
|
361
|
+
* @returns {AllocatedByteView}
|
|
362
|
+
*/
|
|
363
|
+
toBytes(reset = false) {
|
|
364
|
+
let byts;
|
|
365
|
+
if (this.chunks.length === 1) {
|
|
366
|
+
const chunk = this.chunks[0];
|
|
367
|
+
if (reset && this.cursor > chunk.length / 2) {
|
|
368
|
+
byts = this.cursor === chunk.length ? chunk : chunk.subarray(0, this.cursor);
|
|
369
|
+
this._initReuseChunk = null;
|
|
370
|
+
this.chunks = [];
|
|
371
|
+
} else byts = slice$2(chunk, 0, this.cursor);
|
|
372
|
+
} else byts = concat$2(this.chunks, this.cursor);
|
|
373
|
+
if (reset) this.reset();
|
|
374
|
+
return byts;
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
/**
|
|
378
|
+
* U8Bl is a buffer list that writes directly to a user-provided Uint8Array.
|
|
379
|
+
* It provides the same interface as Bl but writes to a fixed destination.
|
|
380
|
+
* @template {ArrayBufferLike} T
|
|
381
|
+
*/
|
|
382
|
+
var U8Bl$2 = class {
|
|
383
|
+
/**
|
|
384
|
+
* @param {Uint8Array<T>} dest
|
|
385
|
+
*/
|
|
386
|
+
constructor(dest) {
|
|
387
|
+
this.dest = dest;
|
|
388
|
+
/** @type {number} */
|
|
389
|
+
this.cursor = 0;
|
|
390
|
+
/** @type {Array<Uint8Array<T>>} */
|
|
391
|
+
this.chunks = [dest];
|
|
392
|
+
}
|
|
393
|
+
reset() {
|
|
394
|
+
this.cursor = 0;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* @param {number} byte
|
|
398
|
+
*/
|
|
399
|
+
pushByte(byte) {
|
|
400
|
+
if (this.cursor >= this.dest.length) throw new Error("write out of bounds, destination buffer is too small");
|
|
401
|
+
this.dest[this.cursor++] = byte;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* @param {ByteView|number[]} bytes
|
|
405
|
+
*/
|
|
406
|
+
push(bytes) {
|
|
407
|
+
if (this.cursor + bytes.length > this.dest.length) throw new Error("write out of bounds, destination buffer is too small");
|
|
408
|
+
this.dest.set(bytes, this.cursor);
|
|
409
|
+
this.cursor += bytes.length;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* @param {boolean} [reset]
|
|
413
|
+
* @returns {Uint8Array<T>}
|
|
414
|
+
*/
|
|
415
|
+
toBytes(reset = false) {
|
|
416
|
+
const byts = this.dest.subarray(0, this.cursor);
|
|
417
|
+
if (reset) this.reset();
|
|
418
|
+
return byts;
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
//#endregion
|
|
422
|
+
//#region node_modules/kubo-rpc-client/node_modules/cborg/lib/common.js
|
|
423
|
+
const decodeErrPrefix$2 = "CBOR decode error:";
|
|
424
|
+
const encodeErrPrefix$2 = "CBOR encode error:";
|
|
425
|
+
const uintMinorPrefixBytes$2 = [];
|
|
426
|
+
uintMinorPrefixBytes$2[23] = 1;
|
|
427
|
+
uintMinorPrefixBytes$2[24] = 2;
|
|
428
|
+
uintMinorPrefixBytes$2[25] = 3;
|
|
429
|
+
uintMinorPrefixBytes$2[26] = 5;
|
|
430
|
+
uintMinorPrefixBytes$2[27] = 9;
|
|
431
|
+
/**
|
|
432
|
+
* @param {Uint8Array} data
|
|
433
|
+
* @param {number} pos
|
|
434
|
+
* @param {number} need
|
|
435
|
+
*/
|
|
436
|
+
function assertEnoughData$2(data, pos, need) {
|
|
437
|
+
if (data.length - pos < need) throw new Error(`${decodeErrPrefix$2} not enough data for type`);
|
|
438
|
+
}
|
|
439
|
+
//#endregion
|
|
440
|
+
//#region node_modules/kubo-rpc-client/node_modules/cborg/lib/0uint.js
|
|
441
|
+
const uintBoundaries$2 = [
|
|
442
|
+
24,
|
|
443
|
+
256,
|
|
444
|
+
65536,
|
|
445
|
+
4294967296,
|
|
446
|
+
BigInt("18446744073709551616")
|
|
447
|
+
];
|
|
448
|
+
/**
|
|
449
|
+
* @typedef {import('../interface.js').ByteWriter} ByteWriter
|
|
450
|
+
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
451
|
+
*/
|
|
452
|
+
/**
|
|
453
|
+
* @param {Uint8Array} data
|
|
454
|
+
* @param {number} offset
|
|
455
|
+
* @param {DecodeOptions} options
|
|
456
|
+
* @returns {number}
|
|
457
|
+
*/
|
|
458
|
+
function readUint8$2(data, offset, options) {
|
|
459
|
+
assertEnoughData$2(data, offset, 1);
|
|
460
|
+
const value = data[offset];
|
|
461
|
+
if (options.strict === true && value < uintBoundaries$2[0]) throw new Error(`${decodeErrPrefix$2} integer encoded in more bytes than necessary (strict decode)`);
|
|
462
|
+
return value;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* @param {Uint8Array} data
|
|
466
|
+
* @param {number} offset
|
|
467
|
+
* @param {DecodeOptions} options
|
|
468
|
+
* @returns {number}
|
|
469
|
+
*/
|
|
470
|
+
function readUint16$2(data, offset, options) {
|
|
471
|
+
assertEnoughData$2(data, offset, 2);
|
|
472
|
+
const value = data[offset] << 8 | data[offset + 1];
|
|
473
|
+
if (options.strict === true && value < uintBoundaries$2[1]) throw new Error(`${decodeErrPrefix$2} integer encoded in more bytes than necessary (strict decode)`);
|
|
474
|
+
return value;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* @param {Uint8Array} data
|
|
478
|
+
* @param {number} offset
|
|
479
|
+
* @param {DecodeOptions} options
|
|
480
|
+
* @returns {number}
|
|
481
|
+
*/
|
|
482
|
+
function readUint32$2(data, offset, options) {
|
|
483
|
+
assertEnoughData$2(data, offset, 4);
|
|
484
|
+
const value = data[offset] * 16777216 + (data[offset + 1] << 16) + (data[offset + 2] << 8) + data[offset + 3];
|
|
485
|
+
if (options.strict === true && value < uintBoundaries$2[2]) throw new Error(`${decodeErrPrefix$2} integer encoded in more bytes than necessary (strict decode)`);
|
|
486
|
+
return value;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* @param {Uint8Array} data
|
|
490
|
+
* @param {number} offset
|
|
491
|
+
* @param {DecodeOptions} options
|
|
492
|
+
* @returns {number|bigint}
|
|
493
|
+
*/
|
|
494
|
+
function readUint64$2(data, offset, options) {
|
|
495
|
+
assertEnoughData$2(data, offset, 8);
|
|
496
|
+
const hi = data[offset] * 16777216 + (data[offset + 1] << 16) + (data[offset + 2] << 8) + data[offset + 3];
|
|
497
|
+
const lo = data[offset + 4] * 16777216 + (data[offset + 5] << 16) + (data[offset + 6] << 8) + data[offset + 7];
|
|
498
|
+
const value = (BigInt(hi) << BigInt(32)) + BigInt(lo);
|
|
499
|
+
if (options.strict === true && value < uintBoundaries$2[3]) throw new Error(`${decodeErrPrefix$2} integer encoded in more bytes than necessary (strict decode)`);
|
|
500
|
+
if (value <= Number.MAX_SAFE_INTEGER) return Number(value);
|
|
501
|
+
if (options.allowBigInt === true) return value;
|
|
502
|
+
throw new Error(`${decodeErrPrefix$2} integers outside of the safe integer range are not supported`);
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* @param {Uint8Array} data
|
|
506
|
+
* @param {number} pos
|
|
507
|
+
* @param {number} _minor
|
|
508
|
+
* @param {DecodeOptions} options
|
|
509
|
+
* @returns {Token}
|
|
510
|
+
*/
|
|
511
|
+
function decodeUint8$2(data, pos, _minor, options) {
|
|
512
|
+
return new Token$2(Type$2.uint, readUint8$2(data, pos + 1, options), 2);
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* @param {Uint8Array} data
|
|
516
|
+
* @param {number} pos
|
|
517
|
+
* @param {number} _minor
|
|
518
|
+
* @param {DecodeOptions} options
|
|
519
|
+
* @returns {Token}
|
|
520
|
+
*/
|
|
521
|
+
function decodeUint16$2(data, pos, _minor, options) {
|
|
522
|
+
return new Token$2(Type$2.uint, readUint16$2(data, pos + 1, options), 3);
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* @param {Uint8Array} data
|
|
526
|
+
* @param {number} pos
|
|
527
|
+
* @param {number} _minor
|
|
528
|
+
* @param {DecodeOptions} options
|
|
529
|
+
* @returns {Token}
|
|
530
|
+
*/
|
|
531
|
+
function decodeUint32$2(data, pos, _minor, options) {
|
|
532
|
+
return new Token$2(Type$2.uint, readUint32$2(data, pos + 1, options), 5);
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* @param {Uint8Array} data
|
|
536
|
+
* @param {number} pos
|
|
537
|
+
* @param {number} _minor
|
|
538
|
+
* @param {DecodeOptions} options
|
|
539
|
+
* @returns {Token}
|
|
540
|
+
*/
|
|
541
|
+
function decodeUint64$2(data, pos, _minor, options) {
|
|
542
|
+
return new Token$2(Type$2.uint, readUint64$2(data, pos + 1, options), 9);
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* @param {ByteWriter} writer
|
|
546
|
+
* @param {Token} token
|
|
547
|
+
*/
|
|
548
|
+
function encodeUint$2(writer, token) {
|
|
549
|
+
return encodeUintValue$2(writer, 0, token.value);
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* @param {ByteWriter} writer
|
|
553
|
+
* @param {number} major
|
|
554
|
+
* @param {number|bigint} uint
|
|
555
|
+
*/
|
|
556
|
+
function encodeUintValue$2(writer, major, uint) {
|
|
557
|
+
if (uint < uintBoundaries$2[0]) {
|
|
558
|
+
const nuint = Number(uint);
|
|
559
|
+
writer.pushByte(major | nuint);
|
|
560
|
+
} else if (uint < uintBoundaries$2[1]) {
|
|
561
|
+
const nuint = Number(uint);
|
|
562
|
+
writer.push([major | 24, nuint]);
|
|
563
|
+
} else if (uint < uintBoundaries$2[2]) {
|
|
564
|
+
const nuint = Number(uint);
|
|
565
|
+
writer.push([
|
|
566
|
+
major | 25,
|
|
567
|
+
nuint >>> 8,
|
|
568
|
+
nuint & 255
|
|
569
|
+
]);
|
|
570
|
+
} else if (uint < uintBoundaries$2[3]) {
|
|
571
|
+
const nuint = Number(uint);
|
|
572
|
+
writer.push([
|
|
573
|
+
major | 26,
|
|
574
|
+
nuint >>> 24 & 255,
|
|
575
|
+
nuint >>> 16 & 255,
|
|
576
|
+
nuint >>> 8 & 255,
|
|
577
|
+
nuint & 255
|
|
578
|
+
]);
|
|
579
|
+
} else {
|
|
580
|
+
const buint = BigInt(uint);
|
|
581
|
+
if (buint < uintBoundaries$2[4]) {
|
|
582
|
+
const set = [
|
|
583
|
+
major | 27,
|
|
584
|
+
0,
|
|
585
|
+
0,
|
|
586
|
+
0,
|
|
587
|
+
0,
|
|
588
|
+
0,
|
|
589
|
+
0,
|
|
590
|
+
0
|
|
591
|
+
];
|
|
592
|
+
let lo = Number(buint & BigInt(4294967295));
|
|
593
|
+
let hi = Number(buint >> BigInt(32) & BigInt(4294967295));
|
|
594
|
+
set[8] = lo & 255;
|
|
595
|
+
lo = lo >> 8;
|
|
596
|
+
set[7] = lo & 255;
|
|
597
|
+
lo = lo >> 8;
|
|
598
|
+
set[6] = lo & 255;
|
|
599
|
+
lo = lo >> 8;
|
|
600
|
+
set[5] = lo & 255;
|
|
601
|
+
set[4] = hi & 255;
|
|
602
|
+
hi = hi >> 8;
|
|
603
|
+
set[3] = hi & 255;
|
|
604
|
+
hi = hi >> 8;
|
|
605
|
+
set[2] = hi & 255;
|
|
606
|
+
hi = hi >> 8;
|
|
607
|
+
set[1] = hi & 255;
|
|
608
|
+
writer.push(set);
|
|
609
|
+
} else throw new Error(`${decodeErrPrefix$2} encountered BigInt larger than allowable range`);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* @param {Token} token
|
|
614
|
+
* @returns {number}
|
|
615
|
+
*/
|
|
616
|
+
encodeUint$2.encodedSize = function encodedSize(token) {
|
|
617
|
+
return encodeUintValue$2.encodedSize(token.value);
|
|
618
|
+
};
|
|
619
|
+
/**
|
|
620
|
+
* @param {number} uint
|
|
621
|
+
* @returns {number}
|
|
622
|
+
*/
|
|
623
|
+
encodeUintValue$2.encodedSize = function encodedSize(uint) {
|
|
624
|
+
if (uint < uintBoundaries$2[0]) return 1;
|
|
625
|
+
if (uint < uintBoundaries$2[1]) return 2;
|
|
626
|
+
if (uint < uintBoundaries$2[2]) return 3;
|
|
627
|
+
if (uint < uintBoundaries$2[3]) return 5;
|
|
628
|
+
return 9;
|
|
629
|
+
};
|
|
630
|
+
/**
|
|
631
|
+
* @param {Token} tok1
|
|
632
|
+
* @param {Token} tok2
|
|
633
|
+
* @returns {number}
|
|
634
|
+
*/
|
|
635
|
+
encodeUint$2.compareTokens = function compareTokens(tok1, tok2) {
|
|
636
|
+
return tok1.value < tok2.value ? -1 : tok1.value > tok2.value ? 1 : 0;
|
|
637
|
+
};
|
|
638
|
+
//#endregion
|
|
639
|
+
//#region node_modules/kubo-rpc-client/node_modules/cborg/lib/1negint.js
|
|
640
|
+
/**
|
|
641
|
+
* @typedef {import('../interface.js').ByteWriter} ByteWriter
|
|
642
|
+
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
643
|
+
*/
|
|
644
|
+
/**
|
|
645
|
+
* @param {Uint8Array} data
|
|
646
|
+
* @param {number} pos
|
|
647
|
+
* @param {number} _minor
|
|
648
|
+
* @param {DecodeOptions} options
|
|
649
|
+
* @returns {Token}
|
|
650
|
+
*/
|
|
651
|
+
function decodeNegint8$2(data, pos, _minor, options) {
|
|
652
|
+
return new Token$2(Type$2.negint, -1 - readUint8$2(data, pos + 1, options), 2);
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* @param {Uint8Array} data
|
|
656
|
+
* @param {number} pos
|
|
657
|
+
* @param {number} _minor
|
|
658
|
+
* @param {DecodeOptions} options
|
|
659
|
+
* @returns {Token}
|
|
660
|
+
*/
|
|
661
|
+
function decodeNegint16$2(data, pos, _minor, options) {
|
|
662
|
+
return new Token$2(Type$2.negint, -1 - readUint16$2(data, pos + 1, options), 3);
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* @param {Uint8Array} data
|
|
666
|
+
* @param {number} pos
|
|
667
|
+
* @param {number} _minor
|
|
668
|
+
* @param {DecodeOptions} options
|
|
669
|
+
* @returns {Token}
|
|
670
|
+
*/
|
|
671
|
+
function decodeNegint32$2(data, pos, _minor, options) {
|
|
672
|
+
return new Token$2(Type$2.negint, -1 - readUint32$2(data, pos + 1, options), 5);
|
|
673
|
+
}
|
|
674
|
+
const neg1b$4 = BigInt(-1);
|
|
675
|
+
const pos1b$4 = BigInt(1);
|
|
676
|
+
/**
|
|
677
|
+
* @param {Uint8Array} data
|
|
678
|
+
* @param {number} pos
|
|
679
|
+
* @param {number} _minor
|
|
680
|
+
* @param {DecodeOptions} options
|
|
681
|
+
* @returns {Token}
|
|
682
|
+
*/
|
|
683
|
+
function decodeNegint64$2(data, pos, _minor, options) {
|
|
684
|
+
const int = readUint64$2(data, pos + 1, options);
|
|
685
|
+
if (typeof int !== "bigint") {
|
|
686
|
+
const value = -1 - int;
|
|
687
|
+
if (value >= Number.MIN_SAFE_INTEGER) return new Token$2(Type$2.negint, value, 9);
|
|
688
|
+
}
|
|
689
|
+
if (options.allowBigInt !== true) throw new Error(`${decodeErrPrefix$2} integers outside of the safe integer range are not supported`);
|
|
690
|
+
return new Token$2(Type$2.negint, neg1b$4 - BigInt(int), 9);
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* @param {ByteWriter} writer
|
|
694
|
+
* @param {Token} token
|
|
695
|
+
*/
|
|
696
|
+
function encodeNegint$2(writer, token) {
|
|
697
|
+
const negint = token.value;
|
|
698
|
+
const unsigned = typeof negint === "bigint" ? negint * neg1b$4 - pos1b$4 : negint * -1 - 1;
|
|
699
|
+
encodeUintValue$2(writer, token.type.majorEncoded, unsigned);
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* @param {Token} token
|
|
703
|
+
* @returns {number}
|
|
704
|
+
*/
|
|
705
|
+
encodeNegint$2.encodedSize = function encodedSize(token) {
|
|
706
|
+
const negint = token.value;
|
|
707
|
+
const unsigned = typeof negint === "bigint" ? negint * neg1b$4 - pos1b$4 : negint * -1 - 1;
|
|
708
|
+
if (unsigned < uintBoundaries$2[0]) return 1;
|
|
709
|
+
if (unsigned < uintBoundaries$2[1]) return 2;
|
|
710
|
+
if (unsigned < uintBoundaries$2[2]) return 3;
|
|
711
|
+
if (unsigned < uintBoundaries$2[3]) return 5;
|
|
712
|
+
return 9;
|
|
713
|
+
};
|
|
714
|
+
/**
|
|
715
|
+
* @param {Token} tok1
|
|
716
|
+
* @param {Token} tok2
|
|
717
|
+
* @returns {number}
|
|
718
|
+
*/
|
|
719
|
+
encodeNegint$2.compareTokens = function compareTokens(tok1, tok2) {
|
|
720
|
+
return tok1.value < tok2.value ? 1 : tok1.value > tok2.value ? -1 : 0;
|
|
721
|
+
};
|
|
722
|
+
//#endregion
|
|
723
|
+
//#region node_modules/kubo-rpc-client/node_modules/cborg/lib/2bytes.js
|
|
724
|
+
/**
|
|
725
|
+
* @typedef {import('../interface.js').ByteWriter} ByteWriter
|
|
726
|
+
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
727
|
+
*/
|
|
728
|
+
/**
|
|
729
|
+
* @param {Uint8Array} data
|
|
730
|
+
* @param {number} pos
|
|
731
|
+
* @param {number} prefix
|
|
732
|
+
* @param {number} length
|
|
733
|
+
* @returns {Token}
|
|
734
|
+
*/
|
|
735
|
+
function toToken$11(data, pos, prefix, length) {
|
|
736
|
+
assertEnoughData$2(data, pos, prefix + length);
|
|
737
|
+
const buf = data.slice(pos + prefix, pos + prefix + length);
|
|
738
|
+
return new Token$2(Type$2.bytes, buf, prefix + length);
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* @param {Uint8Array} data
|
|
742
|
+
* @param {number} pos
|
|
743
|
+
* @param {number} minor
|
|
744
|
+
* @param {DecodeOptions} _options
|
|
745
|
+
* @returns {Token}
|
|
746
|
+
*/
|
|
747
|
+
function decodeBytesCompact$2(data, pos, minor, _options) {
|
|
748
|
+
return toToken$11(data, pos, 1, minor);
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* @param {Uint8Array} data
|
|
752
|
+
* @param {number} pos
|
|
753
|
+
* @param {number} _minor
|
|
754
|
+
* @param {DecodeOptions} options
|
|
755
|
+
* @returns {Token}
|
|
756
|
+
*/
|
|
757
|
+
function decodeBytes8$2(data, pos, _minor, options) {
|
|
758
|
+
return toToken$11(data, pos, 2, readUint8$2(data, pos + 1, options));
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* @param {Uint8Array} data
|
|
762
|
+
* @param {number} pos
|
|
763
|
+
* @param {number} _minor
|
|
764
|
+
* @param {DecodeOptions} options
|
|
765
|
+
* @returns {Token}
|
|
766
|
+
*/
|
|
767
|
+
function decodeBytes16$2(data, pos, _minor, options) {
|
|
768
|
+
return toToken$11(data, pos, 3, readUint16$2(data, pos + 1, options));
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* @param {Uint8Array} data
|
|
772
|
+
* @param {number} pos
|
|
773
|
+
* @param {number} _minor
|
|
774
|
+
* @param {DecodeOptions} options
|
|
775
|
+
* @returns {Token}
|
|
776
|
+
*/
|
|
777
|
+
function decodeBytes32$2(data, pos, _minor, options) {
|
|
778
|
+
return toToken$11(data, pos, 5, readUint32$2(data, pos + 1, options));
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* @param {Uint8Array} data
|
|
782
|
+
* @param {number} pos
|
|
783
|
+
* @param {number} _minor
|
|
784
|
+
* @param {DecodeOptions} options
|
|
785
|
+
* @returns {Token}
|
|
786
|
+
*/
|
|
787
|
+
function decodeBytes64$2(data, pos, _minor, options) {
|
|
788
|
+
const l = readUint64$2(data, pos + 1, options);
|
|
789
|
+
if (typeof l === "bigint") throw new Error(`${decodeErrPrefix$2} 64-bit integer bytes lengths not supported`);
|
|
790
|
+
return toToken$11(data, pos, 9, l);
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* `encodedBytes` allows for caching when we do a byte version of a string
|
|
794
|
+
* for key sorting purposes
|
|
795
|
+
* @param {Token} token
|
|
796
|
+
* @returns {Uint8Array}
|
|
797
|
+
*/
|
|
798
|
+
function tokenBytes$2(token) {
|
|
799
|
+
if (token.encodedBytes === void 0) token.encodedBytes = Type$2.equals(token.type, Type$2.string) ? fromString$3(token.value) : token.value;
|
|
800
|
+
return token.encodedBytes;
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* @param {ByteWriter} writer
|
|
804
|
+
* @param {Token} token
|
|
805
|
+
*/
|
|
806
|
+
function encodeBytes$2(writer, token) {
|
|
807
|
+
const bytes = tokenBytes$2(token);
|
|
808
|
+
encodeUintValue$2(writer, token.type.majorEncoded, bytes.length);
|
|
809
|
+
writer.push(bytes);
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* @param {Token} token
|
|
813
|
+
* @returns {number}
|
|
814
|
+
*/
|
|
815
|
+
encodeBytes$2.encodedSize = function encodedSize(token) {
|
|
816
|
+
const bytes = tokenBytes$2(token);
|
|
817
|
+
return encodeUintValue$2.encodedSize(bytes.length) + bytes.length;
|
|
818
|
+
};
|
|
819
|
+
/**
|
|
820
|
+
* @param {Token} tok1
|
|
821
|
+
* @param {Token} tok2
|
|
822
|
+
* @returns {number}
|
|
823
|
+
*/
|
|
824
|
+
encodeBytes$2.compareTokens = function compareTokens(tok1, tok2) {
|
|
825
|
+
return compareBytes$2(tokenBytes$2(tok1), tokenBytes$2(tok2));
|
|
826
|
+
};
|
|
827
|
+
/**
|
|
828
|
+
* @param {Uint8Array} b1
|
|
829
|
+
* @param {Uint8Array} b2
|
|
830
|
+
* @returns {number}
|
|
831
|
+
*/
|
|
832
|
+
function compareBytes$2(b1, b2) {
|
|
833
|
+
return b1.length < b2.length ? -1 : b1.length > b2.length ? 1 : compare$2(b1, b2);
|
|
834
|
+
}
|
|
835
|
+
//#endregion
|
|
836
|
+
//#region node_modules/kubo-rpc-client/node_modules/cborg/lib/3string.js
|
|
837
|
+
const textDecoder$2 = new TextDecoder();
|
|
838
|
+
const ASCII_THRESHOLD$2 = 32;
|
|
839
|
+
/**
|
|
840
|
+
* @typedef {import('../interface.js').ByteWriter} ByteWriter
|
|
841
|
+
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
842
|
+
*/
|
|
843
|
+
/**
|
|
844
|
+
* Decode UTF-8 bytes to string. For short ASCII strings (common case for map keys),
|
|
845
|
+
* a simple loop is faster than TextDecoder.
|
|
846
|
+
* @param {Uint8Array} bytes
|
|
847
|
+
* @param {number} start
|
|
848
|
+
* @param {number} end
|
|
849
|
+
* @returns {string}
|
|
850
|
+
*/
|
|
851
|
+
function toStr$2(bytes, start, end) {
|
|
852
|
+
if (end - start < ASCII_THRESHOLD$2) {
|
|
853
|
+
let str = "";
|
|
854
|
+
for (let i = start; i < end; i++) {
|
|
855
|
+
const c = bytes[i];
|
|
856
|
+
if (c & 128) return textDecoder$2.decode(bytes.subarray(start, end));
|
|
857
|
+
str += String.fromCharCode(c);
|
|
858
|
+
}
|
|
859
|
+
return str;
|
|
860
|
+
}
|
|
861
|
+
return textDecoder$2.decode(bytes.subarray(start, end));
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* @param {Uint8Array} data
|
|
865
|
+
* @param {number} pos
|
|
866
|
+
* @param {number} prefix
|
|
867
|
+
* @param {number} length
|
|
868
|
+
* @param {DecodeOptions} options
|
|
869
|
+
* @returns {Token}
|
|
870
|
+
*/
|
|
871
|
+
function toToken$10(data, pos, prefix, length, options) {
|
|
872
|
+
const totLength = prefix + length;
|
|
873
|
+
assertEnoughData$2(data, pos, totLength);
|
|
874
|
+
const tok = new Token$2(Type$2.string, toStr$2(data, pos + prefix, pos + totLength), totLength);
|
|
875
|
+
if (options.retainStringBytes === true) tok.byteValue = data.slice(pos + prefix, pos + totLength);
|
|
876
|
+
return tok;
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* @param {Uint8Array} data
|
|
880
|
+
* @param {number} pos
|
|
881
|
+
* @param {number} minor
|
|
882
|
+
* @param {DecodeOptions} options
|
|
883
|
+
* @returns {Token}
|
|
884
|
+
*/
|
|
885
|
+
function decodeStringCompact$2(data, pos, minor, options) {
|
|
886
|
+
return toToken$10(data, pos, 1, minor, options);
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* @param {Uint8Array} data
|
|
890
|
+
* @param {number} pos
|
|
891
|
+
* @param {number} _minor
|
|
892
|
+
* @param {DecodeOptions} options
|
|
893
|
+
* @returns {Token}
|
|
894
|
+
*/
|
|
895
|
+
function decodeString8$2(data, pos, _minor, options) {
|
|
896
|
+
return toToken$10(data, pos, 2, readUint8$2(data, pos + 1, options), options);
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* @param {Uint8Array} data
|
|
900
|
+
* @param {number} pos
|
|
901
|
+
* @param {number} _minor
|
|
902
|
+
* @param {DecodeOptions} options
|
|
903
|
+
* @returns {Token}
|
|
904
|
+
*/
|
|
905
|
+
function decodeString16$2(data, pos, _minor, options) {
|
|
906
|
+
return toToken$10(data, pos, 3, readUint16$2(data, pos + 1, options), options);
|
|
907
|
+
}
|
|
908
|
+
/**
|
|
909
|
+
* @param {Uint8Array} data
|
|
910
|
+
* @param {number} pos
|
|
911
|
+
* @param {number} _minor
|
|
912
|
+
* @param {DecodeOptions} options
|
|
913
|
+
* @returns {Token}
|
|
914
|
+
*/
|
|
915
|
+
function decodeString32$2(data, pos, _minor, options) {
|
|
916
|
+
return toToken$10(data, pos, 5, readUint32$2(data, pos + 1, options), options);
|
|
917
|
+
}
|
|
918
|
+
/**
|
|
919
|
+
* @param {Uint8Array} data
|
|
920
|
+
* @param {number} pos
|
|
921
|
+
* @param {number} _minor
|
|
922
|
+
* @param {DecodeOptions} options
|
|
923
|
+
* @returns {Token}
|
|
924
|
+
*/
|
|
925
|
+
function decodeString64$2(data, pos, _minor, options) {
|
|
926
|
+
const l = readUint64$2(data, pos + 1, options);
|
|
927
|
+
if (typeof l === "bigint") throw new Error(`${decodeErrPrefix$2} 64-bit integer string lengths not supported`);
|
|
928
|
+
return toToken$10(data, pos, 9, l, options);
|
|
929
|
+
}
|
|
930
|
+
const encodeString$2 = encodeBytes$2;
|
|
931
|
+
//#endregion
|
|
932
|
+
//#region node_modules/kubo-rpc-client/node_modules/cborg/lib/4array.js
|
|
933
|
+
/**
|
|
934
|
+
* @typedef {import('../interface.js').ByteWriter} ByteWriter
|
|
935
|
+
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
936
|
+
*/
|
|
937
|
+
/**
|
|
938
|
+
* @param {Uint8Array} _data
|
|
939
|
+
* @param {number} _pos
|
|
940
|
+
* @param {number} prefix
|
|
941
|
+
* @param {number} length
|
|
942
|
+
* @returns {Token}
|
|
943
|
+
*/
|
|
944
|
+
function toToken$9(_data, _pos, prefix, length) {
|
|
945
|
+
return new Token$2(Type$2.array, length, prefix);
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* @param {Uint8Array} data
|
|
949
|
+
* @param {number} pos
|
|
950
|
+
* @param {number} minor
|
|
951
|
+
* @param {DecodeOptions} _options
|
|
952
|
+
* @returns {Token}
|
|
953
|
+
*/
|
|
954
|
+
function decodeArrayCompact$2(data, pos, minor, _options) {
|
|
955
|
+
return toToken$9(data, pos, 1, minor);
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* @param {Uint8Array} data
|
|
959
|
+
* @param {number} pos
|
|
960
|
+
* @param {number} _minor
|
|
961
|
+
* @param {DecodeOptions} options
|
|
962
|
+
* @returns {Token}
|
|
963
|
+
*/
|
|
964
|
+
function decodeArray8$2(data, pos, _minor, options) {
|
|
965
|
+
return toToken$9(data, pos, 2, readUint8$2(data, pos + 1, options));
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* @param {Uint8Array} data
|
|
969
|
+
* @param {number} pos
|
|
970
|
+
* @param {number} _minor
|
|
971
|
+
* @param {DecodeOptions} options
|
|
972
|
+
* @returns {Token}
|
|
973
|
+
*/
|
|
974
|
+
function decodeArray16$2(data, pos, _minor, options) {
|
|
975
|
+
return toToken$9(data, pos, 3, readUint16$2(data, pos + 1, options));
|
|
976
|
+
}
|
|
977
|
+
/**
|
|
978
|
+
* @param {Uint8Array} data
|
|
979
|
+
* @param {number} pos
|
|
980
|
+
* @param {number} _minor
|
|
981
|
+
* @param {DecodeOptions} options
|
|
982
|
+
* @returns {Token}
|
|
983
|
+
*/
|
|
984
|
+
function decodeArray32$2(data, pos, _minor, options) {
|
|
985
|
+
return toToken$9(data, pos, 5, readUint32$2(data, pos + 1, options));
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* @param {Uint8Array} data
|
|
989
|
+
* @param {number} pos
|
|
990
|
+
* @param {number} _minor
|
|
991
|
+
* @param {DecodeOptions} options
|
|
992
|
+
* @returns {Token}
|
|
993
|
+
*/
|
|
994
|
+
function decodeArray64$2(data, pos, _minor, options) {
|
|
995
|
+
const l = readUint64$2(data, pos + 1, options);
|
|
996
|
+
if (typeof l === "bigint") throw new Error(`${decodeErrPrefix$2} 64-bit integer array lengths not supported`);
|
|
997
|
+
return toToken$9(data, pos, 9, l);
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* @param {Uint8Array} data
|
|
1001
|
+
* @param {number} pos
|
|
1002
|
+
* @param {number} _minor
|
|
1003
|
+
* @param {DecodeOptions} options
|
|
1004
|
+
* @returns {Token}
|
|
1005
|
+
*/
|
|
1006
|
+
function decodeArrayIndefinite$2(data, pos, _minor, options) {
|
|
1007
|
+
if (options.allowIndefinite === false) throw new Error(`${decodeErrPrefix$2} indefinite length items not allowed`);
|
|
1008
|
+
return toToken$9(data, pos, 1, Infinity);
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* @param {ByteWriter} writer
|
|
1012
|
+
* @param {Token} token
|
|
1013
|
+
*/
|
|
1014
|
+
function encodeArray$2(writer, token) {
|
|
1015
|
+
encodeUintValue$2(writer, Type$2.array.majorEncoded, token.value);
|
|
1016
|
+
}
|
|
1017
|
+
encodeArray$2.compareTokens = encodeUint$2.compareTokens;
|
|
1018
|
+
/**
|
|
1019
|
+
* @param {Token} token
|
|
1020
|
+
* @returns {number}
|
|
1021
|
+
*/
|
|
1022
|
+
encodeArray$2.encodedSize = function encodedSize(token) {
|
|
1023
|
+
return encodeUintValue$2.encodedSize(token.value);
|
|
1024
|
+
};
|
|
1025
|
+
//#endregion
|
|
1026
|
+
//#region node_modules/kubo-rpc-client/node_modules/cborg/lib/5map.js
|
|
1027
|
+
/**
|
|
1028
|
+
* @typedef {import('../interface.js').ByteWriter} ByteWriter
|
|
1029
|
+
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
1030
|
+
*/
|
|
1031
|
+
/**
|
|
1032
|
+
* @param {Uint8Array} _data
|
|
1033
|
+
* @param {number} _pos
|
|
1034
|
+
* @param {number} prefix
|
|
1035
|
+
* @param {number} length
|
|
1036
|
+
* @returns {Token}
|
|
1037
|
+
*/
|
|
1038
|
+
function toToken$8(_data, _pos, prefix, length) {
|
|
1039
|
+
return new Token$2(Type$2.map, length, prefix);
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* @param {Uint8Array} data
|
|
1043
|
+
* @param {number} pos
|
|
1044
|
+
* @param {number} minor
|
|
1045
|
+
* @param {DecodeOptions} _options
|
|
1046
|
+
* @returns {Token}
|
|
1047
|
+
*/
|
|
1048
|
+
function decodeMapCompact$2(data, pos, minor, _options) {
|
|
1049
|
+
return toToken$8(data, pos, 1, minor);
|
|
1050
|
+
}
|
|
1051
|
+
/**
|
|
1052
|
+
* @param {Uint8Array} data
|
|
1053
|
+
* @param {number} pos
|
|
1054
|
+
* @param {number} _minor
|
|
1055
|
+
* @param {DecodeOptions} options
|
|
1056
|
+
* @returns {Token}
|
|
1057
|
+
*/
|
|
1058
|
+
function decodeMap8$2(data, pos, _minor, options) {
|
|
1059
|
+
return toToken$8(data, pos, 2, readUint8$2(data, pos + 1, options));
|
|
1060
|
+
}
|
|
1061
|
+
/**
|
|
1062
|
+
* @param {Uint8Array} data
|
|
1063
|
+
* @param {number} pos
|
|
1064
|
+
* @param {number} _minor
|
|
1065
|
+
* @param {DecodeOptions} options
|
|
1066
|
+
* @returns {Token}
|
|
1067
|
+
*/
|
|
1068
|
+
function decodeMap16$2(data, pos, _minor, options) {
|
|
1069
|
+
return toToken$8(data, pos, 3, readUint16$2(data, pos + 1, options));
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* @param {Uint8Array} data
|
|
1073
|
+
* @param {number} pos
|
|
1074
|
+
* @param {number} _minor
|
|
1075
|
+
* @param {DecodeOptions} options
|
|
1076
|
+
* @returns {Token}
|
|
1077
|
+
*/
|
|
1078
|
+
function decodeMap32$2(data, pos, _minor, options) {
|
|
1079
|
+
return toToken$8(data, pos, 5, readUint32$2(data, pos + 1, options));
|
|
1080
|
+
}
|
|
1081
|
+
/**
|
|
1082
|
+
* @param {Uint8Array} data
|
|
1083
|
+
* @param {number} pos
|
|
1084
|
+
* @param {number} _minor
|
|
1085
|
+
* @param {DecodeOptions} options
|
|
1086
|
+
* @returns {Token}
|
|
1087
|
+
*/
|
|
1088
|
+
function decodeMap64$2(data, pos, _minor, options) {
|
|
1089
|
+
const l = readUint64$2(data, pos + 1, options);
|
|
1090
|
+
if (typeof l === "bigint") throw new Error(`${decodeErrPrefix$2} 64-bit integer map lengths not supported`);
|
|
1091
|
+
return toToken$8(data, pos, 9, l);
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* @param {Uint8Array} data
|
|
1095
|
+
* @param {number} pos
|
|
1096
|
+
* @param {number} _minor
|
|
1097
|
+
* @param {DecodeOptions} options
|
|
1098
|
+
* @returns {Token}
|
|
1099
|
+
*/
|
|
1100
|
+
function decodeMapIndefinite$2(data, pos, _minor, options) {
|
|
1101
|
+
if (options.allowIndefinite === false) throw new Error(`${decodeErrPrefix$2} indefinite length items not allowed`);
|
|
1102
|
+
return toToken$8(data, pos, 1, Infinity);
|
|
1103
|
+
}
|
|
1104
|
+
/**
|
|
1105
|
+
* @param {ByteWriter} writer
|
|
1106
|
+
* @param {Token} token
|
|
1107
|
+
*/
|
|
1108
|
+
function encodeMap$2(writer, token) {
|
|
1109
|
+
encodeUintValue$2(writer, Type$2.map.majorEncoded, token.value);
|
|
1110
|
+
}
|
|
1111
|
+
encodeMap$2.compareTokens = encodeUint$2.compareTokens;
|
|
1112
|
+
/**
|
|
1113
|
+
* @param {Token} token
|
|
1114
|
+
* @returns {number}
|
|
1115
|
+
*/
|
|
1116
|
+
encodeMap$2.encodedSize = function encodedSize(token) {
|
|
1117
|
+
return encodeUintValue$2.encodedSize(token.value);
|
|
1118
|
+
};
|
|
1119
|
+
//#endregion
|
|
1120
|
+
//#region node_modules/kubo-rpc-client/node_modules/cborg/lib/6tag.js
|
|
1121
|
+
/**
|
|
1122
|
+
* @typedef {import('../interface.js').ByteWriter} ByteWriter
|
|
1123
|
+
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
1124
|
+
*/
|
|
1125
|
+
/**
|
|
1126
|
+
* @param {Uint8Array} _data
|
|
1127
|
+
* @param {number} _pos
|
|
1128
|
+
* @param {number} minor
|
|
1129
|
+
* @param {DecodeOptions} _options
|
|
1130
|
+
* @returns {Token}
|
|
1131
|
+
*/
|
|
1132
|
+
function decodeTagCompact$2(_data, _pos, minor, _options) {
|
|
1133
|
+
return new Token$2(Type$2.tag, minor, 1);
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* @param {Uint8Array} data
|
|
1137
|
+
* @param {number} pos
|
|
1138
|
+
* @param {number} _minor
|
|
1139
|
+
* @param {DecodeOptions} options
|
|
1140
|
+
* @returns {Token}
|
|
1141
|
+
*/
|
|
1142
|
+
function decodeTag8$2(data, pos, _minor, options) {
|
|
1143
|
+
return new Token$2(Type$2.tag, readUint8$2(data, pos + 1, options), 2);
|
|
1144
|
+
}
|
|
1145
|
+
/**
|
|
1146
|
+
* @param {Uint8Array} data
|
|
1147
|
+
* @param {number} pos
|
|
1148
|
+
* @param {number} _minor
|
|
1149
|
+
* @param {DecodeOptions} options
|
|
1150
|
+
* @returns {Token}
|
|
1151
|
+
*/
|
|
1152
|
+
function decodeTag16$2(data, pos, _minor, options) {
|
|
1153
|
+
return new Token$2(Type$2.tag, readUint16$2(data, pos + 1, options), 3);
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* @param {Uint8Array} data
|
|
1157
|
+
* @param {number} pos
|
|
1158
|
+
* @param {number} _minor
|
|
1159
|
+
* @param {DecodeOptions} options
|
|
1160
|
+
* @returns {Token}
|
|
1161
|
+
*/
|
|
1162
|
+
function decodeTag32$2(data, pos, _minor, options) {
|
|
1163
|
+
return new Token$2(Type$2.tag, readUint32$2(data, pos + 1, options), 5);
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* @param {Uint8Array} data
|
|
1167
|
+
* @param {number} pos
|
|
1168
|
+
* @param {number} _minor
|
|
1169
|
+
* @param {DecodeOptions} options
|
|
1170
|
+
* @returns {Token}
|
|
1171
|
+
*/
|
|
1172
|
+
function decodeTag64$2(data, pos, _minor, options) {
|
|
1173
|
+
return new Token$2(Type$2.tag, readUint64$2(data, pos + 1, options), 9);
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* @param {ByteWriter} writer
|
|
1177
|
+
* @param {Token} token
|
|
1178
|
+
*/
|
|
1179
|
+
function encodeTag$2(writer, token) {
|
|
1180
|
+
encodeUintValue$2(writer, Type$2.tag.majorEncoded, token.value);
|
|
1181
|
+
}
|
|
1182
|
+
encodeTag$2.compareTokens = encodeUint$2.compareTokens;
|
|
1183
|
+
/**
|
|
1184
|
+
* @param {Token} token
|
|
1185
|
+
* @returns {number}
|
|
1186
|
+
*/
|
|
1187
|
+
encodeTag$2.encodedSize = function encodedSize(token) {
|
|
1188
|
+
return encodeUintValue$2.encodedSize(token.value);
|
|
1189
|
+
};
|
|
1190
|
+
/**
|
|
1191
|
+
* @param {Uint8Array} _data
|
|
1192
|
+
* @param {number} _pos
|
|
1193
|
+
* @param {number} _minor
|
|
1194
|
+
* @param {DecodeOptions} options
|
|
1195
|
+
* @returns {Token}
|
|
1196
|
+
*/
|
|
1197
|
+
function decodeUndefined$2(_data, _pos, _minor, options) {
|
|
1198
|
+
if (options.allowUndefined === false) throw new Error(`${decodeErrPrefix$2} undefined values are not supported`);
|
|
1199
|
+
else if (options.coerceUndefinedToNull === true) return new Token$2(Type$2.null, null, 1);
|
|
1200
|
+
return new Token$2(Type$2.undefined, void 0, 1);
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* @param {Uint8Array} _data
|
|
1204
|
+
* @param {number} _pos
|
|
1205
|
+
* @param {number} _minor
|
|
1206
|
+
* @param {DecodeOptions} options
|
|
1207
|
+
* @returns {Token}
|
|
1208
|
+
*/
|
|
1209
|
+
function decodeBreak$2(_data, _pos, _minor, options) {
|
|
1210
|
+
if (options.allowIndefinite === false) throw new Error(`${decodeErrPrefix$2} indefinite length items not allowed`);
|
|
1211
|
+
return new Token$2(Type$2.break, void 0, 1);
|
|
1212
|
+
}
|
|
1213
|
+
/**
|
|
1214
|
+
* @param {number} value
|
|
1215
|
+
* @param {number} bytes
|
|
1216
|
+
* @param {DecodeOptions} options
|
|
1217
|
+
* @returns {Token}
|
|
1218
|
+
*/
|
|
1219
|
+
function createToken$2(value, bytes, options) {
|
|
1220
|
+
if (options) {
|
|
1221
|
+
if (options.allowNaN === false && Number.isNaN(value)) throw new Error(`${decodeErrPrefix$2} NaN values are not supported`);
|
|
1222
|
+
if (options.allowInfinity === false && (value === Infinity || value === -Infinity)) throw new Error(`${decodeErrPrefix$2} Infinity values are not supported`);
|
|
1223
|
+
}
|
|
1224
|
+
return new Token$2(Type$2.float, value, bytes);
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* @param {Uint8Array} data
|
|
1228
|
+
* @param {number} pos
|
|
1229
|
+
* @param {number} _minor
|
|
1230
|
+
* @param {DecodeOptions} options
|
|
1231
|
+
* @returns {Token}
|
|
1232
|
+
*/
|
|
1233
|
+
function decodeFloat16$2(data, pos, _minor, options) {
|
|
1234
|
+
return createToken$2(readFloat16$2(data, pos + 1), 3, options);
|
|
1235
|
+
}
|
|
1236
|
+
/**
|
|
1237
|
+
* @param {Uint8Array} data
|
|
1238
|
+
* @param {number} pos
|
|
1239
|
+
* @param {number} _minor
|
|
1240
|
+
* @param {DecodeOptions} options
|
|
1241
|
+
* @returns {Token}
|
|
1242
|
+
*/
|
|
1243
|
+
function decodeFloat32$2(data, pos, _minor, options) {
|
|
1244
|
+
return createToken$2(readFloat32$2(data, pos + 1), 5, options);
|
|
1245
|
+
}
|
|
1246
|
+
/**
|
|
1247
|
+
* @param {Uint8Array} data
|
|
1248
|
+
* @param {number} pos
|
|
1249
|
+
* @param {number} _minor
|
|
1250
|
+
* @param {DecodeOptions} options
|
|
1251
|
+
* @returns {Token}
|
|
1252
|
+
*/
|
|
1253
|
+
function decodeFloat64$2(data, pos, _minor, options) {
|
|
1254
|
+
return createToken$2(readFloat64$2(data, pos + 1), 9, options);
|
|
1255
|
+
}
|
|
1256
|
+
/**
|
|
1257
|
+
* @param {ByteWriter} writer
|
|
1258
|
+
* @param {Token} token
|
|
1259
|
+
* @param {EncodeOptions} options
|
|
1260
|
+
*/
|
|
1261
|
+
function encodeFloat$2(writer, token, options) {
|
|
1262
|
+
const float = token.value;
|
|
1263
|
+
if (float === false) writer.pushByte(Type$2.float.majorEncoded | 20);
|
|
1264
|
+
else if (float === true) writer.pushByte(Type$2.float.majorEncoded | 21);
|
|
1265
|
+
else if (float === null) writer.pushByte(Type$2.float.majorEncoded | 22);
|
|
1266
|
+
else if (float === void 0) writer.pushByte(Type$2.float.majorEncoded | 23);
|
|
1267
|
+
else {
|
|
1268
|
+
let decoded;
|
|
1269
|
+
let success = false;
|
|
1270
|
+
if (!options || options.float64 !== true) {
|
|
1271
|
+
encodeFloat16$2(float);
|
|
1272
|
+
decoded = readFloat16$2(ui8a$2, 1);
|
|
1273
|
+
if (float === decoded || Number.isNaN(float)) {
|
|
1274
|
+
ui8a$2[0] = 249;
|
|
1275
|
+
writer.push(ui8a$2.slice(0, 3));
|
|
1276
|
+
success = true;
|
|
1277
|
+
} else {
|
|
1278
|
+
encodeFloat32$2(float);
|
|
1279
|
+
decoded = readFloat32$2(ui8a$2, 1);
|
|
1280
|
+
if (float === decoded) {
|
|
1281
|
+
ui8a$2[0] = 250;
|
|
1282
|
+
writer.push(ui8a$2.slice(0, 5));
|
|
1283
|
+
success = true;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
if (!success) {
|
|
1288
|
+
encodeFloat64$2(float);
|
|
1289
|
+
decoded = readFloat64$2(ui8a$2, 1);
|
|
1290
|
+
ui8a$2[0] = 251;
|
|
1291
|
+
writer.push(ui8a$2.slice(0, 9));
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
/**
|
|
1296
|
+
* @param {Token} token
|
|
1297
|
+
* @param {EncodeOptions} options
|
|
1298
|
+
* @returns {number}
|
|
1299
|
+
*/
|
|
1300
|
+
encodeFloat$2.encodedSize = function encodedSize(token, options) {
|
|
1301
|
+
const float = token.value;
|
|
1302
|
+
if (float === false || float === true || float === null || float === void 0) return 1;
|
|
1303
|
+
if (!options || options.float64 !== true) {
|
|
1304
|
+
encodeFloat16$2(float);
|
|
1305
|
+
let decoded = readFloat16$2(ui8a$2, 1);
|
|
1306
|
+
if (float === decoded || Number.isNaN(float)) return 3;
|
|
1307
|
+
encodeFloat32$2(float);
|
|
1308
|
+
decoded = readFloat32$2(ui8a$2, 1);
|
|
1309
|
+
if (float === decoded) return 5;
|
|
1310
|
+
}
|
|
1311
|
+
return 9;
|
|
1312
|
+
};
|
|
1313
|
+
const buffer$2 = /* @__PURE__ */ new ArrayBuffer(9);
|
|
1314
|
+
const dataView$2 = new DataView(buffer$2, 1);
|
|
1315
|
+
const ui8a$2 = new Uint8Array(buffer$2, 0);
|
|
1316
|
+
/**
|
|
1317
|
+
* @param {number} inp
|
|
1318
|
+
*/
|
|
1319
|
+
function encodeFloat16$2(inp) {
|
|
1320
|
+
if (inp === Infinity) dataView$2.setUint16(0, 31744, false);
|
|
1321
|
+
else if (inp === -Infinity) dataView$2.setUint16(0, 64512, false);
|
|
1322
|
+
else if (Number.isNaN(inp)) dataView$2.setUint16(0, 32256, false);
|
|
1323
|
+
else {
|
|
1324
|
+
dataView$2.setFloat32(0, inp);
|
|
1325
|
+
const valu32 = dataView$2.getUint32(0);
|
|
1326
|
+
const exponent = (valu32 & 2139095040) >> 23;
|
|
1327
|
+
const mantissa = valu32 & 8388607;
|
|
1328
|
+
if (exponent === 255) dataView$2.setUint16(0, 31744, false);
|
|
1329
|
+
else if (exponent === 0) dataView$2.setUint16(0, (valu32 & 2147483648) >> 16 | mantissa >> 13, false);
|
|
1330
|
+
else {
|
|
1331
|
+
const logicalExponent = exponent - 127;
|
|
1332
|
+
if (logicalExponent < -24) dataView$2.setUint16(0, 0);
|
|
1333
|
+
else if (logicalExponent < -14) dataView$2.setUint16(0, (valu32 & 2147483648) >> 16 | 1 << 24 + logicalExponent, false);
|
|
1334
|
+
else dataView$2.setUint16(0, (valu32 & 2147483648) >> 16 | logicalExponent + 15 << 10 | mantissa >> 13, false);
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* @param {Uint8Array} ui8a
|
|
1340
|
+
* @param {number} pos
|
|
1341
|
+
* @returns {number}
|
|
1342
|
+
*/
|
|
1343
|
+
function readFloat16$2(ui8a, pos) {
|
|
1344
|
+
if (ui8a.length - pos < 2) throw new Error(`${decodeErrPrefix$2} not enough data for float16`);
|
|
1345
|
+
const half = (ui8a[pos] << 8) + ui8a[pos + 1];
|
|
1346
|
+
if (half === 31744) return Infinity;
|
|
1347
|
+
if (half === 64512) return -Infinity;
|
|
1348
|
+
if (half === 32256) return NaN;
|
|
1349
|
+
const exp = half >> 10 & 31;
|
|
1350
|
+
const mant = half & 1023;
|
|
1351
|
+
let val;
|
|
1352
|
+
if (exp === 0) val = mant * 2 ** -24;
|
|
1353
|
+
else if (exp !== 31) val = (mant + 1024) * 2 ** (exp - 25);
|
|
1354
|
+
else val = mant === 0 ? Infinity : NaN;
|
|
1355
|
+
return half & 32768 ? -val : val;
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* @param {number} inp
|
|
1359
|
+
*/
|
|
1360
|
+
function encodeFloat32$2(inp) {
|
|
1361
|
+
dataView$2.setFloat32(0, inp, false);
|
|
1362
|
+
}
|
|
1363
|
+
/**
|
|
1364
|
+
* @param {Uint8Array} ui8a
|
|
1365
|
+
* @param {number} pos
|
|
1366
|
+
* @returns {number}
|
|
1367
|
+
*/
|
|
1368
|
+
function readFloat32$2(ui8a, pos) {
|
|
1369
|
+
if (ui8a.length - pos < 4) throw new Error(`${decodeErrPrefix$2} not enough data for float32`);
|
|
1370
|
+
const offset = (ui8a.byteOffset || 0) + pos;
|
|
1371
|
+
return new DataView(ui8a.buffer, offset, 4).getFloat32(0, false);
|
|
1372
|
+
}
|
|
1373
|
+
/**
|
|
1374
|
+
* @param {number} inp
|
|
1375
|
+
*/
|
|
1376
|
+
function encodeFloat64$2(inp) {
|
|
1377
|
+
dataView$2.setFloat64(0, inp, false);
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* @param {Uint8Array} ui8a
|
|
1381
|
+
* @param {number} pos
|
|
1382
|
+
* @returns {number}
|
|
1383
|
+
*/
|
|
1384
|
+
function readFloat64$2(ui8a, pos) {
|
|
1385
|
+
if (ui8a.length - pos < 8) throw new Error(`${decodeErrPrefix$2} not enough data for float64`);
|
|
1386
|
+
const offset = (ui8a.byteOffset || 0) + pos;
|
|
1387
|
+
return new DataView(ui8a.buffer, offset, 8).getFloat64(0, false);
|
|
1388
|
+
}
|
|
1389
|
+
/**
|
|
1390
|
+
* @typedef {Token & {
|
|
1391
|
+
* _keyBytes?: Uint8Array,
|
|
1392
|
+
* _keyBytesFloat64?: Uint8Array
|
|
1393
|
+
* }} TokenEx
|
|
1394
|
+
*/
|
|
1395
|
+
/**
|
|
1396
|
+
* The canonical CBOR bytes for a major 7 map key. The four simple values encode
|
|
1397
|
+
* to a single byte and every float to its 3, 5 or 9 byte form, exactly as
|
|
1398
|
+
* {@link encodeFloat} writes them. This mirrors the width selection in
|
|
1399
|
+
* `encodeFloat` because the sorter needs the bytes in hand to compare.
|
|
1400
|
+
* @param {Token} token
|
|
1401
|
+
* @param {boolean} float64
|
|
1402
|
+
* @returns {Uint8Array}
|
|
1403
|
+
*/
|
|
1404
|
+
function encodeMajorSevenBytes$1(token, float64) {
|
|
1405
|
+
const float = token.value;
|
|
1406
|
+
if (float === false) return Uint8Array.of(Type$2.float.majorEncoded | 20);
|
|
1407
|
+
if (float === true) return Uint8Array.of(Type$2.float.majorEncoded | 21);
|
|
1408
|
+
if (float === null) return Uint8Array.of(Type$2.float.majorEncoded | 22);
|
|
1409
|
+
if (float === void 0) return Uint8Array.of(Type$2.float.majorEncoded | 23);
|
|
1410
|
+
if (!float64) {
|
|
1411
|
+
encodeFloat16$2(float);
|
|
1412
|
+
if (float === readFloat16$2(ui8a$2, 1) || Number.isNaN(float)) {
|
|
1413
|
+
ui8a$2[0] = 249;
|
|
1414
|
+
return ui8a$2.slice(0, 3);
|
|
1415
|
+
}
|
|
1416
|
+
encodeFloat32$2(float);
|
|
1417
|
+
if (float === readFloat32$2(ui8a$2, 1)) {
|
|
1418
|
+
ui8a$2[0] = 250;
|
|
1419
|
+
return ui8a$2.slice(0, 5);
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
encodeFloat64$2(float);
|
|
1423
|
+
ui8a$2[0] = 251;
|
|
1424
|
+
return ui8a$2.slice(0, 9);
|
|
1425
|
+
}
|
|
1426
|
+
/**
|
|
1427
|
+
* Get the canonical CBOR bytes for a major 7 map key, honouring
|
|
1428
|
+
* `options.float64`. Bytes are cached because Array.sort compares each key
|
|
1429
|
+
* multiple times.
|
|
1430
|
+
* @param {Token} token
|
|
1431
|
+
* @param {EncodeOptions} [options]
|
|
1432
|
+
* @returns {Uint8Array}
|
|
1433
|
+
*/
|
|
1434
|
+
function majorSevenBytes$1(token, options) {
|
|
1435
|
+
const tokenEx = token;
|
|
1436
|
+
const float64 = options?.float64 === true;
|
|
1437
|
+
const cached = float64 ? tokenEx._keyBytesFloat64 : tokenEx._keyBytes;
|
|
1438
|
+
if (cached !== void 0) return cached;
|
|
1439
|
+
const bytes = encodeMajorSevenBytes$1(token, float64);
|
|
1440
|
+
if (float64) tokenEx._keyBytesFloat64 = bytes;
|
|
1441
|
+
else tokenEx._keyBytes = bytes;
|
|
1442
|
+
return bytes;
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Order two major 7 map keys by RFC 7049 §3.9 canonical order: shorter encoding
|
|
1446
|
+
* first, then bytewise. Because the four simple values encode to one byte they
|
|
1447
|
+
* sort ahead of every float, and comparing the `float64`-honouring encoded bytes
|
|
1448
|
+
* (rather than the numeric value) makes negative floats, mixed encoding widths
|
|
1449
|
+
* and `NaN` deterministic regardless of insertion order.
|
|
1450
|
+
* @param {Token} tok1
|
|
1451
|
+
* @param {Token} tok2
|
|
1452
|
+
* @param {EncodeOptions} [options]
|
|
1453
|
+
* @returns {number}
|
|
1454
|
+
*/
|
|
1455
|
+
encodeFloat$2.compareTokens = function compareTokens(tok1, tok2, options) {
|
|
1456
|
+
const b1 = majorSevenBytes$1(tok1, options);
|
|
1457
|
+
const b2 = majorSevenBytes$1(tok2, options);
|
|
1458
|
+
if (b1.length !== b2.length) return b1.length < b2.length ? -1 : 1;
|
|
1459
|
+
return compare$2(b1, b2);
|
|
1460
|
+
};
|
|
1461
|
+
//#endregion
|
|
1462
|
+
//#region node_modules/kubo-rpc-client/node_modules/cborg/lib/jump.js
|
|
1463
|
+
/**
|
|
1464
|
+
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
1465
|
+
* @typedef {import('../interface.js').AllocatedByteView} AllocatedByteView
|
|
1466
|
+
*/
|
|
1467
|
+
/**
|
|
1468
|
+
* @param {Uint8Array} data
|
|
1469
|
+
* @param {number} pos
|
|
1470
|
+
* @param {number} minor
|
|
1471
|
+
*/
|
|
1472
|
+
function invalidMinor$2(data, pos, minor) {
|
|
1473
|
+
throw new Error(`${decodeErrPrefix$2} encountered invalid minor (${minor}) for major ${data[pos] >>> 5}`);
|
|
1474
|
+
}
|
|
1475
|
+
/**
|
|
1476
|
+
* @param {string} msg
|
|
1477
|
+
* @returns {()=>any}
|
|
1478
|
+
*/
|
|
1479
|
+
function errorer$2(msg) {
|
|
1480
|
+
return () => {
|
|
1481
|
+
throw new Error(`${decodeErrPrefix$2} ${msg}`);
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
/** @type {((data:Uint8Array, pos:number, minor:number, options?:DecodeOptions) => any)[]} */
|
|
1485
|
+
const jump$2 = [];
|
|
1486
|
+
for (let i = 0; i <= 23; i++) jump$2[i] = invalidMinor$2;
|
|
1487
|
+
jump$2[24] = decodeUint8$2;
|
|
1488
|
+
jump$2[25] = decodeUint16$2;
|
|
1489
|
+
jump$2[26] = decodeUint32$2;
|
|
1490
|
+
jump$2[27] = decodeUint64$2;
|
|
1491
|
+
jump$2[28] = invalidMinor$2;
|
|
1492
|
+
jump$2[29] = invalidMinor$2;
|
|
1493
|
+
jump$2[30] = invalidMinor$2;
|
|
1494
|
+
jump$2[31] = invalidMinor$2;
|
|
1495
|
+
for (let i = 32; i <= 55; i++) jump$2[i] = invalidMinor$2;
|
|
1496
|
+
jump$2[56] = decodeNegint8$2;
|
|
1497
|
+
jump$2[57] = decodeNegint16$2;
|
|
1498
|
+
jump$2[58] = decodeNegint32$2;
|
|
1499
|
+
jump$2[59] = decodeNegint64$2;
|
|
1500
|
+
jump$2[60] = invalidMinor$2;
|
|
1501
|
+
jump$2[61] = invalidMinor$2;
|
|
1502
|
+
jump$2[62] = invalidMinor$2;
|
|
1503
|
+
jump$2[63] = invalidMinor$2;
|
|
1504
|
+
for (let i = 64; i <= 87; i++) jump$2[i] = decodeBytesCompact$2;
|
|
1505
|
+
jump$2[88] = decodeBytes8$2;
|
|
1506
|
+
jump$2[89] = decodeBytes16$2;
|
|
1507
|
+
jump$2[90] = decodeBytes32$2;
|
|
1508
|
+
jump$2[91] = decodeBytes64$2;
|
|
1509
|
+
jump$2[92] = invalidMinor$2;
|
|
1510
|
+
jump$2[93] = invalidMinor$2;
|
|
1511
|
+
jump$2[94] = invalidMinor$2;
|
|
1512
|
+
jump$2[95] = errorer$2("indefinite length bytes/strings are not supported");
|
|
1513
|
+
for (let i = 96; i <= 119; i++) jump$2[i] = decodeStringCompact$2;
|
|
1514
|
+
jump$2[120] = decodeString8$2;
|
|
1515
|
+
jump$2[121] = decodeString16$2;
|
|
1516
|
+
jump$2[122] = decodeString32$2;
|
|
1517
|
+
jump$2[123] = decodeString64$2;
|
|
1518
|
+
jump$2[124] = invalidMinor$2;
|
|
1519
|
+
jump$2[125] = invalidMinor$2;
|
|
1520
|
+
jump$2[126] = invalidMinor$2;
|
|
1521
|
+
jump$2[127] = errorer$2("indefinite length bytes/strings are not supported");
|
|
1522
|
+
for (let i = 128; i <= 151; i++) jump$2[i] = decodeArrayCompact$2;
|
|
1523
|
+
jump$2[152] = decodeArray8$2;
|
|
1524
|
+
jump$2[153] = decodeArray16$2;
|
|
1525
|
+
jump$2[154] = decodeArray32$2;
|
|
1526
|
+
jump$2[155] = decodeArray64$2;
|
|
1527
|
+
jump$2[156] = invalidMinor$2;
|
|
1528
|
+
jump$2[157] = invalidMinor$2;
|
|
1529
|
+
jump$2[158] = invalidMinor$2;
|
|
1530
|
+
jump$2[159] = decodeArrayIndefinite$2;
|
|
1531
|
+
for (let i = 160; i <= 183; i++) jump$2[i] = decodeMapCompact$2;
|
|
1532
|
+
jump$2[184] = decodeMap8$2;
|
|
1533
|
+
jump$2[185] = decodeMap16$2;
|
|
1534
|
+
jump$2[186] = decodeMap32$2;
|
|
1535
|
+
jump$2[187] = decodeMap64$2;
|
|
1536
|
+
jump$2[188] = invalidMinor$2;
|
|
1537
|
+
jump$2[189] = invalidMinor$2;
|
|
1538
|
+
jump$2[190] = invalidMinor$2;
|
|
1539
|
+
jump$2[191] = decodeMapIndefinite$2;
|
|
1540
|
+
for (let i = 192; i <= 215; i++) jump$2[i] = decodeTagCompact$2;
|
|
1541
|
+
jump$2[216] = decodeTag8$2;
|
|
1542
|
+
jump$2[217] = decodeTag16$2;
|
|
1543
|
+
jump$2[218] = decodeTag32$2;
|
|
1544
|
+
jump$2[219] = decodeTag64$2;
|
|
1545
|
+
jump$2[220] = invalidMinor$2;
|
|
1546
|
+
jump$2[221] = invalidMinor$2;
|
|
1547
|
+
jump$2[222] = invalidMinor$2;
|
|
1548
|
+
jump$2[223] = invalidMinor$2;
|
|
1549
|
+
for (let i = 224; i <= 243; i++) jump$2[i] = errorer$2("simple values are not supported");
|
|
1550
|
+
jump$2[244] = invalidMinor$2;
|
|
1551
|
+
jump$2[245] = invalidMinor$2;
|
|
1552
|
+
jump$2[246] = invalidMinor$2;
|
|
1553
|
+
jump$2[247] = decodeUndefined$2;
|
|
1554
|
+
jump$2[248] = errorer$2("simple values are not supported");
|
|
1555
|
+
jump$2[249] = decodeFloat16$2;
|
|
1556
|
+
jump$2[250] = decodeFloat32$2;
|
|
1557
|
+
jump$2[251] = decodeFloat64$2;
|
|
1558
|
+
jump$2[252] = invalidMinor$2;
|
|
1559
|
+
jump$2[253] = invalidMinor$2;
|
|
1560
|
+
jump$2[254] = invalidMinor$2;
|
|
1561
|
+
jump$2[255] = decodeBreak$2;
|
|
1562
|
+
/** @type {Token[]} */
|
|
1563
|
+
const quick$2 = [];
|
|
1564
|
+
for (let i = 0; i < 24; i++) quick$2[i] = new Token$2(Type$2.uint, i, 1);
|
|
1565
|
+
for (let i = -1; i >= -24; i--) quick$2[31 - i] = new Token$2(Type$2.negint, i, 1);
|
|
1566
|
+
quick$2[64] = new Token$2(Type$2.bytes, new Uint8Array(0), 1);
|
|
1567
|
+
quick$2[96] = new Token$2(Type$2.string, "", 1);
|
|
1568
|
+
quick$2[128] = new Token$2(Type$2.array, 0, 1);
|
|
1569
|
+
quick$2[160] = new Token$2(Type$2.map, 0, 1);
|
|
1570
|
+
quick$2[244] = new Token$2(Type$2.false, false, 1);
|
|
1571
|
+
quick$2[245] = new Token$2(Type$2.true, true, 1);
|
|
1572
|
+
quick$2[246] = new Token$2(Type$2.null, null, 1);
|
|
1573
|
+
/**
|
|
1574
|
+
* @param {Token} token
|
|
1575
|
+
* @returns {AllocatedByteView|undefined}
|
|
1576
|
+
*/
|
|
1577
|
+
function quickEncodeToken$2(token) {
|
|
1578
|
+
switch (token.type) {
|
|
1579
|
+
case Type$2.false: return fromArray$2([244]);
|
|
1580
|
+
case Type$2.true: return fromArray$2([245]);
|
|
1581
|
+
case Type$2.null: return fromArray$2([246]);
|
|
1582
|
+
case Type$2.bytes:
|
|
1583
|
+
if (!token.value.length) return fromArray$2([64]);
|
|
1584
|
+
return;
|
|
1585
|
+
case Type$2.string:
|
|
1586
|
+
if (token.value === "") return fromArray$2([96]);
|
|
1587
|
+
return;
|
|
1588
|
+
case Type$2.array:
|
|
1589
|
+
if (token.value === 0) return fromArray$2([128]);
|
|
1590
|
+
return;
|
|
1591
|
+
case Type$2.map:
|
|
1592
|
+
if (token.value === 0) return fromArray$2([160]);
|
|
1593
|
+
return;
|
|
1594
|
+
case Type$2.uint:
|
|
1595
|
+
if (token.value < 24) return fromArray$2([Number(token.value)]);
|
|
1596
|
+
return;
|
|
1597
|
+
case Type$2.negint: if (token.value >= -24) return fromArray$2([31 - Number(token.value)]);
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
//#endregion
|
|
1601
|
+
//#region node_modules/kubo-rpc-client/node_modules/cborg/lib/encode.js
|
|
1602
|
+
/**
|
|
1603
|
+
* @typedef {import('../interface.js').EncodeOptions} EncodeOptions
|
|
1604
|
+
* @typedef {import('../interface.js').OptionalTypeEncoder} OptionalTypeEncoder
|
|
1605
|
+
* @typedef {import('../interface.js').Reference} Reference
|
|
1606
|
+
* @typedef {import('../interface.js').StrictTypeEncoder} StrictTypeEncoder
|
|
1607
|
+
* @typedef {import('../interface.js').TokenTypeEncoder} TokenTypeEncoder
|
|
1608
|
+
* @typedef {import('../interface.js').TokenOrNestedTokens} TokenOrNestedTokens
|
|
1609
|
+
* @typedef {import('../interface.js').ByteWriter} ByteWriter
|
|
1610
|
+
* @typedef {import('../interface.js').ByteView} ByteView
|
|
1611
|
+
* @typedef {import('../interface.js').AllocatedByteView} AllocatedByteView
|
|
1612
|
+
*/
|
|
1613
|
+
/** @type {EncodeOptions} */
|
|
1614
|
+
const defaultEncodeOptions$2 = {
|
|
1615
|
+
float64: false,
|
|
1616
|
+
mapSorter: mapSorter$2,
|
|
1617
|
+
quickEncodeToken: quickEncodeToken$2
|
|
1618
|
+
};
|
|
1619
|
+
/** @type {EncodeOptions} */
|
|
1620
|
+
const rfc8949EncodeOptions$2 = Object.freeze({
|
|
1621
|
+
mapSorter: rfc8949MapSorter$2,
|
|
1622
|
+
quickEncodeToken: quickEncodeToken$2
|
|
1623
|
+
});
|
|
1624
|
+
/** @returns {TokenTypeEncoder[]} */
|
|
1625
|
+
function makeCborEncoders$2() {
|
|
1626
|
+
const encoders = [];
|
|
1627
|
+
encoders[Type$2.uint.major] = encodeUint$2;
|
|
1628
|
+
encoders[Type$2.negint.major] = encodeNegint$2;
|
|
1629
|
+
encoders[Type$2.bytes.major] = encodeBytes$2;
|
|
1630
|
+
encoders[Type$2.string.major] = encodeString$2;
|
|
1631
|
+
encoders[Type$2.array.major] = encodeArray$2;
|
|
1632
|
+
encoders[Type$2.map.major] = encodeMap$2;
|
|
1633
|
+
encoders[Type$2.tag.major] = encodeTag$2;
|
|
1634
|
+
encoders[Type$2.float.major] = encodeFloat$2;
|
|
1635
|
+
return encoders;
|
|
1636
|
+
}
|
|
1637
|
+
const cborEncoders$2 = makeCborEncoders$2();
|
|
1638
|
+
const defaultWriter$2 = new Bl$2();
|
|
1639
|
+
/** @implements {Reference} */
|
|
1640
|
+
var Ref$2 = class Ref$2 {
|
|
1641
|
+
/**
|
|
1642
|
+
* @param {object|any[]} obj
|
|
1643
|
+
* @param {Reference|undefined} parent
|
|
1644
|
+
*/
|
|
1645
|
+
constructor(obj, parent) {
|
|
1646
|
+
this.obj = obj;
|
|
1647
|
+
this.parent = parent;
|
|
1648
|
+
}
|
|
1649
|
+
/**
|
|
1650
|
+
* @param {object|any[]} obj
|
|
1651
|
+
* @returns {boolean}
|
|
1652
|
+
*/
|
|
1653
|
+
includes(obj) {
|
|
1654
|
+
/** @type {Reference|undefined} */
|
|
1655
|
+
let p = this;
|
|
1656
|
+
do
|
|
1657
|
+
if (p.obj === obj) return true;
|
|
1658
|
+
while (p = p.parent);
|
|
1659
|
+
return false;
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1662
|
+
* @param {Reference|undefined} stack
|
|
1663
|
+
* @param {object|any[]} obj
|
|
1664
|
+
* @returns {Reference}
|
|
1665
|
+
*/
|
|
1666
|
+
static createCheck(stack, obj) {
|
|
1667
|
+
if (stack && stack.includes(obj)) throw new Error(`${encodeErrPrefix$2} object contains circular references`);
|
|
1668
|
+
return new Ref$2(obj, stack);
|
|
1669
|
+
}
|
|
1670
|
+
};
|
|
1671
|
+
const simpleTokens$2 = {
|
|
1672
|
+
null: new Token$2(Type$2.null, null),
|
|
1673
|
+
undefined: new Token$2(Type$2.undefined, void 0),
|
|
1674
|
+
true: new Token$2(Type$2.true, true),
|
|
1675
|
+
false: new Token$2(Type$2.false, false),
|
|
1676
|
+
emptyArray: new Token$2(Type$2.array, 0),
|
|
1677
|
+
emptyMap: new Token$2(Type$2.map, 0)
|
|
1678
|
+
};
|
|
1679
|
+
/** @type {{[typeName: string]: StrictTypeEncoder}} */
|
|
1680
|
+
const typeEncoders$2 = {
|
|
1681
|
+
/**
|
|
1682
|
+
* @param {any} obj
|
|
1683
|
+
* @param {string} _typ
|
|
1684
|
+
* @param {EncodeOptions} _options
|
|
1685
|
+
* @param {Reference} [_refStack]
|
|
1686
|
+
* @returns {TokenOrNestedTokens}
|
|
1687
|
+
*/
|
|
1688
|
+
number(obj, _typ, _options, _refStack) {
|
|
1689
|
+
if (!Number.isInteger(obj) || !Number.isSafeInteger(obj)) return new Token$2(Type$2.float, obj);
|
|
1690
|
+
else if (obj >= 0) return new Token$2(Type$2.uint, obj);
|
|
1691
|
+
else return new Token$2(Type$2.negint, obj);
|
|
1692
|
+
},
|
|
1693
|
+
/**
|
|
1694
|
+
* @param {any} obj
|
|
1695
|
+
* @param {string} _typ
|
|
1696
|
+
* @param {EncodeOptions} _options
|
|
1697
|
+
* @param {Reference} [_refStack]
|
|
1698
|
+
* @returns {TokenOrNestedTokens}
|
|
1699
|
+
*/
|
|
1700
|
+
bigint(obj, _typ, _options, _refStack) {
|
|
1701
|
+
if (obj >= BigInt(0)) return new Token$2(Type$2.uint, obj);
|
|
1702
|
+
else return new Token$2(Type$2.negint, obj);
|
|
1703
|
+
},
|
|
1704
|
+
/**
|
|
1705
|
+
* @param {any} obj
|
|
1706
|
+
* @param {string} _typ
|
|
1707
|
+
* @param {EncodeOptions} _options
|
|
1708
|
+
* @param {Reference} [_refStack]
|
|
1709
|
+
* @returns {TokenOrNestedTokens}
|
|
1710
|
+
*/
|
|
1711
|
+
Uint8Array(obj, _typ, _options, _refStack) {
|
|
1712
|
+
return new Token$2(Type$2.bytes, obj);
|
|
1713
|
+
},
|
|
1714
|
+
/**
|
|
1715
|
+
* @param {any} obj
|
|
1716
|
+
* @param {string} _typ
|
|
1717
|
+
* @param {EncodeOptions} _options
|
|
1718
|
+
* @param {Reference} [_refStack]
|
|
1719
|
+
* @returns {TokenOrNestedTokens}
|
|
1720
|
+
*/
|
|
1721
|
+
string(obj, _typ, _options, _refStack) {
|
|
1722
|
+
return new Token$2(Type$2.string, obj);
|
|
1723
|
+
},
|
|
1724
|
+
/**
|
|
1725
|
+
* @param {any} obj
|
|
1726
|
+
* @param {string} _typ
|
|
1727
|
+
* @param {EncodeOptions} _options
|
|
1728
|
+
* @param {Reference} [_refStack]
|
|
1729
|
+
* @returns {TokenOrNestedTokens}
|
|
1730
|
+
*/
|
|
1731
|
+
boolean(obj, _typ, _options, _refStack) {
|
|
1732
|
+
return obj ? simpleTokens$2.true : simpleTokens$2.false;
|
|
1733
|
+
},
|
|
1734
|
+
/**
|
|
1735
|
+
* @param {any} _obj
|
|
1736
|
+
* @param {string} _typ
|
|
1737
|
+
* @param {EncodeOptions} _options
|
|
1738
|
+
* @param {Reference} [_refStack]
|
|
1739
|
+
* @returns {TokenOrNestedTokens}
|
|
1740
|
+
*/
|
|
1741
|
+
null(_obj, _typ, _options, _refStack) {
|
|
1742
|
+
return simpleTokens$2.null;
|
|
1743
|
+
},
|
|
1744
|
+
/**
|
|
1745
|
+
* @param {any} _obj
|
|
1746
|
+
* @param {string} _typ
|
|
1747
|
+
* @param {EncodeOptions} _options
|
|
1748
|
+
* @param {Reference} [_refStack]
|
|
1749
|
+
* @returns {TokenOrNestedTokens}
|
|
1750
|
+
*/
|
|
1751
|
+
undefined(_obj, _typ, _options, _refStack) {
|
|
1752
|
+
return simpleTokens$2.undefined;
|
|
1753
|
+
},
|
|
1754
|
+
/**
|
|
1755
|
+
* @param {any} obj
|
|
1756
|
+
* @param {string} _typ
|
|
1757
|
+
* @param {EncodeOptions} _options
|
|
1758
|
+
* @param {Reference} [_refStack]
|
|
1759
|
+
* @returns {TokenOrNestedTokens}
|
|
1760
|
+
*/
|
|
1761
|
+
ArrayBuffer(obj, _typ, _options, _refStack) {
|
|
1762
|
+
return new Token$2(Type$2.bytes, new Uint8Array(obj));
|
|
1763
|
+
},
|
|
1764
|
+
/**
|
|
1765
|
+
* @param {any} obj
|
|
1766
|
+
* @param {string} _typ
|
|
1767
|
+
* @param {EncodeOptions} _options
|
|
1768
|
+
* @param {Reference} [_refStack]
|
|
1769
|
+
* @returns {TokenOrNestedTokens}
|
|
1770
|
+
*/
|
|
1771
|
+
DataView(obj, _typ, _options, _refStack) {
|
|
1772
|
+
return new Token$2(Type$2.bytes, new Uint8Array(obj.buffer, obj.byteOffset, obj.byteLength));
|
|
1773
|
+
},
|
|
1774
|
+
/**
|
|
1775
|
+
* @param {any} obj
|
|
1776
|
+
* @param {string} _typ
|
|
1777
|
+
* @param {EncodeOptions} options
|
|
1778
|
+
* @param {Reference} [refStack]
|
|
1779
|
+
* @returns {TokenOrNestedTokens}
|
|
1780
|
+
*/
|
|
1781
|
+
Array(obj, _typ, options, refStack) {
|
|
1782
|
+
if (!obj.length) {
|
|
1783
|
+
if (options.addBreakTokens === true) return [simpleTokens$2.emptyArray, new Token$2(Type$2.break)];
|
|
1784
|
+
return simpleTokens$2.emptyArray;
|
|
1785
|
+
}
|
|
1786
|
+
refStack = Ref$2.createCheck(refStack, obj);
|
|
1787
|
+
const entries = [];
|
|
1788
|
+
let i = 0;
|
|
1789
|
+
for (const e of obj) entries[i++] = objectToTokens$2(e, options, refStack);
|
|
1790
|
+
if (options.addBreakTokens) return [
|
|
1791
|
+
new Token$2(Type$2.array, obj.length),
|
|
1792
|
+
entries,
|
|
1793
|
+
new Token$2(Type$2.break)
|
|
1794
|
+
];
|
|
1795
|
+
return [new Token$2(Type$2.array, obj.length), entries];
|
|
1796
|
+
},
|
|
1797
|
+
/**
|
|
1798
|
+
* @param {any} obj
|
|
1799
|
+
* @param {string} typ
|
|
1800
|
+
* @param {EncodeOptions} options
|
|
1801
|
+
* @param {Reference} [refStack]
|
|
1802
|
+
* @returns {TokenOrNestedTokens}
|
|
1803
|
+
*/
|
|
1804
|
+
Object(obj, typ, options, refStack) {
|
|
1805
|
+
const isMap = typ !== "Object";
|
|
1806
|
+
const keys = isMap ? obj.keys() : Object.keys(obj);
|
|
1807
|
+
const maxLength = isMap ? obj.size : keys.length;
|
|
1808
|
+
/** @type {undefined | [TokenOrNestedTokens, TokenOrNestedTokens][]} */
|
|
1809
|
+
let entries;
|
|
1810
|
+
if (maxLength) {
|
|
1811
|
+
entries = new Array(maxLength);
|
|
1812
|
+
refStack = Ref$2.createCheck(refStack, obj);
|
|
1813
|
+
const skipUndefined = !isMap && options.ignoreUndefinedProperties;
|
|
1814
|
+
let i = 0;
|
|
1815
|
+
for (const key of keys) {
|
|
1816
|
+
const value = isMap ? obj.get(key) : obj[key];
|
|
1817
|
+
if (skipUndefined && value === void 0) continue;
|
|
1818
|
+
entries[i++] = [objectToTokens$2(key, options, refStack), objectToTokens$2(value, options, refStack)];
|
|
1819
|
+
}
|
|
1820
|
+
if (i < maxLength) entries.length = i;
|
|
1821
|
+
}
|
|
1822
|
+
if (!entries?.length) {
|
|
1823
|
+
if (options.addBreakTokens === true) return [simpleTokens$2.emptyMap, new Token$2(Type$2.break)];
|
|
1824
|
+
return simpleTokens$2.emptyMap;
|
|
1825
|
+
}
|
|
1826
|
+
sortMapEntries$2(entries, options);
|
|
1827
|
+
if (options.addBreakTokens) return [
|
|
1828
|
+
new Token$2(Type$2.map, entries.length),
|
|
1829
|
+
entries,
|
|
1830
|
+
new Token$2(Type$2.break)
|
|
1831
|
+
];
|
|
1832
|
+
return [new Token$2(Type$2.map, entries.length), entries];
|
|
1833
|
+
},
|
|
1834
|
+
/**
|
|
1835
|
+
* Encode a `Tagged` wrapper as a CBOR tag header followed by the encoded
|
|
1836
|
+
* form of the wrapped value. The value is recursively tokenised through
|
|
1837
|
+
* `objectToTokens()` so any registered `typeEncoders` apply to it.
|
|
1838
|
+
*
|
|
1839
|
+
* @param {any} obj
|
|
1840
|
+
* @param {string} _typ
|
|
1841
|
+
* @param {EncodeOptions} options
|
|
1842
|
+
* @param {Reference} [refStack]
|
|
1843
|
+
* @returns {TokenOrNestedTokens}
|
|
1844
|
+
*/
|
|
1845
|
+
Tagged(obj, _typ, options, refStack) {
|
|
1846
|
+
return [new Token$2(Type$2.tag, obj.tag), objectToTokens$2(obj.value, options, refStack)];
|
|
1847
|
+
}
|
|
1848
|
+
};
|
|
1849
|
+
typeEncoders$2.Map = typeEncoders$2.Object;
|
|
1850
|
+
typeEncoders$2.Buffer = typeEncoders$2.Uint8Array;
|
|
1851
|
+
for (const typ of "Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" ")) typeEncoders$2[`${typ}Array`] = typeEncoders$2.DataView;
|
|
1852
|
+
/**
|
|
1853
|
+
* @param {any} obj
|
|
1854
|
+
* @param {EncodeOptions} [options]
|
|
1855
|
+
* @param {Reference} [refStack]
|
|
1856
|
+
* @returns {TokenOrNestedTokens}
|
|
1857
|
+
*/
|
|
1858
|
+
function objectToTokens$2(obj, options = {}, refStack) {
|
|
1859
|
+
const typ = is$2(obj);
|
|
1860
|
+
const customTypeEncoder = options && options.typeEncoders && options.typeEncoders[typ] || typeEncoders$2[typ];
|
|
1861
|
+
if (typeof customTypeEncoder === "function") {
|
|
1862
|
+
const tokens = customTypeEncoder(obj, typ, options, refStack);
|
|
1863
|
+
if (tokens != null) return tokens;
|
|
1864
|
+
}
|
|
1865
|
+
const typeEncoder = typeEncoders$2[typ];
|
|
1866
|
+
if (!typeEncoder) throw new Error(`${encodeErrPrefix$2} unsupported type: ${typ}`);
|
|
1867
|
+
return typeEncoder(obj, typ, options, refStack);
|
|
1868
|
+
}
|
|
1869
|
+
/**
|
|
1870
|
+
* @param {TokenOrNestedTokens[]} entries
|
|
1871
|
+
* @param {EncodeOptions} options
|
|
1872
|
+
*/
|
|
1873
|
+
function sortMapEntries$2(entries, options) {
|
|
1874
|
+
const mapSorter = options.mapSorter;
|
|
1875
|
+
if (mapSorter) entries.sort((e1, e2) => mapSorter(e1, e2, options));
|
|
1876
|
+
}
|
|
1877
|
+
/**
|
|
1878
|
+
* @param {(Token|Token[])[]} e1
|
|
1879
|
+
* @param {(Token|Token[])[]} e2
|
|
1880
|
+
* @param {EncodeOptions} [options]
|
|
1881
|
+
* @returns {number}
|
|
1882
|
+
*/
|
|
1883
|
+
function mapSorter$2(e1, e2, options) {
|
|
1884
|
+
const keyToken1 = Array.isArray(e1[0]) ? e1[0][0] : e1[0];
|
|
1885
|
+
const keyToken2 = Array.isArray(e2[0]) ? e2[0][0] : e2[0];
|
|
1886
|
+
if (keyToken1.type.major !== keyToken2.type.major) return keyToken1.type.compare(keyToken2.type);
|
|
1887
|
+
const tcmp = cborEncoders$2[keyToken1.type.major].compareTokens(keyToken1, keyToken2, options);
|
|
1888
|
+
if (tcmp === 0) console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone");
|
|
1889
|
+
return tcmp;
|
|
1890
|
+
}
|
|
1891
|
+
/**
|
|
1892
|
+
* @typedef {Token & { _keyBytes?: AllocatedByteView }} TokenEx
|
|
1893
|
+
*
|
|
1894
|
+
* @param {(Token|Token[])[]} e1
|
|
1895
|
+
* @param {(Token|Token[])[]} e2
|
|
1896
|
+
* @returns {number}
|
|
1897
|
+
*/
|
|
1898
|
+
function rfc8949MapSorter$2(e1, e2) {
|
|
1899
|
+
if (e1[0] instanceof Token$2 && e2[0] instanceof Token$2) {
|
|
1900
|
+
const t1 = e1[0];
|
|
1901
|
+
const t2 = e2[0];
|
|
1902
|
+
if (!t1._keyBytes) t1._keyBytes = encodeRfc8949$2(t1.value);
|
|
1903
|
+
if (!t2._keyBytes) t2._keyBytes = encodeRfc8949$2(t2.value);
|
|
1904
|
+
return compare$2(t1._keyBytes, t2._keyBytes);
|
|
1905
|
+
}
|
|
1906
|
+
throw new Error("rfc8949MapSorter: complex key types are not supported yet");
|
|
1907
|
+
}
|
|
1908
|
+
/**
|
|
1909
|
+
* @param {any} data
|
|
1910
|
+
* @returns {AllocatedByteView}
|
|
1911
|
+
*/
|
|
1912
|
+
function encodeRfc8949$2(data) {
|
|
1913
|
+
return encodeCustom$2(data, cborEncoders$2, rfc8949EncodeOptions$2);
|
|
1914
|
+
}
|
|
1915
|
+
/**
|
|
1916
|
+
* @param {ByteWriter} writer
|
|
1917
|
+
* @param {TokenOrNestedTokens} tokens
|
|
1918
|
+
* @param {TokenTypeEncoder[]} encoders
|
|
1919
|
+
* @param {EncodeOptions} options
|
|
1920
|
+
*/
|
|
1921
|
+
function tokensToEncoded$2(writer, tokens, encoders, options) {
|
|
1922
|
+
if (Array.isArray(tokens)) for (const token of tokens) tokensToEncoded$2(writer, token, encoders, options);
|
|
1923
|
+
else encoders[tokens.type.major](writer, tokens, options);
|
|
1924
|
+
}
|
|
1925
|
+
const MAJOR_UINT$2 = Type$2.uint.majorEncoded;
|
|
1926
|
+
const MAJOR_NEGINT$2 = Type$2.negint.majorEncoded;
|
|
1927
|
+
const MAJOR_BYTES$2 = Type$2.bytes.majorEncoded;
|
|
1928
|
+
const MAJOR_STRING$2 = Type$2.string.majorEncoded;
|
|
1929
|
+
const MAJOR_ARRAY$2 = Type$2.array.majorEncoded;
|
|
1930
|
+
const MAJOR_MAP$1 = Type$2.map.majorEncoded;
|
|
1931
|
+
const SIMPLE_FALSE$2 = Type$2.float.majorEncoded | 20;
|
|
1932
|
+
const SIMPLE_TRUE$2 = Type$2.float.majorEncoded | 21;
|
|
1933
|
+
const SIMPLE_NULL$2 = Type$2.float.majorEncoded | 22;
|
|
1934
|
+
const SIMPLE_UNDEFINED$2 = Type$2.float.majorEncoded | 23;
|
|
1935
|
+
const neg1b$3 = BigInt(-1);
|
|
1936
|
+
const pos1b$3 = BigInt(1);
|
|
1937
|
+
/**
|
|
1938
|
+
* Compact direct-path writes avoid the full uint boundary chain.
|
|
1939
|
+
* @param {ByteWriter} writer
|
|
1940
|
+
* @param {number} major
|
|
1941
|
+
* @param {number|bigint} uint
|
|
1942
|
+
*/
|
|
1943
|
+
function directEncodeUintValue(writer, major, uint) {
|
|
1944
|
+
if (uint < 24) writer.pushByte(major | Number(uint));
|
|
1945
|
+
else encodeUintValue$2(writer, major, uint);
|
|
1946
|
+
}
|
|
1947
|
+
/**
|
|
1948
|
+
* Check if direct encoding can be used for the given options.
|
|
1949
|
+
* Direct encoding bypasses token creation for most values.
|
|
1950
|
+
* @param {EncodeOptions} options
|
|
1951
|
+
* @returns {boolean}
|
|
1952
|
+
*/
|
|
1953
|
+
function canDirectEncode$1(options) {
|
|
1954
|
+
return options.addBreakTokens !== true;
|
|
1955
|
+
}
|
|
1956
|
+
/**
|
|
1957
|
+
* Encode a map through the default deterministic sorter while keeping values
|
|
1958
|
+
* on the direct path. Only keys need tokens for comparison.
|
|
1959
|
+
* @param {ByteWriter} writer
|
|
1960
|
+
* @param {any} data
|
|
1961
|
+
* @param {string} typ
|
|
1962
|
+
* @param {EncodeOptions} options
|
|
1963
|
+
* @param {Reference|undefined} refStack
|
|
1964
|
+
*/
|
|
1965
|
+
function directEncodeMap(writer, data, typ, options, refStack) {
|
|
1966
|
+
const isMap = typ === "Map";
|
|
1967
|
+
const keys = isMap ? data.keys() : Object.keys(data);
|
|
1968
|
+
const maxLength = isMap ? data.size : keys.length;
|
|
1969
|
+
if (!maxLength) {
|
|
1970
|
+
writer.pushByte(MAJOR_MAP$1);
|
|
1971
|
+
return;
|
|
1972
|
+
}
|
|
1973
|
+
refStack = Ref$2.createCheck(refStack, data);
|
|
1974
|
+
const skipUndefined = !isMap && options.ignoreUndefinedProperties;
|
|
1975
|
+
const entries = new Array(maxLength);
|
|
1976
|
+
let length = 0;
|
|
1977
|
+
for (const key of keys) {
|
|
1978
|
+
const value = isMap ? data.get(key) : data[key];
|
|
1979
|
+
if (skipUndefined && value === void 0) continue;
|
|
1980
|
+
entries[length++] = [objectToTokens$2(key, options, refStack), value];
|
|
1981
|
+
}
|
|
1982
|
+
if (length === 0) {
|
|
1983
|
+
writer.pushByte(MAJOR_MAP$1);
|
|
1984
|
+
return;
|
|
1985
|
+
}
|
|
1986
|
+
if (length < maxLength) entries.length = length;
|
|
1987
|
+
entries.sort((e1, e2) => mapSorter$2(e1, e2, options));
|
|
1988
|
+
directEncodeUintValue(writer, MAJOR_MAP$1, length);
|
|
1989
|
+
for (const [key, value] of entries) {
|
|
1990
|
+
tokensToEncoded$2(writer, key, cborEncoders$2, options);
|
|
1991
|
+
directEncode$1(writer, value, options, refStack);
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
/**
|
|
1995
|
+
* Direct encode a value to the writer, bypassing token creation for most types.
|
|
1996
|
+
* Falls back to token-based encoding for custom type encoders.
|
|
1997
|
+
* @param {ByteWriter} writer
|
|
1998
|
+
* @param {any} data
|
|
1999
|
+
* @param {EncodeOptions} options
|
|
2000
|
+
* @param {Reference|undefined} refStack
|
|
2001
|
+
*/
|
|
2002
|
+
function directEncode$1(writer, data, options, refStack) {
|
|
2003
|
+
const typ = is$2(data);
|
|
2004
|
+
const customEncoder = options.typeEncoders && options.typeEncoders[typ];
|
|
2005
|
+
if (customEncoder) {
|
|
2006
|
+
const tokens = customEncoder(data, typ, options, refStack);
|
|
2007
|
+
if (tokens != null) {
|
|
2008
|
+
tokensToEncoded$2(writer, tokens, cborEncoders$2, options);
|
|
2009
|
+
return;
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
switch (typ) {
|
|
2013
|
+
case "null":
|
|
2014
|
+
writer.pushByte(SIMPLE_NULL$2);
|
|
2015
|
+
return;
|
|
2016
|
+
case "undefined":
|
|
2017
|
+
writer.pushByte(SIMPLE_UNDEFINED$2);
|
|
2018
|
+
return;
|
|
2019
|
+
case "boolean":
|
|
2020
|
+
writer.pushByte(data ? SIMPLE_TRUE$2 : SIMPLE_FALSE$2);
|
|
2021
|
+
return;
|
|
2022
|
+
case "number":
|
|
2023
|
+
if (!Number.isInteger(data) || !Number.isSafeInteger(data)) encodeFloat$2(writer, new Token$2(Type$2.float, data), options);
|
|
2024
|
+
else if (data >= 0) directEncodeUintValue(writer, MAJOR_UINT$2, data);
|
|
2025
|
+
else directEncodeUintValue(writer, MAJOR_NEGINT$2, data * -1 - 1);
|
|
2026
|
+
return;
|
|
2027
|
+
case "bigint":
|
|
2028
|
+
if (data >= BigInt(0)) directEncodeUintValue(writer, MAJOR_UINT$2, data);
|
|
2029
|
+
else directEncodeUintValue(writer, MAJOR_NEGINT$2, data * neg1b$3 - pos1b$3);
|
|
2030
|
+
return;
|
|
2031
|
+
case "string": {
|
|
2032
|
+
const bytes = fromString$3(data);
|
|
2033
|
+
directEncodeUintValue(writer, MAJOR_STRING$2, bytes.length);
|
|
2034
|
+
writer.push(bytes);
|
|
2035
|
+
return;
|
|
2036
|
+
}
|
|
2037
|
+
case "Uint8Array":
|
|
2038
|
+
directEncodeUintValue(writer, MAJOR_BYTES$2, data.length);
|
|
2039
|
+
writer.push(data);
|
|
2040
|
+
return;
|
|
2041
|
+
case "Array":
|
|
2042
|
+
if (!data.length) {
|
|
2043
|
+
writer.pushByte(MAJOR_ARRAY$2);
|
|
2044
|
+
return;
|
|
2045
|
+
}
|
|
2046
|
+
refStack = Ref$2.createCheck(refStack, data);
|
|
2047
|
+
directEncodeUintValue(writer, MAJOR_ARRAY$2, data.length);
|
|
2048
|
+
for (const elem of data) directEncode$1(writer, elem, options, refStack);
|
|
2049
|
+
return;
|
|
2050
|
+
case "Object":
|
|
2051
|
+
case "Map":
|
|
2052
|
+
if (options.mapSorter === mapSorter$2) directEncodeMap(writer, data, typ, options, refStack);
|
|
2053
|
+
else tokensToEncoded$2(writer, typeEncoders$2.Object(data, typ, options, refStack), cborEncoders$2, options);
|
|
2054
|
+
return;
|
|
2055
|
+
default: {
|
|
2056
|
+
const typeEncoder = typeEncoders$2[typ];
|
|
2057
|
+
if (!typeEncoder) throw new Error(`${encodeErrPrefix$2} unsupported type: ${typ}`);
|
|
2058
|
+
tokensToEncoded$2(writer, typeEncoder(data, typ, options, refStack), cborEncoders$2, options);
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
/**
|
|
2063
|
+
* @template {ArrayBufferLike} T
|
|
2064
|
+
* @overload
|
|
2065
|
+
* @param {any} data
|
|
2066
|
+
* @param {TokenTypeEncoder[]} encoders
|
|
2067
|
+
* @param {EncodeOptions} options
|
|
2068
|
+
* @param {Uint8Array<T>} destination
|
|
2069
|
+
* @returns {Uint8Array<T>}
|
|
2070
|
+
*/
|
|
2071
|
+
/**
|
|
2072
|
+
* @overload
|
|
2073
|
+
* @param {any} data
|
|
2074
|
+
* @param {TokenTypeEncoder[]} encoders
|
|
2075
|
+
* @param {EncodeOptions} options
|
|
2076
|
+
* @returns {AllocatedByteView}
|
|
2077
|
+
*/
|
|
2078
|
+
/**
|
|
2079
|
+
* @param {any} data
|
|
2080
|
+
* @param {TokenTypeEncoder[]} encoders
|
|
2081
|
+
* @param {EncodeOptions} options
|
|
2082
|
+
* @param {ByteView} [destination]
|
|
2083
|
+
* @returns {ByteView}
|
|
2084
|
+
*/
|
|
2085
|
+
function encodeCustom$2(data, encoders, options, destination) {
|
|
2086
|
+
const hasDest = destination instanceof Uint8Array;
|
|
2087
|
+
let writeTo = hasDest ? new U8Bl$2(destination) : defaultWriter$2;
|
|
2088
|
+
const tokens = objectToTokens$2(data, options);
|
|
2089
|
+
if (!Array.isArray(tokens) && options.quickEncodeToken) {
|
|
2090
|
+
const quickBytes = options.quickEncodeToken(tokens);
|
|
2091
|
+
if (quickBytes) {
|
|
2092
|
+
if (hasDest) {
|
|
2093
|
+
writeTo.push(quickBytes);
|
|
2094
|
+
return writeTo.toBytes();
|
|
2095
|
+
}
|
|
2096
|
+
return quickBytes;
|
|
2097
|
+
}
|
|
2098
|
+
const encoder = encoders[tokens.type.major];
|
|
2099
|
+
if (encoder.encodedSize) {
|
|
2100
|
+
const size = encoder.encodedSize(tokens, options);
|
|
2101
|
+
if (!hasDest) writeTo = new Bl$2(size);
|
|
2102
|
+
encoder(writeTo, tokens, options);
|
|
2103
|
+
if (writeTo.chunks.length !== 1) throw new Error(`Unexpected error: pre-calculated length for ${tokens} was wrong`);
|
|
2104
|
+
return hasDest ? writeTo.toBytes() : asU8A$2(writeTo.chunks[0]);
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
writeTo.reset();
|
|
2108
|
+
tokensToEncoded$2(writeTo, tokens, encoders, options);
|
|
2109
|
+
return writeTo.toBytes(true);
|
|
2110
|
+
}
|
|
2111
|
+
/**
|
|
2112
|
+
* @param {any} data
|
|
2113
|
+
* @param {EncodeOptions} [options]
|
|
2114
|
+
* @returns {AllocatedByteView}
|
|
2115
|
+
*/
|
|
2116
|
+
function encode$8(data, options) {
|
|
2117
|
+
options = Object.assign({}, defaultEncodeOptions$2, options);
|
|
2118
|
+
if (canDirectEncode$1(options)) {
|
|
2119
|
+
defaultWriter$2.reset();
|
|
2120
|
+
directEncode$1(defaultWriter$2, data, options, void 0);
|
|
2121
|
+
return defaultWriter$2.toBytes(true);
|
|
2122
|
+
}
|
|
2123
|
+
return encodeCustom$2(data, cborEncoders$2, options);
|
|
2124
|
+
}
|
|
2125
|
+
//#endregion
|
|
2126
|
+
//#region node_modules/kubo-rpc-client/node_modules/cborg/lib/decode.js
|
|
2127
|
+
/**
|
|
2128
|
+
* @typedef {import('./token.js').Token} Token
|
|
2129
|
+
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
2130
|
+
* @typedef {import('../interface.js').DecodeTokenizer} DecodeTokenizer
|
|
2131
|
+
* @typedef {import('../interface.js').TagDecodeControl} TagDecodeControl
|
|
2132
|
+
*/
|
|
2133
|
+
const defaultDecodeOptions$2 = {
|
|
2134
|
+
strict: false,
|
|
2135
|
+
allowIndefinite: true,
|
|
2136
|
+
allowUndefined: true,
|
|
2137
|
+
allowBigInt: true
|
|
2138
|
+
};
|
|
2139
|
+
/**
|
|
2140
|
+
* @implements {DecodeTokenizer}
|
|
2141
|
+
*/
|
|
2142
|
+
var Tokeniser$2 = class {
|
|
2143
|
+
/**
|
|
2144
|
+
* @param {Uint8Array} data
|
|
2145
|
+
* @param {DecodeOptions} options
|
|
2146
|
+
*/
|
|
2147
|
+
constructor(data, options = {}) {
|
|
2148
|
+
this._pos = 0;
|
|
2149
|
+
this.data = data;
|
|
2150
|
+
this.options = options;
|
|
2151
|
+
}
|
|
2152
|
+
pos() {
|
|
2153
|
+
return this._pos;
|
|
2154
|
+
}
|
|
2155
|
+
done() {
|
|
2156
|
+
return this._pos >= this.data.length;
|
|
2157
|
+
}
|
|
2158
|
+
next() {
|
|
2159
|
+
const byt = this.data[this._pos];
|
|
2160
|
+
let token = quick$2[byt];
|
|
2161
|
+
if (token === void 0) {
|
|
2162
|
+
const decoder = jump$2[byt];
|
|
2163
|
+
if (!decoder) throw new Error(`${decodeErrPrefix$2} no decoder for major type ${byt >>> 5} (byte 0x${byt.toString(16).padStart(2, "0")})`);
|
|
2164
|
+
const minor = byt & 31;
|
|
2165
|
+
token = decoder(this.data, this._pos, minor, this.options);
|
|
2166
|
+
}
|
|
2167
|
+
this._pos += token.encodedLength;
|
|
2168
|
+
return token;
|
|
2169
|
+
}
|
|
2170
|
+
};
|
|
2171
|
+
const DONE$2 = Symbol.for("DONE");
|
|
2172
|
+
const BREAK$2 = Symbol.for("BREAK");
|
|
2173
|
+
/**
|
|
2174
|
+
* @param {Token} token
|
|
2175
|
+
* @param {DecodeTokenizer} tokeniser
|
|
2176
|
+
* @param {DecodeOptions} options
|
|
2177
|
+
* @returns {any|typeof BREAK|typeof DONE}
|
|
2178
|
+
*/
|
|
2179
|
+
function tokenToArray$2(token, tokeniser, options) {
|
|
2180
|
+
const arr = [];
|
|
2181
|
+
for (let i = 0; i < token.value; i++) {
|
|
2182
|
+
const value = tokensToObject$2(tokeniser, options);
|
|
2183
|
+
if (value === BREAK$2) {
|
|
2184
|
+
if (token.value === Infinity) break;
|
|
2185
|
+
throw new Error(`${decodeErrPrefix$2} got unexpected break to lengthed array`);
|
|
2186
|
+
}
|
|
2187
|
+
if (value === DONE$2) throw new Error(`${decodeErrPrefix$2} found array but not enough entries (got ${i}, expected ${token.value})`);
|
|
2188
|
+
arr[i] = value;
|
|
2189
|
+
}
|
|
2190
|
+
return arr;
|
|
2191
|
+
}
|
|
2192
|
+
/**
|
|
2193
|
+
* @param {Token} token
|
|
2194
|
+
* @param {DecodeTokenizer} tokeniser
|
|
2195
|
+
* @param {DecodeOptions} options
|
|
2196
|
+
* @returns {any|typeof BREAK|typeof DONE}
|
|
2197
|
+
*/
|
|
2198
|
+
function tokenToMap$2(token, tokeniser, options) {
|
|
2199
|
+
const useMaps = options.useMaps === true;
|
|
2200
|
+
const rejectDuplicateMapKeys = options.rejectDuplicateMapKeys === true;
|
|
2201
|
+
const obj = useMaps ? void 0 : {};
|
|
2202
|
+
const m = useMaps ? /* @__PURE__ */ new Map() : void 0;
|
|
2203
|
+
for (let i = 0; i < token.value; i++) {
|
|
2204
|
+
const key = tokensToObject$2(tokeniser, options);
|
|
2205
|
+
if (key === BREAK$2) {
|
|
2206
|
+
if (token.value === Infinity) break;
|
|
2207
|
+
throw new Error(`${decodeErrPrefix$2} got unexpected break to lengthed map`);
|
|
2208
|
+
}
|
|
2209
|
+
if (key === DONE$2) throw new Error(`${decodeErrPrefix$2} found map but not enough entries (got ${i} [no key], expected ${token.value})`);
|
|
2210
|
+
if (!useMaps && typeof key !== "string") throw new Error(`${decodeErrPrefix$2} non-string keys not supported (got ${typeof key})`);
|
|
2211
|
+
if (rejectDuplicateMapKeys) {
|
|
2212
|
+
if (useMaps && m.has(key) || !useMaps && Object.hasOwn(obj, key)) throw new Error(`${decodeErrPrefix$2} found repeat map key "${key}"`);
|
|
2213
|
+
}
|
|
2214
|
+
const value = tokensToObject$2(tokeniser, options);
|
|
2215
|
+
if (value === DONE$2) throw new Error(`${decodeErrPrefix$2} found map but not enough entries (got ${i} [no value], expected ${token.value})`);
|
|
2216
|
+
if (useMaps) m.set(key, value);
|
|
2217
|
+
else obj[key] = value;
|
|
2218
|
+
}
|
|
2219
|
+
return useMaps ? m : obj;
|
|
2220
|
+
}
|
|
2221
|
+
/**
|
|
2222
|
+
* Generator that yields [key, value] entries from a CBOR map token.
|
|
2223
|
+
* Used by tag decoders that need to preserve key types (e.g., Tag 259 Map).
|
|
2224
|
+
* @param {Token} token - The map token
|
|
2225
|
+
* @param {DecodeTokenizer} tokeniser
|
|
2226
|
+
* @param {DecodeOptions} options
|
|
2227
|
+
* @returns {Generator<[any, any], void, unknown>}
|
|
2228
|
+
*/
|
|
2229
|
+
function* tokenToMapEntries$2(token, tokeniser, options) {
|
|
2230
|
+
for (let i = 0; i < token.value; i++) {
|
|
2231
|
+
const key = tokensToObject$2(tokeniser, options);
|
|
2232
|
+
if (key === BREAK$2) {
|
|
2233
|
+
if (token.value === Infinity) break;
|
|
2234
|
+
throw new Error(`${decodeErrPrefix$2} got unexpected break to lengthed map`);
|
|
2235
|
+
}
|
|
2236
|
+
if (key === DONE$2) throw new Error(`${decodeErrPrefix$2} found map but not enough entries (got ${i} [no key], expected ${token.value})`);
|
|
2237
|
+
const value = tokensToObject$2(tokeniser, options);
|
|
2238
|
+
if (value === DONE$2) throw new Error(`${decodeErrPrefix$2} found map but not enough entries (got ${i} [no value], expected ${token.value})`);
|
|
2239
|
+
yield [key, value];
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
/**
|
|
2243
|
+
* Creates a TagDecodeControl object for tag decoders.
|
|
2244
|
+
* @param {DecodeTokenizer} tokeniser
|
|
2245
|
+
* @param {DecodeOptions} options
|
|
2246
|
+
* @returns {TagDecodeControl}
|
|
2247
|
+
*/
|
|
2248
|
+
function createTagDecodeControl$2(tokeniser, options) {
|
|
2249
|
+
/** @type {TagDecodeControl & {_called: boolean}} */
|
|
2250
|
+
const decode = function() {
|
|
2251
|
+
if (decode._called) throw new Error(`${decodeErrPrefix$2} tag decode() may only be called once`);
|
|
2252
|
+
decode._called = true;
|
|
2253
|
+
const value = tokensToObject$2(tokeniser, options);
|
|
2254
|
+
if (value === DONE$2) throw new Error(`${decodeErrPrefix$2} tag content missing`);
|
|
2255
|
+
if (value === BREAK$2) throw new Error(`${decodeErrPrefix$2} got unexpected break in tag content`);
|
|
2256
|
+
return value;
|
|
2257
|
+
};
|
|
2258
|
+
decode.entries = function() {
|
|
2259
|
+
if (decode._called) throw new Error(`${decodeErrPrefix$2} tag decode() may only be called once`);
|
|
2260
|
+
decode._called = true;
|
|
2261
|
+
const token = tokeniser.next();
|
|
2262
|
+
if (!Type$2.equals(token.type, Type$2.map)) throw new Error(`${decodeErrPrefix$2} entries() requires map content, got ${token.type.name}`);
|
|
2263
|
+
const entries = [];
|
|
2264
|
+
for (const entry of tokenToMapEntries$2(token, tokeniser, options)) entries.push(entry);
|
|
2265
|
+
return entries;
|
|
2266
|
+
};
|
|
2267
|
+
decode._called = false;
|
|
2268
|
+
return decode;
|
|
2269
|
+
}
|
|
2270
|
+
/**
|
|
2271
|
+
* @param {DecodeTokenizer} tokeniser
|
|
2272
|
+
* @param {DecodeOptions} options
|
|
2273
|
+
* @returns {any|typeof BREAK|typeof DONE}
|
|
2274
|
+
*/
|
|
2275
|
+
function tokensToObject$2(tokeniser, options) {
|
|
2276
|
+
if (tokeniser.done()) return DONE$2;
|
|
2277
|
+
const token = tokeniser.next();
|
|
2278
|
+
if (Type$2.equals(token.type, Type$2.break)) return BREAK$2;
|
|
2279
|
+
if (token.type.terminal) return token.value;
|
|
2280
|
+
if (Type$2.equals(token.type, Type$2.array)) return tokenToArray$2(token, tokeniser, options);
|
|
2281
|
+
if (Type$2.equals(token.type, Type$2.map)) return tokenToMap$2(token, tokeniser, options);
|
|
2282
|
+
if (Type$2.equals(token.type, Type$2.tag)) {
|
|
2283
|
+
if (options.tags && typeof options.tags[token.value] === "function") {
|
|
2284
|
+
const decodeControl = createTagDecodeControl$2(tokeniser, options);
|
|
2285
|
+
const result = options.tags[token.value](decodeControl);
|
|
2286
|
+
if (!decodeControl._called) throw new Error(`${decodeErrPrefix$2} tag decoder must call decode() or entries()`);
|
|
2287
|
+
return result;
|
|
2288
|
+
}
|
|
2289
|
+
throw new Error(`${decodeErrPrefix$2} tag not supported (${token.value})`);
|
|
2290
|
+
}
|
|
2291
|
+
throw new Error("unsupported");
|
|
2292
|
+
}
|
|
2293
|
+
/**
|
|
2294
|
+
* @param {Uint8Array} data
|
|
2295
|
+
* @param {DecodeOptions} [options]
|
|
2296
|
+
* @returns {[any, Uint8Array]}
|
|
2297
|
+
*/
|
|
2298
|
+
function decodeFirst$2(data, options) {
|
|
2299
|
+
if (!(data instanceof Uint8Array)) throw new Error(`${decodeErrPrefix$2} data to decode must be a Uint8Array`);
|
|
2300
|
+
options = Object.assign({}, defaultDecodeOptions$2, options);
|
|
2301
|
+
const u8aData = asU8A$2(data);
|
|
2302
|
+
const tokeniser = options.tokenizer || new Tokeniser$2(u8aData, options);
|
|
2303
|
+
const decoded = tokensToObject$2(tokeniser, options);
|
|
2304
|
+
if (decoded === DONE$2) throw new Error(`${decodeErrPrefix$2} did not find any content to decode`);
|
|
2305
|
+
if (decoded === BREAK$2) throw new Error(`${decodeErrPrefix$2} got unexpected break`);
|
|
2306
|
+
return [decoded, data.subarray(tokeniser.pos())];
|
|
2307
|
+
}
|
|
2308
|
+
/**
|
|
2309
|
+
* @param {Uint8Array} data
|
|
2310
|
+
* @param {DecodeOptions} [options]
|
|
2311
|
+
* @returns {any}
|
|
2312
|
+
*/
|
|
2313
|
+
function decode$9(data, options) {
|
|
2314
|
+
const [decoded, remainder] = decodeFirst$2(data, options);
|
|
2315
|
+
if (remainder.length > 0) throw new Error(`${decodeErrPrefix$2} too many terminals, data makes no sense`);
|
|
2316
|
+
return decoded;
|
|
2317
|
+
}
|
|
2318
|
+
Object.defineProperty(class Tagged$2 {
|
|
2319
|
+
/**
|
|
2320
|
+
* @param {number} tag - CBOR tag number, a non-negative integer
|
|
2321
|
+
* @param {any} value - The value to be tagged; encoded recursively
|
|
2322
|
+
*/
|
|
2323
|
+
constructor(tag, value) {
|
|
2324
|
+
if (typeof tag !== "number" || !Number.isInteger(tag) || tag < 0) throw new TypeError("Tagged: tag must be a non-negative integer");
|
|
2325
|
+
this.tag = tag;
|
|
2326
|
+
this.value = value;
|
|
2327
|
+
}
|
|
2328
|
+
/**
|
|
2329
|
+
* Build a tag decoder for use in `decode()`'s `tags` option that returns the
|
|
2330
|
+
* decoded content wrapped in a `Tagged` instance, preserving the tag number
|
|
2331
|
+
* for the caller to inspect.
|
|
2332
|
+
*
|
|
2333
|
+
* @param {number} tag - The CBOR tag number this decoder will be registered for
|
|
2334
|
+
* @returns {TaggedTagDecoder}
|
|
2335
|
+
*
|
|
2336
|
+
* @example
|
|
2337
|
+
* import { decode, Tagged } from 'cborg'
|
|
2338
|
+
* const value = decode(bytes, { tags: { 16: Tagged.decoder(16) } })
|
|
2339
|
+
* // value instanceof Tagged; value.tag === 16
|
|
2340
|
+
*/
|
|
2341
|
+
static decoder(tag) {
|
|
2342
|
+
return (decode) => new Tagged$2(tag, decode());
|
|
2343
|
+
}
|
|
2344
|
+
/**
|
|
2345
|
+
* Build a `tags` option for `decode()` that wraps each listed tag number in
|
|
2346
|
+
* a `Tagged` instance, preserving those tags through decode without
|
|
2347
|
+
* registering a dedicated decoder per tag.
|
|
2348
|
+
*
|
|
2349
|
+
* @param {...number} tagNumbers - One or more CBOR tag numbers to preserve
|
|
2350
|
+
* @returns {{[tagNumber: number]: TaggedTagDecoder}}
|
|
2351
|
+
*
|
|
2352
|
+
* @example
|
|
2353
|
+
* import { decode, Tagged } from 'cborg'
|
|
2354
|
+
* const value = decode(bytes, { tags: Tagged.preserve(16, 96) })
|
|
2355
|
+
*/
|
|
2356
|
+
static preserve(...tagNumbers) {
|
|
2357
|
+
/** @type {{[tagNumber: number]: TaggedTagDecoder}} */
|
|
2358
|
+
const tags = {};
|
|
2359
|
+
for (const tag of tagNumbers) tags[tag] = Tagged$2.decoder(tag);
|
|
2360
|
+
return tags;
|
|
2361
|
+
}
|
|
2362
|
+
}.prototype, Symbol.toStringTag, { value: "Tagged" });
|
|
2363
|
+
//#endregion
|
|
2364
|
+
//#region node_modules/kubo-rpc-client/node_modules/@ipld/dag-cbor/src/index.js
|
|
2365
|
+
var src_exports$1 = /* @__PURE__ */ __exportAll({
|
|
2366
|
+
code: () => 113,
|
|
2367
|
+
decode: () => decode$8,
|
|
2368
|
+
decodeOptions: () => decodeOptions$2,
|
|
2369
|
+
encode: () => encode$7,
|
|
2370
|
+
encodeOptions: () => encodeOptions$2,
|
|
2371
|
+
name: () => name$2,
|
|
2372
|
+
toByteView: () => toByteView$2
|
|
2373
|
+
});
|
|
2374
|
+
const CID_CBOR_TAG$1 = 42;
|
|
2375
|
+
/**
|
|
2376
|
+
* @template T
|
|
2377
|
+
* @typedef {import('multiformats/codecs/interface').ByteView<T>} ByteView
|
|
2378
|
+
*/
|
|
2379
|
+
/**
|
|
2380
|
+
* @template T
|
|
2381
|
+
* @typedef {import('multiformats/codecs/interface').ArrayBufferView<T>} ArrayBufferView
|
|
2382
|
+
*/
|
|
2383
|
+
/**
|
|
2384
|
+
* @template T
|
|
2385
|
+
* @param {ByteView<T> | ArrayBufferView<T>} buf
|
|
2386
|
+
* @returns {ByteView<T>}
|
|
2387
|
+
*/
|
|
2388
|
+
function toByteView$2(buf) {
|
|
2389
|
+
if (buf instanceof ArrayBuffer) return new Uint8Array(buf, 0, buf.byteLength);
|
|
2390
|
+
return buf;
|
|
2391
|
+
}
|
|
2392
|
+
/**
|
|
2393
|
+
* cidEncoder will receive all Objects during encode, it needs to filter out
|
|
2394
|
+
* anything that's not a CID and return `null` for that so it's encoded as
|
|
2395
|
+
* normal.
|
|
2396
|
+
*
|
|
2397
|
+
* @param {any} obj
|
|
2398
|
+
* @returns {cborg.Token[]|null}
|
|
2399
|
+
*/
|
|
2400
|
+
function cidEncoder$2(obj) {
|
|
2401
|
+
if (obj.asCID !== obj && obj["/"] !== obj.bytes) return null;
|
|
2402
|
+
const cid = CID.asCID(obj);
|
|
2403
|
+
/* c8 ignore next 4 */
|
|
2404
|
+
if (!cid) return null;
|
|
2405
|
+
const bytes = new Uint8Array(cid.bytes.byteLength + 1);
|
|
2406
|
+
bytes.set(cid.bytes, 1);
|
|
2407
|
+
return [new Token$2(Type$2.tag, CID_CBOR_TAG$1), new Token$2(Type$2.bytes, bytes)];
|
|
2408
|
+
}
|
|
2409
|
+
/**
|
|
2410
|
+
* Intercept all `undefined` values from an object walk and reject the entire
|
|
2411
|
+
* object if we find one.
|
|
2412
|
+
*
|
|
2413
|
+
* @returns {null}
|
|
2414
|
+
*/
|
|
2415
|
+
function undefinedEncoder$2() {
|
|
2416
|
+
throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded");
|
|
2417
|
+
}
|
|
2418
|
+
/**
|
|
2419
|
+
* Intercept all `number` values from an object walk and reject the entire
|
|
2420
|
+
* object if we find something that doesn't fit the IPLD data model (NaN &
|
|
2421
|
+
* Infinity).
|
|
2422
|
+
*
|
|
2423
|
+
* @param {number} num
|
|
2424
|
+
* @returns {null}
|
|
2425
|
+
*/
|
|
2426
|
+
function numberEncoder$2(num) {
|
|
2427
|
+
if (Number.isNaN(num)) throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");
|
|
2428
|
+
if (num === Infinity || num === -Infinity) throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");
|
|
2429
|
+
return null;
|
|
2430
|
+
}
|
|
2431
|
+
/**
|
|
2432
|
+
* @param {Map<any, any>} map
|
|
2433
|
+
* @returns {null}
|
|
2434
|
+
*/
|
|
2435
|
+
function mapEncoder$1(map) {
|
|
2436
|
+
for (const key of map.keys()) if (typeof key !== "string" || key.length === 0) throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");
|
|
2437
|
+
return null;
|
|
2438
|
+
}
|
|
2439
|
+
const _encodeOptions$1 = {
|
|
2440
|
+
float64: true,
|
|
2441
|
+
typeEncoders: {
|
|
2442
|
+
Map: mapEncoder$1,
|
|
2443
|
+
Object: cidEncoder$2,
|
|
2444
|
+
undefined: undefinedEncoder$2,
|
|
2445
|
+
number: numberEncoder$2
|
|
2446
|
+
}
|
|
2447
|
+
};
|
|
2448
|
+
const encodeOptions$2 = {
|
|
2449
|
+
..._encodeOptions$1,
|
|
2450
|
+
typeEncoders: { ..._encodeOptions$1.typeEncoders }
|
|
2451
|
+
};
|
|
2452
|
+
/**
|
|
2453
|
+
* @param {import('cborg').TagDecodeControl} decode
|
|
2454
|
+
* @returns {CID}
|
|
2455
|
+
*/
|
|
2456
|
+
function cidDecoder$1(decode) {
|
|
2457
|
+
const bytes = decode();
|
|
2458
|
+
if (bytes[0] !== 0) throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");
|
|
2459
|
+
return CID.decode(bytes.subarray(1));
|
|
2460
|
+
}
|
|
2461
|
+
const _decodeOptions$1 = {
|
|
2462
|
+
allowIndefinite: false,
|
|
2463
|
+
coerceUndefinedToNull: true,
|
|
2464
|
+
allowNaN: false,
|
|
2465
|
+
allowInfinity: false,
|
|
2466
|
+
allowBigInt: true,
|
|
2467
|
+
strict: true,
|
|
2468
|
+
useMaps: false,
|
|
2469
|
+
rejectDuplicateMapKeys: true,
|
|
2470
|
+
/** @type {{ [tagNumber: number]: import('cborg').TagDecoder }} */
|
|
2471
|
+
tags: { [CID_CBOR_TAG$1]: cidDecoder$1 }
|
|
2472
|
+
};
|
|
2473
|
+
const decodeOptions$2 = {
|
|
2474
|
+
..._decodeOptions$1,
|
|
2475
|
+
tags: { ..._decodeOptions$1.tags }
|
|
2476
|
+
};
|
|
2477
|
+
const name$2 = "dag-cbor";
|
|
2478
|
+
/**
|
|
2479
|
+
* @template T
|
|
2480
|
+
* @param {T} node
|
|
2481
|
+
* @returns {ByteView<T>}
|
|
2482
|
+
*/
|
|
2483
|
+
const encode$7 = (node) => encode$8(node, _encodeOptions$1);
|
|
2484
|
+
/**
|
|
2485
|
+
* @template T
|
|
2486
|
+
* @param {ByteView<T> | ArrayBufferView<T>} data
|
|
2487
|
+
* @returns {T}
|
|
2488
|
+
*/
|
|
2489
|
+
const decode$8 = (data) => decode$9(toByteView$2(data), _decodeOptions$1);
|
|
2490
|
+
//#endregion
|
|
2491
|
+
//#region node_modules/@ipld/dag-json/node_modules/cborg/lib/is.js
|
|
23
2492
|
const objectTypeNames$1 = [
|
|
24
2493
|
"Object",
|
|
25
2494
|
"RegExp",
|
|
@@ -57,14 +2526,12 @@ function is$1(value) {
|
|
|
57
2526
|
if (value === true || value === false) return "boolean";
|
|
58
2527
|
const typeOf = typeof value;
|
|
59
2528
|
if (typeOf === "string" || typeOf === "number" || typeOf === "bigint" || typeOf === "symbol") return typeOf;
|
|
60
|
-
/* c8 ignore next 3 */
|
|
61
2529
|
if (typeOf === "function") return "Function";
|
|
62
2530
|
if (Array.isArray(value)) return "Array";
|
|
63
2531
|
if (value instanceof Uint8Array) return "Uint8Array";
|
|
64
2532
|
if (value.constructor === Object) return "Object";
|
|
65
2533
|
const objectType = getObjectType$1(value);
|
|
66
2534
|
if (objectType) return objectType;
|
|
67
|
-
/* c8 ignore next */
|
|
68
2535
|
return "Object";
|
|
69
2536
|
}
|
|
70
2537
|
/**
|
|
@@ -76,7 +2543,7 @@ function getObjectType$1(value) {
|
|
|
76
2543
|
if (objectTypeNames$1.includes(objectTypeName)) return objectTypeName;
|
|
77
2544
|
}
|
|
78
2545
|
//#endregion
|
|
79
|
-
//#region node_modules/
|
|
2546
|
+
//#region node_modules/@ipld/dag-json/node_modules/cborg/lib/token.js
|
|
80
2547
|
var Type$1 = class {
|
|
81
2548
|
/**
|
|
82
2549
|
* @param {number} major
|
|
@@ -89,7 +2556,6 @@ var Type$1 = class {
|
|
|
89
2556
|
this.name = name;
|
|
90
2557
|
this.terminal = terminal;
|
|
91
2558
|
}
|
|
92
|
-
/* c8 ignore next 3 */
|
|
93
2559
|
toString() {
|
|
94
2560
|
return `Type[${this.major}].${this.name}`;
|
|
95
2561
|
}
|
|
@@ -98,7 +2564,6 @@ var Type$1 = class {
|
|
|
98
2564
|
* @returns {number}
|
|
99
2565
|
*/
|
|
100
2566
|
compare(typ) {
|
|
101
|
-
/* c8 ignore next 1 */
|
|
102
2567
|
return this.major < typ.major ? -1 : this.major > typ.major ? 1 : 0;
|
|
103
2568
|
}
|
|
104
2569
|
/**
|
|
@@ -141,16 +2606,19 @@ var Token$1 = class {
|
|
|
141
2606
|
/** @type {Uint8Array|undefined} */
|
|
142
2607
|
this.byteValue = void 0;
|
|
143
2608
|
}
|
|
144
|
-
/* c8 ignore next 3 */
|
|
145
2609
|
toString() {
|
|
146
2610
|
return `Token[${this.type}].${this.value}`;
|
|
147
2611
|
}
|
|
148
2612
|
};
|
|
149
2613
|
//#endregion
|
|
150
|
-
//#region node_modules/
|
|
2614
|
+
//#region node_modules/@ipld/dag-json/node_modules/cborg/lib/byte-utils.js
|
|
151
2615
|
const useBuffer$1 = globalThis.process && !globalThis.process.browser && globalThis.Buffer && typeof globalThis.Buffer.isBuffer === "function";
|
|
152
2616
|
const textEncoder$1 = new TextEncoder();
|
|
153
2617
|
/**
|
|
2618
|
+
* @typedef {import('../interface.js').ByteView} ByteView
|
|
2619
|
+
* @typedef {import('../interface.js').AllocatedByteView} AllocatedByteView
|
|
2620
|
+
*/
|
|
2621
|
+
/**
|
|
154
2622
|
* @param {Uint8Array} buf
|
|
155
2623
|
* @returns {boolean}
|
|
156
2624
|
*/
|
|
@@ -158,11 +2626,10 @@ function isBuffer$1(buf) {
|
|
|
158
2626
|
return useBuffer$1 && globalThis.Buffer.isBuffer(buf);
|
|
159
2627
|
}
|
|
160
2628
|
/**
|
|
161
|
-
* @param {
|
|
162
|
-
* @returns {
|
|
2629
|
+
* @param {ByteView|number[]} buf
|
|
2630
|
+
* @returns {ByteView}
|
|
163
2631
|
*/
|
|
164
2632
|
function asU8A$1(buf) {
|
|
165
|
-
/* c8 ignore next */
|
|
166
2633
|
if (!(buf instanceof Uint8Array)) return Uint8Array.from(buf);
|
|
167
2634
|
return isBuffer$1(buf) ? new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength) : buf;
|
|
168
2635
|
}
|
|
@@ -180,7 +2647,7 @@ const fromString$2 = useBuffer$1 ? (string) => {
|
|
|
180
2647
|
/**
|
|
181
2648
|
* Buffer variant not fast enough for what we need
|
|
182
2649
|
* @param {number[]} arr
|
|
183
|
-
* @returns {
|
|
2650
|
+
* @returns {AllocatedByteView}
|
|
184
2651
|
*/
|
|
185
2652
|
const fromArray$1 = (arr) => {
|
|
186
2653
|
return Uint8Array.from(arr);
|
|
@@ -198,14 +2665,13 @@ const slice$1 = useBuffer$1 ? (bytes, start, end) => {
|
|
|
198
2665
|
return bytes.slice(start, end);
|
|
199
2666
|
};
|
|
200
2667
|
const concat$1 = useBuffer$1 ? (chunks, length) => {
|
|
201
|
-
/* c8 ignore next 1 */
|
|
202
2668
|
chunks = chunks.map((c) => c instanceof Uint8Array ? c : globalThis.Buffer.from(c));
|
|
203
2669
|
return asU8A$1(globalThis.Buffer.concat(chunks, length));
|
|
204
2670
|
} :
|
|
205
2671
|
/**
|
|
206
|
-
* @param {
|
|
2672
|
+
* @param {ByteView[]} chunks
|
|
207
2673
|
* @param {number} length
|
|
208
|
-
* @returns {
|
|
2674
|
+
* @returns {AllocatedByteView}
|
|
209
2675
|
*/
|
|
210
2676
|
(chunks, length) => {
|
|
211
2677
|
const out = new Uint8Array(length);
|
|
@@ -222,7 +2688,7 @@ const alloc$1 = useBuffer$1 ? (size) => {
|
|
|
222
2688
|
} :
|
|
223
2689
|
/**
|
|
224
2690
|
* @param {number} size
|
|
225
|
-
* @returns {
|
|
2691
|
+
* @returns {AllocatedByteView}
|
|
226
2692
|
*/
|
|
227
2693
|
(size) => {
|
|
228
2694
|
return new Uint8Array(size);
|
|
@@ -233,7 +2699,6 @@ const alloc$1 = useBuffer$1 ? (size) => {
|
|
|
233
2699
|
* @returns {number}
|
|
234
2700
|
*/
|
|
235
2701
|
function compare$1(b1, b2) {
|
|
236
|
-
/* c8 ignore next 5 */
|
|
237
2702
|
if (isBuffer$1(b1) && isBuffer$1(b2)) return b1.compare(b2);
|
|
238
2703
|
for (let i = 0; i < b1.length; i++) {
|
|
239
2704
|
if (b1[i] === b2[i]) continue;
|
|
@@ -277,14 +2742,13 @@ const MAX_ARGUMENTS_LENGTH = 4096;
|
|
|
277
2742
|
function decodeCodePointsArray(codePoints) {
|
|
278
2743
|
const len = codePoints.length;
|
|
279
2744
|
if (len <= MAX_ARGUMENTS_LENGTH) return String.fromCharCode.apply(String, codePoints);
|
|
280
|
-
/* c8 ignore next 10 */
|
|
281
2745
|
let res = "";
|
|
282
2746
|
let i = 0;
|
|
283
2747
|
while (i < len) res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));
|
|
284
2748
|
return res;
|
|
285
2749
|
}
|
|
286
2750
|
//#endregion
|
|
287
|
-
//#region node_modules/
|
|
2751
|
+
//#region node_modules/@ipld/dag-json/node_modules/cborg/lib/bl.js
|
|
288
2752
|
/**
|
|
289
2753
|
* Bl is a list of byte chunks, similar to https://github.com/rvagg/bl but for
|
|
290
2754
|
* writing rather than reading.
|
|
@@ -301,6 +2765,10 @@ function decodeCodePointsArray(codePoints) {
|
|
|
301
2765
|
* will be `0` to write at the current cursor position but it can be ahead of
|
|
302
2766
|
* the current cursor. Negative offsets probably work but are untested.
|
|
303
2767
|
*/
|
|
2768
|
+
/**
|
|
2769
|
+
* @typedef {import('../interface.js').ByteView} ByteView
|
|
2770
|
+
* @typedef {import('../interface.js').AllocatedByteView} AllocatedByteView
|
|
2771
|
+
*/
|
|
304
2772
|
const defaultChunkSize$1 = 256;
|
|
305
2773
|
var Bl$1 = class {
|
|
306
2774
|
/**
|
|
@@ -312,9 +2780,9 @@ var Bl$1 = class {
|
|
|
312
2780
|
this.cursor = 0;
|
|
313
2781
|
/** @type {number} */
|
|
314
2782
|
this.maxCursor = -1;
|
|
315
|
-
/** @type {(
|
|
2783
|
+
/** @type {(ByteView|number[])[]} */
|
|
316
2784
|
this.chunks = [];
|
|
317
|
-
/** @type {
|
|
2785
|
+
/** @type {ByteView|number[]|null} */
|
|
318
2786
|
this._initReuseChunk = null;
|
|
319
2787
|
}
|
|
320
2788
|
reset() {
|
|
@@ -327,7 +2795,22 @@ var Bl$1 = class {
|
|
|
327
2795
|
}
|
|
328
2796
|
}
|
|
329
2797
|
/**
|
|
330
|
-
* @param {
|
|
2798
|
+
* @param {number} byte
|
|
2799
|
+
*/
|
|
2800
|
+
pushByte(byte) {
|
|
2801
|
+
let topChunk = this.chunks[this.chunks.length - 1];
|
|
2802
|
+
if (this.cursor > this.maxCursor) {
|
|
2803
|
+
topChunk = alloc$1(this.chunkSize);
|
|
2804
|
+
this.chunks.push(topChunk);
|
|
2805
|
+
this.maxCursor += topChunk.length;
|
|
2806
|
+
if (this._initReuseChunk === null) this._initReuseChunk = topChunk;
|
|
2807
|
+
}
|
|
2808
|
+
const chunkPos = topChunk.length - (this.maxCursor - this.cursor) - 1;
|
|
2809
|
+
topChunk[chunkPos] = byte;
|
|
2810
|
+
this.cursor++;
|
|
2811
|
+
}
|
|
2812
|
+
/**
|
|
2813
|
+
* @param {ByteView|number[]} bytes
|
|
331
2814
|
*/
|
|
332
2815
|
push(bytes) {
|
|
333
2816
|
let topChunk = this.chunks[this.chunks.length - 1];
|
|
@@ -357,14 +2840,13 @@ var Bl$1 = class {
|
|
|
357
2840
|
}
|
|
358
2841
|
/**
|
|
359
2842
|
* @param {boolean} [reset]
|
|
360
|
-
* @returns {
|
|
2843
|
+
* @returns {AllocatedByteView}
|
|
361
2844
|
*/
|
|
362
2845
|
toBytes(reset = false) {
|
|
363
2846
|
let byts;
|
|
364
2847
|
if (this.chunks.length === 1) {
|
|
365
2848
|
const chunk = this.chunks[0];
|
|
366
2849
|
if (reset && this.cursor > chunk.length / 2) {
|
|
367
|
-
/* c8 ignore next 2 */
|
|
368
2850
|
byts = this.cursor === chunk.length ? chunk : chunk.subarray(0, this.cursor);
|
|
369
2851
|
this._initReuseChunk = null;
|
|
370
2852
|
this.chunks = [];
|
|
@@ -377,23 +2859,31 @@ var Bl$1 = class {
|
|
|
377
2859
|
/**
|
|
378
2860
|
* U8Bl is a buffer list that writes directly to a user-provided Uint8Array.
|
|
379
2861
|
* It provides the same interface as Bl but writes to a fixed destination.
|
|
2862
|
+
* @template {ArrayBufferLike} T
|
|
380
2863
|
*/
|
|
381
2864
|
var U8Bl$1 = class {
|
|
382
2865
|
/**
|
|
383
|
-
* @param {Uint8Array} dest
|
|
2866
|
+
* @param {Uint8Array<T>} dest
|
|
384
2867
|
*/
|
|
385
2868
|
constructor(dest) {
|
|
386
2869
|
this.dest = dest;
|
|
387
2870
|
/** @type {number} */
|
|
388
2871
|
this.cursor = 0;
|
|
389
|
-
/** @type {Uint8Array
|
|
2872
|
+
/** @type {Array<Uint8Array<T>>} */
|
|
390
2873
|
this.chunks = [dest];
|
|
391
2874
|
}
|
|
392
2875
|
reset() {
|
|
393
2876
|
this.cursor = 0;
|
|
394
2877
|
}
|
|
395
2878
|
/**
|
|
396
|
-
* @param {
|
|
2879
|
+
* @param {number} byte
|
|
2880
|
+
*/
|
|
2881
|
+
pushByte(byte) {
|
|
2882
|
+
if (this.cursor >= this.dest.length) throw new Error("write out of bounds, destination buffer is too small");
|
|
2883
|
+
this.dest[this.cursor++] = byte;
|
|
2884
|
+
}
|
|
2885
|
+
/**
|
|
2886
|
+
* @param {ByteView|number[]} bytes
|
|
397
2887
|
*/
|
|
398
2888
|
push(bytes) {
|
|
399
2889
|
if (this.cursor + bytes.length > this.dest.length) throw new Error("write out of bounds, destination buffer is too small");
|
|
@@ -402,7 +2892,7 @@ var U8Bl$1 = class {
|
|
|
402
2892
|
}
|
|
403
2893
|
/**
|
|
404
2894
|
* @param {boolean} [reset]
|
|
405
|
-
* @returns {Uint8Array}
|
|
2895
|
+
* @returns {Uint8Array<T>}
|
|
406
2896
|
*/
|
|
407
2897
|
toBytes(reset = false) {
|
|
408
2898
|
const byts = this.dest.subarray(0, this.cursor);
|
|
@@ -411,7 +2901,7 @@ var U8Bl$1 = class {
|
|
|
411
2901
|
}
|
|
412
2902
|
};
|
|
413
2903
|
//#endregion
|
|
414
|
-
//#region node_modules/
|
|
2904
|
+
//#region node_modules/@ipld/dag-json/node_modules/cborg/lib/common.js
|
|
415
2905
|
const decodeErrPrefix$1 = "CBOR decode error:";
|
|
416
2906
|
const encodeErrPrefix$1 = "CBOR encode error:";
|
|
417
2907
|
const uintMinorPrefixBytes$1 = [];
|
|
@@ -429,7 +2919,7 @@ function assertEnoughData$1(data, pos, need) {
|
|
|
429
2919
|
if (data.length - pos < need) throw new Error(`${decodeErrPrefix$1} not enough data for type`);
|
|
430
2920
|
}
|
|
431
2921
|
//#endregion
|
|
432
|
-
//#region node_modules/
|
|
2922
|
+
//#region node_modules/@ipld/dag-json/node_modules/cborg/lib/0uint.js
|
|
433
2923
|
const uintBoundaries$1 = [
|
|
434
2924
|
24,
|
|
435
2925
|
256,
|
|
@@ -548,7 +3038,7 @@ function encodeUint$1(writer, token) {
|
|
|
548
3038
|
function encodeUintValue$1(writer, major, uint) {
|
|
549
3039
|
if (uint < uintBoundaries$1[0]) {
|
|
550
3040
|
const nuint = Number(uint);
|
|
551
|
-
writer.
|
|
3041
|
+
writer.pushByte(major | nuint);
|
|
552
3042
|
} else if (uint < uintBoundaries$1[1]) {
|
|
553
3043
|
const nuint = Number(uint);
|
|
554
3044
|
writer.push([major | 24, nuint]);
|
|
@@ -625,10 +3115,10 @@ encodeUintValue$1.encodedSize = function encodedSize(uint) {
|
|
|
625
3115
|
* @returns {number}
|
|
626
3116
|
*/
|
|
627
3117
|
encodeUint$1.compareTokens = function compareTokens(tok1, tok2) {
|
|
628
|
-
return tok1.value < tok2.value ? -1 : tok1.value > tok2.value ? 1 :
|
|
3118
|
+
return tok1.value < tok2.value ? -1 : tok1.value > tok2.value ? 1 : 0;
|
|
629
3119
|
};
|
|
630
3120
|
//#endregion
|
|
631
|
-
//#region node_modules/
|
|
3121
|
+
//#region node_modules/@ipld/dag-json/node_modules/cborg/lib/1negint.js
|
|
632
3122
|
/**
|
|
633
3123
|
* @typedef {import('../interface.js').ByteWriter} ByteWriter
|
|
634
3124
|
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
@@ -663,8 +3153,8 @@ function decodeNegint16$1(data, pos, _minor, options) {
|
|
|
663
3153
|
function decodeNegint32$1(data, pos, _minor, options) {
|
|
664
3154
|
return new Token$1(Type$1.negint, -1 - readUint32$1(data, pos + 1, options), 5);
|
|
665
3155
|
}
|
|
666
|
-
const neg1b$
|
|
667
|
-
const pos1b$
|
|
3156
|
+
const neg1b$2 = BigInt(-1);
|
|
3157
|
+
const pos1b$2 = BigInt(1);
|
|
668
3158
|
/**
|
|
669
3159
|
* @param {Uint8Array} data
|
|
670
3160
|
* @param {number} pos
|
|
@@ -679,7 +3169,7 @@ function decodeNegint64$1(data, pos, _minor, options) {
|
|
|
679
3169
|
if (value >= Number.MIN_SAFE_INTEGER) return new Token$1(Type$1.negint, value, 9);
|
|
680
3170
|
}
|
|
681
3171
|
if (options.allowBigInt !== true) throw new Error(`${decodeErrPrefix$1} integers outside of the safe integer range are not supported`);
|
|
682
|
-
return new Token$1(Type$1.negint, neg1b$
|
|
3172
|
+
return new Token$1(Type$1.negint, neg1b$2 - BigInt(int), 9);
|
|
683
3173
|
}
|
|
684
3174
|
/**
|
|
685
3175
|
* @param {ByteWriter} writer
|
|
@@ -687,7 +3177,7 @@ function decodeNegint64$1(data, pos, _minor, options) {
|
|
|
687
3177
|
*/
|
|
688
3178
|
function encodeNegint$1(writer, token) {
|
|
689
3179
|
const negint = token.value;
|
|
690
|
-
const unsigned = typeof negint === "bigint" ? negint * neg1b$
|
|
3180
|
+
const unsigned = typeof negint === "bigint" ? negint * neg1b$2 - pos1b$2 : negint * -1 - 1;
|
|
691
3181
|
encodeUintValue$1(writer, token.type.majorEncoded, unsigned);
|
|
692
3182
|
}
|
|
693
3183
|
/**
|
|
@@ -696,8 +3186,7 @@ function encodeNegint$1(writer, token) {
|
|
|
696
3186
|
*/
|
|
697
3187
|
encodeNegint$1.encodedSize = function encodedSize(token) {
|
|
698
3188
|
const negint = token.value;
|
|
699
|
-
const unsigned = typeof negint === "bigint" ? negint * neg1b$
|
|
700
|
-
/* c8 ignore next 4 */
|
|
3189
|
+
const unsigned = typeof negint === "bigint" ? negint * neg1b$2 - pos1b$2 : negint * -1 - 1;
|
|
701
3190
|
if (unsigned < uintBoundaries$1[0]) return 1;
|
|
702
3191
|
if (unsigned < uintBoundaries$1[1]) return 2;
|
|
703
3192
|
if (unsigned < uintBoundaries$1[2]) return 3;
|
|
@@ -710,10 +3199,10 @@ encodeNegint$1.encodedSize = function encodedSize(token) {
|
|
|
710
3199
|
* @returns {number}
|
|
711
3200
|
*/
|
|
712
3201
|
encodeNegint$1.compareTokens = function compareTokens(tok1, tok2) {
|
|
713
|
-
return tok1.value < tok2.value ? 1 : tok1.value > tok2.value ? -1 :
|
|
3202
|
+
return tok1.value < tok2.value ? 1 : tok1.value > tok2.value ? -1 : 0;
|
|
714
3203
|
};
|
|
715
3204
|
//#endregion
|
|
716
|
-
//#region node_modules/
|
|
3205
|
+
//#region node_modules/@ipld/dag-json/node_modules/cborg/lib/2bytes.js
|
|
717
3206
|
/**
|
|
718
3207
|
* @typedef {import('../interface.js').ByteWriter} ByteWriter
|
|
719
3208
|
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
@@ -826,7 +3315,7 @@ function compareBytes$1(b1, b2) {
|
|
|
826
3315
|
return b1.length < b2.length ? -1 : b1.length > b2.length ? 1 : compare$1(b1, b2);
|
|
827
3316
|
}
|
|
828
3317
|
//#endregion
|
|
829
|
-
//#region node_modules/
|
|
3318
|
+
//#region node_modules/@ipld/dag-json/node_modules/cborg/lib/3string.js
|
|
830
3319
|
const textDecoder$1 = new TextDecoder();
|
|
831
3320
|
const ASCII_THRESHOLD$1 = 32;
|
|
832
3321
|
/**
|
|
@@ -922,7 +3411,7 @@ function decodeString64$1(data, pos, _minor, options) {
|
|
|
922
3411
|
}
|
|
923
3412
|
const encodeString$1 = encodeBytes$1;
|
|
924
3413
|
//#endregion
|
|
925
|
-
//#region node_modules/
|
|
3414
|
+
//#region node_modules/@ipld/dag-json/node_modules/cborg/lib/4array.js
|
|
926
3415
|
/**
|
|
927
3416
|
* @typedef {import('../interface.js').ByteWriter} ByteWriter
|
|
928
3417
|
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
@@ -1016,7 +3505,7 @@ encodeArray$1.encodedSize = function encodedSize(token) {
|
|
|
1016
3505
|
return encodeUintValue$1.encodedSize(token.value);
|
|
1017
3506
|
};
|
|
1018
3507
|
//#endregion
|
|
1019
|
-
//#region node_modules/
|
|
3508
|
+
//#region node_modules/@ipld/dag-json/node_modules/cborg/lib/5map.js
|
|
1020
3509
|
/**
|
|
1021
3510
|
* @typedef {import('../interface.js').ByteWriter} ByteWriter
|
|
1022
3511
|
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
@@ -1110,7 +3599,7 @@ encodeMap$1.encodedSize = function encodedSize(token) {
|
|
|
1110
3599
|
return encodeUintValue$1.encodedSize(token.value);
|
|
1111
3600
|
};
|
|
1112
3601
|
//#endregion
|
|
1113
|
-
//#region node_modules/
|
|
3602
|
+
//#region node_modules/@ipld/dag-json/node_modules/cborg/lib/6tag.js
|
|
1114
3603
|
/**
|
|
1115
3604
|
* @typedef {import('../interface.js').ByteWriter} ByteWriter
|
|
1116
3605
|
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
@@ -1253,10 +3742,10 @@ function decodeFloat64$1(data, pos, _minor, options) {
|
|
|
1253
3742
|
*/
|
|
1254
3743
|
function encodeFloat$1(writer, token, options) {
|
|
1255
3744
|
const float = token.value;
|
|
1256
|
-
if (float === false) writer.
|
|
1257
|
-
else if (float === true) writer.
|
|
1258
|
-
else if (float === null) writer.
|
|
1259
|
-
else if (float === void 0) writer.
|
|
3745
|
+
if (float === false) writer.pushByte(Type$1.float.majorEncoded | 20);
|
|
3746
|
+
else if (float === true) writer.pushByte(Type$1.float.majorEncoded | 21);
|
|
3747
|
+
else if (float === null) writer.pushByte(Type$1.float.majorEncoded | 22);
|
|
3748
|
+
else if (float === void 0) writer.pushByte(Type$1.float.majorEncoded | 23);
|
|
1260
3749
|
else {
|
|
1261
3750
|
let decoded;
|
|
1262
3751
|
let success = false;
|
|
@@ -1318,12 +3807,10 @@ function encodeFloat16$1(inp) {
|
|
|
1318
3807
|
const valu32 = dataView$1.getUint32(0);
|
|
1319
3808
|
const exponent = (valu32 & 2139095040) >> 23;
|
|
1320
3809
|
const mantissa = valu32 & 8388607;
|
|
1321
|
-
/* c8 ignore next 6 */
|
|
1322
3810
|
if (exponent === 255) dataView$1.setUint16(0, 31744, false);
|
|
1323
3811
|
else if (exponent === 0) dataView$1.setUint16(0, (valu32 & 2147483648) >> 16 | mantissa >> 13, false);
|
|
1324
3812
|
else {
|
|
1325
3813
|
const logicalExponent = exponent - 127;
|
|
1326
|
-
/* c8 ignore next 6 */
|
|
1327
3814
|
if (logicalExponent < -24) dataView$1.setUint16(0, 0);
|
|
1328
3815
|
else if (logicalExponent < -14) dataView$1.setUint16(0, (valu32 & 2147483648) >> 16 | 1 << 24 + logicalExponent, false);
|
|
1329
3816
|
else dataView$1.setUint16(0, (valu32 & 2147483648) >> 16 | logicalExponent + 15 << 10 | mantissa >> 13, false);
|
|
@@ -1382,15 +3869,82 @@ function readFloat64$1(ui8a, pos) {
|
|
|
1382
3869
|
return new DataView(ui8a.buffer, offset, 8).getFloat64(0, false);
|
|
1383
3870
|
}
|
|
1384
3871
|
/**
|
|
1385
|
-
* @
|
|
1386
|
-
*
|
|
3872
|
+
* @typedef {Token & {
|
|
3873
|
+
* _keyBytes?: Uint8Array,
|
|
3874
|
+
* _keyBytesFloat64?: Uint8Array
|
|
3875
|
+
* }} TokenEx
|
|
3876
|
+
*/
|
|
3877
|
+
/**
|
|
3878
|
+
* The canonical CBOR bytes for a major 7 map key. The four simple values encode
|
|
3879
|
+
* to a single byte and every float to its 3, 5 or 9 byte form, exactly as
|
|
3880
|
+
* {@link encodeFloat} writes them. This mirrors the width selection in
|
|
3881
|
+
* `encodeFloat` because the sorter needs the bytes in hand to compare.
|
|
3882
|
+
* @param {Token} token
|
|
3883
|
+
* @param {boolean} float64
|
|
3884
|
+
* @returns {Uint8Array}
|
|
3885
|
+
*/
|
|
3886
|
+
function encodeMajorSevenBytes(token, float64) {
|
|
3887
|
+
const float = token.value;
|
|
3888
|
+
if (float === false) return Uint8Array.of(Type$1.float.majorEncoded | 20);
|
|
3889
|
+
if (float === true) return Uint8Array.of(Type$1.float.majorEncoded | 21);
|
|
3890
|
+
if (float === null) return Uint8Array.of(Type$1.float.majorEncoded | 22);
|
|
3891
|
+
if (float === void 0) return Uint8Array.of(Type$1.float.majorEncoded | 23);
|
|
3892
|
+
if (!float64) {
|
|
3893
|
+
encodeFloat16$1(float);
|
|
3894
|
+
if (float === readFloat16$1(ui8a$1, 1) || Number.isNaN(float)) {
|
|
3895
|
+
ui8a$1[0] = 249;
|
|
3896
|
+
return ui8a$1.slice(0, 3);
|
|
3897
|
+
}
|
|
3898
|
+
encodeFloat32$1(float);
|
|
3899
|
+
if (float === readFloat32$1(ui8a$1, 1)) {
|
|
3900
|
+
ui8a$1[0] = 250;
|
|
3901
|
+
return ui8a$1.slice(0, 5);
|
|
3902
|
+
}
|
|
3903
|
+
}
|
|
3904
|
+
encodeFloat64$1(float);
|
|
3905
|
+
ui8a$1[0] = 251;
|
|
3906
|
+
return ui8a$1.slice(0, 9);
|
|
3907
|
+
}
|
|
3908
|
+
/**
|
|
3909
|
+
* Get the canonical CBOR bytes for a major 7 map key, honouring
|
|
3910
|
+
* `options.float64`. Bytes are cached because Array.sort compares each key
|
|
3911
|
+
* multiple times.
|
|
3912
|
+
* @param {Token} token
|
|
3913
|
+
* @param {EncodeOptions} [options]
|
|
3914
|
+
* @returns {Uint8Array}
|
|
3915
|
+
*/
|
|
3916
|
+
function majorSevenBytes(token, options) {
|
|
3917
|
+
const tokenEx = token;
|
|
3918
|
+
const float64 = options?.float64 === true;
|
|
3919
|
+
const cached = float64 ? tokenEx._keyBytesFloat64 : tokenEx._keyBytes;
|
|
3920
|
+
if (cached !== void 0) return cached;
|
|
3921
|
+
const bytes = encodeMajorSevenBytes(token, float64);
|
|
3922
|
+
if (float64) tokenEx._keyBytesFloat64 = bytes;
|
|
3923
|
+
else tokenEx._keyBytes = bytes;
|
|
3924
|
+
return bytes;
|
|
3925
|
+
}
|
|
3926
|
+
/**
|
|
3927
|
+
* Order two major 7 map keys by RFC 7049 §3.9 canonical order: shorter encoding
|
|
3928
|
+
* first, then bytewise. Because the four simple values encode to one byte they
|
|
3929
|
+
* sort ahead of every float, and comparing the `float64`-honouring encoded bytes
|
|
3930
|
+
* (rather than the numeric value) makes negative floats, mixed encoding widths
|
|
3931
|
+
* and `NaN` deterministic regardless of insertion order.
|
|
3932
|
+
* @param {Token} tok1
|
|
3933
|
+
* @param {Token} tok2
|
|
3934
|
+
* @param {EncodeOptions} [options]
|
|
1387
3935
|
* @returns {number}
|
|
1388
3936
|
*/
|
|
1389
|
-
encodeFloat$1.compareTokens =
|
|
3937
|
+
encodeFloat$1.compareTokens = function compareTokens(tok1, tok2, options) {
|
|
3938
|
+
const b1 = majorSevenBytes(tok1, options);
|
|
3939
|
+
const b2 = majorSevenBytes(tok2, options);
|
|
3940
|
+
if (b1.length !== b2.length) return b1.length < b2.length ? -1 : 1;
|
|
3941
|
+
return compare$1(b1, b2);
|
|
3942
|
+
};
|
|
1390
3943
|
//#endregion
|
|
1391
|
-
//#region node_modules/
|
|
3944
|
+
//#region node_modules/@ipld/dag-json/node_modules/cborg/lib/jump.js
|
|
1392
3945
|
/**
|
|
1393
3946
|
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
3947
|
+
* @typedef {import('../interface.js').AllocatedByteView} AllocatedByteView
|
|
1394
3948
|
*/
|
|
1395
3949
|
/**
|
|
1396
3950
|
* @param {Uint8Array} data
|
|
@@ -1500,7 +4054,7 @@ quick$1[245] = new Token$1(Type$1.true, true, 1);
|
|
|
1500
4054
|
quick$1[246] = new Token$1(Type$1.null, null, 1);
|
|
1501
4055
|
/**
|
|
1502
4056
|
* @param {Token} token
|
|
1503
|
-
* @returns {
|
|
4057
|
+
* @returns {AllocatedByteView|undefined}
|
|
1504
4058
|
*/
|
|
1505
4059
|
function quickEncodeToken$1(token) {
|
|
1506
4060
|
switch (token.type) {
|
|
@@ -1514,39 +4068,21 @@ function quickEncodeToken$1(token) {
|
|
|
1514
4068
|
if (token.value === "") return fromArray$1([96]);
|
|
1515
4069
|
return;
|
|
1516
4070
|
case Type$1.array:
|
|
1517
|
-
if (token.value === 0) return fromArray$1([128]);
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
return;
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
//#endregion
|
|
1531
|
-
//#region node_modules/kubo-rpc-client/node_modules/cborg/lib/encode.js
|
|
1532
|
-
/**
|
|
1533
|
-
* @typedef {import('../interface.js').EncodeOptions} EncodeOptions
|
|
1534
|
-
* @typedef {import('../interface.js').OptionalTypeEncoder} OptionalTypeEncoder
|
|
1535
|
-
* @typedef {import('../interface.js').Reference} Reference
|
|
1536
|
-
* @typedef {import('../interface.js').StrictTypeEncoder} StrictTypeEncoder
|
|
1537
|
-
* @typedef {import('../interface.js').TokenTypeEncoder} TokenTypeEncoder
|
|
1538
|
-
* @typedef {import('../interface.js').TokenOrNestedTokens} TokenOrNestedTokens
|
|
1539
|
-
* @typedef {import('../interface.js').ByteWriter} ByteWriter
|
|
1540
|
-
*/
|
|
1541
|
-
/** @type {EncodeOptions} */
|
|
1542
|
-
const defaultEncodeOptions$2 = {
|
|
1543
|
-
float64: false,
|
|
1544
|
-
mapSorter: mapSorter$2,
|
|
1545
|
-
quickEncodeToken: quickEncodeToken$1
|
|
1546
|
-
};
|
|
4071
|
+
if (token.value === 0) return fromArray$1([128]);
|
|
4072
|
+
return;
|
|
4073
|
+
case Type$1.map:
|
|
4074
|
+
if (token.value === 0) return fromArray$1([160]);
|
|
4075
|
+
return;
|
|
4076
|
+
case Type$1.uint:
|
|
4077
|
+
if (token.value < 24) return fromArray$1([Number(token.value)]);
|
|
4078
|
+
return;
|
|
4079
|
+
case Type$1.negint: if (token.value >= -24) return fromArray$1([31 - Number(token.value)]);
|
|
4080
|
+
}
|
|
4081
|
+
}
|
|
4082
|
+
//#endregion
|
|
4083
|
+
//#region node_modules/@ipld/dag-json/node_modules/cborg/lib/encode.js
|
|
1547
4084
|
/** @type {EncodeOptions} */
|
|
1548
4085
|
const rfc8949EncodeOptions$1 = Object.freeze({
|
|
1549
|
-
float64: true,
|
|
1550
4086
|
mapSorter: rfc8949MapSorter$1,
|
|
1551
4087
|
quickEncodeToken: quickEncodeToken$1
|
|
1552
4088
|
});
|
|
@@ -1800,25 +4336,11 @@ function objectToTokens$1(obj, options = {}, refStack) {
|
|
|
1800
4336
|
* @param {EncodeOptions} options
|
|
1801
4337
|
*/
|
|
1802
4338
|
function sortMapEntries$1(entries, options) {
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
/**
|
|
1806
|
-
* @param {(Token|Token[])[]} e1
|
|
1807
|
-
* @param {(Token|Token[])[]} e2
|
|
1808
|
-
* @returns {number}
|
|
1809
|
-
*/
|
|
1810
|
-
function mapSorter$2(e1, e2) {
|
|
1811
|
-
/* c8 ignore next 2 */
|
|
1812
|
-
const keyToken1 = Array.isArray(e1[0]) ? e1[0][0] : e1[0];
|
|
1813
|
-
const keyToken2 = Array.isArray(e2[0]) ? e2[0][0] : e2[0];
|
|
1814
|
-
if (keyToken1.type !== keyToken2.type) return keyToken1.type.compare(keyToken2.type);
|
|
1815
|
-
const tcmp = cborEncoders$1[keyToken1.type.major].compareTokens(keyToken1, keyToken2);
|
|
1816
|
-
/* c8 ignore next 5 */
|
|
1817
|
-
if (tcmp === 0) console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone");
|
|
1818
|
-
return tcmp;
|
|
4339
|
+
const mapSorter = options.mapSorter;
|
|
4340
|
+
if (mapSorter) entries.sort((e1, e2) => mapSorter(e1, e2, options));
|
|
1819
4341
|
}
|
|
1820
4342
|
/**
|
|
1821
|
-
* @typedef {Token & { _keyBytes?:
|
|
4343
|
+
* @typedef {Token & { _keyBytes?: AllocatedByteView }} TokenEx
|
|
1822
4344
|
*
|
|
1823
4345
|
* @param {(Token|Token[])[]} e1
|
|
1824
4346
|
* @param {(Token|Token[])[]} e2
|
|
@@ -1836,7 +4358,7 @@ function rfc8949MapSorter$1(e1, e2) {
|
|
|
1836
4358
|
}
|
|
1837
4359
|
/**
|
|
1838
4360
|
* @param {any} data
|
|
1839
|
-
* @returns {
|
|
4361
|
+
* @returns {AllocatedByteView}
|
|
1840
4362
|
*/
|
|
1841
4363
|
function encodeRfc8949$1(data) {
|
|
1842
4364
|
return encodeCustom$1(data, cborEncoders$1, rfc8949EncodeOptions$1);
|
|
@@ -1851,99 +4373,38 @@ function tokensToEncoded$1(writer, tokens, encoders, options) {
|
|
|
1851
4373
|
if (Array.isArray(tokens)) for (const token of tokens) tokensToEncoded$1(writer, token, encoders, options);
|
|
1852
4374
|
else encoders[tokens.type.major](writer, tokens, options);
|
|
1853
4375
|
}
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
*
|
|
1867
|
-
*
|
|
4376
|
+
Type$1.uint.majorEncoded;
|
|
4377
|
+
Type$1.negint.majorEncoded;
|
|
4378
|
+
Type$1.bytes.majorEncoded;
|
|
4379
|
+
Type$1.string.majorEncoded;
|
|
4380
|
+
Type$1.array.majorEncoded;
|
|
4381
|
+
Type$1.map.majorEncoded;
|
|
4382
|
+
Type$1.float.majorEncoded | 20;
|
|
4383
|
+
Type$1.float.majorEncoded | 21;
|
|
4384
|
+
Type$1.float.majorEncoded | 22;
|
|
4385
|
+
Type$1.float.majorEncoded | 23;
|
|
4386
|
+
/**
|
|
4387
|
+
* @template {ArrayBufferLike} T
|
|
4388
|
+
* @overload
|
|
4389
|
+
* @param {any} data
|
|
4390
|
+
* @param {TokenTypeEncoder[]} encoders
|
|
1868
4391
|
* @param {EncodeOptions} options
|
|
1869
|
-
* @
|
|
4392
|
+
* @param {Uint8Array<T>} destination
|
|
4393
|
+
* @returns {Uint8Array<T>}
|
|
1870
4394
|
*/
|
|
1871
|
-
function canDirectEncode$1(options) {
|
|
1872
|
-
return options.addBreakTokens !== true;
|
|
1873
|
-
}
|
|
1874
4395
|
/**
|
|
1875
|
-
*
|
|
1876
|
-
* Falls back to token-based encoding for custom type encoders.
|
|
1877
|
-
* @param {ByteWriter} writer
|
|
4396
|
+
* @overload
|
|
1878
4397
|
* @param {any} data
|
|
4398
|
+
* @param {TokenTypeEncoder[]} encoders
|
|
1879
4399
|
* @param {EncodeOptions} options
|
|
1880
|
-
* @
|
|
4400
|
+
* @returns {AllocatedByteView}
|
|
1881
4401
|
*/
|
|
1882
|
-
function directEncode$1(writer, data, options, refStack) {
|
|
1883
|
-
const typ = is$1(data);
|
|
1884
|
-
const customEncoder = options.typeEncoders && options.typeEncoders[typ];
|
|
1885
|
-
if (customEncoder) {
|
|
1886
|
-
const tokens = customEncoder(data, typ, options, refStack);
|
|
1887
|
-
if (tokens != null) {
|
|
1888
|
-
tokensToEncoded$1(writer, tokens, cborEncoders$1, options);
|
|
1889
|
-
return;
|
|
1890
|
-
}
|
|
1891
|
-
}
|
|
1892
|
-
switch (typ) {
|
|
1893
|
-
case "null":
|
|
1894
|
-
writer.push([SIMPLE_NULL$1]);
|
|
1895
|
-
return;
|
|
1896
|
-
case "undefined":
|
|
1897
|
-
writer.push([SIMPLE_UNDEFINED$1]);
|
|
1898
|
-
return;
|
|
1899
|
-
case "boolean":
|
|
1900
|
-
writer.push([data ? SIMPLE_TRUE$1 : SIMPLE_FALSE$1]);
|
|
1901
|
-
return;
|
|
1902
|
-
case "number":
|
|
1903
|
-
if (!Number.isInteger(data) || !Number.isSafeInteger(data)) encodeFloat$1(writer, new Token$1(Type$1.float, data), options);
|
|
1904
|
-
else if (data >= 0) encodeUintValue$1(writer, MAJOR_UINT$1, data);
|
|
1905
|
-
else encodeUintValue$1(writer, MAJOR_NEGINT$1, data * -1 - 1);
|
|
1906
|
-
return;
|
|
1907
|
-
case "bigint":
|
|
1908
|
-
if (data >= BigInt(0)) encodeUintValue$1(writer, MAJOR_UINT$1, data);
|
|
1909
|
-
else encodeUintValue$1(writer, MAJOR_NEGINT$1, data * neg1b$2 - pos1b$2);
|
|
1910
|
-
return;
|
|
1911
|
-
case "string": {
|
|
1912
|
-
const bytes = fromString$2(data);
|
|
1913
|
-
encodeUintValue$1(writer, MAJOR_STRING$1, bytes.length);
|
|
1914
|
-
writer.push(bytes);
|
|
1915
|
-
return;
|
|
1916
|
-
}
|
|
1917
|
-
case "Uint8Array":
|
|
1918
|
-
encodeUintValue$1(writer, MAJOR_BYTES$1, data.length);
|
|
1919
|
-
writer.push(data);
|
|
1920
|
-
return;
|
|
1921
|
-
case "Array":
|
|
1922
|
-
if (!data.length) {
|
|
1923
|
-
writer.push([MAJOR_ARRAY$1]);
|
|
1924
|
-
return;
|
|
1925
|
-
}
|
|
1926
|
-
refStack = Ref$1.createCheck(refStack, data);
|
|
1927
|
-
encodeUintValue$1(writer, MAJOR_ARRAY$1, data.length);
|
|
1928
|
-
for (const elem of data) directEncode$1(writer, elem, options, refStack);
|
|
1929
|
-
return;
|
|
1930
|
-
case "Object":
|
|
1931
|
-
case "Map":
|
|
1932
|
-
tokensToEncoded$1(writer, typeEncoders$1.Object(data, typ, options, refStack), cborEncoders$1, options);
|
|
1933
|
-
return;
|
|
1934
|
-
default: {
|
|
1935
|
-
const typeEncoder = typeEncoders$1[typ];
|
|
1936
|
-
if (!typeEncoder) throw new Error(`${encodeErrPrefix$1} unsupported type: ${typ}`);
|
|
1937
|
-
tokensToEncoded$1(writer, typeEncoder(data, typ, options, refStack), cborEncoders$1, options);
|
|
1938
|
-
}
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
4402
|
/**
|
|
1942
4403
|
* @param {any} data
|
|
1943
4404
|
* @param {TokenTypeEncoder[]} encoders
|
|
1944
4405
|
* @param {EncodeOptions} options
|
|
1945
|
-
* @param {
|
|
1946
|
-
* @returns {
|
|
4406
|
+
* @param {ByteView} [destination]
|
|
4407
|
+
* @returns {ByteView}
|
|
1947
4408
|
*/
|
|
1948
4409
|
function encodeCustom$1(data, encoders, options, destination) {
|
|
1949
4410
|
const hasDest = destination instanceof Uint8Array;
|
|
@@ -1963,7 +4424,6 @@ function encodeCustom$1(data, encoders, options, destination) {
|
|
|
1963
4424
|
const size = encoder.encodedSize(tokens, options);
|
|
1964
4425
|
if (!hasDest) writeTo = new Bl$1(size);
|
|
1965
4426
|
encoder(writeTo, tokens, options);
|
|
1966
|
-
/* c8 ignore next 4 */
|
|
1967
4427
|
if (writeTo.chunks.length !== 1) throw new Error(`Unexpected error: pre-calculated length for ${tokens} was wrong`);
|
|
1968
4428
|
return hasDest ? writeTo.toBytes() : asU8A$1(writeTo.chunks[0]);
|
|
1969
4429
|
}
|
|
@@ -1972,22 +4432,8 @@ function encodeCustom$1(data, encoders, options, destination) {
|
|
|
1972
4432
|
tokensToEncoded$1(writeTo, tokens, encoders, options);
|
|
1973
4433
|
return writeTo.toBytes(true);
|
|
1974
4434
|
}
|
|
1975
|
-
/**
|
|
1976
|
-
* @param {any} data
|
|
1977
|
-
* @param {EncodeOptions} [options]
|
|
1978
|
-
* @returns {Uint8Array}
|
|
1979
|
-
*/
|
|
1980
|
-
function encode$8(data, options) {
|
|
1981
|
-
options = Object.assign({}, defaultEncodeOptions$2, options);
|
|
1982
|
-
if (canDirectEncode$1(options)) {
|
|
1983
|
-
defaultWriter$1.reset();
|
|
1984
|
-
directEncode$1(defaultWriter$1, data, options, void 0);
|
|
1985
|
-
return defaultWriter$1.toBytes(true);
|
|
1986
|
-
}
|
|
1987
|
-
return encodeCustom$1(data, cborEncoders$1, options);
|
|
1988
|
-
}
|
|
1989
4435
|
//#endregion
|
|
1990
|
-
//#region node_modules/
|
|
4436
|
+
//#region node_modules/@ipld/dag-json/node_modules/cborg/lib/decode.js
|
|
1991
4437
|
/**
|
|
1992
4438
|
* @typedef {import('./token.js').Token} Token
|
|
1993
4439
|
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
@@ -2024,7 +4470,6 @@ var Tokeniser$1 = class {
|
|
|
2024
4470
|
let token = quick$1[byt];
|
|
2025
4471
|
if (token === void 0) {
|
|
2026
4472
|
const decoder = jump$1[byt];
|
|
2027
|
-
/* c8 ignore next 4 */
|
|
2028
4473
|
if (!decoder) throw new Error(`${decodeErrPrefix$1} no decoder for major type ${byt >>> 5} (byte 0x${byt.toString(16).padStart(2, "0")})`);
|
|
2029
4474
|
const minor = byt & 31;
|
|
2030
4475
|
token = decoder(this.data, this._pos, minor, this.options);
|
|
@@ -2039,7 +4484,7 @@ const BREAK$1 = Symbol.for("BREAK");
|
|
|
2039
4484
|
* @param {Token} token
|
|
2040
4485
|
* @param {DecodeTokenizer} tokeniser
|
|
2041
4486
|
* @param {DecodeOptions} options
|
|
2042
|
-
* @returns {any|BREAK|DONE}
|
|
4487
|
+
* @returns {any|typeof BREAK|typeof DONE}
|
|
2043
4488
|
*/
|
|
2044
4489
|
function tokenToArray$1(token, tokeniser, options) {
|
|
2045
4490
|
const arr = [];
|
|
@@ -2058,7 +4503,7 @@ function tokenToArray$1(token, tokeniser, options) {
|
|
|
2058
4503
|
* @param {Token} token
|
|
2059
4504
|
* @param {DecodeTokenizer} tokeniser
|
|
2060
4505
|
* @param {DecodeOptions} options
|
|
2061
|
-
* @returns {any|BREAK|DONE}
|
|
4506
|
+
* @returns {any|typeof BREAK|typeof DONE}
|
|
2062
4507
|
*/
|
|
2063
4508
|
function tokenToMap$1(token, tokeniser, options) {
|
|
2064
4509
|
const useMaps = options.useMaps === true;
|
|
@@ -2111,39 +4556,31 @@ function* tokenToMapEntries$1(token, tokeniser, options) {
|
|
|
2111
4556
|
* @returns {TagDecodeControl}
|
|
2112
4557
|
*/
|
|
2113
4558
|
function createTagDecodeControl$1(tokeniser, options) {
|
|
2114
|
-
|
|
2115
|
-
/**
|
|
2116
|
-
* @type {TagDecodeControl}
|
|
2117
|
-
*/
|
|
4559
|
+
/** @type {TagDecodeControl & {_called: boolean}} */
|
|
2118
4560
|
const decode = function() {
|
|
2119
|
-
if (
|
|
2120
|
-
|
|
4561
|
+
if (decode._called) throw new Error(`${decodeErrPrefix$1} tag decode() may only be called once`);
|
|
4562
|
+
decode._called = true;
|
|
2121
4563
|
const value = tokensToObject$1(tokeniser, options);
|
|
2122
4564
|
if (value === DONE$1) throw new Error(`${decodeErrPrefix$1} tag content missing`);
|
|
2123
4565
|
if (value === BREAK$1) throw new Error(`${decodeErrPrefix$1} got unexpected break in tag content`);
|
|
2124
4566
|
return value;
|
|
2125
4567
|
};
|
|
2126
4568
|
decode.entries = function() {
|
|
2127
|
-
if (
|
|
2128
|
-
|
|
4569
|
+
if (decode._called) throw new Error(`${decodeErrPrefix$1} tag decode() may only be called once`);
|
|
4570
|
+
decode._called = true;
|
|
2129
4571
|
const token = tokeniser.next();
|
|
2130
4572
|
if (!Type$1.equals(token.type, Type$1.map)) throw new Error(`${decodeErrPrefix$1} entries() requires map content, got ${token.type.name}`);
|
|
2131
4573
|
const entries = [];
|
|
2132
4574
|
for (const entry of tokenToMapEntries$1(token, tokeniser, options)) entries.push(entry);
|
|
2133
4575
|
return entries;
|
|
2134
4576
|
};
|
|
2135
|
-
|
|
2136
|
-
get() {
|
|
2137
|
-
return called;
|
|
2138
|
-
},
|
|
2139
|
-
enumerable: false
|
|
2140
|
-
});
|
|
4577
|
+
decode._called = false;
|
|
2141
4578
|
return decode;
|
|
2142
4579
|
}
|
|
2143
4580
|
/**
|
|
2144
4581
|
* @param {DecodeTokenizer} tokeniser
|
|
2145
4582
|
* @param {DecodeOptions} options
|
|
2146
|
-
* @returns {any|BREAK|DONE}
|
|
4583
|
+
* @returns {any|typeof BREAK|typeof DONE}
|
|
2147
4584
|
*/
|
|
2148
4585
|
function tokensToObject$1(tokeniser, options) {
|
|
2149
4586
|
if (tokeniser.done()) return DONE$1;
|
|
@@ -2161,7 +4598,6 @@ function tokensToObject$1(tokeniser, options) {
|
|
|
2161
4598
|
}
|
|
2162
4599
|
throw new Error(`${decodeErrPrefix$1} tag not supported (${token.value})`);
|
|
2163
4600
|
}
|
|
2164
|
-
/* c8 ignore next */
|
|
2165
4601
|
throw new Error("unsupported");
|
|
2166
4602
|
}
|
|
2167
4603
|
/**
|
|
@@ -2184,7 +4620,7 @@ function decodeFirst$1(data, options) {
|
|
|
2184
4620
|
* @param {DecodeOptions} [options]
|
|
2185
4621
|
* @returns {any}
|
|
2186
4622
|
*/
|
|
2187
|
-
function decode$
|
|
4623
|
+
function decode$7(data, options) {
|
|
2188
4624
|
const [decoded, remainder] = decodeFirst$1(data, options);
|
|
2189
4625
|
if (remainder.length > 0) throw new Error(`${decodeErrPrefix$1} too many terminals, data makes no sense`);
|
|
2190
4626
|
return decoded;
|
|
@@ -2235,137 +4671,11 @@ Object.defineProperty(class Tagged$1 {
|
|
|
2235
4671
|
}
|
|
2236
4672
|
}.prototype, Symbol.toStringTag, { value: "Tagged" });
|
|
2237
4673
|
//#endregion
|
|
2238
|
-
//#region node_modules
|
|
2239
|
-
var src_exports$1 = /* @__PURE__ */ __exportAll({
|
|
2240
|
-
code: () => 113,
|
|
2241
|
-
decode: () => decode$7,
|
|
2242
|
-
decodeOptions: () => decodeOptions$2,
|
|
2243
|
-
encode: () => encode$7,
|
|
2244
|
-
encodeOptions: () => encodeOptions$2,
|
|
2245
|
-
name: () => name$2,
|
|
2246
|
-
toByteView: () => toByteView$2
|
|
2247
|
-
});
|
|
2248
|
-
const CID_CBOR_TAG$1 = 42;
|
|
2249
|
-
/**
|
|
2250
|
-
* @template T
|
|
2251
|
-
* @typedef {import('multiformats/codecs/interface').ByteView<T>} ByteView
|
|
2252
|
-
*/
|
|
2253
|
-
/**
|
|
2254
|
-
* @template T
|
|
2255
|
-
* @typedef {import('multiformats/codecs/interface').ArrayBufferView<T>} ArrayBufferView
|
|
2256
|
-
*/
|
|
2257
|
-
/**
|
|
2258
|
-
* @template T
|
|
2259
|
-
* @param {ByteView<T> | ArrayBufferView<T>} buf
|
|
2260
|
-
* @returns {ByteView<T>}
|
|
2261
|
-
*/
|
|
2262
|
-
function toByteView$2(buf) {
|
|
2263
|
-
if (buf instanceof ArrayBuffer) return new Uint8Array(buf, 0, buf.byteLength);
|
|
2264
|
-
return buf;
|
|
2265
|
-
}
|
|
2266
|
-
/**
|
|
2267
|
-
* cidEncoder will receive all Objects during encode, it needs to filter out
|
|
2268
|
-
* anything that's not a CID and return `null` for that so it's encoded as
|
|
2269
|
-
* normal.
|
|
2270
|
-
*
|
|
2271
|
-
* @param {any} obj
|
|
2272
|
-
* @returns {cborg.Token[]|null}
|
|
2273
|
-
*/
|
|
2274
|
-
function cidEncoder$2(obj) {
|
|
2275
|
-
if (obj.asCID !== obj && obj["/"] !== obj.bytes) return null;
|
|
2276
|
-
const cid = CID.asCID(obj);
|
|
2277
|
-
/* c8 ignore next 4 */
|
|
2278
|
-
if (!cid) return null;
|
|
2279
|
-
const bytes = new Uint8Array(cid.bytes.byteLength + 1);
|
|
2280
|
-
bytes.set(cid.bytes, 1);
|
|
2281
|
-
return [new Token$1(Type$1.tag, CID_CBOR_TAG$1), new Token$1(Type$1.bytes, bytes)];
|
|
2282
|
-
}
|
|
2283
|
-
/**
|
|
2284
|
-
* Intercept all `undefined` values from an object walk and reject the entire
|
|
2285
|
-
* object if we find one.
|
|
2286
|
-
*
|
|
2287
|
-
* @returns {null}
|
|
2288
|
-
*/
|
|
2289
|
-
function undefinedEncoder$2() {
|
|
2290
|
-
throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded");
|
|
2291
|
-
}
|
|
2292
|
-
/**
|
|
2293
|
-
* Intercept all `number` values from an object walk and reject the entire
|
|
2294
|
-
* object if we find something that doesn't fit the IPLD data model (NaN &
|
|
2295
|
-
* Infinity).
|
|
2296
|
-
*
|
|
2297
|
-
* @param {number} num
|
|
2298
|
-
* @returns {null}
|
|
2299
|
-
*/
|
|
2300
|
-
function numberEncoder$2(num) {
|
|
2301
|
-
if (Number.isNaN(num)) throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");
|
|
2302
|
-
if (num === Infinity || num === -Infinity) throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");
|
|
2303
|
-
return null;
|
|
2304
|
-
}
|
|
2305
|
-
/**
|
|
2306
|
-
* @param {Map<any, any>} map
|
|
2307
|
-
* @returns {null}
|
|
2308
|
-
*/
|
|
2309
|
-
function mapEncoder$1(map) {
|
|
2310
|
-
for (const key of map.keys()) if (typeof key !== "string" || key.length === 0) throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");
|
|
2311
|
-
return null;
|
|
2312
|
-
}
|
|
2313
|
-
const _encodeOptions$1 = {
|
|
2314
|
-
float64: true,
|
|
2315
|
-
typeEncoders: {
|
|
2316
|
-
Map: mapEncoder$1,
|
|
2317
|
-
Object: cidEncoder$2,
|
|
2318
|
-
undefined: undefinedEncoder$2,
|
|
2319
|
-
number: numberEncoder$2
|
|
2320
|
-
}
|
|
2321
|
-
};
|
|
2322
|
-
const encodeOptions$2 = {
|
|
2323
|
-
..._encodeOptions$1,
|
|
2324
|
-
typeEncoders: { ..._encodeOptions$1.typeEncoders }
|
|
2325
|
-
};
|
|
2326
|
-
/**
|
|
2327
|
-
* @param {import('cborg').TagDecodeControl} decode
|
|
2328
|
-
* @returns {CID}
|
|
2329
|
-
*/
|
|
2330
|
-
function cidDecoder$1(decode) {
|
|
2331
|
-
const bytes = decode();
|
|
2332
|
-
if (bytes[0] !== 0) throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");
|
|
2333
|
-
return CID.decode(bytes.subarray(1));
|
|
2334
|
-
}
|
|
2335
|
-
const _decodeOptions$1 = {
|
|
2336
|
-
allowIndefinite: false,
|
|
2337
|
-
coerceUndefinedToNull: true,
|
|
2338
|
-
allowNaN: false,
|
|
2339
|
-
allowInfinity: false,
|
|
2340
|
-
allowBigInt: true,
|
|
2341
|
-
strict: true,
|
|
2342
|
-
useMaps: false,
|
|
2343
|
-
rejectDuplicateMapKeys: true,
|
|
2344
|
-
/** @type {{ [tagNumber: number]: import('cborg').TagDecoder }} */
|
|
2345
|
-
tags: { [CID_CBOR_TAG$1]: cidDecoder$1 }
|
|
2346
|
-
};
|
|
2347
|
-
const decodeOptions$2 = {
|
|
2348
|
-
..._decodeOptions$1,
|
|
2349
|
-
tags: { ..._decodeOptions$1.tags }
|
|
2350
|
-
};
|
|
2351
|
-
const name$2 = "dag-cbor";
|
|
2352
|
-
/**
|
|
2353
|
-
* @template T
|
|
2354
|
-
* @param {T} node
|
|
2355
|
-
* @returns {ByteView<T>}
|
|
2356
|
-
*/
|
|
2357
|
-
const encode$7 = (node) => encode$8(node, _encodeOptions$1);
|
|
2358
|
-
/**
|
|
2359
|
-
* @template T
|
|
2360
|
-
* @param {ByteView<T> | ArrayBufferView<T>} data
|
|
2361
|
-
* @returns {T}
|
|
2362
|
-
*/
|
|
2363
|
-
const decode$7 = (data) => decode$8(toByteView$2(data), _decodeOptions$1);
|
|
2364
|
-
//#endregion
|
|
2365
|
-
//#region node_modules/kubo-rpc-client/node_modules/cborg/lib/json/encode.js
|
|
4674
|
+
//#region node_modules/@ipld/dag-json/node_modules/cborg/lib/json/encode.js
|
|
2366
4675
|
/**
|
|
2367
4676
|
* @typedef {import('../../interface.js').EncodeOptions} EncodeOptions
|
|
2368
4677
|
* @typedef {import('../../interface.js').ByteWriter} ByteWriter
|
|
4678
|
+
* @typedef {import('../../interface.js').AllocatedByteView} AllocatedByteView
|
|
2369
4679
|
* @typedef {import('../token.js').Token} Token
|
|
2370
4680
|
*/
|
|
2371
4681
|
var JSONEncoder = class extends Array {
|
|
@@ -2467,7 +4777,6 @@ var JSONEncoder = class extends Array {
|
|
|
2467
4777
|
else throw new Error("Unexpected recursive type; this should not happen!");
|
|
2468
4778
|
return;
|
|
2469
4779
|
}
|
|
2470
|
-
/* c8 ignore next 2 */
|
|
2471
4780
|
throw new Error("Unexpected break; this should not happen!");
|
|
2472
4781
|
}
|
|
2473
4782
|
if (token.value === void 0) throw new Error(`${encodeErrPrefix$1} unsupported type: undefined`);
|
|
@@ -2524,7 +4833,6 @@ function mapSorter$1(e1, e2) {
|
|
|
2524
4833
|
if (keyToken1.type !== Type$1.string || keyToken2.type !== Type$1.string) throw new Error(`${encodeErrPrefix$1} non-string map keys are not supported`);
|
|
2525
4834
|
if (keyToken1 < keyToken2) return -1;
|
|
2526
4835
|
if (keyToken1 > keyToken2) return 1;
|
|
2527
|
-
/* c8 ignore next 1 */
|
|
2528
4836
|
throw new Error(`${encodeErrPrefix$1} unexpected duplicate map keys, this is not supported`);
|
|
2529
4837
|
}
|
|
2530
4838
|
const defaultEncodeOptions$1 = {
|
|
@@ -2534,14 +4842,14 @@ const defaultEncodeOptions$1 = {
|
|
|
2534
4842
|
/**
|
|
2535
4843
|
* @param {any} data
|
|
2536
4844
|
* @param {EncodeOptions} [options]
|
|
2537
|
-
* @returns {
|
|
4845
|
+
* @returns {AllocatedByteView}
|
|
2538
4846
|
*/
|
|
2539
4847
|
function encode$6(data, options) {
|
|
2540
4848
|
options = Object.assign({}, defaultEncodeOptions$1, options);
|
|
2541
4849
|
return encodeCustom$1(data, new JSONEncoder(), options);
|
|
2542
4850
|
}
|
|
2543
4851
|
//#endregion
|
|
2544
|
-
//#region node_modules/
|
|
4852
|
+
//#region node_modules/@ipld/dag-json/node_modules/cborg/lib/json/decode.js
|
|
2545
4853
|
/**
|
|
2546
4854
|
* @typedef {import('../../interface.js').DecodeOptions} DecodeOptions
|
|
2547
4855
|
* @typedef {import('../../interface.js').DecodeTokenizer} DecodeTokenizer
|
|
@@ -2676,7 +4984,6 @@ var Tokenizer = class {
|
|
|
2676
4984
|
* @returns {Token}
|
|
2677
4985
|
*/
|
|
2678
4986
|
parseString() {
|
|
2679
|
-
/* c8 ignore next 4 */
|
|
2680
4987
|
if (this.ch() !== 34) throw new Error(`${decodeErrPrefix$1} unexpected character at position ${this._pos}; this shouldn't happen`);
|
|
2681
4988
|
this._pos++;
|
|
2682
4989
|
for (let i = this._pos, l = 0; i < this.data.length && l < 65536; i++, l++) {
|
|
@@ -2707,12 +5014,10 @@ var Tokenizer = class {
|
|
|
2707
5014
|
const readUtf8Char = () => {
|
|
2708
5015
|
const firstByte = this.ch();
|
|
2709
5016
|
let codePoint = null;
|
|
2710
|
-
/* c8 ignore next 1 */
|
|
2711
5017
|
let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
|
|
2712
5018
|
if (this._pos + bytesPerSequence > this.data.length) throw new Error(`${decodeErrPrefix$1} unexpected unicode sequence at position ${this._pos}`);
|
|
2713
5019
|
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
2714
5020
|
switch (bytesPerSequence) {
|
|
2715
|
-
/* c8 ignore next 6 */
|
|
2716
5021
|
case 1:
|
|
2717
5022
|
if (firstByte < 128) codePoint = firstByte;
|
|
2718
5023
|
break;
|
|
@@ -2728,7 +5033,6 @@ var Tokenizer = class {
|
|
|
2728
5033
|
thirdByte = this.data[this._pos + 2];
|
|
2729
5034
|
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
|
|
2730
5035
|
tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
|
|
2731
|
-
/* c8 ignore next 3 */
|
|
2732
5036
|
if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) codePoint = tempCodePoint;
|
|
2733
5037
|
}
|
|
2734
5038
|
break;
|
|
@@ -2741,7 +5045,6 @@ var Tokenizer = class {
|
|
|
2741
5045
|
if (tempCodePoint > 65535 && tempCodePoint < 1114112) codePoint = tempCodePoint;
|
|
2742
5046
|
}
|
|
2743
5047
|
}
|
|
2744
|
-
/* c8 ignore next 5 */
|
|
2745
5048
|
if (codePoint === null) {
|
|
2746
5049
|
codePoint = 65533;
|
|
2747
5050
|
bytesPerSequence = 1;
|
|
@@ -2915,7 +5218,6 @@ var Tokenizer = class {
|
|
|
2915
5218
|
this.modeStack.push("obj-key");
|
|
2916
5219
|
this.skipWhitespace();
|
|
2917
5220
|
return this.parseValue();
|
|
2918
|
-
/* c8 ignore next 2 */
|
|
2919
5221
|
default: throw new Error(`${decodeErrPrefix$1} unexpected parse state at position ${this._pos}; this shouldn't happen`);
|
|
2920
5222
|
}
|
|
2921
5223
|
}
|
|
@@ -2927,10 +5229,10 @@ var Tokenizer = class {
|
|
|
2927
5229
|
*/
|
|
2928
5230
|
function decode$6(data, options) {
|
|
2929
5231
|
options = Object.assign({ tokenizer: new Tokenizer(data, options) }, options);
|
|
2930
|
-
return decode$
|
|
5232
|
+
return decode$7(data, options);
|
|
2931
5233
|
}
|
|
2932
5234
|
//#endregion
|
|
2933
|
-
//#region node_modules
|
|
5235
|
+
//#region node_modules/@ipld/dag-json/src/index.js
|
|
2934
5236
|
var src_exports = /* @__PURE__ */ __exportAll({
|
|
2935
5237
|
code: () => 297,
|
|
2936
5238
|
decode: () => decode$5,
|
|
@@ -3335,14 +5637,12 @@ function is(value) {
|
|
|
3335
5637
|
if (value === true || value === false) return "boolean";
|
|
3336
5638
|
const typeOf = typeof value;
|
|
3337
5639
|
if (typeOf === "string" || typeOf === "number" || typeOf === "bigint" || typeOf === "symbol") return typeOf;
|
|
3338
|
-
/* c8 ignore next 3 */
|
|
3339
5640
|
if (typeOf === "function") return "Function";
|
|
3340
5641
|
if (Array.isArray(value)) return "Array";
|
|
3341
5642
|
if (value instanceof Uint8Array) return "Uint8Array";
|
|
3342
5643
|
if (value.constructor === Object) return "Object";
|
|
3343
5644
|
const objectType = getObjectType(value);
|
|
3344
5645
|
if (objectType) return objectType;
|
|
3345
|
-
/* c8 ignore next */
|
|
3346
5646
|
return "Object";
|
|
3347
5647
|
}
|
|
3348
5648
|
/**
|
|
@@ -3367,7 +5667,6 @@ var Type = class {
|
|
|
3367
5667
|
this.name = name;
|
|
3368
5668
|
this.terminal = terminal;
|
|
3369
5669
|
}
|
|
3370
|
-
/* c8 ignore next 3 */
|
|
3371
5670
|
toString() {
|
|
3372
5671
|
return `Type[${this.major}].${this.name}`;
|
|
3373
5672
|
}
|
|
@@ -3376,7 +5675,6 @@ var Type = class {
|
|
|
3376
5675
|
* @returns {number}
|
|
3377
5676
|
*/
|
|
3378
5677
|
compare(typ) {
|
|
3379
|
-
/* c8 ignore next 1 */
|
|
3380
5678
|
return this.major < typ.major ? -1 : this.major > typ.major ? 1 : 0;
|
|
3381
5679
|
}
|
|
3382
5680
|
/**
|
|
@@ -3419,7 +5717,6 @@ var Token = class {
|
|
|
3419
5717
|
/** @type {Uint8Array|undefined} */
|
|
3420
5718
|
this.byteValue = void 0;
|
|
3421
5719
|
}
|
|
3422
|
-
/* c8 ignore next 3 */
|
|
3423
5720
|
toString() {
|
|
3424
5721
|
return `Token[${this.type}].${this.value}`;
|
|
3425
5722
|
}
|
|
@@ -3429,6 +5726,10 @@ var Token = class {
|
|
|
3429
5726
|
const useBuffer = globalThis.process && !globalThis.process.browser && globalThis.Buffer && typeof globalThis.Buffer.isBuffer === "function";
|
|
3430
5727
|
const textEncoder = new TextEncoder();
|
|
3431
5728
|
/**
|
|
5729
|
+
* @typedef {import('../interface.js').ByteView} ByteView
|
|
5730
|
+
* @typedef {import('../interface.js').AllocatedByteView} AllocatedByteView
|
|
5731
|
+
*/
|
|
5732
|
+
/**
|
|
3432
5733
|
* @param {Uint8Array} buf
|
|
3433
5734
|
* @returns {boolean}
|
|
3434
5735
|
*/
|
|
@@ -3436,11 +5737,10 @@ function isBuffer(buf) {
|
|
|
3436
5737
|
return useBuffer && globalThis.Buffer.isBuffer(buf);
|
|
3437
5738
|
}
|
|
3438
5739
|
/**
|
|
3439
|
-
* @param {
|
|
3440
|
-
* @returns {
|
|
5740
|
+
* @param {ByteView|number[]} buf
|
|
5741
|
+
* @returns {ByteView}
|
|
3441
5742
|
*/
|
|
3442
5743
|
function asU8A(buf) {
|
|
3443
|
-
/* c8 ignore next */
|
|
3444
5744
|
if (!(buf instanceof Uint8Array)) return Uint8Array.from(buf);
|
|
3445
5745
|
return isBuffer(buf) ? new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength) : buf;
|
|
3446
5746
|
}
|
|
@@ -3458,7 +5758,7 @@ const fromString$1 = useBuffer ? (string) => {
|
|
|
3458
5758
|
/**
|
|
3459
5759
|
* Buffer variant not fast enough for what we need
|
|
3460
5760
|
* @param {number[]} arr
|
|
3461
|
-
* @returns {
|
|
5761
|
+
* @returns {AllocatedByteView}
|
|
3462
5762
|
*/
|
|
3463
5763
|
const fromArray = (arr) => {
|
|
3464
5764
|
return Uint8Array.from(arr);
|
|
@@ -3476,14 +5776,13 @@ const slice = useBuffer ? (bytes, start, end) => {
|
|
|
3476
5776
|
return bytes.slice(start, end);
|
|
3477
5777
|
};
|
|
3478
5778
|
const concat = useBuffer ? (chunks, length) => {
|
|
3479
|
-
/* c8 ignore next 1 */
|
|
3480
5779
|
chunks = chunks.map((c) => c instanceof Uint8Array ? c : globalThis.Buffer.from(c));
|
|
3481
5780
|
return asU8A(globalThis.Buffer.concat(chunks, length));
|
|
3482
5781
|
} :
|
|
3483
5782
|
/**
|
|
3484
|
-
* @param {
|
|
5783
|
+
* @param {ByteView[]} chunks
|
|
3485
5784
|
* @param {number} length
|
|
3486
|
-
* @returns {
|
|
5785
|
+
* @returns {AllocatedByteView}
|
|
3487
5786
|
*/
|
|
3488
5787
|
(chunks, length) => {
|
|
3489
5788
|
const out = new Uint8Array(length);
|
|
@@ -3500,7 +5799,7 @@ const alloc = useBuffer ? (size) => {
|
|
|
3500
5799
|
} :
|
|
3501
5800
|
/**
|
|
3502
5801
|
* @param {number} size
|
|
3503
|
-
* @returns {
|
|
5802
|
+
* @returns {AllocatedByteView}
|
|
3504
5803
|
*/
|
|
3505
5804
|
(size) => {
|
|
3506
5805
|
return new Uint8Array(size);
|
|
@@ -3511,7 +5810,6 @@ const alloc = useBuffer ? (size) => {
|
|
|
3511
5810
|
* @returns {number}
|
|
3512
5811
|
*/
|
|
3513
5812
|
function compare(b1, b2) {
|
|
3514
|
-
/* c8 ignore next 5 */
|
|
3515
5813
|
if (isBuffer(b1) && isBuffer(b2)) return b1.compare(b2);
|
|
3516
5814
|
for (let i = 0; i < b1.length; i++) {
|
|
3517
5815
|
if (b1[i] === b2[i]) continue;
|
|
@@ -3565,6 +5863,10 @@ function utf8ToBytes(str) {
|
|
|
3565
5863
|
* will be `0` to write at the current cursor position but it can be ahead of
|
|
3566
5864
|
* the current cursor. Negative offsets probably work but are untested.
|
|
3567
5865
|
*/
|
|
5866
|
+
/**
|
|
5867
|
+
* @typedef {import('../interface.js').ByteView} ByteView
|
|
5868
|
+
* @typedef {import('../interface.js').AllocatedByteView} AllocatedByteView
|
|
5869
|
+
*/
|
|
3568
5870
|
const defaultChunkSize = 256;
|
|
3569
5871
|
var Bl = class {
|
|
3570
5872
|
/**
|
|
@@ -3576,9 +5878,9 @@ var Bl = class {
|
|
|
3576
5878
|
this.cursor = 0;
|
|
3577
5879
|
/** @type {number} */
|
|
3578
5880
|
this.maxCursor = -1;
|
|
3579
|
-
/** @type {(
|
|
5881
|
+
/** @type {(ByteView|number[])[]} */
|
|
3580
5882
|
this.chunks = [];
|
|
3581
|
-
/** @type {
|
|
5883
|
+
/** @type {ByteView|number[]|null} */
|
|
3582
5884
|
this._initReuseChunk = null;
|
|
3583
5885
|
}
|
|
3584
5886
|
reset() {
|
|
@@ -3591,7 +5893,7 @@ var Bl = class {
|
|
|
3591
5893
|
}
|
|
3592
5894
|
}
|
|
3593
5895
|
/**
|
|
3594
|
-
* @param {
|
|
5896
|
+
* @param {ByteView|number[]} bytes
|
|
3595
5897
|
*/
|
|
3596
5898
|
push(bytes) {
|
|
3597
5899
|
let topChunk = this.chunks[this.chunks.length - 1];
|
|
@@ -3621,14 +5923,13 @@ var Bl = class {
|
|
|
3621
5923
|
}
|
|
3622
5924
|
/**
|
|
3623
5925
|
* @param {boolean} [reset]
|
|
3624
|
-
* @returns {
|
|
5926
|
+
* @returns {AllocatedByteView}
|
|
3625
5927
|
*/
|
|
3626
5928
|
toBytes(reset = false) {
|
|
3627
5929
|
let byts;
|
|
3628
5930
|
if (this.chunks.length === 1) {
|
|
3629
5931
|
const chunk = this.chunks[0];
|
|
3630
5932
|
if (reset && this.cursor > chunk.length / 2) {
|
|
3631
|
-
/* c8 ignore next 2 */
|
|
3632
5933
|
byts = this.cursor === chunk.length ? chunk : chunk.subarray(0, this.cursor);
|
|
3633
5934
|
this._initReuseChunk = null;
|
|
3634
5935
|
this.chunks = [];
|
|
@@ -3641,23 +5942,24 @@ var Bl = class {
|
|
|
3641
5942
|
/**
|
|
3642
5943
|
* U8Bl is a buffer list that writes directly to a user-provided Uint8Array.
|
|
3643
5944
|
* It provides the same interface as Bl but writes to a fixed destination.
|
|
5945
|
+
* @template {ArrayBufferLike} T
|
|
3644
5946
|
*/
|
|
3645
5947
|
var U8Bl = class {
|
|
3646
5948
|
/**
|
|
3647
|
-
* @param {Uint8Array} dest
|
|
5949
|
+
* @param {Uint8Array<T>} dest
|
|
3648
5950
|
*/
|
|
3649
5951
|
constructor(dest) {
|
|
3650
5952
|
this.dest = dest;
|
|
3651
5953
|
/** @type {number} */
|
|
3652
5954
|
this.cursor = 0;
|
|
3653
|
-
/** @type {Uint8Array
|
|
5955
|
+
/** @type {Array<Uint8Array<T>>} */
|
|
3654
5956
|
this.chunks = [dest];
|
|
3655
5957
|
}
|
|
3656
5958
|
reset() {
|
|
3657
5959
|
this.cursor = 0;
|
|
3658
5960
|
}
|
|
3659
5961
|
/**
|
|
3660
|
-
* @param {
|
|
5962
|
+
* @param {ByteView|number[]} bytes
|
|
3661
5963
|
*/
|
|
3662
5964
|
push(bytes) {
|
|
3663
5965
|
if (this.cursor + bytes.length > this.dest.length) throw new Error("write out of bounds, destination buffer is too small");
|
|
@@ -3666,7 +5968,7 @@ var U8Bl = class {
|
|
|
3666
5968
|
}
|
|
3667
5969
|
/**
|
|
3668
5970
|
* @param {boolean} [reset]
|
|
3669
|
-
* @returns {Uint8Array}
|
|
5971
|
+
* @returns {Uint8Array<T>}
|
|
3670
5972
|
*/
|
|
3671
5973
|
toBytes(reset = false) {
|
|
3672
5974
|
const byts = this.dest.subarray(0, this.cursor);
|
|
@@ -3889,7 +6191,7 @@ encodeUintValue.encodedSize = function encodedSize(uint) {
|
|
|
3889
6191
|
* @returns {number}
|
|
3890
6192
|
*/
|
|
3891
6193
|
encodeUint.compareTokens = function compareTokens(tok1, tok2) {
|
|
3892
|
-
return tok1.value < tok2.value ? -1 : tok1.value > tok2.value ? 1 :
|
|
6194
|
+
return tok1.value < tok2.value ? -1 : tok1.value > tok2.value ? 1 : 0;
|
|
3893
6195
|
};
|
|
3894
6196
|
//#endregion
|
|
3895
6197
|
//#region node_modules/@ipld/dag-cbor/node_modules/cborg/lib/1negint.js
|
|
@@ -3961,7 +6263,6 @@ function encodeNegint(writer, token) {
|
|
|
3961
6263
|
encodeNegint.encodedSize = function encodedSize(token) {
|
|
3962
6264
|
const negint = token.value;
|
|
3963
6265
|
const unsigned = typeof negint === "bigint" ? negint * neg1b$1 - pos1b$1 : negint * -1 - 1;
|
|
3964
|
-
/* c8 ignore next 4 */
|
|
3965
6266
|
if (unsigned < uintBoundaries[0]) return 1;
|
|
3966
6267
|
if (unsigned < uintBoundaries[1]) return 2;
|
|
3967
6268
|
if (unsigned < uintBoundaries[2]) return 3;
|
|
@@ -3974,7 +6275,7 @@ encodeNegint.encodedSize = function encodedSize(token) {
|
|
|
3974
6275
|
* @returns {number}
|
|
3975
6276
|
*/
|
|
3976
6277
|
encodeNegint.compareTokens = function compareTokens(tok1, tok2) {
|
|
3977
|
-
return tok1.value < tok2.value ? 1 : tok1.value > tok2.value ? -1 :
|
|
6278
|
+
return tok1.value < tok2.value ? 1 : tok1.value > tok2.value ? -1 : 0;
|
|
3978
6279
|
};
|
|
3979
6280
|
//#endregion
|
|
3980
6281
|
//#region node_modules/@ipld/dag-cbor/node_modules/cborg/lib/2bytes.js
|
|
@@ -4582,12 +6883,10 @@ function encodeFloat16(inp) {
|
|
|
4582
6883
|
const valu32 = dataView.getUint32(0);
|
|
4583
6884
|
const exponent = (valu32 & 2139095040) >> 23;
|
|
4584
6885
|
const mantissa = valu32 & 8388607;
|
|
4585
|
-
/* c8 ignore next 6 */
|
|
4586
6886
|
if (exponent === 255) dataView.setUint16(0, 31744, false);
|
|
4587
6887
|
else if (exponent === 0) dataView.setUint16(0, (valu32 & 2147483648) >> 16 | mantissa >> 13, false);
|
|
4588
6888
|
else {
|
|
4589
6889
|
const logicalExponent = exponent - 127;
|
|
4590
|
-
/* c8 ignore next 6 */
|
|
4591
6890
|
if (logicalExponent < -24) dataView.setUint16(0, 0);
|
|
4592
6891
|
else if (logicalExponent < -14) dataView.setUint16(0, (valu32 & 2147483648) >> 16 | 1 << 24 + logicalExponent, false);
|
|
4593
6892
|
else dataView.setUint16(0, (valu32 & 2147483648) >> 16 | logicalExponent + 15 << 10 | mantissa >> 13, false);
|
|
@@ -4655,6 +6954,7 @@ encodeFloat.compareTokens = encodeUint.compareTokens;
|
|
|
4655
6954
|
//#region node_modules/@ipld/dag-cbor/node_modules/cborg/lib/jump.js
|
|
4656
6955
|
/**
|
|
4657
6956
|
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
6957
|
+
* @typedef {import('../interface.js').AllocatedByteView} AllocatedByteView
|
|
4658
6958
|
*/
|
|
4659
6959
|
/**
|
|
4660
6960
|
* @param {Uint8Array} data
|
|
@@ -4764,7 +7064,7 @@ quick[245] = new Token(Type.true, true, 1);
|
|
|
4764
7064
|
quick[246] = new Token(Type.null, null, 1);
|
|
4765
7065
|
/**
|
|
4766
7066
|
* @param {Token} token
|
|
4767
|
-
* @returns {
|
|
7067
|
+
* @returns {AllocatedByteView|undefined}
|
|
4768
7068
|
*/
|
|
4769
7069
|
function quickEncodeToken(token) {
|
|
4770
7070
|
switch (token.type) {
|
|
@@ -4779,11 +7079,9 @@ function quickEncodeToken(token) {
|
|
|
4779
7079
|
return;
|
|
4780
7080
|
case Type.array:
|
|
4781
7081
|
if (token.value === 0) return fromArray([128]);
|
|
4782
|
-
/* c8 ignore next 2 */
|
|
4783
7082
|
return;
|
|
4784
7083
|
case Type.map:
|
|
4785
7084
|
if (token.value === 0) return fromArray([160]);
|
|
4786
|
-
/* c8 ignore next 2 */
|
|
4787
7085
|
return;
|
|
4788
7086
|
case Type.uint:
|
|
4789
7087
|
if (token.value < 24) return fromArray([Number(token.value)]);
|
|
@@ -4801,6 +7099,8 @@ function quickEncodeToken(token) {
|
|
|
4801
7099
|
* @typedef {import('../interface.js').TokenTypeEncoder} TokenTypeEncoder
|
|
4802
7100
|
* @typedef {import('../interface.js').TokenOrNestedTokens} TokenOrNestedTokens
|
|
4803
7101
|
* @typedef {import('../interface.js').ByteWriter} ByteWriter
|
|
7102
|
+
* @typedef {import('../interface.js').ByteView} ByteView
|
|
7103
|
+
* @typedef {import('../interface.js').AllocatedByteView} AllocatedByteView
|
|
4804
7104
|
*/
|
|
4805
7105
|
/** @type {EncodeOptions} */
|
|
4806
7106
|
const defaultEncodeOptions = {
|
|
@@ -4810,7 +7110,6 @@ const defaultEncodeOptions = {
|
|
|
4810
7110
|
};
|
|
4811
7111
|
/** @type {EncodeOptions} */
|
|
4812
7112
|
const rfc8949EncodeOptions = Object.freeze({
|
|
4813
|
-
float64: true,
|
|
4814
7113
|
mapSorter: rfc8949MapSorter,
|
|
4815
7114
|
quickEncodeToken
|
|
4816
7115
|
});
|
|
@@ -5072,17 +7371,15 @@ function sortMapEntries(entries, options) {
|
|
|
5072
7371
|
* @returns {number}
|
|
5073
7372
|
*/
|
|
5074
7373
|
function mapSorter(e1, e2) {
|
|
5075
|
-
/* c8 ignore next 2 */
|
|
5076
7374
|
const keyToken1 = Array.isArray(e1[0]) ? e1[0][0] : e1[0];
|
|
5077
7375
|
const keyToken2 = Array.isArray(e2[0]) ? e2[0][0] : e2[0];
|
|
5078
7376
|
if (keyToken1.type !== keyToken2.type) return keyToken1.type.compare(keyToken2.type);
|
|
5079
7377
|
const tcmp = cborEncoders[keyToken1.type.major].compareTokens(keyToken1, keyToken2);
|
|
5080
|
-
/* c8 ignore next 5 */
|
|
5081
7378
|
if (tcmp === 0) console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone");
|
|
5082
7379
|
return tcmp;
|
|
5083
7380
|
}
|
|
5084
7381
|
/**
|
|
5085
|
-
* @typedef {Token & { _keyBytes?:
|
|
7382
|
+
* @typedef {Token & { _keyBytes?: AllocatedByteView }} TokenEx
|
|
5086
7383
|
*
|
|
5087
7384
|
* @param {(Token|Token[])[]} e1
|
|
5088
7385
|
* @param {(Token|Token[])[]} e2
|
|
@@ -5100,7 +7397,7 @@ function rfc8949MapSorter(e1, e2) {
|
|
|
5100
7397
|
}
|
|
5101
7398
|
/**
|
|
5102
7399
|
* @param {any} data
|
|
5103
|
-
* @returns {
|
|
7400
|
+
* @returns {AllocatedByteView}
|
|
5104
7401
|
*/
|
|
5105
7402
|
function encodeRfc8949(data) {
|
|
5106
7403
|
return encodeCustom(data, cborEncoders, rfc8949EncodeOptions);
|
|
@@ -5203,11 +7500,27 @@ function directEncode(writer, data, options, refStack) {
|
|
|
5203
7500
|
}
|
|
5204
7501
|
}
|
|
5205
7502
|
/**
|
|
7503
|
+
* @template {ArrayBufferLike} T
|
|
7504
|
+
* @overload
|
|
5206
7505
|
* @param {any} data
|
|
5207
7506
|
* @param {TokenTypeEncoder[]} encoders
|
|
5208
7507
|
* @param {EncodeOptions} options
|
|
5209
|
-
* @param {Uint8Array}
|
|
5210
|
-
* @returns {Uint8Array}
|
|
7508
|
+
* @param {Uint8Array<T>} destination
|
|
7509
|
+
* @returns {Uint8Array<T>}
|
|
7510
|
+
*/
|
|
7511
|
+
/**
|
|
7512
|
+
* @overload
|
|
7513
|
+
* @param {any} data
|
|
7514
|
+
* @param {TokenTypeEncoder[]} encoders
|
|
7515
|
+
* @param {EncodeOptions} options
|
|
7516
|
+
* @returns {AllocatedByteView}
|
|
7517
|
+
*/
|
|
7518
|
+
/**
|
|
7519
|
+
* @param {any} data
|
|
7520
|
+
* @param {TokenTypeEncoder[]} encoders
|
|
7521
|
+
* @param {EncodeOptions} options
|
|
7522
|
+
* @param {ByteView} [destination]
|
|
7523
|
+
* @returns {ByteView}
|
|
5211
7524
|
*/
|
|
5212
7525
|
function encodeCustom(data, encoders, options, destination) {
|
|
5213
7526
|
const hasDest = destination instanceof Uint8Array;
|
|
@@ -5227,7 +7540,6 @@ function encodeCustom(data, encoders, options, destination) {
|
|
|
5227
7540
|
const size = encoder.encodedSize(tokens, options);
|
|
5228
7541
|
if (!hasDest) writeTo = new Bl(size);
|
|
5229
7542
|
encoder(writeTo, tokens, options);
|
|
5230
|
-
/* c8 ignore next 4 */
|
|
5231
7543
|
if (writeTo.chunks.length !== 1) throw new Error(`Unexpected error: pre-calculated length for ${tokens} was wrong`);
|
|
5232
7544
|
return hasDest ? writeTo.toBytes() : asU8A(writeTo.chunks[0]);
|
|
5233
7545
|
}
|
|
@@ -5239,7 +7551,7 @@ function encodeCustom(data, encoders, options, destination) {
|
|
|
5239
7551
|
/**
|
|
5240
7552
|
* @param {any} data
|
|
5241
7553
|
* @param {EncodeOptions} [options]
|
|
5242
|
-
* @returns {
|
|
7554
|
+
* @returns {AllocatedByteView}
|
|
5243
7555
|
*/
|
|
5244
7556
|
function encode$2(data, options) {
|
|
5245
7557
|
options = Object.assign({}, defaultEncodeOptions, options);
|
|
@@ -5288,7 +7600,6 @@ var Tokeniser = class {
|
|
|
5288
7600
|
let token = quick[byt];
|
|
5289
7601
|
if (token === void 0) {
|
|
5290
7602
|
const decoder = jump[byt];
|
|
5291
|
-
/* c8 ignore next 4 */
|
|
5292
7603
|
if (!decoder) throw new Error(`${decodeErrPrefix} no decoder for major type ${byt >>> 5} (byte 0x${byt.toString(16).padStart(2, "0")})`);
|
|
5293
7604
|
const minor = byt & 31;
|
|
5294
7605
|
token = decoder(this.data, this._pos, minor, this.options);
|
|
@@ -5303,7 +7614,7 @@ const BREAK = Symbol.for("BREAK");
|
|
|
5303
7614
|
* @param {Token} token
|
|
5304
7615
|
* @param {DecodeTokenizer} tokeniser
|
|
5305
7616
|
* @param {DecodeOptions} options
|
|
5306
|
-
* @returns {any|BREAK|DONE}
|
|
7617
|
+
* @returns {any|typeof BREAK|typeof DONE}
|
|
5307
7618
|
*/
|
|
5308
7619
|
function tokenToArray(token, tokeniser, options) {
|
|
5309
7620
|
const arr = [];
|
|
@@ -5322,7 +7633,7 @@ function tokenToArray(token, tokeniser, options) {
|
|
|
5322
7633
|
* @param {Token} token
|
|
5323
7634
|
* @param {DecodeTokenizer} tokeniser
|
|
5324
7635
|
* @param {DecodeOptions} options
|
|
5325
|
-
* @returns {any|BREAK|DONE}
|
|
7636
|
+
* @returns {any|typeof BREAK|typeof DONE}
|
|
5326
7637
|
*/
|
|
5327
7638
|
function tokenToMap(token, tokeniser, options) {
|
|
5328
7639
|
const useMaps = options.useMaps === true;
|
|
@@ -5407,7 +7718,7 @@ function createTagDecodeControl(tokeniser, options) {
|
|
|
5407
7718
|
/**
|
|
5408
7719
|
* @param {DecodeTokenizer} tokeniser
|
|
5409
7720
|
* @param {DecodeOptions} options
|
|
5410
|
-
* @returns {any|BREAK|DONE}
|
|
7721
|
+
* @returns {any|typeof BREAK|typeof DONE}
|
|
5411
7722
|
*/
|
|
5412
7723
|
function tokensToObject(tokeniser, options) {
|
|
5413
7724
|
if (tokeniser.done()) return DONE;
|
|
@@ -5425,7 +7736,6 @@ function tokensToObject(tokeniser, options) {
|
|
|
5425
7736
|
}
|
|
5426
7737
|
throw new Error(`${decodeErrPrefix} tag not supported (${token.value})`);
|
|
5427
7738
|
}
|
|
5428
|
-
/* c8 ignore next */
|
|
5429
7739
|
throw new Error("unsupported");
|
|
5430
7740
|
}
|
|
5431
7741
|
/**
|
|
@@ -5730,13 +8040,19 @@ let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzr
|
|
|
5730
8040
|
const POOL_SIZE_MULTIPLIER = 128;
|
|
5731
8041
|
let pool, poolOffset;
|
|
5732
8042
|
function fillPool(bytes) {
|
|
5733
|
-
if (
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
|
|
5738
|
-
|
|
5739
|
-
poolOffset
|
|
8043
|
+
if (bytes < 0) throw new RangeError("Wrong ID size");
|
|
8044
|
+
try {
|
|
8045
|
+
if (!pool || pool.length < bytes) {
|
|
8046
|
+
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
|
|
8047
|
+
webcrypto.getRandomValues(pool);
|
|
8048
|
+
poolOffset = 0;
|
|
8049
|
+
} else if (poolOffset + bytes > pool.length) {
|
|
8050
|
+
webcrypto.getRandomValues(pool);
|
|
8051
|
+
poolOffset = 0;
|
|
8052
|
+
}
|
|
8053
|
+
} catch (e) {
|
|
8054
|
+
pool = void 0;
|
|
8055
|
+
throw e;
|
|
5740
8056
|
}
|
|
5741
8057
|
poolOffset += bytes;
|
|
5742
8058
|
}
|