@cef-ai/widget-runtime 2.2.2 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -302,8 +302,8 @@ ${P.stack}`),WA.warn(tl),O&&O.listenerCount("error")>0&&O.emit("error",tl)}let O
302
302
  <h2>${Dl(I.title)}</h2><p>${Dl(I.body)}</p>
303
303
  <button data-hero-cta class="dc-cta">${Dl(I.cta)}</button>
304
304
  </div>`:""}function Y(I){return new Promise(Q=>{let f=document.createElement("div");f.setAttribute("data-confirm",""),f.style.cssText="position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.45);z-index:50;padding:16px;";let U=document.createElement("div");U.setAttribute("role","dialog"),U.setAttribute("aria-modal","true"),U.style.cssText="background:Canvas;color:CanvasText;border:1px solid color-mix(in srgb, currentColor 18%, transparent);border-radius:12px;padding:18px;max-width:340px;box-shadow:0 8px 28px rgba(0,0,0,0.25);",U.innerHTML=`<p style="margin:0 0 14px">${Dl(I)}</p><div style="display:flex;gap:8px;justify-content:flex-end"><button data-cancel style="padding:7px 14px;border-radius:8px;border:1px solid currentColor;background:transparent;cursor:pointer">Cancel</button><button data-ok style="padding:7px 14px;border-radius:8px;border:none;background:#ff5e8a;color:#fff;font-weight:600;cursor:pointer">Confirm</button></div>`,f.appendChild(U);let J=M=>{f.remove(),Q(M)};U.querySelector("[data-cancel]").addEventListener("click",()=>J(!1)),U.querySelector("[data-ok]").addEventListener("click",()=>J(!0)),f.addEventListener("click",M=>{M.target===f&&J(!1)}),l.appendChild(f)})}function R(){l.querySelectorAll("[data-rail-item]").forEach(I=>{I.addEventListener("click",()=>{let Q=I.getAttribute("data-panel");Z(d(Q))||u(Q)})}),l.querySelector("[data-menu-toggle]")?.addEventListener("click",()=>{let I=l.querySelector("[data-menu]");I&&I.toggleAttribute("hidden")}),A.menu?.forEach((I,Q)=>{l.querySelector(`[data-menu-action="${Q}"]`)?.addEventListener("click",async()=>{if(l.querySelector("[data-menu]")?.setAttribute("hidden",""),I.kind==="goto"){u(I.panel);return}I.confirm&&!await Y(I.confirm)||await G.publish(I.event.type,{schema_version:1,...I.event.payload??{}},void 0)})}),l.querySelector("[data-hero-cta]")?.addEventListener("click",()=>u(A.gating.firstRunPanel))}function u(I,Q=!1){l.innerHTML=h();let f=l.querySelector("[data-content]");Q&&!c&&A.gating.hero?(f.innerHTML=m(),B=A.gating.firstRunPanel):W(I),R()}async function i(I=0){if(!c){if(await DN(A,G)){c=!0,u(A.defaultPanel);return}I<5&&setTimeout(()=>void i(I+1),1500)}}u(B,!c)}var LN,d2=Gl(()=>{"use strict";LB();Z2();LN=new Map});var ib=class extends Error{constructor(G,b){super(G);el(this,"code");this.code=b,this.name="TransportError"}},KB=class extends ib{constructor(G,b,t,c){super(G,t);el(this,"status");el(this,"body");this.status=b,this.body=c,this.name="HttpError"}},qB=class extends ib{constructor(G){super(`Request timed out after ${G}ms`,"TIMEOUT");el(this,"timeoutMs");this.timeoutMs=G,this.name="TimeoutError"}},_B=class extends ib{constructor(A){super(A,"NETWORK_ERROR"),this.name="NetworkError"}};function Fo(l,A){let G=A&&typeof A=="object"?A:void 0,b=G?.detail??G?.title??G?.error?.message??`Request failed with status ${l}`,t=G?.type??(G?.error?.code!=null?String(G.error.code):void 0);return new KB(b,l,t,A)}var Ox=new TextEncoder;function Kb(l){let A="";for(let G=0;G<l.length;G++)A+=l[G].toString(16).padStart(2,"0");return A}function Te(l){let A=Yt(l);if(A.length%2!==0)throw new TypeError("hexToBytes: odd-length hex string");let G=new Uint8Array(A.length/2);for(let b=0;b<G.length;b++){let t=Number.parseInt(A.slice(b*2,b*2+2),16);if(Number.isNaN(t))throw new TypeError(`hexToBytes: invalid hex at ${b*2}`);G[b]=t}return G}function gB(l){return l.startsWith("0x")?l:`0x${l}`}function Yt(l){return l.startsWith("0x")?l.slice(2):l}function De(l){let A="";for(let b=0;b<l.length;b++)A+=String.fromCharCode(l[b]);return(typeof btoa=="function"?btoa(A):Buffer.from(A,"binary").toString("base64")).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}var BE=3e4,eE={retries:0,baseDelayMs:0};function ZE(l){return l instanceof Error&&l.name==="AbortError"}function dE(l){return l instanceof KB?l.status===429||l.status>=500:l instanceof _B||l instanceof qB}var na=class{constructor(A){el(this,"baseUrl");el(this,"fetchFn");el(this,"timeoutMs");el(this,"retry");el(this,"defaultHeaders");el(this,"sleep");if(!A.baseUrl)throw new ib("HttpClient: `baseUrl` is required");try{new URL(A.baseUrl)}catch{throw new ib(`HttpClient: invalid baseUrl ${JSON.stringify(A.baseUrl)}`)}this.baseUrl=A.baseUrl.replace(/\/$/,"");let G=A.fetch??globalThis.fetch?.bind(globalThis);if(typeof G!="function")throw new ib("HttpClient: no global fetch available \u2014 pass `config.fetch` (Node < 18?)");this.fetchFn=G,this.timeoutMs=A.timeoutMs??BE,this.retry=I2(A.retry??eE),this.defaultHeaders=A.defaultHeaders??{},this.sleep=A.sleep??(b=>new Promise(t=>setTimeout(t,b)))}async request(A,G,b={}){let t=this.buildUrl(G,b.query),c=b.retry?I2(b.retry):this.retry,{headers:B,body:e}=this.prepare(b),d=0;for(;;)try{return await this.attempt(A,t,B,e,b.signal,b.responseType??"json")}catch(Z){if(d>=c.retries||!dE(Z))throw Z;await this.sleep(nE(c,d)),d++}}prepare(A){let G={Accept:"application/json",...this.defaultHeaders,...A.headers},b;return A.body!==void 0&&(typeof A.body=="string"||A.body instanceof Uint8Array||A.body instanceof ArrayBuffer?b=A.body:(b=JSON.stringify(A.body),Object.keys(G).some(t=>t.toLowerCase()==="content-type")||(G["Content-Type"]="application/json"))),{headers:G,body:b}}async attempt(A,G,b,t,c,B="json"){let e=new AbortController,d=!1,Z=()=>e.abort();c&&(c.aborted?e.abort():c.addEventListener("abort",Z,{once:!0}));let g=setTimeout(()=>{d=!0,e.abort()},this.timeoutMs);try{let n=await this.fetchFn(G.toString(),{method:A,headers:b,body:t,signal:e.signal});if(n.status===204)return;if(B==="headers"){if(!n.ok)throw Fo(n.status,null);let W={};return n.headers.forEach((m,Y)=>{W[Y]=m}),W}if(!n.ok||B==="json"){let W=await n.text(),m=null;if(W)try{m=JSON.parse(W)}catch{let Y=n.headers.get("content-type")??"";if(n.ok&&/\bjson\b/i.test(Y))throw new ib(`Expected JSON but the ${n.status} body did not parse (content-type: ${Y||"none"})`);m=W}if(n.ok)return m;throw Fo(n.status,m)}let h=await n.arrayBuffer();return new Uint8Array(h)}catch(n){throw ZE(n)?d?new qB(this.timeoutMs):n:n instanceof ib?n:new _B(n instanceof Error?n.message:"Network error")}finally{clearTimeout(g),c?.removeEventListener("abort",Z)}}buildUrl(A,G){let b=A.startsWith("/")?`${this.baseUrl}${A}`:`${this.baseUrl}/${A}`,t=new URL(b);if(G)for(let[c,B]of Object.entries(G))B==null||B===""||t.searchParams.set(c,String(B));return t}};function I2(l){if(!Number.isInteger(l.retries)||l.retries<0)throw new ib(`HttpClient: retry.retries must be a non-negative integer (got ${l.retries})`);if(!(l.baseDelayMs>=0))throw new ib(`HttpClient: retry.baseDelayMs must be >= 0 (got ${l.baseDelayMs})`);if(l.maxDelayMs!==void 0&&!(l.maxDelayMs>=0))throw new ib(`HttpClient: retry.maxDelayMs must be >= 0 (got ${l.maxDelayMs})`);return l}function nE(l,A){let G=l.baseDelayMs*2**A;return l.maxDelayMs?Math.min(G,l.maxDelayMs):G}var _G=class extends Error{constructor(G,b,t,c){super(G);el(this,"status");el(this,"code");el(this,"retryable");this.status=b,this.code=t,this.retryable=c,this.name="VaultRequestError"}},aa=class extends _G{constructor(A="Endpoint not implemented (501)"){super(A,501,"NOT_IMPLEMENTED"),this.name="VaultNotImplementedError"}};function R2(l){let A=/(?:requested|last consented) "([^"]+)"/.exec(l)?.[1],G=/now carries "([^"]+)"/.exec(l)?.[1];return{...A!==void 0?{priorCid:A}:{},...G!==void 0?{currentCid:G}:{}}}var ga=class ga extends _G{constructor(G,b=!1){super(G,409,ga.code,b);el(this,"requestedCid");el(this,"currentCid");this.name="BundleChangedError";let{priorCid:t,currentCid:c}=R2(G);this.requestedCid=t,this.currentCid=c}};el(ga,"code","BUNDLE_CHANGED");var Id=ga,Wa=class Wa extends _G{constructor(G,b=!1){super(G,409,Wa.code,b);el(this,"previousCid");el(this,"currentCid");this.name="ReconsentRequiredError";let{priorCid:t,currentCid:c}=R2(G);this.previousCid=t,this.currentCid=c}};el(Wa,"code","RECONSENT_REQUIRED");var Rd=Wa,It=class extends Error{constructor(A="Vault signing requires a signer that implements sign(bytes)."){super(A),this.name="VaultSignerRequiredError"}},Xd=class extends _G{constructor(G,b,t,c){super(G,t,c,!1);el(this,"memberPubkey");this.memberPubkey=b,this.name="CeilingUnknownError"}};function X2(l,A){let G=A&&typeof A=="object"?A:void 0,b=G?.error?.message??`Request failed with status ${l}`,t=G?.error?.code,c=G?.error?.retryable===!0;return l===501?new aa(b):l===409&&t===Id.code?new Id(b,c):l===409&&t===Rd.code?new Rd(b,c):new _G(b,l,t,c)}var bt=class{async authenticate(A){if(A.body!==void 0){let G=new TextEncoder().encode(JSON.stringify(A.body));return{headers:{"Content-Type":"application/json"},body:G}}return{headers:{}}}};var p2=new TextEncoder,oa=()=>new Date().toISOString();function yo(l){return l.startsWith("0x")?l.slice(2):l}function F2(l,A=oa){let G={...l??{}};return typeof G.timestamp!="string"&&(G.timestamp=A()),{body:G,bytes:p2.encode(JSON.stringify(G))}}function Qo(l,A,G,b=oa,t){let c={method:l.toUpperCase(),path:A,query:G,timestamp:b()};t!==void 0&&(c.contentSha256=t);let B=JSON.stringify(c);return{preamble:B,bytes:p2.encode(B)}}function y2(l){if(!/^[A-Za-z0-9+/]*={0,2}$/.test(l)||l.length%4!==0)throw new TypeError("decodeBase64: input is not valid standard base64");let A=typeof atob=="function"?atob(l):Buffer.from(l,"base64").toString("binary"),G=new Uint8Array(A.length);for(let b=0;b<A.length;b++)G[b]=A.charCodeAt(b);return G}async function Q2(l){let A=await crypto.subtle.digest("SHA-256",l);return Kb(new Uint8Array(A))}var aE=3e4,gE=new bt,Le=class{constructor(A){el(this,"baseUrl");el(this,"http");el(this,"defaultAuth");el(this,"timeoutMs");if(!A.url)throw new Error("VaultHttpClient: `url` is required");this.baseUrl=A.url.replace(/\/$/,""),this.defaultAuth=A.auth??gE,this.timeoutMs=A.timeoutMs??aE,this.http=new na({baseUrl:this.baseUrl,fetch:A.fetch,timeoutMs:this.timeoutMs,retry:{retries:0,baseDelayMs:0}})}async send(A,G,b={}){let t=b.auth??this.defaultAuth,c=this.buildUrl(G,b.query),B=await t.authenticate({method:A,path:c.pathname,query:c.search.replace(/^\?/,""),body:b.body,hash:b.rawBody!==void 0?await Q2(b.rawBody):void 0});try{return await this.http.request(A,G,{query:b.query,headers:{...B.headers,...b.headers},body:B.body??b.rawBody,responseType:b.responseType})}catch(e){throw WE(e,this.timeoutMs)}}buildUrl(A,G){let b=A.startsWith("/")?`${this.baseUrl}${A}`:`${this.baseUrl}/${A}`,t=new URL(b);if(G)for(let[c,B]of Object.entries(G))B==null||B===""||t.searchParams.set(c,String(B));return t}};function WE(l,A){return l instanceof KB?X2(l.status,l.body):l instanceof qB?new _G(`Request timed out after ${A}ms`,0,"TIMEOUT"):l instanceof _B?new _G(l.message,0,"NETWORK_ERROR"):l instanceof ib?new _G(l.message,0,l.code??"TRANSPORT_ERROR"):l}var QA="/api/v1",Ul=l=>encodeURIComponent(l),oE=l=>l.split("/").map(Ul).join("/"),kl={vaults:()=>`${QA}/vaults`,vault:l=>`${QA}/vaults/${Ul(l)}`,vaultDelegations:l=>`${QA}/vaults/${Ul(l)}/delegations`,scopes:l=>`${QA}/vaults/${Ul(l)}/scopes`,scope:(l,A)=>`${QA}/vaults/${Ul(l)}/scopes/${Ul(A)}`,agents:l=>`${QA}/vaults/${Ul(l)}/agents`,agent:(l,A)=>`${QA}/vaults/${Ul(l)}/agents/${Ul(A)}`,agentCeiling:(l,A)=>`${QA}/vaults/${Ul(l)}/agents/${Ul(A)}/ceiling`,scopeEvents:(l,A)=>`${QA}/vaults/${Ul(l)}/scopes/${Ul(A)}/events`,scopeObjects:(l,A)=>`${QA}/vaults/${Ul(l)}/scopes/${Ul(A)}/objects`,scopeObject:(l,A,G)=>`${QA}/vaults/${Ul(l)}/scopes/${Ul(A)}/objects/${oE(G)}`,scopeObjectsPresignedUrl:(l,A)=>`${QA}/vaults/${Ul(l)}/scopes/${Ul(A)}/objects/presigned-url`,scopeStreams:(l,A)=>`${QA}/vaults/${Ul(l)}/scopes/${Ul(A)}/streams`,stream:(l,A,G)=>`${QA}/vaults/${Ul(l)}/scopes/${Ul(A)}/streams/${Ul(G)}`,streamEvents:(l,A,G)=>`${QA}/vaults/${Ul(l)}/scopes/${Ul(A)}/streams/${Ul(G)}/events`,jobs:l=>`${QA}/vaults/${Ul(l)}/jobs`,job:(l,A)=>`${QA}/vaults/${Ul(l)}/jobs/${Ul(A)}`,agentJobs:(l,A)=>`${QA}/vaults/${Ul(l)}/agents/${Ul(A)}/jobs`,jobTasks:(l,A)=>`${QA}/vaults/${Ul(l)}/jobs/${Ul(A)}/tasks`,jobTask:(l,A,G)=>`${QA}/vaults/${Ul(l)}/jobs/${Ul(A)}/tasks/${Ul(G)}`,jobTaskLogs:(l,A,G)=>`${QA}/vaults/${Ul(l)}/jobs/${Ul(A)}/tasks/${Ul(G)}/logs`,cubbyQuery:(l,A,G,b)=>`${QA}/vaults/${Ul(l)}/scopes/${Ul(A)}/agents/${G}/cubbies/${Ul(b)}/query`,cubbyExec:(l,A,G,b)=>`${QA}/vaults/${Ul(l)}/scopes/${Ul(A)}/agents/${G}/cubbies/${Ul(b)}/exec`,serviceCubbies:(l,A)=>`${QA}/vaults/${Ul(l)}/services/${A}/cubbies`,serviceCubby:(l,A,G)=>`${QA}/vaults/${Ul(l)}/services/${A}/cubbies/${Ul(G)}`,serviceCubbyQuery:(l,A,G)=>`${QA}/vaults/${Ul(l)}/services/${A}/cubbies/${Ul(G)}/query`,serviceCubbyExec:(l,A,G)=>`${QA}/vaults/${Ul(l)}/services/${A}/cubbies/${Ul(G)}/exec`,serviceCubbyProvision:(l,A,G)=>`${QA}/vaults/${Ul(l)}/services/${A}/cubbies/${Ul(G)}/provision`,memoryTool:(l,A)=>`${QA}/vaults/${Ul(l)}/memory/${Ul(A)}`,connectors:()=>`${QA}/connectors`,connections:l=>`${QA}/vaults/${Ul(l)}/connections`,connection:(l,A)=>`${QA}/vaults/${Ul(l)}/connections/${Ul(A)}`,connectionActions:(l,A)=>`${QA}/vaults/${Ul(l)}/connections/${Ul(A)}/actions`,agentConnections:(l,A)=>`${QA}/vaults/${Ul(l)}/agents/${Ul(A)}/connections`,agentConnection:(l,A,G)=>`${QA}/vaults/${Ul(l)}/agents/${Ul(A)}/connections/${Ul(G)}`,marketplaceAgents:()=>`${QA}/marketplace/agents`,marketplaceAgent:l=>`${QA}/marketplace/agents/${Ul(l)}`,marketplaceAgentVersion:(l,A)=>`${QA}/marketplace/agents/${Ul(l)}/versions/${Ul(A)}`,delegateInfo:()=>`${QA}/delegate-info`,vaultMembers:l=>`${QA}/vaults/${Ul(l)}/members`,vaultMember:(l,A)=>`${QA}/vaults/${Ul(l)}/members/${Ul(A)}`,vaultMemberScopes:(l,A)=>`${QA}/vaults/${Ul(l)}/members/${Ul(A)}/scopes`,vaultSignedRoster:l=>`${QA}/vaults/${Ul(l)}/roster/signed`,memberships:()=>`${QA}/memberships`,health:()=>"/health",ready:()=>"/ready",metrics:()=>"/metrics"};var ha=class{constructor(A){el(this,"http");this.http=A}claim(A){return this.http.send("POST",kl.vaults(),{body:A})}current(){return this.http.send("GET",kl.vaults())}byId(A){return this.http.send("GET",kl.vault(A))}patch(A,G){return this.http.send("PATCH",kl.vault(A),{body:G})}putDelegations(A,G){return this.http.send("PUT",kl.vaultDelegations(A),{body:G})}};var hE={p:0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedn,n:0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn,h:8n,a:0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecn,d:0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3n,Gx:0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,Gy:0x6666666666666666666666666666666666666666666666666666666666666658n},{p:Nb,n:sa,Gx:N2,Gy:E2,a:No,d:Eo}=hE,sE=8n,pd=32,vo=64,Rt=(l="")=>{throw new Error(l)},rE=l=>typeof l=="bigint",k2=l=>typeof l=="string",iE=l=>l instanceof Uint8Array||ArrayBuffer.isView(l)&&l.constructor.name==="Uint8Array",Pe=(l,A)=>!iE(l)||typeof A=="number"&&A>0&&l.length!==A?Rt("Uint8Array expected"):l,Va=l=>new Uint8Array(l),fo=l=>Uint8Array.from(l),w2=(l,A)=>l.toString(16).padStart(A,"0"),ko=l=>Array.from(Pe(l)).map(A=>w2(A,2)).join(""),yc={_0:48,_9:57,A:65,F:70,a:97,f:102},v2=l=>{if(l>=yc._0&&l<=yc._9)return l-yc._0;if(l>=yc.A&&l<=yc.F)return l-(yc.A-10);if(l>=yc.a&&l<=yc.f)return l-(yc.a-10)},wo=l=>{let A="hex invalid";if(!k2(l))return Rt(A);let G=l.length,b=G/2;if(G%2)return Rt(A);let t=Va(b);for(let c=0,B=0;c<b;c++,B+=2){let e=v2(l.charCodeAt(B)),d=v2(l.charCodeAt(B+1));if(e===void 0||d===void 0)return Rt(A);t[c]=e*16+d}return t},ra=(l,A)=>Pe(k2(l)?wo(l):fo(Pe(l)),A),U2=()=>globalThis?.crypto,mE=()=>U2()?.subtle??Rt("crypto.subtle must be defined"),Ho=(...l)=>{let A=Va(l.reduce((b,t)=>b+Pe(t).length,0)),G=0;return l.forEach(b=>{A.set(b,G),G+=b.length}),A},VE=(l=pd)=>U2().getRandomValues(Va(l)),ia=BigInt,$B=(l,A,G,b="bad number: out of range")=>rE(l)&&A<=l&&l<G?l:Rt(b),_l=(l,A=Nb)=>{let G=l%A;return G>=0n?G:A+G},uE=l=>_l(l,sa),C2=(l,A)=>{(l===0n||A<=0n)&&Rt("no inverse n="+l+" mod="+A);let G=_l(l,A),b=A,t=0n,c=1n,B=1n,e=0n;for(;G!==0n;){let d=b/G,Z=b%G,g=t-B*d,n=c-e*d;b=G,G=Z,t=B,c=e,B=g,e=n}return b===1n?_l(t,A):Rt("no inverse")};var H2=l=>l instanceof Qc?l:Rt("Point expected"),Jo=2n**256n,Gc=class Gc{constructor(A,G,b,t){el(this,"ex");el(this,"ey");el(this,"ez");el(this,"et");let c=Jo;this.ex=$B(A,0n,c),this.ey=$B(G,0n,c),this.ez=$B(b,1n,c),this.et=$B(t,0n,c),Object.freeze(this)}static fromAffine(A){return new Gc(A.x,A.y,1n,_l(A.x*A.y))}static fromBytes(A,G=!1){let b=Eo,t=fo(Pe(A,pd)),c=A[31];t[31]=c&-129;let B=Uo(t);$B(B,0n,G?Jo:Nb);let d=_l(B*B),Z=_l(d-1n),g=_l(b*d+1n),{isValid:n,value:h}=RE(Z,g);n||Rt("bad point: y not sqrt");let W=(h&1n)===1n,m=(c&128)!==0;return!G&&h===0n&&m&&Rt("bad point: x==0, isLastByteOdd"),m!==W&&(h=_l(-h)),new Gc(h,B,1n,_l(h*B))}assertValidity(){let A=No,G=Eo,b=this;if(b.is0())throw new Error("bad point: ZERO");let{ex:t,ey:c,ez:B,et:e}=b,d=_l(t*t),Z=_l(c*c),g=_l(B*B),n=_l(g*g),h=_l(d*A),W=_l(g*_l(h+Z)),m=_l(n+_l(G*_l(d*Z)));if(W!==m)throw new Error("bad point: equation left != right (1)");let Y=_l(t*c),R=_l(B*e);if(Y!==R)throw new Error("bad point: equation left != right (2)");return this}equals(A){let{ex:G,ey:b,ez:t}=this,{ex:c,ey:B,ez:e}=H2(A),d=_l(G*e),Z=_l(c*t),g=_l(b*e),n=_l(B*t);return d===Z&&g===n}is0(){return this.equals(Oe)}negate(){return new Gc(_l(-this.ex),this.ey,this.ez,_l(-this.et))}double(){let{ex:A,ey:G,ez:b}=this,t=No,c=_l(A*A),B=_l(G*G),e=_l(2n*_l(b*b)),d=_l(t*c),Z=A+G,g=_l(_l(Z*Z)-c-B),n=d+B,h=n-e,W=d-B,m=_l(g*h),Y=_l(n*W),R=_l(g*W),u=_l(h*n);return new Gc(m,Y,u,R)}add(A){let{ex:G,ey:b,ez:t,et:c}=this,{ex:B,ey:e,ez:d,et:Z}=H2(A),g=No,n=Eo,h=_l(G*B),W=_l(b*e),m=_l(c*n*Z),Y=_l(t*d),R=_l((G+b)*(B+e)-h-W),u=_l(Y-m),i=_l(Y+m),I=_l(W-g*h),Q=_l(R*u),f=_l(i*I),U=_l(R*I),J=_l(u*i);return new Gc(Q,f,J,U)}multiply(A,G=!0){if(!G&&(A===0n||this.is0()))return Oe;if($B(A,1n,sa),A===1n)return this;if(this.equals(Ke))return vE(A).p;let b=Oe,t=Ke;for(let c=this;A>0n;c=c.double(),A>>=1n)A&1n?b=b.add(c):G&&(t=t.add(c));return b}toAffine(){let{ex:A,ey:G,ez:b}=this;if(this.equals(Oe))return{x:0n,y:1n};let t=C2(b,Nb);return _l(b*t)!==1n&&Rt("invalid inverse"),{x:_l(A*t),y:_l(G*t)}}toBytes(){let{x:A,y:G}=this.assertValidity().toAffine(),b=YE(G);return b[31]|=A&1n?128:0,b}toHex(){return ko(this.toBytes())}clearCofactor(){return this.multiply(ia(sE),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let A=this.multiply(sa/2n,!1).double();return sa%2n&&(A=A.add(this)),A.is0()}static fromHex(A,G){return Gc.fromBytes(ra(A),G)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}toRawBytes(){return this.toBytes()}};el(Gc,"BASE"),el(Gc,"ZERO");var Qc=Gc,Ke=new Qc(N2,E2,1n,_l(N2*E2)),Oe=new Qc(0n,1n,1n,0n);Qc.BASE=Ke;Qc.ZERO=Oe;var YE=l=>wo(w2($B(l,0n,Jo),vo)).reverse(),Uo=l=>ia("0x"+ko(fo(Pe(l)).reverse())),Ac=(l,A)=>{let G=l;for(;A-- >0n;)G*=G,G%=Nb;return G},IE=l=>{let G=l*l%Nb*l%Nb,b=Ac(G,2n)*G%Nb,t=Ac(b,1n)*l%Nb,c=Ac(t,5n)*t%Nb,B=Ac(c,10n)*c%Nb,e=Ac(B,20n)*B%Nb,d=Ac(e,40n)*e%Nb,Z=Ac(d,80n)*d%Nb,g=Ac(Z,80n)*d%Nb,n=Ac(g,10n)*c%Nb;return{pow_p_5_8:Ac(n,2n)*l%Nb,b2:G}},J2=0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0n,RE=(l,A)=>{let G=_l(A*A*A),b=_l(G*G*A),t=IE(l*b).pow_p_5_8,c=_l(l*G*t),B=_l(A*c*c),e=c,d=_l(c*J2),Z=B===l,g=B===_l(-l),n=B===_l(-l*J2);return Z&&(c=e),(g||n)&&(c=d),(_l(c)&1n)===1n&&(c=_l(-c)),{isValid:Z||g,value:c}},XE=l=>uE(Uo(l)),pE=(...l)=>QE.sha512Async(...l);var FE=l=>pE(l.hashable).then(l.finish);var S2={zip215:!0},yE=(l,A,G,b=S2)=>{l=ra(l,vo),A=ra(A),G=ra(G,pd);let{zip215:t}=b,c,B,e,d,Z=Uint8Array.of();try{c=Qc.fromHex(G,t),B=Qc.fromHex(l.slice(0,pd),t),e=Uo(l.slice(pd,vo)),d=Ke.multiply(e,!1),Z=Ho(B.toBytes(),c.toBytes(),A)}catch{}return{hashable:Z,finish:n=>{if(d==null||!t&&c.isSmallOrder())return!1;let h=XE(n);return B.add(c.multiply(h,!1)).add(d.negate()).clearCofactor().is0()}}},z2=async(l,A,G,b=S2)=>FE(yE(l,A,G,b));var QE={sha512Async:async(...l)=>{let A=mE(),G=Ho(...l);return Va(await A.digest("SHA-512",G.buffer))},sha512Sync:void 0,bytesToHex:ko,hexToBytes:wo,concatBytes:Ho,mod:_l,invert:C2,randomBytes:VE};var ma=8,NE=256,j2=Math.ceil(NE/ma)+1,xo=2**(ma-1),EE=()=>{let l=[],A=Ke,G=A;for(let b=0;b<j2;b++){G=A,l.push(G);for(let t=1;t<xo;t++)G=G.add(A),l.push(G);A=G.double()}return l},x2,f2=(l,A)=>{let G=A.negate();return l?G:A},vE=l=>{let A=x2||(x2=EE()),G=Oe,b=Ke,t=2**ma,c=t,B=ia(t-1),e=ia(ma);for(let d=0;d<j2;d++){let Z=Number(l&B);l>>=e,Z>xo&&(Z-=c,l+=1n);let g=d*xo,n=g,h=g+Math.abs(Z)-1,W=d%2!==0,m=Z<0;Z===0?b=b.add(f2(W,A[n])):G=G.add(f2(m,A[h]))}return{p:G,f:b}};var le=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function ft(l){return l instanceof Uint8Array||ArrayBuffer.isView(l)&&l.constructor.name==="Uint8Array"}function mG(l){if(!Number.isSafeInteger(l)||l<0)throw new Error("positive integer expected, got "+l)}function fG(l,...A){if(!ft(l))throw new Error("Uint8Array expected");if(A.length>0&&!A.includes(l.length))throw new Error("Uint8Array expected of length "+A+", got length="+l.length)}function qe(l){if(typeof l!="function"||typeof l.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");mG(l.outputLen),mG(l.blockLen)}function Xt(l,A=!0){if(l.destroyed)throw new Error("Hash instance has been destroyed");if(A&&l.finished)throw new Error("Hash#digest() has already been called")}function _e(l,A){fG(l);let G=A.outputLen;if(l.length<G)throw new Error("digestInto() expects output buffer of length at least "+G)}function tt(l){return new Uint32Array(l.buffer,l.byteOffset,Math.floor(l.byteLength/4))}function MG(...l){for(let A=0;A<l.length;A++)l[A].fill(0)}function $e(l){return new DataView(l.buffer,l.byteOffset,l.byteLength)}function kt(l,A){return l<<32-A|l>>>A}function qA(l,A){return l<<A|l>>>32-A>>>0}var T2=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function D2(l){return l<<24&4278190080|l<<8&16711680|l>>>8&65280|l>>>24&255}var tc=T2?l=>l:l=>D2(l);function JE(l){for(let A=0;A<l.length;A++)l[A]=D2(l[A]);return l}var ct=T2?l=>l:JE,L2=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",xE=Array.from({length:256},(l,A)=>A.toString(16).padStart(2,"0"));function Bt(l){if(fG(l),L2)return l.toHex();let A="";for(let G=0;G<l.length;G++)A+=xE[l[G]];return A}var Nc={_0:48,_9:57,A:65,F:70,a:97,f:102};function M2(l){if(l>=Nc._0&&l<=Nc._9)return l-Nc._0;if(l>=Nc.A&&l<=Nc.F)return l-(Nc.A-10);if(l>=Nc.a&&l<=Nc.f)return l-(Nc.a-10)}function WB(l){if(typeof l!="string")throw new Error("hex string expected, got "+typeof l);if(L2)return Uint8Array.fromHex(l);let A=l.length,G=A/2;if(A%2)throw new Error("hex string expected, got unpadded hex of length "+A);let b=new Uint8Array(G);for(let t=0,c=0;t<G;t++,c+=2){let B=M2(l.charCodeAt(c)),e=M2(l.charCodeAt(c+1));if(B===void 0||e===void 0){let d=l[c]+l[c+1];throw new Error('hex string expected, got non-hex character "'+d+'" at index '+c)}b[t]=B*16+e}return b}function Ec(l){if(typeof l!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(l))}function et(l){return typeof l=="string"&&(l=Ec(l)),fG(l),l}function Co(l){return typeof l=="string"&&(l=Ec(l)),fG(l),l}function VG(...l){let A=0;for(let b=0;b<l.length;b++){let t=l[b];fG(t),A+=t.length}let G=new Uint8Array(A);for(let b=0,t=0;b<l.length;b++){let c=l[b];G.set(c,t),t+=c.length}return G}function ua(l,A){if(A!==void 0&&{}.toString.call(A)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(l,A)}var bc=class{};function Fd(l){let A=b=>l().update(et(b)).digest(),G=l();return A.outputLen=G.outputLen,A.blockLen=G.blockLen,A.create=()=>l(),A}function O2(l){let A=(b,t)=>l(t).update(et(b)).digest(),G=l({});return A.outputLen=G.outputLen,A.blockLen=G.blockLen,A.create=b=>l(b),A}function Eb(l=32){if(le&&typeof le.getRandomValues=="function")return le.getRandomValues(new Uint8Array(l));if(le&&typeof le.randomBytes=="function")return Uint8Array.from(le.randomBytes(l));throw new Error("crypto.getRandomValues must be defined")}var P2=Uint8Array.from([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9]);function fE(l,A,G,b){if(typeof l.setBigUint64=="function")return l.setBigUint64(A,G,b);let t=BigInt(32),c=BigInt(4294967295),B=Number(G>>t&c),e=Number(G&c),d=b?4:0,Z=b?0:4;l.setUint32(A+d,B,b),l.setUint32(A+Z,e,b)}function K2(l,A,G){return l&A^~l&G}function q2(l,A,G){return l&A^l&G^A&G}var yd=class extends bc{constructor(A,G,b,t){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=A,this.outputLen=G,this.padOffset=b,this.isLE=t,this.buffer=new Uint8Array(A),this.view=$e(this.buffer)}update(A){Xt(this),A=et(A),fG(A);let{view:G,buffer:b,blockLen:t}=this,c=A.length;for(let B=0;B<c;){let e=Math.min(t-this.pos,c-B);if(e===t){let d=$e(A);for(;t<=c-B;B+=t)this.process(d,B);continue}b.set(A.subarray(B,B+e),this.pos),this.pos+=e,B+=e,this.pos===t&&(this.process(G,0),this.pos=0)}return this.length+=A.length,this.roundClean(),this}digestInto(A){Xt(this),_e(A,this),this.finished=!0;let{buffer:G,view:b,blockLen:t,isLE:c}=this,{pos:B}=this;G[B++]=128,MG(this.buffer.subarray(B)),this.padOffset>t-B&&(this.process(b,0),B=0);for(let n=B;n<t;n++)G[n]=0;fE(b,t-8,BigInt(this.length*8),c),this.process(b,0);let e=$e(A),d=this.outputLen;if(d%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let Z=d/4,g=this.get();if(Z>g.length)throw new Error("_sha2: outputLen bigger than state");for(let n=0;n<Z;n++)e.setUint32(4*n,g[n],c)}digest(){let{buffer:A,outputLen:G}=this;this.digestInto(A);let b=A.slice(0,G);return this.destroy(),b}_cloneInto(A){A||(A=new this.constructor),A.set(...this.get());let{blockLen:G,buffer:b,length:t,finished:c,destroyed:B,pos:e}=this;return A.destroyed=B,A.finished=c,A.length=t,A.pos=e,t%G&&A.buffer.set(b),A}clone(){return this._cloneInto()}},vc=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var mb=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Ya=BigInt(4294967295),_2=BigInt(32);function So(l,A=!1){return A?{h:Number(l&Ya),l:Number(l>>_2&Ya)}:{h:Number(l>>_2&Ya)|0,l:Number(l&Ya)|0}}function Ia(l,A=!1){let G=l.length,b=new Uint32Array(G),t=new Uint32Array(G);for(let c=0;c<G;c++){let{h:B,l:e}=So(l[c],A);[b[c],t[c]]=[B,e]}return[b,t]}var zo=(l,A,G)=>l>>>G,jo=(l,A,G)=>l<<32-G|A>>>G,cc=(l,A,G)=>l>>>G|A<<32-G,Bc=(l,A,G)=>l<<32-G|A>>>G,Ae=(l,A,G)=>l<<64-G|A>>>G-32,Ge=(l,A,G)=>l>>>G-32|A<<64-G,$2=(l,A)=>A,lV=(l,A)=>l,AV=(l,A,G)=>l<<G|A>>>32-G,GV=(l,A,G)=>A<<G|l>>>32-G,bV=(l,A,G)=>A<<G-32|l>>>64-G,tV=(l,A,G)=>l<<G-32|A>>>64-G;function Zt(l,A,G,b){let t=(A>>>0)+(b>>>0);return{h:l+G+(t/2**32|0)|0,l:t|0}}var Qd=(l,A,G)=>(l>>>0)+(A>>>0)+(G>>>0),Nd=(l,A,G,b)=>A+G+b+(l/2**32|0)|0,cV=(l,A,G,b)=>(l>>>0)+(A>>>0)+(G>>>0)+(b>>>0),BV=(l,A,G,b,t)=>A+G+b+t+(l/2**32|0)|0,eV=(l,A,G,b,t)=>(l>>>0)+(A>>>0)+(G>>>0)+(b>>>0)+(t>>>0),ZV=(l,A,G,b,t,c)=>A+G+b+t+c+(l/2**32|0)|0;var $G=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),zl=new Uint32Array(32);function oB(l,A,G,b,t,c){let B=t[c],e=t[c+1],d=zl[2*l],Z=zl[2*l+1],g=zl[2*A],n=zl[2*A+1],h=zl[2*G],W=zl[2*G+1],m=zl[2*b],Y=zl[2*b+1],R=Qd(d,g,B);Z=Nd(R,Z,n,e),d=R|0,{Dh:Y,Dl:m}={Dh:Y^Z,Dl:m^d},{Dh:Y,Dl:m}={Dh:$2(Y,m),Dl:lV(Y,m)},{h:W,l:h}=Zt(W,h,Y,m),{Bh:n,Bl:g}={Bh:n^W,Bl:g^h},{Bh:n,Bl:g}={Bh:cc(n,g,24),Bl:Bc(n,g,24)},zl[2*l]=d,zl[2*l+1]=Z,zl[2*A]=g,zl[2*A+1]=n,zl[2*G]=h,zl[2*G+1]=W,zl[2*b]=m,zl[2*b+1]=Y}function hB(l,A,G,b,t,c){let B=t[c],e=t[c+1],d=zl[2*l],Z=zl[2*l+1],g=zl[2*A],n=zl[2*A+1],h=zl[2*G],W=zl[2*G+1],m=zl[2*b],Y=zl[2*b+1],R=Qd(d,g,B);Z=Nd(R,Z,n,e),d=R|0,{Dh:Y,Dl:m}={Dh:Y^Z,Dl:m^d},{Dh:Y,Dl:m}={Dh:cc(Y,m,16),Dl:Bc(Y,m,16)},{h:W,l:h}=Zt(W,h,Y,m),{Bh:n,Bl:g}={Bh:n^W,Bl:g^h},{Bh:n,Bl:g}={Bh:Ae(n,g,63),Bl:Ge(n,g,63)},zl[2*l]=d,zl[2*l+1]=Z,zl[2*A]=g,zl[2*A+1]=n,zl[2*G]=h,zl[2*G+1]=W,zl[2*b]=m,zl[2*b+1]=Y}function kE(l,A={},G,b,t){if(mG(G),l<0||l>G)throw new Error("outputLen bigger than keyLen");let{key:c,salt:B,personalization:e}=A;if(c!==void 0&&(c.length<1||c.length>G))throw new Error("key length must be undefined or 1.."+G);if(B!==void 0&&B.length!==b)throw new Error("salt must be undefined or "+b);if(e!==void 0&&e.length!==t)throw new Error("personalization must be undefined or "+t)}var Mo=class extends bc{constructor(A,G){super(),this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,mG(A),mG(G),this.blockLen=A,this.outputLen=G,this.buffer=new Uint8Array(A),this.buffer32=tt(this.buffer)}update(A){Xt(this),A=et(A),fG(A);let{blockLen:G,buffer:b,buffer32:t}=this,c=A.length,B=A.byteOffset,e=A.buffer;for(let d=0;d<c;){this.pos===G&&(ct(t),this.compress(t,0,!1),ct(t),this.pos=0);let Z=Math.min(G-this.pos,c-d),g=B+d;if(Z===G&&!(g%4)&&d+Z<c){let n=new Uint32Array(e,g,Math.floor((c-d)/4));ct(n);for(let h=0;d+G<c;h+=t.length,d+=G)this.length+=G,this.compress(n,h,!1);ct(n);continue}b.set(A.subarray(d,d+Z),this.pos),this.pos+=Z,this.length+=Z,d+=Z}return this}digestInto(A){Xt(this),_e(A,this);let{pos:G,buffer32:b}=this;this.finished=!0,MG(this.buffer.subarray(G)),ct(b),this.compress(b,0,!0),ct(b);let t=tt(A);this.get().forEach((c,B)=>t[B]=tc(c))}digest(){let{buffer:A,outputLen:G}=this;this.digestInto(A);let b=A.slice(0,G);return this.destroy(),b}_cloneInto(A){let{buffer:G,length:b,finished:t,destroyed:c,outputLen:B,pos:e}=this;return A||(A=new this.constructor({dkLen:B})),A.set(...this.get()),A.buffer.set(G),A.destroyed=c,A.finished=t,A.length=b,A.pos=e,A.outputLen=B,A}clone(){return this._cloneInto()}},Ra=class extends Mo{constructor(A={}){let G=A.dkLen===void 0?64:A.dkLen;super(128,G),this.v0l=$G[0]|0,this.v0h=$G[1]|0,this.v1l=$G[2]|0,this.v1h=$G[3]|0,this.v2l=$G[4]|0,this.v2h=$G[5]|0,this.v3l=$G[6]|0,this.v3h=$G[7]|0,this.v4l=$G[8]|0,this.v4h=$G[9]|0,this.v5l=$G[10]|0,this.v5h=$G[11]|0,this.v6l=$G[12]|0,this.v6h=$G[13]|0,this.v7l=$G[14]|0,this.v7h=$G[15]|0,kE(G,A,64,16,16);let{key:b,personalization:t,salt:c}=A,B=0;if(b!==void 0&&(b=et(b),B=b.length),this.v0l^=this.outputLen|B<<8|65536|1<<24,c!==void 0){c=et(c);let e=tt(c);this.v4l^=tc(e[0]),this.v4h^=tc(e[1]),this.v5l^=tc(e[2]),this.v5h^=tc(e[3])}if(t!==void 0){t=et(t);let e=tt(t);this.v6l^=tc(e[0]),this.v6h^=tc(e[1]),this.v7l^=tc(e[2]),this.v7h^=tc(e[3])}if(b!==void 0){let e=new Uint8Array(this.blockLen);e.set(b),this.update(e)}}get(){let{v0l:A,v0h:G,v1l:b,v1h:t,v2l:c,v2h:B,v3l:e,v3h:d,v4l:Z,v4h:g,v5l:n,v5h:h,v6l:W,v6h:m,v7l:Y,v7h:R}=this;return[A,G,b,t,c,B,e,d,Z,g,n,h,W,m,Y,R]}set(A,G,b,t,c,B,e,d,Z,g,n,h,W,m,Y,R){this.v0l=A|0,this.v0h=G|0,this.v1l=b|0,this.v1h=t|0,this.v2l=c|0,this.v2h=B|0,this.v3l=e|0,this.v3h=d|0,this.v4l=Z|0,this.v4h=g|0,this.v5l=n|0,this.v5h=h|0,this.v6l=W|0,this.v6h=m|0,this.v7l=Y|0,this.v7h=R|0}compress(A,G,b){this.get().forEach((d,Z)=>zl[Z]=d),zl.set($G,16);let{h:t,l:c}=So(BigInt(this.length));zl[24]=$G[8]^c,zl[25]=$G[9]^t,b&&(zl[28]=~zl[28],zl[29]=~zl[29]);let B=0,e=P2;for(let d=0;d<12;d++)oB(0,4,8,12,A,G+2*e[B++]),hB(0,4,8,12,A,G+2*e[B++]),oB(1,5,9,13,A,G+2*e[B++]),hB(1,5,9,13,A,G+2*e[B++]),oB(2,6,10,14,A,G+2*e[B++]),hB(2,6,10,14,A,G+2*e[B++]),oB(3,7,11,15,A,G+2*e[B++]),hB(3,7,11,15,A,G+2*e[B++]),oB(0,5,10,15,A,G+2*e[B++]),hB(0,5,10,15,A,G+2*e[B++]),oB(1,6,11,12,A,G+2*e[B++]),hB(1,6,11,12,A,G+2*e[B++]),oB(2,7,8,13,A,G+2*e[B++]),hB(2,7,8,13,A,G+2*e[B++]),oB(3,4,9,14,A,G+2*e[B++]),hB(3,4,9,14,A,G+2*e[B++]);this.v0l^=zl[0]^zl[16],this.v0h^=zl[1]^zl[17],this.v1l^=zl[2]^zl[18],this.v1h^=zl[3]^zl[19],this.v2l^=zl[4]^zl[20],this.v2h^=zl[5]^zl[21],this.v3l^=zl[6]^zl[22],this.v3h^=zl[7]^zl[23],this.v4l^=zl[8]^zl[24],this.v4h^=zl[9]^zl[25],this.v5l^=zl[10]^zl[26],this.v5h^=zl[11]^zl[27],this.v6l^=zl[12]^zl[28],this.v6h^=zl[13]^zl[29],this.v7l^=zl[14]^zl[30],this.v7h^=zl[15]^zl[31],MG(zl)}destroy(){this.destroyed=!0,MG(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},nV=O2(l=>new Ra(l));var To=nV;function wE(l){return l("return this")}var ec=typeof globalThis<"u"?globalThis:typeof global<"u"?global:typeof self<"u"?self:typeof window<"u"?window:wE(Function);function lZ(l,A){return typeof ec[l]>"u"?A:ec[l]}var Xa=class{constructor(A){el(this,"__encoding");this.__encoding=A}decode(A){let G="";for(let b=0,t=A.length;b<t;b++)G+=String.fromCharCode(A[b]);return G}};var aV=lZ("TextDecoder",Xa);var pa=class{encode(A){let G=A.length,b=new Uint8Array(G);for(let t=0;t<G;t++)b[t]=A.charCodeAt(t);return b}};var gV=lZ("TextEncoder",pa);function Ed(l){return typeof l=="function"}function UE(){return Number.NaN}var UA=lZ("BigInt",UE);var AZ=UA(0),GZ=UA(1);var WV=UA(1e9),_f=WV*WV,$f=UA(Number.MAX_SAFE_INTEGER);var oV=UA(256),hV=UA(256*256),CE=UA("0x10000000000000000");function bZ(l,{isLe:A=!0,isNegative:G=!1}={}){A||(l=l.slice().reverse());let b=l.length;if(G&&b&&l[b-1]&128){switch(b){case 0:return UA(0);case 1:return UA((l[0]^255)*-1-1);case 2:return UA((l[0]+(l[1]<<8)^65535)*-1-1);case 4:return UA((l[0]+(l[1]<<8)+(l[2]<<16)+l[3]*16777216^4294967295)*-1-1)}let c=new DataView(l.buffer,l.byteOffset);if(b===8)return c.getBigInt64(0,!0);let B=UA(0),e=b%2;for(let d=b-2;d>=e;d-=2)B=B*hV+UA(c.getUint16(d,!0)^65535);return e&&(B=B*oV+UA(l[0]^255)),B*-GZ-GZ}switch(b){case 0:return UA(0);case 1:return UA(l[0]);case 2:return UA(l[0]+(l[1]<<8));case 4:return UA(l[0]+(l[1]<<8)+(l[2]<<16)+l[3]*16777216)}let t=new DataView(l.buffer,l.byteOffset);switch(b){case 8:return t.getBigUint64(0,!0);case 16:return t.getBigUint64(8,!0)*CE+t.getBigUint64(0,!0);default:{let c=UA(0),B=b%2;for(let e=b-2;e>=B;e-=2)c=c*hV+UA(t.getUint16(e,!0));return B&&(c=c*oV+UA(l[0])),c}}}var Do="0123456789abcdef",Fa=new Uint8Array(256),sV=new Uint8Array(256*256);for(let l=0,A=Do.length;l<A;l++)Fa[Do[l].charCodeAt(0)|0]=l|0,l>9&&(Fa[Do[l].toUpperCase().charCodeAt(0)|0]=l|0);for(let l=0;l<256;l++){let A=l<<8;for(let G=0;G<256;G++)sV[A|G]=Fa[l]<<4|Fa[G]}function vb(l,A=-1){if(!l)return new Uint8Array;let G=l.startsWith("0x")?2:0,b=Math.ceil((l.length-G)/2),t=Math.ceil(A===-1?b:A/8),c=new Uint8Array(t),B=t>b?t-b:0;for(let e=B;e<t;e++,G+=2)c[e]=sV[l.charCodeAt(G)<<8|l.charCodeAt(G+1)];return c}function rV(l,{isLe:A=!1,isNegative:G=!1}={}){return!l||l==="0x"?UA(0):bZ(vb(l),{isLe:A,isNegative:G})}var pA=po(mV(),1);function vd(l){return pA.default.isBN(l)}var Oo=/^0x[\da-fA-F]+$/,VV=/^[\da-fA-F]+$/;function Vb(l,A=-1,G){return typeof l=="string"&&(l==="0x"||Oo.test(l))&&(A===-1?G||l.length%2===0:l.length===2+Math.ceil(A/4))}function uV(l){return!!l&&typeof l=="object"}function ya(...l){return A=>(uV(A)||Ed(A))&&l.every(G=>Ed(A[G]))}var Qa=ya("toBigInt");var Na=ya("toBn");function YV(l){return typeof l=="bigint"?l:l?Vb(l)?rV(l.toString()):vd(l)?UA(l.toString()):Qa(l)?l.toBigInt():Na(l)?UA(l.toBn().toString()):UA(l):UA(0)}var PA=typeof UA=="function"&&typeof UA.asIntN=="function";var IV=typeof ec.Buffer=="function"&&typeof ec.Buffer.isBuffer=="function",Nk=typeof ec.process=="object";function RV(l){return IV&&!!l&&Ed(l.readDoubleLE)&&ec.Buffer.isBuffer(l)}function Hb(l){return(l&&l.constructor)===Uint8Array||l instanceof Uint8Array}var SE=new gV;function uG(l){return l?SE.encode(l.toString()):new Uint8Array}function Tl(l,A=!1){if(A&&l==null)throw new Error("u8aToU8a: Expected non-null, non-undefined value");return Hb(l)?RV(l)?new Uint8Array(l):l:Vb(l)?vb(l):Array.isArray(l)?new Uint8Array(l):uG(l)}function nG(...l){let A=l.length,G=new Array(A),b=0;for(let t=0;t<A;t++)G[t]=Tl(l[t]),b+=G[t].length;return Zc(G,b)}function Zc(l,A=0){let G=l.length,b=0;if(!A)for(let c=0;c<G;c++)A+=l[c].length;let t=new Uint8Array(A);for(let c=0;c<G;c++)t.set(l[c],b),b+=l[c].length;return t}function Hd(l){let A=l.length|0;for(let G=0;G<A;G++)if(l[G]|0)return!1;return!0}function jb(l,A){let G=Tl(l),b=Tl(A);if(G.length===b.length){let t=new DataView(G.buffer,G.byteOffset),c=new DataView(b.buffer,b.byteOffset),B=G.length%4|0,e=G.length-B|0;for(let d=0;d<e;d+=4)if(t.getUint32(d)!==c.getUint32(d))return!1;for(let d=e,Z=G.length;d<Z;d++)if(G[d]!==b[d])return!1;return!0}return!1}function Po(l,A=-1,G=!1){let b=Math.ceil(A/8);if(A===-1||l.length===b)return l;if(l.length>b)return l.subarray(0,b);let t=new Uint8Array(b);return t.set(l,G?0:b-l.length),t}function Jd(l,{isLe:A=!0,isNegative:G=!1}={}){A||(l=l.slice().reverse());let b=l.length;if(G&&b&&l[b-1]&128)switch(b){case 0:return new pA.default(0);case 1:return new pA.default((l[0]^255)*-1-1);case 2:return new pA.default((l[0]+(l[1]<<8)^65535)*-1-1);case 3:return new pA.default((l[0]+(l[1]<<8)+(l[2]<<16)^16777215)*-1-1);case 4:return new pA.default((l[0]+(l[1]<<8)+(l[2]<<16)+l[3]*16777216^4294967295)*-1-1);case 5:return new pA.default(((l[0]+(l[1]<<8)+(l[2]<<16)+l[3]*16777216^4294967295)+(l[4]^255)*4294967296)*-1-1);case 6:return new pA.default(((l[0]+(l[1]<<8)+(l[2]<<16)+l[3]*16777216^4294967295)+(l[4]+(l[5]<<8)^65535)*4294967296)*-1-1);default:return new pA.default(l,"le").fromTwos(b*8)}switch(b){case 0:return new pA.default(0);case 1:return new pA.default(l[0]);case 2:return new pA.default(l[0]+(l[1]<<8));case 3:return new pA.default(l[0]+(l[1]<<8)+(l[2]<<16));case 4:return new pA.default(l[0]+(l[1]<<8)+(l[2]<<16)+l[3]*16777216);case 5:return new pA.default(l[0]+(l[1]<<8)+(l[2]<<16)+(l[3]+(l[4]<<8))*16777216);case 6:return new pA.default(l[0]+(l[1]<<8)+(l[2]<<16)+(l[3]+(l[4]<<8)+(l[5]<<16))*16777216);default:return new pA.default(l,"le")}}var Ea=new Array(256),XV=new Array(256*256);for(let l=0;l<256;l++)Ea[l]=l.toString(16).padStart(2,"0");for(let l=0;l<256;l++){let A=l<<8;for(let G=0;G<256;G++)XV[A|G]=Ea[l]+Ea[G]}function Ko(l,A){let G=l.length%2|0,b=l.length-G|0;for(let t=0;t<b;t+=2)A+=XV[l[t]<<8|l[t+1]];return G&&(A+=Ea[l[b]|0]),A}function dt(l,A=-1,G=!0){let b=G?"0x":"";if(l?.length){if(A>0){let t=Math.ceil(A/8);if(l.length>t)return`${Ko(l.subarray(0,t/2),b)}\u2026${Ko(l.subarray(l.length-t/2),"")}`}}else return b;return Ko(l,b)}var zE=new aV("utf-8");function va(l){return l?zE.decode(l):""}var Ha=Tl(`Ethereum Signed Message:
305
- `),tZ=Tl("<Bytes>"),cZ=Tl("</Bytes>"),jE=tZ.length+cZ.length;function BZ(l,A){return l.length>=jE&&jb(l.subarray(0,tZ.length),tZ)&&jb(l.slice(-cZ.length),cZ)||A&&l.length>=Ha.length&&jb(l.subarray(0,Ha.length),Ha)}function qo(l){let A=Tl(l);return BZ(A,!1)?A.subarray(tZ.length,A.length-cZ.length):A}function _o(l){let A=Tl(l);return BZ(A,!0)?A:Zc([tZ,A,cZ])}var pV=UA(256),ME=UA(255);function TE(l,A,G){let b=[],t=G&&l<AZ;for(t&&(l=(l+GZ)*-GZ);l!==AZ;){let c=l%pV,B=Number(t?c^ME:c);A?b.push(B):b.unshift(B),l=(l-c)/pV}return Uint8Array.from(b)}function $o(l,{bitLength:A=-1,isLe:G=!0,isNegative:b=!1}={}){let t=YV(l);if(t===AZ)return A===-1?new Uint8Array(1):new Uint8Array(Math.ceil((A||0)/8));let c=TE(t,G,b);if(A===-1)return c;let B=Math.ceil((A||0)/8),e=new Uint8Array(B);return b&&e.fill(255),e.set(c,G?0:B-c.length),e}function FV(l){if(!l||l==="0x")return"";if(Oo.test(l))return l.substring(2);if(VV.test(l))return l;throw new Error(`Expected hex value to convert, found '${l}'`)}function yV(l,{isLe:A=!1,isNegative:G=!1}={}){if(!l||l==="0x")return new pA.default(0);let b=FV(l),t=new pA.default(b,16,A?"le":"be");return G?t.fromTwos(b.length*4):t}var xd=new pA.default(1),fd=new pA.default(2);var QV=new pA.default(1e9),Ew=QV.mul(QV),vw=new pA.default(Number.MAX_SAFE_INTEGER);function kd(l){return typeof l=="bigint"}function wd(l){return l?pA.default.isBN(l)?l:Vb(l)?yV(l.toString()):kd(l)?new pA.default(l.toString()):Na(l)?l.toBn():Qa(l)?new pA.default(l.toBigInt().toString()):new pA.default(l):new pA.default(0)}var DE={bitLength:-1,isLe:!0,isNegative:!1};function kG(l,{bitLength:A=-1,isLe:G=!0,isNegative:b=!1}=DE){let t=wd(l),c=Math.ceil(A===-1?t.bitLength()/8:(A||0)/8);if(!l)return A===-1?new Uint8Array(1):new Uint8Array(c);let B=new Uint8Array(c),e=b?t.toTwos(c*8):t;return B.set(e.toArray(G?"le":"be",c),0),B}var LE=fd.pow(new pA.default(6)).isub(xd),OE=fd.pow(new pA.default(14)).isub(xd),PE=fd.pow(new pA.default(30)).isub(xd),KE={bitLength:16},qE={bitLength:32};function NV(l){let A=wd(l);if(A.lte(LE))return new Uint8Array([A.toNumber()<<2]);if(A.lte(OE))return kG(A.shln(2).iadd(xd),KE);if(A.lte(PE))return kG(A.shln(2).iadd(fd),qE);let G=kG(A),b=G.length;for(;G[b-1]===0;)b--;if(b<4)throw new Error("Invalid length, previous checks match anything less than 2^30");return Zc([new Uint8Array([(b-4<<2)+3]),G.subarray(0,b)])}function be(l){return Zc([NV(l.length),l])}function lh(l){return typeof l=="string"||l instanceof String}function Ah(l){return typeof l=="number"}function te(l,...A){let G=new Set(["__proto__","constructor","prototype"]);for(let b=0,t=A.length;b<t;b++){let c=A[b];if(c)if(typeof c.entries=="function")for(let[B,e]of c.entries())G.has(B)||(l[B]=e);else{let B=Object.create(null);for(let[e,d]of Object.entries(c))G.has(e)||(B[e]=d);Object.assign(l,B)}}return l}var _E=ec.crypto;function Ja(l){return _E.getRandomValues(l)}var xa={getRandomValues:Ja},$E={crypto:xa},pt,fa=class{constructor(A){EG(this,pt);el(this,"abort",()=>{throw new Error("abort")});el(this,"__wbindgen_is_undefined",A=>GA(this,pt).getObject(A)===void 0);el(this,"__wbindgen_throw",(A,G)=>{throw new Error(GA(this,pt).getString(A,G))});el(this,"__wbg_self_1b7a39e3a92c949c",()=>GA(this,pt).addObject($E));el(this,"__wbg_require_604837428532a733",(A,G)=>{throw new Error(`Unable to require ${GA(this,pt).getString(A,G)}`)});el(this,"__wbg_crypto_968f1772287e2df0",A=>GA(this,pt).addObject(xa));el(this,"__wbg_getRandomValues_a3d34b4fee3c2869",A=>GA(this,pt).addObject(xa.getRandomValues));el(this,"__wbg_getRandomValues_f5e14ab7ac8e995d",(A,G,b)=>{xa.getRandomValues(GA(this,pt).getU8a(G,b))});el(this,"__wbg_randomFillSync_d5bd2d655fdf256a",(A,G,b)=>{throw new Error("randomFillsync is not available")});el(this,"__wbindgen_object_drop_ref",A=>{GA(this,pt).takeObject(A)});bG(this,pt,A)}};pt=new WeakMap;var Ud,Ft,Cd,sB,rB,Hc,nt,eZ,ce,ZZ,ka=class{constructor(A){EG(this,Ud);EG(this,Ft);EG(this,Cd);EG(this,sB);EG(this,rB);EG(this,Hc);EG(this,nt);EG(this,eZ);EG(this,ce);EG(this,ZZ);bG(this,Ud,A),bG(this,sB,null),bG(this,rB,null),bG(this,Ft,new Array(32).fill(void 0).concat(void 0,null,!0,!1)),bG(this,Hc,GA(this,Ft).length),bG(this,ZZ,"none"),bG(this,nt,null),bG(this,eZ,null),bG(this,ce,null),bG(this,Cd,{...new fa(this)})}get error(){return GA(this,eZ)}get type(){return GA(this,ZZ)}get wasm(){return GA(this,nt)}async init(A){(!GA(this,ce)||A)&&bG(this,ce,(A||GA(this,Ud))(GA(this,Cd)));let{error:G,type:b,wasm:t}=await GA(this,ce);return bG(this,ZZ,b),bG(this,nt,t),bG(this,eZ,G),GA(this,nt)}getObject(A){return GA(this,Ft)[A]}dropObject(A){A<36||(GA(this,Ft)[A]=GA(this,Hc),bG(this,Hc,A))}takeObject(A){let G=this.getObject(A);return this.dropObject(A),G}addObject(A){GA(this,Hc)===GA(this,Ft).length&&GA(this,Ft).push(GA(this,Ft).length+1);let G=GA(this,Hc);return bG(this,Hc,GA(this,Ft)[G]),GA(this,Ft)[G]=A,G}getInt32(){return(GA(this,sB)===null||GA(this,sB).buffer!==GA(this,nt).memory.buffer)&&bG(this,sB,new Int32Array(GA(this,nt).memory.buffer)),GA(this,sB)}getUint8(){return(GA(this,rB)===null||GA(this,rB).buffer!==GA(this,nt).memory.buffer)&&bG(this,rB,new Uint8Array(GA(this,nt).memory.buffer)),GA(this,rB)}getU8a(A,G){return this.getUint8().subarray(A/1,A/1+G)}getString(A,G){return va(this.getU8a(A,G))}allocU8a(A){let G=GA(this,nt).__wbindgen_malloc(A.length*1);return this.getUint8().set(A,G/1),[G,A.length]}allocString(A){return this.allocU8a(uG(A))}resultU8a(){let A=this.getInt32()[2],G=this.getInt32()[8/4+1],b=this.getU8a(A,G).slice();return GA(this,nt).__wbindgen_free(A,G*1),b}resultString(){return va(this.resultU8a())}};Ud=new WeakMap,Ft=new WeakMap,Cd=new WeakMap,sB=new WeakMap,rB=new WeakMap,Hc=new WeakMap,nt=new WeakMap,eZ=new WeakMap,ce=new WeakMap,ZZ=new WeakMap;function EV(l,A,G){return async b=>{let t={error:null,type:"none",wasm:null};try{if(A?.length){if(typeof WebAssembly!="object"||typeof WebAssembly.instantiate!="function")throw new Error("WebAssembly is not available in your environment")}else throw new Error("No WebAssembly provided for initialization");let c=await WebAssembly.instantiate(A,{wbg:b});t.wasm=c.instance.exports,t.type="wasm"}catch(c){typeof G=="function"?(t.wasm=G(b),t.type="asm"):(t.error=`FATAL: Unable to initialize @polkadot/wasm-${l}:: ${c.message}`,console.error(t.error))}return t}}var vV="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",HV=new Array(256);for(let l=0,A=vV.length;l<A;l++)HV[vV.charCodeAt(l)]=l;function Gh(l,A){let G=0,b=0,t=-1;for(let c=0,B=A.length-1;t!==B;c++)G=G<<6|HV[l.charCodeAt(c)],(b+=6)>=8&&(A[++t]=G>>>(b-=8)&255);return A}var dc=Uint8Array,iB=Uint16Array,ch=Uint32Array,lv=new dc([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),JV=new dc([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),xV=new dc([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),fV=(l,A)=>{let G=new iB(31);for(let t=0;t<31;++t)G[t]=A+=1<<l[t-1];let b=new ch(G[30]);for(let t=1;t<30;++t)for(let c=G[t];c<G[t+1];++c)b[c]=c-G[t]<<5|t;return[G,b]},[kV,Av]=fV(JV,2);kV[28]=258,Av[258]=28;var[Gv]=fV(xV,0),Bh=new iB(32768);for(let l=0;l<32768;++l){let A=(l&43690)>>>1|(l&21845)<<1;A=(A&52428)>>>2|(A&13107)<<2,A=(A&61680)>>>4|(A&3855)<<4,Bh[l]=((A&65280)>>>8|(A&255)<<8)>>>1}var Sd=(l,A,G)=>{let b=l.length,t=0,c=new iB(A);for(;t<b;++t)l[t]&&++c[l[t]-1];let B=new iB(A);for(t=1;t<A;++t)B[t]=B[t-1]+c[t-1]<<1;let e;if(G){e=new iB(1<<A);let d=15-A;for(t=0;t<b;++t)if(l[t]){let Z=t<<4|l[t],g=A-l[t],n=B[l[t]-1]++<<g;for(let h=n|(1<<g)-1;n<=h;++n)e[Bh[n]>>d]=Z}}else for(e=new iB(b),t=0;t<b;++t)l[t]&&(e[t]=Bh[B[l[t]-1]++]>>15-l[t]);return e},zd=new dc(288);for(let l=0;l<144;++l)zd[l]=8;for(let l=144;l<256;++l)zd[l]=9;for(let l=256;l<280;++l)zd[l]=7;for(let l=280;l<288;++l)zd[l]=8;var wV=new dc(32);for(let l=0;l<32;++l)wV[l]=5;var bv=Sd(zd,9,1),tv=Sd(wV,5,1),wt=(l,A,G)=>{let b=A>>>3;return(l[b]|l[b+1]<<8)>>>(A&7)&G},bh=(l,A)=>{let G=A>>>3;return(l[G]|l[G+1]<<8|l[G+2]<<16)>>>(A&7)},cv=l=>(l>>>3)+(l&7&&1),Bv=(l,A,G)=>{(A==null||A<0)&&(A=0),(G==null||G>l.length)&&(G=l.length);let b=new(l instanceof iB?iB:l instanceof ch?ch:dc)(G-A);return b.set(l.subarray(A,G)),b},th=l=>{let A=l[0];for(let G=1,b=l.length;G<b;++G)l[G]>A&&(A=l[G]);return A},ev=(l,A,G)=>{let b=!G||G.i;G||(G={});let t=l.length,c=!A||!b;A||(A=new dc(t*3));let B=Y=>{let R=A.length;if(Y>R){let u=new dc(Math.max(R<<1,Y));u.set(A),A=u}},e=G.f||0,d=G.p||0,Z=G.b||0,g=G.l,n=G.d,h=G.m,W=G.n;if(e&&!g)return A;let m=t<<3;do{if(!g){G.f=e=wt(l,d,1);let i=wt(l,d+1,3);if(d+=3,i)if(i==1)g=bv,n=tv,h=9,W=5;else if(i==2){let I=wt(l,d,31)+257,Q=wt(l,d+10,15)+4,f=I+wt(l,d+5,31)+1;d+=14;let U=new dc(f),J=new dc(19);for(let y=0;y<Q;++y)J[lv[y]]=wt(l,d+y*3,7);d+=Q*3;let M=th(J),C=(1<<M)-1;if(!b&&d+f*(M+7)>m)break;let D=Sd(J,M,1);for(let y=0;y<f;){let r=D[wt(l,d,C)];d+=r&15;let F=r>>>4;if(F<16)U[y++]=F;else{let E=0,x=0;for(F==16?(x=3+wt(l,d,3),d+=2,E=U[y-1]):F==17?(x=3+wt(l,d,7),d+=3):F==18&&(x=11+wt(l,d,127),d+=7);x--;)U[y++]=E}}let $=U.subarray(0,I),K=U.subarray(I);h=th($),W=th(K),g=Sd($,h,1),n=Sd(K,W,1)}else throw"invalid block type";else{let I=cv(d)+4,Q=l[I-4]|l[I-3]<<8,f=I+Q;if(f>t){if(b)throw"unexpected EOF";break}c&&B(Z+Q),A.set(l.subarray(I,f),Z),G.b=Z+=Q,G.p=d=f<<3;continue}if(d>m)throw"unexpected EOF"}c&&B(Z+131072);let Y=(1<<h)-1,R=(1<<W)-1,u=h+W+18;for(;b||d+u<m;){let i=g[bh(l,d)&Y],I=i>>>4;if(d+=i&15,d>m)throw"unexpected EOF";if(!i)throw"invalid length/literal";if(I<256)A[Z++]=I;else if(I==256){g=void 0;break}else{let Q=I-254;if(I>264){let C=I-257,D=JV[C];Q=wt(l,d,(1<<D)-1)+kV[C],d+=D}let f=n[bh(l,d)&R],U=f>>>4;if(!f)throw"invalid distance";d+=f&15;let J=Gv[U];if(U>3){let C=xV[U];J+=bh(l,d)&(1<<C)-1,d+=C}if(d>m)throw"unexpected EOF";c&&B(Z+131072);let M=Z+Q;for(;Z<M;Z+=4)A[Z]=A[Z-J],A[Z+1]=A[Z+1-J],A[Z+2]=A[Z+2-J],A[Z+3]=A[Z+3-J];Z=M}}G.l=g,G.p=d,G.b=Z,g&&(e=1,G.m=h,G.d=n,G.n=W)}while(!e);return Z==A.length?A:Bv(A,0,Z)},Zv=l=>{if((l[0]&15)!=8||l[0]>>>4>7||(l[0]<<8|l[1])%31)throw"invalid zlib data";if(l[1]&32)throw"invalid zlib data: preset dictionaries not supported"};function eh(l,A){return ev((Zv(l),l.subarray(2,-4)),A)}var dZ=po(UV(),1);var CV=eh(Gh(dZ.bytes,new Uint8Array(dZ.lenIn)),new Uint8Array(dZ.lenOut));var SV=EV("crypto",CV,null);var cA=new ka(SV);async function zV(l){return cA.init(l)}function wG(l){return(...A)=>{if(!cA.wasm)throw new Error("The WASM interface has not been initialized. Ensure that you wait for the initialization Promise with waitReady() from @polkadot/wasm-crypto (or cryptoWaitReady() from @polkadot/util-crypto) before attempting to use WASM-only interfaces.");return l(cA.wasm,...A)}}var jV=wG((l,A)=>(l.ext_bip39_to_entropy(8,...cA.allocString(A)),cA.resultU8a())),MV=wG((l,A,G)=>(l.ext_bip39_to_mini_secret(8,...cA.allocString(A),...cA.allocString(G)),cA.resultU8a())),TV=wG((l,A,G)=>(l.ext_bip39_to_seed(8,...cA.allocString(A),...cA.allocString(G)),cA.resultU8a())),DV=wG((l,A)=>l.ext_bip39_validate(...cA.allocString(A))!==0),LV=wG((l,A)=>(l.ext_ed_from_seed(8,...cA.allocU8a(A)),cA.resultU8a())),OV=wG((l,A,G,b)=>(l.ext_ed_sign(8,...cA.allocU8a(A),...cA.allocU8a(G),...cA.allocU8a(b)),cA.resultU8a())),PV=wG((l,A,G,b)=>l.ext_ed_verify(...cA.allocU8a(A),...cA.allocU8a(G),...cA.allocU8a(b))!==0),KV=wG((l,A)=>(l.ext_secp_from_seed(8,...cA.allocU8a(A)),cA.resultU8a())),qV=wG((l,A)=>(l.ext_secp_pub_compress(8,...cA.allocU8a(A)),cA.resultU8a())),_V=wG((l,A)=>(l.ext_secp_pub_expand(8,...cA.allocU8a(A)),cA.resultU8a())),$V=wG((l,A,G,b)=>(l.ext_secp_recover(8,...cA.allocU8a(A),...cA.allocU8a(G),b),cA.resultU8a())),lu=wG((l,A,G)=>(l.ext_secp_sign(8,...cA.allocU8a(A),...cA.allocU8a(G)),cA.resultU8a()));var Au=wG((l,A,G,b)=>(l.ext_blake2b(8,...cA.allocU8a(A),...cA.allocU8a(G),b),cA.resultU8a())),Gu=wG((l,A,G)=>(l.ext_hmac_sha256(8,...cA.allocU8a(A),...cA.allocU8a(G)),cA.resultU8a())),bu=wG((l,A,G)=>(l.ext_hmac_sha512(8,...cA.allocU8a(A),...cA.allocU8a(G)),cA.resultU8a())),tu=wG((l,A)=>(l.ext_keccak256(8,...cA.allocU8a(A)),cA.resultU8a())),cu=wG((l,A)=>(l.ext_keccak512(8,...cA.allocU8a(A)),cA.resultU8a())),Bu=wG((l,A,G,b)=>(l.ext_pbkdf2(8,...cA.allocU8a(A),...cA.allocU8a(G),b),cA.resultU8a())),eu=wG((l,A,G,b,t,c)=>(l.ext_scrypt(8,...cA.allocU8a(A),...cA.allocU8a(G),b,t,c),cA.resultU8a())),Zu=wG((l,A)=>(l.ext_sha256(8,...cA.allocU8a(A)),cA.resultU8a())),du=wG((l,A)=>(l.ext_sha512(8,...cA.allocU8a(A)),cA.resultU8a()));function TA(){return!!cA.wasm}async function nu(){try{return!!await zV()}catch{return!1}}function Zh(l){return(...A)=>dt(l(...A))}function dh(l,A){return(G,b)=>A(G,l,b)}function Ua(l,A){return(G,b=256,t)=>{let c=Tl(G);return!PA||!t&&TA()?l[b](c):A[b](c)}}function Mb(l,A=256,G,b){let t=Math.ceil(A/8),c=Tl(l);return!PA||!b&&TA()?Au(c,Tl(G),t):G?To(c,{dkLen:t,key:G}):To(c,{dkLen:t})}var nh=Zh(Mb);var gu=new TextEncoder,dv=new TextDecoder,Ca="cere.vault.grant.v1",mB="cere.vault.grant.v2",Be="",nZ=["public","internal","private","restricted"];function aZ(l){return nZ.includes(l)}function Wu(){let l=nZ.map(A=>`"${A}"`);return l.slice(0,-1).join(", ")+" or "+l[l.length-1]}var Sa="X-Grant-Signature",ah="X-Grant-Issued-At";function Ut(l){let A=l.startsWith("0x")?l.slice(2):l;return A.startsWith("0X")&&(A=A.slice(2)),A=A.toLowerCase(),A===""||A.length%2!==0||!/^[0-9a-f]+$/.test(A)?l:`0x${A}`}function gh(l){let A=Ut(l);return`v-${nh(gu.encode(A),128).slice(2)}`}var za="";var lb=class extends Error{constructor(G,b=""){super(G);el(this,"memberPubkey");this.memberPubkey=b,this.name="GrantVerificationError"}};function Wh(l,A,G,b,t,c){return ja(l,A,G,b,t,c,Be)}function ja(l,A,G,b,t,c,B){if(l==="")throw new Error("canonical grant: vaultId is required");if(A==="")throw new Error("canonical grant: memberPubkey is required");if(G==="")throw new Error("canonical grant: role is required");if(t==="")throw new Error("canonical grant: issuedAt is required");let e=Ca;if(B!==Be){if(!aZ(B))throw new Error(`canonical grant: privacyCeiling ${JSON.stringify(B)} must be ${Wu()}`);e=mB}let Z=Object.keys(b).sort(nv).map(n=>`{"name":${xc(n)},"level":${xc(b[n])}}`),g=`{"schema":${xc(e)},"vaultId":${xc(l)},"memberPubkey":${xc(A)},"role":${xc(G)},"scopes":[${Z.join(",")}],"issuedAt":${xc(t)},"expiresAt":${xc(c)}`+(B===Be?"":`,"privacyCeiling":${xc(B)}`)+"}";return gu.encode(g)}function ou(l){if(l.length===0)throw new Error("decode grant: empty document");let A;try{A=JSON.parse(dv.decode(l))}catch(W){throw new Error(`decode grant: ${W instanceof Error?W.message:String(W)}`)}if(typeof A!="object"||A===null||Array.isArray(A))throw new Error("decode grant: document is not a JSON object");let G=A,b=Jc(G,"schema"),t=Jc(G,"privacyCeiling",!0);if(b===Ca){if(t!=="")throw new Error(`decode grant: schema ${JSON.stringify(b)} carries a privacyCeiling; that is ${JSON.stringify(mB)}`)}else if(b===mB){if(!aZ(t))throw new Error(`decode grant: schema ${JSON.stringify(b)} requires a privacyCeiling of ${Wu()}, got ${JSON.stringify(t)}`)}else throw new Error(`decode grant: schema ${JSON.stringify(b)} is not ${JSON.stringify(Ca)} or ${JSON.stringify(mB)}`);let c=Jc(G,"vaultId"),B=Jc(G,"memberPubkey"),e=Jc(G,"role");if(c===""||B===""||e==="")throw new Error("decode grant: vaultId, memberPubkey and role are all required");let d=G.scopes;if(!Array.isArray(d))throw new Error("decode grant: scopes must be an array");let Z={};for(let W of d){if(typeof W!="object"||W===null||Array.isArray(W))throw new Error("decode grant: a scope entry is not an object");let m=Jc(W,"name");if(m==="")throw new Error("decode grant: a scope with no name");Z[m]=Jc(W,"level")}let g=Jc(G,"issuedAt");if(g==="")throw new Error("decode grant: issuedAt is required");let n=Jc(G,"expiresAt");return{schema:b,vaultId:c,memberPubkey:B,role:e,scopes:Z,issuedAt:g,expiresAt:n,privacyCeiling:b===mB?t:""}}async function hu(l,A,G){if(A.length===0||G==="")return!1;let b,t;try{b=Te(Yt(l).toLowerCase()),t=Te(Yt(G).toLowerCase())}catch{return!1}if(b.length!==32||t.length!==64)return!1;try{return await z2(t,A,b)}catch{return!1}}async function oh(l,A,G={}){if(typeof A!="string"||A==="")throw new lb("expectedVaultId is required: verifying a roster against the vault id it carries only proves the response agrees with itself");if(typeof l!="object"||l===null)throw new lb(`signed roster is not an object (got ${au(l)})`);if(typeof l.vaultId!="string"||l.vaultId==="")throw new lb("signed roster carries no vaultId");if(typeof l.orgWalletPubkey!="string"||l.orgWalletPubkey==="")throw new lb("signed roster carries no orgWalletPubkey");if(!Array.isArray(l.grants))throw new lb(`signed roster's grants is not an array (got ${au(l.grants)})`);if(l.vaultId!==A)throw new lb(`signed roster names vault ${l.vaultId}, asked about ${A}`);if(gh(l.orgWalletPubkey)!==A)throw new lb(`orgWalletPubkey ${l.orgWalletPubkey} does not derive vault ${A}`);let b=[];for(let t of l.grants){if(typeof t!="object"||t===null){let c=new lb("signed roster holds a grant that is not an object");G.onUnverifiableGrant?.(c);continue}try{b.push(await su(A,l.orgWalletPubkey,t))}catch(c){if(!(c instanceof lb))throw c;G.onUnverifiableGrant?.(c)}}return b}function au(l){return l===null?"null":Array.isArray(l)?"an array":typeof l}async function su(l,A,G){if(gh(A)!==l)throw new lb(`orgWalletPubkey ${A} does not derive vault ${l}`,G.memberPubkey);let b;try{b=y2(G.doc)}catch(c){throw new lb(`grant document is not valid base64: ${c instanceof Error?c.message:String(c)}`,G.memberPubkey)}if(!await hu(A,b,G.sig))throw new lb(`grant document is not signed by the vault owner (${A})`,G.memberPubkey);let t;try{t=ou(b)}catch(c){throw new lb(c instanceof Error?c.message:String(c),G.memberPubkey)}if(t.vaultId!==l||t.memberPubkey!==G.memberPubkey)throw new lb(`grant document describes a different membership: it names ${t.memberPubkey} on ${t.vaultId}, and was served as ${G.memberPubkey} on ${l}`,G.memberPubkey);return t}function Jc(l,A,G=!1){let b=l[A];if(b===void 0&&G)return"";if(typeof b!="string")throw new Error(`decode grant: ${A} must be a string, got ${b===void 0?"nothing":typeof b}`);return b}function xc(l){return JSON.stringify(l).replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function nv(l,A){let G=Array.from(l),b=Array.from(A),t=Math.min(G.length,b.length);for(let c=0;c<t;c++){let B=G[c].codePointAt(0),e=b[c].codePointAt(0);if(B!==e)return B-e}return G.length-b.length}var Ma=class{constructor(A,G){el(this,"http");el(this,"signer");this.http=A,this.signer=G}mine(){return this.http.send("GET",kl.memberships())}list(A){return this.http.send("GET",kl.vaultMembers(A))}signedRoster(A){return this.http.send("GET",kl.vaultSignedRoster(A))}async put(A,G,b,t,c={}){let B=c.privacyCeiling===void 0?void 0:c.privacyCeiling;if(B!==void 0&&!aZ(B))throw new Error(`put: privacyCeiling ${JSON.stringify(B)} must be one of `+nZ.map(Z=>`"${Z}"`).join(", "));let e=c.scopes??await this.heldScopes(A,G),d=t===void 0?za:t;return this.http.send("PUT",kl.vaultMember(A,G),{body:{role:b,expiresAt:t,...B===void 0?{}:{privacyCeiling:B},timestamp:new Date().toISOString()},headers:await this.grantHeader(A,G,b,e,d,B)})}remove(A,G){return this.http.send("DELETE",kl.vaultMember(A,G),{body:{timestamp:new Date().toISOString()}})}scopes(A,G){return this.http.send("GET",kl.vaultMemberScopes(A,G))}async putScopes(A,G,b,t={}){this.grantSigner();let c=t.standing?.privacyCeiling;if(c!==void 0&&c!==Be&&!aZ(c))throw new Error(`putScopes: standing.privacyCeiling ${JSON.stringify(c)} must be one of `+nZ.map(Z=>`"${Z}"`).join(", ")+", or NO_PRIVACY_CEILING for a member who holds none");let B=t.standing??await this.heldStanding(A,G),e=c??await this.heldCeiling(A,G),d=B.expiresAt===void 0?za:B.expiresAt;try{return await this.http.send("PUT",kl.vaultMemberScopes(A,G),{body:{scopes:b,expiresAt:B.expiresAt,timestamp:new Date().toISOString()},headers:await this.grantHeader(A,G,B.role,b,d,e===void 0||e===Be?void 0:e)})}catch(Z){if(e===void 0&&Z instanceof _G&&Z.status===400&&Z.message.includes(mB)){let g=Ut(G);throw new Xd(`putScopes: ${g} is not in ${A}'s signed roster (it serves live memberships only), so the grant was signed with no privacy ceiling, and vault-api refused it because this member holds one. Nothing was written. Pass \`{ standing: { role, expiresAt, privacyCeiling } }\` with the ceiling the member holds. Server said: ${Z.message}`,g,Z.status,Z.code)}throw Z}}async grantHeader(A,G,b,t,c,B){let e=this.grantSigner(),d=new Date().toISOString(),Z=B===void 0?Wh(A,Ut(G),b,t,d,c):ja(A,Ut(G),b,t,d,c,B);return{[Sa]:Kb(await e.sign(Z,"data")),[ah]:d}}grantSigner(){let A=this.signer;if(A===void 0||typeof A.sign!="function")throw new It(`A membership write must carry the VAULT OWNER's signature over the grant's canonical document, in the ${Sa} header. Construct the SDK with \`signer\` set to the vault owner's key (\`new VaultSDK({ endpoint, signer })\`); a custom \`auth\` provider authenticates the request but cannot sign the grant, because the two cover different bytes.`);if(A.type!=="ed25519")throw new It(`A grant signature must be ed25519 \u2014 vault-api verifies it with SchemeEd25519 and nothing else \u2014 but this signer is "${A.type}". An sr25519 key can authenticate the request and still never authorise the grant.`);return A}async heldCeiling(A,G){let b=Ut(G),t=[],B=(await oh(await this.signedRoster(A),A,{onUnverifiableGrant:d=>t.push(d)})).find(d=>Ut(d.memberPubkey)===b);if(B!==void 0)return B.privacyCeiling;let e=t.find(d=>d.memberPubkey!==""&&Ut(d.memberPubkey)===b);if(e!==void 0)throw new lb(`putScopes: ${b}'s grant in the signed roster of ${A} failed verification (${e.message}), so the privacy ceiling it holds is unknown and no grant document can be signed for it.`,e.memberPubkey)}async heldScopes(A,G){try{return(await this.scopes(A,G)).scopes}catch(b){if(b instanceof _G&&b.status===404)return{};throw b}}async heldStanding(A,G){let b=Ut(G),t=(await this.list(A)).find(c=>c.isOwner!==!0&&Ut(c.memberPubkey)===b);if(t===void 0)throw new Error(`putScopes: ${b} has no membership row on ${A}, so there is no role or expiry to put in the grant document. Add the member first (\`memberships.put\`), or pass \`{ standing: { role, expiresAt } }\` if you already know them.`);return{role:t.role,expiresAt:t.expiresAt}}};var ru=new bt,Ta=class{constructor(A){el(this,"http");this.http=A}getAgent(A,G){let b=G?kl.marketplaceAgentVersion(A,G):kl.marketplaceAgent(A);return this.http.send("GET",b,{auth:ru})}async list(A={}){let G=await this.http.send("GET",kl.marketplaceAgents(),{auth:ru,query:{limit:A.limit,cursor:A.cursor,q:A.query}}),t={items:G.agents??G.items??[]};return G.nextCursor!==void 0&&(t.nextCursor=G.nextCursor),t}};var iu=new bt,Da=class{constructor(A){el(this,"http");this.http=A}live(){return this.http.send("GET",kl.health(),{auth:iu})}ready(){return this.http.send("GET",kl.ready(),{auth:iu})}};var La=class{constructor(A){el(this,"http");this.http=A}list(A){return this.http.send("GET",kl.scopes(A))}get(A,G){return this.http.send("GET",kl.scope(A,G))}create(A,G){return this.http.send("POST",kl.scopes(A),{body:mu(G)})}update(A,G,b){return this.http.send("PATCH",kl.scope(A,G),{body:mu(b)})}delete(A,G){return this.http.send("DELETE",kl.scope(A,G),{body:{}})}};function mu(l){let A={};return"name"in l&&l.name!==void 0&&(A.name=l.name),l.displayName!==void 0&&(A.displayName=l.displayName),l.streamLabel!==void 0&&(A.streamLabel=l.streamLabel),l.metadata!==void 0&&(A.metadata=l.metadata),A}function Vu(l,A){if(l.length>16)throw new Error(`[${A}] \`scopes\` has ${l.length} entries; the server refuses more than 16 \u2014 trim the set before calling`);for(let G of l)if(typeof G!="string"||G.trim().length===0)throw new Error(`[${A}] \`scopes\` contains an empty/blank entry (${JSON.stringify(G)}) \u2014 the server refuses an empty scope member`)}function gZ(l,A){let G=l.scope!==void 0,b=l.scopes!==void 0;if(G&&b)throw new Error(`[${A}] both \`scope\` (${JSON.stringify(l.scope)}) and \`scopes\` (${JSON.stringify(l.scopes)}) were supplied \u2014 these conflict and which one would apply is undefined; pass exactly one.`);if(b){if(!l.scopes||l.scopes.length===0)throw new Error(`[${A}] \`scopes\` must be a non-empty array`);return Vu(l.scopes,A),l.scopes}if(G)return Vu([l.scope],A),[l.scope];throw new Error(`[${A}] requires \`scope\` or a non-empty \`scopes\` array`)}var oZ=class{constructor(A){el(this,"http");this.http=A}async connect(A,G){let{ceiling:b,...t}=G,c=b===void 0?{...t}:{...t,ceiling:Oa(b)};return gZ(G,"Agents.connect"),this.http.send("POST",kl.agents(A),{body:c})}async list(A,G={}){return(await this.http.send("GET",kl.agents(A),{query:{status:G.status}})).items??[]}get(A,G){return this.http.send("GET",kl.agent(A,G))}update(A,G,b){return this.http.send("PATCH",kl.agent(A,G),{body:{settings:b}})}async setCeiling(A,G,b){let t=Oa(b);return this.http.send("PUT",kl.agentCeiling(A,G),{body:{...t}})}disconnect(A,G){return this.http.send("DELETE",kl.agent(A,G),{body:{}})}};function WZ(l){return new _G(`invalid ceiling: ${l}`,0,"BAD_REQUEST")}function Oa(l){if(l===null||typeof l!="object"||Array.isArray(l))throw WZ("expected an object { gpuUnits?, a2aTokens? }");for(let t of Object.keys(l))if(t!=="gpuUnits"&&t!=="a2aTokens")throw WZ(`unknown field ${JSON.stringify(t)} (expected { gpuUnits?, a2aTokens? })`);let A=t=>{let c=l[t];if(c===void 0)return 0;if(typeof c!="number"||!Number.isFinite(c))throw WZ(`${t} must be a finite number (got ${String(c)})`);if(c<0)throw WZ(`${t} must be >= 0 (got ${c})`);return c},G=A("gpuUnits"),b=A("a2aTokens");if(!Number.isInteger(b))throw WZ(`a2aTokens must be an integer (got ${b})`);if(b>Number.MAX_SAFE_INTEGER)throw WZ(`a2aTokens must be <= Number.MAX_SAFE_INTEGER (got ${b})`);return{gpuUnits:G,a2aTokens:b}}var yt=class{constructor(A){el(this,"http");this.http=A}listStreams(A,G,b={}){return this.http.send("GET",kl.scopeStreams(A,G),{query:{active:b.active}})}getStream(A,G,b){return this.http.send("GET",kl.stream(A,G,b))}listStreamEvents(A,G,b,t={}){return this.http.send("GET",kl.streamEvents(A,G,b),{query:{limit:t.limit,cursor:t.cursor}})}listJobs(A,G={}){return this.http.send("GET",kl.jobs(A),{query:{state:G.state,cursor:G.cursor,limit:G.limit}})}getJob(A,G){return this.http.send("GET",kl.job(A,G))}listAgentJobs(A,G,b={}){return this.http.send("GET",kl.agentJobs(A,G),{query:{state:b.state,cursor:b.cursor,limit:b.limit}})}listTasks(A,G,b={}){return this.http.send("GET",kl.jobTasks(A,G),{query:{cursor:b.cursor,limit:b.limit}})}getTask(A,G,b){return this.http.send("GET",kl.jobTask(A,G,b))}listTaskLogs(A,G,b,t={}){return this.http.send("GET",kl.jobTaskLogs(A,G,b),{query:{offset:t.offset,limit:t.limit}})}};var Pa=class{constructor(A,G){el(this,"http");el(this,"vaultId");this.http=A,this.vaultId=G}search(A,G={}){return this.http.send("POST",kl.memoryTool(this.vaultId,"record_search"),{body:{match:A,limit:G.limit,type:G.type,privacy:G.privacy,scope:G.scope,cursor:G.cursor,domain:G.domain}})}list(A,G={}){return this.http.send("POST",kl.memoryTool(this.vaultId,"record_list"),{body:{type:A,limit:G.limit,scope:G.scope,cursor:G.cursor,domain:G.domain}})}get(A){return this.http.send("POST",kl.memoryTool(this.vaultId,"record_get"),{body:{id:A}})}neighbours(A,G={}){return this.http.send("POST",kl.memoryTool(this.vaultId,"record_neighbours"),{body:{id:A,limit:G.limit,edge_type:G.edgeType,direction:G.direction}})}countByType(A={}){return this.http.send("POST",kl.memoryTool(this.vaultId,"record_count_by_type"),{body:{scope:A.scope,domain:A.domain}})}};async function Yu(l){return _a(await l.send("GET",kl.connectors()),"connectors")}var Ka=class{constructor(A,G){el(this,"http");el(this,"vaultId");this.http=A,this.vaultId=G}async list(){return _a(await this.http.send("GET",kl.connections(this.vaultId)),"connections")}create(A){return this.http.send("POST",kl.connections(this.vaultId),{body:uu(A)})}update(A,G){return this.http.send("PATCH",kl.connection(this.vaultId,A),{body:uu(G)})}async revoke(A){await this.http.send("DELETE",kl.connection(this.vaultId,A),{body:{}})}async actions(A){return _a(await this.http.send("GET",kl.connectionActions(this.vaultId,A)),"actions")}},qa=class{constructor(A,G){el(this,"http");el(this,"vaultId");this.http=A,this.vaultId=G}async list(A){return _a(await this.http.send("GET",kl.agentConnections(this.vaultId,A)),"connections")}set(A,G,b){return this.http.send("PUT",kl.agentConnection(this.vaultId,A,G),{body:{actions:b.actions,events:b.events,filter:b.filter??{}}})}async remove(A,G){await this.http.send("DELETE",kl.agentConnection(this.vaultId,A,G),{body:{}})}};function uu(l){let A={};for(let[G,b]of Object.entries(l))b!==void 0&&(A[G]=b);return A}function _a(l,A){let G=l&&typeof l=="object"?l[A]:void 0;return Array.isArray(G)?G:[]}var $a=class{constructor(A){el(this,"http");this.http=A}publish(A,G,b){let c=(Array.isArray(b)?b:[b]).map(B=>({role:"user",...B,timestamp:B.timestamp??new Date().toISOString()}));return this.http.send("POST",kl.scopeEvents(A,G),{body:{events:c}})}};var lg=class{constructor(A){el(this,"http");this.http=A}async upload(A,G,b,t,c={}){return this.http.send("PUT",kl.scopeObject(A,G,b),{rawBody:t,headers:{"Content-Type":c.contentType??"application/octet-stream"}})}async get(A,G,b){return this.http.send("GET",kl.scopeObject(A,G,b),{responseType:"bytes"})}async head(A,G,b){let t=await this.http.send("HEAD",kl.scopeObject(A,G,b),{responseType:"headers"}),c=Number(t["content-length"]??"0");return{size:Number.isFinite(c)?c:0,contentType:t["content-type"]??"",etag:t.etag,updatedAt:t["last-modified"]}}async presignedUrl(A,G,b,t={}){return this.http.send("GET",kl.scopeObjectsPresignedUrl(A,G),{query:{path:b,ttlSeconds:t.ttlSeconds}})}async delete(A,G,b){await this.http.send("DELETE",kl.scopeObject(A,G,b),{body:{timestamp:new Date().toISOString()}})}async list(A,G,b={}){return this.http.send("GET",kl.scopeObjects(A,G),{query:{prefix:b.prefix}})}};function hh(l,A,G,b,t,c={}){let B=new yt(l),e=c.intervalMs??1e3,d=c.pageSize??100,Z=c.onError??(R=>{console.warn("[vault-sdk] subscribe poll failed:",R)}),g=new Set,n,h=!1,W,m=new Promise(R=>W=R);return(async()=>{for(;!h;){try{let R=await B.listStreamEvents(A,G,b.context,{cursor:n,limit:d});for(let u of R.items)g.has(u.eventId)||(g.add(u.eventId),!(b.types&&!b.types.includes(u.type))&&(b.from&&!b.from.includes(u.from??"")||await t(u)));R.nextCursor&&(n=R.nextCursor)}catch(R){Z(R)}if(h)break;await new Promise(R=>setTimeout(R,e))}W()})(),{unsubscribe(){h=!0},closed:m}}var jd=class{constructor(A,G,b){el(this,"http");el(this,"vaultId");el(this,"name");el(this,"events");el(this,"browse");el(this,"_objects");el(this,"streams",{list:(A={})=>this.browse.listStreams(this.vaultId,this.name,A),get:A=>this.browse.getStream(this.vaultId,this.name,A)});el(this,"objects",{upload:async(A,G,b={})=>{let t=await this._objects.upload(this.vaultId,this.name,A,G,b);return b.publishEvent&&await this.publish({type:b.publishEvent.type,context:b.publishEvent.context,payload:{...b.publishEvent.payload,vaultPath:t.vaultPath}}),t},get:A=>this._objects.get(this.vaultId,this.name,A),head:A=>this._objects.head(this.vaultId,this.name,A),presignedUrl:(A,G={})=>this._objects.presignedUrl(this.vaultId,this.name,A,G),delete:A=>this._objects.delete(this.vaultId,this.name,A),list:(A={})=>this._objects.list(this.vaultId,this.name,A)});this.http=A,this.vaultId=G,this.name=b,this.events=new $a(A),this.browse=new yt(A),this._objects=new lg(A)}async publish(A){let G=await this.events.publish(this.vaultId,this.name,A),b=G.rejected??[],t=G.accepted??[];if(b.length>0){let c=b[0];throw new Error(`publish rejected: ${c.reason}${c.code?` (${c.code})`:""}`)}return{eventId:t[0]}}stream(A){return{events:{list:(G={})=>this.browse.listStreamEvents(this.vaultId,this.name,A,G)}}}subscribe(A,G,b={}){return hh(this.http,this.vaultId,this.name,A,G,b)}subscribeAll(A,G,b={}){return Wv(this.http,this.vaultId,this.name,this.browse,A,G,b)}};function Wv(l,A,G,b,t,c,B){let e=B.refreshIntervalMs??3e4,d=B.onError??(R=>{console.warn("[vault-sdk] subscribeAll refresh failed:",R)}),Z=new Map,g=!1,n,h,W=new Promise(R=>h=R),m=R=>{if(Z.has(R)||g)return;let u=hh(l,A,G,{context:R,...t.types?{types:t.types}:{}},c,B);Z.set(R,u)},Y=async()=>{try{let R=await b.listStreams(A,G);for(let u of R.items)m(u.context)}catch(R){d(R)}g||(n=setTimeout(Y,e))};return Y(),{unsubscribe(){if(g)return;g=!0,n&&clearTimeout(n);let R=[];for(let u of Z.values())u.unsubscribe(),R.push(u.closed);Z.clear(),Promise.all(R).then(()=>h())},closed:W}}var hZ=class{constructor(A){el(this,"http");this.http=A}query(A,G,b,t,c,B=[]){return this.http.send("POST",kl.cubbyQuery(A,G,b,t),{body:{sql:c,params:B}})}exec(A,G,b,t,c,B=[]){return this.http.send("POST",kl.cubbyExec(A,G,b,t),{body:{sql:c,params:B}})}serviceQuery(A,G,b,t,c=[]){return this.http.send("POST",kl.serviceCubbyQuery(A,G,b),{body:{sql:t,params:c}})}serviceExec(A,G,b,t,c=[]){return this.http.send("POST",kl.serviceCubbyExec(A,G,b),{body:{sql:t,params:c}})}async serviceList(A,G){return(await this.http.send("GET",kl.serviceCubbies(A,G)))?.data??[]}serviceProvision(A,G,b,t){return this.http.send("POST",kl.serviceCubbyProvision(A,G,b),{body:{migrations:t}})}serviceDelete(A,G,b){return this.http.send("DELETE",kl.serviceCubby(A,G,b))}};var Md=class{constructor(A,G,b){el(this,"vaultId");el(this,"asPubKey");el(this,"cubbies");this.vaultId=G,this.asPubKey=b,this.cubbies=new hZ(A)}list(){return this.cubbies.serviceList(this.vaultId,this.asPubKey)}cubby(A){let{vaultId:G,asPubKey:b,cubbies:t}=this;return{query:(c,B=[])=>t.serviceQuery(G,b,A,c,B),exec:(c,B=[])=>t.serviceExec(G,b,A,c,B),provision:c=>t.serviceProvision(G,b,A,c),delete:()=>t.serviceDelete(G,b,A)}}};var Td=class{constructor(A,G,b,t,c){el(this,"vaultId");el(this,"scope");el(this,"agentId");el(this,"alias");el(this,"api");this.vaultId=G,this.scope=b,this.agentId=t,this.alias=c,this.api=new hZ(A)}query(A,G=[]){return this.api.query(this.vaultId,this.scope,this.agentId,this.alias,A,G)}exec(A,G=[]){return this.api.exec(this.vaultId,this.scope,this.agentId,this.alias,A,G)}};var ee=class l{constructor(A,G,b){el(this,"http");el(this,"vaultIdRoot");el(this,"vaultId");el(this,"agentId");el(this,"scope");el(this,"scopes");el(this,"version");el(this,"asPubKey");el(this,"cubbyAliases");el(this,"status");el(this,"manifest");el(this,"ceiling");el(this,"bundle");el(this,"createdAt");el(this,"updatedAt");el(this,"api");el(this,"browse");el(this,"jobs",{list:(A={})=>this.browse.listAgentJobs(this.vaultIdRoot,this.agentId,A)});this.http=A,this.vaultIdRoot=G,this.vaultId=b.vaultId,this.agentId=b.agentId,this.scope=b.scope,this.scopes=b.scopes,this.version=b.version,this.asPubKey=b.asPubKey,this.cubbyAliases=b.cubbyAliases,this.status=b.status,this.manifest=b.manifest,this.ceiling=b.ceiling,this.bundle=b.bundle,this.createdAt=b.createdAt,this.updatedAt=b.updatedAt,this.api=new oZ(A),this.browse=new yt(A)}cubby(A){if(!this.cubbyAliases.includes(A))throw new Error(`agent ${this.agentId} has no cubby "${A}". Declared aliases: ${this.cubbyAliases.join(", ")||"(none)"}`);return new Td(this.http,this.vaultIdRoot,this.scope,this.agentId,A)}async update(A){let G=await this.api.update(this.vaultIdRoot,this.agentId,A);return new l(this.http,this.vaultIdRoot,G)}async setCeiling(A){let G=await this.api.setCeiling(this.vaultIdRoot,this.agentId,A);return new l(this.http,this.vaultIdRoot,G)}disconnect(){return this.api.disconnect(this.vaultIdRoot,this.agentId)}};var Dd=class{constructor(A,G,b){el(this,"http");el(this,"vaultId");el(this,"jobId");el(this,"browse");el(this,"tasks",{list:(A={})=>this.browse.listTasks(this.vaultId,this.jobId,A),get:A=>this.browse.getTask(this.vaultId,this.jobId,A),logs:(A,G={})=>this.browse.listTaskLogs(this.vaultId,this.jobId,A,G),subscribe:(A,G,b={})=>ov(this.browse,this.vaultId,this.jobId,A,G,b)});this.http=A,this.vaultId=G,this.jobId=b,this.browse=new yt(A)}get(){return this.browse.getJob(this.vaultId,this.jobId)}tree(){throw new Error("JobHandle.tree() requires the orchestrator's tree route which is not yet implemented (returns 501).")}};function ov(l,A,G,b,t,c){let B=c.intervalMs??1e3,e=c.pageSize??100,d=c.onError??(R=>{console.warn("[vault-sdk] tasks.subscribe poll failed:",R)}),Z=new Set,g,n=!1,h,W=new Promise(R=>h=R),m=b.since?Date.parse(b.since):void 0;return(async()=>{for(;!n;){try{let R=await l.listTasks(A,G,{cursor:g,limit:e});for(let u of R.items)if(!Z.has(u.taskId)){if(Z.add(u.taskId),m!==void 0){let i=u.startedAt??u.finishedAt;if(i&&Date.parse(i)<m)continue}await t(u)}R.nextCursor&&(g=R.nextCursor)}catch(R){d(R)}if(n)break;await new Promise(R=>setTimeout(R,B))}h()})(),{unsubscribe(){n=!0},closed:W}}var hv=new TextEncoder;function sh(l){if(!l.scopes||l.scopes.length===0)throw new Error("buildVaultAgreementPayloadV2: `scopes` must be a non-empty array \u2014 an agreement must record at least one scope");let A=Array.from(new Set(l.scopes)),G=l.createdAt??oa,b={version:"v2",agent_service_pub_key:yo(l.asPubKey),agent_id:l.agentId,vault_id:l.vaultId,user_pub_key:yo(l.userPubKey),revoked:!1,expires_at:null,metadata:{scopes:A},created_at:G()};return{payload:b,bytes:hv.encode(JSON.stringify(b))}}async function Ag(l){if(typeof l.signer?.sign!="function")throw new It;let{agentId:A,agentServicePubkey:G}=l.agent;if(!G)throw new Error("signAndSubmitAgreement: `agent.agentServicePubkey` is required");let b=gZ(l,"signAndSubmitAgreement"),{bytes:t}=sh({vaultId:l.vault.id,userPubKey:l.vault.userPubKey,asPubKey:G,agentId:A,scopes:b,createdAt:l.clock}),c=await l.signer.sign(t,"data"),B=Kb(c),e={payload:De(t),signature:{algorithm:"ed25519",signer:gB(l.vault.userPubKey),value:gB(B)}};return await l.gar.postAgreement(e),{agreementSignature:Yt(B)}}var fc=class{constructor(A,G,b={}){el(this,"id");el(this,"bucketId");el(this,"walletPubkey");el(this,"gatewayEndpoint");el(this,"region");el(this,"status");el(this,"disconnectedAt");el(this,"displayName");el(this,"registryBucketId");el(this,"_http");el(this,"_scopes");el(this,"_agents");el(this,"_browse");el(this,"memory");el(this,"connections");el(this,"_access");el(this,"_gar");el(this,"_signer");el(this,"_userPubKey");el(this,"scopes",{list:()=>this._scopes.list(this.id),get:A=>this._scopes.get(this.id,A),create:A=>this._scopes.create(this.id,A),update:(A,G)=>this._scopes.update(this.id,A,G),delete:A=>this._scopes.delete(this.id,A)});el(this,"agents",{connect:async A=>{if(!this._gar)throw new Error("vault.agents.connect requires `garEndpoint` on VaultSDKConfig");if(!this._signer)throw new Error("vault.agents.connect requires a `signer` on VaultSDKConfig");let G=A.agentId.includes(":")?A.agentId.split(":")[0]:"",b=A.agentServicePubkey??G;if(!b)throw new Error(`[vault.agents.connect] cannot derive agentServicePubkey from agentId '${A.agentId}' (expected '<pubkey>:<alias>'); pass agentServicePubkey explicitly`);let t=gZ(A,"vault.agents.connect");A.ceiling!==void 0&&Oa(A.ceiling);let{agreementSignature:c}=await Ag({signer:this._signer,vault:{id:this.id,userPubKey:this._userPubKey},agent:{agentId:A.agentId,agentServicePubkey:b},scopes:t,gar:this._gar}),B=A.scope!==void 0?{scope:A.scope}:{scopes:A.scopes},e={agentId:A.agentId,...B,settings:A.settings??{},agreementSignature:c,...A.ceiling!==void 0?{ceiling:A.ceiling}:{},...A.bundleCid!==void 0?{bundleCid:A.bundleCid}:{}},d=await this._agents.connect(this.id,e);return new ee(this._http,this.id,d)},list:async()=>(await this._agents.list(this.id)).map(G=>new ee(this._http,this.id,G)),get:async A=>{let G=await this._agents.get(this.id,A);return new ee(this._http,this.id,G)},connections:A=>this._access.list(A),setConnection:(A,G,b)=>this._access.set(A,G,b),removeConnection:(A,G)=>this._access.remove(A,G)});el(this,"jobs",{list:(A={})=>this._browse.listJobs(this.id,A),get:A=>new Dd(this._http,this.id,A)});this.id=G.vaultId,this.bucketId=G.bucketId,this.walletPubkey=G.walletPubkey,this.gatewayEndpoint=G.gatewayEndpoint,this.region=G.region,this.status=G.status,this.disconnectedAt=G.disconnectedAt,this.displayName=G.displayName,this.registryBucketId=G.registryBucketId,this._http=A,this._scopes=new La(A),this._agents=new oZ(A),this._browse=new yt(A),this.memory=new Pa(this._http,this.id),this.connections=new Ka(this._http,this.id),this._access=new qa(this._http,this.id),this._gar=b.gar,this._signer=b.signer,this._userPubKey=b.signer?gB(Kb(b.signer.publicKey)):G.walletPubkey}scope(A){return new jd(this._http,this.id,A)}service(A){return new Md(this._http,this.id,A)}connectors(){return Yu(this._http)}isDisconnected(){return this.status==="disconnected"}};var rh=class extends Error{constructor(A){super(`Unsupported signature type "${A}": vault-api accepts only "ed25519" or "sr25519". Pass WalletAuthOptions.sigType to override.`),this.name="UnsupportedSignatureTypeError"}};function Gg(l){if(l==="ed25519"||l==="sr25519")return l;throw new rh(l)}var Ld=class{constructor(A,G={}){el(this,"signer");el(this,"opts");this.signer=A,this.opts=G}async authenticate(A){if(typeof this.signer?.sign!="function")throw new It;let G=this.opts.sigType??Gg(this.signer.type),b={"X-Public-Key":gB(Kb(this.signer.publicKey)),"X-Signature-Type":G},t=A.method.toUpperCase();if(A.hash!==void 0){let{bytes:e}=Qo(t,A.path,A.query,this.opts.clock,A.hash),d=await this.signer.sign(e,"data");return b["X-Signed-Preamble"]=De(e),b["X-Signature"]=Yt(Kb(d)),{headers:b}}if(t==="GET"||t==="HEAD"){let{bytes:e}=Qo(t,A.path,A.query,this.opts.clock),d=await this.signer.sign(e,"data");return b["X-Signed-Preamble"]=De(e),b["X-Signature"]=Yt(Kb(d)),{headers:b}}let{bytes:c}=F2(A.body,this.opts.clock),B=await this.signer.sign(c,"data");return b["Content-Type"]="application/json",b["X-Signature"]=Yt(Kb(B)),{headers:b,body:c}}};var sv=new bt,sZ=class{constructor(A){el(this,"http");this.http=A}async postAgreement(A){await this.http.send("POST","/api/v1/agreements",{body:A,auth:sv})}};var Od=class extends Error{constructor(A){super(A),this.name="OnboardingRequiredError"}};function Xu(l){return{publicKeyHex:`0x${Iu(l.publicKey)}`,keyType:Gg(l.type),async signRawHex(A){let G=await l.sign(A,"data");return Iu(G)}}}function Iu(l){let A="";for(let G=0;G<l.length;G++)A+=l[G].toString(16).padStart(2,"0");return A}async function pu(l){let A=await l.signRawHex(new Uint8Array(0)),G=A.startsWith("0x")?A.slice(2):A;return{"X-Public-Key":l.publicKeyHex,"X-Signature":G,"X-Signature-Type":l.keyType}}async function Ru(l,A,G=fetch){let b=l.replace(/\/+$/,"")+"/auth/onboarding/status",t=await G(b,{method:"GET",headers:await pu(A)});if(t.status===404)return null;if(!t.ok)throw new Error(`onboarding status ${t.status}`);return await t.json()}async function rv(l,A,G=fetch){let b=l.replace(/\/+$/,"")+"/auth/onboarding/bootstrap",t=await G(b,{method:"POST",headers:await pu(A)});if(t.status!==200&&t.status!==207)throw new Error(`onboarding bootstrap ${t.status}`);return await t.json()}async function Fu(l,A,G=fetch,b){let t=await Ru(l,A,G);if(t===null)return{kind:"skipped",status:null};if(t.gateway_is_proxy)return{kind:"ready",status:t};let c,B=t;if(t.faucet_eligible||t.ddc_seed_eligible){b?.(),c=await rv(l,A,G);let e=await Ru(l,A,G);e&&(B=e)}return B.gateway_is_proxy?{kind:"ready",status:B}:{kind:"awaiting-proxy",status:B,bootstrap:c}}var iv=new bt,Pd=class{constructor(A){el(this,"http");this.http=A}async delegate(){let A=await this.http.send("GET",kl.delegateInfo(),{auth:iv}),G=A.delegate_pubkey??A.delegatePubkey;if(!G)throw new Error(`vault-api /delegate-info response is missing delegate_pubkey: ${JSON.stringify(A)}`);return{delegatePubkey:G}}};var mh={PUT:1,GET:2,DELETE:3};function iZ(...l){let A=new Uint8Array(l.reduce((b,t)=>b+t.length,0)),G=0;for(let b of l)A.set(b,G),G+=b.length;return A}function bg(l){let A=BigInt(l);if(A<0n)throw new RangeError(`auth-token: negative varint ${l}`);let G=[];do{let b=Number(A&0x7fn);A>>=7n,A!==0n&&(b|=128),G.push(b)}while(A!==0n);return Uint8Array.from(G)}var yu=(l,A)=>bg(l<<3|A),rZ=(l,A)=>iZ(yu(l,2),bg(A.length),A),ih=(l,A)=>iZ(yu(l,0),bg(A));function mv(l){let A=[rZ(2,l.subject),ih(3,l.canDelegate?1:0)];return l.bucketId!==void 0&&A.push(ih(4,l.bucketId)),l.operations.length>0&&A.push(rZ(5,iZ(...l.operations.map(G=>bg(G))))),A.push(ih(6,l.expiresAt)),iZ(...A)}var Vv="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";function uv(l){let A=[0];for(let b of l){let t=b;for(let c=0;c<A.length;c++)t+=A[c]<<8,A[c]=t%58,t=Math.floor(t/58);for(;t>0;)A.push(t%58),t=Math.floor(t/58)}let G="";for(let b=0;b<l.length&&l[b]===0;b++)G+="1";for(let b=A.length-1;b>=0;b--)G+=Vv[A[b]];return G}async function Vh(l,A){if(l.type!=="ed25519")throw new Error(`auth-token: only ed25519 signers can mint a DDC AuthToken here (signer reports "${l.type}")`);let G=rZ(2,mv(A)),b=await l.sign(G,"token"),t=iZ(rZ(2,l.publicKey),rZ(3,b));return uv(iZ(rZ(1,t),G))}var Yv=24*60*60*1e3,uh=365*Yv,Nu=uh-60*60*1e3,{GET:Eu,PUT:vu,DELETE:Iv}=mh,Hu=[Eu,vu,Iv],Ju=[Eu,vu],Rv=(1n<<64n)-1n,Xv=(1n<<63n)-1n;function Qu(l,A,G){let b;if(typeof A=="bigint")b=A;else if(/^[0-9]+$/.test(A))b=BigInt(A);else throw new Error(`${l} must be a decimal chain bucket id, got "${A}"`);if(b<=0n||b>G)throw new Error(`${l} ${b} is out of range: a chain bucket id is 1..${G}`);return b}function pv(l){let A=l.replace(/^0x/i,"");if(!/^[0-9a-fA-F]{64}$/.test(A))throw new Error(`delegatePubkey must be a 32-byte hex key, got "${l}"`);return Te(A)}async function Yh(l){let A=Qu("vaultBucketId",l.vaultBucketId,Rv),G=Qu("registryBucketId",l.registryBucketId,Xv);if(A===G)throw new Error(`vaultBucketId and registryBucketId are the same bucket (${A}): the vault bucket is private because it holds memory and the registry bucket is public because agent code is read anonymously`);let b=pv(l.delegatePubkey),t=(l.now??Date.now)(),c=l.expiresAt===void 0?t+Nu:l.expiresAt instanceof Date?l.expiresAt.getTime():l.expiresAt;if(!Number.isSafeInteger(c)||c<=t)throw new Error(`expiresAt must be in the future, got ${new Date(c).toISOString()}`);if(c>t+uh)throw new Error(`expiresAt ${new Date(c).toISOString()} is more than one year away; vault-api refuses delegations beyond that`);if(l.signer.type!=="ed25519")throw new Error(`delegation tokens need an ed25519 owner wallet (signer reports "${l.signer.type}")`);let B=await Vh(l.signer,{subject:b,canDelegate:!0,bucketId:A,operations:Hu,expiresAt:c}),e=await Vh(l.signer,{subject:b,canDelegate:!0,bucketId:G,operations:Ju,expiresAt:c});return{vaultDelegationToken:B,registryDelegationToken:e,expiresAt:new Date(c)}}var xH="https://ddc-s3-gateway.compute.dev.ddcdragon.com/auth/info",fH="https://agent-marketplace.compute.dev.ddcdragon.com",kH=3,wH=[2e3,5e3];function UH(l){return l.status===425||l.status===503&&l.retryable===!0}var _Z=class{constructor(A){el(this,"http");el(this,"marketplaceHttp");el(this,"endpoint");el(this,"chainUrl");el(this,"vaults");el(this,"gar");el(this,"signer");el(this,"s3GatewayAuthInfoUrl");el(this,"fetchFn");el(this,"marketplace");el(this,"health");el(this,"memberships");el(this,"vault",{ensure:async(A={})=>{let G=A.onProgress??(()=>{});if(A.onboard!==!1&&this.signer){let B=Xu(this.signer),e=this.gatewayBaseUrl();G({kind:"inspecting-wallet"});let d=await Fu(e,B,this.fetchFn,()=>{G({kind:"funding-wallet"})});if(d.kind==="awaiting-proxy")throw G({kind:"gateway-authorization-required",status:d.status}),new Od("Onboarding required: the gateway does not yet see this wallet's on-chain proxy authorization. Register it externally via `@cef-ai/account`'s `provisioning.ensure({ signer, chainUrl, gateway })`, wait for it to resolve, then retry `vault.ensure()`.")}let t=A.delegationToken;if(!t){if(!this.signer)throw new Error("vault.ensure() needs either a `delegationToken` or a `signer` configured on VaultSDKConfig (the signer drives the on-chain vault-delegate grant).");let B=A.chainUrl??this.chainUrl;if(!B)throw new Error("vault.ensure(): `chainUrl` is required on the wallet path \u2014 the SDK grants vault-api write delegation by submitting an on-chain NonTransfer proxy (`@cef-ai/account`'s `ensureVaultDelegate`) before claiming the vault. Set `chainUrl` on VaultSDKConfig (or pass it per call) with a Cere node WS URL, or pass `delegationToken` to use the legacy token-bearing claim instead.");G({kind:"authorizing-vault"});let{ensureVaultDelegate:e}=await Promise.resolve().then(()=>(SF(),CF));await e({signer:this.signer,chainUrl:B,vaultApiUrl:this.endpoint,fetchFn:this.fetchFn})}G({kind:"provisioning-vault"});let c=await this.claimVaultWithRetry({name:A.name,label:"vault",...t?{delegation_token:t}:{}},A.sleep);return new fc(this.http,c,{gar:this.gar,signer:this.signer})},current:async()=>{let A=await this.vaults.current();return new fc(this.http,A,{gar:this.gar,signer:this.signer})},byId:async A=>{let G=await this.vaults.byId(A);return new fc(this.http,G,{gar:this.gar,signer:this.signer})},rename:async(A,G)=>{let b=await this.vaults.patch(A,{displayName:G,timestamp:new Date().toISOString()});return new fc(this.http,b,{gar:this.gar,signer:this.signer})},delegations:{put:async(A,G)=>{let b=await this.vaults.putDelegations(A,{vaultDelegationToken:G.vaultDelegationToken,registryDelegationToken:G.registryDelegationToken,timestamp:new Date().toISOString()}),{vaultBucketId:t,registryBucketId:c,delegationsExpireAt:B,...e}=b;return{vault:new fc(this.http,{...e,registryBucketId:c},{gar:this.gar,signer:this.signer}),vaultBucketId:t,registryBucketId:c,delegationsExpireAt:B}},grant:async(A,G)=>{if(!this.signer)throw new It;let{delegatePubkey:b}=await new Pd(this.http).delegate(),t=await Yh({signer:this.signer,delegatePubkey:b,vaultBucketId:G.vaultBucketId,registryBucketId:G.registryBucketId,expiresAt:G.expiresAt});return this.vault.delegations.put(A,t)}}});let G=A.auth??(A.signer?new Ld(A.signer):void 0);this.endpoint=A.endpoint,this.chainUrl=A.chainUrl,this.http=new Le({url:A.endpoint,auth:G,fetch:A.fetch,timeoutMs:A.timeoutMs}),this.marketplaceHttp=new Le({url:A.marketplaceEndpoint??fH,fetch:A.fetch,timeoutMs:A.timeoutMs}),A.garEndpoint&&(this.gar=new sZ(new Le({url:A.garEndpoint,fetch:A.fetch,timeoutMs:A.timeoutMs}))),this.signer=A.signer,this.s3GatewayAuthInfoUrl=A.s3GatewayAuthInfoUrl??xH,this.fetchFn=A.fetch??fetch.bind(globalThis),this.vaults=new ha(this.http),this.marketplace=new Ta(this.marketplaceHttp),this.health=new Da(this.http),this.memberships=new Ma(this.http,A.signer)}gatewayBaseUrl(){return this.s3GatewayAuthInfoUrl.replace(/\/+$/,"").replace(/\/auth\/info$/,"")}async claimVaultWithRetry(A,G){let b=G??(t=>new Promise(c=>setTimeout(c,t)));for(let t=1;;t++)try{return await this.vaults.claim(A)}catch(c){if(t>=kH||!(c instanceof _G)||!UH(c))throw c;await b(wH[t-1])}}};function zF(){return nu().then(()=>{if(!TA())throw new Error("Unable to initialize @polkadot/util-crypto");return!0}).catch(()=>!1)}function Ri(l){return l instanceof Uint8Array||ArrayBuffer.isView(l)&&l.constructor.name==="Uint8Array"}function CH(l,...A){if(!Ri(l))throw new Error("Uint8Array expected");if(A.length>0&&!A.includes(l.length))throw new Error("Uint8Array expected of length "+A+", got length="+l.length)}function TF(l,A){return Array.isArray(A)?A.length===0?!0:l?A.every(G=>typeof G=="string"):A.every(G=>Number.isSafeInteger(G)):!1}function xn(l,A){if(typeof A!="string")throw new Error(`${l}: string expected`);return!0}function fn(l){if(!Number.isSafeInteger(l))throw new Error(`invalid integer: ${l}`)}function xW(l){if(!Array.isArray(l))throw new Error("array expected")}function fW(l,A){if(!TF(!0,A))throw new Error(`${l}: array of strings expected`)}function DF(l,A){if(!TF(!1,A))throw new Error(`${l}: array of numbers expected`)}function LF(...l){let A=c=>c,G=(c,B)=>e=>c(B(e)),b=l.map(c=>c.encode).reduceRight(G,A),t=l.map(c=>c.decode).reduce(G,A);return{encode:b,decode:t}}function OF(l){let A=typeof l=="string"?l.split(""):l,G=A.length;fW("alphabet",A);let b=new Map(A.map((t,c)=>[t,c]));return{encode:t=>(xW(t),t.map(c=>{if(!Number.isSafeInteger(c)||c<0||c>=G)throw new Error(`alphabet.encode: digit index outside alphabet "${c}". Allowed: ${l}`);return A[c]})),decode:t=>(xW(t),t.map(c=>{xn("alphabet.decode",c);let B=b.get(c);if(B===void 0)throw new Error(`Unknown letter: "${c}". Allowed: ${l}`);return B}))}}function PF(l=""){return xn("join",l),{encode:A=>(fW("join.decode",A),A.join(l)),decode:A=>(xn("join.decode",A),A.split(l))}}function SH(l,A="="){return fn(l),xn("padding",A),{encode(G){for(fW("padding.encode",G);G.length*l%8;)G.push(A);return G},decode(G){fW("padding.decode",G);let b=G.length;if(b*l%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;b>0&&G[b-1]===A;b--)if((b-1)*l%8===0)throw new Error("padding: invalid, string has too much padding");return G.slice(0,b)}}}function jF(l,A,G){if(A<2)throw new Error(`convertRadix: invalid from=${A}, base cannot be less than 2`);if(G<2)throw new Error(`convertRadix: invalid to=${G}, base cannot be less than 2`);if(xW(l),!l.length)return[];let b=0,t=[],c=Array.from(l,e=>{if(fn(e),e<0||e>=A)throw new Error(`invalid integer: ${e}`);return e}),B=c.length;for(;;){let e=0,d=!0;for(let Z=b;Z<B;Z++){let g=c[Z],n=A*e,h=n+g;if(!Number.isSafeInteger(h)||n/A!==e||h-g!==n)throw new Error("convertRadix: carry overflow");let W=h/G;e=h%G;let m=Math.floor(W);if(c[Z]=m,!Number.isSafeInteger(m)||m*G+e!==h)throw new Error("convertRadix: carry overflow");if(d)m?d=!1:b=Z;else continue}if(t.push(e),d)break}for(let e=0;e<l.length-1&&l[e]===0;e++)t.push(0);return t.reverse()}var KF=(l,A)=>A===0?l:KF(A,l%A),kW=(l,A)=>l+(A-KF(l,A)),Ii=(()=>{let l=[];for(let A=0;A<40;A++)l.push(2**A);return l})();function MF(l,A,G,b){if(xW(l),A<=0||A>32)throw new Error(`convertRadix2: wrong from=${A}`);if(G<=0||G>32)throw new Error(`convertRadix2: wrong to=${G}`);if(kW(A,G)>32)throw new Error(`convertRadix2: carry overflow from=${A} to=${G} carryBits=${kW(A,G)}`);let t=0,c=0,B=Ii[A],e=Ii[G]-1,d=[];for(let Z of l){if(fn(Z),Z>=B)throw new Error(`convertRadix2: invalid data word=${Z} from=${A}`);if(t=t<<A|Z,c+A>32)throw new Error(`convertRadix2: carry overflow pos=${c} from=${A}`);for(c+=A;c>=G;c-=G)d.push((t>>c-G&e)>>>0);let g=Ii[c];if(g===void 0)throw new Error("invalid carry");t&=g-1}if(t=t<<G-c&e,!b&&c>=A)throw new Error("Excess padding");if(!b&&t>0)throw new Error(`Non-zero padding: ${t}`);return b&&c>0&&d.push(t>>>0),d}function zH(l){fn(l);let A=2**8;return{encode:G=>{if(!Ri(G))throw new Error("radix.encode input should be Uint8Array");return jF(Array.from(G),A,l)},decode:G=>(DF("radix.decode",G),Uint8Array.from(jF(G,l,A)))}}function jH(l,A=!1){if(fn(l),l<=0||l>32)throw new Error("radix2: bits should be in (0..32]");if(kW(8,l)>32||kW(l,8)>32)throw new Error("radix2: carry overflow");return{encode:G=>{if(!Ri(G))throw new Error("radix2.encode input should be Uint8Array");return MF(Array.from(G),8,l,!A)},decode:G=>(DF("radix2.decode",G),Uint8Array.from(MF(G,l,8,A)))}}var MH=typeof Uint8Array.from([]).toBase64=="function"&&typeof Uint8Array.fromBase64=="function",TH=(l,A)=>{xn("base64",l);let G=A?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,b=A?"base64url":"base64";if(l.length>0&&!G.test(l))throw new Error("invalid base64");return Uint8Array.fromBase64(l,{alphabet:b,lastChunkHandling:"strict"})},qF=MH?{encode(l){return CH(l),l.toBase64()},decode(l){return TH(l,!1)}}:LF(jH(6),OF("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),SH(6),PF(""));var DH=l=>LF(zH(58),OF(l),PF("")),_F=DH("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");function wW({coder:l,ipfs:A},G){return(b,t)=>(G(b,t),l.decode(A&&t?b.substring(1):b))}function UW({coder:l,ipfs:A}){return(G,b)=>{let t=l.encode(Tl(G));return A&&b?`${A}${t}`:t}}function CW({chars:l,ipfs:A,type:G,withPadding:b}){return(t,c)=>{if(typeof t!="string")throw new Error(`Expected ${G} string input`);if(A&&c&&!t.startsWith(A))throw new Error(`Expected ipfs-compatible ${G} to start with '${A}'`);for(let B=c?1:0,e=t.length;B<e;B++)if(!l.includes(t[B]))if(b&&t[B]==="="){if(B!==e-1){if(t[B+1]!=="=")throw new Error(`Invalid ${G} padding sequence "${t[B]}${t[B+1]}" at index ${B}`)}}else throw new Error(`Invalid ${G} character "${t[B]}" (0x${t.charCodeAt(B).toString(16)}) at index ${B}`);return!0}}var Xi={chars:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",coder:_F,ipfs:"z",type:"base58"},$F=CW(Xi),pi=wW(Xi,$F),Fi=UW(Xi);var OH=uG("SS58PRE");function SW(l){return Mb(nG(OH,l),512)}function ly(l){let A=l[0]&64?2:1,G=A===1?l[0]:(l[0]&63)<<2|l[1]>>6|(l[1]&63)<<8,b=[34+A,35+A].includes(l.length),t=l.length-(b?2:1),c=SW(l.subarray(0,t));return[(l[0]&128)===0&&![46,47].includes(l[0])&&(b?l[l.length-2]===c[0]&&l[l.length-1]===c[1]:l[l.length-1]===c[0]),t,A,G]}var Ay=[{prefix:0,network:"polkadot",displayName:"Polkadot Relay Chain",symbols:["DOT"],decimals:[10],standardAccount:"*25519",website:"https://polkadot.network"},{prefix:1,network:"BareSr25519",displayName:"Bare 32-bit Schnorr/Ristretto (S/R 25519) public key.",symbols:[],decimals:[],standardAccount:"Sr25519",website:null},{prefix:2,network:"kusama",displayName:"Kusama Relay Chain",symbols:["KSM"],decimals:[12],standardAccount:"*25519",website:"https://kusama.network"},{prefix:3,network:"BareEd25519",displayName:"Bare 32-bit Ed25519 public key.",symbols:[],decimals:[],standardAccount:"Ed25519",website:null},{prefix:4,network:"katalchain",displayName:"Katal Chain",symbols:[],decimals:[],standardAccount:"*25519",website:null},{prefix:5,network:"astar",displayName:"Astar Network",symbols:["ASTR"],decimals:[18],standardAccount:"*25519",website:"https://astar.network"},{prefix:6,network:"bifrost",displayName:"Bifrost",symbols:["BNC"],decimals:[12],standardAccount:"*25519",website:"https://bifrost.finance/"},{prefix:7,network:"edgeware",displayName:"Edgeware",symbols:["EDG"],decimals:[18],standardAccount:"*25519",website:"https://edgewa.re"},{prefix:8,network:"karura",displayName:"Karura",symbols:["KAR"],decimals:[12],standardAccount:"*25519",website:"https://karura.network/"},{prefix:9,network:"reynolds",displayName:"Laminar Reynolds Canary",symbols:["REY"],decimals:[18],standardAccount:"*25519",website:"http://laminar.network/"},{prefix:10,network:"acala",displayName:"Acala",symbols:["ACA"],decimals:[12],standardAccount:"*25519",website:"https://acala.network/"},{prefix:11,network:"laminar",displayName:"Laminar",symbols:["LAMI"],decimals:[18],standardAccount:"*25519",website:"http://laminar.network/"},{prefix:12,network:"polymesh",displayName:"Polymesh",symbols:["POLYX"],decimals:[6],standardAccount:"*25519",website:"https://polymath.network/"},{prefix:13,network:"integritee",displayName:"Integritee",symbols:["TEER"],decimals:[12],standardAccount:"*25519",website:"https://integritee.network"},{prefix:14,network:"totem",displayName:"Totem",symbols:["TOTEM"],decimals:[0],standardAccount:"*25519",website:"https://totemaccounting.com"},{prefix:15,network:"synesthesia",displayName:"Synesthesia",symbols:["SYN"],decimals:[12],standardAccount:"*25519",website:"https://synesthesia.network/"},{prefix:16,network:"kulupu",displayName:"Kulupu",symbols:["KLP"],decimals:[12],standardAccount:"*25519",website:"https://kulupu.network/"},{prefix:17,network:"dark",displayName:"Dark Mainnet",symbols:[],decimals:[],standardAccount:"*25519",website:null},{prefix:18,network:"darwinia",displayName:"Darwinia Network",symbols:["RING"],decimals:[18],standardAccount:"secp256k1",website:"https://darwinia.network"},{prefix:19,network:"watr",displayName:"Watr Protocol",symbols:["WATR"],decimals:[18],standardAccount:"*25519",website:"https://www.watr.org"},{prefix:20,network:"stafi",displayName:"Stafi",symbols:["FIS"],decimals:[12],standardAccount:"*25519",website:"https://stafi.io"},{prefix:21,network:"karmachain",displayName:"Karmacoin",symbols:["KCOIN"],decimals:[6],standardAccount:"*25519",website:"https://karmaco.in"},{prefix:22,network:"dock-pos-mainnet",displayName:"Dock Mainnet",symbols:["DCK"],decimals:[6],standardAccount:"*25519",website:"https://dock.io"},{prefix:23,network:"shift",displayName:"ShiftNrg",symbols:[],decimals:[],standardAccount:"*25519",website:null},{prefix:24,network:"zero",displayName:"ZERO",symbols:["ZERO"],decimals:[18],standardAccount:"*25519",website:"https://zero.io"},{prefix:25,network:"zero-alphaville",displayName:"ZERO Alphaville",symbols:["ZERO"],decimals:[18],standardAccount:"*25519",website:"https://zero.io"},{prefix:26,network:"jupiter",displayName:"Jupiter",symbols:["jDOT"],decimals:[10],standardAccount:"*25519",website:"https://jupiter.patract.io"},{prefix:27,network:"kabocha",displayName:"Kabocha",symbols:["KAB"],decimals:[12],standardAccount:"*25519",website:"https://kabocha.network"},{prefix:28,network:"subsocial",displayName:"Subsocial",symbols:[],decimals:[],standardAccount:"*25519",website:null},{prefix:29,network:"cord",displayName:"CORD Network",symbols:["DHI","WAY"],decimals:[12,12],standardAccount:"*25519",website:"https://cord.network/"},{prefix:30,network:"phala",displayName:"Phala Network",symbols:["PHA"],decimals:[12],standardAccount:"*25519",website:"https://phala.network"},{prefix:31,network:"litentry",displayName:"Litentry Network",symbols:["LIT"],decimals:[12],standardAccount:"*25519",website:"https://litentry.com/"},{prefix:32,network:"robonomics",displayName:"Robonomics",symbols:["XRT"],decimals:[9],standardAccount:"*25519",website:"https://robonomics.network"},{prefix:33,network:"datahighway",displayName:"DataHighway",symbols:[],decimals:[],standardAccount:"*25519",website:null},{prefix:34,network:"ares",displayName:"Ares Protocol",symbols:["ARES"],decimals:[12],standardAccount:"*25519",website:"https://www.aresprotocol.com/"},{prefix:35,network:"vln",displayName:"Valiu Liquidity Network",symbols:["USDv"],decimals:[15],standardAccount:"*25519",website:"https://valiu.com/"},{prefix:36,network:"centrifuge",displayName:"Centrifuge Chain",symbols:["CFG"],decimals:[18],standardAccount:"*25519",website:"https://centrifuge.io/"},{prefix:37,network:"nodle",displayName:"Nodle Chain",symbols:["NODL"],decimals:[11],standardAccount:"*25519",website:"https://nodle.io/"},{prefix:38,network:"kilt",displayName:"KILT Spiritnet",symbols:["KILT"],decimals:[15],standardAccount:"*25519",website:"https://kilt.io/"},{prefix:39,network:"mathchain",displayName:"MathChain mainnet",symbols:["MATH"],decimals:[18],standardAccount:"*25519",website:"https://mathwallet.org"},{prefix:40,network:"mathchain-testnet",displayName:"MathChain testnet",symbols:["MATH"],decimals:[18],standardAccount:"*25519",website:"https://mathwallet.org"},{prefix:41,network:"polimec",displayName:"Polimec Protocol",symbols:["PLMC"],decimals:[10],standardAccount:"*25519",website:"https://www.polimec.org/"},{prefix:42,network:"substrate",displayName:"Substrate",symbols:[],decimals:[],standardAccount:"*25519",website:"https://substrate.io/"},{prefix:43,network:"BareSecp256k1",displayName:"Bare 32-bit ECDSA SECP-256k1 public key.",symbols:[],decimals:[],standardAccount:"secp256k1",website:null},{prefix:44,network:"chainx",displayName:"ChainX",symbols:["PCX"],decimals:[8],standardAccount:"*25519",website:"https://chainx.org/"},{prefix:45,network:"uniarts",displayName:"UniArts Network",symbols:["UART","UINK"],decimals:[12,12],standardAccount:"*25519",website:"https://uniarts.me"},{prefix:46,network:"reserved46",displayName:"This prefix is reserved.",symbols:[],decimals:[],standardAccount:null,website:null},{prefix:47,network:"reserved47",displayName:"This prefix is reserved.",symbols:[],decimals:[],standardAccount:null,website:null},{prefix:48,network:"neatcoin",displayName:"Neatcoin Mainnet",symbols:["NEAT"],decimals:[12],standardAccount:"*25519",website:"https://neatcoin.org"},{prefix:49,network:"picasso",displayName:"Picasso",symbols:["PICA"],decimals:[12],standardAccount:"*25519",website:"https://picasso.composable.finance"},{prefix:50,network:"composable",displayName:"Composable Finance",symbols:["LAYR"],decimals:[12],standardAccount:"*25519",website:"https://composable.finance"},{prefix:51,network:"oak",displayName:"OAK Network",symbols:["OAK","TUR"],decimals:[10,10],standardAccount:"*25519",website:"https://oak.tech"},{prefix:52,network:"KICO",displayName:"KICO",symbols:["KICO"],decimals:[14],standardAccount:"*25519",website:"https://dico.io"},{prefix:53,network:"DICO",displayName:"DICO",symbols:["DICO"],decimals:[14],standardAccount:"*25519",website:"https://dico.io"},{prefix:54,network:"cere",displayName:"Cere Network",symbols:["CERE"],decimals:[10],standardAccount:"*25519",website:"https://cere.network"},{prefix:55,network:"xxnetwork",displayName:"xx network",symbols:["XX"],decimals:[9],standardAccount:"*25519",website:"https://xx.network"},{prefix:56,network:"pendulum",displayName:"Pendulum chain",symbols:["PEN"],decimals:[12],standardAccount:"*25519",website:"https://pendulumchain.org/"},{prefix:57,network:"amplitude",displayName:"Amplitude chain",symbols:["AMPE"],decimals:[12],standardAccount:"*25519",website:"https://pendulumchain.org/"},{prefix:58,network:"eternal-civilization",displayName:"Eternal Civilization",symbols:["ECC"],decimals:[12],standardAccount:"*25519",website:"http://www.ysknfr.cn/"},{prefix:63,network:"hydradx",displayName:"Hydration",symbols:["HDX"],decimals:[12],standardAccount:"*25519",website:"https://hydration.net"},{prefix:65,network:"aventus",displayName:"Aventus Mainnet",symbols:["AVT"],decimals:[18],standardAccount:"*25519",website:"https://aventus.io"},{prefix:66,network:"crust",displayName:"Crust Network",symbols:["CRU"],decimals:[12],standardAccount:"*25519",website:"https://crust.network"},{prefix:67,network:"genshiro",displayName:"Genshiro Network",symbols:["GENS","EQD","LPT0"],decimals:[9,9,9],standardAccount:"*25519",website:"https://genshiro.equilibrium.io"},{prefix:68,network:"equilibrium",displayName:"Equilibrium Network",symbols:["EQ"],decimals:[9],standardAccount:"*25519",website:"https://equilibrium.io"},{prefix:69,network:"sora",displayName:"SORA Network",symbols:["XOR"],decimals:[18],standardAccount:"*25519",website:"https://sora.org"},{prefix:71,network:"p3d",displayName:"3DP network",symbols:["P3D"],decimals:[12],standardAccount:"*25519",website:"https://3dpass.org"},{prefix:72,network:"p3dt",displayName:"3DP test network",symbols:["P3Dt"],decimals:[12],standardAccount:"*25519",website:"https://3dpass.org"},{prefix:73,network:"zeitgeist",displayName:"Zeitgeist",symbols:["ZTG"],decimals:[10],standardAccount:"*25519",website:"https://zeitgeist.pm"},{prefix:77,network:"manta",displayName:"Manta network",symbols:["MANTA"],decimals:[18],standardAccount:"*25519",website:"https://manta.network"},{prefix:78,network:"calamari",displayName:"Calamari: Manta Canary Network",symbols:["KMA"],decimals:[12],standardAccount:"*25519",website:"https://manta.network"},{prefix:81,network:"sora_dot_para",displayName:"SORA Polkadot Parachain",symbols:["XOR"],decimals:[18],standardAccount:"*25519",website:"https://sora.org"},{prefix:88,network:"polkadex",displayName:"Polkadex Mainnet",symbols:["PDEX"],decimals:[12],standardAccount:"*25519",website:"https://polkadex.trade"},{prefix:89,network:"polkadexparachain",displayName:"Polkadex Parachain",symbols:["PDEX"],decimals:[12],standardAccount:"*25519",website:"https://polkadex.trade"},{prefix:90,network:"frequency",displayName:"Frequency",symbols:["FRQCY"],decimals:[8],standardAccount:"*25519",website:"https://www.frequency.xyz"},{prefix:92,network:"anmol",displayName:"Anmol Network",symbols:["ANML"],decimals:[18],standardAccount:"*25519",website:"https://anmol.network/"},{prefix:93,network:"fragnova",displayName:"Fragnova Network",symbols:["NOVA"],decimals:[12],standardAccount:"*25519",website:"https://fragnova.com"},{prefix:98,network:"polkasmith",displayName:"PolkaSmith Canary Network",symbols:["PKS"],decimals:[18],standardAccount:"*25519",website:"https://polkafoundry.com"},{prefix:99,network:"polkafoundry",displayName:"PolkaFoundry Network",symbols:["PKF"],decimals:[18],standardAccount:"*25519",website:"https://polkafoundry.com"},{prefix:100,network:"ibtida",displayName:"Anmol Network Ibtida Canary network",symbols:["IANML"],decimals:[18],standardAccount:"*25519",website:"https://anmol.network/"},{prefix:101,network:"origintrail-parachain",displayName:"OriginTrail Parachain",symbols:["OTP"],decimals:[12],standardAccount:"*25519",website:"https://parachain.origintrail.io/"},{prefix:105,network:"pontem-network",displayName:"Pontem Network",symbols:["PONT"],decimals:[10],standardAccount:"*25519",website:"https://pontem.network"},{prefix:110,network:"heiko",displayName:"Heiko",symbols:["HKO"],decimals:[12],standardAccount:"*25519",website:"https://parallel.fi/"},{prefix:113,network:"integritee-incognito",displayName:"Integritee Incognito",symbols:[],decimals:[],standardAccount:"*25519",website:"https://integritee.network"},{prefix:117,network:"tinker",displayName:"Tinker",symbols:["TNKR"],decimals:[12],standardAccount:"*25519",website:"https://invarch.network"},{prefix:126,network:"joystream",displayName:"Joystream",symbols:["JOY"],decimals:[10],standardAccount:"*25519",website:"https://www.joystream.org"},{prefix:128,network:"clover",displayName:"Clover Finance",symbols:["CLV"],decimals:[18],standardAccount:"*25519",website:"https://clover.finance"},{prefix:129,network:"dorafactory-polkadot",displayName:"Dorafactory Polkadot Network",symbols:["DORA"],decimals:[12],standardAccount:"*25519",website:"https://dorafactory.org"},{prefix:131,network:"litmus",displayName:"Litmus Network",symbols:["LIT"],decimals:[12],standardAccount:"*25519",website:"https://litentry.com/"},{prefix:136,network:"altair",displayName:"Altair",symbols:["AIR"],decimals:[18],standardAccount:"*25519",website:"https://centrifuge.io/"},{prefix:137,network:"vara",displayName:"Vara Network",symbols:["VARA"],decimals:[12],standardAccount:"*25519",website:"https://vara.network/"},{prefix:172,network:"parallel",displayName:"Parallel",symbols:["PARA"],decimals:[12],standardAccount:"*25519",website:"https://parallel.fi/"},{prefix:252,network:"social-network",displayName:"Social Network",symbols:["NET"],decimals:[18],standardAccount:"*25519",website:"https://social.network"},{prefix:255,network:"quartz_mainnet",displayName:"QUARTZ by UNIQUE",symbols:["QTZ"],decimals:[18],standardAccount:"*25519",website:"https://unique.network"},{prefix:268,network:"pioneer_network",displayName:"Pioneer Network by Bit.Country",symbols:["NEER"],decimals:[18],standardAccount:"*25519",website:"https://bit.country"},{prefix:420,network:"sora_kusama_para",displayName:"SORA Kusama Parachain",symbols:["XOR"],decimals:[18],standardAccount:"*25519",website:"https://sora.org"},{prefix:440,network:"allfeat_network",displayName:"Allfeat Network",symbols:["AFT"],decimals:[12],standardAccount:"*25519",website:"https://allfeat.network"},{prefix:666,network:"metaquity_network",displayName:"Metaquity Network",symbols:["MQTY"],decimals:[18],standardAccount:"*25519",website:"https://metaquity.xyz/"},{prefix:777,network:"curio",displayName:"Curio",symbols:["CGT"],decimals:[18],standardAccount:"*25519",website:"https://parachain.capitaldex.exchange/"},{prefix:789,network:"geek",displayName:"GEEK Network",symbols:["GEEK"],decimals:[18],standardAccount:"*25519",website:"https://geek.gl"},{prefix:995,network:"ternoa",displayName:"Ternoa",symbols:["CAPS"],decimals:[18],standardAccount:"*25519",website:"https://www.ternoa.network"},{prefix:1110,network:"efinity",displayName:"Efinity",symbols:["EFI"],decimals:[18],standardAccount:"*25519",website:"https://efinity.io/"},{prefix:1221,network:"peaq",displayName:"Peaq Network",symbols:["PEAQ"],decimals:[18],standardAccount:"Sr25519",website:"https://www.peaq.network/"},{prefix:1222,network:"krest",displayName:"Krest Network",symbols:["KREST"],decimals:[18],standardAccount:"Sr25519",website:"https://www.peaq.network/"},{prefix:1284,network:"moonbeam",displayName:"Moonbeam",symbols:["GLMR"],decimals:[18],standardAccount:"secp256k1",website:"https://moonbeam.network"},{prefix:1285,network:"moonriver",displayName:"Moonriver",symbols:["MOVR"],decimals:[18],standardAccount:"secp256k1",website:"https://moonbeam.network"},{prefix:1328,network:"ajuna",displayName:"Ajuna Network",symbols:["AJUN"],decimals:[12],standardAccount:"*25519",website:"https://ajuna.io"},{prefix:1337,network:"bajun",displayName:"Bajun Network",symbols:["BAJU"],decimals:[12],standardAccount:"*25519",website:"https://ajuna.io"},{prefix:1516,network:"societal",displayName:"Societal",symbols:["SCTL"],decimals:[12],standardAccount:"*25519",website:"https://www.sctl.xyz"},{prefix:1985,network:"seals",displayName:"Seals Network",symbols:["SEAL"],decimals:[9],standardAccount:"*25519",website:"https://seals.app"},{prefix:2007,network:"kapex",displayName:"Kapex",symbols:["KAPEX"],decimals:[12],standardAccount:"*25519",website:"https://totemaccounting.com"},{prefix:2009,network:"cloudwalk_mainnet",displayName:"CloudWalk Network Mainnet",symbols:["CWN"],decimals:[18],standardAccount:"*25519",website:"https://explorer.mainnet.cloudwalk.io"},{prefix:2021,network:"logion",displayName:"logion network",symbols:["LGNT"],decimals:[18],standardAccount:"*25519",website:"https://logion.network"},{prefix:2024,network:"vow-chain",displayName:"Enigmatic Smile",symbols:["VOW"],decimals:[18],standardAccount:"*25519",website:"https://www.vow.foundation/"},{prefix:2032,network:"interlay",displayName:"Interlay",symbols:["INTR"],decimals:[10],standardAccount:"*25519",website:"https://interlay.io/"},{prefix:2092,network:"kintsugi",displayName:"Kintsugi",symbols:["KINT"],decimals:[12],standardAccount:"*25519",website:"https://interlay.io/"},{prefix:2106,network:"bitgreen",displayName:"Bitgreen",symbols:["BBB"],decimals:[18],standardAccount:"*25519",website:"https://bitgreen.org/"},{prefix:2112,network:"chainflip",displayName:"Chainflip",symbols:["FLIP"],decimals:[18],standardAccount:"*25519",website:"https://chainflip.io/"},{prefix:2199,network:"moonsama",displayName:"Moonsama",symbols:["SAMA"],decimals:[18],standardAccount:"secp256k1",website:"https://moonsama.com"},{prefix:2206,network:"ICE",displayName:"ICE Network",symbols:["ICY"],decimals:[18],standardAccount:"*25519",website:"https://icenetwork.io"},{prefix:2207,network:"SNOW",displayName:"SNOW: ICE Canary Network",symbols:["ICZ"],decimals:[18],standardAccount:"*25519",website:"https://icenetwork.io"},{prefix:2254,network:"subspace_testnet",displayName:"Subspace testnet",symbols:["tSSC"],decimals:[18],standardAccount:"*25519",website:"https://subspace.network"},{prefix:3333,network:"peerplays",displayName:"Peerplays",symbols:["PPY"],decimals:[18],standardAccount:"secp256k1",website:"https://www.peerplays.com/"},{prefix:4450,network:"g1",displayName:"\u011E1",symbols:["G1"],decimals:[2],standardAccount:"*25519",website:"https://duniter.org"},{prefix:5234,network:"humanode",displayName:"Humanode Network",symbols:["HMND"],decimals:[18],standardAccount:"*25519",website:"https://humanode.io"},{prefix:5845,network:"tangle",displayName:"Tangle Network",symbols:["TNT"],decimals:[18],standardAccount:"*25519",website:"https://www.tangle.tools/"},{prefix:6094,network:"autonomys",displayName:"Autonomys",symbols:["AI3"],decimals:[18],standardAccount:"*25519",website:"https://autonomys.xyz"},{prefix:7007,network:"tidefi",displayName:"Tidefi",symbols:["TDFY"],decimals:[12],standardAccount:"*25519",website:"https://tidefi.com"},{prefix:7013,network:"gm",displayName:"GM",symbols:["FREN","GM","GN"],decimals:[12,0,0],standardAccount:"*25519",website:"https://gmordie.com"},{prefix:7306,network:"krigan",displayName:"Krigan Network",symbols:["KRGN"],decimals:[9],standardAccount:"*25519",website:"https://krigan.network"},{prefix:7391,network:"unique_mainnet",displayName:"Unique Network",symbols:["UNQ"],decimals:[18],standardAccount:"*25519",website:"https://unique.network"},{prefix:8866,network:"golden_gate",displayName:"Golden Gate",symbols:["GGX"],decimals:[18],standardAccount:"*25519",website:"https://ggxchain.io/"},{prefix:8883,network:"sapphire_mainnet",displayName:"Sapphire by Unique",symbols:["QTZ"],decimals:[18],standardAccount:"*25519",website:"https://unique.network"},{prefix:8886,network:"golden_gate_sydney",displayName:"Golden Gate Sydney",symbols:["GGXT"],decimals:[18],standardAccount:"*25519",website:"https://ggxchain.io/"},{prefix:9072,network:"hashed",displayName:"Hashed Network",symbols:["HASH"],decimals:[18],standardAccount:"*25519",website:"https://hashed.network"},{prefix:9807,network:"dentnet",displayName:"DENTNet",symbols:["DENTX"],decimals:[18],standardAccount:"*25519",website:"https://www.dentnet.io"},{prefix:9935,network:"t3rn",displayName:"t3rn",symbols:["TRN"],decimals:[12],standardAccount:"*25519",website:"https://t3rn.io/"},{prefix:10041,network:"basilisk",displayName:"Basilisk",symbols:["BSX"],decimals:[12],standardAccount:"*25519",website:"https://bsx.fi"},{prefix:11330,network:"cess-testnet",displayName:"CESS Testnet",symbols:["TCESS"],decimals:[18],standardAccount:"*25519",website:"https://cess.cloud"},{prefix:11331,network:"cess",displayName:"CESS",symbols:["CESS"],decimals:[18],standardAccount:"*25519",website:"https://cess.cloud"},{prefix:11486,network:"luhn",displayName:"Luhn Network",symbols:["LUHN"],decimals:[18],standardAccount:"*25519",website:"https://luhn.network"},{prefix:11820,network:"contextfree",displayName:"Automata ContextFree",symbols:["CTX"],decimals:[18],standardAccount:"*25519",website:"https://ata.network"},{prefix:12155,network:"impact",displayName:"Impact Protocol Network",symbols:["BSTY"],decimals:[18],standardAccount:"*25519",website:"https://impactprotocol.network/"},{prefix:12191,network:"nftmart",displayName:"NFTMart",symbols:["NMT"],decimals:[12],standardAccount:"*25519",website:"https://nftmart.io"},{prefix:12850,network:"analog-timechain",displayName:"Analog Timechain",symbols:["ANLOG"],decimals:[12],standardAccount:"*25519",website:"https://analog.one"},{prefix:13116,network:"bittensor",displayName:"Bittensor",symbols:["TAO"],decimals:[9],standardAccount:"*25519",website:"https://bittensor.com"},{prefix:14697,network:"goro",displayName:"GORO Network",symbols:["GORO"],decimals:[9],standardAccount:"*25519",website:"https://goro.network"},{prefix:14998,network:"mosaic-chain",displayName:"Mosaic Chain",symbols:["MOS"],decimals:[18],standardAccount:"*25519",website:"https://mosaicchain.io"},{prefix:29972,network:"mythos",displayName:"Mythos",symbols:["MYTH"],decimals:[18],standardAccount:"secp256k1",website:"https://mythos.foundation"},{prefix:8888,network:"xcavate",displayName:"Xcavate Protocol",symbols:["XCAV"],decimals:[12],standardAccount:"*25519",website:"https://xcavate.io/"}];var yi={acala:["0xfc41b9bd8ef8fe53d58c7ea67c794c7ec9a73daf05e6d54b14ff6342c99ba64c"],ajuna:["0xe358eb1d11b31255a286c12e44fe6780b7edb171d657905a97e39f71d9c6c3ee"],"aleph-node":["0x70255b4d28de0fc4e1a193d7e175ad1ccef431598211c55538f1018651a0344e"],astar:["0x9eb76c5184c4ab8679d2d5d819fdf90b9c001403e9e17da2e14b6d8aec4029c6"],basilisk:["0xa85cfb9b9fd4d622a5b28289a02347af987d8f73fa3108450e2b4a11c1ce5755"],bifrost:["0x262e1b2ad728475fd6fe88e62d34c200abe6fd693931ddad144059b1eb884e5b"],"bifrost-kusama":["0x9f28c6a68e0fc9646eff64935684f6eeeece527e37bbe1f213d22caa1d9d6bed"],bittensor:["0x2f0555cc76fc2840a25a6ea3b9637146806f1f44b090c175ffde2a7e5ab36c03"],centrifuge:["0xb3db41421702df9a7fcac62b53ffeac85f7853cc4e689e0b93aeb3db18c09d82","0x67dddf2673b69e5f875f6f25277495834398eafd67f492e09f3f3345e003d1b5"],cere:["0x81443836a9a24caaa23f1241897d1235717535711d1d3fe24eae4fdc942c092c"],composable:["0xdaab8df776eb52ec604a5df5d388bb62a050a0aaec4556a64265b9d42755552d"],creditcoin3:["0x4436a7d64e363df85e065a894721002a86643283f9707338bf195d360ba2ee71","0xfc4ec97a1c1f119c4353aecb4a17c7c0cf7b40d5d660143d8bad9117e9866572","0xfc9df99a665f964aed6649f275055e54df5e3420489538ed31d7788f53d11ef6"],darwinia:["0xe71578b37a7c799b0ab4ee87ffa6f059a6b98f71f06fb8c84a8d88013a548ad6"],dentnet:["0x0313f6a011d128d22f996703cbab05162e2fdc9e031493314fe6db79979c5ca7"],"dock-mainnet":["0x6bfe24dca2a3be10f22212678ac13a6446ec764103c0f3471c71609eac384aae","0xf73467c6544aa68df2ee546b135f955c46b90fa627e9b5d7935f41061bb8a5a9"],edgeware:["0x742a2ca70c2fda6cee4f8df98d64c4c670a052d9568058982dad9d5a7a135c5b"],encointer:["0x7dd99936c1e9e6d1ce7d90eb6f33bea8393b4bf87677d675aa63c9cb3e8c5b5b"],enjin:["0xd8761d3c88f26dc12875c00d3165f7d67243d56fc85b4cf19937601a7916e5a9"],equilibrium:["0x6f1a800de3daff7f5e037ddf66ab22ce03ab91874debeddb1086f5f7dbd48925"],frequency:["0x4a587bf17a404e3572747add7aab7bbe56e805a5479c6c436f07f36fcc8d3ae1"],genshiro:["0x9b8cefc0eb5c568b527998bdd76c184e2b76ae561be76e4667072230217ea243"],hydradx:["0xafdc188f45c71dacbaa0b62e16a91f726c7b8699a9748cdf715459de6b7f366d","0xd2a620c27ec5cbc5621ff9a522689895074f7cca0d08e7134a7804e1a3ba86fc","0x10af6e84234477d84dc572bac0789813b254aa490767ed06fb9591191d1073f9","0x3d75507dd46301767e601265791da1d9cb47b6ebc94e87347b635e5bf58bd047","0x0ed32bfcab4a83517fac88f2aa7cbc2f88d3ab93be9a12b6188a036bf8a943c2"],integritee:["0xcdedc8eadbfa209d3f207bba541e57c3c58a667b05a2e1d1e86353c9000758da","0xe13e7af377c64e83f95e0d70d5e5c3c01d697a84538776c5b9bbe0e7d7b6034c"],"interlay-parachain":["0xbf88efe70e9e0e916416e8bed61f2b45717f517d7f3523e33c7b001e5ffcbc72"],karura:["0xbaf5aabe40646d11f0ee8abbdc64f4a4b7674925cba08e4a05ff9ebed6e2126b"],khala:["0xd43540ba6d3eb4897c28a77d48cb5b729fea37603cbbfc7a86a73b72adb3be8d"],kulupu:["0xf7a99d3cb92853d00d5275c971c132c074636256583fee53b3bbe60d7b8769ba"],kusama:["0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe","0xe3777fa922cafbff200cadeaea1a76bd7898ad5b89f7848999058b50e715f636","0x3fd7b9eb6a00376e5be61f01abb429ffb0b104be05eaff4d458da48fcd425baf"],liberland:["0x6bd89e052d67a45bb60a9a23e8581053d5e0d619f15cb9865946937e690c42d6"],matrixchain:["0x3af4ff48ec76d2efc8476730f423ac07e25ad48f5f4c9dc39c778b164d808615"],mythos:["0xf6ee56e9c5277df5b4ce6ae9983ee88f3cbed27d31beeb98f9f84f997a1ab0b9"],nodle:["0x97da7ede98d7bad4e36b4d734b6055425a3be036da2a332ea5a7037656427a21"],origintrail:["0xe7e0962324a3b86c83404dbea483f25fb5dab4c224791c81b756cfc948006174"],p3d:["0x6c5894837ad89b6d92b114a2fb3eafa8fe3d26a54848e3447015442cd6ef4e66"],parallel:["0xe61a41c53f5dcd0beb09df93b34402aada44cb05117b71059cce40a2723a4e97"],peaq:["0xd2a5d385932d1f650dae03ef8e2748983779ee342c614f80854d32b8cd8fa48c"],pendulum:["0x5d3c298622d5634ed019bf61ea4b71655030015bde9beb0d6a24743714462c86"],phala:["0x1bb969d85965e4bb5a651abbedf21a54b6b31a21f66b5401cc3f1e286268d736"],picasso:["0x6811a339673c9daa897944dcdac99c6e2939cc88245ed21951a0a3c9a2be75bc","0xe8e7f0f4c4f5a00720b4821dbfddefea7490bcf0b19009961cc46957984e2c1c"],polimec:["0x7eb9354488318e7549c722669dcbdcdc526f1fef1420e7944667212f3601fdbd"],polkadex:["0x3920bcb4960a1eef5580cd5367ff3f430eef052774f78468852f7b9cb39f8a3c"],polkadot:["0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3"],polymesh:["0x6fbd74e5e1d0a61d52ccfe9d4adaed16dd3a7caa37c6bc4d0c2fa12e8b2f4063"],quartz:["0xcd4d732201ebe5d6b014edda071c4203e16867305332301dc8d092044b28e554"],rococo:["0x6408de7737c59c238890533af25896a2c20608d8b380bb01029acb392781063e","0xaaf2cd1b74b5f726895921259421b534124726263982522174147046b8827897","0x037f5f3c8e67b314062025fc886fcd6238ea25a4a9b45dce8d246815c9ebe770","0xc196f81260cf1686172b47a79cf002120735d7cb0eb1474e8adce56618456fff","0xf6e9983c37baf68846fedafe21e56718790e39fb1c582abc408b81bc7b208f9a","0x5fce687da39305dfe682b117f0820b319348e8bb37eb16cf34acbf6a202de9d9","0xe7c3d5edde7db964317cd9b51a3a059d7cd99f81bdbce14990047354334c9779","0x1611e1dbf0405379b861e2e27daa90f480b2e6d3682414a80835a52e8cb8a215","0x343442f12fa715489a8714e79a7b264ea88c0d5b8c66b684a7788a516032f6b9","0x78bcd530c6b3a068bc17473cf5d2aff9c287102bed9af3ae3c41c33b9d6c6147","0x47381ee0697153d64404fc578392c8fd5cba9073391908f46c888498415647bd","0x19c0e4fa8ab75f5ac7865e0b8f74ff91eb9a100d336f423cd013a8befba40299"],sora:["0x7e4e32d0feafd4f9c9414b0be86373f9a1efa904809b683453a9af6856d38ad5"],stafi:["0x290a4149f09ea0e402c74c1c7e96ae4239588577fe78932f94f5404c68243d80"],statemine:["0x48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a"],statemint:["0x68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f"],subsocial:["0x0bd72c1c305172e1275278aaeb3f161e02eccb7a819e63f62d47bd53a28189f8"],ternoa:["0x6859c81ca95ef624c9dfe4dc6e3381c33e5d6509e35e147092bfbc780f777c4e"],unique:["0x84322d9cddbf35088f1e54e9a85c967a41a56a4f43445768125e61af166c7d31"],vara:["0xfe1b4c55fd4d668101126434206571a7838a8b6b93a6d1b95d607e78e6c53763"],vtb:["0x286bc8414c7000ce1d6ee6a834e29a54c1784814b76243eb77ed0b2c5573c60f","0x7483b89572fb2bd687c7b9a93b242d0b237f9aba463aba07ec24503931038aaa"],westend:["0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e"],xxnetwork:["0x50dd5d206917bf10502c68fb4d18a59fc8aa31586f4e8856b493e43544aa82aa"],zeitgeist:["0x1bf2a2ecb4a868de66ea8610f2ce7c8c43706561b6476031315f6640fe38e060"]};var Qi={centrifuge:"polkadot",kusama:"polkadot",polkadot:"polkadot",sora:"polkadot",statemine:"polkadot",statemint:"polkadot",westmint:"polkadot"};var Ni={acala:787,ajuna:354,"aleph-node":643,astar:810,bifrost:788,"bifrost-kusama":788,bittensor:354,centrifuge:747,composable:354,creditcoin3:354,darwinia:354,dentnet:734,"dock-mainnet":594,edgeware:523,encointer:434,enjin:1155,equilibrium:99999997,frequency:2091,genshiro:99999996,hydradx:354,integritee:2015,"interlay-parachain":354,karura:686,khala:434,kusama:434,liberland:767,matrixchain:1155,mythos:60,nodle:1003,origintrail:354,parallel:354,peaq:3338,pendulum:354,phala:354,picasso:434,polimec:3344,polkadex:799,polkadot:354,polymesh:595,quartz:631,sora:617,stafi:907,statemine:434,statemint:354,ternoa:995,unique:661,vara:4976,vtb:694,xxnetwork:1955,zeitgeist:354};var Ei={"":!0,"cess-testnet":!0,"dock-testnet":!0,jupiter:!0,"mathchain-testnet":!0,p3dt:!0,subspace_testnet:!0,"zero-alphaville":!0};var Gy=[0,2,42],PH=["testnet"];function KH(l){let A=l.network||"",G=A.replace(/_/g,"-").split("-"),b=l;return b.slip44=Ni[A],b.hasLedgerSupport=!!b.slip44,b.genesisHash=yi[A]||[],b.icon=Qi[A]||"substrate",b.isTestnet=!!Ei[A]||PH.includes(G[G.length-1]),b.isIgnored=b.isTestnet||!(l.standardAccount&&l.decimals?.length&&l.symbols?.length)&&l.prefix!==42,b}function qH({genesisHash:l,prefix:A}){return!!l.length||A===42}function _H(l){return!l.isIgnored&&!!l.network}function $H(l,A){let G=Gy.includes(l.prefix),b=Gy.includes(A.prefix);return G===b?G?0:l.displayName.localeCompare(A.displayName):G?-1:1}var by=Ay.map(KH),zW=by.filter(_H).sort($H),l5=zW.filter(qH);var $Z={allowedDecodedLengths:[1,2,4,8,32,33],allowedEncodedLengths:[3,4,6,10,35,36,37,38],allowedPrefix:zW.map(({prefix:l})=>l),prefix:42};function Pt(l,A,G=-1){if(!l)throw new Error("Invalid empty address passed");if(Hb(l)||Vb(l))return Tl(l);try{let b=pi(l);if(!$Z.allowedEncodedLengths.includes(b.length))throw new Error("Invalid decoded address length");let[t,c,B,e]=ly(b);if(!t&&!A)throw new Error("Invalid decoded address checksum");if(G!==-1&&G!==e)throw new Error(`Expected ss58Format ${G}, received ${e}`);return b.slice(B,c)}catch(b){throw new Error(`Decoding ${l}: ${b.message}`)}}var vi={isLe:!1},jW={isLe:!0};var ty={bitLength:32,isLe:!1},MW={bitLength:32,isLe:!0},$c={bitLength:256,isLe:!1},cy={bitLength:256,isLe:!0};var A5=/^\d+$/,G5=32,ld,Fe,Hi=class Hi{constructor(){EG(this,ld,new Uint8Array(32));EG(this,Fe,!1)}static from(A){let G=new Hi,[b,t]=A.startsWith("/")?[A.substring(1),!0]:[A,!1];return G.soft(A5.test(b)?new pA.default(b,10):b),t?G.harden():G}get chainCode(){return GA(this,ld)}get isHard(){return GA(this,Fe)}get isSoft(){return!GA(this,Fe)}hard(A){return this.soft(A).harden()}harden(){return bG(this,Fe,!0),this}soft(A){return Ah(A)||vd(A)||kd(A)?this.soft(kG(A,cy)):Vb(A)?this.soft(vb(A)):lh(A)?this.soft(be(uG(A))):A.length>G5?this.soft(Mb(A)):(GA(this,ld).fill(0),GA(this,ld).set(A,0),this)}soften(){return bG(this,Fe,!1),this}};ld=new WeakMap,Fe=new WeakMap;var TW=Hi;var b5=/\/(\/?)([^/]+)/g;function kn(l){let A=l.match(b5),G=[],b="";if(A){b=A.join("");for(let t of A)G.push(TW.from(t.substring(1)))}if(b!==l)throw new Error(`Re-constructed path "${b}" does not match input`);return{parts:A,path:G}}var t5=/^((0x[a-fA-F0-9]+|[\p{L}\d]+(?: [\p{L}\d]+)*))((\/\/?[^/]+)*)(\/\/\/(.*))?$/u;function Ji(l){let G=l.normalize("NFC").match(t5);if(G===null)throw new Error("Unable to match provided value to a secret URI");let[,b,,t,,,c]=G,{path:B}=kn(t);return{derivePath:t,password:c,path:B,phrase:b}}var c5=be(uG("Secp256k1HDKD"));function By(l,A){if(!Hb(A)||A.length!==32)throw new Error("Invalid chainCode passed to derive");return Mb(nG(c5,l,A),256)}var B5=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),JB=new Uint32Array(64),DW=class extends yd{constructor(A=32){super(64,A,8,!1),this.A=vc[0]|0,this.B=vc[1]|0,this.C=vc[2]|0,this.D=vc[3]|0,this.E=vc[4]|0,this.F=vc[5]|0,this.G=vc[6]|0,this.H=vc[7]|0}get(){let{A,B:G,C:b,D:t,E:c,F:B,G:e,H:d}=this;return[A,G,b,t,c,B,e,d]}set(A,G,b,t,c,B,e,d){this.A=A|0,this.B=G|0,this.C=b|0,this.D=t|0,this.E=c|0,this.F=B|0,this.G=e|0,this.H=d|0}process(A,G){for(let n=0;n<16;n++,G+=4)JB[n]=A.getUint32(G,!1);for(let n=16;n<64;n++){let h=JB[n-15],W=JB[n-2],m=kt(h,7)^kt(h,18)^h>>>3,Y=kt(W,17)^kt(W,19)^W>>>10;JB[n]=Y+JB[n-7]+m+JB[n-16]|0}let{A:b,B:t,C:c,D:B,E:e,F:d,G:Z,H:g}=this;for(let n=0;n<64;n++){let h=kt(e,6)^kt(e,11)^kt(e,25),W=g+h+K2(e,d,Z)+B5[n]+JB[n]|0,Y=(kt(b,2)^kt(b,13)^kt(b,22))+q2(b,t,c)|0;g=Z,Z=d,d=e,e=B+W|0,B=c,c=t,t=b,b=W+Y|0}b=b+this.A|0,t=t+this.B|0,c=c+this.C|0,B=B+this.D|0,e=e+this.E|0,d=d+this.F|0,Z=Z+this.G|0,g=g+this.H|0,this.set(b,t,c,B,e,d,Z,g)}roundClean(){MG(JB)}destroy(){this.set(0,0,0,0,0,0,0,0),MG(this.buffer)}};var ey=Ia(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(l=>BigInt(l))),e5=ey[0],Z5=ey[1],xB=new Uint32Array(80),fB=new Uint32Array(80),LW=class extends yd{constructor(A=64){super(128,A,16,!1),this.Ah=mb[0]|0,this.Al=mb[1]|0,this.Bh=mb[2]|0,this.Bl=mb[3]|0,this.Ch=mb[4]|0,this.Cl=mb[5]|0,this.Dh=mb[6]|0,this.Dl=mb[7]|0,this.Eh=mb[8]|0,this.El=mb[9]|0,this.Fh=mb[10]|0,this.Fl=mb[11]|0,this.Gh=mb[12]|0,this.Gl=mb[13]|0,this.Hh=mb[14]|0,this.Hl=mb[15]|0}get(){let{Ah:A,Al:G,Bh:b,Bl:t,Ch:c,Cl:B,Dh:e,Dl:d,Eh:Z,El:g,Fh:n,Fl:h,Gh:W,Gl:m,Hh:Y,Hl:R}=this;return[A,G,b,t,c,B,e,d,Z,g,n,h,W,m,Y,R]}set(A,G,b,t,c,B,e,d,Z,g,n,h,W,m,Y,R){this.Ah=A|0,this.Al=G|0,this.Bh=b|0,this.Bl=t|0,this.Ch=c|0,this.Cl=B|0,this.Dh=e|0,this.Dl=d|0,this.Eh=Z|0,this.El=g|0,this.Fh=n|0,this.Fl=h|0,this.Gh=W|0,this.Gl=m|0,this.Hh=Y|0,this.Hl=R|0}process(A,G){for(let I=0;I<16;I++,G+=4)xB[I]=A.getUint32(G),fB[I]=A.getUint32(G+=4);for(let I=16;I<80;I++){let Q=xB[I-15]|0,f=fB[I-15]|0,U=cc(Q,f,1)^cc(Q,f,8)^zo(Q,f,7),J=Bc(Q,f,1)^Bc(Q,f,8)^jo(Q,f,7),M=xB[I-2]|0,C=fB[I-2]|0,D=cc(M,C,19)^Ae(M,C,61)^zo(M,C,6),$=Bc(M,C,19)^Ge(M,C,61)^jo(M,C,6),K=cV(J,$,fB[I-7],fB[I-16]),y=BV(K,U,D,xB[I-7],xB[I-16]);xB[I]=y|0,fB[I]=K|0}let{Ah:b,Al:t,Bh:c,Bl:B,Ch:e,Cl:d,Dh:Z,Dl:g,Eh:n,El:h,Fh:W,Fl:m,Gh:Y,Gl:R,Hh:u,Hl:i}=this;for(let I=0;I<80;I++){let Q=cc(n,h,14)^cc(n,h,18)^Ae(n,h,41),f=Bc(n,h,14)^Bc(n,h,18)^Ge(n,h,41),U=n&W^~n&Y,J=h&m^~h&R,M=eV(i,f,J,Z5[I],fB[I]),C=ZV(M,u,Q,U,e5[I],xB[I]),D=M|0,$=cc(b,t,28)^Ae(b,t,34)^Ae(b,t,39),K=Bc(b,t,28)^Ge(b,t,34)^Ge(b,t,39),y=b&c^b&e^c&e,r=t&B^t&d^B&d;u=Y|0,i=R|0,Y=W|0,R=m|0,W=n|0,m=h|0,{h:n,l:h}=Zt(Z|0,g|0,C|0,D|0),Z=e|0,g=d|0,e=c|0,d=B|0,c=b|0,B=t|0;let F=Qd(D,K,r);b=Nd(F,C,$,y),t=F|0}({h:b,l:t}=Zt(this.Ah|0,this.Al|0,b|0,t|0)),{h:c,l:B}=Zt(this.Bh|0,this.Bl|0,c|0,B|0),{h:e,l:d}=Zt(this.Ch|0,this.Cl|0,e|0,d|0),{h:Z,l:g}=Zt(this.Dh|0,this.Dl|0,Z|0,g|0),{h:n,l:h}=Zt(this.Eh|0,this.El|0,n|0,h|0),{h:W,l:m}=Zt(this.Fh|0,this.Fl|0,W|0,m|0),{h:Y,l:R}=Zt(this.Gh|0,this.Gl|0,Y|0,R|0),{h:u,l:i}=Zt(this.Hh|0,this.Hl|0,u|0,i|0),this.set(b,t,c,B,e,d,Z,g,n,h,W,m,Y,R,u,i)}roundClean(){MG(xB,fB)}destroy(){MG(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ye=Fd(()=>new DW);var OW=Fd(()=>new LW);var PW=class extends bc{constructor(A,G){super(),this.finished=!1,this.destroyed=!1,qe(A);let b=et(G);if(this.iHash=A.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;let t=this.blockLen,c=new Uint8Array(t);c.set(b.length>t?A.create().update(b).digest():b);for(let B=0;B<c.length;B++)c[B]^=54;this.iHash.update(c),this.oHash=A.create();for(let B=0;B<c.length;B++)c[B]^=106;this.oHash.update(c),MG(c)}update(A){return Xt(this),this.iHash.update(A),this}digestInto(A){Xt(this),fG(A,this.outputLen),this.finished=!0,this.iHash.digestInto(A),this.oHash.update(A),this.oHash.digestInto(A),this.destroy()}digest(){let A=new Uint8Array(this.oHash.outputLen);return this.digestInto(A),A}_cloneInto(A){A||(A=Object.create(Object.getPrototypeOf(this),{}));let{oHash:G,iHash:b,finished:t,destroyed:c,blockLen:B,outputLen:e}=this;return A=A,A.finished=t,A.destroyed=c,A.blockLen=B,A.outputLen=e,A.oHash=G._cloneInto(A.oHash),A.iHash=b._cloneInto(A.iHash),A}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Qe=(l,A,G)=>new PW(l,A).update(G).digest();Qe.create=(l,A)=>new PW(l,A);var ki=BigInt(0),fi=BigInt(1);function lB(l,A=""){if(typeof l!="boolean"){let G=A&&`"${A}"`;throw new Error(G+"expected boolean, got type="+typeof l)}return l}function mt(l,A,G=""){let b=ft(l),t=l?.length,c=A!==void 0;if(!b||c&&t!==A){let B=G&&`"${G}" `,e=c?` of length ${A}`:"",d=b?`length=${t}`:`type=${typeof l}`;throw new Error(B+"expected Uint8Array"+e+", got "+d)}return l}function Ad(l){let A=l.toString(16);return A.length&1?"0"+A:A}function wi(l){if(typeof l!="string")throw new Error("hex string expected, got "+typeof l);return l===""?ki:BigInt("0x"+l)}function Ne(l){return wi(Bt(l))}function Kt(l){return fG(l),wi(Bt(Uint8Array.from(l).reverse()))}function wn(l,A){return WB(l.toString(16).padStart(A*2,"0"))}function Un(l,A){return wn(l,A).reverse()}function ZG(l,A,G){let b;if(typeof A=="string")try{b=WB(A)}catch(c){throw new Error(l+" must be hex string or Uint8Array, cause: "+c)}else if(ft(A))b=Uint8Array.from(A);else throw new Error(l+" must be hex string or Uint8Array");let t=b.length;if(typeof G=="number"&&t!==G)throw new Error(l+" of length "+G+" expected, got "+t);return b}function Ui(l,A){if(l.length!==A.length)return!1;let G=0;for(let b=0;b<l.length;b++)G|=l[b]^A[b];return G===0}function KW(l){return Uint8Array.from(l)}var xi=l=>typeof l=="bigint"&&ki<=l;function Ci(l,A,G){return xi(l)&&xi(A)&&xi(G)&&A<=l&&l<G}function Ee(l,A,G,b){if(!Ci(A,G,b))throw new Error("expected valid "+l+": "+G+" <= n < "+b+", got "+A)}function Cn(l){let A;for(A=0;l>ki;l>>=fi,A+=1);return A}var Rc=l=>(fi<<BigInt(l))-fi;function Si(l,A,G){if(typeof l!="number"||l<2)throw new Error("hashLen must be a number");if(typeof A!="number"||A<2)throw new Error("qByteLen must be a number");if(typeof G!="function")throw new Error("hmacFn must be a function");let b=W=>new Uint8Array(W),t=W=>Uint8Array.of(W),c=b(l),B=b(l),e=0,d=()=>{c.fill(1),B.fill(0),e=0},Z=(...W)=>G(B,c,...W),g=(W=b(0))=>{B=Z(t(0),W),c=Z(),W.length!==0&&(B=Z(t(1),W),c=Z())},n=()=>{if(e++>=1e3)throw new Error("drbg: tried 1000 values");let W=0,m=[];for(;W<A;){c=Z();let Y=c.slice();m.push(Y),W+=c.length}return VG(...m)};return(W,m)=>{d(),g(W);let Y;for(;!(Y=m(n()));)g();return d(),Y}}function kB(l,A,G={}){if(!l||typeof l!="object")throw new Error("expected valid options object");function b(t,c,B){let e=l[t];if(B&&e===void 0)return;let d=typeof e;if(d!==c||e===null)throw new Error(`param "${t}" is invalid: expected ${c}, got ${d}`)}Object.entries(A).forEach(([t,c])=>b(t,c,!1)),Object.entries(G).forEach(([t,c])=>b(t,c,!0))}var qW=()=>{throw new Error("not implemented")};function ve(l){let A=new WeakMap;return(G,...b)=>{let t=A.get(G);if(t!==void 0)return t;let c=l(G,...b);return A.set(G,c),c}}var Db=BigInt(0),ob=BigInt(1),He=BigInt(2),ny=BigInt(3),ay=BigInt(4),gy=BigInt(5),a5=BigInt(7),Wy=BigInt(8),g5=BigInt(9),oy=BigInt(16);function IG(l,A){let G=l%A;return G>=Db?G:A+G}function RG(l,A,G){let b=l;for(;A-- >Db;)b*=b,b%=G;return b}function Zy(l,A){if(l===Db)throw new Error("invert: expected non-zero number");if(A<=Db)throw new Error("invert: expected positive modulus, got "+A);let G=IG(l,A),b=A,t=Db,c=ob,B=ob,e=Db;for(;G!==Db;){let Z=b/G,g=b%G,n=t-B*Z,h=c-e*Z;b=G,G=g,t=B,c=e,B=n,e=h}if(b!==ob)throw new Error("invert: does not exist");return IG(t,A)}function zi(l,A,G){if(!l.eql(l.sqr(A),G))throw new Error("Cannot find square root")}function hy(l,A){let G=(l.ORDER+ob)/ay,b=l.pow(A,G);return zi(l,b,A),b}function W5(l,A){let G=(l.ORDER-gy)/Wy,b=l.mul(A,He),t=l.pow(b,G),c=l.mul(A,t),B=l.mul(l.mul(c,He),t),e=l.mul(c,l.sub(B,l.ONE));return zi(l,e,A),e}function o5(l){let A=Vt(l),G=sy(l),b=G(A,A.neg(A.ONE)),t=G(A,b),c=G(A,A.neg(b)),B=(l+a5)/oy;return(e,d)=>{let Z=e.pow(d,B),g=e.mul(Z,b),n=e.mul(Z,t),h=e.mul(Z,c),W=e.eql(e.sqr(g),d),m=e.eql(e.sqr(n),d);Z=e.cmov(Z,g,W),g=e.cmov(h,n,m);let Y=e.eql(e.sqr(g),d),R=e.cmov(Z,g,Y);return zi(e,R,d),R}}function sy(l){if(l<ny)throw new Error("sqrt is not defined for small field");let A=l-ob,G=0;for(;A%He===Db;)A/=He,G++;let b=He,t=Vt(l);for(;dy(t,b)===1;)if(b++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(G===1)return hy;let c=t.pow(b,A),B=(A+ob)/He;return function(d,Z){if(d.is0(Z))return Z;if(dy(d,Z)!==1)throw new Error("Cannot find square root");let g=G,n=d.mul(d.ONE,c),h=d.pow(Z,A),W=d.pow(Z,B);for(;!d.eql(h,d.ONE);){if(d.is0(h))return d.ZERO;let m=1,Y=d.sqr(h);for(;!d.eql(Y,d.ONE);)if(m++,Y=d.sqr(Y),m===g)throw new Error("Cannot find square root");let R=ob<<BigInt(g-m-1),u=d.pow(n,R);g=m,n=d.sqr(u),h=d.mul(h,n),W=d.mul(W,u)}return W}}function h5(l){return l%ay===ny?hy:l%Wy===gy?W5:l%oy===g5?o5(l):sy(l)}var AB=(l,A)=>(IG(l,A)&ob)===ob,s5=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ji(l){let A={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},G=s5.reduce((b,t)=>(b[t]="function",b),A);return kB(l,G),l}function r5(l,A,G){if(G<Db)throw new Error("invalid exponent, negatives unsupported");if(G===Db)return l.ONE;if(G===ob)return A;let b=l.ONE,t=A;for(;G>Db;)G&ob&&(b=l.mul(b,t)),t=l.sqr(t),G>>=ob;return b}function Sn(l,A,G=!1){let b=new Array(A.length).fill(G?l.ZERO:void 0),t=A.reduce((B,e,d)=>l.is0(e)?B:(b[d]=B,l.mul(B,e)),l.ONE),c=l.inv(t);return A.reduceRight((B,e,d)=>l.is0(e)?B:(b[d]=l.mul(B,b[d]),l.mul(B,e)),c),b}function dy(l,A){let G=(l.ORDER-ob)/He,b=l.pow(A,G),t=l.eql(b,l.ONE),c=l.eql(b,l.ZERO),B=l.eql(b,l.neg(l.ONE));if(!t&&!c&&!B)throw new Error("invalid Legendre symbol result");return t?1:c?0:-1}function _W(l,A){A!==void 0&&mG(A);let G=A!==void 0?A:l.toString(2).length,b=Math.ceil(G/8);return{nBitLength:G,nByteLength:b}}function Vt(l,A,G=!1,b={}){if(l<=Db)throw new Error("invalid field: expected ORDER > 0, got "+l);let t,c,B=!1,e;if(typeof A=="object"&&A!=null){if(b.sqrt||G)throw new Error("cannot specify opts in two arguments");let h=A;h.BITS&&(t=h.BITS),h.sqrt&&(c=h.sqrt),typeof h.isLE=="boolean"&&(G=h.isLE),typeof h.modFromBytes=="boolean"&&(B=h.modFromBytes),e=h.allowedLengths}else typeof A=="number"&&(t=A),b.sqrt&&(c=b.sqrt);let{nBitLength:d,nByteLength:Z}=_W(l,t);if(Z>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let g,n=Object.freeze({ORDER:l,isLE:G,BITS:d,BYTES:Z,MASK:Rc(d),ZERO:Db,ONE:ob,allowedLengths:e,create:h=>IG(h,l),isValid:h=>{if(typeof h!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof h);return Db<=h&&h<l},is0:h=>h===Db,isValidNot0:h=>!n.is0(h)&&n.isValid(h),isOdd:h=>(h&ob)===ob,neg:h=>IG(-h,l),eql:(h,W)=>h===W,sqr:h=>IG(h*h,l),add:(h,W)=>IG(h+W,l),sub:(h,W)=>IG(h-W,l),mul:(h,W)=>IG(h*W,l),pow:(h,W)=>r5(n,h,W),div:(h,W)=>IG(h*Zy(W,l),l),sqrN:h=>h*h,addN:(h,W)=>h+W,subN:(h,W)=>h-W,mulN:(h,W)=>h*W,inv:h=>Zy(h,l),sqrt:c||(h=>(g||(g=h5(l)),g(n,h))),toBytes:h=>G?Un(h,Z):wn(h,Z),fromBytes:(h,W=!0)=>{if(e){if(!e.includes(h.length)||h.length>Z)throw new Error("Field.fromBytes: expected "+e+" bytes, got "+h.length);let Y=new Uint8Array(Z);Y.set(h,G?0:Y.length-h.length),h=Y}if(h.length!==Z)throw new Error("Field.fromBytes: expected "+Z+" bytes, got "+h.length);let m=G?Kt(h):Ne(h);if(B&&(m=IG(m,l)),!W&&!n.isValid(m))throw new Error("invalid field element: outside of range 0..ORDER");return m},invertBatch:h=>Sn(n,h),cmov:(h,W,m)=>m?W:h});return Object.freeze(n)}function ry(l){if(typeof l!="bigint")throw new Error("field order must be bigint");let A=l.toString(2).length;return Math.ceil(A/8)}function Mi(l){let A=ry(l);return A+Math.ceil(A/2)}function Ti(l,A,G=!1){let b=l.length,t=ry(A),c=Mi(A);if(b<16||b<c||b>1024)throw new Error("expected "+c+"-1024 bytes of input, got "+b);let B=G?Kt(l):Ne(l),e=IG(B,A-ob)+ob;return G?Un(e,t):wn(e,t)}var Gd=BigInt(0),Je=BigInt(1);function zn(l,A){let G=A.negate();return l?G:A}function GB(l,A){let G=Sn(l.Fp,A.map(b=>b.Z));return A.map((b,t)=>l.fromAffine(b.toAffine(G[t])))}function uy(l,A){if(!Number.isSafeInteger(l)||l<=0||l>A)throw new Error("invalid window size, expected [1.."+A+"], got W="+l)}function Di(l,A){uy(l,A);let G=Math.ceil(A/l)+1,b=2**(l-1),t=2**l,c=Rc(l),B=BigInt(l);return{windows:G,windowSize:b,mask:c,maxNumber:t,shiftBy:B}}function iy(l,A,G){let{windowSize:b,mask:t,maxNumber:c,shiftBy:B}=G,e=Number(l&t),d=l>>B;e>b&&(e-=c,d+=Je);let Z=A*b,g=Z+Math.abs(e)-1,n=e===0,h=e<0,W=A%2!==0;return{nextN:d,offset:g,isZero:n,isNeg:h,isNegF:W,offsetF:Z}}function m5(l,A){if(!Array.isArray(l))throw new Error("array expected");l.forEach((G,b)=>{if(!(G instanceof A))throw new Error("invalid point at index "+b)})}function V5(l,A){if(!Array.isArray(l))throw new Error("array of scalars expected");l.forEach((G,b)=>{if(!A.isValid(G))throw new Error("invalid scalar at index "+b)})}var Li=new WeakMap,Yy=new WeakMap;function Oi(l){return Yy.get(l)||1}function my(l){if(l!==Gd)throw new Error("invalid wNAF")}var bd=class{constructor(A,G){this.BASE=A.BASE,this.ZERO=A.ZERO,this.Fn=A.Fn,this.bits=G}_unsafeLadder(A,G,b=this.ZERO){let t=A;for(;G>Gd;)G&Je&&(b=b.add(t)),t=t.double(),G>>=Je;return b}precomputeWindow(A,G){let{windows:b,windowSize:t}=Di(G,this.bits),c=[],B=A,e=B;for(let d=0;d<b;d++){e=B,c.push(e);for(let Z=1;Z<t;Z++)e=e.add(B),c.push(e);B=e.double()}return c}wNAF(A,G,b){if(!this.Fn.isValid(b))throw new Error("invalid scalar");let t=this.ZERO,c=this.BASE,B=Di(A,this.bits);for(let e=0;e<B.windows;e++){let{nextN:d,offset:Z,isZero:g,isNeg:n,isNegF:h,offsetF:W}=iy(b,e,B);b=d,g?c=c.add(zn(h,G[W])):t=t.add(zn(n,G[Z]))}return my(b),{p:t,f:c}}wNAFUnsafe(A,G,b,t=this.ZERO){let c=Di(A,this.bits);for(let B=0;B<c.windows&&b!==Gd;B++){let{nextN:e,offset:d,isZero:Z,isNeg:g}=iy(b,B,c);if(b=e,!Z){let n=G[d];t=t.add(g?n.negate():n)}}return my(b),t}getPrecomputes(A,G,b){let t=Li.get(G);return t||(t=this.precomputeWindow(G,A),A!==1&&(typeof b=="function"&&(t=b(t)),Li.set(G,t))),t}cached(A,G,b){let t=Oi(A);return this.wNAF(t,this.getPrecomputes(t,A,b),G)}unsafe(A,G,b,t){let c=Oi(A);return c===1?this._unsafeLadder(A,G,t):this.wNAFUnsafe(c,this.getPrecomputes(c,A,b),G,t)}createCache(A,G){uy(G,this.bits),Yy.set(A,G),Li.delete(A)}hasCache(A){return Oi(A)!==1}};function Iy(l,A,G,b){let t=A,c=l.ZERO,B=l.ZERO;for(;G>Gd||b>Gd;)G&Je&&(c=c.add(t)),b&Je&&(B=B.add(t)),t=t.double(),G>>=Je,b>>=Je;return{p1:c,p2:B}}function td(l,A,G,b){m5(G,l),V5(b,A);let t=G.length,c=b.length;if(t!==c)throw new Error("arrays of points and scalars must have equal length");let B=l.ZERO,e=Cn(BigInt(t)),d=1;e>12?d=e-3:e>4?d=e-2:e>0&&(d=2);let Z=Rc(d),g=new Array(Number(Z)+1).fill(B),n=Math.floor((A.BITS-1)/d)*d,h=B;for(let W=n;W>=0;W-=d){g.fill(B);for(let Y=0;Y<c;Y++){let R=b[Y],u=Number(R>>BigInt(W)&Z);g[u]=g[u].add(G[Y])}let m=B;for(let Y=g.length-1,R=B;Y>0;Y--)R=R.add(g[Y]),m=m.add(R);if(h=h.add(m),W!==0)for(let Y=0;Y<d;Y++)h=h.double()}return h}function Vy(l,A,G){if(A){if(A.ORDER!==l)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ji(A),A}else return Vt(l,{isLE:G})}function $W(l,A,G={},b){if(b===void 0&&(b=l==="edwards"),!A||typeof A!="object")throw new Error(`expected valid ${l} CURVE object`);for(let d of["p","n","h"]){let Z=A[d];if(!(typeof Z=="bigint"&&Z>Gd))throw new Error(`CURVE.${d} must be positive bigint`)}let t=Vy(A.p,G.Fp,b),c=Vy(A.n,G.Fn,b),e=["Gx","Gy","a",l==="weierstrass"?"b":"d"];for(let d of e)if(!t.isValid(A[d]))throw new Error(`CURVE.${d} must be valid field element of CURVE.Fp`);return A=Object.freeze(Object.assign({},A)),{CURVE:A,Fp:t,Fn:c}}var Ry=(l,A)=>(l+(l>=0?A:-A)/Xy)/A;function u5(l,A,G){let[[b,t],[c,B]]=A,e=Ry(B*l,G),d=Ry(-t*l,G),Z=l-e*b-d*c,g=-e*t-d*B,n=Z<tB,h=g<tB;n&&(Z=-Z),h&&(g=-g);let W=Rc(Math.ceil(Cn(G)/2))+Bd;if(Z<tB||Z>=W||g<tB||g>=W)throw new Error("splitScalar (endomorphism): failed, k="+l);return{k1neg:n,k1:Z,k2neg:h,k2:g}}function Ki(l){if(!["compact","recovered","der"].includes(l))throw new Error('Signature format must be "compact", "recovered", or "der"');return l}function Pi(l,A){let G={};for(let b of Object.keys(A))G[b]=l[b]===void 0?A[b]:l[b];return lB(G.lowS,"lowS"),lB(G.prehash,"prehash"),G.format!==void 0&&Ki(G.format),G}var qi=class extends Error{constructor(A=""){super(A)}},bB={Err:qi,_tlv:{encode:(l,A)=>{let{Err:G}=bB;if(l<0||l>256)throw new G("tlv.encode: wrong tag");if(A.length&1)throw new G("tlv.encode: unpadded data");let b=A.length/2,t=Ad(b);if(t.length/2&128)throw new G("tlv.encode: long form length too big");let c=b>127?Ad(t.length/2|128):"";return Ad(l)+c+t+A},decode(l,A){let{Err:G}=bB,b=0;if(l<0||l>256)throw new G("tlv.encode: wrong tag");if(A.length<2||A[b++]!==l)throw new G("tlv.decode: wrong tlv");let t=A[b++],c=!!(t&128),B=0;if(!c)B=t;else{let d=t&127;if(!d)throw new G("tlv.decode(long): indefinite length not supported");if(d>4)throw new G("tlv.decode(long): byte length is too big");let Z=A.subarray(b,b+d);if(Z.length!==d)throw new G("tlv.decode: length bytes not complete");if(Z[0]===0)throw new G("tlv.decode(long): zero leftmost byte");for(let g of Z)B=B<<8|g;if(b+=d,B<128)throw new G("tlv.decode(long): not minimal encoding")}let e=A.subarray(b,b+B);if(e.length!==B)throw new G("tlv.decode: wrong value length");return{v:e,l:A.subarray(b+B)}}},_int:{encode(l){let{Err:A}=bB;if(l<tB)throw new A("integer: negative integers are not allowed");let G=Ad(l);if(Number.parseInt(G[0],16)&8&&(G="00"+G),G.length&1)throw new A("unexpected DER parsing assertion: unpadded hex");return G},decode(l){let{Err:A}=bB;if(l[0]&128)throw new A("invalid signature integer: negative");if(l[0]===0&&!(l[1]&128))throw new A("invalid signature integer: unnecessary leading zero");return Ne(l)}},toSig(l){let{Err:A,_int:G,_tlv:b}=bB,t=ZG("signature",l),{v:c,l:B}=b.decode(48,t);if(B.length)throw new A("invalid signature: left bytes after parsing");let{v:e,l:d}=b.decode(2,c),{v:Z,l:g}=b.decode(2,d);if(g.length)throw new A("invalid signature: left bytes after parsing");return{r:G.decode(e),s:G.decode(Z)}},hexFromSig(l){let{_tlv:A,_int:G}=bB,b=A.encode(2,G.encode(l.r)),t=A.encode(2,G.encode(l.s)),c=b+t;return A.encode(48,c)}},tB=BigInt(0),Bd=BigInt(1),Xy=BigInt(2),lo=BigInt(3),Y5=BigInt(4);function cd(l,A){let{BYTES:G}=l,b;if(typeof A=="bigint")b=A;else{let t=ZG("private key",A);try{b=l.fromBytes(t)}catch{throw new Error(`invalid private key: expected ui8a of size ${G}, got ${typeof A}`)}}if(!l.isValidNot0(b))throw new Error("invalid private key: out of range [1..N-1]");return b}function I5(l,A={}){let G=$W("weierstrass",l,A),{Fp:b,Fn:t}=G,c=G.CURVE,{h:B,n:e}=c;kB(A,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:d}=A;if(d&&(!b.is0(c.a)||typeof d.beta!="bigint"||!Array.isArray(d.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let Z=Fy(b,t);function g(){if(!b.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function n(K,y,r){let{x:F,y:E}=y.toAffine(),x=b.toBytes(F);if(lB(r,"isCompressed"),r){g();let s=!b.isOdd(E);return VG(py(s),x)}else return VG(Uint8Array.of(4),x,b.toBytes(E))}function h(K){mt(K,void 0,"Point");let{publicKey:y,publicKeyUncompressed:r}=Z,F=K.length,E=K[0],x=K.subarray(1);if(F===y&&(E===2||E===3)){let s=b.fromBytes(x);if(!b.isValid(s))throw new Error("bad point: is not on curve, wrong x");let p=Y(s),X;try{X=b.sqrt(p)}catch(V){let v=V instanceof Error?": "+V.message:"";throw new Error("bad point: is not on curve, sqrt error"+v)}g();let o=b.isOdd(X);return(E&1)===1!==o&&(X=b.neg(X)),{x:s,y:X}}else if(F===r&&E===4){let s=b.BYTES,p=b.fromBytes(x.subarray(0,s)),X=b.fromBytes(x.subarray(s,s*2));if(!R(p,X))throw new Error("bad point: is not on curve");return{x:p,y:X}}else throw new Error(`bad point: got length ${F}, expected compressed=${y} or uncompressed=${r}`)}let W=A.toBytes||n,m=A.fromBytes||h;function Y(K){let y=b.sqr(K),r=b.mul(y,K);return b.add(b.add(r,b.mul(K,c.a)),c.b)}function R(K,y){let r=b.sqr(y),F=Y(K);return b.eql(r,F)}if(!R(c.Gx,c.Gy))throw new Error("bad curve params: generator point");let u=b.mul(b.pow(c.a,lo),Y5),i=b.mul(b.sqr(c.b),BigInt(27));if(b.is0(b.add(u,i)))throw new Error("bad curve params: a or b");function I(K,y,r=!1){if(!b.isValid(y)||r&&b.is0(y))throw new Error(`bad point coordinate ${K}`);return y}function Q(K){if(!(K instanceof C))throw new Error("ProjectivePoint expected")}function f(K){if(!d||!d.basises)throw new Error("no endo");return u5(K,d.basises,t.ORDER)}let U=ve((K,y)=>{let{X:r,Y:F,Z:E}=K;if(b.eql(E,b.ONE))return{x:r,y:F};let x=K.is0();y==null&&(y=x?b.ONE:b.inv(E));let s=b.mul(r,y),p=b.mul(F,y),X=b.mul(E,y);if(x)return{x:b.ZERO,y:b.ZERO};if(!b.eql(X,b.ONE))throw new Error("invZ was invalid");return{x:s,y:p}}),J=ve(K=>{if(K.is0()){if(A.allowInfinityPoint&&!b.is0(K.Y))return;throw new Error("bad point: ZERO")}let{x:y,y:r}=K.toAffine();if(!b.isValid(y)||!b.isValid(r))throw new Error("bad point: x or y not field elements");if(!R(y,r))throw new Error("bad point: equation left != right");if(!K.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function M(K,y,r,F,E){return r=new C(b.mul(r.X,K),r.Y,r.Z),y=zn(F,y),r=zn(E,r),y.add(r)}class C{constructor(y,r,F){this.X=I("x",y),this.Y=I("y",r,!0),this.Z=I("z",F),Object.freeze(this)}static CURVE(){return c}static fromAffine(y){let{x:r,y:F}=y||{};if(!y||!b.isValid(r)||!b.isValid(F))throw new Error("invalid affine point");if(y instanceof C)throw new Error("projective point not allowed");return b.is0(r)&&b.is0(F)?C.ZERO:new C(r,F,b.ONE)}static fromBytes(y){let r=C.fromAffine(m(mt(y,void 0,"point")));return r.assertValidity(),r}static fromHex(y){return C.fromBytes(ZG("pointHex",y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,r=!0){return $.createCache(this,y),r||this.multiply(lo),this}assertValidity(){J(this)}hasEvenY(){let{y}=this.toAffine();if(!b.isOdd)throw new Error("Field doesn't support isOdd");return!b.isOdd(y)}equals(y){Q(y);let{X:r,Y:F,Z:E}=this,{X:x,Y:s,Z:p}=y,X=b.eql(b.mul(r,p),b.mul(x,E)),o=b.eql(b.mul(F,p),b.mul(s,E));return X&&o}negate(){return new C(this.X,b.neg(this.Y),this.Z)}double(){let{a:y,b:r}=c,F=b.mul(r,lo),{X:E,Y:x,Z:s}=this,p=b.ZERO,X=b.ZERO,o=b.ZERO,a=b.mul(E,E),V=b.mul(x,x),v=b.mul(s,s),S=b.mul(E,x);return S=b.add(S,S),o=b.mul(E,s),o=b.add(o,o),p=b.mul(y,o),X=b.mul(F,v),X=b.add(p,X),p=b.sub(V,X),X=b.add(V,X),X=b.mul(p,X),p=b.mul(S,p),o=b.mul(F,o),v=b.mul(y,v),S=b.sub(a,v),S=b.mul(y,S),S=b.add(S,o),o=b.add(a,a),a=b.add(o,a),a=b.add(a,v),a=b.mul(a,S),X=b.add(X,a),v=b.mul(x,s),v=b.add(v,v),a=b.mul(v,S),p=b.sub(p,a),o=b.mul(v,V),o=b.add(o,o),o=b.add(o,o),new C(p,X,o)}add(y){Q(y);let{X:r,Y:F,Z:E}=this,{X:x,Y:s,Z:p}=y,X=b.ZERO,o=b.ZERO,a=b.ZERO,V=c.a,v=b.mul(c.b,lo),S=b.mul(r,x),z=b.mul(F,s),q=b.mul(E,p),_=b.add(r,F),T=b.add(x,s);_=b.mul(_,T),T=b.add(S,z),_=b.sub(_,T),T=b.add(r,E);let H=b.add(x,p);return T=b.mul(T,H),H=b.add(S,q),T=b.sub(T,H),H=b.add(F,E),X=b.add(s,p),H=b.mul(H,X),X=b.add(z,q),H=b.sub(H,X),a=b.mul(V,T),X=b.mul(v,q),a=b.add(X,a),X=b.sub(z,a),a=b.add(z,a),o=b.mul(X,a),z=b.add(S,S),z=b.add(z,S),q=b.mul(V,q),T=b.mul(v,T),z=b.add(z,q),q=b.sub(S,q),q=b.mul(V,q),T=b.add(T,q),S=b.mul(z,T),o=b.add(o,S),S=b.mul(H,T),X=b.mul(_,X),X=b.sub(X,S),S=b.mul(_,z),a=b.mul(H,a),a=b.add(a,S),new C(X,o,a)}subtract(y){return this.add(y.negate())}is0(){return this.equals(C.ZERO)}multiply(y){let{endo:r}=A;if(!t.isValidNot0(y))throw new Error("invalid scalar: out of range");let F,E,x=s=>$.cached(this,s,p=>GB(C,p));if(r){let{k1neg:s,k1:p,k2neg:X,k2:o}=f(y),{p:a,f:V}=x(p),{p:v,f:S}=x(o);E=V.add(S),F=M(r.beta,a,v,s,X)}else{let{p:s,f:p}=x(y);F=s,E=p}return GB(C,[F,E])[0]}multiplyUnsafe(y){let{endo:r}=A,F=this;if(!t.isValid(y))throw new Error("invalid scalar: out of range");if(y===tB||F.is0())return C.ZERO;if(y===Bd)return F;if($.hasCache(this))return this.multiply(y);if(r){let{k1neg:E,k1:x,k2neg:s,k2:p}=f(y),{p1:X,p2:o}=Iy(C,F,x,p);return M(r.beta,X,o,E,s)}else return $.unsafe(F,y)}multiplyAndAddUnsafe(y,r,F){let E=this.multiplyUnsafe(r).add(y.multiplyUnsafe(F));return E.is0()?void 0:E}toAffine(y){return U(this,y)}isTorsionFree(){let{isTorsionFree:y}=A;return B===Bd?!0:y?y(C,this):$.unsafe(this,e).is0()}clearCofactor(){let{clearCofactor:y}=A;return B===Bd?this:y?y(C,this):this.multiplyUnsafe(B)}isSmallOrder(){return this.multiplyUnsafe(B).is0()}toBytes(y=!0){return lB(y,"isCompressed"),this.assertValidity(),W(C,this,y)}toHex(y=!0){return Bt(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(y=!0){return this.toBytes(y)}_setWindowSize(y){this.precompute(y)}static normalizeZ(y){return GB(C,y)}static msm(y,r){return td(C,t,y,r)}static fromPrivateKey(y){return C.BASE.multiply(cd(t,y))}}C.BASE=new C(c.Gx,c.Gy,b.ONE),C.ZERO=new C(b.ZERO,b.ONE,b.ZERO),C.Fp=b,C.Fn=t;let D=t.BITS,$=new bd(C,A.endo?Math.ceil(D/2):D);return C.BASE.precompute(8),C}function py(l){return Uint8Array.of(l?2:3)}function Fy(l,A){return{secretKey:A.BYTES,publicKey:1+l.BYTES,publicKeyUncompressed:1+2*l.BYTES,publicKeyHasPrefix:!0,signature:2*A.BYTES}}function R5(l,A={}){let{Fn:G}=l,b=A.randomBytes||Eb,t=Object.assign(Fy(l.Fp,G),{seed:Mi(G.ORDER)});function c(W){try{return!!cd(G,W)}catch{return!1}}function B(W,m){let{publicKey:Y,publicKeyUncompressed:R}=t;try{let u=W.length;return m===!0&&u!==Y||m===!1&&u!==R?!1:!!l.fromBytes(W)}catch{return!1}}function e(W=b(t.seed)){return Ti(mt(W,t.seed,"seed"),G.ORDER)}function d(W,m=!0){return l.BASE.multiply(cd(G,W)).toBytes(m)}function Z(W){let m=e(W);return{secretKey:m,publicKey:d(m)}}function g(W){if(typeof W=="bigint")return!1;if(W instanceof l)return!0;let{secretKey:m,publicKey:Y,publicKeyUncompressed:R}=t;if(G.allowedLengths||m===Y)return;let u=ZG("key",W).length;return u===Y||u===R}function n(W,m,Y=!0){if(g(W)===!0)throw new Error("first arg must be private key");if(g(m)===!1)throw new Error("second arg must be public key");let R=cd(G,W);return l.fromHex(m).multiply(R).toBytes(Y)}return Object.freeze({getPublicKey:d,getSharedSecret:n,keygen:Z,Point:l,utils:{isValidSecretKey:c,isValidPublicKey:B,randomSecretKey:e,isValidPrivateKey:c,randomPrivateKey:e,normPrivateKeyToScalar:W=>cd(G,W),precompute(W=8,m=l.BASE){return m.precompute(W,!1)}},lengths:t})}function X5(l,A,G={}){qe(A),kB(G,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let b=G.randomBytes||Eb,t=G.hmac||((r,...F)=>Qe(A,r,VG(...F))),{Fp:c,Fn:B}=l,{ORDER:e,BITS:d}=B,{keygen:Z,getPublicKey:g,getSharedSecret:n,utils:h,lengths:W}=R5(l,G),m={prehash:!1,lowS:typeof G.lowS=="boolean"?G.lowS:!1,format:void 0,extraEntropy:!1},Y="compact";function R(r){let F=e>>Bd;return r>F}function u(r,F){if(!B.isValidNot0(F))throw new Error(`invalid signature ${r}: out of range 1..Point.Fn.ORDER`);return F}function i(r,F){Ki(F);let E=W.signature,x=F==="compact"?E:F==="recovered"?E+1:void 0;return mt(r,x,`${F} signature`)}class I{constructor(F,E,x){this.r=u("r",F),this.s=u("s",E),x!=null&&(this.recovery=x),Object.freeze(this)}static fromBytes(F,E=Y){i(F,E);let x;if(E==="der"){let{r:o,s:a}=bB.toSig(mt(F));return new I(o,a)}E==="recovered"&&(x=F[0],E="compact",F=F.subarray(1));let s=B.BYTES,p=F.subarray(0,s),X=F.subarray(s,s*2);return new I(B.fromBytes(p),B.fromBytes(X),x)}static fromHex(F,E){return this.fromBytes(WB(F),E)}addRecoveryBit(F){return new I(this.r,this.s,F)}recoverPublicKey(F){let E=c.ORDER,{r:x,s,recovery:p}=this;if(p==null||![0,1,2,3].includes(p))throw new Error("recovery id invalid");if(e*Xy<E&&p>1)throw new Error("recovery id is ambiguous for h>1 curve");let o=p===2||p===3?x+e:x;if(!c.isValid(o))throw new Error("recovery id 2 or 3 invalid");let a=c.toBytes(o),V=l.fromBytes(VG(py((p&1)===0),a)),v=B.inv(o),S=f(ZG("msgHash",F)),z=B.create(-S*v),q=B.create(s*v),_=l.BASE.multiplyUnsafe(z).add(V.multiplyUnsafe(q));if(_.is0())throw new Error("point at infinify");return _.assertValidity(),_}hasHighS(){return R(this.s)}toBytes(F=Y){if(Ki(F),F==="der")return WB(bB.hexFromSig(this));let E=B.toBytes(this.r),x=B.toBytes(this.s);if(F==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return VG(Uint8Array.of(this.recovery),E,x)}return VG(E,x)}toHex(F){return Bt(this.toBytes(F))}assertValidity(){}static fromCompact(F){return I.fromBytes(ZG("sig",F),"compact")}static fromDER(F){return I.fromBytes(ZG("sig",F),"der")}normalizeS(){return this.hasHighS()?new I(this.r,B.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Bt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Bt(this.toBytes("compact"))}}let Q=G.bits2int||function(F){if(F.length>8192)throw new Error("input is too large");let E=Ne(F),x=F.length*8-d;return x>0?E>>BigInt(x):E},f=G.bits2int_modN||function(F){return B.create(Q(F))},U=Rc(d);function J(r){return Ee("num < 2^"+d,r,tB,U),B.toBytes(r)}function M(r,F){return mt(r,void 0,"message"),F?mt(A(r),void 0,"prehashed message"):r}function C(r,F,E){if(["recovered","canonical"].some(z=>z in E))throw new Error("sign() legacy options not supported");let{lowS:x,prehash:s,extraEntropy:p}=Pi(E,m);r=M(r,s);let X=f(r),o=cd(B,F),a=[J(o),J(X)];if(p!=null&&p!==!1){let z=p===!0?b(W.secretKey):p;a.push(ZG("extraEntropy",z))}let V=VG(...a),v=X;function S(z){let q=Q(z);if(!B.isValidNot0(q))return;let _=B.inv(q),T=l.BASE.multiply(q).toAffine(),H=B.create(T.x);if(H===tB)return;let w=B.create(_*B.create(v+H*o));if(w===tB)return;let L=(T.x===H?0:2)|Number(T.y&Bd),ll=w;return x&&R(w)&&(ll=B.neg(w),L^=1),new I(H,ll,L)}return{seed:V,k2sig:S}}function D(r,F,E={}){r=ZG("message",r);let{seed:x,k2sig:s}=C(r,F,E);return Si(A.outputLen,B.BYTES,t)(x,s)}function $(r){let F,E=typeof r=="string"||ft(r),x=!E&&r!==null&&typeof r=="object"&&typeof r.r=="bigint"&&typeof r.s=="bigint";if(!E&&!x)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(x)F=new I(r.r,r.s);else if(E){try{F=I.fromBytes(ZG("sig",r),"der")}catch(s){if(!(s instanceof bB.Err))throw s}if(!F)try{F=I.fromBytes(ZG("sig",r),"compact")}catch{return!1}}return F||!1}function K(r,F,E,x={}){let{lowS:s,prehash:p,format:X}=Pi(x,m);if(E=ZG("publicKey",E),F=M(ZG("message",F),p),"strict"in x)throw new Error("options.strict was renamed to lowS");let o=X===void 0?$(r):I.fromBytes(ZG("sig",r),X);if(o===!1)return!1;try{let a=l.fromBytes(E);if(s&&o.hasHighS())return!1;let{r:V,s:v}=o,S=f(F),z=B.inv(v),q=B.create(S*z),_=B.create(V*z),T=l.BASE.multiplyUnsafe(q).add(a.multiplyUnsafe(_));return T.is0()?!1:B.create(T.x)===V}catch{return!1}}function y(r,F,E={}){let{prehash:x}=Pi(E,m);return F=M(F,x),I.fromBytes(r,"recovered").recoverPublicKey(F).toBytes()}return Object.freeze({keygen:Z,getPublicKey:g,getSharedSecret:n,utils:h,lengths:W,Point:l,sign:D,verify:K,recoverPublicKey:y,Signature:I,hash:A})}function p5(l){let A={a:l.a,b:l.b,p:l.Fp.ORDER,n:l.n,h:l.h,Gx:l.Gx,Gy:l.Gy},G=l.Fp,b=l.allowedPrivateKeyLengths?Array.from(new Set(l.allowedPrivateKeyLengths.map(B=>Math.ceil(B/2)))):void 0,t=Vt(A.n,{BITS:l.nBitLength,allowedLengths:b,modFromBytes:l.wrapPrivateKey}),c={Fp:G,Fn:t,allowInfinityPoint:l.allowInfinityPoint,endo:l.endo,isTorsionFree:l.isTorsionFree,clearCofactor:l.clearCofactor,fromBytes:l.fromBytes,toBytes:l.toBytes};return{CURVE:A,curveOpts:c}}function F5(l){let{CURVE:A,curveOpts:G}=p5(l),b={hmac:l.hmac,randomBytes:l.randomBytes,lowS:l.lowS,bits2int:l.bits2int,bits2int_modN:l.bits2int_modN};return{CURVE:A,curveOpts:G,hash:l.hash,ecdsaOpts:b}}function y5(l,A){let G=A.Point;return Object.assign({},A,{ProjectivePoint:G,CURVE:Object.assign({},l,_W(G.Fn.ORDER,G.Fn.BITS))})}function yy(l){let{CURVE:A,curveOpts:G,hash:b,ecdsaOpts:t}=F5(l),c=I5(A,G),B=X5(c,b,t);return y5(l,B)}function Qy(l,A){let G=b=>yy({...l,hash:b});return{...G(A),create:G}}var $i={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Q5={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ny=BigInt(2);function N5(l){let A=$i.p,G=BigInt(3),b=BigInt(6),t=BigInt(11),c=BigInt(22),B=BigInt(23),e=BigInt(44),d=BigInt(88),Z=l*l*l%A,g=Z*Z*l%A,n=RG(g,G,A)*g%A,h=RG(n,G,A)*g%A,W=RG(h,Ny,A)*Z%A,m=RG(W,t,A)*W%A,Y=RG(m,c,A)*m%A,R=RG(Y,e,A)*Y%A,u=RG(R,d,A)*R%A,i=RG(u,e,A)*Y%A,I=RG(i,G,A)*g%A,Q=RG(I,B,A)*m%A,f=RG(Q,b,A)*Z%A,U=RG(f,Ny,A);if(!_i.eql(_i.sqr(U),l))throw new Error("Cannot find square root");return U}var _i=Vt($i.p,{sqrt:N5}),Xc=Qy({...$i,Fp:_i,lowS:!0,endo:Q5},ye);function qt(l,A){if(l.length!==32)throw new Error("Expected valid 32-byte private key as a seed");if(!PA||!A&&TA()){let G=KV(l),b=G.slice(32);if(Hd(b))throw new Error("Invalid publicKey generated from WASM interface");return{publicKey:b,secretKey:G.slice(0,32)}}return{publicKey:Xc.getPublicKey(l,!0),secretKey:l}}function Ao(l,A){return(G,{chainCode:b,isHard:t})=>{if(!t)throw new Error("A soft key was found in the path and is not supported");return l(A(G.secretKey.subarray(0,32),b))}}var lm=Ao(qt,By);var E5=be(uG("Ed25519HDKD"));function Am(l,A){if(!Hb(A)||A.length!==32)throw new Error("Invalid chainCode passed to derive");return Mb(nG(E5,l,A))}function ed(l=32){return Ja(new Uint8Array(l))}var wB=BigInt(0),hb=BigInt(1),Gm=BigInt(2),v5=BigInt(8);function H5(l,A,G,b){let t=l.sqr(G),c=l.sqr(b),B=l.add(l.mul(A.a,t),c),e=l.add(l.ONE,l.mul(A.d,l.mul(t,c)));return l.eql(B,e)}function J5(l,A={}){let G=$W("edwards",l,A,A.FpFnLE),{Fp:b,Fn:t}=G,c=G.CURVE,{h:B}=c;kB(A,{},{uvRatio:"function"});let e=Gm<<BigInt(t.BYTES*8)-hb,d=R=>b.create(R),Z=A.uvRatio||((R,u)=>{try{return{isValid:!0,value:b.sqrt(b.div(R,u))}}catch{return{isValid:!1,value:wB}}});if(!H5(b,c,c.Gx,c.Gy))throw new Error("bad curve params: generator point");function g(R,u,i=!1){let I=i?hb:wB;return Ee("coordinate "+R,u,I,e),u}function n(R){if(!(R instanceof m))throw new Error("ExtendedPoint expected")}let h=ve((R,u)=>{let{X:i,Y:I,Z:Q}=R,f=R.is0();u==null&&(u=f?v5:b.inv(Q));let U=d(i*u),J=d(I*u),M=b.mul(Q,u);if(f)return{x:wB,y:hb};if(M!==hb)throw new Error("invZ was invalid");return{x:U,y:J}}),W=ve(R=>{let{a:u,d:i}=c;if(R.is0())throw new Error("bad point: ZERO");let{X:I,Y:Q,Z:f,T:U}=R,J=d(I*I),M=d(Q*Q),C=d(f*f),D=d(C*C),$=d(J*u),K=d(C*d($+M)),y=d(D+d(i*d(J*M)));if(K!==y)throw new Error("bad point: equation left != right (1)");let r=d(I*Q),F=d(f*U);if(r!==F)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(u,i,I,Q){this.X=g("x",u),this.Y=g("y",i),this.Z=g("z",I,!0),this.T=g("t",Q),Object.freeze(this)}static CURVE(){return c}static fromAffine(u){if(u instanceof m)throw new Error("extended point not allowed");let{x:i,y:I}=u||{};return g("x",i),g("y",I),new m(i,I,hb,d(i*I))}static fromBytes(u,i=!1){let I=b.BYTES,{a:Q,d:f}=c;u=KW(mt(u,I,"point")),lB(i,"zip215");let U=KW(u),J=u[I-1];U[I-1]=J&-129;let M=Kt(U),C=i?e:b.ORDER;Ee("point.y",M,wB,C);let D=d(M*M),$=d(D-hb),K=d(f*D-Q),{isValid:y,value:r}=Z($,K);if(!y)throw new Error("bad point: invalid y coordinate");let F=(r&hb)===hb,E=(J&128)!==0;if(!i&&r===wB&&E)throw new Error("bad point: x=0 and x_0=1");return E!==F&&(r=d(-r)),m.fromAffine({x:r,y:M})}static fromHex(u,i=!1){return m.fromBytes(ZG("point",u),i)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(u=8,i=!0){return Y.createCache(this,u),i||this.multiply(Gm),this}assertValidity(){W(this)}equals(u){n(u);let{X:i,Y:I,Z:Q}=this,{X:f,Y:U,Z:J}=u,M=d(i*J),C=d(f*Q),D=d(I*J),$=d(U*Q);return M===C&&D===$}is0(){return this.equals(m.ZERO)}negate(){return new m(d(-this.X),this.Y,this.Z,d(-this.T))}double(){let{a:u}=c,{X:i,Y:I,Z:Q}=this,f=d(i*i),U=d(I*I),J=d(Gm*d(Q*Q)),M=d(u*f),C=i+I,D=d(d(C*C)-f-U),$=M+U,K=$-J,y=M-U,r=d(D*K),F=d($*y),E=d(D*y),x=d(K*$);return new m(r,F,x,E)}add(u){n(u);let{a:i,d:I}=c,{X:Q,Y:f,Z:U,T:J}=this,{X:M,Y:C,Z:D,T:$}=u,K=d(Q*M),y=d(f*C),r=d(J*I*$),F=d(U*D),E=d((Q+f)*(M+C)-K-y),x=F-r,s=F+r,p=d(y-i*K),X=d(E*x),o=d(s*p),a=d(E*p),V=d(x*s);return new m(X,o,V,a)}subtract(u){return this.add(u.negate())}multiply(u){if(!t.isValidNot0(u))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:i,f:I}=Y.cached(this,u,Q=>GB(m,Q));return GB(m,[i,I])[0]}multiplyUnsafe(u,i=m.ZERO){if(!t.isValid(u))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return u===wB?m.ZERO:this.is0()||u===hb?this:Y.unsafe(this,u,I=>GB(m,I),i)}isSmallOrder(){return this.multiplyUnsafe(B).is0()}isTorsionFree(){return Y.unsafe(this,c.n).is0()}toAffine(u){return h(this,u)}clearCofactor(){return B===hb?this:this.multiplyUnsafe(B)}toBytes(){let{x:u,y:i}=this.toAffine(),I=b.toBytes(i);return I[I.length-1]|=u&hb?128:0,I}toHex(){return Bt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(u){return GB(m,u)}static msm(u,i){return td(m,t,u,i)}_setWindowSize(u){this.precompute(u)}toRawBytes(){return this.toBytes()}}m.BASE=new m(c.Gx,c.Gy,hb,d(c.Gx*c.Gy)),m.ZERO=new m(wB,hb,hb,wB),m.Fp=b,m.Fn=t;let Y=new bd(m,t.BITS);return m.BASE.precompute(8),m}var Go=class{constructor(A){this.ep=A}static fromBytes(A){qW()}static fromHex(A){qW()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(A){return this.ep.toAffine(A)}toHex(){return Bt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(A){return this.assertSame(A),this.init(this.ep.add(A.ep))}subtract(A){return this.assertSame(A),this.init(this.ep.subtract(A.ep))}multiply(A){return this.init(this.ep.multiply(A))}multiplyUnsafe(A){return this.init(this.ep.multiplyUnsafe(A))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(A,G){return this.init(this.ep.precompute(A,G))}toRawBytes(){return this.toBytes()}};function x5(l,A,G={}){if(typeof A!="function")throw new Error('"hash" function param is required');kB(G,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:b}=G,{BASE:t,Fp:c,Fn:B}=l,e=G.randomBytes||Eb,d=G.adjustScalarBytes||(C=>C),Z=G.domain||((C,D,$)=>{if(lB($,"phflag"),D.length||$)throw new Error("Contexts/pre-hash are not supported");return C});function g(C){return B.create(Kt(C))}function n(C){let D=I.secretKey;C=ZG("private key",C,D);let $=ZG("hashed private key",A(C),2*D),K=d($.slice(0,D)),y=$.slice(D,2*D),r=g(K);return{head:K,prefix:y,scalar:r}}function h(C){let{head:D,prefix:$,scalar:K}=n(C),y=t.multiply(K),r=y.toBytes();return{head:D,prefix:$,scalar:K,point:y,pointBytes:r}}function W(C){return h(C).pointBytes}function m(C=Uint8Array.of(),...D){let $=VG(...D);return g(A(Z($,ZG("context",C),!!b)))}function Y(C,D,$={}){C=ZG("message",C),b&&(C=b(C));let{prefix:K,scalar:y,pointBytes:r}=h(D),F=m($.context,K,C),E=t.multiply(F).toBytes(),x=m($.context,E,r,C),s=B.create(F+x*y);if(!B.isValid(s))throw new Error("sign failed: invalid s");let p=VG(E,B.toBytes(s));return mt(p,I.signature,"result")}let R={zip215:!0};function u(C,D,$,K=R){let{context:y,zip215:r}=K,F=I.signature;C=ZG("signature",C,F),D=ZG("message",D),$=ZG("publicKey",$,I.publicKey),r!==void 0&&lB(r,"zip215"),b&&(D=b(D));let E=F/2,x=C.subarray(0,E),s=Kt(C.subarray(E,F)),p,X,o;try{p=l.fromBytes($,r),X=l.fromBytes(x,r),o=t.multiplyUnsafe(s)}catch{return!1}if(!r&&p.isSmallOrder())return!1;let a=m(y,X.toBytes(),p.toBytes(),D);return X.add(p.multiplyUnsafe(a)).subtract(o).clearCofactor().is0()}let i=c.BYTES,I={secretKey:i,publicKey:i,signature:2*i,seed:i};function Q(C=e(I.seed)){return mt(C,I.seed,"seed")}function f(C){let D=M.randomSecretKey(C);return{secretKey:D,publicKey:W(D)}}function U(C){return ft(C)&&C.length===B.BYTES}function J(C,D){try{return!!l.fromBytes(C,D)}catch{return!1}}let M={getExtendedPublicKey:h,randomSecretKey:Q,isValidSecretKey:U,isValidPublicKey:J,toMontgomery(C){let{y:D}=l.fromBytes(C),$=I.publicKey,K=$===32;if(!K&&$!==57)throw new Error("only defined for 25519 and 448");let y=K?c.div(hb+D,hb-D):c.div(D-hb,D+hb);return c.toBytes(y)},toMontgomerySecret(C){let D=I.secretKey;mt(C,D);let $=A(C.subarray(0,D));return d($).subarray(0,D)},randomPrivateKey:Q,precompute(C=8,D=l.BASE){return D.precompute(C,!1)}};return Object.freeze({keygen:f,getPublicKey:W,sign:Y,verify:u,utils:M,Point:l,lengths:I})}function f5(l){let A={a:l.a,d:l.d,p:l.Fp.ORDER,n:l.n,h:l.h,Gx:l.Gx,Gy:l.Gy},G=l.Fp,b=Vt(A.n,l.nBitLength,!0),t={Fp:G,Fn:b,uvRatio:l.uvRatio},c={randomBytes:l.randomBytes,adjustScalarBytes:l.adjustScalarBytes,domain:l.domain,prehash:l.prehash,mapToCurve:l.mapToCurve};return{CURVE:A,curveOpts:t,hash:l.hash,eddsaOpts:c}}function k5(l,A){let G=A.Point;return Object.assign({},A,{ExtendedPoint:G,CURVE:l,nBitLength:G.Fn.BITS,nByteLength:G.Fn.BYTES})}function Ey(l){let{CURVE:A,curveOpts:G,hash:b,eddsaOpts:t}=f5(l),c=J5(A,G),B=x5(c,b,t);return k5(l,B)}var w5=BigInt(0),cB=BigInt(1),vy=BigInt(2),ztl=BigInt(3),U5=BigInt(5),C5=BigInt(8),Zd=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),jn={p:Zd,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:C5,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function S5(l){let A=BigInt(10),G=BigInt(20),b=BigInt(40),t=BigInt(80),c=Zd,e=l*l%c*l%c,d=RG(e,vy,c)*e%c,Z=RG(d,cB,c)*l%c,g=RG(Z,U5,c)*Z%c,n=RG(g,A,c)*g%c,h=RG(n,G,c)*n%c,W=RG(h,b,c)*h%c,m=RG(W,t,c)*W%c,Y=RG(m,t,c)*W%c,R=RG(Y,A,c)*g%c;return{pow_p_5_8:RG(R,vy,c)*l%c,b2:e}}function z5(l){return l[0]&=248,l[31]&=127,l[31]|=64,l}var bm=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Bm(l,A){let G=Zd,b=IG(A*A*A,G),t=IG(b*b*A,G),c=S5(l*t).pow_p_5_8,B=IG(l*b*c,G),e=IG(A*B*B,G),d=B,Z=IG(B*bm,G),g=e===l,n=e===IG(-l,G),h=e===IG(-l*bm,G);return g&&(B=d),(n||h)&&(B=Z),AB(B,G)&&(B=IG(-B,G)),{isValid:g||n,value:B}}var UB=Vt(jn.p,{isLE:!0}),j5=Vt(jn.n,{isLE:!0}),M5={...jn,Fp:UB,hash:OW,adjustScalarBytes:z5,uvRatio:Bm},Lb=Ey(M5);var tm=bm,T5=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),D5=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),L5=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),O5=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Hy=l=>Bm(cB,l),P5=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),cm=l=>Lb.Point.Fp.create(Kt(l)&P5);function Jy(l){let{d:A}=jn,G=Zd,b=u=>UB.create(u),t=b(tm*l*l),c=b((t+cB)*L5),B=BigInt(-1),e=b((B-A*t)*b(t+A)),{isValid:d,value:Z}=Bm(c,e),g=b(Z*l);AB(g,G)||(g=b(-g)),d||(Z=g),d||(B=t);let n=b(B*(t-cB)*O5-e),h=Z*Z,W=b((Z+Z)*e),m=b(n*T5),Y=b(cB-h),R=b(cB+h);return new Lb.Point(b(W*R),b(Y*m),b(m*R),b(W*Y))}function K5(l){fG(l,64);let A=cm(l.subarray(0,32)),G=Jy(A),b=cm(l.subarray(32,64)),t=Jy(b);return new pc(G.add(t))}var pc=class l extends Go{constructor(A){super(A)}static fromAffine(A){return new l(Lb.Point.fromAffine(A))}assertSame(A){if(!(A instanceof l))throw new Error("RistrettoPoint expected")}init(A){return new l(A)}static hashToCurve(A){return K5(ZG("ristrettoHash",A,64))}static fromBytes(A){fG(A,32);let{a:G,d:b}=jn,t=Zd,c=Q=>UB.create(Q),B=cm(A);if(!Ui(UB.toBytes(B),A)||AB(B,t))throw new Error("invalid ristretto255 encoding 1");let e=c(B*B),d=c(cB+G*e),Z=c(cB-G*e),g=c(d*d),n=c(Z*Z),h=c(G*b*g-n),{isValid:W,value:m}=Hy(c(h*n)),Y=c(m*Z),R=c(m*Y*h),u=c((B+B)*Y);AB(u,t)&&(u=c(-u));let i=c(d*R),I=c(u*i);if(!W||AB(I,t)||i===w5)throw new Error("invalid ristretto255 encoding 2");return new l(new Lb.Point(u,i,cB,I))}static fromHex(A){return l.fromBytes(ZG("ristrettoHex",A,32))}static msm(A,G){return td(l,Lb.Point.Fn,A,G)}toBytes(){let{X:A,Y:G,Z:b,T:t}=this.ep,c=Zd,B=R=>UB.create(R),e=B(B(b+G)*B(b-G)),d=B(A*G),Z=B(d*d),{value:g}=Hy(B(e*Z)),n=B(g*e),h=B(g*d),W=B(n*h*t),m;if(AB(t*W,c)){let R=B(G*tm),u=B(A*tm);A=R,G=u,m=B(n*D5)}else m=h;AB(A*W,c)&&(G=B(-G));let Y=B((b-G)*m);return AB(Y,c)&&(Y=B(-Y)),UB.toBytes(Y)}equals(A){this.assertSame(A);let{X:G,Y:b}=this.ep,{X:t,Y:c}=A.ep,B=Z=>UB.create(Z),e=B(G*c)===B(b*t),d=B(b*c)===B(G*t);return e||d}is0(){return this.equals(l.ZERO)}};pc.BASE=new pc(Lb.Point.BASE);pc.ZERO=new pc(Lb.Point.ZERO);pc.Fp=UB;pc.Fn=j5;var PG=pc;function xe(l,A){if(!PA||!A&&TA()){let b=LV(l);return{publicKey:b.slice(32),secretKey:b.slice(0,64)}}let G=Lb.getPublicKey(l);return{publicKey:G,secretKey:Zc([l,G])}}function em(l,{publicKey:A,secretKey:G},b){if(G){if(!A)throw new Error("Expected a valid publicKey")}else throw new Error("Expected a valid secretKey");let t=Tl(l),c=G.subarray(0,32);return!PA||!b&&TA()?OV(A,c,t):Lb.sign(t,c)}function xy(l,A,G,b){let t=Tl(l),c=Tl(G),B=Tl(A);if(c.length!==32)throw new Error(`Invalid publicKey, received ${c.length}, expected 32`);if(B.length!==64)throw new Error(`Invalid signature, received ${B.length} bytes, expected 64`);try{return!PA||!b&&TA()?PV(B,t,c):Lb.verify(B,t,c)}catch{return!1}}var fy=Ao(xe,Am);var Zm=ft;var dd=Kt;var _t=Un;var dm=Ee;var ky=Rc;var q5=BigInt(0),Mn=BigInt(1),_5=BigInt(2),$5=BigInt(7),lJ=BigInt(256),AJ=BigInt(113),Cy=[],Sy=[],zy=[];for(let l=0,A=Mn,G=1,b=0;l<24;l++){[G,b]=[b,(2*G+3*b)%5],Cy.push(2*(5*b+G)),Sy.push((l+1)*(l+2)/2%64);let t=q5;for(let c=0;c<7;c++)A=(A<<Mn^(A>>$5)*AJ)%lJ,A&_5&&(t^=Mn<<(Mn<<BigInt(c))-Mn);zy.push(t)}var jy=Ia(zy,!0),GJ=jy[0],bJ=jy[1],wy=(l,A,G)=>G>32?bV(l,A,G):AV(l,A,G),Uy=(l,A,G)=>G>32?tV(l,A,G):GV(l,A,G);function am(l,A=24){let G=new Uint32Array(10);for(let b=24-A;b<24;b++){for(let B=0;B<10;B++)G[B]=l[B]^l[B+10]^l[B+20]^l[B+30]^l[B+40];for(let B=0;B<10;B+=2){let e=(B+8)%10,d=(B+2)%10,Z=G[d],g=G[d+1],n=wy(Z,g,1)^G[e],h=Uy(Z,g,1)^G[e+1];for(let W=0;W<50;W+=10)l[B+W]^=n,l[B+W+1]^=h}let t=l[2],c=l[3];for(let B=0;B<24;B++){let e=Sy[B],d=wy(t,c,e),Z=Uy(t,c,e),g=Cy[B];t=l[g],c=l[g+1],l[g]=d,l[g+1]=Z}for(let B=0;B<50;B+=10){for(let e=0;e<10;e++)G[e]=l[B+e];for(let e=0;e<10;e++)l[B+e]^=~G[(e+2)%10]&G[(e+4)%10]}l[0]^=GJ[b],l[1]^=bJ[b]}MG(G)}var nm=class l extends bc{constructor(A,G,b,t=!1,c=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=A,this.suffix=G,this.outputLen=b,this.enableXOF=t,this.rounds=c,mG(b),!(0<A&&A<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=tt(this.state)}clone(){return this._cloneInto()}keccak(){ct(this.state32),am(this.state32,this.rounds),ct(this.state32),this.posOut=0,this.pos=0}update(A){Xt(this),A=et(A),fG(A);let{blockLen:G,state:b}=this,t=A.length;for(let c=0;c<t;){let B=Math.min(G-this.pos,t-c);for(let e=0;e<B;e++)b[this.pos++]^=A[c++];this.pos===G&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:A,suffix:G,pos:b,blockLen:t}=this;A[b]^=G,G&128&&b===t-1&&this.keccak(),A[t-1]^=128,this.keccak()}writeInto(A){Xt(this,!1),fG(A),this.finish();let G=this.state,{blockLen:b}=this;for(let t=0,c=A.length;t<c;){this.posOut>=b&&this.keccak();let B=Math.min(b-this.posOut,c-t);A.set(G.subarray(this.posOut,this.posOut+B),t),this.posOut+=B,t+=B}return A}xofInto(A){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(A)}xof(A){return mG(A),this.xofInto(new Uint8Array(A))}digestInto(A){if(_e(A,this),this.finished)throw new Error("digest() was already called");return this.writeInto(A),this.destroy(),A}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,MG(this.state)}_cloneInto(A){let{blockLen:G,suffix:b,outputLen:t,rounds:c,enableXOF:B}=this;return A||(A=new l(G,b,t,B,c)),A.state32.set(this.state32),A.pos=this.pos,A.posOut=this.posOut,A.finished=this.finished,A.rounds=c,A.suffix=b,A.outputLen=t,A.enableXOF=B,A.destroyed=this.destroyed,A}},My=(l,A,G)=>Fd(()=>new nm(A,l,G));var bo=My(1,136,256/8);var Ty=My(1,72,512/8);var CB=OW;var Py=BigInt(0),Ky=BigInt(3);function gm(l){if(typeof l=="string")return Ec(l);if(Zm(l))return l;throw new Error("Wrong data")}function NG(l,A,...G){if(!Zm(A))throw new Error(`${l}: Uint8Array expected`);if(G.length&&!G.includes(A.length))throw new Error(`${l}: Uint8Array expected of length ${G}, not of length=${A.length}`)}function to(l,A){if(!Number.isSafeInteger(A)||A<0||A>4294967295)throw new Error(`${l}: wrong u32 integer: ${A}`);return A}function nd(...l){for(let A of l)A.fill(0)}var fe=Uint8Array.of(),hm=Lb.CURVE.n;function Dy(l,A){NG(l,A,32);let G=dd(A);return dm(l,G,Py,hm),G}var Dn=l=>IG(l,hm),Tn=166,$t={I:1,A:2,C:4,T:8,M:16,K:32},Wm=class l{constructor(A){this.state=new Uint8Array(200),this.pos=0,this.posBegin=0,this.curFlags=0,this.state.set([1,Tn+2,1,0,1,96],0),this.state.set(Ec("STROBEv1.0.2"),6),this.state32=tt(this.state),this.keccakF1600(),this.metaAD(A,!1)}keccakF1600(){am(this.state32)}runF(){this.state[this.pos]^=this.posBegin,this.state[this.pos+1]^=4,this.state[Tn+1]^=128,this.keccakF1600(),this.pos=0,this.posBegin=0}absorb(A){for(let G=0;G<A.length;G++)this.state[this.pos++]^=A[G],this.pos===Tn&&this.runF()}squeeze(A){let G=new Uint8Array(A);for(let b=0;b<G.length;b++)G[b]=this.state[this.pos],this.state[this.pos++]=0,this.pos===Tn&&this.runF();return G}overwrite(A){for(let G=0;G<A.length;G++)this.state[this.pos++]=A[G],this.pos===Tn&&this.runF()}beginOp(A,G){if(G){if(this.curFlags!==A)throw new Error(`Continued op with changed flags from ${this.curFlags.toString(2)} to ${A.toString(2)}`);return}if(A&$t.T)throw new Error("T flag is not supported");let b=this.posBegin;this.posBegin=this.pos+1,this.curFlags=A,this.absorb(new Uint8Array([b,A])),(A&($t.C|$t.K))!==0&&this.pos!==0&&this.runF()}metaAD(A,G){this.beginOp($t.M|$t.A,G),this.absorb(gm(A))}AD(A,G){this.beginOp($t.A,G),this.absorb(gm(A))}PRF(A,G){return this.beginOp($t.I|$t.A|$t.C,G),this.squeeze(A)}KEY(A,G){this.beginOp($t.A|$t.C,G),this.overwrite(gm(A))}clone(){let A=new l("0");return A.pos=this.pos,A.posBegin=this.posBegin,A.state.set(this.state),A.curFlags=this.curFlags,A}clean(){this.state.fill(0),this.pos=0,this.curFlags=0,this.posBegin=0}},om=class{constructor(A){this.strobe=new Wm("Merlin v1.0"),this.appendMessage("dom-sep",A)}appendMessage(A,G){this.strobe.metaAD(A,!1),to("Merlin.appendMessage",G.length),this.strobe.metaAD(_t(G.length,4),!0),this.strobe.AD(G,!1)}challengeBytes(A,G){return this.strobe.metaAD(A,!1),to("Merlin.challengeBytes",G),this.strobe.metaAD(_t(G,4),!0),this.strobe.PRF(G,!1)}clean(){this.strobe.clean()}},BB=class extends om{constructor(A,G=Eb){super(A),this.rng=G}label(A){this.appendMessage("",A)}bytes(A){return this.appendMessage("sign-bytes",A),this}protoName(A){this.appendMessage("proto-name",A)}commitPoint(A,G){this.appendMessage(A,G.toRawBytes())}challengeScalar(A){return Dn(dd(this.challengeBytes(A,64)))}witnessScalar(A,G=[]){return Dn(dd(this.witnessBytes(A,64,G)))}witnessBytes(A,G,b=[]){to("SigningContext.witnessBytes",G);let t=this.strobe.clone();for(let B of b)t.metaAD(A,!1),to("SigningContext.witnessBytes nonce length",B.length),t.metaAD(_t(B.length,4),!0),t.KEY(B,!1);let c=this.rng(32);return t.metaAD("rng",!1),t.KEY(c,!1),t.metaAD(_t(G,4),!1),t.PRF(G,!1)}},tJ=ky(256),qy=l=>_t(l<<Ky&tJ,32),ad=l=>dd(l)>>Ky;function ke(l){NG("secretKey",l,64);let A=ad(l.subarray(0,32));return PG.BASE.multiply(A).toRawBytes()}function sm(l){NG("seed",l,32);let A=CB(l);A[0]&=248,A[31]&=63,A[31]|=64;let G=qy(ad(A.subarray(0,32))),b=A.subarray(32,64),t=VG(G,b);return nd(G,b,A),t}var _y=Ec("substrate");function $y(l,A,G=Eb){NG("message",A),NG("secretKey",l,64);let b=new BB("SigningContext",G);b.label(_y),b.bytes(A);let t=ad(l.subarray(0,32)),c=l.subarray(32,64),B=PG.fromHex(ke(l));b.protoName("Schnorr-sig"),b.commitPoint("sign:pk",B);let e=b.witnessScalar("signing",[c]),d=PG.BASE.multiply(e);b.commitPoint("sign:R",d);let Z=b.challengeScalar("sign:c"),g=Dn(Z*t+e),n=VG(d.toRawBytes(),_t(g,32));return n[63]|=128,b.clean(),n}function lQ(l,A,G){if(NG("message",l),NG("signature",A,64),NG("publicKey",G,32),!(A[63]&128))throw new Error("Schnorrkel marker missing");let b=Uint8Array.from(A.subarray(32,64));b[31]&=127;let t=PG.fromHex(A.subarray(0,32)),c=dd(b);dm("s",c,Py,hm);let B=new BB("SigningContext");B.label(_y),B.bytes(l);let e=PG.fromHex(G);if(e.equals(PG.ZERO))return!1;B.protoName("Schnorr-sig"),B.commitPoint("sign:pk",e),B.commitPoint("sign:R",t);let d=B.challengeScalar("sign:c"),Z=PG.BASE.multiply(c),g=e.negate().multiply(d).add(Z);return B.clean(),nd(b),g.equals(t)}var co={secretSoft(l,A,G=Eb){NG("secretKey",l,64),NG("chainCode",A,32);let b=ad(l.subarray(0,32)),t=l.subarray(32,64),c=PG.fromHex(ke(l)),B=new BB("SchnorrRistrettoHDKD",G);B.bytes(fe),B.appendMessage("chain-code",A),B.commitPoint("public-key",c);let e=B.challengeScalar("HDKD-scalar"),d=B.challengeBytes("HDKD-chaincode",32),Z=VG(_t(b,32),t),g=B.witnessBytes("HDKD-nonce",32,[t,Z]),n=qy(Dn(b+e)),h=VG(n,g);return nd(n,g,Z,d),B.clean(),h},publicSoft(l,A){NG("publicKey",l,32),NG("chainCode",A,32);let G=PG.fromHex(l),b=new BB("SchnorrRistrettoHDKD");b.bytes(fe),b.appendMessage("chain-code",A),b.commitPoint("public-key",G);let t=b.challengeScalar("HDKD-scalar");return b.challengeBytes("HDKD-chaincode",32),b.clean(),G.add(PG.BASE.multiply(t)).toRawBytes()},secretHard(l,A){NG("secretKey",l,64),NG("chainCode",A,32);let G=_t(ad(l.subarray(0,32)),32),b=new BB("SchnorrRistrettoHDKD");b.bytes(fe),b.appendMessage("chain-code",A),b.appendMessage("secret-key",G);let t=b.challengeBytes("HDKD-hard",32),c=b.challengeBytes("HDKD-chaincode",32);b.clean();let B=sm(t);return nd(G,t,c),b.clean(),B}},Ly={proove(l,A,G,b,t,c){b.protoName("DLEQProof"),b.commitPoint("vrf:h",t);let B=b.witnessScalar("proving\x000",[A]),e=PG.BASE.multiply(B);b.commitPoint("vrf:R=g^r",e);let d=t.multiply(B);b.commitPoint("vrf:h^r",d),b.commitPoint("vrf:pk",G),b.commitPoint("vrf:h^sk",c);let Z=b.challengeScalar("prove"),g=Dn(B-Z*l);return{proof:{c:Z,s:g},proofBatchable:{R:e,Hr:d,s:g}}},verify(l,A,G,b,t){if(l.equals(PG.ZERO))return!1;A.protoName("DLEQProof"),A.commitPoint("vrf:h",G);let c=l.multiply(t.c).add(PG.BASE.multiply(t.s));A.commitPoint("vrf:R=g^r",c);let B=b.multiply(t.c).add(G.multiply(t.s));A.commitPoint("vrf:h^r",B),A.commitPoint("vrf:pk",l),A.commitPoint("vrf:h^sk",b);let e=A.challengeScalar("prove");return t.c===e?{R:c,Hr:B,s:t.s}:!1}};function Oy(l,A,G,b,t=Eb){let c=new BB("SigningContext",t);c.label(l),c.bytes(A),c.commitPoint("vrf-nm-pk",b);let B=c.challengeBytes("VRFHash",64),e=PG.hashToCurve(B),d=new BB("VRF",t);return G.length&&d.label(G),c.clean(),nd(B),{input:e,t:d}}var Bo={sign(l,A,G=fe,b=fe,t=Eb){NG("msg",l),NG("secretKey",A,64),NG("ctx",G),NG("extra",b);let c=ad(A.subarray(0,32)),B=A.subarray(32,64),e=PG.fromHex(ke(A)),{input:d,t:Z}=Oy(G,l,b,e,t),g=d.multiply(c),n={input:d,output:g},{proof:h}=Ly.proove(c,B,e,Z,d,g),W=_t(h.c,32),m=_t(h.s,32),Y=VG(n.output.toRawBytes(),W,m);return nd(B,W,m),Y},verify(l,A,G,b=fe,t=fe,c=Eb){NG("msg",l),NG("signature",A,96),NG("pubkey",G,32),NG("ctx",b),NG("extra",t);let B=PG.fromHex(G);if(B.equals(PG.ZERO))return!1;let e={c:Dy("signature.c",A.subarray(32,64)),s:Dy("signature.s",A.subarray(64,96))},{input:d,t:Z}=Oy(b,l,t,B,c),g=PG.fromHex(A.subarray(0,32));if(g.equals(PG.ZERO))throw new Error("vrf.verify: wrong output point (identity)");return Ly.verify(B,Z,d,g,e)!==!1}};function eo(l){return(A,G)=>{if(!Hb(G)||G.length!==32)throw new Error("Invalid chainCode passed to derive");let b=l(A.secretKey,G);return{publicKey:ke(b),secretKey:b}}}var AQ=eo(co.secretHard);var GQ=eo(co.secretSoft);function bQ(l,{chainCode:A,isSoft:G}){return G?GQ(l,A):AQ(l,A)}var cJ={ecdsa:lm,ed25519:fy,ethereum:lm,sr25519:bQ};function Ln(l,A,G){let b=cJ[G],t=l;for(let c of A)t=b(t,c);return t}function On(l){let A=Tl(l);if(A.length!==32)throw new Error(`Expected a seed matching 32 bytes, found ${A.length}`);let G=sm(A);return{publicKey:ke(G),secretKey:G}}function rm(l,{publicKey:A,secretKey:G}){if(A?.length!==32)throw new Error("Expected a valid publicKey, 32-bytes");if(G?.length!==64)throw new Error("Expected a valid secretKey, 64-bytes");return $y(G,Tl(l))}function tQ(l,A,G){let b=Tl(G),t=Tl(A);if(b.length!==32)throw new Error(`Invalid publicKey, received ${b.length} bytes, expected 32`);if(t.length!==64)throw new Error(`Invalid signature, received ${t.length} bytes, expected 64`);return lQ(Tl(l),t,b)}var cQ=new Uint8Array;function im(l,{secretKey:A},G=cQ,b=cQ){if(A?.length!==64)throw new Error("Invalid secretKey, expected 64-bytes");return Bo.sign(Tl(l),A,Tl(G),Tl(b),Eb)}var BQ=new Uint8Array;function mm(l,A,G,b=BQ,t=BQ){let c=Tl(G),B=Tl(A);if(c.length!==32)throw new Error("Invalid publicKey, expected 32-bytes");if(B.length!==96)throw new Error("Invalid vrfSign output, expected 96 bytes");return Bo.verify(Tl(l),B,c,Tl(b),Tl(t))}function Pn(l,A=$Z.prefix){let G=Pt(l);if(A<0||A>16383&&!BJ.includes(A)||[46,47].includes(A))throw new Error("Out of range ss58Format specified");if(!$Z.allowedDecodedLengths.includes(G.length))throw new Error(`Expected a valid key to convert, with length ${$Z.allowedDecodedLengths.join(", ")}`);let b=nG(A<64?[A]:[(A&252)>>2|64,A>>8|(A&3)<<6],G);return Fi(nG(b,SW(b).subarray(0,[32,33].includes(G.length)?2:1)))}var BJ=[29972];var zB=Ua({256:tu,512:cu},{256:bo,512:Ty});function Kn(l,A,G){return l==="keccak"?zB(A,void 0,G):Mb(A,void 0,void 0,G)}var Vm={chars:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",coder:qF,type:"base64",withPadding:!0},eQ=CW(Vm);var um=wW(Vm,eQ),Ym=UW(Vm);function qn(l,A){if(![33,65].includes(l.length))throw new Error(`Invalid publicKey provided, received ${l.length} bytes input`);return l.length===33?l:!PA||!A&&TA()?qV(l):Xc.ProjectivePoint.fromHex(l).toRawBytes(!0)}function we(l,A){if(![33,65].includes(l.length))throw new Error(`Invalid publicKey provided, received ${l.length} bytes input`);if(l.length===65)return l.subarray(1);if(!PA||!A&&TA())return _V(l).subarray(1);let{x:G,y:b}=Xc.ProjectivePoint.fromHex(l);return nG(kG(G,$c),kG(b,$c))}function ZQ(l,A,G,b="blake2",t){let c=Tl(A).subarray(0,64),B=Tl(l),e=!PA||!t&&TA()?$V(B,c,G):Xc.Signature.fromCompact(c).addRecoveryBit(G).recoverPublicKey(B).toRawBytes();if(!e)throw new Error("Unable to recover publicKey from signature");return b==="keccak"?we(e,t):qn(e,t)}function Zo(l,{secretKey:A},G="blake2",b){if(A?.length!==32)throw new Error("Expected valid secp256k1 secretKey, 32-bytes");let t=Kn(G,l,b);if(!PA||!b&&TA())return lu(t,A);let c=Xc.sign(t,A,{lowS:!0});return nG(kG(c.r,$c),kG(c.s,$c),new Uint8Array([c.recovery||0]))}var dQ="ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141".replace(/ /g,""),Im=UA(`0x${dQ}`),Rm=new pA.default(dQ,"hex");function eJ(l,A){let G=bZ(A,vi);if(G>=Im)throw new Error("Tweak parameter is out of range");if(G+=bZ(l,vi),G>=Im&&(G-=Im),G===AZ)throw new Error("Invalid resulting private key");return $o(G,$c)}function ZJ(l,A){let G=new pA.default(A);if(G.cmp(Rm)>=0)throw new Error("Tweak parameter is out of range");if(G.iadd(new pA.default(l)),G.cmp(Rm)>=0&&G.isub(Rm),G.isZero())throw new Error("Invalid resulting private key");return kG(G,$c)}function Xm(l,A,G){if(!Hb(l)||l.length!==32)throw new Error("Expected seckey to be an Uint8Array with length 32");if(!Hb(A)||A.length!==32)throw new Error("Expected tweak to be an Uint8Array with length 32");return!PA||G?ZJ(l,A):eJ(l,A)}function nQ(l,A,G,b="blake2",t){let c=Tl(A);if(c.length!==65)throw new Error(`Expected signature with 65 bytes, ${c.length} found instead`);let B=ZQ(Kn(b,l),c,c[64],b,t),e=Kn(b,B,t),d=Tl(G);return jb(B,d)||(b==="keccak"?jb(e.slice(-20),d.slice(-20)):jb(e,d))}function dJ(l){return[33,65].includes(l.length)&&(l=zB(we(l))),l.slice(-20)}function _n(l){if(!l)return"0x";let A=Tl(l);if(![20,32,33,65].includes(A.length))throw new Error(`Invalid address or publicKey provided, received ${A.length} bytes input`);let G=dt(dJ(A),-1,!1),b=dt(zB(G),-1,!1),t="";for(let c=0;c<40;c++)t=`${t}${parseInt(b[c],16)>7?G[c].toUpperCase():G[c]}`;return`0x${t}`}var no=ye;var nJ={256:no,512:CB},aJ={256:Gu,512:bu};function ao(l,A,G=256,b){let t=Tl(l);return!PA||!b&&TA()?aJ[G](t,A):Qe(nJ[G],t,A)}function aQ(l){if(!l.startsWith("m/"))return!1;let A=l.split("/").slice(1);for(let G of A){let b=/^\d+'?$/.test(G)?parseInt(G.replace(/'$/,""),10):Number.NaN;if(isNaN(b)||b>=2147483648||b<0)return!1}return!0}var gJ=uG("Bitcoin seed");function WQ(l,A){return{chainCode:A,publicKey:qt(l).publicKey,secretKey:l}}function oQ(l,A){let G=kG(A,ty),b=A>=2147483648?nG(new Uint8Array(1),l.secretKey,G):nG(l.publicKey,G);try{let t=ao(l.chainCode,b,512);return WQ(Xm(l.secretKey,t.slice(0,32)),t.slice(32))}catch{return oQ(l,A+1)}}function pm(l,A=""){let G=ao(gJ,l,512),b=WQ(G.slice(0,32),G.slice(32));if(!A||A==="m"||A==="M"||A==="m'"||A==="M'")return b;if(!aQ(A))throw new Error("Invalid derivation path");let t=A.split("/").slice(1);for(let c of t)b=oQ(b,parseInt(c,10)+(c.length>1&&c.endsWith("'")?2147483648:0));return b}function oJ(l,A,G,b){qe(l);let t=ua({dkLen:32,asyncTick:10},b),{c,dkLen:B,asyncTick:e}=t;if(mG(c),mG(B),mG(e),c<1)throw new Error("iterations (c) should be >= 1");let d=Co(A),Z=Co(G),g=new Uint8Array(B),n=Qe.create(l,d),h=n._cloneInto().update(Z);return{c,dkLen:B,asyncTick:e,DK:g,PRF:n,PRFSalt:h}}function hJ(l,A,G,b,t){return l.destroy(),A.destroy(),b&&b.destroy(),MG(t),G}function $n(l,A,G,b){let{c:t,dkLen:c,DK:B,PRF:e,PRFSalt:d}=oJ(l,A,G,b),Z,g=new Uint8Array(4),n=$e(g),h=new Uint8Array(e.outputLen);for(let W=1,m=0;m<c;W++,m+=e.outputLen){let Y=B.subarray(m,m+e.outputLen);n.setInt32(0,W,!1),(Z=d._cloneInto(Z)).update(g).digestInto(h),Y.set(h.subarray(0,Y.length));for(let R=1;R<t;R++){e._cloneInto(Z).update(h).digestInto(h);for(let u=0;u<Y.length;u++)Y[u]^=h[u]}}return hJ(e,d,B,Z,h)}function la(l,A=ed(),G=2048,b){let t=Tl(l),c=Tl(A);return{password:!PA||!b&&TA()?Bu(t,c,G):$n(CB,t,c,{c:G,dkLen:64}),rounds:G,salt:A}}var hQ=Ua({256:Zu,512:du},{256:no,512:CB}),Fm=dh(256,hQ);var sQ="abandon|ability|able|about|above|absent|absorb|abstract|absurd|abuse|access|accident|account|accuse|achieve|acid|acoustic|acquire|across|act|action|actor|actress|actual|adapt|add|addict|address|adjust|admit|adult|advance|advice|aerobic|affair|afford|afraid|again|age|agent|agree|ahead|aim|air|airport|aisle|alarm|album|alcohol|alert|alien|all|alley|allow|almost|alone|alpha|already|also|alter|always|amateur|amazing|among|amount|amused|analyst|anchor|ancient|anger|angle|angry|animal|ankle|announce|annual|another|answer|antenna|antique|anxiety|any|apart|apology|appear|apple|approve|april|arch|arctic|area|arena|argue|arm|armed|armor|army|around|arrange|arrest|arrive|arrow|art|artefact|artist|artwork|ask|aspect|assault|asset|assist|assume|asthma|athlete|atom|attack|attend|attitude|attract|auction|audit|august|aunt|author|auto|autumn|average|avocado|avoid|awake|aware|away|awesome|awful|awkward|axis|baby|bachelor|bacon|badge|bag|balance|balcony|ball|bamboo|banana|banner|bar|barely|bargain|barrel|base|basic|basket|battle|beach|bean|beauty|because|become|beef|before|begin|behave|behind|believe|below|belt|bench|benefit|best|betray|better|between|beyond|bicycle|bid|bike|bind|biology|bird|birth|bitter|black|blade|blame|blanket|blast|bleak|bless|blind|blood|blossom|blouse|blue|blur|blush|board|boat|body|boil|bomb|bone|bonus|book|boost|border|boring|borrow|boss|bottom|bounce|box|boy|bracket|brain|brand|brass|brave|bread|breeze|brick|bridge|brief|bright|bring|brisk|broccoli|broken|bronze|broom|brother|brown|brush|bubble|buddy|budget|buffalo|build|bulb|bulk|bullet|bundle|bunker|burden|burger|burst|bus|business|busy|butter|buyer|buzz|cabbage|cabin|cable|cactus|cage|cake|call|calm|camera|camp|can|canal|cancel|candy|cannon|canoe|canvas|canyon|capable|capital|captain|car|carbon|card|cargo|carpet|carry|cart|case|cash|casino|castle|casual|cat|catalog|catch|category|cattle|caught|cause|caution|cave|ceiling|celery|cement|census|century|cereal|certain|chair|chalk|champion|change|chaos|chapter|charge|chase|chat|cheap|check|cheese|chef|cherry|chest|chicken|chief|child|chimney|choice|choose|chronic|chuckle|chunk|churn|cigar|cinnamon|circle|citizen|city|civil|claim|clap|clarify|claw|clay|clean|clerk|clever|click|client|cliff|climb|clinic|clip|clock|clog|close|cloth|cloud|clown|club|clump|cluster|clutch|coach|coast|coconut|code|coffee|coil|coin|collect|color|column|combine|come|comfort|comic|common|company|concert|conduct|confirm|congress|connect|consider|control|convince|cook|cool|copper|copy|coral|core|corn|correct|cost|cotton|couch|country|couple|course|cousin|cover|coyote|crack|cradle|craft|cram|crane|crash|crater|crawl|crazy|cream|credit|creek|crew|cricket|crime|crisp|critic|crop|cross|crouch|crowd|crucial|cruel|cruise|crumble|crunch|crush|cry|crystal|cube|culture|cup|cupboard|curious|current|curtain|curve|cushion|custom|cute|cycle|dad|damage|damp|dance|danger|daring|dash|daughter|dawn|day|deal|debate|debris|decade|december|decide|decline|decorate|decrease|deer|defense|define|defy|degree|delay|deliver|demand|demise|denial|dentist|deny|depart|depend|deposit|depth|deputy|derive|describe|desert|design|desk|despair|destroy|detail|detect|develop|device|devote|diagram|dial|diamond|diary|dice|diesel|diet|differ|digital|dignity|dilemma|dinner|dinosaur|direct|dirt|disagree|discover|disease|dish|dismiss|disorder|display|distance|divert|divide|divorce|dizzy|doctor|document|dog|doll|dolphin|domain|donate|donkey|donor|door|dose|double|dove|draft|dragon|drama|drastic|draw|dream|dress|drift|drill|drink|drip|drive|drop|drum|dry|duck|dumb|dune|during|dust|dutch|duty|dwarf|dynamic|eager|eagle|early|earn|earth|easily|east|easy|echo|ecology|economy|edge|edit|educate|effort|egg|eight|either|elbow|elder|electric|elegant|element|elephant|elevator|elite|else|embark|embody|embrace|emerge|emotion|employ|empower|empty|enable|enact|end|endless|endorse|enemy|energy|enforce|engage|engine|enhance|enjoy|enlist|enough|enrich|enroll|ensure|enter|entire|entry|envelope|episode|equal|equip|era|erase|erode|erosion|error|erupt|escape|essay|essence|estate|eternal|ethics|evidence|evil|evoke|evolve|exact|example|excess|exchange|excite|exclude|excuse|execute|exercise|exhaust|exhibit|exile|exist|exit|exotic|expand|expect|expire|explain|expose|express|extend|extra|eye|eyebrow|fabric|face|faculty|fade|faint|faith|fall|false|fame|family|famous|fan|fancy|fantasy|farm|fashion|fat|fatal|father|fatigue|fault|favorite|feature|february|federal|fee|feed|feel|female|fence|festival|fetch|fever|few|fiber|fiction|field|figure|file|film|filter|final|find|fine|finger|finish|fire|firm|first|fiscal|fish|fit|fitness|fix|flag|flame|flash|flat|flavor|flee|flight|flip|float|flock|floor|flower|fluid|flush|fly|foam|focus|fog|foil|fold|follow|food|foot|force|forest|forget|fork|fortune|forum|forward|fossil|foster|found|fox|fragile|frame|frequent|fresh|friend|fringe|frog|front|frost|frown|frozen|fruit|fuel|fun|funny|furnace|fury|future|gadget|gain|galaxy|gallery|game|gap|garage|garbage|garden|garlic|garment|gas|gasp|gate|gather|gauge|gaze|general|genius|genre|gentle|genuine|gesture|ghost|giant|gift|giggle|ginger|giraffe|girl|give|glad|glance|glare|glass|glide|glimpse|globe|gloom|glory|glove|glow|glue|goat|goddess|gold|good|goose|gorilla|gospel|gossip|govern|gown|grab|grace|grain|grant|grape|grass|gravity|great|green|grid|grief|grit|grocery|group|grow|grunt|guard|guess|guide|guilt|guitar|gun|gym|habit|hair|half|hammer|hamster|hand|happy|harbor|hard|harsh|harvest|hat|have|hawk|hazard|head|health|heart|heavy|hedgehog|height|hello|helmet|help|hen|hero|hidden|high|hill|hint|hip|hire|history|hobby|hockey|hold|hole|holiday|hollow|home|honey|hood|hope|horn|horror|horse|hospital|host|hotel|hour|hover|hub|huge|human|humble|humor|hundred|hungry|hunt|hurdle|hurry|hurt|husband|hybrid|ice|icon|idea|identify|idle|ignore|ill|illegal|illness|image|imitate|immense|immune|impact|impose|improve|impulse|inch|include|income|increase|index|indicate|indoor|industry|infant|inflict|inform|inhale|inherit|initial|inject|injury|inmate|inner|innocent|input|inquiry|insane|insect|inside|inspire|install|intact|interest|into|invest|invite|involve|iron|island|isolate|issue|item|ivory|jacket|jaguar|jar|jazz|jealous|jeans|jelly|jewel|job|join|joke|journey|joy|judge|juice|jump|jungle|junior|junk|just|kangaroo|keen|keep|ketchup|key|kick|kid|kidney|kind|kingdom|kiss|kit|kitchen|kite|kitten|kiwi|knee|knife|knock|know|lab|label|labor|ladder|lady|lake|lamp|language|laptop|large|later|latin|laugh|laundry|lava|law|lawn|lawsuit|layer|lazy|leader|leaf|learn|leave|lecture|left|leg|legal|legend|leisure|lemon|lend|length|lens|leopard|lesson|letter|level|liar|liberty|library|license|life|lift|light|like|limb|limit|link|lion|liquid|list|little|live|lizard|load|loan|lobster|local|lock|logic|lonely|long|loop|lottery|loud|lounge|love|loyal|lucky|luggage|lumber|lunar|lunch|luxury|lyrics|machine|mad|magic|magnet|maid|mail|main|major|make|mammal|man|manage|mandate|mango|mansion|manual|maple|marble|march|margin|marine|market|marriage|mask|mass|master|match|material|math|matrix|matter|maximum|maze|meadow|mean|measure|meat|mechanic|medal|media|melody|melt|member|memory|mention|menu|mercy|merge|merit|merry|mesh|message|metal|method|middle|midnight|milk|million|mimic|mind|minimum|minor|minute|miracle|mirror|misery|miss|mistake|mix|mixed|mixture|mobile|model|modify|mom|moment|monitor|monkey|monster|month|moon|moral|more|morning|mosquito|mother|motion|motor|mountain|mouse|move|movie|much|muffin|mule|multiply|muscle|museum|mushroom|music|must|mutual|myself|mystery|myth|naive|name|napkin|narrow|nasty|nation|nature|near|neck|need|negative|neglect|neither|nephew|nerve|nest|net|network|neutral|never|news|next|nice|night|noble|noise|nominee|noodle|normal|north|nose|notable|note|nothing|notice|novel|now|nuclear|number|nurse|nut|oak|obey|object|oblige|obscure|observe|obtain|obvious|occur|ocean|october|odor|off|offer|office|often|oil|okay|old|olive|olympic|omit|once|one|onion|online|only|open|opera|opinion|oppose|option|orange|orbit|orchard|order|ordinary|organ|orient|original|orphan|ostrich|other|outdoor|outer|output|outside|oval|oven|over|own|owner|oxygen|oyster|ozone|pact|paddle|page|pair|palace|palm|panda|panel|panic|panther|paper|parade|parent|park|parrot|party|pass|patch|path|patient|patrol|pattern|pause|pave|payment|peace|peanut|pear|peasant|pelican|pen|penalty|pencil|people|pepper|perfect|permit|person|pet|phone|photo|phrase|physical|piano|picnic|picture|piece|pig|pigeon|pill|pilot|pink|pioneer|pipe|pistol|pitch|pizza|place|planet|plastic|plate|play|please|pledge|pluck|plug|plunge|poem|poet|point|polar|pole|police|pond|pony|pool|popular|portion|position|possible|post|potato|pottery|poverty|powder|power|practice|praise|predict|prefer|prepare|present|pretty|prevent|price|pride|primary|print|priority|prison|private|prize|problem|process|produce|profit|program|project|promote|proof|property|prosper|protect|proud|provide|public|pudding|pull|pulp|pulse|pumpkin|punch|pupil|puppy|purchase|purity|purpose|purse|push|put|puzzle|pyramid|quality|quantum|quarter|question|quick|quit|quiz|quote|rabbit|raccoon|race|rack|radar|radio|rail|rain|raise|rally|ramp|ranch|random|range|rapid|rare|rate|rather|raven|raw|razor|ready|real|reason|rebel|rebuild|recall|receive|recipe|record|recycle|reduce|reflect|reform|refuse|region|regret|regular|reject|relax|release|relief|rely|remain|remember|remind|remove|render|renew|rent|reopen|repair|repeat|replace|report|require|rescue|resemble|resist|resource|response|result|retire|retreat|return|reunion|reveal|review|reward|rhythm|rib|ribbon|rice|rich|ride|ridge|rifle|right|rigid|ring|riot|ripple|risk|ritual|rival|river|road|roast|robot|robust|rocket|romance|roof|rookie|room|rose|rotate|rough|round|route|royal|rubber|rude|rug|rule|run|runway|rural|sad|saddle|sadness|safe|sail|salad|salmon|salon|salt|salute|same|sample|sand|satisfy|satoshi|sauce|sausage|save|say|scale|scan|scare|scatter|scene|scheme|school|science|scissors|scorpion|scout|scrap|screen|script|scrub|sea|search|season|seat|second|secret|section|security|seed|seek|segment|select|sell|seminar|senior|sense|sentence|series|service|session|settle|setup|seven|shadow|shaft|shallow|share|shed|shell|sheriff|shield|shift|shine|ship|shiver|shock|shoe|shoot|shop|short|shoulder|shove|shrimp|shrug|shuffle|shy|sibling|sick|side|siege|sight|sign|silent|silk|silly|silver|similar|simple|since|sing|siren|sister|situate|six|size|skate|sketch|ski|skill|skin|skirt|skull|slab|slam|sleep|slender|slice|slide|slight|slim|slogan|slot|slow|slush|small|smart|smile|smoke|smooth|snack|snake|snap|sniff|snow|soap|soccer|social|sock|soda|soft|solar|soldier|solid|solution|solve|someone|song|soon|sorry|sort|soul|sound|soup|source|south|space|spare|spatial|spawn|speak|special|speed|spell|spend|sphere|spice|spider|spike|spin|spirit|split|spoil|sponsor|spoon|sport|spot|spray|spread|spring|spy|square|squeeze|squirrel|stable|stadium|staff|stage|stairs|stamp|stand|start|state|stay|steak|steel|stem|step|stereo|stick|still|sting|stock|stomach|stone|stool|story|stove|strategy|street|strike|strong|struggle|student|stuff|stumble|style|subject|submit|subway|success|such|sudden|suffer|sugar|suggest|suit|summer|sun|sunny|sunset|super|supply|supreme|sure|surface|surge|surprise|surround|survey|suspect|sustain|swallow|swamp|swap|swarm|swear|sweet|swift|swim|swing|switch|sword|symbol|symptom|syrup|system|table|tackle|tag|tail|talent|talk|tank|tape|target|task|taste|tattoo|taxi|teach|team|tell|ten|tenant|tennis|tent|term|test|text|thank|that|theme|then|theory|there|they|thing|this|thought|three|thrive|throw|thumb|thunder|ticket|tide|tiger|tilt|timber|time|tiny|tip|tired|tissue|title|toast|tobacco|today|toddler|toe|together|toilet|token|tomato|tomorrow|tone|tongue|tonight|tool|tooth|top|topic|topple|torch|tornado|tortoise|toss|total|tourist|toward|tower|town|toy|track|trade|traffic|tragic|train|transfer|trap|trash|travel|tray|treat|tree|trend|trial|tribe|trick|trigger|trim|trip|trophy|trouble|truck|true|truly|trumpet|trust|truth|try|tube|tuition|tumble|tuna|tunnel|turkey|turn|turtle|twelve|twenty|twice|twin|twist|two|type|typical|ugly|umbrella|unable|unaware|uncle|uncover|under|undo|unfair|unfold|unhappy|uniform|unique|unit|universe|unknown|unlock|until|unusual|unveil|update|upgrade|uphold|upon|upper|upset|urban|urge|usage|use|used|useful|useless|usual|utility|vacant|vacuum|vague|valid|valley|valve|van|vanish|vapor|various|vast|vault|vehicle|velvet|vendor|venture|venue|verb|verify|version|very|vessel|veteran|viable|vibrant|vicious|victory|video|view|village|vintage|violin|virtual|virus|visa|visit|visual|vital|vivid|vocal|voice|void|volcano|volume|vote|voyage|wage|wagon|wait|walk|wall|walnut|want|warfare|warm|warrior|wash|wasp|waste|water|wave|way|wealth|weapon|wear|weasel|weather|web|wedding|weekend|weird|welcome|west|wet|whale|what|wheat|wheel|when|where|whip|whisper|wide|width|wife|wild|will|win|window|wine|wing|wink|winner|winter|wire|wisdom|wise|wish|witness|wolf|woman|wonder|wood|wool|word|work|world|worry|worth|wrap|wreck|wrestle|wrist|write|wrong|yard|year|yellow|you|young|youth|zebra|zero|zone|zoo".split("|");var rQ="Invalid mnemonic",sJ="Invalid entropy",rJ="Invalid mnemonic checksum";function ym(l){return(l||"").normalize("NFKD")}function iJ(l){return parseInt(l,2)}function mJ(l){return l.map(A=>A.toString(2).padStart(8,"0")).join("")}function VJ(l){return mJ(Array.from(Fm(l))).slice(0,l.length*8/32)}function Qm(l,A){return la(uG(ym(l)),uG(`mnemonic${ym(A)}`)).password}function Nm(l,A=sQ){let G=ym(l).split(" ");if(G.length%3!==0)throw new Error(rQ);let b=G.map(g=>{let n=A.indexOf(g);if(n===-1)throw new Error(rQ);return n.toString(2).padStart(11,"0")}).join(""),t=Math.floor(b.length/33)*32,c=b.slice(0,t),B=b.slice(t),d=c.match(/(.{1,8})/g)?.map(iJ);if(!d||d.length%4!==0||d.length<16||d.length>32)throw new Error(sJ);let Z=Tl(d);if(VJ(Z)!==B)throw new Error(rJ);return Z}function iQ(l,A){try{Nm(l,A)}catch{return!1}return!0}function mQ(l,A,G){return!PA||!A&&!G&&TA()?jV(l):Nm(l,A)}function go(l,A,G){return!PA||!A&&!G&&TA()?DV(l):iQ(l,A)}function Em(l,A="",G,b=32){if(go(l)){if(![32,64].includes(b))throw new Error(`Invalid seed length ${b}, expected 32 or 64`)}else throw new Error("Invalid bip39 mnemonic specified");return b===32?!PA||!G&&TA()?TV(l,A):Qm(l,A).subarray(0,32):Qm(l,A)}function vm(l,A="",G,b){if(go(l,G,b)){if(!G&&!b&&TA())return MV(l,A)}else throw new Error("Invalid bip39 mnemonic specified");let t=mQ(l,G),c=uG(`mnemonic${A}`);return la(t,c).password.slice(0,32)}function Wo(l,A){return l<<A|l>>>32-A}function gd(l,A){let G=l[A+3]&255;return G=G<<8|l[A+2]&255,G=G<<8|l[A+1]&255,G<<8|l[A+0]&255}function Hm(l,A,G){for(let b=0;b<4;b++)l[A+b]=G&255,G>>>=8}function uJ(l,A,G,b,t){let c=0;for(let B=0;B<t;B++)c|=l[A+B]^G[b+B];return(1&c-1>>>8)-1}function xm(l,A,G,b,t){let c=new Uint32Array(16),B=new Uint32Array(16),e=new Uint32Array(16),d=new Uint32Array(4),Z,g,n;for(Z=0;Z<4;Z++)B[5*Z]=gd(b,4*Z),B[1+Z]=gd(G,4*Z),B[6+Z]=gd(A,4*Z),B[11+Z]=gd(G,16+4*Z);for(Z=0;Z<16;Z++)e[Z]=B[Z];for(Z=0;Z<20;Z++){for(g=0;g<4;g++){for(n=0;n<4;n++)d[n]=B[(5*g+4*n)%16];for(d[1]^=Wo(d[0]+d[3]|0,7),d[2]^=Wo(d[1]+d[0]|0,9),d[3]^=Wo(d[2]+d[1]|0,13),d[0]^=Wo(d[3]+d[2]|0,18),n=0;n<4;n++)c[4*g+(g+n)%4]=d[n]}for(n=0;n<16;n++)B[n]=c[n]}if(t){for(Z=0;Z<16;Z++)B[Z]=B[Z]+e[Z]|0;for(Z=0;Z<4;Z++)B[5*Z]=B[5*Z]-gd(b,4*Z)|0,B[6+Z]=B[6+Z]-gd(A,4*Z)|0;for(Z=0;Z<4;Z++)Hm(l,4*Z,B[5*Z]),Hm(l,16+4*Z,B[6+Z])}else for(Z=0;Z<16;Z++)Hm(l,4*Z,B[Z]+e[Z]|0)}var fm=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function YJ(l,A,G,b,t,c,B){let e=new Uint8Array(16),d=new Uint8Array(64),Z,g;if(!t)return 0;for(g=0;g<16;g++)e[g]=0;for(g=0;g<8;g++)e[g]=c[g];for(;t>=64;){for(xm(d,e,B,fm,!1),g=0;g<64;g++)l[A+g]=(G?G[b+g]:0)^d[g];for(Z=1,g=8;g<16;g++)Z=Z+(e[g]&255)|0,e[g]=Z&255,Z>>>=8;t-=64,A+=64,G&&(b+=64)}if(t>0)for(xm(d,e,B,fm,!1),g=0;g<t;g++)l[A+g]=(G?G[b+g]:0)^d[g];return 0}function km(l,A,G,b,t,c,B){let e=new Uint8Array(32);return xm(e,c,B,fm,!0),YJ(l,A,G,b,t,c.subarray(16),e)}function Jm(l,A){let G=0;for(let b=0;b<17;b++)G=G+(l[b]+A[b]|0)|0,l[b]=G&255,G>>>=8}var IJ=new Uint32Array([5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252]);function VQ(l,A,G,b,t,c){let B,e,d,Z=new Uint32Array(17),g=new Uint32Array(17),n=new Uint32Array(17),h=new Uint32Array(17),W=new Uint32Array(17);for(e=0;e<17;e++)g[e]=n[e]=0;for(e=0;e<16;e++)g[e]=c[e];for(g[3]&=15,g[4]&=252,g[7]&=15,g[8]&=252,g[11]&=15,g[12]&=252,g[15]&=15;t>0;){for(e=0;e<17;e++)h[e]=0;for(e=0;e<16&&e<t;++e)h[e]=G[b+e];for(h[e]=1,b+=e,t-=e,Jm(n,h),B=0;B<17;B++)for(Z[B]=0,e=0;e<17;e++)Z[B]=Z[B]+n[e]*(e<=B?g[B-e]:320*g[B+17-e]|0)|0|0;for(B=0;B<17;B++)n[B]=Z[B];for(d=0,e=0;e<16;e++)d=d+n[e]|0,n[e]=d&255,d>>>=8;for(d=d+n[16]|0,n[16]=d&3,d=5*(d>>>2)|0,e=0;e<16;e++)d=d+n[e]|0,n[e]=d&255,d>>>=8;d=d+n[16]|0,n[16]=d}for(e=0;e<17;e++)W[e]=n[e];Jm(n,IJ);let m=-(n[16]>>>7)|0;for(e=0;e<17;e++)n[e]^=m&(W[e]^n[e]);for(e=0;e<16;e++)h[e]=c[e+16];for(h[16]=0,Jm(n,h),e=0;e<16;e++)l[A+e]=n[e];return 0}function RJ(l,A,G,b,t,c){let B=new Uint8Array(16);return VQ(B,0,G,b,t,c),uJ(l,A,B,0,16)}function XJ(l,A,G,b,t){if(G<32)return-1;km(l,0,A,0,G,b,t),VQ(l,16,l,32,G-32,l);for(let c=0;c<16;c++)l[c]=0;return 0}function pJ(l,A,G,b,t){let c=new Uint8Array(32);if(G<32||(km(c,0,null,0,32,b,t),RJ(A,16,A,32,G-32,c)!==0))return-1;km(l,0,A,0,G,b,t);for(let B=0;B<32;B++)l[B]=0;return 0}var FJ=32,yJ=24,wm=32,Um=16;function uQ(l,A){if(l.length!==FJ)throw new Error("bad key size");if(A.length!==yJ)throw new Error("bad nonce size")}function YQ(...l){for(let A=0,G=l.length;A<G;A++)if(!(l[A]instanceof Uint8Array))throw new TypeError("unexpected type, use Uint8Array")}function IQ(l,A,G){YQ(l,A,G),uQ(G,A);let b=new Uint8Array(wm+l.length),t=new Uint8Array(b.length);for(let c=0;c<l.length;c++)b[c+wm]=l[c];return XJ(t,b,b.length,A,G),t.subarray(Um)}function RQ(l,A,G){YQ(l,A,G),uQ(G,A);let b=new Uint8Array(Um+l.length),t=new Uint8Array(b.length);for(let c=0;c<l.length;c++)b[c+Um]=l[c];return b.length<32||pJ(t,b,b.length,A,G)!==0?null:t.subarray(wm)}function Cm(l,A,G){return RQ(l,A,G)}function Sm(l,A,G=ed(24)){return{encrypted:IQ(l,G,A),nonce:G}}function XQ(l,A,G,b,t,c){let B=l[A++]^G[b++],e=l[A++]^G[b++],d=l[A++]^G[b++],Z=l[A++]^G[b++],g=l[A++]^G[b++],n=l[A++]^G[b++],h=l[A++]^G[b++],W=l[A++]^G[b++],m=l[A++]^G[b++],Y=l[A++]^G[b++],R=l[A++]^G[b++],u=l[A++]^G[b++],i=l[A++]^G[b++],I=l[A++]^G[b++],Q=l[A++]^G[b++],f=l[A++]^G[b++],U=B,J=e,M=d,C=Z,D=g,$=n,K=h,y=W,r=m,F=Y,E=R,x=u,s=i,p=I,X=Q,o=f;for(let a=0;a<8;a+=2)D^=qA(U+s|0,7),r^=qA(D+U|0,9),s^=qA(r+D|0,13),U^=qA(s+r|0,18),F^=qA($+J|0,7),p^=qA(F+$|0,9),J^=qA(p+F|0,13),$^=qA(J+p|0,18),X^=qA(E+K|0,7),M^=qA(X+E|0,9),K^=qA(M+X|0,13),E^=qA(K+M|0,18),C^=qA(o+x|0,7),y^=qA(C+o|0,9),x^=qA(y+C|0,13),o^=qA(x+y|0,18),J^=qA(U+C|0,7),M^=qA(J+U|0,9),C^=qA(M+J|0,13),U^=qA(C+M|0,18),K^=qA($+D|0,7),y^=qA(K+$|0,9),D^=qA(y+K|0,13),$^=qA(D+y|0,18),x^=qA(E+F|0,7),r^=qA(x+E|0,9),F^=qA(r+x|0,13),E^=qA(F+r|0,18),s^=qA(o+X|0,7),p^=qA(s+o|0,9),X^=qA(p+s|0,13),o^=qA(X+p|0,18);t[c++]=B+U|0,t[c++]=e+J|0,t[c++]=d+M|0,t[c++]=Z+C|0,t[c++]=g+D|0,t[c++]=n+$|0,t[c++]=h+K|0,t[c++]=W+y|0,t[c++]=m+r|0,t[c++]=Y+F|0,t[c++]=R+E|0,t[c++]=u+x|0,t[c++]=i+s|0,t[c++]=I+p|0,t[c++]=Q+X|0,t[c++]=f+o|0}function zm(l,A,G,b,t){let c=b+0,B=b+16*t;for(let e=0;e<16;e++)G[B+e]=l[A+(2*t-1)*16+e];for(let e=0;e<t;e++,c+=16,A+=16)XQ(G,B,l,A,G,c),e>0&&(B+=16),XQ(G,c,l,A+=16,G,B)}function QJ(l,A,G){let b=ua({dkLen:32,asyncTick:10,maxmem:1073742848},G),{N:t,r:c,p:B,dkLen:e,asyncTick:d,maxmem:Z,onProgress:g}=b;if(mG(t),mG(c),mG(B),mG(e),mG(d),mG(Z),g!==void 0&&typeof g!="function")throw new Error("progressCb should be function");let n=128*c,h=n/4,W=Math.pow(2,32);if(t<=1||t&t-1||t>W)throw new Error("Scrypt: N must be larger than 1, a power of 2, and less than 2^32");if(B<0||B>(W-1)*32/n)throw new Error("Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)");if(e<0||e>(W-1)*32)throw new Error("Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32");if(n*(t+B)>Z)throw new Error("Scrypt: memused is bigger than maxMem. Expected 128 * r * (N + p) > maxmem of "+Z);let Y=$n(ye,l,A,{c:1,dkLen:n*B}),R=tt(Y),u=tt(new Uint8Array(n*t)),i=tt(new Uint8Array(n)),I=()=>{};if(g){let Q=2*t*B,f=Math.max(Math.floor(Q/1e4),1),U=0;I=()=>{U++,g&&(!(U%f)||U===Q)&&g(U/Q)}}return{N:t,r:c,p:B,dkLen:e,blockSize32:h,V:u,B32:R,B:Y,tmp:i,blockMixCb:I,asyncTick:d}}function NJ(l,A,G,b,t){let c=$n(ye,l,G,{c:1,dkLen:A});return MG(G,b,t),c}function pQ(l,A,G){let{N:b,r:t,p:c,dkLen:B,blockSize32:e,V:d,B32:Z,B:g,tmp:n,blockMixCb:h}=QJ(l,A,G);ct(Z);for(let W=0;W<c;W++){let m=e*W;for(let Y=0;Y<e;Y++)d[Y]=Z[m+Y];for(let Y=0,R=0;Y<b-1;Y++)zm(d,R,d,R+=e,t),h();zm(d,(b-1)*e,Z,m,t),h();for(let Y=0;Y<b;Y++){let R=Z[m+e-16]%b;for(let u=0;u<e;u++)n[u]=Z[m+u]^d[R*e+u];zm(n,0,Z,m,t),h()}}return ct(Z),NJ(l,B,g,d,n)}var FQ=[{N:8192,p:10,r:8},{N:16384,p:5,r:8},{N:32768,p:3,r:8},{N:32768,p:1,r:8},{N:65536,p:2,r:8},{N:131072,p:1,r:8}],yQ={N:1<<17,p:1,r:8};function Aa(l,A=ed(),G=yQ,b){let t=Tl(l);return{params:G,password:!PA||!b&&TA()?eu(t,A,Math.log2(G.N),G.r,G.p):pQ(t,A,te({dkLen:64},G)),salt:A}}function jm(l){if(!(l instanceof Uint8Array))throw new Error("Expected input to be a Uint8Array");if(l.length<44)throw new Error(`Invalid input length: expected 44 bytes, found ${l.length}`);let A=l.subarray(0,32),G=Jd(l.subarray(32,36),jW).toNumber(),b=Jd(l.subarray(36,40),jW).toNumber(),t=Jd(l.subarray(40,44),jW).toNumber();if(G>1<<20||b>4||t>16)throw new Error("Scrypt parameters exceed safe limits");if(!FQ.some(B=>B.N===G&&B.p===b&&B.r===t))throw new Error("Invalid injected scrypt params found");return{params:{N:G,p:b,r:t},salt:A}}function Mm(l,{N:A,p:G,r:b}){return nG(l,kG(A,MW),kG(G,MW),kG(b,MW))}var oo=["scrypt","xsalsa20-poly1305"],QQ=["none"],NQ="3";function Tm(l,A,G=oo){if(l){if(G.includes("xsalsa20-poly1305")&&!A)throw new Error("Password required to decode encrypted data")}else throw new Error("No encrypted data available to decode");let b=l;if(A){let t;if(G.includes("scrypt")){let{params:c,salt:B}=jm(l);t=Aa(A,B,c).password,l=l.subarray(44)}else t=uG(A);b=Cm(l.subarray(24),l.subarray(0,24),Po(t,256,!0))}if(!b)throw new Error("Unable to decode using the supplied passphrase");return b}function Dm(l,A,G){return{encoded:Ym(l),encoding:{content:A,type:G?oo:QQ,version:NQ}}}var vQ=l=>(A,G,b)=>nQ(A,G,b,l,!0),Lm=[["ecdsa",vQ("blake2")],["ethereum",vQ("keccak")]],HQ=[["ed25519",xy],["sr25519",tQ]];function ho(l,{message:A,publicKey:G,signature:b},t=[...HQ,...Lm]){return l.isValid=t.some(([c,B])=>{try{if(B(A,b,G))return l.crypto=c,!0}catch{}return!1}),l}function vJ(l,{message:A,publicKey:G,signature:b}){if(![0,1,2].includes(b[0])||![65,66].includes(b.length))throw new Error(`Unknown crypto type, expected signature prefix [0..2], found ${b[0]}`);return b.length===66?l=ho(l,{message:A,publicKey:G,signature:b.subarray(1)},Lm):(l=ho(l,{message:A,publicKey:G,signature:b.subarray(1)},HQ),l.isValid||(l=ho(l,{message:A,publicKey:G,signature:b},Lm)),l.isValid||(l.crypto="none")),l}function HJ(l){return[0,1,2].includes(l[0])&&[65,66].includes(l.length)?vJ:ho}function so(l,A,G){let b=Tl(A);if(![64,65,66].includes(b.length))throw new Error(`Invalid signature length, expected [64..66] bytes, found ${b.length}`);let t=Pt(G),c={message:Tl(l),publicKey:t,signature:b},B={crypto:"none",isValid:!1,isWrapped:BZ(c.message,!0),publicKey:t},e=BZ(c.message,!1),d=HJ(b);return d(B,c),B.crypto!=="none"||B.isWrapped&&!e?B:(c.message=e?qo(c.message):_o(c.message),d(B,c))}var jB=new Uint8Array([161,35,3,33,0]),Wd=new Uint8Array([48,83,2,1,1,48,5,6,3,43,101,112,4,34,4,32]),JQ=32;var Om=64,xQ=32;var Ga=Wd.length;function fQ(l,A,G){let b=Array.isArray(G)||G===void 0?G:[G],t=Tm(A,l,b),c=t.subarray(0,Wd.length);if(!jb(c,Wd))throw new Error("Invalid encoding header found in body");let B=t.subarray(Ga,Ga+Om),e=Ga+Om,d=t.subarray(e,e+jB.length);if(!jb(d,jB)&&(e=Ga+xQ,B=t.subarray(Ga,e),d=t.subarray(e,e+jB.length),!jb(d,jB)))throw new Error("Invalid encoding divider found in body");let Z=e+jB.length;return{publicKey:t.subarray(Z,Z+JQ),secretKey:B}}function kQ({publicKey:l,secretKey:A},G){if(!A)throw new Error("Expected a valid secretKey to be passed to encode");let b=nG(Wd,A,jB,l);if(!G)return b;let{params:t,password:c,salt:B}=Aa(G),{encrypted:e,nonce:d}=Sm(b,c.subarray(0,32));return nG(Mm(B,t),d,e)}function wQ(l,{address:A,meta:G},b,t){return te(Dm(b,["pkcs8",l],t),{address:A,meta:G})}var JJ=new Uint8Array,xJ={ecdsa:qt,ed25519:xe,ethereum:qt,sr25519:On},UQ={ecdsa:new Uint8Array([2]),ed25519:new Uint8Array([0]),ethereum:new Uint8Array([2]),sr25519:new Uint8Array([1])},CQ={ecdsa:(l,A)=>Zo(l,A,"blake2"),ed25519:em,ethereum:(l,A)=>Zo(l,A,"keccak"),sr25519:rm},ro={ecdsa:l=>l.length>32?Mb(l):l,ed25519:l=>l,ethereum:l=>l.length===20?l:zB(we(l)),sr25519:l=>l};function ba(l){return!l||Hd(l)}function SQ(l,A,G){return Mb(nG(A||"",G||"",l))}function Ue({toSS58:l,type:A},{publicKey:G,secretKey:b},t={},c=null,B){let e=(g,n)=>{let h=fQ(g,n||c,B);if(h.secretKey.length===64)G=h.publicKey,b=h.secretKey;else{let W=xJ[A](h.secretKey);G=W.publicKey,b=W.secretKey}},d=g=>(ba(b)&&c&&e(g,c),c=kQ({publicKey:G,secretKey:b},g),B=void 0,c),Z=()=>{let g=ro[A](G);return A==="ethereum"?_n(g):l(g)};return{get address(){return Z()},get addressRaw(){let g=ro[A](G);return A==="ethereum"?g.slice(-20):g},get isLocked(){return ba(b)},get meta(){return t},get publicKey(){return G},get type(){return A},decodePkcs8:e,derive:(g,n)=>{if(A==="ethereum")throw new Error("Unable to derive on this keypair");if(ba(b))throw new Error("Cannot derive on a locked keypair");let{path:h}=kn(g),W=Ln({publicKey:G,secretKey:b},h,A);return Ue({toSS58:l,type:A},W,n,null)},encodePkcs8:g=>d(g),lock:()=>{b=new Uint8Array},setMeta:g=>{t=te({},t,g)},sign:(g,n={})=>{if(ba(b))throw new Error("Cannot sign with a locked key pair");return nG(n.withType?UQ[A]:JJ,CQ[A](Tl(g),{publicKey:G,secretKey:b}))},toJson:g=>{let n=["ecdsa","ethereum"].includes(A)?G.length===20?dt(G):dt(qn(G)):Z();return wQ(A,{address:n,meta:t},d(g),!!g)},unlock:g=>e(g),verify:(g,n,h)=>so(g,n,ro[A](Tl(h))).isValid,vrfSign:(g,n,h)=>{if(ba(b))throw new Error("Cannot sign with a locked key pair");if(A==="sr25519")return im(g,{secretKey:b},n,h);let W=CQ[A](Tl(g),{publicKey:G,secretKey:b});return nG(SQ(W,n,h),W)},vrfVerify:(g,n,h,W,m)=>A==="sr25519"?mm(g,n,G,W,m):so(g,nG(UQ[A],n.subarray(32)),ro[A](Tl(h))).isValid&&jb(n.subarray(0,32),SQ(n.subarray(32),W,m))}}var zQ="bottom drive obey lake curtain smoke basket hold race lonely fit walk";var Ce,io=class{constructor(){EG(this,Ce,{})}add(A){return GA(this,Ce)[Pt(A.address).toString()]=A,A}all(){return Object.values(GA(this,Ce))}get(A){let G=GA(this,Ce)[Pt(A).toString()];if(!G)throw new Error(`Unable to retrieve keypair '${Hb(A)||Vb(A)?dt(Tl(A)):A}'`);return G}remove(A){delete GA(this,Ce)[Pt(A).toString()]}};Ce=new WeakMap;var Pm={ecdsa:l=>qt(l),ed25519:l=>xe(l),ethereum:l=>qt(l),sr25519:l=>On(l)};function fJ({publicKey:l}){return l}var Fc,ca,od,ta=class{constructor(A={}){EG(this,Fc);EG(this,ca);EG(this,od);el(this,"decodeAddress",Pt);el(this,"encodeAddress",(A,G)=>this.type==="ethereum"?_n(A):Pn(A,G??GA(this,od)));if(A.type=A.type||"ed25519",!["ecdsa","ethereum","ed25519","sr25519"].includes(A.type||"undefined"))throw new Error(`Expected a keyring type of either 'ed25519', 'sr25519', 'ethereum' or 'ecdsa', found '${A.type||"unknown"}`);bG(this,Fc,new io),bG(this,od,A.ss58Format),bG(this,ca,A.type)}get pairs(){return this.getPairs()}get publicKeys(){return this.getPublicKeys()}get type(){return GA(this,ca)}addPair(A){return GA(this,Fc).add(A)}addFromAddress(A,G={},b=null,t=this.type,c,B){let e=this.decodeAddress(A,c);return this.addPair(Ue({toSS58:this.encodeAddress,type:t},{publicKey:e,secretKey:new Uint8Array},G,b,B))}addFromJson(A,G){return this.addPair(this.createFromJson(A,G))}addFromMnemonic(A,G={},b=this.type,t){return this.addFromUri(A,G,b,t)}addFromPair(A,G={},b=this.type){return this.addPair(this.createFromPair(A,G,b))}addFromSeed(A,G={},b=this.type){return this.addPair(Ue({toSS58:this.encodeAddress,type:b},Pm[b](A),G,null))}addFromUri(A,G={},b=this.type,t){return this.addPair(this.createFromUri(A,G,b,t))}createFromJson({address:A,encoded:G,encoding:{content:b,type:t,version:c},meta:B},e){if(c==="3"&&b[0]!=="pkcs8")throw new Error(`Unable to decode non-pkcs8 type, [${b.join(",")}] found}`);let d=c==="0"||!Array.isArray(b)?this.type:b[1],Z=Array.isArray(t)?t:[t];if(!["ed25519","sr25519","ecdsa","ethereum"].includes(d))throw new Error(`Unknown crypto type ${d}`);let g=Vb(A)?vb(A):this.decodeAddress(A,e),n=Vb(G)?vb(G):um(G);return Ue({toSS58:this.encodeAddress,type:d},{publicKey:g,secretKey:new Uint8Array},B,n,Z)}createFromPair(A,G={},b=this.type){return Ue({toSS58:this.encodeAddress,type:b},A,G,null)}createFromUri(A,G={},b=this.type,t){let c=A.startsWith("//")?`${zQ}${A}`:A,{derivePath:B,password:e,path:d,phrase:Z}=Ji(c),g,n=Vb(Z,256);if(n)g=vb(Z);else{let W=Z.split(" ");if([12,15,18,21,24].includes(W.length))g=b==="ethereum"?Em(Z,"",!1,64):vm(Z,e,t);else{if(Z.length>32)throw new Error("specified phrase is not a valid mnemonic and is invalid as a raw seed at > 32 bytes");g=uG(Z.padEnd(32))}}let h=b==="ethereum"?n?Pm[b](g):pm(g,B.substring(1)):Ln(Pm[b](g),d,b);return Ue({toSS58:this.encodeAddress,type:b},h,G,null)}getPair(A){return GA(this,Fc).get(A)}getPairs(){return GA(this,Fc).all()}getPublicKeys(){return GA(this,Fc).all().map(fJ)}removePair(A){GA(this,Fc).remove(A)}setSS58Format(A){bG(this,od,A)}toJson(A,G){return GA(this,Fc).get(A).toJson(G)}};Fc=new WeakMap,ca=new WeakMap,od=new WeakMap;var hd=class{constructor(A){el(this,"token");if(this.token=A,!A)throw new Error("DelegationAuthProvider requires a non-empty delegation token")}async authenticate(A){let G={Authorization:`Bearer ${this.token}`};return A.body===void 0?{headers:G}:(G["Content-Type"]="application/json",{headers:G,body:new TextEncoder().encode(JSON.stringify(A.body))})}};var CJ="cef-widget:identity-request",SJ="cef-widget:identity-response",zJ="cef-widget:sign-request",jJ="cef-widget:sign-response";var DQ="unsupported-version";var sd=class extends Error{constructor(A){super(`WidgetProtocolVersionError: ${A}`),this.name="WidgetProtocolVersionError"}},mo=class extends Error{constructor(A){super(`WidgetMalformedMessageError: ${A}`),this.name="WidgetMalformedMessageError"}};function LQ(l){return l!==void 0&&l!==1}function MJ(l){if(!Array.isArray(l)||l.length>65536)return!1;for(let A=0;A<l.length;A++){if(!(A in l))return!1;let G=l[A];if(typeof G!="number"||!Number.isInteger(G)||G<0||G>255)return!1}return!0}var TQ=!1,rd=new Map;function OQ(){TQ||(TQ=!0,window.addEventListener("message",l=>{if(l.source!==window.parent)return;let A=l.data;if(!A||typeof A!="object")return;let{type:G,requestId:b}=A;if(typeof b!="string"||G!==SJ&&G!==jJ)return;let t=rd.get(b);t&&(rd.delete(b),t.resolve(A))}))}function PQ(){return`${Date.now()}-${Math.random().toString(36).slice(2)}`}var Km;async function TJ(){if(window.parent===window)return null;if(Km!==void 0)return Km;OQ();let l=400,A=8e3,G=Date.now()+A;return new Promise((b,t)=>{let c=!1,B,e,d=new Set;function Z(){c=!0,B!==void 0&&(clearTimeout(B),B=void 0),e!==void 0&&(clearTimeout(e),e=void 0);for(let h of d)rd.delete(h);d.clear()}function g(){if(c)return;let h=PQ();d.add(h),rd.set(h,{resolve:W=>{if(c)return;let m=W;if(LQ(m.v)){Z(),t(new sd(`the host replied in protocol v${String(m.v)}; this build speaks v1`));return}if(m.errorCode===DQ){Z(),t(new sd(`the host rejected protocol v1 (${m.error??"no detail"})`));return}if(m.error||!m.pubkey){n();return}let Y={pubkey:m.pubkey,sigType:m.sigType??"ed25519",...m.token?{token:m.token}:{},...m.context?{context:m.context}:{}};Z(),Km=Y,b(Y)},reject:()=>{c||n()}}),window.parent.postMessage({type:CJ,requestId:h,v:1},"*"),n()}function n(){if(c)return;B!==void 0&&(clearTimeout(B),B=void 0);let h=G-Date.now();if(h<=0){Z(),b(null);return}B=setTimeout(()=>{c||g()},Math.min(l,h))}g(),e=setTimeout(()=>{c||(Z(),b(null))},A+l)})}async function DJ(l){if(window.parent===window)throw new Error("sign called outside of an iframe");if(l.length>65536)throw new mo(`sign-request.bytes is ${l.length} bytes; the contract caps it at 65536`);OQ();let A=6e4,G=PQ();return new Promise((b,t)=>{let c=setTimeout(()=>{rd.delete(G),t(new Error("widget signing timed out \u2014 the host page may have closed the widget"))},A);rd.set(G,{resolve:B=>{clearTimeout(c);let e=B;LQ(e.v)?t(new sd(`the host replied in protocol v${String(e.v)}; this build speaks v1`)):e.errorCode===DQ?t(new sd(`the host rejected protocol v1 (${e.error??"no detail"})`)):e.error?t(new Error(e.error)):e.signature===null?t(new Error("widget signing was declined")):MJ(e.signature)?b(Uint8Array.from(e.signature)):t(new mo("sign-response.signature must be null or an array of integers 0-255"))},reject:B=>{clearTimeout(c),t(B)}}),window.parent.postMessage({type:zJ,requestId:G,v:1,bytes:Array.from(l)},"*")})}function KQ(){return{requestIdentity:TJ,sign:DJ}}var LJ=54;function qm(l,A,G){return{type:A,address:Pn(vb(l),LJ),publicKey:vb(l),isReady:async()=>!0,sign:b=>G(b)}}var AN=po($Q(),1);var lN=["private_key","ed25519_private_key","eth_private_key"];function OJ(l){let A=l.trim().replace(/^0x/i,"");return/^[0-9a-fA-F]{64,}$/.test(A)?"0x"+A.slice(0,64).toLowerCase():null}async function PJ(l){for(let A of lN)try{let G=await l.request({method:A});if(typeof G!="string")continue;let b=OJ(G);if(b)return b}catch{}throw new Error("standalone wallet: could not extract embed-wallet seed. Tried: "+lN.join(", "))}function KJ(l){return l.startsWith("0x")?l:`0x${l}`}async function GN(l){await zF();let A=new AN.EmbedWallet({appId:l.appId,env:l.env});await A.init({appId:l.appId,env:l.env,popupMode:"modal"}),await A.connect();let b=await A.getSigner({type:"ed25519"}).getAccount(),t=KJ(b.publicKey).toLowerCase(),c=await PJ(A.provider),e=new ta({type:"ed25519"}).addFromSeed(vb(c)),d=dt(e.publicKey);if(d!==t)throw new Error(`[widget-runtime] standalone wallet: derived pubkey (${d}) does not match the wallet's pubkey (${t}) \u2014 refusing to sign.`);return{pubkey:()=>t,sigType:"ed25519",signRawBytes:async Z=>e.sign(Z)}}var iG=class extends Error{constructor(l,A,G,b){super(A?`${l}: ${A}`:l),this.code=l,this.detail=A,this.traceId=G,this.status=b,this.name="WalletError"}toJSON(){return{name:this.name,code:this.code,detail:this.detail,traceId:this.traceId,message:this.message}}};function qJ(l){if(l.length>=255)throw new TypeError("Alphabet too long");let A=new Uint8Array(256);for(let Z=0;Z<A.length;Z++)A[Z]=255;for(let Z=0;Z<l.length;Z++){let g=l.charAt(Z),n=g.charCodeAt(0);if(A[n]!==255)throw new TypeError(g+" is ambiguous");A[n]=Z}let G=l.length,b=l.charAt(0),t=Math.log(G)/Math.log(256),c=Math.log(256)/Math.log(G);function B(Z){if(Z instanceof Uint8Array||(ArrayBuffer.isView(Z)?Z=new Uint8Array(Z.buffer,Z.byteOffset,Z.byteLength):Array.isArray(Z)&&(Z=Uint8Array.from(Z))),!(Z instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(Z.length===0)return"";let g=0,n=0,h=0,W=Z.length;for(;h!==W&&Z[h]===0;)h++,g++;let m=(W-h)*c+1>>>0,Y=new Uint8Array(m);for(;h!==W;){let i=Z[h],I=0;for(let Q=m-1;(i!==0||I<n)&&Q!==-1;Q--,I++)i+=256*Y[Q]>>>0,Y[Q]=i%G>>>0,i=i/G>>>0;if(i!==0)throw new Error("Non-zero carry");n=I,h++}let R=m-n;for(;R!==m&&Y[R]===0;)R++;let u=b.repeat(g);for(;R<m;++R)u+=l.charAt(Y[R]);return u}function e(Z){if(typeof Z!="string")throw new TypeError("Expected String");if(Z.length===0)return new Uint8Array;let g=0,n=0,h=0;for(;Z[g]===b;)n++,g++;let W=(Z.length-g)*t+1>>>0,m=new Uint8Array(W);for(;g<Z.length;){let i=Z.charCodeAt(g);if(i>255)return;let I=A[i];if(I===255)return;let Q=0;for(let f=W-1;(I!==0||Q<h)&&f!==-1;f--,Q++)I+=G*m[f]>>>0,m[f]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");h=Q,g++}let Y=W-h;for(;Y!==W&&m[Y]===0;)Y++;let R=new Uint8Array(n+(W-Y)),u=n;for(;Y!==W;)R[u++]=m[Y++];return R}function d(Z){let g=e(Z);if(g)return g;throw new Error("Non-base"+G+" character")}return{encode:B,decodeUnsafe:e,decode:d}}var bN=qJ;var _J="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",tN=bN(_J);var Eal=new Uint8Array([241,55,252,128,200,121,231,173,149,167,104,105,124,215,6,125,113,218,113,114,238,51,232,185,156,209,26,46,78,6,58,137]);var val=new TextEncoder().encode("SS58PRE");function cN(l){let A=tN.decode(l);if(A.length!==32)throw new Error(`expected a 32-byte Ed25519 pubkey from the Solana address, got ${A.length}`);return A}var $J="cere-wallet-root-wrap-v1",lx="v1",Hal={[lx]:$J};var id=(l,A,G)=>new Promise((b,t)=>{var c=d=>{try{e(G.next(d))}catch(Z){t(Z)}},B=d=>{try{e(G.throw(d))}catch(Z){t(Z)}},e=d=>d.done?b(d.value):Promise.resolve(d.value).then(c,B);e((G=G.apply(l,A)).next())}),ZN=class{constructor(l){this.chain="evm",this.address=l.address,this.sign=l.sign}getAddress(){return id(this,null,function*(){return this.address})}signMessage(l){return id(this,null,function*(){let A=BN(l),G=yield this.sign("evm",A),b=G.slice(0,32),t=G.slice(32,64),c=G[64]+27;return"0x"+eN(b)+eN(t)+c.toString(16).padStart(2,"0")})}signMessageRaw(l){return id(this,null,function*(){let A=BN(l);return this.sign("evm",A)})}};function BN(l){let A=typeof l=="string"?new TextEncoder().encode(l):l,G=new TextEncoder().encode(`Ethereum Signed Message:
306
- ${A.length}`);return bo(VG(G,A))}function eN(l){let A="";for(let G of l)A+=G.toString(16).padStart(2,"0");return A}var dN=class{constructor(l){this.chain="cere",this.nextId=1,this.address=l.address,this.sign=l.sign}signRaw(l){return id(this,null,function*(){if(l.type!=="ed25519")throw new Error(`PolkadotSigner: unsupported sig type "${l.type}" (only ed25519)`);let A=typeof l.data=="string"?Ax(l.data):l.data,G=yield this.sign("cere",A);return{id:this.nextId++,signature:"0x"+Gx(G)}})}signMessage(l){return id(this,null,function*(){return this.sign("cere",l)})}};function Ax(l){let A=l.startsWith("0x")?l.slice(2):l;if(A.length%2!==0)throw new Error(`PolkadotSigner: odd-length hex "${l}"`);let G=new Uint8Array(A.length/2);for(let b=0;b<G.length;b++)G[b]=parseInt(A.slice(b*2,b*2+2),16);return G}function Gx(l){let A="";for(let G of l)A+=G.toString(16).padStart(2,"0");return A}var nN=class{constructor(l){this.chain="solana",this.address=l.address,this.sign=l.sign}get publicKey(){return this.address}signMessage(l){return id(this,null,function*(){let A=typeof l=="string"?new TextEncoder().encode(l):l;return this.sign("solana",A)})}};var bx=Object.defineProperty,aN=Object.getOwnPropertySymbols,tx=Object.prototype.hasOwnProperty,cx=Object.prototype.propertyIsEnumerable,gN=(l,A,G)=>A in l?bx(l,A,{enumerable:!0,configurable:!0,writable:!0,value:G}):l[A]=G,TB=(l,A)=>{for(var G in A||(A={}))tx.call(A,G)&&gN(l,G,A[G]);if(aN)for(var G of aN(A))cx.call(A,G)&&gN(l,G,A[G]);return l},JG=(l,A,G)=>new Promise((b,t)=>{var c=d=>{try{e(G.next(d))}catch(Z){t(Z)}},B=d=>{try{e(G.throw(d))}catch(Z){t(Z)}},e=d=>d.done?b(d.value):Promise.resolve(d.value).then(c,B);e((G=G.apply(l,A)).next())}),Bx=6e4;function ex(l){let A=null,G=null,b=!1,t=()=>(G||(G=l().then(c=>(A={token:c.token,expMs:new Date(c.expiresAt).getTime()},c.token)).finally(()=>{G=null})),G);return{getToken(){return JG(this,null,function*(){if(b)throw new Error("delegation-closed");return A&&Date.now()<A.expMs-Bx?A.token:t()})},refresh(){return JG(this,null,function*(){if(b)throw new Error("delegation-closed");return A=null,t()})},close(){b=!0,A=null}}}var WN="publickey-credentials-get";function oN(l){let A=l;for(let G of[A?.featurePolicy,A?.permissionsPolicy]){let b=G;if(typeof b?.allowsFeature=="function")return b}return null}function Zx(l,A){try{return new URL(l).origin===new URL(A).origin}catch{return!1}}function dx(l,A){var G;if(!A)return null;let b=l?.querySelectorAll;if(typeof b!="function")return null;let t;try{t=b.call(l,"iframe")}catch{return null}for(let c=0;c<t.length;c+=1){let B=t[c],e=B?.src||((G=B?.getAttribute)==null?void 0:G.call(B,"src"))||"";if(e&&Zx(e,A))return B}return null}function nx(l,A){let G=oN(l);if(!G)return null;let b=oN(dx(l,A));if(b)try{return b.allowsFeature(WN,A)===!0}catch{return null}try{return G.allowsFeature(WN)===!1?!1:null}catch{return null}}function ax(l){if(typeof l!="object"||l===null)return!1;let{code:A,message:G}=l;return typeof A=="string"&&A.length>0&&typeof G=="string"}function hN(l,A){if(!l||!A)return!1;try{let G=new URL(l),b=new URL(A);return G.origin===b.origin}catch{return!1}}function sN(l,A){return!l||!A?!0:l===A}var gx="width=420,height=640,resizable=yes,scrollbars=yes",Wx=400,MB=class{constructor(l){this.popup=null,this.pending=new Map,this.listener=null,this.popupReady=!1,this.outbox=[],this.closeWatch=null,this.opts=TB({openPopup:ox,hostWindow:globalThis.window,defaultTimeoutMs:6e4,handshakeTimeoutMs:1e4,onDiag:()=>{}},l)}request(l,A){return JG(this,arguments,function*(G,b,t={}){var c,B,e;if(!this.popup||this.popup.closed){this.rejectClosedPending();let n=(B=(c=globalThis.location)==null?void 0:c.origin)!=null?B:"",h=`${this.opts.walletOrigin}/embed/wallet?origin=${encodeURIComponent(n)}`;if(this.popup=this.opts.openPopup(h,gx),!this.popup)throw new iG("popup-blocked","popup window failed to open");this.popupReady=!1,this.outbox=[],this.ensureListening()}let d=this.popup,Z=G.id,g=(e=t.timeoutMs)!=null?e:this.opts.defaultTimeoutMs;return new Promise((n,h)=>{let W=setTimeout(()=>{this.pending.has(Z)&&(this.pending.delete(Z),this.outbox=this.outbox.filter(m=>m.id!==Z),h(new iG("internal",`request "${G.type}" (id=${Z}) timed out after ${g}ms`)))},g);this.pending.set(Z,{expectedTypes:b,resolve:m=>n(m),reject:h,timer:W,popup:d}),this.popupReady?this.popup.postMessage(G,this.opts.walletOrigin):(this.outbox.push(G),this.armHandshakeTimeout(Z,G,W)),this.watchForClose()})})}watchForClose(){this.closeWatch||(this.closeWatch=setInterval(()=>{this.rejectClosedPending(),this.pending.size===0&&this.clearCloseWatch()},Wx))}rejectClosedPending(){for(let[l,A]of[...this.pending])A.popup.closed&&(clearTimeout(A.timer),this.pending.delete(l),this.outbox=this.outbox.filter(G=>G.id!==l),A.reject(new iG("popup-closed","the wallet popup was closed before it answered; nothing was created or signed")))}clearCloseWatch(){this.closeWatch&&(clearInterval(this.closeWatch),this.closeWatch=null)}armHandshakeTimeout(l,A,G){let b=this.opts.handshakeTimeoutMs;b>0&&setTimeout(()=>{if(this.popupReady)return;let t=this.pending.get(l);t&&(this.pending.delete(l),this.outbox=this.outbox.filter(c=>c.id!==l),clearTimeout(G),this.opts.onDiag("surface-not-ready",Date.now(),{transport:"popup",request:A.type}),t.reject(new iG("internal",`wallet popup at ${this.opts.walletOrigin} never signalled ready within ${b}ms, so "${A.type}" (id=${l}) was never delivered. The popup may have been blocked, navigated away, or opened by a previous page that has since reloaded (its opener link no longer reaches this document).`)))},b)}close(){this.clearCloseWatch(),this.rejectAllPending("transport closed"),this.popup&&!this.popup.closed&&this.popup.close(),this.popup=null,this.popupReady=!1,this.outbox=[]}destroy(){this.close(),this.listener&&(this.opts.hostWindow.removeEventListener("message",this.listener),this.listener=null)}rejectAllPending(l){for(let[A,G]of this.pending)clearTimeout(G.timer),this.pending.delete(A),G.reject(new iG("internal",l))}ensureListening(){this.listener||(this.listener=l=>this.onMessage(l),this.opts.hostWindow.addEventListener("message",this.listener))}onMessage(l){var A,G;if(!hN(l.origin,this.opts.walletOrigin)){let c=l.data;if(c&&typeof c.id=="string"&&this.pending.has(c.id)){let B=this.pending.get(c.id);this.pending.delete(c.id),clearTimeout(B.timer),B.reject(new iG("origin-mismatch",`message from "${l.origin}" rejected (expected "${this.opts.walletOrigin}")`))}return}let b=l.data;if(!b||typeof b.type!="string"||typeof b.id!="string"||!sN(l.source,this.popup))return;if(b.type==="wallet:ready"){if(this.popupReady)return;this.popupReady=!0;let c=this.outbox;if(this.outbox=[],this.popup&&!this.popup.closed)for(let B of c)this.popup.postMessage(B,this.opts.walletOrigin);return}if(b.type==="wallet:diag"){(G=(A=this.opts).onDiag)==null||G.call(A,b.name,b.at,b.detail);return}let t=this.pending.get(b.id);if(t){if(clearTimeout(t.timer),this.pending.delete(b.id),this.pending.size===0&&this.clearCloseWatch(),b.type==="wallet:error"){t.reject(new iG(b.code,b.message,b.traceId));return}if(!t.expectedTypes.includes(b.type)){t.reject(new iG("internal",`received unexpected response type "${b.type}" for id "${b.id}"`));return}t.resolve(b)}}};function ox(l,A){let G=globalThis.window;return G?.open(l,"_blank",A)}var hx=class{constructor(l){this.iframe=null,this.pending=new Map,this.listener=null,this.ready=!1,this.outbox=[],this.backdrop=null,this.hiddenCssText="",this.overlayVisible=!1,this.opts=TB({hostWindow:globalThis.window,document:globalThis.document,defaultTimeoutMs:6e4,handshakeTimeoutMs:1e4,mountIframe:l.mountIframe,onOverlay:l.onOverlay,onDiag:l.onDiag},l)}ensureIframe(){var l,A,G;if(this.iframe)return;let b=(A=(l=globalThis.location)==null?void 0:l.origin)!=null?A:"",t=`${this.opts.walletOrigin}/embed/wallet?origin=${encodeURIComponent(b)}`,c=`publickey-credentials-get ${this.opts.walletOrigin}`;if(this.opts.mountIframe)this.iframe=this.opts.mountIframe(t,c);else{let B=this.opts.document.createElement("iframe");B.src=t,B.setAttribute("allow",c),B.style.cssText="position:fixed;border:0;width:0;height:0;left:-9999px;",this.opts.document.body.appendChild(B),this.iframe=B}this.hiddenCssText=(G=this.iframe.style.cssText)!=null?G:"",this.ready=!1,this.outbox=[],this.overlayVisible=!1,this.ensureListening()}showOverlay(){var l,A;if(!this.overlayVisible){if(this.overlayVisible=!0,this.iframe){let G=this.opts.document.createElement("div");G.setAttribute("data-wallet-overlay-backdrop",""),G.style.cssText="position:fixed;inset:0;background:rgba(0,0,0,.4);z-index:2147483646;",this.opts.document.body.appendChild(G),this.backdrop=G,this.iframe.style.cssText="position:fixed;border:0;z-index:2147483647;width:min(420px,100vw);height:min(640px,100vh);left:50%;top:50%;transform:translate(-50%,-50%);"}(A=(l=this.opts).onOverlay)==null||A.call(l,!0)}}hideOverlay(){var l,A,G;this.overlayVisible&&(this.overlayVisible=!1,(l=this.backdrop)==null||l.remove(),this.backdrop=null,this.iframe&&(this.iframe.style.cssText=this.hiddenCssText),(G=(A=this.opts).onOverlay)==null||G.call(A,!1))}ensureListening(){this.listener||(this.listener=l=>this.onMessage(l),this.opts.hostWindow.addEventListener("message",this.listener))}request(l,A){return JG(this,arguments,function*(G,b,t={}){var c;this.ensureIframe();let B=G.id,e=(c=t.timeoutMs)!=null?c:this.opts.defaultTimeoutMs;return new Promise((d,Z)=>{let g=setTimeout(()=>{this.pending.has(B)&&(this.pending.delete(B),this.outbox=this.outbox.filter(n=>n.id!==B),Z(new iG("internal",`request "${G.type}" (id=${B}) timed out after ${e}ms`)))},e);this.pending.set(B,{expectedTypes:b,resolve:n=>d(n),reject:Z,timer:g}),this.ready?this.postToIframe(G):(this.outbox.push(G),this.armHandshakeTimeout(B,G,g))})})}armHandshakeTimeout(l,A,G){let b=this.opts.handshakeTimeoutMs;b>0&&setTimeout(()=>{var t,c;if(this.ready)return;let B=this.pending.get(l);B&&(this.pending.delete(l),this.outbox=this.outbox.filter(e=>e.id!==l),clearTimeout(G),(c=(t=this.opts).onDiag)==null||c.call(t,"surface-not-ready",Date.now(),{transport:"iframe",request:A.type}),B.reject(new iG("internal",`wallet iframe at ${this.opts.walletOrigin} never signalled ready within ${b}ms, so "${A.type}" (id=${l}) was never delivered. Check that the wallet origin is reachable and that the host page's Permissions-Policy / CSP does not block the embedded document.`)))},b)}postToIframe(l){var A,G;(G=(A=this.iframe)==null?void 0:A.contentWindow)==null||G.postMessage(l,this.opts.walletOrigin)}close(){var l,A;this.rejectAllPending("transport closed"),(l=this.backdrop)==null||l.remove(),this.backdrop=null,this.overlayVisible=!1,(A=this.iframe)==null||A.remove(),this.iframe=null,this.ready=!1,this.outbox=[]}destroy(){this.close(),this.listener&&(this.opts.hostWindow.removeEventListener("message",this.listener),this.listener=null)}rejectAllPending(l){for(let[A,G]of this.pending)clearTimeout(G.timer),this.pending.delete(A),G.reject(new iG("internal",l))}onMessage(l){var A,G,b;let t=l.data;if(!hN(l.origin,this.opts.walletOrigin)){if(t&&typeof t.id=="string"&&this.pending.has(t.id)){let B=this.pending.get(t.id);this.pending.delete(t.id),clearTimeout(B.timer),B.reject(new iG("origin-mismatch",`message from "${l.origin}" rejected (expected "${this.opts.walletOrigin}")`))}return}if(!t||typeof t.type!="string"||typeof t.id!="string"||!sN(l.source,(A=this.iframe)==null?void 0:A.contentWindow))return;if(t.type==="wallet:ready"){if(this.ready)return;this.ready=!0;let B=this.outbox;this.outbox=[];for(let e of B)this.postToIframe(e);return}if(t.type==="wallet:ui:show"){this.showOverlay();return}if(t.type==="wallet:ui:hide"){this.hideOverlay();return}if(t.type==="wallet:diag"){(b=(G=this.opts).onDiag)==null||b.call(G,t.name,t.at,t.detail);return}let c=this.pending.get(t.id);if(c){if(clearTimeout(c.timer),this.pending.delete(t.id),t.type==="wallet:error"){c.reject(new iG(t.code,t.message,t.traceId));return}if(!c.expectedTypes.includes(t.type)){c.reject(new iG("internal",`received unexpected response type "${t.type}" for id "${t.id}"`));return}c.resolve(t)}}},sx=15*6e4;function rx(l,A){let G=new Set([...Object.keys(l),...Object.keys(A)]);for(let b of G)if(l[b]!==A[b])return!1;return!0}var rN=class{constructor(l){this._addresses=null,this._credentialId=null,this._accountId=null,this._email=null,this._displayName=null,this._hasKeys=!1,this.policyRefused=!1,this._listeners={},this.registerInFlight=null,this.loginInFlight=null,this.relayDiag=(Z,g,n)=>{this.emit("diag",TB({type:"diag",name:Z,at:g},n?{detail:n}:{}))};var A,G,b,t,c,B,e;let d=(A=l.__internal__)==null?void 0:A.transport;if(!d&&!l.walletOrigin)throw new Error("EmbedWallet: `walletOrigin` is required (e.g. https://wallet.example.com).");this.appId=l.appId,this.walletOrigin=(G=l.walletOrigin)!=null?G:"",this.popup={width:(t=(b=l.popup)==null?void 0:b.width)!=null?t:420,height:(B=(c=l.popup)==null?void 0:c.height)!=null?B:640},this.appName=(e=l.appName)!=null?e:"",this.popupOpener=l.popupOpener,this.transport=d??(l.transport==="popup"?new MB({walletOrigin:this.walletOrigin,onDiag:this.relayDiag}):new hx({walletOrigin:this.walletOrigin,onDiag:this.relayDiag}))}get isLoggedIn(){return this._addresses!==null}get addresses(){return this._addresses}get credentialId(){return this._credentialId}get accountId(){return this._accountId}get email(){return this._email}get displayName(){return this._displayName}get hasKeys(){return this._hasKeys}get ceremonySurface(){return this.transport instanceof MB||this.policyRefused||nx(globalThis.document,this.walletOrigin)===!1?"popup":"iframe"}register(){return JG(this,arguments,function*(l={}){return this.registerInFlight||(this.registerInFlight=this.registerImpl(l).finally(()=>{this.registerInFlight=null})),this.registerInFlight})}registerImpl(l){return JG(this,null,function*(){if(this.transport instanceof MB)return this.helloAndAwaitLogin("register",l);let A=new MB(TB({walletOrigin:this.walletOrigin,onDiag:this.relayDiag},this.popupOpener?{openPopup:this.popupOpener}:{}));this.diagPopup("popup-open","register");let G;try{G=yield this.helloAndAwaitLogin("register",l,A)}finally{A.close(),this.diagPopup("popup-close","register")}try{let b=yield this.helloAndAwaitLogin("login",{credentialId:G.credentialId},this.transport,G.credentialId,!1);if(!rx(b.addresses,G.addresses))throw this.clearSessionState(),this.emit("logout",{type:"logout"}),new iG("derivation-mismatch","in-frame re-derivation after registration produced different addresses than the registration ceremony");this._hasKeys=!0,this.diag("session-state",{state:"keyed",hasKeys:!0})}catch(b){if(b instanceof iG&&b.code==="derivation-mismatch")throw b;this._hasKeys=!1,this.diag("session-state",{state:"bearer-active",hasKeys:!1})}return G})}resume(){return JG(this,null,function*(){var l,A,G;let b=yield this.checkSessionStatus();return b?.authenticated&&b.addresses&&b.credentialId?(this._addresses=b.addresses,this._credentialId=b.credentialId,this._hasKeys=b.hasKeys,this._accountId=(l=b.accountId)!=null?l:null,this._email=b.accountId&&(A=b.email)!=null?A:null,this._displayName=b.accountId&&(G=b.displayName)!=null?G:null,this.diag("adopt-session",{hasKeys:b.hasKeys}),this.diag("session-state",{state:b.hasKeys?"keyed":"bearer-active",hasKeys:b.hasKeys}),this.emit("login",{type:"login",addresses:b.addresses}),{addresses:b.addresses,credentialId:b.credentialId,accountCreated:!1}):null})}login(){return JG(this,null,function*(){return this.loginInFlight||(this.loginInFlight=this.loginImpl().finally(()=>{this.loginInFlight=null})),this.loginInFlight})}loginImpl(){return JG(this,null,function*(){let l=yield this.resume();if(l)return l;try{let A=yield this.helloAndAwaitLogin("login");return this._hasKeys=!0,this.diag("session-state",{state:"keyed",hasKeys:!0}),A}catch(A){return this.assertPopupFallbackAllowed(A),this.loginViaPopup()}})}loginViaPopup(){return JG(this,null,function*(){let l=new MB(TB({walletOrigin:this.walletOrigin,onDiag:this.relayDiag},this.popupOpener?{openPopup:this.popupOpener}:{}));this.diagPopup("popup-open","login");try{let A=yield this.helloAndAwaitLogin("login",{},l);return this._hasKeys=!1,this.diag("session-state",{state:"bearer-active",hasKeys:!1}),A}finally{l.close(),this.diagPopup("popup-close","login")}})}assertPopupFallbackAllowed(l){if(!ax(l)||l.code!=="ceremony-policy-denied"||this.transport instanceof MB)throw l;this.policyRefused=!0,this.diag("iframe-ceremony-unavailable",{fallback:"popup"});let A=globalThis.navigator;if(A?.userActivation&&A.userActivation.isActive===!1)throw new iG("gesture-required","a popup ceremony needs a user gesture; retry from a click")}logout(){return JG(this,null,function*(){let l=crypto.randomUUID();try{yield this.transport.request({type:"wallet:logout",id:l},["wallet:result"])}catch{}this.clearSessionState(),this.transport.close(),this.diag("session-state",{state:"logged-out",hasKeys:!1}),this.emit("logout",{type:"logout"})})}clearSessionState(){this._addresses=null,this._credentialId=null,this._hasKeys=!1,this._accountId=null,this._email=null,this._displayName=null}getSigner(l){this.assertLoggedIn("getSigner");let A=(b,t)=>JG(this,null,function*(){return this.signWithStepUp({chain:b,payload:t,requestKind:"sdk"})}),G=this._addresses;switch(l.chain){case"evm":return this.withLiveAddress(new ZN({address:G.evm,sign:A}),()=>this.requireAddresses("getSigner").evm);case"cere":return this.withLiveAddress(new dN({address:G.cere,sign:A}),()=>this.requireAddresses("getSigner").cere);case"solana":return this.withLiveAddress(new nN({address:G.solana,sign:A}),()=>this.requireAddresses("getSigner").solana);default:throw new iG("validation",`getSigner: unknown chain "${String(l.chain)}"`)}}asSigner(){this.assertLoggedIn("asSigner");let l=(G,b,t)=>JG(this,null,function*(){if(!this.isLoggedIn)throw new iG("unauthorized","asSigner: wallet is no longer logged in");return this.signWithStepUp({chain:"cere",payload:G,requestKind:b??"sdk",humanReadable:t})}),A=this;return{type:"ed25519",get address(){return A.requireAddresses("asSigner").cere},get publicKey(){return cN(A.requireAddresses("asSigner").solana)},isReady:()=>JG(this,null,function*(){return this.isLoggedIn}),sign:(G,b,t)=>l(G,b,t?.humanReadable)}}requestDelegation(l){return JG(this,null,function*(){this.assertLoggedIn("requestDelegation");let A=crypto.randomUUID(),G={capabilities:l.capabilities,appId:l.appId,agentPubkey:l.agentPubkey,constraints:l.constraints};return(yield this.transport.request({type:"wallet:requestDelegation",id:A,scope:G,ttl:l.ttl},["wallet:result"])).result})}createDelegation(l){return ex(()=>this.requestDelegation(l))}findApplications(){return JG(this,arguments,function*(l={}){this.assertLoggedIn("findApplications");let A=crypto.randomUUID();return(yield this.transport.request({type:"wallet:findApplications",id:A,appId:l.appId},["wallet:result"])).result})}saveApplication(l){return JG(this,null,function*(){this.assertLoggedIn("saveApplication");let A=crypto.randomUUID();return(yield this.transport.request({type:"wallet:saveApplication",id:A,permissions:l.permissions,email:l.email},["wallet:result"])).result})}on(l,A){var G;let b=this._listeners;return((G=b[l])!=null?G:b[l]=new Set).add(A),this}off(l,A){var G;return(G=this._listeners[l])==null||G.delete(A),this}dispose(){this._addresses=null,this._credentialId=null,this._hasKeys=!1,this._accountId=null,this._email=null,this._displayName=null,this._listeners={},this.transport.destroy()}appContext(){let l=typeof window<"u"?window.location.origin:"";return{appId:this.appId,name:this.appName,origin:l}}helloAndAwaitLogin(l){return JG(this,arguments,function*(A,G={},b=this.transport,t,c=!0){var B,e,d,Z,g,n;let W={type:"wallet:hello",id:crypto.randomUUID(),appContext:this.appContext(),intent:A,label:G.label,credentialId:G.credentialId},m=yield b.request(W,["wallet:login:ok"],A==="register"?{timeoutMs:sx}:{});if(t!==void 0&&m.credentialId!==t)throw new iG("unauthorized","helloAndAwaitLogin: step-up ceremony returned a different credential than the active session; refusing to sign");this._addresses=m.addresses,this._credentialId=m.credentialId,this._hasKeys=!0,this._accountId=(e=(B=m.account)==null?void 0:B.accountId)!=null?e:null,this._email=(Z=(d=m.account)==null?void 0:d.email)!=null?Z:null,this._displayName=(n=(g=m.account)==null?void 0:g.displayName)!=null?n:null,c&&this.emit("login",{type:"login",addresses:m.addresses});let Y=A==="register"?m.accountCreated:!1;return TB({addresses:m.addresses,credentialId:m.credentialId},Y===void 0?{}:{accountCreated:Y})})}signWithStepUp(l){return JG(this,null,function*(){if(this._hasKeys)try{return yield this.sendSign(this.transport,l)}catch(G){throw G instanceof iG&&G.code==="needs-step-up"&&(this._hasKeys=!1),G}let A=this._credentialId;if(this.transport instanceof MB)return yield this.helloAndAwaitLogin("login",{credentialId:A??void 0},this.transport,A??void 0),this.sendSign(this.transport,l);try{yield this.helloAndAwaitLogin("login",{credentialId:A??void 0},this.transport,A??void 0)}catch(G){return this.assertPopupFallbackAllowed(G),this.stepUpViaPopup(l,A)}return this._hasKeys=!0,this.diag("session-state",{state:"keyed",hasKeys:!0}),this.sendSign(this.transport,l)})}stepUpViaPopup(l,A){return JG(this,null,function*(){let G=new MB(TB({walletOrigin:this.walletOrigin,onDiag:this.relayDiag},this.popupOpener?{openPopup:this.popupOpener}:{}));this.diagPopup("popup-open","step-up");try{yield this.helloAndAwaitLogin("login",{credentialId:A??void 0},G,A??void 0);let b=yield this.sendSign(G,l);return this._hasKeys=!1,this.diag("session-state",{state:"bearer-active",hasKeys:!1}),b}finally{G.close(),this.diagPopup("popup-close","step-up")}})}sendSign(l,A){return JG(this,null,function*(){let G=crypto.randomUUID(),t=(yield l.request({type:"wallet:sign",id:G,chain:A.chain,payload:A.payload,requestKind:A.requestKind,humanReadable:A.humanReadable},["wallet:result"])).result;if(!(t instanceof Uint8Array))throw new iG("internal",`popup returned non-Uint8Array sign result (got ${typeof t})`);return t})}checkSessionStatus(){return JG(this,null,function*(){let l=crypto.randomUUID();try{return(yield this.transport.request({type:"wallet:session:status",id:l},["wallet:result"])).result}catch{return null}})}emit(l,A){let G=this._listeners[l];if(G)for(let b of G)try{b(A)}catch{}}diagPopup(l,A){this.diag(l,{intent:A})}diag(l,A){this.emit("diag",TB({type:"diag",name:l,at:Date.now()},A?{detail:A}:{}))}assertLoggedIn(l){if(!this._addresses)throw new iG("unauthorized",`${l}: not logged in`)}requireAddresses(l){if(!this._addresses)throw new iG("unauthorized",`${l}: not logged in`);return this._addresses}withLiveAddress(l,A){return Object.defineProperty(l,"address",{get:A,enumerable:!0,configurable:!0}),l}};var ix=["ddc-read","ddc-write"],iN="cef-widget",mx="1h",Vx=60*60*1e3,ux=10*60*1e3,$m=class extends Error{constructor(){super("PopupBlockedError: the browser did not open the wallet window"),this.name="PopupBlockedError"}},Yx=(l,A)=>{let G=window.open(l,"_blank",A);if(!G)throw new $m;return G},l2=class extends Error{constructor(){super("WidgetWalletUnconfiguredError: this widget was published without a `wallet.origin`, so there is no wallet to sign in to. Rebuild and republish it with a CLI new enough to stamp one (`cef push --kind widget`)."),this.name="WidgetWalletUnconfiguredError"}};function Ix(l){let A=l.publicKey,G="0x";for(let b of A)G+=b.toString(16).padStart(2,"0");return G}function mN(l){if(!l.walletOrigin)throw new l2;let A=new rN({appId:iN,appName:l.appName??"CEF widget",walletOrigin:l.walletOrigin,...l.transport?{transport:l.transport}:{},...l.transport==="popup"?{popupOpener:Yx}:{}}),G=null,b=()=>{let c=G;if(c&&Date.now()-c.mintedAt<Vx-ux)return c.token;let B=A.requestDelegation({capabilities:[...ix],appId:iN,ttl:mx}).then(e=>e.token).catch(e=>{throw G=null,e});return G={token:B,mintedAt:Date.now()},B},t=()=>{let c=A.asSigner(),B=Ix(c);return{pubkey:()=>B,sigType:"ed25519",signRawBytes:e=>c.sign(e),delegation:b}};return{async resume(){return await A.resume()?(G=null,t()):null},async signIn(){return await A.login(),G=null,t()},async register(){return await A.register(),G=null,t()},ceremonySurface(){return A.ceremonySurface}}}var VN="cef-widget-signin",Rx={title:"Sign in to view this",body:"This page reads data you need permission for. Sign in with your CEF account \u2014 the same one you use for the console.",signIn:"Sign in",register:"Create an account"};function DB(l,A,G){let b=document.createElement(l);return b.setAttribute("style",A),G!==void 0&&(b.textContent=G),b}var Xx=["position:fixed","inset:0","z-index:2147483000","display:flex","align-items:center","justify-content:center","padding:24px","background:rgba(15,18,25,.55)",'font:14px/1.5 system-ui,-apple-system,"Segoe UI",sans-serif'].join(";"),px=["max-width:420px","width:100%","box-sizing:border-box","background:#fff","color:#11151c","border-radius:14px","padding:28px","box-shadow:0 18px 48px rgba(15,18,25,.28)"].join(";"),Fx=["appearance:none","border:0","border-radius:9px","padding:11px 18px","font:inherit","font-weight:600","cursor:pointer","background:#6b3df5","color:#fff"].join(";"),yx=["appearance:none","border:1px solid #d7dae2","border-radius:9px","padding:11px 18px","font:inherit","font-weight:600","cursor:pointer","background:#fff","color:#11151c"].join(";");function Qx(l,A={},G){let b={...Rx,...A};return new Promise(t=>{let c=document.getElementById(VN);c&&c.remove();let B=DB("div",Xx);B.id=VN;let e=DB("div",px);e.appendChild(DB("h2","margin:0 0 8px;font-size:18px;font-weight:700",b.title)),e.appendChild(DB("p","margin:0 0 20px;color:#4a5160",b.body));let d=DB("div","display:flex;gap:10px;flex-wrap:wrap"),Z=DB("button",Fx,b.signIn),g=DB("button",yx,b.register);Z.type="button",g.type="button",d.appendChild(Z),d.appendChild(g),e.appendChild(d);let n=DB("p","margin:16px 0 0;color:#b00020;display:none");e.appendChild(n),B.appendChild(e),document.body.appendChild(B);let h=!1,W=l,m=!1,Y=R=>()=>{h||(h=!0,n.style.display="none",Z.disabled=!0,g.disabled=!0,B.style.display="none",R(W).catch(u=>{if(!G||m)throw u;return m=!0,W=G(),console.info("[widget-runtime] framed ceremony refused; retrying in a popup",u),R(W)}).then(u=>{B.remove(),t(u)}).catch(u=>{h=!1,B.style.display="flex",Z.disabled=!1,g.disabled=!1,n.textContent=u instanceof Error?u.message:String(u),n.style.display="block"}))};Z.addEventListener("click",Y(R=>R.signIn())),g.addEventListener("click",Y(R=>R.register()))})}async function uN(l,A,G={}){let b=!0;try{let c=await l.resume();if(c)return c}catch(c){b=!1,console.info("[widget-runtime] wallet surface did not come up; skipping the framed ceremony",c)}if(b)try{return await l.signIn()}catch(c){console.info("[widget-runtime] framed ceremony refused; trying a popup",c)}let t=A();try{return await t.signIn()}catch(c){console.info("[widget-runtime] popup did not open on its own; asking for a click",c)}return Qx(t,G)}var A2={vaultId:["vaultId","vault"],runId:["runId","run"],recordId:["recordId","record"]};function YN(l,A){for(let G of A){let b=l.get(G);if(b&&b.trim())return b.trim()}}function Nx(l){let A=l.hash??"",G=A.indexOf("?"),b=G>=0?A.slice(G+1):A.replace(/^#/,""),t=new URLSearchParams(b),c=new URLSearchParams((l.search??"").replace(/^\?/,"")),B=n=>YN(t,n)??YN(c,n),e={},d=B(A2.vaultId),Z=B(A2.runId),g=B(A2.recordId);return d&&(e.vaultId=d),Z&&(e.runId=Z),g&&(e.recordId=g),Object.keys(e).length>0?e:void 0}function IN(){if(!(typeof window>"u"||!window.location))return Nx(window.location)}var G2=class extends Error{constructor(A="WidgetSignedOutError: the embedding host did not supply an identity (no cef-widget:identity-response within 8s, or a malformed one). Mount createWidgetHost() on the host page."){super(A),this.name="WidgetSignedOutError"}};function RN(l){let A=null;return function(){return A||(A=(async()=>{let b=await l.bridge.requestIdentity();if(b)return{source:"host",publicKey:b.pubkey,sigType:b.sigType,sign:d=>l.bridge.sign(d),...b.token?{token:b.token}:{},...b.context?{context:b.context}:{}};if(window.parent!==window)throw new G2;let t=await l.connectWallet(),c,B=t.delegation?.bind(t);if(B)try{c=await B()}catch(d){console.warn("[widget-runtime] no delegation minted; falling back to signing",d)}let e=l.linkContext?.();return{source:"wallet",publicKey:t.pubkey(),sigType:t.sigType,sign:d=>t.signRawBytes(d),...c&&B?{token:c,renewToken:B}:{},...e?{context:e}:{}}})().catch(b=>{throw A=null,b}),A)}}var uo=class extends Error{constructor(A,G){let b=G===void 0?"this build of the runtime has no vault.byId to open it with":G instanceof Error?G.message:String(G);super(`WidgetVaultUnreachableError: the host opened this widget on vault ${A}, and it cannot be read from here (${b}). Falling back to your own vault would answer from a different database \u2014 which looks exactly like a run that produced nothing.`),this.name="WidgetVaultUnreachableError",this.vaultId=A,this.reason=b}};async function b2(l,A,G){if(!A)return l.ensure({onboard:!1,...G?{delegationToken:G}:{}});if(typeof l.byId!="function")throw new uo(A);try{return await l.byId(A)}catch(b){throw new uo(A,b)}}function XN(l){if(l&&typeof l=="object"&&"columns"in l&&"rows"in l){let A=l.columns,G=l.rows;if(Array.isArray(A)&&Array.isArray(G))return{columns:A.map(String),rows:G,meta:{rowCount:G.length}}}if(Array.isArray(l)){let A=l.length>0?Object.keys(l[0]):[],G=l.map(b=>A.map(t=>b[t]));return{columns:A,rows:G,meta:{rowCount:l.length}}}return console.warn("[widget-runtime] unrecognized cubby query result shape; treating as empty",l),{columns:[],rows:[],meta:{rowCount:0}}}function pN(l,A,G,b){let t,c,B=()=>t??(t=A()),e=async()=>b2(B().vault,b,G),d=()=>(c??(c=e().catch(W=>{throw c=void 0,W})),c),Z=W=>l.queries.find(m=>m.id===W),g=()=>{let W=l.agentId.indexOf(":");return W>0?l.agentId.slice(0,W):""},n=async(W,m)=>{let Y=await d();if(!Y.service)throw new Error(`[widget-runtime] this host's vault-sdk has no agent-service cubby surface, so the query "${W.id}" cannot be answered here`);let R=g();if(!R)throw new Error(`[widget-runtime] "${W.id}" reads the agent service's cubby, but "${l.agentId}" carries no service key to read it from`);let u=W.cubby??l.cubbyAlias;if(!u)throw new Error(`[widget-runtime] "${W.id}" reads the agent service's cubby but names none, and this widget has no cubbyAlias to fall back on \u2014 set \`cubby\` on the query`);return Y.service(R).cubby(u).query(W.sql??"",m)},h=async(W,m)=>{let Y=await d();if(!Y.memory)throw new Error(`[widget-runtime] this host's vault-sdk has no memory surface, so the query "${W.id}" cannot be answered here`);let R=m[0],u=W.limit;switch(W.tool??"search"){case"search":return Y.memory.search(String(R??""),u?{limit:u}:void 0);case"get":return Y.memory.get(String(R??""));case"neighbours":return Y.memory.neighbours(String(R??""),u?{limit:u}:void 0);case"countByType":return Y.memory.countByType();default:throw new Error(`[widget-runtime] "${W.id}" names no memory tool this runtime knows`)}};return{async query(W,m){let Y=Z(W);return Y?.tool?XN(await h(Y,m??[])):XN(await n(Y??{id:W,label:W,sql:W},m??[]))},async publish(W,m,Y){return(await d()).scope(l.scope).publish({type:W,context:Y??"",payload:m})},async connectAgent(){await(await d()).agents.connect({agentId:l.agentId,scope:l.scope})},async agentStatus(){try{return(await(await d()).agents.get(l.agentId)).status==="active"?"connected":"disconnected"}catch{return"disconnected"}}}}function t2(l,A,G,b){let t={endpoint:l.vault,garEndpoint:l.gar,marketplaceEndpoint:l.marketplace,s3GatewayAuthInfoUrl:l.s3GatewayAuthInfo,chainUrl:l.rpc};return b?{...t,auth:Ex(b)}:G?{...t,auth:new hd(G)}:{...t,signer:A}}function Ex(l){return{authenticate:async A=>new hd(await l()).authenticate(A)}}function FN(l,A){let G="anon",b="",t,c,B=new Set,e=Z=>{G=Z;let g={publicKey:b,status:G,...t?{context:t}:{}};for(let n of B)n(g)};function d(){return c??(c=(async()=>{e("connecting");let Z=await A.resolveIdentity(l);b=Z.publicKey,t=Z.context;let g=A.buildVaultClient(l,Z);return e("ready"),g})().catch(Z=>{throw c=void 0,e("anon"),Z})),c}return{async query(Z,g){return(await d()).query(Z,g)},async publish(Z,g,n){return(await d()).publish(Z,g,n)},async identity(){return await d(),{publicKey:b,status:G,...t?{context:t}:{}}},async connect(){return await d(),{publicKey:b,status:G,...t?{context:t}:{}}},async connectAgent(){await(await d()).connectAgent()},async agentStatus(){return(await d()).agentStatus()},onIdentityChange(Z){return B.add(Z),()=>B.delete(Z)}}}var cgl=new TextEncoder;function yN(l,A){let G=new ArrayBuffer(44+l.length*2),b=new DataView(G),t=(B,e)=>{for(let d=0;d<e.length;d++)b.setUint8(B+d,e.charCodeAt(d))};t(0,"RIFF"),b.setUint32(4,36+l.length*2,!0),t(8,"WAVE"),t(12,"fmt "),b.setUint32(16,16,!0),b.setUint16(20,1,!0),b.setUint16(22,1,!0),b.setUint32(24,A,!0),b.setUint32(28,A*2,!0),b.setUint16(32,2,!0),b.setUint16(34,16,!0),t(36,"data"),b.setUint32(40,l.length*2,!0);let c=44;for(let B=0;B<l.length;B++,c+=2){let e=Math.max(-1,Math.min(1,l[B]));b.setInt16(c,e<0?e*32768:e*32767,!0)}return G}function QN(l,A,G){let b=A*G,t=[];for(let c=0;c<l.length;c+=b)t.push(l.subarray(c,Math.min(c+b,l.length)));return t.length?t:[l]}async function NN(l){let A=await l.arrayBuffer(),G=window.OfflineAudioContext||window.webkitOfflineAudioContext,b=new(window.AudioContext||window.webkitAudioContext),t=await b.decodeAudioData(A.slice(0));b.close();let c=Math.ceil(t.duration*16e3),B=new G(1,c,16e3),e=B.createBufferSource();return e.buffer=t,e.connect(B.destination),e.start(),(await B.startRendering()).getChannelData(0).slice()}var dgl=Object.freeze({PUT:1,GET:2,DELETE:3}),ngl=Object.freeze({ED_25519:0,SR_25519:1});async function EN(l,A){let G=l.segmentSeconds??25,b=await A.decode(l.blob),t=b.length/A.sampleRate;l.softCapSeconds&&t>l.softCapSeconds&&l.onWarn?.(`Recording is ${Math.round(t/60)} min; long uploads may be slow.`);let c=QN(b,A.sampleRate,G),B=[];for(let e=0;e<c.length;e++)B.push(await A.upload(yN(c[e],A.sampleRate),e)),l.onProgress?.(e+1,c.length);return A.upload.finalizeUrls?await A.upload.finalizeUrls(B):B}function vN(l){let A=l.keyPrefix??`widget-audio/${crypto.randomUUID()}`,G=l.readTtlSeconds?{ttlSeconds:l.readTtlSeconds}:{},b=async function(c,B){let e=`${A}/${B}.wav`;return await l.objects.upload(e,new Uint8Array(c),{contentType:"audio/wav"}),(await l.objects.presignedUrl(e,G)).url};return b.finalizeUrls=async t=>Promise.all(t.map(async(c,B)=>(await l.objects.presignedUrl(`${A}/${B}.wav`,G)).url)),b}d2();function Ux(l){typeof document<"u"&&document.readyState==="loading"?document.addEventListener("DOMContentLoaded",l,{once:!0}):l()}async function Cx(l){let A=l.wallet?.origin;if(!A)return GN(l.wallet);let G=b=>mN({walletOrigin:A,appName:l.name,...b?{transport:b}:{}});return uN(G(),()=>G("popup"))}function Sx(){let l=window.WidgetSandbox?.manifest;if(!l)return;let A=KQ(),G=RN({bridge:A,connectWallet:()=>Cx(l),linkContext:IN}),b,t,c={resolveIdentity:async()=>{let e=await G();return b=e.token,t=e.renewToken,{source:e.source,publicKey:e.publicKey,sigType:e.sigType,...e.context?{context:e.context}:{}}},buildVaultClient:(e,d)=>{let Z=d.sigType??"ed25519",g=b,n=t,h=Y=>G().then(R=>R.sign(Y)),W=qm(d.publicKey,Z,h);return pN(e,()=>new _Z(t2(e.endpoints,W,g,n)),g,d.context?.vaultId)}},B;if(l.kind==="submit"||l.kind==="conversation"||l.kind==="composite"){let e=null,d=()=>e||(e=(async()=>{let g=await G(),n=qm(g.publicKey,g.sigType,g.sign),h=new _Z(t2(l.endpoints,n,g.token,g.renewToken)),W=await b2(h.vault,g.context?.vaultId,g.token);return vN({objects:W.scope(l.scope).objects})})().catch(g=>{throw e=null,g}),e);B={uploadAudio:(g,n)=>d().then(h=>EN({blob:g,segmentSeconds:n?.segmentSeconds,softCapSeconds:n?.softCapSeconds,onProgress:n?.onProgress,onWarn:n?.onWarn},{decode:NN,upload:h,sampleRate:16e3}))}}window.WidgetRuntime=FN(l,c),window.registerCompositePanel=ON,l.kind&&l.kind!=="custom"&&l.config&&Ux(()=>{let e=document.getElementById("app");if(!e){console.error(`[widget-runtime] widget "${l.widgetId}" declares kind "${l.kind}" but its entry HTML has no <div id="app"></div>, so there is nowhere to render. Add the element, or declare kind "custom" and mount it yourself.`);return}Promise.resolve().then(()=>(Z2(),MN)).then(({mountKind:d})=>d(e,l.config,window.WidgetRuntime,B))})}Sx();})();
305
+ `),tZ=Tl("<Bytes>"),cZ=Tl("</Bytes>"),jE=tZ.length+cZ.length;function BZ(l,A){return l.length>=jE&&jb(l.subarray(0,tZ.length),tZ)&&jb(l.slice(-cZ.length),cZ)||A&&l.length>=Ha.length&&jb(l.subarray(0,Ha.length),Ha)}function qo(l){let A=Tl(l);return BZ(A,!1)?A.subarray(tZ.length,A.length-cZ.length):A}function _o(l){let A=Tl(l);return BZ(A,!0)?A:Zc([tZ,A,cZ])}var pV=UA(256),ME=UA(255);function TE(l,A,G){let b=[],t=G&&l<AZ;for(t&&(l=(l+GZ)*-GZ);l!==AZ;){let c=l%pV,B=Number(t?c^ME:c);A?b.push(B):b.unshift(B),l=(l-c)/pV}return Uint8Array.from(b)}function $o(l,{bitLength:A=-1,isLe:G=!0,isNegative:b=!1}={}){let t=YV(l);if(t===AZ)return A===-1?new Uint8Array(1):new Uint8Array(Math.ceil((A||0)/8));let c=TE(t,G,b);if(A===-1)return c;let B=Math.ceil((A||0)/8),e=new Uint8Array(B);return b&&e.fill(255),e.set(c,G?0:B-c.length),e}function FV(l){if(!l||l==="0x")return"";if(Oo.test(l))return l.substring(2);if(VV.test(l))return l;throw new Error(`Expected hex value to convert, found '${l}'`)}function yV(l,{isLe:A=!1,isNegative:G=!1}={}){if(!l||l==="0x")return new pA.default(0);let b=FV(l),t=new pA.default(b,16,A?"le":"be");return G?t.fromTwos(b.length*4):t}var xd=new pA.default(1),fd=new pA.default(2);var QV=new pA.default(1e9),Ew=QV.mul(QV),vw=new pA.default(Number.MAX_SAFE_INTEGER);function kd(l){return typeof l=="bigint"}function wd(l){return l?pA.default.isBN(l)?l:Vb(l)?yV(l.toString()):kd(l)?new pA.default(l.toString()):Na(l)?l.toBn():Qa(l)?new pA.default(l.toBigInt().toString()):new pA.default(l):new pA.default(0)}var DE={bitLength:-1,isLe:!0,isNegative:!1};function kG(l,{bitLength:A=-1,isLe:G=!0,isNegative:b=!1}=DE){let t=wd(l),c=Math.ceil(A===-1?t.bitLength()/8:(A||0)/8);if(!l)return A===-1?new Uint8Array(1):new Uint8Array(c);let B=new Uint8Array(c),e=b?t.toTwos(c*8):t;return B.set(e.toArray(G?"le":"be",c),0),B}var LE=fd.pow(new pA.default(6)).isub(xd),OE=fd.pow(new pA.default(14)).isub(xd),PE=fd.pow(new pA.default(30)).isub(xd),KE={bitLength:16},qE={bitLength:32};function NV(l){let A=wd(l);if(A.lte(LE))return new Uint8Array([A.toNumber()<<2]);if(A.lte(OE))return kG(A.shln(2).iadd(xd),KE);if(A.lte(PE))return kG(A.shln(2).iadd(fd),qE);let G=kG(A),b=G.length;for(;G[b-1]===0;)b--;if(b<4)throw new Error("Invalid length, previous checks match anything less than 2^30");return Zc([new Uint8Array([(b-4<<2)+3]),G.subarray(0,b)])}function be(l){return Zc([NV(l.length),l])}function lh(l){return typeof l=="string"||l instanceof String}function Ah(l){return typeof l=="number"}function te(l,...A){let G=new Set(["__proto__","constructor","prototype"]);for(let b=0,t=A.length;b<t;b++){let c=A[b];if(c)if(typeof c.entries=="function")for(let[B,e]of c.entries())G.has(B)||(l[B]=e);else{let B=Object.create(null);for(let[e,d]of Object.entries(c))G.has(e)||(B[e]=d);Object.assign(l,B)}}return l}var _E=ec.crypto;function Ja(l){return _E.getRandomValues(l)}var xa={getRandomValues:Ja},$E={crypto:xa},pt,fa=class{constructor(A){EG(this,pt);el(this,"abort",()=>{throw new Error("abort")});el(this,"__wbindgen_is_undefined",A=>GA(this,pt).getObject(A)===void 0);el(this,"__wbindgen_throw",(A,G)=>{throw new Error(GA(this,pt).getString(A,G))});el(this,"__wbg_self_1b7a39e3a92c949c",()=>GA(this,pt).addObject($E));el(this,"__wbg_require_604837428532a733",(A,G)=>{throw new Error(`Unable to require ${GA(this,pt).getString(A,G)}`)});el(this,"__wbg_crypto_968f1772287e2df0",A=>GA(this,pt).addObject(xa));el(this,"__wbg_getRandomValues_a3d34b4fee3c2869",A=>GA(this,pt).addObject(xa.getRandomValues));el(this,"__wbg_getRandomValues_f5e14ab7ac8e995d",(A,G,b)=>{xa.getRandomValues(GA(this,pt).getU8a(G,b))});el(this,"__wbg_randomFillSync_d5bd2d655fdf256a",(A,G,b)=>{throw new Error("randomFillsync is not available")});el(this,"__wbindgen_object_drop_ref",A=>{GA(this,pt).takeObject(A)});bG(this,pt,A)}};pt=new WeakMap;var Ud,Ft,Cd,sB,rB,Hc,nt,eZ,ce,ZZ,ka=class{constructor(A){EG(this,Ud);EG(this,Ft);EG(this,Cd);EG(this,sB);EG(this,rB);EG(this,Hc);EG(this,nt);EG(this,eZ);EG(this,ce);EG(this,ZZ);bG(this,Ud,A),bG(this,sB,null),bG(this,rB,null),bG(this,Ft,new Array(32).fill(void 0).concat(void 0,null,!0,!1)),bG(this,Hc,GA(this,Ft).length),bG(this,ZZ,"none"),bG(this,nt,null),bG(this,eZ,null),bG(this,ce,null),bG(this,Cd,{...new fa(this)})}get error(){return GA(this,eZ)}get type(){return GA(this,ZZ)}get wasm(){return GA(this,nt)}async init(A){(!GA(this,ce)||A)&&bG(this,ce,(A||GA(this,Ud))(GA(this,Cd)));let{error:G,type:b,wasm:t}=await GA(this,ce);return bG(this,ZZ,b),bG(this,nt,t),bG(this,eZ,G),GA(this,nt)}getObject(A){return GA(this,Ft)[A]}dropObject(A){A<36||(GA(this,Ft)[A]=GA(this,Hc),bG(this,Hc,A))}takeObject(A){let G=this.getObject(A);return this.dropObject(A),G}addObject(A){GA(this,Hc)===GA(this,Ft).length&&GA(this,Ft).push(GA(this,Ft).length+1);let G=GA(this,Hc);return bG(this,Hc,GA(this,Ft)[G]),GA(this,Ft)[G]=A,G}getInt32(){return(GA(this,sB)===null||GA(this,sB).buffer!==GA(this,nt).memory.buffer)&&bG(this,sB,new Int32Array(GA(this,nt).memory.buffer)),GA(this,sB)}getUint8(){return(GA(this,rB)===null||GA(this,rB).buffer!==GA(this,nt).memory.buffer)&&bG(this,rB,new Uint8Array(GA(this,nt).memory.buffer)),GA(this,rB)}getU8a(A,G){return this.getUint8().subarray(A/1,A/1+G)}getString(A,G){return va(this.getU8a(A,G))}allocU8a(A){let G=GA(this,nt).__wbindgen_malloc(A.length*1);return this.getUint8().set(A,G/1),[G,A.length]}allocString(A){return this.allocU8a(uG(A))}resultU8a(){let A=this.getInt32()[2],G=this.getInt32()[8/4+1],b=this.getU8a(A,G).slice();return GA(this,nt).__wbindgen_free(A,G*1),b}resultString(){return va(this.resultU8a())}};Ud=new WeakMap,Ft=new WeakMap,Cd=new WeakMap,sB=new WeakMap,rB=new WeakMap,Hc=new WeakMap,nt=new WeakMap,eZ=new WeakMap,ce=new WeakMap,ZZ=new WeakMap;function EV(l,A,G){return async b=>{let t={error:null,type:"none",wasm:null};try{if(A?.length){if(typeof WebAssembly!="object"||typeof WebAssembly.instantiate!="function")throw new Error("WebAssembly is not available in your environment")}else throw new Error("No WebAssembly provided for initialization");let c=await WebAssembly.instantiate(A,{wbg:b});t.wasm=c.instance.exports,t.type="wasm"}catch(c){typeof G=="function"?(t.wasm=G(b),t.type="asm"):(t.error=`FATAL: Unable to initialize @polkadot/wasm-${l}:: ${c.message}`,console.error(t.error))}return t}}var vV="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",HV=new Array(256);for(let l=0,A=vV.length;l<A;l++)HV[vV.charCodeAt(l)]=l;function Gh(l,A){let G=0,b=0,t=-1;for(let c=0,B=A.length-1;t!==B;c++)G=G<<6|HV[l.charCodeAt(c)],(b+=6)>=8&&(A[++t]=G>>>(b-=8)&255);return A}var dc=Uint8Array,iB=Uint16Array,ch=Uint32Array,lv=new dc([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),JV=new dc([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),xV=new dc([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),fV=(l,A)=>{let G=new iB(31);for(let t=0;t<31;++t)G[t]=A+=1<<l[t-1];let b=new ch(G[30]);for(let t=1;t<30;++t)for(let c=G[t];c<G[t+1];++c)b[c]=c-G[t]<<5|t;return[G,b]},[kV,Av]=fV(JV,2);kV[28]=258,Av[258]=28;var[Gv]=fV(xV,0),Bh=new iB(32768);for(let l=0;l<32768;++l){let A=(l&43690)>>>1|(l&21845)<<1;A=(A&52428)>>>2|(A&13107)<<2,A=(A&61680)>>>4|(A&3855)<<4,Bh[l]=((A&65280)>>>8|(A&255)<<8)>>>1}var Sd=(l,A,G)=>{let b=l.length,t=0,c=new iB(A);for(;t<b;++t)l[t]&&++c[l[t]-1];let B=new iB(A);for(t=1;t<A;++t)B[t]=B[t-1]+c[t-1]<<1;let e;if(G){e=new iB(1<<A);let d=15-A;for(t=0;t<b;++t)if(l[t]){let Z=t<<4|l[t],g=A-l[t],n=B[l[t]-1]++<<g;for(let h=n|(1<<g)-1;n<=h;++n)e[Bh[n]>>d]=Z}}else for(e=new iB(b),t=0;t<b;++t)l[t]&&(e[t]=Bh[B[l[t]-1]++]>>15-l[t]);return e},zd=new dc(288);for(let l=0;l<144;++l)zd[l]=8;for(let l=144;l<256;++l)zd[l]=9;for(let l=256;l<280;++l)zd[l]=7;for(let l=280;l<288;++l)zd[l]=8;var wV=new dc(32);for(let l=0;l<32;++l)wV[l]=5;var bv=Sd(zd,9,1),tv=Sd(wV,5,1),wt=(l,A,G)=>{let b=A>>>3;return(l[b]|l[b+1]<<8)>>>(A&7)&G},bh=(l,A)=>{let G=A>>>3;return(l[G]|l[G+1]<<8|l[G+2]<<16)>>>(A&7)},cv=l=>(l>>>3)+(l&7&&1),Bv=(l,A,G)=>{(A==null||A<0)&&(A=0),(G==null||G>l.length)&&(G=l.length);let b=new(l instanceof iB?iB:l instanceof ch?ch:dc)(G-A);return b.set(l.subarray(A,G)),b},th=l=>{let A=l[0];for(let G=1,b=l.length;G<b;++G)l[G]>A&&(A=l[G]);return A},ev=(l,A,G)=>{let b=!G||G.i;G||(G={});let t=l.length,c=!A||!b;A||(A=new dc(t*3));let B=Y=>{let R=A.length;if(Y>R){let u=new dc(Math.max(R<<1,Y));u.set(A),A=u}},e=G.f||0,d=G.p||0,Z=G.b||0,g=G.l,n=G.d,h=G.m,W=G.n;if(e&&!g)return A;let m=t<<3;do{if(!g){G.f=e=wt(l,d,1);let i=wt(l,d+1,3);if(d+=3,i)if(i==1)g=bv,n=tv,h=9,W=5;else if(i==2){let I=wt(l,d,31)+257,Q=wt(l,d+10,15)+4,f=I+wt(l,d+5,31)+1;d+=14;let U=new dc(f),J=new dc(19);for(let y=0;y<Q;++y)J[lv[y]]=wt(l,d+y*3,7);d+=Q*3;let M=th(J),C=(1<<M)-1;if(!b&&d+f*(M+7)>m)break;let D=Sd(J,M,1);for(let y=0;y<f;){let r=D[wt(l,d,C)];d+=r&15;let F=r>>>4;if(F<16)U[y++]=F;else{let E=0,x=0;for(F==16?(x=3+wt(l,d,3),d+=2,E=U[y-1]):F==17?(x=3+wt(l,d,7),d+=3):F==18&&(x=11+wt(l,d,127),d+=7);x--;)U[y++]=E}}let $=U.subarray(0,I),K=U.subarray(I);h=th($),W=th(K),g=Sd($,h,1),n=Sd(K,W,1)}else throw"invalid block type";else{let I=cv(d)+4,Q=l[I-4]|l[I-3]<<8,f=I+Q;if(f>t){if(b)throw"unexpected EOF";break}c&&B(Z+Q),A.set(l.subarray(I,f),Z),G.b=Z+=Q,G.p=d=f<<3;continue}if(d>m)throw"unexpected EOF"}c&&B(Z+131072);let Y=(1<<h)-1,R=(1<<W)-1,u=h+W+18;for(;b||d+u<m;){let i=g[bh(l,d)&Y],I=i>>>4;if(d+=i&15,d>m)throw"unexpected EOF";if(!i)throw"invalid length/literal";if(I<256)A[Z++]=I;else if(I==256){g=void 0;break}else{let Q=I-254;if(I>264){let C=I-257,D=JV[C];Q=wt(l,d,(1<<D)-1)+kV[C],d+=D}let f=n[bh(l,d)&R],U=f>>>4;if(!f)throw"invalid distance";d+=f&15;let J=Gv[U];if(U>3){let C=xV[U];J+=bh(l,d)&(1<<C)-1,d+=C}if(d>m)throw"unexpected EOF";c&&B(Z+131072);let M=Z+Q;for(;Z<M;Z+=4)A[Z]=A[Z-J],A[Z+1]=A[Z+1-J],A[Z+2]=A[Z+2-J],A[Z+3]=A[Z+3-J];Z=M}}G.l=g,G.p=d,G.b=Z,g&&(e=1,G.m=h,G.d=n,G.n=W)}while(!e);return Z==A.length?A:Bv(A,0,Z)},Zv=l=>{if((l[0]&15)!=8||l[0]>>>4>7||(l[0]<<8|l[1])%31)throw"invalid zlib data";if(l[1]&32)throw"invalid zlib data: preset dictionaries not supported"};function eh(l,A){return ev((Zv(l),l.subarray(2,-4)),A)}var dZ=po(UV(),1);var CV=eh(Gh(dZ.bytes,new Uint8Array(dZ.lenIn)),new Uint8Array(dZ.lenOut));var SV=EV("crypto",CV,null);var cA=new ka(SV);async function zV(l){return cA.init(l)}function wG(l){return(...A)=>{if(!cA.wasm)throw new Error("The WASM interface has not been initialized. Ensure that you wait for the initialization Promise with waitReady() from @polkadot/wasm-crypto (or cryptoWaitReady() from @polkadot/util-crypto) before attempting to use WASM-only interfaces.");return l(cA.wasm,...A)}}var jV=wG((l,A)=>(l.ext_bip39_to_entropy(8,...cA.allocString(A)),cA.resultU8a())),MV=wG((l,A,G)=>(l.ext_bip39_to_mini_secret(8,...cA.allocString(A),...cA.allocString(G)),cA.resultU8a())),TV=wG((l,A,G)=>(l.ext_bip39_to_seed(8,...cA.allocString(A),...cA.allocString(G)),cA.resultU8a())),DV=wG((l,A)=>l.ext_bip39_validate(...cA.allocString(A))!==0),LV=wG((l,A)=>(l.ext_ed_from_seed(8,...cA.allocU8a(A)),cA.resultU8a())),OV=wG((l,A,G,b)=>(l.ext_ed_sign(8,...cA.allocU8a(A),...cA.allocU8a(G),...cA.allocU8a(b)),cA.resultU8a())),PV=wG((l,A,G,b)=>l.ext_ed_verify(...cA.allocU8a(A),...cA.allocU8a(G),...cA.allocU8a(b))!==0),KV=wG((l,A)=>(l.ext_secp_from_seed(8,...cA.allocU8a(A)),cA.resultU8a())),qV=wG((l,A)=>(l.ext_secp_pub_compress(8,...cA.allocU8a(A)),cA.resultU8a())),_V=wG((l,A)=>(l.ext_secp_pub_expand(8,...cA.allocU8a(A)),cA.resultU8a())),$V=wG((l,A,G,b)=>(l.ext_secp_recover(8,...cA.allocU8a(A),...cA.allocU8a(G),b),cA.resultU8a())),lu=wG((l,A,G)=>(l.ext_secp_sign(8,...cA.allocU8a(A),...cA.allocU8a(G)),cA.resultU8a()));var Au=wG((l,A,G,b)=>(l.ext_blake2b(8,...cA.allocU8a(A),...cA.allocU8a(G),b),cA.resultU8a())),Gu=wG((l,A,G)=>(l.ext_hmac_sha256(8,...cA.allocU8a(A),...cA.allocU8a(G)),cA.resultU8a())),bu=wG((l,A,G)=>(l.ext_hmac_sha512(8,...cA.allocU8a(A),...cA.allocU8a(G)),cA.resultU8a())),tu=wG((l,A)=>(l.ext_keccak256(8,...cA.allocU8a(A)),cA.resultU8a())),cu=wG((l,A)=>(l.ext_keccak512(8,...cA.allocU8a(A)),cA.resultU8a())),Bu=wG((l,A,G,b)=>(l.ext_pbkdf2(8,...cA.allocU8a(A),...cA.allocU8a(G),b),cA.resultU8a())),eu=wG((l,A,G,b,t,c)=>(l.ext_scrypt(8,...cA.allocU8a(A),...cA.allocU8a(G),b,t,c),cA.resultU8a())),Zu=wG((l,A)=>(l.ext_sha256(8,...cA.allocU8a(A)),cA.resultU8a())),du=wG((l,A)=>(l.ext_sha512(8,...cA.allocU8a(A)),cA.resultU8a()));function TA(){return!!cA.wasm}async function nu(){try{return!!await zV()}catch{return!1}}function Zh(l){return(...A)=>dt(l(...A))}function dh(l,A){return(G,b)=>A(G,l,b)}function Ua(l,A){return(G,b=256,t)=>{let c=Tl(G);return!PA||!t&&TA()?l[b](c):A[b](c)}}function Mb(l,A=256,G,b){let t=Math.ceil(A/8),c=Tl(l);return!PA||!b&&TA()?Au(c,Tl(G),t):G?To(c,{dkLen:t,key:G}):To(c,{dkLen:t})}var nh=Zh(Mb);var gu=new TextEncoder,dv=new TextDecoder,Ca="cere.vault.grant.v1",mB="cere.vault.grant.v2",Be="",nZ=["public","internal","private","restricted"];function aZ(l){return nZ.includes(l)}function Wu(){let l=nZ.map(A=>`"${A}"`);return l.slice(0,-1).join(", ")+" or "+l[l.length-1]}var Sa="X-Grant-Signature",ah="X-Grant-Issued-At";function Ut(l){let A=l.startsWith("0x")?l.slice(2):l;return A.startsWith("0X")&&(A=A.slice(2)),A=A.toLowerCase(),A===""||A.length%2!==0||!/^[0-9a-f]+$/.test(A)?l:`0x${A}`}function gh(l){let A=Ut(l);return`v-${nh(gu.encode(A),128).slice(2)}`}var za="";var lb=class extends Error{constructor(G,b=""){super(G);el(this,"memberPubkey");this.memberPubkey=b,this.name="GrantVerificationError"}};function Wh(l,A,G,b,t,c){return ja(l,A,G,b,t,c,Be)}function ja(l,A,G,b,t,c,B){if(l==="")throw new Error("canonical grant: vaultId is required");if(A==="")throw new Error("canonical grant: memberPubkey is required");if(G==="")throw new Error("canonical grant: role is required");if(t==="")throw new Error("canonical grant: issuedAt is required");let e=Ca;if(B!==Be){if(!aZ(B))throw new Error(`canonical grant: privacyCeiling ${JSON.stringify(B)} must be ${Wu()}`);e=mB}let Z=Object.keys(b).sort(nv).map(n=>`{"name":${xc(n)},"level":${xc(b[n])}}`),g=`{"schema":${xc(e)},"vaultId":${xc(l)},"memberPubkey":${xc(A)},"role":${xc(G)},"scopes":[${Z.join(",")}],"issuedAt":${xc(t)},"expiresAt":${xc(c)}`+(B===Be?"":`,"privacyCeiling":${xc(B)}`)+"}";return gu.encode(g)}function ou(l){if(l.length===0)throw new Error("decode grant: empty document");let A;try{A=JSON.parse(dv.decode(l))}catch(W){throw new Error(`decode grant: ${W instanceof Error?W.message:String(W)}`)}if(typeof A!="object"||A===null||Array.isArray(A))throw new Error("decode grant: document is not a JSON object");let G=A,b=Jc(G,"schema"),t=Jc(G,"privacyCeiling",!0);if(b===Ca){if(t!=="")throw new Error(`decode grant: schema ${JSON.stringify(b)} carries a privacyCeiling; that is ${JSON.stringify(mB)}`)}else if(b===mB){if(!aZ(t))throw new Error(`decode grant: schema ${JSON.stringify(b)} requires a privacyCeiling of ${Wu()}, got ${JSON.stringify(t)}`)}else throw new Error(`decode grant: schema ${JSON.stringify(b)} is not ${JSON.stringify(Ca)} or ${JSON.stringify(mB)}`);let c=Jc(G,"vaultId"),B=Jc(G,"memberPubkey"),e=Jc(G,"role");if(c===""||B===""||e==="")throw new Error("decode grant: vaultId, memberPubkey and role are all required");let d=G.scopes;if(!Array.isArray(d))throw new Error("decode grant: scopes must be an array");let Z={};for(let W of d){if(typeof W!="object"||W===null||Array.isArray(W))throw new Error("decode grant: a scope entry is not an object");let m=Jc(W,"name");if(m==="")throw new Error("decode grant: a scope with no name");Z[m]=Jc(W,"level")}let g=Jc(G,"issuedAt");if(g==="")throw new Error("decode grant: issuedAt is required");let n=Jc(G,"expiresAt");return{schema:b,vaultId:c,memberPubkey:B,role:e,scopes:Z,issuedAt:g,expiresAt:n,privacyCeiling:b===mB?t:""}}async function hu(l,A,G){if(A.length===0||G==="")return!1;let b,t;try{b=Te(Yt(l).toLowerCase()),t=Te(Yt(G).toLowerCase())}catch{return!1}if(b.length!==32||t.length!==64)return!1;try{return await z2(t,A,b)}catch{return!1}}async function oh(l,A,G={}){if(typeof A!="string"||A==="")throw new lb("expectedVaultId is required: verifying a roster against the vault id it carries only proves the response agrees with itself");if(typeof l!="object"||l===null)throw new lb(`signed roster is not an object (got ${au(l)})`);if(typeof l.vaultId!="string"||l.vaultId==="")throw new lb("signed roster carries no vaultId");if(typeof l.orgWalletPubkey!="string"||l.orgWalletPubkey==="")throw new lb("signed roster carries no orgWalletPubkey");if(!Array.isArray(l.grants))throw new lb(`signed roster's grants is not an array (got ${au(l.grants)})`);if(l.vaultId!==A)throw new lb(`signed roster names vault ${l.vaultId}, asked about ${A}`);if(gh(l.orgWalletPubkey)!==A)throw new lb(`orgWalletPubkey ${l.orgWalletPubkey} does not derive vault ${A}`);let b=[];for(let t of l.grants){if(typeof t!="object"||t===null){let c=new lb("signed roster holds a grant that is not an object");G.onUnverifiableGrant?.(c);continue}try{b.push(await su(A,l.orgWalletPubkey,t))}catch(c){if(!(c instanceof lb))throw c;G.onUnverifiableGrant?.(c)}}return b}function au(l){return l===null?"null":Array.isArray(l)?"an array":typeof l}async function su(l,A,G){if(gh(A)!==l)throw new lb(`orgWalletPubkey ${A} does not derive vault ${l}`,G.memberPubkey);let b;try{b=y2(G.doc)}catch(c){throw new lb(`grant document is not valid base64: ${c instanceof Error?c.message:String(c)}`,G.memberPubkey)}if(!await hu(A,b,G.sig))throw new lb(`grant document is not signed by the vault owner (${A})`,G.memberPubkey);let t;try{t=ou(b)}catch(c){throw new lb(c instanceof Error?c.message:String(c),G.memberPubkey)}if(t.vaultId!==l||t.memberPubkey!==G.memberPubkey)throw new lb(`grant document describes a different membership: it names ${t.memberPubkey} on ${t.vaultId}, and was served as ${G.memberPubkey} on ${l}`,G.memberPubkey);return t}function Jc(l,A,G=!1){let b=l[A];if(b===void 0&&G)return"";if(typeof b!="string")throw new Error(`decode grant: ${A} must be a string, got ${b===void 0?"nothing":typeof b}`);return b}function xc(l){return JSON.stringify(l).replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function nv(l,A){let G=Array.from(l),b=Array.from(A),t=Math.min(G.length,b.length);for(let c=0;c<t;c++){let B=G[c].codePointAt(0),e=b[c].codePointAt(0);if(B!==e)return B-e}return G.length-b.length}var Ma=class{constructor(A,G){el(this,"http");el(this,"signer");this.http=A,this.signer=G}mine(){return this.http.send("GET",kl.memberships())}list(A){return this.http.send("GET",kl.vaultMembers(A))}signedRoster(A){return this.http.send("GET",kl.vaultSignedRoster(A))}async put(A,G,b,t,c={}){let B=c.privacyCeiling===void 0?void 0:c.privacyCeiling;if(B!==void 0&&!aZ(B))throw new Error(`put: privacyCeiling ${JSON.stringify(B)} must be one of `+nZ.map(Z=>`"${Z}"`).join(", "));let e=c.scopes??await this.heldScopes(A,G),d=t===void 0?za:t;return this.http.send("PUT",kl.vaultMember(A,G),{body:{role:b,expiresAt:t,...B===void 0?{}:{privacyCeiling:B},timestamp:new Date().toISOString()},headers:await this.grantHeader(A,G,b,e,d,B)})}remove(A,G){return this.http.send("DELETE",kl.vaultMember(A,G),{body:{timestamp:new Date().toISOString()}})}scopes(A,G){return this.http.send("GET",kl.vaultMemberScopes(A,G))}async putScopes(A,G,b,t={}){this.grantSigner();let c=t.standing?.privacyCeiling;if(c!==void 0&&c!==Be&&!aZ(c))throw new Error(`putScopes: standing.privacyCeiling ${JSON.stringify(c)} must be one of `+nZ.map(Z=>`"${Z}"`).join(", ")+", or NO_PRIVACY_CEILING for a member who holds none");let B=t.standing??await this.heldStanding(A,G),e=c??await this.heldCeiling(A,G),d=B.expiresAt===void 0?za:B.expiresAt;try{return await this.http.send("PUT",kl.vaultMemberScopes(A,G),{body:{scopes:b,expiresAt:B.expiresAt,timestamp:new Date().toISOString()},headers:await this.grantHeader(A,G,B.role,b,d,e===void 0||e===Be?void 0:e)})}catch(Z){if(e===void 0&&Z instanceof _G&&Z.status===400&&Z.message.includes(mB)){let g=Ut(G);throw new Xd(`putScopes: ${g} is not in ${A}'s signed roster (it serves live memberships only), so the grant was signed with no privacy ceiling, and vault-api refused it because this member holds one. Nothing was written. Pass \`{ standing: { role, expiresAt, privacyCeiling } }\` with the ceiling the member holds. Server said: ${Z.message}`,g,Z.status,Z.code)}throw Z}}async grantHeader(A,G,b,t,c,B){let e=this.grantSigner(),d=new Date().toISOString(),Z=B===void 0?Wh(A,Ut(G),b,t,d,c):ja(A,Ut(G),b,t,d,c,B);return{[Sa]:Kb(await e.sign(Z,"data")),[ah]:d}}grantSigner(){let A=this.signer;if(A===void 0||typeof A.sign!="function")throw new It(`A membership write must carry the VAULT OWNER's signature over the grant's canonical document, in the ${Sa} header. Construct the SDK with \`signer\` set to the vault owner's key (\`new VaultSDK({ endpoint, signer })\`); a custom \`auth\` provider authenticates the request but cannot sign the grant, because the two cover different bytes.`);if(A.type!=="ed25519")throw new It(`A grant signature must be ed25519 \u2014 vault-api verifies it with SchemeEd25519 and nothing else \u2014 but this signer is "${A.type}". An sr25519 key can authenticate the request and still never authorise the grant.`);return A}async heldCeiling(A,G){let b=Ut(G),t=[],B=(await oh(await this.signedRoster(A),A,{onUnverifiableGrant:d=>t.push(d)})).find(d=>Ut(d.memberPubkey)===b);if(B!==void 0)return B.privacyCeiling;let e=t.find(d=>d.memberPubkey!==""&&Ut(d.memberPubkey)===b);if(e!==void 0)throw new lb(`putScopes: ${b}'s grant in the signed roster of ${A} failed verification (${e.message}), so the privacy ceiling it holds is unknown and no grant document can be signed for it.`,e.memberPubkey)}async heldScopes(A,G){try{return(await this.scopes(A,G)).scopes}catch(b){if(b instanceof _G&&b.status===404)return{};throw b}}async heldStanding(A,G){let b=Ut(G),t=(await this.list(A)).find(c=>c.isOwner!==!0&&Ut(c.memberPubkey)===b);if(t===void 0)throw new Error(`putScopes: ${b} has no membership row on ${A}, so there is no role or expiry to put in the grant document. Add the member first (\`memberships.put\`), or pass \`{ standing: { role, expiresAt } }\` if you already know them.`);return{role:t.role,expiresAt:t.expiresAt}}};var ru=new bt,Ta=class{constructor(A){el(this,"http");this.http=A}getAgent(A,G){let b=G?kl.marketplaceAgentVersion(A,G):kl.marketplaceAgent(A);return this.http.send("GET",b,{auth:ru})}async list(A={}){let G=await this.http.send("GET",kl.marketplaceAgents(),{auth:ru,query:{limit:A.limit,cursor:A.cursor,q:A.query}}),t={items:G.agents??G.items??[]};return G.nextCursor!==void 0&&(t.nextCursor=G.nextCursor),t}};var iu=new bt,Da=class{constructor(A){el(this,"http");this.http=A}live(){return this.http.send("GET",kl.health(),{auth:iu})}ready(){return this.http.send("GET",kl.ready(),{auth:iu})}};var La=class{constructor(A){el(this,"http");this.http=A}list(A){return this.http.send("GET",kl.scopes(A))}get(A,G){return this.http.send("GET",kl.scope(A,G))}create(A,G){return this.http.send("POST",kl.scopes(A),{body:mu(G)})}update(A,G,b){return this.http.send("PATCH",kl.scope(A,G),{body:mu(b)})}delete(A,G){return this.http.send("DELETE",kl.scope(A,G),{body:{}})}};function mu(l){let A={};return"name"in l&&l.name!==void 0&&(A.name=l.name),l.displayName!==void 0&&(A.displayName=l.displayName),l.streamLabel!==void 0&&(A.streamLabel=l.streamLabel),l.metadata!==void 0&&(A.metadata=l.metadata),A}function Vu(l,A){if(l.length>16)throw new Error(`[${A}] \`scopes\` has ${l.length} entries; the server refuses more than 16 \u2014 trim the set before calling`);for(let G of l)if(typeof G!="string"||G.trim().length===0)throw new Error(`[${A}] \`scopes\` contains an empty/blank entry (${JSON.stringify(G)}) \u2014 the server refuses an empty scope member`)}function gZ(l,A){let G=l.scope!==void 0,b=l.scopes!==void 0;if(G&&b)throw new Error(`[${A}] both \`scope\` (${JSON.stringify(l.scope)}) and \`scopes\` (${JSON.stringify(l.scopes)}) were supplied \u2014 these conflict and which one would apply is undefined; pass exactly one.`);if(b){if(!l.scopes||l.scopes.length===0)throw new Error(`[${A}] \`scopes\` must be a non-empty array`);return Vu(l.scopes,A),l.scopes}if(G)return Vu([l.scope],A),[l.scope];throw new Error(`[${A}] requires \`scope\` or a non-empty \`scopes\` array`)}var oZ=class{constructor(A){el(this,"http");this.http=A}async connect(A,G){let{ceiling:b,...t}=G,c=b===void 0?{...t}:{...t,ceiling:Oa(b)};return gZ(G,"Agents.connect"),this.http.send("POST",kl.agents(A),{body:c})}async list(A,G={}){return(await this.http.send("GET",kl.agents(A),{query:{status:G.status}})).items??[]}get(A,G){return this.http.send("GET",kl.agent(A,G))}update(A,G,b){return this.http.send("PATCH",kl.agent(A,G),{body:{settings:b}})}async setCeiling(A,G,b){let t=Oa(b);return this.http.send("PUT",kl.agentCeiling(A,G),{body:{...t}})}disconnect(A,G){return this.http.send("DELETE",kl.agent(A,G),{body:{}})}};function WZ(l){return new _G(`invalid ceiling: ${l}`,0,"BAD_REQUEST")}function Oa(l){if(l===null||typeof l!="object"||Array.isArray(l))throw WZ("expected an object { gpuUnits?, a2aTokens? }");for(let t of Object.keys(l))if(t!=="gpuUnits"&&t!=="a2aTokens")throw WZ(`unknown field ${JSON.stringify(t)} (expected { gpuUnits?, a2aTokens? })`);let A=t=>{let c=l[t];if(c===void 0)return 0;if(typeof c!="number"||!Number.isFinite(c))throw WZ(`${t} must be a finite number (got ${String(c)})`);if(c<0)throw WZ(`${t} must be >= 0 (got ${c})`);return c},G=A("gpuUnits"),b=A("a2aTokens");if(!Number.isInteger(b))throw WZ(`a2aTokens must be an integer (got ${b})`);if(b>Number.MAX_SAFE_INTEGER)throw WZ(`a2aTokens must be <= Number.MAX_SAFE_INTEGER (got ${b})`);return{gpuUnits:G,a2aTokens:b}}var yt=class{constructor(A){el(this,"http");this.http=A}listStreams(A,G,b={}){return this.http.send("GET",kl.scopeStreams(A,G),{query:{active:b.active,limit:b.limit,cursor:b.cursor}})}getStream(A,G,b){return this.http.send("GET",kl.stream(A,G,b))}listStreamEvents(A,G,b,t={}){return this.http.send("GET",kl.streamEvents(A,G,b),{query:{limit:t.limit,cursor:t.cursor}})}listJobs(A,G={}){return this.http.send("GET",kl.jobs(A),{query:{state:G.state,cursor:G.cursor,limit:G.limit}})}getJob(A,G){return this.http.send("GET",kl.job(A,G))}listAgentJobs(A,G,b={}){return this.http.send("GET",kl.agentJobs(A,G),{query:{state:b.state,cursor:b.cursor,limit:b.limit}})}listTasks(A,G,b={}){return this.http.send("GET",kl.jobTasks(A,G),{query:{cursor:b.cursor,limit:b.limit}})}getTask(A,G,b){return this.http.send("GET",kl.jobTask(A,G,b))}listTaskLogs(A,G,b,t={}){return this.http.send("GET",kl.jobTaskLogs(A,G,b),{query:{offset:t.offset,limit:t.limit}})}};var Pa=class{constructor(A,G){el(this,"http");el(this,"vaultId");this.http=A,this.vaultId=G}search(A,G={}){return this.http.send("POST",kl.memoryTool(this.vaultId,"record_search"),{body:{match:A,limit:G.limit,type:G.type,privacy:G.privacy,scope:G.scope,cursor:G.cursor,domain:G.domain}})}list(A,G={}){return this.http.send("POST",kl.memoryTool(this.vaultId,"record_list"),{body:{type:A,limit:G.limit,scope:G.scope,cursor:G.cursor,domain:G.domain}})}get(A){return this.http.send("POST",kl.memoryTool(this.vaultId,"record_get"),{body:{id:A}})}neighbours(A,G={}){return this.http.send("POST",kl.memoryTool(this.vaultId,"record_neighbours"),{body:{id:A,limit:G.limit,edge_type:G.edgeType,direction:G.direction}})}countByType(A={}){return this.http.send("POST",kl.memoryTool(this.vaultId,"record_count_by_type"),{body:{scope:A.scope,domain:A.domain}})}};async function Yu(l){return _a(await l.send("GET",kl.connectors()),"connectors")}var Ka=class{constructor(A,G){el(this,"http");el(this,"vaultId");this.http=A,this.vaultId=G}async list(){return _a(await this.http.send("GET",kl.connections(this.vaultId)),"connections")}create(A){return this.http.send("POST",kl.connections(this.vaultId),{body:uu(A)})}update(A,G){return this.http.send("PATCH",kl.connection(this.vaultId,A),{body:uu(G)})}async revoke(A){await this.http.send("DELETE",kl.connection(this.vaultId,A),{body:{}})}async actions(A){return _a(await this.http.send("GET",kl.connectionActions(this.vaultId,A)),"actions")}},qa=class{constructor(A,G){el(this,"http");el(this,"vaultId");this.http=A,this.vaultId=G}async list(A){return _a(await this.http.send("GET",kl.agentConnections(this.vaultId,A)),"connections")}set(A,G,b){return this.http.send("PUT",kl.agentConnection(this.vaultId,A,G),{body:{actions:b.actions,events:b.events,filter:b.filter??{}}})}async remove(A,G){await this.http.send("DELETE",kl.agentConnection(this.vaultId,A,G),{body:{}})}};function uu(l){let A={};for(let[G,b]of Object.entries(l))b!==void 0&&(A[G]=b);return A}function _a(l,A){let G=l&&typeof l=="object"?l[A]:void 0;return Array.isArray(G)?G:[]}var $a=class{constructor(A){el(this,"http");this.http=A}publish(A,G,b){let c=(Array.isArray(b)?b:[b]).map(B=>({role:"user",...B,timestamp:B.timestamp??new Date().toISOString()}));return this.http.send("POST",kl.scopeEvents(A,G),{body:{events:c}})}};var lg=class{constructor(A){el(this,"http");this.http=A}async upload(A,G,b,t,c={}){return this.http.send("PUT",kl.scopeObject(A,G,b),{rawBody:t,headers:{"Content-Type":c.contentType??"application/octet-stream"}})}async get(A,G,b){return this.http.send("GET",kl.scopeObject(A,G,b),{responseType:"bytes"})}async head(A,G,b){let t=await this.http.send("HEAD",kl.scopeObject(A,G,b),{responseType:"headers"}),c=Number(t["content-length"]??"0");return{size:Number.isFinite(c)?c:0,contentType:t["content-type"]??"",etag:t.etag,updatedAt:t["last-modified"]}}async presignedUrl(A,G,b,t={}){return this.http.send("GET",kl.scopeObjectsPresignedUrl(A,G),{query:{path:b,ttlSeconds:t.ttlSeconds}})}async delete(A,G,b){await this.http.send("DELETE",kl.scopeObject(A,G,b),{body:{timestamp:new Date().toISOString()}})}async list(A,G,b={}){return this.http.send("GET",kl.scopeObjects(A,G),{query:{prefix:b.prefix}})}};function hh(l,A,G,b,t,c={}){let B=new yt(l),e=c.intervalMs??1e3,d=c.pageSize??100,Z=c.onError??(R=>{console.warn("[vault-sdk] subscribe poll failed:",R)}),g=new Set,n,h=!1,W,m=new Promise(R=>W=R);return(async()=>{for(;!h;){try{let R=await B.listStreamEvents(A,G,b.context,{cursor:n,limit:d});for(let u of R.items)g.has(u.eventId)||(g.add(u.eventId),!(b.types&&!b.types.includes(u.type))&&(b.from&&!b.from.includes(u.from??"")||await t(u)));R.nextCursor&&(n=R.nextCursor)}catch(R){Z(R)}if(h)break;await new Promise(R=>setTimeout(R,e))}W()})(),{unsubscribe(){h=!0},closed:m}}var jd=class{constructor(A,G,b){el(this,"http");el(this,"vaultId");el(this,"name");el(this,"events");el(this,"browse");el(this,"_objects");el(this,"streams",{list:(A={})=>this.browse.listStreams(this.vaultId,this.name,A),get:A=>this.browse.getStream(this.vaultId,this.name,A)});el(this,"objects",{upload:async(A,G,b={})=>{let t=await this._objects.upload(this.vaultId,this.name,A,G,b);return b.publishEvent&&await this.publish({type:b.publishEvent.type,context:b.publishEvent.context,payload:{...b.publishEvent.payload,vaultPath:t.vaultPath}}),t},get:A=>this._objects.get(this.vaultId,this.name,A),head:A=>this._objects.head(this.vaultId,this.name,A),presignedUrl:(A,G={})=>this._objects.presignedUrl(this.vaultId,this.name,A,G),delete:A=>this._objects.delete(this.vaultId,this.name,A),list:(A={})=>this._objects.list(this.vaultId,this.name,A)});this.http=A,this.vaultId=G,this.name=b,this.events=new $a(A),this.browse=new yt(A),this._objects=new lg(A)}async publish(A){let G=await this.events.publish(this.vaultId,this.name,A),b=G.rejected??[],t=G.accepted??[];if(b.length>0){let c=b[0];throw new Error(`publish rejected: ${c.reason}${c.code?` (${c.code})`:""}`)}return{eventId:t[0]}}stream(A){return{events:{list:(G={})=>this.browse.listStreamEvents(this.vaultId,this.name,A,G)}}}subscribe(A,G,b={}){return hh(this.http,this.vaultId,this.name,A,G,b)}subscribeAll(A,G,b={}){return Wv(this.http,this.vaultId,this.name,this.browse,A,G,b)}};function Wv(l,A,G,b,t,c,B){let e=B.refreshIntervalMs??3e4,d=B.onError??(R=>{console.warn("[vault-sdk] subscribeAll refresh failed:",R)}),Z=new Map,g=!1,n,h,W=new Promise(R=>h=R),m=R=>{if(Z.has(R)||g)return;let u=hh(l,A,G,{context:R,...t.types?{types:t.types}:{}},c,B);Z.set(R,u)},Y=async()=>{try{let R=await b.listStreams(A,G);for(let u of R.items)m(u.context)}catch(R){d(R)}g||(n=setTimeout(Y,e))};return Y(),{unsubscribe(){if(g)return;g=!0,n&&clearTimeout(n);let R=[];for(let u of Z.values())u.unsubscribe(),R.push(u.closed);Z.clear(),Promise.all(R).then(()=>h())},closed:W}}var hZ=class{constructor(A){el(this,"http");this.http=A}query(A,G,b,t,c,B=[]){return this.http.send("POST",kl.cubbyQuery(A,G,b,t),{body:{sql:c,params:B}})}exec(A,G,b,t,c,B=[]){return this.http.send("POST",kl.cubbyExec(A,G,b,t),{body:{sql:c,params:B}})}serviceQuery(A,G,b,t,c=[]){return this.http.send("POST",kl.serviceCubbyQuery(A,G,b),{body:{sql:t,params:c}})}serviceExec(A,G,b,t,c=[]){return this.http.send("POST",kl.serviceCubbyExec(A,G,b),{body:{sql:t,params:c}})}async serviceList(A,G){return(await this.http.send("GET",kl.serviceCubbies(A,G)))?.data??[]}serviceProvision(A,G,b,t){return this.http.send("POST",kl.serviceCubbyProvision(A,G,b),{body:{migrations:t}})}serviceDelete(A,G,b){return this.http.send("DELETE",kl.serviceCubby(A,G,b))}};var Md=class{constructor(A,G,b){el(this,"vaultId");el(this,"asPubKey");el(this,"cubbies");this.vaultId=G,this.asPubKey=b,this.cubbies=new hZ(A)}list(){return this.cubbies.serviceList(this.vaultId,this.asPubKey)}cubby(A){let{vaultId:G,asPubKey:b,cubbies:t}=this;return{query:(c,B=[])=>t.serviceQuery(G,b,A,c,B),exec:(c,B=[])=>t.serviceExec(G,b,A,c,B),provision:c=>t.serviceProvision(G,b,A,c),delete:()=>t.serviceDelete(G,b,A)}}};var Td=class{constructor(A,G,b,t,c){el(this,"vaultId");el(this,"scope");el(this,"agentId");el(this,"alias");el(this,"api");this.vaultId=G,this.scope=b,this.agentId=t,this.alias=c,this.api=new hZ(A)}query(A,G=[]){return this.api.query(this.vaultId,this.scope,this.agentId,this.alias,A,G)}exec(A,G=[]){return this.api.exec(this.vaultId,this.scope,this.agentId,this.alias,A,G)}};var ee=class l{constructor(A,G,b){el(this,"http");el(this,"vaultIdRoot");el(this,"vaultId");el(this,"agentId");el(this,"scope");el(this,"scopes");el(this,"version");el(this,"asPubKey");el(this,"cubbyAliases");el(this,"status");el(this,"manifest");el(this,"ceiling");el(this,"bundle");el(this,"createdAt");el(this,"updatedAt");el(this,"api");el(this,"browse");el(this,"jobs",{list:(A={})=>this.browse.listAgentJobs(this.vaultIdRoot,this.agentId,A)});this.http=A,this.vaultIdRoot=G,this.vaultId=b.vaultId,this.agentId=b.agentId,this.scope=b.scope,this.scopes=b.scopes,this.version=b.version,this.asPubKey=b.asPubKey,this.cubbyAliases=b.cubbyAliases,this.status=b.status,this.manifest=b.manifest,this.ceiling=b.ceiling,this.bundle=b.bundle,this.createdAt=b.createdAt,this.updatedAt=b.updatedAt,this.api=new oZ(A),this.browse=new yt(A)}cubby(A){if(!this.cubbyAliases.includes(A))throw new Error(`agent ${this.agentId} has no cubby "${A}". Declared aliases: ${this.cubbyAliases.join(", ")||"(none)"}`);return new Td(this.http,this.vaultIdRoot,this.scope,this.agentId,A)}async update(A){let G=await this.api.update(this.vaultIdRoot,this.agentId,A);return new l(this.http,this.vaultIdRoot,G)}async setCeiling(A){let G=await this.api.setCeiling(this.vaultIdRoot,this.agentId,A);return new l(this.http,this.vaultIdRoot,G)}disconnect(){return this.api.disconnect(this.vaultIdRoot,this.agentId)}};var Dd=class{constructor(A,G,b){el(this,"http");el(this,"vaultId");el(this,"jobId");el(this,"browse");el(this,"tasks",{list:(A={})=>this.browse.listTasks(this.vaultId,this.jobId,A),get:A=>this.browse.getTask(this.vaultId,this.jobId,A),logs:(A,G={})=>this.browse.listTaskLogs(this.vaultId,this.jobId,A,G),subscribe:(A,G,b={})=>ov(this.browse,this.vaultId,this.jobId,A,G,b)});this.http=A,this.vaultId=G,this.jobId=b,this.browse=new yt(A)}get(){return this.browse.getJob(this.vaultId,this.jobId)}tree(){throw new Error("JobHandle.tree() requires the orchestrator's tree route which is not yet implemented (returns 501).")}};function ov(l,A,G,b,t,c){let B=c.intervalMs??1e3,e=c.pageSize??100,d=c.onError??(R=>{console.warn("[vault-sdk] tasks.subscribe poll failed:",R)}),Z=new Set,g,n=!1,h,W=new Promise(R=>h=R),m=b.since?Date.parse(b.since):void 0;return(async()=>{for(;!n;){try{let R=await l.listTasks(A,G,{cursor:g,limit:e});for(let u of R.items)if(!Z.has(u.taskId)){if(Z.add(u.taskId),m!==void 0){let i=u.startedAt??u.finishedAt;if(i&&Date.parse(i)<m)continue}await t(u)}R.nextCursor&&(g=R.nextCursor)}catch(R){d(R)}if(n)break;await new Promise(R=>setTimeout(R,B))}h()})(),{unsubscribe(){n=!0},closed:W}}var hv=new TextEncoder;function sh(l){if(!l.scopes||l.scopes.length===0)throw new Error("buildVaultAgreementPayloadV2: `scopes` must be a non-empty array \u2014 an agreement must record at least one scope");let A=Array.from(new Set(l.scopes)),G=l.createdAt??oa,b={version:"v2",agent_service_pub_key:yo(l.asPubKey),agent_id:l.agentId,vault_id:l.vaultId,user_pub_key:yo(l.userPubKey),revoked:!1,expires_at:null,metadata:{scopes:A},created_at:G()};return{payload:b,bytes:hv.encode(JSON.stringify(b))}}async function Ag(l){if(typeof l.signer?.sign!="function")throw new It;let{agentId:A,agentServicePubkey:G}=l.agent;if(!G)throw new Error("signAndSubmitAgreement: `agent.agentServicePubkey` is required");let b=gZ(l,"signAndSubmitAgreement"),{bytes:t}=sh({vaultId:l.vault.id,userPubKey:l.vault.userPubKey,asPubKey:G,agentId:A,scopes:b,createdAt:l.clock}),c=await l.signer.sign(t,"data"),B=Kb(c),e={payload:De(t),signature:{algorithm:"ed25519",signer:gB(l.vault.userPubKey),value:gB(B)}};return await l.gar.postAgreement(e),{agreementSignature:Yt(B)}}var fc=class{constructor(A,G,b={}){el(this,"id");el(this,"bucketId");el(this,"walletPubkey");el(this,"gatewayEndpoint");el(this,"region");el(this,"status");el(this,"disconnectedAt");el(this,"displayName");el(this,"registryBucketId");el(this,"_http");el(this,"_scopes");el(this,"_agents");el(this,"_browse");el(this,"memory");el(this,"connections");el(this,"_access");el(this,"_gar");el(this,"_signer");el(this,"_userPubKey");el(this,"scopes",{list:()=>this._scopes.list(this.id),get:A=>this._scopes.get(this.id,A),create:A=>this._scopes.create(this.id,A),update:(A,G)=>this._scopes.update(this.id,A,G),delete:A=>this._scopes.delete(this.id,A)});el(this,"agents",{connect:async A=>{if(!this._gar)throw new Error("vault.agents.connect requires `garEndpoint` on VaultSDKConfig");if(!this._signer)throw new Error("vault.agents.connect requires a `signer` on VaultSDKConfig");let G=A.agentId.includes(":")?A.agentId.split(":")[0]:"",b=A.agentServicePubkey??G;if(!b)throw new Error(`[vault.agents.connect] cannot derive agentServicePubkey from agentId '${A.agentId}' (expected '<pubkey>:<alias>'); pass agentServicePubkey explicitly`);let t=gZ(A,"vault.agents.connect");A.ceiling!==void 0&&Oa(A.ceiling);let{agreementSignature:c}=await Ag({signer:this._signer,vault:{id:this.id,userPubKey:this._userPubKey},agent:{agentId:A.agentId,agentServicePubkey:b},scopes:t,gar:this._gar}),B=A.scope!==void 0?{scope:A.scope}:{scopes:A.scopes},e={agentId:A.agentId,...B,settings:A.settings??{},agreementSignature:c,...A.ceiling!==void 0?{ceiling:A.ceiling}:{},...A.bundleCid!==void 0?{bundleCid:A.bundleCid}:{}},d=await this._agents.connect(this.id,e);return new ee(this._http,this.id,d)},list:async()=>(await this._agents.list(this.id)).map(G=>new ee(this._http,this.id,G)),get:async A=>{let G=await this._agents.get(this.id,A);return new ee(this._http,this.id,G)},connections:A=>this._access.list(A),setConnection:(A,G,b)=>this._access.set(A,G,b),removeConnection:(A,G)=>this._access.remove(A,G)});el(this,"jobs",{list:(A={})=>this._browse.listJobs(this.id,A),get:A=>new Dd(this._http,this.id,A)});this.id=G.vaultId,this.bucketId=G.bucketId,this.walletPubkey=G.walletPubkey,this.gatewayEndpoint=G.gatewayEndpoint,this.region=G.region,this.status=G.status,this.disconnectedAt=G.disconnectedAt,this.displayName=G.displayName,this.registryBucketId=G.registryBucketId,this._http=A,this._scopes=new La(A),this._agents=new oZ(A),this._browse=new yt(A),this.memory=new Pa(this._http,this.id),this.connections=new Ka(this._http,this.id),this._access=new qa(this._http,this.id),this._gar=b.gar,this._signer=b.signer,this._userPubKey=b.signer?gB(Kb(b.signer.publicKey)):G.walletPubkey}scope(A){return new jd(this._http,this.id,A)}service(A){return new Md(this._http,this.id,A)}connectors(){return Yu(this._http)}isDisconnected(){return this.status==="disconnected"}};var rh=class extends Error{constructor(A){super(`Unsupported signature type "${A}": vault-api accepts only "ed25519" or "sr25519". Pass WalletAuthOptions.sigType to override.`),this.name="UnsupportedSignatureTypeError"}};function Gg(l){if(l==="ed25519"||l==="sr25519")return l;throw new rh(l)}var Ld=class{constructor(A,G={}){el(this,"signer");el(this,"opts");this.signer=A,this.opts=G}async authenticate(A){if(typeof this.signer?.sign!="function")throw new It;let G=this.opts.sigType??Gg(this.signer.type),b={"X-Public-Key":gB(Kb(this.signer.publicKey)),"X-Signature-Type":G},t=A.method.toUpperCase();if(A.hash!==void 0){let{bytes:e}=Qo(t,A.path,A.query,this.opts.clock,A.hash),d=await this.signer.sign(e,"data");return b["X-Signed-Preamble"]=De(e),b["X-Signature"]=Yt(Kb(d)),{headers:b}}if(t==="GET"||t==="HEAD"){let{bytes:e}=Qo(t,A.path,A.query,this.opts.clock),d=await this.signer.sign(e,"data");return b["X-Signed-Preamble"]=De(e),b["X-Signature"]=Yt(Kb(d)),{headers:b}}let{bytes:c}=F2(A.body,this.opts.clock),B=await this.signer.sign(c,"data");return b["Content-Type"]="application/json",b["X-Signature"]=Yt(Kb(B)),{headers:b,body:c}}};var sv=new bt,sZ=class{constructor(A){el(this,"http");this.http=A}async postAgreement(A){await this.http.send("POST","/api/v1/agreements",{body:A,auth:sv})}};var Od=class extends Error{constructor(A){super(A),this.name="OnboardingRequiredError"}};function Xu(l){return{publicKeyHex:`0x${Iu(l.publicKey)}`,keyType:Gg(l.type),async signRawHex(A){let G=await l.sign(A,"data");return Iu(G)}}}function Iu(l){let A="";for(let G=0;G<l.length;G++)A+=l[G].toString(16).padStart(2,"0");return A}async function pu(l){let A=await l.signRawHex(new Uint8Array(0)),G=A.startsWith("0x")?A.slice(2):A;return{"X-Public-Key":l.publicKeyHex,"X-Signature":G,"X-Signature-Type":l.keyType}}async function Ru(l,A,G=fetch){let b=l.replace(/\/+$/,"")+"/auth/onboarding/status",t=await G(b,{method:"GET",headers:await pu(A)});if(t.status===404)return null;if(!t.ok)throw new Error(`onboarding status ${t.status}`);return await t.json()}async function rv(l,A,G=fetch){let b=l.replace(/\/+$/,"")+"/auth/onboarding/bootstrap",t=await G(b,{method:"POST",headers:await pu(A)});if(t.status!==200&&t.status!==207)throw new Error(`onboarding bootstrap ${t.status}`);return await t.json()}async function Fu(l,A,G=fetch,b){let t=await Ru(l,A,G);if(t===null)return{kind:"skipped",status:null};if(t.gateway_is_proxy)return{kind:"ready",status:t};let c,B=t;if(t.faucet_eligible||t.ddc_seed_eligible){b?.(),c=await rv(l,A,G);let e=await Ru(l,A,G);e&&(B=e)}return B.gateway_is_proxy?{kind:"ready",status:B}:{kind:"awaiting-proxy",status:B,bootstrap:c}}var iv=new bt,Pd=class{constructor(A){el(this,"http");this.http=A}async delegate(){let A=await this.http.send("GET",kl.delegateInfo(),{auth:iv}),G=A.delegate_pubkey??A.delegatePubkey;if(!G)throw new Error(`vault-api /delegate-info response is missing delegate_pubkey: ${JSON.stringify(A)}`);return{delegatePubkey:G}}};var mh={PUT:1,GET:2,DELETE:3};function iZ(...l){let A=new Uint8Array(l.reduce((b,t)=>b+t.length,0)),G=0;for(let b of l)A.set(b,G),G+=b.length;return A}function bg(l){let A=BigInt(l);if(A<0n)throw new RangeError(`auth-token: negative varint ${l}`);let G=[];do{let b=Number(A&0x7fn);A>>=7n,A!==0n&&(b|=128),G.push(b)}while(A!==0n);return Uint8Array.from(G)}var yu=(l,A)=>bg(l<<3|A),rZ=(l,A)=>iZ(yu(l,2),bg(A.length),A),ih=(l,A)=>iZ(yu(l,0),bg(A));function mv(l){let A=[rZ(2,l.subject),ih(3,l.canDelegate?1:0)];return l.bucketId!==void 0&&A.push(ih(4,l.bucketId)),l.operations.length>0&&A.push(rZ(5,iZ(...l.operations.map(G=>bg(G))))),A.push(ih(6,l.expiresAt)),iZ(...A)}var Vv="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";function uv(l){let A=[0];for(let b of l){let t=b;for(let c=0;c<A.length;c++)t+=A[c]<<8,A[c]=t%58,t=Math.floor(t/58);for(;t>0;)A.push(t%58),t=Math.floor(t/58)}let G="";for(let b=0;b<l.length&&l[b]===0;b++)G+="1";for(let b=A.length-1;b>=0;b--)G+=Vv[A[b]];return G}async function Vh(l,A){if(l.type!=="ed25519")throw new Error(`auth-token: only ed25519 signers can mint a DDC AuthToken here (signer reports "${l.type}")`);let G=rZ(2,mv(A)),b=await l.sign(G,"token"),t=iZ(rZ(2,l.publicKey),rZ(3,b));return uv(iZ(rZ(1,t),G))}var Yv=24*60*60*1e3,uh=365*Yv,Nu=uh-60*60*1e3,{GET:Eu,PUT:vu,DELETE:Iv}=mh,Hu=[Eu,vu,Iv],Ju=[Eu,vu],Rv=(1n<<64n)-1n,Xv=(1n<<63n)-1n;function Qu(l,A,G){let b;if(typeof A=="bigint")b=A;else if(/^[0-9]+$/.test(A))b=BigInt(A);else throw new Error(`${l} must be a decimal chain bucket id, got "${A}"`);if(b<=0n||b>G)throw new Error(`${l} ${b} is out of range: a chain bucket id is 1..${G}`);return b}function pv(l){let A=l.replace(/^0x/i,"");if(!/^[0-9a-fA-F]{64}$/.test(A))throw new Error(`delegatePubkey must be a 32-byte hex key, got "${l}"`);return Te(A)}async function Yh(l){let A=Qu("vaultBucketId",l.vaultBucketId,Rv),G=Qu("registryBucketId",l.registryBucketId,Xv);if(A===G)throw new Error(`vaultBucketId and registryBucketId are the same bucket (${A}): the vault bucket is private because it holds memory and the registry bucket is public because agent code is read anonymously`);let b=pv(l.delegatePubkey),t=(l.now??Date.now)(),c=l.expiresAt===void 0?t+Nu:l.expiresAt instanceof Date?l.expiresAt.getTime():l.expiresAt;if(!Number.isSafeInteger(c)||c<=t)throw new Error(`expiresAt must be in the future, got ${new Date(c).toISOString()}`);if(c>t+uh)throw new Error(`expiresAt ${new Date(c).toISOString()} is more than one year away; vault-api refuses delegations beyond that`);if(l.signer.type!=="ed25519")throw new Error(`delegation tokens need an ed25519 owner wallet (signer reports "${l.signer.type}")`);let B=await Vh(l.signer,{subject:b,canDelegate:!0,bucketId:A,operations:Hu,expiresAt:c}),e=await Vh(l.signer,{subject:b,canDelegate:!0,bucketId:G,operations:Ju,expiresAt:c});return{vaultDelegationToken:B,registryDelegationToken:e,expiresAt:new Date(c)}}var xH="https://ddc-s3-gateway.compute.dev.ddcdragon.com/auth/info",fH="https://agent-marketplace.compute.dev.ddcdragon.com",kH=3,wH=[2e3,5e3];function UH(l){return l.status===425||l.status===503&&l.retryable===!0}var _Z=class{constructor(A){el(this,"http");el(this,"marketplaceHttp");el(this,"endpoint");el(this,"chainUrl");el(this,"vaults");el(this,"gar");el(this,"signer");el(this,"s3GatewayAuthInfoUrl");el(this,"fetchFn");el(this,"marketplace");el(this,"health");el(this,"memberships");el(this,"vault",{ensure:async(A={})=>{let G=A.onProgress??(()=>{});if(A.onboard!==!1&&this.signer){let B=Xu(this.signer),e=this.gatewayBaseUrl();G({kind:"inspecting-wallet"});let d=await Fu(e,B,this.fetchFn,()=>{G({kind:"funding-wallet"})});if(d.kind==="awaiting-proxy")throw G({kind:"gateway-authorization-required",status:d.status}),new Od("Onboarding required: the gateway does not yet see this wallet's on-chain proxy authorization. Register it externally via `@cef-ai/account`'s `provisioning.ensure({ signer, chainUrl, gateway })`, wait for it to resolve, then retry `vault.ensure()`.")}let t=A.delegationToken;if(!t){if(!this.signer)throw new Error("vault.ensure() needs either a `delegationToken` or a `signer` configured on VaultSDKConfig (the signer drives the on-chain vault-delegate grant).");let B=A.chainUrl??this.chainUrl;if(!B)throw new Error("vault.ensure(): `chainUrl` is required on the wallet path \u2014 the SDK grants vault-api write delegation by submitting an on-chain NonTransfer proxy (`@cef-ai/account`'s `ensureVaultDelegate`) before claiming the vault. Set `chainUrl` on VaultSDKConfig (or pass it per call) with a Cere node WS URL, or pass `delegationToken` to use the legacy token-bearing claim instead.");G({kind:"authorizing-vault"});let{ensureVaultDelegate:e}=await Promise.resolve().then(()=>(SF(),CF));await e({signer:this.signer,chainUrl:B,vaultApiUrl:this.endpoint,fetchFn:this.fetchFn})}G({kind:"provisioning-vault"});let c=await this.claimVaultWithRetry({name:A.name,label:"vault",...t?{delegation_token:t}:{}},A.sleep);return new fc(this.http,c,{gar:this.gar,signer:this.signer})},current:async()=>{let A=await this.vaults.current();return new fc(this.http,A,{gar:this.gar,signer:this.signer})},byId:async A=>{let G=await this.vaults.byId(A);return new fc(this.http,G,{gar:this.gar,signer:this.signer})},rename:async(A,G)=>{let b=await this.vaults.patch(A,{displayName:G,timestamp:new Date().toISOString()});return new fc(this.http,b,{gar:this.gar,signer:this.signer})},delegations:{put:async(A,G)=>{let b=await this.vaults.putDelegations(A,{vaultDelegationToken:G.vaultDelegationToken,registryDelegationToken:G.registryDelegationToken,timestamp:new Date().toISOString()}),{vaultBucketId:t,registryBucketId:c,delegationsExpireAt:B,...e}=b;return{vault:new fc(this.http,{...e,registryBucketId:c},{gar:this.gar,signer:this.signer}),vaultBucketId:t,registryBucketId:c,delegationsExpireAt:B}},grant:async(A,G)=>{if(!this.signer)throw new It;let{delegatePubkey:b}=await new Pd(this.http).delegate(),t=await Yh({signer:this.signer,delegatePubkey:b,vaultBucketId:G.vaultBucketId,registryBucketId:G.registryBucketId,expiresAt:G.expiresAt});return this.vault.delegations.put(A,t)}}});let G=A.auth??(A.signer?new Ld(A.signer):void 0);this.endpoint=A.endpoint,this.chainUrl=A.chainUrl,this.http=new Le({url:A.endpoint,auth:G,fetch:A.fetch,timeoutMs:A.timeoutMs}),this.marketplaceHttp=new Le({url:A.marketplaceEndpoint??fH,fetch:A.fetch,timeoutMs:A.timeoutMs}),A.garEndpoint&&(this.gar=new sZ(new Le({url:A.garEndpoint,fetch:A.fetch,timeoutMs:A.timeoutMs}))),this.signer=A.signer,this.s3GatewayAuthInfoUrl=A.s3GatewayAuthInfoUrl??xH,this.fetchFn=A.fetch??fetch.bind(globalThis),this.vaults=new ha(this.http),this.marketplace=new Ta(this.marketplaceHttp),this.health=new Da(this.http),this.memberships=new Ma(this.http,A.signer)}gatewayBaseUrl(){return this.s3GatewayAuthInfoUrl.replace(/\/+$/,"").replace(/\/auth\/info$/,"")}async claimVaultWithRetry(A,G){let b=G??(t=>new Promise(c=>setTimeout(c,t)));for(let t=1;;t++)try{return await this.vaults.claim(A)}catch(c){if(t>=kH||!(c instanceof _G)||!UH(c))throw c;await b(wH[t-1])}}};function zF(){return nu().then(()=>{if(!TA())throw new Error("Unable to initialize @polkadot/util-crypto");return!0}).catch(()=>!1)}function Ri(l){return l instanceof Uint8Array||ArrayBuffer.isView(l)&&l.constructor.name==="Uint8Array"}function CH(l,...A){if(!Ri(l))throw new Error("Uint8Array expected");if(A.length>0&&!A.includes(l.length))throw new Error("Uint8Array expected of length "+A+", got length="+l.length)}function TF(l,A){return Array.isArray(A)?A.length===0?!0:l?A.every(G=>typeof G=="string"):A.every(G=>Number.isSafeInteger(G)):!1}function xn(l,A){if(typeof A!="string")throw new Error(`${l}: string expected`);return!0}function fn(l){if(!Number.isSafeInteger(l))throw new Error(`invalid integer: ${l}`)}function xW(l){if(!Array.isArray(l))throw new Error("array expected")}function fW(l,A){if(!TF(!0,A))throw new Error(`${l}: array of strings expected`)}function DF(l,A){if(!TF(!1,A))throw new Error(`${l}: array of numbers expected`)}function LF(...l){let A=c=>c,G=(c,B)=>e=>c(B(e)),b=l.map(c=>c.encode).reduceRight(G,A),t=l.map(c=>c.decode).reduce(G,A);return{encode:b,decode:t}}function OF(l){let A=typeof l=="string"?l.split(""):l,G=A.length;fW("alphabet",A);let b=new Map(A.map((t,c)=>[t,c]));return{encode:t=>(xW(t),t.map(c=>{if(!Number.isSafeInteger(c)||c<0||c>=G)throw new Error(`alphabet.encode: digit index outside alphabet "${c}". Allowed: ${l}`);return A[c]})),decode:t=>(xW(t),t.map(c=>{xn("alphabet.decode",c);let B=b.get(c);if(B===void 0)throw new Error(`Unknown letter: "${c}". Allowed: ${l}`);return B}))}}function PF(l=""){return xn("join",l),{encode:A=>(fW("join.decode",A),A.join(l)),decode:A=>(xn("join.decode",A),A.split(l))}}function SH(l,A="="){return fn(l),xn("padding",A),{encode(G){for(fW("padding.encode",G);G.length*l%8;)G.push(A);return G},decode(G){fW("padding.decode",G);let b=G.length;if(b*l%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;b>0&&G[b-1]===A;b--)if((b-1)*l%8===0)throw new Error("padding: invalid, string has too much padding");return G.slice(0,b)}}}function jF(l,A,G){if(A<2)throw new Error(`convertRadix: invalid from=${A}, base cannot be less than 2`);if(G<2)throw new Error(`convertRadix: invalid to=${G}, base cannot be less than 2`);if(xW(l),!l.length)return[];let b=0,t=[],c=Array.from(l,e=>{if(fn(e),e<0||e>=A)throw new Error(`invalid integer: ${e}`);return e}),B=c.length;for(;;){let e=0,d=!0;for(let Z=b;Z<B;Z++){let g=c[Z],n=A*e,h=n+g;if(!Number.isSafeInteger(h)||n/A!==e||h-g!==n)throw new Error("convertRadix: carry overflow");let W=h/G;e=h%G;let m=Math.floor(W);if(c[Z]=m,!Number.isSafeInteger(m)||m*G+e!==h)throw new Error("convertRadix: carry overflow");if(d)m?d=!1:b=Z;else continue}if(t.push(e),d)break}for(let e=0;e<l.length-1&&l[e]===0;e++)t.push(0);return t.reverse()}var KF=(l,A)=>A===0?l:KF(A,l%A),kW=(l,A)=>l+(A-KF(l,A)),Ii=(()=>{let l=[];for(let A=0;A<40;A++)l.push(2**A);return l})();function MF(l,A,G,b){if(xW(l),A<=0||A>32)throw new Error(`convertRadix2: wrong from=${A}`);if(G<=0||G>32)throw new Error(`convertRadix2: wrong to=${G}`);if(kW(A,G)>32)throw new Error(`convertRadix2: carry overflow from=${A} to=${G} carryBits=${kW(A,G)}`);let t=0,c=0,B=Ii[A],e=Ii[G]-1,d=[];for(let Z of l){if(fn(Z),Z>=B)throw new Error(`convertRadix2: invalid data word=${Z} from=${A}`);if(t=t<<A|Z,c+A>32)throw new Error(`convertRadix2: carry overflow pos=${c} from=${A}`);for(c+=A;c>=G;c-=G)d.push((t>>c-G&e)>>>0);let g=Ii[c];if(g===void 0)throw new Error("invalid carry");t&=g-1}if(t=t<<G-c&e,!b&&c>=A)throw new Error("Excess padding");if(!b&&t>0)throw new Error(`Non-zero padding: ${t}`);return b&&c>0&&d.push(t>>>0),d}function zH(l){fn(l);let A=2**8;return{encode:G=>{if(!Ri(G))throw new Error("radix.encode input should be Uint8Array");return jF(Array.from(G),A,l)},decode:G=>(DF("radix.decode",G),Uint8Array.from(jF(G,l,A)))}}function jH(l,A=!1){if(fn(l),l<=0||l>32)throw new Error("radix2: bits should be in (0..32]");if(kW(8,l)>32||kW(l,8)>32)throw new Error("radix2: carry overflow");return{encode:G=>{if(!Ri(G))throw new Error("radix2.encode input should be Uint8Array");return MF(Array.from(G),8,l,!A)},decode:G=>(DF("radix2.decode",G),Uint8Array.from(MF(G,l,8,A)))}}var MH=typeof Uint8Array.from([]).toBase64=="function"&&typeof Uint8Array.fromBase64=="function",TH=(l,A)=>{xn("base64",l);let G=A?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,b=A?"base64url":"base64";if(l.length>0&&!G.test(l))throw new Error("invalid base64");return Uint8Array.fromBase64(l,{alphabet:b,lastChunkHandling:"strict"})},qF=MH?{encode(l){return CH(l),l.toBase64()},decode(l){return TH(l,!1)}}:LF(jH(6),OF("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),SH(6),PF(""));var DH=l=>LF(zH(58),OF(l),PF("")),_F=DH("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");function wW({coder:l,ipfs:A},G){return(b,t)=>(G(b,t),l.decode(A&&t?b.substring(1):b))}function UW({coder:l,ipfs:A}){return(G,b)=>{let t=l.encode(Tl(G));return A&&b?`${A}${t}`:t}}function CW({chars:l,ipfs:A,type:G,withPadding:b}){return(t,c)=>{if(typeof t!="string")throw new Error(`Expected ${G} string input`);if(A&&c&&!t.startsWith(A))throw new Error(`Expected ipfs-compatible ${G} to start with '${A}'`);for(let B=c?1:0,e=t.length;B<e;B++)if(!l.includes(t[B]))if(b&&t[B]==="="){if(B!==e-1){if(t[B+1]!=="=")throw new Error(`Invalid ${G} padding sequence "${t[B]}${t[B+1]}" at index ${B}`)}}else throw new Error(`Invalid ${G} character "${t[B]}" (0x${t.charCodeAt(B).toString(16)}) at index ${B}`);return!0}}var Xi={chars:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",coder:_F,ipfs:"z",type:"base58"},$F=CW(Xi),pi=wW(Xi,$F),Fi=UW(Xi);var OH=uG("SS58PRE");function SW(l){return Mb(nG(OH,l),512)}function ly(l){let A=l[0]&64?2:1,G=A===1?l[0]:(l[0]&63)<<2|l[1]>>6|(l[1]&63)<<8,b=[34+A,35+A].includes(l.length),t=l.length-(b?2:1),c=SW(l.subarray(0,t));return[(l[0]&128)===0&&![46,47].includes(l[0])&&(b?l[l.length-2]===c[0]&&l[l.length-1]===c[1]:l[l.length-1]===c[0]),t,A,G]}var Ay=[{prefix:0,network:"polkadot",displayName:"Polkadot Relay Chain",symbols:["DOT"],decimals:[10],standardAccount:"*25519",website:"https://polkadot.network"},{prefix:1,network:"BareSr25519",displayName:"Bare 32-bit Schnorr/Ristretto (S/R 25519) public key.",symbols:[],decimals:[],standardAccount:"Sr25519",website:null},{prefix:2,network:"kusama",displayName:"Kusama Relay Chain",symbols:["KSM"],decimals:[12],standardAccount:"*25519",website:"https://kusama.network"},{prefix:3,network:"BareEd25519",displayName:"Bare 32-bit Ed25519 public key.",symbols:[],decimals:[],standardAccount:"Ed25519",website:null},{prefix:4,network:"katalchain",displayName:"Katal Chain",symbols:[],decimals:[],standardAccount:"*25519",website:null},{prefix:5,network:"astar",displayName:"Astar Network",symbols:["ASTR"],decimals:[18],standardAccount:"*25519",website:"https://astar.network"},{prefix:6,network:"bifrost",displayName:"Bifrost",symbols:["BNC"],decimals:[12],standardAccount:"*25519",website:"https://bifrost.finance/"},{prefix:7,network:"edgeware",displayName:"Edgeware",symbols:["EDG"],decimals:[18],standardAccount:"*25519",website:"https://edgewa.re"},{prefix:8,network:"karura",displayName:"Karura",symbols:["KAR"],decimals:[12],standardAccount:"*25519",website:"https://karura.network/"},{prefix:9,network:"reynolds",displayName:"Laminar Reynolds Canary",symbols:["REY"],decimals:[18],standardAccount:"*25519",website:"http://laminar.network/"},{prefix:10,network:"acala",displayName:"Acala",symbols:["ACA"],decimals:[12],standardAccount:"*25519",website:"https://acala.network/"},{prefix:11,network:"laminar",displayName:"Laminar",symbols:["LAMI"],decimals:[18],standardAccount:"*25519",website:"http://laminar.network/"},{prefix:12,network:"polymesh",displayName:"Polymesh",symbols:["POLYX"],decimals:[6],standardAccount:"*25519",website:"https://polymath.network/"},{prefix:13,network:"integritee",displayName:"Integritee",symbols:["TEER"],decimals:[12],standardAccount:"*25519",website:"https://integritee.network"},{prefix:14,network:"totem",displayName:"Totem",symbols:["TOTEM"],decimals:[0],standardAccount:"*25519",website:"https://totemaccounting.com"},{prefix:15,network:"synesthesia",displayName:"Synesthesia",symbols:["SYN"],decimals:[12],standardAccount:"*25519",website:"https://synesthesia.network/"},{prefix:16,network:"kulupu",displayName:"Kulupu",symbols:["KLP"],decimals:[12],standardAccount:"*25519",website:"https://kulupu.network/"},{prefix:17,network:"dark",displayName:"Dark Mainnet",symbols:[],decimals:[],standardAccount:"*25519",website:null},{prefix:18,network:"darwinia",displayName:"Darwinia Network",symbols:["RING"],decimals:[18],standardAccount:"secp256k1",website:"https://darwinia.network"},{prefix:19,network:"watr",displayName:"Watr Protocol",symbols:["WATR"],decimals:[18],standardAccount:"*25519",website:"https://www.watr.org"},{prefix:20,network:"stafi",displayName:"Stafi",symbols:["FIS"],decimals:[12],standardAccount:"*25519",website:"https://stafi.io"},{prefix:21,network:"karmachain",displayName:"Karmacoin",symbols:["KCOIN"],decimals:[6],standardAccount:"*25519",website:"https://karmaco.in"},{prefix:22,network:"dock-pos-mainnet",displayName:"Dock Mainnet",symbols:["DCK"],decimals:[6],standardAccount:"*25519",website:"https://dock.io"},{prefix:23,network:"shift",displayName:"ShiftNrg",symbols:[],decimals:[],standardAccount:"*25519",website:null},{prefix:24,network:"zero",displayName:"ZERO",symbols:["ZERO"],decimals:[18],standardAccount:"*25519",website:"https://zero.io"},{prefix:25,network:"zero-alphaville",displayName:"ZERO Alphaville",symbols:["ZERO"],decimals:[18],standardAccount:"*25519",website:"https://zero.io"},{prefix:26,network:"jupiter",displayName:"Jupiter",symbols:["jDOT"],decimals:[10],standardAccount:"*25519",website:"https://jupiter.patract.io"},{prefix:27,network:"kabocha",displayName:"Kabocha",symbols:["KAB"],decimals:[12],standardAccount:"*25519",website:"https://kabocha.network"},{prefix:28,network:"subsocial",displayName:"Subsocial",symbols:[],decimals:[],standardAccount:"*25519",website:null},{prefix:29,network:"cord",displayName:"CORD Network",symbols:["DHI","WAY"],decimals:[12,12],standardAccount:"*25519",website:"https://cord.network/"},{prefix:30,network:"phala",displayName:"Phala Network",symbols:["PHA"],decimals:[12],standardAccount:"*25519",website:"https://phala.network"},{prefix:31,network:"litentry",displayName:"Litentry Network",symbols:["LIT"],decimals:[12],standardAccount:"*25519",website:"https://litentry.com/"},{prefix:32,network:"robonomics",displayName:"Robonomics",symbols:["XRT"],decimals:[9],standardAccount:"*25519",website:"https://robonomics.network"},{prefix:33,network:"datahighway",displayName:"DataHighway",symbols:[],decimals:[],standardAccount:"*25519",website:null},{prefix:34,network:"ares",displayName:"Ares Protocol",symbols:["ARES"],decimals:[12],standardAccount:"*25519",website:"https://www.aresprotocol.com/"},{prefix:35,network:"vln",displayName:"Valiu Liquidity Network",symbols:["USDv"],decimals:[15],standardAccount:"*25519",website:"https://valiu.com/"},{prefix:36,network:"centrifuge",displayName:"Centrifuge Chain",symbols:["CFG"],decimals:[18],standardAccount:"*25519",website:"https://centrifuge.io/"},{prefix:37,network:"nodle",displayName:"Nodle Chain",symbols:["NODL"],decimals:[11],standardAccount:"*25519",website:"https://nodle.io/"},{prefix:38,network:"kilt",displayName:"KILT Spiritnet",symbols:["KILT"],decimals:[15],standardAccount:"*25519",website:"https://kilt.io/"},{prefix:39,network:"mathchain",displayName:"MathChain mainnet",symbols:["MATH"],decimals:[18],standardAccount:"*25519",website:"https://mathwallet.org"},{prefix:40,network:"mathchain-testnet",displayName:"MathChain testnet",symbols:["MATH"],decimals:[18],standardAccount:"*25519",website:"https://mathwallet.org"},{prefix:41,network:"polimec",displayName:"Polimec Protocol",symbols:["PLMC"],decimals:[10],standardAccount:"*25519",website:"https://www.polimec.org/"},{prefix:42,network:"substrate",displayName:"Substrate",symbols:[],decimals:[],standardAccount:"*25519",website:"https://substrate.io/"},{prefix:43,network:"BareSecp256k1",displayName:"Bare 32-bit ECDSA SECP-256k1 public key.",symbols:[],decimals:[],standardAccount:"secp256k1",website:null},{prefix:44,network:"chainx",displayName:"ChainX",symbols:["PCX"],decimals:[8],standardAccount:"*25519",website:"https://chainx.org/"},{prefix:45,network:"uniarts",displayName:"UniArts Network",symbols:["UART","UINK"],decimals:[12,12],standardAccount:"*25519",website:"https://uniarts.me"},{prefix:46,network:"reserved46",displayName:"This prefix is reserved.",symbols:[],decimals:[],standardAccount:null,website:null},{prefix:47,network:"reserved47",displayName:"This prefix is reserved.",symbols:[],decimals:[],standardAccount:null,website:null},{prefix:48,network:"neatcoin",displayName:"Neatcoin Mainnet",symbols:["NEAT"],decimals:[12],standardAccount:"*25519",website:"https://neatcoin.org"},{prefix:49,network:"picasso",displayName:"Picasso",symbols:["PICA"],decimals:[12],standardAccount:"*25519",website:"https://picasso.composable.finance"},{prefix:50,network:"composable",displayName:"Composable Finance",symbols:["LAYR"],decimals:[12],standardAccount:"*25519",website:"https://composable.finance"},{prefix:51,network:"oak",displayName:"OAK Network",symbols:["OAK","TUR"],decimals:[10,10],standardAccount:"*25519",website:"https://oak.tech"},{prefix:52,network:"KICO",displayName:"KICO",symbols:["KICO"],decimals:[14],standardAccount:"*25519",website:"https://dico.io"},{prefix:53,network:"DICO",displayName:"DICO",symbols:["DICO"],decimals:[14],standardAccount:"*25519",website:"https://dico.io"},{prefix:54,network:"cere",displayName:"Cere Network",symbols:["CERE"],decimals:[10],standardAccount:"*25519",website:"https://cere.network"},{prefix:55,network:"xxnetwork",displayName:"xx network",symbols:["XX"],decimals:[9],standardAccount:"*25519",website:"https://xx.network"},{prefix:56,network:"pendulum",displayName:"Pendulum chain",symbols:["PEN"],decimals:[12],standardAccount:"*25519",website:"https://pendulumchain.org/"},{prefix:57,network:"amplitude",displayName:"Amplitude chain",symbols:["AMPE"],decimals:[12],standardAccount:"*25519",website:"https://pendulumchain.org/"},{prefix:58,network:"eternal-civilization",displayName:"Eternal Civilization",symbols:["ECC"],decimals:[12],standardAccount:"*25519",website:"http://www.ysknfr.cn/"},{prefix:63,network:"hydradx",displayName:"Hydration",symbols:["HDX"],decimals:[12],standardAccount:"*25519",website:"https://hydration.net"},{prefix:65,network:"aventus",displayName:"Aventus Mainnet",symbols:["AVT"],decimals:[18],standardAccount:"*25519",website:"https://aventus.io"},{prefix:66,network:"crust",displayName:"Crust Network",symbols:["CRU"],decimals:[12],standardAccount:"*25519",website:"https://crust.network"},{prefix:67,network:"genshiro",displayName:"Genshiro Network",symbols:["GENS","EQD","LPT0"],decimals:[9,9,9],standardAccount:"*25519",website:"https://genshiro.equilibrium.io"},{prefix:68,network:"equilibrium",displayName:"Equilibrium Network",symbols:["EQ"],decimals:[9],standardAccount:"*25519",website:"https://equilibrium.io"},{prefix:69,network:"sora",displayName:"SORA Network",symbols:["XOR"],decimals:[18],standardAccount:"*25519",website:"https://sora.org"},{prefix:71,network:"p3d",displayName:"3DP network",symbols:["P3D"],decimals:[12],standardAccount:"*25519",website:"https://3dpass.org"},{prefix:72,network:"p3dt",displayName:"3DP test network",symbols:["P3Dt"],decimals:[12],standardAccount:"*25519",website:"https://3dpass.org"},{prefix:73,network:"zeitgeist",displayName:"Zeitgeist",symbols:["ZTG"],decimals:[10],standardAccount:"*25519",website:"https://zeitgeist.pm"},{prefix:77,network:"manta",displayName:"Manta network",symbols:["MANTA"],decimals:[18],standardAccount:"*25519",website:"https://manta.network"},{prefix:78,network:"calamari",displayName:"Calamari: Manta Canary Network",symbols:["KMA"],decimals:[12],standardAccount:"*25519",website:"https://manta.network"},{prefix:81,network:"sora_dot_para",displayName:"SORA Polkadot Parachain",symbols:["XOR"],decimals:[18],standardAccount:"*25519",website:"https://sora.org"},{prefix:88,network:"polkadex",displayName:"Polkadex Mainnet",symbols:["PDEX"],decimals:[12],standardAccount:"*25519",website:"https://polkadex.trade"},{prefix:89,network:"polkadexparachain",displayName:"Polkadex Parachain",symbols:["PDEX"],decimals:[12],standardAccount:"*25519",website:"https://polkadex.trade"},{prefix:90,network:"frequency",displayName:"Frequency",symbols:["FRQCY"],decimals:[8],standardAccount:"*25519",website:"https://www.frequency.xyz"},{prefix:92,network:"anmol",displayName:"Anmol Network",symbols:["ANML"],decimals:[18],standardAccount:"*25519",website:"https://anmol.network/"},{prefix:93,network:"fragnova",displayName:"Fragnova Network",symbols:["NOVA"],decimals:[12],standardAccount:"*25519",website:"https://fragnova.com"},{prefix:98,network:"polkasmith",displayName:"PolkaSmith Canary Network",symbols:["PKS"],decimals:[18],standardAccount:"*25519",website:"https://polkafoundry.com"},{prefix:99,network:"polkafoundry",displayName:"PolkaFoundry Network",symbols:["PKF"],decimals:[18],standardAccount:"*25519",website:"https://polkafoundry.com"},{prefix:100,network:"ibtida",displayName:"Anmol Network Ibtida Canary network",symbols:["IANML"],decimals:[18],standardAccount:"*25519",website:"https://anmol.network/"},{prefix:101,network:"origintrail-parachain",displayName:"OriginTrail Parachain",symbols:["OTP"],decimals:[12],standardAccount:"*25519",website:"https://parachain.origintrail.io/"},{prefix:105,network:"pontem-network",displayName:"Pontem Network",symbols:["PONT"],decimals:[10],standardAccount:"*25519",website:"https://pontem.network"},{prefix:110,network:"heiko",displayName:"Heiko",symbols:["HKO"],decimals:[12],standardAccount:"*25519",website:"https://parallel.fi/"},{prefix:113,network:"integritee-incognito",displayName:"Integritee Incognito",symbols:[],decimals:[],standardAccount:"*25519",website:"https://integritee.network"},{prefix:117,network:"tinker",displayName:"Tinker",symbols:["TNKR"],decimals:[12],standardAccount:"*25519",website:"https://invarch.network"},{prefix:126,network:"joystream",displayName:"Joystream",symbols:["JOY"],decimals:[10],standardAccount:"*25519",website:"https://www.joystream.org"},{prefix:128,network:"clover",displayName:"Clover Finance",symbols:["CLV"],decimals:[18],standardAccount:"*25519",website:"https://clover.finance"},{prefix:129,network:"dorafactory-polkadot",displayName:"Dorafactory Polkadot Network",symbols:["DORA"],decimals:[12],standardAccount:"*25519",website:"https://dorafactory.org"},{prefix:131,network:"litmus",displayName:"Litmus Network",symbols:["LIT"],decimals:[12],standardAccount:"*25519",website:"https://litentry.com/"},{prefix:136,network:"altair",displayName:"Altair",symbols:["AIR"],decimals:[18],standardAccount:"*25519",website:"https://centrifuge.io/"},{prefix:137,network:"vara",displayName:"Vara Network",symbols:["VARA"],decimals:[12],standardAccount:"*25519",website:"https://vara.network/"},{prefix:172,network:"parallel",displayName:"Parallel",symbols:["PARA"],decimals:[12],standardAccount:"*25519",website:"https://parallel.fi/"},{prefix:252,network:"social-network",displayName:"Social Network",symbols:["NET"],decimals:[18],standardAccount:"*25519",website:"https://social.network"},{prefix:255,network:"quartz_mainnet",displayName:"QUARTZ by UNIQUE",symbols:["QTZ"],decimals:[18],standardAccount:"*25519",website:"https://unique.network"},{prefix:268,network:"pioneer_network",displayName:"Pioneer Network by Bit.Country",symbols:["NEER"],decimals:[18],standardAccount:"*25519",website:"https://bit.country"},{prefix:420,network:"sora_kusama_para",displayName:"SORA Kusama Parachain",symbols:["XOR"],decimals:[18],standardAccount:"*25519",website:"https://sora.org"},{prefix:440,network:"allfeat_network",displayName:"Allfeat Network",symbols:["AFT"],decimals:[12],standardAccount:"*25519",website:"https://allfeat.network"},{prefix:666,network:"metaquity_network",displayName:"Metaquity Network",symbols:["MQTY"],decimals:[18],standardAccount:"*25519",website:"https://metaquity.xyz/"},{prefix:777,network:"curio",displayName:"Curio",symbols:["CGT"],decimals:[18],standardAccount:"*25519",website:"https://parachain.capitaldex.exchange/"},{prefix:789,network:"geek",displayName:"GEEK Network",symbols:["GEEK"],decimals:[18],standardAccount:"*25519",website:"https://geek.gl"},{prefix:995,network:"ternoa",displayName:"Ternoa",symbols:["CAPS"],decimals:[18],standardAccount:"*25519",website:"https://www.ternoa.network"},{prefix:1110,network:"efinity",displayName:"Efinity",symbols:["EFI"],decimals:[18],standardAccount:"*25519",website:"https://efinity.io/"},{prefix:1221,network:"peaq",displayName:"Peaq Network",symbols:["PEAQ"],decimals:[18],standardAccount:"Sr25519",website:"https://www.peaq.network/"},{prefix:1222,network:"krest",displayName:"Krest Network",symbols:["KREST"],decimals:[18],standardAccount:"Sr25519",website:"https://www.peaq.network/"},{prefix:1284,network:"moonbeam",displayName:"Moonbeam",symbols:["GLMR"],decimals:[18],standardAccount:"secp256k1",website:"https://moonbeam.network"},{prefix:1285,network:"moonriver",displayName:"Moonriver",symbols:["MOVR"],decimals:[18],standardAccount:"secp256k1",website:"https://moonbeam.network"},{prefix:1328,network:"ajuna",displayName:"Ajuna Network",symbols:["AJUN"],decimals:[12],standardAccount:"*25519",website:"https://ajuna.io"},{prefix:1337,network:"bajun",displayName:"Bajun Network",symbols:["BAJU"],decimals:[12],standardAccount:"*25519",website:"https://ajuna.io"},{prefix:1516,network:"societal",displayName:"Societal",symbols:["SCTL"],decimals:[12],standardAccount:"*25519",website:"https://www.sctl.xyz"},{prefix:1985,network:"seals",displayName:"Seals Network",symbols:["SEAL"],decimals:[9],standardAccount:"*25519",website:"https://seals.app"},{prefix:2007,network:"kapex",displayName:"Kapex",symbols:["KAPEX"],decimals:[12],standardAccount:"*25519",website:"https://totemaccounting.com"},{prefix:2009,network:"cloudwalk_mainnet",displayName:"CloudWalk Network Mainnet",symbols:["CWN"],decimals:[18],standardAccount:"*25519",website:"https://explorer.mainnet.cloudwalk.io"},{prefix:2021,network:"logion",displayName:"logion network",symbols:["LGNT"],decimals:[18],standardAccount:"*25519",website:"https://logion.network"},{prefix:2024,network:"vow-chain",displayName:"Enigmatic Smile",symbols:["VOW"],decimals:[18],standardAccount:"*25519",website:"https://www.vow.foundation/"},{prefix:2032,network:"interlay",displayName:"Interlay",symbols:["INTR"],decimals:[10],standardAccount:"*25519",website:"https://interlay.io/"},{prefix:2092,network:"kintsugi",displayName:"Kintsugi",symbols:["KINT"],decimals:[12],standardAccount:"*25519",website:"https://interlay.io/"},{prefix:2106,network:"bitgreen",displayName:"Bitgreen",symbols:["BBB"],decimals:[18],standardAccount:"*25519",website:"https://bitgreen.org/"},{prefix:2112,network:"chainflip",displayName:"Chainflip",symbols:["FLIP"],decimals:[18],standardAccount:"*25519",website:"https://chainflip.io/"},{prefix:2199,network:"moonsama",displayName:"Moonsama",symbols:["SAMA"],decimals:[18],standardAccount:"secp256k1",website:"https://moonsama.com"},{prefix:2206,network:"ICE",displayName:"ICE Network",symbols:["ICY"],decimals:[18],standardAccount:"*25519",website:"https://icenetwork.io"},{prefix:2207,network:"SNOW",displayName:"SNOW: ICE Canary Network",symbols:["ICZ"],decimals:[18],standardAccount:"*25519",website:"https://icenetwork.io"},{prefix:2254,network:"subspace_testnet",displayName:"Subspace testnet",symbols:["tSSC"],decimals:[18],standardAccount:"*25519",website:"https://subspace.network"},{prefix:3333,network:"peerplays",displayName:"Peerplays",symbols:["PPY"],decimals:[18],standardAccount:"secp256k1",website:"https://www.peerplays.com/"},{prefix:4450,network:"g1",displayName:"\u011E1",symbols:["G1"],decimals:[2],standardAccount:"*25519",website:"https://duniter.org"},{prefix:5234,network:"humanode",displayName:"Humanode Network",symbols:["HMND"],decimals:[18],standardAccount:"*25519",website:"https://humanode.io"},{prefix:5845,network:"tangle",displayName:"Tangle Network",symbols:["TNT"],decimals:[18],standardAccount:"*25519",website:"https://www.tangle.tools/"},{prefix:6094,network:"autonomys",displayName:"Autonomys",symbols:["AI3"],decimals:[18],standardAccount:"*25519",website:"https://autonomys.xyz"},{prefix:7007,network:"tidefi",displayName:"Tidefi",symbols:["TDFY"],decimals:[12],standardAccount:"*25519",website:"https://tidefi.com"},{prefix:7013,network:"gm",displayName:"GM",symbols:["FREN","GM","GN"],decimals:[12,0,0],standardAccount:"*25519",website:"https://gmordie.com"},{prefix:7306,network:"krigan",displayName:"Krigan Network",symbols:["KRGN"],decimals:[9],standardAccount:"*25519",website:"https://krigan.network"},{prefix:7391,network:"unique_mainnet",displayName:"Unique Network",symbols:["UNQ"],decimals:[18],standardAccount:"*25519",website:"https://unique.network"},{prefix:8866,network:"golden_gate",displayName:"Golden Gate",symbols:["GGX"],decimals:[18],standardAccount:"*25519",website:"https://ggxchain.io/"},{prefix:8883,network:"sapphire_mainnet",displayName:"Sapphire by Unique",symbols:["QTZ"],decimals:[18],standardAccount:"*25519",website:"https://unique.network"},{prefix:8886,network:"golden_gate_sydney",displayName:"Golden Gate Sydney",symbols:["GGXT"],decimals:[18],standardAccount:"*25519",website:"https://ggxchain.io/"},{prefix:9072,network:"hashed",displayName:"Hashed Network",symbols:["HASH"],decimals:[18],standardAccount:"*25519",website:"https://hashed.network"},{prefix:9807,network:"dentnet",displayName:"DENTNet",symbols:["DENTX"],decimals:[18],standardAccount:"*25519",website:"https://www.dentnet.io"},{prefix:9935,network:"t3rn",displayName:"t3rn",symbols:["TRN"],decimals:[12],standardAccount:"*25519",website:"https://t3rn.io/"},{prefix:10041,network:"basilisk",displayName:"Basilisk",symbols:["BSX"],decimals:[12],standardAccount:"*25519",website:"https://bsx.fi"},{prefix:11330,network:"cess-testnet",displayName:"CESS Testnet",symbols:["TCESS"],decimals:[18],standardAccount:"*25519",website:"https://cess.cloud"},{prefix:11331,network:"cess",displayName:"CESS",symbols:["CESS"],decimals:[18],standardAccount:"*25519",website:"https://cess.cloud"},{prefix:11486,network:"luhn",displayName:"Luhn Network",symbols:["LUHN"],decimals:[18],standardAccount:"*25519",website:"https://luhn.network"},{prefix:11820,network:"contextfree",displayName:"Automata ContextFree",symbols:["CTX"],decimals:[18],standardAccount:"*25519",website:"https://ata.network"},{prefix:12155,network:"impact",displayName:"Impact Protocol Network",symbols:["BSTY"],decimals:[18],standardAccount:"*25519",website:"https://impactprotocol.network/"},{prefix:12191,network:"nftmart",displayName:"NFTMart",symbols:["NMT"],decimals:[12],standardAccount:"*25519",website:"https://nftmart.io"},{prefix:12850,network:"analog-timechain",displayName:"Analog Timechain",symbols:["ANLOG"],decimals:[12],standardAccount:"*25519",website:"https://analog.one"},{prefix:13116,network:"bittensor",displayName:"Bittensor",symbols:["TAO"],decimals:[9],standardAccount:"*25519",website:"https://bittensor.com"},{prefix:14697,network:"goro",displayName:"GORO Network",symbols:["GORO"],decimals:[9],standardAccount:"*25519",website:"https://goro.network"},{prefix:14998,network:"mosaic-chain",displayName:"Mosaic Chain",symbols:["MOS"],decimals:[18],standardAccount:"*25519",website:"https://mosaicchain.io"},{prefix:29972,network:"mythos",displayName:"Mythos",symbols:["MYTH"],decimals:[18],standardAccount:"secp256k1",website:"https://mythos.foundation"},{prefix:8888,network:"xcavate",displayName:"Xcavate Protocol",symbols:["XCAV"],decimals:[12],standardAccount:"*25519",website:"https://xcavate.io/"}];var yi={acala:["0xfc41b9bd8ef8fe53d58c7ea67c794c7ec9a73daf05e6d54b14ff6342c99ba64c"],ajuna:["0xe358eb1d11b31255a286c12e44fe6780b7edb171d657905a97e39f71d9c6c3ee"],"aleph-node":["0x70255b4d28de0fc4e1a193d7e175ad1ccef431598211c55538f1018651a0344e"],astar:["0x9eb76c5184c4ab8679d2d5d819fdf90b9c001403e9e17da2e14b6d8aec4029c6"],basilisk:["0xa85cfb9b9fd4d622a5b28289a02347af987d8f73fa3108450e2b4a11c1ce5755"],bifrost:["0x262e1b2ad728475fd6fe88e62d34c200abe6fd693931ddad144059b1eb884e5b"],"bifrost-kusama":["0x9f28c6a68e0fc9646eff64935684f6eeeece527e37bbe1f213d22caa1d9d6bed"],bittensor:["0x2f0555cc76fc2840a25a6ea3b9637146806f1f44b090c175ffde2a7e5ab36c03"],centrifuge:["0xb3db41421702df9a7fcac62b53ffeac85f7853cc4e689e0b93aeb3db18c09d82","0x67dddf2673b69e5f875f6f25277495834398eafd67f492e09f3f3345e003d1b5"],cere:["0x81443836a9a24caaa23f1241897d1235717535711d1d3fe24eae4fdc942c092c"],composable:["0xdaab8df776eb52ec604a5df5d388bb62a050a0aaec4556a64265b9d42755552d"],creditcoin3:["0x4436a7d64e363df85e065a894721002a86643283f9707338bf195d360ba2ee71","0xfc4ec97a1c1f119c4353aecb4a17c7c0cf7b40d5d660143d8bad9117e9866572","0xfc9df99a665f964aed6649f275055e54df5e3420489538ed31d7788f53d11ef6"],darwinia:["0xe71578b37a7c799b0ab4ee87ffa6f059a6b98f71f06fb8c84a8d88013a548ad6"],dentnet:["0x0313f6a011d128d22f996703cbab05162e2fdc9e031493314fe6db79979c5ca7"],"dock-mainnet":["0x6bfe24dca2a3be10f22212678ac13a6446ec764103c0f3471c71609eac384aae","0xf73467c6544aa68df2ee546b135f955c46b90fa627e9b5d7935f41061bb8a5a9"],edgeware:["0x742a2ca70c2fda6cee4f8df98d64c4c670a052d9568058982dad9d5a7a135c5b"],encointer:["0x7dd99936c1e9e6d1ce7d90eb6f33bea8393b4bf87677d675aa63c9cb3e8c5b5b"],enjin:["0xd8761d3c88f26dc12875c00d3165f7d67243d56fc85b4cf19937601a7916e5a9"],equilibrium:["0x6f1a800de3daff7f5e037ddf66ab22ce03ab91874debeddb1086f5f7dbd48925"],frequency:["0x4a587bf17a404e3572747add7aab7bbe56e805a5479c6c436f07f36fcc8d3ae1"],genshiro:["0x9b8cefc0eb5c568b527998bdd76c184e2b76ae561be76e4667072230217ea243"],hydradx:["0xafdc188f45c71dacbaa0b62e16a91f726c7b8699a9748cdf715459de6b7f366d","0xd2a620c27ec5cbc5621ff9a522689895074f7cca0d08e7134a7804e1a3ba86fc","0x10af6e84234477d84dc572bac0789813b254aa490767ed06fb9591191d1073f9","0x3d75507dd46301767e601265791da1d9cb47b6ebc94e87347b635e5bf58bd047","0x0ed32bfcab4a83517fac88f2aa7cbc2f88d3ab93be9a12b6188a036bf8a943c2"],integritee:["0xcdedc8eadbfa209d3f207bba541e57c3c58a667b05a2e1d1e86353c9000758da","0xe13e7af377c64e83f95e0d70d5e5c3c01d697a84538776c5b9bbe0e7d7b6034c"],"interlay-parachain":["0xbf88efe70e9e0e916416e8bed61f2b45717f517d7f3523e33c7b001e5ffcbc72"],karura:["0xbaf5aabe40646d11f0ee8abbdc64f4a4b7674925cba08e4a05ff9ebed6e2126b"],khala:["0xd43540ba6d3eb4897c28a77d48cb5b729fea37603cbbfc7a86a73b72adb3be8d"],kulupu:["0xf7a99d3cb92853d00d5275c971c132c074636256583fee53b3bbe60d7b8769ba"],kusama:["0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe","0xe3777fa922cafbff200cadeaea1a76bd7898ad5b89f7848999058b50e715f636","0x3fd7b9eb6a00376e5be61f01abb429ffb0b104be05eaff4d458da48fcd425baf"],liberland:["0x6bd89e052d67a45bb60a9a23e8581053d5e0d619f15cb9865946937e690c42d6"],matrixchain:["0x3af4ff48ec76d2efc8476730f423ac07e25ad48f5f4c9dc39c778b164d808615"],mythos:["0xf6ee56e9c5277df5b4ce6ae9983ee88f3cbed27d31beeb98f9f84f997a1ab0b9"],nodle:["0x97da7ede98d7bad4e36b4d734b6055425a3be036da2a332ea5a7037656427a21"],origintrail:["0xe7e0962324a3b86c83404dbea483f25fb5dab4c224791c81b756cfc948006174"],p3d:["0x6c5894837ad89b6d92b114a2fb3eafa8fe3d26a54848e3447015442cd6ef4e66"],parallel:["0xe61a41c53f5dcd0beb09df93b34402aada44cb05117b71059cce40a2723a4e97"],peaq:["0xd2a5d385932d1f650dae03ef8e2748983779ee342c614f80854d32b8cd8fa48c"],pendulum:["0x5d3c298622d5634ed019bf61ea4b71655030015bde9beb0d6a24743714462c86"],phala:["0x1bb969d85965e4bb5a651abbedf21a54b6b31a21f66b5401cc3f1e286268d736"],picasso:["0x6811a339673c9daa897944dcdac99c6e2939cc88245ed21951a0a3c9a2be75bc","0xe8e7f0f4c4f5a00720b4821dbfddefea7490bcf0b19009961cc46957984e2c1c"],polimec:["0x7eb9354488318e7549c722669dcbdcdc526f1fef1420e7944667212f3601fdbd"],polkadex:["0x3920bcb4960a1eef5580cd5367ff3f430eef052774f78468852f7b9cb39f8a3c"],polkadot:["0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3"],polymesh:["0x6fbd74e5e1d0a61d52ccfe9d4adaed16dd3a7caa37c6bc4d0c2fa12e8b2f4063"],quartz:["0xcd4d732201ebe5d6b014edda071c4203e16867305332301dc8d092044b28e554"],rococo:["0x6408de7737c59c238890533af25896a2c20608d8b380bb01029acb392781063e","0xaaf2cd1b74b5f726895921259421b534124726263982522174147046b8827897","0x037f5f3c8e67b314062025fc886fcd6238ea25a4a9b45dce8d246815c9ebe770","0xc196f81260cf1686172b47a79cf002120735d7cb0eb1474e8adce56618456fff","0xf6e9983c37baf68846fedafe21e56718790e39fb1c582abc408b81bc7b208f9a","0x5fce687da39305dfe682b117f0820b319348e8bb37eb16cf34acbf6a202de9d9","0xe7c3d5edde7db964317cd9b51a3a059d7cd99f81bdbce14990047354334c9779","0x1611e1dbf0405379b861e2e27daa90f480b2e6d3682414a80835a52e8cb8a215","0x343442f12fa715489a8714e79a7b264ea88c0d5b8c66b684a7788a516032f6b9","0x78bcd530c6b3a068bc17473cf5d2aff9c287102bed9af3ae3c41c33b9d6c6147","0x47381ee0697153d64404fc578392c8fd5cba9073391908f46c888498415647bd","0x19c0e4fa8ab75f5ac7865e0b8f74ff91eb9a100d336f423cd013a8befba40299"],sora:["0x7e4e32d0feafd4f9c9414b0be86373f9a1efa904809b683453a9af6856d38ad5"],stafi:["0x290a4149f09ea0e402c74c1c7e96ae4239588577fe78932f94f5404c68243d80"],statemine:["0x48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a"],statemint:["0x68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f"],subsocial:["0x0bd72c1c305172e1275278aaeb3f161e02eccb7a819e63f62d47bd53a28189f8"],ternoa:["0x6859c81ca95ef624c9dfe4dc6e3381c33e5d6509e35e147092bfbc780f777c4e"],unique:["0x84322d9cddbf35088f1e54e9a85c967a41a56a4f43445768125e61af166c7d31"],vara:["0xfe1b4c55fd4d668101126434206571a7838a8b6b93a6d1b95d607e78e6c53763"],vtb:["0x286bc8414c7000ce1d6ee6a834e29a54c1784814b76243eb77ed0b2c5573c60f","0x7483b89572fb2bd687c7b9a93b242d0b237f9aba463aba07ec24503931038aaa"],westend:["0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e"],xxnetwork:["0x50dd5d206917bf10502c68fb4d18a59fc8aa31586f4e8856b493e43544aa82aa"],zeitgeist:["0x1bf2a2ecb4a868de66ea8610f2ce7c8c43706561b6476031315f6640fe38e060"]};var Qi={centrifuge:"polkadot",kusama:"polkadot",polkadot:"polkadot",sora:"polkadot",statemine:"polkadot",statemint:"polkadot",westmint:"polkadot"};var Ni={acala:787,ajuna:354,"aleph-node":643,astar:810,bifrost:788,"bifrost-kusama":788,bittensor:354,centrifuge:747,composable:354,creditcoin3:354,darwinia:354,dentnet:734,"dock-mainnet":594,edgeware:523,encointer:434,enjin:1155,equilibrium:99999997,frequency:2091,genshiro:99999996,hydradx:354,integritee:2015,"interlay-parachain":354,karura:686,khala:434,kusama:434,liberland:767,matrixchain:1155,mythos:60,nodle:1003,origintrail:354,parallel:354,peaq:3338,pendulum:354,phala:354,picasso:434,polimec:3344,polkadex:799,polkadot:354,polymesh:595,quartz:631,sora:617,stafi:907,statemine:434,statemint:354,ternoa:995,unique:661,vara:4976,vtb:694,xxnetwork:1955,zeitgeist:354};var Ei={"":!0,"cess-testnet":!0,"dock-testnet":!0,jupiter:!0,"mathchain-testnet":!0,p3dt:!0,subspace_testnet:!0,"zero-alphaville":!0};var Gy=[0,2,42],PH=["testnet"];function KH(l){let A=l.network||"",G=A.replace(/_/g,"-").split("-"),b=l;return b.slip44=Ni[A],b.hasLedgerSupport=!!b.slip44,b.genesisHash=yi[A]||[],b.icon=Qi[A]||"substrate",b.isTestnet=!!Ei[A]||PH.includes(G[G.length-1]),b.isIgnored=b.isTestnet||!(l.standardAccount&&l.decimals?.length&&l.symbols?.length)&&l.prefix!==42,b}function qH({genesisHash:l,prefix:A}){return!!l.length||A===42}function _H(l){return!l.isIgnored&&!!l.network}function $H(l,A){let G=Gy.includes(l.prefix),b=Gy.includes(A.prefix);return G===b?G?0:l.displayName.localeCompare(A.displayName):G?-1:1}var by=Ay.map(KH),zW=by.filter(_H).sort($H),l5=zW.filter(qH);var $Z={allowedDecodedLengths:[1,2,4,8,32,33],allowedEncodedLengths:[3,4,6,10,35,36,37,38],allowedPrefix:zW.map(({prefix:l})=>l),prefix:42};function Pt(l,A,G=-1){if(!l)throw new Error("Invalid empty address passed");if(Hb(l)||Vb(l))return Tl(l);try{let b=pi(l);if(!$Z.allowedEncodedLengths.includes(b.length))throw new Error("Invalid decoded address length");let[t,c,B,e]=ly(b);if(!t&&!A)throw new Error("Invalid decoded address checksum");if(G!==-1&&G!==e)throw new Error(`Expected ss58Format ${G}, received ${e}`);return b.slice(B,c)}catch(b){throw new Error(`Decoding ${l}: ${b.message}`)}}var vi={isLe:!1},jW={isLe:!0};var ty={bitLength:32,isLe:!1},MW={bitLength:32,isLe:!0},$c={bitLength:256,isLe:!1},cy={bitLength:256,isLe:!0};var A5=/^\d+$/,G5=32,ld,Fe,Hi=class Hi{constructor(){EG(this,ld,new Uint8Array(32));EG(this,Fe,!1)}static from(A){let G=new Hi,[b,t]=A.startsWith("/")?[A.substring(1),!0]:[A,!1];return G.soft(A5.test(b)?new pA.default(b,10):b),t?G.harden():G}get chainCode(){return GA(this,ld)}get isHard(){return GA(this,Fe)}get isSoft(){return!GA(this,Fe)}hard(A){return this.soft(A).harden()}harden(){return bG(this,Fe,!0),this}soft(A){return Ah(A)||vd(A)||kd(A)?this.soft(kG(A,cy)):Vb(A)?this.soft(vb(A)):lh(A)?this.soft(be(uG(A))):A.length>G5?this.soft(Mb(A)):(GA(this,ld).fill(0),GA(this,ld).set(A,0),this)}soften(){return bG(this,Fe,!1),this}};ld=new WeakMap,Fe=new WeakMap;var TW=Hi;var b5=/\/(\/?)([^/]+)/g;function kn(l){let A=l.match(b5),G=[],b="";if(A){b=A.join("");for(let t of A)G.push(TW.from(t.substring(1)))}if(b!==l)throw new Error(`Re-constructed path "${b}" does not match input`);return{parts:A,path:G}}var t5=/^((0x[a-fA-F0-9]+|[\p{L}\d]+(?: [\p{L}\d]+)*))((\/\/?[^/]+)*)(\/\/\/(.*))?$/u;function Ji(l){let G=l.normalize("NFC").match(t5);if(G===null)throw new Error("Unable to match provided value to a secret URI");let[,b,,t,,,c]=G,{path:B}=kn(t);return{derivePath:t,password:c,path:B,phrase:b}}var c5=be(uG("Secp256k1HDKD"));function By(l,A){if(!Hb(A)||A.length!==32)throw new Error("Invalid chainCode passed to derive");return Mb(nG(c5,l,A),256)}var B5=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),JB=new Uint32Array(64),DW=class extends yd{constructor(A=32){super(64,A,8,!1),this.A=vc[0]|0,this.B=vc[1]|0,this.C=vc[2]|0,this.D=vc[3]|0,this.E=vc[4]|0,this.F=vc[5]|0,this.G=vc[6]|0,this.H=vc[7]|0}get(){let{A,B:G,C:b,D:t,E:c,F:B,G:e,H:d}=this;return[A,G,b,t,c,B,e,d]}set(A,G,b,t,c,B,e,d){this.A=A|0,this.B=G|0,this.C=b|0,this.D=t|0,this.E=c|0,this.F=B|0,this.G=e|0,this.H=d|0}process(A,G){for(let n=0;n<16;n++,G+=4)JB[n]=A.getUint32(G,!1);for(let n=16;n<64;n++){let h=JB[n-15],W=JB[n-2],m=kt(h,7)^kt(h,18)^h>>>3,Y=kt(W,17)^kt(W,19)^W>>>10;JB[n]=Y+JB[n-7]+m+JB[n-16]|0}let{A:b,B:t,C:c,D:B,E:e,F:d,G:Z,H:g}=this;for(let n=0;n<64;n++){let h=kt(e,6)^kt(e,11)^kt(e,25),W=g+h+K2(e,d,Z)+B5[n]+JB[n]|0,Y=(kt(b,2)^kt(b,13)^kt(b,22))+q2(b,t,c)|0;g=Z,Z=d,d=e,e=B+W|0,B=c,c=t,t=b,b=W+Y|0}b=b+this.A|0,t=t+this.B|0,c=c+this.C|0,B=B+this.D|0,e=e+this.E|0,d=d+this.F|0,Z=Z+this.G|0,g=g+this.H|0,this.set(b,t,c,B,e,d,Z,g)}roundClean(){MG(JB)}destroy(){this.set(0,0,0,0,0,0,0,0),MG(this.buffer)}};var ey=Ia(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(l=>BigInt(l))),e5=ey[0],Z5=ey[1],xB=new Uint32Array(80),fB=new Uint32Array(80),LW=class extends yd{constructor(A=64){super(128,A,16,!1),this.Ah=mb[0]|0,this.Al=mb[1]|0,this.Bh=mb[2]|0,this.Bl=mb[3]|0,this.Ch=mb[4]|0,this.Cl=mb[5]|0,this.Dh=mb[6]|0,this.Dl=mb[7]|0,this.Eh=mb[8]|0,this.El=mb[9]|0,this.Fh=mb[10]|0,this.Fl=mb[11]|0,this.Gh=mb[12]|0,this.Gl=mb[13]|0,this.Hh=mb[14]|0,this.Hl=mb[15]|0}get(){let{Ah:A,Al:G,Bh:b,Bl:t,Ch:c,Cl:B,Dh:e,Dl:d,Eh:Z,El:g,Fh:n,Fl:h,Gh:W,Gl:m,Hh:Y,Hl:R}=this;return[A,G,b,t,c,B,e,d,Z,g,n,h,W,m,Y,R]}set(A,G,b,t,c,B,e,d,Z,g,n,h,W,m,Y,R){this.Ah=A|0,this.Al=G|0,this.Bh=b|0,this.Bl=t|0,this.Ch=c|0,this.Cl=B|0,this.Dh=e|0,this.Dl=d|0,this.Eh=Z|0,this.El=g|0,this.Fh=n|0,this.Fl=h|0,this.Gh=W|0,this.Gl=m|0,this.Hh=Y|0,this.Hl=R|0}process(A,G){for(let I=0;I<16;I++,G+=4)xB[I]=A.getUint32(G),fB[I]=A.getUint32(G+=4);for(let I=16;I<80;I++){let Q=xB[I-15]|0,f=fB[I-15]|0,U=cc(Q,f,1)^cc(Q,f,8)^zo(Q,f,7),J=Bc(Q,f,1)^Bc(Q,f,8)^jo(Q,f,7),M=xB[I-2]|0,C=fB[I-2]|0,D=cc(M,C,19)^Ae(M,C,61)^zo(M,C,6),$=Bc(M,C,19)^Ge(M,C,61)^jo(M,C,6),K=cV(J,$,fB[I-7],fB[I-16]),y=BV(K,U,D,xB[I-7],xB[I-16]);xB[I]=y|0,fB[I]=K|0}let{Ah:b,Al:t,Bh:c,Bl:B,Ch:e,Cl:d,Dh:Z,Dl:g,Eh:n,El:h,Fh:W,Fl:m,Gh:Y,Gl:R,Hh:u,Hl:i}=this;for(let I=0;I<80;I++){let Q=cc(n,h,14)^cc(n,h,18)^Ae(n,h,41),f=Bc(n,h,14)^Bc(n,h,18)^Ge(n,h,41),U=n&W^~n&Y,J=h&m^~h&R,M=eV(i,f,J,Z5[I],fB[I]),C=ZV(M,u,Q,U,e5[I],xB[I]),D=M|0,$=cc(b,t,28)^Ae(b,t,34)^Ae(b,t,39),K=Bc(b,t,28)^Ge(b,t,34)^Ge(b,t,39),y=b&c^b&e^c&e,r=t&B^t&d^B&d;u=Y|0,i=R|0,Y=W|0,R=m|0,W=n|0,m=h|0,{h:n,l:h}=Zt(Z|0,g|0,C|0,D|0),Z=e|0,g=d|0,e=c|0,d=B|0,c=b|0,B=t|0;let F=Qd(D,K,r);b=Nd(F,C,$,y),t=F|0}({h:b,l:t}=Zt(this.Ah|0,this.Al|0,b|0,t|0)),{h:c,l:B}=Zt(this.Bh|0,this.Bl|0,c|0,B|0),{h:e,l:d}=Zt(this.Ch|0,this.Cl|0,e|0,d|0),{h:Z,l:g}=Zt(this.Dh|0,this.Dl|0,Z|0,g|0),{h:n,l:h}=Zt(this.Eh|0,this.El|0,n|0,h|0),{h:W,l:m}=Zt(this.Fh|0,this.Fl|0,W|0,m|0),{h:Y,l:R}=Zt(this.Gh|0,this.Gl|0,Y|0,R|0),{h:u,l:i}=Zt(this.Hh|0,this.Hl|0,u|0,i|0),this.set(b,t,c,B,e,d,Z,g,n,h,W,m,Y,R,u,i)}roundClean(){MG(xB,fB)}destroy(){MG(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ye=Fd(()=>new DW);var OW=Fd(()=>new LW);var PW=class extends bc{constructor(A,G){super(),this.finished=!1,this.destroyed=!1,qe(A);let b=et(G);if(this.iHash=A.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;let t=this.blockLen,c=new Uint8Array(t);c.set(b.length>t?A.create().update(b).digest():b);for(let B=0;B<c.length;B++)c[B]^=54;this.iHash.update(c),this.oHash=A.create();for(let B=0;B<c.length;B++)c[B]^=106;this.oHash.update(c),MG(c)}update(A){return Xt(this),this.iHash.update(A),this}digestInto(A){Xt(this),fG(A,this.outputLen),this.finished=!0,this.iHash.digestInto(A),this.oHash.update(A),this.oHash.digestInto(A),this.destroy()}digest(){let A=new Uint8Array(this.oHash.outputLen);return this.digestInto(A),A}_cloneInto(A){A||(A=Object.create(Object.getPrototypeOf(this),{}));let{oHash:G,iHash:b,finished:t,destroyed:c,blockLen:B,outputLen:e}=this;return A=A,A.finished=t,A.destroyed=c,A.blockLen=B,A.outputLen=e,A.oHash=G._cloneInto(A.oHash),A.iHash=b._cloneInto(A.iHash),A}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Qe=(l,A,G)=>new PW(l,A).update(G).digest();Qe.create=(l,A)=>new PW(l,A);var ki=BigInt(0),fi=BigInt(1);function lB(l,A=""){if(typeof l!="boolean"){let G=A&&`"${A}"`;throw new Error(G+"expected boolean, got type="+typeof l)}return l}function mt(l,A,G=""){let b=ft(l),t=l?.length,c=A!==void 0;if(!b||c&&t!==A){let B=G&&`"${G}" `,e=c?` of length ${A}`:"",d=b?`length=${t}`:`type=${typeof l}`;throw new Error(B+"expected Uint8Array"+e+", got "+d)}return l}function Ad(l){let A=l.toString(16);return A.length&1?"0"+A:A}function wi(l){if(typeof l!="string")throw new Error("hex string expected, got "+typeof l);return l===""?ki:BigInt("0x"+l)}function Ne(l){return wi(Bt(l))}function Kt(l){return fG(l),wi(Bt(Uint8Array.from(l).reverse()))}function wn(l,A){return WB(l.toString(16).padStart(A*2,"0"))}function Un(l,A){return wn(l,A).reverse()}function ZG(l,A,G){let b;if(typeof A=="string")try{b=WB(A)}catch(c){throw new Error(l+" must be hex string or Uint8Array, cause: "+c)}else if(ft(A))b=Uint8Array.from(A);else throw new Error(l+" must be hex string or Uint8Array");let t=b.length;if(typeof G=="number"&&t!==G)throw new Error(l+" of length "+G+" expected, got "+t);return b}function Ui(l,A){if(l.length!==A.length)return!1;let G=0;for(let b=0;b<l.length;b++)G|=l[b]^A[b];return G===0}function KW(l){return Uint8Array.from(l)}var xi=l=>typeof l=="bigint"&&ki<=l;function Ci(l,A,G){return xi(l)&&xi(A)&&xi(G)&&A<=l&&l<G}function Ee(l,A,G,b){if(!Ci(A,G,b))throw new Error("expected valid "+l+": "+G+" <= n < "+b+", got "+A)}function Cn(l){let A;for(A=0;l>ki;l>>=fi,A+=1);return A}var Rc=l=>(fi<<BigInt(l))-fi;function Si(l,A,G){if(typeof l!="number"||l<2)throw new Error("hashLen must be a number");if(typeof A!="number"||A<2)throw new Error("qByteLen must be a number");if(typeof G!="function")throw new Error("hmacFn must be a function");let b=W=>new Uint8Array(W),t=W=>Uint8Array.of(W),c=b(l),B=b(l),e=0,d=()=>{c.fill(1),B.fill(0),e=0},Z=(...W)=>G(B,c,...W),g=(W=b(0))=>{B=Z(t(0),W),c=Z(),W.length!==0&&(B=Z(t(1),W),c=Z())},n=()=>{if(e++>=1e3)throw new Error("drbg: tried 1000 values");let W=0,m=[];for(;W<A;){c=Z();let Y=c.slice();m.push(Y),W+=c.length}return VG(...m)};return(W,m)=>{d(),g(W);let Y;for(;!(Y=m(n()));)g();return d(),Y}}function kB(l,A,G={}){if(!l||typeof l!="object")throw new Error("expected valid options object");function b(t,c,B){let e=l[t];if(B&&e===void 0)return;let d=typeof e;if(d!==c||e===null)throw new Error(`param "${t}" is invalid: expected ${c}, got ${d}`)}Object.entries(A).forEach(([t,c])=>b(t,c,!1)),Object.entries(G).forEach(([t,c])=>b(t,c,!0))}var qW=()=>{throw new Error("not implemented")};function ve(l){let A=new WeakMap;return(G,...b)=>{let t=A.get(G);if(t!==void 0)return t;let c=l(G,...b);return A.set(G,c),c}}var Db=BigInt(0),ob=BigInt(1),He=BigInt(2),ny=BigInt(3),ay=BigInt(4),gy=BigInt(5),a5=BigInt(7),Wy=BigInt(8),g5=BigInt(9),oy=BigInt(16);function IG(l,A){let G=l%A;return G>=Db?G:A+G}function RG(l,A,G){let b=l;for(;A-- >Db;)b*=b,b%=G;return b}function Zy(l,A){if(l===Db)throw new Error("invert: expected non-zero number");if(A<=Db)throw new Error("invert: expected positive modulus, got "+A);let G=IG(l,A),b=A,t=Db,c=ob,B=ob,e=Db;for(;G!==Db;){let Z=b/G,g=b%G,n=t-B*Z,h=c-e*Z;b=G,G=g,t=B,c=e,B=n,e=h}if(b!==ob)throw new Error("invert: does not exist");return IG(t,A)}function zi(l,A,G){if(!l.eql(l.sqr(A),G))throw new Error("Cannot find square root")}function hy(l,A){let G=(l.ORDER+ob)/ay,b=l.pow(A,G);return zi(l,b,A),b}function W5(l,A){let G=(l.ORDER-gy)/Wy,b=l.mul(A,He),t=l.pow(b,G),c=l.mul(A,t),B=l.mul(l.mul(c,He),t),e=l.mul(c,l.sub(B,l.ONE));return zi(l,e,A),e}function o5(l){let A=Vt(l),G=sy(l),b=G(A,A.neg(A.ONE)),t=G(A,b),c=G(A,A.neg(b)),B=(l+a5)/oy;return(e,d)=>{let Z=e.pow(d,B),g=e.mul(Z,b),n=e.mul(Z,t),h=e.mul(Z,c),W=e.eql(e.sqr(g),d),m=e.eql(e.sqr(n),d);Z=e.cmov(Z,g,W),g=e.cmov(h,n,m);let Y=e.eql(e.sqr(g),d),R=e.cmov(Z,g,Y);return zi(e,R,d),R}}function sy(l){if(l<ny)throw new Error("sqrt is not defined for small field");let A=l-ob,G=0;for(;A%He===Db;)A/=He,G++;let b=He,t=Vt(l);for(;dy(t,b)===1;)if(b++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(G===1)return hy;let c=t.pow(b,A),B=(A+ob)/He;return function(d,Z){if(d.is0(Z))return Z;if(dy(d,Z)!==1)throw new Error("Cannot find square root");let g=G,n=d.mul(d.ONE,c),h=d.pow(Z,A),W=d.pow(Z,B);for(;!d.eql(h,d.ONE);){if(d.is0(h))return d.ZERO;let m=1,Y=d.sqr(h);for(;!d.eql(Y,d.ONE);)if(m++,Y=d.sqr(Y),m===g)throw new Error("Cannot find square root");let R=ob<<BigInt(g-m-1),u=d.pow(n,R);g=m,n=d.sqr(u),h=d.mul(h,n),W=d.mul(W,u)}return W}}function h5(l){return l%ay===ny?hy:l%Wy===gy?W5:l%oy===g5?o5(l):sy(l)}var AB=(l,A)=>(IG(l,A)&ob)===ob,s5=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ji(l){let A={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},G=s5.reduce((b,t)=>(b[t]="function",b),A);return kB(l,G),l}function r5(l,A,G){if(G<Db)throw new Error("invalid exponent, negatives unsupported");if(G===Db)return l.ONE;if(G===ob)return A;let b=l.ONE,t=A;for(;G>Db;)G&ob&&(b=l.mul(b,t)),t=l.sqr(t),G>>=ob;return b}function Sn(l,A,G=!1){let b=new Array(A.length).fill(G?l.ZERO:void 0),t=A.reduce((B,e,d)=>l.is0(e)?B:(b[d]=B,l.mul(B,e)),l.ONE),c=l.inv(t);return A.reduceRight((B,e,d)=>l.is0(e)?B:(b[d]=l.mul(B,b[d]),l.mul(B,e)),c),b}function dy(l,A){let G=(l.ORDER-ob)/He,b=l.pow(A,G),t=l.eql(b,l.ONE),c=l.eql(b,l.ZERO),B=l.eql(b,l.neg(l.ONE));if(!t&&!c&&!B)throw new Error("invalid Legendre symbol result");return t?1:c?0:-1}function _W(l,A){A!==void 0&&mG(A);let G=A!==void 0?A:l.toString(2).length,b=Math.ceil(G/8);return{nBitLength:G,nByteLength:b}}function Vt(l,A,G=!1,b={}){if(l<=Db)throw new Error("invalid field: expected ORDER > 0, got "+l);let t,c,B=!1,e;if(typeof A=="object"&&A!=null){if(b.sqrt||G)throw new Error("cannot specify opts in two arguments");let h=A;h.BITS&&(t=h.BITS),h.sqrt&&(c=h.sqrt),typeof h.isLE=="boolean"&&(G=h.isLE),typeof h.modFromBytes=="boolean"&&(B=h.modFromBytes),e=h.allowedLengths}else typeof A=="number"&&(t=A),b.sqrt&&(c=b.sqrt);let{nBitLength:d,nByteLength:Z}=_W(l,t);if(Z>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let g,n=Object.freeze({ORDER:l,isLE:G,BITS:d,BYTES:Z,MASK:Rc(d),ZERO:Db,ONE:ob,allowedLengths:e,create:h=>IG(h,l),isValid:h=>{if(typeof h!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof h);return Db<=h&&h<l},is0:h=>h===Db,isValidNot0:h=>!n.is0(h)&&n.isValid(h),isOdd:h=>(h&ob)===ob,neg:h=>IG(-h,l),eql:(h,W)=>h===W,sqr:h=>IG(h*h,l),add:(h,W)=>IG(h+W,l),sub:(h,W)=>IG(h-W,l),mul:(h,W)=>IG(h*W,l),pow:(h,W)=>r5(n,h,W),div:(h,W)=>IG(h*Zy(W,l),l),sqrN:h=>h*h,addN:(h,W)=>h+W,subN:(h,W)=>h-W,mulN:(h,W)=>h*W,inv:h=>Zy(h,l),sqrt:c||(h=>(g||(g=h5(l)),g(n,h))),toBytes:h=>G?Un(h,Z):wn(h,Z),fromBytes:(h,W=!0)=>{if(e){if(!e.includes(h.length)||h.length>Z)throw new Error("Field.fromBytes: expected "+e+" bytes, got "+h.length);let Y=new Uint8Array(Z);Y.set(h,G?0:Y.length-h.length),h=Y}if(h.length!==Z)throw new Error("Field.fromBytes: expected "+Z+" bytes, got "+h.length);let m=G?Kt(h):Ne(h);if(B&&(m=IG(m,l)),!W&&!n.isValid(m))throw new Error("invalid field element: outside of range 0..ORDER");return m},invertBatch:h=>Sn(n,h),cmov:(h,W,m)=>m?W:h});return Object.freeze(n)}function ry(l){if(typeof l!="bigint")throw new Error("field order must be bigint");let A=l.toString(2).length;return Math.ceil(A/8)}function Mi(l){let A=ry(l);return A+Math.ceil(A/2)}function Ti(l,A,G=!1){let b=l.length,t=ry(A),c=Mi(A);if(b<16||b<c||b>1024)throw new Error("expected "+c+"-1024 bytes of input, got "+b);let B=G?Kt(l):Ne(l),e=IG(B,A-ob)+ob;return G?Un(e,t):wn(e,t)}var Gd=BigInt(0),Je=BigInt(1);function zn(l,A){let G=A.negate();return l?G:A}function GB(l,A){let G=Sn(l.Fp,A.map(b=>b.Z));return A.map((b,t)=>l.fromAffine(b.toAffine(G[t])))}function uy(l,A){if(!Number.isSafeInteger(l)||l<=0||l>A)throw new Error("invalid window size, expected [1.."+A+"], got W="+l)}function Di(l,A){uy(l,A);let G=Math.ceil(A/l)+1,b=2**(l-1),t=2**l,c=Rc(l),B=BigInt(l);return{windows:G,windowSize:b,mask:c,maxNumber:t,shiftBy:B}}function iy(l,A,G){let{windowSize:b,mask:t,maxNumber:c,shiftBy:B}=G,e=Number(l&t),d=l>>B;e>b&&(e-=c,d+=Je);let Z=A*b,g=Z+Math.abs(e)-1,n=e===0,h=e<0,W=A%2!==0;return{nextN:d,offset:g,isZero:n,isNeg:h,isNegF:W,offsetF:Z}}function m5(l,A){if(!Array.isArray(l))throw new Error("array expected");l.forEach((G,b)=>{if(!(G instanceof A))throw new Error("invalid point at index "+b)})}function V5(l,A){if(!Array.isArray(l))throw new Error("array of scalars expected");l.forEach((G,b)=>{if(!A.isValid(G))throw new Error("invalid scalar at index "+b)})}var Li=new WeakMap,Yy=new WeakMap;function Oi(l){return Yy.get(l)||1}function my(l){if(l!==Gd)throw new Error("invalid wNAF")}var bd=class{constructor(A,G){this.BASE=A.BASE,this.ZERO=A.ZERO,this.Fn=A.Fn,this.bits=G}_unsafeLadder(A,G,b=this.ZERO){let t=A;for(;G>Gd;)G&Je&&(b=b.add(t)),t=t.double(),G>>=Je;return b}precomputeWindow(A,G){let{windows:b,windowSize:t}=Di(G,this.bits),c=[],B=A,e=B;for(let d=0;d<b;d++){e=B,c.push(e);for(let Z=1;Z<t;Z++)e=e.add(B),c.push(e);B=e.double()}return c}wNAF(A,G,b){if(!this.Fn.isValid(b))throw new Error("invalid scalar");let t=this.ZERO,c=this.BASE,B=Di(A,this.bits);for(let e=0;e<B.windows;e++){let{nextN:d,offset:Z,isZero:g,isNeg:n,isNegF:h,offsetF:W}=iy(b,e,B);b=d,g?c=c.add(zn(h,G[W])):t=t.add(zn(n,G[Z]))}return my(b),{p:t,f:c}}wNAFUnsafe(A,G,b,t=this.ZERO){let c=Di(A,this.bits);for(let B=0;B<c.windows&&b!==Gd;B++){let{nextN:e,offset:d,isZero:Z,isNeg:g}=iy(b,B,c);if(b=e,!Z){let n=G[d];t=t.add(g?n.negate():n)}}return my(b),t}getPrecomputes(A,G,b){let t=Li.get(G);return t||(t=this.precomputeWindow(G,A),A!==1&&(typeof b=="function"&&(t=b(t)),Li.set(G,t))),t}cached(A,G,b){let t=Oi(A);return this.wNAF(t,this.getPrecomputes(t,A,b),G)}unsafe(A,G,b,t){let c=Oi(A);return c===1?this._unsafeLadder(A,G,t):this.wNAFUnsafe(c,this.getPrecomputes(c,A,b),G,t)}createCache(A,G){uy(G,this.bits),Yy.set(A,G),Li.delete(A)}hasCache(A){return Oi(A)!==1}};function Iy(l,A,G,b){let t=A,c=l.ZERO,B=l.ZERO;for(;G>Gd||b>Gd;)G&Je&&(c=c.add(t)),b&Je&&(B=B.add(t)),t=t.double(),G>>=Je,b>>=Je;return{p1:c,p2:B}}function td(l,A,G,b){m5(G,l),V5(b,A);let t=G.length,c=b.length;if(t!==c)throw new Error("arrays of points and scalars must have equal length");let B=l.ZERO,e=Cn(BigInt(t)),d=1;e>12?d=e-3:e>4?d=e-2:e>0&&(d=2);let Z=Rc(d),g=new Array(Number(Z)+1).fill(B),n=Math.floor((A.BITS-1)/d)*d,h=B;for(let W=n;W>=0;W-=d){g.fill(B);for(let Y=0;Y<c;Y++){let R=b[Y],u=Number(R>>BigInt(W)&Z);g[u]=g[u].add(G[Y])}let m=B;for(let Y=g.length-1,R=B;Y>0;Y--)R=R.add(g[Y]),m=m.add(R);if(h=h.add(m),W!==0)for(let Y=0;Y<d;Y++)h=h.double()}return h}function Vy(l,A,G){if(A){if(A.ORDER!==l)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ji(A),A}else return Vt(l,{isLE:G})}function $W(l,A,G={},b){if(b===void 0&&(b=l==="edwards"),!A||typeof A!="object")throw new Error(`expected valid ${l} CURVE object`);for(let d of["p","n","h"]){let Z=A[d];if(!(typeof Z=="bigint"&&Z>Gd))throw new Error(`CURVE.${d} must be positive bigint`)}let t=Vy(A.p,G.Fp,b),c=Vy(A.n,G.Fn,b),e=["Gx","Gy","a",l==="weierstrass"?"b":"d"];for(let d of e)if(!t.isValid(A[d]))throw new Error(`CURVE.${d} must be valid field element of CURVE.Fp`);return A=Object.freeze(Object.assign({},A)),{CURVE:A,Fp:t,Fn:c}}var Ry=(l,A)=>(l+(l>=0?A:-A)/Xy)/A;function u5(l,A,G){let[[b,t],[c,B]]=A,e=Ry(B*l,G),d=Ry(-t*l,G),Z=l-e*b-d*c,g=-e*t-d*B,n=Z<tB,h=g<tB;n&&(Z=-Z),h&&(g=-g);let W=Rc(Math.ceil(Cn(G)/2))+Bd;if(Z<tB||Z>=W||g<tB||g>=W)throw new Error("splitScalar (endomorphism): failed, k="+l);return{k1neg:n,k1:Z,k2neg:h,k2:g}}function Ki(l){if(!["compact","recovered","der"].includes(l))throw new Error('Signature format must be "compact", "recovered", or "der"');return l}function Pi(l,A){let G={};for(let b of Object.keys(A))G[b]=l[b]===void 0?A[b]:l[b];return lB(G.lowS,"lowS"),lB(G.prehash,"prehash"),G.format!==void 0&&Ki(G.format),G}var qi=class extends Error{constructor(A=""){super(A)}},bB={Err:qi,_tlv:{encode:(l,A)=>{let{Err:G}=bB;if(l<0||l>256)throw new G("tlv.encode: wrong tag");if(A.length&1)throw new G("tlv.encode: unpadded data");let b=A.length/2,t=Ad(b);if(t.length/2&128)throw new G("tlv.encode: long form length too big");let c=b>127?Ad(t.length/2|128):"";return Ad(l)+c+t+A},decode(l,A){let{Err:G}=bB,b=0;if(l<0||l>256)throw new G("tlv.encode: wrong tag");if(A.length<2||A[b++]!==l)throw new G("tlv.decode: wrong tlv");let t=A[b++],c=!!(t&128),B=0;if(!c)B=t;else{let d=t&127;if(!d)throw new G("tlv.decode(long): indefinite length not supported");if(d>4)throw new G("tlv.decode(long): byte length is too big");let Z=A.subarray(b,b+d);if(Z.length!==d)throw new G("tlv.decode: length bytes not complete");if(Z[0]===0)throw new G("tlv.decode(long): zero leftmost byte");for(let g of Z)B=B<<8|g;if(b+=d,B<128)throw new G("tlv.decode(long): not minimal encoding")}let e=A.subarray(b,b+B);if(e.length!==B)throw new G("tlv.decode: wrong value length");return{v:e,l:A.subarray(b+B)}}},_int:{encode(l){let{Err:A}=bB;if(l<tB)throw new A("integer: negative integers are not allowed");let G=Ad(l);if(Number.parseInt(G[0],16)&8&&(G="00"+G),G.length&1)throw new A("unexpected DER parsing assertion: unpadded hex");return G},decode(l){let{Err:A}=bB;if(l[0]&128)throw new A("invalid signature integer: negative");if(l[0]===0&&!(l[1]&128))throw new A("invalid signature integer: unnecessary leading zero");return Ne(l)}},toSig(l){let{Err:A,_int:G,_tlv:b}=bB,t=ZG("signature",l),{v:c,l:B}=b.decode(48,t);if(B.length)throw new A("invalid signature: left bytes after parsing");let{v:e,l:d}=b.decode(2,c),{v:Z,l:g}=b.decode(2,d);if(g.length)throw new A("invalid signature: left bytes after parsing");return{r:G.decode(e),s:G.decode(Z)}},hexFromSig(l){let{_tlv:A,_int:G}=bB,b=A.encode(2,G.encode(l.r)),t=A.encode(2,G.encode(l.s)),c=b+t;return A.encode(48,c)}},tB=BigInt(0),Bd=BigInt(1),Xy=BigInt(2),lo=BigInt(3),Y5=BigInt(4);function cd(l,A){let{BYTES:G}=l,b;if(typeof A=="bigint")b=A;else{let t=ZG("private key",A);try{b=l.fromBytes(t)}catch{throw new Error(`invalid private key: expected ui8a of size ${G}, got ${typeof A}`)}}if(!l.isValidNot0(b))throw new Error("invalid private key: out of range [1..N-1]");return b}function I5(l,A={}){let G=$W("weierstrass",l,A),{Fp:b,Fn:t}=G,c=G.CURVE,{h:B,n:e}=c;kB(A,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:d}=A;if(d&&(!b.is0(c.a)||typeof d.beta!="bigint"||!Array.isArray(d.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let Z=Fy(b,t);function g(){if(!b.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function n(K,y,r){let{x:F,y:E}=y.toAffine(),x=b.toBytes(F);if(lB(r,"isCompressed"),r){g();let s=!b.isOdd(E);return VG(py(s),x)}else return VG(Uint8Array.of(4),x,b.toBytes(E))}function h(K){mt(K,void 0,"Point");let{publicKey:y,publicKeyUncompressed:r}=Z,F=K.length,E=K[0],x=K.subarray(1);if(F===y&&(E===2||E===3)){let s=b.fromBytes(x);if(!b.isValid(s))throw new Error("bad point: is not on curve, wrong x");let p=Y(s),X;try{X=b.sqrt(p)}catch(V){let v=V instanceof Error?": "+V.message:"";throw new Error("bad point: is not on curve, sqrt error"+v)}g();let o=b.isOdd(X);return(E&1)===1!==o&&(X=b.neg(X)),{x:s,y:X}}else if(F===r&&E===4){let s=b.BYTES,p=b.fromBytes(x.subarray(0,s)),X=b.fromBytes(x.subarray(s,s*2));if(!R(p,X))throw new Error("bad point: is not on curve");return{x:p,y:X}}else throw new Error(`bad point: got length ${F}, expected compressed=${y} or uncompressed=${r}`)}let W=A.toBytes||n,m=A.fromBytes||h;function Y(K){let y=b.sqr(K),r=b.mul(y,K);return b.add(b.add(r,b.mul(K,c.a)),c.b)}function R(K,y){let r=b.sqr(y),F=Y(K);return b.eql(r,F)}if(!R(c.Gx,c.Gy))throw new Error("bad curve params: generator point");let u=b.mul(b.pow(c.a,lo),Y5),i=b.mul(b.sqr(c.b),BigInt(27));if(b.is0(b.add(u,i)))throw new Error("bad curve params: a or b");function I(K,y,r=!1){if(!b.isValid(y)||r&&b.is0(y))throw new Error(`bad point coordinate ${K}`);return y}function Q(K){if(!(K instanceof C))throw new Error("ProjectivePoint expected")}function f(K){if(!d||!d.basises)throw new Error("no endo");return u5(K,d.basises,t.ORDER)}let U=ve((K,y)=>{let{X:r,Y:F,Z:E}=K;if(b.eql(E,b.ONE))return{x:r,y:F};let x=K.is0();y==null&&(y=x?b.ONE:b.inv(E));let s=b.mul(r,y),p=b.mul(F,y),X=b.mul(E,y);if(x)return{x:b.ZERO,y:b.ZERO};if(!b.eql(X,b.ONE))throw new Error("invZ was invalid");return{x:s,y:p}}),J=ve(K=>{if(K.is0()){if(A.allowInfinityPoint&&!b.is0(K.Y))return;throw new Error("bad point: ZERO")}let{x:y,y:r}=K.toAffine();if(!b.isValid(y)||!b.isValid(r))throw new Error("bad point: x or y not field elements");if(!R(y,r))throw new Error("bad point: equation left != right");if(!K.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function M(K,y,r,F,E){return r=new C(b.mul(r.X,K),r.Y,r.Z),y=zn(F,y),r=zn(E,r),y.add(r)}class C{constructor(y,r,F){this.X=I("x",y),this.Y=I("y",r,!0),this.Z=I("z",F),Object.freeze(this)}static CURVE(){return c}static fromAffine(y){let{x:r,y:F}=y||{};if(!y||!b.isValid(r)||!b.isValid(F))throw new Error("invalid affine point");if(y instanceof C)throw new Error("projective point not allowed");return b.is0(r)&&b.is0(F)?C.ZERO:new C(r,F,b.ONE)}static fromBytes(y){let r=C.fromAffine(m(mt(y,void 0,"point")));return r.assertValidity(),r}static fromHex(y){return C.fromBytes(ZG("pointHex",y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,r=!0){return $.createCache(this,y),r||this.multiply(lo),this}assertValidity(){J(this)}hasEvenY(){let{y}=this.toAffine();if(!b.isOdd)throw new Error("Field doesn't support isOdd");return!b.isOdd(y)}equals(y){Q(y);let{X:r,Y:F,Z:E}=this,{X:x,Y:s,Z:p}=y,X=b.eql(b.mul(r,p),b.mul(x,E)),o=b.eql(b.mul(F,p),b.mul(s,E));return X&&o}negate(){return new C(this.X,b.neg(this.Y),this.Z)}double(){let{a:y,b:r}=c,F=b.mul(r,lo),{X:E,Y:x,Z:s}=this,p=b.ZERO,X=b.ZERO,o=b.ZERO,a=b.mul(E,E),V=b.mul(x,x),v=b.mul(s,s),S=b.mul(E,x);return S=b.add(S,S),o=b.mul(E,s),o=b.add(o,o),p=b.mul(y,o),X=b.mul(F,v),X=b.add(p,X),p=b.sub(V,X),X=b.add(V,X),X=b.mul(p,X),p=b.mul(S,p),o=b.mul(F,o),v=b.mul(y,v),S=b.sub(a,v),S=b.mul(y,S),S=b.add(S,o),o=b.add(a,a),a=b.add(o,a),a=b.add(a,v),a=b.mul(a,S),X=b.add(X,a),v=b.mul(x,s),v=b.add(v,v),a=b.mul(v,S),p=b.sub(p,a),o=b.mul(v,V),o=b.add(o,o),o=b.add(o,o),new C(p,X,o)}add(y){Q(y);let{X:r,Y:F,Z:E}=this,{X:x,Y:s,Z:p}=y,X=b.ZERO,o=b.ZERO,a=b.ZERO,V=c.a,v=b.mul(c.b,lo),S=b.mul(r,x),z=b.mul(F,s),q=b.mul(E,p),_=b.add(r,F),T=b.add(x,s);_=b.mul(_,T),T=b.add(S,z),_=b.sub(_,T),T=b.add(r,E);let H=b.add(x,p);return T=b.mul(T,H),H=b.add(S,q),T=b.sub(T,H),H=b.add(F,E),X=b.add(s,p),H=b.mul(H,X),X=b.add(z,q),H=b.sub(H,X),a=b.mul(V,T),X=b.mul(v,q),a=b.add(X,a),X=b.sub(z,a),a=b.add(z,a),o=b.mul(X,a),z=b.add(S,S),z=b.add(z,S),q=b.mul(V,q),T=b.mul(v,T),z=b.add(z,q),q=b.sub(S,q),q=b.mul(V,q),T=b.add(T,q),S=b.mul(z,T),o=b.add(o,S),S=b.mul(H,T),X=b.mul(_,X),X=b.sub(X,S),S=b.mul(_,z),a=b.mul(H,a),a=b.add(a,S),new C(X,o,a)}subtract(y){return this.add(y.negate())}is0(){return this.equals(C.ZERO)}multiply(y){let{endo:r}=A;if(!t.isValidNot0(y))throw new Error("invalid scalar: out of range");let F,E,x=s=>$.cached(this,s,p=>GB(C,p));if(r){let{k1neg:s,k1:p,k2neg:X,k2:o}=f(y),{p:a,f:V}=x(p),{p:v,f:S}=x(o);E=V.add(S),F=M(r.beta,a,v,s,X)}else{let{p:s,f:p}=x(y);F=s,E=p}return GB(C,[F,E])[0]}multiplyUnsafe(y){let{endo:r}=A,F=this;if(!t.isValid(y))throw new Error("invalid scalar: out of range");if(y===tB||F.is0())return C.ZERO;if(y===Bd)return F;if($.hasCache(this))return this.multiply(y);if(r){let{k1neg:E,k1:x,k2neg:s,k2:p}=f(y),{p1:X,p2:o}=Iy(C,F,x,p);return M(r.beta,X,o,E,s)}else return $.unsafe(F,y)}multiplyAndAddUnsafe(y,r,F){let E=this.multiplyUnsafe(r).add(y.multiplyUnsafe(F));return E.is0()?void 0:E}toAffine(y){return U(this,y)}isTorsionFree(){let{isTorsionFree:y}=A;return B===Bd?!0:y?y(C,this):$.unsafe(this,e).is0()}clearCofactor(){let{clearCofactor:y}=A;return B===Bd?this:y?y(C,this):this.multiplyUnsafe(B)}isSmallOrder(){return this.multiplyUnsafe(B).is0()}toBytes(y=!0){return lB(y,"isCompressed"),this.assertValidity(),W(C,this,y)}toHex(y=!0){return Bt(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(y=!0){return this.toBytes(y)}_setWindowSize(y){this.precompute(y)}static normalizeZ(y){return GB(C,y)}static msm(y,r){return td(C,t,y,r)}static fromPrivateKey(y){return C.BASE.multiply(cd(t,y))}}C.BASE=new C(c.Gx,c.Gy,b.ONE),C.ZERO=new C(b.ZERO,b.ONE,b.ZERO),C.Fp=b,C.Fn=t;let D=t.BITS,$=new bd(C,A.endo?Math.ceil(D/2):D);return C.BASE.precompute(8),C}function py(l){return Uint8Array.of(l?2:3)}function Fy(l,A){return{secretKey:A.BYTES,publicKey:1+l.BYTES,publicKeyUncompressed:1+2*l.BYTES,publicKeyHasPrefix:!0,signature:2*A.BYTES}}function R5(l,A={}){let{Fn:G}=l,b=A.randomBytes||Eb,t=Object.assign(Fy(l.Fp,G),{seed:Mi(G.ORDER)});function c(W){try{return!!cd(G,W)}catch{return!1}}function B(W,m){let{publicKey:Y,publicKeyUncompressed:R}=t;try{let u=W.length;return m===!0&&u!==Y||m===!1&&u!==R?!1:!!l.fromBytes(W)}catch{return!1}}function e(W=b(t.seed)){return Ti(mt(W,t.seed,"seed"),G.ORDER)}function d(W,m=!0){return l.BASE.multiply(cd(G,W)).toBytes(m)}function Z(W){let m=e(W);return{secretKey:m,publicKey:d(m)}}function g(W){if(typeof W=="bigint")return!1;if(W instanceof l)return!0;let{secretKey:m,publicKey:Y,publicKeyUncompressed:R}=t;if(G.allowedLengths||m===Y)return;let u=ZG("key",W).length;return u===Y||u===R}function n(W,m,Y=!0){if(g(W)===!0)throw new Error("first arg must be private key");if(g(m)===!1)throw new Error("second arg must be public key");let R=cd(G,W);return l.fromHex(m).multiply(R).toBytes(Y)}return Object.freeze({getPublicKey:d,getSharedSecret:n,keygen:Z,Point:l,utils:{isValidSecretKey:c,isValidPublicKey:B,randomSecretKey:e,isValidPrivateKey:c,randomPrivateKey:e,normPrivateKeyToScalar:W=>cd(G,W),precompute(W=8,m=l.BASE){return m.precompute(W,!1)}},lengths:t})}function X5(l,A,G={}){qe(A),kB(G,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let b=G.randomBytes||Eb,t=G.hmac||((r,...F)=>Qe(A,r,VG(...F))),{Fp:c,Fn:B}=l,{ORDER:e,BITS:d}=B,{keygen:Z,getPublicKey:g,getSharedSecret:n,utils:h,lengths:W}=R5(l,G),m={prehash:!1,lowS:typeof G.lowS=="boolean"?G.lowS:!1,format:void 0,extraEntropy:!1},Y="compact";function R(r){let F=e>>Bd;return r>F}function u(r,F){if(!B.isValidNot0(F))throw new Error(`invalid signature ${r}: out of range 1..Point.Fn.ORDER`);return F}function i(r,F){Ki(F);let E=W.signature,x=F==="compact"?E:F==="recovered"?E+1:void 0;return mt(r,x,`${F} signature`)}class I{constructor(F,E,x){this.r=u("r",F),this.s=u("s",E),x!=null&&(this.recovery=x),Object.freeze(this)}static fromBytes(F,E=Y){i(F,E);let x;if(E==="der"){let{r:o,s:a}=bB.toSig(mt(F));return new I(o,a)}E==="recovered"&&(x=F[0],E="compact",F=F.subarray(1));let s=B.BYTES,p=F.subarray(0,s),X=F.subarray(s,s*2);return new I(B.fromBytes(p),B.fromBytes(X),x)}static fromHex(F,E){return this.fromBytes(WB(F),E)}addRecoveryBit(F){return new I(this.r,this.s,F)}recoverPublicKey(F){let E=c.ORDER,{r:x,s,recovery:p}=this;if(p==null||![0,1,2,3].includes(p))throw new Error("recovery id invalid");if(e*Xy<E&&p>1)throw new Error("recovery id is ambiguous for h>1 curve");let o=p===2||p===3?x+e:x;if(!c.isValid(o))throw new Error("recovery id 2 or 3 invalid");let a=c.toBytes(o),V=l.fromBytes(VG(py((p&1)===0),a)),v=B.inv(o),S=f(ZG("msgHash",F)),z=B.create(-S*v),q=B.create(s*v),_=l.BASE.multiplyUnsafe(z).add(V.multiplyUnsafe(q));if(_.is0())throw new Error("point at infinify");return _.assertValidity(),_}hasHighS(){return R(this.s)}toBytes(F=Y){if(Ki(F),F==="der")return WB(bB.hexFromSig(this));let E=B.toBytes(this.r),x=B.toBytes(this.s);if(F==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return VG(Uint8Array.of(this.recovery),E,x)}return VG(E,x)}toHex(F){return Bt(this.toBytes(F))}assertValidity(){}static fromCompact(F){return I.fromBytes(ZG("sig",F),"compact")}static fromDER(F){return I.fromBytes(ZG("sig",F),"der")}normalizeS(){return this.hasHighS()?new I(this.r,B.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Bt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Bt(this.toBytes("compact"))}}let Q=G.bits2int||function(F){if(F.length>8192)throw new Error("input is too large");let E=Ne(F),x=F.length*8-d;return x>0?E>>BigInt(x):E},f=G.bits2int_modN||function(F){return B.create(Q(F))},U=Rc(d);function J(r){return Ee("num < 2^"+d,r,tB,U),B.toBytes(r)}function M(r,F){return mt(r,void 0,"message"),F?mt(A(r),void 0,"prehashed message"):r}function C(r,F,E){if(["recovered","canonical"].some(z=>z in E))throw new Error("sign() legacy options not supported");let{lowS:x,prehash:s,extraEntropy:p}=Pi(E,m);r=M(r,s);let X=f(r),o=cd(B,F),a=[J(o),J(X)];if(p!=null&&p!==!1){let z=p===!0?b(W.secretKey):p;a.push(ZG("extraEntropy",z))}let V=VG(...a),v=X;function S(z){let q=Q(z);if(!B.isValidNot0(q))return;let _=B.inv(q),T=l.BASE.multiply(q).toAffine(),H=B.create(T.x);if(H===tB)return;let w=B.create(_*B.create(v+H*o));if(w===tB)return;let L=(T.x===H?0:2)|Number(T.y&Bd),ll=w;return x&&R(w)&&(ll=B.neg(w),L^=1),new I(H,ll,L)}return{seed:V,k2sig:S}}function D(r,F,E={}){r=ZG("message",r);let{seed:x,k2sig:s}=C(r,F,E);return Si(A.outputLen,B.BYTES,t)(x,s)}function $(r){let F,E=typeof r=="string"||ft(r),x=!E&&r!==null&&typeof r=="object"&&typeof r.r=="bigint"&&typeof r.s=="bigint";if(!E&&!x)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(x)F=new I(r.r,r.s);else if(E){try{F=I.fromBytes(ZG("sig",r),"der")}catch(s){if(!(s instanceof bB.Err))throw s}if(!F)try{F=I.fromBytes(ZG("sig",r),"compact")}catch{return!1}}return F||!1}function K(r,F,E,x={}){let{lowS:s,prehash:p,format:X}=Pi(x,m);if(E=ZG("publicKey",E),F=M(ZG("message",F),p),"strict"in x)throw new Error("options.strict was renamed to lowS");let o=X===void 0?$(r):I.fromBytes(ZG("sig",r),X);if(o===!1)return!1;try{let a=l.fromBytes(E);if(s&&o.hasHighS())return!1;let{r:V,s:v}=o,S=f(F),z=B.inv(v),q=B.create(S*z),_=B.create(V*z),T=l.BASE.multiplyUnsafe(q).add(a.multiplyUnsafe(_));return T.is0()?!1:B.create(T.x)===V}catch{return!1}}function y(r,F,E={}){let{prehash:x}=Pi(E,m);return F=M(F,x),I.fromBytes(r,"recovered").recoverPublicKey(F).toBytes()}return Object.freeze({keygen:Z,getPublicKey:g,getSharedSecret:n,utils:h,lengths:W,Point:l,sign:D,verify:K,recoverPublicKey:y,Signature:I,hash:A})}function p5(l){let A={a:l.a,b:l.b,p:l.Fp.ORDER,n:l.n,h:l.h,Gx:l.Gx,Gy:l.Gy},G=l.Fp,b=l.allowedPrivateKeyLengths?Array.from(new Set(l.allowedPrivateKeyLengths.map(B=>Math.ceil(B/2)))):void 0,t=Vt(A.n,{BITS:l.nBitLength,allowedLengths:b,modFromBytes:l.wrapPrivateKey}),c={Fp:G,Fn:t,allowInfinityPoint:l.allowInfinityPoint,endo:l.endo,isTorsionFree:l.isTorsionFree,clearCofactor:l.clearCofactor,fromBytes:l.fromBytes,toBytes:l.toBytes};return{CURVE:A,curveOpts:c}}function F5(l){let{CURVE:A,curveOpts:G}=p5(l),b={hmac:l.hmac,randomBytes:l.randomBytes,lowS:l.lowS,bits2int:l.bits2int,bits2int_modN:l.bits2int_modN};return{CURVE:A,curveOpts:G,hash:l.hash,ecdsaOpts:b}}function y5(l,A){let G=A.Point;return Object.assign({},A,{ProjectivePoint:G,CURVE:Object.assign({},l,_W(G.Fn.ORDER,G.Fn.BITS))})}function yy(l){let{CURVE:A,curveOpts:G,hash:b,ecdsaOpts:t}=F5(l),c=I5(A,G),B=X5(c,b,t);return y5(l,B)}function Qy(l,A){let G=b=>yy({...l,hash:b});return{...G(A),create:G}}var $i={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Q5={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ny=BigInt(2);function N5(l){let A=$i.p,G=BigInt(3),b=BigInt(6),t=BigInt(11),c=BigInt(22),B=BigInt(23),e=BigInt(44),d=BigInt(88),Z=l*l*l%A,g=Z*Z*l%A,n=RG(g,G,A)*g%A,h=RG(n,G,A)*g%A,W=RG(h,Ny,A)*Z%A,m=RG(W,t,A)*W%A,Y=RG(m,c,A)*m%A,R=RG(Y,e,A)*Y%A,u=RG(R,d,A)*R%A,i=RG(u,e,A)*Y%A,I=RG(i,G,A)*g%A,Q=RG(I,B,A)*m%A,f=RG(Q,b,A)*Z%A,U=RG(f,Ny,A);if(!_i.eql(_i.sqr(U),l))throw new Error("Cannot find square root");return U}var _i=Vt($i.p,{sqrt:N5}),Xc=Qy({...$i,Fp:_i,lowS:!0,endo:Q5},ye);function qt(l,A){if(l.length!==32)throw new Error("Expected valid 32-byte private key as a seed");if(!PA||!A&&TA()){let G=KV(l),b=G.slice(32);if(Hd(b))throw new Error("Invalid publicKey generated from WASM interface");return{publicKey:b,secretKey:G.slice(0,32)}}return{publicKey:Xc.getPublicKey(l,!0),secretKey:l}}function Ao(l,A){return(G,{chainCode:b,isHard:t})=>{if(!t)throw new Error("A soft key was found in the path and is not supported");return l(A(G.secretKey.subarray(0,32),b))}}var lm=Ao(qt,By);var E5=be(uG("Ed25519HDKD"));function Am(l,A){if(!Hb(A)||A.length!==32)throw new Error("Invalid chainCode passed to derive");return Mb(nG(E5,l,A))}function ed(l=32){return Ja(new Uint8Array(l))}var wB=BigInt(0),hb=BigInt(1),Gm=BigInt(2),v5=BigInt(8);function H5(l,A,G,b){let t=l.sqr(G),c=l.sqr(b),B=l.add(l.mul(A.a,t),c),e=l.add(l.ONE,l.mul(A.d,l.mul(t,c)));return l.eql(B,e)}function J5(l,A={}){let G=$W("edwards",l,A,A.FpFnLE),{Fp:b,Fn:t}=G,c=G.CURVE,{h:B}=c;kB(A,{},{uvRatio:"function"});let e=Gm<<BigInt(t.BYTES*8)-hb,d=R=>b.create(R),Z=A.uvRatio||((R,u)=>{try{return{isValid:!0,value:b.sqrt(b.div(R,u))}}catch{return{isValid:!1,value:wB}}});if(!H5(b,c,c.Gx,c.Gy))throw new Error("bad curve params: generator point");function g(R,u,i=!1){let I=i?hb:wB;return Ee("coordinate "+R,u,I,e),u}function n(R){if(!(R instanceof m))throw new Error("ExtendedPoint expected")}let h=ve((R,u)=>{let{X:i,Y:I,Z:Q}=R,f=R.is0();u==null&&(u=f?v5:b.inv(Q));let U=d(i*u),J=d(I*u),M=b.mul(Q,u);if(f)return{x:wB,y:hb};if(M!==hb)throw new Error("invZ was invalid");return{x:U,y:J}}),W=ve(R=>{let{a:u,d:i}=c;if(R.is0())throw new Error("bad point: ZERO");let{X:I,Y:Q,Z:f,T:U}=R,J=d(I*I),M=d(Q*Q),C=d(f*f),D=d(C*C),$=d(J*u),K=d(C*d($+M)),y=d(D+d(i*d(J*M)));if(K!==y)throw new Error("bad point: equation left != right (1)");let r=d(I*Q),F=d(f*U);if(r!==F)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(u,i,I,Q){this.X=g("x",u),this.Y=g("y",i),this.Z=g("z",I,!0),this.T=g("t",Q),Object.freeze(this)}static CURVE(){return c}static fromAffine(u){if(u instanceof m)throw new Error("extended point not allowed");let{x:i,y:I}=u||{};return g("x",i),g("y",I),new m(i,I,hb,d(i*I))}static fromBytes(u,i=!1){let I=b.BYTES,{a:Q,d:f}=c;u=KW(mt(u,I,"point")),lB(i,"zip215");let U=KW(u),J=u[I-1];U[I-1]=J&-129;let M=Kt(U),C=i?e:b.ORDER;Ee("point.y",M,wB,C);let D=d(M*M),$=d(D-hb),K=d(f*D-Q),{isValid:y,value:r}=Z($,K);if(!y)throw new Error("bad point: invalid y coordinate");let F=(r&hb)===hb,E=(J&128)!==0;if(!i&&r===wB&&E)throw new Error("bad point: x=0 and x_0=1");return E!==F&&(r=d(-r)),m.fromAffine({x:r,y:M})}static fromHex(u,i=!1){return m.fromBytes(ZG("point",u),i)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(u=8,i=!0){return Y.createCache(this,u),i||this.multiply(Gm),this}assertValidity(){W(this)}equals(u){n(u);let{X:i,Y:I,Z:Q}=this,{X:f,Y:U,Z:J}=u,M=d(i*J),C=d(f*Q),D=d(I*J),$=d(U*Q);return M===C&&D===$}is0(){return this.equals(m.ZERO)}negate(){return new m(d(-this.X),this.Y,this.Z,d(-this.T))}double(){let{a:u}=c,{X:i,Y:I,Z:Q}=this,f=d(i*i),U=d(I*I),J=d(Gm*d(Q*Q)),M=d(u*f),C=i+I,D=d(d(C*C)-f-U),$=M+U,K=$-J,y=M-U,r=d(D*K),F=d($*y),E=d(D*y),x=d(K*$);return new m(r,F,x,E)}add(u){n(u);let{a:i,d:I}=c,{X:Q,Y:f,Z:U,T:J}=this,{X:M,Y:C,Z:D,T:$}=u,K=d(Q*M),y=d(f*C),r=d(J*I*$),F=d(U*D),E=d((Q+f)*(M+C)-K-y),x=F-r,s=F+r,p=d(y-i*K),X=d(E*x),o=d(s*p),a=d(E*p),V=d(x*s);return new m(X,o,V,a)}subtract(u){return this.add(u.negate())}multiply(u){if(!t.isValidNot0(u))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:i,f:I}=Y.cached(this,u,Q=>GB(m,Q));return GB(m,[i,I])[0]}multiplyUnsafe(u,i=m.ZERO){if(!t.isValid(u))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return u===wB?m.ZERO:this.is0()||u===hb?this:Y.unsafe(this,u,I=>GB(m,I),i)}isSmallOrder(){return this.multiplyUnsafe(B).is0()}isTorsionFree(){return Y.unsafe(this,c.n).is0()}toAffine(u){return h(this,u)}clearCofactor(){return B===hb?this:this.multiplyUnsafe(B)}toBytes(){let{x:u,y:i}=this.toAffine(),I=b.toBytes(i);return I[I.length-1]|=u&hb?128:0,I}toHex(){return Bt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(u){return GB(m,u)}static msm(u,i){return td(m,t,u,i)}_setWindowSize(u){this.precompute(u)}toRawBytes(){return this.toBytes()}}m.BASE=new m(c.Gx,c.Gy,hb,d(c.Gx*c.Gy)),m.ZERO=new m(wB,hb,hb,wB),m.Fp=b,m.Fn=t;let Y=new bd(m,t.BITS);return m.BASE.precompute(8),m}var Go=class{constructor(A){this.ep=A}static fromBytes(A){qW()}static fromHex(A){qW()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(A){return this.ep.toAffine(A)}toHex(){return Bt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(A){return this.assertSame(A),this.init(this.ep.add(A.ep))}subtract(A){return this.assertSame(A),this.init(this.ep.subtract(A.ep))}multiply(A){return this.init(this.ep.multiply(A))}multiplyUnsafe(A){return this.init(this.ep.multiplyUnsafe(A))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(A,G){return this.init(this.ep.precompute(A,G))}toRawBytes(){return this.toBytes()}};function x5(l,A,G={}){if(typeof A!="function")throw new Error('"hash" function param is required');kB(G,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:b}=G,{BASE:t,Fp:c,Fn:B}=l,e=G.randomBytes||Eb,d=G.adjustScalarBytes||(C=>C),Z=G.domain||((C,D,$)=>{if(lB($,"phflag"),D.length||$)throw new Error("Contexts/pre-hash are not supported");return C});function g(C){return B.create(Kt(C))}function n(C){let D=I.secretKey;C=ZG("private key",C,D);let $=ZG("hashed private key",A(C),2*D),K=d($.slice(0,D)),y=$.slice(D,2*D),r=g(K);return{head:K,prefix:y,scalar:r}}function h(C){let{head:D,prefix:$,scalar:K}=n(C),y=t.multiply(K),r=y.toBytes();return{head:D,prefix:$,scalar:K,point:y,pointBytes:r}}function W(C){return h(C).pointBytes}function m(C=Uint8Array.of(),...D){let $=VG(...D);return g(A(Z($,ZG("context",C),!!b)))}function Y(C,D,$={}){C=ZG("message",C),b&&(C=b(C));let{prefix:K,scalar:y,pointBytes:r}=h(D),F=m($.context,K,C),E=t.multiply(F).toBytes(),x=m($.context,E,r,C),s=B.create(F+x*y);if(!B.isValid(s))throw new Error("sign failed: invalid s");let p=VG(E,B.toBytes(s));return mt(p,I.signature,"result")}let R={zip215:!0};function u(C,D,$,K=R){let{context:y,zip215:r}=K,F=I.signature;C=ZG("signature",C,F),D=ZG("message",D),$=ZG("publicKey",$,I.publicKey),r!==void 0&&lB(r,"zip215"),b&&(D=b(D));let E=F/2,x=C.subarray(0,E),s=Kt(C.subarray(E,F)),p,X,o;try{p=l.fromBytes($,r),X=l.fromBytes(x,r),o=t.multiplyUnsafe(s)}catch{return!1}if(!r&&p.isSmallOrder())return!1;let a=m(y,X.toBytes(),p.toBytes(),D);return X.add(p.multiplyUnsafe(a)).subtract(o).clearCofactor().is0()}let i=c.BYTES,I={secretKey:i,publicKey:i,signature:2*i,seed:i};function Q(C=e(I.seed)){return mt(C,I.seed,"seed")}function f(C){let D=M.randomSecretKey(C);return{secretKey:D,publicKey:W(D)}}function U(C){return ft(C)&&C.length===B.BYTES}function J(C,D){try{return!!l.fromBytes(C,D)}catch{return!1}}let M={getExtendedPublicKey:h,randomSecretKey:Q,isValidSecretKey:U,isValidPublicKey:J,toMontgomery(C){let{y:D}=l.fromBytes(C),$=I.publicKey,K=$===32;if(!K&&$!==57)throw new Error("only defined for 25519 and 448");let y=K?c.div(hb+D,hb-D):c.div(D-hb,D+hb);return c.toBytes(y)},toMontgomerySecret(C){let D=I.secretKey;mt(C,D);let $=A(C.subarray(0,D));return d($).subarray(0,D)},randomPrivateKey:Q,precompute(C=8,D=l.BASE){return D.precompute(C,!1)}};return Object.freeze({keygen:f,getPublicKey:W,sign:Y,verify:u,utils:M,Point:l,lengths:I})}function f5(l){let A={a:l.a,d:l.d,p:l.Fp.ORDER,n:l.n,h:l.h,Gx:l.Gx,Gy:l.Gy},G=l.Fp,b=Vt(A.n,l.nBitLength,!0),t={Fp:G,Fn:b,uvRatio:l.uvRatio},c={randomBytes:l.randomBytes,adjustScalarBytes:l.adjustScalarBytes,domain:l.domain,prehash:l.prehash,mapToCurve:l.mapToCurve};return{CURVE:A,curveOpts:t,hash:l.hash,eddsaOpts:c}}function k5(l,A){let G=A.Point;return Object.assign({},A,{ExtendedPoint:G,CURVE:l,nBitLength:G.Fn.BITS,nByteLength:G.Fn.BYTES})}function Ey(l){let{CURVE:A,curveOpts:G,hash:b,eddsaOpts:t}=f5(l),c=J5(A,G),B=x5(c,b,t);return k5(l,B)}var w5=BigInt(0),cB=BigInt(1),vy=BigInt(2),ztl=BigInt(3),U5=BigInt(5),C5=BigInt(8),Zd=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),jn={p:Zd,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:C5,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function S5(l){let A=BigInt(10),G=BigInt(20),b=BigInt(40),t=BigInt(80),c=Zd,e=l*l%c*l%c,d=RG(e,vy,c)*e%c,Z=RG(d,cB,c)*l%c,g=RG(Z,U5,c)*Z%c,n=RG(g,A,c)*g%c,h=RG(n,G,c)*n%c,W=RG(h,b,c)*h%c,m=RG(W,t,c)*W%c,Y=RG(m,t,c)*W%c,R=RG(Y,A,c)*g%c;return{pow_p_5_8:RG(R,vy,c)*l%c,b2:e}}function z5(l){return l[0]&=248,l[31]&=127,l[31]|=64,l}var bm=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Bm(l,A){let G=Zd,b=IG(A*A*A,G),t=IG(b*b*A,G),c=S5(l*t).pow_p_5_8,B=IG(l*b*c,G),e=IG(A*B*B,G),d=B,Z=IG(B*bm,G),g=e===l,n=e===IG(-l,G),h=e===IG(-l*bm,G);return g&&(B=d),(n||h)&&(B=Z),AB(B,G)&&(B=IG(-B,G)),{isValid:g||n,value:B}}var UB=Vt(jn.p,{isLE:!0}),j5=Vt(jn.n,{isLE:!0}),M5={...jn,Fp:UB,hash:OW,adjustScalarBytes:z5,uvRatio:Bm},Lb=Ey(M5);var tm=bm,T5=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),D5=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),L5=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),O5=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Hy=l=>Bm(cB,l),P5=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),cm=l=>Lb.Point.Fp.create(Kt(l)&P5);function Jy(l){let{d:A}=jn,G=Zd,b=u=>UB.create(u),t=b(tm*l*l),c=b((t+cB)*L5),B=BigInt(-1),e=b((B-A*t)*b(t+A)),{isValid:d,value:Z}=Bm(c,e),g=b(Z*l);AB(g,G)||(g=b(-g)),d||(Z=g),d||(B=t);let n=b(B*(t-cB)*O5-e),h=Z*Z,W=b((Z+Z)*e),m=b(n*T5),Y=b(cB-h),R=b(cB+h);return new Lb.Point(b(W*R),b(Y*m),b(m*R),b(W*Y))}function K5(l){fG(l,64);let A=cm(l.subarray(0,32)),G=Jy(A),b=cm(l.subarray(32,64)),t=Jy(b);return new pc(G.add(t))}var pc=class l extends Go{constructor(A){super(A)}static fromAffine(A){return new l(Lb.Point.fromAffine(A))}assertSame(A){if(!(A instanceof l))throw new Error("RistrettoPoint expected")}init(A){return new l(A)}static hashToCurve(A){return K5(ZG("ristrettoHash",A,64))}static fromBytes(A){fG(A,32);let{a:G,d:b}=jn,t=Zd,c=Q=>UB.create(Q),B=cm(A);if(!Ui(UB.toBytes(B),A)||AB(B,t))throw new Error("invalid ristretto255 encoding 1");let e=c(B*B),d=c(cB+G*e),Z=c(cB-G*e),g=c(d*d),n=c(Z*Z),h=c(G*b*g-n),{isValid:W,value:m}=Hy(c(h*n)),Y=c(m*Z),R=c(m*Y*h),u=c((B+B)*Y);AB(u,t)&&(u=c(-u));let i=c(d*R),I=c(u*i);if(!W||AB(I,t)||i===w5)throw new Error("invalid ristretto255 encoding 2");return new l(new Lb.Point(u,i,cB,I))}static fromHex(A){return l.fromBytes(ZG("ristrettoHex",A,32))}static msm(A,G){return td(l,Lb.Point.Fn,A,G)}toBytes(){let{X:A,Y:G,Z:b,T:t}=this.ep,c=Zd,B=R=>UB.create(R),e=B(B(b+G)*B(b-G)),d=B(A*G),Z=B(d*d),{value:g}=Hy(B(e*Z)),n=B(g*e),h=B(g*d),W=B(n*h*t),m;if(AB(t*W,c)){let R=B(G*tm),u=B(A*tm);A=R,G=u,m=B(n*D5)}else m=h;AB(A*W,c)&&(G=B(-G));let Y=B((b-G)*m);return AB(Y,c)&&(Y=B(-Y)),UB.toBytes(Y)}equals(A){this.assertSame(A);let{X:G,Y:b}=this.ep,{X:t,Y:c}=A.ep,B=Z=>UB.create(Z),e=B(G*c)===B(b*t),d=B(b*c)===B(G*t);return e||d}is0(){return this.equals(l.ZERO)}};pc.BASE=new pc(Lb.Point.BASE);pc.ZERO=new pc(Lb.Point.ZERO);pc.Fp=UB;pc.Fn=j5;var PG=pc;function xe(l,A){if(!PA||!A&&TA()){let b=LV(l);return{publicKey:b.slice(32),secretKey:b.slice(0,64)}}let G=Lb.getPublicKey(l);return{publicKey:G,secretKey:Zc([l,G])}}function em(l,{publicKey:A,secretKey:G},b){if(G){if(!A)throw new Error("Expected a valid publicKey")}else throw new Error("Expected a valid secretKey");let t=Tl(l),c=G.subarray(0,32);return!PA||!b&&TA()?OV(A,c,t):Lb.sign(t,c)}function xy(l,A,G,b){let t=Tl(l),c=Tl(G),B=Tl(A);if(c.length!==32)throw new Error(`Invalid publicKey, received ${c.length}, expected 32`);if(B.length!==64)throw new Error(`Invalid signature, received ${B.length} bytes, expected 64`);try{return!PA||!b&&TA()?PV(B,t,c):Lb.verify(B,t,c)}catch{return!1}}var fy=Ao(xe,Am);var Zm=ft;var dd=Kt;var _t=Un;var dm=Ee;var ky=Rc;var q5=BigInt(0),Mn=BigInt(1),_5=BigInt(2),$5=BigInt(7),lJ=BigInt(256),AJ=BigInt(113),Cy=[],Sy=[],zy=[];for(let l=0,A=Mn,G=1,b=0;l<24;l++){[G,b]=[b,(2*G+3*b)%5],Cy.push(2*(5*b+G)),Sy.push((l+1)*(l+2)/2%64);let t=q5;for(let c=0;c<7;c++)A=(A<<Mn^(A>>$5)*AJ)%lJ,A&_5&&(t^=Mn<<(Mn<<BigInt(c))-Mn);zy.push(t)}var jy=Ia(zy,!0),GJ=jy[0],bJ=jy[1],wy=(l,A,G)=>G>32?bV(l,A,G):AV(l,A,G),Uy=(l,A,G)=>G>32?tV(l,A,G):GV(l,A,G);function am(l,A=24){let G=new Uint32Array(10);for(let b=24-A;b<24;b++){for(let B=0;B<10;B++)G[B]=l[B]^l[B+10]^l[B+20]^l[B+30]^l[B+40];for(let B=0;B<10;B+=2){let e=(B+8)%10,d=(B+2)%10,Z=G[d],g=G[d+1],n=wy(Z,g,1)^G[e],h=Uy(Z,g,1)^G[e+1];for(let W=0;W<50;W+=10)l[B+W]^=n,l[B+W+1]^=h}let t=l[2],c=l[3];for(let B=0;B<24;B++){let e=Sy[B],d=wy(t,c,e),Z=Uy(t,c,e),g=Cy[B];t=l[g],c=l[g+1],l[g]=d,l[g+1]=Z}for(let B=0;B<50;B+=10){for(let e=0;e<10;e++)G[e]=l[B+e];for(let e=0;e<10;e++)l[B+e]^=~G[(e+2)%10]&G[(e+4)%10]}l[0]^=GJ[b],l[1]^=bJ[b]}MG(G)}var nm=class l extends bc{constructor(A,G,b,t=!1,c=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=A,this.suffix=G,this.outputLen=b,this.enableXOF=t,this.rounds=c,mG(b),!(0<A&&A<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=tt(this.state)}clone(){return this._cloneInto()}keccak(){ct(this.state32),am(this.state32,this.rounds),ct(this.state32),this.posOut=0,this.pos=0}update(A){Xt(this),A=et(A),fG(A);let{blockLen:G,state:b}=this,t=A.length;for(let c=0;c<t;){let B=Math.min(G-this.pos,t-c);for(let e=0;e<B;e++)b[this.pos++]^=A[c++];this.pos===G&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:A,suffix:G,pos:b,blockLen:t}=this;A[b]^=G,G&128&&b===t-1&&this.keccak(),A[t-1]^=128,this.keccak()}writeInto(A){Xt(this,!1),fG(A),this.finish();let G=this.state,{blockLen:b}=this;for(let t=0,c=A.length;t<c;){this.posOut>=b&&this.keccak();let B=Math.min(b-this.posOut,c-t);A.set(G.subarray(this.posOut,this.posOut+B),t),this.posOut+=B,t+=B}return A}xofInto(A){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(A)}xof(A){return mG(A),this.xofInto(new Uint8Array(A))}digestInto(A){if(_e(A,this),this.finished)throw new Error("digest() was already called");return this.writeInto(A),this.destroy(),A}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,MG(this.state)}_cloneInto(A){let{blockLen:G,suffix:b,outputLen:t,rounds:c,enableXOF:B}=this;return A||(A=new l(G,b,t,B,c)),A.state32.set(this.state32),A.pos=this.pos,A.posOut=this.posOut,A.finished=this.finished,A.rounds=c,A.suffix=b,A.outputLen=t,A.enableXOF=B,A.destroyed=this.destroyed,A}},My=(l,A,G)=>Fd(()=>new nm(A,l,G));var bo=My(1,136,256/8);var Ty=My(1,72,512/8);var CB=OW;var Py=BigInt(0),Ky=BigInt(3);function gm(l){if(typeof l=="string")return Ec(l);if(Zm(l))return l;throw new Error("Wrong data")}function NG(l,A,...G){if(!Zm(A))throw new Error(`${l}: Uint8Array expected`);if(G.length&&!G.includes(A.length))throw new Error(`${l}: Uint8Array expected of length ${G}, not of length=${A.length}`)}function to(l,A){if(!Number.isSafeInteger(A)||A<0||A>4294967295)throw new Error(`${l}: wrong u32 integer: ${A}`);return A}function nd(...l){for(let A of l)A.fill(0)}var fe=Uint8Array.of(),hm=Lb.CURVE.n;function Dy(l,A){NG(l,A,32);let G=dd(A);return dm(l,G,Py,hm),G}var Dn=l=>IG(l,hm),Tn=166,$t={I:1,A:2,C:4,T:8,M:16,K:32},Wm=class l{constructor(A){this.state=new Uint8Array(200),this.pos=0,this.posBegin=0,this.curFlags=0,this.state.set([1,Tn+2,1,0,1,96],0),this.state.set(Ec("STROBEv1.0.2"),6),this.state32=tt(this.state),this.keccakF1600(),this.metaAD(A,!1)}keccakF1600(){am(this.state32)}runF(){this.state[this.pos]^=this.posBegin,this.state[this.pos+1]^=4,this.state[Tn+1]^=128,this.keccakF1600(),this.pos=0,this.posBegin=0}absorb(A){for(let G=0;G<A.length;G++)this.state[this.pos++]^=A[G],this.pos===Tn&&this.runF()}squeeze(A){let G=new Uint8Array(A);for(let b=0;b<G.length;b++)G[b]=this.state[this.pos],this.state[this.pos++]=0,this.pos===Tn&&this.runF();return G}overwrite(A){for(let G=0;G<A.length;G++)this.state[this.pos++]=A[G],this.pos===Tn&&this.runF()}beginOp(A,G){if(G){if(this.curFlags!==A)throw new Error(`Continued op with changed flags from ${this.curFlags.toString(2)} to ${A.toString(2)}`);return}if(A&$t.T)throw new Error("T flag is not supported");let b=this.posBegin;this.posBegin=this.pos+1,this.curFlags=A,this.absorb(new Uint8Array([b,A])),(A&($t.C|$t.K))!==0&&this.pos!==0&&this.runF()}metaAD(A,G){this.beginOp($t.M|$t.A,G),this.absorb(gm(A))}AD(A,G){this.beginOp($t.A,G),this.absorb(gm(A))}PRF(A,G){return this.beginOp($t.I|$t.A|$t.C,G),this.squeeze(A)}KEY(A,G){this.beginOp($t.A|$t.C,G),this.overwrite(gm(A))}clone(){let A=new l("0");return A.pos=this.pos,A.posBegin=this.posBegin,A.state.set(this.state),A.curFlags=this.curFlags,A}clean(){this.state.fill(0),this.pos=0,this.curFlags=0,this.posBegin=0}},om=class{constructor(A){this.strobe=new Wm("Merlin v1.0"),this.appendMessage("dom-sep",A)}appendMessage(A,G){this.strobe.metaAD(A,!1),to("Merlin.appendMessage",G.length),this.strobe.metaAD(_t(G.length,4),!0),this.strobe.AD(G,!1)}challengeBytes(A,G){return this.strobe.metaAD(A,!1),to("Merlin.challengeBytes",G),this.strobe.metaAD(_t(G,4),!0),this.strobe.PRF(G,!1)}clean(){this.strobe.clean()}},BB=class extends om{constructor(A,G=Eb){super(A),this.rng=G}label(A){this.appendMessage("",A)}bytes(A){return this.appendMessage("sign-bytes",A),this}protoName(A){this.appendMessage("proto-name",A)}commitPoint(A,G){this.appendMessage(A,G.toRawBytes())}challengeScalar(A){return Dn(dd(this.challengeBytes(A,64)))}witnessScalar(A,G=[]){return Dn(dd(this.witnessBytes(A,64,G)))}witnessBytes(A,G,b=[]){to("SigningContext.witnessBytes",G);let t=this.strobe.clone();for(let B of b)t.metaAD(A,!1),to("SigningContext.witnessBytes nonce length",B.length),t.metaAD(_t(B.length,4),!0),t.KEY(B,!1);let c=this.rng(32);return t.metaAD("rng",!1),t.KEY(c,!1),t.metaAD(_t(G,4),!1),t.PRF(G,!1)}},tJ=ky(256),qy=l=>_t(l<<Ky&tJ,32),ad=l=>dd(l)>>Ky;function ke(l){NG("secretKey",l,64);let A=ad(l.subarray(0,32));return PG.BASE.multiply(A).toRawBytes()}function sm(l){NG("seed",l,32);let A=CB(l);A[0]&=248,A[31]&=63,A[31]|=64;let G=qy(ad(A.subarray(0,32))),b=A.subarray(32,64),t=VG(G,b);return nd(G,b,A),t}var _y=Ec("substrate");function $y(l,A,G=Eb){NG("message",A),NG("secretKey",l,64);let b=new BB("SigningContext",G);b.label(_y),b.bytes(A);let t=ad(l.subarray(0,32)),c=l.subarray(32,64),B=PG.fromHex(ke(l));b.protoName("Schnorr-sig"),b.commitPoint("sign:pk",B);let e=b.witnessScalar("signing",[c]),d=PG.BASE.multiply(e);b.commitPoint("sign:R",d);let Z=b.challengeScalar("sign:c"),g=Dn(Z*t+e),n=VG(d.toRawBytes(),_t(g,32));return n[63]|=128,b.clean(),n}function lQ(l,A,G){if(NG("message",l),NG("signature",A,64),NG("publicKey",G,32),!(A[63]&128))throw new Error("Schnorrkel marker missing");let b=Uint8Array.from(A.subarray(32,64));b[31]&=127;let t=PG.fromHex(A.subarray(0,32)),c=dd(b);dm("s",c,Py,hm);let B=new BB("SigningContext");B.label(_y),B.bytes(l);let e=PG.fromHex(G);if(e.equals(PG.ZERO))return!1;B.protoName("Schnorr-sig"),B.commitPoint("sign:pk",e),B.commitPoint("sign:R",t);let d=B.challengeScalar("sign:c"),Z=PG.BASE.multiply(c),g=e.negate().multiply(d).add(Z);return B.clean(),nd(b),g.equals(t)}var co={secretSoft(l,A,G=Eb){NG("secretKey",l,64),NG("chainCode",A,32);let b=ad(l.subarray(0,32)),t=l.subarray(32,64),c=PG.fromHex(ke(l)),B=new BB("SchnorrRistrettoHDKD",G);B.bytes(fe),B.appendMessage("chain-code",A),B.commitPoint("public-key",c);let e=B.challengeScalar("HDKD-scalar"),d=B.challengeBytes("HDKD-chaincode",32),Z=VG(_t(b,32),t),g=B.witnessBytes("HDKD-nonce",32,[t,Z]),n=qy(Dn(b+e)),h=VG(n,g);return nd(n,g,Z,d),B.clean(),h},publicSoft(l,A){NG("publicKey",l,32),NG("chainCode",A,32);let G=PG.fromHex(l),b=new BB("SchnorrRistrettoHDKD");b.bytes(fe),b.appendMessage("chain-code",A),b.commitPoint("public-key",G);let t=b.challengeScalar("HDKD-scalar");return b.challengeBytes("HDKD-chaincode",32),b.clean(),G.add(PG.BASE.multiply(t)).toRawBytes()},secretHard(l,A){NG("secretKey",l,64),NG("chainCode",A,32);let G=_t(ad(l.subarray(0,32)),32),b=new BB("SchnorrRistrettoHDKD");b.bytes(fe),b.appendMessage("chain-code",A),b.appendMessage("secret-key",G);let t=b.challengeBytes("HDKD-hard",32),c=b.challengeBytes("HDKD-chaincode",32);b.clean();let B=sm(t);return nd(G,t,c),b.clean(),B}},Ly={proove(l,A,G,b,t,c){b.protoName("DLEQProof"),b.commitPoint("vrf:h",t);let B=b.witnessScalar("proving\x000",[A]),e=PG.BASE.multiply(B);b.commitPoint("vrf:R=g^r",e);let d=t.multiply(B);b.commitPoint("vrf:h^r",d),b.commitPoint("vrf:pk",G),b.commitPoint("vrf:h^sk",c);let Z=b.challengeScalar("prove"),g=Dn(B-Z*l);return{proof:{c:Z,s:g},proofBatchable:{R:e,Hr:d,s:g}}},verify(l,A,G,b,t){if(l.equals(PG.ZERO))return!1;A.protoName("DLEQProof"),A.commitPoint("vrf:h",G);let c=l.multiply(t.c).add(PG.BASE.multiply(t.s));A.commitPoint("vrf:R=g^r",c);let B=b.multiply(t.c).add(G.multiply(t.s));A.commitPoint("vrf:h^r",B),A.commitPoint("vrf:pk",l),A.commitPoint("vrf:h^sk",b);let e=A.challengeScalar("prove");return t.c===e?{R:c,Hr:B,s:t.s}:!1}};function Oy(l,A,G,b,t=Eb){let c=new BB("SigningContext",t);c.label(l),c.bytes(A),c.commitPoint("vrf-nm-pk",b);let B=c.challengeBytes("VRFHash",64),e=PG.hashToCurve(B),d=new BB("VRF",t);return G.length&&d.label(G),c.clean(),nd(B),{input:e,t:d}}var Bo={sign(l,A,G=fe,b=fe,t=Eb){NG("msg",l),NG("secretKey",A,64),NG("ctx",G),NG("extra",b);let c=ad(A.subarray(0,32)),B=A.subarray(32,64),e=PG.fromHex(ke(A)),{input:d,t:Z}=Oy(G,l,b,e,t),g=d.multiply(c),n={input:d,output:g},{proof:h}=Ly.proove(c,B,e,Z,d,g),W=_t(h.c,32),m=_t(h.s,32),Y=VG(n.output.toRawBytes(),W,m);return nd(B,W,m),Y},verify(l,A,G,b=fe,t=fe,c=Eb){NG("msg",l),NG("signature",A,96),NG("pubkey",G,32),NG("ctx",b),NG("extra",t);let B=PG.fromHex(G);if(B.equals(PG.ZERO))return!1;let e={c:Dy("signature.c",A.subarray(32,64)),s:Dy("signature.s",A.subarray(64,96))},{input:d,t:Z}=Oy(b,l,t,B,c),g=PG.fromHex(A.subarray(0,32));if(g.equals(PG.ZERO))throw new Error("vrf.verify: wrong output point (identity)");return Ly.verify(B,Z,d,g,e)!==!1}};function eo(l){return(A,G)=>{if(!Hb(G)||G.length!==32)throw new Error("Invalid chainCode passed to derive");let b=l(A.secretKey,G);return{publicKey:ke(b),secretKey:b}}}var AQ=eo(co.secretHard);var GQ=eo(co.secretSoft);function bQ(l,{chainCode:A,isSoft:G}){return G?GQ(l,A):AQ(l,A)}var cJ={ecdsa:lm,ed25519:fy,ethereum:lm,sr25519:bQ};function Ln(l,A,G){let b=cJ[G],t=l;for(let c of A)t=b(t,c);return t}function On(l){let A=Tl(l);if(A.length!==32)throw new Error(`Expected a seed matching 32 bytes, found ${A.length}`);let G=sm(A);return{publicKey:ke(G),secretKey:G}}function rm(l,{publicKey:A,secretKey:G}){if(A?.length!==32)throw new Error("Expected a valid publicKey, 32-bytes");if(G?.length!==64)throw new Error("Expected a valid secretKey, 64-bytes");return $y(G,Tl(l))}function tQ(l,A,G){let b=Tl(G),t=Tl(A);if(b.length!==32)throw new Error(`Invalid publicKey, received ${b.length} bytes, expected 32`);if(t.length!==64)throw new Error(`Invalid signature, received ${t.length} bytes, expected 64`);return lQ(Tl(l),t,b)}var cQ=new Uint8Array;function im(l,{secretKey:A},G=cQ,b=cQ){if(A?.length!==64)throw new Error("Invalid secretKey, expected 64-bytes");return Bo.sign(Tl(l),A,Tl(G),Tl(b),Eb)}var BQ=new Uint8Array;function mm(l,A,G,b=BQ,t=BQ){let c=Tl(G),B=Tl(A);if(c.length!==32)throw new Error("Invalid publicKey, expected 32-bytes");if(B.length!==96)throw new Error("Invalid vrfSign output, expected 96 bytes");return Bo.verify(Tl(l),B,c,Tl(b),Tl(t))}function Pn(l,A=$Z.prefix){let G=Pt(l);if(A<0||A>16383&&!BJ.includes(A)||[46,47].includes(A))throw new Error("Out of range ss58Format specified");if(!$Z.allowedDecodedLengths.includes(G.length))throw new Error(`Expected a valid key to convert, with length ${$Z.allowedDecodedLengths.join(", ")}`);let b=nG(A<64?[A]:[(A&252)>>2|64,A>>8|(A&3)<<6],G);return Fi(nG(b,SW(b).subarray(0,[32,33].includes(G.length)?2:1)))}var BJ=[29972];var zB=Ua({256:tu,512:cu},{256:bo,512:Ty});function Kn(l,A,G){return l==="keccak"?zB(A,void 0,G):Mb(A,void 0,void 0,G)}var Vm={chars:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",coder:qF,type:"base64",withPadding:!0},eQ=CW(Vm);var um=wW(Vm,eQ),Ym=UW(Vm);function qn(l,A){if(![33,65].includes(l.length))throw new Error(`Invalid publicKey provided, received ${l.length} bytes input`);return l.length===33?l:!PA||!A&&TA()?qV(l):Xc.ProjectivePoint.fromHex(l).toRawBytes(!0)}function we(l,A){if(![33,65].includes(l.length))throw new Error(`Invalid publicKey provided, received ${l.length} bytes input`);if(l.length===65)return l.subarray(1);if(!PA||!A&&TA())return _V(l).subarray(1);let{x:G,y:b}=Xc.ProjectivePoint.fromHex(l);return nG(kG(G,$c),kG(b,$c))}function ZQ(l,A,G,b="blake2",t){let c=Tl(A).subarray(0,64),B=Tl(l),e=!PA||!t&&TA()?$V(B,c,G):Xc.Signature.fromCompact(c).addRecoveryBit(G).recoverPublicKey(B).toRawBytes();if(!e)throw new Error("Unable to recover publicKey from signature");return b==="keccak"?we(e,t):qn(e,t)}function Zo(l,{secretKey:A},G="blake2",b){if(A?.length!==32)throw new Error("Expected valid secp256k1 secretKey, 32-bytes");let t=Kn(G,l,b);if(!PA||!b&&TA())return lu(t,A);let c=Xc.sign(t,A,{lowS:!0});return nG(kG(c.r,$c),kG(c.s,$c),new Uint8Array([c.recovery||0]))}var dQ="ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141".replace(/ /g,""),Im=UA(`0x${dQ}`),Rm=new pA.default(dQ,"hex");function eJ(l,A){let G=bZ(A,vi);if(G>=Im)throw new Error("Tweak parameter is out of range");if(G+=bZ(l,vi),G>=Im&&(G-=Im),G===AZ)throw new Error("Invalid resulting private key");return $o(G,$c)}function ZJ(l,A){let G=new pA.default(A);if(G.cmp(Rm)>=0)throw new Error("Tweak parameter is out of range");if(G.iadd(new pA.default(l)),G.cmp(Rm)>=0&&G.isub(Rm),G.isZero())throw new Error("Invalid resulting private key");return kG(G,$c)}function Xm(l,A,G){if(!Hb(l)||l.length!==32)throw new Error("Expected seckey to be an Uint8Array with length 32");if(!Hb(A)||A.length!==32)throw new Error("Expected tweak to be an Uint8Array with length 32");return!PA||G?ZJ(l,A):eJ(l,A)}function nQ(l,A,G,b="blake2",t){let c=Tl(A);if(c.length!==65)throw new Error(`Expected signature with 65 bytes, ${c.length} found instead`);let B=ZQ(Kn(b,l),c,c[64],b,t),e=Kn(b,B,t),d=Tl(G);return jb(B,d)||(b==="keccak"?jb(e.slice(-20),d.slice(-20)):jb(e,d))}function dJ(l){return[33,65].includes(l.length)&&(l=zB(we(l))),l.slice(-20)}function _n(l){if(!l)return"0x";let A=Tl(l);if(![20,32,33,65].includes(A.length))throw new Error(`Invalid address or publicKey provided, received ${A.length} bytes input`);let G=dt(dJ(A),-1,!1),b=dt(zB(G),-1,!1),t="";for(let c=0;c<40;c++)t=`${t}${parseInt(b[c],16)>7?G[c].toUpperCase():G[c]}`;return`0x${t}`}var no=ye;var nJ={256:no,512:CB},aJ={256:Gu,512:bu};function ao(l,A,G=256,b){let t=Tl(l);return!PA||!b&&TA()?aJ[G](t,A):Qe(nJ[G],t,A)}function aQ(l){if(!l.startsWith("m/"))return!1;let A=l.split("/").slice(1);for(let G of A){let b=/^\d+'?$/.test(G)?parseInt(G.replace(/'$/,""),10):Number.NaN;if(isNaN(b)||b>=2147483648||b<0)return!1}return!0}var gJ=uG("Bitcoin seed");function WQ(l,A){return{chainCode:A,publicKey:qt(l).publicKey,secretKey:l}}function oQ(l,A){let G=kG(A,ty),b=A>=2147483648?nG(new Uint8Array(1),l.secretKey,G):nG(l.publicKey,G);try{let t=ao(l.chainCode,b,512);return WQ(Xm(l.secretKey,t.slice(0,32)),t.slice(32))}catch{return oQ(l,A+1)}}function pm(l,A=""){let G=ao(gJ,l,512),b=WQ(G.slice(0,32),G.slice(32));if(!A||A==="m"||A==="M"||A==="m'"||A==="M'")return b;if(!aQ(A))throw new Error("Invalid derivation path");let t=A.split("/").slice(1);for(let c of t)b=oQ(b,parseInt(c,10)+(c.length>1&&c.endsWith("'")?2147483648:0));return b}function oJ(l,A,G,b){qe(l);let t=ua({dkLen:32,asyncTick:10},b),{c,dkLen:B,asyncTick:e}=t;if(mG(c),mG(B),mG(e),c<1)throw new Error("iterations (c) should be >= 1");let d=Co(A),Z=Co(G),g=new Uint8Array(B),n=Qe.create(l,d),h=n._cloneInto().update(Z);return{c,dkLen:B,asyncTick:e,DK:g,PRF:n,PRFSalt:h}}function hJ(l,A,G,b,t){return l.destroy(),A.destroy(),b&&b.destroy(),MG(t),G}function $n(l,A,G,b){let{c:t,dkLen:c,DK:B,PRF:e,PRFSalt:d}=oJ(l,A,G,b),Z,g=new Uint8Array(4),n=$e(g),h=new Uint8Array(e.outputLen);for(let W=1,m=0;m<c;W++,m+=e.outputLen){let Y=B.subarray(m,m+e.outputLen);n.setInt32(0,W,!1),(Z=d._cloneInto(Z)).update(g).digestInto(h),Y.set(h.subarray(0,Y.length));for(let R=1;R<t;R++){e._cloneInto(Z).update(h).digestInto(h);for(let u=0;u<Y.length;u++)Y[u]^=h[u]}}return hJ(e,d,B,Z,h)}function la(l,A=ed(),G=2048,b){let t=Tl(l),c=Tl(A);return{password:!PA||!b&&TA()?Bu(t,c,G):$n(CB,t,c,{c:G,dkLen:64}),rounds:G,salt:A}}var hQ=Ua({256:Zu,512:du},{256:no,512:CB}),Fm=dh(256,hQ);var sQ="abandon|ability|able|about|above|absent|absorb|abstract|absurd|abuse|access|accident|account|accuse|achieve|acid|acoustic|acquire|across|act|action|actor|actress|actual|adapt|add|addict|address|adjust|admit|adult|advance|advice|aerobic|affair|afford|afraid|again|age|agent|agree|ahead|aim|air|airport|aisle|alarm|album|alcohol|alert|alien|all|alley|allow|almost|alone|alpha|already|also|alter|always|amateur|amazing|among|amount|amused|analyst|anchor|ancient|anger|angle|angry|animal|ankle|announce|annual|another|answer|antenna|antique|anxiety|any|apart|apology|appear|apple|approve|april|arch|arctic|area|arena|argue|arm|armed|armor|army|around|arrange|arrest|arrive|arrow|art|artefact|artist|artwork|ask|aspect|assault|asset|assist|assume|asthma|athlete|atom|attack|attend|attitude|attract|auction|audit|august|aunt|author|auto|autumn|average|avocado|avoid|awake|aware|away|awesome|awful|awkward|axis|baby|bachelor|bacon|badge|bag|balance|balcony|ball|bamboo|banana|banner|bar|barely|bargain|barrel|base|basic|basket|battle|beach|bean|beauty|because|become|beef|before|begin|behave|behind|believe|below|belt|bench|benefit|best|betray|better|between|beyond|bicycle|bid|bike|bind|biology|bird|birth|bitter|black|blade|blame|blanket|blast|bleak|bless|blind|blood|blossom|blouse|blue|blur|blush|board|boat|body|boil|bomb|bone|bonus|book|boost|border|boring|borrow|boss|bottom|bounce|box|boy|bracket|brain|brand|brass|brave|bread|breeze|brick|bridge|brief|bright|bring|brisk|broccoli|broken|bronze|broom|brother|brown|brush|bubble|buddy|budget|buffalo|build|bulb|bulk|bullet|bundle|bunker|burden|burger|burst|bus|business|busy|butter|buyer|buzz|cabbage|cabin|cable|cactus|cage|cake|call|calm|camera|camp|can|canal|cancel|candy|cannon|canoe|canvas|canyon|capable|capital|captain|car|carbon|card|cargo|carpet|carry|cart|case|cash|casino|castle|casual|cat|catalog|catch|category|cattle|caught|cause|caution|cave|ceiling|celery|cement|census|century|cereal|certain|chair|chalk|champion|change|chaos|chapter|charge|chase|chat|cheap|check|cheese|chef|cherry|chest|chicken|chief|child|chimney|choice|choose|chronic|chuckle|chunk|churn|cigar|cinnamon|circle|citizen|city|civil|claim|clap|clarify|claw|clay|clean|clerk|clever|click|client|cliff|climb|clinic|clip|clock|clog|close|cloth|cloud|clown|club|clump|cluster|clutch|coach|coast|coconut|code|coffee|coil|coin|collect|color|column|combine|come|comfort|comic|common|company|concert|conduct|confirm|congress|connect|consider|control|convince|cook|cool|copper|copy|coral|core|corn|correct|cost|cotton|couch|country|couple|course|cousin|cover|coyote|crack|cradle|craft|cram|crane|crash|crater|crawl|crazy|cream|credit|creek|crew|cricket|crime|crisp|critic|crop|cross|crouch|crowd|crucial|cruel|cruise|crumble|crunch|crush|cry|crystal|cube|culture|cup|cupboard|curious|current|curtain|curve|cushion|custom|cute|cycle|dad|damage|damp|dance|danger|daring|dash|daughter|dawn|day|deal|debate|debris|decade|december|decide|decline|decorate|decrease|deer|defense|define|defy|degree|delay|deliver|demand|demise|denial|dentist|deny|depart|depend|deposit|depth|deputy|derive|describe|desert|design|desk|despair|destroy|detail|detect|develop|device|devote|diagram|dial|diamond|diary|dice|diesel|diet|differ|digital|dignity|dilemma|dinner|dinosaur|direct|dirt|disagree|discover|disease|dish|dismiss|disorder|display|distance|divert|divide|divorce|dizzy|doctor|document|dog|doll|dolphin|domain|donate|donkey|donor|door|dose|double|dove|draft|dragon|drama|drastic|draw|dream|dress|drift|drill|drink|drip|drive|drop|drum|dry|duck|dumb|dune|during|dust|dutch|duty|dwarf|dynamic|eager|eagle|early|earn|earth|easily|east|easy|echo|ecology|economy|edge|edit|educate|effort|egg|eight|either|elbow|elder|electric|elegant|element|elephant|elevator|elite|else|embark|embody|embrace|emerge|emotion|employ|empower|empty|enable|enact|end|endless|endorse|enemy|energy|enforce|engage|engine|enhance|enjoy|enlist|enough|enrich|enroll|ensure|enter|entire|entry|envelope|episode|equal|equip|era|erase|erode|erosion|error|erupt|escape|essay|essence|estate|eternal|ethics|evidence|evil|evoke|evolve|exact|example|excess|exchange|excite|exclude|excuse|execute|exercise|exhaust|exhibit|exile|exist|exit|exotic|expand|expect|expire|explain|expose|express|extend|extra|eye|eyebrow|fabric|face|faculty|fade|faint|faith|fall|false|fame|family|famous|fan|fancy|fantasy|farm|fashion|fat|fatal|father|fatigue|fault|favorite|feature|february|federal|fee|feed|feel|female|fence|festival|fetch|fever|few|fiber|fiction|field|figure|file|film|filter|final|find|fine|finger|finish|fire|firm|first|fiscal|fish|fit|fitness|fix|flag|flame|flash|flat|flavor|flee|flight|flip|float|flock|floor|flower|fluid|flush|fly|foam|focus|fog|foil|fold|follow|food|foot|force|forest|forget|fork|fortune|forum|forward|fossil|foster|found|fox|fragile|frame|frequent|fresh|friend|fringe|frog|front|frost|frown|frozen|fruit|fuel|fun|funny|furnace|fury|future|gadget|gain|galaxy|gallery|game|gap|garage|garbage|garden|garlic|garment|gas|gasp|gate|gather|gauge|gaze|general|genius|genre|gentle|genuine|gesture|ghost|giant|gift|giggle|ginger|giraffe|girl|give|glad|glance|glare|glass|glide|glimpse|globe|gloom|glory|glove|glow|glue|goat|goddess|gold|good|goose|gorilla|gospel|gossip|govern|gown|grab|grace|grain|grant|grape|grass|gravity|great|green|grid|grief|grit|grocery|group|grow|grunt|guard|guess|guide|guilt|guitar|gun|gym|habit|hair|half|hammer|hamster|hand|happy|harbor|hard|harsh|harvest|hat|have|hawk|hazard|head|health|heart|heavy|hedgehog|height|hello|helmet|help|hen|hero|hidden|high|hill|hint|hip|hire|history|hobby|hockey|hold|hole|holiday|hollow|home|honey|hood|hope|horn|horror|horse|hospital|host|hotel|hour|hover|hub|huge|human|humble|humor|hundred|hungry|hunt|hurdle|hurry|hurt|husband|hybrid|ice|icon|idea|identify|idle|ignore|ill|illegal|illness|image|imitate|immense|immune|impact|impose|improve|impulse|inch|include|income|increase|index|indicate|indoor|industry|infant|inflict|inform|inhale|inherit|initial|inject|injury|inmate|inner|innocent|input|inquiry|insane|insect|inside|inspire|install|intact|interest|into|invest|invite|involve|iron|island|isolate|issue|item|ivory|jacket|jaguar|jar|jazz|jealous|jeans|jelly|jewel|job|join|joke|journey|joy|judge|juice|jump|jungle|junior|junk|just|kangaroo|keen|keep|ketchup|key|kick|kid|kidney|kind|kingdom|kiss|kit|kitchen|kite|kitten|kiwi|knee|knife|knock|know|lab|label|labor|ladder|lady|lake|lamp|language|laptop|large|later|latin|laugh|laundry|lava|law|lawn|lawsuit|layer|lazy|leader|leaf|learn|leave|lecture|left|leg|legal|legend|leisure|lemon|lend|length|lens|leopard|lesson|letter|level|liar|liberty|library|license|life|lift|light|like|limb|limit|link|lion|liquid|list|little|live|lizard|load|loan|lobster|local|lock|logic|lonely|long|loop|lottery|loud|lounge|love|loyal|lucky|luggage|lumber|lunar|lunch|luxury|lyrics|machine|mad|magic|magnet|maid|mail|main|major|make|mammal|man|manage|mandate|mango|mansion|manual|maple|marble|march|margin|marine|market|marriage|mask|mass|master|match|material|math|matrix|matter|maximum|maze|meadow|mean|measure|meat|mechanic|medal|media|melody|melt|member|memory|mention|menu|mercy|merge|merit|merry|mesh|message|metal|method|middle|midnight|milk|million|mimic|mind|minimum|minor|minute|miracle|mirror|misery|miss|mistake|mix|mixed|mixture|mobile|model|modify|mom|moment|monitor|monkey|monster|month|moon|moral|more|morning|mosquito|mother|motion|motor|mountain|mouse|move|movie|much|muffin|mule|multiply|muscle|museum|mushroom|music|must|mutual|myself|mystery|myth|naive|name|napkin|narrow|nasty|nation|nature|near|neck|need|negative|neglect|neither|nephew|nerve|nest|net|network|neutral|never|news|next|nice|night|noble|noise|nominee|noodle|normal|north|nose|notable|note|nothing|notice|novel|now|nuclear|number|nurse|nut|oak|obey|object|oblige|obscure|observe|obtain|obvious|occur|ocean|october|odor|off|offer|office|often|oil|okay|old|olive|olympic|omit|once|one|onion|online|only|open|opera|opinion|oppose|option|orange|orbit|orchard|order|ordinary|organ|orient|original|orphan|ostrich|other|outdoor|outer|output|outside|oval|oven|over|own|owner|oxygen|oyster|ozone|pact|paddle|page|pair|palace|palm|panda|panel|panic|panther|paper|parade|parent|park|parrot|party|pass|patch|path|patient|patrol|pattern|pause|pave|payment|peace|peanut|pear|peasant|pelican|pen|penalty|pencil|people|pepper|perfect|permit|person|pet|phone|photo|phrase|physical|piano|picnic|picture|piece|pig|pigeon|pill|pilot|pink|pioneer|pipe|pistol|pitch|pizza|place|planet|plastic|plate|play|please|pledge|pluck|plug|plunge|poem|poet|point|polar|pole|police|pond|pony|pool|popular|portion|position|possible|post|potato|pottery|poverty|powder|power|practice|praise|predict|prefer|prepare|present|pretty|prevent|price|pride|primary|print|priority|prison|private|prize|problem|process|produce|profit|program|project|promote|proof|property|prosper|protect|proud|provide|public|pudding|pull|pulp|pulse|pumpkin|punch|pupil|puppy|purchase|purity|purpose|purse|push|put|puzzle|pyramid|quality|quantum|quarter|question|quick|quit|quiz|quote|rabbit|raccoon|race|rack|radar|radio|rail|rain|raise|rally|ramp|ranch|random|range|rapid|rare|rate|rather|raven|raw|razor|ready|real|reason|rebel|rebuild|recall|receive|recipe|record|recycle|reduce|reflect|reform|refuse|region|regret|regular|reject|relax|release|relief|rely|remain|remember|remind|remove|render|renew|rent|reopen|repair|repeat|replace|report|require|rescue|resemble|resist|resource|response|result|retire|retreat|return|reunion|reveal|review|reward|rhythm|rib|ribbon|rice|rich|ride|ridge|rifle|right|rigid|ring|riot|ripple|risk|ritual|rival|river|road|roast|robot|robust|rocket|romance|roof|rookie|room|rose|rotate|rough|round|route|royal|rubber|rude|rug|rule|run|runway|rural|sad|saddle|sadness|safe|sail|salad|salmon|salon|salt|salute|same|sample|sand|satisfy|satoshi|sauce|sausage|save|say|scale|scan|scare|scatter|scene|scheme|school|science|scissors|scorpion|scout|scrap|screen|script|scrub|sea|search|season|seat|second|secret|section|security|seed|seek|segment|select|sell|seminar|senior|sense|sentence|series|service|session|settle|setup|seven|shadow|shaft|shallow|share|shed|shell|sheriff|shield|shift|shine|ship|shiver|shock|shoe|shoot|shop|short|shoulder|shove|shrimp|shrug|shuffle|shy|sibling|sick|side|siege|sight|sign|silent|silk|silly|silver|similar|simple|since|sing|siren|sister|situate|six|size|skate|sketch|ski|skill|skin|skirt|skull|slab|slam|sleep|slender|slice|slide|slight|slim|slogan|slot|slow|slush|small|smart|smile|smoke|smooth|snack|snake|snap|sniff|snow|soap|soccer|social|sock|soda|soft|solar|soldier|solid|solution|solve|someone|song|soon|sorry|sort|soul|sound|soup|source|south|space|spare|spatial|spawn|speak|special|speed|spell|spend|sphere|spice|spider|spike|spin|spirit|split|spoil|sponsor|spoon|sport|spot|spray|spread|spring|spy|square|squeeze|squirrel|stable|stadium|staff|stage|stairs|stamp|stand|start|state|stay|steak|steel|stem|step|stereo|stick|still|sting|stock|stomach|stone|stool|story|stove|strategy|street|strike|strong|struggle|student|stuff|stumble|style|subject|submit|subway|success|such|sudden|suffer|sugar|suggest|suit|summer|sun|sunny|sunset|super|supply|supreme|sure|surface|surge|surprise|surround|survey|suspect|sustain|swallow|swamp|swap|swarm|swear|sweet|swift|swim|swing|switch|sword|symbol|symptom|syrup|system|table|tackle|tag|tail|talent|talk|tank|tape|target|task|taste|tattoo|taxi|teach|team|tell|ten|tenant|tennis|tent|term|test|text|thank|that|theme|then|theory|there|they|thing|this|thought|three|thrive|throw|thumb|thunder|ticket|tide|tiger|tilt|timber|time|tiny|tip|tired|tissue|title|toast|tobacco|today|toddler|toe|together|toilet|token|tomato|tomorrow|tone|tongue|tonight|tool|tooth|top|topic|topple|torch|tornado|tortoise|toss|total|tourist|toward|tower|town|toy|track|trade|traffic|tragic|train|transfer|trap|trash|travel|tray|treat|tree|trend|trial|tribe|trick|trigger|trim|trip|trophy|trouble|truck|true|truly|trumpet|trust|truth|try|tube|tuition|tumble|tuna|tunnel|turkey|turn|turtle|twelve|twenty|twice|twin|twist|two|type|typical|ugly|umbrella|unable|unaware|uncle|uncover|under|undo|unfair|unfold|unhappy|uniform|unique|unit|universe|unknown|unlock|until|unusual|unveil|update|upgrade|uphold|upon|upper|upset|urban|urge|usage|use|used|useful|useless|usual|utility|vacant|vacuum|vague|valid|valley|valve|van|vanish|vapor|various|vast|vault|vehicle|velvet|vendor|venture|venue|verb|verify|version|very|vessel|veteran|viable|vibrant|vicious|victory|video|view|village|vintage|violin|virtual|virus|visa|visit|visual|vital|vivid|vocal|voice|void|volcano|volume|vote|voyage|wage|wagon|wait|walk|wall|walnut|want|warfare|warm|warrior|wash|wasp|waste|water|wave|way|wealth|weapon|wear|weasel|weather|web|wedding|weekend|weird|welcome|west|wet|whale|what|wheat|wheel|when|where|whip|whisper|wide|width|wife|wild|will|win|window|wine|wing|wink|winner|winter|wire|wisdom|wise|wish|witness|wolf|woman|wonder|wood|wool|word|work|world|worry|worth|wrap|wreck|wrestle|wrist|write|wrong|yard|year|yellow|you|young|youth|zebra|zero|zone|zoo".split("|");var rQ="Invalid mnemonic",sJ="Invalid entropy",rJ="Invalid mnemonic checksum";function ym(l){return(l||"").normalize("NFKD")}function iJ(l){return parseInt(l,2)}function mJ(l){return l.map(A=>A.toString(2).padStart(8,"0")).join("")}function VJ(l){return mJ(Array.from(Fm(l))).slice(0,l.length*8/32)}function Qm(l,A){return la(uG(ym(l)),uG(`mnemonic${ym(A)}`)).password}function Nm(l,A=sQ){let G=ym(l).split(" ");if(G.length%3!==0)throw new Error(rQ);let b=G.map(g=>{let n=A.indexOf(g);if(n===-1)throw new Error(rQ);return n.toString(2).padStart(11,"0")}).join(""),t=Math.floor(b.length/33)*32,c=b.slice(0,t),B=b.slice(t),d=c.match(/(.{1,8})/g)?.map(iJ);if(!d||d.length%4!==0||d.length<16||d.length>32)throw new Error(sJ);let Z=Tl(d);if(VJ(Z)!==B)throw new Error(rJ);return Z}function iQ(l,A){try{Nm(l,A)}catch{return!1}return!0}function mQ(l,A,G){return!PA||!A&&!G&&TA()?jV(l):Nm(l,A)}function go(l,A,G){return!PA||!A&&!G&&TA()?DV(l):iQ(l,A)}function Em(l,A="",G,b=32){if(go(l)){if(![32,64].includes(b))throw new Error(`Invalid seed length ${b}, expected 32 or 64`)}else throw new Error("Invalid bip39 mnemonic specified");return b===32?!PA||!G&&TA()?TV(l,A):Qm(l,A).subarray(0,32):Qm(l,A)}function vm(l,A="",G,b){if(go(l,G,b)){if(!G&&!b&&TA())return MV(l,A)}else throw new Error("Invalid bip39 mnemonic specified");let t=mQ(l,G),c=uG(`mnemonic${A}`);return la(t,c).password.slice(0,32)}function Wo(l,A){return l<<A|l>>>32-A}function gd(l,A){let G=l[A+3]&255;return G=G<<8|l[A+2]&255,G=G<<8|l[A+1]&255,G<<8|l[A+0]&255}function Hm(l,A,G){for(let b=0;b<4;b++)l[A+b]=G&255,G>>>=8}function uJ(l,A,G,b,t){let c=0;for(let B=0;B<t;B++)c|=l[A+B]^G[b+B];return(1&c-1>>>8)-1}function xm(l,A,G,b,t){let c=new Uint32Array(16),B=new Uint32Array(16),e=new Uint32Array(16),d=new Uint32Array(4),Z,g,n;for(Z=0;Z<4;Z++)B[5*Z]=gd(b,4*Z),B[1+Z]=gd(G,4*Z),B[6+Z]=gd(A,4*Z),B[11+Z]=gd(G,16+4*Z);for(Z=0;Z<16;Z++)e[Z]=B[Z];for(Z=0;Z<20;Z++){for(g=0;g<4;g++){for(n=0;n<4;n++)d[n]=B[(5*g+4*n)%16];for(d[1]^=Wo(d[0]+d[3]|0,7),d[2]^=Wo(d[1]+d[0]|0,9),d[3]^=Wo(d[2]+d[1]|0,13),d[0]^=Wo(d[3]+d[2]|0,18),n=0;n<4;n++)c[4*g+(g+n)%4]=d[n]}for(n=0;n<16;n++)B[n]=c[n]}if(t){for(Z=0;Z<16;Z++)B[Z]=B[Z]+e[Z]|0;for(Z=0;Z<4;Z++)B[5*Z]=B[5*Z]-gd(b,4*Z)|0,B[6+Z]=B[6+Z]-gd(A,4*Z)|0;for(Z=0;Z<4;Z++)Hm(l,4*Z,B[5*Z]),Hm(l,16+4*Z,B[6+Z])}else for(Z=0;Z<16;Z++)Hm(l,4*Z,B[Z]+e[Z]|0)}var fm=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function YJ(l,A,G,b,t,c,B){let e=new Uint8Array(16),d=new Uint8Array(64),Z,g;if(!t)return 0;for(g=0;g<16;g++)e[g]=0;for(g=0;g<8;g++)e[g]=c[g];for(;t>=64;){for(xm(d,e,B,fm,!1),g=0;g<64;g++)l[A+g]=(G?G[b+g]:0)^d[g];for(Z=1,g=8;g<16;g++)Z=Z+(e[g]&255)|0,e[g]=Z&255,Z>>>=8;t-=64,A+=64,G&&(b+=64)}if(t>0)for(xm(d,e,B,fm,!1),g=0;g<t;g++)l[A+g]=(G?G[b+g]:0)^d[g];return 0}function km(l,A,G,b,t,c,B){let e=new Uint8Array(32);return xm(e,c,B,fm,!0),YJ(l,A,G,b,t,c.subarray(16),e)}function Jm(l,A){let G=0;for(let b=0;b<17;b++)G=G+(l[b]+A[b]|0)|0,l[b]=G&255,G>>>=8}var IJ=new Uint32Array([5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252]);function VQ(l,A,G,b,t,c){let B,e,d,Z=new Uint32Array(17),g=new Uint32Array(17),n=new Uint32Array(17),h=new Uint32Array(17),W=new Uint32Array(17);for(e=0;e<17;e++)g[e]=n[e]=0;for(e=0;e<16;e++)g[e]=c[e];for(g[3]&=15,g[4]&=252,g[7]&=15,g[8]&=252,g[11]&=15,g[12]&=252,g[15]&=15;t>0;){for(e=0;e<17;e++)h[e]=0;for(e=0;e<16&&e<t;++e)h[e]=G[b+e];for(h[e]=1,b+=e,t-=e,Jm(n,h),B=0;B<17;B++)for(Z[B]=0,e=0;e<17;e++)Z[B]=Z[B]+n[e]*(e<=B?g[B-e]:320*g[B+17-e]|0)|0|0;for(B=0;B<17;B++)n[B]=Z[B];for(d=0,e=0;e<16;e++)d=d+n[e]|0,n[e]=d&255,d>>>=8;for(d=d+n[16]|0,n[16]=d&3,d=5*(d>>>2)|0,e=0;e<16;e++)d=d+n[e]|0,n[e]=d&255,d>>>=8;d=d+n[16]|0,n[16]=d}for(e=0;e<17;e++)W[e]=n[e];Jm(n,IJ);let m=-(n[16]>>>7)|0;for(e=0;e<17;e++)n[e]^=m&(W[e]^n[e]);for(e=0;e<16;e++)h[e]=c[e+16];for(h[16]=0,Jm(n,h),e=0;e<16;e++)l[A+e]=n[e];return 0}function RJ(l,A,G,b,t,c){let B=new Uint8Array(16);return VQ(B,0,G,b,t,c),uJ(l,A,B,0,16)}function XJ(l,A,G,b,t){if(G<32)return-1;km(l,0,A,0,G,b,t),VQ(l,16,l,32,G-32,l);for(let c=0;c<16;c++)l[c]=0;return 0}function pJ(l,A,G,b,t){let c=new Uint8Array(32);if(G<32||(km(c,0,null,0,32,b,t),RJ(A,16,A,32,G-32,c)!==0))return-1;km(l,0,A,0,G,b,t);for(let B=0;B<32;B++)l[B]=0;return 0}var FJ=32,yJ=24,wm=32,Um=16;function uQ(l,A){if(l.length!==FJ)throw new Error("bad key size");if(A.length!==yJ)throw new Error("bad nonce size")}function YQ(...l){for(let A=0,G=l.length;A<G;A++)if(!(l[A]instanceof Uint8Array))throw new TypeError("unexpected type, use Uint8Array")}function IQ(l,A,G){YQ(l,A,G),uQ(G,A);let b=new Uint8Array(wm+l.length),t=new Uint8Array(b.length);for(let c=0;c<l.length;c++)b[c+wm]=l[c];return XJ(t,b,b.length,A,G),t.subarray(Um)}function RQ(l,A,G){YQ(l,A,G),uQ(G,A);let b=new Uint8Array(Um+l.length),t=new Uint8Array(b.length);for(let c=0;c<l.length;c++)b[c+Um]=l[c];return b.length<32||pJ(t,b,b.length,A,G)!==0?null:t.subarray(wm)}function Cm(l,A,G){return RQ(l,A,G)}function Sm(l,A,G=ed(24)){return{encrypted:IQ(l,G,A),nonce:G}}function XQ(l,A,G,b,t,c){let B=l[A++]^G[b++],e=l[A++]^G[b++],d=l[A++]^G[b++],Z=l[A++]^G[b++],g=l[A++]^G[b++],n=l[A++]^G[b++],h=l[A++]^G[b++],W=l[A++]^G[b++],m=l[A++]^G[b++],Y=l[A++]^G[b++],R=l[A++]^G[b++],u=l[A++]^G[b++],i=l[A++]^G[b++],I=l[A++]^G[b++],Q=l[A++]^G[b++],f=l[A++]^G[b++],U=B,J=e,M=d,C=Z,D=g,$=n,K=h,y=W,r=m,F=Y,E=R,x=u,s=i,p=I,X=Q,o=f;for(let a=0;a<8;a+=2)D^=qA(U+s|0,7),r^=qA(D+U|0,9),s^=qA(r+D|0,13),U^=qA(s+r|0,18),F^=qA($+J|0,7),p^=qA(F+$|0,9),J^=qA(p+F|0,13),$^=qA(J+p|0,18),X^=qA(E+K|0,7),M^=qA(X+E|0,9),K^=qA(M+X|0,13),E^=qA(K+M|0,18),C^=qA(o+x|0,7),y^=qA(C+o|0,9),x^=qA(y+C|0,13),o^=qA(x+y|0,18),J^=qA(U+C|0,7),M^=qA(J+U|0,9),C^=qA(M+J|0,13),U^=qA(C+M|0,18),K^=qA($+D|0,7),y^=qA(K+$|0,9),D^=qA(y+K|0,13),$^=qA(D+y|0,18),x^=qA(E+F|0,7),r^=qA(x+E|0,9),F^=qA(r+x|0,13),E^=qA(F+r|0,18),s^=qA(o+X|0,7),p^=qA(s+o|0,9),X^=qA(p+s|0,13),o^=qA(X+p|0,18);t[c++]=B+U|0,t[c++]=e+J|0,t[c++]=d+M|0,t[c++]=Z+C|0,t[c++]=g+D|0,t[c++]=n+$|0,t[c++]=h+K|0,t[c++]=W+y|0,t[c++]=m+r|0,t[c++]=Y+F|0,t[c++]=R+E|0,t[c++]=u+x|0,t[c++]=i+s|0,t[c++]=I+p|0,t[c++]=Q+X|0,t[c++]=f+o|0}function zm(l,A,G,b,t){let c=b+0,B=b+16*t;for(let e=0;e<16;e++)G[B+e]=l[A+(2*t-1)*16+e];for(let e=0;e<t;e++,c+=16,A+=16)XQ(G,B,l,A,G,c),e>0&&(B+=16),XQ(G,c,l,A+=16,G,B)}function QJ(l,A,G){let b=ua({dkLen:32,asyncTick:10,maxmem:1073742848},G),{N:t,r:c,p:B,dkLen:e,asyncTick:d,maxmem:Z,onProgress:g}=b;if(mG(t),mG(c),mG(B),mG(e),mG(d),mG(Z),g!==void 0&&typeof g!="function")throw new Error("progressCb should be function");let n=128*c,h=n/4,W=Math.pow(2,32);if(t<=1||t&t-1||t>W)throw new Error("Scrypt: N must be larger than 1, a power of 2, and less than 2^32");if(B<0||B>(W-1)*32/n)throw new Error("Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)");if(e<0||e>(W-1)*32)throw new Error("Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32");if(n*(t+B)>Z)throw new Error("Scrypt: memused is bigger than maxMem. Expected 128 * r * (N + p) > maxmem of "+Z);let Y=$n(ye,l,A,{c:1,dkLen:n*B}),R=tt(Y),u=tt(new Uint8Array(n*t)),i=tt(new Uint8Array(n)),I=()=>{};if(g){let Q=2*t*B,f=Math.max(Math.floor(Q/1e4),1),U=0;I=()=>{U++,g&&(!(U%f)||U===Q)&&g(U/Q)}}return{N:t,r:c,p:B,dkLen:e,blockSize32:h,V:u,B32:R,B:Y,tmp:i,blockMixCb:I,asyncTick:d}}function NJ(l,A,G,b,t){let c=$n(ye,l,G,{c:1,dkLen:A});return MG(G,b,t),c}function pQ(l,A,G){let{N:b,r:t,p:c,dkLen:B,blockSize32:e,V:d,B32:Z,B:g,tmp:n,blockMixCb:h}=QJ(l,A,G);ct(Z);for(let W=0;W<c;W++){let m=e*W;for(let Y=0;Y<e;Y++)d[Y]=Z[m+Y];for(let Y=0,R=0;Y<b-1;Y++)zm(d,R,d,R+=e,t),h();zm(d,(b-1)*e,Z,m,t),h();for(let Y=0;Y<b;Y++){let R=Z[m+e-16]%b;for(let u=0;u<e;u++)n[u]=Z[m+u]^d[R*e+u];zm(n,0,Z,m,t),h()}}return ct(Z),NJ(l,B,g,d,n)}var FQ=[{N:8192,p:10,r:8},{N:16384,p:5,r:8},{N:32768,p:3,r:8},{N:32768,p:1,r:8},{N:65536,p:2,r:8},{N:131072,p:1,r:8}],yQ={N:1<<17,p:1,r:8};function Aa(l,A=ed(),G=yQ,b){let t=Tl(l);return{params:G,password:!PA||!b&&TA()?eu(t,A,Math.log2(G.N),G.r,G.p):pQ(t,A,te({dkLen:64},G)),salt:A}}function jm(l){if(!(l instanceof Uint8Array))throw new Error("Expected input to be a Uint8Array");if(l.length<44)throw new Error(`Invalid input length: expected 44 bytes, found ${l.length}`);let A=l.subarray(0,32),G=Jd(l.subarray(32,36),jW).toNumber(),b=Jd(l.subarray(36,40),jW).toNumber(),t=Jd(l.subarray(40,44),jW).toNumber();if(G>1<<20||b>4||t>16)throw new Error("Scrypt parameters exceed safe limits");if(!FQ.some(B=>B.N===G&&B.p===b&&B.r===t))throw new Error("Invalid injected scrypt params found");return{params:{N:G,p:b,r:t},salt:A}}function Mm(l,{N:A,p:G,r:b}){return nG(l,kG(A,MW),kG(G,MW),kG(b,MW))}var oo=["scrypt","xsalsa20-poly1305"],QQ=["none"],NQ="3";function Tm(l,A,G=oo){if(l){if(G.includes("xsalsa20-poly1305")&&!A)throw new Error("Password required to decode encrypted data")}else throw new Error("No encrypted data available to decode");let b=l;if(A){let t;if(G.includes("scrypt")){let{params:c,salt:B}=jm(l);t=Aa(A,B,c).password,l=l.subarray(44)}else t=uG(A);b=Cm(l.subarray(24),l.subarray(0,24),Po(t,256,!0))}if(!b)throw new Error("Unable to decode using the supplied passphrase");return b}function Dm(l,A,G){return{encoded:Ym(l),encoding:{content:A,type:G?oo:QQ,version:NQ}}}var vQ=l=>(A,G,b)=>nQ(A,G,b,l,!0),Lm=[["ecdsa",vQ("blake2")],["ethereum",vQ("keccak")]],HQ=[["ed25519",xy],["sr25519",tQ]];function ho(l,{message:A,publicKey:G,signature:b},t=[...HQ,...Lm]){return l.isValid=t.some(([c,B])=>{try{if(B(A,b,G))return l.crypto=c,!0}catch{}return!1}),l}function vJ(l,{message:A,publicKey:G,signature:b}){if(![0,1,2].includes(b[0])||![65,66].includes(b.length))throw new Error(`Unknown crypto type, expected signature prefix [0..2], found ${b[0]}`);return b.length===66?l=ho(l,{message:A,publicKey:G,signature:b.subarray(1)},Lm):(l=ho(l,{message:A,publicKey:G,signature:b.subarray(1)},HQ),l.isValid||(l=ho(l,{message:A,publicKey:G,signature:b},Lm)),l.isValid||(l.crypto="none")),l}function HJ(l){return[0,1,2].includes(l[0])&&[65,66].includes(l.length)?vJ:ho}function so(l,A,G){let b=Tl(A);if(![64,65,66].includes(b.length))throw new Error(`Invalid signature length, expected [64..66] bytes, found ${b.length}`);let t=Pt(G),c={message:Tl(l),publicKey:t,signature:b},B={crypto:"none",isValid:!1,isWrapped:BZ(c.message,!0),publicKey:t},e=BZ(c.message,!1),d=HJ(b);return d(B,c),B.crypto!=="none"||B.isWrapped&&!e?B:(c.message=e?qo(c.message):_o(c.message),d(B,c))}var jB=new Uint8Array([161,35,3,33,0]),Wd=new Uint8Array([48,83,2,1,1,48,5,6,3,43,101,112,4,34,4,32]),JQ=32;var Om=64,xQ=32;var Ga=Wd.length;function fQ(l,A,G){let b=Array.isArray(G)||G===void 0?G:[G],t=Tm(A,l,b),c=t.subarray(0,Wd.length);if(!jb(c,Wd))throw new Error("Invalid encoding header found in body");let B=t.subarray(Ga,Ga+Om),e=Ga+Om,d=t.subarray(e,e+jB.length);if(!jb(d,jB)&&(e=Ga+xQ,B=t.subarray(Ga,e),d=t.subarray(e,e+jB.length),!jb(d,jB)))throw new Error("Invalid encoding divider found in body");let Z=e+jB.length;return{publicKey:t.subarray(Z,Z+JQ),secretKey:B}}function kQ({publicKey:l,secretKey:A},G){if(!A)throw new Error("Expected a valid secretKey to be passed to encode");let b=nG(Wd,A,jB,l);if(!G)return b;let{params:t,password:c,salt:B}=Aa(G),{encrypted:e,nonce:d}=Sm(b,c.subarray(0,32));return nG(Mm(B,t),d,e)}function wQ(l,{address:A,meta:G},b,t){return te(Dm(b,["pkcs8",l],t),{address:A,meta:G})}var JJ=new Uint8Array,xJ={ecdsa:qt,ed25519:xe,ethereum:qt,sr25519:On},UQ={ecdsa:new Uint8Array([2]),ed25519:new Uint8Array([0]),ethereum:new Uint8Array([2]),sr25519:new Uint8Array([1])},CQ={ecdsa:(l,A)=>Zo(l,A,"blake2"),ed25519:em,ethereum:(l,A)=>Zo(l,A,"keccak"),sr25519:rm},ro={ecdsa:l=>l.length>32?Mb(l):l,ed25519:l=>l,ethereum:l=>l.length===20?l:zB(we(l)),sr25519:l=>l};function ba(l){return!l||Hd(l)}function SQ(l,A,G){return Mb(nG(A||"",G||"",l))}function Ue({toSS58:l,type:A},{publicKey:G,secretKey:b},t={},c=null,B){let e=(g,n)=>{let h=fQ(g,n||c,B);if(h.secretKey.length===64)G=h.publicKey,b=h.secretKey;else{let W=xJ[A](h.secretKey);G=W.publicKey,b=W.secretKey}},d=g=>(ba(b)&&c&&e(g,c),c=kQ({publicKey:G,secretKey:b},g),B=void 0,c),Z=()=>{let g=ro[A](G);return A==="ethereum"?_n(g):l(g)};return{get address(){return Z()},get addressRaw(){let g=ro[A](G);return A==="ethereum"?g.slice(-20):g},get isLocked(){return ba(b)},get meta(){return t},get publicKey(){return G},get type(){return A},decodePkcs8:e,derive:(g,n)=>{if(A==="ethereum")throw new Error("Unable to derive on this keypair");if(ba(b))throw new Error("Cannot derive on a locked keypair");let{path:h}=kn(g),W=Ln({publicKey:G,secretKey:b},h,A);return Ue({toSS58:l,type:A},W,n,null)},encodePkcs8:g=>d(g),lock:()=>{b=new Uint8Array},setMeta:g=>{t=te({},t,g)},sign:(g,n={})=>{if(ba(b))throw new Error("Cannot sign with a locked key pair");return nG(n.withType?UQ[A]:JJ,CQ[A](Tl(g),{publicKey:G,secretKey:b}))},toJson:g=>{let n=["ecdsa","ethereum"].includes(A)?G.length===20?dt(G):dt(qn(G)):Z();return wQ(A,{address:n,meta:t},d(g),!!g)},unlock:g=>e(g),verify:(g,n,h)=>so(g,n,ro[A](Tl(h))).isValid,vrfSign:(g,n,h)=>{if(ba(b))throw new Error("Cannot sign with a locked key pair");if(A==="sr25519")return im(g,{secretKey:b},n,h);let W=CQ[A](Tl(g),{publicKey:G,secretKey:b});return nG(SQ(W,n,h),W)},vrfVerify:(g,n,h,W,m)=>A==="sr25519"?mm(g,n,G,W,m):so(g,nG(UQ[A],n.subarray(32)),ro[A](Tl(h))).isValid&&jb(n.subarray(0,32),SQ(n.subarray(32),W,m))}}var zQ="bottom drive obey lake curtain smoke basket hold race lonely fit walk";var Ce,io=class{constructor(){EG(this,Ce,{})}add(A){return GA(this,Ce)[Pt(A.address).toString()]=A,A}all(){return Object.values(GA(this,Ce))}get(A){let G=GA(this,Ce)[Pt(A).toString()];if(!G)throw new Error(`Unable to retrieve keypair '${Hb(A)||Vb(A)?dt(Tl(A)):A}'`);return G}remove(A){delete GA(this,Ce)[Pt(A).toString()]}};Ce=new WeakMap;var Pm={ecdsa:l=>qt(l),ed25519:l=>xe(l),ethereum:l=>qt(l),sr25519:l=>On(l)};function fJ({publicKey:l}){return l}var Fc,ca,od,ta=class{constructor(A={}){EG(this,Fc);EG(this,ca);EG(this,od);el(this,"decodeAddress",Pt);el(this,"encodeAddress",(A,G)=>this.type==="ethereum"?_n(A):Pn(A,G??GA(this,od)));if(A.type=A.type||"ed25519",!["ecdsa","ethereum","ed25519","sr25519"].includes(A.type||"undefined"))throw new Error(`Expected a keyring type of either 'ed25519', 'sr25519', 'ethereum' or 'ecdsa', found '${A.type||"unknown"}`);bG(this,Fc,new io),bG(this,od,A.ss58Format),bG(this,ca,A.type)}get pairs(){return this.getPairs()}get publicKeys(){return this.getPublicKeys()}get type(){return GA(this,ca)}addPair(A){return GA(this,Fc).add(A)}addFromAddress(A,G={},b=null,t=this.type,c,B){let e=this.decodeAddress(A,c);return this.addPair(Ue({toSS58:this.encodeAddress,type:t},{publicKey:e,secretKey:new Uint8Array},G,b,B))}addFromJson(A,G){return this.addPair(this.createFromJson(A,G))}addFromMnemonic(A,G={},b=this.type,t){return this.addFromUri(A,G,b,t)}addFromPair(A,G={},b=this.type){return this.addPair(this.createFromPair(A,G,b))}addFromSeed(A,G={},b=this.type){return this.addPair(Ue({toSS58:this.encodeAddress,type:b},Pm[b](A),G,null))}addFromUri(A,G={},b=this.type,t){return this.addPair(this.createFromUri(A,G,b,t))}createFromJson({address:A,encoded:G,encoding:{content:b,type:t,version:c},meta:B},e){if(c==="3"&&b[0]!=="pkcs8")throw new Error(`Unable to decode non-pkcs8 type, [${b.join(",")}] found}`);let d=c==="0"||!Array.isArray(b)?this.type:b[1],Z=Array.isArray(t)?t:[t];if(!["ed25519","sr25519","ecdsa","ethereum"].includes(d))throw new Error(`Unknown crypto type ${d}`);let g=Vb(A)?vb(A):this.decodeAddress(A,e),n=Vb(G)?vb(G):um(G);return Ue({toSS58:this.encodeAddress,type:d},{publicKey:g,secretKey:new Uint8Array},B,n,Z)}createFromPair(A,G={},b=this.type){return Ue({toSS58:this.encodeAddress,type:b},A,G,null)}createFromUri(A,G={},b=this.type,t){let c=A.startsWith("//")?`${zQ}${A}`:A,{derivePath:B,password:e,path:d,phrase:Z}=Ji(c),g,n=Vb(Z,256);if(n)g=vb(Z);else{let W=Z.split(" ");if([12,15,18,21,24].includes(W.length))g=b==="ethereum"?Em(Z,"",!1,64):vm(Z,e,t);else{if(Z.length>32)throw new Error("specified phrase is not a valid mnemonic and is invalid as a raw seed at > 32 bytes");g=uG(Z.padEnd(32))}}let h=b==="ethereum"?n?Pm[b](g):pm(g,B.substring(1)):Ln(Pm[b](g),d,b);return Ue({toSS58:this.encodeAddress,type:b},h,G,null)}getPair(A){return GA(this,Fc).get(A)}getPairs(){return GA(this,Fc).all()}getPublicKeys(){return GA(this,Fc).all().map(fJ)}removePair(A){GA(this,Fc).remove(A)}setSS58Format(A){bG(this,od,A)}toJson(A,G){return GA(this,Fc).get(A).toJson(G)}};Fc=new WeakMap,ca=new WeakMap,od=new WeakMap;var hd=class{constructor(A){el(this,"token");if(this.token=A,!A)throw new Error("DelegationAuthProvider requires a non-empty delegation token")}async authenticate(A){let G={Authorization:`Bearer ${this.token}`};return A.body===void 0?{headers:G}:(G["Content-Type"]="application/json",{headers:G,body:new TextEncoder().encode(JSON.stringify(A.body))})}};var CJ="cef-widget:identity-request",SJ="cef-widget:identity-response",zJ="cef-widget:sign-request",jJ="cef-widget:sign-response";var DQ="unsupported-version";var sd=class extends Error{constructor(A){super(`WidgetProtocolVersionError: ${A}`),this.name="WidgetProtocolVersionError"}},mo=class extends Error{constructor(A){super(`WidgetMalformedMessageError: ${A}`),this.name="WidgetMalformedMessageError"}};function LQ(l){return l!==void 0&&l!==1}function MJ(l){if(!Array.isArray(l)||l.length>65536)return!1;for(let A=0;A<l.length;A++){if(!(A in l))return!1;let G=l[A];if(typeof G!="number"||!Number.isInteger(G)||G<0||G>255)return!1}return!0}var TQ=!1,rd=new Map;function OQ(){TQ||(TQ=!0,window.addEventListener("message",l=>{if(l.source!==window.parent)return;let A=l.data;if(!A||typeof A!="object")return;let{type:G,requestId:b}=A;if(typeof b!="string"||G!==SJ&&G!==jJ)return;let t=rd.get(b);t&&(rd.delete(b),t.resolve(A))}))}function PQ(){return`${Date.now()}-${Math.random().toString(36).slice(2)}`}var Km;async function TJ(){if(window.parent===window)return null;if(Km!==void 0)return Km;OQ();let l=400,A=8e3,G=Date.now()+A;return new Promise((b,t)=>{let c=!1,B,e,d=new Set;function Z(){c=!0,B!==void 0&&(clearTimeout(B),B=void 0),e!==void 0&&(clearTimeout(e),e=void 0);for(let h of d)rd.delete(h);d.clear()}function g(){if(c)return;let h=PQ();d.add(h),rd.set(h,{resolve:W=>{if(c)return;let m=W;if(LQ(m.v)){Z(),t(new sd(`the host replied in protocol v${String(m.v)}; this build speaks v1`));return}if(m.errorCode===DQ){Z(),t(new sd(`the host rejected protocol v1 (${m.error??"no detail"})`));return}if(m.error||!m.pubkey){n();return}let Y={pubkey:m.pubkey,sigType:m.sigType??"ed25519",...m.token?{token:m.token}:{},...m.context?{context:m.context}:{}};Z(),Km=Y,b(Y)},reject:()=>{c||n()}}),window.parent.postMessage({type:CJ,requestId:h,v:1},"*"),n()}function n(){if(c)return;B!==void 0&&(clearTimeout(B),B=void 0);let h=G-Date.now();if(h<=0){Z(),b(null);return}B=setTimeout(()=>{c||g()},Math.min(l,h))}g(),e=setTimeout(()=>{c||(Z(),b(null))},A+l)})}async function DJ(l){if(window.parent===window)throw new Error("sign called outside of an iframe");if(l.length>65536)throw new mo(`sign-request.bytes is ${l.length} bytes; the contract caps it at 65536`);OQ();let A=6e4,G=PQ();return new Promise((b,t)=>{let c=setTimeout(()=>{rd.delete(G),t(new Error("widget signing timed out \u2014 the host page may have closed the widget"))},A);rd.set(G,{resolve:B=>{clearTimeout(c);let e=B;LQ(e.v)?t(new sd(`the host replied in protocol v${String(e.v)}; this build speaks v1`)):e.errorCode===DQ?t(new sd(`the host rejected protocol v1 (${e.error??"no detail"})`)):e.error?t(new Error(e.error)):e.signature===null?t(new Error("widget signing was declined")):MJ(e.signature)?b(Uint8Array.from(e.signature)):t(new mo("sign-response.signature must be null or an array of integers 0-255"))},reject:B=>{clearTimeout(c),t(B)}}),window.parent.postMessage({type:zJ,requestId:G,v:1,bytes:Array.from(l)},"*")})}function KQ(){return{requestIdentity:TJ,sign:DJ}}var LJ=54;function qm(l,A,G){return{type:A,address:Pn(vb(l),LJ),publicKey:vb(l),isReady:async()=>!0,sign:b=>G(b)}}var AN=po($Q(),1);var lN=["private_key","ed25519_private_key","eth_private_key"];function OJ(l){let A=l.trim().replace(/^0x/i,"");return/^[0-9a-fA-F]{64,}$/.test(A)?"0x"+A.slice(0,64).toLowerCase():null}async function PJ(l){for(let A of lN)try{let G=await l.request({method:A});if(typeof G!="string")continue;let b=OJ(G);if(b)return b}catch{}throw new Error("standalone wallet: could not extract embed-wallet seed. Tried: "+lN.join(", "))}function KJ(l){return l.startsWith("0x")?l:`0x${l}`}async function GN(l){await zF();let A=new AN.EmbedWallet({appId:l.appId,env:l.env});await A.init({appId:l.appId,env:l.env,popupMode:"modal"}),await A.connect();let b=await A.getSigner({type:"ed25519"}).getAccount(),t=KJ(b.publicKey).toLowerCase(),c=await PJ(A.provider),e=new ta({type:"ed25519"}).addFromSeed(vb(c)),d=dt(e.publicKey);if(d!==t)throw new Error(`[widget-runtime] standalone wallet: derived pubkey (${d}) does not match the wallet's pubkey (${t}) \u2014 refusing to sign.`);return{pubkey:()=>t,sigType:"ed25519",signRawBytes:async Z=>e.sign(Z)}}var iG=class extends Error{constructor(l,A,G,b){super(A?`${l}: ${A}`:l),this.code=l,this.detail=A,this.traceId=G,this.status=b,this.name="WalletError"}toJSON(){return{name:this.name,code:this.code,detail:this.detail,traceId:this.traceId,message:this.message}}};function qJ(l){if(l.length>=255)throw new TypeError("Alphabet too long");let A=new Uint8Array(256);for(let Z=0;Z<A.length;Z++)A[Z]=255;for(let Z=0;Z<l.length;Z++){let g=l.charAt(Z),n=g.charCodeAt(0);if(A[n]!==255)throw new TypeError(g+" is ambiguous");A[n]=Z}let G=l.length,b=l.charAt(0),t=Math.log(G)/Math.log(256),c=Math.log(256)/Math.log(G);function B(Z){if(Z instanceof Uint8Array||(ArrayBuffer.isView(Z)?Z=new Uint8Array(Z.buffer,Z.byteOffset,Z.byteLength):Array.isArray(Z)&&(Z=Uint8Array.from(Z))),!(Z instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(Z.length===0)return"";let g=0,n=0,h=0,W=Z.length;for(;h!==W&&Z[h]===0;)h++,g++;let m=(W-h)*c+1>>>0,Y=new Uint8Array(m);for(;h!==W;){let i=Z[h],I=0;for(let Q=m-1;(i!==0||I<n)&&Q!==-1;Q--,I++)i+=256*Y[Q]>>>0,Y[Q]=i%G>>>0,i=i/G>>>0;if(i!==0)throw new Error("Non-zero carry");n=I,h++}let R=m-n;for(;R!==m&&Y[R]===0;)R++;let u=b.repeat(g);for(;R<m;++R)u+=l.charAt(Y[R]);return u}function e(Z){if(typeof Z!="string")throw new TypeError("Expected String");if(Z.length===0)return new Uint8Array;let g=0,n=0,h=0;for(;Z[g]===b;)n++,g++;let W=(Z.length-g)*t+1>>>0,m=new Uint8Array(W);for(;g<Z.length;){let i=Z.charCodeAt(g);if(i>255)return;let I=A[i];if(I===255)return;let Q=0;for(let f=W-1;(I!==0||Q<h)&&f!==-1;f--,Q++)I+=G*m[f]>>>0,m[f]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");h=Q,g++}let Y=W-h;for(;Y!==W&&m[Y]===0;)Y++;let R=new Uint8Array(n+(W-Y)),u=n;for(;Y!==W;)R[u++]=m[Y++];return R}function d(Z){let g=e(Z);if(g)return g;throw new Error("Non-base"+G+" character")}return{encode:B,decodeUnsafe:e,decode:d}}var bN=qJ;var _J="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",tN=bN(_J);var Eal=new Uint8Array([241,55,252,128,200,121,231,173,149,167,104,105,124,215,6,125,113,218,113,114,238,51,232,185,156,209,26,46,78,6,58,137]);var val=new TextEncoder().encode("SS58PRE");function cN(l){let A=tN.decode(l);if(A.length!==32)throw new Error(`expected a 32-byte Ed25519 pubkey from the Solana address, got ${A.length}`);return A}var $J="cere-wallet-root-wrap-v1",lx="v1",Hal={[lx]:$J};var id=(l,A,G)=>new Promise((b,t)=>{var c=d=>{try{e(G.next(d))}catch(Z){t(Z)}},B=d=>{try{e(G.throw(d))}catch(Z){t(Z)}},e=d=>d.done?b(d.value):Promise.resolve(d.value).then(c,B);e((G=G.apply(l,A)).next())}),ZN=class{constructor(l){this.chain="evm",this.address=l.address,this.sign=l.sign}getAddress(){return id(this,null,function*(){return this.address})}signMessage(l){return id(this,null,function*(){let A=BN(l),G=yield this.sign("evm",A),b=G.slice(0,32),t=G.slice(32,64),c=G[64]+27;return"0x"+eN(b)+eN(t)+c.toString(16).padStart(2,"0")})}signMessageRaw(l){return id(this,null,function*(){let A=BN(l);return this.sign("evm",A)})}};function BN(l){let A=typeof l=="string"?new TextEncoder().encode(l):l,G=new TextEncoder().encode(`Ethereum Signed Message:
306
+ ${A.length}`);return bo(VG(G,A))}function eN(l){let A="";for(let G of l)A+=G.toString(16).padStart(2,"0");return A}var dN=class{constructor(l){this.chain="cere",this.nextId=1,this.address=l.address,this.sign=l.sign}signRaw(l){return id(this,null,function*(){if(l.type!=="ed25519")throw new Error(`PolkadotSigner: unsupported sig type "${l.type}" (only ed25519)`);let A=typeof l.data=="string"?Ax(l.data):l.data,G=yield this.sign("cere",A);return{id:this.nextId++,signature:"0x"+Gx(G)}})}signMessage(l){return id(this,null,function*(){return this.sign("cere",l)})}};function Ax(l){let A=l.startsWith("0x")?l.slice(2):l;if(A.length%2!==0)throw new Error(`PolkadotSigner: odd-length hex "${l}"`);let G=new Uint8Array(A.length/2);for(let b=0;b<G.length;b++)G[b]=parseInt(A.slice(b*2,b*2+2),16);return G}function Gx(l){let A="";for(let G of l)A+=G.toString(16).padStart(2,"0");return A}var nN=class{constructor(l){this.chain="solana",this.address=l.address,this.sign=l.sign}get publicKey(){return this.address}signMessage(l){return id(this,null,function*(){let A=typeof l=="string"?new TextEncoder().encode(l):l;return this.sign("solana",A)})}};var bx=Object.defineProperty,aN=Object.getOwnPropertySymbols,tx=Object.prototype.hasOwnProperty,cx=Object.prototype.propertyIsEnumerable,gN=(l,A,G)=>A in l?bx(l,A,{enumerable:!0,configurable:!0,writable:!0,value:G}):l[A]=G,TB=(l,A)=>{for(var G in A||(A={}))tx.call(A,G)&&gN(l,G,A[G]);if(aN)for(var G of aN(A))cx.call(A,G)&&gN(l,G,A[G]);return l},JG=(l,A,G)=>new Promise((b,t)=>{var c=d=>{try{e(G.next(d))}catch(Z){t(Z)}},B=d=>{try{e(G.throw(d))}catch(Z){t(Z)}},e=d=>d.done?b(d.value):Promise.resolve(d.value).then(c,B);e((G=G.apply(l,A)).next())}),Bx=6e4;function ex(l){let A=null,G=null,b=!1,t=()=>(G||(G=l().then(c=>(A={token:c.token,expMs:new Date(c.expiresAt).getTime()},c.token)).finally(()=>{G=null})),G);return{getToken(){return JG(this,null,function*(){if(b)throw new Error("delegation-closed");return A&&Date.now()<A.expMs-Bx?A.token:t()})},refresh(){return JG(this,null,function*(){if(b)throw new Error("delegation-closed");return A=null,t()})},close(){b=!0,A=null}}}var WN="publickey-credentials-get";function oN(l){let A=l;for(let G of[A?.featurePolicy,A?.permissionsPolicy]){let b=G;if(typeof b?.allowsFeature=="function")return b}return null}function Zx(l,A){try{return new URL(l).origin===new URL(A).origin}catch{return!1}}function dx(l,A){var G;if(!A)return null;let b=l?.querySelectorAll;if(typeof b!="function")return null;let t;try{t=b.call(l,"iframe")}catch{return null}for(let c=0;c<t.length;c+=1){let B=t[c],e=B?.src||((G=B?.getAttribute)==null?void 0:G.call(B,"src"))||"";if(e&&Zx(e,A))return B}return null}function nx(l,A){let G=oN(l);if(!G)return null;let b=oN(dx(l,A));if(b)try{return b.allowsFeature(WN,A)===!0}catch{return null}try{return G.allowsFeature(WN)===!1?!1:null}catch{return null}}function ax(l){if(typeof l!="object"||l===null)return!1;let{code:A,message:G}=l;return typeof A=="string"&&A.length>0&&typeof G=="string"}function hN(l,A){if(!l||!A)return!1;try{let G=new URL(l),b=new URL(A);return G.origin===b.origin}catch{return!1}}function sN(l,A){return!l||!A?!0:l===A}var gx="width=420,height=640,resizable=yes,scrollbars=yes",Wx=400,MB=class{constructor(l){this.popup=null,this.pending=new Map,this.listener=null,this.popupReady=!1,this.outbox=[],this.closeWatch=null,this.opts=TB({openPopup:ox,hostWindow:globalThis.window,defaultTimeoutMs:6e4,handshakeTimeoutMs:1e4,onDiag:()=>{}},l)}request(l,A){return JG(this,arguments,function*(G,b,t={}){var c,B,e;if(!this.popup||this.popup.closed){this.rejectClosedPending();let n=(B=(c=globalThis.location)==null?void 0:c.origin)!=null?B:"",h=`${this.opts.walletOrigin}/embed/wallet?origin=${encodeURIComponent(n)}`;if(this.popup=this.opts.openPopup(h,gx),!this.popup)throw new iG("popup-blocked","popup window failed to open");this.popupReady=!1,this.outbox=[],this.ensureListening()}let d=this.popup,Z=G.id,g=(e=t.timeoutMs)!=null?e:this.opts.defaultTimeoutMs;return new Promise((n,h)=>{let W=setTimeout(()=>{this.pending.has(Z)&&(this.pending.delete(Z),this.outbox=this.outbox.filter(m=>m.id!==Z),h(new iG("internal",`request "${G.type}" (id=${Z}) timed out after ${g}ms`)))},g);this.pending.set(Z,{expectedTypes:b,resolve:m=>n(m),reject:h,timer:W,popup:d}),this.popupReady?this.popup.postMessage(G,this.opts.walletOrigin):(this.outbox.push(G),this.armHandshakeTimeout(Z,G,W)),this.watchForClose()})})}watchForClose(){this.closeWatch||(this.closeWatch=setInterval(()=>{this.rejectClosedPending(),this.pending.size===0&&this.clearCloseWatch()},Wx))}rejectClosedPending(){for(let[l,A]of[...this.pending])A.popup.closed&&(clearTimeout(A.timer),this.pending.delete(l),this.outbox=this.outbox.filter(G=>G.id!==l),A.reject(new iG("popup-closed","the wallet popup was closed before it answered; nothing was created or signed")))}clearCloseWatch(){this.closeWatch&&(clearInterval(this.closeWatch),this.closeWatch=null)}armHandshakeTimeout(l,A,G){let b=this.opts.handshakeTimeoutMs;b>0&&setTimeout(()=>{if(this.popupReady)return;let t=this.pending.get(l);t&&(this.pending.delete(l),this.outbox=this.outbox.filter(c=>c.id!==l),clearTimeout(G),this.opts.onDiag("surface-not-ready",Date.now(),{transport:"popup",request:A.type}),t.reject(new iG("internal",`wallet popup at ${this.opts.walletOrigin} never signalled ready within ${b}ms, so "${A.type}" (id=${l}) was never delivered. The popup may have been blocked, navigated away, or opened by a previous page that has since reloaded (its opener link no longer reaches this document).`)))},b)}close(){this.clearCloseWatch(),this.rejectAllPending("transport closed"),this.popup&&!this.popup.closed&&this.popup.close(),this.popup=null,this.popupReady=!1,this.outbox=[]}destroy(){this.close(),this.listener&&(this.opts.hostWindow.removeEventListener("message",this.listener),this.listener=null)}rejectAllPending(l){for(let[A,G]of this.pending)clearTimeout(G.timer),this.pending.delete(A),G.reject(new iG("internal",l))}ensureListening(){this.listener||(this.listener=l=>this.onMessage(l),this.opts.hostWindow.addEventListener("message",this.listener))}onMessage(l){var A,G;if(!hN(l.origin,this.opts.walletOrigin)){let c=l.data;if(c&&typeof c.id=="string"&&this.pending.has(c.id)){let B=this.pending.get(c.id);this.pending.delete(c.id),clearTimeout(B.timer),B.reject(new iG("origin-mismatch",`message from "${l.origin}" rejected (expected "${this.opts.walletOrigin}")`))}return}let b=l.data;if(!b||typeof b.type!="string"||typeof b.id!="string"||!sN(l.source,this.popup))return;if(b.type==="wallet:ready"){if(this.popupReady)return;this.popupReady=!0;let c=this.outbox;if(this.outbox=[],this.popup&&!this.popup.closed)for(let B of c)this.popup.postMessage(B,this.opts.walletOrigin);return}if(b.type==="wallet:diag"){(G=(A=this.opts).onDiag)==null||G.call(A,b.name,b.at,b.detail);return}let t=this.pending.get(b.id);if(t){if(clearTimeout(t.timer),this.pending.delete(b.id),this.pending.size===0&&this.clearCloseWatch(),b.type==="wallet:error"){t.reject(new iG(b.code,b.message,b.traceId));return}if(!t.expectedTypes.includes(b.type)){t.reject(new iG("internal",`received unexpected response type "${b.type}" for id "${b.id}"`));return}t.resolve(b)}}};function ox(l,A){let G=globalThis.window;return G?.open(l,"_blank",A)}var hx=class{constructor(l){this.iframe=null,this.pending=new Map,this.listener=null,this.ready=!1,this.outbox=[],this.backdrop=null,this.hiddenCssText="",this.overlayVisible=!1,this.opts=TB({hostWindow:globalThis.window,document:globalThis.document,defaultTimeoutMs:6e4,handshakeTimeoutMs:1e4,mountIframe:l.mountIframe,onOverlay:l.onOverlay,onDiag:l.onDiag},l)}ensureIframe(){var l,A,G;if(this.iframe)return;let b=(A=(l=globalThis.location)==null?void 0:l.origin)!=null?A:"",t=`${this.opts.walletOrigin}/embed/wallet?origin=${encodeURIComponent(b)}`,c=`publickey-credentials-get ${this.opts.walletOrigin}`;if(this.opts.mountIframe)this.iframe=this.opts.mountIframe(t,c);else{let B=this.opts.document.createElement("iframe");B.src=t,B.setAttribute("allow",c),B.style.cssText="position:fixed;border:0;width:0;height:0;left:-9999px;",this.opts.document.body.appendChild(B),this.iframe=B}this.hiddenCssText=(G=this.iframe.style.cssText)!=null?G:"",this.ready=!1,this.outbox=[],this.overlayVisible=!1,this.ensureListening()}showOverlay(){var l,A;if(!this.overlayVisible){if(this.overlayVisible=!0,this.iframe){let G=this.opts.document.createElement("div");G.setAttribute("data-wallet-overlay-backdrop",""),G.style.cssText="position:fixed;inset:0;background:rgba(0,0,0,.4);z-index:2147483646;",this.opts.document.body.appendChild(G),this.backdrop=G,this.iframe.style.cssText="position:fixed;border:0;z-index:2147483647;width:min(420px,100vw);height:min(640px,100vh);left:50%;top:50%;transform:translate(-50%,-50%);"}(A=(l=this.opts).onOverlay)==null||A.call(l,!0)}}hideOverlay(){var l,A,G;this.overlayVisible&&(this.overlayVisible=!1,(l=this.backdrop)==null||l.remove(),this.backdrop=null,this.iframe&&(this.iframe.style.cssText=this.hiddenCssText),(G=(A=this.opts).onOverlay)==null||G.call(A,!1))}ensureListening(){this.listener||(this.listener=l=>this.onMessage(l),this.opts.hostWindow.addEventListener("message",this.listener))}request(l,A){return JG(this,arguments,function*(G,b,t={}){var c;this.ensureIframe();let B=G.id,e=(c=t.timeoutMs)!=null?c:this.opts.defaultTimeoutMs;return new Promise((d,Z)=>{let g=setTimeout(()=>{this.pending.has(B)&&(this.pending.delete(B),this.outbox=this.outbox.filter(n=>n.id!==B),Z(new iG("internal",`request "${G.type}" (id=${B}) timed out after ${e}ms`)))},e);this.pending.set(B,{expectedTypes:b,resolve:n=>d(n),reject:Z,timer:g}),this.ready?this.postToIframe(G):(this.outbox.push(G),this.armHandshakeTimeout(B,G,g))})})}armHandshakeTimeout(l,A,G){let b=this.opts.handshakeTimeoutMs;b>0&&setTimeout(()=>{var t,c;if(this.ready)return;let B=this.pending.get(l);B&&(this.pending.delete(l),this.outbox=this.outbox.filter(e=>e.id!==l),clearTimeout(G),(c=(t=this.opts).onDiag)==null||c.call(t,"surface-not-ready",Date.now(),{transport:"iframe",request:A.type}),B.reject(new iG("internal",`wallet iframe at ${this.opts.walletOrigin} never signalled ready within ${b}ms, so "${A.type}" (id=${l}) was never delivered. Check that the wallet origin is reachable and that the host page's Permissions-Policy / CSP does not block the embedded document.`)))},b)}postToIframe(l){var A,G;(G=(A=this.iframe)==null?void 0:A.contentWindow)==null||G.postMessage(l,this.opts.walletOrigin)}close(){var l,A;this.rejectAllPending("transport closed"),(l=this.backdrop)==null||l.remove(),this.backdrop=null,this.overlayVisible=!1,(A=this.iframe)==null||A.remove(),this.iframe=null,this.ready=!1,this.outbox=[]}destroy(){this.close(),this.listener&&(this.opts.hostWindow.removeEventListener("message",this.listener),this.listener=null)}rejectAllPending(l){for(let[A,G]of this.pending)clearTimeout(G.timer),this.pending.delete(A),G.reject(new iG("internal",l))}onMessage(l){var A,G,b;let t=l.data;if(!hN(l.origin,this.opts.walletOrigin)){if(t&&typeof t.id=="string"&&this.pending.has(t.id)){let B=this.pending.get(t.id);this.pending.delete(t.id),clearTimeout(B.timer),B.reject(new iG("origin-mismatch",`message from "${l.origin}" rejected (expected "${this.opts.walletOrigin}")`))}return}if(!t||typeof t.type!="string"||typeof t.id!="string"||!sN(l.source,(A=this.iframe)==null?void 0:A.contentWindow))return;if(t.type==="wallet:ready"){if(this.ready)return;this.ready=!0;let B=this.outbox;this.outbox=[];for(let e of B)this.postToIframe(e);return}if(t.type==="wallet:ui:show"){this.showOverlay();return}if(t.type==="wallet:ui:hide"){this.hideOverlay();return}if(t.type==="wallet:diag"){(b=(G=this.opts).onDiag)==null||b.call(G,t.name,t.at,t.detail);return}let c=this.pending.get(t.id);if(c){if(clearTimeout(c.timer),this.pending.delete(t.id),t.type==="wallet:error"){c.reject(new iG(t.code,t.message,t.traceId));return}if(!c.expectedTypes.includes(t.type)){c.reject(new iG("internal",`received unexpected response type "${t.type}" for id "${t.id}"`));return}c.resolve(t)}}},sx=15*6e4;function rx(l,A){let G=new Set([...Object.keys(l),...Object.keys(A)]);for(let b of G)if(l[b]!==A[b])return!1;return!0}var rN=class{constructor(l){this._addresses=null,this._credentialId=null,this._accountId=null,this._email=null,this._displayName=null,this._hasKeys=!1,this.policyRefused=!1,this._listeners={},this.registerInFlight=null,this.loginInFlight=null,this.relayDiag=(Z,g,n)=>{this.emit("diag",TB({type:"diag",name:Z,at:g},n?{detail:n}:{}))};var A,G,b,t,c,B,e;let d=(A=l.__internal__)==null?void 0:A.transport;if(!d&&!l.walletOrigin)throw new Error("EmbedWallet: `walletOrigin` is required (e.g. https://wallet.example.com).");this.appId=l.appId,this.walletOrigin=(G=l.walletOrigin)!=null?G:"",this.popup={width:(t=(b=l.popup)==null?void 0:b.width)!=null?t:420,height:(B=(c=l.popup)==null?void 0:c.height)!=null?B:640},this.appName=(e=l.appName)!=null?e:"",this.popupOpener=l.popupOpener,this.transport=d??(l.transport==="popup"?new MB({walletOrigin:this.walletOrigin,onDiag:this.relayDiag}):new hx({walletOrigin:this.walletOrigin,onDiag:this.relayDiag}))}get isLoggedIn(){return this._addresses!==null}get addresses(){return this._addresses}get credentialId(){return this._credentialId}get accountId(){return this._accountId}get email(){return this._email}get displayName(){return this._displayName}get hasKeys(){return this._hasKeys}get ceremonySurface(){return this.transport instanceof MB||this.policyRefused||nx(globalThis.document,this.walletOrigin)===!1?"popup":"iframe"}register(){return JG(this,arguments,function*(l={}){return this.registerInFlight||(this.registerInFlight=this.registerImpl(l).finally(()=>{this.registerInFlight=null})),this.registerInFlight})}registerImpl(l){return JG(this,null,function*(){if(this.transport instanceof MB)return this.helloAndAwaitLogin("register",l);let A=new MB(TB({walletOrigin:this.walletOrigin,onDiag:this.relayDiag},this.popupOpener?{openPopup:this.popupOpener}:{}));this.diagPopup("popup-open","register");let G;try{G=yield this.helloAndAwaitLogin("register",l,A)}finally{A.close(),this.diagPopup("popup-close","register")}try{let b=yield this.helloAndAwaitLogin("login",{credentialId:G.credentialId},this.transport,G.credentialId,!1);if(!rx(b.addresses,G.addresses))throw this.clearSessionState(),this.emit("logout",{type:"logout"}),new iG("derivation-mismatch","in-frame re-derivation after registration produced different addresses than the registration ceremony");this._hasKeys=!0,this.diag("session-state",{state:"keyed",hasKeys:!0})}catch(b){if(b instanceof iG&&b.code==="derivation-mismatch")throw b;this._hasKeys=!1,this.diag("session-state",{state:"bearer-active",hasKeys:!1})}return G})}resume(){return JG(this,null,function*(){var l,A,G;let b=yield this.checkSessionStatus();return b?.authenticated&&b.addresses&&b.credentialId?(this._addresses=b.addresses,this._credentialId=b.credentialId,this._hasKeys=b.hasKeys,this._accountId=(l=b.accountId)!=null?l:null,this._email=b.accountId&&(A=b.email)!=null?A:null,this._displayName=b.accountId&&(G=b.displayName)!=null?G:null,this.diag("adopt-session",{hasKeys:b.hasKeys}),this.diag("session-state",{state:b.hasKeys?"keyed":"bearer-active",hasKeys:b.hasKeys}),this.emit("login",{type:"login",addresses:b.addresses}),{addresses:b.addresses,credentialId:b.credentialId,accountCreated:!1}):null})}login(){return JG(this,null,function*(){return this.loginInFlight||(this.loginInFlight=this.loginImpl().finally(()=>{this.loginInFlight=null})),this.loginInFlight})}loginImpl(){return JG(this,null,function*(){let l=yield this.resume();if(l)return l;try{let A=yield this.helloAndAwaitLogin("login");return this._hasKeys=!0,this.diag("session-state",{state:"keyed",hasKeys:!0}),A}catch(A){return this.assertPopupFallbackAllowed(A),this.loginViaPopup()}})}loginViaPopup(){return JG(this,null,function*(){let l=new MB(TB({walletOrigin:this.walletOrigin,onDiag:this.relayDiag},this.popupOpener?{openPopup:this.popupOpener}:{}));this.diagPopup("popup-open","login");try{let A=yield this.helloAndAwaitLogin("login",{},l);return this._hasKeys=!1,this.diag("session-state",{state:"bearer-active",hasKeys:!1}),A}finally{l.close(),this.diagPopup("popup-close","login")}})}assertPopupFallbackAllowed(l){if(!ax(l)||l.code!=="ceremony-policy-denied"||this.transport instanceof MB)throw l;this.policyRefused=!0,this.diag("iframe-ceremony-unavailable",{fallback:"popup"});let A=globalThis.navigator;if(A?.userActivation&&A.userActivation.isActive===!1)throw new iG("gesture-required","a popup ceremony needs a user gesture; retry from a click")}logout(){return JG(this,null,function*(){let l=crypto.randomUUID();try{yield this.transport.request({type:"wallet:logout",id:l},["wallet:result"])}catch{}this.clearSessionState(),this.transport.close(),this.diag("session-state",{state:"logged-out",hasKeys:!1}),this.emit("logout",{type:"logout"})})}clearSessionState(){this._addresses=null,this._credentialId=null,this._hasKeys=!1,this._accountId=null,this._email=null,this._displayName=null}getSigner(l){this.assertLoggedIn("getSigner");let A=(b,t)=>JG(this,null,function*(){return this.signWithStepUp({chain:b,payload:t,requestKind:"sdk"})}),G=this._addresses;switch(l.chain){case"evm":return this.withLiveAddress(new ZN({address:G.evm,sign:A}),()=>this.requireAddresses("getSigner").evm);case"cere":return this.withLiveAddress(new dN({address:G.cere,sign:A}),()=>this.requireAddresses("getSigner").cere);case"solana":return this.withLiveAddress(new nN({address:G.solana,sign:A}),()=>this.requireAddresses("getSigner").solana);default:throw new iG("validation",`getSigner: unknown chain "${String(l.chain)}"`)}}asSigner(){this.assertLoggedIn("asSigner");let l=(G,b,t)=>JG(this,null,function*(){if(!this.isLoggedIn)throw new iG("unauthorized","asSigner: wallet is no longer logged in");return this.signWithStepUp({chain:"cere",payload:G,requestKind:b??"sdk",humanReadable:t})}),A=this;return{type:"ed25519",get address(){return A.requireAddresses("asSigner").cere},get publicKey(){return cN(A.requireAddresses("asSigner").solana)},isReady:()=>JG(this,null,function*(){return this.isLoggedIn}),sign:(G,b,t)=>l(G,b,t?.humanReadable)}}requestDelegation(l){return JG(this,null,function*(){this.assertLoggedIn("requestDelegation");let A=crypto.randomUUID(),G={capabilities:l.capabilities,appId:l.appId,agentPubkey:l.agentPubkey,constraints:l.constraints};return(yield this.transport.request({type:"wallet:requestDelegation",id:A,scope:G,ttl:l.ttl},["wallet:result"])).result})}createDelegation(l){return ex(()=>this.requestDelegation(l))}findApplications(){return JG(this,arguments,function*(l={}){this.assertLoggedIn("findApplications");let A=crypto.randomUUID();return(yield this.transport.request({type:"wallet:findApplications",id:A,appId:l.appId},["wallet:result"])).result})}saveApplication(l){return JG(this,null,function*(){this.assertLoggedIn("saveApplication");let A=crypto.randomUUID();return(yield this.transport.request({type:"wallet:saveApplication",id:A,permissions:l.permissions,email:l.email},["wallet:result"])).result})}on(l,A){var G;let b=this._listeners;return((G=b[l])!=null?G:b[l]=new Set).add(A),this}off(l,A){var G;return(G=this._listeners[l])==null||G.delete(A),this}dispose(){this._addresses=null,this._credentialId=null,this._hasKeys=!1,this._accountId=null,this._email=null,this._displayName=null,this._listeners={},this.transport.destroy()}appContext(){let l=typeof window<"u"?window.location.origin:"";return{appId:this.appId,name:this.appName,origin:l}}helloAndAwaitLogin(l){return JG(this,arguments,function*(A,G={},b=this.transport,t,c=!0){var B,e,d,Z,g,n;let W={type:"wallet:hello",id:crypto.randomUUID(),appContext:this.appContext(),intent:A,label:G.label,credentialId:G.credentialId},m=yield b.request(W,["wallet:login:ok"],A==="register"?{timeoutMs:sx}:{});if(t!==void 0&&m.credentialId!==t)throw new iG("unauthorized","helloAndAwaitLogin: step-up ceremony returned a different credential than the active session; refusing to sign");this._addresses=m.addresses,this._credentialId=m.credentialId,this._hasKeys=!0,this._accountId=(e=(B=m.account)==null?void 0:B.accountId)!=null?e:null,this._email=(Z=(d=m.account)==null?void 0:d.email)!=null?Z:null,this._displayName=(n=(g=m.account)==null?void 0:g.displayName)!=null?n:null,c&&this.emit("login",{type:"login",addresses:m.addresses});let Y=A==="register"?m.accountCreated:!1;return TB({addresses:m.addresses,credentialId:m.credentialId},Y===void 0?{}:{accountCreated:Y})})}signWithStepUp(l){return JG(this,null,function*(){if(this._hasKeys)try{return yield this.sendSign(this.transport,l)}catch(G){throw G instanceof iG&&G.code==="needs-step-up"&&(this._hasKeys=!1),G}let A=this._credentialId;if(this.transport instanceof MB)return yield this.helloAndAwaitLogin("login",{credentialId:A??void 0},this.transport,A??void 0),this.sendSign(this.transport,l);try{yield this.helloAndAwaitLogin("login",{credentialId:A??void 0},this.transport,A??void 0)}catch(G){return this.assertPopupFallbackAllowed(G),this.stepUpViaPopup(l,A)}return this._hasKeys=!0,this.diag("session-state",{state:"keyed",hasKeys:!0}),this.sendSign(this.transport,l)})}stepUpViaPopup(l,A){return JG(this,null,function*(){let G=new MB(TB({walletOrigin:this.walletOrigin,onDiag:this.relayDiag},this.popupOpener?{openPopup:this.popupOpener}:{}));this.diagPopup("popup-open","step-up");try{yield this.helloAndAwaitLogin("login",{credentialId:A??void 0},G,A??void 0);let b=yield this.sendSign(G,l);return this._hasKeys=!1,this.diag("session-state",{state:"bearer-active",hasKeys:!1}),b}finally{G.close(),this.diagPopup("popup-close","step-up")}})}sendSign(l,A){return JG(this,null,function*(){let G=crypto.randomUUID(),t=(yield l.request({type:"wallet:sign",id:G,chain:A.chain,payload:A.payload,requestKind:A.requestKind,humanReadable:A.humanReadable},["wallet:result"])).result;if(!(t instanceof Uint8Array))throw new iG("internal",`popup returned non-Uint8Array sign result (got ${typeof t})`);return t})}checkSessionStatus(){return JG(this,null,function*(){let l=crypto.randomUUID();try{return(yield this.transport.request({type:"wallet:session:status",id:l},["wallet:result"])).result}catch{return null}})}emit(l,A){let G=this._listeners[l];if(G)for(let b of G)try{b(A)}catch{}}diagPopup(l,A){this.diag(l,{intent:A})}diag(l,A){this.emit("diag",TB({type:"diag",name:l,at:Date.now()},A?{detail:A}:{}))}assertLoggedIn(l){if(!this._addresses)throw new iG("unauthorized",`${l}: not logged in`)}requireAddresses(l){if(!this._addresses)throw new iG("unauthorized",`${l}: not logged in`);return this._addresses}withLiveAddress(l,A){return Object.defineProperty(l,"address",{get:A,enumerable:!0,configurable:!0}),l}};var ix=["ddc-read","ddc-write"],iN="cef-widget",mx="1h",Vx=60*60*1e3,ux=10*60*1e3,$m=class extends Error{constructor(){super("PopupBlockedError: the browser did not open the wallet window"),this.name="PopupBlockedError"}},Yx=(l,A)=>{let G=window.open(l,"_blank",A);if(!G)throw new $m;return G},l2=class extends Error{constructor(){super("WidgetWalletUnconfiguredError: this widget was published without a `wallet.origin`, so there is no wallet to sign in to. Rebuild and republish it with a CLI new enough to stamp one (`cef push --kind widget`)."),this.name="WidgetWalletUnconfiguredError"}};function Ix(l){let A=l.publicKey,G="0x";for(let b of A)G+=b.toString(16).padStart(2,"0");return G}function mN(l){if(!l.walletOrigin)throw new l2;let A=new rN({appId:iN,appName:l.appName??"CEF widget",walletOrigin:l.walletOrigin,...l.transport?{transport:l.transport}:{},...l.transport==="popup"?{popupOpener:Yx}:{}}),G=null,b=()=>{let c=G;if(c&&Date.now()-c.mintedAt<Vx-ux)return c.token;let B=A.requestDelegation({capabilities:[...ix],appId:iN,ttl:mx}).then(e=>e.token).catch(e=>{throw G=null,e});return G={token:B,mintedAt:Date.now()},B},t=()=>{let c=A.asSigner(),B=Ix(c);return{pubkey:()=>B,sigType:"ed25519",signRawBytes:e=>c.sign(e),delegation:b}};return{async resume(){return await A.resume()?(G=null,t()):null},async signIn(){return await A.login(),G=null,t()},async register(){return await A.register(),G=null,t()},ceremonySurface(){return A.ceremonySurface}}}var VN="cef-widget-signin",Rx={title:"Sign in to view this",body:"This page reads data you need permission for. Sign in with your CEF account \u2014 the same one you use for the console.",signIn:"Sign in",register:"Create an account"};function DB(l,A,G){let b=document.createElement(l);return b.setAttribute("style",A),G!==void 0&&(b.textContent=G),b}var Xx=["position:fixed","inset:0","z-index:2147483000","display:flex","align-items:center","justify-content:center","padding:24px","background:rgba(15,18,25,.55)",'font:14px/1.5 system-ui,-apple-system,"Segoe UI",sans-serif'].join(";"),px=["max-width:420px","width:100%","box-sizing:border-box","background:#fff","color:#11151c","border-radius:14px","padding:28px","box-shadow:0 18px 48px rgba(15,18,25,.28)"].join(";"),Fx=["appearance:none","border:0","border-radius:9px","padding:11px 18px","font:inherit","font-weight:600","cursor:pointer","background:#6b3df5","color:#fff"].join(";"),yx=["appearance:none","border:1px solid #d7dae2","border-radius:9px","padding:11px 18px","font:inherit","font-weight:600","cursor:pointer","background:#fff","color:#11151c"].join(";");function Qx(l,A={},G){let b={...Rx,...A};return new Promise(t=>{let c=document.getElementById(VN);c&&c.remove();let B=DB("div",Xx);B.id=VN;let e=DB("div",px);e.appendChild(DB("h2","margin:0 0 8px;font-size:18px;font-weight:700",b.title)),e.appendChild(DB("p","margin:0 0 20px;color:#4a5160",b.body));let d=DB("div","display:flex;gap:10px;flex-wrap:wrap"),Z=DB("button",Fx,b.signIn),g=DB("button",yx,b.register);Z.type="button",g.type="button",d.appendChild(Z),d.appendChild(g),e.appendChild(d);let n=DB("p","margin:16px 0 0;color:#b00020;display:none");e.appendChild(n),B.appendChild(e),document.body.appendChild(B);let h=!1,W=l,m=!1,Y=R=>()=>{h||(h=!0,n.style.display="none",Z.disabled=!0,g.disabled=!0,B.style.display="none",R(W).catch(u=>{if(!G||m)throw u;return m=!0,W=G(),console.info("[widget-runtime] framed ceremony refused; retrying in a popup",u),R(W)}).then(u=>{B.remove(),t(u)}).catch(u=>{h=!1,B.style.display="flex",Z.disabled=!1,g.disabled=!1,n.textContent=u instanceof Error?u.message:String(u),n.style.display="block"}))};Z.addEventListener("click",Y(R=>R.signIn())),g.addEventListener("click",Y(R=>R.register()))})}async function uN(l,A,G={}){let b=!0;try{let c=await l.resume();if(c)return c}catch(c){b=!1,console.info("[widget-runtime] wallet surface did not come up; skipping the framed ceremony",c)}if(b)try{return await l.signIn()}catch(c){console.info("[widget-runtime] framed ceremony refused; trying a popup",c)}let t=A();try{return await t.signIn()}catch(c){console.info("[widget-runtime] popup did not open on its own; asking for a click",c)}return Qx(t,G)}var A2={vaultId:["vaultId","vault"],runId:["runId","run"],recordId:["recordId","record"]};function YN(l,A){for(let G of A){let b=l.get(G);if(b&&b.trim())return b.trim()}}function Nx(l){let A=l.hash??"",G=A.indexOf("?"),b=G>=0?A.slice(G+1):A.replace(/^#/,""),t=new URLSearchParams(b),c=new URLSearchParams((l.search??"").replace(/^\?/,"")),B=n=>YN(t,n)??YN(c,n),e={},d=B(A2.vaultId),Z=B(A2.runId),g=B(A2.recordId);return d&&(e.vaultId=d),Z&&(e.runId=Z),g&&(e.recordId=g),Object.keys(e).length>0?e:void 0}function IN(){if(!(typeof window>"u"||!window.location))return Nx(window.location)}var G2=class extends Error{constructor(A="WidgetSignedOutError: the embedding host did not supply an identity (no cef-widget:identity-response within 8s, or a malformed one). Mount createWidgetHost() on the host page."){super(A),this.name="WidgetSignedOutError"}};function RN(l){let A=null;return function(){return A||(A=(async()=>{let b=await l.bridge.requestIdentity();if(b)return{source:"host",publicKey:b.pubkey,sigType:b.sigType,sign:d=>l.bridge.sign(d),...b.token?{token:b.token}:{},...b.context?{context:b.context}:{}};if(window.parent!==window)throw new G2;let t=await l.connectWallet(),c,B=t.delegation?.bind(t);if(B)try{c=await B()}catch(d){console.warn("[widget-runtime] no delegation minted; falling back to signing",d)}let e=l.linkContext?.();return{source:"wallet",publicKey:t.pubkey(),sigType:t.sigType,sign:d=>t.signRawBytes(d),...c&&B?{token:c,renewToken:B}:{},...e?{context:e}:{}}})().catch(b=>{throw A=null,b}),A)}}var uo=class extends Error{constructor(A,G){let b=G===void 0?"this build of the runtime has no vault.byId to open it with":G instanceof Error?G.message:String(G);super(`WidgetVaultUnreachableError: the host opened this widget on vault ${A}, and it cannot be read from here (${b}). Falling back to your own vault would answer from a different database \u2014 which looks exactly like a run that produced nothing.`),this.name="WidgetVaultUnreachableError",this.vaultId=A,this.reason=b}};async function b2(l,A,G){if(!A)return l.ensure({onboard:!1,...G?{delegationToken:G}:{}});if(typeof l.byId!="function")throw new uo(A);try{return await l.byId(A)}catch(b){throw new uo(A,b)}}function XN(l){if(l&&typeof l=="object"&&"columns"in l&&"rows"in l){let A=l.columns,G=l.rows;if(Array.isArray(A)&&Array.isArray(G))return{columns:A.map(String),rows:G,meta:{rowCount:G.length}}}if(Array.isArray(l)){let A=l.length>0?Object.keys(l[0]):[],G=l.map(b=>A.map(t=>b[t]));return{columns:A,rows:G,meta:{rowCount:l.length}}}return console.warn("[widget-runtime] unrecognized cubby query result shape; treating as empty",l),{columns:[],rows:[],meta:{rowCount:0}}}function pN(l,A,G,b){let t,c,B=()=>t??(t=A()),e=async()=>b2(B().vault,b,G),d=()=>(c??(c=e().catch(W=>{throw c=void 0,W})),c),Z=W=>l.queries.find(m=>m.id===W),g=()=>{let W=l.agentId.indexOf(":");return W>0?l.agentId.slice(0,W):""},n=async(W,m)=>{let Y=await d();if(!Y.service)throw new Error(`[widget-runtime] this host's vault-sdk has no agent-service cubby surface, so the query "${W.id}" cannot be answered here`);let R=g();if(!R)throw new Error(`[widget-runtime] "${W.id}" reads the agent service's cubby, but "${l.agentId}" carries no service key to read it from`);let u=W.cubby??l.cubbyAlias;if(!u)throw new Error(`[widget-runtime] "${W.id}" reads the agent service's cubby but names none, and this widget has no cubbyAlias to fall back on \u2014 set \`cubby\` on the query`);return Y.service(R).cubby(u).query(W.sql??"",m)},h=async(W,m)=>{let Y=await d();if(!Y.memory)throw new Error(`[widget-runtime] this host's vault-sdk has no memory surface, so the query "${W.id}" cannot be answered here`);let R=m[0],u=W.limit;switch(W.tool??"search"){case"search":return Y.memory.search(String(R??""),u?{limit:u}:void 0);case"get":return Y.memory.get(String(R??""));case"neighbours":return Y.memory.neighbours(String(R??""),u?{limit:u}:void 0);case"countByType":return Y.memory.countByType();default:throw new Error(`[widget-runtime] "${W.id}" names no memory tool this runtime knows`)}};return{async query(W,m){let Y=Z(W);return Y?.tool?XN(await h(Y,m??[])):XN(await n(Y??{id:W,label:W,sql:W},m??[]))},async publish(W,m,Y,R){return(await d()).scope(l.scope).publish({type:W,context:Y??"",payload:m,...R?.target?{target:R.target}:{}})},async connectAgent(){await(await d()).agents.connect({agentId:l.agentId,scope:l.scope})},async agentStatus(){try{return(await(await d()).agents.get(l.agentId)).status==="active"?"connected":"disconnected"}catch{return"disconnected"}}}}function t2(l,A,G,b){let t={endpoint:l.vault,garEndpoint:l.gar,marketplaceEndpoint:l.marketplace,s3GatewayAuthInfoUrl:l.s3GatewayAuthInfo,chainUrl:l.rpc};return b?{...t,auth:Ex(b)}:G?{...t,auth:new hd(G)}:{...t,signer:A}}function Ex(l){return{authenticate:async A=>new hd(await l()).authenticate(A)}}function FN(l,A){let G="anon",b="",t,c,B=new Set,e=Z=>{G=Z;let g={publicKey:b,status:G,...t?{context:t}:{}};for(let n of B)n(g)};function d(){return c??(c=(async()=>{e("connecting");let Z=await A.resolveIdentity(l);b=Z.publicKey,t=Z.context;let g=A.buildVaultClient(l,Z);return e("ready"),g})().catch(Z=>{throw c=void 0,e("anon"),Z})),c}return{async query(Z,g){return(await d()).query(Z,g)},async publish(Z,g,n,h){return(await d()).publish(Z,g,n,h)},async identity(){return await d(),{publicKey:b,status:G,...t?{context:t}:{}}},async connect(){return await d(),{publicKey:b,status:G,...t?{context:t}:{}}},async connectAgent(){await(await d()).connectAgent()},async agentStatus(){return(await d()).agentStatus()},onIdentityChange(Z){return B.add(Z),()=>B.delete(Z)}}}var cgl=new TextEncoder;function yN(l,A){let G=new ArrayBuffer(44+l.length*2),b=new DataView(G),t=(B,e)=>{for(let d=0;d<e.length;d++)b.setUint8(B+d,e.charCodeAt(d))};t(0,"RIFF"),b.setUint32(4,36+l.length*2,!0),t(8,"WAVE"),t(12,"fmt "),b.setUint32(16,16,!0),b.setUint16(20,1,!0),b.setUint16(22,1,!0),b.setUint32(24,A,!0),b.setUint32(28,A*2,!0),b.setUint16(32,2,!0),b.setUint16(34,16,!0),t(36,"data"),b.setUint32(40,l.length*2,!0);let c=44;for(let B=0;B<l.length;B++,c+=2){let e=Math.max(-1,Math.min(1,l[B]));b.setInt16(c,e<0?e*32768:e*32767,!0)}return G}function QN(l,A,G){let b=A*G,t=[];for(let c=0;c<l.length;c+=b)t.push(l.subarray(c,Math.min(c+b,l.length)));return t.length?t:[l]}async function NN(l){let A=await l.arrayBuffer(),G=window.OfflineAudioContext||window.webkitOfflineAudioContext,b=new(window.AudioContext||window.webkitAudioContext),t=await b.decodeAudioData(A.slice(0));b.close();let c=Math.ceil(t.duration*16e3),B=new G(1,c,16e3),e=B.createBufferSource();return e.buffer=t,e.connect(B.destination),e.start(),(await B.startRendering()).getChannelData(0).slice()}var dgl=Object.freeze({PUT:1,GET:2,DELETE:3}),ngl=Object.freeze({ED_25519:0,SR_25519:1});async function EN(l,A){let G=l.segmentSeconds??25,b=await A.decode(l.blob),t=b.length/A.sampleRate;l.softCapSeconds&&t>l.softCapSeconds&&l.onWarn?.(`Recording is ${Math.round(t/60)} min; long uploads may be slow.`);let c=QN(b,A.sampleRate,G),B=[];for(let e=0;e<c.length;e++)B.push(await A.upload(yN(c[e],A.sampleRate),e)),l.onProgress?.(e+1,c.length);return A.upload.finalizeUrls?await A.upload.finalizeUrls(B):B}function vN(l){let A=l.keyPrefix??`widget-audio/${crypto.randomUUID()}`,G=l.readTtlSeconds?{ttlSeconds:l.readTtlSeconds}:{},b=async function(c,B){let e=`${A}/${B}.wav`;return await l.objects.upload(e,new Uint8Array(c),{contentType:"audio/wav"}),(await l.objects.presignedUrl(e,G)).url};return b.finalizeUrls=async t=>Promise.all(t.map(async(c,B)=>(await l.objects.presignedUrl(`${A}/${B}.wav`,G)).url)),b}d2();function Ux(l){typeof document<"u"&&document.readyState==="loading"?document.addEventListener("DOMContentLoaded",l,{once:!0}):l()}async function Cx(l){let A=l.wallet?.origin;if(!A)return GN(l.wallet);let G=b=>mN({walletOrigin:A,appName:l.name,...b?{transport:b}:{}});return uN(G(),()=>G("popup"))}function Sx(){let l=window.WidgetSandbox?.manifest;if(!l)return;let A=KQ(),G=RN({bridge:A,connectWallet:()=>Cx(l),linkContext:IN}),b,t,c={resolveIdentity:async()=>{let e=await G();return b=e.token,t=e.renewToken,{source:e.source,publicKey:e.publicKey,sigType:e.sigType,...e.context?{context:e.context}:{}}},buildVaultClient:(e,d)=>{let Z=d.sigType??"ed25519",g=b,n=t,h=Y=>G().then(R=>R.sign(Y)),W=qm(d.publicKey,Z,h);return pN(e,()=>new _Z(t2(e.endpoints,W,g,n)),g,d.context?.vaultId)}},B;if(l.kind==="submit"||l.kind==="conversation"||l.kind==="composite"){let e=null,d=()=>e||(e=(async()=>{let g=await G(),n=qm(g.publicKey,g.sigType,g.sign),h=new _Z(t2(l.endpoints,n,g.token,g.renewToken)),W=await b2(h.vault,g.context?.vaultId,g.token);return vN({objects:W.scope(l.scope).objects})})().catch(g=>{throw e=null,g}),e);B={uploadAudio:(g,n)=>d().then(h=>EN({blob:g,segmentSeconds:n?.segmentSeconds,softCapSeconds:n?.softCapSeconds,onProgress:n?.onProgress,onWarn:n?.onWarn},{decode:NN,upload:h,sampleRate:16e3}))}}window.WidgetRuntime=FN(l,c),window.registerCompositePanel=ON,l.kind&&l.kind!=="custom"&&l.config&&Ux(()=>{let e=document.getElementById("app");if(!e){console.error(`[widget-runtime] widget "${l.widgetId}" declares kind "${l.kind}" but its entry HTML has no <div id="app"></div>, so there is nowhere to render. Add the element, or declare kind "custom" and mount it yourself.`);return}Promise.resolve().then(()=>(Z2(),MN)).then(({mountKind:d})=>d(e,l.config,window.WidgetRuntime,B))})}Sx();})();
307
307
  /*! Bundled license information:
308
308
 
309
309
  @scure/base/index.js: