@aztec/accounts 0.0.1-commit.42ee6df9b → 0.0.1-commit.431c48d

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 (105) hide show
  1. package/artifacts/EcdsaKAccount.json +10590 -9314
  2. package/artifacts/EcdsaRAccount.json +10586 -9310
  3. package/artifacts/SchnorrAccount.json +10674 -9442
  4. package/artifacts/SchnorrInitializerlessAccount.json +8526 -0
  5. package/artifacts/SimulatedEcdsaAccount.d.json.ts +3 -0
  6. package/artifacts/SimulatedEcdsaAccount.json +10972 -0
  7. package/artifacts/SimulatedSchnorrAccount.d.json.ts +3 -0
  8. package/artifacts/SimulatedSchnorrAccount.json +11084 -0
  9. package/dest/defaults/account_contract.d.ts +7 -1
  10. package/dest/defaults/account_contract.d.ts.map +1 -1
  11. package/dest/defaults/account_contract.js +6 -0
  12. package/dest/{stub/account_contract.d.ts → defaults/stub_account_contract.d.ts} +1 -1
  13. package/dest/defaults/stub_account_contract.d.ts.map +1 -0
  14. package/dest/ecdsa/ecdsa_k/account_contract.d.ts +1 -1
  15. package/dest/ecdsa/ecdsa_k/account_contract.js +6 -2
  16. package/dest/ecdsa/ecdsa_k/lazy.js +1 -1
  17. package/dest/ecdsa/ecdsa_r/account_contract.d.ts +1 -1
  18. package/dest/ecdsa/ecdsa_r/account_contract.js +6 -2
  19. package/dest/ecdsa/ecdsa_r/lazy.js +1 -1
  20. package/dest/ecdsa/ssh_ecdsa_r/account_contract.d.ts +1 -1
  21. package/dest/ecdsa/ssh_ecdsa_r/account_contract.js +6 -2
  22. package/dest/ecdsa/stub/index.d.ts +11 -0
  23. package/dest/ecdsa/stub/index.d.ts.map +1 -0
  24. package/dest/ecdsa/stub/index.js +18 -0
  25. package/dest/ecdsa/stub/lazy.d.ts +14 -0
  26. package/dest/ecdsa/stub/lazy.d.ts.map +1 -0
  27. package/dest/ecdsa/stub/lazy.js +22 -0
  28. package/dest/schnorr/account_contract.d.ts +8 -4
  29. package/dest/schnorr/account_contract.d.ts.map +1 -1
  30. package/dest/schnorr/account_contract.js +6 -5
  31. package/dest/schnorr/index.d.ts +3 -23
  32. package/dest/schnorr/index.d.ts.map +1 -1
  33. package/dest/schnorr/index.js +2 -35
  34. package/dest/schnorr/initializerless/index.d.ts +25 -0
  35. package/dest/schnorr/initializerless/index.d.ts.map +1 -0
  36. package/dest/schnorr/initializerless/index.js +46 -0
  37. package/dest/schnorr/initializerless/lazy.d.ts +29 -0
  38. package/dest/schnorr/initializerless/lazy.d.ts.map +1 -0
  39. package/dest/schnorr/initializerless/lazy.js +54 -0
  40. package/dest/schnorr/lazy.d.ts +3 -27
  41. package/dest/schnorr/lazy.d.ts.map +1 -1
  42. package/dest/schnorr/lazy.js +2 -43
  43. package/dest/schnorr/private_immutable/index.d.ts +23 -0
  44. package/dest/schnorr/private_immutable/index.d.ts.map +1 -0
  45. package/dest/schnorr/private_immutable/index.js +35 -0
  46. package/dest/schnorr/private_immutable/lazy.d.ts +27 -0
  47. package/dest/schnorr/private_immutable/lazy.d.ts.map +1 -0
  48. package/dest/schnorr/private_immutable/lazy.js +43 -0
  49. package/dest/schnorr/stub/index.d.ts +11 -0
  50. package/dest/schnorr/stub/index.d.ts.map +1 -0
  51. package/dest/schnorr/stub/index.js +18 -0
  52. package/dest/schnorr/stub/lazy.d.ts +14 -0
  53. package/dest/schnorr/stub/lazy.d.ts.map +1 -0
  54. package/dest/schnorr/stub/lazy.js +22 -0
  55. package/dest/testing/configuration.d.ts +9 -1
  56. package/dest/testing/configuration.d.ts.map +1 -1
  57. package/dest/testing/configuration.js +6 -2
  58. package/dest/testing/index.d.ts +5 -5
  59. package/dest/testing/index.d.ts.map +1 -1
  60. package/dest/testing/index.js +20 -12
  61. package/dest/testing/lazy.d.ts +4 -4
  62. package/dest/testing/lazy.d.ts.map +1 -1
  63. package/dest/testing/lazy.js +20 -12
  64. package/dest/utils/index.d.ts +2 -1
  65. package/dest/utils/index.d.ts.map +1 -1
  66. package/dest/utils/index.js +1 -0
  67. package/dest/utils/key_derivation.d.ts +9 -0
  68. package/dest/utils/key_derivation.d.ts.map +1 -0
  69. package/dest/utils/key_derivation.js +16 -0
  70. package/package.json +10 -10
  71. package/src/defaults/account_contract.ts +9 -0
  72. package/src/ecdsa/ecdsa_k/account_contract.ts +1 -1
  73. package/src/ecdsa/ecdsa_k/lazy.ts +1 -1
  74. package/src/ecdsa/ecdsa_r/account_contract.ts +1 -1
  75. package/src/ecdsa/ecdsa_r/lazy.ts +1 -1
  76. package/src/ecdsa/ssh_ecdsa_r/account_contract.ts +1 -1
  77. package/src/ecdsa/stub/index.ts +28 -0
  78. package/src/ecdsa/stub/lazy.ts +34 -0
  79. package/src/schnorr/account_contract.ts +18 -5
  80. package/src/schnorr/index.ts +2 -50
  81. package/src/schnorr/initializerless/index.ts +62 -0
  82. package/src/schnorr/initializerless/lazy.ts +70 -0
  83. package/src/schnorr/lazy.ts +2 -60
  84. package/src/schnorr/private_immutable/index.ts +50 -0
  85. package/src/schnorr/private_immutable/lazy.ts +60 -0
  86. package/src/schnorr/stub/index.ts +30 -0
  87. package/src/schnorr/stub/lazy.ts +34 -0
  88. package/src/testing/configuration.ts +15 -2
  89. package/src/testing/index.ts +29 -13
  90. package/src/testing/lazy.ts +28 -13
  91. package/src/utils/index.ts +1 -0
  92. package/src/utils/key_derivation.ts +15 -0
  93. package/artifacts/SimulatedAccount.json +0 -6482
  94. package/dest/stub/account_contract.d.ts.map +0 -1
  95. package/dest/stub/index.d.ts +0 -20
  96. package/dest/stub/index.d.ts.map +0 -1
  97. package/dest/stub/index.js +0 -28
  98. package/dest/stub/lazy.d.ts +0 -25
  99. package/dest/stub/lazy.d.ts.map +0 -1
  100. package/dest/stub/lazy.js +0 -37
  101. package/src/stub/index.ts +0 -40
  102. package/src/stub/lazy.ts +0 -51
  103. /package/artifacts/{SimulatedAccount.d.json.ts → SchnorrInitializerlessAccount.d.json.ts} +0 -0
  104. /package/dest/{stub/account_contract.js → defaults/stub_account_contract.js} +0 -0
  105. /package/src/{stub/account_contract.ts → defaults/stub_account_contract.ts} +0 -0
@@ -4,15 +4,17 @@
4
4
  * @packageDocumentation
5
5
  */
6
6
  import { Fr } from '@aztec/aztec.js/fields';
7
- import { deriveSigningKey } from '@aztec/stdlib/keys';
7
+ import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
8
8
 
9
- import { getSchnorrAccountContractAddress } from '../schnorr/index.js';
9
+ import { getSchnorrInitializerlessAccountContractAddress } from '../schnorr/initializerless/index.js';
10
+ import { getSchnorrAccountContractAddress } from '../schnorr/private_immutable/index.js';
11
+ import { deriveSecretKeyFromSigningKey } from '../utils/key_derivation.js';
10
12
  import {
11
13
  INITIAL_TEST_ACCOUNT_SALTS,
12
- INITIAL_TEST_ENCRYPTION_KEYS,
13
14
  INITIAL_TEST_SECRET_KEYS,
14
15
  INITIAL_TEST_SIGNING_KEYS,
15
16
  type InitialAccountData,
17
+ type InitialAccountType,
16
18
  } from './configuration.js';
17
19
 
18
20
  export {
@@ -21,8 +23,16 @@ export {
21
23
  INITIAL_TEST_SECRET_KEYS,
22
24
  INITIAL_TEST_SIGNING_KEYS,
23
25
  type InitialAccountData,
26
+ type InitialAccountType,
24
27
  } from './configuration.js';
25
28
 
29
+ /** Derives the account contract address for the given type */
30
+ function getTestAccountAddress(type: InitialAccountType, signingKey: GrumpkinScalar, salt: Fr, secret?: Fr) {
31
+ return type === 'schnorr'
32
+ ? getSchnorrAccountContractAddress(signingKey, salt, secret)
33
+ : getSchnorrInitializerlessAccountContractAddress(signingKey, salt, secret);
34
+ }
35
+
26
36
  /**
27
37
  * Gets the basic information for initial test accounts.
28
38
  */
@@ -30,30 +40,36 @@ export function getInitialTestAccountsData(): Promise<InitialAccountData[]> {
30
40
  return Promise.all(
31
41
  INITIAL_TEST_SECRET_KEYS.map(async (secret, i) => ({
32
42
  secret,
33
- signingKey: INITIAL_TEST_ENCRYPTION_KEYS[i],
43
+ signingKey: INITIAL_TEST_SIGNING_KEYS[i],
34
44
  salt: INITIAL_TEST_ACCOUNT_SALTS[i],
35
- address: await getSchnorrAccountContractAddress(
36
- secret,
37
- INITIAL_TEST_ACCOUNT_SALTS[i],
45
+ type: 'schnorr_initializerless' as const,
46
+ address: await getSchnorrInitializerlessAccountContractAddress(
38
47
  INITIAL_TEST_SIGNING_KEYS[i],
48
+ INITIAL_TEST_ACCOUNT_SALTS[i],
49
+ secret,
39
50
  ),
40
51
  })),
41
52
  );
42
53
  }
43
54
 
44
55
  /**
45
- * Generate a fixed amount of random schnorr account contract instance.
56
+ * Generate a fixed amount of random schnorr account contract instances of the given type
46
57
  */
47
- export async function generateSchnorrAccounts(numberOfAccounts: number): Promise<Promise<InitialAccountData[]>> {
48
- const secrets = Array.from({ length: numberOfAccounts }, () => Fr.random());
58
+ export async function generateSchnorrAccounts(
59
+ numberOfAccounts: number,
60
+ type: InitialAccountType = 'schnorr_initializerless',
61
+ ): Promise<InitialAccountData[]> {
62
+ const signingKeys = Array.from({ length: numberOfAccounts }, () => GrumpkinScalar.random());
49
63
  return await Promise.all(
50
- secrets.map(async secret => {
64
+ signingKeys.map(async signingKey => {
51
65
  const salt = Fr.random();
66
+ const secret = await deriveSecretKeyFromSigningKey(signingKey);
52
67
  return {
53
68
  secret,
54
- signingKey: deriveSigningKey(secret),
69
+ signingKey,
55
70
  salt,
56
- address: await getSchnorrAccountContractAddress(secret, salt),
71
+ type,
72
+ address: await getTestAccountAddress(type, signingKey, salt, secret),
57
73
  };
58
74
  }),
59
75
  );
@@ -4,19 +4,28 @@
4
4
  * @packageDocumentation
5
5
  */
6
6
  import { Fr } from '@aztec/aztec.js/fields';
7
- import { deriveSigningKey } from '@aztec/stdlib/keys';
7
+ import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
8
8
 
9
- import { getSchnorrAccountContractAddress } from '../schnorr/lazy.js';
9
+ import { getSchnorrInitializerlessAccountContractAddress } from '../schnorr/initializerless/lazy.js';
10
+ import { getSchnorrAccountContractAddress } from '../schnorr/private_immutable/lazy.js';
11
+ import { deriveSecretKeyFromSigningKey } from '../utils/key_derivation.js';
10
12
  import {
11
13
  INITIAL_TEST_ACCOUNT_SALTS,
12
- INITIAL_TEST_ENCRYPTION_KEYS,
13
14
  INITIAL_TEST_SECRET_KEYS,
14
15
  INITIAL_TEST_SIGNING_KEYS,
15
16
  type InitialAccountData,
17
+ type InitialAccountType,
16
18
  } from './configuration.js';
17
19
 
18
20
  export { INITIAL_TEST_ACCOUNT_SALTS, INITIAL_TEST_SECRET_KEYS } from './configuration.js';
19
21
 
22
+ /** Derives the account contract address for the given type */
23
+ function getTestAccountAddress(type: InitialAccountType, signingKey: GrumpkinScalar, salt: Fr, secret?: Fr) {
24
+ return type === 'schnorr'
25
+ ? getSchnorrAccountContractAddress(signingKey, salt, secret)
26
+ : getSchnorrInitializerlessAccountContractAddress(signingKey, salt, secret);
27
+ }
28
+
20
29
  /**
21
30
  * Gets the basic information for initial test accounts.
22
31
  */
@@ -24,30 +33,36 @@ export function getInitialTestAccountsData(): Promise<InitialAccountData[]> {
24
33
  return Promise.all(
25
34
  INITIAL_TEST_SECRET_KEYS.map(async (secret, i) => ({
26
35
  secret,
27
- signingKey: INITIAL_TEST_ENCRYPTION_KEYS[i],
36
+ signingKey: INITIAL_TEST_SIGNING_KEYS[i],
28
37
  salt: INITIAL_TEST_ACCOUNT_SALTS[i],
29
- address: await getSchnorrAccountContractAddress(
30
- secret,
31
- INITIAL_TEST_ACCOUNT_SALTS[i],
38
+ type: 'schnorr_initializerless' as const,
39
+ address: await getSchnorrInitializerlessAccountContractAddress(
32
40
  INITIAL_TEST_SIGNING_KEYS[i],
41
+ INITIAL_TEST_ACCOUNT_SALTS[i],
42
+ secret,
33
43
  ),
34
44
  })),
35
45
  );
36
46
  }
37
47
 
38
48
  /**
39
- * Generate a fixed amount of random schnorr account contract instance.
49
+ * Generate a fixed amount of random schnorr account contract instances of the given type
40
50
  */
41
- export async function generateSchnorrAccounts(numberOfAccounts: number): Promise<InitialAccountData[]> {
42
- const secrets = Array.from({ length: numberOfAccounts }, () => Fr.random());
51
+ export async function generateSchnorrAccounts(
52
+ numberOfAccounts: number,
53
+ type: InitialAccountType = 'schnorr_initializerless',
54
+ ): Promise<InitialAccountData[]> {
55
+ const signingKeys = Array.from({ length: numberOfAccounts }, () => GrumpkinScalar.random());
43
56
  return await Promise.all(
44
- secrets.map(async secret => {
57
+ signingKeys.map(async signingKey => {
45
58
  const salt = Fr.random();
59
+ const secret = await deriveSecretKeyFromSigningKey(signingKey);
46
60
  return {
47
61
  secret,
48
- signingKey: deriveSigningKey(secret),
62
+ signingKey,
49
63
  salt,
50
- address: await getSchnorrAccountContractAddress(secret, salt),
64
+ type,
65
+ address: await getTestAccountAddress(type, signingKey, salt, secret),
51
66
  };
52
67
  }),
53
68
  );
@@ -1 +1,2 @@
1
+ export * from './key_derivation.js';
1
2
  export * from './ssh_agent.js';
@@ -0,0 +1,15 @@
1
+ import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
2
+ import { sha256ToField } from '@aztec/foundation/crypto/sha256';
3
+ import type { Fr } from '@aztec/foundation/curves/bn254';
4
+ import type { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
5
+
6
+ const SIGNING_KEY_TO_SECRET_KEY_SEPARATOR = sha256ToField([Buffer.from('@aztec/accounts/signing_key_to_secret_key')]);
7
+
8
+ /**
9
+ * Derives the privacy secret key (the seed for the viewing/nullifier keyset that PXE holds) from the account's signing
10
+ * key. The signing key is the ownership root the user controls; the privacy keyset hangs off it through this one-way
11
+ * hash, so a value handled by PXE can never be used to recover the signing key.
12
+ */
13
+ export function deriveSecretKeyFromSigningKey(signingKey: GrumpkinScalar): Promise<Fr> {
14
+ return poseidon2Hash([SIGNING_KEY_TO_SECRET_KEY_SEPARATOR, signingKey.hi, signingKey.lo]);
15
+ }