@aztec/accounts 0.22.0 → 0.24.0
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/artifacts/EcdsaAccount.json +564 -317
- package/dest/artifacts/SchnorrAccount.json +709 -461
- package/dest/artifacts/SchnorrSingleKeyAccount.json +836 -587
- package/dest/defaults/account_entrypoint.d.ts +3 -3
- package/dest/defaults/account_entrypoint.d.ts.map +1 -1
- package/dest/defaults/account_entrypoint.js +59 -47
- package/dest/defaults/account_interface.d.ts +3 -3
- package/dest/defaults/account_interface.d.ts.map +1 -1
- package/dest/defaults/account_interface.js +4 -4
- package/dest/defaults/entrypoint_payload.d.ts +13 -8
- package/dest/defaults/entrypoint_payload.d.ts.map +1 -1
- package/dest/defaults/entrypoint_payload.js +27 -10
- package/package.json +7 -7
- package/src/artifacts/EcdsaAccount.json +3273 -0
- package/src/artifacts/SchnorrAccount.json +3265 -0
- package/src/artifacts/SchnorrSingleKeyAccount.json +3180 -0
- package/src/defaults/account_contract.ts +25 -0
- package/src/defaults/account_entrypoint.ts +141 -0
- package/src/defaults/account_interface.ts +39 -0
- package/src/defaults/constants.ts +4 -0
- package/src/defaults/entrypoint_payload.ts +112 -0
- package/src/defaults/index.ts +13 -0
- package/src/ecdsa/account_contract.ts +38 -0
- package/src/ecdsa/artifact.ts +5 -0
- package/src/ecdsa/index.ts +42 -0
- package/src/schnorr/account_contract.ts +38 -0
- package/src/schnorr/artifact.ts +5 -0
- package/src/schnorr/index.ts +47 -0
- package/src/single_key/account_contract.ts +45 -0
- package/src/single_key/artifact.ts +7 -0
- package/src/single_key/index.ts +52 -0
- package/src/testing/configuration.ts +81 -0
- package/src/testing/create_account.ts +39 -0
- package/src/testing/index.ts +11 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { generatePublicKey } from '@aztec/aztec.js';
|
|
2
|
+
import { AccountWalletWithPrivateKey } from '@aztec/aztec.js/wallet';
|
|
3
|
+
import { PXE } from '@aztec/circuit-types';
|
|
4
|
+
import { Fr, GrumpkinScalar } from '@aztec/foundation/fields';
|
|
5
|
+
|
|
6
|
+
import { getSchnorrAccount } from '../schnorr/index.js';
|
|
7
|
+
|
|
8
|
+
export const INITIAL_TEST_ENCRYPTION_KEYS = [
|
|
9
|
+
GrumpkinScalar.fromString('2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281'),
|
|
10
|
+
GrumpkinScalar.fromString('aebd1b4be76efa44f5ee655c20bf9ea60f7ae44b9a7fd1fd9f189c7a0b0cdae'),
|
|
11
|
+
GrumpkinScalar.fromString('0f6addf0da06c33293df974a565b03d1ab096090d907d98055a8b7f4954e120c'),
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
export const INITIAL_TEST_SIGNING_KEYS = INITIAL_TEST_ENCRYPTION_KEYS;
|
|
15
|
+
|
|
16
|
+
export const INITIAL_TEST_ACCOUNT_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Gets a collection of wallets for the Aztec accounts that are initially stored in the test environment.
|
|
20
|
+
* @param pxe - PXE instance.
|
|
21
|
+
* @returns A set of AccountWallet implementations for each of the initial accounts.
|
|
22
|
+
*/
|
|
23
|
+
export function getInitialTestAccountsWallets(pxe: PXE): Promise<AccountWalletWithPrivateKey[]> {
|
|
24
|
+
return Promise.all(
|
|
25
|
+
INITIAL_TEST_ENCRYPTION_KEYS.map((encryptionKey, i) =>
|
|
26
|
+
getSchnorrAccount(pxe, encryptionKey!, INITIAL_TEST_SIGNING_KEYS[i]!, INITIAL_TEST_ACCOUNT_SALTS[i]).getWallet(),
|
|
27
|
+
),
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Queries a PXE for it's registered accounts and returns wallets for those accounts using keys in the initial test accounts.
|
|
33
|
+
* @param pxe - PXE instance.
|
|
34
|
+
* @returns A set of AccountWallet implementations for each of the initial accounts.
|
|
35
|
+
*/
|
|
36
|
+
export async function getDeployedTestAccountsWallets(pxe: PXE): Promise<AccountWalletWithPrivateKey[]> {
|
|
37
|
+
const registeredAccounts = await pxe.getRegisteredAccounts();
|
|
38
|
+
return Promise.all(
|
|
39
|
+
INITIAL_TEST_ENCRYPTION_KEYS.filter(initialKey => {
|
|
40
|
+
const publicKey = generatePublicKey(initialKey);
|
|
41
|
+
return registeredAccounts.find(registered => registered.publicKey.equals(publicKey)) != undefined;
|
|
42
|
+
}).map((encryptionKey, i) =>
|
|
43
|
+
getSchnorrAccount(pxe, encryptionKey!, INITIAL_TEST_SIGNING_KEYS[i]!, INITIAL_TEST_ACCOUNT_SALTS[i]).getWallet(),
|
|
44
|
+
),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Deploys the initial set of schnorr signature accounts to the test environment
|
|
50
|
+
* @param pxe - PXE instance.
|
|
51
|
+
* @returns The set of deployed Account objects and associated private encryption keys
|
|
52
|
+
*/
|
|
53
|
+
export async function deployInitialTestAccounts(pxe: PXE) {
|
|
54
|
+
const accounts = INITIAL_TEST_ENCRYPTION_KEYS.map((privateKey, i) => {
|
|
55
|
+
const account = getSchnorrAccount(pxe, privateKey, INITIAL_TEST_SIGNING_KEYS[i], INITIAL_TEST_ACCOUNT_SALTS[i]);
|
|
56
|
+
return {
|
|
57
|
+
account,
|
|
58
|
+
privateKey,
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
// Attempt to get as much parallelism as possible
|
|
62
|
+
const deployMethods = await Promise.all(
|
|
63
|
+
accounts.map(async x => {
|
|
64
|
+
const deployMethod = await x.account.getDeployMethod();
|
|
65
|
+
await deployMethod.create({ contractAddressSalt: x.account.salt });
|
|
66
|
+
await deployMethod.simulate({});
|
|
67
|
+
return deployMethod;
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
// Send tx together to try and get them in the same rollup
|
|
71
|
+
const sentTxs = deployMethods.map(dm => {
|
|
72
|
+
return dm.send();
|
|
73
|
+
});
|
|
74
|
+
await Promise.all(
|
|
75
|
+
sentTxs.map(async (tx, i) => {
|
|
76
|
+
const wallet = await accounts[i].account.getWallet();
|
|
77
|
+
return tx.wait({ wallet });
|
|
78
|
+
}),
|
|
79
|
+
);
|
|
80
|
+
return accounts;
|
|
81
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { AccountWalletWithPrivateKey } from '@aztec/aztec.js/wallet';
|
|
2
|
+
import { PXE } from '@aztec/circuit-types';
|
|
3
|
+
import { GrumpkinScalar } from '@aztec/circuits.js';
|
|
4
|
+
|
|
5
|
+
import { getSchnorrAccount } from '../schnorr/index.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Deploys and registers a new account using random private keys and returns the associated Schnorr account wallet. Useful for testing.
|
|
9
|
+
* @param pxe - PXE.
|
|
10
|
+
* @returns - A wallet for a fresh account.
|
|
11
|
+
*/
|
|
12
|
+
export function createAccount(pxe: PXE): Promise<AccountWalletWithPrivateKey> {
|
|
13
|
+
return getSchnorrAccount(pxe, GrumpkinScalar.random(), GrumpkinScalar.random()).waitDeploy();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates a given number of random accounts using the Schnorr account wallet.
|
|
18
|
+
* @param pxe - PXE.
|
|
19
|
+
* @param numberOfAccounts - How many accounts to create.
|
|
20
|
+
* @returns The created account wallets.
|
|
21
|
+
*/
|
|
22
|
+
export async function createAccounts(pxe: PXE, numberOfAccounts = 1): Promise<AccountWalletWithPrivateKey[]> {
|
|
23
|
+
const accounts = [];
|
|
24
|
+
|
|
25
|
+
// Prepare deployments
|
|
26
|
+
for (let i = 0; i < numberOfAccounts; ++i) {
|
|
27
|
+
const account = getSchnorrAccount(pxe, GrumpkinScalar.random(), GrumpkinScalar.random());
|
|
28
|
+
// Unfortunately the function below is not stateless and we call it here because it takes a long time to run and
|
|
29
|
+
// the results get stored within the account object. By calling it here we increase the probability of all the
|
|
30
|
+
// accounts being deployed in the same block because it makes the deploy() method basically instant.
|
|
31
|
+
await account.getDeployMethod().then(d => d.simulate({ contractAddressSalt: account.salt }));
|
|
32
|
+
accounts.push(account);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Send them and await them to be mined
|
|
36
|
+
const txs = await Promise.all(accounts.map(account => account.deploy()));
|
|
37
|
+
await Promise.all(txs.map(tx => tx.wait({ interval: 0.1 })));
|
|
38
|
+
return Promise.all(accounts.map(account => account.getWallet()));
|
|
39
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `@aztec/accounts/testing` export provides utility methods for testing, in particular in a Sandbox environment.
|
|
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.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export * from './create_account.js';
|
|
11
|
+
export * from './configuration.js';
|