Skip to content

Commit

Permalink
feat: substitute the use of StarknetChainId for ChainId
Browse files Browse the repository at this point in the history
  • Loading branch information
BenFaruna committed Sep 10, 2024
1 parent c0f9835 commit 2fce1c8
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 57 deletions.
4 changes: 2 additions & 2 deletions src/provider/interface.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { RPC06, RPC07 } from '../channel';
import { StarknetChainId } from '../constants';
import type {
AccountInvocations,
BigNumberish,
Block,
BlockIdentifier,
Call,
CallContractResponse,
ChainId,
ContractClassResponse,
ContractVersion,
DeclareContractResponse,
Expand Down Expand Up @@ -41,7 +41,7 @@ export abstract class ProviderInterface {
*
* @returns the chain Id
*/
public abstract getChainId(): Promise<StarknetChainId>;
public abstract getChainId(): Promise<ChainId>;

/**
* Calls a function on the Starknet contract.
Expand Down
5 changes: 3 additions & 2 deletions src/types/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { StarknetChainId } from '../../constants';
import { weierstrass } from '../../utils/ec';
import { EDataAvailabilityMode, ResourceBounds } from '../api';
import { CairoEnum } from '../cairoEnum';
Expand Down Expand Up @@ -159,7 +158,7 @@ export type Details = {
nonce: BigNumberish;
maxFee: BigNumberish;
version: BigNumberish;
chainId: StarknetChainId;
chainId: ChainId;
};

export type InvocationsDetailsWithNonce =
Expand Down Expand Up @@ -313,4 +312,6 @@ export type ContractVersion = {
compiler: CompilerVersion;
};

export type ChainId = `0x${string}`;

export * from './contract';
4 changes: 2 additions & 2 deletions src/types/provider/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NetworkName } from '../../constants';
import { BlockIdentifier } from '../lib';
import { BlockIdentifier, ChainId } from '../lib';

export interface ProviderOptions extends RpcProviderOptions {}

Expand All @@ -21,4 +21,4 @@ export type RpcProviderOptions = {
batch?: false | number;
};

export type ChainId = `0x${string}`;
// export type ChainId = `0x${string}`;
14 changes: 7 additions & 7 deletions src/types/signer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { StarknetChainId } from '../constants';
import { ETransactionVersion, ETransactionVersion2, ETransactionVersion3 } from './api';
import {
BigNumberish,
CairoVersion,
ChainId,
DeployAccountContractPayload,
InvocationsDetails,
V3TransactionDetails,
Expand All @@ -16,7 +16,7 @@ export type InvocationsSignerDetails = (V2InvocationsSignerDetails | V3Invocatio
export type V2InvocationsSignerDetails = {
walletAddress: string;
cairoVersion: CairoVersion;
chainId: StarknetChainId;
chainId: ChainId;
nonce: BigNumberish;
maxFee: BigNumberish;
version: `${ETransactionVersion2}`;
Expand All @@ -25,7 +25,7 @@ export type V2InvocationsSignerDetails = {
export type V3InvocationsSignerDetails = V3TransactionDetails & {
walletAddress: string;
cairoVersion: CairoVersion;
chainId: StarknetChainId;
chainId: ChainId;
version: `${ETransactionVersion3}`;
};

Expand All @@ -37,15 +37,15 @@ export type V2DeclareSignerDetails = Required<InvocationsDetails> & {
classHash: string;
compiledClassHash?: string;
senderAddress: string;
chainId: StarknetChainId;
chainId: ChainId;
version: `${ETransactionVersion2}`;
};

export type V3DeclareSignerDetails = V3TransactionDetails & {
classHash: string;
compiledClassHash: string;
senderAddress: string;
chainId: StarknetChainId;
chainId: ChainId;
version: `${ETransactionVersion3}`;
};

Expand All @@ -56,13 +56,13 @@ export type DeployAccountSignerDetails =
export type V2DeployAccountSignerDetails = Required<DeployAccountContractPayload> &
Required<InvocationsDetails> & {
contractAddress: BigNumberish;
chainId: StarknetChainId;
chainId: ChainId;
version: `${ETransactionVersion2}`;
};

export type V3DeployAccountSignerDetails = Required<DeployAccountContractPayload> &
V3TransactionDetails & {
contractAddress: BigNumberish;
chainId: StarknetChainId;
chainId: ChainId;
version: `${ETransactionVersion3}`;
};
10 changes: 5 additions & 5 deletions src/utils/calldata/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { decodeShortString } from '../shortString';
const guard = {
/**
* Checks if the data is a BigInt (BN) and throws an error if not.
*
*
* @param {Record<string, any>} data - The data object containing the key to check.
* @param {Record<string, any>} type - The type definition object.
* @param {string} key - The key in the data object to check.
Expand All @@ -21,7 +21,7 @@ const guard = {

/**
* Throws an error for unhandled formatter types.
*
*
* @param {Record<string, any>} data - The data object containing the key.
* @param {Record<string, any>} type - The type definition object.
* @param {string} key - The key in the data object to check.
Expand All @@ -39,21 +39,21 @@ const guard = {
* @param {Record<string, any>} type - The type definition for the data.
* @param {any} [sameType] - The same type definition to be used (optional).
* @returns {Record<string, any>} The formatted data.
*
*
* @example
* // Example 1: Formatting a simple object
* const data = { value: '123', name: 'test' };
* const type = { value: 'number', name: 'string' };
* const formatted = formatter(data, type);
* // formatted: { value: 123, name: 'test' }
*
*
* @example
* // Example 2: Formatting an object with nested structures
* const data = { user: { id: '123', age: '30' }, active: '1' };
* const type = { user: { id: 'number', age: 'number' }, active: 'number' };
* const formatted = formatter(data, type);
* // formatted: { user: { id: 123, age: 30 }, active: 1 }
*
*
* @example
* // Example 3: Handling arrays in the data object
* const data = { items: ['1', '2', '3'], name: 'test' };
Expand Down
8 changes: 4 additions & 4 deletions src/utils/calldata/tuple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,22 @@ function extractCairo1Tuple(type: string): string[] {
/**
* Convert a tuple string definition into an object-like definition.
* Supports both Cairo 0 and Cairo 1 tuple formats.
*
*
* @param type - The tuple string definition (e.g., "(u8, u8)" or "(x:u8, y:u8)").
* @returns An array of strings or objects representing the tuple components.
*
*
* @example
* // Cairo 0 Tuple
* const cairo0Tuple = "(u8, u8)";
* const result = extractTupleMemberTypes(cairo0Tuple);
* // result: ["u8", "u8"]
*
*
* @example
* // Named Cairo 0 Tuple
* const namedCairo0Tuple = "(x:u8, y:u8)";
* const namedResult = extractTupleMemberTypes(namedCairo0Tuple);
* // namedResult: [{ name: "x", type: "u8" }, { name: "y", type: "u8" }]
*
*
* @example
* // Cairo 1 Tuple
* const cairo1Tuple = "(core::result::Result::<u8, u8>, u8)";
Expand Down
15 changes: 7 additions & 8 deletions src/utils/hash/transactionHash/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
* Transaction Hash based on Transaction Version
*/

import { StarknetChainId } from '../../../constants';
import { BigNumberish, Calldata } from '../../../types';
import { BigNumberish, Calldata, ChainId } from '../../../types';
import {
EDAMode,
ETransactionVersion,
Expand Down Expand Up @@ -38,15 +37,15 @@ type CalcV2InvokeTxHashArgs = {
version: `${ETransactionVersion2}`;
compiledCalldata: Calldata;
maxFee: BigNumberish;
chainId: StarknetChainId;
chainId: ChainId;
nonce: BigNumberish;
};

type CalcV3InvokeTxHashArgs = {
senderAddress: BigNumberish;
version: `${ETransactionVersion3}`;
compiledCalldata: Calldata;
chainId: StarknetChainId;
chainId: ChainId;
nonce: BigNumberish;
accountDeploymentData: BigNumberish[];
nonceDataAvailabilityMode: EDAMode;
Expand Down Expand Up @@ -96,7 +95,7 @@ type CalcV2DeclareTxHashArgs = {
senderAddress: BigNumberish;
version: `${ETransactionVersion2}`;
maxFee: BigNumberish;
chainId: StarknetChainId;
chainId: ChainId;
nonce: BigNumberish;
compiledClassHash?: string;
};
Expand All @@ -106,7 +105,7 @@ type CalcV3DeclareTxHashArgs = {
compiledClassHash: string;
senderAddress: BigNumberish;
version: `${ETransactionVersion3}`;
chainId: StarknetChainId;
chainId: ChainId;
nonce: BigNumberish;
accountDeploymentData: BigNumberish[];
nonceDataAvailabilityMode: EDAMode;
Expand Down Expand Up @@ -164,7 +163,7 @@ type CalcV2DeployAccountTxHashArgs = {
salt: BigNumberish;
version: `${ETransactionVersion2}`;
maxFee: BigNumberish;
chainId: StarknetChainId;
chainId: ChainId;
nonce: BigNumberish;
};

Expand All @@ -174,7 +173,7 @@ type CalcV3DeployAccountTxHashArgs = {
compiledConstructorCalldata: Calldata;
salt: BigNumberish;
version: `${ETransactionVersion3}`;
chainId: StarknetChainId;
chainId: ChainId;
nonce: BigNumberish;
nonceDataAvailabilityMode: EDAMode;
feeDataAvailabilityMode: EDAMode;
Expand Down
10 changes: 5 additions & 5 deletions src/utils/hash/transactionHash/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* eslint-disable no-param-reassign */
/* eslint-disable import/extensions */
import { StarknetChainId, TransactionHashPrefix } from '../../../constants';
import { BigNumberish, RawCalldata } from '../../../types';
import { BigNumberish, ChainId, RawCalldata } from '../../../types';
import { starkCurve } from '../../ec';
import { toBigInt } from '../../num';
import { getSelector } from '../selector';
Expand Down Expand Up @@ -33,7 +33,7 @@ export function calculateTransactionHashCommon(
entryPointSelector: BigNumberish,
calldata: RawCalldata,
maxFee: BigNumberish,
chainId: StarknetChainId,
chainId: ChainId,
additionalData: BigNumberish[] = []
): string {
const calldataHash = computeHashOnElements(calldata);
Expand Down Expand Up @@ -61,7 +61,7 @@ export function calculateDeclareTransactionHash(
senderAddress: BigNumberish,
version: BigNumberish,
maxFee: BigNumberish,
chainId: StarknetChainId,
chainId: ChainId,
nonce: BigNumberish,
compiledClassHash?: string
): string {
Expand All @@ -88,7 +88,7 @@ export function calculateDeployAccountTransactionHash(
salt: BigNumberish,
version: BigNumberish,
maxFee: BigNumberish,
chainId: StarknetChainId,
chainId: ChainId,
nonce: BigNumberish
) {
const calldata = [classHash, salt, ...constructorCalldata];
Expand All @@ -114,7 +114,7 @@ export function calculateTransactionHash(
version: BigNumberish,
calldata: RawCalldata,
maxFee: BigNumberish,
chainId: StarknetChainId,
chainId: ChainId,
nonce: BigNumberish
): string {
return calculateTransactionHashCommon(
Expand Down
12 changes: 6 additions & 6 deletions src/utils/hash/transactionHash/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import { poseidonHashMany } from '@scure/starknet';

import { StarknetChainId, TransactionHashPrefix } from '../../../constants';
import { BigNumberish, Calldata } from '../../../types';
import { TransactionHashPrefix } from '../../../constants';
import { BigNumberish, Calldata, ChainId } from '../../../types';
import { EDAMode, ResourceBounds } from '../../../types/api';
import { toHex } from '../../num';
import { encodeShortString } from '../../shortString';
Expand Down Expand Up @@ -42,7 +42,7 @@ export function calculateTransactionHashCommon(
txHashPrefix: TransactionHashPrefix,
version: BigNumberish,
senderAddress: BigNumberish,
chainId: StarknetChainId,
chainId: ChainId,
nonce: BigNumberish,
tip: BigNumberish,
paymasterData: BigNumberish[],
Expand Down Expand Up @@ -77,7 +77,7 @@ export function calculateDeployAccountTransactionHash(
compiledConstructorCalldata: Calldata,
salt: BigNumberish,
version: BigNumberish,
chainId: StarknetChainId,
chainId: ChainId,
nonce: BigNumberish,
nonceDataAvailabilityMode: EDAMode,
feeDataAvailabilityMode: EDAMode,
Expand Down Expand Up @@ -109,7 +109,7 @@ export function calculateDeclareTransactionHash(
compiledClassHash: string,
senderAddress: BigNumberish,
version: BigNumberish,
chainId: StarknetChainId,
chainId: ChainId,
nonce: BigNumberish,
accountDeploymentData: BigNumberish[],
nonceDataAvailabilityMode: EDAMode,
Expand Down Expand Up @@ -141,7 +141,7 @@ export function calculateInvokeTransactionHash(
senderAddress: BigNumberish,
version: BigNumberish,
compiledCalldata: Calldata,
chainId: StarknetChainId,
chainId: ChainId,
nonce: BigNumberish,
accountDeploymentData: BigNumberish[],
nonceDataAvailabilityMode: EDAMode,
Expand Down
Loading

0 comments on commit 2fce1c8

Please sign in to comment.