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