@aztec/wallets 5.0.0-private.20260319 → 5.0.0-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/account-contract-providers/bundle.d.ts +6 -8
- package/dest/embedded/account-contract-providers/bundle.d.ts.map +1 -1
- package/dest/embedded/account-contract-providers/bundle.js +10 -10
- package/dest/embedded/account-contract-providers/lazy.d.ts +6 -8
- package/dest/embedded/account-contract-providers/lazy.d.ts.map +1 -1
- package/dest/embedded/account-contract-providers/lazy.js +20 -10
- package/dest/embedded/account-contract-providers/types.d.ts +6 -8
- package/dest/embedded/account-contract-providers/types.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.d.ts +54 -8
- package/dest/embedded/embedded_wallet.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.js +214 -68
- package/dest/embedded/entrypoints/browser.d.ts +2 -2
- package/dest/embedded/entrypoints/browser.d.ts.map +1 -1
- package/dest/embedded/entrypoints/browser.js +39 -10
- package/dest/embedded/entrypoints/node.d.ts +2 -2
- package/dest/embedded/entrypoints/node.d.ts.map +1 -1
- package/dest/embedded/entrypoints/node.js +33 -10
- package/dest/embedded/store_encryption.d.ts +67 -0
- package/dest/embedded/store_encryption.d.ts.map +1 -0
- package/dest/embedded/store_encryption.js +71 -0
- package/dest/embedded/wallet_db.d.ts +7 -6
- package/dest/embedded/wallet_db.d.ts.map +1 -1
- package/dest/embedded/wallet_db.js +12 -11
- package/dest/testing.d.ts +8 -4
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +8 -14
- package/package.json +12 -10
- package/src/embedded/account-contract-providers/bundle.ts +13 -12
- package/src/embedded/account-contract-providers/lazy.ts +23 -12
- package/src/embedded/account-contract-providers/types.ts +6 -4
- package/src/embedded/embedded_wallet.ts +271 -75
- package/src/embedded/entrypoints/browser.ts +47 -20
- package/src/embedded/entrypoints/node.ts +46 -26
- package/src/embedded/store_encryption.ts +107 -0
- package/src/embedded/wallet_db.ts +15 -12
- package/src/testing.ts +11 -16
|
@@ -1,38 +1,96 @@
|
|
|
1
|
-
import { type Account,
|
|
1
|
+
import { type Account, NO_FROM } from '@aztec/aztec.js/account';
|
|
2
2
|
import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import {
|
|
4
|
+
ContractFunctionInteraction,
|
|
5
|
+
type InteractionWaitOptions,
|
|
6
|
+
NO_WAIT,
|
|
7
|
+
type SendReturn,
|
|
8
|
+
type WaitOpts,
|
|
9
|
+
} from '@aztec/aztec.js/contracts';
|
|
10
|
+
import type {
|
|
11
|
+
Aliased,
|
|
12
|
+
ExecuteUtilityOptions,
|
|
13
|
+
PrivateEvent,
|
|
14
|
+
PrivateEventFilter,
|
|
15
|
+
ProfileOptions,
|
|
16
|
+
SendOptions,
|
|
17
|
+
SimulateOptions,
|
|
18
|
+
} from '@aztec/aztec.js/wallet';
|
|
19
|
+
import { AccountManager, TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
6
20
|
import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
21
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
22
|
+
import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
|
|
23
|
+
import { Schnorr } from '@aztec/foundation/crypto/schnorr';
|
|
7
24
|
import { Fq, Fr } from '@aztec/foundation/curves/bn254';
|
|
8
25
|
import type { Logger } from '@aztec/foundation/log';
|
|
26
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
9
27
|
import type { PXEConfig, PXECreationOptions } from '@aztec/pxe/client/lazy';
|
|
10
28
|
import type { PXE } from '@aztec/pxe/server';
|
|
29
|
+
import type { ContractArtifact, EventMetadataDefinition, FunctionCall } from '@aztec/stdlib/abi';
|
|
11
30
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
12
|
-
import {
|
|
31
|
+
import { type ContractInstanceWithAddress, getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
13
32
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
14
33
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
15
34
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
16
35
|
import {
|
|
36
|
+
type ContractOverrides,
|
|
17
37
|
ExecutionPayload,
|
|
18
38
|
SimulationOverrides,
|
|
19
|
-
type
|
|
39
|
+
type TxExecutionRequest,
|
|
40
|
+
type TxProfileResult,
|
|
41
|
+
TxStatus,
|
|
42
|
+
type UtilityExecutionResult,
|
|
20
43
|
collectOffchainEffects,
|
|
21
44
|
mergeExecutionPayloads,
|
|
22
45
|
} from '@aztec/stdlib/tx';
|
|
23
|
-
import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
46
|
+
import { BaseWallet, type SimulateViaEntrypointOptions, getGasLimits } from '@aztec/wallet-sdk/base-wallet';
|
|
24
47
|
|
|
25
48
|
import type { AccountContractsProvider } from './account-contract-providers/types.js';
|
|
26
49
|
import { type AccountType, WalletDB } from './wallet_db.js';
|
|
27
50
|
|
|
51
|
+
/** Options for the PXE instance created by the EmbeddedWallet. */
|
|
52
|
+
export type EmbeddedWalletPXEOptions = Partial<PXEConfig> & PXECreationOptions;
|
|
53
|
+
|
|
54
|
+
/** Splits a unified EmbeddedWalletPXEOptions into PXEConfig overrides and PXECreationOptions. */
|
|
55
|
+
export function splitPxeOptions(pxe?: EmbeddedWalletPXEOptions): {
|
|
56
|
+
config: Partial<PXEConfig>;
|
|
57
|
+
creation: PXECreationOptions;
|
|
58
|
+
} {
|
|
59
|
+
if (!pxe) {
|
|
60
|
+
return { config: {}, creation: {} };
|
|
61
|
+
}
|
|
62
|
+
const { loggers, loggerActorLabel, proverOrOptions, store, simulator, hooks, preloadedContractsProvider, ...config } =
|
|
63
|
+
pxe;
|
|
64
|
+
return {
|
|
65
|
+
config,
|
|
66
|
+
creation: { loggers, loggerActorLabel, proverOrOptions, store, simulator, hooks, preloadedContractsProvider },
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Options for the EmbeddedWallet's own DB (accounts, senders — distinct from PXE state). */
|
|
71
|
+
export type EmbeddedWalletDBOptions = {
|
|
72
|
+
/** Override the wallet DB backend. If omitted, an IndexedDB (browser) / LMDB (node) store is created. */
|
|
73
|
+
store?: AztecAsyncKVStore;
|
|
74
|
+
};
|
|
75
|
+
|
|
28
76
|
export type EmbeddedWalletOptions = {
|
|
29
77
|
/** Parent logger. Child loggers are derived via createChild() for each subsystem. */
|
|
30
78
|
logger?: Logger;
|
|
31
79
|
/** Use ephemeral (in-memory) stores. Data will not persist across sessions. */
|
|
32
80
|
ephemeral?: boolean;
|
|
33
|
-
/**
|
|
81
|
+
/** PXE configuration and dependency overrides (custom store, prover, simulator). */
|
|
82
|
+
pxe?: EmbeddedWalletPXEOptions;
|
|
83
|
+
/** Wallet DB dependency overrides (custom store). */
|
|
84
|
+
walletDb?: EmbeddedWalletDBOptions;
|
|
85
|
+
/**
|
|
86
|
+
* Override PXE configuration.
|
|
87
|
+
* @deprecated Use `pxe` instead.
|
|
88
|
+
*/
|
|
34
89
|
pxeConfig?: Partial<PXEConfig>;
|
|
35
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* Advanced PXE creation options (custom store, prover, simulator).
|
|
92
|
+
* @deprecated Use `pxe` instead.
|
|
93
|
+
*/
|
|
36
94
|
pxeOptions?: PXECreationOptions;
|
|
37
95
|
};
|
|
38
96
|
|
|
@@ -41,6 +99,10 @@ const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
|
|
|
41
99
|
export class EmbeddedWallet extends BaseWallet {
|
|
42
100
|
protected estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING;
|
|
43
101
|
|
|
102
|
+
// Stub class ids, populated on wallet startup
|
|
103
|
+
// to avoid redundant work per simulation
|
|
104
|
+
protected stubClassIds = new Map<AccountType, Fr>();
|
|
105
|
+
|
|
44
106
|
constructor(
|
|
45
107
|
pxe: PXE,
|
|
46
108
|
aztecNode: AztecNode,
|
|
@@ -52,10 +114,6 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
52
114
|
}
|
|
53
115
|
|
|
54
116
|
protected async getAccountFromAddress(address: AztecAddress): Promise<Account> {
|
|
55
|
-
if (address.equals(AztecAddress.ZERO)) {
|
|
56
|
-
return new SignerlessAccount();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
117
|
const { secretKey, salt, signingKey, type } = await this.walletDB.retrieveAccount(address);
|
|
60
118
|
const accountManager = await this.createAccountInternal(type, secretKey, salt, signingKey);
|
|
61
119
|
const account = await accountManager.getAccount();
|
|
@@ -73,15 +131,17 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
73
131
|
|
|
74
132
|
override async registerSender(address: AztecAddress, alias: string) {
|
|
75
133
|
await this.walletDB.storeSender(address, alias);
|
|
76
|
-
|
|
134
|
+
await this.pxe.registerTaggingSecretSource({ kind: 'address-derived', sender: address });
|
|
135
|
+
return address;
|
|
77
136
|
}
|
|
78
137
|
|
|
79
138
|
override async getAddressBook(): Promise<Aliased<AztecAddress>[]> {
|
|
80
|
-
const
|
|
139
|
+
const sources = await this.pxe.getTaggingSecretSources({ kind: 'address-derived' });
|
|
140
|
+
const senders = sources.map(source => source.sender);
|
|
81
141
|
const storedSenders = await this.walletDB.listSenders();
|
|
82
142
|
for (const storedSender of storedSenders) {
|
|
83
143
|
if (senders.findIndex(sender => sender.equals(storedSender.item)) === -1) {
|
|
84
|
-
await this.pxe.
|
|
144
|
+
await this.pxe.registerTaggingSecretSource({ kind: 'address-derived', sender: storedSender.item });
|
|
85
145
|
}
|
|
86
146
|
}
|
|
87
147
|
return storedSenders;
|
|
@@ -96,19 +156,24 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
96
156
|
executionPayload: ExecutionPayload,
|
|
97
157
|
opts: SendOptions<W>,
|
|
98
158
|
): Promise<SendReturn<W>> {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
159
|
+
// PXE has autoSync disabled by the embedded wallet entrypoints, so we sync once here to cover
|
|
160
|
+
// both the inner simulateTx (via simulateViaEntrypoint) and the proveTx that super.sendTx
|
|
161
|
+
await this.pxe.sync();
|
|
162
|
+
const feeOptions = await this.completeFeeOptions({
|
|
163
|
+
from: opts.from,
|
|
164
|
+
feePayer: executionPayload.feePayer,
|
|
165
|
+
gasSettings: opts.fee?.gasSettings,
|
|
166
|
+
forEstimation: true,
|
|
167
|
+
});
|
|
104
168
|
|
|
105
169
|
// Simulate the transaction first to estimate gas and capture required
|
|
106
170
|
// private authwitnesses based on offchain effects.
|
|
107
171
|
const simulationResult = await this.simulateViaEntrypoint(executionPayload, {
|
|
108
172
|
from: opts.from,
|
|
109
173
|
feeOptions,
|
|
110
|
-
|
|
174
|
+
additionalScopes: opts.additionalScopes,
|
|
111
175
|
skipTxValidation: true,
|
|
176
|
+
sendMessagesAs: opts.sendMessagesAs,
|
|
112
177
|
});
|
|
113
178
|
|
|
114
179
|
const offchainEffects = collectOffchainEffects(simulationResult.privateExecutionResult);
|
|
@@ -116,7 +181,7 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
116
181
|
offchainEffects.map(async effect => {
|
|
117
182
|
try {
|
|
118
183
|
const authRequest = await CallAuthorizationRequest.fromFields(effect.data);
|
|
119
|
-
return this.createAuthWit(
|
|
184
|
+
return this.createAuthWit(authRequest.onBehalfOf, {
|
|
120
185
|
consumer: effect.contractAddress,
|
|
121
186
|
innerHash: authRequest.innerHash,
|
|
122
187
|
});
|
|
@@ -130,7 +195,8 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
130
195
|
executionPayload.authWitnesses.push(authwit);
|
|
131
196
|
}
|
|
132
197
|
}
|
|
133
|
-
const
|
|
198
|
+
const maxTxGasLimits = await this.getMaxTxGasLimits();
|
|
199
|
+
const estimated = getGasLimits(simulationResult.gasUsed, maxTxGasLimits, this.estimatedGasPadding);
|
|
134
200
|
this.log.verbose(
|
|
135
201
|
`Estimated gas limits for tx: DA=${estimated.gasLimits.daGas} L2=${estimated.gasLimits.l2Gas} teardownDA=${estimated.teardownGasLimits.daGas} teardownL2=${estimated.teardownGasLimits.l2Gas}`,
|
|
136
202
|
);
|
|
@@ -141,12 +207,130 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
141
207
|
gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
|
|
142
208
|
teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits,
|
|
143
209
|
});
|
|
210
|
+
let wait: InteractionWaitOptions = opts.wait;
|
|
211
|
+
if (wait !== NO_WAIT) {
|
|
212
|
+
const callerWaitOpts: WaitOpts = typeof wait === 'object' ? wait : {};
|
|
213
|
+
wait = {
|
|
214
|
+
...callerWaitOpts,
|
|
215
|
+
// Default to PROPOSED so the wait returns as soon as the tx lands in a proposed L2 block,
|
|
216
|
+
// rather than waiting until the end of the slot for the checkpoint to be published to L1.
|
|
217
|
+
// This is what makes MBPS (Multiple Blocks Per Slot) actually improve UX: with CHECKPOINTED
|
|
218
|
+
// we'd block until L1 inclusion regardless of how early in the slot the tx was sequenced.
|
|
219
|
+
// The tradeoff is a weaker guarantee — a proposed block only becomes canonical once it (or
|
|
220
|
+
// a later block in the same slot) is checkpointed, so a tx could be re-orged out if the
|
|
221
|
+
// proposer fails to publish to L1 (which should be rare, since they'd get slashed for it).
|
|
222
|
+
waitForStatus: callerWaitOpts.waitForStatus ?? TxStatus.PROPOSED,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
144
225
|
return super.sendTx(executionPayload, {
|
|
145
226
|
...opts,
|
|
227
|
+
wait: wait as W,
|
|
146
228
|
fee: { ...opts.fee, gasSettings },
|
|
147
229
|
});
|
|
148
230
|
}
|
|
149
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Overrides the base simulateTx to drive PXE syncing explicitly. The PXE created by the embedded
|
|
234
|
+
* wallet has autoSync disabled (so we can share one sync across simulate+send in sendTx); for
|
|
235
|
+
* standalone simulations we still need a fresh anchor block, which we provide here.
|
|
236
|
+
*/
|
|
237
|
+
public override async simulateTx(
|
|
238
|
+
executionPayload: ExecutionPayload,
|
|
239
|
+
opts: SimulateOptions,
|
|
240
|
+
): Promise<TxSimulationResultWithAppOffset> {
|
|
241
|
+
await this.pxe.sync();
|
|
242
|
+
return super.simulateTx(executionPayload, opts);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
public override async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
|
|
246
|
+
await this.pxe.sync();
|
|
247
|
+
return super.profileTx(executionPayload, opts);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
public override async executeUtility(
|
|
251
|
+
call: FunctionCall,
|
|
252
|
+
opts: ExecuteUtilityOptions,
|
|
253
|
+
): Promise<UtilityExecutionResult> {
|
|
254
|
+
await this.pxe.sync();
|
|
255
|
+
return super.executeUtility(call, opts);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
public override async getPrivateEvents<T>(
|
|
259
|
+
eventDef: EventMetadataDefinition,
|
|
260
|
+
eventFilter: PrivateEventFilter,
|
|
261
|
+
): Promise<PrivateEvent<T>[]> {
|
|
262
|
+
await this.pxe.sync();
|
|
263
|
+
return super.getPrivateEvents<T>(eventDef, eventFilter);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
public override async registerContract(
|
|
267
|
+
instance: ContractInstanceWithAddress,
|
|
268
|
+
artifact?: ContractArtifact,
|
|
269
|
+
secretKey?: Fr,
|
|
270
|
+
): Promise<ContractInstanceWithAddress> {
|
|
271
|
+
// registerContract may call pxe.updateContract under the hood, which depends on a fresh anchor
|
|
272
|
+
// block to verify the current class id from the node.
|
|
273
|
+
await this.pxe.sync();
|
|
274
|
+
return super.registerContract(instance, artifact, secretKey);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Hashes and registers the stub class for every supported account type with PXE, populating
|
|
279
|
+
* stubClassIds. Called on wallet initialization.
|
|
280
|
+
*/
|
|
281
|
+
async initStubClasses(): Promise<void> {
|
|
282
|
+
const schnorrArtifact = await this.accountContracts.getStubAccountContractArtifact('schnorr');
|
|
283
|
+
const { id: schnorrClassId } = await getContractClassFromArtifact(schnorrArtifact);
|
|
284
|
+
await this.pxe.registerContractClass(schnorrArtifact);
|
|
285
|
+
|
|
286
|
+
// ecdsa stubs share the same class id
|
|
287
|
+
const ecdsaArtifact = await this.accountContracts.getStubAccountContractArtifact('ecdsasecp256r1');
|
|
288
|
+
const { id: ecdsaClassId } = await getContractClassFromArtifact(ecdsaArtifact);
|
|
289
|
+
await this.pxe.registerContractClass(ecdsaArtifact);
|
|
290
|
+
|
|
291
|
+
this.stubClassIds.set('schnorr', schnorrClassId);
|
|
292
|
+
this.stubClassIds.set('schnorr_initializerless', schnorrClassId);
|
|
293
|
+
this.stubClassIds.set('ecdsasecp256k1', ecdsaClassId);
|
|
294
|
+
this.stubClassIds.set('ecdsasecp256r1', ecdsaClassId);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Builds contract overrides for all provided addresses by replacing their account contracts with stub implementations.
|
|
299
|
+
* Uses a type-specific stub artifact so that the stub's constructor selector matches the real account's constructor.
|
|
300
|
+
*/
|
|
301
|
+
protected async buildAccountOverrides(addresses: AztecAddress[]): Promise<ContractOverrides> {
|
|
302
|
+
const accounts = await this.getAccounts();
|
|
303
|
+
const contracts: ContractOverrides = {};
|
|
304
|
+
|
|
305
|
+
const filtered = accounts.filter(acc => addresses.some(addr => addr.equals(acc.item)));
|
|
306
|
+
|
|
307
|
+
for (const account of filtered) {
|
|
308
|
+
const address = account.item;
|
|
309
|
+
const { type } = await this.walletDB.retrieveAccount(address);
|
|
310
|
+
const stubClassId = this.stubClassIds.get(type);
|
|
311
|
+
if (!stubClassId) {
|
|
312
|
+
throw new Error(
|
|
313
|
+
`Stub class for account type '${type}' was not registered at wallet init. This is a bug — initStubClasses should cover every supported AccountType.`,
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const originalAccount = await this.getAccountFromAddress(address);
|
|
318
|
+
const completeAddress = originalAccount.getCompleteAddress();
|
|
319
|
+
const contractInstance = await this.pxe.getContractInstance(completeAddress.address);
|
|
320
|
+
if (!contractInstance) {
|
|
321
|
+
throw new Error(
|
|
322
|
+
`No contract instance found for address: ${completeAddress.address} during account override building. This is a bug!`,
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
contracts[address.toString()] = {
|
|
327
|
+
instance: { ...contractInstance, currentContractClassId: stubClassId },
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return contracts;
|
|
332
|
+
}
|
|
333
|
+
|
|
150
334
|
/**
|
|
151
335
|
* Simulates calls via a stub account entrypoint, bypassing real account authorization.
|
|
152
336
|
* This allows kernelless simulation with contract overrides, skipping expensive
|
|
@@ -155,66 +339,52 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
155
339
|
protected override async simulateViaEntrypoint(
|
|
156
340
|
executionPayload: ExecutionPayload,
|
|
157
341
|
opts: SimulateViaEntrypointOptions,
|
|
158
|
-
): Promise<
|
|
159
|
-
const { from, feeOptions,
|
|
160
|
-
|
|
161
|
-
let overrides: SimulationOverrides | undefined;
|
|
162
|
-
let fromAccount: Account;
|
|
163
|
-
if (!from.equals(AztecAddress.ZERO)) {
|
|
164
|
-
const { account, instance, artifact } = await this.getFakeAccountDataFor(from);
|
|
165
|
-
fromAccount = account;
|
|
166
|
-
overrides = {
|
|
167
|
-
contracts: { [from.toString()]: { instance, artifact } },
|
|
168
|
-
};
|
|
169
|
-
} else {
|
|
170
|
-
fromAccount = await this.getAccountFromAddress(from);
|
|
171
|
-
}
|
|
342
|
+
): Promise<TxSimulationResultWithAppOffset> {
|
|
343
|
+
const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement, sendMessagesAs } = opts;
|
|
344
|
+
const scopes = this.scopesFrom(from, additionalScopes);
|
|
172
345
|
|
|
173
346
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
174
|
-
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
175
|
-
txNonce: Fr.random(),
|
|
176
|
-
cancellable: this.cancellableTransactions,
|
|
177
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
178
|
-
};
|
|
179
347
|
const finalExecutionPayload = feeExecutionPayload
|
|
180
348
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
181
349
|
: executionPayload;
|
|
182
350
|
const chainInfo = await this.getChainInfo();
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
)
|
|
189
|
-
|
|
351
|
+
|
|
352
|
+
const accountOverrides = await this.buildAccountOverrides(scopes);
|
|
353
|
+
const overrides = new SimulationOverrides({ contracts: accountOverrides });
|
|
354
|
+
|
|
355
|
+
let txRequest: TxExecutionRequest;
|
|
356
|
+
if (from === NO_FROM) {
|
|
357
|
+
const entrypoint = new DefaultEntrypoint();
|
|
358
|
+
txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
359
|
+
} else {
|
|
360
|
+
const { type } = await this.walletDB.retrieveAccount(from);
|
|
361
|
+
const originalAccount = await this.getAccountFromAddress(from);
|
|
362
|
+
const completeAddress = originalAccount.getCompleteAddress();
|
|
363
|
+
const account = await this.accountContracts.createStubAccount(completeAddress, type);
|
|
364
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
365
|
+
txNonce: Fr.random(),
|
|
366
|
+
cancellable: this.cancellableTransactions,
|
|
367
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
368
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
369
|
+
};
|
|
370
|
+
txRequest = await account.createTxExecutionRequest(
|
|
371
|
+
finalExecutionPayload,
|
|
372
|
+
feeOptions.gasSettings,
|
|
373
|
+
chainInfo,
|
|
374
|
+
executionOptions,
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
190
379
|
simulatePublic: true,
|
|
191
380
|
skipFeeEnforcement,
|
|
192
381
|
skipTxValidation,
|
|
193
382
|
overrides,
|
|
194
383
|
scopes,
|
|
384
|
+
senderForTags: this.senderForTagsFrom(from, sendMessagesAs),
|
|
195
385
|
});
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
private async getFakeAccountDataFor(address: AztecAddress) {
|
|
199
|
-
const originalAccount = await this.getAccountFromAddress(address);
|
|
200
|
-
if (originalAccount instanceof SignerlessAccount) {
|
|
201
|
-
throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
|
|
202
|
-
}
|
|
203
|
-
const originalAddress = (originalAccount as Account).getCompleteAddress();
|
|
204
|
-
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
205
|
-
if (!contractInstance) {
|
|
206
|
-
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
207
|
-
}
|
|
208
|
-
const stubAccount = await this.accountContracts.createStubAccount(originalAddress);
|
|
209
|
-
const stubArtifact = await this.accountContracts.getStubAccountContractArtifact();
|
|
210
|
-
const instance = await getContractInstanceFromInstantiationParams(stubArtifact, {
|
|
211
|
-
salt: Fr.random(),
|
|
212
|
-
});
|
|
213
|
-
return {
|
|
214
|
-
account: stubAccount,
|
|
215
|
-
instance,
|
|
216
|
-
artifact: stubArtifact,
|
|
217
|
-
};
|
|
386
|
+
const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
|
|
387
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
218
388
|
}
|
|
219
389
|
|
|
220
390
|
protected async createAccountInternal(
|
|
@@ -224,11 +394,19 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
224
394
|
signingKey: Buffer,
|
|
225
395
|
): Promise<AccountManager> {
|
|
226
396
|
let contract;
|
|
397
|
+
let immutablesHash;
|
|
398
|
+
let publicKey;
|
|
227
399
|
switch (type) {
|
|
228
400
|
case 'schnorr': {
|
|
229
401
|
contract = await this.accountContracts.getSchnorrAccountContract(Fq.fromBuffer(signingKey));
|
|
230
402
|
break;
|
|
231
403
|
}
|
|
404
|
+
case 'schnorr_initializerless': {
|
|
405
|
+
contract = await this.accountContracts.getSchnorrInitializerlessAccountContract(Fq.fromBuffer(signingKey));
|
|
406
|
+
publicKey = await new Schnorr().computePublicKey(Fq.fromBuffer(signingKey));
|
|
407
|
+
immutablesHash = await poseidon2Hash([publicKey.x, publicKey.y]);
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
232
410
|
case 'ecdsasecp256k1': {
|
|
233
411
|
contract = await this.accountContracts.getEcdsaKAccountContract(signingKey);
|
|
234
412
|
break;
|
|
@@ -242,17 +420,29 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
242
420
|
}
|
|
243
421
|
}
|
|
244
422
|
|
|
245
|
-
const accountManager = await AccountManager.create(this, secret, contract, salt);
|
|
423
|
+
const accountManager = await AccountManager.create(this, secret, contract, { salt, immutablesHash });
|
|
246
424
|
|
|
247
425
|
const instance = accountManager.getInstance();
|
|
248
426
|
const existingInstance = await this.pxe.getContractInstance(instance.address);
|
|
249
427
|
if (!existingInstance) {
|
|
250
428
|
const existingArtifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
429
|
+
const artifact = existingArtifact ?? (await accountManager.getAccountContract().getContractArtifact());
|
|
251
430
|
await this.registerContract(
|
|
252
431
|
instance,
|
|
253
432
|
!existingArtifact ? await accountManager.getAccountContract().getContractArtifact() : undefined,
|
|
254
433
|
accountManager.getSecretKey(),
|
|
255
434
|
);
|
|
435
|
+
if (type === 'schnorr_initializerless') {
|
|
436
|
+
const constructor = artifact.functions.find(f => f.name === 'constructor');
|
|
437
|
+
if (!constructor) {
|
|
438
|
+
throw new Error('Could not create SchnorrInitializerlessAccountContract: constructor ABI not found');
|
|
439
|
+
}
|
|
440
|
+
const storeCall = new ContractFunctionInteraction(this, instance.address, constructor, [
|
|
441
|
+
publicKey!.x,
|
|
442
|
+
publicKey!.y,
|
|
443
|
+
]);
|
|
444
|
+
await storeCall.simulate({ from: instance.address });
|
|
445
|
+
}
|
|
256
446
|
}
|
|
257
447
|
return accountManager;
|
|
258
448
|
}
|
|
@@ -274,6 +464,11 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
274
464
|
return this.createAndStoreAccount(alias ?? '', 'schnorr', secret, salt, sk.toBuffer());
|
|
275
465
|
}
|
|
276
466
|
|
|
467
|
+
createSchnorrInitializerlessAccount(secret: Fr, salt: Fr, signingKey?: Fq, alias?: string): Promise<AccountManager> {
|
|
468
|
+
const sk = signingKey ?? deriveSigningKey(secret);
|
|
469
|
+
return this.createAndStoreAccount(alias ?? '', 'schnorr_initializerless', secret, salt, sk.toBuffer());
|
|
470
|
+
}
|
|
471
|
+
|
|
277
472
|
createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer, alias?: string): Promise<AccountManager> {
|
|
278
473
|
return this.createAndStoreAccount(alias ?? '', 'ecdsasecp256r1', secret, salt, signingKey);
|
|
279
474
|
}
|
|
@@ -290,7 +485,8 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
290
485
|
this.estimatedGasPadding = value ?? DEFAULT_ESTIMATED_GAS_PADDING;
|
|
291
486
|
}
|
|
292
487
|
|
|
293
|
-
stop() {
|
|
294
|
-
|
|
488
|
+
async stop(): Promise<void> {
|
|
489
|
+
await this.pxe.stop();
|
|
490
|
+
await this.walletDB.close();
|
|
295
491
|
}
|
|
296
492
|
}
|
|
@@ -3,10 +3,13 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
|
3
3
|
import { createStore, openTmpStore } from '@aztec/kv-store/indexeddb';
|
|
4
4
|
import { type PXE, type PXECreationOptions, createPXE } from '@aztec/pxe/client/lazy';
|
|
5
5
|
import { type PXEConfig, getPXEConfig } from '@aztec/pxe/config';
|
|
6
|
+
import { getStandardAuthRegistry } from '@aztec/standard-contracts/auth-registry/lazy';
|
|
7
|
+
import { getStandardHandshakeRegistry } from '@aztec/standard-contracts/handshake-registry/lazy';
|
|
8
|
+
import { getStandardMultiCallEntrypoint } from '@aztec/standard-contracts/multi-call-entrypoint/lazy';
|
|
6
9
|
|
|
7
10
|
import { LazyAccountContractsProvider } from '../account-contract-providers/lazy.js';
|
|
8
11
|
import type { AccountContractsProvider } from '../account-contract-providers/types.js';
|
|
9
|
-
import { EmbeddedWallet, type EmbeddedWalletOptions } from '../embedded_wallet.js';
|
|
12
|
+
import { EmbeddedWallet, type EmbeddedWalletOptions, splitPxeOptions } from '../embedded_wallet.js';
|
|
10
13
|
import { WalletDB } from '../wallet_db.js';
|
|
11
14
|
|
|
12
15
|
export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
@@ -26,10 +29,16 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
|
26
29
|
const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
|
|
27
30
|
const l1Contracts = await aztecNode.getL1ContractAddresses();
|
|
28
31
|
|
|
32
|
+
// Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
|
|
33
|
+
const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
|
|
34
|
+
const mergedConfigOverrides = { ...options.pxeConfig, ...pxeConfigFromPxe };
|
|
35
|
+
const mergedCreationOverrides: PXECreationOptions = { ...options.pxeOptions, ...pxeCreationFromPxe };
|
|
36
|
+
|
|
29
37
|
const pxeConfig: PXEConfig = Object.assign(getPXEConfig(), {
|
|
30
|
-
proverEnabled:
|
|
38
|
+
proverEnabled: mergedConfigOverrides.proverEnabled,
|
|
31
39
|
dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
|
|
32
|
-
|
|
40
|
+
autoSync: false,
|
|
41
|
+
...mergedConfigOverrides,
|
|
33
42
|
});
|
|
34
43
|
|
|
35
44
|
if (options.ephemeral) {
|
|
@@ -37,36 +46,54 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
|
37
46
|
}
|
|
38
47
|
|
|
39
48
|
const pxeOptions: PXECreationOptions = {
|
|
40
|
-
...
|
|
49
|
+
...mergedCreationOverrides,
|
|
50
|
+
preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
|
|
51
|
+
getPreloadedContracts: async () => [
|
|
52
|
+
await getStandardMultiCallEntrypoint(),
|
|
53
|
+
await getStandardAuthRegistry(),
|
|
54
|
+
await getStandardHandshakeRegistry(),
|
|
55
|
+
],
|
|
56
|
+
},
|
|
41
57
|
loggers: {
|
|
42
58
|
store: rootLogger.createChild('pxe:data'),
|
|
43
59
|
pxe: rootLogger.createChild('pxe:service'),
|
|
44
60
|
prover: rootLogger.createChild('pxe:prover'),
|
|
45
|
-
...
|
|
61
|
+
...mergedCreationOverrides.loggers,
|
|
46
62
|
},
|
|
47
63
|
};
|
|
48
64
|
|
|
49
65
|
const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
|
|
50
66
|
|
|
51
|
-
const walletDBStore =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
const walletDBStore =
|
|
68
|
+
options.walletDb?.store ??
|
|
69
|
+
(options.ephemeral
|
|
70
|
+
? await openTmpStore(true)
|
|
71
|
+
: await createStore(
|
|
72
|
+
'wallet_data',
|
|
73
|
+
{
|
|
74
|
+
dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
|
|
75
|
+
dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
|
|
76
|
+
rollupAddress: l1Contracts.rollupAddress,
|
|
77
|
+
},
|
|
78
|
+
1,
|
|
79
|
+
rootLogger.createChild('wallet:data'),
|
|
80
|
+
));
|
|
81
|
+
const walletDB = new WalletDB(walletDBStore, rootLogger.createChild('wallet:db').info);
|
|
64
82
|
|
|
65
|
-
|
|
83
|
+
const wallet = new this(pxe, aztecNode, walletDB, new LazyAccountContractsProvider(), rootLogger) as T;
|
|
84
|
+
await wallet.initStubClasses();
|
|
85
|
+
return wallet;
|
|
66
86
|
}
|
|
67
87
|
}
|
|
68
88
|
|
|
69
89
|
export { BrowserEmbeddedWallet as EmbeddedWallet };
|
|
70
|
-
export type { EmbeddedWalletOptions } from '../embedded_wallet.js';
|
|
90
|
+
export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
|
|
71
91
|
export { WalletDB } from '../wallet_db.js';
|
|
72
92
|
export type { AccountType } from '../wallet_db.js';
|
|
93
|
+
|
|
94
|
+
// At-rest encryption helpers are intentionally NOT re-exported here. They live
|
|
95
|
+
// on the `@aztec/wallets/embedded/store-encryption` sub-path so consumers
|
|
96
|
+
// (and bundlers) of this entrypoint don't transitively pull in
|
|
97
|
+
// `@aztec/kv-store/sqlite-opfs` and its `new Worker(new URL('./worker.js'))`
|
|
98
|
+
// chain into `@aztec/sqlite3mc-wasm`. Apps that don't use encryption-at-rest
|
|
99
|
+
// (e.g. the playground) should never see sqlite-opfs in their bundle.
|