@aztec/wallet-sdk 3.0.3-rc.3 → 4.0.0-devnet.1-patch.0
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 +229 -332
- package/dest/base-wallet/base_wallet.d.ts +51 -11
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +88 -22
- 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 +48 -0
- package/dest/base-wallet/utils.d.ts.map +1 -0
- package/dest/base-wallet/utils.js +128 -0
- package/dest/crypto.d.ts +192 -0
- package/dest/crypto.d.ts.map +1 -0
- package/dest/crypto.js +394 -0
- 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 +131 -0
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -0
- package/dest/extension/provider/extension_wallet.js +271 -0
- package/dest/extension/provider/index.d.ts +3 -0
- package/dest/extension/provider/index.d.ts.map +1 -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 +108 -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 +178 -29
- package/dest/types.d.ts +123 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +11 -0
- package/package.json +20 -11
- package/src/base-wallet/base_wallet.ts +139 -41
- package/src/base-wallet/index.ts +1 -0
- package/src/base-wallet/utils.ts +229 -0
- package/src/crypto.ts +499 -0
- 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/extension/provider/extension_wallet.ts +321 -0
- package/src/extension/provider/index.ts +7 -0
- package/src/manager/index.ts +3 -15
- package/src/manager/types.ts +112 -4
- package/src/manager/wallet_manager.ts +204 -31
- package/src/types.ts +132 -0
- 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 -23
- package/dest/providers/extension/extension_wallet.d.ts.map +0 -1
- package/dest/providers/extension/extension_wallet.js +0 -96
- package/dest/providers/extension/index.d.ts +0 -4
- package/dest/providers/extension/index.d.ts.map +0 -1
- package/dest/providers/types.d.ts +0 -67
- package/dest/providers/types.d.ts.map +0 -1
- package/dest/providers/types.js +0 -3
- package/src/providers/extension/extension_provider.ts +0 -72
- package/src/providers/extension/extension_wallet.ts +0 -124
- package/src/providers/extension/index.ts +0 -3
- package/src/providers/types.ts +0 -71
- /package/dest/{providers/extension → extension/provider}/index.js +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
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,
|
|
5
|
+
import type { Aliased, AppCapabilities, BatchResults, BatchedMethod, 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';
|
|
@@ -10,10 +11,10 @@ import type { PXE } from '@aztec/pxe/server';
|
|
|
10
11
|
import { type ContractArtifact, type EventMetadataDefinition, type FunctionCall } from '@aztec/stdlib/abi';
|
|
11
12
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
12
13
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
13
|
-
import { type
|
|
14
|
+
import { type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
14
15
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
15
16
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
16
|
-
import type
|
|
17
|
+
import { type TxExecutionRequest, type TxProfileResult, TxSimulationResult, type UtilitySimulationResult } from '@aztec/stdlib/tx';
|
|
17
18
|
import { ExecutionPayload } from '@aztec/stdlib/tx';
|
|
18
19
|
/**
|
|
19
20
|
* Options to configure fee payment for a transaction
|
|
@@ -36,7 +37,7 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
36
37
|
protected readonly pxe: PXE;
|
|
37
38
|
protected readonly aztecNode: AztecNode;
|
|
38
39
|
protected log: import("@aztec/foundation/log").Logger;
|
|
39
|
-
protected
|
|
40
|
+
protected minFeePadding: number;
|
|
40
41
|
protected cancellableTransactions: boolean;
|
|
41
42
|
protected constructor(pxe: PXE, aztecNode: AztecNode);
|
|
42
43
|
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
@@ -51,8 +52,22 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
51
52
|
getAddressBook(): Promise<Aliased<AztecAddress>[]>;
|
|
52
53
|
getChainInfo(): Promise<ChainInfo>;
|
|
53
54
|
protected createTxExecutionRequestFromPayloadAndFee(executionPayload: ExecutionPayload, from: AztecAddress, feeOptions: FeeOptions): Promise<TxExecutionRequest>;
|
|
54
|
-
createAuthWit(from: AztecAddress, messageHashOrIntent:
|
|
55
|
-
|
|
55
|
+
createAuthWit(from: AztecAddress, messageHashOrIntent: IntentInnerHash | CallIntent): Promise<AuthWitness>;
|
|
56
|
+
/**
|
|
57
|
+
* Request capabilities from the wallet.
|
|
58
|
+
*
|
|
59
|
+
* This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
|
|
60
|
+
* Embedded wallets typically don't support capability-based authorization (no user authorization flow),
|
|
61
|
+
* while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
|
|
62
|
+
* friction by allowing apps to request permissions upfront.
|
|
63
|
+
*
|
|
64
|
+
* TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
|
|
65
|
+
* while the feature stabilizes.
|
|
66
|
+
*
|
|
67
|
+
* @param _manifest - Application capability manifest declaring what operations the app needs
|
|
68
|
+
*/
|
|
69
|
+
requestCapabilities(_manifest: AppCapabilities): Promise<WalletCapabilities>;
|
|
70
|
+
batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>>;
|
|
56
71
|
/**
|
|
57
72
|
* Completes partial user-provided fee options with wallet defaults.
|
|
58
73
|
* @param from - The address where the transaction is being sent from
|
|
@@ -81,14 +96,39 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
81
96
|
}>;
|
|
82
97
|
registerSender(address: AztecAddress, _alias?: string): Promise<AztecAddress>;
|
|
83
98
|
registerContract(instance: ContractInstanceWithAddress, artifact?: ContractArtifact, secretKey?: Fr): Promise<ContractInstanceWithAddress>;
|
|
99
|
+
/**
|
|
100
|
+
* Simulates calls through the standard PXE path (account entrypoint).
|
|
101
|
+
* @param executionPayload - The execution payload to simulate.
|
|
102
|
+
* @param from - The sender address.
|
|
103
|
+
* @param feeOptions - Fee options for the transaction.
|
|
104
|
+
* @param skipTxValidation - Whether to skip tx validation.
|
|
105
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement.
|
|
106
|
+
*/
|
|
107
|
+
protected simulateViaEntrypoint(executionPayload: ExecutionPayload, from: AztecAddress, feeOptions: FeeOptions, skipTxValidation?: boolean, skipFeeEnforcement?: boolean): Promise<TxSimulationResult>;
|
|
108
|
+
/**
|
|
109
|
+
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
110
|
+
* on the node while sending the remaining calls through the standard PXE path.
|
|
111
|
+
* Return values from both paths are merged back in original call order.
|
|
112
|
+
* @param executionPayload - The execution payload to simulate.
|
|
113
|
+
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
114
|
+
* @returns The merged simulation result.
|
|
115
|
+
*/
|
|
84
116
|
simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult>;
|
|
85
117
|
profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult>;
|
|
86
|
-
sendTx(executionPayload: ExecutionPayload, opts: SendOptions): Promise<
|
|
118
|
+
sendTx<W extends InteractionWaitOptions = undefined>(executionPayload: ExecutionPayload, opts: SendOptions<W>): Promise<SendReturn<W>>;
|
|
87
119
|
protected contextualizeError(err: Error, ...context: string[]): Error;
|
|
88
120
|
simulateUtility(call: FunctionCall, authwits?: AuthWitness[]): Promise<UtilitySimulationResult>;
|
|
89
|
-
getContractClassMetadata(id: Fr, includeArtifact?: boolean): Promise<ContractClassMetadata>;
|
|
90
|
-
getContractMetadata(address: AztecAddress): Promise<ContractMetadata>;
|
|
91
|
-
getTxReceipt(txHash: TxHash): Promise<TxReceipt>;
|
|
92
121
|
getPrivateEvents<T>(eventDef: EventMetadataDefinition, eventFilter: PrivateEventFilter): Promise<PrivateEvent<T>[]>;
|
|
122
|
+
getContractMetadata(address: AztecAddress): Promise<{
|
|
123
|
+
instance: ContractInstanceWithAddress | undefined;
|
|
124
|
+
isContractInitialized: boolean;
|
|
125
|
+
isContractPublished: boolean;
|
|
126
|
+
isContractUpdated: boolean;
|
|
127
|
+
updatedContractClassId: Fr | undefined;
|
|
128
|
+
}>;
|
|
129
|
+
getContractClassMetadata(id: Fr): Promise<{
|
|
130
|
+
isArtifactRegistered: boolean;
|
|
131
|
+
isContractClassPubliclyRegistered: boolean;
|
|
132
|
+
}>;
|
|
93
133
|
}
|
|
94
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
134
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFzZV93YWxsZXQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9iYXNlX3dhbGxldC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxPQUFPLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUN2RCxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsZUFBZSxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDakYsT0FBTyxFQUFFLEtBQUssc0JBQXNCLEVBQVcsS0FBSyxVQUFVLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQUNsRyxPQUFPLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBRTVELE9BQU8sS0FBSyxFQUNWLE9BQU8s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UFlLENBQUMsSUFBSSxFQUFFLFlBQVksRUFBRSxRQUFRLENBQUMsRUFBRSxXQUFXLEVBQUUsR0FBRyxPQUFPLENBQUMsdUJBQXVCLENBQUMsQ0FFOUY7SUFFSyxnQkFBZ0IsQ0FBQyxDQUFDLEVBQ3RCLFFBQVEsRUFBRSx1QkFBdUIsRUFDakMsV0FBVyxFQUFFLGtCQUFrQixHQUM5QixPQUFPLENBQUMsWUFBWSxDQUFDLENBQUMsQ0FBQyxFQUFFLENBQUMsQ0FlNUI7SUFFSyxtQkFBbUIsQ0FBQyxPQUFPLEVBQUUsWUFBWTs7Ozs7O09BZTlDO0lBRUssd0JBQXdCLENBQUMsRUFBRSxFQUFFLEVBQUU7OztPQU1wQztDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base_wallet.d.ts","sourceRoot":"","sources":["../../src/base-wallet/base_wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"base_wallet.d.ts","sourceRoot":"","sources":["../../src/base-wallet/base_wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,EAAE,KAAK,sBAAsB,EAAW,KAAK,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAClG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,KAAK,EACV,OAAO,EACP,eAAe,EACf,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,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C,CAAC,EACtB,QAAQ,EAAE,uBAAuB,EACjC,WAAW,EAAE,kBAAkB,GAC9B,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAe5B;IAEK,mBAAmB,CAAC,OAAO,EAAE,YAAY;;;;;;OAe9C;IAEK,wBAAwB,CAAC,EAAE,EAAE,EAAE;;;OAMpC;CACF"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { NO_WAIT } from '@aztec/aztec.js/contracts';
|
|
2
|
+
import { waitForTx } from '@aztec/aztec.js/node';
|
|
1
3
|
import { GAS_ESTIMATION_DA_GAS_LIMIT, 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';
|
|
@@ -6,22 +8,24 @@ import { decodeFromAbi } from '@aztec/stdlib/abi';
|
|
|
6
8
|
import { computePartialAddress, getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
7
9
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
8
10
|
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
11
|
+
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
9
12
|
import { mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
10
13
|
import { inspect } from 'util';
|
|
14
|
+
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
11
15
|
/**
|
|
12
16
|
* A base class for Wallet implementations
|
|
13
17
|
*/ export class BaseWallet {
|
|
14
18
|
pxe;
|
|
15
19
|
aztecNode;
|
|
16
20
|
log;
|
|
17
|
-
|
|
21
|
+
minFeePadding;
|
|
18
22
|
cancellableTransactions;
|
|
19
23
|
// Protected because we want to force wallets to instantiate their own PXE.
|
|
20
24
|
constructor(pxe, aztecNode){
|
|
21
25
|
this.pxe = pxe;
|
|
22
26
|
this.aztecNode = aztecNode;
|
|
23
27
|
this.log = createLogger('wallet-sdk:base_wallet');
|
|
24
|
-
this.
|
|
28
|
+
this.minFeePadding = 0.5;
|
|
25
29
|
this.cancellableTransactions = false;
|
|
26
30
|
}
|
|
27
31
|
/**
|
|
@@ -56,11 +60,28 @@ import { inspect } from 'util';
|
|
|
56
60
|
executionPayload
|
|
57
61
|
]) : executionPayload;
|
|
58
62
|
const fromAccount = await this.getAccountFromAddress(from);
|
|
59
|
-
|
|
63
|
+
const chainInfo = await this.getChainInfo();
|
|
64
|
+
return fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
|
|
60
65
|
}
|
|
61
66
|
async createAuthWit(from, messageHashOrIntent) {
|
|
62
67
|
const account = await this.getAccountFromAddress(from);
|
|
63
|
-
|
|
68
|
+
const chainInfo = await this.getChainInfo();
|
|
69
|
+
return account.createAuthWit(messageHashOrIntent, chainInfo);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Request capabilities from the wallet.
|
|
73
|
+
*
|
|
74
|
+
* This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
|
|
75
|
+
* Embedded wallets typically don't support capability-based authorization (no user authorization flow),
|
|
76
|
+
* while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
|
|
77
|
+
* friction by allowing apps to request permissions upfront.
|
|
78
|
+
*
|
|
79
|
+
* TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
|
|
80
|
+
* while the feature stabilizes.
|
|
81
|
+
*
|
|
82
|
+
* @param _manifest - Application capability manifest declaring what operations the app needs
|
|
83
|
+
*/ requestCapabilities(_manifest) {
|
|
84
|
+
throw new Error('Not implemented');
|
|
64
85
|
}
|
|
65
86
|
async batch(methods) {
|
|
66
87
|
const results = [];
|
|
@@ -88,7 +109,7 @@ import { inspect } from 'util';
|
|
|
88
109
|
* @param gasSettings - User-provided partial gas settings
|
|
89
110
|
* @returns - Complete fee options that can be used to create a transaction execution request
|
|
90
111
|
*/ async completeFeeOptions(from, feePayer, gasSettings) {
|
|
91
|
-
const maxFeesPerGas = gasSettings?.maxFeesPerGas ?? (await this.aztecNode.
|
|
112
|
+
const maxFeesPerGas = gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentMinFees()).mul(1 + this.minFeePadding);
|
|
92
113
|
let accountFeePaymentMethodOptions;
|
|
93
114
|
// The transaction does not include a fee payment method, so we set the flag
|
|
94
115
|
// for the account to use its fee juice balance
|
|
@@ -132,7 +153,7 @@ import { inspect } from 'util';
|
|
|
132
153
|
return this.pxe.registerSender(address);
|
|
133
154
|
}
|
|
134
155
|
async registerContract(instance, artifact, secretKey) {
|
|
135
|
-
const
|
|
156
|
+
const existingInstance = await this.pxe.getContractInstance(instance.address);
|
|
136
157
|
if (existingInstance) {
|
|
137
158
|
// Instance already registered in the wallet
|
|
138
159
|
if (artifact) {
|
|
@@ -148,11 +169,10 @@ import { inspect } from 'util';
|
|
|
148
169
|
// Instance not registered yet
|
|
149
170
|
if (!artifact) {
|
|
150
171
|
// Try to get the artifact from the wallet's contract class storage
|
|
151
|
-
|
|
152
|
-
if (!
|
|
172
|
+
artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
173
|
+
if (!artifact) {
|
|
153
174
|
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
175
|
}
|
|
155
|
-
artifact = classMetadata.artifact;
|
|
156
176
|
}
|
|
157
177
|
await this.pxe.registerContract({
|
|
158
178
|
artifact,
|
|
@@ -164,10 +184,38 @@ import { inspect } from 'util';
|
|
|
164
184
|
}
|
|
165
185
|
return instance;
|
|
166
186
|
}
|
|
167
|
-
|
|
187
|
+
/**
|
|
188
|
+
* Simulates calls through the standard PXE path (account entrypoint).
|
|
189
|
+
* @param executionPayload - The execution payload to simulate.
|
|
190
|
+
* @param from - The sender address.
|
|
191
|
+
* @param feeOptions - Fee options for the transaction.
|
|
192
|
+
* @param skipTxValidation - Whether to skip tx validation.
|
|
193
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement.
|
|
194
|
+
*/ async simulateViaEntrypoint(executionPayload, from, feeOptions, skipTxValidation, skipFeeEnforcement) {
|
|
195
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions);
|
|
196
|
+
return this.pxe.simulateTx(txRequest, true, skipTxValidation, skipFeeEnforcement);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
200
|
+
* on the node while sending the remaining calls through the standard PXE path.
|
|
201
|
+
* Return values from both paths are merged back in original call order.
|
|
202
|
+
* @param executionPayload - The execution payload to simulate.
|
|
203
|
+
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
204
|
+
* @returns The merged simulation result.
|
|
205
|
+
*/ async simulateTx(executionPayload, opts) {
|
|
168
206
|
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);
|
|
169
|
-
const
|
|
170
|
-
|
|
207
|
+
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
208
|
+
const remainingPayload = {
|
|
209
|
+
...executionPayload,
|
|
210
|
+
calls: remainingCalls
|
|
211
|
+
};
|
|
212
|
+
const chainInfo = await this.getChainInfo();
|
|
213
|
+
const blockHeader = await this.pxe.getSyncedBlockHeader();
|
|
214
|
+
const [optimizedResults, normalResult] = await Promise.all([
|
|
215
|
+
optimizableCalls.length > 0 ? simulateViaNode(this.aztecNode, optimizableCalls, opts.from, chainInfo, feeOptions.gasSettings, blockHeader, opts.skipFeeEnforcement ?? true) : Promise.resolve([]),
|
|
216
|
+
remainingCalls.length > 0 ? this.simulateViaEntrypoint(remainingPayload, opts.from, feeOptions, opts.skipTxValidation, opts.skipFeeEnforcement ?? true) : Promise.resolve(null)
|
|
217
|
+
]);
|
|
218
|
+
return buildMergedSimulationResult(optimizedResults, normalResult);
|
|
171
219
|
}
|
|
172
220
|
async profileTx(executionPayload, opts) {
|
|
173
221
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
@@ -188,7 +236,13 @@ import { inspect } from 'util';
|
|
|
188
236
|
throw this.contextualizeError(err, inspect(tx));
|
|
189
237
|
});
|
|
190
238
|
this.log.info(`Sent transaction ${txHash}`);
|
|
191
|
-
return txHash
|
|
239
|
+
// If wait is NO_WAIT, return txHash immediately
|
|
240
|
+
if (opts.wait === NO_WAIT) {
|
|
241
|
+
return txHash;
|
|
242
|
+
}
|
|
243
|
+
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
244
|
+
const waitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
245
|
+
return await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
192
246
|
}
|
|
193
247
|
contextualizeError(err, ...context) {
|
|
194
248
|
let contextStr = '';
|
|
@@ -206,15 +260,6 @@ import { inspect } from 'util';
|
|
|
206
260
|
simulateUtility(call, authwits) {
|
|
207
261
|
return this.pxe.simulateUtility(call, authwits);
|
|
208
262
|
}
|
|
209
|
-
getContractClassMetadata(id, includeArtifact = false) {
|
|
210
|
-
return this.pxe.getContractClassMetadata(id, includeArtifact);
|
|
211
|
-
}
|
|
212
|
-
getContractMetadata(address) {
|
|
213
|
-
return this.pxe.getContractMetadata(address);
|
|
214
|
-
}
|
|
215
|
-
getTxReceipt(txHash) {
|
|
216
|
-
return this.aztecNode.getTxReceipt(txHash);
|
|
217
|
-
}
|
|
218
263
|
async getPrivateEvents(eventDef, eventFilter) {
|
|
219
264
|
const pxeEvents = await this.pxe.getPrivateEvents(eventDef.eventSelector, eventFilter);
|
|
220
265
|
const decodedEvents = pxeEvents.map((pxeEvent)=>{
|
|
@@ -231,4 +276,25 @@ import { inspect } from 'util';
|
|
|
231
276
|
});
|
|
232
277
|
return decodedEvents;
|
|
233
278
|
}
|
|
279
|
+
async getContractMetadata(address) {
|
|
280
|
+
const instance = await this.pxe.getContractInstance(address);
|
|
281
|
+
const initNullifier = await siloNullifier(address, address.toField());
|
|
282
|
+
const publiclyRegisteredContract = await this.aztecNode.getContract(address);
|
|
283
|
+
const initNullifierMembershipWitness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
284
|
+
const isContractUpdated = publiclyRegisteredContract && !publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
285
|
+
return {
|
|
286
|
+
instance: instance ?? undefined,
|
|
287
|
+
isContractInitialized: !!initNullifierMembershipWitness,
|
|
288
|
+
isContractPublished: !!publiclyRegisteredContract,
|
|
289
|
+
isContractUpdated: !!isContractUpdated,
|
|
290
|
+
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
async getContractClassMetadata(id) {
|
|
294
|
+
const publiclyRegisteredContractClass = await this.aztecNode.getContractClass(id);
|
|
295
|
+
return {
|
|
296
|
+
isArtifactRegistered: !!await this.pxe.getContractArtifact(id),
|
|
297
|
+
isContractClassPubliclyRegistered: !!publiclyRegisteredContractClass
|
|
298
|
+
};
|
|
299
|
+
}
|
|
234
300
|
}
|
|
@@ -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,48 @@
|
|
|
1
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
2
|
+
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
3
|
+
import { type FunctionCall } from '@aztec/stdlib/abi';
|
|
4
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
6
|
+
import { type BlockHeader, type ExecutionPayload, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
7
|
+
/**
|
|
8
|
+
* Splits an execution payload into a leading prefix of public static calls
|
|
9
|
+
* (eligible for direct node simulation) and the remaining calls.
|
|
10
|
+
*
|
|
11
|
+
* Only a leading run of public static calls is eligible for optimization.
|
|
12
|
+
* Any non-public-static call may enqueue public state mutations
|
|
13
|
+
* (e.g. private calls can enqueue public calls), so all calls that follow
|
|
14
|
+
* must go through the normal simulation path to see the correct state.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
export declare function extractOptimizablePublicStaticCalls(payload: ExecutionPayload): {
|
|
18
|
+
/** Leading public static calls eligible for direct node simulation. */
|
|
19
|
+
optimizableCalls: FunctionCall[];
|
|
20
|
+
/** All remaining calls. */
|
|
21
|
+
remainingCalls: FunctionCall[];
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Simulates public static calls by splitting them into batches of MAX_ENQUEUED_CALLS_PER_CALL
|
|
25
|
+
* and sending each batch directly to the node.
|
|
26
|
+
*
|
|
27
|
+
* @param node - The Aztec node to simulate on.
|
|
28
|
+
* @param publicStaticCalls - Array of public static function calls to optimize.
|
|
29
|
+
* @param from - The account address making the calls.
|
|
30
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
31
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
32
|
+
* @param blockHeader - Block header to use as anchor.
|
|
33
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
34
|
+
* @returns Array of TxSimulationResult, one per batch.
|
|
35
|
+
*/
|
|
36
|
+
export declare function simulateViaNode(node: AztecNode, publicStaticCalls: FunctionCall[], from: AztecAddress, chainInfo: ChainInfo, gasSettings: GasSettings, blockHeader: BlockHeader, skipFeeEnforcement?: boolean): Promise<TxSimulationResult[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Merges simulation results from the optimized (public static) and normal paths.
|
|
39
|
+
* Since optimized calls are always a leading prefix, return values are simply
|
|
40
|
+
* concatenated: optimized first, then normal.
|
|
41
|
+
* Stats are taken from the normal result only (the optimized path doesn't produce them).
|
|
42
|
+
*
|
|
43
|
+
* @param optimizedResults - Results from optimized public static call batches.
|
|
44
|
+
* @param normalResult - Result from normal simulation (null if all calls were optimized).
|
|
45
|
+
* @returns A single TxSimulationResult with return values in original call order.
|
|
46
|
+
*/
|
|
47
|
+
export declare function buildMergedSimulationResult(optimizedResults: TxSimulationResult[], normalResult: TxSimulationResult | null): TxSimulationResult;
|
|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,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAuB/B;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CACzC,gBAAgB,EAAE,kBAAkB,EAAE,EACtC,YAAY,EAAE,kBAAkB,GAAG,IAAI,GACtC,kBAAkB,CAoBpB"}
|
|
@@ -0,0 +1,128 @@
|
|
|
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 { generateSimulatedProvingResult } from '@aztec/pxe/simulator';
|
|
5
|
+
import { ClaimedLengthArray, CountedPublicCallRequest, PrivateCircuitPublicInputs, PublicCallRequest } from '@aztec/stdlib/kernel';
|
|
6
|
+
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
7
|
+
import { HashedValues, PrivateCallExecutionResult, PrivateExecutionResult, Tx, TxContext, 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
|
+
*/ export function extractOptimizablePublicStaticCalls(payload) {
|
|
18
|
+
const splitIndex = payload.calls.findIndex((call)=>!call.isPublicStatic());
|
|
19
|
+
const boundary = splitIndex === -1 ? payload.calls.length : splitIndex;
|
|
20
|
+
return {
|
|
21
|
+
optimizableCalls: payload.calls.slice(0, boundary),
|
|
22
|
+
remainingCalls: payload.calls.slice(boundary)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Simulates a batch of public static calls by bypassing account entrypoint and private execution,
|
|
27
|
+
* directly constructing a minimal Tx and calling node.simulatePublicCalls.
|
|
28
|
+
*
|
|
29
|
+
* @param node - The Aztec node to simulate on.
|
|
30
|
+
* @param publicStaticCalls - Array of public static function calls (max MAX_ENQUEUED_CALLS_PER_CALL).
|
|
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
|
+
* @returns TxSimulationResult with public return values.
|
|
37
|
+
*/ async function simulateBatchViaNode(node, publicStaticCalls, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement) {
|
|
38
|
+
const txContext = new TxContext(chainInfo.chainId, chainInfo.version, gasSettings);
|
|
39
|
+
const publicFunctionCalldata = [];
|
|
40
|
+
for (const call of publicStaticCalls){
|
|
41
|
+
const calldata = await HashedValues.fromCalldata([
|
|
42
|
+
call.selector.toField(),
|
|
43
|
+
...call.args
|
|
44
|
+
]);
|
|
45
|
+
publicFunctionCalldata.push(calldata);
|
|
46
|
+
}
|
|
47
|
+
const publicCallRequests = makeTuple(MAX_ENQUEUED_CALLS_PER_CALL, (i)=>{
|
|
48
|
+
const call = publicStaticCalls[i];
|
|
49
|
+
if (!call) {
|
|
50
|
+
return CountedPublicCallRequest.empty();
|
|
51
|
+
}
|
|
52
|
+
const publicCallRequest = new PublicCallRequest(from, call.to, call.isStatic, publicFunctionCalldata[i].hash);
|
|
53
|
+
// Counter starts at 1 (minRevertibleSideEffectCounter) so all calls are revertible
|
|
54
|
+
return new CountedPublicCallRequest(publicCallRequest, i + 1);
|
|
55
|
+
});
|
|
56
|
+
const publicCallRequestsArray = new ClaimedLengthArray(publicCallRequests, publicStaticCalls.length);
|
|
57
|
+
const publicInputs = PrivateCircuitPublicInputs.from({
|
|
58
|
+
...PrivateCircuitPublicInputs.empty(),
|
|
59
|
+
anchorBlockHeader: blockHeader,
|
|
60
|
+
txContext: txContext,
|
|
61
|
+
publicCallRequests: publicCallRequestsArray,
|
|
62
|
+
startSideEffectCounter: new Fr(0),
|
|
63
|
+
endSideEffectCounter: new Fr(publicStaticCalls.length + 1)
|
|
64
|
+
});
|
|
65
|
+
// Minimal entrypoint structure — no real private execution, just public call requests
|
|
66
|
+
const emptyEntrypoint = new PrivateCallExecutionResult(Buffer.alloc(0), Buffer.alloc(0), new Map(), publicInputs, [], new Map(), [], [], [], [], []);
|
|
67
|
+
const privateResult = new PrivateExecutionResult(emptyEntrypoint, Fr.random(), publicFunctionCalldata);
|
|
68
|
+
const provingResult = await generateSimulatedProvingResult(privateResult, (_contractAddress, _functionSelector)=>Promise.resolve(''), 1);
|
|
69
|
+
provingResult.publicInputs.feePayer = from;
|
|
70
|
+
const tx = await Tx.create({
|
|
71
|
+
data: provingResult.publicInputs,
|
|
72
|
+
chonkProof: ChonkProof.empty(),
|
|
73
|
+
contractClassLogFields: [],
|
|
74
|
+
publicFunctionCalldata: publicFunctionCalldata
|
|
75
|
+
});
|
|
76
|
+
const publicOutput = await node.simulatePublicCalls(tx, skipFeeEnforcement);
|
|
77
|
+
if (publicOutput.revertReason) {
|
|
78
|
+
throw publicOutput.revertReason;
|
|
79
|
+
}
|
|
80
|
+
return new TxSimulationResult(privateResult, provingResult.publicInputs, publicOutput, undefined);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Simulates public static calls by splitting them into batches of MAX_ENQUEUED_CALLS_PER_CALL
|
|
84
|
+
* and sending each batch directly to the node.
|
|
85
|
+
*
|
|
86
|
+
* @param node - The Aztec node to simulate on.
|
|
87
|
+
* @param publicStaticCalls - Array of public static function calls to optimize.
|
|
88
|
+
* @param from - The account address making the calls.
|
|
89
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
90
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
91
|
+
* @param blockHeader - Block header to use as anchor.
|
|
92
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
93
|
+
* @returns Array of TxSimulationResult, one per batch.
|
|
94
|
+
*/ export async function simulateViaNode(node, publicStaticCalls, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement = true) {
|
|
95
|
+
const batches = [];
|
|
96
|
+
for(let i = 0; i < publicStaticCalls.length; i += MAX_ENQUEUED_CALLS_PER_CALL){
|
|
97
|
+
batches.push(publicStaticCalls.slice(i, i + MAX_ENQUEUED_CALLS_PER_CALL));
|
|
98
|
+
}
|
|
99
|
+
const results = [];
|
|
100
|
+
for (const batch of batches){
|
|
101
|
+
const result = await simulateBatchViaNode(node, batch, from, chainInfo, gasSettings, blockHeader, skipFeeEnforcement);
|
|
102
|
+
results.push(result);
|
|
103
|
+
}
|
|
104
|
+
return results;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Merges simulation results from the optimized (public static) and normal paths.
|
|
108
|
+
* Since optimized calls are always a leading prefix, return values are simply
|
|
109
|
+
* concatenated: optimized first, then normal.
|
|
110
|
+
* Stats are taken from the normal result only (the optimized path doesn't produce them).
|
|
111
|
+
*
|
|
112
|
+
* @param optimizedResults - Results from optimized public static call batches.
|
|
113
|
+
* @param normalResult - Result from normal simulation (null if all calls were optimized).
|
|
114
|
+
* @returns A single TxSimulationResult with return values in original call order.
|
|
115
|
+
*/ export function buildMergedSimulationResult(optimizedResults, normalResult) {
|
|
116
|
+
const optimizedReturnValues = optimizedResults.flatMap((r)=>r.publicOutput?.publicReturnValues ?? []);
|
|
117
|
+
const normalReturnValues = normalResult?.publicOutput?.publicReturnValues ?? [];
|
|
118
|
+
const allReturnValues = [
|
|
119
|
+
...optimizedReturnValues,
|
|
120
|
+
...normalReturnValues
|
|
121
|
+
];
|
|
122
|
+
const baseResult = normalResult ?? optimizedResults[0];
|
|
123
|
+
const mergedPublicOutput = baseResult.publicOutput ? {
|
|
124
|
+
...baseResult.publicOutput,
|
|
125
|
+
publicReturnValues: allReturnValues
|
|
126
|
+
} : undefined;
|
|
127
|
+
return new TxSimulationResult(baseResult.privateExecutionResult, baseResult.publicInputs, mergedPublicOutput, normalResult?.stats);
|
|
128
|
+
}
|