@aztec/wallets 0.0.1-commit.9ef841308 → 0.0.1-commit.a4600f49
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 +52 -8
- package/dest/embedded/embedded_wallet.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.js +192 -47
- 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 +34 -11
- 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 +236 -48
- package/src/embedded/entrypoints/browser.ts +41 -21
- 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 -17
|
@@ -1,40 +1,96 @@
|
|
|
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
34
|
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
|
+
/**
|
|
86
|
+
* Override PXE configuration.
|
|
87
|
+
* @deprecated Use `pxe` instead.
|
|
88
|
+
*/
|
|
36
89
|
pxeConfig?: Partial<PXEConfig>;
|
|
37
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* Advanced PXE creation options (custom store, prover, simulator).
|
|
92
|
+
* @deprecated Use `pxe` instead.
|
|
93
|
+
*/
|
|
38
94
|
pxeOptions?: PXECreationOptions;
|
|
39
95
|
};
|
|
40
96
|
|
|
@@ -43,6 +99,10 @@ const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
|
|
|
43
99
|
export class EmbeddedWallet extends BaseWallet {
|
|
44
100
|
protected estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING;
|
|
45
101
|
|
|
102
|
+
// Stub class ids, populated on wallet startup
|
|
103
|
+
// to avoid redundant work per simulation
|
|
104
|
+
protected stubClassIds = new Map<AccountType, Fr>();
|
|
105
|
+
|
|
46
106
|
constructor(
|
|
47
107
|
pxe: PXE,
|
|
48
108
|
aztecNode: AztecNode,
|
|
@@ -71,15 +131,17 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
71
131
|
|
|
72
132
|
override async registerSender(address: AztecAddress, alias: string) {
|
|
73
133
|
await this.walletDB.storeSender(address, alias);
|
|
74
|
-
|
|
134
|
+
await this.pxe.registerTaggingSecretSource({ kind: 'address-derived', sender: address });
|
|
135
|
+
return address;
|
|
75
136
|
}
|
|
76
137
|
|
|
77
138
|
override async getAddressBook(): Promise<Aliased<AztecAddress>[]> {
|
|
78
|
-
const
|
|
139
|
+
const sources = await this.pxe.getTaggingSecretSources({ kind: 'address-derived' });
|
|
140
|
+
const senders = sources.map(source => source.sender);
|
|
79
141
|
const storedSenders = await this.walletDB.listSenders();
|
|
80
142
|
for (const storedSender of storedSenders) {
|
|
81
143
|
if (senders.findIndex(sender => sender.equals(storedSender.item)) === -1) {
|
|
82
|
-
await this.pxe.
|
|
144
|
+
await this.pxe.registerTaggingSecretSource({ kind: 'address-derived', sender: storedSender.item });
|
|
83
145
|
}
|
|
84
146
|
}
|
|
85
147
|
return storedSenders;
|
|
@@ -94,19 +156,24 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
94
156
|
executionPayload: ExecutionPayload,
|
|
95
157
|
opts: SendOptions<W>,
|
|
96
158
|
): Promise<SendReturn<W>> {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
+
});
|
|
102
168
|
|
|
103
169
|
// Simulate the transaction first to estimate gas and capture required
|
|
104
170
|
// private authwitnesses based on offchain effects.
|
|
105
171
|
const simulationResult = await this.simulateViaEntrypoint(executionPayload, {
|
|
106
172
|
from: opts.from,
|
|
107
173
|
feeOptions,
|
|
108
|
-
|
|
174
|
+
additionalScopes: opts.additionalScopes,
|
|
109
175
|
skipTxValidation: true,
|
|
176
|
+
sendMessagesAs: opts.sendMessagesAs,
|
|
110
177
|
});
|
|
111
178
|
|
|
112
179
|
const offchainEffects = collectOffchainEffects(simulationResult.privateExecutionResult);
|
|
@@ -128,7 +195,8 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
128
195
|
executionPayload.authWitnesses.push(authwit);
|
|
129
196
|
}
|
|
130
197
|
}
|
|
131
|
-
const
|
|
198
|
+
const maxTxGasLimits = await this.getMaxTxGasLimits();
|
|
199
|
+
const estimated = getGasLimits(simulationResult.gasUsed, maxTxGasLimits, this.estimatedGasPadding);
|
|
132
200
|
this.log.verbose(
|
|
133
201
|
`Estimated gas limits for tx: DA=${estimated.gasLimits.daGas} L2=${estimated.gasLimits.l2Gas} teardownDA=${estimated.teardownGasLimits.daGas} teardownL2=${estimated.teardownGasLimits.l2Gas}`,
|
|
134
202
|
);
|
|
@@ -139,12 +207,119 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
139
207
|
gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
|
|
140
208
|
teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits,
|
|
141
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
|
+
}
|
|
142
225
|
return super.sendTx(executionPayload, {
|
|
143
226
|
...opts,
|
|
227
|
+
wait: wait as W,
|
|
144
228
|
fee: { ...opts.fee, gasSettings },
|
|
145
229
|
});
|
|
146
230
|
}
|
|
147
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
|
+
/**
|
|
267
|
+
* Hashes and registers the stub class for every supported account type with PXE, populating
|
|
268
|
+
* stubClassIds. Called on wallet initialization.
|
|
269
|
+
*/
|
|
270
|
+
async initStubClasses(): Promise<void> {
|
|
271
|
+
const schnorrArtifact = await this.accountContracts.getStubAccountContractArtifact('schnorr');
|
|
272
|
+
const { id: schnorrClassId } = await getContractClassFromArtifact(schnorrArtifact);
|
|
273
|
+
await this.pxe.registerContractClass(schnorrArtifact);
|
|
274
|
+
|
|
275
|
+
// ecdsa stubs share the same class id
|
|
276
|
+
const ecdsaArtifact = await this.accountContracts.getStubAccountContractArtifact('ecdsasecp256r1');
|
|
277
|
+
const { id: ecdsaClassId } = await getContractClassFromArtifact(ecdsaArtifact);
|
|
278
|
+
await this.pxe.registerContractClass(ecdsaArtifact);
|
|
279
|
+
|
|
280
|
+
this.stubClassIds.set('schnorr', schnorrClassId);
|
|
281
|
+
this.stubClassIds.set('schnorr_initializerless', schnorrClassId);
|
|
282
|
+
this.stubClassIds.set('ecdsasecp256k1', ecdsaClassId);
|
|
283
|
+
this.stubClassIds.set('ecdsasecp256r1', ecdsaClassId);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Builds contract overrides for all provided addresses by replacing their account contracts with stub implementations.
|
|
288
|
+
* Uses a type-specific stub artifact so that the stub's constructor selector matches the real account's constructor.
|
|
289
|
+
*/
|
|
290
|
+
protected async buildAccountOverrides(addresses: AztecAddress[]): Promise<ContractOverrides> {
|
|
291
|
+
const accounts = await this.getAccounts();
|
|
292
|
+
const contracts: ContractOverrides = {};
|
|
293
|
+
|
|
294
|
+
const filtered = accounts.filter(acc => addresses.some(addr => addr.equals(acc.item)));
|
|
295
|
+
|
|
296
|
+
for (const account of filtered) {
|
|
297
|
+
const address = account.item;
|
|
298
|
+
const { type } = await this.walletDB.retrieveAccount(address);
|
|
299
|
+
const stubClassId = this.stubClassIds.get(type);
|
|
300
|
+
if (!stubClassId) {
|
|
301
|
+
throw new Error(
|
|
302
|
+
`Stub class for account type '${type}' was not registered at wallet init. This is a bug — initStubClasses should cover every supported AccountType.`,
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const originalAccount = await this.getAccountFromAddress(address);
|
|
307
|
+
const completeAddress = originalAccount.getCompleteAddress();
|
|
308
|
+
const contractInstance = await this.pxe.getContractInstance(completeAddress.address);
|
|
309
|
+
if (!contractInstance) {
|
|
310
|
+
throw new Error(
|
|
311
|
+
`No contract instance found for address: ${completeAddress.address} during account override building. This is a bug!`,
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
contracts[address.toString()] = {
|
|
316
|
+
instance: { ...contractInstance, currentContractClassId: stubClassId },
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return contracts;
|
|
321
|
+
}
|
|
322
|
+
|
|
148
323
|
/**
|
|
149
324
|
* Simulates calls via a stub account entrypoint, bypassing real account authorization.
|
|
150
325
|
* This allows kernelless simulation with contract overrides, skipping expensive
|
|
@@ -153,8 +328,9 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
153
328
|
protected override async simulateViaEntrypoint(
|
|
154
329
|
executionPayload: ExecutionPayload,
|
|
155
330
|
opts: SimulateViaEntrypointOptions,
|
|
156
|
-
): Promise<
|
|
157
|
-
const { from, feeOptions,
|
|
331
|
+
): Promise<TxSimulationResultWithAppOffset> {
|
|
332
|
+
const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement, sendMessagesAs } = opts;
|
|
333
|
+
const scopes = this.scopesFrom(from, additionalScopes);
|
|
158
334
|
|
|
159
335
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
160
336
|
const finalExecutionPayload = feeExecutionPayload
|
|
@@ -162,16 +338,18 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
162
338
|
: executionPayload;
|
|
163
339
|
const chainInfo = await this.getChainInfo();
|
|
164
340
|
|
|
165
|
-
|
|
341
|
+
const accountOverrides = await this.buildAccountOverrides(scopes);
|
|
342
|
+
const overrides = new SimulationOverrides({ contracts: accountOverrides });
|
|
343
|
+
|
|
166
344
|
let txRequest: TxExecutionRequest;
|
|
167
345
|
if (from === NO_FROM) {
|
|
168
346
|
const entrypoint = new DefaultEntrypoint();
|
|
169
347
|
txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
170
348
|
} else {
|
|
171
|
-
const {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
349
|
+
const { type } = await this.walletDB.retrieveAccount(from);
|
|
350
|
+
const originalAccount = await this.getAccountFromAddress(from);
|
|
351
|
+
const completeAddress = originalAccount.getCompleteAddress();
|
|
352
|
+
const account = await this.accountContracts.createStubAccount(completeAddress, type);
|
|
175
353
|
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
176
354
|
txNonce: Fr.random(),
|
|
177
355
|
cancellable: this.cancellableTransactions,
|
|
@@ -186,32 +364,16 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
186
364
|
);
|
|
187
365
|
}
|
|
188
366
|
|
|
189
|
-
|
|
367
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
190
368
|
simulatePublic: true,
|
|
191
369
|
skipFeeEnforcement,
|
|
192
370
|
skipTxValidation,
|
|
193
371
|
overrides,
|
|
194
372
|
scopes,
|
|
373
|
+
senderForTags: this.senderForTagsFrom(from, sendMessagesAs),
|
|
195
374
|
});
|
|
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
|
-
};
|
|
375
|
+
const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
|
|
376
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
215
377
|
}
|
|
216
378
|
|
|
217
379
|
protected async createAccountInternal(
|
|
@@ -221,11 +383,19 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
221
383
|
signingKey: Buffer,
|
|
222
384
|
): Promise<AccountManager> {
|
|
223
385
|
let contract;
|
|
386
|
+
let immutablesHash;
|
|
387
|
+
let publicKey;
|
|
224
388
|
switch (type) {
|
|
225
389
|
case 'schnorr': {
|
|
226
390
|
contract = await this.accountContracts.getSchnorrAccountContract(Fq.fromBuffer(signingKey));
|
|
227
391
|
break;
|
|
228
392
|
}
|
|
393
|
+
case 'schnorr_initializerless': {
|
|
394
|
+
contract = await this.accountContracts.getSchnorrInitializerlessAccountContract(Fq.fromBuffer(signingKey));
|
|
395
|
+
publicKey = await new Schnorr().computePublicKey(Fq.fromBuffer(signingKey));
|
|
396
|
+
immutablesHash = await poseidon2Hash([publicKey.x, publicKey.y]);
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
229
399
|
case 'ecdsasecp256k1': {
|
|
230
400
|
contract = await this.accountContracts.getEcdsaKAccountContract(signingKey);
|
|
231
401
|
break;
|
|
@@ -239,17 +409,29 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
239
409
|
}
|
|
240
410
|
}
|
|
241
411
|
|
|
242
|
-
const accountManager = await AccountManager.create(this, secret, contract, salt);
|
|
412
|
+
const accountManager = await AccountManager.create(this, secret, contract, { salt, immutablesHash });
|
|
243
413
|
|
|
244
414
|
const instance = accountManager.getInstance();
|
|
245
415
|
const existingInstance = await this.pxe.getContractInstance(instance.address);
|
|
246
416
|
if (!existingInstance) {
|
|
247
417
|
const existingArtifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
418
|
+
const artifact = existingArtifact ?? (await accountManager.getAccountContract().getContractArtifact());
|
|
248
419
|
await this.registerContract(
|
|
249
420
|
instance,
|
|
250
421
|
!existingArtifact ? await accountManager.getAccountContract().getContractArtifact() : undefined,
|
|
251
422
|
accountManager.getSecretKey(),
|
|
252
423
|
);
|
|
424
|
+
if (type === 'schnorr_initializerless') {
|
|
425
|
+
const constructor = artifact.functions.find(f => f.name === 'constructor');
|
|
426
|
+
if (!constructor) {
|
|
427
|
+
throw new Error('Could not create SchnorrInitializerlessAccountContract: constructor ABI not found');
|
|
428
|
+
}
|
|
429
|
+
const storeCall = new ContractFunctionInteraction(this, instance.address, constructor, [
|
|
430
|
+
publicKey!.x,
|
|
431
|
+
publicKey!.y,
|
|
432
|
+
]);
|
|
433
|
+
await storeCall.simulate({ from: instance.address });
|
|
434
|
+
}
|
|
253
435
|
}
|
|
254
436
|
return accountManager;
|
|
255
437
|
}
|
|
@@ -271,6 +453,11 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
271
453
|
return this.createAndStoreAccount(alias ?? '', 'schnorr', secret, salt, sk.toBuffer());
|
|
272
454
|
}
|
|
273
455
|
|
|
456
|
+
createSchnorrInitializerlessAccount(secret: Fr, salt: Fr, signingKey?: Fq, alias?: string): Promise<AccountManager> {
|
|
457
|
+
const sk = signingKey ?? deriveSigningKey(secret);
|
|
458
|
+
return this.createAndStoreAccount(alias ?? '', 'schnorr_initializerless', secret, salt, sk.toBuffer());
|
|
459
|
+
}
|
|
460
|
+
|
|
274
461
|
createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer, alias?: string): Promise<AccountManager> {
|
|
275
462
|
return this.createAndStoreAccount(alias ?? '', 'ecdsasecp256r1', secret, salt, signingKey);
|
|
276
463
|
}
|
|
@@ -287,7 +474,8 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
287
474
|
this.estimatedGasPadding = value ?? DEFAULT_ESTIMATED_GAS_PADDING;
|
|
288
475
|
}
|
|
289
476
|
|
|
290
|
-
stop() {
|
|
291
|
-
|
|
477
|
+
async stop(): Promise<void> {
|
|
478
|
+
await this.pxe.stop();
|
|
479
|
+
await this.walletDB.close();
|
|
292
480
|
}
|
|
293
481
|
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { type AztecNode, createAztecNodeClient } from '@aztec/aztec.js/node';
|
|
2
2
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import { createStore, openTmpStore } from '@aztec/kv-store/
|
|
3
|
+
import { createStore, openTmpStore } from '@aztec/kv-store/sqlite-opfs';
|
|
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,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
|
-
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';
|
|
@@ -3,11 +3,14 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
|
3
3
|
import { createStore, openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
4
4
|
import { type PXEConfig, getPXEConfig } from '@aztec/pxe/config';
|
|
5
5
|
import { type PXE, type PXECreationOptions, createPXE } 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';
|
|
13
|
+
import { EmbeddedWallet, type EmbeddedWalletOptions, splitPxeOptions } from '../embedded_wallet.js';
|
|
11
14
|
import { WalletDB } from '../wallet_db.js';
|
|
12
15
|
|
|
13
16
|
export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
@@ -27,10 +30,16 @@ export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
|
27
30
|
const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
|
|
28
31
|
const l1Contracts = await aztecNode.getL1ContractAddresses();
|
|
29
32
|
|
|
33
|
+
// Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
|
|
34
|
+
const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
|
|
35
|
+
const mergedConfigOverrides = { ...options.pxeConfig, ...pxeConfigFromPxe };
|
|
36
|
+
const mergedCreationOverrides: PXECreationOptions = { ...options.pxeOptions, ...pxeCreationFromPxe };
|
|
37
|
+
|
|
30
38
|
const pxeConfig: PXEConfig = Object.assign(getPXEConfig(), {
|
|
31
|
-
proverEnabled:
|
|
39
|
+
proverEnabled: mergedConfigOverrides.proverEnabled,
|
|
32
40
|
dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
|
|
33
|
-
|
|
41
|
+
autoSync: false,
|
|
42
|
+
...mergedConfigOverrides,
|
|
34
43
|
});
|
|
35
44
|
|
|
36
45
|
if (options.ephemeral) {
|
|
@@ -38,42 +47,53 @@ export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
|
38
47
|
}
|
|
39
48
|
|
|
40
49
|
const pxeOptions: PXECreationOptions = {
|
|
41
|
-
...
|
|
50
|
+
...mergedCreationOverrides,
|
|
51
|
+
preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
|
|
52
|
+
getPreloadedContracts: async () => [
|
|
53
|
+
await getStandardMultiCallEntrypoint(),
|
|
54
|
+
await getStandardAuthRegistry(),
|
|
55
|
+
await getStandardHandshakeRegistry(),
|
|
56
|
+
],
|
|
57
|
+
},
|
|
42
58
|
loggers: {
|
|
43
59
|
store: rootLogger.createChild('pxe:data'),
|
|
44
60
|
pxe: rootLogger.createChild('pxe:service'),
|
|
45
61
|
prover: rootLogger.createChild('pxe:prover'),
|
|
46
|
-
...
|
|
62
|
+
...mergedCreationOverrides.loggers,
|
|
47
63
|
},
|
|
48
64
|
};
|
|
49
65
|
|
|
50
66
|
const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
|
|
51
67
|
|
|
52
|
-
const walletDBStore =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
const walletDBStore =
|
|
69
|
+
options.walletDb?.store ??
|
|
70
|
+
(options.ephemeral
|
|
71
|
+
? await openTmpStore(
|
|
72
|
+
`wallet_data_${l1Contracts.rollupAddress}`,
|
|
73
|
+
true,
|
|
74
|
+
undefined,
|
|
75
|
+
undefined,
|
|
76
|
+
rootLogger.createChild('wallet:data').getBindings(),
|
|
77
|
+
)
|
|
78
|
+
: await createStore(
|
|
79
|
+
'wallet_data',
|
|
80
|
+
1,
|
|
81
|
+
{
|
|
82
|
+
dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
|
|
83
|
+
dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
|
|
84
|
+
rollupAddress: l1Contracts.rollupAddress,
|
|
85
|
+
},
|
|
86
|
+
rootLogger.createChild('wallet:data').getBindings(),
|
|
87
|
+
));
|
|
88
|
+
const walletDB = new WalletDB(walletDBStore, rootLogger.createChild('wallet:db').info);
|
|
71
89
|
|
|
72
|
-
|
|
90
|
+
const wallet = new this(pxe, aztecNode, walletDB, new BundleAccountContractsProvider(), rootLogger) as T;
|
|
91
|
+
await wallet.initStubClasses();
|
|
92
|
+
return wallet;
|
|
73
93
|
}
|
|
74
94
|
}
|
|
75
95
|
|
|
76
96
|
export { NodeEmbeddedWallet as EmbeddedWallet };
|
|
77
|
-
export type { EmbeddedWalletOptions } from '../embedded_wallet.js';
|
|
97
|
+
export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
|
|
78
98
|
export { WalletDB } from '../wallet_db.js';
|
|
79
99
|
export type { AccountType } from '../wallet_db.js';
|