UNPKG

@walletconnect/utils

Version:

Utilities for WalletConnect Protocol

4 lines • 105 kB
import{detect as ys}from"detect-browser";import{toMiliseconds as Ke,FIVE_MINUTES as qn,fromMiliseconds as ms}from"@walletconnect/time";import{getDocument as ne,getNavigator as Kn,getLocation as Fn}from"@walletconnect/window-getters";import{getWindowMetadata as ws}from"@walletconnect/window-metadata";import{recoverAddress as xs}from"viem";import re from"bs58";import{decode as vs,encode as Es}from"@msgpack/msgpack";import{base32 as Bs}from"@scure/base";import{decodeJWT as Is}from"@walletconnect/relay-auth";import{toString as st,fromString as ft,concat as oe}from"uint8arrays";import{RELAY_JSONRPC as As}from"@walletconnect/relay-api";import{blake2b as Ss}from"blakejs";const xe=":";function Fe(t){const[e,n]=t.split(xe);return{namespace:e,reference:n}}function zn(t){const{namespace:e,reference:n}=t;return[e,n].join(xe)}function ze(t){const[e,n,r]=t.split(xe);return{namespace:e,reference:n,address:r}}function Gn(t){const{namespace:e,reference:n,address:r}=t;return[e,n,r].join(xe)}function Ge(t,e){const n=[];return t.forEach(r=>{const o=e(r);n.includes(o)||n.push(o)}),n}function Zn(t){const{address:e}=ze(t);return e}function Wn(t){const{namespace:e,reference:n}=ze(t);return zn({namespace:e,reference:n})}function Ns(t,e){const{namespace:n,reference:r}=Fe(e);return Gn({namespace:n,reference:r,address:t})}function Os(t){return Ge(t,Zn)}function Yn(t){return Ge(t,Wn)}function Us(t,e=[]){const n=[];return Object.keys(t).forEach(r=>{if(e.length&&!e.includes(r))return;const o=t[r];n.push(...o.accounts)}),n}function _s(t,e=[]){const n=[];return Object.keys(t).forEach(r=>{if(e.length&&!e.includes(r))return;const o=t[r];n.push(...Yn(o.accounts))}),n}function Ts(t,e=[]){const n=[];return Object.keys(t).forEach(r=>{if(e.length&&!e.includes(r))return;const o=t[r];n.push(...ve(r,o))}),n}function ve(t,e){return t.includes(":")?[t]:e.chains||[]}var Rs=Object.defineProperty,$s=Object.defineProperties,Cs=Object.getOwnPropertyDescriptors,Xn=Object.getOwnPropertySymbols,Ls=Object.prototype.hasOwnProperty,js=Object.prototype.propertyIsEnumerable,Jn=(t,e,n)=>e in t?Rs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Qn=(t,e)=>{for(var n in e||(e={}))Ls.call(e,n)&&Jn(t,n,e[n]);if(Xn)for(var n of Xn(e))js.call(e,n)&&Jn(t,n,e[n]);return t},ks=(t,e)=>$s(t,Cs(e));const tr="ReactNative",J={reactNative:"react-native",node:"node",browser:"browser",unknown:"unknown"},Ee=" ",Ps=":",er="/",Ze=2,Hs=1e3,nr="js";function We(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function Bt(){return!ne()&&!!Kn()&&navigator.product===tr}function Ds(){return Bt()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="android"}function Ms(){return Bt()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="ios"}function zt(){return!We()&&!!Kn()&&!!ne()}function Pt(){return Bt()?J.reactNative:We()?J.node:zt()?J.browser:J.unknown}function Vs(){var t;try{return Bt()&&typeof global<"u"&&typeof(global==null?void 0:global.Application)<"u"?(t=global.Application)==null?void 0:t.applicationId:void 0}catch{return}}function rr(t,e){const n=new URLSearchParams(t);for(const r of Object.keys(e).sort())if(e.hasOwnProperty(r)){const o=e[r];o!==void 0&&n.set(r,o)}return n.toString()}function qs(t){var e,n;const r=or();try{return t!=null&&t.url&&r.url&&new URL(t.url).host!==new URL(r.url).host&&(console.warn(`The configured WalletConnect 'metadata.url':${t.url} differs from the actual page url:${r.url}. This is probably unintended and can lead to issues.`),t.url=r.url),(e=t?.icons)!=null&&e.length&&t.icons.length>0&&(t.icons=t.icons.filter(o=>o!=="")),ks(Qn(Qn({},r),t),{url:t?.url||r.url,name:t?.name||r.name,description:t?.description||r.description,icons:(n=t?.icons)!=null&&n.length&&t.icons.length>0?t.icons:r.icons})}catch(o){return console.warn("Error populating app metadata",o),t||r}}function or(){return ws()||{name:"",description:"",url:"",icons:[""]}}function Ks(t,e){var n;const r=Pt(),o={protocol:t,version:e,env:r};return r==="browser"&&(o.host=((n=Fn())==null?void 0:n.host)||"unknown"),o}function sr(){if(Pt()===J.reactNative&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"){const{OS:n,Version:r}=global.Platform;return[n,r].join("-")}const t=ys();if(t===null)return"unknown";const e=t.os?t.os.replace(" ","").toLowerCase():"unknown";return t.type==="browser"?[e,t.name,t.version].join("-"):[e,t.version].join("-")}function ir(){var t;const e=Pt();return e===J.browser?[e,((t=Fn())==null?void 0:t.host)||"unknown"].join(":"):e}function fr(t,e,n){const r=sr(),o=ir();return[[t,e].join("-"),[nr,n].join("-"),r,o].join("/")}function Fs({protocol:t,version:e,relayUrl:n,sdkVersion:r,auth:o,projectId:s,useOnCloseEvent:i,bundleId:f,packageName:c}){const u=n.split("?"),a=fr(t,e,r),l={auth:o,ua:a,projectId:s,useOnCloseEvent:i||void 0,packageName:c||void 0,bundleId:f||void 0},h=rr(u[1]||"",l);return u[0]+"?"+h}function zs(t){let e=(t.match(/^[^:]+(?=:\/\/)/gi)||[])[0];const n=typeof e<"u"?t.split("://")[1]:t;return e=e==="wss"?"https":"http",[e,n].join("://")}function Gs(t,e,n){if(!t[e]||typeof t[e]!==n)throw new Error(`Missing or invalid "${e}" param`)}function cr(t,e=Ze){return ar(t.split(er),e)}function Zs(t){return cr(t).join(Ee)}function It(t,e){return t.filter(n=>e.includes(n)).length===t.length}function ar(t,e=Ze){return t.slice(Math.max(t.length-e,0))}function Ws(t){return Object.fromEntries(t.entries())}function Ys(t){return new Map(Object.entries(t))}function Xs(t,e){const n={};return Object.keys(t).forEach(r=>{n[r]=e(t[r])}),n}const Js=t=>t;function ur(t){return t.trim().replace(/^\w/,e=>e.toUpperCase())}function Qs(t){return t.split(Ee).map(e=>ur(e)).join(Ee)}function ti(t=qn,e){const n=Ke(t||qn);let r,o,s,i;return{resolve:f=>{s&&r&&(clearTimeout(s),r(f),i=Promise.resolve(f))},reject:f=>{s&&o&&(clearTimeout(s),o(f))},done:()=>new Promise((f,c)=>{if(i)return f(i);s=setTimeout(()=>{const u=new Error(e);i=Promise.reject(u),c(u)},n),r=f,o=c})}}function ei(t,e,n){return new Promise(async(r,o)=>{const s=setTimeout(()=>o(new Error(n)),e);try{const i=await t;r(i)}catch(i){o(i)}clearTimeout(s)})}function Ye(t,e){if(typeof e=="string"&&e.startsWith(`${t}:`))return e;if(t.toLowerCase()==="topic"){if(typeof e!="string")throw new Error('Value must be "string" for expirer target type: topic');return`topic:${e}`}else if(t.toLowerCase()==="id"){if(typeof e!="number")throw new Error('Value must be "number" for expirer target type: id');return`id:${e}`}throw new Error(`Unknown expirer target type: ${t}`)}function ni(t){return Ye("topic",t)}function ri(t){return Ye("id",t)}function oi(t){const[e,n]=t.split(":"),r={id:void 0,topic:void 0};if(e==="topic"&&typeof n=="string")r.topic=n;else if(e==="id"&&Number.isInteger(Number(n)))r.id=Number(n);else throw new Error(`Invalid target, expected id:number or topic:string, got ${e}:${n}`);return r}function si(t,e){return ms((e||Date.now())+Ke(t))}function ii(t){return Date.now()>=Ke(t)}function fi(t,e){return`${t}${e?`:${e}`:""}`}function ct(t=[],e=[]){return[...new Set([...t,...e])]}async function ci({id:t,topic:e,wcDeepLink:n}){var r;try{if(!n)return;const o=typeof n=="string"?JSON.parse(n):n,s=o?.href;if(typeof s!="string")return;const i=lr(s,t,e),f=Pt();if(f===J.browser){if(!((r=ne())!=null&&r.hasFocus())){console.warn("Document does not have focus, skipping deeplink.");return}dr(i)}else f===J.reactNative&&typeof(global==null?void 0:global.Linking)<"u"&&await global.Linking.openURL(i)}catch(o){console.error(o)}}function lr(t,e,n){const r=`requestId=${e}&sessionTopic=${n}`;t.endsWith("/")&&(t=t.slice(0,-1));let o=`${t}`;if(t.startsWith("https://t.me")){const s=t.includes("?")?"&startapp=":"?startapp=";o=`${o}${s}${gr(r,!0)}`}else o=`${o}/wc?${r}`;return o}function dr(t){let e="_self";pr()?e="_top":(hr()||t.startsWith("https://")||t.startsWith("http://"))&&(e="_blank"),window.open(t,e,"noreferrer noopener")}async function ai(t,e){let n="";try{if(zt()&&(n=localStorage.getItem(e),n))return n;n=await t.getItem(e)}catch(r){console.error(r)}return n}function Xe(t,e){return t.filter(n=>e.includes(n))}function ui(t,e){if(!t.includes(e))return null;const n=t.split(/([&,?,=])/),r=n.indexOf(e);return n[r+2]}function li(){return typeof crypto<"u"&&crypto!=null&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/gu,t=>{const e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function di(){return typeof process<"u"&&process.env.IS_VITEST==="true"}function hr(){return typeof window<"u"&&(!!window.TelegramWebviewProxy||!!window.Telegram||!!window.TelegramWebviewProxyProto)}function pr(){try{return window.self!==window.top}catch{return!1}}function gr(t,e=!1){const n=Buffer.from(t).toString("base64");return e?n.replace(/[=]/g,""):n}function Je(t){return Buffer.from(t,"base64").toString("utf-8")}function hi(t){return new Promise(e=>setTimeout(e,t))}const Be=BigInt(2**32-1),br=BigInt(32);function yr(t,e=!1){return e?{h:Number(t&Be),l:Number(t>>br&Be)}:{h:Number(t>>br&Be)|0,l:Number(t&Be)|0}}function mr(t,e=!1){const n=t.length;let r=new Uint32Array(n),o=new Uint32Array(n);for(let s=0;s<n;s++){const{h:i,l:f}=yr(t[s],e);[r[s],o[s]]=[i,f]}return[r,o]}const wr=(t,e,n)=>t>>>n,xr=(t,e,n)=>t<<32-n|e>>>n,At=(t,e,n)=>t>>>n|e<<32-n,St=(t,e,n)=>t<<32-n|e>>>n,se=(t,e,n)=>t<<64-n|e>>>n-32,ie=(t,e,n)=>t>>>n-32|e<<64-n,pi=(t,e)=>e,gi=(t,e)=>t,bi=(t,e,n)=>t<<n|e>>>32-n,yi=(t,e,n)=>e<<n|t>>>32-n,mi=(t,e,n)=>e<<n-32|t>>>64-n,wi=(t,e,n)=>t<<n-32|e>>>64-n;function dt(t,e,n,r){const o=(e>>>0)+(r>>>0);return{h:t+n+(o/2**32|0)|0,l:o|0}}const Qe=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),tn=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,xi=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),vi=(t,e,n,r,o)=>e+n+r+o+(t/2**32|0)|0,Ei=(t,e,n,r,o)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(o>>>0),Bi=(t,e,n,r,o,s)=>e+n+r+o+s+(t/2**32|0)|0,Gt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function en(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function mt(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function at(t,...e){if(!en(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function nn(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");mt(t.outputLen),mt(t.blockLen)}function Nt(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function rn(t,e){at(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function fe(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function ut(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function on(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function gt(t,e){return t<<32-e|t>>>e}const vr=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Er(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}const wt=vr?t=>t:t=>Er(t);function Ii(t){for(let e=0;e<t.length;e++)t[e]=Er(t[e]);return t}const Ot=vr?t=>t:Ii,Br=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Ai=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function ce(t){if(at(t),Br)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=Ai[t[n]];return e}const xt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ir(t){if(t>=xt._0&&t<=xt._9)return t-xt._0;if(t>=xt.A&&t<=xt.F)return t-(xt.A-10);if(t>=xt.a&&t<=xt.f)return t-(xt.a-10)}function sn(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(Br)return Uint8Array.fromHex(t);const e=t.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let o=0,s=0;o<n;o++,s+=2){const i=Ir(t.charCodeAt(s)),f=Ir(t.charCodeAt(s+1));if(i===void 0||f===void 0){const c=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}r[o]=i*16+f}return r}function Si(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function ht(t){return typeof t=="string"&&(t=Si(t)),at(t),t}function Ht(...t){let e=0;for(let r=0;r<t.length;r++){const o=t[r];at(o),e+=o.length}const n=new Uint8Array(e);for(let r=0,o=0;r<t.length;r++){const s=t[r];n.set(s,o),o+=s.length}return n}class Ie{}function ae(t){const e=r=>t().update(ht(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Ni(t){const e=(r,o)=>t(o).update(ht(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function Zt(t=32){if(Gt&&typeof Gt.getRandomValues=="function")return Gt.getRandomValues(new Uint8Array(t));if(Gt&&typeof Gt.randomBytes=="function")return Uint8Array.from(Gt.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}const Oi=BigInt(0),ue=BigInt(1),Ui=BigInt(2),_i=BigInt(7),Ti=BigInt(256),Ri=BigInt(113),Ar=[],Sr=[],Nr=[];for(let t=0,e=ue,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],Ar.push(2*(5*r+n)),Sr.push((t+1)*(t+2)/2%64);let o=Oi;for(let s=0;s<7;s++)e=(e<<ue^(e>>_i)*Ri)%Ti,e&Ui&&(o^=ue<<(ue<<BigInt(s))-ue);Nr.push(o)}const Or=mr(Nr,!0),$i=Or[0],Ci=Or[1],Ur=(t,e,n)=>n>32?mi(t,e,n):bi(t,e,n),_r=(t,e,n)=>n>32?wi(t,e,n):yi(t,e,n);function Li(t,e=24){const n=new Uint32Array(10);for(let r=24-e;r<24;r++){for(let i=0;i<10;i++)n[i]=t[i]^t[i+10]^t[i+20]^t[i+30]^t[i+40];for(let i=0;i<10;i+=2){const f=(i+8)%10,c=(i+2)%10,u=n[c],a=n[c+1],l=Ur(u,a,1)^n[f],h=_r(u,a,1)^n[f+1];for(let g=0;g<50;g+=10)t[i+g]^=l,t[i+g+1]^=h}let o=t[2],s=t[3];for(let i=0;i<24;i++){const f=Sr[i],c=Ur(o,s,f),u=_r(o,s,f),a=Ar[i];o=t[a],s=t[a+1],t[a]=c,t[a+1]=u}for(let i=0;i<50;i+=10){for(let f=0;f<10;f++)n[f]=t[i+f];for(let f=0;f<10;f++)t[i+f]^=~n[(f+2)%10]&n[(f+4)%10]}t[0]^=$i[r],t[1]^=Ci[r]}ut(n)}class Vn extends Ie{constructor(e,n,r,o=!1,s=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=n,this.outputLen=r,this.enableXOF=o,this.rounds=s,mt(r),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=fe(this.state)}clone(){return this._cloneInto()}keccak(){Ot(this.state32),Li(this.state32,this.rounds),Ot(this.state32),this.posOut=0,this.pos=0}update(e){Nt(this),e=ht(e),at(e);const{blockLen:n,state:r}=this,o=e.length;for(let s=0;s<o;){const i=Math.min(n-this.pos,o-s);for(let f=0;f<i;f++)r[this.pos++]^=e[s++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:n,pos:r,blockLen:o}=this;e[r]^=n,(n&128)!==0&&r===o-1&&this.keccak(),e[o-1]^=128,this.keccak()}writeInto(e){Nt(this,!1),at(e),this.finish();const n=this.state,{blockLen:r}=this;for(let o=0,s=e.length;o<s;){this.posOut>=r&&this.keccak();const i=Math.min(r-this.posOut,s-o);e.set(n.subarray(this.posOut,this.posOut+i),o),this.posOut+=i,o+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return mt(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(rn(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,ut(this.state)}_cloneInto(e){const{blockLen:n,suffix:r,outputLen:o,rounds:s,enableXOF:i}=this;return e||(e=new Vn(n,r,o,i,s)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=s,e.suffix=r,e.outputLen=o,e.enableXOF=i,e.destroyed=this.destroyed,e}}const ji=(t,e,n)=>ae(()=>new Vn(e,t,n)),ki=ji(1,136,256/8);function Pi(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const o=BigInt(32),s=BigInt(4294967295),i=Number(n>>o&s),f=Number(n&s),c=r?4:0,u=r?0:4;t.setUint32(e+c,i,r),t.setUint32(e+u,f,r)}function Hi(t,e,n){return t&e^~t&n}function Di(t,e,n){return t&e^t&n^e&n}class Tr extends Ie{constructor(e,n,r,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=o,this.buffer=new Uint8Array(e),this.view=on(this.buffer)}update(e){Nt(this),e=ht(e),at(e);const{view:n,buffer:r,blockLen:o}=this,s=e.length;for(let i=0;i<s;){const f=Math.min(o-this.pos,s-i);if(f===o){const c=on(e);for(;o<=s-i;i+=o)this.process(c,i);continue}r.set(e.subarray(i,i+f),this.pos),this.pos+=f,i+=f,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Nt(this),rn(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:o,isLE:s}=this;let{pos:i}=this;n[i++]=128,ut(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(r,0),i=0);for(let l=i;l<o;l++)n[l]=0;Pi(r,o-8,BigInt(this.length*8),s),this.process(r,0);const f=on(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=c/4,a=this.get();if(u>a.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)f.setUint32(4*l,a[l],s)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:o,finished:s,destroyed:i,pos:f}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=f,o%n&&e.buffer.set(r),e}clone(){return this._cloneInto()}}const Ut=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),W=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),Y=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),Mi=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),_t=new Uint32Array(64);class Vi extends Tr{constructor(e=32){super(64,e,8,!1),this.A=Ut[0]|0,this.B=Ut[1]|0,this.C=Ut[2]|0,this.D=Ut[3]|0,this.E=Ut[4]|0,this.F=Ut[5]|0,this.G=Ut[6]|0,this.H=Ut[7]|0}get(){const{A:e,B:n,C:r,D:o,E:s,F:i,G:f,H:c}=this;return[e,n,r,o,s,i,f,c]}set(e,n,r,o,s,i,f,c){this.A=e|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=f|0,this.H=c|0}process(e,n){for(let l=0;l<16;l++,n+=4)_t[l]=e.getUint32(n,!1);for(let l=16;l<64;l++){const h=_t[l-15],g=_t[l-2],m=gt(h,7)^gt(h,18)^h>>>3,b=gt(g,17)^gt(g,19)^g>>>10;_t[l]=b+_t[l-7]+m+_t[l-16]|0}let{A:r,B:o,C:s,D:i,E:f,F:c,G:u,H:a}=this;for(let l=0;l<64;l++){const h=gt(f,6)^gt(f,11)^gt(f,25),g=a+h+Hi(f,c,u)+Mi[l]+_t[l]|0,b=(gt(r,2)^gt(r,13)^gt(r,22))+Di(r,o,s)|0;a=u,u=c,c=f,f=i+g|0,i=s,s=o,o=r,r=g+b|0}r=r+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,f=f+this.E|0,c=c+this.F|0,u=u+this.G|0,a=a+this.H|0,this.set(r,o,s,i,f,c,u,a)}roundClean(){ut(_t)}destroy(){this.set(0,0,0,0,0,0,0,0),ut(this.buffer)}}const Rr=mr(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),qi=Rr[0],Ki=Rr[1],Tt=new Uint32Array(80),Rt=new Uint32Array(80);class fn extends Tr{constructor(e=64){super(128,e,16,!1),this.Ah=Y[0]|0,this.Al=Y[1]|0,this.Bh=Y[2]|0,this.Bl=Y[3]|0,this.Ch=Y[4]|0,this.Cl=Y[5]|0,this.Dh=Y[6]|0,this.Dl=Y[7]|0,this.Eh=Y[8]|0,this.El=Y[9]|0,this.Fh=Y[10]|0,this.Fl=Y[11]|0,this.Gh=Y[12]|0,this.Gl=Y[13]|0,this.Hh=Y[14]|0,this.Hl=Y[15]|0}get(){const{Ah:e,Al:n,Bh:r,Bl:o,Ch:s,Cl:i,Dh:f,Dl:c,Eh:u,El:a,Fh:l,Fl:h,Gh:g,Gl:m,Hh:b,Hl:v}=this;return[e,n,r,o,s,i,f,c,u,a,l,h,g,m,b,v]}set(e,n,r,o,s,i,f,c,u,a,l,h,g,m,b,v){this.Ah=e|0,this.Al=n|0,this.Bh=r|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=f|0,this.Dl=c|0,this.Eh=u|0,this.El=a|0,this.Fh=l|0,this.Fl=h|0,this.Gh=g|0,this.Gl=m|0,this.Hh=b|0,this.Hl=v|0}process(e,n){for(let C=0;C<16;C++,n+=4)Tt[C]=e.getUint32(n),Rt[C]=e.getUint32(n+=4);for(let C=16;C<80;C++){const H=Tt[C-15]|0,_=Rt[C-15]|0,k=At(H,_,1)^At(H,_,8)^wr(H,_,7),P=St(H,_,1)^St(H,_,8)^xr(H,_,7),R=Tt[C-2]|0,d=Rt[C-2]|0,w=At(R,d,19)^se(R,d,61)^wr(R,d,6),p=St(R,d,19)^ie(R,d,61)^xr(R,d,6),y=xi(P,p,Rt[C-7],Rt[C-16]),x=vi(y,k,w,Tt[C-7],Tt[C-16]);Tt[C]=x|0,Rt[C]=y|0}let{Ah:r,Al:o,Bh:s,Bl:i,Ch:f,Cl:c,Dh:u,Dl:a,Eh:l,El:h,Fh:g,Fl:m,Gh:b,Gl:v,Hh:L,Hl:V}=this;for(let C=0;C<80;C++){const H=At(l,h,14)^At(l,h,18)^se(l,h,41),_=St(l,h,14)^St(l,h,18)^ie(l,h,41),k=l&g^~l&b,P=h&m^~h&v,R=Ei(V,_,P,Ki[C],Rt[C]),d=Bi(R,L,H,k,qi[C],Tt[C]),w=R|0,p=At(r,o,28)^se(r,o,34)^se(r,o,39),y=St(r,o,28)^ie(r,o,34)^ie(r,o,39),x=r&s^r&f^s&f,B=o&i^o&c^i&c;L=b|0,V=v|0,b=g|0,v=m|0,g=l|0,m=h|0,{h:l,l:h}=dt(u|0,a|0,d|0,w|0),u=f|0,a=c|0,f=s|0,c=i|0,s=r|0,i=o|0;const E=Qe(w,y,B);r=tn(E,d,p,x),o=E|0}({h:r,l:o}=dt(this.Ah|0,this.Al|0,r|0,o|0)),{h:s,l:i}=dt(this.Bh|0,this.Bl|0,s|0,i|0),{h:f,l:c}=dt(this.Ch|0,this.Cl|0,f|0,c|0),{h:u,l:a}=dt(this.Dh|0,this.Dl|0,u|0,a|0),{h:l,l:h}=dt(this.Eh|0,this.El|0,l|0,h|0),{h:g,l:m}=dt(this.Fh|0,this.Fl|0,g|0,m|0),{h:b,l:v}=dt(this.Gh|0,this.Gl|0,b|0,v|0),{h:L,l:V}=dt(this.Hh|0,this.Hl|0,L|0,V|0),this.set(r,o,s,i,f,c,u,a,l,h,g,m,b,v,L,V)}roundClean(){ut(Tt,Rt)}destroy(){ut(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class Fi extends fn{constructor(){super(48),this.Ah=W[0]|0,this.Al=W[1]|0,this.Bh=W[2]|0,this.Bl=W[3]|0,this.Ch=W[4]|0,this.Cl=W[5]|0,this.Dh=W[6]|0,this.Dl=W[7]|0,this.Eh=W[8]|0,this.El=W[9]|0,this.Fh=W[10]|0,this.Fl=W[11]|0,this.Gh=W[12]|0,this.Gl=W[13]|0,this.Hh=W[14]|0,this.Hl=W[15]|0}}const X=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class zi extends fn{constructor(){super(32),this.Ah=X[0]|0,this.Al=X[1]|0,this.Bh=X[2]|0,this.Bl=X[3]|0,this.Ch=X[4]|0,this.Cl=X[5]|0,this.Dh=X[6]|0,this.Dl=X[7]|0,this.Eh=X[8]|0,this.El=X[9]|0,this.Fh=X[10]|0,this.Fl=X[11]|0,this.Gh=X[12]|0,this.Gl=X[13]|0,this.Hh=X[14]|0,this.Hl=X[15]|0}}const Ae=ae(()=>new Vi),Gi=ae(()=>new fn),Zi=ae(()=>new Fi),Wi=ae(()=>new zi),Yi=Uint8Array.from([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9]),F=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),N=new Uint32Array(32);function $t(t,e,n,r,o,s){const i=o[s],f=o[s+1];let c=N[2*t],u=N[2*t+1],a=N[2*e],l=N[2*e+1],h=N[2*n],g=N[2*n+1],m=N[2*r],b=N[2*r+1],v=Qe(c,a,i);u=tn(v,u,l,f),c=v|0,{Dh:b,Dl:m}={Dh:b^u,Dl:m^c},{Dh:b,Dl:m}={Dh:pi(b,m),Dl:gi(b)},{h:g,l:h}=dt(g,h,b,m),{Bh:l,Bl:a}={Bh:l^g,Bl:a^h},{Bh:l,Bl:a}={Bh:At(l,a,24),Bl:St(l,a,24)},N[2*t]=c,N[2*t+1]=u,N[2*e]=a,N[2*e+1]=l,N[2*n]=h,N[2*n+1]=g,N[2*r]=m,N[2*r+1]=b}function Ct(t,e,n,r,o,s){const i=o[s],f=o[s+1];let c=N[2*t],u=N[2*t+1],a=N[2*e],l=N[2*e+1],h=N[2*n],g=N[2*n+1],m=N[2*r],b=N[2*r+1],v=Qe(c,a,i);u=tn(v,u,l,f),c=v|0,{Dh:b,Dl:m}={Dh:b^u,Dl:m^c},{Dh:b,Dl:m}={Dh:At(b,m,16),Dl:St(b,m,16)},{h:g,l:h}=dt(g,h,b,m),{Bh:l,Bl:a}={Bh:l^g,Bl:a^h},{Bh:l,Bl:a}={Bh:se(l,a,63),Bl:ie(l,a,63)},N[2*t]=c,N[2*t+1]=u,N[2*e]=a,N[2*e+1]=l,N[2*n]=h,N[2*n+1]=g,N[2*r]=m,N[2*r+1]=b}function Xi(t,e={},n,r,o){if(mt(n),t<0||t>n)throw new Error("outputLen bigger than keyLen");const{key:s,salt:i,personalization:f}=e;if(s!==void 0&&(s.length<1||s.length>n))throw new Error("key length must be undefined or 1.."+n);if(i!==void 0&&i.length!==r)throw new Error("salt must be undefined or "+r);if(f!==void 0&&f.length!==o)throw new Error("personalization must be undefined or "+o)}class Ji extends Ie{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,mt(e),mt(n),this.blockLen=e,this.outputLen=n,this.buffer=new Uint8Array(e),this.buffer32=fe(this.buffer)}update(e){Nt(this),e=ht(e),at(e);const{blockLen:n,buffer:r,buffer32:o}=this,s=e.length,i=e.byteOffset,f=e.buffer;for(let c=0;c<s;){this.pos===n&&(Ot(o),this.compress(o,0,!1),Ot(o),this.pos=0);const u=Math.min(n-this.pos,s-c),a=i+c;if(u===n&&!(a%4)&&c+u<s){const l=new Uint32Array(f,a,Math.floor((s-c)/4));Ot(l);for(let h=0;c+n<s;h+=o.length,c+=n)this.length+=n,this.compress(l,h,!1);Ot(l);continue}r.set(e.subarray(c,c+u),this.pos),this.pos+=u,this.length+=u,c+=u}return this}digestInto(e){Nt(this),rn(e,this);const{pos:n,buffer32:r}=this;this.finished=!0,ut(this.buffer.subarray(n)),Ot(r),this.compress(r,0,!0),Ot(r);const o=fe(e);this.get().forEach((s,i)=>o[i]=wt(s))}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){const{buffer:n,length:r,finished:o,destroyed:s,outputLen:i,pos:f}=this;return e||(e=new this.constructor({dkLen:i})),e.set(...this.get()),e.buffer.set(n),e.destroyed=s,e.finished=o,e.length=r,e.pos=f,e.outputLen=i,e}clone(){return this._cloneInto()}}class Qi extends Ji{constructor(e={}){const n=e.dkLen===void 0?64:e.dkLen;super(128,n),this.v0l=F[0]|0,this.v0h=F[1]|0,this.v1l=F[2]|0,this.v1h=F[3]|0,this.v2l=F[4]|0,this.v2h=F[5]|0,this.v3l=F[6]|0,this.v3h=F[7]|0,this.v4l=F[8]|0,this.v4h=F[9]|0,this.v5l=F[10]|0,this.v5h=F[11]|0,this.v6l=F[12]|0,this.v6h=F[13]|0,this.v7l=F[14]|0,this.v7h=F[15]|0,Xi(n,e,64,16,16);let{key:r,personalization:o,salt:s}=e,i=0;if(r!==void 0&&(r=ht(r),i=r.length),this.v0l^=this.outputLen|i<<8|65536|1<<24,s!==void 0){s=ht(s);const f=fe(s);this.v4l^=wt(f[0]),this.v4h^=wt(f[1]),this.v5l^=wt(f[2]),this.v5h^=wt(f[3])}if(o!==void 0){o=ht(o);const f=fe(o);this.v6l^=wt(f[0]),this.v6h^=wt(f[1]),this.v7l^=wt(f[2]),this.v7h^=wt(f[3])}if(r!==void 0){const f=new Uint8Array(this.blockLen);f.set(r),this.update(f)}}get(){let{v0l:e,v0h:n,v1l:r,v1h:o,v2l:s,v2h:i,v3l:f,v3h:c,v4l:u,v4h:a,v5l:l,v5h:h,v6l:g,v6h:m,v7l:b,v7h:v}=this;return[e,n,r,o,s,i,f,c,u,a,l,h,g,m,b,v]}set(e,n,r,o,s,i,f,c,u,a,l,h,g,m,b,v){this.v0l=e|0,this.v0h=n|0,this.v1l=r|0,this.v1h=o|0,this.v2l=s|0,this.v2h=i|0,this.v3l=f|0,this.v3h=c|0,this.v4l=u|0,this.v4h=a|0,this.v5l=l|0,this.v5h=h|0,this.v6l=g|0,this.v6h=m|0,this.v7l=b|0,this.v7h=v|0}compress(e,n,r){this.get().forEach((c,u)=>N[u]=c),N.set(F,16);let{h:o,l:s}=yr(BigInt(this.length));N[24]=F[8]^s,N[25]=F[9]^o,r&&(N[28]=~N[28],N[29]=~N[29]);let i=0;const f=Yi;for(let c=0;c<12;c++)$t(0,4,8,12,e,n+2*f[i++]),Ct(0,4,8,12,e,n+2*f[i++]),$t(1,5,9,13,e,n+2*f[i++]),Ct(1,5,9,13,e,n+2*f[i++]),$t(2,6,10,14,e,n+2*f[i++]),Ct(2,6,10,14,e,n+2*f[i++]),$t(3,7,11,15,e,n+2*f[i++]),Ct(3,7,11,15,e,n+2*f[i++]),$t(0,5,10,15,e,n+2*f[i++]),Ct(0,5,10,15,e,n+2*f[i++]),$t(1,6,11,12,e,n+2*f[i++]),Ct(1,6,11,12,e,n+2*f[i++]),$t(2,7,8,13,e,n+2*f[i++]),Ct(2,7,8,13,e,n+2*f[i++]),$t(3,4,9,14,e,n+2*f[i++]),Ct(3,4,9,14,e,n+2*f[i++]);this.v0l^=N[0]^N[16],this.v0h^=N[1]^N[17],this.v1l^=N[2]^N[18],this.v1h^=N[3]^N[19],this.v2l^=N[4]^N[20],this.v2h^=N[5]^N[21],this.v3l^=N[6]^N[22],this.v3h^=N[7]^N[23],this.v4l^=N[8]^N[24],this.v4h^=N[9]^N[25],this.v5l^=N[10]^N[26],this.v5h^=N[11]^N[27],this.v6l^=N[12]^N[28],this.v6h^=N[13]^N[29],this.v7l^=N[14]^N[30],this.v7h^=N[15]^N[31],ut(N)}destroy(){this.destroyed=!0,ut(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const tf=Ni(t=>new Qi(t)),ef="https://rpc.walletconnect.org/v1";function cn(t){const e=`Ethereum Signed Message: ${t.length}`,n=new TextEncoder().encode(e+t);return"0x"+Buffer.from(ki(n)).toString("hex")}async function $r(t,e,n,r,o,s){switch(n.t){case"eip191":return await Cr(t,e,n.s);case"eip1271":return await Lr(t,e,n.s,r,o,s);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${n.t}`)}}async function Cr(t,e,n){return(await xs({hash:cn(e),signature:n})).toLowerCase()===t.toLowerCase()}async function Lr(t,e,n,r,o,s){const i=Fe(r);if(!i.namespace||!i.reference)throw new Error(`isValidEip1271Signature failed: chainId must be in CAIP-2 format, received: ${r}`);try{const f="0x1626ba7e",c="0000000000000000000000000000000000000000000000000000000000000040",u=n.substring(2),a=(u.length/2).toString(16).padStart(64,"0"),l=(e.startsWith("0x")?e:cn(e)).substring(2),h=f+l+c+a+u,g=await fetch(`${s||ef}/?chainId=${r}&projectId=${o}`,{headers:{"Content-Type":"application/json"},method:"POST",body:JSON.stringify({id:nf(),jsonrpc:"2.0",method:"eth_call",params:[{to:t,data:h},"latest"]})}),{result:m}=await g.json();return m?m.slice(0,f.length).toLowerCase()===f.toLowerCase():!1}catch(f){return console.error("isValidEip1271Signature: ",f),!1}}function nf(){return Date.now()+Math.floor(Math.random()*1e3)}function rf(t){const e=atob(t),n=new Uint8Array(e.length);for(let i=0;i<e.length;i++)n[i]=e.charCodeAt(i);const r=n[0];if(r===0)throw new Error("No signatures found");const o=1+r*64;if(n.length<o)throw new Error("Transaction data too short for claimed signature count");if(n.length<100)throw new Error("Transaction too short");const s=Buffer.from(t,"base64").slice(1,65);return re.encode(s)}function of(t){const e=new Uint8Array(Buffer.from(t,"base64")),n=Array.from("TransactionData::").map(s=>s.charCodeAt(0)),r=new Uint8Array(n.length+e.length);r.set(n),r.set(e,n.length);const o=tf(r,{dkLen:32});return re.encode(o)}function sf(t){const e=new Uint8Array(Ae(jr(t)));return re.encode(e)}function jr(t){if(t instanceof Uint8Array)return t;if(Array.isArray(t))return new Uint8Array(t);if(typeof t=="object"&&t!=null&&t.data)return new Uint8Array(Object.values(t.data));if(typeof t=="object"&&t)return new Uint8Array(Object.values(t));throw new Error("getNearUint8ArrayFromBytes: Unexpected result type from bytes array")}function ff(t){const e=Buffer.from(t,"base64"),n=vs(e).txn;if(!n)throw new Error("Invalid signed transaction: missing 'txn' field");const r=Es(n),o=Buffer.from("TX"),s=Buffer.concat([o,Buffer.from(r)]),i=Wi(s);return Bs.encode(i).replace(/=+$/,"")}function an(t){const e=[];let n=BigInt(t);for(;n>=BigInt(128);)e.push(Number(n&BigInt(127)|BigInt(128))),n>>=BigInt(7);return e.push(Number(n)),Buffer.from(e)}function cf(t){const e=Buffer.from(t.signed.bodyBytes,"base64"),n=Buffer.from(t.signed.authInfoBytes,"base64"),r=Buffer.from(t.signature.signature,"base64"),o=[];o.push(Buffer.from([10])),o.push(an(e.length)),o.push(e),o.push(Buffer.from([18])),o.push(an(n.length)),o.push(n),o.push(Buffer.from([26])),o.push(an(r.length)),o.push(r);const s=Buffer.concat(o),i=Ae(s);return Buffer.from(i).toString("hex").toUpperCase()}var af=Object.defineProperty,uf=Object.defineProperties,lf=Object.getOwnPropertyDescriptors,kr=Object.getOwnPropertySymbols,df=Object.prototype.hasOwnProperty,hf=Object.prototype.propertyIsEnumerable,Pr=(t,e,n)=>e in t?af(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,un=(t,e)=>{for(var n in e||(e={}))df.call(e,n)&&Pr(t,n,e[n]);if(kr)for(var n of kr(e))hf.call(e,n)&&Pr(t,n,e[n]);return t},Hr=(t,e)=>uf(t,lf(e));const pf="did:pkh:",Se=t=>t?.split(":"),Dr=t=>{const e=t&&Se(t);if(e)return t.includes(pf)?e[3]:e[1]},Mr=t=>{const e=t&&Se(t);if(e)return e[2]+":"+e[3]},ln=t=>{const e=t&&Se(t);if(e)return e.pop()};async function gf(t){const{cacao:e,projectId:n}=t,{s:r,p:o}=e,s=Vr(o,o.iss),i=ln(o.iss);return await $r(i,s,r,Mr(o.iss),n)}const Vr=(t,e)=>{const n=`${t.domain} wants you to sign in with your Ethereum account:`,r=ln(e);if(!t.aud&&!t.uri)throw new Error("Either `aud` or `uri` is required to construct the message");let o=t.statement||void 0;const s=`URI: ${t.aud||t.uri}`,i=`Version: ${t.version}`,f=`Chain ID: ${Dr(e)}`,c=`Nonce: ${t.nonce}`,u=`Issued At: ${t.iat}`,a=t.exp?`Expiration Time: ${t.exp}`:void 0,l=t.nbf?`Not Before: ${t.nbf}`:void 0,h=t.requestId?`Request ID: ${t.requestId}`:void 0,g=t.resources?`Resources:${t.resources.map(b=>` - ${b}`).join("")}`:void 0,m=Oe(t.resources);if(m){const b=Lt(m);o=pn(o,b)}return[n,r,"",o,"",s,i,f,c,u,a,l,h,g].filter(b=>b!=null).join(` `)};function bf(t,e,n){return n.includes("did:pkh:")||(n=`did:pkh:${n}`),{h:{t:"caip122"},p:{iss:n,domain:t.domain,aud:t.aud,version:t.version,nonce:t.nonce,iat:t.iat,statement:t.statement,requestId:t.requestId,resources:t.resources,nbf:t.nbf,exp:t.exp},s:e}}function yf(t){var e;const{authPayload:n,chains:r,methods:o}=t,s=n.statement||"";if(!(r!=null&&r.length))return n;const i=n.chains,f=Xe(i,r);if(!(f!=null&&f.length))throw new Error("No supported chains");const c=qr(n.resources);if(!c)return n;bt(c);const u=Kr(c,"eip155");let a=n?.resources||[];if(u!=null&&u.length){const l=Fr(u),h=Xe(l,o);if(!(h!=null&&h.length))throw new Error(`Supported methods don't satisfy the requested: ${JSON.stringify(l)}, supported: ${JSON.stringify(o)}`);const g=dn("request",h,{chains:f}),m=Wr(c,"eip155",g);a=((e=n?.resources)==null?void 0:e.slice(0,-1))||[],a.push(Ne(m))}return Hr(un({},n),{statement:Xr(s,Oe(a)),chains:f,resources:n!=null&&n.resources||a.length>0?a:void 0})}function qr(t){const e=Oe(t);if(e&&hn(e))return Lt(e)}function mf(t,e){var n;return(n=t?.att)==null?void 0:n.hasOwnProperty(e)}function Kr(t,e){var n,r;return(n=t?.att)!=null&&n[e]?Object.keys((r=t?.att)==null?void 0:r[e]):[]}function wf(t){return t?.map(e=>Object.keys(e))||[]}function Fr(t){return t?.map(e=>{var n;return(n=e.split("/"))==null?void 0:n[1]})||[]}function zr(t){return Buffer.from(JSON.stringify(t)).toString("base64")}function Gr(t){return JSON.parse(Buffer.from(t,"base64").toString("utf-8"))}function bt(t){if(!t)throw new Error("No recap provided, value is undefined");if(!t.att)throw new Error("No `att` property found");const e=Object.keys(t.att);if(!(e!=null&&e.length))throw new Error("No resources found in `att` property");e.forEach(n=>{const r=t.att[n];if(Array.isArray(r))throw new Error(`Resource must be an object: ${n}`);if(typeof r!="object")throw new Error(`Resource must be an object: ${n}`);if(!Object.keys(r).length)throw new Error(`Resource object is empty: ${n}`);Object.keys(r).forEach(o=>{const s=r[o];if(!Array.isArray(s))throw new Error(`Ability limits ${o} must be an array of objects, found: ${s}`);if(!s.length)throw new Error(`Value of ${o} is empty array, must be an array with objects`);s.forEach(i=>{if(typeof i!="object")throw new Error(`Ability limits (${o}) must be an array of objects, found: ${i}`)})})})}function Zr(t,e,n,r={}){return n?.sort((o,s)=>o.localeCompare(s)),{att:{[t]:dn(e,n,r)}}}function Wr(t,e,n){var r;t.att[e]=un({},n);const o=(r=Object.keys(t.att))==null?void 0:r.sort((i,f)=>i.localeCompare(f)),s={att:{}};return o.reduce((i,f)=>(i.att[f]=t.att[f],i),s)}function dn(t,e,n={}){e=e?.sort((o,s)=>o.localeCompare(s));const r=e.map(o=>({[`${t}/${o}`]:[n]}));return Object.assign({},...r)}function Ne(t){return bt(t),`urn:recap:${zr(t).replace(/=/g,"")}`}function Lt(t){const e=Gr(t.replace("urn:recap:",""));return bt(e),e}function xf(t,e,n){const r=Zr(t,e,n);return Ne(r)}function hn(t){return t&&t.includes("urn:recap:")}function vf(t,e){const n=Lt(t),r=Lt(e),o=Yr(n,r);return Ne(o)}function Yr(t,e){bt(t),bt(e);const n=Object.keys(t.att).concat(Object.keys(e.att)).sort((o,s)=>o.localeCompare(s)),r={att:{}};return n.forEach(o=>{var s,i;Object.keys(((s=t.att)==null?void 0:s[o])||{}).concat(Object.keys(((i=e.att)==null?void 0:i[o])||{})).sort((f,c)=>f.localeCompare(c)).forEach(f=>{var c,u;r.att[o]=Hr(un({},r.att[o]),{[f]:((c=t.att[o])==null?void 0:c[f])||((u=e.att[o])==null?void 0:u[f])})})}),r}function pn(t="",e){bt(e);const n="I further authorize the stated URI to perform the following actions on my behalf: ";if(t.includes(n))return t;const r=[];let o=0;Object.keys(e.att).forEach(f=>{const c=Object.keys(e.att[f]).map(l=>({ability:l.split("/")[0],action:l.split("/")[1]}));c.sort((l,h)=>l.action.localeCompare(h.action));const u={};c.forEach(l=>{u[l.ability]||(u[l.ability]=[]),u[l.ability].push(l.action)});const a=Object.keys(u).map(l=>(o++,`(${o}) '${l}': '${u[l].join("', '")}' for '${f}'.`));r.push(a.join(", ").replace(".,","."))});const s=r.join(" "),i=`${n}${s}`;return`${t?t+" ":""}${i}`}function Ef(t){var e;const n=Lt(t);bt(n);const r=(e=n.att)==null?void 0:e.eip155;return r?Object.keys(r).map(o=>o.split("/")[1]):[]}function Bf(t){const e=Lt(t);bt(e);const n=[];return Object.values(e.att).forEach(r=>{Object.values(r).forEach(o=>{var s;(s=o?.[0])!=null&&s.chains&&n.push(o[0].chains)})}),[...new Set(n.flat())]}function Xr(t,e){if(!e)return t;const n=Lt(e);return bt(n),pn(t,n)}function Oe(t){if(!t)return;const e=t?.[t.length-1];return hn(e)?e:void 0}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */function Jr(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function gn(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function bn(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function nt(t,...e){if(!Jr(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Qr(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function If(t,e){nt(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function jt(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Wt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Af(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}const Sf=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Nf(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function yn(t){if(typeof t=="string")t=Nf(t);else if(Jr(t))t=mn(t);else throw new Error("Uint8Array expected, got "+typeof t);return t}function Of(t,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(t,e)}function Uf(t,e){if(t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t[r]^e[r];return n===0}const _f=(t,e)=>{function n(r,...o){if(nt(r),!Sf)throw new Error("Non little-endian hardware is not yet supported");if(t.nonceLength!==void 0){const a=o[0];if(!a)throw new Error("nonce / iv required");t.varSizeNonce?nt(a):nt(a,t.nonceLength)}const s=t.tagLength;s&&o[1]!==void 0&&nt(o[1]);const i=e(r,...o),f=(a,l)=>{if(l!==void 0){if(a!==2)throw new Error("cipher output not supported");nt(l)}};let c=!1;return{encrypt(a,l){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,nt(a),f(i.encrypt.length,l),i.encrypt(a,l)},decrypt(a,l){if(nt(a),s&&a.length<s)throw new Error("invalid ciphertext length: smaller than tagLength="+s);return f(i.decrypt.length,l),i.decrypt(a,l)}}}return Object.assign(n,t),n};function to(t,e,n=!0){if(e===void 0)return new Uint8Array(t);if(e.length!==t)throw new Error("invalid output length, expected "+t+", got: "+e.length);if(n&&!Rf(e))throw new Error("invalid output, must be aligned");return e}function eo(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const o=BigInt(32),s=BigInt(4294967295),i=Number(n>>o&s),f=Number(n&s),c=r?4:0,u=r?0:4;t.setUint32(e+c,i,r),t.setUint32(e+u,f,r)}function Tf(t,e,n){gn(n);const r=new Uint8Array(16),o=Af(r);return eo(o,0,BigInt(e),n),eo(o,8,BigInt(t),n),r}function Rf(t){return t.byteOffset%4===0}function mn(t){return Uint8Array.from(t)}const no=t=>Uint8Array.from(t.split("").map(e=>e.charCodeAt(0))),$f=no("expand 16-byte k"),Cf=no("expand 32-byte k"),Lf=jt($f),jf=jt(Cf);function M(t,e){return t<<e|t>>>32-e}function wn(t){return t.byteOffset%4===0}const Ue=64,kf=16,ro=2**32-1,oo=new Uint32Array;function Pf(t,e,n,r,o,s,i,f){const c=o.length,u=new Uint8Array(Ue),a=jt(u),l=wn(o)&&wn(s),h=l?jt(o):oo,g=l?jt(s):oo;for(let m=0;m<c;i++){if(t(e,n,r,a,i,f),i>=ro)throw new Error("arx: counter overflow");const b=Math.min(Ue,c-m);if(l&&b===Ue){const v=m/4;if(m%4!==0)throw new Error("arx: invalid block position");for(let L=0,V;L<kf;L++)V=v+L,g[V]=h[V]^a[L];m+=Ue;continue}for(let v=0,L;v<b;v++)L=m+v,s[L]=o[L]^u[v];m+=b}}function Hf(t,e){const{allowShortKeys:n,extendNonceFn:r,counterLength:o,counterRight:s,rounds:i}=Of({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return bn(o),bn(i),gn(s),gn(n),(f,c,u,a,l=0)=>{nt(f),nt(c),nt(u);const h=u.length;if(a===void 0&&(a=new Uint8Array(h)),nt(a),bn(l),l<0||l>=ro)throw new Error("arx: counter overflow");if(a.length<h)throw new Error(`arx: output (${a.length}) is shorter than data (${h})`);const g=[];let m=f.length,b,v;if(m===32)g.push(b=mn(f)),v=jf;else if(m===16&&n)b=new Uint8Array(32),b.set(f),b.set(f,16),v=Lf,g.push(b);else throw new Error(`arx: invalid 32-byte key, got length=${m}`);wn(c)||g.push(c=mn(c));const L=jt(b);if(r){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(v,L,jt(c.subarray(0,16)),L),c=c.subarray(16)}const V=16-o;if(V!==c.length)throw new Error(`arx: nonce must be ${V} or 16 bytes`);if(V!==12){const H=new Uint8Array(12);H.set(c,s?0:12-c.length),c=H,g.push(c)}const C=jt(c);return Pf(t,v,L,C,u,a,l,i),Wt(...g),a}}const G=(t,e)=>t[e++]&255|(t[e++]&255)<<8;class Df{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=yn(e),nt(e,32);const n=G(e,0),r=G(e,2),o=G(e,4),s=G(e,6),i=G(e,8),f=G(e,10),c=G(e,12),u=G(e,14);this.r[0]=n&8191,this.r[1]=(n>>>13|r<<3)&8191,this.r[2]=(r>>>10|o<<6)&7939,this.r[3]=(o>>>7|s<<9)&8191,this.r[4]=(s>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|f<<2)&8191,this.r[7]=(f>>>11|c<<5)&8065,this.r[8]=(c>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let a=0;a<8;a++)this.pad[a]=G(e,16+2*a)}process(e,n,r=!1){const o=r?0:2048,{h:s,r:i}=this,f=i[0],c=i[1],u=i[2],a=i[3],l=i[4],h=i[5],g=i[6],m=i[7],b=i[8],v=i[9],L=G(e,n+0),V=G(e,n+2),C=G(e,n+4),H=G(e,n+6),_=G(e,n+8),k=G(e,n+10),P=G(e,n+12),R=G(e,n+14);let d=s[0]+(L&8191),w=s[1]+((L>>>13|V<<3)&8191),p=s[2]+((V>>>10|C<<6)&8191),y=s[3]+((C>>>7|H<<9)&8191),x=s[4]+((H>>>4|_<<12)&8191),B=s[5]+(_>>>1&8191),E=s[6]+((_>>>14|k<<2)&8191),I=s[7]+((k>>>11|P<<5)&8191),S=s[8]+((P>>>8|R<<8)&8191),O=s[9]+(R>>>5|o),A=0,T=A+d*f+w*(5*v)+p*(5*b)+y*(5*m)+x*(5*g);A=T>>>13,T&=8191,T+=B*(5*h)+E*(5*l)+I*(5*a)+S*(5*u)+O*(5*c),A+=T>>>13,T&=8191;let U=A+d*c+w*f+p*(5*v)+y*(5*b)+x*(5*m);A=U>>>13,U&=8191,U+=B*(5*g)+E*(5*h)+I*(5*l)+S*(5*a)+O*(5*u),A+=U>>>13,U&=8191;let $=A+d*u+w*c+p*f+y*(5*v)+x*(5*b);A=$>>>13,$&=8191,$+=B*(5*m)+E*(5*g)+I*(5*h)+S*(5*l)+O*(5*a),A+=$>>>13,$&=8191;let D=A+d*a+w*u+p*c+y*f+x*(5*v);A=D>>>13,D&=8191,D+=B*(5*b)+E*(5*m)+I*(5*g)+S*(5*h)+O*(5*l),A+=D>>>13,D&=8191;let q=A+d*l+w*a+p*u+y*c+x*f;A=q>>>13,q&=8191,q+=B*(5*v)+E*(5*b)+I*(5*m)+S*(5*g)+O*(5*h),A+=q>>>13,q&=8191;let j=A+d*h+w*l+p*a+y*u+x*c;A=j>>>13,j&=8191,j+=B*f+E*(5*v)+I*(5*b)+S*(5*m)+O*(5*g),A+=j>>>13,j&=8191;let K=A+d*g+w*h+p*l+y*a+x*u;A=K>>>13,K&=8191,K+=B*c+E*f+I*(5*v)+S*(5*b)+O*(5*m),A+=K>>>13,K&=8191;let et=A+d*m+w*g+p*h+y*l+x*a;A=et>>>13,et&=8191,et+=B*u+E*c+I*f+S*(5*v)+O*(5*b),A+=et>>>13,et&=8191;let Z=A+d*b+w*m+p*g+y*h+x*l;A=Z>>>13,Z&=8191,Z+=B*a+E*u+I*c+S*f+O*(5*v),A+=Z>>>13,Z&=8191;let z=A+d*v+w*b+p*m+y*g+x*h;A=z>>>13,z&=8191,z+=B*l+E*a+I*u+S*c+O*f,A+=z>>>13,z&=8191,A=(A<<2)+A|0,A=A+T|0,T=A&8191,A=A>>>13,U+=A,s[0]=T,s[1]=U,s[2]=$,s[3]=D,s[4]=q,s[5]=j,s[6]=K,s[7]=et,s[8]=Z,s[9]=z}finalize(){const{h:e,pad:n}=this,r=new Uint16Array(10);let o=e[1]>>>13;e[1]&=8191;for(let f=2;f<10;f++)e[f]+=o,o=e[f]>>>13,e[f]&=8191;e[0]+=o*5,o=e[0]>>>13,e[0]&=8191,e[1]+=o,o=e[1]>>>13,e[1]&=8191,e[2]+=o,r[0]=e[0]+5,o=r[0]>>>13,r[0]&=8191;for(let f=1;f<10;f++)r[f]=e[f]+o,o=r[f]>>>13,r[f]&=8191;r[9]-=8192;let s=(o^1)-1;for(let f=0;f<10;f++)r[f]&=s;s=~s;for(let f=0;f<10;f++)e[f]=e[f]&s|r[f];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let i=e[0]+n[0];e[0]=i&65535;for(let f=1;f<8;f++)i=(e[f]+n[f]|0)+(i>>>16)|0,e[f]=i&65535;Wt(r)}update(e){Qr(this),e=yn(e),nt(e);const{buffer:n,blockLen:r}=this,o=e.length;for(let s=0;s<o;){const i=Math.min(r-this.pos,o-s);if(i===r){for(;r<=o-s;s+=r)this.process(e,s);continue}n.set(e.subarray(s,s+i),this.pos),this.pos+=i,s+=i,this.pos===r&&(this.process(n,0,!1),this.pos=0)}return this}destroy(){Wt(this.h,this.r,this.buffer,this.pad)}digestInto(e){Qr(this),If(e,this),this.finished=!0;const{buffer:n,h:r}=this;let{pos:o}=this;if(o){for(n[o++]=1;o<16;o++)n[o]=0;this.process(n,0,!0)}this.finalize();let s=0;for(let i=0;i<8;i++)e[s++]=r[i]>>>0,e[s++]=r[i]>>>8;return e}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}}function Mf(t){const e=(r,o)=>t(o).update(yn(r)).digest(),n=t(new Uint8Array(32));return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}const Vf=Mf(t=>new Df(t));function qf(t,e,n,r,o,s=20){let i=t[0],f=t[1],c=t[2],u=t[3],a=e[0],l=e[1],h=e[2],g=e[3],m=e[4],b=e[5],v=e[6],L=e[7],V=o,C=n[0],H=n[1],_=n[2],k=i,P=f,R=c,d=u,w=a,p=l,y=h,x=g,B=m,E=b,I=v,S=L,O=V,A=C,T=H,U=_;for(let D=0;D<s;D+=2)k=k+w|0,O=M(O^k,16),B=B+O|0,w=M(w^B,12),k=k+w|0,O=M(O^k,8),B=B+O|0,w=M(w^B,7),P=P+p|0,A=M(A^P,16),E=E+A|0,p=M(p^E,12),P=P+p|0,A=M(A^P,8),E=E+A|0,p=M(p^E,7),R=R+y|0,T=M(T^R,16),I=I+T|0,y=M(y^I,12),R=R+y|0,T=M(T^R,8),I=I+T|0,y=M(y^I,7),d=d+x|0,U=M(U^d,16),S=S+U|0,x=M(x^S,12),d=d+x|0,U=M(U^d,8),S=S+U|0,x=M(x^S,7),k=k+p|0,U=M(U^k,16),I=I+U|0,p=M(p^I,12),k=k+p|0,U=M(U^k,8),I=I+U|0,p=M(p^I,7),P=P+y|0,O=M(O^P,16),S=S+O|0,y=M(y^S,12),P=P+y|0,O=M(O^P,8),S=S+O|0,y=M(y^S,7),R=R+x|0,A=M(A^R,16),B=B+A|0,x=M(x^B,12),R=R+x|0,A=M(A^R,8),B=B+A|0,x=M(x^B,7),d=d+w|0,T=M(T^d,16),E=E+T|0,w=M(w^E,12),d=d+w|0,T=M(T^d,8),E=E+T|0,w=M(w^E,7);let $=0;r[$++]=i+k|0,r[$++]=f+P|0,r[$++]=c+R|0,r[$++]=u+d|0,r[$++]=a+w|0,r[$++]=l+p|0,r[$++]=h+y|0,r[$++]=g+x|0,r[$++]=m+B|0,r[$++]=b+E|0,r[$++]=v+I|0,r[$++]=L+S|0,r[$++]=V+O|0,r[$++]=C+A|0,r[$++]=H+T|0,r[$++]=_+U|0}const Kf=Hf(qf,{counterRight:!1,counterLength:4,allowShortKeys:!1}),Ff=new Uint8Array(16),so=(t,e)=>{t.update(e);const n=e.length%16;n&&t.update(Ff.subarray(n))},zf=new Uint8Array(32);function io(t,e,n,r,o){const s=t(e,n,zf),i=Vf.create(s);o&&so(i,o),so(i,r);const f=Tf(r.length,o?o.length:0,!0);i.update(f);const c=i.digest();return Wt(s,f),c}const Gf=t=>(e,n,r)=>({encrypt(s,i){const f=s.length;i=to(f+16,i,!1),i.set(s);const c=i.subarray(0,-16);t(e,n,c,c,1);const u=io(t,e,n,c,r);return i.set(u,f),Wt(u),i},decrypt(s,i){i=to(s.length-16,i,!1);const f=s.subarray(0,-16),c=s.subarray(-16),u=io(t,e,n,f,r);if(!Uf(c,u))throw new Error("invalid tag");return i.set(s.subarray(0,-16)),t(e,n,i,i,1),Wt(u),i}}),fo=_f({blockSize:64,nonceLength:12,tagLength:16},Gf(Kf));class co extends Ie{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,nn(e);const r=ht(n);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const o=this.blockLen,s=new Uint