@enbox/browser 0.3.46 → 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 +93 -16
- package/dist/browser.mjs.map +3 -3
- package/dist/esm/ui/connect-modal.js +185 -40
- package/dist/esm/ui/connect-modal.js.map +1 -1
- package/dist/types/ui/connect-modal.d.ts +4 -3
- package/dist/types/ui/connect-modal.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ui/connect-modal.ts +197 -43
package/dist/browser.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Enbox as
|
|
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 ho,defineProtocol as go,repository as wo}from"@enbox/api";import
|
|
|
103
103
|
opacity: 0;
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
`,
|
|
106
|
+
`,Ht=`
|
|
107
107
|
<!DOCTYPE html>
|
|
108
108
|
<html lang='en'>
|
|
109
109
|
<head>
|
|
@@ -119,7 +119,7 @@ import{Enbox as ho,defineProtocol as go,repository as wo}from"@enbox/api";import
|
|
|
119
119
|
font-family: Arial, sans-serif;
|
|
120
120
|
text-align: center;
|
|
121
121
|
}
|
|
122
|
-
${
|
|
122
|
+
${lt}
|
|
123
123
|
</style>
|
|
124
124
|
</head>
|
|
125
125
|
<body>
|
|
@@ -132,8 +132,8 @@ import{Enbox as ho,defineProtocol as go,repository as wo}from"@enbox/api";import
|
|
|
132
132
|
</div>
|
|
133
133
|
</body>
|
|
134
134
|
</html>
|
|
135
|
-
`,
|
|
136
|
-
${
|
|
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,13 +145,13 @@ import{Enbox as ho,defineProtocol as go,repository as wo}from"@enbox/api";import
|
|
|
145
145
|
opacity: 1;
|
|
146
146
|
pointer-events: all;
|
|
147
147
|
}
|
|
148
|
-
`,document.head.append(
|
|
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
|
-
`,I.lastElementChild.addEventListener("click",Ee),document.body.prepend(I),pe=!0)}function Ut(){pe&&(Z?.remove(),Z=null,I?.remove(),I=null,pe=!1)}function Ee(){document.documentElement.removeAttribute("drl-link-loading"),ce=null}var ce=null,ue=!1,ee=null,te=null;function qt(){ue||(ee=async e=>{let t=e.target?.closest("a");if(t){let n=t.href,r=V(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(At)):(ce=i,setTimeout(()=>document.documentElement.setAttribute("drl-link-loading",""),50));let l=await tt(o);if(!l.length)throw new Error("no valid DWN endpoints found");let p=`${l[0].replace(de,"")}/${o}/${i}`;s?a&&!a.closed&&(a.location.href=p):ce===i&&(window.location.href=p)}catch{throw ce===i&&Ee(),new Error(`DID endpoint resolution failed for the DRL: ${n}`)}}}},te=async e=>{let t=e.composedPath()[0];if(e.pointerType==="mouse"&&e.button===2||e.pointerType==="touch"&&e.isPrimary){if($(),t?.src&&V(t.src)){B=t,t.__src__=t.src;let n=t.src.replace(Ze,"https:").replace(de,""),o=await(await nt())?.match(n);if(o){let i=o.headers.get("dwn-composed-url");i&&(t.src=i)}t.addEventListener("pointerup",$,{once:!0})}}else t===B&&$()},document.addEventListener("click",ee),document.addEventListener("pointercancel",$),document.addEventListener("pointerdown",te),ue=!0)}function It(){ue&&(ee&&(document.removeEventListener("click",ee),ee=null),te&&(document.removeEventListener("pointerdown",te),te=null),document.removeEventListener("pointercancel",$),$(),Ee(),ue=!1)}var B=null;async function $(e){e?.type==="pointerup"&&await new Promise(t=>requestAnimationFrame(()=>t())),B&&(B.src=B.__src__,delete B.__src__,B=null)}function Un(e={}){e.didResolvers&&(ye=new Ve({didResolvers:e.didResolvers})),e.serviceWorker!==!1&&Dt(e),typeof window<"u"&&typeof window.document<"u"&&(e.injectStyles!==!1&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Xe,{once:!0}):Xe()),e.links!==!1&&qt())}function qn(){typeof window<"u"&&typeof window.document<"u"&&(It(),Ut())}async function In(){return typeof caches>"u"?!1:caches.delete(et)}import{ConnectClient as fn}from"@enbox/connect";function rt(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=Bt(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 Bt(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 Ht,CONNECT_DENIED_TOKEN as jt,ConnectClient as Kt}from"@enbox/connect";var xe="/dweb-connect",ne="enbox-connect-loaded",oe="enbox-connect-request",re="enbox-connect-response";function fe(e,t,n){if(e.origin!==t||e.source!==n)return;let r=e.data;if(!(typeof r!="object"||r===null))return r}var zt=3e5,$t=500,Gt="enbox-dweb-connect",Yt="width=500,height=700,menubar=no,toolbar=no,location=no,status=no";function Ft(){if(typeof window>"u")throw new Error("[@enbox/browser] DWeb Connect is only available in browser environments.")}var H=class extends Error{constructor(){super("[@enbox/browser] Wallet popup was closed before the wallet finished loading."),this.name="PopupWindowClosedError"}},G=class{constructor(t){this.requiresPin=!1;this._settled=!1;this._walletEpkReceived=!1;Ft(),this._walletOrigin=new URL(t.walletUrl).origin,this._timeoutMs=t.timeoutMs??zt;let n=new URL(xe,t.walletUrl).toString(),r=window.open(n,Gt,Yt);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()},$t)}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:oe,jwe:t},this._walletOrigin)}async awaitResponse(){return await this._responsePromise}onMessage(t){let n=fe(t,this._walletOrigin,this._popup);if(n!==void 0){if(n.type===ne){this.onLoadedBeacon(n);return}n.type===re&&this.onResponseMessage(n)}}onLoadedBeacon(t){if(this._settled||this._walletEpkReceived)return;let n;try{Ht(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 H);return}this._settled=!0,this.cleanup(),this._resolveResponse?.(jt)}}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 me(){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 Jt(e){let t=new G({walletUrl:e.walletUrl,timeoutMs:e.timeout}),n=new Kt({transport:t});try{return await n.connect({appName:e.appName??globalThis.location.host,appIcon:e.appIcon,clientMetadata:me(),permissionRequests:e.permissionRequests})}catch(r){if(r instanceof H)return;throw r}}var st=[-1,10,16,26,18,24,16,18,22,22,26],lt=[-1,1,1,1,2,2,4,4,4,5,5],ct=[-1,26,44,70,100,134,172,196,242,292,346],Qt=0,it=10;function at(e){return ct[e]-st[e]*lt[e]}function Me(e,t){let n=new TextEncoder().encode(e),r=0;for(let f=1;f<=it;f++){let h=at(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 ${it}-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=at(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 l=new Uint8Array(s/8);for(let f=0;f<o.length;f++)l[f>>3]|=o[f]<<7-(f&7);let p=Xt(l,r),c=17+4*r,g=Array.from({length:c},()=>new Array(c).fill(!1)),R=Array.from({length:c},()=>new Array(c).fill(!1));tn(g,R,r),rn(g,R,p);let y=t??-1;if(y===-1){let f=1/0;for(let h=0;h<8;h++){_e(g,R,h),Re(g,R,h);let P=an(g);P<f&&(f=P,y=h),_e(g,R,h)}}return _e(g,R,y),Re(g,R,y),{size:c,modules:g,version:r,mask:y}}function Xt(e,t){let n=lt[t],r=st[t],o=ct[t],i=n-o%n,s=Math.floor(o/n),a=[],l=[],p=Vt(r),c=0;for(let f=0;f<n;f++){let h=s-r+(f<i?0:1),P=e.slice(c,c+h);c+=h,a.push(P),l.push(Zt(P,p))}let g=new Uint8Array(o),R=0,y=s-r+1;for(let f=0;f<y;f++)for(let h=0;h<n;h++)f<a[h].length&&(g[R++]=a[h][f]);for(let f=0;f<r;f++)for(let h=0;h<n;h++)g[R++]=l[h][f];return g}function ke(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 Vt(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]=ke(t[o],n),o+1<e&&(t[o]^=t[o+1]);n=ke(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]^=ke(t[i],o)}return n}var en=[[],[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50]];function S(e,t,n,r,o){e[r][n]=o,t[r][n]=!0}function tn(e,t,n){let r=e.length;for(let i=0;i<r;i++)S(e,t,6,i,i%2===0),S(e,t,i,6,i%2===0);Ce(e,t,3,3),Ce(e,t,r-4,3),Ce(e,t,3,r-4);let o=en[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||nn(e,t,o[i],o[s]);Re(e,t,0),S(e,t,8,r-8,!0),n>=7&&on(e,t,n)}function Ce(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,l=r+i;if(a<0||a>=o||l<0||l>=o)continue;let p=Math.max(Math.abs(s),Math.abs(i));S(e,t,a,l,p!==2&&p!==4)}}function nn(e,t,n,r){for(let o=-2;o<=2;o++)for(let i=-2;i<=2;i++)S(e,t,n+i,r+o,Math.max(Math.abs(i),Math.abs(o))!==1)}function Re(e,t,n){let r=e.length,o=Qt<<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++)S(e,t,8,a,(s>>>a&1)!==0);S(e,t,8,7,(s>>>6&1)!==0),S(e,t,8,8,(s>>>7&1)!==0),S(e,t,7,8,(s>>>8&1)!==0);for(let a=9;a<15;a++)S(e,t,14-a,8,(s>>>a&1)!==0);for(let a=0;a<8;a++)S(e,t,r-1-a,8,(s>>>a&1)!==0);for(let a=8;a<15;a++)S(e,t,8,r-15+a,(s>>>a&1)!==0)}function on(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,l=r-11+s%3,p=Math.floor(s/3);S(e,t,l,p,a),S(e,t,p,l,a)}}function rn(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 l=i-a,c=(i+1&2)===0?r-1-s:s;!t[c][l]&&o<n.length*8&&(e[c][l]=(n[o>>3]>>>7-(o&7)&1)!==0,o++)}}}function _e(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 an(e){let t=e.length,n=0;for(let a=0;a<t;a++){let l=!1,p=0;for(let c=0;c<t;c++)c===0||e[a][c]!==l?(l=e[a][c],p=1):(p++,p===5?n+=3:p>5&&(n+=1))}for(let a=0;a<t;a++){let l=!1,p=0;for(let c=0;c<t;c++)c===0||e[c][a]!==l?(l=e[c][a],p=1):(p++,p===5?n+=3:p>5&&(n+=1))}for(let a=0;a<t-1;a++)for(let l=0;l<t-1;l++){let p=e[a][l];p===e[a][l+1]&&p===e[a+1][l]&&p===e[a+1][l+1]&&(n+=3)}let r=(a,l)=>{if(![!0,!1,!0,!0,!0,!1,!0].every((y,f)=>a[l+f]===y))return 0;let g=l>=4&&a.slice(l-4,l).every(y=>!y),R=l+11<=a.length&&a.slice(l+7,l+11).every(y=>!y);return(g?40:0)+(R?40:0)};for(let a=0;a<t;a++){let l=e[a],p=e.map(c=>c[a]);for(let c=0;c+7<=t;c++)n+=r(l,c),n+=r(p,c)}let o=0;for(let a of e)for(let l of a)l&&o++;let i=t*t,s=Math.ceil(Math.abs(o*20-i*10)/i)-1;return n+=s*10,n}var Pe="http://www.w3.org/2000/svg";function Te(e,t={}){let n=t.dark??"#000000",r=t.light??"#ffffff",o=t.quietZone??2,i=e.size+o*2,s="";for(let c=0;c<e.size;c++)for(let g=0;g<e.size;g++)e.modules[c][g]&&(s+=`M${g+o} ${c+o}h1v1h-1z`);let a=document.createElementNS(Pe,"svg");a.setAttribute("viewBox",`0 0 ${i} ${i}`),a.setAttribute("shape-rendering","crispEdges"),a.setAttribute("role","img");let l=document.createElementNS(Pe,"rect");l.setAttribute("width",String(i)),l.setAttribute("height",String(i)),l.setAttribute("fill",r),a.appendChild(l);let p=document.createElementNS(Pe,"path");return p.setAttribute("d",s),p.setAttribute("fill",n),a.appendChild(p),a}var dt="/.well-known/enbox-connect";async function he(e){try{let t=new URL(dt,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 Se(e){return await he(e)!==void 0}import{DidJwk as sn}from"@enbox/dids";import{X25519 as ln}from"@enbox/crypto";import{CONNECT_DENIED_TOKEN as cn,openResponse as dn,randomToken as pt,RelayClientTransport as pn,sealRequest as un}from"@enbox/connect";var Le=6,Y=class extends Error{constructor(){super("[@enbox/browser] Relay connect cancelled."),this.name="RelayConnectCancelledError"}};async function Ne(e){let n=(e.createTransport??(h=>new pn(h)))({connectServerUrl:e.connectServerUrl,walletUri:e.walletUri,timeoutMs:e.timeoutMs,pollIntervalMs:e.pollIntervalMs,onClaimed:e.onClaimed}),r=await sn.create(),o=await ln.generateKey(),i={kty:"OKP",crv:"X25519",x:o.x},s=pt(),a=pt(),l=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:l.reply},c=await un({request:p,signer:r,encryption:l.encryption}),g=await n.deliverRequest(c);g!==void 0&&e.onWalletUriReady(g);let y=await(e.cancelled===void 0?n.awaitResponse():Promise.race([n.awaitResponse(),e.cancelled]));if(y===cn)return;let f;for(let h=1;h<=Le;h++){let P=await(e.cancelled===void 0?e.requestPin(h,f):Promise.race([e.requestPin(h,f),e.cancelled]));try{let E=await dn({jwe:y,recipientPrivateKey:o,expected:{clientDid:r.uri,nonce:s,state:a},pin:P});if(E.delegatePortableDid===void 0)throw new Error("Connect: wallet response omitted `delegatePortableDid`.");return{delegatePortableDid:E.delegatePortableDid,delegateGrants:E.delegateGrants,connectedDid:E.providerDid,sessionRevocations:E.sessionRevocations}}catch(E){let L=E instanceof Error?E:new Error(String(E));if(L.message.startsWith("Connect:"))throw L;f=L}}throw new Error(`[@enbox/browser] The pairing code did not match after ${Le} attempts.`)}var mt="enbox:connect:lastChoice",mn=3e4,hn=1e4,ge=4,gn=4,We={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 ht(e){return(await he(e))?.connectServerUrl}async function wn(e){let t=new G({walletUrl:e.walletUrl,timeoutMs:e.timeoutMs});return await new fn({transport:t}).connect({appName:e.appName,appIcon:e.appIcon,clientMetadata:me(),permissionRequests:e.permissionRequests})}function vn(){return typeof window>"u"?!1:(window.matchMedia?.("(pointer: coarse)").matches??!1)&&Math.min(window.innerWidth,window.innerHeight)<900}function bn(){return{runRelay:Ne,runPopup:wn,discoverConnectServerUrl:ht,validateWalletUrl:Se,isMobile:vn,storage:typeof localStorage>"u"?void 0:localStorage}}function yn(e){try{let t=e?.getItem(mt);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 En(e,t){try{e?.setItem(mt,JSON.stringify(t))}catch{}}function xn(){let e,t={active:!0},n=new Promise((r,o)=>{e=()=>{t.active===!0&&(t.active=!1,o(new Y))}});return n.catch(()=>{}),t.cancelled=n,t.cancel=e,t}function De(e){if(typeof window>"u"||typeof document>"u")throw new Error("[@enbox/browser] The connect modal is only available in browser environments.");let t={...bn(),...e.deps},n=e.wallets??[],r=e.rememberChoice??!0,o=e.appName??window.location.host,i=e.relayWalletPath??"/connect/app",s=t.isMobile(),a=r?yn(t.storage):void 0,l=e.walletUrl!==void 0,p=e.walletUrl??(a!==void 0&&(l||Cn(n,a.walletUrl))?a.walletUrl:void 0)??n[0]?.url,c=e.preferredMethod??a?.method??"phone";return new Promise((g,R)=>{let y=document.createElement("div");y.id="enbox-connect-modal";let f=y.attachShadow({mode:"open"}),h=document.createElement("style");h.textContent=Rn,f.appendChild(h);let P=document.createElement("div");P.className="overlay";let E=document.createElement("div");E.className="modal",E.setAttribute("role","dialog"),E.setAttribute("aria-modal","true"),E.setAttribute("aria-label",`Connect to ${o}`);let L=e.theme??{},F=L.appearance??"auto";F!=="auto"&&E.setAttribute("data-appearance",F);let we=window.matchMedia?.("(prefers-color-scheme: dark)"),wt=L.accent!==void 0||L.accentContrast!==void 0||L.light!==void 0||L.dark!==void 0,Ue=()=>{let d=F==="auto"?we?.matches===!0?"dark":"light":F,m={accent:L.accent,accentContrast:L.accentContrast,...L[d]};for(let u of Object.keys(We)){let C=m[u];typeof C=="string"&&C.trim()!==""?E.style.setProperty(We[u],C):E.style.removeProperty(We[u])}},qe=()=>Ue();wt&&(Ue(),F==="auto"&&we?.addEventListener?.("change",qe));let W=!1,J,A,ve=!1,Q,Ie=new Map,vt=()=>{J?.cancel(),clearTimeout(A),document.removeEventListener("keydown",Ge),we?.removeEventListener?.("change",qe);try{document.body.removeChild(y)}catch{}},ae=d=>{W||(W=!0,vt(),d())},Be=d=>{r&&En(t.storage,{method:c,walletUrl:p??""}),xt(),setTimeout(()=>ae(()=>g(d)),1200)},be=()=>ae(()=>R(new Error("[@enbox/browser] Connect cancelled.")));E.appendChild(Pn(o,e.appIcon,be));let q=document.createElement("div");q.className="stage",q.setAttribute("aria-live","polite"),E.appendChild(q);let X=document.createElement("div");X.className="footer",E.appendChild(X);let N=(...d)=>{q.replaceChildren(...d),q.classList.remove("fade-in"),q.offsetWidth,q.classList.add("fade-in")},He=d=>{N(b("div","spinner"),b("p","stage-caption",d))},bt=d=>{if(s){let u=document.createElement("a");u.className="deep-link",u.href=d.walletUri,u.textContent="Continue in your wallet",N(u,b("p","stage-caption","Your wallet opens to approve this connection."),b("p","stage-subline","Come back here when you\u2019re done."));return}let m=document.createElement("div");m.className="qr-box",m.replaceChildren(Te(Me(d.walletUri),{dark:"#14141f",light:"transparent",quietZone:2})),N(m,b("p","stage-caption","Scan with your phone\u2019s camera"),b("p","stage-subline","Your wallet stays on your phone."))},yt=()=>{let d=document.createElement("div");d.className="claimed-pulse",N(d,b("p","stage-caption","Phone connected \u2014 finish there"),b("p","stage-subline","Approve the request on your phone, then come back here."))},Et=(d,m)=>new Promise(u=>{Q=u;let C=document.createElement("div");C.className="pin-row",m!==void 0&&C.classList.add("shake");let v=[];for(let k=0;k<ge;k++){let x=document.createElement("input");x.className="pin-input",x.type="text",x.inputMode="numeric",x.maxLength=1,x.setAttribute("aria-label",`Code digit ${k+1}`),v.push(x),C.appendChild(x)}let O=()=>{let k=v.map(x=>x.value).join("");if(k.length===ge&&Q!==void 0){let x=Q;Q=void 0,He("Checking the code\u2026"),x(k)}};v.forEach((k,x)=>{k.addEventListener("input",()=>{k.value=k.value.replace(/\D/g,"").slice(0,1),k.value!==""&&x+1<v.length&&v[x+1].focus(),O()}),k.addEventListener("keydown",M=>{M.key==="Backspace"&&k.value===""&&x>0&&v[x-1].focus()}),k.addEventListener("paste",M=>{let T=(M.clipboardData?.getData("text")??"").replace(/\D/g,"").slice(0,ge);T.length!==0&&(M.preventDefault(),T.split("").forEach((D,z)=>{v[z]!==void 0&&(v[z].value=D)}),v[Math.min(T.length,ge)-1]?.focus(),O())})}),N(b("p","stage-caption","Enter the code shown on your phone"),C,...m!==void 0?[b("p","stage-error","That code doesn\u2019t match \u2014 check your phone.")]:[b("p","stage-subline",d===1?"Phone connected.":"")]),v[0].focus()}),xt=()=>{let d=b("div","check");d.textContent="\u2713",N(d,b("p","stage-caption","You\u2019re connected."))},je=()=>{N(b("p","stage-caption","No problem \u2014 nothing was shared."),ie("Start over",()=>{j()}),Oe("Close",()=>ae(()=>g(void 0))))},se=(d,m)=>{N(b("p","stage-caption",d),ie("Start over",()=>{j()}),Oe("Close",()=>ae(()=>R(m??new Error(`[@enbox/browser] ${d}`)))))},Ct=()=>{N(b("p","stage-caption","This wallet can\u2019t connect by phone here."),b("p","stage-subline","You can continue in this browser instead."),ie("Use this browser",()=>{le()}))},_t=()=>{N(b("p","stage-caption","Connect with a wallet in this browser"),b("p","stage-subline","Your wallet opens in a small window to approve this connection."),ie("Open wallet window",()=>{le()}))},Pt=()=>{N(b("div","spinner"),b("p","stage-caption","Finish in the wallet window"),b("p","stage-subline","We\u2019ll wrap up here as soon as you\u2019re done."))},Ke=d=>{N(b("p","stage-caption",d?"Your browser blocked the wallet window.":"The wallet window was closed."),ie(d?"Open it now":"Reopen window",()=>{le()}),...s?[]:[Oe("Use your phone instead",()=>{$e("phone")})])},kt=async d=>{if(e.connectServerUrl!==void 0)return e.connectServerUrl;let m=Ie.get(d);return m===void 0&&(m=t.discoverConnectServerUrl(d),Ie.set(d,m)),m},Rt=d=>{clearTimeout(A);let m=Math.max(hn,d*1e3-mn);A=setTimeout(()=>{!W&&Q===void 0&&c==="phone"&&ze()},m)},ze=async()=>{if(J?.cancel(),clearTimeout(A),p===void 0){se("No wallet is configured.");return}c="phone",K(),He("Getting things ready\u2026");let d=new URL(p).origin,m=await kt(d);if(m===void 0){Ct();return}let u=xn();J=u;try{let C=await t.runRelay({connectServerUrl:m,walletUri:new URL(i,d).toString(),appName:o,appIcon:e.appIcon,clientMetadata:me(),permissionRequests:e.permissionRequests,timeoutMs:e.timeout,cancelled:u.cancelled,onWalletUriReady:v=>{u.active&&!W&&(bt(v),Rt(v.expiresIn))},onClaimed:()=>{u.active&&!W&&(clearTimeout(A),yt())},requestPin:(v,O)=>(clearTimeout(A),Et(v,O))});if(!u.active||W)return;C===void 0?je():Be(C)}catch(C){if(!u.active||W||C instanceof Y)return;let v=C instanceof Error?C:new Error(String(C));se(/timed out/i.test(v.message)?"That took too long, so we stopped for safety.":"Something went wrong while connecting.",v)}},le=()=>{if(J?.cancel(),clearTimeout(A),p===void 0){se("No wallet is configured.");return}if(ve)return;c="browser",K();let d;try{d=t.runPopup({walletUrl:p,permissionRequests:e.permissionRequests,appName:o,appIcon:e.appIcon,timeoutMs:e.timeout})}catch(m){let u=m instanceof Error&&/popup blocked/i.test(m.message);Ke(u);return}ve=!0,Pt(),d.then(m=>{W||(m===void 0?je():Be(m))}).catch(m=>{if(W)return;if(m instanceof H){Ke(!1);return}let u=m instanceof Error?m:new Error(String(m));se(/timed out/i.test(u.message)?"That took too long, so we stopped for safety.":"Something went wrong while connecting.",u)}).finally(()=>{ve=!1})},j=async()=>{c==="browser"?(J?.cancel(),clearTimeout(A),K(),_t()):await ze()},$e=async d=>{c=d,await j()},K=()=>{X.replaceChildren();let d=document.createElement("div");if(d.className="footer-row",c==="phone"){let u=document.createElement("button");u.className="footer-link method-link",u.textContent="No phone? Use this browser \u2192",u.addEventListener("click",()=>{le()}),d.appendChild(u)}else if(!s){let u=document.createElement("button");u.className="footer-link method-link",u.textContent="Use your phone instead \u2192",u.addEventListener("click",()=>{$e("phone")}),d.appendChild(u)}let m;if(!l&&n.length>0){let u=Mt();d.appendChild(u.toggle),m=u.panel}d.childElementCount>0&&X.appendChild(d),m!==void 0&&X.appendChild(m)},Mt=()=>{let d=n.find(w=>w.url===p),m=document.createElement("button");m.className="footer-link wallet-toggle",m.setAttribute("aria-expanded","false"),m.textContent=`Wallet: ${d?.name??_n(p)??"Choose"} \u25BE`;let u=document.createElement("div");u.className="wallet-panel",u.hidden=!0;let C=[],v=document.createElement("div");if(v.className="wallet-empty",v.textContent="No wallets match your search.",v.hidden=!0,n.length>gn){let w=document.createElement("input");w.type="search",w.className="wallet-search",w.placeholder="Search wallets\u2026",w.setAttribute("aria-label","Search wallets"),w.addEventListener("input",()=>{let _=w.value.trim().toLowerCase(),U=0;for(let{wallet:Je,el:Tt}of C){let Qe=_===""||Je.name.toLowerCase().includes(_)||Je.url.toLowerCase().includes(_);Tt.hidden=!Qe,Qe&&(U+=1)}v.hidden=U>0}),u.appendChild(w)}let O=document.createElement("div");O.className="wallet-scroll";let k=document.createElement("div");k.className="wallet-grid";for(let w of n){let _=document.createElement("button");_.className="wallet-tile",_.title=w.name,_.appendChild(rt(w));let U=document.createElement("span");U.className="wallet-tile-name",U.textContent=w.name,_.appendChild(U),w.url===p&&(_.classList.add("selected"),_.setAttribute("aria-pressed","true")),_.addEventListener("click",()=>{p=w.url,K(),j()}),C.push({wallet:w,el:_}),k.appendChild(_)}O.appendChild(k),O.appendChild(v),u.appendChild(O);let x=document.createElement("div");x.className="wallet-custom";let M=document.createElement("input");M.className="url-input",M.type="url",M.placeholder="https://your-wallet.example";let T=document.createElement("button");T.className="url-go",T.textContent="Use";let D=document.createElement("div");D.className="url-error",D.hidden=!0;let z=!1,Ye=w=>{p=w,K(),j()},Fe=async()=>{let w=M.value.trim();if(w==="")return;let _;try{_=new URL(w.includes("://")?w:`https://${w}`).origin}catch{M.classList.add("invalid");return}if(z){Ye(_);return}T.disabled=!0,T.textContent="Checking\u2026",D.hidden=!0;let U=await t.validateWalletUrl(_);if(T.disabled=!1,U){T.textContent="Use",Ye(_);return}z=!0,T.textContent="Use anyway",M.classList.add("invalid"),D.textContent=`Couldn't verify a wallet at ${_}.`,D.hidden=!1};return M.addEventListener("input",()=>{z=!1,T.textContent="Use",M.classList.remove("invalid"),D.hidden=!0}),M.addEventListener("keydown",w=>{w.key==="Enter"&&Fe()}),T.addEventListener("click",()=>{Fe()}),x.appendChild(M),x.appendChild(T),u.appendChild(x),u.appendChild(D),m.addEventListener("click",()=>{u.hidden=!u.hidden,m.setAttribute("aria-expanded",u.hidden?"false":"true")}),{toggle:m,panel:u}};P.addEventListener("click",d=>{d.target===P&&be()});let Ge=d=>{if(d.key==="Escape"){be();return}d.key==="Tab"&&kn(f,d)};document.addEventListener("keydown",Ge),P.appendChild(E),f.appendChild(P),document.body.appendChild(y),K(),j()})}function Cn(e,t){return e.some(n=>n.url===t)}function _n(e){if(e!==void 0)try{return new URL(e).hostname}catch{return e}}function b(e,t,n){let r=document.createElement(e);return r.className=t,n!==void 0&&(r.textContent=n),r}function ie(e,t){let n=document.createElement("button");return n.className="stage-btn",n.textContent=e,n.addEventListener("click",t),n}function Oe(e,t){let n=document.createElement("button");return n.className="footer-link",n.textContent=e,n.addEventListener("click",t),n}function Pn(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 kn(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 ut=`
|
|
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
155
|
--ec-bg: #ffffff;
|
|
156
156
|
--ec-surface: #f5f6f8;
|
|
157
157
|
--ec-text: #17171f;
|
|
@@ -160,7 +160,7 @@ import{Enbox as ho,defineProtocol as go,repository as wo}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;`,vt=`
|
|
164
164
|
--ec-bg: #181822;
|
|
165
165
|
--ec-surface: #23232f;
|
|
166
166
|
--ec-text: #e9e9f0;
|
|
@@ -169,7 +169,7 @@ import{Enbox as ho,defineProtocol as go,repository as wo}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;`,On=`
|
|
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 ho,defineProtocol as go,repository as wo}from"@enbox/api";import
|
|
|
204
204
|
50% { transform: scale(1); opacity: 1; }
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
.modal {${
|
|
207
|
+
.modal {${wt}
|
|
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 ho,defineProtocol as go,repository as wo}from"@enbox/api";import
|
|
|
220
220
|
flex-direction: column;
|
|
221
221
|
}
|
|
222
222
|
@media (prefers-color-scheme: dark) {
|
|
223
|
-
.modal {${
|
|
223
|
+
.modal {${vt}
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
|
-
.modal[data-appearance='light'] {${
|
|
226
|
+
.modal[data-appearance='light'] {${wt}
|
|
227
227
|
}
|
|
228
|
-
.modal[data-appearance='dark'] {${
|
|
228
|
+
.modal[data-appearance='dark'] {${vt}
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
button, input { font-family: inherit; }
|
|
@@ -259,6 +259,7 @@ import{Enbox as ho,defineProtocol as go,repository as wo}from"@enbox/api";import
|
|
|
259
259
|
.stage.fade-in > * { animation: stageIn 0.15s ease-out; }
|
|
260
260
|
|
|
261
261
|
.qr-box {
|
|
262
|
+
position: relative;
|
|
262
263
|
width: 200px;
|
|
263
264
|
height: 200px;
|
|
264
265
|
padding: 10px;
|
|
@@ -268,6 +269,25 @@ import{Enbox as ho,defineProtocol as go,repository as wo}from"@enbox/api";import
|
|
|
268
269
|
}
|
|
269
270
|
.qr-box svg { width: 100%; height: 100%; display: block; }
|
|
270
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
|
+
|
|
271
291
|
.claimed-pulse {
|
|
272
292
|
width: 64px; height: 64px; border-radius: 50%;
|
|
273
293
|
background: var(--ec-accent-soft); position: relative;
|
|
@@ -283,7 +303,10 @@ import{Enbox as ho,defineProtocol as go,repository as wo}from"@enbox/api";import
|
|
|
283
303
|
.stage-error { font-size: 13px; color: var(--ec-danger); }
|
|
284
304
|
|
|
285
305
|
.deep-link {
|
|
286
|
-
display:
|
|
306
|
+
display: flex;
|
|
307
|
+
align-items: center;
|
|
308
|
+
justify-content: center;
|
|
309
|
+
gap: 10px;
|
|
287
310
|
width: 100%;
|
|
288
311
|
padding: 13px 16px;
|
|
289
312
|
border-radius: 12px;
|
|
@@ -293,6 +316,13 @@ import{Enbox as ho,defineProtocol as go,repository as wo}from"@enbox/api";import
|
|
|
293
316
|
font-size: 15px;
|
|
294
317
|
text-decoration: none;
|
|
295
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; }
|
|
296
326
|
|
|
297
327
|
.pin-row { display: flex; gap: 10px; }
|
|
298
328
|
.pin-row.shake { animation: shake 0.4s ease-in-out; }
|
|
@@ -366,7 +396,54 @@ import{Enbox as ho,defineProtocol as go,repository as wo}from"@enbox/api";import
|
|
|
366
396
|
}
|
|
367
397
|
.footer-link:hover { color: var(--ec-text); background: var(--ec-surface); }
|
|
368
398
|
.method-link { color: var(--ec-accent); }
|
|
369
|
-
|
|
399
|
+
|
|
400
|
+
.wallet-row-label { font-size: 12px; color: var(--ec-muted); padding: 2px 2px 0; }
|
|
401
|
+
|
|
402
|
+
.wallet-row {
|
|
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
|
+
}
|
|
370
447
|
|
|
371
448
|
.wallet-panel { width: 100%; padding: 4px 0 2px; display: flex; flex-direction: column; gap: 8px; }
|
|
372
449
|
.wallet-search {
|
|
@@ -447,5 +524,5 @@ import{Enbox as ho,defineProtocol as go,repository as wo}from"@enbox/api";import
|
|
|
447
524
|
.overlay, .modal, .stage.fade-in > *, .pin-row.shake { animation: none; }
|
|
448
525
|
.claimed-pulse::after { animation: none; }
|
|
449
526
|
}
|
|
450
|
-
`;var
|
|
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};
|
|
451
528
|
//# sourceMappingURL=browser.mjs.map
|