-
Notifications
You must be signed in to change notification settings - Fork 304
/
Copy pathregister_class.ts
19 lines (17 loc) · 1 KB
/
register_class.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS, getContractClassFromArtifact } from '@aztec/circuits.js';
import { ContractArtifact, bufferAsFields } from '@aztec/foundation/abi';
import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
import { Wallet } from '../wallet/index.js';
import { getRegistererContract } from './protocol_contracts.js';
/** Sets up a call to register a contract class given its artifact. */
export async function registerContractClass(
wallet: Wallet,
artifact: ContractArtifact,
): Promise<ContractFunctionInteraction> {
const { artifactHash, privateFunctionsRoot, publicBytecodeCommitment, packedBytecode } =
getContractClassFromArtifact(artifact);
const encodedBytecode = bufferAsFields(packedBytecode, MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS);
const registerer = getRegistererContract(wallet);
await wallet.addCapsule(encodedBytecode);
return registerer.methods.register(artifactHash, privateFunctionsRoot, publicBytecodeCommitment);
}