@aztec/wallet-sdk 0.0.1-commit.f295ac2 → 0.0.1-commit.fc805bf
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/README.md +217 -294
- package/dest/base-wallet/base_wallet.d.ts +20 -7
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +29 -11
- package/dest/crypto.d.ts +59 -50
- package/dest/crypto.d.ts.map +1 -1
- package/dest/crypto.js +202 -108
- package/dest/emoji_alphabet.d.ts +35 -0
- package/dest/emoji_alphabet.d.ts.map +1 -0
- package/dest/emoji_alphabet.js +299 -0
- package/dest/extension/handlers/background_connection_handler.d.ts +158 -0
- package/dest/extension/handlers/background_connection_handler.d.ts.map +1 -0
- package/dest/extension/handlers/background_connection_handler.js +258 -0
- package/dest/extension/handlers/content_script_connection_handler.d.ts +56 -0
- package/dest/extension/handlers/content_script_connection_handler.d.ts.map +1 -0
- package/dest/extension/handlers/content_script_connection_handler.js +174 -0
- package/dest/extension/handlers/index.d.ts +12 -0
- package/dest/extension/handlers/index.d.ts.map +1 -0
- package/dest/extension/handlers/index.js +10 -0
- package/dest/extension/handlers/internal_message_types.d.ts +63 -0
- package/dest/extension/handlers/internal_message_types.d.ts.map +1 -0
- package/dest/extension/handlers/internal_message_types.js +22 -0
- package/dest/extension/provider/extension_provider.d.ts +107 -0
- package/dest/extension/provider/extension_provider.d.ts.map +1 -0
- package/dest/extension/provider/extension_provider.js +160 -0
- package/dest/extension/provider/extension_wallet.d.ts +131 -0
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -0
- package/dest/{providers/extension → extension/provider}/extension_wallet.js +48 -95
- package/dest/extension/provider/index.d.ts +3 -0
- package/dest/extension/provider/index.d.ts.map +1 -0
- package/dest/{providers/extension → extension/provider}/index.js +0 -2
- package/dest/manager/index.d.ts +2 -8
- package/dest/manager/index.d.ts.map +1 -1
- package/dest/manager/index.js +0 -6
- package/dest/manager/types.d.ts +88 -6
- package/dest/manager/types.d.ts.map +1 -1
- package/dest/manager/types.js +17 -1
- package/dest/manager/wallet_manager.d.ts +50 -7
- package/dest/manager/wallet_manager.d.ts.map +1 -1
- package/dest/manager/wallet_manager.js +174 -44
- package/dest/types.d.ts +43 -12
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +3 -2
- package/package.json +10 -9
- package/src/base-wallet/base_wallet.ts +45 -20
- package/src/crypto.ts +237 -113
- package/src/emoji_alphabet.ts +317 -0
- package/src/extension/handlers/background_connection_handler.ts +423 -0
- package/src/extension/handlers/content_script_connection_handler.ts +246 -0
- package/src/extension/handlers/index.ts +25 -0
- package/src/extension/handlers/internal_message_types.ts +69 -0
- package/src/extension/provider/extension_provider.ts +233 -0
- package/src/{providers/extension → extension/provider}/extension_wallet.ts +52 -110
- package/src/extension/provider/index.ts +7 -0
- package/src/manager/index.ts +2 -10
- package/src/manager/types.ts +91 -5
- package/src/manager/wallet_manager.ts +192 -46
- package/src/types.ts +44 -10
- package/dest/providers/extension/extension_provider.d.ts +0 -63
- package/dest/providers/extension/extension_provider.d.ts.map +0 -1
- package/dest/providers/extension/extension_provider.js +0 -124
- package/dest/providers/extension/extension_wallet.d.ts +0 -155
- package/dest/providers/extension/extension_wallet.d.ts.map +0 -1
- package/dest/providers/extension/index.d.ts +0 -6
- package/dest/providers/extension/index.d.ts.map +0 -1
- package/src/providers/extension/extension_provider.ts +0 -167
- package/src/providers/extension/index.ts +0 -5
package/src/manager/types.ts
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
import type { ChainInfo } from '@aztec/aztec.js/account';
|
|
2
2
|
import type { Wallet } from '@aztec/aztec.js/wallet';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* A pending connection that requires user verification before finalizing.
|
|
6
|
+
*
|
|
7
|
+
* After key exchange, both dApp and wallet compute a verification hash independently.
|
|
8
|
+
* The dApp should display this hash (typically as emojis) and let the user confirm
|
|
9
|
+
* it matches what's shown in their wallet before calling `confirm()`.
|
|
10
|
+
*
|
|
11
|
+
* This protects the dApp from connecting to a malicious wallet that might be
|
|
12
|
+
* intercepting the connection (MITM attack).
|
|
13
|
+
*/
|
|
14
|
+
export interface PendingConnection {
|
|
15
|
+
/**
|
|
16
|
+
* The verification hash computed from the shared secret.
|
|
17
|
+
* Use `hashToEmoji()` to convert to a visual representation for user verification.
|
|
18
|
+
* The user should confirm this matches what their wallet displays.
|
|
19
|
+
*/
|
|
20
|
+
verificationHash: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Confirms the connection after user verifies the emojis match.
|
|
24
|
+
* @returns The connected wallet instance
|
|
25
|
+
*/
|
|
26
|
+
confirm(): Promise<Wallet>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Cancels the pending connection.
|
|
30
|
+
* Call this if the user indicates the emojis don't match.
|
|
31
|
+
*/
|
|
32
|
+
cancel(): void;
|
|
33
|
+
}
|
|
34
|
+
|
|
4
35
|
/**
|
|
5
36
|
* Configuration for extension wallets
|
|
6
37
|
*/
|
|
@@ -34,7 +65,7 @@ export interface WalletManagerConfig {
|
|
|
34
65
|
/**
|
|
35
66
|
* Type of wallet provider
|
|
36
67
|
*/
|
|
37
|
-
export type WalletProviderType = 'extension' | 'web'
|
|
68
|
+
export type WalletProviderType = 'extension' | 'web';
|
|
38
69
|
|
|
39
70
|
/**
|
|
40
71
|
* Callback type for wallet disconnect events at the provider level.
|
|
@@ -57,13 +88,32 @@ export interface WalletProvider {
|
|
|
57
88
|
/** Additional metadata */
|
|
58
89
|
metadata?: Record<string, unknown>;
|
|
59
90
|
/**
|
|
60
|
-
*
|
|
91
|
+
* Establishes a secure channel with this wallet provider.
|
|
92
|
+
*
|
|
93
|
+
* This performs the ECDH key exchange and returns a pending connection with the
|
|
94
|
+
* verification hash. The channel is encrypted but NOT yet verified - the dApp
|
|
95
|
+
* should display the hash (as emojis) to the user and let them confirm it
|
|
96
|
+
* matches their wallet before calling `confirm()`.
|
|
97
|
+
*
|
|
61
98
|
* @param appId - Application identifier for the requesting dapp
|
|
99
|
+
* @returns A pending connection with verification hash and confirm/cancel methods
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* const pending = await provider.establishSecureChannel('my-app');
|
|
104
|
+
*
|
|
105
|
+
* // Show emojis to user for verification
|
|
106
|
+
* const emojis = hashToEmoji(pending.verificationHash);
|
|
107
|
+
* showDialog(`Verify these match your wallet: ${emojis}`);
|
|
108
|
+
*
|
|
109
|
+
* // User confirms emojis match
|
|
110
|
+
* const wallet = await pending.confirm();
|
|
111
|
+
* ```
|
|
62
112
|
*/
|
|
63
|
-
|
|
113
|
+
establishSecureChannel(appId: string): Promise<PendingConnection>;
|
|
64
114
|
/**
|
|
65
115
|
* Disconnects the current wallet and cleans up resources.
|
|
66
|
-
* After calling this, the wallet returned from
|
|
116
|
+
* After calling this, the wallet returned from confirm() should no longer be used.
|
|
67
117
|
* @returns A promise that resolves when disconnection is complete
|
|
68
118
|
*/
|
|
69
119
|
disconnect?(): Promise<void>;
|
|
@@ -86,6 +136,42 @@ export interface WalletProvider {
|
|
|
86
136
|
export interface DiscoverWalletsOptions {
|
|
87
137
|
/** Chain information to filter by */
|
|
88
138
|
chainInfo: ChainInfo;
|
|
89
|
-
/**
|
|
139
|
+
/** Application ID making the request */
|
|
140
|
+
appId: string;
|
|
141
|
+
/** Discovery timeout in milliseconds. Default: 60000 (60s) */
|
|
90
142
|
timeout?: number;
|
|
143
|
+
/**
|
|
144
|
+
* Callback invoked when a wallet provider is discovered.
|
|
145
|
+
* Use this to show wallets to users as they approve them, rather than
|
|
146
|
+
* waiting for the full timeout.
|
|
147
|
+
*/
|
|
148
|
+
onWalletDiscovered?: (provider: WalletProvider) => void;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* A cancellable discovery session.
|
|
153
|
+
*
|
|
154
|
+
* Returned by `WalletManager.getAvailableWallets()` to allow consumers to
|
|
155
|
+
* cancel discovery when no longer needed (e.g., network changes, user navigates away).
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const discovery = WalletManager.configure({...}).getAvailableWallets({...});
|
|
160
|
+
*
|
|
161
|
+
* // Iterate over discovered wallets
|
|
162
|
+
* for await (const wallet of discovery.wallets) {
|
|
163
|
+
* console.log(`Found: ${wallet.name}`);
|
|
164
|
+
* }
|
|
165
|
+
*
|
|
166
|
+
* // Cancel discovery when no longer needed
|
|
167
|
+
* discovery.cancel();
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export interface DiscoverySession {
|
|
171
|
+
/** Async iterator that yields wallet providers as they're discovered */
|
|
172
|
+
wallets: AsyncIterable<WalletProvider>;
|
|
173
|
+
/** Promise that resolves when discovery completes or is cancelled */
|
|
174
|
+
done: Promise<void>;
|
|
175
|
+
/** Cancel discovery immediately and clean up resources */
|
|
176
|
+
cancel: () => void;
|
|
91
177
|
}
|
|
@@ -1,14 +1,48 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ChainInfo } from '@aztec/aztec.js/account';
|
|
2
|
+
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
3
|
+
|
|
4
|
+
import { type DiscoveredWallet, ExtensionProvider, ExtensionWallet } from '../extension/provider/index.js';
|
|
5
|
+
import { WalletMessageType } from '../types.js';
|
|
2
6
|
import type {
|
|
3
7
|
DiscoverWalletsOptions,
|
|
8
|
+
DiscoverySession,
|
|
4
9
|
ExtensionWalletConfig,
|
|
10
|
+
PendingConnection,
|
|
5
11
|
ProviderDisconnectionCallback,
|
|
6
12
|
WalletManagerConfig,
|
|
7
13
|
WalletProvider,
|
|
8
14
|
} from './types.js';
|
|
9
15
|
|
|
10
16
|
/**
|
|
11
|
-
* Manager for wallet discovery, configuration, and connection
|
|
17
|
+
* Manager for wallet discovery, configuration, and connection.
|
|
18
|
+
*
|
|
19
|
+
* This is the main entry point for dApps to discover and connect to wallets.
|
|
20
|
+
*
|
|
21
|
+
* @example Basic usage with async iterator
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const discovery = WalletManager.configure({ extensions: { enabled: true } })
|
|
24
|
+
* .getAvailableWallets({ chainInfo, appId: 'my-app' });
|
|
25
|
+
*
|
|
26
|
+
* // Iterate over discovered wallets
|
|
27
|
+
* for await (const provider of discovery.wallets) {
|
|
28
|
+
* console.log(`Found wallet: ${provider.name}`);
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* // Or cancel early when done
|
|
32
|
+
* discovery.cancel();
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example With callback for discovered wallets
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const discovery = manager.getAvailableWallets({
|
|
38
|
+
* chainInfo,
|
|
39
|
+
* appId: 'my-app',
|
|
40
|
+
* onWalletDiscovered: (provider) => console.log(`Found: ${provider.name}`),
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // Wait for discovery to complete or cancel it
|
|
44
|
+
* await discovery.done;
|
|
45
|
+
* ```
|
|
12
46
|
*/
|
|
13
47
|
export class WalletManager {
|
|
14
48
|
private config: WalletManagerConfig = {
|
|
@@ -33,65 +67,177 @@ export class WalletManager {
|
|
|
33
67
|
|
|
34
68
|
/**
|
|
35
69
|
* Discovers all available wallets for a given chain and version.
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
70
|
+
*
|
|
71
|
+
* Returns a `DiscoverySession` with:
|
|
72
|
+
* - `wallets`: AsyncIterable to iterate over discovered wallets
|
|
73
|
+
* - `done`: Promise that resolves when discovery completes or is cancelled
|
|
74
|
+
* - `cancel()`: Function to stop discovery immediately
|
|
75
|
+
*
|
|
76
|
+
* If `onWalletDiscovered` callback is provided, wallets are also streamed via callback.
|
|
77
|
+
*
|
|
78
|
+
* @param options - Discovery options including chain info, appId, and timeout
|
|
79
|
+
* @returns A cancellable discovery session
|
|
39
80
|
*/
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const
|
|
81
|
+
getAvailableWallets(options: DiscoverWalletsOptions): DiscoverySession {
|
|
82
|
+
const { chainInfo, appId } = options;
|
|
83
|
+
const abortController = new AbortController();
|
|
84
|
+
|
|
85
|
+
const pendingProviders: WalletProvider[] = [];
|
|
86
|
+
let pendingResolve: ((result: IteratorResult<WalletProvider>) => void) | null = null;
|
|
87
|
+
let completed = false;
|
|
88
|
+
|
|
89
|
+
const { promise: donePromise, resolve: resolveDone } = promiseWithResolvers<void>();
|
|
90
|
+
|
|
91
|
+
const markComplete = () => {
|
|
92
|
+
completed = true;
|
|
93
|
+
resolveDone();
|
|
94
|
+
if (pendingResolve) {
|
|
95
|
+
const resolve = pendingResolve;
|
|
96
|
+
pendingResolve = null;
|
|
97
|
+
resolve({ value: undefined, done: true });
|
|
98
|
+
}
|
|
99
|
+
};
|
|
43
100
|
|
|
44
101
|
if (this.config.extensions?.enabled) {
|
|
45
|
-
const discoveredWallets = await ExtensionProvider.discoverExtensions(chainInfo, options.timeout);
|
|
46
102
|
const extensionConfig = this.config.extensions;
|
|
47
103
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
104
|
+
void ExtensionProvider.discoverWallets(chainInfo, {
|
|
105
|
+
appId,
|
|
106
|
+
timeout: options.timeout,
|
|
107
|
+
signal: abortController.signal,
|
|
108
|
+
onWalletDiscovered: discoveredWallet => {
|
|
109
|
+
const provider = this.createProviderFromDiscoveredWallet(discoveredWallet, chainInfo, extensionConfig);
|
|
110
|
+
if (!provider) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
52
113
|
|
|
53
|
-
|
|
114
|
+
// Call user's callback if provided
|
|
115
|
+
options.onWalletDiscovered?.(provider);
|
|
54
116
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
return
|
|
117
|
+
// Also queue for async iterator
|
|
118
|
+
if (pendingResolve) {
|
|
119
|
+
const resolve = pendingResolve;
|
|
120
|
+
pendingResolve = null;
|
|
121
|
+
resolve({ value: provider, done: false });
|
|
122
|
+
} else {
|
|
123
|
+
pendingProviders.push(provider);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
}).then(markComplete);
|
|
127
|
+
} else {
|
|
128
|
+
markComplete();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const wallets: AsyncIterable<WalletProvider> = {
|
|
132
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
133
|
+
[Symbol.asyncIterator](): AsyncIterator<WalletProvider> {
|
|
134
|
+
return {
|
|
135
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
136
|
+
next(): Promise<IteratorResult<WalletProvider>> {
|
|
137
|
+
if (pendingProviders.length > 0) {
|
|
138
|
+
return Promise.resolve({ value: pendingProviders.shift()!, done: false });
|
|
77
139
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (extensionWallet) {
|
|
82
|
-
return extensionWallet.isDisconnected();
|
|
140
|
+
|
|
141
|
+
if (completed) {
|
|
142
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
83
143
|
}
|
|
84
|
-
|
|
144
|
+
|
|
145
|
+
return new Promise(resolve => {
|
|
146
|
+
pendingResolve = resolve;
|
|
147
|
+
});
|
|
85
148
|
},
|
|
86
149
|
};
|
|
150
|
+
},
|
|
151
|
+
};
|
|
87
152
|
|
|
88
|
-
|
|
89
|
-
|
|
153
|
+
return {
|
|
154
|
+
wallets,
|
|
155
|
+
done: donePromise,
|
|
156
|
+
cancel: () => abortController.abort(),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Creates a WalletProvider from a discovered wallet.
|
|
162
|
+
* Returns null if the wallet is not allowed by config.
|
|
163
|
+
* @param discoveredWallet - The discovered wallet from extension discovery.
|
|
164
|
+
* @param chainInfo - Network information.
|
|
165
|
+
* @param extensionConfig - Extension wallet configuration.
|
|
166
|
+
*/
|
|
167
|
+
private createProviderFromDiscoveredWallet(
|
|
168
|
+
discoveredWallet: DiscoveredWallet,
|
|
169
|
+
chainInfo: ChainInfo,
|
|
170
|
+
extensionConfig: ExtensionWalletConfig,
|
|
171
|
+
): WalletProvider | null {
|
|
172
|
+
const { info } = discoveredWallet;
|
|
173
|
+
|
|
174
|
+
if (!this.isExtensionAllowed(info.id, extensionConfig)) {
|
|
175
|
+
return null;
|
|
90
176
|
}
|
|
91
177
|
|
|
92
|
-
|
|
178
|
+
let extensionWallet: ExtensionWallet | null = null;
|
|
179
|
+
|
|
180
|
+
const provider: WalletProvider = {
|
|
181
|
+
id: info.id,
|
|
182
|
+
type: 'extension',
|
|
183
|
+
name: info.name,
|
|
184
|
+
icon: info.icon,
|
|
185
|
+
metadata: {
|
|
186
|
+
version: info.version,
|
|
187
|
+
},
|
|
188
|
+
establishSecureChannel: async (connectAppId: string): Promise<PendingConnection> => {
|
|
189
|
+
const connection = await discoveredWallet.establishSecureChannel();
|
|
190
|
+
|
|
191
|
+
provider.metadata = {
|
|
192
|
+
...provider.metadata,
|
|
193
|
+
verificationHash: connection.info.verificationHash,
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
verificationHash: connection.info.verificationHash!,
|
|
198
|
+
confirm: () => {
|
|
199
|
+
return Promise.resolve(
|
|
200
|
+
ExtensionWallet.create(
|
|
201
|
+
connection.info.id,
|
|
202
|
+
connection.port,
|
|
203
|
+
connection.sharedKey,
|
|
204
|
+
chainInfo,
|
|
205
|
+
connectAppId,
|
|
206
|
+
),
|
|
207
|
+
);
|
|
208
|
+
},
|
|
209
|
+
cancel: () => {
|
|
210
|
+
// Send disconnect to terminate the session on the extension side
|
|
211
|
+
// but keep the port open so we can retry key exchange
|
|
212
|
+
connection.port.postMessage({
|
|
213
|
+
type: WalletMessageType.DISCONNECT,
|
|
214
|
+
requestId: discoveredWallet.requestId,
|
|
215
|
+
});
|
|
216
|
+
// Don't close the port - allow retry with fresh key exchange
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
},
|
|
220
|
+
disconnect: async () => {
|
|
221
|
+
if (extensionWallet) {
|
|
222
|
+
await extensionWallet.disconnect();
|
|
223
|
+
extensionWallet = null;
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
onDisconnect: (callback: ProviderDisconnectionCallback) => {
|
|
227
|
+
if (extensionWallet) {
|
|
228
|
+
return extensionWallet.onDisconnect(callback);
|
|
229
|
+
}
|
|
230
|
+
return () => {};
|
|
231
|
+
},
|
|
232
|
+
isDisconnected: () => {
|
|
233
|
+
if (extensionWallet) {
|
|
234
|
+
return extensionWallet.isDisconnected();
|
|
235
|
+
}
|
|
236
|
+
return true;
|
|
237
|
+
},
|
|
238
|
+
};
|
|
93
239
|
|
|
94
|
-
return
|
|
240
|
+
return provider;
|
|
95
241
|
}
|
|
96
242
|
|
|
97
243
|
/**
|
package/src/types.ts
CHANGED
|
@@ -11,14 +11,17 @@ export enum WalletMessageType {
|
|
|
11
11
|
DISCOVERY = 'aztec-wallet-discovery',
|
|
12
12
|
/** Discovery response from a wallet */
|
|
13
13
|
DISCOVERY_RESPONSE = 'aztec-wallet-discovery-response',
|
|
14
|
-
/**
|
|
15
|
-
SESSION_DISCONNECTED = 'aztec-wallet-session-disconnected',
|
|
16
|
-
/** Explicit disconnect request from dApp */
|
|
14
|
+
/** Disconnect message (unencrypted control message, bidirectional) */
|
|
17
15
|
DISCONNECT = 'aztec-wallet-disconnect',
|
|
16
|
+
/** Key exchange request sent over MessageChannel */
|
|
17
|
+
KEY_EXCHANGE_REQUEST = 'aztec-wallet-key-exchange-request',
|
|
18
|
+
/** Key exchange response sent over MessageChannel */
|
|
19
|
+
KEY_EXCHANGE_RESPONSE = 'aztec-wallet-key-exchange-response',
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
|
-
* Information about an installed Aztec wallet
|
|
23
|
+
* Information about an installed Aztec wallet.
|
|
24
|
+
* Used during discovery phase before key exchange.
|
|
22
25
|
*/
|
|
23
26
|
export interface WalletInfo {
|
|
24
27
|
/** Unique identifier for the wallet */
|
|
@@ -29,10 +32,17 @@ export interface WalletInfo {
|
|
|
29
32
|
icon?: string;
|
|
30
33
|
/** Wallet version */
|
|
31
34
|
version: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Full information about a connected Aztec wallet including crypto material.
|
|
39
|
+
* Available after key exchange completes.
|
|
40
|
+
*/
|
|
41
|
+
export interface ConnectedWalletInfo extends WalletInfo {
|
|
32
42
|
/** Wallet's ECDH public key for secure channel establishment */
|
|
33
43
|
publicKey: ExportedPublicKey;
|
|
34
44
|
/**
|
|
35
|
-
*
|
|
45
|
+
* Verification hash for verification.
|
|
36
46
|
* Both dApp and wallet independently compute this from the ECDH shared secret.
|
|
37
47
|
* Use {@link hashToEmoji} to convert to a visual representation for user verification.
|
|
38
48
|
*/
|
|
@@ -72,27 +82,51 @@ export interface WalletResponse {
|
|
|
72
82
|
}
|
|
73
83
|
|
|
74
84
|
/**
|
|
75
|
-
* Discovery message for finding installed wallets (public, unencrypted)
|
|
85
|
+
* Discovery message for finding installed wallets (public, unencrypted).
|
|
76
86
|
*/
|
|
77
87
|
export interface DiscoveryRequest {
|
|
78
88
|
/** Message type for discovery */
|
|
79
89
|
type: WalletMessageType.DISCOVERY;
|
|
80
90
|
/** Request ID */
|
|
81
91
|
requestId: string;
|
|
92
|
+
/** Application ID making the request */
|
|
93
|
+
appId: string;
|
|
82
94
|
/** Chain information to check if wallet supports this network */
|
|
83
95
|
chainInfo: ChainInfo;
|
|
84
|
-
/** dApp's ECDH public key for deriving shared secret */
|
|
85
|
-
publicKey: ExportedPublicKey;
|
|
86
96
|
}
|
|
87
97
|
|
|
88
98
|
/**
|
|
89
|
-
* Discovery response from a wallet (public, unencrypted)
|
|
99
|
+
* Discovery response from a wallet (public, unencrypted).
|
|
90
100
|
*/
|
|
91
101
|
export interface DiscoveryResponse {
|
|
92
102
|
/** Message type for discovery response */
|
|
93
103
|
type: WalletMessageType.DISCOVERY_RESPONSE;
|
|
94
104
|
/** Request ID matching the discovery request */
|
|
95
105
|
requestId: string;
|
|
96
|
-
/**
|
|
106
|
+
/** Basic wallet information */
|
|
97
107
|
walletInfo: WalletInfo;
|
|
98
108
|
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Key exchange request sent over MessageChannel after discovery approval.
|
|
112
|
+
*/
|
|
113
|
+
export interface KeyExchangeRequest {
|
|
114
|
+
/** Message type */
|
|
115
|
+
type: WalletMessageType.KEY_EXCHANGE_REQUEST;
|
|
116
|
+
/** Request ID matching the discovery request */
|
|
117
|
+
requestId: string;
|
|
118
|
+
/** dApp's ECDH public key for deriving shared secret */
|
|
119
|
+
publicKey: ExportedPublicKey;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Key exchange response sent over MessageChannel.
|
|
124
|
+
*/
|
|
125
|
+
export interface KeyExchangeResponse {
|
|
126
|
+
/** Message type */
|
|
127
|
+
type: WalletMessageType.KEY_EXCHANGE_RESPONSE;
|
|
128
|
+
/** Request ID matching the discovery request */
|
|
129
|
+
requestId: string;
|
|
130
|
+
/** Wallet's ECDH public key for deriving shared secret */
|
|
131
|
+
publicKey: ExportedPublicKey;
|
|
132
|
+
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { ChainInfo } from '@aztec/aztec.js/account';
|
|
2
|
-
import { type WalletInfo } from '../../types.js';
|
|
3
|
-
/**
|
|
4
|
-
* A discovered wallet with its secure channel components.
|
|
5
|
-
* Returned by {@link ExtensionProvider.discoverExtensions}.
|
|
6
|
-
*/
|
|
7
|
-
export interface DiscoveredWallet {
|
|
8
|
-
/** Basic wallet information (id, name, icon, version, publicKey, verificationHash) */
|
|
9
|
-
info: WalletInfo;
|
|
10
|
-
/** The MessagePort for private communication with the wallet */
|
|
11
|
-
port: MessagePort;
|
|
12
|
-
/** The derived AES-256-GCM shared key for encryption */
|
|
13
|
-
sharedKey: CryptoKey;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Provider for discovering Aztec wallet extensions.
|
|
17
|
-
*
|
|
18
|
-
* This class handles the discovery phase of wallet communication:
|
|
19
|
-
* 1. Broadcasts a discovery request with the dApp's public key
|
|
20
|
-
* 2. Receives responses from installed wallets with their public keys
|
|
21
|
-
* 3. Derives shared secrets and computes verification hashes
|
|
22
|
-
* 4. Returns discovered wallets with their secure channel components
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```typescript
|
|
26
|
-
* const wallets = await ExtensionProvider.discoverExtensions(chainInfo);
|
|
27
|
-
* // Display wallets to user with optional emoji verification
|
|
28
|
-
* for (const wallet of wallets) {
|
|
29
|
-
* const emoji = hashToEmoji(wallet.info.verificationHash!);
|
|
30
|
-
* console.log(`${wallet.info.name}: ${emoji}`);
|
|
31
|
-
* }
|
|
32
|
-
* // User selects a wallet after verifying
|
|
33
|
-
* const wallet = await ExtensionWallet.create(wallets[0], chainInfo, 'my-app');
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare class ExtensionProvider {
|
|
37
|
-
private static discoveryInProgress;
|
|
38
|
-
/**
|
|
39
|
-
* Discovers all installed Aztec wallet extensions and establishes secure channel components.
|
|
40
|
-
*
|
|
41
|
-
* This method:
|
|
42
|
-
* 1. Generates an ECDH key pair for this discovery session
|
|
43
|
-
* 2. Broadcasts a discovery request with the dApp's public key
|
|
44
|
-
* 3. Receives responses from wallets with their public keys and MessagePorts
|
|
45
|
-
* 4. Derives shared secrets and computes verification hashes
|
|
46
|
-
*
|
|
47
|
-
* @param chainInfo - Chain information to check if extensions support this network
|
|
48
|
-
* @param timeout - How long to wait for extensions to respond (ms)
|
|
49
|
-
* @returns Array of discovered wallets with their secure channel components
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* const wallets = await ExtensionProvider.discoverExtensions({
|
|
54
|
-
* chainId: Fr(31337),
|
|
55
|
-
* version: Fr(0)
|
|
56
|
-
* });
|
|
57
|
-
* // Access wallet info and secure channel
|
|
58
|
-
* const { info, port, sharedKey } = wallets[0];
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
static discoverExtensions(chainInfo: ChainInfo, timeout?: number): Promise<DiscoveredWallet[]>;
|
|
62
|
-
}
|
|
63
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXh0ZW5zaW9uX3Byb3ZpZGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvcHJvdmlkZXJzL2V4dGVuc2lvbi9leHRlbnNpb25fcHJvdmlkZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFLekQsT0FBTyxFQUFpRCxLQUFLLFVBQVUsRUFBcUIsTUFBTSxnQkFBZ0IsQ0FBQztBQUVuSDs7O0dBR0c7QUFDSCxNQUFNLFdBQVcsZ0JBQWdCO0lBQy9CLHNGQUFzRjtJQUN0RixJQUFJLEVBQUUsVUFBVSxDQUFDO0lBQ2pCLGdFQUFnRTtJQUNoRSxJQUFJLEVBQUUsV0FBVyxDQUFDO0lBQ2xCLHdEQUF3RDtJQUN4RCxTQUFTLEVBQUUsU0FBUyxDQUFDO0NBQ3RCO0FBV0Q7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBb0JHO0FBQ0gscUJBQWEsaUJBQWlCO0lBQzVCLE9BQU8sQ0FBQyxNQUFNLENBQUMsbUJBQW1CLENBQVM7SUFFM0M7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7T0FzQkc7SUFDSCxPQUFhLGtCQUFrQixDQUFDLFNBQVMsRUFBRSxTQUFTLEVBQUUsT0FBTyxHQUFFLE1BQWEsR0FBRyxPQUFPLENBQUMsZ0JBQWdCLEVBQUUsQ0FBQyxDQXlGekc7Q0FDRiJ9
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extension_provider.d.ts","sourceRoot":"","sources":["../../../src/providers/extension/extension_provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAKzD,OAAO,EAAiD,KAAK,UAAU,EAAqB,MAAM,gBAAgB,CAAC;AAEnH;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sFAAsF;IACtF,IAAI,EAAE,UAAU,CAAC;IACjB,gEAAgE;IAChE,IAAI,EAAE,WAAW,CAAC;IAClB,wDAAwD;IACxD,SAAS,EAAE,SAAS,CAAC;CACtB;AAWD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAS;IAE3C;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,OAAa,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,GAAE,MAAa,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAyFzG;CACF"}
|