@aztec/wallet-sdk 0.0.1-commit.fcb71a6 → 3.0.0-devnet.2-patch.1
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 +241 -267
- package/dest/crypto.d.ts +183 -0
- package/dest/crypto.d.ts.map +1 -0
- package/dest/crypto.js +300 -0
- package/dest/manager/index.d.ts +4 -3
- package/dest/manager/index.d.ts.map +1 -1
- package/dest/manager/index.js +2 -0
- package/dest/manager/types.d.ts +22 -1
- package/dest/manager/types.d.ts.map +1 -1
- package/dest/manager/wallet_manager.d.ts +1 -1
- package/dest/manager/wallet_manager.d.ts.map +1 -1
- package/dest/manager/wallet_manager.js +34 -15
- package/dest/providers/extension/extension_provider.d.ts +53 -7
- package/dest/providers/extension/extension_provider.d.ts.map +1 -1
- package/dest/providers/extension/extension_provider.js +81 -13
- package/dest/providers/extension/extension_wallet.d.ts +140 -8
- package/dest/providers/extension/extension_wallet.d.ts.map +1 -1
- package/dest/providers/extension/extension_wallet.js +268 -46
- package/dest/providers/extension/index.d.ts +6 -4
- package/dest/providers/extension/index.d.ts.map +1 -1
- package/dest/providers/extension/index.js +2 -0
- package/dest/types.d.ts +92 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +10 -0
- package/package.json +10 -8
- package/src/crypto.ts +375 -0
- package/src/manager/index.ts +4 -8
- package/src/manager/types.ts +22 -0
- package/src/manager/wallet_manager.ts +43 -16
- package/src/providers/extension/extension_provider.ts +112 -17
- package/src/providers/extension/extension_wallet.ts +310 -55
- package/src/providers/extension/index.ts +5 -3
- package/src/{providers/types.ts → types.ts} +33 -6
- package/dest/providers/types.d.ts +0 -67
- package/dest/providers/types.d.ts.map +0 -1
- package/dest/providers/types.js +0 -3
|
@@ -2,63 +2,125 @@ import { WalletSchema } from '@aztec/aztec.js/wallet';
|
|
|
2
2
|
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
3
3
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
4
4
|
import { schemaHasMethod } from '@aztec/foundation/schemas';
|
|
5
|
+
import { decrypt, encrypt } from '../../crypto.js';
|
|
6
|
+
import { WalletMessageType } from '../../types.js';
|
|
5
7
|
/**
|
|
6
8
|
* A wallet implementation that communicates with browser extension wallets
|
|
7
|
-
*
|
|
9
|
+
* using a secure encrypted MessageChannel.
|
|
10
|
+
*
|
|
11
|
+
* This class uses a pre-established secure channel from the discovery phase:
|
|
12
|
+
*
|
|
13
|
+
* 1. **MessageChannel**: A private communication channel created during discovery,
|
|
14
|
+
* not visible to other scripts on the page (unlike window.postMessage).
|
|
15
|
+
*
|
|
16
|
+
* 2. **ECDH Key Exchange**: The shared secret was derived during discovery using
|
|
17
|
+
* Elliptic Curve Diffie-Hellman key exchange.
|
|
18
|
+
*
|
|
19
|
+
* 3. **AES-GCM Encryption**: All messages are encrypted using AES-256-GCM,
|
|
20
|
+
* providing both confidentiality and authenticity.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // Discovery returns wallets with secure channel components
|
|
25
|
+
* const wallets = await ExtensionProvider.discoverExtensions(chainInfo);
|
|
26
|
+
* const { info, port, sharedKey } = wallets[0];
|
|
27
|
+
*
|
|
28
|
+
* // User can verify emoji if desired
|
|
29
|
+
* console.log('Verify:', hashToEmoji(info.verificationHash!));
|
|
30
|
+
*
|
|
31
|
+
* // Create wallet using the discovered components
|
|
32
|
+
* const wallet = await ExtensionWallet.create(info, chainInfo, port, sharedKey, 'my-dapp');
|
|
33
|
+
*
|
|
34
|
+
* // All subsequent calls are encrypted
|
|
35
|
+
* const accounts = await wallet.getAccounts();
|
|
36
|
+
* ```
|
|
8
37
|
*/ export class ExtensionWallet {
|
|
9
38
|
chainInfo;
|
|
10
39
|
appId;
|
|
11
40
|
extensionId;
|
|
12
|
-
|
|
13
|
-
|
|
41
|
+
port;
|
|
42
|
+
sharedKey;
|
|
43
|
+
/** Map of pending requests awaiting responses, keyed by message ID */ inFlight;
|
|
44
|
+
disconnected;
|
|
45
|
+
disconnectCallbacks;
|
|
46
|
+
/**
|
|
47
|
+
* Private constructor - use {@link ExtensionWallet.create} to instantiate.
|
|
48
|
+
* @param chainInfo - The chain information (chainId and version)
|
|
49
|
+
* @param appId - Application identifier for the requesting dApp
|
|
50
|
+
* @param extensionId - The unique identifier of the target wallet extension
|
|
51
|
+
* @param port - The MessagePort for private communication with the wallet
|
|
52
|
+
* @param sharedKey - The derived AES-256-GCM shared key for encryption
|
|
53
|
+
*/ constructor(chainInfo, appId, extensionId, port, sharedKey){
|
|
14
54
|
this.chainInfo = chainInfo;
|
|
15
55
|
this.appId = appId;
|
|
16
56
|
this.extensionId = extensionId;
|
|
57
|
+
this.port = port;
|
|
58
|
+
this.sharedKey = sharedKey;
|
|
17
59
|
this.inFlight = new Map();
|
|
60
|
+
this.disconnected = false;
|
|
61
|
+
this.disconnectCallbacks = [];
|
|
62
|
+
this.walletProxy = null;
|
|
18
63
|
}
|
|
64
|
+
/** Cached Wallet proxy instance */ walletProxy;
|
|
19
65
|
/**
|
|
20
|
-
* Creates an ExtensionWallet instance that
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* @param
|
|
24
|
-
* @
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
* Creates an ExtensionWallet instance that communicates with a browser extension
|
|
67
|
+
* over a secure encrypted MessageChannel.
|
|
68
|
+
*
|
|
69
|
+
* @param walletInfo - The wallet info from ExtensionProvider.discoverExtensions()
|
|
70
|
+
* @param chainInfo - The chain information (chainId and version) for request context
|
|
71
|
+
* @param port - The MessagePort for private communication with the wallet
|
|
72
|
+
* @param sharedKey - The derived AES-256-GCM shared key for encryption
|
|
73
|
+
* @param appId - Application identifier used to identify the requesting dApp to the wallet
|
|
74
|
+
* @returns The ExtensionWallet instance. Use {@link getWallet} to get the Wallet interface.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const wallets = await ExtensionProvider.discoverExtensions(chainInfo);
|
|
79
|
+
* const { info, port, sharedKey } = wallets[0];
|
|
80
|
+
* const extensionWallet = ExtensionWallet.create(
|
|
81
|
+
* info,
|
|
82
|
+
* { chainId: Fr(31337), version: Fr(0) },
|
|
83
|
+
* port,
|
|
84
|
+
* sharedKey,
|
|
85
|
+
* 'my-defi-app'
|
|
86
|
+
* );
|
|
87
|
+
*
|
|
88
|
+
* // Register disconnect handler
|
|
89
|
+
* extensionWallet.onDisconnect(() => console.log('Disconnected!'));
|
|
90
|
+
*
|
|
91
|
+
* // Get the Wallet interface for dApp usage
|
|
92
|
+
* const wallet = extensionWallet.getWallet();
|
|
93
|
+
* const accounts = await wallet.getAccounts();
|
|
94
|
+
* ```
|
|
95
|
+
*/ static create(walletInfo, chainInfo, port, sharedKey, appId) {
|
|
96
|
+
const wallet = new ExtensionWallet(chainInfo, appId, walletInfo.id, port, sharedKey);
|
|
97
|
+
// Set up message handler - all messages are now encrypted
|
|
98
|
+
wallet.port.onmessage = (event)=>{
|
|
99
|
+
void wallet.handleEncryptedResponse(event.data);
|
|
100
|
+
};
|
|
101
|
+
wallet.port.start();
|
|
102
|
+
return wallet;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Returns a Wallet interface that proxies all method calls through the secure channel.
|
|
106
|
+
*
|
|
107
|
+
* The returned Wallet can be used directly by dApps - all method calls are automatically
|
|
108
|
+
* encrypted and sent to the wallet extension.
|
|
109
|
+
*
|
|
110
|
+
* @returns A Wallet implementation that encrypts all communication
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const extensionWallet = ExtensionWallet.create(info, chainInfo, port, sharedKey, 'my-app');
|
|
115
|
+
* const wallet = extensionWallet.getWallet();
|
|
116
|
+
* const accounts = await wallet.getAccounts();
|
|
117
|
+
* ```
|
|
118
|
+
*/ getWallet() {
|
|
119
|
+
if (this.walletProxy) {
|
|
120
|
+
return this.walletProxy;
|
|
121
|
+
}
|
|
60
122
|
// Create a Proxy that intercepts wallet method calls and forwards them to the extension
|
|
61
|
-
|
|
123
|
+
this.walletProxy = new Proxy(this, {
|
|
62
124
|
get: (target, prop)=>{
|
|
63
125
|
if (schemaHasMethod(WalletSchema, prop.toString())) {
|
|
64
126
|
return async (...args)=>{
|
|
@@ -73,8 +135,65 @@ import { schemaHasMethod } from '@aztec/foundation/schemas';
|
|
|
73
135
|
}
|
|
74
136
|
}
|
|
75
137
|
});
|
|
138
|
+
return this.walletProxy;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Handles an encrypted response received from the wallet extension.
|
|
142
|
+
*
|
|
143
|
+
* Decrypts the response using the shared AES key and resolves or rejects
|
|
144
|
+
* the corresponding pending promise based on the response content.
|
|
145
|
+
*
|
|
146
|
+
* @param encrypted - The encrypted response from the wallet
|
|
147
|
+
*/ async handleEncryptedResponse(encrypted) {
|
|
148
|
+
if (!this.sharedKey) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
const response = await decrypt(this.sharedKey, encrypted);
|
|
153
|
+
const { messageId, result, error, walletId: responseWalletId } = response;
|
|
154
|
+
// Check for disconnect notification from the wallet backend
|
|
155
|
+
// This is sent as an encrypted error response with a special type
|
|
156
|
+
if (error && typeof error === 'object' && 'type' in error && error.type === WalletMessageType.SESSION_DISCONNECTED) {
|
|
157
|
+
this.handleDisconnect();
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (!messageId || !responseWalletId) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (this.extensionId !== responseWalletId) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (!this.inFlight.has(messageId)) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const { resolve, reject } = this.inFlight.get(messageId);
|
|
170
|
+
if (error) {
|
|
171
|
+
reject(new Error(jsonStringify(error)));
|
|
172
|
+
} else {
|
|
173
|
+
resolve(result);
|
|
174
|
+
}
|
|
175
|
+
this.inFlight.delete(messageId);
|
|
176
|
+
// eslint-disable-next-line no-empty
|
|
177
|
+
} catch {}
|
|
76
178
|
}
|
|
77
|
-
|
|
179
|
+
/**
|
|
180
|
+
* Sends an encrypted wallet method call over the secure MessageChannel.
|
|
181
|
+
*
|
|
182
|
+
* The message is encrypted using AES-256-GCM with the shared key derived
|
|
183
|
+
* during discovery. A unique message ID is generated to correlate
|
|
184
|
+
* the response.
|
|
185
|
+
*
|
|
186
|
+
* @param call - The wallet method call containing method name and arguments
|
|
187
|
+
* @returns A Promise that resolves with the decrypted result from the wallet
|
|
188
|
+
*
|
|
189
|
+
* @throws Error if the secure channel has not been established or wallet is disconnected
|
|
190
|
+
*/ async postMessage(call) {
|
|
191
|
+
if (this.disconnected) {
|
|
192
|
+
throw new Error('Wallet has been disconnected');
|
|
193
|
+
}
|
|
194
|
+
if (!this.port || !this.sharedKey) {
|
|
195
|
+
throw new Error('Secure channel not established');
|
|
196
|
+
}
|
|
78
197
|
const messageId = globalThis.crypto.randomUUID();
|
|
79
198
|
const message = {
|
|
80
199
|
type: call.type,
|
|
@@ -84,7 +203,9 @@ import { schemaHasMethod } from '@aztec/foundation/schemas';
|
|
|
84
203
|
appId: this.appId,
|
|
85
204
|
walletId: this.extensionId
|
|
86
205
|
};
|
|
87
|
-
|
|
206
|
+
// Encrypt the message and send over the private MessageChannel
|
|
207
|
+
const encrypted = await encrypt(this.sharedKey, message);
|
|
208
|
+
this.port.postMessage(encrypted);
|
|
88
209
|
const { promise, resolve, reject } = promiseWithResolvers();
|
|
89
210
|
this.inFlight.set(messageId, {
|
|
90
211
|
promise,
|
|
@@ -93,4 +214,105 @@ import { schemaHasMethod } from '@aztec/foundation/schemas';
|
|
|
93
214
|
});
|
|
94
215
|
return promise;
|
|
95
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Handles wallet disconnection.
|
|
219
|
+
* Rejects all pending requests and notifies registered callbacks.
|
|
220
|
+
* @internal
|
|
221
|
+
*/ handleDisconnect() {
|
|
222
|
+
if (this.disconnected) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
this.disconnected = true;
|
|
226
|
+
// Close the port to prevent any further messages
|
|
227
|
+
if (this.port) {
|
|
228
|
+
this.port.onmessage = null;
|
|
229
|
+
this.port.close();
|
|
230
|
+
}
|
|
231
|
+
// Reject all pending requests
|
|
232
|
+
// Note: These rejections should be caught by the callers, but we log them
|
|
233
|
+
// here to help with debugging if they become unhandled
|
|
234
|
+
const error = new Error('Wallet disconnected');
|
|
235
|
+
for (const { reject } of this.inFlight.values()){
|
|
236
|
+
reject(error);
|
|
237
|
+
}
|
|
238
|
+
this.inFlight.clear();
|
|
239
|
+
// Notify registered callbacks
|
|
240
|
+
for (const callback of this.disconnectCallbacks){
|
|
241
|
+
try {
|
|
242
|
+
callback();
|
|
243
|
+
} catch {
|
|
244
|
+
// Ignore errors in callbacks
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Registers a callback to be invoked when the wallet disconnects.
|
|
250
|
+
*
|
|
251
|
+
* @param callback - Function to call when wallet disconnects
|
|
252
|
+
* @returns A function to unregister the callback
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* const wallet = await ExtensionWallet.create(...);
|
|
257
|
+
* const unsubscribe = wallet.onDisconnect(() => {
|
|
258
|
+
* console.log('Wallet disconnected! Please reconnect.');
|
|
259
|
+
* // Clean up UI, prompt user to reconnect, etc.
|
|
260
|
+
* });
|
|
261
|
+
* // Later: unsubscribe(); to stop receiving notifications
|
|
262
|
+
* ```
|
|
263
|
+
*/ onDisconnect(callback) {
|
|
264
|
+
this.disconnectCallbacks.push(callback);
|
|
265
|
+
return ()=>{
|
|
266
|
+
const index = this.disconnectCallbacks.indexOf(callback);
|
|
267
|
+
if (index !== -1) {
|
|
268
|
+
this.disconnectCallbacks.splice(index, 1);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Returns whether the wallet has been disconnected.
|
|
274
|
+
*
|
|
275
|
+
* @returns true if the wallet is no longer connected
|
|
276
|
+
*/ isDisconnected() {
|
|
277
|
+
return this.disconnected;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Disconnects from the wallet and cleans up resources.
|
|
281
|
+
*
|
|
282
|
+
* This method notifies the wallet extension that the session is ending,
|
|
283
|
+
* allowing it to clean up its state. After calling this method, the wallet
|
|
284
|
+
* instance can no longer be used and any pending requests will be rejected.
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```typescript
|
|
288
|
+
* const wallet = await provider.connect('my-app');
|
|
289
|
+
* // ... use wallet ...
|
|
290
|
+
* await wallet.disconnect(); // Clean disconnect when done
|
|
291
|
+
* ```
|
|
292
|
+
*/ async disconnect() {
|
|
293
|
+
if (this.disconnected) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
// Send disconnect message to extension before closing
|
|
297
|
+
if (this.port && this.sharedKey) {
|
|
298
|
+
try {
|
|
299
|
+
const message = {
|
|
300
|
+
type: WalletMessageType.DISCONNECT,
|
|
301
|
+
messageId: globalThis.crypto.randomUUID(),
|
|
302
|
+
chainInfo: this.chainInfo,
|
|
303
|
+
appId: this.appId,
|
|
304
|
+
walletId: this.extensionId,
|
|
305
|
+
args: []
|
|
306
|
+
};
|
|
307
|
+
const encrypted = await encrypt(this.sharedKey, message);
|
|
308
|
+
this.port.postMessage(encrypted);
|
|
309
|
+
} catch {
|
|
310
|
+
// Ignore errors sending disconnect message
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
this.handleDisconnect();
|
|
314
|
+
if (this.port) {
|
|
315
|
+
this.port.close();
|
|
316
|
+
}
|
|
317
|
+
}
|
|
96
318
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export { ExtensionWallet } from './extension_wallet.js';
|
|
2
|
-
export { ExtensionProvider } from './extension_provider.js';
|
|
3
|
-
export
|
|
4
|
-
|
|
1
|
+
export { ExtensionWallet, type DisconnectCallback } from './extension_wallet.js';
|
|
2
|
+
export { ExtensionProvider, type DiscoveredWallet } from './extension_provider.js';
|
|
3
|
+
export * from '../../crypto.js';
|
|
4
|
+
export { WalletMessageType } from '../../types.js';
|
|
5
|
+
export type { WalletInfo, WalletMessage, WalletResponse, DiscoveryRequest, DiscoveryResponse } from '../../types.js';
|
|
6
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9wcm92aWRlcnMvZXh0ZW5zaW9uL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxlQUFlLEVBQUUsS0FBSyxrQkFBa0IsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBQ2pGLE9BQU8sRUFBRSxpQkFBaUIsRUFBRSxLQUFLLGdCQUFnQixFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFDbkYsY0FBYyxpQkFBaUIsQ0FBQztBQUNoQyxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxnQkFBZ0IsQ0FBQztBQUNuRCxZQUFZLEVBQUUsVUFBVSxFQUFFLGFBQWEsRUFBRSxjQUFjLEVBQUUsZ0JBQWdCLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxnQkFBZ0IsQ0FBQyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/extension/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/extension/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACnF,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dest/types.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { ChainInfo } from '@aztec/aztec.js/account';
|
|
2
|
+
import type { ExportedPublicKey } from './crypto.js';
|
|
3
|
+
/**
|
|
4
|
+
* Message types for wallet SDK communication.
|
|
5
|
+
* All types are prefixed with 'aztec-wallet-' for namespacing.
|
|
6
|
+
*/
|
|
7
|
+
export declare enum WalletMessageType {
|
|
8
|
+
/** Discovery request to find installed wallets */
|
|
9
|
+
DISCOVERY = "aztec-wallet-discovery",
|
|
10
|
+
/** Discovery response from a wallet */
|
|
11
|
+
DISCOVERY_RESPONSE = "aztec-wallet-discovery-response",
|
|
12
|
+
/** Session disconnected notification (unencrypted control message) */
|
|
13
|
+
SESSION_DISCONNECTED = "aztec-wallet-session-disconnected",
|
|
14
|
+
/** Explicit disconnect request from dApp */
|
|
15
|
+
DISCONNECT = "aztec-wallet-disconnect"
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Information about an installed Aztec wallet
|
|
19
|
+
*/
|
|
20
|
+
export interface WalletInfo {
|
|
21
|
+
/** Unique identifier for the wallet */
|
|
22
|
+
id: string;
|
|
23
|
+
/** Display name of the wallet */
|
|
24
|
+
name: string;
|
|
25
|
+
/** URL to the wallet's icon */
|
|
26
|
+
icon?: string;
|
|
27
|
+
/** Wallet version */
|
|
28
|
+
version: string;
|
|
29
|
+
/** Wallet's ECDH public key for secure channel establishment */
|
|
30
|
+
publicKey: ExportedPublicKey;
|
|
31
|
+
/**
|
|
32
|
+
* Hash of the shared secret for anti-MITM verification.
|
|
33
|
+
* Both dApp and wallet independently compute this from the ECDH shared secret.
|
|
34
|
+
* Use {@link hashToEmoji} to convert to a visual representation for user verification.
|
|
35
|
+
*/
|
|
36
|
+
verificationHash?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Message format for wallet communication (internal, before encryption)
|
|
40
|
+
*/
|
|
41
|
+
export interface WalletMessage {
|
|
42
|
+
/** Unique message ID for tracking responses */
|
|
43
|
+
messageId: string;
|
|
44
|
+
/** The wallet method to call */
|
|
45
|
+
type: string;
|
|
46
|
+
/** Arguments for the method */
|
|
47
|
+
args: unknown[];
|
|
48
|
+
/** Chain information */
|
|
49
|
+
chainInfo: ChainInfo;
|
|
50
|
+
/** Application ID making the request */
|
|
51
|
+
appId: string;
|
|
52
|
+
/** Wallet ID to target a specific wallet */
|
|
53
|
+
walletId: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Response message from wallet
|
|
57
|
+
*/
|
|
58
|
+
export interface WalletResponse {
|
|
59
|
+
/** Message ID matching the request */
|
|
60
|
+
messageId: string;
|
|
61
|
+
/** Result data (if successful) */
|
|
62
|
+
result?: unknown;
|
|
63
|
+
/** Error data (if failed) */
|
|
64
|
+
error?: unknown;
|
|
65
|
+
/** Wallet ID that sent the response */
|
|
66
|
+
walletId: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Discovery message for finding installed wallets (public, unencrypted)
|
|
70
|
+
*/
|
|
71
|
+
export interface DiscoveryRequest {
|
|
72
|
+
/** Message type for discovery */
|
|
73
|
+
type: WalletMessageType.DISCOVERY;
|
|
74
|
+
/** Request ID */
|
|
75
|
+
requestId: string;
|
|
76
|
+
/** Chain information to check if wallet supports this network */
|
|
77
|
+
chainInfo: ChainInfo;
|
|
78
|
+
/** dApp's ECDH public key for deriving shared secret */
|
|
79
|
+
publicKey: ExportedPublicKey;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Discovery response from a wallet (public, unencrypted)
|
|
83
|
+
*/
|
|
84
|
+
export interface DiscoveryResponse {
|
|
85
|
+
/** Message type for discovery response */
|
|
86
|
+
type: WalletMessageType.DISCOVERY_RESPONSE;
|
|
87
|
+
/** Request ID matching the discovery request */
|
|
88
|
+
requestId: string;
|
|
89
|
+
/** Wallet information */
|
|
90
|
+
walletInfo: WalletInfo;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy90eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUV6RCxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBRSxNQUFNLGFBQWEsQ0FBQztBQUVyRDs7O0dBR0c7QUFDSCxvQkFBWSxpQkFBaUI7SUFDM0Isa0RBQWtEO0lBQ2xELFNBQVMsMkJBQTJCO0lBQ3BDLHVDQUF1QztJQUN2QyxrQkFBa0Isb0NBQW9DO0lBQ3RELHNFQUFzRTtJQUN0RSxvQkFBb0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ixed with 'aztec-wallet-' for namespacing.
|
|
4
|
+
*/ export var WalletMessageType = /*#__PURE__*/ function(WalletMessageType) {
|
|
5
|
+
/** Discovery request to find installed wallets */ WalletMessageType["DISCOVERY"] = "aztec-wallet-discovery";
|
|
6
|
+
/** Discovery response from a wallet */ WalletMessageType["DISCOVERY_RESPONSE"] = "aztec-wallet-discovery-response";
|
|
7
|
+
/** Session disconnected notification (unencrypted control message) */ WalletMessageType["SESSION_DISCONNECTED"] = "aztec-wallet-session-disconnected";
|
|
8
|
+
/** Explicit disconnect request from dApp */ WalletMessageType["DISCONNECT"] = "aztec-wallet-disconnect";
|
|
9
|
+
return WalletMessageType;
|
|
10
|
+
}({});
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/wallet-sdk",
|
|
3
3
|
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/wallet-sdk",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "3.0.0-devnet.2-patch.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./base-wallet": "./dest/base-wallet/index.js",
|
|
8
8
|
"./providers/extension": "./dest/providers/extension/index.js",
|
|
9
|
+
"./crypto": "./dest/crypto.js",
|
|
10
|
+
"./types": "./dest/types.js",
|
|
9
11
|
"./manager": "./dest/manager/index.js"
|
|
10
12
|
},
|
|
11
13
|
"typedocOptions": {
|
|
@@ -62,15 +64,15 @@
|
|
|
62
64
|
]
|
|
63
65
|
},
|
|
64
66
|
"dependencies": {
|
|
65
|
-
"@aztec/aztec.js": "0.0.
|
|
66
|
-
"@aztec/constants": "0.0.
|
|
67
|
-
"@aztec/entrypoints": "0.0.
|
|
68
|
-
"@aztec/foundation": "0.0.
|
|
69
|
-
"@aztec/pxe": "0.0.
|
|
70
|
-
"@aztec/stdlib": "0.0.
|
|
67
|
+
"@aztec/aztec.js": "3.0.0-devnet.2-patch.1",
|
|
68
|
+
"@aztec/constants": "3.0.0-devnet.2-patch.1",
|
|
69
|
+
"@aztec/entrypoints": "3.0.0-devnet.2-patch.1",
|
|
70
|
+
"@aztec/foundation": "3.0.0-devnet.2-patch.1",
|
|
71
|
+
"@aztec/pxe": "3.0.0-devnet.2-patch.1",
|
|
72
|
+
"@aztec/stdlib": "3.0.0-devnet.2-patch.1"
|
|
71
73
|
},
|
|
72
74
|
"devDependencies": {
|
|
73
|
-
"@aztec/noir-contracts.js": "0.0.
|
|
75
|
+
"@aztec/noir-contracts.js": "3.0.0-devnet.2-patch.1",
|
|
74
76
|
"@jest/globals": "^30.0.0",
|
|
75
77
|
"@types/jest": "^30.0.0",
|
|
76
78
|
"@types/node": "^22.15.17",
|