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 12, 2024
1 parent 000f6fb commit 72cd2d2
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 50 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}`;
};
3 changes: 1 addition & 2 deletions src/utils/calldata/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ const guard = {
isBN: (data: Record<string, any>, type: Record<string, any>, key: string) => {
if (!isBigInt(data[key]))
throw new Error(
`Data and formatter mismatch on ${key}:${type[key]}, expected response data ${key}:${
data[key]
`Data and formatter mismatch on ${key}:${type[key]}, expected response data ${key}:${data[key]
} to be BN instead it is ${typeof data[key]}`
);
},
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
26 changes: 13 additions & 13 deletions src/utils/starknetId.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StarknetChainId, ZERO } from '../constants';
import { BigNumberish } from '../types';
import { BigNumberish, ChainId } from '../types';
import { tuple } from './calldata/cairo';
import { CairoCustomEnum } from './calldata/enum/CairoCustomEnum';
/* eslint-disable no-param-reassign */
Expand Down Expand Up @@ -132,7 +132,7 @@ export const StarknetIdContract = {
/**
* Returns the Starknet ID contract address based on the provided chain ID.
*
* @param {StarknetChainId} chainId The chain ID of the Starknet network.
* @param {ChainId} chainId The chain ID of the Starknet network.
* @return {string} The Starknet ID contract address.
* @throws {Error} Throws an error if the Starknet ID contract is not deployed on the network.
* @example
Expand All @@ -141,7 +141,7 @@ export const StarknetIdContract = {
* // result = "0x154bc2e1af9260b9e66af0e9c46fc757ff893b3ff6a85718a810baf1474"
* ```
*/
export function getStarknetIdContract(chainId: StarknetChainId): string {
export function getStarknetIdContract(chainId: ChainId): string {
switch (chainId) {
case StarknetChainId.SN_MAIN:
return StarknetIdContract.MAINNET;
Expand All @@ -162,7 +162,7 @@ export const StarknetIdIdentityContract = {
/**
* Returns the Starknet ID identity contract address for the given chain ID.
*
* @param {StarknetChainId} chainId The chain ID for the specified network.
* @param {ChainId} chainId The chain ID for the specified network.
*
* @return {string} The Starknet ID identity contract address for the specified network.
*
Expand All @@ -173,7 +173,7 @@ export const StarknetIdIdentityContract = {
* // result = "0x3697660a0981d734780731949ecb2b4a38d6a58fc41629ed611e8defda"
* ```
*/
export function getStarknetIdIdentityContract(chainId: StarknetChainId): string {
export function getStarknetIdIdentityContract(chainId: ChainId): string {
switch (chainId) {
case StarknetChainId.SN_MAIN:
return StarknetIdIdentityContract.MAINNET;
Expand All @@ -192,7 +192,7 @@ export const StarknetIdMulticallContract =
/**
* Returns the Starknet.id multicall contract address based on the provided chainId.
*
* @param {StarknetChainId} chainId - The chainId of the network.
* @param {ChainId} chainId - The chainId of the network.
* @return {string} - The address of the Starknet.id multicall contract.
* @throws {Error} - If the Starknet.id multicall contract is not deployed on the network.
* @example
Expand All @@ -201,7 +201,7 @@ export const StarknetIdMulticallContract =
* // result = "0x034ffb8f4452df7a613a0210824d6414dbadcddce6c6e19bf4ddc9e22ce5f970"
* ```
*/
export function getStarknetIdMulticallContract(chainId: StarknetChainId): string {
export function getStarknetIdMulticallContract(chainId: ChainId): string {
switch (chainId) {
case StarknetChainId.SN_MAIN:
return StarknetIdMulticallContract;
Expand All @@ -222,7 +222,7 @@ export const StarknetIdVerifierContract = {
/**
* Returns the address of the Starknet ID Verifier contract based on the specified chain ID.
*
* @param {StarknetChainId} chainId - The ID of the Starknet chain.
* @param {ChainId} chainId - The ID of the Starknet chain.
* @return {string} - The address of the Starknet ID Verifier contract.
* @throws {Error} - If the Starknet ID Verifier contract is not deployed on the specified network.
* @example
Expand All @@ -231,7 +231,7 @@ export const StarknetIdVerifierContract = {
* // result = "0x60B94fEDe525f815AE5E8377A463e121C787cCCf3a36358Aa9B18c12c4D566"
* ```
*/
export function getStarknetIdVerifierContract(chainId: StarknetChainId): string {
export function getStarknetIdVerifierContract(chainId: ChainId): string {
switch (chainId) {
case StarknetChainId.SN_MAIN:
return StarknetIdVerifierContract.MAINNET;
Expand All @@ -252,7 +252,7 @@ export const StarknetIdPfpContract = {
/**
* Retrieves the contract address of the Starknet.id profile picture verifier contract based on the given chain ID.
*
* @param {StarknetChainId} chainId - The chain ID of the network.
* @param {ChainId} chainId - The chain ID of the network.
* @returns {string} - The contract address of the Starknet.id profile picture verifier contract.
* @throws {Error} - Throws an error if the Starknet.id profile picture verifier contract is not yet deployed on the network.
* @example
Expand All @@ -261,7 +261,7 @@ export const StarknetIdPfpContract = {
* // result = "0x9e7bdb8dabd02ea8cfc23b1d1c5278e46490f193f87516ed5ff2dfec02"
* ```
*/
export function getStarknetIdPfpContract(chainId: StarknetChainId): string {
export function getStarknetIdPfpContract(chainId: ChainId): string {
switch (chainId) {
case StarknetChainId.SN_MAIN:
return StarknetIdPfpContract.MAINNET;
Expand All @@ -284,7 +284,7 @@ export const StarknetIdPopContract = {
/**
* Retrieves the Starknet ID Proof of Personhood (IdPop) verifier contract address for the given chain ID.
*
* @param {StarknetChainId} chainId - The chain ID of the Starknet network.
* @param {ChainId} chainId - The chain ID of the Starknet network.
* @return {string} - The Starknet ID Pop contract address.
* @throws {Error} - If the Starknet ID Pop contract is not deployed on the specified network.
* @example
Expand All @@ -293,7 +293,7 @@ export const StarknetIdPopContract = {
* // result = "0x15ae88ae054caa74090b89025c1595683f12edf7a4ed2ad0274de3e1d4a"
* ```
*/
export function getStarknetIdPopContract(chainId: StarknetChainId): string {
export function getStarknetIdPopContract(chainId: ChainId): string {
switch (chainId) {
case StarknetChainId.SN_MAIN:
return StarknetIdPopContract.MAINNET;
Expand Down
Loading

0 comments on commit 72cd2d2

Please sign in to comment.