@aztec/wallet-sdk 0.0.1-commit.96bb3f7 → 0.0.1-commit.993d240
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 +218 -355
- package/dest/base-wallet/base_wallet.d.ts +109 -40
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +286 -71
- package/dest/base-wallet/index.d.ts +3 -2
- package/dest/base-wallet/index.d.ts.map +1 -1
- package/dest/base-wallet/index.js +1 -0
- package/dest/base-wallet/utils.d.ts +52 -0
- package/dest/base-wallet/utils.d.ts.map +1 -0
- package/dest/base-wallet/utils.js +137 -0
- package/dest/crypto.d.ts +111 -27
- package/dest/crypto.d.ts.map +1 -1
- package/dest/crypto.js +307 -41
- 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 +168 -0
- package/dest/extension/handlers/background_connection_handler.d.ts.map +1 -0
- package/dest/extension/handlers/background_connection_handler.js +294 -0
- package/dest/extension/handlers/content_script_connection_handler.d.ts +57 -0
- package/dest/extension/handlers/content_script_connection_handler.d.ts.map +1 -0
- package/dest/extension/handlers/content_script_connection_handler.js +193 -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 +65 -0
- package/dest/extension/handlers/internal_message_types.d.ts.map +1 -0
- package/dest/extension/handlers/internal_message_types.js +24 -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 +152 -0
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -0
- package/dest/extension/provider/extension_wallet.js +349 -0
- 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 -1
- package/dest/iframe/handlers/iframe_connection_handler.d.ts +122 -0
- package/dest/iframe/handlers/iframe_connection_handler.d.ts.map +1 -0
- package/dest/iframe/handlers/iframe_connection_handler.js +239 -0
- package/dest/iframe/handlers/index.d.ts +2 -0
- package/dest/iframe/handlers/index.d.ts.map +1 -0
- package/dest/iframe/handlers/index.js +1 -0
- package/dest/iframe/provider/iframe_discovery.d.ts +25 -0
- package/dest/iframe/provider/iframe_discovery.d.ts.map +1 -0
- package/dest/iframe/provider/iframe_discovery.js +167 -0
- package/dest/iframe/provider/iframe_provider.d.ts +65 -0
- package/dest/iframe/provider/iframe_provider.d.ts.map +1 -0
- package/dest/iframe/provider/iframe_provider.js +257 -0
- package/dest/iframe/provider/iframe_wallet.d.ts +85 -0
- package/dest/iframe/provider/iframe_wallet.d.ts.map +1 -0
- package/dest/iframe/provider/iframe_wallet.js +269 -0
- package/dest/iframe/provider/index.d.ts +4 -0
- package/dest/iframe/provider/index.d.ts.map +1 -0
- package/dest/iframe/provider/index.js +3 -0
- package/dest/manager/index.d.ts +2 -7
- package/dest/manager/index.d.ts.map +1 -1
- package/dest/manager/index.js +0 -4
- package/dest/manager/types.d.ts +109 -5
- 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 +208 -29
- package/dest/types.d.ts +117 -15
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +39 -2
- package/package.json +22 -11
- package/src/base-wallet/base_wallet.ts +395 -128
- package/src/base-wallet/index.ts +7 -1
- package/src/base-wallet/utils.ts +248 -0
- package/src/crypto.ts +367 -47
- package/src/emoji_alphabet.ts +317 -0
- package/src/extension/handlers/background_connection_handler.ts +456 -0
- package/src/extension/handlers/content_script_connection_handler.ts +264 -0
- package/src/extension/handlers/index.ts +25 -0
- package/src/extension/handlers/internal_message_types.ts +71 -0
- package/src/extension/provider/extension_provider.ts +233 -0
- package/src/extension/provider/extension_wallet.ts +410 -0
- package/src/extension/provider/index.ts +7 -0
- package/src/iframe/handlers/iframe_connection_handler.ts +341 -0
- package/src/iframe/handlers/index.ts +7 -0
- package/src/iframe/provider/iframe_discovery.ts +185 -0
- package/src/iframe/provider/iframe_provider.ts +331 -0
- package/src/iframe/provider/iframe_wallet.ts +323 -0
- package/src/iframe/provider/index.ts +3 -0
- package/src/manager/index.ts +3 -9
- package/src/manager/types.ts +113 -4
- package/src/manager/wallet_manager.ts +235 -30
- package/src/types.ts +129 -14
- package/dest/providers/extension/extension_provider.d.ts +0 -17
- package/dest/providers/extension/extension_provider.d.ts.map +0 -1
- package/dest/providers/extension/extension_provider.js +0 -56
- package/dest/providers/extension/extension_wallet.d.ts +0 -95
- package/dest/providers/extension/extension_wallet.d.ts.map +0 -1
- package/dest/providers/extension/extension_wallet.js +0 -225
- package/dest/providers/extension/index.d.ts +0 -5
- package/dest/providers/extension/index.d.ts.map +0 -1
- package/src/providers/extension/extension_provider.ts +0 -72
- package/src/providers/extension/extension_wallet.ts +0 -275
- package/src/providers/extension/index.ts +0 -11
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
2
|
+
import { NO_WAIT, extractOffchainOutput } from '@aztec/aztec.js/contracts';
|
|
3
|
+
import { waitForTx } from '@aztec/aztec.js/node';
|
|
4
|
+
import { ContractInitializationStatus, TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
2
5
|
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
6
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
3
7
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
8
|
import { createLogger } from '@aztec/foundation/log';
|
|
9
|
+
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
5
10
|
import { decodeFromAbi } from '@aztec/stdlib/abi';
|
|
11
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
12
|
import { computePartialAddress, getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
7
13
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
8
|
-
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
14
|
+
import { Gas, GasFees, GasSettings, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
15
|
+
import { computeSiloedPrivateInitializationNullifier, computeSiloedPublicInitializationNullifier } from '@aztec/stdlib/hash';
|
|
9
16
|
import { mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
10
17
|
import { inspect } from 'util';
|
|
18
|
+
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
11
19
|
/**
|
|
12
20
|
* A base class for Wallet implementations
|
|
13
21
|
*/ export class BaseWallet {
|
|
@@ -16,14 +24,36 @@ import { inspect } from 'util';
|
|
|
16
24
|
log;
|
|
17
25
|
minFeePadding;
|
|
18
26
|
cancellableTransactions;
|
|
27
|
+
// A wallet is instantiated for a particular chain, so chain info never changes during its lifetime.
|
|
28
|
+
// We cache it here because getChainInfo is called frequently (every tx simulation, send, auth wit, etc.).
|
|
29
|
+
nodeInfoPromise;
|
|
19
30
|
// Protected because we want to force wallets to instantiate their own PXE.
|
|
20
|
-
constructor(pxe, aztecNode){
|
|
31
|
+
constructor(pxe, aztecNode, log = createLogger('wallet-sdk:base_wallet')){
|
|
21
32
|
this.pxe = pxe;
|
|
22
33
|
this.aztecNode = aztecNode;
|
|
23
|
-
this.log =
|
|
34
|
+
this.log = log;
|
|
24
35
|
this.minFeePadding = 0.5;
|
|
25
36
|
this.cancellableTransactions = false;
|
|
26
37
|
}
|
|
38
|
+
scopesFrom(from, additionalScopes = []) {
|
|
39
|
+
const allScopes = from === NO_FROM ? additionalScopes : [
|
|
40
|
+
from,
|
|
41
|
+
...additionalScopes
|
|
42
|
+
];
|
|
43
|
+
const scopeSet = new Set(allScopes.map((address)=>address.toString()));
|
|
44
|
+
return [
|
|
45
|
+
...scopeSet
|
|
46
|
+
].map(AztecAddress.fromString);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Picks the sender address PXE should tag private messages with. Returns `undefined` when there is no signing
|
|
50
|
+
* account (`from === NO_FROM`) and no explicit override; in that case any private log emitted by the tx using
|
|
51
|
+
* the wallet-supplied default sender will fail the "Sender for tags is not set" assertion.
|
|
52
|
+
* @param from - Tx sender, or `NO_FROM`.
|
|
53
|
+
* @param sendMessagesAs - Explicit override.
|
|
54
|
+
*/ senderForTagsFrom(from, sendMessagesAs) {
|
|
55
|
+
return sendMessagesAs ?? (from === NO_FROM ? undefined : from);
|
|
56
|
+
}
|
|
27
57
|
/**
|
|
28
58
|
* Returns the list of aliased contacts associated with the wallet.
|
|
29
59
|
* This base implementation directly returns PXE's senders, but note that in general contacts are a superset of senders.
|
|
@@ -38,7 +68,10 @@ import { inspect } from 'util';
|
|
|
38
68
|
}));
|
|
39
69
|
}
|
|
40
70
|
async getChainInfo() {
|
|
41
|
-
|
|
71
|
+
if (!this.nodeInfoPromise) {
|
|
72
|
+
this.nodeInfoPromise = this.aztecNode.getNodeInfo();
|
|
73
|
+
}
|
|
74
|
+
const { l1ChainId, rollupVersion } = await this.nodeInfoPromise;
|
|
42
75
|
return {
|
|
43
76
|
chainId: new Fr(l1ChainId),
|
|
44
77
|
version: new Fr(rollupVersion)
|
|
@@ -46,21 +79,44 @@ import { inspect } from 'util';
|
|
|
46
79
|
}
|
|
47
80
|
async createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions) {
|
|
48
81
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
49
|
-
const executionOptions = {
|
|
50
|
-
txNonce: Fr.random(),
|
|
51
|
-
cancellable: this.cancellableTransactions,
|
|
52
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
53
|
-
};
|
|
54
82
|
const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
|
|
55
83
|
feeExecutionPayload,
|
|
56
84
|
executionPayload
|
|
57
85
|
]) : executionPayload;
|
|
58
|
-
const
|
|
59
|
-
|
|
86
|
+
const chainInfo = await this.getChainInfo();
|
|
87
|
+
if (from === NO_FROM) {
|
|
88
|
+
const entrypoint = new DefaultEntrypoint();
|
|
89
|
+
return entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
90
|
+
} else {
|
|
91
|
+
const fromAccount = await this.getAccountFromAddress(from);
|
|
92
|
+
const executionOptions = {
|
|
93
|
+
txNonce: Fr.random(),
|
|
94
|
+
cancellable: this.cancellableTransactions,
|
|
95
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
96
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
97
|
+
};
|
|
98
|
+
return fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
|
|
99
|
+
}
|
|
60
100
|
}
|
|
61
101
|
async createAuthWit(from, messageHashOrIntent) {
|
|
62
102
|
const account = await this.getAccountFromAddress(from);
|
|
63
|
-
|
|
103
|
+
const chainInfo = await this.getChainInfo();
|
|
104
|
+
return account.createAuthWit(messageHashOrIntent, chainInfo);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Request capabilities from the wallet.
|
|
108
|
+
*
|
|
109
|
+
* This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
|
|
110
|
+
* Embedded wallets typically don't support capability-based authorization (no user authorization flow),
|
|
111
|
+
* while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
|
|
112
|
+
* friction by allowing apps to request permissions upfront.
|
|
113
|
+
*
|
|
114
|
+
* TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
|
|
115
|
+
* while the feature stabilizes.
|
|
116
|
+
*
|
|
117
|
+
* @param _manifest - Application capability manifest declaring what operations the app needs
|
|
118
|
+
*/ requestCapabilities(_manifest) {
|
|
119
|
+
throw new Error('Not implemented');
|
|
64
120
|
}
|
|
65
121
|
async batch(methods) {
|
|
66
122
|
const results = [];
|
|
@@ -83,26 +139,33 @@ import { inspect } from 'util';
|
|
|
83
139
|
}
|
|
84
140
|
/**
|
|
85
141
|
* Completes partial user-provided fee options with wallet defaults.
|
|
86
|
-
* @param
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
*/ async completeFeeOptions(from, feePayer, gasSettings) {
|
|
91
|
-
const maxFeesPerGas = gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentMinFees()).mul(1 + this.minFeePadding);
|
|
142
|
+
* @param config - Fee completion config.
|
|
143
|
+
*/ async completeFeeOptions(config) {
|
|
144
|
+
const { from, feePayer, gasSettings, forEstimation, congestionEstimate } = config;
|
|
145
|
+
const maxFeesPerGas = gasSettings?.maxFeesPerGas ?? (await this.getMinFees(congestionEstimate)).mul(1 + this.minFeePadding);
|
|
92
146
|
let accountFeePaymentMethodOptions;
|
|
93
|
-
//
|
|
94
|
-
//
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
147
|
+
// If from is an address, we need to determine the appropriate fee payment method options for the
|
|
148
|
+
// account contract entrypoint to use
|
|
149
|
+
if (from !== NO_FROM) {
|
|
150
|
+
if (!feePayer) {
|
|
151
|
+
// The transaction does not include a fee payment method, so we set the flag
|
|
152
|
+
// for the account to use its fee juice balance
|
|
153
|
+
accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
|
|
154
|
+
} else {
|
|
155
|
+
// The transaction includes fee payment method, so we check if we are the fee payer for it
|
|
156
|
+
// (this can only happen if the embedded payment method is FeeJuiceWithClaim)
|
|
157
|
+
accountFeePaymentMethodOptions = from.equals(feePayer) ? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM : AccountFeePaymentMethodOptions.EXTERNAL;
|
|
158
|
+
}
|
|
101
159
|
}
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
160
|
+
const gasSettingsOverrides = {
|
|
161
|
+
gasLimits: gasSettings?.gasLimits ? Gas.from(gasSettings.gasLimits) : undefined,
|
|
162
|
+
teardownGasLimits: gasSettings?.teardownGasLimits ? Gas.from(gasSettings.teardownGasLimits) : undefined,
|
|
163
|
+
maxFeesPerGas,
|
|
164
|
+
maxPriorityFeesPerGas: gasSettings?.maxPriorityFeesPerGas ?? GasFees.empty()
|
|
165
|
+
};
|
|
166
|
+
// When estimating gas (simulation), use high limits so the simulation doesn't run out of gas.
|
|
167
|
+
// When sending for real, use protocol max limits that the network will actually accept.
|
|
168
|
+
const fullGasSettings = forEstimation ? GasSettings.forEstimation(gasSettingsOverrides) : GasSettings.fallback(gasSettingsOverrides);
|
|
106
169
|
this.log.debug(`Using L2 gas settings`, fullGasSettings);
|
|
107
170
|
return {
|
|
108
171
|
gasSettings: fullGasSettings,
|
|
@@ -111,28 +174,30 @@ import { inspect } from 'util';
|
|
|
111
174
|
};
|
|
112
175
|
}
|
|
113
176
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* to
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
177
|
+
* Returns the worst-case min fee across predicted future slots.
|
|
178
|
+
* Falls back to getCurrentMinFees if the node doesn't support getPredictedMinFees.
|
|
179
|
+
* @param estimate - The mana usage estimate to use for fee prediction. Defaults to Limit for conservative estimation.
|
|
180
|
+
*/ async getMinFees(estimate = ManaUsageEstimate.Limit) {
|
|
181
|
+
try {
|
|
182
|
+
const predicted = await this.aztecNode.getPredictedMinFees(estimate);
|
|
183
|
+
if (predicted.length === 0) {
|
|
184
|
+
return this.aztecNode.getCurrentMinFees();
|
|
185
|
+
}
|
|
186
|
+
return predicted.reduce((worst, fees)=>fees.feePerL2Gas > worst.feePerL2Gas ? fees : worst);
|
|
187
|
+
} catch (err) {
|
|
188
|
+
// Fallback for old nodes that don't support getPredictedMinFees.
|
|
189
|
+
// Only fall back on method-not-found errors (JSON-RPC code -32601); rethrow others.
|
|
190
|
+
if (err?.cause?.code === -32601 || err?.message?.includes('Method not found')) {
|
|
191
|
+
return this.aztecNode.getCurrentMinFees();
|
|
192
|
+
}
|
|
193
|
+
throw err;
|
|
194
|
+
}
|
|
130
195
|
}
|
|
131
196
|
registerSender(address, _alias = '') {
|
|
132
197
|
return this.pxe.registerSender(address);
|
|
133
198
|
}
|
|
134
199
|
async registerContract(instance, artifact, secretKey) {
|
|
135
|
-
const
|
|
200
|
+
const existingInstance = await this.pxe.getContractInstance(instance.address);
|
|
136
201
|
if (existingInstance) {
|
|
137
202
|
// Instance already registered in the wallet
|
|
138
203
|
if (artifact) {
|
|
@@ -148,11 +213,10 @@ import { inspect } from 'util';
|
|
|
148
213
|
// Instance not registered yet
|
|
149
214
|
if (!artifact) {
|
|
150
215
|
// Try to get the artifact from the wallet's contract class storage
|
|
151
|
-
|
|
152
|
-
if (!
|
|
216
|
+
artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
217
|
+
if (!artifact) {
|
|
153
218
|
throw new Error(`Cannot register contract at ${instance.address.toString()}: artifact is required but not provided, and wallet does not have the artifact for contract class ${instance.currentContractClassId.toString()}`);
|
|
154
219
|
}
|
|
155
|
-
artifact = classMetadata.artifact;
|
|
156
220
|
}
|
|
157
221
|
await this.pxe.registerContract({
|
|
158
222
|
artifact,
|
|
@@ -164,20 +228,110 @@ import { inspect } from 'util';
|
|
|
164
228
|
}
|
|
165
229
|
return instance;
|
|
166
230
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
231
|
+
registerContractClass(artifact) {
|
|
232
|
+
return this.pxe.registerContractClass(artifact);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Simulates calls through the standard PXE path (account entrypoint).
|
|
236
|
+
* @param executionPayload - The execution payload to simulate.
|
|
237
|
+
* @param opts - Simulation options.
|
|
238
|
+
*/ async simulateViaEntrypoint(executionPayload, opts) {
|
|
239
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, opts.feeOptions);
|
|
240
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
241
|
+
simulatePublic: true,
|
|
242
|
+
skipTxValidation: opts.skipTxValidation,
|
|
243
|
+
skipFeeEnforcement: opts.skipFeeEnforcement,
|
|
244
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
245
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs),
|
|
246
|
+
overrides: opts.overrides
|
|
247
|
+
});
|
|
248
|
+
const appCallOffset = await this.computeAppCallOffset(opts.from, opts.feeOptions);
|
|
249
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Computes the index where the app's calls begin in the flattened array of calls (0 = entrypoint/root, 1..N = fee
|
|
253
|
+
* calls, N+1 = app).
|
|
254
|
+
* @param from - The sender address, or NO_FROM for the default entrypoint.
|
|
255
|
+
* @param feeOptions - Fee options containing the wallet fee payment method.
|
|
256
|
+
*/ async computeAppCallOffset(from, feeOptions) {
|
|
257
|
+
if (from === NO_FROM) {
|
|
258
|
+
return 0;
|
|
259
|
+
}
|
|
260
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
261
|
+
return (feeExecutionPayload?.calls.length ?? 0) + 1; // +1 for entrypoint
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
265
|
+
* on the node while sending the remaining calls through the standard PXE path.
|
|
266
|
+
* Return values from both paths are merged back in original call order.
|
|
267
|
+
* @param executionPayload - The execution payload to simulate.
|
|
268
|
+
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
269
|
+
* @returns The merged simulation result.
|
|
270
|
+
*/ async simulateTx(executionPayload, opts) {
|
|
271
|
+
const feeOptions = await this.completeFeeOptions({
|
|
272
|
+
from: opts.from,
|
|
273
|
+
feePayer: executionPayload.feePayer,
|
|
274
|
+
gasSettings: opts.fee?.gasSettings,
|
|
275
|
+
forEstimation: true,
|
|
276
|
+
congestionEstimate: opts.fee?.congestionEstimate
|
|
277
|
+
});
|
|
278
|
+
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
279
|
+
const remainingPayload = {
|
|
280
|
+
...executionPayload,
|
|
281
|
+
calls: remainingCalls
|
|
282
|
+
};
|
|
283
|
+
const chainInfo = await this.getChainInfo();
|
|
284
|
+
let blockHeader;
|
|
285
|
+
// PXE might not be synced yet, so we pull the latest header from the node
|
|
286
|
+
// To keep things consistent, we'll always try with PXE first
|
|
287
|
+
try {
|
|
288
|
+
blockHeader = await this.pxe.getSyncedBlockHeader();
|
|
289
|
+
} catch {
|
|
290
|
+
blockHeader = (await this.aztecNode.getBlockData('latest')).header;
|
|
291
|
+
}
|
|
292
|
+
const simulationOrigin = opts.from === NO_FROM ? AztecAddress.ZERO : opts.from;
|
|
293
|
+
const [optimizedResults, normalResult] = await Promise.all([
|
|
294
|
+
optimizableCalls.length > 0 ? simulateViaNode(this.aztecNode, optimizableCalls, simulationOrigin, chainInfo, feeOptions.gasSettings, blockHeader, opts.skipFeeEnforcement ?? true, this.getContractName.bind(this), opts.overrides) : Promise.resolve([]),
|
|
295
|
+
remainingCalls.length > 0 ? this.simulateViaEntrypoint(remainingPayload, {
|
|
296
|
+
from: opts.from,
|
|
297
|
+
feeOptions,
|
|
298
|
+
additionalScopes: opts.additionalScopes,
|
|
299
|
+
skipTxValidation: opts.skipTxValidation,
|
|
300
|
+
skipFeeEnforcement: opts.skipFeeEnforcement ?? true,
|
|
301
|
+
sendMessagesAs: opts.sendMessagesAs,
|
|
302
|
+
overrides: opts.overrides
|
|
303
|
+
}) : Promise.resolve(null)
|
|
304
|
+
]);
|
|
305
|
+
return buildMergedSimulationResult(optimizedResults, normalResult);
|
|
171
306
|
}
|
|
172
307
|
async profileTx(executionPayload, opts) {
|
|
173
|
-
const feeOptions = await this.completeFeeOptions(
|
|
308
|
+
const feeOptions = await this.completeFeeOptions({
|
|
309
|
+
from: opts.from,
|
|
310
|
+
feePayer: executionPayload.feePayer,
|
|
311
|
+
gasSettings: opts.fee?.gasSettings,
|
|
312
|
+
congestionEstimate: opts.fee?.congestionEstimate
|
|
313
|
+
});
|
|
174
314
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
175
|
-
return this.pxe.profileTx(txRequest,
|
|
315
|
+
return this.pxe.profileTx(txRequest, {
|
|
316
|
+
profileMode: opts.profileMode,
|
|
317
|
+
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
318
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
319
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs)
|
|
320
|
+
});
|
|
176
321
|
}
|
|
177
322
|
async sendTx(executionPayload, opts) {
|
|
178
|
-
const feeOptions = await this.completeFeeOptions(
|
|
323
|
+
const feeOptions = await this.completeFeeOptions({
|
|
324
|
+
from: opts.from,
|
|
325
|
+
feePayer: executionPayload.feePayer,
|
|
326
|
+
gasSettings: opts.fee?.gasSettings,
|
|
327
|
+
congestionEstimate: opts.fee?.congestionEstimate
|
|
328
|
+
});
|
|
179
329
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
180
|
-
const provenTx = await this.pxe.proveTx(txRequest
|
|
330
|
+
const provenTx = await this.pxe.proveTx(txRequest, {
|
|
331
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
332
|
+
senderForTags: this.senderForTagsFrom(opts.from, opts.sendMessagesAs)
|
|
333
|
+
});
|
|
334
|
+
const offchainOutput = extractOffchainOutput(provenTx.getOffchainEffects(), provenTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp);
|
|
181
335
|
const tx = await provenTx.toTx();
|
|
182
336
|
const txHash = tx.getTxHash();
|
|
183
337
|
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
@@ -188,7 +342,35 @@ import { inspect } from 'util';
|
|
|
188
342
|
throw this.contextualizeError(err, inspect(tx));
|
|
189
343
|
});
|
|
190
344
|
this.log.info(`Sent transaction ${txHash}`);
|
|
191
|
-
return txHash
|
|
345
|
+
// If wait is NO_WAIT, return txHash immediately
|
|
346
|
+
if (opts.wait === NO_WAIT) {
|
|
347
|
+
return {
|
|
348
|
+
txHash,
|
|
349
|
+
...offchainOutput
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
353
|
+
const waitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
354
|
+
const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
355
|
+
// Display debug logs from public execution if present (served in test mode only)
|
|
356
|
+
if (receipt.debugLogs?.length) {
|
|
357
|
+
await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
|
|
358
|
+
}
|
|
359
|
+
return {
|
|
360
|
+
receipt,
|
|
361
|
+
...offchainOutput
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Resolves a contract address to a human-readable name via PXE, if available.
|
|
366
|
+
* @param address - The contract address to resolve.
|
|
367
|
+
*/ async getContractName(address) {
|
|
368
|
+
const instance = await this.pxe.getContractInstance(address);
|
|
369
|
+
if (!instance) {
|
|
370
|
+
return undefined;
|
|
371
|
+
}
|
|
372
|
+
const artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
373
|
+
return artifact?.name;
|
|
192
374
|
}
|
|
193
375
|
contextualizeError(err, ...context) {
|
|
194
376
|
let contextStr = '';
|
|
@@ -203,17 +385,11 @@ import { inspect } from 'util';
|
|
|
203
385
|
}
|
|
204
386
|
return err;
|
|
205
387
|
}
|
|
206
|
-
|
|
207
|
-
return this.pxe.
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
getContractMetadata(address) {
|
|
213
|
-
return this.pxe.getContractMetadata(address);
|
|
214
|
-
}
|
|
215
|
-
getTxReceipt(txHash) {
|
|
216
|
-
return this.aztecNode.getTxReceipt(txHash);
|
|
388
|
+
executeUtility(call, opts) {
|
|
389
|
+
return this.pxe.executeUtility(call, {
|
|
390
|
+
authwits: opts.authWitnesses,
|
|
391
|
+
scopes: opts.scopes
|
|
392
|
+
});
|
|
217
393
|
}
|
|
218
394
|
async getPrivateEvents(eventDef, eventFilter) {
|
|
219
395
|
const pxeEvents = await this.pxe.getPrivateEvents(eventDef.eventSelector, eventFilter);
|
|
@@ -231,4 +407,43 @@ import { inspect } from 'util';
|
|
|
231
407
|
});
|
|
232
408
|
return decodedEvents;
|
|
233
409
|
}
|
|
410
|
+
/**
|
|
411
|
+
* Returns metadata about a contract, including whether it has been initialized, published, and updated.
|
|
412
|
+
* @param address - The contract address to query.
|
|
413
|
+
*/ async getContractMetadata(address) {
|
|
414
|
+
const instance = await this.pxe.getContractInstance(address);
|
|
415
|
+
const publiclyRegisteredContractPromise = this.aztecNode.getContract(address);
|
|
416
|
+
let initializationStatus;
|
|
417
|
+
if (instance) {
|
|
418
|
+
// We have the instance, so we can compute the private initialization nullifier (which includes init_hash and is
|
|
419
|
+
// emitted by both private and public initializers) and get a definitive INITIALIZED/UNINITIALIZED answer.
|
|
420
|
+
const initNullifier = await computeSiloedPrivateInitializationNullifier(address, instance.initializationHash);
|
|
421
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
422
|
+
initializationStatus = witness ? ContractInitializationStatus.INITIALIZED : ContractInitializationStatus.UNINITIALIZED;
|
|
423
|
+
} else {
|
|
424
|
+
// Without the instance we lack the init_hash needed for the private nullifier. We fall back to checking the
|
|
425
|
+
// public initialization nullifier (computed from address alone). Not all contracts emit it (only those with
|
|
426
|
+
// public functions that require initialization checks), so its absence doesn't mean the contract is
|
|
427
|
+
// uninitialized.
|
|
428
|
+
const publicNullifier = await computeSiloedPublicInitializationNullifier(address);
|
|
429
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', publicNullifier);
|
|
430
|
+
initializationStatus = witness ? ContractInitializationStatus.INITIALIZED : ContractInitializationStatus.UNKNOWN;
|
|
431
|
+
}
|
|
432
|
+
const publiclyRegisteredContract = await publiclyRegisteredContractPromise;
|
|
433
|
+
const isContractUpdated = publiclyRegisteredContract && !publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
434
|
+
return {
|
|
435
|
+
instance: instance ?? undefined,
|
|
436
|
+
initializationStatus,
|
|
437
|
+
isContractPublished: !!publiclyRegisteredContract,
|
|
438
|
+
isContractUpdated: !!isContractUpdated,
|
|
439
|
+
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
async getContractClassMetadata(id) {
|
|
443
|
+
const publiclyRegisteredContractClass = await this.aztecNode.getContractClass(id);
|
|
444
|
+
return {
|
|
445
|
+
isArtifactRegistered: !!await this.pxe.getContractArtifact(id),
|
|
446
|
+
isContractClassPubliclyRegistered: !!publiclyRegisteredContractClass
|
|
447
|
+
};
|
|
448
|
+
}
|
|
234
449
|
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { BaseWallet, type FeeOptions } from './base_wallet.js';
|
|
2
|
-
|
|
1
|
+
export { BaseWallet, type CompleteFeeOptionsConfig, type FeeOptions, type SimulateViaEntrypointOptions, } from './base_wallet.js';
|
|
2
|
+
export { simulateViaNode, buildMergedSimulationResult, extractOptimizablePublicStaticCalls } from './utils.js';
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsVUFBVSxFQUNWLEtBQUssd0JBQXdCLEVBQzdCLEtBQUssVUFBVSxFQUNmLEtBQUssNEJBQTRCLEdBQ2xDLE1BQU0sa0JBQWtCLENBQUM7QUFDMUIsT0FBTyxFQUFFLGVBQWUsRUFBRSwyQkFBMkIsRUFBRSxtQ0FBbUMsRUFBRSxNQUFNLFlBQVksQ0FBQyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base-wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base-wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EACf,KAAK,4BAA4B,GAClC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,mCAAmC,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
2
|
+
import { TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
3
|
+
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
4
|
+
import type { ContractNameResolver } from '@aztec/pxe/client/lazy';
|
|
5
|
+
import { type FunctionCall } from '@aztec/stdlib/abi';
|
|
6
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
|
+
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
8
|
+
import { type BlockHeader, type ExecutionPayload, type SimulationOverrides, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
9
|
+
/**
|
|
10
|
+
* Splits an execution payload into a leading prefix of public static calls
|
|
11
|
+
* (eligible for direct node simulation) and the remaining calls.
|
|
12
|
+
*
|
|
13
|
+
* Only a leading run of public static calls is eligible for optimization.
|
|
14
|
+
* Any non-public-static call may enqueue public state mutations
|
|
15
|
+
* (e.g. private calls can enqueue public calls), so all calls that follow
|
|
16
|
+
* must go through the normal simulation path to see the correct state.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
export declare function extractOptimizablePublicStaticCalls(payload: ExecutionPayload): {
|
|
20
|
+
/** Leading public static calls eligible for direct node simulation. */
|
|
21
|
+
optimizableCalls: FunctionCall[];
|
|
22
|
+
/** All remaining calls. */
|
|
23
|
+
remainingCalls: FunctionCall[];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Simulates public static calls by splitting them into batches of MAX_ENQUEUED_CALLS_PER_CALL
|
|
27
|
+
* and sending each batch directly to the node.
|
|
28
|
+
*
|
|
29
|
+
* @param node - The Aztec node to simulate on.
|
|
30
|
+
* @param publicStaticCalls - Array of public static function calls to optimize.
|
|
31
|
+
* @param from - The account address making the calls.
|
|
32
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
33
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
34
|
+
* @param blockHeader - Block header to use as anchor.
|
|
35
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
36
|
+
* @param getContractName - Resolver for contract names (used for debug log display).
|
|
37
|
+
* @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
|
|
38
|
+
* @returns Array of TxSimulationResult, one per batch.
|
|
39
|
+
*/
|
|
40
|
+
export declare function simulateViaNode(node: AztecNode, publicStaticCalls: FunctionCall[], from: AztecAddress, chainInfo: ChainInfo, gasSettings: GasSettings, blockHeader: BlockHeader, skipFeeEnforcement: boolean | undefined, getContractName: ContractNameResolver, overrides?: SimulationOverrides): Promise<TxSimulationResult[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Merges simulation results from the optimized (public static) and normal paths.
|
|
43
|
+
* Since optimized calls are always a leading prefix, return values are simply
|
|
44
|
+
* concatenated: optimized first, then normal.
|
|
45
|
+
* Stats are taken from the normal result only (the optimized path doesn't produce them).
|
|
46
|
+
*
|
|
47
|
+
* @param optimizedResults - Results from optimized public static call batches.
|
|
48
|
+
* @param normalResult - Result from normal simulation (null if all calls were optimized).
|
|
49
|
+
* @returns A single TxSimulationResult with return values in original call order.
|
|
50
|
+
*/
|
|
51
|
+
export declare function buildMergedSimulationResult(optimizedResults: TxSimulationResult[], normalResult: TxSimulationResultWithAppOffset | null): TxSimulationResultWithAppOffset;
|
|
52
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC91dGlscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUN0RCxPQUFPLEVBQUUsK0JBQStCLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUV6RSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUkvRCxPQUFPLEtBQUssRUFBRSxvQkFBb0IsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBR25FLE9BQU8sRUFBRSxLQUFLLFlBQVksRUFBb0IsTUFBTSxtQkFBbUIsQ0FBQztBQUN4RSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQVFyRCxPQUFPLEVBQ0wsS0FBSyxXQUFXLEVBQ2hCLEtBQUssZ0JBQWdCLEVBS3JCLEtBQUssbUJBQW1CLEVBR3hCLGtCQUFrQixFQUNuQixNQUFNLGtCQUFrQixDQUFDO0FBRTFCOzs7Ozs7Ozs7R0FTRztBQUNILHdCQUFnQixtQ0FBbUMsQ0FBQyxPQUFPLEVBQUUsZ0JBQWdCLEdBQUc7SUFDOUUsdUVBQXVFO0lBQ3ZFLGdCQUFnQixFQUFFLFlBQVksRUFBRSxDQUFDO0lBQ2pDLDJCQUEyQjtJQUMzQixjQUFjLEVBQUUsWUFBWSxFQUFFLENBQUM7Q0FDaEMsQ0FPQTtBQTBHRDs7Ozs7Ozs7Ozs7Ozs7R0FjRztBQUNILHdCQUFzQixlQUFlLENBQ25DLElBQUksRUFBRSxTQUFTLEVBQ2YsaUJBQWlCLEVBQUUsWUFBWSxFQUFFLEVBQ2pDLElBQUksRUFBRSxZQUFZLEVBQ2xCLFNBQVMsRUFBRSxTQUFTLEVBQ3BCLFdBQVcsRUFBRSxXQUFXLEVBQ3hCLFdBQVcsRUFBRSxXQUFXLEVBQ3hCLGtCQUFrQixxQkFBZ0IsRUFDbEMsZUFBZSxFQUFFLG9CQUFvQixFQUNyQyxTQUFTLENBQUMsRUFBRSxtQkFBbUIsR0FDOUIsT0FBTyxDQUFDLGtCQUFrQixFQUFFLENBQUMsQ0F5Qi9CO0FBRUQ7Ozs7Ozs7OztHQVNHO0FBQ0gsd0JBQWdCLDJCQUEyQixDQUN6QyxnQkFBZ0IsRUFBRSxrQkFBa0IsRUFBRSxFQUN0QyxZQUFZLEVBQUUsK0JBQStCLEdBQUcsSUFBSSxHQUNuRCwrQkFBK0IsQ0FxQmpDIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/base-wallet/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AAEzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAI/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAGnE,OAAO,EAAE,KAAK,YAAY,EAAoB,MAAM,mBAAmB,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQrD,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,gBAAgB,EAKrB,KAAK,mBAAmB,EAGxB,kBAAkB,EACnB,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;GASG;AACH,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,gBAAgB,GAAG;IAC9E,uEAAuE;IACvE,gBAAgB,EAAE,YAAY,EAAE,CAAC;IACjC,2BAA2B;IAC3B,cAAc,EAAE,YAAY,EAAE,CAAC;CAChC,CAOA;AA0GD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,SAAS,EACf,iBAAiB,EAAE,YAAY,EAAE,EACjC,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,kBAAkB,qBAAgB,EAClC,eAAe,EAAE,oBAAoB,EACrC,SAAS,CAAC,EAAE,mBAAmB,GAC9B,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAyB/B;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CACzC,gBAAgB,EAAE,kBAAkB,EAAE,EACtC,YAAY,EAAE,+BAA+B,GAAG,IAAI,GACnD,+BAA+B,CAqBjC"}
|