@enbox/browser 0.3.38 → 0.3.40
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 +16 -16
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/browser-connect-handler.js +3 -3
- package/dist/esm/browser-connect-handler.js.map +1 -1
- package/dist/esm/dweb-connect-client.js +267 -190
- package/dist/esm/dweb-connect-client.js.map +1 -1
- package/dist/esm/dweb-connect-messages.js +54 -0
- package/dist/esm/dweb-connect-messages.js.map +1 -0
- package/dist/esm/dweb-connect-wallet.js +209 -0
- package/dist/esm/dweb-connect-wallet.js.map +1 -0
- package/dist/esm/index.js +9 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/ui/wallet-selector.js +6 -2
- package/dist/esm/ui/wallet-selector.js.map +1 -1
- package/dist/types/dweb-connect-client.d.ts +123 -59
- package/dist/types/dweb-connect-client.d.ts.map +1 -1
- package/dist/types/dweb-connect-messages.d.ts +64 -0
- package/dist/types/dweb-connect-messages.d.ts.map +1 -0
- package/dist/types/dweb-connect-wallet.d.ts +101 -0
- package/dist/types/dweb-connect-wallet.d.ts.map +1 -0
- package/dist/types/index.d.ts +8 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/ui/wallet-selector.d.ts.map +1 -1
- package/package.json +9 -6
- package/src/browser-connect-handler.ts +4 -4
- package/src/dweb-connect-client.ts +327 -251
- package/src/dweb-connect-messages.ts +91 -0
- package/src/dweb-connect-wallet.ts +258 -0
- package/src/index.ts +24 -5
- package/src/ui/wallet-selector.ts +7 -2
- package/dist/esm/dweb-connect-crypto.js +0 -112
- package/dist/esm/dweb-connect-crypto.js.map +0 -1
- package/dist/types/dweb-connect-crypto.d.ts +0 -52
- package/dist/types/dweb-connect-crypto.d.ts.map +0 -1
- package/src/dweb-connect-crypto.ts +0 -156
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DWeb Connect wallet transport — the wallet side of the popup/postMessage
|
|
3
|
+
* connect flow, exported for wallet apps (e.g. the Enbox web wallet).
|
|
4
|
+
*
|
|
5
|
+
* A wallet's `/dweb-connect` page creates one transport per session:
|
|
6
|
+
*
|
|
7
|
+
* 1. `create()` generates a fresh ephemeral X25519 key pair and emits the
|
|
8
|
+
* `loaded` beacon (public key + wallet origin) to the opener window with a
|
|
9
|
+
* pinned `targetOrigin`.
|
|
10
|
+
* 2. `awaitRequest()` receives the sealed request ciphertext and opens it via
|
|
11
|
+
* the `@enbox/connect` kernel (`ConnectProvider.openRequest`), which
|
|
12
|
+
* value-checks the `apv` origin binding against this wallet's origin.
|
|
13
|
+
* 3. After the consent ceremony, the wallet posts the sealed response JWE via
|
|
14
|
+
* `sendResponse()` — or the deny token via `deny()` — back to the opener,
|
|
15
|
+
* again with a pinned `targetOrigin`.
|
|
16
|
+
*
|
|
17
|
+
* The dapp origin is never assumed: it is taken from an explicit option or
|
|
18
|
+
* derived from `document.referrer`, and `create()` fails when neither is
|
|
19
|
+
* available. `'*'` is never used as a `targetOrigin`.
|
|
20
|
+
*
|
|
21
|
+
* @module
|
|
22
|
+
*/
|
|
23
|
+
import type { ConnectRequest } from '@enbox/connect';
|
|
24
|
+
/** Options for creating a {@link WalletPostMessageTransport}. */
|
|
25
|
+
export type WalletPostMessageTransportOptions = {
|
|
26
|
+
/**
|
|
27
|
+
* Origin of the dapp that opened this wallet popup. When omitted, it is
|
|
28
|
+
* derived from `document.referrer`; creation fails when neither is
|
|
29
|
+
* available — the transport never falls back to `'*'`.
|
|
30
|
+
*/
|
|
31
|
+
dappOrigin?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The dapp window to exchange messages with.
|
|
34
|
+
* @default window.opener
|
|
35
|
+
*/
|
|
36
|
+
dappWindow?: Window;
|
|
37
|
+
/**
|
|
38
|
+
* Budget in milliseconds for awaiting the dapp's sealed request.
|
|
39
|
+
* @default 300_000 (5 minutes)
|
|
40
|
+
*/
|
|
41
|
+
timeoutMs?: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Wallet-side postMessage transport for the DWeb Connect popup flow.
|
|
45
|
+
*
|
|
46
|
+
* Security properties:
|
|
47
|
+
* - `targetOrigin` of every outbound `postMessage` (beacon and response) is
|
|
48
|
+
* pinned to the dapp origin — never `'*'`.
|
|
49
|
+
* - Inbound messages are dropped unless `event.origin` equals the pinned dapp
|
|
50
|
+
* origin AND `event.source` is the dapp window.
|
|
51
|
+
* - The ephemeral X25519 private key never leaves the transport; the request
|
|
52
|
+
* JWE is opened by the kernel with the `apv` header value-checked against
|
|
53
|
+
* this wallet's own origin.
|
|
54
|
+
*/
|
|
55
|
+
export declare class WalletPostMessageTransport {
|
|
56
|
+
private readonly _dappOrigin;
|
|
57
|
+
private readonly _dappWindow;
|
|
58
|
+
private readonly _recipientPrivateKey;
|
|
59
|
+
private _requestReceived;
|
|
60
|
+
private _timeoutId?;
|
|
61
|
+
private _messageListener?;
|
|
62
|
+
private readonly _requestPromise;
|
|
63
|
+
private _resolveRequest?;
|
|
64
|
+
private _rejectRequest?;
|
|
65
|
+
private constructor();
|
|
66
|
+
/**
|
|
67
|
+
* Creates the transport for one connect session: resolves and pins the dapp
|
|
68
|
+
* origin, generates a fresh ephemeral X25519 key pair, starts listening for
|
|
69
|
+
* the sealed request, and emits the `loaded` beacon to the dapp window.
|
|
70
|
+
*
|
|
71
|
+
* @throws If not in a browser, if no dapp window is available, or if the
|
|
72
|
+
* dapp origin can neither be supplied nor derived from the referrer.
|
|
73
|
+
*/
|
|
74
|
+
static create(options?: WalletPostMessageTransportOptions): Promise<WalletPostMessageTransport>;
|
|
75
|
+
/** The pinned origin of the dapp this transport exchanges messages with. */
|
|
76
|
+
get dappOrigin(): string;
|
|
77
|
+
/**
|
|
78
|
+
* Awaits the dapp's sealed request and opens it via the kernel: ECDH-ES
|
|
79
|
+
* decryption with this session's ephemeral key, `apv` value-checked against
|
|
80
|
+
* this wallet's origin, JWT signature verification, and payload shape
|
|
81
|
+
* assertion. Rejects on timeout, on an unopenable request, or when the
|
|
82
|
+
* request does not use the `post_message` reply mode.
|
|
83
|
+
*/
|
|
84
|
+
awaitRequest(): Promise<ConnectRequest>;
|
|
85
|
+
/**
|
|
86
|
+
* Posts the sealed response JWE (or the deny token) back to the dapp window
|
|
87
|
+
* with the `targetOrigin` pinned to the dapp origin, then closes the
|
|
88
|
+
* transport.
|
|
89
|
+
*
|
|
90
|
+
* @param idToken - The sealed response JWE, or the literal deny token.
|
|
91
|
+
*/
|
|
92
|
+
sendResponse(idToken: string): void;
|
|
93
|
+
/** Posts the deny token back to the dapp — the user rejected the request. */
|
|
94
|
+
deny(): void;
|
|
95
|
+
/** Stops listening and releases the session's timers. Idempotent. */
|
|
96
|
+
close(): void;
|
|
97
|
+
private onMessage;
|
|
98
|
+
private openRequest;
|
|
99
|
+
private settleRequest;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=dweb-connect-wallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dweb-connect-wallet.d.ts","sourceRoot":"","sources":["../../src/dweb-connect-wallet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAgBrD,iEAAiE;AACjE,MAAM,MAAM,iCAAiC,GAAG;IAC9C;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,qBAAa,0BAA0B;IACrC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAM;IAE3C,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,UAAU,CAAC,CAAgC;IACnD,OAAO,CAAC,gBAAgB,CAAC,CAAgC;IAEzD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA0B;IAC1D,OAAO,CAAC,eAAe,CAAC,CAAoC;IAC5D,OAAO,CAAC,cAAc,CAAC,CAAyB;IAEhD,OAAO;IAsBP;;;;;;;OAOG;WACiB,MAAM,CAAC,OAAO,GAAE,iCAAsC,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAgChH,4EAA4E;IAC5E,IAAW,UAAU,IAAI,MAAM,CAE9B;IAED;;;;;;OAMG;IACU,YAAY,IAAI,OAAO,CAAC,cAAc,CAAC;IAIpD;;;;;;OAMG;IACI,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAQ1C,6EAA6E;IACtE,IAAI,IAAI,IAAI;IAInB,qEAAqE;IAC9D,KAAK,IAAI,IAAI;IAQpB,OAAO,CAAC,SAAS;YAeH,WAAW;IAsBzB,OAAO,CAAC,aAAa;CAStB"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -27,12 +27,16 @@ export { Enbox, defineProtocol, repository, } from '@enbox/api';
|
|
|
27
27
|
export type { EnboxAnonymousOptions, EnboxConnectOptions, EnboxConnectResult, EnboxParams, EnboxSessionParams, } from '@enbox/api';
|
|
28
28
|
export { AuthManager, AuthSession, normalizeProtocolRequests, WalletConnect, } from '@enbox/auth/browser';
|
|
29
29
|
export type { AuthEvent, AuthEventHandler, AuthManagerOptions, AuthState, ConnectHandler, ConnectOptions, ConnectResult, DisconnectOptions, HandlerConnectOptions, ImportFromPortableOptions, VaultConnectOptions, Permission, PortableIdentity, ProtocolRequest, RegistrationOptions, StorageAdapter, SyncOption, WalletConnectOptions, } from '@enbox/auth/browser';
|
|
30
|
+
export { CONNECT_DENIED_TOKEN, ConnectProvider } from '@enbox/connect';
|
|
31
|
+
export type { ConnectApproval, ConnectPermissionRequest, ConnectRequest } from '@enbox/connect';
|
|
30
32
|
export * from './web-features.js';
|
|
31
33
|
export { BrowserConnectHandler, DEFAULT_WALLETS } from './browser-connect-handler.js';
|
|
32
34
|
export type { BrowserConnectHandlerOptions, WalletOption } from './browser-connect-handler.js';
|
|
33
|
-
export {
|
|
34
|
-
export type {
|
|
35
|
+
export { connectViaPopup, PopupClientTransport, PopupWindowClosedError } from './dweb-connect-client.js';
|
|
36
|
+
export type { PopupClientTransportOptions, PopupConnectOptions } from './dweb-connect-client.js';
|
|
37
|
+
export { WalletPostMessageTransport } from './dweb-connect-wallet.js';
|
|
38
|
+
export type { WalletPostMessageTransportOptions } from './dweb-connect-wallet.js';
|
|
39
|
+
export { DWEB_CONNECT_LOADED_MESSAGE_TYPE, DWEB_CONNECT_PATH, DWEB_CONNECT_REQUEST_MESSAGE_TYPE, DWEB_CONNECT_RESPONSE_MESSAGE_TYPE, } from './dweb-connect-messages.js';
|
|
40
|
+
export type { DWebConnectLoadedMessage, DWebConnectRequestMessage, DWebConnectResponseMessage, } from './dweb-connect-messages.js';
|
|
35
41
|
export { showWalletSelector } from './ui/wallet-selector.js';
|
|
36
|
-
export { encryptPostMessagePayload, generateEphemeralKeyPair } from './dweb-connect-crypto.js';
|
|
37
|
-
export type { EncryptedPostMessagePayload } from './dweb-connect-crypto.js';
|
|
38
42
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAMH,OAAO,EACL,KAAK,EACL,cAAc,EACd,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,WAAW,EACX,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAMpB,OAAO,EACL,WAAW,EACX,WAAW,EACX,yBAAyB,EACzB,aAAa,GACd,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,kBAAkB,EAClB,SAAS,EACT,cAAc,EACd,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,EACnB,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,UAAU,EACV,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAMH,OAAO,EACL,KAAK,EACL,cAAc,EACd,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,WAAW,EACX,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAMpB,OAAO,EACL,WAAW,EACX,WAAW,EACX,yBAAyB,EACzB,aAAa,GACd,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,kBAAkB,EAClB,SAAS,EACT,cAAc,EACd,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,EACnB,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,UAAU,EACV,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAO7B,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACvE,YAAY,EAAE,eAAe,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAMhG,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,eAAe,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACzG,YAAY,EAAE,2BAA2B,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACjG,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AACtE,YAAY,EAAE,iCAAiC,EAAE,MAAM,0BAA0B,CAAC;AAClF,OAAO,EACL,gCAAgC,EAChC,iBAAiB,EACjB,iCAAiC,EACjC,kCAAkC,GACnC,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,wBAAwB,EACxB,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,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,CAoL3E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enbox/browser",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.40",
|
|
4
4
|
"description": "Enbox tools and features to use in the browser",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/esm/index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"clean": "rm -rf dist",
|
|
13
13
|
"build:esm": "rm -rf dist/esm dist/types && bun tsc -p tsconfig.json",
|
|
14
|
-
"build:browser": "rm -rf dist/browser.mjs && bun ../../build/browser-bundle.js --metafile --external @enbox/agent --external @enbox/api --external @enbox/auth --external @enbox/auth/browser --external @enbox/dids",
|
|
14
|
+
"build:browser": "rm -rf dist/browser.mjs && bun ../../build/browser-bundle.js --metafile --external @enbox/agent --external @enbox/api --external @enbox/auth --external @enbox/auth/browser --external @enbox/common --external @enbox/connect --external @enbox/crypto --external @enbox/dids",
|
|
15
15
|
"build": "bun run clean && bun run build:esm && bun run build:browser",
|
|
16
16
|
"lint": "eslint . --max-warnings 0",
|
|
17
17
|
"lint:fix": "eslint . --fix",
|
|
@@ -66,10 +66,13 @@
|
|
|
66
66
|
"access": "public"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@enbox/agent": "0.8.
|
|
70
|
-
"@enbox/api": "0.6.
|
|
71
|
-
"@enbox/auth": "0.6.
|
|
72
|
-
"@enbox/
|
|
69
|
+
"@enbox/agent": "0.8.16",
|
|
70
|
+
"@enbox/api": "0.6.54",
|
|
71
|
+
"@enbox/auth": "0.6.62",
|
|
72
|
+
"@enbox/common": "0.1.3",
|
|
73
|
+
"@enbox/connect": "0.1.1",
|
|
74
|
+
"@enbox/crypto": "0.1.5",
|
|
75
|
+
"@enbox/dids": "0.1.5"
|
|
73
76
|
},
|
|
74
77
|
"devDependencies": {
|
|
75
78
|
"@typescript-eslint/eslint-plugin": "8.32.1",
|
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type { ConnectPermissionRequest } from '@enbox/
|
|
10
|
+
import type { ConnectPermissionRequest } from '@enbox/connect';
|
|
11
11
|
import type { ConnectHandler, ConnectResult } from '@enbox/auth';
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import { connectViaPopup } from './dweb-connect-client.js';
|
|
14
14
|
import { showWalletSelector } from './ui/wallet-selector.js';
|
|
15
15
|
|
|
16
16
|
/** A wallet entry shown in the wallet selector modal. */
|
|
@@ -121,8 +121,8 @@ export function BrowserConnectHandler(
|
|
|
121
121
|
walletUrl = await showWalletSelector(wallets);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
// 2. Run the DWeb Connect popup flow.
|
|
125
|
-
return
|
|
124
|
+
// 2. Run the DWeb Connect popup flow over the connect kernel.
|
|
125
|
+
return connectViaPopup({
|
|
126
126
|
walletUrl,
|
|
127
127
|
permissionRequests: params.permissionRequests,
|
|
128
128
|
timeout,
|