@aztec/aztec.js 0.1.0-alpha24 → 0.1.0-alpha26

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 (36) hide show
  1. package/.tsbuildinfo +1 -1
  2. package/dest/abis/ecdsa_account_contract.json +47 -0
  3. package/dest/abis/schnorr_single_key_account_contract.json +96 -0
  4. package/dest/account_impl/single_key_account_contract.d.ts.map +1 -1
  5. package/dest/account_impl/single_key_account_contract.js +4 -4
  6. package/dest/account_impl/stored_key_account_contract.d.ts +1 -0
  7. package/dest/account_impl/stored_key_account_contract.d.ts.map +1 -1
  8. package/dest/account_impl/stored_key_account_contract.js +5 -2
  9. package/dest/aztec_rpc_client/aztec_rpc_client.d.ts +2 -1
  10. package/dest/aztec_rpc_client/aztec_rpc_client.d.ts.map +1 -1
  11. package/dest/aztec_rpc_client/aztec_rpc_client.js +5 -5
  12. package/dest/aztec_rpc_client/wallet.d.ts +7 -4
  13. package/dest/aztec_rpc_client/wallet.d.ts.map +1 -1
  14. package/dest/aztec_rpc_client/wallet.js +17 -5
  15. package/dest/contract/contract.d.ts +2 -3
  16. package/dest/contract/contract.d.ts.map +1 -1
  17. package/dest/contract/contract.js +1 -1
  18. package/dest/contract_deployer/contract_deployer.d.ts.map +1 -1
  19. package/dest/contract_deployer/contract_deployer.js +2 -1
  20. package/dest/contract_deployer/deploy_method.js +2 -2
  21. package/dest/utils/account.js +2 -2
  22. package/dest/utils/l1_contracts.d.ts +8 -0
  23. package/dest/utils/l1_contracts.d.ts.map +1 -1
  24. package/dest/utils/l1_contracts.js +10 -2
  25. package/package.json +5 -4
  26. package/src/abis/ecdsa_account_contract.json +47 -0
  27. package/src/abis/schnorr_single_key_account_contract.json +96 -0
  28. package/src/account_impl/single_key_account_contract.ts +5 -4
  29. package/src/account_impl/stored_key_account_contract.ts +11 -4
  30. package/src/aztec_rpc_client/aztec_rpc_client.ts +5 -3
  31. package/src/aztec_rpc_client/wallet.ts +20 -10
  32. package/src/contract/contract.ts +2 -2
  33. package/src/contract_deployer/contract_deployer.ts +1 -0
  34. package/src/contract_deployer/deploy_method.ts +2 -2
  35. package/src/utils/account.ts +1 -1
  36. package/src/utils/l1_contracts.ts +21 -1
@@ -0,0 +1,96 @@
1
+ {
2
+ "name": "SchnorrSingleKeyAccount",
3
+ "functions": [
4
+ {
5
+ "name": "constructor",
6
+ "functionType": "secret",
7
+ "parameters": [],
8
+ "returnTypes": []
9
+ },
10
+ {
11
+ "name": "entrypoint",
12
+ "functionType": "secret",
13
+ "parameters": [
14
+ {
15
+ "name": "payload",
16
+ "type": {
17
+ "kind": "struct",
18
+ "fields": [
19
+ {
20
+ "name": "flattened_args_hashes",
21
+ "type": {
22
+ "kind": "array",
23
+ "length": 2,
24
+ "type": {
25
+ "kind": "field"
26
+ }
27
+ }
28
+ },
29
+ {
30
+ "name": "flattened_selectors",
31
+ "type": {
32
+ "kind": "array",
33
+ "length": 2,
34
+ "type": {
35
+ "kind": "field"
36
+ }
37
+ }
38
+ },
39
+ {
40
+ "name": "flattened_targets",
41
+ "type": {
42
+ "kind": "array",
43
+ "length": 2,
44
+ "type": {
45
+ "kind": "field"
46
+ }
47
+ }
48
+ },
49
+ {
50
+ "name": "nonce",
51
+ "type": {
52
+ "kind": "field"
53
+ }
54
+ }
55
+ ]
56
+ },
57
+ "visibility": "public"
58
+ },
59
+ {
60
+ "name": "owner",
61
+ "type": {
62
+ "kind": "array",
63
+ "length": 64,
64
+ "type": {
65
+ "kind": "integer",
66
+ "sign": "unsigned",
67
+ "width": 8
68
+ }
69
+ },
70
+ "visibility": "public"
71
+ },
72
+ {
73
+ "name": "signature",
74
+ "type": {
75
+ "kind": "array",
76
+ "length": 64,
77
+ "type": {
78
+ "kind": "integer",
79
+ "sign": "unsigned",
80
+ "width": 8
81
+ }
82
+ },
83
+ "visibility": "public"
84
+ },
85
+ {
86
+ "name": "partial_address",
87
+ "type": {
88
+ "kind": "field"
89
+ },
90
+ "visibility": "public"
91
+ }
92
+ ],
93
+ "returnTypes": []
94
+ }
95
+ ]
96
+ }
@@ -2,13 +2,14 @@ import { AztecAddress, CircuitsWasm, FunctionData, PartialContractAddress, TxCon
2
2
  import { Signer } from '@aztec/circuits.js/barretenberg';
3
3
  import { ContractAbi, encodeArguments, generateFunctionSelector } from '@aztec/foundation/abi';
4
4
  import { ExecutionRequest, PackedArguments, TxExecutionRequest } from '@aztec/types';
5
+
5
6
  import partition from 'lodash.partition';
7
+
8
+ import SchnorrSingleKeyAccountContractAbi from '../abis/schnorr_account_contract.json' assert { type: 'json' };
6
9
  import { generatePublicKey } from '../index.js';
7
10
  import { buildPayload, hashPayload } from './entrypoint_payload.js';
8
11
  import { AccountImplementation } from './index.js';
9
12
 
10
- import SchnorrAccountContractAbi from '../abis/schnorr_account_contract.json' assert { type: 'json' };
11
-
12
13
  /**
13
14
  * Account contract implementation that uses a single key for signing and encryption. This public key is not
14
15
  * stored in the contract, but rather verified against the contract address. Note that this approach is not
@@ -56,10 +57,10 @@ export class SingleKeyAccountContract implements AccountImplementation {
56
57
  }
57
58
 
58
59
  private getEntrypointAbi() {
59
- // We use the SchnorrAccountContract because it implements the interface we need, but ideally
60
+ // We use the SchnorrSingleKeyAccountContract because it implements the interface we need, but ideally
60
61
  // we should have an interface that defines the entrypoint for SingleKeyAccountContracts and
61
62
  // load the abi from it.
62
- const abi = (SchnorrAccountContractAbi as any as ContractAbi).functions.find(f => f.name === 'entrypoint');
63
+ const abi = (SchnorrSingleKeyAccountContractAbi as any as ContractAbi).functions.find(f => f.name === 'entrypoint');
63
64
  if (!abi) throw new Error(`Entrypoint abi for account contract not found`);
64
65
  return abi;
65
66
  }
@@ -1,19 +1,25 @@
1
1
  import { AztecAddress, CircuitsWasm, FunctionData, TxContext } from '@aztec/circuits.js';
2
2
  import { Signer } from '@aztec/circuits.js/barretenberg';
3
3
  import { ContractAbi, encodeArguments, generateFunctionSelector } from '@aztec/foundation/abi';
4
+ import { DebugLogger, createDebugLogger } from '@aztec/foundation/log';
4
5
  import { ExecutionRequest, PackedArguments, TxExecutionRequest } from '@aztec/types';
6
+
5
7
  import partition from 'lodash.partition';
6
- import { buildPayload, hashPayload } from './entrypoint_payload.js';
7
- import { AccountImplementation } from './index.js';
8
8
 
9
9
  import EcdsaAccountContractAbi from '../abis/ecdsa_account_contract.json' assert { type: 'json' };
10
+ import { buildPayload, hashPayload } from './entrypoint_payload.js';
11
+ import { AccountImplementation } from './index.js';
10
12
 
11
13
  /**
12
14
  * Account contract implementation that keeps a signing public key in storage, and is retrieved on
13
15
  * every new request in order to validate the payload signature.
14
16
  */
15
17
  export class StoredKeyAccountContract implements AccountImplementation {
16
- constructor(private address: AztecAddress, private privateKey: Buffer, private signer: Signer) {}
18
+ private log: DebugLogger;
19
+
20
+ constructor(private address: AztecAddress, private privateKey: Buffer, private signer: Signer) {
21
+ this.log = createDebugLogger('aztec:client:accounts:stored_key');
22
+ }
17
23
 
18
24
  getAddress(): AztecAddress {
19
25
  return this.address;
@@ -30,8 +36,9 @@ export class StoredKeyAccountContract implements AccountImplementation {
30
36
  const wasm = await CircuitsWasm.get();
31
37
  const { payload, packedArguments: callsPackedArguments } = await buildPayload(privateCalls, publicCalls);
32
38
  const hash = hashPayload(payload);
33
-
34
39
  const signature = this.signer.constructSignature(hash, this.privateKey).toBuffer();
40
+ this.log(`Signed challenge ${hash.toString('hex')} as ${signature.toString('hex')}`);
41
+
35
42
  const args = [payload, signature];
36
43
  const abi = this.getEntrypointAbi();
37
44
  const selector = generateFunctionSelector(abi.name, abi.parameters);
@@ -1,5 +1,5 @@
1
1
  import { AztecAddress, EthAddress, Fr, Point } from '@aztec/circuits.js';
2
- import { createJsonRpcClient } from '@aztec/foundation/json-rpc';
2
+ import { createJsonRpcClient, defaultFetch } from '@aztec/foundation/json-rpc';
3
3
  import {
4
4
  AztecRPC,
5
5
  ContractData,
@@ -8,9 +8,10 @@ import {
8
8
  Tx,
9
9
  TxExecutionRequest,
10
10
  TxHash,
11
+ TxReceipt,
11
12
  } from '@aztec/types';
12
13
 
13
- export const createAztecRpcClient = (url: string): AztecRPC =>
14
+ export const createAztecRpcClient = (url: string, fetch = defaultFetch): AztecRPC =>
14
15
  createJsonRpcClient<AztecRPC>(
15
16
  url,
16
17
  {
@@ -23,6 +24,7 @@ export const createAztecRpcClient = (url: string): AztecRPC =>
23
24
  Point,
24
25
  Fr,
25
26
  },
26
- { Tx, ContractDeploymentTx },
27
+ { Tx, ContractDeploymentTx, TxReceipt },
27
28
  false,
29
+ fetch,
28
30
  );
@@ -1,5 +1,4 @@
1
- import { AztecAddress, Fr, Point, TxContext } from '@aztec/circuits.js';
2
- import { ContractAbi } from '@aztec/foundation/abi';
1
+ import { AztecAddress, Fr, PartialContractAddress, Point, PublicKey, TxContext } from '@aztec/circuits.js';
3
2
  import {
4
3
  AztecRPC,
5
4
  ContractData,
@@ -31,19 +30,21 @@ export abstract class BaseWallet implements Wallet {
31
30
  executions: ExecutionRequest[],
32
31
  txContext: TxContext,
33
32
  ): Promise<TxExecutionRequest>;
34
- addAccount(
35
- privKey: Buffer,
33
+ addAccount(privKey: Buffer, address: AztecAddress, partialContractAddress: Fr): Promise<AztecAddress> {
34
+ return this.rpc.addAccount(privKey, address, partialContractAddress);
35
+ }
36
+ addPublicKeyAndPartialAddress(
36
37
  address: AztecAddress,
37
- partialContractAddress: Fr,
38
- abi?: ContractAbi | undefined,
39
- ): Promise<AztecAddress> {
40
- return this.rpc.addAccount(privKey, address, partialContractAddress, abi);
38
+ publicKey: PublicKey,
39
+ partialAddress: PartialContractAddress,
40
+ ): Promise<void> {
41
+ return this.rpc.addPublicKeyAndPartialAddress(address, publicKey, partialAddress);
41
42
  }
42
43
  getAccounts(): Promise<AztecAddress[]> {
43
44
  return this.rpc.getAccounts();
44
45
  }
45
- getAccountPublicKey(address: AztecAddress): Promise<Point> {
46
- return this.rpc.getAccountPublicKey(address);
46
+ getPublicKey(address: AztecAddress): Promise<Point> {
47
+ return this.rpc.getPublicKey(address);
47
48
  }
48
49
  addContracts(contracts: DeployedContract[]): Promise<void> {
49
50
  return this.rpc.addContracts(contracts);
@@ -63,6 +64,9 @@ export abstract class BaseWallet implements Wallet {
63
64
  getStorageAt(contract: AztecAddress, storageSlot: Fr): Promise<any> {
64
65
  return this.rpc.getStorageAt(contract, storageSlot);
65
66
  }
67
+ getPublicStorageAt(contract: AztecAddress, storageSlot: Fr): Promise<any> {
68
+ return this.rpc.getPublicStorageAt(contract, storageSlot);
69
+ }
66
70
  viewTx(functionName: string, args: any[], to: AztecAddress, from?: AztecAddress | undefined): Promise<any> {
67
71
  return this.rpc.viewTx(functionName, args, to, from);
68
72
  }
@@ -81,6 +85,12 @@ export abstract class BaseWallet implements Wallet {
81
85
  getNodeInfo(): Promise<NodeInfo> {
82
86
  return this.rpc.getNodeInfo();
83
87
  }
88
+ getPublicKeyAndPartialAddress(address: AztecAddress): Promise<[Point, PartialContractAddress]> {
89
+ return this.rpc.getPublicKeyAndPartialAddress(address);
90
+ }
91
+ isAccountSynchronised(account: AztecAddress) {
92
+ return this.rpc.isAccountSynchronised(account);
93
+ }
84
94
  }
85
95
 
86
96
  /**
@@ -10,7 +10,7 @@ import { ContractFunctionInteraction } from './contract_function_interaction.js'
10
10
  * Type representing a contract method that returns a ContractFunctionInteraction instance
11
11
  * and has a readonly 'selector' property of type Buffer. Takes any number of arguments.
12
12
  */
13
- type ContractMethod = ((...args: any[]) => ContractFunctionInteraction) & {
13
+ export type ContractMethod = ((...args: any[]) => ContractFunctionInteraction) & {
14
14
  /**
15
15
  * The unique identifier for a contract function in bytecode.
16
16
  */
@@ -42,7 +42,7 @@ export class Contract {
42
42
  /**
43
43
  * The wallet.
44
44
  */
45
- private wallet: Wallet,
45
+ protected wallet: Wallet,
46
46
  ) {
47
47
  abi.functions.forEach((f: FunctionAbi) => {
48
48
  const interactionFunction = (...args: any[]) => {
@@ -8,6 +8,7 @@ import { DeployMethod } from './deploy_method.js';
8
8
  * A class for deploying contract.
9
9
  */
10
10
  export class ContractDeployer {
11
+ // TODO: remove this?
11
12
  constructor(private abi: ContractAbi, private arc: AztecRPC, private publicKey?: PublicKey) {}
12
13
 
13
14
  /**
@@ -89,6 +89,8 @@ export class DeployMethod extends ContractFunctionInteraction {
89
89
  const portalContract = options.portalContract ?? EthAddress.ZERO;
90
90
  const contractAddressSalt = options.contractAddressSalt ?? Fr.random();
91
91
 
92
+ const { chainId, version } = await this.wallet.getNodeInfo();
93
+
92
94
  const { address, constructorHash, functionTreeRoot, partialAddress } = await getContractDeploymentInfo(
93
95
  this.abi,
94
96
  this.args,
@@ -104,8 +106,6 @@ export class DeployMethod extends ContractFunctionInteraction {
104
106
  portalContract,
105
107
  );
106
108
 
107
- const { chainId, version } = await this.wallet.getNodeInfo();
108
-
109
109
  const txContext = new TxContext(false, false, true, contractDeploymentData, new Fr(chainId), new Fr(version));
110
110
  const executionRequest = this.getExecutionRequest(address, AztecAddress.ZERO);
111
111
  const txRequest = await this.wallet.createAuthenticatedTxRequest([executionRequest], txContext);
@@ -27,7 +27,7 @@ export async function createAccounts(
27
27
  const privKey = i == 0 && privateKey ? privateKey : randomBytes(32);
28
28
  const publicKey = await generatePublicKey(privKey);
29
29
  const deploymentInfo = await getContractDeploymentInfo(accountContractAbi, [], salt, publicKey);
30
- await aztecRpcClient.addAccount(privKey, deploymentInfo.address, deploymentInfo.partialAddress, accountContractAbi);
30
+ await aztecRpcClient.addAccount(privKey, deploymentInfo.address, deploymentInfo.partialAddress);
31
31
  const contractDeployer = new ContractDeployer(accountContractAbi, aztecRpcClient, publicKey);
32
32
  const tx = contractDeployer.deploy().send({ contractAddressSalt: salt });
33
33
  await tx.isMined(0, 0.5);
@@ -1,4 +1,5 @@
1
1
  import { EthAddress } from '@aztec/circuits.js';
2
+ import { retryUntil } from '@aztec/foundation/retry';
2
3
 
3
4
  /**
4
5
  * A dictionary of the Aztec-deployed L1 contracts.
@@ -16,6 +17,14 @@ export type L1ContractAddresses = {
16
17
  * Address of the L1/L2 messaging inbox contract.
17
18
  */
18
19
  inbox: EthAddress;
20
+ /**
21
+ * Address of the L1/L2 messaging outbox contract.
22
+ */
23
+ outbox: EthAddress;
24
+ /**
25
+ * Address of the decoder helper contract
26
+ */
27
+ decoderHelper?: EthAddress;
19
28
 
20
29
  /**
21
30
  * Registry Address.
@@ -32,7 +41,18 @@ type L1ContractAddressesResp = {
32
41
 
33
42
  export const getL1ContractAddresses = async (url: string): Promise<L1ContractAddresses> => {
34
43
  const reqUrl = new URL(`${url}/api/l1-contract-addresses`);
35
- const response = (await (await fetch(reqUrl.toString())).json()) as unknown as L1ContractAddressesResp;
44
+ const response = await retryUntil(
45
+ async () => {
46
+ try {
47
+ return (await (await fetch(reqUrl.toString())).json()) as unknown as L1ContractAddressesResp;
48
+ } catch (err) {
49
+ // do nothing
50
+ }
51
+ },
52
+ 'isSandboxReady',
53
+ 120,
54
+ 1,
55
+ );
36
56
  const result = Object.fromEntries(
37
57
  Object.entries(response).map(([key, value]) => [key, EthAddress.fromString(value)]),
38
58
  );