@aztec/accounts 0.0.0-test.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/README.md +41 -0
  2. package/artifacts/EcdsaKAccount.d.json.ts +3 -0
  3. package/artifacts/EcdsaKAccount.json +6257 -0
  4. package/artifacts/EcdsaRAccount.d.json.ts +3 -0
  5. package/artifacts/EcdsaRAccount.json +6257 -0
  6. package/artifacts/SchnorrAccount.d.json.ts +3 -0
  7. package/artifacts/SchnorrAccount.json +6354 -0
  8. package/artifacts/SchnorrSingleKeyAccount.d.json.ts +3 -0
  9. package/artifacts/SchnorrSingleKeyAccount.json +3937 -0
  10. package/dest/dapp/dapp_interface.d.ts +10 -0
  11. package/dest/dapp/dapp_interface.d.ts.map +1 -0
  12. package/dest/dapp/dapp_interface.js +16 -0
  13. package/dest/dapp/index.d.ts +2 -0
  14. package/dest/dapp/index.d.ts.map +1 -0
  15. package/dest/dapp/index.js +1 -0
  16. package/dest/defaults/account_contract.d.ts +15 -0
  17. package/dest/defaults/account_contract.d.ts.map +1 -0
  18. package/dest/defaults/account_contract.js +10 -0
  19. package/dest/defaults/account_interface.d.ts +27 -0
  20. package/dest/defaults/account_interface.d.ts.map +1 -0
  21. package/dest/defaults/account_interface.js +37 -0
  22. package/dest/defaults/index.d.ts +10 -0
  23. package/dest/defaults/index.d.ts.map +1 -0
  24. package/dest/defaults/index.js +8 -0
  25. package/dest/ecdsa/ecdsa_k/account_contract.d.ts +18 -0
  26. package/dest/ecdsa/ecdsa_k/account_contract.d.ts.map +1 -0
  27. package/dest/ecdsa/ecdsa_k/account_contract.js +38 -0
  28. package/dest/ecdsa/ecdsa_k/index.d.ts +43 -0
  29. package/dest/ecdsa/ecdsa_k/index.d.ts.map +1 -0
  30. package/dest/ecdsa/ecdsa_k/index.js +44 -0
  31. package/dest/ecdsa/ecdsa_k/lazy.d.ts +47 -0
  32. package/dest/ecdsa/ecdsa_k/lazy.d.ts.map +1 -0
  33. package/dest/ecdsa/ecdsa_k/lazy.js +52 -0
  34. package/dest/ecdsa/index.d.ts +3 -0
  35. package/dest/ecdsa/index.d.ts.map +1 -0
  36. package/dest/ecdsa/index.js +2 -0
  37. package/dest/ecdsa/lazy.d.ts +3 -0
  38. package/dest/ecdsa/lazy.d.ts.map +1 -0
  39. package/dest/ecdsa/lazy.js +2 -0
  40. package/dest/ecdsa/ssh_ecdsa_r/account_contract.d.ts +21 -0
  41. package/dest/ecdsa/ssh_ecdsa_r/account_contract.d.ts.map +1 -0
  42. package/dest/ecdsa/ssh_ecdsa_r/account_contract.js +80 -0
  43. package/dest/ecdsa/ssh_ecdsa_r/index.d.ts +46 -0
  44. package/dest/ecdsa/ssh_ecdsa_r/index.d.ts.map +1 -0
  45. package/dest/ecdsa/ssh_ecdsa_r/index.js +47 -0
  46. package/dest/ecdsa/ssh_ecdsa_r/lazy.d.ts +49 -0
  47. package/dest/ecdsa/ssh_ecdsa_r/lazy.d.ts.map +1 -0
  48. package/dest/ecdsa/ssh_ecdsa_r/lazy.js +57 -0
  49. package/dest/schnorr/account_contract.d.ts +24 -0
  50. package/dest/schnorr/account_contract.d.ts.map +1 -0
  51. package/dest/schnorr/account_contract.js +37 -0
  52. package/dest/schnorr/index.d.ts +57 -0
  53. package/dest/schnorr/index.d.ts.map +1 -0
  54. package/dest/schnorr/index.js +66 -0
  55. package/dest/schnorr/lazy.d.ts +61 -0
  56. package/dest/schnorr/lazy.d.ts.map +1 -0
  57. package/dest/schnorr/lazy.js +74 -0
  58. package/dest/single_key/account_contract.d.ts +17 -0
  59. package/dest/single_key/account_contract.d.ts.map +1 -0
  60. package/dest/single_key/account_contract.js +42 -0
  61. package/dest/single_key/index.d.ts +39 -0
  62. package/dest/single_key/index.d.ts.map +1 -0
  63. package/dest/single_key/index.js +45 -0
  64. package/dest/single_key/lazy.d.ts +43 -0
  65. package/dest/single_key/lazy.d.ts.map +1 -0
  66. package/dest/single_key/lazy.js +53 -0
  67. package/dest/testing/configuration.d.ts +28 -0
  68. package/dest/testing/configuration.d.ts.map +1 -0
  69. package/dest/testing/configuration.js +15 -0
  70. package/dest/testing/create_account.d.ts +43 -0
  71. package/dest/testing/create_account.d.ts.map +1 -0
  72. package/dest/testing/create_account.js +58 -0
  73. package/dest/testing/index.d.ts +35 -0
  74. package/dest/testing/index.d.ts.map +1 -0
  75. package/dest/testing/index.js +47 -0
  76. package/dest/testing/lazy.d.ts +34 -0
  77. package/dest/testing/lazy.d.ts.map +1 -0
  78. package/dest/testing/lazy.js +46 -0
  79. package/dest/utils/index.d.ts +2 -0
  80. package/dest/utils/index.d.ts.map +1 -0
  81. package/dest/utils/index.js +1 -0
  82. package/dest/utils/ssh_agent.d.ts +36 -0
  83. package/dest/utils/ssh_agent.d.ts.map +1 -0
  84. package/dest/utils/ssh_agent.js +153 -0
  85. package/package.json +106 -0
  86. package/src/dapp/dapp_interface.ts +38 -0
  87. package/src/dapp/index.ts +1 -0
  88. package/src/defaults/account_contract.ts +21 -0
  89. package/src/defaults/account_interface.ts +59 -0
  90. package/src/defaults/index.ts +10 -0
  91. package/src/ecdsa/ecdsa_k/account_contract.ts +39 -0
  92. package/src/ecdsa/ecdsa_k/index.ts +63 -0
  93. package/src/ecdsa/ecdsa_k/lazy.ts +71 -0
  94. package/src/ecdsa/index.ts +2 -0
  95. package/src/ecdsa/lazy.ts +2 -0
  96. package/src/ecdsa/ssh_ecdsa_r/account_contract.ts +89 -0
  97. package/src/ecdsa/ssh_ecdsa_r/index.ts +67 -0
  98. package/src/ecdsa/ssh_ecdsa_r/lazy.ts +78 -0
  99. package/src/schnorr/account_contract.ts +39 -0
  100. package/src/schnorr/index.ts +97 -0
  101. package/src/schnorr/lazy.ts +107 -0
  102. package/src/single_key/account_contract.ts +43 -0
  103. package/src/single_key/index.ts +63 -0
  104. package/src/single_key/lazy.ts +71 -0
  105. package/src/testing/configuration.ts +39 -0
  106. package/src/testing/create_account.ts +93 -0
  107. package/src/testing/index.ts +92 -0
  108. package/src/testing/lazy.ts +86 -0
  109. package/src/utils/index.ts +1 -0
  110. package/src/utils/ssh_agent.ts +136 -0
@@ -0,0 +1,67 @@
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
+ import type { NoirCompiledContract } from '@aztec/stdlib/noir';
15
+
16
+ import EcdsaRAccountContractJson from '../../../artifacts/EcdsaKAccount.json' assert { type: 'json' };
17
+ import { EcdsaRSSHBaseAccountContract } from './account_contract.js';
18
+
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
+ }
40
+
41
+ /**
42
+ * Creates an Account that relies on an ECDSA signing key for authentication.
43
+ * @param pxe - An PXE server instance.
44
+ * @param secretKey - Secret key used to derive all the keystore keys.
45
+ * @param signingPublicKey - Secp2561 key used to identify its corresponding private key in the SSH Agent.
46
+ * @param salt - Deployment salt.
47
+ * @returns An account manager initialized with the account contract and its deployment params
48
+ */
49
+ export function getEcdsaRSSHAccount(
50
+ pxe: PXE,
51
+ secretKey: Fr,
52
+ signingPublicKey: Buffer,
53
+ salt?: Salt,
54
+ ): Promise<AccountManager> {
55
+ return AccountManager.create(pxe, secretKey, new EcdsaRSSHAccountContract(signingPublicKey), salt);
56
+ }
57
+
58
+ /**
59
+ * Gets a wallet for an already registered account using ECDSA signatures.
60
+ * @param pxe - An PXE server instance.
61
+ * @param address - Address for the account.
62
+ * @param signingPrivateKey - ECDSA key used for signing transactions.
63
+ * @returns A wallet for this account that can be used to interact with a contract instance.
64
+ */
65
+ export function getEcdsaRSSHWallet(pxe: PXE, address: AztecAddress, signingPublicKey: Buffer): Promise<AccountWallet> {
66
+ return getWallet(pxe, address, new EcdsaRSSHAccountContract(signingPublicKey));
67
+ }
@@ -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
+ }
@@ -0,0 +1,39 @@
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
+
7
+ import { DefaultAccountContract } from '../defaults/account_contract.js';
8
+
9
+ /**
10
+ * Account contract that authenticates transactions using Schnorr signatures
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.
14
+ */
15
+ export abstract class SchnorrBaseAccountContract extends DefaultAccountContract {
16
+ constructor(private signingPrivateKey: GrumpkinScalar) {
17
+ super();
18
+ }
19
+
20
+ async getDeploymentArgs() {
21
+ const signingPublicKey = await new Schnorr().computePublicKey(this.signingPrivateKey);
22
+ return [signingPublicKey.x, signingPublicKey.y];
23
+ }
24
+
25
+ getAuthWitnessProvider(_address: CompleteAddress): AuthWitnessProvider {
26
+ return new SchnorrAuthWitnessProvider(this.signingPrivateKey);
27
+ }
28
+ }
29
+
30
+ /** Creates auth witnesses using Schnorr signatures. */
31
+ export class SchnorrAuthWitnessProvider implements AuthWitnessProvider {
32
+ constructor(private signingPrivateKey: GrumpkinScalar) {}
33
+
34
+ async createAuthWit(messageHash: Fr): Promise<AuthWitness> {
35
+ const schnorr = new Schnorr();
36
+ const signature = await schnorr.constructSignature(messageHash.toBuffer(), this.signingPrivateKey);
37
+ return new AuthWitness(messageHash, [...signature.toBuffer()]);
38
+ }
39
+ }
@@ -0,0 +1,97 @@
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
+ import type { NoirCompiledContract } from '@aztec/stdlib/noir';
16
+
17
+ import SchnorrAccountContractJson from '../../artifacts/SchnorrAccount.json' assert { type: 'json' };
18
+ import { SchnorrBaseAccountContract } from './account_contract.js';
19
+
20
+ export const SchnorrAccountContractArtifact = loadContractArtifact(SchnorrAccountContractJson as NoirCompiledContract);
21
+
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
+ }
36
+
37
+ /**
38
+ * Creates an Account Manager that relies on a Grumpkin signing key for authentication.
39
+ * @param pxe - An PXE server instance.
40
+ * @param secretKey - Secret key used to derive all the keystore keys.
41
+ * @param signingPrivateKey - Grumpkin key used for signing transactions.
42
+ * @param salt - Deployment salt.
43
+ * @returns An account manager initialized with the account contract and its deployment params
44
+ */
45
+ export function getSchnorrAccount(
46
+ pxe: PXE,
47
+ secretKey: Fr,
48
+ signingPrivateKey: GrumpkinScalar,
49
+ salt?: Salt,
50
+ ): Promise<AccountManager> {
51
+ return AccountManager.create(pxe, secretKey, new SchnorrAccountContract(signingPrivateKey), salt);
52
+ }
53
+
54
+ /**
55
+ * Gets a wallet for an already registered account using Schnorr signatures.
56
+ * @param pxe - An PXE server instance.
57
+ * @param address - Address for the account.
58
+ * @param signingPrivateKey - Grumpkin key used for signing transactions.
59
+ * @returns A wallet for this account that can be used to interact with a contract instance.
60
+ */
61
+ export function getSchnorrWallet(
62
+ pxe: PXE,
63
+ address: AztecAddress,
64
+ signingPrivateKey: GrumpkinScalar,
65
+ ): Promise<AccountWallet> {
66
+ return getWallet(pxe, address, new SchnorrAccountContract(signingPrivateKey));
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
+ }
@@ -0,0 +1,43 @@
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
+
7
+ import { DefaultAccountContract } from '../defaults/account_contract.js';
8
+
9
+ /**
10
+ * Account contract that authenticates transactions using Schnorr signatures verified against
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.
14
+ */
15
+ export abstract class SingleKeyBaseAccountContract extends DefaultAccountContract {
16
+ constructor(private encryptionPrivateKey: GrumpkinScalar) {
17
+ super();
18
+ }
19
+
20
+ getDeploymentArgs() {
21
+ return Promise.resolve(undefined);
22
+ }
23
+
24
+ getAuthWitnessProvider(account: CompleteAddress): AuthWitnessProvider {
25
+ return new SingleKeyAuthWitnessProvider(this.encryptionPrivateKey, account);
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Creates auth witnesses using Schnorr signatures and including the partial address and public key
31
+ * in the witness, so verifiers do not need to store the public key and can instead validate it
32
+ * by reconstructing the current address.
33
+ */
34
+ class SingleKeyAuthWitnessProvider implements AuthWitnessProvider {
35
+ constructor(private privateKey: GrumpkinScalar, private account: CompleteAddress) {}
36
+
37
+ async createAuthWit(messageHash: Fr): Promise<AuthWitness> {
38
+ const schnorr = new Schnorr();
39
+ const signature = await schnorr.constructSignature(messageHash.toBuffer(), this.privateKey);
40
+ const witness = [...this.account.publicKeys.toFields(), ...signature.toBuffer(), this.account.partialAddress];
41
+ return Promise.resolve(new AuthWitness(messageHash, witness));
42
+ }
43
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * The `@aztec/accounts/single_key` export provides a testing account contract implementation that uses a single Grumpkin key for both authentication and encryption.
3
+ * It is not recommended to use this account type in production.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import type { AztecAddress, Fr, GrumpkinScalar } from '@aztec/aztec.js';
8
+ import { AccountManager, type Salt } from '@aztec/aztec.js/account';
9
+ import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet';
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';
15
+
16
+ import SchnorrSingleKeyAccountContractJson from '../../artifacts/SchnorrSingleKeyAccount.json' assert { type: 'json' };
17
+ import { SingleKeyBaseAccountContract } from './account_contract.js';
18
+
19
+ export const SchnorrSingleKeyAccountContractArtifact = loadContractArtifact(
20
+ SchnorrSingleKeyAccountContractJson as NoirCompiledContract,
21
+ );
22
+
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
+ }
37
+
38
+ /**
39
+ * Creates an Account that uses the same Grumpkin key for encryption and authentication.
40
+ * @param pxe - An PXE server instance.
41
+ * @param secretKey - Secret key used to derive all the keystore keys (in this case also used to get signing key).
42
+ * @param salt - Deployment salt.
43
+ * @returns An account manager initialized with the account contract and its deployment params
44
+ */
45
+ export function getUnsafeSchnorrAccount(pxe: PXE, secretKey: Fr, salt?: Salt) {
46
+ const encryptionPrivateKey = deriveMasterIncomingViewingSecretKey(secretKey);
47
+ return AccountManager.create(pxe, secretKey, new SingleKeyAccountContract(encryptionPrivateKey), salt);
48
+ }
49
+
50
+ /**
51
+ * Gets a wallet for an already registered account using Schnorr signatures with a single key for encryption and authentication.
52
+ * @param pxe - An PXE server instance.
53
+ * @param address - Address for the account.
54
+ * @param signingPrivateKey - Grumpkin key used for note encryption and signing transactions.
55
+ * @returns A wallet for this account that can be used to interact with a contract instance.
56
+ */
57
+ export function getUnsafeSchnorrWallet(
58
+ pxe: PXE,
59
+ address: AztecAddress,
60
+ signingPrivateKey: GrumpkinScalar,
61
+ ): Promise<AccountWallet> {
62
+ return getWallet(pxe, address, new SingleKeyAccountContract(signingPrivateKey));
63
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The `@aztec/accounts/single_key` export provides a testing account contract implementation that uses a single Grumpkin key for both authentication and encryption.
3
+ * It is not recommended to use this account type in production.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import type { AztecAddress, Fr, GrumpkinScalar } from '@aztec/aztec.js';
8
+ import { AccountManager, type Salt } from '@aztec/aztec.js/account';
9
+ import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet';
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
+
15
+ import { SingleKeyBaseAccountContract } from './account_contract.js';
16
+
17
+ /**
18
+ * Lazily loads the contract artifact
19
+ * @returns The contract artifact for the single key account contract
20
+ */
21
+ export async function getSingleKeyAccountContractArtifact() {
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: schnorrAccountContractJson } = await import('../../artifacts/SchnorrAccount.json');
28
+ return loadContractArtifact(schnorrAccountContractJson);
29
+ }
30
+
31
+ /**
32
+ * Account contract that authenticates transactions using Schnorr signatures verified against
33
+ * the note encryption key, relying on a single private key for both encryption and authentication.
34
+ * Lazily loads the contract artifact
35
+ */
36
+ export class SingleKeyAccountContract extends SingleKeyBaseAccountContract {
37
+ constructor(signingPrivateKey: GrumpkinScalar) {
38
+ super(signingPrivateKey);
39
+ }
40
+
41
+ override getContractArtifact(): Promise<ContractArtifact> {
42
+ return getSingleKeyAccountContractArtifact();
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Creates an Account that uses the same Grumpkin key for encryption and authentication.
48
+ * @param pxe - An PXE server instance.
49
+ * @param secretKey - Secret key used to derive all the keystore keys (in this case also used to get signing key).
50
+ * @param salt - Deployment salt.
51
+ * @returns An account manager initialized with the account contract and its deployment params
52
+ */
53
+ export function getUnsafeSchnorrAccount(pxe: PXE, secretKey: Fr, salt?: Salt) {
54
+ const encryptionPrivateKey = deriveMasterIncomingViewingSecretKey(secretKey);
55
+ return AccountManager.create(pxe, secretKey, new SingleKeyAccountContract(encryptionPrivateKey), salt);
56
+ }
57
+
58
+ /**
59
+ * Gets a wallet for an already registered account using Schnorr signatures with a single key for encryption and authentication.
60
+ * @param pxe - An PXE server instance.
61
+ * @param address - Address for the account.
62
+ * @param signingPrivateKey - Grumpkin key used for note encryption and signing transactions.
63
+ * @returns A wallet for this account that can be used to interact with a contract instance.
64
+ */
65
+ export function getUnsafeSchnorrWallet(
66
+ pxe: PXE,
67
+ address: AztecAddress,
68
+ signingPrivateKey: GrumpkinScalar,
69
+ ): Promise<AccountWallet> {
70
+ return getWallet(pxe, address, new SingleKeyAccountContract(signingPrivateKey));
71
+ }
@@ -0,0 +1,39 @@
1
+ import { Fr, GrumpkinScalar } from '@aztec/foundation/fields';
2
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import { deriveMasterIncomingViewingSecretKey } from '@aztec/stdlib/keys';
4
+
5
+ export const INITIAL_TEST_SECRET_KEYS = [
6
+ Fr.fromHexString('2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281'),
7
+ Fr.fromHexString('aebd1b4be76efa44f5ee655c20bf9ea60f7ae44b9a7fd1fd9f189c7a0b0cdae'),
8
+ Fr.fromHexString('0f6addf0da06c33293df974a565b03d1ab096090d907d98055a8b7f4954e120c'),
9
+ ];
10
+
11
+ export const INITIAL_TEST_ENCRYPTION_KEYS = INITIAL_TEST_SECRET_KEYS.map(secretKey =>
12
+ deriveMasterIncomingViewingSecretKey(secretKey),
13
+ );
14
+ // TODO(#5837): come up with a standard signing key derivation scheme instead of using ivsk_m as signing keys here
15
+ export const INITIAL_TEST_SIGNING_KEYS = INITIAL_TEST_ENCRYPTION_KEYS;
16
+
17
+ export const INITIAL_TEST_ACCOUNT_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO];
18
+
19
+ /**
20
+ * Data for generating an initial account.
21
+ */
22
+ export interface InitialAccountData {
23
+ /**
24
+ * Secret to derive the keys for the account.
25
+ */
26
+ secret: Fr;
27
+ /**
28
+ * Signing key od the account.
29
+ */
30
+ signingKey: GrumpkinScalar;
31
+ /**
32
+ * Contract address salt.
33
+ */
34
+ salt: Fr;
35
+ /**
36
+ * Address of the schnorr account contract.
37
+ */
38
+ address: AztecAddress;
39
+ }