@aztec/aztec.js 0.6.7 → 0.7.0
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/.tsbuildinfo +1 -1
- package/dest/abis/ecdsa_account_contract.json +2 -2
- package/dest/abis/schnorr_account_contract.json +2 -2
- package/dest/abis/schnorr_auth_witness_account_contract.json +3 -3
- package/dest/abis/schnorr_single_key_account_contract.json +1 -1
- package/dest/account/entrypoint/auth_witness_account_entrypoint.d.ts +3 -3
- package/dest/account/entrypoint/auth_witness_account_entrypoint.d.ts.map +1 -1
- package/dest/account/entrypoint/auth_witness_account_entrypoint.js +3 -6
- package/dest/account/entrypoint/entrypoint_payload.js +1 -1
- package/dest/account/entrypoint/index.d.ts +2 -9
- package/dest/account/entrypoint/index.d.ts.map +1 -1
- package/dest/account/entrypoint/index.js +2 -3
- package/dest/account/entrypoint/single_key_account_entrypoint.d.ts +2 -2
- package/dest/account/entrypoint/single_key_account_entrypoint.d.ts.map +1 -1
- package/dest/account/entrypoint/single_key_account_entrypoint.js +2 -5
- package/dest/account/entrypoint/stored_key_account_entrypoint.d.ts +2 -2
- package/dest/account/entrypoint/stored_key_account_entrypoint.d.ts.map +1 -1
- package/dest/account/entrypoint/stored_key_account_entrypoint.js +2 -5
- package/dest/aztec_rpc_client/wallet.d.ts +4 -4
- package/dest/aztec_rpc_client/wallet.d.ts.map +1 -1
- package/dest/aztec_rpc_client/wallet.js +5 -5
- package/dest/contract/base_contract_interaction.d.ts +0 -5
- package/dest/contract/base_contract_interaction.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.js +1 -1
- package/dest/contract/batch_call.d.ts +2 -3
- package/dest/contract/batch_call.d.ts.map +1 -1
- package/dest/contract/batch_call.js +3 -4
- package/dest/contract/contract.d.ts +17 -0
- package/dest/contract/contract.d.ts.map +1 -1
- package/dest/contract/contract.js +21 -1
- package/dest/contract/contract.test.js +3 -5
- package/dest/contract/contract_base.d.ts +10 -1
- package/dest/contract/contract_base.d.ts.map +1 -1
- package/dest/contract/contract_base.js +12 -1
- package/dest/contract/contract_function_interaction.d.ts +1 -2
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +3 -4
- package/dest/contract_deployer/contract_deployer.test.js +2 -4
- package/dest/main.js +1 -1
- package/dest/sandbox/index.d.ts +4 -9
- package/dest/sandbox/index.d.ts.map +1 -1
- package/dest/sandbox/index.js +7 -13
- package/dest/utils/account.d.ts +17 -14
- package/dest/utils/account.d.ts.map +1 -1
- package/dest/utils/account.js +33 -54
- package/dest/utils/cheat_codes.js +2 -2
- package/package.json +4 -4
- package/src/abis/ecdsa_account_contract.json +2 -2
- package/src/abis/schnorr_account_contract.json +2 -2
- package/src/abis/schnorr_auth_witness_account_contract.json +3 -3
- package/src/abis/schnorr_single_key_account_contract.json +1 -1
- package/src/account/entrypoint/auth_witness_account_entrypoint.ts +3 -10
- package/src/account/entrypoint/entrypoint_payload.ts +1 -1
- package/src/account/entrypoint/index.ts +2 -10
- package/src/account/entrypoint/single_key_account_entrypoint.ts +2 -9
- package/src/account/entrypoint/stored_key_account_entrypoint.ts +2 -9
- package/src/aztec_rpc_client/wallet.ts +6 -12
- package/src/contract/base_contract_interaction.ts +0 -5
- package/src/contract/batch_call.ts +3 -4
- package/src/contract/contract.test.ts +2 -4
- package/src/contract/contract.ts +23 -0
- package/src/contract/contract_base.ts +14 -2
- package/src/contract/contract_function_interaction.ts +2 -3
- package/src/contract_deployer/contract_deployer.test.ts +1 -3
- package/src/sandbox/index.ts +6 -19
- package/src/utils/account.ts +35 -79
- package/src/utils/cheat_codes.ts +1 -1
- package/dest/account/entrypoint/entrypoint_collection.d.ts +0 -26
- package/dest/account/entrypoint/entrypoint_collection.d.ts.map +0 -1
- package/dest/account/entrypoint/entrypoint_collection.js +0 -40
- package/src/account/entrypoint/entrypoint_collection.ts +0 -51
|
@@ -7,7 +7,7 @@ import SchnorrAuthWitnessAccountContractAbi from '../../abis/schnorr_auth_witnes
|
|
|
7
7
|
import { generatePublicKey } from '../../index.js';
|
|
8
8
|
import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from '../../utils/defaults.js';
|
|
9
9
|
import { buildPayload, hashPayload } from './entrypoint_payload.js';
|
|
10
|
-
import {
|
|
10
|
+
import { Entrypoint } from './index.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Account contract implementation that uses a single key for signing and encryption. This public key is not
|
|
@@ -59,10 +59,7 @@ export class AuthWitnessAccountEntrypoint implements Entrypoint {
|
|
|
59
59
|
* @param opts - The options
|
|
60
60
|
* @returns The TxRequest, the auth witness to insert in db and the message signed
|
|
61
61
|
*/
|
|
62
|
-
async createTxExecutionRequestWithWitness(
|
|
63
|
-
executions: FunctionCall[],
|
|
64
|
-
opts: CreateTxRequestOpts = {},
|
|
65
|
-
): Promise<{
|
|
62
|
+
async createTxExecutionRequestWithWitness(executions: FunctionCall[]): Promise<{
|
|
66
63
|
/** The transaction request */
|
|
67
64
|
txRequest: TxExecutionRequest;
|
|
68
65
|
/** The auth witness */
|
|
@@ -70,10 +67,6 @@ export class AuthWitnessAccountEntrypoint implements Entrypoint {
|
|
|
70
67
|
/** The message signed */
|
|
71
68
|
message: Buffer;
|
|
72
69
|
}> {
|
|
73
|
-
if (opts.origin && !opts.origin.equals(this.address)) {
|
|
74
|
-
throw new Error(`Sender ${opts.origin.toString()} does not match account address ${this.address.toString()}`);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
70
|
const { payload, packedArguments: callsPackedArguments } = await buildPayload(executions);
|
|
78
71
|
const message = await hashPayload(payload);
|
|
79
72
|
const witness = await this.createAuthWitness(message);
|
|
@@ -92,7 +85,7 @@ export class AuthWitnessAccountEntrypoint implements Entrypoint {
|
|
|
92
85
|
return { txRequest, message, witness };
|
|
93
86
|
}
|
|
94
87
|
|
|
95
|
-
createTxExecutionRequest(
|
|
88
|
+
createTxExecutionRequest(_executions: FunctionCall[]): Promise<TxExecutionRequest> {
|
|
96
89
|
throw new Error(`Not implemented, use createTxExecutionRequestWithWitness instead`);
|
|
97
90
|
}
|
|
98
91
|
|
|
@@ -5,7 +5,7 @@ import { FunctionCall, PackedArguments, emptyFunctionCall } from '@aztec/types';
|
|
|
5
5
|
|
|
6
6
|
import partition from 'lodash.partition';
|
|
7
7
|
|
|
8
|
-
// These must match the values defined in yarn-project/noir-libs/noir
|
|
8
|
+
// These must match the values defined in yarn-project/noir-libs/aztec-noir/src/entrypoint.nr
|
|
9
9
|
export const ACCOUNT_MAX_PRIVATE_CALLS = 2;
|
|
10
10
|
export const ACCOUNT_MAX_PUBLIC_CALLS = 2;
|
|
11
11
|
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import { AztecAddress } from '@aztec/circuits.js';
|
|
2
1
|
import { FunctionCall, TxExecutionRequest } from '@aztec/types';
|
|
3
2
|
|
|
4
|
-
export * from './
|
|
3
|
+
export * from './auth_witness_account_entrypoint.js';
|
|
5
4
|
export * from './entrypoint_payload.js';
|
|
6
5
|
export * from './entrypoint_utils.js';
|
|
7
6
|
export * from './single_key_account_entrypoint.js';
|
|
8
7
|
export * from './stored_key_account_entrypoint.js';
|
|
9
|
-
export * from './auth_witness_account_entrypoint.js';
|
|
10
|
-
|
|
11
|
-
/** Options for creating a tx request out of a set of function calls. */
|
|
12
|
-
export type CreateTxRequestOpts = {
|
|
13
|
-
/** Origin of the tx. Needs to be an address managed by this account. */
|
|
14
|
-
origin?: AztecAddress;
|
|
15
|
-
};
|
|
16
8
|
|
|
17
9
|
// docs:start:entrypoint-interface
|
|
18
10
|
/**
|
|
@@ -26,6 +18,6 @@ export interface Entrypoint {
|
|
|
26
18
|
* @param opts - Options.
|
|
27
19
|
* @returns The authenticated transaction execution request.
|
|
28
20
|
*/
|
|
29
|
-
createTxExecutionRequest(executions: FunctionCall[]
|
|
21
|
+
createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest>;
|
|
30
22
|
}
|
|
31
23
|
// docs:end:entrypoint-interface
|
|
@@ -7,7 +7,7 @@ import SchnorrSingleKeyAccountContractAbi from '../../abis/schnorr_single_key_ac
|
|
|
7
7
|
import { generatePublicKey } from '../../index.js';
|
|
8
8
|
import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from '../../utils/defaults.js';
|
|
9
9
|
import { buildPayload, hashPayload } from './entrypoint_payload.js';
|
|
10
|
-
import {
|
|
10
|
+
import { Entrypoint } from './index.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Account contract implementation that uses a single key for signing and encryption. This public key is not
|
|
@@ -23,14 +23,7 @@ export class SingleKeyAccountEntrypoint implements Entrypoint {
|
|
|
23
23
|
private version: number = DEFAULT_VERSION,
|
|
24
24
|
) {}
|
|
25
25
|
|
|
26
|
-
async createTxExecutionRequest(
|
|
27
|
-
executions: FunctionCall[],
|
|
28
|
-
opts: CreateTxRequestOpts = {},
|
|
29
|
-
): Promise<TxExecutionRequest> {
|
|
30
|
-
if (opts.origin && !opts.origin.equals(this.address)) {
|
|
31
|
-
throw new Error(`Sender ${opts.origin.toString()} does not match account address ${this.address.toString()}`);
|
|
32
|
-
}
|
|
33
|
-
|
|
26
|
+
async createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest> {
|
|
34
27
|
const { payload, packedArguments: callsPackedArguments } = await buildPayload(executions);
|
|
35
28
|
const message = await hashPayload(payload);
|
|
36
29
|
|
|
@@ -7,7 +7,7 @@ import { FunctionCall, PackedArguments, TxExecutionRequest } from '@aztec/types'
|
|
|
7
7
|
import EcdsaAccountContractAbi from '../../abis/ecdsa_account_contract.json' assert { type: 'json' };
|
|
8
8
|
import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from '../../utils/defaults.js';
|
|
9
9
|
import { buildPayload, hashPayload } from './entrypoint_payload.js';
|
|
10
|
-
import {
|
|
10
|
+
import { Entrypoint } from './index.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Account contract implementation that keeps a signing public key in storage, and is retrieved on
|
|
@@ -25,14 +25,7 @@ export class StoredKeyAccountEntrypoint implements Entrypoint {
|
|
|
25
25
|
this.log = createDebugLogger('aztec:client:accounts:stored_key');
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
async createTxExecutionRequest(
|
|
29
|
-
executions: FunctionCall[],
|
|
30
|
-
opts: CreateTxRequestOpts = {},
|
|
31
|
-
): Promise<TxExecutionRequest> {
|
|
32
|
-
if (opts.origin && !opts.origin.equals(this.address)) {
|
|
33
|
-
throw new Error(`Sender ${opts.origin.toString()} does not match account address ${this.address.toString()}`);
|
|
34
|
-
}
|
|
35
|
-
|
|
28
|
+
async createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest> {
|
|
36
29
|
const { payload, packedArguments: callsPackedArguments } = await buildPayload(executions);
|
|
37
30
|
const message = await hashPayload(payload);
|
|
38
31
|
const signature = this.sign(message).toBuffer();
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
TxReceipt,
|
|
17
17
|
} from '@aztec/types';
|
|
18
18
|
|
|
19
|
-
import { AuthWitnessAccountEntrypoint,
|
|
19
|
+
import { AuthWitnessAccountEntrypoint, Entrypoint } from '../account/entrypoint/index.js';
|
|
20
20
|
import { CompleteAddress } from '../index.js';
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -30,7 +30,7 @@ export type Wallet = Entrypoint & AztecRPC;
|
|
|
30
30
|
export abstract class BaseWallet implements Wallet {
|
|
31
31
|
constructor(protected readonly rpc: AztecRPC) {}
|
|
32
32
|
|
|
33
|
-
abstract createTxExecutionRequest(execs: FunctionCall[]
|
|
33
|
+
abstract createTxExecutionRequest(execs: FunctionCall[]): Promise<TxExecutionRequest>;
|
|
34
34
|
|
|
35
35
|
registerAccount(privKey: GrumpkinPrivateKey, partialAddress: PartialAddress): Promise<void> {
|
|
36
36
|
return this.rpc.registerAccount(privKey, partialAddress);
|
|
@@ -110,8 +110,8 @@ export class EntrypointWallet extends BaseWallet {
|
|
|
110
110
|
constructor(rpc: AztecRPC, protected accountImpl: Entrypoint) {
|
|
111
111
|
super(rpc);
|
|
112
112
|
}
|
|
113
|
-
createTxExecutionRequest(executions: FunctionCall[]
|
|
114
|
-
return this.accountImpl.createTxExecutionRequest(executions
|
|
113
|
+
createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest> {
|
|
114
|
+
return this.accountImpl.createTxExecutionRequest(executions);
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
|
|
@@ -136,14 +136,8 @@ export class AuthWitnessEntrypointWallet extends BaseWallet {
|
|
|
136
136
|
* @param opts - The options.
|
|
137
137
|
* @returns - The TxRequest
|
|
138
138
|
*/
|
|
139
|
-
async createTxExecutionRequest(
|
|
140
|
-
|
|
141
|
-
opts: CreateTxRequestOpts = {},
|
|
142
|
-
): Promise<TxExecutionRequest> {
|
|
143
|
-
const { txRequest, message, witness } = await this.accountImpl.createTxExecutionRequestWithWitness(
|
|
144
|
-
executions,
|
|
145
|
-
opts,
|
|
146
|
-
);
|
|
139
|
+
async createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest> {
|
|
140
|
+
const { txRequest, message, witness } = await this.accountImpl.createTxExecutionRequestWithWitness(executions);
|
|
147
141
|
await this.rpc.addAuthWitness(Fr.fromBuffer(message), witness);
|
|
148
142
|
return txRequest;
|
|
149
143
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AztecAddress } from '@aztec/circuits.js';
|
|
2
1
|
import { AztecRPC, Tx, TxExecutionRequest } from '@aztec/types';
|
|
3
2
|
|
|
4
3
|
import { SentTx } from './sent_tx.js';
|
|
@@ -8,10 +7,6 @@ import { SentTx } from './sent_tx.js';
|
|
|
8
7
|
* Allows the user to specify the sender address and nonce for a transaction.
|
|
9
8
|
*/
|
|
10
9
|
export interface SendMethodOptions {
|
|
11
|
-
/**
|
|
12
|
-
* Sender's address initiating the transaction.
|
|
13
|
-
*/
|
|
14
|
-
origin?: AztecAddress;
|
|
15
10
|
/**
|
|
16
11
|
* Wether to skip the simulation of the public part of the transaction.
|
|
17
12
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FunctionCall, TxExecutionRequest, Wallet } from '../index.js';
|
|
2
|
-
import { BaseContractInteraction
|
|
2
|
+
import { BaseContractInteraction } from './base_contract_interaction.js';
|
|
3
3
|
|
|
4
4
|
/** A batch of function calls to be sent as a single transaction through a wallet. */
|
|
5
5
|
export class BatchCall extends BaseContractInteraction {
|
|
@@ -10,12 +10,11 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
10
10
|
/**
|
|
11
11
|
* Create a transaction execution request that represents this batch, encoded and authenticated by the
|
|
12
12
|
* user's wallet, ready to be simulated.
|
|
13
|
-
* @param options - An optional object containing additional configuration for the transaction.
|
|
14
13
|
* @returns A Promise that resolves to a transaction instance.
|
|
15
14
|
*/
|
|
16
|
-
public async create(
|
|
15
|
+
public async create(): Promise<TxExecutionRequest> {
|
|
17
16
|
if (!this.txRequest) {
|
|
18
|
-
this.txRequest = await this.wallet.createTxExecutionRequest(this.calls
|
|
17
|
+
this.txRequest = await this.wallet.createTxExecutionRequest(this.calls);
|
|
19
18
|
}
|
|
20
19
|
return this.txRequest;
|
|
21
20
|
}
|
|
@@ -109,9 +109,7 @@ describe('Contract Class', () => {
|
|
|
109
109
|
const fooContract = await Contract.at(contractAddress, defaultAbi, wallet);
|
|
110
110
|
const param0 = 12;
|
|
111
111
|
const param1 = 345n;
|
|
112
|
-
const sentTx = fooContract.methods.bar(param0, param1).send(
|
|
113
|
-
origin: account.address,
|
|
114
|
-
});
|
|
112
|
+
const sentTx = fooContract.methods.bar(param0, param1).send();
|
|
115
113
|
const txHash = await sentTx.getTxHash();
|
|
116
114
|
const receipt = await sentTx.getReceipt();
|
|
117
115
|
|
|
@@ -134,7 +132,7 @@ describe('Contract Class', () => {
|
|
|
134
132
|
|
|
135
133
|
it('should not call create on an unconstrained function', async () => {
|
|
136
134
|
const fooContract = await Contract.at(contractAddress, defaultAbi, wallet);
|
|
137
|
-
await expect(fooContract.methods.qux().create(
|
|
135
|
+
await expect(fooContract.methods.qux().create()).rejects.toThrow();
|
|
138
136
|
});
|
|
139
137
|
|
|
140
138
|
it('should not call view on a secret or open function', async () => {
|
package/src/contract/contract.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ContractAbi } from '@aztec/foundation/abi';
|
|
2
2
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
3
|
+
import { PublicKey } from '@aztec/types';
|
|
3
4
|
|
|
4
5
|
import { Wallet } from '../aztec_rpc_client/wallet.js';
|
|
6
|
+
import { DeployMethod, Point } from '../index.js';
|
|
5
7
|
import { ContractBase } from './contract_base.js';
|
|
6
8
|
|
|
7
9
|
/**
|
|
@@ -26,4 +28,25 @@ export class Contract extends ContractBase {
|
|
|
26
28
|
}
|
|
27
29
|
return new Contract(extendedContractData.getCompleteAddress(), abi, wallet);
|
|
28
30
|
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates a tx to deploy a new instance of a contract.
|
|
34
|
+
* @param wallet - The wallet for executing the deployment.
|
|
35
|
+
* @param abi - ABI of the contract to deploy.
|
|
36
|
+
* @param args - Arguments for the constructor.
|
|
37
|
+
*/
|
|
38
|
+
public static deploy(wallet: Wallet, abi: ContractAbi, args: any[]) {
|
|
39
|
+
return new DeployMethod(Point.ZERO, wallet, abi, args);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Creates a tx to deploy a new instance of a contract using the specified public key to derive the address.
|
|
44
|
+
* @param publicKey - Public key for deriving the address.
|
|
45
|
+
* @param wallet - The wallet for executing the deployment.
|
|
46
|
+
* @param abi - ABI of the contract to deploy.
|
|
47
|
+
* @param args - Arguments for the constructor.
|
|
48
|
+
*/
|
|
49
|
+
public static deployWithPublicKey(publicKey: PublicKey, wallet: Wallet, abi: ContractAbi, args: any[]) {
|
|
50
|
+
return new DeployMethod(publicKey, wallet, abi, args);
|
|
51
|
+
}
|
|
29
52
|
}
|
|
@@ -19,7 +19,7 @@ export type ContractMethod = ((...args: any[]) => ContractFunctionInteraction) &
|
|
|
19
19
|
/**
|
|
20
20
|
* Abstract implementation of a contract extended by the Contract class and generated contract types.
|
|
21
21
|
*/
|
|
22
|
-
export
|
|
22
|
+
export class ContractBase {
|
|
23
23
|
/**
|
|
24
24
|
* An object containing contract methods mapped to their respective names.
|
|
25
25
|
*/
|
|
@@ -56,10 +56,22 @@ export abstract class ContractBase {
|
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Address of the contract.
|
|
61
|
+
*/
|
|
62
|
+
public get address() {
|
|
60
63
|
return this.completeAddress.address;
|
|
61
64
|
}
|
|
62
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Creates a new instance of the contract wrapper attached to a different wallet.
|
|
68
|
+
* @param wallet - Wallet to use for sending txs.
|
|
69
|
+
* @returns A new contract instance.
|
|
70
|
+
*/
|
|
71
|
+
public withWallet(wallet: Wallet): this {
|
|
72
|
+
return new ContractBase(this.completeAddress, this.abi, wallet) as this;
|
|
73
|
+
}
|
|
74
|
+
|
|
63
75
|
/**
|
|
64
76
|
* Attach the current contract instance to a portal contract and optionally add its dependencies.
|
|
65
77
|
* The function will return a promise that resolves when all contracts have been added to the AztecRPCClient.
|
|
@@ -38,15 +38,14 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
38
38
|
/**
|
|
39
39
|
* Create a transaction execution request that represents this call, encoded and authenticated by the
|
|
40
40
|
* user's wallet, ready to be simulated.
|
|
41
|
-
* @param options - An optional object containing additional configuration for the transaction.
|
|
42
41
|
* @returns A Promise that resolves to a transaction instance.
|
|
43
42
|
*/
|
|
44
|
-
public async create(
|
|
43
|
+
public async create(): Promise<TxExecutionRequest> {
|
|
45
44
|
if (this.functionDao.functionType === FunctionType.UNCONSTRAINED) {
|
|
46
45
|
throw new Error("Can't call `create` on an unconstrained function.");
|
|
47
46
|
}
|
|
48
47
|
if (!this.txRequest) {
|
|
49
|
-
this.txRequest = await this.wallet.createTxExecutionRequest([this.request()]
|
|
48
|
+
this.txRequest = await this.wallet.createTxExecutionRequest([this.request()]);
|
|
50
49
|
}
|
|
51
50
|
return this.txRequest;
|
|
52
51
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EthAddress, Fr, Point } from '@aztec/circuits.js';
|
|
2
2
|
import { ContractAbi, FunctionType } from '@aztec/foundation/abi';
|
|
3
3
|
import { AztecRPC, PublicKey, Tx, TxHash, TxReceipt } from '@aztec/types';
|
|
4
4
|
|
|
@@ -26,7 +26,6 @@ describe.skip('Contract Deployer', () => {
|
|
|
26
26
|
const publicKey: PublicKey = Point.random();
|
|
27
27
|
const portalContract = EthAddress.random();
|
|
28
28
|
const contractAddressSalt = Fr.random();
|
|
29
|
-
const account = AztecAddress.random();
|
|
30
29
|
const args = [12, 345n];
|
|
31
30
|
|
|
32
31
|
const mockTx = { type: 'Tx' } as any as Tx;
|
|
@@ -44,7 +43,6 @@ describe.skip('Contract Deployer', () => {
|
|
|
44
43
|
const sentTx = deployer.deploy(args[0], args[1]).send({
|
|
45
44
|
portalContract,
|
|
46
45
|
contractAddressSalt,
|
|
47
|
-
origin: account,
|
|
48
46
|
});
|
|
49
47
|
const txHash = await sentTx.getTxHash();
|
|
50
48
|
const receipt = await sentTx.getReceipt();
|
package/src/sandbox/index.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Fr, GrumpkinScalar } from '@aztec/circuits.js';
|
|
2
|
-
import { ContractAbi } from '@aztec/foundation/abi';
|
|
3
2
|
import { sleep } from '@aztec/foundation/sleep';
|
|
4
3
|
|
|
5
4
|
import zip from 'lodash.zip';
|
|
6
5
|
|
|
7
6
|
import SchnorrAccountContractAbi from '../abis/schnorr_account_contract.json' assert { type: 'json' };
|
|
8
|
-
import { AccountWallet, AztecRPC,
|
|
7
|
+
import { AccountWallet, AztecRPC, createAztecRpcClient, getSchnorrAccount } from '../index.js';
|
|
9
8
|
|
|
10
9
|
export const INITIAL_SANDBOX_ENCRYPTION_KEYS = [
|
|
11
10
|
GrumpkinScalar.fromString('2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281'),
|
|
@@ -19,20 +18,7 @@ export const INITIAL_SANDBOX_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO];
|
|
|
19
18
|
|
|
20
19
|
export const INITIAL_SANDBOX_ACCOUNT_CONTRACT_ABI = SchnorrAccountContractAbi;
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
* Gets a single wallet that manages all the Aztec accounts that are initially stored in the sandbox.
|
|
24
|
-
* @param aztecRpc - An instance of the Aztec RPC interface.
|
|
25
|
-
* @returns An AccountWallet implementation that includes all the initial accounts.
|
|
26
|
-
*/
|
|
27
|
-
export async function getSandboxAccountsWallet(aztecRpc: AztecRPC): Promise<EntrypointWallet> {
|
|
28
|
-
return await getAccountWallets(
|
|
29
|
-
aztecRpc,
|
|
30
|
-
INITIAL_SANDBOX_ACCOUNT_CONTRACT_ABI as unknown as ContractAbi,
|
|
31
|
-
INITIAL_SANDBOX_ENCRYPTION_KEYS,
|
|
32
|
-
INITIAL_SANDBOX_SIGNING_KEYS,
|
|
33
|
-
INITIAL_SANDBOX_SALTS,
|
|
34
|
-
);
|
|
35
|
-
}
|
|
21
|
+
export const { SANDBOX_URL = 'http://localhost:8080' } = process.env;
|
|
36
22
|
|
|
37
23
|
/**
|
|
38
24
|
* Gets a collection of wallets for the Aztec accounts that are initially stored in the sandbox.
|
|
@@ -84,12 +70,13 @@ export async function deployInitialSandboxAccounts(aztecRpc: AztecRPC) {
|
|
|
84
70
|
|
|
85
71
|
/**
|
|
86
72
|
* Function to wait until the sandbox becomes ready for use.
|
|
87
|
-
* @param
|
|
73
|
+
* @param rpc - The rpc client connected to the sandbox.
|
|
88
74
|
*/
|
|
89
|
-
export async function waitForSandbox(
|
|
75
|
+
export async function waitForSandbox(rpc?: AztecRPC) {
|
|
76
|
+
rpc = rpc ?? createAztecRpcClient(SANDBOX_URL);
|
|
90
77
|
while (true) {
|
|
91
78
|
try {
|
|
92
|
-
await
|
|
79
|
+
await rpc.getNodeInfo();
|
|
93
80
|
break;
|
|
94
81
|
} catch (err) {
|
|
95
82
|
await sleep(1000);
|
package/src/utils/account.ts
CHANGED
|
@@ -1,91 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { ContractAbi } from '@aztec/foundation/abi';
|
|
4
|
-
import { createDebugLogger } from '@aztec/foundation/log';
|
|
5
|
-
import { AztecRPC, TxStatus } from '@aztec/types';
|
|
1
|
+
import { CompleteAddress, GrumpkinScalar } from '@aztec/circuits.js';
|
|
2
|
+
import { AztecRPC } from '@aztec/types';
|
|
6
3
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { ContractDeployer, EntrypointCollection, StoredKeyAccountEntrypoint, generatePublicKey } from '../index.js';
|
|
4
|
+
import { AccountWallet } from '../aztec_rpc_client/wallet.js';
|
|
5
|
+
import { getSchnorrAccount } from '../index.js';
|
|
10
6
|
|
|
11
7
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
8
|
+
* Deploys and registers a new account using random private keys and returns the associated wallet. Useful for testing.
|
|
9
|
+
* @param rpc - RPC client.
|
|
10
|
+
* @returns - A wallet for a fresh account.
|
|
14
11
|
*/
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
accountContractAbi: ContractAbi,
|
|
18
|
-
privateKey?: GrumpkinPrivateKey,
|
|
19
|
-
salt = Fr.random(),
|
|
20
|
-
numberOfAccounts = 1,
|
|
21
|
-
logger = createDebugLogger('aztec:aztec.js:accounts'),
|
|
22
|
-
): Promise<Wallet> {
|
|
23
|
-
const accountImpls = new EntrypointCollection();
|
|
24
|
-
|
|
25
|
-
for (let i = 0; i < numberOfAccounts; ++i) {
|
|
26
|
-
// TODO(#662): Let the aztec rpc server generate the keypair rather than hardcoding the private key
|
|
27
|
-
const privKey = i == 0 && privateKey ? privateKey : GrumpkinScalar.random();
|
|
28
|
-
const publicKey = await generatePublicKey(privKey);
|
|
29
|
-
const deploymentInfo = await getContractDeploymentInfo(accountContractAbi, [], salt, publicKey);
|
|
30
|
-
await aztecRpcClient.registerAccount(privKey, deploymentInfo.completeAddress.partialAddress);
|
|
31
|
-
const contractDeployer = new ContractDeployer(accountContractAbi, aztecRpcClient, publicKey);
|
|
32
|
-
const tx = contractDeployer.deploy().send({ contractAddressSalt: salt });
|
|
33
|
-
await tx.isMined({ interval: 0.5 });
|
|
34
|
-
const receipt = await tx.getReceipt();
|
|
35
|
-
if (receipt.status !== TxStatus.MINED) {
|
|
36
|
-
throw new Error(`Deployment tx not mined (status is ${receipt.status})`);
|
|
37
|
-
}
|
|
38
|
-
const address = receipt.contractAddress!;
|
|
39
|
-
if (!address.equals(deploymentInfo.completeAddress.address)) {
|
|
40
|
-
throw new Error(
|
|
41
|
-
`Deployment address does not match for account contract (expected ${deploymentInfo.completeAddress.address.toString()} got ${address.toString()})`,
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
logger(`Created account ${address.toString()} with public key ${publicKey.toString()}`);
|
|
45
|
-
accountImpls.registerAccount(
|
|
46
|
-
address,
|
|
47
|
-
new SingleKeyAccountEntrypoint(address, deploymentInfo.completeAddress.partialAddress, privKey),
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
return new EntrypointWallet(aztecRpcClient, accountImpls);
|
|
12
|
+
export function createAccount(rpc: AztecRPC): Promise<AccountWallet> {
|
|
13
|
+
return getSchnorrAccount(rpc, GrumpkinScalar.random(), GrumpkinScalar.random()).waitDeploy();
|
|
51
14
|
}
|
|
52
15
|
|
|
53
16
|
/**
|
|
54
|
-
*
|
|
55
|
-
* @param
|
|
56
|
-
* @
|
|
57
|
-
* @param privateKeys - The encryption private keys used to create the accounts.
|
|
58
|
-
* @param signingKeys - The signing private keys used to create the accounts.
|
|
59
|
-
* @param salts - The salt values used to create the accounts.
|
|
60
|
-
* @returns An AccountWallet implementation that includes all the accounts found.
|
|
17
|
+
* Creates a random address and registers it as a recipient on the RPC server. Useful for testing.
|
|
18
|
+
* @param rpc - RPC client.
|
|
19
|
+
* @returns Complete address of the registered recipient.
|
|
61
20
|
*/
|
|
62
|
-
export async function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
salts: Fr[],
|
|
68
|
-
) {
|
|
69
|
-
if (privateKeys.length != salts.length || signingKeys.length != privateKeys.length) {
|
|
70
|
-
throw new Error('Keys and salts must be the same length');
|
|
71
|
-
}
|
|
72
|
-
const accountCollection = new EntrypointCollection();
|
|
73
|
-
const schnorr = await Schnorr.new();
|
|
74
|
-
|
|
75
|
-
for (let i = 0; i < privateKeys.length; i++) {
|
|
76
|
-
const publicKey = await generatePublicKey(privateKeys[i]);
|
|
77
|
-
const signingPublicKey = await generatePublicKey(signingKeys[i]);
|
|
78
|
-
const deploymentInfo = await getContractDeploymentInfo(
|
|
79
|
-
accountContractAbi,
|
|
80
|
-
[signingPublicKey.x, signingPublicKey.y],
|
|
81
|
-
salts[i],
|
|
82
|
-
publicKey,
|
|
83
|
-
);
|
|
84
|
-
const address = deploymentInfo.completeAddress.address;
|
|
21
|
+
export async function createRecipient(rpc: AztecRPC): Promise<CompleteAddress> {
|
|
22
|
+
const completeAddress = await CompleteAddress.random();
|
|
23
|
+
await rpc.registerRecipient(completeAddress);
|
|
24
|
+
return completeAddress;
|
|
25
|
+
}
|
|
85
26
|
|
|
86
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Creates a given number of random accounts using the Schnorr account wallet.
|
|
29
|
+
* @param rpc - RPC interface.
|
|
30
|
+
* @param numberOfAccounts - How many accounts to create.
|
|
31
|
+
* @returns The created account wallets.
|
|
32
|
+
*/
|
|
33
|
+
export async function createAccounts(rpc: AztecRPC, numberOfAccounts = 1): Promise<AccountWallet[]> {
|
|
34
|
+
const accounts = [];
|
|
87
35
|
|
|
88
|
-
|
|
36
|
+
// Prepare deployments
|
|
37
|
+
for (let i = 0; i < numberOfAccounts; ++i) {
|
|
38
|
+
const account = getSchnorrAccount(rpc, GrumpkinScalar.random(), GrumpkinScalar.random());
|
|
39
|
+
await account.getDeployMethod().then(d => d.simulate({ contractAddressSalt: account.salt }));
|
|
40
|
+
accounts.push(account);
|
|
89
41
|
}
|
|
90
|
-
|
|
42
|
+
|
|
43
|
+
// Send them and await them to be mined
|
|
44
|
+
const txs = await Promise.all(accounts.map(account => account.deploy()));
|
|
45
|
+
await Promise.all(txs.map(tx => tx.wait({ interval: 0.1 })));
|
|
46
|
+
return Promise.all(accounts.map(account => account.getWallet()));
|
|
91
47
|
}
|
package/src/utils/cheat_codes.ts
CHANGED
|
@@ -234,7 +234,7 @@ export class AztecCheatCodes {
|
|
|
234
234
|
*/
|
|
235
235
|
public computeSlotInMap(baseSlot: Fr | bigint, key: Fr | bigint | AztecAddress): Fr {
|
|
236
236
|
// Based on `at` function in
|
|
237
|
-
// aztec3-packages/yarn-project/noir-
|
|
237
|
+
// aztec3-packages/yarn-project/noir-libs/aztec-noir/src/state_vars/map.nr
|
|
238
238
|
return Fr.fromBuffer(
|
|
239
239
|
pedersenPlookupCommitInputs(
|
|
240
240
|
this.wasm,
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { AztecAddress } from '@aztec/circuits.js';
|
|
2
|
-
import { FunctionCall, TxExecutionRequest } from '@aztec/types';
|
|
3
|
-
import { Account } from '../account.js';
|
|
4
|
-
import { CreateTxRequestOpts, Entrypoint } from './index.js';
|
|
5
|
-
/**
|
|
6
|
-
* An entrypoint that groups together multiple concrete entrypoints.
|
|
7
|
-
* Delegates to the registered entrypoints based on the requested origin.
|
|
8
|
-
*/
|
|
9
|
-
export declare class EntrypointCollection implements Entrypoint {
|
|
10
|
-
private entrypoints;
|
|
11
|
-
constructor(entrypoints?: [AztecAddress, Entrypoint][]);
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new instance out of a set of Accounts.
|
|
14
|
-
* @param accounts - Accounts to register in this entrypoint.
|
|
15
|
-
* @returns A new instance.
|
|
16
|
-
*/
|
|
17
|
-
static fromAccounts(accounts: Account[]): Promise<EntrypointCollection>;
|
|
18
|
-
/**
|
|
19
|
-
* Registers an entrypoint against an aztec address
|
|
20
|
-
* @param addr - The aztec address against which to register the implementation.
|
|
21
|
-
* @param impl - The entrypoint to be registered.
|
|
22
|
-
*/
|
|
23
|
-
registerAccount(addr: AztecAddress, impl: Entrypoint): void;
|
|
24
|
-
createTxExecutionRequest(executions: FunctionCall[], opts?: CreateTxRequestOpts): Promise<TxExecutionRequest>;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=entrypoint_collection.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entrypoint_collection.d.ts","sourceRoot":"","sources":["../../../src/account/entrypoint/entrypoint_collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7D;;;GAGG;AACH,qBAAa,oBAAqB,YAAW,UAAU;IACrD,OAAO,CAAC,WAAW,CAAsC;gBAE7C,WAAW,GAAE,CAAC,YAAY,EAAE,UAAU,CAAC,EAAO;IAM1D;;;;OAIG;WACU,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE;IAQ7C;;;;OAIG;IACI,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU;IAIpD,wBAAwB,CAC7B,UAAU,EAAE,YAAY,EAAE,EAC1B,IAAI,GAAE,mBAAwB,GAC7B,OAAO,CAAC,kBAAkB,CAAC;CAM/B"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An entrypoint that groups together multiple concrete entrypoints.
|
|
3
|
-
* Delegates to the registered entrypoints based on the requested origin.
|
|
4
|
-
*/
|
|
5
|
-
export class EntrypointCollection {
|
|
6
|
-
constructor(entrypoints = []) {
|
|
7
|
-
this.entrypoints = new Map();
|
|
8
|
-
for (const [key, value] of entrypoints) {
|
|
9
|
-
this.registerAccount(key, value);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new instance out of a set of Accounts.
|
|
14
|
-
* @param accounts - Accounts to register in this entrypoint.
|
|
15
|
-
* @returns A new instance.
|
|
16
|
-
*/
|
|
17
|
-
static async fromAccounts(accounts) {
|
|
18
|
-
const collection = new EntrypointCollection();
|
|
19
|
-
for (const account of accounts) {
|
|
20
|
-
collection.registerAccount((await account.getCompleteAddress()).address, await account.getEntrypoint());
|
|
21
|
-
}
|
|
22
|
-
return collection;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Registers an entrypoint against an aztec address
|
|
26
|
-
* @param addr - The aztec address against which to register the implementation.
|
|
27
|
-
* @param impl - The entrypoint to be registered.
|
|
28
|
-
*/
|
|
29
|
-
registerAccount(addr, impl) {
|
|
30
|
-
this.entrypoints.set(addr.toString(), impl);
|
|
31
|
-
}
|
|
32
|
-
createTxExecutionRequest(executions, opts = {}) {
|
|
33
|
-
const defaultAccount = this.entrypoints.values().next().value;
|
|
34
|
-
const impl = opts.origin ? this.entrypoints.get(opts.origin.toString()) : defaultAccount;
|
|
35
|
-
if (!impl)
|
|
36
|
-
throw new Error(`No entrypoint registered for ${opts.origin}`);
|
|
37
|
-
return impl.createTxExecutionRequest(executions, opts);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW50cnlwb2ludF9jb2xsZWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2FjY291bnQvZW50cnlwb2ludC9lbnRyeXBvaW50X2NvbGxlY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBTUE7OztHQUdHO0FBQ0gsTUFBTSxPQUFPLG9CQUFvQjtJQUcvQixZQUFZLGNBQTRDLEVBQUU7UUFGbEQsZ0JBQVcsR0FBNEIsSUFBSSxHQUFHLEVBQUUsQ0FBQztRQUd2RCxLQUFLLE1BQU0sQ0FBQyxHQUFHLEVBQUUsS0FBSyxDQUFDLElBQUksV0FBVyxFQUFFO1lBQ3RDLElBQUksQ0FBQyxlQUFlLENBQUMsR0FBRyxFQUFFLEtBQUssQ0FBQyxDQUFDO1NBQ2xDO0lBQ0gsQ0FBQztJQUVEOzs7O09BSUc7SUFDSCxNQUFNLENBQUMsS0FBSyxDQUFDLFlBQVksQ0FBQyxRQUFtQjtRQUMzQyxNQUFNLFVBQVUsR0FBRyxJQUFJLG9CQUFvQixFQUFFLENBQUM7UUFDOUMsS0FBSyxNQUFNLE9BQU8sSUFBSSxRQUFRLEVBQUU7WUFDOUIsVUFBVSxDQUFDLGVBQWUsQ0FBQyxDQUFDLE1BQU0sT0FBTyxDQUFDLGtCQUFrQixFQUFFLENBQUMsQ0FBQyxPQUFPLEVBQUUsTUFBTSxPQUFPLENBQUMsYUFBYSxFQUFFLENBQUMsQ0FBQztTQUN6RztRQUNELE9BQU8sVUFBVSxDQUFDO0lBQ3BCLENBQUM7SUFFRDs7OztPQUlHO0lBQ0ksZUFBZSxDQUFDLElBQWtCLEVBQUUsSUFBZ0I7UUFDekQsSUFBSSxDQUFDLFdBQVcsQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLFFBQVEsRUFBRSxFQUFFLElBQUksQ0FBQyxDQUFDO0lBQzlDLENBQUM7SUFFTSx3QkFBd0IsQ0FDN0IsVUFBMEIsRUFDMUIsT0FBNEIsRUFBRTtRQUU5QixNQUFNLGNBQWMsR0FBRyxJQUFJLENBQUMsV0FBVyxDQUFDLE1BQU0sRUFBRSxDQUFDLElBQUksRUFBRSxDQUFDLEtBQW1CLENBQUM7UUFDNUUsTUFBTSxJQUFJLEdBQUcsSUFBSSxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLE1BQU0sQ0FBQyxRQUFRLEVBQUUsQ0FBQyxDQUFDLENBQUMsQ0FBQyxjQUFjLENBQUM7UUFDekYsSUFBSSxDQUFDLElBQUk7WUFBRSxNQUFNLElBQUksS0FBSyxDQUFDLGdDQUFnQyxJQUFJLENBQUMsTUFBTSxFQUFFLENBQUMsQ0FBQztRQUMxRSxPQUFPLElBQUksQ0FBQyx3QkFBd0IsQ0FBQyxVQUFVLEVBQUUsSUFBSSxDQUFDLENBQUM7SUFDekQsQ0FBQztDQUNGIn0=
|