diff --git a/README.md b/README.md index dd0fad7..3242e8c 100644 --- a/README.md +++ b/README.md @@ -38,11 +38,12 @@ import { WALLET_API } from '@starknet-io/types-js'; - /src/wallet-api/typedData.ts -## Versioning (pending SPEC PR merge) +## Versioning -(MAJOR.MINOR) Version of this package should follow [starknet-spec](https://github.com/starkware-libs/starknet-specs) semantic versioning. -PATCH version can diverge based on bug-fixes -ex. Starknet types v0.7.x <-> Starknet Spec v0.7.x +Starknet types-js v0.7 == Starknet Spec v0.7 +Starknet types-js v0.8 == Starknet Spec v0.8 + +(MAJOR.MINOR) Version of this package follow [starknet-spec](https://github.com/starkware-libs/starknet-specs) semantic versioning. PATCH version can diverge based on bug-fixes ## Devs Build diff --git a/src/api/components.ts b/src/api/components.ts index 90c8f3d..22b94c4 100644 --- a/src/api/components.ts +++ b/src/api/components.ts @@ -1,10 +1,36 @@ -// TODO: To be completed in future revisions -// This is in API SPEC extracted from starknetjs RPC 0.8rc0 components.ts - // ****************** // * PRIMITIVES // ****************** +import type { + ABI_TYPE_CONSTRUCTOR, + ABI_TYPE_FUNCTION, + ABI_TYPE_L1_HANDLER, + CALL_TYPE, + EBlockTag, + EDataAvailabilityMode, + ESimulationFlag, + ETransactionVersion, + EVENT_ABI_TYPE, + L1_DA_MODE, + PRICE_UNIT_FRI, + PRICE_UNIT_WEI, + STATE_MUTABILITY_EXTERNAL, + STATE_MUTABILITY_VIEW, + STATUS_ACCEPTED_ON_L1, + STATUS_ACCEPTED_ON_L2, + STATUS_PENDING, + STATUS_RECEIVED, + STATUS_REJECTED, + STATUS_REVERTED, + STATUS_SUCCEEDED, + STRUCT_ABI_TYPE, + TXN_TYPE_DECLARE, + TXN_TYPE_DEPLOY, + TXN_TYPE_DEPLOY_ACCOUNT, + TXN_TYPE_INVOKE, +} from './constants.js'; + /** * A field element. represented by at most 63 hex digits * @pattern ^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$ @@ -44,34 +70,57 @@ export type TXN_HASH = FELT; */ export type L1_TXN_HASH = NUM_AS_HEX; export type CHAIN_ID = NUM_AS_HEX; -export type STRUCT_ABI_TYPE = 'struct'; -export type EVENT_ABI_TYPE = 'event'; -export type FUNCTION_ABI_TYPE = 'function' | 'l1_handler' | 'constructor'; +export type STATE_MUTABILITY = STATE_MUTABILITY_VIEW | STATE_MUTABILITY_EXTERNAL; +export type FUNCTION_ABI_TYPE = ABI_TYPE_FUNCTION | ABI_TYPE_L1_HANDLER | ABI_TYPE_CONSTRUCTOR; /** - * Represents the type of an entry point. + * common definition */ -export type ENTRY_POINT_TYPE = 'EXTERNAL' | 'L1_HANDLER' | 'CONSTRUCTOR'; +export type ABI_NAME_AND_TYPE = { name: string; type: string }; /** - * Represents the type of a function call. + * common outputs */ -export type CALL_TYPE = 'DELEGATE' | 'LIBRARY_CALL' | 'CALL'; +export type ABI_TYPE = { type: string }; +/** + * Represents the type of an entry point. + */ +export type ENTRY_POINT_TYPE = + | Uppercase + | Uppercase + | Uppercase; + /** * Represents the finality status of the transaction, including the case the txn is still in the mempool or failed validation during the block construction phase */ -export type TXN_STATUS = 'RECEIVED' | 'REJECTED' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1'; +export type TXN_STATUS = + | STATUS_RECEIVED + | STATUS_REJECTED + | STATUS_ACCEPTED_ON_L2 + | STATUS_ACCEPTED_ON_L1; /** * Flags that indicate how to simulate a given transaction. By default, the sequencer behavior is replicated locally (enough funds are expected to be in the account, and the fee will be deducted from the balance before the simulation of the next transaction). To skip the fee charge, use the SKIP_FEE_CHARGE flag. */ -export type SIMULATION_FLAG = 'SKIP_VALIDATE' | 'SKIP_FEE_CHARGE'; +export type SIMULATION_FLAG = + | typeof ESimulationFlag.SKIP_VALIDATE + | typeof ESimulationFlag.SKIP_FEE_CHARGE; /** - * Data availability mode + * Data availability mode. + * Specifies a storage domain in Starknet. Each domain has different guarantees regarding availability */ -export type DA_MODE = 'L1' | 'L2'; -export type TXN_TYPE = 'DECLARE' | 'DEPLOY' | 'DEPLOY_ACCOUNT' | 'INVOKE' | 'L1_HANDLER'; -export type TXN_FINALITY_STATUS = 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1'; -export type TXN_EXECUTION_STATUS = 'SUCCEEDED' | 'REVERTED'; -export type BLOCK_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED'; -export type BLOCK_TAG = 'latest' | 'pending'; +export type DA_MODE = EDataAvailabilityMode; +export type TXN_TYPE = + | TXN_TYPE_DECLARE + | TXN_TYPE_DEPLOY + | TXN_TYPE_DEPLOY_ACCOUNT + | TXN_TYPE_INVOKE + | Uppercase; +export type TXN_FINALITY_STATUS = STATUS_ACCEPTED_ON_L2 | STATUS_ACCEPTED_ON_L1; +export type TXN_EXECUTION_STATUS = STATUS_SUCCEEDED | STATUS_REVERTED; +export type BLOCK_STATUS = + | STATUS_PENDING + | STATUS_ACCEPTED_ON_L2 + | STATUS_ACCEPTED_ON_L1 + | STATUS_REJECTED; +export type BLOCK_TAG = EBlockTag; // ***************** // * WEBSOCKET API @@ -240,9 +289,9 @@ export type BLOCK_HEADER = { timestamp: number; sequencer_address: FELT; l1_gas_price: RESOURCE_PRICE; - l2_gas_price?: RESOURCE_PRICE; + l2_gas_price: RESOURCE_PRICE; l1_data_gas_price: RESOURCE_PRICE; - l1_da_mode: 'BLOB' | 'CALLDATA'; + l1_da_mode: L1_DA_MODE; starknet_version: string; }; @@ -251,8 +300,9 @@ export type PENDING_BLOCK_HEADER = { timestamp: number; sequencer_address: FELT; l1_gas_price: RESOURCE_PRICE; + l2_gas_price: RESOURCE_PRICE; l1_data_gas_price: RESOURCE_PRICE; - l1_da_mode: 'BLOB' | 'CALLDATA'; + l1_da_mode: L1_DA_MODE; starknet_version: string; }; @@ -279,9 +329,9 @@ export type DEPLOYED_CONTRACT_ITEM = { export type CONTRACT_STORAGE_DIFF_ITEM = { /** - * The contract address for which the storage changed (in FELT format) + * The contract address for which the storage changed */ - address: string; + address: FELT; /** * The changes in the storage of the contract */ @@ -290,13 +340,13 @@ export type CONTRACT_STORAGE_DIFF_ITEM = { export type StorageDiffItem = { /** - * The key of the changed value (in FELT format) + * The key of the changed value */ - key: string; + key: FELT; /** - * The new value applied to the given address (in FELT format) + * The new value applied to the given address */ - value: string; + value: FELT; }; export type TXN = INVOKE_TXN | L1_HANDLER_TXN | DECLARE_TXN | DEPLOY_TXN | DEPLOY_ACCOUNT_TXN; @@ -304,40 +354,40 @@ export type TXN = INVOKE_TXN | L1_HANDLER_TXN | DECLARE_TXN | DEPLOY_TXN | DEPLO export type DECLARE_TXN = DECLARE_TXN_V0 | DECLARE_TXN_V1 | DECLARE_TXN_V2 | DECLARE_TXN_V3; export type DECLARE_TXN_V0 = { - type: 'DECLARE'; + type: TXN_TYPE_DECLARE; sender_address: ADDRESS; max_fee: FELT; - version: '0x0' | '0x100000000000000000000000000000000'; + version: typeof ETransactionVersion.V0 | typeof ETransactionVersion.F0; signature: SIGNATURE; class_hash: FELT; }; export type DECLARE_TXN_V1 = { - type: 'DECLARE'; + type: TXN_TYPE_DECLARE; sender_address: ADDRESS; max_fee: FELT; - version: '0x1' | '0x100000000000000000000000000000001'; + version: typeof ETransactionVersion.V1 | typeof ETransactionVersion.F1; signature: SIGNATURE; nonce: FELT; class_hash: FELT; }; export type DECLARE_TXN_V2 = { - type: 'DECLARE'; + type: TXN_TYPE_DECLARE; sender_address: ADDRESS; compiled_class_hash: FELT; max_fee: FELT; - version: '0x2' | '0x100000000000000000000000000000002'; + version: typeof ETransactionVersion.V2 | typeof ETransactionVersion.F2; signature: SIGNATURE; nonce: FELT; class_hash: FELT; }; export type DECLARE_TXN_V3 = { - type: 'DECLARE'; + type: TXN_TYPE_DECLARE; sender_address: ADDRESS; compiled_class_hash: FELT; - version: '0x3' | '0x100000000000000000000000000000003'; + version: typeof ETransactionVersion.V3 | typeof ETransactionVersion.F3; signature: SIGNATURE; nonce: FELT; class_hash: FELT; @@ -365,32 +415,31 @@ export type BROADCASTED_DECLARE_TXN = | BROADCASTED_DECLARE_TXN_V3; export type BROADCASTED_DECLARE_TXN_V1 = { - type: 'DECLARE'; + type: TXN_TYPE_DECLARE; sender_address: ADDRESS; max_fee: FELT; - // todo: check if working, prev i fixed it with NUM_AS_HEX - version: '0x1' | '0x100000000000000000000000000000001'; + version: typeof ETransactionVersion.V1 | typeof ETransactionVersion.F1; signature: SIGNATURE; nonce: FELT; contract_class: DEPRECATED_CONTRACT_CLASS; }; export type BROADCASTED_DECLARE_TXN_V2 = { - type: 'DECLARE'; + type: TXN_TYPE_DECLARE; sender_address: ADDRESS; compiled_class_hash: FELT; max_fee: FELT; - version: '0x2' | '0x100000000000000000000000000000002'; + version: typeof ETransactionVersion.V2 | typeof ETransactionVersion.F2; signature: SIGNATURE; nonce: FELT; contract_class: CONTRACT_CLASS; }; export type BROADCASTED_DECLARE_TXN_V3 = { - type: 'DECLARE'; + type: TXN_TYPE_DECLARE; sender_address: ADDRESS; compiled_class_hash: FELT; - version: '0x3' | '0x100000000000000000000000000000003'; + version: typeof ETransactionVersion.V3 | typeof ETransactionVersion.F3; signature: SIGNATURE; nonce: FELT; contract_class: CONTRACT_CLASS; @@ -406,9 +455,9 @@ export type BROADCASTED_DECLARE_TXN_V3 = { export type DEPLOY_ACCOUNT_TXN = DEPLOY_ACCOUNT_TXN_V1 | DEPLOY_ACCOUNT_TXN_V3; export type DEPLOY_ACCOUNT_TXN_V1 = { - type: 'DEPLOY_ACCOUNT'; + type: TXN_TYPE_DEPLOY_ACCOUNT; max_fee: FELT; - version: '0x1' | '0x100000000000000000000000000000001'; + version: typeof ETransactionVersion.V1 | typeof ETransactionVersion.F1; signature: SIGNATURE; nonce: FELT; contract_address_salt: FELT; @@ -417,8 +466,8 @@ export type DEPLOY_ACCOUNT_TXN_V1 = { }; export type DEPLOY_ACCOUNT_TXN_V3 = { - type: 'DEPLOY_ACCOUNT'; - version: '0x3' | '0x100000000000000000000000000000003'; + type: TXN_TYPE_DEPLOY_ACCOUNT; + version: typeof ETransactionVersion.V3 | typeof ETransactionVersion.F3; signature: SIGNATURE; nonce: FELT; contract_address_salt: FELT; @@ -432,7 +481,7 @@ export type DEPLOY_ACCOUNT_TXN_V3 = { }; export type DEPLOY_TXN = { - type: 'DEPLOY'; + type: TXN_TYPE_DEPLOY; version: FELT; contract_address_salt: FELT; constructor_calldata: FELT[]; @@ -442,9 +491,9 @@ export type DEPLOY_TXN = { export type INVOKE_TXN = INVOKE_TXN_V0 | INVOKE_TXN_V1 | INVOKE_TXN_V3; export type INVOKE_TXN_V0 = { - type: 'INVOKE'; + type: TXN_TYPE_INVOKE; max_fee: FELT; - version: '0x0' | '0x100000000000000000000000000000000'; + version: typeof ETransactionVersion.V0 | typeof ETransactionVersion.F0; signature: SIGNATURE; contract_address: ADDRESS; entry_point_selector: FELT; @@ -452,20 +501,20 @@ export type INVOKE_TXN_V0 = { }; export type INVOKE_TXN_V1 = { - type: 'INVOKE'; + type: TXN_TYPE_INVOKE; sender_address: ADDRESS; calldata: FELT[]; max_fee: FELT; - version: '0x1' | '0x100000000000000000000000000000001'; + version: typeof ETransactionVersion.V1 | typeof ETransactionVersion.F1; signature: SIGNATURE; nonce: FELT; }; export type INVOKE_TXN_V3 = { - type: 'INVOKE'; + type: TXN_TYPE_INVOKE; sender_address: ADDRESS; calldata: FELT[]; - version: '0x3' | '0x100000000000000000000000000000003'; + version: typeof ETransactionVersion.V3 | typeof ETransactionVersion.F3; signature: SIGNATURE; nonce: FELT; resource_bounds: RESOURCE_BOUNDS_MAPPING; @@ -477,8 +526,8 @@ export type INVOKE_TXN_V3 = { }; export type L1_HANDLER_TXN = { - version: '0x0'; - type: 'L1_HANDLER'; + version: typeof ETransactionVersion.V0; + type: Uppercase; nonce: NUM_AS_HEX; } & FUNCTION_CALL; @@ -492,34 +541,34 @@ export type COMMON_RECEIPT_PROPERTIES = { } & (SUCCESSFUL_COMMON_RECEIPT_PROPERTIES | REVERTED_COMMON_RECEIPT_PROPERTIES); type SUCCESSFUL_COMMON_RECEIPT_PROPERTIES = { - execution_status: 'SUCCEEDED'; + execution_status: STATUS_SUCCEEDED; }; type REVERTED_COMMON_RECEIPT_PROPERTIES = { - execution_status: 'REVERTED'; + execution_status: STATUS_REVERTED; revert_reason: string; }; export type INVOKE_TXN_RECEIPT = { - type: 'INVOKE'; + type: TXN_TYPE_INVOKE; } & COMMON_RECEIPT_PROPERTIES; export type DECLARE_TXN_RECEIPT = { - type: 'DECLARE'; + type: TXN_TYPE_DECLARE; } & COMMON_RECEIPT_PROPERTIES; export type DEPLOY_ACCOUNT_TXN_RECEIPT = { - type: 'DEPLOY_ACCOUNT'; + type: TXN_TYPE_DEPLOY_ACCOUNT; contract_address: FELT; } & COMMON_RECEIPT_PROPERTIES; export type DEPLOY_TXN_RECEIPT = { - type: 'DEPLOY'; + type: TXN_TYPE_DEPLOY; contract_address: FELT; } & COMMON_RECEIPT_PROPERTIES; export type L1_HANDLER_TXN_RECEIPT = { - type: 'L1_HANDLER'; + type: Uppercase; message_hash: NUM_AS_HEX; } & COMMON_RECEIPT_PROPERTIES; @@ -587,47 +636,79 @@ export type SIERRA_ENTRY_POINT = { export type CONTRACT_ABI = readonly CONTRACT_ABI_ENTRY[]; -export type CONTRACT_ABI_ENTRY = { - selector: FELT; - input: string; - output: string; -}; +export type CONTRACT_ABI_ENTRY = FUNCTION_ABI_ENTRY | EVENT_ABI_ENTRY | STRUCT_ABI_ENTRY; export type STRUCT_ABI_ENTRY = { + /** + * Struct ABI type + */ type: STRUCT_ABI_TYPE; + /** + * Struct name + */ name: string; size: number; members: STRUCT_MEMBER[]; }; export type STRUCT_MEMBER = TYPED_PARAMETER & { + /** + * offset of this property within the struct + */ offset: number; }; export type EVENT_ABI_ENTRY = { + /** + * Event ABI type + */ type: EVENT_ABI_TYPE; + /** + * Event name + */ name: string; keys: TYPED_PARAMETER[]; data: TYPED_PARAMETER[]; }; -export type FUNCTION_STATE_MUTABILITY = 'view'; +export type FUNCTION_STATE_MUTABILITY = STATE_MUTABILITY_VIEW; export type FUNCTION_ABI_ENTRY = { + /** + * Function ABI type + */ type: FUNCTION_ABI_TYPE; + /** + * Function name + */ name: string; + /** + * Typed parameter + */ inputs: TYPED_PARAMETER[]; + /** + * Typed parameter + */ outputs: TYPED_PARAMETER[]; - stateMutability: FUNCTION_STATE_MUTABILITY; + /** + * Function state mutability + */ + stateMutability?: FUNCTION_STATE_MUTABILITY; }; export type TYPED_PARAMETER = { + /** + * Parameter name + */ name: string; + /** + * Parameter type + */ type: string; }; -export type SIMULATION_FLAG_FOR_ESTIMATE_FEE = 'SKIP_VALIDATE'; -export type PRICE_UNIT = 'WEI' | 'FRI'; +export type SIMULATION_FLAG_FOR_ESTIMATE_FEE = typeof ESimulationFlag.SKIP_VALIDATE; +export type PRICE_UNIT = PRICE_UNIT_WEI | PRICE_UNIT_FRI; export type FEE_ESTIMATE = { /** @@ -668,7 +749,17 @@ export type FEE_PAYMENT = { }; export type RESOURCE_BOUNDS_MAPPING = { + /** + * The max amount and max price per unit of L1 gas used in this tx + */ l1_gas: RESOURCE_BOUNDS; + /** + * The max amount and max price per unit of L1 blob gas used in this tx + */ + l1_data_gas: RESOURCE_BOUNDS; + /** + * The max amount and max price per unit of L2 gas used in this tx + */ l2_gas: RESOURCE_BOUNDS; }; @@ -682,26 +773,6 @@ export type RESOURCE_PRICE = { price_in_wei: FELT; }; -/* export type COMPUTATION_RESOURCES = { - steps: number; - memory_holes?: number; - range_check_builtin_applications?: number; - pedersen_builtin_applications?: number; - poseidon_builtin_applications?: number; - ec_op_builtin_applications?: number; - ecdsa_builtin_applications?: number; - bitwise_builtin_applications?: number; - keccak_builtin_applications?: number; - segment_arena_builtin?: number; -}; - -export type EXECUTION_RESOURCES = COMPUTATION_RESOURCES & { - data_availability: { - l1_gas: number; - l1_data_gas: number; - }; -}; */ - /** * the resources consumed by the transaction */ @@ -723,27 +794,45 @@ export type EXECUTION_RESOURCES = { l2_gas: number; }; -export type MERKLE_NODE = { +/** + * a node in the Merkle-Patricia tree, can be a leaf, binary node, or an edge node + */ +export type MERKLE_NODE = BINARY_NODE | EDGE_NODE; + +/** + * an internal node whose both children are non-zero + */ +export type BINARY_NODE = { + /** + * the hash of the left child + */ + left: FELT; + /** + * the hash of the right child + */ + right: FELT; +}; + +/** + * represents a path to the highest non-zero descendant node + */ +export type EDGE_NODE = { /** - * Integer + * an integer whose binary representation represents the path from the current node to its highest non-zero descendant (bounded by 2^251) */ - path: number; + path: NUM_AS_HEX; /** - * Integer + * the length of the path (bounded by 251) */ length: number; - value: FELT; /** - * the hash of the child nodes, if not present then the node is a leaf + * the hash of the unique non-zero maximal-height descendant node */ - children_hashes?: { - left: FELT; - right: FELT; - }; + child: FELT; }; /** - * a node_hash -> node mapping of all the nodes in the union of the paths between the requested leaves and the root (for each node present, its sibling is also present) + * a node_hash -> node mapping of all the nodes in the union of the paths between the requested leaves and the root */ export type NODE_HASH_TO_NODE_MAPPING = Array<{ node_hash: FELT; node: MERKLE_NODE }>; @@ -751,7 +840,13 @@ export type NODE_HASH_TO_NODE_MAPPING = Array<{ node_hash: FELT; node: MERKLE_NO * structured error that can later be processed by wallets or sdks. * error frame or the error raised during execution */ -export type CONTRACT_EXECUTION_ERROR = +export type CONTRACT_EXECUTION_ERROR = CONTRACT_EXECUTION_ERROR_INNER; + +/** + * structured error that can later be processed by wallets or sdks. + * error frame or the error raised during execution + */ +export type CONTRACT_EXECUTION_ERROR_INNER = | { contract_address: ADDRESS; class_hash: FELT; @@ -778,7 +873,7 @@ export type TRANSACTION_TRACE = { * Represents a transaction trace for an invoke transaction. */ export type INVOKE_TXN_TRACE = { - type: 'INVOKE'; + type: TXN_TYPE_INVOKE; execute_invocation: FUNCTION_INVOCATION | { revert_reason: string }; validate_invocation?: FUNCTION_INVOCATION; fee_transfer_invocation?: FUNCTION_INVOCATION; @@ -790,7 +885,7 @@ export type INVOKE_TXN_TRACE = { * Represents a transaction trace for a declare transaction. */ export type DECLARE_TXN_TRACE = { - type: 'DECLARE'; + type: TXN_TYPE_DECLARE; validate_invocation?: FUNCTION_INVOCATION; fee_transfer_invocation?: FUNCTION_INVOCATION; state_diff?: STATE_DIFF; @@ -801,7 +896,7 @@ export type DECLARE_TXN_TRACE = { * Represents a transaction trace for a deploy account transaction. */ export type DEPLOY_ACCOUNT_TXN_TRACE = { - type: 'DEPLOY_ACCOUNT'; + type: TXN_TYPE_DEPLOY_ACCOUNT; constructor_invocation: FUNCTION_INVOCATION; validate_invocation?: FUNCTION_INVOCATION; fee_transfer_invocation?: FUNCTION_INVOCATION; @@ -813,7 +908,7 @@ export type DEPLOY_ACCOUNT_TXN_TRACE = { * Represents a transaction trace for an L1 handler transaction. */ export type L1_HANDLER_TXN_TRACE = { - type: 'L1_HANDLER'; + type: Uppercase; function_invocation: FUNCTION_INVOCATION; state_diff?: STATE_DIFF; execution_resources: EXECUTION_RESOURCES; @@ -828,15 +923,50 @@ export type NESTED_CALL = FUNCTION_INVOCATION; * Represents a function invocation along with its execution details. */ export type FUNCTION_INVOCATION = FUNCTION_CALL & { - caller_address: string; - class_hash: string; + /** + * The address of the invoking contract. 0 for the root invocation + */ + caller_address: FELT; + /** + * The hash of the class being called + */ + class_hash: FELT; entry_point_type: ENTRY_POINT_TYPE; call_type: CALL_TYPE; - result: string[]; + /** + * The value returned from the function invocation + */ + result: FELT[]; + /** + * The calls made by this invocation + */ calls: NESTED_CALL[]; + /** + * The events emitted in this invocation + */ events: ORDERED_EVENT[]; + /** + * The messages sent by this invocation to L1 + */ messages: ORDERED_MESSAGE[]; - execution_resources: any; // COMPUTATION_RESOURCES; // TODO: kad bude rpc spreman popravit + /** + * Resources consumed by the internal call + */ + execution_resources: INNER_CALL_EXECUTION_RESOURCES; +}; + +/** + * the resources consumed by an inner call (does not account for state diffs since data is squashed across the transaction) + */ +export type INNER_CALL_EXECUTION_RESOURCES = { + /** + * l1 gas consumed by this transaction, used for l2-->l1 messages and state updates if blobs are not used + */ + l1_gas: number; + /** + * l2 gas consumed by this transaction, used for computation and calldata + */ + l2_gas: number; }; /** @@ -866,3 +996,11 @@ export type TXN_STATUS_RESULT = { */ failure_reason?: string; }; + +/** + * (contract_address, storage_keys) pairs + */ +export type CONTRACT_STORAGE_KEYS = { + contract_address: ADDRESS; + storage_keys: FELT[]; +}; diff --git a/src/api/constants.ts b/src/api/constants.ts new file mode 100644 index 0000000..ed3440d --- /dev/null +++ b/src/api/constants.ts @@ -0,0 +1,189 @@ +export type STATUS_ACCEPTED_ON_L2 = 'ACCEPTED_ON_L2'; +export const STATUS_ACCEPTED_ON_L2 = 'ACCEPTED_ON_L2'; + +export type STATUS_ACCEPTED_ON_L1 = 'ACCEPTED_ON_L1'; +export const STATUS_ACCEPTED_ON_L1 = 'ACCEPTED_ON_L1'; + +export type STATUS_SUCCEEDED = 'SUCCEEDED'; +export const STATUS_SUCCEEDED = 'SUCCEEDED'; + +export type STATUS_REVERTED = 'REVERTED'; +export const STATUS_REVERTED = 'REVERTED'; + +export type STATUS_PENDING = 'PENDING'; +export const STATUS_PENDING = 'PENDING'; + +export type STATUS_REJECTED = 'REJECTED'; +export const STATUS_REJECTED = 'REJECTED'; + +export type STATUS_RECEIVED = 'RECEIVED'; +export const STATUS_RECEIVED = 'RECEIVED'; + +export type TXN_TYPE_DECLARE = 'DECLARE'; +export const TXN_TYPE_DECLARE = 'DECLARE'; + +export type TXN_TYPE_DEPLOY = 'DEPLOY'; +export const TXN_TYPE_DEPLOY = 'DEPLOY'; + +export type TXN_TYPE_DEPLOY_ACCOUNT = 'DEPLOY_ACCOUNT'; +export const TXN_TYPE_DEPLOY_ACCOUNT = 'DEPLOY_ACCOUNT'; + +export type TXN_TYPE_INVOKE = 'INVOKE'; +export const TXN_TYPE_INVOKE = 'INVOKE'; + +export type TXN_TYPE_L1_HANDLER = 'L1_HANDLER'; +export const TXN_TYPE_L1_HANDLER = 'L1_HANDLER'; + +export type STRUCT_ABI_TYPE = 'struct'; +export const STRUCT_ABI_TYPE = 'struct'; + +export type EVENT_ABI_TYPE = 'event'; +export const EVENT_ABI_TYPE = 'event'; + +export type ABI_TYPE_FUNCTION = 'function'; +export const ABI_TYPE_FUNCTION = 'function'; + +export type ABI_TYPE_CONSTRUCTOR = 'constructor'; +export const ABI_TYPE_CONSTRUCTOR = 'constructor'; + +export type ABI_TYPE_L1_HANDLER = 'l1_handler'; +export const ABI_TYPE_L1_HANDLER = 'l1_handler'; + +export type ABI_TYPE_ENUM = 'enum'; +export const ABI_TYPE_ENUM = 'enum'; + +export type STATE_MUTABILITY_VIEW = 'view'; +export const STATE_MUTABILITY_VIEW = 'view'; + +export type STATE_MUTABILITY_EXTERNAL = 'external'; +export const STATE_MUTABILITY_EXTERNAL = 'external'; + +export type PRICE_UNIT_WEI = 'WEI'; +export const PRICE_UNIT_WEI = 'WEI'; + +export type PRICE_UNIT_FRI = 'FRI'; +export const PRICE_UNIT_FRI = 'FRI'; + +export const L1_DA_MODE = { + BLOB: 'BLOB', + CALLDATA: 'CALLDATA', +} as const; +export type L1_DA_MODE = (typeof L1_DA_MODE)[keyof typeof L1_DA_MODE]; + +/** + * Represents the type of a function call. + */ +export const CALL_TYPE = { + DELEGATE: 'DELEGATE', + LIBRARY_CALL: 'LIBRARY_CALL', + CALL: 'CALL', +} as const; +export type CALL_TYPE = (typeof CALL_TYPE)[keyof typeof CALL_TYPE]; + +// Enums Derived From Spec Types (require manual check for changes) +export const ETransactionType = { + DECLARE: TXN_TYPE_DECLARE, + DEPLOY: TXN_TYPE_DEPLOY, + DEPLOY_ACCOUNT: TXN_TYPE_DEPLOY_ACCOUNT, + INVOKE: TXN_TYPE_INVOKE, + L1_HANDLER: TXN_TYPE_L1_HANDLER, +} as const; + +export type ETransactionType = (typeof ETransactionType)[keyof typeof ETransactionType]; + +export const ESimulationFlag = { + SKIP_VALIDATE: 'SKIP_VALIDATE', + SKIP_FEE_CHARGE: 'SKIP_FEE_CHARGE', +} as const; + +export type ESimulationFlag = (typeof ESimulationFlag)[keyof typeof ESimulationFlag]; + +export const ETransactionStatus = { + RECEIVED: STATUS_RECEIVED, + REJECTED: STATUS_REJECTED, + ACCEPTED_ON_L2: STATUS_ACCEPTED_ON_L2, + ACCEPTED_ON_L1: STATUS_ACCEPTED_ON_L1, +} as const; + +export type ETransactionStatus = (typeof ETransactionStatus)[keyof typeof ETransactionStatus]; + +export const ETransactionFinalityStatus = { + ACCEPTED_ON_L2: STATUS_ACCEPTED_ON_L2, + ACCEPTED_ON_L1: STATUS_ACCEPTED_ON_L1, +} as const; + +export type ETransactionFinalityStatus = + (typeof ETransactionFinalityStatus)[keyof typeof ETransactionFinalityStatus]; + +export const ETransactionExecutionStatus = { + SUCCEEDED: STATUS_SUCCEEDED, + REVERTED: STATUS_REVERTED, +} as const; + +export type ETransactionExecutionStatus = + (typeof ETransactionExecutionStatus)[keyof typeof ETransactionExecutionStatus]; + +export const EBlockTag = { + LATEST: 'latest', + PENDING: 'pending', +} as const; + +export type EBlockTag = (typeof EBlockTag)[keyof typeof EBlockTag]; + +// 'L1' | 'L2' +export const EDataAvailabilityMode = { + L1: 'L1', + L2: 'L2', +} as const; + +export type EDataAvailabilityMode = + (typeof EDataAvailabilityMode)[keyof typeof EDataAvailabilityMode]; + +// 0 | 1 +export const EDAMode = { + L1: 0, + L2: 1, +} as const; + +export type EDAMode = (typeof EDAMode)[keyof typeof EDAMode]; + +/** + * V_ Transaction versions HexString + * F_ Fee Transaction Versions HexString (2 ** 128 + TRANSACTION_VERSION) + */ +export const ETransactionVersion = { + V0: '0x0', + V1: '0x1', + V2: '0x2', + V3: '0x3', + F0: '0x100000000000000000000000000000000', + F1: '0x100000000000000000000000000000001', + F2: '0x100000000000000000000000000000002', + F3: '0x100000000000000000000000000000003', +} as const; + +export type ETransactionVersion = (typeof ETransactionVersion)[keyof typeof ETransactionVersion]; +/** + * Old Transaction Versions + */ + +export const ETransactionVersion2 = { + V0: ETransactionVersion.V0, + V1: ETransactionVersion.V1, + V2: ETransactionVersion.V2, + F0: ETransactionVersion.F0, + F1: ETransactionVersion.F1, + F2: ETransactionVersion.F2, +} as const; +export type ETransactionVersion2 = (typeof ETransactionVersion2)[keyof typeof ETransactionVersion2]; + +/** + * V3 Transaction Versions + */ + +export const ETransactionVersion3 = { + V3: ETransactionVersion.V3, + F3: ETransactionVersion.F3, +} as const; + +export type ETransactionVersion3 = (typeof ETransactionVersion3)[keyof typeof ETransactionVersion3]; diff --git a/src/api/contract.ts b/src/api/contract.ts index d4ad335..d1dc63b 100644 --- a/src/api/contract.ts +++ b/src/api/contract.ts @@ -1,100 +1,135 @@ /** - * TypeScript Representation of Cairo1 v2+ Starknet Contract ABI - * - * starknet_metadata.json - tags/v0.8rc0 - * * 'starknet-specs' (OpenRpc protocol types) * https://github.com/starkware-libs/starknet-specs */ +import type { ABI_NAME_AND_TYPE, ABI_TYPE, STATE_MUTABILITY } from './components.js'; +import type { + ABI_TYPE_CONSTRUCTOR, + ABI_TYPE_ENUM, + ABI_TYPE_FUNCTION, + ABI_TYPE_L1_HANDLER, + EVENT_ABI_TYPE, + STRUCT_ABI_TYPE, +} from './constants.js'; + +// *** ABI *** +/** + * Cairo v>=2 Contract ABI + */ export type ABI = Array< FUNCTION | CONSTRUCTOR | L1_HANDLER | EVENT | STRUCT | ENUM | INTERFACE | IMPL >; export type FUNCTION = { - type: 'function'; + type: ABI_TYPE_FUNCTION; + /** + * the function's name + */ name: string; - inputs: Array<{ - name: string; - type: string; - }>; - outputs?: Array<{ - type: string; - }>; - state_mutability: 'view' | 'external'; + /** + * the arguments name and type. + */ + inputs: ABI_NAME_AND_TYPE[]; + /** + * the output type. + */ + outputs: ABI_TYPE[]; + state_mutability: STATE_MUTABILITY; }; export type CONSTRUCTOR = { - type: 'constructor'; - name: 'constructor'; - inputs: Array<{ - name: string; - type: string; - }>; + type: ABI_TYPE_CONSTRUCTOR; + name: ABI_TYPE_CONSTRUCTOR; + inputs: ABI_NAME_AND_TYPE[]; }; export type L1_HANDLER = { - type: 'l1_handler'; + type: ABI_TYPE_L1_HANDLER; name: string; - inputs: Array<{ - name: string; - type: string; - }>; - outputs?: Array<{ - type: string; - }>; - state_mutability: 'view' | 'external'; + inputs: ABI_NAME_AND_TYPE[]; + outputs: ABI_TYPE[]; + state_mutability: STATE_MUTABILITY; }; export type EVENT = { - type: 'event'; + type: EVENT_ABI_TYPE; + /** + * the name of the (Cairo) type associated with the event + */ name: string; } & (ENUM_EVENT | STRUCT_EVENT); export type STRUCT_EVENT = { - kind: 'struct'; - members: Array; + kind: STRUCT_ABI_TYPE; + /** + * struct members + */ + members: EVENT_FIELD[]; }; export type ENUM_EVENT = { - kind: 'enum'; - variants: Array; + kind: ABI_TYPE_ENUM; + /** + * enum variants + */ + variants: EVENT_FIELD[]; }; export type STRUCT = { - type: 'struct'; + type: STRUCT_ABI_TYPE; + /** + * the (Cairo) struct name, including namespacing + */ name: string; - members: Array<{ - name: string; - type: string; - }>; + /** + * name of the struct member. + * type of the struct member, including namespacing. + */ + members: ABI_NAME_AND_TYPE[]; }; export type ENUM = { - type: 'enum'; + type: ABI_TYPE_ENUM; + /** + * the (Cairo) enum name, including namespacing + */ name: string; - variants: Array<{ - name: string; - type: string; - }>; + /** + * name of the enum variant. + * type of the enum variant, including namespacing. + */ + variants: ABI_NAME_AND_TYPE[]; }; export type INTERFACE = { type: 'interface'; name: string; - items: Array; + items: FUNCTION[]; }; export type IMPL = { type: 'impl'; + /** + * the name of an impl containing contract entry points + */ name: string; + /** + * the name of the trait corresponding to this impl + */ interface_name: string; }; -export type EVENT_KIND = 'struct' | 'enum'; +export type EVENT_KIND = STRUCT_ABI_TYPE | ABI_TYPE_ENUM; export type EVENT_FIELD = { + /** + * the name of the struct member or enum variant + */ name: string; + /** + * the Cairo type of the member or variant, including namespacing + */ type: string; kind: 'key' | 'data' | 'nested' | 'flat'; }; diff --git a/src/api/errors.ts b/src/api/errors.ts index da557e2..887e3f8 100644 --- a/src/api/errors.ts +++ b/src/api/errors.ts @@ -1,4 +1,5 @@ import type { CONTRACT_EXECUTION_ERROR } from './components.js'; +import type { STATUS_RECEIVED, STATUS_REJECTED } from './constants.js'; export interface FAILED_TO_RECEIVE_TXN { code: 1; @@ -9,7 +10,7 @@ export interface NO_TRACE_AVAILABLE { code: 10; message: 'No trace available for transaction'; data: { - status: 'RECEIVED' | 'REJECTED'; + status: STATUS_RECEIVED | STATUS_REJECTED; }; } @@ -93,6 +94,11 @@ export interface TRANSACTION_EXECUTION_ERROR { }; } +export interface STORAGE_PROOF_NOT_SUPPORTED { + code: 42; + message: "the node doesn't support storage proofs for blocks that are too far in the past"; +} + export interface CLASS_ALREADY_DECLARED { code: 51; message: 'Class already declared'; @@ -175,7 +181,14 @@ export interface TOO_MANY_BLOCKS_BACK { message: 'Cannot go back more than 1024 blocks'; } +export interface CALL_ON_PENDING { + code: 69; + message: 'This method does not support being called on the pending block'; +} + export interface COMPILATION_ERROR { + code: 100; + message: 'Failed to compile the contract'; /** * "More data about the compilation failure */ diff --git a/src/api/executable.ts b/src/api/executable.ts index e0c94d6..614fcfe 100644 --- a/src/api/executable.ts +++ b/src/api/executable.ts @@ -21,7 +21,7 @@ export type CASM_COMPILED_CONTRACT_CLASS = { */ hints: Array<[number | Array, number | Array]>; /** - * a list of sizes of segments in the bytecode, each segment is hashed invidually when computing the bytecode hash. + * a list of sizes of segments in the bytecode, each segment is hashed individually when computing the bytecode hash. * Integer */ bytecode_segment_lengths?: number; @@ -42,7 +42,7 @@ export type Deref = { export type DoubleDeref = { /** - * A (CellRef, offsest) tuple + * A (CellRef, offset) tuple */ DoubleDeref: [CellRef | number]; }; diff --git a/src/api/index.ts b/src/api/index.ts index 6ea76e6..a380271 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -3,3 +3,4 @@ export * from './contract.js'; export * as Errors from './errors.js'; export * as SPEC from './components.js'; export * from './nonspec.js'; +export * from './constants.js'; diff --git a/src/api/methods.ts b/src/api/methods.ts index e1fa07d..8982696 100644 --- a/src/api/methods.ts +++ b/src/api/methods.ts @@ -8,6 +8,7 @@ import type { BROADCASTED_INVOKE_TXN, BROADCASTED_TXN, CHAIN_ID, + CONTRACT_STORAGE_KEYS, EMITTED_EVENT, EVENT_FILTER, EVENT_KEYS, @@ -57,6 +58,10 @@ type ReadMethods = { // Returns the version of the Starknet JSON-RPC specification being used starknet_specVersion: { params: []; + /** + * Semver of Starknet's JSON-RPC spec being used + * @example 0.7.1 + */ result: string; }; @@ -193,11 +198,17 @@ type ReadMethods = { errors: Errors.CONTRACT_NOT_FOUND | Errors.CONTRACT_ERROR | Errors.BLOCK_NOT_FOUND; }; - // Estimate the fee for Starknet transactions + /** + * Estimate the fee for Starknet transactions + * + * Estimates the resources required by a given sequence of transactions when applied on a given state. + * If one of the transactions reverts or fails due to any reason (e.g. validation failure or an internal error), + * a TRANSACTION_EXECUTION_ERROR is returned. For v0-2 transactions the estimate is given in wei, and for v3 transactions it is given in fri. + */ starknet_estimateFee: { params: { request: BROADCASTED_TXN[]; - simulation_flags?: [SIMULATION_FLAG_FOR_ESTIMATE_FEE] | []; // Diverged from spec (0.5 can't be, 0.6 must be) + simulation_flags: [SIMULATION_FLAG_FOR_ESTIMATE_FEE] | []; block_id: BLOCK_ID; }; result: FeeEstimate[]; @@ -282,20 +293,28 @@ type ReadMethods = { */ starknet_getStorageProof: { params: { + /** + * The hash of the requested block, or number (height) of the requested block, or a block tag + */ + block_id: BLOCK_ID; /** * a list of the class hashes for which we want to prove membership in the classes trie */ - class_hashes?: Array; + class_hashes?: FELT[]; /** * a list of contracts for which we want to prove membership in the global state trie */ - contract_addresses?: Array
; + contract_addresses?: ADDRESS[]; /** * a list of (contract_address, storage_keys) pairs */ - contracts_storage_keys?: Array<{ contract_address: ADDRESS; storage_keys: FELT }>; + contracts_storage_keys?: CONTRACT_STORAGE_KEYS[]; }; + /** + * The requested storage proofs. Note that if a requested leaf has the default value, the path to it may end in an edge node whose path is not a prefix of the requested leaf, thus effectively proving non-membership + */ result: StorageProof; + errors: Errors.BLOCK_NOT_FOUND | Errors.STORAGE_PROOF_NOT_SUPPORTED; }; /** @@ -409,14 +428,14 @@ type WebSocketMethods = { /** * The block to get notifications from, default is latest, limited to 1024 blocks back */ - block?: BLOCK_ID; + block_id?: BLOCK_ID; }; result: SUBSCRIPTION_ID; - errors: Errors.TOO_MANY_BLOCKS_BACK; + errors: Errors.TOO_MANY_BLOCKS_BACK | Errors.BLOCK_NOT_FOUND | Errors.CALL_ON_PENDING; events: [ { - name: 'starknet_subscriptionNewHeads'; - result: { + method: 'starknet_subscriptionNewHeads'; + params: { subscription_id: SUBSCRIPTION_ID; result: BLOCK_HEADER; }; @@ -425,10 +444,10 @@ type WebSocketMethods = { /** * Notifies the subscriber of a reorganization of the chain. */ - name: 'starknet_subscriptionReorg'; - result: { + method: 'starknet_subscriptionReorg'; + params: { subscription_id: SUBSCRIPTION_ID; - result: REORG_DATA; // TODO: WTF SPEC + result: REORG_DATA; }; }, ]; @@ -448,14 +467,18 @@ type WebSocketMethods = { /** * The block to get notifications from, default is latest, limited to 1024 blocks back */ - block?: BLOCK_ID; + block_id?: BLOCK_ID; }; result: SUBSCRIPTION_ID; - errors: Errors.TOO_MANY_KEYS_IN_FILTER | Errors.TOO_MANY_BLOCKS_BACK; + errors: + | Errors.TOO_MANY_KEYS_IN_FILTER + | Errors.TOO_MANY_BLOCKS_BACK + | Errors.BLOCK_NOT_FOUND + | Errors.CALL_ON_PENDING; events: [ { - name: 'starknet_subscriptionEvents'; - result: { + method: 'starknet_subscriptionEvents'; + params: { subscription_id: SUBSCRIPTION_ID; result: EMITTED_EVENT; }; @@ -464,10 +487,10 @@ type WebSocketMethods = { /** * Notifies the subscriber of a reorganization of the chain. */ - name: 'starknet_subscriptionReorg'; - result: { + method: 'starknet_subscriptionReorg'; + params: { subscription_id: SUBSCRIPTION_ID; - result: REORG_DATA; // TODO: WTF SPEC + result: REORG_DATA; }; }, ]; @@ -483,14 +506,14 @@ type WebSocketMethods = { /** * The block to get notifications from, default is latest, limited to 1024 blocks back */ - block?: BLOCK_ID; + block_id?: BLOCK_ID; }; result: SUBSCRIPTION_ID; - errors: Errors.TOO_MANY_BLOCKS_BACK; + errors: Errors.TOO_MANY_BLOCKS_BACK | Errors.BLOCK_NOT_FOUND; events: [ { - name: 'starknet_subscriptionTransactionsStatus'; - result: { + method: 'starknet_subscriptionTransactionStatus'; + params: { subscription_id: SUBSCRIPTION_ID; result: NEW_TXN_STATUS; }; @@ -499,10 +522,10 @@ type WebSocketMethods = { /** * Notifies the subscriber of a reorganization of the chain. */ - name: 'starknet_subscriptionReorg'; - result: { + method: 'starknet_subscriptionReorg'; + params: { subscription_id: SUBSCRIPTION_ID; - result: REORG_DATA; // TODO: WTF SPEC + result: REORG_DATA; }; }, ]; @@ -527,8 +550,8 @@ type WebSocketMethods = { errors: Errors.TOO_MANY_ADDRESSES_IN_FILTER; events: [ { - name: 'starknet_subscriptionPendingTransactions'; - result: { + method: 'starknet_subscriptionPendingTransactions'; + params: { subscription_id: SUBSCRIPTION_ID; result: TXN_HASH | TXN; }; diff --git a/src/api/nonspec.ts b/src/api/nonspec.ts index b579aea..dd87fc8 100644 --- a/src/api/nonspec.ts +++ b/src/api/nonspec.ts @@ -85,8 +85,28 @@ export type L1L2MessagesStatus = Array; // response starknet_getStorageProof (merkle paths) export type StorageProof = { classes_proof: NODE_HASH_TO_NODE_MAPPING; - contracts_proof: NODE_HASH_TO_NODE_MAPPING; - contracts_storage_proofs: Array; + contracts_proof: { + /** + * The nodes in the union of the paths from the contracts tree root to the requested leaves + */ + nodes: NODE_HASH_TO_NODE_MAPPING; + /** + * The nonce and class hash for each requested contract address, in the order in which they appear in the request. These values are needed to construct the associated leaf node + */ + contract_leaves_data: { + nonce: FELT; + class_hash: FELT; + }[]; + }; + contracts_storage_proofs: NODE_HASH_TO_NODE_MAPPING[]; + global_roots: { + contracts_tree_root: FELT; + classes_tree_root: FELT; + /** + * the associated block hash (needed in case the caller used a block tag for the block_id parameter) + */ + block_hash: FELT; + }; }; // Nice Components names @@ -133,111 +153,3 @@ export type StorageDiffs = Array; export type DeprecatedDeclaredClasses = Array; export type NonceUpdates = NONCE_UPDATE[]; export type ReplacedClasses = REPLACED_CLASS[]; - -// Enums Derived From Spec Types (require manual check for changes) -export const ETransactionType = { - DECLARE: 'DECLARE', - DEPLOY: 'DEPLOY', - DEPLOY_ACCOUNT: 'DEPLOY_ACCOUNT', - INVOKE: 'INVOKE', - L1_HANDLER: 'L1_HANDLER', -} as const; - -export type ETransactionType = (typeof ETransactionType)[keyof typeof ETransactionType]; - -export const ESimulationFlag = { - SKIP_VALIDATE: 'SKIP_VALIDATE', - SKIP_FEE_CHARGE: 'SKIP_FEE_CHARGE', -} as const; - -export type ESimulationFlag = (typeof ESimulationFlag)[keyof typeof ESimulationFlag]; - -export const ETransactionStatus = { - RECEIVED: 'RECEIVED', - REJECTED: 'REJECTED', - ACCEPTED_ON_L2: 'ACCEPTED_ON_L2', - ACCEPTED_ON_L1: 'ACCEPTED_ON_L1', -} as const; - -export type ETransactionStatus = (typeof ETransactionStatus)[keyof typeof ETransactionStatus]; - -export const ETransactionFinalityStatus = { - ACCEPTED_ON_L2: 'ACCEPTED_ON_L2', - ACCEPTED_ON_L1: 'ACCEPTED_ON_L1', -} as const; - -export type ETransactionFinalityStatus = - (typeof ETransactionFinalityStatus)[keyof typeof ETransactionFinalityStatus]; - -export const ETransactionExecutionStatus = { - SUCCEEDED: 'SUCCEEDED', - REVERTED: 'REVERTED', -} as const; - -export type ETransactionExecutionStatus = - (typeof ETransactionExecutionStatus)[keyof typeof ETransactionExecutionStatus]; - -export const EBlockTag = { - LATEST: 'latest', - PENDING: 'pending', -} as const; - -export type EBlockTag = (typeof EBlockTag)[keyof typeof EBlockTag]; - -// 'L1' | 'L2' -export const EDataAvailabilityMode = { - L1: 'L1', - L2: 'L2', -} as const; - -export type EDataAvailabilityMode = - (typeof EDataAvailabilityMode)[keyof typeof EDataAvailabilityMode]; - -// 0 | 1 -export const EDAMode = { - L1: 0, - L2: 1, -} as const; - -export type EDAMode = (typeof EDAMode)[keyof typeof EDAMode]; - -/** - * V_ Transaction versions HexString - * F_ Fee Transaction Versions HexString (2 ** 128 + TRANSACTION_VERSION) - */ -export const ETransactionVersion = { - V0: '0x0', - V1: '0x1', - V2: '0x2', - V3: '0x3', - F0: '0x100000000000000000000000000000000', - F1: '0x100000000000000000000000000000001', - F2: '0x100000000000000000000000000000002', - F3: '0x100000000000000000000000000000003', -} as const; - -export type ETransactionVersion = (typeof ETransactionVersion)[keyof typeof ETransactionVersion]; -/** - * Old Transaction Versions - */ - -export const ETransactionVersion2 = { - V0: '0x0', - V1: '0x1', - V2: '0x2', - F0: '0x100000000000000000000000000000000', - F1: '0x100000000000000000000000000000001', - F2: '0x100000000000000000000000000000002', -} as const; -export type ETransactionVersion2 = (typeof ETransactionVersion2)[keyof typeof ETransactionVersion2]; - -/** - * V3 Transaction Versions - */ - -export const ETransactionVersion3 = { - V3: '0x3', - F3: '0x100000000000000000000000000000003', -} as const; - -export type ETransactionVersion3 = (typeof ETransactionVersion3)[keyof typeof ETransactionVersion3]; diff --git a/src/wallet-api/typedData.ts b/src/wallet-api/typedData.ts index a0c892d..5aea53e 100644 --- a/src/wallet-api/typedData.ts +++ b/src/wallet-api/typedData.ts @@ -1,3 +1,5 @@ +import type { ABI_TYPE_ENUM } from '../api/constants.js'; + export const TypedDataRevision = { ACTIVE: '1', LEGACY: '0', @@ -7,7 +9,7 @@ export type TypedDataRevision = (typeof TypedDataRevision)[keyof typeof TypedDat export type StarknetEnumType = { name: string; - type: 'enum'; + type: ABI_TYPE_ENUM; contains: string; };