@aztec-labs/aztec.js 6.0.0-nightly.20260829
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 +44 -0
- package/dest/account/account.d.ts +44 -0
- package/dest/account/account.d.ts.map +1 -0
- package/dest/account/account.js +31 -0
- package/dest/account/account_contract.d.ts +49 -0
- package/dest/account/account_contract.d.ts.map +1 -0
- package/dest/account/account_contract.js +20 -0
- package/dest/account/index.d.ts +11 -0
- package/dest/account/index.d.ts.map +1 -0
- package/dest/account/index.js +6 -0
- package/dest/api/abi.d.ts +4 -0
- package/dest/api/abi.d.ts.map +1 -0
- package/dest/api/abi.js +1 -0
- package/dest/api/account.d.ts +5 -0
- package/dest/api/account.d.ts.map +1 -0
- package/dest/api/account.js +3 -0
- package/dest/api/addresses.d.ts +4 -0
- package/dest/api/addresses.d.ts.map +1 -0
- package/dest/api/addresses.js +3 -0
- package/dest/api/authorization.d.ts +5 -0
- package/dest/api/authorization.d.ts.map +1 -0
- package/dest/api/authorization.js +4 -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 +48 -0
- package/dest/api/contract.d.ts.map +1 -0
- package/dest/api/contract.js +46 -0
- 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 +4 -0
- package/dest/api/deployment.d.ts.map +1 -0
- package/dest/api/deployment.js +3 -0
- package/dest/api/eth_address.d.ts +2 -0
- package/dest/api/eth_address.d.ts.map +1 -0
- package/dest/api/eth_address.js +1 -0
- package/dest/api/ethereum.d.ts +2 -0
- package/dest/api/ethereum.d.ts.map +1 -0
- package/dest/api/ethereum.js +1 -0
- package/dest/api/event_cursor.d.ts +44 -0
- package/dest/api/event_cursor.d.ts.map +1 -0
- package/dest/api/event_cursor.js +42 -0
- package/dest/api/events.d.ts +36 -0
- package/dest/api/events.d.ts.map +1 -0
- package/dest/api/events.js +59 -0
- package/dest/api/fee.d.ts +6 -0
- package/dest/api/fee.d.ts.map +1 -0
- package/dest/api/fee.js +4 -0
- package/dest/api/fee_testing.d.ts +2 -0
- package/dest/api/fee_testing.d.ts.map +1 -0
- package/dest/api/fee_testing.js +1 -0
- package/dest/api/fields.d.ts +4 -0
- package/dest/api/fields.d.ts.map +1 -0
- package/dest/api/fields.js +3 -0
- 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 +3 -0
- package/dest/api/log.d.ts.map +1 -0
- package/dest/api/log.js +2 -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 +25 -0
- package/dest/api/node.d.ts.map +1 -0
- package/dest/api/node.js +22 -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 +6 -0
- package/dest/api/protocol.d.ts.map +1 -0
- package/dest/api/protocol.js +5 -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 +3 -0
- package/dest/api/tx.d.ts.map +1 -0
- package/dest/api/tx.js +1 -0
- package/dest/api/utils.d.ts +13 -0
- package/dest/api/utils.d.ts.map +1 -0
- package/dest/api/utils.js +12 -0
- package/dest/api/wallet.d.ts +8 -0
- package/dest/api/wallet.d.ts.map +1 -0
- package/dest/api/wallet.js +7 -0
- package/dest/authorization/call_authorization_request.d.ts +46 -0
- package/dest/authorization/call_authorization_request.d.ts.map +1 -0
- package/dest/authorization/call_authorization_request.js +72 -0
- package/dest/contract/base_contract_interaction.d.ts +32 -0
- package/dest/contract/base_contract_interaction.d.ts.map +1 -0
- package/dest/contract/base_contract_interaction.js +24 -0
- package/dest/contract/batch_call.d.ts +27 -0
- package/dest/contract/batch_call.d.ts.map +1 -0
- package/dest/contract/batch_call.js +152 -0
- package/dest/contract/checker.d.ts +11 -0
- package/dest/contract/checker.d.ts.map +1 -0
- package/dest/contract/checker.js +107 -0
- package/dest/contract/contract.d.ts +33 -0
- package/dest/contract/contract.d.ts.map +1 -0
- package/dest/contract/contract.js +36 -0
- package/dest/contract/contract_base.d.ts +51 -0
- package/dest/contract/contract_base.d.ts.map +1 -0
- package/dest/contract/contract_base.js +38 -0
- package/dest/contract/contract_function_interaction.d.ts +67 -0
- package/dest/contract/contract_function_interaction.d.ts.map +1 -0
- package/dest/contract/contract_function_interaction.js +218 -0
- package/dest/contract/deploy_method.d.ts +433 -0
- package/dest/contract/deploy_method.d.ts.map +1 -0
- package/dest/contract/deploy_method.js +471 -0
- package/dest/contract/fastforward_contract_update.d.ts +25 -0
- package/dest/contract/fastforward_contract_update.d.ts.map +1 -0
- package/dest/contract/fastforward_contract_update.js +57 -0
- package/dest/contract/interaction_options.d.ts +213 -0
- package/dest/contract/interaction_options.d.ts.map +1 -0
- package/dest/contract/interaction_options.js +87 -0
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts +18 -0
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/contract-class-registry.js +137 -0
- package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +25 -0
- package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/contract-instance-registry.js +366 -0
- package/dest/contract/protocol_contracts/fee-juice.d.ts +24 -0
- package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/fee-juice.js +383 -0
- package/dest/contract/wait_for_proven.d.ts +18 -0
- package/dest/contract/wait_for_proven.d.ts.map +1 -0
- package/dest/contract/wait_for_proven.js +17 -0
- package/dest/contract/wait_opts.d.ts +21 -0
- package/dest/contract/wait_opts.d.ts.map +1 -0
- package/dest/contract/wait_opts.js +5 -0
- package/dest/deployment/contract_deployer.d.ts +28 -0
- package/dest/deployment/contract_deployer.d.ts.map +1 -0
- package/dest/deployment/contract_deployer.js +35 -0
- package/dest/deployment/publish_class.d.ts +6 -0
- package/dest/deployment/publish_class.d.ts.map +1 -0
- package/dest/deployment/publish_class.js +17 -0
- package/dest/deployment/publish_instance.d.ts +10 -0
- package/dest/deployment/publish_instance.d.ts.map +1 -0
- package/dest/deployment/publish_instance.js +11 -0
- package/dest/ethereum/portal_manager.d.ts +146 -0
- package/dest/ethereum/portal_manager.d.ts.map +1 -0
- package/dest/ethereum/portal_manager.js +415 -0
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts +23 -0
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -0
- package/dest/fee/fee_juice_payment_method_with_claim.js +46 -0
- 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 +69 -0
- package/dest/fee/private_fee_payment_method.d.ts.map +1 -0
- package/dest/fee/private_fee_payment_method.js +122 -0
- package/dest/fee/public_fee_payment_method.d.ts +59 -0
- package/dest/fee/public_fee_payment_method.d.ts.map +1 -0
- package/dest/fee/public_fee_payment_method.js +116 -0
- package/dest/fee/sponsored_fee_payment.d.ts +17 -0
- package/dest/fee/sponsored_fee_payment.d.ts.map +1 -0
- package/dest/fee/sponsored_fee_payment.js +33 -0
- package/dest/scripts/generate_protocol_contract_types.d.ts +2 -0
- package/dest/scripts/generate_protocol_contract_types.d.ts.map +1 -0
- package/dest/scripts/generate_protocol_contract_types.js +128 -0
- package/dest/test/fixtures.d.ts +13 -0
- package/dest/test/fixtures.d.ts.map +1 -0
- package/dest/test/fixtures.js +185 -0
- package/dest/utils/abi_types.d.ts +32 -0
- package/dest/utils/abi_types.d.ts.map +1 -0
- package/dest/utils/abi_types.js +1 -0
- package/dest/utils/authwit.d.ts +119 -0
- package/dest/utils/authwit.d.ts.map +1 -0
- package/dest/utils/authwit.js +266 -0
- package/dest/utils/cross_chain.d.ts +28 -0
- package/dest/utils/cross_chain.d.ts.map +1 -0
- package/dest/utils/cross_chain.js +26 -0
- package/dest/utils/fee_juice.d.ts +8 -0
- package/dest/utils/fee_juice.d.ts.map +1 -0
- package/dest/utils/fee_juice.js +10 -0
- package/dest/utils/field_compressed_string.d.ts +17 -0
- package/dest/utils/field_compressed_string.d.ts.map +1 -0
- package/dest/utils/field_compressed_string.js +15 -0
- package/dest/utils/node.d.ts +24 -0
- package/dest/utils/node.d.ts.map +1 -0
- package/dest/utils/node.js +80 -0
- package/dest/utils/pub_key.d.ts +9 -0
- package/dest/utils/pub_key.d.ts.map +1 -0
- package/dest/utils/pub_key.js +8 -0
- package/dest/wallet/account_entrypoint_meta_payment_method.d.ts +33 -0
- package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -0
- package/dest/wallet/account_entrypoint_meta_payment_method.js +63 -0
- package/dest/wallet/account_manager.d.ts +73 -0
- package/dest/wallet/account_manager.d.ts.map +1 -0
- package/dest/wallet/account_manager.js +102 -0
- package/dest/wallet/capabilities.d.ts +456 -0
- package/dest/wallet/capabilities.d.ts.map +1 -0
- package/dest/wallet/capabilities.js +3 -0
- package/dest/wallet/deploy_account_method.d.ts +97 -0
- package/dest/wallet/deploy_account_method.d.ts.map +1 -0
- package/dest/wallet/deploy_account_method.js +127 -0
- package/dest/wallet/index.d.ts +5 -0
- package/dest/wallet/index.d.ts.map +1 -0
- package/dest/wallet/index.js +4 -0
- package/dest/wallet/tx_simulation_result_with_app_offset.d.ts +40 -0
- package/dest/wallet/tx_simulation_result_with_app_offset.d.ts.map +1 -0
- package/dest/wallet/tx_simulation_result_with_app_offset.js +65 -0
- package/dest/wallet/wallet.d.ts +1451 -0
- package/dest/wallet/wallet.d.ts.map +1 -0
- package/dest/wallet/wallet.js +430 -0
- package/package.json +138 -0
- package/src/account/account.ts +72 -0
- package/src/account/account_contract.ts +80 -0
- package/src/account/index.ts +12 -0
- package/src/api/README.md +7 -0
- package/src/api/abi.ts +42 -0
- package/src/api/account.ts +12 -0
- package/src/api/addresses.ts +3 -0
- package/src/api/authorization.ts +15 -0
- package/src/api/block.ts +2 -0
- package/src/api/contract.ts +86 -0
- package/src/api/crypto.ts +1 -0
- package/src/api/deployment.ts +3 -0
- package/src/api/eth_address.ts +1 -0
- package/src/api/ethereum.ts +10 -0
- package/src/api/event_cursor.ts +60 -0
- package/src/api/events.ts +79 -0
- package/src/api/fee.ts +5 -0
- package/src/api/fee_testing.ts +1 -0
- package/src/api/fields.ts +3 -0
- package/src/api/keys.ts +8 -0
- package/src/api/log.ts +2 -0
- package/src/api/messaging.ts +2 -0
- package/src/api/node.ts +30 -0
- package/src/api/note.ts +1 -0
- package/src/api/protocol.ts +6 -0
- package/src/api/trees.ts +2 -0
- package/src/api/tx.ts +20 -0
- package/src/api/utils.ts +14 -0
- package/src/api/wallet.ts +83 -0
- package/src/authorization/call_authorization_request.ts +93 -0
- package/src/contract/base_contract_interaction.ts +62 -0
- package/src/contract/batch_call.ts +188 -0
- package/src/contract/checker.ts +122 -0
- package/src/contract/contract.ts +52 -0
- package/src/contract/contract_base.ts +73 -0
- package/src/contract/contract_function_interaction.ts +297 -0
- package/src/contract/deploy_method.ts +877 -0
- package/src/contract/fastforward_contract_update.ts +71 -0
- package/src/contract/interaction_options.ts +301 -0
- package/src/contract/protocol_contracts/contract-class-registry.ts +104 -0
- package/src/contract/protocol_contracts/contract-instance-registry.ts +241 -0
- package/src/contract/protocol_contracts/fee-juice.ts +257 -0
- package/src/contract/wait_for_proven.ts +43 -0
- package/src/contract/wait_opts.ts +26 -0
- package/src/deployment/contract_deployer.ts +40 -0
- package/src/deployment/publish_class.ts +34 -0
- package/src/deployment/publish_instance.ts +24 -0
- package/src/ethereum/portal_manager.ts +539 -0
- package/src/fee/fee_juice_payment_method_with_claim.ts +63 -0
- package/src/fee/fee_payment_method.ts +26 -0
- package/src/fee/private_fee_payment_method.ts +145 -0
- package/src/fee/public_fee_payment_method.ts +145 -0
- package/src/fee/sponsored_fee_payment.ts +45 -0
- package/src/scripts/generate_protocol_contract_types.ts +160 -0
- package/src/test/fixtures.ts +126 -0
- package/src/utils/abi_types.ts +32 -0
- package/src/utils/authwit.ts +327 -0
- package/src/utils/cross_chain.ts +55 -0
- package/src/utils/fee_juice.ts +14 -0
- package/src/utils/field_compressed_string.ts +27 -0
- package/src/utils/node.ts +110 -0
- package/src/utils/pub_key.ts +12 -0
- package/src/wallet/account_entrypoint_meta_payment_method.ts +76 -0
- package/src/wallet/account_manager.ts +164 -0
- package/src/wallet/capabilities.ts +505 -0
- package/src/wallet/deploy_account_method.ts +234 -0
- package/src/wallet/index.ts +4 -0
- package/src/wallet/tx_simulation_result_with_app_offset.ts +100 -0
- package/src/wallet/wallet.ts +668 -0
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import type { ChainInfo } from '@aztec-labs/entrypoints/interfaces';
|
|
2
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
3
|
+
import { STANDARD_AUTH_REGISTRY_ADDRESS } from '@aztec-labs/standard-contracts/auth-registry/constants';
|
|
4
|
+
import { type ABIParameterVisibility, type FunctionAbi, type FunctionCall, FunctionType } from '@aztec-labs/stdlib/abi';
|
|
5
|
+
import { AuthWitness, computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec-labs/stdlib/auth-witness';
|
|
6
|
+
import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
|
|
7
|
+
import { computeVarArgsHash } from '@aztec-labs/stdlib/hash';
|
|
8
|
+
import type { TxProfileResult } from '@aztec-labs/stdlib/tx';
|
|
9
|
+
|
|
10
|
+
import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
11
|
+
import type {
|
|
12
|
+
InteractionWaitOptions,
|
|
13
|
+
ProfileInteractionOptions,
|
|
14
|
+
SendInteractionOptions,
|
|
15
|
+
SendInteractionOptionsWithoutWait,
|
|
16
|
+
SendReturn,
|
|
17
|
+
SimulateInteractionOptions,
|
|
18
|
+
SimulationResult,
|
|
19
|
+
TxSendResultMined,
|
|
20
|
+
} from '../contract/interaction_options.js';
|
|
21
|
+
import type { Wallet } from '../wallet/index.js';
|
|
22
|
+
|
|
23
|
+
/** Intent with an inner hash */
|
|
24
|
+
export type IntentInnerHash = {
|
|
25
|
+
/** The consumer */
|
|
26
|
+
consumer: AztecAddress;
|
|
27
|
+
/** The action to approve */
|
|
28
|
+
innerHash: Fr;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** Intent with a call */
|
|
32
|
+
export type CallIntent = {
|
|
33
|
+
/** The caller to approve */
|
|
34
|
+
caller: AztecAddress;
|
|
35
|
+
/** The call to approve */
|
|
36
|
+
call: FunctionCall;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** Intent with a ContractFunctionInteraction */
|
|
40
|
+
export type ContractFunctionInteractionCallIntent = {
|
|
41
|
+
/** The caller to approve */
|
|
42
|
+
caller: AztecAddress;
|
|
43
|
+
/** The action to approve */
|
|
44
|
+
action: ContractFunctionInteraction;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Identifies ContractFunctionInteractionCallIntents */
|
|
48
|
+
export function isContractFunctionInteractionCallIntent(
|
|
49
|
+
messageHashOrIntent: Fr | IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
|
|
50
|
+
): messageHashOrIntent is ContractFunctionInteractionCallIntent {
|
|
51
|
+
return (
|
|
52
|
+
'caller' in messageHashOrIntent &&
|
|
53
|
+
'action' in messageHashOrIntent &&
|
|
54
|
+
messageHashOrIntent.action instanceof ContractFunctionInteraction
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Compute an authentication witness message hash from an intent and metadata
|
|
60
|
+
*
|
|
61
|
+
* If using the `IntentInnerHash`, the consumer is the address that can "consume" the authwit, for token approvals it is the token contract itself.
|
|
62
|
+
* The `innerHash` itself will be the message that a contract is allowed to execute.
|
|
63
|
+
* At the point of "approval checking", the validating contract (account for private and registry for public) will be computing the message hash
|
|
64
|
+
* (`H(consumer, chainid, version, inner_hash)`) where the all but the `inner_hash` is injected from the context (consumer = msg_sender),
|
|
65
|
+
* and use it for the authentication check.
|
|
66
|
+
* Therefore, any allowed `innerHash` will therefore also have information around where it can be spent (version, chainId) and who can spend it (consumer).
|
|
67
|
+
*
|
|
68
|
+
* If using the `CallIntent`, the caller is the address that is making the call, for a token approval from Alice to Bob, this would be Bob.
|
|
69
|
+
* The action is then used along with the `caller` to compute the `innerHash` and the consumer.
|
|
70
|
+
*
|
|
71
|
+
*
|
|
72
|
+
* @param intent - The intent to approve (consumer and innerHash or caller and action)
|
|
73
|
+
* The consumer is the address that can "consume" the authwit, for token approvals it is the token contract itself.
|
|
74
|
+
* The caller is the address that is making the call, for a token approval from Alice to Bob, this would be Bob.
|
|
75
|
+
* The caller becomes part of the `inner_hash` and is dealt with entirely in application logic.
|
|
76
|
+
* @param metadata - The metadata for the intent (chainId, version)
|
|
77
|
+
* @returns The message hash for the action
|
|
78
|
+
*/
|
|
79
|
+
export const computeAuthWitMessageHash = async (
|
|
80
|
+
intent: IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
|
|
81
|
+
metadata: ChainInfo,
|
|
82
|
+
) => {
|
|
83
|
+
const chainId = metadata.chainId;
|
|
84
|
+
const version = metadata.version;
|
|
85
|
+
|
|
86
|
+
if ('caller' in intent) {
|
|
87
|
+
const call = isContractFunctionInteractionCallIntent(intent) ? await intent.action.getFunctionCall() : intent.call;
|
|
88
|
+
return computeOuterAuthWitHash(
|
|
89
|
+
call.to,
|
|
90
|
+
chainId,
|
|
91
|
+
version,
|
|
92
|
+
await computeInnerAuthWitHashFromAction(intent.caller, call),
|
|
93
|
+
);
|
|
94
|
+
} else {
|
|
95
|
+
const inner = Buffer.isBuffer(intent.innerHash) ? Fr.fromBuffer(intent.innerHash) : intent.innerHash;
|
|
96
|
+
return computeOuterAuthWitHash(intent.consumer, chainId, version, inner);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Compute an authentication witness message hash from an intent and metadata. This is just
|
|
102
|
+
* a wrapper around computeAuthwitMessageHash that allows receiving an already computed messageHash as input
|
|
103
|
+
* @param messageHashOrIntent - The precomputed messageHash or intent to approve (consumer and innerHash or caller and call/action)
|
|
104
|
+
* @param metadata - The metadata for the intent (chainId, version)
|
|
105
|
+
* @returns The message hash for the intent
|
|
106
|
+
*/
|
|
107
|
+
export async function getMessageHashFromIntent(
|
|
108
|
+
messageHashOrIntent: Fr | IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
|
|
109
|
+
chainInfo: ChainInfo,
|
|
110
|
+
) {
|
|
111
|
+
let messageHash: Fr;
|
|
112
|
+
const { chainId, version } = chainInfo;
|
|
113
|
+
if (messageHashOrIntent instanceof Fr) {
|
|
114
|
+
messageHash = messageHashOrIntent;
|
|
115
|
+
} else {
|
|
116
|
+
messageHash = await computeAuthWitMessageHash(messageHashOrIntent, { chainId, version });
|
|
117
|
+
}
|
|
118
|
+
return messageHash;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Computes the inner authwitness hash for either a function call or an action, for it to later be combined with the metadata
|
|
123
|
+
* required for the outer hash and eventually the full AuthWitness.
|
|
124
|
+
* @param caller - Who is going to be calling the function
|
|
125
|
+
* @param action - The action to compute the inner hash from
|
|
126
|
+
* @returns The inner hash for the action
|
|
127
|
+
**/
|
|
128
|
+
export const computeInnerAuthWitHashFromAction = async (
|
|
129
|
+
caller: AztecAddress,
|
|
130
|
+
action: FunctionCall | ContractFunctionInteraction,
|
|
131
|
+
) => {
|
|
132
|
+
const call = action instanceof ContractFunctionInteraction ? await action.getFunctionCall() : action;
|
|
133
|
+
return computeInnerAuthWitHash([caller.toField(), call.selector.toField(), await computeVarArgsHash(call.args)]);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Lookup the validity of an authwit in private and public contexts.
|
|
138
|
+
*
|
|
139
|
+
* Uses the chain id and version of the wallet.
|
|
140
|
+
*
|
|
141
|
+
* @param wallet - The wallet use to simulate and read the public data
|
|
142
|
+
* @param onBehalfOf - The address of the "approver"
|
|
143
|
+
* @param intent - The consumer and inner hash or the caller and action to lookup
|
|
144
|
+
* @param witness - The computed authentication witness to check
|
|
145
|
+
* @returns - A struct containing the validity of the authwit in private and public contexts.
|
|
146
|
+
*/
|
|
147
|
+
export async function lookupValidity(
|
|
148
|
+
wallet: Wallet,
|
|
149
|
+
onBehalfOf: AztecAddress,
|
|
150
|
+
intent: IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
|
|
151
|
+
witness: AuthWitness,
|
|
152
|
+
): Promise<{
|
|
153
|
+
/** boolean flag indicating if the authwit is valid in private context */
|
|
154
|
+
isValidInPrivate: boolean;
|
|
155
|
+
/** boolean flag indicating if the authwit is valid in public context */
|
|
156
|
+
isValidInPublic: boolean;
|
|
157
|
+
}> {
|
|
158
|
+
let innerHash, consumer;
|
|
159
|
+
if ('caller' in intent) {
|
|
160
|
+
const call = isContractFunctionInteractionCallIntent(intent) ? await intent.action.getFunctionCall() : intent.call;
|
|
161
|
+
innerHash = await computeInnerAuthWitHashFromAction(intent.caller, call);
|
|
162
|
+
consumer = call.to;
|
|
163
|
+
} else {
|
|
164
|
+
({ innerHash, consumer } = intent);
|
|
165
|
+
}
|
|
166
|
+
const chainInfo = await wallet.getChainInfo();
|
|
167
|
+
const messageHash = await getMessageHashFromIntent(intent, chainInfo);
|
|
168
|
+
const results = { isValidInPrivate: false, isValidInPublic: false };
|
|
169
|
+
|
|
170
|
+
// Check private
|
|
171
|
+
const lookupValidityAbi = {
|
|
172
|
+
name: 'lookup_validity',
|
|
173
|
+
isInitializer: false,
|
|
174
|
+
functionType: FunctionType.UTILITY,
|
|
175
|
+
isOnlySelf: false,
|
|
176
|
+
isStatic: false,
|
|
177
|
+
parameters: [
|
|
178
|
+
{
|
|
179
|
+
name: 'consumer',
|
|
180
|
+
type: {
|
|
181
|
+
fields: [{ name: 'inner', type: { kind: 'field' } }],
|
|
182
|
+
kind: 'struct',
|
|
183
|
+
path: 'aztec::protocol_types::address::aztec_address::AztecAddress',
|
|
184
|
+
},
|
|
185
|
+
visibility: 'private' as ABIParameterVisibility,
|
|
186
|
+
},
|
|
187
|
+
{ name: 'inner_hash', type: { kind: 'field' }, visibility: 'private' as ABIParameterVisibility },
|
|
188
|
+
],
|
|
189
|
+
returnType: { kind: 'boolean' },
|
|
190
|
+
errorTypes: {},
|
|
191
|
+
} as FunctionAbi;
|
|
192
|
+
try {
|
|
193
|
+
results.isValidInPrivate = (
|
|
194
|
+
await new ContractFunctionInteraction(wallet, onBehalfOf, lookupValidityAbi, [consumer, innerHash]).simulate({
|
|
195
|
+
from: onBehalfOf,
|
|
196
|
+
authWitnesses: [witness],
|
|
197
|
+
})
|
|
198
|
+
).result as boolean;
|
|
199
|
+
// TODO: Narrow down the error to make sure simulation failed due to an invalid authwit
|
|
200
|
+
// eslint-disable-next-line no-empty
|
|
201
|
+
} catch {}
|
|
202
|
+
|
|
203
|
+
// check public
|
|
204
|
+
const isConsumableAbi = {
|
|
205
|
+
name: 'utility_is_consumable',
|
|
206
|
+
isInitializer: false,
|
|
207
|
+
functionType: FunctionType.UTILITY,
|
|
208
|
+
isOnlySelf: false,
|
|
209
|
+
isStatic: false,
|
|
210
|
+
parameters: [
|
|
211
|
+
{
|
|
212
|
+
name: 'address',
|
|
213
|
+
type: {
|
|
214
|
+
fields: [{ name: 'inner', type: { kind: 'field' } }],
|
|
215
|
+
kind: 'struct',
|
|
216
|
+
path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
|
|
217
|
+
},
|
|
218
|
+
visibility: 'private' as ABIParameterVisibility,
|
|
219
|
+
},
|
|
220
|
+
{ name: 'message_hash', type: { kind: 'field' }, visibility: 'private' as ABIParameterVisibility },
|
|
221
|
+
],
|
|
222
|
+
returnType: { kind: 'boolean' },
|
|
223
|
+
errorTypes: {},
|
|
224
|
+
} as FunctionAbi;
|
|
225
|
+
results.isValidInPublic = (
|
|
226
|
+
await new ContractFunctionInteraction(wallet, STANDARD_AUTH_REGISTRY_ADDRESS, isConsumableAbi, [
|
|
227
|
+
onBehalfOf,
|
|
228
|
+
messageHash,
|
|
229
|
+
]).simulate({ from: onBehalfOf })
|
|
230
|
+
).result as boolean;
|
|
231
|
+
|
|
232
|
+
return results;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Convenience class designed to wrap the very common interaction of setting a public authwit in the AuthRegistry contract
|
|
237
|
+
*/
|
|
238
|
+
export class SetPublicAuthwitContractInteraction extends ContractFunctionInteraction {
|
|
239
|
+
private constructor(
|
|
240
|
+
wallet: Wallet,
|
|
241
|
+
private from: AztecAddress,
|
|
242
|
+
messageHash: Fr,
|
|
243
|
+
authorized: boolean,
|
|
244
|
+
) {
|
|
245
|
+
super(wallet, STANDARD_AUTH_REGISTRY_ADDRESS, SetPublicAuthwitContractInteraction.getSetAuthorizedAbi(), [
|
|
246
|
+
messageHash,
|
|
247
|
+
authorized,
|
|
248
|
+
]);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
static async create(
|
|
252
|
+
wallet: Wallet,
|
|
253
|
+
from: AztecAddress,
|
|
254
|
+
messageHashOrIntent: Fr | IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
|
|
255
|
+
authorized: boolean,
|
|
256
|
+
) {
|
|
257
|
+
const chainInfo = await wallet.getChainInfo();
|
|
258
|
+
const messageHash = await getMessageHashFromIntent(messageHashOrIntent, chainInfo);
|
|
259
|
+
return new SetPublicAuthwitContractInteraction(wallet, from, messageHash, authorized);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Overrides the simulate method, adding the sender of the authwit (authorizer) as from
|
|
264
|
+
* and preventing misuse
|
|
265
|
+
* @param options - An optional object containing additional configuration for the transaction.
|
|
266
|
+
* @returns The result of the transaction as returned by the contract function.
|
|
267
|
+
*/
|
|
268
|
+
public override simulate(
|
|
269
|
+
options: Omit<SimulateInteractionOptions, 'from'> = {} as Omit<SimulateInteractionOptions, 'from'>,
|
|
270
|
+
): Promise<SimulationResult> {
|
|
271
|
+
return super.simulate({ ...options, from: this.from } as SimulateInteractionOptions);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Overrides the profile method, adding the sender of the authwit (authorizer) as from
|
|
276
|
+
* and preventing misuse
|
|
277
|
+
* @param options - Same options as `simulate`, plus profiling method
|
|
278
|
+
* @returns An object containing the function return value and profile result.
|
|
279
|
+
*/
|
|
280
|
+
public override profile(
|
|
281
|
+
options: Omit<ProfileInteractionOptions, 'from'> = { profileMode: 'gates' },
|
|
282
|
+
): Promise<TxProfileResult> {
|
|
283
|
+
return super.profile({ ...options, from: this.from });
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Overrides the send method, adding the sender of the authwit (authorizer) as from
|
|
288
|
+
* and preventing misuse
|
|
289
|
+
* @param options - An optional object containing 'fee' options information
|
|
290
|
+
* @returns A TxReceipt (if wait is true/undefined) or TxHash (if wait is false)
|
|
291
|
+
*/
|
|
292
|
+
public override send(options?: Omit<SendInteractionOptionsWithoutWait, 'from'>): Promise<TxSendResultMined>;
|
|
293
|
+
// Generic overload for explicit wait values
|
|
294
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
295
|
+
public override send<W extends InteractionWaitOptions>(
|
|
296
|
+
options?: Omit<SendInteractionOptions<W>, 'from'>,
|
|
297
|
+
): Promise<SendReturn<W>>;
|
|
298
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
299
|
+
public override send(
|
|
300
|
+
options?: Omit<SendInteractionOptions<InteractionWaitOptions>, 'from'>,
|
|
301
|
+
): Promise<SendReturn<InteractionWaitOptions>> {
|
|
302
|
+
return super.send({ ...options, from: this.from });
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
private static getSetAuthorizedAbi(): FunctionAbi {
|
|
306
|
+
return {
|
|
307
|
+
name: 'set_authorized',
|
|
308
|
+
isInitializer: false,
|
|
309
|
+
functionType: FunctionType.PUBLIC,
|
|
310
|
+
isOnlySelf: true,
|
|
311
|
+
isStatic: false,
|
|
312
|
+
parameters: [
|
|
313
|
+
{
|
|
314
|
+
name: 'message_hash',
|
|
315
|
+
type: { kind: 'field' },
|
|
316
|
+
visibility: 'private' as ABIParameterVisibility,
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
name: 'authorize',
|
|
320
|
+
type: { kind: 'boolean' },
|
|
321
|
+
visibility: 'private' as ABIParameterVisibility,
|
|
322
|
+
},
|
|
323
|
+
],
|
|
324
|
+
errorTypes: {},
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
2
|
+
import { retryUntil } from '@aztec-labs/foundation/retry';
|
|
3
|
+
import type { BlockTag } from '@aztec-labs/stdlib/block';
|
|
4
|
+
import type { AztecNode } from '@aztec-labs/stdlib/interfaces/client';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Waits for the L1 to L2 message to be ready to be consumed.
|
|
8
|
+
* @param node - Aztec node instance used to obtain the information about the message
|
|
9
|
+
* @param l1ToL2MessageHash - Hash of the L1 to L2 message
|
|
10
|
+
* @param opts - Options
|
|
11
|
+
*/
|
|
12
|
+
export function waitForL1ToL2MessageReady(
|
|
13
|
+
node: Pick<AztecNode, 'getBlockData' | 'getL1ToL2MessageIndex'>,
|
|
14
|
+
l1ToL2MessageHash: Fr,
|
|
15
|
+
opts: {
|
|
16
|
+
/** Timeout for the operation in seconds */ timeoutSeconds: number;
|
|
17
|
+
/**
|
|
18
|
+
* Chain tip to evaluate readiness against. Defaults to `'latest'`. Set this to the tip the consuming PXE syncs to
|
|
19
|
+
* (e.g. `'proven'`) so readiness answers whether the message is present at the same block the transaction
|
|
20
|
+
* simulation will anchor to, not at a newer tip.
|
|
21
|
+
*/
|
|
22
|
+
chainTip?: BlockTag;
|
|
23
|
+
},
|
|
24
|
+
): Promise<boolean> {
|
|
25
|
+
return retryUntil(
|
|
26
|
+
() => isL1ToL2MessageReady(node, l1ToL2MessageHash, opts.chainTip),
|
|
27
|
+
`L1 to L2 message ${l1ToL2MessageHash.toString()} ready`,
|
|
28
|
+
opts.timeoutSeconds,
|
|
29
|
+
1,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Returns whether the L1 to L2 message is ready to be consumed.
|
|
35
|
+
* @param node - Aztec node instance used to obtain the information about the message
|
|
36
|
+
* @param l1ToL2MessageHash - Hash of the L1 to L2 message
|
|
37
|
+
* @param chainTip - Chain tip to evaluate readiness against. Defaults to `'latest'`. Pass the tip the consuming PXE
|
|
38
|
+
* syncs to (e.g. `'proven'`) so readiness is checked at the block the transaction simulation will anchor to.
|
|
39
|
+
* @returns True if the message is ready to be consumed, false otherwise
|
|
40
|
+
*/
|
|
41
|
+
export async function isL1ToL2MessageReady(
|
|
42
|
+
node: Pick<AztecNode, 'getBlockData' | 'getL1ToL2MessageIndex'>,
|
|
43
|
+
l1ToL2MessageHash: Fr,
|
|
44
|
+
chainTip: BlockTag = 'latest',
|
|
45
|
+
): Promise<boolean> {
|
|
46
|
+
const messageIndex = await node.getL1ToL2MessageIndex(l1ToL2MessageHash);
|
|
47
|
+
if (messageIndex === undefined) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Blocks consume L1-to-L2 messages in Inbox order into consecutive leaves of the message tree, so the message is
|
|
52
|
+
// available at a tip exactly when that tip's tree has grown past the message's leaf index.
|
|
53
|
+
const block = await node.getBlockData(chainTip);
|
|
54
|
+
return block !== undefined && messageIndex < BigInt(block.header.state.l1ToL2MessageTree.nextAvailableLeafIndex);
|
|
55
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
2
|
+
import { ProtocolContractAddress } from '@aztec-labs/protocol-contracts';
|
|
3
|
+
import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
|
|
4
|
+
import { deriveStorageSlotInMap } from '@aztec-labs/stdlib/hash';
|
|
5
|
+
import type { AztecNode } from '@aztec-labs/stdlib/interfaces/client';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns the owner's fee juice balance.
|
|
9
|
+
* Note: This is used only e2e_local_network_example test. TODO: Consider nuking.
|
|
10
|
+
*/
|
|
11
|
+
export async function getFeeJuiceBalance(owner: AztecAddress, node: AztecNode): Promise<bigint> {
|
|
12
|
+
const slot = await deriveStorageSlotInMap(new Fr(1), owner);
|
|
13
|
+
return (await node.getPublicStorageAt('latest', ProtocolContractAddress.FeeJuice, slot)).toBigInt();
|
|
14
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The representation of a FieldCompressedString in aztec.nr
|
|
5
|
+
*/
|
|
6
|
+
interface NoirFieldCompressedString {
|
|
7
|
+
/**
|
|
8
|
+
* The field value of the string
|
|
9
|
+
*/
|
|
10
|
+
value: bigint;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* This turns
|
|
14
|
+
* @param field - The field that contains the string
|
|
15
|
+
* @returns - the string that is decoded from the field
|
|
16
|
+
*/
|
|
17
|
+
export const readFieldCompressedString = (field: NoirFieldCompressedString): string => {
|
|
18
|
+
const vals: number[] = Array.from(new Fr(field.value).toBuffer());
|
|
19
|
+
|
|
20
|
+
let str = '';
|
|
21
|
+
for (let i = 0; i < vals.length; i++) {
|
|
22
|
+
if (vals[i] != 0) {
|
|
23
|
+
str += String.fromCharCode(Number(vals[i]));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return str;
|
|
27
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { Logger } from '@aztec-labs/foundation/log';
|
|
2
|
+
import { retryUntil } from '@aztec-labs/foundation/retry';
|
|
3
|
+
import { sleep } from '@aztec-labs/foundation/sleep';
|
|
4
|
+
import type { AztecNode } from '@aztec-labs/stdlib/interfaces/client';
|
|
5
|
+
import type { TxHash, TxReceipt } from '@aztec-labs/stdlib/tx';
|
|
6
|
+
import { SortedTxStatuses, TxStatus } from '@aztec-labs/stdlib/tx';
|
|
7
|
+
|
|
8
|
+
import { DefaultWaitOpts, type WaitOpts } from '../contract/wait_opts.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Waits for an Aztec node to become reachable, polling {@link AztecNode.getNodeInfo} until it succeeds.
|
|
12
|
+
* @param node - The Aztec node to contact.
|
|
13
|
+
* @param logger - Optional logger for polling progress.
|
|
14
|
+
* @param opts - Optional timeout and interval (in seconds). `timeout` defaults to {@link DefaultWaitOpts.timeout};
|
|
15
|
+
* pass `timeout: 0` to wait indefinitely.
|
|
16
|
+
* @throws TimeoutError if the node stays unreachable past the timeout.
|
|
17
|
+
*/
|
|
18
|
+
export const waitForNode = async (node: AztecNode, logger?: Logger, opts?: Pick<WaitOpts, 'timeout' | 'interval'>) => {
|
|
19
|
+
await retryUntil(
|
|
20
|
+
async () => {
|
|
21
|
+
try {
|
|
22
|
+
logger?.verbose('Attempting to contact Aztec node...');
|
|
23
|
+
await node.getNodeInfo();
|
|
24
|
+
logger?.verbose('Contacted Aztec node');
|
|
25
|
+
return true;
|
|
26
|
+
} catch {
|
|
27
|
+
logger?.verbose('Failed to contact Aztec Node');
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
},
|
|
31
|
+
'RPC Get Node Info',
|
|
32
|
+
opts?.timeout ?? DefaultWaitOpts.timeout,
|
|
33
|
+
opts?.interval ?? DefaultWaitOpts.interval,
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** Returns true if the receipt status is at least the desired status level. */
|
|
38
|
+
function hasReachedStatus(receipt: TxReceipt, desiredStatus: TxStatus): boolean {
|
|
39
|
+
return SortedTxStatuses.indexOf(receipt.status) >= SortedTxStatuses.indexOf(desiredStatus);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Waits for a transaction to be mined and returns its receipt.
|
|
44
|
+
* @param node - The Aztec node to query for transaction status
|
|
45
|
+
* @param txHash - The hash of the transaction to wait for
|
|
46
|
+
* @param opts - Optional configuration for waiting behavior
|
|
47
|
+
* @returns The transaction receipt
|
|
48
|
+
* @throws If the transaction fails and dontThrowOnRevert is not set
|
|
49
|
+
*/
|
|
50
|
+
export async function waitForTx(node: AztecNode, txHash: TxHash, opts?: WaitOpts): Promise<TxReceipt> {
|
|
51
|
+
const ignoreDroppedReceiptsFor = opts?.ignoreDroppedReceiptsFor ?? DefaultWaitOpts.ignoreDroppedReceiptsFor;
|
|
52
|
+
const waitForStatus = opts?.waitForStatus ?? TxStatus.CHECKPOINTED;
|
|
53
|
+
const timeout = opts?.timeout ?? DefaultWaitOpts.timeout;
|
|
54
|
+
// The initial delay counts against the timeout: the deadline is fixed before sleeping, and the sleep never
|
|
55
|
+
// exceeds it.
|
|
56
|
+
const deadline = timeout ? { deadline: new Date(Date.now() + timeout * 1000) } : undefined;
|
|
57
|
+
|
|
58
|
+
if (opts?.initialDelay) {
|
|
59
|
+
const delay = Math.min(opts.initialDelay, timeout ?? Infinity);
|
|
60
|
+
await sleep(delay * 1000);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// The grace period for DROPPED receipts starts at the first poll, so the initial delay does not consume it.
|
|
64
|
+
const startTime = Date.now();
|
|
65
|
+
|
|
66
|
+
const receipt = await retryUntil(
|
|
67
|
+
async () => {
|
|
68
|
+
const txReceipt = await node.getTxReceipt(txHash);
|
|
69
|
+
// If receipt is not yet available, try again
|
|
70
|
+
if (txReceipt.isPending()) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
// If the tx was "dropped", either return it or ignore based on timing.
|
|
74
|
+
// We can ignore it at first because the transaction may have been sent to node 1, and now we're asking node 2 for the receipt.
|
|
75
|
+
// If we don't allow a short grace period, we could incorrectly return a TxReceipt with status DROPPED.
|
|
76
|
+
if (txReceipt.isDropped()) {
|
|
77
|
+
const elapsedSeconds = (Date.now() - startTime) / 1000;
|
|
78
|
+
if (!ignoreDroppedReceiptsFor || elapsedSeconds > ignoreDroppedReceiptsFor) {
|
|
79
|
+
return txReceipt;
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
// Check if the receipt has reached the desired status level
|
|
84
|
+
if (!hasReachedStatus(txReceipt, waitForStatus)) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
return txReceipt;
|
|
88
|
+
},
|
|
89
|
+
'isMined',
|
|
90
|
+
deadline,
|
|
91
|
+
opts?.interval ?? DefaultWaitOpts.interval,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
if (!receipt.isMined()) {
|
|
95
|
+
throw new Error(`Transaction ${txHash.toString()} was ${receipt.status}. Reason: ${receipt.error ?? 'unknown'}`);
|
|
96
|
+
}
|
|
97
|
+
if (!receipt.hasExecutionSucceeded() && !opts?.dontThrowOnRevert) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
`Transaction ${txHash.toString()} reverted: ${receipt.executionResult}. Reason: ${receipt.error ?? 'unknown'}`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return receipt;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export {
|
|
107
|
+
createAztecNodeClient,
|
|
108
|
+
type AztecNode,
|
|
109
|
+
type AztecNodeClientOptions,
|
|
110
|
+
} from '@aztec-labs/stdlib/interfaces/client';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Grumpkin } from '@aztec-labs/foundation/crypto/grumpkin';
|
|
2
|
+
import type { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
|
|
3
|
+
import type { PublicKey } from '@aztec-labs/stdlib/keys';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Method for generating a public grumpkin key from a private key.
|
|
7
|
+
* @param privateKey - The private key.
|
|
8
|
+
* @returns The generated public key.
|
|
9
|
+
*/
|
|
10
|
+
export function generatePublicKey(privateKey: GrumpkinScalar): Promise<PublicKey> {
|
|
11
|
+
return Grumpkin.mul(Grumpkin.generator, privateKey);
|
|
12
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { AccountFeePaymentMethodOptions } from '@aztec-labs/entrypoints/account';
|
|
2
|
+
import type { ChainInfo } from '@aztec-labs/entrypoints/interfaces';
|
|
3
|
+
import { ProtocolContractAddress } from '@aztec-labs/protocol-contracts';
|
|
4
|
+
import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
|
|
5
|
+
import type { GasSettings } from '@aztec-labs/stdlib/gas';
|
|
6
|
+
import { ExecutionPayload } from '@aztec-labs/stdlib/tx';
|
|
7
|
+
|
|
8
|
+
import type { Account } from '../account/account.js';
|
|
9
|
+
import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Fee payment method that allows an account contract to pay for its own deployment
|
|
13
|
+
* It works by rerouting the provided fee payment method through the account's entrypoint,
|
|
14
|
+
* which sets itself as fee payer. If no payment method is provided, it is assumed the
|
|
15
|
+
* account will pay with its own fee juice balance.
|
|
16
|
+
*
|
|
17
|
+
* Usually, in order to pay fees it is necessary to obtain an ExecutionPayload that encodes the necessary information
|
|
18
|
+
* that is sent to the user's account entrypoint, that has plumbing to handle it.
|
|
19
|
+
* If there's no account contract yet (it's being deployed) a MultiCallContract is used, which doesn't have a concept of fees or
|
|
20
|
+
* how to handle this payload.
|
|
21
|
+
* HOWEVER, the account contract's entrypoint does, so this method reshapes that fee payload into a call to the account contract entrypoint
|
|
22
|
+
* being deployed with the original fee payload.
|
|
23
|
+
*
|
|
24
|
+
* This class can be seen in action in DeployAccountMethod.ts#getSelfPaymentMethod
|
|
25
|
+
*/
|
|
26
|
+
export class AccountEntrypointMetaPaymentMethod implements FeePaymentMethod {
|
|
27
|
+
constructor(
|
|
28
|
+
private account: Account,
|
|
29
|
+
private chainInfo: ChainInfo,
|
|
30
|
+
private paymentMethod?: FeePaymentMethod,
|
|
31
|
+
private feeEntrypointOptions?: any,
|
|
32
|
+
) {}
|
|
33
|
+
|
|
34
|
+
getAsset(): Promise<AztecAddress> {
|
|
35
|
+
return this.paymentMethod?.getAsset() ?? Promise.resolve(ProtocolContractAddress.FeeJuice);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async getExecutionPayload(): Promise<ExecutionPayload> {
|
|
39
|
+
// Get the execution payload for the fee
|
|
40
|
+
const innerPayload = (await this.paymentMethod?.getExecutionPayload()) ?? ExecutionPayload.empty();
|
|
41
|
+
|
|
42
|
+
// If no fee entrypoint options were provided, compute them based on the wrapped payment method
|
|
43
|
+
// This mimics how the actual account contract works when invoked directly:
|
|
44
|
+
// - If we are the fee payer, are there calls in the inner payload? In that case, those calls can
|
|
45
|
+
// only be claiming fee juice, so we use FEE_JUICE_WITH_CLAIM
|
|
46
|
+
// - If we are the fee payer, but there are no calls, then we assume the account already has
|
|
47
|
+
// fee juice and can pay directly with PREEXISTING_FEE_JUICE
|
|
48
|
+
// - If we are not the fee payer, then EXTERNAL is used
|
|
49
|
+
let options = this.feeEntrypointOptions;
|
|
50
|
+
if (!options) {
|
|
51
|
+
const feePayer = (await this.paymentMethod?.getFeePayer()) ?? this.account.getAddress();
|
|
52
|
+
const isFeePayer = feePayer.equals(this.account.getAddress());
|
|
53
|
+
|
|
54
|
+
let accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.EXTERNAL;
|
|
55
|
+
if (isFeePayer) {
|
|
56
|
+
accountFeePaymentMethodOptions =
|
|
57
|
+
innerPayload.calls.length === 0
|
|
58
|
+
? AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE
|
|
59
|
+
: AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
options = { feePaymentMethodOptions: accountFeePaymentMethodOptions };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Use the generic wrapping mechanism from the account interface
|
|
66
|
+
return this.account.wrapExecutionPayload(innerPayload, this.chainInfo, options);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
getFeePayer(): Promise<AztecAddress> {
|
|
70
|
+
return this.paymentMethod?.getFeePayer() ?? Promise.resolve(this.account.getAddress());
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
getGasSettings(): GasSettings | undefined {
|
|
74
|
+
return this.paymentMethod?.getGasSettings();
|
|
75
|
+
}
|
|
76
|
+
}
|