@fireproof/database
Version:
Live database for the web
1,765 lines (1,743 loc) • 135 kB
JavaScript
console.log('cjs/node build');
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
for (var name2 in all)
__defProp(target, name2, { get: all[name2], enumerable: true });
};
var __copyProps = (to, from3, except, desc) => {
if (from3 && typeof from3 === "object" || typeof from3 === "function") {
for (let key of __getOwnPropNames(from3))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from3[key], enumerable: !(desc = __getOwnPropDesc(from3, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// ../../node_modules/.pnpm/charwise@3.0.1/node_modules/charwise/codec/number.js
var require_number = __commonJS({
"../../node_modules/.pnpm/charwise@3.0.1/node_modules/charwise/codec/number.js"(exports) {
exports.encode = function(number) {
if (isNaN(number)) {
return "DaN";
}
if (number === 0) {
return "FE 0M0";
}
if (number === Infinity) {
return "FF";
}
if (number === -Infinity) {
return "DD";
}
var splitScientificNotation = number.toExponential().split("e");
var exponent = Number(splitScientificNotation[1]) + 500;
var mantissa = splitScientificNotation[0] + (splitScientificNotation[0].indexOf(".") === -1 ? "." : "") + "0".repeat(20);
var encoded = "E" + padStart(String(exponent), 3) + "M" + String(mantissa);
if (number > 0) {
return "F" + encoded;
} else {
return "D" + flip(encoded);
}
};
exports.decode = function(encoded) {
if (encoded === "DaN") {
return NaN;
}
if (encoded === "FF") {
return Infinity;
}
if (encoded === "DD") {
return -Infinity;
}
var isNegative = encoded[0] === "D";
var splitEncoded = (isNegative ? flip(encoded) : encoded).slice(2).split("M");
return Number((isNegative ? "-" : "") + splitEncoded[1] + "e" + String(Number(splitEncoded[0]) - 500));
};
function flip(number) {
var flipped = "";
for (var i = 0; i < number.length; i++) {
var digit = number[i];
if (isNaN(Number(digit)) || digit === " ") {
if (digit !== "-") {
flipped += digit;
}
} else {
flipped += String(9 - Number(digit));
}
}
return flipped;
}
function padStart(str, count) {
return " ".repeat(count - str.length).substr(0, count) + str;
}
}
});
// ../../node_modules/.pnpm/charwise@3.0.1/node_modules/charwise/codec/object.js
var require_object = __commonJS({
"../../node_modules/.pnpm/charwise@3.0.1/node_modules/charwise/codec/object.js"(exports) {
var dictEscape = { "?": "?@", "!": "??", '"': "?%" };
function escape(str) {
if (!/[!"]/.test(str)) {
return str;
}
return str.replace(/[\?!"]/g, function(match) {
return dictEscape[match];
});
}
var dictUnescape = { "?@": "?", "??": "!", "?%": '"' };
function unescape(str) {
if (!/\?[%\?@]/.test(str)) {
return str;
}
return str.replace(/\?[%\?@]/g, function(match) {
return dictUnescape[match];
});
}
exports.factory = function(codec) {
return {
encode: encode6,
decode: decode7
};
function encode6(array) {
if (array === null) {
return "A";
}
if (!Array.isArray(array)) {
throw new Error("can only encode arrays");
}
var l = array.length;
if (l == 0) {
return "K!";
}
var s = encodeItem(array[0]);
for (var i = 1; i < l; i++) {
s += '"' + encodeItem(array[i]);
}
return "K" + s + "!";
}
function encodeItem(item) {
if (typeof item === "object") {
return encode6(item);
}
return escape(codec.encode(item));
}
function decode7(encoded) {
if (encoded === "A") {
return null;
}
if (encoded === "K!") {
return [];
}
var items = encoded.split('"');
var pointers = [[]];
var array;
var depth = 0;
var l = items.length;
for (var i = 0; i < l; i++) {
var item = items[i];
var itemLength = item.length;
var open = 0;
while (item[open] == "K") {
open++;
}
var close = 0;
while (item[itemLength - close - 1] == "!") {
close++;
}
var content = item.slice(open, itemLength - close);
var newdepth = depth + open;
for (var j = depth; j < newdepth; j++) {
pointers[j + 1] = [];
pointers[j].push(pointers[j + 1]);
depth = newdepth;
array = pointers[depth];
}
if (content.length !== 0) {
array.push(codec.decode(unescape(content)));
}
var newdepth = depth - close;
for (var j = newdepth; j < depth; j++) {
pointers[j + 1] = [];
depth = newdepth;
array = pointers[depth];
}
}
return pointers[0][0];
}
};
}
});
// ../../node_modules/.pnpm/charwise@3.0.1/node_modules/charwise/index.js
var require_charwise = __commonJS({
"../../node_modules/.pnpm/charwise@3.0.1/node_modules/charwise/index.js"(exports) {
var number = require_number();
var object = require_object();
var flip = exports.flip = function(n) {
var s = n.toString();
var f = "";
for (var i in s) {
f += s[i] == "." ? "." : 9 - +s[i];
}
return f;
};
exports.number = number;
exports.string = {
encode: function(s) {
if (!/\x00|\x01/.test(s))
return "J" + s;
else {
return "J" + s.replace(/\x01/g, "").replace(/\x00/g, "");
}
},
decode: function(s) {
if ("J" === s[0])
return s.substring(1);
}
};
exports.encode = function(t) {
return exports[typeof t].encode(t);
};
exports.decode = function(s) {
if (s === "")
return s;
if (!decoders[s[0]])
throw new Error("no decoder for:" + JSON.stringify(s));
return decoders[s[0]](s);
};
exports.object = object.factory(exports);
exports.boolean = {
encode: function(b) {
return b ? "C" : "B";
},
decode: function(b) {
return "C" === b;
}
};
exports.undefined = {
encode: function(b) {
return "L";
},
decode: function() {
return void 0;
}
};
var decoders = {
A: exports.object.decode,
//null
B: exports.boolean.decode,
// false
C: exports.boolean.decode,
// true
D: exports.number.decode,
// number
F: exports.number.decode,
// number
// G Date
// H Date
// I Buffer
J: exports.string.decode,
// String
K: exports.object.decode,
// Array
L: exports.undefined.decode
// undefined
};
exports.buffer = false;
exports.type = "charwise";
}
});
// src/index.ts
var src_exports2 = {};
__export(src_exports2, {
Index: () => Index,
index: () => index
});
module.exports = __toCommonJS(src_exports2);
// ../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/vendor/varint.js
var encode_1 = encode;
var MSB = 128;
var REST = 127;
var MSBALL = ~REST;
var INT = Math.pow(2, 31);
function encode(num, out, offset) {
out = out || [];
offset = offset || 0;
var oldOffset = offset;
while (num >= INT) {
out[offset++] = num & 255 | MSB;
num /= 128;
}
while (num & MSBALL) {
out[offset++] = num & 255 | MSB;
num >>>= 7;
}
out[offset] = num | 0;
encode.bytes = offset - oldOffset + 1;
return out;
}
var decode = read;
var MSB$1 = 128;
var REST$1 = 127;
function read(buf2, offset) {
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf2.length;
do {
if (counter >= l) {
read.bytes = 0;
throw new RangeError("Could not decode varint");
}
b = buf2[counter++];
res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
shift += 7;
} while (b >= MSB$1);
read.bytes = counter - offset;
return res;
}
var N1 = Math.pow(2, 7);
var N2 = Math.pow(2, 14);
var N3 = Math.pow(2, 21);
var N4 = Math.pow(2, 28);
var N5 = Math.pow(2, 35);
var N6 = Math.pow(2, 42);
var N7 = Math.pow(2, 49);
var N8 = Math.pow(2, 56);
var N9 = Math.pow(2, 63);
var length = function(value) {
return value < N1 ? 1 : value < N2 ? 2 : value < N3 ? 3 : value < N4 ? 4 : value < N5 ? 5 : value < N6 ? 6 : value < N7 ? 7 : value < N8 ? 8 : value < N9 ? 9 : 10;
};
var varint = {
encode: encode_1,
decode,
encodingLength: length
};
var _brrp_varint = varint;
var varint_default = _brrp_varint;
// ../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/varint.js
var decode2 = (data, offset = 0) => {
const code2 = varint_default.decode(data, offset);
return [code2, varint_default.decode.bytes];
};
var encodeTo = (int, target, offset = 0) => {
varint_default.encode(int, target, offset);
return target;
};
var encodingLength = (int) => {
return varint_default.encodingLength(int);
};
// ../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/bytes.js
var bytes_exports = {};
__export(bytes_exports, {
coerce: () => coerce,
empty: () => empty,
equals: () => equals,
fromHex: () => fromHex,
fromString: () => fromString,
isBinary: () => isBinary,
toHex: () => toHex,
toString: () => toString
});
var empty = new Uint8Array(0);
var toHex = (d) => d.reduce((hex, byte) => hex + byte.toString(16).padStart(2, "0"), "");
var fromHex = (hex) => {
const hexes = hex.match(/../g);
return hexes ? new Uint8Array(hexes.map((b) => parseInt(b, 16))) : empty;
};
var equals = (aa, bb) => {
if (aa === bb)
return true;
if (aa.byteLength !== bb.byteLength) {
return false;
}
for (let ii = 0; ii < aa.byteLength; ii++) {
if (aa[ii] !== bb[ii]) {
return false;
}
}
return true;
};
var coerce = (o) => {
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array")
return o;
if (o instanceof ArrayBuffer)
return new Uint8Array(o);
if (ArrayBuffer.isView(o)) {
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
}
throw new Error("Unknown type, must be binary type");
};
var isBinary = (o) => o instanceof ArrayBuffer || ArrayBuffer.isView(o);
var fromString = (str) => new TextEncoder().encode(str);
var toString = (b) => new TextDecoder().decode(b);
// ../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/hashes/digest.js
var create = (code2, digest) => {
const size = digest.byteLength;
const sizeOffset = encodingLength(code2);
const digestOffset = sizeOffset + encodingLength(size);
const bytes = new Uint8Array(digestOffset + size);
encodeTo(code2, bytes, 0);
encodeTo(size, bytes, sizeOffset);
bytes.set(digest, digestOffset);
return new Digest(code2, size, digest, bytes);
};
var decode3 = (multihash) => {
const bytes = coerce(multihash);
const [code2, sizeOffset] = decode2(bytes);
const [size, digestOffset] = decode2(bytes.subarray(sizeOffset));
const digest = bytes.subarray(sizeOffset + digestOffset);
if (digest.byteLength !== size) {
throw new Error("Incorrect length");
}
return new Digest(code2, size, digest, bytes);
};
var equals2 = (a, b) => {
if (a === b) {
return true;
} else {
const data = (
/** @type {{code?:unknown, size?:unknown, bytes?:unknown}} */
b
);
return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
}
};
var Digest = class {
/**
* Creates a multihash digest.
*
* @param {Code} code
* @param {Size} size
* @param {Uint8Array} digest
* @param {Uint8Array} bytes
*/
constructor(code2, size, digest, bytes) {
this.code = code2;
this.size = size;
this.digest = digest;
this.bytes = bytes;
}
};
// ../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/vendor/base-x.js
function base(ALPHABET, name2) {
if (ALPHABET.length >= 255) {
throw new TypeError("Alphabet too long");
}
var BASE_MAP = new Uint8Array(256);
for (var j = 0; j < BASE_MAP.length; j++) {
BASE_MAP[j] = 255;
}
for (var i = 0; i < ALPHABET.length; i++) {
var x = ALPHABET.charAt(i);
var xc = x.charCodeAt(0);
if (BASE_MAP[xc] !== 255) {
throw new TypeError(x + " is ambiguous");
}
BASE_MAP[xc] = i;
}
var BASE = ALPHABET.length;
var LEADER = ALPHABET.charAt(0);
var FACTOR = Math.log(BASE) / Math.log(256);
var iFACTOR = Math.log(256) / Math.log(BASE);
function encode6(source) {
if (source instanceof Uint8Array)
;
else if (ArrayBuffer.isView(source)) {
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
} else if (Array.isArray(source)) {
source = Uint8Array.from(source);
}
if (!(source instanceof Uint8Array)) {
throw new TypeError("Expected Uint8Array");
}
if (source.length === 0) {
return "";
}
var zeroes = 0;
var length2 = 0;
var pbegin = 0;
var pend = source.length;
while (pbegin !== pend && source[pbegin] === 0) {
pbegin++;
zeroes++;
}
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
var b58 = new Uint8Array(size);
while (pbegin !== pend) {
var carry = source[pbegin];
var i2 = 0;
for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
carry += 256 * b58[it1] >>> 0;
b58[it1] = carry % BASE >>> 0;
carry = carry / BASE >>> 0;
}
if (carry !== 0) {
throw new Error("Non-zero carry");
}
length2 = i2;
pbegin++;
}
var it2 = size - length2;
while (it2 !== size && b58[it2] === 0) {
it2++;
}
var str = LEADER.repeat(zeroes);
for (; it2 < size; ++it2) {
str += ALPHABET.charAt(b58[it2]);
}
return str;
}
function decodeUnsafe(source) {
if (typeof source !== "string") {
throw new TypeError("Expected String");
}
if (source.length === 0) {
return new Uint8Array();
}
var psz = 0;
if (source[psz] === " ") {
return;
}
var zeroes = 0;
var length2 = 0;
while (source[psz] === LEADER) {
zeroes++;
psz++;
}
var size = (source.length - psz) * FACTOR + 1 >>> 0;
var b256 = new Uint8Array(size);
while (source[psz]) {
var carry = BASE_MAP[source.charCodeAt(psz)];
if (carry === 255) {
return;
}
var i2 = 0;
for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
carry += BASE * b256[it3] >>> 0;
b256[it3] = carry % 256 >>> 0;
carry = carry / 256 >>> 0;
}
if (carry !== 0) {
throw new Error("Non-zero carry");
}
length2 = i2;
psz++;
}
if (source[psz] === " ") {
return;
}
var it4 = size - length2;
while (it4 !== size && b256[it4] === 0) {
it4++;
}
var vch = new Uint8Array(zeroes + (size - it4));
var j2 = zeroes;
while (it4 !== size) {
vch[j2++] = b256[it4++];
}
return vch;
}
function decode7(string) {
var buffer2 = decodeUnsafe(string);
if (buffer2) {
return buffer2;
}
throw new Error(`Non-${name2} character`);
}
return {
encode: encode6,
decodeUnsafe,
decode: decode7
};
}
var src = base;
var _brrp__multiformats_scope_baseX = src;
var base_x_default = _brrp__multiformats_scope_baseX;
// ../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/bases/base.js
var Encoder = class {
/**
* @param {Base} name
* @param {Prefix} prefix
* @param {(bytes:Uint8Array) => string} baseEncode
*/
constructor(name2, prefix, baseEncode) {
this.name = name2;
this.prefix = prefix;
this.baseEncode = baseEncode;
}
/**
* @param {Uint8Array} bytes
* @returns {API.Multibase<Prefix>}
*/
encode(bytes) {
if (bytes instanceof Uint8Array) {
return `${this.prefix}${this.baseEncode(bytes)}`;
} else {
throw Error("Unknown type, must be binary type");
}
}
};
var Decoder = class {
/**
* @param {Base} name
* @param {Prefix} prefix
* @param {(text:string) => Uint8Array} baseDecode
*/
constructor(name2, prefix, baseDecode) {
this.name = name2;
this.prefix = prefix;
if (prefix.codePointAt(0) === void 0) {
throw new Error("Invalid prefix character");
}
this.prefixCodePoint = /** @type {number} */
prefix.codePointAt(0);
this.baseDecode = baseDecode;
}
/**
* @param {string} text
*/
decode(text) {
if (typeof text === "string") {
if (text.codePointAt(0) !== this.prefixCodePoint) {
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
}
return this.baseDecode(text.slice(this.prefix.length));
} else {
throw Error("Can only multibase decode strings");
}
}
/**
* @template {string} OtherPrefix
* @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
* @returns {ComposedDecoder<Prefix|OtherPrefix>}
*/
or(decoder) {
return or(this, decoder);
}
};
var ComposedDecoder = class {
/**
* @param {Decoders<Prefix>} decoders
*/
constructor(decoders) {
this.decoders = decoders;
}
/**
* @template {string} OtherPrefix
* @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder
* @returns {ComposedDecoder<Prefix|OtherPrefix>}
*/
or(decoder) {
return or(this, decoder);
}
/**
* @param {string} input
* @returns {Uint8Array}
*/
decode(input) {
const prefix = (
/** @type {Prefix} */
input[0]
);
const decoder = this.decoders[prefix];
if (decoder) {
return decoder.decode(input);
} else {
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
}
}
};
var or = (left, right) => new ComposedDecoder(
/** @type {Decoders<L|R>} */
{
...left.decoders || { [
/** @type API.UnibaseDecoder<L> */
left.prefix
]: left },
...right.decoders || { [
/** @type API.UnibaseDecoder<R> */
right.prefix
]: right }
}
);
var Codec = class {
/**
* @param {Base} name
* @param {Prefix} prefix
* @param {(bytes:Uint8Array) => string} baseEncode
* @param {(text:string) => Uint8Array} baseDecode
*/
constructor(name2, prefix, baseEncode, baseDecode) {
this.name = name2;
this.prefix = prefix;
this.baseEncode = baseEncode;
this.baseDecode = baseDecode;
this.encoder = new Encoder(name2, prefix, baseEncode);
this.decoder = new Decoder(name2, prefix, baseDecode);
}
/**
* @param {Uint8Array} input
*/
encode(input) {
return this.encoder.encode(input);
}
/**
* @param {string} input
*/
decode(input) {
return this.decoder.decode(input);
}
};
var from = ({ name: name2, prefix, encode: encode6, decode: decode7 }) => new Codec(name2, prefix, encode6, decode7);
var baseX = ({ prefix, name: name2, alphabet }) => {
const { encode: encode6, decode: decode7 } = base_x_default(alphabet, name2);
return from({
prefix,
name: name2,
encode: encode6,
/**
* @param {string} text
*/
decode: (text) => coerce(decode7(text))
});
};
var decode4 = (string, alphabet, bitsPerChar, name2) => {
const codes = {};
for (let i = 0; i < alphabet.length; ++i) {
codes[alphabet[i]] = i;
}
let end = string.length;
while (string[end - 1] === "=") {
--end;
}
const out = new Uint8Array(end * bitsPerChar / 8 | 0);
let bits = 0;
let buffer2 = 0;
let written = 0;
for (let i = 0; i < end; ++i) {
const value = codes[string[i]];
if (value === void 0) {
throw new SyntaxError(`Non-${name2} character`);
}
buffer2 = buffer2 << bitsPerChar | value;
bits += bitsPerChar;
if (bits >= 8) {
bits -= 8;
out[written++] = 255 & buffer2 >> bits;
}
}
if (bits >= bitsPerChar || 255 & buffer2 << 8 - bits) {
throw new SyntaxError("Unexpected end of data");
}
return out;
};
var encode2 = (data, alphabet, bitsPerChar) => {
const pad = alphabet[alphabet.length - 1] === "=";
const mask = (1 << bitsPerChar) - 1;
let out = "";
let bits = 0;
let buffer2 = 0;
for (let i = 0; i < data.length; ++i) {
buffer2 = buffer2 << 8 | data[i];
bits += 8;
while (bits > bitsPerChar) {
bits -= bitsPerChar;
out += alphabet[mask & buffer2 >> bits];
}
}
if (bits) {
out += alphabet[mask & buffer2 << bitsPerChar - bits];
}
if (pad) {
while (out.length * bitsPerChar & 7) {
out += "=";
}
}
return out;
};
var rfc4648 = ({ name: name2, prefix, bitsPerChar, alphabet }) => {
return from({
prefix,
name: name2,
encode(input) {
return encode2(input, alphabet, bitsPerChar);
},
decode(input) {
return decode4(input, alphabet, bitsPerChar, name2);
}
});
};
// ../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/bases/base58.js
var base58btc = baseX({
name: "base58btc",
prefix: "z",
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
});
var base58flickr = baseX({
name: "base58flickr",
prefix: "Z",
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
});
// ../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/bases/base32.js
var base32 = rfc4648({
prefix: "b",
name: "base32",
alphabet: "abcdefghijklmnopqrstuvwxyz234567",
bitsPerChar: 5
});
var base32upper = rfc4648({
prefix: "B",
name: "base32upper",
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
bitsPerChar: 5
});
var base32pad = rfc4648({
prefix: "c",
name: "base32pad",
alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
bitsPerChar: 5
});
var base32padupper = rfc4648({
prefix: "C",
name: "base32padupper",
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
bitsPerChar: 5
});
var base32hex = rfc4648({
prefix: "v",
name: "base32hex",
alphabet: "0123456789abcdefghijklmnopqrstuv",
bitsPerChar: 5
});
var base32hexupper = rfc4648({
prefix: "V",
name: "base32hexupper",
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
bitsPerChar: 5
});
var base32hexpad = rfc4648({
prefix: "t",
name: "base32hexpad",
alphabet: "0123456789abcdefghijklmnopqrstuv=",
bitsPerChar: 5
});
var base32hexpadupper = rfc4648({
prefix: "T",
name: "base32hexpadupper",
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
bitsPerChar: 5
});
var base32z = rfc4648({
prefix: "h",
name: "base32z",
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
bitsPerChar: 5
});
// ../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/cid.js
var format = (link, base2) => {
const { bytes, version } = link;
switch (version) {
case 0:
return toStringV0(
bytes,
baseCache(link),
/** @type {API.MultibaseEncoder<"z">} */
base2 || base58btc.encoder
);
default:
return toStringV1(
bytes,
baseCache(link),
/** @type {API.MultibaseEncoder<Prefix>} */
base2 || base32.encoder
);
}
};
var cache = /* @__PURE__ */ new WeakMap();
var baseCache = (cid) => {
const baseCache2 = cache.get(cid);
if (baseCache2 == null) {
const baseCache3 = /* @__PURE__ */ new Map();
cache.set(cid, baseCache3);
return baseCache3;
}
return baseCache2;
};
var CID = class _CID {
/**
* @param {Version} version - Version of the CID
* @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
* @param {API.MultihashDigest<Alg>} multihash - (Multi)hash of the of the content.
* @param {Uint8Array} bytes
*
*/
constructor(version, code2, multihash, bytes) {
this.code = code2;
this.version = version;
this.multihash = multihash;
this.bytes = bytes;
this["/"] = bytes;
}
/**
* Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
* please either use `CID.asCID(cid)` or switch to new signalling mechanism
*
* @deprecated
*/
get asCID() {
return this;
}
// ArrayBufferView
get byteOffset() {
return this.bytes.byteOffset;
}
// ArrayBufferView
get byteLength() {
return this.bytes.byteLength;
}
/**
* @returns {CID<Data, API.DAG_PB, API.SHA_256, 0>}
*/
toV0() {
switch (this.version) {
case 0: {
return (
/** @type {CID<Data, API.DAG_PB, API.SHA_256, 0>} */
this
);
}
case 1: {
const { code: code2, multihash } = this;
if (code2 !== DAG_PB_CODE) {
throw new Error("Cannot convert a non dag-pb CID to CIDv0");
}
if (multihash.code !== SHA_256_CODE) {
throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
}
return (
/** @type {CID<Data, API.DAG_PB, API.SHA_256, 0>} */
_CID.createV0(
/** @type {API.MultihashDigest<API.SHA_256>} */
multihash
)
);
}
default: {
throw Error(
`Can not convert CID version ${this.version} to version 0. This is a bug please report`
);
}
}
}
/**
* @returns {CID<Data, Format, Alg, 1>}
*/
toV1() {
switch (this.version) {
case 0: {
const { code: code2, digest } = this.multihash;
const multihash = create(code2, digest);
return (
/** @type {CID<Data, Format, Alg, 1>} */
_CID.createV1(this.code, multihash)
);
}
case 1: {
return (
/** @type {CID<Data, Format, Alg, 1>} */
this
);
}
default: {
throw Error(
`Can not convert CID version ${this.version} to version 1. This is a bug please report`
);
}
}
}
/**
* @param {unknown} other
* @returns {other is CID<Data, Format, Alg, Version>}
*/
equals(other) {
return _CID.equals(this, other);
}
/**
* @template {unknown} Data
* @template {number} Format
* @template {number} Alg
* @template {API.Version} Version
* @param {API.Link<Data, Format, Alg, Version>} self
* @param {unknown} other
* @returns {other is CID}
*/
static equals(self, other) {
const unknown = (
/** @type {{code?:unknown, version?:unknown, multihash?:unknown}} */
other
);
return unknown && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
}
/**
* @param {API.MultibaseEncoder<string>} [base]
* @returns {string}
*/
toString(base2) {
return format(this, base2);
}
toJSON() {
return { "/": format(this) };
}
link() {
return this;
}
get [Symbol.toStringTag]() {
return "CID";
}
// Legacy
[Symbol.for("nodejs.util.inspect.custom")]() {
return `CID(${this.toString()})`;
}
/**
* Takes any input `value` and returns a `CID` instance if it was
* a `CID` otherwise returns `null`. If `value` is instanceof `CID`
* it will return value back. If `value` is not instance of this CID
* class, but is compatible CID it will return new instance of this
* `CID` class. Otherwise returns null.
*
* This allows two different incompatible versions of CID library to
* co-exist and interop as long as binary interface is compatible.
*
* @template {unknown} Data
* @template {number} Format
* @template {number} Alg
* @template {API.Version} Version
* @template {unknown} U
* @param {API.Link<Data, Format, Alg, Version>|U} input
* @returns {CID<Data, Format, Alg, Version>|null}
*/
static asCID(input) {
if (input == null) {
return null;
}
const value = (
/** @type {any} */
input
);
if (value instanceof _CID) {
return value;
} else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
const { version, code: code2, multihash, bytes } = value;
return new _CID(
version,
code2,
/** @type {API.MultihashDigest<Alg>} */
multihash,
bytes || encodeCID(version, code2, multihash.bytes)
);
} else if (value[cidSymbol] === true) {
const { version, multihash, code: code2 } = value;
const digest = (
/** @type {API.MultihashDigest<Alg>} */
decode3(multihash)
);
return _CID.create(version, code2, digest);
} else {
return null;
}
}
/**
*
* @template {unknown} Data
* @template {number} Format
* @template {number} Alg
* @template {API.Version} Version
* @param {Version} version - Version of the CID
* @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
* @param {API.MultihashDigest<Alg>} digest - (Multi)hash of the of the content.
* @returns {CID<Data, Format, Alg, Version>}
*/
static create(version, code2, digest) {
if (typeof code2 !== "number") {
throw new Error("String codecs are no longer supported");
}
if (!(digest.bytes instanceof Uint8Array)) {
throw new Error("Invalid digest");
}
switch (version) {
case 0: {
if (code2 !== DAG_PB_CODE) {
throw new Error(
`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`
);
} else {
return new _CID(version, code2, digest, digest.bytes);
}
}
case 1: {
const bytes = encodeCID(version, code2, digest.bytes);
return new _CID(version, code2, digest, bytes);
}
default: {
throw new Error("Invalid version");
}
}
}
/**
* Simplified version of `create` for CIDv0.
*
* @template {unknown} [T=unknown]
* @param {API.MultihashDigest<typeof SHA_256_CODE>} digest - Multihash.
* @returns {CID<T, typeof DAG_PB_CODE, typeof SHA_256_CODE, 0>}
*/
static createV0(digest) {
return _CID.create(0, DAG_PB_CODE, digest);
}
/**
* Simplified version of `create` for CIDv1.
*
* @template {unknown} Data
* @template {number} Code
* @template {number} Alg
* @param {Code} code - Content encoding format code.
* @param {API.MultihashDigest<Alg>} digest - Miltihash of the content.
* @returns {CID<Data, Code, Alg, 1>}
*/
static createV1(code2, digest) {
return _CID.create(1, code2, digest);
}
/**
* Decoded a CID from its binary representation. The byte array must contain
* only the CID with no additional bytes.
*
* An error will be thrown if the bytes provided do not contain a valid
* binary representation of a CID.
*
* @template {unknown} Data
* @template {number} Code
* @template {number} Alg
* @template {API.Version} Ver
* @param {API.ByteView<API.Link<Data, Code, Alg, Ver>>} bytes
* @returns {CID<Data, Code, Alg, Ver>}
*/
static decode(bytes) {
const [cid, remainder] = _CID.decodeFirst(bytes);
if (remainder.length) {
throw new Error("Incorrect length");
}
return cid;
}
/**
* Decoded a CID from its binary representation at the beginning of a byte
* array.
*
* Returns an array with the first element containing the CID and the second
* element containing the remainder of the original byte array. The remainder
* will be a zero-length byte array if the provided bytes only contained a
* binary CID representation.
*
* @template {unknown} T
* @template {number} C
* @template {number} A
* @template {API.Version} V
* @param {API.ByteView<API.Link<T, C, A, V>>} bytes
* @returns {[CID<T, C, A, V>, Uint8Array]}
*/
static decodeFirst(bytes) {
const specs = _CID.inspectBytes(bytes);
const prefixSize = specs.size - specs.multihashSize;
const multihashBytes = coerce(
bytes.subarray(prefixSize, prefixSize + specs.multihashSize)
);
if (multihashBytes.byteLength !== specs.multihashSize) {
throw new Error("Incorrect length");
}
const digestBytes = multihashBytes.subarray(
specs.multihashSize - specs.digestSize
);
const digest = new Digest(
specs.multihashCode,
specs.digestSize,
digestBytes,
multihashBytes
);
const cid = specs.version === 0 ? _CID.createV0(
/** @type {API.MultihashDigest<API.SHA_256>} */
digest
) : _CID.createV1(specs.codec, digest);
return [
/** @type {CID<T, C, A, V>} */
cid,
bytes.subarray(specs.size)
];
}
/**
* Inspect the initial bytes of a CID to determine its properties.
*
* Involves decoding up to 4 varints. Typically this will require only 4 to 6
* bytes but for larger multicodec code values and larger multihash digest
* lengths these varints can be quite large. It is recommended that at least
* 10 bytes be made available in the `initialBytes` argument for a complete
* inspection.
*
* @template {unknown} T
* @template {number} C
* @template {number} A
* @template {API.Version} V
* @param {API.ByteView<API.Link<T, C, A, V>>} initialBytes
* @returns {{ version:V, codec:C, multihashCode:A, digestSize:number, multihashSize:number, size:number }}
*/
static inspectBytes(initialBytes) {
let offset = 0;
const next = () => {
const [i, length2] = decode2(initialBytes.subarray(offset));
offset += length2;
return i;
};
let version = (
/** @type {V} */
next()
);
let codec = (
/** @type {C} */
DAG_PB_CODE
);
if (
/** @type {number} */
version === 18
) {
version = /** @type {V} */
0;
offset = 0;
} else {
codec = /** @type {C} */
next();
}
if (version !== 0 && version !== 1) {
throw new RangeError(`Invalid CID version ${version}`);
}
const prefixSize = offset;
const multihashCode = (
/** @type {A} */
next()
);
const digestSize = next();
const size = offset + digestSize;
const multihashSize = size - prefixSize;
return { version, codec, multihashCode, digestSize, multihashSize, size };
}
/**
* Takes cid in a string representation and creates an instance. If `base`
* decoder is not provided will use a default from the configuration. It will
* throw an error if encoding of the CID is not compatible with supplied (or
* a default decoder).
*
* @template {string} Prefix
* @template {unknown} Data
* @template {number} Code
* @template {number} Alg
* @template {API.Version} Ver
* @param {API.ToString<API.Link<Data, Code, Alg, Ver>, Prefix>} source
* @param {API.MultibaseDecoder<Prefix>} [base]
* @returns {CID<Data, Code, Alg, Ver>}
*/
static parse(source, base2) {
const [prefix, bytes] = parseCIDtoBytes(source, base2);
const cid = _CID.decode(bytes);
if (cid.version === 0 && source[0] !== "Q") {
throw Error("Version 0 CID string must not include multibase prefix");
}
baseCache(cid).set(prefix, source);
return cid;
}
};
var parseCIDtoBytes = (source, base2) => {
switch (source[0]) {
case "Q": {
const decoder = base2 || base58btc;
return [
/** @type {Prefix} */
base58btc.prefix,
decoder.decode(`${base58btc.prefix}${source}`)
];
}
case base58btc.prefix: {
const decoder = base2 || base58btc;
return [
/** @type {Prefix} */
base58btc.prefix,
decoder.decode(source)
];
}
case base32.prefix: {
const decoder = base2 || base32;
return [
/** @type {Prefix} */
base32.prefix,
decoder.decode(source)
];
}
default: {
if (base2 == null) {
throw Error(
"To parse non base32 or base58btc encoded CID multibase decoder must be provided"
);
}
return [
/** @type {Prefix} */
source[0],
base2.decode(source)
];
}
}
};
var toStringV0 = (bytes, cache2, base2) => {
const { prefix } = base2;
if (prefix !== base58btc.prefix) {
throw Error(`Cannot string encode V0 in ${base2.name} encoding`);
}
const cid = cache2.get(prefix);
if (cid == null) {
const cid2 = base2.encode(bytes).slice(1);
cache2.set(prefix, cid2);
return cid2;
} else {
return cid;
}
};
var toStringV1 = (bytes, cache2, base2) => {
const { prefix } = base2;
const cid = cache2.get(prefix);
if (cid == null) {
const cid2 = base2.encode(bytes);
cache2.set(prefix, cid2);
return cid2;
} else {
return cid;
}
};
var DAG_PB_CODE = 112;
var SHA_256_CODE = 18;
var encodeCID = (version, code2, multihash) => {
const codeOffset = encodingLength(version);
const hashOffset = codeOffset + encodingLength(code2);
const bytes = new Uint8Array(hashOffset + multihash.byteLength);
encodeTo(version, bytes, 0);
encodeTo(code2, bytes, codeOffset);
bytes.set(multihash, hashOffset);
return bytes;
};
var cidSymbol = Symbol.for("@ipld/js-cid/CID");
// ../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/hashes/hasher.js
var from2 = ({ name: name2, code: code2, encode: encode6 }) => new Hasher(name2, code2, encode6);
var Hasher = class {
/**
*
* @param {Name} name
* @param {Code} code
* @param {(input: Uint8Array) => Await<Uint8Array>} encode
*/
constructor(name2, code2, encode6) {
this.name = name2;
this.code = code2;
this.encode = encode6;
}
/**
* @param {Uint8Array} input
* @returns {Await<Digest.Digest<Code, number>>}
*/
digest(input) {
if (input instanceof Uint8Array) {
const result = this.encode(input);
return result instanceof Uint8Array ? create(this.code, result) : result.then((digest) => create(this.code, digest));
} else {
throw Error("Unknown type, must be binary type");
}
}
};
// ../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/block.js
function readonly({ enumerable = true, configurable = false } = {}) {
return { enumerable, configurable, writable: false };
}
function* linksWithin(path, value) {
if (value != null && typeof value === "object") {
if (Array.isArray(value)) {
for (const [index2, element] of value.entries()) {
const elementPath = [...path, index2];
const cid = CID.asCID(element);
if (cid) {
yield [elementPath.join("/"), cid];
} else if (typeof element === "object") {
yield* links(element, elementPath);
}
}
} else {
const cid = CID.asCID(value);
if (cid) {
yield [path.join("/"), cid];
} else {
yield* links(value, path);
}
}
}
}
function* links(source, base2) {
if (source == null || source instanceof Uint8Array) {
return;
}
const cid = CID.asCID(source);
if (cid) {
yield [base2.join("/"), cid];
}
for (const [key, value] of Object.entries(source)) {
const path = (
/** @type {[string|number, string]} */
[...base2, key]
);
yield* linksWithin(path, value);
}
}
function* treeWithin(path, value) {
if (Array.isArray(value)) {
for (const [index2, element] of value.entries()) {
const elementPath = [...path, index2];
yield elementPath.join("/");
if (typeof element === "object" && !CID.asCID(element)) {
yield* tree(element, elementPath);
}
}
} else {
yield* tree(value, path);
}
}
function* tree(source, base2) {
if (source == null || typeof source !== "object") {
return;
}
for (const [key, value] of Object.entries(source)) {
const path = (
/** @type {[string|number, string]} */
[...base2, key]
);
yield path.join("/");
if (value != null && !(value instanceof Uint8Array) && typeof value === "object" && !CID.asCID(value)) {
yield* treeWithin(path, value);
}
}
}
function get(source, path) {
let node = (
/** @type {Record<string, any>} */
source
);
for (const [index2, key] of path.entries()) {
node = node[key];
if (node == null) {
throw new Error(`Object has no property at ${path.slice(0, index2 + 1).map((part) => `[${JSON.stringify(part)}]`).join("")}`);
}
const cid = CID.asCID(node);
if (cid) {
return { value: cid, remaining: path.slice(index2 + 1).join("/") };
}
}
return { value: node };
}
var Block = class {
/**
* @param {object} options
* @param {CID<T, C, A, V>} options.cid
* @param {API.ByteView<T>} options.bytes
* @param {T} options.value
*/
constructor({ cid, bytes, value }) {
if (!cid || !bytes || typeof value === "undefined") {
throw new Error("Missing required argument");
}
this.cid = cid;
this.bytes = bytes;
this.value = value;
this.asBlock = this;
Object.defineProperties(this, {
cid: readonly(),
bytes: readonly(),
value: readonly(),
asBlock: readonly()
});
}
links() {
return links(this.value, []);
}
tree() {
return tree(this.value, []);
}
/**
*
* @param {string} [path]
* @returns {API.BlockCursorView<unknown>}
*/
get(path = "/") {
return get(this.value, path.split("/").filter(Boolean));
}
};
async function encode3({ value, codec, hasher }) {
if (typeof value === "undefined")
throw new Error('Missing required argument "value"');
if (!codec || !hasher)
throw new Error("Missing required argument: codec or hasher");
const bytes = codec.encode(value);
const hash = await hasher.digest(bytes);
const cid = CID.create(
1,
codec.code,
hash
);
return new Block({ value, bytes, cid });
}
function createUnsafe({ bytes, cid, value: maybeValue, codec }) {
const value = maybeValue !== void 0 ? maybeValue : codec && codec.decode(bytes);
if (value === void 0)
throw new Error('Missing required argument, must either provide "value" or "codec"');
return new Block({
// eslint-disable-next-line object-shorthand
cid: (
/** @type {CID<T, Code, Alg, V>} */
cid
),
bytes,
value
});
}
async function create2({ bytes, cid, hasher, codec }) {
if (!bytes)
throw new Error('Missing required argument "bytes"');
if (!hasher)
throw new Error('Missing required argument "hasher"');
const value = codec.decode(bytes);
const hash = await hasher.digest(bytes);
if (!bytes_exports.equals(cid.multihash.bytes, hash.bytes)) {
throw new Error("CID hash does not match bytes");
}
return createUnsafe({
bytes,
cid,
value,
codec
});
}
// ../../node_modules/.pnpm/multiformats@12.0.1/node_modules/multiformats/src/hashes/sha2.js
var import_crypto = __toESM(require("crypto"), 1);
var sha256 = from2({
name: "sha2-256",
code: 18,
encode: (input) => coerce(import_crypto.default.createHash("sha256").update(input).digest())
});
var sha512 = from2({
name: "sha2-512",
code: 19,
encode: (input) => coerce(import_crypto.default.createHash("sha512").update(input).digest())
});
// ../../node_modules/.pnpm/@ipld+dag-cbor@9.0.4/node_modules/@ipld/dag-cbor/src/index.js
var src_exports = {};
__export(src_exports, {
code: () => code,
decode: () => decode6,
encode: () => encode5,
name: () => name
});
// ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/is.js
var typeofs = [
"string",
"number",
"bigint",
"symbol"
];
var objectTypeNames = [
"Function",
"Generator",
"AsyncGenerator",
"GeneratorFunction",
"AsyncGeneratorFunction",
"AsyncFunction",
"Observable",
"Array",
"Buffer",
"Object",
"RegExp",
"Date",
"Error",
"Map",
"Set",
"WeakMap",
"WeakSet",
"ArrayBuffer",
"SharedArrayBuffer",
"DataView",
"Promise",
"URL",
"HTMLElement",
"Int8Array",
"Uint8Array",
"Uint8ClampedArray",
"Int16Array",
"Uint16Array",
"Int32Array",
"Uint32Array",
"Float32Array",
"Float64Array",
"BigInt64Array",
"BigUint64Array"
];
function is(value) {
if (value === null) {
return "null";
}
if (value === void 0) {
return "undefined";
}
if (value === true || value === false) {
return "boolean";
}
const typeOf = typeof value;
if (typeofs.includes(typeOf)) {
return typeOf;
}
if (typeOf === "function") {
return "Function";
}
if (Array.isArray(value)) {
return "Array";
}
if (isBuffer(value)) {
return "Buffer";
}
const objectType = getObjectType(value);
if (objectType) {
return objectType;
}
return "Object";
}
function isBuffer(value) {
return value && value.constructor && value.constructor.isBuffer && value.constructor.isBuffer.call(null, value);
}
function getObjectType(value) {
const objectTypeName = Object.prototype.toString.call(value).slice(8, -1);
if (objectTypeNames.includes(objectTypeName)) {
return objectTypeName;
}
return void 0;
}
// ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/token.js
var Type = class {
constructor(major, name2, terminal) {
this.major = major;
this.majorEncoded = major << 5;
this.name = name2;
this.terminal = terminal;
}
toString() {
return `Type[${this.major}].${this.name}`;
}
compare(typ) {
return this.major < typ.major ? -1 : this.major > typ.major ? 1 : 0;
}
};
Type.uint = new Type(0, "uint", true);
Type.negint = new Type(1, "negint", true);
Type.bytes = new Type(2, "bytes", true);
Type.string = new Type(3, "string", true);
Type.array = new Type(4, "array", false);
Type.map = new Type(5, "map", false);
Type.tag = new Type(6, "tag", false);
Type.float = new Type(7, "float", true);
Type.false = new Type(7, "false", true);
Type.true = new Type(7, "true", true);
Type.null = new Type(7, "null", true);
Type.undefined = new Type(7, "undefined", true);
Type.break = new Type(7, "break", true);
var Token = class {
constructor(type, value, encodedLength) {
this.type = type;
this.value = value;
this.encodedLength = encodedLength;
this.encodedBytes = void 0;
this.byteValue = void 0;
}
toString() {
return `Token[${this.type}].${this.value}`;
}
};
// ../../node_modules/.pnpm/cborg@2.0.4/node_modules/cborg/esm/lib/byte-utils.js
var useBuffer = globalThis.process && !globalThis.process.browser && globalThis.Buffer && typeof globalThis.Buffer.isBuffer === "function";
var textDecoder = new TextDecoder();
var textEncoder = new TextEncoder();
function isBuffer2(buf2) {
return useBuffer && globalThis.Buffer.isBuffer(buf2);
}
function asU8A(buf2) {
if (!(buf2 instanceof Uint8Array)) {
return Uint8Array.from(buf2);
}
return isBuffer2(buf2) ? new Uint8Array(buf2.buffer, buf2.byteOffset, buf2.byteLength) : buf2;
}
var toString2 = useBuffer ? (bytes, start, end) => {
return end - start > 64 ? globalThis.Buffer.from(bytes.subarray(start, end)).toString("utf8") : utf8Slice(bytes, start, end);
} : (bytes, start, end) => {
return end - start > 64 ? textDecoder.decode(bytes.subarray(start, end)) : utf8Slice(bytes, start, end);
};
var fromString2 = useBuffer ? (string) => {
return string.length > 64 ? globalThis.Buffer.from(string) : utf8ToBytes(string);
} : (string) => {
return string.length > 64 ? textEncoder.encode(string) : utf8ToBytes(string);
};
var fromArray = (arr) => {
return Uint8Array.from(arr);
};
var slice = useBuffer ? (bytes, start, end) => {
if (isBuffer2(bytes)) {
return new Uint8Array(bytes.subarray(start, end));
}
return bytes.slice(start, end);
} : (bytes, start, end) => {
return bytes.slice(start, end);
};
var concat = useBuffer ? (chunks, length2) => {
chunks = chunks.map((c) => c instanceof Uint8Array ? c : globalThis.Buffer.from(c));
return asU8A(globalThis.Buffer.concat(chunks, length2));
} : (chunks, length2) => {
const out = new Uint8Array(length2);
let off = 0;
for (let b of chunks) {
if (off + b.length > out.length) {
b = b.subarray(0, out.length - off);
}
out.set(b, off);
off += b.length;
}
return out;
};
var alloc = useBuffer ? (size) => {
return globalThis.Buffer.allocUnsafe(size);
} : (size) => {
return new Uint8Array(size);
};
function compare(b1, b2) {
if (isBuffer2(b1) && isBuffer2(b2)) {
return b1.compare(b2);
}
for (let i = 0; i < b1.length; i++) {
if (b1[i] === b2[i]) {
con