@aztec/wallet-sdk 0.0.1-commit.2448fdb → 0.0.1-commit.2606882
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 +125 -0
- package/dest/base-wallet/base_wallet.d.ts +24 -5
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +57 -14
- package/dest/base-wallet/utils.d.ts +5 -3
- package/dest/base-wallet/utils.d.ts.map +1 -1
- package/dest/base-wallet/utils.js +8 -4
- package/dest/extension/handlers/background_connection_handler.d.ts +12 -2
- package/dest/extension/handlers/background_connection_handler.d.ts.map +1 -1
- package/dest/extension/handlers/background_connection_handler.js +44 -8
- package/dest/extension/handlers/content_script_connection_handler.d.ts +2 -1
- package/dest/extension/handlers/content_script_connection_handler.d.ts.map +1 -1
- package/dest/extension/handlers/content_script_connection_handler.js +19 -0
- package/dest/extension/handlers/internal_message_types.d.ts +3 -1
- package/dest/extension/handlers/internal_message_types.d.ts.map +1 -1
- package/dest/extension/handlers/internal_message_types.js +3 -1
- package/dest/extension/provider/extension_wallet.d.ts +26 -3
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -1
- package/dest/extension/provider/extension_wallet.js +80 -9
- package/dest/iframe/handlers/iframe_connection_handler.d.ts +6 -2
- package/dest/iframe/handlers/iframe_connection_handler.d.ts.map +1 -1
- package/dest/iframe/handlers/iframe_connection_handler.js +18 -7
- package/dest/iframe/provider/iframe_wallet.d.ts +20 -3
- package/dest/iframe/provider/iframe_wallet.d.ts.map +1 -1
- package/dest/iframe/provider/iframe_wallet.js +79 -10
- package/dest/types.d.ts +52 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +25 -0
- package/package.json +8 -8
- package/src/base-wallet/base_wallet.ts +64 -9
- package/src/base-wallet/utils.ts +9 -1
- package/src/extension/handlers/background_connection_handler.ts +42 -9
- package/src/extension/handlers/content_script_connection_handler.ts +18 -0
- package/src/extension/handlers/internal_message_types.ts +2 -0
- package/src/extension/provider/extension_wallet.ts +94 -8
- package/src/iframe/handlers/iframe_connection_handler.ts +21 -8
- package/src/iframe/provider/iframe_wallet.ts +103 -9
- package/src/types.ts +59 -0
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { ChainInfo } from '@aztec/aztec.js/account';
|
|
10
10
|
import { type Wallet } from '@aztec/aztec.js/wallet';
|
|
11
|
-
import { type DisconnectCallback } from '../../types.js';
|
|
11
|
+
import { type DisconnectCallback, type HeartbeatOptions, type WalletSdkLogger } from '../../types.js';
|
|
12
12
|
/**
|
|
13
13
|
* A wallet implementation that communicates with a web wallet loaded in an iframe
|
|
14
14
|
* using encrypted postMessage.
|
|
@@ -35,6 +35,11 @@ export declare class IframeWallet {
|
|
|
35
35
|
private disconnected;
|
|
36
36
|
private disconnectCallbacks;
|
|
37
37
|
private messageListener;
|
|
38
|
+
private heartbeatTimer;
|
|
39
|
+
private lastInboundAt;
|
|
40
|
+
private log;
|
|
41
|
+
private heartbeatIntervalMs;
|
|
42
|
+
private heartbeatDeadAfterMs;
|
|
38
43
|
private constructor();
|
|
39
44
|
/**
|
|
40
45
|
* Creates a proxied IframeWallet that implements the {@link Wallet} interface.
|
|
@@ -50,9 +55,11 @@ export declare class IframeWallet {
|
|
|
50
55
|
* @param sharedKey - AES-256-GCM key derived from ECDH key exchange
|
|
51
56
|
* @param chainInfo - Network information (chainId and version)
|
|
52
57
|
* @param appId - Application identifier for the requesting dApp
|
|
58
|
+
* @param logger - Optional logger; defaults to a no-op logger to keep extension/page bundles small
|
|
59
|
+
* @param heartbeatOptions - Optional override for heartbeat tuning (mostly useful for tests)
|
|
53
60
|
* @returns A proxied IframeWallet — call `.asWallet()` to get the typed `Wallet`
|
|
54
61
|
*/
|
|
55
|
-
static create(walletId: string, sessionId: string, iframeWindow: Window, walletOrigin: string, sharedKey: CryptoKey, chainInfo: ChainInfo, appId: string): IframeWallet;
|
|
62
|
+
static create(walletId: string, sessionId: string, iframeWindow: Window, walletOrigin: string, sharedKey: CryptoKey, chainInfo: ChainInfo, appId: string, logger?: WalletSdkLogger, heartbeatOptions?: HeartbeatOptions): IframeWallet;
|
|
56
63
|
/**
|
|
57
64
|
* Returns this wallet as a typed {@link Wallet} interface.
|
|
58
65
|
* When accessed through the Proxy (via `create()`), returns the proxy itself.
|
|
@@ -60,9 +67,19 @@ export declare class IframeWallet {
|
|
|
60
67
|
asWallet(): Wallet;
|
|
61
68
|
private handleEncryptedResponse;
|
|
62
69
|
private postMessage;
|
|
70
|
+
/**
|
|
71
|
+
* Start liveness probing while at least one request is in flight. PINGs are
|
|
72
|
+
* unencrypted control messages — older wallet handlers that don't understand
|
|
73
|
+
* them simply drop them, but any inbound traffic (PONG, encrypted response,
|
|
74
|
+
* disconnect notice) resets the idle timer, so a slow-but-alive legacy wallet
|
|
75
|
+
* never trips a false disconnect.
|
|
76
|
+
*/
|
|
77
|
+
private startHeartbeat;
|
|
78
|
+
private maybeStopHeartbeat;
|
|
79
|
+
private heartbeatTick;
|
|
63
80
|
private handleDisconnect;
|
|
64
81
|
onDisconnect(callback: DisconnectCallback): () => void;
|
|
65
82
|
isDisconnected(): boolean;
|
|
66
83
|
disconnect(): void;
|
|
67
84
|
}
|
|
68
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
85
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaWZyYW1lX3dhbGxldC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2lmcmFtZS9wcm92aWRlci9pZnJhbWVfd2FsbGV0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7O0dBT0c7QUFDSCxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUN6RCxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQWdCLE1BQU0sd0JBQ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CLENBQUMsRUFBRSxnQkFBZ0IsR0FDbEMsWUFBWSxDQXNEZDtJQUVEOzs7T0FHRztJQUNILFFBQVEsSUFBSSxNQUFNLENBRWpCO1lBRWEsdUJBQXVCO1lBMEJ2QixXQUFXO0lBMkJ6Qjs7Ozs7O09BTUc7SUFDSCxPQUFPLENBQUMsY0FBYztJQVF0QixPQUFPLENBQUMsa0JBQWtCO0lBTzFCLE9BQU8sQ0FBQyxhQUFhO0lBdUJyQixPQUFPLENBQUMsZ0JBQWdCO0lBK0J4QixZQUFZLENBQUMsUUFBUSxFQUFFLGtCQUFrQixHQUFHLE1BQU0sSUFBSSxDQVFyRDtJQUVELGNBQWMsSUFBSSxPQUFPLENBRXhCO0lBRUQsVUFBVSxJQUFJLElBQUksQ0FNakI7Q0FDRiJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iframe_wallet.d.ts","sourceRoot":"","sources":["../../../src/iframe/provider/iframe_wallet.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,wBAAwB,CAAC;AAOnE,OAAO,
|
|
1
|
+
{"version":3,"file":"iframe_wallet.d.ts","sourceRoot":"","sources":["../../../src/iframe/provider/iframe_wallet.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,wBAAwB,CAAC;AAOnE,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EAKrB,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AAaxB;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAY;IAYrB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,SAAS;IAjBnB,OAAO,CAAC,QAAQ,CAAoD;IACpE,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,mBAAmB,CAA4B;IACvD,OAAO,CAAC,eAAe,CAA4C;IACnE,OAAO,CAAC,cAAc,CAA+C;IACrE,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,GAAG,CAAkB;IAC7B,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,oBAAoB,CAAS;IAErC,OAAO,eAcN;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,MAAM,CACX,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,eAAe,EACxB,gBAAgB,CAAC,EAAE,gBAAgB,GAClC,YAAY,CAsDd;IAED;;;OAGG;IACH,QAAQ,IAAI,MAAM,CAEjB;YAEa,uBAAuB;YA0BvB,WAAW;IA2BzB;;;;;;OAMG;IACH,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,aAAa;IAuBrB,OAAO,CAAC,gBAAgB;IA+BxB,YAAY,CAAC,QAAQ,EAAE,kBAAkB,GAAG,MAAM,IAAI,CAQrD;IAED,cAAc,IAAI,OAAO,CAExB;IAED,UAAU,IAAI,IAAI,CAMjB;CACF"}
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
*/ import { WalletSchema } from '@aztec/aztec.js/wallet';
|
|
9
9
|
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
10
10
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
11
|
-
import { schemaHasMethod } from '@aztec/foundation/schemas';
|
|
11
|
+
import { getSchemaReturnType, schemaHasMethod } from '@aztec/foundation/schemas';
|
|
12
12
|
import { decrypt, encrypt } from '../../crypto.js';
|
|
13
|
-
import { WalletMessageType } from '../../types.js';
|
|
13
|
+
import { DEFAULT_HEARTBEAT_DEAD_AFTER_MS, DEFAULT_HEARTBEAT_INTERVAL_MS, NOOP_LOGGER, WalletMessageType } from '../../types.js';
|
|
14
14
|
/**
|
|
15
15
|
* A wallet implementation that communicates with a web wallet loaded in an iframe
|
|
16
16
|
* using encrypted postMessage.
|
|
@@ -36,7 +36,12 @@ import { WalletMessageType } from '../../types.js';
|
|
|
36
36
|
disconnected;
|
|
37
37
|
disconnectCallbacks;
|
|
38
38
|
messageListener;
|
|
39
|
-
|
|
39
|
+
heartbeatTimer;
|
|
40
|
+
lastInboundAt;
|
|
41
|
+
log;
|
|
42
|
+
heartbeatIntervalMs;
|
|
43
|
+
heartbeatDeadAfterMs;
|
|
44
|
+
constructor(chainInfo, appId, walletId, sessionId, iframeWindow, walletOrigin, sharedKey, logger, heartbeatOptions){
|
|
40
45
|
this.chainInfo = chainInfo;
|
|
41
46
|
this.appId = appId;
|
|
42
47
|
this.walletId = walletId;
|
|
@@ -48,6 +53,11 @@ import { WalletMessageType } from '../../types.js';
|
|
|
48
53
|
this.disconnected = false;
|
|
49
54
|
this.disconnectCallbacks = [];
|
|
50
55
|
this.messageListener = null;
|
|
56
|
+
this.heartbeatTimer = null;
|
|
57
|
+
this.lastInboundAt = 0;
|
|
58
|
+
this.log = logger ?? NOOP_LOGGER;
|
|
59
|
+
this.heartbeatIntervalMs = heartbeatOptions?.intervalMs ?? DEFAULT_HEARTBEAT_INTERVAL_MS;
|
|
60
|
+
this.heartbeatDeadAfterMs = heartbeatOptions?.deadAfterMs ?? DEFAULT_HEARTBEAT_DEAD_AFTER_MS;
|
|
51
61
|
}
|
|
52
62
|
/**
|
|
53
63
|
* Creates a proxied IframeWallet that implements the {@link Wallet} interface.
|
|
@@ -63,9 +73,11 @@ import { WalletMessageType } from '../../types.js';
|
|
|
63
73
|
* @param sharedKey - AES-256-GCM key derived from ECDH key exchange
|
|
64
74
|
* @param chainInfo - Network information (chainId and version)
|
|
65
75
|
* @param appId - Application identifier for the requesting dApp
|
|
76
|
+
* @param logger - Optional logger; defaults to a no-op logger to keep extension/page bundles small
|
|
77
|
+
* @param heartbeatOptions - Optional override for heartbeat tuning (mostly useful for tests)
|
|
66
78
|
* @returns A proxied IframeWallet — call `.asWallet()` to get the typed `Wallet`
|
|
67
|
-
*/ static create(walletId, sessionId, iframeWindow, walletOrigin, sharedKey, chainInfo, appId) {
|
|
68
|
-
const wallet = new IframeWallet(chainInfo, appId, walletId, sessionId, iframeWindow, walletOrigin, sharedKey);
|
|
79
|
+
*/ static create(walletId, sessionId, iframeWindow, walletOrigin, sharedKey, chainInfo, appId, logger, heartbeatOptions) {
|
|
80
|
+
const wallet = new IframeWallet(chainInfo, appId, walletId, sessionId, iframeWindow, walletOrigin, sharedKey, logger, heartbeatOptions);
|
|
69
81
|
wallet.messageListener = (event)=>{
|
|
70
82
|
if (event.origin !== walletOrigin) {
|
|
71
83
|
return;
|
|
@@ -74,9 +86,14 @@ import { WalletMessageType } from '../../types.js';
|
|
|
74
86
|
if (!msg || typeof msg !== 'object') {
|
|
75
87
|
return;
|
|
76
88
|
}
|
|
77
|
-
if (msg.
|
|
89
|
+
if (msg.sessionId !== sessionId) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
// Any inbound traffic on our session counts as proof of liveness.
|
|
93
|
+
wallet.lastInboundAt = Date.now();
|
|
94
|
+
if (msg.type === WalletMessageType.SECURE_RESPONSE) {
|
|
78
95
|
void wallet.handleEncryptedResponse(msg.encrypted);
|
|
79
|
-
} else if (msg.type === WalletMessageType.SESSION_DISCONNECTED
|
|
96
|
+
} else if (msg.type === WalletMessageType.SESSION_DISCONNECTED) {
|
|
80
97
|
wallet.handleDisconnect();
|
|
81
98
|
}
|
|
82
99
|
};
|
|
@@ -91,7 +108,7 @@ import { WalletMessageType } from '../../types.js';
|
|
|
91
108
|
type: prop.toString(),
|
|
92
109
|
args
|
|
93
110
|
});
|
|
94
|
-
return WalletSchema[prop.toString()]
|
|
111
|
+
return getSchemaReturnType(WalletSchema[prop.toString()]).parseAsync(result);
|
|
95
112
|
};
|
|
96
113
|
} else {
|
|
97
114
|
return target[prop];
|
|
@@ -122,8 +139,11 @@ import { WalletMessageType } from '../../types.js';
|
|
|
122
139
|
pending.resolve(result);
|
|
123
140
|
}
|
|
124
141
|
this.inFlight.delete(messageId);
|
|
125
|
-
|
|
126
|
-
|
|
142
|
+
this.maybeStopHeartbeat();
|
|
143
|
+
} catch (err) {
|
|
144
|
+
this.log.warn('Failed to decrypt wallet response', {
|
|
145
|
+
err
|
|
146
|
+
});
|
|
127
147
|
}
|
|
128
148
|
}
|
|
129
149
|
async postMessage(call) {
|
|
@@ -151,13 +171,62 @@ import { WalletMessageType } from '../../types.js';
|
|
|
151
171
|
resolve,
|
|
152
172
|
reject
|
|
153
173
|
});
|
|
174
|
+
this.startHeartbeat();
|
|
154
175
|
return promise;
|
|
155
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Start liveness probing while at least one request is in flight. PINGs are
|
|
179
|
+
* unencrypted control messages — older wallet handlers that don't understand
|
|
180
|
+
* them simply drop them, but any inbound traffic (PONG, encrypted response,
|
|
181
|
+
* disconnect notice) resets the idle timer, so a slow-but-alive legacy wallet
|
|
182
|
+
* never trips a false disconnect.
|
|
183
|
+
*/ startHeartbeat() {
|
|
184
|
+
if (this.heartbeatTimer !== null || this.disconnected) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
this.lastInboundAt = Date.now();
|
|
188
|
+
this.heartbeatTimer = setInterval(()=>this.heartbeatTick(), this.heartbeatIntervalMs);
|
|
189
|
+
}
|
|
190
|
+
maybeStopHeartbeat() {
|
|
191
|
+
if (this.inFlight.size === 0 && this.heartbeatTimer !== null) {
|
|
192
|
+
clearInterval(this.heartbeatTimer);
|
|
193
|
+
this.heartbeatTimer = null;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
heartbeatTick() {
|
|
197
|
+
if (this.disconnected || this.inFlight.size === 0) {
|
|
198
|
+
this.maybeStopHeartbeat();
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const idleMs = Date.now() - this.lastInboundAt;
|
|
202
|
+
if (idleMs >= this.heartbeatDeadAfterMs) {
|
|
203
|
+
this.log.warn('Iframe wallet channel unresponsive — declaring disconnect', {
|
|
204
|
+
idleMs,
|
|
205
|
+
inFlight: this.inFlight.size
|
|
206
|
+
});
|
|
207
|
+
this.handleDisconnect();
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
this.iframeWindow.postMessage({
|
|
212
|
+
type: WalletMessageType.PING,
|
|
213
|
+
sessionId: this.sessionId
|
|
214
|
+
}, this.walletOrigin);
|
|
215
|
+
} catch (err) {
|
|
216
|
+
this.log.warn('Failed to send heartbeat PING', {
|
|
217
|
+
err
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
156
221
|
handleDisconnect() {
|
|
157
222
|
if (this.disconnected) {
|
|
158
223
|
return;
|
|
159
224
|
}
|
|
160
225
|
this.disconnected = true;
|
|
226
|
+
if (this.heartbeatTimer !== null) {
|
|
227
|
+
clearInterval(this.heartbeatTimer);
|
|
228
|
+
this.heartbeatTimer = null;
|
|
229
|
+
}
|
|
161
230
|
if (this.messageListener) {
|
|
162
231
|
window.removeEventListener('message', this.messageListener);
|
|
163
232
|
this.messageListener = null;
|
package/dest/types.d.ts
CHANGED
|
@@ -22,7 +22,14 @@ export declare enum WalletMessageType {
|
|
|
22
22
|
/** Encrypted wallet response wrapper */
|
|
23
23
|
SECURE_RESPONSE = "aztec-wallet-secure-response",
|
|
24
24
|
/** Session disconnected notification */
|
|
25
|
-
SESSION_DISCONNECTED = "aztec-wallet-session-disconnected"
|
|
25
|
+
SESSION_DISCONNECTED = "aztec-wallet-session-disconnected",
|
|
26
|
+
/** Liveness probe sent by the dApp while a request is in flight */
|
|
27
|
+
PING = "aztec-wallet-ping",
|
|
28
|
+
/** Liveness response from the wallet. Any inbound message (including a regular
|
|
29
|
+
* encrypted response) is treated as proof of liveness, so a missing PONG alone
|
|
30
|
+
* never trips disconnect — the dApp also resets its liveness timer on traffic.
|
|
31
|
+
*/
|
|
32
|
+
PONG = "aztec-wallet-pong"
|
|
26
33
|
}
|
|
27
34
|
/**
|
|
28
35
|
* Information about an installed Aztec wallet.
|
|
@@ -132,4 +139,47 @@ export interface KeyExchangeResponse {
|
|
|
132
139
|
* Callback invoked when a wallet connection is disconnected.
|
|
133
140
|
*/
|
|
134
141
|
export type DisconnectCallback = () => void;
|
|
135
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Default heartbeat tuning shared by both transports.
|
|
144
|
+
*
|
|
145
|
+
* - `intervalMs`: how often the dApp sends PING probes while a request is in flight.
|
|
146
|
+
* - `deadAfterMs`: how long the channel can stay silent (no PONG, no encrypted
|
|
147
|
+
* response, no DISCONNECT) before the dApp declares the wallet unreachable
|
|
148
|
+
* and rejects all in-flight requests. Generous enough that long-running
|
|
149
|
+
* operations (proveTx, sendTx) on legacy wallets that don't reply to PING
|
|
150
|
+
* still succeed — any inbound traffic resets the timer.
|
|
151
|
+
*/
|
|
152
|
+
export declare const DEFAULT_HEARTBEAT_INTERVAL_MS = 5000;
|
|
153
|
+
export declare const DEFAULT_HEARTBEAT_DEAD_AFTER_MS = 300000;
|
|
154
|
+
/** Override knobs for the heartbeat — mostly useful for tests. */
|
|
155
|
+
export interface HeartbeatOptions {
|
|
156
|
+
/** How often to send PING probes while a request is in flight (ms). */
|
|
157
|
+
intervalMs?: number;
|
|
158
|
+
/** Idle ceiling before declaring disconnect (ms). */
|
|
159
|
+
deadAfterMs?: number;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Minimal logger surface used by the wallet SDK.
|
|
163
|
+
*
|
|
164
|
+
* Defined locally so that wallet hosts (browser extensions, iframe wallet pages)
|
|
165
|
+
* can pass a simple `console`-backed logger without pulling in the full
|
|
166
|
+
* `@aztec/foundation` logging runtime, which is non-trivial to bundle in those
|
|
167
|
+
* contexts. Structurally compatible with `Logger` from `@aztec/foundation/log`,
|
|
168
|
+
* so dApp-side callers can pass that type directly.
|
|
169
|
+
*/
|
|
170
|
+
export interface WalletSdkLogger {
|
|
171
|
+
/** Diagnostic messages — typically discarded in production. */
|
|
172
|
+
debug: (message: string, data?: unknown) => void;
|
|
173
|
+
/** Informational messages — significant lifecycle events. */
|
|
174
|
+
info: (message: string, data?: unknown) => void;
|
|
175
|
+
/** Recoverable problems — channel decryption failure, missed heartbeats, etc. */
|
|
176
|
+
warn: (message: string, data?: unknown) => void;
|
|
177
|
+
/** Errors that prevent normal operation. */
|
|
178
|
+
error: (message: string, errOrData?: unknown, data?: unknown) => void;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* No-op logger used as the default when callers don't provide one. Discards all
|
|
182
|
+
* messages — wallet hosts that want diagnostics should pass their own logger.
|
|
183
|
+
*/
|
|
184
|
+
export declare const NOOP_LOGGER: WalletSdkLogger;
|
|
185
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy90eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUV6RCxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBRSxNQUFNLGFBQWEsQ0FBQztBQUVyRDs7O0dBR0c7QUFDSCxvQkFBWSxpQkFBaUI7SUFDM0Isa0RBQWtEO0lBQ2xELFNBQVMsMkJBQTJCO0lBQ3BDLHVDQUF1QztJQUN2QyxrQkFBa0Isb0NBQW9DO0lBQ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UFFLENBQUMsT0FBTyxFQUFFLE1BQU0sRUFBRSxJQUFJLENBQUMsRUFBRSxPQUFPLEtBQUssSUFBSSxDQUFDO0lBQ2hELDRDQUE0QztJQUM1QyxLQUFLLEVBQUUsQ0FBQyxPQUFPLEVBQUUsTUFBTSxFQUFFLFNBQVMsQ0FBQyxFQUFFLE9BQU8sRUFBRSxJQUFJLENBQUMsRUFBRSxPQUFPLEtBQUssSUFBSSxDQUFDO0NBQ3ZFO0FBRUQ7OztHQUdHO0FBQ0gsZUFBTyxNQUFNLFdBQVcsRUFBRSxlQUt6QixDQUFDIn0=
|
package/dest/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD;;;GAGG;AACH,oBAAY,iBAAiB;IAC3B,kDAAkD;IAClD,SAAS,2BAA2B;IACpC,uCAAuC;IACvC,kBAAkB,oCAAoC;IACtD,sEAAsE;IACtE,UAAU,4BAA4B;IACtC,oDAAoD;IACpD,oBAAoB,sCAAsC;IAC1D,qDAAqD;IACrD,qBAAqB,uCAAuC;IAC5D,0BAA0B;IAC1B,YAAY,uBAAuB;IACnC,uCAAuC;IACvC,cAAc,gCAAgC;IAC9C,wCAAwC;IACxC,eAAe,iCAAiC;IAChD,wCAAwC;IACxC,oBAAoB,sCAAsC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD;;;GAGG;AACH,oBAAY,iBAAiB;IAC3B,kDAAkD;IAClD,SAAS,2BAA2B;IACp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;AACH,MAAM,WAAW,eAAe;IAC9B,iEAA+D;IAC/D,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACjD,+DAA6D;IAC7D,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAChD,mFAAiF;IACjF,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAChD,4CAA4C;IAC5C,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACvE;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,eAKzB,CAAC"}
|
package/dest/types.js
CHANGED
|
@@ -11,5 +11,30 @@
|
|
|
11
11
|
/** Encrypted wallet message wrapper */ WalletMessageType["SECURE_MESSAGE"] = "aztec-wallet-secure-message";
|
|
12
12
|
/** Encrypted wallet response wrapper */ WalletMessageType["SECURE_RESPONSE"] = "aztec-wallet-secure-response";
|
|
13
13
|
/** Session disconnected notification */ WalletMessageType["SESSION_DISCONNECTED"] = "aztec-wallet-session-disconnected";
|
|
14
|
+
/** Liveness probe sent by the dApp while a request is in flight */ WalletMessageType["PING"] = "aztec-wallet-ping";
|
|
15
|
+
/** Liveness response from the wallet. Any inbound message (including a regular
|
|
16
|
+
* encrypted response) is treated as proof of liveness, so a missing PONG alone
|
|
17
|
+
* never trips disconnect — the dApp also resets its liveness timer on traffic.
|
|
18
|
+
*/ WalletMessageType["PONG"] = "aztec-wallet-pong";
|
|
14
19
|
return WalletMessageType;
|
|
15
20
|
}({});
|
|
21
|
+
/**
|
|
22
|
+
* Default heartbeat tuning shared by both transports.
|
|
23
|
+
*
|
|
24
|
+
* - `intervalMs`: how often the dApp sends PING probes while a request is in flight.
|
|
25
|
+
* - `deadAfterMs`: how long the channel can stay silent (no PONG, no encrypted
|
|
26
|
+
* response, no DISCONNECT) before the dApp declares the wallet unreachable
|
|
27
|
+
* and rejects all in-flight requests. Generous enough that long-running
|
|
28
|
+
* operations (proveTx, sendTx) on legacy wallets that don't reply to PING
|
|
29
|
+
* still succeed — any inbound traffic resets the timer.
|
|
30
|
+
*/ export const DEFAULT_HEARTBEAT_INTERVAL_MS = 5_000;
|
|
31
|
+
export const DEFAULT_HEARTBEAT_DEAD_AFTER_MS = 300_000;
|
|
32
|
+
/**
|
|
33
|
+
* No-op logger used as the default when callers don't provide one. Discards all
|
|
34
|
+
* messages — wallet hosts that want diagnostics should pass their own logger.
|
|
35
|
+
*/ export const NOOP_LOGGER = {
|
|
36
|
+
debug: ()=>{},
|
|
37
|
+
info: ()=>{},
|
|
38
|
+
warn: ()=>{},
|
|
39
|
+
error: ()=>{}
|
|
40
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.2606882",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./base-wallet": "./dest/base-wallet/index.js",
|
|
@@ -75,15 +75,15 @@
|
|
|
75
75
|
]
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
79
|
-
"@aztec/constants": "0.0.1-commit.
|
|
80
|
-
"@aztec/entrypoints": "0.0.1-commit.
|
|
81
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
82
|
-
"@aztec/pxe": "0.0.1-commit.
|
|
83
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
78
|
+
"@aztec/aztec.js": "0.0.1-commit.2606882",
|
|
79
|
+
"@aztec/constants": "0.0.1-commit.2606882",
|
|
80
|
+
"@aztec/entrypoints": "0.0.1-commit.2606882",
|
|
81
|
+
"@aztec/foundation": "0.0.1-commit.2606882",
|
|
82
|
+
"@aztec/pxe": "0.0.1-commit.2606882",
|
|
83
|
+
"@aztec/stdlib": "0.0.1-commit.2606882"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
86
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.2606882",
|
|
87
87
|
"@jest/globals": "^30.0.0",
|
|
88
88
|
"@types/jest": "^30.0.0",
|
|
89
89
|
"@types/node": "^22.15.17",
|
|
@@ -48,7 +48,7 @@ import {
|
|
|
48
48
|
getContractClassFromArtifact,
|
|
49
49
|
} from '@aztec/stdlib/contract';
|
|
50
50
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
51
|
-
import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
51
|
+
import { Gas, GasFees, GasSettings, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
52
52
|
import {
|
|
53
53
|
computeSiloedPrivateInitializationNullifier,
|
|
54
54
|
computeSiloedPublicInitializationNullifier,
|
|
@@ -56,11 +56,12 @@ import {
|
|
|
56
56
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
57
57
|
import {
|
|
58
58
|
BlockHeader,
|
|
59
|
+
ExecutionPayload,
|
|
59
60
|
type TxExecutionRequest,
|
|
60
61
|
type TxProfileResult,
|
|
61
62
|
type UtilityExecutionResult,
|
|
63
|
+
mergeExecutionPayloads,
|
|
62
64
|
} from '@aztec/stdlib/tx';
|
|
63
|
-
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
64
65
|
|
|
65
66
|
import { inspect } from 'util';
|
|
66
67
|
|
|
@@ -84,7 +85,7 @@ export type FeeOptions = {
|
|
|
84
85
|
/** Options for `simulateViaEntrypoint`. */
|
|
85
86
|
export type SimulateViaEntrypointOptions = Pick<
|
|
86
87
|
SimulateOptions,
|
|
87
|
-
'from' | 'additionalScopes' | 'skipTxValidation' | 'skipFeeEnforcement'
|
|
88
|
+
'from' | 'additionalScopes' | 'skipTxValidation' | 'skipFeeEnforcement' | 'sendMessagesAs' | 'overrides'
|
|
88
89
|
> & {
|
|
89
90
|
/** Fee options for the entrypoint */
|
|
90
91
|
feeOptions: FeeOptions;
|
|
@@ -100,6 +101,11 @@ export type CompleteFeeOptionsConfig = {
|
|
|
100
101
|
gasSettings?: Partial<FieldsOf<GasSettings>>;
|
|
101
102
|
/** If true, returns gas settings with high gas limits for estimation. If false, uses fallback limits. */
|
|
102
103
|
forEstimation?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Assumed network congestion level for fee prediction. Controls how aggressively the wallet
|
|
106
|
+
* estimates future fees. Defaults to Limit (worst case) when not specified.
|
|
107
|
+
*/
|
|
108
|
+
congestionEstimate?: ManaUsageEstimate;
|
|
103
109
|
};
|
|
104
110
|
|
|
105
111
|
/**
|
|
@@ -125,6 +131,17 @@ export abstract class BaseWallet implements Wallet {
|
|
|
125
131
|
return [...scopeSet].map(AztecAddress.fromString);
|
|
126
132
|
}
|
|
127
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Picks the sender address PXE should tag private messages with. Returns `undefined` when there is no signing
|
|
136
|
+
* account (`from === NO_FROM`) and no explicit override; in that case any private log emitted by the tx using
|
|
137
|
+
* the wallet-supplied default sender will fail the "Sender for tags is not set" assertion.
|
|
138
|
+
* @param from - Tx sender, or `NO_FROM`.
|
|
139
|
+
* @param sendMessagesAs - Explicit override.
|
|
140
|
+
*/
|
|
141
|
+
protected senderForTagsFrom(from: AztecAddress | NoFrom, sendMessagesAs?: AztecAddress): AztecAddress | undefined {
|
|
142
|
+
return sendMessagesAs ?? (from === NO_FROM ? undefined : from);
|
|
143
|
+
}
|
|
144
|
+
|
|
128
145
|
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
129
146
|
|
|
130
147
|
abstract getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
@@ -229,9 +246,9 @@ export abstract class BaseWallet implements Wallet {
|
|
|
229
246
|
* @param config - Fee completion config.
|
|
230
247
|
*/
|
|
231
248
|
protected async completeFeeOptions(config: CompleteFeeOptionsConfig): Promise<FeeOptions> {
|
|
232
|
-
const { from, feePayer, gasSettings, forEstimation } = config;
|
|
249
|
+
const { from, feePayer, gasSettings, forEstimation, congestionEstimate } = config;
|
|
233
250
|
const maxFeesPerGas =
|
|
234
|
-
gasSettings?.maxFeesPerGas ?? (await this.
|
|
251
|
+
gasSettings?.maxFeesPerGas ?? (await this.getMinFees(congestionEstimate)).mul(1 + this.minFeePadding);
|
|
235
252
|
let accountFeePaymentMethodOptions;
|
|
236
253
|
// If from is an address, we need to determine the appropriate fee payment method options for the
|
|
237
254
|
// account contract entrypoint to use
|
|
@@ -267,6 +284,28 @@ export abstract class BaseWallet implements Wallet {
|
|
|
267
284
|
};
|
|
268
285
|
}
|
|
269
286
|
|
|
287
|
+
/**
|
|
288
|
+
* Returns the worst-case min fee across predicted future slots.
|
|
289
|
+
* Falls back to getCurrentMinFees if the node doesn't support getPredictedMinFees.
|
|
290
|
+
* @param estimate - The mana usage estimate to use for fee prediction. Defaults to Limit for conservative estimation.
|
|
291
|
+
*/
|
|
292
|
+
protected async getMinFees(estimate: ManaUsageEstimate = ManaUsageEstimate.Limit): Promise<GasFees> {
|
|
293
|
+
try {
|
|
294
|
+
const predicted = await this.aztecNode.getPredictedMinFees(estimate);
|
|
295
|
+
if (predicted.length === 0) {
|
|
296
|
+
return this.aztecNode.getCurrentMinFees();
|
|
297
|
+
}
|
|
298
|
+
return predicted.reduce((worst, fees) => (fees.feePerL2Gas > worst.feePerL2Gas ? fees : worst));
|
|
299
|
+
} catch (err: any) {
|
|
300
|
+
// Fallback for old nodes that don't support getPredictedMinFees.
|
|
301
|
+
// Only fall back on method-not-found errors (JSON-RPC code -32601); rethrow others.
|
|
302
|
+
if (err?.cause?.code === -32601 || err?.message?.includes('Method not found')) {
|
|
303
|
+
return this.aztecNode.getCurrentMinFees();
|
|
304
|
+
}
|
|
305
|
+
throw err;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
270
309
|
registerSender(address: AztecAddress, _alias: string = ''): Promise<AztecAddress> {
|
|
271
310
|
return this.pxe.registerSender(address);
|
|
272
311
|
}
|
|
@@ -309,6 +348,10 @@ export abstract class BaseWallet implements Wallet {
|
|
|
309
348
|
return instance;
|
|
310
349
|
}
|
|
311
350
|
|
|
351
|
+
registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
352
|
+
return this.pxe.registerContractClass(artifact);
|
|
353
|
+
}
|
|
354
|
+
|
|
312
355
|
/**
|
|
313
356
|
* Simulates calls through the standard PXE path (account entrypoint).
|
|
314
357
|
* @param executionPayload - The execution payload to simulate.
|
|
@@ -325,6 +368,8 @@ export abstract class BaseWallet implements Wallet {
|
|
|
325
368
|
skipTxValidation: opts.skipTxValidation,
|
|
326
369
|
skipFeeEnforcement: opts.skipFeeEnforcement,
|
|
327
370
|
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
371
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
372
|
+
overrides: opts.overrides,
|
|
328
373
|
});
|
|
329
374
|
const appCallOffset = await this.computeAppCallOffset(opts.from, opts.feeOptions);
|
|
330
375
|
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
@@ -361,6 +406,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
361
406
|
feePayer: executionPayload.feePayer,
|
|
362
407
|
gasSettings: opts.fee?.gasSettings,
|
|
363
408
|
forEstimation: true,
|
|
409
|
+
congestionEstimate: opts.fee?.congestionEstimate,
|
|
364
410
|
});
|
|
365
411
|
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
366
412
|
const remainingPayload = { ...executionPayload, calls: remainingCalls };
|
|
@@ -372,7 +418,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
372
418
|
try {
|
|
373
419
|
blockHeader = await this.pxe.getSyncedBlockHeader();
|
|
374
420
|
} catch {
|
|
375
|
-
blockHeader = (await this.aztecNode.
|
|
421
|
+
blockHeader = (await this.aztecNode.getBlockData('latest'))!.header;
|
|
376
422
|
}
|
|
377
423
|
|
|
378
424
|
const simulationOrigin = opts.from === NO_FROM ? AztecAddress.ZERO : opts.from;
|
|
@@ -387,6 +433,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
387
433
|
blockHeader,
|
|
388
434
|
opts.skipFeeEnforcement ?? true,
|
|
389
435
|
this.getContractName.bind(this),
|
|
436
|
+
opts.overrides,
|
|
390
437
|
)
|
|
391
438
|
: Promise.resolve([]),
|
|
392
439
|
remainingCalls.length > 0
|
|
@@ -396,6 +443,8 @@ export abstract class BaseWallet implements Wallet {
|
|
|
396
443
|
additionalScopes: opts.additionalScopes,
|
|
397
444
|
skipTxValidation: opts.skipTxValidation,
|
|
398
445
|
skipFeeEnforcement: opts.skipFeeEnforcement ?? true,
|
|
446
|
+
sendMessagesAs: opts.sendMessagesAs,
|
|
447
|
+
overrides: opts.overrides,
|
|
399
448
|
})
|
|
400
449
|
: Promise.resolve(null),
|
|
401
450
|
]);
|
|
@@ -408,12 +457,14 @@ export abstract class BaseWallet implements Wallet {
|
|
|
408
457
|
from: opts.from,
|
|
409
458
|
feePayer: executionPayload.feePayer,
|
|
410
459
|
gasSettings: opts.fee?.gasSettings,
|
|
460
|
+
congestionEstimate: opts.fee?.congestionEstimate,
|
|
411
461
|
});
|
|
412
462
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
413
463
|
return this.pxe.profileTx(txRequest, {
|
|
414
464
|
profileMode: opts.profileMode,
|
|
415
465
|
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
416
466
|
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
467
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
417
468
|
});
|
|
418
469
|
}
|
|
419
470
|
|
|
@@ -425,16 +476,20 @@ export abstract class BaseWallet implements Wallet {
|
|
|
425
476
|
from: opts.from,
|
|
426
477
|
feePayer: executionPayload.feePayer,
|
|
427
478
|
gasSettings: opts.fee?.gasSettings,
|
|
479
|
+
congestionEstimate: opts.fee?.congestionEstimate,
|
|
428
480
|
});
|
|
429
481
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
430
|
-
const provenTx = await this.pxe.proveTx(txRequest,
|
|
482
|
+
const provenTx = await this.pxe.proveTx(txRequest, {
|
|
483
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
484
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
485
|
+
});
|
|
431
486
|
const offchainOutput = extractOffchainOutput(
|
|
432
487
|
provenTx.getOffchainEffects(),
|
|
433
488
|
provenTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp,
|
|
434
489
|
);
|
|
435
490
|
const tx = await provenTx.toTx();
|
|
436
491
|
const txHash = tx.getTxHash();
|
|
437
|
-
if (await this.aztecNode.
|
|
492
|
+
if ((await this.aztecNode.getTxReceipt(txHash)).isMined()) {
|
|
438
493
|
throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
|
|
439
494
|
}
|
|
440
495
|
this.log.debug(`Sending transaction ${txHash}`);
|
|
@@ -453,7 +508,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
453
508
|
const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
454
509
|
|
|
455
510
|
// Display debug logs from public execution if present (served in test mode only)
|
|
456
|
-
if (receipt.debugLogs?.length) {
|
|
511
|
+
if (receipt.isMined() && receipt.debugLogs?.length) {
|
|
457
512
|
await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
|
|
458
513
|
}
|
|
459
514
|
|
package/src/base-wallet/utils.ts
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
PrivateCallExecutionResult,
|
|
26
26
|
PrivateExecutionResult,
|
|
27
27
|
PublicSimulationOutput,
|
|
28
|
+
type SimulationOverrides,
|
|
28
29
|
Tx,
|
|
29
30
|
TxContext,
|
|
30
31
|
TxSimulationResult,
|
|
@@ -65,6 +66,8 @@ export function extractOptimizablePublicStaticCalls(payload: ExecutionPayload):
|
|
|
65
66
|
* @param gasSettings - Gas settings for the transaction.
|
|
66
67
|
* @param blockHeader - Block header to use as anchor.
|
|
67
68
|
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
69
|
+
* @param getContractName - Resolver for contract names (used for debug log display).
|
|
70
|
+
* @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
|
|
68
71
|
* @returns TxSimulationResult with public return values.
|
|
69
72
|
*/
|
|
70
73
|
async function simulateBatchViaNode(
|
|
@@ -76,6 +79,7 @@ async function simulateBatchViaNode(
|
|
|
76
79
|
blockHeader: BlockHeader,
|
|
77
80
|
skipFeeEnforcement: boolean,
|
|
78
81
|
getContractName: ContractNameResolver,
|
|
82
|
+
overrides?: SimulationOverrides,
|
|
79
83
|
): Promise<TxSimulationResult> {
|
|
80
84
|
const txContext = new TxContext(chainInfo.chainId, chainInfo.version, gasSettings);
|
|
81
85
|
|
|
@@ -143,7 +147,7 @@ async function simulateBatchViaNode(
|
|
|
143
147
|
publicFunctionCalldata: publicFunctionCalldata,
|
|
144
148
|
});
|
|
145
149
|
|
|
146
|
-
const publicOutput = await node.simulatePublicCalls(tx, skipFeeEnforcement);
|
|
150
|
+
const publicOutput = await node.simulatePublicCalls(tx, skipFeeEnforcement, overrides);
|
|
147
151
|
|
|
148
152
|
if (publicOutput.revertReason) {
|
|
149
153
|
throw publicOutput.revertReason;
|
|
@@ -166,6 +170,8 @@ async function simulateBatchViaNode(
|
|
|
166
170
|
* @param gasSettings - Gas settings for the transaction.
|
|
167
171
|
* @param blockHeader - Block header to use as anchor.
|
|
168
172
|
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
173
|
+
* @param getContractName - Resolver for contract names (used for debug log display).
|
|
174
|
+
* @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
|
|
169
175
|
* @returns Array of TxSimulationResult, one per batch.
|
|
170
176
|
*/
|
|
171
177
|
export async function simulateViaNode(
|
|
@@ -177,6 +183,7 @@ export async function simulateViaNode(
|
|
|
177
183
|
blockHeader: BlockHeader,
|
|
178
184
|
skipFeeEnforcement: boolean = true,
|
|
179
185
|
getContractName: ContractNameResolver,
|
|
186
|
+
overrides?: SimulationOverrides,
|
|
180
187
|
): Promise<TxSimulationResult[]> {
|
|
181
188
|
const batches: FunctionCall[][] = [];
|
|
182
189
|
|
|
@@ -196,6 +203,7 @@ export async function simulateViaNode(
|
|
|
196
203
|
blockHeader,
|
|
197
204
|
skipFeeEnforcement,
|
|
198
205
|
getContractName,
|
|
206
|
+
overrides,
|
|
199
207
|
);
|
|
200
208
|
results.push(result);
|
|
201
209
|
}
|