@enbox/browser 0.3.45 → 0.3.47

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.
package/dist/browser.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import{Enbox as oo,defineProtocol as ro,repository as io}from"@enbox/api";import{AuthManager as ao,AuthSession as lo,normalizeProtocolRequests as co,WalletConnect as po}from"@enbox/auth/browser";import{CONNECT_DENIED_TOKEN as fo,ConnectProvider as mo}from"@enbox/connect";import{DidDht as Et,DidWeb as xt,UniversalResolver as Ge}from"@enbox/dids";function X(e){let t=e.indexOf("://dweb/");if(t===-1)return null;let n=e.slice(0,t);if(n!=="http"&&n!=="https")return null;let r=e.slice(t+8);if(r.length===0)return null;let o=r.indexOf("/");return o===-1?[r,""]:o===0?null:[r.slice(0,o),r.slice(o+1)]}var be=new Ge({didResolvers:[Et,xt]}),Ye=/^http:/,ce=/\/$/,Fe="drl";async function Je(e){let{didDocument:t}=await be.resolve(e),n=t?.service?.find(r=>r.type==="DecentralizedWebNode")?.serviceEndpoint;return n?(Array.isArray(n)?n:[n]).filter(r=>typeof r=="string"&&r.startsWith("http")):[]}async function Qe(){if(!(typeof caches>"u"))return caches.open(Fe)}async function Ct(e,t,n,r){let o=e.request.url.replace(Ye,"https:").replace(ce,""),i=await Qe(),a=await i?.match(o);if(a){if(!navigator.onLine)return a;let s=await r?.onCacheCheck?.(e,o);if(s){let l=a.headers.get("dwn-cache-time");if(l&&Date.now()<Number(l)+(Number(s.ttl)||0))return a}}try{if(n)return await _t(e,t,o,n,i,r);{let s=await be.resolve(t);return new Response(JSON.stringify(s),{status:200,headers:{"Content-Type":"application/json"}})}}catch(s){return s instanceof Response?s:(console.log(`Error in DID URL fetch: ${s}`),new Response("DID URL fetch error",{status:500}))}}async function _t(e,t,n,r,o,i){let a=await Je(t);if(!a?.length)throw new Response("DWeb Node resolution failed: no valid endpoints found.",{status:530});let s;for(let l of a)try{let d=`${l.replace(ce,"")}/${t}/${r}`,p=await fetch(d,{headers:e.request.headers});if(p.ok)return await i?.onCacheCheck?.(e,n)&&o&&Pt(n,d,p,o),p;console.log(`DWN endpoint error: ${p.status}`),s=new Response("DWeb Node request failed",{status:p.status})}catch(d){console.log(`DWN endpoint error: ${d}`),s=new Response("DWeb Node request failed",{status:500})}return s}async function Pt(e,t,n,r){try{let o=n.clone(),i=new Headers(o.headers);i.append("dwn-cache-time",Date.now().toString()),i.append("dwn-composed-url",t);let a=new Response(o.body,{headers:i});await r.put(e,a)}catch(o){console.log(`Failed to cache DRL response: ${o}`)}}async function Rt(e={}){try{if(typeof ServiceWorkerGlobalScope<"u"&&self instanceof ServiceWorkerGlobalScope){let t=self;t.skipWaiting(),t.addEventListener("activate",n=>{n.waitUntil(t.clients.claim())}),t.addEventListener("fetch",n=>{let r=X(n.request.url);r&&n.respondWith(Ct(n,r[0],r[1],e))})}else if(globalThis?.navigator?.serviceWorker){if(!await navigator.serviceWorker.getRegistration("/")){let n=e.path||document?.currentScript?.src||import.meta.url;n&&navigator.serviceWorker.register(n,{type:"module"}).catch(r=>{console.error("DWeb networking feature installation failed: ",r)})}}else throw new Error("DWeb networking features are not available for install in this environment")}catch(t){console.error("Error in installing networking features:",t)}}var Xe=`
1
+ import{Enbox as Eo,defineProtocol as Co,repository as _o}from"@enbox/api";import{AuthManager as Po,AuthSession as Ro,normalizeProtocolRequests as Mo,WalletConnect as To}from"@enbox/auth/browser";import{CONNECT_DENIED_TOKEN as Wo,ConnectProvider as Lo}from"@enbox/connect";import{DidDht as At,DidWeb as Ut,UniversalResolver as ot}from"@enbox/dids";function ee(e){let t=e.indexOf("://dweb/");if(t===-1)return null;let n=e.slice(0,t);if(n!=="http"&&n!=="https")return null;let r=e.slice(t+8);if(r.length===0)return null;let o=r.indexOf("/");return o===-1?[r,""]:o===0?null:[r.slice(0,o),r.slice(o+1)]}var ke=new ot({didResolvers:[At,Ut]}),rt=/^http:/,me=/\/$/,it="drl";async function at(e){let{didDocument:t}=await ke.resolve(e),n=t?.service?.find(r=>r.type==="DecentralizedWebNode")?.serviceEndpoint;return n?(Array.isArray(n)?n:[n]).filter(r=>typeof r=="string"&&r.startsWith("http")):[]}async function st(){if(!(typeof caches>"u"))return caches.open(it)}async function qt(e,t,n,r){let o=e.request.url.replace(rt,"https:").replace(me,""),i=await st(),s=await i?.match(o);if(s){if(!navigator.onLine)return s;let a=await r?.onCacheCheck?.(e,o);if(a){let d=s.headers.get("dwn-cache-time");if(d&&Date.now()<Number(d)+(Number(a.ttl)||0))return s}}try{if(n)return await It(e,t,o,n,i,r);{let a=await ke.resolve(t);return new Response(JSON.stringify(a),{status:200,headers:{"Content-Type":"application/json"}})}}catch(a){return a instanceof Response?a:(console.log(`Error in DID URL fetch: ${a}`),new Response("DID URL fetch error",{status:500}))}}async function It(e,t,n,r,o,i){let s=await at(t);if(!s?.length)throw new Response("DWeb Node resolution failed: no valid endpoints found.",{status:530});let a;for(let d of s)try{let p=`${d.replace(me,"")}/${t}/${r}`,u=await fetch(p,{headers:e.request.headers});if(u.ok)return await i?.onCacheCheck?.(e,n)&&o&&Bt(n,p,u,o),u;console.log(`DWN endpoint error: ${u.status}`),a=new Response("DWeb Node request failed",{status:u.status})}catch(p){console.log(`DWN endpoint error: ${p}`),a=new Response("DWeb Node request failed",{status:500})}return a}async function Bt(e,t,n,r){try{let o=n.clone(),i=new Headers(o.headers);i.append("dwn-cache-time",Date.now().toString()),i.append("dwn-composed-url",t);let s=new Response(o.body,{headers:i});await r.put(e,s)}catch(o){console.log(`Failed to cache DRL response: ${o}`)}}async function jt(e={}){try{if(typeof ServiceWorkerGlobalScope<"u"&&self instanceof ServiceWorkerGlobalScope){let t=self;t.skipWaiting(),t.addEventListener("activate",n=>{n.waitUntil(t.clients.claim())}),t.addEventListener("fetch",n=>{let r=ee(n.request.url);r&&n.respondWith(qt(n,r[0],r[1],e))})}else if(globalThis?.navigator?.serviceWorker){if(!await navigator.serviceWorker.getRegistration("/")){let n=e.path||document?.currentScript?.src||import.meta.url;n&&navigator.serviceWorker.register(n,{type:"module"}).catch(r=>{console.error("DWeb networking feature installation failed: ",r)})}}else throw new Error("DWeb networking features are not available for install in this environment")}catch(t){console.error("Error in installing networking features:",t)}}var lt=`
2
2
  .drl-loading-overlay {
3
3
  position: fixed;
4
4
  inset: 0;
@@ -103,7 +103,7 @@ import{Enbox as oo,defineProtocol as ro,repository as io}from"@enbox/api";import
103
103
  opacity: 0;
104
104
  }
105
105
  }
106
- `,kt=`
106
+ `,Ht=`
107
107
  <!DOCTYPE html>
108
108
  <html lang='en'>
109
109
  <head>
@@ -119,7 +119,7 @@ import{Enbox as oo,defineProtocol as ro,repository as io}from"@enbox/api";import
119
119
  font-family: Arial, sans-serif;
120
120
  text-align: center;
121
121
  }
122
- ${Xe}
122
+ ${lt}
123
123
  </style>
124
124
  </head>
125
125
  <body>
@@ -132,8 +132,8 @@ import{Enbox as oo,defineProtocol as ro,repository as io}from"@enbox/api";import
132
132
  </div>
133
133
  </body>
134
134
  </html>
135
- `,de=!1,q=null,V=null;function Ke(){de||(V=document.createElement("style"),V.innerHTML=`
136
- ${Xe}
135
+ `,he=!1,H=null,te=null;function nt(){he||(te=document.createElement("style"),te.innerHTML=`
136
+ ${lt}
137
137
 
138
138
  .drl-loading-overlay {
139
139
  opacity: 0;
@@ -145,15 +145,38 @@ import{Enbox as oo,defineProtocol as ro,repository as io}from"@enbox/api";import
145
145
  opacity: 1;
146
146
  pointer-events: all;
147
147
  }
148
- `,document.head.append(V),q=document.createElement("div"),q.classList.add("drl-loading-overlay"),q.innerHTML=`
148
+ `,document.head.append(te),H=document.createElement("div"),H.classList.add("drl-loading-overlay"),H.innerHTML=`
149
149
  <div class='drl-loading-spinner'>
150
150
  <div></div>
151
151
  Loading DRL
152
152
  </div>
153
153
  <span tabindex='0'></span>
154
- `,q.lastElementChild.addEventListener("click",ve),document.body.prepend(q),de=!0)}function Mt(){de&&(V?.remove(),V=null,q?.remove(),q=null,de=!1)}function ve(){document.documentElement.removeAttribute("drl-link-loading"),le=null}var le=null,pe=!1,Z=null,ee=null;function Tt(){pe||(Z=async e=>{let t=e.target?.closest("a");if(t){let n=t.href,r=X(n);if(r){let o=r[0],i=r[1],a=t.target==="_blank";e.preventDefault();try{let s=null;a?(s=window.open("","_blank"),s&&s.document.write(kt)):(le=i,setTimeout(()=>document.documentElement.setAttribute("drl-link-loading",""),50));let l=await Je(o);if(!l.length)throw new Error("no valid DWN endpoints found");let d=`${l[0].replace(ce,"")}/${o}/${i}`;a?s&&!s.closed&&(s.location.href=d):le===i&&(window.location.href=d)}catch{throw le===i&&ve(),new Error(`DID endpoint resolution failed for the DRL: ${n}`)}}}},ee=async e=>{let t=e.composedPath()[0];if(e.pointerType==="mouse"&&e.button===2||e.pointerType==="touch"&&e.isPrimary){if(z(),t?.src&&X(t.src)){I=t,t.__src__=t.src;let n=t.src.replace(Ye,"https:").replace(ce,""),o=await(await Qe())?.match(n);if(o){let i=o.headers.get("dwn-composed-url");i&&(t.src=i)}t.addEventListener("pointerup",z,{once:!0})}}else t===I&&z()},document.addEventListener("click",Z),document.addEventListener("pointercancel",z),document.addEventListener("pointerdown",ee),pe=!0)}function St(){pe&&(Z&&(document.removeEventListener("click",Z),Z=null),ee&&(document.removeEventListener("pointerdown",ee),ee=null),document.removeEventListener("pointercancel",z),z(),ve(),pe=!1)}var I=null;async function z(e){e?.type==="pointerup"&&await new Promise(t=>requestAnimationFrame(()=>t())),I&&(I.src=I.__src__,delete I.__src__,I=null)}function Rn(e={}){e.didResolvers&&(be=new Ge({didResolvers:e.didResolvers})),e.serviceWorker!==!1&&Rt(e),typeof window<"u"&&typeof window.document<"u"&&(e.injectStyles!==!1&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Ke,{once:!0}):Ke()),e.links!==!1&&Tt())}function kn(){typeof window<"u"&&typeof window.document<"u"&&(St(),Mt())}async function Mn(){return typeof caches>"u"?!1:caches.delete(Fe)}import{ConnectClient as on}from"@enbox/connect";function Ve(e){let t=document.createElement("span");t.className="wallet-icon";let n=document.createElement("span");n.className="wallet-badge",n.textContent=e.name.charAt(0).toUpperCase(),t.appendChild(n);let r=Wt(e);if(r.length===0)return t;let o=document.createElement("img");o.className="wallet-img",o.alt="",o.width=28,o.height=28;let i=0;return o.addEventListener("error",()=>{i+=1,i<r.length?o.src=r[i]:o.remove()}),o.src=r[i],t.appendChild(o),t}function Wt(e){if(e.icon!==void 0)return[e.icon];let t;try{t=new URL(e.url).origin}catch{return[]}return[`${t}/favicon.svg`,`${t}/favicon.ico`,`${t}/favicon.png`]}import{assertX25519PublicJwk as Nt,CONNECT_DENIED_TOKEN as Lt,ConnectClient as Ot}from"@enbox/connect";var ye="/dweb-connect",te="enbox-connect-loaded",ne="enbox-connect-request",oe="enbox-connect-response";function ue(e,t,n){if(e.origin!==t||e.source!==n)return;let r=e.data;if(!(typeof r!="object"||r===null))return r}var Dt=3e5,Ut=500,At="enbox-dweb-connect",qt="width=500,height=700,menubar=no,toolbar=no,location=no,status=no";function It(){if(typeof window>"u")throw new Error("[@enbox/browser] DWeb Connect is only available in browser environments.")}var $=class extends Error{constructor(){super("[@enbox/browser] Wallet popup was closed before the wallet finished loading."),this.name="PopupWindowClosedError"}},K=class{constructor(t){this.requiresPin=!1;this._settled=!1;this._walletEpkReceived=!1;It(),this._walletOrigin=new URL(t.walletUrl).origin,this._timeoutMs=t.timeoutMs??Dt;let n=new URL(ye,t.walletUrl).toString(),r=window.open(n,At,qt);if(!r)throw new Error("[@enbox/browser] Popup blocked. Allow popups for this site to connect to a wallet.");this._popup=r,this._walletEpkPromise=new Promise((o,i)=>{this._resolveWalletEpk=o,this._rejectWalletEpk=i}),this._responsePromise=new Promise((o,i)=>{this._resolveResponse=o,this._rejectResponse=i}),this._responsePromise.catch(()=>{}),this._messageListener=o=>{this.onMessage(o)},window.addEventListener("message",this._messageListener),this._timeoutId=setTimeout(()=>{this.fail(new Error("[@enbox/browser] DWeb Connect timed out waiting for wallet response."))},this._timeoutMs),this._closedPollId=setInterval(()=>{this.onClosedPoll()},Ut)}async requestProfile(t){return{encryption:{mode:"ecdh-es",walletEpk:await this._walletEpkPromise,walletOrigin:this._walletOrigin},reply:{mode:"post_message"},state:t}}async deliverRequest(t){this._popup.postMessage({type:ne,jwe:t},this._walletOrigin)}async awaitResponse(){return await this._responsePromise}onMessage(t){let n=ue(t,this._walletOrigin,this._popup);if(n!==void 0){if(n.type===te){this.onLoadedBeacon(n);return}n.type===oe&&this.onResponseMessage(n)}}onLoadedBeacon(t){if(this._settled||this._walletEpkReceived)return;let n;try{Nt(t.walletEpk),n=t.walletEpk}catch{this.fail(new Error("[@enbox/browser] Wallet loaded beacon did not carry a valid X25519 public key."));return}if(t.walletOrigin!==this._walletOrigin){this.fail(new Error("[@enbox/browser] Wallet loaded beacon origin does not match the configured wallet origin."));return}this._walletEpkReceived=!0,this._resolveWalletEpk?.(n)}onResponseMessage(t){if(!this._settled){if(typeof t.payload!="string"){this.fail(new Error("[@enbox/browser] Wallet response message did not carry a ciphertext payload."));return}this._settled=!0,this.cleanup(),this._rejectWalletEpk?.(new Error("[@enbox/browser] Wallet responded before the handshake was established.")),this._resolveResponse?.(t.payload)}}onClosedPoll(){if(!(this._settled||this._popup.closed!==!0)){if(!this._walletEpkReceived){this.fail(new $);return}this._settled=!0,this.cleanup(),this._resolveResponse?.(Lt)}}fail(t){if(!this._settled){this._settled=!0,this.cleanup();try{this._popup.close()}catch{}this._rejectWalletEpk?.(t),this._rejectResponse?.(t)}}cleanup(){clearTimeout(this._timeoutId),clearInterval(this._closedPollId),this._messageListener!==void 0&&(window.removeEventListener("message",this._messageListener),this._messageListener=void 0)}};function fe(){let e=Intl.DateTimeFormat().resolvedOptions(),t=Array.isArray(globalThis.navigator.languages)?globalThis.navigator.languages.filter(n=>typeof n=="string"&&n.length>0):void 0;return{origin:globalThis.location.origin,userAgent:globalThis.navigator.userAgent,platform:globalThis.navigator.platform,language:globalThis.navigator.language,...t&&t.length>0?{languages:t}:{},...e.timeZone?{timezone:e.timeZone}:{}}}async function $t(e){let t=new K({walletUrl:e.walletUrl,timeoutMs:e.timeout}),n=new Ot({transport:t});try{return await n.connect({appName:e.appName??globalThis.location.host,appIcon:e.appIcon,clientMetadata:fe(),permissionRequests:e.permissionRequests})}catch(r){if(r instanceof $)return;throw r}}var tt=[-1,10,16,26,18,24,16,18,22,22,26],nt=[-1,1,1,1,2,2,4,4,4,5,5],ot=[-1,26,44,70,100,134,172,196,242,292,346],Bt=0,Ze=10;function et(e){return ot[e]-tt[e]*nt[e]}function Re(e,t){let n=new TextEncoder().encode(e),r=0;for(let u=1;u<=Ze;u++){let f=et(u)*8;if(4+(u<=9?8:16)+n.length*8<=f){r=u;break}}if(r===0)throw new Error(`[@enbox/browser] QR payload too long (${n.length} bytes exceeds version ${Ze}-M capacity).`);let o=[],i=(u,f)=>{for(let R=f-1;R>=0;R--)o.push(u>>>R&1)};i(4,4),i(n.length,r<=9?8:16);for(let u of n)i(u,8);let a=et(r)*8;i(0,Math.min(4,a-o.length)),i(0,(8-o.length%8)%8);let s=[236,17];for(let u=0;o.length<a;u++)i(s[u%2],8);let l=new Uint8Array(a/8);for(let u=0;u<o.length;u++)l[u>>3]|=o[u]<<7-(u&7);let d=jt(l,r),p=17+4*r,h=Array.from({length:p},()=>new Array(p).fill(!1)),P=Array.from({length:p},()=>new Array(p).fill(!1));Gt(h,P,r),Jt(h,P,d);let E=t??-1;if(E===-1){let u=1/0;for(let f=0;f<8;f++){xe(h,P,f),Pe(h,P,f);let R=Qt(h);R<u&&(u=R,E=f),xe(h,P,f)}}return xe(h,P,E),Pe(h,P,E),{size:p,modules:h,version:r,mask:E}}function jt(e,t){let n=nt[t],r=tt[t],o=ot[t],i=n-o%n,a=Math.floor(o/n),s=[],l=[],d=Ht(r),p=0;for(let u=0;u<n;u++){let f=a-r+(u<i?0:1),R=e.slice(p,p+f);p+=f,s.push(R),l.push(zt(R,d))}let h=new Uint8Array(o),P=0,E=a-r+1;for(let u=0;u<E;u++)for(let f=0;f<n;f++)u<s[f].length&&(h[P++]=s[f][u]);for(let u=0;u<r;u++)for(let f=0;f<n;f++)h[P++]=l[f][u];return h}function _e(e,t){let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return n&255}function Ht(e){let t=new Uint8Array(e);t[e-1]=1;let n=1;for(let r=0;r<e;r++){for(let o=0;o<e;o++)t[o]=_e(t[o],n),o+1<e&&(t[o]^=t[o+1]);n=_e(n,2)}return t}function zt(e,t){let n=new Uint8Array(t.length);for(let r of e){let o=r^n[0];n.copyWithin(0,1),n[n.length-1]=0;for(let i=0;i<t.length;i++)n[i]^=_e(t[i],o)}return n}var Kt=[[],[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50]];function T(e,t,n,r,o){e[r][n]=o,t[r][n]=!0}function Gt(e,t,n){let r=e.length;for(let i=0;i<r;i++)T(e,t,6,i,i%2===0),T(e,t,i,6,i%2===0);Ee(e,t,3,3),Ee(e,t,r-4,3),Ee(e,t,3,r-4);let o=Kt[n];for(let i=0;i<o.length;i++)for(let a=0;a<o.length;a++)i===0&&a===0||i===0&&a===o.length-1||i===o.length-1&&a===0||Yt(e,t,o[i],o[a]);Pe(e,t,0),T(e,t,8,r-8,!0),n>=7&&Ft(e,t,n)}function Ee(e,t,n,r){let o=e.length;for(let i=-4;i<=4;i++)for(let a=-4;a<=4;a++){let s=n+a,l=r+i;if(s<0||s>=o||l<0||l>=o)continue;let d=Math.max(Math.abs(a),Math.abs(i));T(e,t,s,l,d!==2&&d!==4)}}function Yt(e,t,n,r){for(let o=-2;o<=2;o++)for(let i=-2;i<=2;i++)T(e,t,n+i,r+o,Math.max(Math.abs(i),Math.abs(o))!==1)}function Pe(e,t,n){let r=e.length,o=Bt<<3|n,i=o;for(let s=0;s<10;s++)i=i<<1^(i>>>9)*1335;let a=(o<<10|i)^21522;for(let s=0;s<=5;s++)T(e,t,8,s,(a>>>s&1)!==0);T(e,t,8,7,(a>>>6&1)!==0),T(e,t,8,8,(a>>>7&1)!==0),T(e,t,7,8,(a>>>8&1)!==0);for(let s=9;s<15;s++)T(e,t,14-s,8,(a>>>s&1)!==0);for(let s=0;s<8;s++)T(e,t,r-1-s,8,(a>>>s&1)!==0);for(let s=8;s<15;s++)T(e,t,8,r-15+s,(a>>>s&1)!==0)}function Ft(e,t,n){let r=e.length,o=n;for(let a=0;a<12;a++)o=o<<1^(o>>>11)*7973;let i=n<<12|o;for(let a=0;a<18;a++){let s=(i>>>a&1)!==0,l=r-11+a%3,d=Math.floor(a/3);T(e,t,l,d,s),T(e,t,d,l,s)}}function Jt(e,t,n){let r=e.length,o=0;for(let i=r-1;i>=1;i-=2){i===6&&(i=5);for(let a=0;a<r;a++)for(let s=0;s<2;s++){let l=i-s,p=(i+1&2)===0?r-1-a:a;!t[p][l]&&o<n.length*8&&(e[p][l]=(n[o>>3]>>>7-(o&7)&1)!==0,o++)}}}function xe(e,t,n){let r=e.length;for(let o=0;o<r;o++)for(let i=0;i<r;i++){if(t[o][i])continue;let a;switch(n){case 0:a=(i+o)%2===0;break;case 1:a=o%2===0;break;case 2:a=i%3===0;break;case 3:a=(i+o)%3===0;break;case 4:a=(Math.floor(i/3)+Math.floor(o/2))%2===0;break;case 5:a=i*o%2+i*o%3===0;break;case 6:a=(i*o%2+i*o%3)%2===0;break;default:a=((i+o)%2+i*o%3)%2===0;break}a&&(e[o][i]=!e[o][i])}}function Qt(e){let t=e.length,n=0;for(let s=0;s<t;s++){let l=!1,d=0;for(let p=0;p<t;p++)p===0||e[s][p]!==l?(l=e[s][p],d=1):(d++,d===5?n+=3:d>5&&(n+=1))}for(let s=0;s<t;s++){let l=!1,d=0;for(let p=0;p<t;p++)p===0||e[p][s]!==l?(l=e[p][s],d=1):(d++,d===5?n+=3:d>5&&(n+=1))}for(let s=0;s<t-1;s++)for(let l=0;l<t-1;l++){let d=e[s][l];d===e[s][l+1]&&d===e[s+1][l]&&d===e[s+1][l+1]&&(n+=3)}let r=(s,l)=>{if(![!0,!1,!0,!0,!0,!1,!0].every((E,u)=>s[l+u]===E))return 0;let h=l>=4&&s.slice(l-4,l).every(E=>!E),P=l+11<=s.length&&s.slice(l+7,l+11).every(E=>!E);return(h?40:0)+(P?40:0)};for(let s=0;s<t;s++){let l=e[s],d=e.map(p=>p[s]);for(let p=0;p+7<=t;p++)n+=r(l,p),n+=r(d,p)}let o=0;for(let s of e)for(let l of s)l&&o++;let i=t*t,a=Math.ceil(Math.abs(o*20-i*10)/i)-1;return n+=a*10,n}var Ce="http://www.w3.org/2000/svg";function ke(e,t={}){let n=t.dark??"#000000",r=t.light??"#ffffff",o=t.quietZone??2,i=e.size+o*2,a="";for(let p=0;p<e.size;p++)for(let h=0;h<e.size;h++)e.modules[p][h]&&(a+=`M${h+o} ${p+o}h1v1h-1z`);let s=document.createElementNS(Ce,"svg");s.setAttribute("viewBox",`0 0 ${i} ${i}`),s.setAttribute("shape-rendering","crispEdges"),s.setAttribute("role","img");let l=document.createElementNS(Ce,"rect");l.setAttribute("width",String(i)),l.setAttribute("height",String(i)),l.setAttribute("fill",r),s.appendChild(l);let d=document.createElementNS(Ce,"path");return d.setAttribute("d",a),d.setAttribute("fill",n),s.appendChild(d),s}var rt="/.well-known/enbox-connect";async function me(e){try{let t=new URL(rt,e).toString(),n=await fetch(t,{signal:AbortSignal.timeout(6e3)});if(!n.ok)return;let r=await n.json();return typeof r?.connectServerUrl!="string"?void 0:{connectServerUrl:r.connectServerUrl}}catch{return}}async function Me(e){return await me(e)!==void 0}import{DidJwk as Xt}from"@enbox/dids";import{X25519 as Vt}from"@enbox/crypto";import{CONNECT_DENIED_TOKEN as Zt,openResponse as en,randomToken as it,RelayClientTransport as tn,sealRequest as nn}from"@enbox/connect";var Te=6,G=class extends Error{constructor(){super("[@enbox/browser] Relay connect cancelled."),this.name="RelayConnectCancelledError"}};async function Se(e){let n=(e.createTransport??(f=>new tn(f)))({connectServerUrl:e.connectServerUrl,walletUri:e.walletUri,timeoutMs:e.timeoutMs,pollIntervalMs:e.pollIntervalMs,onClaimed:e.onClaimed}),r=await Xt.create(),o=await Vt.generateKey(),i={kty:"OKP",crv:"X25519",x:o.x},a=it(),s=it(),l=await n.requestProfile(s),d={clientDid:r.uri,appName:e.appName,appIcon:e.appIcon,clientMetadata:e.clientMetadata,permissionRequests:e.permissionRequests,supportedDidMethods:["did:dht","did:jwk"],nonce:a,state:s,responseKey:i,reply:l.reply},p=await nn({request:d,signer:r,encryption:l.encryption}),h=await n.deliverRequest(p);h!==void 0&&e.onWalletUriReady(h);let E=await(e.cancelled===void 0?n.awaitResponse():Promise.race([n.awaitResponse(),e.cancelled]));if(E===Zt)return;let u;for(let f=1;f<=Te;f++){let R=await(e.cancelled===void 0?e.requestPin(f,u):Promise.race([e.requestPin(f,u),e.cancelled]));try{let k=await en({jwe:E,recipientPrivateKey:o,expected:{clientDid:r.uri,nonce:a,state:s},pin:R});if(k.delegatePortableDid===void 0)throw new Error("Connect: wallet response omitted `delegatePortableDid`.");return{delegatePortableDid:k.delegatePortableDid,delegateGrants:k.delegateGrants,connectedDid:k.providerDid,sessionRevocations:k.sessionRevocations}}catch(k){let S=k instanceof Error?k:new Error(String(k));if(S.message.startsWith("Connect:"))throw S;u=S}}throw new Error(`[@enbox/browser] The pairing code did not match after ${Te} attempts.`)}var st="enbox:connect:lastChoice",rn=3e4,sn=1e4,he=4;async function at(e){return(await me(e))?.connectServerUrl}async function an(e){let t=new K({walletUrl:e.walletUrl,timeoutMs:e.timeoutMs});return await new on({transport:t}).connect({appName:e.appName,appIcon:e.appIcon,clientMetadata:fe(),permissionRequests:e.permissionRequests})}function ln(){return typeof window>"u"?!1:(window.matchMedia?.("(pointer: coarse)").matches??!1)&&Math.min(window.innerWidth,window.innerHeight)<900}function cn(){return{runRelay:Se,runPopup:an,discoverConnectServerUrl:at,validateWalletUrl:Me,isMobile:ln,storage:typeof localStorage>"u"?void 0:localStorage}}function dn(e){try{let t=e?.getItem(st);if(t==null)return;let n=JSON.parse(t);if((n.method==="phone"||n.method==="browser")&&typeof n.walletUrl=="string")return{method:n.method,walletUrl:n.walletUrl}}catch{}}function pn(e,t){try{e?.setItem(st,JSON.stringify(t))}catch{}}function un(){let e,t={active:!0},n=new Promise((r,o)=>{e=()=>{t.active===!0&&(t.active=!1,o(new G))}});return n.catch(()=>{}),t.cancelled=n,t.cancel=e,t}function Ne(e){if(typeof window>"u"||typeof document>"u")throw new Error("[@enbox/browser] The connect modal is only available in browser environments.");let t={...cn(),...e.deps},n=e.wallets??[],r=e.rememberChoice??!0,o=e.appName??window.location.host,i=e.relayWalletPath??"/connect/app",a=t.isMobile(),s=r?dn(t.storage):void 0,l=e.walletUrl!==void 0,d=e.walletUrl??(s!==void 0&&(l||fn(n,s.walletUrl))?s.walletUrl:void 0)??n[0]?.url,p=e.preferredMethod??s?.method??"phone";return new Promise((h,P)=>{let E=document.createElement("div");E.id="enbox-connect-modal";let u=E.attachShadow({mode:"open"}),f=window.matchMedia?.("(prefers-color-scheme: dark)").matches??!1,R=document.createElement("style");R.textContent=gn(f),u.appendChild(R);let k=document.createElement("div");k.className="overlay";let S=document.createElement("div");S.className="modal",S.setAttribute("role","dialog"),S.setAttribute("aria-modal","true"),S.setAttribute("aria-label",`Connect to ${o}`);let O=!1,Y,D,ge=!1,F,Oe=new Map,ct=()=>{Y?.cancel(),clearTimeout(D),document.removeEventListener("keydown",Be);try{document.body.removeChild(E)}catch{}},ie=c=>{O||(O=!0,ct(),c())},De=c=>{r&&pn(t.storage,{method:p,walletUrl:d??""}),ft(),setTimeout(()=>ie(()=>h(c)),1200)},we=()=>ie(()=>P(new Error("[@enbox/browser] Connect cancelled.")));S.appendChild(mn(o,e.appIcon,we));let A=document.createElement("div");A.className="stage",A.setAttribute("aria-live","polite"),S.appendChild(A);let B=document.createElement("div");B.className="footer",S.appendChild(B);let W=(...c)=>{A.replaceChildren(...c),A.classList.remove("fade-in"),A.offsetWidth,A.classList.add("fade-in")},Ue=c=>{W(y("div","spinner"),y("p","stage-caption",c))},dt=c=>{if(a){let w=document.createElement("a");w.className="deep-link",w.href=c.walletUri,w.textContent="Continue in your wallet",W(w,y("p","stage-caption","Your wallet opens to approve this connection."),y("p","stage-subline","Come back here when you\u2019re done."));return}let m=document.createElement("div");m.className="qr-box",m.replaceChildren(ke(Re(c.walletUri),{dark:f?"#e8e8f0":"#14141f",light:"transparent",quietZone:2})),W(m,y("p","stage-caption","Scan with your phone\u2019s camera"),y("p","stage-subline","Your wallet stays on your phone, so you can approve things anywhere."))},pt=()=>{let c=document.createElement("div");c.className="claimed-pulse",W(c,y("p","stage-caption","Phone connected \u2014 finish there"),y("p","stage-subline","Approve the request on your phone, then come back here."))},ut=(c,m)=>new Promise(w=>{F=w;let b=document.createElement("div");b.className="pin-row",m!==void 0&&b.classList.add("shake");let x=[];for(let C=0;C<he;C++){let g=document.createElement("input");g.className="pin-input",g.type="text",g.inputMode="numeric",g.maxLength=1,g.setAttribute("aria-label",`Code digit ${C+1}`),x.push(g),b.appendChild(g)}let L=()=>{let C=x.map(g=>g.value).join("");if(C.length===he&&F!==void 0){let g=F;F=void 0,Ue("Checking the code\u2026"),g(C)}};x.forEach((C,g)=>{C.addEventListener("input",()=>{C.value=C.value.replace(/\D/g,"").slice(0,1),C.value!==""&&g+1<x.length&&x[g+1].focus(),L()}),C.addEventListener("keydown",M=>{M.key==="Backspace"&&C.value===""&&g>0&&x[g-1].focus()}),C.addEventListener("paste",M=>{let N=(M.clipboardData?.getData("text")??"").replace(/\D/g,"").slice(0,he);N.length!==0&&(M.preventDefault(),N.split("").forEach((J,Q)=>{x[Q]!==void 0&&(x[Q].value=J)}),x[Math.min(N.length,he)-1]?.focus(),L())})}),W(y("p","stage-caption","Enter the code shown on your phone"),b,...m!==void 0?[y("p","stage-error","That code doesn\u2019t match \u2014 check your phone.")]:[y("p","stage-subline",c===1?"Phone connected.":"")]),x[0].focus()}),ft=()=>{let c=y("div","check");c.textContent="\u2713",W(c,y("p","stage-caption","You\u2019re connected."))},Ae=()=>{W(y("p","stage-caption","No problem \u2014 nothing was shared."),re("Start over",()=>{j()}),We("Close",()=>ie(()=>h(void 0))))},se=(c,m)=>{W(y("p","stage-caption",c),re("Start over",()=>{j()}),We("Close",()=>ie(()=>P(m??new Error(`[@enbox/browser] ${c}`)))))},mt=()=>{W(y("p","stage-caption","This wallet can\u2019t connect by phone here."),y("p","stage-subline","You can continue in this browser instead."),re("Use this browser",()=>{ae()}))},ht=()=>{W(y("p","stage-caption","Connect with a wallet in this browser"),y("p","stage-subline","Your wallet opens in a small window to approve this connection."),re("Open wallet window",()=>{ae()}))},gt=()=>{W(y("div","spinner"),y("p","stage-caption","Finish in the wallet window"),y("p","stage-subline","We\u2019ll wrap up here as soon as you\u2019re done."))},qe=c=>{W(y("p","stage-caption",c?"Your browser blocked the wallet window.":"The wallet window was closed."),re(c?"Open it now":"Reopen window",()=>{ae()}),...a?[]:[We("Use your phone instead",()=>{$e("phone")})])},wt=async c=>{if(e.connectServerUrl!==void 0)return e.connectServerUrl;let m=Oe.get(c);return m===void 0&&(m=t.discoverConnectServerUrl(c),Oe.set(c,m)),m},bt=c=>{clearTimeout(D);let m=Math.max(sn,c*1e3-rn);D=setTimeout(()=>{!O&&F===void 0&&p==="phone"&&Ie()},m)},Ie=async()=>{if(Y?.cancel(),clearTimeout(D),d===void 0){se("No wallet is configured.");return}p="phone",H(),Ue("Getting things ready\u2026");let c=new URL(d).origin,m=await wt(c);if(m===void 0){mt();return}let w=un();Y=w;try{let b=await t.runRelay({connectServerUrl:m,walletUri:new URL(i,c).toString(),appName:o,appIcon:e.appIcon,clientMetadata:fe(),permissionRequests:e.permissionRequests,timeoutMs:e.timeout,cancelled:w.cancelled,onWalletUriReady:x=>{w.active&&!O&&(dt(x),bt(x.expiresIn))},onClaimed:()=>{w.active&&!O&&(clearTimeout(D),pt())},requestPin:(x,L)=>(clearTimeout(D),ut(x,L))});if(!w.active||O)return;b===void 0?Ae():De(b)}catch(b){if(!w.active||O||b instanceof G)return;let x=b instanceof Error?b:new Error(String(b));se(/timed out/i.test(x.message)?"That took too long, so we stopped for safety.":"Something went wrong while connecting.",x)}},ae=()=>{if(Y?.cancel(),clearTimeout(D),d===void 0){se("No wallet is configured.");return}if(ge)return;p="browser",H();let c;try{c=t.runPopup({walletUrl:d,permissionRequests:e.permissionRequests,appName:o,appIcon:e.appIcon,timeoutMs:e.timeout})}catch(m){let w=m instanceof Error&&/popup blocked/i.test(m.message);qe(w);return}ge=!0,gt(),c.then(m=>{O||(m===void 0?Ae():De(m))}).catch(m=>{if(O)return;if(m instanceof $){qe(!1);return}let w=m instanceof Error?m:new Error(String(m));se(/timed out/i.test(w.message)?"That took too long, so we stopped for safety.":"Something went wrong while connecting.",w)}).finally(()=>{ge=!1})},j=async()=>{p==="browser"?(Y?.cancel(),clearTimeout(D),H(),ht()):await Ie()},$e=async c=>{p=c,await j()},H=()=>{if(B.replaceChildren(),p==="phone"){let c=document.createElement("button");c.className="footer-link method-link",c.textContent="No phone handy? Use this browser \u2192",c.addEventListener("click",()=>{ae()}),B.appendChild(c)}else if(!a){let c=document.createElement("button");c.className="footer-link method-link",c.textContent="Use your phone instead \u2192",c.addEventListener("click",()=>{$e("phone")}),B.appendChild(c)}!l&&n.length>0&&B.appendChild(vt())},vt=()=>{let c=document.createElement("div");c.className="wallet-switcher";let m=n.find(v=>v.url===d),w=document.createElement("button");w.className="footer-link wallet-toggle",w.setAttribute("aria-expanded","false"),w.textContent=`Wallet: ${m?.name??d??"Choose"} \u25BE`;let b=document.createElement("div");b.className="wallet-panel",b.hidden=!0;let x=[],L=document.createElement("div");if(L.className="wallet-empty",L.textContent="No wallets match your search.",L.hidden=!0,n.length>5){let v=document.createElement("input");v.type="search",v.className="wallet-search",v.placeholder="Search wallets\u2026",v.addEventListener("input",()=>{let _=v.value.trim().toLowerCase(),U=0;for(let{wallet:He,el:yt}of x){let ze=_===""||He.name.toLowerCase().includes(_)||He.url.toLowerCase().includes(_);yt.hidden=!ze,ze&&(U+=1)}L.hidden=U>0}),b.appendChild(v)}for(let v of n){let _=document.createElement("button");_.className="wallet-row",_.appendChild(Ve(v));let U=document.createElement("span");U.className="wallet-row-name",U.textContent=v.name,_.appendChild(U),v.url===d&&_.classList.add("selected"),_.addEventListener("click",()=>{d=v.url,H(),j()}),x.push({wallet:v,el:_}),b.appendChild(_)}b.appendChild(L);let C=document.createElement("div");C.className="wallet-custom";let g=document.createElement("input");g.className="url-input",g.type="url",g.placeholder="https://your-wallet.example";let M=document.createElement("button");M.className="url-go",M.textContent="Use";let N=document.createElement("div");N.className="url-error",N.hidden=!0;let J=!1,Q=v=>{d=v,H(),j()},je=async()=>{let v=g.value.trim();if(v==="")return;let _;try{_=new URL(v.includes("://")?v:`https://${v}`).origin}catch{g.classList.add("invalid");return}if(J){Q(_);return}M.disabled=!0,M.textContent="Checking\u2026",N.hidden=!0;let U=await t.validateWalletUrl(_);if(M.disabled=!1,U){M.textContent="Use",Q(_);return}J=!0,M.textContent="Use anyway",g.classList.add("invalid"),N.textContent=`Couldn't verify a wallet at ${_}.`,N.hidden=!1};return g.addEventListener("input",()=>{J=!1,M.textContent="Use",g.classList.remove("invalid"),N.hidden=!0}),g.addEventListener("keydown",v=>{v.key==="Enter"&&je()}),M.addEventListener("click",()=>{je()}),C.appendChild(g),C.appendChild(M),b.appendChild(C),b.appendChild(N),w.addEventListener("click",()=>{b.hidden=!b.hidden,w.setAttribute("aria-expanded",b.hidden?"false":"true")}),c.appendChild(w),c.appendChild(b),c};k.addEventListener("click",c=>{c.target===k&&we()});let Be=c=>{if(c.key==="Escape"){we();return}c.key==="Tab"&&hn(u,c)};document.addEventListener("keydown",Be),k.appendChild(S),u.appendChild(k),document.body.appendChild(E),H(),j()})}function fn(e,t){return e.some(n=>n.url===t)}function y(e,t,n){let r=document.createElement(e);return r.className=t,n!==void 0&&(r.textContent=n),r}function re(e,t){let n=document.createElement("button");return n.className="stage-btn",n.textContent=e,n.addEventListener("click",t),n}function We(e,t){let n=document.createElement("button");return n.className="footer-link",n.textContent=e,n.addEventListener("click",t),n}function mn(e,t,n){let r=document.createElement("div");r.className="header";let o=document.createElement("div");if(o.className="header-identity",t!==void 0){let s=document.createElement("img");s.className="header-icon",s.src=t,s.alt="",s.width=24,s.height=24,s.addEventListener("error",()=>s.remove()),o.appendChild(s)}let i=document.createElement("h2");i.textContent=`Connect to ${e}`,o.appendChild(i);let a=document.createElement("button");return a.className="close-btn",a.setAttribute("aria-label","Close"),a.textContent="\xD7",a.addEventListener("click",n),r.appendChild(o),r.appendChild(a),r}function hn(e,t){let n=Array.from(e.querySelectorAll('button, input, a[href], [tabindex]:not([tabindex="-1"])')).filter(a=>!a.hasAttribute("disabled")&&a.offsetParent!==null);if(n.length===0)return;let r=n[0],o=n[n.length-1],i=e.activeElement;t.shiftKey&&(i===r||i===null)?(t.preventDefault(),o.focus()):!t.shiftKey&&i===o&&(t.preventDefault(),r.focus())}function gn(e){let t=e?"#1a1a2e":"#ffffff",n=e?"#e0e0e0":"#1a1a2e",r=e?"#888":"#666",o=e?"#333":"#e0e0e0",i=e?"#16213e":"#f8f9fa",a=e?"#4a9eff":"#0066cc",s=e?"rgba(74, 158, 255, 0.16)":"rgba(0, 102, 204, 0.1)",l=e?"#ff6b6b":"#c0392b";return`
154
+ `,H.lastElementChild.addEventListener("click",Pe),document.body.prepend(H),he=!0)}function zt(){he&&(te?.remove(),te=null,H?.remove(),H=null,he=!1)}function Pe(){document.documentElement.removeAttribute("drl-link-loading"),fe=null}var fe=null,ge=!1,ne=null,oe=null;function Kt(){ge||(ne=async e=>{let t=e.target?.closest("a");if(t){let n=t.href,r=ee(n);if(r){let o=r[0],i=r[1],s=t.target==="_blank";e.preventDefault();try{let a=null;s?(a=window.open("","_blank"),a&&a.document.write(Ht)):(fe=i,setTimeout(()=>document.documentElement.setAttribute("drl-link-loading",""),50));let d=await at(o);if(!d.length)throw new Error("no valid DWN endpoints found");let p=`${d[0].replace(me,"")}/${o}/${i}`;s?a&&!a.closed&&(a.location.href=p):fe===i&&(window.location.href=p)}catch{throw fe===i&&Pe(),new Error(`DID endpoint resolution failed for the DRL: ${n}`)}}}},oe=async e=>{let t=e.composedPath()[0];if(e.pointerType==="mouse"&&e.button===2||e.pointerType==="touch"&&e.isPrimary){if(G(),t?.src&&ee(t.src)){z=t,t.__src__=t.src;let n=t.src.replace(rt,"https:").replace(me,""),o=await(await st())?.match(n);if(o){let i=o.headers.get("dwn-composed-url");i&&(t.src=i)}t.addEventListener("pointerup",G,{once:!0})}}else t===z&&G()},document.addEventListener("click",ne),document.addEventListener("pointercancel",G),document.addEventListener("pointerdown",oe),ge=!0)}function $t(){ge&&(ne&&(document.removeEventListener("click",ne),ne=null),oe&&(document.removeEventListener("pointerdown",oe),oe=null),document.removeEventListener("pointercancel",G),G(),Pe(),ge=!1)}var z=null;async function G(e){e?.type==="pointerup"&&await new Promise(t=>requestAnimationFrame(()=>t())),z&&(z.src=z.__src__,delete z.__src__,z=null)}function Kn(e={}){e.didResolvers&&(ke=new ot({didResolvers:e.didResolvers})),e.serviceWorker!==!1&&jt(e),typeof window<"u"&&typeof window.document<"u"&&(e.injectStyles!==!1&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",nt,{once:!0}):nt()),e.links!==!1&&Kt())}function $n(){typeof window<"u"&&typeof window.document<"u"&&($t(),zt())}async function Gn(){return typeof caches>"u"?!1:caches.delete(it)}import{ConnectClient as bn}from"@enbox/connect";function re(e){let t=document.createElement("span");t.className="wallet-icon";let n=document.createElement("span");n.className="wallet-badge",n.textContent=e.name.charAt(0).toUpperCase(),t.appendChild(n);let r=Gt(e);if(r.length===0)return t;let o=document.createElement("img");o.className="wallet-img",o.alt="",o.width=28,o.height=28;let i=0;return o.addEventListener("error",()=>{i+=1,i<r.length?o.src=r[i]:o.remove()}),o.src=r[i],t.appendChild(o),t}function Gt(e){if(e.icon!==void 0)return[e.icon];let t;try{t=new URL(e.url).origin}catch{return[]}return[`${t}/favicon.svg`,`${t}/favicon.ico`,`${t}/favicon.png`]}import{assertX25519PublicJwk as Yt,CONNECT_DENIED_TOKEN as Ft,ConnectClient as Jt}from"@enbox/connect";var Re="/dweb-connect",ie="enbox-connect-loaded",ae="enbox-connect-request",se="enbox-connect-response";function we(e,t,n){if(e.origin!==t||e.source!==n)return;let r=e.data;if(!(typeof r!="object"||r===null))return r}var Qt=3e5,Xt=500,Vt="enbox-dweb-connect",Zt="width=500,height=700,menubar=no,toolbar=no,location=no,status=no";function en(){if(typeof window>"u")throw new Error("[@enbox/browser] DWeb Connect is only available in browser environments.")}var K=class extends Error{constructor(){super("[@enbox/browser] Wallet popup was closed before the wallet finished loading."),this.name="PopupWindowClosedError"}},Y=class{constructor(t){this.requiresPin=!1;this._settled=!1;this._walletEpkReceived=!1;en(),this._walletOrigin=new URL(t.walletUrl).origin,this._timeoutMs=t.timeoutMs??Qt;let n=new URL(Re,t.walletUrl).toString(),r=window.open(n,Vt,Zt);if(!r)throw new Error("[@enbox/browser] Popup blocked. Allow popups for this site to connect to a wallet.");this._popup=r,this._walletEpkPromise=new Promise((o,i)=>{this._resolveWalletEpk=o,this._rejectWalletEpk=i}),this._responsePromise=new Promise((o,i)=>{this._resolveResponse=o,this._rejectResponse=i}),this._responsePromise.catch(()=>{}),this._messageListener=o=>{this.onMessage(o)},window.addEventListener("message",this._messageListener),this._timeoutId=setTimeout(()=>{this.fail(new Error("[@enbox/browser] DWeb Connect timed out waiting for wallet response."))},this._timeoutMs),this._closedPollId=setInterval(()=>{this.onClosedPoll()},Xt)}async requestProfile(t){return{encryption:{mode:"ecdh-es",walletEpk:await this._walletEpkPromise,walletOrigin:this._walletOrigin},reply:{mode:"post_message"},state:t}}async deliverRequest(t){this._popup.postMessage({type:ae,jwe:t},this._walletOrigin)}async awaitResponse(){return await this._responsePromise}onMessage(t){let n=we(t,this._walletOrigin,this._popup);if(n!==void 0){if(n.type===ie){this.onLoadedBeacon(n);return}n.type===se&&this.onResponseMessage(n)}}onLoadedBeacon(t){if(this._settled||this._walletEpkReceived)return;let n;try{Yt(t.walletEpk),n=t.walletEpk}catch{this.fail(new Error("[@enbox/browser] Wallet loaded beacon did not carry a valid X25519 public key."));return}if(t.walletOrigin!==this._walletOrigin){this.fail(new Error("[@enbox/browser] Wallet loaded beacon origin does not match the configured wallet origin."));return}this._walletEpkReceived=!0,this._resolveWalletEpk?.(n)}onResponseMessage(t){if(!this._settled){if(typeof t.payload!="string"){this.fail(new Error("[@enbox/browser] Wallet response message did not carry a ciphertext payload."));return}this._settled=!0,this.cleanup(),this._rejectWalletEpk?.(new Error("[@enbox/browser] Wallet responded before the handshake was established.")),this._resolveResponse?.(t.payload)}}onClosedPoll(){if(!(this._settled||this._popup.closed!==!0)){if(!this._walletEpkReceived){this.fail(new K);return}this._settled=!0,this.cleanup(),this._resolveResponse?.(Ft)}}fail(t){if(!this._settled){this._settled=!0,this.cleanup();try{this._popup.close()}catch{}this._rejectWalletEpk?.(t),this._rejectResponse?.(t)}}cleanup(){clearTimeout(this._timeoutId),clearInterval(this._closedPollId),this._messageListener!==void 0&&(window.removeEventListener("message",this._messageListener),this._messageListener=void 0)}};function ve(){let e=Intl.DateTimeFormat().resolvedOptions(),t=Array.isArray(globalThis.navigator.languages)?globalThis.navigator.languages.filter(n=>typeof n=="string"&&n.length>0):void 0;return{origin:globalThis.location.origin,userAgent:globalThis.navigator.userAgent,platform:globalThis.navigator.platform,language:globalThis.navigator.language,...t&&t.length>0?{languages:t}:{},...e.timeZone?{timezone:e.timeZone}:{}}}async function tn(e){let t=new Y({walletUrl:e.walletUrl,timeoutMs:e.timeout}),n=new Jt({transport:t});try{return await n.connect({appName:e.appName??globalThis.location.host,appIcon:e.appIcon,clientMetadata:ve(),permissionRequests:e.permissionRequests})}catch(r){if(r instanceof K)return;throw r}}var pt=[-1,10,16,26,18,24,16,18,22,22,26],ut=[-1,1,1,1,2,2,4,4,4,5,5],ft=[-1,26,44,70,100,134,172,196,242,292,346],nn=0,ct=10;function dt(e){return ft[e]-pt[e]*ut[e]}function Ne(e,t){let n=new TextEncoder().encode(e),r=0;for(let f=1;f<=ct;f++){let m=dt(f)*8;if(4+(f<=9?8:16)+n.length*8<=m){r=f;break}}if(r===0)throw new Error(`[@enbox/browser] QR payload too long (${n.length} bytes exceeds version ${ct}-M capacity).`);let o=[],i=(f,m)=>{for(let P=m-1;P>=0;P--)o.push(f>>>P&1)};i(4,4),i(n.length,r<=9?8:16);for(let f of n)i(f,8);let s=dt(r)*8;i(0,Math.min(4,s-o.length)),i(0,(8-o.length%8)%8);let a=[236,17];for(let f=0;o.length<s;f++)i(a[f%2],8);let d=new Uint8Array(s/8);for(let f=0;f<o.length;f++)d[f>>3]|=o[f]<<7-(f&7);let p=on(d,r),u=17+4*r,v=Array.from({length:u},()=>new Array(u).fill(!1)),R=Array.from({length:u},()=>new Array(u).fill(!1));ln(v,R,r),pn(v,R,p);let E=t??-1;if(E===-1){let f=1/0;for(let m=0;m<8;m++){Te(v,R,m),Le(v,R,m);let P=un(v);P<f&&(f=P,E=m),Te(v,R,m)}}return Te(v,R,E),Le(v,R,E),{size:u,modules:v,version:r,mask:E}}function on(e,t){let n=ut[t],r=pt[t],o=ft[t],i=n-o%n,s=Math.floor(o/n),a=[],d=[],p=rn(r),u=0;for(let f=0;f<n;f++){let m=s-r+(f<i?0:1),P=e.slice(u,u+m);u+=m,a.push(P),d.push(an(P,p))}let v=new Uint8Array(o),R=0,E=s-r+1;for(let f=0;f<E;f++)for(let m=0;m<n;m++)f<a[m].length&&(v[R++]=a[m][f]);for(let f=0;f<r;f++)for(let m=0;m<n;m++)v[R++]=d[m][f];return v}function We(e,t){let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return n&255}function rn(e){let t=new Uint8Array(e);t[e-1]=1;let n=1;for(let r=0;r<e;r++){for(let o=0;o<e;o++)t[o]=We(t[o],n),o+1<e&&(t[o]^=t[o+1]);n=We(n,2)}return t}function an(e,t){let n=new Uint8Array(t.length);for(let r of e){let o=r^n[0];n.copyWithin(0,1),n[n.length-1]=0;for(let i=0;i<t.length;i++)n[i]^=We(t[i],o)}return n}var sn=[[],[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50]];function M(e,t,n,r,o){e[r][n]=o,t[r][n]=!0}function ln(e,t,n){let r=e.length;for(let i=0;i<r;i++)M(e,t,6,i,i%2===0),M(e,t,i,6,i%2===0);Me(e,t,3,3),Me(e,t,r-4,3),Me(e,t,3,r-4);let o=sn[n];for(let i=0;i<o.length;i++)for(let s=0;s<o.length;s++)i===0&&s===0||i===0&&s===o.length-1||i===o.length-1&&s===0||cn(e,t,o[i],o[s]);Le(e,t,0),M(e,t,8,r-8,!0),n>=7&&dn(e,t,n)}function Me(e,t,n,r){let o=e.length;for(let i=-4;i<=4;i++)for(let s=-4;s<=4;s++){let a=n+s,d=r+i;if(a<0||a>=o||d<0||d>=o)continue;let p=Math.max(Math.abs(s),Math.abs(i));M(e,t,a,d,p!==2&&p!==4)}}function cn(e,t,n,r){for(let o=-2;o<=2;o++)for(let i=-2;i<=2;i++)M(e,t,n+i,r+o,Math.max(Math.abs(i),Math.abs(o))!==1)}function Le(e,t,n){let r=e.length,o=nn<<3|n,i=o;for(let a=0;a<10;a++)i=i<<1^(i>>>9)*1335;let s=(o<<10|i)^21522;for(let a=0;a<=5;a++)M(e,t,8,a,(s>>>a&1)!==0);M(e,t,8,7,(s>>>6&1)!==0),M(e,t,8,8,(s>>>7&1)!==0),M(e,t,7,8,(s>>>8&1)!==0);for(let a=9;a<15;a++)M(e,t,14-a,8,(s>>>a&1)!==0);for(let a=0;a<8;a++)M(e,t,r-1-a,8,(s>>>a&1)!==0);for(let a=8;a<15;a++)M(e,t,8,r-15+a,(s>>>a&1)!==0)}function dn(e,t,n){let r=e.length,o=n;for(let s=0;s<12;s++)o=o<<1^(o>>>11)*7973;let i=n<<12|o;for(let s=0;s<18;s++){let a=(i>>>s&1)!==0,d=r-11+s%3,p=Math.floor(s/3);M(e,t,d,p,a),M(e,t,p,d,a)}}function pn(e,t,n){let r=e.length,o=0;for(let i=r-1;i>=1;i-=2){i===6&&(i=5);for(let s=0;s<r;s++)for(let a=0;a<2;a++){let d=i-a,u=(i+1&2)===0?r-1-s:s;!t[u][d]&&o<n.length*8&&(e[u][d]=(n[o>>3]>>>7-(o&7)&1)!==0,o++)}}}function Te(e,t,n){let r=e.length;for(let o=0;o<r;o++)for(let i=0;i<r;i++){if(t[o][i])continue;let s;switch(n){case 0:s=(i+o)%2===0;break;case 1:s=o%2===0;break;case 2:s=i%3===0;break;case 3:s=(i+o)%3===0;break;case 4:s=(Math.floor(i/3)+Math.floor(o/2))%2===0;break;case 5:s=i*o%2+i*o%3===0;break;case 6:s=(i*o%2+i*o%3)%2===0;break;default:s=((i+o)%2+i*o%3)%2===0;break}s&&(e[o][i]=!e[o][i])}}function un(e){let t=e.length,n=0;for(let a=0;a<t;a++){let d=!1,p=0;for(let u=0;u<t;u++)u===0||e[a][u]!==d?(d=e[a][u],p=1):(p++,p===5?n+=3:p>5&&(n+=1))}for(let a=0;a<t;a++){let d=!1,p=0;for(let u=0;u<t;u++)u===0||e[u][a]!==d?(d=e[u][a],p=1):(p++,p===5?n+=3:p>5&&(n+=1))}for(let a=0;a<t-1;a++)for(let d=0;d<t-1;d++){let p=e[a][d];p===e[a][d+1]&&p===e[a+1][d]&&p===e[a+1][d+1]&&(n+=3)}let r=(a,d)=>{if(![!0,!1,!0,!0,!0,!1,!0].every((E,f)=>a[d+f]===E))return 0;let v=d>=4&&a.slice(d-4,d).every(E=>!E),R=d+11<=a.length&&a.slice(d+7,d+11).every(E=>!E);return(v?40:0)+(R?40:0)};for(let a=0;a<t;a++){let d=e[a],p=e.map(u=>u[a]);for(let u=0;u+7<=t;u++)n+=r(d,u),n+=r(p,u)}let o=0;for(let a of e)for(let d of a)d&&o++;let i=t*t,s=Math.ceil(Math.abs(o*20-i*10)/i)-1;return n+=s*10,n}var Se="http://www.w3.org/2000/svg";function Oe(e,t={}){let n=t.dark??"#000000",r=t.light??"#ffffff",o=t.quietZone??2,i=e.size+o*2,s="";for(let u=0;u<e.size;u++)for(let v=0;v<e.size;v++)e.modules[u][v]&&(s+=`M${v+o} ${u+o}h1v1h-1z`);let a=document.createElementNS(Se,"svg");a.setAttribute("viewBox",`0 0 ${i} ${i}`),a.setAttribute("shape-rendering","crispEdges"),a.setAttribute("role","img");let d=document.createElementNS(Se,"rect");d.setAttribute("width",String(i)),d.setAttribute("height",String(i)),d.setAttribute("fill",r),a.appendChild(d);let p=document.createElementNS(Se,"path");return p.setAttribute("d",s),p.setAttribute("fill",n),a.appendChild(p),a}var mt="/.well-known/enbox-connect";async function be(e){try{let t=new URL(mt,e).toString(),n=await fetch(t,{signal:AbortSignal.timeout(6e3)});if(!n.ok)return;let r=await n.json();return typeof r?.connectServerUrl!="string"?void 0:{connectServerUrl:r.connectServerUrl}}catch{return}}async function De(e){return await be(e)!==void 0}import{DidJwk as fn}from"@enbox/dids";import{X25519 as mn}from"@enbox/crypto";import{CONNECT_DENIED_TOKEN as hn,openResponse as gn,randomToken as ht,RelayClientTransport as wn,sealRequest as vn}from"@enbox/connect";var Ae=6,F=class extends Error{constructor(){super("[@enbox/browser] Relay connect cancelled."),this.name="RelayConnectCancelledError"}};async function Ue(e){let n=(e.createTransport??(m=>new wn(m)))({connectServerUrl:e.connectServerUrl,walletUri:e.walletUri,timeoutMs:e.timeoutMs,pollIntervalMs:e.pollIntervalMs,onClaimed:e.onClaimed}),r=await fn.create(),o=await mn.generateKey(),i={kty:"OKP",crv:"X25519",x:o.x},s=ht(),a=ht(),d=await n.requestProfile(a),p={clientDid:r.uri,appName:e.appName,appIcon:e.appIcon,clientMetadata:e.clientMetadata,permissionRequests:e.permissionRequests,supportedDidMethods:["did:dht","did:jwk"],nonce:s,state:a,responseKey:i,reply:d.reply},u=await vn({request:p,signer:r,encryption:d.encryption}),v=await n.deliverRequest(u);v!==void 0&&e.onWalletUriReady(v);let E=await(e.cancelled===void 0?n.awaitResponse():Promise.race([n.awaitResponse(),e.cancelled]));if(E===hn)return;let f;for(let m=1;m<=Ae;m++){let P=await(e.cancelled===void 0?e.requestPin(m,f):Promise.race([e.requestPin(m,f),e.cancelled]));try{let C=await gn({jwe:E,recipientPrivateKey:o,expected:{clientDid:r.uri,nonce:s,state:a},pin:P});if(C.delegatePortableDid===void 0)throw new Error("Connect: wallet response omitted `delegatePortableDid`.");return{delegatePortableDid:C.delegatePortableDid,delegateGrants:C.delegateGrants,connectedDid:C.providerDid,sessionRevocations:C.sessionRevocations}}catch(C){let S=C instanceof Error?C:new Error(String(C));if(S.message.startsWith("Connect:"))throw S;f=S}}throw new Error(`[@enbox/browser] The pairing code did not match after ${Ae} attempts.`)}var bt="enbox:connect:lastChoice",yn=3e4,xn=1e4,ye=4,En=4,gt=3,qe={background:"--ec-bg",surface:"--ec-surface",text:"--ec-text",textMuted:"--ec-muted",border:"--ec-border",accent:"--ec-accent",accentContrast:"--ec-accent-contrast",danger:"--ec-danger",success:"--ec-success"};async function yt(e){return(await be(e))?.connectServerUrl}async function Cn(e){let t=new Y({walletUrl:e.walletUrl,timeoutMs:e.timeoutMs});return await new bn({transport:t}).connect({appName:e.appName,appIcon:e.appIcon,clientMetadata:ve(),permissionRequests:e.permissionRequests})}function _n(){return typeof window>"u"?!1:(window.matchMedia?.("(pointer: coarse)").matches??!1)&&Math.min(window.innerWidth,window.innerHeight)<900}function kn(){return{runRelay:Ue,runPopup:Cn,discoverConnectServerUrl:yt,validateWalletUrl:De,isMobile:_n,storage:typeof localStorage>"u"?void 0:localStorage}}function Pn(e){try{let t=e?.getItem(bt);if(t==null)return;let n=JSON.parse(t);if((n.method==="phone"||n.method==="browser")&&typeof n.walletUrl=="string")return{method:n.method,walletUrl:n.walletUrl}}catch{}}function Rn(e,t){try{e?.setItem(bt,JSON.stringify(t))}catch{}}function Mn(){let e,t={active:!0},n=new Promise((r,o)=>{e=()=>{t.active===!0&&(t.active=!1,o(new F))}});return n.catch(()=>{}),t.cancelled=n,t.cancel=e,t}function Be(e){if(typeof window>"u"||typeof document>"u")throw new Error("[@enbox/browser] The connect modal is only available in browser environments.");let t={...kn(),...e.deps},n=Sn(e.wallets??[]),r=e.rememberChoice??!0,o=e.appName??window.location.host,i=e.relayWalletPath??"/connect/app",s=t.isMobile(),a=r?Pn(t.storage):void 0,d=e.walletUrl!==void 0,p=e.walletUrl??(a!==void 0&&(d||Tn(n,a.walletUrl))?a.walletUrl:void 0)??n[0]?.url,u=e.preferredMethod??a?.method??"phone";return new Promise((v,R)=>{let E=document.createElement("div");E.id="enbox-connect-modal";let f=E.attachShadow({mode:"open"}),m=document.createElement("style");m.textContent=On,f.appendChild(m);let P=document.createElement("div");P.className="overlay";let C=document.createElement("div");C.className="modal",C.setAttribute("role","dialog"),C.setAttribute("aria-modal","true"),C.setAttribute("aria-label",`Connect to ${o}`);let S=e.theme??{},J=S.appearance??"auto";J!=="auto"&&C.setAttribute("data-appearance",J);let xe=window.matchMedia?.("(prefers-color-scheme: dark)"),Et=S.accent!==void 0||S.accentContrast!==void 0||S.light!==void 0||S.dark!==void 0,He=()=>{let l=J==="auto"?xe?.matches===!0?"dark":"light":J,c={accent:S.accent,accentContrast:S.accentContrast,...S[l]};for(let x of Object.keys(qe)){let w=c[x];typeof w=="string"&&w.trim()!==""?C.style.setProperty(qe[x],w):C.style.removeProperty(qe[x])}},ze=()=>He();Et&&(He(),J==="auto"&&xe?.addEventListener?.("change",ze));let O=!1,Q,D,Ee=!1,X,Ke=new Map,$=[],$e=l=>n.find(c=>c.url===l)??{name:Wn(l)??l,url:l},Ct=()=>{if(p===void 0){$=n.slice(0,gt);return}if($.some(c=>c.url===p))return;let l=$e(p);$=[l,...n.filter(c=>c.url!==l.url)].slice(0,gt)},ce=l=>{p=l,Z(),V()},_t=()=>{Q?.cancel(),clearTimeout(D),document.removeEventListener("keydown",Ve),xe?.removeEventListener?.("change",ze);try{document.body.removeChild(E)}catch{}},de=l=>{O||(O=!0,_t(),l())},Ge=l=>{r&&Rn(t.storage,{method:u,walletUrl:p??""}),Mt(),setTimeout(()=>de(()=>v(l)),1200)},Ce=()=>de(()=>R(new Error("[@enbox/browser] Connect cancelled.")));C.appendChild(Ln(o,e.appIcon,Ce));let q=document.createElement("div");q.className="stage",q.setAttribute("aria-live","polite"),C.appendChild(q);let I=document.createElement("div");I.className="footer",C.appendChild(I);let W=(...l)=>{q.replaceChildren(...l),q.classList.remove("fade-in"),q.offsetWidth,q.classList.add("fade-in")},Ye=l=>{W(y("div","spinner"),y("p","stage-caption",l))},kt=l=>{let c=p!==void 0?$e(p):void 0,x=c?.name??"your wallet";if(s){let b=document.createElement("a");b.className="deep-link",b.href=l.walletUri,c!==void 0&&b.appendChild(re(c)),b.appendChild(y("span","deep-link-label",`Continue in ${x}`)),W(b,y("p","stage-caption",`${x} opens to approve this connection.`),y("p","stage-subline","Come back here when you\u2019re done."));return}let w=document.createElement("div");if(w.className="qr-box",w.replaceChildren(Oe(Ne(l.walletUri),{dark:"#14141f",light:"transparent",quietZone:2})),c!==void 0){let b=y("div","qr-logo");b.appendChild(re(c)),w.appendChild(b)}W(w,y("p","stage-caption","Scan with your phone\u2019s camera"),y("p","stage-subline",`${x} stays on your phone.`))},Pt=()=>{let l=document.createElement("div");l.className="claimed-pulse",W(l,y("p","stage-caption","Phone connected \u2014 finish there"),y("p","stage-subline","Approve the request on your phone, then come back here."))},Rt=(l,c)=>new Promise(x=>{X=x;let w=document.createElement("div");w.className="pin-row",c!==void 0&&w.classList.add("shake");let b=[];for(let k=0;k<ye;k++){let _=document.createElement("input");_.className="pin-input",_.type="text",_.inputMode="numeric",_.maxLength=1,_.setAttribute("aria-label",`Code digit ${k+1}`),b.push(_),w.appendChild(_)}let B=()=>{let k=b.map(_=>_.value).join("");if(k.length===ye&&X!==void 0){let _=X;X=void 0,Ye("Checking the code\u2026"),_(k)}};b.forEach((k,_)=>{k.addEventListener("input",()=>{k.value=k.value.replace(/\D/g,"").slice(0,1),k.value!==""&&_+1<b.length&&b[_+1].focus(),B()}),k.addEventListener("keydown",A=>{A.key==="Backspace"&&k.value===""&&_>0&&b[_-1].focus()}),k.addEventListener("paste",A=>{let U=(A.clipboardData?.getData("text")??"").replace(/\D/g,"").slice(0,ye);U.length!==0&&(A.preventDefault(),U.split("").forEach((L,T)=>{b[T]!==void 0&&(b[T].value=L)}),b[Math.min(U.length,ye)-1]?.focus(),B())})}),W(y("p","stage-caption","Enter the code shown on your phone"),w,...c!==void 0?[y("p","stage-error","That code doesn\u2019t match \u2014 check your phone.")]:[y("p","stage-subline",l===1?"Phone connected.":"")]),b[0].focus()}),Mt=()=>{let l=y("div","check");l.textContent="\u2713",W(l,y("p","stage-caption","You\u2019re connected."))},Fe=()=>{W(y("p","stage-caption","No problem \u2014 nothing was shared."),le("Start over",()=>{V()}),Ie("Close",()=>de(()=>v(void 0))))},pe=(l,c)=>{W(y("p","stage-caption",l),le("Start over",()=>{V()}),Ie("Close",()=>de(()=>R(c??new Error(`[@enbox/browser] ${l}`)))))},Tt=()=>{W(y("p","stage-caption","This wallet can\u2019t connect by phone here."),y("p","stage-subline","You can continue in this browser instead."),le("Use this browser",()=>{ue()}))},St=()=>{W(y("p","stage-caption","Connect with a wallet in this browser"),y("p","stage-subline","Your wallet opens in a small window to approve this connection."),le("Open wallet window",()=>{ue()}))},Wt=()=>{W(y("div","spinner"),y("p","stage-caption","Finish in the wallet window"),y("p","stage-subline","We\u2019ll wrap up here as soon as you\u2019re done."))},Je=l=>{W(y("p","stage-caption",l?"Your browser blocked the wallet window.":"The wallet window was closed."),le(l?"Open it now":"Reopen window",()=>{ue()}),...s?[]:[Ie("Use your phone instead",()=>{Xe("phone")})])},Lt=async l=>{if(e.connectServerUrl!==void 0)return e.connectServerUrl;let c=Ke.get(l);return c===void 0&&(c=t.discoverConnectServerUrl(l),Ke.set(l,c)),c},Nt=l=>{clearTimeout(D);let c=Math.max(xn,l*1e3-yn);D=setTimeout(()=>{!O&&X===void 0&&u==="phone"&&Qe()},c)},Qe=async()=>{if(Q?.cancel(),clearTimeout(D),p===void 0){pe("No wallet is configured.");return}u="phone",Z(),Ye("Getting things ready\u2026");let l=new URL(p).origin,c=await Lt(l);if(c===void 0){Tt();return}let x=Mn();Q=x;try{let w=await t.runRelay({connectServerUrl:c,walletUri:new URL(i,l).toString(),appName:o,appIcon:e.appIcon,clientMetadata:ve(),permissionRequests:e.permissionRequests,timeoutMs:e.timeout,cancelled:x.cancelled,onWalletUriReady:b=>{x.active&&!O&&(kt(b),Nt(b.expiresIn))},onClaimed:()=>{x.active&&!O&&(clearTimeout(D),Pt())},requestPin:(b,B)=>(clearTimeout(D),Rt(b,B))});if(!x.active||O)return;w===void 0?Fe():Ge(w)}catch(w){if(!x.active||O||w instanceof F)return;let b=w instanceof Error?w:new Error(String(w));pe(/timed out/i.test(b.message)?"That took too long, so we stopped for safety.":"Something went wrong while connecting.",b)}},ue=()=>{if(Q?.cancel(),clearTimeout(D),p===void 0){pe("No wallet is configured.");return}if(Ee)return;u="browser",Z();let l;try{l=t.runPopup({walletUrl:p,permissionRequests:e.permissionRequests,appName:o,appIcon:e.appIcon,timeoutMs:e.timeout})}catch(c){let x=c instanceof Error&&/popup blocked/i.test(c.message);Je(x);return}Ee=!0,Wt(),l.then(c=>{O||(c===void 0?Fe():Ge(c))}).catch(c=>{if(O)return;if(c instanceof K){Je(!1);return}let x=c instanceof Error?c:new Error(String(c));pe(/timed out/i.test(x.message)?"That took too long, so we stopped for safety.":"Something went wrong while connecting.",x)}).finally(()=>{Ee=!1})},V=async()=>{u==="browser"?(Q?.cancel(),clearTimeout(D),Z(),St()):await Qe()},Xe=async l=>{u=l,await V()},Z=()=>{if(I.replaceChildren(),!d){Ct();let c=Ot();c.label!==void 0&&I.appendChild(c.label),I.appendChild(c.row),I.appendChild(c.panel)}let l=document.createElement("div");if(l.className="footer-row",u==="phone"){let c=document.createElement("button");c.className="footer-link method-link",c.textContent="No phone? Use this browser \u2192",c.addEventListener("click",()=>{ue()}),l.appendChild(c)}else if(!s){let c=document.createElement("button");c.className="footer-link method-link",c.textContent="Use your phone instead \u2192",c.addEventListener("click",()=>{Xe("phone")}),l.appendChild(c)}l.childElementCount>0&&I.appendChild(l)},Ot=()=>{let l=document.createElement("div");l.className="wallet-row",l.setAttribute("role","radiogroup"),l.setAttribute("aria-label","Wallet");for(let h of $){let g=document.createElement("button");g.className="row-tile",g.title=h.description??h.name,g.setAttribute("role","radio");let N=h.url===p;g.setAttribute("aria-checked",N?"true":"false"),N&&g.classList.add("selected"),g.appendChild(re(h)),g.appendChild(y("span","row-tile-name",h.name)),g.addEventListener("click",()=>{h.url!==p&&ce(h.url)}),l.appendChild(g)}let c=document.createElement("div");c.className="wallet-panel",c.hidden=!0;let x=n.filter(h=>!$.some(g=>g.url===h.url)).length,w=document.createElement("button");w.className="row-tile more-tile",w.title="All wallets",w.setAttribute("aria-expanded","false"),w.appendChild(y("span","more-count",x>0?`+${x}`:"\u22EF")),w.appendChild(y("span","row-tile-name","More")),w.addEventListener("click",()=>{c.hidden=!c.hidden,w.setAttribute("aria-expanded",c.hidden?"false":"true")}),l.appendChild(w);let b=$.length>0?y("div","wallet-row-label","Connecting with"):void 0,B=[],k=document.createElement("div");if(k.className="wallet-empty",k.textContent="No wallets match your search.",k.hidden=!0,n.length>En){let h=document.createElement("input");h.type="search",h.className="wallet-search",h.placeholder="Search wallets\u2026",h.setAttribute("aria-label","Search wallets"),h.addEventListener("input",()=>{let g=h.value.trim().toLowerCase(),N=0;for(let{wallet:et,el:Dt}of B){let tt=g===""||et.name.toLowerCase().includes(g)||et.url.toLowerCase().includes(g);Dt.hidden=!tt,tt&&(N+=1)}k.hidden=N>0}),c.appendChild(h)}let _=document.createElement("div");_.className="wallet-scroll";let A=document.createElement("div");A.className="wallet-grid";for(let h of n){let g=document.createElement("button");g.className="wallet-tile",g.title=h.name,g.appendChild(re(h));let N=document.createElement("span");N.className="wallet-tile-name",N.textContent=h.name,g.appendChild(N),h.url===p&&(g.classList.add("selected"),g.setAttribute("aria-pressed","true")),g.addEventListener("click",()=>{ce(h.url)}),B.push({wallet:h,el:g}),A.appendChild(g)}_.appendChild(A),_.appendChild(k),c.appendChild(_);let U=document.createElement("div");U.className="wallet-custom";let L=document.createElement("input");L.className="url-input",L.type="url",L.placeholder="https://your-wallet.example";let T=document.createElement("button");T.className="url-go",T.textContent="Use";let j=document.createElement("div");j.className="url-error",j.hidden=!0;let _e=!1,Ze=async()=>{let h=L.value.trim();if(h==="")return;let g;try{g=new URL(h.includes("://")?h:`https://${h}`).origin}catch{L.classList.add("invalid");return}if(_e){ce(g);return}T.disabled=!0,T.textContent="Checking\u2026",j.hidden=!0;let N=await t.validateWalletUrl(g);if(T.disabled=!1,N){T.textContent="Use",ce(g);return}_e=!0,T.textContent="Use anyway",L.classList.add("invalid"),j.textContent=`Couldn't verify a wallet at ${g}.`,j.hidden=!1};return L.addEventListener("input",()=>{_e=!1,T.textContent="Use",L.classList.remove("invalid"),j.hidden=!0}),L.addEventListener("keydown",h=>{h.key==="Enter"&&Ze()}),T.addEventListener("click",()=>{Ze()}),U.appendChild(L),U.appendChild(T),c.appendChild(U),c.appendChild(j),{label:b,row:l,panel:c}};P.addEventListener("click",l=>{l.target===P&&Ce()});let Ve=l=>{if(l.key==="Escape"){Ce();return}l.key==="Tab"&&Nn(f,l)};document.addEventListener("keydown",Ve),P.appendChild(C),f.appendChild(P),document.body.appendChild(E),Z(),V()})}function Tn(e,t){return e.some(n=>n.url===t)}function Sn(e){return e.filter((t,n)=>e.findIndex(r=>r.url===t.url)===n)}function Wn(e){if(e!==void 0)try{return new URL(e).hostname}catch{return e}}function y(e,t,n){let r=document.createElement(e);return r.className=t,n!==void 0&&(r.textContent=n),r}function le(e,t){let n=document.createElement("button");return n.className="stage-btn",n.textContent=e,n.addEventListener("click",t),n}function Ie(e,t){let n=document.createElement("button");return n.className="footer-link",n.textContent=e,n.addEventListener("click",t),n}function Ln(e,t,n){let r=document.createElement("div");r.className="header";let o=document.createElement("div");if(o.className="header-identity",t!==void 0){let a=document.createElement("img");a.className="header-icon",a.src=t,a.alt="",a.width=24,a.height=24,a.addEventListener("error",()=>a.remove()),o.appendChild(a)}let i=document.createElement("h2");i.textContent=`Connect to ${e}`,o.appendChild(i);let s=document.createElement("button");return s.className="close-btn",s.setAttribute("aria-label","Close"),s.textContent="\xD7",s.addEventListener("click",n),r.appendChild(o),r.appendChild(s),r}function Nn(e,t){let n=Array.from(e.querySelectorAll('button, input, a[href], [tabindex]:not([tabindex="-1"])')).filter(s=>!s.hasAttribute("disabled")&&s.offsetParent!==null);if(n.length===0)return;let r=n[0],o=n[n.length-1],i=e.activeElement;t.shiftKey&&(i===r||i===null)?(t.preventDefault(),o.focus()):!t.shiftKey&&i===o&&(t.preventDefault(),r.focus())}var wt=`
155
+ --ec-bg: #ffffff;
156
+ --ec-surface: #f5f6f8;
157
+ --ec-text: #17171f;
158
+ --ec-muted: #63636e;
159
+ --ec-border: #e3e4e9;
160
+ --ec-accent: #0a62d0;
161
+ --ec-accent-contrast: #ffffff;
162
+ --ec-danger: #c0392b;
163
+ --ec-success: #1e9e5a;`,vt=`
164
+ --ec-bg: #181822;
165
+ --ec-surface: #23232f;
166
+ --ec-text: #e9e9f0;
167
+ --ec-muted: #9a9aa6;
168
+ --ec-border: #33333f;
169
+ --ec-accent: #58a6ff;
170
+ --ec-accent-contrast: #0b1526;
171
+ --ec-danger: #ff7a7a;
172
+ --ec-success: #43d17c;`,On=`
155
173
  * { box-sizing: border-box; margin: 0; padding: 0; }
156
174
 
175
+ /* Keep the hidden attribute authoritative: author display values (e.g.
176
+ the panel's flex) would otherwise override the UA's [hidden] rule and
177
+ leave "collapsed" sections permanently expanded. */
178
+ [hidden] { display: none !important; }
179
+
157
180
  .overlay {
158
181
  position: fixed;
159
182
  inset: 0;
@@ -161,6 +184,7 @@ import{Enbox as oo,defineProtocol as ro,repository as io}from"@enbox/api";import
161
184
  display: flex;
162
185
  align-items: center;
163
186
  justify-content: center;
187
+ padding: 16px;
164
188
  background: rgba(0, 0, 0, 0.5);
165
189
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
166
190
  animation: fadeIn 0.15s ease-out;
@@ -175,115 +199,159 @@ import{Enbox as oo,defineProtocol as ro,repository as io}from"@enbox/api";import
175
199
  40%, 80% { transform: translateX(6px); }
176
200
  }
177
201
  @keyframes spin { to { transform: rotate(360deg); } }
202
+ @keyframes claimedPulse {
203
+ 0%, 100% { transform: scale(0.85); opacity: 0.7; }
204
+ 50% { transform: scale(1); opacity: 1; }
205
+ }
178
206
 
179
- .modal {
180
- background: ${t};
181
- color: ${n};
207
+ .modal {${wt}
208
+ --ec-accent-soft: color-mix(in srgb, var(--ec-accent) 14%, transparent);
209
+ background: var(--ec-bg);
210
+ color: var(--ec-text);
182
211
  border-radius: 16px;
183
212
  width: 400px;
184
- max-width: 92vw;
185
- max-height: 88vh;
213
+ max-width: 100%;
214
+ max-height: calc(100vh - 32px);
186
215
  overflow-y: auto;
187
- padding: 20px 24px 16px;
188
- box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
216
+ padding: 16px 20px 12px;
217
+ box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
189
218
  animation: slideUp 0.2s ease-out;
190
219
  display: flex;
191
220
  flex-direction: column;
192
221
  }
222
+ @media (prefers-color-scheme: dark) {
223
+ .modal {${vt}
224
+ }
225
+ }
226
+ .modal[data-appearance='light'] {${wt}
227
+ }
228
+ .modal[data-appearance='dark'] {${vt}
229
+ }
193
230
 
194
- .header { display: flex; justify-content: space-between; align-items: center; }
231
+ button, input { font-family: inherit; }
232
+ button:focus-visible, a:focus-visible {
233
+ outline: 2px solid var(--ec-accent);
234
+ outline-offset: 2px;
235
+ }
236
+
237
+ .header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
195
238
  .header-identity { display: flex; align-items: center; gap: 10px; min-width: 0; }
196
- .header-icon { border-radius: 6px; }
239
+ .header-icon { border-radius: 6px; flex-shrink: 0; }
197
240
  h2 { font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
198
241
 
199
242
  .close-btn {
200
243
  background: none; border: none; font-size: 24px; cursor: pointer;
201
- color: ${r}; padding: 4px 8px; border-radius: 8px; line-height: 1;
244
+ color: var(--ec-muted); padding: 4px 8px; border-radius: 8px; line-height: 1;
245
+ flex-shrink: 0;
202
246
  }
203
- .close-btn:hover { color: ${n}; background: ${i}; }
247
+ .close-btn:hover { color: var(--ec-text); background: var(--ec-surface); }
204
248
 
205
249
  .stage {
206
- min-height: 300px;
250
+ min-height: 240px;
207
251
  display: flex;
208
252
  flex-direction: column;
209
253
  align-items: center;
210
254
  justify-content: center;
211
- gap: 12px;
255
+ gap: 10px;
212
256
  text-align: center;
213
- padding: 16px 0;
257
+ padding: 12px 0 10px;
214
258
  }
215
259
  .stage.fade-in > * { animation: stageIn 0.15s ease-out; }
216
260
 
217
261
  .qr-box {
218
- width: 216px;
219
- height: 216px;
220
- padding: 12px;
262
+ position: relative;
263
+ width: 200px;
264
+ height: 200px;
265
+ padding: 10px;
221
266
  border-radius: 12px;
222
- background: ${e?"#10192e":"#ffffff"}
267
+ background: #ffffff;
268
+ border: 1px solid #e3e4e9;
269
+ }
270
+ .qr-box svg { width: 100%; height: 100%; display: block; }
271
+
272
+ /* Selected wallet's mark on the QR centre. Like the card, the plate is
273
+ theme-invariant white so the logo sits on a scannable ground. */
274
+ .qr-logo {
275
+ position: absolute;
276
+ top: 50%;
277
+ left: 50%;
278
+ transform: translate(-50%, -50%);
279
+ width: 44px;
280
+ height: 44px;
281
+ border-radius: 10px;
282
+ background: #ffffff;
283
+ border: 1px solid #e3e4e9;
284
+ display: flex;
285
+ align-items: center;
286
+ justify-content: center;
287
+ }
288
+ .qr-logo .wallet-icon { width: 30px; height: 30px; }
289
+ .qr-logo .wallet-badge { border-radius: 8px; font-size: 15px; }
290
+
223
291
  .claimed-pulse {
224
292
  width: 64px; height: 64px; border-radius: 50%;
225
- background: ${s}; position: relative;
293
+ background: var(--ec-accent-soft); position: relative;
226
294
  }
227
295
  .claimed-pulse::after {
228
296
  content: ''; position: absolute; inset: 18px; border-radius: 50%;
229
- background: ${a};
230
- animation: enbox-claimed-pulse 1.6s ease-in-out infinite;
297
+ background: var(--ec-accent);
298
+ animation: claimedPulse 1.6s ease-in-out infinite;
231
299
  }
232
- @keyframes enbox-claimed-pulse {
233
- 0%, 100% { transform: scale(0.85); opacity: 0.7; }
234
- 50% { transform: scale(1); opacity: 1; }
235
- }
236
- @media (prefers-reduced-motion: reduce) {
237
- .claimed-pulse::after { animation: none; }
238
- };
239
- border: 1px solid ${o};
240
- }
241
- .qr-box svg { width: 100%; height: 100%; display: block; }
242
300
 
243
301
  .stage-caption { font-size: 15px; font-weight: 600; }
244
- .stage-subline { font-size: 13px; color: ${r}; max-width: 300px; line-height: 1.45; }
245
- .stage-error { font-size: 13px; color: ${l}; }
302
+ .stage-subline { font-size: 13px; color: var(--ec-muted); max-width: 300px; line-height: 1.45; }
303
+ .stage-error { font-size: 13px; color: var(--ec-danger); }
246
304
 
247
305
  .deep-link {
248
- display: block;
306
+ display: flex;
307
+ align-items: center;
308
+ justify-content: center;
309
+ gap: 10px;
249
310
  width: 100%;
250
- padding: 14px 16px;
311
+ padding: 13px 16px;
251
312
  border-radius: 12px;
252
- background: ${a};
253
- color: #fff;
313
+ background: var(--ec-accent);
314
+ color: var(--ec-accent-contrast);
254
315
  font-weight: 600;
255
316
  font-size: 15px;
256
317
  text-decoration: none;
257
318
  }
319
+ .deep-link .wallet-icon { width: 24px; height: 24px; }
320
+ .deep-link .wallet-badge {
321
+ border-radius: 6px;
322
+ font-size: 12px;
323
+ background: var(--ec-accent-contrast);
324
+ }
325
+ .deep-link .wallet-img { border-radius: 6px; }
258
326
 
259
327
  .pin-row { display: flex; gap: 10px; }
260
328
  .pin-row.shake { animation: shake 0.4s ease-in-out; }
261
329
  .pin-input {
262
- width: 48px; height: 56px;
330
+ width: 46px; height: 54px;
263
331
  text-align: center;
264
332
  font-size: 24px; font-weight: 600;
265
- color: ${n};
266
- background: ${i};
267
- border: 1px solid ${o};
333
+ color: var(--ec-text);
334
+ background: var(--ec-surface);
335
+ border: 1px solid var(--ec-border);
268
336
  border-radius: 10px;
269
337
  outline: none;
270
338
  }
271
- .pin-input:focus { border-color: ${a}; }
339
+ .pin-input:focus { border-color: var(--ec-accent); }
272
340
 
273
341
  .check {
274
342
  width: 56px; height: 56px;
275
343
  display: flex; align-items: center; justify-content: center;
276
344
  border-radius: 50%;
277
- background: ${e?"#43d17c":"#1e9e5a"};
278
- color: #fff;
345
+ background: var(--ec-success);
346
+ color: #ffffff;
279
347
  font-size: 28px;
280
348
  }
281
349
 
282
350
  .spinner {
283
351
  width: 32px; height: 32px;
284
352
  border-radius: 50%;
285
- border: 3px solid ${o};
286
- border-top-color: ${a};
353
+ border: 3px solid var(--ec-border);
354
+ border-top-color: var(--ec-accent);
287
355
  animation: spin 0.8s linear infinite;
288
356
  }
289
357
 
@@ -291,87 +359,170 @@ import{Enbox as oo,defineProtocol as ro,repository as io}from"@enbox/api";import
291
359
  padding: 10px 20px;
292
360
  border: none;
293
361
  border-radius: 10px;
294
- background: ${a};
295
- color: #fff;
362
+ background: var(--ec-accent);
363
+ color: var(--ec-accent-contrast);
296
364
  font-size: 14px;
297
365
  font-weight: 500;
298
366
  cursor: pointer;
299
367
  }
300
- .stage-btn:hover { filter: brightness(1.1); }
368
+ .stage-btn:hover { filter: brightness(1.08); }
301
369
 
302
370
  .footer {
303
- border-top: 1px solid ${o};
304
- padding-top: 10px;
371
+ border-top: 1px solid var(--ec-border);
372
+ padding-top: 8px;
305
373
  display: flex;
306
374
  flex-direction: column;
307
375
  gap: 6px;
376
+ }
377
+
378
+ .footer-row {
379
+ display: flex;
308
380
  align-items: center;
381
+ justify-content: space-between;
382
+ flex-wrap: wrap;
383
+ gap: 2px 8px;
309
384
  }
385
+ .footer-row > * { min-width: 0; }
386
+ .footer-row > :only-child { margin-inline: auto; }
310
387
 
311
388
  .footer-link {
312
389
  background: none;
313
390
  border: none;
314
- color: ${r};
391
+ color: var(--ec-muted);
315
392
  font-size: 13px;
316
393
  cursor: pointer;
317
- padding: 4px 8px;
394
+ padding: 5px 8px;
318
395
  border-radius: 8px;
319
396
  }
320
- .footer-link:hover { color: ${n}; background: ${i}; }
321
- .method-link { color: ${a}; }
397
+ .footer-link:hover { color: var(--ec-text); background: var(--ec-surface); }
398
+ .method-link { color: var(--ec-accent); }
399
+
400
+ .wallet-row-label { font-size: 12px; color: var(--ec-muted); padding: 2px 2px 0; }
322
401
 
323
- .wallet-switcher { width: 100%; display: flex; flex-direction: column; align-items: center; }
324
- .wallet-panel { width: 100%; padding: 6px 0; display: flex; flex-direction: column; gap: 4px; }
325
402
  .wallet-row {
326
- width: 100%;
327
- text-align: left;
328
- padding: 8px 12px;
329
- background: ${i};
330
- border: 1px solid ${o};
331
- border-radius: 10px;
332
- color: ${n};
333
- font-size: 13px;
403
+ display: grid;
404
+ grid-template-columns: repeat(4, 1fr);
405
+ gap: 8px;
406
+ }
407
+ .row-tile {
408
+ display: flex;
409
+ flex-direction: column;
410
+ align-items: center;
411
+ justify-content: center;
412
+ gap: 6px;
413
+ padding: 10px 6px;
414
+ min-width: 0;
415
+ background: var(--ec-surface);
416
+ border: 1px solid var(--ec-border);
417
+ border-radius: 12px;
418
+ color: var(--ec-text);
419
+ font-size: 11px;
420
+ cursor: pointer;
421
+ }
422
+ .row-tile:hover { border-color: var(--ec-accent); }
423
+ .row-tile.selected {
424
+ border-color: var(--ec-accent);
425
+ background: var(--ec-accent-soft);
426
+ box-shadow: inset 0 0 0 1px var(--ec-accent);
427
+ }
428
+ .row-tile.selected .row-tile-name { font-weight: 600; }
429
+ .row-tile .wallet-icon { width: 28px; height: 28px; }
430
+ .row-tile-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
431
+
432
+ .more-tile { color: var(--ec-muted); }
433
+ .more-tile:hover { color: var(--ec-text); }
434
+ .more-tile[aria-expanded='true'] { border-color: var(--ec-accent); }
435
+ .more-count {
436
+ width: 28px;
437
+ height: 28px;
438
+ border-radius: 8px;
439
+ display: inline-flex;
440
+ align-items: center;
441
+ justify-content: center;
442
+ font-size: 12px;
443
+ font-weight: 600;
444
+ background: var(--ec-accent-soft);
445
+ color: var(--ec-accent);
446
+ }
447
+
448
+ .wallet-panel { width: 100%; padding: 4px 0 2px; display: flex; flex-direction: column; gap: 8px; }
449
+ .wallet-search {
450
+ width: 100%; padding: 8px 12px;
451
+ border-radius: 10px; border: 1px solid var(--ec-border); background: transparent;
452
+ color: inherit; font: inherit; font-size: 13px;
453
+ }
454
+ .wallet-search:focus { outline: none; border-color: var(--ec-accent); }
455
+
456
+ .wallet-scroll { max-height: 260px; overflow-y: auto; }
457
+ .wallet-grid {
458
+ display: grid;
459
+ grid-template-columns: repeat(3, 1fr);
460
+ gap: 8px;
461
+ }
462
+ .wallet-tile {
463
+ aspect-ratio: 1;
464
+ display: flex;
465
+ flex-direction: column;
466
+ align-items: center;
467
+ justify-content: center;
468
+ gap: 8px;
469
+ padding: 8px;
470
+ min-width: 0;
471
+ background: var(--ec-surface);
472
+ border: 1px solid var(--ec-border);
473
+ border-radius: 12px;
474
+ color: var(--ec-text);
475
+ font-size: 12px;
334
476
  cursor: pointer;
335
477
  }
336
- .wallet-row:hover, .wallet-row.selected { border-color: ${a}; }
478
+ .wallet-tile:hover { border-color: var(--ec-accent); }
479
+ .wallet-tile.selected {
480
+ border-color: var(--ec-accent);
481
+ background: var(--ec-accent-soft);
482
+ box-shadow: inset 0 0 0 1px var(--ec-accent);
483
+ }
484
+ .wallet-tile-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
337
485
 
338
486
  .wallet-icon { position: relative; width: 28px; height: 28px; flex-shrink: 0; display: inline-flex; }
487
+ .wallet-tile .wallet-icon { width: 40px; height: 40px; }
339
488
  .wallet-badge {
340
- width: 28px; height: 28px; border-radius: 8px; display: inline-flex;
489
+ width: 100%; height: 100%; border-radius: 8px; display: inline-flex;
341
490
  align-items: center; justify-content: center; font-size: 13px;
342
- font-weight: 600; background: ${s}; color: ${a};
491
+ font-weight: 600; background: var(--ec-accent-soft); color: var(--ec-accent);
343
492
  }
344
- .wallet-img { position: absolute; inset: 0; width: 28px; height: 28px; border-radius: 8px; object-fit: cover; }
345
- .wallet-row-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
346
- .wallet-search {
347
- width: 100%; box-sizing: border-box; padding: 8px 10px; margin-bottom: 4px;
348
- border-radius: 8px; border: 1px solid ${o}; background: transparent;
349
- color: inherit; font: inherit;
350
- }
351
- .wallet-search:focus { outline: none; border-color: ${a}; }
352
- .wallet-empty { padding: 8px 10px; font-size: 12px; opacity: 0.7; }
353
- .url-error { padding: 4px 2px 0; font-size: 12px; color: ${l}; }
354
- .wallet-custom { display: flex; gap: 6px; margin-top: 4px; }
493
+ .wallet-tile .wallet-badge { border-radius: 10px; font-size: 17px; }
494
+ .wallet-img { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 8px; object-fit: cover; }
495
+ .wallet-tile .wallet-img { border-radius: 10px; }
496
+
497
+ .wallet-empty { padding: 10px 4px; font-size: 12px; color: var(--ec-muted); text-align: center; }
498
+
499
+ .wallet-custom { display: flex; gap: 6px; }
355
500
  .url-input {
356
501
  flex: 1;
357
502
  padding: 8px 12px;
358
- border: 1px solid ${o};
503
+ border: 1px solid var(--ec-border);
359
504
  border-radius: 10px;
360
505
  font-size: 13px;
361
- background: ${i};
362
- color: ${n};
506
+ background: var(--ec-surface);
507
+ color: var(--ec-text);
363
508
  outline: none;
364
509
  }
365
- .url-input:focus { border-color: ${a}; }
366
- .url-input.invalid { border-color: ${l}; }
510
+ .url-input:focus { border-color: var(--ec-accent); }
511
+ .url-input.invalid { border-color: var(--ec-danger); }
367
512
  .url-go {
368
513
  padding: 8px 14px;
369
514
  border: none;
370
515
  border-radius: 10px;
371
- background: ${a};
372
- color: #fff;
516
+ background: var(--ec-accent);
517
+ color: var(--ec-accent-contrast);
373
518
  font-size: 13px;
374
519
  cursor: pointer;
375
520
  }
376
- `}var lt=[{name:"Enbox",url:"https://enbox-wallet.pages.dev",description:"Manage your digital identity and data"},{name:"Prism",url:"https://prism-wallet.pages.dev",description:"A clear view into your digital identity"},{name:"Matcha",url:"https://matcha-wallet.pages.dev",description:"A fresh approach to digital identity"},{name:"Onyx",url:"https://onyx-wallet.pages.dev",description:"A refined home for your digital identity"}];function wn(e={}){let{wallets:t=lt,walletUrl:n,timeout:r,appName:o,appIcon:i,preferredMethod:a,rememberChoice:s,connectServerUrl:l,relayWalletPath:d}=e;return{async requestAccess(p){return Ne({wallets:t,walletUrl:n,preferredMethod:a,rememberChoice:s,appName:o,appIcon:i??`${window.location.origin}/favicon.ico`,connectServerUrl:l,relayWalletPath:d,timeout:r,permissionRequests:p.permissionRequests})}}}import{X25519 as bn}from"@enbox/crypto";import{CONNECT_DENIED_TOKEN as vn,ConnectProvider as yn}from"@enbox/connect";var En=3e5,Le=class e{constructor(t){this._requestReceived=!1;this._dappOrigin=t.dappOrigin,this._dappWindow=t.dappWindow,this._recipientPrivateKey=t.recipientPrivateKey,this._requestPromise=new Promise((n,r)=>{this._resolveRequest=n,this._rejectRequest=r}),this._requestPromise.catch(()=>{}),this._messageListener=n=>{this.onMessage(n)},window.addEventListener("message",this._messageListener),this._timeoutId=setTimeout(()=>{this.close(),this._rejectRequest?.(new Error("[@enbox/browser] Timed out waiting for the connect request from the dapp."))},t.timeoutMs)}static async create(t={}){if(typeof window>"u")throw new Error("[@enbox/browser] WalletPostMessageTransport is only available in browser environments.");let n=t.dappWindow??window.opener;if(!n)throw new Error("[@enbox/browser] No opener window: the DWeb Connect page must be opened as a popup by the dapp.");let r=xn(t.dappOrigin),o=await bn.generateKey(),i={kty:"OKP",crv:"X25519",x:o.x},a=new e({dappOrigin:r,dappWindow:n,recipientPrivateKey:o,timeoutMs:t.timeoutMs??En});return n.postMessage({type:te,walletEpk:i,walletOrigin:globalThis.location.origin},r),a}get dappOrigin(){return this._dappOrigin}async awaitRequest(){return await this._requestPromise}sendResponse(t){this._dappWindow.postMessage({type:oe,payload:t},this._dappOrigin),this.close()}deny(){this.sendResponse(vn)}close(){clearTimeout(this._timeoutId),this._messageListener!==void 0&&(window.removeEventListener("message",this._messageListener),this._messageListener=void 0)}onMessage(t){let n=ue(t,this._dappOrigin,this._dappWindow);if(n!==void 0&&!(n.type!==ne||this._requestReceived)){if(this._requestReceived=!0,typeof n.jwe!="string"){this.settleRequest(new Error("[@enbox/browser] Connect request message did not carry a ciphertext payload."));return}this.openRequest(n.jwe)}}async openRequest(t){try{let n=await yn.openRequest({jwe:t,decryption:{mode:"ecdh-es",recipientPrivateKey:this._recipientPrivateKey,walletOrigin:globalThis.location.origin}});if(n.reply.mode!=="post_message"){this.settleRequest(new Error("[@enbox/browser] Connect request over the popup channel must use the `post_message` reply mode."));return}this.settleRequest(n)}catch(n){this.settleRequest(n instanceof Error?n:new Error(String(n)))}}settleRequest(t){if(clearTimeout(this._timeoutId),t instanceof Error){this.close(),this._rejectRequest?.(t);return}this._resolveRequest?.(t)}};function xn(e){if(e!==void 0)return new URL(e).origin;if(document.referrer)return new URL(document.referrer).origin;throw new Error("[@enbox/browser] Unable to determine the dapp origin: no `dappOrigin` option was provided and `document.referrer` is empty.")}import{TypedRecord as Po}from"@enbox/api";import{BrowserStorage as ko}from"@enbox/auth/browser";import{DwnInterface as To}from"@enbox/agent";import{DateSort as Wo,DwnInterfaceName as No,DwnMethodName as Lo}from"@enbox/dwn-sdk-js";export{ao as AuthManager,lo as AuthSession,wn as BrowserConnectHandler,ko as BrowserStorage,fo as CONNECT_DENIED_TOKEN,mo as ConnectProvider,lt as DEFAULT_WALLETS,te as DWEB_CONNECT_LOADED_MESSAGE_TYPE,ye as DWEB_CONNECT_PATH,ne as DWEB_CONNECT_REQUEST_MESSAGE_TYPE,oe as DWEB_CONNECT_RESPONSE_MESSAGE_TYPE,Wo as DateSort,To as DwnInterface,No as DwnInterfaceName,Lo as DwnMethodName,oo as Enbox,Te as MAX_PIN_ATTEMPTS,K as PopupClientTransport,$ as PopupWindowClosedError,G as RelayConnectCancelledError,Po as TypedRecord,rt as WALLET_WELL_KNOWN_PATH,po as WalletConnect,Le as WalletPostMessageTransport,Rn as activatePolyfills,Pt as cacheResponse,Mn as clearDrlCache,$t as connectViaPopup,kn as deactivatePolyfills,ro as defineProtocol,at as discoverWalletConnectServerUrl,Re as encodeQr,_t as fetchResource,me as fetchWalletWellKnown,Je as getDwnEndpoints,Ct as handleEvent,co as normalizeProtocolRequests,X as parseDrlUrl,Me as probeWalletWellKnown,ke as qrToSvg,io as repository,Ne as runConnectModal,Se as runRelayConnect};
521
+ .url-error { font-size: 12px; color: var(--ec-danger); }
522
+
523
+ @media (prefers-reduced-motion: reduce) {
524
+ .overlay, .modal, .stage.fade-in > *, .pin-row.shake { animation: none; }
525
+ .claimed-pulse::after { animation: none; }
526
+ }
527
+ `;var xt=[{name:"Enbox",url:"https://enbox-wallet.pages.dev",description:"Manage your digital identity and data"},{name:"Prism",url:"https://prism-wallet.pages.dev",description:"A clear view into your digital identity"},{name:"Matcha",url:"https://matcha-wallet.pages.dev",description:"A fresh approach to digital identity"},{name:"Onyx",url:"https://onyx-wallet.pages.dev",description:"A refined home for your digital identity"}];function Dn(e={}){let{wallets:t=xt,walletUrl:n,timeout:r,appName:o,appIcon:i,preferredMethod:s,rememberChoice:a,connectServerUrl:d,relayWalletPath:p,theme:u}=e;return{async requestAccess(v){return Be({wallets:t,walletUrl:n,preferredMethod:s,rememberChoice:a,appName:o,appIcon:i??`${window.location.origin}/favicon.ico`,connectServerUrl:d,relayWalletPath:p,timeout:r,theme:u,permissionRequests:v.permissionRequests})}}}import{X25519 as An}from"@enbox/crypto";import{CONNECT_DENIED_TOKEN as Un,ConnectProvider as qn}from"@enbox/connect";var In=3e5,je=class e{constructor(t){this._requestReceived=!1;this._dappOrigin=t.dappOrigin,this._dappWindow=t.dappWindow,this._recipientPrivateKey=t.recipientPrivateKey,this._requestPromise=new Promise((n,r)=>{this._resolveRequest=n,this._rejectRequest=r}),this._requestPromise.catch(()=>{}),this._messageListener=n=>{this.onMessage(n)},window.addEventListener("message",this._messageListener),this._timeoutId=setTimeout(()=>{this.close(),this._rejectRequest?.(new Error("[@enbox/browser] Timed out waiting for the connect request from the dapp."))},t.timeoutMs)}static async create(t={}){if(typeof window>"u")throw new Error("[@enbox/browser] WalletPostMessageTransport is only available in browser environments.");let n=t.dappWindow??window.opener;if(!n)throw new Error("[@enbox/browser] No opener window: the DWeb Connect page must be opened as a popup by the dapp.");let r=Bn(t.dappOrigin),o=await An.generateKey(),i={kty:"OKP",crv:"X25519",x:o.x},s=new e({dappOrigin:r,dappWindow:n,recipientPrivateKey:o,timeoutMs:t.timeoutMs??In});return n.postMessage({type:ie,walletEpk:i,walletOrigin:globalThis.location.origin},r),s}get dappOrigin(){return this._dappOrigin}async awaitRequest(){return await this._requestPromise}sendResponse(t){this._dappWindow.postMessage({type:se,payload:t},this._dappOrigin),this.close()}deny(){this.sendResponse(Un)}close(){clearTimeout(this._timeoutId),this._messageListener!==void 0&&(window.removeEventListener("message",this._messageListener),this._messageListener=void 0)}onMessage(t){let n=we(t,this._dappOrigin,this._dappWindow);if(n!==void 0&&!(n.type!==ae||this._requestReceived)){if(this._requestReceived=!0,typeof n.jwe!="string"){this.settleRequest(new Error("[@enbox/browser] Connect request message did not carry a ciphertext payload."));return}this.openRequest(n.jwe)}}async openRequest(t){try{let n=await qn.openRequest({jwe:t,decryption:{mode:"ecdh-es",recipientPrivateKey:this._recipientPrivateKey,walletOrigin:globalThis.location.origin}});if(n.reply.mode!=="post_message"){this.settleRequest(new Error("[@enbox/browser] Connect request over the popup channel must use the `post_message` reply mode."));return}this.settleRequest(n)}catch(n){this.settleRequest(n instanceof Error?n:new Error(String(n)))}}settleRequest(t){if(clearTimeout(this._timeoutId),t instanceof Error){this.close(),this._rejectRequest?.(t);return}this._resolveRequest?.(t)}};function Bn(e){if(e!==void 0)return new URL(e).origin;if(document.referrer)return new URL(document.referrer).origin;throw new Error("[@enbox/browser] Unable to determine the dapp origin: no `dappOrigin` option was provided and `document.referrer` is empty.")}import{TypedRecord as zo}from"@enbox/api";import{BrowserStorage as $o}from"@enbox/auth/browser";import{DwnInterface as Yo}from"@enbox/agent";import{DateSort as Jo,DwnInterfaceName as Qo,DwnMethodName as Xo}from"@enbox/dwn-sdk-js";export{Po as AuthManager,Ro as AuthSession,Dn as BrowserConnectHandler,$o as BrowserStorage,Wo as CONNECT_DENIED_TOKEN,Lo as ConnectProvider,xt as DEFAULT_WALLETS,ie as DWEB_CONNECT_LOADED_MESSAGE_TYPE,Re as DWEB_CONNECT_PATH,ae as DWEB_CONNECT_REQUEST_MESSAGE_TYPE,se as DWEB_CONNECT_RESPONSE_MESSAGE_TYPE,Jo as DateSort,Yo as DwnInterface,Qo as DwnInterfaceName,Xo as DwnMethodName,Eo as Enbox,Ae as MAX_PIN_ATTEMPTS,Y as PopupClientTransport,K as PopupWindowClosedError,F as RelayConnectCancelledError,zo as TypedRecord,mt as WALLET_WELL_KNOWN_PATH,To as WalletConnect,je as WalletPostMessageTransport,Kn as activatePolyfills,Bt as cacheResponse,Gn as clearDrlCache,tn as connectViaPopup,$n as deactivatePolyfills,Co as defineProtocol,yt as discoverWalletConnectServerUrl,Ne as encodeQr,It as fetchResource,be as fetchWalletWellKnown,at as getDwnEndpoints,qt as handleEvent,Mo as normalizeProtocolRequests,ee as parseDrlUrl,De as probeWalletWellKnown,Oe as qrToSvg,_o as repository,Be as runConnectModal,Ue as runRelayConnect};
377
528
  //# sourceMappingURL=browser.mjs.map