UNPKG

@fireproof/database

Version:
4 lines 1.26 MB
{ "version": 3, "sources": ["../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/is.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/token.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/byte-utils.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/bl.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/common.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/0uint.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/1negint.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/2bytes.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/3string.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/4array.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/5map.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/6tag.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/7float.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/jump.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/encode.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/decode.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/cborg.js", "../../../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/vendor/varint.js", "../../../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/varint.js", "../../../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/bytes.js", "../../../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/hashes/digest.js", "../../../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/vendor/base-x.js", "../../../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/bases/base.js", "../../../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/bases/base58.js", "../../../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/bases/base32.js", "../../../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/link/interface.js", "../../../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/cid.js", "../../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/encode.js", "../../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/decode.js", "../../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/length.js", "../../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/index.js", "../../../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/hashes/hasher.js", "../../../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/interface.js", "../../../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/index.js", "../../../../node_modules/.pnpm/pvtsutils@1.3.3/node_modules/pvtsutils/build/index.js", "../../../../node_modules/.pnpm/tslib@2.6.1/node_modules/tslib/tslib.es6.mjs", "../../../../node_modules/.pnpm/pvutils@1.1.3/node_modules/pvutils/build/utils.js", "../../../../node_modules/.pnpm/asn1js@3.0.5/node_modules/asn1js/build/index.js", "../../../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.6/node_modules/@peculiar/asn1-schema/build/cjs/enums.js", "../../../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.6/node_modules/@peculiar/asn1-schema/build/cjs/types/bit_string.js", "../../../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.6/node_modules/@peculiar/asn1-schema/build/cjs/types/octet_string.js", "../../../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.6/node_modules/@peculiar/asn1-schema/build/cjs/types/index.js", "../../../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.6/node_modules/@peculiar/asn1-schema/build/cjs/converters.js", "../../../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.6/node_modules/@peculiar/asn1-schema/build/cjs/helper.js", "../../../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.6/node_modules/@peculiar/asn1-schema/build/cjs/schema.js", "../../../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.6/node_modules/@peculiar/asn1-schema/build/cjs/storage.js", "../../../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.6/node_modules/@peculiar/asn1-schema/build/cjs/decorators.js", "../../../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.6/node_modules/@peculiar/asn1-schema/build/cjs/errors/schema_validation.js", "../../../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.6/node_modules/@peculiar/asn1-schema/build/cjs/errors/index.js", "../../../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.6/node_modules/@peculiar/asn1-schema/build/cjs/parser.js", "../../../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.6/node_modules/@peculiar/asn1-schema/build/cjs/serializer.js", "../../../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.6/node_modules/@peculiar/asn1-schema/build/cjs/objects.js", "../../../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.6/node_modules/@peculiar/asn1-schema/build/cjs/convert.js", "../../../../node_modules/.pnpm/@peculiar+asn1-schema@2.3.6/node_modules/@peculiar/asn1-schema/build/cjs/index.js", "../../../../node_modules/.pnpm/@peculiar+json-schema@1.1.12/node_modules/@peculiar/json-schema/build/index.js", "../../../../node_modules/.pnpm/webcrypto-core@1.7.7/node_modules/webcrypto-core/build/webcrypto-core.js", "../../../../node_modules/.pnpm/@peculiar+webcrypto@1.4.3/node_modules/@peculiar/webcrypto/build/webcrypto.js", "../../../../node_modules/.pnpm/idb@7.1.1/node_modules/idb/build/wrap-idb-value.js", "../../../../node_modules/.pnpm/idb@7.1.1/node_modules/idb/build/index.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/json/encode.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/json/decode.js", "../../../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/json/json.js", "../../../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/bases/base64.js", "../../../../node_modules/.pnpm/@ipld+dag-json@10.1.3/node_modules/@ipld/dag-json/src/index.js", "../../src/version.ts", "../../src/store.ts", "../../src/store-browser.ts", "../../src/store-fs.ts", "../../src/database.ts", "../../src/write-queue.ts", "../../../../node_modules/.pnpm/multiformats@11.0.2/node_modules/multiformats/vendor/varint.js", "../../../../node_modules/.pnpm/multiformats@11.0.2/node_modules/multiformats/src/varint.js", "../../../../node_modules/.pnpm/multiformats@11.0.2/node_modules/multiformats/src/bytes.js", "../../../../node_modules/.pnpm/multiformats@11.0.2/node_modules/multiformats/src/hashes/digest.js", "../../../../node_modules/.pnpm/multiformats@11.0.2/node_modules/multiformats/vendor/base-x.js", "../../../../node_modules/.pnpm/multiformats@11.0.2/node_modules/multiformats/src/bases/base.js", "../../../../node_modules/.pnpm/multiformats@11.0.2/node_modules/multiformats/src/bases/base58.js", "../../../../node_modules/.pnpm/multiformats@11.0.2/node_modules/multiformats/src/bases/base32.js", "../../../../node_modules/.pnpm/multiformats@11.0.2/node_modules/multiformats/src/cid.js", "../../../../node_modules/.pnpm/multiformats@11.0.2/node_modules/multiformats/src/link.js", "../../../../node_modules/.pnpm/@alanshaw+pail@0.3.3/node_modules/@alanshaw/pail/src/block.js", "../../../../node_modules/.pnpm/@ipld+car@5.2.0/node_modules/@ipld/car/src/reader.js", "../../../../node_modules/.pnpm/@ipld+dag-cbor@9.0.4/node_modules/@ipld/dag-cbor/src/index.js", "../../../../node_modules/.pnpm/@ipld+car@5.2.0/node_modules/@ipld/car/src/header-validator.js", "../../../../node_modules/.pnpm/@ipld+car@5.2.0/node_modules/@ipld/car/src/decoder-common.js", "../../../../node_modules/.pnpm/@ipld+car@5.2.0/node_modules/@ipld/car/src/decoder.js", "../../../../node_modules/.pnpm/@ipld+car@5.2.0/node_modules/@ipld/car/src/reader-browser.js", "../../../../node_modules/.pnpm/@ipld+car@5.2.0/node_modules/@ipld/car/src/buffer-reader.js", "../../../../node_modules/.pnpm/@ipld+car@5.2.0/node_modules/@ipld/car/src/indexer.js", "../../../../node_modules/.pnpm/@ipld+car@5.2.0/node_modules/@ipld/car/src/iterator.js", "../../../../node_modules/.pnpm/@ipld+car@5.2.0/node_modules/@ipld/car/src/writer.js", "../../../../node_modules/.pnpm/@ipld+car@5.2.0/node_modules/@ipld/car/src/encoder.js", "../../../../node_modules/.pnpm/@ipld+car@5.2.0/node_modules/@ipld/car/src/writer-browser.js", "../../../../node_modules/.pnpm/@ipld+car@5.2.0/node_modules/@ipld/car/src/buffer-writer.js", "../../../../node_modules/.pnpm/cborg@1.10.0/node_modules/cborg/esm/lib/is.js", "../../../../node_modules/.pnpm/cborg@1.10.0/node_modules/cborg/esm/lib/token.js", "../../../../node_modules/.pnpm/cborg@1.10.0/node_modules/cborg/esm/lib/byte-utils.js", "../../../../node_modules/.pnpm/cborg@1.10.0/node_modules/cborg/esm/lib/bl.js", "../../../../node_modules/.pnpm/cborg@1.10.0/node_modules/cborg/esm/lib/common.js", "../../../../node_modules/.pnpm/cborg@1.10.0/node_modules/cborg/esm/lib/0uint.js", "../../../../node_modules/.pnpm/cborg@1.10.0/node_modules/cborg/esm/lib/1negint.js", "../../../../node_modules/.pnpm/cborg@1.10.0/node_modules/cborg/esm/lib/2bytes.js", "../../../../node_modules/.pnpm/cborg@1.10.0/node_modules/cborg/esm/lib/3string.js", "../../../../node_modules/.pnpm/cborg@1.10.0/node_modules/cborg/esm/lib/4array.js", "../../../../node_modules/.pnpm/cborg@1.10.0/node_modules/cborg/esm/lib/5map.js", "../../../../node_modules/.pnpm/cborg@1.10.0/node_modules/cborg/esm/lib/6tag.js", "../../../../node_modules/.pnpm/cborg@1.10.0/node_modules/cborg/esm/lib/7float.js", "../../../../node_modules/.pnpm/cborg@1.10.0/node_modules/cborg/esm/lib/jump.js", "../../../../node_modules/.pnpm/cborg@1.10.0/node_modules/cborg/esm/lib/encode.js", "../../../../node_modules/.pnpm/cborg@1.10.0/node_modules/cborg/esm/lib/decode.js", "../../../../node_modules/.pnpm/cborg@1.10.0/node_modules/cborg/esm/lib/length.js", "../../../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/block.js", "../../../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/hashes/sha2.js", "../../../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/codecs/raw.js", "../../src/loader-helpers.ts", "../../src/encrypted-block.ts", "../../../../node_modules/.pnpm/prolly-trees@1.0.4/node_modules/prolly-trees/esm/src/utils.js", "../../../../node_modules/.pnpm/prolly-trees@1.0.4/node_modules/prolly-trees/esm/src/base.js", "../../../../node_modules/.pnpm/prolly-trees@1.0.4/node_modules/prolly-trees/esm/src/cid-set.js", "../../src/crypto.ts", "../../src/encrypt-helpers.ts", "../../../../node_modules/.pnpm/prolly-trees@1.0.4/node_modules/prolly-trees/esm/src/cache.js", "../../src/loader.ts", "../../src/transaction.ts", "../../../../node_modules/.pnpm/multiformats@11.0.2/node_modules/multiformats/src/hashes/hasher.js", "../../../../node_modules/.pnpm/multiformats@11.0.2/node_modules/multiformats/src/block.js", "../../../../node_modules/.pnpm/multiformats@11.0.2/node_modules/multiformats/src/hashes/sha2.js", "../../../../node_modules/.pnpm/@alanshaw+pail@0.3.3/node_modules/@alanshaw/pail/src/clock.js", "../../../../node_modules/.pnpm/@alanshaw+pail@0.3.3/node_modules/@alanshaw/pail/src/shard.js", "../../../../node_modules/.pnpm/@alanshaw+pail@0.3.3/node_modules/@alanshaw/pail/src/index.js", "../../../../node_modules/.pnpm/@alanshaw+pail@0.3.3/node_modules/@alanshaw/pail/src/crdt.js", "../../src/crdt-helpers.ts", "../../src/crdt.ts"], "sourcesContent": ["const typeofs = [\n 'string',\n 'number',\n 'bigint',\n 'symbol'\n];\nconst objectTypeNames = [\n 'Function',\n 'Generator',\n 'AsyncGenerator',\n 'GeneratorFunction',\n 'AsyncGeneratorFunction',\n 'AsyncFunction',\n 'Observable',\n 'Array',\n 'Buffer',\n 'Object',\n 'RegExp',\n 'Date',\n 'Error',\n 'Map',\n 'Set',\n 'WeakMap',\n 'WeakSet',\n 'ArrayBuffer',\n 'SharedArrayBuffer',\n 'DataView',\n 'Promise',\n 'URL',\n 'HTMLElement',\n 'Int8Array',\n 'Uint8Array',\n 'Uint8ClampedArray',\n 'Int16Array',\n 'Uint16Array',\n 'Int32Array',\n 'Uint32Array',\n 'Float32Array',\n 'Float64Array',\n 'BigInt64Array',\n 'BigUint64Array'\n];\nexport function is(value) {\n if (value === null) {\n return 'null';\n }\n if (value === undefined) {\n return 'undefined';\n }\n if (value === true || value === false) {\n return 'boolean';\n }\n const typeOf = typeof value;\n if (typeofs.includes(typeOf)) {\n return typeOf;\n }\n if (typeOf === 'function') {\n return 'Function';\n }\n if (Array.isArray(value)) {\n return 'Array';\n }\n if (isBuffer(value)) {\n return 'Buffer';\n }\n const objectType = getObjectType(value);\n if (objectType) {\n return objectType;\n }\n return 'Object';\n}\nfunction isBuffer(value) {\n return value && value.constructor && value.constructor.isBuffer && value.constructor.isBuffer.call(null, value);\n}\nfunction getObjectType(value) {\n const objectTypeName = Object.prototype.toString.call(value).slice(8, -1);\n if (objectTypeNames.includes(objectTypeName)) {\n return objectTypeName;\n }\n return undefined;\n}", "class Type {\n constructor(major, name, terminal) {\n this.major = major;\n this.majorEncoded = major << 5;\n this.name = name;\n this.terminal = terminal;\n }\n toString() {\n return `Type[${ this.major }].${ this.name }`;\n }\n compare(typ) {\n return this.major < typ.major ? -1 : this.major > typ.major ? 1 : 0;\n }\n}\nType.uint = new Type(0, 'uint', true);\nType.negint = new Type(1, 'negint', true);\nType.bytes = new Type(2, 'bytes', true);\nType.string = new Type(3, 'string', true);\nType.array = new Type(4, 'array', false);\nType.map = new Type(5, 'map', false);\nType.tag = new Type(6, 'tag', false);\nType.float = new Type(7, 'float', true);\nType.false = new Type(7, 'false', true);\nType.true = new Type(7, 'true', true);\nType.null = new Type(7, 'null', true);\nType.undefined = new Type(7, 'undefined', true);\nType.break = new Type(7, 'break', true);\nclass Token {\n constructor(type, value, encodedLength) {\n this.type = type;\n this.value = value;\n this.encodedLength = encodedLength;\n this.encodedBytes = undefined;\n this.byteValue = undefined;\n }\n toString() {\n return `Token[${ this.type }].${ this.value }`;\n }\n}\nexport {\n Type,\n Token\n};", "export const useBuffer = globalThis.process && !globalThis.process.browser && globalThis.Buffer && typeof globalThis.Buffer.isBuffer === 'function';\nconst textDecoder = new TextDecoder();\nconst textEncoder = new TextEncoder();\nfunction isBuffer(buf) {\n return useBuffer && globalThis.Buffer.isBuffer(buf);\n}\nexport function asU8A(buf) {\n if (!(buf instanceof Uint8Array)) {\n return Uint8Array.from(buf);\n }\n return isBuffer(buf) ? new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength) : buf;\n}\nexport const toString = useBuffer ? (bytes, start, end) => {\n return end - start > 64 ? globalThis.Buffer.from(bytes.subarray(start, end)).toString('utf8') : utf8Slice(bytes, start, end);\n} : (bytes, start, end) => {\n return end - start > 64 ? textDecoder.decode(bytes.subarray(start, end)) : utf8Slice(bytes, start, end);\n};\nexport const fromString = useBuffer ? string => {\n return string.length > 64 ? globalThis.Buffer.from(string) : utf8ToBytes(string);\n} : string => {\n return string.length > 64 ? textEncoder.encode(string) : utf8ToBytes(string);\n};\nexport const fromArray = arr => {\n return Uint8Array.from(arr);\n};\nexport const slice = useBuffer ? (bytes, start, end) => {\n if (isBuffer(bytes)) {\n return new Uint8Array(bytes.subarray(start, end));\n }\n return bytes.slice(start, end);\n} : (bytes, start, end) => {\n return bytes.slice(start, end);\n};\nexport const concat = useBuffer ? (chunks, length) => {\n chunks = chunks.map(c => c instanceof Uint8Array ? c : globalThis.Buffer.from(c));\n return asU8A(globalThis.Buffer.concat(chunks, length));\n} : (chunks, length) => {\n const out = new Uint8Array(length);\n let off = 0;\n for (let b of chunks) {\n if (off + b.length > out.length) {\n b = b.subarray(0, out.length - off);\n }\n out.set(b, off);\n off += b.length;\n }\n return out;\n};\nexport const alloc = useBuffer ? size => {\n return globalThis.Buffer.allocUnsafe(size);\n} : size => {\n return new Uint8Array(size);\n};\nexport const toHex = useBuffer ? d => {\n if (typeof d === 'string') {\n return d;\n }\n return globalThis.Buffer.from(toBytes(d)).toString('hex');\n} : d => {\n if (typeof d === 'string') {\n return d;\n }\n return Array.prototype.reduce.call(toBytes(d), (p, c) => `${ p }${ c.toString(16).padStart(2, '0') }`, '');\n};\nexport const fromHex = useBuffer ? hex => {\n if (hex instanceof Uint8Array) {\n return hex;\n }\n return globalThis.Buffer.from(hex, 'hex');\n} : hex => {\n if (hex instanceof Uint8Array) {\n return hex;\n }\n if (!hex.length) {\n return new Uint8Array(0);\n }\n return new Uint8Array(hex.split('').map((c, i, d) => i % 2 === 0 ? `0x${ c }${ d[i + 1] }` : '').filter(Boolean).map(e => parseInt(e, 16)));\n};\nfunction toBytes(obj) {\n if (obj instanceof Uint8Array && obj.constructor.name === 'Uint8Array') {\n return obj;\n }\n if (obj instanceof ArrayBuffer) {\n return new Uint8Array(obj);\n }\n if (ArrayBuffer.isView(obj)) {\n return new Uint8Array(obj.buffer, obj.byteOffset, obj.byteLength);\n }\n throw new Error('Unknown type, must be binary type');\n}\nexport function compare(b1, b2) {\n if (isBuffer(b1) && isBuffer(b2)) {\n return b1.compare(b2);\n }\n for (let i = 0; i < b1.length; i++) {\n if (b1[i] === b2[i]) {\n continue;\n }\n return b1[i] < b2[i] ? -1 : 1;\n }\n return 0;\n}\nfunction utf8ToBytes(string, units = Infinity) {\n let codePoint;\n const length = string.length;\n let leadSurrogate = null;\n const bytes = [];\n for (let i = 0; i < length; ++i) {\n codePoint = string.charCodeAt(i);\n if (codePoint > 55295 && codePoint < 57344) {\n if (!leadSurrogate) {\n if (codePoint > 56319) {\n if ((units -= 3) > -1)\n bytes.push(239, 191, 189);\n continue;\n } else if (i + 1 === length) {\n if ((units -= 3) > -1)\n bytes.push(239, 191, 189);\n continue;\n }\n leadSurrogate = codePoint;\n continue;\n }\n if (codePoint < 56320) {\n if ((units -= 3) > -1)\n bytes.push(239, 191, 189);\n leadSurrogate = codePoint;\n continue;\n }\n codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;\n } else if (leadSurrogate) {\n if ((units -= 3) > -1)\n bytes.push(239, 191, 189);\n }\n leadSurrogate = null;\n if (codePoint < 128) {\n if ((units -= 1) < 0)\n break;\n bytes.push(codePoint);\n } else if (codePoint < 2048) {\n if ((units -= 2) < 0)\n break;\n bytes.push(codePoint >> 6 | 192, codePoint & 63 | 128);\n } else if (codePoint < 65536) {\n if ((units -= 3) < 0)\n break;\n bytes.push(codePoint >> 12 | 224, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);\n } else if (codePoint < 1114112) {\n if ((units -= 4) < 0)\n break;\n bytes.push(codePoint >> 18 | 240, codePoint >> 12 & 63 | 128, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);\n } else {\n throw new Error('Invalid code point');\n }\n }\n return bytes;\n}\nfunction utf8Slice(buf, offset, end) {\n const res = [];\n while (offset < end) {\n const firstByte = buf[offset];\n let codePoint = null;\n let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;\n if (offset + bytesPerSequence <= end) {\n let secondByte, thirdByte, fourthByte, tempCodePoint;\n switch (bytesPerSequence) {\n case 1:\n if (firstByte < 128) {\n codePoint = firstByte;\n }\n break;\n case 2:\n secondByte = buf[offset + 1];\n if ((secondByte & 192) === 128) {\n tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;\n if (tempCodePoint > 127) {\n codePoint = tempCodePoint;\n }\n }\n break;\n case 3:\n secondByte = buf[offset + 1];\n thirdByte = buf[offset + 2];\n if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {\n tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;\n if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {\n codePoint = tempCodePoint;\n }\n }\n break;\n case 4:\n secondByte = buf[offset + 1];\n thirdByte = buf[offset + 2];\n fourthByte = buf[offset + 3];\n if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {\n tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;\n if (tempCodePoint > 65535 && tempCodePoint < 1114112) {\n codePoint = tempCodePoint;\n }\n }\n }\n }\n if (codePoint === null) {\n codePoint = 65533;\n bytesPerSequence = 1;\n } else if (codePoint > 65535) {\n codePoint -= 65536;\n res.push(codePoint >>> 10 & 1023 | 55296);\n codePoint = 56320 | codePoint & 1023;\n }\n res.push(codePoint);\n offset += bytesPerSequence;\n }\n return decodeCodePointsArray(res);\n}\nconst MAX_ARGUMENTS_LENGTH = 4096;\nexport function decodeCodePointsArray(codePoints) {\n const len = codePoints.length;\n if (len <= MAX_ARGUMENTS_LENGTH) {\n return String.fromCharCode.apply(String, codePoints);\n }\n let res = '';\n let i = 0;\n while (i < len) {\n res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));\n }\n return res;\n}", "import {\n alloc,\n concat,\n slice\n} from './byte-utils.js';\nconst defaultChunkSize = 256;\nexport class Bl {\n constructor(chunkSize = defaultChunkSize) {\n this.chunkSize = chunkSize;\n this.cursor = 0;\n this.maxCursor = -1;\n this.chunks = [];\n this._initReuseChunk = null;\n }\n reset() {\n this.cursor = 0;\n this.maxCursor = -1;\n if (this.chunks.length) {\n this.chunks = [];\n }\n if (this._initReuseChunk !== null) {\n this.chunks.push(this._initReuseChunk);\n this.maxCursor = this._initReuseChunk.length - 1;\n }\n }\n push(bytes) {\n let topChunk = this.chunks[this.chunks.length - 1];\n const newMax = this.cursor + bytes.length;\n if (newMax <= this.maxCursor + 1) {\n const chunkPos = topChunk.length - (this.maxCursor - this.cursor) - 1;\n topChunk.set(bytes, chunkPos);\n } else {\n if (topChunk) {\n const chunkPos = topChunk.length - (this.maxCursor - this.cursor) - 1;\n if (chunkPos < topChunk.length) {\n this.chunks[this.chunks.length - 1] = topChunk.subarray(0, chunkPos);\n this.maxCursor = this.cursor - 1;\n }\n }\n if (bytes.length < 64 && bytes.length < this.chunkSize) {\n topChunk = alloc(this.chunkSize);\n this.chunks.push(topChunk);\n this.maxCursor += topChunk.length;\n if (this._initReuseChunk === null) {\n this._initReuseChunk = topChunk;\n }\n topChunk.set(bytes, 0);\n } else {\n this.chunks.push(bytes);\n this.maxCursor += bytes.length;\n }\n }\n this.cursor += bytes.length;\n }\n toBytes(reset = false) {\n let byts;\n if (this.chunks.length === 1) {\n const chunk = this.chunks[0];\n if (reset && this.cursor > chunk.length / 2) {\n byts = this.cursor === chunk.length ? chunk : chunk.subarray(0, this.cursor);\n this._initReuseChunk = null;\n this.chunks = [];\n } else {\n byts = slice(chunk, 0, this.cursor);\n }\n } else {\n byts = concat(this.chunks, this.cursor);\n }\n if (reset) {\n this.reset();\n }\n return byts;\n }\n}", "const decodeErrPrefix = 'CBOR decode error:';\nconst encodeErrPrefix = 'CBOR encode error:';\nconst uintMinorPrefixBytes = [];\nuintMinorPrefixBytes[23] = 1;\nuintMinorPrefixBytes[24] = 2;\nuintMinorPrefixBytes[25] = 3;\nuintMinorPrefixBytes[26] = 5;\nuintMinorPrefixBytes[27] = 9;\nfunction assertEnoughData(data, pos, need) {\n if (data.length - pos < need) {\n throw new Error(`${ decodeErrPrefix } not enough data for type`);\n }\n}\nexport {\n decodeErrPrefix,\n encodeErrPrefix,\n uintMinorPrefixBytes,\n assertEnoughData\n};", "import {\n Token,\n Type\n} from './token.js';\nimport {\n decodeErrPrefix,\n assertEnoughData\n} from './common.js';\nexport const uintBoundaries = [\n 24,\n 256,\n 65536,\n 4294967296,\n BigInt('18446744073709551616')\n];\nexport function readUint8(data, offset, options) {\n assertEnoughData(data, offset, 1);\n const value = data[offset];\n if (options.strict === true && value < uintBoundaries[0]) {\n throw new Error(`${ decodeErrPrefix } integer encoded in more bytes than necessary (strict decode)`);\n }\n return value;\n}\nexport function readUint16(data, offset, options) {\n assertEnoughData(data, offset, 2);\n const value = data[offset] << 8 | data[offset + 1];\n if (options.strict === true && value < uintBoundaries[1]) {\n throw new Error(`${ decodeErrPrefix } integer encoded in more bytes than necessary (strict decode)`);\n }\n return value;\n}\nexport function readUint32(data, offset, options) {\n assertEnoughData(data, offset, 4);\n const value = data[offset] * 16777216 + (data[offset + 1] << 16) + (data[offset + 2] << 8) + data[offset + 3];\n if (options.strict === true && value < uintBoundaries[2]) {\n throw new Error(`${ decodeErrPrefix } integer encoded in more bytes than necessary (strict decode)`);\n }\n return value;\n}\nexport function readUint64(data, offset, options) {\n assertEnoughData(data, offset, 8);\n const hi = data[offset] * 16777216 + (data[offset + 1] << 16) + (data[offset + 2] << 8) + data[offset + 3];\n const lo = data[offset + 4] * 16777216 + (data[offset + 5] << 16) + (data[offset + 6] << 8) + data[offset + 7];\n const value = (BigInt(hi) << BigInt(32)) + BigInt(lo);\n if (options.strict === true && value < uintBoundaries[3]) {\n throw new Error(`${ decodeErrPrefix } integer encoded in more bytes than necessary (strict decode)`);\n }\n if (value <= Number.MAX_SAFE_INTEGER) {\n return Number(value);\n }\n if (options.allowBigInt === true) {\n return value;\n }\n throw new Error(`${ decodeErrPrefix } integers outside of the safe integer range are not supported`);\n}\nexport function decodeUint8(data, pos, _minor, options) {\n return new Token(Type.uint, readUint8(data, pos + 1, options), 2);\n}\nexport function decodeUint16(data, pos, _minor, options) {\n return new Token(Type.uint, readUint16(data, pos + 1, options), 3);\n}\nexport function decodeUint32(data, pos, _minor, options) {\n return new Token(Type.uint, readUint32(data, pos + 1, options), 5);\n}\nexport function decodeUint64(data, pos, _minor, options) {\n return new Token(Type.uint, readUint64(data, pos + 1, options), 9);\n}\nexport function encodeUint(buf, token) {\n return encodeUintValue(buf, 0, token.value);\n}\nexport function encodeUintValue(buf, major, uint) {\n if (uint < uintBoundaries[0]) {\n const nuint = Number(uint);\n buf.push([major | nuint]);\n } else if (uint < uintBoundaries[1]) {\n const nuint = Number(uint);\n buf.push([\n major | 24,\n nuint\n ]);\n } else if (uint < uintBoundaries[2]) {\n const nuint = Number(uint);\n buf.push([\n major | 25,\n nuint >>> 8,\n nuint & 255\n ]);\n } else if (uint < uintBoundaries[3]) {\n const nuint = Number(uint);\n buf.push([\n major | 26,\n nuint >>> 24 & 255,\n nuint >>> 16 & 255,\n nuint >>> 8 & 255,\n nuint & 255\n ]);\n } else {\n const buint = BigInt(uint);\n if (buint < uintBoundaries[4]) {\n const set = [\n major | 27,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0\n ];\n let lo = Number(buint & BigInt(4294967295));\n let hi = Number(buint >> BigInt(32) & BigInt(4294967295));\n set[8] = lo & 255;\n lo = lo >> 8;\n set[7] = lo & 255;\n lo = lo >> 8;\n set[6] = lo & 255;\n lo = lo >> 8;\n set[5] = lo & 255;\n set[4] = hi & 255;\n hi = hi >> 8;\n set[3] = hi & 255;\n hi = hi >> 8;\n set[2] = hi & 255;\n hi = hi >> 8;\n set[1] = hi & 255;\n buf.push(set);\n } else {\n throw new Error(`${ decodeErrPrefix } encountered BigInt larger than allowable range`);\n }\n }\n}\nencodeUint.encodedSize = function encodedSize(token) {\n return encodeUintValue.encodedSize(token.value);\n};\nencodeUintValue.encodedSize = function encodedSize(uint) {\n if (uint < uintBoundaries[0]) {\n return 1;\n }\n if (uint < uintBoundaries[1]) {\n return 2;\n }\n if (uint < uintBoundaries[2]) {\n return 3;\n }\n if (uint < uintBoundaries[3]) {\n return 5;\n }\n return 9;\n};\nencodeUint.compareTokens = function compareTokens(tok1, tok2) {\n return tok1.value < tok2.value ? -1 : tok1.value > tok2.value ? 1 : 0;\n};", "import {\n Token,\n Type\n} from './token.js';\nimport * as uint from './0uint.js';\nimport { decodeErrPrefix } from './common.js';\nexport function decodeNegint8(data, pos, _minor, options) {\n return new Token(Type.negint, -1 - uint.readUint8(data, pos + 1, options), 2);\n}\nexport function decodeNegint16(data, pos, _minor, options) {\n return new Token(Type.negint, -1 - uint.readUint16(data, pos + 1, options), 3);\n}\nexport function decodeNegint32(data, pos, _minor, options) {\n return new Token(Type.negint, -1 - uint.readUint32(data, pos + 1, options), 5);\n}\nconst neg1b = BigInt(-1);\nconst pos1b = BigInt(1);\nexport function decodeNegint64(data, pos, _minor, options) {\n const int = uint.readUint64(data, pos + 1, options);\n if (typeof int !== 'bigint') {\n const value = -1 - int;\n if (value >= Number.MIN_SAFE_INTEGER) {\n return new Token(Type.negint, value, 9);\n }\n }\n if (options.allowBigInt !== true) {\n throw new Error(`${ decodeErrPrefix } integers outside of the safe integer range are not supported`);\n }\n return new Token(Type.negint, neg1b - BigInt(int), 9);\n}\nexport function encodeNegint(buf, token) {\n const negint = token.value;\n const unsigned = typeof negint === 'bigint' ? negint * neg1b - pos1b : negint * -1 - 1;\n uint.encodeUintValue(buf, token.type.majorEncoded, unsigned);\n}\nencodeNegint.encodedSize = function encodedSize(token) {\n const negint = token.value;\n const unsigned = typeof negint === 'bigint' ? negint * neg1b - pos1b : negint * -1 - 1;\n if (unsigned < uint.uintBoundaries[0]) {\n return 1;\n }\n if (unsigned < uint.uintBoundaries[1]) {\n return 2;\n }\n if (unsigned < uint.uintBoundaries[2]) {\n return 3;\n }\n if (unsigned < uint.uintBoundaries[3]) {\n return 5;\n }\n return 9;\n};\nencodeNegint.compareTokens = function compareTokens(tok1, tok2) {\n return tok1.value < tok2.value ? 1 : tok1.value > tok2.value ? -1 : 0;\n};", "import {\n Token,\n Type\n} from './token.js';\nimport {\n assertEnoughData,\n decodeErrPrefix\n} from './common.js';\nimport * as uint from './0uint.js';\nimport {\n compare,\n fromString,\n slice\n} from './byte-utils.js';\nfunction toToken(data, pos, prefix, length) {\n assertEnoughData(data, pos, prefix + length);\n const buf = slice(data, pos + prefix, pos + prefix + length);\n return new Token(Type.bytes, buf, prefix + length);\n}\nexport function decodeBytesCompact(data, pos, minor, _options) {\n return toToken(data, pos, 1, minor);\n}\nexport function decodeBytes8(data, pos, _minor, options) {\n return toToken(data, pos, 2, uint.readUint8(data, pos + 1, options));\n}\nexport function decodeBytes16(data, pos, _minor, options) {\n return toToken(data, pos, 3, uint.readUint16(data, pos + 1, options));\n}\nexport function decodeBytes32(data, pos, _minor, options) {\n return toToken(data, pos, 5, uint.readUint32(data, pos + 1, options));\n}\nexport function decodeBytes64(data, pos, _minor, options) {\n const l = uint.readUint64(data, pos + 1, options);\n if (typeof l === 'bigint') {\n throw new Error(`${ decodeErrPrefix } 64-bit integer bytes lengths not supported`);\n }\n return toToken(data, pos, 9, l);\n}\nfunction tokenBytes(token) {\n if (token.encodedBytes === undefined) {\n token.encodedBytes = token.type === Type.string ? fromString(token.value) : token.value;\n }\n return token.encodedBytes;\n}\nexport function encodeBytes(buf, token) {\n const bytes = tokenBytes(token);\n uint.encodeUintValue(buf, token.type.majorEncoded, bytes.length);\n buf.push(bytes);\n}\nencodeBytes.encodedSize = function encodedSize(token) {\n const bytes = tokenBytes(token);\n return uint.encodeUintValue.encodedSize(bytes.length) + bytes.length;\n};\nencodeBytes.compareTokens = function compareTokens(tok1, tok2) {\n return compareBytes(tokenBytes(tok1), tokenBytes(tok2));\n};\nexport function compareBytes(b1, b2) {\n return b1.length < b2.length ? -1 : b1.length > b2.length ? 1 : compare(b1, b2);\n}", "import {\n Token,\n Type\n} from './token.js';\nimport {\n assertEnoughData,\n decodeErrPrefix\n} from './common.js';\nimport * as uint from './0uint.js';\nimport { encodeBytes } from './2bytes.js';\nimport {\n toString,\n slice\n} from './byte-utils.js';\nfunction toToken(data, pos, prefix, length, options) {\n const totLength = prefix + length;\n assertEnoughData(data, pos, totLength);\n const tok = new Token(Type.string, toString(data, pos + prefix, pos + totLength), totLength);\n if (options.retainStringBytes === true) {\n tok.byteValue = slice(data, pos + prefix, pos + totLength);\n }\n return tok;\n}\nexport function decodeStringCompact(data, pos, minor, options) {\n return toToken(data, pos, 1, minor, options);\n}\nexport function decodeString8(data, pos, _minor, options) {\n return toToken(data, pos, 2, uint.readUint8(data, pos + 1, options), options);\n}\nexport function decodeString16(data, pos, _minor, options) {\n return toToken(data, pos, 3, uint.readUint16(data, pos + 1, options), options);\n}\nexport function decodeString32(data, pos, _minor, options) {\n return toToken(data, pos, 5, uint.readUint32(data, pos + 1, options), options);\n}\nexport function decodeString64(data, pos, _minor, options) {\n const l = uint.readUint64(data, pos + 1, options);\n if (typeof l === 'bigint') {\n throw new Error(`${ decodeErrPrefix } 64-bit integer string lengths not supported`);\n }\n return toToken(data, pos, 9, l, options);\n}\nexport const encodeString = encodeBytes;", "import {\n Token,\n Type\n} from './token.js';\nimport * as uint from './0uint.js';\nimport { decodeErrPrefix } from './common.js';\nfunction toToken(_data, _pos, prefix, length) {\n return new Token(Type.array, length, prefix);\n}\nexport function decodeArrayCompact(data, pos, minor, _options) {\n return toToken(data, pos, 1, minor);\n}\nexport function decodeArray8(data, pos, _minor, options) {\n return toToken(data, pos, 2, uint.readUint8(data, pos + 1, options));\n}\nexport function decodeArray16(data, pos, _minor, options) {\n return toToken(data, pos, 3, uint.readUint16(data, pos + 1, options));\n}\nexport function decodeArray32(data, pos, _minor, options) {\n return toToken(data, pos, 5, uint.readUint32(data, pos + 1, options));\n}\nexport function decodeArray64(data, pos, _minor, options) {\n const l = uint.readUint64(data, pos + 1, options);\n if (typeof l === 'bigint') {\n throw new Error(`${ decodeErrPrefix } 64-bit integer array lengths not supported`);\n }\n return toToken(data, pos, 9, l);\n}\nexport function decodeArrayIndefinite(data, pos, _minor, options) {\n if (options.allowIndefinite === false) {\n throw new Error(`${ decodeErrPrefix } indefinite length items not allowed`);\n }\n return toToken(data, pos, 1, Infinity);\n}\nexport function encodeArray(buf, token) {\n uint.encodeUintValue(buf, Type.array.majorEncoded, token.value);\n}\nencodeArray.compareTokens = uint.encodeUint.compareTokens;\nencodeArray.encodedSize = function encodedSize(token) {\n return uint.encodeUintValue.encodedSize(token.value);\n};", "import {\n Token,\n Type\n} from './token.js';\nimport * as uint from './0uint.js';\nimport { decodeErrPrefix } from './common.js';\nfunction toToken(_data, _pos, prefix, length) {\n return new Token(Type.map, length, prefix);\n}\nexport function decodeMapCompact(data, pos, minor, _options) {\n return toToken(data, pos, 1, minor);\n}\nexport function decodeMap8(data, pos, _minor, options) {\n return toToken(data, pos, 2, uint.readUint8(data, pos + 1, options));\n}\nexport function decodeMap16(data, pos, _minor, options) {\n return toToken(data, pos, 3, uint.readUint16(data, pos + 1, options));\n}\nexport function decodeMap32(data, pos, _minor, options) {\n return toToken(data, pos, 5, uint.readUint32(data, pos + 1, options));\n}\nexport function decodeMap64(data, pos, _minor, options) {\n const l = uint.readUint64(data, pos + 1, options);\n if (typeof l === 'bigint') {\n throw new Error(`${ decodeErrPrefix } 64-bit integer map lengths not supported`);\n }\n return toToken(data, pos, 9, l);\n}\nexport function decodeMapIndefinite(data, pos, _minor, options) {\n if (options.allowIndefinite === false) {\n throw new Error(`${ decodeErrPrefix } indefinite length items not allowed`);\n }\n return toToken(data, pos, 1, Infinity);\n}\nexport function encodeMap(buf, token) {\n uint.encodeUintValue(buf, Type.map.majorEncoded, token.value);\n}\nencodeMap.compareTokens = uint.encodeUint.compareTokens;\nencodeMap.encodedSize = function encodedSize(token) {\n return uint.encodeUintValue.encodedSize(token.value);\n};", "import {\n Token,\n Type\n} from './token.js';\nimport * as uint from './0uint.js';\nexport function decodeTagCompact(_data, _pos, minor, _options) {\n return new Token(Type.tag, minor, 1);\n}\nexport function decodeTag8(data, pos, _minor, options) {\n return new Token(Type.tag, uint.readUint8(data, pos + 1, options), 2);\n}\nexport function decodeTag16(data, pos, _minor, options) {\n return new Token(Type.tag, uint.readUint16(data, pos + 1, options), 3);\n}\nexport function decodeTag32(data, pos, _minor, options) {\n return new Token(Type.tag, uint.readUint32(data, pos + 1, options), 5);\n}\nexport function decodeTag64(data, pos, _minor, options) {\n return new Token(Type.tag, uint.readUint64(data, pos + 1, options), 9);\n}\nexport function encodeTag(buf, token) {\n uint.encodeUintValue(buf, Type.tag.majorEncoded, token.value);\n}\nencodeTag.compareTokens = uint.encodeUint.compareTokens;\nencodeTag.encodedSize = function encodedSize(token) {\n return uint.encodeUintValue.encodedSize(token.value);\n};", "import {\n Token,\n Type\n} from './token.js';\nimport { decodeErrPrefix } from './common.js';\nimport { encodeUint } from './0uint.js';\nconst MINOR_FALSE = 20;\nconst MINOR_TRUE = 21;\nconst MINOR_NULL = 22;\nconst MINOR_UNDEFINED = 23;\nexport function decodeUndefined(_data, _pos, _minor, options) {\n if (options.allowUndefined === false) {\n throw new Error(`${ decodeErrPrefix } undefined values are not supported`);\n } else if (options.coerceUndefinedToNull === true) {\n return new Token(Type.null, null, 1);\n }\n return new Token(Type.undefined, undefined, 1);\n}\nexport function decodeBreak(_data, _pos, _minor, options) {\n if (options.allowIndefinite === false) {\n throw new Error(`${ decodeErrPrefix } indefinite length items not allowed`);\n }\n return new Token(Type.break, undefined, 1);\n}\nfunction createToken(value, bytes, options) {\n if (options) {\n if (options.allowNaN === false && Number.isNaN(value)) {\n throw new Error(`${ decodeErrPrefix } NaN values are not supported`);\n }\n if (options.allowInfinity === false && (value === Infinity || value === -Infinity)) {\n throw new Error(`${ decodeErrPrefix } Infinity values are not supported`);\n }\n }\n return new Token(Type.float, value, bytes);\n}\nexport function decodeFloat16(data, pos, _minor, options) {\n return createToken(readFloat16(data, pos + 1), 3, options);\n}\nexport function decodeFloat32(data, pos, _minor, options) {\n return createToken(readFloat32(data, pos + 1), 5, options);\n}\nexport function decodeFloat64(data, pos, _minor, options) {\n return createToken(readFloat64(data, pos + 1), 9, options);\n}\nexport function encodeFloat(buf, token, options) {\n const float = token.value;\n if (float === false) {\n buf.push([Type.float.majorEncoded | MINOR_FALSE]);\n } else if (float === true) {\n buf.push([Type.float.majorEncoded | MINOR_TRUE]);\n } else if (float === null) {\n buf.push([Type.float.majorEncoded | MINOR_NULL]);\n } else if (float === undefined) {\n buf.push([Type.float.majorEncoded | MINOR_UNDEFINED]);\n } else {\n let decoded;\n let success = false;\n if (!options || options.float64 !== true) {\n encodeFloat16(float);\n decoded = readFloat16(ui8a, 1);\n if (float === decoded || Number.isNaN(float)) {\n ui8a[0] = 249;\n buf.push(ui8a.slice(0, 3));\n success = true;\n } else {\n encodeFloat32(float);\n decoded = readFloat32(ui8a, 1);\n if (float === decoded) {\n ui8a[0] = 250;\n buf.push(ui8a.slice(0, 5));\n success = true;\n }\n }\n }\n if (!success) {\n encodeFloat64(float);\n decoded = readFloat64(ui8a, 1);\n ui8a[0] = 251;\n buf.push(ui8a.slice(0, 9));\n }\n }\n}\nencodeFloat.encodedSize = function encodedSize(token, options) {\n const float = token.value;\n if (float === false || float === true || float === null || float === undefined) {\n return 1;\n }\n if (!options || options.float64 !== true) {\n encodeFloat16(float);\n let decoded = readFloat16(ui8a, 1);\n if (float === decoded || Number.isNaN(float)) {\n return 3;\n }\n encodeFloat32(float);\n decoded = readFloat32(ui8a, 1);\n if (float === decoded) {\n return 5;\n }\n }\n return 9;\n};\nconst buffer = new ArrayBuffer(9);\nconst dataView = new DataView(buffer, 1);\nconst ui8a = new Uint8Array(buffer, 0);\nfunction encodeFloat16(inp) {\n if (inp === Infinity) {\n dataView.setUint16(0, 31744, false);\n } else if (inp === -Infinity) {\n dataView.setUint16(0, 64512, false);\n } else if (Number.isNaN(inp)) {\n dataView.setUint16(0, 32256, false);\n } else {\n dataView.setFloat32(0, inp);\n const valu32 = dataView.getUint32(0);\n const exponent = (valu32 & 2139095040) >> 23;\n const mantissa = valu32 & 8388607;\n if (exponent === 255) {\n dataView.setUint16(0, 31744, false);\n } else if (exponent === 0) {\n dataView.setUint16(0, (inp & 2147483648) >> 16 | mantissa >> 13, false);\n } else {\n const logicalExponent = exponent - 127;\n if (logicalExponent < -24) {\n dataView.setUint16(0, 0);\n } else if (logicalExponent < -14) {\n dataView.setUint16(0, (valu32 & 2147483648) >> 16 | 1 << 24 + logicalExponent, false);\n } else {\n dataView.setUint16(0, (valu32 & 2147483648) >> 16 | logicalExponent + 15 << 10 | mantissa >> 13, false);\n }\n }\n }\n}\nfunction readFloat16(ui8a, pos) {\n if (ui8a.length - pos < 2) {\n throw new Error(`${ decodeErrPrefix } not enough data for float16`);\n }\n const half = (ui8a[pos] << 8) + ui8a[pos + 1];\n if (half === 31744) {\n return Infinity;\n }\n if (half === 64512) {\n return -Infinity;\n }\n if (half === 32256) {\n return NaN;\n }\n const exp = half >> 10 & 31;\n const mant = half & 1023;\n let val;\n if (exp === 0) {\n val = mant * 2 ** -24;\n } else if (exp !== 31) {\n val = (mant + 1024) * 2 ** (exp - 25);\n } else {\n val = mant === 0 ? Infinity : NaN;\n }\n return half & 32768 ? -val : val;\n}\nfunction encodeFloat32(inp) {\n dataView.setFloat32(0, inp, false);\n}\nfunction readFloat32(ui8a, pos) {\n if (ui8a.length - pos < 4) {\n throw new Error(`${ decodeErrPrefix } not enough data for float32`);\n }\n const offset = (ui8a.byteOffset || 0) + pos;\n return new DataView(ui8a.buffer, offset, 4).getFloat32(0, false);\n}\nfunction encodeFloat64(inp) {\n dataView.setFloat64(0, inp, false);\n}\nfunction readFloat64(ui8a, pos) {\n if (ui8a.length - pos < 8) {\n throw new Error(`${ decodeErrPrefix } not enough data for float64`);\n }\n const offset = (ui8a.byteOffset || 0) + pos;\n return new DataView(ui8a.buffer, offset, 8).getFloat64(0, false);\n}\nencodeFloat.compareTokens = encodeUint.compareTokens;", "import {\n Token,\n Type\n} from './token.js';\nimport * as uint from './0uint.js';\nimport * as negint from './1negint.js';\nimport * as bytes from './2bytes.js';\nimport * as string from './3string.js';\nimport * as array from './4array.js';\nimport * as map from './5map.js';\nimport * as tag from './6tag.js';\nimport * as float from './7float.js';\nimport { decodeErrPrefix } from './common.js';\nimport { fromArray } from './byte-utils.js';\nfunction invalidMinor(data, pos, minor) {\n throw new Error(`${ decodeErrPrefix } encountered invalid minor (${ minor }) for major ${ data[pos] >>> 5 }`);\n}\nfunction errorer(msg) {\n return () => {\n throw new Error(`${ decodeErrPrefix } ${ msg }`);\n };\n}\nexport const jump = [];\nfor (let i = 0; i <= 23; i++) {\n jump[i] = invalidMinor;\n}\njump[24] = uint.decodeUint8;\njump[25] = uint.decodeUint16;\njump[26] = uint.decodeUint32;\njump[27] = uint.decodeUint64;\njump[28] = invalidMinor;\njump[29] = invalidMinor;\njump[30] = invalidMinor;\njump[31] = invalidMinor;\nfor (let i = 32; i <= 55; i++) {\n jump[i] = invalidMinor;\n}\njump[56] = negint.decodeNegint8;\njump[57] = negint.decodeNegint16;\njump[58] = negint.decodeNegint32;\njump[59] = negint.decodeNegint64;\njump[60] = invalidMinor;\njump[61] = invalidMinor;\njump[62] = invalidMinor;\njump[63] = invalidMinor;\nfor (let i = 64; i <= 87; i++) {\n jump[i] = bytes.decodeBytesCompact;\n}\njump[88] = bytes.decodeBytes8;\njump[89] = bytes.decodeBytes16;\njump[90] = bytes.decodeBytes32;\njump[91] = bytes.decodeBytes64;\njump[92] = invalidMinor;\njump[93] = invalidMinor;\njump[94] = invalidMinor;\njump[95] = errorer('indefinite length bytes/strings are not supported');\nfor (let i = 96; i <= 119; i++) {\n jump[i] = string.decodeStringCompact;\n}\njump[120] = string.decodeString8;\njump[121] = string.decodeString16;\njump[122] = string.decodeString32;\njump[123] = string.decodeString64;\njump[124] = invalidMinor;\njump[125] = invalidMinor;\njump[126] = invalidMinor;\njump[127] = errorer('indefinite length bytes/strings are not supported');\nfor (let i = 128; i <= 151; i++) {\n jump[i] = array.decodeArrayCompact;\n}\njump[152] = array.decodeArray8;\njump[153] = array.decodeArray16;\njump[154] = array.decodeArray32;\njump[155] = array.decodeArray64;\njump[156] = invalidMinor;\njump[157] = invalidMinor;\njump[158] = invalidMinor;\njump[159] = array.decodeArrayIndefinite;\nfor (let i = 160; i <= 183; i++) {\n jump[i] = map.decodeMapCompact;\n}\njump[184] = map.decodeMap8;\njump[185] = map.decodeMap16;\njump[186] = map.decodeMap32;\njump[187] = map.decodeMap64;\njump[188] = invalidMinor;\njump[189] = invalidMinor;\njump[190] = invalidMinor;\njump[191] = map.decodeMapIndefinite;\nfor (let i = 192; i <= 215; i++) {\n jump[i] = tag.decodeTagCompact;\n}\njump[216] = tag.decodeTag8;\njump[217] = tag.decodeTag16;\njump[218] = tag.decodeTag32;\njump[219] = tag.decodeTag64;\njump[220] = invalidMinor;\njump[221] = invalidMinor;\njump[222] = invalidMinor;\njump[223] = invalidMinor;\nfor (let i = 224; i <= 243; i++) {\n jump[i] = errorer('simple values are not supported');\n}\njump[244] = invalidMinor;\njump[245] = invalidMinor;\njump[246] = invalidMinor;\njump[247] = float.decodeUndefined;\njump[248] = errorer('simple values are not supported');\njump[249] = float.decodeFloat16;\njump[250] = float.decodeFloat32;\njump[251] = float.decodeFloat64;\njump[252] = invalidMinor;\njump[253] = invalidMinor;\njump[254] = invalidMinor;\njump[255] = float.decodeBreak;\nexport const quick = [];\nfor (let i = 0; i < 24; i++) {\n quick[i] = new Token(Type.uint, i, 1);\n}\nfor (let i = -1; i >= -24; i--) {\n quick[31 - i] = new Token(Type.negint, i, 1);\n}\nquick[64] = new Token(Type.bytes, new Uint8Array(0), 1);\nquick[96] = new Token(Type.string, '', 1);\nquick[128] = new Token(Type.array, 0, 1);\nquick[160] = new Token(Type.map, 0, 1);\nquick[244] = new Token(Type.false, false, 1);\nquick[245] = new Token(Type.true, true, 1);\nquick[246] = new Token(Type.null, null, 1);\nexport function quickEncodeToken(token) {\n switch (token.type) {\n case Type.false:\n return fromArray([244]);\n case Type.true:\n return fromArray([245]);\n case Type.null:\n return fromArray([246]);\n case Type.bytes:\n if (!token.value.length) {\n return fromArray([64]);\n }\n return;\n case Type.string:\n if (token.value === '') {\n return fromArray([96]);\n }\n return;\n case Type.array:\n if (token.value === 0) {\n return fromArray([128]);\n }\n return;\n case Type.map:\n if (token.value === 0) {\n return fromArray([160]);\n }\n return;\n case Type.uint:\n if (token.value < 24) {\n return fromArray([Number(token.value)]);\n }\n return;\n case Type.negint:\n if (token.value >= -24) {\n return fromArray([31