@aztec/wallet-sdk 0.0.1-commit.d431d1c → 0.0.1-commit.db765a8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +217 -294
- package/dest/base-wallet/base_wallet.d.ts +47 -9
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +120 -18
- package/dest/base-wallet/index.d.ts +2 -1
- package/dest/base-wallet/index.d.ts.map +1 -1
- package/dest/base-wallet/index.js +1 -0
- package/dest/base-wallet/utils.d.ts +49 -0
- package/dest/base-wallet/utils.d.ts.map +1 -0
- package/dest/base-wallet/utils.js +131 -0
- package/dest/crypto.d.ts +59 -50
- package/dest/crypto.d.ts.map +1 -1
- package/dest/crypto.js +202 -108
- package/dest/emoji_alphabet.d.ts +35 -0
- package/dest/emoji_alphabet.d.ts.map +1 -0
- package/dest/emoji_alphabet.js +299 -0
- package/dest/extension/handlers/background_connection_handler.d.ts +158 -0
- package/dest/extension/handlers/background_connection_handler.d.ts.map +1 -0
- package/dest/extension/handlers/background_connection_handler.js +258 -0
- package/dest/extension/handlers/content_script_connection_handler.d.ts +56 -0
- package/dest/extension/handlers/content_script_connection_handler.d.ts.map +1 -0
- package/dest/extension/handlers/content_script_connection_handler.js +174 -0
- package/dest/extension/handlers/index.d.ts +12 -0
- package/dest/extension/handlers/index.d.ts.map +1 -0
- package/dest/extension/handlers/index.js +10 -0
- package/dest/extension/handlers/internal_message_types.d.ts +63 -0
- package/dest/extension/handlers/internal_message_types.d.ts.map +1 -0
- package/dest/extension/handlers/internal_message_types.js +22 -0
- package/dest/extension/provider/extension_provider.d.ts +107 -0
- package/dest/extension/provider/extension_provider.d.ts.map +1 -0
- package/dest/extension/provider/extension_provider.js +160 -0
- package/dest/extension/provider/extension_wallet.d.ts +132 -0
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -0
- package/dest/{providers/extension → extension/provider}/extension_wallet.js +57 -97
- package/dest/extension/provider/index.d.ts +3 -0
- package/dest/extension/provider/index.d.ts.map +1 -0
- package/dest/{providers/extension → extension/provider}/index.js +0 -2
- package/dest/manager/index.d.ts +2 -8
- package/dest/manager/index.d.ts.map +1 -1
- package/dest/manager/index.js +0 -6
- package/dest/manager/types.d.ts +91 -9
- package/dest/manager/types.d.ts.map +1 -1
- package/dest/manager/types.js +17 -1
- package/dest/manager/wallet_manager.d.ts +50 -7
- package/dest/manager/wallet_manager.d.ts.map +1 -1
- package/dest/manager/wallet_manager.js +174 -44
- package/dest/types.d.ts +43 -12
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +3 -2
- package/package.json +17 -10
- package/src/base-wallet/base_wallet.ts +154 -35
- package/src/base-wallet/index.ts +1 -0
- package/src/base-wallet/utils.ts +238 -0
- package/src/crypto.ts +237 -113
- package/src/emoji_alphabet.ts +317 -0
- package/src/extension/handlers/background_connection_handler.ts +423 -0
- package/src/extension/handlers/content_script_connection_handler.ts +246 -0
- package/src/extension/handlers/index.ts +25 -0
- package/src/extension/handlers/internal_message_types.ts +69 -0
- package/src/extension/provider/extension_provider.ts +233 -0
- package/src/{providers/extension → extension/provider}/extension_wallet.ts +61 -111
- package/src/extension/provider/index.ts +7 -0
- package/src/manager/index.ts +2 -10
- package/src/manager/types.ts +94 -8
- package/src/manager/wallet_manager.ts +190 -46
- package/src/types.ts +44 -10
- package/dest/providers/extension/extension_provider.d.ts +0 -63
- package/dest/providers/extension/extension_provider.d.ts.map +0 -1
- package/dest/providers/extension/extension_provider.js +0 -124
- package/dest/providers/extension/extension_wallet.d.ts +0 -155
- package/dest/providers/extension/extension_wallet.d.ts.map +0 -1
- package/dest/providers/extension/index.d.ts +0 -6
- package/dest/providers/extension/index.d.ts.map +0 -1
- package/src/providers/extension/extension_provider.ts +0 -167
- package/src/providers/extension/index.ts +0 -5
package/dest/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.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B"}
|
package/dest/types.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
*/ export var WalletMessageType = /*#__PURE__*/ function(WalletMessageType) {
|
|
5
5
|
/** Discovery request to find installed wallets */ WalletMessageType["DISCOVERY"] = "aztec-wallet-discovery";
|
|
6
6
|
/** Discovery response from a wallet */ WalletMessageType["DISCOVERY_RESPONSE"] = "aztec-wallet-discovery-response";
|
|
7
|
-
/**
|
|
8
|
-
/**
|
|
7
|
+
/** Disconnect message (unencrypted control message, bidirectional) */ WalletMessageType["DISCONNECT"] = "aztec-wallet-disconnect";
|
|
8
|
+
/** Key exchange request sent over MessageChannel */ WalletMessageType["KEY_EXCHANGE_REQUEST"] = "aztec-wallet-key-exchange-request";
|
|
9
|
+
/** Key exchange response sent over MessageChannel */ WalletMessageType["KEY_EXCHANGE_RESPONSE"] = "aztec-wallet-key-exchange-response";
|
|
9
10
|
return WalletMessageType;
|
|
10
11
|
}({});
|
package/package.json
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
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.db765a8",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./base-wallet": "./dest/base-wallet/index.js",
|
|
8
|
-
"./
|
|
8
|
+
"./extension/handlers": "./dest/extension/handlers/index.js",
|
|
9
|
+
"./extension/provider": "./dest/extension/provider/index.js",
|
|
9
10
|
"./crypto": "./dest/crypto.js",
|
|
10
11
|
"./types": "./dest/types.js",
|
|
11
12
|
"./manager": "./dest/manager/index.js"
|
|
12
13
|
},
|
|
13
14
|
"typedocOptions": {
|
|
14
15
|
"entryPoints": [
|
|
15
|
-
"./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"
|
|
16
22
|
],
|
|
23
|
+
"name": "Wallet SDK",
|
|
17
24
|
"tsconfig": "./tsconfig.json"
|
|
18
25
|
},
|
|
19
26
|
"scripts": {
|
|
@@ -64,15 +71,15 @@
|
|
|
64
71
|
]
|
|
65
72
|
},
|
|
66
73
|
"dependencies": {
|
|
67
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
68
|
-
"@aztec/constants": "0.0.1-commit.
|
|
69
|
-
"@aztec/entrypoints": "0.0.1-commit.
|
|
70
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
71
|
-
"@aztec/pxe": "0.0.1-commit.
|
|
72
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
74
|
+
"@aztec/aztec.js": "0.0.1-commit.db765a8",
|
|
75
|
+
"@aztec/constants": "0.0.1-commit.db765a8",
|
|
76
|
+
"@aztec/entrypoints": "0.0.1-commit.db765a8",
|
|
77
|
+
"@aztec/foundation": "0.0.1-commit.db765a8",
|
|
78
|
+
"@aztec/pxe": "0.0.1-commit.db765a8",
|
|
79
|
+
"@aztec/stdlib": "0.0.1-commit.db765a8"
|
|
73
80
|
},
|
|
74
81
|
"devDependencies": {
|
|
75
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
82
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.db765a8",
|
|
76
83
|
"@jest/globals": "^30.0.0",
|
|
77
84
|
"@types/jest": "^30.0.0",
|
|
78
85
|
"@types/node": "^22.15.17",
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import type { Account } from '@aztec/aztec.js/account';
|
|
2
2
|
import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import {
|
|
4
|
+
type InteractionWaitOptions,
|
|
5
|
+
NO_WAIT,
|
|
6
|
+
type SendReturn,
|
|
7
|
+
extractOffchainOutput,
|
|
8
|
+
} from '@aztec/aztec.js/contracts';
|
|
3
9
|
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
10
|
+
import { waitForTx } from '@aztec/aztec.js/node';
|
|
4
11
|
import type {
|
|
5
12
|
Aliased,
|
|
13
|
+
AppCapabilities,
|
|
6
14
|
BatchResults,
|
|
7
15
|
BatchedMethod,
|
|
16
|
+
ExecuteUtilityOptions,
|
|
8
17
|
PrivateEvent,
|
|
9
18
|
PrivateEventFilter,
|
|
10
19
|
ProfileOptions,
|
|
11
20
|
SendOptions,
|
|
12
21
|
SimulateOptions,
|
|
13
22
|
Wallet,
|
|
23
|
+
WalletCapabilities,
|
|
14
24
|
} from '@aztec/aztec.js/wallet';
|
|
15
25
|
import {
|
|
16
26
|
GAS_ESTIMATION_DA_GAS_LIMIT,
|
|
@@ -23,6 +33,7 @@ import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
|
23
33
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
24
34
|
import { createLogger } from '@aztec/foundation/log';
|
|
25
35
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
36
|
+
import { type AccessScopes, displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
26
37
|
import type { PXE, PackedPrivateEvent } from '@aztec/pxe/server';
|
|
27
38
|
import {
|
|
28
39
|
type ContractArtifact,
|
|
@@ -31,7 +42,7 @@ import {
|
|
|
31
42
|
decodeFromAbi,
|
|
32
43
|
} from '@aztec/stdlib/abi';
|
|
33
44
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
34
|
-
import
|
|
45
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
35
46
|
import {
|
|
36
47
|
type ContractInstanceWithAddress,
|
|
37
48
|
computePartialAddress,
|
|
@@ -41,18 +52,19 @@ import { SimulationError } from '@aztec/stdlib/errors';
|
|
|
41
52
|
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
42
53
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
43
54
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
44
|
-
import
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
TxProfileResult,
|
|
48
|
-
TxReceipt,
|
|
55
|
+
import {
|
|
56
|
+
BlockHeader,
|
|
57
|
+
type TxExecutionRequest,
|
|
58
|
+
type TxProfileResult,
|
|
49
59
|
TxSimulationResult,
|
|
50
|
-
|
|
60
|
+
type UtilityExecutionResult,
|
|
51
61
|
} from '@aztec/stdlib/tx';
|
|
52
62
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
53
63
|
|
|
54
64
|
import { inspect } from 'util';
|
|
55
65
|
|
|
66
|
+
import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
|
|
67
|
+
|
|
56
68
|
/**
|
|
57
69
|
* Options to configure fee payment for a transaction
|
|
58
70
|
*/
|
|
@@ -72,8 +84,6 @@ export type FeeOptions = {
|
|
|
72
84
|
* A base class for Wallet implementations
|
|
73
85
|
*/
|
|
74
86
|
export abstract class BaseWallet implements Wallet {
|
|
75
|
-
protected log = createLogger('wallet-sdk:base_wallet');
|
|
76
|
-
|
|
77
87
|
protected minFeePadding = 0.5;
|
|
78
88
|
protected cancellableTransactions = false;
|
|
79
89
|
|
|
@@ -81,8 +91,15 @@ export abstract class BaseWallet implements Wallet {
|
|
|
81
91
|
protected constructor(
|
|
82
92
|
protected readonly pxe: PXE,
|
|
83
93
|
protected readonly aztecNode: AztecNode,
|
|
94
|
+
protected log = createLogger('wallet-sdk:base_wallet'),
|
|
84
95
|
) {}
|
|
85
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
|
+
|
|
86
103
|
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
87
104
|
|
|
88
105
|
abstract getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
@@ -137,6 +154,23 @@ export abstract class BaseWallet implements Wallet {
|
|
|
137
154
|
return account.createAuthWit(messageHashOrIntent, chainInfo);
|
|
138
155
|
}
|
|
139
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Request capabilities from the wallet.
|
|
159
|
+
*
|
|
160
|
+
* This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
|
|
161
|
+
* Embedded wallets typically don't support capability-based authorization (no user authorization flow),
|
|
162
|
+
* while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
|
|
163
|
+
* friction by allowing apps to request permissions upfront.
|
|
164
|
+
*
|
|
165
|
+
* TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
|
|
166
|
+
* while the feature stabilizes.
|
|
167
|
+
*
|
|
168
|
+
* @param _manifest - Application capability manifest declaring what operations the app needs
|
|
169
|
+
*/
|
|
170
|
+
public requestCapabilities(_manifest: AppCapabilities): Promise<WalletCapabilities> {
|
|
171
|
+
throw new Error('Not implemented');
|
|
172
|
+
}
|
|
173
|
+
|
|
140
174
|
public async batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>> {
|
|
141
175
|
const results: any[] = [];
|
|
142
176
|
for (const method of methods) {
|
|
@@ -263,29 +297,98 @@ export abstract class BaseWallet implements Wallet {
|
|
|
263
297
|
return instance;
|
|
264
298
|
}
|
|
265
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
|
+
*/
|
|
266
329
|
async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
|
|
267
330
|
const feeOptions = opts.fee?.estimateGas
|
|
268
331
|
? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings)
|
|
269
332
|
: await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
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);
|
|
277
372
|
}
|
|
278
373
|
|
|
279
374
|
async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
|
|
280
375
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
281
376
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
282
|
-
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
|
+
});
|
|
283
382
|
}
|
|
284
383
|
|
|
285
|
-
async sendTx
|
|
384
|
+
public async sendTx<W extends InteractionWaitOptions = undefined>(
|
|
385
|
+
executionPayload: ExecutionPayload,
|
|
386
|
+
opts: SendOptions<W>,
|
|
387
|
+
): Promise<SendReturn<W>> {
|
|
286
388
|
const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
287
389
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
288
|
-
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());
|
|
289
392
|
const tx = await provenTx.toTx();
|
|
290
393
|
const txHash = tx.getTxHash();
|
|
291
394
|
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
@@ -296,7 +399,35 @@ export abstract class BaseWallet implements Wallet {
|
|
|
296
399
|
throw this.contextualizeError(err, inspect(tx));
|
|
297
400
|
});
|
|
298
401
|
this.log.info(`Sent transaction ${txHash}`);
|
|
299
|
-
|
|
402
|
+
|
|
403
|
+
// If wait is NO_WAIT, return txHash immediately
|
|
404
|
+
if (opts.wait === NO_WAIT) {
|
|
405
|
+
return { txHash, ...offchainOutput } as SendReturn<W>;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// Otherwise, wait for the full receipt (default behavior on wait: undefined)
|
|
409
|
+
const waitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
|
|
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;
|
|
300
431
|
}
|
|
301
432
|
|
|
302
433
|
protected contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -313,12 +444,8 @@ export abstract class BaseWallet implements Wallet {
|
|
|
313
444
|
return err;
|
|
314
445
|
}
|
|
315
446
|
|
|
316
|
-
|
|
317
|
-
return this.pxe.
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
321
|
-
return this.aztecNode.getTxReceipt(txHash);
|
|
447
|
+
executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult> {
|
|
448
|
+
return this.pxe.executeUtility(call, { authwits: opts.authWitnesses, scopes: [opts.scope] });
|
|
322
449
|
}
|
|
323
450
|
|
|
324
451
|
async getPrivateEvents<T>(
|
|
@@ -345,14 +472,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
345
472
|
const instance = await this.pxe.getContractInstance(address);
|
|
346
473
|
const initNullifier = await siloNullifier(address, address.toField());
|
|
347
474
|
const publiclyRegisteredContract = await this.aztecNode.getContract(address);
|
|
348
|
-
const
|
|
349
|
-
this.aztecNode.getNullifierMembershipWitness('latest', initNullifier),
|
|
350
|
-
publiclyRegisteredContract
|
|
351
|
-
? this.aztecNode.getContractClass(
|
|
352
|
-
publiclyRegisteredContract.currentContractClassId || instance?.currentContractClassId,
|
|
353
|
-
)
|
|
354
|
-
: undefined,
|
|
355
|
-
]);
|
|
475
|
+
const initNullifierMembershipWitness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
356
476
|
const isContractUpdated =
|
|
357
477
|
publiclyRegisteredContract &&
|
|
358
478
|
!publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
@@ -360,7 +480,6 @@ export abstract class BaseWallet implements Wallet {
|
|
|
360
480
|
instance: instance ?? undefined,
|
|
361
481
|
isContractInitialized: !!initNullifierMembershipWitness,
|
|
362
482
|
isContractPublished: !!publiclyRegisteredContract,
|
|
363
|
-
isContractClassPubliclyRegistered: !!publiclyRegisteredContractClass,
|
|
364
483
|
isContractUpdated: !!isContractUpdated,
|
|
365
484
|
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined,
|
|
366
485
|
};
|
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
|
+
}
|