@aztec/aztec.js 0.0.1-commit.9b94fc1 → 0.0.1-commit.a072138
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 +9 -10
- package/dest/account/account_contract.d.ts.map +1 -1
- package/dest/account/account_with_secret_key.d.ts +21 -9
- 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 +4 -3
- package/dest/account/index.d.ts.map +1 -1
- package/dest/account/index.js +2 -0
- package/dest/account/signerless_account.d.ts +6 -7
- package/dest/account/signerless_account.d.ts.map +1 -1
- package/dest/account/signerless_account.js +8 -11
- 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 +16 -10
- package/dest/api/contract.d.ts.map +1 -1
- package/dest/api/contract.js +14 -8
- 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 +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 +23 -2
- 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 +1 -1
- package/dest/contract/batch_call.d.ts.map +1 -1
- package/dest/contract/batch_call.js +3 -1
- 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 +1 -1
- package/dest/contract/deploy_method.d.ts +64 -17
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +42 -24
- package/dest/contract/interaction_options.d.ts +42 -5
- package/dest/contract/interaction_options.d.ts.map +1 -1
- package/dest/contract/interaction_options.js +8 -1
- package/dest/contract/protocol_contracts/auth-registry.d.ts +27 -0
- package/dest/contract/protocol_contracts/auth-registry.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/auth-registry.js +558 -0
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts +26 -0
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/contract-class-registry.js +385 -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 +426 -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 +575 -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 +583 -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/broadcast_function.js +4 -4
- package/dest/deployment/publish_class.js +3 -3
- 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 +9 -6
- package/dest/ethereum/portal_manager.d.ts.map +1 -1
- package/dest/ethereum/portal_manager.js +17 -18
- package/dest/fee/fee_juice_payment_method_with_claim.js +1 -1
- package/dest/fee/private_fee_payment_method.js +1 -1
- package/dest/fee/public_fee_payment_method.js +1 -1
- 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 +2 -2
- package/dest/utils/abi_types.d.ts.map +1 -1
- package/dest/utils/authwit.d.ts +9 -7
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +6 -10
- package/dest/utils/cross_chain.d.ts +2 -2
- package/dest/utils/cross_chain.d.ts.map +1 -1
- package/dest/utils/fee_juice.js +1 -1
- package/dest/utils/field_compressed_string.js +1 -1
- 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/utils/pub_key.d.ts +2 -2
- package/dest/utils/pub_key.d.ts.map +1 -1
- package/dest/utils/pub_key.js +1 -1
- 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 +6 -9
- package/dest/wallet/account_manager.d.ts.map +1 -1
- package/dest/wallet/account_manager.js +6 -12
- package/dest/wallet/capabilities.d.ts +444 -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 +35 -7
- package/dest/wallet/deploy_account_method.d.ts.map +1 -1
- package/dest/wallet/deploy_account_method.js +8 -6
- 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 +1542 -917
- package/dest/wallet/wallet.d.ts.map +1 -1
- package/dest/wallet/wallet.js +191 -86
- package/package.json +15 -13
- package/src/account/account.ts +34 -58
- package/src/account/account_contract.ts +7 -8
- package/src/account/account_with_secret_key.ts +34 -9
- package/src/account/index.ts +3 -2
- package/src/account/signerless_account.ts +14 -13
- package/src/api/account.ts +9 -3
- package/src/api/authorization.ts +1 -0
- package/src/api/contract.ts +22 -7
- package/src/api/fields.ts +2 -1
- 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 +47 -2
- package/src/authorization/call_authorization_request.ts +1 -1
- package/src/contract/base_contract_interaction.ts +27 -15
- package/src/contract/batch_call.ts +4 -2
- package/src/contract/deploy_method.ts +123 -30
- package/src/contract/interaction_options.ts +49 -4
- package/src/contract/protocol_contracts/auth-registry.ts +351 -0
- package/src/contract/protocol_contracts/contract-class-registry.ts +241 -0
- package/src/contract/protocol_contracts/contract-instance-registry.ts +302 -0
- package/src/contract/protocol_contracts/fee-juice.ts +264 -0
- package/src/contract/protocol_contracts/multi-call-entrypoint.ts +332 -0
- package/src/contract/protocol_contracts/public-checks.ts +316 -0
- package/src/contract/wait_for_proven.ts +1 -1
- package/src/contract/wait_opts.ts +21 -0
- package/src/deployment/broadcast_function.ts +4 -4
- package/src/deployment/publish_class.ts +3 -3
- package/src/deployment/publish_instance.ts +3 -6
- package/src/ethereum/portal_manager.ts +20 -24
- package/src/fee/fee_juice_payment_method_with_claim.ts +1 -1
- package/src/fee/private_fee_payment_method.ts +1 -1
- package/src/fee/public_fee_payment_method.ts +1 -1
- package/src/scripts/generate_protocol_contract_types.ts +150 -0
- package/src/utils/abi_types.ts +1 -1
- package/src/utils/authwit.ts +20 -8
- package/src/utils/cross_chain.ts +1 -1
- package/src/utils/fee_juice.ts +1 -1
- package/src/utils/field_compressed_string.ts +1 -1
- package/src/utils/node.ts +62 -0
- package/src/utils/pub_key.ts +2 -2
- package/src/wallet/account_entrypoint_meta_payment_method.ts +28 -60
- package/src/wallet/account_manager.ts +6 -14
- package/src/wallet/capabilities.ts +491 -0
- package/src/wallet/deploy_account_method.ts +38 -14
- package/src/wallet/index.ts +1 -0
- package/src/wallet/wallet.ts +307 -92
- 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 -51
- 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/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 -130
- package/src/contract/unsafe_contract.ts +0 -19
|
@@ -1,34 +1,62 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { ContractArtifact, FunctionArtifact } from '@aztec/stdlib/abi';
|
|
3
3
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
5
5
|
import type { PublicKeys } from '@aztec/stdlib/keys';
|
|
6
6
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
7
7
|
|
|
8
|
+
import type { Account } from '../account/account.js';
|
|
8
9
|
import type { Contract } from '../contract/contract.js';
|
|
9
10
|
import type { ContractBase } from '../contract/contract_base.js';
|
|
10
11
|
import {
|
|
11
12
|
DeployMethod,
|
|
12
|
-
type
|
|
13
|
+
type DeployOptionsWithoutWait,
|
|
13
14
|
type RequestDeployOptions,
|
|
14
15
|
type SimulateDeployOptions,
|
|
15
16
|
} from '../contract/deploy_method.js';
|
|
17
|
+
import type { FeePaymentMethodOption, InteractionWaitOptions } from '../contract/interaction_options.js';
|
|
16
18
|
import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
|
|
17
19
|
import { AccountEntrypointMetaPaymentMethod } from './account_entrypoint_meta_payment_method.js';
|
|
18
20
|
import type { Wallet } from './index.js';
|
|
19
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Extended fee payment method option for account deployments that includes entrypoint wrapping options
|
|
24
|
+
*/
|
|
25
|
+
export type DeployAccountFeePaymentMethodOption = FeePaymentMethodOption & {
|
|
26
|
+
/** Optional entrypoint-specific options for wrapping execution payloads */
|
|
27
|
+
feeEntrypointOptions?: unknown;
|
|
28
|
+
};
|
|
29
|
+
|
|
20
30
|
/**
|
|
21
31
|
* The configuration options for the request method. Omits the contractAddressSalt, since
|
|
22
32
|
* for account contracts that is fixed in the constructor
|
|
23
33
|
*/
|
|
24
|
-
export type RequestDeployAccountOptions = Omit<RequestDeployOptions, 'contractAddressSalt'
|
|
34
|
+
export type RequestDeployAccountOptions = Omit<RequestDeployOptions, 'contractAddressSalt' | 'fee'> & {
|
|
35
|
+
/** Fee options specific to account deployment */
|
|
36
|
+
fee?: DeployAccountFeePaymentMethodOption;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Base configuration options for the send/prove methods without wait parameter. Omits:
|
|
41
|
+
* - The contractAddressSalt, since for account contracts that is fixed in the constructor.
|
|
42
|
+
* - UniversalDeployment flag, since account contracts are always deployed with it set to true
|
|
43
|
+
*/
|
|
44
|
+
export type DeployAccountOptionsWithoutWait = Omit<DeployOptionsWithoutWait, 'contractAddressSalt' | 'universalDeploy'>;
|
|
25
45
|
|
|
26
46
|
/**
|
|
27
47
|
* The configuration options for the send/prove methods. Omits:
|
|
28
48
|
* - The contractAddressSalt, since for account contracts that is fixed in the constructor.
|
|
29
49
|
* - UniversalDeployment flag, since account contracts are always deployed with it set to true
|
|
30
50
|
*/
|
|
31
|
-
export type DeployAccountOptions =
|
|
51
|
+
export type DeployAccountOptions<W extends InteractionWaitOptions = undefined> = DeployAccountOptionsWithoutWait & {
|
|
52
|
+
/**
|
|
53
|
+
* Whether to wait for the transaction to be mined.
|
|
54
|
+
* - undefined (default): wait with default options and return TxReceipt
|
|
55
|
+
* - WaitOpts object: wait with custom options and return TxReceipt
|
|
56
|
+
* - false: return txHash immediately without waiting
|
|
57
|
+
*/
|
|
58
|
+
wait?: W;
|
|
59
|
+
};
|
|
32
60
|
|
|
33
61
|
/**
|
|
34
62
|
* The configuration options for the simulate method. Omits the contractAddressSalt, since
|
|
@@ -47,6 +75,7 @@ export class DeployAccountMethod<TContract extends ContractBase = Contract> exte
|
|
|
47
75
|
artifact: ContractArtifact,
|
|
48
76
|
postDeployCtor: (instance: ContractInstanceWithAddress, wallet: Wallet) => TContract,
|
|
49
77
|
private salt: Fr,
|
|
78
|
+
private account: Account,
|
|
50
79
|
args: any[] = [],
|
|
51
80
|
constructorNameOrArtifact?: string | FunctionArtifact,
|
|
52
81
|
) {
|
|
@@ -61,19 +90,14 @@ export class DeployAccountMethod<TContract extends ContractBase = Contract> exte
|
|
|
61
90
|
* For more details on how the fee payment routing works see documentation of AccountEntrypointMetaPaymentMethod class.
|
|
62
91
|
*
|
|
63
92
|
* @param originalPaymentMethod - originalPaymentMethod The original payment method to be wrapped.
|
|
93
|
+
* @param feeEntrypointOptions - Optional entrypoint-specific options for wrapping. If not provided, will be auto-computed based on the payment method.
|
|
64
94
|
* @returns A FeePaymentMethod that routes the original one through the account's entrypoint (AccountEntrypointMetaPaymentMethod)
|
|
65
95
|
*/
|
|
66
|
-
private getSelfFeePaymentMethod(originalPaymentMethod?: FeePaymentMethod) {
|
|
96
|
+
private getSelfFeePaymentMethod(originalPaymentMethod?: FeePaymentMethod, feeEntrypointOptions?: any) {
|
|
67
97
|
if (!this.address) {
|
|
68
98
|
throw new Error('Instance is not yet constructed. This is a bug!');
|
|
69
99
|
}
|
|
70
|
-
return new AccountEntrypointMetaPaymentMethod(
|
|
71
|
-
this.wallet,
|
|
72
|
-
this.artifact,
|
|
73
|
-
'entrypoint',
|
|
74
|
-
this.address,
|
|
75
|
-
originalPaymentMethod,
|
|
76
|
-
);
|
|
100
|
+
return new AccountEntrypointMetaPaymentMethod(this.account, originalPaymentMethod, feeEntrypointOptions);
|
|
77
101
|
}
|
|
78
102
|
|
|
79
103
|
/**
|
|
@@ -97,7 +121,7 @@ export class DeployAccountMethod<TContract extends ContractBase = Contract> exte
|
|
|
97
121
|
const executionPayloads = [deploymentExecutionPayload];
|
|
98
122
|
// If this is a self-deployment, manage the fee accordingly
|
|
99
123
|
if (opts?.deployer?.equals(AztecAddress.ZERO)) {
|
|
100
|
-
const feePaymentMethod = this.getSelfFeePaymentMethod(opts?.fee?.paymentMethod);
|
|
124
|
+
const feePaymentMethod = this.getSelfFeePaymentMethod(opts?.fee?.paymentMethod, opts?.fee?.feeEntrypointOptions);
|
|
101
125
|
const feeExecutionPayload = await feePaymentMethod.getExecutionPayload();
|
|
102
126
|
// Notice they are reversed (fee payment usually goes first):
|
|
103
127
|
// this is because we need to construct the contract BEFORE it can pay for its own fee
|
|
@@ -113,7 +137,7 @@ export class DeployAccountMethod<TContract extends ContractBase = Contract> exte
|
|
|
113
137
|
return mergeExecutionPayloads(executionPayloads);
|
|
114
138
|
}
|
|
115
139
|
|
|
116
|
-
override convertDeployOptionsToRequestOptions(options:
|
|
140
|
+
override convertDeployOptionsToRequestOptions(options: DeployAccountOptionsWithoutWait): RequestDeployOptions {
|
|
117
141
|
return {
|
|
118
142
|
...options,
|
|
119
143
|
// Deployer is handled in the request method and forcibly set to undefined,
|
package/src/wallet/index.ts
CHANGED
package/src/wallet/wallet.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
2
|
-
import
|
|
2
|
+
import { BlockNumber, BlockNumberPositiveSchema } from '@aztec/foundation/branded-types';
|
|
3
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import {
|
|
5
|
+
type AbiDecoded,
|
|
4
6
|
AbiTypeSchema,
|
|
5
7
|
type ContractArtifact,
|
|
6
8
|
ContractArtifactSchema,
|
|
@@ -10,15 +12,10 @@ import {
|
|
|
10
12
|
} from '@aztec/stdlib/abi';
|
|
11
13
|
import { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
12
14
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
13
|
-
import {
|
|
14
|
-
type ContractClassMetadata,
|
|
15
|
-
ContractClassWithIdSchema,
|
|
16
|
-
type ContractInstanceWithAddress,
|
|
17
|
-
ContractInstanceWithAddressSchema,
|
|
18
|
-
type ContractMetadata,
|
|
19
|
-
} from '@aztec/stdlib/contract';
|
|
15
|
+
import { type ContractInstanceWithAddress, ContractInstanceWithAddressSchema } from '@aztec/stdlib/contract';
|
|
20
16
|
import { Gas } from '@aztec/stdlib/gas';
|
|
21
|
-
import { AbiDecodedSchema, type ApiSchemaFor,
|
|
17
|
+
import { AbiDecodedSchema, type ApiSchemaFor, optional, schemas, zodFor } from '@aztec/stdlib/schemas';
|
|
18
|
+
import type { ExecutionPayload, InTx } from '@aztec/stdlib/tx';
|
|
22
19
|
import {
|
|
23
20
|
Capsule,
|
|
24
21
|
HashedValues,
|
|
@@ -27,19 +24,23 @@ import {
|
|
|
27
24
|
TxReceipt,
|
|
28
25
|
TxSimulationResult,
|
|
29
26
|
UtilitySimulationResult,
|
|
27
|
+
inTxSchema,
|
|
30
28
|
} from '@aztec/stdlib/tx';
|
|
31
|
-
import type { ExecutionPayload } from '@aztec/stdlib/tx';
|
|
32
29
|
|
|
33
30
|
import { z } from 'zod';
|
|
34
31
|
|
|
35
|
-
import
|
|
36
|
-
FeeEstimationOptions,
|
|
37
|
-
GasSettingsOption,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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,
|
|
41
41
|
} from '../contract/interaction_options.js';
|
|
42
42
|
import type { CallIntent, IntentInnerHash } from '../utils/authwit.js';
|
|
43
|
+
import type { AppCapabilities, WalletCapabilities } from './capabilities.js';
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
46
|
* A wrapper type that allows any item to be associated with an alias.
|
|
@@ -57,7 +58,7 @@ export type Aliased<T> = {
|
|
|
57
58
|
|
|
58
59
|
/**
|
|
59
60
|
* Options for simulating interactions with the wallet. Overrides the fee settings of an interaction with
|
|
60
|
-
* a simplified version that only hints at the wallet
|
|
61
|
+
* a simplified version that only hints at the wallet whether the interaction contains a
|
|
61
62
|
* fee payment method or not
|
|
62
63
|
*/
|
|
63
64
|
export type SimulateOptions = Omit<SimulateInteractionOptions, 'fee'> & {
|
|
@@ -67,7 +68,7 @@ export type SimulateOptions = Omit<SimulateInteractionOptions, 'fee'> & {
|
|
|
67
68
|
|
|
68
69
|
/**
|
|
69
70
|
* Options for profiling interactions with the wallet. Overrides the fee settings of an interaction with
|
|
70
|
-
* a simplified version that only hints at the wallet
|
|
71
|
+
* a simplified version that only hints at the wallet whether the interaction contains a
|
|
71
72
|
* fee payment method or not
|
|
72
73
|
*/
|
|
73
74
|
export type ProfileOptions = Omit<ProfileInteractionOptions, 'fee'> & {
|
|
@@ -77,45 +78,54 @@ export type ProfileOptions = Omit<ProfileInteractionOptions, 'fee'> & {
|
|
|
77
78
|
|
|
78
79
|
/**
|
|
79
80
|
* Options for sending/proving interactions with the wallet. Overrides the fee settings of an interaction with
|
|
80
|
-
* a simplified version that only hints at the wallet
|
|
81
|
+
* a simplified version that only hints at the wallet whether the interaction contains a
|
|
81
82
|
* fee payment method or not
|
|
82
83
|
*/
|
|
83
|
-
export type SendOptions =
|
|
84
|
+
export type SendOptions<W extends InteractionWaitOptions = undefined> = Omit<
|
|
85
|
+
SendInteractionOptionsWithoutWait,
|
|
86
|
+
'fee'
|
|
87
|
+
> & {
|
|
84
88
|
/** The fee options */
|
|
85
89
|
fee?: GasSettingsOption;
|
|
90
|
+
/** Whether to wait for the transaction to be mined */
|
|
91
|
+
wait?: W;
|
|
86
92
|
};
|
|
87
93
|
|
|
88
94
|
/**
|
|
89
|
-
* 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).
|
|
90
96
|
*/
|
|
91
|
-
export type BatchableMethods =
|
|
92
|
-
Wallet,
|
|
93
|
-
'registerContract' | 'sendTx' | 'registerSender' | 'simulateUtility' | 'simulateTx'
|
|
94
|
-
>;
|
|
97
|
+
export type BatchableMethods = Omit<Wallet, 'batch'>;
|
|
95
98
|
|
|
96
99
|
/**
|
|
97
|
-
*
|
|
98
|
-
* This is what the wallet will accept as arguments to the `batch` method.
|
|
100
|
+
* A method call with its name and arguments.
|
|
99
101
|
*/
|
|
100
|
-
|
|
102
|
+
type BatchedMethodInternal<T extends keyof BatchableMethods> = {
|
|
101
103
|
/** The method name */
|
|
102
104
|
name: T;
|
|
103
105
|
/** The method arguments */
|
|
104
106
|
args: Parameters<BatchableMethods[T]>;
|
|
105
107
|
};
|
|
106
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
|
+
|
|
107
117
|
/**
|
|
108
118
|
* Helper type to extract the return type of a batched method
|
|
109
119
|
*/
|
|
110
120
|
export type BatchedMethodResult<T> =
|
|
111
|
-
T extends
|
|
121
|
+
T extends BatchedMethodInternal<infer K> ? Awaited<ReturnType<BatchableMethods[K]>> : never;
|
|
112
122
|
|
|
113
123
|
/**
|
|
114
124
|
* Wrapper type for batch results that includes the method name for discriminated union deserialization.
|
|
115
125
|
* Each result is wrapped as \{ name: 'methodName', result: ActualResult \} to allow proper deserialization
|
|
116
126
|
* when AztecAddress and TxHash would otherwise be ambiguous (both are hex strings).
|
|
117
127
|
*/
|
|
118
|
-
export type BatchedMethodResultWrapper<T extends BatchedMethod
|
|
128
|
+
export type BatchedMethodResultWrapper<T extends BatchedMethod> = {
|
|
119
129
|
/** The method name */
|
|
120
130
|
name: T['name'];
|
|
121
131
|
/** The method result */
|
|
@@ -125,25 +135,79 @@ export type BatchedMethodResultWrapper<T extends BatchedMethod<keyof BatchableMe
|
|
|
125
135
|
/**
|
|
126
136
|
* Maps a tuple of BatchedMethod to a tuple of their wrapped return types
|
|
127
137
|
*/
|
|
128
|
-
export type BatchResults<T extends readonly BatchedMethod
|
|
138
|
+
export type BatchResults<T extends readonly BatchedMethod[]> = {
|
|
129
139
|
[K in keyof T]: BatchedMethodResultWrapper<T[K]>;
|
|
130
140
|
};
|
|
131
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Filter options when querying private events.
|
|
144
|
+
*/
|
|
145
|
+
export type PrivateEventFilter = {
|
|
146
|
+
/** The address of the contract that emitted the events. */
|
|
147
|
+
contractAddress: AztecAddress;
|
|
148
|
+
/** Addresses of accounts that are in scope for this filter. */
|
|
149
|
+
scopes: AztecAddress[];
|
|
150
|
+
/** Transaction in which the events were emitted. */
|
|
151
|
+
txHash?: TxHash;
|
|
152
|
+
/** The block number from which to start fetching events (inclusive).
|
|
153
|
+
* Optional. If provided, it must be greater or equal than 1.
|
|
154
|
+
* Defaults to the initial L2 block number (INITIAL_L2_BLOCK_NUM).
|
|
155
|
+
* */
|
|
156
|
+
fromBlock?: BlockNumber;
|
|
157
|
+
/** The block number until which to fetch logs (not inclusive).
|
|
158
|
+
* Optional. If provided, it must be greater than fromBlock.
|
|
159
|
+
* Defaults to the latest known block to PXE + 1.
|
|
160
|
+
*/
|
|
161
|
+
toBlock?: BlockNumber;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* An ABI decoded private event with associated metadata.
|
|
166
|
+
*/
|
|
167
|
+
export type PrivateEvent<T> = {
|
|
168
|
+
/** The ABI decoded event */
|
|
169
|
+
event: T;
|
|
170
|
+
/** Metadata describing event context information such as tx and block */
|
|
171
|
+
metadata: InTx;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Contract metadata including deployment and registration status.
|
|
176
|
+
*/
|
|
177
|
+
export type ContractMetadata = {
|
|
178
|
+
/** The contract instance */
|
|
179
|
+
instance?: ContractInstanceWithAddress;
|
|
180
|
+
/** Whether the contract has been initialized (init nullifier exists) */
|
|
181
|
+
isContractInitialized: boolean;
|
|
182
|
+
/** Whether the contract instance is publicly deployed on-chain */
|
|
183
|
+
isContractPublished: boolean;
|
|
184
|
+
/** Whether the contract has been updated to a different class */
|
|
185
|
+
isContractUpdated: boolean;
|
|
186
|
+
/** The updated contract class ID if the contract has been updated */
|
|
187
|
+
updatedContractClassId?: Fr | undefined;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Contract class metadata.
|
|
192
|
+
*/
|
|
193
|
+
export type ContractClassMetadata = {
|
|
194
|
+
/** Whether the artifact is registered in the wallet */
|
|
195
|
+
isArtifactRegistered: boolean;
|
|
196
|
+
/** Whether the contract class is publicly registered on-chain */
|
|
197
|
+
isContractClassPubliclyRegistered: boolean;
|
|
198
|
+
};
|
|
199
|
+
|
|
132
200
|
/**
|
|
133
201
|
* The wallet interface.
|
|
134
202
|
*/
|
|
135
203
|
export type Wallet = {
|
|
136
|
-
getContractClassMetadata(id: Fr, includeArtifact?: boolean): Promise<ContractClassMetadata>;
|
|
137
|
-
getContractMetadata(address: AztecAddress): Promise<ContractMetadata>;
|
|
138
204
|
getPrivateEvents<T>(
|
|
139
|
-
contractAddress: AztecAddress,
|
|
140
205
|
eventMetadata: EventMetadataDefinition,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
recipients: AztecAddress[],
|
|
144
|
-
): Promise<T[]>;
|
|
206
|
+
eventFilter: PrivateEventFilter,
|
|
207
|
+
): Promise<PrivateEvent<T>[]>;
|
|
145
208
|
getChainInfo(): Promise<ChainInfo>;
|
|
146
|
-
|
|
209
|
+
getContractMetadata(address: AztecAddress): Promise<ContractMetadata>;
|
|
210
|
+
getContractClassMetadata(id: Fr): Promise<ContractClassMetadata>;
|
|
147
211
|
registerSender(address: AztecAddress, alias?: string): Promise<AztecAddress>;
|
|
148
212
|
getAddressBook(): Promise<Aliased<AztecAddress>[]>;
|
|
149
213
|
getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
@@ -155,9 +219,13 @@ export type Wallet = {
|
|
|
155
219
|
simulateTx(exec: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult>;
|
|
156
220
|
simulateUtility(call: FunctionCall, authwits?: AuthWitness[]): Promise<UtilitySimulationResult>;
|
|
157
221
|
profileTx(exec: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult>;
|
|
158
|
-
sendTx
|
|
159
|
-
|
|
160
|
-
|
|
222
|
+
sendTx<W extends InteractionWaitOptions = undefined>(
|
|
223
|
+
exec: ExecutionPayload,
|
|
224
|
+
opts: SendOptions<W>,
|
|
225
|
+
): Promise<SendReturn<W>>;
|
|
226
|
+
createAuthWit(from: AztecAddress, messageHashOrIntent: IntentInnerHash | CallIntent): Promise<AuthWitness>;
|
|
227
|
+
requestCapabilities(manifest: AppCapabilities): Promise<WalletCapabilities>;
|
|
228
|
+
batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>>;
|
|
161
229
|
};
|
|
162
230
|
|
|
163
231
|
export const FunctionCallSchema = z.object({
|
|
@@ -195,11 +263,19 @@ export const WalletSimulationFeeOptionSchema = GasSettingsOptionSchema.extend({
|
|
|
195
263
|
estimateGas: optional(z.boolean()),
|
|
196
264
|
});
|
|
197
265
|
|
|
266
|
+
export const WaitOptsSchema = z.object({
|
|
267
|
+
ignoreDroppedReceiptsFor: optional(z.number()),
|
|
268
|
+
timeout: optional(z.number()),
|
|
269
|
+
interval: optional(z.number()),
|
|
270
|
+
dontThrowOnRevert: optional(z.boolean()),
|
|
271
|
+
});
|
|
272
|
+
|
|
198
273
|
export const SendOptionsSchema = z.object({
|
|
199
274
|
from: schemas.AztecAddress,
|
|
200
275
|
authWitnesses: optional(z.array(AuthWitness.schema)),
|
|
201
276
|
capsules: optional(z.array(Capsule.schema)),
|
|
202
277
|
fee: optional(GasSettingsOptionSchema),
|
|
278
|
+
wait: optional(z.union([z.literal(NO_WAIT), WaitOptsSchema])),
|
|
203
279
|
});
|
|
204
280
|
|
|
205
281
|
export const SimulateOptionsSchema = z.object({
|
|
@@ -218,7 +294,6 @@ export const ProfileOptionsSchema = SimulateOptionsSchema.extend({
|
|
|
218
294
|
});
|
|
219
295
|
|
|
220
296
|
export const MessageHashOrIntentSchema = z.union([
|
|
221
|
-
schemas.Fr,
|
|
222
297
|
z.object({ consumer: schemas.AztecAddress, innerHash: schemas.Fr }),
|
|
223
298
|
z.object({
|
|
224
299
|
caller: schemas.AztecAddress,
|
|
@@ -226,59 +301,168 @@ export const MessageHashOrIntentSchema = z.union([
|
|
|
226
301
|
}),
|
|
227
302
|
]);
|
|
228
303
|
|
|
229
|
-
export const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
args: z.tuple([ContractInstanceWithAddressSchema, optional(ContractArtifactSchema), optional(schemas.Fr)]),
|
|
237
|
-
}),
|
|
238
|
-
z.object({
|
|
239
|
-
name: z.literal('sendTx'),
|
|
240
|
-
args: z.tuple([ExecutionPayloadSchema, SendOptionsSchema]),
|
|
241
|
-
}),
|
|
242
|
-
z.object({
|
|
243
|
-
name: z.literal('simulateUtility'),
|
|
244
|
-
args: z.tuple([FunctionCallSchema, optional(z.array(AuthWitness.schema))]),
|
|
245
|
-
}),
|
|
304
|
+
export const EventMetadataDefinitionSchema = z.object({
|
|
305
|
+
eventSelector: schemas.EventSelector,
|
|
306
|
+
abiType: AbiTypeSchema,
|
|
307
|
+
fieldNames: z.array(z.string()),
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
export const PrivateEventSchema: z.ZodType<any> = zodFor<PrivateEvent<AbiDecoded>>()(
|
|
246
311
|
z.object({
|
|
247
|
-
|
|
248
|
-
|
|
312
|
+
event: AbiDecodedSchema,
|
|
313
|
+
metadata: inTxSchema(),
|
|
249
314
|
}),
|
|
250
|
-
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
export const PrivateEventFilterSchema = z.object({
|
|
318
|
+
contractAddress: schemas.AztecAddress,
|
|
319
|
+
scopes: z.array(schemas.AztecAddress),
|
|
320
|
+
txHash: optional(TxHash.schema),
|
|
321
|
+
fromBlock: optional(BlockNumberPositiveSchema),
|
|
322
|
+
toBlock: optional(BlockNumberPositiveSchema),
|
|
323
|
+
});
|
|
251
324
|
|
|
252
325
|
export const ContractMetadataSchema = z.object({
|
|
253
|
-
|
|
326
|
+
instance: optional(ContractInstanceWithAddressSchema),
|
|
254
327
|
isContractInitialized: z.boolean(),
|
|
255
328
|
isContractPublished: z.boolean(),
|
|
256
|
-
|
|
329
|
+
isContractUpdated: z.boolean(),
|
|
330
|
+
updatedContractClassId: optional(schemas.Fr),
|
|
331
|
+
});
|
|
257
332
|
|
|
258
333
|
export const ContractClassMetadataSchema = z.object({
|
|
259
|
-
|
|
334
|
+
isArtifactRegistered: z.boolean(),
|
|
260
335
|
isContractClassPubliclyRegistered: z.boolean(),
|
|
261
|
-
|
|
262
|
-
}) satisfies ZodFor<ContractClassMetadata>;
|
|
336
|
+
});
|
|
263
337
|
|
|
264
|
-
export const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
fieldNames: z.array(z.string()),
|
|
338
|
+
export const ContractFunctionPatternSchema = z.object({
|
|
339
|
+
contract: z.union([schemas.AztecAddress, z.literal('*')]),
|
|
340
|
+
function: z.union([z.string(), z.literal('*')]),
|
|
268
341
|
});
|
|
269
342
|
|
|
270
|
-
export const
|
|
343
|
+
export const AccountsCapabilitySchema = z.object({
|
|
344
|
+
type: z.literal('accounts'),
|
|
345
|
+
canGet: optional(z.boolean()),
|
|
346
|
+
canCreateAuthWit: optional(z.boolean()),
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
export const GrantedAccountsCapabilitySchema = AccountsCapabilitySchema.extend({
|
|
350
|
+
accounts: z.array(z.object({ alias: z.string(), item: schemas.AztecAddress })),
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
export const ContractsCapabilitySchema = z.object({
|
|
354
|
+
type: z.literal('contracts'),
|
|
355
|
+
contracts: z.union([z.literal('*'), z.array(schemas.AztecAddress)]),
|
|
356
|
+
canRegister: optional(z.boolean()),
|
|
357
|
+
canGetMetadata: optional(z.boolean()),
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
export const GrantedContractsCapabilitySchema = ContractsCapabilitySchema;
|
|
361
|
+
|
|
362
|
+
export const ContractClassesCapabilitySchema = z.object({
|
|
363
|
+
type: z.literal('contractClasses'),
|
|
364
|
+
classes: z.union([z.literal('*'), z.array(schemas.Fr)]),
|
|
365
|
+
canGetMetadata: z.boolean(),
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
export const GrantedContractClassesCapabilitySchema = ContractClassesCapabilitySchema;
|
|
369
|
+
|
|
370
|
+
export const SimulationCapabilitySchema = z.object({
|
|
371
|
+
type: z.literal('simulation'),
|
|
372
|
+
transactions: optional(
|
|
373
|
+
z.object({
|
|
374
|
+
scope: z.union([z.literal('*'), z.array(ContractFunctionPatternSchema)]),
|
|
375
|
+
}),
|
|
376
|
+
),
|
|
377
|
+
utilities: optional(
|
|
378
|
+
z.object({
|
|
379
|
+
scope: z.union([z.literal('*'), z.array(ContractFunctionPatternSchema)]),
|
|
380
|
+
}),
|
|
381
|
+
),
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
export const GrantedSimulationCapabilitySchema = SimulationCapabilitySchema;
|
|
385
|
+
|
|
386
|
+
export const TransactionCapabilitySchema = z.object({
|
|
387
|
+
type: z.literal('transaction'),
|
|
388
|
+
scope: z.union([z.literal('*'), z.array(ContractFunctionPatternSchema)]),
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
export const GrantedTransactionCapabilitySchema = TransactionCapabilitySchema;
|
|
392
|
+
|
|
393
|
+
export const DataCapabilitySchema = z.object({
|
|
394
|
+
type: z.literal('data'),
|
|
395
|
+
addressBook: optional(z.boolean()),
|
|
396
|
+
privateEvents: optional(
|
|
397
|
+
z.object({
|
|
398
|
+
contracts: z.union([z.literal('*'), z.array(schemas.AztecAddress)]),
|
|
399
|
+
}),
|
|
400
|
+
),
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
export const GrantedDataCapabilitySchema = DataCapabilitySchema;
|
|
404
|
+
|
|
405
|
+
export const CapabilitySchema = z.discriminatedUnion('type', [
|
|
406
|
+
AccountsCapabilitySchema,
|
|
407
|
+
ContractsCapabilitySchema,
|
|
408
|
+
ContractClassesCapabilitySchema,
|
|
409
|
+
SimulationCapabilitySchema,
|
|
410
|
+
TransactionCapabilitySchema,
|
|
411
|
+
DataCapabilitySchema,
|
|
412
|
+
]);
|
|
413
|
+
|
|
414
|
+
export const GrantedCapabilitySchema = z.discriminatedUnion('type', [
|
|
415
|
+
GrantedAccountsCapabilitySchema,
|
|
416
|
+
GrantedContractsCapabilitySchema,
|
|
417
|
+
GrantedContractClassesCapabilitySchema,
|
|
418
|
+
GrantedSimulationCapabilitySchema,
|
|
419
|
+
GrantedTransactionCapabilitySchema,
|
|
420
|
+
GrantedDataCapabilitySchema,
|
|
421
|
+
]);
|
|
422
|
+
|
|
423
|
+
export const AppCapabilitiesSchema = z.object({
|
|
424
|
+
version: z.literal('1.0'),
|
|
425
|
+
metadata: z.object({
|
|
426
|
+
name: z.string(),
|
|
427
|
+
version: z.string(),
|
|
428
|
+
description: optional(z.string()),
|
|
429
|
+
url: optional(z.string()),
|
|
430
|
+
icon: optional(z.string()),
|
|
431
|
+
}),
|
|
432
|
+
capabilities: z.array(CapabilitySchema),
|
|
433
|
+
behavior: optional(
|
|
434
|
+
z.object({
|
|
435
|
+
mode: optional(z.enum(['strict', 'permissive'])),
|
|
436
|
+
expiration: optional(z.number()),
|
|
437
|
+
}),
|
|
438
|
+
),
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
export const WalletCapabilitiesSchema = z.object({
|
|
442
|
+
version: z.literal('1.0'),
|
|
443
|
+
granted: z.array(GrantedCapabilitySchema),
|
|
444
|
+
wallet: z.object({
|
|
445
|
+
name: z.string(),
|
|
446
|
+
version: z.string(),
|
|
447
|
+
}),
|
|
448
|
+
expiresAt: optional(z.number()),
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Record of all wallet method schemas (excluding batch).
|
|
453
|
+
* This is the single source of truth for method schemas - batch schemas are derived from this.
|
|
454
|
+
*/
|
|
455
|
+
const WalletMethodSchemas = {
|
|
271
456
|
getChainInfo: z
|
|
272
457
|
.function()
|
|
273
458
|
.args()
|
|
274
459
|
.returns(z.object({ chainId: schemas.Fr, version: schemas.Fr })),
|
|
275
|
-
getContractClassMetadata: z.function().args(schemas.Fr, optional(z.boolean())).returns(ContractClassMetadataSchema),
|
|
276
460
|
getContractMetadata: z.function().args(schemas.AztecAddress).returns(ContractMetadataSchema),
|
|
277
|
-
|
|
461
|
+
getContractClassMetadata: z.function().args(schemas.Fr).returns(ContractClassMetadataSchema),
|
|
278
462
|
getPrivateEvents: z
|
|
279
463
|
.function()
|
|
280
|
-
.args(
|
|
281
|
-
.returns(z.array(
|
|
464
|
+
.args(EventMetadataDefinitionSchema, PrivateEventFilterSchema)
|
|
465
|
+
.returns(z.array(PrivateEventSchema)),
|
|
282
466
|
registerSender: z.function().args(schemas.AztecAddress, optional(z.string())).returns(schemas.AztecAddress),
|
|
283
467
|
getAddressBook: z
|
|
284
468
|
.function()
|
|
@@ -298,21 +482,52 @@ export const WalletSchema: ApiSchemaFor<Wallet> = {
|
|
|
298
482
|
.args(FunctionCallSchema, optional(z.array(AuthWitness.schema)))
|
|
299
483
|
.returns(UtilitySimulationResult.schema),
|
|
300
484
|
profileTx: z.function().args(ExecutionPayloadSchema, ProfileOptionsSchema).returns(TxProfileResult.schema),
|
|
301
|
-
sendTx: z
|
|
485
|
+
sendTx: z
|
|
486
|
+
.function()
|
|
487
|
+
.args(ExecutionPayloadSchema, SendOptionsSchema)
|
|
488
|
+
.returns(z.union([TxHash.schema, TxReceipt.schema])),
|
|
302
489
|
createAuthWit: z.function().args(schemas.AztecAddress, MessageHashOrIntentSchema).returns(AuthWitness.schema),
|
|
490
|
+
requestCapabilities: z.function().args(AppCapabilitiesSchema).returns(WalletCapabilitiesSchema),
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Creates batch schemas from the individual wallet methods.
|
|
495
|
+
* This allows us to define them once and derive batch schemas automatically,
|
|
496
|
+
* reducing duplication and ensuring consistency.
|
|
497
|
+
*/
|
|
498
|
+
function createBatchSchemas<T extends Record<string, z.ZodFunction<z.ZodTuple<any, any>, z.ZodTypeAny>>>(
|
|
499
|
+
methodSchemas: T,
|
|
500
|
+
) {
|
|
501
|
+
const names = Object.keys(methodSchemas) as (keyof T)[];
|
|
502
|
+
|
|
503
|
+
const namesAndArgs = names.map(name =>
|
|
504
|
+
z.object({
|
|
505
|
+
name: z.literal(name),
|
|
506
|
+
args: methodSchemas[name].parameters(),
|
|
507
|
+
}),
|
|
508
|
+
);
|
|
509
|
+
|
|
510
|
+
const namesAndReturns = names.map(name =>
|
|
511
|
+
z.object({
|
|
512
|
+
name: z.literal(name),
|
|
513
|
+
result: methodSchemas[name].returnType(),
|
|
514
|
+
}),
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
// Type assertion needed because discriminatedUnion expects a tuple type [T, T, ...T[]]
|
|
518
|
+
// but we're building the array dynamically. The runtime behavior is correct.
|
|
519
|
+
return {
|
|
520
|
+
input: z.discriminatedUnion('name', namesAndArgs as [(typeof namesAndArgs)[0], ...typeof namesAndArgs]),
|
|
521
|
+
output: z.discriminatedUnion('name', namesAndReturns as [(typeof namesAndReturns)[0], ...typeof namesAndReturns]),
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
const { input: BatchedMethodSchema, output: BatchedResultSchema } = createBatchSchemas(WalletMethodSchemas);
|
|
526
|
+
|
|
527
|
+
export { BatchedMethodSchema, BatchedResultSchema };
|
|
528
|
+
|
|
529
|
+
export const WalletSchema: ApiSchemaFor<Wallet> = {
|
|
530
|
+
...WalletMethodSchemas,
|
|
303
531
|
// @ts-expect-error - ApiSchemaFor cannot properly type generic methods with readonly arrays
|
|
304
|
-
batch: z
|
|
305
|
-
.function()
|
|
306
|
-
.args(z.array(BatchedMethodSchema))
|
|
307
|
-
.returns(
|
|
308
|
-
z.array(
|
|
309
|
-
z.discriminatedUnion('name', [
|
|
310
|
-
z.object({ name: z.literal('registerSender'), result: schemas.AztecAddress }),
|
|
311
|
-
z.object({ name: z.literal('registerContract'), result: ContractInstanceWithAddressSchema }),
|
|
312
|
-
z.object({ name: z.literal('sendTx'), result: TxHash.schema }),
|
|
313
|
-
z.object({ name: z.literal('simulateUtility'), result: UtilitySimulationResult.schema }),
|
|
314
|
-
z.object({ name: z.literal('simulateTx'), result: TxSimulationResult.schema }),
|
|
315
|
-
]),
|
|
316
|
-
),
|
|
317
|
-
),
|
|
532
|
+
batch: z.function().args(z.array(BatchedMethodSchema)).returns(z.array(BatchedResultSchema)),
|
|
318
533
|
};
|