@aztec/wallet-sdk 0.0.1-commit.f146247c → 0.0.1-commit.f224bb98b
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/dest/base-wallet/base_wallet.d.ts +31 -6
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +98 -12
- 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/extension/provider/extension_wallet.d.ts +3 -2
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -1
- package/dest/extension/provider/extension_wallet.js +9 -2
- package/dest/manager/types.d.ts +4 -4
- package/dest/manager/types.d.ts.map +1 -1
- package/dest/manager/wallet_manager.d.ts +1 -1
- package/dest/manager/wallet_manager.d.ts.map +1 -1
- package/dest/manager/wallet_manager.js +2 -2
- package/package.json +15 -9
- package/src/base-wallet/base_wallet.ts +122 -21
- package/src/base-wallet/index.ts +1 -0
- package/src/base-wallet/utils.ts +238 -0
- package/src/extension/provider/extension_wallet.ts +12 -4
- package/src/manager/types.ts +3 -3
- package/src/manager/wallet_manager.ts +7 -9
|
@@ -2,19 +2,20 @@ import type { Account } from '@aztec/aztec.js/account';
|
|
|
2
2
|
import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
|
|
3
3
|
import { type InteractionWaitOptions, type SendReturn } from '@aztec/aztec.js/contracts';
|
|
4
4
|
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
5
|
-
import type { Aliased, AppCapabilities, BatchResults, BatchedMethod, PrivateEvent, PrivateEventFilter, ProfileOptions, SendOptions, SimulateOptions, Wallet, WalletCapabilities } 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';
|
|
6
6
|
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
7
7
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
8
8
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
9
9
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
10
|
+
import { type AccessScopes } from '@aztec/pxe/client/lazy';
|
|
10
11
|
import type { PXE } from '@aztec/pxe/server';
|
|
11
12
|
import { type ContractArtifact, type EventMetadataDefinition, type FunctionCall } from '@aztec/stdlib/abi';
|
|
12
13
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
13
|
-
import
|
|
14
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
14
15
|
import { type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
15
16
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
16
17
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
17
|
-
import type
|
|
18
|
+
import { type TxExecutionRequest, type TxProfileResult, TxSimulationResult, type UtilityExecutionResult } from '@aztec/stdlib/tx';
|
|
18
19
|
import { ExecutionPayload } from '@aztec/stdlib/tx';
|
|
19
20
|
/**
|
|
20
21
|
* Options to configure fee payment for a transaction
|
|
@@ -39,7 +40,8 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
39
40
|
protected log: import("@aztec/foundation/log").Logger;
|
|
40
41
|
protected minFeePadding: number;
|
|
41
42
|
protected cancellableTransactions: boolean;
|
|
42
|
-
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[];
|
|
43
45
|
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
44
46
|
abstract getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
45
47
|
/**
|
|
@@ -96,11 +98,34 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
96
98
|
}>;
|
|
97
99
|
registerSender(address: AztecAddress, _alias?: string): Promise<AztecAddress>;
|
|
98
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
|
+
*/
|
|
99
119
|
simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult>;
|
|
100
120
|
profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult>;
|
|
101
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>;
|
|
102
127
|
protected contextualizeError(err: Error, ...context: string[]): Error;
|
|
103
|
-
|
|
128
|
+
executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult>;
|
|
104
129
|
getPrivateEvents<T>(eventDef: EventMetadataDefinition, eventFilter: PrivateEventFilter): Promise<PrivateEvent<T>[]>;
|
|
105
130
|
getContractMetadata(address: AztecAddress): Promise<{
|
|
106
131
|
instance: ContractInstanceWithAddress | undefined;
|
|
@@ -114,4 +139,4 @@ export declare abstract class BaseWallet implements Wallet {
|
|
|
114
139
|
isContractClassPubliclyRegistered: boolean;
|
|
115
140
|
}>;
|
|
116
141
|
}
|
|
117
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
142
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFzZV93YWxsZXQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC9iYXNlX3dhbGxldC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxPQUFPLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUN2RCxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsZUFBZSxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDakYsT0FBTyxFQUNMLEtBQUssc0JBQXNCLEVBRTNCLEtBQUssVUFBVSxFQUVoQixNQUFNLDJCQUEyQixDQUFDO0FBQ25DLE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFFNUQsT0FBTyxLQUFLLEVBQ1YsT0FBTyxFQUNQLGVBQWUsRUFDZixZQUFZLEVBQ1osYUFBY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sQ0FBQyxVQUFVLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0ErQnhCO0lBRUQ7OztPQUdHO0lBQ0gsVUFBZ0IsZUFBZSxDQUFDLE9BQU8sRUFBRSxZQUFZLEdBQUcsT0FBTyxDQUFDLE1BQU0sR0FBRyxTQUFTLENBQUMsQ0FPbEY7SUFFRCxTQUFTLENBQUMsa0JBQWtCLENBQUMsR0FBRyxFQUFFLEtBQUssRUFBRSxHQUFHLE9BQU8sRUFBRSxNQUFNLEVBQUUsR0FBRyxLQUFLLENBWXBFO0lBRUQsY0FBYyxDQUFDLElBQUksRUFBRSxZQUFZLEVBQUUsSUFBSSxFQUFFLHFCQUFxQixHQUFHLE9BQU8sQ0FBQyxzQkFBc0IsQ0FBQyxDQUUvRjtJQUVLLGdCQUFnQixDQUFDLENBQUMsRUFDdEIsUUFBUSxFQUFFLHVCQUF1QixFQUNqQyxXQUFXLEVBQUUsa0JBQWtCLEdBQzlCLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxDQWU1QjtJQUVLLG1CQUFtQixDQUFDLE9BQU8sRUFBRSxZQUFZOzs7Ozs7T0FlOUM7SUFFSyx3QkFBd0IsQ0FBQyxFQUFFLEVBQUUsRUFBRTs7O09BTXBDO0NBQ0YifQ==
|
|
@@ -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,
|
|
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,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AEK,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAQlG;IAEY,MAAM,CAAC,CAAC,SAAS,sBAAsB,GAAG,SAAS,EAC9D,gBAAgB,EAAE,gBAAgB,EAClC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CA+BxB;IAED;;;OAGG;IACH,UAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAOlF;IAED,SAAS,CAAC,kBAAkB,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,KAAK,CAYpE;IAED,cAAc,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAE/F;IAEK,gBAAgB,CAAC,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,16 +1,19 @@
|
|
|
1
|
-
import { NO_WAIT } from '@aztec/aztec.js/contracts';
|
|
1
|
+
import { NO_WAIT, extractOffchainOutput } from '@aztec/aztec.js/contracts';
|
|
2
2
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
3
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';
|
|
4
4
|
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
5
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
6
|
import { createLogger } from '@aztec/foundation/log';
|
|
7
|
+
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
7
8
|
import { decodeFromAbi } from '@aztec/stdlib/abi';
|
|
9
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
10
|
import { computePartialAddress, getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
9
11
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
10
12
|
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
11
13
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
12
14
|
import { mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
13
15
|
import { inspect } from 'util';
|
|
16
|
+
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
14
17
|
/**
|
|
15
18
|
* A base class for Wallet implementations
|
|
16
19
|
*/ export class BaseWallet {
|
|
@@ -20,13 +23,23 @@ import { inspect } from 'util';
|
|
|
20
23
|
minFeePadding;
|
|
21
24
|
cancellableTransactions;
|
|
22
25
|
// Protected because we want to force wallets to instantiate their own PXE.
|
|
23
|
-
constructor(pxe, aztecNode){
|
|
26
|
+
constructor(pxe, aztecNode, log = createLogger('wallet-sdk:base_wallet')){
|
|
24
27
|
this.pxe = pxe;
|
|
25
28
|
this.aztecNode = aztecNode;
|
|
26
|
-
this.log =
|
|
29
|
+
this.log = log;
|
|
27
30
|
this.minFeePadding = 0.5;
|
|
28
31
|
this.cancellableTransactions = false;
|
|
29
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
|
+
}
|
|
30
43
|
/**
|
|
31
44
|
* Returns the list of aliased contacts associated with the wallet.
|
|
32
45
|
* This base implementation directly returns PXE's senders, but note that in general contacts are a superset of senders.
|
|
@@ -183,20 +196,66 @@ import { inspect } from 'util';
|
|
|
183
196
|
}
|
|
184
197
|
return instance;
|
|
185
198
|
}
|
|
186
|
-
|
|
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) {
|
|
187
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);
|
|
188
|
-
const
|
|
189
|
-
|
|
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);
|
|
190
244
|
}
|
|
191
245
|
async profileTx(executionPayload, opts) {
|
|
192
246
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
193
247
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
194
|
-
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
|
+
});
|
|
195
253
|
}
|
|
196
254
|
async sendTx(executionPayload, opts) {
|
|
197
255
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
198
256
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
199
|
-
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());
|
|
200
259
|
const tx = await provenTx.toTx();
|
|
201
260
|
const txHash = tx.getTxHash();
|
|
202
261
|
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
@@ -209,11 +268,33 @@ import { inspect } from 'util';
|
|
|
209
268
|
this.log.info(`Sent transaction ${txHash}`);
|
|
210
269
|
// If wait is NO_WAIT, return txHash immediately
|
|
211
270
|
if (opts.wait === NO_WAIT) {
|
|
212
|
-
return
|
|
271
|
+
return {
|
|
272
|
+
txHash,
|
|
273
|
+
...offchainOutput
|
|
274
|
+
};
|
|
213
275
|
}
|
|
214
276
|
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
215
277
|
const waitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
216
|
-
|
|
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;
|
|
217
298
|
}
|
|
218
299
|
contextualizeError(err, ...context) {
|
|
219
300
|
let contextStr = '';
|
|
@@ -228,8 +309,13 @@ import { inspect } from 'util';
|
|
|
228
309
|
}
|
|
229
310
|
return err;
|
|
230
311
|
}
|
|
231
|
-
|
|
232
|
-
return this.pxe.
|
|
312
|
+
executeUtility(call, opts) {
|
|
313
|
+
return this.pxe.executeUtility(call, {
|
|
314
|
+
authwits: opts.authWitnesses,
|
|
315
|
+
scopes: [
|
|
316
|
+
opts.scope
|
|
317
|
+
]
|
|
318
|
+
});
|
|
233
319
|
}
|
|
234
320
|
async getPrivateEvents(eventDef, eventFilter) {
|
|
235
321
|
const pxeEvents = await this.pxe.getPrivateEvents(eventDef.eventSelector, eventFilter);
|
|
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlLXdhbGxldC91dGlscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxzQkFB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BAA2B,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
|
+
}
|
|
@@ -80,7 +80,8 @@ export declare class ExtensionWallet {
|
|
|
80
80
|
* const accounts = await wallet.getAccounts();
|
|
81
81
|
* ```
|
|
82
82
|
*/
|
|
83
|
-
static create(extensionId: string, port: MessagePort, sharedKey: CryptoKey, chainInfo: ChainInfo, appId: string):
|
|
83
|
+
static create(extensionId: string, port: MessagePort, sharedKey: CryptoKey, chainInfo: ChainInfo, appId: string): ExtensionWallet;
|
|
84
|
+
asWallet(): Wallet;
|
|
84
85
|
private handleEncryptedResponse;
|
|
85
86
|
private postMessage;
|
|
86
87
|
/**
|
|
@@ -128,4 +129,4 @@ export declare class ExtensionWallet {
|
|
|
128
129
|
*/
|
|
129
130
|
disconnect(): Promise<void>;
|
|
130
131
|
}
|
|
131
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
132
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXh0ZW5zaW9uX3dhbGxldC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2V4dGVuc2lvbi9wcm92aWRlci9leHRlbnNpb25fd2FsbGV0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBQ3pELE9BQU8sRUFBRSxLQUFLLE1BQU0sRUFBZ0IsTUFBTSx3QkFBd0IsQ0FBQztBQW9CbkU7O0dBRUc7QUFDSCxNQUFNLE1BQU0sa0JBQWtCLEdBQUcsTUFBTSxJQUFJLENBQUM7QUFFNUM7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7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ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,wBAAwB,CAAC;AAoBnE;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,eAAe;IAexB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,SAAS;IAlBnB,sEAAsE;IACtE,OAAO,CAAC,QAAQ,CAAoD;IACpE,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,mBAAmB,CAA4B;IAEvD;;;;;;;OAOG;IACH,OAAO,eAMH;IAEJ;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,MAAM,CAAC,MAAM,CACX,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,WAAW,EACjB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,MAAM,GACZ,MAAM,
|
|
1
|
+
{"version":3,"file":"extension_wallet.d.ts","sourceRoot":"","sources":["../../../src/extension/provider/extension_wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,wBAAwB,CAAC;AAoBnE;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,eAAe;IAexB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,SAAS;IAlBnB,sEAAsE;IACtE,OAAO,CAAC,QAAQ,CAAoD;IACpE,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,mBAAmB,CAA4B;IAEvD;;;;;;;OAOG;IACH,OAAO,eAMH;IAEJ;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,MAAM,CAAC,MAAM,CACX,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,WAAW,EACjB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,MAAM,GACZ,eAAe,CAkCjB;IAED,QAAQ,IAAI,MAAM,CAIjB;YAUa,uBAAuB;YA8CvB,WAAW;IA0BzB;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IA0BxB;;;;;;;;;;;;;;;OAeG;IACH,YAAY,CAAC,QAAQ,EAAE,kBAAkB,GAAG,MAAM,IAAI,CAQrD;IAED;;;;OAIG;IACH,cAAc,IAAI,OAAO,CAExB;IAED;;;;;;;;;;;;;OAaG;IAEG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAahC;CACF"}
|
|
@@ -100,8 +100,10 @@ import { WalletMessageType } from '../../types.js';
|
|
|
100
100
|
};
|
|
101
101
|
wallet.port.start();
|
|
102
102
|
return new Proxy(wallet, {
|
|
103
|
-
get: (target, prop)=>{
|
|
104
|
-
if (
|
|
103
|
+
get: (target, prop, receiver)=>{
|
|
104
|
+
if (prop === 'asWallet') {
|
|
105
|
+
return ()=>receiver;
|
|
106
|
+
} else if (schemaHasMethod(WalletSchema, prop.toString())) {
|
|
105
107
|
return async (...args)=>{
|
|
106
108
|
const result = await target.postMessage({
|
|
107
109
|
type: prop.toString(),
|
|
@@ -115,6 +117,11 @@ import { WalletMessageType } from '../../types.js';
|
|
|
115
117
|
}
|
|
116
118
|
});
|
|
117
119
|
}
|
|
120
|
+
asWallet() {
|
|
121
|
+
// Overridden by the proxy in create() to return the proxy itself.
|
|
122
|
+
// This body is never reached when accessed through create().
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
118
125
|
/**
|
|
119
126
|
* Handles an encrypted response received from the wallet extension.
|
|
120
127
|
*
|
package/dest/manager/types.d.ts
CHANGED
|
@@ -107,18 +107,18 @@ export interface WalletProvider {
|
|
|
107
107
|
* After calling this, the wallet returned from confirm() should no longer be used.
|
|
108
108
|
* @returns A promise that resolves when disconnection is complete
|
|
109
109
|
*/
|
|
110
|
-
disconnect
|
|
110
|
+
disconnect(): Promise<void>;
|
|
111
111
|
/**
|
|
112
112
|
* Registers a callback to be invoked when the wallet disconnects unexpectedly.
|
|
113
113
|
* @param callback - Function to call when wallet disconnects
|
|
114
114
|
* @returns A function to unregister the callback
|
|
115
115
|
*/
|
|
116
|
-
onDisconnect
|
|
116
|
+
onDisconnect(callback: ProviderDisconnectionCallback): () => void;
|
|
117
117
|
/**
|
|
118
118
|
* Returns whether the provider's wallet connection has been disconnected.
|
|
119
119
|
* @returns true if the wallet is no longer connected
|
|
120
120
|
*/
|
|
121
|
-
isDisconnected
|
|
121
|
+
isDisconnected(): boolean;
|
|
122
122
|
}
|
|
123
123
|
/**
|
|
124
124
|
* Options for discovering wallets
|
|
@@ -164,4 +164,4 @@ export interface DiscoverySession {
|
|
|
164
164
|
/** Cancel discovery immediately and clean up resources */
|
|
165
165
|
cancel: () => void;
|
|
166
166
|
}
|
|
167
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
167
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tYW5hZ2VyL3R5cGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBQ3pELE9BQU8sS0FBSyxFQUFFLE1BQU0sRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBRXJEOzs7Ozs7Ozs7R0FTRztBQUNILE1BQ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ed;
|
|
69
69
|
}
|
|
70
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
70
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2FsbGV0X21hbmFnZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tYW5hZ2VyL3dhbGxldF9tYW5hZ2VyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUtBLE9BQU8sS0FBSyxFQUNWLHNCQUFzQixFQUN0QixnQkFBZ0IsRUFJaEIsbUJBQW1CLEVBRXBCLE1BQU0sWUFBWSxDQUFDO0FBRXBCOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0E4Qkc7QUFDSCxxQkFBYSxhQUFhO0lBQ3hCLE9BQU8sQ0FBQyxNQUFNLENBR1o7SUFFRixPQUFPLGVBQWlCO0lBRXhCOzs7T0FHRztJQUNILE1BQU0sQ0FBQyxTQUFTLENBQUMsTUFBTSxFQUFFLG1CQUFtQixHQUFHLGFBQWEsQ0FPM0Q7SUFFRDs7Ozs7Ozs7Ozs7O09BWUc7SUFDSCxtQkFBbUIsQ0FBQyxPQUFPLEVBQUUsc0JBQXNCLEdBQUcsZ0JBQWdCLENBNkVyRTtJQUVEOzs7Ozs7T0FNRztJQUNILE9BQU8sQ0FBQyxrQ0FBa0M7SUEwRTFDOzs7O09BSUc7SUFDSCxPQUFPLENBQUMsa0JBQWtCO0NBVzNCIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet_manager.d.ts","sourceRoot":"","sources":["../../src/manager/wallet_manager.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,sBAAsB,EACtB,gBAAgB,EAIhB,mBAAmB,EAEpB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAGZ;IAEF,OAAO,eAAiB;IAExB;;;OAGG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,mBAAmB,GAAG,aAAa,CAO3D;IAED;;;;;;;;;;;;OAYG;IACH,mBAAmB,CAAC,OAAO,EAAE,sBAAsB,GAAG,gBAAgB,CA6ErE;IAED;;;;;;OAMG;IACH,OAAO,CAAC,kCAAkC;
|
|
1
|
+
{"version":3,"file":"wallet_manager.d.ts","sourceRoot":"","sources":["../../src/manager/wallet_manager.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,sBAAsB,EACtB,gBAAgB,EAIhB,mBAAmB,EAEpB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAGZ;IAEF,OAAO,eAAiB;IAExB;;;OAGG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,mBAAmB,GAAG,aAAa,CAO3D;IAED;;;;;;;;;;;;OAYG;IACH,mBAAmB,CAAC,OAAO,EAAE,sBAAsB,GAAG,gBAAgB,CA6ErE;IAED;;;;;;OAMG;IACH,OAAO,CAAC,kCAAkC;IA0E1C;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;CAW3B"}
|
|
@@ -176,7 +176,8 @@ import { WalletMessageType } from '../types.js';
|
|
|
176
176
|
return {
|
|
177
177
|
verificationHash: connection.info.verificationHash,
|
|
178
178
|
confirm: ()=>{
|
|
179
|
-
|
|
179
|
+
extensionWallet = ExtensionWallet.create(connection.info.id, connection.port, connection.sharedKey, chainInfo, connectAppId);
|
|
180
|
+
return Promise.resolve(extensionWallet.asWallet());
|
|
180
181
|
},
|
|
181
182
|
cancel: ()=>{
|
|
182
183
|
// Send disconnect to terminate the session on the extension side
|
|
@@ -185,7 +186,6 @@ import { WalletMessageType } from '../types.js';
|
|
|
185
186
|
type: WalletMessageType.DISCONNECT,
|
|
186
187
|
requestId: discoveredWallet.requestId
|
|
187
188
|
});
|
|
188
|
-
// Don't close the port - allow retry with fresh key exchange
|
|
189
189
|
}
|
|
190
190
|
};
|
|
191
191
|
},
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/wallet-sdk",
|
|
3
3
|
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/wallet-sdk",
|
|
4
|
-
"version": "0.0.1-commit.
|
|
4
|
+
"version": "0.0.1-commit.f224bb98b",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./base-wallet": "./dest/base-wallet/index.js",
|
|
@@ -13,8 +13,14 @@
|
|
|
13
13
|
},
|
|
14
14
|
"typedocOptions": {
|
|
15
15
|
"entryPoints": [
|
|
16
|
-
"./src/index.ts"
|
|
16
|
+
"./src/base-wallet/index.ts",
|
|
17
|
+
"./src/extension/handlers/index.ts",
|
|
18
|
+
"./src/extension/provider/index.ts",
|
|
19
|
+
"./src/crypto.ts",
|
|
20
|
+
"./src/types.ts",
|
|
21
|
+
"./src/manager/index.ts"
|
|
17
22
|
],
|
|
23
|
+
"name": "Wallet SDK",
|
|
18
24
|
"tsconfig": "./tsconfig.json"
|
|
19
25
|
},
|
|
20
26
|
"scripts": {
|
|
@@ -65,15 +71,15 @@
|
|
|
65
71
|
]
|
|
66
72
|
},
|
|
67
73
|
"dependencies": {
|
|
68
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
69
|
-
"@aztec/constants": "0.0.1-commit.
|
|
70
|
-
"@aztec/entrypoints": "0.0.1-commit.
|
|
71
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
72
|
-
"@aztec/pxe": "0.0.1-commit.
|
|
73
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
74
|
+
"@aztec/aztec.js": "0.0.1-commit.f224bb98b",
|
|
75
|
+
"@aztec/constants": "0.0.1-commit.f224bb98b",
|
|
76
|
+
"@aztec/entrypoints": "0.0.1-commit.f224bb98b",
|
|
77
|
+
"@aztec/foundation": "0.0.1-commit.f224bb98b",
|
|
78
|
+
"@aztec/pxe": "0.0.1-commit.f224bb98b",
|
|
79
|
+
"@aztec/stdlib": "0.0.1-commit.f224bb98b"
|
|
74
80
|
},
|
|
75
81
|
"devDependencies": {
|
|
76
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
82
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.f224bb98b",
|
|
77
83
|
"@jest/globals": "^30.0.0",
|
|
78
84
|
"@types/jest": "^30.0.0",
|
|
79
85
|
"@types/node": "^22.15.17",
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { Account } from '@aztec/aztec.js/account';
|
|
2
2
|
import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type InteractionWaitOptions,
|
|
5
|
+
NO_WAIT,
|
|
6
|
+
type SendReturn,
|
|
7
|
+
extractOffchainOutput,
|
|
8
|
+
} from '@aztec/aztec.js/contracts';
|
|
4
9
|
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
5
10
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
6
11
|
import type {
|
|
@@ -8,6 +13,7 @@ import type {
|
|
|
8
13
|
AppCapabilities,
|
|
9
14
|
BatchResults,
|
|
10
15
|
BatchedMethod,
|
|
16
|
+
ExecuteUtilityOptions,
|
|
11
17
|
PrivateEvent,
|
|
12
18
|
PrivateEventFilter,
|
|
13
19
|
ProfileOptions,
|
|
@@ -27,6 +33,7 @@ import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
|
27
33
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
28
34
|
import { createLogger } from '@aztec/foundation/log';
|
|
29
35
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
36
|
+
import { type AccessScopes, displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
30
37
|
import type { PXE, PackedPrivateEvent } from '@aztec/pxe/server';
|
|
31
38
|
import {
|
|
32
39
|
type ContractArtifact,
|
|
@@ -35,7 +42,7 @@ import {
|
|
|
35
42
|
decodeFromAbi,
|
|
36
43
|
} from '@aztec/stdlib/abi';
|
|
37
44
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
38
|
-
import
|
|
45
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
39
46
|
import {
|
|
40
47
|
type ContractInstanceWithAddress,
|
|
41
48
|
computePartialAddress,
|
|
@@ -45,16 +52,19 @@ import { SimulationError } from '@aztec/stdlib/errors';
|
|
|
45
52
|
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
46
53
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
47
54
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
48
|
-
import
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
import {
|
|
56
|
+
BlockHeader,
|
|
57
|
+
type TxExecutionRequest,
|
|
58
|
+
type TxProfileResult,
|
|
51
59
|
TxSimulationResult,
|
|
52
|
-
|
|
60
|
+
type UtilityExecutionResult,
|
|
53
61
|
} from '@aztec/stdlib/tx';
|
|
54
62
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
55
63
|
|
|
56
64
|
import { inspect } from 'util';
|
|
57
65
|
|
|
66
|
+
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
67
|
+
|
|
58
68
|
/**
|
|
59
69
|
* Options to configure fee payment for a transaction
|
|
60
70
|
*/
|
|
@@ -74,8 +84,6 @@ export type FeeOptions = {
|
|
|
74
84
|
* A base class for Wallet implementations
|
|
75
85
|
*/
|
|
76
86
|
export abstract class BaseWallet implements Wallet {
|
|
77
|
-
protected log = createLogger('wallet-sdk:base_wallet');
|
|
78
|
-
|
|
79
87
|
protected minFeePadding = 0.5;
|
|
80
88
|
protected cancellableTransactions = false;
|
|
81
89
|
|
|
@@ -83,8 +91,15 @@ export abstract class BaseWallet implements Wallet {
|
|
|
83
91
|
protected constructor(
|
|
84
92
|
protected readonly pxe: PXE,
|
|
85
93
|
protected readonly aztecNode: AztecNode,
|
|
94
|
+
protected log = createLogger('wallet-sdk:base_wallet'),
|
|
86
95
|
) {}
|
|
87
96
|
|
|
97
|
+
protected scopesFrom(from: AztecAddress, additionalScopes: AztecAddress[] = []): AztecAddress[] {
|
|
98
|
+
const allScopes = from.isZero() ? additionalScopes : [from, ...additionalScopes];
|
|
99
|
+
const scopeSet = new Set(allScopes.map(address => address.toString()));
|
|
100
|
+
return [...scopeSet].map(AztecAddress.fromString);
|
|
101
|
+
}
|
|
102
|
+
|
|
88
103
|
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
89
104
|
|
|
90
105
|
abstract getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
@@ -282,23 +297,88 @@ export abstract class BaseWallet implements Wallet {
|
|
|
282
297
|
return instance;
|
|
283
298
|
}
|
|
284
299
|
|
|
300
|
+
/**
|
|
301
|
+
* Simulates calls through the standard PXE path (account entrypoint).
|
|
302
|
+
* @param executionPayload - The execution payload to simulate.
|
|
303
|
+
* @param from - The sender address.
|
|
304
|
+
* @param feeOptions - Fee options for the transaction.
|
|
305
|
+
* @param skipTxValidation - Whether to skip tx validation.
|
|
306
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement.
|
|
307
|
+
* @param scopes - The scopes to use for the simulation.
|
|
308
|
+
*/
|
|
309
|
+
protected async simulateViaEntrypoint(
|
|
310
|
+
executionPayload: ExecutionPayload,
|
|
311
|
+
from: AztecAddress,
|
|
312
|
+
feeOptions: FeeOptions,
|
|
313
|
+
scopes: AccessScopes,
|
|
314
|
+
skipTxValidation?: boolean,
|
|
315
|
+
skipFeeEnforcement?: boolean,
|
|
316
|
+
) {
|
|
317
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions);
|
|
318
|
+
return this.pxe.simulateTx(txRequest, { simulatePublic: true, skipTxValidation, skipFeeEnforcement, scopes });
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Simulates a transaction, optimizing leading public static calls by running them directly
|
|
323
|
+
* on the node while sending the remaining calls through the standard PXE path.
|
|
324
|
+
* Return values from both paths are merged back in original call order.
|
|
325
|
+
* @param executionPayload - The execution payload to simulate.
|
|
326
|
+
* @param opts - Simulation options (from address, fee settings, etc.).
|
|
327
|
+
* @returns The merged simulation result.
|
|
328
|
+
*/
|
|
285
329
|
async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
|
|
286
330
|
const feeOptions = opts.fee?.estimateGas
|
|
287
331
|
? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings)
|
|
288
332
|
: await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
333
|
+
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
334
|
+
const remainingPayload = { ...executionPayload, calls: remainingCalls };
|
|
335
|
+
|
|
336
|
+
const chainInfo = await this.getChainInfo();
|
|
337
|
+
let blockHeader: BlockHeader;
|
|
338
|
+
// PXE might not be synced yet, so we pull the latest header from the node
|
|
339
|
+
// To keep things consistent, we'll always try with PXE first
|
|
340
|
+
try {
|
|
341
|
+
blockHeader = await this.pxe.getSyncedBlockHeader();
|
|
342
|
+
} catch {
|
|
343
|
+
blockHeader = (await this.aztecNode.getBlockHeader())!;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const [optimizedResults, normalResult] = await Promise.all([
|
|
347
|
+
optimizableCalls.length > 0
|
|
348
|
+
? simulateViaNode(
|
|
349
|
+
this.aztecNode,
|
|
350
|
+
optimizableCalls,
|
|
351
|
+
opts.from,
|
|
352
|
+
chainInfo,
|
|
353
|
+
feeOptions.gasSettings,
|
|
354
|
+
blockHeader,
|
|
355
|
+
opts.skipFeeEnforcement ?? true,
|
|
356
|
+
this.getContractName.bind(this),
|
|
357
|
+
)
|
|
358
|
+
: Promise.resolve([]),
|
|
359
|
+
remainingCalls.length > 0
|
|
360
|
+
? this.simulateViaEntrypoint(
|
|
361
|
+
remainingPayload,
|
|
362
|
+
opts.from,
|
|
363
|
+
feeOptions,
|
|
364
|
+
this.scopesFrom(opts.from, opts.additionalScopes),
|
|
365
|
+
opts.skipTxValidation,
|
|
366
|
+
opts.skipFeeEnforcement ?? true,
|
|
367
|
+
)
|
|
368
|
+
: Promise.resolve(null),
|
|
369
|
+
]);
|
|
370
|
+
|
|
371
|
+
return buildMergedSimulationResult(optimizedResults, normalResult);
|
|
296
372
|
}
|
|
297
373
|
|
|
298
374
|
async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
|
|
299
375
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
300
376
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
301
|
-
return this.pxe.profileTx(txRequest,
|
|
377
|
+
return this.pxe.profileTx(txRequest, {
|
|
378
|
+
profileMode: opts.profileMode,
|
|
379
|
+
skipProofGeneration: opts.skipProofGeneration ?? true,
|
|
380
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
381
|
+
});
|
|
302
382
|
}
|
|
303
383
|
|
|
304
384
|
public async sendTx<W extends InteractionWaitOptions = undefined>(
|
|
@@ -307,7 +387,8 @@ export abstract class BaseWallet implements Wallet {
|
|
|
307
387
|
): Promise<SendReturn<W>> {
|
|
308
388
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
309
389
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
310
|
-
const provenTx = await this.pxe.proveTx(txRequest);
|
|
390
|
+
const provenTx = await this.pxe.proveTx(txRequest, this.scopesFrom(opts.from, opts.additionalScopes));
|
|
391
|
+
const offchainOutput = extractOffchainOutput(provenTx.getOffchainEffects());
|
|
311
392
|
const tx = await provenTx.toTx();
|
|
312
393
|
const txHash = tx.getTxHash();
|
|
313
394
|
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
@@ -321,12 +402,32 @@ export abstract class BaseWallet implements Wallet {
|
|
|
321
402
|
|
|
322
403
|
// If wait is NO_WAIT, return txHash immediately
|
|
323
404
|
if (opts.wait === NO_WAIT) {
|
|
324
|
-
return txHash as SendReturn<W>;
|
|
405
|
+
return { txHash, ...offchainOutput } as SendReturn<W>;
|
|
325
406
|
}
|
|
326
407
|
|
|
327
408
|
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
328
409
|
const waitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
329
|
-
|
|
410
|
+
const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
|
|
411
|
+
|
|
412
|
+
// Display debug logs from public execution if present (served in test mode only)
|
|
413
|
+
if (receipt.debugLogs?.length) {
|
|
414
|
+
await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return { receipt, ...offchainOutput } as SendReturn<W>;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Resolves a contract address to a human-readable name via PXE, if available.
|
|
422
|
+
* @param address - The contract address to resolve.
|
|
423
|
+
*/
|
|
424
|
+
protected async getContractName(address: AztecAddress): Promise<string | undefined> {
|
|
425
|
+
const instance = await this.pxe.getContractInstance(address);
|
|
426
|
+
if (!instance) {
|
|
427
|
+
return undefined;
|
|
428
|
+
}
|
|
429
|
+
const artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
430
|
+
return artifact?.name;
|
|
330
431
|
}
|
|
331
432
|
|
|
332
433
|
protected contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -343,8 +444,8 @@ export abstract class BaseWallet implements Wallet {
|
|
|
343
444
|
return err;
|
|
344
445
|
}
|
|
345
446
|
|
|
346
|
-
|
|
347
|
-
return this.pxe.
|
|
447
|
+
executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult> {
|
|
448
|
+
return this.pxe.executeUtility(call, { authwits: opts.authWitnesses, scopes: [opts.scope] });
|
|
348
449
|
}
|
|
349
450
|
|
|
350
451
|
async getPrivateEvents<T>(
|
package/src/base-wallet/index.ts
CHANGED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
2
|
+
import { MAX_ENQUEUED_CALLS_PER_CALL } from '@aztec/constants';
|
|
3
|
+
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
4
|
+
import { makeTuple } from '@aztec/foundation/array';
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
|
+
import type { Tuple } from '@aztec/foundation/serialize';
|
|
7
|
+
import type { ContractNameResolver } from '@aztec/pxe/client/lazy';
|
|
8
|
+
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
9
|
+
import { generateSimulatedProvingResult } from '@aztec/pxe/simulator';
|
|
10
|
+
import { type FunctionCall, FunctionSelector } from '@aztec/stdlib/abi';
|
|
11
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
12
|
+
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
13
|
+
import {
|
|
14
|
+
ClaimedLengthArray,
|
|
15
|
+
CountedPublicCallRequest,
|
|
16
|
+
PrivateCircuitPublicInputs,
|
|
17
|
+
PublicCallRequest,
|
|
18
|
+
} from '@aztec/stdlib/kernel';
|
|
19
|
+
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
20
|
+
import {
|
|
21
|
+
type BlockHeader,
|
|
22
|
+
type ExecutionPayload,
|
|
23
|
+
HashedValues,
|
|
24
|
+
PrivateCallExecutionResult,
|
|
25
|
+
PrivateExecutionResult,
|
|
26
|
+
PublicSimulationOutput,
|
|
27
|
+
Tx,
|
|
28
|
+
TxContext,
|
|
29
|
+
TxSimulationResult,
|
|
30
|
+
} from '@aztec/stdlib/tx';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Splits an execution payload into a leading prefix of public static calls
|
|
34
|
+
* (eligible for direct node simulation) and the remaining calls.
|
|
35
|
+
*
|
|
36
|
+
* Only a leading run of public static calls is eligible for optimization.
|
|
37
|
+
* Any non-public-static call may enqueue public state mutations
|
|
38
|
+
* (e.g. private calls can enqueue public calls), so all calls that follow
|
|
39
|
+
* must go through the normal simulation path to see the correct state.
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
export function extractOptimizablePublicStaticCalls(payload: ExecutionPayload): {
|
|
43
|
+
/** Leading public static calls eligible for direct node simulation. */
|
|
44
|
+
optimizableCalls: FunctionCall[];
|
|
45
|
+
/** All remaining calls. */
|
|
46
|
+
remainingCalls: FunctionCall[];
|
|
47
|
+
} {
|
|
48
|
+
const splitIndex = payload.calls.findIndex(call => !call.isPublicStatic());
|
|
49
|
+
const boundary = splitIndex === -1 ? payload.calls.length : splitIndex;
|
|
50
|
+
return {
|
|
51
|
+
optimizableCalls: payload.calls.slice(0, boundary),
|
|
52
|
+
remainingCalls: payload.calls.slice(boundary),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Simulates a batch of public static calls by bypassing account entrypoint and private execution,
|
|
58
|
+
* directly constructing a minimal Tx and calling node.simulatePublicCalls.
|
|
59
|
+
*
|
|
60
|
+
* @param node - The Aztec node to simulate on.
|
|
61
|
+
* @param publicStaticCalls - Array of public static function calls (max MAX_ENQUEUED_CALLS_PER_CALL).
|
|
62
|
+
* @param from - The account address making the calls.
|
|
63
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
64
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
65
|
+
* @param blockHeader - Block header to use as anchor.
|
|
66
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
67
|
+
* @returns TxSimulationResult with public return values.
|
|
68
|
+
*/
|
|
69
|
+
async function simulateBatchViaNode(
|
|
70
|
+
node: AztecNode,
|
|
71
|
+
publicStaticCalls: FunctionCall[],
|
|
72
|
+
from: AztecAddress,
|
|
73
|
+
chainInfo: ChainInfo,
|
|
74
|
+
gasSettings: GasSettings,
|
|
75
|
+
blockHeader: BlockHeader,
|
|
76
|
+
skipFeeEnforcement: boolean,
|
|
77
|
+
getContractName: ContractNameResolver,
|
|
78
|
+
): Promise<TxSimulationResult> {
|
|
79
|
+
const txContext = new TxContext(chainInfo.chainId, chainInfo.version, gasSettings);
|
|
80
|
+
|
|
81
|
+
const publicFunctionCalldata: HashedValues[] = [];
|
|
82
|
+
for (const call of publicStaticCalls) {
|
|
83
|
+
const calldata = await HashedValues.fromCalldata([call.selector.toField(), ...call.args]);
|
|
84
|
+
publicFunctionCalldata.push(calldata);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const publicCallRequests = makeTuple(MAX_ENQUEUED_CALLS_PER_CALL, i => {
|
|
88
|
+
const call = publicStaticCalls[i];
|
|
89
|
+
if (!call) {
|
|
90
|
+
return CountedPublicCallRequest.empty();
|
|
91
|
+
}
|
|
92
|
+
const publicCallRequest = new PublicCallRequest(from, call.to, call.isStatic, publicFunctionCalldata[i]!.hash);
|
|
93
|
+
// Counter starts at 1 (minRevertibleSideEffectCounter) so all calls are revertible
|
|
94
|
+
return new CountedPublicCallRequest(publicCallRequest, i + 1);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const publicCallRequestsArray: ClaimedLengthArray<CountedPublicCallRequest, typeof MAX_ENQUEUED_CALLS_PER_CALL> =
|
|
98
|
+
new ClaimedLengthArray(
|
|
99
|
+
publicCallRequests as Tuple<CountedPublicCallRequest, typeof MAX_ENQUEUED_CALLS_PER_CALL>,
|
|
100
|
+
publicStaticCalls.length,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const publicInputs = PrivateCircuitPublicInputs.from({
|
|
104
|
+
...PrivateCircuitPublicInputs.empty(),
|
|
105
|
+
anchorBlockHeader: blockHeader,
|
|
106
|
+
txContext: txContext,
|
|
107
|
+
publicCallRequests: publicCallRequestsArray,
|
|
108
|
+
startSideEffectCounter: new Fr(0),
|
|
109
|
+
endSideEffectCounter: new Fr(publicStaticCalls.length + 1),
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Minimal entrypoint structure — no real private execution, just public call requests
|
|
113
|
+
const emptyEntrypoint = new PrivateCallExecutionResult(
|
|
114
|
+
Buffer.alloc(0),
|
|
115
|
+
Buffer.alloc(0),
|
|
116
|
+
new Map(),
|
|
117
|
+
publicInputs,
|
|
118
|
+
[],
|
|
119
|
+
new Map(),
|
|
120
|
+
[],
|
|
121
|
+
[],
|
|
122
|
+
[],
|
|
123
|
+
[],
|
|
124
|
+
[],
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const privateResult = new PrivateExecutionResult(emptyEntrypoint, Fr.random(), publicFunctionCalldata);
|
|
128
|
+
|
|
129
|
+
const provingResult = await generateSimulatedProvingResult(
|
|
130
|
+
privateResult,
|
|
131
|
+
(_contractAddress: AztecAddress, _functionSelector: FunctionSelector) => Promise.resolve(''),
|
|
132
|
+
node,
|
|
133
|
+
1, // minRevertibleSideEffectCounter
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
provingResult.publicInputs.feePayer = from;
|
|
137
|
+
|
|
138
|
+
const tx = await Tx.create({
|
|
139
|
+
data: provingResult.publicInputs,
|
|
140
|
+
chonkProof: ChonkProof.empty(),
|
|
141
|
+
contractClassLogFields: [],
|
|
142
|
+
publicFunctionCalldata: publicFunctionCalldata,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const publicOutput = await node.simulatePublicCalls(tx, skipFeeEnforcement);
|
|
146
|
+
|
|
147
|
+
if (publicOutput.revertReason) {
|
|
148
|
+
throw publicOutput.revertReason;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Display debug logs from the public simulation.
|
|
152
|
+
await displayDebugLogs(publicOutput.debugLogs, getContractName);
|
|
153
|
+
|
|
154
|
+
return new TxSimulationResult(privateResult, provingResult.publicInputs, publicOutput, undefined);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Simulates public static calls by splitting them into batches of MAX_ENQUEUED_CALLS_PER_CALL
|
|
159
|
+
* and sending each batch directly to the node.
|
|
160
|
+
*
|
|
161
|
+
* @param node - The Aztec node to simulate on.
|
|
162
|
+
* @param publicStaticCalls - Array of public static function calls to optimize.
|
|
163
|
+
* @param from - The account address making the calls.
|
|
164
|
+
* @param chainInfo - Chain information (chainId and version).
|
|
165
|
+
* @param gasSettings - Gas settings for the transaction.
|
|
166
|
+
* @param blockHeader - Block header to use as anchor.
|
|
167
|
+
* @param skipFeeEnforcement - Whether to skip fee enforcement during simulation.
|
|
168
|
+
* @returns Array of TxSimulationResult, one per batch.
|
|
169
|
+
*/
|
|
170
|
+
export async function simulateViaNode(
|
|
171
|
+
node: AztecNode,
|
|
172
|
+
publicStaticCalls: FunctionCall[],
|
|
173
|
+
from: AztecAddress,
|
|
174
|
+
chainInfo: ChainInfo,
|
|
175
|
+
gasSettings: GasSettings,
|
|
176
|
+
blockHeader: BlockHeader,
|
|
177
|
+
skipFeeEnforcement: boolean = true,
|
|
178
|
+
getContractName: ContractNameResolver,
|
|
179
|
+
): Promise<TxSimulationResult[]> {
|
|
180
|
+
const batches: FunctionCall[][] = [];
|
|
181
|
+
|
|
182
|
+
for (let i = 0; i < publicStaticCalls.length; i += MAX_ENQUEUED_CALLS_PER_CALL) {
|
|
183
|
+
batches.push(publicStaticCalls.slice(i, i + MAX_ENQUEUED_CALLS_PER_CALL));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const results: TxSimulationResult[] = [];
|
|
187
|
+
|
|
188
|
+
for (const batch of batches) {
|
|
189
|
+
const result = await simulateBatchViaNode(
|
|
190
|
+
node,
|
|
191
|
+
batch,
|
|
192
|
+
from,
|
|
193
|
+
chainInfo,
|
|
194
|
+
gasSettings,
|
|
195
|
+
blockHeader,
|
|
196
|
+
skipFeeEnforcement,
|
|
197
|
+
getContractName,
|
|
198
|
+
);
|
|
199
|
+
results.push(result);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return results;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Merges simulation results from the optimized (public static) and normal paths.
|
|
207
|
+
* Since optimized calls are always a leading prefix, return values are simply
|
|
208
|
+
* concatenated: optimized first, then normal.
|
|
209
|
+
* Stats are taken from the normal result only (the optimized path doesn't produce them).
|
|
210
|
+
*
|
|
211
|
+
* @param optimizedResults - Results from optimized public static call batches.
|
|
212
|
+
* @param normalResult - Result from normal simulation (null if all calls were optimized).
|
|
213
|
+
* @returns A single TxSimulationResult with return values in original call order.
|
|
214
|
+
*/
|
|
215
|
+
export function buildMergedSimulationResult(
|
|
216
|
+
optimizedResults: TxSimulationResult[],
|
|
217
|
+
normalResult: TxSimulationResult | null,
|
|
218
|
+
): TxSimulationResult {
|
|
219
|
+
const optimizedReturnValues = optimizedResults.flatMap(r => r.publicOutput?.publicReturnValues ?? []);
|
|
220
|
+
const normalReturnValues = normalResult?.publicOutput?.publicReturnValues ?? [];
|
|
221
|
+
const allReturnValues = [...optimizedReturnValues, ...normalReturnValues];
|
|
222
|
+
|
|
223
|
+
const baseResult = normalResult ?? optimizedResults[0];
|
|
224
|
+
|
|
225
|
+
const mergedPublicOutput: PublicSimulationOutput | undefined = baseResult.publicOutput
|
|
226
|
+
? {
|
|
227
|
+
...baseResult.publicOutput,
|
|
228
|
+
publicReturnValues: allReturnValues,
|
|
229
|
+
}
|
|
230
|
+
: undefined;
|
|
231
|
+
|
|
232
|
+
return new TxSimulationResult(
|
|
233
|
+
baseResult.privateExecutionResult,
|
|
234
|
+
baseResult.publicInputs,
|
|
235
|
+
mergedPublicOutput,
|
|
236
|
+
normalResult?.stats,
|
|
237
|
+
);
|
|
238
|
+
}
|
|
@@ -109,7 +109,7 @@ export class ExtensionWallet {
|
|
|
109
109
|
sharedKey: CryptoKey,
|
|
110
110
|
chainInfo: ChainInfo,
|
|
111
111
|
appId: string,
|
|
112
|
-
):
|
|
112
|
+
): ExtensionWallet {
|
|
113
113
|
const wallet = new ExtensionWallet(chainInfo, appId, extensionId, port, sharedKey);
|
|
114
114
|
|
|
115
115
|
// Set up message handler for encrypted responses and unencrypted control messages
|
|
@@ -127,8 +127,10 @@ export class ExtensionWallet {
|
|
|
127
127
|
wallet.port.start();
|
|
128
128
|
|
|
129
129
|
return new Proxy(wallet, {
|
|
130
|
-
get: (target, prop) => {
|
|
131
|
-
if (
|
|
130
|
+
get: (target, prop, receiver) => {
|
|
131
|
+
if (prop === 'asWallet') {
|
|
132
|
+
return () => receiver as unknown as Wallet;
|
|
133
|
+
} else if (schemaHasMethod(WalletSchema, prop.toString())) {
|
|
132
134
|
return async (...args: unknown[]) => {
|
|
133
135
|
const result = await target.postMessage({
|
|
134
136
|
type: prop.toString() as keyof FunctionsOf<Wallet>,
|
|
@@ -140,7 +142,13 @@ export class ExtensionWallet {
|
|
|
140
142
|
return target[prop as keyof ExtensionWallet];
|
|
141
143
|
}
|
|
142
144
|
},
|
|
143
|
-
})
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
asWallet(): Wallet {
|
|
149
|
+
// Overridden by the proxy in create() to return the proxy itself.
|
|
150
|
+
// This body is never reached when accessed through create().
|
|
151
|
+
return this as unknown as Wallet;
|
|
144
152
|
}
|
|
145
153
|
|
|
146
154
|
/**
|
package/src/manager/types.ts
CHANGED
|
@@ -116,18 +116,18 @@ export interface WalletProvider {
|
|
|
116
116
|
* After calling this, the wallet returned from confirm() should no longer be used.
|
|
117
117
|
* @returns A promise that resolves when disconnection is complete
|
|
118
118
|
*/
|
|
119
|
-
disconnect
|
|
119
|
+
disconnect(): Promise<void>;
|
|
120
120
|
/**
|
|
121
121
|
* Registers a callback to be invoked when the wallet disconnects unexpectedly.
|
|
122
122
|
* @param callback - Function to call when wallet disconnects
|
|
123
123
|
* @returns A function to unregister the callback
|
|
124
124
|
*/
|
|
125
|
-
onDisconnect
|
|
125
|
+
onDisconnect(callback: ProviderDisconnectionCallback): () => void;
|
|
126
126
|
/**
|
|
127
127
|
* Returns whether the provider's wallet connection has been disconnected.
|
|
128
128
|
* @returns true if the wallet is no longer connected
|
|
129
129
|
*/
|
|
130
|
-
isDisconnected
|
|
130
|
+
isDisconnected(): boolean;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
/**
|
|
@@ -196,15 +196,14 @@ export class WalletManager {
|
|
|
196
196
|
return {
|
|
197
197
|
verificationHash: connection.info.verificationHash!,
|
|
198
198
|
confirm: () => {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
connectAppId,
|
|
206
|
-
),
|
|
199
|
+
extensionWallet = ExtensionWallet.create(
|
|
200
|
+
connection.info.id,
|
|
201
|
+
connection.port,
|
|
202
|
+
connection.sharedKey,
|
|
203
|
+
chainInfo,
|
|
204
|
+
connectAppId,
|
|
207
205
|
);
|
|
206
|
+
return Promise.resolve(extensionWallet.asWallet());
|
|
208
207
|
},
|
|
209
208
|
cancel: () => {
|
|
210
209
|
// Send disconnect to terminate the session on the extension side
|
|
@@ -213,7 +212,6 @@ export class WalletManager {
|
|
|
213
212
|
type: WalletMessageType.DISCONNECT,
|
|
214
213
|
requestId: discoveredWallet.requestId,
|
|
215
214
|
});
|
|
216
|
-
// Don't close the port - allow retry with fresh key exchange
|
|
217
215
|
},
|
|
218
216
|
};
|
|
219
217
|
},
|