@walletconnect/utils
Version:
Utilities for WalletConnect Protocol
4 lines • 110 kB
JavaScript
import{detect as Ds}from"detect-browser";import{toMiliseconds as Xe,FIVE_MINUTES as er,fromMiliseconds as Vs}from"@walletconnect/time";import{getDocument as ae,getNavigator as nr,getLocation as rr}from"@walletconnect/window-getters";import{getWindowMetadata as Ms}from"@walletconnect/window-metadata";import{Signature as Ks,Secp256k1 as qs}from"ox";import ue from"bs58";import{decode as Fs,encode as Zs}from"@msgpack/msgpack";import{base32 as Gs}from"@scure/base";import{decodeJWT as zs}from"@walletconnect/relay-auth";import{toString as it,fromString as at,concat as le}from"uint8arrays";import{RELAY_JSONRPC as Ys}from"@walletconnect/relay-api";import{blake2b as Ws}from"blakejs";import{generatePlatformLogger as Xs}from"@walletconnect/logger";const Ae=":";function Je(t){const[e,n]=t.split(Ae);return{namespace:e,reference:n}}function or(t){const{namespace:e,reference:n}=t;return[e,n].join(Ae)}function Qe(t){const[e,n,r]=t.split(Ae);return{namespace:e,reference:n,address:r}}function sr(t){const{namespace:e,reference:n,address:r}=t;return[e,n,r].join(Ae)}function tn(t,e){const n=[];return t.forEach(r=>{const o=e(r);n.includes(o)||n.push(o)}),n}function ir(t){const{address:e}=Qe(t);return e}function cr(t){const{namespace:e,reference:n}=Qe(t);return or({namespace:e,reference:n})}function Js(t,e){const{namespace:n,reference:r}=Je(e);return sr({namespace:n,reference:r,address:t})}function Qs(t){return tn(t,ir)}function fr(t){return tn(t,cr)}function ti(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 ei(t,e=[]){const n=[];return Object.keys(t).forEach(r=>{if(e.length&&!e.includes(r))return;const o=t[r];n.push(...fr(o.accounts))}),n}function ni(t,e=[]){const n=[];return Object.keys(t).forEach(r=>{if(e.length&&!e.includes(r))return;const o=t[r];n.push(...Se(r,o))}),n}function Se(t,e){return t.includes(":")?[t]:e.chains||[]}var ri=Object.defineProperty,oi=Object.defineProperties,si=Object.getOwnPropertyDescriptors,ar=Object.getOwnPropertySymbols,ii=Object.prototype.hasOwnProperty,ci=Object.prototype.propertyIsEnumerable,en=(t,e,n)=>e in t?ri(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ur=(t,e)=>{for(var n in e||(e={}))ii.call(e,n)&&en(t,n,e[n]);if(ar)for(var n of ar(e))ci.call(e,n)&&en(t,n,e[n]);return t},fi=(t,e)=>oi(t,si(e)),lr=(t,e,n)=>en(t,typeof e!="symbol"?e+"":e,n);const dr="ReactNative",et={reactNative:"react-native",node:"node",browser:"browser",unknown:"unknown"},Oe=" ",ai=":",hr="/",nn=2,ui=1e3,pr="js";function rn(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function It(){return!ae()&&!!nr()&&navigator.product===dr}function li(){return It()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="android"}function di(){return It()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="ios"}function Wt(){return!rn()&&!!nr()&&!!ae()}function Vt(){return It()?et.reactNative:rn()?et.node:Wt()?et.browser:et.unknown}function hi(){var t;try{return It()&&typeof global<"u"&&typeof(global==null?void 0:global.Application)<"u"?(t=global.Application)==null?void 0:t.applicationId:void 0}catch{return}}function gr(t,e){const n=new URLSearchParams(t);return Object.entries(e).sort(([r],[o])=>r.localeCompare(o)).forEach(([r,o])=>{o!=null&&n.set(r,String(o))}),n.toString()}function pi(t){var e,n;const r=br();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!=="")),fi(ur(ur({},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 br(){return Ms()||{name:"",description:"",url:"",icons:[""]}}function gi(t,e){var n;const r=Vt(),o={protocol:t,version:e,env:r};return r==="browser"&&(o.host=((n=rr())==null?void 0:n.host)||"unknown"),o}function yr(){if(Vt()===et.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=Ds();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 mr(){var t;const e=Vt();return e===et.browser?[e,((t=rr())==null?void 0:t.host)||"unknown"].join(":"):e}function wr(t,e,n){const r=yr(),o=mr();return[[t,e].join("-"),[pr,n].join("-"),r,o].join("/")}function bi({protocol:t,version:e,relayUrl:n,sdkVersion:r,auth:o,projectId:s,useOnCloseEvent:i,bundleId:c,packageName:f}){const u=n.split("?"),a=wr(t,e,r),l={auth:o,ua:a,projectId:s,useOnCloseEvent:i||void 0,packageName:f||void 0,bundleId:c||void 0},d=gr(u[1]||"",l);return u[0]+"?"+d}function yi(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 mi(t,e,n){if(!t[e]||typeof t[e]!==n)throw new Error(`Missing or invalid "${e}" param`)}function vr(t,e=nn){return xr(t.split(hr),e)}function wi(t){return vr(t).join(Oe)}function At(t,e){return t.filter(n=>e.includes(n)).length===t.length}function xr(t,e=nn){return t.slice(Math.max(t.length-e,0))}function vi(t){return Object.fromEntries(t.entries())}function xi(t){return new Map(Object.entries(t))}function Ei(t,e){const n={};return Object.keys(t).forEach(r=>{n[r]=e(t[r])}),n}const Bi=t=>t;function Er(t){return t.trim().replace(/^\w/,e=>e.toUpperCase())}function Ii(t){return t.split(Oe).map(e=>Er(e)).join(Oe)}function Ai(t=er,e){const n=Xe(t||er);let r,o,s,i;return{resolve:c=>{s&&r&&(clearTimeout(s),r(c),i=Promise.resolve(c))},reject:c=>{s&&o&&(clearTimeout(s),o(c))},done:()=>new Promise((c,f)=>{if(i)return c(i);s=setTimeout(()=>{const u=new Error(e);i=Promise.reject(u),f(u)},n),r=c,o=f})}}function Si(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 on(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 Oi(t){return on("topic",t)}function Ni(t){return on("id",t)}function Ui(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 _i(t,e){return Vs((e||Date.now())+Xe(t))}function Ri(t){return Date.now()>=Xe(t)}function $i(t,e){return`${t}${e?`:${e}`:""}`}function ut(t=[],e=[]){return[...new Set([...t,...e])]}async function Ti({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=Br(s,t,e),c=Vt();if(c===et.browser){if(!((r=ae())!=null&&r.hasFocus())){console.warn("Document does not have focus, skipping deeplink.");return}Ir(i)}else c===et.reactNative&&typeof(global==null?void 0:global.Linking)<"u"&&await global.Linking.openURL(i)}catch(o){console.error(o)}}function Br(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}${Or(r,!0)}`}else o=`${o}/wc?${r}`;return o}function Ir(t){let e="_self";Sr()?e="_top":(Ar()||t.startsWith("https://")||t.startsWith("http://"))&&(e="_blank"),window.open(t,e,"noreferrer noopener")}async function Ci(t,e){let n="";try{if(Wt()&&(n=localStorage.getItem(e),n))return n;n=await t.getItem(e)}catch(r){console.error(r)}return n}function sn(t,e){return t.filter(n=>e.includes(n))}function ji(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 ki(){return typeof process<"u"&&process.env.IS_VITEST==="true"}function Ar(){return typeof window<"u"&&(!!window.TelegramWebviewProxy||!!window.Telegram||!!window.TelegramWebviewProxyProto)}function Sr(){try{return window.self!==window.top}catch{return!1}}function Or(t,e=!1){const n=Buffer.from(t).toString("base64");return e?n.replace(/[=]/g,""):n}function cn(t){return Buffer.from(t,"base64").toString("utf-8")}function Pi(t){return new Promise(e=>setTimeout(e,t))}class Hi{constructor({limit:e}){lr(this,"limit"),lr(this,"set"),this.limit=e,this.set=new Set}add(e){if(!this.set.has(e)){if(this.set.size>=this.limit){const n=this.set.values().next().value;n&&this.set.delete(n)}this.set.add(e)}}has(e){return this.set.has(e)}}const Ne=BigInt(2**32-1),Nr=BigInt(32);function Ur(t,e=!1){return e?{h:Number(t&Ne),l:Number(t>>Nr&Ne)}:{h:Number(t>>Nr&Ne)|0,l:Number(t&Ne)|0}}function _r(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:c}=Ur(t[s],e);[r[s],o[s]]=[i,c]}return[r,o]}const Rr=(t,e,n)=>t>>>n,$r=(t,e,n)=>t<<32-n|e>>>n,St=(t,e,n)=>t>>>n|e<<32-n,Ot=(t,e,n)=>t<<32-n|e>>>n,de=(t,e,n)=>t<<64-n|e>>>n-32,he=(t,e,n)=>t>>>n-32|e<<64-n,Di=(t,e)=>e,Vi=(t,e)=>t,Mi=(t,e,n)=>t<<n|e>>>32-n,Ki=(t,e,n)=>e<<n|t>>>32-n,qi=(t,e,n)=>e<<n-32|t>>>64-n,Fi=(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 fn=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),an=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,Zi=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),Gi=(t,e,n,r,o)=>e+n+r+o+(t/2**32|0)|0,zi=(t,e,n,r,o)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(o>>>0),Yi=(t,e,n,r,o,s)=>e+n+r+o+s+(t/2**32|0)|0,Xt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ue(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 ht(t,...e){if(!Ue(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 _e(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 un(t,e){ht(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function pe(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function lt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function ln(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function bt(t,e){return t<<32-e|t>>>e}const Tr=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Cr(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}const wt=Tr?t=>t:t=>Cr(t);function Wi(t){for(let e=0;e<t.length;e++)t[e]=Cr(t[e]);return t}const Ut=Tr?t=>t:Wi,jr=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Xi=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Jt(t){if(ht(t),jr)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=Xi[t[n]];return e}const vt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Lr(t){if(t>=vt._0&&t<=vt._9)return t-vt._0;if(t>=vt.A&&t<=vt.F)return t-(vt.A-10);if(t>=vt.a&&t<=vt.f)return t-(vt.a-10)}function Re(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(jr)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=Lr(t.charCodeAt(s)),c=Lr(t.charCodeAt(s+1));if(i===void 0||c===void 0){const f=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+f+'" at index '+s)}r[o]=i*16+c}return r}function kr(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function pt(t){return typeof t=="string"&&(t=kr(t)),ht(t),t}function _t(...t){let e=0;for(let r=0;r<t.length;r++){const o=t[r];ht(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 $e{}function ge(t){const e=r=>t().update(pt(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Ji(t){const e=(r,o)=>t(o).update(pt(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function Mt(t=32){if(Xt&&typeof Xt.getRandomValues=="function")return Xt.getRandomValues(new Uint8Array(t));if(Xt&&typeof Xt.randomBytes=="function")return Uint8Array.from(Xt.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}const Qi=BigInt(0),be=BigInt(1),tc=BigInt(2),ec=BigInt(7),nc=BigInt(256),rc=BigInt(113),Pr=[],Hr=[],Dr=[];for(let t=0,e=be,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],Pr.push(2*(5*r+n)),Hr.push((t+1)*(t+2)/2%64);let o=Qi;for(let s=0;s<7;s++)e=(e<<be^(e>>ec)*rc)%nc,e&tc&&(o^=be<<(be<<BigInt(s))-be);Dr.push(o)}const Vr=_r(Dr,!0),oc=Vr[0],sc=Vr[1],Mr=(t,e,n)=>n>32?qi(t,e,n):Mi(t,e,n),Kr=(t,e,n)=>n>32?Fi(t,e,n):Ki(t,e,n);function ic(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 c=(i+8)%10,f=(i+2)%10,u=n[f],a=n[f+1],l=Mr(u,a,1)^n[c],d=Kr(u,a,1)^n[c+1];for(let h=0;h<50;h+=10)t[i+h]^=l,t[i+h+1]^=d}let o=t[2],s=t[3];for(let i=0;i<24;i++){const c=Hr[i],f=Mr(o,s,c),u=Kr(o,s,c),a=Pr[i];o=t[a],s=t[a+1],t[a]=f,t[a+1]=u}for(let i=0;i<50;i+=10){for(let c=0;c<10;c++)n[c]=t[i+c];for(let c=0;c<10;c++)t[i+c]^=~n[(c+2)%10]&n[(c+4)%10]}t[0]^=oc[r],t[1]^=sc[r]}lt(n)}class Jn extends $e{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=pe(this.state)}clone(){return this._cloneInto()}keccak(){Ut(this.state32),ic(this.state32,this.rounds),Ut(this.state32),this.posOut=0,this.pos=0}update(e){Nt(this),e=pt(e),ht(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 c=0;c<i;c++)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),ht(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(un(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,lt(this.state)}_cloneInto(e){const{blockLen:n,suffix:r,outputLen:o,rounds:s,enableXOF:i}=this;return e||(e=new Jn(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 cc=(t,e,n)=>ge(()=>new Jn(e,t,n)),fc=cc(1,136,256/8);function ac(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),c=Number(n&s),f=r?4:0,u=r?0:4;t.setUint32(e+f,i,r),t.setUint32(e+u,c,r)}function uc(t,e,n){return t&e^~t&n}function lc(t,e,n){return t&e^t&n^e&n}class qr extends $e{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=ln(this.buffer)}update(e){Nt(this),e=pt(e),ht(e);const{view:n,buffer:r,blockLen:o}=this,s=e.length;for(let i=0;i<s;){const c=Math.min(o-this.pos,s-i);if(c===o){const f=ln(e);for(;o<=s-i;i+=o)this.process(f,i);continue}r.set(e.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Nt(this),un(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:o,isLE:s}=this;let{pos:i}=this;n[i++]=128,lt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(r,0),i=0);for(let l=i;l<o;l++)n[l]=0;ac(r,o-8,BigInt(this.length*8),s),this.process(r,0);const c=ln(e),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=f/4,a=this.get();if(u>a.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.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:c}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=c,o%n&&e.buffer.set(r),e}clone(){return this._cloneInto()}}const Rt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),X=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),J=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),dc=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 hc extends qr{constructor(e=32){super(64,e,8,!1),this.A=Rt[0]|0,this.B=Rt[1]|0,this.C=Rt[2]|0,this.D=Rt[3]|0,this.E=Rt[4]|0,this.F=Rt[5]|0,this.G=Rt[6]|0,this.H=Rt[7]|0}get(){const{A:e,B:n,C:r,D:o,E:s,F:i,G:c,H:f}=this;return[e,n,r,o,s,i,c,f]}set(e,n,r,o,s,i,c,f){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=c|0,this.H=f|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 d=$t[l-15],h=$t[l-2],y=bt(d,7)^bt(d,18)^d>>>3,m=bt(h,17)^bt(h,19)^h>>>10;$t[l]=m+$t[l-7]+y+$t[l-16]|0}let{A:r,B:o,C:s,D:i,E:c,F:f,G:u,H:a}=this;for(let l=0;l<64;l++){const d=bt(c,6)^bt(c,11)^bt(c,25),h=a+d+uc(c,f,u)+dc[l]+$t[l]|0,m=(bt(r,2)^bt(r,13)^bt(r,22))+lc(r,o,s)|0;a=u,u=f,f=c,c=i+h|0,i=s,s=o,o=r,r=h+m|0}r=r+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,f=f+this.F|0,u=u+this.G|0,a=a+this.H|0,this.set(r,o,s,i,c,f,u,a)}roundClean(){lt($t)}destroy(){this.set(0,0,0,0,0,0,0,0),lt(this.buffer)}}const Fr=_r(["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))),pc=Fr[0],gc=Fr[1],Tt=new Uint32Array(80),Ct=new Uint32Array(80);class dn extends qr{constructor(e=64){super(128,e,16,!1),this.Ah=J[0]|0,this.Al=J[1]|0,this.Bh=J[2]|0,this.Bl=J[3]|0,this.Ch=J[4]|0,this.Cl=J[5]|0,this.Dh=J[6]|0,this.Dl=J[7]|0,this.Eh=J[8]|0,this.El=J[9]|0,this.Fh=J[10]|0,this.Fl=J[11]|0,this.Gh=J[12]|0,this.Gl=J[13]|0,this.Hh=J[14]|0,this.Hl=J[15]|0}get(){const{Ah:e,Al:n,Bh:r,Bl:o,Ch:s,Cl:i,Dh:c,Dl:f,Eh:u,El:a,Fh:l,Fl:d,Gh:h,Gl:y,Hh:m,Hl:w}=this;return[e,n,r,o,s,i,c,f,u,a,l,d,h,y,m,w]}set(e,n,r,o,s,i,c,f,u,a,l,d,h,y,m,w){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=c|0,this.Dl=f|0,this.Eh=u|0,this.El=a|0,this.Fh=l|0,this.Fl=d|0,this.Gh=h|0,this.Gl=y|0,this.Hh=m|0,this.Hl=w|0}process(e,n){for(let R=0;R<16;R++,n+=4)Tt[R]=e.getUint32(n),Ct[R]=e.getUint32(n+=4);for(let R=16;R<80;R++){const Z=Tt[R-15]|0,H=Ct[R-15]|0,j=St(Z,H,1)^St(Z,H,8)^Rr(Z,H,7),L=Ot(Z,H,1)^Ot(Z,H,8)^$r(Z,H,7),k=Tt[R-2]|0,O=Ct[R-2]|0,T=St(k,O,19)^de(k,O,61)^Rr(k,O,6),C=Ot(k,O,19)^he(k,O,61)^$r(k,O,6),_=Zi(L,C,Ct[R-7],Ct[R-16]),p=Gi(_,j,T,Tt[R-7],Tt[R-16]);Tt[R]=p|0,Ct[R]=_|0}let{Ah:r,Al:o,Bh:s,Bl:i,Ch:c,Cl:f,Dh:u,Dl:a,Eh:l,El:d,Fh:h,Fl:y,Gh:m,Gl:w,Hh:U,Hl:F}=this;for(let R=0;R<80;R++){const Z=St(l,d,14)^St(l,d,18)^de(l,d,41),H=Ot(l,d,14)^Ot(l,d,18)^he(l,d,41),j=l&h^~l&m,L=d&y^~d&w,k=zi(F,H,L,gc[R],Ct[R]),O=Yi(k,U,Z,j,pc[R],Tt[R]),T=k|0,C=St(r,o,28)^de(r,o,34)^de(r,o,39),_=Ot(r,o,28)^he(r,o,34)^he(r,o,39),p=r&s^r&c^s&c,b=o&i^o&f^i&f;U=m|0,F=w|0,m=h|0,w=y|0,h=l|0,y=d|0,{h:l,l:d}=dt(u|0,a|0,O|0,T|0),u=c|0,a=f|0,c=s|0,f=i|0,s=r|0,i=o|0;const g=fn(T,_,b);r=an(g,O,C,p),o=g|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:c,l:f}=dt(this.Ch|0,this.Cl|0,c|0,f|0),{h:u,l:a}=dt(this.Dh|0,this.Dl|0,u|0,a|0),{h:l,l:d}=dt(this.Eh|0,this.El|0,l|0,d|0),{h,l:y}=dt(this.Fh|0,this.Fl|0,h|0,y|0),{h:m,l:w}=dt(this.Gh|0,this.Gl|0,m|0,w|0),{h:U,l:F}=dt(this.Hh|0,this.Hl|0,U|0,F|0),this.set(r,o,s,i,c,f,u,a,l,d,h,y,m,w,U,F)}roundClean(){lt(Tt,Ct)}destroy(){lt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class bc extends dn{constructor(){super(48),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 Q=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class yc extends dn{constructor(){super(32),this.Ah=Q[0]|0,this.Al=Q[1]|0,this.Bh=Q[2]|0,this.Bl=Q[3]|0,this.Ch=Q[4]|0,this.Cl=Q[5]|0,this.Dh=Q[6]|0,this.Dl=Q[7]|0,this.Eh=Q[8]|0,this.El=Q[9]|0,this.Fh=Q[10]|0,this.Fl=Q[11]|0,this.Gh=Q[12]|0,this.Gl=Q[13]|0,this.Hh=Q[14]|0,this.Hl=Q[15]|0}}const Te=ge(()=>new hc),mc=ge(()=>new dn),wc=ge(()=>new bc),vc=ge(()=>new yc),xc=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]),z=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),S=new Uint32Array(32);function jt(t,e,n,r,o,s){const i=o[s],c=o[s+1];let f=S[2*t],u=S[2*t+1],a=S[2*e],l=S[2*e+1],d=S[2*n],h=S[2*n+1],y=S[2*r],m=S[2*r+1],w=fn(f,a,i);u=an(w,u,l,c),f=w|0,{Dh:m,Dl:y}={Dh:m^u,Dl:y^f},{Dh:m,Dl:y}={Dh:Di(m,y),Dl:Vi(m)},{h,l:d}=dt(h,d,m,y),{Bh:l,Bl:a}={Bh:l^h,Bl:a^d},{Bh:l,Bl:a}={Bh:St(l,a,24),Bl:Ot(l,a,24)},S[2*t]=f,S[2*t+1]=u,S[2*e]=a,S[2*e+1]=l,S[2*n]=d,S[2*n+1]=h,S[2*r]=y,S[2*r+1]=m}function Lt(t,e,n,r,o,s){const i=o[s],c=o[s+1];let f=S[2*t],u=S[2*t+1],a=S[2*e],l=S[2*e+1],d=S[2*n],h=S[2*n+1],y=S[2*r],m=S[2*r+1],w=fn(f,a,i);u=an(w,u,l,c),f=w|0,{Dh:m,Dl:y}={Dh:m^u,Dl:y^f},{Dh:m,Dl:y}={Dh:St(m,y,16),Dl:Ot(m,y,16)},{h,l:d}=dt(h,d,m,y),{Bh:l,Bl:a}={Bh:l^h,Bl:a^d},{Bh:l,Bl:a}={Bh:de(l,a,63),Bl:he(l,a,63)},S[2*t]=f,S[2*t+1]=u,S[2*e]=a,S[2*e+1]=l,S[2*n]=d,S[2*n+1]=h,S[2*r]=y,S[2*r+1]=m}function Ec(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:c}=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(c!==void 0&&c.length!==o)throw new Error("personalization must be undefined or "+o)}class Bc extends $e{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=pe(this.buffer)}update(e){Nt(this),e=pt(e),ht(e);const{blockLen:n,buffer:r,buffer32:o}=this,s=e.length,i=e.byteOffset,c=e.buffer;for(let f=0;f<s;){this.pos===n&&(Ut(o),this.compress(o,0,!1),Ut(o),this.pos=0);const u=Math.min(n-this.pos,s-f),a=i+f;if(u===n&&!(a%4)&&f+u<s){const l=new Uint32Array(c,a,Math.floor((s-f)/4));Ut(l);for(let d=0;f+n<s;d+=o.length,f+=n)this.length+=n,this.compress(l,d,!1);Ut(l);continue}r.set(e.subarray(f,f+u),this.pos),this.pos+=u,this.length+=u,f+=u}return this}digestInto(e){Nt(this),un(e,this);const{pos:n,buffer32:r}=this;this.finished=!0,lt(this.buffer.subarray(n)),Ut(r),this.compress(r,0,!0),Ut(r);const o=pe(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:c}=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=c,e.outputLen=i,e}clone(){return this._cloneInto()}}class Ic extends Bc{constructor(e={}){const n=e.dkLen===void 0?64:e.dkLen;super(128,n),this.v0l=z[0]|0,this.v0h=z[1]|0,this.v1l=z[2]|0,this.v1h=z[3]|0,this.v2l=z[4]|0,this.v2h=z[5]|0,this.v3l=z[6]|0,this.v3h=z[7]|0,this.v4l=z[8]|0,this.v4h=z[9]|0,this.v5l=z[10]|0,this.v5h=z[11]|0,this.v6l=z[12]|0,this.v6h=z[13]|0,this.v7l=z[14]|0,this.v7h=z[15]|0,Ec(n,e,64,16,16);let{key:r,personalization:o,salt:s}=e,i=0;if(r!==void 0&&(r=pt(r),i=r.length),this.v0l^=this.outputLen|i<<8|65536|1<<24,s!==void 0){s=pt(s);const c=pe(s);this.v4l^=wt(c[0]),this.v4h^=wt(c[1]),this.v5l^=wt(c[2]),this.v5h^=wt(c[3])}if(o!==void 0){o=pt(o);const c=pe(o);this.v6l^=wt(c[0]),this.v6h^=wt(c[1]),this.v7l^=wt(c[2]),this.v7h^=wt(c[3])}if(r!==void 0){const c=new Uint8Array(this.blockLen);c.set(r),this.update(c)}}get(){let{v0l:e,v0h:n,v1l:r,v1h:o,v2l:s,v2h:i,v3l:c,v3h:f,v4l:u,v4h:a,v5l:l,v5h:d,v6l:h,v6h:y,v7l:m,v7h:w}=this;return[e,n,r,o,s,i,c,f,u,a,l,d,h,y,m,w]}set(e,n,r,o,s,i,c,f,u,a,l,d,h,y,m,w){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=c|0,this.v3h=f|0,this.v4l=u|0,this.v4h=a|0,this.v5l=l|0,this.v5h=d|0,this.v6l=h|0,this.v6h=y|0,this.v7l=m|0,this.v7h=w|0}compress(e,n,r){this.get().forEach((f,u)=>S[u]=f),S.set(z,16);let{h:o,l:s}=Ur(BigInt(this.length));S[24]=z[8]^s,S[25]=z[9]^o,r&&(S[28]=~S[28],S[29]=~S[29]);let i=0;const c=xc;for(let f=0;f<12;f++)jt(0,4,8,12,e,n+2*c[i++]),Lt(0,4,8,12,e,n+2*c[i++]),jt(1,5,9,13,e,n+2*c[i++]),Lt(1,5,9,13,e,n+2*c[i++]),jt(2,6,10,14,e,n+2*c[i++]),Lt(2,6,10,14,e,n+2*c[i++]),jt(3,7,11,15,e,n+2*c[i++]),Lt(3,7,11,15,e,n+2*c[i++]),jt(0,5,10,15,e,n+2*c[i++]),Lt(0,5,10,15,e,n+2*c[i++]),jt(1,6,11,12,e,n+2*c[i++]),Lt(1,6,11,12,e,n+2*c[i++]),jt(2,7,8,13,e,n+2*c[i++]),Lt(2,7,8,13,e,n+2*c[i++]),jt(3,4,9,14,e,n+2*c[i++]),Lt(3,4,9,14,e,n+2*c[i++]);this.v0l^=S[0]^S[16],this.v0h^=S[1]^S[17],this.v1l^=S[2]^S[18],this.v1h^=S[3]^S[19],this.v2l^=S[4]^S[20],this.v2h^=S[5]^S[21],this.v3l^=S[6]^S[22],this.v3h^=S[7]^S[23],this.v4l^=S[8]^S[24],this.v4h^=S[9]^S[25],this.v5l^=S[10]^S[26],this.v5h^=S[11]^S[27],this.v6l^=S[12]^S[28],this.v6h^=S[13]^S[29],this.v7l^=S[14]^S[30],this.v7h^=S[15]^S[31],lt(S)}destroy(){this.destroyed=!0,lt(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const Ac=Ji(t=>new Ic(t)),Sc="https://rpc.walletconnect.org/v1";function hn(t){const e=`Ethereum Signed Message:
${t.length}`,n=new TextEncoder().encode(e+t);return"0x"+Buffer.from(fc(n)).toString("hex")}async function Zr(t,e,n,r,o,s){switch(n.t){case"eip191":return await Gr(t,e,n.s);case"eip1271":return await zr(t,e,n.s,r,o,s);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${n.t}`)}}function Gr(t,e,n){const r=Ks.fromHex(n);return qs.recoverAddress({payload:hn(e),signature:r}).toLowerCase()===t.toLowerCase()}async function zr(t,e,n,r,o,s){const i=Je(r);if(!i.namespace||!i.reference)throw new Error(`isValidEip1271Signature failed: chainId must be in CAIP-2 format, received: ${r}`);try{const c="0x1626ba7e",f="0000000000000000000000000000000000000000000000000000000000000040",u=n.substring(2),a=(u.length/2).toString(16).padStart(64,"0"),l=(e.startsWith("0x")?e:hn(e)).substring(2),d=c+l+f+a+u,h=await fetch(`${s||Sc}/?chainId=${r}&projectId=${o}`,{headers:{"Content-Type":"application/json"},method:"POST",body:JSON.stringify({id:Oc(),jsonrpc:"2.0",method:"eth_call",params:[{to:t,data:d},"latest"]})}),{result:y}=await h.json();return y?y.slice(0,c.length).toLowerCase()===c.toLowerCase():!1}catch(c){return console.error("isValidEip1271Signature: ",c),!1}}function Oc(){return Date.now()+Math.floor(Math.random()*1e3)}function Nc(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 ue.encode(s)}function Uc(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=Ac(r,{dkLen:32});return ue.encode(o)}function _c(t){const e=new Uint8Array(Te(Yr(t)));return ue.encode(e)}function Yr(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 Rc(t){const e=Buffer.from(t,"base64"),n=Fs(e).txn;if(!n)throw new Error("Invalid signed transaction: missing 'txn' field");const r=Zs(n),o=Buffer.from("TX"),s=Buffer.concat([o,Buffer.from(r)]),i=vc(s);return Gs.encode(i).replace(/=+$/,"")}function pn(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 $c(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(pn(e.length)),o.push(e),o.push(Buffer.from([18])),o.push(pn(n.length)),o.push(n),o.push(Buffer.from([26])),o.push(pn(r.length)),o.push(r);const s=Buffer.concat(o),i=Te(s);return Buffer.from(i).toString("hex").toUpperCase()}function Tc(t){var e,n;const r=[];try{if(typeof t=="string")return r.push(t),r;if(typeof t!="object")return r;t!=null&&t.id&&r.push(t.id);const o=(n=(e=t?.capabilities)==null?void 0:e.caip345)==null?void 0:n.transactionHashes;o&&r.push(...o)}catch(o){console.warn("getWalletSendCallsHashes failed: ",o)}return r}var Cc=Object.defineProperty,jc=Object.defineProperties,Lc=Object.getOwnPropertyDescriptors,Wr=Object.getOwnPropertySymbols,kc=Object.prototype.hasOwnProperty,Pc=Object.prototype.propertyIsEnumerable,Xr=(t,e,n)=>e in t?Cc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,gn=(t,e)=>{for(var n in e||(e={}))kc.call(e,n)&&Xr(t,n,e[n]);if(Wr)for(var n of Wr(e))Pc.call(e,n)&&Xr(t,n,e[n]);return t},Jr=(t,e)=>jc(t,Lc(e));const Qr="did:pkh:",Hc={eip155:"Ethereum",solana:"Solana",bip122:"Bitcoin"},Dc=t=>t?Hc[t]||t:"",ye=t=>t?.split(":"),to=t=>{const e=t&&ye(t);if(e)return t.includes(Qr)?e[3]:e[1]},eo=t=>{const e=t&&ye(t);if(e)return t.includes(Qr)?e[2]:e[0]},no=t=>{const e=t&&ye(t);if(e)return e[2]+":"+e[3]},bn=t=>{const e=t&&ye(t);if(e)return e.pop()};async function Vc(t){const{cacao:e,projectId:n}=t,{s:r,p:o}=e,s=ro(o,o.iss),i=bn(o.iss);return await Zr(i,s,r,no(o.iss),n)}const ro=(t,e)=>{const n=eo(e);if(!n)throw new Error("Invalid issuer: "+e);const r=`${t.domain} wants you to sign in with your ${Dc(n)} account:`,o=bn(e);if(!t.aud&&!t.uri)throw new Error("Either `aud` or `uri` is required to construct the message");let s=t.statement||void 0;const i=`URI: ${t.aud||t.uri}`,c=`Version: ${t.version}`,f=`Chain ID: ${to(e)}`,u=`Nonce: ${t.nonce}`,a=`Issued At: ${t.iat}`,l=t.exp?`Expiration Time: ${t.exp}`:void 0,d=t.nbf?`Not Before: ${t.nbf}`:void 0,h=t.requestId?`Request ID: ${t.requestId}`:void 0,y=t.resources?`Resources:${t.resources.map(w=>`
- ${w}`).join("")}`:void 0,m=je(t.resources);if(m){const w=kt(m);s=wn(s,w)}return[r,o,"",s,"",i,c,f,u,a,l,d,h,y].filter(w=>w!=null).join(`
`)};function Mc(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 Kc(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,c=sn(i,r);if(!(c!=null&&c.length))throw new Error("No supported chains");const f=oo(n.resources);if(!f)return n;yt(f);const u=so(f,"eip155");let a=n?.resources||[];if(u!=null&&u.length){const l=io(u),d=sn(l,o);if(!(d!=null&&d.length))throw new Error(`Supported methods don't satisfy the requested: ${JSON.stringify(l)}, supported: ${JSON.stringify(o)}`);const h=yn("request",d,{chains:c}),y=uo(f,"eip155",h);a=((e=n?.resources)==null?void 0:e.slice(0,-1))||[],a.push(Ce(y))}return Jr(gn({},n),{statement:ho(s,je(a)),chains:c,resources:n!=null&&n.resources||a.length>0?a:void 0})}function oo(t){const e=je(t);if(e&&mn(e))return kt(e)}function qc(t,e){var n;return(n=t?.att)==null?void 0:n.hasOwnProperty(e)}function so(t,e){var n,r;return(n=t?.att)!=null&&n[e]?Object.keys((r=t?.att)==null?void 0:r[e]):[]}function Fc(t){return t?.map(e=>Object.keys(e))||[]}function io(t){return t?.map(e=>{var n;return(n=e.split("/"))==null?void 0:n[1]})||[]}function co(t){return Buffer.from(JSON.stringify(t)).toString("base64")}function fo(t){return JSON.parse(Buffer.from(t,"base64").toString("utf-8"))}function yt(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 ao(t,e,n,r={}){return n?.sort((o,s)=>o.localeCompare(s)),{att:{[t]:yn(e,n,r)}}}function uo(t,e,n){var r;t.att[e]=gn({},n);const o=(r=Object.keys(t.att))==null?void 0:r.sort((i,c)=>i.localeCompare(c)),s={att:{}};return o.reduce((i,c)=>(i.att[c]=t.att[c],i),s)}function yn(t,e,n={}){e=e?.sort((o,s)=>o.localeCompare(s));const r=e.map(o=>({[`${t}/${o}`]:[n]}));return Object.assign({},...r)}function Ce(t){return yt(t),`urn:recap:${co(t).replace(/=/g,"")}`}function kt(t){const e=fo(t.replace("urn:recap:",""));return yt(e),e}function Zc(t,e,n){const r=ao(t,e,n);return Ce(r)}function mn(t){return t&&t.includes("urn:recap:")}function Gc(t,e){const n=kt(t),r=kt(e),o=lo(n,r);return Ce(o)}function lo(t,e){yt(t),yt(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((c,f)=>c.localeCompare(f)).forEach(c=>{var f,u;r.att[o]=Jr(gn({},r.att[o]),{[c]:((f=t.att[o])==null?void 0:f[c])||((u=e.att[o])==null?void 0:u[c])})})}),r}function wn(t="",e){yt(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(c=>{const f=Object.keys(e.att[c]).map(l=>({ability:l.split("/")[0],action:l.split("/")[1]}));f.sort((l,d)=>l.action.localeCompare(d.action));const u={};f.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 '${c}'.`));r.push(a.join(", ").replace(".,","."))});const s=r.join(" "),i=`${n}${s}`;return`${t?t+" ":""}${i}`}function zc(t){var e;const n=kt(t);yt(n);const r=(e=n.att)==null?void 0:e.eip155;return r?Object.keys(r).map(o=>o.split("/")[1]):[]}function Yc(t){const e=kt(t);yt(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 ho(t,e){if(!e)return t;const n=kt(e);return yt(n),wn(t,n)}function je(t){if(!t)return;const e=t?.[t.length-1];return mn(e)?e:void 0}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */function po(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function vn(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function xn(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function ot(t,...e){if(!po(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 go(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 Wc(t,e){ot(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Pt(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Qt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Xc(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}const Jc=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Qc(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function En(t){if(typeof t=="string")t=Qc(t);else if(po(t))t=Bn(t);else throw new Error("Uint8Array expected, got "+typeof t);return t}function tf(t,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(t,e)}function ef(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 nf=(t,e)=>{function n(r,...o){if(ot(r),!Jc)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?ot(a):ot(a,t.nonceLength)}const s=t.tagLength;s&&o[1]!==void 0&&ot(o[1]);const i=e(r,...o),c=(a,l)=>{if(l!==void 0){if(a!==2)throw new Error("cipher output not supported");ot(l)}};let f=!1;return{encrypt(a,l){if(f)throw new Error("cannot encrypt() twice with same key + nonce");return f=!0,ot(a),c(i.encrypt.length,l),i.encrypt(a,l)},decrypt(a,l){if(ot(a),s&&a.length<s)throw new Error("invalid ciphertext length: smaller than tagLength="+s);return c(i.decrypt.length,l),i.decrypt(a,l)}}}return Object.assign(n,t),n};function bo(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&&!of(e))throw new Error("invalid output, must be aligned");return e}function yo(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),c=Number(n&s),f=r?4:0,u=r?0:4;t.setUint32(e+f,i,r),t.setUint32(e+u,c,r)}function rf(t,e,n){vn(n);const r=new Uint8Array(16),o=Xc(r);return yo(o,0,BigInt(e),n),yo(o,8,BigInt(t),n),r}function of(t){return t.byteOffset%4===0}function Bn(t){return Uint8Array.from(t)}const mo=t=>Uint8Array.from(t.split("").map(e=>e.charCodeAt(0))),sf=mo("expand 16-byte k"),cf=mo("expand 32-byte k"),ff=Pt(sf),af=Pt(cf);function K(t,e){return t<<e|t>>>32-e}function In(t){return t.byteOffset%4===0}const Le=64,uf=16,wo=2**32-1,vo=new Uint32Array;function lf(t,e,n,r,o,s,i,c){const f=o.length,u=new Uint8Array(Le),a=Pt(u),l=In(o)&&In(s),d=l?Pt(o):vo,h=l?Pt(s):vo;for(let y=0;y<f;i++){if(t(e,n,r,a,i,c),i>=wo)throw new Error("arx: counter overflow");const m=Math.min(Le,f-y);if(l&&m===Le){const w=y/4;if(y%4!==0)throw new Error("arx: invalid block position");for(let U=0,F;U<uf;U++)F=w+U,h[F]=d[F]^a[U];y+=Le;continue}for(let w=0,U;w<m;w++)U=y+w,s[U]=o[U]^u[w];y+=m}}function df(t,e){const{allowShortKeys:n,extendNonceFn:r,counterLength:o,counterRight:s,rounds:i}=tf({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return xn(o),xn(i),vn(s),vn(n),(c,f,u,a,l=0)=>{ot(c),ot(f),ot(u);const d=u.length;if(a===void 0&&(a=new Uint8Array(d)),ot(a),xn(l),l<0||l>=wo)throw new Error("arx: counter overflow");if(a.length<d)throw new Error(`arx: output (${a.length}) is shorter than data (${d})`);const h=[];let y=c.length,m,w;if(y===32)h.push(m=Bn(c)),w=af;else if(y===16&&n)m=new Uint8Array(32),m.set(c),m.set(c,16),w=ff,h.push(m);else throw new Error(`arx: invalid 32-byte key, got length=${y}`);In(f)||h.push(f=Bn(f));const U=Pt(m);if(r){if(f.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(w,U,Pt(f.subarray(0,16)),U),f=f.subarray(16)}const F=16-o;if(F!==f.length)throw new Error(`arx: nonce must be ${F} or 16 bytes`);if(F!==12){const Z=new Uint8Array(12);Z.set(f,s?0:12-f.length),f=Z,h.push(f)}const R=Pt(f);return lf(t,w,U,R,u,a,l,i),Qt(...h),a}}const W=(t,e)=>t[e++]&255|(t[e++]&255)<<8;class hf{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=En(e),ot(e,32);const n=W(e,0),r=W(e,2),o=W(e,4),s=W(e,6),i=W(e,8),c=W(e,10),f=W(e,12),u=W(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|c<<2)&8191,this.r[7]=(c>>>11|f<<5)&8065,this.r[8]=(f>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let a=0;a<8;a++)this.pad[a]=W(e,16+2*a)}process(e,n,r=!1){const o=r?0:2048,{h:s,r:i}=this,c=i[0],f=i[1],u=i[2],a=i[3],l=i[4],d=i[5],h=i[6],y=i[7],m=i[8],w=i[9],U=W(e,n+0),F=W(e,n+2),R=W(e,n+4),Z=W(e,n+6),H=W(e,n+8),j=W(e,n+10),L=W(e,n+12),k=W(e,n+14);let O=s[0]+(U&8191),T=s[1]+((U>>>13|F<<3)&8191),C=s[2]+((F>>>10|R<<6)&8191),_=s[3]+((R>>>7|Z<<9)&8191),p=s[4]+((Z>>>4|H<<12)&8191),b=s[5]+(H>>>1&8191),g=s[6]+((H>>>14|j<<2)&8191),x=s[7]+((j>>>11|L<<5)&8191),E=s[8]+((L>>>8|k<<8)&8191),I=s[9]+(k>>>5|o),v=0,B=v+O*c+T*(5*w)+C*(5*m)+_*(5*y)+p*(5*h);v=B>>>13,B&=8191,B+=b*(5*d)+g*(5*l)+x*(5*a)+E*(5*u)+I*(5*f),v+=B>>>13,B&=8191;let A=v+O*f+T*c+C*(5*w)+_*(5*m)+p*(5*y);v=A>>>13,A&=8191,A+=b*(5*h)+g*(5*d)+x*(5*l)+E*(5*a)+I*(5*u),v+=A>>>13,A&=8191;let N=v+O*u+T*f+C*c+_*(5*w)+p*(5*m);v=N>>>13,N&=8191,N+=b*(5*y)+g*(5*h)+x*(5*d)+E*(5*l)+I*(5*a),v+=N>>>13,N&=8191;let D=v+O*a+T*u+C*f+_*c+p*(5*w);v=D>>>13,D&=8191,D+=b*(5*m)+g*(5*y)+x*(5*h)+E*(5*d)+I*(5*l),v+=D>>>13,D&=8191;let P=v+O*l+T*a+C*u+_*f+p*c;v=P>>>13,P&=8191,P+=b*(5*w)+g*(5*m)+x*(5*y)+E*(5*h)+I*(5*d),v+=P>>>13,P&=8191;let $=v+O*d+T*l+C*a+_*u+p*f;v=$>>>13,$&=8191,$+=b*c+g*(5*w)+x*(5*m)+E*(5*y)+I*(5*h),v+=$>>>13,$&=8191;let V=v+O*h+T*d+C*l+_*a+p*u;v=V>>>13,V&=8191,V+=b*f+g*c+x*(5*w)+E*(5*m)+I*(5*y),v+=V>>>13,V&=8191;let q=v+O*y+T*h+C*d+_*l+p*a;v=q>>>13,q&=8191,q+=b*u+g*f+x*c+E*(5*w)+I*(5*m),v+=q>>>13,q&=8191;let G=v+O*m+T*y+C*h+_*d+p*l;v=G>>>13,G&=8191,G+=b*a+g*u+x*f+E*c+I*(5*w),v+=G>>>13,G&=8191;let M=v+O*w+T*m+C*y+_*h+p*d;v=M>>>13,M&=8191,M+=b*l+g*a+x*u+E*f+I*c,v+=M>>>13,M&=8191,v=(v<<2)+v|0,v=v+B|0,B=v&8191,v=v>>>13,A+=v,s[0]=B,s[1]=A,s[2]=N,s[3]=D,s[4]=P,s[5]=$,s[6]=V,s[7]=q,s[8]=G,s[9]=M}finalize(){const{h:e,pad:n}=this,r=new Uint16Array(10);let o=e[1]>>>13;e[1]&=8191;for(let c=2;c<10;c++)e[c]+=o,o=e[c]>>>13,e[c]&=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 c=1;c<10;c++)r[c]=e[c]+o,o=r[c]>>>13,r[c]&=8191;r[9]-=8192;let s=(o^1)-1;for(let c=0;c<10;c++)r[c]&=s;s=~s;for(let c=0;c<10;c++)e[c]=e[c]&s|r[c];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 c=1;c<8;c++)i=(e[c]+n[c]|0)+(i>>>16)|0,e[c]=i&65535;Qt(r)}update(e){go(this),e=En(e),ot(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(){Qt(this.h,this.r,this.buffer,this.pad)}digestInto(e){go(this),Wc(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 pf(t){const e=(r,o)=>t(o).update(En(r)).digest(),n=t(new Uint8Array(32));return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}const gf=pf(t=>new hf(t));function bf(t,e,n,r,o,s=20){let i=t[0],c=t[1],f=t[2],u=t[3],a=e[0],l=e[1],d=e[2],h=e[3],y=e[4],m=e[5],w=e[6],U=e[7],F=o,R=n[0],Z=n[1],H=n[2],j=i,L=c,k=f,O=u,T=a,C=l,_=d,p=h,b=y,g=m,x=w,E=U,I=F,v=R,B=Z,A=H;for(let D=0;D<s;D+=2)j=j+T|0,I=K(I^j,16),b=b+I|0,T=K(T^b,12),j=j+T|0,I=K(I^j,8),b=b+I|0,T=K(T^b,7),L=L+C|0,v=K(v^L,16),g=g+v|0,C=K(C^g,12),L=L+C|0,v=K(v^L,8),g=g+v|0,C=K(C^g,7),k=k+_|0,B=K(B^k,16),x=x+B|0,_=K(_^x,12),k=k+_|0,B=K(B^k,8),x=x+B|0,_=K(_^x,7),O=O+p|0,A=K(A^O,16),E=E+A|0,p=K(p^E,12),O=O+p|0,A=K(A^O,8),E=E+A|0,p=K(p^E,7),j=j+C|0,A=K(A^j,16),x=x+A|0,C=K(C^x,12),j=j+C|0,A=K(A^j,8),x=x+A|0,C=K(C^x,7),L=L+_|0,I=K(I^L,16),E=E+I|0,_=K(_^E,12),L=L+_|0,I=K(I^L,8),E=E+I|0,_=K(_^E,7),k=k+p|0,v=K(v^k,16),b=b+v|0,p=K(p^b,12),k=k+p|0,v=K(v^k,8),b=b+v|0,p=K(p^b,7),O=O+T|0,B=K(B^O,16),g=g+B|0,T=K(T^g,12),O=O+T|0,B=K(B^O,8),g=g+B|0,T=K(T^g,7);let N=0;r[N++]=i+j|0,r[N++]=c+L|0,r[N++]=f+k|0,r[N++]=u+O|0,r[N++]=a+T|0,r[N++]=l+C|0,r[N++]=d+_|0,r[N++]=h+p|0,r[N++]=y+b|0,r[N++]=m+g|0,r[N++]=w+x|0,r[N++]=U+E|0,r[N++]=F+I|0,r[N++]=R+v|0,r[N++]=Z+B|0,r[N++]=H+A|0}const yf=df(bf,{counterRight:!1,counterLength:4,allowShortKeys:!1}),mf=new Uint8Array(16),xo=(t,e)=>{t.update(e);const n=e.length%16;n&&t.update(mf.subarray(n))},wf=new Uint8Array(3