@aztec/aztec.js 3.0.3 → 4.0.0-devnet.1-patch.0
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/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 +10 -6
- package/dest/api/events.d.ts.map +1 -1
- package/dest/api/events.js +30 -20
- 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 +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 +3 -12
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +6 -6
- package/dest/contract/deploy_method.d.ts +63 -16
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +41 -23
- 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 +15 -0
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/contract-class-registry.js +127 -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 +585 -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 +593 -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.js +10 -10
- package/dest/fee/public_fee_payment_method.js +10 -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/authwit.d.ts +8 -6
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +5 -9
- 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 +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 +34 -6
- package/dest/wallet/deploy_account_method.d.ts.map +1 -1
- package/dest/wallet/deploy_account_method.js +7 -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 +1642 -1007
- package/dest/wallet/wallet.d.ts.map +1 -1
- package/dest/wallet/wallet.js +201 -107
- package/package.json +24 -13
- 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/account.ts +9 -3
- package/src/api/authorization.ts +1 -0
- package/src/api/contract.ts +24 -9
- package/src/api/deployment.ts +0 -1
- package/src/api/events.ts +35 -27
- 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 +47 -3
- package/src/contract/base_contract_interaction.ts +27 -15
- package/src/contract/batch_call.ts +4 -2
- package/src/contract/contract_function_interaction.ts +13 -6
- package/src/contract/deploy_method.ts +122 -29
- 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 +96 -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/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 +7 -7
- package/src/fee/public_fee_payment_method.ts +8 -8
- package/src/fee/sponsored_fee_payment.ts +3 -3
- package/src/scripts/generate_protocol_contract_types.ts +150 -0
- package/src/utils/authwit.ts +19 -7
- 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 +491 -0
- package/src/wallet/deploy_account_method.ts +37 -13
- package/src/wallet/index.ts +1 -0
- package/src/wallet/wallet.ts +319 -118
- 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
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
2
|
-
import { EncodedAppEntrypointCalls } from '@aztec/entrypoints/encoding';
|
|
3
2
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
4
|
-
import {
|
|
5
|
-
type ContractArtifact,
|
|
6
|
-
type FunctionArtifact,
|
|
7
|
-
FunctionCall,
|
|
8
|
-
FunctionSelector,
|
|
9
|
-
encodeArguments,
|
|
10
|
-
getFunctionArtifactByName,
|
|
11
|
-
} from '@aztec/stdlib/abi';
|
|
12
3
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
13
4
|
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
14
5
|
import { ExecutionPayload } from '@aztec/stdlib/tx';
|
|
15
6
|
|
|
7
|
+
import type { Account } from '../account/account.js';
|
|
16
8
|
import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
|
|
17
|
-
import type { Wallet } from './index.js';
|
|
18
9
|
|
|
19
10
|
/**
|
|
20
11
|
* Fee payment method that allows an account contract to pay for its own deployment
|
|
@@ -33,11 +24,9 @@ import type { Wallet } from './index.js';
|
|
|
33
24
|
*/
|
|
34
25
|
export class AccountEntrypointMetaPaymentMethod implements FeePaymentMethod {
|
|
35
26
|
constructor(
|
|
36
|
-
private
|
|
37
|
-
private artifact: ContractArtifact,
|
|
38
|
-
private feePaymentNameOrArtifact: string | FunctionArtifact,
|
|
39
|
-
private accountAddress: AztecAddress,
|
|
27
|
+
private account: Account,
|
|
40
28
|
private paymentMethod?: FeePaymentMethod,
|
|
29
|
+
private feeEntrypointOptions?: any,
|
|
41
30
|
) {}
|
|
42
31
|
|
|
43
32
|
getAsset(): Promise<AztecAddress> {
|
|
@@ -45,59 +34,38 @@ export class AccountEntrypointMetaPaymentMethod implements FeePaymentMethod {
|
|
|
45
34
|
}
|
|
46
35
|
|
|
47
36
|
async getExecutionPayload(): Promise<ExecutionPayload> {
|
|
48
|
-
// Get the execution payload for the fee
|
|
49
|
-
|
|
50
|
-
// FeeJuice balance
|
|
51
|
-
const { calls: feeCalls, authWitnesses: feeAuthwitnesses } =
|
|
52
|
-
(await this.paymentMethod?.getExecutionPayload()) ?? ExecutionPayload.empty();
|
|
53
|
-
// Encode the calls for the fee
|
|
54
|
-
const feePayer = (await this.paymentMethod?.getFeePayer()) ?? this.accountAddress;
|
|
55
|
-
const isFeePayer = feePayer.equals(this.accountAddress);
|
|
56
|
-
let accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.EXTERNAL;
|
|
57
|
-
if (isFeePayer) {
|
|
58
|
-
// If the account is the fee payer, and the incoming fee payload has calls
|
|
59
|
-
// it can only be FeeJuicePaymentMethodWithClaim
|
|
60
|
-
// If the payload has no calls, it's paying using
|
|
61
|
-
// its own fee juice balance
|
|
62
|
-
accountFeePaymentMethodOptions =
|
|
63
|
-
feeCalls.length === 0
|
|
64
|
-
? AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE
|
|
65
|
-
: AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM;
|
|
66
|
-
}
|
|
67
|
-
const feeEncodedCalls = await EncodedAppEntrypointCalls.create(feeCalls);
|
|
37
|
+
// Get the execution payload for the fee
|
|
38
|
+
const innerPayload = (await this.paymentMethod?.getExecutionPayload()) ?? ExecutionPayload.empty();
|
|
68
39
|
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
40
|
+
// If no fee entrypoint options were provided, compute them based on the wrapped payment method
|
|
41
|
+
// This mimics how the actual account contract works when invoked directly:
|
|
42
|
+
// - If we are the fee payer, are there calls in the inner payload? In that case, those calls can
|
|
43
|
+
// only be claiming fee juice, so we use FEE_JUICE_WITH_CLAIM
|
|
44
|
+
// - If we are the fee payer, but there are no calls, then we assume the account already has
|
|
45
|
+
// fee juice and can pay directly with PREEXISTING_FEE_JUICE
|
|
46
|
+
// - If we are not the fee payer, then EXTERNAL is used
|
|
47
|
+
let options = this.feeEntrypointOptions;
|
|
48
|
+
if (!options) {
|
|
49
|
+
const feePayer = (await this.paymentMethod?.getFeePayer()) ?? this.account.getAddress();
|
|
50
|
+
const isFeePayer = feePayer.equals(this.account.getAddress());
|
|
75
51
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
encodeArguments(feePaymentArtifact, args),
|
|
84
|
-
feePaymentArtifact.returnTypes,
|
|
85
|
-
);
|
|
52
|
+
let accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.EXTERNAL;
|
|
53
|
+
if (isFeePayer) {
|
|
54
|
+
accountFeePaymentMethodOptions =
|
|
55
|
+
innerPayload.calls.length === 0
|
|
56
|
+
? AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE
|
|
57
|
+
: AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM;
|
|
58
|
+
}
|
|
86
59
|
|
|
87
|
-
|
|
88
|
-
|
|
60
|
+
options = { feePaymentMethodOptions: accountFeePaymentMethodOptions };
|
|
61
|
+
}
|
|
89
62
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
[payloadAuthWitness, ...feeAuthwitnesses],
|
|
93
|
-
[],
|
|
94
|
-
feeEncodedCalls.hashedArguments,
|
|
95
|
-
feePayer,
|
|
96
|
-
);
|
|
63
|
+
// Use the generic wrapping mechanism from the account interface
|
|
64
|
+
return this.account.wrapExecutionPayload(innerPayload, options);
|
|
97
65
|
}
|
|
98
66
|
|
|
99
67
|
getFeePayer(): Promise<AztecAddress> {
|
|
100
|
-
return this.paymentMethod?.getFeePayer() ?? Promise.resolve(this.
|
|
68
|
+
return this.paymentMethod?.getFeePayer() ?? Promise.resolve(this.account.getAddress());
|
|
101
69
|
}
|
|
102
70
|
|
|
103
71
|
getGasSettings(): GasSettings | undefined {
|
|
@@ -9,7 +9,6 @@ import { deriveKeys } from '@aztec/stdlib/keys';
|
|
|
9
9
|
import type { AccountContract } from '../account/account_contract.js';
|
|
10
10
|
import { AccountWithSecretKey } from '../account/account_with_secret_key.js';
|
|
11
11
|
import type { Salt } from '../account/index.js';
|
|
12
|
-
import type { AccountInterface } from '../account/interface.js';
|
|
13
12
|
import { Contract } from '../contract/contract.js';
|
|
14
13
|
import { DeployAccountMethod } from './deploy_account_method.js';
|
|
15
14
|
import type { Wallet } from './wallet.js';
|
|
@@ -58,16 +57,6 @@ export class AccountManager {
|
|
|
58
57
|
return this.getPublicKeys().hash();
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
/**
|
|
62
|
-
* Returns the entrypoint for this account as defined by its account contract.
|
|
63
|
-
* @returns An entrypoint.
|
|
64
|
-
*/
|
|
65
|
-
public async getAccountInterface(): Promise<AccountInterface> {
|
|
66
|
-
const chainInfo = await this.wallet.getChainInfo();
|
|
67
|
-
const completeAddress = await this.getCompleteAddress();
|
|
68
|
-
return this.accountContract.getInterface(completeAddress, chainInfo);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
60
|
/**
|
|
72
61
|
* Gets the calculated complete address associated with this account.
|
|
73
62
|
* Does not require the account to have been published for public execution.
|
|
@@ -103,8 +92,9 @@ export class AccountManager {
|
|
|
103
92
|
* @returns A Wallet instance.
|
|
104
93
|
*/
|
|
105
94
|
public async getAccount(): Promise<AccountWithSecretKey> {
|
|
106
|
-
const
|
|
107
|
-
|
|
95
|
+
const completeAddress = await this.getCompleteAddress();
|
|
96
|
+
const account = this.accountContract.getAccount(completeAddress);
|
|
97
|
+
return new AccountWithSecretKey(account, this.secretKey, this.salt);
|
|
108
98
|
}
|
|
109
99
|
|
|
110
100
|
/**
|
|
@@ -134,12 +124,14 @@ export class AccountManager {
|
|
|
134
124
|
constructorArgs: undefined,
|
|
135
125
|
};
|
|
136
126
|
|
|
127
|
+
const account = await this.getAccount();
|
|
137
128
|
return new DeployAccountMethod(
|
|
138
129
|
this.getPublicKeys(),
|
|
139
130
|
this.wallet,
|
|
140
131
|
artifact,
|
|
141
132
|
instance => Contract.at(instance.address, artifact, this.wallet),
|
|
142
133
|
new Fr(this.salt),
|
|
134
|
+
account,
|
|
143
135
|
constructorArgs,
|
|
144
136
|
constructorName,
|
|
145
137
|
);
|
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
+
|
|
4
|
+
import type { Aliased } from './wallet.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Current capability manifest version.
|
|
8
|
+
*/
|
|
9
|
+
export const CAPABILITY_VERSION = '1.0' as const;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Pattern for matching contract functions with wildcards.
|
|
13
|
+
*
|
|
14
|
+
* Used in simulation and transaction capabilities to specify which
|
|
15
|
+
* contract functions are allowed.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Allow any function on a specific contract
|
|
19
|
+
* \{ contract: ammAddress, function: '*' \}
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Allow only 'swap' function on a specific contract
|
|
23
|
+
* \{ contract: ammAddress, function: 'swap' \}
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Allow 'transfer' on any contract
|
|
27
|
+
* \{ contract: '*', function: 'transfer' \}
|
|
28
|
+
*/
|
|
29
|
+
export interface ContractFunctionPattern {
|
|
30
|
+
/** Contract address or '*' for any contract */
|
|
31
|
+
contract: AztecAddress | '*';
|
|
32
|
+
|
|
33
|
+
/** Function name or '*' for any function */
|
|
34
|
+
function: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Account access capability - grants access to user accounts.
|
|
39
|
+
*
|
|
40
|
+
* Maps to wallet methods:
|
|
41
|
+
* - getAccounts (when canGet: true)
|
|
42
|
+
* - createAuthWit (when canCreateAuthWit: true)
|
|
43
|
+
*
|
|
44
|
+
* The wallet decides which accounts to reveal to the app.
|
|
45
|
+
* Apps don't specify which accounts they want - they just request
|
|
46
|
+
* the capability and the wallet shows them the available accounts.
|
|
47
|
+
*/
|
|
48
|
+
export interface AccountsCapability {
|
|
49
|
+
/** Discriminator for capability type */
|
|
50
|
+
type: 'accounts';
|
|
51
|
+
|
|
52
|
+
/** Can get accounts from wallet. Maps to: getAccounts */
|
|
53
|
+
canGet?: boolean;
|
|
54
|
+
|
|
55
|
+
/** Can create auth witnesses for accounts. Maps to: createAuthWit */
|
|
56
|
+
canCreateAuthWit?: boolean;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Granted account access capability.
|
|
61
|
+
*
|
|
62
|
+
* Extends the request with specific accounts that were granted by the wallet.
|
|
63
|
+
*/
|
|
64
|
+
export interface GrantedAccountsCapability extends AccountsCapability {
|
|
65
|
+
/** Specific accounts granted by the wallet with their aliases. The wallet adds this when granting the capability. */
|
|
66
|
+
accounts: Aliased<AztecAddress>[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Contract interaction capability - for registering and querying contracts.
|
|
71
|
+
*
|
|
72
|
+
* Maps to wallet methods:
|
|
73
|
+
* - registerContract (when canRegister: true)
|
|
74
|
+
* - getContractMetadata (when canGetMetadata: true)
|
|
75
|
+
*
|
|
76
|
+
* Matching is done by contract address, not class ID. This allows updating
|
|
77
|
+
* existing contracts with new artifacts (e.g., when contract is upgraded
|
|
78
|
+
* to a new contractClassId on-chain).
|
|
79
|
+
*
|
|
80
|
+
* Note: For querying contract class metadata, use ContractClassesCapability instead.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* // Register and query specific contracts
|
|
84
|
+
* \{
|
|
85
|
+
* type: 'contracts',
|
|
86
|
+
* contracts: [ammAddress, tokenAddress],
|
|
87
|
+
* canRegister: true,
|
|
88
|
+
* canGetMetadata: true
|
|
89
|
+
* \}
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* // Query any contract (read-only)
|
|
93
|
+
* \{
|
|
94
|
+
* type: 'contracts',
|
|
95
|
+
* contracts: '*',
|
|
96
|
+
* canGetMetadata: true
|
|
97
|
+
* \}
|
|
98
|
+
*/
|
|
99
|
+
export interface ContractsCapability {
|
|
100
|
+
/** Discriminator for capability type */
|
|
101
|
+
type: 'contracts';
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Which contracts this applies to:
|
|
105
|
+
* - '*': Any contract address
|
|
106
|
+
* - AztecAddress[]: Specific contract addresses
|
|
107
|
+
*/
|
|
108
|
+
contracts: '*' | AztecAddress[];
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Can register contracts and update existing registrations.
|
|
112
|
+
* Maps to: registerContract
|
|
113
|
+
*
|
|
114
|
+
* When true, allows:
|
|
115
|
+
* - Registering new contract instances at specified addresses
|
|
116
|
+
* - Re-registering existing contracts with updated artifacts (e.g., after upgrade)
|
|
117
|
+
*/
|
|
118
|
+
canRegister?: boolean;
|
|
119
|
+
|
|
120
|
+
/** Can query contract metadata. Maps to: getContractMetadata */
|
|
121
|
+
canGetMetadata?: boolean;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Granted contract interaction capability.
|
|
126
|
+
*
|
|
127
|
+
* The wallet may reduce the scope (e.g., from '*' to specific addresses).
|
|
128
|
+
*/
|
|
129
|
+
export interface GrantedContractsCapability extends ContractsCapability {}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Contract class capability - for querying contract class metadata.
|
|
133
|
+
*
|
|
134
|
+
* Maps to wallet methods:
|
|
135
|
+
* - getContractClassMetadata
|
|
136
|
+
*
|
|
137
|
+
* Contract classes are identified by their class ID (Fr), not by contract address.
|
|
138
|
+
* Multiple contract instances can share the same class. This capability grants
|
|
139
|
+
* permission to query metadata for specific contract classes.
|
|
140
|
+
*
|
|
141
|
+
* Apps typically acquire this permission automatically when registering a contract
|
|
142
|
+
* with an artifact (the wallet auto-grants permission for that contract's class ID).
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* // Query specific contract classes
|
|
146
|
+
* \{
|
|
147
|
+
* type: 'contractClasses',
|
|
148
|
+
* classes: [classId1, classId2],
|
|
149
|
+
* canGetMetadata: true
|
|
150
|
+
* \}
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* // Query any contract class (wildcard)
|
|
154
|
+
* \{
|
|
155
|
+
* type: 'contractClasses',
|
|
156
|
+
* classes: '*',
|
|
157
|
+
* canGetMetadata: true
|
|
158
|
+
* \}
|
|
159
|
+
*/
|
|
160
|
+
export interface ContractClassesCapability {
|
|
161
|
+
/** Discriminator for capability type */
|
|
162
|
+
type: 'contractClasses';
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Which contract classes this applies to:
|
|
166
|
+
* - '*': Any contract class ID
|
|
167
|
+
* - Fr[]: Specific contract class IDs
|
|
168
|
+
*/
|
|
169
|
+
classes: '*' | Fr[];
|
|
170
|
+
|
|
171
|
+
/** Can query contract class metadata. Maps to: getContractClassMetadata */
|
|
172
|
+
canGetMetadata: boolean;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Granted contract class capability.
|
|
177
|
+
*
|
|
178
|
+
* The wallet may reduce the scope (e.g., from '*' to specific class IDs).
|
|
179
|
+
*/
|
|
180
|
+
export interface GrantedContractClassesCapability extends ContractClassesCapability {}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Transaction simulation capability - for simulating transactions and utilities.
|
|
184
|
+
*
|
|
185
|
+
* Maps to wallet methods:
|
|
186
|
+
* - simulateTx (when transactions scope specified)
|
|
187
|
+
* - simulateUtility (when utilities scope specified)
|
|
188
|
+
* - profileTx (when transactions scope specified)
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* // Simulate any transaction on specific contracts
|
|
192
|
+
* \{
|
|
193
|
+
* type: 'simulation',
|
|
194
|
+
* transactions: \{
|
|
195
|
+
* scope: [
|
|
196
|
+
* \{ contract: ammAddress, function: '*' \},
|
|
197
|
+
* \{ contract: tokenAddress, function: 'transfer' \}
|
|
198
|
+
* ]
|
|
199
|
+
* \}
|
|
200
|
+
* \}
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* // Simulate any transaction and utility call
|
|
204
|
+
* \{
|
|
205
|
+
* type: 'simulation',
|
|
206
|
+
* transactions: \{ scope: '*' \},
|
|
207
|
+
* utilities: \{ scope: '*' \}
|
|
208
|
+
* \}
|
|
209
|
+
*/
|
|
210
|
+
export interface SimulationCapability {
|
|
211
|
+
/** Discriminator for capability type */
|
|
212
|
+
type: 'simulation';
|
|
213
|
+
|
|
214
|
+
/** Transaction simulation scope. Maps to: simulateTx, profileTx */
|
|
215
|
+
transactions?: {
|
|
216
|
+
/**
|
|
217
|
+
* Which contracts/functions to allow:
|
|
218
|
+
* - '*': Any transaction
|
|
219
|
+
* - ContractFunctionPattern[]: Specific contract functions
|
|
220
|
+
*/
|
|
221
|
+
scope: '*' | ContractFunctionPattern[];
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/** Utility simulation scope (unconstrained calls). Maps to: simulateUtility */
|
|
225
|
+
utilities?: {
|
|
226
|
+
/**
|
|
227
|
+
* Which contracts/functions to allow:
|
|
228
|
+
* - '*': Any utility call
|
|
229
|
+
* - ContractFunctionPattern[]: Specific contract functions
|
|
230
|
+
*/
|
|
231
|
+
scope: '*' | ContractFunctionPattern[];
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Granted transaction simulation capability.
|
|
237
|
+
*
|
|
238
|
+
* The wallet may reduce the scope (e.g., from '*' to specific patterns).
|
|
239
|
+
*/
|
|
240
|
+
export interface GrantedSimulationCapability extends SimulationCapability {}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Transaction execution capability - for sending transactions.
|
|
244
|
+
*
|
|
245
|
+
* Maps to wallet methods:
|
|
246
|
+
* - sendTx
|
|
247
|
+
*
|
|
248
|
+
* Policy enforcement (rate limits, spending limits) should be handled
|
|
249
|
+
* at the contract level in Aztec, not at the wallet level.
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* // Send specific transactions with approval
|
|
253
|
+
* \{
|
|
254
|
+
* type: 'transaction',
|
|
255
|
+
* scope: [
|
|
256
|
+
* \{ contract: ammAddress, function: 'swap' \},
|
|
257
|
+
* \{ contract: ammAddress, function: 'addLiquidity' \}
|
|
258
|
+
* ]
|
|
259
|
+
* \}
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* // Send any transaction
|
|
263
|
+
* \{
|
|
264
|
+
* type: 'transaction',
|
|
265
|
+
* scope: '*'
|
|
266
|
+
* \}
|
|
267
|
+
*/
|
|
268
|
+
export interface TransactionCapability {
|
|
269
|
+
/** Discriminator for capability type */
|
|
270
|
+
type: 'transaction';
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Which contracts/functions to allow:
|
|
274
|
+
* - '*': Any transaction
|
|
275
|
+
* - ContractFunctionPattern[]: Specific patterns
|
|
276
|
+
*/
|
|
277
|
+
scope: '*' | ContractFunctionPattern[];
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Granted transaction execution capability.
|
|
282
|
+
*
|
|
283
|
+
* The wallet may reduce the scope (e.g., from '*' to specific patterns).
|
|
284
|
+
*/
|
|
285
|
+
export interface GrantedTransactionCapability extends TransactionCapability {}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Data access capability - for querying private data.
|
|
289
|
+
*
|
|
290
|
+
* Maps to wallet methods:
|
|
291
|
+
* - getAddressBook (when addressBook: true)
|
|
292
|
+
* - getPrivateEvents (when privateEvents specified)
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* // Access address book and events from specific contract
|
|
296
|
+
* \{
|
|
297
|
+
* type: 'data',
|
|
298
|
+
* addressBook: true,
|
|
299
|
+
* privateEvents: \{
|
|
300
|
+
* contracts: [ammAddress],
|
|
301
|
+
* events: ['Swap', 'LiquidityAdded']
|
|
302
|
+
* \}
|
|
303
|
+
* \}
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* // Access all events from any contract
|
|
307
|
+
* \{
|
|
308
|
+
* type: 'data',
|
|
309
|
+
* privateEvents: \{
|
|
310
|
+
* contracts: '*',
|
|
311
|
+
* events: '*'
|
|
312
|
+
* \}
|
|
313
|
+
* \}
|
|
314
|
+
*/
|
|
315
|
+
export interface DataCapability {
|
|
316
|
+
/** Discriminator for capability type */
|
|
317
|
+
type: 'data';
|
|
318
|
+
|
|
319
|
+
/** Access to address book. Maps to: getAddressBook */
|
|
320
|
+
addressBook?: boolean;
|
|
321
|
+
|
|
322
|
+
/** Access to private events. Maps to: getPrivateEvents */
|
|
323
|
+
privateEvents?: {
|
|
324
|
+
/**
|
|
325
|
+
* Which contracts to allow event queries from:
|
|
326
|
+
* - '*': Any contract
|
|
327
|
+
* - AztecAddress[]: Specific contracts
|
|
328
|
+
*/
|
|
329
|
+
contracts: '*' | AztecAddress[];
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Granted data access capability.
|
|
335
|
+
*
|
|
336
|
+
* The wallet may reduce the scope (e.g., from '*' to specific contracts).
|
|
337
|
+
*/
|
|
338
|
+
export interface GrantedDataCapability extends DataCapability {}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Union type of all capability scopes (app request).
|
|
342
|
+
*
|
|
343
|
+
* Capabilities group wallet operations by their security sensitivity
|
|
344
|
+
* and functional cohesion, making permission requests understandable
|
|
345
|
+
* to users.
|
|
346
|
+
*/
|
|
347
|
+
export type Capability =
|
|
348
|
+
| AccountsCapability
|
|
349
|
+
| ContractsCapability
|
|
350
|
+
| ContractClassesCapability
|
|
351
|
+
| SimulationCapability
|
|
352
|
+
| TransactionCapability
|
|
353
|
+
| DataCapability;
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Union type of all granted capabilities (wallet response).
|
|
357
|
+
*
|
|
358
|
+
* The wallet may augment capabilities with additional information:
|
|
359
|
+
* - AccountsCapability: adds specific accounts granted
|
|
360
|
+
* - Other capabilities: may reduce scope (e.g., '*' to specific addresses)
|
|
361
|
+
*/
|
|
362
|
+
export type GrantedCapability =
|
|
363
|
+
| GrantedAccountsCapability
|
|
364
|
+
| GrantedContractsCapability
|
|
365
|
+
| GrantedContractClassesCapability
|
|
366
|
+
| GrantedSimulationCapability
|
|
367
|
+
| GrantedTransactionCapability
|
|
368
|
+
| GrantedDataCapability;
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Application capability manifest.
|
|
372
|
+
*
|
|
373
|
+
* Sent by dApp to declare all operations it needs. This reduces authorization
|
|
374
|
+
* friction from multiple dialogs to a single comprehensive permission request.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* // DEX application manifest
|
|
378
|
+
* const manifest: AppCapabilities = \{
|
|
379
|
+
* version: CAPABILITY_VERSION,
|
|
380
|
+
* metadata: \{
|
|
381
|
+
* name: 'MyDEX',
|
|
382
|
+
* version: '1.0.0',
|
|
383
|
+
* description: 'Decentralized exchange for private token swaps',
|
|
384
|
+
* url: 'https://example.com',
|
|
385
|
+
* icon: 'https://example.com/icon.png'
|
|
386
|
+
* \},
|
|
387
|
+
* capabilities: [
|
|
388
|
+
* \{
|
|
389
|
+
* type: 'accounts',
|
|
390
|
+
* canGet: true,
|
|
391
|
+
* canCreateAuthWit: true
|
|
392
|
+
* \},
|
|
393
|
+
* \{
|
|
394
|
+
* type: 'contracts',
|
|
395
|
+
* contracts: [ammAddress, tokenAAddress, tokenBAddress],
|
|
396
|
+
* canRegister: true,
|
|
397
|
+
* canGetMetadata: true
|
|
398
|
+
* \},
|
|
399
|
+
* \{
|
|
400
|
+
* type: 'simulation',
|
|
401
|
+
* transactions: \{
|
|
402
|
+
* scope: [\{ contract: ammAddress, function: '*' \}]
|
|
403
|
+
* \}
|
|
404
|
+
* \},
|
|
405
|
+
* \{
|
|
406
|
+
* type: 'transaction',
|
|
407
|
+
* scope: [\{ contract: ammAddress, function: 'swap' \}]
|
|
408
|
+
* \}
|
|
409
|
+
* ]
|
|
410
|
+
* \};
|
|
411
|
+
*/
|
|
412
|
+
export interface AppCapabilities {
|
|
413
|
+
/**
|
|
414
|
+
* Manifest version for forward compatibility.
|
|
415
|
+
* Currently only '1.0' is supported.
|
|
416
|
+
*/
|
|
417
|
+
version: typeof CAPABILITY_VERSION;
|
|
418
|
+
|
|
419
|
+
/** Application metadata for display in authorization dialogs. */
|
|
420
|
+
metadata: {
|
|
421
|
+
/** Human-readable app name */
|
|
422
|
+
name: string;
|
|
423
|
+
|
|
424
|
+
/** App version */
|
|
425
|
+
version: string;
|
|
426
|
+
|
|
427
|
+
/** Optional description of what the app does */
|
|
428
|
+
description?: string;
|
|
429
|
+
|
|
430
|
+
/** Optional website URL */
|
|
431
|
+
url?: string;
|
|
432
|
+
|
|
433
|
+
/** Optional icon URL or data URI */
|
|
434
|
+
icon?: string;
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Requested capabilities grouped by scope.
|
|
439
|
+
*/
|
|
440
|
+
capabilities: Capability[];
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Wallet capability response.
|
|
445
|
+
*
|
|
446
|
+
* Returned by wallet after user reviews and approves/denies the capability request.
|
|
447
|
+
*
|
|
448
|
+
* The wallet can modify requested capabilities:
|
|
449
|
+
* - Reduce scope (e.g., restrict to specific contracts instead of '*')
|
|
450
|
+
* - Add information (e.g., specify which accounts are granted)
|
|
451
|
+
* - Deny capabilities (by omitting them from the `granted` array)
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* // App requests
|
|
455
|
+
* const manifest: AppCapabilities = \{
|
|
456
|
+
* version: '1.0',
|
|
457
|
+
* metadata: \{ name: 'MyDApp', version: '1.0.0' \},
|
|
458
|
+
* capabilities: [
|
|
459
|
+
* \{ type: 'accounts', canGet: true \},
|
|
460
|
+
* \{ type: 'contracts', contracts: '*', canRegister: true \}
|
|
461
|
+
* ]
|
|
462
|
+
* \};
|
|
463
|
+
*
|
|
464
|
+
* // Wallet responds with specific accounts and restricted contracts
|
|
465
|
+
* const response = await wallet.requestCapabilities(manifest);
|
|
466
|
+
* console.log(response.granted);
|
|
467
|
+
* // [
|
|
468
|
+
* // \{ type: 'accounts', canGet: true, accounts: [addr1, addr2] \},
|
|
469
|
+
* // \{ type: 'contracts', contracts: [specificContract], canRegister: true \}
|
|
470
|
+
* // ]
|
|
471
|
+
*/
|
|
472
|
+
export interface WalletCapabilities {
|
|
473
|
+
/** Response version for forward compatibility. */
|
|
474
|
+
version: typeof CAPABILITY_VERSION;
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Capabilities granted by the wallet.
|
|
478
|
+
* Capabilities not in this array were implicitly denied.
|
|
479
|
+
* Empty array means the user denied all capabilities.
|
|
480
|
+
*/
|
|
481
|
+
granted: GrantedCapability[];
|
|
482
|
+
|
|
483
|
+
/** Wallet implementation details. */
|
|
484
|
+
wallet: {
|
|
485
|
+
/** Wallet name/implementation */
|
|
486
|
+
name: string;
|
|
487
|
+
|
|
488
|
+
/** Wallet version */
|
|
489
|
+
version: string;
|
|
490
|
+
};
|
|
491
|
+
}
|