UNPKG

@walletconnect/utils

Version:

Utilities for WalletConnect Protocol

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