@aztec/accounts 0.76.4 → 0.77.0-testnet-ignition.21

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 (111) hide show
  1. package/README.md +11 -8
  2. package/artifacts/EcdsaKAccount.d.json.ts +1 -1
  3. package/artifacts/EcdsaKAccount.json +850 -690
  4. package/artifacts/EcdsaRAccount.d.json.ts +1 -1
  5. package/artifacts/EcdsaRAccount.json +684 -524
  6. package/artifacts/SchnorrAccount.d.json.ts +1 -1
  7. package/artifacts/SchnorrAccount.json +692 -459
  8. package/artifacts/SchnorrSingleKeyAccount.d.json.ts +1 -1
  9. package/artifacts/SchnorrSingleKeyAccount.json +227 -301
  10. package/dest/dapp/dapp_interface.d.ts +1 -2
  11. package/dest/dapp/dapp_interface.d.ts.map +1 -1
  12. package/dest/dapp/dapp_interface.js +3 -5
  13. package/dest/dapp/index.js +0 -1
  14. package/dest/defaults/account_contract.d.ts +5 -7
  15. package/dest/defaults/account_contract.d.ts.map +1 -1
  16. package/dest/defaults/account_contract.js +2 -9
  17. package/dest/defaults/account_interface.d.ts +8 -4
  18. package/dest/defaults/account_interface.d.ts.map +1 -1
  19. package/dest/defaults/account_interface.js +8 -5
  20. package/dest/defaults/index.js +1 -3
  21. package/dest/ecdsa/ecdsa_k/account_contract.d.ts +5 -3
  22. package/dest/ecdsa/ecdsa_k/account_contract.d.ts.map +1 -1
  23. package/dest/ecdsa/ecdsa_k/account_contract.js +19 -14
  24. package/dest/ecdsa/ecdsa_k/index.d.ts +15 -5
  25. package/dest/ecdsa/ecdsa_k/index.d.ts.map +1 -1
  26. package/dest/ecdsa/ecdsa_k/index.js +21 -10
  27. package/dest/ecdsa/ecdsa_k/lazy.d.ts +47 -0
  28. package/dest/ecdsa/ecdsa_k/lazy.d.ts.map +1 -0
  29. package/dest/ecdsa/ecdsa_k/lazy.js +52 -0
  30. package/dest/ecdsa/index.js +0 -1
  31. package/dest/ecdsa/lazy.d.ts +3 -0
  32. package/dest/ecdsa/lazy.d.ts.map +1 -0
  33. package/dest/ecdsa/lazy.js +2 -0
  34. package/dest/ecdsa/ssh_ecdsa_r/account_contract.d.ts +5 -3
  35. package/dest/ecdsa/ssh_ecdsa_r/account_contract.d.ts.map +1 -1
  36. package/dest/ecdsa/ssh_ecdsa_r/account_contract.js +55 -51
  37. package/dest/ecdsa/ssh_ecdsa_r/index.d.ts +18 -5
  38. package/dest/ecdsa/ssh_ecdsa_r/index.d.ts.map +1 -1
  39. package/dest/ecdsa/ssh_ecdsa_r/index.js +24 -10
  40. package/dest/ecdsa/ssh_ecdsa_r/lazy.d.ts +49 -0
  41. package/dest/ecdsa/ssh_ecdsa_r/lazy.d.ts.map +1 -0
  42. package/dest/ecdsa/ssh_ecdsa_r/lazy.js +57 -0
  43. package/dest/schnorr/account_contract.d.ts +13 -4
  44. package/dest/schnorr/account_contract.d.ts.map +1 -1
  45. package/dest/schnorr/account_contract.js +18 -14
  46. package/dest/schnorr/index.d.ts +32 -6
  47. package/dest/schnorr/index.d.ts.map +1 -1
  48. package/dest/schnorr/index.js +43 -10
  49. package/dest/schnorr/lazy.d.ts +61 -0
  50. package/dest/schnorr/lazy.d.ts.map +1 -0
  51. package/dest/schnorr/lazy.js +74 -0
  52. package/dest/single_key/account_contract.d.ts +6 -3
  53. package/dest/single_key/account_contract.d.ts.map +1 -1
  54. package/dest/single_key/account_contract.js +17 -13
  55. package/dest/single_key/index.d.ts +16 -8
  56. package/dest/single_key/index.d.ts.map +1 -1
  57. package/dest/single_key/index.js +23 -13
  58. package/dest/single_key/lazy.d.ts +43 -0
  59. package/dest/single_key/lazy.d.ts.map +1 -0
  60. package/dest/single_key/lazy.js +53 -0
  61. package/dest/testing/configuration.d.ts +23 -24
  62. package/dest/testing/configuration.d.ts.map +1 -1
  63. package/dest/testing/configuration.js +8 -79
  64. package/dest/testing/create_account.d.ts +38 -15
  65. package/dest/testing/create_account.d.ts.map +1 -1
  66. package/dest/testing/create_account.js +53 -49
  67. package/dest/testing/index.d.ts +28 -4
  68. package/dest/testing/index.d.ts.map +1 -1
  69. package/dest/testing/index.js +42 -6
  70. package/dest/testing/lazy.d.ts +34 -0
  71. package/dest/testing/lazy.d.ts.map +1 -0
  72. package/dest/testing/lazy.js +46 -0
  73. package/dest/utils/index.js +0 -1
  74. package/dest/utils/ssh_agent.js +75 -31
  75. package/package.json +12 -10
  76. package/src/dapp/dapp_interface.ts +7 -2
  77. package/src/defaults/account_contract.ts +5 -9
  78. package/src/defaults/account_interface.ts +8 -4
  79. package/src/ecdsa/ecdsa_k/account_contract.ts +9 -8
  80. package/src/ecdsa/ecdsa_k/index.ts +25 -5
  81. package/src/ecdsa/ecdsa_k/lazy.ts +71 -0
  82. package/src/ecdsa/lazy.ts +2 -0
  83. package/src/ecdsa/ssh_ecdsa_r/account_contract.ts +9 -8
  84. package/src/ecdsa/ssh_ecdsa_r/index.ts +29 -5
  85. package/src/ecdsa/ssh_ecdsa_r/lazy.ts +78 -0
  86. package/src/schnorr/account_contract.ts +10 -9
  87. package/src/schnorr/index.ts +56 -7
  88. package/src/schnorr/lazy.ts +107 -0
  89. package/src/single_key/account_contract.ts +9 -8
  90. package/src/single_key/index.ts +29 -11
  91. package/src/single_key/lazy.ts +71 -0
  92. package/src/testing/configuration.ts +21 -103
  93. package/src/testing/create_account.ts +79 -57
  94. package/src/testing/index.ts +85 -4
  95. package/src/testing/lazy.ts +86 -0
  96. package/dest/ecdsa/ecdsa_k/artifact.d.ts +0 -3
  97. package/dest/ecdsa/ecdsa_k/artifact.d.ts.map +0 -1
  98. package/dest/ecdsa/ecdsa_k/artifact.js +0 -4
  99. package/dest/ecdsa/ssh_ecdsa_r/artifact.d.ts +0 -2
  100. package/dest/ecdsa/ssh_ecdsa_r/artifact.d.ts.map +0 -1
  101. package/dest/ecdsa/ssh_ecdsa_r/artifact.js +0 -4
  102. package/dest/schnorr/artifact.d.ts +0 -2
  103. package/dest/schnorr/artifact.d.ts.map +0 -1
  104. package/dest/schnorr/artifact.js +0 -4
  105. package/dest/single_key/artifact.d.ts +0 -2
  106. package/dest/single_key/artifact.d.ts.map +0 -1
  107. package/dest/single_key/artifact.js +0 -4
  108. package/src/ecdsa/ecdsa_k/artifact.ts +0 -7
  109. package/src/ecdsa/ssh_ecdsa_r/artifact.ts +0 -5
  110. package/src/schnorr/artifact.ts +0 -5
  111. package/src/single_key/artifact.ts +0 -7
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The `@aztec/accounts/single_key` export provides a testing account contract implementation that uses a single Grumpkin key for both authentication and encryption.
3
+ * It is not recommended to use this account type in production.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import type { AztecAddress, Fr, GrumpkinScalar } from '@aztec/aztec.js';
8
+ import { AccountManager, type Salt } from '@aztec/aztec.js/account';
9
+ import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet';
10
+ import type { ContractArtifact } from '@aztec/stdlib/abi';
11
+ import { loadContractArtifact } from '@aztec/stdlib/abi';
12
+ import type { PXE } from '@aztec/stdlib/interfaces/client';
13
+ import { deriveMasterIncomingViewingSecretKey } from '@aztec/stdlib/keys';
14
+
15
+ import { SingleKeyBaseAccountContract } from './account_contract.js';
16
+
17
+ /**
18
+ * Lazily loads the contract artifact
19
+ * @returns The contract artifact for the single key account contract
20
+ */
21
+ export async function getSingleKeyAccountContractArtifact() {
22
+ // Cannot assert this import as it's incompatible with browsers
23
+ // https://caniuse.com/mdn-javascript_statements_import_import_assertions_type_json
24
+ // Use the new "with" syntax once supported by firefox
25
+ // https://caniuse.com/mdn-javascript_statements_import_import_attributes_type_json
26
+ // In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
27
+ const { default: schnorrAccountContractJson } = await import('../../artifacts/SchnorrAccount.json');
28
+ return loadContractArtifact(schnorrAccountContractJson);
29
+ }
30
+
31
+ /**
32
+ * Account contract that authenticates transactions using Schnorr signatures verified against
33
+ * the note encryption key, relying on a single private key for both encryption and authentication.
34
+ * Lazily loads the contract artifact
35
+ */
36
+ export class SingleKeyAccountContract extends SingleKeyBaseAccountContract {
37
+ constructor(signingPrivateKey: GrumpkinScalar) {
38
+ super(signingPrivateKey);
39
+ }
40
+
41
+ override getContractArtifact(): Promise<ContractArtifact> {
42
+ return getSingleKeyAccountContractArtifact();
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Creates an Account that uses the same Grumpkin key for encryption and authentication.
48
+ * @param pxe - An PXE server instance.
49
+ * @param secretKey - Secret key used to derive all the keystore keys (in this case also used to get signing key).
50
+ * @param salt - Deployment salt.
51
+ * @returns An account manager initialized with the account contract and its deployment params
52
+ */
53
+ export function getUnsafeSchnorrAccount(pxe: PXE, secretKey: Fr, salt?: Salt) {
54
+ const encryptionPrivateKey = deriveMasterIncomingViewingSecretKey(secretKey);
55
+ return AccountManager.create(pxe, secretKey, new SingleKeyAccountContract(encryptionPrivateKey), salt);
56
+ }
57
+
58
+ /**
59
+ * Gets a wallet for an already registered account using Schnorr signatures with a single key for encryption and authentication.
60
+ * @param pxe - An PXE server instance.
61
+ * @param address - Address for the account.
62
+ * @param signingPrivateKey - Grumpkin key used for note encryption and signing transactions.
63
+ * @returns A wallet for this account that can be used to interact with a contract instance.
64
+ */
65
+ export function getUnsafeSchnorrWallet(
66
+ pxe: PXE,
67
+ address: AztecAddress,
68
+ signingPrivateKey: GrumpkinScalar,
69
+ ): Promise<AccountWallet> {
70
+ return getWallet(pxe, address, new SingleKeyAccountContract(signingPrivateKey));
71
+ }
@@ -1,12 +1,6 @@
1
- import { generatePublicKey } from '@aztec/aztec.js';
2
- import { registerContractClass } from '@aztec/aztec.js/deployment';
3
- import { DefaultMultiCallEntrypoint } from '@aztec/aztec.js/entrypoint';
4
- import { type AccountWalletWithSecretKey, SignerlessWallet } from '@aztec/aztec.js/wallet';
5
- import { type PXE } from '@aztec/circuit-types';
6
- import { deriveMasterIncomingViewingSecretKey, deriveSigningKey } from '@aztec/circuits.js/keys';
7
- import { Fr } from '@aztec/foundation/fields';
8
-
9
- import { SchnorrAccountContractArtifact, getSchnorrAccount } from '../schnorr/index.js';
1
+ import { Fr, GrumpkinScalar } from '@aztec/foundation/fields';
2
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import { deriveMasterIncomingViewingSecretKey } from '@aztec/stdlib/keys';
10
4
 
11
5
  export const INITIAL_TEST_SECRET_KEYS = [
12
6
  Fr.fromHexString('2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281'),
@@ -23,99 +17,23 @@ export const INITIAL_TEST_SIGNING_KEYS = INITIAL_TEST_ENCRYPTION_KEYS;
23
17
  export const INITIAL_TEST_ACCOUNT_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO];
24
18
 
25
19
  /**
26
- * Gets a collection of wallets for the Aztec accounts that are initially stored in the test environment.
27
- * @param pxe - PXE instance.
28
- * @returns A set of AccountWallet implementations for each of the initial accounts.
29
- */
30
- export function getInitialTestAccountsWallets(pxe: PXE): Promise<AccountWalletWithSecretKey[]> {
31
- return Promise.all(
32
- INITIAL_TEST_SECRET_KEYS.map(async (encryptionKey, i) => {
33
- const account = await getSchnorrAccount(
34
- pxe,
35
- encryptionKey!,
36
- INITIAL_TEST_SIGNING_KEYS[i]!,
37
- INITIAL_TEST_ACCOUNT_SALTS[i],
38
- );
39
- return account.getWallet();
40
- }),
41
- );
42
- }
43
-
44
- /**
45
- * Queries a PXE for it's registered accounts and returns wallets for those accounts using keys in the initial test accounts.
46
- * @param pxe - PXE instance.
47
- * @returns A set of AccountWallet implementations for each of the initial accounts.
48
- */
49
- export async function getDeployedTestAccountsWallets(pxe: PXE): Promise<AccountWalletWithSecretKey[]> {
50
- const registeredAccounts = await pxe.getRegisteredAccounts();
51
- const publicKeys = await Promise.all(
52
- INITIAL_TEST_SECRET_KEYS.map(async initialSecretKey => {
53
- const initialEncryptionKey = deriveMasterIncomingViewingSecretKey(initialSecretKey);
54
- const publicKey = await generatePublicKey(initialEncryptionKey);
55
- return { sk: initialSecretKey, pk: publicKey };
56
- }),
57
- );
58
- return Promise.all(
59
- publicKeys
60
- .filter(keyPairs => {
61
- return (
62
- registeredAccounts.find(registered =>
63
- registered.publicKeys.masterIncomingViewingPublicKey.equals(keyPairs.pk),
64
- ) != undefined
65
- );
66
- })
67
- .map(async keyPairs => {
68
- const signingKey = deriveSigningKey(keyPairs.sk);
69
- // TODO(#5726): use actual salt here instead of hardcoding Fr.ZERO
70
- const account = await getSchnorrAccount(pxe, keyPairs.sk, signingKey, Fr.ZERO);
71
- return account.getWallet();
72
- }),
73
- );
74
- }
75
-
76
- /**
77
- * Deploys the initial set of schnorr signature accounts to the test environment
78
- * @param pxe - PXE instance.
79
- * @returns The set of deployed Account objects and associated private encryption keys
20
+ * Data for generating an initial account.
80
21
  */
81
- export async function deployInitialTestAccounts(pxe: PXE) {
82
- const accounts = await Promise.all(
83
- INITIAL_TEST_SECRET_KEYS.map(async (secretKey, i) => {
84
- const account = await getSchnorrAccount(
85
- pxe,
86
- secretKey,
87
- INITIAL_TEST_SIGNING_KEYS[i],
88
- INITIAL_TEST_ACCOUNT_SALTS[i],
89
- );
90
- return {
91
- account,
92
- secretKey,
93
- };
94
- }),
95
- );
96
- // Register contract class to avoid duplicate nullifier errors
97
- const { l1ChainId: chainId, protocolVersion } = await pxe.getNodeInfo();
98
- const deployWallet = new SignerlessWallet(pxe, new DefaultMultiCallEntrypoint(chainId, protocolVersion));
99
- await (await registerContractClass(deployWallet, SchnorrAccountContractArtifact)).send().wait();
100
- // Attempt to get as much parallelism as possible
101
- const deployTxs = await Promise.all(
102
- accounts.map(async x => {
103
- const deployMethod = await x.account.getDeployMethod();
104
- const tx = await deployMethod.prove({
105
- contractAddressSalt: new Fr(x.account.salt),
106
- universalDeploy: true,
107
- });
108
- return tx;
109
- }),
110
- );
111
- // Send tx together to try and get them in the same rollup
112
- const sentTxs = deployTxs.map(tx => {
113
- return tx.send();
114
- });
115
- await Promise.all(
116
- sentTxs.map(tx => {
117
- return tx.wait();
118
- }),
119
- );
120
- return accounts;
22
+ export interface InitialAccountData {
23
+ /**
24
+ * Secret to derive the keys for the account.
25
+ */
26
+ secret: Fr;
27
+ /**
28
+ * Signing key od the account.
29
+ */
30
+ signingKey: GrumpkinScalar;
31
+ /**
32
+ * Contract address salt.
33
+ */
34
+ salt: Fr;
35
+ /**
36
+ * Address of the schnorr account contract.
37
+ */
38
+ address: AztecAddress;
121
39
  }
@@ -1,71 +1,93 @@
1
- import { type WaitOpts } from '@aztec/aztec.js';
2
- import { type AccountWalletWithSecretKey } from '@aztec/aztec.js/wallet';
3
- import { type PXE } from '@aztec/circuit-types';
4
- import { Fr, deriveSigningKey } from '@aztec/circuits.js';
1
+ import { type AccountManager, FeeJuicePaymentMethod, type PXE, type WaitOpts } from '@aztec/aztec.js';
2
+ import { Fr } from '@aztec/foundation/fields';
3
+ import { deriveSigningKey } from '@aztec/stdlib/keys';
5
4
 
6
- import { getSchnorrAccount } from '../schnorr/index.js';
5
+ import { getSchnorrAccount, getSchnorrAccountContractAddress } from '../schnorr/index.js';
6
+ import type { InitialAccountData } from './configuration.js';
7
7
 
8
8
  /**
9
- * Deploys and registers a new account using random private keys and returns the associated Schnorr account wallet. Useful for testing.
10
- * @param pxe - PXE.
11
- * @returns - A wallet for a fresh account.
9
+ * Generate a fixed amount of random schnorr account contract instance.
12
10
  */
13
- export async function createAccount(pxe: PXE): Promise<AccountWalletWithSecretKey> {
14
- const secretKey = Fr.random();
15
- const signingKey = deriveSigningKey(secretKey);
16
- const account = await getSchnorrAccount(pxe, secretKey, signingKey);
17
- return account.waitSetup();
11
+ export async function generateSchnorrAccounts(numberOfAccounts: number) {
12
+ const secrets = Array.from({ length: numberOfAccounts }, () => Fr.random());
13
+ return await Promise.all(
14
+ secrets.map(async secret => {
15
+ const salt = Fr.random();
16
+ return {
17
+ secret,
18
+ signingKey: deriveSigningKey(secret),
19
+ salt,
20
+ address: await getSchnorrAccountContractAddress(secret, salt),
21
+ };
22
+ }),
23
+ );
18
24
  }
19
25
 
20
26
  /**
21
- * Creates a given number of random accounts using the Schnorr account wallet.
22
- * @param pxe - PXE.
23
- * @param numberOfAccounts - How many accounts to create.
24
- * @param secrets - Optional array of secrets to use for the accounts. If empty, random secrets will be generated.
25
- * @throws If the secrets array is not empty and does not have the same length as the number of accounts.
26
- * @returns The created account wallets.
27
+ * Data for deploying funded account.
27
28
  */
28
- export async function createAccounts(
29
+ type DeployAccountData = Pick<InitialAccountData, 'secret' | 'salt'> & {
30
+ /**
31
+ * An optional signingKey if it's not derived from the secret.
32
+ */
33
+ signingKey?: InitialAccountData['signingKey'];
34
+ };
35
+
36
+ /**
37
+ * Deploy schnorr account contract.
38
+ * It will pay for the fee for the deployment itself. So it must be funded with the prefilled public data.
39
+ */
40
+ export async function deployFundedSchnorrAccount(
29
41
  pxe: PXE,
30
- numberOfAccounts = 1,
31
- secrets: Fr[] = [],
32
- waitOpts: WaitOpts = { interval: 0.1 },
33
- ): Promise<AccountWalletWithSecretKey[]> {
34
- if (secrets.length == 0) {
35
- secrets = Array.from({ length: numberOfAccounts }, () => Fr.random());
36
- } else if (secrets.length > 0 && secrets.length !== numberOfAccounts) {
37
- throw new Error('Secrets array must be empty or have the same length as the number of accounts');
38
- }
42
+ account: DeployAccountData,
43
+ opts: WaitOpts & {
44
+ /**
45
+ * Whether or not to skip registering contract class.
46
+ */
47
+ skipClassRegistration?: boolean;
48
+ } = { interval: 0.1, skipClassRegistration: false },
49
+ ): Promise<AccountManager> {
50
+ const signingKey = account.signingKey ?? deriveSigningKey(account.secret);
51
+ const accountManager = await getSchnorrAccount(pxe, account.secret, signingKey, account.salt);
39
52
 
40
- // Prepare deployments
41
- const accountsAndDeployments = await Promise.all(
42
- secrets.map(async (secret, index) => {
43
- const signingKey = deriveSigningKey(secret);
44
- const account = await getSchnorrAccount(pxe, secret, signingKey);
53
+ // Pay the fee by the account itself.
54
+ // This only works when the world state is prefilled with the balance for the account in test environment.
55
+ const paymentMethod = new FeeJuicePaymentMethod(accountManager.getAddress());
45
56
 
46
- // only register the contract class once
47
- let skipClassRegistration = true;
48
- if (index === 0) {
49
- // for the first account, check if the contract class is already registered, otherwise we should register now
50
- if (
51
- !(await pxe.getContractClassMetadata(account.getInstance().contractClassId)).isContractClassPubliclyRegistered
52
- ) {
53
- skipClassRegistration = false;
54
- }
55
- }
57
+ await accountManager
58
+ .deploy({
59
+ skipClassRegistration: opts.skipClassRegistration,
60
+ skipPublicDeployment: true,
61
+ fee: { paymentMethod },
62
+ })
63
+ .wait(opts);
56
64
 
57
- const deployMethod = await account.getDeployMethod();
58
- const provenTx = await deployMethod.prove({
59
- contractAddressSalt: new Fr(account.salt),
60
- skipClassRegistration,
61
- skipPublicDeployment: true,
62
- universalDeploy: true,
63
- });
64
- return { account, provenTx };
65
- }),
66
- );
65
+ return accountManager;
66
+ }
67
67
 
68
- // Send them and await them to be mined
69
- await Promise.all(accountsAndDeployments.map(({ provenTx }) => provenTx.send().wait(waitOpts)));
70
- return Promise.all(accountsAndDeployments.map(({ account }) => account.getWallet()));
68
+ /**
69
+ * Deploy schnorr account contracts.
70
+ * They will pay for the fees for the deployment themselves. So they must be funded with the prefilled public data.
71
+ */
72
+ export async function deployFundedSchnorrAccounts(
73
+ pxe: PXE,
74
+ accounts: DeployAccountData[],
75
+ opts: WaitOpts & {
76
+ /**
77
+ * Whether or not to skip registering contract class.
78
+ */
79
+ skipClassRegistration?: boolean;
80
+ } = { interval: 0.1, skipClassRegistration: false },
81
+ ): Promise<AccountManager[]> {
82
+ const accountManagers: AccountManager[] = [];
83
+ // Serial due to https://github.com/AztecProtocol/aztec-packages/issues/12045
84
+ for (let i = 0; i < accounts.length; i++) {
85
+ accountManagers.push(
86
+ await deployFundedSchnorrAccount(pxe, accounts[i], {
87
+ ...opts,
88
+ skipClassRegistration: i !== 0 || opts.skipClassRegistration, // Register the contract class at most once.
89
+ }),
90
+ );
91
+ }
92
+ return accountManagers;
71
93
  }
@@ -1,11 +1,92 @@
1
1
  /**
2
2
  * The `@aztec/accounts/testing` export provides utility methods for testing, in particular in a Sandbox environment.
3
3
  *
4
- * Use the {@link createAccount} and {@link createAccounts} methods to create new sample accounts for testing,
5
- * or use {@link getInitialTestAccountsWallets} to obtain a list of wallets for the Sandbox pre-seeded accounts.
4
+ * Use {@link getInitialTestAccountsWallets} to obtain a list of wallets for the Sandbox pre-seeded accounts.
6
5
  *
7
6
  * @packageDocumentation
8
7
  */
8
+ import type { PXE } from '@aztec/aztec.js';
9
+ import type { AccountWalletWithSecretKey } from '@aztec/aztec.js/wallet';
9
10
 
10
- export * from './create_account.js';
11
- export * from './configuration.js';
11
+ import {
12
+ getSchnorrAccount,
13
+ getSchnorrAccountContractAddress,
14
+ getSchnorrWalletWithSecretKey,
15
+ } from '../schnorr/index.js';
16
+ import type { InitialAccountData } from './configuration.js';
17
+ import {
18
+ INITIAL_TEST_ACCOUNT_SALTS,
19
+ INITIAL_TEST_ENCRYPTION_KEYS,
20
+ INITIAL_TEST_SECRET_KEYS,
21
+ INITIAL_TEST_SIGNING_KEYS,
22
+ } from './configuration.js';
23
+
24
+ export {
25
+ type InitialAccountData,
26
+ INITIAL_TEST_ACCOUNT_SALTS,
27
+ INITIAL_TEST_ENCRYPTION_KEYS,
28
+ INITIAL_TEST_SECRET_KEYS,
29
+ INITIAL_TEST_SIGNING_KEYS,
30
+ } from './configuration.js';
31
+
32
+ /**
33
+ * Gets the basic information for initial test accounts.
34
+ */
35
+ export function getInitialTestAccounts(): Promise<InitialAccountData[]> {
36
+ return Promise.all(
37
+ INITIAL_TEST_SECRET_KEYS.map(async (secret, i) => ({
38
+ secret,
39
+ signingKey: INITIAL_TEST_ENCRYPTION_KEYS[i],
40
+ salt: INITIAL_TEST_ACCOUNT_SALTS[i],
41
+ address: await getSchnorrAccountContractAddress(
42
+ secret,
43
+ INITIAL_TEST_ACCOUNT_SALTS[i],
44
+ INITIAL_TEST_SIGNING_KEYS[i],
45
+ ),
46
+ })),
47
+ );
48
+ }
49
+
50
+ /**
51
+ * Gets a collection of wallets for the Aztec accounts that are initially stored in the test environment.
52
+ * @param pxe - PXE instance.
53
+ * @returns A set of AccountWallet implementations for each of the initial accounts.
54
+ */
55
+ export function getInitialTestAccountsWallets(pxe: PXE): Promise<AccountWalletWithSecretKey[]> {
56
+ return Promise.all(
57
+ INITIAL_TEST_SECRET_KEYS.map(async (encryptionKey, i) => {
58
+ const account = await getSchnorrAccount(
59
+ pxe,
60
+ encryptionKey!,
61
+ INITIAL_TEST_SIGNING_KEYS[i]!,
62
+ INITIAL_TEST_ACCOUNT_SALTS[i],
63
+ );
64
+ return account.getWallet();
65
+ }),
66
+ );
67
+ }
68
+
69
+ /**
70
+ * Queries a PXE for it's registered accounts.
71
+ * @param pxe - PXE instance.
72
+ * @returns A set of key data for each of the initial accounts.
73
+ */
74
+ export async function getDeployedTestAccounts(pxe: PXE): Promise<InitialAccountData[]> {
75
+ const registeredAccounts = await pxe.getRegisteredAccounts();
76
+ const testAccounts = await getInitialTestAccounts();
77
+ return testAccounts.filter(t => registeredAccounts.some(r => r.address.equals(t.address)));
78
+ }
79
+
80
+ /**
81
+ * Queries a PXE for it's registered accounts and returns wallets for those accounts using keys in the initial test accounts.
82
+ * @param pxe - PXE instance.
83
+ * @returns A set of AccountWallet implementations for each of the initial accounts.
84
+ */
85
+ export async function getDeployedTestAccountsWallets(pxe: PXE): Promise<AccountWalletWithSecretKey[]> {
86
+ const testAccounts = await getDeployedTestAccounts(pxe);
87
+ return Promise.all(
88
+ testAccounts.map(({ secret, signingKey, salt }) => getSchnorrWalletWithSecretKey(pxe, secret, signingKey, salt)),
89
+ );
90
+ }
91
+
92
+ export { deployFundedSchnorrAccount, deployFundedSchnorrAccounts, generateSchnorrAccounts } from './create_account.js';
@@ -0,0 +1,86 @@
1
+ /**
2
+ * The `@aztec/accounts/testing/lazy` export provides utility methods for testing, in particular in a Sandbox environment.
3
+ *
4
+ * Use {@link getInitialTestAccountsWallets} to obtain a list of wallets for the Sandbox pre-seeded accounts.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ import type { PXE } from '@aztec/aztec.js';
9
+ import type { AccountWalletWithSecretKey } from '@aztec/aztec.js/wallet';
10
+
11
+ import { getSchnorrAccount, getSchnorrAccountContractAddress, getSchnorrWalletWithSecretKey } from '../schnorr/lazy.js';
12
+ import {
13
+ INITIAL_TEST_ACCOUNT_SALTS,
14
+ INITIAL_TEST_ENCRYPTION_KEYS,
15
+ INITIAL_TEST_SECRET_KEYS,
16
+ INITIAL_TEST_SIGNING_KEYS,
17
+ type InitialAccountData,
18
+ } from './configuration.js';
19
+
20
+ export {
21
+ type InitialAccountData,
22
+ INITIAL_TEST_ACCOUNT_SALTS,
23
+ INITIAL_TEST_ENCRYPTION_KEYS,
24
+ INITIAL_TEST_SECRET_KEYS,
25
+ INITIAL_TEST_SIGNING_KEYS,
26
+ } from './configuration.js';
27
+
28
+ /**
29
+ * Gets the basic information for initial test accounts.
30
+ */
31
+ export function getInitialTestAccounts(): Promise<InitialAccountData[]> {
32
+ return Promise.all(
33
+ INITIAL_TEST_SECRET_KEYS.map(async (secret, i) => ({
34
+ secret,
35
+ signingKey: INITIAL_TEST_ENCRYPTION_KEYS[i],
36
+ salt: INITIAL_TEST_ACCOUNT_SALTS[i],
37
+ address: await getSchnorrAccountContractAddress(
38
+ secret,
39
+ INITIAL_TEST_ACCOUNT_SALTS[i],
40
+ INITIAL_TEST_SIGNING_KEYS[i],
41
+ ),
42
+ })),
43
+ );
44
+ }
45
+
46
+ /**
47
+ * Gets a collection of wallets for the Aztec accounts that are initially stored in the test environment.
48
+ * @param pxe - PXE instance.
49
+ * @returns A set of AccountWallet implementations for each of the initial accounts.
50
+ */
51
+ export function getInitialTestAccountsWallets(pxe: PXE): Promise<AccountWalletWithSecretKey[]> {
52
+ return Promise.all(
53
+ INITIAL_TEST_SECRET_KEYS.map(async (encryptionKey, i) => {
54
+ const account = await getSchnorrAccount(
55
+ pxe,
56
+ encryptionKey!,
57
+ INITIAL_TEST_SIGNING_KEYS[i]!,
58
+ INITIAL_TEST_ACCOUNT_SALTS[i],
59
+ );
60
+ return account.getWallet();
61
+ }),
62
+ );
63
+ }
64
+
65
+ /**
66
+ * Queries a PXE for it's registered accounts.
67
+ * @param pxe - PXE instance.
68
+ * @returns A set of key data for each of the initial accounts.
69
+ */
70
+ export async function getDeployedTestAccounts(pxe: PXE): Promise<InitialAccountData[]> {
71
+ const registeredAccounts = await pxe.getRegisteredAccounts();
72
+ const testAccounts = await getInitialTestAccounts();
73
+ return testAccounts.filter(t => registeredAccounts.some(r => r.address.equals(t.address)));
74
+ }
75
+
76
+ /**
77
+ * Queries a PXE for it's registered accounts and returns wallets for those accounts using keys in the initial test accounts.
78
+ * @param pxe - PXE instance.
79
+ * @returns A set of AccountWallet implementations for each of the initial accounts.
80
+ */
81
+ export async function getDeployedTestAccountsWallets(pxe: PXE): Promise<AccountWalletWithSecretKey[]> {
82
+ const testAccounts = await getDeployedTestAccounts(pxe);
83
+ return Promise.all(
84
+ testAccounts.map(({ secret, signingKey, salt }) => getSchnorrWalletWithSecretKey(pxe, secret, signingKey, salt)),
85
+ );
86
+ }
@@ -1,3 +0,0 @@
1
- import { type ContractArtifact } from '@aztec/aztec.js';
2
- export declare const EcdsaKAccountContractArtifact: ContractArtifact;
3
- //# sourceMappingURL=artifact.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"artifact.d.ts","sourceRoot":"","sources":["../../../src/ecdsa/ecdsa_k/artifact.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAmD,MAAM,iBAAiB,CAAC;AAIzG,eAAO,MAAM,6BAA6B,EAAE,gBAE3C,CAAC"}
@@ -1,4 +0,0 @@
1
- import { loadContractArtifact } from '@aztec/aztec.js';
2
- import EcdsaKAccountContractJson from '../../../artifacts/EcdsaKAccount.json' assert { type: 'json' };
3
- export const EcdsaKAccountContractArtifact = loadContractArtifact(EcdsaKAccountContractJson);
4
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXJ0aWZhY3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvZWNkc2EvZWNkc2Ffay9hcnRpZmFjdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQW9ELG9CQUFvQixFQUFFLE1BQU0saUJBQWlCLENBQUM7QUFFekcsT0FBTyx5QkFBeUIsTUFBTSx1Q0FBdUMsQ0FBQyxTQUFTLElBQUksRUFBRSxNQUFNLEVBQUUsQ0FBQztBQUV0RyxNQUFNLENBQUMsTUFBTSw2QkFBNkIsR0FBcUIsb0JBQW9CLENBQ2pGLHlCQUFpRCxDQUNsRCxDQUFDIn0=
@@ -1,2 +0,0 @@
1
- export declare const EcdsaRAccountContractArtifact: import("@aztec/aztec.js").ContractArtifact;
2
- //# sourceMappingURL=artifact.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"artifact.d.ts","sourceRoot":"","sources":["../../../src/ecdsa/ssh_ecdsa_r/artifact.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,6BAA6B,4CAA0E,CAAC"}
@@ -1,4 +0,0 @@
1
- import { loadContractArtifact } from '@aztec/aztec.js';
2
- import EcdsaRAccountContractJson from '../../../artifacts/EcdsaRAccount.json' assert { type: 'json' };
3
- export const EcdsaRAccountContractArtifact = loadContractArtifact(EcdsaRAccountContractJson);
4
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXJ0aWZhY3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvZWNkc2Evc3NoX2VjZHNhX3IvYXJ0aWZhY3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUE2QixvQkFBb0IsRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBRWxGLE9BQU8seUJBQXlCLE1BQU0sdUNBQXVDLENBQUMsU0FBUyxJQUFJLEVBQUUsTUFBTSxFQUFFLENBQUM7QUFFdEcsTUFBTSxDQUFDLE1BQU0sNkJBQTZCLEdBQUcsb0JBQW9CLENBQUMseUJBQWlELENBQUMsQ0FBQyJ9
@@ -1,2 +0,0 @@
1
- export declare const SchnorrAccountContractArtifact: import("@aztec/aztec.js").ContractArtifact;
2
- //# sourceMappingURL=artifact.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"artifact.d.ts","sourceRoot":"","sources":["../../src/schnorr/artifact.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,8BAA8B,4CAA2E,CAAC"}
@@ -1,4 +0,0 @@
1
- import { loadContractArtifact } from '@aztec/aztec.js';
2
- import SchnorrAccountContractJson from '../../artifacts/SchnorrAccount.json' assert { type: 'json' };
3
- export const SchnorrAccountContractArtifact = loadContractArtifact(SchnorrAccountContractJson);
4
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXJ0aWZhY3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc2Nobm9yci9hcnRpZmFjdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQTZCLG9CQUFvQixFQUFFLE1BQU0saUJBQWlCLENBQUM7QUFFbEYsT0FBTywwQkFBMEIsTUFBTSxxQ0FBcUMsQ0FBQyxTQUFTLElBQUksRUFBRSxNQUFNLEVBQUUsQ0FBQztBQUVyRyxNQUFNLENBQUMsTUFBTSw4QkFBOEIsR0FBRyxvQkFBb0IsQ0FBQywwQkFBa0QsQ0FBQyxDQUFDIn0=
@@ -1,2 +0,0 @@
1
- export declare const SchnorrSingleKeyAccountContractArtifact: import("@aztec/aztec.js").ContractArtifact;
2
- //# sourceMappingURL=artifact.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"artifact.d.ts","sourceRoot":"","sources":["../../src/single_key/artifact.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,uCAAuC,4CAEnD,CAAC"}
@@ -1,4 +0,0 @@
1
- import { loadContractArtifact } from '@aztec/aztec.js';
2
- import SchnorrSingleKeyAccountContractJson from '../../artifacts/SchnorrSingleKeyAccount.json' assert { type: 'json' };
3
- export const SchnorrSingleKeyAccountContractArtifact = loadContractArtifact(SchnorrSingleKeyAccountContractJson);
4
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXJ0aWZhY3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc2luZ2xlX2tleS9hcnRpZmFjdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQTZCLG9CQUFvQixFQUFFLE1BQU0saUJBQWlCLENBQUM7QUFFbEYsT0FBTyxtQ0FBbUMsTUFBTSw4Q0FBOEMsQ0FBQyxTQUFTLElBQUksRUFBRSxNQUFNLEVBQUUsQ0FBQztBQUV2SCxNQUFNLENBQUMsTUFBTSx1Q0FBdUMsR0FBRyxvQkFBb0IsQ0FDekUsbUNBQTJELENBQzVELENBQUMifQ==
@@ -1,7 +0,0 @@
1
- import { type ContractArtifact, type NoirCompiledContract, loadContractArtifact } from '@aztec/aztec.js';
2
-
3
- import EcdsaKAccountContractJson from '../../../artifacts/EcdsaKAccount.json' assert { type: 'json' };
4
-
5
- export const EcdsaKAccountContractArtifact: ContractArtifact = loadContractArtifact(
6
- EcdsaKAccountContractJson as NoirCompiledContract,
7
- );
@@ -1,5 +0,0 @@
1
- import { type NoirCompiledContract, loadContractArtifact } from '@aztec/aztec.js';
2
-
3
- import EcdsaRAccountContractJson from '../../../artifacts/EcdsaRAccount.json' assert { type: 'json' };
4
-
5
- export const EcdsaRAccountContractArtifact = loadContractArtifact(EcdsaRAccountContractJson as NoirCompiledContract);
@@ -1,5 +0,0 @@
1
- import { type NoirCompiledContract, loadContractArtifact } from '@aztec/aztec.js';
2
-
3
- import SchnorrAccountContractJson from '../../artifacts/SchnorrAccount.json' assert { type: 'json' };
4
-
5
- export const SchnorrAccountContractArtifact = loadContractArtifact(SchnorrAccountContractJson as NoirCompiledContract);
@@ -1,7 +0,0 @@
1
- import { type NoirCompiledContract, loadContractArtifact } from '@aztec/aztec.js';
2
-
3
- import SchnorrSingleKeyAccountContractJson from '../../artifacts/SchnorrSingleKeyAccount.json' assert { type: 'json' };
4
-
5
- export const SchnorrSingleKeyAccountContractArtifact = loadContractArtifact(
6
- SchnorrSingleKeyAccountContractJson as NoirCompiledContract,
7
- );