@aztec/aztec.js 3.0.0-canary.a9708bd → 3.0.0-devnet.2-patch.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/README.md +1 -1
- package/dest/account/account.d.ts +59 -0
- package/dest/account/account.d.ts.map +1 -0
- package/dest/account/account.js +59 -0
- package/dest/account/account_contract.d.ts +7 -7
- package/dest/account/account_contract.d.ts.map +1 -1
- package/dest/account/account_contract.js +0 -1
- package/dest/account/account_with_secret_key.d.ts +24 -0
- package/dest/account/account_with_secret_key.d.ts.map +1 -0
- package/dest/{wallet/account_wallet_with_private_key.js → account/account_with_secret_key.js} +5 -5
- package/dest/account/index.d.ts +3 -6
- package/dest/account/index.d.ts.map +1 -1
- package/dest/account/index.js +1 -4
- package/dest/account/interface.d.ts +2 -2
- package/dest/account/interface.d.ts.map +1 -1
- package/dest/account/signerless_account.d.ts +23 -0
- package/dest/account/signerless_account.d.ts.map +1 -0
- package/dest/account/signerless_account.js +27 -0
- package/dest/api/abi.d.ts +2 -1
- package/dest/api/abi.d.ts.map +1 -1
- package/dest/api/account.d.ts +6 -3
- package/dest/api/account.d.ts.map +1 -1
- package/dest/api/account.js +4 -1
- package/dest/api/addresses.d.ts +2 -1
- package/dest/api/addresses.d.ts.map +1 -1
- package/dest/api/addresses.js +1 -0
- package/dest/api/authorization.d.ts +3 -1
- package/dest/api/authorization.d.ts.map +1 -1
- package/dest/api/authorization.js +2 -0
- package/dest/api/block.d.ts +3 -0
- package/dest/api/block.d.ts.map +1 -0
- package/dest/api/block.js +2 -0
- package/dest/api/contract.d.ts +8 -9
- package/dest/api/contract.d.ts.map +1 -1
- package/dest/api/contract.js +6 -6
- package/dest/api/crypto.d.ts +2 -0
- package/dest/api/crypto.d.ts.map +1 -0
- package/dest/api/crypto.js +1 -0
- package/dest/api/deployment.d.ts +1 -1
- package/dest/api/eth_address.d.ts +1 -1
- package/dest/api/ethereum.d.ts +1 -2
- package/dest/api/ethereum.d.ts.map +1 -1
- package/dest/api/ethereum.js +0 -1
- package/dest/api/events.d.ts +12 -0
- package/dest/api/events.d.ts.map +1 -0
- package/dest/api/events.js +30 -0
- package/dest/api/fee.d.ts +2 -3
- package/dest/api/fee.d.ts.map +1 -1
- package/dest/api/fee.js +0 -1
- package/dest/api/fee_testing.d.ts +1 -1
- package/dest/api/fields.d.ts +3 -2
- package/dest/api/fields.d.ts.map +1 -1
- package/dest/api/fields.js +2 -1
- package/dest/api/keys.d.ts +4 -0
- package/dest/api/keys.d.ts.map +1 -0
- package/dest/api/keys.js +3 -0
- package/dest/api/log.d.ts +2 -1
- package/dest/api/log.d.ts.map +1 -1
- package/dest/api/log.js +1 -0
- package/dest/api/messaging.d.ts +3 -0
- package/dest/api/messaging.d.ts.map +1 -0
- package/dest/api/messaging.js +2 -0
- package/dest/api/node.d.ts +21 -0
- package/dest/api/node.d.ts.map +1 -0
- package/dest/api/node.js +18 -0
- package/dest/api/note.d.ts +2 -0
- package/dest/api/note.d.ts.map +1 -0
- package/dest/api/note.js +1 -0
- package/dest/api/protocol.d.ts +3 -0
- package/dest/api/protocol.d.ts.map +1 -0
- package/dest/api/protocol.js +2 -0
- package/dest/api/trees.d.ts +3 -0
- package/dest/api/trees.d.ts.map +1 -0
- package/dest/api/trees.js +2 -0
- package/dest/api/tx.d.ts +2 -0
- package/dest/api/tx.d.ts.map +1 -0
- package/dest/api/tx.js +1 -0
- package/dest/api/utils.d.ts +11 -7
- package/dest/api/utils.d.ts.map +1 -1
- package/dest/api/utils.js +10 -5
- package/dest/api/wallet.d.ts +4 -2
- package/dest/api/wallet.d.ts.map +1 -1
- package/dest/api/wallet.js +3 -1
- package/dest/authorization/call_authorization_request.d.ts +2 -23
- package/dest/authorization/call_authorization_request.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.d.ts +7 -50
- package/dest/contract/base_contract_interaction.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.js +6 -106
- package/dest/contract/batch_call.d.ts +14 -23
- package/dest/contract/batch_call.d.ts.map +1 -1
- package/dest/contract/batch_call.js +72 -64
- package/dest/contract/checker.d.ts +1 -1
- package/dest/contract/contract.d.ts +3 -3
- package/dest/contract/contract.d.ts.map +1 -1
- package/dest/contract/contract.js +5 -16
- package/dest/contract/contract_base.d.ts +5 -12
- package/dest/contract/contract_base.d.ts.map +1 -1
- package/dest/contract/contract_base.js +5 -12
- package/dest/contract/contract_function_interaction.d.ts +32 -43
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +47 -56
- package/dest/contract/deploy_method.d.ts +69 -61
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +72 -88
- package/dest/contract/deploy_sent_tx.d.ts +12 -8
- package/dest/contract/deploy_sent_tx.d.ts.map +1 -1
- package/dest/contract/deploy_sent_tx.js +15 -12
- package/dest/contract/get_gas_limits.d.ts +1 -1
- package/dest/contract/interaction_options.d.ts +76 -21
- package/dest/contract/interaction_options.d.ts.map +1 -1
- package/dest/contract/interaction_options.js +45 -3
- package/dest/contract/protocol_contracts.d.ts +1 -1
- package/dest/contract/sent_tx.d.ts +5 -6
- package/dest/contract/sent_tx.d.ts.map +1 -1
- package/dest/contract/sent_tx.js +6 -6
- package/dest/contract/unsafe_contract.d.ts +1 -1
- package/dest/contract/unsafe_contract.d.ts.map +1 -1
- package/dest/contract/unsafe_contract.js +1 -1
- package/dest/contract/wait_for_proven.d.ts +4 -4
- package/dest/contract/wait_for_proven.d.ts.map +1 -1
- package/dest/contract/wait_for_proven.js +2 -2
- package/dest/deployment/broadcast_function.d.ts +1 -1
- package/dest/deployment/broadcast_function.js +1 -1
- package/dest/deployment/contract_deployer.d.ts +1 -1
- package/dest/deployment/contract_deployer.d.ts.map +1 -1
- package/dest/deployment/contract_deployer.js +1 -1
- package/dest/deployment/publish_class.d.ts +1 -1
- package/dest/deployment/publish_class.js +1 -1
- package/dest/deployment/publish_instance.d.ts +2 -2
- package/dest/deployment/publish_instance.d.ts.map +1 -1
- package/dest/deployment/publish_instance.js +2 -5
- package/dest/ethereum/portal_manager.d.ts +7 -10
- package/dest/ethereum/portal_manager.d.ts.map +1 -1
- package/dest/ethereum/portal_manager.js +43 -19
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts +14 -9
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -1
- package/dest/fee/fee_juice_payment_method_with_claim.js +24 -15
- package/dest/fee/fee_payment_method.d.ts +26 -0
- package/dest/fee/fee_payment_method.d.ts.map +1 -0
- package/dest/fee/fee_payment_method.js +3 -0
- package/dest/fee/private_fee_payment_method.d.ts +24 -7
- package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/private_fee_payment_method.js +38 -17
- package/dest/fee/public_fee_payment_method.d.ts +24 -7
- package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/public_fee_payment_method.js +41 -18
- package/dest/fee/sponsored_fee_payment.d.ts +4 -2
- package/dest/fee/sponsored_fee_payment.d.ts.map +1 -1
- package/dest/fee/sponsored_fee_payment.js +6 -2
- package/dest/utils/abi_types.d.ts +2 -2
- package/dest/utils/abi_types.d.ts.map +1 -1
- package/dest/utils/authwit.d.ts +80 -28
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +231 -25
- package/dest/utils/cross_chain.d.ts +24 -0
- package/dest/utils/cross_chain.d.ts.map +1 -0
- package/dest/utils/cross_chain.js +30 -0
- package/dest/utils/fee_juice.d.ts +4 -3
- package/dest/utils/fee_juice.d.ts.map +1 -1
- package/dest/utils/fee_juice.js +4 -3
- package/dest/utils/field_compressed_string.d.ts +1 -1
- package/dest/utils/field_compressed_string.d.ts.map +1 -1
- package/dest/utils/field_compressed_string.js +1 -1
- package/dest/utils/node.d.ts +2 -2
- package/dest/utils/node.d.ts.map +1 -1
- package/dest/utils/pub_key.d.ts +2 -2
- package/dest/utils/pub_key.d.ts.map +1 -1
- package/dest/utils/pub_key.js +2 -3
- package/dest/wallet/account_entrypoint_meta_payment_method.d.ts +34 -0
- package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -0
- package/dest/wallet/account_entrypoint_meta_payment_method.js +76 -0
- package/dest/wallet/account_manager.d.ts +66 -0
- package/dest/wallet/account_manager.d.ts.map +1 -0
- package/dest/wallet/account_manager.js +113 -0
- package/dest/wallet/deploy_account_method.d.ts +52 -0
- package/dest/wallet/deploy_account_method.d.ts.map +1 -0
- package/dest/wallet/deploy_account_method.js +77 -0
- package/dest/wallet/index.d.ts +2 -16
- package/dest/wallet/index.d.ts.map +1 -1
- package/dest/wallet/index.js +1 -19
- package/dest/wallet/wallet.d.ts +2012 -7
- package/dest/wallet/wallet.d.ts.map +1 -1
- package/dest/wallet/wallet.js +198 -3
- package/package.json +29 -24
- package/src/account/account.ts +96 -0
- package/src/account/account_contract.ts +5 -7
- package/src/{wallet/account_wallet_with_private_key.ts → account/account_with_secret_key.ts} +7 -9
- package/src/account/index.ts +2 -5
- package/src/account/interface.ts +1 -1
- package/src/account/signerless_account.ts +45 -0
- package/src/api/abi.ts +11 -0
- package/src/api/account.ts +5 -2
- package/src/api/addresses.ts +1 -0
- package/src/api/authorization.ts +11 -0
- package/src/api/block.ts +2 -0
- package/src/api/contract.ts +20 -11
- package/src/api/crypto.ts +1 -0
- package/src/api/ethereum.ts +0 -1
- package/src/api/events.ts +44 -0
- package/src/api/fee.ts +1 -2
- package/src/api/fields.ts +2 -1
- package/src/api/keys.ts +8 -0
- package/src/api/log.ts +1 -0
- package/src/api/messaging.ts +2 -0
- package/src/api/node.ts +20 -0
- package/src/api/note.ts +1 -0
- package/src/api/protocol.ts +2 -0
- package/src/api/trees.ts +2 -0
- package/src/api/tx.ts +13 -0
- package/src/api/utils.ts +12 -19
- package/src/api/wallet.ts +31 -5
- package/src/authorization/call_authorization_request.ts +1 -1
- package/src/contract/base_contract_interaction.ts +9 -139
- package/src/contract/batch_call.ts +87 -79
- package/src/contract/contract.ts +8 -16
- package/src/contract/contract_base.ts +5 -15
- package/src/contract/contract_function_interaction.ts +72 -105
- package/src/contract/deploy_method.ts +123 -104
- package/src/contract/deploy_sent_tx.ts +19 -18
- package/src/contract/interaction_options.ts +121 -25
- package/src/contract/sent_tx.ts +6 -7
- package/src/contract/unsafe_contract.ts +1 -1
- package/src/contract/wait_for_proven.ts +4 -4
- package/src/deployment/broadcast_function.ts +1 -1
- package/src/deployment/contract_deployer.ts +3 -2
- package/src/deployment/publish_class.ts +1 -1
- package/src/deployment/publish_instance.ts +3 -8
- package/src/ethereum/portal_manager.ts +62 -40
- package/src/fee/fee_juice_payment_method_with_claim.ts +30 -19
- package/src/fee/fee_payment_method.ts +26 -0
- package/src/fee/private_fee_payment_method.ts +64 -43
- package/src/fee/public_fee_payment_method.ts +77 -51
- package/src/fee/sponsored_fee_payment.ts +9 -1
- package/src/utils/abi_types.ts +1 -1
- package/src/utils/authwit.ts +257 -39
- package/src/utils/cross_chain.ts +53 -0
- package/src/utils/fee_juice.ts +5 -4
- package/src/utils/field_compressed_string.ts +1 -1
- package/src/utils/pub_key.ts +3 -4
- package/src/wallet/account_entrypoint_meta_payment_method.ts +106 -0
- package/src/wallet/account_manager.ts +154 -0
- package/src/wallet/deploy_account_method.ts +126 -0
- package/src/wallet/index.ts +1 -32
- package/src/wallet/wallet.ts +358 -29
- package/dest/account_manager/account_manager.d.ts +0 -119
- package/dest/account_manager/account_manager.d.ts.map +0 -1
- package/dest/account_manager/account_manager.js +0 -202
- package/dest/account_manager/deploy_account_sent_tx.d.ts +0 -30
- package/dest/account_manager/deploy_account_sent_tx.d.ts.map +0 -1
- package/dest/account_manager/deploy_account_sent_tx.js +0 -29
- package/dest/account_manager/index.d.ts +0 -3
- package/dest/account_manager/index.d.ts.map +0 -1
- package/dest/account_manager/index.js +0 -2
- package/dest/api/interfaces.d.ts +0 -2
- package/dest/api/interfaces.d.ts.map +0 -1
- package/dest/api/interfaces.js +0 -1
- package/dest/api/log_id.d.ts +0 -2
- package/dest/api/log_id.d.ts.map +0 -1
- package/dest/api/log_id.js +0 -1
- package/dest/api/rpc.d.ts +0 -3
- package/dest/api/rpc.d.ts.map +0 -1
- package/dest/api/rpc.js +0 -2
- package/dest/api/tx_hash.d.ts +0 -2
- package/dest/api/tx_hash.d.ts.map +0 -1
- package/dest/api/tx_hash.js +0 -1
- package/dest/contract/deploy_proven_tx.d.ts +0 -21
- package/dest/contract/deploy_proven_tx.d.ts.map +0 -1
- package/dest/contract/deploy_proven_tx.js +0 -21
- package/dest/contract/proven_tx.d.ts +0 -21
- package/dest/contract/proven_tx.d.ts.map +0 -1
- package/dest/contract/proven_tx.js +0 -23
- package/dest/ethereum/l1_contracts.d.ts +0 -3
- package/dest/ethereum/l1_contracts.d.ts.map +0 -1
- package/dest/ethereum/l1_contracts.js +0 -13
- package/dest/fee/account_entrypoint_meta_payment_method.d.ts +0 -31
- package/dest/fee/account_entrypoint_meta_payment_method.d.ts.map +0 -1
- package/dest/fee/account_entrypoint_meta_payment_method.js +0 -64
- package/dest/fee/fee_juice_payment_method.d.ts +0 -14
- package/dest/fee/fee_juice_payment_method.d.ts.map +0 -1
- package/dest/fee/fee_juice_payment_method.js +0 -21
- package/dest/fee/utils.d.ts +0 -13
- package/dest/fee/utils.d.ts.map +0 -1
- package/dest/fee/utils.js +0 -32
- package/dest/index.d.ts +0 -59
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -62
- package/dest/rpc_clients/node/index.d.ts +0 -12
- package/dest/rpc_clients/node/index.d.ts.map +0 -1
- package/dest/rpc_clients/node/index.js +0 -72
- package/dest/rpc_clients/pxe_client.d.ts +0 -10
- package/dest/rpc_clients/pxe_client.d.ts.map +0 -1
- package/dest/rpc_clients/pxe_client.js +0 -23
- package/dest/utils/pxe.d.ts +0 -4
- package/dest/utils/pxe.d.ts.map +0 -1
- package/dest/utils/pxe.js +0 -14
- package/dest/wallet/account_wallet.d.ts +0 -74
- package/dest/wallet/account_wallet.d.ts.map +0 -1
- package/dest/wallet/account_wallet.js +0 -232
- package/dest/wallet/account_wallet_with_private_key.d.ts +0 -26
- package/dest/wallet/account_wallet_with_private_key.d.ts.map +0 -1
- package/dest/wallet/base_wallet.d.ts +0 -48
- package/dest/wallet/base_wallet.d.ts.map +0 -1
- package/dest/wallet/base_wallet.js +0 -70
- package/dest/wallet/signerless_wallet.d.ts +0 -23
- package/dest/wallet/signerless_wallet.d.ts.map +0 -1
- package/dest/wallet/signerless_wallet.js +0 -33
- package/src/account_manager/account_manager.ts +0 -276
- package/src/account_manager/deploy_account_sent_tx.ts +0 -46
- package/src/account_manager/index.ts +0 -2
- package/src/api/interfaces.ts +0 -1
- package/src/api/log_id.ts +0 -1
- package/src/api/rpc.ts +0 -2
- package/src/api/tx_hash.ts +0 -1
- package/src/contract/deploy_proven_tx.ts +0 -45
- package/src/contract/proven_tx.ts +0 -36
- package/src/ethereum/l1_contracts.ts +0 -21
- package/src/fee/account_entrypoint_meta_payment_method.ts +0 -89
- package/src/fee/fee_juice_payment_method.ts +0 -25
- package/src/fee/utils.ts +0 -39
- package/src/index.ts +0 -85
- package/src/rpc_clients/node/index.ts +0 -77
- package/src/rpc_clients/pxe_client.ts +0 -25
- package/src/utils/pxe.ts +0 -17
- package/src/wallet/account_wallet.ts +0 -246
- package/src/wallet/base_wallet.ts +0 -141
- package/src/wallet/signerless_wallet.ts +0 -56
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
2
|
+
import { EncodedAppEntrypointCalls } from '@aztec/entrypoints/encoding';
|
|
3
|
+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
4
|
+
import {
|
|
5
|
+
type ContractArtifact,
|
|
6
|
+
type FunctionArtifact,
|
|
7
|
+
FunctionCall,
|
|
8
|
+
FunctionSelector,
|
|
9
|
+
encodeArguments,
|
|
10
|
+
getFunctionArtifactByName,
|
|
11
|
+
} from '@aztec/stdlib/abi';
|
|
12
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
13
|
+
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
14
|
+
import { ExecutionPayload } from '@aztec/stdlib/tx';
|
|
15
|
+
|
|
16
|
+
import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
|
|
17
|
+
import type { Wallet } from './index.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Fee payment method that allows an account contract to pay for its own deployment
|
|
21
|
+
* It works by rerouting the provided fee payment method through the account's entrypoint,
|
|
22
|
+
* which sets itself as fee payer. If no payment method is provided, it is assumed the
|
|
23
|
+
* account will pay with its own fee juice balance.
|
|
24
|
+
*
|
|
25
|
+
* Usually, in order to pay fees it is necessary to obtain an ExecutionPayload that encodes the necessary information
|
|
26
|
+
* that is sent to the user's account entrypoint, that has plumbing to handle it.
|
|
27
|
+
* If there's no account contract yet (it's being deployed) a MultiCallContract is used, which doesn't have a concept of fees or
|
|
28
|
+
* how to handle this payload.
|
|
29
|
+
* HOWEVER, the account contract's entrypoint does, so this method reshapes that fee payload into a call to the account contract entrypoint
|
|
30
|
+
* being deployed with the original fee payload.
|
|
31
|
+
*
|
|
32
|
+
* This class can be seen in action in DeployAccountMethod.ts#getSelfPaymentMethod
|
|
33
|
+
*/
|
|
34
|
+
export class AccountEntrypointMetaPaymentMethod implements FeePaymentMethod {
|
|
35
|
+
constructor(
|
|
36
|
+
private wallet: Wallet,
|
|
37
|
+
private artifact: ContractArtifact,
|
|
38
|
+
private feePaymentNameOrArtifact: string | FunctionArtifact,
|
|
39
|
+
private accountAddress: AztecAddress,
|
|
40
|
+
private paymentMethod?: FeePaymentMethod,
|
|
41
|
+
) {}
|
|
42
|
+
|
|
43
|
+
getAsset(): Promise<AztecAddress> {
|
|
44
|
+
return this.paymentMethod?.getAsset() ?? Promise.resolve(ProtocolContractAddress.FeeJuice);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async getExecutionPayload(): Promise<ExecutionPayload> {
|
|
48
|
+
// Get the execution payload for the fee, it includes the calls and potentially authWitnesses
|
|
49
|
+
// It can be empty because the account might attempt to pay for the tx fee using its own
|
|
50
|
+
// FeeJuice balance
|
|
51
|
+
const { calls: feeCalls, authWitnesses: feeAuthwitnesses } =
|
|
52
|
+
(await this.paymentMethod?.getExecutionPayload()) ?? ExecutionPayload.empty();
|
|
53
|
+
// Encode the calls for the fee
|
|
54
|
+
const feePayer = (await this.paymentMethod?.getFeePayer()) ?? this.accountAddress;
|
|
55
|
+
const isFeePayer = feePayer.equals(this.accountAddress);
|
|
56
|
+
let accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.EXTERNAL;
|
|
57
|
+
if (isFeePayer) {
|
|
58
|
+
// If the account is the fee payer, and the incoming fee payload has calls
|
|
59
|
+
// it can only be FeeJuicePaymentMethodWithClaim
|
|
60
|
+
// If the payload has no calls, it's paying using
|
|
61
|
+
// its own fee juice balance
|
|
62
|
+
accountFeePaymentMethodOptions =
|
|
63
|
+
feeCalls.length === 0
|
|
64
|
+
? AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE
|
|
65
|
+
: AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM;
|
|
66
|
+
}
|
|
67
|
+
const feeEncodedCalls = await EncodedAppEntrypointCalls.create(feeCalls);
|
|
68
|
+
|
|
69
|
+
// Get the entrypoint args
|
|
70
|
+
const args = [feeEncodedCalls, accountFeePaymentMethodOptions, false];
|
|
71
|
+
const feePaymentArtifact =
|
|
72
|
+
typeof this.feePaymentNameOrArtifact === 'string'
|
|
73
|
+
? getFunctionArtifactByName(this.artifact, this.feePaymentNameOrArtifact)
|
|
74
|
+
: this.feePaymentNameOrArtifact;
|
|
75
|
+
|
|
76
|
+
const entrypointCall = new FunctionCall(
|
|
77
|
+
feePaymentArtifact.name,
|
|
78
|
+
this.accountAddress,
|
|
79
|
+
await FunctionSelector.fromNameAndParameters(feePaymentArtifact.name, feePaymentArtifact.parameters),
|
|
80
|
+
feePaymentArtifact.functionType,
|
|
81
|
+
false /** hideMsgSender -- set to `false`, because it's not applicable for an entrypoint function (only for enqueued public calls) */,
|
|
82
|
+
feePaymentArtifact.isStatic,
|
|
83
|
+
encodeArguments(feePaymentArtifact, args),
|
|
84
|
+
feePaymentArtifact.returnTypes,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
// Compute the authwitness required to verify the combined payload
|
|
88
|
+
const payloadAuthWitness = await this.wallet.createAuthWit(this.accountAddress, await feeEncodedCalls.hash());
|
|
89
|
+
|
|
90
|
+
return new ExecutionPayload(
|
|
91
|
+
[entrypointCall],
|
|
92
|
+
[payloadAuthWitness, ...feeAuthwitnesses],
|
|
93
|
+
[],
|
|
94
|
+
feeEncodedCalls.hashedArguments,
|
|
95
|
+
feePayer,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
getFeePayer(): Promise<AztecAddress> {
|
|
100
|
+
return this.paymentMethod?.getFeePayer() ?? Promise.resolve(this.accountAddress);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
getGasSettings(): GasSettings | undefined {
|
|
104
|
+
return this.paymentMethod?.getGasSettings();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import {
|
|
3
|
+
CompleteAddress,
|
|
4
|
+
type ContractInstanceWithAddress,
|
|
5
|
+
getContractInstanceFromInstantiationParams,
|
|
6
|
+
} from '@aztec/stdlib/contract';
|
|
7
|
+
import { deriveKeys } from '@aztec/stdlib/keys';
|
|
8
|
+
|
|
9
|
+
import type { AccountContract } from '../account/account_contract.js';
|
|
10
|
+
import { AccountWithSecretKey } from '../account/account_with_secret_key.js';
|
|
11
|
+
import type { Salt } from '../account/index.js';
|
|
12
|
+
import type { AccountInterface } from '../account/interface.js';
|
|
13
|
+
import { Contract } from '../contract/contract.js';
|
|
14
|
+
import { DeployAccountMethod } from './deploy_account_method.js';
|
|
15
|
+
import type { Wallet } from './wallet.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Manages a user account. Provides methods for calculating the account's address and other related data,
|
|
19
|
+
* plus a helper to return a preconfigured deploy method.
|
|
20
|
+
*/
|
|
21
|
+
export class AccountManager {
|
|
22
|
+
private constructor(
|
|
23
|
+
private wallet: Wallet,
|
|
24
|
+
private secretKey: Fr,
|
|
25
|
+
private accountContract: AccountContract,
|
|
26
|
+
private instance: ContractInstanceWithAddress,
|
|
27
|
+
/**
|
|
28
|
+
* Contract instantiation salt for the account contract
|
|
29
|
+
*/
|
|
30
|
+
public readonly salt: Salt,
|
|
31
|
+
) {}
|
|
32
|
+
|
|
33
|
+
static async create(wallet: Wallet, secretKey: Fr, accountContract: AccountContract, salt?: Salt) {
|
|
34
|
+
const { publicKeys } = await deriveKeys(secretKey);
|
|
35
|
+
salt = salt !== undefined ? new Fr(salt) : Fr.random();
|
|
36
|
+
|
|
37
|
+
const { constructorName, constructorArgs } = (await accountContract.getInitializationFunctionAndArgs()) ?? {
|
|
38
|
+
constructorName: undefined,
|
|
39
|
+
constructorArgs: undefined,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const artifact = await accountContract.getContractArtifact();
|
|
43
|
+
const instance = await getContractInstanceFromInstantiationParams(artifact, {
|
|
44
|
+
constructorArtifact: constructorName,
|
|
45
|
+
constructorArgs,
|
|
46
|
+
salt: salt,
|
|
47
|
+
publicKeys,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return new AccountManager(wallet, secretKey, accountContract, instance, salt);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
protected getPublicKeys() {
|
|
54
|
+
return this.instance.publicKeys;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
protected getPublicKeysHash() {
|
|
58
|
+
return this.getPublicKeys().hash();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Returns the entrypoint for this account as defined by its account contract.
|
|
63
|
+
* @returns An entrypoint.
|
|
64
|
+
*/
|
|
65
|
+
public async getAccountInterface(): Promise<AccountInterface> {
|
|
66
|
+
const chainInfo = await this.wallet.getChainInfo();
|
|
67
|
+
const completeAddress = await this.getCompleteAddress();
|
|
68
|
+
return this.accountContract.getInterface(completeAddress, chainInfo);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Gets the calculated complete address associated with this account.
|
|
73
|
+
* Does not require the account to have been published for public execution.
|
|
74
|
+
* @returns The address, partial address, and encryption public key.
|
|
75
|
+
*/
|
|
76
|
+
public getCompleteAddress(): Promise<CompleteAddress> {
|
|
77
|
+
return CompleteAddress.fromSecretKeyAndInstance(this.secretKey, this.instance);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Returns the secret key used to derive the rest of the privacy keys for this contract
|
|
82
|
+
*/
|
|
83
|
+
public getSecretKey() {
|
|
84
|
+
return this.secretKey;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
get address() {
|
|
88
|
+
return this.instance.address;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Returns the contract instance definition associated with this account.
|
|
93
|
+
* Does not require the account to have been published for public execution.
|
|
94
|
+
* @returns ContractInstance instance.
|
|
95
|
+
*/
|
|
96
|
+
public getInstance(): ContractInstanceWithAddress {
|
|
97
|
+
return this.instance;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Returns a Wallet instance associated with this account. Use it to create Contract
|
|
102
|
+
* instances to be interacted with from this account.
|
|
103
|
+
* @returns A Wallet instance.
|
|
104
|
+
*/
|
|
105
|
+
public async getAccount(): Promise<AccountWithSecretKey> {
|
|
106
|
+
const accountInterface = await this.getAccountInterface();
|
|
107
|
+
return new AccountWithSecretKey(accountInterface, this.secretKey, this.salt);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Returns the account contract that backs this account.
|
|
112
|
+
* @returns The account contract
|
|
113
|
+
*/
|
|
114
|
+
getAccountContract(): AccountContract {
|
|
115
|
+
return this.accountContract;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Returns a preconfigured deploy method that contains all the necessary function
|
|
120
|
+
* calls to deploy the account contract.
|
|
121
|
+
*/
|
|
122
|
+
public async getDeployMethod(): Promise<DeployAccountMethod> {
|
|
123
|
+
const artifact = await this.accountContract.getContractArtifact();
|
|
124
|
+
|
|
125
|
+
if (!(await this.hasInitializer())) {
|
|
126
|
+
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/15576):
|
|
127
|
+
// there should be a path which enables an account contract's class & instance to be published,
|
|
128
|
+
// even if the account contract doesn't have an initializer function. This should not throw.
|
|
129
|
+
throw new Error(`Account contract ${artifact.name} does not have an initializer function to call.`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const { constructorName, constructorArgs } = (await this.accountContract.getInitializationFunctionAndArgs()) ?? {
|
|
133
|
+
constructorName: undefined,
|
|
134
|
+
constructorArgs: undefined,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
return new DeployAccountMethod(
|
|
138
|
+
this.getPublicKeys(),
|
|
139
|
+
this.wallet,
|
|
140
|
+
artifact,
|
|
141
|
+
instance => Contract.at(instance.address, artifact, this.wallet),
|
|
142
|
+
new Fr(this.salt),
|
|
143
|
+
constructorArgs,
|
|
144
|
+
constructorName,
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Returns whether this account contract has an initializer function.
|
|
150
|
+
*/
|
|
151
|
+
public async hasInitializer() {
|
|
152
|
+
return (await this.accountContract.getInitializationFunctionAndArgs()) !== undefined;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import type { ContractArtifact, FunctionArtifact } from '@aztec/stdlib/abi';
|
|
3
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
5
|
+
import type { PublicKeys } from '@aztec/stdlib/keys';
|
|
6
|
+
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
7
|
+
|
|
8
|
+
import type { Contract } from '../contract/contract.js';
|
|
9
|
+
import type { ContractBase } from '../contract/contract_base.js';
|
|
10
|
+
import {
|
|
11
|
+
DeployMethod,
|
|
12
|
+
type DeployOptions,
|
|
13
|
+
type RequestDeployOptions,
|
|
14
|
+
type SimulateDeployOptions,
|
|
15
|
+
} from '../contract/deploy_method.js';
|
|
16
|
+
import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
|
|
17
|
+
import { AccountEntrypointMetaPaymentMethod } from './account_entrypoint_meta_payment_method.js';
|
|
18
|
+
import type { Wallet } from './index.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The configuration options for the request method. Omits the contractAddressSalt, since
|
|
22
|
+
* for account contracts that is fixed in the constructor
|
|
23
|
+
*/
|
|
24
|
+
export type RequestDeployAccountOptions = Omit<RequestDeployOptions, 'contractAddressSalt'>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The configuration options for the send/prove methods. Omits:
|
|
28
|
+
* - The contractAddressSalt, since for account contracts that is fixed in the constructor.
|
|
29
|
+
* - UniversalDeployment flag, since account contracts are always deployed with it set to true
|
|
30
|
+
*/
|
|
31
|
+
export type DeployAccountOptions = Omit<DeployOptions, 'contractAddressSalt' | 'universalDeploy'>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The configuration options for the simulate method. Omits the contractAddressSalt, since
|
|
35
|
+
* for account contracts that is fixed in the constructor
|
|
36
|
+
*/
|
|
37
|
+
export type SimulateDeployAccountOptions = Omit<SimulateDeployOptions, 'contractAddressSalt'>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Modified version of the DeployMethod used to deploy account contracts. Supports deploying
|
|
41
|
+
* contracts that can pay for their own fee, plus some preconfigured options to avoid errors.
|
|
42
|
+
*/
|
|
43
|
+
export class DeployAccountMethod<TContract extends ContractBase = Contract> extends DeployMethod<TContract> {
|
|
44
|
+
constructor(
|
|
45
|
+
publicKeys: PublicKeys,
|
|
46
|
+
wallet: Wallet,
|
|
47
|
+
artifact: ContractArtifact,
|
|
48
|
+
postDeployCtor: (instance: ContractInstanceWithAddress, wallet: Wallet) => TContract,
|
|
49
|
+
private salt: Fr,
|
|
50
|
+
args: any[] = [],
|
|
51
|
+
constructorNameOrArtifact?: string | FunctionArtifact,
|
|
52
|
+
) {
|
|
53
|
+
super(publicKeys, wallet, artifact, postDeployCtor, args, constructorNameOrArtifact);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns a FeePaymentMethod that routes the original one provided as an argument
|
|
58
|
+
* through the account's entrypoint. This allows an account contract to pay
|
|
59
|
+
* for its own deployment and initialization.
|
|
60
|
+
*
|
|
61
|
+
* For more details on how the fee payment routing works see documentation of AccountEntrypointMetaPaymentMethod class.
|
|
62
|
+
*
|
|
63
|
+
* @param originalPaymentMethod - originalPaymentMethod The original payment method to be wrapped.
|
|
64
|
+
* @returns A FeePaymentMethod that routes the original one through the account's entrypoint (AccountEntrypointMetaPaymentMethod)
|
|
65
|
+
*/
|
|
66
|
+
private getSelfFeePaymentMethod(originalPaymentMethod?: FeePaymentMethod) {
|
|
67
|
+
if (!this.address) {
|
|
68
|
+
throw new Error('Instance is not yet constructed. This is a bug!');
|
|
69
|
+
}
|
|
70
|
+
return new AccountEntrypointMetaPaymentMethod(
|
|
71
|
+
this.wallet,
|
|
72
|
+
this.artifact,
|
|
73
|
+
'entrypoint',
|
|
74
|
+
this.address,
|
|
75
|
+
originalPaymentMethod,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Returns the execution payload that allows this operation to happen on chain.
|
|
81
|
+
* @param opts - Configuration options.
|
|
82
|
+
* @returns The execution payload for this operation
|
|
83
|
+
*/
|
|
84
|
+
public override async request(opts?: RequestDeployAccountOptions): Promise<ExecutionPayload> {
|
|
85
|
+
const optionsWithDefaults: RequestDeployOptions = {
|
|
86
|
+
...opts,
|
|
87
|
+
// Regardless of whom sends the transaction, account contracts
|
|
88
|
+
// are always deployed as universalDeployment: true
|
|
89
|
+
deployer: undefined,
|
|
90
|
+
contractAddressSalt: new Fr(this.salt),
|
|
91
|
+
skipClassPublication: opts?.skipClassPublication ?? true,
|
|
92
|
+
skipInstancePublication: opts?.skipInstancePublication ?? true,
|
|
93
|
+
skipInitialization: opts?.skipInitialization ?? false,
|
|
94
|
+
};
|
|
95
|
+
// Override the fee to undefined, since we'll replace it
|
|
96
|
+
const deploymentExecutionPayload = await super.request({ ...optionsWithDefaults, fee: undefined });
|
|
97
|
+
const executionPayloads = [deploymentExecutionPayload];
|
|
98
|
+
// If this is a self-deployment, manage the fee accordingly
|
|
99
|
+
if (opts?.deployer?.equals(AztecAddress.ZERO)) {
|
|
100
|
+
const feePaymentMethod = this.getSelfFeePaymentMethod(opts?.fee?.paymentMethod);
|
|
101
|
+
const feeExecutionPayload = await feePaymentMethod.getExecutionPayload();
|
|
102
|
+
// Notice they are reversed (fee payment usually goes first):
|
|
103
|
+
// this is because we need to construct the contract BEFORE it can pay for its own fee
|
|
104
|
+
executionPayloads.push(feeExecutionPayload);
|
|
105
|
+
} else {
|
|
106
|
+
const feeExecutionPayload = opts?.fee?.paymentMethod
|
|
107
|
+
? await opts.fee.paymentMethod.getExecutionPayload()
|
|
108
|
+
: undefined;
|
|
109
|
+
if (feeExecutionPayload) {
|
|
110
|
+
executionPayloads.unshift(feeExecutionPayload);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return mergeExecutionPayloads(executionPayloads);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
override convertDeployOptionsToRequestOptions(options: DeployOptions): RequestDeployOptions {
|
|
117
|
+
return {
|
|
118
|
+
...options,
|
|
119
|
+
// Deployer is handled in the request method and forcibly set to undefined,
|
|
120
|
+
// since our account contracts are created with universalDeployment: true
|
|
121
|
+
// We need to forward it though, because depending on the deployer we have to assemble
|
|
122
|
+
// The fee payment method one way or another
|
|
123
|
+
deployer: options.from,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
package/src/wallet/index.ts
CHANGED
|
@@ -1,33 +1,2 @@
|
|
|
1
|
-
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
|
-
import type { PXE } from '@aztec/stdlib/interfaces/client';
|
|
3
|
-
|
|
4
|
-
import type { AccountContract } from '../account/account_contract.js';
|
|
5
|
-
import { AccountWallet } from './account_wallet.js';
|
|
6
|
-
|
|
7
1
|
export * from './wallet.js';
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './account_wallet_with_private_key.js';
|
|
10
|
-
export * from './signerless_wallet.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Gets a wallet for an already registered account.
|
|
14
|
-
* @param pxe - PXE Service instance.
|
|
15
|
-
* @param address - Address for the account.
|
|
16
|
-
* @param accountContract - Account contract implementation.
|
|
17
|
-
* @returns A wallet for this account that can be used to interact with a contract instance.
|
|
18
|
-
*/
|
|
19
|
-
export async function getWallet(
|
|
20
|
-
pxe: PXE,
|
|
21
|
-
address: AztecAddress,
|
|
22
|
-
accountContract: AccountContract,
|
|
23
|
-
): Promise<AccountWallet> {
|
|
24
|
-
const completeAddress = (await pxe.getRegisteredAccounts()).find(completeAddress =>
|
|
25
|
-
completeAddress.address.equals(address),
|
|
26
|
-
);
|
|
27
|
-
if (!completeAddress) {
|
|
28
|
-
throw new Error(`Account ${address} not found`);
|
|
29
|
-
}
|
|
30
|
-
const nodeInfo = await pxe.getNodeInfo();
|
|
31
|
-
const entrypoint = accountContract.getInterface(completeAddress, nodeInfo);
|
|
32
|
-
return new AccountWallet(pxe, entrypoint);
|
|
33
|
-
}
|
|
2
|
+
export * from './account_manager.js';
|