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