@aztec/aztec.js 0.0.0-test.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/README.md +44 -0
- package/dest/account/contract.d.ts +37 -0
- package/dest/account/contract.d.ts.map +1 -0
- package/dest/account/contract.js +16 -0
- package/dest/account/index.d.ts +15 -0
- package/dest/account/index.d.ts.map +1 -0
- package/dest/account/index.js +9 -0
- package/dest/account/interface.d.ts +31 -0
- package/dest/account/interface.d.ts.map +1 -0
- package/dest/account/interface.js +4 -0
- package/dest/account/wallet.d.ts +11 -0
- package/dest/account/wallet.d.ts.map +1 -0
- package/dest/account/wallet.js +3 -0
- package/dest/account_manager/deploy_account_method.d.ts +15 -0
- package/dest/account_manager/deploy_account_method.d.ts.map +1 -0
- package/dest/account_manager/deploy_account_method.js +43 -0
- package/dest/account_manager/deploy_account_sent_tx.d.ts +30 -0
- package/dest/account_manager/deploy_account_sent_tx.d.ts.map +1 -0
- package/dest/account_manager/deploy_account_sent_tx.js +29 -0
- package/dest/account_manager/index.d.ts +108 -0
- package/dest/account_manager/index.d.ts.map +1 -0
- package/dest/account_manager/index.js +159 -0
- package/dest/api/abi.d.ts +3 -0
- package/dest/api/abi.d.ts.map +1 -0
- package/dest/api/abi.js +1 -0
- package/dest/api/account.d.ts +3 -0
- package/dest/api/account.d.ts.map +1 -0
- package/dest/api/account.js +2 -0
- package/dest/api/addresses.d.ts +3 -0
- package/dest/api/addresses.d.ts.map +1 -0
- package/dest/api/addresses.js +2 -0
- package/dest/api/cheat_codes.d.ts +26 -0
- package/dest/api/cheat_codes.d.ts.map +1 -0
- package/dest/api/cheat_codes.js +25 -0
- package/dest/api/deployment.d.ts +4 -0
- package/dest/api/deployment.d.ts.map +1 -0
- package/dest/api/deployment.js +3 -0
- package/dest/api/entrypoint.d.ts +2 -0
- package/dest/api/entrypoint.d.ts.map +1 -0
- package/dest/api/entrypoint.js +1 -0
- package/dest/api/eth_address.d.ts +2 -0
- package/dest/api/eth_address.d.ts.map +1 -0
- package/dest/api/eth_address.js +1 -0
- package/dest/api/ethereum/anvil_test_watcher.d.ts +32 -0
- package/dest/api/ethereum/anvil_test_watcher.d.ts.map +1 -0
- package/dest/api/ethereum/anvil_test_watcher.js +133 -0
- package/dest/api/ethereum/chain_monitor.d.ts +25 -0
- package/dest/api/ethereum/chain_monitor.d.ts.map +1 -0
- package/dest/api/ethereum/chain_monitor.js +74 -0
- package/dest/api/ethereum/cheat_codes.d.ts +63 -0
- package/dest/api/ethereum/cheat_codes.d.ts.map +1 -0
- package/dest/api/ethereum/cheat_codes.js +162 -0
- package/dest/api/ethereum/index.d.ts +7 -0
- package/dest/api/ethereum/index.d.ts.map +1 -0
- package/dest/api/ethereum/index.js +6 -0
- package/dest/api/ethereum/l1_contracts.d.ts +3 -0
- package/dest/api/ethereum/l1_contracts.d.ts.map +1 -0
- package/dest/api/ethereum/l1_contracts.js +13 -0
- package/dest/api/ethereum/portal_manager.d.ts +136 -0
- package/dest/api/ethereum/portal_manager.d.ts.map +1 -0
- package/dest/api/ethereum/portal_manager.js +286 -0
- package/dest/api/fee.d.ts +6 -0
- package/dest/api/fee.d.ts.map +1 -0
- package/dest/api/fee.js +4 -0
- package/dest/api/fields.d.ts +2 -0
- package/dest/api/fields.d.ts.map +1 -0
- package/dest/api/fields.js +1 -0
- package/dest/api/interfaces/pxe.d.ts +2 -0
- package/dest/api/interfaces/pxe.d.ts.map +1 -0
- package/dest/api/interfaces/pxe.js +1 -0
- package/dest/api/log.d.ts +2 -0
- package/dest/api/log.d.ts.map +1 -0
- package/dest/api/log.js +1 -0
- package/dest/api/log_id.d.ts +2 -0
- package/dest/api/log_id.d.ts.map +1 -0
- package/dest/api/log_id.js +1 -0
- package/dest/api/tx_hash.d.ts +2 -0
- package/dest/api/tx_hash.d.ts.map +1 -0
- package/dest/api/tx_hash.js +1 -0
- package/dest/api/wallet.d.ts +2 -0
- package/dest/api/wallet.d.ts.map +1 -0
- package/dest/api/wallet.js +1 -0
- package/dest/contract/base_contract_interaction.d.ts +98 -0
- package/dest/contract/base_contract_interaction.d.ts.map +1 -0
- package/dest/contract/base_contract_interaction.js +149 -0
- package/dest/contract/batch_call.d.ts +28 -0
- package/dest/contract/batch_call.d.ts.map +1 -0
- package/dest/contract/batch_call.js +91 -0
- package/dest/contract/checker.d.ts +11 -0
- package/dest/contract/checker.d.ts.map +1 -0
- package/dest/contract/checker.js +107 -0
- package/dest/contract/contract.d.ts +41 -0
- package/dest/contract/contract.d.ts.map +1 -0
- package/dest/contract/contract.js +52 -0
- package/dest/contract/contract_base.d.ts +61 -0
- package/dest/contract/contract_base.d.ts.map +1 -0
- package/dest/contract/contract_base.js +45 -0
- package/dest/contract/contract_function_interaction.d.ts +68 -0
- package/dest/contract/contract_function_interaction.d.ts.map +1 -0
- package/dest/contract/contract_function_interaction.js +122 -0
- package/dest/contract/deploy_method.d.ts +113 -0
- package/dest/contract/deploy_method.d.ts.map +1 -0
- package/dest/contract/deploy_method.js +212 -0
- package/dest/contract/deploy_proven_tx.d.ts +21 -0
- package/dest/contract/deploy_proven_tx.d.ts.map +1 -0
- package/dest/contract/deploy_proven_tx.js +19 -0
- package/dest/contract/deploy_sent_tx.d.ts +45 -0
- package/dest/contract/deploy_sent_tx.d.ts.map +1 -0
- package/dest/contract/deploy_sent_tx.js +43 -0
- package/dest/contract/get_gas_limits.d.ts +18 -0
- package/dest/contract/get_gas_limits.d.ts.map +1 -0
- package/dest/contract/get_gas_limits.js +10 -0
- package/dest/contract/index.d.ts +45 -0
- package/dest/contract/index.d.ts.map +1 -0
- package/dest/contract/index.js +43 -0
- package/dest/contract/protocol_contracts.d.ts +9 -0
- package/dest/contract/protocol_contracts.d.ts.map +1 -0
- package/dest/contract/protocol_contracts.js +26 -0
- package/dest/contract/proven_tx.d.ts +17 -0
- package/dest/contract/proven_tx.d.ts.map +1 -0
- package/dest/contract/proven_tx.js +22 -0
- package/dest/contract/sent_tx.d.ts +61 -0
- package/dest/contract/sent_tx.d.ts.map +1 -0
- package/dest/contract/sent_tx.js +102 -0
- package/dest/contract/unsafe_contract.d.ts +15 -0
- package/dest/contract/unsafe_contract.d.ts.map +1 -0
- package/dest/contract/unsafe_contract.js +6 -0
- package/dest/deployment/broadcast_function.d.ts +24 -0
- package/dest/deployment/broadcast_function.d.ts.map +1 -0
- package/dest/deployment/broadcast_function.js +70 -0
- package/dest/deployment/contract_deployer.d.ts +27 -0
- package/dest/deployment/contract_deployer.d.ts.map +1 -0
- package/dest/deployment/contract_deployer.js +30 -0
- package/dest/deployment/deploy_instance.d.ts +10 -0
- package/dest/deployment/deploy_instance.d.ts.map +1 -0
- package/dest/deployment/deploy_instance.js +14 -0
- package/dest/deployment/index.d.ts +2 -0
- package/dest/deployment/index.d.ts.map +1 -0
- package/dest/deployment/index.js +1 -0
- package/dest/deployment/register_class.d.ts +6 -0
- package/dest/deployment/register_class.d.ts.map +1 -0
- package/dest/deployment/register_class.js +22 -0
- package/dest/entrypoint/default_entrypoint.d.ts +12 -0
- package/dest/entrypoint/default_entrypoint.d.ts.map +1 -0
- package/dest/entrypoint/default_entrypoint.js +28 -0
- package/dest/entrypoint/default_multi_call_entrypoint.d.ts +15 -0
- package/dest/entrypoint/default_multi_call_entrypoint.d.ts.map +1 -0
- package/dest/entrypoint/default_multi_call_entrypoint.js +130 -0
- package/dest/entrypoint/entrypoint.d.ts +35 -0
- package/dest/entrypoint/entrypoint.d.ts.map +1 -0
- package/dest/entrypoint/entrypoint.js +4 -0
- package/dest/entrypoint/payload.d.ts +128 -0
- package/dest/entrypoint/payload.d.ts.map +1 -0
- package/dest/entrypoint/payload.js +143 -0
- package/dest/fee/fee_juice_payment_method.d.ts +14 -0
- package/dest/fee/fee_juice_payment_method.d.ts.map +1 -0
- package/dest/fee/fee_juice_payment_method.js +20 -0
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts +18 -0
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -0
- package/dest/fee/fee_juice_payment_method_with_claim.js +37 -0
- package/dest/fee/fee_payment_method.d.ts +22 -0
- package/dest/fee/fee_payment_method.d.ts.map +1 -0
- package/dest/fee/fee_payment_method.js +3 -0
- package/dest/fee/private_fee_payment_method.d.ts +51 -0
- package/dest/fee/private_fee_payment_method.d.ts.map +1 -0
- package/dest/fee/private_fee_payment_method.js +103 -0
- package/dest/fee/public_fee_payment_method.d.ts +41 -0
- package/dest/fee/public_fee_payment_method.d.ts.map +1 -0
- package/dest/fee/public_fee_payment_method.js +97 -0
- package/dest/index.d.ts +66 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +69 -0
- package/dest/rpc_clients/index.d.ts +3 -0
- package/dest/rpc_clients/index.d.ts.map +1 -0
- package/dest/rpc_clients/index.js +2 -0
- package/dest/rpc_clients/node/index.d.ts +12 -0
- package/dest/rpc_clients/node/index.d.ts.map +1 -0
- package/dest/rpc_clients/node/index.js +78 -0
- package/dest/rpc_clients/pxe_client.d.ts +10 -0
- package/dest/rpc_clients/pxe_client.d.ts.map +1 -0
- package/dest/rpc_clients/pxe_client.js +23 -0
- package/dest/utils/abi_types.d.ts +29 -0
- package/dest/utils/abi_types.d.ts.map +1 -0
- package/dest/utils/abi_types.js +1 -0
- package/dest/utils/authwit.d.ts +60 -0
- package/dest/utils/authwit.d.ts.map +1 -0
- package/dest/utils/authwit.js +74 -0
- package/dest/utils/aztec_cheatcodes.d.ts +59 -0
- package/dest/utils/aztec_cheatcodes.d.ts.map +1 -0
- package/dest/utils/aztec_cheatcodes.js +62 -0
- package/dest/utils/fee_juice.d.ts +7 -0
- package/dest/utils/fee_juice.d.ts.map +1 -0
- package/dest/utils/fee_juice.js +9 -0
- package/dest/utils/field_compressed_string.d.ts +17 -0
- package/dest/utils/field_compressed_string.d.ts.map +1 -0
- package/dest/utils/field_compressed_string.js +15 -0
- package/dest/utils/index.d.ts +8 -0
- package/dest/utils/index.d.ts.map +1 -0
- package/dest/utils/index.js +6 -0
- package/dest/utils/node.d.ts +5 -0
- package/dest/utils/node.d.ts.map +1 -0
- package/dest/utils/node.js +15 -0
- package/dest/utils/pub_key.d.ts +9 -0
- package/dest/utils/pub_key.d.ts.map +1 -0
- package/dest/utils/pub_key.js +9 -0
- package/dest/utils/pxe.d.ts +4 -0
- package/dest/utils/pxe.d.ts.map +1 -0
- package/dest/utils/pxe.js +14 -0
- package/dest/wallet/account_wallet.d.ts +76 -0
- package/dest/wallet/account_wallet.d.ts.map +1 -0
- package/dest/wallet/account_wallet.js +231 -0
- package/dest/wallet/account_wallet_with_private_key.d.ts +26 -0
- package/dest/wallet/account_wallet_with_private_key.d.ts.map +1 -0
- package/dest/wallet/account_wallet_with_private_key.js +22 -0
- package/dest/wallet/base_wallet.d.ts +73 -0
- package/dest/wallet/base_wallet.d.ts.map +1 -0
- package/dest/wallet/base_wallet.js +123 -0
- package/dest/wallet/index.d.ts +17 -0
- package/dest/wallet/index.d.ts.map +1 -0
- package/dest/wallet/index.js +20 -0
- package/dest/wallet/signerless_wallet.d.ts +25 -0
- package/dest/wallet/signerless_wallet.d.ts.map +1 -0
- package/dest/wallet/signerless_wallet.js +36 -0
- package/package.json +116 -0
- package/src/account/contract.ts +56 -0
- package/src/account/index.ts +16 -0
- package/src/account/interface.ts +36 -0
- package/src/account/wallet.ts +13 -0
- package/src/account_manager/deploy_account_method.ts +86 -0
- package/src/account_manager/deploy_account_sent_tx.ts +42 -0
- package/src/account_manager/index.ts +229 -0
- package/src/api/README.md +7 -0
- package/src/api/abi.ts +10 -0
- package/src/api/account.ts +10 -0
- package/src/api/addresses.ts +2 -0
- package/src/api/cheat_codes.ts +35 -0
- package/src/api/deployment.ts +3 -0
- package/src/api/entrypoint.ts +1 -0
- package/src/api/eth_address.ts +1 -0
- package/src/api/ethereum/anvil_test_watcher.ts +158 -0
- package/src/api/ethereum/chain_monitor.ts +88 -0
- package/src/api/ethereum/cheat_codes.ts +184 -0
- package/src/api/ethereum/index.ts +19 -0
- package/src/api/ethereum/l1_contracts.ts +21 -0
- package/src/api/ethereum/portal_manager.ts +410 -0
- package/src/api/fee.ts +5 -0
- package/src/api/fields.ts +1 -0
- package/src/api/interfaces/pxe.ts +1 -0
- package/src/api/log.ts +1 -0
- package/src/api/log_id.ts +1 -0
- package/src/api/tx_hash.ts +1 -0
- package/src/api/wallet.ts +7 -0
- package/src/contract/base_contract_interaction.ts +192 -0
- package/src/contract/batch_call.ts +95 -0
- package/src/contract/checker.ts +117 -0
- package/src/contract/contract.ts +69 -0
- package/src/contract/contract_base.ts +90 -0
- package/src/contract/contract_function_interaction.ts +173 -0
- package/src/contract/deploy_method.ts +271 -0
- package/src/contract/deploy_proven_tx.ts +34 -0
- package/src/contract/deploy_sent_tx.ts +74 -0
- package/src/contract/get_gas_limits.ts +26 -0
- package/src/contract/index.ts +48 -0
- package/src/contract/protocol_contracts.ts +35 -0
- package/src/contract/proven_tx.ts +42 -0
- package/src/contract/sent_tx.ts +141 -0
- package/src/contract/unsafe_contract.ts +19 -0
- package/src/deployment/broadcast_function.ts +148 -0
- package/src/deployment/contract_deployer.ts +41 -0
- package/src/deployment/deploy_instance.ts +31 -0
- package/src/deployment/index.ts +1 -0
- package/src/deployment/register_class.ts +44 -0
- package/src/entrypoint/default_entrypoint.ts +39 -0
- package/src/entrypoint/default_multi_call_entrypoint.ts +93 -0
- package/src/entrypoint/entrypoint.ts +39 -0
- package/src/entrypoint/payload.ts +238 -0
- package/src/fee/fee_juice_payment_method.ts +26 -0
- package/src/fee/fee_juice_payment_method_with_claim.ts +49 -0
- package/src/fee/fee_payment_method.ts +22 -0
- package/src/fee/private_fee_payment_method.ts +118 -0
- package/src/fee/public_fee_payment_method.ts +114 -0
- package/src/index.ts +106 -0
- package/src/rpc_clients/index.ts +2 -0
- package/src/rpc_clients/node/index.ts +77 -0
- package/src/rpc_clients/pxe_client.ts +25 -0
- package/src/utils/abi_types.ts +25 -0
- package/src/utils/authwit.ts +110 -0
- package/src/utils/aztec_cheatcodes.ts +77 -0
- package/src/utils/fee_juice.ts +14 -0
- package/src/utils/field_compressed_string.ts +27 -0
- package/src/utils/index.ts +21 -0
- package/src/utils/node.ts +19 -0
- package/src/utils/pub_key.ts +13 -0
- package/src/utils/pxe.ts +17 -0
- package/src/wallet/account_wallet.ts +242 -0
- package/src/wallet/account_wallet_with_private_key.ts +40 -0
- package/src/wallet/base_wallet.ts +198 -0
- package/src/wallet/index.ts +33 -0
- package/src/wallet/signerless_wallet.ts +52 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
2
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { NoRetryError, makeBackoff, retry } from '@aztec/foundation/retry';
|
|
4
|
+
import type { PXE } from '@aztec/stdlib/interfaces/client';
|
|
5
|
+
import type { ComponentsVersions } from '@aztec/stdlib/versioning';
|
|
6
|
+
|
|
7
|
+
import { Axios, type AxiosError } from 'axios';
|
|
8
|
+
import { inspect } from 'util';
|
|
9
|
+
|
|
10
|
+
import { createPXEClient } from '../pxe_client.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A fetch implementation using axios.
|
|
14
|
+
* @param host - The URL of the host.
|
|
15
|
+
* @param rpcMethod - The RPC method to call.
|
|
16
|
+
* @param body - The body of the request.
|
|
17
|
+
* @param useApiEndpoints - Whether to use the API endpoints or inject the method in the body.
|
|
18
|
+
* @returns The response data.
|
|
19
|
+
*/
|
|
20
|
+
async function axiosFetch(host: string, rpcMethod: string, body: any, useApiEndpoints: boolean) {
|
|
21
|
+
const request = new Axios({
|
|
22
|
+
headers: { 'content-type': 'application/json' },
|
|
23
|
+
transformRequest: [(data: any) => jsonStringify(data)],
|
|
24
|
+
transformResponse: [(data: any) => JSON.parse(data)],
|
|
25
|
+
});
|
|
26
|
+
const [url, content] = useApiEndpoints ? [`${host}/${rpcMethod}`, body] : [host, { ...body, method: rpcMethod }];
|
|
27
|
+
const resp = await request.post(url, content).catch((error: AxiosError) => {
|
|
28
|
+
if (error.response) {
|
|
29
|
+
return error.response;
|
|
30
|
+
}
|
|
31
|
+
const errorMessage = `Error fetching from host ${host} with method ${rpcMethod}: ${inspect(error)}`;
|
|
32
|
+
throw new Error(errorMessage);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const isOK = resp.status >= 200 && resp.status < 300;
|
|
36
|
+
if (isOK) {
|
|
37
|
+
const headers = {
|
|
38
|
+
get: (header: string) =>
|
|
39
|
+
typeof resp.headers.get === 'function' ? resp.headers.get(header)?.toString() : undefined,
|
|
40
|
+
};
|
|
41
|
+
return { response: resp.data, headers };
|
|
42
|
+
} else {
|
|
43
|
+
const errorMessage = `Error ${resp.status} from json-rpc server ${host} on ${rpcMethod}: ${resp.data.error.message}`;
|
|
44
|
+
if (resp.status >= 400 && resp.status < 500) {
|
|
45
|
+
throw new NoRetryError(errorMessage);
|
|
46
|
+
} else {
|
|
47
|
+
throw new Error(errorMessage);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Creates a PXE client with a given set of retries on non-server errors.
|
|
54
|
+
* Checks that PXE matches the expected version, and warns if not.
|
|
55
|
+
* @param rpcUrl - URL of the RPC server wrapping the PXE.
|
|
56
|
+
* @param _logger - Debug logger to warn version incompatibilities.
|
|
57
|
+
* @returns A PXE client.
|
|
58
|
+
*/
|
|
59
|
+
export function createCompatibleClient(
|
|
60
|
+
rpcUrl: string,
|
|
61
|
+
logger: Logger = createLogger('aztecjs:pxe_client'),
|
|
62
|
+
versions: Partial<ComponentsVersions> = {},
|
|
63
|
+
): Promise<PXE> {
|
|
64
|
+
// Use axios due to timeout issues with fetch when proving TXs.
|
|
65
|
+
const fetch = async (host: string, rpcMethod: string, body: any, useApiEndpoints: boolean) => {
|
|
66
|
+
return await retry(
|
|
67
|
+
() => axiosFetch(host, rpcMethod, body, useApiEndpoints),
|
|
68
|
+
`JsonRpcClient request ${rpcMethod} to ${host}`,
|
|
69
|
+
makeBackoff([1, 2, 3]),
|
|
70
|
+
logger,
|
|
71
|
+
false,
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
const pxe = createPXEClient(rpcUrl, versions, fetch);
|
|
75
|
+
|
|
76
|
+
return Promise.resolve(pxe);
|
|
77
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createSafeJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client';
|
|
2
|
+
import { protocolContractTreeRoot } from '@aztec/protocol-contracts';
|
|
3
|
+
import { type PXE, PXESchema } from '@aztec/stdlib/interfaces/client';
|
|
4
|
+
import { type ComponentsVersions, getVersioningResponseHandler } from '@aztec/stdlib/versioning';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a JSON-RPC client to remotely talk to PXE.
|
|
8
|
+
* @param url - The URL of the PXE.
|
|
9
|
+
* @param fetch - The fetch implementation to use.
|
|
10
|
+
* @returns A JSON-RPC client of PXE.
|
|
11
|
+
*/
|
|
12
|
+
export function createPXEClient(
|
|
13
|
+
url: string,
|
|
14
|
+
versions: Partial<ComponentsVersions> = {},
|
|
15
|
+
fetch = makeFetch([1, 2, 3], false),
|
|
16
|
+
): PXE {
|
|
17
|
+
return createSafeJsonRpcClient<PXE>(url, PXESchema, {
|
|
18
|
+
namespaceMethods: 'pxe',
|
|
19
|
+
fetch,
|
|
20
|
+
onResponse: getVersioningResponseHandler({
|
|
21
|
+
l2ProtocolContractsTreeRoot: protocolContractTreeRoot.toString(),
|
|
22
|
+
...versions,
|
|
23
|
+
}),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import type { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import type { EventSelector, FunctionSelector } from '@aztec/stdlib/abi';
|
|
4
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
|
|
6
|
+
/** Any type that can be converted into a field for a contract call. */
|
|
7
|
+
export type FieldLike = Fr | Buffer | bigint | number | { /** Converts to field */ toField: () => Fr };
|
|
8
|
+
|
|
9
|
+
/** Any type that can be converted into an EthAddress Aztec.nr struct. */
|
|
10
|
+
export type EthAddressLike = { /** Wrapped address */ address: FieldLike } | EthAddress;
|
|
11
|
+
|
|
12
|
+
/** Any type that can be converted into an AztecAddress Aztec.nr struct. */
|
|
13
|
+
export type AztecAddressLike = { /** Wrapped address */ address: FieldLike } | AztecAddress;
|
|
14
|
+
|
|
15
|
+
/** Any type that can be converted into a FunctionSelector Aztec.nr struct. */
|
|
16
|
+
export type FunctionSelectorLike = FieldLike | FunctionSelector;
|
|
17
|
+
|
|
18
|
+
/** Any type that can be converted into an EventSelector Aztec.nr struct. */
|
|
19
|
+
export type EventSelectorLike = FieldLike | EventSelector;
|
|
20
|
+
|
|
21
|
+
/** Any type that can be converted into a U128. */
|
|
22
|
+
export type U128Like = bigint | number;
|
|
23
|
+
|
|
24
|
+
/** Any type that can be converted into a struct with a single `inner` field. */
|
|
25
|
+
export type WrappedFieldLike = { /** Wrapped value */ inner: FieldLike } | FieldLike;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { GeneratorIndex } from '@aztec/constants';
|
|
2
|
+
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
|
|
3
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
4
|
+
import type { FunctionCall } from '@aztec/stdlib/abi';
|
|
5
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
+
import { HashedValues } from '@aztec/stdlib/tx';
|
|
7
|
+
|
|
8
|
+
import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
9
|
+
|
|
10
|
+
/** Metadata for the intent */
|
|
11
|
+
export type IntentMetadata = {
|
|
12
|
+
/** The chain id to approve */
|
|
13
|
+
chainId: Fr;
|
|
14
|
+
/** The version to approve */
|
|
15
|
+
version: Fr;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** Intent with an inner hash */
|
|
19
|
+
export type IntentInnerHash = {
|
|
20
|
+
/** The consumer */
|
|
21
|
+
consumer: AztecAddress;
|
|
22
|
+
/** The action to approve */
|
|
23
|
+
innerHash: Buffer | Fr;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** Intent with an action */
|
|
27
|
+
export type IntentAction = {
|
|
28
|
+
/** The caller to approve */
|
|
29
|
+
caller: AztecAddress;
|
|
30
|
+
/** The action to approve */
|
|
31
|
+
action: ContractFunctionInteraction | FunctionCall;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// docs:start:authwit_computeAuthWitMessageHash
|
|
35
|
+
/**
|
|
36
|
+
* Compute an authentication witness message hash from an intent and metadata
|
|
37
|
+
*
|
|
38
|
+
* If using the `IntentInnerHash`, the consumer is the address that can "consume" the authwit, for token approvals it is the token contract itself.
|
|
39
|
+
* The `innerHash` itself will be the message that a contract is allowed to execute.
|
|
40
|
+
* At the point of "approval checking", the validating contract (account for private and registry for public) will be computing the message hash
|
|
41
|
+
* (`H(consumer, chainid, version, inner_hash)`) where the all but the `inner_hash` is injected from the context (consumer = msg_sender),
|
|
42
|
+
* and use it for the authentication check.
|
|
43
|
+
* Therefore, any allowed `innerHash` will therefore also have information around where it can be spent (version, chainId) and who can spend it (consumer).
|
|
44
|
+
*
|
|
45
|
+
* If using the `IntentAction`, the caller is the address that is making the call, for a token approval from Alice to Bob, this would be Bob.
|
|
46
|
+
* The action is then used along with the `caller` to compute the `innerHash` and the consumer.
|
|
47
|
+
*
|
|
48
|
+
*
|
|
49
|
+
* @param intent - The intent to approve (consumer and innerHash or caller and action)
|
|
50
|
+
* The consumer is the address that can "consume" the authwit, for token approvals it is the token contract itself.
|
|
51
|
+
* The caller is the address that is making the call, for a token approval from Alice to Bob, this would be Bob.
|
|
52
|
+
* The caller becomes part of the `inner_hash` and is dealt with entirely in application logic.
|
|
53
|
+
* @param metadata - The metadata for the intent (chainId, version)
|
|
54
|
+
* @returns The message hash for the action
|
|
55
|
+
*/
|
|
56
|
+
export const computeAuthWitMessageHash = async (intent: IntentInnerHash | IntentAction, metadata: IntentMetadata) => {
|
|
57
|
+
const chainId = metadata.chainId;
|
|
58
|
+
const version = metadata.version;
|
|
59
|
+
|
|
60
|
+
if ('caller' in intent) {
|
|
61
|
+
const action = intent.action instanceof ContractFunctionInteraction ? await intent.action.request() : intent.action;
|
|
62
|
+
return computeOuterAuthWitHash(
|
|
63
|
+
action.to,
|
|
64
|
+
chainId,
|
|
65
|
+
version,
|
|
66
|
+
await computeInnerAuthWitHashFromAction(intent.caller, action),
|
|
67
|
+
);
|
|
68
|
+
} else {
|
|
69
|
+
const inner = Buffer.isBuffer(intent.innerHash) ? Fr.fromBuffer(intent.innerHash) : intent.innerHash;
|
|
70
|
+
return computeOuterAuthWitHash(intent.consumer, chainId, version, inner);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
// docs:end:authwit_computeAuthWitMessageHash
|
|
74
|
+
|
|
75
|
+
export const computeInnerAuthWitHashFromAction = async (caller: AztecAddress, action: FunctionCall) =>
|
|
76
|
+
computeInnerAuthWitHash([
|
|
77
|
+
caller.toField(),
|
|
78
|
+
action.selector.toField(),
|
|
79
|
+
(await HashedValues.fromValues(action.args)).hash,
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Compute the inner hash for an authentication witness.
|
|
84
|
+
* This is the "intent" of the message, before siloed with the consumer.
|
|
85
|
+
* It is used as part of the `computeAuthWitMessageHash` but can also be used
|
|
86
|
+
* in case the message is not a "call" to a function, but arbitrary data.
|
|
87
|
+
* @param args - The arguments to hash
|
|
88
|
+
* @returns The inner hash for the witness
|
|
89
|
+
*/
|
|
90
|
+
export const computeInnerAuthWitHash = (args: Fr[]) => {
|
|
91
|
+
return poseidon2HashWithSeparator(args, GeneratorIndex.AUTHWIT_INNER);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Compute the outer hash for an authentication witness.
|
|
96
|
+
* This is the value siloed with its "consumer" and what the `on_behalf_of`
|
|
97
|
+
* should be signing.
|
|
98
|
+
* The consumer is who will be consuming the message, for token approvals it
|
|
99
|
+
* is the token contract itself (because the token makes the call to check the approval).
|
|
100
|
+
* It is used as part of the `computeAuthWitMessageHash` but can also be used
|
|
101
|
+
* in case the message is not a "call" to a function, but arbitrary data.
|
|
102
|
+
* @param consumer - The address that can "consume" the authwit
|
|
103
|
+
* @param chainId - The chain id that can "consume" the authwit
|
|
104
|
+
* @param version - The version that can "consume" the authwit
|
|
105
|
+
* @param innerHash - The inner hash for the witness
|
|
106
|
+
* @returns The outer hash for the witness
|
|
107
|
+
*/
|
|
108
|
+
const computeOuterAuthWitHash = (consumer: AztecAddress, chainId: Fr, version: Fr, innerHash: Fr) => {
|
|
109
|
+
return poseidon2HashWithSeparator([consumer.toField(), chainId, version, innerHash], GeneratorIndex.AUTHWIT_OUTER);
|
|
110
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import { deriveStorageSlotInMap } from '@aztec/stdlib/hash';
|
|
5
|
+
import type { PXE } from '@aztec/stdlib/interfaces/client';
|
|
6
|
+
import type { Note } from '@aztec/stdlib/note';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A class that provides utility functions for interacting with the aztec chain.
|
|
10
|
+
*/
|
|
11
|
+
export class AztecCheatCodes {
|
|
12
|
+
constructor(
|
|
13
|
+
/**
|
|
14
|
+
* The PXE Service to use for interacting with the chain
|
|
15
|
+
*/
|
|
16
|
+
public pxe: PXE,
|
|
17
|
+
/**
|
|
18
|
+
* The logger to use for the aztec cheatcodes
|
|
19
|
+
*/
|
|
20
|
+
public logger = createLogger('aztecjs:cheat_codes'),
|
|
21
|
+
) {}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Computes the slot value for a given map and key.
|
|
25
|
+
* @param mapSlot - The slot of the map (specified in Aztec.nr contract)
|
|
26
|
+
* @param key - The key to lookup in the map
|
|
27
|
+
* @returns The storage slot of the value in the map
|
|
28
|
+
*/
|
|
29
|
+
public computeSlotInMap(mapSlot: Fr | bigint, key: Fr | bigint | AztecAddress): Promise<Fr> {
|
|
30
|
+
const keyFr = typeof key === 'bigint' ? new Fr(key) : key.toField();
|
|
31
|
+
return deriveStorageSlotInMap(mapSlot, keyFr);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get the current blocknumber
|
|
36
|
+
* @returns The current block number
|
|
37
|
+
*/
|
|
38
|
+
public async blockNumber(): Promise<number> {
|
|
39
|
+
return await this.pxe.getBlockNumber();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get the current timestamp
|
|
44
|
+
* @returns The current timestamp
|
|
45
|
+
*/
|
|
46
|
+
public async timestamp(): Promise<number> {
|
|
47
|
+
const res = await this.pxe.getBlock(await this.blockNumber());
|
|
48
|
+
return res?.header.globalVariables.timestamp.toNumber() ?? 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Loads the value stored at the given slot in the public storage of the given contract.
|
|
53
|
+
* @param who - The address of the contract
|
|
54
|
+
* @param slot - The storage slot to lookup
|
|
55
|
+
* @returns The value stored at the given slot
|
|
56
|
+
*/
|
|
57
|
+
public async loadPublic(who: AztecAddress, slot: Fr | bigint): Promise<Fr> {
|
|
58
|
+
const storageValue = await this.pxe.getPublicStorageAt(who, new Fr(slot));
|
|
59
|
+
return storageValue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Loads the value stored at the given slot in the private storage of the given contract.
|
|
64
|
+
* @param contract - The address of the contract
|
|
65
|
+
* @param owner - The owner for whom the notes are encrypted
|
|
66
|
+
* @param slot - The storage slot to lookup
|
|
67
|
+
* @returns The notes stored at the given slot
|
|
68
|
+
*/
|
|
69
|
+
public async loadPrivate(owner: AztecAddress, contract: AztecAddress, slot: Fr | bigint): Promise<Note[]> {
|
|
70
|
+
const extendedNotes = await this.pxe.getNotes({
|
|
71
|
+
owner,
|
|
72
|
+
contractAddress: contract,
|
|
73
|
+
storageSlot: new Fr(slot),
|
|
74
|
+
});
|
|
75
|
+
return extendedNotes.map(extendedNote => extendedNote.note);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
3
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import { deriveStorageSlotInMap } from '@aztec/stdlib/hash';
|
|
5
|
+
|
|
6
|
+
import type { PXE } from '../api/interfaces/pxe.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Returns the owner's fee juice balance.
|
|
10
|
+
*/
|
|
11
|
+
export async function getFeeJuiceBalance(owner: AztecAddress, pxe: PXE): Promise<bigint> {
|
|
12
|
+
const slot = await deriveStorageSlotInMap(new Fr(1), owner);
|
|
13
|
+
return (await pxe.getPublicStorageAt(ProtocolContractAddress.FeeJuice, slot)).toBigInt();
|
|
14
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The representation of a FieldCompressedString in aztec.nr
|
|
5
|
+
*/
|
|
6
|
+
interface NoirFieldCompressedString {
|
|
7
|
+
/**
|
|
8
|
+
* The field value of the string
|
|
9
|
+
*/
|
|
10
|
+
value: bigint;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* This turns
|
|
14
|
+
* @param field - The field that contains the string
|
|
15
|
+
* @returns - the string that is decoded from the field
|
|
16
|
+
*/
|
|
17
|
+
export const readFieldCompressedString = (field: NoirFieldCompressedString): string => {
|
|
18
|
+
const vals: number[] = Array.from(new Fr(field.value).toBuffer());
|
|
19
|
+
|
|
20
|
+
let str = '';
|
|
21
|
+
for (let i = 0; i < vals.length; i++) {
|
|
22
|
+
if (vals[i] != 0) {
|
|
23
|
+
str += String.fromCharCode(Number(vals[i]));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return str;
|
|
27
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { generatePublicKey } from './pub_key.js';
|
|
2
|
+
export {
|
|
3
|
+
type AztecAddressLike,
|
|
4
|
+
type EthAddressLike,
|
|
5
|
+
type EventSelectorLike,
|
|
6
|
+
type FieldLike,
|
|
7
|
+
type FunctionSelectorLike,
|
|
8
|
+
type U128Like,
|
|
9
|
+
type WrappedFieldLike,
|
|
10
|
+
} from './abi_types.js';
|
|
11
|
+
export {
|
|
12
|
+
computeAuthWitMessageHash,
|
|
13
|
+
computeInnerAuthWitHash,
|
|
14
|
+
computeInnerAuthWitHashFromAction,
|
|
15
|
+
type IntentAction,
|
|
16
|
+
type IntentInnerHash,
|
|
17
|
+
} from './authwit.js';
|
|
18
|
+
export { waitForPXE } from './pxe.js';
|
|
19
|
+
export { waitForNode, createAztecNodeClient, type AztecNode } from './node.js';
|
|
20
|
+
export { getFeeJuiceBalance } from './fee_juice.js';
|
|
21
|
+
export { readFieldCompressedString } from './field_compressed_string.js';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
3
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
4
|
+
|
|
5
|
+
export const waitForNode = async (node: AztecNode, logger?: Logger) => {
|
|
6
|
+
await retryUntil(async () => {
|
|
7
|
+
try {
|
|
8
|
+
logger?.verbose('Attempting to contact Aztec node...');
|
|
9
|
+
await node.getNodeInfo();
|
|
10
|
+
logger?.verbose('Contacted Aztec node');
|
|
11
|
+
return true;
|
|
12
|
+
} catch (error) {
|
|
13
|
+
logger?.verbose('Failed to contact Aztec Node');
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}, 'RPC Get Node Info');
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { createAztecNodeClient, type AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Grumpkin } from '@aztec/foundation/crypto';
|
|
2
|
+
import type { GrumpkinScalar } from '@aztec/foundation/fields';
|
|
3
|
+
import type { PublicKey } from '@aztec/stdlib/keys';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Method for generating a public grumpkin key from a private key.
|
|
7
|
+
* @param privateKey - The private key.
|
|
8
|
+
* @returns The generated public key.
|
|
9
|
+
*/
|
|
10
|
+
export function generatePublicKey(privateKey: GrumpkinScalar): Promise<PublicKey> {
|
|
11
|
+
const grumpkin = new Grumpkin();
|
|
12
|
+
return grumpkin.mul(grumpkin.generator(), privateKey);
|
|
13
|
+
}
|
package/src/utils/pxe.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
3
|
+
import type { PXE } from '@aztec/stdlib/interfaces/client';
|
|
4
|
+
|
|
5
|
+
export const waitForPXE = async (pxe: PXE, logger?: Logger) => {
|
|
6
|
+
await retryUntil(async () => {
|
|
7
|
+
try {
|
|
8
|
+
logger?.verbose('Attempting to contact PXE...');
|
|
9
|
+
await pxe.getNodeInfo();
|
|
10
|
+
logger?.verbose('Contacted PXE');
|
|
11
|
+
return true;
|
|
12
|
+
} catch (error) {
|
|
13
|
+
logger?.verbose('Failed to contact PXE');
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}, 'RPC Get Node Info');
|
|
17
|
+
};
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
3
|
+
import { type ABIParameterVisibility, type FunctionAbi, FunctionType } from '@aztec/stdlib/abi';
|
|
4
|
+
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
5
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
+
import type { PXE } from '@aztec/stdlib/interfaces/client';
|
|
7
|
+
import type { TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
8
|
+
|
|
9
|
+
import type { AccountInterface } from '../account/interface.js';
|
|
10
|
+
import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
11
|
+
import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js';
|
|
12
|
+
import {
|
|
13
|
+
type IntentAction,
|
|
14
|
+
type IntentInnerHash,
|
|
15
|
+
computeAuthWitMessageHash,
|
|
16
|
+
computeInnerAuthWitHashFromAction,
|
|
17
|
+
} from '../utils/authwit.js';
|
|
18
|
+
import { BaseWallet } from './base_wallet.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A wallet implementation that forwards authentication requests to a provided account.
|
|
22
|
+
*/
|
|
23
|
+
export class AccountWallet extends BaseWallet {
|
|
24
|
+
constructor(pxe: PXE, protected account: AccountInterface) {
|
|
25
|
+
super(pxe, [account.getAddress()]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
createTxExecutionRequest(exec: ExecutionRequestInit): Promise<TxExecutionRequest> {
|
|
29
|
+
return this.account.createTxExecutionRequest(exec);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getChainId(): Fr {
|
|
33
|
+
return this.account.getChainId();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getVersion(): Fr {
|
|
37
|
+
return this.account.getVersion();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
override isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean> {
|
|
41
|
+
return this.pxe.isL1ToL2MessageSynced(l1ToL2Message);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Computes an authentication witness from either a message hash or an intent.
|
|
46
|
+
*
|
|
47
|
+
* If a message hash is provided, it will create a witness for the hash directly.
|
|
48
|
+
* Otherwise, it will compute the message hash using the intent, along with the
|
|
49
|
+
* chain id and the version values provided by the wallet.
|
|
50
|
+
*
|
|
51
|
+
* @param messageHashOrIntent - The message hash of the intent to approve
|
|
52
|
+
* @returns The authentication witness
|
|
53
|
+
*/
|
|
54
|
+
async createAuthWit(messageHashOrIntent: Fr | Buffer | IntentAction | IntentInnerHash): Promise<AuthWitness> {
|
|
55
|
+
let messageHash: Fr;
|
|
56
|
+
if (Buffer.isBuffer(messageHashOrIntent)) {
|
|
57
|
+
messageHash = Fr.fromBuffer(messageHashOrIntent);
|
|
58
|
+
} else if (messageHashOrIntent instanceof Fr) {
|
|
59
|
+
messageHash = messageHashOrIntent;
|
|
60
|
+
} else {
|
|
61
|
+
messageHash = await this.getMessageHash(messageHashOrIntent);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const witness = await this.account.createAuthWit(messageHash);
|
|
65
|
+
await this.pxe.addAuthWitness(witness);
|
|
66
|
+
return witness;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Returns a function interaction to set a message hash as authorized or revoked in this account.
|
|
71
|
+
*
|
|
72
|
+
* Public calls can then consume this authorization.
|
|
73
|
+
*
|
|
74
|
+
* @param messageHashOrIntent - The message hash or intent to authorize/revoke
|
|
75
|
+
* @param authorized - True to authorize, false to revoke authorization.
|
|
76
|
+
* @returns - A function interaction.
|
|
77
|
+
*/
|
|
78
|
+
public async setPublicAuthWit(
|
|
79
|
+
messageHashOrIntent: Fr | Buffer | IntentInnerHash | IntentAction,
|
|
80
|
+
authorized: boolean,
|
|
81
|
+
): Promise<ContractFunctionInteraction> {
|
|
82
|
+
let messageHash: Fr;
|
|
83
|
+
if (Buffer.isBuffer(messageHashOrIntent)) {
|
|
84
|
+
messageHash = Fr.fromBuffer(messageHashOrIntent);
|
|
85
|
+
} else if (messageHashOrIntent instanceof Fr) {
|
|
86
|
+
messageHash = messageHashOrIntent;
|
|
87
|
+
} else {
|
|
88
|
+
messageHash = await this.getMessageHash(messageHashOrIntent);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return new ContractFunctionInteraction(this, ProtocolContractAddress.AuthRegistry, this.getSetAuthorizedAbi(), [
|
|
92
|
+
messageHash,
|
|
93
|
+
authorized,
|
|
94
|
+
]);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private async getInnerHashAndConsumer(intent: IntentInnerHash | IntentAction): Promise<{
|
|
98
|
+
/** The inner hash */
|
|
99
|
+
innerHash: Fr;
|
|
100
|
+
/** The consumer of the authwit */
|
|
101
|
+
consumer: AztecAddress;
|
|
102
|
+
}> {
|
|
103
|
+
if ('caller' in intent && 'action' in intent) {
|
|
104
|
+
const action =
|
|
105
|
+
intent.action instanceof ContractFunctionInteraction ? await intent.action.request() : intent.action;
|
|
106
|
+
return {
|
|
107
|
+
innerHash: await computeInnerAuthWitHashFromAction(intent.caller, action),
|
|
108
|
+
consumer: action.to,
|
|
109
|
+
};
|
|
110
|
+
} else if (Buffer.isBuffer(intent.innerHash)) {
|
|
111
|
+
return { innerHash: Fr.fromBuffer(intent.innerHash), consumer: intent.consumer };
|
|
112
|
+
}
|
|
113
|
+
return { innerHash: intent.innerHash, consumer: intent.consumer };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Returns the message hash for the given intent
|
|
118
|
+
*
|
|
119
|
+
* @param intent - A tuple of (consumer and inner hash) or (caller and action)
|
|
120
|
+
* @returns The message hash
|
|
121
|
+
*/
|
|
122
|
+
private getMessageHash(intent: IntentInnerHash | IntentAction): Promise<Fr> {
|
|
123
|
+
const chainId = this.getChainId();
|
|
124
|
+
const version = this.getVersion();
|
|
125
|
+
return computeAuthWitMessageHash(intent, { chainId, version });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Lookup the validity of an authwit in private and public contexts.
|
|
130
|
+
*
|
|
131
|
+
* Uses the chain id and version of the wallet.
|
|
132
|
+
*
|
|
133
|
+
* @param onBehalfOf - The address of the "approver"
|
|
134
|
+
* @param intent - The consumer and inner hash or the caller and action to lookup
|
|
135
|
+
*
|
|
136
|
+
* @returns - A struct containing the validity of the authwit in private and public contexts.
|
|
137
|
+
*/
|
|
138
|
+
async lookupValidity(
|
|
139
|
+
onBehalfOf: AztecAddress,
|
|
140
|
+
intent: IntentInnerHash | IntentAction,
|
|
141
|
+
): Promise<{
|
|
142
|
+
/** boolean flag indicating if the authwit is valid in private context */
|
|
143
|
+
isValidInPrivate: boolean;
|
|
144
|
+
/** boolean flag indicating if the authwit is valid in public context */
|
|
145
|
+
isValidInPublic: boolean;
|
|
146
|
+
}> {
|
|
147
|
+
const { innerHash, consumer } = await this.getInnerHashAndConsumer(intent);
|
|
148
|
+
|
|
149
|
+
const messageHash = await this.getMessageHash(intent);
|
|
150
|
+
const results = { isValidInPrivate: false, isValidInPublic: false };
|
|
151
|
+
|
|
152
|
+
// Check private
|
|
153
|
+
const witness = await this.getAuthWitness(messageHash);
|
|
154
|
+
if (witness !== undefined) {
|
|
155
|
+
results.isValidInPrivate = (await new ContractFunctionInteraction(this, onBehalfOf, this.getLookupValidityAbi(), [
|
|
156
|
+
consumer,
|
|
157
|
+
innerHash,
|
|
158
|
+
]).simulate()) as boolean;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// check public
|
|
162
|
+
results.isValidInPublic = (await new ContractFunctionInteraction(
|
|
163
|
+
this,
|
|
164
|
+
ProtocolContractAddress.AuthRegistry,
|
|
165
|
+
this.getIsConsumableAbi(),
|
|
166
|
+
[onBehalfOf, messageHash],
|
|
167
|
+
).simulate()) as boolean;
|
|
168
|
+
|
|
169
|
+
return results;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Returns the complete address of the account that implements this wallet. */
|
|
173
|
+
public getCompleteAddress() {
|
|
174
|
+
return this.account.getCompleteAddress();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Returns the address of the account that implements this wallet. */
|
|
178
|
+
public override getAddress() {
|
|
179
|
+
return this.getCompleteAddress().address;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
private getSetAuthorizedAbi(): FunctionAbi {
|
|
183
|
+
return {
|
|
184
|
+
name: 'set_authorized',
|
|
185
|
+
isInitializer: false,
|
|
186
|
+
functionType: FunctionType.PUBLIC,
|
|
187
|
+
isInternal: true,
|
|
188
|
+
isStatic: false,
|
|
189
|
+
parameters: [
|
|
190
|
+
{
|
|
191
|
+
name: 'message_hash',
|
|
192
|
+
type: { kind: 'field' },
|
|
193
|
+
visibility: 'private' as ABIParameterVisibility,
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
name: 'authorize',
|
|
197
|
+
type: { kind: 'boolean' },
|
|
198
|
+
visibility: 'private' as ABIParameterVisibility,
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
returnTypes: [],
|
|
202
|
+
errorTypes: {},
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
private getLookupValidityAbi(): FunctionAbi {
|
|
207
|
+
return {
|
|
208
|
+
name: 'lookup_validity',
|
|
209
|
+
isInitializer: false,
|
|
210
|
+
functionType: FunctionType.UNCONSTRAINED,
|
|
211
|
+
isInternal: false,
|
|
212
|
+
isStatic: false,
|
|
213
|
+
parameters: [{ name: 'message_hash', type: { kind: 'field' }, visibility: 'private' as ABIParameterVisibility }],
|
|
214
|
+
returnTypes: [{ kind: 'boolean' }],
|
|
215
|
+
errorTypes: {},
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private getIsConsumableAbi(): FunctionAbi {
|
|
220
|
+
return {
|
|
221
|
+
name: 'unconstrained_is_consumable',
|
|
222
|
+
isInitializer: false,
|
|
223
|
+
functionType: FunctionType.UNCONSTRAINED,
|
|
224
|
+
isInternal: false,
|
|
225
|
+
isStatic: false,
|
|
226
|
+
parameters: [
|
|
227
|
+
{
|
|
228
|
+
name: 'address',
|
|
229
|
+
type: {
|
|
230
|
+
fields: [{ name: 'inner', type: { kind: 'field' } }],
|
|
231
|
+
kind: 'struct',
|
|
232
|
+
path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
|
|
233
|
+
},
|
|
234
|
+
visibility: 'private' as ABIParameterVisibility,
|
|
235
|
+
},
|
|
236
|
+
{ name: 'message_hash', type: { kind: 'field' }, visibility: 'private' as ABIParameterVisibility },
|
|
237
|
+
],
|
|
238
|
+
returnTypes: [{ kind: 'boolean' }],
|
|
239
|
+
errorTypes: {},
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}
|