@aztec/wallets 0.0.1-commit.b9865e97 → 0.0.1-commit.be03c316
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 +53 -17
- 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 +42 -25
- 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,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
|
}
|