@enbox/browser 0.2.1 → 0.3.0
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/esm/browser-connect-handler.js +17 -5
- package/dist/esm/browser-connect-handler.js.map +1 -1
- package/dist/esm/dweb-connect-client.js +11 -6
- package/dist/esm/dweb-connect-client.js.map +1 -1
- package/dist/esm/index.js +39 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/ui/wallet-selector.js +32 -6
- package/dist/esm/ui/wallet-selector.js.map +1 -1
- package/dist/types/browser-connect-handler.d.ts +18 -4
- package/dist/types/browser-connect-handler.d.ts.map +1 -1
- package/dist/types/dweb-connect-client.d.ts +22 -2
- package/dist/types/dweb-connect-client.d.ts.map +1 -1
- package/dist/types/index.d.ts +32 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/ui/wallet-selector.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/browser-connect-handler.ts +35 -5
- package/src/dweb-connect-client.ts +35 -6
- package/src/index.ts +82 -1
- package/src/ui/wallet-selector.ts +35 -6
|
@@ -19,7 +19,16 @@ import { DWebConnect } from './dweb-connect-client.js';
|
|
|
19
19
|
import { showWalletSelector } from './ui/wallet-selector.js';
|
|
20
20
|
/** Default wallets shown in the selector when no overrides are provided. */
|
|
21
21
|
export const DEFAULT_WALLETS = [
|
|
22
|
-
{
|
|
22
|
+
{
|
|
23
|
+
name: 'Enbox Wallet',
|
|
24
|
+
url: 'https://enbox-wallet.pages.dev',
|
|
25
|
+
description: 'Your digital identity wallet',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'Blue Enbox Wallet',
|
|
29
|
+
url: 'https://blue-enbox-wallet.pages.dev',
|
|
30
|
+
description: 'Your digital identity wallet',
|
|
31
|
+
},
|
|
23
32
|
];
|
|
24
33
|
/**
|
|
25
34
|
* Create a browser-native connect handler using DWeb Connect
|
|
@@ -33,18 +42,19 @@ export const DEFAULT_WALLETS = [
|
|
|
33
42
|
*
|
|
34
43
|
* @example
|
|
35
44
|
* ```ts
|
|
36
|
-
* import { AuthManager } from '@enbox/
|
|
37
|
-
* import { BrowserConnectHandler } from '@enbox/browser';
|
|
45
|
+
* import { AuthManager, BrowserConnectHandler } from '@enbox/browser';
|
|
38
46
|
*
|
|
39
47
|
* const auth = await AuthManager.create({
|
|
40
|
-
* connectHandler: BrowserConnectHandler(
|
|
48
|
+
* connectHandler: BrowserConnectHandler({
|
|
49
|
+
* appName: 'My Dapp',
|
|
50
|
+
* }),
|
|
41
51
|
* });
|
|
42
52
|
*
|
|
43
53
|
* const session = await auth.connect({ protocols: [NotesProtocol] });
|
|
44
54
|
* ```
|
|
45
55
|
*/
|
|
46
56
|
export function BrowserConnectHandler(options = {}) {
|
|
47
|
-
const { wallets = DEFAULT_WALLETS, walletUrl: fixedWalletUrl, timeout, } = options;
|
|
57
|
+
const { wallets = DEFAULT_WALLETS, walletUrl: fixedWalletUrl, timeout, appName, appIcon, } = options;
|
|
48
58
|
return {
|
|
49
59
|
requestAccess(params) {
|
|
50
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -58,6 +68,8 @@ export function BrowserConnectHandler(options = {}) {
|
|
|
58
68
|
walletUrl,
|
|
59
69
|
permissionRequests: params.permissionRequests,
|
|
60
70
|
timeout,
|
|
71
|
+
appName,
|
|
72
|
+
appIcon,
|
|
61
73
|
});
|
|
62
74
|
});
|
|
63
75
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-connect-handler.js","sourceRoot":"","sources":["../../src/browser-connect-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;;;;;;;;;;AAKH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"browser-connect-handler.js","sourceRoot":"","sources":["../../src/browser-connect-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;;;;;;;;;;AAKH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAiB7D,4EAA4E;AAC5E,MAAM,CAAC,MAAM,eAAe,GAAmB;IAC7C;QACE,IAAI,EAAU,cAAc;QAC5B,GAAG,EAAW,gCAAgC;QAC9C,WAAW,EAAG,8BAA8B;KAC7C;IACD;QACE,IAAI,EAAU,mBAAmB;QACjC,GAAG,EAAW,qCAAqC;QACnD,WAAW,EAAG,8BAA8B;KAC7C;CACF,CAAC;AAoCF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,qBAAqB,CACnC,UAAwC,EAAE;IAE1C,MAAM,EACJ,OAAO,GAAG,eAAe,EACzB,SAAS,EAAE,cAAc,EACzB,OAAO,EACP,OAAO,EACP,OAAO,GACR,GAAG,OAAO,CAAC;IAEZ,OAAO;QACC,aAAa,CAAC,MAEnB;;gBACC,2BAA2B;gBAC3B,IAAI,SAAS,GAAG,cAAc,CAAC;gBAC/B,IAAI,CAAC,SAAS,EAAE,CAAC;oBACf,SAAS,GAAG,MAAM,kBAAkB,CAAC,OAAO,CAAC,CAAC;gBAChD,CAAC;gBAED,sCAAsC;gBACtC,OAAO,WAAW,CAAC,UAAU,CAAC;oBAC5B,SAAS;oBACT,kBAAkB,EAAE,MAAM,CAAC,kBAAkB;oBAC7C,OAAO;oBACP,OAAO;oBACP,OAAO;iBACR,CAAC,CAAC;YACL,CAAC;SAAA;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -23,7 +23,8 @@ import { decryptPostMessagePayload, generateEphemeralKeyPair } from './dweb-conn
|
|
|
23
23
|
* Protocol:
|
|
24
24
|
* 1. Dapp opens `${walletUrl}/dweb-connect` as a popup.
|
|
25
25
|
* 2. Wallet sends `{ type: 'dweb-connect-loaded' }` when ready.
|
|
26
|
-
* 3. Dapp sends `{ type: 'dweb-connect-authorization-request', did, permissions
|
|
26
|
+
* 3. Dapp sends `{ type: 'dweb-connect-authorization-request', did, permissions,
|
|
27
|
+
* appName?, appIcon?, portableIdentity? }`.
|
|
27
28
|
* 4. Wallet shows consent UI, then sends back
|
|
28
29
|
* `{ type: 'dweb-connect-authorization-response', delegateDid, grants }`.
|
|
29
30
|
* 5. Popup closes.
|
|
@@ -33,15 +34,15 @@ import { decryptPostMessagePayload, generateEphemeralKeyPair } from './dweb-conn
|
|
|
33
34
|
*/
|
|
34
35
|
function initClient(options) {
|
|
35
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
const { walletUrl, did, permissionRequests, timeout = 300000, } = options;
|
|
37
|
+
const { walletUrl, did, permissionRequests, timeout = 300000, appName, appIcon, portableIdentity, } = options;
|
|
37
38
|
if (typeof window === 'undefined') {
|
|
38
|
-
throw new Error('[@enbox/
|
|
39
|
+
throw new Error('[@enbox/browser] DWeb Connect is only available in browser environments.');
|
|
39
40
|
}
|
|
40
41
|
// Open the wallet's DWeb Connect page as a popup.
|
|
41
42
|
const popupUrl = new URL('/dweb-connect', walletUrl).toString();
|
|
42
43
|
const popup = window.open(popupUrl, 'enbox-dweb-connect', 'width=500,height=700,menubar=no,toolbar=no,location=no,status=no');
|
|
43
44
|
if (!popup) {
|
|
44
|
-
throw new Error('[@enbox/
|
|
45
|
+
throw new Error('[@enbox/browser] Popup blocked. Allow popups for this site to connect to a wallet.');
|
|
45
46
|
}
|
|
46
47
|
// Generate an ephemeral ECDH keypair for this connect session.
|
|
47
48
|
// The public key is sent to the wallet so it can encrypt the response
|
|
@@ -71,7 +72,7 @@ function initClient(options) {
|
|
|
71
72
|
popup.close();
|
|
72
73
|
}
|
|
73
74
|
catch ( /* best effort */_a) { /* best effort */ }
|
|
74
|
-
reject(new Error('[@enbox/
|
|
75
|
+
reject(new Error('[@enbox/browser] DWeb Connect timed out waiting for wallet response.'));
|
|
75
76
|
}
|
|
76
77
|
}, timeout);
|
|
77
78
|
// Monitor popup closed without response (user closed the window).
|
|
@@ -91,12 +92,16 @@ function initClient(options) {
|
|
|
91
92
|
}
|
|
92
93
|
const { type } = (_a = event.data) !== null && _a !== void 0 ? _a : {};
|
|
93
94
|
if (type === 'dweb-connect-loaded') {
|
|
94
|
-
// Wallet is ready — send the authorization request with
|
|
95
|
+
// Wallet is ready — send the authorization request with
|
|
96
|
+
// ephemeral public key and optional app metadata.
|
|
95
97
|
popup.postMessage({
|
|
96
98
|
type: 'dweb-connect-authorization-request',
|
|
97
99
|
did,
|
|
98
100
|
permissions: permissionRequests,
|
|
99
101
|
ephemeralPublicKey: dappPublicKeyBase64url,
|
|
102
|
+
appName,
|
|
103
|
+
appIcon,
|
|
104
|
+
portableIdentity,
|
|
100
105
|
}, walletOrigin);
|
|
101
106
|
return;
|
|
102
107
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dweb-connect-client.js","sourceRoot":"","sources":["../../src/dweb-connect-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;;;;;;;;;;AAOH,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"dweb-connect-client.js","sourceRoot":"","sources":["../../src/dweb-connect-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;;;;;;;;;;AAOH,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AA6C/F;;;;;;;;;;;;;;GAcG;AACH,SAAe,UAAU,CAAC,OAAiC;;QACzD,MAAM,EACJ,SAAS,EACT,GAAG,EACH,kBAAkB,EAClB,OAAO,GAAG,MAAO,EACjB,OAAO,EACP,OAAO,EACP,gBAAgB,GACjB,GAAG,OAAO,CAAC;QAEZ,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CACb,0EAA0E,CAC3E,CAAC;QACJ,CAAC;QAED,kDAAkD;QAClD,MAAM,QAAQ,GAAG,IA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|
|
2
|
+
* @enbox/browser — The Enbox browser SDK.
|
|
3
|
+
*
|
|
4
|
+
* For browser-based dapps, this is the only package you need to import.
|
|
5
|
+
* It re-exports the high-level API from `@enbox/api`, the authentication
|
|
6
|
+
* layer from `@enbox/auth`, and provides browser-specific connect handlers.
|
|
7
|
+
*
|
|
8
|
+
* @example Single-import dapp setup
|
|
9
|
+
* ```ts
|
|
10
|
+
* import {
|
|
11
|
+
* Enbox, AuthManager, BrowserConnectHandler,
|
|
12
|
+
* defineProtocol, repository,
|
|
13
|
+
* type AuthSession,
|
|
14
|
+
* } from '@enbox/browser';
|
|
15
|
+
*
|
|
16
|
+
* const auth = await AuthManager.create({
|
|
17
|
+
* connectHandler: BrowserConnectHandler({ appName: 'My App' }),
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* const session = await auth.connect({ protocols: [MyProtocol] });
|
|
21
|
+
* const enbox = Enbox.connect({ session });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* For non-browser environments (Node.js, CLI, desktop), import from
|
|
25
|
+
* `@enbox/api` and `@enbox/auth` directly instead.
|
|
26
|
+
*
|
|
27
|
+
* @packageDocumentation
|
|
28
|
+
*/
|
|
29
|
+
// ─── Re-exports from @enbox/api ─────────────────────────────────
|
|
30
|
+
//
|
|
31
|
+
// The high-level Enbox API: DWN records, protocols, repositories.
|
|
32
|
+
export { Enbox, defineProtocol, repository, } from '@enbox/api';
|
|
33
|
+
// ─── Re-exports from @enbox/auth ────────────────────────────────
|
|
34
|
+
//
|
|
35
|
+
// Authentication lifecycle, session management, connect handlers.
|
|
36
|
+
export { AuthManager, AuthSession, normalizeProtocolRequests, WalletConnect, } from '@enbox/auth';
|
|
37
|
+
// ─── Browser-specific exports ───────────────────────────────────
|
|
38
|
+
//
|
|
39
|
+
// DWeb Connect, wallet selector, DRL polyfills.
|
|
1
40
|
export * from './web-features.js';
|
|
2
41
|
export { BrowserConnectHandler, DEFAULT_WALLETS } from './browser-connect-handler.js';
|
|
3
42
|
export { DWebConnect } from './dweb-connect-client.js';
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEtF,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,mEAAmE;AACnE,EAAE;AACF,kEAAkE;AAElE,OAAO,EACL,KAAK,EACL,cAAc,EACd,UAAU,GACX,MAAM,YAAY,CAAC;AAOpB,mEAAmE;AACnE,EAAE;AACF,kEAAkE;AAElE,OAAO,EACL,WAAW,EACX,WAAW,EACX,yBAAyB,EACzB,aAAa,GACd,MAAM,aAAa,CAAC;AAwBrB,mEAAmE;AACnE,EAAE;AACF,gDAAgD;AAEhD,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEtF,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
/** Shows the wallet selector modal and resolves with the chosen wallet URL. */
|
|
10
10
|
export function showWalletSelector(wallets) {
|
|
11
11
|
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
12
|
-
throw new Error('[@enbox/
|
|
12
|
+
throw new Error('[@enbox/browser] Wallet selector is only available in browser environments.');
|
|
13
13
|
}
|
|
14
14
|
return new Promise((resolve, reject) => {
|
|
15
15
|
var _a, _b;
|
|
@@ -44,7 +44,7 @@ export function showWalletSelector(wallets) {
|
|
|
44
44
|
closeBtn.innerHTML = '×';
|
|
45
45
|
closeBtn.addEventListener('click', () => {
|
|
46
46
|
cleanup();
|
|
47
|
-
reject(new Error('[@enbox/
|
|
47
|
+
reject(new Error('[@enbox/browser] Wallet selection cancelled.'));
|
|
48
48
|
});
|
|
49
49
|
header.appendChild(title);
|
|
50
50
|
header.appendChild(closeBtn);
|
|
@@ -61,14 +61,23 @@ export function showWalletSelector(wallets) {
|
|
|
61
61
|
icon.width = 32;
|
|
62
62
|
icon.height = 32;
|
|
63
63
|
icon.onerror = () => { icon.style.display = 'none'; };
|
|
64
|
+
const textGroup = document.createElement('div');
|
|
65
|
+
textGroup.className = 'wallet-text';
|
|
64
66
|
const name = document.createElement('span');
|
|
65
67
|
name.className = 'wallet-name';
|
|
66
68
|
name.textContent = wallet.name;
|
|
69
|
+
textGroup.appendChild(name);
|
|
70
|
+
if (wallet.description) {
|
|
71
|
+
const desc = document.createElement('span');
|
|
72
|
+
desc.className = 'wallet-description';
|
|
73
|
+
desc.textContent = wallet.description;
|
|
74
|
+
textGroup.appendChild(desc);
|
|
75
|
+
}
|
|
67
76
|
const arrow = document.createElement('span');
|
|
68
77
|
arrow.className = 'arrow';
|
|
69
78
|
arrow.textContent = '\u203A'; // ›
|
|
70
79
|
item.appendChild(icon);
|
|
71
|
-
item.appendChild(
|
|
80
|
+
item.appendChild(textGroup);
|
|
72
81
|
item.appendChild(arrow);
|
|
73
82
|
item.addEventListener('click', () => {
|
|
74
83
|
cleanup();
|
|
@@ -123,7 +132,7 @@ export function showWalletSelector(wallets) {
|
|
|
123
132
|
overlay.addEventListener('click', (e) => {
|
|
124
133
|
if (e.target === overlay) {
|
|
125
134
|
cleanup();
|
|
126
|
-
reject(new Error('[@enbox/
|
|
135
|
+
reject(new Error('[@enbox/browser] Wallet selection cancelled.'));
|
|
127
136
|
}
|
|
128
137
|
});
|
|
129
138
|
// Close on Escape.
|
|
@@ -131,7 +140,7 @@ export function showWalletSelector(wallets) {
|
|
|
131
140
|
if (e.key === 'Escape') {
|
|
132
141
|
document.removeEventListener('keydown', onKeydown);
|
|
133
142
|
cleanup();
|
|
134
|
-
reject(new Error('[@enbox/
|
|
143
|
+
reject(new Error('[@enbox/browser] Wallet selection cancelled.'));
|
|
135
144
|
}
|
|
136
145
|
};
|
|
137
146
|
document.addEventListener('keydown', onKeydown);
|
|
@@ -257,11 +266,28 @@ function buildStyles(isDark) {
|
|
|
257
266
|
}
|
|
258
267
|
.wallet-item:hover { background: ${itemHover}; }
|
|
259
268
|
|
|
260
|
-
.wallet-
|
|
269
|
+
.wallet-text {
|
|
270
|
+
flex: 1;
|
|
271
|
+
display: flex;
|
|
272
|
+
flex-direction: column;
|
|
273
|
+
gap: 2px;
|
|
274
|
+
min-width: 0;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
.wallet-name { font-weight: 500; }
|
|
278
|
+
|
|
279
|
+
.wallet-description {
|
|
280
|
+
font-size: 12px;
|
|
281
|
+
color: ${muted};
|
|
282
|
+
white-space: nowrap;
|
|
283
|
+
overflow: hidden;
|
|
284
|
+
text-overflow: ellipsis;
|
|
285
|
+
}
|
|
261
286
|
|
|
262
287
|
.arrow {
|
|
263
288
|
font-size: 20px;
|
|
264
289
|
color: ${muted};
|
|
290
|
+
flex-shrink: 0;
|
|
265
291
|
}
|
|
266
292
|
|
|
267
293
|
.separator {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-selector.js","sourceRoot":"","sources":["../../../src/ui/wallet-selector.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,+EAA+E;AAC/E,MAAM,UAAU,kBAAkB,CAAC,OAAuB;IACxD,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;QACrE,MAAM,IAAI,KAAK,CAAC,
|
|
1
|
+
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;;;oBAMxB,MAAM;;;;;;;;;;;;GAYvB,CAAC;AACJ,CAAC"}
|
|
@@ -11,10 +11,12 @@ import type { ConnectHandler } from '@enbox/auth';
|
|
|
11
11
|
export interface WalletOption {
|
|
12
12
|
/** Display name (e.g. "Enbox Wallet"). */
|
|
13
13
|
name: string;
|
|
14
|
-
/** Base URL of the wallet app (e.g. "https://wallet.
|
|
14
|
+
/** Base URL of the wallet app (e.g. "https://enbox-wallet.pages.dev"). */
|
|
15
15
|
url: string;
|
|
16
16
|
/** Optional icon URL. If omitted, the wallet's favicon is used. */
|
|
17
17
|
icon?: string;
|
|
18
|
+
/** Short description shown below the wallet name in the selector. */
|
|
19
|
+
description?: string;
|
|
18
20
|
}
|
|
19
21
|
/** Default wallets shown in the selector when no overrides are provided. */
|
|
20
22
|
export declare const DEFAULT_WALLETS: WalletOption[];
|
|
@@ -35,6 +37,17 @@ export interface BrowserConnectHandlerOptions {
|
|
|
35
37
|
* @default 300_000 (5 minutes)
|
|
36
38
|
*/
|
|
37
39
|
timeout?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Display name of the requesting application.
|
|
42
|
+
* Shown in the wallet's permission consent screen.
|
|
43
|
+
*/
|
|
44
|
+
appName?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Icon URL of the requesting application.
|
|
47
|
+
* Shown alongside the app name in the wallet's consent screen.
|
|
48
|
+
* Defaults to `${window.location.origin}/favicon.ico` if omitted.
|
|
49
|
+
*/
|
|
50
|
+
appIcon?: string;
|
|
38
51
|
}
|
|
39
52
|
/**
|
|
40
53
|
* Create a browser-native connect handler using DWeb Connect
|
|
@@ -48,11 +61,12 @@ export interface BrowserConnectHandlerOptions {
|
|
|
48
61
|
*
|
|
49
62
|
* @example
|
|
50
63
|
* ```ts
|
|
51
|
-
* import { AuthManager } from '@enbox/
|
|
52
|
-
* import { BrowserConnectHandler } from '@enbox/browser';
|
|
64
|
+
* import { AuthManager, BrowserConnectHandler } from '@enbox/browser';
|
|
53
65
|
*
|
|
54
66
|
* const auth = await AuthManager.create({
|
|
55
|
-
* connectHandler: BrowserConnectHandler(
|
|
67
|
+
* connectHandler: BrowserConnectHandler({
|
|
68
|
+
* appName: 'My Dapp',
|
|
69
|
+
* }),
|
|
56
70
|
* });
|
|
57
71
|
*
|
|
58
72
|
* const session = await auth.connect({ protocols: [NotesProtocol] });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-connect-handler.d.ts","sourceRoot":"","sources":["../../src/browser-connect-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAiB,MAAM,aAAa,CAAC;AAKjE,yDAAyD;AACzD,MAAM,WAAW,YAAY;IAC3B,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IAEb,
|
|
1
|
+
{"version":3,"file":"browser-connect-handler.d.ts","sourceRoot":"","sources":["../../src/browser-connect-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAiB,MAAM,aAAa,CAAC;AAKjE,yDAAyD;AACzD,MAAM,WAAW,YAAY;IAC3B,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IAEb,0EAA0E;IAC1E,GAAG,EAAE,MAAM,CAAC;IAEZ,mEAAmE;IACnE,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,qEAAqE;IACrE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,4EAA4E;AAC5E,eAAO,MAAM,eAAe,EAAE,YAAY,EAWzC,CAAC;AAEF,oDAAoD;AACpD,MAAM,WAAW,4BAA4B;IAC3C;;;OAGG;IACH,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IAEzB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,GAAE,4BAAiC,GACzC,cAAc,CA6BhB"}
|
|
@@ -8,10 +8,11 @@
|
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
10
|
import type { ConnectResult } from '@enbox/auth';
|
|
11
|
+
import type { PortableDid } from '@enbox/dids';
|
|
11
12
|
import type { ConnectPermissionRequest } from '@enbox/agent';
|
|
12
13
|
/** Options for initiating a DWeb Connect flow via popup. */
|
|
13
14
|
export interface DWebConnectClientOptions {
|
|
14
|
-
/** Base URL of the wallet app (e.g. "https://wallet.
|
|
15
|
+
/** Base URL of the wallet app (e.g. "https://enbox-wallet.pages.dev"). */
|
|
15
16
|
walletUrl: string;
|
|
16
17
|
/** The DID to pre-select in the wallet's identity picker. */
|
|
17
18
|
did?: string;
|
|
@@ -26,6 +27,24 @@ export interface DWebConnectClientOptions {
|
|
|
26
27
|
* @default 300_000 (5 minutes)
|
|
27
28
|
*/
|
|
28
29
|
timeout?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Display name of the requesting application.
|
|
32
|
+
* Shown in the wallet's permission consent screen.
|
|
33
|
+
*/
|
|
34
|
+
appName?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Icon URL of the requesting application.
|
|
37
|
+
* Shown alongside the app name in the wallet's consent screen.
|
|
38
|
+
*/
|
|
39
|
+
appIcon?: string;
|
|
40
|
+
/**
|
|
41
|
+
* A PortableDid to transfer to the wallet for identity import.
|
|
42
|
+
*
|
|
43
|
+
* When provided, the wallet imports this identity and creates
|
|
44
|
+
* delegate grants for the dapp, allowing the dapp to transition
|
|
45
|
+
* from local-DID mode to delegate mode while keeping the same DID.
|
|
46
|
+
*/
|
|
47
|
+
portableIdentity?: PortableDid;
|
|
29
48
|
}
|
|
30
49
|
/**
|
|
31
50
|
* Open a wallet popup and run the DWeb Connect postMessage flow.
|
|
@@ -33,7 +52,8 @@ export interface DWebConnectClientOptions {
|
|
|
33
52
|
* Protocol:
|
|
34
53
|
* 1. Dapp opens `${walletUrl}/dweb-connect` as a popup.
|
|
35
54
|
* 2. Wallet sends `{ type: 'dweb-connect-loaded' }` when ready.
|
|
36
|
-
* 3. Dapp sends `{ type: 'dweb-connect-authorization-request', did, permissions
|
|
55
|
+
* 3. Dapp sends `{ type: 'dweb-connect-authorization-request', did, permissions,
|
|
56
|
+
* appName?, appIcon?, portableIdentity? }`.
|
|
37
57
|
* 4. Wallet shows consent UI, then sends back
|
|
38
58
|
* `{ type: 'dweb-connect-authorization-response', delegateDid, grants }`.
|
|
39
59
|
* 5. Popup closes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dweb-connect-client.d.ts","sourceRoot":"","sources":["../../src/dweb-connect-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"dweb-connect-client.d.ts","sourceRoot":"","sources":["../../src/dweb-connect-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,wBAAwB,EAAqC,MAAM,cAAc,CAAC;AAKhG,4DAA4D;AAC5D,MAAM,WAAW,wBAAwB;IACvC,0EAA0E;IAC1E,SAAS,EAAE,MAAM,CAAC;IAElB,6DAA6D;IAC7D,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,kBAAkB,EAAE,wBAAwB,EAAE,CAAC;IAE/C;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,WAAW,CAAC;CAChC;AAED;;;;;;;;;;;;;;GAcG;AACH,iBAAe,UAAU,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CA2J/F;AAED;;;;;;;;;;;GAWG;AACH,iBAAe,kBAAkB,CAC/B,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,OAAO,SAAQ,GACd,OAAO,CAAC,OAAO,CAAC,CA+ClB;AAED,eAAO,MAAM,WAAW;;;CAAqC,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @enbox/browser — The Enbox browser SDK.
|
|
3
|
+
*
|
|
4
|
+
* For browser-based dapps, this is the only package you need to import.
|
|
5
|
+
* It re-exports the high-level API from `@enbox/api`, the authentication
|
|
6
|
+
* layer from `@enbox/auth`, and provides browser-specific connect handlers.
|
|
7
|
+
*
|
|
8
|
+
* @example Single-import dapp setup
|
|
9
|
+
* ```ts
|
|
10
|
+
* import {
|
|
11
|
+
* Enbox, AuthManager, BrowserConnectHandler,
|
|
12
|
+
* defineProtocol, repository,
|
|
13
|
+
* type AuthSession,
|
|
14
|
+
* } from '@enbox/browser';
|
|
15
|
+
*
|
|
16
|
+
* const auth = await AuthManager.create({
|
|
17
|
+
* connectHandler: BrowserConnectHandler({ appName: 'My App' }),
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* const session = await auth.connect({ protocols: [MyProtocol] });
|
|
21
|
+
* const enbox = Enbox.connect({ session });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* For non-browser environments (Node.js, CLI, desktop), import from
|
|
25
|
+
* `@enbox/api` and `@enbox/auth` directly instead.
|
|
26
|
+
*
|
|
27
|
+
* @packageDocumentation
|
|
28
|
+
*/
|
|
29
|
+
export { Enbox, defineProtocol, repository, } from '@enbox/api';
|
|
30
|
+
export type { EnboxParams, EnboxAnonymousOptions, } from '@enbox/api';
|
|
31
|
+
export { AuthManager, AuthSession, normalizeProtocolRequests, WalletConnect, } from '@enbox/auth';
|
|
32
|
+
export type { AuthEvent, AuthEventHandler, AuthManagerOptions, AuthState, ConnectHandler, ConnectOptions, ConnectResult, DisconnectOptions, HandlerConnectOptions, ImportFromPhraseOptions, ImportFromPortableOptions, LocalConnectOptions, Permission, PortableIdentity, ProtocolRequest, RegistrationOptions, StorageAdapter, SyncOption, WalletConnectOptions, } from '@enbox/auth';
|
|
1
33
|
export * from './web-features.js';
|
|
2
34
|
export { BrowserConnectHandler, DEFAULT_WALLETS } from './browser-connect-handler.js';
|
|
3
35
|
export type { BrowserConnectHandlerOptions, WalletOption } from './browser-connect-handler.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACtF,YAAY,EAAE,4BAA4B,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,YAAY,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAC/F,YAAY,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAMH,OAAO,EACL,KAAK,EACL,cAAc,EACd,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,WAAW,EACX,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAMpB,OAAO,EACL,WAAW,EACX,WAAW,EACX,yBAAyB,EACzB,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,kBAAkB,EAClB,SAAS,EACT,cAAc,EACd,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,EACvB,yBAAyB,EACzB,mBAAmB,EACnB,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,UAAU,EACV,oBAAoB,GACrB,MAAM,aAAa,CAAC;AAMrB,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACtF,YAAY,EAAE,4BAA4B,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,YAAY,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAC/F,YAAY,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-selector.d.ts","sourceRoot":"","sources":["../../../src/ui/wallet-selector.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElE,+EAA+E;AAC/E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"wallet-selector.d.ts","sourceRoot":"","sources":["../../../src/ui/wallet-selector.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElE,+EAA+E;AAC/E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA+K3E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enbox/browser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Enbox tools and features to use in the browser",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/esm/index.js",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@enbox/agent": "0.6.3",
|
|
59
|
+
"@enbox/api": "0.6.15",
|
|
59
60
|
"@enbox/auth": "0.6.23",
|
|
60
61
|
"@enbox/dids": "0.1.0"
|
|
61
62
|
},
|
|
@@ -18,16 +18,28 @@ export interface WalletOption {
|
|
|
18
18
|
/** Display name (e.g. "Enbox Wallet"). */
|
|
19
19
|
name: string;
|
|
20
20
|
|
|
21
|
-
/** Base URL of the wallet app (e.g. "https://wallet.
|
|
21
|
+
/** Base URL of the wallet app (e.g. "https://enbox-wallet.pages.dev"). */
|
|
22
22
|
url: string;
|
|
23
23
|
|
|
24
24
|
/** Optional icon URL. If omitted, the wallet's favicon is used. */
|
|
25
25
|
icon?: string;
|
|
26
|
+
|
|
27
|
+
/** Short description shown below the wallet name in the selector. */
|
|
28
|
+
description?: string;
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
/** Default wallets shown in the selector when no overrides are provided. */
|
|
29
32
|
export const DEFAULT_WALLETS: WalletOption[] = [
|
|
30
|
-
{
|
|
33
|
+
{
|
|
34
|
+
name : 'Enbox Wallet',
|
|
35
|
+
url : 'https://enbox-wallet.pages.dev',
|
|
36
|
+
description : 'Your digital identity wallet',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name : 'Blue Enbox Wallet',
|
|
40
|
+
url : 'https://blue-enbox-wallet.pages.dev',
|
|
41
|
+
description : 'Your digital identity wallet',
|
|
42
|
+
},
|
|
31
43
|
];
|
|
32
44
|
|
|
33
45
|
/** Options for creating a BrowserConnectHandler. */
|
|
@@ -49,6 +61,19 @@ export interface BrowserConnectHandlerOptions {
|
|
|
49
61
|
* @default 300_000 (5 minutes)
|
|
50
62
|
*/
|
|
51
63
|
timeout?: number;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Display name of the requesting application.
|
|
67
|
+
* Shown in the wallet's permission consent screen.
|
|
68
|
+
*/
|
|
69
|
+
appName?: string;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Icon URL of the requesting application.
|
|
73
|
+
* Shown alongside the app name in the wallet's consent screen.
|
|
74
|
+
* Defaults to `${window.location.origin}/favicon.ico` if omitted.
|
|
75
|
+
*/
|
|
76
|
+
appIcon?: string;
|
|
52
77
|
}
|
|
53
78
|
|
|
54
79
|
/**
|
|
@@ -63,11 +88,12 @@ export interface BrowserConnectHandlerOptions {
|
|
|
63
88
|
*
|
|
64
89
|
* @example
|
|
65
90
|
* ```ts
|
|
66
|
-
* import { AuthManager } from '@enbox/
|
|
67
|
-
* import { BrowserConnectHandler } from '@enbox/browser';
|
|
91
|
+
* import { AuthManager, BrowserConnectHandler } from '@enbox/browser';
|
|
68
92
|
*
|
|
69
93
|
* const auth = await AuthManager.create({
|
|
70
|
-
* connectHandler: BrowserConnectHandler(
|
|
94
|
+
* connectHandler: BrowserConnectHandler({
|
|
95
|
+
* appName: 'My Dapp',
|
|
96
|
+
* }),
|
|
71
97
|
* });
|
|
72
98
|
*
|
|
73
99
|
* const session = await auth.connect({ protocols: [NotesProtocol] });
|
|
@@ -80,6 +106,8 @@ export function BrowserConnectHandler(
|
|
|
80
106
|
wallets = DEFAULT_WALLETS,
|
|
81
107
|
walletUrl: fixedWalletUrl,
|
|
82
108
|
timeout,
|
|
109
|
+
appName,
|
|
110
|
+
appIcon,
|
|
83
111
|
} = options;
|
|
84
112
|
|
|
85
113
|
return {
|
|
@@ -97,6 +125,8 @@ export function BrowserConnectHandler(
|
|
|
97
125
|
walletUrl,
|
|
98
126
|
permissionRequests: params.permissionRequests,
|
|
99
127
|
timeout,
|
|
128
|
+
appName,
|
|
129
|
+
appIcon,
|
|
100
130
|
});
|
|
101
131
|
},
|
|
102
132
|
};
|
|
@@ -17,7 +17,7 @@ import { decryptPostMessagePayload, generateEphemeralKeyPair } from './dweb-conn
|
|
|
17
17
|
|
|
18
18
|
/** Options for initiating a DWeb Connect flow via popup. */
|
|
19
19
|
export interface DWebConnectClientOptions {
|
|
20
|
-
/** Base URL of the wallet app (e.g. "https://wallet.
|
|
20
|
+
/** Base URL of the wallet app (e.g. "https://enbox-wallet.pages.dev"). */
|
|
21
21
|
walletUrl: string;
|
|
22
22
|
|
|
23
23
|
/** The DID to pre-select in the wallet's identity picker. */
|
|
@@ -35,6 +35,27 @@ export interface DWebConnectClientOptions {
|
|
|
35
35
|
* @default 300_000 (5 minutes)
|
|
36
36
|
*/
|
|
37
37
|
timeout?: number;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Display name of the requesting application.
|
|
41
|
+
* Shown in the wallet's permission consent screen.
|
|
42
|
+
*/
|
|
43
|
+
appName?: string;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Icon URL of the requesting application.
|
|
47
|
+
* Shown alongside the app name in the wallet's consent screen.
|
|
48
|
+
*/
|
|
49
|
+
appIcon?: string;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A PortableDid to transfer to the wallet for identity import.
|
|
53
|
+
*
|
|
54
|
+
* When provided, the wallet imports this identity and creates
|
|
55
|
+
* delegate grants for the dapp, allowing the dapp to transition
|
|
56
|
+
* from local-DID mode to delegate mode while keeping the same DID.
|
|
57
|
+
*/
|
|
58
|
+
portableIdentity?: PortableDid;
|
|
38
59
|
}
|
|
39
60
|
|
|
40
61
|
/**
|
|
@@ -43,7 +64,8 @@ export interface DWebConnectClientOptions {
|
|
|
43
64
|
* Protocol:
|
|
44
65
|
* 1. Dapp opens `${walletUrl}/dweb-connect` as a popup.
|
|
45
66
|
* 2. Wallet sends `{ type: 'dweb-connect-loaded' }` when ready.
|
|
46
|
-
* 3. Dapp sends `{ type: 'dweb-connect-authorization-request', did, permissions
|
|
67
|
+
* 3. Dapp sends `{ type: 'dweb-connect-authorization-request', did, permissions,
|
|
68
|
+
* appName?, appIcon?, portableIdentity? }`.
|
|
47
69
|
* 4. Wallet shows consent UI, then sends back
|
|
48
70
|
* `{ type: 'dweb-connect-authorization-response', delegateDid, grants }`.
|
|
49
71
|
* 5. Popup closes.
|
|
@@ -57,11 +79,14 @@ async function initClient(options: DWebConnectClientOptions): Promise<ConnectRes
|
|
|
57
79
|
did,
|
|
58
80
|
permissionRequests,
|
|
59
81
|
timeout = 300_000,
|
|
82
|
+
appName,
|
|
83
|
+
appIcon,
|
|
84
|
+
portableIdentity,
|
|
60
85
|
} = options;
|
|
61
86
|
|
|
62
87
|
if (typeof window === 'undefined') {
|
|
63
88
|
throw new Error(
|
|
64
|
-
'[@enbox/
|
|
89
|
+
'[@enbox/browser] DWeb Connect is only available in browser environments.'
|
|
65
90
|
);
|
|
66
91
|
}
|
|
67
92
|
|
|
@@ -75,7 +100,7 @@ async function initClient(options: DWebConnectClientOptions): Promise<ConnectRes
|
|
|
75
100
|
|
|
76
101
|
if (!popup) {
|
|
77
102
|
throw new Error(
|
|
78
|
-
'[@enbox/
|
|
103
|
+
'[@enbox/browser] Popup blocked. Allow popups for this site to connect to a wallet.'
|
|
79
104
|
);
|
|
80
105
|
}
|
|
81
106
|
|
|
@@ -108,7 +133,7 @@ async function initClient(options: DWebConnectClientOptions): Promise<ConnectRes
|
|
|
108
133
|
cleanup();
|
|
109
134
|
try { popup.close(); } catch { /* best effort */ }
|
|
110
135
|
reject(new Error(
|
|
111
|
-
'[@enbox/
|
|
136
|
+
'[@enbox/browser] DWeb Connect timed out waiting for wallet response.'
|
|
112
137
|
));
|
|
113
138
|
}
|
|
114
139
|
}, timeout);
|
|
@@ -130,12 +155,16 @@ async function initClient(options: DWebConnectClientOptions): Promise<ConnectRes
|
|
|
130
155
|
const { type } = event.data ?? {};
|
|
131
156
|
|
|
132
157
|
if (type === 'dweb-connect-loaded') {
|
|
133
|
-
// Wallet is ready — send the authorization request with
|
|
158
|
+
// Wallet is ready — send the authorization request with
|
|
159
|
+
// ephemeral public key and optional app metadata.
|
|
134
160
|
popup.postMessage({
|
|
135
161
|
type : 'dweb-connect-authorization-request',
|
|
136
162
|
did,
|
|
137
163
|
permissions : permissionRequests,
|
|
138
164
|
ephemeralPublicKey : dappPublicKeyBase64url,
|
|
165
|
+
appName,
|
|
166
|
+
appIcon,
|
|
167
|
+
portableIdentity,
|
|
139
168
|
}, walletOrigin);
|
|
140
169
|
return;
|
|
141
170
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @enbox/browser — The Enbox browser SDK.
|
|
3
|
+
*
|
|
4
|
+
* For browser-based dapps, this is the only package you need to import.
|
|
5
|
+
* It re-exports the high-level API from `@enbox/api`, the authentication
|
|
6
|
+
* layer from `@enbox/auth`, and provides browser-specific connect handlers.
|
|
7
|
+
*
|
|
8
|
+
* @example Single-import dapp setup
|
|
9
|
+
* ```ts
|
|
10
|
+
* import {
|
|
11
|
+
* Enbox, AuthManager, BrowserConnectHandler,
|
|
12
|
+
* defineProtocol, repository,
|
|
13
|
+
* type AuthSession,
|
|
14
|
+
* } from '@enbox/browser';
|
|
15
|
+
*
|
|
16
|
+
* const auth = await AuthManager.create({
|
|
17
|
+
* connectHandler: BrowserConnectHandler({ appName: 'My App' }),
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* const session = await auth.connect({ protocols: [MyProtocol] });
|
|
21
|
+
* const enbox = Enbox.connect({ session });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* For non-browser environments (Node.js, CLI, desktop), import from
|
|
25
|
+
* `@enbox/api` and `@enbox/auth` directly instead.
|
|
26
|
+
*
|
|
27
|
+
* @packageDocumentation
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
// ─── Re-exports from @enbox/api ─────────────────────────────────
|
|
31
|
+
//
|
|
32
|
+
// The high-level Enbox API: DWN records, protocols, repositories.
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
Enbox,
|
|
36
|
+
defineProtocol,
|
|
37
|
+
repository,
|
|
38
|
+
} from '@enbox/api';
|
|
39
|
+
|
|
40
|
+
export type {
|
|
41
|
+
EnboxParams,
|
|
42
|
+
EnboxAnonymousOptions,
|
|
43
|
+
} from '@enbox/api';
|
|
44
|
+
|
|
45
|
+
// ─── Re-exports from @enbox/auth ────────────────────────────────
|
|
46
|
+
//
|
|
47
|
+
// Authentication lifecycle, session management, connect handlers.
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
AuthManager,
|
|
51
|
+
AuthSession,
|
|
52
|
+
normalizeProtocolRequests,
|
|
53
|
+
WalletConnect,
|
|
54
|
+
} from '@enbox/auth';
|
|
55
|
+
|
|
56
|
+
export type {
|
|
57
|
+
AuthEvent,
|
|
58
|
+
AuthEventHandler,
|
|
59
|
+
AuthManagerOptions,
|
|
60
|
+
AuthState,
|
|
61
|
+
ConnectHandler,
|
|
62
|
+
ConnectOptions,
|
|
63
|
+
ConnectResult,
|
|
64
|
+
DisconnectOptions,
|
|
65
|
+
HandlerConnectOptions,
|
|
66
|
+
ImportFromPhraseOptions,
|
|
67
|
+
ImportFromPortableOptions,
|
|
68
|
+
LocalConnectOptions,
|
|
69
|
+
Permission,
|
|
70
|
+
PortableIdentity,
|
|
71
|
+
ProtocolRequest,
|
|
72
|
+
RegistrationOptions,
|
|
73
|
+
StorageAdapter,
|
|
74
|
+
SyncOption,
|
|
75
|
+
WalletConnectOptions,
|
|
76
|
+
} from '@enbox/auth';
|
|
77
|
+
|
|
78
|
+
// ─── Browser-specific exports ───────────────────────────────────
|
|
79
|
+
//
|
|
80
|
+
// DWeb Connect, wallet selector, DRL polyfills.
|
|
81
|
+
|
|
1
82
|
export * from './web-features.js';
|
|
2
83
|
export { BrowserConnectHandler, DEFAULT_WALLETS } from './browser-connect-handler.js';
|
|
3
84
|
export type { BrowserConnectHandlerOptions, WalletOption } from './browser-connect-handler.js';
|
|
4
85
|
export { DWebConnect } from './dweb-connect-client.js';
|
|
5
86
|
export type { DWebConnectClientOptions } from './dweb-connect-client.js';
|
|
6
87
|
export { encryptPostMessagePayload, generateEphemeralKeyPair } from './dweb-connect-crypto.js';
|
|
7
|
-
export type { EncryptedPostMessagePayload } from './dweb-connect-crypto.js';
|
|
88
|
+
export type { EncryptedPostMessagePayload } from './dweb-connect-crypto.js';
|
|
@@ -12,7 +12,7 @@ import type { WalletOption } from '../browser-connect-handler.js';
|
|
|
12
12
|
/** Shows the wallet selector modal and resolves with the chosen wallet URL. */
|
|
13
13
|
export function showWalletSelector(wallets: WalletOption[]): Promise<string> {
|
|
14
14
|
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
15
|
-
throw new Error('[@enbox/
|
|
15
|
+
throw new Error('[@enbox/browser] Wallet selector is only available in browser environments.');
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
return new Promise<string>((resolve, reject) => {
|
|
@@ -52,7 +52,7 @@ export function showWalletSelector(wallets: WalletOption[]): Promise<string> {
|
|
|
52
52
|
closeBtn.innerHTML = '×';
|
|
53
53
|
closeBtn.addEventListener('click', () => {
|
|
54
54
|
cleanup();
|
|
55
|
-
reject(new Error('[@enbox/
|
|
55
|
+
reject(new Error('[@enbox/browser] Wallet selection cancelled.'));
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
header.appendChild(title);
|
|
@@ -74,16 +74,28 @@ export function showWalletSelector(wallets: WalletOption[]): Promise<string> {
|
|
|
74
74
|
icon.height = 32;
|
|
75
75
|
icon.onerror = (): void => { icon.style.display = 'none'; };
|
|
76
76
|
|
|
77
|
+
const textGroup = document.createElement('div');
|
|
78
|
+
textGroup.className = 'wallet-text';
|
|
79
|
+
|
|
77
80
|
const name = document.createElement('span');
|
|
78
81
|
name.className = 'wallet-name';
|
|
79
82
|
name.textContent = wallet.name;
|
|
80
83
|
|
|
84
|
+
textGroup.appendChild(name);
|
|
85
|
+
|
|
86
|
+
if (wallet.description) {
|
|
87
|
+
const desc = document.createElement('span');
|
|
88
|
+
desc.className = 'wallet-description';
|
|
89
|
+
desc.textContent = wallet.description;
|
|
90
|
+
textGroup.appendChild(desc);
|
|
91
|
+
}
|
|
92
|
+
|
|
81
93
|
const arrow = document.createElement('span');
|
|
82
94
|
arrow.className = 'arrow';
|
|
83
95
|
arrow.textContent = '\u203A'; // ›
|
|
84
96
|
|
|
85
97
|
item.appendChild(icon);
|
|
86
|
-
item.appendChild(
|
|
98
|
+
item.appendChild(textGroup);
|
|
87
99
|
item.appendChild(arrow);
|
|
88
100
|
|
|
89
101
|
item.addEventListener('click', () => {
|
|
@@ -152,7 +164,7 @@ export function showWalletSelector(wallets: WalletOption[]): Promise<string> {
|
|
|
152
164
|
overlay.addEventListener('click', (e) => {
|
|
153
165
|
if (e.target === overlay) {
|
|
154
166
|
cleanup();
|
|
155
|
-
reject(new Error('[@enbox/
|
|
167
|
+
reject(new Error('[@enbox/browser] Wallet selection cancelled.'));
|
|
156
168
|
}
|
|
157
169
|
});
|
|
158
170
|
|
|
@@ -161,7 +173,7 @@ export function showWalletSelector(wallets: WalletOption[]): Promise<string> {
|
|
|
161
173
|
if (e.key === 'Escape') {
|
|
162
174
|
document.removeEventListener('keydown', onKeydown);
|
|
163
175
|
cleanup();
|
|
164
|
-
reject(new Error('[@enbox/
|
|
176
|
+
reject(new Error('[@enbox/browser] Wallet selection cancelled.'));
|
|
165
177
|
}
|
|
166
178
|
};
|
|
167
179
|
document.addEventListener('keydown', onKeydown);
|
|
@@ -294,11 +306,28 @@ function buildStyles(isDark: boolean): string {
|
|
|
294
306
|
}
|
|
295
307
|
.wallet-item:hover { background: ${itemHover}; }
|
|
296
308
|
|
|
297
|
-
.wallet-
|
|
309
|
+
.wallet-text {
|
|
310
|
+
flex: 1;
|
|
311
|
+
display: flex;
|
|
312
|
+
flex-direction: column;
|
|
313
|
+
gap: 2px;
|
|
314
|
+
min-width: 0;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
.wallet-name { font-weight: 500; }
|
|
318
|
+
|
|
319
|
+
.wallet-description {
|
|
320
|
+
font-size: 12px;
|
|
321
|
+
color: ${muted};
|
|
322
|
+
white-space: nowrap;
|
|
323
|
+
overflow: hidden;
|
|
324
|
+
text-overflow: ellipsis;
|
|
325
|
+
}
|
|
298
326
|
|
|
299
327
|
.arrow {
|
|
300
328
|
font-size: 20px;
|
|
301
329
|
color: ${muted};
|
|
330
|
+
flex-shrink: 0;
|
|
302
331
|
}
|
|
303
332
|
|
|
304
333
|
.separator {
|