@aztec/aztec.js 0.23.0 → 0.26.1
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/dest/account/index.d.ts +1 -1
- package/dest/account/index.d.ts.map +1 -1
- package/dest/account/interface.d.ts +12 -2
- package/dest/account/interface.d.ts.map +1 -1
- package/dest/account/interface.js +1 -1
- package/dest/account_manager/index.d.ts +4 -2
- package/dest/account_manager/index.d.ts.map +1 -1
- package/dest/account_manager/index.js +15 -6
- package/dest/api/account.d.ts +1 -1
- package/dest/api/account.d.ts.map +1 -1
- package/dest/api/account.js +1 -1
- package/dest/api/deployment.d.ts +4 -0
- package/dest/api/deployment.d.ts.map +1 -0
- package/dest/api/deployment.js +4 -0
- package/dest/api/fee.d.ts +5 -0
- package/dest/api/fee.d.ts.map +1 -0
- package/dest/api/fee.js +4 -0
- package/dest/contract/base_contract_interaction.d.ts +5 -0
- 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 +3 -2
- package/dest/contract/batch_call.d.ts.map +1 -1
- package/dest/contract/batch_call.js +4 -3
- package/dest/contract/contract.d.ts +4 -2
- package/dest/contract/contract.d.ts.map +1 -1
- package/dest/contract/contract.js +7 -5
- package/dest/contract/contract_function_interaction.d.ts +2 -2
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +4 -4
- package/dest/contract/deploy_method.d.ts +37 -12
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +79 -35
- package/dest/contract/deploy_sent_tx.d.ts +3 -3
- package/dest/contract/deploy_sent_tx.d.ts.map +1 -1
- package/dest/contract/deploy_sent_tx.js +4 -7
- package/dest/contract/sent_tx.d.ts.map +1 -1
- package/dest/contract/sent_tx.js +10 -10
- package/dest/contract/unsafe_contract.d.ts +15 -0
- package/dest/contract/unsafe_contract.d.ts.map +1 -0
- package/dest/contract/unsafe_contract.js +14 -0
- package/dest/deployment/broadcast_function.d.ts +24 -0
- package/dest/deployment/broadcast_function.d.ts.map +1 -0
- package/dest/deployment/broadcast_function.js +67 -0
- package/dest/{contract_deployer → deployment}/contract_deployer.d.ts +4 -3
- package/dest/deployment/contract_deployer.d.ts.map +1 -0
- package/dest/{contract_deployer → deployment}/contract_deployer.js +5 -4
- package/dest/deployment/deploy_instance.d.ts +13 -0
- package/dest/deployment/deploy_instance.d.ts.map +1 -0
- package/dest/deployment/deploy_instance.js +13 -0
- package/dest/deployment/index.d.ts.map +1 -0
- package/dest/{contract_deployer → deployment}/index.js +1 -1
- package/dest/deployment/protocol_contracts.d.ts +7 -0
- package/dest/deployment/protocol_contracts.d.ts.map +1 -0
- package/dest/deployment/protocol_contracts.js +14 -0
- package/dest/deployment/register_class.d.ts +6 -0
- package/dest/deployment/register_class.d.ts.map +1 -0
- package/dest/deployment/register_class.js +12 -0
- package/dest/fee/fee_payment_method.d.ts +24 -0
- package/dest/fee/fee_payment_method.d.ts.map +1 -0
- package/dest/fee/fee_payment_method.js +2 -0
- package/dest/fee/native_fee_payment_method.d.ts +32 -0
- package/dest/fee/native_fee_payment_method.d.ts.map +1 -0
- package/dest/fee/native_fee_payment_method.js +54 -0
- package/dest/fee/private_fee_payment_method.d.ts +52 -0
- package/dest/fee/private_fee_payment_method.d.ts.map +1 -0
- package/dest/fee/private_fee_payment_method.js +62 -0
- package/dest/fee/public_fee_payment_method.d.ts +52 -0
- package/dest/fee/public_fee_payment_method.d.ts.map +1 -0
- package/dest/fee/public_fee_payment_method.js +62 -0
- package/dest/index.d.ts +6 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +7 -5
- package/dest/rpc_clients/pxe_client.d.ts.map +1 -1
- package/dest/rpc_clients/pxe_client.js +15 -15
- package/dest/utils/authwit.d.ts +30 -4
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +35 -5
- package/dest/utils/cheat_codes.js +3 -3
- package/dest/utils/index.d.ts +0 -1
- package/dest/utils/index.d.ts.map +1 -1
- package/dest/utils/index.js +1 -2
- package/dest/utils/l2_contracts.js +2 -2
- package/dest/wallet/account_wallet.d.ts +10 -3
- package/dest/wallet/account_wallet.d.ts.map +1 -1
- package/dest/wallet/account_wallet.js +34 -10
- package/dest/wallet/base_wallet.d.ts +7 -4
- package/dest/wallet/base_wallet.d.ts.map +1 -1
- package/dest/wallet/base_wallet.js +9 -3
- package/dest/wallet/signerless_wallet.js +2 -2
- package/package.json +9 -6
- package/src/account/contract.ts +33 -0
- package/src/account/index.ts +16 -0
- package/src/account/interface.ts +47 -0
- package/src/account/wallet.ts +8 -0
- package/src/account_manager/deploy_account_sent_tx.ts +42 -0
- package/src/account_manager/index.ts +188 -0
- package/src/api/README.md +7 -0
- package/src/api/abi.ts +3 -0
- package/src/api/account.ts +13 -0
- package/src/api/aztec_address.ts +1 -0
- package/src/api/deployment.ts +3 -0
- package/src/api/eth_address.ts +1 -0
- package/src/api/ethereum.ts +6 -0
- package/src/api/fee.ts +4 -0
- package/src/api/fields.ts +1 -0
- package/src/api/init.ts +10 -0
- package/src/api/interfaces/pxe.ts +1 -0
- package/src/api/log_id.ts +1 -0
- package/src/api/tx_hash.ts +1 -0
- package/src/api/wallet.ts +1 -0
- package/src/contract/base_contract_interaction.ts +67 -0
- package/src/contract/batch_call.ts +24 -0
- package/src/contract/checker.ts +117 -0
- package/src/contract/contract.ts +64 -0
- package/src/contract/contract_base.ts +72 -0
- package/src/contract/contract_function_interaction.ts +80 -0
- package/src/contract/deploy_method.ts +192 -0
- package/src/contract/deploy_sent_tx.ts +66 -0
- package/src/contract/index.ts +44 -0
- package/src/contract/sent_tx.ts +135 -0
- package/src/contract/unsafe_contract.ts +19 -0
- package/src/deployment/broadcast_function.ts +118 -0
- package/src/deployment/contract_deployer.ts +42 -0
- package/src/deployment/deploy_instance.ts +28 -0
- package/src/deployment/index.ts +1 -0
- package/src/deployment/protocol_contracts.ts +17 -0
- package/src/deployment/register_class.ts +19 -0
- package/src/fee/fee_payment_method.ts +25 -0
- package/src/fee/native_fee_payment_method.ts +60 -0
- package/src/fee/private_fee_payment_method.ts +79 -0
- package/src/fee/public_fee_payment_method.ts +79 -0
- package/src/index.ts +150 -0
- package/src/rpc_clients/index.ts +1 -0
- package/src/rpc_clients/pxe_client.ts +63 -0
- package/src/utils/abi_types.ts +16 -0
- package/src/utils/account.ts +32 -0
- package/src/utils/authwit.ts +62 -0
- package/src/utils/cheat_codes.ts +297 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/l1_contracts.ts +21 -0
- package/src/utils/l2_contracts.ts +12 -0
- package/src/utils/pub_key.ts +12 -0
- package/src/utils/pxe.ts +16 -0
- package/src/wallet/account_wallet.ts +94 -0
- package/src/wallet/account_wallet_with_private_key.ts +28 -0
- package/src/wallet/base_wallet.ts +129 -0
- package/src/wallet/create_recipient.ts +13 -0
- package/src/wallet/index.ts +31 -0
- package/src/wallet/signerless_wallet.ts +37 -0
- package/dest/contract_deployer/contract_deployer.d.ts.map +0 -1
- package/dest/contract_deployer/index.d.ts.map +0 -1
- package/dest/utils/secrets.d.ts +0 -8
- package/dest/utils/secrets.d.ts.map +0 -1
- package/dest/utils/secrets.js +0 -10
- /package/dest/{contract_deployer → deployment}/index.d.ts +0 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { PublicKey } from '@aztec/circuit-types';
|
|
2
|
+
import { AztecAddress } from '@aztec/circuits.js';
|
|
3
|
+
import { ContractArtifact } from '@aztec/foundation/abi';
|
|
4
|
+
import { Point } from '@aztec/foundation/fields';
|
|
5
|
+
|
|
6
|
+
import { Wallet } from '../account/wallet.js';
|
|
7
|
+
import { DeployMethod } from '../contract/deploy_method.js';
|
|
8
|
+
import { Contract } from '../contract/index.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A class for deploying contract.
|
|
12
|
+
* @remarks Keeping this around even though we have Aztec.nr contract types because it can be useful for non-TS users.
|
|
13
|
+
*/
|
|
14
|
+
export class ContractDeployer {
|
|
15
|
+
constructor(
|
|
16
|
+
private artifact: ContractArtifact,
|
|
17
|
+
private wallet: Wallet,
|
|
18
|
+
private publicKey?: PublicKey,
|
|
19
|
+
private constructorName?: string,
|
|
20
|
+
) {}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Deploy a contract using the provided ABI and constructor arguments.
|
|
24
|
+
* This function creates a new DeployMethod instance that can be used to send deployment transactions
|
|
25
|
+
* and query deployment status. The method accepts any number of constructor arguments, which will
|
|
26
|
+
* be passed to the contract's constructor during deployment.
|
|
27
|
+
*
|
|
28
|
+
* @param args - The constructor arguments for the contract being deployed.
|
|
29
|
+
* @returns A DeployMethod instance configured with the ABI, PXE, and constructor arguments.
|
|
30
|
+
*/
|
|
31
|
+
public deploy(...args: any[]) {
|
|
32
|
+
const postDeployCtor = (address: AztecAddress, wallet: Wallet) => Contract.at(address, this.artifact, wallet);
|
|
33
|
+
return new DeployMethod(
|
|
34
|
+
this.publicKey ?? Point.ZERO,
|
|
35
|
+
this.wallet,
|
|
36
|
+
this.artifact,
|
|
37
|
+
postDeployCtor,
|
|
38
|
+
args,
|
|
39
|
+
this.constructorName,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ContractInstanceWithAddress } from '@aztec/types/contracts';
|
|
2
|
+
|
|
3
|
+
import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
4
|
+
import { Wallet } from '../wallet/index.js';
|
|
5
|
+
import { getDeployerContract } from './protocol_contracts.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Sets up a call to the canonical deployer contract to publicly deploy a contract instance.
|
|
9
|
+
* @param wallet - The wallet to use for the deployment.
|
|
10
|
+
* @param instance - The instance to deploy.
|
|
11
|
+
* @param opts - Additional options.
|
|
12
|
+
*/
|
|
13
|
+
export function deployInstance(
|
|
14
|
+
wallet: Wallet,
|
|
15
|
+
instance: ContractInstanceWithAddress,
|
|
16
|
+
opts: { /** Set to true to *not* mix in the deployer into the address. */ universalDeploy?: boolean } = {},
|
|
17
|
+
): ContractFunctionInteraction {
|
|
18
|
+
const deployer = getDeployerContract(wallet);
|
|
19
|
+
const { salt, contractClassId, portalContractAddress, publicKeysHash } = instance;
|
|
20
|
+
return deployer.methods.deploy(
|
|
21
|
+
salt,
|
|
22
|
+
contractClassId,
|
|
23
|
+
instance.initializationHash,
|
|
24
|
+
portalContractAddress,
|
|
25
|
+
publicKeysHash,
|
|
26
|
+
!!opts.universalDeploy,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './contract_deployer.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getCanonicalClassRegisterer } from '@aztec/protocol-contracts/class-registerer';
|
|
2
|
+
import { getCanonicalInstanceDeployer } from '@aztec/protocol-contracts/instance-deployer';
|
|
3
|
+
|
|
4
|
+
import { UnsafeContract } from '../contract/unsafe_contract.js';
|
|
5
|
+
import { Wallet } from '../wallet/index.js';
|
|
6
|
+
|
|
7
|
+
/** Returns a Contract wrapper for the class registerer. */
|
|
8
|
+
export function getRegistererContract(wallet: Wallet) {
|
|
9
|
+
const { artifact, instance } = getCanonicalClassRegisterer();
|
|
10
|
+
return new UnsafeContract(instance, artifact, wallet);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Returns a Contract wrapper for the instance deployer. */
|
|
14
|
+
export function getDeployerContract(wallet: Wallet) {
|
|
15
|
+
const { artifact, instance } = getCanonicalInstanceDeployer();
|
|
16
|
+
return new UnsafeContract(instance, artifact, wallet);
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS, getContractClassFromArtifact } from '@aztec/circuits.js';
|
|
2
|
+
import { ContractArtifact, bufferAsFields } from '@aztec/foundation/abi';
|
|
3
|
+
|
|
4
|
+
import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
5
|
+
import { Wallet } from '../wallet/index.js';
|
|
6
|
+
import { getRegistererContract } from './protocol_contracts.js';
|
|
7
|
+
|
|
8
|
+
/** Sets up a call to register a contract class given its artifact. */
|
|
9
|
+
export async function registerContractClass(
|
|
10
|
+
wallet: Wallet,
|
|
11
|
+
artifact: ContractArtifact,
|
|
12
|
+
): Promise<ContractFunctionInteraction> {
|
|
13
|
+
const { artifactHash, privateFunctionsRoot, publicBytecodeCommitment, packedBytecode } =
|
|
14
|
+
getContractClassFromArtifact(artifact);
|
|
15
|
+
const encodedBytecode = bufferAsFields(packedBytecode, MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS);
|
|
16
|
+
const registerer = getRegistererContract(wallet);
|
|
17
|
+
await wallet.addCapsule(encodedBytecode);
|
|
18
|
+
return registerer.methods.register(artifactHash, privateFunctionsRoot, publicBytecodeCommitment);
|
|
19
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FunctionCall } from '@aztec/circuit-types';
|
|
2
|
+
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
3
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Holds information about how the fee for a transaction is to be paid.
|
|
7
|
+
*/
|
|
8
|
+
export interface FeePaymentMethod {
|
|
9
|
+
/**
|
|
10
|
+
* The asset used to pay the fee.
|
|
11
|
+
*/
|
|
12
|
+
getAsset(): AztecAddress;
|
|
13
|
+
/**
|
|
14
|
+
* Address which will hold the fee payment.
|
|
15
|
+
*/
|
|
16
|
+
getPaymentContract(): AztecAddress;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Creates a function call to pay the fee in the given asset.
|
|
20
|
+
* TODO(fees) replace maxFee with gas limits
|
|
21
|
+
* @param maxFee - The maximum fee to be paid in the given asset.
|
|
22
|
+
* @returns The function call to pay the fee.
|
|
23
|
+
*/
|
|
24
|
+
getFunctionCalls(maxFee: Fr): Promise<FunctionCall[]>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { FunctionCall } from '@aztec/circuit-types';
|
|
2
|
+
import { FunctionData } from '@aztec/circuits.js';
|
|
3
|
+
import { FunctionSelector } from '@aztec/foundation/abi';
|
|
4
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
5
|
+
import { GasTokenAddress } from '@aztec/protocol-contracts/gas-token';
|
|
6
|
+
|
|
7
|
+
import { FeePaymentMethod } from './fee_payment_method.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Pay fee directly in the native gas token.
|
|
11
|
+
*/
|
|
12
|
+
export class NativeFeePaymentMethod implements FeePaymentMethod {
|
|
13
|
+
static #GAS_TOKEN = GasTokenAddress;
|
|
14
|
+
|
|
15
|
+
constructor() {}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Gets the native gas asset used to pay the fee.
|
|
19
|
+
* @returns The asset used to pay the fee.
|
|
20
|
+
*/
|
|
21
|
+
getAsset() {
|
|
22
|
+
return NativeFeePaymentMethod.#GAS_TOKEN;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The contract responsible for fee payment. This will be the same as the asset.
|
|
27
|
+
* @returns The contract address responsible for holding the fee payment.
|
|
28
|
+
*/
|
|
29
|
+
getPaymentContract() {
|
|
30
|
+
return NativeFeePaymentMethod.#GAS_TOKEN;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Fee payments in the native gas token are always public.
|
|
35
|
+
* @returns false
|
|
36
|
+
*/
|
|
37
|
+
isPrivateFeePayment(): boolean {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Creates a function call to pay the fee in gas token..
|
|
43
|
+
* @param feeLimit - The maximum fee to be paid in gas token.
|
|
44
|
+
* @returns A function call
|
|
45
|
+
*/
|
|
46
|
+
getFunctionCalls(feeLimit: Fr): Promise<FunctionCall[]> {
|
|
47
|
+
return Promise.resolve([
|
|
48
|
+
{
|
|
49
|
+
to: NativeFeePaymentMethod.#GAS_TOKEN,
|
|
50
|
+
functionData: new FunctionData(FunctionSelector.fromSignature('check_balance(Field)'), false, false, false),
|
|
51
|
+
args: [feeLimit],
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
to: NativeFeePaymentMethod.#GAS_TOKEN,
|
|
55
|
+
functionData: new FunctionData(FunctionSelector.fromSignature('pay_fee(Field)'), false, false, false),
|
|
56
|
+
args: [feeLimit],
|
|
57
|
+
},
|
|
58
|
+
]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { FunctionCall } from '@aztec/circuit-types';
|
|
2
|
+
import { FunctionData } from '@aztec/circuits.js';
|
|
3
|
+
import { FunctionSelector } from '@aztec/foundation/abi';
|
|
4
|
+
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
5
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
6
|
+
|
|
7
|
+
import { computeAuthWitMessageHash } from '../utils/authwit.js';
|
|
8
|
+
import { AccountWalletWithPrivateKey } from '../wallet/account_wallet_with_private_key.js';
|
|
9
|
+
import { FeePaymentMethod } from './fee_payment_method.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Holds information about how the fee for a transaction is to be paid.
|
|
13
|
+
*/
|
|
14
|
+
export class PrivateFeePaymentMethod implements FeePaymentMethod {
|
|
15
|
+
constructor(
|
|
16
|
+
/**
|
|
17
|
+
* The asset used to pay the fee.
|
|
18
|
+
*/
|
|
19
|
+
private asset: AztecAddress,
|
|
20
|
+
/**
|
|
21
|
+
* Address which will hold the fee payment.
|
|
22
|
+
*/
|
|
23
|
+
private paymentContract: AztecAddress,
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* An auth witness provider to authorize fee payments
|
|
27
|
+
*/
|
|
28
|
+
private wallet: AccountWalletWithPrivateKey,
|
|
29
|
+
) {}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The asset used to pay the fee.
|
|
33
|
+
* @returns The asset used to pay the fee.
|
|
34
|
+
*/
|
|
35
|
+
getAsset() {
|
|
36
|
+
return this.asset;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The address which will facilitate the fee payment.
|
|
41
|
+
* @returns The contract address responsible for holding the fee payment.
|
|
42
|
+
*/
|
|
43
|
+
getPaymentContract() {
|
|
44
|
+
return this.paymentContract;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Creates a function call to pay the fee in the given asset.
|
|
49
|
+
* @param maxFee - The maximum fee to be paid in the given asset.
|
|
50
|
+
* @returns The function call to pay the fee.
|
|
51
|
+
*/
|
|
52
|
+
async getFunctionCalls(maxFee: Fr): Promise<FunctionCall[]> {
|
|
53
|
+
const nonce = Fr.random();
|
|
54
|
+
const messageHash = computeAuthWitMessageHash(this.paymentContract, {
|
|
55
|
+
args: [this.wallet.getAddress(), this.paymentContract, maxFee, nonce],
|
|
56
|
+
functionData: new FunctionData(
|
|
57
|
+
FunctionSelector.fromSignature('unshield((Field),(Field),Field,Field)'),
|
|
58
|
+
false,
|
|
59
|
+
true,
|
|
60
|
+
false,
|
|
61
|
+
),
|
|
62
|
+
to: this.asset,
|
|
63
|
+
});
|
|
64
|
+
await this.wallet.createAuthWitness(messageHash);
|
|
65
|
+
|
|
66
|
+
return [
|
|
67
|
+
{
|
|
68
|
+
to: this.getPaymentContract(),
|
|
69
|
+
functionData: new FunctionData(
|
|
70
|
+
FunctionSelector.fromSignature('fee_entrypoint_private(Field,(Field),Field)'),
|
|
71
|
+
false,
|
|
72
|
+
true,
|
|
73
|
+
false,
|
|
74
|
+
),
|
|
75
|
+
args: [maxFee, this.asset, nonce],
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { FunctionCall } from '@aztec/circuit-types';
|
|
2
|
+
import { FunctionData } from '@aztec/circuits.js';
|
|
3
|
+
import { FunctionSelector } from '@aztec/foundation/abi';
|
|
4
|
+
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
5
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
6
|
+
|
|
7
|
+
import { computeAuthWitMessageHash } from '../utils/authwit.js';
|
|
8
|
+
import { AccountWallet } from '../wallet/account_wallet.js';
|
|
9
|
+
import { FeePaymentMethod } from './fee_payment_method.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Holds information about how the fee for a transaction is to be paid.
|
|
13
|
+
*/
|
|
14
|
+
export class PublicFeePaymentMethod implements FeePaymentMethod {
|
|
15
|
+
constructor(
|
|
16
|
+
/**
|
|
17
|
+
* The asset used to pay the fee.
|
|
18
|
+
*/
|
|
19
|
+
private asset: AztecAddress,
|
|
20
|
+
/**
|
|
21
|
+
* Address which will hold the fee payment.
|
|
22
|
+
*/
|
|
23
|
+
private paymentContract: AztecAddress,
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* An auth witness provider to authorize fee payments
|
|
27
|
+
*/
|
|
28
|
+
private wallet: AccountWallet,
|
|
29
|
+
) {}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The asset used to pay the fee.
|
|
33
|
+
* @returns The asset used to pay the fee.
|
|
34
|
+
*/
|
|
35
|
+
getAsset() {
|
|
36
|
+
return this.asset;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The address which will facilitate the fee payment.
|
|
41
|
+
* @returns The contract address responsible for holding the fee payment.
|
|
42
|
+
*/
|
|
43
|
+
getPaymentContract() {
|
|
44
|
+
return this.paymentContract;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Creates a function call to pay the fee in the given asset.
|
|
49
|
+
* @param maxFee - The maximum fee to be paid in the given asset.
|
|
50
|
+
* @returns The function call to pay the fee.
|
|
51
|
+
*/
|
|
52
|
+
getFunctionCalls(maxFee: Fr): Promise<FunctionCall[]> {
|
|
53
|
+
const nonce = Fr.random();
|
|
54
|
+
const messageHash = computeAuthWitMessageHash(this.paymentContract, {
|
|
55
|
+
args: [this.wallet.getAddress(), this.paymentContract, maxFee, nonce],
|
|
56
|
+
functionData: new FunctionData(
|
|
57
|
+
FunctionSelector.fromSignature('transfer_public((Field),(Field),Field,Field)'),
|
|
58
|
+
false,
|
|
59
|
+
false,
|
|
60
|
+
false,
|
|
61
|
+
),
|
|
62
|
+
to: this.asset,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return Promise.resolve([
|
|
66
|
+
this.wallet.setPublicAuth(messageHash, true).request(),
|
|
67
|
+
{
|
|
68
|
+
to: this.getPaymentContract(),
|
|
69
|
+
functionData: new FunctionData(
|
|
70
|
+
FunctionSelector.fromSignature('fee_entrypoint_public(Field,(Field),Field)'),
|
|
71
|
+
false,
|
|
72
|
+
true,
|
|
73
|
+
false,
|
|
74
|
+
),
|
|
75
|
+
args: [maxFee, this.asset, nonce],
|
|
76
|
+
},
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is our public api.
|
|
3
|
+
* Do NOT "export * from ..." here.
|
|
4
|
+
* Everything here should be explicit, to ensure we can clearly see everything we're exposing to the world.
|
|
5
|
+
* If it's exposed, people will use it, and then we can't remove/change the api without breaking client code.
|
|
6
|
+
* At the time of writing we overexpose things that should only be internal.
|
|
7
|
+
*
|
|
8
|
+
* TODO: Review and narrow scope of public api.
|
|
9
|
+
* We should also consider exposing subsections of the api via package.json exports, like we do with foundation.
|
|
10
|
+
* This can allow consumers to import much smaller parts of the library to incur less overhead.
|
|
11
|
+
* It will also allow web bundlers do perform intelligent chunking of bundles etc.
|
|
12
|
+
* Some work as been done on this within the api folder, providing the alternative import style of e.g.:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { TxHash } from '@aztec.js/tx_hash'
|
|
15
|
+
* import { type ContractArtifact, type FunctionArtifact, FunctionSelector } from '@aztec/aztec.js/abi';
|
|
16
|
+
* import { AztecAddress } from '@aztec/aztec.js/aztec_address';
|
|
17
|
+
* import { EthAddress } from '@aztec/aztec.js/eth_address';
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* TODO: Ultimately reimplement this mega exporter by mega exporting a granular api (then deprecate it).
|
|
21
|
+
*/
|
|
22
|
+
export {
|
|
23
|
+
WaitOpts,
|
|
24
|
+
ContractFunctionInteraction,
|
|
25
|
+
Contract,
|
|
26
|
+
ContractBase,
|
|
27
|
+
ContractMethod,
|
|
28
|
+
SentTx,
|
|
29
|
+
BatchCall,
|
|
30
|
+
DeployMethod,
|
|
31
|
+
DeploySentTx,
|
|
32
|
+
} from './contract/index.js';
|
|
33
|
+
|
|
34
|
+
export { ContractDeployer } from './deployment/index.js';
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
generatePublicKey,
|
|
38
|
+
FieldLike,
|
|
39
|
+
EthAddressLike,
|
|
40
|
+
CheatCodes,
|
|
41
|
+
AztecAddressLike,
|
|
42
|
+
FunctionSelectorLike,
|
|
43
|
+
WrappedFieldLike,
|
|
44
|
+
isContractDeployed,
|
|
45
|
+
EthCheatCodes,
|
|
46
|
+
computeAuthWitMessageHash,
|
|
47
|
+
computeInnerAuthWitHash,
|
|
48
|
+
computeOuterAuthWitHash,
|
|
49
|
+
waitForPXE,
|
|
50
|
+
waitForAccountSynch,
|
|
51
|
+
} from './utils/index.js';
|
|
52
|
+
|
|
53
|
+
export { createPXEClient } from './rpc_clients/index.js';
|
|
54
|
+
|
|
55
|
+
export { AuthWitnessProvider } from './account/index.js';
|
|
56
|
+
|
|
57
|
+
export { AccountContract } from './account/index.js';
|
|
58
|
+
export { AccountManager } from './account_manager/index.js';
|
|
59
|
+
|
|
60
|
+
export { AccountWalletWithPrivateKey, AccountWallet, Wallet, SignerlessWallet } from './wallet/index.js';
|
|
61
|
+
|
|
62
|
+
// // TODO https://github.com/AztecProtocol/aztec-packages/issues/2632 --> FunctionSelector might not need to be exposed
|
|
63
|
+
// // here once the issue is resolved.
|
|
64
|
+
export {
|
|
65
|
+
AztecAddress,
|
|
66
|
+
EthAddress,
|
|
67
|
+
Fr,
|
|
68
|
+
Fq,
|
|
69
|
+
GlobalVariables,
|
|
70
|
+
GrumpkinScalar,
|
|
71
|
+
Point,
|
|
72
|
+
getContractInstanceFromDeployParams,
|
|
73
|
+
getContractClassFromArtifact,
|
|
74
|
+
INITIAL_L2_BLOCK_NUM,
|
|
75
|
+
} from '@aztec/circuits.js';
|
|
76
|
+
|
|
77
|
+
export { computeMessageSecretHash } from '@aztec/circuits.js/hash';
|
|
78
|
+
|
|
79
|
+
export { Grumpkin, Schnorr } from '@aztec/circuits.js/barretenberg';
|
|
80
|
+
|
|
81
|
+
export {
|
|
82
|
+
AuthWitness,
|
|
83
|
+
AztecNode,
|
|
84
|
+
Body,
|
|
85
|
+
CompleteAddress,
|
|
86
|
+
ContractData,
|
|
87
|
+
DeployedContract,
|
|
88
|
+
ExtendedContractData,
|
|
89
|
+
ExtendedNote,
|
|
90
|
+
FunctionCall,
|
|
91
|
+
GrumpkinPrivateKey,
|
|
92
|
+
L1ToL2Message,
|
|
93
|
+
L1Actor,
|
|
94
|
+
L2Actor,
|
|
95
|
+
L2Block,
|
|
96
|
+
L2BlockL2Logs,
|
|
97
|
+
LogFilter,
|
|
98
|
+
LogId,
|
|
99
|
+
LogType,
|
|
100
|
+
MerkleTreeId,
|
|
101
|
+
Note,
|
|
102
|
+
PXE,
|
|
103
|
+
PackedArguments,
|
|
104
|
+
PartialAddress,
|
|
105
|
+
PublicKey,
|
|
106
|
+
SyncStatus,
|
|
107
|
+
Tx,
|
|
108
|
+
TxExecutionRequest,
|
|
109
|
+
TxHash,
|
|
110
|
+
TxReceipt,
|
|
111
|
+
TxStatus,
|
|
112
|
+
UnencryptedL2Log,
|
|
113
|
+
createAztecNodeClient,
|
|
114
|
+
emptyFunctionCall,
|
|
115
|
+
merkleTreeIds,
|
|
116
|
+
mockTx,
|
|
117
|
+
Comparator,
|
|
118
|
+
} from '@aztec/circuit-types';
|
|
119
|
+
export { NodeInfo } from '@aztec/types/interfaces';
|
|
120
|
+
|
|
121
|
+
export { ContractInstanceWithAddress, ContractClassWithId } from '@aztec/types/contracts';
|
|
122
|
+
|
|
123
|
+
// TODO: These kinds of things have no place on our public api.
|
|
124
|
+
// External devs will almost certainly have their own methods of doing these things.
|
|
125
|
+
// If we want to use them in our own "aztec.js consuming code", import them from foundation as needed.
|
|
126
|
+
export { encodeArguments } from '@aztec/foundation/abi';
|
|
127
|
+
export { sha256 } from '@aztec/foundation/crypto';
|
|
128
|
+
export { DebugLogger, createDebugLogger, onLog } from '@aztec/foundation/log';
|
|
129
|
+
export { retry, retryUntil } from '@aztec/foundation/retry';
|
|
130
|
+
export { sleep } from '@aztec/foundation/sleep';
|
|
131
|
+
export { elapsed } from '@aztec/foundation/timer';
|
|
132
|
+
export { fileURLToPath } from '@aztec/foundation/url';
|
|
133
|
+
export { to2Fields, toBigInt } from '@aztec/foundation/serialize';
|
|
134
|
+
export { toBigIntBE } from '@aztec/foundation/bigint-buffer';
|
|
135
|
+
export { makeFetch } from '@aztec/foundation/json-rpc/client';
|
|
136
|
+
export { FieldsOf } from '@aztec/foundation/types';
|
|
137
|
+
|
|
138
|
+
export {
|
|
139
|
+
DeployL1Contracts,
|
|
140
|
+
L1ContractArtifactsForDeployment,
|
|
141
|
+
deployL1Contract,
|
|
142
|
+
deployL1Contracts,
|
|
143
|
+
} from '@aztec/ethereum';
|
|
144
|
+
|
|
145
|
+
// Start of section that exports public api via granular api.
|
|
146
|
+
// Here you *can* do `export *` as the granular api defacto exports things explicitly.
|
|
147
|
+
// This entire index file will be deprecated at some point after we're satisfied.
|
|
148
|
+
export * from './api/init.js';
|
|
149
|
+
export * from './api/abi.js';
|
|
150
|
+
export * from './api/fee.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pxe_client.js';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthWitness,
|
|
3
|
+
ContractData,
|
|
4
|
+
ExtendedContractData,
|
|
5
|
+
ExtendedNote,
|
|
6
|
+
ExtendedUnencryptedL2Log,
|
|
7
|
+
L2Block,
|
|
8
|
+
L2BlockL2Logs,
|
|
9
|
+
LogId,
|
|
10
|
+
Note,
|
|
11
|
+
NullifierMembershipWitness,
|
|
12
|
+
PXE,
|
|
13
|
+
Tx,
|
|
14
|
+
TxEffect,
|
|
15
|
+
TxExecutionRequest,
|
|
16
|
+
TxHash,
|
|
17
|
+
TxReceipt,
|
|
18
|
+
} from '@aztec/circuit-types';
|
|
19
|
+
import {
|
|
20
|
+
AztecAddress,
|
|
21
|
+
CompleteAddress,
|
|
22
|
+
EthAddress,
|
|
23
|
+
Fr,
|
|
24
|
+
FunctionSelector,
|
|
25
|
+
GrumpkinScalar,
|
|
26
|
+
Point,
|
|
27
|
+
} from '@aztec/circuits.js';
|
|
28
|
+
import { createJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Creates a JSON-RPC client to remotely talk to PXE.
|
|
32
|
+
* @param url - The URL of the PXE.
|
|
33
|
+
* @param fetch - The fetch implementation to use.
|
|
34
|
+
* @returns A JSON-RPC client of PXE.
|
|
35
|
+
*/
|
|
36
|
+
export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3], false)): PXE =>
|
|
37
|
+
createJsonRpcClient<PXE>(
|
|
38
|
+
url,
|
|
39
|
+
{
|
|
40
|
+
AuthWitness,
|
|
41
|
+
AztecAddress,
|
|
42
|
+
CompleteAddress,
|
|
43
|
+
ContractData,
|
|
44
|
+
FunctionSelector,
|
|
45
|
+
EthAddress,
|
|
46
|
+
ExtendedContractData,
|
|
47
|
+
ExtendedNote,
|
|
48
|
+
ExtendedUnencryptedL2Log,
|
|
49
|
+
Fr,
|
|
50
|
+
GrumpkinScalar,
|
|
51
|
+
L2Block,
|
|
52
|
+
TxEffect,
|
|
53
|
+
LogId,
|
|
54
|
+
Note,
|
|
55
|
+
Point,
|
|
56
|
+
TxExecutionRequest,
|
|
57
|
+
TxHash,
|
|
58
|
+
},
|
|
59
|
+
{ Tx, TxReceipt, L2BlockL2Logs, NullifierMembershipWitness },
|
|
60
|
+
false,
|
|
61
|
+
'pxe',
|
|
62
|
+
fetch,
|
|
63
|
+
);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AztecAddress, EthAddress, Fr, FunctionSelector } from '@aztec/circuits.js';
|
|
2
|
+
|
|
3
|
+
/** Any type that can be converted into a field for a contract call. */
|
|
4
|
+
export type FieldLike = Fr | Buffer | bigint | number | { /** Converts to field */ toField: () => Fr };
|
|
5
|
+
|
|
6
|
+
/** Any type that can be converted into an EthAddress Aztec.nr struct. */
|
|
7
|
+
export type EthAddressLike = { /** Wrapped address */ address: FieldLike } | EthAddress;
|
|
8
|
+
|
|
9
|
+
/** Any type that can be converted into an AztecAddress Aztec.nr struct. */
|
|
10
|
+
export type AztecAddressLike = { /** Wrapped address */ address: FieldLike } | AztecAddress;
|
|
11
|
+
|
|
12
|
+
/** Any type that can be converted into an FunctionSelector Aztec.nr struct. */
|
|
13
|
+
export type FunctionSelectorLike = FieldLike | FunctionSelector;
|
|
14
|
+
|
|
15
|
+
/** Any type that can be converted into a struct with a single `inner` field. */
|
|
16
|
+
export type WrappedFieldLike = { /** Wrapped value */ inner: FieldLike } | FieldLike;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CompleteAddress, PXE } from '@aztec/circuit-types';
|
|
2
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
3
|
+
|
|
4
|
+
import { DefaultWaitOpts, WaitOpts } from '../contract/index.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Waits for the account to finish synchronizing with the PXE Service.
|
|
8
|
+
* @param pxe - PXE instance
|
|
9
|
+
* @param address - Address to wait for synch
|
|
10
|
+
* @param opts - Wait options
|
|
11
|
+
*/
|
|
12
|
+
export async function waitForAccountSynch(
|
|
13
|
+
pxe: PXE,
|
|
14
|
+
address: CompleteAddress,
|
|
15
|
+
{ interval, timeout }: WaitOpts = DefaultWaitOpts,
|
|
16
|
+
): Promise<void> {
|
|
17
|
+
const publicKey = address.publicKey.toString();
|
|
18
|
+
await retryUntil(
|
|
19
|
+
async () => {
|
|
20
|
+
const status = await pxe.getSyncStatus();
|
|
21
|
+
const accountSynchedToBlock = status.notes[publicKey];
|
|
22
|
+
if (typeof accountSynchedToBlock === 'undefined') {
|
|
23
|
+
return false;
|
|
24
|
+
} else {
|
|
25
|
+
return accountSynchedToBlock >= status.blocks;
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
'waitForAccountSynch',
|
|
29
|
+
timeout,
|
|
30
|
+
interval,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { FunctionCall, PackedArguments } from '@aztec/circuit-types';
|
|
2
|
+
import { AztecAddress, Fr, GeneratorIndex } from '@aztec/circuits.js';
|
|
3
|
+
import { pedersenHash } from '@aztec/foundation/crypto';
|
|
4
|
+
|
|
5
|
+
// docs:start:authwit_computeAuthWitMessageHash
|
|
6
|
+
/**
|
|
7
|
+
* Compute an authentication witness message hash from a caller and a request
|
|
8
|
+
* H(target: AztecAddress, H(caller: AztecAddress, selector: Field, args_hash: Field))
|
|
9
|
+
* Example usage would be `bob` authenticating `alice` to perform a transfer of `10`
|
|
10
|
+
* tokens from his account to herself:
|
|
11
|
+
* H(token, H(alice, transfer_selector, H(bob, alice, 10, nonce)))
|
|
12
|
+
* `bob` then signs the message hash and gives it to `alice` who can then perform the
|
|
13
|
+
* action.
|
|
14
|
+
* @param caller - The caller approved to make the call
|
|
15
|
+
* @param request - The request to be made (function call)
|
|
16
|
+
* @returns The message hash for the witness
|
|
17
|
+
*/
|
|
18
|
+
export const computeAuthWitMessageHash = (caller: AztecAddress, request: FunctionCall) => {
|
|
19
|
+
return computeOuterAuthWitHash(
|
|
20
|
+
request.to.toField(),
|
|
21
|
+
computeInnerAuthWitHash([
|
|
22
|
+
caller.toField(),
|
|
23
|
+
request.functionData.selector.toField(),
|
|
24
|
+
PackedArguments.fromArgs(request.args).hash,
|
|
25
|
+
]),
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
// docs:end:authwit_computeAuthWitMessageHash
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Compute the inner hash for an authentication witness.
|
|
32
|
+
* This is the "intent" of the message, before siloed with the consumer.
|
|
33
|
+
* It is used as part of the `computeAuthWitMessageHash` but can also be used
|
|
34
|
+
* in case the message is not a "call" to a function, but arbitrary data.
|
|
35
|
+
* @param args - The arguments to hash
|
|
36
|
+
* @returns The inner hash for the witness
|
|
37
|
+
*/
|
|
38
|
+
export const computeInnerAuthWitHash = (args: Fr[]) => {
|
|
39
|
+
return pedersenHash(
|
|
40
|
+
args.map(fr => fr.toBuffer()),
|
|
41
|
+
GeneratorIndex.AUTHWIT_INNER,
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Compute the outer hash for an authentication witness.
|
|
47
|
+
* This is the value siloed with its "consumer" and what the `on_behalf_of`
|
|
48
|
+
* should be signing.
|
|
49
|
+
* The consumer is who will be consuming the message, for token approvals it
|
|
50
|
+
* is the token contract itself (because the token makes the call to check the approval).
|
|
51
|
+
* It is used as part of the `computeAuthWitMessageHash` but can also be used
|
|
52
|
+
* in case the message is not a "call" to a function, but arbitrary data.
|
|
53
|
+
* @param consumer - The address that can "consume" the authwit
|
|
54
|
+
* @param innerHash - The inner hash for the witness
|
|
55
|
+
* @returns The outer hash for the witness
|
|
56
|
+
*/
|
|
57
|
+
export const computeOuterAuthWitHash = (consumer: AztecAddress, innerHash: Fr) => {
|
|
58
|
+
return pedersenHash(
|
|
59
|
+
[consumer.toField(), innerHash].map(fr => fr.toBuffer()),
|
|
60
|
+
GeneratorIndex.AUTHWIT_OUTER,
|
|
61
|
+
);
|
|
62
|
+
};
|