@aztec/aztec.js 0.6.6 → 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 +3 -3
- package/dest/abis/schnorr_account_contract.json +3 -3
- 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 +5 -4
- package/src/abis/ecdsa_account_contract.json +3 -3
- package/src/abis/schnorr_account_contract.json +3 -3
- 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
|
@@ -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=
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { AztecAddress } from '@aztec/circuits.js';
|
|
2
|
-
import { FunctionCall, TxExecutionRequest } from '@aztec/types';
|
|
3
|
-
|
|
4
|
-
import { Account } from '../account.js';
|
|
5
|
-
import { CreateTxRequestOpts, Entrypoint } from './index.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* An entrypoint that groups together multiple concrete entrypoints.
|
|
9
|
-
* Delegates to the registered entrypoints based on the requested origin.
|
|
10
|
-
*/
|
|
11
|
-
export class EntrypointCollection implements Entrypoint {
|
|
12
|
-
private entrypoints: Map<string, Entrypoint> = new Map();
|
|
13
|
-
|
|
14
|
-
constructor(entrypoints: [AztecAddress, Entrypoint][] = []) {
|
|
15
|
-
for (const [key, value] of entrypoints) {
|
|
16
|
-
this.registerAccount(key, value);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Creates a new instance out of a set of Accounts.
|
|
22
|
-
* @param accounts - Accounts to register in this entrypoint.
|
|
23
|
-
* @returns A new instance.
|
|
24
|
-
*/
|
|
25
|
-
static async fromAccounts(accounts: Account[]) {
|
|
26
|
-
const collection = new EntrypointCollection();
|
|
27
|
-
for (const account of accounts) {
|
|
28
|
-
collection.registerAccount((await account.getCompleteAddress()).address, await account.getEntrypoint());
|
|
29
|
-
}
|
|
30
|
-
return collection;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Registers an entrypoint against an aztec address
|
|
35
|
-
* @param addr - The aztec address against which to register the implementation.
|
|
36
|
-
* @param impl - The entrypoint to be registered.
|
|
37
|
-
*/
|
|
38
|
-
public registerAccount(addr: AztecAddress, impl: Entrypoint) {
|
|
39
|
-
this.entrypoints.set(addr.toString(), impl);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public createTxExecutionRequest(
|
|
43
|
-
executions: FunctionCall[],
|
|
44
|
-
opts: CreateTxRequestOpts = {},
|
|
45
|
-
): Promise<TxExecutionRequest> {
|
|
46
|
-
const defaultAccount = this.entrypoints.values().next().value as Entrypoint;
|
|
47
|
-
const impl = opts.origin ? this.entrypoints.get(opts.origin.toString()) : defaultAccount;
|
|
48
|
-
if (!impl) throw new Error(`No entrypoint registered for ${opts.origin}`);
|
|
49
|
-
return impl.createTxExecutionRequest(executions, opts);
|
|
50
|
-
}
|
|
51
|
-
}
|