UNPKG

@hashgraphonline/standards-agent-kit

Version:

A modular SDK for building on-chain autonomous agents using Hashgraph Online Standards, including HCS-10 for agent discovery and communication.

1,348 lines 1.26 MB
var fg = Object.defineProperty; var mg = (r, e, t) => e in r ? fg(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t; var On = (r, e, t) => mg(r, typeof e != "symbol" ? e + "" : e, t); import { Client as $r, PrivateKey as Rr, Transaction as Zc, PublicKey as _i, Timestamp as hg, Status as du, AccountUpdateTransaction as gg, AccountCreateTransaction as bg, Hbar as Ja, CustomFixedFee as yg, AccountId as vg, TokenId as wg, KeyList as oo, TopicCreateTransaction as xg, TopicMessageSubmitTransaction as _g, TopicId as Eg, TransferTransaction as Tg } from "@hashgraph/sdk"; import { proto as pu } from "@hashgraph/proto"; import * as co from "fs"; import Wn from "fs"; import * as lo from "path"; import Na from "path"; import * as kg from "crypto"; function Sg(r) { return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r; } var Qr = { exports: {} }, uo, fu; function Ig() { if (fu) return uo; fu = 1; function r(t) { try { return JSON.stringify(t); } catch { return '"[Circular]"'; } } uo = e; function e(t, n, i) { var a = i && i.stringify || r, s = 1; if (typeof t == "object" && t !== null) { var o = n.length + s; if (o === 1) return t; var l = new Array(o); l[0] = a(t); for (var u = 1; u < o; u++) l[u] = a(n[u]); return l.join(" "); } if (typeof t != "string") return t; var c = n.length; if (c === 0) return t; for (var d = "", p = 1 - s, g = -1, f = t && t.length || 0, b = 0; b < f; ) { if (t.charCodeAt(b) === 37 && b + 1 < f) { switch (g = g > -1 ? g : 0, t.charCodeAt(b + 1)) { case 100: // 'd' case 102: if (p >= c || n[p] == null) break; g < b && (d += t.slice(g, b)), d += Number(n[p]), g = b + 2, b++; break; case 105: if (p >= c || n[p] == null) break; g < b && (d += t.slice(g, b)), d += Math.floor(Number(n[p])), g = b + 2, b++; break; case 79: // 'O' case 111: // 'o' case 106: if (p >= c || n[p] === void 0) break; g < b && (d += t.slice(g, b)); var y = typeof n[p]; if (y === "string") { d += "'" + n[p] + "'", g = b + 2, b++; break; } if (y === "function") { d += n[p].name || "<anonymous>", g = b + 2, b++; break; } d += a(n[p]), g = b + 2, b++; break; case 115: if (p >= c) break; g < b && (d += t.slice(g, b)), d += String(n[p]), g = b + 2, b++; break; case 37: g < b && (d += t.slice(g, b)), d += "%", g = b + 2, b++, p--; break; } ++p; } ++b; } return g === -1 ? t : (g < f && (d += t.slice(g)), d); } return uo; } var mu; function Ag() { if (mu) return Qr.exports; mu = 1; const r = Ig(); Qr.exports = c; const e = Z().console || {}, t = { mapHttpRequest: N, mapHttpResponse: N, wrapRequestSerializer: L, wrapResponseSerializer: L, wrapErrorSerializer: L, req: N, res: N, err: T, errWithCause: T }; function n(k, I) { return k === "silent" ? 1 / 0 : I.levels.values[k]; } const i = Symbol("pino.logFuncs"), a = Symbol("pino.hierarchy"), s = { error: "log", fatal: "error", warn: "error", info: "log", debug: "log", trace: "log" }; function o(k, I) { const P = { logger: I, parent: k[a] }; I[a] = P; } function l(k, I, P) { const M = {}; I.forEach((D) => { M[D] = P[D] ? P[D] : e[D] || e[s[D] || "log"] || te; }), k[i] = M; } function u(k, I) { return Array.isArray(k) ? k.filter(function(M) { return M !== "!stdSerializers.err"; }) : k === !0 ? Object.keys(I) : !1; } function c(k) { k = k || {}, k.browser = k.browser || {}; const I = k.browser.transmit; if (I && typeof I.send != "function") throw Error("pino: transmit option must have a send function"); const P = k.browser.write || e; k.browser.write && (k.browser.asObject = !0); const M = k.serializers || {}, D = u(k.browser.serialize, M); let W = k.browser.serialize; Array.isArray(k.browser.serialize) && k.browser.serialize.indexOf("!stdSerializers.err") > -1 && (W = !1); const re = Object.keys(k.customLevels || {}), K = ["error", "fatal", "warn", "info", "debug", "trace"].concat(re); typeof P == "function" && K.forEach(function(ze) { P[ze] = P; }), (k.enabled === !1 || k.browser.disabled) && (k.level = "silent"); const ie = k.level || "info", q = Object.create(P); q.log || (q.log = te), l(q, K, P), o({}, q), Object.defineProperty(q, "levelVal", { get: qe }), Object.defineProperty(q, "level", { get: De, set: bt }); const Y = { transmit: I, serialize: D, asObject: k.browser.asObject, formatters: k.browser.formatters, levels: K, timestamp: R(k), messageKey: k.messageKey || "msg", onChild: k.onChild || te }; q.levels = d(k), q.level = ie, q.setMaxListeners = q.getMaxListeners = q.emit = q.addListener = q.on = q.prependListener = q.once = q.prependOnceListener = q.removeListener = q.removeAllListeners = q.listeners = q.listenerCount = q.eventNames = q.write = q.flush = te, q.serializers = M, q._serialize = D, q._stdErrSerialize = W, q.child = function(...ze) { return Rt.call(this, Y, ...ze); }, I && (q._logEvent = j()); function qe() { return n(this.level, this); } function De() { return this._level; } function bt(ze) { if (ze !== "silent" && !this.levels.values[ze]) throw Error("unknown level " + ze); this._level = ze, f(this, Y, q, "error"), f(this, Y, q, "fatal"), f(this, Y, q, "warn"), f(this, Y, q, "info"), f(this, Y, q, "debug"), f(this, Y, q, "trace"), re.forEach((Ue) => { f(this, Y, q, Ue); }); } function Rt(ze, Ue, Ct) { if (!Ue) throw new Error("missing bindings for child Pino"); Ct = Ct || {}, D && Ue.serializers && (Ct.serializers = Ue.serializers); const Rn = Ct.serializers; if (D && Rn) { var yr = Object.assign({}, M, Rn), Yr = k.browser.serialize === !0 ? Object.keys(yr) : D; delete Ue.serializers, _([Ue], Yr, yr, this._stdErrSerialize); } function hn(vr) { this._childLevel = (vr._childLevel | 0) + 1, this.bindings = Ue, yr && (this.serializers = yr, this._serialize = Yr), I && (this._logEvent = j( [].concat(vr._logEvent.bindings, Ue) )); } hn.prototype = this; const Lt = new hn(this); return o(this, Lt), Lt.child = function(...vr) { return Rt.call(this, ze, ...vr); }, Lt.level = Ct.level || this.level, ze.onChild(Lt), Lt; } return q; } function d(k) { const I = k.customLevels || {}, P = Object.assign({}, c.levels.values, I), M = Object.assign({}, c.levels.labels, p(I)); return { values: P, labels: M }; } function p(k) { const I = {}; return Object.keys(k).forEach(function(P) { I[k[P]] = P; }), I; } c.levels = { values: { fatal: 60, error: 50, warn: 40, info: 30, debug: 20, trace: 10 }, labels: { 10: "trace", 20: "debug", 30: "info", 40: "warn", 50: "error", 60: "fatal" } }, c.stdSerializers = t, c.stdTimeFunctions = Object.assign({}, { nullTime: ce, epochTime: be, unixTime: ke, isoTime: Ae }); function g(k) { const I = []; k.bindings && I.push(k.bindings); let P = k[a]; for (; P.parent; ) P = P.parent, P.logger.bindings && I.push(P.logger.bindings); return I.reverse(); } function f(k, I, P, M) { if (Object.defineProperty(k, M, { value: n(k.level, P) > n(M, P) ? te : P[i][M], writable: !0, enumerable: !0, configurable: !0 }), k[M] === te) { if (!I.transmit) return; const W = I.transmit.level || k.level, re = n(W, P); if (n(M, P) < re) return; } k[M] = y(k, I, P, M); const D = g(k); D.length !== 0 && (k[M] = b(D, k[M])); } function b(k, I) { return function() { return I.apply(this, [...k, ...arguments]); }; } function y(k, I, P, M) { return /* @__PURE__ */ function(D) { return function() { const re = I.timestamp(), K = new Array(arguments.length), ie = Object.getPrototypeOf && Object.getPrototypeOf(this) === e ? e : this; for (var q = 0; q < K.length; q++) K[q] = arguments[q]; var Y = !1; if (I.serialize && (_(K, this._serialize, this.serializers, this._stdErrSerialize), Y = !0), I.asObject || I.formatters ? D.call(ie, x(this, M, K, re, I)) : D.apply(ie, K), I.transmit) { const qe = I.transmit.level || k._level, De = n(qe, P), bt = n(M, P); if (bt < De) return; E(this, { ts: re, methodLevel: M, methodValue: bt, transmitValue: P.levels.values[I.transmit.level || k._level], send: I.transmit.send, val: n(k._level, P) }, K, Y); } }; }(k[i][M]); } function x(k, I, P, M, D) { const { level: W, log: re = (De) => De } = D.formatters || {}, K = P.slice(); let ie = K[0]; const q = {}; if (M && (q.time = M), W) { const De = W(I, k.levels.values[I]); Object.assign(q, De); } else q.level = k.levels.values[I]; let Y = (k._childLevel | 0) + 1; if (Y < 1 && (Y = 1), ie !== null && typeof ie == "object") { for (; Y-- && typeof K[0] == "object"; ) Object.assign(q, K.shift()); ie = K.length ? r(K.shift(), K) : void 0; } else typeof ie == "string" && (ie = r(K.shift(), K)); return ie !== void 0 && (q[D.messageKey] = ie), re(q); } function _(k, I, P, M) { for (const D in k) if (M && k[D] instanceof Error) k[D] = c.stdSerializers.err(k[D]); else if (typeof k[D] == "object" && !Array.isArray(k[D]) && I) for (const W in k[D]) I.indexOf(W) > -1 && W in P && (k[D][W] = P[W](k[D][W])); } function E(k, I, P, M = !1) { const D = I.send, W = I.ts, re = I.methodLevel, K = I.methodValue, ie = I.val, q = k._logEvent.bindings; M || _( P, k._serialize || Object.keys(k.serializers), k.serializers, k._stdErrSerialize === void 0 ? !0 : k._stdErrSerialize ), k._logEvent.ts = W, k._logEvent.messages = P.filter(function(Y) { return q.indexOf(Y) === -1; }), k._logEvent.level.label = re, k._logEvent.level.value = K, D(re, k._logEvent, ie), k._logEvent = j(q); } function j(k) { return { ts: 0, messages: [], bindings: k || [], level: { label: "", value: 0 } }; } function T(k) { const I = { type: k.constructor.name, msg: k.message, stack: k.stack }; for (const P in k) I[P] === void 0 && (I[P] = k[P]); return I; } function R(k) { return typeof k.timestamp == "function" ? k.timestamp : k.timestamp === !1 ? ce : be; } function N() { return {}; } function L(k) { return k; } function te() { } function ce() { return !1; } function be() { return Date.now(); } function ke() { return Math.round(Date.now() / 1e3); } function Ae() { return new Date(Date.now()).toISOString(); } function Z() { function k(I) { return typeof I < "u" && I; } try { return typeof globalThis < "u" || Object.defineProperty(Object.prototype, "globalThis", { get: function() { return delete Object.prototype.globalThis, this.globalThis = this; }, configurable: !0 }), globalThis; } catch { return k(self) || k(window) || k(this) || {}; } } return Qr.exports.default = c, Qr.exports.pino = c, Qr.exports; } var Rg = Ag(); const Cg = /* @__PURE__ */ Sg(Rg), cf = class li { constructor(e = {}) { const t = e.level || "info"; this.moduleContext = e.module || "app"; const n = { level: t, enabled: !e.silent, transport: e.prettyPrint !== !1 ? { target: "pino-pretty", options: { colorize: !0, translateTime: "SYS:standard", ignore: "pid,hostname" } } : void 0 }; this.logger = Cg(n); } static getInstance(e = {}) { const t = e.module || "default"; return li.instances.has(t) || li.instances.set(t, new li(e)), li.instances.get(t); } setLogLevel(e) { this.logger.level = e; } getLevel() { return this.logger.level; } setSilent(e) { e && (this.logger.level = "silent"); } setModule(e) { this.moduleContext = e; } debug(...e) { this.logger.debug({ module: this.moduleContext }, ...e); } info(...e) { this.logger.info({ module: this.moduleContext }, ...e); } warn(...e) { this.logger.warn({ module: this.moduleContext }, ...e); } error(...e) { this.logger.error({ module: this.moduleContext }, ...e); } trace(...e) { this.logger.trace({ module: this.moduleContext }, ...e); } }; cf.instances = /* @__PURE__ */ new Map(); let Se = cf; class Og { constructor() { this.modelViewerLoaded = !1, this.modelViewerLoading = null, this.config = { cdnUrl: "https://kiloscribe.com/api/inscription-cdn/", network: "mainnet", retryAttempts: 3, retryBackoff: 300, debug: !1, showLoadingIndicator: !1, loadingCallbackName: null }, this.configMapping = { hcsCdnUrl: "cdnUrl", hcsNetwork: "network", hcsRetryAttempts: "retryAttempts", hcsRetryBackoff: "retryBackoff", hcsDebug: "debug", hcsShowLoadingIndicator: "showLoadingIndicator", hcsLoadingCallbackName: "loadingCallbackName" }, this.LoadedScripts = {}, this.LoadedWasm = {}, this.LoadedImages = {}, this.LoadedVideos = {}, this.LoadedAudios = {}, this.LoadedAudioUrls = {}, this.LoadedGLBs = {}, this.scriptLoadedEvent = new Event("HCSScriptLoaded"), this.loadQueue = [], this.isProcessingQueue = !1; try { this.logger = Se.getInstance({ module: "HCS-3", level: this.config.debug ? "debug" : "error" }); } catch { this.logger = this.createFallbackLogger(); } } createFallbackLogger() { return { debug: (...t) => this.config.debug && console.debug("[HCS-3]", ...t), info: (...t) => this.config.debug && console.info("[HCS-3]", ...t), warn: (...t) => console.warn("[HCS-3]", ...t), error: (...t) => console.error("[HCS-3]", ...t), setLogLevel: (t) => { this.config.debug = t === "debug"; } }; } log(...e) { if (e.length === 0) this.logger.debug(""); else if (e.length === 1) this.logger.debug(String(e[0])); else { const t = String(e[0]), n = e.slice(1); this.logger.debug(t, n); } } error(...e) { if (e.length === 0) this.logger.error(""); else if (e.length === 1) this.logger.error(String(e[0])); else { const t = String(e[0]), n = e.slice(1); this.logger.error(t, n); } } loadConfigFromHTML() { const e = document.querySelector( "script[data-hcs-config]" ); e && (Object.keys(this.configMapping).forEach((t) => { if (e.dataset[t]) { const n = this.configMapping[t]; let i = e.dataset[t]; i === "true" && (i = !0), i === "false" && (i = !1), !isNaN(Number(i)) && i !== "" && (i = Number(i)), this.config[n] = i; } }), this.logger.setLogLevel(this.config.debug ? "debug" : "error")), this.log("Loaded config:", this.config); } updateLoadingStatus(e, t) { if (this.LoadedScripts[e] !== "loaded" && (this.config.showLoadingIndicator && console.log("[HCS Loading] " + e + " : " + t), this.LoadedScripts[e] = t, this.config.loadingCallbackName && typeof window[this.config.loadingCallbackName] == "function")) { const n = window[this.config.loadingCallbackName]; typeof n == "function" && n(e, t); } } async fetchWithRetry(e, t = this.config.retryAttempts, n = this.config.retryBackoff) { try { const i = await fetch(e); if (!i.ok) throw new Error("HTTP error! status: " + i.status); return i; } catch (i) { if (t > 0) return this.log( "Retrying fetch for " + e + " Attempts left: " + (t - 1) ), await this.sleep(n), this.fetchWithRetry(e, t - 1, n * 2); throw i; } } sleep(e) { return new Promise((t) => setTimeout(t, e)); } isDuplicate(e) { return !!this.LoadedScripts[e]; } async retrieveHCS1Data(e, t = this.config.cdnUrl, n = this.config.network) { const i = n.replace(/['"]+/g, ""); return await (await this.fetchWithRetry( t + e + "?network=" + i )).blob(); } async loadScript(e) { const t = e.getAttribute("data-src"), n = e.getAttribute("data-script-id"), i = t == null ? void 0 : t.split("/").pop(), a = e.getAttribute("type"), s = e.hasAttribute("data-required"), o = e.getAttribute("type") === "module"; if (!this.isDuplicate(i || "")) { this.updateLoadingStatus(n, "loading"); try { const l = e.getAttribute("data-cdn-url") || this.config.cdnUrl, u = e.getAttribute("data-network") || this.config.network, c = await this.retrieveHCS1Data(i, l, u); if (a === "wasm") { const d = await c.arrayBuffer(), p = await WebAssembly.compile(d); this.LoadedWasm[n] = await WebAssembly.instantiate(p, { env: {}, ...e.dataset }), this.updateLoadingStatus(n, "loaded"), window.dispatchEvent(this.scriptLoadedEvent), this.log("Loaded wasm: " + n); } else { const d = await c.text(), p = document.createElement("script"); if (p.textContent = d, p.className = "hcs-inline-script", n && p.setAttribute("data-loaded-script-id", n), o) { p.type = "module"; const g = new Blob([d], { type: "application/javascript" }); p.src = URL.createObjectURL(g); } document.body.appendChild(p), this.updateLoadingStatus(n, "loaded"), window.dispatchEvent(this.scriptLoadedEvent), this.log("Loaded script: " + n), p.onerror = (g) => { if (this.error("Failed to load " + a + ": " + n, g), this.updateLoadingStatus(n, "failed"), s) throw g; }; } } catch (l) { if (this.error("Failed to load " + a + ": " + n, l), this.updateLoadingStatus(n, "failed"), s) throw l; } } } async loadModuleExports(e) { const t = document.querySelector( 'script[data-loaded-script-id="' + e + '"]' ); if (!t) throw new Error("Module script with id " + e + " not found"); const n = t.getAttribute("src"); if (!n) throw new Error("Module script " + e + " has no src attribute"); try { return await import( /* webpackIgnore: true */ n ); } catch (i) { throw this.error("Failed to import module", i), i; } } async loadStylesheet(e) { const t = e.getAttribute("data-src"), n = e.getAttribute("data-script-id"), i = t == null ? void 0 : t.split("/").pop(), a = e.hasAttribute("data-required"); if (!this.isDuplicate(i || "")) { this.updateLoadingStatus(n, "loading"); try { const s = e.getAttribute("data-cdn-url") || this.config.cdnUrl, o = e.getAttribute("data-network") || this.config.network, u = await (await this.retrieveHCS1Data(i, s, o)).text(), c = document.createElement("style"); c.textContent = u, document.head.appendChild(c), this.updateLoadingStatus(n, "loaded"), window.dispatchEvent(this.scriptLoadedEvent), this.log("Loaded and inlined stylesheet: " + n); } catch (s) { if (this.error("Failed to load stylesheet: " + n, s), this.updateLoadingStatus(n, "failed"), a) throw s; } } } async loadImage(e) { const t = e.getAttribute("data-src"), n = t == null ? void 0 : t.split("/").pop(); this.log("Loading image: " + n), this.updateLoadingStatus("Image: " + n, "loaded"); try { const i = e.getAttribute("data-cdn-url") || this.config.cdnUrl, a = e.getAttribute("data-network") || this.config.network, s = await this.retrieveHCS1Data(n, i, a), o = URL.createObjectURL(s); e.src = o, this.LoadedImages[n] = o, this.updateLoadingStatus("Image: " + n, "loaded"), this.log("Loaded image: " + n); } catch (i) { this.error("Failed to load image: " + n, i), this.updateLoadingStatus("Image: " + n, "failed"); } } async loadMedia(e, t) { const n = e.getAttribute("data-src"), i = n == null ? void 0 : n.split("/").pop(); this.log("Loading " + t + ": " + i), this.updateLoadingStatus(t + ": " + i, "loading"); try { const a = e.getAttribute("data-cdn-url") || this.config.cdnUrl, s = e.getAttribute("data-network") || this.config.network, o = await this.retrieveHCS1Data(i, a, s), l = URL.createObjectURL(o); e.src = l, t === "video" ? this.LoadedVideos[i] = l : this.LoadedAudioUrls[i] = l, this.updateLoadingStatus(t + ": " + i, "loaded"), this.log("Loaded " + t + ": " + i); } catch (a) { this.error("Failed to load " + t + ": " + i, a), this.updateLoadingStatus(t + ": " + i, "failed"); } } async loadModelViewer() { return this.modelViewerLoading ? this.modelViewerLoading : this.modelViewerLoaded ? Promise.resolve() : (this.modelViewerLoading = new Promise((e) => { const t = document.createElement("script"); t.setAttribute("data-src", "hcs://1/0.0.7293044"), t.setAttribute("data-script-id", "model-viewer"), t.setAttribute("type", "module"), window.addEventListener( "HCSScriptLoaded", () => { this.modelViewerLoaded = !0, e(); }, { once: !0 } ), this.loadScript(t); }), this.modelViewerLoading); } async loadGLB(e) { var i; await this.loadModelViewer(); const t = e.getAttribute("data-src"), n = t == null ? void 0 : t.split("/").pop(); this.log("Loading GLB: " + n), this.updateLoadingStatus("GLB: " + n, "loading"); try { const a = e.getAttribute("data-cdn-url") || this.config.cdnUrl, s = e.getAttribute("data-network") || this.config.network; let o; e.tagName.toLowerCase() !== "model-viewer" ? (o = document.createElement("model-viewer"), Array.from(e.attributes).forEach((c) => { o.setAttribute(c.name, c.value); }), o.setAttribute("camera-controls", ""), o.setAttribute("auto-rotate", ""), o.setAttribute("ar", ""), (i = e.parentNode) == null || i.replaceChild(o, e)) : o = e; const l = await this.retrieveHCS1Data(n, a, s), u = URL.createObjectURL(l); o.setAttribute("src", u), this.LoadedGLBs[n] = u, this.updateLoadingStatus("GLB: " + n, "loaded"), this.log("Loaded GLB: " + n); } catch (a) { this.error("Failed to load GLB: " + n, a), this.updateLoadingStatus("GLB: " + n, "failed"); } } async loadResource(e, t, n) { return new Promise((i) => { this.loadQueue.push({ element: e, type: t, order: n, resolve: i }), this.processQueue(); }); } async processQueue() { if (!this.isProcessingQueue) { for (this.isProcessingQueue = !0; this.loadQueue.length > 0; ) { const e = this.loadQueue.shift(); try { e.type === "script" ? await this.loadScript(e.element) : e.type === "image" ? await this.loadImage(e.element) : e.type === "video" || e.type === "audio" ? await this.loadMedia(e.element, e.type) : e.type === "glb" ? await this.loadGLB(e.element) : e.type === "css" && await this.loadStylesheet(e.element), e.resolve(); } catch (t) { if (this.error("Error processing queue item:", t), e.type === "script" && e.element.hasAttribute("data-required")) break; } } this.isProcessingQueue = !1; } } async replaceHCSInStyle(e) { let t = e, n = t.indexOf("hcs://"); for (; n !== -1; ) { let i = n; for (; i < t.length && !["'", '"', " ", ")"].includes(t[i]); ) i++; const a = t.substring(n, i), s = a.split("/").pop(); try { const o = this.config.cdnUrl, l = this.config.network, u = await this.retrieveHCS1Data(s, o, l), c = URL.createObjectURL(u); t = t.substring(0, n) + c + t.substring(i), this.LoadedImages[s] = c, this.log("Replaced CSS HCS URL: " + a + " with " + c); } catch (o) { this.error("Failed to load CSS image: " + s, o); } n = t.indexOf("hcs://", n + 1); } return t; } async processInlineStyles() { var n; const e = document.querySelectorAll('[style*="hcs://"]'); this.log( "Found " + e.length + " elements with HCS style references" ); for (const i of Array.from(e)) { const a = i.getAttribute("style"); if (a) { this.log("Processing style: " + a); const s = await this.replaceHCSInStyle(a); a !== s && (i.setAttribute("style", s), this.log("Updated style to: " + s)); } } const t = document.querySelectorAll("style"); for (const i of Array.from(t)) if ((n = i.textContent) != null && n.includes("hcs://")) { const a = await this.replaceHCSInStyle(i.textContent); i.textContent !== a && (i.textContent = a); } } async init() { return this.loadConfigFromHTML(), new Promise((e) => { const t = async () => { const n = document.querySelectorAll( 'script[data-src^="hcs://"]' ), i = document.querySelectorAll( 'img[data-src^="hcs://"], img[src^="hcs://"]' ), a = document.querySelectorAll( 'video[data-src^="hcs://"], video[src^="hcs://"]' ), s = document.querySelectorAll( 'audio[data-src^="hcs://"], audio[src^="hcs://"]' ), o = document.querySelectorAll( 'model-viewer[data-src^="hcs://"]' ), l = document.querySelectorAll( 'link[data-src^="hcs://"]' ); document.querySelectorAll('[src^="hcs://"]').forEach((d) => { const p = d.getAttribute("src"); p && (d.setAttribute("data-src", p), d.removeAttribute("src")); }), await this.processInlineStyles(); const u = []; [ { elements: n, type: "script" }, { elements: i, type: "image" }, { elements: a, type: "video" }, { elements: s, type: "audio" }, { elements: o, type: "glb" }, { elements: l, type: "css" } ].forEach(({ elements: d, type: p }) => { d.forEach((g) => { const f = parseInt(g.getAttribute("data-load-order") || "") || 1 / 0; u.push( this.loadResource(g, p, f) ); }); }), await Promise.all(u); const c = new MutationObserver((d) => { d.forEach((p) => { var g; if (p.addedNodes.forEach((f) => { var b, y, x; if (f.nodeType === Node.ELEMENT_NODE) { const _ = f; if ((b = _.getAttribute("style")) != null && b.includes("hcs://") && this.processInlineStyles(), _.tagName.toLowerCase() === "style" && ((y = _.textContent) != null && y.includes("hcs://")) && this.processInlineStyles(), (x = _.getAttribute("src")) != null && x.startsWith("hcs://")) { const j = _.getAttribute("src"); switch (_.setAttribute("data-src", j), _.removeAttribute("src"), _.tagName.toLowerCase()) { case "img": this.loadResource(_, "image", 1 / 0); break; case "video": this.loadResource(_, "video", 1 / 0); break; case "audio": this.loadResource(_, "audio", 1 / 0); break; case "script": this.loadResource(_, "script", 1 / 0); break; } } _.matches('script[data-src^="hcs://"]') ? this.loadResource(_, "script", 1 / 0) : _.matches('img[data-src^="hcs://"]') ? this.loadResource(_, "image", 1 / 0) : _.matches('video[data-src^="hcs://"]') ? this.loadResource(_, "video", 1 / 0) : _.matches('audio[data-src^="hcs://"]') ? this.loadResource(_, "audio", 1 / 0) : _.matches('model-viewer[data-src^="hcs://"]') ? this.loadResource(_, "glb", 1 / 0) : _.matches('link[data-src^="hcs://"]') && this.loadResource(_, "css", 1 / 0), _.querySelectorAll( '[data-src^="hcs://"], [src^="hcs://"]' ).forEach((j) => { const T = j, R = T.tagName.toLowerCase(), N = T.getAttribute("src"); switch (N != null && N.startsWith("hcs://") && (T.setAttribute("data-src", N), T.removeAttribute("src")), R) { case "script": this.loadResource(T, "script", 1 / 0); break; case "img": this.loadResource(T, "image", 1 / 0); break; case "video": this.loadResource(T, "video", 1 / 0); break; case "audio": this.loadResource(T, "audio", 1 / 0); break; case "model-viewer": this.loadResource(T, "glb", 1 / 0); break; case "link": this.loadResource(T, "css", 1 / 0); break; } }); } }), p.type === "attributes") { const f = p.target; if (p.attributeName === "style" && ((g = f.getAttribute("style")) != null && g.includes("hcs://"))) this.processInlineStyles(); else if (p.attributeName === "src") { const b = f.getAttribute("src"); if (b != null && b.startsWith("hcs://")) { f.setAttribute("data-src", b), f.removeAttribute("src"); const y = f.tagName.toLowerCase(); ["img", "video", "audio"].includes(y) && this.loadResource(f, y, 1 / 0); } } } }); }); document.body ? c.observe(document.body, { childList: !0, subtree: !0, attributes: !0, attributeFilter: ["style", "src", "data-src"] }) : document.addEventListener("DOMContentLoaded", () => { c.observe(document.body, { childList: !0, subtree: !0, attributes: !0, attributeFilter: ["style", "src", "data-src"] }); }), e(); }; document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", t) : t(); }); } async preloadImage(e) { this.log("Loading image:" + e), this.updateLoadingStatus("image: " + e, "loading"); const t = await this.retrieveHCS1Data(e), n = URL.createObjectURL(t); return this.LoadedImages[e] = n, this.updateLoadingStatus("image: " + e, "loaded"), n; } async preloadAudio(e) { const t = document.createElement("audio"); t.setAttribute("data-topic-id", e), t.setAttribute("data-src", "hcs://1/" + e), document.body.appendChild(t), await this.loadMedia(t, "audio"); const n = document.querySelector( 'audio[data-topic-id="' + e + '"]' ); return n ? this.LoadedAudioUrls[e] = n.src : console.error("Failed to preload audio: " + e), this.LoadedAudioUrls[e]; } async playAudio(e, t = 1) { const n = this.LoadedAudioUrls[e]; if (n) { const i = new Audio(n); i.volume = t, this.LoadedAudios[e] = i, i.play().catch((a) => { console.error("Failed to play audio:", a); }), i.addEventListener("ended", () => { i.remove(), delete this.LoadedAudios[e]; }); } else console.error("Audio not preloaded: " + e); } async pauseAudio(e) { var n, i; const t = document.querySelector( 'audio[data-topic-id="' + e + '"]' ); t ? (console.log("found element", t), t.pause(), (n = this.LoadedAudios[e]) == null || n.pause()) : (i = this.LoadedAudios[e]) == null || i.pause(); } async loadAndPlayAudio(e, t = !1, n = 1) { let i = document.querySelector( 'audio[data-topic-id="' + e + '"]' ); if (i) i.volume = n, await i.play(); else { const a = document.createElement("audio"); a.volume = n, t && a.setAttribute("autoplay", "autoplay"), a.setAttribute("data-topic-id", e), a.setAttribute("data-src", "hcs://1/" + e), document.body.appendChild(a), await this.loadMedia(a, "audio"), i = document.querySelector( 'audio[data-topic-id="' + e + '"]' ), t || await i.play(); } } } const $g = typeof window > "u"; $g || (window.HCS = new Og(), window.HCS.init().then(() => { console.log("All HCS resources loaded"), typeof window.HCSReady == "function" && (console.log("Running HCSReady..."), window.HCSReady()); })); function hu(r) { if (!Number.isSafeInteger(r) || r < 0) throw new Error(`Wrong positive integer: ${r}`); } function lf(r, ...e) { if (!(r instanceof Uint8Array)) throw new Error("Expected Uint8Array"); if (e.length > 0 && !e.includes(r.length)) throw new Error(`Expected Uint8Array of length ${e}, not of length=${r.length}`); } function gu(r, e = !0) { if (r.destroyed) throw new Error("Hash instance has been destroyed"); if (e && r.finished) throw new Error("Hash#digest() has already been called"); } function Pg(r, e) { lf(r); const t = e.outputLen; if (r.length < t) throw new Error(`digestInto() expects output buffer of length at least ${t}`); } const _a = /* @__PURE__ */ BigInt(2 ** 32 - 1), bu = /* @__PURE__ */ BigInt(32); function Ng(r, e = !1) { return e ? { h: Number(r & _a), l: Number(r >> bu & _a) } : { h: Number(r >> bu & _a) | 0, l: Number(r & _a) | 0 }; } function jg(r, e = !1) { let t = new Uint32Array(r.length), n = new Uint32Array(r.length); for (let i = 0; i < r.length; i++) { const { h: a, l: s } = Ng(r[i], e); [t[i], n[i]] = [a, s]; } return [t, n]; } const Lg = (r, e, t) => r << t | e >>> 32 - t, Fg = (r, e, t) => e << t | r >>> 32 - t, Mg = (r, e, t) => e << t - 32 | r >>> 64 - t, Dg = (r, e, t) => r << t - 32 | e >>> 64 - t; /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */ const Ug = (r) => r instanceof Uint8Array, Bg = (r) => new Uint32Array(r.buffer, r.byteOffset, Math.floor(r.byteLength / 4)), qg = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68; if (!qg) throw new Error("Non little-endian hardware is not supported"); function zg(r) { if (typeof r != "string") throw new Error(`utf8ToBytes expected string, got ${typeof r}`); return new Uint8Array(new TextEncoder().encode(r)); } function uf(r) { if (typeof r == "string" && (r = zg(r)), !Ug(r)) throw new Error(`expected Uint8Array, got ${typeof r}`); return r; } class Hg { // Safe version that clones internal state clone() { return this._cloneInto(); } } function Zg(r) { const e = (n) => r().update(uf(n)).digest(), t = r(); return e.outputLen = t.outputLen, e.blockLen = t.blockLen, e.create = () => r(), e; } const [df, pf, ff] = [[], [], []], Vg = /* @__PURE__ */ BigInt(0), ei = /* @__PURE__ */ BigInt(1), Gg = /* @__PURE__ */ BigInt(2), Wg = /* @__PURE__ */ BigInt(7), Kg = /* @__PURE__ */ BigInt(256), Jg = /* @__PURE__ */ BigInt(113); for (let r = 0, e = ei, t = 1, n = 0; r < 24; r++) { [t, n] = [n, (2 * t + 3 * n) % 5], df.push(2 * (5 * n + t)), pf.push((r + 1) * (r + 2) / 2 % 64); let i = Vg; for (let a = 0; a < 7; a++) e = (e << ei ^ (e >> Wg) * Jg) % Kg, e & Gg && (i ^= ei << (ei << /* @__PURE__ */ BigInt(a)) - ei); ff.push(i); } const [Xg, Yg] = /* @__PURE__ */ jg(ff, !0), yu = (r, e, t) => t > 32 ? Mg(r, e, t) : Lg(r, e, t), vu = (r, e, t) => t > 32 ? Dg(r, e, t) : Fg(r, e, t); function Qg(r, e = 24) { const t = new Uint32Array(10); for (let n = 24 - e; n < 24; n++) { for (let s = 0; s < 10; s++) t[s] = r[s] ^ r[s + 10] ^ r[s + 20] ^ r[s + 30] ^ r[s + 40]; for (let s = 0; s < 10; s += 2) { const o = (s + 8) % 10, l = (s + 2) % 10, u = t[l], c = t[l + 1], d = yu(u, c, 1) ^ t[o], p = vu(u, c, 1) ^ t[o + 1]; for (let g = 0; g < 50; g += 10) r[s + g] ^= d, r[s + g + 1] ^= p; } let i = r[2], a = r[3]; for (let s = 0; s < 24; s++) { const o = pf[s], l = yu(i, a, o), u = vu(i, a, o), c = df[s]; i = r[c], a = r[c + 1], r[c] = l, r[c + 1] = u; } for (let s = 0; s < 50; s += 10) { for (let o = 0; o < 10; o++) t[o] = r[s + o]; for (let o = 0; o < 10; o++) r[s + o] ^= ~t[(o + 2) % 10] & t[(o + 4) % 10]; } r[0] ^= Xg[n], r[1] ^= Yg[n]; } t.fill(0); } class Fl extends Hg { // NOTE: we accept arguments in bytes instead of bits here. constructor(e, t, n, i = !1, a = 24) { if (super(), this.blockLen = e, this.suffix = t, this.outputLen = n, this.enableXOF = i, this.rounds = a, this.pos = 0, this.posOut = 0, this.finished = !1, this.destroyed = !1, hu(n), 0 >= this.blockLen || this.blockLen >= 200) throw new Error("Sha3 supports only keccak-f1600 function"); this.state = new Uint8Array(200), this.state32 = Bg(this.state); } keccak() { Qg(this.state32, this.rounds), this.posOut = 0, this.pos = 0; } update(e) { gu(this); const { blockLen: t, state: n } = this; e = uf(e); const i = e.length; for (let a = 0; a < i; ) { const s = Math.min(t - this.pos, i - a); for (let o = 0; o < s; o++) n[this.pos++] ^= e[a++]; this.pos === t && this.keccak(); } return this; } finish() { if (this.finished) return; this.finished = !0; const { state: e, suffix: t, pos: n, blockLen: i } = this; e[n] ^= t, (t & 128) !== 0 && n === i - 1 && this.keccak(), e[i - 1] ^= 128, this.keccak(); } writeInto(e) { gu(this, !1), lf(e), this.finish(); const t = this.state, { blockLen: n } = this; for (let i = 0, a = e.length; i < a; ) { this.posOut >= n && this.keccak(); const s = Math.min(n - this.posOut, a - i); e.set(t.subarray(this.posOut, this.posOut + s), i), this.posOut += s, i += s; } return e; } xofInto(e) { if (!this.enableXOF) throw new Error("XOF is not possible for this instance"); return this.writeInto(e); } xof(e) { return hu(e), this.xofInto(new Uint8Array(e)); } digestInto(e) { if (Pg(e, this), this.finished) throw new Error("digest() was already called"); return this.writeInto(e), this.destroy(), e; } digest() { return this.digestInto(new Uint8Array(this.outputLen)); } destroy() { this.destroyed = !0, this.state.fill(0); } _cloneInto(e) { const { blockLen: t, suffix: n, outputLen: i, rounds: a, enableXOF: s } = this; return e || (e = new Fl(t, n, i, s, a)), e.state32.set(this.state32), e.pos = this.pos, e.posOut = this.posOut, e.finished = this.finished, e.rounds = a, e.suffix = n, e.outputLen = i, e.enableXOF = s, e.destroyed = this.destroyed, e; } } const eb = (r, e, t) => Zg(() => new Fl(e, r, t)), tb = /* @__PURE__ */ eb(1, 136, 256 / 8), nb = "6.13.5"; function wu(r, e, t) { for (let n in e) { let i = e[n]; Object.defineProperty(r, n, { enumerable: !0, value: i, writable: !1 }); } } function Er(r) { if (r == null) return "null"; if (Array.isArray(r)) return "[ " + r.map(Er).join(", ") + " ]"; if (r instanceof Uint8Array) { const e = "0123456789abcdef"; let t = "0x"; for (let n = 0; n < r.length; n++) t += e[r[n] >> 4], t += e[r[n] & 15]; return t; } if (typeof r == "object" && typeof r.toJSON == "function") return Er(r.toJSON()); switch (typeof r) { case "boolean": case "symbol": return r.toString(); case "bigint": return BigInt(r).toString(); case "number": return r.toString(); case "string": return JSON.stringify(r); case "object": { const e = Object.keys(r); return e.sort(), "{ " + e.map((t) => `${Er(t)}: ${Er(r[t])}`).join(", ") + " }"; } } return "[ COULD NOT SERIALIZE ]"; } function rb(r, e, t) { let n = r; { const a = []; if (t) { if ("message" in t || "code" in t || "name" in t) throw new Error(`value will overwrite populated values: ${Er(t)}`); for (const s in t) { if (s === "shortMessage") continue; const o = t[s]; a.push(s + "=" + Er(o)); } } a.push(`code=${e}`), a.push(`version=${nb}`), a.length && (r += " (" + a.join(", ") + ")"); } let i; switch (e) { case "INVALID_ARGUMENT": i = new TypeError(r); break; case "NUMERIC_FAULT": case "BUFFER_OVERRUN": i = new RangeError(r); break; default: i = new Error(r); } return wu(i, { code: e }), t && Object.assign(i, t), i.shortMessage == null && wu(i, { shortMessage: n }), i; } function ib(r, e, t, n) { throw rb(e, t, n); } function ab(r, e, t, n) { ib(r, e, "INVALID_ARGUMENT", { argument: t, value: n }); } ["NFD", "NFC", "NFKD", "NFKC"].reduce((r, e) => { try { if ("test".normalize(e) !== "test") throw new Error("bad"); if (e === "NFD" && "é".normalize("NFD") !== "é") throw new Error("broken"); r.push(e); } catch { } return r; }, []); function sb(r, e, t) { if (r instanceof Uint8Array) return r; if (typeof r == "string" && r.match(/^0x(?:[0-9a-f][0-9a-f])*$/i)) { const n = new Uint8Array((r.length - 2) / 2); let i = 2; for (let a = 0; a < n.length; a++) n[a] = parseInt(r.substring(i, i + 2), 16), i += 2; return n; } ab(!1, "invalid BytesLike value", e || "value", r); } function mf(r, e) { return sb(r, e); } const xu = "0123456789abcdef"; function ob(r) { const e = mf(r); let t = "0x"; for (let n = 0; n < e.length; n++) { const i = e[n]; t += xu[(i & 240) >> 4] + xu[i & 15]; } return t; } let hf = !1; const gf = function(r) { return tb(r); }; let bf = gf; function Rs(r) { const e = mf(r, "data"); return ob(bf(e)); } Rs._ = gf; Rs.lock = function() { hf = !0; }; Rs.register = function(r) { if (hf) throw new TypeError("keccak256 is locked"); bf = r; }; Object.freeze(Rs); BigInt(0); BigInt(1); BigInt(0); BigInt(36); (function() { const r = {}; for (let e = 0; e < 36; e++) { const t = "0123456789abcdefghijklmnopqrstuvwxyz"[e]; r[t] = BigInt(e); } return r; })(); BigInt(0); BigInt(1); BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); function ia(r) { const e = /* @__PURE__ */ new Set(); return r.forEach((t) => e.add(t)), Object.freeze(e); } const cb = "external public payable override"; ia(cb.split(" ")); const yf = "constant external internal payable private public pure view override"; ia(yf.split(" ")); const vf = "constructor error event fallback function receive struct"; ia(vf.split(" ")); const wf = "calldata memory storage payable indexed"; ia(wf.split(" ")); const lb = "tuple returns", ub = [vf, wf, lb, yf].join(" "); ia(ub.split(" ")); const mn = /* @__PURE__ */ new Map(); mn.set(0, "GENERIC_PANIC"); mn.set(1, "ASSERT_FALSE"); mn.set(17, "OVERFLOW"); mn.set(18, "DIVIDE_BY_ZERO"); mn.set(33, "ENUM_RANGE_ERROR"); mn.set(34, "BAD_STORAGE_DATA"); mn.set(49, "STACK_UNDERFLOW"); mn.set(50, "ARRAY_RANGE_ERROR"); mn.set(65, "OUT_OF_MEMORY"); mn.set(81, "UNINITIALIZED_FUNCTION_CALL"); var xf = {}, Cs = {}; Cs.byteLength = fb; Cs.toByteArray = hb; Cs.fromByteArray = yb; var ln = [], $t = [], db = typeof Uint8Array < "u" ? Uint8Array : Array, po = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; for (var wr = 0, pb = po.length; wr < pb; ++wr) ln[wr] = po[wr], $t[po.charCodeAt(wr)] = wr; $t[45] = 62; $t[95] = 63; function _f(r) { var e = r.length; if (e % 4 > 0) throw new Error("Invalid string. Length must be a multiple of 4"); var t = r.indexOf("="); t === -1 && (t = e); var n = t === e ? 0 : 4 - t % 4; return [t, n]; } function fb(r) { var e = _f(r), t = e[0], n = e[1]; return (t + n) * 3 / 4 - n; } function mb(r, e, t) { return (e + t) * 3 / 4 - t; } function hb(r) { var e, t = _f(r), n = t[0], i = t[1], a = new db(mb(r, n, i)), s = 0, o = i > 0 ? n - 4 : n, l; for (l = 0; l < o; l += 4) e = $t[r.charCodeAt(l)] << 18 | $t[r.charCodeAt(l + 1)] << 12 | $t[r.charCodeAt(l + 2)] << 6 | $t[r.charCodeAt(l + 3)], a[s++] = e >> 16 & 255, a[s++] = e >> 8 & 255, a[s++] = e & 255; return i === 2 && (e = $t[r.charCodeAt(l)] << 2 | $t[r.charCodeAt(l + 1)] >> 4, a[s++] = e & 255), i === 1 && (e = $t[r.charCodeAt(l)] << 10 | $t[r.charCodeAt(l + 1)] << 4 | $t[r.charCodeAt(l + 2)] >> 2, a[s++] = e >> 8 & 255, a[s++] = e & 255), a; } function gb(r) { return ln[r >> 18 & 63] + ln[r >> 12 & 63] + ln[r >> 6 & 63] + ln[r & 63]; } function bb(r, e, t) { for (var n, i = [], a = e; a < t; a += 3) n = (r[a] << 16 & 16711680) + (r[a + 1] << 8 & 65280) + (r[a + 2] & 255), i.push(gb(n)); return i.join(""); } function yb(r) { for (var e, t = r.length, n = t % 3, i = [], a = 16383, s = 0, o = t - n; s < o; s += a) i.push(bb(r, s, s + a > o ? o : s + a)); return n === 1 ? (e = r[t - 1], i.push( ln[e >> 2] + ln[e << 4 & 63] + "==" )) : n === 2 && (e = (r[t - 2] << 8) + r[t - 1], i.push( ln[e >> 10] + ln[e >> 4 & 63] + ln[e << 2 & 63] + "=" )), i.join(""); } var Ml = {}; /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */ Ml.read = function(r, e, t, n, i) { var a, s, o = i * 8 - n - 1, l = (1 << o) - 1, u = l >> 1, c = -7, d = t ? i - 1 : 0, p = t ? -1 : 1, g = r[e + d]; for (d += p, a = g & (1 << -c) - 1, g >>= -c, c += o; c > 0; a = a * 256 + r[e + d], d += p, c -= 8) ; for (s = a & (1 << -c) - 1, a >>= -c, c += n; c > 0; s = s * 256 + r[e + d], d += p, c -= 8) ; if (a === 0) a = 1 - u; else { if (a === l) return s ? NaN : (g ? -1 : 1) * (1 / 0); s = s + Math.pow(2, n), a = a - u; } return (g ? -1 : 1) * s * Math.pow(2, a - n); }; Ml.write = function(r, e, t, n, i, a) { var s, o, l, u = a * 8 - i - 1, c = (1 << u) - 1, d = c >> 1, p = i === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, g = n ? 0 : a - 1, f = n ? 1 : -1, b = e < 0 || e === 0 && 1 / e < 0 ? 1 : 0; for (e = Math.abs(e), isNaN(e) || e === 1 / 0 ? (o = isNaN(e) ? 1 : 0, s = c) : (s = Math.floor(Math.log(e) / Math.LN2), e * (l = Math.pow(2, -s)) < 1 && (s--, l *= 2), s + d >= 1 ? e += p / l : e += p * Math.pow(2, 1 - d), e * l >= 2 && (s++, l /= 2), s + d >= c ? (o = 0, s = c) : s + d >= 1 ? (o = (e * l - 1) * Math.pow(2, i), s = s + d) : (o = e * Math.pow(2, d - 1) * Math.pow(2, i), s = 0)); i >= 8; r[t + g] = o & 255, g += f, o /= 256, i -= 8) ; for (s = s << i | o, u += i; u > 0; r[t + g] = s & 255, g += f, s /= 256, u -= 8) ; r[t + g - f] |= b * 128; }; /*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh <https://feross.org> * @license MIT */ (function(r) { const e = Cs, t = Ml, n = typeof Symbol == "function" && typeof Symbol.for == "function" ? Symbol.for("nodejs.util.inspect.custom") : null; r.Buffer = c, r.SlowBuffer = T, r.INSPECT_MAX_BYTES = 50; const i = 2147483647; r.kMaxLength = i; const { Uint8Array: a, ArrayBuffer: s, SharedArrayBuffer: o } = globalThis; c.TYPED_ARRAY_SUPPORT = l(), !c.TYPED_ARRAY_SUPPORT && typeof console < "u" && typeof console.error == "function" && console.error( "This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support." ); function l() { try { const v = new a(1), m = { foo: function() { return 42; } }; return Object.setPrototypeOf(m, a.prototype), Object.setPrototypeOf(v, m), v.foo() === 42; } catch { return !1; } } Object.defineProperty(c.prototype, "parent", { enumerable: !0, get: function() { if (c.isBuffer(this)) return this.buffer; } }), Object.defineProperty(c.prototype, "offset", { enumerable: !0, get: function() { if (c.isBuffer(this)) return this.byteOffset; } }); function u(v) { if (v > i) throw new RangeError('The value "' + v + '" is invalid for option "size"'); const m = new a(v); return Object.setPrototypeOf(m, c.prototype), m; } function c(v, m, h) { if (typeof v == "number") { if (typeof m == "string") throw new TypeError( 'The "string" argument must be of type string. Received type number' ); return f(v); } return d(v, m, h); } c.poolSize = 8192; function d(v, m, h) { if (typeof v == "string") return b(v, m); if (s.isView(v)) return x(v); if (v == null) throw new TypeError( "The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof v ); if (Qt(v, s) || v && Qt(v.buffer, s) || typeof o < "u" && (Qt(v, o) || v && Qt(v.buffer, o))) return _(v, m, h); if (typeof v == "number") throw new TypeError( 'The "value" argument must not be of type number. Received type number' ); const w = v.valueOf && v.valueOf(); if (w != null && w !== v) return c.from(w, m, h); const S = E(v); if (S) return S; if (typeof Symbol < "u" &&