@aztec/wallet-sdk 0.0.1-commit.9593d84 → 0.0.1-commit.96bb3f7
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 +173 -139
- package/dest/base-wallet/base_wallet.d.ts +5 -5
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +18 -9
- package/dest/crypto.d.ts +146 -0
- package/dest/crypto.d.ts.map +1 -0
- package/dest/crypto.js +216 -0
- package/dest/manager/index.d.ts +2 -2
- package/dest/manager/index.d.ts.map +1 -1
- package/dest/manager/wallet_manager.js +1 -1
- package/dest/providers/extension/extension_provider.d.ts +2 -2
- package/dest/providers/extension/extension_provider.d.ts.map +1 -1
- package/dest/providers/extension/extension_wallet.d.ts +79 -7
- package/dest/providers/extension/extension_wallet.d.ts.map +1 -1
- package/dest/providers/extension/extension_wallet.js +173 -44
- package/dest/providers/extension/index.d.ts +3 -2
- package/dest/providers/extension/index.d.ts.map +1 -1
- package/dest/providers/extension/index.js +1 -0
- package/dest/types.d.ts +83 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +3 -0
- package/package.json +12 -10
- package/src/base-wallet/base_wallet.ts +19 -13
- package/src/crypto.ts +283 -0
- package/src/manager/index.ts +1 -7
- package/src/manager/wallet_manager.ts +1 -1
- package/src/providers/extension/extension_provider.ts +1 -1
- package/src/providers/extension/extension_wallet.ts +206 -55
- package/src/providers/extension/index.ts +9 -1
- package/src/{providers/types.ts → types.ts} +22 -4
- 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,61 +2,86 @@ 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, deriveSharedKey, encrypt, exportPublicKey, generateKeyPair, importPublicKey } from '../../crypto.js';
|
|
5
6
|
/**
|
|
6
7
|
* A wallet implementation that communicates with browser extension wallets
|
|
7
|
-
*
|
|
8
|
+
* using a secure encrypted MessageChannel.
|
|
9
|
+
*
|
|
10
|
+
* This class establishes a private communication channel with a wallet extension
|
|
11
|
+
* using the following security mechanisms:
|
|
12
|
+
*
|
|
13
|
+
* 1. **MessageChannel**: Creates a private communication channel that is not
|
|
14
|
+
* visible to other scripts on the page (unlike window.postMessage).
|
|
15
|
+
*
|
|
16
|
+
* 2. **ECDH Key Exchange**: Uses Elliptic Curve Diffie-Hellman to derive a
|
|
17
|
+
* shared secret between the dApp and wallet without transmitting private keys.
|
|
18
|
+
*
|
|
19
|
+
* 3. **AES-GCM Encryption**: All messages after channel establishment are
|
|
20
|
+
* encrypted using AES-256-GCM, providing both confidentiality and authenticity.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // Discovery returns wallet info including the wallet's public key
|
|
25
|
+
* const wallets = await ExtensionProvider.discoverExtensions(chainInfo);
|
|
26
|
+
* const walletInfo = wallets[0];
|
|
27
|
+
*
|
|
28
|
+
* // Create a secure connection to the wallet
|
|
29
|
+
* const wallet = await ExtensionWallet.create(walletInfo, chainInfo, 'my-dapp');
|
|
30
|
+
*
|
|
31
|
+
* // All subsequent calls are encrypted
|
|
32
|
+
* const accounts = await wallet.getAccounts();
|
|
33
|
+
* ```
|
|
8
34
|
*/ export class ExtensionWallet {
|
|
9
35
|
chainInfo;
|
|
10
36
|
appId;
|
|
11
37
|
extensionId;
|
|
12
|
-
inFlight;
|
|
13
|
-
|
|
38
|
+
/** Map of pending requests awaiting responses, keyed by message ID */ inFlight;
|
|
39
|
+
/** The MessagePort for private communication with the extension */ port;
|
|
40
|
+
/** The derived AES-GCM key for encrypting/decrypting messages */ sharedKey;
|
|
41
|
+
/**
|
|
42
|
+
* Private constructor - use {@link ExtensionWallet.create} to instantiate.
|
|
43
|
+
* @param chainInfo - The chain information (chainId and version)
|
|
44
|
+
* @param appId - Application identifier for the requesting dApp
|
|
45
|
+
* @param extensionId - The unique identifier of the target wallet extension
|
|
46
|
+
*/ constructor(chainInfo, appId, extensionId){
|
|
14
47
|
this.chainInfo = chainInfo;
|
|
15
48
|
this.appId = appId;
|
|
16
49
|
this.extensionId = extensionId;
|
|
17
50
|
this.inFlight = new Map();
|
|
51
|
+
this.port = null;
|
|
52
|
+
this.sharedKey = null;
|
|
18
53
|
}
|
|
19
54
|
/**
|
|
20
55
|
* Creates an ExtensionWallet instance that proxies wallet calls to a browser extension
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
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
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const { resolve, reject } = wallet.inFlight.get(messageId);
|
|
53
|
-
if (error) {
|
|
54
|
-
reject(new Error(jsonStringify(error)));
|
|
55
|
-
} else {
|
|
56
|
-
resolve(result);
|
|
57
|
-
}
|
|
58
|
-
wallet.inFlight.delete(messageId);
|
|
59
|
-
});
|
|
56
|
+
* over a secure encrypted MessageChannel.
|
|
57
|
+
*
|
|
58
|
+
* The connection process:
|
|
59
|
+
* 1. Generates an ECDH key pair for this session
|
|
60
|
+
* 2. Derives a shared AES-256 key using the wallet's public key
|
|
61
|
+
* 3. Creates a MessageChannel and transfers one port to the extension
|
|
62
|
+
* 4. Returns a Proxy that encrypts all wallet method calls
|
|
63
|
+
*
|
|
64
|
+
* @param walletInfo - The discovered wallet information, including the wallet's ECDH public key
|
|
65
|
+
* @param chainInfo - The chain information (chainId and version) for request context
|
|
66
|
+
* @param appId - Application identifier used to identify the requesting dApp to the wallet
|
|
67
|
+
* @returns A Promise resolving to a Wallet implementation that encrypts all communication
|
|
68
|
+
*
|
|
69
|
+
* @throws Error if the secure channel cannot be established
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const wallet = await ExtensionWallet.create(
|
|
74
|
+
* walletInfo,
|
|
75
|
+
* { chainId: Fr(31337), version: Fr(0) },
|
|
76
|
+
* 'my-defi-app'
|
|
77
|
+
* );
|
|
78
|
+
* ```
|
|
79
|
+
*/ static async create(walletInfo, chainInfo, appId) {
|
|
80
|
+
const wallet = new ExtensionWallet(chainInfo, appId, walletInfo.id);
|
|
81
|
+
if (!walletInfo.publicKey) {
|
|
82
|
+
throw new Error('Wallet does not support secure channel establishment (missing public key)');
|
|
83
|
+
}
|
|
84
|
+
await wallet.establishSecureChannel(walletInfo.publicKey);
|
|
60
85
|
// Create a Proxy that intercepts wallet method calls and forwards them to the extension
|
|
61
86
|
return new Proxy(wallet, {
|
|
62
87
|
get: (target, prop)=>{
|
|
@@ -74,7 +99,89 @@ import { schemaHasMethod } from '@aztec/foundation/schemas';
|
|
|
74
99
|
}
|
|
75
100
|
});
|
|
76
101
|
}
|
|
77
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Establishes a secure MessageChannel with ECDH key exchange.
|
|
104
|
+
*
|
|
105
|
+
* This method performs the cryptographic handshake:
|
|
106
|
+
* 1. Generates a new ECDH P-256 key pair for this session
|
|
107
|
+
* 2. Imports the wallet's public key and derives a shared secret
|
|
108
|
+
* 3. Creates a MessageChannel for private communication
|
|
109
|
+
* 4. Sends a connection request with our public key via window.postMessage
|
|
110
|
+
* (this is the only public message - subsequent communication uses the private channel)
|
|
111
|
+
*
|
|
112
|
+
* @param walletExportedPublicKey - The wallet's ECDH public key in JWK format
|
|
113
|
+
*/ async establishSecureChannel(walletExportedPublicKey) {
|
|
114
|
+
const keyPair = await generateKeyPair();
|
|
115
|
+
const exportedPublicKey = await exportPublicKey(keyPair.publicKey);
|
|
116
|
+
const walletPublicKey = await importPublicKey(walletExportedPublicKey);
|
|
117
|
+
this.sharedKey = await deriveSharedKey(keyPair.privateKey, walletPublicKey);
|
|
118
|
+
const channel = new MessageChannel();
|
|
119
|
+
this.port = channel.port1;
|
|
120
|
+
this.port.onmessage = async (event)=>{
|
|
121
|
+
await this.handleEncryptedResponse(event.data);
|
|
122
|
+
};
|
|
123
|
+
this.port.start();
|
|
124
|
+
// Send connection request with our public key and transfer port2 to content script
|
|
125
|
+
// This is the only public postMessage - it contains our public key (safe to expose)
|
|
126
|
+
// and transfers the MessagePort for subsequent private communication
|
|
127
|
+
const connectRequest = {
|
|
128
|
+
type: 'aztec-wallet-connect',
|
|
129
|
+
walletId: this.extensionId,
|
|
130
|
+
appId: this.appId,
|
|
131
|
+
publicKey: exportedPublicKey
|
|
132
|
+
};
|
|
133
|
+
window.postMessage(jsonStringify(connectRequest), '*', [
|
|
134
|
+
channel.port2
|
|
135
|
+
]);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Handles an encrypted response received from the wallet extension.
|
|
139
|
+
*
|
|
140
|
+
* Decrypts the response using the shared AES key and resolves or rejects
|
|
141
|
+
* the corresponding pending promise based on the response content.
|
|
142
|
+
*
|
|
143
|
+
* @param encrypted - The encrypted response from the wallet
|
|
144
|
+
*/ async handleEncryptedResponse(encrypted) {
|
|
145
|
+
if (!this.sharedKey) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
const response = await decrypt(this.sharedKey, encrypted);
|
|
150
|
+
const { messageId, result, error, walletId: responseWalletId } = response;
|
|
151
|
+
if (!messageId || !responseWalletId) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (this.extensionId !== responseWalletId) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (!this.inFlight.has(messageId)) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const { resolve, reject } = this.inFlight.get(messageId);
|
|
161
|
+
if (error) {
|
|
162
|
+
reject(new Error(jsonStringify(error)));
|
|
163
|
+
} else {
|
|
164
|
+
resolve(result);
|
|
165
|
+
}
|
|
166
|
+
this.inFlight.delete(messageId);
|
|
167
|
+
// eslint-disable-next-line no-empty
|
|
168
|
+
} catch {}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Sends an encrypted wallet method call over the secure MessageChannel.
|
|
172
|
+
*
|
|
173
|
+
* The message is encrypted using AES-256-GCM with the shared key derived
|
|
174
|
+
* during channel establishment. A unique message ID is generated to correlate
|
|
175
|
+
* the response.
|
|
176
|
+
*
|
|
177
|
+
* @param call - The wallet method call containing method name and arguments
|
|
178
|
+
* @returns A Promise that resolves with the decrypted result from the wallet
|
|
179
|
+
*
|
|
180
|
+
* @throws Error if the secure channel has not been established
|
|
181
|
+
*/ async postMessage(call) {
|
|
182
|
+
if (!this.port || !this.sharedKey) {
|
|
183
|
+
throw new Error('Secure channel not established');
|
|
184
|
+
}
|
|
78
185
|
const messageId = globalThis.crypto.randomUUID();
|
|
79
186
|
const message = {
|
|
80
187
|
type: call.type,
|
|
@@ -84,7 +191,9 @@ import { schemaHasMethod } from '@aztec/foundation/schemas';
|
|
|
84
191
|
appId: this.appId,
|
|
85
192
|
walletId: this.extensionId
|
|
86
193
|
};
|
|
87
|
-
|
|
194
|
+
// Encrypt the message and send over the private MessageChannel
|
|
195
|
+
const encrypted = await encrypt(this.sharedKey, message);
|
|
196
|
+
this.port.postMessage(encrypted);
|
|
88
197
|
const { promise, resolve, reject } = promiseWithResolvers();
|
|
89
198
|
this.inFlight.set(messageId, {
|
|
90
199
|
promise,
|
|
@@ -93,4 +202,24 @@ import { schemaHasMethod } from '@aztec/foundation/schemas';
|
|
|
93
202
|
});
|
|
94
203
|
return promise;
|
|
95
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Closes the secure channel and cleans up resources.
|
|
207
|
+
*
|
|
208
|
+
* After calling this method, the wallet instance can no longer be used.
|
|
209
|
+
* Any pending requests will not receive responses.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* const wallet = await ExtensionWallet.create(walletInfo, chainInfo, 'my-app');
|
|
214
|
+
* // ... use wallet ...
|
|
215
|
+
* wallet.close(); // Clean up when done
|
|
216
|
+
* ```
|
|
217
|
+
*/ close() {
|
|
218
|
+
if (this.port) {
|
|
219
|
+
this.port.close();
|
|
220
|
+
this.port = null;
|
|
221
|
+
}
|
|
222
|
+
this.sharedKey = null;
|
|
223
|
+
this.inFlight.clear();
|
|
224
|
+
}
|
|
96
225
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { ExtensionWallet } from './extension_wallet.js';
|
|
2
2
|
export { ExtensionProvider } from './extension_provider.js';
|
|
3
|
-
export
|
|
4
|
-
|
|
3
|
+
export * from '../../crypto.js';
|
|
4
|
+
export type { WalletInfo, WalletMessage, WalletResponse, DiscoveryRequest, DiscoveryResponse, ConnectRequest, } from '../../types.js';
|
|
5
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9wcm92aWRlcnMvZXh0ZW5zaW9uL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxlQUFlLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUN4RCxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUM1RCxjQUFjLGlCQUFpQixDQUFDO0FBQ2hDLFlBQVksRUFDVixVQUFVLEVBQ1YsYUFBYSxFQUNiLGNBQWMsRUFDZCxnQkFBZ0IsRUFDaEIsaUJBQWlCLEVBQ2pCLGNBQWMsR0FDZixNQUFNLGdCQUFnQixDQUFDIn0=
|
|
@@ -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;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/extension/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,cAAc,iBAAiB,CAAC;AAChC,YAAY,EACV,UAAU,EACV,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,GACf,MAAM,gBAAgB,CAAC"}
|
package/dest/types.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { ChainInfo } from '@aztec/aztec.js/account';
|
|
2
|
+
import type { ExportedPublicKey } from './crypto.js';
|
|
3
|
+
/**
|
|
4
|
+
* Information about an installed Aztec wallet
|
|
5
|
+
*/
|
|
6
|
+
export interface WalletInfo {
|
|
7
|
+
/** Unique identifier for the wallet */
|
|
8
|
+
id: string;
|
|
9
|
+
/** Display name of the wallet */
|
|
10
|
+
name: string;
|
|
11
|
+
/** URL to the wallet's icon */
|
|
12
|
+
icon?: string;
|
|
13
|
+
/** Wallet version */
|
|
14
|
+
version: string;
|
|
15
|
+
/** Wallet's ECDH public key for secure channel establishment */
|
|
16
|
+
publicKey: ExportedPublicKey;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Message format for wallet communication (internal, before encryption)
|
|
20
|
+
*/
|
|
21
|
+
export interface WalletMessage {
|
|
22
|
+
/** Unique message ID for tracking responses */
|
|
23
|
+
messageId: string;
|
|
24
|
+
/** The wallet method to call */
|
|
25
|
+
type: string;
|
|
26
|
+
/** Arguments for the method */
|
|
27
|
+
args: unknown[];
|
|
28
|
+
/** Chain information */
|
|
29
|
+
chainInfo: ChainInfo;
|
|
30
|
+
/** Application ID making the request */
|
|
31
|
+
appId: string;
|
|
32
|
+
/** Wallet ID to target a specific wallet */
|
|
33
|
+
walletId: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Response message from wallet
|
|
37
|
+
*/
|
|
38
|
+
export interface WalletResponse {
|
|
39
|
+
/** Message ID matching the request */
|
|
40
|
+
messageId: string;
|
|
41
|
+
/** Result data (if successful) */
|
|
42
|
+
result?: unknown;
|
|
43
|
+
/** Error data (if failed) */
|
|
44
|
+
error?: unknown;
|
|
45
|
+
/** Wallet ID that sent the response */
|
|
46
|
+
walletId: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Discovery message for finding installed wallets (public, unencrypted)
|
|
50
|
+
*/
|
|
51
|
+
export interface DiscoveryRequest {
|
|
52
|
+
/** Message type for discovery */
|
|
53
|
+
type: 'aztec-wallet-discovery';
|
|
54
|
+
/** Request ID */
|
|
55
|
+
requestId: string;
|
|
56
|
+
/** Chain information to check if wallet supports this network */
|
|
57
|
+
chainInfo: ChainInfo;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Discovery response from a wallet (public, unencrypted)
|
|
61
|
+
*/
|
|
62
|
+
export interface DiscoveryResponse {
|
|
63
|
+
/** Message type for discovery response */
|
|
64
|
+
type: 'aztec-wallet-discovery-response';
|
|
65
|
+
/** Request ID matching the discovery request */
|
|
66
|
+
requestId: string;
|
|
67
|
+
/** Wallet information */
|
|
68
|
+
walletInfo: WalletInfo;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Connection request to establish secure channel
|
|
72
|
+
*/
|
|
73
|
+
export interface ConnectRequest {
|
|
74
|
+
/** Message type for connection */
|
|
75
|
+
type: 'aztec-wallet-connect';
|
|
76
|
+
/** Target wallet ID */
|
|
77
|
+
walletId: string;
|
|
78
|
+
/** Application ID */
|
|
79
|
+
appId: string;
|
|
80
|
+
/** dApp's ECDH public key for deriving shared secret */
|
|
81
|
+
publicKey: ExportedPublicKey;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy90eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUV6RCxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBRSxNQUFNLGFBQWEsQ0FBQztBQUVyRDs7R0FFRztBQUNILE1BQU0sV0FBVyxVQUFVO0lBQ3pCLHVDQUF1QztJQUN2QyxFQUFFLEVBQUUsTUFBTSxDQUFDO0lBQ1gsaUNBQWlDO0lBQ2pDLElBQUksRUFBRSxNQUFNLENBQUM7SUFDYiwrQkFBK0I7SUFDL0IsSUFBSSxDQUFDLEVBQUUsTUFBTSxDQUFDO0lBQ2QscUJBQXFCO0lBQ3JCLE9BQU8sRUFBRSxNQUFNLENBQUM7SUFDaEIsZ0VBQWdFO0lBQ2hFLFNBQVMsRUFBRSxpQkFBaUIsQ0FBQztDQUM5QjtBQUVEOztHQUVHO0FBQ0gsTUFBTSxXQUFXLGFBQWE7SUFDNUIsK0NBQStDO0lBQy9DLFNBQVMsRUFBRSxNQUFNLENBQUM7SUFDbEIsZ0NBQWdDO0lBQ2hDLElBQUksRUFBRSxNQUFNLENBQUM7SUFDYiwrQkFBK0I7SUFDL0IsSUFBSSxFQUFFLE9BQU8sRUFBRSxDQUFDO0lBQ2hCLHdCQUF3QjtJQUN4QixTQUFTLEVBQUUsU0F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E,SAAS,EAAE,SAAS,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,0CAA0C;IAC1C,IAAI,EAAE,iCAAiC,CAAC;IACxC,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,yBAAyB;IACzB,UAAU,EAAE,UAAU,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,kCAAkC;IAClC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,uBAAuB;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,qBAAqB;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,SAAS,EAAE,iBAAiB,CAAC;CAC9B"}
|
package/dest/types.js
ADDED
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.1-commit.
|
|
4
|
+
"version": "0.0.1-commit.96bb3f7",
|
|
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": {
|
|
@@ -15,8 +17,8 @@
|
|
|
15
17
|
"tsconfig": "./tsconfig.json"
|
|
16
18
|
},
|
|
17
19
|
"scripts": {
|
|
18
|
-
"build": "yarn clean &&
|
|
19
|
-
"build:dev": "
|
|
20
|
+
"build": "yarn clean && ../scripts/tsc.sh",
|
|
21
|
+
"build:dev": "../scripts/tsc.sh --watch",
|
|
20
22
|
"build:ts": "tsc -b",
|
|
21
23
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
22
24
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
@@ -62,15 +64,15 @@
|
|
|
62
64
|
]
|
|
63
65
|
},
|
|
64
66
|
"dependencies": {
|
|
65
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
66
|
-
"@aztec/constants": "0.0.1-commit.
|
|
67
|
-
"@aztec/entrypoints": "0.0.1-commit.
|
|
68
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
69
|
-
"@aztec/pxe": "0.0.1-commit.
|
|
70
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
67
|
+
"@aztec/aztec.js": "0.0.1-commit.96bb3f7",
|
|
68
|
+
"@aztec/constants": "0.0.1-commit.96bb3f7",
|
|
69
|
+
"@aztec/entrypoints": "0.0.1-commit.96bb3f7",
|
|
70
|
+
"@aztec/foundation": "0.0.1-commit.96bb3f7",
|
|
71
|
+
"@aztec/pxe": "0.0.1-commit.96bb3f7",
|
|
72
|
+
"@aztec/stdlib": "0.0.1-commit.96bb3f7"
|
|
71
73
|
},
|
|
72
74
|
"devDependencies": {
|
|
73
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
75
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.96bb3f7",
|
|
74
76
|
"@jest/globals": "^30.0.0",
|
|
75
77
|
"@types/jest": "^30.0.0",
|
|
76
78
|
"@types/node": "^22.15.17",
|
|
@@ -6,6 +6,8 @@ import type {
|
|
|
6
6
|
BatchResults,
|
|
7
7
|
BatchableMethods,
|
|
8
8
|
BatchedMethod,
|
|
9
|
+
PrivateEvent,
|
|
10
|
+
PrivateEventFilter,
|
|
9
11
|
ProfileOptions,
|
|
10
12
|
SendOptions,
|
|
11
13
|
SimulateOptions,
|
|
@@ -19,10 +21,10 @@ import {
|
|
|
19
21
|
} from '@aztec/constants';
|
|
20
22
|
import { AccountFeePaymentMethodOptions, type DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
21
23
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
22
|
-
import { Fr } from '@aztec/foundation/
|
|
24
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
23
25
|
import { createLogger } from '@aztec/foundation/log';
|
|
24
26
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
25
|
-
import type { PXE } from '@aztec/pxe/server';
|
|
27
|
+
import type { PXE, PackedPrivateEvent } from '@aztec/pxe/server';
|
|
26
28
|
import {
|
|
27
29
|
type ContractArtifact,
|
|
28
30
|
type EventMetadataDefinition,
|
|
@@ -74,7 +76,7 @@ export type FeeOptions = {
|
|
|
74
76
|
export abstract class BaseWallet implements Wallet {
|
|
75
77
|
protected log = createLogger('wallet-sdk:base_wallet');
|
|
76
78
|
|
|
77
|
-
protected
|
|
79
|
+
protected minFeePadding = 0.5;
|
|
78
80
|
protected cancellableTransactions = false;
|
|
79
81
|
|
|
80
82
|
// Protected because we want to force wallets to instantiate their own PXE.
|
|
@@ -163,7 +165,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
163
165
|
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
164
166
|
): Promise<FeeOptions> {
|
|
165
167
|
const maxFeesPerGas =
|
|
166
|
-
gasSettings?.maxFeesPerGas ?? (await this.aztecNode.
|
|
168
|
+
gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentMinFees()).mul(1 + this.minFeePadding);
|
|
167
169
|
let accountFeePaymentMethodOptions;
|
|
168
170
|
// The transaction does not include a fee payment method, so we set the flag
|
|
169
171
|
// for the account to use its fee juice balance
|
|
@@ -325,17 +327,21 @@ export abstract class BaseWallet implements Wallet {
|
|
|
325
327
|
}
|
|
326
328
|
|
|
327
329
|
async getPrivateEvents<T>(
|
|
328
|
-
contractAddress: AztecAddress,
|
|
329
330
|
eventDef: EventMetadataDefinition,
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
): Promise<T[]> {
|
|
334
|
-
const events = await this.pxe.getPrivateEvents(contractAddress, eventDef.eventSelector, from, limit, recipients);
|
|
331
|
+
eventFilter: PrivateEventFilter,
|
|
332
|
+
): Promise<PrivateEvent<T>[]> {
|
|
333
|
+
const pxeEvents = await this.pxe.getPrivateEvents(eventDef.eventSelector, eventFilter);
|
|
335
334
|
|
|
336
|
-
const decodedEvents =
|
|
337
|
-
|
|
338
|
-
|
|
335
|
+
const decodedEvents = pxeEvents.map((pxeEvent: PackedPrivateEvent): PrivateEvent<T> => {
|
|
336
|
+
return {
|
|
337
|
+
event: decodeFromAbi([eventDef.abiType], pxeEvent.packedEvent) as T,
|
|
338
|
+
metadata: {
|
|
339
|
+
l2BlockNumber: pxeEvent.l2BlockNumber,
|
|
340
|
+
l2BlockHash: pxeEvent.l2BlockHash,
|
|
341
|
+
txHash: pxeEvent.txHash,
|
|
342
|
+
},
|
|
343
|
+
};
|
|
344
|
+
});
|
|
339
345
|
|
|
340
346
|
return decodedEvents;
|
|
341
347
|
}
|