@aztec/wallets 0.0.1-commit.993d240 → 0.0.1-commit.9a89641
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 +2 -1
- package/dest/embedded/account-contract-providers/bundle.d.ts.map +1 -1
- package/dest/embedded/account-contract-providers/bundle.js +10 -5
- package/dest/embedded/account-contract-providers/lazy.d.ts +2 -1
- package/dest/embedded/account-contract-providers/lazy.d.ts.map +1 -1
- package/dest/embedded/account-contract-providers/lazy.js +10 -6
- package/dest/embedded/account-contract-providers/types.d.ts +2 -1
- package/dest/embedded/account-contract-providers/types.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.d.ts +5 -6
- package/dest/embedded/embedded_wallet.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.js +68 -27
- 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 +21 -18
- 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 +24 -12
- package/dest/embedded/store_encryption.d.ts +9 -2
- package/dest/embedded/store_encryption.d.ts.map +1 -1
- package/dest/embedded/store_encryption.js +27 -5
- package/dest/embedded/wallet_db.d.ts +5 -3
- package/dest/embedded/wallet_db.d.ts.map +1 -1
- package/dest/embedded/wallet_db.js +4 -2
- package/dest/testing.d.ts +8 -4
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +8 -14
- package/package.json +11 -11
- package/src/embedded/account-contract-providers/bundle.ts +11 -5
- package/src/embedded/account-contract-providers/lazy.ts +11 -6
- package/src/embedded/account-contract-providers/types.ts +1 -0
- package/src/embedded/embedded_wallet.ts +63 -36
- package/src/embedded/entrypoints/browser.ts +26 -28
- package/src/embedded/entrypoints/node.ts +33 -27
- package/src/embedded/store_encryption.ts +42 -3
- package/src/embedded/wallet_db.ts +6 -3
- package/src/testing.ts +11 -17
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { type Account, NO_FROM } from '@aztec/aztec.js/account';
|
|
2
2
|
import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ContractFunctionInteraction,
|
|
5
|
+
type InteractionWaitOptions,
|
|
6
|
+
NO_WAIT,
|
|
7
|
+
type SendReturn,
|
|
8
|
+
type WaitOpts,
|
|
9
|
+
} from '@aztec/aztec.js/contracts';
|
|
4
10
|
import type {
|
|
5
11
|
Aliased,
|
|
6
12
|
ExecuteUtilityOptions,
|
|
@@ -13,17 +19,18 @@ import type {
|
|
|
13
19
|
import { AccountManager, TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
|
|
14
20
|
import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
15
21
|
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
22
|
+
import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
|
|
23
|
+
import { Schnorr } from '@aztec/foundation/crypto/schnorr';
|
|
16
24
|
import { Fq, Fr } from '@aztec/foundation/curves/bn254';
|
|
17
25
|
import type { Logger } from '@aztec/foundation/log';
|
|
18
26
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
19
27
|
import type { PXEConfig, PXECreationOptions } from '@aztec/pxe/client/lazy';
|
|
20
28
|
import type { PXE } from '@aztec/pxe/server';
|
|
21
|
-
import type {
|
|
29
|
+
import type { EventMetadataDefinition, FunctionCall } from '@aztec/stdlib/abi';
|
|
22
30
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
23
|
-
import {
|
|
31
|
+
import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
24
32
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
25
33
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
26
|
-
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
27
34
|
import {
|
|
28
35
|
type ContractOverrides,
|
|
29
36
|
ExecutionPayload,
|
|
@@ -35,7 +42,7 @@ import {
|
|
|
35
42
|
collectOffchainEffects,
|
|
36
43
|
mergeExecutionPayloads,
|
|
37
44
|
} from '@aztec/stdlib/tx';
|
|
38
|
-
import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
45
|
+
import { BaseWallet, type SimulateViaEntrypointOptions, getGasLimits } from '@aztec/wallet-sdk/base-wallet';
|
|
39
46
|
|
|
40
47
|
import type { AccountContractsProvider } from './account-contract-providers/types.js';
|
|
41
48
|
import { type AccountType, WalletDB } from './wallet_db.js';
|
|
@@ -123,15 +130,17 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
123
130
|
|
|
124
131
|
override async registerSender(address: AztecAddress, alias: string) {
|
|
125
132
|
await this.walletDB.storeSender(address, alias);
|
|
126
|
-
|
|
133
|
+
await this.pxe.registerTaggingSecretSource({ kind: 'address-derived', sender: address });
|
|
134
|
+
return address;
|
|
127
135
|
}
|
|
128
136
|
|
|
129
137
|
override async getAddressBook(): Promise<Aliased<AztecAddress>[]> {
|
|
130
|
-
const
|
|
138
|
+
const sources = await this.pxe.getTaggingSecretSources({ kind: 'address-derived' });
|
|
139
|
+
const senders = sources.map(source => source.sender);
|
|
131
140
|
const storedSenders = await this.walletDB.listSenders();
|
|
132
141
|
for (const storedSender of storedSenders) {
|
|
133
142
|
if (senders.findIndex(sender => sender.equals(storedSender.item)) === -1) {
|
|
134
|
-
await this.pxe.
|
|
143
|
+
await this.pxe.registerTaggingSecretSource({ kind: 'address-derived', sender: storedSender.item });
|
|
135
144
|
}
|
|
136
145
|
}
|
|
137
146
|
return storedSenders;
|
|
@@ -185,7 +194,8 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
185
194
|
executionPayload.authWitnesses.push(authwit);
|
|
186
195
|
}
|
|
187
196
|
}
|
|
188
|
-
const
|
|
197
|
+
const maxTxGasLimits = await this.getMaxTxGasLimits();
|
|
198
|
+
const estimated = getGasLimits(simulationResult.gasUsed, maxTxGasLimits, this.estimatedGasPadding);
|
|
189
199
|
this.log.verbose(
|
|
190
200
|
`Estimated gas limits for tx: DA=${estimated.gasLimits.daGas} L2=${estimated.gasLimits.l2Gas} teardownDA=${estimated.teardownGasLimits.daGas} teardownL2=${estimated.teardownGasLimits.l2Gas}`,
|
|
191
201
|
);
|
|
@@ -196,20 +206,24 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
196
206
|
gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
|
|
197
207
|
teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits,
|
|
198
208
|
});
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
+
};
|
|
210
223
|
}
|
|
211
224
|
return super.sendTx(executionPayload, {
|
|
212
225
|
...opts,
|
|
226
|
+
wait: wait as W,
|
|
213
227
|
fee: { ...opts.fee, gasSettings },
|
|
214
228
|
});
|
|
215
229
|
}
|
|
@@ -248,17 +262,6 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
248
262
|
return super.getPrivateEvents<T>(eventDef, eventFilter);
|
|
249
263
|
}
|
|
250
264
|
|
|
251
|
-
public override async registerContract(
|
|
252
|
-
instance: ContractInstanceWithAddress,
|
|
253
|
-
artifact?: ContractArtifact,
|
|
254
|
-
secretKey?: Fr,
|
|
255
|
-
): Promise<ContractInstanceWithAddress> {
|
|
256
|
-
// registerContract may call pxe.updateContract under the hood, which depends on a fresh anchor
|
|
257
|
-
// block to verify the current class id from the node.
|
|
258
|
-
await this.pxe.sync();
|
|
259
|
-
return super.registerContract(instance, artifact, secretKey);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
265
|
/**
|
|
263
266
|
* Hashes and registers the stub class for every supported account type with PXE, populating
|
|
264
267
|
* stubClassIds. Called on wallet initialization.
|
|
@@ -274,6 +277,7 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
274
277
|
await this.pxe.registerContractClass(ecdsaArtifact);
|
|
275
278
|
|
|
276
279
|
this.stubClassIds.set('schnorr', schnorrClassId);
|
|
280
|
+
this.stubClassIds.set('schnorr_initializerless', schnorrClassId);
|
|
277
281
|
this.stubClassIds.set('ecdsasecp256k1', ecdsaClassId);
|
|
278
282
|
this.stubClassIds.set('ecdsasecp256r1', ecdsaClassId);
|
|
279
283
|
}
|
|
@@ -325,7 +329,7 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
325
329
|
opts: SimulateViaEntrypointOptions,
|
|
326
330
|
): Promise<TxSimulationResultWithAppOffset> {
|
|
327
331
|
const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement, sendMessagesAs } = opts;
|
|
328
|
-
const scopes = this.scopesFrom(from, additionalScopes);
|
|
332
|
+
const scopes = this.scopesFrom(from, additionalScopes ?? [], sendMessagesAs);
|
|
329
333
|
|
|
330
334
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
331
335
|
const finalExecutionPayload = feeExecutionPayload
|
|
@@ -378,11 +382,19 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
378
382
|
signingKey: Buffer,
|
|
379
383
|
): Promise<AccountManager> {
|
|
380
384
|
let contract;
|
|
385
|
+
let immutablesHash;
|
|
386
|
+
let publicKey;
|
|
381
387
|
switch (type) {
|
|
382
388
|
case 'schnorr': {
|
|
383
389
|
contract = await this.accountContracts.getSchnorrAccountContract(Fq.fromBuffer(signingKey));
|
|
384
390
|
break;
|
|
385
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
|
+
}
|
|
386
398
|
case 'ecdsasecp256k1': {
|
|
387
399
|
contract = await this.accountContracts.getEcdsaKAccountContract(signingKey);
|
|
388
400
|
break;
|
|
@@ -396,17 +408,29 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
396
408
|
}
|
|
397
409
|
}
|
|
398
410
|
|
|
399
|
-
const accountManager = await AccountManager.create(this, secret, contract, { salt });
|
|
411
|
+
const accountManager = await AccountManager.create(this, secret, contract, { salt, immutablesHash });
|
|
400
412
|
|
|
401
413
|
const instance = accountManager.getInstance();
|
|
402
414
|
const existingInstance = await this.pxe.getContractInstance(instance.address);
|
|
403
415
|
if (!existingInstance) {
|
|
404
416
|
const existingArtifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
|
|
417
|
+
const artifact = existingArtifact ?? (await accountManager.getAccountContract().getContractArtifact());
|
|
405
418
|
await this.registerContract(
|
|
406
419
|
instance,
|
|
407
420
|
!existingArtifact ? await accountManager.getAccountContract().getContractArtifact() : undefined,
|
|
408
421
|
accountManager.getSecretKey(),
|
|
409
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
|
+
}
|
|
410
434
|
}
|
|
411
435
|
return accountManager;
|
|
412
436
|
}
|
|
@@ -423,9 +447,12 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
423
447
|
return accountManager;
|
|
424
448
|
}
|
|
425
449
|
|
|
426
|
-
createSchnorrAccount(secret: Fr, salt: Fr, signingKey
|
|
427
|
-
|
|
428
|
-
|
|
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());
|
|
429
456
|
}
|
|
430
457
|
|
|
431
458
|
createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer, alias?: string): Promise<AccountManager> {
|
|
@@ -1,15 +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
6
|
import { getStandardAuthRegistry } from '@aztec/standard-contracts/auth-registry/lazy';
|
|
7
|
+
import { getStandardHandshakeRegistry } from '@aztec/standard-contracts/handshake-registry/lazy';
|
|
7
8
|
import { getStandardMultiCallEntrypoint } from '@aztec/standard-contracts/multi-call-entrypoint/lazy';
|
|
8
9
|
|
|
9
10
|
import { LazyAccountContractsProvider } from '../account-contract-providers/lazy.js';
|
|
10
11
|
import type { AccountContractsProvider } from '../account-contract-providers/types.js';
|
|
11
12
|
import { EmbeddedWallet, type EmbeddedWalletOptions, splitPxeOptions } from '../embedded_wallet.js';
|
|
12
|
-
import { WalletDB } from '../wallet_db.js';
|
|
13
|
+
import { WALLET_DATA_SCHEMA_VERSION, WalletDB } from '../wallet_db.js';
|
|
13
14
|
|
|
14
15
|
export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
15
16
|
static async create<T extends BrowserEmbeddedWallet = BrowserEmbeddedWallet>(
|
|
@@ -26,7 +27,6 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
|
26
27
|
const rootLogger = options.logger ?? createLogger('embedded-wallet');
|
|
27
28
|
|
|
28
29
|
const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
|
|
29
|
-
const l1Contracts = await aztecNode.getL1ContractAddresses();
|
|
30
30
|
|
|
31
31
|
// Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
|
|
32
32
|
const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
|
|
@@ -34,8 +34,9 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
|
34
34
|
const mergedCreationOverrides: PXECreationOptions = { ...options.pxeOptions, ...pxeCreationFromPxe };
|
|
35
35
|
|
|
36
36
|
const pxeConfig: PXEConfig = Object.assign(getPXEConfig(), {
|
|
37
|
-
proverEnabled: mergedConfigOverrides.proverEnabled
|
|
38
|
-
|
|
37
|
+
proverEnabled: mergedConfigOverrides.proverEnabled,
|
|
38
|
+
// Unused in the browser: sqlite-opfs keys stores by name, not directory.
|
|
39
|
+
dataDirectory: 'pxe_data',
|
|
39
40
|
autoSync: false,
|
|
40
41
|
...mergedConfigOverrides,
|
|
41
42
|
});
|
|
@@ -47,7 +48,11 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
|
47
48
|
const pxeOptions: PXECreationOptions = {
|
|
48
49
|
...mergedCreationOverrides,
|
|
49
50
|
preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
|
|
50
|
-
getPreloadedContracts: async () => [
|
|
51
|
+
getPreloadedContracts: async () => [
|
|
52
|
+
await getStandardMultiCallEntrypoint(),
|
|
53
|
+
await getStandardAuthRegistry(),
|
|
54
|
+
await getStandardHandshakeRegistry(),
|
|
55
|
+
],
|
|
51
56
|
},
|
|
52
57
|
loggers: {
|
|
53
58
|
store: rootLogger.createChild('pxe:data'),
|
|
@@ -59,20 +64,20 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
|
59
64
|
|
|
60
65
|
const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
|
|
61
66
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
(options.ephemeral
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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(
|
|
74
|
+
'wallet_data',
|
|
75
|
+
WALLET_DATA_SCHEMA_VERSION,
|
|
76
|
+
{ l1ChainId, rollupAddress: l1ContractAddresses.rollupAddress },
|
|
77
|
+
rootLogger.createChild('wallet:data'),
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
76
81
|
const walletDB = new WalletDB(walletDBStore, rootLogger.createChild('wallet:db').info);
|
|
77
82
|
|
|
78
83
|
const wallet = new this(pxe, aztecNode, walletDB, new LazyAccountContractsProvider(), rootLogger) as T;
|
|
@@ -85,10 +90,3 @@ export { BrowserEmbeddedWallet as EmbeddedWallet };
|
|
|
85
90
|
export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
|
|
86
91
|
export { WalletDB } from '../wallet_db.js';
|
|
87
92
|
export type { AccountType } from '../wallet_db.js';
|
|
88
|
-
|
|
89
|
-
// At-rest encryption helpers are intentionally NOT re-exported here. They live
|
|
90
|
-
// on the `@aztec/wallets/embedded/store-encryption` sub-path so consumers
|
|
91
|
-
// (and bundlers) of this entrypoint don't transitively pull in
|
|
92
|
-
// `@aztec/kv-store/sqlite-opfs` and its `new Worker(new URL('./worker.js'))`
|
|
93
|
-
// chain into `@aztec/sqlite3mc-wasm`. Apps that don't use encryption-at-rest
|
|
94
|
-
// (e.g. the playground) should never see sqlite-opfs in their bundle.
|
|
@@ -1,16 +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
6
|
import { getStandardAuthRegistry } from '@aztec/standard-contracts/auth-registry';
|
|
7
|
+
import { getStandardHandshakeRegistry } from '@aztec/standard-contracts/handshake-registry';
|
|
7
8
|
import { getStandardMultiCallEntrypoint } from '@aztec/standard-contracts/multi-call-entrypoint';
|
|
8
9
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
9
10
|
|
|
10
11
|
import { BundleAccountContractsProvider } from '../account-contract-providers/bundle.js';
|
|
11
12
|
import type { AccountContractsProvider } from '../account-contract-providers/types.js';
|
|
12
13
|
import { EmbeddedWallet, type EmbeddedWalletOptions, splitPxeOptions } from '../embedded_wallet.js';
|
|
13
|
-
import { WalletDB } from '../wallet_db.js';
|
|
14
|
+
import { WALLET_DATA_SCHEMA_VERSION, WalletDB } from '../wallet_db.js';
|
|
15
|
+
|
|
16
|
+
const DEFAULT_WALLET_DATA_DIRECTORY = 'aztec-wallet-data';
|
|
14
17
|
|
|
15
18
|
export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
16
19
|
static async create<T extends NodeEmbeddedWallet = NodeEmbeddedWallet>(
|
|
@@ -27,7 +30,6 @@ export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
|
27
30
|
const rootLogger = options.logger ?? createLogger('embedded-wallet');
|
|
28
31
|
|
|
29
32
|
const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
|
|
30
|
-
const l1Contracts = await aztecNode.getL1ContractAddresses();
|
|
31
33
|
|
|
32
34
|
// Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
|
|
33
35
|
const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
|
|
@@ -35,8 +37,8 @@ export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
|
35
37
|
const mergedCreationOverrides: PXECreationOptions = { ...options.pxeOptions, ...pxeCreationFromPxe };
|
|
36
38
|
|
|
37
39
|
const pxeConfig: PXEConfig = Object.assign(getPXEConfig(), {
|
|
38
|
-
proverEnabled: mergedConfigOverrides.proverEnabled
|
|
39
|
-
dataDirectory:
|
|
40
|
+
proverEnabled: mergedConfigOverrides.proverEnabled,
|
|
41
|
+
dataDirectory: DEFAULT_WALLET_DATA_DIRECTORY,
|
|
40
42
|
autoSync: false,
|
|
41
43
|
...mergedConfigOverrides,
|
|
42
44
|
});
|
|
@@ -48,7 +50,11 @@ export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
|
48
50
|
const pxeOptions: PXECreationOptions = {
|
|
49
51
|
...mergedCreationOverrides,
|
|
50
52
|
preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
|
|
51
|
-
getPreloadedContracts: async () => [
|
|
53
|
+
getPreloadedContracts: async () => [
|
|
54
|
+
await getStandardMultiCallEntrypoint(),
|
|
55
|
+
await getStandardAuthRegistry(),
|
|
56
|
+
await getStandardHandshakeRegistry(),
|
|
57
|
+
],
|
|
52
58
|
},
|
|
53
59
|
loggers: {
|
|
54
60
|
store: rootLogger.createChild('pxe:data'),
|
|
@@ -60,26 +66,26 @@ export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
|
60
66
|
|
|
61
67
|
const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
|
|
62
68
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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(
|
|
77
|
+
'wallet_data',
|
|
78
|
+
WALLET_DATA_SCHEMA_VERSION,
|
|
79
|
+
{
|
|
80
|
+
dataDirectory: pxeConfig.dataDirectory ?? DEFAULT_WALLET_DATA_DIRECTORY,
|
|
81
|
+
dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
|
|
82
|
+
l1ChainId,
|
|
83
|
+
rollupAddress: l1ContractAddresses.rollupAddress,
|
|
84
|
+
},
|
|
85
|
+
bindings,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
83
89
|
const walletDB = new WalletDB(walletDBStore, rootLogger.createChild('wallet:db').info);
|
|
84
90
|
|
|
85
91
|
const wallet = new this(pxe, aztecNode, walletDB, new BundleAccountContractsProvider(), rootLogger) as T;
|
|
@@ -8,7 +8,12 @@
|
|
|
8
8
|
* surfaces, so callers don't leak the SAH Pool's OPFS lock.
|
|
9
9
|
*/
|
|
10
10
|
import type { Logger } from '@aztec/foundation/log';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
AztecSQLiteOPFSStore,
|
|
13
|
+
SqliteCorruptionError,
|
|
14
|
+
SqliteEncryptionError,
|
|
15
|
+
deletePoolDirectory,
|
|
16
|
+
} from '@aztec/kv-store/sqlite-opfs';
|
|
12
17
|
|
|
13
18
|
/** Which of the embedded wallet's two stores failed to open. */
|
|
14
19
|
export type EmbeddedStoreName = 'pxe' | 'wallet';
|
|
@@ -49,6 +54,28 @@ export type OpenSqliteEncryptedStoreFn = (
|
|
|
49
54
|
const defaultOpenStore: OpenSqliteEncryptedStoreFn = (log, name, poolDirectory, encryptionKey) =>
|
|
50
55
|
AztecSQLiteOPFSStore.open(log, name, false, poolDirectory, encryptionKey);
|
|
51
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Internal seam for tests to inject a fake store wiper. Defaults to removing the store's OPFS pool directory
|
|
59
|
+
* outright. Not part of the public API.
|
|
60
|
+
*
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
export type WipeSqliteStoreFn = (poolDirectory: string | undefined) => Promise<void>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Deletes a store's OPFS pool directory. Safe to call only after a *failed* open() — a live store's SAH pool holds
|
|
67
|
+
* a lock on the directory and the removal would reject. A store with no `poolDirectory` lives in the shared default
|
|
68
|
+
* pool, which we won't blow away (it would take unrelated stores with it), so wiping is a no-op there.
|
|
69
|
+
*/
|
|
70
|
+
const defaultWipeStore: WipeSqliteStoreFn = async poolDirectory => {
|
|
71
|
+
if (!poolDirectory) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
await deletePoolDirectory(poolDirectory).catch(() => {
|
|
75
|
+
// Already gone / never created — nothing to wipe.
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
52
79
|
/**
|
|
53
80
|
* Opens the PXE and wallet stores in sequence, both encrypted with keys obtained from `getEncryptionKey`.
|
|
54
81
|
*
|
|
@@ -75,10 +102,11 @@ export async function openEncryptedEmbeddedStores(
|
|
|
75
102
|
getEncryptionKey: () => Promise<Uint8Array>,
|
|
76
103
|
log: Logger,
|
|
77
104
|
openStore: OpenSqliteEncryptedStoreFn = defaultOpenStore,
|
|
105
|
+
wipeStore: WipeSqliteStoreFn = defaultWipeStore,
|
|
78
106
|
): Promise<{ pxeStore: AztecSQLiteOPFSStore; walletStore: AztecSQLiteOPFSStore }> {
|
|
79
|
-
const pxeStore = await openOneStore('pxe', config.pxe, getEncryptionKey, log, openStore);
|
|
107
|
+
const pxeStore = await openOneStore('pxe', config.pxe, getEncryptionKey, log, openStore, wipeStore);
|
|
80
108
|
try {
|
|
81
|
-
const walletStore = await openOneStore('wallet', config.wallet, getEncryptionKey, log, openStore);
|
|
109
|
+
const walletStore = await openOneStore('wallet', config.wallet, getEncryptionKey, log, openStore, wipeStore);
|
|
82
110
|
return { pxeStore, walletStore };
|
|
83
111
|
} catch (err) {
|
|
84
112
|
// Cleanup is best-effort — if close() itself throws (e.g. worker already dead), swallow it so the original error
|
|
@@ -94,6 +122,7 @@ async function openOneStore(
|
|
|
94
122
|
getEncryptionKey: () => Promise<Uint8Array>,
|
|
95
123
|
log: Logger,
|
|
96
124
|
openStore: OpenSqliteEncryptedStoreFn,
|
|
125
|
+
wipeStore: WipeSqliteStoreFn,
|
|
97
126
|
): Promise<AztecSQLiteOPFSStore> {
|
|
98
127
|
const key = await getEncryptionKey();
|
|
99
128
|
try {
|
|
@@ -102,6 +131,16 @@ async function openOneStore(
|
|
|
102
131
|
if (err instanceof SqliteEncryptionError && err.code === 'decrypt_failed') {
|
|
103
132
|
throw new EmbeddedWalletEncryptionError(storeName, { cause: err });
|
|
104
133
|
}
|
|
134
|
+
if (err instanceof SqliteCorruptionError) {
|
|
135
|
+
// A corrupt image is unrecoverable — no key or retry against the same bytes brings it back. Self-heal
|
|
136
|
+
// instead of dead-ending forever: wipe the store's OPFS directory (safe — the failed open left no SAH-pool
|
|
137
|
+
// lock behind) and reopen a fresh, empty one, so callers see a normal first-run rather than a permanent
|
|
138
|
+
// "database disk image is malformed" on every open.
|
|
139
|
+
log.warn(`Embedded wallet '${storeName}' store is corrupt (${err.message}); wiping and reopening fresh`);
|
|
140
|
+
await wipeStore(poolDirectory);
|
|
141
|
+
// open() transferred (detached) the previous key buffer, so fetch a fresh one for the reopen.
|
|
142
|
+
return await openStore(log, name, poolDirectory, await getEncryptionKey());
|
|
143
|
+
}
|
|
105
144
|
throw err;
|
|
106
145
|
}
|
|
107
146
|
}
|
|
@@ -4,13 +4,16 @@ import type { LogFn } from '@aztec/foundation/log';
|
|
|
4
4
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
5
5
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
6
|
|
|
7
|
-
export const AccountTypes = ['schnorr', 'ecdsasecp256r1', 'ecdsasecp256k1'] as const;
|
|
7
|
+
export const AccountTypes = ['schnorr', 'schnorr_initializerless', 'ecdsasecp256r1', 'ecdsasecp256k1'] as const;
|
|
8
8
|
export type AccountType = (typeof AccountTypes)[number];
|
|
9
9
|
|
|
10
10
|
function accountKey(field: string, address: AztecAddress | string): string {
|
|
11
11
|
return `${field}:${address.toString()}`;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
/** Bump when the WalletDB layout changes; a new version selects a fresh store, leaving the old one intact. */
|
|
15
|
+
export const WALLET_DATA_SCHEMA_VERSION = 1;
|
|
16
|
+
|
|
14
17
|
export class WalletDB {
|
|
15
18
|
private accounts: AztecAsyncMap<string, Buffer>;
|
|
16
19
|
private aliases: AztecAsyncMap<string, Buffer>;
|
|
@@ -83,7 +86,7 @@ export class WalletDB {
|
|
|
83
86
|
|
|
84
87
|
return accountAddresses.map(addressStr => ({
|
|
85
88
|
alias: aliasesByAddress.get(addressStr) ?? '',
|
|
86
|
-
item: AztecAddress.
|
|
89
|
+
item: AztecAddress.fromStringUnsafe(addressStr),
|
|
87
90
|
}));
|
|
88
91
|
}
|
|
89
92
|
|
|
@@ -92,7 +95,7 @@ export class WalletDB {
|
|
|
92
95
|
for await (const [alias, item] of this.aliases.entriesAsync({ start: 'senders:', end: 'senders:\uffff' })) {
|
|
93
96
|
result.push({
|
|
94
97
|
alias: alias.slice('senders:'.length),
|
|
95
|
-
item: AztecAddress.
|
|
98
|
+
item: AztecAddress.fromStringUnsafe(item.toString()),
|
|
96
99
|
});
|
|
97
100
|
}
|
|
98
101
|
return result;
|
package/src/testing.ts
CHANGED
|
@@ -1,32 +1,25 @@
|
|
|
1
1
|
import type { InitialAccountData } from '@aztec/accounts/testing';
|
|
2
2
|
import { getInitialTestAccountsData } from '@aztec/accounts/testing/lazy';
|
|
3
|
-
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
4
|
-
import type { WaitOpts } from '@aztec/aztec.js/contracts';
|
|
5
3
|
import type { AccountManager } from '@aztec/aztec.js/wallet';
|
|
6
4
|
import type { Fq, Fr } from '@aztec/foundation/curves/bn254';
|
|
7
5
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
6
|
|
|
9
7
|
interface WalletWithSchnorrAccounts {
|
|
10
|
-
|
|
8
|
+
createSchnorrInitializerlessAccount(secret: Fr, salt: Fr, signingKey: Fq, alias?: string): Promise<AccountManager>;
|
|
11
9
|
}
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Creates the given (genesis-funded) test accounts as initializerless schnorr accounts. Initializerless
|
|
13
|
+
* accounts need no deployment tx — creating one registers the instance and materializes its immutable keys
|
|
14
|
+
* locally — so the accounts are usable as soon as they are created, funded via genesis at their addresses.
|
|
15
|
+
*/
|
|
16
|
+
export async function createFundedInitializerlessAccounts(
|
|
14
17
|
wallet: WalletWithSchnorrAccounts,
|
|
15
18
|
accountsData: InitialAccountData[],
|
|
16
|
-
waitOptions?: WaitOpts,
|
|
17
19
|
) {
|
|
18
20
|
const accountManagers = [];
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const { secret, salt, signingKey } = accountsData[i];
|
|
22
|
-
const accountManager = await wallet.createSchnorrAccount(secret, salt, signingKey);
|
|
23
|
-
const deployMethod = await accountManager.getDeployMethod();
|
|
24
|
-
await deployMethod.send({
|
|
25
|
-
from: NO_FROM,
|
|
26
|
-
skipClassPublication: i !== 0,
|
|
27
|
-
wait: waitOptions,
|
|
28
|
-
});
|
|
29
|
-
accountManagers.push(accountManager);
|
|
21
|
+
for (const { secret, salt, signingKey } of accountsData) {
|
|
22
|
+
accountManagers.push(await wallet.createSchnorrInitializerlessAccount(secret, salt, signingKey));
|
|
30
23
|
}
|
|
31
24
|
return accountManagers;
|
|
32
25
|
}
|
|
@@ -37,7 +30,8 @@ export async function registerInitialLocalNetworkAccountsInWallet(
|
|
|
37
30
|
const testAccounts = await getInitialTestAccountsData();
|
|
38
31
|
return Promise.all(
|
|
39
32
|
testAccounts.map(async account => {
|
|
40
|
-
return (await wallet.
|
|
33
|
+
return (await wallet.createSchnorrInitializerlessAccount(account.secret, account.salt, account.signingKey))
|
|
34
|
+
.address;
|
|
41
35
|
}),
|
|
42
36
|
);
|
|
43
37
|
}
|