@aztec/aztec.js 0.81.0 → 0.82.1-alpha-testnet.1

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 (192) hide show
  1. package/dest/account/{contract.d.ts → account_contract.d.ts} +3 -2
  2. package/dest/account/account_contract.d.ts.map +1 -0
  3. package/dest/account/index.d.ts +2 -3
  4. package/dest/account/index.d.ts.map +1 -1
  5. package/dest/account/index.js +1 -2
  6. package/dest/account/interface.d.ts +1 -13
  7. package/dest/account/interface.d.ts.map +1 -1
  8. package/dest/account/interface.js +1 -0
  9. package/dest/account_manager/account_manager.d.ts +106 -0
  10. package/dest/account_manager/account_manager.d.ts.map +1 -0
  11. package/dest/account_manager/account_manager.js +216 -0
  12. package/dest/account_manager/deploy_account_sent_tx.d.ts +3 -3
  13. package/dest/account_manager/deploy_account_sent_tx.d.ts.map +1 -1
  14. package/dest/account_manager/deploy_account_sent_tx.js +2 -2
  15. package/dest/account_manager/index.d.ts +1 -105
  16. package/dest/account_manager/index.d.ts.map +1 -1
  17. package/dest/account_manager/index.js +1 -166
  18. package/dest/api/account.d.ts +2 -1
  19. package/dest/api/account.d.ts.map +1 -1
  20. package/dest/api/contract.d.ts +4 -1
  21. package/dest/api/contract.d.ts.map +1 -1
  22. package/dest/api/contract.js +3 -0
  23. package/dest/api/fee.d.ts +2 -1
  24. package/dest/api/fee.d.ts.map +1 -1
  25. package/dest/api/fee.js +1 -0
  26. package/dest/api/fee_testing.d.ts +2 -0
  27. package/dest/api/fee_testing.d.ts.map +1 -0
  28. package/dest/api/fee_testing.js +1 -0
  29. package/dest/api/utils.d.ts +2 -1
  30. package/dest/api/utils.d.ts.map +1 -1
  31. package/dest/api/utils.js +2 -1
  32. package/dest/api/wallet.d.ts +1 -1
  33. package/dest/api/wallet.d.ts.map +1 -1
  34. package/dest/contract/base_contract_interaction.d.ts +22 -57
  35. package/dest/contract/base_contract_interaction.d.ts.map +1 -1
  36. package/dest/contract/base_contract_interaction.js +12 -67
  37. package/dest/contract/batch_call.d.ts +6 -18
  38. package/dest/contract/batch_call.d.ts.map +1 -1
  39. package/dest/contract/batch_call.js +25 -54
  40. package/dest/contract/contract.d.ts +1 -1
  41. package/dest/contract/contract.d.ts.map +1 -1
  42. package/dest/contract/contract_base.d.ts +1 -1
  43. package/dest/contract/contract_base.d.ts.map +1 -1
  44. package/dest/contract/contract_function_interaction.d.ts +38 -18
  45. package/dest/contract/contract_function_interaction.d.ts.map +1 -1
  46. package/dest/contract/contract_function_interaction.js +34 -41
  47. package/dest/contract/deploy_method.d.ts +7 -8
  48. package/dest/contract/deploy_method.d.ts.map +1 -1
  49. package/dest/contract/deploy_method.js +27 -32
  50. package/dest/contract/deploy_proven_tx.d.ts +2 -3
  51. package/dest/contract/deploy_proven_tx.d.ts.map +1 -1
  52. package/dest/contract/deploy_proven_tx.js +1 -1
  53. package/dest/contract/deploy_sent_tx.d.ts +2 -3
  54. package/dest/contract/deploy_sent_tx.d.ts.map +1 -1
  55. package/dest/contract/deploy_sent_tx.js +4 -4
  56. package/dest/contract/protocol_contracts.d.ts +1 -1
  57. package/dest/contract/protocol_contracts.d.ts.map +1 -1
  58. package/dest/contract/proven_tx.d.ts +3 -5
  59. package/dest/contract/proven_tx.d.ts.map +1 -1
  60. package/dest/contract/proven_tx.js +2 -6
  61. package/dest/contract/sent_tx.d.ts +4 -16
  62. package/dest/contract/sent_tx.d.ts.map +1 -1
  63. package/dest/contract/sent_tx.js +6 -37
  64. package/dest/contract/unsafe_contract.d.ts +1 -1
  65. package/dest/contract/unsafe_contract.d.ts.map +1 -1
  66. package/dest/contract/wait_for_proven.d.ts +17 -0
  67. package/dest/contract/wait_for_proven.d.ts.map +1 -0
  68. package/dest/contract/wait_for_proven.js +17 -0
  69. package/dest/deployment/broadcast_function.js +12 -8
  70. package/dest/deployment/contract_deployer.d.ts +1 -1
  71. package/dest/deployment/contract_deployer.d.ts.map +1 -1
  72. package/dest/deployment/register_class.d.ts +1 -1
  73. package/dest/deployment/register_class.d.ts.map +1 -1
  74. package/dest/deployment/register_class.js +6 -11
  75. package/dest/ethereum/portal_manager.d.ts +20 -11
  76. package/dest/ethereum/portal_manager.d.ts.map +1 -1
  77. package/dest/ethereum/portal_manager.js +64 -30
  78. package/dest/fee/account_entrypoint_meta_payment_method.d.ts +31 -0
  79. package/dest/fee/account_entrypoint_meta_payment_method.d.ts.map +1 -0
  80. package/dest/fee/account_entrypoint_meta_payment_method.js +64 -0
  81. package/dest/fee/fee_juice_payment_method.d.ts +3 -3
  82. package/dest/fee/fee_juice_payment_method.d.ts.map +1 -1
  83. package/dest/fee/fee_juice_payment_method.js +3 -2
  84. package/dest/fee/fee_juice_payment_method_with_claim.d.ts +4 -4
  85. package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -1
  86. package/dest/fee/fee_juice_payment_method_with_claim.js +6 -5
  87. package/dest/fee/private_fee_payment_method.d.ts +6 -6
  88. package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
  89. package/dest/fee/private_fee_payment_method.js +13 -12
  90. package/dest/fee/public_fee_payment_method.d.ts +7 -7
  91. package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
  92. package/dest/fee/public_fee_payment_method.js +10 -11
  93. package/dest/fee/sponsored_fee_payment.d.ts +15 -0
  94. package/dest/fee/sponsored_fee_payment.d.ts.map +1 -0
  95. package/dest/fee/sponsored_fee_payment.js +30 -0
  96. package/dest/fee/utils.d.ts +13 -0
  97. package/dest/fee/utils.d.ts.map +1 -0
  98. package/dest/fee/utils.js +32 -0
  99. package/dest/utils/authwit.d.ts +16 -9
  100. package/dest/utils/authwit.d.ts.map +1 -1
  101. package/dest/utils/authwit.js +27 -36
  102. package/dest/wallet/account_wallet.d.ts +6 -6
  103. package/dest/wallet/account_wallet.d.ts.map +1 -1
  104. package/dest/wallet/account_wallet.js +15 -17
  105. package/dest/wallet/base_wallet.d.ts +12 -35
  106. package/dest/wallet/base_wallet.d.ts.map +1 -1
  107. package/dest/wallet/base_wallet.js +11 -64
  108. package/dest/wallet/index.d.ts +2 -2
  109. package/dest/wallet/index.d.ts.map +1 -1
  110. package/dest/wallet/index.js +1 -1
  111. package/dest/wallet/signerless_wallet.d.ts +3 -3
  112. package/dest/wallet/signerless_wallet.d.ts.map +1 -1
  113. package/dest/wallet/signerless_wallet.js +3 -6
  114. package/dest/wallet/wallet.d.ts +11 -0
  115. package/dest/wallet/wallet.d.ts.map +1 -0
  116. package/package.json +10 -8
  117. package/src/account/{contract.ts → account_contract.ts} +2 -1
  118. package/src/account/index.ts +2 -3
  119. package/src/account/interface.ts +1 -12
  120. package/src/account_manager/account_manager.ts +294 -0
  121. package/src/account_manager/deploy_account_sent_tx.ts +4 -4
  122. package/src/account_manager/index.ts +1 -237
  123. package/src/api/account.ts +2 -8
  124. package/src/api/contract.ts +5 -5
  125. package/src/api/fee.ts +2 -1
  126. package/src/api/fee_testing.ts +1 -0
  127. package/src/api/utils.ts +1 -1
  128. package/src/api/wallet.ts +7 -1
  129. package/src/contract/base_contract_interaction.ts +32 -88
  130. package/src/contract/batch_call.ts +40 -43
  131. package/src/contract/contract.ts +1 -1
  132. package/src/contract/contract_base.ts +1 -1
  133. package/src/contract/contract_function_interaction.ts +85 -56
  134. package/src/contract/deploy_method.ts +24 -26
  135. package/src/contract/deploy_proven_tx.ts +3 -4
  136. package/src/contract/deploy_sent_tx.ts +6 -6
  137. package/src/contract/protocol_contracts.ts +1 -1
  138. package/src/contract/proven_tx.ts +4 -22
  139. package/src/contract/sent_tx.ts +6 -47
  140. package/src/contract/unsafe_contract.ts +1 -1
  141. package/src/contract/wait_for_proven.ts +38 -0
  142. package/src/deployment/broadcast_function.ts +40 -40
  143. package/src/deployment/contract_deployer.ts +1 -1
  144. package/src/deployment/register_class.ts +9 -22
  145. package/src/ethereum/portal_manager.ts +73 -24
  146. package/src/fee/account_entrypoint_meta_payment_method.ts +90 -0
  147. package/src/fee/fee_juice_payment_method.ts +4 -5
  148. package/src/fee/fee_juice_payment_method_with_claim.ts +24 -20
  149. package/src/fee/private_fee_payment_method.ts +29 -28
  150. package/src/fee/public_fee_payment_method.ts +29 -29
  151. package/src/fee/sponsored_fee_payment.ts +38 -0
  152. package/src/fee/utils.ts +39 -0
  153. package/src/utils/authwit.ts +26 -37
  154. package/src/wallet/account_wallet.ts +18 -17
  155. package/src/wallet/base_wallet.ts +27 -88
  156. package/src/wallet/index.ts +2 -2
  157. package/src/wallet/signerless_wallet.ts +9 -8
  158. package/src/wallet/wallet.ts +34 -0
  159. package/dest/account/contract.d.ts.map +0 -1
  160. package/dest/account/wallet.d.ts +0 -11
  161. package/dest/account/wallet.d.ts.map +0 -1
  162. package/dest/account_manager/deploy_account_method.d.ts +0 -15
  163. package/dest/account_manager/deploy_account_method.d.ts.map +0 -1
  164. package/dest/account_manager/deploy_account_method.js +0 -36
  165. package/dest/api/entrypoint.d.ts +0 -2
  166. package/dest/api/entrypoint.d.ts.map +0 -1
  167. package/dest/api/entrypoint.js +0 -1
  168. package/dest/entrypoint/default_entrypoint.d.ts +0 -12
  169. package/dest/entrypoint/default_entrypoint.d.ts.map +0 -1
  170. package/dest/entrypoint/default_entrypoint.js +0 -28
  171. package/dest/entrypoint/default_multi_call_entrypoint.d.ts +0 -15
  172. package/dest/entrypoint/default_multi_call_entrypoint.d.ts.map +0 -1
  173. package/dest/entrypoint/default_multi_call_entrypoint.js +0 -130
  174. package/dest/entrypoint/entrypoint.d.ts +0 -39
  175. package/dest/entrypoint/entrypoint.d.ts.map +0 -1
  176. package/dest/entrypoint/entrypoint.js +0 -20
  177. package/dest/entrypoint/payload.d.ts +0 -128
  178. package/dest/entrypoint/payload.d.ts.map +0 -1
  179. package/dest/entrypoint/payload.js +0 -143
  180. package/dest/fee/fee_payment_method.d.ts +0 -22
  181. package/dest/fee/fee_payment_method.d.ts.map +0 -1
  182. package/dest/fee/fee_payment_method.js +0 -3
  183. package/src/account/wallet.ts +0 -13
  184. package/src/account_manager/deploy_account_method.ts +0 -67
  185. package/src/api/entrypoint.ts +0 -1
  186. package/src/entrypoint/default_entrypoint.ts +0 -39
  187. package/src/entrypoint/default_multi_call_entrypoint.ts +0 -93
  188. package/src/entrypoint/entrypoint.ts +0 -60
  189. package/src/entrypoint/payload.ts +0 -238
  190. package/src/fee/fee_payment_method.ts +0 -22
  191. /package/dest/account/{contract.js → account_contract.js} +0 -0
  192. /package/dest/{account → wallet}/wallet.js +0 -0
@@ -1,4 +1,4 @@
1
- import { DefaultEntrypoint } from '../entrypoint/default_entrypoint.js';
1
+ import { DefaultEntrypoint } from '@aztec/entrypoints/default';
2
2
  import { BaseWallet } from './base_wallet.js';
3
3
  /**
4
4
  * Wallet implementation which creates a transaction request directly to the requested contract without any signing.
@@ -7,13 +7,13 @@ import { BaseWallet } from './base_wallet.js';
7
7
  constructor(pxe, entrypoint){
8
8
  super(pxe), this.entrypoint = entrypoint;
9
9
  }
10
- async createTxExecutionRequest(execution) {
10
+ async createTxExecutionRequest(execution, fee, options) {
11
11
  let entrypoint = this.entrypoint;
12
12
  if (!entrypoint) {
13
13
  const { l1ChainId: chainId, protocolVersion } = await this.pxe.getNodeInfo();
14
14
  entrypoint = new DefaultEntrypoint(chainId, protocolVersion);
15
15
  }
16
- return entrypoint.createTxExecutionRequest(execution);
16
+ return entrypoint.createTxExecutionRequest(execution, fee, options);
17
17
  }
18
18
  getChainId() {
19
19
  throw new Error('SignerlessWallet: Method getChainId not implemented.');
@@ -30,7 +30,4 @@ import { BaseWallet } from './base_wallet.js';
30
30
  createAuthWit(_intent) {
31
31
  throw new Error('SignerlessWallet: Method createAuthWit not implemented.');
32
32
  }
33
- isL1ToL2MessageSynced(l1ToL2Message) {
34
- return this.pxe.isL1ToL2MessageSynced(l1ToL2Message);
35
- }
36
33
  }
@@ -0,0 +1,11 @@
1
+ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
2
+ import type { PXE } from '@aztec/stdlib/interfaces/client';
3
+ import type { AccountInterface } from '../account/interface.js';
4
+ import type { IntentAction, IntentInnerHash } from '../utils/authwit.js';
5
+ /**
6
+ * The wallet interface.
7
+ */
8
+ export type Wallet = AccountInterface & Pick<PXE, 'simulateTx' | 'simulateUnconstrained' | 'profileTx' | 'sendTx' | 'getContractClassMetadata' | 'getContractMetadata' | 'registerContract' | 'registerContractClass' | 'proveTx' | 'getNodeInfo' | 'getPXEInfo' | 'getCurrentBaseFees' | 'updateContract' | 'registerSender' | 'getSenders' | 'removeSender' | 'getTxReceipt' | 'getPrivateEvents' | 'getPublicEvents'> & {
9
+ createAuthWit(intent: IntentInnerHash | IntentAction): Promise<AuthWitness>;
10
+ };
11
+ //# sourceMappingURL=wallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/wallet/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAC;AAE3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,gBAAgB,GACnC,IAAI,CACF,GAAG,EACD,YAAY,GACZ,uBAAuB,GACvB,WAAW,GACX,QAAQ,GACR,0BAA0B,GAC1B,qBAAqB,GACrB,kBAAkB,GAClB,uBAAuB,GACvB,SAAS,GACT,aAAa,GACb,YAAY,GACZ,oBAAoB,GACpB,gBAAgB,GAChB,gBAAgB,GAChB,YAAY,GACZ,cAAc,GACd,cAAc,GACd,kBAAkB,GAClB,iBAAiB,CACpB,GAAG;IACF,aAAa,CAAC,MAAM,EAAE,eAAe,GAAG,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CAC7E,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aztec/aztec.js",
3
3
  "homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/aztec.js",
4
- "version": "0.81.0",
4
+ "version": "0.82.1-alpha-testnet.1",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": "./dest/index.js",
@@ -23,7 +23,8 @@
23
23
  "./tx_hash": "./dest/api/tx_hash.js",
24
24
  "./wallet": "./dest/api/wallet.js",
25
25
  "./utils": "./dest/api/utils.js",
26
- "./testing": "./dest/api/testing.js"
26
+ "./testing": "./dest/api/testing.js",
27
+ "./fee/testing": "./dest/api/fee_testing.js"
27
28
  },
28
29
  "typedocOptions": {
29
30
  "entryPoints": [
@@ -79,12 +80,13 @@
79
80
  ]
80
81
  },
81
82
  "dependencies": {
82
- "@aztec/constants": "0.81.0",
83
- "@aztec/ethereum": "0.81.0",
84
- "@aztec/foundation": "0.81.0",
85
- "@aztec/l1-artifacts": "0.81.0",
86
- "@aztec/protocol-contracts": "0.81.0",
87
- "@aztec/stdlib": "0.81.0",
83
+ "@aztec/constants": "0.82.1-alpha-testnet.1",
84
+ "@aztec/entrypoints": "0.82.1-alpha-testnet.1",
85
+ "@aztec/ethereum": "0.82.1-alpha-testnet.1",
86
+ "@aztec/foundation": "0.82.1-alpha-testnet.1",
87
+ "@aztec/l1-artifacts": "0.82.1-alpha-testnet.1",
88
+ "@aztec/protocol-contracts": "0.82.1-alpha-testnet.1",
89
+ "@aztec/stdlib": "0.82.1-alpha-testnet.1",
88
90
  "axios": "^1.7.2",
89
91
  "tslib": "^2.4.0",
90
92
  "viem": "2.23.7"
@@ -1,10 +1,11 @@
1
+ import type { AuthWitnessProvider } from '@aztec/entrypoints/interfaces';
1
2
  import { Fr } from '@aztec/foundation/fields';
2
3
  import type { ContractArtifact } from '@aztec/stdlib/abi';
3
4
  import type { CompleteAddress, NodeInfo } from '@aztec/stdlib/contract';
4
5
  import { getContractInstanceFromDeployParams } from '@aztec/stdlib/contract';
5
6
  import { deriveKeys } from '@aztec/stdlib/keys';
6
7
 
7
- import type { AccountInterface, AuthWitnessProvider } from './interface.js';
8
+ import type { AccountInterface } from './interface.js';
8
9
 
9
10
  // docs:start:account-contract-interface
10
11
  /**
@@ -8,9 +8,8 @@
8
8
  */
9
9
  import type { Fr } from '@aztec/foundation/fields';
10
10
 
11
- export { type AccountContract, getAccountContractAddress } from './contract.js';
12
- export { type AccountInterface, type AuthWitnessProvider } from './interface.js';
13
- export * from './wallet.js';
11
+ export { type AccountContract, getAccountContractAddress } from './account_contract.js';
12
+ export { type AccountInterface } from './interface.js';
14
13
 
15
14
  /** A contract deployment salt. */
16
15
  export type Salt = Fr | number | bigint;
@@ -1,20 +1,9 @@
1
+ import type { AuthWitnessProvider, EntrypointInterface } from '@aztec/entrypoints/interfaces';
1
2
  import type { Fr } from '@aztec/foundation/fields';
2
- import type { AuthWitness } from '@aztec/stdlib/auth-witness';
3
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import type { CompleteAddress } from '@aztec/stdlib/contract';
5
5
 
6
- import type { EntrypointInterface } from '../entrypoint/entrypoint.js';
7
-
8
6
  // docs:start:account-interface
9
- /** Creates authorization witnesses. */
10
- export interface AuthWitnessProvider {
11
- /**
12
- * Computes an authentication witness from either a message hash
13
- * @param messageHash - The message hash to approve
14
- * @returns The authentication witness
15
- */
16
- createAuthWit(messageHash: Fr | Buffer): Promise<AuthWitness>;
17
- }
18
7
 
19
8
  /**
20
9
  * Handler for interfacing with an account. Knows how to create transaction execution
@@ -0,0 +1,294 @@
1
+ import { DefaultMultiCallEntrypoint } from '@aztec/entrypoints/multicall';
2
+ import { Fr } from '@aztec/foundation/fields';
3
+ import { CompleteAddress, type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
4
+ import { getContractInstanceFromDeployParams } from '@aztec/stdlib/contract';
5
+ import type { GasSettings } from '@aztec/stdlib/gas';
6
+ import type { PXE } from '@aztec/stdlib/interfaces/client';
7
+ import { deriveKeys } from '@aztec/stdlib/keys';
8
+
9
+ import type { AccountContract } from '../account/account_contract.js';
10
+ import type { Salt } from '../account/index.js';
11
+ import type { AccountInterface } from '../account/interface.js';
12
+ import { Contract } from '../contract/contract.js';
13
+ import { DeployMethod, type DeployOptions } from '../contract/deploy_method.js';
14
+ import { DefaultWaitOpts, type WaitOpts } from '../contract/sent_tx.js';
15
+ import { AccountEntrypointMetaPaymentMethod } from '../fee/account_entrypoint_meta_payment_method.js';
16
+ import { FeeJuicePaymentMethod, type FeePaymentMethod } from '../index.js';
17
+ import { AccountWalletWithSecretKey, SignerlessWallet, type Wallet } from '../wallet/index.js';
18
+ import { DeployAccountSentTx } from './deploy_account_sent_tx.js';
19
+
20
+ /**
21
+ * Options to deploy an account contract.
22
+ */
23
+ export type DeployAccountOptions = Pick<
24
+ DeployOptions,
25
+ 'fee' | 'skipClassRegistration' | 'skipPublicDeployment' | 'skipInitialization'
26
+ > & {
27
+ /**
28
+ * Wallet used for deploying the account contract. Must be funded in order to pay for the fee.
29
+ */
30
+ deployWallet?: Wallet;
31
+ };
32
+
33
+ /**
34
+ * Manages a user account. Provides methods for calculating the account's address, deploying the account contract,
35
+ * and creating and registering the user wallet in the PXE Service.
36
+ */
37
+ export class AccountManager {
38
+ private constructor(
39
+ private pxe: PXE,
40
+ private secretKey: Fr,
41
+ private accountContract: AccountContract,
42
+ private instance: ContractInstanceWithAddress,
43
+ /**
44
+ * Deployment salt for the account contract
45
+ */
46
+ public readonly salt: Salt,
47
+ ) {}
48
+
49
+ static async create(pxe: PXE, secretKey: Fr, accountContract: AccountContract, salt?: Salt) {
50
+ const { publicKeys } = await deriveKeys(secretKey);
51
+ salt = salt !== undefined ? new Fr(salt) : Fr.random();
52
+
53
+ const { constructorName, constructorArgs } = (await accountContract.getDeploymentFunctionAndArgs()) ?? {
54
+ constructorName: undefined,
55
+ constructorArgs: undefined,
56
+ };
57
+
58
+ const artifact = await accountContract.getContractArtifact();
59
+ const instance = await getContractInstanceFromDeployParams(artifact, {
60
+ constructorArtifact: constructorName,
61
+ constructorArgs,
62
+ salt: salt,
63
+ publicKeys,
64
+ });
65
+
66
+ return new AccountManager(pxe, secretKey, accountContract, instance, salt);
67
+ }
68
+
69
+ protected getPublicKeys() {
70
+ return this.instance.publicKeys;
71
+ }
72
+
73
+ protected getPublicKeysHash() {
74
+ return this.getPublicKeys().hash();
75
+ }
76
+
77
+ /**
78
+ * Returns the entrypoint for this account as defined by its account contract.
79
+ * @returns An entrypoint.
80
+ */
81
+ public async getAccount(): Promise<AccountInterface> {
82
+ const nodeInfo = await this.pxe.getNodeInfo();
83
+ const completeAddress = await this.getCompleteAddress();
84
+ return this.accountContract.getInterface(completeAddress, nodeInfo);
85
+ }
86
+
87
+ /**
88
+ * Gets the calculated complete address associated with this account.
89
+ * Does not require the account to be deployed or registered.
90
+ * @returns The address, partial address, and encryption public key.
91
+ */
92
+ public getCompleteAddress(): Promise<CompleteAddress> {
93
+ return CompleteAddress.fromSecretKeyAndInstance(this.secretKey, this.instance);
94
+ }
95
+
96
+ /**
97
+ * Gets the address for this given account.
98
+ * Does not require the account to be deployed or registered.
99
+ * @returns The address.
100
+ */
101
+ public getAddress() {
102
+ return this.instance.address;
103
+ }
104
+
105
+ /**
106
+ * Returns the contract instance definition associated with this account.
107
+ * Does not require the account to be deployed or registered.
108
+ * @returns ContractInstance instance.
109
+ */
110
+ public getInstance(): ContractInstanceWithAddress {
111
+ return this.instance;
112
+ }
113
+
114
+ /**
115
+ * Returns a Wallet instance associated with this account. Use it to create Contract
116
+ * instances to be interacted with from this account.
117
+ * @returns A Wallet instance.
118
+ */
119
+ public async getWallet(): Promise<AccountWalletWithSecretKey> {
120
+ const entrypoint = await this.getAccount();
121
+ return new AccountWalletWithSecretKey(this.pxe, entrypoint, this.secretKey, this.salt);
122
+ }
123
+
124
+ /**
125
+ * Registers this account in the PXE Service and returns the associated wallet. Registering
126
+ * the account on the PXE Service is required for managing private state associated with it.
127
+ * Use the returned wallet to create Contract instances to be interacted with from this account.
128
+ * @param opts - Options to wait for the account to be synched.
129
+ * @returns A Wallet instance.
130
+ */
131
+ public async register(): Promise<AccountWalletWithSecretKey> {
132
+ await this.pxe.registerContract({
133
+ artifact: await this.accountContract.getContractArtifact(),
134
+ instance: this.getInstance(),
135
+ });
136
+
137
+ await this.pxe.registerAccount(this.secretKey, (await this.getCompleteAddress()).partialAddress);
138
+
139
+ return this.getWallet();
140
+ }
141
+
142
+ /**
143
+ * Returns the pre-populated deployment method to deploy the account contract that backs this account.
144
+ * If no wallet is provided, it uses a signerless wallet with the multi call entrypoint
145
+ * @param deployWallet - Wallet used for deploying the account contract.
146
+ * @returns A DeployMethod instance that deploys this account contract
147
+ */
148
+ async #getDeployMethod(deployWallet?: Wallet): Promise<DeployMethod> {
149
+ const artifact = await this.accountContract.getContractArtifact();
150
+
151
+ if (!(await this.isDeployable())) {
152
+ throw new Error(`Account contract ${artifact.name} does not require deployment.`);
153
+ }
154
+
155
+ const completeAddress = await this.getCompleteAddress();
156
+
157
+ await this.pxe.registerAccount(this.secretKey, completeAddress.partialAddress);
158
+
159
+ const { constructorName, constructorArgs } = (await this.accountContract.getDeploymentFunctionAndArgs()) ?? {
160
+ constructorName: undefined,
161
+ constructorArgs: undefined,
162
+ };
163
+
164
+ if (deployWallet) {
165
+ // If deploying using an existing wallet/account, treat it like regular contract deployment.
166
+ const thisWallet = await this.getWallet();
167
+ return new DeployMethod(
168
+ this.getPublicKeys(),
169
+ deployWallet,
170
+ artifact,
171
+ address => Contract.at(address, artifact, thisWallet),
172
+ constructorArgs,
173
+ constructorName,
174
+ );
175
+ }
176
+
177
+ const { l1ChainId: chainId, protocolVersion } = await this.pxe.getNodeInfo();
178
+ // We use a signerless wallet with the multi call entrypoint in order to make multiple calls in one go.
179
+ // If we used getWallet, the deployment would get routed via the account contract entrypoint
180
+ // and it can't be used unless the contract is initialized.
181
+ const wallet = new SignerlessWallet(this.pxe, new DefaultMultiCallEntrypoint(chainId, protocolVersion));
182
+
183
+ return new DeployMethod(
184
+ this.getPublicKeys(),
185
+ wallet,
186
+ artifact,
187
+ address => Contract.at(address, artifact, wallet),
188
+ constructorArgs,
189
+ constructorName,
190
+ );
191
+ }
192
+
193
+ /**
194
+ * Returns a FeePaymentMethod that routes the original one provided as an argument
195
+ * through the account's entrypoint. This allows an account contract to pay
196
+ * for its own deployment and initialization.
197
+ *
198
+ * For more details on how the fee payment routing works see documentation of AccountEntrypointMetaPaymentMethod class.
199
+ *
200
+ * @param originalPaymentMethod - originalPaymentMethod The original payment method to be wrapped.
201
+ * @returns A FeePaymentMethod that routes the original one through the account's entrypoint (AccountEntrypointMetaPaymentMethod)
202
+ */
203
+ async #getSelfPaymentMethod(originalPaymentMethod?: FeePaymentMethod) {
204
+ const artifact = await this.accountContract.getContractArtifact();
205
+ const wallet = await this.getWallet();
206
+ const address = wallet.getAddress();
207
+ return new AccountEntrypointMetaPaymentMethod(
208
+ artifact,
209
+ wallet,
210
+ 'entrypoint',
211
+ address,
212
+ originalPaymentMethod ?? new FeeJuicePaymentMethod(address),
213
+ );
214
+ }
215
+
216
+ /**
217
+ * Deploys the account contract that backs this account.
218
+ * Does not register the associated class nor publicly deploy the instance by default.
219
+ * Uses the salt provided in the constructor or a randomly generated one.
220
+ * Registers the account in the PXE Service before deploying the contract.
221
+ * @param opts - Fee options to be used for the deployment.
222
+ * @returns A SentTx object that can be waited to get the associated Wallet.
223
+ */
224
+ public deploy(opts?: DeployAccountOptions): DeployAccountSentTx {
225
+ let deployMethod: DeployMethod;
226
+ const sentTx = this.#getDeployMethod(opts?.deployWallet)
227
+ .then(method => {
228
+ deployMethod = method;
229
+ if (!opts?.deployWallet && opts?.fee) {
230
+ return this.#getSelfPaymentMethod(opts?.fee?.paymentMethod);
231
+ }
232
+ })
233
+ .then(maybeWrappedPaymentMethod => {
234
+ let fee = opts?.fee;
235
+ if (maybeWrappedPaymentMethod) {
236
+ fee = { ...opts?.fee, paymentMethod: maybeWrappedPaymentMethod };
237
+ }
238
+ return deployMethod.send({
239
+ contractAddressSalt: new Fr(this.salt),
240
+ skipClassRegistration: opts?.skipClassRegistration ?? true,
241
+ skipPublicDeployment: opts?.skipPublicDeployment ?? true,
242
+ skipInitialization: opts?.skipInitialization ?? false,
243
+ universalDeploy: true,
244
+ fee,
245
+ });
246
+ })
247
+ .then(tx => tx.getTxHash());
248
+ return new DeployAccountSentTx(this.pxe, sentTx, this.getWallet());
249
+ }
250
+
251
+ /**
252
+ * Estimates the gas needed to deploy the account contract that backs this account.
253
+ * This method is here to ensure that the fee payment method is correctly set up in case
254
+ * the account contract needs to pay for its own deployment.
255
+ * @param opts - Fee options to be used for the deployment.
256
+ * @returns The gas estimations for the account contract deployment and initialization.
257
+ */
258
+ public async estimateDeploymentGas(
259
+ opts?: DeployAccountOptions,
260
+ ): Promise<Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>> {
261
+ const deployMethod = await this.#getDeployMethod(opts?.deployWallet);
262
+ const fee =
263
+ !opts?.deployWallet && opts?.fee
264
+ ? { ...opts.fee, paymentMethod: await this.#getSelfPaymentMethod(opts.fee.paymentMethod) }
265
+ : opts?.fee;
266
+ return deployMethod.estimateGas({
267
+ contractAddressSalt: new Fr(this.salt),
268
+ skipClassRegistration: opts?.skipClassRegistration ?? true,
269
+ skipPublicDeployment: opts?.skipPublicDeployment ?? true,
270
+ skipInitialization: opts?.skipInitialization ?? false,
271
+ universalDeploy: true,
272
+ fee,
273
+ });
274
+ }
275
+
276
+ /**
277
+ * Deploys the account contract that backs this account if needed and awaits the tx to be mined.
278
+ * Uses the salt provided in the constructor or a randomly generated one. If no initialization
279
+ * is required it skips the transaction, and only registers the account in the PXE Service.
280
+ * @param opts - Options to wait for the tx to be mined.
281
+ * @returns A Wallet instance.
282
+ */
283
+ public async waitSetup(opts: DeployAccountOptions & WaitOpts = DefaultWaitOpts): Promise<AccountWalletWithSecretKey> {
284
+ await ((await this.isDeployable()) ? this.deploy(opts).wait(opts) : this.register());
285
+ return this.getWallet();
286
+ }
287
+
288
+ /**
289
+ * Returns whether this account contract has a constructor and needs deployment.
290
+ */
291
+ public async isDeployable() {
292
+ return (await this.accountContract.getDeploymentFunctionAndArgs()) !== undefined;
293
+ }
294
+ }
@@ -1,9 +1,9 @@
1
1
  import type { FieldsOf } from '@aztec/foundation/types';
2
- import type { PXE } from '@aztec/stdlib/interfaces/client';
2
+ import type { AztecNode, PXE } from '@aztec/stdlib/interfaces/client';
3
3
  import type { TxHash, TxReceipt } from '@aztec/stdlib/tx';
4
4
 
5
- import type { Wallet } from '../account/index.js';
6
5
  import { DefaultWaitOpts, SentTx, type WaitOpts } from '../contract/sent_tx.js';
6
+ import type { Wallet } from '../wallet/wallet.js';
7
7
 
8
8
  /** Extends a transaction receipt with a wallet instance for the newly deployed contract. */
9
9
  export type DeployAccountTxReceipt = FieldsOf<TxReceipt> & {
@@ -15,8 +15,8 @@ export type DeployAccountTxReceipt = FieldsOf<TxReceipt> & {
15
15
  * A deployment transaction for an account contract sent to the network, extending SentTx with methods to get the resulting wallet.
16
16
  */
17
17
  export class DeployAccountSentTx extends SentTx {
18
- constructor(pxe: PXE, txHashPromise: Promise<TxHash>, private getWalletPromise: Promise<Wallet>) {
19
- super(pxe, txHashPromise);
18
+ constructor(pxeOrNode: AztecNode | PXE, txHashPromise: Promise<TxHash>, private getWalletPromise: Promise<Wallet>) {
19
+ super(pxeOrNode, txHashPromise);
20
20
  }
21
21
 
22
22
  /**