@aztec/accounts 0.70.0 → 0.72.1

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 (45) hide show
  1. package/artifacts/EcdsaKAccount.json +456 -273
  2. package/artifacts/EcdsaRAccount.json +355 -172
  3. package/artifacts/SchnorrAccount.json +632 -457
  4. package/artifacts/SchnorrSingleKeyAccount.json +165 -49
  5. package/dest/defaults/account_contract.d.ts +1 -1
  6. package/dest/defaults/account_contract.d.ts.map +1 -1
  7. package/dest/ecdsa/ecdsa_k/account_contract.d.ts +1 -1
  8. package/dest/ecdsa/ecdsa_k/account_contract.d.ts.map +1 -1
  9. package/dest/ecdsa/ecdsa_k/account_contract.js +5 -5
  10. package/dest/ecdsa/ecdsa_k/index.d.ts +2 -1
  11. package/dest/ecdsa/ecdsa_k/index.d.ts.map +1 -1
  12. package/dest/ecdsa/ecdsa_k/index.js +3 -2
  13. package/dest/ecdsa/ssh_ecdsa_r/account_contract.d.ts +1 -1
  14. package/dest/ecdsa/ssh_ecdsa_r/account_contract.js +2 -2
  15. package/dest/ecdsa/ssh_ecdsa_r/index.d.ts +2 -1
  16. package/dest/ecdsa/ssh_ecdsa_r/index.d.ts.map +1 -1
  17. package/dest/ecdsa/ssh_ecdsa_r/index.js +3 -2
  18. package/dest/schnorr/account_contract.d.ts +1 -1
  19. package/dest/schnorr/account_contract.d.ts.map +1 -1
  20. package/dest/schnorr/account_contract.js +6 -6
  21. package/dest/schnorr/index.d.ts +2 -1
  22. package/dest/schnorr/index.d.ts.map +1 -1
  23. package/dest/schnorr/index.js +3 -2
  24. package/dest/single_key/account_contract.d.ts +1 -1
  25. package/dest/single_key/account_contract.d.ts.map +1 -1
  26. package/dest/single_key/account_contract.js +4 -4
  27. package/dest/single_key/index.d.ts +2 -1
  28. package/dest/single_key/index.d.ts.map +1 -1
  29. package/dest/single_key/index.js +3 -2
  30. package/dest/testing/configuration.d.ts.map +1 -1
  31. package/dest/testing/configuration.js +21 -13
  32. package/dest/testing/create_account.d.ts.map +1 -1
  33. package/dest/testing/create_account.js +6 -5
  34. package/package.json +8 -8
  35. package/src/defaults/account_contract.ts +1 -1
  36. package/src/ecdsa/ecdsa_k/account_contract.ts +4 -4
  37. package/src/ecdsa/ecdsa_k/index.ts +8 -2
  38. package/src/ecdsa/ssh_ecdsa_r/account_contract.ts +1 -1
  39. package/src/ecdsa/ssh_ecdsa_r/index.ts +8 -2
  40. package/src/schnorr/account_contract.ts +5 -5
  41. package/src/schnorr/index.ts +3 -2
  42. package/src/single_key/account_contract.ts +4 -4
  43. package/src/single_key/index.ts +3 -2
  44. package/src/testing/configuration.ts +44 -22
  45. package/src/testing/create_account.ts +5 -4
@@ -20,9 +20,15 @@ export { EcdsaKAccountContract };
20
20
  * @param secretKey - Secret key used to derive all the keystore keys.
21
21
  * @param signingPrivateKey - Secp256k1 key used for signing transactions.
22
22
  * @param salt - Deployment salt.
23
+ * @returns An account manager initialized with the account contract and its deployment params
23
24
  */
24
- export function getEcdsaKAccount(pxe: PXE, secretKey: Fr, signingPrivateKey: Buffer, salt?: Salt): AccountManager {
25
- return new AccountManager(pxe, secretKey, new EcdsaKAccountContract(signingPrivateKey), salt);
25
+ export function getEcdsaKAccount(
26
+ pxe: PXE,
27
+ secretKey: Fr,
28
+ signingPrivateKey: Buffer,
29
+ salt?: Salt,
30
+ ): Promise<AccountManager> {
31
+ return AccountManager.create(pxe, secretKey, new EcdsaKAccountContract(signingPrivateKey), salt);
26
32
  }
27
33
 
28
34
  /**
@@ -22,7 +22,7 @@ export class EcdsaRSSHAccountContract extends DefaultAccountContract {
22
22
  }
23
23
 
24
24
  getDeploymentArgs() {
25
- return [this.signingPublicKey.subarray(0, 32), this.signingPublicKey.subarray(32, 64)];
25
+ return Promise.resolve([this.signingPublicKey.subarray(0, 32), this.signingPublicKey.subarray(32, 64)]);
26
26
  }
27
27
 
28
28
  getAuthWitnessProvider(_address: CompleteAddress): AuthWitnessProvider {
@@ -20,9 +20,15 @@ export { EcdsaRSSHAccountContract };
20
20
  * @param secretKey - Secret key used to derive all the keystore keys.
21
21
  * @param signingPublicKey - Secp2561 key used to identify its corresponding private key in the SSH Agent.
22
22
  * @param salt - Deployment salt.
23
+ * @returns An account manager initialized with the account contract and its deployment params
23
24
  */
24
- export function getEcdsaRSSHAccount(pxe: PXE, secretKey: Fr, signingPublicKey: Buffer, salt?: Salt): AccountManager {
25
- return new AccountManager(pxe, secretKey, new EcdsaRSSHAccountContract(signingPublicKey), salt);
25
+ export function getEcdsaRSSHAccount(
26
+ pxe: PXE,
27
+ secretKey: Fr,
28
+ signingPublicKey: Buffer,
29
+ salt?: Salt,
30
+ ): Promise<AccountManager> {
31
+ return AccountManager.create(pxe, secretKey, new EcdsaRSSHAccountContract(signingPublicKey), salt);
26
32
  }
27
33
 
28
34
  /**
@@ -16,8 +16,8 @@ export class SchnorrAccountContract extends DefaultAccountContract {
16
16
  super(SchnorrAccountContractArtifact as ContractArtifact);
17
17
  }
18
18
 
19
- getDeploymentArgs() {
20
- const signingPublicKey = new Schnorr().computePublicKey(this.signingPrivateKey);
19
+ async getDeploymentArgs() {
20
+ const signingPublicKey = await new Schnorr().computePublicKey(this.signingPrivateKey);
21
21
  return [signingPublicKey.x, signingPublicKey.y];
22
22
  }
23
23
 
@@ -30,9 +30,9 @@ export class SchnorrAccountContract extends DefaultAccountContract {
30
30
  class SchnorrAuthWitnessProvider implements AuthWitnessProvider {
31
31
  constructor(private signingPrivateKey: GrumpkinScalar) {}
32
32
 
33
- createAuthWit(messageHash: Fr): Promise<AuthWitness> {
33
+ async createAuthWit(messageHash: Fr): Promise<AuthWitness> {
34
34
  const schnorr = new Schnorr();
35
- const signature = schnorr.constructSignature(messageHash.toBuffer(), this.signingPrivateKey).toBuffer();
36
- return Promise.resolve(new AuthWitness(messageHash, [...signature]));
35
+ const signature = await schnorr.constructSignature(messageHash.toBuffer(), this.signingPrivateKey);
36
+ return new AuthWitness(messageHash, [...signature.toBuffer()]);
37
37
  }
38
38
  }
@@ -21,14 +21,15 @@ export { SchnorrAccountContractArtifact } from './artifact.js';
21
21
  * @param secretKey - Secret key used to derive all the keystore keys.
22
22
  * @param signingPrivateKey - Grumpkin key used for signing transactions.
23
23
  * @param salt - Deployment salt.
24
+ * @returns An account manager initialized with the account contract and its deployment params
24
25
  */
25
26
  export function getSchnorrAccount(
26
27
  pxe: PXE,
27
28
  secretKey: Fr,
28
29
  signingPrivateKey: GrumpkinScalar,
29
30
  salt?: Salt,
30
- ): AccountManager {
31
- return new AccountManager(pxe, secretKey, new SchnorrAccountContract(signingPrivateKey), salt);
31
+ ): Promise<AccountManager> {
32
+ return AccountManager.create(pxe, secretKey, new SchnorrAccountContract(signingPrivateKey), salt);
32
33
  }
33
34
 
34
35
  /**
@@ -16,8 +16,8 @@ export class SingleKeyAccountContract extends DefaultAccountContract {
16
16
  super(SchnorrSingleKeyAccountContractArtifact as ContractArtifact);
17
17
  }
18
18
 
19
- getDeploymentArgs(): undefined {
20
- return undefined;
19
+ getDeploymentArgs() {
20
+ return Promise.resolve(undefined);
21
21
  }
22
22
 
23
23
  getAuthWitnessProvider(account: CompleteAddress): AuthWitnessProvider {
@@ -33,9 +33,9 @@ export class SingleKeyAccountContract extends DefaultAccountContract {
33
33
  class SingleKeyAuthWitnessProvider implements AuthWitnessProvider {
34
34
  constructor(private privateKey: GrumpkinScalar, private account: CompleteAddress) {}
35
35
 
36
- createAuthWit(messageHash: Fr): Promise<AuthWitness> {
36
+ async createAuthWit(messageHash: Fr): Promise<AuthWitness> {
37
37
  const schnorr = new Schnorr();
38
- const signature = schnorr.constructSignature(messageHash.toBuffer(), this.privateKey);
38
+ const signature = await schnorr.constructSignature(messageHash.toBuffer(), this.privateKey);
39
39
  const witness = [...this.account.publicKeys.toFields(), ...signature.toBuffer(), this.account.partialAddress];
40
40
  return Promise.resolve(new AuthWitness(messageHash, witness));
41
41
  }
@@ -20,10 +20,11 @@ export { SchnorrSingleKeyAccountContractArtifact as SingleKeyAccountContractArti
20
20
  * @param pxe - An PXE server instance.
21
21
  * @param secretKey - Secret key used to derive all the keystore keys (in this case also used to get signing key).
22
22
  * @param salt - Deployment salt.
23
+ * @returns An account manager initialized with the account contract and its deployment params
23
24
  */
24
- export function getSingleKeyAccount(pxe: PXE, secretKey: Fr, salt?: Salt): AccountManager {
25
+ export function getSingleKeyAccount(pxe: PXE, secretKey: Fr, salt?: Salt) {
25
26
  const encryptionPrivateKey = deriveMasterIncomingViewingSecretKey(secretKey);
26
- return new AccountManager(pxe, secretKey, new SingleKeyAccountContract(encryptionPrivateKey), salt);
27
+ return AccountManager.create(pxe, secretKey, new SingleKeyAccountContract(encryptionPrivateKey), salt);
27
28
  }
28
29
 
29
30
  /**
@@ -29,9 +29,15 @@ export const INITIAL_TEST_ACCOUNT_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO];
29
29
  */
30
30
  export function getInitialTestAccountsWallets(pxe: PXE): Promise<AccountWalletWithSecretKey[]> {
31
31
  return Promise.all(
32
- INITIAL_TEST_SECRET_KEYS.map((encryptionKey, i) =>
33
- getSchnorrAccount(pxe, encryptionKey!, INITIAL_TEST_SIGNING_KEYS[i]!, INITIAL_TEST_ACCOUNT_SALTS[i]).getWallet(),
34
- ),
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
+ }),
35
41
  );
36
42
  }
37
43
 
@@ -42,20 +48,29 @@ export function getInitialTestAccountsWallets(pxe: PXE): Promise<AccountWalletWi
42
48
  */
43
49
  export async function getDeployedTestAccountsWallets(pxe: PXE): Promise<AccountWalletWithSecretKey[]> {
44
50
  const registeredAccounts = await pxe.getRegisteredAccounts();
45
- return Promise.all(
46
- INITIAL_TEST_SECRET_KEYS.filter(initialSecretKey => {
51
+ const publicKeys = await Promise.all(
52
+ INITIAL_TEST_SECRET_KEYS.map(async initialSecretKey => {
47
53
  const initialEncryptionKey = deriveMasterIncomingViewingSecretKey(initialSecretKey);
48
- const publicKey = generatePublicKey(initialEncryptionKey);
49
- return (
50
- registeredAccounts.find(registered => registered.publicKeys.masterIncomingViewingPublicKey.equals(publicKey)) !=
51
- undefined
52
- );
53
- }).map(secretKey => {
54
- const signingKey = deriveSigningKey(secretKey);
55
- // TODO(#5726): use actual salt here instead of hardcoding Fr.ZERO
56
- return getSchnorrAccount(pxe, secretKey, signingKey, Fr.ZERO).getWallet();
54
+ const publicKey = await generatePublicKey(initialEncryptionKey);
55
+ return { sk: initialSecretKey, pk: publicKey };
57
56
  }),
58
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
+ );
59
74
  }
60
75
 
61
76
  /**
@@ -64,13 +79,20 @@ export async function getDeployedTestAccountsWallets(pxe: PXE): Promise<AccountW
64
79
  * @returns The set of deployed Account objects and associated private encryption keys
65
80
  */
66
81
  export async function deployInitialTestAccounts(pxe: PXE) {
67
- const accounts = INITIAL_TEST_SECRET_KEYS.map((secretKey, i) => {
68
- const account = getSchnorrAccount(pxe, secretKey, INITIAL_TEST_SIGNING_KEYS[i], INITIAL_TEST_ACCOUNT_SALTS[i]);
69
- return {
70
- account,
71
- secretKey,
72
- };
73
- });
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
+ );
74
96
  // Register contract class to avoid duplicate nullifier errors
75
97
  const { l1ChainId: chainId, protocolVersion } = await pxe.getNodeInfo();
76
98
  const deployWallet = new SignerlessWallet(pxe, new DefaultMultiCallEntrypoint(chainId, protocolVersion));
@@ -80,7 +102,7 @@ export async function deployInitialTestAccounts(pxe: PXE) {
80
102
  accounts.map(async x => {
81
103
  const deployMethod = await x.account.getDeployMethod();
82
104
  const tx = await deployMethod.prove({
83
- contractAddressSalt: x.account.salt,
105
+ contractAddressSalt: new Fr(x.account.salt),
84
106
  universalDeploy: true,
85
107
  });
86
108
  return tx;
@@ -10,10 +10,11 @@ import { getSchnorrAccount } from '../schnorr/index.js';
10
10
  * @param pxe - PXE.
11
11
  * @returns - A wallet for a fresh account.
12
12
  */
13
- export function createAccount(pxe: PXE): Promise<AccountWalletWithSecretKey> {
13
+ export async function createAccount(pxe: PXE): Promise<AccountWalletWithSecretKey> {
14
14
  const secretKey = Fr.random();
15
15
  const signingKey = deriveSigningKey(secretKey);
16
- return getSchnorrAccount(pxe, secretKey, signingKey).waitSetup();
16
+ const account = await getSchnorrAccount(pxe, secretKey, signingKey);
17
+ return account.waitSetup();
17
18
  }
18
19
 
19
20
  /**
@@ -40,7 +41,7 @@ export async function createAccounts(
40
41
  const accountsAndDeployments = await Promise.all(
41
42
  secrets.map(async (secret, index) => {
42
43
  const signingKey = deriveSigningKey(secret);
43
- const account = getSchnorrAccount(pxe, secret, signingKey);
44
+ const account = await getSchnorrAccount(pxe, secret, signingKey);
44
45
 
45
46
  // only register the contract class once
46
47
  let skipClassRegistration = true;
@@ -53,7 +54,7 @@ export async function createAccounts(
53
54
 
54
55
  const deployMethod = await account.getDeployMethod();
55
56
  const provenTx = await deployMethod.prove({
56
- contractAddressSalt: account.salt,
57
+ contractAddressSalt: new Fr(account.salt),
57
58
  skipClassRegistration,
58
59
  skipPublicDeployment: true,
59
60
  universalDeploy: true,