{
  "version": 3,
  "sources": ["index.js", "atcute/packages/utilities/uint8array/lib/index.ts", "atcute/packages/utilities/multibase/lib/utils.ts", "atcute/packages/utilities/multibase/lib/bases/base64-web.ts", "atcute/packages/utilities/multibase/lib/bases/base32.ts", "atcute/packages/utilities/varint/lib/index.ts", "atcute/packages/utilities/cid/lib/codec.ts", "atcute/packages/utilities/cid/lib/cid-link.ts", "atcute/packages/utilities/cbor/lib/bytes.ts", "atcute/packages/utilities/cbor/lib/decode.ts", "atcute/packages/utilities/car/lib/utilities/sync-byte-reader.ts", "atcute/packages/utilities/car/lib/utilities/car.ts", "atcute/packages/utilities/car/lib/utilities/sync-car-reader.ts", "atcute/packages/utilities/car/lib/reader.ts", "atcute/packages/utilities/car/lib/atproto-repo.ts", "read-car.js", "package.json", "firehose.js"],
  "sourcesContent": ["export * from './read-car';\nexport * from './firehose';\n", "const textEncoder = new TextEncoder();\nconst textDecoder = new TextDecoder();\n\nconst subtle = crypto.subtle;\n\n/**\n * creates an Uint8Array of the requested size, with the contents zeroed\n */\nexport const alloc = (size: number): Uint8Array => {\n\treturn new Uint8Array(size);\n};\n\n/**\n * creates an Uint8Array of the requested size, where the contents may not be\n * zeroed out. only use if you're certain that the contents will be overwritten\n */\nexport const allocUnsafe = alloc;\n\n/**\n * compares two Uint8Array buffers\n */\nexport const compare = (a: Uint8Array, b: Uint8Array): number => {\n\tconst alen = a.length;\n\tconst blen = b.length;\n\n\tif (alen > blen) {\n\t\treturn 1;\n\t}\n\tif (alen < blen) {\n\t\treturn -1;\n\t}\n\n\tfor (let i = 0; i < alen; i++) {\n\t\tconst ax = a[i];\n\t\tconst bx = b[i];\n\n\t\tif (ax < bx) {\n\t\t\treturn -1;\n\t\t}\n\n\t\tif (ax > bx) {\n\t\t\treturn 1;\n\t\t}\n\t}\n\n\treturn 0;\n};\n\n/**\n * checks if the two Uint8Array buffers are equal\n */\nexport const equals = (a: Uint8Array, b: Uint8Array): boolean => {\n\tif (a === b) {\n\t\treturn true;\n\t}\n\n\tlet len: number;\n\tif ((len = a.length) === b.length) {\n\t\twhile (len--) {\n\t\t\tif (a[len] !== b[len]) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn len === -1;\n};\n\n/**\n * checks if the two Uint8Array buffers are equal, timing-safe version\n */\nexport const timingSafeEquals = (a: Uint8Array, b: Uint8Array): boolean => {\n\tlet len: number;\n\tlet out = 0;\n\tif ((len = a.length) === b.length) {\n\t\twhile (len--) {\n\t\t\tout |= a[len] ^ b[len];\n\t\t}\n\t}\n\n\treturn len === -1 && out === 0;\n};\n\n/**\n * concatenates multiple Uint8Array buffers into one\n */\nexport const concat = (arrays: Uint8Array[], size?: number): Uint8Array => {\n\tlet written = 0;\n\n\tlet len = arrays.length;\n\tlet idx: number;\n\n\tif (size === undefined) {\n\t\tfor (idx = size = 0; idx < len; idx++) {\n\t\t\tconst chunk = arrays[idx];\n\t\t\tsize += chunk.length;\n\t\t}\n\t}\n\n\tconst buffer = new Uint8Array(size);\n\n\tfor (idx = 0; idx < len; idx++) {\n\t\tconst chunk = arrays[idx];\n\n\t\tbuffer.set(chunk, written);\n\t\twritten += chunk.length;\n\t}\n\n\treturn buffer;\n};\n\n/**\n * encodes a UTF-8 string into the buffer\n */\nexport const encodeUtf8Into = (to: Uint8Array, str: string, offset?: number, length?: number): number => {\n\tlet buffer: Uint8Array;\n\n\tif (offset === undefined) {\n\t\tbuffer = to;\n\t} else if (length === undefined) {\n\t\tbuffer = to.subarray(offset);\n\t} else {\n\t\tbuffer = to.subarray(offset, offset + length);\n\t}\n\n\tconst result = textEncoder.encodeInto(str, buffer);\n\n\treturn result.written;\n};\n\n/**\n * decodes a UTF-8 string from a buffer\n */\nexport const decodeUtf8From = (from: Uint8Array, offset?: number, length?: number): string => {\n\tlet buffer: Uint8Array;\n\n\tif (offset === undefined) {\n\t\tbuffer = from;\n\t} else if (length === undefined) {\n\t\tbuffer = from.subarray(offset);\n\t} else {\n\t\tbuffer = from.subarray(offset, offset + length);\n\t}\n\n\tconst result = textDecoder.decode(buffer);\n\n\treturn result;\n};\n\n/**\n * get a SHA-256 digest of this buffer\n */\nexport const toSha256 = async (buffer: Uint8Array): Promise<Uint8Array> => {\n\treturn new Uint8Array(await subtle.digest('SHA-256', buffer));\n};\n", "import { alloc, allocUnsafe } from '@atcute/uint8array';\n\nexport const createRfc4648Encode = (alphabet: string, bitsPerChar: number, pad: boolean) => {\n\treturn (bytes: Uint8Array): string => {\n\t\tconst mask = (1 << bitsPerChar) - 1;\n\t\tlet str = '';\n\n\t\tlet bits = 0; // Number of bits currently in the buffer\n\t\tlet buffer = 0; // Bits waiting to be written out, MSB first\n\t\tfor (let i = 0; i < bytes.length; ++i) {\n\t\t\t// Slurp data into the buffer:\n\t\t\tbuffer = (buffer << 8) | bytes[i];\n\t\t\tbits += 8;\n\n\t\t\t// Write out as much as we can:\n\t\t\twhile (bits > bitsPerChar) {\n\t\t\t\tbits -= bitsPerChar;\n\t\t\t\tstr += alphabet[mask & (buffer >> bits)];\n\t\t\t}\n\t\t}\n\n\t\t// Partial character:\n\t\tif (bits !== 0) {\n\t\t\tstr += alphabet[mask & (buffer << (bitsPerChar - bits))];\n\t\t}\n\n\t\t// Add padding characters until we hit a byte boundary:\n\t\tif (pad) {\n\t\t\twhile (((str.length * bitsPerChar) & 7) !== 0) {\n\t\t\t\tstr += '=';\n\t\t\t}\n\t\t}\n\n\t\treturn str;\n\t};\n};\n\nexport const createRfc4648Decode = (alphabet: string, bitsPerChar: number, pad: boolean) => {\n\t// Build the character lookup table:\n\tconst codes: Record<string, number> = {};\n\tfor (let i = 0; i < alphabet.length; ++i) {\n\t\tcodes[alphabet[i]] = i;\n\t}\n\n\treturn (str: string) => {\n\t\t// Count the padding bytes:\n\t\tlet end = str.length;\n\t\twhile (pad && str[end - 1] === '=') {\n\t\t\t--end;\n\t\t}\n\n\t\t// Allocate the output:\n\t\tconst bytes = allocUnsafe(((end * bitsPerChar) / 8) | 0);\n\n\t\t// Parse the data:\n\t\tlet bits = 0; // Number of bits currently in the buffer\n\t\tlet buffer = 0; // Bits waiting to be written out, MSB first\n\t\tlet written = 0; // Next byte to write\n\t\tfor (let i = 0; i < end; ++i) {\n\t\t\t// Read one character from the string:\n\t\t\tconst value = codes[str[i]];\n\t\t\tif (value === undefined) {\n\t\t\t\tthrow new SyntaxError(`invalid base string`);\n\t\t\t}\n\n\t\t\t// Append the bits to the buffer:\n\t\t\tbuffer = (buffer << bitsPerChar) | value;\n\t\t\tbits += bitsPerChar;\n\n\t\t\t// Write out some bits if the buffer has a byte's worth:\n\t\t\tif (bits >= 8) {\n\t\t\t\tbits -= 8;\n\t\t\t\tbytes[written++] = 0xff & (buffer >> bits);\n\t\t\t}\n\t\t}\n\n\t\t// Verify that we have received just enough bits:\n\t\tif (bits >= bitsPerChar || (0xff & (buffer << (8 - bits))) !== 0) {\n\t\t\tthrow new SyntaxError('unexpected end of data');\n\t\t}\n\n\t\treturn bytes;\n\t};\n};\n\nexport const createBtcBaseEncode = (alphabet: string) => {\n\tif (alphabet.length >= 255) {\n\t\tthrow new RangeError(`alphabet too long`);\n\t}\n\n\tconst BASE = alphabet.length;\n\tconst LEADER = alphabet.charAt(0);\n\tconst iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up\n\n\treturn (source: Uint8Array): string => {\n\t\tif (source.length === 0) {\n\t\t\treturn '';\n\t\t}\n\n\t\t// Skip & count leading zeroes.\n\t\tlet zeroes = 0;\n\t\tlet length = 0;\n\t\tlet pbegin = 0;\n\t\tconst pend = source.length;\n\t\twhile (pbegin !== pend && source[pbegin] === 0) {\n\t\t\tpbegin++;\n\t\t\tzeroes++;\n\t\t}\n\n\t\t// Allocate enough space in big-endian base58 representation.\n\t\tconst size = ((pend - pbegin) * iFACTOR + 1) >>> 0;\n\t\tconst b58 = alloc(size);\n\n\t\t// Process the bytes.\n\t\twhile (pbegin !== pend) {\n\t\t\tlet carry = source[pbegin];\n\n\t\t\t// Apply \"b58 = b58 * 256 + ch\".\n\t\t\tlet i = 0;\n\t\t\tfor (let it1 = size - 1; (carry !== 0 || i < length) && it1 !== -1; it1--, i++) {\n\t\t\t\tcarry += (256 * b58[it1]) >>> 0;\n\t\t\t\tb58[it1] = carry % BASE >>> 0;\n\t\t\t\tcarry = (carry / BASE) >>> 0;\n\t\t\t}\n\n\t\t\tif (carry !== 0) {\n\t\t\t\tthrow new Error('non-zero carry');\n\t\t\t}\n\n\t\t\tlength = i;\n\t\t\tpbegin++;\n\t\t}\n\n\t\t// Skip leading zeroes in base58 result.\n\t\tlet it2 = size - length;\n\t\twhile (it2 !== size && b58[it2] === 0) {\n\t\t\tit2++;\n\t\t}\n\n\t\t// Translate the result into a string.\n\t\tlet str = LEADER.repeat(zeroes);\n\t\tfor (; it2 < size; ++it2) {\n\t\t\tstr += alphabet.charAt(b58[it2]);\n\t\t}\n\n\t\treturn str;\n\t};\n};\n\nexport const createBtcBaseDecode = (alphabet: string) => {\n\tif (alphabet.length >= 255) {\n\t\tthrow new RangeError(`alphabet too long`);\n\t}\n\n\tconst BASE_MAP = allocUnsafe(256).fill(255);\n\tfor (let i = 0; i < alphabet.length; i++) {\n\t\tconst xc = alphabet.charCodeAt(i);\n\n\t\tif (BASE_MAP[xc] !== 255) {\n\t\t\tthrow new RangeError(`${alphabet[i]} is ambiguous`);\n\t\t}\n\n\t\tBASE_MAP[xc] = i;\n\t}\n\n\tconst BASE = alphabet.length;\n\tconst LEADER = alphabet.charAt(0);\n\tconst FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up\n\n\treturn (source: string): Uint8Array => {\n\t\tif (source.length === 0) {\n\t\t\treturn allocUnsafe(0);\n\t\t}\n\n\t\t// Skip and count leading '1's.\n\t\tlet psz = 0;\n\t\tlet zeroes = 0;\n\t\tlet length = 0;\n\n\t\twhile (source[psz] === LEADER) {\n\t\t\tzeroes++;\n\t\t\tpsz++;\n\t\t}\n\n\t\t// Allocate enough space in big-endian base256 representation.\n\t\tconst size = ((source.length - psz) * FACTOR + 1) >>> 0; // log(58) / log(256), rounded up.\n\t\tconst b256 = alloc(size);\n\n\t\t// Process the characters.\n\t\twhile (psz < source.length) {\n\t\t\t// Decode character\n\t\t\tlet carry = BASE_MAP[source.charCodeAt(psz)];\n\n\t\t\t// Invalid character\n\t\t\tif (carry === 255) {\n\t\t\t\tthrow new Error(`invalid string`);\n\t\t\t}\n\n\t\t\tlet i = 0;\n\t\t\tfor (let it3 = size - 1; (carry !== 0 || i < length) && it3 !== -1; it3--, i++) {\n\t\t\t\tcarry += (BASE * b256[it3]) >>> 0;\n\t\t\t\tb256[it3] = carry % 256 >>> 0;\n\t\t\t\tcarry = (carry / 256) >>> 0;\n\t\t\t}\n\t\t\tif (carry !== 0) {\n\t\t\t\tthrow new Error('non-zero carry');\n\t\t\t}\n\t\t\tlength = i;\n\t\t\tpsz++;\n\t\t}\n\n\t\t// Skip leading zeroes in b256.\n\t\tlet it4 = size - length;\n\t\twhile (it4 !== size && b256[it4] === 0) {\n\t\t\tit4++;\n\t\t}\n\n\t\tif (it4 === zeroes) {\n\t\t\treturn b256;\n\t\t}\n\n\t\tconst vch = allocUnsafe(zeroes + (size - it4));\n\t\tvch.fill(0, 0, zeroes);\n\t\tvch.set(b256.subarray(it4), zeroes);\n\n\t\treturn vch;\n\t};\n};\n", "import { createRfc4648Decode, createRfc4648Encode } from '../utils.js';\n\nconst HAS_UINT8_BASE64_SUPPORT = 'fromBase64' in Uint8Array;\n\nconst BASE64_CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\nconst BASE64URL_CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';\n\n// seems to be faster if we just check for the specific characters that are forbidden yet\n// allowed by fromBase64.\nconst WS_RE = /[\\s]/;\nconst WS_PAD_RE = /[\\s=]/;\n\n// #region base64\n/** @internal */\nexport const _fromBase64Polyfill = /*#__PURE__*/ createRfc4648Decode(BASE64_CHARSET, 6, false);\n/** @internal */\nexport const _toBase64Polyfill = /*#__PURE__*/ createRfc4648Encode(BASE64_CHARSET, 6, false);\n\n/** @internal */\nexport const _fromBase64Native = (str: string): Uint8Array => {\n\tif (str.length % 4 === 1 || WS_PAD_RE.test(str)) {\n\t\tthrow new SyntaxError(`invalid base64 string`);\n\t}\n\n\treturn Uint8Array.fromBase64(str, { alphabet: 'base64', lastChunkHandling: 'loose' });\n};\n\n/** @internal */\nexport const _toBase64Native = (bytes: Uint8Array): string => {\n\treturn bytes.toBase64({ alphabet: 'base64', omitPadding: true });\n};\n\nexport const fromBase64 = !HAS_UINT8_BASE64_SUPPORT ? _fromBase64Polyfill : _fromBase64Native;\n\nexport const toBase64 = !HAS_UINT8_BASE64_SUPPORT ? _toBase64Polyfill : _toBase64Native;\n// #endregion\n\n// #region base64pad\n/** @internal */\nexport const _fromBase64PadPolyfill = /*#__PURE__*/ createRfc4648Decode(BASE64_CHARSET, 6, true);\n/** @internal */\nexport const _toBase64PadPolyfill = /*#__PURE__*/ createRfc4648Encode(BASE64_CHARSET, 6, true);\n\n/** @internal */\nexport const _fromBase64PadNative = (str: string): Uint8Array => {\n\tif (str.length % 4 !== 0 || WS_RE.test(str)) {\n\t\tthrow new SyntaxError(`invalid base64 string`);\n\t}\n\n\treturn Uint8Array.fromBase64(str, { alphabet: 'base64', lastChunkHandling: 'strict' });\n};\n\n/** @internal */\nexport const _toBase64PadNative = (bytes: Uint8Array): string => {\n\treturn bytes.toBase64({ alphabet: 'base64', omitPadding: false });\n};\n\nexport const fromBase64Pad = !HAS_UINT8_BASE64_SUPPORT ? _fromBase64PadPolyfill : _fromBase64PadNative;\n\nexport const toBase64Pad = !HAS_UINT8_BASE64_SUPPORT ? _toBase64PadPolyfill : _toBase64PadNative;\n// #endregion\n\n// #region base64url\n/** @internal */\nexport const _fromBase64UrlPolyfill = /*#__PURE__*/ createRfc4648Decode(BASE64URL_CHARSET, 6, false);\n/** @internal */\nexport const _toBase64UrlPolyfill = /*#__PURE__*/ createRfc4648Encode(BASE64URL_CHARSET, 6, false);\n\n/** @internal */\nexport const _fromBase64UrlNative = (str: string): Uint8Array => {\n\tif (str.length % 4 === 1 || WS_PAD_RE.test(str)) {\n\t\tthrow new SyntaxError(`invalid base64 string`);\n\t}\n\n\treturn Uint8Array.fromBase64(str, { alphabet: 'base64url', lastChunkHandling: 'loose' });\n};\n\n/** @internal */\nexport const _toBase64UrlNative = (bytes: Uint8Array): string => {\n\treturn bytes.toBase64({ alphabet: 'base64url', omitPadding: true });\n};\n\nexport const fromBase64Url = !HAS_UINT8_BASE64_SUPPORT ? _fromBase64UrlPolyfill : _fromBase64UrlNative;\n\nexport const toBase64Url = !HAS_UINT8_BASE64_SUPPORT ? _toBase64UrlPolyfill : _toBase64UrlNative;\n// #endregion\n\n// #region base64urlpad\n/** @internal */\nexport const _fromBase64UrlPadPolyfill = /*#__PURE__*/ createRfc4648Decode(BASE64URL_CHARSET, 6, true);\n/** @internal */\nexport const _toBase64UrlPadPolyfill = /*#__PURE__*/ createRfc4648Encode(BASE64URL_CHARSET, 6, true);\n\n/** @internal */\nexport const _fromBase64UrlPadNative = (str: string): Uint8Array => {\n\tif (str.length % 4 !== 0 || WS_RE.test(str)) {\n\t\tthrow new SyntaxError(`invalid base64 string`);\n\t}\n\n\treturn Uint8Array.fromBase64(str, { alphabet: 'base64url', lastChunkHandling: 'strict' });\n};\n\n/** @internal */\nexport const _toBase64UrlPadNative = (bytes: Uint8Array): string => {\n\treturn bytes.toBase64({ alphabet: 'base64url', omitPadding: false });\n};\n\nexport const fromBase64UrlPad = !HAS_UINT8_BASE64_SUPPORT\n\t? _fromBase64UrlPadPolyfill\n\t: _fromBase64UrlPadNative;\n\nexport const toBase64UrlPad = !HAS_UINT8_BASE64_SUPPORT ? _toBase64UrlPadPolyfill : _toBase64UrlPadNative;\n// #endregion\n", "import { createRfc4648Decode, createRfc4648Encode } from '../utils.js';\n\nconst BASE32_CHARSET = 'abcdefghijklmnopqrstuvwxyz234567';\n\nexport const fromBase32 = /*#__PURE__*/ createRfc4648Decode(BASE32_CHARSET, 5, false);\n\nexport const toBase32 = /*#__PURE__*/ createRfc4648Encode(BASE32_CHARSET, 5, false);\n", "const MSB = 0x80;\nconst REST = 0x7f;\nconst MSBALL = ~REST;\nconst INT = 2 ** 31;\n\nconst N1 = 2 ** 7;\nconst N2 = 2 ** 14;\nconst N3 = 2 ** 21;\nconst N4 = 2 ** 28;\nconst N5 = 2 ** 35;\nconst N6 = 2 ** 42;\nconst N7 = 2 ** 49;\nconst N8 = 2 ** 56;\nconst N9 = 2 ** 63;\n\n/**\n * Encodes a varint\n * @param num Number to encode\n * @param buf Buffer to write on\n * @param offset Starting position on the buffer\n * @returns The amount of bytes written\n */\nexport const encode = (num: number, buf: Uint8Array | number[], offset = 0): number => {\n\tif (num > Number.MAX_SAFE_INTEGER) {\n\t\tthrow new RangeError('could not encode varint');\n\t}\n\n\tconst start = offset;\n\n\twhile (num >= INT) {\n\t\tbuf[offset++] = (num & 0xff) | MSB;\n\t\tnum /= 128;\n\t}\n\n\twhile (num & MSBALL) {\n\t\tbuf[offset++] = (num & 0xff) | MSB;\n\t\tnum >>>= 7;\n\t}\n\n\tbuf[offset] = num | 0;\n\treturn offset - start + 1;\n};\n\n/**\n * Decodes a varint\n * @param buf Buffer to read from\n * @param offset Starting position on the buffer\n * @returns A tuple containing the resulting number, and the amount of bytes read\n */\nexport const decode = (buf: Uint8Array | number[], offset = 0): [num: number, read: number] => {\n\t// deno-lint-ignore prefer-const\n\tlet l = buf.length;\n\n\tlet res = 0;\n\tlet shift = 0;\n\tlet counter = offset;\n\tlet b: number;\n\n\tdo {\n\t\tif (counter >= l) {\n\t\t\tthrow new RangeError('could not decode varint');\n\t\t}\n\n\t\tb = buf[counter++];\n\t\tres += shift < 28 ? (b & REST) << shift : (b & REST) * Math.pow(2, shift);\n\t\tshift += 7;\n\t} while (b >= MSB);\n\n\treturn [res, counter - offset];\n};\n\n/**\n * Returns encoding length\n * @param num The number to encode\n * @returns Amount of bytes needed for encoding\n */\nexport const encodingLength = (num: number): number => {\n\treturn num < N1\n\t\t? 1\n\t\t: num < N2\n\t\t\t? 2\n\t\t\t: num < N3\n\t\t\t\t? 3\n\t\t\t\t: num < N4\n\t\t\t\t\t? 4\n\t\t\t\t\t: num < N5\n\t\t\t\t\t\t? 5\n\t\t\t\t\t\t: num < N6\n\t\t\t\t\t\t\t? 6\n\t\t\t\t\t\t\t: num < N7\n\t\t\t\t\t\t\t\t? 7\n\t\t\t\t\t\t\t\t: num < N8\n\t\t\t\t\t\t\t\t\t? 8\n\t\t\t\t\t\t\t\t\t: num < N9\n\t\t\t\t\t\t\t\t\t\t? 9\n\t\t\t\t\t\t\t\t\t\t: 10;\n};\n", "import { fromBase32, toBase32 } from '@atcute/multibase';\nimport { allocUnsafe, toSha256 } from '@atcute/uint8array';\nimport * as varint from '@atcute/varint';\n\nexport const CID_VERSION = 1;\nexport const HASH_SHA256 = 0x12;\n\nexport const CODEC_RAW = 0x55;\nexport const CODEC_DCBOR = 0x71;\n\n/**\n * Represents a Content Identifier (CID), in particular, a limited subset of\n * CIDv1 as described by DASL specifications.\n * https://dasl.ing/cid.html\n */\nexport interface Cid {\n\t/** CID version, this is always `1` for CIDv1 */\n\tversion: number;\n\t/** Multicodec type for the data, can be `0x55` for raw data or `0x71` for DAG-CBOR */\n\tcodec: number;\n\t/** Digest contents */\n\tdigest: {\n\t\t/** Multicodec type for the digest, this is always `0x12` for SHA-256 */\n\t\tcodec: number;\n\t\t/** Raw hash bytes */\n\t\tcontents: Uint8Array;\n\t};\n\t/** Raw CID bytes */\n\tbytes: Uint8Array;\n}\n\nexport const create = async (codec: 0x55 | 0x71, data: Uint8Array): Promise<Cid> => {\n\tconst digest = await toSha256(data);\n\n\tconst digestSize = digest.length;\n\tconst digestLebSize = varint.encodingLength(digestSize);\n\n\tconst bytes = allocUnsafe(3 + digestLebSize + digestSize);\n\n\tbytes[0] = CID_VERSION;\n\tbytes[1] = codec;\n\tbytes[2] = HASH_SHA256;\n\n\tvarint.encode(digestSize, bytes, 3);\n\tbytes.set(digest, 3 + digestLebSize);\n\n\tconst cid: Cid = {\n\t\tversion: CID_VERSION,\n\t\tcodec: codec,\n\t\tdigest: {\n\t\t\tcodec: HASH_SHA256,\n\t\t\tcontents: digest,\n\t\t},\n\t\tbytes: bytes,\n\t};\n\n\treturn cid;\n};\n\nexport const decodeFirst = (bytes: Uint8Array): [decoded: Cid, remainder: Uint8Array] => {\n\tconst length = bytes.length;\n\n\tif (length < 5) {\n\t\tthrow new RangeError(`cid too short`);\n\t}\n\n\tconst version = bytes[0];\n\tconst codec = bytes[1];\n\tconst digestCodec = bytes[2];\n\n\tif (version !== CID_VERSION) {\n\t\tthrow new RangeError(`incorrect cid version (got v${version})`);\n\t}\n\n\tif (codec !== CODEC_DCBOR && codec !== CODEC_RAW) {\n\t\tthrow new RangeError(`incorrect cid codec (got 0x${codec.toString(16)})`);\n\t}\n\n\tif (digestCodec !== HASH_SHA256) {\n\t\tthrow new RangeError(`incorrect cid hash type (got 0x${digestCodec.toString(16)})`);\n\t}\n\n\tconst [digestSize, digestLebSize] = varint.decode(bytes, 3);\n\tconst digestOffset = 3 + digestLebSize;\n\n\tif (length - digestOffset < digestSize) {\n\t\tthrow new RangeError(`digest too short (expected ${digestSize} bytes; got ${length - digestOffset})`);\n\t}\n\n\tconst remainder = bytes.subarray(digestOffset + digestSize);\n\n\tconst cid: Cid = {\n\t\tversion: CID_VERSION,\n\t\tcodec: codec,\n\t\tdigest: {\n\t\t\tcodec: digestCodec,\n\t\t\tcontents: bytes.subarray(digestOffset, digestOffset + digestSize),\n\t\t},\n\t\tbytes: bytes.subarray(0, digestOffset + digestSize),\n\t};\n\n\treturn [cid, remainder];\n};\n\nexport const decode = (bytes: Uint8Array): Cid => {\n\tconst [cid, remainder] = decodeFirst(bytes);\n\n\tif (remainder.length !== 0) {\n\t\tthrow new RangeError(`cid bytes includes remainder`);\n\t}\n\n\treturn cid;\n};\n\nexport const fromString = (input: string): Cid => {\n\tif (input.length < 2 || input[0] !== 'b') {\n\t\tthrow new SyntaxError(`not a multibase base32 string`);\n\t}\n\n\tconst bytes = fromBase32(input.slice(1));\n\treturn decode(bytes);\n};\n\nexport const toString = (cid: Cid): string => {\n\tconst encoded = toBase32(cid.bytes);\n\treturn `b${encoded}`;\n};\n\nexport const fromBinary = (input: Uint8Array): Cid => {\n\tif (input.length < 2) {\n\t\tthrow new RangeError(`cid bytes too short`);\n\t}\n\n\tif (input[0] !== 0) {\n\t\tthrow new SyntaxError(`incorrect binary cid`);\n\t}\n\n\tconst bytes = input.subarray(1);\n\treturn decode(bytes);\n};\n\nexport const toBinary = (cid: Cid): Uint8Array => {\n\tconst bytes = allocUnsafe(1 + cid.bytes.length);\n\tbytes[0] = 0;\n\tbytes.set(cid.bytes, 1);\n\n\treturn bytes;\n};\n", "import { toBase32 } from '@atcute/multibase';\n\nimport { decode, fromString, type Cid } from './codec.js';\n\nexport interface CidLink {\n\t$link: string;\n}\n\nexport class CidLinkWrapper implements CidLink {\n\tconstructor(public bytes: Uint8Array) {}\n\n\tget $link(): string {\n\t\tconst encoded = toBase32(this.bytes);\n\t\treturn `b${encoded}`;\n\t}\n\n\ttoJSON(): CidLink {\n\t\treturn { $link: this.$link };\n\t}\n}\n\nexport const isCidLink = (value: unknown): value is CidLink => {\n\tconst val = value as any;\n\n\treturn (\n\t\tval instanceof CidLinkWrapper ||\n\t\t(val !== null && typeof val === 'object' && typeof val.$link === 'string')\n\t);\n};\n\nexport const toCidLink = (cid: Cid): CidLink => {\n\treturn new CidLinkWrapper(cid.bytes);\n};\n\nexport const fromCidLink = (link: CidLink): Cid => {\n\tif (link instanceof CidLinkWrapper) {\n\t\treturn decode(link.bytes);\n\t}\n\n\treturn fromString(link.$link);\n};\n", "import { fromBase64, toBase64 } from '@atcute/multibase';\n\nexport interface Bytes {\n\t$bytes: string;\n}\n\nexport class BytesWrapper implements Bytes {\n\tconstructor(public buf: Uint8Array) {}\n\n\tget $bytes(): string {\n\t\treturn toBase64(this.buf);\n\t}\n\n\ttoJSON(): Bytes {\n\t\treturn { $bytes: this.$bytes };\n\t}\n}\n\nexport const toBytes = (buf: Uint8Array): Bytes => {\n\treturn new BytesWrapper(buf);\n};\n\nexport const fromBytes = (bytes: Bytes): Uint8Array => {\n\tif (bytes instanceof BytesWrapper) {\n\t\treturn bytes.buf;\n\t}\n\n\treturn fromBase64(bytes.$bytes);\n};\n", "import { CidLinkWrapper, type CidLink } from '@atcute/cid';\nimport { decodeUtf8From } from '@atcute/uint8array';\n\nimport { toBytes, type Bytes } from './bytes.js';\n\ninterface State {\n\tb: Uint8Array;\n\tv: DataView | null;\n\tp: number;\n}\n\nconst readArgument = (state: State, info: number): number => {\n\tif (info < 24) {\n\t\treturn info;\n\t}\n\n\tswitch (info) {\n\t\tcase 24: {\n\t\t\treturn readUint8(state);\n\t\t}\n\t\tcase 25: {\n\t\t\treturn readUint16(state);\n\t\t}\n\t\tcase 26: {\n\t\t\treturn readUint32(state);\n\t\t}\n\t\tcase 27: {\n\t\t\treturn readUint53(state);\n\t\t}\n\t}\n\n\tthrow new Error(`invalid argument encoding; got ${info}`);\n};\n\nconst readFloat64 = (state: State): number => {\n\tconst view = (state.v ??= new DataView(state.b.buffer, state.b.byteOffset, state.b.byteLength));\n\tconst value = view.getFloat64(state.p);\n\n\tstate.p += 8;\n\treturn value;\n};\n\nconst readUint8 = (state: State): number => {\n\treturn state.b[state.p++];\n};\n\nconst readUint16 = (state: State): number => {\n\tlet pos = state.p;\n\n\tconst buf = state.b;\n\tconst value = (buf[pos++] << 8) | buf[pos++];\n\n\tstate.p = pos;\n\treturn value;\n};\n\nconst readUint32 = (state: State): number => {\n\tlet pos = state.p;\n\n\tconst buf = state.b;\n\tconst value = ((buf[pos++] << 24) | (buf[pos++] << 16) | (buf[pos++] << 8) | buf[pos++]) >>> 0;\n\n\tstate.p = pos;\n\treturn value;\n};\n\nconst readUint53 = (state: State): number => {\n\tlet pos = state.p;\n\n\tconst buf = state.b;\n\n\tconst hi = ((buf[pos++] << 24) | (buf[pos++] << 16) | (buf[pos++] << 8) | buf[pos++]) >>> 0;\n\n\tif (hi > 0x1fffff) {\n\t\tthrow new RangeError(`can't decode integers beyond safe integer range`);\n\t}\n\n\tconst lo = ((buf[pos++] << 24) | (buf[pos++] << 16) | (buf[pos++] << 8) | buf[pos++]) >>> 0;\n\tconst value = hi * 2 ** 32 + lo;\n\n\tstate.p = pos;\n\treturn value;\n};\n\nconst readString = (state: State, length: number): string => {\n\tconst string = decodeUtf8From(state.b, state.p, length);\n\tstate.p += length;\n\n\treturn string;\n};\n\nconst readBytes = (state: State, length: number): Bytes => {\n\tconst slice = state.b.subarray(state.p, (state.p += length));\n\n\treturn toBytes(slice);\n};\n\nconst readTypeInfo = (state: State): [number, number] => {\n\tconst prelude = readUint8(state);\n\treturn [prelude >> 5, prelude & 0x1f];\n};\n\nconst readCid = (state: State, length: number): CidLink => {\n\t// CID bytes are prefixed with 0x00 for historical reasons, apparently.\n\tconst slice = state.b.subarray(state.p + 1, (state.p += length));\n\n\treturn new CidLinkWrapper(slice);\n};\n\nconst enum ContainerType {\n\tMAP,\n\tARRAY,\n}\n\ntype Container =\n\t| {\n\t\t\tt: ContainerType.MAP;\n\t\t\tc: Record<string, unknown>;\n\t\t\tk: string | null;\n\t\t\tr: number;\n\t\t\tn: Container | null;\n\t  }\n\t| {\n\t\t\tt: ContainerType.ARRAY;\n\t\t\tc: any[];\n\t\t\tk: null;\n\t\t\tr: number;\n\t\t\tn: Container | null;\n\t  };\n\nexport const decodeFirst = (buf: Uint8Array): [value: any, remainder: Uint8Array] => {\n\tconst len = buf.length;\n\n\tconst state: State = {\n\t\tb: buf,\n\t\tv: null,\n\t\tp: 0,\n\t};\n\n\tlet stack: Container | null = null;\n\tlet result: any;\n\n\tjump: while (state.p < len) {\n\t\tconst prelude = readUint8(state);\n\n\t\tconst type = prelude >> 5;\n\t\tconst info = prelude & 0x1f;\n\t\tconst arg = type < 7 ? readArgument(state, info) : 0;\n\n\t\tlet value: any;\n\n\t\tswitch (type) {\n\t\t\tcase 0: {\n\t\t\t\tvalue = arg;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 1: {\n\t\t\t\tvalue = -1 - arg;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 2: {\n\t\t\t\tvalue = readBytes(state, arg);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 3: {\n\t\t\t\tvalue = readString(state, arg);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 4: {\n\t\t\t\tconst arr = new Array(arg);\n\t\t\t\tvalue = arr;\n\n\t\t\t\tif (arg > 0) {\n\t\t\t\t\tstack = { t: ContainerType.ARRAY, c: arr, k: null, r: arg, n: stack };\n\t\t\t\t\tcontinue jump;\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 5: {\n\t\t\t\tconst obj: Record<string, unknown> = {};\n\t\t\t\tvalue = obj;\n\n\t\t\t\tif (arg > 0) {\n\t\t\t\t\t// `arg * 2` because we're reading both keys and values\n\t\t\t\t\tstack = { t: ContainerType.MAP, c: obj, k: null, r: arg * 2, n: stack };\n\t\t\t\t\tcontinue jump;\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 6: {\n\t\t\t\tswitch (arg) {\n\t\t\t\t\tcase 42: {\n\t\t\t\t\t\tconst [type, info] = readTypeInfo(state);\n\t\t\t\t\t\tif (type !== 2) {\n\t\t\t\t\t\t\tthrow new TypeError(`expected cid-link to be type 2 (bytes); got type ${type}`);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst len = readArgument(state, info);\n\t\t\t\t\t\tvalue = readCid(state, len);\n\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tthrow new TypeError(`unsupported tag; got ${arg}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 7: {\n\t\t\t\tswitch (info) {\n\t\t\t\t\tcase 20:\n\t\t\t\t\tcase 21: {\n\t\t\t\t\t\tvalue = info === 21;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase 22: {\n\t\t\t\t\t\tvalue = null;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase 27: {\n\t\t\t\t\t\tvalue = readFloat64(state);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tthrow new Error(`invalid simple value; got ${info}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new TypeError(`invalid type; got ${type}`);\n\t\t\t}\n\t\t}\n\n\t\twhile (stack !== null) {\n\t\t\tconst node = stack;\n\n\t\t\tswitch (node.t) {\n\t\t\t\tcase ContainerType.ARRAY: {\n\t\t\t\t\tconst index = node.c.length - node.r;\n\t\t\t\t\tnode.c[index] = value;\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase ContainerType.MAP: {\n\t\t\t\t\tif (node.k === null) {\n\t\t\t\t\t\tif (typeof value !== 'string') {\n\t\t\t\t\t\t\tthrow new TypeError(`expected map to only have string keys; got ${type}`);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tnode.k = value;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (node.k === '__proto__') {\n\t\t\t\t\t\t\t// Guard against prototype pollution. CWE-1321\n\t\t\t\t\t\t\tObject.defineProperty(node.c, node.k, { enumerable: true, configurable: true, writable: true });\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tnode.c[node.k] = value;\n\t\t\t\t\t\tnode.k = null;\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (--node.r !== 0) {\n\t\t\t\t// We still have more values to decode, continue\n\t\t\t\tcontinue jump;\n\t\t\t}\n\n\t\t\t// Unwrap the stack\n\t\t\tvalue = node.c;\n\t\t\tstack = node.n;\n\t\t}\n\n\t\tresult = value;\n\t\tbreak;\n\t}\n\n\treturn [result, buf.subarray(state.p)];\n};\n\nexport const decode = (buf: Uint8Array): any => {\n\tconst [value, remainder] = decodeFirst(buf);\n\tif (remainder.length !== 0) {\n\t\tthrow new Error(`decoded value contains remainder`);\n\t}\n\n\treturn value;\n};\n", "export interface SyncByteReader {\n\treadonly pos: number;\n\tupto(size: number): Uint8Array;\n\texactly(size: number, seek: boolean): Uint8Array;\n\tseek(size: number): void;\n}\n\nexport const createUint8Reader = (buf: Uint8Array): SyncByteReader => {\n\tlet pos = 0;\n\n\treturn {\n\t\tget pos() {\n\t\t\treturn pos;\n\t\t},\n\n\t\tseek(size) {\n\t\t\tif (size > buf.length - pos) {\n\t\t\t\tthrow new RangeError('unexpected end of data');\n\t\t\t}\n\n\t\t\tpos += size;\n\t\t},\n\t\tupto(size) {\n\t\t\treturn buf.subarray(pos, pos + Math.min(size, buf.length - pos));\n\t\t},\n\t\texactly(size, seek) {\n\t\t\tif (size > buf.length - pos) {\n\t\t\t\tthrow new RangeError('unexpected end of data');\n\t\t\t}\n\n\t\t\tconst slice = buf.subarray(pos, pos + size);\n\t\t\tif (seek) {\n\t\t\t\tpos += size;\n\t\t\t}\n\n\t\t\treturn slice;\n\t\t},\n\t};\n};\n", "import * as CBOR from '@atcute/cbor';\nimport * as CID from '@atcute/cid';\n\nexport interface CarV1Header {\n\tversion: 1;\n\troots: CID.CidLink[];\n}\n\nexport const isCarV1Header = (value: unknown): value is CarV1Header => {\n\tif (value === null || typeof value !== 'object') {\n\t\treturn false;\n\t}\n\n\tconst { version, roots } = value as CarV1Header;\n\treturn version === 1 && Array.isArray(roots) && roots.every((root) => root instanceof CBOR.CidLinkWrapper);\n};\n", "import * as CBOR from '@atcute/cbor';\nimport * as CID from '@atcute/cid';\nimport * as varint from '@atcute/varint';\n\nimport { isCarV1Header, type CarV1Header } from './car.js';\nimport type { SyncByteReader } from './sync-byte-reader.js';\n\nconst readVarint = (reader: SyncByteReader, size: number): number => {\n\tconst buf = reader.upto(size);\n\tif (buf.length === 0) {\n\t\tthrow new RangeError(`unexpected end of data`);\n\t}\n\n\tconst [int, read] = varint.decode(buf);\n\treader.seek(read);\n\n\treturn int;\n};\n\nconst readHeader = (reader: SyncByteReader): CarV1Header => {\n\tconst length = readVarint(reader, 8);\n\tif (length === 0) {\n\t\tthrow new RangeError(`invalid car header; length=0`);\n\t}\n\n\tconst rawHeader = reader.exactly(length, true);\n\tconst header = CBOR.decode(rawHeader);\n\tif (!isCarV1Header(header)) {\n\t\tthrow new TypeError(`expected a car v1 archive`);\n\t}\n\n\treturn header;\n};\n\nconst readCid = (reader: SyncByteReader): CID.Cid => {\n\tconst head = reader.upto(3 + 4);\n\n\tconst version = head[0];\n\tconst codec = head[1];\n\tconst digestCodec = head[2];\n\n\tif (version !== CID.CID_VERSION) {\n\t\tthrow new RangeError(`incorrect cid version (got v${version})`);\n\t}\n\n\tif (codec !== CID.CODEC_DCBOR && codec !== CID.CODEC_RAW) {\n\t\tthrow new RangeError(`incorrect cid codec (got 0x${codec.toString(16)})`);\n\t}\n\n\tif (digestCodec !== CID.HASH_SHA256) {\n\t\tthrow new RangeError(`incorrect cid hash type (got 0x${digestCodec.toString(16)})`);\n\t}\n\n\tconst [digestSize, digestLebSize] = varint.decode(head, 3);\n\n\tconst bytes = reader.exactly(3 + digestLebSize + digestSize, true);\n\tconst digest = bytes.subarray(3 + digestLebSize);\n\n\tconst cid: CID.Cid = {\n\t\tversion: version,\n\t\tcodec: codec,\n\t\tdigest: {\n\t\t\tcodec: digestCodec,\n\t\t\tcontents: digest,\n\t\t},\n\t\tbytes: bytes,\n\t};\n\n\treturn cid;\n};\n\nconst readBlockHeader = (reader: SyncByteReader): { cid: CID.Cid; blockSize: number } => {\n\tconst start = reader.pos;\n\n\tlet size = readVarint(reader, 8);\n\tif (size === 0) {\n\t\tthrow new Error(`invalid car section; length=0`);\n\t}\n\n\tsize += reader.pos - start;\n\n\tconst cid = readCid(reader);\n\tconst blockSize = size - (reader.pos - start);\n\n\treturn { cid, blockSize };\n};\n\nexport const createCarReader = (reader: SyncByteReader) => {\n\tconst { roots } = readHeader(reader);\n\n\treturn {\n\t\troots,\n\t\t*iterate(): Generator<{ cid: CID.Cid; bytes: Uint8Array }> {\n\t\t\twhile (reader.upto(8).length > 0) {\n\t\t\t\tconst { cid, blockSize } = readBlockHeader(reader);\n\t\t\t\tconst bytes = reader.exactly(blockSize, true);\n\n\t\t\t\tyield { cid, bytes };\n\t\t\t}\n\t\t},\n\t};\n};\n", "import { createUint8Reader } from './utilities/sync-byte-reader.js';\nimport { createCarReader } from './utilities/sync-car-reader.js';\n\nexport const readCar = (buffer: Uint8Array) => {\n\tconst reader = createUint8Reader(buffer);\n\treturn createCarReader(reader);\n};\n", "import * as CBOR from '@atcute/cbor';\nimport * as CID from '@atcute/cid';\n\nimport { readCar } from './reader.js';\n\nconst decoder = new TextDecoder();\n\nexport class RepoEntry {\n\tconstructor(\n\t\tpublic readonly collection: string,\n\t\tpublic readonly rkey: string,\n\t\tpublic readonly cid: CID.CidLink,\n\t\tprivate blockmap: BlockMap,\n\t) {}\n\n\tget bytes(): Uint8Array {\n\t\tconst cid = this.cid.$link;\n\n\t\tconst bytes = this.blockmap.get(cid);\n\t\tassert(bytes != null, `cid not found in blockmap; cid=${cid}`);\n\n\t\treturn bytes;\n\t}\n\n\tget record(): unknown {\n\t\treturn CBOR.decode(this.bytes);\n\t}\n}\n\nexport function* iterateAtpRepo(buf: Uint8Array): Generator<RepoEntry> {\n\tconst { roots, iterate } = readCar(buf);\n\tassert(roots.length === 1, `expected only 1 root in the car archive; got=${roots.length}`);\n\n\t// Collect all archive entries into a mapping of CID string -> actual bytes\n\tconst blockmap: BlockMap = new Map();\n\tfor (const entry of iterate()) {\n\t\tblockmap.set(CID.toString(entry.cid), entry.bytes);\n\t}\n\n\t// Read the head, then walk through the MST tree from there.\n\tconst commit = readObject(blockmap, roots[0]) as Commit;\n\tfor (const { key, cid } of walkEntries(blockmap, commit.data)) {\n\t\tconst [collection, rkey] = key.split('/');\n\n\t\tyield new RepoEntry(collection, rkey, cid, blockmap);\n\t}\n}\n\nfunction readObject(map: BlockMap, link: CID.CidLink): unknown {\n\tconst cid = link.$link;\n\n\tconst bytes = map.get(cid);\n\tassert(bytes != null, `cid not found in blockmap; cid=${cid}`);\n\n\tconst data = CBOR.decode(bytes);\n\n\treturn data;\n}\n\nfunction* walkEntries(map: BlockMap, pointer: CID.CidLink): Generator<NodeEntry> {\n\tconst data = readObject(map, pointer) as MstNode;\n\tconst entries = data.e;\n\n\tlet lastKey = '';\n\n\tif (data.l !== null) {\n\t\tyield* walkEntries(map, data.l);\n\t}\n\n\tfor (let i = 0, il = entries.length; i < il; i++) {\n\t\tconst entry = entries[i];\n\n\t\tconst key_str = decoder.decode(CBOR.fromBytes(entry.k));\n\t\tconst key = lastKey.slice(0, entry.p) + key_str;\n\n\t\tlastKey = key;\n\n\t\tyield { key: key, cid: entry.v };\n\n\t\tif (entry.t !== null) {\n\t\t\tyield* walkEntries(map, entry.t);\n\t\t}\n\t}\n}\n\nfunction assert(condition: boolean, message: string): asserts condition {\n\tif (!condition) {\n\t\tthrow new Error(message);\n\t}\n}\n\ntype BlockMap = Map<string, Uint8Array>;\n\ninterface Commit {\n\tversion: 3;\n\tdid: string;\n\tdata: CID.CidLink;\n\trev: string;\n\tprev: CID.CidLink | null;\n\tsig: CBOR.Bytes;\n}\n\ninterface TreeEntry {\n\t/** count of bytes shared with previous TreeEntry in this Node (if any) */\n\tp: number;\n\t/** remainder of key for this TreeEntry, after \"prefixlen\" have been removed */\n\tk: CBOR.Bytes;\n\t/** link to a sub-tree Node at a lower level which has keys sorting after this TreeEntry's key (to the \"right\"), but before the next TreeEntry's key in this Node (if any) */\n\tv: CID.CidLink;\n\t/** next subtree (to the right of leaf) */\n\tt: CID.CidLink | null;\n}\n\ninterface MstNode {\n\t/** link to sub-tree Node on a lower level and with all keys sorting before keys at this node */\n\tl: CID.CidLink | null;\n\t/** ordered list of TreeEntry objects */\n\te: TreeEntry[];\n}\n\ninterface NodeEntry {\n\tkey: string;\n\tcid: CID.CidLink;\n}\n", "// @ts-check\n\nimport { readCar, iterateAtpRepo } from '@atcute/car';\nimport { decode, toCidLink } from '@atcute/cbor';\n\nconst YIELD_AFTER_ITERATION = 300;\n\n/**\n * @param {ArrayBuffer | Uint8Array} messageBuf\n * @param {string} did\n */\nexport function readCAR(messageBuf, did) {\n  if (typeof messageBuf === 'string')\n    [messageBuf, did] = /** @type {[any, any]} */([did, messageBuf]);\n\n  // for (const x of iterateAtpRepo(messageBuf)) {\n  //   console.log(x);\n  // }\n\n  /** @type {import('./firehose').FirehoseRepositoryRecord<keyof import('./firehose').RepositoryRecordTypes$>[] & { parseTime: number } | undefined} */\n  let all;\n  for (const _chunk of sequenceReadCARCore(messageBuf, did, Infinity)) {\n    if (_chunk) all = _chunk;\n  }\n  return   /** @type {NonNullable<typeof all>} */(all);\n}\n\n/**\n * @param {ArrayBuffer | Uint8Array} messageBuf\n * @param {string} did\n */\nexport function sequenceReadCAR(messageBuf, did) {\n  return sequenceReadCARCore(messageBuf, did, YIELD_AFTER_ITERATION);\n}\n\n/**\n * @param {ArrayBuffer | Uint8Array} messageBuf\n * @param {string} did\n * @param {number} yieldAfterIteration\n */\nfunction* sequenceReadCARCore(messageBuf, did, yieldAfterIteration) {\n  if (typeof messageBuf === 'string')\n    [messageBuf, did] = /** @type {[any, any]} */([did, messageBuf]);\n\n  const parseStart = Date.now();\n  let pauseTime = 0;\n\n  let batchParseStart = parseStart;\n\n  const bytes = messageBuf instanceof ArrayBuffer ? new Uint8Array(messageBuf) : messageBuf;\n\n  const car = readCar(bytes);\n\n  const recordsByCid = new Map();\n  const keyByCid = new Map();\n  const errors = [];\n  const decoder = new TextDecoder();\n\n  let iteration = 0;\n  for (const block of car.iterate()) {\n    iteration++;\n    if (iteration % yieldAfterIteration === yieldAfterIteration - 1) {\n      // parsing, but not yielding any records yet\n      const pauseStart = Date.now();\n      const emptyBatch = /** @type {never[] & { parseTime: number }} */([]);\n      emptyBatch.parseTime = pauseStart - batchParseStart;\n      yield emptyBatch;\n      batchParseStart = Date.now();\n      pauseTime += batchParseStart - pauseStart;\n    }\n\n    const record = decode(block.bytes);\n    if (record.$type) {\n      const blockCid = toCidLink(block.cid).$link;\n      recordsByCid.set(blockCid, record);\n    } else if (Array.isArray(record.e)) {\n      let key = '';\n      for (const sub of record.e) {\n        iteration++;\n        if (iteration % yieldAfterIteration === yieldAfterIteration - 1) {\n          // parsing, but not yielding any records yet\n          const pauseStart = Date.now();\n          const emptyBatch = /** @type {never[] & { parseTime: number }} */([]);\n          emptyBatch.parseTime = pauseStart - batchParseStart;\n          yield emptyBatch;\n          batchParseStart = Date.now();\n          pauseTime += batchParseStart - pauseStart;\n        }\n\n        if (!sub.k || !sub.v) continue;\n        try {\n          const keySuffix = decoder.decode(sub.k.buf);\n          key = key.slice(0, sub.p || 0) + keySuffix;\n\n          let cid;\n          if (typeof sub.v === 'string') {\n            cid = sub.v;\n          } else if (sub.v.$link) {\n            cid = String(sub.v.$link);\n          }\n\n          if (!cid) continue;\n\n          keyByCid.set(cid, key);\n        } catch (error) {\n          if (!errors.length) console.error(error);\n          errors.push(error);\n        }\n      }\n    }\n  }\n\n  /** @type {import('./firehose').FirehoseRecord[] & { parseTime: number }} */\n  let batch = /** @type {*} */([]);\n\n  /** @type {import('./firehose').FirehoseRecord[] & { parseTime: number }} */\n  const all = /** @type {*} */([]);\n\n  for (const entry of recordsByCid) {\n    const cid = entry[0].$link ? String(entry[0].$link) : String(entry[0]);\n    /** @type {import('./firehose').FirehoseRecord} */\n    const record = entry[1];\n    record.repo = did;\n    record.cid = cid;\n    const key = keyByCid.get(cid);\n    if (key) {\n      record.path = key;\n      record.uri = 'at://' + did + '/' + key;\n    }\n\n    // let's recreate the record, to pack the GC and avoid deoptimized objects\n    batch.push(record);\n    all.push(record);\n\n    iteration++;\n    if (iteration % yieldAfterIteration === yieldAfterIteration - 1) {\n      const pauseStart = Date.now();\n      batch.parseTime = pauseStart - batchParseStart;\n      yield batch;\n      batch = /** @type {*} */([]);\n      batchParseStart = Date.now();\n      pauseTime += batchParseStart - pauseStart;\n    }\n  }\n\n  // record.seq = commit.seq; 471603945\n  // record.since = /** @type {string} */(commit.since); 3ksfhcmgghv2g\n  // record.action = op.action;\n  // record.cid = cid;\n  // record.path = op.path;\n  // record.timestamp = commit.time ? Date.parse(commit.time) : Date.now(); 2024-05-13T19:59:10.457Z\n\n  // record.repo = fullDID;\n  // record.uri = fullDID + '/' + 'op.path';\n  // record.action = 'create';\n\n  const finish = Date.now();\n  if (batch.length) {\n    batch.parseTime = finish - batchParseStart;\n    yield batch;\n  }\n  all.parseTime = finish - parseStart - pauseTime;\n  return all;\n}\n\n/**\n * @param {ArrayBuffer | Uint8Array} messageBuf\n * @param {string} did\n */\nexport function readCARATC(messageBuf, did) {\n  if (typeof messageBuf === 'string')\n    [messageBuf, did] = /** @type {[any, any]} */([did, messageBuf]);\n\n  // for (const x of iterateAtpRepo(messageBuf)) {\n  //   console.log(x);\n  // }\n\n  /** @type {import('./firehose').FirehoseRepositoryRecord<keyof import('./firehose').RepositoryRecordTypes$>[] & { parseTime: number } | undefined} */\n  let all;\n  for (const _chunk of sequenceReadCARCore(messageBuf, did, Infinity)) {\n    if (_chunk) all = _chunk;\n  }\n  return   /** @type {NonNullable<typeof all>} */(all);\n}\n\n/**\n * @param {ArrayBuffer | Uint8Array} messageBuf\n * @param {string} did\n */\nexport function sequenceReadCARATC(messageBuf, did) {\n  return sequenceReadCARCoreATC(messageBuf, did, YIELD_AFTER_ITERATION);\n}\n\n/**\n * @param {ArrayBuffer | Uint8Array} messageBuf\n * @param {string} did\n * @param {number} yieldAfterIteration\n */\nfunction* sequenceReadCARCoreATC(messageBuf, did, yieldAfterIteration) {\n  if (typeof messageBuf === 'string')\n    [messageBuf, did] = /** @type {[any, any]} */([did, messageBuf]);\n\n  const parseStart = Date.now();\n  let pauseTime = 0;\n\n  let batchParseStart = parseStart;\n\n  const bytes = messageBuf instanceof ArrayBuffer ? new Uint8Array(messageBuf) : messageBuf;\n\n  /** @type {import('./firehose').FirehoseRecord[] & { parseTime: number }} */\n  let batch = /** @type {*} */([]);\n\n  /** @type {import('./firehose').FirehoseRecord[] & { parseTime: number }} */\n  const all = /** @type {*} */([]);\n\n  let iteration = 0;\n  for (const entry of iterateAtpRepo(bytes)) {\n    const { cid: { $link: cid }, collection, rkey, record } = entry;\n\n    record.repo = did;\n    record.cid = cid;\n    record.path = collection + '/' + rkey;\n    record.uri = 'at://' + did + '/' + collection + '/' + rkey;\n\n    batch.push(record);\n    all.push(record);\n\n    iteration++;\n    if (iteration % yieldAfterIteration === yieldAfterIteration - 1) {\n      const pauseStart = Date.now();\n      batch.parseTime = pauseStart - batchParseStart;\n      yield batch;\n      batch = /** @type {*} */([]);\n      batchParseStart = Date.now();\n      pauseTime += batchParseStart - pauseStart;\n    }\n  }\n\n\n  const finish = Date.now();\n  if (batch.length) {\n    batch.parseTime = finish - batchParseStart;\n    yield batch;\n  }\n  all.parseTime = finish - parseStart - pauseTime;\n  return all;\n}", "{\n  \"name\": \"6sky\",\n  \"version\": \"0.9.13\",\n  \"author\": \"Oleg Mihailik\",\n  \"license\": \"MIT\",\n  \"description\": \"BlueSky firehose/WebSocket and CAR in plain JavaScript\",\n  \"repository\": \"https://github.com/colds-ky/bski\",\n  \"main\": \"index.cjs\",\n  \"exports\": {\n    \"import\": \"./index.js\",\n    \"require\": \"./index.cjs\"\n  },\n  \"type\": \"module\",\n  \"scripts\": {\n    \"build\": \"esbuild --bundle index.js --tsconfig=tsconfig.json --analyze --format=iife --sourcemap --global-name=bski --outfile=index.cjs\",\n    \"build-rollup\": \"rollup index.js --format=iife --sourcemap --name=bski --file=index.cjs\",\n    \"test\": \"node tests/test.cjs\"\n  },\n  \"keywords\": [\n    \"bluesky\",\n    \"bsky\",\n    \"bski\",\n    \"atproto\",\n    \"firehose\",\n    \"car\",\n    \"dag/cbor\",\n    \"dag\",\n    \"cbor\"\n  ],\n  \"devDependencies\": {\n    \"esbuild\": \"^0.24.2\",\n    \"rollup\": \"^4.32.1\"\n  },\n  \"dependencies\": {\n    \"@atcute/car\": \"^2.0.1\"\n  }\n}\n", "// @ts-check\n/// <reference types='@atproto/api' />\n\nimport { readCar } from '@atcute/car';\nimport { decode, decodeFirst, fromBytes, toCidLink } from '@atcute/cbor';\n\nimport { version } from './package.json';\nexport { version };\n\nconst emptyUint8Array = new Uint8Array();\n\n/**\n * @typedef {{\n *  'app.bsky.feed.like': import('@atproto/api').AppBskyFeedLike.Record,\n *  'app.bsky.feed.post': import('@atproto/api').AppBskyFeedPost.Record,\n *  'app.bsky.feed.repost': import('@atproto/api').AppBskyFeedRepost.Record,\n *  'app.bsky.feed.threadgate': import('@atproto/api').AppBskyFeedThreadgate.Record,\n *  'app.bsky.graph.follow': import('@atproto/api').AppBskyGraphFollow.Record,\n *  'app.bsky.graph.block': import('@atproto/api').AppBskyGraphBlock.Record,\n *  'app.bsky.graph.list': import('@atproto/api').AppBskyGraphList.Record,\n *  'app.bsky.graph.listitem': import('@atproto/api').AppBskyGraphListitem.Record,\n *  'app.bsky.graph.listblock': import('@atproto/api').AppBskyGraphListblock.Record,\n *  'app.bsky.actor.profile': import('@atproto/api').AppBskyActorProfile.Record\n *  'app.bsky.feed.generator': import('@atproto/api').AppBskyFeedGenerator.Record\n *  'app.bsky.feed.postgate': import('@atproto/api').AppBskyFeedPostgate.Record\n *  'chat.bsky.actor.declaration': import('@atproto/api').ChatBskyActorDeclaration.Record,\n *  'app.bsky.graph.starterpack': import('@atproto/api').AppBskyGraphStarterpack.Record\n * }} RepositoryRecordTypes$\n */\n\n/**\n * @template {keyof RepositoryRecordTypes$} $Type\n * @typedef {RepositoryRecordTypes$[$Type] & {\n *  repo: string,\n *  uri: string,\n *  cid: string,\n *  action: 'create' | 'update',\n *  path: string,\n *  $type: $Type,\n *  since: string,\n *  time: string,\n *  receiveTimestamp: number,\n *  parseTime: number\n * }} FirehoseRepositoryRecord\n */\n\n/**\n * @typedef {{\n *  repo: string,\n *  uri: string,\n *  action: 'delete',\n *  path: string,\n *  $type: keyof RepositoryRecordTypes$,\n *  since: string,\n *  time: string,\n *  receiveTimestamp: number,\n *  parseTime: number\n * }} FirehoseDeleteRecord\n */\n\n\n/**\n * @typedef {{\n *  $type: '#identity',\n *  repo: string,\n *  action?: never,\n *  handle: string,\n *  time: string,\n *  receiveTimestamp: number,\n *  parseTime: number\n * }} FirehoseIdentityRecord\n */\n\n/**\n * @typedef {{\n *  $type: '#identity',\n *  repo: string,\n *  action?: never,\n *  active: boolean,\n *  time: string,\n *  receiveTimestamp: number,\n *  parseTime: number\n * }} FirehoseAccountRecord\n */\n\n/**\n * @typedef {{\n *  $type: 'error',\n *  action?: never,\n *  message: string,\n *  receiveTimestamp: number,\n *  parseTime: number\n * } & Record<string, unknown>} FirehoseErrorRecord\n */\n\n/**\n * @typedef {FirehoseRepositoryRecord<'app.bsky.feed.like'> |\n * FirehoseRepositoryRecord<'app.bsky.feed.post'> |\n * FirehoseRepositoryRecord<'app.bsky.feed.repost'> |\n * FirehoseRepositoryRecord<'app.bsky.feed.threadgate'> |\n * FirehoseRepositoryRecord<'app.bsky.graph.follow'> |\n * FirehoseRepositoryRecord<'app.bsky.graph.block'> |\n * FirehoseRepositoryRecord<'app.bsky.graph.list'> |\n * FirehoseRepositoryRecord<'app.bsky.graph.listitem'> |\n * FirehoseRepositoryRecord<'app.bsky.graph.listblock'> |\n * FirehoseRepositoryRecord<'app.bsky.actor.profile'> |\n * FirehoseRepositoryRecord<'app.bsky.feed.generator'> |\n * FirehoseRepositoryRecord<'app.bsky.feed.postgate'> |\n * FirehoseRepositoryRecord<'chat.bsky.actor.declaration'> |\n * FirehoseRepositoryRecord<'app.bsky.graph.starterpack'> |\n * FirehoseDeleteRecord |\n * FirehoseIdentityRecord |\n * FirehoseAccountRecord |\n * FirehoseErrorRecord\n * } FirehoseRecord\n */\n\nexport const known$Types = /** @type {const} */([\n  'app.bsky.feed.like', 'app.bsky.feed.post', 'app.bsky.feed.repost', 'app.bsky.feed.threadgate',\n  'app.bsky.graph.follow', 'app.bsky.graph.block', 'app.bsky.graph.list', 'app.bsky.graph.listitem', 'app.bsky.graph.listblock',\n  'app.bsky.actor.profile',\n  'app.bsky.feed.generator',\n  'app.bsky.feed.postgate',\n  'chat.bsky.actor.declaration',\n  'app.bsky.graph.starterpack'\n]);\n\nfirehose.knownTypes = known$Types;\n\nfunction requireWebsocket() {\n  const globalObj = typeof global !== 'undefined' && global || typeof globalThis !== 'undefined' && globalThis;\n  const requireFn = globalObj?.['require'];\n  if (typeof requireFn === 'function') return /** @type {typeof WebSocket} */(requireFn('ws'));\n  throw new Error('WebSocket not available');\n}\n\nfirehose.each = each;\nfirehose.version = version;\n\n/**\n * @param {string} [address]\n * @returns {AsyncGenerator<FirehoseRecord[], void, void>}\n */\nexport async function* firehose(address) {\n  const WebSocketImpl = typeof WebSocket === 'function' ? WebSocket :\n    requireWebsocket();\n\n  const wsAddress = address || 'wss://bsky.network/xrpc/com.atproto.sync.subscribeRepos';\n\n  const ws = new WebSocketImpl(wsAddress);\n  ws.binaryType = 'arraybuffer';\n  ws.addEventListener('message', handleMessage);\n  ws.addEventListener('error', handleError);\n  ws.addEventListener('close', handleClose)\n\n  let buf = createAwaitPromise();\n  let closed = false;\n\n  try {\n\n    while (true) {\n      await buf.promise;\n      if (buf.block?.length) {\n        const block = buf.block;\n        buf = createAwaitPromise();\n        if (closed) {\n          block['messages'] = block; // backwards compatibility trick\n          if (block.length) yield block;\n          break;\n        }\n        yield block;\n      } else {\n        buf = createAwaitPromise();\n      }\n    }\n  } finally {\n    if (!closed) {\n      try { ws.close(); }\n      catch (error) { }\n    }\n  }\n\n  function handleClose() {\n    closed = true;\n    buf.resolve();\n  }\n\n  function handleMessage(event) {\n    const receiveTimestamp = Date.now();\n\n    if (typeof event.data?.byteLength === 'number') {\n      parseMessageBufAndResolve(receiveTimestamp, event.data);\n    } else if (typeof event.data?.arrayBuffer === 'function') {\n      event.data.arrayBuffer().then(arrayBuffer => parseMessageBufAndResolve(receiveTimestamp, arrayBuffer))\n    } else {\n      buf.block.push({\n        $type: 'error',\n        message: 'WebSocket message type not supported.',\n        data: event.data,\n        receiveTimestamp,\n        parseTime: 0\n      });\n      buf.resolve();\n    }\n  }\n\n  /**\n   * @param {number} receiveTimestamp\n   * @param {ArrayBuffer} arrayBuf\n   */\n  function parseMessageBufAndResolve(receiveTimestamp, arrayBuf) {\n    parseMessageBuf(receiveTimestamp, new Uint8Array(arrayBuf));\n    buf.resolve();\n  }\n\n  /**\n   * @param {number} receiveTimestamp\n   * @param {Uint8Array} messageBuf\n   */\n  function parseMessageBuf(receiveTimestamp, messageBuf) {\n    const parseStart = performance.now();\n    try {\n      parseMessageBufWorker(receiveTimestamp, parseStart, messageBuf);\n      buf.resolve();\n    } catch (parseError) {\n      buf.block.push({\n        $type: 'error',\n        message: parseError.message,\n        receiveTimestamp,\n        parseTime: performance.now() - parseStart\n      });\n    }\n\n    buf.resolve();\n  }\n\n  /**\n * @param {number} receiveTimestamp\n * @param {number} parseStart\n * @param {Uint8Array} messageBuf\n */\n  function parseMessageBufWorker(receiveTimestamp, parseStart, messageBuf) {\n    const [header, remainder] = decodeFirst(messageBuf);\n    const [body, remainder2] = decodeFirst(remainder);\n    if (remainder2.length > 0) {\n      return buf.block.push({\n        $type: 'error',\n        message: 'Excess bytes in message.',\n        receiveTimestamp,\n        parseTime: performance.now() - parseStart\n      });\n    }\n\n    const { t, op } = header;\n\n    if (op === -1) {\n      return buf.block.push({\n        $type: 'error',\n        message: 'Error header#' + body.error + ': ' + body.message,\n        receiveTimestamp,\n        parseTime: performance.now() - parseStart\n      });\n    }\n\n    if (t === '#commit') {\n      const commit = body;\n\n      // A commit can contain no changes\n      if (!('blocks' in commit) || !(commit.blocks.$bytes.length)) {\n        return buf.block.push({\n          $type: 'com.atproto.sync.subscribeRepos#commit',\n          ...commit,\n          blocks: emptyUint8Array,\n          ops: [],\n          receiveTimestamp,\n          parseTime: performance.now() - parseStart\n        });\n      }\n\n      const blocks = fromBytes(commit.blocks);\n      const car = readCarToMap(blocks);\n      for (let opIndex = 0; opIndex < commit.ops.length; opIndex++) {\n        const op = commit.ops[opIndex];\n        const action = op.action;\n\n        const now = performance.now();\n        const record = op.cid ? car.get(op.cid.$link) : undefined;\n\n        if (action === 'create' || action === 'update') {\n          if (!op.cid) {\n            buf.block.push({\n              $type: 'error',\n              message: 'Missing commit.ops[' + (opIndex - 1) + '].cid.',\n              receiveTimestamp,\n              parseTime: now - parseStart,\n              commit\n            });\n            parseStart = now;\n            continue;\n          }\n\n          if (!record) {\n            buf.block.push({\n              $type: 'error',\n              message: 'Unresolved commit.ops[' + (opIndex - 1) + '].cid ' + op.cid,\n              receiveTimestamp,\n              parseTime: now - parseStart,\n              commit\n            });\n            parseStart = now;\n            continue;\n          }\n\n          record.action = action;\n          record.uri = 'at://' + commit.repo + '/' + op.path;\n          record.path = op.path;\n          record.cid = op.cid;\n          record.receiveTimestamp = receiveTimestamp;\n          record.parseTime = now - parseStart;\n\n          buf.block.push(record);\n          continue;\n        } else if (action === 'delete') {\n          buf.block.push({\n            action,\n            path: op.path,\n            receiveTimestamp,\n            parseTime: now - parseStart\n          });\n          parseStart = now;\n        } else {\n          buf.block.push({\n            $type: 'error',\n            message: 'Unknown action ' + op.action,\n            ...record,\n            receiveTimestamp,\n            parseTime: now - parseStart\n          });\n          parseStart = now;\n          continue;\n        }\n      }\n      return;\n    }\n\n    return buf.block.push({\n      $type: t,\n      ...body,\n      receiveTimestamp,\n      parseTime: performance.now() - parseStart\n    });\n  }\n\n  function handleError(error) {\n    console.error(error);\n    const errorText =\n      error.message || 'WebSocket error ' + error;\n    buf.reject(new Error(errorText));\n  }\n\n}\n\n/**\n * @param {string} [address]\n * @returns {AsyncGenerator<FirehoseRecord, void, void>}\n */\nasync function* each(address) {\n  for await (const block of firehose(address)) {\n    yield* block;\n  }\n}\n\n/**\n * @returns {{\n *  block: FirehoseRecord[],\n *  resolve: () => void,\n *  reject: (reason?: any) => void,\n *  promise: Promise<void>\n * }} */\nfunction createAwaitPromise() {\n  const result = {\n    /** @type {FirehoseRecord[]} */\n    block: []\n  };\n  result.promise = new Promise((resolve, reject) => {\n    result.resolve = resolve;\n    result.reject = reject;\n  });\n  return /** @type {*} */(result);\n}\n\n/** @param {Uint8Array} buffer */\nfunction readCarToMap(buffer) {\n  const records = new Map();\n  for (const { cid, bytes } of readCar(buffer).iterate()) {\n    records.set(toCidLink(cid).$link, decode(bytes));\n  }\n  return records;\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,MAAM,cAAc,IAAI,YAAY;AACpC,MAAM,cAAc,IAAI,YAAY;AAEpC,MAAM,SAAS,OAAO;AAKf,MAAM,QAAQ,CAAC,SAA6B;AAClD,WAAO,IAAI,WAAW,IAAI;AAAA,EAC3B;AAMO,MAAM,cAAc;AAqHpB,MAAM,iBAAiB,CAAC,MAAkB,QAAiB,WAA4B;AAC7F,QAAI;AAEJ,QAAI,WAAW,QAAW;AACzB,eAAS;AAAA,IACV,WAAW,WAAW,QAAW;AAChC,eAAS,KAAK,SAAS,MAAM;AAAA,IAC9B,OAAO;AACN,eAAS,KAAK,SAAS,QAAQ,SAAS,MAAM;AAAA,IAC/C;AAEA,UAAM,SAAS,YAAY,OAAO,MAAM;AAExC,WAAO;AAAA,EACR;;;ACjJO,MAAM,sBAAsB,CAAC,UAAkB,aAAqB,QAAiB;AAC3F,WAAO,CAAC,UAA8B;AACrC,YAAM,QAAQ,KAAK,eAAe;AAClC,UAAI,MAAM;AA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BAAiB,SAAS,SAAS,OAAO,GAAG;AAC3C,aAAO;AAAA,IACT;AAAA,EACF;AASA,WAAS,qBAAqB;AAC5B,UAAM,SAAS;AAAA;AAAA,MAEb,OAAO,CAAC;AAAA,IACV;AACA,WAAO,UAAU,IAAI,QAAQ,CAAC,SAAS,WAAW;AAChD,aAAO,UAAU;AACjB,aAAO,SAAS;AAAA,IAClB,CAAC;AACD;AAAA;AAAA,MAAwB;AAAA;AAAA,EAC1B;AAGA,WAAS,aAAa,QAAQ;AAC5B,UAAM,UAAU,oBAAI,IAAI;AACxB,eAAW,EAAE,KAAK,MAAM,KAAK,QAAQ,MAAM,EAAE,QAAQ,GAAG;AACtD,cAAQ,IAAI,UAAU,GAAG,EAAE,OAAOC,QAAO,KAAK,CAAC;AAAA,IACjD;AACA,WAAO;AAAA,EACT;",
  "names": ["type", "info", "len", "decode", "version", "decode", "readCid", "version", "decode", "decoder", "decode", "op", "decode"]
}
