@aztec/aztec.js 0.1.0-alpha42 → 0.1.0-alpha44

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 (40) hide show
  1. package/.tsbuildinfo +1 -1
  2. package/README.md +7 -7
  3. package/dest/abis/ecdsa_account_contract.json +26084 -3
  4. package/dest/abis/schnorr_account_contract.json +20750 -3
  5. package/dest/abis/schnorr_single_key_account_contract.json +19848 -1
  6. package/dest/account/account.js +2 -2
  7. package/dest/account/contract/ecdsa_account_contract.js +1 -1
  8. package/dest/account/contract/schnorr_account_contract.js +1 -1
  9. package/dest/account/contract/single_key_account_contract.js +1 -1
  10. package/dest/aztec_rpc_client/aztec_rpc_client.d.ts +1 -2
  11. package/dest/aztec_rpc_client/aztec_rpc_client.d.ts.map +1 -1
  12. package/dest/aztec_rpc_client/aztec_rpc_client.js +2 -3
  13. package/dest/aztec_rpc_client/wallet.d.ts +2 -2
  14. package/dest/aztec_rpc_client/wallet.d.ts.map +1 -1
  15. package/dest/aztec_rpc_client/wallet.js +3 -3
  16. package/dest/contract/sent_tx.d.ts +3 -0
  17. package/dest/contract/sent_tx.d.ts.map +1 -1
  18. package/dest/contract/sent_tx.js +4 -1
  19. package/dest/main.js +1 -1
  20. package/dest/sandbox/index.d.ts +7423 -0
  21. package/dest/sandbox/index.d.ts.map +1 -1
  22. package/dest/sandbox/index.js +1 -1
  23. package/dest/utils/account.js +2 -2
  24. package/dest/utils/cheat_codes.d.ts +26 -26
  25. package/dest/utils/cheat_codes.d.ts.map +1 -1
  26. package/dest/utils/cheat_codes.js +39 -39
  27. package/package.json +4 -4
  28. package/src/abis/ecdsa_account_contract.json +26084 -3
  29. package/src/abis/schnorr_account_contract.json +20750 -3
  30. package/src/abis/schnorr_single_key_account_contract.json +19848 -1
  31. package/src/account/account.ts +1 -1
  32. package/src/account/contract/ecdsa_account_contract.ts +1 -1
  33. package/src/account/contract/schnorr_account_contract.ts +1 -1
  34. package/src/account/contract/single_key_account_contract.ts +1 -1
  35. package/src/aztec_rpc_client/aztec_rpc_client.ts +1 -2
  36. package/src/aztec_rpc_client/wallet.ts +3 -3
  37. package/src/contract/sent_tx.ts +3 -0
  38. package/src/sandbox/index.ts +1 -1
  39. package/src/utils/account.ts +1 -1
  40. package/src/utils/cheat_codes.ts +35 -35
@@ -84,7 +84,7 @@ export class Account {
84
84
  */
85
85
  public async register(): Promise<AccountWallet> {
86
86
  const completeAddress = await this.getCompleteAddress();
87
- await this.rpc.registerAccount(this.encryptionPrivateKey, completeAddress);
87
+ await this.rpc.registerAccount(this.encryptionPrivateKey, completeAddress.partialAddress);
88
88
  return this.getWallet();
89
89
  }
90
90
 
@@ -22,6 +22,6 @@ import { AccountContract } from './index.js';
22
22
  }
23
23
 
24
24
  public getContractAbi(): ContractAbi {
25
- return EcdsaAccountContractAbi as ContractAbi;
25
+ return EcdsaAccountContractAbi as unknown as ContractAbi;
26
26
  }
27
27
  }
@@ -23,6 +23,6 @@ export class SchnorrAccountContract implements AccountContract {
23
23
  }
24
24
 
25
25
  public getContractAbi(): ContractAbi {
26
- return SchnorrAccountContractAbi as ContractAbi;
26
+ return SchnorrAccountContractAbi as unknown as ContractAbi;
27
27
  }
28
28
  }
@@ -29,6 +29,6 @@ export class SingleKeyAccountContract implements AccountContract {
29
29
  }
30
30
 
31
31
  public getContractAbi(): ContractAbi {
32
- return SchnorrSingleKeyAccountContractAbi as ContractAbi;
32
+ return SchnorrSingleKeyAccountContractAbi as unknown as ContractAbi;
33
33
  }
34
34
  }
@@ -12,8 +12,7 @@ import {
12
12
  TxReceipt,
13
13
  } from '@aztec/types';
14
14
 
15
- export { mustSucceedFetch } from '@aztec/foundation/json-rpc/client';
16
- export { mustSucceedFetchUnlessNoRetry } from '@aztec/foundation/json-rpc/client';
15
+ export { makeFetch } from '@aztec/foundation/json-rpc/client';
17
16
 
18
17
  export const createAztecRpcClient = (url: string, fetch = defaultFetch): AztecRPC =>
19
18
  createJsonRpcClient<AztecRPC>(
@@ -1,4 +1,4 @@
1
- import { AztecAddress, CircuitsWasm, Fr, PrivateKey, TxContext } from '@aztec/circuits.js';
1
+ import { AztecAddress, CircuitsWasm, Fr, PartialAddress, PrivateKey, TxContext } from '@aztec/circuits.js';
2
2
  import {
3
3
  AztecRPC,
4
4
  ContractData,
@@ -31,8 +31,8 @@ export abstract class BaseWallet implements Wallet {
31
31
 
32
32
  abstract createTxExecutionRequest(execs: FunctionCall[], opts?: CreateTxRequestOpts): Promise<TxExecutionRequest>;
33
33
 
34
- registerAccount(privKey: PrivateKey, completeAddress: CompleteAddress): Promise<void> {
35
- return this.rpc.registerAccount(privKey, completeAddress);
34
+ registerAccount(privKey: PrivateKey, partialAddress: PartialAddress): Promise<void> {
35
+ return this.rpc.registerAccount(privKey, partialAddress);
36
36
  }
37
37
  registerRecipient(account: CompleteAddress): Promise<void> {
38
38
  return this.rpc.registerRecipient(account);
@@ -69,6 +69,9 @@ export class SentTx {
69
69
  * Resolves to true if the transaction status is 'MINED', false otherwise.
70
70
  * Throws an error if the transaction receipt cannot be fetched after the given timeout.
71
71
  *
72
+ * @deprecated Use wait() instead as it throws if the tx is not mined,
73
+ * while this would silently fail if the return value isn't checked explicitly.
74
+ *
72
75
  * @param opts - Options for configuring the waiting for the tx to be mined.
73
76
  * @returns A Promise that resolves to a boolean indicating if the transaction is mined or not.
74
77
  */
@@ -25,7 +25,7 @@ export const INITIAL_SANDBOX_ACCOUNT_CONTRACT_ABI = SchnorrAccountContractAbi;
25
25
  export async function getSandboxAccountsWallet(aztecRpc: AztecRPC) {
26
26
  return await getAccountWallets(
27
27
  aztecRpc,
28
- INITIAL_SANDBOX_ACCOUNT_CONTRACT_ABI as ContractAbi,
28
+ INITIAL_SANDBOX_ACCOUNT_CONTRACT_ABI as unknown as ContractAbi,
29
29
  INITIAL_SANDBOX_ENCRYPTION_KEYS,
30
30
  INITIAL_SANDBOX_SIGNING_KEYS,
31
31
  INITIAL_SANDBOX_SALTS,
@@ -27,7 +27,7 @@ export async function createAccounts(
27
27
  const privKey = i == 0 && privateKey ? privateKey : PrivateKey.random();
28
28
  const publicKey = await generatePublicKey(privKey);
29
29
  const deploymentInfo = await getContractDeploymentInfo(accountContractAbi, [], salt, publicKey);
30
- await aztecRpcClient.registerAccount(privKey, deploymentInfo.completeAddress);
30
+ await aztecRpcClient.registerAccount(privKey, deploymentInfo.completeAddress.partialAddress);
31
31
  const contractDeployer = new ContractDeployer(accountContractAbi, aztecRpcClient, publicKey);
32
32
  const tx = contractDeployer.deploy().send({ contractAddressSalt: salt });
33
33
  await tx.isMined({ interval: 0.5 });
@@ -17,35 +17,35 @@ const toFr = (value: Fr | bigint): Fr => {
17
17
  export class CheatCodes {
18
18
  constructor(
19
19
  /**
20
- * The L1 cheat codes.
20
+ * The cheat codes for ethereum (L1).
21
21
  */
22
- public l1: L1CheatCodes,
22
+ public eth: EthCheatCodes,
23
23
  /**
24
- * The L2 cheat codes.
24
+ * The cheat codes for aztec.
25
25
  */
26
- public l2: L2CheatCodes,
26
+ public aztec: AztecCheatCodes,
27
27
  ) {}
28
28
 
29
29
  static async create(rpcUrl: string, aztecRpc: AztecRPC): Promise<CheatCodes> {
30
- const l1CheatCodes = new L1CheatCodes(rpcUrl);
31
- const l2CheatCodes = new L2CheatCodes(aztecRpc, await CircuitsWasm.get(), l1CheatCodes);
32
- return new CheatCodes(l1CheatCodes, l2CheatCodes);
30
+ const ethCheatCodes = new EthCheatCodes(rpcUrl);
31
+ const aztecCheatCodes = new AztecCheatCodes(aztecRpc, await CircuitsWasm.get(), ethCheatCodes);
32
+ return new CheatCodes(ethCheatCodes, aztecCheatCodes);
33
33
  }
34
34
  }
35
35
 
36
36
  /**
37
- * A class that provides utility functions for interacting with the L1 chain.
37
+ * A class that provides utility functions for interacting with ethereum (L1).
38
38
  */
39
- export class L1CheatCodes {
39
+ export class EthCheatCodes {
40
40
  constructor(
41
41
  /**
42
42
  * The RPC client to use for interacting with the chain
43
43
  */
44
44
  public rpcUrl: string,
45
45
  /**
46
- * The logger to use for the l1 cheatcodes
46
+ * The logger to use for the eth cheatcodes
47
47
  */
48
- public logger = createDebugLogger('aztec:cheat_codes:l1'),
48
+ public logger = createDebugLogger('aztec:cheat_codes:eth'),
49
49
  ) {}
50
50
 
51
51
  async rpcCall(method: string, params: any[]) {
@@ -91,7 +91,7 @@ export class L1CheatCodes {
91
91
  * @returns The current chainId
92
92
  */
93
93
  public async mine(numberOfBlocks = 1): Promise<void> {
94
- const res = await this.rpcCall('anvil_mine', [numberOfBlocks]);
94
+ const res = await this.rpcCall('hardhat_mine', [numberOfBlocks]);
95
95
  if (res.error) throw new Error(`Error mining: ${res.error.message}`);
96
96
  this.logger(`Mined ${numberOfBlocks} blocks`);
97
97
  }
@@ -101,7 +101,7 @@ export class L1CheatCodes {
101
101
  * @param timestamp - The timestamp to set the next block to
102
102
  */
103
103
  public async setNextBlockTimestamp(timestamp: number): Promise<void> {
104
- const res = await this.rpcCall('anvil_setNextBlockTimestamp', [timestamp]);
104
+ const res = await this.rpcCall('evm_setNextBlockTimestamp', [timestamp]);
105
105
  if (res.error) throw new Error(`Error setting next block timestamp: ${res.error.message}`);
106
106
  this.logger(`Set next block timestamp to ${timestamp}`);
107
107
  }
@@ -111,7 +111,7 @@ export class L1CheatCodes {
111
111
  * @param fileName - The file name to dump state into
112
112
  */
113
113
  public async dumpChainState(fileName: string): Promise<void> {
114
- const res = await this.rpcCall('anvil_dumpState', []);
114
+ const res = await this.rpcCall('hardhat_dumpState', []);
115
115
  if (res.error) throw new Error(`Error dumping state: ${res.error.message}`);
116
116
  const jsonContent = JSON.stringify(res.result);
117
117
  fs.writeFileSync(`${fileName}.json`, jsonContent, 'utf8');
@@ -124,13 +124,13 @@ export class L1CheatCodes {
124
124
  */
125
125
  public async loadChainState(fileName: string): Promise<void> {
126
126
  const data = JSON.parse(fs.readFileSync(`${fileName}.json`, 'utf8'));
127
- const res = await this.rpcCall('anvil_loadState', [data]);
127
+ const res = await this.rpcCall('hardhat_loadState', [data]);
128
128
  if (res.error) throw new Error(`Error loading state: ${res.error.message}`);
129
129
  this.logger(`Loaded state from ${fileName}`);
130
130
  }
131
131
 
132
132
  /**
133
- * Load the value at a storage slot of a contract address on L1
133
+ * Load the value at a storage slot of a contract address on eth
134
134
  * @param contract - The contract address
135
135
  * @param slot - The storage slot
136
136
  * @returns - The value at the storage slot
@@ -141,14 +141,14 @@ export class L1CheatCodes {
141
141
  }
142
142
 
143
143
  /**
144
- * Set the value at a storage slot of a contract address on L1
144
+ * Set the value at a storage slot of a contract address on eth
145
145
  * @param contract - The contract address
146
146
  * @param slot - The storage slot
147
147
  * @param value - The value to set the storage slot to
148
148
  */
149
149
  public async store(contract: EthAddress, slot: bigint, value: bigint): Promise<void> {
150
150
  // for the rpc call, we need to change value to be a 32 byte hex string.
151
- const res = await this.rpcCall('anvil_setStorageAt', [contract.toString(), toHex(slot), toHex(value, true)]);
151
+ const res = await this.rpcCall('hardhat_setStorageAt', [contract.toString(), toHex(slot), toHex(value, true)]);
152
152
  if (res.error) throw new Error(`Error setting storage for contract ${contract} at ${slot}: ${res.error.message}`);
153
153
  this.logger(`Set storage for contract ${contract} at ${slot} to ${value}`);
154
154
  }
@@ -169,9 +169,9 @@ export class L1CheatCodes {
169
169
  * Send transactions impersonating an externally owned account or contract.
170
170
  * @param who - The address to impersonate
171
171
  */
172
- public async startPrank(who: EthAddress): Promise<void> {
173
- const res = await this.rpcCall('anvil_impersonateAccount', [who.toString()]);
174
- if (res.error) throw new Error(`Error pranking ${who}: ${res.error.message}`);
172
+ public async startImpersonating(who: EthAddress): Promise<void> {
173
+ const res = await this.rpcCall('hardhat_impersonateAccount', [who.toString()]);
174
+ if (res.error) throw new Error(`Error impersonating ${who}: ${res.error.message}`);
175
175
  this.logger(`Impersonating ${who}`);
176
176
  }
177
177
 
@@ -179,9 +179,9 @@ export class L1CheatCodes {
179
179
  * Stop impersonating an account that you are currently impersonating.
180
180
  * @param who - The address to stop impersonating
181
181
  */
182
- public async stopPrank(who: EthAddress): Promise<void> {
183
- const res = await this.rpcCall('anvil_stopImpersonatingAccount', [who.toString()]);
184
- if (res.error) throw new Error(`Error pranking ${who}: ${res.error.message}`);
182
+ public async stopImpersonating(who: EthAddress): Promise<void> {
183
+ const res = await this.rpcCall('hardhat_stopImpersonatingAccount', [who.toString()]);
184
+ if (res.error) throw new Error(`Error when stopping the impersonation of ${who}: ${res.error.message}`);
185
185
  this.logger(`Stopped impersonating ${who}`);
186
186
  }
187
187
 
@@ -191,7 +191,7 @@ export class L1CheatCodes {
191
191
  * @param bytecode - The bytecode to set
192
192
  */
193
193
  public async etch(contract: EthAddress, bytecode: `0x${string}`): Promise<void> {
194
- const res = await this.rpcCall('anvil_setCode', [contract.toString(), bytecode]);
194
+ const res = await this.rpcCall('hardhat_setCode', [contract.toString(), bytecode]);
195
195
  if (res.error) throw new Error(`Error setting bytecode for ${contract}: ${res.error.message}`);
196
196
  this.logger(`Set bytecode for ${contract} to ${bytecode}`);
197
197
  }
@@ -208,9 +208,9 @@ export class L1CheatCodes {
208
208
  }
209
209
 
210
210
  /**
211
- * A class that provides utility functions for interacting with the L2 chain.
211
+ * A class that provides utility functions for interacting with the aztec chain.
212
212
  */
213
- export class L2CheatCodes {
213
+ export class AztecCheatCodes {
214
214
  constructor(
215
215
  /**
216
216
  * The RPC client to use for interacting with the chain
@@ -221,13 +221,13 @@ export class L2CheatCodes {
221
221
  */
222
222
  public wasm: CircuitsWasm,
223
223
  /**
224
- * The L1 cheat codes.
224
+ * The eth cheat codes.
225
225
  */
226
- public l1: L1CheatCodes,
226
+ public eth: EthCheatCodes,
227
227
  /**
228
- * The logger to use for the l2 cheatcodes
228
+ * The logger to use for the aztec cheatcodes
229
229
  */
230
- public logger = createDebugLogger('aztec:cheat_codes:l2'),
230
+ public logger = createDebugLogger('aztec:cheat_codes:aztec'),
231
231
  ) {}
232
232
 
233
233
  /**
@@ -256,16 +256,16 @@ export class L2CheatCodes {
256
256
  }
257
257
 
258
258
  /**
259
- * Set time of the next execution on L2.
260
- * It also modifies time on L1 for next execution and stores this time as the last rollup block on the rollup contract.
259
+ * Set time of the next execution on aztec.
260
+ * It also modifies time on eth for next execution and stores this time as the last rollup block on the rollup contract.
261
261
  * @param to - The timestamp to set the next block to (must be greater than current time)
262
262
  */
263
263
  public async warp(to: number): Promise<void> {
264
264
  const rollupContract = (await this.aztecRpc.getNodeInfo()).rollupAddress;
265
- await this.l1.setNextBlockTimestamp(to);
265
+ await this.eth.setNextBlockTimestamp(to);
266
266
  // also store this time on the rollup contract (slot 1 tracks `lastBlockTs`).
267
267
  // This is because when the sequencer executes public functions, it uses the timestamp stored in the rollup contract.
268
- await this.l1.store(rollupContract, 1n, BigInt(to));
268
+ await this.eth.store(rollupContract, 1n, BigInt(to));
269
269
  }
270
270
 
271
271
  /**