UNPKG

@walletconnect/utils

Version:

Utilities for WalletConnect Protocol

4 lines • 107 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var ps=require("detect-browser"),ze=require("@walletconnect/time"),me=require("@walletconnect/window-getters"),gs=require("@walletconnect/window-metadata"),bs=require("viem"),ms=require("bs58"),Mn=require("@msgpack/msgpack"),ys=require("@scure/base"),ws=require("@walletconnect/relay-auth"),V=require("uint8arrays"),xs=require("@walletconnect/relay-api"),vs=require("blakejs");function Es(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var rt=Es(ms);const wt=":";function qt(e){const[t,n]=e.split(wt);return{namespace:t,reference:n}}function qn(e){const{namespace:t,reference:n}=e;return[t,n].join(wt)}function Ft(e){const[t,n,r]=e.split(wt);return{namespace:t,reference:n,address:r}}function Fn(e){const{namespace:t,reference:n,address:r}=e;return[t,n,r].join(wt)}function Kt(e,t){const n=[];return e.forEach(r=>{const o=t(r);n.includes(o)||n.push(o)}),n}function Kn(e){const{address:t}=Ft(e);return t}function zn(e){const{namespace:t,reference:n}=Ft(e);return qn({namespace:t,reference:n})}function As(e,t){const{namespace:n,reference:r}=qt(t);return Fn({namespace:n,reference:r,address:e})}function Ss(e){return Kt(e,Kn)}function Gn(e){return Kt(e,zn)}function Bs(e,t=[]){const n=[];return Object.keys(e).forEach(r=>{if(t.length&&!t.includes(r))return;const o=e[r];n.push(...o.accounts)}),n}function Is(e,t=[]){const n=[];return Object.keys(e).forEach(r=>{if(t.length&&!t.includes(r))return;const o=e[r];n.push(...Gn(o.accounts))}),n}function Ns(e,t=[]){const n=[];return Object.keys(e).forEach(r=>{if(t.length&&!t.includes(r))return;const o=e[r];n.push(...xt(r,o))}),n}function xt(e,t){return e.includes(":")?[e]:t.chains||[]}var Os=Object.defineProperty,Us=Object.defineProperties,_s=Object.getOwnPropertyDescriptors,Zn=Object.getOwnPropertySymbols,Rs=Object.prototype.hasOwnProperty,Ts=Object.prototype.propertyIsEnumerable,zt=(e,t,n)=>t in e?Os(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Yn=(e,t)=>{for(var n in t||(t={}))Rs.call(t,n)&&zt(e,n,t[n]);if(Zn)for(var n of Zn(t))Ts.call(t,n)&&zt(e,n,t[n]);return e},Cs=(e,t)=>Us(e,_s(t)),Wn=(e,t,n)=>zt(e,typeof t!="symbol"?t+"":t,n);const Xn="ReactNative",Q={reactNative:"react-native",node:"node",browser:"browser",unknown:"unknown"},vt=" ",$s=":",Jn="/",Gt=2,Ls=1e3,Qn="js";function Zt(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function Ae(){return!me.getDocument()&&!!me.getNavigator()&&navigator.product===Xn}function js(){return Ae()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="android"}function Ps(){return Ae()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="ios"}function Ge(){return!Zt()&&!!me.getNavigator()&&!!me.getDocument()}function ke(){return Ae()?Q.reactNative:Zt()?Q.node:Ge()?Q.browser:Q.unknown}function ks(){var e;try{return Ae()&&typeof global<"u"&&typeof(global==null?void 0:global.Application)<"u"?(e=global.Application)==null?void 0:e.applicationId:void 0}catch{return}}function er(e,t){const n=new URLSearchParams(e);for(const r of Object.keys(t).sort())if(t.hasOwnProperty(r)){const o=t[r];o!==void 0&&n.set(r,o)}return n.toString()}function Ds(e){var t,n;const r=tr();try{return e!=null&&e.url&&r.url&&new URL(e.url).host!==new URL(r.url).host&&(console.warn(`The configured WalletConnect 'metadata.url':${e.url} differs from the actual page url:${r.url}. This is probably unintended and can lead to issues.`),e.url=r.url),(t=e?.icons)!=null&&t.length&&e.icons.length>0&&(e.icons=e.icons.filter(o=>o!=="")),Cs(Yn(Yn({},r),e),{url:e?.url||r.url,name:e?.name||r.name,description:e?.description||r.description,icons:(n=e?.icons)!=null&&n.length&&e.icons.length>0?e.icons:r.icons})}catch(o){return console.warn("Error populating app metadata",o),e||r}}function tr(){return gs.getWindowMetadata()||{name:"",description:"",url:"",icons:[""]}}function Hs(e,t){var n;const r=ke(),o={protocol:e,version:t,env:r};return r==="browser"&&(o.host=((n=me.getLocation())==null?void 0:n.host)||"unknown"),o}function nr(){if(ke()===Q.reactNative&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"){const{OS:n,Version:r}=global.Platform;return[n,r].join("-")}const e=ps.detect();if(e===null)return"unknown";const t=e.os?e.os.replace(" ","").toLowerCase():"unknown";return e.type==="browser"?[t,e.name,e.version].join("-"):[t,e.version].join("-")}function rr(){var e;const t=ke();return t===Q.browser?[t,((e=me.getLocation())==null?void 0:e.host)||"unknown"].join(":"):t}function or(e,t,n){const r=nr(),o=rr();return[[e,t].join("-"),[Qn,n].join("-"),r,o].join("/")}function Vs({protocol:e,version:t,relayUrl:n,sdkVersion:r,auth:o,projectId:s,useOnCloseEvent:i,bundleId:c,packageName:a}){const l=n.split("?"),f=or(e,t,r),u={auth:o,ua:f,projectId:s,useOnCloseEvent:i||void 0,packageName:a||void 0,bundleId:c||void 0},h=er(l[1]||"",u);return l[0]+"?"+h}function Ms(e){let t=(e.match(/^[^:]+(?=:\/\/)/gi)||[])[0];const n=typeof t<"u"?e.split("://")[1]:e;return t=t==="wss"?"https":"http",[t,n].join("://")}function qs(e,t,n){if(!e[t]||typeof e[t]!==n)throw new Error(`Missing or invalid "${t}" param`)}function sr(e,t=Gt){return ir(e.split(Jn),t)}function Fs(e){return sr(e).join(vt)}function Se(e,t){return e.filter(n=>t.includes(n)).length===e.length}function ir(e,t=Gt){return e.slice(Math.max(e.length-t,0))}function Ks(e){return Object.fromEntries(e.entries())}function zs(e){return new Map(Object.entries(e))}function Gs(e,t){const n={};return Object.keys(e).forEach(r=>{n[r]=t(e[r])}),n}const Zs=e=>e;function cr(e){return e.trim().replace(/^\w/,t=>t.toUpperCase())}function Ys(e){return e.split(vt).map(t=>cr(t)).join(vt)}function Ws(e=ze.FIVE_MINUTES,t){const n=ze.toMiliseconds(e||ze.FIVE_MINUTES);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,a)=>{if(i)return c(i);s=setTimeout(()=>{const l=new Error(t);i=Promise.reject(l),a(l)},n),r=c,o=a})}}function Xs(e,t,n){return new Promise(async(r,o)=>{const s=setTimeout(()=>o(new Error(n)),t);try{const i=await e;r(i)}catch(i){o(i)}clearTimeout(s)})}function Yt(e,t){if(typeof t=="string"&&t.startsWith(`${e}:`))return t;if(e.toLowerCase()==="topic"){if(typeof t!="string")throw new Error('Value must be "string" for expirer target type: topic');return`topic:${t}`}else if(e.toLowerCase()==="id"){if(typeof t!="number")throw new Error('Value must be "number" for expirer target type: id');return`id:${t}`}throw new Error(`Unknown expirer target type: ${e}`)}function Js(e){return Yt("topic",e)}function Qs(e){return Yt("id",e)}function ei(e){const[t,n]=e.split(":"),r={id:void 0,topic:void 0};if(t==="topic"&&typeof n=="string")r.topic=n;else if(t==="id"&&Number.isInteger(Number(n)))r.id=Number(n);else throw new Error(`Invalid target, expected id:number or topic:string, got ${t}:${n}`);return r}function ti(e,t){return ze.fromMiliseconds((t||Date.now())+ze.toMiliseconds(e))}function ni(e){return Date.now()>=ze.toMiliseconds(e)}function ri(e,t){return`${e}${t?`:${t}`:""}`}function ce(e=[],t=[]){return[...new Set([...e,...t])]}async function oi({id:e,topic:t,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=fr(s,e,t),c=ke();if(c===Q.browser){if(!((r=me.getDocument())!=null&&r.hasFocus())){console.warn("Document does not have focus, skipping deeplink.");return}ar(i)}else c===Q.reactNative&&typeof(global==null?void 0:global.Linking)<"u"&&await global.Linking.openURL(i)}catch(o){console.error(o)}}function fr(e,t,n){const r=`requestId=${t}&sessionTopic=${n}`;e.endsWith("/")&&(e=e.slice(0,-1));let o=`${e}`;if(e.startsWith("https://t.me")){const s=e.includes("?")?"&startapp=":"?startapp=";o=`${o}${s}${dr(r,!0)}`}else o=`${o}/wc?${r}`;return o}function ar(e){let t="_self";lr()?t="_top":(ur()||e.startsWith("https://")||e.startsWith("http://"))&&(t="_blank"),window.open(e,t,"noreferrer noopener")}async function si(e,t){let n="";try{if(Ge()&&(n=localStorage.getItem(t),n))return n;n=await e.getItem(t)}catch(r){console.error(r)}return n}function Wt(e,t){return e.filter(n=>t.includes(n))}function ii(e,t){if(!e.includes(t))return null;const n=e.split(/([&,?,=])/),r=n.indexOf(t);return n[r+2]}function ci(){return typeof crypto<"u"&&crypto!=null&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/gu,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function fi(){return typeof process<"u"&&process.env.IS_VITEST==="true"}function ur(){return typeof window<"u"&&(!!window.TelegramWebviewProxy||!!window.Telegram||!!window.TelegramWebviewProxyProto)}function lr(){try{return window.self!==window.top}catch{return!1}}function dr(e,t=!1){const n=Buffer.from(e).toString("base64");return t?n.replace(/[=]/g,""):n}function Xt(e){return Buffer.from(e,"base64").toString("utf-8")}function ai(e){return new Promise(t=>setTimeout(t,e))}class ui{constructor({limit:t}){Wn(this,"limit"),Wn(this,"set"),this.limit=t,this.set=new Set}add(t){if(!this.set.has(t)){if(this.set.size>=this.limit){const n=this.set.values().next().value;n&&this.set.delete(n)}this.set.add(t)}}has(t){return this.set.has(t)}}const Et=BigInt(2**32-1),hr=BigInt(32);function pr(e,t=!1){return t?{h:Number(e&Et),l:Number(e>>hr&Et)}:{h:Number(e>>hr&Et)|0,l:Number(e&Et)|0}}function gr(e,t=!1){const n=e.length;let r=new Uint32Array(n),o=new Uint32Array(n);for(let s=0;s<n;s++){const{h:i,l:c}=pr(e[s],t);[r[s],o[s]]=[i,c]}return[r,o]}const br=(e,t,n)=>e>>>n,mr=(e,t,n)=>e<<32-n|t>>>n,Be=(e,t,n)=>e>>>n|t<<32-n,Ie=(e,t,n)=>e<<32-n|t>>>n,ot=(e,t,n)=>e<<64-n|t>>>n-32,st=(e,t,n)=>e>>>n-32|t<<64-n,li=(e,t)=>t,di=(e,t)=>e,hi=(e,t,n)=>e<<n|t>>>32-n,pi=(e,t,n)=>t<<n|e>>>32-n,gi=(e,t,n)=>t<<n-32|e>>>64-n,bi=(e,t,n)=>e<<n-32|t>>>64-n;function le(e,t,n,r){const o=(t>>>0)+(r>>>0);return{h:e+n+(o/2**32|0)|0,l:o|0}}const Jt=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),Qt=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,mi=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),yi=(e,t,n,r,o)=>t+n+r+o+(e/2**32|0)|0,wi=(e,t,n,r,o)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(o>>>0),xi=(e,t,n,r,o,s)=>t+n+r+o+s+(e/2**32|0)|0,Ze=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function en(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function ye(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function fe(e,...t){if(!en(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function tn(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");ye(e.outputLen),ye(e.blockLen)}function Ne(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function nn(e,t){fe(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function it(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function ae(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function rn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function pe(e,t){return e<<32-t|e>>>t}const yr=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function wr(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const we=yr?e=>e:e=>wr(e);function vi(e){for(let t=0;t<e.length;t++)e[t]=wr(e[t]);return e}const Oe=yr?e=>e:vi,xr=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Ei=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ct(e){if(fe(e),xr)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=Ei[e[n]];return t}const xe={_0:48,_9:57,A:65,F:70,a:97,f:102};function vr(e){if(e>=xe._0&&e<=xe._9)return e-xe._0;if(e>=xe.A&&e<=xe.F)return e-(xe.A-10);if(e>=xe.a&&e<=xe.f)return e-(xe.a-10)}function on(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(xr)return Uint8Array.fromHex(e);const t=e.length,n=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let o=0,s=0;o<n;o++,s+=2){const i=vr(e.charCodeAt(s)),c=vr(e.charCodeAt(s+1));if(i===void 0||c===void 0){const a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}r[o]=i*16+c}return r}function Ai(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function de(e){return typeof e=="string"&&(e=Ai(e)),fe(e),e}function De(...e){let t=0;for(let r=0;r<e.length;r++){const o=e[r];fe(o),t+=o.length}const n=new Uint8Array(t);for(let r=0,o=0;r<e.length;r++){const s=e[r];n.set(s,o),o+=s.length}return n}class At{}function ft(e){const t=r=>e().update(de(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Si(e){const t=(r,o)=>e(o).update(de(r)).digest(),n=e({});return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=r=>e(r),t}function Ye(e=32){if(Ze&&typeof Ze.getRandomValues=="function")return Ze.getRandomValues(new Uint8Array(e));if(Ze&&typeof Ze.randomBytes=="function")return Uint8Array.from(Ze.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}const Bi=BigInt(0),at=BigInt(1),Ii=BigInt(2),Ni=BigInt(7),Oi=BigInt(256),Ui=BigInt(113),Er=[],Ar=[],Sr=[];for(let e=0,t=at,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],Er.push(2*(5*r+n)),Ar.push((e+1)*(e+2)/2%64);let o=Bi;for(let s=0;s<7;s++)t=(t<<at^(t>>Ni)*Ui)%Oi,t&Ii&&(o^=at<<(at<<BigInt(s))-at);Sr.push(o)}const Br=gr(Sr,!0),_i=Br[0],Ri=Br[1],Ir=(e,t,n)=>n>32?gi(e,t,n):hi(e,t,n),Nr=(e,t,n)=>n>32?bi(e,t,n):pi(e,t,n);function Ti(e,t=24){const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let i=0;i<10;i++)n[i]=e[i]^e[i+10]^e[i+20]^e[i+30]^e[i+40];for(let i=0;i<10;i+=2){const c=(i+8)%10,a=(i+2)%10,l=n[a],f=n[a+1],u=Ir(l,f,1)^n[c],h=Nr(l,f,1)^n[c+1];for(let g=0;g<50;g+=10)e[i+g]^=u,e[i+g+1]^=h}let o=e[2],s=e[3];for(let i=0;i<24;i++){const c=Ar[i],a=Ir(o,s,c),l=Nr(o,s,c),f=Er[i];o=e[f],s=e[f+1],e[f]=a,e[f+1]=l}for(let i=0;i<50;i+=10){for(let c=0;c<10;c++)n[c]=e[i+c];for(let c=0;c<10;c++)e[i+c]^=~n[(c+2)%10]&n[(c+4)%10]}e[0]^=_i[r],e[1]^=Ri[r]}ae(n)}class Vn extends At{constructor(t,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=t,this.suffix=n,this.outputLen=r,this.enableXOF=o,this.rounds=s,ye(r),!(0<t&&t<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=it(this.state)}clone(){return this._cloneInto()}keccak(){Oe(this.state32),Ti(this.state32,this.rounds),Oe(this.state32),this.posOut=0,this.pos=0}update(t){Ne(this),t=de(t),fe(t);const{blockLen:n,state:r}=this,o=t.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++]^=t[s++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:n,pos:r,blockLen:o}=this;t[r]^=n,(n&128)!==0&&r===o-1&&this.keccak(),t[o-1]^=128,this.keccak()}writeInto(t){Ne(this,!1),fe(t),this.finish();const n=this.state,{blockLen:r}=this;for(let o=0,s=t.length;o<s;){this.posOut>=r&&this.keccak();const i=Math.min(r-this.posOut,s-o);t.set(n.subarray(this.posOut,this.posOut+i),o),this.posOut+=i,o+=i}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return ye(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(nn(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,ae(this.state)}_cloneInto(t){const{blockLen:n,suffix:r,outputLen:o,rounds:s,enableXOF:i}=this;return t||(t=new Vn(n,r,o,i,s)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=s,t.suffix=r,t.outputLen=o,t.enableXOF=i,t.destroyed=this.destroyed,t}}const Ci=(e,t,n)=>ft(()=>new Vn(t,e,n)),$i=Ci(1,136,256/8);function Li(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const o=BigInt(32),s=BigInt(4294967295),i=Number(n>>o&s),c=Number(n&s),a=r?4:0,l=r?0:4;e.setUint32(t+a,i,r),e.setUint32(t+l,c,r)}function ji(e,t,n){return e&t^~e&n}function Pi(e,t,n){return e&t^e&n^t&n}class Or extends At{constructor(t,n,r,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=o,this.buffer=new Uint8Array(t),this.view=rn(this.buffer)}update(t){Ne(this),t=de(t),fe(t);const{view:n,buffer:r,blockLen:o}=this,s=t.length;for(let i=0;i<s;){const c=Math.min(o-this.pos,s-i);if(c===o){const a=rn(t);for(;o<=s-i;i+=o)this.process(a,i);continue}r.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ne(this),nn(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:o,isLE:s}=this;let{pos:i}=this;n[i++]=128,ae(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(r,0),i=0);for(let u=i;u<o;u++)n[u]=0;Li(r,o-8,BigInt(this.length*8),s),this.process(r,0);const c=rn(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=a/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)c.setUint32(4*u,f[u],s)}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:n,buffer:r,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%n&&t.buffer.set(r),t}clone(){return this._cloneInto()}}const Ue=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]),X=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),ki=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]),_e=new Uint32Array(64);class Di extends Or{constructor(t=32){super(64,t,8,!1),this.A=Ue[0]|0,this.B=Ue[1]|0,this.C=Ue[2]|0,this.D=Ue[3]|0,this.E=Ue[4]|0,this.F=Ue[5]|0,this.G=Ue[6]|0,this.H=Ue[7]|0}get(){const{A:t,B:n,C:r,D:o,E:s,F:i,G:c,H:a}=this;return[t,n,r,o,s,i,c,a]}set(t,n,r,o,s,i,c,a){this.A=t|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=a|0}process(t,n){for(let u=0;u<16;u++,n+=4)_e[u]=t.getUint32(n,!1);for(let u=16;u<64;u++){const h=_e[u-15],g=_e[u-2],w=pe(h,7)^pe(h,18)^h>>>3,m=pe(g,17)^pe(g,19)^g>>>10;_e[u]=m+_e[u-7]+w+_e[u-16]|0}let{A:r,B:o,C:s,D:i,E:c,F:a,G:l,H:f}=this;for(let u=0;u<64;u++){const h=pe(c,6)^pe(c,11)^pe(c,25),g=f+h+ji(c,a,l)+ki[u]+_e[u]|0,m=(pe(r,2)^pe(r,13)^pe(r,22))+Pi(r,o,s)|0;f=l,l=a,a=c,c=i+g|0,i=s,s=o,o=r,r=g+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,a=a+this.F|0,l=l+this.G|0,f=f+this.H|0,this.set(r,o,s,i,c,a,l,f)}roundClean(){ae(_e)}destroy(){this.set(0,0,0,0,0,0,0,0),ae(this.buffer)}}const Ur=gr(["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(e=>BigInt(e))),Hi=Ur[0],Vi=Ur[1],Re=new Uint32Array(80),Te=new Uint32Array(80);class sn extends Or{constructor(t=64){super(128,t,16,!1),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}get(){const{Ah:t,Al:n,Bh:r,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:l,El:f,Fh:u,Fl:h,Gh:g,Gl:w,Hh:m,Hl:x}=this;return[t,n,r,o,s,i,c,a,l,f,u,h,g,w,m,x]}set(t,n,r,o,s,i,c,a,l,f,u,h,g,w,m,x){this.Ah=t|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=a|0,this.Eh=l|0,this.El=f|0,this.Fh=u|0,this.Fl=h|0,this.Gh=g|0,this.Gl=w|0,this.Hh=m|0,this.Hl=x|0}process(t,n){for(let L=0;L<16;L++,n+=4)Re[L]=t.getUint32(n),Te[L]=t.getUint32(n+=4);for(let L=16;L<80;L++){const q=Re[L-15]|0,_=Te[L-15]|0,P=Be(q,_,1)^Be(q,_,8)^br(q,_,7),j=Ie(q,_,1)^Ie(q,_,8)^mr(q,_,7),C=Re[L-2]|0,d=Te[L-2]|0,y=Be(C,d,19)^ot(C,d,61)^br(C,d,6),p=Ie(C,d,19)^st(C,d,61)^mr(C,d,6),b=mi(j,p,Te[L-7],Te[L-16]),v=yi(b,P,y,Re[L-7],Re[L-16]);Re[L]=v|0,Te[L]=b|0}let{Ah:r,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:l,Dl:f,Eh:u,El:h,Fh:g,Fl:w,Gh:m,Gl:x,Hh:T,Hl:M}=this;for(let L=0;L<80;L++){const q=Be(u,h,14)^Be(u,h,18)^ot(u,h,41),_=Ie(u,h,14)^Ie(u,h,18)^st(u,h,41),P=u&g^~u&m,j=h&w^~h&x,C=wi(M,_,j,Vi[L],Te[L]),d=xi(C,T,q,P,Hi[L],Re[L]),y=C|0,p=Be(r,o,28)^ot(r,o,34)^ot(r,o,39),b=Ie(r,o,28)^st(r,o,34)^st(r,o,39),v=r&s^r&c^s&c,A=o&i^o&a^i&a;T=m|0,M=x|0,m=g|0,x=w|0,g=u|0,w=h|0,{h:u,l:h}=le(l|0,f|0,d|0,y|0),l=c|0,f=a|0,c=s|0,a=i|0,s=r|0,i=o|0;const E=Jt(y,b,A);r=Qt(E,d,p,v),o=E|0}({h:r,l:o}=le(this.Ah|0,this.Al|0,r|0,o|0)),{h:s,l:i}=le(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=le(this.Ch|0,this.Cl|0,c|0,a|0),{h:l,l:f}=le(this.Dh|0,this.Dl|0,l|0,f|0),{h:u,l:h}=le(this.Eh|0,this.El|0,u|0,h|0),{h:g,l:w}=le(this.Fh|0,this.Fl|0,g|0,w|0),{h:m,l:x}=le(this.Gh|0,this.Gl|0,m|0,x|0),{h:T,l:M}=le(this.Hh|0,this.Hl|0,T|0,M|0),this.set(r,o,s,i,c,a,l,f,u,h,g,w,m,x,T,M)}roundClean(){ae(Re,Te)}destroy(){ae(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class Mi extends sn{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 J=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class qi extends sn{constructor(){super(32),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}}const St=ft(()=>new Di),Fi=ft(()=>new sn),Ki=ft(()=>new Mi),zi=ft(()=>new qi),Gi=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]),N=new Uint32Array(32);function Ce(e,t,n,r,o,s){const i=o[s],c=o[s+1];let a=N[2*e],l=N[2*e+1],f=N[2*t],u=N[2*t+1],h=N[2*n],g=N[2*n+1],w=N[2*r],m=N[2*r+1],x=Jt(a,f,i);l=Qt(x,l,u,c),a=x|0,{Dh:m,Dl:w}={Dh:m^l,Dl:w^a},{Dh:m,Dl:w}={Dh:li(m,w),Dl:di(m)},{h:g,l:h}=le(g,h,m,w),{Bh:u,Bl:f}={Bh:u^g,Bl:f^h},{Bh:u,Bl:f}={Bh:Be(u,f,24),Bl:Ie(u,f,24)},N[2*e]=a,N[2*e+1]=l,N[2*t]=f,N[2*t+1]=u,N[2*n]=h,N[2*n+1]=g,N[2*r]=w,N[2*r+1]=m}function $e(e,t,n,r,o,s){const i=o[s],c=o[s+1];let a=N[2*e],l=N[2*e+1],f=N[2*t],u=N[2*t+1],h=N[2*n],g=N[2*n+1],w=N[2*r],m=N[2*r+1],x=Jt(a,f,i);l=Qt(x,l,u,c),a=x|0,{Dh:m,Dl:w}={Dh:m^l,Dl:w^a},{Dh:m,Dl:w}={Dh:Be(m,w,16),Dl:Ie(m,w,16)},{h:g,l:h}=le(g,h,m,w),{Bh:u,Bl:f}={Bh:u^g,Bl:f^h},{Bh:u,Bl:f}={Bh:ot(u,f,63),Bl:st(u,f,63)},N[2*e]=a,N[2*e+1]=l,N[2*t]=f,N[2*t+1]=u,N[2*n]=h,N[2*n+1]=g,N[2*r]=w,N[2*r+1]=m}function Zi(e,t={},n,r,o){if(ye(n),e<0||e>n)throw new Error("outputLen bigger than keyLen");const{key:s,salt:i,personalization:c}=t;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 Yi extends At{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,ye(t),ye(n),this.blockLen=t,this.outputLen=n,this.buffer=new Uint8Array(t),this.buffer32=it(this.buffer)}update(t){Ne(this),t=de(t),fe(t);const{blockLen:n,buffer:r,buffer32:o}=this,s=t.length,i=t.byteOffset,c=t.buffer;for(let a=0;a<s;){this.pos===n&&(Oe(o),this.compress(o,0,!1),Oe(o),this.pos=0);const l=Math.min(n-this.pos,s-a),f=i+a;if(l===n&&!(f%4)&&a+l<s){const u=new Uint32Array(c,f,Math.floor((s-a)/4));Oe(u);for(let h=0;a+n<s;h+=o.length,a+=n)this.length+=n,this.compress(u,h,!1);Oe(u);continue}r.set(t.subarray(a,a+l),this.pos),this.pos+=l,this.length+=l,a+=l}return this}digestInto(t){Ne(this),nn(t,this);const{pos:n,buffer32:r}=this;this.finished=!0,ae(this.buffer.subarray(n)),Oe(r),this.compress(r,0,!0),Oe(r);const o=it(t);this.get().forEach((s,i)=>o[i]=we(s))}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){const{buffer:n,length:r,finished:o,destroyed:s,outputLen:i,pos:c}=this;return t||(t=new this.constructor({dkLen:i})),t.set(...this.get()),t.buffer.set(n),t.destroyed=s,t.finished=o,t.length=r,t.pos=c,t.outputLen=i,t}clone(){return this._cloneInto()}}class Wi extends Yi{constructor(t={}){const n=t.dkLen===void 0?64:t.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,Zi(n,t,64,16,16);let{key:r,personalization:o,salt:s}=t,i=0;if(r!==void 0&&(r=de(r),i=r.length),this.v0l^=this.outputLen|i<<8|65536|1<<24,s!==void 0){s=de(s);const c=it(s);this.v4l^=we(c[0]),this.v4h^=we(c[1]),this.v5l^=we(c[2]),this.v5h^=we(c[3])}if(o!==void 0){o=de(o);const c=it(o);this.v6l^=we(c[0]),this.v6h^=we(c[1]),this.v7l^=we(c[2]),this.v7h^=we(c[3])}if(r!==void 0){const c=new Uint8Array(this.blockLen);c.set(r),this.update(c)}}get(){let{v0l:t,v0h:n,v1l:r,v1h:o,v2l:s,v2h:i,v3l:c,v3h:a,v4l:l,v4h:f,v5l:u,v5h:h,v6l:g,v6h:w,v7l:m,v7h:x}=this;return[t,n,r,o,s,i,c,a,l,f,u,h,g,w,m,x]}set(t,n,r,o,s,i,c,a,l,f,u,h,g,w,m,x){this.v0l=t|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=a|0,this.v4l=l|0,this.v4h=f|0,this.v5l=u|0,this.v5h=h|0,this.v6l=g|0,this.v6h=w|0,this.v7l=m|0,this.v7h=x|0}compress(t,n,r){this.get().forEach((a,l)=>N[l]=a),N.set(z,16);let{h:o,l:s}=pr(BigInt(this.length));N[24]=z[8]^s,N[25]=z[9]^o,r&&(N[28]=~N[28],N[29]=~N[29]);let i=0;const c=Gi;for(let a=0;a<12;a++)Ce(0,4,8,12,t,n+2*c[i++]),$e(0,4,8,12,t,n+2*c[i++]),Ce(1,5,9,13,t,n+2*c[i++]),$e(1,5,9,13,t,n+2*c[i++]),Ce(2,6,10,14,t,n+2*c[i++]),$e(2,6,10,14,t,n+2*c[i++]),Ce(3,7,11,15,t,n+2*c[i++]),$e(3,7,11,15,t,n+2*c[i++]),Ce(0,5,10,15,t,n+2*c[i++]),$e(0,5,10,15,t,n+2*c[i++]),Ce(1,6,11,12,t,n+2*c[i++]),$e(1,6,11,12,t,n+2*c[i++]),Ce(2,7,8,13,t,n+2*c[i++]),$e(2,7,8,13,t,n+2*c[i++]),Ce(3,4,9,14,t,n+2*c[i++]),$e(3,4,9,14,t,n+2*c[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],ae(N)}destroy(){this.destroyed=!0,ae(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const Xi=Si(e=>new Wi(e)),Ji="https://rpc.walletconnect.org/v1";function cn(e){const t=`Ethereum Signed Message: ${e.length}`,n=new TextEncoder().encode(t+e);return"0x"+Buffer.from($i(n)).toString("hex")}async function _r(e,t,n,r,o,s){switch(n.t){case"eip191":return await Rr(e,t,n.s);case"eip1271":return await Tr(e,t,n.s,r,o,s);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${n.t}`)}}async function Rr(e,t,n){return(await bs.recoverAddress({hash:cn(t),signature:n})).toLowerCase()===e.toLowerCase()}async function Tr(e,t,n,r,o,s){const i=qt(r);if(!i.namespace||!i.reference)throw new Error(`isValidEip1271Signature failed: chainId must be in CAIP-2 format, received: ${r}`);try{const c="0x1626ba7e",a="0000000000000000000000000000000000000000000000000000000000000040",l=n.substring(2),f=(l.length/2).toString(16).padStart(64,"0"),u=(t.startsWith("0x")?t:cn(t)).substring(2),h=c+u+a+f+l,g=await fetch(`${s||Ji}/?chainId=${r}&projectId=${o}`,{headers:{"Content-Type":"application/json"},method:"POST",body:JSON.stringify({id:Qi(),jsonrpc:"2.0",method:"eth_call",params:[{to:e,data:h},"latest"]})}),{result:w}=await g.json();return w?w.slice(0,c.length).toLowerCase()===c.toLowerCase():!1}catch(c){return console.error("isValidEip1271Signature: ",c),!1}}function Qi(){return Date.now()+Math.floor(Math.random()*1e3)}function ec(e){const t=atob(e),n=new Uint8Array(t.length);for(let i=0;i<t.length;i++)n[i]=t.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(e,"base64").slice(1,65);return rt.default.encode(s)}function tc(e){const t=new Uint8Array(Buffer.from(e,"base64")),n=Array.from("TransactionData::").map(s=>s.charCodeAt(0)),r=new Uint8Array(n.length+t.length);r.set(n),r.set(t,n.length);const o=Xi(r,{dkLen:32});return rt.default.encode(o)}function nc(e){const t=new Uint8Array(St(Cr(e)));return rt.default.encode(t)}function Cr(e){if(e instanceof Uint8Array)return e;if(Array.isArray(e))return new Uint8Array(e);if(typeof e=="object"&&e!=null&&e.data)return new Uint8Array(Object.values(e.data));if(typeof e=="object"&&e)return new Uint8Array(Object.values(e));throw new Error("getNearUint8ArrayFromBytes: Unexpected result type from bytes array")}function rc(e){const t=Buffer.from(e,"base64"),n=Mn.decode(t).txn;if(!n)throw new Error("Invalid signed transaction: missing 'txn' field");const r=Mn.encode(n),o=Buffer.from("TX"),s=Buffer.concat([o,Buffer.from(r)]),i=zi(s);return ys.base32.encode(i).replace(/=+$/,"")}function fn(e){const t=[];let n=BigInt(e);for(;n>=BigInt(128);)t.push(Number(n&BigInt(127)|BigInt(128))),n>>=BigInt(7);return t.push(Number(n)),Buffer.from(t)}function oc(e){const t=Buffer.from(e.signed.bodyBytes,"base64"),n=Buffer.from(e.signed.authInfoBytes,"base64"),r=Buffer.from(e.signature.signature,"base64"),o=[];o.push(Buffer.from([10])),o.push(fn(t.length)),o.push(t),o.push(Buffer.from([18])),o.push(fn(n.length)),o.push(n),o.push(Buffer.from([26])),o.push(fn(r.length)),o.push(r);const s=Buffer.concat(o),i=St(s);return Buffer.from(i).toString("hex").toUpperCase()}var sc=Object.defineProperty,ic=Object.defineProperties,cc=Object.getOwnPropertyDescriptors,$r=Object.getOwnPropertySymbols,fc=Object.prototype.hasOwnProperty,ac=Object.prototype.propertyIsEnumerable,Lr=(e,t,n)=>t in e?sc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,an=(e,t)=>{for(var n in t||(t={}))fc.call(t,n)&&Lr(e,n,t[n]);if($r)for(var n of $r(t))ac.call(t,n)&&Lr(e,n,t[n]);return e},jr=(e,t)=>ic(e,cc(t));const uc="did:pkh:",Bt=e=>e?.split(":"),Pr=e=>{const t=e&&Bt(e);if(t)return e.includes(uc)?t[3]:t[1]},kr=e=>{const t=e&&Bt(e);if(t)return t[2]+":"+t[3]},un=e=>{const t=e&&Bt(e);if(t)return t.pop()};async function lc(e){const{cacao:t,projectId:n}=e,{s:r,p:o}=t,s=Dr(o,o.iss),i=un(o.iss);return await _r(i,s,r,kr(o.iss),n)}const Dr=(e,t)=>{const n=`${e.domain} wants you to sign in with your Ethereum account:`,r=un(t);if(!e.aud&&!e.uri)throw new Error("Either `aud` or `uri` is required to construct the message");let o=e.statement||void 0;const s=`URI: ${e.aud||e.uri}`,i=`Version: ${e.version}`,c=`Chain ID: ${Pr(t)}`,a=`Nonce: ${e.nonce}`,l=`Issued At: ${e.iat}`,f=e.exp?`Expiration Time: ${e.exp}`:void 0,u=e.nbf?`Not Before: ${e.nbf}`:void 0,h=e.requestId?`Request ID: ${e.requestId}`:void 0,g=e.resources?`Resources:${e.resources.map(m=>` - ${m}`).join("")}`:void 0,w=Nt(e.resources);if(w){const m=Le(w);o=hn(o,m)}return[n,r,"",o,"",s,i,c,a,l,f,u,h,g].filter(m=>m!=null).join(` `)};function dc(e,t,n){return n.includes("did:pkh:")||(n=`did:pkh:${n}`),{h:{t:"caip122"},p:{iss:n,domain:e.domain,aud:e.aud,version:e.version,nonce:e.nonce,iat:e.iat,statement:e.statement,requestId:e.requestId,resources:e.resources,nbf:e.nbf,exp:e.exp},s:t}}function hc(e){var t;const{authPayload:n,chains:r,methods:o}=e,s=n.statement||"";if(!(r!=null&&r.length))return n;const i=n.chains,c=Wt(i,r);if(!(c!=null&&c.length))throw new Error("No supported chains");const a=Hr(n.resources);if(!a)return n;ge(a);const l=Vr(a,"eip155");let f=n?.resources||[];if(l!=null&&l.length){const u=Mr(l),h=Wt(u,o);if(!(h!=null&&h.length))throw new Error(`Supported methods don't satisfy the requested: ${JSON.stringify(u)}, supported: ${JSON.stringify(o)}`);const g=ln("request",h,{chains:c}),w=zr(a,"eip155",g);f=((t=n?.resources)==null?void 0:t.slice(0,-1))||[],f.push(It(w))}return jr(an({},n),{statement:Zr(s,Nt(f)),chains:c,resources:n!=null&&n.resources||f.length>0?f:void 0})}function Hr(e){const t=Nt(e);if(t&&dn(t))return Le(t)}function pc(e,t){var n;return(n=e?.att)==null?void 0:n.hasOwnProperty(t)}function Vr(e,t){var n,r;return(n=e?.att)!=null&&n[t]?Object.keys((r=e?.att)==null?void 0:r[t]):[]}function gc(e){return e?.map(t=>Object.keys(t))||[]}function Mr(e){return e?.map(t=>{var n;return(n=t.split("/"))==null?void 0:n[1]})||[]}function qr(e){return Buffer.from(JSON.stringify(e)).toString("base64")}function Fr(e){return JSON.parse(Buffer.from(e,"base64").toString("utf-8"))}function ge(e){if(!e)throw new Error("No recap provided, value is undefined");if(!e.att)throw new Error("No `att` property found");const t=Object.keys(e.att);if(!(t!=null&&t.length))throw new Error("No resources found in `att` property");t.forEach(n=>{const r=e.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 Kr(e,t,n,r={}){return n?.sort((o,s)=>o.localeCompare(s)),{att:{[e]:ln(t,n,r)}}}function zr(e,t,n){var r;e.att[t]=an({},n);const o=(r=Object.keys(e.att))==null?void 0:r.sort((i,c)=>i.localeCompare(c)),s={att:{}};return o.reduce((i,c)=>(i.att[c]=e.att[c],i),s)}function ln(e,t,n={}){t=t?.sort((o,s)=>o.localeCompare(s));const r=t.map(o=>({[`${e}/${o}`]:[n]}));return Object.assign({},...r)}function It(e){return ge(e),`urn:recap:${qr(e).replace(/=/g,"")}`}function Le(e){const t=Fr(e.replace("urn:recap:",""));return ge(t),t}function bc(e,t,n){const r=Kr(e,t,n);return It(r)}function dn(e){return e&&e.includes("urn:recap:")}function mc(e,t){const n=Le(e),r=Le(t),o=Gr(n,r);return It(o)}function Gr(e,t){ge(e),ge(t);const n=Object.keys(e.att).concat(Object.keys(t.att)).sort((o,s)=>o.localeCompare(s)),r={att:{}};return n.forEach(o=>{var s,i;Object.keys(((s=e.att)==null?void 0:s[o])||{}).concat(Object.keys(((i=t.att)==null?void 0:i[o])||{})).sort((c,a)=>c.localeCompare(a)).forEach(c=>{var a,l;r.att[o]=jr(an({},r.att[o]),{[c]:((a=e.att[o])==null?void 0:a[c])||((l=t.att[o])==null?void 0:l[c])})})}),r}function hn(e="",t){ge(t);const n="I further authorize the stated URI to perform the following actions on my behalf: ";if(e.includes(n))return e;const r=[];let o=0;Object.keys(t.att).forEach(c=>{const a=Object.keys(t.att[c]).map(u=>({ability:u.split("/")[0],action:u.split("/")[1]}));a.sort((u,h)=>u.action.localeCompare(h.action));const l={};a.forEach(u=>{l[u.ability]||(l[u.ability]=[]),l[u.ability].push(u.action)});const f=Object.keys(l).map(u=>(o++,`(${o}) '${u}': '${l[u].join("', '")}' for '${c}'.`));r.push(f.join(", ").replace(".,","."))});const s=r.join(" "),i=`${n}${s}`;return`${e?e+" ":""}${i}`}function yc(e){var t;const n=Le(e);ge(n);const r=(t=n.att)==null?void 0:t.eip155;return r?Object.keys(r).map(o=>o.split("/")[1]):[]}function wc(e){const t=Le(e);ge(t);const n=[];return Object.values(t.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 Zr(e,t){if(!t)return e;const n=Le(t);return ge(n),hn(e,n)}function Nt(e){if(!e)return;const t=e?.[e.length-1];return dn(t)?t:void 0}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */function Yr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function pn(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function gn(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function re(e,...t){if(!Yr(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Wr(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function xc(e,t){re(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function je(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function We(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function vc(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}const Ec=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Ac(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function bn(e){if(typeof e=="string")e=Ac(e);else if(Yr(e))e=mn(e);else throw new Error("Uint8Array expected, got "+typeof e);return e}function Sc(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function Bc(e,t){if(e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return n===0}const Ic=(e,t)=>{function n(r,...o){if(re(r),!Ec)throw new Error("Non little-endian hardware is not yet supported");if(e.nonceLength!==void 0){const f=o[0];if(!f)throw new Error("nonce / iv required");e.varSizeNonce?re(f):re(f,e.nonceLength)}const s=e.tagLength;s&&o[1]!==void 0&&re(o[1]);const i=t(r,...o),c=(f,u)=>{if(u!==void 0){if(f!==2)throw new Error("cipher output not supported");re(u)}};let a=!1;return{encrypt(f,u){if(a)throw new Error("cannot encrypt() twice with same key + nonce");return a=!0,re(f),c(i.encrypt.length,u),i.encrypt(f,u)},decrypt(f,u){if(re(f),s&&f.length<s)throw new Error("invalid ciphertext length: smaller than tagLength="+s);return c(i.decrypt.length,u),i.decrypt(f,u)}}}return Object.assign(n,e),n};function Xr(e,t,n=!0){if(t===void 0)return new Uint8Array(e);if(t.length!==e)throw new Error("invalid output length, expected "+e+", got: "+t.length);if(n&&!Oc(t))throw new Error("invalid output, must be aligned");return t}function Jr(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const o=BigInt(32),s=BigInt(4294967295),i=Number(n>>o&s),c=Number(n&s),a=r?4:0,l=r?0:4;e.setUint32(t+a,i,r),e.setUint32(t+l,c,r)}function Nc(e,t,n){pn(n);const r=new Uint8Array(16),o=vc(r);return Jr(o,0,BigInt(t),n),Jr(o,8,BigInt(e),n),r}function Oc(e){return e.byteOffset%4===0}function mn(e){return Uint8Array.from(e)}const Qr=e=>Uint8Array.from(e.split("").map(t=>t.charCodeAt(0))),Uc=Qr("expand 16-byte k"),_c=Qr("expand 32-byte k"),Rc=je(Uc),Tc=je(_c);function H(e,t){return e<<t|e>>>32-t}function yn(e){return e.byteOffset%4===0}const Ot=64,Cc=16,eo=2**32-1,to=new Uint32Array;function $c(e,t,n,r,o,s,i,c){const a=o.length,l=new Uint8Array(Ot),f=je(l),u=yn(o)&&yn(s),h=u?je(o):to,g=u?je(s):to;for(let w=0;w<a;i++){if(e(t,n,r,f,i,c),i>=eo)throw new Error("arx: counter overflow");const m=Math.min(Ot,a-w);if(u&&m===Ot){const x=w/4;if(w%4!==0)throw new Error("arx: invalid block position");for(let T=0,M;T<Cc;T++)M=x+T,g[M]=h[M]^f[T];w+=Ot;continue}for(let x=0,T;x<m;x++)T=w+x,s[T]=o[T]^l[x];w+=m}}function Lc(e,t){const{allowShortKeys:n,extendNonceFn:r,counterLength:o,counterRight:s,rounds:i}=Sc({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return gn(o),gn(i),pn(s),pn(n),(c,a,l,f,u=0)=>{re(c),re(a),re(l);const h=l.length;if(f===void 0&&(f=new Uint8Array(h)),re(f),gn(u),u<0||u>=eo)throw new Error("arx: counter overflow");if(f.length<h)throw new Error(`arx: output (${f.length}) is shorter than data (${h})`);const g=[];let w=c.length,m,x;if(w===32)g.push(m=mn(c)),x=Tc;else if(w===16&&n)m=new Uint8Array(32),m.set(c),m.set(c,16),x=Rc,g.push(m);else throw new Error(`arx: invalid 32-byte key, got length=${w}`);yn(a)||g.push(a=mn(a));const T=je(m);if(r){if(a.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(x,T,je(a.subarray(0,16)),T),a=a.subarray(16)}const M=16-o;if(M!==a.length)throw new Error(`arx: nonce must be ${M} or 16 bytes`);if(M!==12){const q=new Uint8Array(12);q.set(a,s?0:12-a.length),a=q,g.push(a)}const L=je(a);return $c(e,x,T,L,l,f,u,i),We(...g),f}}const Z=(e,t)=>e[t++]&255|(e[t++]&255)<<8;class jc{constructor(t){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,t=bn(t),re(t,32);const n=Z(t,0),r=Z(t,2),o=Z(t,4),s=Z(t,6),i=Z(t,8),c=Z(t,10),a=Z(t,12),l=Z(t,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|a<<5)&8065,this.r[8]=(a>>>8|l<<8)&8191,this.r[9]=l>>>5&127;for(let f=0;f<8;f++)this.pad[f]=Z(t,16+2*f)}process(t,n,r=!1){const o=r?0:2048,{h:s,r:i}=this,c=i[0],a=i[1],l=i[2],f=i[3],u=i[4],h=i[5],g=i[6],w=i[7],m=i[8],x=i[9],T=Z(t,n+0),M=Z(t,n+2),L=Z(t,n+4),q=Z(t,n+6),_=Z(t,n+8),P=Z(t,n+10),j=Z(t,n+12),C=Z(t,n+14);let d=s[0]+(T&8191),y=s[1]+((T>>>13|M<<3)&8191),p=s[2]+((M>>>10|L<<6)&8191),b=s[3]+((L>>>7|q<<9)&8191),v=s[4]+((q>>>4|_<<12)&8191),A=s[5]+(_>>>1&8191),E=s[6]+((_>>>14|P<<2)&8191),S=s[7]+((P>>>11|j<<5)&8191),I=s[8]+((j>>>8|C<<8)&8191),O=s[9]+(C>>>5|o),B=0,R=B+d*c+y*(5*x)+p*(5*m)+b*(5*w)+v*(5*g);B=R>>>13,R&=8191,R+=A*(5*h)+E*(5*u)+S*(5*f)+I*(5*l)+O*(5*a),B+=R>>>13,R&=8191;let U=B+d*a+y*c+p*(5*x)+b*(5*m)+v*(5*w);B=U>>>13,U&=8191,U+=A*(5*g)+E*(5*h)+S*(5*u)+I*(5*f)+O*(5*l),B+=U>>>13,U&=8191;let $=B+d*l+y*a+p*c+b*(5*x)+v*(5*m);B=$>>>13,$&=8191,$+=A*(5*w)+E*(5*g)+S*(5*h)+I*(5*u)+O*(5*f),B+=$>>>13,$&=8191;let D=B+d*f+y*l+p*a+b*c+v*(5*x);B=D>>>13,D&=8191,D+=A*(5*m)+E*(5*w)+S*(5*g)+I*(5*h)+O*(5*u),B+=D>>>13,D&=8191;let F=B+d*u+y*f+p*l+b*a+v*c;B=F>>>13,F&=8191,F+=A*(5*x)+E*(5*m)+S*(5*w)+I*(5*g)+O*(5*h),B+=F>>>13,F&=8191;let k=B+d*h+y*u+p*f+b*l+v*a;B=k>>>13,k&=8191,k+=A*c+E*(5*x)+S*(5*m)+I*(5*w)+O*(5*g),B+=k>>>13,k&=8191;let K=B+d*g+y*h+p*u+b*f+v*l;B=K>>>13,K&=8191,K+=A*a+E*c+S*(5*x)+I*(5*m)+O*(5*w),B+=K>>>13,K&=8191;let ne=B+d*w+y*g+p*h+b*u+v*f;B=ne>>>13,ne&=8191,ne+=A*l+E*a+S*c+I*(5*x)+O*(5*m),B+=ne>>>13,ne&=8191;let Y=B+d*m+y*w+p*g+b*h+v*u;B=Y>>>13,Y&=8191,Y+=A*f+E*l+S*a+I*c+O*(5*x),B+=Y>>>13,Y&=8191;let G=B+d*x+y*m+p*w+b*g+v*h;B=G>>>13,G&=8191,G+=A*u+E*f+S*l+I*a+O*c,B+=G>>>13,G&=8191,B=(B<<2)+B|0,B=B+R|0,R=B&8191,B=B>>>13,U+=B,s[0]=R,s[1]=U,s[2]=$,s[3]=D,s[4]=F,s[5]=k,s[6]=K,s[7]=ne,s[8]=Y,s[9]=G}finalize(){const{h:t,pad:n}=this,r=new Uint16Array(10);let o=t[1]>>>13;t[1]&=8191;for(let c=2;c<10;c++)t[c]+=o,o=t[c]>>>13,t[c]&=8191;t[0]+=o*5,o=t[0]>>>13,t[0]&=8191,t[1]+=o,o=t[1]>>>13,t[1]&=8191,t[2]+=o,r[0]=t[0]+5,o=r[0]>>>13,r[0]&=8191;for(let c=1;c<10;c++)r[c]=t[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++)t[c]=t[c]&s|r[c];t[0]=(t[0]|t[1]<<13)&65535,t[1]=(t[1]>>>3|t[2]<<10)&65535,t[2]=(t[2]>>>6|t[3]<<7)&65535,t[3]=(t[3]>>>9|t[4]<<4)&65535,t[4]=(t[4]>>>12|t[5]<<1|t[6]<<14)&65535,t[5]=(t[6]>>>2|t[7]<<11)&65535,t[6]=(t[7]>>>5|t[8]<<8)&65535,t[7]=(t[8]>>>8|t[9]<<5)&65535;let i=t[0]+n[0];t[0]=i&65535;for(let c=1;c<8;c++)i=(t[c]+n[c]|0)+(i>>>16)|0,t[c]=i&65535;We(r)}update(t){Wr(this),t=bn(t),re(t);const{buffer:n,blockLen:r}=this,o=t.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(t,s);continue}n.set(t.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(){We(this.h,this.r,this.buffer,this.pad)}digestInto(t){Wr(this),xc(t,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++)t[s++]=r[i]>>>0,t[s++]=r[i]>>>8;return t}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}}function Pc(e){const t=(r,o)=>e(o).update(bn(r)).digest(),n=e(new Uint8Array(32));return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=r=>e(r),t}const kc=Pc(e=>new jc(e));function Dc(e,t,n,r,o,s=20){let i=e[0],c=e[1],a=e[2],l=e[3],f=t[0],u=t[1],h=t[2],g=t[3],w=t[4],m=t[5],x=t[6],T=t[7],M=o,L=n[0],q=n[1],_=n[2],P=i,j=c,C=a,d=l,y=f,p=u,b=h,v=g,A=w,E=m,S=x,I=T,O=M,B=L,R=q,U=_;for(let D=0;D<s;D+=2)P=P+y|0,O=H(O^P,16),A=A+O|0,y=H(y^A,12),P=P+y|0,O=H(O^P,8),A=A+O|0,y=H(y^A,7),j=j+p|0,B=H(B^j,16),E=E+B|0,p=H(p^E,12),j=j+p|0,B=H(B^j,8),E=E+B|0,p=H(p^E,7),C=C+b|0,R=H(R^C,16),S=S+R|0,b=H(b^S,12),C=C+b|0,R=H(R^C,8),S=S+R|0,b=H(b^S,7),d=d+v|0,U=H(U^d,16),I=I+U|0,v=H(v^I,12),d=d+v|0,U=H(U^d,8),I=I+U|0,v=H(v^I,7),P=P+p|0,U=H(U^P,16),S=S+U|0,p=H(p^S,12),P=P+p|0,U=H(U^P,8),S=S+U|0,p=H(p^S,7),j=j+b|0,O=H(O^j,16),I=I+O|0,b=H(b^I,12),j=j+b|0,O=H(O^j,8),I=I+O|0,b=H(b^I,7),C=C+v|0,B=H(B^C,16),A=A+B|0,v=H(v^A,12),C=C+v|0,B=H(B^C,8),A=A+B|0,v=H(v^A,7),d=d+y|0,R=H(R^d,16),E=E+R|0,y=H(y^E,12),d=d+y|0,R=H(R^d,8),E=E+R|0,y=H(y^E,7);let $=0;r[$++]=i+P|0,r[$++]=c+j|0,r[$++]=a+C|0,r[$++]=l+d|0,r[$++]=f+y|0,r[$++]=u+p|0,r[$++]=h+b|0,r[$++]=g+v|0,r[$++]=w+A|0,r[$++]=m+E|0,r[$++]=x+S|0,r[$++]=T+I|0,r[$++]=M+O|0,r[$++]=L+B|0,r[$++]=q+R|0,r[$++]=_+U|0}const Hc=Lc(Dc,{counterRight:!1,counterLength:4,allowShortKeys:!1}),Vc=new Uint8Array(16),no=(e,t)=>{e.update(t);const n=t.length%16;n&&e.update(Vc.subarray(n))},Mc=new Uint8Array(32);function ro(e,t,n,r,o){const s=e(t,n,Mc),i=kc.create(s);o&&no(i,o),no(i,r);const c=Nc(r.length,o?o.length:0,!0);i.update(c);const a=i.digest();return We(s,c),a}const qc=e=>(t,n,r)=>({encrypt(s,i){const c=s.length;i=Xr(c+16,i,!1),i.set(s);const a=i.subarray(0,-16);e(t,n,a,a,1);const l=ro(e,t,n,a,r);return i.set(l,c),We(l),i},decrypt(s,i){i=Xr(s.length-16,i,!1);const c=s.subarray(0,-16),a=s.subarray(-16),l=ro(e,t,n,c,r);if(!Bc(a,l))throw new Error("invalid tag");return i.set(s.subarray(0,-