@aztec/wallet-sdk 0.0.1-commit.d431d1c → 0.0.1-commit.db765a8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +217 -294
- package/dest/base-wallet/base_wallet.d.ts +47 -9
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +120 -18
- package/dest/base-wallet/index.d.ts +2 -1
- 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 +49 -0
- package/dest/base-wallet/utils.d.ts.map +1 -0
- package/dest/base-wallet/utils.js +131 -0
- package/dest/crypto.d.ts +59 -50
- package/dest/crypto.d.ts.map +1 -1
- package/dest/crypto.js +202 -108
- package/dest/emoji_alphabet.d.ts +35 -0
- package/dest/emoji_alphabet.d.ts.map +1 -0
- package/dest/emoji_alphabet.js +299 -0
- package/dest/extension/handlers/background_connection_handler.d.ts +158 -0
- package/dest/extension/handlers/background_connection_handler.d.ts.map +1 -0
- package/dest/extension/handlers/background_connection_handler.js +258 -0
- package/dest/extension/handlers/content_script_connection_handler.d.ts +56 -0
- package/dest/extension/handlers/content_script_connection_handler.d.ts.map +1 -0
- package/dest/extension/handlers/content_script_connection_handler.js +174 -0
- package/dest/extension/handlers/index.d.ts +12 -0
- package/dest/extension/handlers/index.d.ts.map +1 -0
- package/dest/extension/handlers/index.js +10 -0
- package/dest/extension/handlers/internal_message_types.d.ts +63 -0
- package/dest/extension/handlers/internal_message_types.d.ts.map +1 -0
- package/dest/extension/handlers/internal_message_types.js +22 -0
- package/dest/extension/provider/extension_provider.d.ts +107 -0
- package/dest/extension/provider/extension_provider.d.ts.map +1 -0
- package/dest/extension/provider/extension_provider.js +160 -0
- package/dest/extension/provider/extension_wallet.d.ts +132 -0
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -0
- package/dest/{providers/extension → extension/provider}/extension_wallet.js +57 -97
- package/dest/extension/provider/index.d.ts +3 -0
- package/dest/extension/provider/index.d.ts.map +1 -0
- package/dest/{providers/extension → extension/provider}/index.js +0 -2
- package/dest/manager/index.d.ts +2 -8
- package/dest/manager/index.d.ts.map +1 -1
- package/dest/manager/index.js +0 -6
- package/dest/manager/types.d.ts +91 -9
- package/dest/manager/types.d.ts.map +1 -1
- package/dest/manager/types.js +17 -1
- package/dest/manager/wallet_manager.d.ts +50 -7
- package/dest/manager/wallet_manager.d.ts.map +1 -1
- package/dest/manager/wallet_manager.js +174 -44
- package/dest/types.d.ts +43 -12
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +3 -2
- package/package.json +17 -10
- package/src/base-wallet/base_wallet.ts +154 -35
- package/src/base-wallet/index.ts +1 -0
- package/src/base-wallet/utils.ts +238 -0
- package/src/crypto.ts +237 -113
- package/src/emoji_alphabet.ts +317 -0
- package/src/extension/handlers/background_connection_handler.ts +423 -0
- package/src/extension/handlers/content_script_connection_handler.ts +246 -0
- package/src/extension/handlers/index.ts +25 -0
- package/src/extension/handlers/internal_message_types.ts +69 -0
- package/src/extension/provider/extension_provider.ts +233 -0
- package/src/{providers/extension → extension/provider}/extension_wallet.ts +61 -111
- package/src/extension/provider/index.ts +7 -0
- package/src/manager/index.ts +2 -10
- package/src/manager/types.ts +94 -8
- package/src/manager/wallet_manager.ts +190 -46
- package/src/types.ts +44 -10
- package/dest/providers/extension/extension_provider.d.ts +0 -63
- package/dest/providers/extension/extension_provider.d.ts.map +0 -1
- package/dest/providers/extension/extension_provider.js +0 -124
- package/dest/providers/extension/extension_wallet.d.ts +0 -155
- package/dest/providers/extension/extension_wallet.d.ts.map +0 -1
- package/dest/providers/extension/index.d.ts +0 -6
- package/dest/providers/extension/index.d.ts.map +0 -1
- package/src/providers/extension/extension_provider.ts +0 -167
- package/src/providers/extension/index.ts +0 -5
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import type { Account } from '@aztec/aztec.js/account';
|
|
2
2
|
import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import { type InteractionWaitOptions, type SendReturn } from '@aztec/aztec.js/contracts';
|
|
3
4
|
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
4
|
-
import type { Aliased, BatchResults, BatchedMethod, PrivateEvent, PrivateEventFilter, ProfileOptions, SendOptions, SimulateOptions, Wallet } from '@aztec/aztec.js/wallet';
|
|
5
|
+
import type { Aliased, AppCapabilities, BatchResults, BatchedMethod, ExecuteUtilityOptions, PrivateEvent, PrivateEventFilter, ProfileOptions, SendOptions, SimulateOptions, Wallet, WalletCapabilities } from '@aztec/aztec.js/wallet';
|
|
5
6
|
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
6
7
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
7
8
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
8
9
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
10
|
+
import { type AccessScopes } from '@aztec/pxe/client/lazy';
|
|
9
11
|
import type { PXE } from '@aztec/pxe/server';
|
|
10
12
|
import { type ContractArtifact, type EventMetadataDefinition, type FunctionCall } from '@aztec/stdlib/abi';
|
|
11
13
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
12
|
-
import
|
|
14
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
13
15
|
import { type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
14
16
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
15
17
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
16
|
-
import type
|
|
18
|
+
import { type TxExecutionRequest, type TxProfileResult, TxSimulationResult, type UtilityExecutionResult } from '@aztec/stdlib/tx';
|
|
17
19
|
import { ExecutionPayload } from '@aztec/stdlib/tx';
|
|
18
20
|
/**
|
|
19
21
|
* Options to configure fee payment for a transaction
|
|
@@ -38,7 +40,8 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
38
40
|
protected log: import("@aztec/foundation/log").Logger;
|
|
39
41
|
protected minFeePadding: number;
|
|
40
42
|
protected cancellableTransactions: boolean;
|
|
41
|
-
protected constructor(pxe: PXE, aztecNode: AztecNode);
|
|
43
|
+
protected constructor(pxe: PXE, aztecNode: AztecNode, log?: import("@aztec/foundation/log").Logger);
|
|
44
|
+
protected scopesFrom(from: AztecAddress, additionalScopes?: AztecAddress[]): AztecAddress[];
|
|
42
45
|
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
43
46
|
abstract getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
44
47
|
/**
|
|
@@ -52,6 +55,20 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
52
55
|
getChainInfo(): Promise<ChainInfo>;
|
|
53
56
|
protected createTxExecutionRequestFromPayloadAndFee(executionPayload: ExecutionPayload, from: AztecAddress, feeOptions: FeeOptions): Promise<TxExecutionRequest>;
|
|
54
57
|
createAuthWit(from: AztecAddress, messageHashOrIntent: IntentInnerHash | CallIntent): Promise<AuthWitness>;
|
|
58
|
+
/**
|
|
59
|
+
* Request capabilities from the wallet.
|
|
60
|
+
*
|
|
61
|
+
* This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
|
|
62
|
+
* Embedded wallets typically don't support capability-based authorization (no user authorization flow),
|
|
63
|
+
* while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
|
|
64
|
+
* friction by allowing apps to request permissions upfront.
|
|
65
|
+
*
|
|
66
|
+
* TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
|
|
67
|
+
* while the feature stabilizes.
|
|
68
|
+
*
|
|
69
|
+
* @param _manifest - Application capability manifest declaring what operations the app needs
|
|
70
|
+
*/
|
|
71
|
+
requestCapabilities(_manifest: AppCapabilities): Promise<WalletCapabilities>;
|
|
55
72
|
batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>>;
|
|
56
73
|
/**
|
|
57
74
|
* Completes partial user-provided fee options with wallet defaults.
|
|
@@ -81,18 +98,39 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
81
98
|
}>;
|
|
82
99
|
registerSender(address: AztecAddress, _alias?: string): Promise<AztecAddress>;
|
|
83
100
|
registerContract(instance: ContractInstanceWithAddress, artifact?: ContractArtifact, secretKey?: Fr): Promise<ContractInstanceWithAddress>;
|
|
101
|
+
/**
|
|
102
|
+
* Simulates calls through the standard PXE path (account entrypoint).
|
|
103
|
+
* @param executionPayload - The execution payload to simulate.
|
|
104
|
+
* @param from - The sender address.
|
|
105
|
+
* @param feeOptions - Fee options for the transaction.
|
|
106
|
+
* @param skipTxValidation - Whether to skip tx validation.
|
|
107
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement.
|
|
108
|
+
* @param scopes - The scopes to use for the simulation.
|
|
109
|
+
*/
|
|
110
|
+
protected simulateViaEntrypoint(executionPayload: ExecutionPayload, from: AztecAddress, feeOptions: FeeOptions, scopes: AccessScopes, skipTxValidation?: boolean, skipFeeEnforcement?: boolean): Promise<TxSimulationResult>;
|
|
111
|
+
/**
|
|
112
|
+
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
113
|
+
* on the node while sending the remaining calls through the standard PXE path.
|
|
114
|
+
* Return values from both paths are merged back in original call order.
|
|
115
|
+
* @param executionPayload - The execution payload to simulate.
|
|
116
|
+
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
117
|
+
* @returns The merged simulation result.
|
|
118
|
+
*/
|
|
84
119
|
simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult>;
|
|
85
120
|
profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult>;
|
|
86
|
-
sendTx(executionPayload: ExecutionPayload, opts: SendOptions): Promise<
|
|
121
|
+
sendTx<W extends InteractionWaitOptions = undefined>(executionPayload: ExecutionPayload, opts: SendOptions<W>): Promise<SendReturn<W>>;
|
|
122
|
+
/**
|
|
123
|
+
* Resolves a contract address to a human-readable name via PXE, if available.
|
|
124
|
+
* @param address - The contract address to resolve.
|
|
125
|
+
*/
|
|
126
|
+
protected getContractName(address: AztecAddress): Promise<string | undefined>;
|
|
87
127
|
protected contextualizeError(err: Error, ...context: string[]): Error;
|
|
88
|
-
|
|
89
|
-
getTxReceipt(txHash: TxHash): Promise<TxReceipt>;
|
|
128
|
+
executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult>;
|
|
90
129
|
getPrivateEvents<T>(eventDef: EventMetadataDefinition, eventFilter: PrivateEventFilter): Promise<PrivateEvent<T>[]>;
|
|
91
130
|
getContractMetadata(address: AztecAddress): Promise<{
|
|
92
131
|
instance: ContractInstanceWithAddress | undefined;
|
|
93
132
|
isContractInitialized: boolean;
|
|
94
133
|
isContractPublished: boolean;
|
|
95
|
-
isContractClassPubliclyRegistered: boolean;
|
|
96
134
|
isContractUpdated: boolean;
|
|
97
135
|
updatedContractClassId: Fr | undefined;
|
|
98
136
|
}>;
|
|
@@ -101,4 +139,4 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
101
139
|
isContractClassPubliclyRegistered: boolean;
|
|
102
140
|
}>;
|
|
103
141
|
}
|
|
104
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
142
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFzZV93YWxsZXQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9iYXNlX3dhbGxldC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxPQUFPLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUN2RCxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsZUFBZSxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDakYsT0FBTyxFQUNMLEtBQUssc0JBQXNCLEVBRTNCLEtBQUssVUFBVSxFQUVoQixNQUFNLDJC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MIT, GAS_ESTIMATION_L2_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT } from '@aztec/constants';
|
|
2
4
|
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
3
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
6
|
import { createLogger } from '@aztec/foundation/log';
|
|
7
|
+
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
5
8
|
import { decodeFromAbi } from '@aztec/stdlib/abi';
|
|
9
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
10
|
import { computePartialAddress, getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
7
11
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
8
12
|
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
9
13
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
10
14
|
import { mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
11
15
|
import { inspect } from 'util';
|
|
16
|
+
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
12
17
|
/**
|
|
13
18
|
* A base class for Wallet implementations
|
|
14
19
|
*/ export class BaseWallet {
|
|
@@ -18,13 +23,23 @@ import { inspect } from 'util';
|
|
|
18
23
|
minFeePadding;
|
|
19
24
|
cancellableTransactions;
|
|
20
25
|
// Protected because we want to force wallets to instantiate their own PXE.
|
|
21
|
-
constructor(pxe, aztecNode){
|
|
26
|
+
constructor(pxe, aztecNode, log = createLogger('wallet-sdk:base_wallet')){
|
|
22
27
|
this.pxe = pxe;
|
|
23
28
|
this.aztecNode = aztecNode;
|
|
24
|
-
this.log =
|
|
29
|
+
this.log = log;
|
|
25
30
|
this.minFeePadding = 0.5;
|
|
26
31
|
this.cancellableTransactions = false;
|
|
27
32
|
}
|
|
33
|
+
scopesFrom(from, additionalScopes = []) {
|
|
34
|
+
const allScopes = from.isZero() ? additionalScopes : [
|
|
35
|
+
from,
|
|
36
|
+
...additionalScopes
|
|
37
|
+
];
|
|
38
|
+
const scopeSet = new Set(allScopes.map((address)=>address.toString()));
|
|
39
|
+
return [
|
|
40
|
+
...scopeSet
|
|
41
|
+
].map(AztecAddress.fromString);
|
|
42
|
+
}
|
|
28
43
|
/**
|
|
29
44
|
* Returns the list of aliased contacts associated with the wallet.
|
|
30
45
|
* This base implementation directly returns PXE's senders, but note that in general contacts are a superset of senders.
|
|
@@ -65,6 +80,21 @@ import { inspect } from 'util';
|
|
|
65
80
|
const chainInfo = await this.getChainInfo();
|
|
66
81
|
return account.createAuthWit(messageHashOrIntent, chainInfo);
|
|
67
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Request capabilities from the wallet.
|
|
85
|
+
*
|
|
86
|
+
* This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
|
|
87
|
+
* Embedded wallets typically don't support capability-based authorization (no user authorization flow),
|
|
88
|
+
* while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
|
|
89
|
+
* friction by allowing apps to request permissions upfront.
|
|
90
|
+
*
|
|
91
|
+
* TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
|
|
92
|
+
* while the feature stabilizes.
|
|
93
|
+
*
|
|
94
|
+
* @param _manifest - Application capability manifest declaring what operations the app needs
|
|
95
|
+
*/ requestCapabilities(_manifest) {
|
|
96
|
+
throw new Error('Not implemented');
|
|
97
|
+
}
|
|
68
98
|
async batch(methods) {
|
|
69
99
|
const results = [];
|
|
70
100
|
for (const method of methods){
|
|
@@ -166,20 +196,66 @@ import { inspect } from 'util';
|
|
|
166
196
|
}
|
|
167
197
|
return instance;
|
|
168
198
|
}
|
|
169
|
-
|
|
199
|
+
/**
|
|
200
|
+
* Simulates calls through the standard PXE path (account entrypoint).
|
|
201
|
+
* @param executionPayload - The execution payload to simulate.
|
|
202
|
+
* @param from - The sender address.
|
|
203
|
+
* @param feeOptions - Fee options for the transaction.
|
|
204
|
+
* @param skipTxValidation - Whether to skip tx validation.
|
|
205
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement.
|
|
206
|
+
* @param scopes - The scopes to use for the simulation.
|
|
207
|
+
*/ async simulateViaEntrypoint(executionPayload, from, feeOptions, scopes, skipTxValidation, skipFeeEnforcement) {
|
|
208
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions);
|
|
209
|
+
return this.pxe.simulateTx(txRequest, {
|
|
210
|
+
simulatePublic: true,
|
|
211
|
+
skipTxValidation,
|
|
212
|
+
skipFeeEnforcement,
|
|
213
|
+
scopes
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
218
|
+
* on the node while sending the remaining calls through the standard PXE path.
|
|
219
|
+
* Return values from both paths are merged back in original call order.
|
|
220
|
+
* @param executionPayload - The execution payload to simulate.
|
|
221
|
+
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
222
|
+
* @returns The merged simulation result.
|
|
223
|
+
*/ async simulateTx(executionPayload, opts) {
|
|
170
224
|
const feeOptions = opts.fee?.estimateGas ? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings) : await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
171
|
-
const
|
|
172
|
-
|
|
225
|
+
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
226
|
+
const remainingPayload = {
|
|
227
|
+
...executionPayload,
|
|
228
|
+
calls: remainingCalls
|
|
229
|
+
};
|
|
230
|
+
const chainInfo = await this.getChainInfo();
|
|
231
|
+
let blockHeader;
|
|
232
|
+
// PXE might not be synced yet, so we pull the latest header from the node
|
|
233
|
+
// To keep things consistent, we'll always try with PXE first
|
|
234
|
+
try {
|
|
235
|
+
blockHeader = await this.pxe.getSyncedBlockHeader();
|
|
236
|
+
} catch {
|
|
237
|
+
blockHeader = await this.aztecNode.getBlockHeader();
|
|
238
|
+
}
|
|
239
|
+
const [optimizedResults, normalResult] = await Promise.all([
|
|
240
|
+
optimizableCalls.length > 0 ? simulateViaNode(this.aztecNode, optimizableCalls, opts.from, chainInfo, feeOptions.gasSettings, blockHeader, opts.skipFeeEnforcement ?? true, this.getContractName.bind(this)) : Promise.resolve([]),
|
|
241
|
+
remainingCalls.length > 0 ? this.simulateViaEntrypoint(remainingPayload, opts.from, feeOptions, this.scopesFrom(opts.from, opts.additionalScopes), opts.skipTxValidation, opts.skipFeeEnforcement ?? true) : Promise.resolve(null)
|
|
242
|
+
]);
|
|
243
|
+
return buildMergedSimulationResult(optimizedResults, normalResult);
|
|
173
244
|
}
|
|
174
245
|
async profileTx(executionPayload, opts) {
|
|
175
246
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
176
247
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
177
|
-
return this.pxe.profileTx(txRequest,
|
|
248
|
+
return this.pxe.profileTx(txRequest, {
|
|
249
|
+
profileMode: opts.profileMode,
|
|
250
|
+
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
251
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes)
|
|
252
|
+
});
|
|
178
253
|
}
|
|
179
254
|
async sendTx(executionPayload, opts) {
|
|
180
255
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
181
256
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
182
|
-
const provenTx = await this.pxe.proveTx(txRequest);
|
|
257
|
+
const provenTx = await this.pxe.proveTx(txRequest, this.scopesFrom(opts.from, opts.additionalScopes));
|
|
258
|
+
const offchainOutput = extractOffchainOutput(provenTx.getOffchainEffects());
|
|
183
259
|
const tx = await provenTx.toTx();
|
|
184
260
|
const txHash = tx.getTxHash();
|
|
185
261
|
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
@@ -190,7 +266,35 @@ import { inspect } from 'util';
|
|
|
190
266
|
throw this.contextualizeError(err, inspect(tx));
|
|
191
267
|
});
|
|
192
268
|
this.log.info(`Sent transaction ${txHash}`);
|
|
193
|
-
return txHash
|
|
269
|
+
// If wait is NO_WAIT, return txHash immediately
|
|
270
|
+
if (opts.wait === NO_WAIT) {
|
|
271
|
+
return {
|
|
272
|
+
txHash,
|
|
273
|
+
...offchainOutput
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
277
|
+
const waitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
278
|
+
const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
279
|
+
// Display debug logs from public execution if present (served in test mode only)
|
|
280
|
+
if (receipt.debugLogs?.length) {
|
|
281
|
+
await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
receipt,
|
|
285
|
+
...offchainOutput
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Resolves a contract address to a human-readable name via PXE, if available.
|
|
290
|
+
* @param address - The contract address to resolve.
|
|
291
|
+
*/ async getContractName(address) {
|
|
292
|
+
const instance = await this.pxe.getContractInstance(address);
|
|
293
|
+
if (!instance) {
|
|
294
|
+
return undefined;
|
|
295
|
+
}
|
|
296
|
+
const artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
297
|
+
return artifact?.name;
|
|
194
298
|
}
|
|
195
299
|
contextualizeError(err, ...context) {
|
|
196
300
|
let contextStr = '';
|
|
@@ -205,11 +309,13 @@ import { inspect } from 'util';
|
|
|
205
309
|
}
|
|
206
310
|
return err;
|
|
207
311
|
}
|
|
208
|
-
|
|
209
|
-
return this.pxe.
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
312
|
+
executeUtility(call, opts) {
|
|
313
|
+
return this.pxe.executeUtility(call, {
|
|
314
|
+
authwits: opts.authWitnesses,
|
|
315
|
+
scopes: [
|
|
316
|
+
opts.scope
|
|
317
|
+
]
|
|
318
|
+
});
|
|
213
319
|
}
|
|
214
320
|
async getPrivateEvents(eventDef, eventFilter) {
|
|
215
321
|
const pxeEvents = await this.pxe.getPrivateEvents(eventDef.eventSelector, eventFilter);
|
|
@@ -231,16 +337,12 @@ import { inspect } from 'util';
|
|
|
231
337
|
const instance = await this.pxe.getContractInstance(address);
|
|
232
338
|
const initNullifier = await siloNullifier(address, address.toField());
|
|
233
339
|
const publiclyRegisteredContract = await this.aztecNode.getContract(address);
|
|
234
|
-
const
|
|
235
|
-
this.aztecNode.getNullifierMembershipWitness('latest', initNullifier),
|
|
236
|
-
publiclyRegisteredContract ? this.aztecNode.getContractClass(publiclyRegisteredContract.currentContractClassId || instance?.currentContractClassId) : undefined
|
|
237
|
-
]);
|
|
340
|
+
const initNullifierMembershipWitness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
238
341
|
const isContractUpdated = publiclyRegisteredContract && !publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
239
342
|
return {
|
|
240
343
|
instance: instance ?? undefined,
|
|
241
344
|
isContractInitialized: !!initNullifierMembershipWitness,
|
|
242
345
|
isContractPublished: !!publiclyRegisteredContract,
|
|
243
|
-
isContractClassPubliclyRegistered: !!publiclyRegisteredContractClass,
|
|
244
346
|
isContractUpdated: !!isContractUpdated,
|
|
245
347
|
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined
|
|
246
348
|
};
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { BaseWallet, type FeeOptions } from './base_wallet.js';
|
|
2
|
-
|
|
2
|
+
export { simulateViaNode, buildMergedSimulationResult, extractOptimizablePublicStaticCalls } from './utils.js';
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLEtBQUssVUFBVSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFDL0QsT0FBTyxFQUFFLGVBQWUsRUFBRSwyQkFBMkIsRUFBRSxtQ0FBbUMsRUFBRSxNQUFNLFlBQVksQ0FBQyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base-wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base-wallet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,mCAAmC,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
2
|
+
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
3
|
+
import type { ContractNameResolver } from '@aztec/pxe/client/lazy';
|
|
4
|
+
import { type FunctionCall } from '@aztec/stdlib/abi';
|
|
5
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
+
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
7
|
+
import { type BlockHeader, type ExecutionPayload, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
8
|
+
/**
|
|
9
|
+
* Splits an execution payload into a leading prefix of public static calls
|
|
10
|
+
* (eligible for direct node simulation) and the remaining calls.
|
|
11
|
+
*
|
|
12
|
+
* Only a leading run of public static calls is eligible for optimization.
|
|
13
|
+
* Any non-public-static call may enqueue public state mutations
|
|
14
|
+
* (e.g. private calls can enqueue public calls), so all calls that follow
|
|
15
|
+
* must go through the normal simulation path to see the correct state.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractOptimizablePublicStaticCalls(payload: ExecutionPayload): {
|
|
19
|
+
/** Leading public static calls eligible for direct node simulation. */
|
|
20
|
+
optimizableCalls: FunctionCall[];
|
|
21
|
+
/** All remaining calls. */
|
|
22
|
+
remainingCalls: FunctionCall[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Simulates public static calls by splitting them into batches of MAX_ENQUEUED_CALLS_PER_CALL
|
|
26
|
+
* and sending each batch directly to the node.
|
|
27
|
+
*
|
|
28
|
+
* @param node - The Aztec node to simulate on.
|
|
29
|
+
* @param publicStaticCalls - Array of public static function calls to optimize.
|
|
30
|
+
* @param from - The account address making the calls.
|
|
31
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
32
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
33
|
+
* @param blockHeader - Block header to use as anchor.
|
|
34
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
35
|
+
* @returns Array of TxSimulationResult, one per batch.
|
|
36
|
+
*/
|
|
37
|
+
export declare function simulateViaNode(node: AztecNode, publicStaticCalls: FunctionCall[], from: AztecAddress, chainInfo: ChainInfo, gasSettings: GasSettings, blockHeader: BlockHeader, skipFeeEnforcement: boolean | undefined, getContractName: ContractNameResolver): Promise<TxSimulationResult[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Merges simulation results from the optimized (public static) and normal paths.
|
|
40
|
+
* Since optimized calls are always a leading prefix, return values are simply
|
|
41
|
+
* concatenated: optimized first, then normal.
|
|
42
|
+
* Stats are taken from the normal result only (the optimized path doesn't produce them).
|
|
43
|
+
*
|
|
44
|
+
* @param optimizedResults - Results from optimized public static call batches.
|
|
45
|
+
* @param normalResult - Result from normal simulation (null if all calls were optimized).
|
|
46
|
+
* @returns A single TxSimulationResult with return values in original call order.
|
|
47
|
+
*/
|
|
48
|
+
export declare function buildMergedSimulationResult(optimizedResults: TxSimulationResult[], normalResult: TxSimulationResult | null): TxSimulationResult;
|
|
49
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC91dGlscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUV0RCxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUkvRCxPQUFPLEtBQUssRUFBRSxvQkFBb0IsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBR25FLE9BQU8sRUFBRSxLQUFLLFlBQVksRUFBb0IsTUFBTSxtQkFBbUIsQ0FBQztBQUN4RSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQVFyRCxPQUFPLEVBQ0wsS0FBSyxXQUFXLEVBQ2hCLEtBQUssZ0JBQWdCLEVBT3JCLGtCQUFrQixFQUNuQixNQUFNLGtCQUFrQixDQUFDO0FBRTFCOzs7Ozs7Ozs7R0FTRztBQUNILHdCQUFnQixtQ0FBbUMsQ0FBQyxPQUFPLEVBQUUsZ0JBQWdCLEdBQUc7SUFDOUUsdUVBQXVFO0lBQ3ZFLGdCQUFnQixFQUFFLFlBQVksRUFBRSxDQUFDO0lBQ2pDLDJCQUEyQjtJQUMzQixjQUFjLEVBQUUsWUFBWSx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AC,OAAO,EAAE,gBAAgB,GAAG;IAC9E,uEAAuE;IACvE,gBAAgB,EAAE,YAAY,EAAE,CAAC;IACjC,2BAA2B;IAC3B,cAAc,EAAE,YAAY,EAAE,CAAC;CAChC,CAOA;AAuGD;;;;;;;;;;;;GAYG;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,GACpC,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAwB/B;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CACzC,gBAAgB,EAAE,kBAAkB,EAAE,EACtC,YAAY,EAAE,kBAAkB,GAAG,IAAI,GACtC,kBAAkB,CAoBpB"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { MAX_ENQUEUED_CALLS_PER_CALL } from '@aztec/constants';
|
|
2
|
+
import { makeTuple } from '@aztec/foundation/array';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
+
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
5
|
+
import { generateSimulatedProvingResult } from '@aztec/pxe/simulator';
|
|
6
|
+
import { ClaimedLengthArray, CountedPublicCallRequest, PrivateCircuitPublicInputs, PublicCallRequest } from '@aztec/stdlib/kernel';
|
|
7
|
+
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
8
|
+
import { HashedValues, PrivateCallExecutionResult, PrivateExecutionResult, Tx, TxContext, 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
|
+
*/ export function extractOptimizablePublicStaticCalls(payload) {
|
|
19
|
+
const splitIndex = payload.calls.findIndex((call)=>!call.isPublicStatic());
|
|
20
|
+
const boundary = splitIndex === -1 ? payload.calls.length : splitIndex;
|
|
21
|
+
return {
|
|
22
|
+
optimizableCalls: payload.calls.slice(0, boundary),
|
|
23
|
+
remainingCalls: payload.calls.slice(boundary)
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Simulates a batch of public static calls by bypassing account entrypoint and private execution,
|
|
28
|
+
* directly constructing a minimal Tx and calling node.simulatePublicCalls.
|
|
29
|
+
*
|
|
30
|
+
* @param node - The Aztec node to simulate on.
|
|
31
|
+
* @param publicStaticCalls - Array of public static function calls (max MAX_ENQUEUED_CALLS_PER_CALL).
|
|
32
|
+
* @param from - The account address making the calls.
|
|
33
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
34
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
35
|
+
* @param blockHeader - Block header to use as anchor.
|
|
36
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
37
|
+
* @returns TxSimulationResult with public return values.
|
|
38
|
+
*/ async function simulateBatchViaNode(node, publicStaticCalls, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement, getContractName) {
|
|
39
|
+
const txContext = new TxContext(chainInfo.chainId, chainInfo.version, gasSettings);
|
|
40
|
+
const publicFunctionCalldata = [];
|
|
41
|
+
for (const call of publicStaticCalls){
|
|
42
|
+
const calldata = await HashedValues.fromCalldata([
|
|
43
|
+
call.selector.toField(),
|
|
44
|
+
...call.args
|
|
45
|
+
]);
|
|
46
|
+
publicFunctionCalldata.push(calldata);
|
|
47
|
+
}
|
|
48
|
+
const publicCallRequests = makeTuple(MAX_ENQUEUED_CALLS_PER_CALL, (i)=>{
|
|
49
|
+
const call = publicStaticCalls[i];
|
|
50
|
+
if (!call) {
|
|
51
|
+
return CountedPublicCallRequest.empty();
|
|
52
|
+
}
|
|
53
|
+
const publicCallRequest = new PublicCallRequest(from, call.to, call.isStatic, publicFunctionCalldata[i].hash);
|
|
54
|
+
// Counter starts at 1 (minRevertibleSideEffectCounter) so all calls are revertible
|
|
55
|
+
return new CountedPublicCallRequest(publicCallRequest, i + 1);
|
|
56
|
+
});
|
|
57
|
+
const publicCallRequestsArray = new ClaimedLengthArray(publicCallRequests, publicStaticCalls.length);
|
|
58
|
+
const publicInputs = PrivateCircuitPublicInputs.from({
|
|
59
|
+
...PrivateCircuitPublicInputs.empty(),
|
|
60
|
+
anchorBlockHeader: blockHeader,
|
|
61
|
+
txContext: txContext,
|
|
62
|
+
publicCallRequests: publicCallRequestsArray,
|
|
63
|
+
startSideEffectCounter: new Fr(0),
|
|
64
|
+
endSideEffectCounter: new Fr(publicStaticCalls.length + 1)
|
|
65
|
+
});
|
|
66
|
+
// Minimal entrypoint structure — no real private execution, just public call requests
|
|
67
|
+
const emptyEntrypoint = new PrivateCallExecutionResult(Buffer.alloc(0), Buffer.alloc(0), new Map(), publicInputs, [], new Map(), [], [], [], [], []);
|
|
68
|
+
const privateResult = new PrivateExecutionResult(emptyEntrypoint, Fr.random(), publicFunctionCalldata);
|
|
69
|
+
const provingResult = await generateSimulatedProvingResult(privateResult, (_contractAddress, _functionSelector)=>Promise.resolve(''), node, 1);
|
|
70
|
+
provingResult.publicInputs.feePayer = from;
|
|
71
|
+
const tx = await Tx.create({
|
|
72
|
+
data: provingResult.publicInputs,
|
|
73
|
+
chonkProof: ChonkProof.empty(),
|
|
74
|
+
contractClassLogFields: [],
|
|
75
|
+
publicFunctionCalldata: publicFunctionCalldata
|
|
76
|
+
});
|
|
77
|
+
const publicOutput = await node.simulatePublicCalls(tx, skipFeeEnforcement);
|
|
78
|
+
if (publicOutput.revertReason) {
|
|
79
|
+
throw publicOutput.revertReason;
|
|
80
|
+
}
|
|
81
|
+
// Display debug logs from the public simulation.
|
|
82
|
+
await displayDebugLogs(publicOutput.debugLogs, getContractName);
|
|
83
|
+
return new TxSimulationResult(privateResult, provingResult.publicInputs, publicOutput, undefined);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Simulates public static calls by splitting them into batches of MAX_ENQUEUED_CALLS_PER_CALL
|
|
87
|
+
* and sending each batch directly to the node.
|
|
88
|
+
*
|
|
89
|
+
* @param node - The Aztec node to simulate on.
|
|
90
|
+
* @param publicStaticCalls - Array of public static function calls to optimize.
|
|
91
|
+
* @param from - The account address making the calls.
|
|
92
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
93
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
94
|
+
* @param blockHeader - Block header to use as anchor.
|
|
95
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
96
|
+
* @returns Array of TxSimulationResult, one per batch.
|
|
97
|
+
*/ export async function simulateViaNode(node, publicStaticCalls, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement = true, getContractName) {
|
|
98
|
+
const batches = [];
|
|
99
|
+
for(let i = 0; i < publicStaticCalls.length; i += MAX_ENQUEUED_CALLS_PER_CALL){
|
|
100
|
+
batches.push(publicStaticCalls.slice(i, i + MAX_ENQUEUED_CALLS_PER_CALL));
|
|
101
|
+
}
|
|
102
|
+
const results = [];
|
|
103
|
+
for (const batch of batches){
|
|
104
|
+
const result = await simulateBatchViaNode(node, batch, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement, getContractName);
|
|
105
|
+
results.push(result);
|
|
106
|
+
}
|
|
107
|
+
return results;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Merges simulation results from the optimized (public static) and normal paths.
|
|
111
|
+
* Since optimized calls are always a leading prefix, return values are simply
|
|
112
|
+
* concatenated: optimized first, then normal.
|
|
113
|
+
* Stats are taken from the normal result only (the optimized path doesn't produce them).
|
|
114
|
+
*
|
|
115
|
+
* @param optimizedResults - Results from optimized public static call batches.
|
|
116
|
+
* @param normalResult - Result from normal simulation (null if all calls were optimized).
|
|
117
|
+
* @returns A single TxSimulationResult with return values in original call order.
|
|
118
|
+
*/ export function buildMergedSimulationResult(optimizedResults, normalResult) {
|
|
119
|
+
const optimizedReturnValues = optimizedResults.flatMap((r)=>r.publicOutput?.publicReturnValues ?? []);
|
|
120
|
+
const normalReturnValues = normalResult?.publicOutput?.publicReturnValues ?? [];
|
|
121
|
+
const allReturnValues = [
|
|
122
|
+
...optimizedReturnValues,
|
|
123
|
+
...normalReturnValues
|
|
124
|
+
];
|
|
125
|
+
const baseResult = normalResult ?? optimizedResults[0];
|
|
126
|
+
const mergedPublicOutput = baseResult.publicOutput ? {
|
|
127
|
+
...baseResult.publicOutput,
|
|
128
|
+
publicReturnValues: allReturnValues
|
|
129
|
+
} : undefined;
|
|
130
|
+
return new TxSimulationResult(baseResult.privateExecutionResult, baseResult.publicInputs, mergedPublicOutput, normalResult?.stats);
|
|
131
|
+
}
|