@aztec/aztec.js 0.0.1-commit.03f7ef2 → 0.0.1-commit.04852196a
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/account.d.ts +25 -40
- package/dest/account/account.d.ts.map +1 -1
- package/dest/account/account.js +19 -47
- package/dest/account/account_contract.d.ts +8 -9
- package/dest/account/account_contract.d.ts.map +1 -1
- package/dest/account/account_with_secret_key.d.ts +19 -7
- package/dest/account/account_with_secret_key.d.ts.map +1 -1
- package/dest/account/account_with_secret_key.js +21 -4
- package/dest/account/index.d.ts +3 -2
- package/dest/account/index.d.ts.map +1 -1
- package/dest/account/index.js +2 -0
- package/dest/account/signerless_account.d.ts +5 -6
- package/dest/account/signerless_account.d.ts.map +1 -1
- package/dest/account/signerless_account.js +8 -11
- package/dest/api/abi.d.ts +2 -2
- package/dest/api/abi.d.ts.map +1 -1
- package/dest/api/account.d.ts +2 -4
- package/dest/api/account.d.ts.map +1 -1
- package/dest/api/account.js +1 -3
- package/dest/api/authorization.d.ts +2 -2
- package/dest/api/authorization.d.ts.map +1 -1
- package/dest/api/authorization.js +1 -1
- package/dest/api/contract.d.ts +18 -12
- package/dest/api/contract.d.ts.map +1 -1
- package/dest/api/contract.js +16 -10
- package/dest/api/deployment.d.ts +1 -2
- package/dest/api/deployment.d.ts.map +1 -1
- package/dest/api/deployment.js +0 -1
- package/dest/api/events.d.ts +18 -6
- package/dest/api/events.d.ts.map +1 -1
- package/dest/api/events.js +37 -22
- package/dest/api/fields.d.ts +2 -1
- package/dest/api/fields.d.ts.map +1 -1
- package/dest/api/fields.js +1 -0
- package/dest/api/keys.d.ts +1 -1
- package/dest/api/keys.js +1 -1
- package/dest/api/node.d.ts +8 -4
- package/dest/api/node.d.ts.map +1 -1
- package/dest/api/node.js +7 -3
- package/dest/api/protocol.d.ts +7 -1
- package/dest/api/protocol.d.ts.map +1 -1
- package/dest/api/protocol.js +6 -0
- package/dest/api/tx.d.ts +2 -2
- package/dest/api/tx.d.ts.map +1 -1
- package/dest/api/tx.js +1 -1
- package/dest/api/wallet.d.ts +3 -2
- package/dest/api/wallet.d.ts.map +1 -1
- package/dest/api/wallet.js +2 -1
- package/dest/authorization/call_authorization_request.d.ts +22 -1
- package/dest/authorization/call_authorization_request.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.d.ts +8 -10
- package/dest/contract/base_contract_interaction.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.js +5 -17
- package/dest/contract/batch_call.d.ts +3 -3
- package/dest/contract/batch_call.d.ts.map +1 -1
- package/dest/contract/batch_call.js +20 -9
- package/dest/contract/contract_base.d.ts +4 -1
- package/dest/contract/contract_base.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.d.ts +7 -16
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +107 -18
- package/dest/contract/deploy_method.d.ts +91 -19
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +73 -34
- package/dest/contract/get_gas_limits.js +3 -3
- package/dest/contract/interaction_options.d.ts +99 -21
- package/dest/contract/interaction_options.d.ts.map +1 -1
- package/dest/contract/interaction_options.js +41 -1
- package/dest/contract/protocol_contracts/auth-registry.d.ts +36 -0
- package/dest/contract/protocol_contracts/auth-registry.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/auth-registry.js +1005 -0
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts +15 -0
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/contract-class-registry.js +139 -0
- package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +22 -0
- package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/contract-instance-registry.js +465 -0
- package/dest/contract/protocol_contracts/fee-juice.d.ts +21 -0
- package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/fee-juice.js +434 -0
- package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts +34 -0
- package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/multi-call-entrypoint.js +601 -0
- package/dest/contract/protocol_contracts/public-checks.d.ts +26 -0
- package/dest/contract/protocol_contracts/public-checks.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/public-checks.js +609 -0
- package/dest/contract/wait_for_proven.d.ts +2 -2
- package/dest/contract/wait_for_proven.d.ts.map +1 -1
- package/dest/contract/wait_for_proven.js +1 -1
- package/dest/contract/wait_opts.d.ts +16 -0
- package/dest/contract/wait_opts.d.ts.map +1 -0
- package/dest/contract/wait_opts.js +5 -0
- package/dest/deployment/publish_class.js +2 -2
- 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 +3 -3
- package/dest/ethereum/portal_manager.d.ts +7 -4
- package/dest/ethereum/portal_manager.d.ts.map +1 -1
- package/dest/ethereum/portal_manager.js +15 -16
- package/dest/fee/fee_juice_payment_method_with_claim.js +6 -6
- package/dest/fee/private_fee_payment_method.d.ts +2 -1
- package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/private_fee_payment_method.js +11 -10
- package/dest/fee/public_fee_payment_method.d.ts +2 -1
- package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/public_fee_payment_method.js +11 -10
- package/dest/fee/sponsored_fee_payment.js +3 -3
- 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 +120 -0
- package/dest/utils/abi_types.d.ts +6 -1
- package/dest/utils/abi_types.d.ts.map +1 -1
- package/dest/utils/abi_types.js +1 -1
- package/dest/utils/authwit.d.ts +8 -6
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +15 -15
- package/dest/utils/cross_chain.d.ts +3 -8
- package/dest/utils/cross_chain.d.ts.map +1 -1
- package/dest/utils/cross_chain.js +8 -15
- package/dest/utils/node.d.ts +12 -1
- package/dest/utils/node.d.ts.map +1 -1
- package/dest/utils/node.js +46 -0
- package/dest/wallet/account_entrypoint_meta_payment_method.d.ts +5 -8
- package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -1
- package/dest/wallet/account_entrypoint_meta_payment_method.js +28 -43
- package/dest/wallet/account_manager.d.ts +5 -8
- package/dest/wallet/account_manager.d.ts.map +1 -1
- package/dest/wallet/account_manager.js +5 -11
- package/dest/wallet/capabilities.d.ts +452 -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 +46 -7
- package/dest/wallet/deploy_account_method.d.ts.map +1 -1
- package/dest/wallet/deploy_account_method.js +33 -5
- package/dest/wallet/index.d.ts +2 -1
- package/dest/wallet/index.d.ts.map +1 -1
- package/dest/wallet/index.js +1 -0
- package/dest/wallet/wallet.d.ts +1810 -2493
- package/dest/wallet/wallet.d.ts.map +1 -1
- package/dest/wallet/wallet.js +230 -108
- package/package.json +25 -14
- package/src/account/account.ts +34 -58
- package/src/account/account_contract.ts +6 -7
- package/src/account/account_with_secret_key.ts +33 -8
- package/src/account/index.ts +2 -1
- package/src/account/signerless_account.ts +13 -12
- package/src/api/abi.ts +1 -0
- package/src/api/account.ts +9 -3
- package/src/api/authorization.ts +1 -0
- package/src/api/contract.ts +31 -9
- package/src/api/deployment.ts +0 -1
- package/src/api/events.ts +50 -32
- package/src/api/fields.ts +1 -0
- package/src/api/keys.ts +2 -2
- package/src/api/node.ts +7 -3
- package/src/api/protocol.ts +7 -0
- package/src/api/tx.ts +2 -0
- package/src/api/wallet.ts +48 -3
- package/src/contract/base_contract_interaction.ts +28 -15
- package/src/contract/batch_call.ts +20 -15
- package/src/contract/contract_function_interaction.ts +114 -26
- package/src/contract/deploy_method.ts +179 -41
- package/src/contract/get_gas_limits.ts +3 -3
- package/src/contract/interaction_options.ts +141 -23
- package/src/contract/protocol_contracts/auth-registry.ts +553 -0
- package/src/contract/protocol_contracts/contract-class-registry.ts +99 -0
- package/src/contract/protocol_contracts/contract-instance-registry.ts +302 -0
- package/src/contract/protocol_contracts/fee-juice.ts +266 -0
- package/src/contract/protocol_contracts/multi-call-entrypoint.ts +336 -0
- package/src/contract/protocol_contracts/public-checks.ts +320 -0
- package/src/contract/wait_for_proven.ts +1 -1
- package/src/contract/wait_opts.ts +21 -0
- package/src/deployment/publish_class.ts +2 -2
- package/src/deployment/publish_instance.ts +3 -6
- package/src/ethereum/portal_manager.ts +17 -21
- package/src/fee/fee_juice_payment_method_with_claim.ts +5 -5
- package/src/fee/private_fee_payment_method.ts +8 -7
- package/src/fee/public_fee_payment_method.ts +9 -8
- package/src/fee/sponsored_fee_payment.ts +3 -3
- package/src/scripts/generate_protocol_contract_types.ts +150 -0
- package/src/utils/abi_types.ts +7 -0
- package/src/utils/authwit.ts +34 -24
- package/src/utils/cross_chain.ts +9 -18
- package/src/utils/node.ts +62 -0
- package/src/wallet/account_entrypoint_meta_payment_method.ts +28 -60
- package/src/wallet/account_manager.ts +5 -13
- package/src/wallet/capabilities.ts +500 -0
- package/src/wallet/deploy_account_method.ts +74 -13
- package/src/wallet/index.ts +1 -0
- package/src/wallet/wallet.ts +367 -128
- package/dest/account/interface.d.ts +0 -19
- package/dest/account/interface.d.ts.map +0 -1
- package/dest/account/interface.js +0 -5
- package/dest/contract/deploy_sent_tx.d.ts +0 -48
- package/dest/contract/deploy_sent_tx.d.ts.map +0 -1
- package/dest/contract/deploy_sent_tx.js +0 -46
- package/dest/contract/protocol_contracts.d.ts +0 -9
- package/dest/contract/protocol_contracts.d.ts.map +0 -1
- package/dest/contract/protocol_contracts.js +0 -26
- package/dest/contract/sent_tx.d.ts +0 -50
- package/dest/contract/sent_tx.d.ts.map +0 -1
- package/dest/contract/sent_tx.js +0 -90
- package/dest/contract/unsafe_contract.d.ts +0 -15
- package/dest/contract/unsafe_contract.d.ts.map +0 -1
- package/dest/contract/unsafe_contract.js +0 -6
- package/dest/deployment/broadcast_function.d.ts +0 -24
- package/dest/deployment/broadcast_function.d.ts.map +0 -1
- package/dest/deployment/broadcast_function.js +0 -74
- package/src/account/interface.ts +0 -25
- package/src/contract/deploy_sent_tx.ts +0 -75
- package/src/contract/protocol_contracts.ts +0 -35
- package/src/contract/sent_tx.ts +0 -129
- package/src/contract/unsafe_contract.ts +0 -19
- package/src/deployment/broadcast_function.ts +0 -148
package/src/wallet/wallet.ts
CHANGED
|
@@ -7,20 +7,15 @@ import {
|
|
|
7
7
|
type ContractArtifact,
|
|
8
8
|
ContractArtifactSchema,
|
|
9
9
|
type EventMetadataDefinition,
|
|
10
|
-
|
|
11
|
-
FunctionType,
|
|
10
|
+
FunctionCall,
|
|
12
11
|
} from '@aztec/stdlib/abi';
|
|
13
12
|
import { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
14
13
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
|
-
import {
|
|
16
|
-
type ContractClassMetadata,
|
|
17
|
-
ContractClassWithIdSchema,
|
|
18
|
-
type ContractInstanceWithAddress,
|
|
19
|
-
ContractInstanceWithAddressSchema,
|
|
20
|
-
type ContractMetadata,
|
|
21
|
-
} from '@aztec/stdlib/contract';
|
|
14
|
+
import { type ContractInstanceWithAddress, ContractInstanceWithAddressSchema } from '@aztec/stdlib/contract';
|
|
22
15
|
import { Gas } from '@aztec/stdlib/gas';
|
|
16
|
+
import { LogId } from '@aztec/stdlib/logs';
|
|
23
17
|
import { AbiDecodedSchema, type ApiSchemaFor, optional, schemas, zodFor } from '@aztec/stdlib/schemas';
|
|
18
|
+
import type { ExecutionPayload, InTx } from '@aztec/stdlib/tx';
|
|
24
19
|
import {
|
|
25
20
|
Capsule,
|
|
26
21
|
HashedValues,
|
|
@@ -28,21 +23,24 @@ import {
|
|
|
28
23
|
TxProfileResult,
|
|
29
24
|
TxReceipt,
|
|
30
25
|
TxSimulationResult,
|
|
31
|
-
|
|
26
|
+
UtilityExecutionResult,
|
|
32
27
|
inTxSchema,
|
|
33
28
|
} from '@aztec/stdlib/tx';
|
|
34
|
-
import type { ExecutionPayload, InTx } from '@aztec/stdlib/tx';
|
|
35
29
|
|
|
36
30
|
import { z } from 'zod';
|
|
37
31
|
|
|
38
|
-
import
|
|
39
|
-
FeeEstimationOptions,
|
|
40
|
-
GasSettingsOption,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
import {
|
|
33
|
+
type FeeEstimationOptions,
|
|
34
|
+
type GasSettingsOption,
|
|
35
|
+
type InteractionWaitOptions,
|
|
36
|
+
NO_WAIT,
|
|
37
|
+
type ProfileInteractionOptions,
|
|
38
|
+
type SendInteractionOptionsWithoutWait,
|
|
39
|
+
type SendReturn,
|
|
40
|
+
type SimulateInteractionOptions,
|
|
44
41
|
} from '../contract/interaction_options.js';
|
|
45
42
|
import type { CallIntent, IntentInnerHash } from '../utils/authwit.js';
|
|
43
|
+
import type { AppCapabilities, WalletCapabilities } from './capabilities.js';
|
|
46
44
|
|
|
47
45
|
/**
|
|
48
46
|
* A wrapper type that allows any item to be associated with an alias.
|
|
@@ -60,7 +58,7 @@ export type Aliased<T> = {
|
|
|
60
58
|
|
|
61
59
|
/**
|
|
62
60
|
* Options for simulating interactions with the wallet. Overrides the fee settings of an interaction with
|
|
63
|
-
* a simplified version that only hints at the wallet
|
|
61
|
+
* a simplified version that only hints at the wallet whether the interaction contains a
|
|
64
62
|
* fee payment method or not
|
|
65
63
|
*/
|
|
66
64
|
export type SimulateOptions = Omit<SimulateInteractionOptions, 'fee'> & {
|
|
@@ -70,7 +68,7 @@ export type SimulateOptions = Omit<SimulateInteractionOptions, 'fee'> & {
|
|
|
70
68
|
|
|
71
69
|
/**
|
|
72
70
|
* Options for profiling interactions with the wallet. Overrides the fee settings of an interaction with
|
|
73
|
-
* a simplified version that only hints at the wallet
|
|
71
|
+
* a simplified version that only hints at the wallet whether the interaction contains a
|
|
74
72
|
* fee payment method or not
|
|
75
73
|
*/
|
|
76
74
|
export type ProfileOptions = Omit<ProfileInteractionOptions, 'fee'> & {
|
|
@@ -80,45 +78,54 @@ export type ProfileOptions = Omit<ProfileInteractionOptions, 'fee'> & {
|
|
|
80
78
|
|
|
81
79
|
/**
|
|
82
80
|
* Options for sending/proving interactions with the wallet. Overrides the fee settings of an interaction with
|
|
83
|
-
* a simplified version that only hints at the wallet
|
|
81
|
+
* a simplified version that only hints at the wallet whether the interaction contains a
|
|
84
82
|
* fee payment method or not
|
|
85
83
|
*/
|
|
86
|
-
export type SendOptions =
|
|
84
|
+
export type SendOptions<W extends InteractionWaitOptions = undefined> = Omit<
|
|
85
|
+
SendInteractionOptionsWithoutWait,
|
|
86
|
+
'fee'
|
|
87
|
+
> & {
|
|
87
88
|
/** The fee options */
|
|
88
89
|
fee?: GasSettingsOption;
|
|
90
|
+
/** Whether to wait for the transaction to be mined */
|
|
91
|
+
wait?: W;
|
|
89
92
|
};
|
|
90
93
|
|
|
91
94
|
/**
|
|
92
|
-
* Helper type that represents all methods that can be batched.
|
|
95
|
+
* Helper type that represents all methods that can be batched (all methods except batch itself).
|
|
93
96
|
*/
|
|
94
|
-
export type BatchableMethods =
|
|
95
|
-
Wallet,
|
|
96
|
-
'registerContract' | 'sendTx' | 'registerSender' | 'simulateUtility' | 'simulateTx'
|
|
97
|
-
>;
|
|
97
|
+
export type BatchableMethods = Omit<Wallet, 'batch'>;
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
|
-
*
|
|
101
|
-
* This is what the wallet will accept as arguments to the `batch` method.
|
|
100
|
+
* A method call with its name and arguments.
|
|
102
101
|
*/
|
|
103
|
-
|
|
102
|
+
type BatchedMethodInternal<T extends keyof BatchableMethods> = {
|
|
104
103
|
/** The method name */
|
|
105
104
|
name: T;
|
|
106
105
|
/** The method arguments */
|
|
107
106
|
args: Parameters<BatchableMethods[T]>;
|
|
108
107
|
};
|
|
109
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Union of all possible batched method calls.
|
|
111
|
+
* This ensures type safety: the `args` must match the specific `name`.
|
|
112
|
+
*/
|
|
113
|
+
export type BatchedMethod = {
|
|
114
|
+
[K in keyof BatchableMethods]: BatchedMethodInternal<K>;
|
|
115
|
+
}[keyof BatchableMethods];
|
|
116
|
+
|
|
110
117
|
/**
|
|
111
118
|
* Helper type to extract the return type of a batched method
|
|
112
119
|
*/
|
|
113
120
|
export type BatchedMethodResult<T> =
|
|
114
|
-
T extends
|
|
121
|
+
T extends BatchedMethodInternal<infer K> ? Awaited<ReturnType<BatchableMethods[K]>> : never;
|
|
115
122
|
|
|
116
123
|
/**
|
|
117
124
|
* Wrapper type for batch results that includes the method name for discriminated union deserialization.
|
|
118
125
|
* Each result is wrapped as \{ name: 'methodName', result: ActualResult \} to allow proper deserialization
|
|
119
126
|
* when AztecAddress and TxHash would otherwise be ambiguous (both are hex strings).
|
|
120
127
|
*/
|
|
121
|
-
export type BatchedMethodResultWrapper<T extends BatchedMethod
|
|
128
|
+
export type BatchedMethodResultWrapper<T extends BatchedMethod> = {
|
|
122
129
|
/** The method name */
|
|
123
130
|
name: T['name'];
|
|
124
131
|
/** The method result */
|
|
@@ -128,54 +135,120 @@ export type BatchedMethodResultWrapper<T extends BatchedMethod<keyof BatchableMe
|
|
|
128
135
|
/**
|
|
129
136
|
* Maps a tuple of BatchedMethod to a tuple of their wrapped return types
|
|
130
137
|
*/
|
|
131
|
-
export type BatchResults<T extends readonly BatchedMethod
|
|
138
|
+
export type BatchResults<T extends readonly BatchedMethod[]> = {
|
|
132
139
|
[K in keyof T]: BatchedMethodResultWrapper<T[K]>;
|
|
133
140
|
};
|
|
134
141
|
|
|
135
142
|
/**
|
|
136
|
-
*
|
|
143
|
+
* Base filter options for event queries.
|
|
137
144
|
*/
|
|
138
|
-
export type
|
|
139
|
-
/** The address of the contract that emitted the events. */
|
|
140
|
-
contractAddress: AztecAddress;
|
|
141
|
-
/** Addresses of accounts that are in scope for this filter. */
|
|
142
|
-
scopes: AztecAddress[];
|
|
145
|
+
export type EventFilterBase = {
|
|
143
146
|
/** Transaction in which the events were emitted. */
|
|
144
147
|
txHash?: TxHash;
|
|
145
148
|
/** The block number from which to start fetching events (inclusive).
|
|
146
149
|
* Optional. If provided, it must be greater or equal than 1.
|
|
147
150
|
* Defaults to the initial L2 block number (INITIAL_L2_BLOCK_NUM).
|
|
148
|
-
|
|
151
|
+
*/
|
|
149
152
|
fromBlock?: BlockNumber;
|
|
150
153
|
/** The block number until which to fetch logs (not inclusive).
|
|
151
154
|
* Optional. If provided, it must be greater than fromBlock.
|
|
152
|
-
* Defaults to the latest known block to PXE + 1.
|
|
153
155
|
*/
|
|
154
156
|
toBlock?: BlockNumber;
|
|
157
|
+
/** Log id after which to start fetching logs. Used for pagination. */
|
|
158
|
+
afterLog?: LogId;
|
|
155
159
|
};
|
|
156
160
|
|
|
157
161
|
/**
|
|
158
|
-
*
|
|
162
|
+
* Filter options when querying private events.
|
|
159
163
|
*/
|
|
160
|
-
export type
|
|
164
|
+
export type PrivateEventFilter = EventFilterBase & {
|
|
165
|
+
/** The address of the contract that emitted the events. */
|
|
166
|
+
contractAddress: AztecAddress;
|
|
167
|
+
/** Addresses of accounts that are in scope for this filter. */
|
|
168
|
+
scopes: AztecAddress[];
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Filter options when querying public events.
|
|
173
|
+
*/
|
|
174
|
+
export type PublicEventFilter = EventFilterBase & {
|
|
175
|
+
/** The address of the contract that emitted the events. */
|
|
176
|
+
contractAddress?: AztecAddress;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* An ABI decoded event with associated metadata.
|
|
181
|
+
* @typeParam T - The decoded event type
|
|
182
|
+
* @typeParam M - Additional metadata fields (empty by default)
|
|
183
|
+
*/
|
|
184
|
+
export type Event<T, M extends object = object> = {
|
|
161
185
|
/** The ABI decoded event */
|
|
162
186
|
event: T;
|
|
163
187
|
/** Metadata describing event context information such as tx and block */
|
|
164
|
-
metadata: InTx;
|
|
188
|
+
metadata: InTx & M;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/** An ABI decoded private event with associated metadata. */
|
|
192
|
+
export type PrivateEvent<T> = Event<T>;
|
|
193
|
+
|
|
194
|
+
/** An ABI decoded public event with associated metadata (includes contract address). */
|
|
195
|
+
export type PublicEvent<T> = Event<
|
|
196
|
+
T,
|
|
197
|
+
{
|
|
198
|
+
/**
|
|
199
|
+
* Address of the contract that emitted this event
|
|
200
|
+
*/
|
|
201
|
+
contractAddress: AztecAddress;
|
|
202
|
+
}
|
|
203
|
+
>;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Contract metadata including deployment and registration status.
|
|
207
|
+
*/
|
|
208
|
+
export type ContractMetadata = {
|
|
209
|
+
/** The contract instance */
|
|
210
|
+
instance?: ContractInstanceWithAddress;
|
|
211
|
+
/** Whether the contract has been initialized (init nullifier exists) */
|
|
212
|
+
isContractInitialized: boolean;
|
|
213
|
+
/** Whether the contract instance is publicly deployed on-chain */
|
|
214
|
+
isContractPublished: boolean;
|
|
215
|
+
/** Whether the contract has been updated to a different class */
|
|
216
|
+
isContractUpdated: boolean;
|
|
217
|
+
/** The updated contract class ID if the contract has been updated */
|
|
218
|
+
updatedContractClassId?: Fr | undefined;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Contract class metadata.
|
|
223
|
+
*/
|
|
224
|
+
export type ContractClassMetadata = {
|
|
225
|
+
/** Whether the artifact is registered in the wallet */
|
|
226
|
+
isArtifactRegistered: boolean;
|
|
227
|
+
/** Whether the contract class is publicly registered on-chain */
|
|
228
|
+
isContractClassPubliclyRegistered: boolean;
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Options for executing a utility function call.
|
|
233
|
+
*/
|
|
234
|
+
export type ExecuteUtilityOptions = {
|
|
235
|
+
/** The scope for the utility execution (determines which notes and keys are visible). */
|
|
236
|
+
scope: AztecAddress;
|
|
237
|
+
/** Optional auth witnesses to use during execution. */
|
|
238
|
+
authWitnesses?: AuthWitness[];
|
|
165
239
|
};
|
|
166
240
|
|
|
167
241
|
/**
|
|
168
242
|
* The wallet interface.
|
|
169
243
|
*/
|
|
170
244
|
export type Wallet = {
|
|
171
|
-
getContractClassMetadata(id: Fr, includeArtifact?: boolean): Promise<ContractClassMetadata>;
|
|
172
|
-
getContractMetadata(address: AztecAddress): Promise<ContractMetadata>;
|
|
173
245
|
getPrivateEvents<T>(
|
|
174
246
|
eventMetadata: EventMetadataDefinition,
|
|
175
247
|
eventFilter: PrivateEventFilter,
|
|
176
248
|
): Promise<PrivateEvent<T>[]>;
|
|
177
249
|
getChainInfo(): Promise<ChainInfo>;
|
|
178
|
-
|
|
250
|
+
getContractMetadata(address: AztecAddress): Promise<ContractMetadata>;
|
|
251
|
+
getContractClassMetadata(id: Fr): Promise<ContractClassMetadata>;
|
|
179
252
|
registerSender(address: AztecAddress, alias?: string): Promise<AztecAddress>;
|
|
180
253
|
getAddressBook(): Promise<Aliased<AztecAddress>[]>;
|
|
181
254
|
getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
@@ -185,26 +258,19 @@ export type Wallet = {
|
|
|
185
258
|
secretKey?: Fr,
|
|
186
259
|
): Promise<ContractInstanceWithAddress>;
|
|
187
260
|
simulateTx(exec: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult>;
|
|
188
|
-
|
|
261
|
+
executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult>;
|
|
189
262
|
profileTx(exec: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult>;
|
|
190
|
-
sendTx
|
|
191
|
-
|
|
192
|
-
|
|
263
|
+
sendTx<W extends InteractionWaitOptions = undefined>(
|
|
264
|
+
exec: ExecutionPayload,
|
|
265
|
+
opts: SendOptions<W>,
|
|
266
|
+
): Promise<SendReturn<W>>;
|
|
267
|
+
createAuthWit(from: AztecAddress, messageHashOrIntent: IntentInnerHash | CallIntent): Promise<AuthWitness>;
|
|
268
|
+
requestCapabilities(manifest: AppCapabilities): Promise<WalletCapabilities>;
|
|
269
|
+
batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>>;
|
|
193
270
|
};
|
|
194
271
|
|
|
195
|
-
export const FunctionCallSchema = z.object({
|
|
196
|
-
name: z.string(),
|
|
197
|
-
to: schemas.AztecAddress,
|
|
198
|
-
selector: schemas.FunctionSelector,
|
|
199
|
-
type: z.nativeEnum(FunctionType),
|
|
200
|
-
isStatic: z.boolean(),
|
|
201
|
-
hideMsgSender: z.boolean(),
|
|
202
|
-
args: z.array(schemas.Fr),
|
|
203
|
-
returnTypes: z.array(AbiTypeSchema),
|
|
204
|
-
});
|
|
205
|
-
|
|
206
272
|
export const ExecutionPayloadSchema = z.object({
|
|
207
|
-
calls: z.array(
|
|
273
|
+
calls: z.array(FunctionCall.schema),
|
|
208
274
|
authWitnesses: z.array(AuthWitness.schema),
|
|
209
275
|
capsules: z.array(Capsule.schema),
|
|
210
276
|
extraHashedArgs: z.array(HashedValues.schema),
|
|
@@ -227,11 +293,20 @@ export const WalletSimulationFeeOptionSchema = GasSettingsOptionSchema.extend({
|
|
|
227
293
|
estimateGas: optional(z.boolean()),
|
|
228
294
|
});
|
|
229
295
|
|
|
296
|
+
export const WaitOptsSchema = z.object({
|
|
297
|
+
ignoreDroppedReceiptsFor: optional(z.number()),
|
|
298
|
+
timeout: optional(z.number()),
|
|
299
|
+
interval: optional(z.number()),
|
|
300
|
+
dontThrowOnRevert: optional(z.boolean()),
|
|
301
|
+
});
|
|
302
|
+
|
|
230
303
|
export const SendOptionsSchema = z.object({
|
|
231
304
|
from: schemas.AztecAddress,
|
|
232
305
|
authWitnesses: optional(z.array(AuthWitness.schema)),
|
|
233
306
|
capsules: optional(z.array(Capsule.schema)),
|
|
234
307
|
fee: optional(GasSettingsOptionSchema),
|
|
308
|
+
wait: optional(z.union([z.literal(NO_WAIT), WaitOptsSchema])),
|
|
309
|
+
additionalScopes: optional(z.array(schemas.AztecAddress)),
|
|
235
310
|
});
|
|
236
311
|
|
|
237
312
|
export const SimulateOptionsSchema = z.object({
|
|
@@ -242,6 +317,7 @@ export const SimulateOptionsSchema = z.object({
|
|
|
242
317
|
skipTxValidation: optional(z.boolean()),
|
|
243
318
|
skipFeeEnforcement: optional(z.boolean()),
|
|
244
319
|
includeMetadata: optional(z.boolean()),
|
|
320
|
+
additionalScopes: optional(z.array(schemas.AztecAddress)),
|
|
245
321
|
});
|
|
246
322
|
|
|
247
323
|
export const ProfileOptionsSchema = SimulateOptionsSchema.extend({
|
|
@@ -250,59 +326,35 @@ export const ProfileOptionsSchema = SimulateOptionsSchema.extend({
|
|
|
250
326
|
});
|
|
251
327
|
|
|
252
328
|
export const MessageHashOrIntentSchema = z.union([
|
|
253
|
-
schemas.Fr,
|
|
254
329
|
z.object({ consumer: schemas.AztecAddress, innerHash: schemas.Fr }),
|
|
255
330
|
z.object({
|
|
256
331
|
caller: schemas.AztecAddress,
|
|
257
|
-
call:
|
|
332
|
+
call: FunctionCall.schema,
|
|
258
333
|
}),
|
|
259
334
|
]);
|
|
260
335
|
|
|
261
|
-
export const BatchedMethodSchema = z.union([
|
|
262
|
-
z.object({
|
|
263
|
-
name: z.literal('registerSender'),
|
|
264
|
-
args: z.tuple([schemas.AztecAddress, optional(z.string())]),
|
|
265
|
-
}),
|
|
266
|
-
z.object({
|
|
267
|
-
name: z.literal('registerContract'),
|
|
268
|
-
args: z.tuple([ContractInstanceWithAddressSchema, optional(ContractArtifactSchema), optional(schemas.Fr)]),
|
|
269
|
-
}),
|
|
270
|
-
z.object({
|
|
271
|
-
name: z.literal('sendTx'),
|
|
272
|
-
args: z.tuple([ExecutionPayloadSchema, SendOptionsSchema]),
|
|
273
|
-
}),
|
|
274
|
-
z.object({
|
|
275
|
-
name: z.literal('simulateUtility'),
|
|
276
|
-
args: z.tuple([FunctionCallSchema, optional(z.array(AuthWitness.schema))]),
|
|
277
|
-
}),
|
|
278
|
-
z.object({
|
|
279
|
-
name: z.literal('simulateTx'),
|
|
280
|
-
args: z.tuple([ExecutionPayloadSchema, SimulateOptionsSchema]),
|
|
281
|
-
}),
|
|
282
|
-
]);
|
|
283
|
-
|
|
284
|
-
export const ContractMetadataSchema = zodFor<ContractMetadata>()(
|
|
285
|
-
z.object({
|
|
286
|
-
contractInstance: z.union([ContractInstanceWithAddressSchema, z.undefined()]),
|
|
287
|
-
isContractInitialized: z.boolean(),
|
|
288
|
-
isContractPublished: z.boolean(),
|
|
289
|
-
}),
|
|
290
|
-
);
|
|
291
|
-
|
|
292
|
-
export const ContractClassMetadataSchema = zodFor<ContractClassMetadata>()(
|
|
293
|
-
z.object({
|
|
294
|
-
contractClass: z.union([ContractClassWithIdSchema, z.undefined()]),
|
|
295
|
-
isContractClassPubliclyRegistered: z.boolean(),
|
|
296
|
-
artifact: z.union([ContractArtifactSchema, z.undefined()]),
|
|
297
|
-
}),
|
|
298
|
-
);
|
|
299
|
-
|
|
300
336
|
export const EventMetadataDefinitionSchema = z.object({
|
|
301
337
|
eventSelector: schemas.EventSelector,
|
|
302
338
|
abiType: AbiTypeSchema,
|
|
303
339
|
fieldNames: z.array(z.string()),
|
|
304
340
|
});
|
|
305
341
|
|
|
342
|
+
const EventFilterBaseSchema = z.object({
|
|
343
|
+
txHash: optional(TxHash.schema),
|
|
344
|
+
fromBlock: optional(BlockNumberPositiveSchema),
|
|
345
|
+
toBlock: optional(BlockNumberPositiveSchema),
|
|
346
|
+
afterLog: optional(LogId.schema),
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
export const PrivateEventFilterSchema = EventFilterBaseSchema.extend({
|
|
350
|
+
contractAddress: schemas.AztecAddress,
|
|
351
|
+
scopes: z.array(schemas.AztecAddress),
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
export const PublicEventFilterSchema = EventFilterBaseSchema.extend({
|
|
355
|
+
contractAddress: optional(schemas.AztecAddress),
|
|
356
|
+
});
|
|
357
|
+
|
|
306
358
|
export const PrivateEventSchema: z.ZodType<any> = zodFor<PrivateEvent<AbiDecoded>>()(
|
|
307
359
|
z.object({
|
|
308
360
|
event: AbiDecodedSchema,
|
|
@@ -310,22 +362,167 @@ export const PrivateEventSchema: z.ZodType<any> = zodFor<PrivateEvent<AbiDecoded
|
|
|
310
362
|
}),
|
|
311
363
|
);
|
|
312
364
|
|
|
313
|
-
export const
|
|
365
|
+
export const PublicEventSchema = zodFor<PublicEvent<AbiDecoded>>()(
|
|
366
|
+
z.object({
|
|
367
|
+
event: AbiDecodedSchema,
|
|
368
|
+
metadata: z.intersection(inTxSchema(), z.object({ contractAddress: schemas.AztecAddress })),
|
|
369
|
+
}),
|
|
370
|
+
);
|
|
371
|
+
|
|
372
|
+
export const ContractMetadataSchema = z.object({
|
|
373
|
+
instance: optional(ContractInstanceWithAddressSchema),
|
|
374
|
+
isContractInitialized: z.boolean(),
|
|
375
|
+
isContractPublished: z.boolean(),
|
|
376
|
+
isContractUpdated: z.boolean(),
|
|
377
|
+
updatedContractClassId: optional(schemas.Fr),
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
export const ContractClassMetadataSchema = z.object({
|
|
381
|
+
isArtifactRegistered: z.boolean(),
|
|
382
|
+
isContractClassPubliclyRegistered: z.boolean(),
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
export const ContractFunctionPatternSchema = z.object({
|
|
386
|
+
contract: z.union([schemas.AztecAddress, z.literal('*')]),
|
|
387
|
+
function: z.union([z.string(), z.literal('*')]),
|
|
388
|
+
additionalScopes: optional(z.union([z.array(schemas.AztecAddress), z.literal('*')])),
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
export const AccountsCapabilitySchema = z.object({
|
|
392
|
+
type: z.literal('accounts'),
|
|
393
|
+
canGet: optional(z.boolean()),
|
|
394
|
+
canCreateAuthWit: optional(z.boolean()),
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
export const GrantedAccountsCapabilitySchema = AccountsCapabilitySchema.extend({
|
|
398
|
+
accounts: z.array(z.object({ alias: z.string(), item: schemas.AztecAddress })),
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
export const ContractsCapabilitySchema = z.object({
|
|
402
|
+
type: z.literal('contracts'),
|
|
403
|
+
contracts: z.union([z.literal('*'), z.array(schemas.AztecAddress)]),
|
|
404
|
+
canRegister: optional(z.boolean()),
|
|
405
|
+
canGetMetadata: optional(z.boolean()),
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
export const GrantedContractsCapabilitySchema = ContractsCapabilitySchema;
|
|
409
|
+
|
|
410
|
+
export const ContractClassesCapabilitySchema = z.object({
|
|
411
|
+
type: z.literal('contractClasses'),
|
|
412
|
+
classes: z.union([z.literal('*'), z.array(schemas.Fr)]),
|
|
413
|
+
canGetMetadata: z.boolean(),
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
export const GrantedContractClassesCapabilitySchema = ContractClassesCapabilitySchema;
|
|
417
|
+
|
|
418
|
+
export const SimulationCapabilitySchema = z.object({
|
|
419
|
+
type: z.literal('simulation'),
|
|
420
|
+
transactions: optional(
|
|
421
|
+
z.object({
|
|
422
|
+
scope: z.union([z.literal('*'), z.array(ContractFunctionPatternSchema)]),
|
|
423
|
+
}),
|
|
424
|
+
),
|
|
425
|
+
utilities: optional(
|
|
426
|
+
z.object({
|
|
427
|
+
scope: z.union([z.literal('*'), z.array(ContractFunctionPatternSchema)]),
|
|
428
|
+
}),
|
|
429
|
+
),
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
export const GrantedSimulationCapabilitySchema = SimulationCapabilitySchema;
|
|
433
|
+
|
|
434
|
+
export const TransactionCapabilitySchema = z.object({
|
|
435
|
+
type: z.literal('transaction'),
|
|
436
|
+
scope: z.union([z.literal('*'), z.array(ContractFunctionPatternSchema)]),
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
export const GrantedTransactionCapabilitySchema = TransactionCapabilitySchema;
|
|
440
|
+
|
|
441
|
+
export const DataCapabilitySchema = z.object({
|
|
442
|
+
type: z.literal('data'),
|
|
443
|
+
addressBook: optional(z.boolean()),
|
|
444
|
+
privateEvents: optional(
|
|
445
|
+
z.object({
|
|
446
|
+
contracts: z.union([z.literal('*'), z.array(schemas.AztecAddress)]),
|
|
447
|
+
}),
|
|
448
|
+
),
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
export const GrantedDataCapabilitySchema = DataCapabilitySchema;
|
|
452
|
+
|
|
453
|
+
export const CapabilitySchema = z.discriminatedUnion('type', [
|
|
454
|
+
AccountsCapabilitySchema,
|
|
455
|
+
ContractsCapabilitySchema,
|
|
456
|
+
ContractClassesCapabilitySchema,
|
|
457
|
+
SimulationCapabilitySchema,
|
|
458
|
+
TransactionCapabilitySchema,
|
|
459
|
+
DataCapabilitySchema,
|
|
460
|
+
]);
|
|
461
|
+
|
|
462
|
+
export const GrantedCapabilitySchema = z.discriminatedUnion('type', [
|
|
463
|
+
GrantedAccountsCapabilitySchema,
|
|
464
|
+
GrantedContractsCapabilitySchema,
|
|
465
|
+
GrantedContractClassesCapabilitySchema,
|
|
466
|
+
GrantedSimulationCapabilitySchema,
|
|
467
|
+
GrantedTransactionCapabilitySchema,
|
|
468
|
+
GrantedDataCapabilitySchema,
|
|
469
|
+
]);
|
|
470
|
+
|
|
471
|
+
export const AppCapabilitiesSchema = z.object({
|
|
472
|
+
version: z.literal('1.0'),
|
|
473
|
+
metadata: z.object({
|
|
474
|
+
name: z.string(),
|
|
475
|
+
version: z.string(),
|
|
476
|
+
description: optional(z.string()),
|
|
477
|
+
url: optional(z.string()),
|
|
478
|
+
icon: optional(z.string()),
|
|
479
|
+
}),
|
|
480
|
+
capabilities: z.array(CapabilitySchema),
|
|
481
|
+
behavior: optional(
|
|
482
|
+
z.object({
|
|
483
|
+
mode: optional(z.enum(['strict', 'permissive'])),
|
|
484
|
+
expiration: optional(z.number()),
|
|
485
|
+
}),
|
|
486
|
+
),
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
export const WalletCapabilitiesSchema = z.object({
|
|
490
|
+
version: z.literal('1.0'),
|
|
491
|
+
granted: z.array(GrantedCapabilitySchema),
|
|
492
|
+
wallet: z.object({
|
|
493
|
+
name: z.string(),
|
|
494
|
+
version: z.string(),
|
|
495
|
+
}),
|
|
496
|
+
expiresAt: optional(z.number()),
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
const OffchainEffectSchema = z.object({
|
|
500
|
+
data: z.array(schemas.Fr),
|
|
314
501
|
contractAddress: schemas.AztecAddress,
|
|
315
|
-
scopes: z.array(schemas.AztecAddress),
|
|
316
|
-
txHash: optional(TxHash.schema),
|
|
317
|
-
fromBlock: optional(BlockNumberPositiveSchema),
|
|
318
|
-
toBlock: optional(BlockNumberPositiveSchema),
|
|
319
502
|
});
|
|
320
503
|
|
|
321
|
-
|
|
504
|
+
const OffchainMessageSchema = z.object({
|
|
505
|
+
recipient: schemas.AztecAddress,
|
|
506
|
+
payload: z.array(schemas.Fr),
|
|
507
|
+
contractAddress: schemas.AztecAddress,
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
const OffchainOutputSchema = z.object({
|
|
511
|
+
offchainEffects: z.array(OffchainEffectSchema),
|
|
512
|
+
offchainMessages: z.array(OffchainMessageSchema),
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Record of all wallet method schemas (excluding batch).
|
|
517
|
+
* This is the single source of truth for method schemas - batch schemas are derived from this.
|
|
518
|
+
*/
|
|
519
|
+
const WalletMethodSchemas = {
|
|
322
520
|
getChainInfo: z
|
|
323
521
|
.function()
|
|
324
522
|
.args()
|
|
325
523
|
.returns(z.object({ chainId: schemas.Fr, version: schemas.Fr })),
|
|
326
|
-
getContractClassMetadata: z.function().args(schemas.Fr, optional(z.boolean())).returns(ContractClassMetadataSchema),
|
|
327
524
|
getContractMetadata: z.function().args(schemas.AztecAddress).returns(ContractMetadataSchema),
|
|
328
|
-
|
|
525
|
+
getContractClassMetadata: z.function().args(schemas.Fr).returns(ContractClassMetadataSchema),
|
|
329
526
|
getPrivateEvents: z
|
|
330
527
|
.function()
|
|
331
528
|
.args(EventMetadataDefinitionSchema, PrivateEventFilterSchema)
|
|
@@ -344,26 +541,68 @@ export const WalletSchema: ApiSchemaFor<Wallet> = {
|
|
|
344
541
|
.args(ContractInstanceWithAddressSchema, optional(ContractArtifactSchema), optional(schemas.Fr))
|
|
345
542
|
.returns(ContractInstanceWithAddressSchema),
|
|
346
543
|
simulateTx: z.function().args(ExecutionPayloadSchema, SimulateOptionsSchema).returns(TxSimulationResult.schema),
|
|
347
|
-
|
|
544
|
+
executeUtility: z
|
|
348
545
|
.function()
|
|
349
|
-
.args(
|
|
350
|
-
|
|
546
|
+
.args(
|
|
547
|
+
FunctionCall.schema,
|
|
548
|
+
z.object({
|
|
549
|
+
scope: schemas.AztecAddress,
|
|
550
|
+
authWitnesses: optional(z.array(AuthWitness.schema)),
|
|
551
|
+
}),
|
|
552
|
+
)
|
|
553
|
+
.returns(UtilityExecutionResult.schema),
|
|
351
554
|
profileTx: z.function().args(ExecutionPayloadSchema, ProfileOptionsSchema).returns(TxProfileResult.schema),
|
|
352
|
-
sendTx: z
|
|
353
|
-
createAuthWit: z.function().args(schemas.AztecAddress, MessageHashOrIntentSchema).returns(AuthWitness.schema),
|
|
354
|
-
// @ts-expect-error - ApiSchemaFor cannot properly type generic methods with readonly arrays
|
|
355
|
-
batch: z
|
|
555
|
+
sendTx: z
|
|
356
556
|
.function()
|
|
357
|
-
.args(
|
|
557
|
+
.args(ExecutionPayloadSchema, SendOptionsSchema)
|
|
358
558
|
.returns(
|
|
359
|
-
z.
|
|
360
|
-
z.
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
z.object({ name: z.literal('sendTx'), result: TxHash.schema }),
|
|
364
|
-
z.object({ name: z.literal('simulateUtility'), result: UtilitySimulationResult.schema }),
|
|
365
|
-
z.object({ name: z.literal('simulateTx'), result: TxSimulationResult.schema }),
|
|
366
|
-
]),
|
|
367
|
-
),
|
|
559
|
+
z.union([
|
|
560
|
+
z.object({ txHash: TxHash.schema }).merge(OffchainOutputSchema),
|
|
561
|
+
z.object({ receipt: TxReceipt.schema }).merge(OffchainOutputSchema),
|
|
562
|
+
]),
|
|
368
563
|
),
|
|
564
|
+
createAuthWit: z.function().args(schemas.AztecAddress, MessageHashOrIntentSchema).returns(AuthWitness.schema),
|
|
565
|
+
requestCapabilities: z.function().args(AppCapabilitiesSchema).returns(WalletCapabilitiesSchema),
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Creates batch schemas from the individual wallet methods.
|
|
570
|
+
* This allows us to define them once and derive batch schemas automatically,
|
|
571
|
+
* reducing duplication and ensuring consistency.
|
|
572
|
+
*/
|
|
573
|
+
function createBatchSchemas<T extends Record<string, z.ZodFunction<z.ZodTuple<any, any>, z.ZodTypeAny>>>(
|
|
574
|
+
methodSchemas: T,
|
|
575
|
+
) {
|
|
576
|
+
const names = Object.keys(methodSchemas) as (keyof T)[];
|
|
577
|
+
|
|
578
|
+
const namesAndArgs = names.map(name =>
|
|
579
|
+
z.object({
|
|
580
|
+
name: z.literal(name),
|
|
581
|
+
args: methodSchemas[name].parameters(),
|
|
582
|
+
}),
|
|
583
|
+
);
|
|
584
|
+
|
|
585
|
+
const namesAndReturns = names.map(name =>
|
|
586
|
+
z.object({
|
|
587
|
+
name: z.literal(name),
|
|
588
|
+
result: methodSchemas[name].returnType(),
|
|
589
|
+
}),
|
|
590
|
+
);
|
|
591
|
+
|
|
592
|
+
// Type assertion needed because discriminatedUnion expects a tuple type [T, T, ...T[]]
|
|
593
|
+
// but we're building the array dynamically. The runtime behavior is correct.
|
|
594
|
+
return {
|
|
595
|
+
input: z.discriminatedUnion('name', namesAndArgs as [(typeof namesAndArgs)[0], ...typeof namesAndArgs]),
|
|
596
|
+
output: z.discriminatedUnion('name', namesAndReturns as [(typeof namesAndReturns)[0], ...typeof namesAndReturns]),
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
const { input: BatchedMethodSchema, output: BatchedResultSchema } = createBatchSchemas(WalletMethodSchemas);
|
|
601
|
+
|
|
602
|
+
export { BatchedMethodSchema, BatchedResultSchema };
|
|
603
|
+
|
|
604
|
+
export const WalletSchema: ApiSchemaFor<Wallet> = {
|
|
605
|
+
...WalletMethodSchemas,
|
|
606
|
+
// @ts-expect-error - ApiSchemaFor cannot properly type generic methods with readonly arrays
|
|
607
|
+
batch: z.function().args(z.array(BatchedMethodSchema)).returns(z.array(BatchedResultSchema)),
|
|
369
608
|
};
|