@enbox/browser 0.3.48 → 0.3.49
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 +33 -46
- package/dist/browser.mjs.map +3 -3
- package/dist/esm/browser-connect-handler.js +10 -0
- package/dist/esm/browser-connect-handler.js.map +1 -1
- package/dist/esm/ui/connect-modal.js +49 -50
- package/dist/esm/ui/connect-modal.js.map +1 -1
- package/dist/types/browser-connect-handler.d.ts.map +1 -1
- package/dist/types/ui/connect-modal.d.ts +3 -3
- package/dist/types/ui/connect-modal.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/browser-connect-handler.ts +10 -0
- package/src/ui/connect-modal.ts +50 -49
package/dist/browser.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Enbox as
|
|
1
|
+
import{Enbox as _o,defineProtocol as ko,repository as Po}from"@enbox/api";import{AuthManager as Mo,AuthSession as To,normalizeProtocolRequests as So,WalletConnect as Wo}from"@enbox/auth/browser";import{CONNECT_DENIED_TOKEN as No,ConnectProvider as Oo}from"@enbox/connect";import{DidDht as qt,DidWeb as It,UniversalResolver as it}from"@enbox/dids";function ne(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 Re=new it({didResolvers:[qt,It]}),at=/^http:/,ge=/\/$/,st="drl";async function lt(e){let{didDocument:t}=await Re.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 ct(){if(!(typeof caches>"u"))return caches.open(st)}async function Bt(e,t,n,r){let o=e.request.url.replace(at,"https:").replace(ge,""),i=await ct(),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 Ht(e,t,o,n,i,r);{let a=await Re.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 Ht(e,t,n,r,o,i){let s=await lt(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(ge,"")}/${t}/${r}`,u=await fetch(p,{headers:e.request.headers});if(u.ok)return await i?.onCacheCheck?.(e,n)&&o&&jt(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 jt(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 Kt(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=ne(n.request.url);r&&n.respondWith(Bt(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 dt=`
|
|
2
2
|
.drl-loading-overlay {
|
|
3
3
|
position: fixed;
|
|
4
4
|
inset: 0;
|
|
@@ -103,7 +103,7 @@ import{Enbox as Eo,defineProtocol as Co,repository as _o}from"@enbox/api";import
|
|
|
103
103
|
opacity: 0;
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
`,
|
|
106
|
+
`,zt=`
|
|
107
107
|
<!DOCTYPE html>
|
|
108
108
|
<html lang='en'>
|
|
109
109
|
<head>
|
|
@@ -119,7 +119,7 @@ import{Enbox as Eo,defineProtocol as Co,repository as _o}from"@enbox/api";import
|
|
|
119
119
|
font-family: Arial, sans-serif;
|
|
120
120
|
text-align: center;
|
|
121
121
|
}
|
|
122
|
-
${
|
|
122
|
+
${dt}
|
|
123
123
|
</style>
|
|
124
124
|
</head>
|
|
125
125
|
<body>
|
|
@@ -132,8 +132,8 @@ import{Enbox as Eo,defineProtocol as Co,repository as _o}from"@enbox/api";import
|
|
|
132
132
|
</div>
|
|
133
133
|
</body>
|
|
134
134
|
</html>
|
|
135
|
-
`,
|
|
136
|
-
${
|
|
135
|
+
`,we=!1,K=null,oe=null;function rt(){we||(oe=document.createElement("style"),oe.innerHTML=`
|
|
136
|
+
${dt}
|
|
137
137
|
|
|
138
138
|
.drl-loading-overlay {
|
|
139
139
|
opacity: 0;
|
|
@@ -145,13 +145,13 @@ import{Enbox as Eo,defineProtocol as Co,repository as _o}from"@enbox/api";import
|
|
|
145
145
|
opacity: 1;
|
|
146
146
|
pointer-events: all;
|
|
147
147
|
}
|
|
148
|
-
`,document.head.append(
|
|
148
|
+
`,document.head.append(oe),K=document.createElement("div"),K.classList.add("drl-loading-overlay"),K.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
|
-
`,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=`
|
|
154
|
+
`,K.lastElementChild.addEventListener("click",Me),document.body.prepend(K),we=!0)}function $t(){we&&(oe?.remove(),oe=null,K?.remove(),K=null,we=!1)}function Me(){document.documentElement.removeAttribute("drl-link-loading"),he=null}var he=null,ve=!1,re=null,ie=null;function Gt(){ve||(re=async e=>{let t=e.target?.closest("a");if(t){let n=t.href,r=ne(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(zt)):(he=i,setTimeout(()=>document.documentElement.setAttribute("drl-link-loading",""),50));let d=await lt(o);if(!d.length)throw new Error("no valid DWN endpoints found");let p=`${d[0].replace(ge,"")}/${o}/${i}`;s?a&&!a.closed&&(a.location.href=p):he===i&&(window.location.href=p)}catch{throw he===i&&Me(),new Error(`DID endpoint resolution failed for the DRL: ${n}`)}}}},ie=async e=>{let t=e.composedPath()[0];if(e.pointerType==="mouse"&&e.button===2||e.pointerType==="touch"&&e.isPrimary){if(Y(),t?.src&&ne(t.src)){z=t,t.__src__=t.src;let n=t.src.replace(at,"https:").replace(ge,""),o=await(await ct())?.match(n);if(o){let i=o.headers.get("dwn-composed-url");i&&(t.src=i)}t.addEventListener("pointerup",Y,{once:!0})}}else t===z&&Y()},document.addEventListener("click",re),document.addEventListener("pointercancel",Y),document.addEventListener("pointerdown",ie),ve=!0)}function Yt(){ve&&(re&&(document.removeEventListener("click",re),re=null),ie&&(document.removeEventListener("pointerdown",ie),ie=null),document.removeEventListener("pointercancel",Y),Y(),Me(),ve=!1)}var z=null;async function Y(e){e?.type==="pointerup"&&await new Promise(t=>requestAnimationFrame(()=>t())),z&&(z.src=z.__src__,delete z.__src__,z=null)}function Gn(e={}){e.didResolvers&&(Re=new it({didResolvers:e.didResolvers})),e.serviceWorker!==!1&&Kt(e),typeof window<"u"&&typeof window.document<"u"&&(e.injectStyles!==!1&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",rt,{once:!0}):rt()),e.links!==!1&&Gt())}function Yn(){typeof window<"u"&&typeof window.document<"u"&&(Yt(),$t())}async function Fn(){return typeof caches>"u"?!1:caches.delete(st)}import{ConnectClient as xn}from"@enbox/connect";function ae(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=Ft(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 Ft(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 Jt,CONNECT_DENIED_TOKEN as Qt,ConnectClient as Xt}from"@enbox/connect";var Te="/dweb-connect",se="enbox-connect-loaded",le="enbox-connect-request",ce="enbox-connect-response";function be(e,t,n){if(e.origin!==t||e.source!==n)return;let r=e.data;if(!(typeof r!="object"||r===null))return r}var Vt=3e5,Zt=500,en="enbox-dweb-connect",tn="width=500,height=700,menubar=no,toolbar=no,location=no,status=no";function nn(){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"}},F=class{constructor(t){this.requiresPin=!1;this._settled=!1;this._walletEpkReceived=!1;nn(),this._walletOrigin=new URL(t.walletUrl).origin,this._timeoutMs=t.timeoutMs??Vt;let n=new URL(Te,t.walletUrl).toString(),r=window.open(n,en,tn);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()},Zt)}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:le,jwe:t},this._walletOrigin)}async awaitResponse(){return await this._responsePromise}onMessage(t){let n=be(t,this._walletOrigin,this._popup);if(n!==void 0){if(n.type===se){this.onLoadedBeacon(n);return}n.type===ce&&this.onResponseMessage(n)}}onLoadedBeacon(t){if(this._settled||this._walletEpkReceived)return;let n;try{Jt(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?.(Qt)}}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 ye(){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 on(e){let t=new F({walletUrl:e.walletUrl,timeoutMs:e.timeout}),n=new Xt({transport:t});try{return await n.connect({appName:e.appName??globalThis.location.host,appIcon:e.appIcon,clientMetadata:ye(),permissionRequests:e.permissionRequests})}catch(r){if(r instanceof $)return;throw r}}var ft=[-1,10,16,26,18,24,16,18,22,22,26],mt=[-1,1,1,1,2,2,4,4,4,5,5],ht=[-1,26,44,70,100,134,172,196,242,292,346],rn=0,pt=10;function ut(e){return ht[e]-ft[e]*mt[e]}function De(e,t){let n=new TextEncoder().encode(e),r=0;for(let f=1;f<=pt;f++){let h=ut(f)*8;if(4+(f<=9?8:16)+n.length*8<=h){r=f;break}}if(r===0)throw new Error(`[@enbox/browser] QR payload too long (${n.length} bytes exceeds version ${pt}-M capacity).`);let o=[],i=(f,h)=>{for(let P=h-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=ut(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=an(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));dn(v,R,r),fn(v,R,p);let C=t??-1;if(C===-1){let f=1/0;for(let h=0;h<8;h++){We(v,R,h),Oe(v,R,h);let P=mn(v);P<f&&(f=P,C=h),We(v,R,h)}}return We(v,R,C),Oe(v,R,C),{size:u,modules:v,version:r,mask:C}}function an(e,t){let n=mt[t],r=ft[t],o=ht[t],i=n-o%n,s=Math.floor(o/n),a=[],d=[],p=sn(r),u=0;for(let f=0;f<n;f++){let h=s-r+(f<i?0:1),P=e.slice(u,u+h);u+=h,a.push(P),d.push(ln(P,p))}let v=new Uint8Array(o),R=0,C=s-r+1;for(let f=0;f<C;f++)for(let h=0;h<n;h++)f<a[h].length&&(v[R++]=a[h][f]);for(let f=0;f<r;f++)for(let h=0;h<n;h++)v[R++]=d[h][f];return v}function Ne(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 sn(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]=Ne(t[o],n),o+1<e&&(t[o]^=t[o+1]);n=Ne(n,2)}return t}function ln(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]^=Ne(t[i],o)}return n}var cn=[[],[],[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 dn(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);Se(e,t,3,3),Se(e,t,r-4,3),Se(e,t,3,r-4);let o=cn[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||pn(e,t,o[i],o[s]);Oe(e,t,0),T(e,t,8,r-8,!0),n>=7&&un(e,t,n)}function Se(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));T(e,t,a,d,p!==2&&p!==4)}}function pn(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 Oe(e,t,n){let r=e.length,o=rn<<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++)T(e,t,8,a,(s>>>a&1)!==0);T(e,t,8,7,(s>>>6&1)!==0),T(e,t,8,8,(s>>>7&1)!==0),T(e,t,7,8,(s>>>8&1)!==0);for(let a=9;a<15;a++)T(e,t,14-a,8,(s>>>a&1)!==0);for(let a=0;a<8;a++)T(e,t,r-1-a,8,(s>>>a&1)!==0);for(let a=8;a<15;a++)T(e,t,8,r-15+a,(s>>>a&1)!==0)}function un(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);T(e,t,d,p,a),T(e,t,p,d,a)}}function fn(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 We(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 mn(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((C,f)=>a[d+f]===C))return 0;let v=d>=4&&a.slice(d-4,d).every(C=>!C),R=d+11<=a.length&&a.slice(d+7,d+11).every(C=>!C);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 Le="http://www.w3.org/2000/svg";function Ae(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(Le,"svg");a.setAttribute("viewBox",`0 0 ${i} ${i}`),a.setAttribute("shape-rendering","crispEdges"),a.setAttribute("role","img");let d=document.createElementNS(Le,"rect");d.setAttribute("width",String(i)),d.setAttribute("height",String(i)),d.setAttribute("fill",r),a.appendChild(d);let p=document.createElementNS(Le,"path");return p.setAttribute("d",s),p.setAttribute("fill",n),a.appendChild(p),a}var gt="/.well-known/enbox-connect";async function xe(e){try{let t=new URL(gt,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 Ue(e){return await xe(e)!==void 0}import{DidJwk as hn}from"@enbox/dids";import{X25519 as gn}from"@enbox/crypto";import{CONNECT_DENIED_TOKEN as wn,openResponse as vn,randomToken as wt,RelayClientTransport as bn,sealRequest as yn}from"@enbox/connect";var qe=6,J=class extends Error{constructor(){super("[@enbox/browser] Relay connect cancelled."),this.name="RelayConnectCancelledError"}};async function Ie(e){let n=(e.createTransport??(h=>new bn(h)))({connectServerUrl:e.connectServerUrl,walletUri:e.walletUri,timeoutMs:e.timeoutMs,pollIntervalMs:e.pollIntervalMs,onClaimed:e.onClaimed}),r=await hn.create(),o=await gn.generateKey(),i={kty:"OKP",crv:"X25519",x:o.x},s=wt(),a=wt(),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 yn({request:p,signer:r,encryption:d.encryption}),v=await n.deliverRequest(u);v!==void 0&&e.onWalletUriReady(v);let C=await(e.cancelled===void 0?n.awaitResponse():Promise.race([n.awaitResponse(),e.cancelled]));if(C===wn)return;let f;for(let h=1;h<=qe;h++){let P=await(e.cancelled===void 0?e.requestPin(h,f):Promise.race([e.requestPin(h,f),e.cancelled]));try{let _=await vn({jwe:C,recipientPrivateKey:o,expected:{clientDid:r.uri,nonce:s,state:a},pin:P});if(_.delegatePortableDid===void 0)throw new Error("Connect: wallet response omitted `delegatePortableDid`.");return{delegatePortableDid:_.delegatePortableDid,delegateGrants:_.delegateGrants,connectedDid:_.providerDid,sessionRevocations:_.sessionRevocations}}catch(_){let S=_ instanceof Error?_:new Error(String(_));if(S.message.startsWith("Connect:"))throw S;f=S}}throw new Error(`[@enbox/browser] The pairing code did not match after ${qe} attempts.`)}var xt="enbox:connect:lastChoice",En=3e4,Cn=1e4,Ee=4,_n=4,vt=3,Be={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 Et(e){return(await xe(e))?.connectServerUrl}async function kn(e){let t=new F({walletUrl:e.walletUrl,timeoutMs:e.timeoutMs});return await new xn({transport:t}).connect({appName:e.appName,appIcon:e.appIcon,clientMetadata:ye(),permissionRequests:e.permissionRequests})}function Pn(){return typeof window>"u"?!1:(window.matchMedia?.("(pointer: coarse)").matches??!1)&&Math.min(window.innerWidth,window.innerHeight)<900}function Rn(){return{runRelay:Ie,runPopup:kn,discoverConnectServerUrl:Et,validateWalletUrl:Ue,isMobile:Pn,storage:typeof localStorage>"u"?void 0:localStorage}}function Mn(e){try{let t=e?.getItem(xt);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 Tn(e,t){try{e?.setItem(xt,JSON.stringify(t))}catch{}}function Sn(){let e,t={active:!0},n=new Promise((r,o)=>{e=()=>{t.active===!0&&(t.active=!1,o(new J))}});return n.catch(()=>{}),t.cancelled=n,t.cancel=e,t}function je(e){if(typeof window>"u"||typeof document>"u")throw new Error("[@enbox/browser] The connect modal is only available in browser environments.");let t={...Rn(),...e.deps},n=Ln(e.wallets??[]),r=e.rememberChoice??!0,o=e.appName??window.location.host,i=e.relayWalletPath??"/connect/app",s=t.isMobile(),a=r?Mn(t.storage):void 0,d=e.walletUrl!==void 0,p=e.walletUrl??(a!==void 0&&(d||Wn(n,a.walletUrl))?a.walletUrl:void 0)??n[0]?.url,u=e.preferredMethod??a?.method??"phone";return new Promise((v,R)=>{let C=document.createElement("div");C.id="enbox-connect-modal";let f=C.attachShadow({mode:"open"}),h=document.createElement("style");h.textContent=An,f.appendChild(h);let P=document.createElement("div");P.className="overlay";let _=document.createElement("div");_.className="modal",_.setAttribute("role","dialog"),_.setAttribute("aria-modal","true"),_.setAttribute("aria-label",`Connect to ${o}`);let S=e.theme??{},Q=S.appearance??"auto";Q!=="auto"&&_.setAttribute("data-appearance",Q);let Ce=window.matchMedia?.("(prefers-color-scheme: dark)"),_t=S.accent!==void 0||S.accentContrast!==void 0||S.light!==void 0||S.dark!==void 0,ze=()=>{let l=Q==="auto"?Ce?.matches===!0?"dark":"light":Q,c={accent:S.accent,accentContrast:S.accentContrast,...S[l]};for(let x of Object.keys(Be)){let w=c[x];typeof w=="string"&&w.trim()!==""?_.style.setProperty(Be[x],w):_.style.removeProperty(Be[x])}},$e=()=>ze();_t&&(ze(),Q==="auto"&&Ce?.addEventListener?.("change",$e));let D=!1,X,A,_e=!1,V,Ge=new Map,G=[],Ye=l=>n.find(c=>c.url===l)??{name:Nn(l)??l,url:l},kt=()=>{if(p===void 0){G=n.slice(0,vt);return}if(G.some(c=>c.url===p))return;let l=Ye(p);G=[l,...n.filter(c=>c.url!==l.url)].slice(0,vt)},pe=l=>{p=l,ee(),Z()},Pt=()=>{X?.cancel(),clearTimeout(A),document.removeEventListener("keydown",et),Ce?.removeEventListener?.("change",$e);try{document.body.removeChild(C)}catch{}},ue=l=>{D||(D=!0,Pt(),l())},Fe=l=>{r&&Tn(t.storage,{method:u,walletUrl:p??""}),St(),setTimeout(()=>ue(()=>v(l)),1200)},ke=()=>ue(()=>R(new Error("[@enbox/browser] Connect cancelled.")));_.appendChild(On(o,e.appIcon,ke));let U=document.createElement("div");U.className="stage",U.setAttribute("aria-live","polite"),_.appendChild(U);let q=document.createElement("div");q.className="footer",_.appendChild(q);let W=(...l)=>{U.replaceChildren(...l),U.classList.remove("fade-in"),U.offsetWidth,U.classList.add("fade-in")},Je=l=>{W(y("div","spinner"),y("p","stage-caption",l))},Rt=l=>{let c=p!==void 0?Ye(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(ae(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(Ae(De(l.walletUri),{dark:"#14141f",light:"transparent",quietZone:2})),c!==void 0){let b=y("div","qr-logo");b.appendChild(ae(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.`))},Mt=()=>{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."))},Tt=(l,c)=>new Promise(x=>{V=x;let w=document.createElement("div");w.className="pin-row",c!==void 0&&w.classList.add("shake");let b=[];for(let k=0;k<Ee;k++){let E=document.createElement("input");E.className="pin-input",E.type="text",E.inputMode="numeric",E.maxLength=1,E.setAttribute("aria-label",`Code digit ${k+1}`),b.push(E),w.appendChild(E)}let I=()=>{let k=b.map(E=>E.value).join("");if(k.length===Ee&&V!==void 0){let E=V;V=void 0,Je("Checking the code\u2026"),E(k)}};b.forEach((k,E)=>{k.addEventListener("input",()=>{k.value=k.value.replace(/\D/g,"").slice(0,1),k.value!==""&&E+1<b.length&&b[E+1].focus(),I()}),k.addEventListener("keydown",M=>{M.key==="Backspace"&&k.value===""&&E>0&&b[E-1].focus()}),k.addEventListener("paste",M=>{let B=(M.clipboardData?.getData("text")??"").replace(/\D/g,"").slice(0,Ee);B.length!==0&&(M.preventDefault(),B.split("").forEach((te,H)=>{b[H]!==void 0&&(b[H].value=te)}),b[Math.min(B.length,Ee)-1]?.focus(),I())})}),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()}),St=()=>{let l=y("div","check");l.textContent="\u2713",W(l,y("p","stage-caption","You\u2019re connected."))},Qe=()=>{W(y("p","stage-caption","No problem \u2014 nothing was shared."),de("Start over",()=>{Z()}),He("Close",()=>ue(()=>v(void 0))))},fe=(l,c)=>{W(y("p","stage-caption",l),de("Start over",()=>{Z()}),He("Close",()=>ue(()=>R(c??new Error(`[@enbox/browser] ${l}`)))))},Wt=()=>{W(y("p","stage-caption","This wallet can\u2019t connect by phone here."),y("p","stage-subline","You can continue in this browser instead."),de("Use this browser",()=>{me()}))},Lt=()=>{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."),de("Open wallet window",()=>{me()}))},Nt=()=>{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."))},Xe=l=>{W(y("p","stage-caption",l?"Your browser blocked the wallet window.":"The wallet window was closed."),de(l?"Open it now":"Reopen window",()=>{me()}),...s?[]:[He("Use your phone instead",()=>{Ze("phone")})])},Ot=async l=>{if(e.connectServerUrl!==void 0)return e.connectServerUrl;let c=Ge.get(l);return c===void 0&&(c=t.discoverConnectServerUrl(l),Ge.set(l,c)),c},Dt=l=>{clearTimeout(A);let c=Math.max(Cn,l*1e3-En);A=setTimeout(()=>{!D&&V===void 0&&u==="phone"&&Ve()},c)},Ve=async()=>{if(X?.cancel(),clearTimeout(A),p===void 0){fe("No wallet is configured.");return}u="phone",ee(),Je("Getting things ready\u2026");let l=new URL(p).origin,c=await Ot(l);if(c===void 0){Wt();return}let x=Sn();X=x;try{let w=await t.runRelay({connectServerUrl:c,walletUri:new URL(i,l).toString(),appName:o,appIcon:e.appIcon,clientMetadata:ye(),permissionRequests:e.permissionRequests,timeoutMs:e.timeout,cancelled:x.cancelled,onWalletUriReady:b=>{x.active&&!D&&(Rt(b),Dt(b.expiresIn))},onClaimed:()=>{x.active&&!D&&(clearTimeout(A),Mt())},requestPin:(b,I)=>(clearTimeout(A),Tt(b,I))});if(!x.active||D)return;w===void 0?Qe():Fe(w)}catch(w){if(!x.active||D||w instanceof J)return;let b=w instanceof Error?w:new Error(String(w));fe(/timed out/i.test(b.message)?"That took too long, so we stopped for safety.":"Something went wrong while connecting.",b)}},me=()=>{if(X?.cancel(),clearTimeout(A),p===void 0){fe("No wallet is configured.");return}if(_e)return;u="browser",ee();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);Xe(x);return}_e=!0,Nt(),l.then(c=>{D||(c===void 0?Qe():Fe(c))}).catch(c=>{if(D)return;if(c instanceof $){Xe(!1);return}let x=c instanceof Error?c:new Error(String(c));fe(/timed out/i.test(x.message)?"That took too long, so we stopped for safety.":"Something went wrong while connecting.",x)}).finally(()=>{_e=!1})},Z=async()=>{u==="browser"?(X?.cancel(),clearTimeout(A),ee(),Lt()):await Ve()},Ze=async l=>{u=l,await Z()},ee=()=>{if(q.replaceChildren(),!d){kt();let c=At();c.label!==void 0&&q.appendChild(c.label),q.appendChild(c.row),q.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",()=>{me()}),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",()=>{Ze("phone")}),l.appendChild(c)}l.childElementCount>0&&q.appendChild(l)},At=()=>{let l=document.createElement("div");l.className="wallet-row",l.setAttribute("role","radiogroup"),l.setAttribute("aria-label","Wallet");for(let m of G){let g=document.createElement("button");g.className="row-tile",g.title=m.description??m.name,g.setAttribute("role","radio");let L=m.url===p;g.setAttribute("aria-checked",L?"true":"false"),L&&g.classList.add("selected"),g.appendChild(ae(m)),g.appendChild(y("span","row-tile-name",m.name)),g.addEventListener("click",()=>{m.url!==p&&pe(m.url)}),l.appendChild(g)}let c=document.createElement("div");c.className="wallet-panel",c.hidden=!0;let x=n.filter(m=>!G.some(g=>g.url===m.url)),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.length>0?`+${x.length}`:"\u22EF")),w.appendChild(y("span","row-tile-name","More")),w.addEventListener("click",()=>{c.hidden=!c.hidden,w.setAttribute("aria-expanded",c.hidden?"false":"true"),c.hidden||te()}),l.appendChild(w);let b=G.length>0?y("div","wallet-row-label","Connecting with"):void 0,I=[],k=document.createElement("div");if(k.className="wallet-empty",k.textContent="No other wallets match your search.",k.hidden=!0,x.length>_n){let m=document.createElement("input");m.type="search",m.className="wallet-search",m.placeholder="Search wallets\u2026",m.setAttribute("aria-label","Search wallets"),m.addEventListener("input",()=>{let g=m.value.trim().toLowerCase(),L=0;for(let{wallet:nt,el:Ut}of I){let ot=g===""||nt.name.toLowerCase().includes(g)||nt.url.toLowerCase().includes(g);Ut.hidden=!ot,ot&&(L+=1)}k.hidden=L>0,te()}),c.appendChild(m)}let E=document.createElement("div");E.className="wallet-scroll-wrap",E.hidden=x.length===0;let M=document.createElement("div");M.className="wallet-scroll";let B=document.createElement("div");B.className="wallet-grid";let te=()=>{let m=M.scrollHeight-M.clientHeight>1,g=M.scrollTop+M.clientHeight>=M.scrollHeight-1;E.classList.toggle("scroll-hint",m&&!g)};M.addEventListener("scroll",te);for(let m of x){let g=document.createElement("button");g.className="wallet-tile",g.title=m.description??m.name,g.appendChild(ae(m));let L=document.createElement("span");L.className="wallet-tile-name",L.textContent=m.name,g.appendChild(L),g.addEventListener("click",()=>{pe(m.url)}),I.push({wallet:m,el:g}),B.appendChild(g)}M.appendChild(B),M.appendChild(k),E.appendChild(M),c.appendChild(E);let H=document.createElement("div");H.className="wallet-custom";let N=document.createElement("input");N.className="url-input",N.type="url",N.placeholder="https://your-wallet.example";let O=document.createElement("button");O.className="url-go",O.textContent="Use";let j=document.createElement("div");j.className="url-error",j.hidden=!0;let Pe=!1,tt=async()=>{let m=N.value.trim();if(m==="")return;let g;try{g=new URL(m.includes("://")?m:`https://${m}`).origin}catch{N.classList.add("invalid");return}if(Pe){pe(g);return}O.disabled=!0,O.textContent="Checking\u2026",j.hidden=!0;let L=await t.validateWalletUrl(g);if(O.disabled=!1,L){O.textContent="Use",pe(g);return}Pe=!0,O.textContent="Use anyway",N.classList.add("invalid"),j.textContent=`Couldn't verify a wallet at ${g}.`,j.hidden=!1};return N.addEventListener("input",()=>{Pe=!1,O.textContent="Use",N.classList.remove("invalid"),j.hidden=!0}),N.addEventListener("keydown",m=>{m.key==="Enter"&&tt()}),O.addEventListener("click",()=>{tt()}),H.appendChild(N),H.appendChild(O),c.appendChild(H),c.appendChild(j),{label:b,row:l,panel:c}};P.addEventListener("click",l=>{l.target===P&&ke()});let et=l=>{if(l.key==="Escape"){ke();return}l.key==="Tab"&&Dn(f,l)};document.addEventListener("keydown",et),P.appendChild(_),f.appendChild(P),document.body.appendChild(C),ee(),Z()})}function Wn(e,t){return e.some(n=>n.url===t)}function Ln(e){return e.filter((t,n)=>e.findIndex(r=>r.url===t.url)===n)}function Nn(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 de(e,t){let n=document.createElement("button");return n.className="stage-btn",n.textContent=e,n.addEventListener("click",t),n}function He(e,t){let n=document.createElement("button");return n.className="footer-link",n.textContent=e,n.addEventListener("click",t),n}function On(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 Dn(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 bt=`
|
|
155
155
|
--ec-bg: #ffffff;
|
|
156
156
|
--ec-surface: #f5f6f8;
|
|
157
157
|
--ec-text: #17171f;
|
|
@@ -160,7 +160,7 @@ import{Enbox as Eo,defineProtocol as Co,repository as _o}from"@enbox/api";import
|
|
|
160
160
|
--ec-accent: #0a62d0;
|
|
161
161
|
--ec-accent-contrast: #ffffff;
|
|
162
162
|
--ec-danger: #c0392b;
|
|
163
|
-
--ec-success: #1e9e5a;`,
|
|
163
|
+
--ec-success: #1e9e5a;`,yt=`
|
|
164
164
|
--ec-bg: #181822;
|
|
165
165
|
--ec-surface: #23232f;
|
|
166
166
|
--ec-text: #e9e9f0;
|
|
@@ -169,7 +169,7 @@ import{Enbox as Eo,defineProtocol as Co,repository as _o}from"@enbox/api";import
|
|
|
169
169
|
--ec-accent: #58a6ff;
|
|
170
170
|
--ec-accent-contrast: #0b1526;
|
|
171
171
|
--ec-danger: #ff7a7a;
|
|
172
|
-
--ec-success: #43d17c;`,
|
|
172
|
+
--ec-success: #43d17c;`,An=`
|
|
173
173
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
174
174
|
|
|
175
175
|
/* Keep the hidden attribute authoritative: author display values (e.g.
|
|
@@ -204,7 +204,7 @@ import{Enbox as Eo,defineProtocol as Co,repository as _o}from"@enbox/api";import
|
|
|
204
204
|
50% { transform: scale(1); opacity: 1; }
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
.modal {${
|
|
207
|
+
.modal {${bt}
|
|
208
208
|
--ec-accent-soft: color-mix(in srgb, var(--ec-accent) 14%, transparent);
|
|
209
209
|
background: var(--ec-bg);
|
|
210
210
|
color: var(--ec-text);
|
|
@@ -220,12 +220,12 @@ import{Enbox as Eo,defineProtocol as Co,repository as _o}from"@enbox/api";import
|
|
|
220
220
|
flex-direction: column;
|
|
221
221
|
}
|
|
222
222
|
@media (prefers-color-scheme: dark) {
|
|
223
|
-
.modal {${
|
|
223
|
+
.modal {${yt}
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
|
-
.modal[data-appearance='light'] {${
|
|
226
|
+
.modal[data-appearance='light'] {${bt}
|
|
227
227
|
}
|
|
228
|
-
.modal[data-appearance='dark'] {${
|
|
228
|
+
.modal[data-appearance='dark'] {${yt}
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
button, input { font-family: inherit; }
|
|
@@ -404,7 +404,7 @@ import{Enbox as Eo,defineProtocol as Co,repository as _o}from"@enbox/api";import
|
|
|
404
404
|
grid-template-columns: repeat(4, 1fr);
|
|
405
405
|
gap: 8px;
|
|
406
406
|
}
|
|
407
|
-
.row-tile {
|
|
407
|
+
.row-tile, .wallet-tile {
|
|
408
408
|
display: flex;
|
|
409
409
|
flex-direction: column;
|
|
410
410
|
align-items: center;
|
|
@@ -419,15 +419,15 @@ import{Enbox as Eo,defineProtocol as Co,repository as _o}from"@enbox/api";import
|
|
|
419
419
|
font-size: 11px;
|
|
420
420
|
cursor: pointer;
|
|
421
421
|
}
|
|
422
|
-
.row-tile:hover { border-color: var(--ec-accent); }
|
|
422
|
+
.row-tile:hover, .wallet-tile:hover { border-color: var(--ec-accent); }
|
|
423
423
|
.row-tile.selected {
|
|
424
424
|
border-color: var(--ec-accent);
|
|
425
425
|
background: var(--ec-accent-soft);
|
|
426
426
|
box-shadow: inset 0 0 0 1px var(--ec-accent);
|
|
427
427
|
}
|
|
428
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; }
|
|
429
|
+
.row-tile .wallet-icon, .wallet-tile .wallet-icon { width: 28px; height: 28px; }
|
|
430
|
+
.row-tile-name, .wallet-tile-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
431
431
|
|
|
432
432
|
.more-tile { color: var(--ec-muted); }
|
|
433
433
|
.more-tile:hover { color: var(--ec-text); }
|
|
@@ -453,46 +453,33 @@ import{Enbox as Eo,defineProtocol as Co,repository as _o}from"@enbox/api";import
|
|
|
453
453
|
}
|
|
454
454
|
.wallet-search:focus { outline: none; border-color: var(--ec-accent); }
|
|
455
455
|
|
|
456
|
-
|
|
456
|
+
/* Cap the grid at three rows of tiles; past that it scrolls in place,
|
|
457
|
+
and the wrapper's bottom fade hints that more wallets are below. */
|
|
458
|
+
.wallet-scroll-wrap { position: relative; }
|
|
459
|
+
.wallet-scroll { max-height: 220px; overflow-y: auto; }
|
|
460
|
+
.wallet-scroll-wrap.scroll-hint::after {
|
|
461
|
+
content: '';
|
|
462
|
+
position: absolute;
|
|
463
|
+
left: 0;
|
|
464
|
+
right: 0;
|
|
465
|
+
bottom: 0;
|
|
466
|
+
height: 28px;
|
|
467
|
+
background: linear-gradient(to bottom, transparent, var(--ec-bg));
|
|
468
|
+
pointer-events: none;
|
|
469
|
+
}
|
|
457
470
|
.wallet-grid {
|
|
458
471
|
display: grid;
|
|
459
|
-
grid-template-columns: repeat(
|
|
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;
|
|
472
|
+
grid-template-columns: repeat(4, 1fr);
|
|
468
473
|
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;
|
|
476
|
-
cursor: pointer;
|
|
477
|
-
}
|
|
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
474
|
}
|
|
484
|
-
.wallet-tile-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
485
475
|
|
|
486
476
|
.wallet-icon { position: relative; width: 28px; height: 28px; flex-shrink: 0; display: inline-flex; }
|
|
487
|
-
.wallet-tile .wallet-icon { width: 40px; height: 40px; }
|
|
488
477
|
.wallet-badge {
|
|
489
478
|
width: 100%; height: 100%; border-radius: 8px; display: inline-flex;
|
|
490
479
|
align-items: center; justify-content: center; font-size: 13px;
|
|
491
480
|
font-weight: 600; background: var(--ec-accent-soft); color: var(--ec-accent);
|
|
492
481
|
}
|
|
493
|
-
.wallet-tile .wallet-badge { border-radius: 10px; font-size: 17px; }
|
|
494
482
|
.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
483
|
|
|
497
484
|
.wallet-empty { padding: 10px 4px; font-size: 12px; color: var(--ec-muted); text-align: center; }
|
|
498
485
|
|
|
@@ -524,5 +511,5 @@ import{Enbox as Eo,defineProtocol as Co,repository as _o}from"@enbox/api";import
|
|
|
524
511
|
.overlay, .modal, .stage.fade-in > *, .pin-row.shake { animation: none; }
|
|
525
512
|
.claimed-pulse::after { animation: none; }
|
|
526
513
|
}
|
|
527
|
-
`;var
|
|
514
|
+
`;var Ct=[{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"},{name:"Taffy",url:"https://taffy-wallet.pages.dev",description:"A playful take on your digital identity"},{name:"Astoria",url:"https://astoria-wallet.pages.dev",description:"A grand home for your digital identity"}];function Un(e={}){let{wallets:t=Ct,walletUrl:n,timeout:r,appName:o,appIcon:i,preferredMethod:s,rememberChoice:a,connectServerUrl:d,relayWalletPath:p,theme:u}=e;return{async requestAccess(v){return je({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 qn}from"@enbox/crypto";import{CONNECT_DENIED_TOKEN as In,ConnectProvider as Bn}from"@enbox/connect";var Hn=3e5,Ke=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=jn(t.dappOrigin),o=await qn.generateKey(),i={kty:"OKP",crv:"X25519",x:o.x},s=new e({dappOrigin:r,dappWindow:n,recipientPrivateKey:o,timeoutMs:t.timeoutMs??Hn});return n.postMessage({type:se,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:ce,payload:t},this._dappOrigin),this.close()}deny(){this.sendResponse(In)}close(){clearTimeout(this._timeoutId),this._messageListener!==void 0&&(window.removeEventListener("message",this._messageListener),this._messageListener=void 0)}onMessage(t){let n=be(t,this._dappOrigin,this._dappWindow);if(n!==void 0&&!(n.type!==le||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 Bn.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 jn(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 $o}from"@enbox/api";import{BrowserStorage as Yo}from"@enbox/auth/browser";import{DwnInterface as Jo}from"@enbox/agent";import{DateSort as Xo,DwnInterfaceName as Vo,DwnMethodName as Zo}from"@enbox/dwn-sdk-js";export{Mo as AuthManager,To as AuthSession,Un as BrowserConnectHandler,Yo as BrowserStorage,No as CONNECT_DENIED_TOKEN,Oo as ConnectProvider,Ct as DEFAULT_WALLETS,se as DWEB_CONNECT_LOADED_MESSAGE_TYPE,Te as DWEB_CONNECT_PATH,le as DWEB_CONNECT_REQUEST_MESSAGE_TYPE,ce as DWEB_CONNECT_RESPONSE_MESSAGE_TYPE,Xo as DateSort,Jo as DwnInterface,Vo as DwnInterfaceName,Zo as DwnMethodName,_o as Enbox,qe as MAX_PIN_ATTEMPTS,F as PopupClientTransport,$ as PopupWindowClosedError,J as RelayConnectCancelledError,$o as TypedRecord,gt as WALLET_WELL_KNOWN_PATH,Wo as WalletConnect,Ke as WalletPostMessageTransport,Gn as activatePolyfills,jt as cacheResponse,Fn as clearDrlCache,on as connectViaPopup,Yn as deactivatePolyfills,ko as defineProtocol,Et as discoverWalletConnectServerUrl,De as encodeQr,Ht as fetchResource,xe as fetchWalletWellKnown,lt as getDwnEndpoints,Bt as handleEvent,So as normalizeProtocolRequests,ne as parseDrlUrl,Ue as probeWalletWellKnown,Ae as qrToSvg,Po as repository,je as runConnectModal,Ie as runRelayConnect};
|
|
528
515
|
//# sourceMappingURL=browser.mjs.map
|