@aztec/aztec.js 0.7.3 → 0.7.5

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 (147) hide show
  1. package/.tsbuildinfo +1 -1
  2. package/dest/abis/ecdsa_account_contract.json +530 -11
  3. package/dest/abis/schnorr_account_contract.json +530 -11
  4. package/dest/abis/schnorr_single_key_account_contract.json +523 -24
  5. package/dest/account/contract/base_account_contract.d.ts +17 -0
  6. package/dest/account/contract/base_account_contract.d.ts.map +1 -0
  7. package/dest/account/contract/base_account_contract.js +17 -0
  8. package/dest/account/contract/ecdsa_account_contract.d.ts +6 -7
  9. package/dest/account/contract/ecdsa_account_contract.d.ts.map +1 -1
  10. package/dest/account/contract/ecdsa_account_contract.js +18 -9
  11. package/dest/account/contract/index.d.ts +11 -8
  12. package/dest/account/contract/index.d.ts.map +1 -1
  13. package/dest/account/contract/index.js +2 -2
  14. package/dest/account/contract/schnorr_account_contract.d.ts +7 -8
  15. package/dest/account/contract/schnorr_account_contract.d.ts.map +1 -1
  16. package/dest/account/contract/schnorr_account_contract.js +17 -9
  17. package/dest/account/contract/single_key_account_contract.d.ts +6 -8
  18. package/dest/account/contract/single_key_account_contract.d.ts.map +1 -1
  19. package/dest/account/contract/single_key_account_contract.js +26 -7
  20. package/dest/account/defaults/default_entrypoint.d.ts +17 -0
  21. package/dest/account/defaults/default_entrypoint.d.ts.map +1 -0
  22. package/dest/account/defaults/default_entrypoint.js +90 -0
  23. package/dest/account/defaults/default_interface.d.ts +17 -0
  24. package/dest/account/defaults/default_interface.d.ts.map +1 -0
  25. package/dest/account/defaults/default_interface.js +22 -0
  26. package/dest/account/defaults/entrypoint_payload.d.ts.map +1 -0
  27. package/dest/account/defaults/entrypoint_payload.js +48 -0
  28. package/dest/account/defaults/index.d.ts +4 -0
  29. package/dest/account/defaults/index.d.ts.map +1 -0
  30. package/dest/account/defaults/index.js +4 -0
  31. package/dest/account/index.d.ts +8 -8
  32. package/dest/account/index.d.ts.map +1 -1
  33. package/dest/account/index.js +11 -12
  34. package/dest/account/interface.d.ts +31 -0
  35. package/dest/account/interface.d.ts.map +1 -0
  36. package/dest/account/interface.js +3 -0
  37. package/dest/account/{deploy_account_sent_tx.d.ts → manager/deploy_account_sent_tx.d.ts} +1 -1
  38. package/dest/account/manager/deploy_account_sent_tx.d.ts.map +1 -0
  39. package/dest/account/{deploy_account_sent_tx.js → manager/deploy_account_sent_tx.js} +2 -2
  40. package/dest/account/{account.d.ts → manager/index.d.ts} +7 -6
  41. package/dest/account/manager/index.d.ts.map +1 -0
  42. package/dest/account/{account.js → manager/index.js} +7 -7
  43. package/dest/{aztec_rpc_client/aztec_rpc_client.d.ts → aztec_rpc_client.d.ts} +1 -2
  44. package/dest/aztec_rpc_client.d.ts.map +1 -0
  45. package/dest/aztec_rpc_client.js +19 -0
  46. package/dest/contract/contract.d.ts +1 -1
  47. package/dest/contract/contract.d.ts.map +1 -1
  48. package/dest/contract/contract.js +1 -1
  49. package/dest/contract/contract.test.js +9 -3
  50. package/dest/contract/contract_base.d.ts +1 -1
  51. package/dest/contract/contract_base.d.ts.map +1 -1
  52. package/dest/contract/contract_function_interaction.d.ts +4 -4
  53. package/dest/contract/contract_function_interaction.d.ts.map +1 -1
  54. package/dest/contract/contract_function_interaction.js +1 -1
  55. package/dest/contract_deployer/deploy_method.d.ts.map +1 -1
  56. package/dest/contract_deployer/deploy_method.js +2 -1
  57. package/dest/index.d.ts +2 -1
  58. package/dest/index.d.ts.map +1 -1
  59. package/dest/index.js +3 -2
  60. package/dest/main.js +1 -1
  61. package/dest/sandbox/index.d.ts +70 -14
  62. package/dest/sandbox/index.d.ts.map +1 -1
  63. package/dest/utils/account.d.ts +1 -1
  64. package/dest/utils/account.d.ts.map +1 -1
  65. package/dest/utils/account.js +1 -1
  66. package/dest/wallet/account_wallet.d.ts +29 -0
  67. package/dest/wallet/account_wallet.d.ts.map +1 -0
  68. package/dest/wallet/account_wallet.js +61 -0
  69. package/dest/wallet/base_wallet.d.ts +38 -0
  70. package/dest/wallet/base_wallet.d.ts.map +1 -0
  71. package/dest/wallet/base_wallet.js +78 -0
  72. package/dest/wallet/index.d.ts +9 -0
  73. package/dest/wallet/index.d.ts.map +1 -0
  74. package/dest/wallet/index.js +4 -0
  75. package/dest/wallet/signerless_wallet.d.ts +13 -0
  76. package/dest/wallet/signerless_wallet.d.ts.map +1 -0
  77. package/dest/wallet/signerless_wallet.js +26 -0
  78. package/package.json +4 -4
  79. package/src/abis/ecdsa_account_contract.json +530 -11
  80. package/src/abis/schnorr_account_contract.json +530 -11
  81. package/src/abis/schnorr_single_key_account_contract.json +523 -24
  82. package/src/account/contract/base_account_contract.ts +25 -0
  83. package/src/account/contract/ecdsa_account_contract.ts +21 -12
  84. package/src/account/contract/index.ts +13 -8
  85. package/src/account/contract/schnorr_account_contract.ts +20 -12
  86. package/src/account/contract/single_key_account_contract.ts +28 -12
  87. package/src/account/defaults/default_entrypoint.ts +95 -0
  88. package/src/account/defaults/default_interface.ts +36 -0
  89. package/src/account/defaults/index.ts +3 -0
  90. package/src/account/index.ts +14 -14
  91. package/src/account/interface.ts +35 -0
  92. package/src/account/{deploy_account_sent_tx.ts → manager/deploy_account_sent_tx.ts} +1 -1
  93. package/src/account/{account.ts → manager/index.ts} +8 -7
  94. package/src/{aztec_rpc_client/aztec_rpc_client.ts → aztec_rpc_client.ts} +4 -2
  95. package/src/contract/contract.test.ts +9 -3
  96. package/src/contract/contract.ts +1 -1
  97. package/src/contract/contract_base.ts +1 -1
  98. package/src/contract/contract_function_interaction.ts +3 -3
  99. package/src/contract_deployer/deploy_method.ts +1 -0
  100. package/src/index.ts +2 -1
  101. package/src/utils/account.ts +1 -1
  102. package/src/wallet/account_wallet.ts +70 -0
  103. package/src/wallet/base_wallet.ts +103 -0
  104. package/src/wallet/index.ts +10 -0
  105. package/src/wallet/signerless_wallet.ts +39 -0
  106. package/dest/abis/schnorr_auth_witness_account_contract.json +0 -643
  107. package/dest/account/account.d.ts.map +0 -1
  108. package/dest/account/contract/auth_witness_account_contract.d.ts +0 -17
  109. package/dest/account/contract/auth_witness_account_contract.d.ts.map +0 -1
  110. package/dest/account/contract/auth_witness_account_contract.js +0 -23
  111. package/dest/account/deploy_account_sent_tx.d.ts.map +0 -1
  112. package/dest/account/entrypoint/auth_witness_account_entrypoint.d.ts +0 -74
  113. package/dest/account/entrypoint/auth_witness_account_entrypoint.d.ts.map +0 -1
  114. package/dest/account/entrypoint/auth_witness_account_entrypoint.js +0 -68
  115. package/dest/account/entrypoint/entrypoint_payload.d.ts.map +0 -1
  116. package/dest/account/entrypoint/entrypoint_payload.js +0 -48
  117. package/dest/account/entrypoint/entrypoint_utils.d.ts +0 -14
  118. package/dest/account/entrypoint/entrypoint_utils.d.ts.map +0 -1
  119. package/dest/account/entrypoint/entrypoint_utils.js +0 -24
  120. package/dest/account/entrypoint/index.d.ts +0 -20
  121. package/dest/account/entrypoint/index.d.ts.map +0 -1
  122. package/dest/account/entrypoint/index.js +0 -7
  123. package/dest/account/entrypoint/single_key_account_entrypoint.d.ts +0 -19
  124. package/dest/account/entrypoint/single_key_account_entrypoint.d.ts.map +0 -1
  125. package/dest/account/entrypoint/single_key_account_entrypoint.js +0 -50
  126. package/dest/account/entrypoint/stored_key_account_entrypoint.d.ts +0 -20
  127. package/dest/account/entrypoint/stored_key_account_entrypoint.d.ts.map +0 -1
  128. package/dest/account/entrypoint/stored_key_account_entrypoint.js +0 -47
  129. package/dest/aztec_rpc_client/aztec_rpc_client.d.ts.map +0 -1
  130. package/dest/aztec_rpc_client/aztec_rpc_client.js +0 -18
  131. package/dest/aztec_rpc_client/index.d.ts +0 -3
  132. package/dest/aztec_rpc_client/index.d.ts.map +0 -1
  133. package/dest/aztec_rpc_client/index.js +0 -3
  134. package/dest/aztec_rpc_client/wallet.d.ts +0 -109
  135. package/dest/aztec_rpc_client/wallet.d.ts.map +0 -1
  136. package/dest/aztec_rpc_client/wallet.js +0 -186
  137. package/src/abis/schnorr_auth_witness_account_contract.json +0 -643
  138. package/src/account/contract/auth_witness_account_contract.ts +0 -35
  139. package/src/account/entrypoint/auth_witness_account_entrypoint.ts +0 -125
  140. package/src/account/entrypoint/entrypoint_utils.ts +0 -31
  141. package/src/account/entrypoint/index.ts +0 -23
  142. package/src/account/entrypoint/single_key_account_entrypoint.ts +0 -55
  143. package/src/account/entrypoint/stored_key_account_entrypoint.ts +0 -56
  144. package/src/aztec_rpc_client/index.ts +0 -2
  145. package/src/aztec_rpc_client/wallet.ts +0 -219
  146. /package/dest/account/{entrypoint → defaults}/entrypoint_payload.d.ts +0 -0
  147. /package/src/account/{entrypoint → defaults}/entrypoint_payload.ts +0 -0
@@ -0,0 +1,25 @@
1
+ import { ContractAbi } from '@aztec/foundation/abi';
2
+ import { CompleteAddress, NodeInfo } from '@aztec/types';
3
+
4
+ import { DefaultAccountInterface } from '../defaults/default_interface.js';
5
+ import { AccountInterface, AuthWitnessProvider } from '../interface.js';
6
+ import { AccountContract } from './index.js';
7
+
8
+ /**
9
+ * Base class for implementing an account contract. Requires that the account uses the
10
+ * default entrypoint method signature.
11
+ */
12
+ export abstract class BaseAccountContract implements AccountContract {
13
+ abstract getAuthWitnessProvider(address: CompleteAddress): AuthWitnessProvider;
14
+ abstract getDeploymentArgs(): Promise<any[]>;
15
+
16
+ constructor(private abi: ContractAbi) {}
17
+
18
+ getContractAbi(): ContractAbi {
19
+ return this.abi;
20
+ }
21
+
22
+ getInterface(address: CompleteAddress, nodeInfo: NodeInfo): Promise<AccountInterface> {
23
+ return Promise.resolve(new DefaultAccountInterface(this.getAuthWitnessProvider(address), address, nodeInfo));
24
+ }
25
+ }
@@ -1,29 +1,38 @@
1
+ import { Fr } from '@aztec/circuits.js';
1
2
  import { Ecdsa } from '@aztec/circuits.js/barretenberg';
2
3
  import { ContractAbi } from '@aztec/foundation/abi';
3
- import { CompleteAddress, NodeInfo } from '@aztec/types';
4
+ import { AuthWitness, CompleteAddress } from '@aztec/types';
4
5
 
5
6
  import EcdsaAccountContractAbi from '../../abis/ecdsa_account_contract.json' assert { type: 'json' };
6
- import { StoredKeyAccountEntrypoint } from '../entrypoint/stored_key_account_entrypoint.js';
7
- import { AccountContract } from './index.js';
7
+ import { AuthWitnessProvider } from '../interface.js';
8
+ import { BaseAccountContract } from './base_account_contract.js';
8
9
 
9
10
  /**
10
11
  * Account contract that authenticates transactions using ECDSA signatures
11
12
  * verified against a secp256k1 public key stored in an immutable encrypted note.
12
- */ export class EcdsaAccountContract implements AccountContract {
13
- constructor(private signingPrivateKey: Buffer) {}
13
+ */
14
+ export class EcdsaAccountContract extends BaseAccountContract {
15
+ constructor(private signingPrivateKey: Buffer) {
16
+ super(EcdsaAccountContractAbi as unknown as ContractAbi);
17
+ }
14
18
 
15
- public async getDeploymentArgs() {
19
+ async getDeploymentArgs() {
16
20
  const signingPublicKey = await Ecdsa.new().then(e => e.computePublicKey(this.signingPrivateKey));
17
21
  return [signingPublicKey.subarray(0, 32), signingPublicKey.subarray(32, 64)];
18
22
  }
19
23
 
20
- public async getEntrypoint({ address }: CompleteAddress, { chainId, version }: NodeInfo) {
21
- const ecdsa = await Ecdsa.new();
22
- const signClosure = (msg: Buffer) => ecdsa.constructSignature(msg, this.signingPrivateKey);
23
- return new StoredKeyAccountEntrypoint(address, signClosure, chainId, version);
24
+ getAuthWitnessProvider(_address: CompleteAddress): AuthWitnessProvider {
25
+ return new EcdsaAuthWitnessProvider(this.signingPrivateKey);
24
26
  }
27
+ }
25
28
 
26
- public getContractAbi(): ContractAbi {
27
- return EcdsaAccountContractAbi as unknown as ContractAbi;
29
+ /** Creates auth witnesses using ECDSA signatures. */
30
+ class EcdsaAuthWitnessProvider implements AuthWitnessProvider {
31
+ constructor(private signingPrivateKey: Buffer) {}
32
+
33
+ async createAuthWitness(message: Fr): Promise<AuthWitness> {
34
+ const ecdsa = await Ecdsa.new();
35
+ const signature = ecdsa.constructSignature(message.toBuffer(), this.signingPrivateKey);
36
+ return new AuthWitness(message, [...signature.r, ...signature.s]);
28
37
  }
29
38
  }
@@ -1,32 +1,37 @@
1
1
  import { ContractAbi } from '@aztec/foundation/abi';
2
2
  import { CompleteAddress, NodeInfo } from '@aztec/types';
3
3
 
4
- import { Entrypoint } from '../index.js';
4
+ import { AccountInterface } from '../interface.js';
5
5
 
6
6
  export * from './ecdsa_account_contract.js';
7
7
  export * from './schnorr_account_contract.js';
8
8
  export * from './single_key_account_contract.js';
9
- export * from './auth_witness_account_contract.js';
9
+ export * from './base_account_contract.js';
10
10
 
11
11
  // docs:start:account-contract-interface
12
12
  /**
13
- * An account contract instance. Knows its ABI, deployment arguments, and to create
14
- * transaction execution requests out of function calls through an entrypoint.
13
+ * An account contract instance. Knows its ABI, deployment arguments, how to create
14
+ * transaction execution requests out of function calls, and how to authorize actions.
15
15
  */
16
16
  export interface AccountContract {
17
17
  /**
18
18
  * Returns the ABI of this account contract.
19
19
  */
20
20
  getContractAbi(): ContractAbi;
21
+
21
22
  /**
22
23
  * Returns the deployment arguments for this instance.
23
24
  */
24
25
  getDeploymentArgs(): Promise<any[]>;
26
+
25
27
  /**
26
- * Creates an entrypoint for creating transaction execution requests for this account contract.
27
- * @param address - Complete address of the deployed account contract.
28
- * @param nodeInfo - Chain id and protocol version where the account contract is deployed.
28
+ * Returns the account interface for this account contract given a deployment at the provided address.
29
+ * The account interface is responsible for assembling tx requests given requested function calls, and
30
+ * for creating signed auth witnesses given action identifiers (message hashes).
31
+ * @param address - Address where this account contract is deployed.
32
+ * @param nodeInfo - Info on the chain where it is deployed.
33
+ * @returns An account interface instance for creating tx requests and authorizing actions.
29
34
  */
30
- getEntrypoint(address: CompleteAddress, nodeInfo: NodeInfo): Promise<Entrypoint>;
35
+ getInterface(address: CompleteAddress, nodeInfo: NodeInfo): Promise<AccountInterface>;
31
36
  }
32
37
  // docs:end:account-contract-interface
@@ -1,30 +1,38 @@
1
+ import { Fr } from '@aztec/circuits.js';
1
2
  import { Schnorr } from '@aztec/circuits.js/barretenberg';
2
3
  import { ContractAbi } from '@aztec/foundation/abi';
3
- import { CompleteAddress, GrumpkinPrivateKey, NodeInfo } from '@aztec/types';
4
+ import { AuthWitness, CompleteAddress, GrumpkinPrivateKey } from '@aztec/types';
4
5
 
5
6
  import SchnorrAccountContractAbi from '../../abis/schnorr_account_contract.json' assert { type: 'json' };
6
- import { StoredKeyAccountEntrypoint } from '../entrypoint/stored_key_account_entrypoint.js';
7
- import { AccountContract } from './index.js';
7
+ import { AuthWitnessProvider } from '../interface.js';
8
+ import { BaseAccountContract } from './base_account_contract.js';
8
9
 
9
10
  /**
10
11
  * Account contract that authenticates transactions using Schnorr signatures
11
12
  * verified against a Grumpkin public key stored in an immutable encrypted note.
12
13
  */
13
- export class SchnorrAccountContract implements AccountContract {
14
- constructor(private signingPrivateKey: GrumpkinPrivateKey) {}
14
+ export class SchnorrAccountContract extends BaseAccountContract {
15
+ constructor(private signingPrivateKey: GrumpkinPrivateKey) {
16
+ super(SchnorrAccountContractAbi as unknown as ContractAbi);
17
+ }
15
18
 
16
- public async getDeploymentArgs() {
19
+ async getDeploymentArgs() {
17
20
  const signingPublicKey = await Schnorr.new().then(e => e.computePublicKey(this.signingPrivateKey));
18
21
  return [signingPublicKey.x, signingPublicKey.y];
19
22
  }
20
23
 
21
- public async getEntrypoint({ address }: CompleteAddress, { chainId, version }: NodeInfo) {
22
- const schnorr = await Schnorr.new();
23
- const signClosure = (msg: Buffer) => schnorr.constructSignature(msg, this.signingPrivateKey);
24
- return new StoredKeyAccountEntrypoint(address, signClosure, chainId, version);
24
+ getAuthWitnessProvider(_address: CompleteAddress): AuthWitnessProvider {
25
+ return new SchnorrAuthWitnessProvider(this.signingPrivateKey);
25
26
  }
27
+ }
26
28
 
27
- public getContractAbi(): ContractAbi {
28
- return SchnorrAccountContractAbi as unknown as ContractAbi;
29
+ /** Creates auth witnesses using Schnorr signatures. */
30
+ class SchnorrAuthWitnessProvider implements AuthWitnessProvider {
31
+ constructor(private signingPrivateKey: GrumpkinPrivateKey) {}
32
+
33
+ async createAuthWitness(message: Fr): Promise<AuthWitness> {
34
+ const schnorr = await Schnorr.new();
35
+ const signature = schnorr.constructSignature(message.toBuffer(), this.signingPrivateKey).toBuffer();
36
+ return new AuthWitness(message, [...signature]);
29
37
  }
30
38
  }
@@ -1,28 +1,44 @@
1
+ import { Fr, PartialAddress } from '@aztec/circuits.js';
2
+ import { Schnorr } from '@aztec/circuits.js/barretenberg';
1
3
  import { ContractAbi } from '@aztec/foundation/abi';
2
- import { CompleteAddress, GrumpkinPrivateKey, NodeInfo } from '@aztec/types';
4
+ import { AuthWitness, CompleteAddress, GrumpkinPrivateKey } from '@aztec/types';
3
5
 
4
6
  import SchnorrSingleKeyAccountContractAbi from '../../abis/schnorr_single_key_account_contract.json' assert { type: 'json' };
5
- import { SingleKeyAccountEntrypoint } from '../entrypoint/single_key_account_entrypoint.js';
6
- import { AccountContract } from './index.js';
7
+ import { generatePublicKey } from '../../index.js';
8
+ import { AuthWitnessProvider } from '../interface.js';
9
+ import { BaseAccountContract } from './base_account_contract.js';
7
10
 
8
11
  /**
9
12
  * Account contract that authenticates transactions using Schnorr signatures verified against
10
13
  * the note encryption key, relying on a single private key for both encryption and authentication.
11
14
  */
12
- export class SingleKeyAccountContract implements AccountContract {
13
- constructor(private encryptionPrivateKey: GrumpkinPrivateKey) {}
15
+ export class SingleKeyAccountContract extends BaseAccountContract {
16
+ constructor(private encryptionPrivateKey: GrumpkinPrivateKey) {
17
+ super(SchnorrSingleKeyAccountContractAbi as unknown as ContractAbi);
18
+ }
14
19
 
15
- public getDeploymentArgs() {
20
+ getDeploymentArgs(): Promise<any[]> {
16
21
  return Promise.resolve([]);
17
22
  }
18
23
 
19
- public getEntrypoint({ address, partialAddress }: CompleteAddress, { chainId, version }: NodeInfo) {
20
- return Promise.resolve(
21
- new SingleKeyAccountEntrypoint(address, partialAddress, this.encryptionPrivateKey, chainId, version),
22
- );
24
+ getAuthWitnessProvider({ partialAddress }: CompleteAddress): AuthWitnessProvider {
25
+ return new SingleKeyAuthWitnessProvider(this.encryptionPrivateKey, partialAddress);
23
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: GrumpkinPrivateKey, private partialAddress: PartialAddress) {}
24
36
 
25
- public getContractAbi(): ContractAbi {
26
- return SchnorrSingleKeyAccountContractAbi as unknown as ContractAbi;
37
+ async createAuthWitness(message: Fr): Promise<AuthWitness> {
38
+ const schnorr = await Schnorr.new();
39
+ const signature = schnorr.constructSignature(message.toBuffer(), this.privateKey);
40
+ const publicKey = await generatePublicKey(this.privateKey);
41
+ const witness = [...publicKey.toFields(), ...signature.toBuffer(), this.partialAddress];
42
+ return new AuthWitness(message, witness);
27
43
  }
28
44
  }
@@ -0,0 +1,95 @@
1
+ import { AztecAddress, Fr, FunctionData, TxContext } from '@aztec/circuits.js';
2
+ import { FunctionAbiHeader, encodeArguments } from '@aztec/foundation/abi';
3
+ import { FunctionCall, PackedArguments, TxExecutionRequest } from '@aztec/types';
4
+
5
+ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from '../../utils/defaults.js';
6
+ import { AuthWitnessProvider, EntrypointInterface } from '../interface.js';
7
+ import { buildPayload, hashPayload } from './entrypoint_payload.js';
8
+
9
+ /**
10
+ * Implementation for an entrypoint interface that follows the default entrypoint signature
11
+ * for an account, which accepts an EntrypointPayload as defined in noir-libs/aztec-noir/src/entrypoint.nr.
12
+ */
13
+ export class DefaultAccountEntrypoint implements EntrypointInterface {
14
+ constructor(
15
+ private address: AztecAddress,
16
+ private auth: AuthWitnessProvider,
17
+ private chainId: number = DEFAULT_CHAIN_ID,
18
+ private version: number = DEFAULT_VERSION,
19
+ ) {}
20
+
21
+ async createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest> {
22
+ const { payload, packedArguments: callsPackedArguments } = await buildPayload(executions);
23
+ const abi = this.getEntrypointAbi();
24
+ const packedArgs = await PackedArguments.fromArgs(encodeArguments(abi, [payload]));
25
+ const message = Fr.fromBuffer(await hashPayload(payload));
26
+ const authWitness = await this.auth.createAuthWitness(message);
27
+ const txRequest = TxExecutionRequest.from({
28
+ argsHash: packedArgs.hash,
29
+ origin: this.address,
30
+ functionData: FunctionData.fromAbi(abi),
31
+ txContext: TxContext.empty(this.chainId, this.version),
32
+ packedArguments: [...callsPackedArguments, packedArgs],
33
+ authWitnesses: [authWitness],
34
+ });
35
+
36
+ return txRequest;
37
+ }
38
+
39
+ private getEntrypointAbi() {
40
+ return {
41
+ name: 'entrypoint',
42
+ functionType: 'secret',
43
+ isInternal: false,
44
+ parameters: [
45
+ {
46
+ name: 'payload',
47
+ type: {
48
+ kind: 'struct',
49
+ path: 'aztec::entrypoint::EntrypointPayload',
50
+ fields: [
51
+ {
52
+ name: 'flattened_args_hashes',
53
+ type: {
54
+ kind: 'array',
55
+ length: 4,
56
+ type: {
57
+ kind: 'field',
58
+ },
59
+ },
60
+ },
61
+ {
62
+ name: 'flattened_selectors',
63
+ type: {
64
+ kind: 'array',
65
+ length: 4,
66
+ type: {
67
+ kind: 'field',
68
+ },
69
+ },
70
+ },
71
+ {
72
+ name: 'flattened_targets',
73
+ type: {
74
+ kind: 'array',
75
+ length: 4,
76
+ type: {
77
+ kind: 'field',
78
+ },
79
+ },
80
+ },
81
+ {
82
+ name: 'nonce',
83
+ type: {
84
+ kind: 'field',
85
+ },
86
+ },
87
+ ],
88
+ },
89
+ visibility: 'public',
90
+ },
91
+ ],
92
+ returnTypes: [],
93
+ } as unknown as FunctionAbiHeader;
94
+ }
95
+ }
@@ -0,0 +1,36 @@
1
+ import { CompleteAddress, Fr } from '@aztec/circuits.js';
2
+ import { AuthWitness, FunctionCall, NodeInfo, TxExecutionRequest } from '@aztec/types';
3
+
4
+ import { AccountInterface, AuthWitnessProvider, EntrypointInterface } from '../interface.js';
5
+ import { DefaultAccountEntrypoint } from './default_entrypoint.js';
6
+
7
+ /**
8
+ * Default implementation for an account interface. Requires that the account uses the default
9
+ * entrypoint signature, which accepts an EntrypointPayload as defined in noir-libs/aztec-noir/src/entrypoint.nr.
10
+ */
11
+ export class DefaultAccountInterface implements AccountInterface {
12
+ private entrypoint: EntrypointInterface;
13
+
14
+ constructor(
15
+ private authWitnessProvider: AuthWitnessProvider,
16
+ private address: CompleteAddress,
17
+ nodeInfo: Pick<NodeInfo, 'chainId' | 'version'>,
18
+ ) {
19
+ this.entrypoint = new DefaultAccountEntrypoint(
20
+ address.address,
21
+ authWitnessProvider,
22
+ nodeInfo.chainId,
23
+ nodeInfo.version,
24
+ );
25
+ }
26
+
27
+ createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest> {
28
+ return this.entrypoint.createTxExecutionRequest(executions);
29
+ }
30
+ createAuthWitness(message: Fr): Promise<AuthWitness> {
31
+ return this.authWitnessProvider.createAuthWitness(message);
32
+ }
33
+ getCompleteAddress(): CompleteAddress {
34
+ return this.address;
35
+ }
36
+ }
@@ -0,0 +1,3 @@
1
+ export * from './entrypoint_payload.js';
2
+ export * from './default_entrypoint.js';
3
+ export * from './default_interface.js';
@@ -1,15 +1,15 @@
1
1
  import { AztecRPC, CompleteAddress, GrumpkinPrivateKey } from '@aztec/types';
2
2
 
3
3
  import { AccountContract, AccountWallet, AztecAddress, Fr } from '../index.js';
4
- import { Account } from './account.js';
5
4
  import { EcdsaAccountContract } from './contract/ecdsa_account_contract.js';
6
5
  import { SchnorrAccountContract } from './contract/schnorr_account_contract.js';
7
6
  import { SingleKeyAccountContract } from './contract/single_key_account_contract.js';
7
+ import { AccountManager } from './manager/index.js';
8
8
 
9
- export { Account } from './account.js';
10
9
  export * from './contract/index.js';
11
- export * from './entrypoint/index.js';
12
- export { CompleteAddress };
10
+ export * from './defaults/index.js';
11
+ export { AccountInterface, AuthWitnessProvider } from './interface.js';
12
+ export { AccountManager, CompleteAddress };
13
13
 
14
14
  /** A contract deployment salt. */
15
15
  export type Salt = Fr | number | bigint;
@@ -26,8 +26,8 @@ export function getEcdsaAccount(
26
26
  encryptionPrivateKey: GrumpkinPrivateKey,
27
27
  signingPrivateKey: Buffer,
28
28
  saltOrAddress?: Salt | CompleteAddress,
29
- ): Account {
30
- return new Account(rpc, encryptionPrivateKey, new EcdsaAccountContract(signingPrivateKey), saltOrAddress);
29
+ ): AccountManager {
30
+ return new AccountManager(rpc, encryptionPrivateKey, new EcdsaAccountContract(signingPrivateKey), saltOrAddress);
31
31
  }
32
32
 
33
33
  /**
@@ -42,8 +42,8 @@ export function getSchnorrAccount(
42
42
  encryptionPrivateKey: GrumpkinPrivateKey,
43
43
  signingPrivateKey: GrumpkinPrivateKey,
44
44
  saltOrAddress?: Salt | CompleteAddress,
45
- ): Account {
46
- return new Account(rpc, encryptionPrivateKey, new SchnorrAccountContract(signingPrivateKey), saltOrAddress);
45
+ ): AccountManager {
46
+ return new AccountManager(rpc, encryptionPrivateKey, new SchnorrAccountContract(signingPrivateKey), saltOrAddress);
47
47
  }
48
48
 
49
49
  /**
@@ -56,8 +56,8 @@ export function getUnsafeSchnorrAccount(
56
56
  rpc: AztecRPC,
57
57
  encryptionAndSigningPrivateKey: GrumpkinPrivateKey,
58
58
  saltOrAddress?: Salt | CompleteAddress,
59
- ): Account {
60
- return new Account(
59
+ ): AccountManager {
60
+ return new AccountManager(
61
61
  rpc,
62
62
  encryptionAndSigningPrivateKey,
63
63
  new SingleKeyAccountContract(encryptionAndSigningPrivateKey),
@@ -85,18 +85,18 @@ export function getUnsafeSchnorrWallet(
85
85
  * @param rpc - An AztecRPC server instance.
86
86
  * @param address - Address for the account.
87
87
  * @param accountContract - Account contract implementation.
88
- * * @returns A wallet for this account that can be used to interact with a contract instance.
88
+ * @returns A wallet for this account that can be used to interact with a contract instance.
89
89
  */
90
90
  export async function getWallet(
91
91
  rpc: AztecRPC,
92
92
  address: AztecAddress,
93
93
  accountContract: AccountContract,
94
94
  ): Promise<AccountWallet> {
95
- const completeAddress = await rpc.getAccount(address);
95
+ const completeAddress = await rpc.getRegisteredAccount(address);
96
96
  if (!completeAddress) {
97
97
  throw new Error(`Account ${address} not found`);
98
98
  }
99
99
  const nodeInfo = await rpc.getNodeInfo();
100
- const entrypoint = await accountContract.getEntrypoint(completeAddress, nodeInfo);
101
- return new AccountWallet(rpc, entrypoint, completeAddress);
100
+ const entrypoint = await accountContract.getInterface(completeAddress, nodeInfo);
101
+ return new AccountWallet(rpc, entrypoint);
102
102
  }
@@ -0,0 +1,35 @@
1
+ import { Fr } from '@aztec/circuits.js';
2
+ import { AuthWitness, CompleteAddress, FunctionCall, TxExecutionRequest } from '@aztec/types';
3
+
4
+ // docs:start:account-interface
5
+ /** Creates authorization witnesses. */
6
+ export interface AuthWitnessProvider {
7
+ /**
8
+ * Create an authorization witness for the given message.
9
+ * @param message - Message to authorize.
10
+ */
11
+ createAuthWitness(message: Fr): Promise<AuthWitness>;
12
+ }
13
+
14
+ /** Creates transaction execution requests out of a set of function calls. */
15
+ export interface EntrypointInterface {
16
+ /**
17
+ * Generates an authenticated request out of set of function calls.
18
+ * @param executions - The execution intents to be run.
19
+ * @param opts - Options.
20
+ * @returns The authenticated transaction execution request.
21
+ */
22
+ createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest>;
23
+ }
24
+
25
+ /**
26
+ * Handler for interfacing with an account. Knows how to create transaction execution
27
+ * requests and authorize actions for its corresponding account.
28
+ */
29
+ export interface AccountInterface extends AuthWitnessProvider, EntrypointInterface {
30
+ /**
31
+ * Returns the complete address for this account.
32
+ */
33
+ getCompleteAddress(): CompleteAddress;
34
+ }
35
+ // docs:end:account-interface
@@ -1,7 +1,7 @@
1
1
  import { FieldsOf } from '@aztec/circuits.js';
2
2
  import { TxHash, TxReceipt } from '@aztec/types';
3
3
 
4
- import { SentTx, WaitOpts, Wallet } from '../index.js';
4
+ import { SentTx, WaitOpts, Wallet } from '../../index.js';
5
5
 
6
6
  /** Extends a transaction receipt with a wallet instance for the newly deployed contract. */
7
7
  export type DeployAccountTxReceipt = FieldsOf<TxReceipt> & {
@@ -1,15 +1,16 @@
1
1
  import { Fr, PublicKey, getContractDeploymentInfo } from '@aztec/circuits.js';
2
2
  import { AztecRPC, CompleteAddress, GrumpkinPrivateKey } from '@aztec/types';
3
3
 
4
- import { AccountWallet, ContractDeployer, DeployMethod, WaitOpts, generatePublicKey } from '../index.js';
4
+ import { AccountWallet, ContractDeployer, DeployMethod, WaitOpts, generatePublicKey } from '../../index.js';
5
+ import { AccountContract, Salt } from '../index.js';
6
+ import { AccountInterface } from '../interface.js';
5
7
  import { DeployAccountSentTx } from './deploy_account_sent_tx.js';
6
- import { AccountContract, Entrypoint, Salt } from './index.js';
7
8
 
8
9
  /**
9
10
  * Manages a user account. Provides methods for calculating the account's address, deploying the account contract,
10
11
  * and creating and registering the user wallet in the RPC server.
11
12
  */
12
- export class Account {
13
+ export class AccountManager {
13
14
  /** Deployment salt for the account contract. */
14
15
  public readonly salt?: Fr;
15
16
 
@@ -41,10 +42,10 @@ export class Account {
41
42
  * Returns the entrypoint for this account as defined by its account contract.
42
43
  * @returns An entrypoint.
43
44
  */
44
- public async getEntrypoint(): Promise<Entrypoint> {
45
+ public async getAccount(): Promise<AccountInterface> {
45
46
  const nodeInfo = await this.rpc.getNodeInfo();
46
47
  const completeAddress = await this.getCompleteAddress();
47
- return this.accountContract.getEntrypoint(completeAddress, nodeInfo);
48
+ return this.accountContract.getInterface(completeAddress, nodeInfo);
48
49
  }
49
50
 
50
51
  /**
@@ -72,8 +73,8 @@ export class Account {
72
73
  * @returns A Wallet instance.
73
74
  */
74
75
  public async getWallet(): Promise<AccountWallet> {
75
- const entrypoint = await this.getEntrypoint();
76
- return new AccountWallet(this.rpc, entrypoint, await this.getCompleteAddress());
76
+ const entrypoint = await this.getAccount();
77
+ return new AccountWallet(this.rpc, entrypoint);
77
78
  }
78
79
 
79
80
  /**
@@ -1,6 +1,7 @@
1
1
  import { AztecAddress, CompleteAddress, EthAddress, Fr, GrumpkinScalar, Point } from '@aztec/circuits.js';
2
- import { createJsonRpcClient, defaultFetch } from '@aztec/foundation/json-rpc/client';
2
+ import { createJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client';
3
3
  import {
4
+ AuthWitness,
4
5
  AztecRPC,
5
6
  ContractData,
6
7
  ExtendedContractData,
@@ -14,7 +15,7 @@ import {
14
15
 
15
16
  export { makeFetch } from '@aztec/foundation/json-rpc/client';
16
17
 
17
- export const createAztecRpcClient = (url: string, fetch = defaultFetch): AztecRPC =>
18
+ export const createAztecRpcClient = (url: string, fetch = makeFetch([1, 2, 3], true)): AztecRPC =>
18
19
  createJsonRpcClient<AztecRPC>(
19
20
  url,
20
21
  {
@@ -29,6 +30,7 @@ export const createAztecRpcClient = (url: string, fetch = defaultFetch): AztecRP
29
30
  Fr,
30
31
  GrumpkinScalar,
31
32
  NotePreimage,
33
+ AuthWitness,
32
34
  },
33
35
  { Tx, TxReceipt, L2BlockL2Logs },
34
36
  false,
@@ -14,7 +14,7 @@ import {
14
14
 
15
15
  import { MockProxy, mock } from 'jest-mock-extended';
16
16
 
17
- import { Wallet } from '../aztec_rpc_client/wallet.js';
17
+ import { Wallet } from '../wallet/index.js';
18
18
  import { Contract } from './contract.js';
19
19
 
20
20
  describe('Contract Class', () => {
@@ -28,7 +28,13 @@ describe('Contract Class', () => {
28
28
  const mockTxHash = { type: 'TxHash' } as any as TxHash;
29
29
  const mockTxReceipt = { type: 'TxReceipt' } as any as TxReceipt;
30
30
  const mockViewResultValue = 1;
31
- const mockNodeInfo: NodeInfo = { version: 1, chainId: 2, rollupAddress: EthAddress.random(), client: '' };
31
+ const mockNodeInfo: NodeInfo = {
32
+ version: 1,
33
+ chainId: 2,
34
+ rollupAddress: EthAddress.random(),
35
+ client: '',
36
+ compatibleNargoVersion: 'vx.x.x-aztec.x',
37
+ };
32
38
 
33
39
  const defaultAbi: ContractAbi = {
34
40
  name: 'FooContract',
@@ -102,7 +108,7 @@ describe('Contract Class', () => {
102
108
  wallet.getTxReceipt.mockResolvedValue(mockTxReceipt);
103
109
  wallet.getNodeInfo.mockResolvedValue(mockNodeInfo);
104
110
  wallet.simulateTx.mockResolvedValue(mockTx);
105
- wallet.getAccounts.mockResolvedValue([account]);
111
+ wallet.getRegisteredAccounts.mockResolvedValue([account]);
106
112
  });
107
113
 
108
114
  it('should create and send a contract method tx', async () => {
@@ -2,8 +2,8 @@ import { ContractAbi } from '@aztec/foundation/abi';
2
2
  import { AztecAddress } from '@aztec/foundation/aztec-address';
3
3
  import { PublicKey } from '@aztec/types';
4
4
 
5
- import { Wallet } from '../aztec_rpc_client/wallet.js';
6
5
  import { DeployMethod, Point } from '../index.js';
6
+ import { Wallet } from '../wallet/index.js';
7
7
  import { ContractBase } from './contract_base.js';
8
8
 
9
9
  /**
@@ -2,7 +2,7 @@ import { ContractAbi, FunctionAbi, FunctionSelector } from '@aztec/foundation/ab
2
2
  import { EthAddress } from '@aztec/foundation/eth-address';
3
3
  import { CompleteAddress, DeployedContract } from '@aztec/types';
4
4
 
5
- import { Wallet } from '../aztec_rpc_client/wallet.js';
5
+ import { Wallet } from '../wallet/index.js';
6
6
  import { ContractFunctionInteraction } from './contract_function_interaction.js';
7
7
 
8
8
  /**
@@ -1,8 +1,8 @@
1
1
  import { AztecAddress, FunctionData } from '@aztec/circuits.js';
2
- import { FunctionAbi, FunctionType, encodeArguments } from '@aztec/foundation/abi';
2
+ import { FunctionAbiHeader, FunctionType, encodeArguments } from '@aztec/foundation/abi';
3
3
  import { FunctionCall, TxExecutionRequest } from '@aztec/types';
4
4
 
5
- import { Wallet } from '../aztec_rpc_client/wallet.js';
5
+ import { Wallet } from '../wallet/index.js';
6
6
  import { BaseContractInteraction, SendMethodOptions } from './base_contract_interaction.js';
7
7
 
8
8
  export { SendMethodOptions };
@@ -26,7 +26,7 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
26
26
  constructor(
27
27
  protected wallet: Wallet,
28
28
  protected contractAddress: AztecAddress,
29
- protected functionDao: FunctionAbi,
29
+ protected functionDao: FunctionAbiHeader,
30
30
  protected args: any[],
31
31
  ) {
32
32
  super(wallet);
@@ -89,6 +89,7 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
89
89
  argsHash: packedArguments.hash,
90
90
  txContext,
91
91
  packedArguments: [packedArguments],
92
+ authWitnesses: [],
92
93
  });
93
94
 
94
95
  this.txRequest = txRequest;