@walletconnect/utils
Advanced tools
@@ -1,10 +0,11 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var Jt=require("detect-browser"),D=require("@walletconnect/time"),C=require("@walletconnect/window-getters"),Wt=require("@walletconnect/window-metadata"),Re=require("@ethersproject/hash"),zt=require("@ethersproject/transactions"),Te=require("@stablelib/chacha20poly1305"),Yt=require("@stablelib/hkdf"),B=require("@stablelib/random"),H=require("@stablelib/sha256"),Gt=require("@stablelib/x25519"),p=require("uint8arrays"),Qt=require("elliptic"),Zt=require("@walletconnect/relay-auth"),Xt=require("@walletconnect/relay-api");function en(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if(n!=="default"){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,Object.freeze(t)}var Ae=en(Gt);const J=":";function te(e){const[t,n]=e.split(J);return{namespace:t,reference:n}}function Ie(e){const{namespace:t,reference:n}=e;return[t,n].join(J)}function ne(e){const[t,n,r]=e.split(J);return{namespace:t,reference:n,address:r}}function Pe(e){const{namespace:t,reference:n,address:r}=e;return[t,n,r].join(J)}function re(e,t){const n=[];return e.forEach(r=>{const o=t(r);n.includes(o)||n.push(o)}),n}function Ce(e){const{address:t}=ne(e);return t}function je(e){const{namespace:t,reference:n}=ne(e);return Ie({namespace:t,reference:n})}function tn(e,t){const{namespace:n,reference:r}=te(t);return Pe({namespace:n,reference:r,address:e})}function nn(e){return re(e,Ce)}function $e(e){return re(e,je)}function rn(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 on(e,t=[]){const n=[];return Object.keys(e).forEach(r=>{if(t.length&&!t.includes(r))return;const o=e[r];n.push(...$e(o.accounts))}),n}function sn(e,t=[]){const n=[];return Object.keys(e).forEach(r=>{if(t.length&&!t.includes(r))return;const o=e[r];n.push(...W(r,o))}),n}function W(e,t){return e.includes(":")?[e]:t.chains||[]}const Ue="ReactNative",y={reactNative:"react-native",node:"node",browser:"browser",unknown:"unknown"},z=" ",an=":",_e="/",oe=2,cn=1e3,De="js";function se(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function O(){return!C.getDocument()&&!!C.getNavigator()&&navigator.product===Ue}function un(){return O()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="android"}function ln(){return O()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="ios"}function M(){return!se()&&!!C.getNavigator()&&!!C.getDocument()}function j(){return O()?y.reactNative:se()?y.node:M()?y.browser:y.unknown}function dn(){var e;try{return O()&&typeof global<"u"&&typeof(global==null?void 0:global.Application)<"u"?(e=global.Application)==null?void 0:e.applicationId:void 0}catch{return}}function Ve(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 pn(){return Wt.getWindowMetadata()||{name:"",description:"",url:"",icons:[""]}}function fn(e,t){var n;const r=j(),o={protocol:e,version:t,env:r};return r==="browser"&&(o.host=((n=C.getLocation())==null?void 0:n.host)||"unknown"),o}function ke(){if(j()===y.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=Jt.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 xe(){var e;const t=j();return t===y.browser?[t,((e=C.getLocation())==null?void 0:e.host)||"unknown"].join(":"):t}function Me(e,t,n){const r=ke(),o=xe();return[[e,t].join("-"),[De,n].join("-"),r,o].join("/")}function mn({protocol:e,version:t,relayUrl:n,sdkVersion:r,auth:o,projectId:s,useOnCloseEvent:a,bundleId:c,packageName:d}){const i=n.split("?"),l=Me(e,t,r),u={auth:o,ua:l,projectId:s,useOnCloseEvent:a||void 0,packageName:d||void 0,bundleId:c||void 0},f=Ve(i[1]||"",u);return i[0]+"?"+f}function gn(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 hn(e,t,n){if(!e[t]||typeof e[t]!==n)throw new Error(`Missing or invalid "${t}" param`)}function Le(e,t=oe){return Fe(e.split(_e),t)}function yn(e){return Le(e).join(z)}function R(e,t){return e.filter(n=>t.includes(n)).length===e.length}function Fe(e,t=oe){return e.slice(Math.max(e.length-t,0))}function vn(e){return Object.fromEntries(e.entries())}function En(e){return new Map(Object.entries(e))}function bn(e,t){const n={};return Object.keys(e).forEach(r=>{n[r]=t(e[r])}),n}const Nn=e=>e;function Ke(e){return e.trim().replace(/^\w/,t=>t.toUpperCase())}function Sn(e){return e.split(z).map(t=>Ke(t)).join(z)}function wn(e=D.FIVE_MINUTES,t){const n=D.toMiliseconds(e||D.FIVE_MINUTES);let r,o,s,a;return{resolve:c=>{s&&r&&(clearTimeout(s),r(c),a=Promise.resolve(c))},reject:c=>{s&&o&&(clearTimeout(s),o(c))},done:()=>new Promise((c,d)=>{if(a)return c(a);s=setTimeout(()=>{const i=new Error(t);a=Promise.reject(i),d(i)},n),r=c,o=d})}}function On(e,t,n){return new Promise(async(r,o)=>{const s=setTimeout(()=>o(new Error(n)),t);try{const a=await e;r(a)}catch(a){o(a)}clearTimeout(s)})}function ie(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 Rn(e){return ie("topic",e)}function Tn(e){return ie("id",e)}function An(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 In(e,t){return D.fromMiliseconds((t||Date.now())+D.toMiliseconds(e))}function Pn(e){return Date.now()>=D.toMiliseconds(e)}function Cn(e,t){return`${e}${t?`:${t}`:""}`}function S(e=[],t=[]){return[...new Set([...e,...t])]}async function jn({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 a=qe(s,e,t),c=j();if(c===y.browser){if(!((r=C.getDocument())!=null&&r.hasFocus())){console.warn("Document does not have focus, skipping deeplink.");return}Be(a)}else c===y.reactNative&&typeof(global==null?void 0:global.Linking)<"u"&&await global.Linking.openURL(a)}catch(o){console.error(o)}}function qe(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}${We(r,!0)}`}else o=`${o}/wc?${r}`;return o}function Be(e){let t="_self";Je()?t="_top":(He()||e.startsWith("https://")||e.startsWith("http://"))&&(t="_blank"),window.open(e,t,"noreferrer noopener")}async function $n(e,t){let n="";try{if(M()&&(n=localStorage.getItem(t),n))return n;n=await e.getItem(t)}catch(r){console.error(r)}return n}function ae(e,t){return e.filter(n=>t.includes(n))}function Un(e,t){if(!e.includes(t))return null;const n=e.split(/([&,?,=])/),r=n.indexOf(t);return n[r+2]}function _n(){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 Dn(){return typeof process<"u"&&process.env.IS_VITEST==="true"}function He(){return typeof window<"u"&&(!!window.TelegramWebviewProxy||!!window.Telegram||!!window.TelegramWebviewProxyProto)}function Je(){try{return window.self!==window.top}catch{return!1}}function We(e,t=!1){const n=Buffer.from(e).toString("base64");return t?n.replace(/[=]/g,""):n}function ce(e){return Buffer.from(e,"base64").toString("utf-8")}function Vn(e){return new Promise(t=>setTimeout(t,e))}const kn="https://rpc.walletconnect.org/v1";async function ze(e,t,n,r,o,s){switch(n.t){case"eip191":return Ye(e,t,n.s);case"eip1271":return await Ge(e,t,n.s,r,o,s);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${n.t}`)}}function Ye(e,t,n){return zt.recoverAddress(Re.hashMessage(t),n).toLowerCase()===e.toLowerCase()}async function Ge(e,t,n,r,o,s){const a=te(r);if(!a.namespace||!a.reference)throw new Error(`isValidEip1271Signature failed: chainId must be in CAIP-2 format, received: ${r}`);try{const c="0x1626ba7e",d="0000000000000000000000000000000000000000000000000000000000000040",i="0000000000000000000000000000000000000000000000000000000000000041",l=n.substring(2),u=Re.hashMessage(t).substring(2),f=c+u+d+i+l,h=await fetch(`${s||kn}/?chainId=${r}&projectId=${o}`,{method:"POST",body:JSON.stringify({id:xn(),jsonrpc:"2.0",method:"eth_call",params:[{to:e,data:f},"latest"]})}),{result:m}=await h.json();return m?m.slice(0,c.length).toLowerCase()===c.toLowerCase():!1}catch(c){return console.error("isValidEip1271Signature: ",c),!1}}function xn(){return Date.now()+Math.floor(Math.random()*1e3)}var Mn=Object.defineProperty,Ln=Object.defineProperties,Fn=Object.getOwnPropertyDescriptors,Qe=Object.getOwnPropertySymbols,Kn=Object.prototype.hasOwnProperty,qn=Object.prototype.propertyIsEnumerable,Ze=(e,t,n)=>t in e?Mn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ue=(e,t)=>{for(var n in t||(t={}))Kn.call(t,n)&&Ze(e,n,t[n]);if(Qe)for(var n of Qe(t))qn.call(t,n)&&Ze(e,n,t[n]);return e},Xe=(e,t)=>Ln(e,Fn(t));const Bn="did:pkh:",Y=e=>e?.split(":"),et=e=>{const t=e&&Y(e);if(t)return e.includes(Bn)?t[3]:t[1]},tt=e=>{const t=e&&Y(e);if(t)return t[2]+":"+t[3]},le=e=>{const t=e&&Y(e);if(t)return t.pop()};async function Hn(e){const{cacao:t,projectId:n}=e,{s:r,p:o}=t,s=nt(o,o.iss),a=le(o.iss);return await ze(a,s,r,tt(o.iss),n)}const nt=(e,t)=>{const n=`${e.domain} wants you to sign in with your Ethereum account:`,r=le(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}`,a=`Version: ${e.version}`,c=`Chain ID: ${et(t)}`,d=`Nonce: ${e.nonce}`,i=`Issued At: ${e.iat}`,l=e.exp?`Expiration Time: ${e.exp}`:void 0,u=e.nbf?`Not Before: ${e.nbf}`:void 0,f=e.requestId?`Request ID: ${e.requestId}`:void 0,h=e.resources?`Resources:${e.resources.map(g=>` | ||
- ${g}`).join("")}`:void 0,m=Q(e.resources);if(m){const g=T(m);o=fe(o,g)}return[n,r,"",o,"",s,a,c,d,i,l,u,f,h].filter(g=>g!=null).join(` | ||
`)};function Jn(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 Wn(e){var t;const{authPayload:n,chains:r,methods:o}=e,s=n.statement||"";if(!(r!=null&&r.length))return n;const a=n.chains,c=ae(a,r);if(!(c!=null&&c.length))throw new Error("No supported chains");const d=rt(n.resources);if(!d)return n;N(d);const i=ot(d,"eip155");let l=n?.resources||[];if(i!=null&&i.length){const u=st(i),f=ae(u,o);if(!(f!=null&&f.length))throw new Error(`Supported methods don't satisfy the requested: ${JSON.stringify(u)}, supported: ${JSON.stringify(o)}`);const h=de("request",f,{chains:c}),m=ut(d,"eip155",h);l=((t=n?.resources)==null?void 0:t.slice(0,-1))||[],l.push(G(m))}return Xe(ue({},n),{statement:dt(s,Q(l)),chains:c,resources:n!=null&&n.resources||l.length>0?l:void 0})}function rt(e){const t=Q(e);if(t&&pe(t))return T(t)}function zn(e,t){var n;return(n=e?.att)==null?void 0:n.hasOwnProperty(t)}function ot(e,t){var n,r;return(n=e?.att)!=null&&n[t]?Object.keys((r=e?.att)==null?void 0:r[t]):[]}function Yn(e){return e?.map(t=>Object.keys(t))||[]}function st(e){return e?.map(t=>{var n;return(n=t.split("/"))==null?void 0:n[1]})||[]}function it(e){return Buffer.from(JSON.stringify(e)).toString("base64")}function at(e){return JSON.parse(Buffer.from(e,"base64").toString("utf-8"))}function N(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(a=>{if(typeof a!="object")throw new Error(`Ability limits (${o}) must be an array of objects, found: ${a}`)})})})}function ct(e,t,n,r={}){return n?.sort((o,s)=>o.localeCompare(s)),{att:{[e]:de(t,n,r)}}}function ut(e,t,n){var r;return e.att[t]=ue({},n),((r=Object.keys(e.att))==null?void 0:r.sort((o,s)=>o.localeCompare(s))).reduce((o,s)=>(o.att[s]=e.att[s],o),{att:{}})}function de(e,t,n={}){t=t?.sort((o,s)=>o.localeCompare(s));const r=t.map(o=>({[`${e}/${o}`]:[n]}));return Object.assign({},...r)}function G(e){return N(e),`urn:recap:${it(e).replace(/=/g,"")}`}function T(e){const t=at(e.replace("urn:recap:",""));return N(t),t}function Gn(e,t,n){const r=ct(e,t,n);return G(r)}function pe(e){return e&&e.includes("urn:recap:")}function Qn(e,t){const n=T(e),r=T(t),o=lt(n,r);return G(o)}function lt(e,t){N(e),N(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,a;Object.keys(((s=e.att)==null?void 0:s[o])||{}).concat(Object.keys(((a=t.att)==null?void 0:a[o])||{})).sort((c,d)=>c.localeCompare(d)).forEach(c=>{var d,i;r.att[o]=Xe(ue({},r.att[o]),{[c]:((d=e.att[o])==null?void 0:d[c])||((i=t.att[o])==null?void 0:i[c])})})}),r}function fe(e="",t){N(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 d=Object.keys(t.att[c]).map(u=>({ability:u.split("/")[0],action:u.split("/")[1]}));d.sort((u,f)=>u.action.localeCompare(f.action));const i={};d.forEach(u=>{i[u.ability]||(i[u.ability]=[]),i[u.ability].push(u.action)});const l=Object.keys(i).map(u=>(o++,`(${o}) '${u}': '${i[u].join("', '")}' for '${c}'.`));r.push(l.join(", ").replace(".,","."))});const s=r.join(" "),a=`${n}${s}`;return`${e?e+" ":""}${a}`}function Zn(e){var t;const n=T(e);N(n);const r=(t=n.att)==null?void 0:t.eip155;return r?Object.keys(r).map(o=>o.split("/")[1]):[]}function Xn(e){const t=T(e);N(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 dt(e,t){if(!t)return e;const n=T(t);return N(n),fe(e,n)}function Q(e){if(!e)return;const t=e?.[e.length-1];return pe(t)?t:void 0}const me="base10",v="base16",ge="base64pad",er="base64url",V="utf8",he=0,k=1,L=2,tr=0,pt=1,F=12,ye=32;function nr(){const e=Ae.generateKeyPair();return{privateKey:p.toString(e.secretKey,v),publicKey:p.toString(e.publicKey,v)}}function rr(){const e=B.randomBytes(ye);return p.toString(e,v)}function or(e,t){const n=Ae.sharedKey(p.fromString(e,v),p.fromString(t,v),!0),r=new Yt.HKDF(H.SHA256,n).expand(ye);return p.toString(r,v)}function sr(e){const t=H.hash(p.fromString(e,v));return p.toString(t,v)}function ir(e){const t=H.hash(p.fromString(e,V));return p.toString(t,v)}function ve(e){return p.fromString(`${e}`,me)}function $(e){return Number(p.toString(e,me))}function ar(e){const t=ve(typeof e.type<"u"?e.type:he);if($(t)===k&&typeof e.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");const n=typeof e.senderPublicKey<"u"?p.fromString(e.senderPublicKey,v):void 0,r=typeof e.iv<"u"?p.fromString(e.iv,v):B.randomBytes(F),o=new Te.ChaCha20Poly1305(p.fromString(e.symKey,v)).seal(r,p.fromString(e.message,V));return Ee({type:t,sealed:o,iv:r,senderPublicKey:n,encoding:e.encoding})}function cr(e,t){const n=ve(L),r=B.randomBytes(F),o=p.fromString(e,V);return Ee({type:n,sealed:o,iv:r,encoding:t})}function ur(e){const t=new Te.ChaCha20Poly1305(p.fromString(e.symKey,v)),{sealed:n,iv:r}=Z({encoded:e.encoded,encoding:e?.encoding}),o=t.open(r,n);if(o===null)throw new Error("Failed to decrypt");return p.toString(o,V)}function lr(e,t){const{sealed:n}=Z({encoded:e,encoding:t});return p.toString(n,V)}function Ee(e){const{encoding:t=ge}=e;if($(e.type)===L)return p.toString(p.concat([e.type,e.sealed]),t);if($(e.type)===k){if(typeof e.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");return p.toString(p.concat([e.type,e.senderPublicKey,e.iv,e.sealed]),t)}return p.toString(p.concat([e.type,e.iv,e.sealed]),t)}function Z(e){const{encoded:t,encoding:n=ge}=e,r=p.fromString(t,n),o=r.slice(tr,pt),s=pt;if($(o)===k){const i=s+ye,l=i+F,u=r.slice(s,i),f=r.slice(i,l),h=r.slice(l);return{type:o,sealed:h,iv:f,senderPublicKey:u}}if($(o)===L){const i=r.slice(s),l=B.randomBytes(F);return{type:o,sealed:i,iv:l}}const a=s+F,c=r.slice(s,a),d=r.slice(a);return{type:o,sealed:d,iv:c}}function dr(e,t){const n=Z({encoded:e,encoding:t?.encoding});return ft({type:$(n.type),senderPublicKey:typeof n.senderPublicKey<"u"?p.toString(n.senderPublicKey,v):void 0,receiverPublicKey:t?.receiverPublicKey})}function ft(e){const t=e?.type||he;if(t===k){if(typeof e?.senderPublicKey>"u")throw new Error("missing sender public key");if(typeof e?.receiverPublicKey>"u")throw new Error("missing receiver public key")}return{type:t,senderPublicKey:e?.senderPublicKey,receiverPublicKey:e?.receiverPublicKey}}function pr(e){return e.type===k&&typeof e.senderPublicKey=="string"&&typeof e.receiverPublicKey=="string"}function fr(e){return e.type===L}function mt(e){return new Qt.ec("p256").keyFromPublic({x:Buffer.from(e.x,"base64").toString("hex"),y:Buffer.from(e.y,"base64").toString("hex")},"hex")}function mr(e){let t=e.replace(/-/g,"+").replace(/_/g,"/");const n=t.length%4;return n>0&&(t+="=".repeat(4-n)),t}function gr(e){return Buffer.from(mr(e),"base64")}function hr(e,t){const[n,r,o]=e.split("."),s=gr(o);if(s.length!==64)throw new Error("Invalid signature length");const a=s.slice(0,32).toString("hex"),c=s.slice(32,64).toString("hex"),d=`${n}.${r}`,i=new H.SHA256().update(Buffer.from(d)).digest(),l=mt(t),u=Buffer.from(i).toString("hex");if(!l.verify(u,{r:a,s:c}))throw new Error("Invalid signature");return Zt.decodeJWT(e).payload}const gt="irn";function yr(e){return e?.relay||{protocol:gt}}function vr(e){const t=Xt.RELAY_JSONRPC[e];if(typeof t>"u")throw new Error(`Relay Protocol not supported: ${e}`);return t}function ht(e,t="-"){const n={},r="relay"+t;return Object.keys(e).forEach(o=>{if(o.startsWith(r)){const s=o.replace(r,""),a=e[o];n[s]=a}}),n}function Er(e){if(!e.includes("wc:")){const i=ce(e);i!=null&&i.includes("wc:")&&(e=i)}e=e.includes("wc://")?e.replace("wc://",""):e,e=e.includes("wc:")?e.replace("wc:",""):e;const t=e.indexOf(":"),n=e.indexOf("?")!==-1?e.indexOf("?"):void 0,r=e.substring(0,t),o=e.substring(t+1,n).split("@"),s=typeof n<"u"?e.substring(n):"",a=new URLSearchParams(s),c={};a.forEach((i,l)=>{c[l]=i});const d=typeof c.methods=="string"?c.methods.split(","):void 0;return{protocol:r,topic:yt(o[0]),version:parseInt(o[1],10),symKey:c.symKey,relay:ht(c),methods:d,expiryTimestamp:c.expiryTimestamp?parseInt(c.expiryTimestamp,10):void 0}}function yt(e){return e.startsWith("//")?e.substring(2):e}function vt(e,t="-"){const n="relay",r={};return Object.keys(e).forEach(o=>{const s=n+t+o;e[o]&&(r[s]=e[o])}),r}function br(e){const t=new URLSearchParams,n=vt(e.relay);Object.keys(n).sort().forEach(o=>{t.set(o,n[o])}),t.set("symKey",e.symKey),e.expiryTimestamp&&t.set("expiryTimestamp",e.expiryTimestamp.toString()),e.methods&&t.set("methods",e.methods.join(","));const r=t.toString();return`${e.protocol}:${e.topic}@${e.version}?${r}`}function Nr(e,t,n){return`${e}?wc_ev=${n}&topic=${t}`}var Sr=Object.defineProperty,wr=Object.defineProperties,Or=Object.getOwnPropertyDescriptors,Et=Object.getOwnPropertySymbols,Rr=Object.prototype.hasOwnProperty,Tr=Object.prototype.propertyIsEnumerable,bt=(e,t,n)=>t in e?Sr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ar=(e,t)=>{for(var n in t||(t={}))Rr.call(t,n)&&bt(e,n,t[n]);if(Et)for(var n of Et(t))Tr.call(t,n)&&bt(e,n,t[n]);return e},Ir=(e,t)=>wr(e,Or(t));function U(e){const t=[];return e.forEach(n=>{const[r,o]=n.split(":");t.push(`${r}:${o}`)}),t}function Nt(e){const t=[];return Object.values(e).forEach(n=>{t.push(...U(n.accounts))}),t}function St(e,t){const n=[];return Object.values(e).forEach(r=>{U(r.accounts).includes(t)&&n.push(...r.methods)}),n}function wt(e,t){const n=[];return Object.values(e).forEach(r=>{U(r.accounts).includes(t)&&n.push(...r.events)}),n}function Pr(e,t){const n=_t(e,t);if(n)throw new Error(n.message);const r={};for(const[o,s]of Object.entries(e))r[o]={methods:s.methods,events:s.events,chains:s.accounts.map(a=>`${a.split(":")[0]}:${a.split(":")[1]}`)};return r}function Cr(e){const{proposal:{requiredNamespaces:t,optionalNamespaces:n={}},supportedNamespaces:r}=e,o=Ne(t),s=Ne(n),a={};Object.keys(r).forEach(i=>{const l=r[i].chains,u=r[i].methods,f=r[i].events,h=r[i].accounts;l.forEach(m=>{if(!h.some(g=>g.includes(m)))throw new Error(`No accounts provided for chain ${m} in namespace ${i}`)}),a[i]={chains:l,methods:u,events:f,accounts:h}});const c=Vt(t,a,"approve()");if(c)throw new Error(c.message);const d={};return!Object.keys(t).length&&!Object.keys(n).length?a:(Object.keys(o).forEach(i=>{const l=r[i].chains.filter(m=>{var g,b;return(b=(g=o[i])==null?void 0:g.chains)==null?void 0:b.includes(m)}),u=r[i].methods.filter(m=>{var g,b;return(b=(g=o[i])==null?void 0:g.methods)==null?void 0:b.includes(m)}),f=r[i].events.filter(m=>{var g,b;return(b=(g=o[i])==null?void 0:g.events)==null?void 0:b.includes(m)}),h=l.map(m=>r[i].accounts.filter(g=>g.includes(`${m}:`))).flat();d[i]={chains:l,methods:u,events:f,accounts:h}}),Object.keys(s).forEach(i=>{var l,u,f,h,m,g;if(!r[i])return;const b=(u=(l=s[i])==null?void 0:l.chains)==null?void 0:u.filter(I=>r[i].chains.includes(I)),qt=r[i].methods.filter(I=>{var P,x;return(x=(P=s[i])==null?void 0:P.methods)==null?void 0:x.includes(I)}),Bt=r[i].events.filter(I=>{var P,x;return(x=(P=s[i])==null?void 0:P.events)==null?void 0:x.includes(I)}),Ht=b?.map(I=>r[i].accounts.filter(P=>P.includes(`${I}:`))).flat();d[i]={chains:S((f=d[i])==null?void 0:f.chains,b),methods:S((h=d[i])==null?void 0:h.methods,qt),events:S((m=d[i])==null?void 0:m.events,Bt),accounts:S((g=d[i])==null?void 0:g.accounts,Ht)}}),d)}function be(e){return e.includes(":")}function Ot(e){return be(e)?e.split(":")[0]:e}function Ne(e){var t,n,r;const o={};if(!X(e))return o;for(const[s,a]of Object.entries(e)){const c=be(s)?[s]:a.chains,d=a.methods||[],i=a.events||[],l=Ot(s);o[l]=Ir(Ar({},o[l]),{chains:S(c,(t=o[l])==null?void 0:t.chains),methods:S(d,(n=o[l])==null?void 0:n.methods),events:S(i,(r=o[l])==null?void 0:r.events)})}return o}function Rt(e){const t={};return e?.forEach(n=>{const[r,o]=n.split(":");t[r]||(t[r]={accounts:[],chains:[],events:[]}),t[r].accounts.push(n),t[r].chains.push(`${r}:${o}`)}),t}function jr(e,t){t=t.map(r=>r.replace("did:pkh:",""));const n=Rt(t);for(const[r,o]of Object.entries(n))o.methods?o.methods=S(o.methods,e):o.methods=e,o.events=["chainChanged","accountsChanged"];return n}const Tt={INVALID_METHOD:{message:"Invalid method.",code:1001},INVALID_EVENT:{message:"Invalid event.",code:1002},INVALID_UPDATE_REQUEST:{message:"Invalid update request.",code:1003},INVALID_EXTEND_REQUEST:{message:"Invalid extend request.",code:1004},INVALID_SESSION_SETTLE_REQUEST:{message:"Invalid session settle request.",code:1005},UNAUTHORIZED_METHOD:{message:"Unauthorized method.",code:3001},UNAUTHORIZED_EVENT:{message:"Unauthorized event.",code:3002},UNAUTHORIZED_UPDATE_REQUEST:{message:"Unauthorized update request.",code:3003},UNAUTHORIZED_EXTEND_REQUEST:{message:"Unauthorized extend request.",code:3004},USER_REJECTED:{message:"User rejected.",code:5e3},USER_REJECTED_CHAINS:{message:"User rejected chains.",code:5001},USER_REJECTED_METHODS:{message:"User rejected methods.",code:5002},USER_REJECTED_EVENTS:{message:"User rejected events.",code:5003},UNSUPPORTED_CHAINS:{message:"Unsupported chains.",code:5100},UNSUPPORTED_METHODS:{message:"Unsupported methods.",code:5101},UNSUPPORTED_EVENTS:{message:"Unsupported events.",code:5102},UNSUPPORTED_ACCOUNTS:{message:"Unsupported accounts.",code:5103},UNSUPPORTED_NAMESPACE_KEY:{message:"Unsupported namespace key.",code:5104},USER_DISCONNECTED:{message:"User disconnected.",code:6e3},SESSION_SETTLEMENT_FAILED:{message:"Session settlement failed.",code:7e3},WC_METHOD_UNSUPPORTED:{message:"Unsupported wc_ method.",code:10001}},At={NOT_INITIALIZED:{message:"Not initialized.",code:1},NO_MATCHING_KEY:{message:"No matching key.",code:2},RESTORE_WILL_OVERRIDE:{message:"Restore will override.",code:3},RESUBSCRIBED:{message:"Resubscribed.",code:4},MISSING_OR_INVALID:{message:"Missing or invalid.",code:5},EXPIRED:{message:"Expired.",code:6},UNKNOWN_TYPE:{message:"Unknown type.",code:7},MISMATCHED_TOPIC:{message:"Mismatched topic.",code:8},NON_CONFORMING_NAMESPACES:{message:"Non conforming namespaces.",code:9}};function w(e,t){const{message:n,code:r}=At[e];return{message:t?`${n} ${t}`:n,code:r}}function _(e,t){const{message:n,code:r}=Tt[e];return{message:t?`${n} ${t}`:n,code:r}}function K(e,t){return Array.isArray(e)?typeof t<"u"&&e.length?e.every(t):!0:!1}function X(e){return Object.getPrototypeOf(e)===Object.prototype&&Object.keys(e).length}function A(e){return typeof e>"u"}function E(e,t){return t&&A(e)?!0:typeof e=="string"&&!!e.trim().length}function ee(e,t){return t&&A(e)?!0:typeof e=="number"&&!isNaN(e)}function $r(e,t){const{requiredNamespaces:n}=t,r=Object.keys(e.namespaces),o=Object.keys(n);let s=!0;return R(o,r)?(r.forEach(a=>{const{accounts:c,methods:d,events:i}=e.namespaces[a],l=U(c),u=n[a];(!R(W(a,u),l)||!R(u.methods,d)||!R(u.events,i))&&(s=!1)}),s):!1}function q(e){return E(e,!1)&&e.includes(":")?e.split(":").length===2:!1}function It(e){if(E(e,!1)&&e.includes(":")){const t=e.split(":");if(t.length===3){const n=t[0]+":"+t[1];return!!t[2]&&q(n)}}return!1}function Ur(e){function t(n){try{return typeof new URL(n)<"u"}catch{return!1}}try{if(E(e,!1)){if(t(e))return!0;const n=ce(e);return t(n)}}catch{}return!1}function _r(e){var t;return(t=e?.proposer)==null?void 0:t.publicKey}function Dr(e){return e?.topic}function Vr(e,t){let n=null;return E(e?.publicKey,!1)||(n=w("MISSING_OR_INVALID",`${t} controller public key should be a string`)),n}function Se(e){let t=!0;return K(e)?e.length&&(t=e.every(n=>E(n,!1))):t=!1,t}function Pt(e,t,n){let r=null;return K(t)&&t.length?t.forEach(o=>{r||q(o)||(r=_("UNSUPPORTED_CHAINS",`${n}, chain ${o} should be a string and conform to "namespace:chainId" format`))}):q(e)||(r=_("UNSUPPORTED_CHAINS",`${n}, chains must be defined as "namespace:chainId" e.g. "eip155:1": {...} in the namespace key OR as an array of CAIP-2 chainIds e.g. eip155: { chains: ["eip155:1", "eip155:5"] }`)),r}function Ct(e,t,n){let r=null;return Object.entries(e).forEach(([o,s])=>{if(r)return;const a=Pt(o,W(o,s),`${t} ${n}`);a&&(r=a)}),r}function jt(e,t){let n=null;return K(e)?e.forEach(r=>{n||It(r)||(n=_("UNSUPPORTED_ACCOUNTS",`${t}, account ${r} should be a string and conform to "namespace:chainId:address" format`))}):n=_("UNSUPPORTED_ACCOUNTS",`${t}, accounts should be an array of strings conforming to "namespace:chainId:address" format`),n}function $t(e,t){let n=null;return Object.values(e).forEach(r=>{if(n)return;const o=jt(r?.accounts,`${t} namespace`);o&&(n=o)}),n}function Ut(e,t){let n=null;return Se(e?.methods)?Se(e?.events)||(n=_("UNSUPPORTED_EVENTS",`${t}, events should be an array of strings or empty array for no events`)):n=_("UNSUPPORTED_METHODS",`${t}, methods should be an array of strings or empty array for no methods`),n}function we(e,t){let n=null;return Object.values(e).forEach(r=>{if(n)return;const o=Ut(r,`${t}, namespace`);o&&(n=o)}),n}function kr(e,t,n){let r=null;if(e&&X(e)){const o=we(e,t);o&&(r=o);const s=Ct(e,t,n);s&&(r=s)}else r=w("MISSING_OR_INVALID",`${t}, ${n} should be an object with data`);return r}function _t(e,t){let n=null;if(e&&X(e)){const r=we(e,t);r&&(n=r);const o=$t(e,t);o&&(n=o)}else n=w("MISSING_OR_INVALID",`${t}, namespaces should be an object with data`);return n}function Dt(e){return E(e.protocol,!0)}function xr(e,t){let n=!1;return t&&!e?n=!0:e&&K(e)&&e.length&&e.forEach(r=>{n=Dt(r)}),n}function Mr(e){return typeof e=="number"}function Lr(e){return typeof e<"u"&&typeof e!==null}function Fr(e){return!(!e||typeof e!="object"||!e.code||!ee(e.code,!1)||!e.message||!E(e.message,!1))}function Kr(e){return!(A(e)||!E(e.method,!1))}function qr(e){return!(A(e)||A(e.result)&&A(e.error)||!ee(e.id,!1)||!E(e.jsonrpc,!1))}function Br(e){return!(A(e)||!E(e.name,!1))}function Hr(e,t){return!(!q(t)||!Nt(e).includes(t))}function Jr(e,t,n){return E(n,!1)?St(e,t).includes(n):!1}function Wr(e,t,n){return E(n,!1)?wt(e,t).includes(n):!1}function Vt(e,t,n){let r=null;const o=zr(e),s=Yr(t),a=Object.keys(o),c=Object.keys(s),d=kt(Object.keys(e)),i=kt(Object.keys(t)),l=d.filter(u=>!i.includes(u));return l.length&&(r=w("NON_CONFORMING_NAMESPACES",`${n} namespaces keys don't satisfy requiredNamespaces. | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var Rr=require("detect-browser"),me=require("@walletconnect/time"),ae=require("@walletconnect/window-getters"),Tr=require("@walletconnect/window-metadata"),Ur=require("@ethersproject/transactions"),_r=require("@walletconnect/relay-auth"),N=require("uint8arrays"),Cr=require("elliptic"),Pr=require("@walletconnect/relay-api");const $e=":";function We(e){const[t,n]=e.split($e);return{namespace:t,reference:n}}function $t(e){const{namespace:t,reference:n}=e;return[t,n].join($e)}function Je(e){const[t,n,r]=e.split($e);return{namespace:t,reference:n,address:r}}function Lt(e){const{namespace:t,reference:n,address:r}=e;return[t,n,r].join($e)}function Ye(e,t){const n=[];return e.forEach(r=>{const o=t(r);n.includes(o)||n.push(o)}),n}function Bt(e){const{address:t}=Je(e);return t}function jt(e){const{namespace:t,reference:n}=Je(e);return $t({namespace:t,reference:n})}function $r(e,t){const{namespace:n,reference:r}=We(t);return Lt({namespace:n,reference:r,address:e})}function Lr(e){return Ye(e,Bt)}function kt(e){return Ye(e,jt)}function Br(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 jr(e,t=[]){const n=[];return Object.keys(e).forEach(r=>{if(t.length&&!t.includes(r))return;const o=e[r];n.push(...kt(o.accounts))}),n}function kr(e,t=[]){const n=[];return Object.keys(e).forEach(r=>{if(t.length&&!t.includes(r))return;const o=e[r];n.push(...Le(r,o))}),n}function Le(e,t){return e.includes(":")?[e]:t.chains||[]}const Vt="ReactNative",H={reactNative:"react-native",node:"node",browser:"browser",unknown:"unknown"},Be=" ",Vr=":",Dt="/",Xe=2,Dr=1e3,Mt="js";function Qe(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function te(){return!ae.getDocument()&&!!ae.getNavigator()&&navigator.product===Vt}function Mr(){return te()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="android"}function Fr(){return te()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="ios"}function Ie(){return!Qe()&&!!ae.getNavigator()&&!!ae.getDocument()}function ue(){return te()?H.reactNative:Qe()?H.node:Ie()?H.browser:H.unknown}function Hr(){var e;try{return te()&&typeof global<"u"&&typeof(global==null?void 0:global.Application)<"u"?(e=global.Application)==null?void 0:e.applicationId:void 0}catch{return}}function Ft(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 Kr(){return Tr.getWindowMetadata()||{name:"",description:"",url:"",icons:[""]}}function qr(e,t){var n;const r=ue(),o={protocol:e,version:t,env:r};return r==="browser"&&(o.host=((n=ae.getLocation())==null?void 0:n.host)||"unknown"),o}function Ht(){if(ue()===H.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=Rr.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 Kt(){var e;const t=ue();return t===H.browser?[t,((e=ae.getLocation())==null?void 0:e.host)||"unknown"].join(":"):t}function qt(e,t,n){const r=Ht(),o=Kt();return[[e,t].join("-"),[Mt,n].join("-"),r,o].join("/")}function zr({protocol:e,version:t,relayUrl:n,sdkVersion:r,auth:o,projectId:s,useOnCloseEvent:i,bundleId:c,packageName:u}){const a=n.split("?"),l=qt(e,t,r),f={auth:o,ua:l,projectId:s,useOnCloseEvent:i||void 0,packageName:u||void 0,bundleId:c||void 0},d=Ft(a[1]||"",f);return a[0]+"?"+d}function Gr(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 Wr(e,t,n){if(!e[t]||typeof e[t]!==n)throw new Error(`Missing or invalid "${t}" param`)}function zt(e,t=Xe){return Gt(e.split(Dt),t)}function Jr(e){return zt(e).join(Be)}function ne(e,t){return e.filter(n=>t.includes(n)).length===e.length}function Gt(e,t=Xe){return e.slice(Math.max(e.length-t,0))}function Yr(e){return Object.fromEntries(e.entries())}function Xr(e){return new Map(Object.entries(e))}function Qr(e,t){const n={};return Object.keys(e).forEach(r=>{n[r]=t(e[r])}),n}const Zr=e=>e;function Wt(e){return e.trim().replace(/^\w/,t=>t.toUpperCase())}function eo(e){return e.split(Be).map(t=>Wt(t)).join(Be)}function to(e=me.FIVE_MINUTES,t){const n=me.toMiliseconds(e||me.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,u)=>{if(i)return c(i);s=setTimeout(()=>{const a=new Error(t);i=Promise.reject(a),u(a)},n),r=c,o=u})}}function no(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 Ze(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 ro(e){return Ze("topic",e)}function oo(e){return Ze("id",e)}function so(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 io(e,t){return me.fromMiliseconds((t||Date.now())+me.toMiliseconds(e))}function co(e){return Date.now()>=me.toMiliseconds(e)}function ao(e,t){return`${e}${t?`:${t}`:""}`}function Q(e=[],t=[]){return[...new Set([...e,...t])]}async function uo({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=Jt(s,e,t),c=ue();if(c===H.browser){if(!((r=ae.getDocument())!=null&&r.hasFocus())){console.warn("Document does not have focus, skipping deeplink.");return}Yt(i)}else c===H.reactNative&&typeof(global==null?void 0:global.Linking)<"u"&&await global.Linking.openURL(i)}catch(o){console.error(o)}}function Jt(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}${Zt(r,!0)}`}else o=`${o}/wc?${r}`;return o}function Yt(e){let t="_self";Qt()?t="_top":(Xt()||e.startsWith("https://")||e.startsWith("http://"))&&(t="_blank"),window.open(e,t,"noreferrer noopener")}async function fo(e,t){let n="";try{if(Ie()&&(n=localStorage.getItem(t),n))return n;n=await e.getItem(t)}catch(r){console.error(r)}return n}function et(e,t){return e.filter(n=>t.includes(n))}function lo(e,t){if(!e.includes(t))return null;const n=e.split(/([&,?,=])/),r=n.indexOf(t);return n[r+2]}function po(){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 ho(){return typeof process<"u"&&process.env.IS_VITEST==="true"}function Xt(){return typeof window<"u"&&(!!window.TelegramWebviewProxy||!!window.Telegram||!!window.TelegramWebviewProxyProto)}function Qt(){try{return window.self!==window.top}catch{return!1}}function Zt(e,t=!1){const n=Buffer.from(e).toString("base64");return t?n.replace(/[=]/g,""):n}function tt(e){return Buffer.from(e,"base64").toString("utf-8")}function go(e){return new Promise(t=>setTimeout(t,e))}function Oe(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function yo(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function je(e,...t){if(!yo(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 nt(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Oe(e.outputLen),Oe(e.blockLen)}function be(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 en(e,t){je(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}const ke=BigInt(2**32-1),tn=BigInt(32);function mo(e,t=!1){return t?{h:Number(e&ke),l:Number(e>>tn&ke)}:{h:Number(e>>tn&ke)|0,l:Number(e&ke)|0}}function bo(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let o=0;o<e.length;o++){const{h:s,l:i}=mo(e[o],t);[n[o],r[o]]=[s,i]}return[n,r]}const wo=(e,t,n)=>e<<n|t>>>32-n,Eo=(e,t,n)=>t<<n|e>>>32-n,vo=(e,t,n)=>t<<n-32|e>>>64-n,xo=(e,t,n)=>e<<n-32|t>>>64-n,we=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ao(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function rt(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function W(e,t){return e<<32-t|e>>>t}const nn=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function So(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function rn(e){for(let t=0;t<e.length;t++)e[t]=So(e[t])}function No(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function Ee(e){return typeof e=="string"&&(e=No(e)),je(e),e}class ot{clone(){return this._cloneInto()}}function on(e){const t=r=>e().update(Ee(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Re(e=32){if(we&&typeof we.getRandomValues=="function")return we.getRandomValues(new Uint8Array(e));if(we&&typeof we.randomBytes=="function")return we.randomBytes(e);throw new Error("crypto.getRandomValues must be defined")}const sn=[],cn=[],an=[],Io=BigInt(0),Te=BigInt(1),Oo=BigInt(2),Ro=BigInt(7),To=BigInt(256),Uo=BigInt(113);for(let e=0,t=Te,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],sn.push(2*(5*r+n)),cn.push((e+1)*(e+2)/2%64);let o=Io;for(let s=0;s<7;s++)t=(t<<Te^(t>>Ro)*Uo)%To,t&Oo&&(o^=Te<<(Te<<BigInt(s))-Te);an.push(o)}const[_o,Co]=bo(an,!0),un=(e,t,n)=>n>32?vo(e,t,n):wo(e,t,n),fn=(e,t,n)=>n>32?xo(e,t,n):Eo(e,t,n);function Po(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,u=(i+2)%10,a=n[u],l=n[u+1],f=un(a,l,1)^n[c],d=fn(a,l,1)^n[c+1];for(let g=0;g<50;g+=10)e[i+g]^=f,e[i+g+1]^=d}let o=e[2],s=e[3];for(let i=0;i<24;i++){const c=cn[i],u=un(o,s,c),a=fn(o,s,c),l=sn[i];o=e[l],s=e[l+1],e[l]=u,e[l+1]=a}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]^=_o[r],e[1]^=Co[r]}n.fill(0)}class Pt extends ot{constructor(t,n,r,o=!1,s=24){if(super(),this.blockLen=t,this.suffix=n,this.outputLen=r,this.enableXOF=o,this.rounds=s,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,Oe(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=Ao(this.state)}keccak(){nn||rn(this.state32),Po(this.state32,this.rounds),nn||rn(this.state32),this.posOut=0,this.pos=0}update(t){be(this);const{blockLen:n,state:r}=this;t=Ee(t);const 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&&r===o-1&&this.keccak(),t[o-1]^=128,this.keccak()}writeInto(t){be(this,!1),je(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 Oe(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(en(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,this.state.fill(0)}_cloneInto(t){const{blockLen:n,suffix:r,outputLen:o,rounds:s,enableXOF:i}=this;return t||(t=new Pt(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 $o=(e,t,n)=>on(()=>new Pt(t,e,n)),Lo=$o(1,136,256/8),Bo="https://rpc.walletconnect.org/v1";function st(e){const t=`Ethereum Signed Message: | ||
${e.length}`,n=new TextEncoder().encode(t+e);return"0x"+Buffer.from(Lo(n)).toString("hex")}async function ln(e,t,n,r,o,s){switch(n.t){case"eip191":return dn(e,t,n.s);case"eip1271":return await pn(e,t,n.s,r,o,s);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${n.t}`)}}function dn(e,t,n){return Ur.recoverAddress(st(t),n).toLowerCase()===e.toLowerCase()}async function pn(e,t,n,r,o,s){const i=We(r);if(!i.namespace||!i.reference)throw new Error(`isValidEip1271Signature failed: chainId must be in CAIP-2 format, received: ${r}`);try{const c="0x1626ba7e",u="0000000000000000000000000000000000000000000000000000000000000040",a="0000000000000000000000000000000000000000000000000000000000000041",l=n.substring(2),f=st(t).substring(2),d=c+f+u+a+l,g=await fetch(`${s||Bo}/?chainId=${r}&projectId=${o}`,{method:"POST",body:JSON.stringify({id:jo(),jsonrpc:"2.0",method:"eth_call",params:[{to:e,data:d},"latest"]})}),{result:y}=await g.json();return y?y.slice(0,c.length).toLowerCase()===c.toLowerCase():!1}catch(c){return console.error("isValidEip1271Signature: ",c),!1}}function jo(){return Date.now()+Math.floor(Math.random()*1e3)}var ko=Object.defineProperty,Vo=Object.defineProperties,Do=Object.getOwnPropertyDescriptors,hn=Object.getOwnPropertySymbols,Mo=Object.prototype.hasOwnProperty,Fo=Object.prototype.propertyIsEnumerable,gn=(e,t,n)=>t in e?ko(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,it=(e,t)=>{for(var n in t||(t={}))Mo.call(t,n)&&gn(e,n,t[n]);if(hn)for(var n of hn(t))Fo.call(t,n)&&gn(e,n,t[n]);return e},yn=(e,t)=>Vo(e,Do(t));const Ho="did:pkh:",Ve=e=>e?.split(":"),mn=e=>{const t=e&&Ve(e);if(t)return e.includes(Ho)?t[3]:t[1]},bn=e=>{const t=e&&Ve(e);if(t)return t[2]+":"+t[3]},ct=e=>{const t=e&&Ve(e);if(t)return t.pop()};async function Ko(e){const{cacao:t,projectId:n}=e,{s:r,p:o}=t,s=wn(o,o.iss),i=ct(o.iss);return await ln(i,s,r,bn(o.iss),n)}const wn=(e,t)=>{const n=`${e.domain} wants you to sign in with your Ethereum account:`,r=ct(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: ${mn(t)}`,u=`Nonce: ${e.nonce}`,a=`Issued At: ${e.iat}`,l=e.exp?`Expiration Time: ${e.exp}`:void 0,f=e.nbf?`Not Before: ${e.nbf}`:void 0,d=e.requestId?`Request ID: ${e.requestId}`:void 0,g=e.resources?`Resources:${e.resources.map(p=>` | ||
- ${p}`).join("")}`:void 0,y=Me(e.resources);if(y){const p=re(y);o=ft(o,p)}return[n,r,"",o,"",s,i,c,u,a,l,f,d,g].filter(p=>p!=null).join(` | ||
`)};function qo(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 zo(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=et(i,r);if(!(c!=null&&c.length))throw new Error("No supported chains");const u=En(n.resources);if(!u)return n;J(u);const a=vn(u,"eip155");let l=n?.resources||[];if(a!=null&&a.length){const f=xn(a),d=et(f,o);if(!(d!=null&&d.length))throw new Error(`Supported methods don't satisfy the requested: ${JSON.stringify(f)}, supported: ${JSON.stringify(o)}`);const g=at("request",d,{chains:c}),y=In(u,"eip155",g);l=((t=n?.resources)==null?void 0:t.slice(0,-1))||[],l.push(De(y))}return yn(it({},n),{statement:Rn(s,Me(l)),chains:c,resources:n!=null&&n.resources||l.length>0?l:void 0})}function En(e){const t=Me(e);if(t&&ut(t))return re(t)}function Go(e,t){var n;return(n=e?.att)==null?void 0:n.hasOwnProperty(t)}function vn(e,t){var n,r;return(n=e?.att)!=null&&n[t]?Object.keys((r=e?.att)==null?void 0:r[t]):[]}function Wo(e){return e?.map(t=>Object.keys(t))||[]}function xn(e){return e?.map(t=>{var n;return(n=t.split("/"))==null?void 0:n[1]})||[]}function An(e){return Buffer.from(JSON.stringify(e)).toString("base64")}function Sn(e){return JSON.parse(Buffer.from(e,"base64").toString("utf-8"))}function J(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 Nn(e,t,n,r={}){return n?.sort((o,s)=>o.localeCompare(s)),{att:{[e]:at(t,n,r)}}}function In(e,t,n){var r;return e.att[t]=it({},n),((r=Object.keys(e.att))==null?void 0:r.sort((o,s)=>o.localeCompare(s))).reduce((o,s)=>(o.att[s]=e.att[s],o),{att:{}})}function at(e,t,n={}){t=t?.sort((o,s)=>o.localeCompare(s));const r=t.map(o=>({[`${e}/${o}`]:[n]}));return Object.assign({},...r)}function De(e){return J(e),`urn:recap:${An(e).replace(/=/g,"")}`}function re(e){const t=Sn(e.replace("urn:recap:",""));return J(t),t}function Jo(e,t,n){const r=Nn(e,t,n);return De(r)}function ut(e){return e&&e.includes("urn:recap:")}function Yo(e,t){const n=re(e),r=re(t),o=On(n,r);return De(o)}function On(e,t){J(e),J(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,u)=>c.localeCompare(u)).forEach(c=>{var u,a;r.att[o]=yn(it({},r.att[o]),{[c]:((u=e.att[o])==null?void 0:u[c])||((a=t.att[o])==null?void 0:a[c])})})}),r}function ft(e="",t){J(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 u=Object.keys(t.att[c]).map(f=>({ability:f.split("/")[0],action:f.split("/")[1]}));u.sort((f,d)=>f.action.localeCompare(d.action));const a={};u.forEach(f=>{a[f.ability]||(a[f.ability]=[]),a[f.ability].push(f.action)});const l=Object.keys(a).map(f=>(o++,`(${o}) '${f}': '${a[f].join("', '")}' for '${c}'.`));r.push(l.join(", ").replace(".,","."))});const s=r.join(" "),i=`${n}${s}`;return`${e?e+" ":""}${i}`}function Xo(e){var t;const n=re(e);J(n);const r=(t=n.att)==null?void 0:t.eip155;return r?Object.keys(r).map(o=>o.split("/")[1]):[]}function Qo(e){const t=re(e);J(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 Rn(e,t){if(!t)return e;const n=re(t);return J(n),ft(e,n)}function Me(e){if(!e)return;const t=e?.[e.length-1];return ut(t)?t:void 0}function lt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Tn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function K(e,...t){if(!Tn(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 Un(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 Zo(e,t){K(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function _n(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}const oe=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)),es=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),ts=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!ts)throw new Error("Non little-endian hardware is not supported");function ns(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function dt(e){if(typeof e=="string")e=ns(e);else if(Tn(e))e=pt(e);else throw new Error("Uint8Array expected, got "+typeof e);return e}function rs(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function os(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 ss=(e,t)=>{function n(r,...o){if(K(r),e.nonceLength!==void 0){const l=o[0];if(!l)throw new Error("nonce / iv required");e.varSizeNonce?K(l):K(l,e.nonceLength)}const s=e.tagLength;s&&o[1]!==void 0&&K(o[1]);const i=t(r,...o),c=(l,f)=>{if(f!==void 0){if(l!==2)throw new Error("cipher output not supported");K(f)}};let u=!1;return{encrypt(l,f){if(u)throw new Error("cannot encrypt() twice with same key + nonce");return u=!0,K(l),c(i.encrypt.length,f),i.encrypt(l,f)},decrypt(l,f){if(K(l),s&&l.length<s)throw new Error("invalid ciphertext length: smaller than tagLength="+s);return c(i.decrypt.length,f),i.decrypt(l,f)}}}return Object.assign(n,e),n};function Cn(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&&!is(t))throw new Error("invalid output, must be aligned");return t}function Pn(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),u=r?4:0,a=r?0:4;e.setUint32(t+u,i,r),e.setUint32(t+a,c,r)}function is(e){return e.byteOffset%4===0}function pt(e){return Uint8Array.from(e)}function ve(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}const $n=e=>Uint8Array.from(e.split("").map(t=>t.charCodeAt(0))),cs=$n("expand 16-byte k"),as=$n("expand 32-byte k"),us=oe(cs),fs=oe(as);function x(e,t){return e<<t|e>>>32-t}function ht(e){return e.byteOffset%4===0}const Fe=64,ls=16,Ln=2**32-1,Bn=new Uint32Array;function ds(e,t,n,r,o,s,i,c){const u=o.length,a=new Uint8Array(Fe),l=oe(a),f=ht(o)&&ht(s),d=f?oe(o):Bn,g=f?oe(s):Bn;for(let y=0;y<u;i++){if(e(t,n,r,l,i,c),i>=Ln)throw new Error("arx: counter overflow");const p=Math.min(Fe,u-y);if(f&&p===Fe){const m=y/4;if(y%4!==0)throw new Error("arx: invalid block position");for(let B=0,b;B<ls;B++)b=m+B,g[b]=d[b]^l[B];y+=Fe;continue}for(let m=0,B;m<p;m++)B=y+m,s[B]=o[B]^a[m];y+=p}}function ps(e,t){const{allowShortKeys:n,extendNonceFn:r,counterLength:o,counterRight:s,rounds:i}=rs({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return lt(o),lt(i),_n(s),_n(n),(c,u,a,l,f=0)=>{K(c),K(u),K(a);const d=a.length;if(l===void 0&&(l=new Uint8Array(d)),K(l),lt(f),f<0||f>=Ln)throw new Error("arx: counter overflow");if(l.length<d)throw new Error(`arx: output (${l.length}) is shorter than data (${d})`);const g=[];let y=c.length,p,m;if(y===32)g.push(p=pt(c)),m=fs;else if(y===16&&n)p=new Uint8Array(32),p.set(c),p.set(c,16),m=us,g.push(p);else throw new Error(`arx: invalid 32-byte key, got length=${y}`);ht(u)||g.push(u=pt(u));const B=oe(p);if(r){if(u.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(m,B,oe(u.subarray(0,16)),B),u=u.subarray(16)}const b=16-o;if(b!==u.length)throw new Error(`arx: nonce must be ${b} or 16 bytes`);if(b!==12){const S=new Uint8Array(12);S.set(u,s?0:12-u.length),u=S,g.push(u)}const U=oe(u);return ds(e,m,B,U,a,l,f,i),ve(...g),l}}const M=(e,t)=>e[t++]&255|(e[t++]&255)<<8;class hs{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=dt(t),K(t,32);const n=M(t,0),r=M(t,2),o=M(t,4),s=M(t,6),i=M(t,8),c=M(t,10),u=M(t,12),a=M(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|u<<5)&8065,this.r[8]=(u>>>8|a<<8)&8191,this.r[9]=a>>>5&127;for(let l=0;l<8;l++)this.pad[l]=M(t,16+2*l)}process(t,n,r=!1){const o=r?0:2048,{h:s,r:i}=this,c=i[0],u=i[1],a=i[2],l=i[3],f=i[4],d=i[5],g=i[6],y=i[7],p=i[8],m=i[9],B=M(t,n+0),b=M(t,n+2),U=M(t,n+4),S=M(t,n+6),V=M(t,n+8),E=M(t,n+10),L=M(t,n+12),j=M(t,n+14);let v=s[0]+(B&8191),A=s[1]+((B>>>13|b<<3)&8191),w=s[2]+((b>>>10|U<<6)&8191),P=s[3]+((U>>>7|S<<9)&8191),I=s[4]+((S>>>4|V<<12)&8191),_=s[5]+(V>>>1&8191),O=s[6]+((V>>>14|E<<2)&8191),R=s[7]+((E>>>11|L<<5)&8191),T=s[8]+((L>>>8|j<<8)&8191),C=s[9]+(j>>>5|o),h=0,k=h+v*c+A*(5*m)+w*(5*p)+P*(5*y)+I*(5*g);h=k>>>13,k&=8191,k+=_*(5*d)+O*(5*f)+R*(5*l)+T*(5*a)+C*(5*u),h+=k>>>13,k&=8191;let D=h+v*u+A*c+w*(5*m)+P*(5*p)+I*(5*y);h=D>>>13,D&=8191,D+=_*(5*g)+O*(5*d)+R*(5*f)+T*(5*l)+C*(5*a),h+=D>>>13,D&=8191;let $=h+v*a+A*u+w*c+P*(5*m)+I*(5*p);h=$>>>13,$&=8191,$+=_*(5*y)+O*(5*g)+R*(5*d)+T*(5*f)+C*(5*l),h+=$>>>13,$&=8191;let z=h+v*l+A*a+w*u+P*c+I*(5*m);h=z>>>13,z&=8191,z+=_*(5*p)+O*(5*y)+R*(5*g)+T*(5*d)+C*(5*f),h+=z>>>13,z&=8191;let Y=h+v*f+A*l+w*a+P*u+I*c;h=Y>>>13,Y&=8191,Y+=_*(5*m)+O*(5*p)+R*(5*y)+T*(5*g)+C*(5*d),h+=Y>>>13,Y&=8191;let X=h+v*d+A*f+w*l+P*a+I*u;h=X>>>13,X&=8191,X+=_*c+O*(5*m)+R*(5*p)+T*(5*y)+C*(5*g),h+=X>>>13,X&=8191;let pe=h+v*g+A*d+w*f+P*l+I*a;h=pe>>>13,pe&=8191,pe+=_*u+O*c+R*(5*m)+T*(5*p)+C*(5*y),h+=pe>>>13,pe&=8191;let he=h+v*y+A*g+w*d+P*f+I*l;h=he>>>13,he&=8191,he+=_*a+O*u+R*c+T*(5*m)+C*(5*p),h+=he>>>13,he&=8191;let ge=h+v*p+A*y+w*g+P*d+I*f;h=ge>>>13,ge&=8191,ge+=_*l+O*a+R*u+T*c+C*(5*m),h+=ge>>>13,ge&=8191;let ye=h+v*m+A*p+w*y+P*g+I*d;h=ye>>>13,ye&=8191,ye+=_*f+O*l+R*a+T*u+C*c,h+=ye>>>13,ye&=8191,h=(h<<2)+h|0,h=h+k|0,k=h&8191,h=h>>>13,D+=h,s[0]=k,s[1]=D,s[2]=$,s[3]=z,s[4]=Y,s[5]=X,s[6]=pe,s[7]=he,s[8]=ge,s[9]=ye}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;ve(r)}update(t){Un(this);const{buffer:n,blockLen:r}=this;t=dt(t);const 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(){ve(this.h,this.r,this.buffer,this.pad)}digestInto(t){Un(this),Zo(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 gs(e){const t=(r,o)=>e(o).update(dt(r)).digest(),n=e(new Uint8Array(32));return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=r=>e(r),t}const ys=gs(e=>new hs(e));function ms(e,t,n,r,o,s=20){let i=e[0],c=e[1],u=e[2],a=e[3],l=t[0],f=t[1],d=t[2],g=t[3],y=t[4],p=t[5],m=t[6],B=t[7],b=o,U=n[0],S=n[1],V=n[2],E=i,L=c,j=u,v=a,A=l,w=f,P=d,I=g,_=y,O=p,R=m,T=B,C=b,h=U,k=S,D=V;for(let z=0;z<s;z+=2)E=E+A|0,C=x(C^E,16),_=_+C|0,A=x(A^_,12),E=E+A|0,C=x(C^E,8),_=_+C|0,A=x(A^_,7),L=L+w|0,h=x(h^L,16),O=O+h|0,w=x(w^O,12),L=L+w|0,h=x(h^L,8),O=O+h|0,w=x(w^O,7),j=j+P|0,k=x(k^j,16),R=R+k|0,P=x(P^R,12),j=j+P|0,k=x(k^j,8),R=R+k|0,P=x(P^R,7),v=v+I|0,D=x(D^v,16),T=T+D|0,I=x(I^T,12),v=v+I|0,D=x(D^v,8),T=T+D|0,I=x(I^T,7),E=E+w|0,D=x(D^E,16),R=R+D|0,w=x(w^R,12),E=E+w|0,D=x(D^E,8),R=R+D|0,w=x(w^R,7),L=L+P|0,C=x(C^L,16),T=T+C|0,P=x(P^T,12),L=L+P|0,C=x(C^L,8),T=T+C|0,P=x(P^T,7),j=j+I|0,h=x(h^j,16),_=_+h|0,I=x(I^_,12),j=j+I|0,h=x(h^j,8),_=_+h|0,I=x(I^_,7),v=v+A|0,k=x(k^v,16),O=O+k|0,A=x(A^O,12),v=v+A|0,k=x(k^v,8),O=O+k|0,A=x(A^O,7);let $=0;r[$++]=i+E|0,r[$++]=c+L|0,r[$++]=u+j|0,r[$++]=a+v|0,r[$++]=l+A|0,r[$++]=f+w|0,r[$++]=d+P|0,r[$++]=g+I|0,r[$++]=y+_|0,r[$++]=p+O|0,r[$++]=m+R|0,r[$++]=B+T|0,r[$++]=b+C|0,r[$++]=U+h|0,r[$++]=S+k|0,r[$++]=V+D|0}const bs=ps(ms,{counterRight:!1,counterLength:4,allowShortKeys:!1}),ws=new Uint8Array(16),jn=(e,t)=>{e.update(t);const n=t.length%16;n&&e.update(ws.subarray(n))},Es=new Uint8Array(32);function kn(e,t,n,r,o){const s=e(t,n,Es),i=ys.create(s);o&&jn(i,o),jn(i,r);const c=new Uint8Array(16),u=es(c);Pn(u,0,BigInt(o?o.length:0),!0),Pn(u,8,BigInt(r.length),!0),i.update(c);const a=i.digest();return ve(s,c),a}const vs=e=>(t,n,r)=>({encrypt(s,i){const c=s.length;i=Cn(c+16,i,!1),i.set(s);const u=i.subarray(0,-16);e(t,n,u,u,1);const a=kn(e,t,n,u,r);return i.set(a,c),ve(a),i},decrypt(s,i){i=Cn(s.length-16,i,!1);const c=s.subarray(0,-16),u=s.subarray(-16),a=kn(e,t,n,c,r);if(!os(u,a))throw new Error("invalid tag");return i.set(s.subarray(0,-16)),e(t,n,i,i,1),ve(a),i}}),Vn=ss({blockSize:64,nonceLength:12,tagLength:16},vs(bs));class Dn extends ot{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,nt(t);const r=Ee(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const o=this.blockLen,s=new Uint8Array(o);s.set(r.length>o?t.create().update(r).digest():r);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(t){return be(this),this.iHash.update(t),this}digestInto(t){be(this),je(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=n._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const gt=(e,t,n)=>new Dn(e,t).update(n).digest();gt.create=(e,t)=>new Dn(e,t);function xs(e,t,n){return nt(e),n===void 0&&(n=new Uint8Array(e.outputLen)),gt(e,Ee(n),Ee(t))}const yt=new Uint8Array([0]),Mn=new Uint8Array;function As(e,t,n,r=32){if(nt(e),Oe(r),r>255*e.outputLen)throw new Error("Length should be <= 255*HashLen");const o=Math.ceil(r/e.outputLen);n===void 0&&(n=Mn);const s=new Uint8Array(o*e.outputLen),i=gt.create(e,t),c=i._cloneInto(),u=new Uint8Array(i.outputLen);for(let a=0;a<o;a++)yt[0]=a+1,c.update(a===0?Mn:u).update(n).update(yt).digestInto(u),s.set(u,e.outputLen*a),i._cloneInto(c);return i.destroy(),c.destroy(),u.fill(0),yt.fill(0),s.slice(0,r)}const Ss=(e,t,n,r,o)=>As(e,xs(e,t,n),r,o);function Ns(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),u=r?4:0,a=r?0:4;e.setUint32(t+u,i,r),e.setUint32(t+a,c,r)}function Is(e,t,n){return e&t^~e&n}function Os(e,t,n){return e&t^e&n^t&n}class Rs extends ot{constructor(t,n,r,o){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=rt(this.buffer)}update(t){be(this);const{view:n,buffer:r,blockLen:o}=this;t=Ee(t);const s=t.length;for(let i=0;i<s;){const c=Math.min(o-this.pos,s-i);if(c===o){const u=rt(t);for(;o<=s-i;i+=o)this.process(u,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){be(this),en(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:o,isLE:s}=this;let{pos:i}=this;n[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(r,0),i=0);for(let f=i;f<o;f++)n[f]=0;Ns(r,o-8,BigInt(this.length*8),s),this.process(r,0);const c=rt(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const a=u/4,l=this.get();if(a>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<a;f++)c.setUint32(4*f,l[f],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.length=o,t.pos=c,t.finished=s,t.destroyed=i,o%n&&t.buffer.set(r),t}}const Ts=new Uint32Array([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]),se=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ie=new Uint32Array(64);class Us extends Rs{constructor(){super(64,32,8,!1),this.A=se[0]|0,this.B=se[1]|0,this.C=se[2]|0,this.D=se[3]|0,this.E=se[4]|0,this.F=se[5]|0,this.G=se[6]|0,this.H=se[7]|0}get(){const{A:t,B:n,C:r,D:o,E:s,F:i,G:c,H:u}=this;return[t,n,r,o,s,i,c,u]}set(t,n,r,o,s,i,c,u){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=u|0}process(t,n){for(let f=0;f<16;f++,n+=4)ie[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){const d=ie[f-15],g=ie[f-2],y=W(d,7)^W(d,18)^d>>>3,p=W(g,17)^W(g,19)^g>>>10;ie[f]=p+ie[f-7]+y+ie[f-16]|0}let{A:r,B:o,C:s,D:i,E:c,F:u,G:a,H:l}=this;for(let f=0;f<64;f++){const d=W(c,6)^W(c,11)^W(c,25),g=l+d+Is(c,u,a)+Ts[f]+ie[f]|0,p=(W(r,2)^W(r,13)^W(r,22))+Os(r,o,s)|0;l=a,a=u,u=c,c=i+g|0,i=s,s=o,o=r,r=g+p|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,u=u+this.F|0,a=a+this.G|0,l=l+this.H|0,this.set(r,o,s,i,c,u,a,l)}roundClean(){ie.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const He=on(()=>new Us);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Fn=BigInt(0);function mt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Hn(e){if(!mt(e))throw new Error("Uint8Array expected")}const _s=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Cs(e){Hn(e);let t="";for(let n=0;n<e.length;n++)t+=_s[e[n]];return t}function Ps(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Fn:BigInt("0x"+e)}const Z={_0:48,_9:57,A:65,F:70,a:97,f:102};function Kn(e){if(e>=Z._0&&e<=Z._9)return e-Z._0;if(e>=Z.A&&e<=Z.F)return e-(Z.A-10);if(e>=Z.a&&e<=Z.f)return e-(Z.a-10)}function qn(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof 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=Kn(e.charCodeAt(s)),c=Kn(e.charCodeAt(s+1));if(i===void 0||c===void 0){const u=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+u+'" at index '+s)}r[o]=i*16+c}return r}function zn(e){return Hn(e),Ps(Cs(Uint8Array.from(e).reverse()))}function $s(e,t){return qn(e.toString(16).padStart(t*2,"0"))}function Ls(e,t){return $s(e,t).reverse()}function Gn(e,t,n){let r;if(typeof t=="string")try{r=qn(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(mt(t))r=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");const o=r.length;if(typeof n=="number"&&o!==n)throw new Error(e+" of length "+n+" expected, got "+o);return r}const bt=e=>typeof e=="bigint"&&Fn<=e;function Bs(e,t,n){return bt(e)&&bt(t)&&bt(n)&&t<=e&&e<n}function Wn(e,t,n,r){if(!Bs(t,n,r))throw new Error("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}const js={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||mt(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function ks(e,t,n={}){const r=(o,s,i)=>{const c=js[s];if(typeof c!="function")throw new Error("invalid validator function");const u=e[o];if(!(i&&u===void 0)&&!c(u,e))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+u)};for(const[o,s]of Object.entries(t))r(o,s,!1);for(const[o,s]of Object.entries(n))r(o,s,!0);return e}const xe=BigInt(0),Ke=BigInt(1);function Jn(e,t){const n=e%t;return n>=xe?n:t+n}function Vs(e,t,n){if(t<xe)throw new Error("invalid exponent, negatives unsupported");if(n<=xe)throw new Error("invalid modulus");if(n===Ke)return xe;let r=Ke;for(;t>xe;)t&Ke&&(r=r*e%n),e=e*e%n,t>>=Ke;return r}function G(e,t,n){let r=e;for(;t-- >xe;)r*=r,r%=n;return r}BigInt(0),BigInt(1),BigInt(0),BigInt(1),BigInt(2),BigInt(8);const Ae=BigInt(0),wt=BigInt(1);function Ds(e){return ks(e,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...e})}function Ms(e){const t=Ds(e),{P:n}=t,r=b=>Jn(b,n),o=t.montgomeryBits,s=Math.ceil(o/8),i=t.nByteLength,c=t.adjustScalarBytes||(b=>b),u=t.powPminus2||(b=>Vs(b,n-BigInt(2),n));function a(b,U,S){const V=r(b*(U-S));return U=r(U-V),S=r(S+V),[U,S]}const l=(t.a-BigInt(2))/BigInt(4);function f(b,U){Wn("u",b,Ae,n),Wn("scalar",U,Ae,n);const S=U,V=b;let E=wt,L=Ae,j=b,v=wt,A=Ae,w;for(let I=BigInt(o-1);I>=Ae;I--){const _=S>>I&wt;A^=_,w=a(A,E,j),E=w[0],j=w[1],w=a(A,L,v),L=w[0],v=w[1],A=_;const O=E+L,R=r(O*O),T=E-L,C=r(T*T),h=R-C,k=j+v,D=j-v,$=r(D*O),z=r(k*T),Y=$+z,X=$-z;j=r(Y*Y),v=r(V*r(X*X)),E=r(R*C),L=r(h*(R+r(l*h)))}w=a(A,E,j),E=w[0],j=w[1],w=a(A,L,v),L=w[0],v=w[1];const P=u(L);return r(E*P)}function d(b){return Ls(r(b),s)}function g(b){const U=Gn("u coordinate",b,s);return i===32&&(U[31]&=127),zn(U)}function y(b){const U=Gn("scalar",b),S=U.length;if(S!==s&&S!==i){let V=""+s+" or "+i;throw new Error("invalid scalar, expected "+V+" bytes, got "+S)}return zn(c(U))}function p(b,U){const S=g(U),V=y(b),E=f(S,V);if(E===Ae)throw new Error("invalid private or public key received");return d(E)}const m=d(t.Gu);function B(b){return p(b,m)}return{scalarMult:p,scalarMultBase:B,getSharedSecret:(b,U)=>p(b,U),getPublicKey:b=>B(b),utils:{randomPrivateKey:()=>t.randomBytes(t.nByteLength)},GuBytes:m}}const Et=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949");BigInt(0);const Fs=BigInt(1),Yn=BigInt(2),Hs=BigInt(3),Ks=BigInt(5);BigInt(8);function qs(e){const t=BigInt(10),n=BigInt(20),r=BigInt(40),o=BigInt(80),s=Et,c=e*e%s*e%s,u=G(c,Yn,s)*c%s,a=G(u,Fs,s)*e%s,l=G(a,Ks,s)*a%s,f=G(l,t,s)*l%s,d=G(f,n,s)*f%s,g=G(d,r,s)*d%s,y=G(g,o,s)*g%s,p=G(y,o,s)*g%s,m=G(p,t,s)*l%s;return{pow_p_5_8:G(m,Yn,s)*e%s,b2:c}}function zs(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}const vt=(()=>Ms({P:Et,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:e=>{const t=Et,{pow_p_5_8:n,b2:r}=qs(e);return Jn(G(n,Hs,t)*r,t)},adjustScalarBytes:zs,randomBytes:Re}))(),xt="base10",F="base16",At="base64pad",Gs="base64url",Se="utf8",St=0,Ne=1,Ue=2,Ws=0,Xn=1,_e=12,Nt=32;function Js(){const e=vt.utils.randomPrivateKey(),t=vt.getPublicKey(e);return{privateKey:N.toString(e,F),publicKey:N.toString(t,F)}}function Ys(){const e=Re(Nt);return N.toString(e,F)}function Xs(e,t){const n=vt.getSharedSecret(N.fromString(e,F),N.fromString(t,F)),r=Ss(He,n,void 0,void 0,Nt);return N.toString(r,F)}function Qs(e){const t=He(N.fromString(e,F));return N.toString(t,F)}function Zs(e){const t=He(N.fromString(e,Se));return N.toString(t,F)}function It(e){return N.fromString(`${e}`,xt)}function fe(e){return Number(N.toString(e,xt))}function ei(e){const t=It(typeof e.type<"u"?e.type:St);if(fe(t)===Ne&&typeof e.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");const n=typeof e.senderPublicKey<"u"?N.fromString(e.senderPublicKey,F):void 0,r=typeof e.iv<"u"?N.fromString(e.iv,F):Re(_e),o=N.fromString(e.symKey,F),s=Vn(o,r).encrypt(N.fromString(e.message,Se));return Ot({type:t,sealed:s,iv:r,senderPublicKey:n,encoding:e.encoding})}function ti(e){const t=N.fromString(e.symKey,F),{sealed:n,iv:r}=qe(e),o=Vn(t,r).decrypt(n);if(o===null)throw new Error("Failed to decrypt");return N.toString(o,Se)}function ni(e,t){const n=It(Ue),r=Re(_e),o=N.fromString(e,Se);return Ot({type:n,sealed:o,iv:r,encoding:t})}function ri(e,t){const{sealed:n}=qe({encoded:e,encoding:t});return N.toString(n,Se)}function Ot(e){const{encoding:t=At}=e;if(fe(e.type)===Ue)return N.toString(N.concat([e.type,e.sealed]),t);if(fe(e.type)===Ne){if(typeof e.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");return N.toString(N.concat([e.type,e.senderPublicKey,e.iv,e.sealed]),t)}return N.toString(N.concat([e.type,e.iv,e.sealed]),t)}function qe(e){const{encoded:t,encoding:n=At}=e,r=N.fromString(t,n),o=r.slice(Ws,Xn),s=Xn;if(fe(o)===Ne){const a=s+Nt,l=a+_e,f=r.slice(s,a),d=r.slice(a,l),g=r.slice(l);return{type:o,sealed:g,iv:d,senderPublicKey:f}}if(fe(o)===Ue){const a=r.slice(s),l=Re(_e);return{type:o,sealed:a,iv:l}}const i=s+_e,c=r.slice(s,i),u=r.slice(i);return{type:o,sealed:u,iv:c}}function oi(e,t){const n=qe({encoded:e,encoding:t?.encoding});return Qn({type:fe(n.type),senderPublicKey:typeof n.senderPublicKey<"u"?N.toString(n.senderPublicKey,F):void 0,receiverPublicKey:t?.receiverPublicKey})}function Qn(e){const t=e?.type||St;if(t===Ne){if(typeof e?.senderPublicKey>"u")throw new Error("missing sender public key");if(typeof e?.receiverPublicKey>"u")throw new Error("missing receiver public key")}return{type:t,senderPublicKey:e?.senderPublicKey,receiverPublicKey:e?.receiverPublicKey}}function si(e){return e.type===Ne&&typeof e.senderPublicKey=="string"&&typeof e.receiverPublicKey=="string"}function ii(e){return e.type===Ue}function Zn(e){return new Cr.ec("p256").keyFromPublic({x:Buffer.from(e.x,"base64").toString("hex"),y:Buffer.from(e.y,"base64").toString("hex")},"hex")}function ci(e){let t=e.replace(/-/g,"+").replace(/_/g,"/");const n=t.length%4;return n>0&&(t+="=".repeat(4-n)),t}function ai(e){return Buffer.from(ci(e),"base64")}function ui(e,t){const[n,r,o]=e.split("."),s=ai(o);if(s.length!==64)throw new Error("Invalid signature length");const i=s.slice(0,32).toString("hex"),c=s.slice(32,64).toString("hex"),u=`${n}.${r}`,a=He(u),l=Zn(t),f=N.toString(a,F);if(!l.verify(f,{r:i,s:c}))throw new Error("Invalid signature");return _r.decodeJWT(e).payload}const er="irn";function fi(e){return e?.relay||{protocol:er}}function li(e){const t=Pr.RELAY_JSONRPC[e];if(typeof t>"u")throw new Error(`Relay Protocol not supported: ${e}`);return t}function tr(e,t="-"){const n={},r="relay"+t;return Object.keys(e).forEach(o=>{if(o.startsWith(r)){const s=o.replace(r,""),i=e[o];n[s]=i}}),n}function di(e){if(!e.includes("wc:")){const a=tt(e);a!=null&&a.includes("wc:")&&(e=a)}e=e.includes("wc://")?e.replace("wc://",""):e,e=e.includes("wc:")?e.replace("wc:",""):e;const t=e.indexOf(":"),n=e.indexOf("?")!==-1?e.indexOf("?"):void 0,r=e.substring(0,t),o=e.substring(t+1,n).split("@"),s=typeof n<"u"?e.substring(n):"",i=new URLSearchParams(s),c={};i.forEach((a,l)=>{c[l]=a});const u=typeof c.methods=="string"?c.methods.split(","):void 0;return{protocol:r,topic:nr(o[0]),version:parseInt(o[1],10),symKey:c.symKey,relay:tr(c),methods:u,expiryTimestamp:c.expiryTimestamp?parseInt(c.expiryTimestamp,10):void 0}}function nr(e){return e.startsWith("//")?e.substring(2):e}function rr(e,t="-"){const n="relay",r={};return Object.keys(e).forEach(o=>{const s=n+t+o;e[o]&&(r[s]=e[o])}),r}function pi(e){const t=new URLSearchParams,n=rr(e.relay);Object.keys(n).sort().forEach(o=>{t.set(o,n[o])}),t.set("symKey",e.symKey),e.expiryTimestamp&&t.set("expiryTimestamp",e.expiryTimestamp.toString()),e.methods&&t.set("methods",e.methods.join(","));const r=t.toString();return`${e.protocol}:${e.topic}@${e.version}?${r}`}function hi(e,t,n){return`${e}?wc_ev=${n}&topic=${t}`}var gi=Object.defineProperty,yi=Object.defineProperties,mi=Object.getOwnPropertyDescriptors,or=Object.getOwnPropertySymbols,bi=Object.prototype.hasOwnProperty,wi=Object.prototype.propertyIsEnumerable,sr=(e,t,n)=>t in e?gi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ei=(e,t)=>{for(var n in t||(t={}))bi.call(t,n)&&sr(e,n,t[n]);if(or)for(var n of or(t))wi.call(t,n)&&sr(e,n,t[n]);return e},vi=(e,t)=>yi(e,mi(t));function le(e){const t=[];return e.forEach(n=>{const[r,o]=n.split(":");t.push(`${r}:${o}`)}),t}function ir(e){const t=[];return Object.values(e).forEach(n=>{t.push(...le(n.accounts))}),t}function cr(e,t){const n=[];return Object.values(e).forEach(r=>{le(r.accounts).includes(t)&&n.push(...r.methods)}),n}function ar(e,t){const n=[];return Object.values(e).forEach(r=>{le(r.accounts).includes(t)&&n.push(...r.events)}),n}function xi(e,t){const n=wr(e,t);if(n)throw new Error(n.message);const r={};for(const[o,s]of Object.entries(e))r[o]={methods:s.methods,events:s.events,chains:s.accounts.map(i=>`${i.split(":")[0]}:${i.split(":")[1]}`)};return r}function Ai(e){const{proposal:{requiredNamespaces:t,optionalNamespaces:n={}},supportedNamespaces:r}=e,o=Tt(t),s=Tt(n),i={};Object.keys(r).forEach(a=>{const l=r[a].chains,f=r[a].methods,d=r[a].events,g=r[a].accounts;l.forEach(y=>{if(!g.some(p=>p.includes(y)))throw new Error(`No accounts provided for chain ${y} in namespace ${a}`)}),i[a]={chains:l,methods:f,events:d,accounts:g}});const c=vr(t,i,"approve()");if(c)throw new Error(c.message);const u={};return!Object.keys(t).length&&!Object.keys(n).length?i:(Object.keys(o).forEach(a=>{const l=r[a].chains.filter(y=>{var p,m;return(m=(p=o[a])==null?void 0:p.chains)==null?void 0:m.includes(y)}),f=r[a].methods.filter(y=>{var p,m;return(m=(p=o[a])==null?void 0:p.methods)==null?void 0:m.includes(y)}),d=r[a].events.filter(y=>{var p,m;return(m=(p=o[a])==null?void 0:p.events)==null?void 0:m.includes(y)}),g=l.map(y=>r[a].accounts.filter(p=>p.includes(`${y}:`))).flat();u[a]={chains:l,methods:f,events:d,accounts:g}}),Object.keys(s).forEach(a=>{var l,f,d,g,y,p;if(!r[a])return;const m=(f=(l=s[a])==null?void 0:l.chains)==null?void 0:f.filter(S=>r[a].chains.includes(S)),B=r[a].methods.filter(S=>{var V,E;return(E=(V=s[a])==null?void 0:V.methods)==null?void 0:E.includes(S)}),b=r[a].events.filter(S=>{var V,E;return(E=(V=s[a])==null?void 0:V.events)==null?void 0:E.includes(S)}),U=m?.map(S=>r[a].accounts.filter(V=>V.includes(`${S}:`))).flat();u[a]={chains:Q((d=u[a])==null?void 0:d.chains,m),methods:Q((g=u[a])==null?void 0:g.methods,B),events:Q((y=u[a])==null?void 0:y.events,b),accounts:Q((p=u[a])==null?void 0:p.accounts,U)}}),u)}function Rt(e){return e.includes(":")}function ur(e){return Rt(e)?e.split(":")[0]:e}function Tt(e){var t,n,r;const o={};if(!ze(e))return o;for(const[s,i]of Object.entries(e)){const c=Rt(s)?[s]:i.chains,u=i.methods||[],a=i.events||[],l=ur(s);o[l]=vi(Ei({},o[l]),{chains:Q(c,(t=o[l])==null?void 0:t.chains),methods:Q(u,(n=o[l])==null?void 0:n.methods),events:Q(a,(r=o[l])==null?void 0:r.events)})}return o}function fr(e){const t={};return e?.forEach(n=>{const[r,o]=n.split(":");t[r]||(t[r]={accounts:[],chains:[],events:[]}),t[r].accounts.push(n),t[r].chains.push(`${r}:${o}`)}),t}function Si(e,t){t=t.map(r=>r.replace("did:pkh:",""));const n=fr(t);for(const[r,o]of Object.entries(n))o.methods?o.methods=Q(o.methods,e):o.methods=e,o.events=["chainChanged","accountsChanged"];return n}const lr={INVALID_METHOD:{message:"Invalid method.",code:1001},INVALID_EVENT:{message:"Invalid event.",code:1002},INVALID_UPDATE_REQUEST:{message:"Invalid update request.",code:1003},INVALID_EXTEND_REQUEST:{message:"Invalid extend request.",code:1004},INVALID_SESSION_SETTLE_REQUEST:{message:"Invalid session settle request.",code:1005},UNAUTHORIZED_METHOD:{message:"Unauthorized method.",code:3001},UNAUTHORIZED_EVENT:{message:"Unauthorized event.",code:3002},UNAUTHORIZED_UPDATE_REQUEST:{message:"Unauthorized update request.",code:3003},UNAUTHORIZED_EXTEND_REQUEST:{message:"Unauthorized extend request.",code:3004},USER_REJECTED:{message:"User rejected.",code:5e3},USER_REJECTED_CHAINS:{message:"User rejected chains.",code:5001},USER_REJECTED_METHODS:{message:"User rejected methods.",code:5002},USER_REJECTED_EVENTS:{message:"User rejected events.",code:5003},UNSUPPORTED_CHAINS:{message:"Unsupported chains.",code:5100},UNSUPPORTED_METHODS:{message:"Unsupported methods.",code:5101},UNSUPPORTED_EVENTS:{message:"Unsupported events.",code:5102},UNSUPPORTED_ACCOUNTS:{message:"Unsupported accounts.",code:5103},UNSUPPORTED_NAMESPACE_KEY:{message:"Unsupported namespace key.",code:5104},USER_DISCONNECTED:{message:"User disconnected.",code:6e3},SESSION_SETTLEMENT_FAILED:{message:"Session settlement failed.",code:7e3},WC_METHOD_UNSUPPORTED:{message:"Unsupported wc_ method.",code:10001}},dr={NOT_INITIALIZED:{message:"Not initialized.",code:1},NO_MATCHING_KEY:{message:"No matching key.",code:2},RESTORE_WILL_OVERRIDE:{message:"Restore will override.",code:3},RESUBSCRIBED:{message:"Resubscribed.",code:4},MISSING_OR_INVALID:{message:"Missing or invalid.",code:5},EXPIRED:{message:"Expired.",code:6},UNKNOWN_TYPE:{message:"Unknown type.",code:7},MISMATCHED_TOPIC:{message:"Mismatched topic.",code:8},NON_CONFORMING_NAMESPACES:{message:"Non conforming namespaces.",code:9}};function ee(e,t){const{message:n,code:r}=dr[e];return{message:t?`${n} ${t}`:n,code:r}}function de(e,t){const{message:n,code:r}=lr[e];return{message:t?`${n} ${t}`:n,code:r}}function Ce(e,t){return Array.isArray(e)?typeof t<"u"&&e.length?e.every(t):!0:!1}function ze(e){return Object.getPrototypeOf(e)===Object.prototype&&Object.keys(e).length}function ce(e){return typeof e>"u"}function q(e,t){return t&&ce(e)?!0:typeof e=="string"&&!!e.trim().length}function Ge(e,t){return t&&ce(e)?!0:typeof e=="number"&&!isNaN(e)}function Ni(e,t){const{requiredNamespaces:n}=t,r=Object.keys(e.namespaces),o=Object.keys(n);let s=!0;return ne(o,r)?(r.forEach(i=>{const{accounts:c,methods:u,events:a}=e.namespaces[i],l=le(c),f=n[i];(!ne(Le(i,f),l)||!ne(f.methods,u)||!ne(f.events,a))&&(s=!1)}),s):!1}function Pe(e){return q(e,!1)&&e.includes(":")?e.split(":").length===2:!1}function pr(e){if(q(e,!1)&&e.includes(":")){const t=e.split(":");if(t.length===3){const n=t[0]+":"+t[1];return!!t[2]&&Pe(n)}}return!1}function Ii(e){function t(n){try{return typeof new URL(n)<"u"}catch{return!1}}try{if(q(e,!1)){if(t(e))return!0;const n=tt(e);return t(n)}}catch{}return!1}function Oi(e){var t;return(t=e?.proposer)==null?void 0:t.publicKey}function Ri(e){return e?.topic}function Ti(e,t){let n=null;return q(e?.publicKey,!1)||(n=ee("MISSING_OR_INVALID",`${t} controller public key should be a string`)),n}function Ut(e){let t=!0;return Ce(e)?e.length&&(t=e.every(n=>q(n,!1))):t=!1,t}function hr(e,t,n){let r=null;return Ce(t)&&t.length?t.forEach(o=>{r||Pe(o)||(r=de("UNSUPPORTED_CHAINS",`${n}, chain ${o} should be a string and conform to "namespace:chainId" format`))}):Pe(e)||(r=de("UNSUPPORTED_CHAINS",`${n}, chains must be defined as "namespace:chainId" e.g. "eip155:1": {...} in the namespace key OR as an array of CAIP-2 chainIds e.g. eip155: { chains: ["eip155:1", "eip155:5"] }`)),r}function gr(e,t,n){let r=null;return Object.entries(e).forEach(([o,s])=>{if(r)return;const i=hr(o,Le(o,s),`${t} ${n}`);i&&(r=i)}),r}function yr(e,t){let n=null;return Ce(e)?e.forEach(r=>{n||pr(r)||(n=de("UNSUPPORTED_ACCOUNTS",`${t}, account ${r} should be a string and conform to "namespace:chainId:address" format`))}):n=de("UNSUPPORTED_ACCOUNTS",`${t}, accounts should be an array of strings conforming to "namespace:chainId:address" format`),n}function mr(e,t){let n=null;return Object.values(e).forEach(r=>{if(n)return;const o=yr(r?.accounts,`${t} namespace`);o&&(n=o)}),n}function br(e,t){let n=null;return Ut(e?.methods)?Ut(e?.events)||(n=de("UNSUPPORTED_EVENTS",`${t}, events should be an array of strings or empty array for no events`)):n=de("UNSUPPORTED_METHODS",`${t}, methods should be an array of strings or empty array for no methods`),n}function _t(e,t){let n=null;return Object.values(e).forEach(r=>{if(n)return;const o=br(r,`${t}, namespace`);o&&(n=o)}),n}function Ui(e,t,n){let r=null;if(e&&ze(e)){const o=_t(e,t);o&&(r=o);const s=gr(e,t,n);s&&(r=s)}else r=ee("MISSING_OR_INVALID",`${t}, ${n} should be an object with data`);return r}function wr(e,t){let n=null;if(e&&ze(e)){const r=_t(e,t);r&&(n=r);const o=mr(e,t);o&&(n=o)}else n=ee("MISSING_OR_INVALID",`${t}, namespaces should be an object with data`);return n}function Er(e){return q(e.protocol,!0)}function _i(e,t){let n=!1;return t&&!e?n=!0:e&&Ce(e)&&e.length&&e.forEach(r=>{n=Er(r)}),n}function Ci(e){return typeof e=="number"}function Pi(e){return typeof e<"u"&&typeof e!==null}function $i(e){return!(!e||typeof e!="object"||!e.code||!Ge(e.code,!1)||!e.message||!q(e.message,!1))}function Li(e){return!(ce(e)||!q(e.method,!1))}function Bi(e){return!(ce(e)||ce(e.result)&&ce(e.error)||!Ge(e.id,!1)||!q(e.jsonrpc,!1))}function ji(e){return!(ce(e)||!q(e.name,!1))}function ki(e,t){return!(!Pe(t)||!ir(e).includes(t))}function Vi(e,t,n){return q(n,!1)?cr(e,t).includes(n):!1}function Di(e,t,n){return q(n,!1)?ar(e,t).includes(n):!1}function vr(e,t,n){let r=null;const o=Mi(e),s=Fi(t),i=Object.keys(o),c=Object.keys(s),u=xr(Object.keys(e)),a=xr(Object.keys(t)),l=u.filter(f=>!a.includes(f));return l.length&&(r=ee("NON_CONFORMING_NAMESPACES",`${n} namespaces keys don't satisfy requiredNamespaces. | ||
Required: ${l.toString()} | ||
Received: ${Object.keys(t).toString()}`)),R(a,c)||(r=w("NON_CONFORMING_NAMESPACES",`${n} namespaces chains don't satisfy required namespaces. | ||
Required: ${a.toString()} | ||
Approved: ${c.toString()}`)),Object.keys(t).forEach(u=>{if(!u.includes(":")||r)return;const f=U(t[u].accounts);f.includes(u)||(r=w("NON_CONFORMING_NAMESPACES",`${n} namespaces accounts don't satisfy namespace accounts for ${u} | ||
Required: ${u} | ||
Approved: ${f.toString()}`))}),a.forEach(u=>{r||(R(o[u].methods,s[u].methods)?R(o[u].events,s[u].events)||(r=w("NON_CONFORMING_NAMESPACES",`${n} namespaces events don't satisfy namespace events for ${u}`)):r=w("NON_CONFORMING_NAMESPACES",`${n} namespaces methods don't satisfy namespace methods for ${u}`))}),r}function zr(e){const t={};return Object.keys(e).forEach(n=>{var r;n.includes(":")?t[n]=e[n]:(r=e[n].chains)==null||r.forEach(o=>{t[o]={methods:e[n].methods,events:e[n].events}})}),t}function kt(e){return[...new Set(e.map(t=>t.includes(":")?t.split(":")[0]:t))]}function Yr(e){const t={};return Object.keys(e).forEach(n=>{if(n.includes(":"))t[n]=e[n];else{const r=U(e[n].accounts);r?.forEach(o=>{t[o]={accounts:e[n].accounts.filter(s=>s.includes(`${o}:`)),methods:e[n].methods,events:e[n].events}})}}),t}function Gr(e,t){return ee(e,!1)&&e<=t.max&&e>=t.min}function Qr(){const e=j();return new Promise(t=>{switch(e){case y.browser:t(xt());break;case y.reactNative:t(Mt());break;case y.node:t(Lt());break;default:t(!0)}})}function xt(){return M()&&navigator?.onLine}async function Mt(){if(O()&&typeof global<"u"&&global!=null&&global.NetInfo){const e=await(global==null?void 0:global.NetInfo.fetch());return e?.isConnected}return!0}function Lt(){return!0}function Zr(e){switch(j()){case y.browser:Ft(e);break;case y.reactNative:Kt(e);break;case y.node:break}}function Ft(e){!O()&&M()&&(window.addEventListener("online",()=>e(!0)),window.addEventListener("offline",()=>e(!1)))}function Kt(e){O()&&typeof global<"u"&&global!=null&&global.NetInfo&&global?.NetInfo.addEventListener(t=>e(t?.isConnected))}const Oe={};class Xr{static get(t){return Oe[t]}static set(t,n){Oe[t]=n}static delete(t){delete Oe[t]}}exports.BASE10=me,exports.BASE16=v,exports.BASE64=ge,exports.BASE64URL=er,exports.COLON=an,exports.DEFAULT_DEPTH=oe,exports.EMPTY_SPACE=z,exports.ENV_MAP=y,exports.INTERNAL_ERRORS=At,exports.MemoryStore=Xr,exports.ONE_THOUSAND=cn,exports.REACT_NATIVE_PRODUCT=Ue,exports.RELAYER_DEFAULT_PROTOCOL=gt,exports.SDK_ERRORS=Tt,exports.SDK_TYPE=De,exports.SLASH=_e,exports.TYPE_0=he,exports.TYPE_1=k,exports.TYPE_2=L,exports.UTF8=V,exports.addResourceToRecap=ut,exports.appendToQueryString=Ve,exports.assertType=hn,exports.assignAbilityToActions=de,exports.base64Decode=at,exports.base64Encode=it,exports.buildApprovedNamespaces=Cr,exports.buildAuthObject=Jn,exports.buildNamespacesFromAuth=jr,exports.buildRecapStatement=dt,exports.calcExpiry=In,exports.capitalize=Sn,exports.capitalizeWord=Ke,exports.createDelayedPromise=wn,exports.createEncodedRecap=Gn,exports.createExpiringPromise=On,exports.createRecap=ct,exports.decodeRecap=T,exports.decodeTypeByte=$,exports.decodeTypeTwoEnvelope=lr,exports.decrypt=ur,exports.deriveSymKey=or,exports.deserialize=Z,exports.encodeRecap=G,exports.encodeTypeByte=ve,exports.encodeTypeTwoEnvelope=cr,exports.encrypt=ar,exports.engineEvent=Cn,exports.enumify=Nn,exports.formatAccountId=Pe,exports.formatAccountWithChain=tn,exports.formatChainId=Ie,exports.formatDeeplinkUrl=qe,exports.formatExpirerTarget=ie,exports.formatIdTarget=Tn,exports.formatMessage=nt,exports.formatMessageContext=yn,exports.formatRelayParams=vt,exports.formatRelayRpcUrl=mn,exports.formatStatementFromRecap=fe,exports.formatTopicTarget=Rn,exports.formatUA=Me,exports.formatUri=br,exports.fromBase64=ce,exports.generateKeyPair=nr,exports.generateRandomBytes32=rr,exports.getAccountsChains=U,exports.getAccountsFromNamespaces=rn,exports.getAddressFromAccount=Ce,exports.getAddressesFromAccounts=nn,exports.getAppId=dn,exports.getAppMetadata=pn,exports.getBrowserOnlineStatus=xt,exports.getChainFromAccount=je,exports.getChainsFromAccounts=$e,exports.getChainsFromNamespace=W,exports.getChainsFromNamespaces=on,exports.getChainsFromRecap=Xn,exports.getChainsFromRequiredNamespaces=sn,exports.getCommonValuesInArrays=ae,exports.getCryptoKeyFromKeyData=mt,exports.getDecodedRecapFromResources=rt,exports.getDeepLink=$n,exports.getDidAddress=le,exports.getDidAddressSegments=Y,exports.getDidChainId=et,exports.getEnvironment=j,exports.getHttpUrl=gn,exports.getInternalError=w,exports.getJavascriptID=xe,exports.getJavascriptOS=ke,exports.getLastItems=Fe,exports.getLinkModeURL=Nr,exports.getMethodsFromRecap=Zn,exports.getNamespacedDidChainId=tt,exports.getNamespacesChains=Nt,exports.getNamespacesEventsForChainId=wt,exports.getNamespacesFromAccounts=Rt,exports.getNamespacesMethodsForChainId=St,exports.getNodeOnlineStatus=Lt,exports.getReCapActions=st,exports.getReactNativeOnlineStatus=Mt,exports.getRecapAbilitiesFromResource=Yn,exports.getRecapFromResources=Q,exports.getRecapResource=ot,exports.getRelayClientMetadata=fn,exports.getRelayProtocolApi=vr,exports.getRelayProtocolName=yr,exports.getRequiredNamespacesFromNamespaces=Pr,exports.getSdkError=_,exports.getSearchParamFromURL=Un,exports.getUniqueValues=re,exports.handleDeeplinkRedirect=jn,exports.hasOverlap=R,exports.hashKey=sr,exports.hashMessage=ir,exports.isAndroid=un,exports.isBrowser=M,exports.isCaipNamespace=be,exports.isConformingNamespaces=Vt,exports.isExpired=Pn,exports.isIframe=Je,exports.isIos=ln,exports.isNode=se,exports.isOnline=Qr,exports.isProposalStruct=_r,exports.isReactNative=O,exports.isRecap=pe,exports.isSessionCompatible=$r,exports.isSessionStruct=Dr,exports.isTelegram=He,exports.isTestRun=Dn,exports.isTypeOneEnvelope=pr,exports.isTypeTwoEnvelope=fr,exports.isUndefined=A,exports.isValidAccountId=It,exports.isValidAccounts=jt,exports.isValidActions=Ut,exports.isValidArray=K,exports.isValidChainId=q,exports.isValidChains=Pt,exports.isValidController=Vr,exports.isValidEip1271Signature=Ge,exports.isValidEip191Signature=Ye,exports.isValidErrorReason=Fr,exports.isValidEvent=Br,exports.isValidId=Mr,exports.isValidNamespaceAccounts=$t,exports.isValidNamespaceActions=we,exports.isValidNamespaceChains=Ct,exports.isValidNamespaceMethodsOrEvents=Se,exports.isValidNamespaces=_t,exports.isValidNamespacesChainId=Hr,exports.isValidNamespacesEvent=Wr,exports.isValidNamespacesRequest=Jr,exports.isValidNumber=ee,exports.isValidObject=X,exports.isValidParams=Lr,exports.isValidRecap=N,exports.isValidRelay=Dt,exports.isValidRelays=xr,exports.isValidRequest=Kr,exports.isValidRequestExpiry=Gr,exports.isValidRequiredNamespaces=kr,exports.isValidResponse=qr,exports.isValidString=E,exports.isValidUrl=Ur,exports.mapEntries=bn,exports.mapToObj=vn,exports.mergeArrays=S,exports.mergeEncodedRecaps=Qn,exports.mergeRecaps=lt,exports.normalizeNamespaces=Ne,exports.objToMap=En,exports.openDeeplink=Be,exports.parseAccountId=ne,exports.parseChainId=te,exports.parseContextNames=Le,exports.parseExpirerTarget=An,exports.parseNamespaceKey=Ot,exports.parseRelayParams=ht,exports.parseTopic=yt,exports.parseUri=Er,exports.populateAuthPayload=Wn,exports.recapHasResource=zn,exports.serialize=Ee,exports.sleep=Vn,exports.subscribeToBrowserNetworkChange=Ft,exports.subscribeToNetworkChange=Zr,exports.subscribeToReactNativeNetworkChange=Kt,exports.toBase64=We,exports.uuidv4=_n,exports.validateDecoding=dr,exports.validateEncoding=ft,exports.validateSignedCacao=Hn,exports.verifyP256Jwt=hr,exports.verifySignature=ze; | ||
Received: ${Object.keys(t).toString()}`)),ne(i,c)||(r=ee("NON_CONFORMING_NAMESPACES",`${n} namespaces chains don't satisfy required namespaces. | ||
Required: ${i.toString()} | ||
Approved: ${c.toString()}`)),Object.keys(t).forEach(f=>{if(!f.includes(":")||r)return;const d=le(t[f].accounts);d.includes(f)||(r=ee("NON_CONFORMING_NAMESPACES",`${n} namespaces accounts don't satisfy namespace accounts for ${f} | ||
Required: ${f} | ||
Approved: ${d.toString()}`))}),i.forEach(f=>{r||(ne(o[f].methods,s[f].methods)?ne(o[f].events,s[f].events)||(r=ee("NON_CONFORMING_NAMESPACES",`${n} namespaces events don't satisfy namespace events for ${f}`)):r=ee("NON_CONFORMING_NAMESPACES",`${n} namespaces methods don't satisfy namespace methods for ${f}`))}),r}function Mi(e){const t={};return Object.keys(e).forEach(n=>{var r;n.includes(":")?t[n]=e[n]:(r=e[n].chains)==null||r.forEach(o=>{t[o]={methods:e[n].methods,events:e[n].events}})}),t}function xr(e){return[...new Set(e.map(t=>t.includes(":")?t.split(":")[0]:t))]}function Fi(e){const t={};return Object.keys(e).forEach(n=>{if(n.includes(":"))t[n]=e[n];else{const r=le(e[n].accounts);r?.forEach(o=>{t[o]={accounts:e[n].accounts.filter(s=>s.includes(`${o}:`)),methods:e[n].methods,events:e[n].events}})}}),t}function Hi(e,t){return Ge(e,!1)&&e<=t.max&&e>=t.min}function Ki(){const e=ue();return new Promise(t=>{switch(e){case H.browser:t(Ar());break;case H.reactNative:t(Sr());break;case H.node:t(Nr());break;default:t(!0)}})}function Ar(){return Ie()&&navigator?.onLine}async function Sr(){if(te()&&typeof global<"u"&&global!=null&&global.NetInfo){const e=await(global==null?void 0:global.NetInfo.fetch());return e?.isConnected}return!0}function Nr(){return!0}function qi(e){switch(ue()){case H.browser:Ir(e);break;case H.reactNative:Or(e);break;case H.node:break}}function Ir(e){!te()&&Ie()&&(window.addEventListener("online",()=>e(!0)),window.addEventListener("offline",()=>e(!1)))}function Or(e){te()&&typeof global<"u"&&global!=null&&global.NetInfo&&global?.NetInfo.addEventListener(t=>e(t?.isConnected))}const Ct={};class zi{static get(t){return Ct[t]}static set(t,n){Ct[t]=n}static delete(t){delete Ct[t]}}exports.BASE10=xt,exports.BASE16=F,exports.BASE64=At,exports.BASE64URL=Gs,exports.COLON=Vr,exports.DEFAULT_DEPTH=Xe,exports.EMPTY_SPACE=Be,exports.ENV_MAP=H,exports.INTERNAL_ERRORS=dr,exports.MemoryStore=zi,exports.ONE_THOUSAND=Dr,exports.REACT_NATIVE_PRODUCT=Vt,exports.RELAYER_DEFAULT_PROTOCOL=er,exports.SDK_ERRORS=lr,exports.SDK_TYPE=Mt,exports.SLASH=Dt,exports.TYPE_0=St,exports.TYPE_1=Ne,exports.TYPE_2=Ue,exports.UTF8=Se,exports.addResourceToRecap=In,exports.appendToQueryString=Ft,exports.assertType=Wr,exports.assignAbilityToActions=at,exports.base64Decode=Sn,exports.base64Encode=An,exports.buildApprovedNamespaces=Ai,exports.buildAuthObject=qo,exports.buildNamespacesFromAuth=Si,exports.buildRecapStatement=Rn,exports.calcExpiry=io,exports.capitalize=eo,exports.capitalizeWord=Wt,exports.createDelayedPromise=to,exports.createEncodedRecap=Jo,exports.createExpiringPromise=no,exports.createRecap=Nn,exports.decodeRecap=re,exports.decodeTypeByte=fe,exports.decodeTypeTwoEnvelope=ri,exports.decrypt=ti,exports.deriveSymKey=Xs,exports.deserialize=qe,exports.encodeRecap=De,exports.encodeTypeByte=It,exports.encodeTypeTwoEnvelope=ni,exports.encrypt=ei,exports.engineEvent=ao,exports.enumify=Zr,exports.formatAccountId=Lt,exports.formatAccountWithChain=$r,exports.formatChainId=$t,exports.formatDeeplinkUrl=Jt,exports.formatExpirerTarget=Ze,exports.formatIdTarget=oo,exports.formatMessage=wn,exports.formatMessageContext=Jr,exports.formatRelayParams=rr,exports.formatRelayRpcUrl=zr,exports.formatStatementFromRecap=ft,exports.formatTopicTarget=ro,exports.formatUA=qt,exports.formatUri=pi,exports.fromBase64=tt,exports.generateKeyPair=Js,exports.generateRandomBytes32=Ys,exports.getAccountsChains=le,exports.getAccountsFromNamespaces=Br,exports.getAddressFromAccount=Bt,exports.getAddressesFromAccounts=Lr,exports.getAppId=Hr,exports.getAppMetadata=Kr,exports.getBrowserOnlineStatus=Ar,exports.getChainFromAccount=jt,exports.getChainsFromAccounts=kt,exports.getChainsFromNamespace=Le,exports.getChainsFromNamespaces=jr,exports.getChainsFromRecap=Qo,exports.getChainsFromRequiredNamespaces=kr,exports.getCommonValuesInArrays=et,exports.getCryptoKeyFromKeyData=Zn,exports.getDecodedRecapFromResources=En,exports.getDeepLink=fo,exports.getDidAddress=ct,exports.getDidAddressSegments=Ve,exports.getDidChainId=mn,exports.getEnvironment=ue,exports.getHttpUrl=Gr,exports.getInternalError=ee,exports.getJavascriptID=Kt,exports.getJavascriptOS=Ht,exports.getLastItems=Gt,exports.getLinkModeURL=hi,exports.getMethodsFromRecap=Xo,exports.getNamespacedDidChainId=bn,exports.getNamespacesChains=ir,exports.getNamespacesEventsForChainId=ar,exports.getNamespacesFromAccounts=fr,exports.getNamespacesMethodsForChainId=cr,exports.getNodeOnlineStatus=Nr,exports.getReCapActions=xn,exports.getReactNativeOnlineStatus=Sr,exports.getRecapAbilitiesFromResource=Wo,exports.getRecapFromResources=Me,exports.getRecapResource=vn,exports.getRelayClientMetadata=qr,exports.getRelayProtocolApi=li,exports.getRelayProtocolName=fi,exports.getRequiredNamespacesFromNamespaces=xi,exports.getSdkError=de,exports.getSearchParamFromURL=lo,exports.getUniqueValues=Ye,exports.handleDeeplinkRedirect=uo,exports.hasOverlap=ne,exports.hashEthereumMessage=st,exports.hashKey=Qs,exports.hashMessage=Zs,exports.isAndroid=Mr,exports.isBrowser=Ie,exports.isCaipNamespace=Rt,exports.isConformingNamespaces=vr,exports.isExpired=co,exports.isIframe=Qt,exports.isIos=Fr,exports.isNode=Qe,exports.isOnline=Ki,exports.isProposalStruct=Oi,exports.isReactNative=te,exports.isRecap=ut,exports.isSessionCompatible=Ni,exports.isSessionStruct=Ri,exports.isTelegram=Xt,exports.isTestRun=ho,exports.isTypeOneEnvelope=si,exports.isTypeTwoEnvelope=ii,exports.isUndefined=ce,exports.isValidAccountId=pr,exports.isValidAccounts=yr,exports.isValidActions=br,exports.isValidArray=Ce,exports.isValidChainId=Pe,exports.isValidChains=hr,exports.isValidController=Ti,exports.isValidEip1271Signature=pn,exports.isValidEip191Signature=dn,exports.isValidErrorReason=$i,exports.isValidEvent=ji,exports.isValidId=Ci,exports.isValidNamespaceAccounts=mr,exports.isValidNamespaceActions=_t,exports.isValidNamespaceChains=gr,exports.isValidNamespaceMethodsOrEvents=Ut,exports.isValidNamespaces=wr,exports.isValidNamespacesChainId=ki,exports.isValidNamespacesEvent=Di,exports.isValidNamespacesRequest=Vi,exports.isValidNumber=Ge,exports.isValidObject=ze,exports.isValidParams=Pi,exports.isValidRecap=J,exports.isValidRelay=Er,exports.isValidRelays=_i,exports.isValidRequest=Li,exports.isValidRequestExpiry=Hi,exports.isValidRequiredNamespaces=Ui,exports.isValidResponse=Bi,exports.isValidString=q,exports.isValidUrl=Ii,exports.mapEntries=Qr,exports.mapToObj=Yr,exports.mergeArrays=Q,exports.mergeEncodedRecaps=Yo,exports.mergeRecaps=On,exports.normalizeNamespaces=Tt,exports.objToMap=Xr,exports.openDeeplink=Yt,exports.parseAccountId=Je,exports.parseChainId=We,exports.parseContextNames=zt,exports.parseExpirerTarget=so,exports.parseNamespaceKey=ur,exports.parseRelayParams=tr,exports.parseTopic=nr,exports.parseUri=di,exports.populateAuthPayload=zo,exports.recapHasResource=Go,exports.serialize=Ot,exports.sleep=go,exports.subscribeToBrowserNetworkChange=Ir,exports.subscribeToNetworkChange=qi,exports.subscribeToReactNativeNetworkChange=Or,exports.toBase64=Zt,exports.uuidv4=po,exports.validateDecoding=oi,exports.validateEncoding=Qn,exports.validateSignedCacao=Ko,exports.verifyP256Jwt=ui,exports.verifySignature=ln; | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -1,10 +0,11 @@ | ||
import{detect as Xn}from"detect-browser";import{toMiliseconds as X,FIVE_MINUTES as Ie,fromMiliseconds as et}from"@walletconnect/time";import{getDocument as ee,getNavigator as $e,getLocation as Te}from"@walletconnect/window-getters";import{getWindowMetadata as nt}from"@walletconnect/window-metadata";import{hashMessage as Pe}from"@ethersproject/hash";import{recoverAddress as tt}from"@ethersproject/transactions";import{ChaCha20Poly1305 as je}from"@stablelib/chacha20poly1305";import{HKDF as rt}from"@stablelib/hkdf";import{randomBytes as q}from"@stablelib/random";import{SHA256 as Ae,hash as Ce}from"@stablelib/sha256";import*as Ue from"@stablelib/x25519";import{toString as v,fromString as w,concat as ne}from"uint8arrays";import{ec as ot}from"elliptic";import{decodeJWT as st}from"@walletconnect/relay-auth";import{RELAY_JSONRPC as it}from"@walletconnect/relay-api";const B=":";function te(e){const[n,t]=e.split(B);return{namespace:n,reference:t}}function _e(e){const{namespace:n,reference:t}=e;return[n,t].join(B)}function re(e){const[n,t,r]=e.split(B);return{namespace:n,reference:t,address:r}}function ke(e){const{namespace:n,reference:t,address:r}=e;return[n,t,r].join(B)}function oe(e,n){const t=[];return e.forEach(r=>{const o=n(r);t.includes(o)||t.push(o)}),t}function De(e){const{address:n}=re(e);return n}function xe(e){const{namespace:n,reference:t}=re(e);return _e({namespace:n,reference:t})}function ct(e,n){const{namespace:t,reference:r}=te(n);return ke({namespace:t,reference:r,address:e})}function at(e){return oe(e,De)}function Ve(e){return oe(e,xe)}function ut(e,n=[]){const t=[];return Object.keys(e).forEach(r=>{if(n.length&&!n.includes(r))return;const o=e[r];t.push(...o.accounts)}),t}function lt(e,n=[]){const t=[];return Object.keys(e).forEach(r=>{if(n.length&&!n.includes(r))return;const o=e[r];t.push(...Ve(o.accounts))}),t}function dt(e,n=[]){const t=[];return Object.keys(e).forEach(r=>{if(n.length&&!n.includes(r))return;const o=e[r];t.push(...H(r,o))}),t}function H(e,n){return e.includes(":")?[e]:n.chains||[]}const Me="ReactNative",y={reactNative:"react-native",node:"node",browser:"browser",unknown:"unknown"},W=" ",ft=":",Le="/",se=2,pt=1e3,Ke="js";function ie(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function R(){return!ee()&&!!$e()&&navigator.product===Me}function mt(){return R()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="android"}function ht(){return R()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="ios"}function V(){return!ie()&&!!$e()&&!!ee()}function A(){return R()?y.reactNative:ie()?y.node:V()?y.browser:y.unknown}function yt(){var e;try{return R()&&typeof global<"u"&&typeof(global==null?void 0:global.Application)<"u"?(e=global.Application)==null?void 0:e.applicationId:void 0}catch{return}}function Fe(e,n){const t=new URLSearchParams(e);for(const r of Object.keys(n).sort())if(n.hasOwnProperty(r)){const o=n[r];o!==void 0&&t.set(r,o)}return t.toString()}function gt(){return nt()||{name:"",description:"",url:"",icons:[""]}}function vt(e,n){var t;const r=A(),o={protocol:e,version:n,env:r};return r==="browser"&&(o.host=((t=Te())==null?void 0:t.host)||"unknown"),o}function qe(){if(A()===y.reactNative&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"){const{OS:t,Version:r}=global.Platform;return[t,r].join("-")}const e=Xn();if(e===null)return"unknown";const n=e.os?e.os.replace(" ","").toLowerCase():"unknown";return e.type==="browser"?[n,e.name,e.version].join("-"):[n,e.version].join("-")}function Be(){var e;const n=A();return n===y.browser?[n,((e=Te())==null?void 0:e.host)||"unknown"].join(":"):n}function He(e,n,t){const r=qe(),o=Be();return[[e,n].join("-"),[Ke,t].join("-"),r,o].join("/")}function bt({protocol:e,version:n,relayUrl:t,sdkVersion:r,auth:o,projectId:s,useOnCloseEvent:c,bundleId:a,packageName:d}){const i=t.split("?"),l=He(e,n,r),u={auth:o,ua:l,projectId:s,useOnCloseEvent:c||void 0,packageName:d||void 0,bundleId:a||void 0},f=Fe(i[1]||"",u);return i[0]+"?"+f}function Et(e){let n=(e.match(/^[^:]+(?=:\/\/)/gi)||[])[0];const t=typeof n<"u"?e.split("://")[1]:e;return n=n==="wss"?"https":"http",[n,t].join("://")}function wt(e,n,t){if(!e[n]||typeof e[n]!==t)throw new Error(`Missing or invalid "${n}" param`)}function We(e,n=se){return Je(e.split(Le),n)}function Nt(e){return We(e).join(W)}function I(e,n){return e.filter(t=>n.includes(t)).length===e.length}function Je(e,n=se){return e.slice(Math.max(e.length-n,0))}function Ot(e){return Object.fromEntries(e.entries())}function St(e){return new Map(Object.entries(e))}function Rt(e,n){const t={};return Object.keys(e).forEach(r=>{t[r]=n(e[r])}),t}const It=e=>e;function ze(e){return e.trim().replace(/^\w/,n=>n.toUpperCase())}function $t(e){return e.split(W).map(n=>ze(n)).join(W)}function Tt(e=Ie,n){const t=X(e||Ie);let r,o,s,c;return{resolve:a=>{s&&r&&(clearTimeout(s),r(a),c=Promise.resolve(a))},reject:a=>{s&&o&&(clearTimeout(s),o(a))},done:()=>new Promise((a,d)=>{if(c)return a(c);s=setTimeout(()=>{const i=new Error(n);c=Promise.reject(i),d(i)},t),r=a,o=d})}}function Pt(e,n,t){return new Promise(async(r,o)=>{const s=setTimeout(()=>o(new Error(t)),n);try{const c=await e;r(c)}catch(c){o(c)}clearTimeout(s)})}function ce(e,n){if(typeof n=="string"&&n.startsWith(`${e}:`))return n;if(e.toLowerCase()==="topic"){if(typeof n!="string")throw new Error('Value must be "string" for expirer target type: topic');return`topic:${n}`}else if(e.toLowerCase()==="id"){if(typeof n!="number")throw new Error('Value must be "number" for expirer target type: id');return`id:${n}`}throw new Error(`Unknown expirer target type: ${e}`)}function jt(e){return ce("topic",e)}function At(e){return ce("id",e)}function Ct(e){const[n,t]=e.split(":"),r={id:void 0,topic:void 0};if(n==="topic"&&typeof t=="string")r.topic=t;else if(n==="id"&&Number.isInteger(Number(t)))r.id=Number(t);else throw new Error(`Invalid target, expected id:number or topic:string, got ${n}:${t}`);return r}function Ut(e,n){return et((n||Date.now())+X(e))}function _t(e){return Date.now()>=X(e)}function kt(e,n){return`${e}${n?`:${n}`:""}`}function O(e=[],n=[]){return[...new Set([...e,...n])]}async function Dt({id:e,topic:n,wcDeepLink:t}){var r;try{if(!t)return;const o=typeof t=="string"?JSON.parse(t):t,s=o?.href;if(typeof s!="string")return;const c=Ge(s,e,n),a=A();if(a===y.browser){if(!((r=ee())!=null&&r.hasFocus())){console.warn("Document does not have focus, skipping deeplink.");return}Ye(c)}else a===y.reactNative&&typeof(global==null?void 0:global.Linking)<"u"&&await global.Linking.openURL(c)}catch(o){console.error(o)}}function Ge(e,n,t){const r=`requestId=${n}&sessionTopic=${t}`;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}${Xe(r,!0)}`}else o=`${o}/wc?${r}`;return o}function Ye(e){let n="_self";Ze()?n="_top":(Qe()||e.startsWith("https://")||e.startsWith("http://"))&&(n="_blank"),window.open(e,n,"noreferrer noopener")}async function xt(e,n){let t="";try{if(V()&&(t=localStorage.getItem(n),t))return t;t=await e.getItem(n)}catch(r){console.error(r)}return t}function ae(e,n){return e.filter(t=>n.includes(t))}function Vt(e,n){if(!e.includes(n))return null;const t=e.split(/([&,?,=])/),r=t.indexOf(n);return t[r+2]}function Mt(){return typeof crypto<"u"&&crypto!=null&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/gu,e=>{const n=Math.random()*16|0;return(e==="x"?n:n&3|8).toString(16)})}function Lt(){return typeof process<"u"&&process.env.IS_VITEST==="true"}function Qe(){return typeof window<"u"&&(!!window.TelegramWebviewProxy||!!window.Telegram||!!window.TelegramWebviewProxyProto)}function Ze(){try{return window.self!==window.top}catch{return!1}}function Xe(e,n=!1){const t=Buffer.from(e).toString("base64");return n?t.replace(/[=]/g,""):t}function ue(e){return Buffer.from(e,"base64").toString("utf-8")}function Kt(e){return new Promise(n=>setTimeout(n,e))}const Ft="https://rpc.walletconnect.org/v1";async function en(e,n,t,r,o,s){switch(t.t){case"eip191":return nn(e,n,t.s);case"eip1271":return await tn(e,n,t.s,r,o,s);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${t.t}`)}}function nn(e,n,t){return tt(Pe(n),t).toLowerCase()===e.toLowerCase()}async function tn(e,n,t,r,o,s){const c=te(r);if(!c.namespace||!c.reference)throw new Error(`isValidEip1271Signature failed: chainId must be in CAIP-2 format, received: ${r}`);try{const a="0x1626ba7e",d="0000000000000000000000000000000000000000000000000000000000000040",i="0000000000000000000000000000000000000000000000000000000000000041",l=t.substring(2),u=Pe(n).substring(2),f=a+u+d+i+l,h=await fetch(`${s||Ft}/?chainId=${r}&projectId=${o}`,{method:"POST",body:JSON.stringify({id:qt(),jsonrpc:"2.0",method:"eth_call",params:[{to:e,data:f},"latest"]})}),{result:p}=await h.json();return p?p.slice(0,a.length).toLowerCase()===a.toLowerCase():!1}catch(a){return console.error("isValidEip1271Signature: ",a),!1}}function qt(){return Date.now()+Math.floor(Math.random()*1e3)}var Bt=Object.defineProperty,Ht=Object.defineProperties,Wt=Object.getOwnPropertyDescriptors,rn=Object.getOwnPropertySymbols,Jt=Object.prototype.hasOwnProperty,zt=Object.prototype.propertyIsEnumerable,on=(e,n,t)=>n in e?Bt(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,le=(e,n)=>{for(var t in n||(n={}))Jt.call(n,t)&&on(e,t,n[t]);if(rn)for(var t of rn(n))zt.call(n,t)&&on(e,t,n[t]);return e},sn=(e,n)=>Ht(e,Wt(n));const Gt="did:pkh:",J=e=>e?.split(":"),cn=e=>{const n=e&&J(e);if(n)return e.includes(Gt)?n[3]:n[1]},an=e=>{const n=e&&J(e);if(n)return n[2]+":"+n[3]},de=e=>{const n=e&&J(e);if(n)return n.pop()};async function Yt(e){const{cacao:n,projectId:t}=e,{s:r,p:o}=n,s=un(o,o.iss),c=de(o.iss);return await en(c,s,r,an(o.iss),t)}const un=(e,n)=>{const t=`${e.domain} wants you to sign in with your Ethereum account:`,r=de(n);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}`,c=`Version: ${e.version}`,a=`Chain ID: ${cn(n)}`,d=`Nonce: ${e.nonce}`,i=`Issued At: ${e.iat}`,l=e.exp?`Expiration Time: ${e.exp}`:void 0,u=e.nbf?`Not Before: ${e.nbf}`:void 0,f=e.requestId?`Request ID: ${e.requestId}`:void 0,h=e.resources?`Resources:${e.resources.map(m=>` | ||
- ${m}`).join("")}`:void 0,p=G(e.resources);if(p){const m=$(p);o=me(o,m)}return[t,r,"",o,"",s,c,a,d,i,l,u,f,h].filter(m=>m!=null).join(` | ||
`)};function Qt(e,n,t){return t.includes("did:pkh:")||(t=`did:pkh:${t}`),{h:{t:"caip122"},p:{iss:t,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:n}}function Zt(e){var n;const{authPayload:t,chains:r,methods:o}=e,s=t.statement||"";if(!(r!=null&&r.length))return t;const c=t.chains,a=ae(c,r);if(!(a!=null&&a.length))throw new Error("No supported chains");const d=ln(t.resources);if(!d)return t;N(d);const i=dn(d,"eip155");let l=t?.resources||[];if(i!=null&&i.length){const u=fn(i),f=ae(u,o);if(!(f!=null&&f.length))throw new Error(`Supported methods don't satisfy the requested: ${JSON.stringify(u)}, supported: ${JSON.stringify(o)}`);const h=fe("request",f,{chains:a}),p=yn(d,"eip155",h);l=((n=t?.resources)==null?void 0:n.slice(0,-1))||[],l.push(z(p))}return sn(le({},t),{statement:vn(s,G(l)),chains:a,resources:t!=null&&t.resources||l.length>0?l:void 0})}function ln(e){const n=G(e);if(n&&pe(n))return $(n)}function Xt(e,n){var t;return(t=e?.att)==null?void 0:t.hasOwnProperty(n)}function dn(e,n){var t,r;return(t=e?.att)!=null&&t[n]?Object.keys((r=e?.att)==null?void 0:r[n]):[]}function er(e){return e?.map(n=>Object.keys(n))||[]}function fn(e){return e?.map(n=>{var t;return(t=n.split("/"))==null?void 0:t[1]})||[]}function pn(e){return Buffer.from(JSON.stringify(e)).toString("base64")}function mn(e){return JSON.parse(Buffer.from(e,"base64").toString("utf-8"))}function N(e){if(!e)throw new Error("No recap provided, value is undefined");if(!e.att)throw new Error("No `att` property found");const n=Object.keys(e.att);if(!(n!=null&&n.length))throw new Error("No resources found in `att` property");n.forEach(t=>{const r=e.att[t];if(Array.isArray(r))throw new Error(`Resource must be an object: ${t}`);if(typeof r!="object")throw new Error(`Resource must be an object: ${t}`);if(!Object.keys(r).length)throw new Error(`Resource object is empty: ${t}`);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(c=>{if(typeof c!="object")throw new Error(`Ability limits (${o}) must be an array of objects, found: ${c}`)})})})}function hn(e,n,t,r={}){return t?.sort((o,s)=>o.localeCompare(s)),{att:{[e]:fe(n,t,r)}}}function yn(e,n,t){var r;return e.att[n]=le({},t),((r=Object.keys(e.att))==null?void 0:r.sort((o,s)=>o.localeCompare(s))).reduce((o,s)=>(o.att[s]=e.att[s],o),{att:{}})}function fe(e,n,t={}){n=n?.sort((o,s)=>o.localeCompare(s));const r=n.map(o=>({[`${e}/${o}`]:[t]}));return Object.assign({},...r)}function z(e){return N(e),`urn:recap:${pn(e).replace(/=/g,"")}`}function $(e){const n=mn(e.replace("urn:recap:",""));return N(n),n}function nr(e,n,t){const r=hn(e,n,t);return z(r)}function pe(e){return e&&e.includes("urn:recap:")}function tr(e,n){const t=$(e),r=$(n),o=gn(t,r);return z(o)}function gn(e,n){N(e),N(n);const t=Object.keys(e.att).concat(Object.keys(n.att)).sort((o,s)=>o.localeCompare(s)),r={att:{}};return t.forEach(o=>{var s,c;Object.keys(((s=e.att)==null?void 0:s[o])||{}).concat(Object.keys(((c=n.att)==null?void 0:c[o])||{})).sort((a,d)=>a.localeCompare(d)).forEach(a=>{var d,i;r.att[o]=sn(le({},r.att[o]),{[a]:((d=e.att[o])==null?void 0:d[a])||((i=n.att[o])==null?void 0:i[a])})})}),r}function me(e="",n){N(n);const t="I further authorize the stated URI to perform the following actions on my behalf: ";if(e.includes(t))return e;const r=[];let o=0;Object.keys(n.att).forEach(a=>{const d=Object.keys(n.att[a]).map(u=>({ability:u.split("/")[0],action:u.split("/")[1]}));d.sort((u,f)=>u.action.localeCompare(f.action));const i={};d.forEach(u=>{i[u.ability]||(i[u.ability]=[]),i[u.ability].push(u.action)});const l=Object.keys(i).map(u=>(o++,`(${o}) '${u}': '${i[u].join("', '")}' for '${a}'.`));r.push(l.join(", ").replace(".,","."))});const s=r.join(" "),c=`${t}${s}`;return`${e?e+" ":""}${c}`}function rr(e){var n;const t=$(e);N(t);const r=(n=t.att)==null?void 0:n.eip155;return r?Object.keys(r).map(o=>o.split("/")[1]):[]}function or(e){const n=$(e);N(n);const t=[];return Object.values(n.att).forEach(r=>{Object.values(r).forEach(o=>{var s;(s=o?.[0])!=null&&s.chains&&t.push(o[0].chains)})}),[...new Set(t.flat())]}function vn(e,n){if(!n)return e;const t=$(n);return N(t),me(e,t)}function G(e){if(!e)return;const n=e?.[e.length-1];return pe(n)?n:void 0}const he="base10",g="base16",ye="base64pad",sr="base64url",k="utf8",ge=0,D=1,M=2,ir=0,bn=1,L=12,ve=32;function cr(){const e=Ue.generateKeyPair();return{privateKey:v(e.secretKey,g),publicKey:v(e.publicKey,g)}}function ar(){const e=q(ve);return v(e,g)}function ur(e,n){const t=Ue.sharedKey(w(e,g),w(n,g),!0),r=new rt(Ae,t).expand(ve);return v(r,g)}function lr(e){const n=Ce(w(e,g));return v(n,g)}function dr(e){const n=Ce(w(e,k));return v(n,g)}function be(e){return w(`${e}`,he)}function C(e){return Number(v(e,he))}function fr(e){const n=be(typeof e.type<"u"?e.type:ge);if(C(n)===D&&typeof e.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");const t=typeof e.senderPublicKey<"u"?w(e.senderPublicKey,g):void 0,r=typeof e.iv<"u"?w(e.iv,g):q(L),o=new je(w(e.symKey,g)).seal(r,w(e.message,k));return Ee({type:n,sealed:o,iv:r,senderPublicKey:t,encoding:e.encoding})}function pr(e,n){const t=be(M),r=q(L),o=w(e,k);return Ee({type:t,sealed:o,iv:r,encoding:n})}function mr(e){const n=new je(w(e.symKey,g)),{sealed:t,iv:r}=Y({encoded:e.encoded,encoding:e?.encoding}),o=n.open(r,t);if(o===null)throw new Error("Failed to decrypt");return v(o,k)}function hr(e,n){const{sealed:t}=Y({encoded:e,encoding:n});return v(t,k)}function Ee(e){const{encoding:n=ye}=e;if(C(e.type)===M)return v(ne([e.type,e.sealed]),n);if(C(e.type)===D){if(typeof e.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");return v(ne([e.type,e.senderPublicKey,e.iv,e.sealed]),n)}return v(ne([e.type,e.iv,e.sealed]),n)}function Y(e){const{encoded:n,encoding:t=ye}=e,r=w(n,t),o=r.slice(ir,bn),s=bn;if(C(o)===D){const i=s+ve,l=i+L,u=r.slice(s,i),f=r.slice(i,l),h=r.slice(l);return{type:o,sealed:h,iv:f,senderPublicKey:u}}if(C(o)===M){const i=r.slice(s),l=q(L);return{type:o,sealed:i,iv:l}}const c=s+L,a=r.slice(s,c),d=r.slice(c);return{type:o,sealed:d,iv:a}}function yr(e,n){const t=Y({encoded:e,encoding:n?.encoding});return En({type:C(t.type),senderPublicKey:typeof t.senderPublicKey<"u"?v(t.senderPublicKey,g):void 0,receiverPublicKey:n?.receiverPublicKey})}function En(e){const n=e?.type||ge;if(n===D){if(typeof e?.senderPublicKey>"u")throw new Error("missing sender public key");if(typeof e?.receiverPublicKey>"u")throw new Error("missing receiver public key")}return{type:n,senderPublicKey:e?.senderPublicKey,receiverPublicKey:e?.receiverPublicKey}}function gr(e){return e.type===D&&typeof e.senderPublicKey=="string"&&typeof e.receiverPublicKey=="string"}function vr(e){return e.type===M}function wn(e){return new ot("p256").keyFromPublic({x:Buffer.from(e.x,"base64").toString("hex"),y:Buffer.from(e.y,"base64").toString("hex")},"hex")}function br(e){let n=e.replace(/-/g,"+").replace(/_/g,"/");const t=n.length%4;return t>0&&(n+="=".repeat(4-t)),n}function Er(e){return Buffer.from(br(e),"base64")}function wr(e,n){const[t,r,o]=e.split("."),s=Er(o);if(s.length!==64)throw new Error("Invalid signature length");const c=s.slice(0,32).toString("hex"),a=s.slice(32,64).toString("hex"),d=`${t}.${r}`,i=new Ae().update(Buffer.from(d)).digest(),l=wn(n),u=Buffer.from(i).toString("hex");if(!l.verify(u,{r:c,s:a}))throw new Error("Invalid signature");return st(e).payload}const Nn="irn";function Nr(e){return e?.relay||{protocol:Nn}}function Or(e){const n=it[e];if(typeof n>"u")throw new Error(`Relay Protocol not supported: ${e}`);return n}function On(e,n="-"){const t={},r="relay"+n;return Object.keys(e).forEach(o=>{if(o.startsWith(r)){const s=o.replace(r,""),c=e[o];t[s]=c}}),t}function Sr(e){if(!e.includes("wc:")){const i=ue(e);i!=null&&i.includes("wc:")&&(e=i)}e=e.includes("wc://")?e.replace("wc://",""):e,e=e.includes("wc:")?e.replace("wc:",""):e;const n=e.indexOf(":"),t=e.indexOf("?")!==-1?e.indexOf("?"):void 0,r=e.substring(0,n),o=e.substring(n+1,t).split("@"),s=typeof t<"u"?e.substring(t):"",c=new URLSearchParams(s),a={};c.forEach((i,l)=>{a[l]=i});const d=typeof a.methods=="string"?a.methods.split(","):void 0;return{protocol:r,topic:Sn(o[0]),version:parseInt(o[1],10),symKey:a.symKey,relay:On(a),methods:d,expiryTimestamp:a.expiryTimestamp?parseInt(a.expiryTimestamp,10):void 0}}function Sn(e){return e.startsWith("//")?e.substring(2):e}function Rn(e,n="-"){const t="relay",r={};return Object.keys(e).forEach(o=>{const s=t+n+o;e[o]&&(r[s]=e[o])}),r}function Rr(e){const n=new URLSearchParams,t=Rn(e.relay);Object.keys(t).sort().forEach(o=>{n.set(o,t[o])}),n.set("symKey",e.symKey),e.expiryTimestamp&&n.set("expiryTimestamp",e.expiryTimestamp.toString()),e.methods&&n.set("methods",e.methods.join(","));const r=n.toString();return`${e.protocol}:${e.topic}@${e.version}?${r}`}function Ir(e,n,t){return`${e}?wc_ev=${t}&topic=${n}`}var $r=Object.defineProperty,Tr=Object.defineProperties,Pr=Object.getOwnPropertyDescriptors,In=Object.getOwnPropertySymbols,jr=Object.prototype.hasOwnProperty,Ar=Object.prototype.propertyIsEnumerable,$n=(e,n,t)=>n in e?$r(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,Cr=(e,n)=>{for(var t in n||(n={}))jr.call(n,t)&&$n(e,t,n[t]);if(In)for(var t of In(n))Ar.call(n,t)&&$n(e,t,n[t]);return e},Ur=(e,n)=>Tr(e,Pr(n));function U(e){const n=[];return e.forEach(t=>{const[r,o]=t.split(":");n.push(`${r}:${o}`)}),n}function Tn(e){const n=[];return Object.values(e).forEach(t=>{n.push(...U(t.accounts))}),n}function Pn(e,n){const t=[];return Object.values(e).forEach(r=>{U(r.accounts).includes(n)&&t.push(...r.methods)}),t}function jn(e,n){const t=[];return Object.values(e).forEach(r=>{U(r.accounts).includes(n)&&t.push(...r.events)}),t}function _r(e,n){const t=Kn(e,n);if(t)throw new Error(t.message);const r={};for(const[o,s]of Object.entries(e))r[o]={methods:s.methods,events:s.events,chains:s.accounts.map(c=>`${c.split(":")[0]}:${c.split(":")[1]}`)};return r}function kr(e){const{proposal:{requiredNamespaces:n,optionalNamespaces:t={}},supportedNamespaces:r}=e,o=Ne(n),s=Ne(t),c={};Object.keys(r).forEach(i=>{const l=r[i].chains,u=r[i].methods,f=r[i].events,h=r[i].accounts;l.forEach(p=>{if(!h.some(m=>m.includes(p)))throw new Error(`No accounts provided for chain ${p} in namespace ${i}`)}),c[i]={chains:l,methods:u,events:f,accounts:h}});const a=qn(n,c,"approve()");if(a)throw new Error(a.message);const d={};return!Object.keys(n).length&&!Object.keys(t).length?c:(Object.keys(o).forEach(i=>{const l=r[i].chains.filter(p=>{var m,E;return(E=(m=o[i])==null?void 0:m.chains)==null?void 0:E.includes(p)}),u=r[i].methods.filter(p=>{var m,E;return(E=(m=o[i])==null?void 0:m.methods)==null?void 0:E.includes(p)}),f=r[i].events.filter(p=>{var m,E;return(E=(m=o[i])==null?void 0:m.events)==null?void 0:E.includes(p)}),h=l.map(p=>r[i].accounts.filter(m=>m.includes(`${p}:`))).flat();d[i]={chains:l,methods:u,events:f,accounts:h}}),Object.keys(s).forEach(i=>{var l,u,f,h,p,m;if(!r[i])return;const E=(u=(l=s[i])==null?void 0:l.chains)==null?void 0:u.filter(P=>r[i].chains.includes(P)),Yn=r[i].methods.filter(P=>{var j,x;return(x=(j=s[i])==null?void 0:j.methods)==null?void 0:x.includes(P)}),Qn=r[i].events.filter(P=>{var j,x;return(x=(j=s[i])==null?void 0:j.events)==null?void 0:x.includes(P)}),Zn=E?.map(P=>r[i].accounts.filter(j=>j.includes(`${P}:`))).flat();d[i]={chains:O((f=d[i])==null?void 0:f.chains,E),methods:O((h=d[i])==null?void 0:h.methods,Yn),events:O((p=d[i])==null?void 0:p.events,Qn),accounts:O((m=d[i])==null?void 0:m.accounts,Zn)}}),d)}function we(e){return e.includes(":")}function An(e){return we(e)?e.split(":")[0]:e}function Ne(e){var n,t,r;const o={};if(!Q(e))return o;for(const[s,c]of Object.entries(e)){const a=we(s)?[s]:c.chains,d=c.methods||[],i=c.events||[],l=An(s);o[l]=Ur(Cr({},o[l]),{chains:O(a,(n=o[l])==null?void 0:n.chains),methods:O(d,(t=o[l])==null?void 0:t.methods),events:O(i,(r=o[l])==null?void 0:r.events)})}return o}function Cn(e){const n={};return e?.forEach(t=>{const[r,o]=t.split(":");n[r]||(n[r]={accounts:[],chains:[],events:[]}),n[r].accounts.push(t),n[r].chains.push(`${r}:${o}`)}),n}function Dr(e,n){n=n.map(r=>r.replace("did:pkh:",""));const t=Cn(n);for(const[r,o]of Object.entries(t))o.methods?o.methods=O(o.methods,e):o.methods=e,o.events=["chainChanged","accountsChanged"];return t}const Un={INVALID_METHOD:{message:"Invalid method.",code:1001},INVALID_EVENT:{message:"Invalid event.",code:1002},INVALID_UPDATE_REQUEST:{message:"Invalid update request.",code:1003},INVALID_EXTEND_REQUEST:{message:"Invalid extend request.",code:1004},INVALID_SESSION_SETTLE_REQUEST:{message:"Invalid session settle request.",code:1005},UNAUTHORIZED_METHOD:{message:"Unauthorized method.",code:3001},UNAUTHORIZED_EVENT:{message:"Unauthorized event.",code:3002},UNAUTHORIZED_UPDATE_REQUEST:{message:"Unauthorized update request.",code:3003},UNAUTHORIZED_EXTEND_REQUEST:{message:"Unauthorized extend request.",code:3004},USER_REJECTED:{message:"User rejected.",code:5e3},USER_REJECTED_CHAINS:{message:"User rejected chains.",code:5001},USER_REJECTED_METHODS:{message:"User rejected methods.",code:5002},USER_REJECTED_EVENTS:{message:"User rejected events.",code:5003},UNSUPPORTED_CHAINS:{message:"Unsupported chains.",code:5100},UNSUPPORTED_METHODS:{message:"Unsupported methods.",code:5101},UNSUPPORTED_EVENTS:{message:"Unsupported events.",code:5102},UNSUPPORTED_ACCOUNTS:{message:"Unsupported accounts.",code:5103},UNSUPPORTED_NAMESPACE_KEY:{message:"Unsupported namespace key.",code:5104},USER_DISCONNECTED:{message:"User disconnected.",code:6e3},SESSION_SETTLEMENT_FAILED:{message:"Session settlement failed.",code:7e3},WC_METHOD_UNSUPPORTED:{message:"Unsupported wc_ method.",code:10001}},_n={NOT_INITIALIZED:{message:"Not initialized.",code:1},NO_MATCHING_KEY:{message:"No matching key.",code:2},RESTORE_WILL_OVERRIDE:{message:"Restore will override.",code:3},RESUBSCRIBED:{message:"Resubscribed.",code:4},MISSING_OR_INVALID:{message:"Missing or invalid.",code:5},EXPIRED:{message:"Expired.",code:6},UNKNOWN_TYPE:{message:"Unknown type.",code:7},MISMATCHED_TOPIC:{message:"Mismatched topic.",code:8},NON_CONFORMING_NAMESPACES:{message:"Non conforming namespaces.",code:9}};function S(e,n){const{message:t,code:r}=_n[e];return{message:n?`${t} ${n}`:t,code:r}}function _(e,n){const{message:t,code:r}=Un[e];return{message:n?`${t} ${n}`:t,code:r}}function K(e,n){return Array.isArray(e)?typeof n<"u"&&e.length?e.every(n):!0:!1}function Q(e){return Object.getPrototypeOf(e)===Object.prototype&&Object.keys(e).length}function T(e){return typeof e>"u"}function b(e,n){return n&&T(e)?!0:typeof e=="string"&&!!e.trim().length}function Z(e,n){return n&&T(e)?!0:typeof e=="number"&&!isNaN(e)}function xr(e,n){const{requiredNamespaces:t}=n,r=Object.keys(e.namespaces),o=Object.keys(t);let s=!0;return I(o,r)?(r.forEach(c=>{const{accounts:a,methods:d,events:i}=e.namespaces[c],l=U(a),u=t[c];(!I(H(c,u),l)||!I(u.methods,d)||!I(u.events,i))&&(s=!1)}),s):!1}function F(e){return b(e,!1)&&e.includes(":")?e.split(":").length===2:!1}function kn(e){if(b(e,!1)&&e.includes(":")){const n=e.split(":");if(n.length===3){const t=n[0]+":"+n[1];return!!n[2]&&F(t)}}return!1}function Vr(e){function n(t){try{return typeof new URL(t)<"u"}catch{return!1}}try{if(b(e,!1)){if(n(e))return!0;const t=ue(e);return n(t)}}catch{}return!1}function Mr(e){var n;return(n=e?.proposer)==null?void 0:n.publicKey}function Lr(e){return e?.topic}function Kr(e,n){let t=null;return b(e?.publicKey,!1)||(t=S("MISSING_OR_INVALID",`${n} controller public key should be a string`)),t}function Oe(e){let n=!0;return K(e)?e.length&&(n=e.every(t=>b(t,!1))):n=!1,n}function Dn(e,n,t){let r=null;return K(n)&&n.length?n.forEach(o=>{r||F(o)||(r=_("UNSUPPORTED_CHAINS",`${t}, chain ${o} should be a string and conform to "namespace:chainId" format`))}):F(e)||(r=_("UNSUPPORTED_CHAINS",`${t}, chains must be defined as "namespace:chainId" e.g. "eip155:1": {...} in the namespace key OR as an array of CAIP-2 chainIds e.g. eip155: { chains: ["eip155:1", "eip155:5"] }`)),r}function xn(e,n,t){let r=null;return Object.entries(e).forEach(([o,s])=>{if(r)return;const c=Dn(o,H(o,s),`${n} ${t}`);c&&(r=c)}),r}function Vn(e,n){let t=null;return K(e)?e.forEach(r=>{t||kn(r)||(t=_("UNSUPPORTED_ACCOUNTS",`${n}, account ${r} should be a string and conform to "namespace:chainId:address" format`))}):t=_("UNSUPPORTED_ACCOUNTS",`${n}, accounts should be an array of strings conforming to "namespace:chainId:address" format`),t}function Mn(e,n){let t=null;return Object.values(e).forEach(r=>{if(t)return;const o=Vn(r?.accounts,`${n} namespace`);o&&(t=o)}),t}function Ln(e,n){let t=null;return Oe(e?.methods)?Oe(e?.events)||(t=_("UNSUPPORTED_EVENTS",`${n}, events should be an array of strings or empty array for no events`)):t=_("UNSUPPORTED_METHODS",`${n}, methods should be an array of strings or empty array for no methods`),t}function Se(e,n){let t=null;return Object.values(e).forEach(r=>{if(t)return;const o=Ln(r,`${n}, namespace`);o&&(t=o)}),t}function Fr(e,n,t){let r=null;if(e&&Q(e)){const o=Se(e,n);o&&(r=o);const s=xn(e,n,t);s&&(r=s)}else r=S("MISSING_OR_INVALID",`${n}, ${t} should be an object with data`);return r}function Kn(e,n){let t=null;if(e&&Q(e)){const r=Se(e,n);r&&(t=r);const o=Mn(e,n);o&&(t=o)}else t=S("MISSING_OR_INVALID",`${n}, namespaces should be an object with data`);return t}function Fn(e){return b(e.protocol,!0)}function qr(e,n){let t=!1;return n&&!e?t=!0:e&&K(e)&&e.length&&e.forEach(r=>{t=Fn(r)}),t}function Br(e){return typeof e=="number"}function Hr(e){return typeof e<"u"&&typeof e!==null}function Wr(e){return!(!e||typeof e!="object"||!e.code||!Z(e.code,!1)||!e.message||!b(e.message,!1))}function Jr(e){return!(T(e)||!b(e.method,!1))}function zr(e){return!(T(e)||T(e.result)&&T(e.error)||!Z(e.id,!1)||!b(e.jsonrpc,!1))}function Gr(e){return!(T(e)||!b(e.name,!1))}function Yr(e,n){return!(!F(n)||!Tn(e).includes(n))}function Qr(e,n,t){return b(t,!1)?Pn(e,n).includes(t):!1}function Zr(e,n,t){return b(t,!1)?jn(e,n).includes(t):!1}function qn(e,n,t){let r=null;const o=Xr(e),s=eo(n),c=Object.keys(o),a=Object.keys(s),d=Bn(Object.keys(e)),i=Bn(Object.keys(n)),l=d.filter(u=>!i.includes(u));return l.length&&(r=S("NON_CONFORMING_NAMESPACES",`${t} namespaces keys don't satisfy requiredNamespaces. | ||
import{detect as Pr}from"detect-browser";import{toMiliseconds as We,FIVE_MINUTES as jt,fromMiliseconds as Lr}from"@walletconnect/time";import{getDocument as ze,getNavigator as Ct,getLocation as kt}from"@walletconnect/window-getters";import{getWindowMetadata as Br}from"@walletconnect/window-metadata";import{recoverAddress as jr}from"@ethersproject/transactions";import{decodeJWT as Cr}from"@walletconnect/relay-auth";import{toString as K,fromString as W,concat as Je}from"uint8arrays";import{ec as kr}from"elliptic";import{RELAY_JSONRPC as Dr}from"@walletconnect/relay-api";const Pe=":";function Ye(e){const[t,n]=e.split(Pe);return{namespace:t,reference:n}}function Dt(e){const{namespace:t,reference:n}=e;return[t,n].join(Pe)}function Xe(e){const[t,n,r]=e.split(Pe);return{namespace:t,reference:n,address:r}}function Mt(e){const{namespace:t,reference:n,address:r}=e;return[t,n,r].join(Pe)}function Ze(e,t){const n=[];return e.forEach(r=>{const o=t(r);n.includes(o)||n.push(o)}),n}function Vt(e){const{address:t}=Xe(e);return t}function Ht(e){const{namespace:t,reference:n}=Xe(e);return Dt({namespace:t,reference:n})}function Mr(e,t){const{namespace:n,reference:r}=Ye(t);return Mt({namespace:n,reference:r,address:e})}function Vr(e){return Ze(e,Vt)}function Kt(e){return Ze(e,Ht)}function Hr(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 Kr(e,t=[]){const n=[];return Object.keys(e).forEach(r=>{if(t.length&&!t.includes(r))return;const o=e[r];n.push(...Kt(o.accounts))}),n}function Fr(e,t=[]){const n=[];return Object.keys(e).forEach(r=>{if(t.length&&!t.includes(r))return;const o=e[r];n.push(...Le(r,o))}),n}function Le(e,t){return e.includes(":")?[e]:t.chains||[]}const Ft="ReactNative",H={reactNative:"react-native",node:"node",browser:"browser",unknown:"unknown"},Be=" ",qr=":",qt="/",Qe=2,Gr=1e3,Gt="js";function et(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function ne(){return!ze()&&!!Ct()&&navigator.product===Ft}function Wr(){return ne()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="android"}function zr(){return ne()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="ios"}function Ae(){return!et()&&!!Ct()&&!!ze()}function ue(){return ne()?H.reactNative:et()?H.node:Ae()?H.browser:H.unknown}function Jr(){var e;try{return ne()&&typeof global<"u"&&typeof(global==null?void 0:global.Application)<"u"?(e=global.Application)==null?void 0:e.applicationId:void 0}catch{return}}function Wt(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 Yr(){return Br()||{name:"",description:"",url:"",icons:[""]}}function Xr(e,t){var n;const r=ue(),o={protocol:e,version:t,env:r};return r==="browser"&&(o.host=((n=kt())==null?void 0:n.host)||"unknown"),o}function zt(){if(ue()===H.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=Pr();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 Jt(){var e;const t=ue();return t===H.browser?[t,((e=kt())==null?void 0:e.host)||"unknown"].join(":"):t}function Yt(e,t,n){const r=zt(),o=Jt();return[[e,t].join("-"),[Gt,n].join("-"),r,o].join("/")}function Zr({protocol:e,version:t,relayUrl:n,sdkVersion:r,auth:o,projectId:s,useOnCloseEvent:i,bundleId:c,packageName:u}){const a=n.split("?"),l=Yt(e,t,r),f={auth:o,ua:l,projectId:s,useOnCloseEvent:i||void 0,packageName:u||void 0,bundleId:c||void 0},d=Wt(a[1]||"",f);return a[0]+"?"+d}function Qr(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 eo(e,t,n){if(!e[t]||typeof e[t]!==n)throw new Error(`Missing or invalid "${t}" param`)}function Xt(e,t=Qe){return Zt(e.split(qt),t)}function to(e){return Xt(e).join(Be)}function re(e,t){return e.filter(n=>t.includes(n)).length===e.length}function Zt(e,t=Qe){return e.slice(Math.max(e.length-t,0))}function no(e){return Object.fromEntries(e.entries())}function ro(e){return new Map(Object.entries(e))}function oo(e,t){const n={};return Object.keys(e).forEach(r=>{n[r]=t(e[r])}),n}const so=e=>e;function Qt(e){return e.trim().replace(/^\w/,t=>t.toUpperCase())}function io(e){return e.split(Be).map(t=>Qt(t)).join(Be)}function co(e=jt,t){const n=We(e||jt);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,u)=>{if(i)return c(i);s=setTimeout(()=>{const a=new Error(t);i=Promise.reject(a),u(a)},n),r=c,o=u})}}function ao(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 tt(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 uo(e){return tt("topic",e)}function fo(e){return tt("id",e)}function lo(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 ho(e,t){return Lr((t||Date.now())+We(e))}function po(e){return Date.now()>=We(e)}function go(e,t){return`${e}${t?`:${t}`:""}`}function Q(e=[],t=[]){return[...new Set([...e,...t])]}async function yo({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=en(s,e,t),c=ue();if(c===H.browser){if(!((r=ze())!=null&&r.hasFocus())){console.warn("Document does not have focus, skipping deeplink.");return}tn(i)}else c===H.reactNative&&typeof(global==null?void 0:global.Linking)<"u"&&await global.Linking.openURL(i)}catch(o){console.error(o)}}function en(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}${on(r,!0)}`}else o=`${o}/wc?${r}`;return o}function tn(e){let t="_self";rn()?t="_top":(nn()||e.startsWith("https://")||e.startsWith("http://"))&&(t="_blank"),window.open(e,t,"noreferrer noopener")}async function mo(e,t){let n="";try{if(Ae()&&(n=localStorage.getItem(t),n))return n;n=await e.getItem(t)}catch(r){console.error(r)}return n}function nt(e,t){return e.filter(n=>t.includes(n))}function bo(e,t){if(!e.includes(t))return null;const n=e.split(/([&,?,=])/),r=n.indexOf(t);return n[r+2]}function wo(){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 Eo(){return typeof process<"u"&&process.env.IS_VITEST==="true"}function nn(){return typeof window<"u"&&(!!window.TelegramWebviewProxy||!!window.Telegram||!!window.TelegramWebviewProxyProto)}function rn(){try{return window.self!==window.top}catch{return!1}}function on(e,t=!1){const n=Buffer.from(e).toString("base64");return t?n.replace(/[=]/g,""):n}function rt(e){return Buffer.from(e,"base64").toString("utf-8")}function vo(e){return new Promise(t=>setTimeout(t,e))}function Ne(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function xo(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function je(e,...t){if(!xo(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 ot(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ne(e.outputLen),Ne(e.blockLen)}function me(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 sn(e,t){je(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}const Ce=BigInt(2**32-1),cn=BigInt(32);function Oo(e,t=!1){return t?{h:Number(e&Ce),l:Number(e>>cn&Ce)}:{h:Number(e>>cn&Ce)|0,l:Number(e&Ce)|0}}function Io(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let o=0;o<e.length;o++){const{h:s,l:i}=Oo(e[o],t);[n[o],r[o]]=[s,i]}return[n,r]}const Ao=(e,t,n)=>e<<n|t>>>32-n,No=(e,t,n)=>t<<n|e>>>32-n,So=(e,t,n)=>t<<n-32|e>>>64-n,Uo=(e,t,n)=>e<<n-32|t>>>64-n,be=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function _o(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function st(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function J(e,t){return e<<32-t|e>>>t}const an=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function To(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function un(e){for(let t=0;t<e.length;t++)e[t]=To(e[t])}function $o(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function we(e){return typeof e=="string"&&(e=$o(e)),je(e),e}class it{clone(){return this._cloneInto()}}function fn(e){const t=r=>e().update(we(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Se(e=32){if(be&&typeof be.getRandomValues=="function")return be.getRandomValues(new Uint8Array(e));if(be&&typeof be.randomBytes=="function")return be.randomBytes(e);throw new Error("crypto.getRandomValues must be defined")}const ln=[],dn=[],hn=[],Ro=BigInt(0),Ue=BigInt(1),Po=BigInt(2),Lo=BigInt(7),Bo=BigInt(256),jo=BigInt(113);for(let e=0,t=Ue,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],ln.push(2*(5*r+n)),dn.push((e+1)*(e+2)/2%64);let o=Ro;for(let s=0;s<7;s++)t=(t<<Ue^(t>>Lo)*jo)%Bo,t&Po&&(o^=Ue<<(Ue<<BigInt(s))-Ue);hn.push(o)}const[Co,ko]=Io(hn,!0),pn=(e,t,n)=>n>32?So(e,t,n):Ao(e,t,n),gn=(e,t,n)=>n>32?Uo(e,t,n):No(e,t,n);function Do(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,u=(i+2)%10,a=n[u],l=n[u+1],f=pn(a,l,1)^n[c],d=gn(a,l,1)^n[c+1];for(let g=0;g<50;g+=10)e[i+g]^=f,e[i+g+1]^=d}let o=e[2],s=e[3];for(let i=0;i<24;i++){const c=dn[i],u=pn(o,s,c),a=gn(o,s,c),l=ln[i];o=e[l],s=e[l+1],e[l]=u,e[l+1]=a}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]^=Co[r],e[1]^=ko[r]}n.fill(0)}class Bt extends it{constructor(t,n,r,o=!1,s=24){if(super(),this.blockLen=t,this.suffix=n,this.outputLen=r,this.enableXOF=o,this.rounds=s,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,Ne(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=_o(this.state)}keccak(){an||un(this.state32),Do(this.state32,this.rounds),an||un(this.state32),this.posOut=0,this.pos=0}update(t){me(this);const{blockLen:n,state:r}=this;t=we(t);const 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&&r===o-1&&this.keccak(),t[o-1]^=128,this.keccak()}writeInto(t){me(this,!1),je(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 Ne(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(sn(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,this.state.fill(0)}_cloneInto(t){const{blockLen:n,suffix:r,outputLen:o,rounds:s,enableXOF:i}=this;return t||(t=new Bt(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 Mo=(e,t,n)=>fn(()=>new Bt(t,e,n)),Vo=Mo(1,136,256/8),Ho="https://rpc.walletconnect.org/v1";function ct(e){const t=`Ethereum Signed Message: | ||
${e.length}`,n=new TextEncoder().encode(t+e);return"0x"+Buffer.from(Vo(n)).toString("hex")}async function yn(e,t,n,r,o,s){switch(n.t){case"eip191":return mn(e,t,n.s);case"eip1271":return await bn(e,t,n.s,r,o,s);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${n.t}`)}}function mn(e,t,n){return jr(ct(t),n).toLowerCase()===e.toLowerCase()}async function bn(e,t,n,r,o,s){const i=Ye(r);if(!i.namespace||!i.reference)throw new Error(`isValidEip1271Signature failed: chainId must be in CAIP-2 format, received: ${r}`);try{const c="0x1626ba7e",u="0000000000000000000000000000000000000000000000000000000000000040",a="0000000000000000000000000000000000000000000000000000000000000041",l=n.substring(2),f=ct(t).substring(2),d=c+f+u+a+l,g=await fetch(`${s||Ho}/?chainId=${r}&projectId=${o}`,{method:"POST",body:JSON.stringify({id:Ko(),jsonrpc:"2.0",method:"eth_call",params:[{to:e,data:d},"latest"]})}),{result:y}=await g.json();return y?y.slice(0,c.length).toLowerCase()===c.toLowerCase():!1}catch(c){return console.error("isValidEip1271Signature: ",c),!1}}function Ko(){return Date.now()+Math.floor(Math.random()*1e3)}var Fo=Object.defineProperty,qo=Object.defineProperties,Go=Object.getOwnPropertyDescriptors,wn=Object.getOwnPropertySymbols,Wo=Object.prototype.hasOwnProperty,zo=Object.prototype.propertyIsEnumerable,En=(e,t,n)=>t in e?Fo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,at=(e,t)=>{for(var n in t||(t={}))Wo.call(t,n)&&En(e,n,t[n]);if(wn)for(var n of wn(t))zo.call(t,n)&&En(e,n,t[n]);return e},vn=(e,t)=>qo(e,Go(t));const Jo="did:pkh:",ke=e=>e?.split(":"),xn=e=>{const t=e&&ke(e);if(t)return e.includes(Jo)?t[3]:t[1]},On=e=>{const t=e&&ke(e);if(t)return t[2]+":"+t[3]},ut=e=>{const t=e&&ke(e);if(t)return t.pop()};async function Yo(e){const{cacao:t,projectId:n}=e,{s:r,p:o}=t,s=In(o,o.iss),i=ut(o.iss);return await yn(i,s,r,On(o.iss),n)}const In=(e,t)=>{const n=`${e.domain} wants you to sign in with your Ethereum account:`,r=ut(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: ${xn(t)}`,u=`Nonce: ${e.nonce}`,a=`Issued At: ${e.iat}`,l=e.exp?`Expiration Time: ${e.exp}`:void 0,f=e.nbf?`Not Before: ${e.nbf}`:void 0,d=e.requestId?`Request ID: ${e.requestId}`:void 0,g=e.resources?`Resources:${e.resources.map(h=>` | ||
- ${h}`).join("")}`:void 0,y=Me(e.resources);if(y){const h=oe(y);o=dt(o,h)}return[n,r,"",o,"",s,i,c,u,a,l,f,d,g].filter(h=>h!=null).join(` | ||
`)};function Xo(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 Zo(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=nt(i,r);if(!(c!=null&&c.length))throw new Error("No supported chains");const u=An(n.resources);if(!u)return n;Y(u);const a=Nn(u,"eip155");let l=n?.resources||[];if(a!=null&&a.length){const f=Sn(a),d=nt(f,o);if(!(d!=null&&d.length))throw new Error(`Supported methods don't satisfy the requested: ${JSON.stringify(f)}, supported: ${JSON.stringify(o)}`);const g=ft("request",d,{chains:c}),y=$n(u,"eip155",g);l=((t=n?.resources)==null?void 0:t.slice(0,-1))||[],l.push(De(y))}return vn(at({},n),{statement:Pn(s,Me(l)),chains:c,resources:n!=null&&n.resources||l.length>0?l:void 0})}function An(e){const t=Me(e);if(t&<(t))return oe(t)}function Qo(e,t){var n;return(n=e?.att)==null?void 0:n.hasOwnProperty(t)}function Nn(e,t){var n,r;return(n=e?.att)!=null&&n[t]?Object.keys((r=e?.att)==null?void 0:r[t]):[]}function es(e){return e?.map(t=>Object.keys(t))||[]}function Sn(e){return e?.map(t=>{var n;return(n=t.split("/"))==null?void 0:n[1]})||[]}function Un(e){return Buffer.from(JSON.stringify(e)).toString("base64")}function _n(e){return JSON.parse(Buffer.from(e,"base64").toString("utf-8"))}function Y(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 Tn(e,t,n,r={}){return n?.sort((o,s)=>o.localeCompare(s)),{att:{[e]:ft(t,n,r)}}}function $n(e,t,n){var r;return e.att[t]=at({},n),((r=Object.keys(e.att))==null?void 0:r.sort((o,s)=>o.localeCompare(s))).reduce((o,s)=>(o.att[s]=e.att[s],o),{att:{}})}function ft(e,t,n={}){t=t?.sort((o,s)=>o.localeCompare(s));const r=t.map(o=>({[`${e}/${o}`]:[n]}));return Object.assign({},...r)}function De(e){return Y(e),`urn:recap:${Un(e).replace(/=/g,"")}`}function oe(e){const t=_n(e.replace("urn:recap:",""));return Y(t),t}function ts(e,t,n){const r=Tn(e,t,n);return De(r)}function lt(e){return e&&e.includes("urn:recap:")}function ns(e,t){const n=oe(e),r=oe(t),o=Rn(n,r);return De(o)}function Rn(e,t){Y(e),Y(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,u)=>c.localeCompare(u)).forEach(c=>{var u,a;r.att[o]=vn(at({},r.att[o]),{[c]:((u=e.att[o])==null?void 0:u[c])||((a=t.att[o])==null?void 0:a[c])})})}),r}function dt(e="",t){Y(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 u=Object.keys(t.att[c]).map(f=>({ability:f.split("/")[0],action:f.split("/")[1]}));u.sort((f,d)=>f.action.localeCompare(d.action));const a={};u.forEach(f=>{a[f.ability]||(a[f.ability]=[]),a[f.ability].push(f.action)});const l=Object.keys(a).map(f=>(o++,`(${o}) '${f}': '${a[f].join("', '")}' for '${c}'.`));r.push(l.join(", ").replace(".,","."))});const s=r.join(" "),i=`${n}${s}`;return`${e?e+" ":""}${i}`}function rs(e){var t;const n=oe(e);Y(n);const r=(t=n.att)==null?void 0:t.eip155;return r?Object.keys(r).map(o=>o.split("/")[1]):[]}function os(e){const t=oe(e);Y(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 Pn(e,t){if(!t)return e;const n=oe(t);return Y(n),dt(e,n)}function Me(e){if(!e)return;const t=e?.[e.length-1];return lt(t)?t:void 0}function ht(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Ln(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function F(e,...t){if(!Ln(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 Bn(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 ss(e,t){F(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function jn(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}const se=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)),is=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),cs=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!cs)throw new Error("Non little-endian hardware is not supported");function as(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function pt(e){if(typeof e=="string")e=as(e);else if(Ln(e))e=gt(e);else throw new Error("Uint8Array expected, got "+typeof e);return e}function us(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function fs(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 ls=(e,t)=>{function n(r,...o){if(F(r),e.nonceLength!==void 0){const l=o[0];if(!l)throw new Error("nonce / iv required");e.varSizeNonce?F(l):F(l,e.nonceLength)}const s=e.tagLength;s&&o[1]!==void 0&&F(o[1]);const i=t(r,...o),c=(l,f)=>{if(f!==void 0){if(l!==2)throw new Error("cipher output not supported");F(f)}};let u=!1;return{encrypt(l,f){if(u)throw new Error("cannot encrypt() twice with same key + nonce");return u=!0,F(l),c(i.encrypt.length,f),i.encrypt(l,f)},decrypt(l,f){if(F(l),s&&l.length<s)throw new Error("invalid ciphertext length: smaller than tagLength="+s);return c(i.decrypt.length,f),i.decrypt(l,f)}}}return Object.assign(n,e),n};function Cn(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&&!ds(t))throw new Error("invalid output, must be aligned");return t}function kn(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),u=r?4:0,a=r?0:4;e.setUint32(t+u,i,r),e.setUint32(t+a,c,r)}function ds(e){return e.byteOffset%4===0}function gt(e){return Uint8Array.from(e)}function Ee(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}const Dn=e=>Uint8Array.from(e.split("").map(t=>t.charCodeAt(0))),hs=Dn("expand 16-byte k"),ps=Dn("expand 32-byte k"),gs=se(hs),ys=se(ps);function x(e,t){return e<<t|e>>>32-t}function yt(e){return e.byteOffset%4===0}const Ve=64,ms=16,Mn=2**32-1,Vn=new Uint32Array;function bs(e,t,n,r,o,s,i,c){const u=o.length,a=new Uint8Array(Ve),l=se(a),f=yt(o)&&yt(s),d=f?se(o):Vn,g=f?se(s):Vn;for(let y=0;y<u;i++){if(e(t,n,r,l,i,c),i>=Mn)throw new Error("arx: counter overflow");const h=Math.min(Ve,u-y);if(f&&h===Ve){const m=y/4;if(y%4!==0)throw new Error("arx: invalid block position");for(let B=0,b;B<ms;B++)b=m+B,g[b]=d[b]^l[B];y+=Ve;continue}for(let m=0,B;m<h;m++)B=y+m,s[B]=o[B]^a[m];y+=h}}function ws(e,t){const{allowShortKeys:n,extendNonceFn:r,counterLength:o,counterRight:s,rounds:i}=us({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return ht(o),ht(i),jn(s),jn(n),(c,u,a,l,f=0)=>{F(c),F(u),F(a);const d=a.length;if(l===void 0&&(l=new Uint8Array(d)),F(l),ht(f),f<0||f>=Mn)throw new Error("arx: counter overflow");if(l.length<d)throw new Error(`arx: output (${l.length}) is shorter than data (${d})`);const g=[];let y=c.length,h,m;if(y===32)g.push(h=gt(c)),m=ys;else if(y===16&&n)h=new Uint8Array(32),h.set(c),h.set(c,16),m=gs,g.push(h);else throw new Error(`arx: invalid 32-byte key, got length=${y}`);yt(u)||g.push(u=gt(u));const B=se(h);if(r){if(u.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(m,B,se(u.subarray(0,16)),B),u=u.subarray(16)}const b=16-o;if(b!==u.length)throw new Error(`arx: nonce must be ${b} or 16 bytes`);if(b!==12){const I=new Uint8Array(12);I.set(u,s?0:12-u.length),u=I,g.push(u)}const _=se(u);return bs(e,m,B,_,a,l,f,i),Ee(...g),l}}const M=(e,t)=>e[t++]&255|(e[t++]&255)<<8;class Es{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=pt(t),F(t,32);const n=M(t,0),r=M(t,2),o=M(t,4),s=M(t,6),i=M(t,8),c=M(t,10),u=M(t,12),a=M(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|u<<5)&8065,this.r[8]=(u>>>8|a<<8)&8191,this.r[9]=a>>>5&127;for(let l=0;l<8;l++)this.pad[l]=M(t,16+2*l)}process(t,n,r=!1){const o=r?0:2048,{h:s,r:i}=this,c=i[0],u=i[1],a=i[2],l=i[3],f=i[4],d=i[5],g=i[6],y=i[7],h=i[8],m=i[9],B=M(t,n+0),b=M(t,n+2),_=M(t,n+4),I=M(t,n+6),k=M(t,n+8),E=M(t,n+10),L=M(t,n+12),j=M(t,n+14);let v=s[0]+(B&8191),O=s[1]+((B>>>13|b<<3)&8191),w=s[2]+((b>>>10|_<<6)&8191),R=s[3]+((_>>>7|I<<9)&8191),A=s[4]+((I>>>4|k<<12)&8191),T=s[5]+(k>>>1&8191),N=s[6]+((k>>>14|E<<2)&8191),S=s[7]+((E>>>11|L<<5)&8191),U=s[8]+((L>>>8|j<<8)&8191),$=s[9]+(j>>>5|o),p=0,C=p+v*c+O*(5*m)+w*(5*h)+R*(5*y)+A*(5*g);p=C>>>13,C&=8191,C+=T*(5*d)+N*(5*f)+S*(5*l)+U*(5*a)+$*(5*u),p+=C>>>13,C&=8191;let D=p+v*u+O*c+w*(5*m)+R*(5*h)+A*(5*y);p=D>>>13,D&=8191,D+=T*(5*g)+N*(5*d)+S*(5*f)+U*(5*l)+$*(5*a),p+=D>>>13,D&=8191;let P=p+v*a+O*u+w*c+R*(5*m)+A*(5*h);p=P>>>13,P&=8191,P+=T*(5*y)+N*(5*g)+S*(5*d)+U*(5*f)+$*(5*l),p+=P>>>13,P&=8191;let G=p+v*l+O*a+w*u+R*c+A*(5*m);p=G>>>13,G&=8191,G+=T*(5*h)+N*(5*y)+S*(5*g)+U*(5*d)+$*(5*f),p+=G>>>13,G&=8191;let X=p+v*f+O*l+w*a+R*u+A*c;p=X>>>13,X&=8191,X+=T*(5*m)+N*(5*h)+S*(5*y)+U*(5*g)+$*(5*d),p+=X>>>13,X&=8191;let Z=p+v*d+O*f+w*l+R*a+A*u;p=Z>>>13,Z&=8191,Z+=T*c+N*(5*m)+S*(5*h)+U*(5*y)+$*(5*g),p+=Z>>>13,Z&=8191;let he=p+v*g+O*d+w*f+R*l+A*a;p=he>>>13,he&=8191,he+=T*u+N*c+S*(5*m)+U*(5*h)+$*(5*y),p+=he>>>13,he&=8191;let pe=p+v*y+O*g+w*d+R*f+A*l;p=pe>>>13,pe&=8191,pe+=T*a+N*u+S*c+U*(5*m)+$*(5*h),p+=pe>>>13,pe&=8191;let ge=p+v*h+O*y+w*g+R*d+A*f;p=ge>>>13,ge&=8191,ge+=T*l+N*a+S*u+U*c+$*(5*m),p+=ge>>>13,ge&=8191;let ye=p+v*m+O*h+w*y+R*g+A*d;p=ye>>>13,ye&=8191,ye+=T*f+N*l+S*a+U*u+$*c,p+=ye>>>13,ye&=8191,p=(p<<2)+p|0,p=p+C|0,C=p&8191,p=p>>>13,D+=p,s[0]=C,s[1]=D,s[2]=P,s[3]=G,s[4]=X,s[5]=Z,s[6]=he,s[7]=pe,s[8]=ge,s[9]=ye}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;Ee(r)}update(t){Bn(this);const{buffer:n,blockLen:r}=this;t=pt(t);const 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(){Ee(this.h,this.r,this.buffer,this.pad)}digestInto(t){Bn(this),ss(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 vs(e){const t=(r,o)=>e(o).update(pt(r)).digest(),n=e(new Uint8Array(32));return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=r=>e(r),t}const xs=vs(e=>new Es(e));function Os(e,t,n,r,o,s=20){let i=e[0],c=e[1],u=e[2],a=e[3],l=t[0],f=t[1],d=t[2],g=t[3],y=t[4],h=t[5],m=t[6],B=t[7],b=o,_=n[0],I=n[1],k=n[2],E=i,L=c,j=u,v=a,O=l,w=f,R=d,A=g,T=y,N=h,S=m,U=B,$=b,p=_,C=I,D=k;for(let G=0;G<s;G+=2)E=E+O|0,$=x($^E,16),T=T+$|0,O=x(O^T,12),E=E+O|0,$=x($^E,8),T=T+$|0,O=x(O^T,7),L=L+w|0,p=x(p^L,16),N=N+p|0,w=x(w^N,12),L=L+w|0,p=x(p^L,8),N=N+p|0,w=x(w^N,7),j=j+R|0,C=x(C^j,16),S=S+C|0,R=x(R^S,12),j=j+R|0,C=x(C^j,8),S=S+C|0,R=x(R^S,7),v=v+A|0,D=x(D^v,16),U=U+D|0,A=x(A^U,12),v=v+A|0,D=x(D^v,8),U=U+D|0,A=x(A^U,7),E=E+w|0,D=x(D^E,16),S=S+D|0,w=x(w^S,12),E=E+w|0,D=x(D^E,8),S=S+D|0,w=x(w^S,7),L=L+R|0,$=x($^L,16),U=U+$|0,R=x(R^U,12),L=L+R|0,$=x($^L,8),U=U+$|0,R=x(R^U,7),j=j+A|0,p=x(p^j,16),T=T+p|0,A=x(A^T,12),j=j+A|0,p=x(p^j,8),T=T+p|0,A=x(A^T,7),v=v+O|0,C=x(C^v,16),N=N+C|0,O=x(O^N,12),v=v+O|0,C=x(C^v,8),N=N+C|0,O=x(O^N,7);let P=0;r[P++]=i+E|0,r[P++]=c+L|0,r[P++]=u+j|0,r[P++]=a+v|0,r[P++]=l+O|0,r[P++]=f+w|0,r[P++]=d+R|0,r[P++]=g+A|0,r[P++]=y+T|0,r[P++]=h+N|0,r[P++]=m+S|0,r[P++]=B+U|0,r[P++]=b+$|0,r[P++]=_+p|0,r[P++]=I+C|0,r[P++]=k+D|0}const Is=ws(Os,{counterRight:!1,counterLength:4,allowShortKeys:!1}),As=new Uint8Array(16),Hn=(e,t)=>{e.update(t);const n=t.length%16;n&&e.update(As.subarray(n))},Ns=new Uint8Array(32);function Kn(e,t,n,r,o){const s=e(t,n,Ns),i=xs.create(s);o&&Hn(i,o),Hn(i,r);const c=new Uint8Array(16),u=is(c);kn(u,0,BigInt(o?o.length:0),!0),kn(u,8,BigInt(r.length),!0),i.update(c);const a=i.digest();return Ee(s,c),a}const Ss=e=>(t,n,r)=>({encrypt(s,i){const c=s.length;i=Cn(c+16,i,!1),i.set(s);const u=i.subarray(0,-16);e(t,n,u,u,1);const a=Kn(e,t,n,u,r);return i.set(a,c),Ee(a),i},decrypt(s,i){i=Cn(s.length-16,i,!1);const c=s.subarray(0,-16),u=s.subarray(-16),a=Kn(e,t,n,c,r);if(!fs(u,a))throw new Error("invalid tag");return i.set(s.subarray(0,-16)),e(t,n,i,i,1),Ee(a),i}}),Fn=ls({blockSize:64,nonceLength:12,tagLength:16},Ss(Is));class qn extends it{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,ot(t);const r=we(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const o=this.blockLen,s=new Uint8Array(o);s.set(r.length>o?t.create().update(r).digest():r);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(t){return me(this),this.iHash.update(t),this}digestInto(t){me(this),je(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=n._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const mt=(e,t,n)=>new qn(e,t).update(n).digest();mt.create=(e,t)=>new qn(e,t);function Us(e,t,n){return ot(e),n===void 0&&(n=new Uint8Array(e.outputLen)),mt(e,we(n),we(t))}const bt=new Uint8Array([0]),Gn=new Uint8Array;function _s(e,t,n,r=32){if(ot(e),Ne(r),r>255*e.outputLen)throw new Error("Length should be <= 255*HashLen");const o=Math.ceil(r/e.outputLen);n===void 0&&(n=Gn);const s=new Uint8Array(o*e.outputLen),i=mt.create(e,t),c=i._cloneInto(),u=new Uint8Array(i.outputLen);for(let a=0;a<o;a++)bt[0]=a+1,c.update(a===0?Gn:u).update(n).update(bt).digestInto(u),s.set(u,e.outputLen*a),i._cloneInto(c);return i.destroy(),c.destroy(),u.fill(0),bt.fill(0),s.slice(0,r)}const Ts=(e,t,n,r,o)=>_s(e,Us(e,t,n),r,o);function $s(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),u=r?4:0,a=r?0:4;e.setUint32(t+u,i,r),e.setUint32(t+a,c,r)}function Rs(e,t,n){return e&t^~e&n}function Ps(e,t,n){return e&t^e&n^t&n}class Ls extends it{constructor(t,n,r,o){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=st(this.buffer)}update(t){me(this);const{view:n,buffer:r,blockLen:o}=this;t=we(t);const s=t.length;for(let i=0;i<s;){const c=Math.min(o-this.pos,s-i);if(c===o){const u=st(t);for(;o<=s-i;i+=o)this.process(u,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){me(this),sn(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:o,isLE:s}=this;let{pos:i}=this;n[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(r,0),i=0);for(let f=i;f<o;f++)n[f]=0;$s(r,o-8,BigInt(this.length*8),s),this.process(r,0);const c=st(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const a=u/4,l=this.get();if(a>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<a;f++)c.setUint32(4*f,l[f],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.length=o,t.pos=c,t.finished=s,t.destroyed=i,o%n&&t.buffer.set(r),t}}const Bs=new Uint32Array([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]),ie=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ce=new Uint32Array(64);class js extends Ls{constructor(){super(64,32,8,!1),this.A=ie[0]|0,this.B=ie[1]|0,this.C=ie[2]|0,this.D=ie[3]|0,this.E=ie[4]|0,this.F=ie[5]|0,this.G=ie[6]|0,this.H=ie[7]|0}get(){const{A:t,B:n,C:r,D:o,E:s,F:i,G:c,H:u}=this;return[t,n,r,o,s,i,c,u]}set(t,n,r,o,s,i,c,u){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=u|0}process(t,n){for(let f=0;f<16;f++,n+=4)ce[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){const d=ce[f-15],g=ce[f-2],y=J(d,7)^J(d,18)^d>>>3,h=J(g,17)^J(g,19)^g>>>10;ce[f]=h+ce[f-7]+y+ce[f-16]|0}let{A:r,B:o,C:s,D:i,E:c,F:u,G:a,H:l}=this;for(let f=0;f<64;f++){const d=J(c,6)^J(c,11)^J(c,25),g=l+d+Rs(c,u,a)+Bs[f]+ce[f]|0,h=(J(r,2)^J(r,13)^J(r,22))+Ps(r,o,s)|0;l=a,a=u,u=c,c=i+g|0,i=s,s=o,o=r,r=g+h|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,u=u+this.F|0,a=a+this.G|0,l=l+this.H|0,this.set(r,o,s,i,c,u,a,l)}roundClean(){ce.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const He=fn(()=>new js);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Wn=BigInt(0);function wt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function zn(e){if(!wt(e))throw new Error("Uint8Array expected")}const Cs=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ks(e){zn(e);let t="";for(let n=0;n<e.length;n++)t+=Cs[e[n]];return t}function Ds(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Wn:BigInt("0x"+e)}const ee={_0:48,_9:57,A:65,F:70,a:97,f:102};function Jn(e){if(e>=ee._0&&e<=ee._9)return e-ee._0;if(e>=ee.A&&e<=ee.F)return e-(ee.A-10);if(e>=ee.a&&e<=ee.f)return e-(ee.a-10)}function Yn(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof 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=Jn(e.charCodeAt(s)),c=Jn(e.charCodeAt(s+1));if(i===void 0||c===void 0){const u=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+u+'" at index '+s)}r[o]=i*16+c}return r}function Xn(e){return zn(e),Ds(ks(Uint8Array.from(e).reverse()))}function Ms(e,t){return Yn(e.toString(16).padStart(t*2,"0"))}function Vs(e,t){return Ms(e,t).reverse()}function Zn(e,t,n){let r;if(typeof t=="string")try{r=Yn(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(wt(t))r=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");const o=r.length;if(typeof n=="number"&&o!==n)throw new Error(e+" of length "+n+" expected, got "+o);return r}const Et=e=>typeof e=="bigint"&&Wn<=e;function Hs(e,t,n){return Et(e)&&Et(t)&&Et(n)&&t<=e&&e<n}function Qn(e,t,n,r){if(!Hs(t,n,r))throw new Error("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}const Ks={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||wt(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function Fs(e,t,n={}){const r=(o,s,i)=>{const c=Ks[s];if(typeof c!="function")throw new Error("invalid validator function");const u=e[o];if(!(i&&u===void 0)&&!c(u,e))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+u)};for(const[o,s]of Object.entries(t))r(o,s,!1);for(const[o,s]of Object.entries(n))r(o,s,!0);return e}const ve=BigInt(0),Ke=BigInt(1);function er(e,t){const n=e%t;return n>=ve?n:t+n}function qs(e,t,n){if(t<ve)throw new Error("invalid exponent, negatives unsupported");if(n<=ve)throw new Error("invalid modulus");if(n===Ke)return ve;let r=Ke;for(;t>ve;)t&Ke&&(r=r*e%n),e=e*e%n,t>>=Ke;return r}function z(e,t,n){let r=e;for(;t-- >ve;)r*=r,r%=n;return r}BigInt(0),BigInt(1),BigInt(0),BigInt(1),BigInt(2),BigInt(8);const xe=BigInt(0),vt=BigInt(1);function Gs(e){return Fs(e,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...e})}function Ws(e){const t=Gs(e),{P:n}=t,r=b=>er(b,n),o=t.montgomeryBits,s=Math.ceil(o/8),i=t.nByteLength,c=t.adjustScalarBytes||(b=>b),u=t.powPminus2||(b=>qs(b,n-BigInt(2),n));function a(b,_,I){const k=r(b*(_-I));return _=r(_-k),I=r(I+k),[_,I]}const l=(t.a-BigInt(2))/BigInt(4);function f(b,_){Qn("u",b,xe,n),Qn("scalar",_,xe,n);const I=_,k=b;let E=vt,L=xe,j=b,v=vt,O=xe,w;for(let A=BigInt(o-1);A>=xe;A--){const T=I>>A&vt;O^=T,w=a(O,E,j),E=w[0],j=w[1],w=a(O,L,v),L=w[0],v=w[1],O=T;const N=E+L,S=r(N*N),U=E-L,$=r(U*U),p=S-$,C=j+v,D=j-v,P=r(D*N),G=r(C*U),X=P+G,Z=P-G;j=r(X*X),v=r(k*r(Z*Z)),E=r(S*$),L=r(p*(S+r(l*p)))}w=a(O,E,j),E=w[0],j=w[1],w=a(O,L,v),L=w[0],v=w[1];const R=u(L);return r(E*R)}function d(b){return Vs(r(b),s)}function g(b){const _=Zn("u coordinate",b,s);return i===32&&(_[31]&=127),Xn(_)}function y(b){const _=Zn("scalar",b),I=_.length;if(I!==s&&I!==i){let k=""+s+" or "+i;throw new Error("invalid scalar, expected "+k+" bytes, got "+I)}return Xn(c(_))}function h(b,_){const I=g(_),k=y(b),E=f(I,k);if(E===xe)throw new Error("invalid private or public key received");return d(E)}const m=d(t.Gu);function B(b){return h(b,m)}return{scalarMult:h,scalarMultBase:B,getSharedSecret:(b,_)=>h(b,_),getPublicKey:b=>B(b),utils:{randomPrivateKey:()=>t.randomBytes(t.nByteLength)},GuBytes:m}}const xt=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949");BigInt(0);const zs=BigInt(1),tr=BigInt(2),Js=BigInt(3),Ys=BigInt(5);BigInt(8);function Xs(e){const t=BigInt(10),n=BigInt(20),r=BigInt(40),o=BigInt(80),s=xt,c=e*e%s*e%s,u=z(c,tr,s)*c%s,a=z(u,zs,s)*e%s,l=z(a,Ys,s)*a%s,f=z(l,t,s)*l%s,d=z(f,n,s)*f%s,g=z(d,r,s)*d%s,y=z(g,o,s)*g%s,h=z(y,o,s)*g%s,m=z(h,t,s)*l%s;return{pow_p_5_8:z(m,tr,s)*e%s,b2:c}}function Zs(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}const Ot=(()=>Ws({P:xt,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:e=>{const t=xt,{pow_p_5_8:n,b2:r}=Xs(e);return er(z(n,Js,t)*r,t)},adjustScalarBytes:Zs,randomBytes:Se}))(),It="base10",V="base16",At="base64pad",Qs="base64url",Oe="utf8",Nt=0,Ie=1,_e=2,ei=0,nr=1,Te=12,St=32;function ti(){const e=Ot.utils.randomPrivateKey(),t=Ot.getPublicKey(e);return{privateKey:K(e,V),publicKey:K(t,V)}}function ni(){const e=Se(St);return K(e,V)}function ri(e,t){const n=Ot.getSharedSecret(W(e,V),W(t,V)),r=Ts(He,n,void 0,void 0,St);return K(r,V)}function oi(e){const t=He(W(e,V));return K(t,V)}function si(e){const t=He(W(e,Oe));return K(t,V)}function Ut(e){return W(`${e}`,It)}function fe(e){return Number(K(e,It))}function ii(e){const t=Ut(typeof e.type<"u"?e.type:Nt);if(fe(t)===Ie&&typeof e.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");const n=typeof e.senderPublicKey<"u"?W(e.senderPublicKey,V):void 0,r=typeof e.iv<"u"?W(e.iv,V):Se(Te),o=W(e.symKey,V),s=Fn(o,r).encrypt(W(e.message,Oe));return _t({type:t,sealed:s,iv:r,senderPublicKey:n,encoding:e.encoding})}function ci(e){const t=W(e.symKey,V),{sealed:n,iv:r}=Fe(e),o=Fn(t,r).decrypt(n);if(o===null)throw new Error("Failed to decrypt");return K(o,Oe)}function ai(e,t){const n=Ut(_e),r=Se(Te),o=W(e,Oe);return _t({type:n,sealed:o,iv:r,encoding:t})}function ui(e,t){const{sealed:n}=Fe({encoded:e,encoding:t});return K(n,Oe)}function _t(e){const{encoding:t=At}=e;if(fe(e.type)===_e)return K(Je([e.type,e.sealed]),t);if(fe(e.type)===Ie){if(typeof e.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");return K(Je([e.type,e.senderPublicKey,e.iv,e.sealed]),t)}return K(Je([e.type,e.iv,e.sealed]),t)}function Fe(e){const{encoded:t,encoding:n=At}=e,r=W(t,n),o=r.slice(ei,nr),s=nr;if(fe(o)===Ie){const a=s+St,l=a+Te,f=r.slice(s,a),d=r.slice(a,l),g=r.slice(l);return{type:o,sealed:g,iv:d,senderPublicKey:f}}if(fe(o)===_e){const a=r.slice(s),l=Se(Te);return{type:o,sealed:a,iv:l}}const i=s+Te,c=r.slice(s,i),u=r.slice(i);return{type:o,sealed:u,iv:c}}function fi(e,t){const n=Fe({encoded:e,encoding:t?.encoding});return rr({type:fe(n.type),senderPublicKey:typeof n.senderPublicKey<"u"?K(n.senderPublicKey,V):void 0,receiverPublicKey:t?.receiverPublicKey})}function rr(e){const t=e?.type||Nt;if(t===Ie){if(typeof e?.senderPublicKey>"u")throw new Error("missing sender public key");if(typeof e?.receiverPublicKey>"u")throw new Error("missing receiver public key")}return{type:t,senderPublicKey:e?.senderPublicKey,receiverPublicKey:e?.receiverPublicKey}}function li(e){return e.type===Ie&&typeof e.senderPublicKey=="string"&&typeof e.receiverPublicKey=="string"}function di(e){return e.type===_e}function or(e){return new kr("p256").keyFromPublic({x:Buffer.from(e.x,"base64").toString("hex"),y:Buffer.from(e.y,"base64").toString("hex")},"hex")}function hi(e){let t=e.replace(/-/g,"+").replace(/_/g,"/");const n=t.length%4;return n>0&&(t+="=".repeat(4-n)),t}function pi(e){return Buffer.from(hi(e),"base64")}function gi(e,t){const[n,r,o]=e.split("."),s=pi(o);if(s.length!==64)throw new Error("Invalid signature length");const i=s.slice(0,32).toString("hex"),c=s.slice(32,64).toString("hex"),u=`${n}.${r}`,a=He(u),l=or(t),f=K(a,V);if(!l.verify(f,{r:i,s:c}))throw new Error("Invalid signature");return Cr(e).payload}const sr="irn";function yi(e){return e?.relay||{protocol:sr}}function mi(e){const t=Dr[e];if(typeof t>"u")throw new Error(`Relay Protocol not supported: ${e}`);return t}function ir(e,t="-"){const n={},r="relay"+t;return Object.keys(e).forEach(o=>{if(o.startsWith(r)){const s=o.replace(r,""),i=e[o];n[s]=i}}),n}function bi(e){if(!e.includes("wc:")){const a=rt(e);a!=null&&a.includes("wc:")&&(e=a)}e=e.includes("wc://")?e.replace("wc://",""):e,e=e.includes("wc:")?e.replace("wc:",""):e;const t=e.indexOf(":"),n=e.indexOf("?")!==-1?e.indexOf("?"):void 0,r=e.substring(0,t),o=e.substring(t+1,n).split("@"),s=typeof n<"u"?e.substring(n):"",i=new URLSearchParams(s),c={};i.forEach((a,l)=>{c[l]=a});const u=typeof c.methods=="string"?c.methods.split(","):void 0;return{protocol:r,topic:cr(o[0]),version:parseInt(o[1],10),symKey:c.symKey,relay:ir(c),methods:u,expiryTimestamp:c.expiryTimestamp?parseInt(c.expiryTimestamp,10):void 0}}function cr(e){return e.startsWith("//")?e.substring(2):e}function ar(e,t="-"){const n="relay",r={};return Object.keys(e).forEach(o=>{const s=n+t+o;e[o]&&(r[s]=e[o])}),r}function wi(e){const t=new URLSearchParams,n=ar(e.relay);Object.keys(n).sort().forEach(o=>{t.set(o,n[o])}),t.set("symKey",e.symKey),e.expiryTimestamp&&t.set("expiryTimestamp",e.expiryTimestamp.toString()),e.methods&&t.set("methods",e.methods.join(","));const r=t.toString();return`${e.protocol}:${e.topic}@${e.version}?${r}`}function Ei(e,t,n){return`${e}?wc_ev=${n}&topic=${t}`}var vi=Object.defineProperty,xi=Object.defineProperties,Oi=Object.getOwnPropertyDescriptors,ur=Object.getOwnPropertySymbols,Ii=Object.prototype.hasOwnProperty,Ai=Object.prototype.propertyIsEnumerable,fr=(e,t,n)=>t in e?vi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ni=(e,t)=>{for(var n in t||(t={}))Ii.call(t,n)&&fr(e,n,t[n]);if(ur)for(var n of ur(t))Ai.call(t,n)&&fr(e,n,t[n]);return e},Si=(e,t)=>xi(e,Oi(t));function le(e){const t=[];return e.forEach(n=>{const[r,o]=n.split(":");t.push(`${r}:${o}`)}),t}function lr(e){const t=[];return Object.values(e).forEach(n=>{t.push(...le(n.accounts))}),t}function dr(e,t){const n=[];return Object.values(e).forEach(r=>{le(r.accounts).includes(t)&&n.push(...r.methods)}),n}function hr(e,t){const n=[];return Object.values(e).forEach(r=>{le(r.accounts).includes(t)&&n.push(...r.events)}),n}function Ui(e,t){const n=Ir(e,t);if(n)throw new Error(n.message);const r={};for(const[o,s]of Object.entries(e))r[o]={methods:s.methods,events:s.events,chains:s.accounts.map(i=>`${i.split(":")[0]}:${i.split(":")[1]}`)};return r}function _i(e){const{proposal:{requiredNamespaces:t,optionalNamespaces:n={}},supportedNamespaces:r}=e,o=$t(t),s=$t(n),i={};Object.keys(r).forEach(a=>{const l=r[a].chains,f=r[a].methods,d=r[a].events,g=r[a].accounts;l.forEach(y=>{if(!g.some(h=>h.includes(y)))throw new Error(`No accounts provided for chain ${y} in namespace ${a}`)}),i[a]={chains:l,methods:f,events:d,accounts:g}});const c=Nr(t,i,"approve()");if(c)throw new Error(c.message);const u={};return!Object.keys(t).length&&!Object.keys(n).length?i:(Object.keys(o).forEach(a=>{const l=r[a].chains.filter(y=>{var h,m;return(m=(h=o[a])==null?void 0:h.chains)==null?void 0:m.includes(y)}),f=r[a].methods.filter(y=>{var h,m;return(m=(h=o[a])==null?void 0:h.methods)==null?void 0:m.includes(y)}),d=r[a].events.filter(y=>{var h,m;return(m=(h=o[a])==null?void 0:h.events)==null?void 0:m.includes(y)}),g=l.map(y=>r[a].accounts.filter(h=>h.includes(`${y}:`))).flat();u[a]={chains:l,methods:f,events:d,accounts:g}}),Object.keys(s).forEach(a=>{var l,f,d,g,y,h;if(!r[a])return;const m=(f=(l=s[a])==null?void 0:l.chains)==null?void 0:f.filter(I=>r[a].chains.includes(I)),B=r[a].methods.filter(I=>{var k,E;return(E=(k=s[a])==null?void 0:k.methods)==null?void 0:E.includes(I)}),b=r[a].events.filter(I=>{var k,E;return(E=(k=s[a])==null?void 0:k.events)==null?void 0:E.includes(I)}),_=m?.map(I=>r[a].accounts.filter(k=>k.includes(`${I}:`))).flat();u[a]={chains:Q((d=u[a])==null?void 0:d.chains,m),methods:Q((g=u[a])==null?void 0:g.methods,B),events:Q((y=u[a])==null?void 0:y.events,b),accounts:Q((h=u[a])==null?void 0:h.accounts,_)}}),u)}function Tt(e){return e.includes(":")}function pr(e){return Tt(e)?e.split(":")[0]:e}function $t(e){var t,n,r;const o={};if(!qe(e))return o;for(const[s,i]of Object.entries(e)){const c=Tt(s)?[s]:i.chains,u=i.methods||[],a=i.events||[],l=pr(s);o[l]=Si(Ni({},o[l]),{chains:Q(c,(t=o[l])==null?void 0:t.chains),methods:Q(u,(n=o[l])==null?void 0:n.methods),events:Q(a,(r=o[l])==null?void 0:r.events)})}return o}function gr(e){const t={};return e?.forEach(n=>{const[r,o]=n.split(":");t[r]||(t[r]={accounts:[],chains:[],events:[]}),t[r].accounts.push(n),t[r].chains.push(`${r}:${o}`)}),t}function Ti(e,t){t=t.map(r=>r.replace("did:pkh:",""));const n=gr(t);for(const[r,o]of Object.entries(n))o.methods?o.methods=Q(o.methods,e):o.methods=e,o.events=["chainChanged","accountsChanged"];return n}const yr={INVALID_METHOD:{message:"Invalid method.",code:1001},INVALID_EVENT:{message:"Invalid event.",code:1002},INVALID_UPDATE_REQUEST:{message:"Invalid update request.",code:1003},INVALID_EXTEND_REQUEST:{message:"Invalid extend request.",code:1004},INVALID_SESSION_SETTLE_REQUEST:{message:"Invalid session settle request.",code:1005},UNAUTHORIZED_METHOD:{message:"Unauthorized method.",code:3001},UNAUTHORIZED_EVENT:{message:"Unauthorized event.",code:3002},UNAUTHORIZED_UPDATE_REQUEST:{message:"Unauthorized update request.",code:3003},UNAUTHORIZED_EXTEND_REQUEST:{message:"Unauthorized extend request.",code:3004},USER_REJECTED:{message:"User rejected.",code:5e3},USER_REJECTED_CHAINS:{message:"User rejected chains.",code:5001},USER_REJECTED_METHODS:{message:"User rejected methods.",code:5002},USER_REJECTED_EVENTS:{message:"User rejected events.",code:5003},UNSUPPORTED_CHAINS:{message:"Unsupported chains.",code:5100},UNSUPPORTED_METHODS:{message:"Unsupported methods.",code:5101},UNSUPPORTED_EVENTS:{message:"Unsupported events.",code:5102},UNSUPPORTED_ACCOUNTS:{message:"Unsupported accounts.",code:5103},UNSUPPORTED_NAMESPACE_KEY:{message:"Unsupported namespace key.",code:5104},USER_DISCONNECTED:{message:"User disconnected.",code:6e3},SESSION_SETTLEMENT_FAILED:{message:"Session settlement failed.",code:7e3},WC_METHOD_UNSUPPORTED:{message:"Unsupported wc_ method.",code:10001}},mr={NOT_INITIALIZED:{message:"Not initialized.",code:1},NO_MATCHING_KEY:{message:"No matching key.",code:2},RESTORE_WILL_OVERRIDE:{message:"Restore will override.",code:3},RESUBSCRIBED:{message:"Resubscribed.",code:4},MISSING_OR_INVALID:{message:"Missing or invalid.",code:5},EXPIRED:{message:"Expired.",code:6},UNKNOWN_TYPE:{message:"Unknown type.",code:7},MISMATCHED_TOPIC:{message:"Mismatched topic.",code:8},NON_CONFORMING_NAMESPACES:{message:"Non conforming namespaces.",code:9}};function te(e,t){const{message:n,code:r}=mr[e];return{message:t?`${n} ${t}`:n,code:r}}function de(e,t){const{message:n,code:r}=yr[e];return{message:t?`${n} ${t}`:n,code:r}}function $e(e,t){return Array.isArray(e)?typeof t<"u"&&e.length?e.every(t):!0:!1}function qe(e){return Object.getPrototypeOf(e)===Object.prototype&&Object.keys(e).length}function ae(e){return typeof e>"u"}function q(e,t){return t&&ae(e)?!0:typeof e=="string"&&!!e.trim().length}function Ge(e,t){return t&&ae(e)?!0:typeof e=="number"&&!isNaN(e)}function $i(e,t){const{requiredNamespaces:n}=t,r=Object.keys(e.namespaces),o=Object.keys(n);let s=!0;return re(o,r)?(r.forEach(i=>{const{accounts:c,methods:u,events:a}=e.namespaces[i],l=le(c),f=n[i];(!re(Le(i,f),l)||!re(f.methods,u)||!re(f.events,a))&&(s=!1)}),s):!1}function Re(e){return q(e,!1)&&e.includes(":")?e.split(":").length===2:!1}function br(e){if(q(e,!1)&&e.includes(":")){const t=e.split(":");if(t.length===3){const n=t[0]+":"+t[1];return!!t[2]&&Re(n)}}return!1}function Ri(e){function t(n){try{return typeof new URL(n)<"u"}catch{return!1}}try{if(q(e,!1)){if(t(e))return!0;const n=rt(e);return t(n)}}catch{}return!1}function Pi(e){var t;return(t=e?.proposer)==null?void 0:t.publicKey}function Li(e){return e?.topic}function Bi(e,t){let n=null;return q(e?.publicKey,!1)||(n=te("MISSING_OR_INVALID",`${t} controller public key should be a string`)),n}function Rt(e){let t=!0;return $e(e)?e.length&&(t=e.every(n=>q(n,!1))):t=!1,t}function wr(e,t,n){let r=null;return $e(t)&&t.length?t.forEach(o=>{r||Re(o)||(r=de("UNSUPPORTED_CHAINS",`${n}, chain ${o} should be a string and conform to "namespace:chainId" format`))}):Re(e)||(r=de("UNSUPPORTED_CHAINS",`${n}, chains must be defined as "namespace:chainId" e.g. "eip155:1": {...} in the namespace key OR as an array of CAIP-2 chainIds e.g. eip155: { chains: ["eip155:1", "eip155:5"] }`)),r}function Er(e,t,n){let r=null;return Object.entries(e).forEach(([o,s])=>{if(r)return;const i=wr(o,Le(o,s),`${t} ${n}`);i&&(r=i)}),r}function vr(e,t){let n=null;return $e(e)?e.forEach(r=>{n||br(r)||(n=de("UNSUPPORTED_ACCOUNTS",`${t}, account ${r} should be a string and conform to "namespace:chainId:address" format`))}):n=de("UNSUPPORTED_ACCOUNTS",`${t}, accounts should be an array of strings conforming to "namespace:chainId:address" format`),n}function xr(e,t){let n=null;return Object.values(e).forEach(r=>{if(n)return;const o=vr(r?.accounts,`${t} namespace`);o&&(n=o)}),n}function Or(e,t){let n=null;return Rt(e?.methods)?Rt(e?.events)||(n=de("UNSUPPORTED_EVENTS",`${t}, events should be an array of strings or empty array for no events`)):n=de("UNSUPPORTED_METHODS",`${t}, methods should be an array of strings or empty array for no methods`),n}function Pt(e,t){let n=null;return Object.values(e).forEach(r=>{if(n)return;const o=Or(r,`${t}, namespace`);o&&(n=o)}),n}function ji(e,t,n){let r=null;if(e&&qe(e)){const o=Pt(e,t);o&&(r=o);const s=Er(e,t,n);s&&(r=s)}else r=te("MISSING_OR_INVALID",`${t}, ${n} should be an object with data`);return r}function Ir(e,t){let n=null;if(e&&qe(e)){const r=Pt(e,t);r&&(n=r);const o=xr(e,t);o&&(n=o)}else n=te("MISSING_OR_INVALID",`${t}, namespaces should be an object with data`);return n}function Ar(e){return q(e.protocol,!0)}function Ci(e,t){let n=!1;return t&&!e?n=!0:e&&$e(e)&&e.length&&e.forEach(r=>{n=Ar(r)}),n}function ki(e){return typeof e=="number"}function Di(e){return typeof e<"u"&&typeof e!==null}function Mi(e){return!(!e||typeof e!="object"||!e.code||!Ge(e.code,!1)||!e.message||!q(e.message,!1))}function Vi(e){return!(ae(e)||!q(e.method,!1))}function Hi(e){return!(ae(e)||ae(e.result)&&ae(e.error)||!Ge(e.id,!1)||!q(e.jsonrpc,!1))}function Ki(e){return!(ae(e)||!q(e.name,!1))}function Fi(e,t){return!(!Re(t)||!lr(e).includes(t))}function qi(e,t,n){return q(n,!1)?dr(e,t).includes(n):!1}function Gi(e,t,n){return q(n,!1)?hr(e,t).includes(n):!1}function Nr(e,t,n){let r=null;const o=Wi(e),s=zi(t),i=Object.keys(o),c=Object.keys(s),u=Sr(Object.keys(e)),a=Sr(Object.keys(t)),l=u.filter(f=>!a.includes(f));return l.length&&(r=te("NON_CONFORMING_NAMESPACES",`${n} namespaces keys don't satisfy requiredNamespaces. | ||
Required: ${l.toString()} | ||
Received: ${Object.keys(n).toString()}`)),I(c,a)||(r=S("NON_CONFORMING_NAMESPACES",`${t} namespaces chains don't satisfy required namespaces. | ||
Required: ${c.toString()} | ||
Approved: ${a.toString()}`)),Object.keys(n).forEach(u=>{if(!u.includes(":")||r)return;const f=U(n[u].accounts);f.includes(u)||(r=S("NON_CONFORMING_NAMESPACES",`${t} namespaces accounts don't satisfy namespace accounts for ${u} | ||
Required: ${u} | ||
Approved: ${f.toString()}`))}),c.forEach(u=>{r||(I(o[u].methods,s[u].methods)?I(o[u].events,s[u].events)||(r=S("NON_CONFORMING_NAMESPACES",`${t} namespaces events don't satisfy namespace events for ${u}`)):r=S("NON_CONFORMING_NAMESPACES",`${t} namespaces methods don't satisfy namespace methods for ${u}`))}),r}function Xr(e){const n={};return Object.keys(e).forEach(t=>{var r;t.includes(":")?n[t]=e[t]:(r=e[t].chains)==null||r.forEach(o=>{n[o]={methods:e[t].methods,events:e[t].events}})}),n}function Bn(e){return[...new Set(e.map(n=>n.includes(":")?n.split(":")[0]:n))]}function eo(e){const n={};return Object.keys(e).forEach(t=>{if(t.includes(":"))n[t]=e[t];else{const r=U(e[t].accounts);r?.forEach(o=>{n[o]={accounts:e[t].accounts.filter(s=>s.includes(`${o}:`)),methods:e[t].methods,events:e[t].events}})}}),n}function no(e,n){return Z(e,!1)&&e<=n.max&&e>=n.min}function to(){const e=A();return new Promise(n=>{switch(e){case y.browser:n(Hn());break;case y.reactNative:n(Wn());break;case y.node:n(Jn());break;default:n(!0)}})}function Hn(){return V()&&navigator?.onLine}async function Wn(){if(R()&&typeof global<"u"&&global!=null&&global.NetInfo){const e=await(global==null?void 0:global.NetInfo.fetch());return e?.isConnected}return!0}function Jn(){return!0}function ro(e){switch(A()){case y.browser:zn(e);break;case y.reactNative:Gn(e);break;case y.node:break}}function zn(e){!R()&&V()&&(window.addEventListener("online",()=>e(!0)),window.addEventListener("offline",()=>e(!1)))}function Gn(e){R()&&typeof global<"u"&&global!=null&&global.NetInfo&&global?.NetInfo.addEventListener(n=>e(n?.isConnected))}const Re={};class oo{static get(n){return Re[n]}static set(n,t){Re[n]=t}static delete(n){delete Re[n]}}export{he as BASE10,g as BASE16,ye as BASE64,sr as BASE64URL,ft as COLON,se as DEFAULT_DEPTH,W as EMPTY_SPACE,y as ENV_MAP,_n as INTERNAL_ERRORS,oo as MemoryStore,pt as ONE_THOUSAND,Me as REACT_NATIVE_PRODUCT,Nn as RELAYER_DEFAULT_PROTOCOL,Un as SDK_ERRORS,Ke as SDK_TYPE,Le as SLASH,ge as TYPE_0,D as TYPE_1,M as TYPE_2,k as UTF8,yn as addResourceToRecap,Fe as appendToQueryString,wt as assertType,fe as assignAbilityToActions,mn as base64Decode,pn as base64Encode,kr as buildApprovedNamespaces,Qt as buildAuthObject,Dr as buildNamespacesFromAuth,vn as buildRecapStatement,Ut as calcExpiry,$t as capitalize,ze as capitalizeWord,Tt as createDelayedPromise,nr as createEncodedRecap,Pt as createExpiringPromise,hn as createRecap,$ as decodeRecap,C as decodeTypeByte,hr as decodeTypeTwoEnvelope,mr as decrypt,ur as deriveSymKey,Y as deserialize,z as encodeRecap,be as encodeTypeByte,pr as encodeTypeTwoEnvelope,fr as encrypt,kt as engineEvent,It as enumify,ke as formatAccountId,ct as formatAccountWithChain,_e as formatChainId,Ge as formatDeeplinkUrl,ce as formatExpirerTarget,At as formatIdTarget,un as formatMessage,Nt as formatMessageContext,Rn as formatRelayParams,bt as formatRelayRpcUrl,me as formatStatementFromRecap,jt as formatTopicTarget,He as formatUA,Rr as formatUri,ue as fromBase64,cr as generateKeyPair,ar as generateRandomBytes32,U as getAccountsChains,ut as getAccountsFromNamespaces,De as getAddressFromAccount,at as getAddressesFromAccounts,yt as getAppId,gt as getAppMetadata,Hn as getBrowserOnlineStatus,xe as getChainFromAccount,Ve as getChainsFromAccounts,H as getChainsFromNamespace,lt as getChainsFromNamespaces,or as getChainsFromRecap,dt as getChainsFromRequiredNamespaces,ae as getCommonValuesInArrays,wn as getCryptoKeyFromKeyData,ln as getDecodedRecapFromResources,xt as getDeepLink,de as getDidAddress,J as getDidAddressSegments,cn as getDidChainId,A as getEnvironment,Et as getHttpUrl,S as getInternalError,Be as getJavascriptID,qe as getJavascriptOS,Je as getLastItems,Ir as getLinkModeURL,rr as getMethodsFromRecap,an as getNamespacedDidChainId,Tn as getNamespacesChains,jn as getNamespacesEventsForChainId,Cn as getNamespacesFromAccounts,Pn as getNamespacesMethodsForChainId,Jn as getNodeOnlineStatus,fn as getReCapActions,Wn as getReactNativeOnlineStatus,er as getRecapAbilitiesFromResource,G as getRecapFromResources,dn as getRecapResource,vt as getRelayClientMetadata,Or as getRelayProtocolApi,Nr as getRelayProtocolName,_r as getRequiredNamespacesFromNamespaces,_ as getSdkError,Vt as getSearchParamFromURL,oe as getUniqueValues,Dt as handleDeeplinkRedirect,I as hasOverlap,lr as hashKey,dr as hashMessage,mt as isAndroid,V as isBrowser,we as isCaipNamespace,qn as isConformingNamespaces,_t as isExpired,Ze as isIframe,ht as isIos,ie as isNode,to as isOnline,Mr as isProposalStruct,R as isReactNative,pe as isRecap,xr as isSessionCompatible,Lr as isSessionStruct,Qe as isTelegram,Lt as isTestRun,gr as isTypeOneEnvelope,vr as isTypeTwoEnvelope,T as isUndefined,kn as isValidAccountId,Vn as isValidAccounts,Ln as isValidActions,K as isValidArray,F as isValidChainId,Dn as isValidChains,Kr as isValidController,tn as isValidEip1271Signature,nn as isValidEip191Signature,Wr as isValidErrorReason,Gr as isValidEvent,Br as isValidId,Mn as isValidNamespaceAccounts,Se as isValidNamespaceActions,xn as isValidNamespaceChains,Oe as isValidNamespaceMethodsOrEvents,Kn as isValidNamespaces,Yr as isValidNamespacesChainId,Zr as isValidNamespacesEvent,Qr as isValidNamespacesRequest,Z as isValidNumber,Q as isValidObject,Hr as isValidParams,N as isValidRecap,Fn as isValidRelay,qr as isValidRelays,Jr as isValidRequest,no as isValidRequestExpiry,Fr as isValidRequiredNamespaces,zr as isValidResponse,b as isValidString,Vr as isValidUrl,Rt as mapEntries,Ot as mapToObj,O as mergeArrays,tr as mergeEncodedRecaps,gn as mergeRecaps,Ne as normalizeNamespaces,St as objToMap,Ye as openDeeplink,re as parseAccountId,te as parseChainId,We as parseContextNames,Ct as parseExpirerTarget,An as parseNamespaceKey,On as parseRelayParams,Sn as parseTopic,Sr as parseUri,Zt as populateAuthPayload,Xt as recapHasResource,Ee as serialize,Kt as sleep,zn as subscribeToBrowserNetworkChange,ro as subscribeToNetworkChange,Gn as subscribeToReactNativeNetworkChange,Xe as toBase64,Mt as uuidv4,yr as validateDecoding,En as validateEncoding,Yt as validateSignedCacao,wr as verifyP256Jwt,en as verifySignature}; | ||
Received: ${Object.keys(t).toString()}`)),re(i,c)||(r=te("NON_CONFORMING_NAMESPACES",`${n} namespaces chains don't satisfy required namespaces. | ||
Required: ${i.toString()} | ||
Approved: ${c.toString()}`)),Object.keys(t).forEach(f=>{if(!f.includes(":")||r)return;const d=le(t[f].accounts);d.includes(f)||(r=te("NON_CONFORMING_NAMESPACES",`${n} namespaces accounts don't satisfy namespace accounts for ${f} | ||
Required: ${f} | ||
Approved: ${d.toString()}`))}),i.forEach(f=>{r||(re(o[f].methods,s[f].methods)?re(o[f].events,s[f].events)||(r=te("NON_CONFORMING_NAMESPACES",`${n} namespaces events don't satisfy namespace events for ${f}`)):r=te("NON_CONFORMING_NAMESPACES",`${n} namespaces methods don't satisfy namespace methods for ${f}`))}),r}function Wi(e){const t={};return Object.keys(e).forEach(n=>{var r;n.includes(":")?t[n]=e[n]:(r=e[n].chains)==null||r.forEach(o=>{t[o]={methods:e[n].methods,events:e[n].events}})}),t}function Sr(e){return[...new Set(e.map(t=>t.includes(":")?t.split(":")[0]:t))]}function zi(e){const t={};return Object.keys(e).forEach(n=>{if(n.includes(":"))t[n]=e[n];else{const r=le(e[n].accounts);r?.forEach(o=>{t[o]={accounts:e[n].accounts.filter(s=>s.includes(`${o}:`)),methods:e[n].methods,events:e[n].events}})}}),t}function Ji(e,t){return Ge(e,!1)&&e<=t.max&&e>=t.min}function Yi(){const e=ue();return new Promise(t=>{switch(e){case H.browser:t(Ur());break;case H.reactNative:t(_r());break;case H.node:t(Tr());break;default:t(!0)}})}function Ur(){return Ae()&&navigator?.onLine}async function _r(){if(ne()&&typeof global<"u"&&global!=null&&global.NetInfo){const e=await(global==null?void 0:global.NetInfo.fetch());return e?.isConnected}return!0}function Tr(){return!0}function Xi(e){switch(ue()){case H.browser:$r(e);break;case H.reactNative:Rr(e);break;case H.node:break}}function $r(e){!ne()&&Ae()&&(window.addEventListener("online",()=>e(!0)),window.addEventListener("offline",()=>e(!1)))}function Rr(e){ne()&&typeof global<"u"&&global!=null&&global.NetInfo&&global?.NetInfo.addEventListener(t=>e(t?.isConnected))}const Lt={};class Zi{static get(t){return Lt[t]}static set(t,n){Lt[t]=n}static delete(t){delete Lt[t]}}export{It as BASE10,V as BASE16,At as BASE64,Qs as BASE64URL,qr as COLON,Qe as DEFAULT_DEPTH,Be as EMPTY_SPACE,H as ENV_MAP,mr as INTERNAL_ERRORS,Zi as MemoryStore,Gr as ONE_THOUSAND,Ft as REACT_NATIVE_PRODUCT,sr as RELAYER_DEFAULT_PROTOCOL,yr as SDK_ERRORS,Gt as SDK_TYPE,qt as SLASH,Nt as TYPE_0,Ie as TYPE_1,_e as TYPE_2,Oe as UTF8,$n as addResourceToRecap,Wt as appendToQueryString,eo as assertType,ft as assignAbilityToActions,_n as base64Decode,Un as base64Encode,_i as buildApprovedNamespaces,Xo as buildAuthObject,Ti as buildNamespacesFromAuth,Pn as buildRecapStatement,ho as calcExpiry,io as capitalize,Qt as capitalizeWord,co as createDelayedPromise,ts as createEncodedRecap,ao as createExpiringPromise,Tn as createRecap,oe as decodeRecap,fe as decodeTypeByte,ui as decodeTypeTwoEnvelope,ci as decrypt,ri as deriveSymKey,Fe as deserialize,De as encodeRecap,Ut as encodeTypeByte,ai as encodeTypeTwoEnvelope,ii as encrypt,go as engineEvent,so as enumify,Mt as formatAccountId,Mr as formatAccountWithChain,Dt as formatChainId,en as formatDeeplinkUrl,tt as formatExpirerTarget,fo as formatIdTarget,In as formatMessage,to as formatMessageContext,ar as formatRelayParams,Zr as formatRelayRpcUrl,dt as formatStatementFromRecap,uo as formatTopicTarget,Yt as formatUA,wi as formatUri,rt as fromBase64,ti as generateKeyPair,ni as generateRandomBytes32,le as getAccountsChains,Hr as getAccountsFromNamespaces,Vt as getAddressFromAccount,Vr as getAddressesFromAccounts,Jr as getAppId,Yr as getAppMetadata,Ur as getBrowserOnlineStatus,Ht as getChainFromAccount,Kt as getChainsFromAccounts,Le as getChainsFromNamespace,Kr as getChainsFromNamespaces,os as getChainsFromRecap,Fr as getChainsFromRequiredNamespaces,nt as getCommonValuesInArrays,or as getCryptoKeyFromKeyData,An as getDecodedRecapFromResources,mo as getDeepLink,ut as getDidAddress,ke as getDidAddressSegments,xn as getDidChainId,ue as getEnvironment,Qr as getHttpUrl,te as getInternalError,Jt as getJavascriptID,zt as getJavascriptOS,Zt as getLastItems,Ei as getLinkModeURL,rs as getMethodsFromRecap,On as getNamespacedDidChainId,lr as getNamespacesChains,hr as getNamespacesEventsForChainId,gr as getNamespacesFromAccounts,dr as getNamespacesMethodsForChainId,Tr as getNodeOnlineStatus,Sn as getReCapActions,_r as getReactNativeOnlineStatus,es as getRecapAbilitiesFromResource,Me as getRecapFromResources,Nn as getRecapResource,Xr as getRelayClientMetadata,mi as getRelayProtocolApi,yi as getRelayProtocolName,Ui as getRequiredNamespacesFromNamespaces,de as getSdkError,bo as getSearchParamFromURL,Ze as getUniqueValues,yo as handleDeeplinkRedirect,re as hasOverlap,ct as hashEthereumMessage,oi as hashKey,si as hashMessage,Wr as isAndroid,Ae as isBrowser,Tt as isCaipNamespace,Nr as isConformingNamespaces,po as isExpired,rn as isIframe,zr as isIos,et as isNode,Yi as isOnline,Pi as isProposalStruct,ne as isReactNative,lt as isRecap,$i as isSessionCompatible,Li as isSessionStruct,nn as isTelegram,Eo as isTestRun,li as isTypeOneEnvelope,di as isTypeTwoEnvelope,ae as isUndefined,br as isValidAccountId,vr as isValidAccounts,Or as isValidActions,$e as isValidArray,Re as isValidChainId,wr as isValidChains,Bi as isValidController,bn as isValidEip1271Signature,mn as isValidEip191Signature,Mi as isValidErrorReason,Ki as isValidEvent,ki as isValidId,xr as isValidNamespaceAccounts,Pt as isValidNamespaceActions,Er as isValidNamespaceChains,Rt as isValidNamespaceMethodsOrEvents,Ir as isValidNamespaces,Fi as isValidNamespacesChainId,Gi as isValidNamespacesEvent,qi as isValidNamespacesRequest,Ge as isValidNumber,qe as isValidObject,Di as isValidParams,Y as isValidRecap,Ar as isValidRelay,Ci as isValidRelays,Vi as isValidRequest,Ji as isValidRequestExpiry,ji as isValidRequiredNamespaces,Hi as isValidResponse,q as isValidString,Ri as isValidUrl,oo as mapEntries,no as mapToObj,Q as mergeArrays,ns as mergeEncodedRecaps,Rn as mergeRecaps,$t as normalizeNamespaces,ro as objToMap,tn as openDeeplink,Xe as parseAccountId,Ye as parseChainId,Xt as parseContextNames,lo as parseExpirerTarget,pr as parseNamespaceKey,ir as parseRelayParams,cr as parseTopic,bi as parseUri,Zo as populateAuthPayload,Qo as recapHasResource,_t as serialize,vo as sleep,$r as subscribeToBrowserNetworkChange,Xi as subscribeToNetworkChange,Rr as subscribeToReactNativeNetworkChange,on as toBase64,wo as uuidv4,fi as validateDecoding,rr as validateEncoding,Yo as validateSignedCacao,gi as verifyP256Jwt,yn as verifySignature}; | ||
//# sourceMappingURL=index.es.js.map |
@@ -12,5 +12,5 @@ import { CryptoTypes } from "@walletconnect/types"; | ||
export declare type P256KeyDataType = { | ||
crv: "P-256"; | ||
ext: true; | ||
key_ops: ["verify"]; | ||
crv: "P-256" | string; | ||
ext: true | boolean; | ||
key_ops: ["verify"] | string[]; | ||
kty: string; | ||
@@ -28,4 +28,4 @@ x: string; | ||
export declare function encrypt(params: CryptoTypes.EncryptParams): string; | ||
export declare function decrypt(params: CryptoTypes.DecryptParams): string; | ||
export declare function encodeTypeTwoEnvelope(message: string, encoding?: CryptoTypes.EncodingType): string; | ||
export declare function decrypt(params: CryptoTypes.DecryptParams): string; | ||
export declare function decodeTypeTwoEnvelope(encoded: string, encoding?: CryptoTypes.EncodingType): string; | ||
@@ -32,0 +32,0 @@ export declare function serialize(params: CryptoTypes.EncodingParams): string; |
import { AuthTypes } from "@walletconnect/types"; | ||
export declare function hashEthereumMessage(message: string): string; | ||
export declare function verifySignature(address: string, reconstructedMessage: string, cacaoSignature: AuthTypes.CacaoSignature, chainId: string, projectId: string, baseRpcUrl?: string): Promise<boolean>; | ||
@@ -3,0 +4,0 @@ export declare function isValidEip191Signature(address: string, message: string, signature: string): boolean; |
{ | ||
"name": "@walletconnect/utils", | ||
"description": "Utilities for WalletConnect Protocol", | ||
"version": "2.17.5", | ||
"version": "2.18.0-rc-1", | ||
"author": "WalletConnect, Inc. <walletconnect.com>", | ||
@@ -34,16 +34,13 @@ "homepage": "https://github.com/walletconnect/walletconnect-monorepo/", | ||
"dependencies": { | ||
"@ethersproject/hash": "5.7.0", | ||
"@ethersproject/transactions": "5.7.0", | ||
"@stablelib/chacha20poly1305": "1.0.1", | ||
"@stablelib/hkdf": "1.0.1", | ||
"@stablelib/random": "1.0.2", | ||
"@stablelib/sha256": "1.0.1", | ||
"@stablelib/x25519": "1.0.3", | ||
"@noble/ciphers": "1.2.1", | ||
"@noble/curves": "1.8.1", | ||
"@noble/hashes": "1.7.1", | ||
"@walletconnect/jsonrpc-utils": "1.0.8", | ||
"@walletconnect/keyvaluestorage": "1.1.1", | ||
"@walletconnect/relay-api": "1.0.11", | ||
"@walletconnect/relay-auth": "1.0.4", | ||
"@walletconnect/relay-auth": "1.1.0", | ||
"@walletconnect/safe-json": "1.0.2", | ||
"@walletconnect/time": "1.0.2", | ||
"@walletconnect/types": "2.17.5", | ||
"@walletconnect/types": "2.18.0-rc-1", | ||
"@walletconnect/window-getters": "1.0.1", | ||
@@ -53,5 +50,7 @@ "@walletconnect/window-metadata": "1.0.1", | ||
"elliptic": "6.6.1", | ||
"query-string": "7.1.3", | ||
"uint8arrays": "3.1.0" | ||
}, | ||
"devDependencies": { | ||
"@stablelib/x25519": "1.0.3", | ||
"@types/elliptic": "6.4.18", | ||
@@ -58,0 +57,0 @@ "@types/lodash.isequal": "4.5.6", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
3232398
19.36%17
-10.53%2362
6.11%10
11.11%26
13.04%4
100%134
2.29%4
33.33%2
100%