@aztec/wallets 0.0.1-commit.2e20a94 → 0.0.1-commit.3100065
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 +3 -6
- package/dest/embedded/account-contract-providers/bundle.d.ts.map +1 -1
- package/dest/embedded/account-contract-providers/bundle.js +10 -9
- package/dest/embedded/account-contract-providers/lazy.d.ts +3 -6
- package/dest/embedded/account-contract-providers/lazy.d.ts.map +1 -1
- package/dest/embedded/account-contract-providers/lazy.js +10 -10
- package/dest/embedded/account-contract-providers/types.d.ts +3 -6
- package/dest/embedded/account-contract-providers/types.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.d.ts +29 -4
- package/dest/embedded/embedded_wallet.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.js +135 -44
- package/dest/embedded/entrypoints/browser.d.ts +1 -1
- package/dest/embedded/entrypoints/browser.d.ts.map +1 -1
- package/dest/embedded/entrypoints/browser.js +20 -7
- package/dest/embedded/entrypoints/node.d.ts +1 -1
- package/dest/embedded/entrypoints/node.d.ts.map +1 -1
- package/dest/embedded/entrypoints/node.js +19 -6
- 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 +12 -11
- package/src/embedded/account-contract-providers/lazy.ts +12 -12
- package/src/embedded/account-contract-providers/types.ts +2 -2
- package/src/embedded/embedded_wallet.ts +162 -39
- package/src/embedded/entrypoints/browser.ts +31 -16
- package/src/embedded/entrypoints/node.ts +36 -21
- package/src/embedded/store_encryption.ts +107 -0
- package/src/embedded/wallet_db.ts +15 -12
- package/src/testing.ts +11 -17
|
@@ -1,29 +1,48 @@
|
|
|
1
1
|
import { type Account, NO_FROM } from '@aztec/aztec.js/account';
|
|
2
2
|
import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
|
|
3
|
-
import {
|
|
4
|
-
|
|
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';
|
|
5
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 {
|
|
18
35
|
type ContractOverrides,
|
|
19
36
|
ExecutionPayload,
|
|
20
37
|
SimulationOverrides,
|
|
21
38
|
type TxExecutionRequest,
|
|
39
|
+
type TxProfileResult,
|
|
22
40
|
TxStatus,
|
|
41
|
+
type UtilityExecutionResult,
|
|
23
42
|
collectOffchainEffects,
|
|
24
43
|
mergeExecutionPayloads,
|
|
25
44
|
} from '@aztec/stdlib/tx';
|
|
26
|
-
import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
45
|
+
import { BaseWallet, type SimulateViaEntrypointOptions, getGasLimits } from '@aztec/wallet-sdk/base-wallet';
|
|
27
46
|
|
|
28
47
|
import type { AccountContractsProvider } from './account-contract-providers/types.js';
|
|
29
48
|
import { type AccountType, WalletDB } from './wallet_db.js';
|
|
@@ -39,10 +58,20 @@ export function splitPxeOptions(pxe?: EmbeddedWalletPXEOptions): {
|
|
|
39
58
|
if (!pxe) {
|
|
40
59
|
return { config: {}, creation: {} };
|
|
41
60
|
}
|
|
42
|
-
const { loggers, loggerActorLabel, proverOrOptions, store, simulator, ...config } =
|
|
43
|
-
|
|
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
|
+
};
|
|
44
67
|
}
|
|
45
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
|
+
|
|
46
75
|
export type EmbeddedWalletOptions = {
|
|
47
76
|
/** Parent logger. Child loggers are derived via createChild() for each subsystem. */
|
|
48
77
|
logger?: Logger;
|
|
@@ -50,6 +79,8 @@ export type EmbeddedWalletOptions = {
|
|
|
50
79
|
ephemeral?: boolean;
|
|
51
80
|
/** PXE configuration and dependency overrides (custom store, prover, simulator). */
|
|
52
81
|
pxe?: EmbeddedWalletPXEOptions;
|
|
82
|
+
/** Wallet DB dependency overrides (custom store). */
|
|
83
|
+
walletDb?: EmbeddedWalletDBOptions;
|
|
53
84
|
/**
|
|
54
85
|
* Override PXE configuration.
|
|
55
86
|
* @deprecated Use `pxe` instead.
|
|
@@ -67,6 +98,10 @@ const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
|
|
|
67
98
|
export class EmbeddedWallet extends BaseWallet {
|
|
68
99
|
protected estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING;
|
|
69
100
|
|
|
101
|
+
// Stub class ids, populated on wallet startup
|
|
102
|
+
// to avoid redundant work per simulation
|
|
103
|
+
protected stubClassIds = new Map<AccountType, Fr>();
|
|
104
|
+
|
|
70
105
|
constructor(
|
|
71
106
|
pxe: PXE,
|
|
72
107
|
aztecNode: AztecNode,
|
|
@@ -95,15 +130,17 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
95
130
|
|
|
96
131
|
override async registerSender(address: AztecAddress, alias: string) {
|
|
97
132
|
await this.walletDB.storeSender(address, alias);
|
|
98
|
-
|
|
133
|
+
await this.pxe.registerTaggingSecretSource({ kind: 'address-derived', sender: address });
|
|
134
|
+
return address;
|
|
99
135
|
}
|
|
100
136
|
|
|
101
137
|
override async getAddressBook(): Promise<Aliased<AztecAddress>[]> {
|
|
102
|
-
const
|
|
138
|
+
const sources = await this.pxe.getTaggingSecretSources({ kind: 'address-derived' });
|
|
139
|
+
const senders = sources.map(source => source.sender);
|
|
103
140
|
const storedSenders = await this.walletDB.listSenders();
|
|
104
141
|
for (const storedSender of storedSenders) {
|
|
105
142
|
if (senders.findIndex(sender => sender.equals(storedSender.item)) === -1) {
|
|
106
|
-
await this.pxe.
|
|
143
|
+
await this.pxe.registerTaggingSecretSource({ kind: 'address-derived', sender: storedSender.item });
|
|
107
144
|
}
|
|
108
145
|
}
|
|
109
146
|
return storedSenders;
|
|
@@ -118,6 +155,9 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
118
155
|
executionPayload: ExecutionPayload,
|
|
119
156
|
opts: SendOptions<W>,
|
|
120
157
|
): Promise<SendReturn<W>> {
|
|
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();
|
|
121
161
|
const feeOptions = await this.completeFeeOptions({
|
|
122
162
|
from: opts.from,
|
|
123
163
|
feePayer: executionPayload.feePayer,
|
|
@@ -132,6 +172,7 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
132
172
|
feeOptions,
|
|
133
173
|
additionalScopes: opts.additionalScopes,
|
|
134
174
|
skipTxValidation: true,
|
|
175
|
+
sendMessagesAs: opts.sendMessagesAs,
|
|
135
176
|
});
|
|
136
177
|
|
|
137
178
|
const offchainEffects = collectOffchainEffects(simulationResult.privateExecutionResult);
|
|
@@ -153,7 +194,8 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
153
194
|
executionPayload.authWitnesses.push(authwit);
|
|
154
195
|
}
|
|
155
196
|
}
|
|
156
|
-
const
|
|
197
|
+
const maxTxGasLimits = await this.getMaxTxGasLimits();
|
|
198
|
+
const estimated = getGasLimits(simulationResult.gasUsed, maxTxGasLimits, this.estimatedGasPadding);
|
|
157
199
|
this.log.verbose(
|
|
158
200
|
`Estimated gas limits for tx: DA=${estimated.gasLimits.daGas} L2=${estimated.gasLimits.l2Gas} teardownDA=${estimated.teardownGasLimits.daGas} teardownL2=${estimated.teardownGasLimits.l2Gas}`,
|
|
159
201
|
);
|
|
@@ -164,24 +206,82 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
164
206
|
gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
|
|
165
207
|
teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits,
|
|
166
208
|
});
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
+
};
|
|
178
223
|
}
|
|
179
224
|
return super.sendTx(executionPayload, {
|
|
180
225
|
...opts,
|
|
226
|
+
wait: wait as W,
|
|
181
227
|
fee: { ...opts.fee, gasSettings },
|
|
182
228
|
});
|
|
183
229
|
}
|
|
184
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
|
+
|
|
185
285
|
/**
|
|
186
286
|
* Builds contract overrides for all provided addresses by replacing their account contracts with stub implementations.
|
|
187
287
|
* Uses a type-specific stub artifact so that the stub's constructor selector matches the real account's constructor.
|
|
@@ -195,7 +295,12 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
195
295
|
for (const account of filtered) {
|
|
196
296
|
const address = account.item;
|
|
197
297
|
const { type } = await this.walletDB.retrieveAccount(address);
|
|
198
|
-
const
|
|
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
|
+
}
|
|
199
304
|
|
|
200
305
|
const originalAccount = await this.getAccountFromAddress(address);
|
|
201
306
|
const completeAddress = originalAccount.getCompleteAddress();
|
|
@@ -206,15 +311,8 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
206
311
|
);
|
|
207
312
|
}
|
|
208
313
|
|
|
209
|
-
const stubConstructorArgs = type === 'schnorr' ? [Fr.ZERO, Fr.ZERO] : [Buffer.alloc(32), Buffer.alloc(32)];
|
|
210
|
-
const stubInstance = await getContractInstanceFromInstantiationParams(stubArtifact, {
|
|
211
|
-
salt: Fr.random(),
|
|
212
|
-
constructorArgs: stubConstructorArgs,
|
|
213
|
-
});
|
|
214
|
-
|
|
215
314
|
contracts[address.toString()] = {
|
|
216
|
-
instance:
|
|
217
|
-
artifact: stubArtifact,
|
|
315
|
+
instance: { ...contractInstance, currentContractClassId: stubClassId },
|
|
218
316
|
};
|
|
219
317
|
}
|
|
220
318
|
|
|
@@ -230,7 +328,7 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
230
328
|
executionPayload: ExecutionPayload,
|
|
231
329
|
opts: SimulateViaEntrypointOptions,
|
|
232
330
|
): Promise<TxSimulationResultWithAppOffset> {
|
|
233
|
-
const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement } = opts;
|
|
331
|
+
const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement, sendMessagesAs } = opts;
|
|
234
332
|
const scopes = this.scopesFrom(from, additionalScopes);
|
|
235
333
|
|
|
236
334
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
@@ -240,7 +338,7 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
240
338
|
const chainInfo = await this.getChainInfo();
|
|
241
339
|
|
|
242
340
|
const accountOverrides = await this.buildAccountOverrides(scopes);
|
|
243
|
-
const overrides = new SimulationOverrides(accountOverrides);
|
|
341
|
+
const overrides = new SimulationOverrides({ contracts: accountOverrides });
|
|
244
342
|
|
|
245
343
|
let txRequest: TxExecutionRequest;
|
|
246
344
|
if (from === NO_FROM) {
|
|
@@ -271,6 +369,7 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
271
369
|
skipTxValidation,
|
|
272
370
|
overrides,
|
|
273
371
|
scopes,
|
|
372
|
+
senderForTags: this.senderForTagsFrom(from, sendMessagesAs),
|
|
274
373
|
});
|
|
275
374
|
const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
|
|
276
375
|
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
@@ -283,11 +382,19 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
283
382
|
signingKey: Buffer,
|
|
284
383
|
): Promise<AccountManager> {
|
|
285
384
|
let contract;
|
|
385
|
+
let immutablesHash;
|
|
386
|
+
let publicKey;
|
|
286
387
|
switch (type) {
|
|
287
388
|
case 'schnorr': {
|
|
288
389
|
contract = await this.accountContracts.getSchnorrAccountContract(Fq.fromBuffer(signingKey));
|
|
289
390
|
break;
|
|
290
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
|
+
}
|
|
291
398
|
case 'ecdsasecp256k1': {
|
|
292
399
|
contract = await this.accountContracts.getEcdsaKAccountContract(signingKey);
|
|
293
400
|
break;
|
|
@@ -301,17 +408,29 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
301
408
|
}
|
|
302
409
|
}
|
|
303
410
|
|
|
304
|
-
const accountManager = await AccountManager.create(this, secret, contract, salt);
|
|
411
|
+
const accountManager = await AccountManager.create(this, secret, contract, { salt, immutablesHash });
|
|
305
412
|
|
|
306
413
|
const instance = accountManager.getInstance();
|
|
307
414
|
const existingInstance = await this.pxe.getContractInstance(instance.address);
|
|
308
415
|
if (!existingInstance) {
|
|
309
416
|
const existingArtifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
417
|
+
const artifact = existingArtifact ?? (await accountManager.getAccountContract().getContractArtifact());
|
|
310
418
|
await this.registerContract(
|
|
311
419
|
instance,
|
|
312
420
|
!existingArtifact ? await accountManager.getAccountContract().getContractArtifact() : undefined,
|
|
313
421
|
accountManager.getSecretKey(),
|
|
314
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
|
+
}
|
|
315
434
|
}
|
|
316
435
|
return accountManager;
|
|
317
436
|
}
|
|
@@ -328,9 +447,12 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
328
447
|
return accountManager;
|
|
329
448
|
}
|
|
330
449
|
|
|
331
|
-
createSchnorrAccount(secret: Fr, salt: Fr, signingKey
|
|
332
|
-
|
|
333
|
-
|
|
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());
|
|
334
456
|
}
|
|
335
457
|
|
|
336
458
|
createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer, alias?: string): Promise<AccountManager> {
|
|
@@ -349,7 +471,8 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
349
471
|
this.estimatedGasPadding = value ?? DEFAULT_ESTIMATED_GAS_PADDING;
|
|
350
472
|
}
|
|
351
473
|
|
|
352
|
-
stop() {
|
|
353
|
-
|
|
474
|
+
async stop(): Promise<void> {
|
|
475
|
+
await this.pxe.stop();
|
|
476
|
+
await this.walletDB.close();
|
|
354
477
|
}
|
|
355
478
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
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';
|
|
@@ -32,8 +35,9 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
|
32
35
|
const mergedCreationOverrides: PXECreationOptions = { ...options.pxeOptions, ...pxeCreationFromPxe };
|
|
33
36
|
|
|
34
37
|
const pxeConfig: PXEConfig = Object.assign(getPXEConfig(), {
|
|
35
|
-
proverEnabled: mergedConfigOverrides.proverEnabled
|
|
38
|
+
proverEnabled: mergedConfigOverrides.proverEnabled,
|
|
36
39
|
dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
|
|
40
|
+
autoSync: false,
|
|
37
41
|
...mergedConfigOverrides,
|
|
38
42
|
});
|
|
39
43
|
|
|
@@ -43,6 +47,13 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
|
43
47
|
|
|
44
48
|
const pxeOptions: PXECreationOptions = {
|
|
45
49
|
...mergedCreationOverrides,
|
|
50
|
+
preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
|
|
51
|
+
getPreloadedContracts: async () => [
|
|
52
|
+
await getStandardMultiCallEntrypoint(),
|
|
53
|
+
await getStandardAuthRegistry(),
|
|
54
|
+
await getStandardHandshakeRegistry(),
|
|
55
|
+
],
|
|
56
|
+
},
|
|
46
57
|
loggers: {
|
|
47
58
|
store: rootLogger.createChild('pxe:data'),
|
|
48
59
|
pxe: rootLogger.createChild('pxe:service'),
|
|
@@ -53,21 +64,25 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
|
53
64
|
|
|
54
65
|
const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
|
|
55
66
|
|
|
56
|
-
const walletDBStore =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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);
|
|
69
82
|
|
|
70
|
-
|
|
83
|
+
const wallet = new this(pxe, aztecNode, walletDB, new LazyAccountContractsProvider(), rootLogger) as T;
|
|
84
|
+
await wallet.initStubClasses();
|
|
85
|
+
return wallet;
|
|
71
86
|
}
|
|
72
87
|
}
|
|
73
88
|
|
|
@@ -3,6 +3,9 @@ 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';
|
|
@@ -33,8 +36,9 @@ export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
|
33
36
|
const mergedCreationOverrides: PXECreationOptions = { ...options.pxeOptions, ...pxeCreationFromPxe };
|
|
34
37
|
|
|
35
38
|
const pxeConfig: PXEConfig = Object.assign(getPXEConfig(), {
|
|
36
|
-
proverEnabled: mergedConfigOverrides.proverEnabled
|
|
39
|
+
proverEnabled: mergedConfigOverrides.proverEnabled,
|
|
37
40
|
dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
|
|
41
|
+
autoSync: false,
|
|
38
42
|
...mergedConfigOverrides,
|
|
39
43
|
});
|
|
40
44
|
|
|
@@ -44,6 +48,13 @@ export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
|
44
48
|
|
|
45
49
|
const pxeOptions: PXECreationOptions = {
|
|
46
50
|
...mergedCreationOverrides,
|
|
51
|
+
preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
|
|
52
|
+
getPreloadedContracts: async () => [
|
|
53
|
+
await getStandardMultiCallEntrypoint(),
|
|
54
|
+
await getStandardAuthRegistry(),
|
|
55
|
+
await getStandardHandshakeRegistry(),
|
|
56
|
+
],
|
|
57
|
+
},
|
|
47
58
|
loggers: {
|
|
48
59
|
store: rootLogger.createChild('pxe:data'),
|
|
49
60
|
pxe: rootLogger.createChild('pxe:service'),
|
|
@@ -54,27 +65,31 @@ export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
|
54
65
|
|
|
55
66
|
const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
|
|
56
67
|
|
|
57
|
-
const walletDBStore =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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);
|
|
76
89
|
|
|
77
|
-
|
|
90
|
+
const wallet = new this(pxe, aztecNode, walletDB, new BundleAccountContractsProvider(), rootLogger) as T;
|
|
91
|
+
await wallet.initStubClasses();
|
|
92
|
+
return wallet;
|
|
78
93
|
}
|
|
79
94
|
}
|
|
80
95
|
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wallet-layer helpers for opening the embedded wallet's two encrypted stores (PXE + walletDB) as a cohesive unit.
|
|
3
|
+
*
|
|
4
|
+
* Sits on top of `@aztec/kv-store/sqlite-opfs`'s typed `SqliteEncryptionError` and adds:
|
|
5
|
+
*
|
|
6
|
+
* - `storeName: 'pxe' | 'wallet'`, telling callers WHICH store failed.
|
|
7
|
+
* - Cleanup: when the wallet store fails to open, ensures the already-opened PXE store is closed before the error
|
|
8
|
+
* surfaces, so callers don't leak the SAH Pool's OPFS lock.
|
|
9
|
+
*/
|
|
10
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
11
|
+
import { AztecSQLiteOPFSStore, SqliteEncryptionError } from '@aztec/kv-store/sqlite-opfs';
|
|
12
|
+
|
|
13
|
+
/** Which of the embedded wallet's two stores failed to open. */
|
|
14
|
+
export type EmbeddedStoreName = 'pxe' | 'wallet';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Thrown by {@link openEncryptedEmbeddedStores} when one of the two stores cannot be decrypted with the supplied
|
|
18
|
+
* key. The original {@link SqliteEncryptionError} is preserved as `cause`.
|
|
19
|
+
*/
|
|
20
|
+
export class EmbeddedWalletEncryptionError extends Error {
|
|
21
|
+
readonly storeName: EmbeddedStoreName;
|
|
22
|
+
|
|
23
|
+
constructor(storeName: EmbeddedStoreName, opts: { cause: SqliteEncryptionError }) {
|
|
24
|
+
super(`Embedded wallet '${storeName}' store could not be decrypted with the provided key`, { cause: opts.cause });
|
|
25
|
+
this.name = 'EmbeddedWalletEncryptionError';
|
|
26
|
+
this.storeName = storeName;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Configuration for {@link openEncryptedEmbeddedStores}. */
|
|
31
|
+
export interface OpenEncryptedEmbeddedStoresOptions {
|
|
32
|
+
pxe: { name: string; poolDirectory?: string };
|
|
33
|
+
wallet: { name: string; poolDirectory?: string };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Internal seam for tests to inject a fake store opener. Defaults to `AztecSQLiteOPFSStore.open`. Not part of the
|
|
38
|
+
* public API.
|
|
39
|
+
*
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
export type OpenSqliteEncryptedStoreFn = (
|
|
43
|
+
log: Logger,
|
|
44
|
+
name: string,
|
|
45
|
+
poolDirectory: string | undefined,
|
|
46
|
+
encryptionKey: Uint8Array,
|
|
47
|
+
) => Promise<AztecSQLiteOPFSStore>;
|
|
48
|
+
|
|
49
|
+
const defaultOpenStore: OpenSqliteEncryptedStoreFn = (log, name, poolDirectory, encryptionKey) =>
|
|
50
|
+
AztecSQLiteOPFSStore.open(log, name, false, poolDirectory, encryptionKey);
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Opens the PXE and wallet stores in sequence, both encrypted with keys obtained from `getEncryptionKey`.
|
|
54
|
+
*
|
|
55
|
+
* The callback is invoked once per store (twice total per call) because `AztecSQLiteOPFSStore.open` *transfers*
|
|
56
|
+
* the key buffer to its worker. A single buffer would detach between the two opens.
|
|
57
|
+
*
|
|
58
|
+
* Failure modes:
|
|
59
|
+
*
|
|
60
|
+
* - PXE store fails to decrypt → throws `EmbeddedWalletEncryptionError({ storeName: 'pxe', cause })`. No cleanup
|
|
61
|
+
* needed (nothing was opened).
|
|
62
|
+
* - Wallet store fails to decrypt → closes the already-opened PXE store then throws
|
|
63
|
+
* `EmbeddedWalletEncryptionError({ storeName: 'wallet', cause })`.
|
|
64
|
+
* - Any non-decrypt error during the wallet open → still closes PXE, then re-throws the original error unwrapped
|
|
65
|
+
* (preserves callers' existing untyped error handling for non-encryption faults).
|
|
66
|
+
*
|
|
67
|
+
* @param config - Per-store name/poolDirectory.
|
|
68
|
+
* @param getEncryptionKey - Returns a fresh 32-byte key per call (the buffer
|
|
69
|
+
* detaches on transfer, so each call must allocate).
|
|
70
|
+
* @param log - Logger for both stores.
|
|
71
|
+
* @param openStore - Internal test seam. Do not pass in production code.
|
|
72
|
+
*/
|
|
73
|
+
export async function openEncryptedEmbeddedStores(
|
|
74
|
+
config: OpenEncryptedEmbeddedStoresOptions,
|
|
75
|
+
getEncryptionKey: () => Promise<Uint8Array>,
|
|
76
|
+
log: Logger,
|
|
77
|
+
openStore: OpenSqliteEncryptedStoreFn = defaultOpenStore,
|
|
78
|
+
): Promise<{ pxeStore: AztecSQLiteOPFSStore; walletStore: AztecSQLiteOPFSStore }> {
|
|
79
|
+
const pxeStore = await openOneStore('pxe', config.pxe, getEncryptionKey, log, openStore);
|
|
80
|
+
try {
|
|
81
|
+
const walletStore = await openOneStore('wallet', config.wallet, getEncryptionKey, log, openStore);
|
|
82
|
+
return { pxeStore, walletStore };
|
|
83
|
+
} catch (err) {
|
|
84
|
+
// Cleanup is best-effort — if close() itself throws (e.g. worker already dead), swallow it so the original error
|
|
85
|
+
// surfaces unobstructed.
|
|
86
|
+
await pxeStore.close().catch(() => {});
|
|
87
|
+
throw err;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function openOneStore(
|
|
92
|
+
storeName: EmbeddedStoreName,
|
|
93
|
+
{ name, poolDirectory }: { name: string; poolDirectory?: string },
|
|
94
|
+
getEncryptionKey: () => Promise<Uint8Array>,
|
|
95
|
+
log: Logger,
|
|
96
|
+
openStore: OpenSqliteEncryptedStoreFn,
|
|
97
|
+
): Promise<AztecSQLiteOPFSStore> {
|
|
98
|
+
const key = await getEncryptionKey();
|
|
99
|
+
try {
|
|
100
|
+
return await openStore(log, name, poolDirectory, key);
|
|
101
|
+
} catch (err) {
|
|
102
|
+
if (err instanceof SqliteEncryptionError && err.code === 'decrypt_failed') {
|
|
103
|
+
throw new EmbeddedWalletEncryptionError(storeName, { cause: err });
|
|
104
|
+
}
|
|
105
|
+
throw err;
|
|
106
|
+
}
|
|
107
|
+
}
|