@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
package/src/contract/sent_tx.ts
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
2
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
3
|
-
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
4
|
-
import { TxHash, type TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
5
|
-
|
|
6
|
-
import type { Wallet } from '../wallet/wallet.js';
|
|
7
|
-
|
|
8
|
-
/** Options related to waiting for a tx. */
|
|
9
|
-
export type WaitOpts = {
|
|
10
|
-
/** The amount of time to ignore TxStatus.DROPPED receipts (in seconds) due to the presumption that it is being propagated by the p2p network. Defaults to 5. */
|
|
11
|
-
ignoreDroppedReceiptsFor?: number;
|
|
12
|
-
/** The maximum time (in seconds) to wait for the transaction to be mined. Defaults to 60. */
|
|
13
|
-
timeout?: number;
|
|
14
|
-
/** The time interval (in seconds) between retries to fetch the transaction receipt. Defaults to 1. */
|
|
15
|
-
interval?: number;
|
|
16
|
-
/** Whether to accept a revert as a status code for the tx when waiting for it. If false, will throw if the tx reverts. */
|
|
17
|
-
dontThrowOnRevert?: boolean;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const DefaultWaitOpts: WaitOpts = {
|
|
21
|
-
ignoreDroppedReceiptsFor: 5,
|
|
22
|
-
timeout: 300,
|
|
23
|
-
interval: 1,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* The SentTx class represents a sent transaction through the PXE (or directly to a node) providing methods to fetch
|
|
28
|
-
* its hash, receipt, and mining status.
|
|
29
|
-
*/
|
|
30
|
-
export class SentTx {
|
|
31
|
-
protected sendTxPromise: Promise<void>;
|
|
32
|
-
protected sendTxError?: Error;
|
|
33
|
-
protected txHash?: TxHash;
|
|
34
|
-
|
|
35
|
-
constructor(
|
|
36
|
-
protected walletOrNode: Wallet | AztecNode,
|
|
37
|
-
sendTx: () => Promise<TxHash>,
|
|
38
|
-
) {
|
|
39
|
-
const { promise, resolve } = promiseWithResolvers<void>();
|
|
40
|
-
this.sendTxPromise = promise;
|
|
41
|
-
sendTx()
|
|
42
|
-
.then(txHash => {
|
|
43
|
-
this.txHash = txHash;
|
|
44
|
-
resolve();
|
|
45
|
-
})
|
|
46
|
-
.catch(err => {
|
|
47
|
-
this.sendTxError = err;
|
|
48
|
-
// Calling resolve instead of reject here because we want to throw the error when getTxHash is called.
|
|
49
|
-
resolve();
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Retrieves the transaction hash of the SentTx instance.
|
|
55
|
-
* The function internally awaits for the 'txHashPromise' to resolve, and then returns the resolved transaction hash.
|
|
56
|
-
*
|
|
57
|
-
* @returns A promise that resolves to the transaction hash of the SentTx instance.
|
|
58
|
-
* TODO(#7717): Don't throw here.
|
|
59
|
-
*/
|
|
60
|
-
public async getTxHash(): Promise<TxHash> {
|
|
61
|
-
// Make sure sendTx has been resolved, which can be triggered when it returns a txHash or when it throws an error.
|
|
62
|
-
await this.sendTxPromise;
|
|
63
|
-
|
|
64
|
-
// If sendTx threw an error, throw it.
|
|
65
|
-
if (this.sendTxError) {
|
|
66
|
-
throw this.sendTxError;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// sendTx returned a txHash if it's been resolved and no error was set.
|
|
70
|
-
return Promise.resolve(this.txHash!);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Retrieve the transaction receipt associated with the current SentTx instance.
|
|
75
|
-
* The function fetches the transaction hash using 'getTxHash' and then queries
|
|
76
|
-
* the PXE to get the corresponding transaction receipt.
|
|
77
|
-
*
|
|
78
|
-
* @returns A promise that resolves to a TxReceipt object representing the fetched transaction receipt.
|
|
79
|
-
*/
|
|
80
|
-
public async getReceipt(): Promise<TxReceipt> {
|
|
81
|
-
const txHash = await this.getTxHash();
|
|
82
|
-
return await this.walletOrNode.getTxReceipt(txHash);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Awaits for a tx to be mined and returns the receipt. Throws if tx is not mined.
|
|
87
|
-
* @param opts - Options for configuring the waiting for the tx to be mined.
|
|
88
|
-
* @returns The transaction receipt.
|
|
89
|
-
*/
|
|
90
|
-
public async wait(opts?: WaitOpts): Promise<TxReceipt> {
|
|
91
|
-
const receipt = await this.waitForReceipt(opts);
|
|
92
|
-
if (receipt.status !== TxStatus.SUCCESS && !opts?.dontThrowOnRevert) {
|
|
93
|
-
throw new Error(
|
|
94
|
-
`Transaction ${(await this.getTxHash()).toString()} was ${receipt.status}. Reason: ${receipt.error ?? 'unknown'}`,
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
return receipt;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
protected async waitForReceipt(opts?: WaitOpts): Promise<TxReceipt> {
|
|
101
|
-
const txHash = await this.getTxHash();
|
|
102
|
-
const startTime = Date.now();
|
|
103
|
-
const ignoreDroppedReceiptsFor = opts?.ignoreDroppedReceiptsFor ?? DefaultWaitOpts.ignoreDroppedReceiptsFor;
|
|
104
|
-
|
|
105
|
-
return await retryUntil(
|
|
106
|
-
async () => {
|
|
107
|
-
const txReceipt = await this.walletOrNode.getTxReceipt(txHash);
|
|
108
|
-
// If receipt is not yet available, try again
|
|
109
|
-
if (txReceipt.status === TxStatus.PENDING) {
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
// If the tx was "dropped", either return it or ignore based on timing.
|
|
113
|
-
// We can ignore it at first because the transaction may have been sent to node 1, and now we're asking node 2 for the receipt.
|
|
114
|
-
// If we don't allow a short grace period, we could incorrectly return a TxReceipt with status DROPPED.
|
|
115
|
-
if (txReceipt.status === TxStatus.DROPPED) {
|
|
116
|
-
const elapsedSeconds = (Date.now() - startTime) / 1000;
|
|
117
|
-
if (!ignoreDroppedReceiptsFor || elapsedSeconds > ignoreDroppedReceiptsFor) {
|
|
118
|
-
return txReceipt;
|
|
119
|
-
}
|
|
120
|
-
return undefined;
|
|
121
|
-
}
|
|
122
|
-
return txReceipt;
|
|
123
|
-
},
|
|
124
|
-
'isMined',
|
|
125
|
-
opts?.timeout ?? DefaultWaitOpts.timeout,
|
|
126
|
-
opts?.interval ?? DefaultWaitOpts.interval,
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
-
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
3
|
-
|
|
4
|
-
import type { Wallet } from '../wallet/wallet.js';
|
|
5
|
-
import { ContractBase } from './contract_base.js';
|
|
6
|
-
|
|
7
|
-
/** Unsafe constructor for ContractBase that bypasses the check that the instance is registered in the wallet. */
|
|
8
|
-
export class UnsafeContract extends ContractBase {
|
|
9
|
-
constructor(
|
|
10
|
-
/** The deployed contract instance definition. */
|
|
11
|
-
instance: ContractInstanceWithAddress,
|
|
12
|
-
/** The Application Binary Interface for the contract. */
|
|
13
|
-
artifact: ContractArtifact,
|
|
14
|
-
/** The wallet used for interacting with this contract. */
|
|
15
|
-
wallet: Wallet,
|
|
16
|
-
) {
|
|
17
|
-
super(instance.address, artifact, wallet);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ARTIFACT_FUNCTION_TREE_MAX_HEIGHT,
|
|
3
|
-
CONTRACT_CLASS_REGISTRY_BYTECODE_CAPSULE_SLOT,
|
|
4
|
-
MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
|
|
5
|
-
} from '@aztec/constants';
|
|
6
|
-
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
7
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
8
|
-
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
9
|
-
import { type ContractArtifact, FunctionSelector, FunctionType, bufferAsFields } from '@aztec/stdlib/abi';
|
|
10
|
-
import {
|
|
11
|
-
computeVerificationKeyHash,
|
|
12
|
-
createPrivateFunctionMembershipProof,
|
|
13
|
-
createUtilityFunctionMembershipProof,
|
|
14
|
-
getContractClassFromArtifact,
|
|
15
|
-
} from '@aztec/stdlib/contract';
|
|
16
|
-
import { Capsule } from '@aztec/stdlib/tx';
|
|
17
|
-
|
|
18
|
-
import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
19
|
-
import { getClassRegistryContract } from '../contract/protocol_contracts.js';
|
|
20
|
-
import type { Wallet } from '../wallet/index.js';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Sets up a call to broadcast a private function's bytecode via the ClassRegistry contract.
|
|
24
|
-
* Note that this is not required for users to call the function, but is rather a convenience to make
|
|
25
|
-
* this code publicly available so dapps or wallets do not need to redistribute it.
|
|
26
|
-
* @param wallet - Wallet to send the transaction.
|
|
27
|
-
* @param artifact - Contract artifact that contains the function to be broadcast.
|
|
28
|
-
* @param selector - Selector of the function to be broadcast.
|
|
29
|
-
* @returns A ContractFunctionInteraction object that can be used to send the transaction.
|
|
30
|
-
*/
|
|
31
|
-
export async function broadcastPrivateFunction(
|
|
32
|
-
wallet: Wallet,
|
|
33
|
-
artifact: ContractArtifact,
|
|
34
|
-
selector: FunctionSelector,
|
|
35
|
-
): Promise<ContractFunctionInteraction> {
|
|
36
|
-
const contractClass = await getContractClassFromArtifact(artifact);
|
|
37
|
-
const privateFunctions = artifact.functions.filter(fn => fn.functionType === FunctionType.PRIVATE);
|
|
38
|
-
const functionsAndSelectors = await Promise.all(
|
|
39
|
-
privateFunctions.map(async fn => ({
|
|
40
|
-
f: fn,
|
|
41
|
-
selector: await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters),
|
|
42
|
-
})),
|
|
43
|
-
);
|
|
44
|
-
const privateFunctionArtifact = functionsAndSelectors.find(fn => selector.equals(fn.selector))?.f;
|
|
45
|
-
if (!privateFunctionArtifact) {
|
|
46
|
-
throw new Error(`Private function with selector ${selector.toString()} not found`);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const {
|
|
50
|
-
artifactTreeSiblingPath,
|
|
51
|
-
artifactTreeLeafIndex,
|
|
52
|
-
artifactMetadataHash,
|
|
53
|
-
functionMetadataHash,
|
|
54
|
-
utilityFunctionsTreeRoot,
|
|
55
|
-
privateFunctionTreeSiblingPath,
|
|
56
|
-
privateFunctionTreeLeafIndex,
|
|
57
|
-
} = await createPrivateFunctionMembershipProof(selector, artifact);
|
|
58
|
-
|
|
59
|
-
const vkHash = await computeVerificationKeyHash(privateFunctionArtifact);
|
|
60
|
-
|
|
61
|
-
const classRegistry = await getClassRegistryContract(wallet);
|
|
62
|
-
const bytecode = bufferAsFields(
|
|
63
|
-
privateFunctionArtifact.bytecode,
|
|
64
|
-
MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
|
|
65
|
-
);
|
|
66
|
-
return classRegistry.methods
|
|
67
|
-
.broadcast_private_function(
|
|
68
|
-
contractClass.id,
|
|
69
|
-
artifactMetadataHash,
|
|
70
|
-
utilityFunctionsTreeRoot,
|
|
71
|
-
privateFunctionTreeSiblingPath,
|
|
72
|
-
privateFunctionTreeLeafIndex,
|
|
73
|
-
padArrayEnd(artifactTreeSiblingPath, Fr.ZERO, ARTIFACT_FUNCTION_TREE_MAX_HEIGHT),
|
|
74
|
-
artifactTreeLeafIndex,
|
|
75
|
-
// eslint-disable-next-line camelcase
|
|
76
|
-
{ selector, metadata_hash: functionMetadataHash, vk_hash: vkHash },
|
|
77
|
-
)
|
|
78
|
-
.with({
|
|
79
|
-
capsules: [
|
|
80
|
-
new Capsule(
|
|
81
|
-
ProtocolContractAddress.ContractClassRegistry,
|
|
82
|
-
new Fr(CONTRACT_CLASS_REGISTRY_BYTECODE_CAPSULE_SLOT),
|
|
83
|
-
bytecode,
|
|
84
|
-
),
|
|
85
|
-
],
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Sets up a call to broadcast a utility function's bytecode via the ClassRegistry contract.
|
|
91
|
-
* Note that this is not required for users to call the function, but is rather a convenience to make
|
|
92
|
-
* this code publicly available so dapps or wallets do not need to redistribute it.
|
|
93
|
-
* @param wallet - Wallet to send the transaction.
|
|
94
|
-
* @param artifact - Contract artifact that contains the function to be broadcast.
|
|
95
|
-
* @param selector - Selector of the function to be broadcast.
|
|
96
|
-
* @returns A ContractFunctionInteraction object that can be used to send the transaction.
|
|
97
|
-
*/
|
|
98
|
-
export async function broadcastUtilityFunction(
|
|
99
|
-
wallet: Wallet,
|
|
100
|
-
artifact: ContractArtifact,
|
|
101
|
-
selector: FunctionSelector,
|
|
102
|
-
): Promise<ContractFunctionInteraction> {
|
|
103
|
-
const contractClass = await getContractClassFromArtifact(artifact);
|
|
104
|
-
const utilityFunctions = artifact.functions.filter(fn => fn.functionType === FunctionType.UTILITY);
|
|
105
|
-
const utilityFunctionsAndSelectors = await Promise.all(
|
|
106
|
-
utilityFunctions.map(async fn => ({
|
|
107
|
-
f: fn,
|
|
108
|
-
selector: await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters),
|
|
109
|
-
})),
|
|
110
|
-
);
|
|
111
|
-
const utilityFunctionArtifact = utilityFunctionsAndSelectors.find(fn => selector.equals(fn.selector))?.f;
|
|
112
|
-
if (!utilityFunctionArtifact) {
|
|
113
|
-
throw new Error(`Utility function with selector ${selector.toString()} not found`);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const {
|
|
117
|
-
artifactMetadataHash,
|
|
118
|
-
artifactTreeLeafIndex,
|
|
119
|
-
artifactTreeSiblingPath,
|
|
120
|
-
functionMetadataHash,
|
|
121
|
-
privateFunctionsArtifactTreeRoot,
|
|
122
|
-
} = await createUtilityFunctionMembershipProof(selector, artifact);
|
|
123
|
-
|
|
124
|
-
const classRegistry = await getClassRegistryContract(wallet);
|
|
125
|
-
const bytecode = bufferAsFields(
|
|
126
|
-
utilityFunctionArtifact.bytecode,
|
|
127
|
-
MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
|
|
128
|
-
);
|
|
129
|
-
return classRegistry.methods
|
|
130
|
-
.broadcast_utility_function(
|
|
131
|
-
contractClass.id,
|
|
132
|
-
artifactMetadataHash,
|
|
133
|
-
privateFunctionsArtifactTreeRoot,
|
|
134
|
-
padArrayEnd(artifactTreeSiblingPath, Fr.ZERO, ARTIFACT_FUNCTION_TREE_MAX_HEIGHT),
|
|
135
|
-
artifactTreeLeafIndex,
|
|
136
|
-
// eslint-disable-next-line camelcase
|
|
137
|
-
{ selector, metadata_hash: functionMetadataHash },
|
|
138
|
-
)
|
|
139
|
-
.with({
|
|
140
|
-
capsules: [
|
|
141
|
-
new Capsule(
|
|
142
|
-
ProtocolContractAddress.ContractClassRegistry,
|
|
143
|
-
new Fr(CONTRACT_CLASS_REGISTRY_BYTECODE_CAPSULE_SLOT),
|
|
144
|
-
bytecode,
|
|
145
|
-
),
|
|
146
|
-
],
|
|
147
|
-
});
|
|
148
|
-
}
|