@aztec/aztec.js 0.14.1 → 0.14.2

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.
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.14.1",
4
+ "version": "0.14.2",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  "node": "./dest/index.js",
@@ -38,10 +38,10 @@
38
38
  "rootDir": "./src"
39
39
  },
40
40
  "dependencies": {
41
- "@aztec/circuits.js": "0.14.1",
42
- "@aztec/ethereum": "0.14.1",
43
- "@aztec/foundation": "0.14.1",
44
- "@aztec/types": "0.14.1",
41
+ "@aztec/circuits.js": "0.14.2",
42
+ "@aztec/ethereum": "0.14.2",
43
+ "@aztec/foundation": "0.14.2",
44
+ "@aztec/types": "0.14.2",
45
45
  "lodash.every": "^4.6.0",
46
46
  "lodash.partition": "^4.6.0",
47
47
  "lodash.zip": "^4.2.0",
@@ -1,7 +1,9 @@
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 { DefaultWaitOpts, SentTx, WaitOpts } from '../../contract/sent_tx.js';
5
+ import { Wallet } from '../../wallet/index.js';
6
+ import { waitForAccountSynch } from './util.js';
5
7
 
6
8
  /** Extends a transaction receipt with a wallet instance for the newly deployed contract. */
7
9
  export type DeployAccountTxReceipt = FieldsOf<TxReceipt> & {
@@ -32,8 +34,9 @@ export class DeployAccountSentTx extends SentTx {
32
34
  * @param opts - Options for configuring the waiting for the tx to be mined.
33
35
  * @returns The transaction receipt with the wallet for the deployed account contract.
34
36
  */
35
- public async wait(opts?: WaitOpts): Promise<DeployAccountTxReceipt> {
37
+ public async wait(opts: WaitOpts = DefaultWaitOpts): Promise<DeployAccountTxReceipt> {
36
38
  const receipt = await super.wait(opts);
39
+ await waitForAccountSynch(this.pxe, this.wallet.getCompleteAddress(), opts);
37
40
  return { ...receipt, wallet: this.wallet };
38
41
  }
39
42
  }
@@ -2,6 +2,7 @@ import { PublicKey, getContractDeploymentInfo } from '@aztec/circuits.js';
2
2
  import { Fr } from '@aztec/foundation/fields';
3
3
  import { CompleteAddress, GrumpkinPrivateKey, PXE } from '@aztec/types';
4
4
 
5
+ import { DefaultWaitOpts } from '../../contract/sent_tx.js';
5
6
  import {
6
7
  AccountWalletWithPrivateKey,
7
8
  ContractDeployer,
@@ -12,6 +13,7 @@ import {
12
13
  import { AccountContract, Salt } from '../index.js';
13
14
  import { AccountInterface } from '../interface.js';
14
15
  import { DeployAccountSentTx } from './deploy_account_sent_tx.js';
16
+ import { waitForAccountSynch } from './util.js';
15
17
 
16
18
  /**
17
19
  * Manages a user account. Provides methods for calculating the account's address, deploying the account contract,
@@ -88,11 +90,12 @@ export class AccountManager {
88
90
  * Registers this account in the PXE Service and returns the associated wallet. Registering
89
91
  * the account on the PXE Service is required for managing private state associated with it.
90
92
  * Use the returned wallet to create Contract instances to be interacted with from this account.
93
+ * @param opts - Options to wait for the account to be synched.
91
94
  * @returns A Wallet instance.
92
95
  */
93
- public async register(): Promise<AccountWalletWithPrivateKey> {
94
- const completeAddress = await this.getCompleteAddress();
95
- await this.pxe.registerAccount(this.encryptionPrivateKey, completeAddress.partialAddress);
96
+ public async register(opts: WaitOpts = DefaultWaitOpts): Promise<AccountWalletWithPrivateKey> {
97
+ const address = await this.#register();
98
+ await waitForAccountSynch(this.pxe, address, opts);
96
99
  return this.getWallet();
97
100
  }
98
101
 
@@ -105,7 +108,7 @@ export class AccountManager {
105
108
  public async getDeployMethod() {
106
109
  if (!this.deployMethod) {
107
110
  if (!this.salt) throw new Error(`Cannot deploy account contract without known salt.`);
108
- await this.register();
111
+ await this.#register();
109
112
  const encryptionPublicKey = await this.getEncryptionPublicKey();
110
113
  const deployer = new ContractDeployer(this.accountContract.getContractArtifact(), this.pxe, encryptionPublicKey);
111
114
  const args = await this.accountContract.getDeploymentArgs();
@@ -138,8 +141,14 @@ export class AccountManager {
138
141
  * @param opts - Options to wait for the tx to be mined.
139
142
  * @returns A Wallet instance.
140
143
  */
141
- public async waitDeploy(opts: WaitOpts = {}): Promise<AccountWalletWithPrivateKey> {
144
+ public async waitDeploy(opts: WaitOpts = DefaultWaitOpts): Promise<AccountWalletWithPrivateKey> {
142
145
  await this.deploy().then(tx => tx.wait(opts));
143
146
  return this.getWallet();
144
147
  }
148
+
149
+ async #register(): Promise<CompleteAddress> {
150
+ const completeAddress = await this.getCompleteAddress();
151
+ await this.pxe.registerAccount(this.encryptionPrivateKey, completeAddress.partialAddress);
152
+ return completeAddress;
153
+ }
145
154
  }
@@ -0,0 +1,29 @@
1
+ import { CompleteAddress, PXE, WaitOpts, retryUntil } from '../../index.js';
2
+
3
+ /**
4
+ * Waits for the account to finish synchronizing with the PXE Service.
5
+ * @param pxe - PXE instance
6
+ * @param address - Address to wait for synch
7
+ * @param opts - Wait options
8
+ */
9
+ export async function waitForAccountSynch(
10
+ pxe: PXE,
11
+ address: CompleteAddress,
12
+ { interval, timeout }: WaitOpts,
13
+ ): Promise<void> {
14
+ const publicKey = address.publicKey.toString();
15
+ await retryUntil(
16
+ async () => {
17
+ const status = await pxe.getSyncStatus();
18
+ const accountSynchedToBlock = status.notes[publicKey];
19
+ if (typeof accountSynchedToBlock === 'undefined') {
20
+ return false;
21
+ } else {
22
+ return accountSynchedToBlock >= status.blocks;
23
+ }
24
+ },
25
+ 'waitForAccountSynch',
26
+ timeout,
27
+ interval,
28
+ );
29
+ }
@@ -37,6 +37,6 @@
37
37
  */
38
38
  export * from './contract.js';
39
39
  export * from './contract_function_interaction.js';
40
- export * from './sent_tx.js';
40
+ export { SentTx, WaitOpts } from './sent_tx.js';
41
41
  export * from './contract_base.js';
42
42
  export * from './batch_call.js';
@@ -19,7 +19,7 @@ export type WaitOpts = {
19
19
  debug?: boolean;
20
20
  };
21
21
 
22
- const DefaultWaitOpts: WaitOpts = {
22
+ export const DefaultWaitOpts: WaitOpts = {
23
23
  timeout: 60,
24
24
  interval: 1,
25
25
  waitForNotesSync: true,