@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
@@ -6,14 +6,34 @@
6
6
  */
7
7
  import { AccountManager, type Salt } from '@aztec/aztec.js/account';
8
8
  import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet';
9
- import { type PXE } from '@aztec/circuit-types';
10
- import { type AztecAddress, type Fr } from '@aztec/circuits.js';
9
+ import { Fr } from '@aztec/foundation/fields';
10
+ import type { ContractArtifact } from '@aztec/stdlib/abi';
11
+ import { loadContractArtifact } from '@aztec/stdlib/abi';
12
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
13
+ import type { PXE } from '@aztec/stdlib/interfaces/client';
14
+ import type { NoirCompiledContract } from '@aztec/stdlib/noir';
11
15
 
12
- import { EcdsaKAccountContract } from './account_contract.js';
16
+ import EcdsaKAccountContractJson from '../../../artifacts/EcdsaKAccount.json' assert { type: 'json' };
17
+ import { EcdsaKBaseAccountContract } from './account_contract.js';
13
18
 
14
- export { EcdsaKAccountContractArtifact } from './artifact.js';
15
- export { EcdsaKAccountContract };
19
+ export const EcdsaKAccountContractArtifact: ContractArtifact = loadContractArtifact(
20
+ EcdsaKAccountContractJson as NoirCompiledContract,
21
+ );
16
22
 
23
+ /**
24
+ * Account contract that authenticates transactions using ECDSA signatures
25
+ * verified against a secp256k1 public key stored in an immutable encrypted note.
26
+ * Eagerly loads the contract artifact
27
+ */
28
+ export class EcdsaKAccountContract extends EcdsaKBaseAccountContract {
29
+ constructor(signingPrivateKey: Buffer) {
30
+ super(signingPrivateKey);
31
+ }
32
+
33
+ override getContractArtifact(): Promise<ContractArtifact> {
34
+ return Promise.resolve(EcdsaKAccountContractArtifact);
35
+ }
36
+ }
17
37
  /**
18
38
  * Creates an Account that relies on an ECDSA signing key for authentication.
19
39
  * @param pxe - An PXE server instance.
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The `@aztec/accounts/ecdsa` export provides an ECDSA account contract implementation, that uses an ECDSA private key for authentication, and a Grumpkin key for encryption.
3
+ * Consider using this account type when working with integrations with Ethereum wallets.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import { AccountManager, type Salt } from '@aztec/aztec.js/account';
8
+ import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet';
9
+ import { Fr } from '@aztec/foundation/fields';
10
+ import type { ContractArtifact } from '@aztec/stdlib/abi';
11
+ import { loadContractArtifact } from '@aztec/stdlib/abi';
12
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
13
+ import type { PXE } from '@aztec/stdlib/interfaces/client';
14
+
15
+ import { EcdsaKBaseAccountContract } from './account_contract.js';
16
+
17
+ /**
18
+ * Lazily loads the contract artifact
19
+ * @returns The contract artifact for the ecdsa K account contract
20
+ */
21
+ export async function getEcdsaKAccountContractArtifact() {
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: ecdsaKAccountContractJson } = await import('../../../artifacts/EcdsaKAccount.json');
28
+ return loadContractArtifact(ecdsaKAccountContractJson);
29
+ }
30
+
31
+ /**
32
+ * Account contract that authenticates transactions using ECDSA signatures
33
+ * verified against a secp256k1 public key stored in an immutable encrypted note.
34
+ * Lazily loads the contract artifact
35
+ */
36
+ export class EcdsaKAccountContract extends EcdsaKBaseAccountContract {
37
+ constructor(signingPrivateKey: Buffer) {
38
+ super(signingPrivateKey);
39
+ }
40
+
41
+ override getContractArtifact(): Promise<ContractArtifact> {
42
+ return getEcdsaKAccountContractArtifact();
43
+ }
44
+ }
45
+ /**
46
+ * Creates an Account that relies on an ECDSA signing key for authentication.
47
+ * @param pxe - An PXE server instance.
48
+ * @param secretKey - Secret key used to derive all the keystore keys.
49
+ * @param signingPrivateKey - Secp256k1 key used for signing transactions.
50
+ * @param salt - Deployment salt.
51
+ * @returns An account manager initialized with the account contract and its deployment params
52
+ */
53
+ export function getEcdsaKAccount(
54
+ pxe: PXE,
55
+ secretKey: Fr,
56
+ signingPrivateKey: Buffer,
57
+ salt?: Salt,
58
+ ): Promise<AccountManager> {
59
+ return AccountManager.create(pxe, secretKey, new EcdsaKAccountContract(signingPrivateKey), salt);
60
+ }
61
+
62
+ /**
63
+ * Gets a wallet for an already registered account using ECDSA signatures.
64
+ * @param pxe - An PXE server instance.
65
+ * @param address - Address for the account.
66
+ * @param signingPrivateKey - ECDSA key used for signing transactions.
67
+ * @returns A wallet for this account that can be used to interact with a contract instance.
68
+ */
69
+ export function getEcdsaKWallet(pxe: PXE, address: AztecAddress, signingPrivateKey: Buffer): Promise<AccountWallet> {
70
+ return getWallet(pxe, address, new EcdsaKAccountContract(signingPrivateKey));
71
+ }
@@ -0,0 +1,2 @@
1
+ export * from './ecdsa_k/lazy.js';
2
+ export * from './ssh_ecdsa_r/lazy.js';
@@ -1,12 +1,11 @@
1
- import { type AuthWitnessProvider } from '@aztec/aztec.js/account';
2
- import { AuthWitness, type CompleteAddress } from '@aztec/circuit-types';
3
- import { EcdsaSignature } from '@aztec/circuits.js/barretenberg';
4
- import { type ContractArtifact } from '@aztec/foundation/abi';
5
- import { type Fr } from '@aztec/foundation/fields';
1
+ import type { AuthWitnessProvider } from '@aztec/aztec.js/account';
2
+ import { EcdsaSignature } from '@aztec/foundation/crypto';
3
+ import type { Fr } from '@aztec/foundation/fields';
4
+ import { AuthWitness } from '@aztec/stdlib/auth-witness';
5
+ import { CompleteAddress } from '@aztec/stdlib/contract';
6
6
 
7
7
  import { DefaultAccountContract } from '../../defaults/account_contract.js';
8
8
  import { signWithAgent } from '../../utils/ssh_agent.js';
9
- import { EcdsaRAccountContractArtifact } from './artifact.js';
10
9
 
11
10
  const secp256r1N = 115792089210356248762697446949407573529996955224135760342422259061068512044369n;
12
11
  /**
@@ -15,10 +14,12 @@ const secp256r1N = 1157920892103562487626974469494075735299969552241357603424222
15
14
  * Since this implementation relays signatures to an SSH agent, we provide the
16
15
  * public key here not for signature verification, but to identify actual identity
17
16
  * that will be used to sign authwitnesses.
17
+ * This abstract version does not provide a way to retrieve the artifact, as it
18
+ * can be implemented with or without lazy loading.
18
19
  */
19
- export class EcdsaRSSHAccountContract extends DefaultAccountContract {
20
+ export abstract class EcdsaRSSHBaseAccountContract extends DefaultAccountContract {
20
21
  constructor(private signingPublicKey: Buffer) {
21
- super(EcdsaRAccountContractArtifact as ContractArtifact);
22
+ super();
22
23
  }
23
24
 
24
25
  getDeploymentArgs() {
@@ -6,13 +6,37 @@
6
6
  */
7
7
  import { AccountManager, type Salt } from '@aztec/aztec.js/account';
8
8
  import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet';
9
- import { type PXE } from '@aztec/circuit-types';
10
- import { type AztecAddress, type Fr } from '@aztec/circuits.js';
9
+ import { Fr } from '@aztec/foundation/fields';
10
+ import type { ContractArtifact } from '@aztec/stdlib/abi';
11
+ import { loadContractArtifact } from '@aztec/stdlib/abi';
12
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
13
+ import type { PXE } from '@aztec/stdlib/interfaces/client';
14
+ import type { NoirCompiledContract } from '@aztec/stdlib/noir';
11
15
 
12
- import { EcdsaRSSHAccountContract } from './account_contract.js';
16
+ import EcdsaRAccountContractJson from '../../../artifacts/EcdsaKAccount.json' assert { type: 'json' };
17
+ import { EcdsaRSSHBaseAccountContract } from './account_contract.js';
13
18
 
14
- export { EcdsaRAccountContractArtifact } from './artifact.js';
15
- export { EcdsaRSSHAccountContract };
19
+ export const EcdsaRAccountContractArtifact: ContractArtifact = loadContractArtifact(
20
+ EcdsaRAccountContractJson as NoirCompiledContract,
21
+ );
22
+
23
+ /**
24
+ * Account contract that authenticates transactions using ECDSA signatures
25
+ * verified against a secp256r1 public key stored in an immutable encrypted note.
26
+ * Since this implementation relays signatures to an SSH agent, we provide the
27
+ * public key here not for signature verification, but to identify actual identity
28
+ * that will be used to sign authwitnesses.
29
+ * Eagerly loads the contract artifact
30
+ */
31
+ export class EcdsaRSSHAccountContract extends EcdsaRSSHBaseAccountContract {
32
+ constructor(signingPrivateKey: Buffer) {
33
+ super(signingPrivateKey);
34
+ }
35
+
36
+ override getContractArtifact(): Promise<ContractArtifact> {
37
+ return Promise.resolve(EcdsaRAccountContractArtifact);
38
+ }
39
+ }
16
40
 
17
41
  /**
18
42
  * Creates an Account that relies on an ECDSA signing key for authentication.
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The `@aztec/accounts/ecdsa` export provides an ECDSA account contract implementation, that uses an ECDSA private key for authentication, and a Grumpkin key for encryption.
3
+ * Consider using this account type when working with integrations with Ethereum wallets.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import { AccountManager, type Salt } from '@aztec/aztec.js/account';
8
+ import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet';
9
+ import { Fr } from '@aztec/foundation/fields';
10
+ import type { ContractArtifact } from '@aztec/stdlib/abi';
11
+ import { loadContractArtifact } from '@aztec/stdlib/abi';
12
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
13
+ import type { PXE } from '@aztec/stdlib/interfaces/client';
14
+
15
+ import { EcdsaRSSHBaseAccountContract } from './account_contract.js';
16
+
17
+ /*
18
+ * Lazily loads the contract artifact
19
+ * @returns The contract artifact for the ecdsa R account contract
20
+ */
21
+ /**
22
+ *
23
+ */
24
+ export async function getEcdsaRAccountContractArtifact() {
25
+ // Cannot assert this import as it's incompatible with browsers
26
+ // https://caniuse.com/mdn-javascript_statements_import_import_assertions_type_json
27
+ // Use the new "with" syntax once supported by firefox
28
+ // https://caniuse.com/mdn-javascript_statements_import_import_attributes_type_json
29
+ // In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
30
+ const { default: ecdsaKAccountContractJson } = await import('../../../artifacts/EcdsaRAccount.json');
31
+ return loadContractArtifact(ecdsaKAccountContractJson);
32
+ }
33
+
34
+ /**
35
+ * Account contract that authenticates transactions using ECDSA signatures
36
+ * verified against a secp256r1 public key stored in an immutable encrypted note.
37
+ * Since this implementation relays signatures to an SSH agent, we provide the
38
+ * public key here not for signature verification, but to identify actual identity
39
+ * that will be used to sign authwitnesses.
40
+ * Lazily loads the contract artifact
41
+ */
42
+ export class EcdsaRSSHAccountContract extends EcdsaRSSHBaseAccountContract {
43
+ constructor(signingPrivateKey: Buffer) {
44
+ super(signingPrivateKey);
45
+ }
46
+
47
+ override getContractArtifact(): Promise<ContractArtifact> {
48
+ return getEcdsaRAccountContractArtifact();
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Creates an Account that relies on an ECDSA signing key for authentication.
54
+ * @param pxe - An PXE server instance.
55
+ * @param secretKey - Secret key used to derive all the keystore keys.
56
+ * @param signingPublicKey - Secp2561 key used to identify its corresponding private key in the SSH Agent.
57
+ * @param salt - Deployment salt.
58
+ * @returns An account manager initialized with the account contract and its deployment params
59
+ */
60
+ export function getEcdsaRSSHAccount(
61
+ pxe: PXE,
62
+ secretKey: Fr,
63
+ signingPublicKey: Buffer,
64
+ salt?: Salt,
65
+ ): Promise<AccountManager> {
66
+ return AccountManager.create(pxe, secretKey, new EcdsaRSSHAccountContract(signingPublicKey), salt);
67
+ }
68
+
69
+ /**
70
+ * Gets a wallet for an already registered account using ECDSA signatures.
71
+ * @param pxe - An PXE server instance.
72
+ * @param address - Address for the account.
73
+ * @param signingPrivateKey - ECDSA key used for signing transactions.
74
+ * @returns A wallet for this account that can be used to interact with a contract instance.
75
+ */
76
+ export function getEcdsaRSSHWallet(pxe: PXE, address: AztecAddress, signingPublicKey: Buffer): Promise<AccountWallet> {
77
+ return getWallet(pxe, address, new EcdsaRSSHAccountContract(signingPublicKey));
78
+ }
@@ -1,19 +1,20 @@
1
- import { type AuthWitnessProvider } from '@aztec/aztec.js/account';
2
- import { AuthWitness, type CompleteAddress, type GrumpkinScalar } from '@aztec/circuit-types';
3
- import { Schnorr } from '@aztec/circuits.js/barretenberg';
4
- import { type ContractArtifact } from '@aztec/foundation/abi';
5
- import { type Fr } from '@aztec/foundation/fields';
1
+ import type { AuthWitnessProvider } from '@aztec/aztec.js/account';
2
+ import { Schnorr } from '@aztec/foundation/crypto';
3
+ import { Fr, GrumpkinScalar } from '@aztec/foundation/fields';
4
+ import { AuthWitness } from '@aztec/stdlib/auth-witness';
5
+ import { CompleteAddress } from '@aztec/stdlib/contract';
6
6
 
7
7
  import { DefaultAccountContract } from '../defaults/account_contract.js';
8
- import { SchnorrAccountContractArtifact } from './artifact.js';
9
8
 
10
9
  /**
11
10
  * Account contract that authenticates transactions using Schnorr signatures
12
11
  * verified against a Grumpkin public key stored in an immutable encrypted note.
12
+ * This abstract version does not provide a way to retrieve the artifact, as it
13
+ * can be implemented with or without lazy loading.
13
14
  */
14
- export class SchnorrAccountContract extends DefaultAccountContract {
15
+ export abstract class SchnorrBaseAccountContract extends DefaultAccountContract {
15
16
  constructor(private signingPrivateKey: GrumpkinScalar) {
16
- super(SchnorrAccountContractArtifact as ContractArtifact);
17
+ super();
17
18
  }
18
19
 
19
20
  async getDeploymentArgs() {
@@ -27,7 +28,7 @@ export class SchnorrAccountContract extends DefaultAccountContract {
27
28
  }
28
29
 
29
30
  /** Creates auth witnesses using Schnorr signatures. */
30
- class SchnorrAuthWitnessProvider implements AuthWitnessProvider {
31
+ export class SchnorrAuthWitnessProvider implements AuthWitnessProvider {
31
32
  constructor(private signingPrivateKey: GrumpkinScalar) {}
32
33
 
33
34
  async createAuthWit(messageHash: Fr): Promise<AuthWitness> {
@@ -4,16 +4,35 @@
4
4
  *
5
5
  * @packageDocumentation
6
6
  */
7
- import { AccountManager, type Salt } from '@aztec/aztec.js/account';
8
- import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet';
9
- import { type GrumpkinScalar, type PXE } from '@aztec/circuit-types';
10
- import { type AztecAddress, type Fr } from '@aztec/circuits.js';
7
+ import { AccountManager, type Salt, getAccountContractAddress } from '@aztec/aztec.js/account';
8
+ import { type AccountWallet, type AccountWalletWithSecretKey, getWallet } from '@aztec/aztec.js/wallet';
9
+ import { Fr, GrumpkinScalar } from '@aztec/foundation/fields';
10
+ import type { ContractArtifact } from '@aztec/stdlib/abi';
11
+ import { loadContractArtifact } from '@aztec/stdlib/abi';
12
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
13
+ import type { PXE } from '@aztec/stdlib/interfaces/client';
14
+ import { deriveSigningKey } from '@aztec/stdlib/keys';
15
+ import type { NoirCompiledContract } from '@aztec/stdlib/noir';
11
16
 
12
- import { SchnorrAccountContract } from './account_contract.js';
17
+ import SchnorrAccountContractJson from '../../artifacts/SchnorrAccount.json' assert { type: 'json' };
18
+ import { SchnorrBaseAccountContract } from './account_contract.js';
13
19
 
14
- export { SchnorrAccountContract };
20
+ export const SchnorrAccountContractArtifact = loadContractArtifact(SchnorrAccountContractJson as NoirCompiledContract);
15
21
 
16
- export { SchnorrAccountContractArtifact } from './artifact.js';
22
+ /**
23
+ * Account contract that authenticates transactions using Schnorr signatures
24
+ * verified against a Grumpkin public key stored in an immutable encrypted note.
25
+ * Eagerly loads the contract artifact
26
+ */
27
+ export class SchnorrAccountContract extends SchnorrBaseAccountContract {
28
+ constructor(signingPrivateKey: GrumpkinScalar) {
29
+ super(signingPrivateKey);
30
+ }
31
+
32
+ override getContractArtifact(): Promise<ContractArtifact> {
33
+ return Promise.resolve(SchnorrAccountContractArtifact);
34
+ }
35
+ }
17
36
 
18
37
  /**
19
38
  * Creates an Account Manager that relies on a Grumpkin signing key for authentication.
@@ -46,3 +65,33 @@ export function getSchnorrWallet(
46
65
  ): Promise<AccountWallet> {
47
66
  return getWallet(pxe, address, new SchnorrAccountContract(signingPrivateKey));
48
67
  }
68
+
69
+ /**
70
+ * Gets a wallet for an already registered account using Schnorr signatures.
71
+ * @param pxe - An PXE server instance.
72
+ * @param secretKey - Secret key used to derive all the keystore keys.
73
+ * @param signingPrivateKey - Grumpkin key used for signing transactions.
74
+ * @param salt - Deployment salt.
75
+ * @returns A wallet for this account that can be used to interact with a contract instance.
76
+ */
77
+ export async function getSchnorrWalletWithSecretKey(
78
+ pxe: PXE,
79
+ secretKey: Fr,
80
+ signingPrivateKey: GrumpkinScalar,
81
+ salt: Salt,
82
+ ): Promise<AccountWalletWithSecretKey> {
83
+ const account = await getSchnorrAccount(pxe, secretKey, signingPrivateKey, salt);
84
+ return account.getWallet();
85
+ }
86
+
87
+ /**
88
+ * Compute the address of a schnorr account contract.
89
+ * @param secret - A seed for deriving the signing key and public keys.
90
+ * @param salt - The contract address salt.
91
+ * @param signingPrivateKey - A specific signing private key that's not derived from the secret.
92
+ */
93
+ export async function getSchnorrAccountContractAddress(secret: Fr, salt: Fr, signingPrivateKey?: GrumpkinScalar) {
94
+ const signingKey = signingPrivateKey ?? deriveSigningKey(secret);
95
+ const accountContract = new SchnorrAccountContract(signingKey);
96
+ return await getAccountContractAddress(accountContract, secret, salt);
97
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * The `@aztec/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 { AccountManager, type Salt, getAccountContractAddress } from '@aztec/aztec.js/account';
8
+ import { type AccountWallet, type AccountWalletWithSecretKey, getWallet } from '@aztec/aztec.js/wallet';
9
+ import { Fr, GrumpkinScalar } from '@aztec/foundation/fields';
10
+ import type { ContractArtifact } from '@aztec/stdlib/abi';
11
+ import { loadContractArtifact } from '@aztec/stdlib/abi';
12
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
13
+ import type { PXE } from '@aztec/stdlib/interfaces/client';
14
+ import { deriveSigningKey } from '@aztec/stdlib/keys';
15
+
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 getSchnorrAccountContractArtifact() {
23
+ // Cannot assert this import as it's incompatible with browsers
24
+ // https://caniuse.com/mdn-javascript_statements_import_import_assertions_type_json
25
+ // Use the new "with" syntax once supported by firefox
26
+ // https://caniuse.com/mdn-javascript_statements_import_import_attributes_type_json
27
+ // In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
28
+ const { default: schnorrAccountContractJson } = await import('../../artifacts/SchnorrAccount.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 SchnorrAccountContract extends SchnorrBaseAccountContract {
38
+ constructor(signingPrivateKey: GrumpkinScalar) {
39
+ super(signingPrivateKey);
40
+ }
41
+
42
+ override getContractArtifact(): Promise<ContractArtifact> {
43
+ return getSchnorrAccountContractArtifact();
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Creates an Account Manager that relies on a Grumpkin signing key for authentication.
49
+ * @param pxe - An PXE server instance.
50
+ * @param secretKey - Secret key used to derive all the keystore keys.
51
+ * @param signingPrivateKey - Grumpkin key used for signing transactions.
52
+ * @param salt - Deployment salt.
53
+ * @returns An account manager initialized with the account contract and its deployment params
54
+ */
55
+ export function getSchnorrAccount(
56
+ pxe: PXE,
57
+ secretKey: Fr,
58
+ signingPrivateKey: GrumpkinScalar,
59
+ salt?: Salt,
60
+ ): Promise<AccountManager> {
61
+ return AccountManager.create(pxe, secretKey, new SchnorrAccountContract(signingPrivateKey), salt);
62
+ }
63
+
64
+ /**
65
+ * Gets a wallet for an already registered account using Schnorr signatures.
66
+ * @param pxe - An PXE server instance.
67
+ * @param address - Address for the account.
68
+ * @param signingPrivateKey - Grumpkin key used for signing transactions.
69
+ * @returns A wallet for this account that can be used to interact with a contract instance.
70
+ */
71
+ export function getSchnorrWallet(
72
+ pxe: PXE,
73
+ address: AztecAddress,
74
+ signingPrivateKey: GrumpkinScalar,
75
+ ): Promise<AccountWallet> {
76
+ return getWallet(pxe, address, new SchnorrAccountContract(signingPrivateKey));
77
+ }
78
+
79
+ /**
80
+ * Gets a wallet for an already registered account using Schnorr signatures.
81
+ * @param pxe - An PXE server instance.
82
+ * @param secretKey - Secret key used to derive all the keystore keys.
83
+ * @param signingPrivateKey - Grumpkin key used for signing transactions.
84
+ * @param salt - Deployment salt.
85
+ * @returns A wallet for this account that can be used to interact with a contract instance.
86
+ */
87
+ export async function getSchnorrWalletWithSecretKey(
88
+ pxe: PXE,
89
+ secretKey: Fr,
90
+ signingPrivateKey: GrumpkinScalar,
91
+ salt: Salt,
92
+ ): Promise<AccountWalletWithSecretKey> {
93
+ const account = await getSchnorrAccount(pxe, secretKey, signingPrivateKey, salt);
94
+ return account.getWallet();
95
+ }
96
+
97
+ /**
98
+ * Compute the address of a schnorr account contract.
99
+ * @param secret - A seed for deriving the signing key and public keys.
100
+ * @param salt - The contract address salt.
101
+ * @param signingPrivateKey - A specific signing private key that's not derived from the secret.
102
+ */
103
+ export async function getSchnorrAccountContractAddress(secret: Fr, salt: Fr, signingPrivateKey?: GrumpkinScalar) {
104
+ const signingKey = signingPrivateKey ?? deriveSigningKey(secret);
105
+ const accountContract = new SchnorrAccountContract(signingKey);
106
+ return await getAccountContractAddress(accountContract, secret, salt);
107
+ }
@@ -1,19 +1,20 @@
1
- import { type AuthWitnessProvider } from '@aztec/aztec.js/account';
2
- import { AuthWitness, type CompleteAddress, type GrumpkinScalar } from '@aztec/circuit-types';
3
- import { Schnorr } from '@aztec/circuits.js/barretenberg';
4
- import { type ContractArtifact } from '@aztec/foundation/abi';
5
- import { type Fr } from '@aztec/foundation/fields';
1
+ import type { AuthWitnessProvider } from '@aztec/aztec.js/account';
2
+ import { Schnorr } from '@aztec/foundation/crypto';
3
+ import { type Fr, GrumpkinScalar } from '@aztec/foundation/fields';
4
+ import { AuthWitness } from '@aztec/stdlib/auth-witness';
5
+ import { CompleteAddress } from '@aztec/stdlib/contract';
6
6
 
7
7
  import { DefaultAccountContract } from '../defaults/account_contract.js';
8
- import { SchnorrSingleKeyAccountContractArtifact } from './artifact.js';
9
8
 
10
9
  /**
11
10
  * Account contract that authenticates transactions using Schnorr signatures verified against
12
11
  * the note encryption key, relying on a single private key for both encryption and authentication.
12
+ * This abstract version does not provide a way to retrieve the artifact, as it
13
+ * can be implemented with or without lazy loading.
13
14
  */
14
- export class SingleKeyAccountContract extends DefaultAccountContract {
15
+ export abstract class SingleKeyBaseAccountContract extends DefaultAccountContract {
15
16
  constructor(private encryptionPrivateKey: GrumpkinScalar) {
16
- super(SchnorrSingleKeyAccountContractArtifact as ContractArtifact);
17
+ super();
17
18
  }
18
19
 
19
20
  getDeploymentArgs() {
@@ -4,16 +4,36 @@
4
4
  *
5
5
  * @packageDocumentation
6
6
  */
7
+ import type { AztecAddress, Fr, GrumpkinScalar } from '@aztec/aztec.js';
7
8
  import { AccountManager, type Salt } from '@aztec/aztec.js/account';
8
9
  import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet';
9
- import { type GrumpkinScalar, type PXE } from '@aztec/circuit-types';
10
- import { type AztecAddress, type Fr, deriveMasterIncomingViewingSecretKey } from '@aztec/circuits.js';
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
+ import type { NoirCompiledContract } from '@aztec/stdlib/noir';
11
15
 
12
- import { SingleKeyAccountContract } from './account_contract.js';
16
+ import SchnorrSingleKeyAccountContractJson from '../../artifacts/SchnorrSingleKeyAccount.json' assert { type: 'json' };
17
+ import { SingleKeyBaseAccountContract } from './account_contract.js';
13
18
 
14
- export { SingleKeyAccountContract };
19
+ export const SchnorrSingleKeyAccountContractArtifact = loadContractArtifact(
20
+ SchnorrSingleKeyAccountContractJson as NoirCompiledContract,
21
+ );
15
22
 
16
- export { SchnorrSingleKeyAccountContractArtifact as SingleKeyAccountContractArtifact } from './artifact.js';
23
+ /**
24
+ * Account contract that authenticates transactions using Schnorr signatures verified against
25
+ * the note encryption key, relying on a single private key for both encryption and authentication.
26
+ * Eagerly loads the contract artifact
27
+ */
28
+ export class SingleKeyAccountContract extends SingleKeyBaseAccountContract {
29
+ constructor(signingPrivateKey: GrumpkinScalar) {
30
+ super(signingPrivateKey);
31
+ }
32
+
33
+ override getContractArtifact(): Promise<ContractArtifact> {
34
+ return Promise.resolve(SchnorrSingleKeyAccountContractArtifact);
35
+ }
36
+ }
17
37
 
18
38
  /**
19
39
  * Creates an Account that uses the same Grumpkin key for encryption and authentication.
@@ -22,7 +42,7 @@ export { SchnorrSingleKeyAccountContractArtifact as SingleKeyAccountContractArti
22
42
  * @param salt - Deployment salt.
23
43
  * @returns An account manager initialized with the account contract and its deployment params
24
44
  */
25
- export function getSingleKeyAccount(pxe: PXE, secretKey: Fr, salt?: Salt) {
45
+ export function getUnsafeSchnorrAccount(pxe: PXE, secretKey: Fr, salt?: Salt) {
26
46
  const encryptionPrivateKey = deriveMasterIncomingViewingSecretKey(secretKey);
27
47
  return AccountManager.create(pxe, secretKey, new SingleKeyAccountContract(encryptionPrivateKey), salt);
28
48
  }
@@ -34,12 +54,10 @@ export function getSingleKeyAccount(pxe: PXE, secretKey: Fr, salt?: Salt) {
34
54
  * @param signingPrivateKey - Grumpkin key used for note encryption and signing transactions.
35
55
  * @returns A wallet for this account that can be used to interact with a contract instance.
36
56
  */
37
- export function getSingleKeyWallet(
57
+ export function getUnsafeSchnorrWallet(
38
58
  pxe: PXE,
39
59
  address: AztecAddress,
40
- signingKey: GrumpkinScalar,
60
+ signingPrivateKey: GrumpkinScalar,
41
61
  ): Promise<AccountWallet> {
42
- return getWallet(pxe, address, new SingleKeyAccountContract(signingKey));
62
+ return getWallet(pxe, address, new SingleKeyAccountContract(signingPrivateKey));
43
63
  }
44
-
45
- export { getSingleKeyAccount as getUnsafeSchnorrAccount, getSingleKeyWallet as getUnsafeSchnorrWallet };