Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion yarn-project/types/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('@aztec/foundation/eslint-legacy');
module.exports = require('@aztec/foundation/eslint');
3 changes: 2 additions & 1 deletion yarn-project/types/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Unverified Data
# Types
A package containing types which are relevant through all the Aztec Typescript codebase (L2Block, Tx etc.).
43 changes: 34 additions & 9 deletions yarn-project/types/src/contract_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FUNCTION_SELECTOR_NUM_BYTES } from '@aztec/circuits.js';
export { BufferReader } from '@aztec/circuits.js/utils';

/**
* Used for retrieval of contract data (A3 address, portal contract address, bytecode)
* Used for retrieval of contract data (A3 address, portal contract address, bytecode).
*/
export interface ContractDataSource {
/**
Expand All @@ -27,42 +27,67 @@ export interface ContractDataSource {

/**
* Lookup all contract public data in an L2 block.
* @param blockNumber - The block number
* @param blockNumber - The block number.
* @returns Public data of contracts deployed in L2 block, including public function bytecode.
*/
getL2ContractPublicDataInBlock(blockNumber: number): Promise<ContractPublicData[]>;

/**
* Lookup contract info in an L2 block.
* @param blockNumber - The block number
* @param blockNumber - The block number.
* @returns Portal contract address info of contracts deployed in L2 block.
*/
getL2ContractInfoInBlock(blockNumber: number): Promise<ContractData[] | undefined>;

/**
* Returns a contract's encoded public function, given its function selector.
* @param address - The contract aztec address.
* @param functionSelector - The function's selector
* @param functionSelector - The function's selector.
* @returns The function's data.
*/
getPublicFunction(address: AztecAddress, functionSelector: Buffer): Promise<EncodedContractFunction | undefined>;
}

/**
* Represents encoded contract function.
*/
export class EncodedContractFunction {
constructor(public functionSelector: Buffer, public bytecode: Buffer) {}
constructor(
/**
* The function selector.
*/
public functionSelector: Buffer,
/**
* The function bytecode.
*/
public bytecode: Buffer,
) {}

toBuffer() {
/**
* Serializes this instance into a buffer.
* @returns Encoded buffer.
*/
toBuffer(): Buffer {
const bytecodeBuf = Buffer.concat([numToInt32BE(this.bytecode.length), this.bytecode]);
return serializeToBuffer(this.functionSelector, bytecodeBuf);
}

static fromBuffer(buffer: Buffer | BufferReader) {
/**
* Deserializes a contract function object from an encoded buffer.
* @param buffer - The encoded buffer.
* @returns The deserialized contract function.
*/
static fromBuffer(buffer: Buffer | BufferReader): EncodedContractFunction {
const reader = BufferReader.asReader(buffer);
const fnSelector = reader.readBytes(FUNCTION_SELECTOR_NUM_BYTES);
return new EncodedContractFunction(fnSelector, reader.readBuffer());
}

static random() {
/**
* Creates a random contract function.
* @returns A random contract function.
*/
static random(): EncodedContractFunction {
return new EncodedContractFunction(randomBytes(4), randomBytes(64));
}
}
Expand All @@ -82,7 +107,7 @@ export class ContractPublicData {
public contractData: ContractData,

/**
* ABIs of public functions
* ABIs of public functions.
*/
public publicFunctions: EncodedContractFunction[],
) {
Expand Down
12 changes: 12 additions & 0 deletions yarn-project/types/src/create_tx_hash.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import { Fr, keccak } from '@aztec/foundation';
import { TxHash } from './tx_hash.js';

/**
* Defines transaction data.
*/
interface TxData {
/**
* Commitments to be inserted into a private data tree that are created in the transaction.
*/
newCommitments: Fr[];
/**
* Nullifiers to be inserted into a nullifier tree that are created in the transaction.
*/
newNullifiers: Fr[];
/**
* Contractc leaves to be inserted into a contract tree that are created in the transaction.
*/
newContracts: Fr[];
}

Expand Down
Loading