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