@aztec/wallets 4.1.2 → 4.2.0-aztecnr-rc.2
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/embedded/embedded_wallet.d.ts +14 -5
- package/dest/embedded/embedded_wallet.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.js +99 -53
- package/dest/testing.d.ts +1 -1
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +2 -2
- package/package.json +19 -10
- package/src/embedded/embedded_wallet.ts +129 -63
- package/src/testing.ts +2 -1
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { type Account } from '@aztec/aztec.js/account';
|
|
2
|
-
import type
|
|
2
|
+
import { type InteractionWaitOptions, type SendReturn } from '@aztec/aztec.js/contracts';
|
|
3
|
+
import type { Aliased, SendOptions } from '@aztec/aztec.js/wallet';
|
|
3
4
|
import { AccountManager } from '@aztec/aztec.js/wallet';
|
|
4
5
|
import { Fq, Fr } from '@aztec/foundation/curves/bn254';
|
|
5
6
|
import type { Logger } from '@aztec/foundation/log';
|
|
6
|
-
import type {
|
|
7
|
+
import type { PXEConfig, PXECreationOptions } from '@aztec/pxe/client/lazy';
|
|
7
8
|
import type { PXE } from '@aztec/pxe/server';
|
|
8
9
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
9
10
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
10
11
|
import { ExecutionPayload, type TxSimulationResult } from '@aztec/stdlib/tx';
|
|
11
|
-
import { BaseWallet, type
|
|
12
|
+
import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
12
13
|
import type { AccountContractsProvider } from './account-contract-providers/types.js';
|
|
13
14
|
import { type AccountType, WalletDB } from './wallet_db.js';
|
|
14
15
|
export type EmbeddedWalletOptions = {
|
|
@@ -24,17 +25,24 @@ export type EmbeddedWalletOptions = {
|
|
|
24
25
|
export declare class EmbeddedWallet extends BaseWallet {
|
|
25
26
|
protected walletDB: WalletDB;
|
|
26
27
|
protected accountContracts: AccountContractsProvider;
|
|
28
|
+
protected estimatedGasPadding: number;
|
|
27
29
|
constructor(pxe: PXE, aztecNode: AztecNode, walletDB: WalletDB, accountContracts: AccountContractsProvider, log?: Logger);
|
|
28
30
|
protected getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
29
31
|
getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
30
32
|
registerSender(address: AztecAddress, alias: string): Promise<AztecAddress>;
|
|
31
33
|
getAddressBook(): Promise<Aliased<AztecAddress>[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Overrides the base sendTx to add a pre-simulation step before the actual send. The simulation
|
|
36
|
+
* estimates actual gas usage and captures call authorization requests to generate
|
|
37
|
+
* the necessary authwitnesses.
|
|
38
|
+
*/
|
|
39
|
+
sendTx<W extends InteractionWaitOptions = undefined>(executionPayload: ExecutionPayload, opts: SendOptions<W>): Promise<SendReturn<W>>;
|
|
32
40
|
/**
|
|
33
41
|
* Simulates calls via a stub account entrypoint, bypassing real account authorization.
|
|
34
42
|
* This allows kernelless simulation with contract overrides, skipping expensive
|
|
35
43
|
* private kernel circuit execution.
|
|
36
44
|
*/
|
|
37
|
-
protected simulateViaEntrypoint(executionPayload: ExecutionPayload,
|
|
45
|
+
protected simulateViaEntrypoint(executionPayload: ExecutionPayload, opts: SimulateViaEntrypointOptions): Promise<TxSimulationResult>;
|
|
38
46
|
private getFakeAccountDataFor;
|
|
39
47
|
protected createAccountInternal(type: AccountType, secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager>;
|
|
40
48
|
createAndStoreAccount(alias: string, type: AccountType, secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager>;
|
|
@@ -42,6 +50,7 @@ export declare class EmbeddedWallet extends BaseWallet {
|
|
|
42
50
|
createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer, alias?: string): Promise<AccountManager>;
|
|
43
51
|
createECDSAKAccount(secret: Fr, salt: Fr, signingKey: Buffer, alias?: string): Promise<AccountManager>;
|
|
44
52
|
setMinFeePadding(value?: number): void;
|
|
53
|
+
setEstimatedGasPadding(value?: number): void;
|
|
45
54
|
stop(): Promise<void>;
|
|
46
55
|
}
|
|
47
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
56
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW1iZWRkZWRfd2FsbGV0LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZW1iZWRkZWQvZW1iZWRkZWRfd2FsbGV0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxLQUFLLE9BQU8sRUFBVyxNQUFNLHlCQUF5QixDQUFDO0FBRWhFLE9BQU8sRUFBRSxLQUFLLHNCQUFzQixFQUFFLEtBQUssVUFBVSxFQUFnQixNQUFNLDJCQUEyQixDQUFDO0FBQ3ZHLE9BQU8sS0FBSyxFQUFFLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUNuRSxPQUFPLEVBQUUsY0FBYyxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFHeEQsT0FBTyxFQUFFLEVBQUUsRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN4RCxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUNwRCxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsa0JBQWtCLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUM1RSxPQUFPLEtBQUssRUFBRSxHQUFHLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUM3QyxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFHM0QsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU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QyxNQUFNLEVBQUUsRUFBRSxFQUFFLElBQUksRUFBRSxFQUFFLEVBQUUsVUFBVSxDQUFDLEVBQUUsRUFBRSxFQUFFLEtBQUssQ0FBQyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsY0FBYyxDQUFDLENBR25HO0lBRUQsbUJBQW1CLENBQUMsTUFBTSxFQUFFLEVBQUUsRUFBRSxJQUFJLEVBQUUsRUFBRSxFQUFFLFVBQVUsRUFBRSxNQUFNLEVBQUUsS0FBSyxDQUFDLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxjQUFjLENBQUMsQ0FFckc7SUFFRCxtQkFBbUIsQ0FBQyxNQUFNLEVBQUUsRUFBRSxFQUFFLElBQUksRUFBRSxFQUFFLEVBQUUsVUFBVSxFQUFFLE1BQU0sRUFBRSxLQUFLLENBQUMsRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLGNBQWMsQ0FBQyxDQUVyRztJQUVELGdCQUFnQixDQUFDLEtBQUssQ0FBQyxFQUFFLE1BQU0sUUFFOUI7SUFFRCxzQkFBc0IsQ0FBQyxLQUFLLENBQUMsRUFBRSxNQUFNLFFBRXBDO0lBRUQsSUFBSSxrQkFFSDtDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embedded_wallet.d.ts","sourceRoot":"","sources":["../../src/embedded/embedded_wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,
|
|
1
|
+
{"version":3,"file":"embedded_wallet.d.ts","sourceRoot":"","sources":["../../src/embedded/embedded_wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAW,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAE,KAAK,sBAAsB,EAAE,KAAK,UAAU,EAAgB,MAAM,2BAA2B,CAAC;AACvG,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,cAAc,E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AAO,CAAC,cAAc,CAAC,CAErG;IAED,mBAAmB,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAErG;IAED,gBAAgB,CAAC,KAAK,CAAC,EAAE,MAAM,QAE9B;IAED,sBAAsB,CAAC,KAAK,CAAC,EAAE,MAAM,QAEpC;IAED,IAAI,kBAEH;CACF"}
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
2
|
+
import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import { getGasLimits } from '@aztec/aztec.js/contracts';
|
|
2
4
|
import { AccountManager } from '@aztec/aztec.js/wallet';
|
|
5
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
3
6
|
import { Fq, Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
7
|
import { getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
|
|
8
|
+
import { GasSettings } from '@aztec/stdlib/gas';
|
|
6
9
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
7
|
-
import { mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
10
|
+
import { collectOffchainEffects, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
8
11
|
import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
|
|
12
|
+
const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
|
|
9
13
|
export class EmbeddedWallet extends BaseWallet {
|
|
10
14
|
walletDB;
|
|
11
15
|
accountContracts;
|
|
16
|
+
estimatedGasPadding;
|
|
12
17
|
constructor(pxe, aztecNode, walletDB, accountContracts, log){
|
|
13
|
-
super(pxe, aztecNode, log), this.walletDB = walletDB, this.accountContracts = accountContracts;
|
|
18
|
+
super(pxe, aztecNode, log), this.walletDB = walletDB, this.accountContracts = accountContracts, this.estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING;
|
|
14
19
|
}
|
|
15
20
|
async getAccountFromAddress(address) {
|
|
16
|
-
if (address.equals(AztecAddress.ZERO)) {
|
|
17
|
-
return new SignerlessAccount();
|
|
18
|
-
}
|
|
19
21
|
const { secretKey, salt, signingKey, type } = await this.walletDB.retrieveAccount(address);
|
|
20
22
|
const accountManager = await this.createAccountInternal(type, secretKey, salt, signingKey);
|
|
21
23
|
const account = await accountManager.getAccount();
|
|
@@ -42,72 +44,113 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
42
44
|
return storedSenders;
|
|
43
45
|
}
|
|
44
46
|
/**
|
|
47
|
+
* Overrides the base sendTx to add a pre-simulation step before the actual send. The simulation
|
|
48
|
+
* estimates actual gas usage and captures call authorization requests to generate
|
|
49
|
+
* the necessary authwitnesses.
|
|
50
|
+
*/ async sendTx(executionPayload, opts) {
|
|
51
|
+
const feeOptions = await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
52
|
+
// Simulate the transaction first to estimate gas and capture required
|
|
53
|
+
// private authwitnesses based on offchain effects.
|
|
54
|
+
const simulationResult = await this.simulateViaEntrypoint(executionPayload, {
|
|
55
|
+
from: opts.from,
|
|
56
|
+
feeOptions,
|
|
57
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
58
|
+
skipTxValidation: true
|
|
59
|
+
});
|
|
60
|
+
const offchainEffects = collectOffchainEffects(simulationResult.privateExecutionResult);
|
|
61
|
+
const authWitnesses = await Promise.all(offchainEffects.map(async (effect)=>{
|
|
62
|
+
try {
|
|
63
|
+
const authRequest = await CallAuthorizationRequest.fromFields(effect.data);
|
|
64
|
+
return this.createAuthWit(authRequest.onBehalfOf, {
|
|
65
|
+
consumer: effect.contractAddress,
|
|
66
|
+
innerHash: authRequest.innerHash
|
|
67
|
+
});
|
|
68
|
+
} catch {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
}));
|
|
72
|
+
for (const authwit of authWitnesses){
|
|
73
|
+
if (authwit) {
|
|
74
|
+
executionPayload.authWitnesses.push(authwit);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const estimated = getGasLimits(simulationResult, this.estimatedGasPadding);
|
|
78
|
+
this.log.verbose(`Estimated gas limits for tx: DA=${estimated.gasLimits.daGas} L2=${estimated.gasLimits.l2Gas} teardownDA=${estimated.teardownGasLimits.daGas} teardownL2=${estimated.teardownGasLimits.l2Gas}`);
|
|
79
|
+
const gasSettings = GasSettings.from({
|
|
80
|
+
...opts.fee?.gasSettings,
|
|
81
|
+
maxFeesPerGas: feeOptions.gasSettings.maxFeesPerGas,
|
|
82
|
+
maxPriorityFeesPerGas: feeOptions.gasSettings.maxPriorityFeesPerGas,
|
|
83
|
+
gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
|
|
84
|
+
teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits
|
|
85
|
+
});
|
|
86
|
+
return super.sendTx(executionPayload, {
|
|
87
|
+
...opts,
|
|
88
|
+
fee: {
|
|
89
|
+
...opts.fee,
|
|
90
|
+
gasSettings
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
45
95
|
* Simulates calls via a stub account entrypoint, bypassing real account authorization.
|
|
46
96
|
* This allows kernelless simulation with contract overrides, skipping expensive
|
|
47
97
|
* private kernel circuit execution.
|
|
48
|
-
*/ async simulateViaEntrypoint(executionPayload,
|
|
49
|
-
const {
|
|
98
|
+
*/ async simulateViaEntrypoint(executionPayload, opts) {
|
|
99
|
+
const { from, feeOptions, scopes, skipTxValidation, skipFeeEnforcement } = opts;
|
|
50
100
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
51
|
-
const executionOptions = {
|
|
52
|
-
txNonce: Fr.random(),
|
|
53
|
-
cancellable: this.cancellableTransactions,
|
|
54
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
55
|
-
};
|
|
56
101
|
const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
|
|
57
102
|
feeExecutionPayload,
|
|
58
103
|
executionPayload
|
|
59
104
|
]) : executionPayload;
|
|
60
105
|
const chainInfo = await this.getChainInfo();
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
106
|
+
let overrides;
|
|
107
|
+
let txRequest;
|
|
108
|
+
if (from === NO_FROM) {
|
|
109
|
+
const entrypoint = new DefaultEntrypoint();
|
|
110
|
+
txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
111
|
+
} else {
|
|
112
|
+
const { account, instance, artifact } = await this.getFakeAccountDataFor(from);
|
|
113
|
+
overrides = {
|
|
67
114
|
contracts: {
|
|
68
115
|
[from.toString()]: {
|
|
69
116
|
instance,
|
|
70
117
|
artifact
|
|
71
118
|
}
|
|
72
119
|
}
|
|
73
|
-
}
|
|
120
|
+
};
|
|
121
|
+
const executionOptions = {
|
|
122
|
+
txNonce: Fr.random(),
|
|
123
|
+
cancellable: this.cancellableTransactions,
|
|
124
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
125
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
126
|
+
};
|
|
127
|
+
txRequest = await account.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
|
|
128
|
+
}
|
|
129
|
+
return this.pxe.simulateTx(txRequest, {
|
|
130
|
+
simulatePublic: true,
|
|
131
|
+
skipFeeEnforcement,
|
|
132
|
+
skipTxValidation,
|
|
133
|
+
overrides,
|
|
74
134
|
scopes
|
|
75
135
|
});
|
|
76
136
|
}
|
|
77
137
|
async getFakeAccountDataFor(address) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const originalAccount = await this.getAccountFromAddress(address);
|
|
84
|
-
if (originalAccount instanceof SignerlessAccount) {
|
|
85
|
-
throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
|
|
86
|
-
}
|
|
87
|
-
const originalAddress = originalAccount.getCompleteAddress();
|
|
88
|
-
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
89
|
-
if (!contractInstance) {
|
|
90
|
-
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
91
|
-
}
|
|
92
|
-
const stubAccount = await this.accountContracts.createStubAccount(originalAddress);
|
|
93
|
-
const stubArtifact = await this.accountContracts.getStubAccountContractArtifact();
|
|
94
|
-
const instance = await getContractInstanceFromInstantiationParams(stubArtifact, {
|
|
95
|
-
salt: Fr.random()
|
|
96
|
-
});
|
|
97
|
-
return {
|
|
98
|
-
account: stubAccount,
|
|
99
|
-
instance,
|
|
100
|
-
artifact: stubArtifact
|
|
101
|
-
};
|
|
102
|
-
} else {
|
|
103
|
-
const { instance, artifact } = await this.accountContracts.getMulticallContract();
|
|
104
|
-
const account = new SignerlessAccount();
|
|
105
|
-
return {
|
|
106
|
-
instance,
|
|
107
|
-
account,
|
|
108
|
-
artifact
|
|
109
|
-
};
|
|
138
|
+
const originalAccount = await this.getAccountFromAddress(address);
|
|
139
|
+
const originalAddress = originalAccount.getCompleteAddress();
|
|
140
|
+
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
141
|
+
if (!contractInstance) {
|
|
142
|
+
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
110
143
|
}
|
|
144
|
+
const stubAccount = await this.accountContracts.createStubAccount(originalAddress);
|
|
145
|
+
const stubArtifact = await this.accountContracts.getStubAccountContractArtifact();
|
|
146
|
+
const instance = await getContractInstanceFromInstantiationParams(stubArtifact, {
|
|
147
|
+
salt: Fr.random()
|
|
148
|
+
});
|
|
149
|
+
return {
|
|
150
|
+
account: stubAccount,
|
|
151
|
+
instance,
|
|
152
|
+
artifact: stubArtifact
|
|
153
|
+
};
|
|
111
154
|
}
|
|
112
155
|
async createAccountInternal(type, secret, salt, signingKey) {
|
|
113
156
|
let contract;
|
|
@@ -165,6 +208,9 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
165
208
|
setMinFeePadding(value) {
|
|
166
209
|
this.minFeePadding = value ?? 0.5;
|
|
167
210
|
}
|
|
211
|
+
setEstimatedGasPadding(value) {
|
|
212
|
+
this.estimatedGasPadding = value ?? DEFAULT_ESTIMATED_GAS_PADDING;
|
|
213
|
+
}
|
|
168
214
|
stop() {
|
|
169
215
|
return this.pxe.stop();
|
|
170
216
|
}
|
package/dest/testing.d.ts
CHANGED
|
@@ -9,4 +9,4 @@ interface WalletWithSchnorrAccounts {
|
|
|
9
9
|
export declare function deployFundedSchnorrAccounts(wallet: WalletWithSchnorrAccounts, accountsData: InitialAccountData[], waitOptions?: WaitOpts): Promise<AccountManager[]>;
|
|
10
10
|
export declare function registerInitialLocalNetworkAccountsInWallet(wallet: WalletWithSchnorrAccounts): Promise<AztecAddress[]>;
|
|
11
11
|
export {};
|
|
12
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
12
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3Rlc3RpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsa0JBQWtCLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUdsRSxPQUFPLEtBQUssRUFBRSxRQUFRLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQUMxRCxPQUFPLEtBQUssRUFBRSxjQUFjLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUM3RCxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDN0QsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBRTNELFVBQVUseUJBQXlCO0lBQ2pDLG9CQUFvQixDQUFDLE1BQU0sRUFBRSxFQUFFLEVBQUUsSUFBSSxFQUFFLEVBQUUsRUFBRSxVQUFVLENBQUMsRUFBRSxFQUFFLEVBQUUsS0FBSyxDQUFDLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxjQUFjLENBQUMsQ0FBQztDQUN0RztBQUVELHdCQUFzQiwyQkFBMkIsQ0FDL0MsTUFBTSxFQUFFLHlCQUF5QixFQUNqQyxZQUFZLEVBQUUsa0JBQWtCLEVBQUUsRUFDbEMsV0FBVyxDQUFDLEVBQUUsUUFBUSw2QkFnQnZCO0FBRUQsd0JBQXNCLDJDQUEyQyxDQUMvRCxNQUFNLEVBQUUseUJBQXlCLEdBQ2hDLE9BQU8sQ0FBQyxZQUFZLEVBQUUsQ0FBQyxDQU96QiJ9
|
package/dest/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAGlE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D,UAAU,yBAAyB;IACjC,oBAAoB,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CACtG;AAED,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,yBAAyB,EACjC,YAAY,EAAE,kBAAkB,EAAE,EAClC,WAAW,CAAC,EAAE,QAAQ,6BAgBvB;AAED,wBAAsB,2CAA2C,CAC/D,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,YAAY,EAAE,CAAC,CAOzB"}
|
package/dest/testing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getInitialTestAccountsData } from '@aztec/accounts/testing/lazy';
|
|
2
|
-
import {
|
|
2
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
3
3
|
export async function deployFundedSchnorrAccounts(wallet, accountsData, waitOptions) {
|
|
4
4
|
const accountManagers = [];
|
|
5
5
|
// Serial due to https://github.com/AztecProtocol/aztec-packages/issues/12045
|
|
@@ -8,7 +8,7 @@ export async function deployFundedSchnorrAccounts(wallet, accountsData, waitOpti
|
|
|
8
8
|
const accountManager = await wallet.createSchnorrAccount(secret, salt, signingKey);
|
|
9
9
|
const deployMethod = await accountManager.getDeployMethod();
|
|
10
10
|
await deployMethod.send({
|
|
11
|
-
from:
|
|
11
|
+
from: NO_FROM,
|
|
12
12
|
skipClassPublication: i !== 0,
|
|
13
13
|
wait: waitOptions
|
|
14
14
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/wallets",
|
|
3
3
|
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/wallets",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.2.0-aztecnr-rc.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./embedded": {
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"../package.common.json"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@aztec/accounts": "4.
|
|
31
|
-
"@aztec/aztec.js": "4.
|
|
32
|
-
"@aztec/entrypoints": "4.
|
|
33
|
-
"@aztec/foundation": "4.
|
|
34
|
-
"@aztec/kv-store": "4.
|
|
35
|
-
"@aztec/protocol-contracts": "4.
|
|
36
|
-
"@aztec/pxe": "4.
|
|
37
|
-
"@aztec/stdlib": "4.
|
|
38
|
-
"@aztec/wallet-sdk": "4.
|
|
30
|
+
"@aztec/accounts": "4.2.0-aztecnr-rc.2",
|
|
31
|
+
"@aztec/aztec.js": "4.2.0-aztecnr-rc.2",
|
|
32
|
+
"@aztec/entrypoints": "4.2.0-aztecnr-rc.2",
|
|
33
|
+
"@aztec/foundation": "4.2.0-aztecnr-rc.2",
|
|
34
|
+
"@aztec/kv-store": "4.2.0-aztecnr-rc.2",
|
|
35
|
+
"@aztec/protocol-contracts": "4.2.0-aztecnr-rc.2",
|
|
36
|
+
"@aztec/pxe": "4.2.0-aztecnr-rc.2",
|
|
37
|
+
"@aztec/stdlib": "4.2.0-aztecnr-rc.2",
|
|
38
|
+
"@aztec/wallet-sdk": "4.2.0-aztecnr-rc.2"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@jest/globals": "^30.0.0",
|
|
@@ -49,6 +49,15 @@
|
|
|
49
49
|
"src",
|
|
50
50
|
"!*.test.*"
|
|
51
51
|
],
|
|
52
|
+
"typedocOptions": {
|
|
53
|
+
"entryPoints": [
|
|
54
|
+
"./src/embedded/entrypoints/browser.ts",
|
|
55
|
+
"./src/embedded/entrypoints/node.ts",
|
|
56
|
+
"./src/testing.ts"
|
|
57
|
+
],
|
|
58
|
+
"name": "Wallets",
|
|
59
|
+
"tsconfig": "./tsconfig.json"
|
|
60
|
+
},
|
|
52
61
|
"engines": {
|
|
53
62
|
"node": ">=20.10"
|
|
54
63
|
},
|
|
@@ -1,17 +1,28 @@
|
|
|
1
|
-
import { type Account,
|
|
2
|
-
import
|
|
1
|
+
import { type Account, NO_FROM } from '@aztec/aztec.js/account';
|
|
2
|
+
import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import { type InteractionWaitOptions, type SendReturn, getGasLimits } from '@aztec/aztec.js/contracts';
|
|
4
|
+
import type { Aliased, SendOptions } from '@aztec/aztec.js/wallet';
|
|
3
5
|
import { AccountManager } from '@aztec/aztec.js/wallet';
|
|
4
6
|
import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
7
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
5
8
|
import { Fq, Fr } from '@aztec/foundation/curves/bn254';
|
|
6
9
|
import type { Logger } from '@aztec/foundation/log';
|
|
7
|
-
import type {
|
|
10
|
+
import type { PXEConfig, PXECreationOptions } from '@aztec/pxe/client/lazy';
|
|
8
11
|
import type { PXE } from '@aztec/pxe/server';
|
|
9
12
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
13
|
import { getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
|
|
14
|
+
import { GasSettings } from '@aztec/stdlib/gas';
|
|
11
15
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
12
16
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
13
|
-
import {
|
|
14
|
-
|
|
17
|
+
import {
|
|
18
|
+
ExecutionPayload,
|
|
19
|
+
SimulationOverrides,
|
|
20
|
+
type TxExecutionRequest,
|
|
21
|
+
type TxSimulationResult,
|
|
22
|
+
collectOffchainEffects,
|
|
23
|
+
mergeExecutionPayloads,
|
|
24
|
+
} from '@aztec/stdlib/tx';
|
|
25
|
+
import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
15
26
|
|
|
16
27
|
import type { AccountContractsProvider } from './account-contract-providers/types.js';
|
|
17
28
|
import { type AccountType, WalletDB } from './wallet_db.js';
|
|
@@ -27,7 +38,11 @@ export type EmbeddedWalletOptions = {
|
|
|
27
38
|
pxeOptions?: PXECreationOptions;
|
|
28
39
|
};
|
|
29
40
|
|
|
41
|
+
const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
|
|
42
|
+
|
|
30
43
|
export class EmbeddedWallet extends BaseWallet {
|
|
44
|
+
protected estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING;
|
|
45
|
+
|
|
31
46
|
constructor(
|
|
32
47
|
pxe: PXE,
|
|
33
48
|
aztecNode: AztecNode,
|
|
@@ -39,10 +54,6 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
39
54
|
}
|
|
40
55
|
|
|
41
56
|
protected async getAccountFromAddress(address: AztecAddress): Promise<Account> {
|
|
42
|
-
if (address.equals(AztecAddress.ZERO)) {
|
|
43
|
-
return new SignerlessAccount();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
57
|
const { secretKey, salt, signingKey, type } = await this.walletDB.retrieveAccount(address);
|
|
47
58
|
const accountManager = await this.createAccountInternal(type, secretKey, salt, signingKey);
|
|
48
59
|
const account = await accountManager.getAccount();
|
|
@@ -74,6 +85,66 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
74
85
|
return storedSenders;
|
|
75
86
|
}
|
|
76
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Overrides the base sendTx to add a pre-simulation step before the actual send. The simulation
|
|
90
|
+
* estimates actual gas usage and captures call authorization requests to generate
|
|
91
|
+
* the necessary authwitnesses.
|
|
92
|
+
*/
|
|
93
|
+
public override async sendTx<W extends InteractionWaitOptions = undefined>(
|
|
94
|
+
executionPayload: ExecutionPayload,
|
|
95
|
+
opts: SendOptions<W>,
|
|
96
|
+
): Promise<SendReturn<W>> {
|
|
97
|
+
const feeOptions = await this.completeFeeOptionsForEstimation(
|
|
98
|
+
opts.from,
|
|
99
|
+
executionPayload.feePayer,
|
|
100
|
+
opts.fee?.gasSettings,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
// Simulate the transaction first to estimate gas and capture required
|
|
104
|
+
// private authwitnesses based on offchain effects.
|
|
105
|
+
const simulationResult = await this.simulateViaEntrypoint(executionPayload, {
|
|
106
|
+
from: opts.from,
|
|
107
|
+
feeOptions,
|
|
108
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
109
|
+
skipTxValidation: true,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const offchainEffects = collectOffchainEffects(simulationResult.privateExecutionResult);
|
|
113
|
+
const authWitnesses = await Promise.all(
|
|
114
|
+
offchainEffects.map(async effect => {
|
|
115
|
+
try {
|
|
116
|
+
const authRequest = await CallAuthorizationRequest.fromFields(effect.data);
|
|
117
|
+
return this.createAuthWit(authRequest.onBehalfOf, {
|
|
118
|
+
consumer: effect.contractAddress,
|
|
119
|
+
innerHash: authRequest.innerHash,
|
|
120
|
+
});
|
|
121
|
+
} catch {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
}),
|
|
125
|
+
);
|
|
126
|
+
for (const authwit of authWitnesses) {
|
|
127
|
+
if (authwit) {
|
|
128
|
+
executionPayload.authWitnesses.push(authwit);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const estimated = getGasLimits(simulationResult, this.estimatedGasPadding);
|
|
132
|
+
this.log.verbose(
|
|
133
|
+
`Estimated gas limits for tx: DA=${estimated.gasLimits.daGas} L2=${estimated.gasLimits.l2Gas} teardownDA=${estimated.teardownGasLimits.daGas} teardownL2=${estimated.teardownGasLimits.l2Gas}`,
|
|
134
|
+
);
|
|
135
|
+
const gasSettings = GasSettings.from({
|
|
136
|
+
...opts.fee?.gasSettings,
|
|
137
|
+
maxFeesPerGas: feeOptions.gasSettings.maxFeesPerGas,
|
|
138
|
+
maxPriorityFeesPerGas: feeOptions.gasSettings.maxPriorityFeesPerGas,
|
|
139
|
+
gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
|
|
140
|
+
teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits,
|
|
141
|
+
});
|
|
142
|
+
return super.sendTx(executionPayload, {
|
|
143
|
+
...opts,
|
|
144
|
+
fee: { ...opts.fee, gasSettings },
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
77
148
|
/**
|
|
78
149
|
* Simulates calls via a stub account entrypoint, bypassing real account authorization.
|
|
79
150
|
* This allows kernelless simulation with contract overrides, skipping expensive
|
|
@@ -81,75 +152,66 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
81
152
|
*/
|
|
82
153
|
protected override async simulateViaEntrypoint(
|
|
83
154
|
executionPayload: ExecutionPayload,
|
|
84
|
-
|
|
85
|
-
feeOptions: FeeOptions,
|
|
86
|
-
scopes: AccessScopes,
|
|
87
|
-
_skipTxValidation?: boolean,
|
|
88
|
-
_skipFeeEnforcement?: boolean,
|
|
155
|
+
opts: SimulateViaEntrypointOptions,
|
|
89
156
|
): Promise<TxSimulationResult> {
|
|
90
|
-
const {
|
|
157
|
+
const { from, feeOptions, scopes, skipTxValidation, skipFeeEnforcement } = opts;
|
|
91
158
|
|
|
92
159
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
93
|
-
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
94
|
-
txNonce: Fr.random(),
|
|
95
|
-
cancellable: this.cancellableTransactions,
|
|
96
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
97
|
-
};
|
|
98
160
|
const finalExecutionPayload = feeExecutionPayload
|
|
99
161
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
100
162
|
: executionPayload;
|
|
101
163
|
const chainInfo = await this.getChainInfo();
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
164
|
+
|
|
165
|
+
let overrides: SimulationOverrides | undefined;
|
|
166
|
+
let txRequest: TxExecutionRequest;
|
|
167
|
+
if (from === NO_FROM) {
|
|
168
|
+
const entrypoint = new DefaultEntrypoint();
|
|
169
|
+
txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
170
|
+
} else {
|
|
171
|
+
const { account, instance, artifact } = await this.getFakeAccountDataFor(from);
|
|
172
|
+
overrides = {
|
|
173
|
+
contracts: { [from.toString()]: { instance, artifact } },
|
|
174
|
+
};
|
|
175
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
176
|
+
txNonce: Fr.random(),
|
|
177
|
+
cancellable: this.cancellableTransactions,
|
|
178
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
179
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
180
|
+
};
|
|
181
|
+
txRequest = await account.createTxExecutionRequest(
|
|
182
|
+
finalExecutionPayload,
|
|
183
|
+
feeOptions.gasSettings,
|
|
184
|
+
chainInfo,
|
|
185
|
+
executionOptions,
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
108
189
|
return this.pxe.simulateTx(txRequest, {
|
|
109
190
|
simulatePublic: true,
|
|
110
|
-
skipFeeEnforcement
|
|
111
|
-
skipTxValidation
|
|
112
|
-
overrides
|
|
113
|
-
contracts: { [from.toString()]: { instance, artifact } },
|
|
114
|
-
},
|
|
191
|
+
skipFeeEnforcement,
|
|
192
|
+
skipTxValidation,
|
|
193
|
+
overrides,
|
|
115
194
|
scopes,
|
|
116
195
|
});
|
|
117
196
|
}
|
|
118
197
|
|
|
119
198
|
private async getFakeAccountDataFor(address: AztecAddress) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const originalAccount = await this.getAccountFromAddress(address);
|
|
126
|
-
if (originalAccount instanceof SignerlessAccount) {
|
|
127
|
-
throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
|
|
128
|
-
}
|
|
129
|
-
const originalAddress = (originalAccount as Account).getCompleteAddress();
|
|
130
|
-
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
131
|
-
if (!contractInstance) {
|
|
132
|
-
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
133
|
-
}
|
|
134
|
-
const stubAccount = await this.accountContracts.createStubAccount(originalAddress);
|
|
135
|
-
const stubArtifact = await this.accountContracts.getStubAccountContractArtifact();
|
|
136
|
-
const instance = await getContractInstanceFromInstantiationParams(stubArtifact, {
|
|
137
|
-
salt: Fr.random(),
|
|
138
|
-
});
|
|
139
|
-
return {
|
|
140
|
-
account: stubAccount,
|
|
141
|
-
instance,
|
|
142
|
-
artifact: stubArtifact,
|
|
143
|
-
};
|
|
144
|
-
} else {
|
|
145
|
-
const { instance, artifact } = await this.accountContracts.getMulticallContract();
|
|
146
|
-
const account = new SignerlessAccount();
|
|
147
|
-
return {
|
|
148
|
-
instance,
|
|
149
|
-
account,
|
|
150
|
-
artifact,
|
|
151
|
-
};
|
|
199
|
+
const originalAccount = await this.getAccountFromAddress(address);
|
|
200
|
+
const originalAddress = originalAccount.getCompleteAddress();
|
|
201
|
+
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
202
|
+
if (!contractInstance) {
|
|
203
|
+
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
152
204
|
}
|
|
205
|
+
const stubAccount = await this.accountContracts.createStubAccount(originalAddress);
|
|
206
|
+
const stubArtifact = await this.accountContracts.getStubAccountContractArtifact();
|
|
207
|
+
const instance = await getContractInstanceFromInstantiationParams(stubArtifact, {
|
|
208
|
+
salt: Fr.random(),
|
|
209
|
+
});
|
|
210
|
+
return {
|
|
211
|
+
account: stubAccount,
|
|
212
|
+
instance,
|
|
213
|
+
artifact: stubArtifact,
|
|
214
|
+
};
|
|
153
215
|
}
|
|
154
216
|
|
|
155
217
|
protected async createAccountInternal(
|
|
@@ -221,6 +283,10 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
221
283
|
this.minFeePadding = value ?? 0.5;
|
|
222
284
|
}
|
|
223
285
|
|
|
286
|
+
setEstimatedGasPadding(value?: number) {
|
|
287
|
+
this.estimatedGasPadding = value ?? DEFAULT_ESTIMATED_GAS_PADDING;
|
|
288
|
+
}
|
|
289
|
+
|
|
224
290
|
stop() {
|
|
225
291
|
return this.pxe.stop();
|
|
226
292
|
}
|
package/src/testing.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { InitialAccountData } from '@aztec/accounts/testing';
|
|
2
2
|
import { getInitialTestAccountsData } from '@aztec/accounts/testing/lazy';
|
|
3
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
3
4
|
import type { WaitOpts } from '@aztec/aztec.js/contracts';
|
|
4
5
|
import type { AccountManager } from '@aztec/aztec.js/wallet';
|
|
5
6
|
import type { Fq, Fr } from '@aztec/foundation/curves/bn254';
|
|
@@ -21,7 +22,7 @@ export async function deployFundedSchnorrAccounts(
|
|
|
21
22
|
const accountManager = await wallet.createSchnorrAccount(secret, salt, signingKey);
|
|
22
23
|
const deployMethod = await accountManager.getDeployMethod();
|
|
23
24
|
await deployMethod.send({
|
|
24
|
-
from:
|
|
25
|
+
from: NO_FROM,
|
|
25
26
|
skipClassPublication: i !== 0,
|
|
26
27
|
wait: waitOptions,
|
|
27
28
|
});
|