UNPKG

@hashgraphonline/standards-sdk

Version:

The Hashgraph Online Standards SDK provides a complete implementation of the Hashgraph Consensus Standards (HCS), giving developers all the tools needed to build applications on Hedera.

20 lines 4.25 MB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).StandardsSDK={})}(this,(function(exports){"use strict";var __defProp3=Object.defineProperty,__typeError=e=>{throw TypeError(e)},__defNormalProp3=(e,t,r)=>t in e?__defProp3(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,__publicField3=(e,t,r)=>__defNormalProp3(e,"symbol"!=typeof t?t+"":t,r),__accessCheck=(e,t,r)=>t.has(e)||__typeError("Cannot "+r),__privateGet=(e,t,r)=>(__accessCheck(e,t,"read from private field"),r?r.call(e):t.get(e)),__privateAdd=(e,t,r)=>t.has(e)?__typeError("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),__privateSet=(e,t,r,n)=>(__accessCheck(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r),__privateMethod=(e,t,r)=>(__accessCheck(e,t,"access private method"),r),__privateWrapper=(e,t,r,n)=>({set _(n){__privateSet(e,t,n,r)},get _(){return __privateGet(e,t,n)}}),_a3,_names,_data,_dataLength,_Writer_instances,writeData_fn,_data2,_offset,_bytesRead,_parent,_maxInflation,_Reader_instances,incrementBytesRead_fn,peekBytes_fn,_options,_offset2,_tokens,_TokenString_instances,subTokenString_fn,_ParamType_instances,walkAsync_fn,_AbiCoder_instances,getCoder_fn,_errors,_events,_functions,_abiCoder,_Interface_instances,getFunction_fn,getEvent_fn;function _mergeNamespaces(e,t){for(var r=0;r<t.length;r++){const n=t[r];if("string"!=typeof n&&!Array.isArray(n))for(const t in n)if("default"!==t&&!(t in e)){const r=Object.getOwnPropertyDescriptor(n,t);r&&Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>n[t]})}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}function getDefaultExportFromCjs$6(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var browser$l={exports:{}},process$5=browser$l.exports={},cachedSetTimeout$4,cachedClearTimeout$4;function defaultSetTimout$4(){throw new Error("setTimeout has not been defined")}function defaultClearTimeout$4(){throw new Error("clearTimeout has not been defined")}function runTimeout$4(e){if(cachedSetTimeout$4===setTimeout)return setTimeout(e,0);if((cachedSetTimeout$4===defaultSetTimout$4||!cachedSetTimeout$4)&&setTimeout)return cachedSetTimeout$4=setTimeout,setTimeout(e,0);try{return cachedSetTimeout$4(e,0)}catch(t){try{return cachedSetTimeout$4.call(null,e,0)}catch(r){return cachedSetTimeout$4.call(this,e,0)}}}function runClearTimeout$4(e){if(cachedClearTimeout$4===clearTimeout)return clearTimeout(e);if((cachedClearTimeout$4===defaultClearTimeout$4||!cachedClearTimeout$4)&&clearTimeout)return cachedClearTimeout$4=clearTimeout,clearTimeout(e);try{return cachedClearTimeout$4(e)}catch(t){try{return cachedClearTimeout$4.call(null,e)}catch(r){return cachedClearTimeout$4.call(this,e)}}}!function(){try{cachedSetTimeout$4="function"==typeof setTimeout?setTimeout:defaultSetTimout$4}catch(e){cachedSetTimeout$4=defaultSetTimout$4}try{cachedClearTimeout$4="function"==typeof clearTimeout?clearTimeout:defaultClearTimeout$4}catch(e){cachedClearTimeout$4=defaultClearTimeout$4}}();var queue$4=[],draining$4=!1,currentQueue$4,queueIndex$4=-1;function cleanUpNextTick$4(){draining$4&&currentQueue$4&&(draining$4=!1,currentQueue$4.length?queue$4=currentQueue$4.concat(queue$4):queueIndex$4=-1,queue$4.length&&drainQueue$4())}function drainQueue$4(){if(!draining$4){var e=runTimeout$4(cleanUpNextTick$4);draining$4=!0;for(var t=queue$4.length;t;){for(currentQueue$4=queue$4,queue$4=[];++queueIndex$4<t;)currentQueue$4&&currentQueue$4[queueIndex$4].run();queueIndex$4=-1,t=queue$4.length}currentQueue$4=null,draining$4=!1,runClearTimeout$4(e)}}function Item$4(e,t){this.fun=e,this.array=t}function noop$9(){}process$5.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];queue$4.push(new Item$4(e,t)),1!==queue$4.length||draining$4||runTimeout$4(drainQueue$4)},Item$4.prototype.run=function(){this.fun.apply(null,this.array)},process$5.title="browser",process$5.browser=!0,process$5.env={},process$5.argv=[],process$5.version="",process$5.versions={},process$5.on=noop$9,process$5.addListener=noop$9,process$5.once=noop$9,process$5.off=noop$9,process$5.removeListener=noop$9,process$5.removeAllListeners=noop$9,process$5.emit=noop$9,process$5.prependListener=noop$9,process$5.prependOnceListener=noop$9,process$5.listeners=function(e){return[]},process$5.binding=function(e){throw new Error("process.binding is not supported")},process$5.cwd=function(){return"/"},process$5.chdir=function(e){throw new Error("process.chdir is not supported")},process$5.umask=function(){return 0};var browserExports$5=browser$l.exports;const process$1$4=getDefaultExportFromCjs$6(browserExports$5);var commonjsGlobal$4="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function getDefaultExportFromCjs$5(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var browser$k={exports:{}},quickFormatUnescaped$3,hasRequiredQuickFormatUnescaped$3,hasRequiredBrowser$h;function requireQuickFormatUnescaped$3(){if(hasRequiredQuickFormatUnescaped$3)return quickFormatUnescaped$3;function e(e){try{return JSON.stringify(e)}catch(t){return'"[Circular]"'}}return hasRequiredQuickFormatUnescaped$3=1,quickFormatUnescaped$3=function(t,r,n){var i=n&&n.stringify||e;if("object"==typeof t&&null!==t){var o=r.length+1;if(1===o)return t;var a=new Array(o);a[0]=i(t);for(var s=1;s<o;s++)a[s]=i(r[s]);return a.join(" ")}if("string"!=typeof t)return t;var c=r.length;if(0===c)return t;for(var u="",l=0,d=-1,p=t&&t.length||0,f=0;f<p;){if(37===t.charCodeAt(f)&&f+1<p){switch(d=d>-1?d:0,t.charCodeAt(f+1)){case 100:case 102:if(l>=c)break;if(null==r[l])break;d<f&&(u+=t.slice(d,f)),u+=Number(r[l]),d=f+2,f++;break;case 105:if(l>=c)break;if(null==r[l])break;d<f&&(u+=t.slice(d,f)),u+=Math.floor(Number(r[l])),d=f+2,f++;break;case 79:case 111:case 106:if(l>=c)break;if(void 0===r[l])break;d<f&&(u+=t.slice(d,f));var h=typeof r[l];if("string"===h){u+="'"+r[l]+"'",d=f+2,f++;break}if("function"===h){u+=r[l].name||"<anonymous>",d=f+2,f++;break}u+=i(r[l]),d=f+2,f++;break;case 115:if(l>=c)break;d<f&&(u+=t.slice(d,f)),u+=String(r[l]),d=f+2,f++;break;case 37:d<f&&(u+=t.slice(d,f)),u+="%",d=f+2,f++,l--}++l}++f}if(-1===d)return t;d<p&&(u+=t.slice(d));return u}}function requireBrowser$h(){if(hasRequiredBrowser$h)return browser$k.exports;hasRequiredBrowser$h=1;const e=requireQuickFormatUnescaped$3();browser$k.exports=c;const t=function(){function e(e){return void 0!==e&&e}try{return"undefined"!=typeof globalThis||Object.defineProperty(Object.prototype,"globalThis",{get:function(){return delete Object.prototype.globalThis,this.globalThis=this},configurable:!0}),globalThis}catch(t){return e(self)||e(window)||e(this)||{}}}().console||{},r={mapHttpRequest:h,mapHttpResponse:h,wrapRequestSerializer:m,wrapResponseSerializer:m,wrapErrorSerializer:m,req:h,res:h,err:p,errWithCause:p};function n(e,t){return"silent"===e?1/0:t.levels.values[e]}const i=Symbol("pino.logFuncs"),o=Symbol("pino.hierarchy"),a={error:"log",fatal:"error",warn:"error",info:"log",debug:"log",trace:"log"};function s(e,t){const r={logger:t,parent:e[o]};t[o]=r}function c(e){(e=e||{}).browser=e.browser||{};const r=e.browser.transmit;if(r&&"function"!=typeof r.send)throw Error("pino: transmit option must have a send function");const o=e.browser.write||t;e.browser.write&&(e.browser.asObject=!0);const p=e.serializers||{},h=function(e,t){if(Array.isArray(e))return e.filter((function(e){return"!stdSerializers.err"!==e}));return!0===e&&Object.keys(t)}(e.browser.serialize,p);let m=e.browser.serialize;Array.isArray(e.browser.serialize)&&e.browser.serialize.indexOf("!stdSerializers.err")>-1&&(m=!1);const y=Object.keys(e.customLevels||{}),b=["error","fatal","warn","info","debug","trace"].concat(y);"function"==typeof o&&b.forEach((function(e){o[e]=o})),(!1===e.enabled||e.browser.disabled)&&(e.level="silent");const v=e.level||"info",w=Object.create(o);w.log||(w.log=g),function(e,r,n){const o={};r.forEach((e=>{o[e]=n[e]?n[e]:t[e]||t[a[e]||"log"]||g})),e[i]=o}(w,b,o),s({},w),Object.defineProperty(w,"levelVal",{get:function(){return n(this.level,this)}}),Object.defineProperty(w,"level",{get:function(){return this._level},set:function(e){if("silent"!==e&&!this.levels.values[e])throw Error("unknown level "+e);this._level=e,u(this,x,w,"error"),u(this,x,w,"fatal"),u(this,x,w,"warn"),u(this,x,w,"info"),u(this,x,w,"debug"),u(this,x,w,"trace"),y.forEach((e=>{u(this,x,w,e)}))}});const x={transmit:r,serialize:h,asObject:e.browser.asObject,asObjectBindingsOnly:e.browser.asObjectBindingsOnly,formatters:e.browser.formatters,levels:b,timestamp:f(e),messageKey:e.messageKey||"msg",onChild:e.onChild||g};function _(t,n,i){if(!n)throw new Error("missing bindings for child Pino");i=i||{},h&&n.serializers&&(i.serializers=n.serializers);const o=i.serializers;if(h&&o){var a=Object.assign({},p,o),c=!0===e.browser.serialize?Object.keys(a):h;delete n.serializers,l([n],c,a,this._stdErrSerialize)}function u(e){this._childLevel=1+(0|e._childLevel),this.bindings=n,a&&(this.serializers=a,this._serialize=c),r&&(this._logEvent=d([].concat(e._logEvent.bindings,n)))}u.prototype=this;const f=new u(this);return s(this,f),f.child=function(...e){return _.call(this,t,...e)},f.level=i.level||this.level,t.onChild(f),f}return w.levels=function(e){const t=e.customLevels||{},r=Object.assign({},c.levels.values,t),n=Object.assign({},c.levels.labels,function(e){const t={};return Object.keys(e).forEach((function(r){t[e[r]]=r})),t}(t));return{values:r,labels:n}}(e),w.level=v,w.isLevelEnabled=function(e){return!!this.levels.values[e]&&this.levels.values[e]>=this.levels.values[this.level]},w.setMaxListeners=w.getMaxListeners=w.emit=w.addListener=w.on=w.prependListener=w.once=w.prependOnceListener=w.removeListener=w.removeAllListeners=w.listeners=w.listenerCount=w.eventNames=w.write=w.flush=g,w.serializers=p,w._serialize=h,w._stdErrSerialize=m,w.child=function(...e){return _.call(this,x,...e)},r&&(w._logEvent=d()),w}function u(r,a,s,c){if(Object.defineProperty(r,c,{value:n(r.level,s)>n(c,s)?g:s[i][c],writable:!0,enumerable:!0,configurable:!0}),r[c]===g){if(!a.transmit)return;const e=n(a.transmit.level||r.level,s);if(n(c,s)<e)return}r[c]=function(r,o,a,s){return function(i){return function(){const c=o.timestamp(),u=new Array(arguments.length),p=Object.getPrototypeOf&&Object.getPrototypeOf(this)===t?t:this;for(var f=0;f<u.length;f++)u[f]=arguments[f];var h=!1;if(o.serialize&&(l(u,this._serialize,this.serializers,this._stdErrSerialize),h=!0),o.asObject||o.formatters?i.call(p,...function(t,r,n,i,o){const{level:a,log:s=e=>e}=o.formatters||{},c=n.slice();let u=c[0];const l={};let d=1+(0|t._childLevel);d<1&&(d=1);i&&(l.time=i);if(a){const e=a(r,t.levels.values[r]);Object.assign(l,e)}else l.level=t.levels.values[r];if(o.asObjectBindingsOnly){if(null!==u&&"object"==typeof u)for(;d--&&"object"==typeof c[0];)Object.assign(l,c.shift());return[s(l),...c]}if(null!==u&&"object"==typeof u){for(;d--&&"object"==typeof c[0];)Object.assign(l,c.shift());u=c.length?e(c.shift(),c):void 0}else"string"==typeof u&&(u=e(c.shift(),c));void 0!==u&&(l[o.messageKey]=u);return[s(l)]}(this,s,u,c,o)):i.apply(p,u),o.transmit){const e=n(o.transmit.level||r._level,a),t=n(s,a);if(t<e)return;!function(e,t,r,n=!1){const i=t.send,o=t.ts,a=t.methodLevel,s=t.methodValue,c=t.val,u=e._logEvent.bindings;n||l(r,e._serialize||Object.keys(e.serializers),e.serializers,void 0===e._stdErrSerialize||e._stdErrSerialize);e._logEvent.ts=o,e._logEvent.messages=r.filter((function(e){return-1===u.indexOf(e)})),e._logEvent.level.label=a,e._logEvent.level.value=s,i(a,e._logEvent,c),e._logEvent=d(u)}(this,{ts:c,methodLevel:s,methodValue:t,transmitValue:a.levels.values[o.transmit.level||r._level],send:o.transmit.send,val:n(r._level,a)},u,h)}}}(r[i][s])}(r,a,s,c);const u=function(e){const t=[];e.bindings&&t.push(e.bindings);let r=e[o];for(;r.parent;)r=r.parent,r.logger.bindings&&t.push(r.logger.bindings);return t.reverse()}(r);0!==u.length&&(r[c]=function(e,t){return function(){return t.apply(this,[...e,...arguments])}}(u,r[c]))}function l(e,t,r,n){for(const i in e)if(n&&e[i]instanceof Error)e[i]=c.stdSerializers.err(e[i]);else if("object"==typeof e[i]&&!Array.isArray(e[i])&&t)for(const n in e[i])t.indexOf(n)>-1&&n in r&&(e[i][n]=r[n](e[i][n]))}function d(e){return{ts:0,messages:[],bindings:e||[],level:{label:"",value:0}}}function p(e){const t={type:e.constructor.name,msg:e.message,stack:e.stack};for(const r in e)void 0===t[r]&&(t[r]=e[r]);return t}function f(e){return"function"==typeof e.timestamp?e.timestamp:!1===e.timestamp?y:b}function h(){return{}}function m(e){return e}function g(){}function y(){return!1}function b(){return Date.now()}return 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=r,c.stdTimeFunctions=Object.assign({},{nullTime:y,epochTime:b,unixTime:function(){return Math.round(Date.now()/1e3)},isoTime:function(){return new Date(Date.now()).toISOString()}}),browser$k.exports.default=c,browser$k.exports.pino=c,browser$k.exports}var browserExports$4=requireBrowser$h();const e$t=getDefaultExportFromCjs$5(browserExports$4);let Logger$5=(_a3=class{constructor(e={}){const t="true"===process$1$4.env.DISABLE_LOGS,r=e.silent||t,n=r?"silent":e.level||"info";this.moduleContext=e.module||"app";const i={level:n,enabled:!r,transport:!r&&!1!==e.prettyPrint?{target:"pino-pretty",options:{colorize:!0,translateTime:"SYS:standard",ignore:"pid,hostname"}}:void 0};this.logger=e$t(i)}static getInstance(e={}){const t=e.module||"default";if("true"===process$1$4.env.DISABLE_LOGS&&_a3.instances.has(t)){"silent"!==_a3.instances.get(t).getLevel()&&_a3.instances.delete(t)}return _a3.instances.has(t)||_a3.instances.set(t,new _a3(e)),_a3.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)}},_a3.instances=new Map,_a3);const sleep$1=e=>new Promise((t=>setTimeout(t,e)));class HCS{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=Logger$5.getInstance({module:"HCS-3",level:this.config.debug?"debug":"error"})}catch(e){this.logger=this.createFallbackLogger()}}createFallbackLogger(){return{debug:(...e)=>this.config.debug&&console.debug("[HCS-3]",...e),info:(...e)=>this.config.debug&&console.info("[HCS-3]",...e),warn:(...e)=>console.warn("[HCS-3]",...e),error:(...e)=>console.error("[HCS-3]",...e),setLogLevel:e=>{this.config.debug="debug"===e}}}log(...e){if(0===e.length)this.logger.debug("");else if(1===e.length)this.logger.debug(String(e[0]));else{const t=String(e[0]),r=e.slice(1);this.logger.debug(t,r)}}error(...e){if(0===e.length)this.logger.error("");else if(1===e.length)this.logger.error(String(e[0]));else{const t=String(e[0]),r=e.slice(1);this.logger.error(t,r)}}loadConfigFromHTML(){const e=document.querySelector("script[data-hcs-config]");e&&(Object.keys(this.configMapping).forEach((t=>{if(e.dataset[t]){const r=this.configMapping[t];let n=e.dataset[t];"true"===n&&(n=!0),"false"===n&&(n=!1),isNaN(Number(n))||""===n||(n=Number(n)),this.config[r]=n}})),this.logger.setLogLevel(this.config.debug?"debug":"error")),this.log("Loaded config:",this.config)}updateLoadingStatus(e,t){if("loaded"!==this.LoadedScripts[e]&&(this.config.showLoadingIndicator&&console.log("[HCS Loading] "+e+" : "+t),this.LoadedScripts[e]=t,this.config.loadingCallbackName&&"function"==typeof window[this.config.loadingCallbackName])){const r=window[this.config.loadingCallbackName];"function"==typeof r&&r(e,t)}}async fetchWithRetry(e,t=this.config.retryAttempts,r=this.config.retryBackoff){try{const t=await fetch(e);if(!t.ok)throw new Error("HTTP error! status: "+t.status);return t}catch(n){if(t>0)return this.log("Retrying fetch for "+e+" Attempts left: "+(t-1)),await this.sleep(r),this.fetchWithRetry(e,t-1,2*r);throw n}}sleep(e){return new Promise((t=>setTimeout(t,e)))}isDuplicate(e){return!!this.LoadedScripts[e]}async retrieveHCS1Data(e,t=this.config.cdnUrl,r=this.config.network){const n=r.replace(/['"]+/g,""),i=await this.fetchWithRetry(t+e+"?network="+n);return await i.blob()}async loadScript(e){const t=e.getAttribute("data-src"),r=e.getAttribute("data-script-id"),n=t?.split("/").pop(),i=e.getAttribute("type"),o=e.hasAttribute("data-required"),a="module"===e.getAttribute("type");if(!this.isDuplicate(n||"")){this.updateLoadingStatus(r,"loading");try{const t=e.getAttribute("data-cdn-url")||this.config.cdnUrl,s=e.getAttribute("data-network")||this.config.network,c=await this.retrieveHCS1Data(n,t,s);if("wasm"===i){const t=await c.arrayBuffer(),n=await WebAssembly.compile(t);this.LoadedWasm[r]=await WebAssembly.instantiate(n,{env:{},...e.dataset}),this.updateLoadingStatus(r,"loaded"),window.dispatchEvent(this.scriptLoadedEvent),this.log("Loaded wasm: "+r)}else{const e=await c.text(),t=document.createElement("script");if(t.textContent=e,t.className="hcs-inline-script",r&&t.setAttribute("data-loaded-script-id",r),a){t.type="module";const r=new Blob([e],{type:"application/javascript"});t.src=URL.createObjectURL(r)}document.body.appendChild(t),this.updateLoadingStatus(r,"loaded"),window.dispatchEvent(this.scriptLoadedEvent),this.log("Loaded script: "+r),t.onerror=e=>{if(this.error("Failed to load "+i+": "+r,e),this.updateLoadingStatus(r,"failed"),o)throw e}}}catch(s){if(this.error("Failed to load "+i+": "+r,s),this.updateLoadingStatus(r,"failed"),o)throw s}}}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 r=t.getAttribute("src");if(!r)throw new Error("Module script "+e+" has no src attribute");try{return await import(r)}catch(n){throw this.error("Failed to import module",n),n}}async loadStylesheet(e){const t=e.getAttribute("data-src"),r=e.getAttribute("data-script-id"),n=t?.split("/").pop(),i=e.hasAttribute("data-required");if(!this.isDuplicate(n||"")){this.updateLoadingStatus(r,"loading");try{const t=e.getAttribute("data-cdn-url")||this.config.cdnUrl,i=e.getAttribute("data-network")||this.config.network,o=await this.retrieveHCS1Data(n,t,i),a=await o.text(),s=document.createElement("style");s.textContent=a,document.head.appendChild(s),this.updateLoadingStatus(r,"loaded"),window.dispatchEvent(this.scriptLoadedEvent),this.log("Loaded and inlined stylesheet: "+r)}catch(o){if(this.error("Failed to load stylesheet: "+r,o),this.updateLoadingStatus(r,"failed"),i)throw o}}}async loadImage(e){const t=e.getAttribute("data-src"),r=t?.split("/").pop();this.log("Loading image: "+r),this.updateLoadingStatus("Image: "+r,"loaded");try{const t=e.getAttribute("data-cdn-url")||this.config.cdnUrl,n=e.getAttribute("data-network")||this.config.network,i=await this.retrieveHCS1Data(r,t,n),o=URL.createObjectURL(i);e.src=o,this.LoadedImages[r]=o,this.updateLoadingStatus("Image: "+r,"loaded"),this.log("Loaded image: "+r)}catch(n){this.error("Failed to load image: "+r,n),this.updateLoadingStatus("Image: "+r,"failed")}}async loadMedia(e,t){const r=e.getAttribute("data-src"),n=r?.split("/").pop();this.log("Loading "+t+": "+n),this.updateLoadingStatus(t+": "+n,"loading");try{const r=e.getAttribute("data-cdn-url")||this.config.cdnUrl,i=e.getAttribute("data-network")||this.config.network,o=await this.retrieveHCS1Data(n,r,i),a=URL.createObjectURL(o);e.src=a,"video"===t?this.LoadedVideos[n]=a:this.LoadedAudioUrls[n]=a,this.updateLoadingStatus(t+": "+n,"loaded"),this.log("Loaded "+t+": "+n)}catch(i){this.error("Failed to load "+t+": "+n,i),this.updateLoadingStatus(t+": "+n,"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){await this.loadModelViewer();const t=e.getAttribute("data-src"),r=t?.split("/").pop();this.log("Loading GLB: "+r),this.updateLoadingStatus("GLB: "+r,"loading");try{const t=e.getAttribute("data-cdn-url")||this.config.cdnUrl,n=e.getAttribute("data-network")||this.config.network;let i;"model-viewer"!==e.tagName.toLowerCase()?(i=document.createElement("model-viewer"),Array.from(e.attributes).forEach((e=>{i.setAttribute(e.name,e.value)})),i.setAttribute("camera-controls",""),i.setAttribute("auto-rotate",""),i.setAttribute("ar",""),e.parentNode?.replaceChild(i,e)):i=e;const o=await this.retrieveHCS1Data(r,t,n),a=URL.createObjectURL(o);i.setAttribute("src",a),this.LoadedGLBs[r]=a,this.updateLoadingStatus("GLB: "+r,"loaded"),this.log("Loaded GLB: "+r)}catch(n){this.error("Failed to load GLB: "+r,n),this.updateLoadingStatus("GLB: "+r,"failed")}}async loadResource(e,t,r){return new Promise((n=>{this.loadQueue.push({element:e,type:t,order:r,resolve:n}),this.processQueue()}))}async processQueue(){if(!this.isProcessingQueue){for(this.isProcessingQueue=!0;this.loadQueue.length>0;){const t=this.loadQueue.shift();try{"script"===t.type?await this.loadScript(t.element):"image"===t.type?await this.loadImage(t.element):"video"===t.type||"audio"===t.type?await this.loadMedia(t.element,t.type):"glb"===t.type?await this.loadGLB(t.element):"css"===t.type&&await this.loadStylesheet(t.element),t.resolve()}catch(e){if(this.error("Error processing queue item:",e),"script"===t.type&&t.element.hasAttribute("data-required"))break}}this.isProcessingQueue=!1}}async replaceHCSInStyle(e){let t=e,r=t.indexOf("hcs://");for(;-1!==r;){let e=r;for(;e<t.length&&!["'",'"'," ",")"].includes(t[e]);)e++;const i=t.substring(r,e),o=i.split("/").pop();try{const n=this.config.cdnUrl,a=this.config.network,s=await this.retrieveHCS1Data(o,n,a),c=URL.createObjectURL(s);t=t.substring(0,r)+c+t.substring(e),this.LoadedImages[o]=c,this.log("Replaced CSS HCS URL: "+i+" with "+c)}catch(n){this.error("Failed to load CSS image: "+o,n)}r=t.indexOf("hcs://",r+1)}return t}async processInlineStyles(){const e=document.querySelectorAll('[style*="hcs://"]');this.log("Found "+e.length+" elements with HCS style references");for(const r of Array.from(e)){const e=r.getAttribute("style");if(e){this.log("Processing style: "+e);const t=await this.replaceHCSInStyle(e);e!==t&&(r.setAttribute("style",t),this.log("Updated style to: "+t))}}const t=document.querySelectorAll("style");for(const r of Array.from(t))if(r.textContent?.includes("hcs://")){const e=await this.replaceHCSInStyle(r.textContent);r.textContent!==e&&(r.textContent=e)}}async init(){return this.loadConfigFromHTML(),new Promise((e=>{const t=async()=>{const t=document.querySelectorAll('script[data-src^="hcs://"]'),r=document.querySelectorAll('img[data-src^="hcs://"], img[src^="hcs://"]'),n=document.querySelectorAll('video[data-src^="hcs://"], video[src^="hcs://"]'),i=document.querySelectorAll('audio[data-src^="hcs://"], audio[src^="hcs://"]'),o=document.querySelectorAll('model-viewer[data-src^="hcs://"]'),a=document.querySelectorAll('link[data-src^="hcs://"]');document.querySelectorAll('[src^="hcs://"]').forEach((e=>{const t=e.getAttribute("src");t&&(e.setAttribute("data-src",t),e.removeAttribute("src"))})),await this.processInlineStyles();const s=[];[{elements:t,type:"script"},{elements:r,type:"image"},{elements:n,type:"video"},{elements:i,type:"audio"},{elements:o,type:"glb"},{elements:a,type:"css"}].forEach((({elements:e,type:t})=>{e.forEach((e=>{const r=parseInt(e.getAttribute("data-load-order")||"")||1/0;s.push(this.loadResource(e,t,r))}))})),await Promise.all(s);const c=new MutationObserver((e=>{e.forEach((e=>{if(e.addedNodes.forEach((e=>{if(e.nodeType===Node.ELEMENT_NODE){const t=e;if(t.getAttribute("style")?.includes("hcs://")&&this.processInlineStyles(),"style"===t.tagName.toLowerCase()&&t.textContent?.includes("hcs://")&&this.processInlineStyles(),t.getAttribute("src")?.startsWith("hcs://")){const e=t.getAttribute("src");t.setAttribute("data-src",e),t.removeAttribute("src");switch(t.tagName.toLowerCase()){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"script":this.loadResource(t,"script",1/0)}}t.matches('script[data-src^="hcs://"]')?this.loadResource(t,"script",1/0):t.matches('img[data-src^="hcs://"]')?this.loadResource(t,"image",1/0):t.matches('video[data-src^="hcs://"]')?this.loadResource(t,"video",1/0):t.matches('audio[data-src^="hcs://"]')?this.loadResource(t,"audio",1/0):t.matches('model-viewer[data-src^="hcs://"]')?this.loadResource(t,"glb",1/0):t.matches('link[data-src^="hcs://"]')&&this.loadResource(t,"css",1/0);t.querySelectorAll('[data-src^="hcs://"], [src^="hcs://"]').forEach((e=>{const t=e,r=t.tagName.toLowerCase(),n=t.getAttribute("src");switch(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)}}))}})),"attributes"===e.type){const t=e.target;if("style"===e.attributeName&&t.getAttribute("style")?.includes("hcs://"))this.processInlineStyles();else if("src"===e.attributeName){const e=t.getAttribute("src");if(e?.startsWith("hcs://")){t.setAttribute("data-src",e),t.removeAttribute("src");const r=t.tagName.toLowerCase();["img","video","audio"].includes(r)&&this.loadResource(t,r,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()};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",t):t()}))}async preloadImage(e){this.log("Loading image:"+e),this.updateLoadingStatus("image: "+e,"loading");const t=await this.retrieveHCS1Data(e),r=URL.createObjectURL(t);return this.LoadedImages[e]=r,this.updateLoadingStatus("image: "+e,"loaded"),r}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 r=document.querySelector('audio[data-topic-id="'+e+'"]');return r?this.LoadedAudioUrls[e]=r.src:console.error("Failed to preload audio: "+e),this.LoadedAudioUrls[e]}async playAudio(e,t=1){const r=this.LoadedAudioUrls[e];if(r){const n=new Audio(r);n.volume=t,this.LoadedAudios[e]=n,n.play().catch((e=>{console.error("Failed to play audio:",e)})),n.addEventListener("ended",(()=>{n.remove(),delete this.LoadedAudios[e]}))}else console.error("Audio not preloaded: "+e)}async pauseAudio(e){const t=document.querySelector('audio[data-topic-id="'+e+'"]');t?(console.log("found element",t),t.pause(),this.LoadedAudios[e]?.pause()):this.LoadedAudios[e]?.pause()}async loadAndPlayAudio(e,t=!1,r=1){let n=document.querySelector('audio[data-topic-id="'+e+'"]');if(n)n.volume=r,await n.play();else{const i=document.createElement("audio");i.volume=r,t&&i.setAttribute("autoplay","autoplay"),i.setAttribute("data-topic-id",e),i.setAttribute("data-src","hcs://1/"+e),document.body.appendChild(i),await this.loadMedia(i,"audio"),n=document.querySelector('audio[data-topic-id="'+e+'"]'),t||await n.play()}}}class WasmBridge{constructor(){this.wasm=null,this.WASM_VECTOR_LEN=0,this.cachedUint8Memory=null,this.cachedDataViewMemory=null,this.textEncoder=new TextEncoder,this.textDecoder=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),this.textDecoder.decode(),this.logger=Logger$5.getInstance({module:"WasmBridge"})}setLogLevel(e){this.logger.setLogLevel(e)}get wasmInstance(){if(!this.wasm)throw new Error("WASM not initialized");return this.wasm}getUint8Memory(){if(!this.wasm)throw new Error("WASM not initialized");return null!==this.cachedUint8Memory&&0!==this.cachedUint8Memory.byteLength||(this.cachedUint8Memory=new Uint8Array(this.wasm.memory.buffer)),this.cachedUint8Memory}getDataViewMemory(){if(!this.wasm)throw new Error("WASM not initialized");return null!==this.cachedDataViewMemory&&this.cachedDataViewMemory.buffer===this.wasm.memory.buffer||(this.cachedDataViewMemory=new DataView(this.wasm.memory.buffer)),this.cachedDataViewMemory}encodeString(e,t){if(0===e.length)return{read:0,written:0};const r=this.textEncoder.encode(e);return t.set(r),{read:e.length,written:r.length}}passStringToWasm(e,t,r){if(void 0===r){const r=this.textEncoder.encode(e),n=t(r.length,1);return this.getUint8Memory().set(r,n),this.WASM_VECTOR_LEN=r.length,n}let n=this.textEncoder.encode(e).length,i=t(n,1);const o=this.getUint8Memory();let a=0;for(;a<n;a++){const t=e.charCodeAt(a);if(t>127)break;o[i+a]=t}if(a!==n){0!==a&&(e=e.slice(a)),i=r(i,n,n=a+3*this.textEncoder.encode(e).length,1);const t=this.getUint8Memory().subarray(i+a,i+n);a+=this.encodeString(e,t).written}return this.WASM_VECTOR_LEN=a,i}getStringFromWasm(e,t){return e>>>=0,this.textDecoder.decode(this.getUint8Memory().subarray(e,e+t))}createWasmFunction(e){if(!this.wasm)throw new Error("WASM not initialized");return(...t)=>{const r=this.wasm.__wbindgen_add_to_stack_pointer(-16);let n=[0,0];try{const i=[r,...t.map((e=>[this.passStringToWasm(e,this.wasm.__wbindgen_malloc,this.wasm.__wbindgen_realloc),this.WASM_VECTOR_LEN])).flat()];e.apply(this.wasm,i);const o=this.getDataViewMemory().getInt32(r+0,!0),a=this.getDataViewMemory().getInt32(r+4,!0);return n=[o,a],this.getStringFromWasm(o,a)}finally{this.wasm.__wbindgen_add_to_stack_pointer(16),this.wasm.__wbindgen_free(n[0],n[1],1)}}}async initWasm(e){const t=this,r={__wbindgen_placeholder__:{__wbindgen_throw:function(e,r){const n=t.getStringFromWasm(e,r);throw t.logger.error(`WASM error: ${n}`),new Error(n)}}};try{this.logger.debug("Compiling WASM module");const t=await WebAssembly.compile(e);this.logger.debug("Instantiating WASM module");const n=await WebAssembly.instantiate(t,r);return this.wasm=n.exports,this.logger.info("WASM module initialized successfully"),this.wasm}catch(n){throw this.logger.error("Failed to initialize WASM module",n),n}}createStateData(e,t={}){let r={};return e?.c?.inputType?.stateData&&(t.latestRoundData&&Object.keys(e.c.inputType.stateData).every((e=>e in t.latestRoundData))?(r.latestRoundData={},Object.entries(e.c.inputType.stateData).forEach((([e,n])=>{r.latestRoundData[e]=String(t.latestRoundData[e])}))):Object.entries(e.c.inputType.stateData).forEach((([e,n])=>{const i=t[e];i&&"object"==typeof i&&"values"in i&&i.values.length>0?r[e]=String(i.values[0]):r[e]=this.getDefaultValueForType(n)}))),r}getDefaultValueForType(e){return e.startsWith("uint")||e.startsWith("int")||"number"===e?"0":"bool"===e?"false":""}executeWasm(e,t){if(!this.wasm)throw this.logger.error("WASM not initialized"),new Error("WASM not initialized");try{this.logger.debug("Executing WASM with stateData",e);return this.createWasmFunction(this.wasmInstance.process_state)(JSON.stringify(e),JSON.stringify(t))}catch(r){throw this.logger.error("Error executing WASM",r),r}}getParams(){return this.createWasmFunction(this.wasmInstance.get_params)()}} /** * @license * Copyright 2009 The Closure Library Authors * Copyright 2020 Daniel Wirtz / The long.js Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0 */var wasm=null;try{wasm=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch{}function Long(e,t,r){this.low=0|e,this.high=0|t,this.unsigned=!!r}function isLong(e){return!0===(e&&e.__isLong__)}function ctz32(e){var t=Math.clz32(e&-e);return e?31-t:t}Long.prototype.__isLong__,Object.defineProperty(Long.prototype,"__isLong__",{value:!0}),Long.isLong=isLong;var INT_CACHE={},UINT_CACHE={};function fromInt(e,t){var r,n,i;return t?(i=0<=(e>>>=0)&&e<256)&&(n=UINT_CACHE[e])?n:(r=fromBits(e,0,!0),i&&(UINT_CACHE[e]=r),r):(i=-128<=(e|=0)&&e<128)&&(n=INT_CACHE[e])?n:(r=fromBits(e,e<0?-1:0,!1),i&&(INT_CACHE[e]=r),r)}function fromNumber(e,t){if(isNaN(e))return t?UZERO:ZERO;if(t){if(e<0)return UZERO;if(e>=TWO_PWR_64_DBL)return MAX_UNSIGNED_VALUE}else{if(e<=-0x8000000000000000)return MIN_VALUE;if(e+1>=TWO_PWR_63_DBL)return MAX_VALUE}return e<0?fromNumber(-e,t).neg():fromBits(e%TWO_PWR_32_DBL|0,e/TWO_PWR_32_DBL|0,t)}function fromBits(e,t,r){return new Long(e,t,r)}Long.fromInt=fromInt,Long.fromNumber=fromNumber,Long.fromBits=fromBits;var pow_dbl=Math.pow;function fromString(e,t,r){if(0===e.length)throw Error("empty string");if("number"==typeof t?(r=t,t=!1):t=!!t,"NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return t?UZERO:ZERO;if((r=r||10)<2||36<r)throw RangeError("radix");var n;if((n=e.indexOf("-"))>0)throw Error("interior hyphen");if(0===n)return fromString(e.substring(1),t,r).neg();for(var i=fromNumber(pow_dbl(r,8)),o=ZERO,a=0;a<e.length;a+=8){var s=Math.min(8,e.length-a),c=parseInt(e.substring(a,a+s),r);if(s<8){var u=fromNumber(pow_dbl(r,s));o=o.mul(u).add(fromNumber(c))}else o=(o=o.mul(i)).add(fromNumber(c))}return o.unsigned=t,o}function fromValue(e,t){return"number"==typeof e?fromNumber(e,t):"string"==typeof e?fromString(e,t):fromBits(e.low,e.high,"boolean"==typeof t?t:e.unsigned)}Long.fromString=fromString,Long.fromValue=fromValue;var TWO_PWR_16_DBL=65536,TWO_PWR_24_DBL=1<<24,TWO_PWR_32_DBL=TWO_PWR_16_DBL*TWO_PWR_16_DBL,TWO_PWR_64_DBL=TWO_PWR_32_DBL*TWO_PWR_32_DBL,TWO_PWR_63_DBL=TWO_PWR_64_DBL/2,TWO_PWR_24=fromInt(TWO_PWR_24_DBL),ZERO=fromInt(0);Long.ZERO=ZERO;var UZERO=fromInt(0,!0);Long.UZERO=UZERO;var ONE=fromInt(1);Long.ONE=ONE;var UONE=fromInt(1,!0);Long.UONE=UONE;var NEG_ONE=fromInt(-1);Long.NEG_ONE=NEG_ONE;var MAX_VALUE=fromBits(-1,2147483647,!1);Long.MAX_VALUE=MAX_VALUE;var MAX_UNSIGNED_VALUE=fromBits(-1,-1,!0);Long.MAX_UNSIGNED_VALUE=MAX_UNSIGNED_VALUE;var MIN_VALUE=fromBits(0,-2147483648,!1);Long.MIN_VALUE=MIN_VALUE;var LongPrototype=Long.prototype;LongPrototype.toInt=function(){return this.unsigned?this.low>>>0:this.low},LongPrototype.toNumber=function(){return this.unsigned?(this.high>>>0)*TWO_PWR_32_DBL+(this.low>>>0):this.high*TWO_PWR_32_DBL+(this.low>>>0)},LongPrototype.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(MIN_VALUE)){var t=fromNumber(e),r=this.div(t),n=r.mul(t).sub(this);return r.toString(e)+n.toInt().toString(e)}return"-"+this.neg().toString(e)}for(var i=fromNumber(pow_dbl(e,6),this.unsigned),o=this,a="";;){var s=o.div(i),c=(o.sub(s.mul(i)).toInt()>>>0).toString(e);if((o=s).isZero())return c+a;for(;c.length<6;)c="0"+c;a=""+c+a}},LongPrototype.getHighBits=function(){return this.high},LongPrototype.getHighBitsUnsigned=function(){return this.high>>>0},LongPrototype.getLowBits=function(){return this.low},LongPrototype.getLowBitsUnsigned=function(){return this.low>>>0},LongPrototype.getNumBitsAbs=function(){if(this.isNegative())return this.eq(MIN_VALUE)?64:this.neg().getNumBitsAbs();for(var e=0!=this.high?this.high:this.low,t=31;t>0&&!(e&1<<t);t--);return 0!=this.high?t+33:t+1},LongPrototype.isSafeInteger=function(){var e=this.high>>21;return!e||!this.unsigned&&(-1===e&&!(0===this.low&&-2097152===this.high))},LongPrototype.isZero=function(){return 0===this.high&&0===this.low},LongPrototype.eqz=LongPrototype.isZero,LongPrototype.isNegative=function(){return!this.unsigned&&this.high<0},LongPrototype.isPositive=function(){return this.unsigned||this.high>=0},LongPrototype.isOdd=function(){return!(1&~this.low)},LongPrototype.isEven=function(){return!(1&this.low)},LongPrototype.equals=function(e){return isLong(e)||(e=fromValue(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&(this.high===e.high&&this.low===e.low)},LongPrototype.eq=LongPrototype.equals,LongPrototype.notEquals=function(e){return!this.eq(e)},LongPrototype.neq=LongPrototype.notEquals,LongPrototype.ne=LongPrototype.notEquals,LongPrototype.lessThan=function(e){return this.comp(e)<0},LongPrototype.lt=LongPrototype.lessThan,LongPrototype.lessThanOrEqual=function(e){return this.comp(e)<=0},LongPrototype.lte=LongPrototype.lessThanOrEqual,LongPrototype.le=LongPrototype.lessThanOrEqual,LongPrototype.greaterThan=function(e){return this.comp(e)>0},LongPrototype.gt=LongPrototype.greaterThan,LongPrototype.greaterThanOrEqual=function(e){return this.comp(e)>=0},LongPrototype.gte=LongPrototype.greaterThanOrEqual,LongPrototype.ge=LongPrototype.greaterThanOrEqual,LongPrototype.compare=function(e){if(isLong(e)||(e=fromValue(e)),this.eq(e))return 0;var t=this.isNegative(),r=e.isNegative();return t&&!r?-1:!t&&r?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},LongPrototype.comp=LongPrototype.compare,LongPrototype.negate=function(){return!this.unsigned&&this.eq(MIN_VALUE)?MIN_VALUE:this.not().add(ONE)},LongPrototype.neg=LongPrototype.negate,LongPrototype.add=function(e){isLong(e)||(e=fromValue(e));var t=this.high>>>16,r=65535&this.high,n=this.low>>>16,i=65535&this.low,o=e.high>>>16,a=65535&e.high,s=e.low>>>16,c=0,u=0,l=0,d=0;return l+=(d+=i+(65535&e.low))>>>16,u+=(l+=n+s)>>>16,c+=(u+=r+a)>>>16,c+=t+o,fromBits((l&=65535)<<16|(d&=65535),(c&=65535)<<16|(u&=65535),this.unsigned)},LongPrototype.subtract=function(e){return isLong(e)||(e=fromValue(e)),this.add(e.neg())},LongPrototype.sub=LongPrototype.subtract,LongPrototype.multiply=function(e){if(this.isZero())return this;if(isLong(e)||(e=fromValue(e)),wasm)return fromBits(wasm.mul(this.low,this.high,e.low,e.high),wasm.get_high(),this.unsigned);if(e.isZero())return this.unsigned?UZERO:ZERO;if(this.eq(MIN_VALUE))return e.isOdd()?MIN_VALUE:ZERO;if(e.eq(MIN_VALUE))return this.isOdd()?MIN_VALUE:ZERO;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(TWO_PWR_24)&&e.lt(TWO_PWR_24))return fromNumber(this.toNumber()*e.toNumber(),this.unsigned);var t=this.high>>>16,r=65535&this.high,n=this.low>>>16,i=65535&this.low,o=e.high>>>16,a=65535&e.high,s=e.low>>>16,c=65535&e.low,u=0,l=0,d=0,p=0;return d+=(p+=i*c)>>>16,l+=(d+=n*c)>>>16,d&=65535,l+=(d+=i*s)>>>16,u+=(l+=r*c)>>>16,l&=65535,u+=(l+=n*s)>>>16,l&=65535,u+=(l+=i*a)>>>16,u+=t*c+r*s+n*a+i*o,fromBits((d&=65535)<<16|(p&=65535),(u&=65535)<<16|(l&=65535),this.unsigned)},LongPrototype.mul=LongPrototype.multiply,LongPrototype.divide=function(e){if(isLong(e)||(e=fromValue(e)),e.isZero())throw Error("division by zero");var t,r,n;if(wasm)return this.unsigned||-2147483648!==this.high||-1!==e.low||-1!==e.high?fromBits((this.unsigned?wasm.div_u:wasm.div_s)(this.low,this.high,e.low,e.high),wasm.get_high(),this.unsigned):this;if(this.isZero())return this.unsigned?UZERO:ZERO;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return UZERO;if(e.gt(this.shru(1)))return UONE;n=UZERO}else{if(this.eq(MIN_VALUE))return e.eq(ONE)||e.eq(NEG_ONE)?MIN_VALUE:e.eq(MIN_VALUE)?ONE:(t=this.shr(1).div(e).shl(1)).eq(ZERO)?e.isNegative()?ONE:NEG_ONE:(r=this.sub(e.mul(t)),n=t.add(r.div(e)));if(e.eq(MIN_VALUE))return this.unsigned?UZERO:ZERO;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();n=ZERO}for(r=this;r.gte(e);){t=Math.max(1,Math.floor(r.toNumber()/e.toNumber()));for(var i=Math.ceil(Math.log(t)/Math.LN2),o=i<=48?1:pow_dbl(2,i-48),a=fromNumber(t),s=a.mul(e);s.isNegative()||s.gt(r);)s=(a=fromNumber(t-=o,this.unsigned)).mul(e);a.isZero()&&(a=ONE),n=n.add(a),r=r.sub(s)}return n},LongPrototype.div=LongPrototype.divide,LongPrototype.modulo=function(e){return isLong(e)||(e=fromValue(e)),wasm?fromBits((this.unsigned?wasm.rem_u:wasm.rem_s)(this.low,this.high,e.low,e.high),wasm.get_high(),this.unsigned):this.sub(this.div(e).mul(e))},LongPrototype.mod=LongPrototype.modulo,LongPrototype.rem=LongPrototype.modulo,LongPrototype.not=function(){return fromBits(~this.low,~this.high,this.unsigned)},LongPrototype.countLeadingZeros=function(){return this.high?Math.clz32(this.high):Math.clz32(this.low)+32},LongPrototype.clz=LongPrototype.countLeadingZeros,LongPrototype.countTrailingZeros=function(){return this.low?ctz32(this.low):ctz32(this.high)+32},LongPrototype.ctz=LongPrototype.countTrailingZeros,LongPrototype.and=function(e){return isLong(e)||(e=fromValue(e)),fromBits(this.low&e.low,this.high&e.high,this.unsigned)},LongPrototype.or=function(e){return isLong(e)||(e=fromValue(e)),fromBits(this.low|e.low,this.high|e.high,this.unsigned)},LongPrototype.xor=function(e){return isLong(e)||(e=fromValue(e)),fromBits(this.low^e.low,this.high^e.high,this.unsigned)},LongPrototype.shiftLeft=function(e){return isLong(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?fromBits(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):fromBits(0,this.low<<e-32,this.unsigned)},LongPrototype.shl=LongPrototype.shiftLeft,LongPrototype.shiftRight=function(e){return isLong(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?fromBits(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):fromBits(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},LongPrototype.shr=LongPrototype.shiftRight,LongPrototype.shiftRightUnsigned=function(e){return isLong(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?fromBits(this.low>>>e|this.high<<32-e,this.high>>>e,this.unsigned):fromBits(32===e?this.high:this.high>>>e-32,0,this.unsigned)},LongPrototype.shru=LongPrototype.shiftRightUnsigned,LongPrototype.shr_u=LongPrototype.shiftRightUnsigned,LongPrototype.rotateLeft=function(e){var t;return isLong(e)&&(e=e.toInt()),0==(e&=63)?this:32===e?fromBits(this.high,this.low,this.unsigned):e<32?(t=32-e,fromBits(this.low<<e|this.high>>>t,this.high<<e|this.low>>>t,this.unsigned)):(t=32-(e-=32),fromBits(this.high<<e|this.low>>>t,this.low<<e|this.high>>>t,this.unsigned))},LongPrototype.rotl=LongPrototype.rotateLeft,LongPrototype.rotateRight=function(e){var t;return isLong(e)&&(e=e.toInt()),0==(e&=63)?this:32===e?fromBits(this.high,this.low,this.unsigned):e<32?(t=32-e,fromBits(this.high<<t|this.low>>>e,this.low<<t|this.high>>>e,this.unsigned)):(t=32-(e-=32),fromBits(this.low<<t|this.high>>>e,this.high<<t|this.low>>>e,this.unsigned))},LongPrototype.rotr=LongPrototype.rotateRight,LongPrototype.toSigned=function(){return this.unsigned?fromBits(this.low,this.high,!1):this},LongPrototype.toUnsigned=function(){return this.unsigned?this:fromBits(this.low,this.high,!0)},LongPrototype.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},LongPrototype.toBytesLE=function(){var e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24,255&e,e>>>8&255,e>>>16&255,e>>>24]},LongPrototype.toBytesBE=function(){var e=this.high,t=this.low;return[e>>>24,e>>>16&255,e>>>8&255,255&e,t>>>24,t>>>16&255,t>>>8&255,255&t]},Long.fromBytes=function(e,t,r){return r?Long.fromBytesLE(e,t):Long.fromBytesBE(e,t)},Long.fromBytesLE=function(e,t){return new Long(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,t)},Long.fromBytesBE=function(e,t){return new Long(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],t)},"function"==typeof BigInt&&(Long.fromBigInt=function(e,t){return fromBits(Number(BigInt.asIntN(32,e)),Number(BigInt.asIntN(32,e>>BigInt(32))),t)},Long.fromValue=function(e,t){return"bigint"==typeof e?fromBigInt(e,t):fromValue(e,t)},LongPrototype.toBigInt=function(){var e=BigInt(this.low>>>0);return BigInt(this.unsigned?this.high>>>0:this.high)<<BigInt(32)|e});var isNumeric=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,mathceil=Math.ceil,mathfloor=Math.floor,bignumberError="[BigNumber Error] ",tooManyDigits=bignumberError+"Number primitive has more than 15 significant digits: ",BASE=1e14,LOG_BASE=14,MAX_SAFE_INTEGER$1=9007199254740991,POWS_TEN=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],SQRT_BASE=1e7,MAX=1e9;function clone(e){var t,r,n,i,o,a=w.prototype={constructor:w,toString:null,valueOf:null},s=new w(1),c=20,u=4,l=-7,d=21,p=-1e7,f=1e7,h=!1,m=1,g=0,y={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},b="0123456789abcdefghijklmnopqrstuvwxyz",v=!0;function w(e,t){var i,o,a,s,l,d,h,m,g=this;if(!(g instanceof w))return new w(e,t);if(null==t){if(e&&!0===e._isBigNumber)return g.s=e.s,void(!e.c||e.e>f?g.c=g.e=null:e.e<p?g.c=[g.e=0]:(g.e=e.e,g.c=e.c.slice()));if((d="number"==typeof e)&&0*e==0){if(g.s=1/e<0?(e=-e,-1):1,e===~~e){for(s=0,l=e;l>=10;l/=10,s++);return void(s>f?g.c=g.e=null:(g.e=s,g.c=[e]))}m=String(e)}else{if(!isNumeric.test(m=String(e)))return n(g,m,d);g.s=45==m.charCodeAt(0)?(m=m.slice(1),-1):1}(s=m.indexOf("."))>-1&&(m=m.replace(".","")),(l=m.search(/e/i))>0?(s<0&&(s=l),s+=+m.slice(l+1),m=m.substring(0,l)):s<0&&(s=m.length)}else{if(intCheck(t,2,b.length,"Base"),10==t&&v)return k(g=new w(e),c+g.e+1,u);if(m=String(e),d="number"==typeof e){if(0*e!=0)return n(g,m,d,t);if(g.s=1/e<0?(m=m.slice(1),-1):1,w.DEBUG&&m.replace(/^0\.0*|\./,"").length>15)throw Error(tooManyDigits+e)}else g.s=45===m.charCodeAt(0)?(m=m.slice(1),-1):1;for(i=b.slice(0,t),s=l=0,h=m.length;l<h;l++)if(i.indexOf(o=m.charAt(l))<0){if("."==o){if(l>s){s=h;continue}}else if(!a&&(m==m.toUpperCase()&&(m=m.toLowerCase())||m==m.toLowerCase()&&(m=m.toUpperCase()))){a=!0,l=-1,s=0;continue}return n(g,String(e),d,t)}d=!1,(s=(m=r(m,t,10,g.s)).indexOf("."))>-1?m=m.replace(".",""):s=m.length}for(l=0;48===m.charCodeAt(l);l++);for(h=m.length;48===m.charCodeAt(--h););if(m=m.slice(l,++h)){if(h-=l,d&&w.DEBUG&&h>15&&(e>MAX_SAFE_INTEGER$1||e!==mathfloor(e)))throw Error(tooManyDigits+g.s*e);if((s=s-l-1)>f)g.c=g.e=null;else if(s<p)g.c=[g.e=0];else{if(g.e=s,g.c=[],l=(s+1)%LOG_BASE,s<0&&(l+=LOG_BASE),l<h){for(l&&g.c.push(+m.slice(0,l)),h-=LOG_BASE;l<h;)g.c.push(+m.slice(l,l+=LOG_BASE));l=LOG_BASE-(m=m.slice(l)).length}else l-=h;for(;l--;m+="0");g.c.push(+m)}}else g.c=[g.e=0]}function x(e,t,r,n){var i,o,a,s,c;if(null==r?r=u:intCheck(r,0,8),!e.c)return e.toString();if(i=e.c[0],a=e.e,null==t)c=coeffToString(e.c),c=1==n||2==n&&(a<=l||a>=d)?toExponential(c,a):toFixedPoint(c,a,"0");else if(o=(e=k(new w(e),t,r)).e,s=(c=coeffToString(e.c)).length,1==n||2==n&&(t<=o||o<=l)){for(;s<t;c+="0",s++);c=toExponential(c,o)}else if(t-=a,c=toFixedPoint(c,o,"0"),o+1>s){if(--t>0)for(c+=".";t--;c+="0");}else if((t+=o-s)>0)for(o+1==s&&(c+=".");t--;c+="0");return e.s<0&&i?"-"+c:c}function _(e,t){for(var r,n,i=1,o=new w(e[0]);i<e.length;i++)(!(n=new w(e[i])).s||(r=compare(o,n))===t||0===r&&o.s===t)&&(o=n);return o}function $(e,t,r){for(var n=1,i=t.length;!t[--i];t.pop());for(i=t[0];i>=10;i/=10,n++);return(r=n+r*LOG_BASE-1)>f?e.c=e.e=null:r<p?e.c=[e.e=0]:(e.e=r,e.c=t),e}function k(e,t,r,n){var i,o,a,s,c,u,l,d=e.c,h=POWS_TEN;if(d){e:{for(i=1,s=d[0];s>=10;s/=10,i++);if((o=t-i)<0)o+=LOG_BASE,a=t,c=d[u=0],l=mathfloor(c/h[i-a-1]%10);else if((u=mathceil((o+1)/LOG_BASE))>=d.length){if(!n)break e;for(;d.length<=u;d.push(0));c=l=0,i=1,a=(o%=LOG_BASE)-LOG_BASE+1}else{for(c=s=d[u],i=1;s>=10;s/=10,i++);l=(a=(o%=LOG_BASE)-LOG_BASE+i)<0?0:mathfloor(c/h[i-a-1]%10)}if(n=n||t<0||null!=d[u+1]||(a<0?c:c%h[i-a-1]),n=r<4?(l||n)&&(0==r||r==(e.s<0?3: