@aztec-labs/wallets 6.0.0-nightly.20260829

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.
Files changed (41) hide show
  1. package/dest/embedded/account-contract-providers/bundle.d.ts +19 -0
  2. package/dest/embedded/account-contract-providers/bundle.d.ts.map +1 -0
  3. package/dest/embedded/account-contract-providers/bundle.js +29 -0
  4. package/dest/embedded/account-contract-providers/lazy.d.ts +19 -0
  5. package/dest/embedded/account-contract-providers/lazy.d.ts.map +1 -0
  6. package/dest/embedded/account-contract-providers/lazy.js +39 -0
  7. package/dest/embedded/account-contract-providers/types.d.ts +20 -0
  8. package/dest/embedded/account-contract-providers/types.d.ts.map +1 -0
  9. package/dest/embedded/account-contract-providers/types.js +6 -0
  10. package/dest/embedded/embedded_wallet.d.ts +103 -0
  11. package/dest/embedded/embedded_wallet.d.ts.map +1 -0
  12. package/dest/embedded/embedded_wallet.js +359 -0
  13. package/dest/embedded/entrypoints/browser.d.ts +14 -0
  14. package/dest/embedded/entrypoints/browser.d.ts.map +1 -0
  15. package/dest/embedded/entrypoints/browser.js +72 -0
  16. package/dest/embedded/entrypoints/node.d.ts +14 -0
  17. package/dest/embedded/entrypoints/node.d.ts.map +1 -0
  18. package/dest/embedded/entrypoints/node.js +75 -0
  19. package/dest/embedded/entrypoints/resolve_aztec_node.d.ts +4 -0
  20. package/dest/embedded/entrypoints/resolve_aztec_node.d.ts.map +1 -0
  21. package/dest/embedded/entrypoints/resolve_aztec_node.js +4 -0
  22. package/dest/embedded/store_encryption.d.ts +74 -0
  23. package/dest/embedded/store_encryption.d.ts.map +1 -0
  24. package/dest/embedded/store_encryption.js +93 -0
  25. package/dest/embedded/wallet_db.d.ts +41 -0
  26. package/dest/embedded/wallet_db.d.ts.map +1 -0
  27. package/dest/embedded/wallet_db.js +133 -0
  28. package/dest/testing.d.ts +16 -0
  29. package/dest/testing.d.ts.map +1 -0
  30. package/dest/testing.js +18 -0
  31. package/package.json +102 -0
  32. package/src/embedded/account-contract-providers/bundle.ts +43 -0
  33. package/src/embedded/account-contract-providers/lazy.ts +53 -0
  34. package/src/embedded/account-contract-providers/types.ts +21 -0
  35. package/src/embedded/embedded_wallet.ts +481 -0
  36. package/src/embedded/entrypoints/browser.ts +93 -0
  37. package/src/embedded/entrypoints/node.ts +100 -0
  38. package/src/embedded/entrypoints/resolve_aztec_node.ts +10 -0
  39. package/src/embedded/store_encryption.ts +146 -0
  40. package/src/embedded/wallet_db.ts +150 -0
  41. package/src/testing.ts +37 -0
@@ -0,0 +1,14 @@
1
+ import type { AztecNode } from '@aztec-labs/aztec.js/node';
2
+ import { type Logger } from '@aztec-labs/foundation/log';
3
+ import { type PXE } from '@aztec-labs/pxe/client/lazy';
4
+ import type { AccountContractsProvider } from '../account-contract-providers/types.js';
5
+ import { EmbeddedWallet, type EmbeddedWalletOptions } from '../embedded_wallet.js';
6
+ import { WalletDB } from '../wallet_db.js';
7
+ export declare class BrowserEmbeddedWallet extends EmbeddedWallet {
8
+ static create<T extends BrowserEmbeddedWallet = BrowserEmbeddedWallet>(this: new (pxe: PXE, aztecNode: AztecNode, walletDB: WalletDB, accountContracts: AccountContractsProvider, log?: Logger) => T, nodeOrUrl: string | AztecNode, options?: EmbeddedWalletOptions): Promise<T>;
9
+ }
10
+ export { BrowserEmbeddedWallet as EmbeddedWallet };
11
+ export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
12
+ export { WalletDB } from '../wallet_db.js';
13
+ export type { AccountType } from '../wallet_db.js';
14
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnJvd3Nlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2VtYmVkZGVkL2VudHJ5cG9pbnRzL2Jyb3dzZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsU0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0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../src/embedded/entrypoints/browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,4BAA4B,CAAC;AAEvE,OAAO,EAAE,KAAK,GAAG,EAAwD,MAAM,6BAA6B,CAAC;AAO7G,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAmB,MAAM,uBAAuB,CAAC;AACpG,OAAO,EAA8B,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGvE,qBAAa,qBAAsB,SAAQ,cAAc;IACvD,OAAa,MAAM,CAAC,CAAC,SAAS,qBAAqB,GAAG,qBAAqB,EACzE,IAAI,EAAE,KACJ,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,gBAAgB,EAAE,wBAAwB,EAC1C,GAAG,CAAC,EAAE,MAAM,KACT,CAAC,EACN,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,CAAC,CAAC,CA4DZ;CACF;AAED,OAAO,EAAE,qBAAqB,IAAI,cAAc,EAAE,CAAC;AACnD,YAAY,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAC7F,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,72 @@
1
+ import { createLogger } from '@aztec-labs/foundation/log';
2
+ import { openTmpStore } from '@aztec-labs/kv-store/sqlite-opfs';
3
+ import { createPXE, openBrowserStore } from '@aztec-labs/pxe/client/lazy';
4
+ import { getPXEConfig } from '@aztec-labs/pxe/config';
5
+ import { getStandardAuthRegistry } from '@aztec-labs/standard-contracts/auth-registry/lazy';
6
+ import { getStandardHandshakeRegistry } from '@aztec-labs/standard-contracts/handshake-registry/lazy';
7
+ import { getStandardMultiCallEntrypoint } from '@aztec-labs/standard-contracts/multi-call-entrypoint/lazy';
8
+ import { LazyAccountContractsProvider } from '../account-contract-providers/lazy.js';
9
+ import { EmbeddedWallet, splitPxeOptions } from '../embedded_wallet.js';
10
+ import { WALLET_DATA_SCHEMA_VERSION, WalletDB } from '../wallet_db.js';
11
+ import { resolveAztecNode } from './resolve_aztec_node.js';
12
+ export class BrowserEmbeddedWallet extends EmbeddedWallet {
13
+ static async create(nodeOrUrl, options = {}) {
14
+ const rootLogger = options.logger ?? createLogger('embedded-wallet');
15
+ const aztecNode = resolveAztecNode(nodeOrUrl, options.nodeClientOptions);
16
+ // Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
17
+ const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
18
+ const mergedConfigOverrides = {
19
+ ...options.pxeConfig,
20
+ ...pxeConfigFromPxe
21
+ };
22
+ const mergedCreationOverrides = {
23
+ ...options.pxeOptions,
24
+ ...pxeCreationFromPxe
25
+ };
26
+ const pxeConfig = Object.assign(getPXEConfig(), {
27
+ proverEnabled: mergedConfigOverrides.proverEnabled,
28
+ // Unused in the browser: sqlite-opfs keys stores by name, not directory.
29
+ dataDirectory: 'pxe_data',
30
+ autoSync: false,
31
+ ...mergedConfigOverrides
32
+ });
33
+ if (options.ephemeral) {
34
+ delete pxeConfig.dataDirectory;
35
+ }
36
+ const pxeOptions = {
37
+ ...mergedCreationOverrides,
38
+ preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
39
+ getPreloadedContracts: async ()=>[
40
+ await getStandardMultiCallEntrypoint(),
41
+ await getStandardAuthRegistry(),
42
+ await getStandardHandshakeRegistry()
43
+ ]
44
+ },
45
+ loggers: {
46
+ store: rootLogger.createChild('pxe:data'),
47
+ pxe: rootLogger.createChild('pxe:service'),
48
+ prover: rootLogger.createChild('pxe:prover'),
49
+ ...mergedCreationOverrides.loggers
50
+ }
51
+ };
52
+ const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
53
+ let walletDBStore = options.walletDb?.store;
54
+ if (!walletDBStore) {
55
+ if (options.ephemeral) {
56
+ walletDBStore = await openTmpStore(true);
57
+ } else {
58
+ const { l1ChainId, l1ContractAddresses } = await aztecNode.getNodeInfo();
59
+ walletDBStore = await openBrowserStore('wallet_data', WALLET_DATA_SCHEMA_VERSION, {
60
+ l1ChainId,
61
+ rollupAddress: l1ContractAddresses.rollupAddress
62
+ }, rootLogger.createChild('wallet:data'));
63
+ }
64
+ }
65
+ const walletDB = new WalletDB(walletDBStore, rootLogger.createChild('wallet:db').info);
66
+ const wallet = new this(pxe, aztecNode, walletDB, new LazyAccountContractsProvider(), rootLogger);
67
+ await wallet.initStubClasses();
68
+ return wallet;
69
+ }
70
+ }
71
+ export { BrowserEmbeddedWallet as EmbeddedWallet };
72
+ export { WalletDB } from '../wallet_db.js';
@@ -0,0 +1,14 @@
1
+ import { type Logger } from '@aztec-labs/foundation/log';
2
+ import { type PXE } from '@aztec-labs/pxe/server';
3
+ import type { AztecNode } from '@aztec-labs/stdlib/interfaces/client';
4
+ import type { AccountContractsProvider } from '../account-contract-providers/types.js';
5
+ import { EmbeddedWallet, type EmbeddedWalletOptions } from '../embedded_wallet.js';
6
+ import { WalletDB } from '../wallet_db.js';
7
+ export declare class NodeEmbeddedWallet extends EmbeddedWallet {
8
+ static create<T extends NodeEmbeddedWallet = NodeEmbeddedWallet>(this: new (pxe: PXE, aztecNode: AztecNode, walletDB: WalletDB, accountContracts: AccountContractsProvider, log?: Logger) => T, nodeOrUrl: string | AztecNode, options?: EmbeddedWalletOptions): Promise<T>;
9
+ }
10
+ export { NodeEmbeddedWallet as EmbeddedWallet };
11
+ export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
12
+ export { WalletDB } from '../wallet_db.js';
13
+ export type { AccountType } from '../wallet_db.js';
14
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm9kZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2VtYmVkZGVkL2VudHJ5cG9pbnRzL25vZGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEtBQUssTUFBTSxFQUFnQixNQUFNLDRCQUE0QixDQUFDO0FBR3ZFLE9BQU8sRUFBRSxLQUFLLEdBQUcsRUFBaUQsTUFBTSx3QkFBd0IsQ0FBQztBQUlqRyxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxzQ0FBc0MsQ0FBQztBQUd0RSxPQUFPLEtBQUssRUFBRSx3QkFBd0IsRUFBRSxNQUFNLHdDQUF3QyxDQUFDO0FBQ3ZGLE9BQU8sRUFBRSxjQUFjLEVBQUUsS0FBSyxxQkFBcUIsRUFBbUIsTUFBTSx1QkFBdUIsQ0FBQztBQUNwRyxPQUFPLEVBQThCLFFBQVEsRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBS3ZFLHFCQUFhLGtCQUFtQixTQUFRLGNBQWM7SUFDcEQsT0FBYSxNQUFNLENBQUMsQ0FBQyxTQUFTLGtCQUFrQixHQUFHLGtCQUFrQixFQUNuRSxJQUFJLEVBQUUsS0FDSixHQUFHLEVBQUUsR0FBRyxFQUNSLFNBQVMsRUFBRSxTQUFTLEVBQ3BCLFFBQVEsRUFBRSxRQUFRLEVBQ2xCLGdCQUFnQixFQUFFLHdCQUF3QixFQUMxQyxHQUFHLENBQUMsRUFBRSxNQUFNLEtBQ1QsQ0FBQyxFQUNOLFNBQVMsRUFBRSxNQUFNLEdBQUcsU0FBUyxFQUM3QixPQUFPLEdBQUUscUJBQTBCLEdBQ2xDLE9BQU8sQ0FBQyxDQUFDLENBQUMs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AM,uBAAuB,CAAC;AAC7F,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,75 @@
1
+ import { createLogger } from '@aztec-labs/foundation/log';
2
+ import { openTmpStore } from '@aztec-labs/kv-store/lmdb-v2';
3
+ import { getPXEConfig } from '@aztec-labs/pxe/config';
4
+ import { createPXE, openStore } from '@aztec-labs/pxe/server';
5
+ import { getStandardAuthRegistry } from '@aztec-labs/standard-contracts/auth-registry';
6
+ import { getStandardHandshakeRegistry } from '@aztec-labs/standard-contracts/handshake-registry';
7
+ import { getStandardMultiCallEntrypoint } from '@aztec-labs/standard-contracts/multi-call-entrypoint';
8
+ import { BundleAccountContractsProvider } from '../account-contract-providers/bundle.js';
9
+ import { EmbeddedWallet, splitPxeOptions } from '../embedded_wallet.js';
10
+ import { WALLET_DATA_SCHEMA_VERSION, WalletDB } from '../wallet_db.js';
11
+ import { resolveAztecNode } from './resolve_aztec_node.js';
12
+ const DEFAULT_WALLET_DATA_DIRECTORY = 'aztec-wallet-data';
13
+ export class NodeEmbeddedWallet extends EmbeddedWallet {
14
+ static async create(nodeOrUrl, options = {}) {
15
+ const rootLogger = options.logger ?? createLogger('embedded-wallet');
16
+ const aztecNode = resolveAztecNode(nodeOrUrl, options.nodeClientOptions);
17
+ // Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
18
+ const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
19
+ const mergedConfigOverrides = {
20
+ ...options.pxeConfig,
21
+ ...pxeConfigFromPxe
22
+ };
23
+ const mergedCreationOverrides = {
24
+ ...options.pxeOptions,
25
+ ...pxeCreationFromPxe
26
+ };
27
+ const pxeConfig = Object.assign(getPXEConfig(), {
28
+ proverEnabled: mergedConfigOverrides.proverEnabled,
29
+ dataDirectory: DEFAULT_WALLET_DATA_DIRECTORY,
30
+ autoSync: false,
31
+ ...mergedConfigOverrides
32
+ });
33
+ if (options.ephemeral) {
34
+ delete pxeConfig.dataDirectory;
35
+ }
36
+ const pxeOptions = {
37
+ ...mergedCreationOverrides,
38
+ preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
39
+ getPreloadedContracts: async ()=>[
40
+ await getStandardMultiCallEntrypoint(),
41
+ await getStandardAuthRegistry(),
42
+ await getStandardHandshakeRegistry()
43
+ ]
44
+ },
45
+ loggers: {
46
+ store: rootLogger.createChild('pxe:data'),
47
+ pxe: rootLogger.createChild('pxe:service'),
48
+ prover: rootLogger.createChild('pxe:prover'),
49
+ ...mergedCreationOverrides.loggers
50
+ }
51
+ };
52
+ const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
53
+ let walletDBStore = options.walletDb?.store;
54
+ if (!walletDBStore) {
55
+ const bindings = rootLogger.createChild('wallet:data').getBindings();
56
+ if (options.ephemeral) {
57
+ walletDBStore = await openTmpStore('wallet_data', true, undefined, undefined, bindings);
58
+ } else {
59
+ const { l1ChainId, l1ContractAddresses } = await aztecNode.getNodeInfo();
60
+ walletDBStore = await openStore('wallet_data', WALLET_DATA_SCHEMA_VERSION, {
61
+ dataDirectory: pxeConfig.dataDirectory ?? DEFAULT_WALLET_DATA_DIRECTORY,
62
+ dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
63
+ l1ChainId,
64
+ rollupAddress: l1ContractAddresses.rollupAddress
65
+ }, bindings);
66
+ }
67
+ }
68
+ const walletDB = new WalletDB(walletDBStore, rootLogger.createChild('wallet:db').info);
69
+ const wallet = new this(pxe, aztecNode, walletDB, new BundleAccountContractsProvider(), rootLogger);
70
+ await wallet.initStubClasses();
71
+ return wallet;
72
+ }
73
+ }
74
+ export { NodeEmbeddedWallet as EmbeddedWallet };
75
+ export { WalletDB } from '../wallet_db.js';
@@ -0,0 +1,4 @@
1
+ import { type AztecNode, type AztecNodeClientOptions } from '@aztec-labs/stdlib/interfaces/client';
2
+ /** Returns a provided node or creates a JSON-RPC client for a node URL. */
3
+ export declare function resolveAztecNode(nodeOrUrl: string | AztecNode, nodeClientOptions?: AztecNodeClientOptions): AztecNode;
4
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVzb2x2ZV9henRlY19ub2RlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvZW1iZWRkZWQvZW50cnlwb2ludHMvcmVzb2x2ZV9henRlY19ub2RlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFDTCxLQUFLLFNBQVMsRUFDZCxLQUFLLHNCQUFzQixFQUU1QixNQUFNLHNDQUFzQyxDQUFDO0FBRTlDLDJFQUEyRTtBQUMzRSx3QkFBZ0IsZ0JBQWdCLENBQUMsU0FBUyxFQUFFLE1BQU0sR0FBRyxTQUFTLEVBQUUsaUJBQWlCLENBQUMsRUFBRSxzQkFBc0IsR0FBRyxTQUFTLENBRXJIIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve_aztec_node.d.ts","sourceRoot":"","sources":["../../../src/embedded/entrypoints/resolve_aztec_node.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,sBAAsB,EAE5B,MAAM,sCAAsC,CAAC;AAE9C,2EAA2E;AAC3E,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,iBAAiB,CAAC,EAAE,sBAAsB,GAAG,SAAS,CAErH"}
@@ -0,0 +1,4 @@
1
+ import { createAztecNodeClient } from '@aztec-labs/stdlib/interfaces/client';
2
+ /** Returns a provided node or creates a JSON-RPC client for a node URL. */ export function resolveAztecNode(nodeOrUrl, nodeClientOptions) {
3
+ return typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl, nodeClientOptions) : nodeOrUrl;
4
+ }
@@ -0,0 +1,74 @@
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-labs/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-labs/foundation/log';
11
+ import { AztecSQLiteOPFSStore, SqliteEncryptionError } from '@aztec-labs/kv-store/sqlite-opfs';
12
+ /** Which of the embedded wallet's two stores failed to open. */
13
+ export type EmbeddedStoreName = 'pxe' | 'wallet';
14
+ /**
15
+ * Thrown by {@link openEncryptedEmbeddedStores} when one of the two stores cannot be decrypted with the supplied
16
+ * key. The original {@link SqliteEncryptionError} is preserved as `cause`.
17
+ */
18
+ export declare class EmbeddedWalletEncryptionError extends Error {
19
+ readonly storeName: EmbeddedStoreName;
20
+ constructor(storeName: EmbeddedStoreName, opts: {
21
+ cause: SqliteEncryptionError;
22
+ });
23
+ }
24
+ /** Configuration for {@link openEncryptedEmbeddedStores}. */
25
+ export interface OpenEncryptedEmbeddedStoresOptions {
26
+ pxe: {
27
+ name: string;
28
+ poolDirectory?: string;
29
+ };
30
+ wallet: {
31
+ name: string;
32
+ poolDirectory?: string;
33
+ };
34
+ }
35
+ /**
36
+ * Internal seam for tests to inject a fake store opener. Defaults to `AztecSQLiteOPFSStore.open`. Not part of the
37
+ * public API.
38
+ *
39
+ * @internal
40
+ */
41
+ export type OpenSqliteEncryptedStoreFn = (log: Logger, name: string, poolDirectory: string | undefined, encryptionKey: Uint8Array) => Promise<AztecSQLiteOPFSStore>;
42
+ /**
43
+ * Internal seam for tests to inject a fake store wiper. Defaults to removing the store's OPFS pool directory
44
+ * outright. Not part of the public API.
45
+ *
46
+ * @internal
47
+ */
48
+ export type WipeSqliteStoreFn = (poolDirectory: string | undefined) => Promise<void>;
49
+ /**
50
+ * Opens the PXE and wallet stores in sequence, both encrypted with keys obtained from `getEncryptionKey`.
51
+ *
52
+ * The callback is invoked once per store (twice total per call) because `AztecSQLiteOPFSStore.open` *transfers*
53
+ * the key buffer to its worker. A single buffer would detach between the two opens.
54
+ *
55
+ * Failure modes:
56
+ *
57
+ * - PXE store fails to decrypt → throws `EmbeddedWalletEncryptionError({ storeName: 'pxe', cause })`. No cleanup
58
+ * needed (nothing was opened).
59
+ * - Wallet store fails to decrypt → closes the already-opened PXE store then throws
60
+ * `EmbeddedWalletEncryptionError({ storeName: 'wallet', cause })`.
61
+ * - Any non-decrypt error during the wallet open → still closes PXE, then re-throws the original error unwrapped
62
+ * (preserves callers' existing untyped error handling for non-encryption faults).
63
+ *
64
+ * @param config - Per-store name/poolDirectory.
65
+ * @param getEncryptionKey - Returns a fresh 32-byte key per call (the buffer
66
+ * detaches on transfer, so each call must allocate).
67
+ * @param log - Logger for both stores.
68
+ * @param openStore - Internal test seam. Do not pass in production code.
69
+ */
70
+ export declare function openEncryptedEmbeddedStores(config: OpenEncryptedEmbeddedStoresOptions, getEncryptionKey: () => Promise<Uint8Array>, log: Logger, openStore?: OpenSqliteEncryptedStoreFn, wipeStore?: WipeSqliteStoreFn): Promise<{
71
+ pxeStore: AztecSQLiteOPFSStore;
72
+ walletStore: AztecSQLiteOPFSStore;
73
+ }>;
74
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RvcmVfZW5jcnlwdGlvbi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2VtYmVkZGVkL3N0b3JlX2VuY3J5cHRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7O0dBUUc7QUFDSCxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSw0QkFBNEIsQ0FBQztBQUN6RCxPQUFPLEVBQ0wsb0JBQW9C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MAAM,GAAG,SAAS,EACjC,aAAa,EAAE,UAAU,KACtB,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAKnC;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAgBrF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,kCAAkC,EAC1C,gBAAgB,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,EAC3C,GAAG,EAAE,MAAM,EACX,SAAS,GAAE,0BAA6C,EACxD,SAAS,GAAE,iBAAoC,GAC9C,OAAO,CAAC;IAAE,QAAQ,EAAE,oBAAoB,CAAC;IAAC,WAAW,EAAE,oBAAoB,CAAA;CAAE,CAAC,CAWhF"}
@@ -0,0 +1,93 @@
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-labs/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
+ */ import { AztecSQLiteOPFSStore, SqliteCorruptionError, SqliteEncryptionError, deletePoolDirectory } from '@aztec-labs/kv-store/sqlite-opfs';
10
+ /**
11
+ * Thrown by {@link openEncryptedEmbeddedStores} when one of the two stores cannot be decrypted with the supplied
12
+ * key. The original {@link SqliteEncryptionError} is preserved as `cause`.
13
+ */ export class EmbeddedWalletEncryptionError extends Error {
14
+ storeName;
15
+ constructor(storeName, opts){
16
+ super(`Embedded wallet '${storeName}' store could not be decrypted with the provided key`, {
17
+ cause: opts.cause
18
+ });
19
+ this.name = 'EmbeddedWalletEncryptionError';
20
+ this.storeName = storeName;
21
+ }
22
+ }
23
+ const defaultOpenStore = (log, name, poolDirectory, encryptionKey)=>AztecSQLiteOPFSStore.open(log, name, false, poolDirectory, encryptionKey);
24
+ /**
25
+ * Deletes a store's OPFS pool directory. Safe to call only after a *failed* open() — a live store's SAH pool holds
26
+ * a lock on the directory and the removal would reject. A store with no `poolDirectory` lives in the shared default
27
+ * pool, which we won't blow away (it would take unrelated stores with it), so wiping is a no-op there.
28
+ */ const defaultWipeStore = async (poolDirectory)=>{
29
+ if (!poolDirectory) {
30
+ return;
31
+ }
32
+ await deletePoolDirectory(poolDirectory).catch(()=>{
33
+ // Already gone / never created — nothing to wipe.
34
+ });
35
+ };
36
+ /**
37
+ * Opens the PXE and wallet stores in sequence, both encrypted with keys obtained from `getEncryptionKey`.
38
+ *
39
+ * The callback is invoked once per store (twice total per call) because `AztecSQLiteOPFSStore.open` *transfers*
40
+ * the key buffer to its worker. A single buffer would detach between the two opens.
41
+ *
42
+ * Failure modes:
43
+ *
44
+ * - PXE store fails to decrypt → throws `EmbeddedWalletEncryptionError({ storeName: 'pxe', cause })`. No cleanup
45
+ * needed (nothing was opened).
46
+ * - Wallet store fails to decrypt → closes the already-opened PXE store then throws
47
+ * `EmbeddedWalletEncryptionError({ storeName: 'wallet', cause })`.
48
+ * - Any non-decrypt error during the wallet open → still closes PXE, then re-throws the original error unwrapped
49
+ * (preserves callers' existing untyped error handling for non-encryption faults).
50
+ *
51
+ * @param config - Per-store name/poolDirectory.
52
+ * @param getEncryptionKey - Returns a fresh 32-byte key per call (the buffer
53
+ * detaches on transfer, so each call must allocate).
54
+ * @param log - Logger for both stores.
55
+ * @param openStore - Internal test seam. Do not pass in production code.
56
+ */ export async function openEncryptedEmbeddedStores(config, getEncryptionKey, log, openStore = defaultOpenStore, wipeStore = defaultWipeStore) {
57
+ const pxeStore = await openOneStore('pxe', config.pxe, getEncryptionKey, log, openStore, wipeStore);
58
+ try {
59
+ const walletStore = await openOneStore('wallet', config.wallet, getEncryptionKey, log, openStore, wipeStore);
60
+ return {
61
+ pxeStore,
62
+ walletStore
63
+ };
64
+ } catch (err) {
65
+ // Cleanup is best-effort — if close() itself throws (e.g. worker already dead), swallow it so the original error
66
+ // surfaces unobstructed.
67
+ await pxeStore.close().catch(()=>{});
68
+ throw err;
69
+ }
70
+ }
71
+ async function openOneStore(storeName, { name, poolDirectory }, getEncryptionKey, log, openStore, wipeStore) {
72
+ const key = await getEncryptionKey();
73
+ try {
74
+ return await openStore(log, name, poolDirectory, key);
75
+ } catch (err) {
76
+ if (err instanceof SqliteEncryptionError && err.code === 'decrypt_failed') {
77
+ throw new EmbeddedWalletEncryptionError(storeName, {
78
+ cause: err
79
+ });
80
+ }
81
+ if (err instanceof SqliteCorruptionError) {
82
+ // A corrupt image is unrecoverable — no key or retry against the same bytes brings it back. Self-heal
83
+ // instead of dead-ending forever: wipe the store's OPFS directory (safe — the failed open left no SAH-pool
84
+ // lock behind) and reopen a fresh, empty one, so callers see a normal first-run rather than a permanent
85
+ // "database disk image is malformed" on every open.
86
+ log.warn(`Embedded wallet '${storeName}' store is corrupt (${err.message}); wiping and reopening fresh`);
87
+ await wipeStore(poolDirectory);
88
+ // open() transferred (detached) the previous key buffer, so fetch a fresh one for the reopen.
89
+ return await openStore(log, name, poolDirectory, await getEncryptionKey());
90
+ }
91
+ throw err;
92
+ }
93
+ }
@@ -0,0 +1,41 @@
1
+ import type { Aliased } from '@aztec-labs/aztec.js/wallet';
2
+ import { Fq, Fr } from '@aztec-labs/foundation/curves/bn254';
3
+ import type { LogFn } from '@aztec-labs/foundation/log';
4
+ import type { AztecAsyncKVStore } from '@aztec-labs/kv-store';
5
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
6
+ export declare const AccountTypes: readonly ["schnorr", "schnorr_initializerless", "ecdsasecp256r1", "ecdsasecp256k1"];
7
+ export type AccountType = (typeof AccountTypes)[number];
8
+ /** Bump when the WalletDB layout changes; a new version selects a fresh store, leaving the old one intact. */
9
+ export declare const WALLET_DATA_SCHEMA_VERSION = 1;
10
+ export declare class WalletDB {
11
+ #private;
12
+ private store;
13
+ private userLog;
14
+ private accounts;
15
+ private aliases;
16
+ constructor(store: AztecAsyncKVStore, userLog: LogFn);
17
+ storeAccount(address: AztecAddress, { type, secretKey, salt, alias, signingKey }: {
18
+ type: AccountType;
19
+ secretKey: Fr;
20
+ salt: Fr;
21
+ signingKey: Fq | Buffer;
22
+ alias: string | undefined;
23
+ }, log?: LogFn): Promise<void>;
24
+ storeSender(address: AztecAddress, alias: string, log?: LogFn): Promise<void>;
25
+ retrieveAccount(address: AztecAddress | string): Promise<{
26
+ address: string | AztecAddress;
27
+ secretKey: Fr;
28
+ salt: Fr;
29
+ type: "ecdsasecp256k1" | "ecdsasecp256r1" | "schnorr" | "schnorr_initializerless";
30
+ signingKey: Buffer<ArrayBufferLike>;
31
+ }>;
32
+ listAccounts(): Promise<Aliased<AztecAddress>[]>;
33
+ listSenders(): Promise<Aliased<AztecAddress>[]>;
34
+ /**
35
+ * Deletes an account's stored data and every alias pointing at it atomically. Deletion is local to this store;
36
+ * any state the PXE holds for the account is unaffected.
37
+ */
38
+ deleteAccount(address: AztecAddress): Promise<void>;
39
+ close(): Promise<void>;
40
+ }
41
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2FsbGV0X2RiLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZW1iZWRkZWQvd2FsbGV0X2RiLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLE9BQU8sRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQzNELE9BQU8sRUFBRSxFQUFFLEVBQUUsRUFBRSxFQUFFLE1BQU0scUNBQXFDLENBQUM7QUFDN0QsT0FBTyxLQUFLLEVBQUUsS0FBSyxFQUFFLE1BQU0sNEJBQTRCLENBQUM7QUFDeEQsT0FBTyxLQUFLLEVBQUUsaUJBQWlC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S,EAAE,EAAE,CAAC;QACd,IAAI,EAAE,EAAE,CAAC;QACT,UAAU,EAAE,EAAE,GAAG,MAAM,CAAC;QACxB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;KAC3B,EACD,GAAG,GAAE,KAAoB,iBAe1B;IAEK,WAAW,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,GAAE,KAAoB,iBAGhF;IAEK,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM;;;;;;OAcnD;IAEK,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC,CAWrD;IAEK,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC,CASpD;IAoBD;;;OAGG;IACG,aAAa,CAAC,OAAO,EAAE,YAAY,iBAiBxC;IAEK,KAAK,kBAEV;CACF"}
@@ -0,0 +1,133 @@
1
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
2
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
3
+ export const AccountTypes = [
4
+ 'schnorr',
5
+ 'schnorr_initializerless',
6
+ 'ecdsasecp256r1',
7
+ 'ecdsasecp256k1'
8
+ ];
9
+ function accountKey(field, address) {
10
+ return `${field}:${address.toString()}`;
11
+ }
12
+ /** Bump when the WalletDB layout changes; a new version selects a fresh store, leaving the old one intact. */ export const WALLET_DATA_SCHEMA_VERSION = 1;
13
+ export class WalletDB {
14
+ store;
15
+ userLog;
16
+ accounts;
17
+ aliases;
18
+ constructor(store, userLog){
19
+ this.store = store;
20
+ this.userLog = userLog;
21
+ this.accounts = store.openMap('accounts');
22
+ this.aliases = store.openMap('aliases');
23
+ }
24
+ async storeAccount(address, { type, secretKey, salt, alias, signingKey }, log = this.userLog) {
25
+ await this.store.transactionAsync(async ()=>{
26
+ if (alias) {
27
+ await this.aliases.set(`accounts:${alias}`, Buffer.from(address.toString()));
28
+ }
29
+ await this.accounts.set(accountKey('type', address), Buffer.from(type));
30
+ await this.accounts.set(accountKey('sk', address), secretKey.toBuffer());
31
+ await this.accounts.set(accountKey('salt', address), salt.toBuffer());
32
+ await this.accounts.set(accountKey('signingKey', address), 'toBuffer' in signingKey ? signingKey.toBuffer() : signingKey);
33
+ });
34
+ log(`Account stored in database${alias ? ` with alias ${alias}` : ''}`);
35
+ }
36
+ async storeSender(address, alias, log = this.userLog) {
37
+ await this.aliases.set(`senders:${alias}`, Buffer.from(address.toString()));
38
+ log(`Sender stored in database with alias ${alias}`);
39
+ }
40
+ async retrieveAccount(address) {
41
+ const secretKeyBuffer = await this.accounts.getAsync(accountKey('sk', address));
42
+ if (!secretKeyBuffer) {
43
+ throw new Error(`Account "${address.toString()}" does not exist on this wallet.`);
44
+ }
45
+ const [saltBuffer, typeBuffer, signingKey] = await Promise.all([
46
+ this.accounts.getAsync(accountKey('salt', address)),
47
+ this.accounts.getAsync(accountKey('type', address)),
48
+ this.accounts.getAsync(accountKey('signingKey', address))
49
+ ]);
50
+ const secretKey = Fr.fromBuffer(secretKeyBuffer);
51
+ const salt = Fr.fromBuffer(saltBuffer);
52
+ const type = typeBuffer.toString('utf8');
53
+ return {
54
+ address,
55
+ secretKey,
56
+ salt,
57
+ type,
58
+ signingKey: signingKey
59
+ };
60
+ }
61
+ async listAccounts() {
62
+ // Read aliases and account addresses in parallel using range queries
63
+ const [aliasesByAddress, accountAddresses] = await Promise.all([
64
+ this.#readAccountAliases(),
65
+ this.#readAccountAddresses()
66
+ ]);
67
+ return accountAddresses.map((addressStr)=>({
68
+ alias: aliasesByAddress.get(addressStr) ?? '',
69
+ item: AztecAddress.fromStringUnsafe(addressStr)
70
+ }));
71
+ }
72
+ async listSenders() {
73
+ const result = [];
74
+ for await (const [alias, item] of this.aliases.entriesAsync({
75
+ start: 'senders:',
76
+ end: 'senders:\uffff'
77
+ })){
78
+ result.push({
79
+ alias: alias.slice('senders:'.length),
80
+ item: AztecAddress.fromStringUnsafe(item.toString())
81
+ });
82
+ }
83
+ return result;
84
+ }
85
+ async #readAccountAliases() {
86
+ const aliasesByAddress = new Map();
87
+ for await (const [alias, item] of this.aliases.entriesAsync({
88
+ start: 'accounts:',
89
+ end: 'accounts:\uffff'
90
+ })){
91
+ const address = item.toString();
92
+ aliasesByAddress.set(address, alias.slice('accounts:'.length));
93
+ }
94
+ return aliasesByAddress;
95
+ }
96
+ async #readAccountAddresses() {
97
+ const addresses = [];
98
+ // Range query on 'type:' prefix — one entry per account, avoids scanning sk/salt/signingKey entries
99
+ for await (const [key] of this.accounts.entriesAsync({
100
+ start: 'type:',
101
+ end: 'type:\uffff'
102
+ })){
103
+ addresses.push(key.slice('type:'.length));
104
+ }
105
+ return addresses;
106
+ }
107
+ /**
108
+ * Deletes an account's stored data and every alias pointing at it atomically. Deletion is local to this store;
109
+ * any state the PXE holds for the account is unaffected.
110
+ */ async deleteAccount(address) {
111
+ await this.store.transactionAsync(async ()=>{
112
+ await Promise.all([
113
+ this.accounts.delete(accountKey('sk', address)),
114
+ this.accounts.delete(accountKey('salt', address)),
115
+ this.accounts.delete(accountKey('type', address)),
116
+ this.accounts.delete(accountKey('signingKey', address))
117
+ ]);
118
+ const aliasKeys = [];
119
+ for await (const [key, item] of this.aliases.entriesAsync({
120
+ start: 'accounts:',
121
+ end: 'accounts:\uffff'
122
+ })){
123
+ if (item.toString() === address.toString()) {
124
+ aliasKeys.push(key);
125
+ }
126
+ }
127
+ await Promise.all(aliasKeys.map((key)=>this.aliases.delete(key)));
128
+ });
129
+ }
130
+ async close() {
131
+ await this.store.close();
132
+ }
133
+ }
@@ -0,0 +1,16 @@
1
+ import type { InitialAccountData } from '@aztec-labs/accounts/testing';
2
+ import type { AccountManager } from '@aztec-labs/aztec.js/wallet';
3
+ import type { Fq, Fr } from '@aztec-labs/foundation/curves/bn254';
4
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
5
+ interface WalletWithSchnorrAccounts {
6
+ createSchnorrInitializerlessAccount(secret: Fr, salt: Fr, signingKey: Fq, alias?: string): Promise<AccountManager>;
7
+ }
8
+ /**
9
+ * Creates the given (genesis-funded) test accounts as initializerless schnorr accounts. Initializerless
10
+ * accounts need no deployment tx — creating one registers the instance and materializes its immutable keys
11
+ * locally — so the accounts are usable as soon as they are created, funded via genesis at their addresses.
12
+ */
13
+ export declare function createFundedInitializerlessAccounts(wallet: WalletWithSchnorrAccounts, accountsData: InitialAccountData[]): Promise<AccountManager[]>;
14
+ export declare function registerInitialLocalNetworkAccountsInWallet(wallet: WalletWithSchnorrAccounts): Promise<AztecAddress[]>;
15
+ export {};
16
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3Rlc3RpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsa0JBQWtCLEVBQUUsTUFBTSw4QkFBOEIsQ0FBQztBQUV2RSxPQUFPLEtBQUssRUFBRSxjQUFjLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNsRSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsRUFBRSxFQUFFLE1BQU0scUNBQXFDLENBQUM7QUFDbEUsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLGtDQUFrQyxDQUFDO0FBRWhFLFVBQVUseUJBQXlCO0lBQ2pDLG1DQUFtQyxDQUFDLE1BQU0sRUFBRSxFQUFFLEVBQUUsSUFBSSxFQUFFLEVBQUUsRUFBRSxVQUFVLEVBQUUsRUFBRSxFQUFFLEtBQUssQ0FBQyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsY0FBYyxDQUFDLENBQUM7Q0FDcEg7QUFFRDs7OztHQUlHO0FBQ0gsd0JBQXNCLG1DQUFtQyxDQUN2RCxNQUFNLEVBQUUseUJBQXlCLEVBQ2pDLFlBQVksRUFBRSxrQkFBa0IsRUFBRSw2QkFPbkM7QUFFRCx3QkFBc0IsMkNBQTJDLENBQy9ELE1BQU0sRUFBRSx5QkFBeUIsR0FDaEMsT0FBTyxDQUFDLFlBQVksRUFBRSxDQUFDLENBUXpCIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAEhE,UAAU,yBAAyB;IACjC,mCAAmC,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CACpH;AAED;;;;GAIG;AACH,wBAAsB,mCAAmC,CACvD,MAAM,EAAE,yBAAyB,EACjC,YAAY,EAAE,kBAAkB,EAAE,6BAOnC;AAED,wBAAsB,2CAA2C,CAC/D,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,YAAY,EAAE,CAAC,CAQzB"}
@@ -0,0 +1,18 @@
1
+ import { getInitialTestAccountsData } from '@aztec-labs/accounts/testing/lazy';
2
+ /**
3
+ * Creates the given (genesis-funded) test accounts as initializerless schnorr accounts. Initializerless
4
+ * accounts need no deployment tx — creating one registers the instance and materializes its immutable keys
5
+ * locally — so the accounts are usable as soon as they are created, funded via genesis at their addresses.
6
+ */ export async function createFundedInitializerlessAccounts(wallet, accountsData) {
7
+ const accountManagers = [];
8
+ for (const { secret, salt, signingKey } of accountsData){
9
+ accountManagers.push(await wallet.createSchnorrInitializerlessAccount(secret, salt, signingKey));
10
+ }
11
+ return accountManagers;
12
+ }
13
+ export async function registerInitialLocalNetworkAccountsInWallet(wallet) {
14
+ const testAccounts = await getInitialTestAccountsData();
15
+ return Promise.all(testAccounts.map(async (account)=>{
16
+ return (await wallet.createSchnorrInitializerlessAccount(account.secret, account.salt, account.signingKey)).address;
17
+ }));
18
+ }