@aztec-labs/accounts 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 (138) hide show
  1. package/README.md +40 -0
  2. package/artifacts/EcdsaKAccount.d.json.ts +3 -0
  3. package/artifacts/EcdsaKAccount.json +12861 -0
  4. package/artifacts/EcdsaRAccount.d.json.ts +3 -0
  5. package/artifacts/EcdsaRAccount.json +12861 -0
  6. package/artifacts/SchnorrAccount.d.json.ts +3 -0
  7. package/artifacts/SchnorrAccount.json +12914 -0
  8. package/artifacts/SchnorrInitializerlessAccount.d.json.ts +3 -0
  9. package/artifacts/SchnorrInitializerlessAccount.json +8530 -0
  10. package/artifacts/SimulatedEcdsaAccount.d.json.ts +3 -0
  11. package/artifacts/SimulatedEcdsaAccount.json +10980 -0
  12. package/artifacts/SimulatedSchnorrAccount.d.json.ts +3 -0
  13. package/artifacts/SimulatedSchnorrAccount.json +11092 -0
  14. package/dest/defaults/account_contract.d.ts +26 -0
  15. package/dest/defaults/account_contract.d.ts.map +1 -0
  16. package/dest/defaults/account_contract.js +18 -0
  17. package/dest/defaults/index.d.ts +9 -0
  18. package/dest/defaults/index.d.ts.map +1 -0
  19. package/dest/defaults/index.js +7 -0
  20. package/dest/defaults/stub_account_contract.d.ts +29 -0
  21. package/dest/defaults/stub_account_contract.d.ts.map +1 -0
  22. package/dest/defaults/stub_account_contract.js +30 -0
  23. package/dest/ecdsa/ecdsa_k/account_contract.d.ts +19 -0
  24. package/dest/ecdsa/ecdsa_k/account_contract.d.ts.map +1 -0
  25. package/dest/ecdsa/ecdsa_k/account_contract.js +45 -0
  26. package/dest/ecdsa/ecdsa_k/index.d.ts +19 -0
  27. package/dest/ecdsa/ecdsa_k/index.d.ts.map +1 -0
  28. package/dest/ecdsa/ecdsa_k/index.js +23 -0
  29. package/dest/ecdsa/ecdsa_k/lazy.d.ts +23 -0
  30. package/dest/ecdsa/ecdsa_k/lazy.d.ts.map +1 -0
  31. package/dest/ecdsa/ecdsa_k/lazy.js +31 -0
  32. package/dest/ecdsa/ecdsa_r/account_contract.d.ts +19 -0
  33. package/dest/ecdsa/ecdsa_r/account_contract.d.ts.map +1 -0
  34. package/dest/ecdsa/ecdsa_r/account_contract.js +45 -0
  35. package/dest/ecdsa/ecdsa_r/index.d.ts +19 -0
  36. package/dest/ecdsa/ecdsa_r/index.d.ts.map +1 -0
  37. package/dest/ecdsa/ecdsa_r/index.js +23 -0
  38. package/dest/ecdsa/ecdsa_r/lazy.d.ts +23 -0
  39. package/dest/ecdsa/ecdsa_r/lazy.d.ts.map +1 -0
  40. package/dest/ecdsa/ecdsa_r/lazy.js +31 -0
  41. package/dest/ecdsa/index.d.ts +4 -0
  42. package/dest/ecdsa/index.d.ts.map +1 -0
  43. package/dest/ecdsa/index.js +3 -0
  44. package/dest/ecdsa/lazy.d.ts +4 -0
  45. package/dest/ecdsa/lazy.d.ts.map +1 -0
  46. package/dest/ecdsa/lazy.js +3 -0
  47. package/dest/ecdsa/ssh_ecdsa_r/account_contract.d.ts +22 -0
  48. package/dest/ecdsa/ssh_ecdsa_r/account_contract.d.ts.map +1 -0
  49. package/dest/ecdsa/ssh_ecdsa_r/account_contract.js +87 -0
  50. package/dest/ecdsa/ssh_ecdsa_r/index.d.ts +21 -0
  51. package/dest/ecdsa/ssh_ecdsa_r/index.d.ts.map +1 -0
  52. package/dest/ecdsa/ssh_ecdsa_r/index.js +22 -0
  53. package/dest/ecdsa/ssh_ecdsa_r/lazy.d.ts +21 -0
  54. package/dest/ecdsa/ssh_ecdsa_r/lazy.d.ts.map +1 -0
  55. package/dest/ecdsa/ssh_ecdsa_r/lazy.js +22 -0
  56. package/dest/ecdsa/stub/index.d.ts +11 -0
  57. package/dest/ecdsa/stub/index.d.ts.map +1 -0
  58. package/dest/ecdsa/stub/index.js +18 -0
  59. package/dest/ecdsa/stub/lazy.d.ts +14 -0
  60. package/dest/ecdsa/stub/lazy.d.ts.map +1 -0
  61. package/dest/ecdsa/stub/lazy.js +22 -0
  62. package/dest/schnorr/account_contract.d.ts +32 -0
  63. package/dest/schnorr/account_contract.d.ts.map +1 -0
  64. package/dest/schnorr/account_contract.js +41 -0
  65. package/dest/schnorr/index.d.ts +3 -0
  66. package/dest/schnorr/index.d.ts.map +1 -0
  67. package/dest/schnorr/index.js +2 -0
  68. package/dest/schnorr/initializerless/index.d.ts +25 -0
  69. package/dest/schnorr/initializerless/index.d.ts.map +1 -0
  70. package/dest/schnorr/initializerless/index.js +46 -0
  71. package/dest/schnorr/initializerless/lazy.d.ts +29 -0
  72. package/dest/schnorr/initializerless/lazy.d.ts.map +1 -0
  73. package/dest/schnorr/initializerless/lazy.js +54 -0
  74. package/dest/schnorr/lazy.d.ts +3 -0
  75. package/dest/schnorr/lazy.d.ts.map +1 -0
  76. package/dest/schnorr/lazy.js +2 -0
  77. package/dest/schnorr/private_immutable/index.d.ts +23 -0
  78. package/dest/schnorr/private_immutable/index.d.ts.map +1 -0
  79. package/dest/schnorr/private_immutable/index.js +35 -0
  80. package/dest/schnorr/private_immutable/lazy.d.ts +27 -0
  81. package/dest/schnorr/private_immutable/lazy.d.ts.map +1 -0
  82. package/dest/schnorr/private_immutable/lazy.js +43 -0
  83. package/dest/schnorr/stub/index.d.ts +11 -0
  84. package/dest/schnorr/stub/index.d.ts.map +1 -0
  85. package/dest/schnorr/stub/index.js +18 -0
  86. package/dest/schnorr/stub/lazy.d.ts +14 -0
  87. package/dest/schnorr/stub/lazy.d.ts.map +1 -0
  88. package/dest/schnorr/stub/lazy.js +22 -0
  89. package/dest/testing/configuration.d.ts +37 -0
  90. package/dest/testing/configuration.d.ts.map +1 -0
  91. package/dest/testing/configuration.js +19 -0
  92. package/dest/testing/index.d.ts +11 -0
  93. package/dest/testing/index.d.ts.map +1 -0
  94. package/dest/testing/index.js +43 -0
  95. package/dest/testing/lazy.d.ts +11 -0
  96. package/dest/testing/lazy.d.ts.map +1 -0
  97. package/dest/testing/lazy.js +43 -0
  98. package/dest/utils/index.d.ts +3 -0
  99. package/dest/utils/index.d.ts.map +1 -0
  100. package/dest/utils/index.js +2 -0
  101. package/dest/utils/key_derivation.d.ts +9 -0
  102. package/dest/utils/key_derivation.d.ts.map +1 -0
  103. package/dest/utils/key_derivation.js +19 -0
  104. package/dest/utils/ssh_agent.d.ts +33 -0
  105. package/dest/utils/ssh_agent.d.ts.map +1 -0
  106. package/dest/utils/ssh_agent.js +155 -0
  107. package/package.json +108 -0
  108. package/src/defaults/account_contract.ts +47 -0
  109. package/src/defaults/index.ts +9 -0
  110. package/src/defaults/stub_account_contract.ts +39 -0
  111. package/src/ecdsa/ecdsa_k/account_contract.ts +42 -0
  112. package/src/ecdsa/ecdsa_k/index.ts +31 -0
  113. package/src/ecdsa/ecdsa_k/lazy.ts +39 -0
  114. package/src/ecdsa/ecdsa_r/account_contract.ts +42 -0
  115. package/src/ecdsa/ecdsa_r/index.ts +31 -0
  116. package/src/ecdsa/ecdsa_r/lazy.ts +39 -0
  117. package/src/ecdsa/index.ts +3 -0
  118. package/src/ecdsa/lazy.ts +3 -0
  119. package/src/ecdsa/ssh_ecdsa_r/account_contract.ts +92 -0
  120. package/src/ecdsa/ssh_ecdsa_r/index.ts +28 -0
  121. package/src/ecdsa/ssh_ecdsa_r/lazy.ts +28 -0
  122. package/src/ecdsa/stub/index.ts +28 -0
  123. package/src/ecdsa/stub/lazy.ts +34 -0
  124. package/src/schnorr/account_contract.ts +53 -0
  125. package/src/schnorr/index.ts +2 -0
  126. package/src/schnorr/initializerless/index.ts +62 -0
  127. package/src/schnorr/initializerless/lazy.ts +70 -0
  128. package/src/schnorr/lazy.ts +2 -0
  129. package/src/schnorr/private_immutable/index.ts +50 -0
  130. package/src/schnorr/private_immutable/lazy.ts +60 -0
  131. package/src/schnorr/stub/index.ts +30 -0
  132. package/src/schnorr/stub/lazy.ts +34 -0
  133. package/src/testing/configuration.ts +53 -0
  134. package/src/testing/index.ts +76 -0
  135. package/src/testing/lazy.ts +69 -0
  136. package/src/utils/index.ts +2 -0
  137. package/src/utils/key_derivation.ts +18 -0
  138. package/src/utils/ssh_agent.ts +138 -0
@@ -0,0 +1,53 @@
1
+ import type { AuthWitnessProvider } from '@aztec-labs/aztec.js/account';
2
+ import { Schnorr } from '@aztec-labs/foundation/crypto/schnorr';
3
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
4
+ import { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
5
+ import { AuthWitness } from '@aztec-labs/stdlib/auth-witness';
6
+ import { CompleteAddress } from '@aztec-labs/stdlib/contract';
7
+
8
+ import { DefaultAccountContract } from '../defaults/account_contract.js';
9
+
10
+ /**
11
+ * Account contract that authenticates transactions using Schnorr signatures
12
+ * verified against a Grumpkin public key stored in an immutable encrypted note.
13
+ * This abstract version does not provide a way to retrieve the artifact, as it
14
+ * can be implemented with or without lazy loading.
15
+ */
16
+ export abstract class SchnorrBaseAccountContract extends DefaultAccountContract {
17
+ constructor(protected signingPrivateKey: GrumpkinScalar) {
18
+ super();
19
+ }
20
+
21
+ /** The Grumpkin public key this account verifies signatures against. */
22
+ getSigningPublicKey() {
23
+ return new Schnorr().computePublicKey(this.signingPrivateKey);
24
+ }
25
+
26
+ async getInitializationFunctionAndArgs(): Promise<
27
+ | {
28
+ /** The name of the function used to initialize the contract */
29
+ constructorName: string;
30
+ /** The args to the function used to initialize the contract */
31
+ constructorArgs: any[];
32
+ }
33
+ | undefined
34
+ > {
35
+ const signingPublicKey = await this.getSigningPublicKey();
36
+ return { constructorName: 'constructor', constructorArgs: [signingPublicKey.x, signingPublicKey.y] };
37
+ }
38
+
39
+ getAuthWitnessProvider(_address: CompleteAddress): AuthWitnessProvider {
40
+ return new SchnorrAuthWitnessProvider(this.signingPrivateKey);
41
+ }
42
+ }
43
+
44
+ /** Creates auth witnesses using Schnorr signatures. */
45
+ export class SchnorrAuthWitnessProvider implements AuthWitnessProvider {
46
+ constructor(private signingPrivateKey: GrumpkinScalar) {}
47
+
48
+ async createAuthWit(messageHash: Fr): Promise<AuthWitness> {
49
+ const schnorr = new Schnorr();
50
+ const signature = await schnorr.constructSignature(messageHash, this.signingPrivateKey);
51
+ return new AuthWitness(messageHash, signature.toLimbFields());
52
+ }
53
+ }
@@ -0,0 +1,2 @@
1
+ export * from './private_immutable/index.js';
2
+ export * from './initializerless/index.js';
@@ -0,0 +1,62 @@
1
+ /**
2
+ * The `@aztec-labs/accounts/schnorr` export provides an account contract implementation that uses Schnorr signatures with a Grumpkin key for authentication, and a separate Grumpkin key for encryption.
3
+ * This is the suggested account contract type for most use cases within Aztec.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import { getAccountContractAddress } from '@aztec-labs/aztec.js/account';
8
+ import type { AztecAddress } from '@aztec-labs/aztec.js/addresses';
9
+ import { poseidon2Hash } from '@aztec-labs/foundation/crypto/poseidon';
10
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
11
+ import { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
12
+ import type { ContractArtifact } from '@aztec-labs/stdlib/abi';
13
+ import { loadContractArtifact } from '@aztec-labs/stdlib/abi';
14
+ import type { NoirCompiledContract } from '@aztec-labs/stdlib/noir';
15
+
16
+ import SchnorrInitializerlessAccountContractJson from '../../../artifacts/SchnorrInitializerlessAccount.json' with { type: 'json' };
17
+ import { deriveSecretKeyFromSigningKey } from '../../utils/key_derivation.js';
18
+ import { SchnorrBaseAccountContract } from '../account_contract.js';
19
+
20
+ export const SchnorrInitializerlessAccountContractArtifact = loadContractArtifact(
21
+ SchnorrInitializerlessAccountContractJson as NoirCompiledContract,
22
+ );
23
+
24
+ /**
25
+ * Account contract that authenticates transactions using Schnorr signatures
26
+ * verified against a Grumpkin public key stored in an immutable encrypted note.
27
+ * Eagerly loads the contract artifact
28
+ */
29
+ export class SchnorrInitializerlessAccountContract extends SchnorrBaseAccountContract {
30
+ constructor(signingPrivateKey: GrumpkinScalar) {
31
+ super(signingPrivateKey);
32
+ }
33
+
34
+ override getInitializationFunctionAndArgs() {
35
+ return Promise.resolve(undefined);
36
+ }
37
+
38
+ override async getImmutablesHash(): Promise<Fr> {
39
+ const signingPublicKey = await this.getSigningPublicKey();
40
+ return poseidon2Hash([signingPublicKey.x, signingPublicKey.y]);
41
+ }
42
+
43
+ override getContractArtifact(): Promise<ContractArtifact> {
44
+ return Promise.resolve(SchnorrInitializerlessAccountContractArtifact);
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Compute the address of a schnorr account contract.
50
+ * @param signingPrivateKey - The account's signing private key.
51
+ * @param salt - The contract address salt.
52
+ * @param secretKey - Seed for the account's privacy keys. Derived from the signing key when omitted.
53
+ */
54
+ export async function getSchnorrInitializerlessAccountContractAddress(
55
+ signingPrivateKey: GrumpkinScalar,
56
+ salt: Fr,
57
+ secretKey?: Fr,
58
+ ): Promise<AztecAddress> {
59
+ const resolvedSecretKey = secretKey ?? (await deriveSecretKeyFromSigningKey(signingPrivateKey));
60
+ const accountContract = new SchnorrInitializerlessAccountContract(signingPrivateKey);
61
+ return await getAccountContractAddress(accountContract, resolvedSecretKey, salt);
62
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * The `@aztec-labs/accounts/schnorr` export provides an account contract implementation that uses Schnorr signatures with a Grumpkin key for authentication, and a separate Grumpkin key for encryption.
3
+ * This is the suggested account contract type for most use cases within Aztec.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import { getAccountContractAddress } from '@aztec-labs/aztec.js/account';
8
+ import { poseidon2Hash } from '@aztec-labs/foundation/crypto/poseidon';
9
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
10
+ import { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
11
+ import type { ContractArtifact } from '@aztec-labs/stdlib/abi';
12
+ import { loadContractArtifact } from '@aztec-labs/stdlib/abi';
13
+ import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
14
+
15
+ import { deriveSecretKeyFromSigningKey } from '../../utils/key_derivation.js';
16
+ import { SchnorrBaseAccountContract } from '../account_contract.js';
17
+
18
+ /**
19
+ * Lazily loads the contract artifact
20
+ * @returns The contract artifact for the schnorr account contract
21
+ */
22
+ export async function getSchnorrInitializerlessAccountContractArtifact() {
23
+ // Cannot assert this import as it's incompatible with bundlers like vite
24
+ // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352
25
+ // Even if now supported by all major browsers, the MIME type is replaced with
26
+ // "text/javascript"
27
+ // In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
28
+ const { default: schnorrAccountContractJson } = await import('../../../artifacts/SchnorrInitializerlessAccount.json');
29
+ return loadContractArtifact(schnorrAccountContractJson);
30
+ }
31
+
32
+ /**
33
+ * Account contract that authenticates transactions using Schnorr signatures
34
+ * verified against a Grumpkin public key stored in an immutable encrypted note.
35
+ * Lazily loads the contract artifact
36
+ */
37
+ export class SchnorrInitializerlessAccountContract extends SchnorrBaseAccountContract {
38
+ constructor(signingPrivateKey: GrumpkinScalar) {
39
+ super(signingPrivateKey);
40
+ }
41
+
42
+ override getInitializationFunctionAndArgs() {
43
+ return Promise.resolve(undefined);
44
+ }
45
+
46
+ override async getImmutablesHash(): Promise<Fr> {
47
+ const signingPublicKey = await this.getSigningPublicKey();
48
+ return poseidon2Hash([signingPublicKey.x, signingPublicKey.y]);
49
+ }
50
+
51
+ override getContractArtifact(): Promise<ContractArtifact> {
52
+ return getSchnorrInitializerlessAccountContractArtifact();
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Compute the address of a schnorr account contract.
58
+ * @param signingPrivateKey - The account's signing private key.
59
+ * @param salt - The contract address salt.
60
+ * @param secretKey - Seed for the account's privacy keys. Derived from the signing key when omitted.
61
+ */
62
+ export async function getSchnorrInitializerlessAccountContractAddress(
63
+ signingPrivateKey: GrumpkinScalar,
64
+ salt: Fr,
65
+ secretKey?: Fr,
66
+ ): Promise<AztecAddress> {
67
+ const resolvedSecretKey = secretKey ?? (await deriveSecretKeyFromSigningKey(signingPrivateKey));
68
+ const accountContract = new SchnorrInitializerlessAccountContract(signingPrivateKey);
69
+ return await getAccountContractAddress(accountContract, resolvedSecretKey, salt);
70
+ }
@@ -0,0 +1,2 @@
1
+ export * from './private_immutable/lazy.js';
2
+ export * from './initializerless/lazy.js';
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The `@aztec-labs/accounts/schnorr` export provides an account contract implementation that uses Schnorr signatures with a Grumpkin key for authentication, and a separate Grumpkin key for encryption.
3
+ * This is the suggested account contract type for most use cases within Aztec.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import { getAccountContractAddress } from '@aztec-labs/aztec.js/account';
8
+ import type { AztecAddress } from '@aztec-labs/aztec.js/addresses';
9
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
10
+ import { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
11
+ import type { ContractArtifact } from '@aztec-labs/stdlib/abi';
12
+ import { loadContractArtifact } from '@aztec-labs/stdlib/abi';
13
+ import type { NoirCompiledContract } from '@aztec-labs/stdlib/noir';
14
+
15
+ import SchnorrAccountContractJson from '../../../artifacts/SchnorrAccount.json' with { type: 'json' };
16
+ import { deriveSecretKeyFromSigningKey } from '../../utils/key_derivation.js';
17
+ import { SchnorrBaseAccountContract } from '../account_contract.js';
18
+
19
+ export const SchnorrAccountContractArtifact = loadContractArtifact(SchnorrAccountContractJson as NoirCompiledContract);
20
+
21
+ /**
22
+ * Account contract that authenticates transactions using Schnorr signatures
23
+ * verified against a Grumpkin public key stored in an immutable encrypted note.
24
+ * Eagerly loads the contract artifact
25
+ */
26
+ export class SchnorrAccountContract extends SchnorrBaseAccountContract {
27
+ constructor(signingPrivateKey: GrumpkinScalar) {
28
+ super(signingPrivateKey);
29
+ }
30
+
31
+ override getContractArtifact(): Promise<ContractArtifact> {
32
+ return Promise.resolve(SchnorrAccountContractArtifact);
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Compute the address of a schnorr account contract.
38
+ * @param signingPrivateKey - The account's signing private key.
39
+ * @param salt - The contract address salt.
40
+ * @param secretKey - Seed for the account's privacy keys. Derived from the signing key when omitted.
41
+ */
42
+ export async function getSchnorrAccountContractAddress(
43
+ signingPrivateKey: GrumpkinScalar,
44
+ salt: Fr,
45
+ secretKey?: Fr,
46
+ ): Promise<AztecAddress> {
47
+ const resolvedSecretKey = secretKey ?? (await deriveSecretKeyFromSigningKey(signingPrivateKey));
48
+ const accountContract = new SchnorrAccountContract(signingPrivateKey);
49
+ return await getAccountContractAddress(accountContract, resolvedSecretKey, salt);
50
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * The `@aztec-labs/accounts/schnorr` export provides an account contract implementation that uses Schnorr signatures with a Grumpkin key for authentication, and a separate Grumpkin key for encryption.
3
+ * This is the suggested account contract type for most use cases within Aztec.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import { getAccountContractAddress } from '@aztec-labs/aztec.js/account';
8
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
9
+ import { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
10
+ import type { ContractArtifact } from '@aztec-labs/stdlib/abi';
11
+ import { loadContractArtifact } from '@aztec-labs/stdlib/abi';
12
+ import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
13
+
14
+ import { deriveSecretKeyFromSigningKey } from '../../utils/key_derivation.js';
15
+ import { SchnorrBaseAccountContract } from '../account_contract.js';
16
+
17
+ /**
18
+ * Lazily loads the contract artifact
19
+ * @returns The contract artifact for the schnorr account contract
20
+ */
21
+ export async function getSchnorrAccountContractArtifact() {
22
+ // Cannot assert this import as it's incompatible with bundlers like vite
23
+ // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352
24
+ // Even if now supported by all major browsers, the MIME type is replaced with
25
+ // "text/javascript"
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
33
+ * verified against a Grumpkin public key stored in an immutable encrypted note.
34
+ * Lazily loads the contract artifact
35
+ */
36
+ export class SchnorrAccountContract extends SchnorrBaseAccountContract {
37
+ constructor(signingPrivateKey: GrumpkinScalar) {
38
+ super(signingPrivateKey);
39
+ }
40
+
41
+ override getContractArtifact(): Promise<ContractArtifact> {
42
+ return getSchnorrAccountContractArtifact();
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Compute the address of a schnorr account contract.
48
+ * @param signingPrivateKey - The account's signing private key.
49
+ * @param salt - The contract address salt.
50
+ * @param secretKey - Seed for the account's privacy keys. Derived from the signing key when omitted.
51
+ */
52
+ export async function getSchnorrAccountContractAddress(
53
+ signingPrivateKey: GrumpkinScalar,
54
+ salt: Fr,
55
+ secretKey?: Fr,
56
+ ): Promise<AztecAddress> {
57
+ const resolvedSecretKey = secretKey ?? (await deriveSecretKeyFromSigningKey(signingPrivateKey));
58
+ const accountContract = new SchnorrAccountContract(signingPrivateKey);
59
+ return await getAccountContractAddress(accountContract, resolvedSecretKey, salt);
60
+ }
@@ -0,0 +1,30 @@
1
+ import { BaseAccount } from '@aztec-labs/aztec.js/account';
2
+ import type { CompleteAddress } from '@aztec-labs/aztec.js/addresses';
3
+ import { DefaultAccountEntrypoint } from '@aztec-labs/entrypoints/account';
4
+ import { loadContractArtifact } from '@aztec-labs/stdlib/abi';
5
+ import type { NoirCompiledContract } from '@aztec-labs/stdlib/noir';
6
+
7
+ import SimulatedSchnorrAccountJson from '../../../artifacts/SimulatedSchnorrAccount.json' with { type: 'json' };
8
+ import { StubBaseAccountContract } from '../../defaults/stub_account_contract.js';
9
+
10
+ export const StubSchnorrAccountContractArtifact = loadContractArtifact(
11
+ SimulatedSchnorrAccountJson as NoirCompiledContract,
12
+ );
13
+
14
+ /** Stub account contract for Schnorr accounts. Eagerly loads the contract artifact. */
15
+ export class StubSchnorrAccountContract extends StubBaseAccountContract {
16
+ override getContractArtifact() {
17
+ return Promise.resolve(StubSchnorrAccountContractArtifact);
18
+ }
19
+ }
20
+
21
+ /** Creates a Schnorr stub account that impersonates the one with the provided address. */
22
+ export function createStubSchnorrAccount(originalAddress: CompleteAddress) {
23
+ const accountContract = new StubSchnorrAccountContract();
24
+ const authWitnessProvider = accountContract.getAuthWitnessProvider(originalAddress);
25
+ return new BaseAccount(
26
+ new DefaultAccountEntrypoint(originalAddress.address, authWitnessProvider),
27
+ authWitnessProvider,
28
+ originalAddress,
29
+ );
30
+ }
@@ -0,0 +1,34 @@
1
+ import { BaseAccount } from '@aztec-labs/aztec.js/account';
2
+ import type { CompleteAddress } from '@aztec-labs/aztec.js/addresses';
3
+ import { DefaultAccountEntrypoint } from '@aztec-labs/entrypoints/account';
4
+ import { loadContractArtifact } from '@aztec-labs/stdlib/abi';
5
+
6
+ import { StubBaseAccountContract } from '../../defaults/stub_account_contract.js';
7
+
8
+ /**
9
+ * Lazily loads the Schnorr stub contract artifact (browser-compatible).
10
+ */
11
+ export async function getStubSchnorrAccountContractArtifact() {
12
+ // Cannot assert this import as it's incompatible with bundlers like vite
13
+ // https://github.com/vitejs/vite/issues/19095#issuecomment-2566074352
14
+ const { default: json } = await import('../../../artifacts/SimulatedSchnorrAccount.json');
15
+ return loadContractArtifact(json);
16
+ }
17
+
18
+ /** Stub account contract for Schnorr accounts. Lazily loads the contract artifact. */
19
+ export class StubSchnorrAccountContract extends StubBaseAccountContract {
20
+ override getContractArtifact() {
21
+ return getStubSchnorrAccountContractArtifact();
22
+ }
23
+ }
24
+
25
+ /** Creates a Schnorr stub account that impersonates the one with the provided address. */
26
+ export function createStubSchnorrAccount(originalAddress: CompleteAddress) {
27
+ const accountContract = new StubSchnorrAccountContract();
28
+ const authWitnessProvider = accountContract.getAuthWitnessProvider(originalAddress);
29
+ return new BaseAccount(
30
+ new DefaultAccountEntrypoint(originalAddress.address, authWitnessProvider),
31
+ authWitnessProvider,
32
+ originalAddress,
33
+ );
34
+ }
@@ -0,0 +1,53 @@
1
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
2
+ import { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
3
+ import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
4
+ import { deriveMasterIncomingViewingSecretKey } from '@aztec-labs/stdlib/keys';
5
+
6
+ export const INITIAL_TEST_SECRET_KEYS = [
7
+ Fr.fromHexString('2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281'),
8
+ Fr.fromHexString('aebd1b4be76efa44f5ee655c20bf9ea60f7ae44b9a7fd1fd9f189c7a0b0cdae'),
9
+ Fr.fromHexString('0f6addf0da06c33293df974a565b03d1ab096090d907d98055a8b7f4954e120c'),
10
+ ];
11
+
12
+ export const INITIAL_TEST_ENCRYPTION_KEYS = INITIAL_TEST_SECRET_KEYS.map(secretKey =>
13
+ deriveMasterIncomingViewingSecretKey(secretKey),
14
+ );
15
+
16
+ export const INITIAL_TEST_SIGNING_KEYS = [
17
+ GrumpkinScalar.fromHexString('0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'),
18
+ GrumpkinScalar.fromHexString('202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e'),
19
+ GrumpkinScalar.fromHexString('404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e'),
20
+ ];
21
+
22
+ export const INITIAL_TEST_ACCOUNT_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO];
23
+
24
+ /**
25
+ * The schnorr account contract variant a test account uses.
26
+ */
27
+ export type InitialAccountType = 'schnorr' | 'schnorr_initializerless';
28
+
29
+ /**
30
+ * Data for generating an initial account.
31
+ */
32
+ export interface InitialAccountData {
33
+ /**
34
+ * Secret to derive the keys for the account.
35
+ */
36
+ secret: Fr;
37
+ /**
38
+ * Signing key od the account.
39
+ */
40
+ signingKey: GrumpkinScalar;
41
+ /**
42
+ * Contract address salt.
43
+ */
44
+ salt: Fr;
45
+ /**
46
+ * Address of the schnorr account contract.
47
+ */
48
+ address: AztecAddress;
49
+ /**
50
+ * Account contract variant.
51
+ */
52
+ type?: InitialAccountType;
53
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * The `@aztec-labs/accounts/testing` export provides utility methods for testing, in particular in a local network environment.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ import { Fr } from '@aztec-labs/aztec.js/fields';
7
+ import { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
8
+
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';
12
+ import {
13
+ INITIAL_TEST_ACCOUNT_SALTS,
14
+ INITIAL_TEST_SECRET_KEYS,
15
+ INITIAL_TEST_SIGNING_KEYS,
16
+ type InitialAccountData,
17
+ type InitialAccountType,
18
+ } from './configuration.js';
19
+
20
+ export {
21
+ INITIAL_TEST_ACCOUNT_SALTS,
22
+ INITIAL_TEST_ENCRYPTION_KEYS,
23
+ INITIAL_TEST_SECRET_KEYS,
24
+ INITIAL_TEST_SIGNING_KEYS,
25
+ type InitialAccountData,
26
+ type InitialAccountType,
27
+ } from './configuration.js';
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
+
36
+ /**
37
+ * Gets the basic information for initial test accounts.
38
+ */
39
+ export function getInitialTestAccountsData(): Promise<InitialAccountData[]> {
40
+ return Promise.all(
41
+ INITIAL_TEST_SECRET_KEYS.map(async (secret, i) => ({
42
+ secret,
43
+ signingKey: INITIAL_TEST_SIGNING_KEYS[i],
44
+ salt: INITIAL_TEST_ACCOUNT_SALTS[i],
45
+ type: 'schnorr_initializerless' as const,
46
+ address: await getSchnorrInitializerlessAccountContractAddress(
47
+ INITIAL_TEST_SIGNING_KEYS[i],
48
+ INITIAL_TEST_ACCOUNT_SALTS[i],
49
+ secret,
50
+ ),
51
+ })),
52
+ );
53
+ }
54
+
55
+ /**
56
+ * Generate a fixed amount of random schnorr account contract instances of the given type
57
+ */
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());
63
+ return await Promise.all(
64
+ signingKeys.map(async signingKey => {
65
+ const salt = Fr.random();
66
+ const secret = await deriveSecretKeyFromSigningKey(signingKey);
67
+ return {
68
+ secret,
69
+ signingKey,
70
+ salt,
71
+ type,
72
+ address: await getTestAccountAddress(type, signingKey, salt, secret),
73
+ };
74
+ }),
75
+ );
76
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * The `@aztec-labs/accounts/testing/lazy` export provides utility methods for testing, in particular in a local network environment.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ import { Fr } from '@aztec-labs/aztec.js/fields';
7
+ import { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
8
+
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';
12
+ import {
13
+ INITIAL_TEST_ACCOUNT_SALTS,
14
+ INITIAL_TEST_SECRET_KEYS,
15
+ INITIAL_TEST_SIGNING_KEYS,
16
+ type InitialAccountData,
17
+ type InitialAccountType,
18
+ } from './configuration.js';
19
+
20
+ export { INITIAL_TEST_ACCOUNT_SALTS, INITIAL_TEST_SECRET_KEYS } from './configuration.js';
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
+
29
+ /**
30
+ * Gets the basic information for initial test accounts.
31
+ */
32
+ export function getInitialTestAccountsData(): Promise<InitialAccountData[]> {
33
+ return Promise.all(
34
+ INITIAL_TEST_SECRET_KEYS.map(async (secret, i) => ({
35
+ secret,
36
+ signingKey: INITIAL_TEST_SIGNING_KEYS[i],
37
+ salt: INITIAL_TEST_ACCOUNT_SALTS[i],
38
+ type: 'schnorr_initializerless' as const,
39
+ address: await getSchnorrInitializerlessAccountContractAddress(
40
+ INITIAL_TEST_SIGNING_KEYS[i],
41
+ INITIAL_TEST_ACCOUNT_SALTS[i],
42
+ secret,
43
+ ),
44
+ })),
45
+ );
46
+ }
47
+
48
+ /**
49
+ * Generate a fixed amount of random schnorr account contract instances of the given type
50
+ */
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());
56
+ return await Promise.all(
57
+ signingKeys.map(async signingKey => {
58
+ const salt = Fr.random();
59
+ const secret = await deriveSecretKeyFromSigningKey(signingKey);
60
+ return {
61
+ secret,
62
+ signingKey,
63
+ salt,
64
+ type,
65
+ address: await getTestAccountAddress(type, signingKey, salt, secret),
66
+ };
67
+ }),
68
+ );
69
+ }
@@ -0,0 +1,2 @@
1
+ export * from './key_derivation.js';
2
+ export * from './ssh_agent.js';
@@ -0,0 +1,18 @@
1
+ import { poseidon2Hash } from '@aztec-labs/foundation/crypto/poseidon';
2
+ import { sha256ToField } from '@aztec-labs/foundation/crypto/sha256';
3
+ import type { Fr } from '@aztec-labs/foundation/curves/bn254';
4
+ import type { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
5
+
6
+ // Frozen string, not a package reference: it is hashed into every secret key derived below, so
7
+ // changing it changes the address of every account derived from a signing key. It keeps the old
8
+ // @aztec scope for that reason and must not be updated to track the package name.
9
+ const SIGNING_KEY_TO_SECRET_KEY_SEPARATOR = sha256ToField([Buffer.from('@aztec/accounts/signing_key_to_secret_key')]);
10
+
11
+ /**
12
+ * Derives the privacy secret key (the seed for the viewing/nullifier keyset that PXE holds) from the account's signing
13
+ * key. The signing key is the ownership root the user controls; the privacy keyset hangs off it through this one-way
14
+ * hash, so a value handled by PXE can never be used to recover the signing key.
15
+ */
16
+ export function deriveSecretKeyFromSigningKey(signingKey: GrumpkinScalar): Promise<Fr> {
17
+ return poseidon2Hash([SIGNING_KEY_TO_SECRET_KEY_SEPARATOR, signingKey.hi, signingKey.lo]);
18
+ }