Repository: 0xs34n/starknet.js
Pull request #627 (2023-05-30 06:02:21)

refactor: group type exports
Aggregates exported types and interfaces into the `types` folder.

Moved types/interfaces with new default locations and legacy re-exports:
- `BigNumberish` from `utils/num` to `types/lib`
- `BlockIdentifier` from `provider/utils` to `types/lib`
- `Uint256` from `utils/uint256` to `types/lib`
- the `utils/typedData/types.ts` file renamed and moved to `types/`

Moved types/interfaces without location changes in the published module bundle:
- `ProviderOptions` from `provider/default` to `types/provider/configuration`
- `RpcProviderOptions` from `provider/rpc` to `types/provider/configuration`
- `SequencerHttpMethod` from `provider/sequncer` to `types/provider/configuration`
- `SequencerProviderOptions` from `provider/sequncer` to `types/provider/configuration`


netlify[bot]: ### <span aria-hidden="true">👷</span> Deploy Preview for *starknetjs* processing.


|  Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | 62983cdbc4ee16e9d125cc5a7047601599b1e87a |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/sites/starknetjs/deploys/6475916e42972400077fce12 |

Patch:
diff --git a/src/account/default.ts b/src/account/default.ts
index f03c45fd..76298918 100644
--- a/src/account/default.ts
+++ b/src/account/default.ts
@@ -1,11 +1,12 @@
 import { UDC, ZERO } from '../constants';
-import { ProviderInterface, ProviderOptions } from '../provider';
+import { ProviderInterface } from '../provider';
 import { Provider } from '../provider/default';
-import { BlockIdentifier } from '../provider/utils';
 import { Signer, SignerInterface } from '../signer';
 import {
   Abi,
   AllowArray,
+  BigNumberish,
+  BlockIdentifier,
   CairoVersion,
   Call,
   DeclareAndDeployContractPayload,
@@ -20,6 +21,7 @@ import {
   Details,
   EstimateFee,
   EstimateFeeAction,
+  EstimateFeeBulk,
   EstimateFeeDetails,
   Invocation,
   InvocationsDetails,
@@ -27,13 +29,15 @@ import {
   InvokeFunctionResponse,
   MultiDeployContractResponse,
   Nonce,
+  ProviderOptions,
   Signature,
   TransactionBulk,
+  TransactionSimulation,
   TransactionStatus,
   TransactionType,
+  TypedData,
   UniversalDeployerContractPayload,
 } from '../types';
-import { EstimateFeeBulk, TransactionSimulation } from '../types/account';
 import { CallData } from '../utils/calldata';
 import { extractContractHashes, isSierra } from '../utils/contract';
 import { starkCurve } from '../utils/ec';
@@ -44,11 +48,11 @@ import {
   transactionVersion,
   transactionVersion_2,
 } from '../utils/hash';
-import { BigNumberish, toBigInt, toCairoBool } from '../utils/num';
+import { toBigInt, toCairoBool } from '../utils/num';
 import { parseContract } from '../utils/provider';
 import { estimatedFeeToMaxFee, formatSignature, randomAddress } from '../utils/stark';
 import { getExecuteCalldata } from '../utils/transaction';
-import { TypedData, getMessageHash } from '../utils/typedData';
+import { getMessageHash } from '../utils/typedData';
 import { AccountInterface } from './interface';
 
 export class Account extends Provider implements AccountInterface {
diff --git a/src/account/interface.ts b/src/account/interface.ts
index 666ad750..8fd332ce 100644
--- a/src/account/interface.ts
+++ b/src/account/interface.ts
@@ -1,9 +1,10 @@
 import { ProviderInterface } from '../provider';
-import { BlockIdentifier } from '../provider/utils';
 import { SignerInterface } from '../signer';
 import {
   Abi,
   AllowArray,
+  BigNumberish,
+  BlockIdentifier,
   CairoVersion,
   Call,
   DeclareAndDeployContractPayload,
@@ -24,10 +25,9 @@ import {
   Signature,
   TransactionBulk,
   TransactionSimulation,
+  TypedData,
   UniversalDeployerContractPayload,
 } from '../types';
-import { BigNumberish } from '../utils/num';
-import { TypedData } from '../utils/typedData/types';
 
 export abstract class AccountInterface extends ProviderInterface {
   public abstract address: string;
diff --git a/src/contract/interface.ts b/src/contract/interface.ts
index 23550a70..b7d599d4 100644
--- a/src/contract/interface.ts
+++ b/src/contract/interface.ts
@@ -1,10 +1,10 @@
 import { AccountInterface } from '../account';
 import { ProviderInterface } from '../provider';
-import { BlockIdentifier } from '../provider/utils';
 import {
   Abi,
   ArgsOrCalldata,
   AsyncContractFunction,
+  BlockIdentifier,
   CallOptions,
   ContractFunction,
   EstimateFeeResponse,
diff --git a/src/index.ts b/src/index.ts
index 1a07d698..c5713c28 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,12 +1,15 @@
 /**
  * Main
  */
+export * from './account';
 export * from './contract';
-export * from './types';
 export * from './provider';
-export * from './account';
 export * from './signer';
 
+// TODO: decide on final export style
+export * from './types';
+export * as types from './types';
+
 /**
  * Utils
  */
diff --git a/src/provider/default.ts b/src/provider/default.ts
index d47f5879..5f1259a5 100644
--- a/src/provider/default.ts
+++ b/src/provider/default.ts
@@ -1,5 +1,7 @@
 import { StarknetChainId } from '../constants';
 import {
+  BigNumberish,
+  BlockIdentifier,
   Call,
   CallContractResponse,
   ContractClass,
@@ -18,23 +20,19 @@ import {
   InvocationsDetailsWithNonce,
   InvokeFunctionResponse,
   Nonce,
+  ProviderOptions,
   RPC,
+  RpcProviderOptions,
+  SequencerProviderOptions,
   StateUpdateResponse,
   Storage,
   TransactionSimulationResponse,
   waitForTransactionOptions,
 } from '../types';
-import { BigNumberish } from '../utils/num';
 import { ProviderInterface } from './interface';
-import { RpcProvider, RpcProviderOptions } from './rpc';
-import { SequencerProvider, SequencerProviderOptions } from './sequencer';
+import { RpcProvider } from './rpc';
+import { SequencerProvider } from './sequencer';
 import { getAddressFromStarkName, getStarkName } from './starknetId';
-import { BlockIdentifier } from './utils';
-
-export interface ProviderOptions {
-  sequencer?: SequencerProviderOptions;
-  rpc?: RpcProviderOptions;
-}
 
 export class Provider implements ProviderInterface {
   private provider!: ProviderInterface;
diff --git a/src/provider/interface.ts b/src/provider/interface.ts
index 5b4ab5d8..4b538db0 100644
--- a/src/provider/interface.ts
+++ b/src/provider/interface.ts
@@ -1,5 +1,7 @@
 import { StarknetChainId } from '../constants';
 import type {
+  BigNumberish,
+  BlockIdentifier,
   Call,
   CallContractResponse,
   ContractClass,
@@ -25,8 +27,6 @@ import type {
   TransactionSimulationResponse,
   waitForTransactionOptions,
 } from '../types';
-import type { BigNumberish } from '../utils/num';
-import { BlockIdentifier } from './utils';
 
 export abstract class ProviderInterface {
   /**
diff --git a/src/provider/rpc.ts b/src/provider/rpc.ts
index b9a27829..e570d8ff 100644
--- a/src/provider/rpc.ts
+++ b/src/provider/rpc.ts
@@ -1,5 +1,7 @@
 import { StarknetChainId } from '../constants';
 import {
+  BigNumberish,
+  BlockIdentifier,
   Call,
   CallContractResponse,
   DeclareContractResponse,
@@ -16,6 +18,7 @@ import {
   InvocationsDetailsWithNonce,
   InvokeFunctionResponse,
   RPC,
+  RpcProviderOptions,
   TransactionSimulationResponse,
   TransactionStatus,
   waitForTransactionOptions,
@@ -24,22 +27,14 @@ import { CallData } from '../utils/calldata';
 import fetch from '../utils/fetchPonyfill';
 import { getSelectorFromName } from '../utils/hash';
 import { stringify } from '../utils/json';
-import { BigNumberish, toHex } from '../utils/num';
+import { toHex } from '../utils/num';
 import { wait } from '../utils/provider';
 import { RPCResponseParser } from '../utils/responseParser/rpc';
 import { signatureToHexArray } from '../utils/stark';
 import { LibraryError } from './errors';
 import { ProviderInterface } from './interface';
 import { getAddressFromStarkName, getStarkName } from './starknetId';
-import { Block, BlockIdentifier } from './utils';
-
-export type RpcProviderOptions = {
-  nodeUrl: string;
-  retries?: number;
-  headers?: object;
-  blockIdentifier?: BlockIdentifier;
-  chainId?: StarknetChainId;
-};
+import { Block } from './utils';
 
 // Default Pathfinder disabled pending block https://github.com/eqlabs/pathfinder/blob/main/README.md
 // Note that pending support is disabled by default and must be enabled by setting poll-pending=true in the configuration options.
diff --git a/src/provider/sequencer.ts b/src/provider/sequencer.ts
index ed5f288b..b1384439 100644
--- a/src/provider/sequencer.ts
+++ b/src/provider/sequencer.ts
@@ -2,6 +2,8 @@ import urljoin from 'url-join';
 
 import { BaseUrl, NetworkName, StarknetChainId } from '../constants';
 import {
+  BigNumberish,
+  BlockIdentifier,
   CairoAssembly,
   Call,
   CallContractResponse,
@@ -23,6 +25,8 @@ import {
   InvocationsDetailsWithNonce,
   InvokeFunctionResponse,
   Sequencer,
+  SequencerHttpMethod,
+  SequencerProviderOptions,
   StateUpdateResponse,
   TransactionSimulationResponse,
   TransactionStatus,
@@ -36,7 +40,6 @@ import fetch from '../utils/fetchPonyfill';
 import { feeTransactionVersion, getSelector, getSelectorFromName } from '../utils/hash';
 import { parse, parseAlwaysAsBig, stringify } from '../utils/json';
 import {
-  BigNumberish,
   bigNumberishArrayToDecimalStringArray,
   getDecimalString,
   getHexString,
@@ -51,25 +54,7 @@ import { buildUrl } from '../utils/url';
 import { GatewayError, HttpError, LibraryError } from './errors';
 import { ProviderInterface } from './interface';
 import { getAddressFromStarkName, getStarkName } from './starknetId';
-import { Block, BlockIdentifier } from './utils';
-
-export type SequencerHttpMethod = 'POST' | 'GET';
-
-export type SequencerProviderOptions = {
-  headers?: Record<string, string>;
-  blockIdentifier?: BlockIdentifier;
-} & (
-  | {
-      network: NetworkName | StarknetChainId;
-      chainId?: StarknetChainId;
-    }
-  | {
-      baseUrl: string;
-      feederGatewayUrl?: string;
-      gatewayUrl?: string;
-      chainId?: StarknetChainId;
-    }
-);
+import { Block } from './utils';
 
 function isEmptyQueryObject(obj?: Record<any, any>): obj is undefined {
   return (
diff --git a/src/provider/starknetId.ts b/src/provider/starknetId.ts
index 701d8e1a..3a67a5c0 100644
--- a/src/provider/starknetId.ts
+++ b/src/provider/starknetId.ts
@@ -1,5 +1,5 @@
+import { BigNumberish } from '../types';
 import { CallData } from '../utils/calldata';
-import { BigNumberish } from '../utils/num';
 import { getStarknetIdContract, useDecoded, useEncoded } from '../utils/starknetId';
 import { ProviderInterface } from './interface';
 
diff --git a/src/provider/utils.ts b/src/provider/utils.ts
index 720a73b1..806f77b3 100644
--- a/src/provider/utils.ts
+++ b/src/provider/utils.ts
@@ -1,6 +1,9 @@
 /* eslint-disable max-classes-per-file */
-import type { BlockNumber, SequencerIdentifier } from '../types';
-import { BigNumberish, isHex, toHex } from '../utils/num';
+import type { BigNumberish, BlockIdentifier, BlockNumber, SequencerIdentifier } from '../types';
+import { isHex, toHex } from '../utils/num';
+
+/** @deprecated prefer importing from 'types' over 'provider/utils' */
+export type { BlockIdentifier };
 
 /**
  *
@@ -29,11 +32,6 @@ export function txIdentifier(txHash?: BigNumberish, txId?: BigNumberish): string
   return `transactionHash=${hashString}`;
 }
 
-// hex string and BN are detected as block hashes
-// decimal string and number are detected as block numbers
-// null appends nothing to the request url
-
-export type BlockIdentifier = BlockNumber | BigNumberish;
 export const validBlockTags = ['latest', 'pending'];
 
 export class Block {
diff --git a/src/signer/default.ts b/src/signer/default.ts
index 389e6854..353dd0c4 100644
--- a/src/signer/default.ts
+++ b/src/signer/default.ts
@@ -1,5 +1,12 @@
-import { Abi, Call, DeclareSignerDetails, InvocationsSignerDetails, Signature } from '../types';
-import { DeployAccountSignerDetails } from '../types/signer';
+import {
+  Abi,
+  Call,
+  DeclareSignerDetails,
+  DeployAccountSignerDetails,
+  InvocationsSignerDetails,
+  Signature,
+  TypedData,
+} from '../types';
 import { CallData } from '../utils/calldata';
 import { starkCurve } from '../utils/ec';
 import { buf2hex } from '../utils/encode';
@@ -10,7 +17,7 @@ import {
 } from '../utils/hash';
 import { toHex } from '../utils/num';
 import { getExecuteCalldata } from '../utils/transaction';
-import { TypedData, getMessageHash } from '../utils/typedData';
+import { getMessageHash } from '../utils/typedData';
 import { SignerInterface } from './interface';
 
 export class Signer implements SignerInterface {
diff --git a/src/signer/interface.ts b/src/signer/interface.ts
index fa582ae8..ef9f2cd8 100644
--- a/src/signer/interface.ts
+++ b/src/signer/interface.ts
@@ -1,6 +1,12 @@
-import { Abi, Call, DeclareSignerDetails, InvocationsSignerDetails, Signature } from '../types';
-import { DeployAccountSignerDetails } from '../types/signer';
-import { TypedData } from '../utils/typedData';
+import {
+  Abi,
+  Call,
+  DeclareSignerDetails,
+  DeployAccountSignerDetails,
+  InvocationsSignerDetails,
+  Signature,
+  TypedData,
+} from '../types';
 
 export abstract class SignerInterface {
   /**
diff --git a/src/types/account.ts b/src/types/account.ts
index 1b829c18..5d5723ab 100644
--- a/src/types/account.ts
+++ b/src/types/account.ts
@@ -1,5 +1,4 @@
-import { BlockIdentifier } from '../provider/utils';
-import { BigNumberish } from '../utils/num';
+import { BigNumberish, BlockIdentifier } from './lib';
 import {
   DeclareTransactionReceiptResponse,
   EstimateFeeResponse,
diff --git a/src/types/api/sequencer.ts b/src/types/api/sequencer.ts
index e6dffc58..43e8f2ba 100644
--- a/src/types/api/sequencer.ts
+++ b/src/types/api/sequencer.ts
@@ -1,8 +1,8 @@
-import { BlockIdentifier } from '../../provider/utils';
-import { BigNumberish } from '../../utils/num';
 import {
   Abi,
   AllowArray,
+  BigNumberish,
+  BlockIdentifier,
   BlockNumber,
   ByteCode,
   CairoAssembly,
diff --git a/src/types/contract.ts b/src/types/contract.ts
index ea5dfb0c..2bbef2e5 100644
--- a/src/types/contract.ts
+++ b/src/types/contract.ts
@@ -1,6 +1,4 @@
-import { BlockIdentifier } from '../provider/utils';
-import { BigNumberish } from '../utils/num';
-import { RawArgsArray, Signature } from './lib';
+import { BigNumberish, BlockIdentifier, RawArgsArray, Signature } from './lib';
 
 export type AsyncContractFunction<T = any> = (...args: ArgsOrCalldataWithOptions) => Promise<T>;
 export type ContractFunction = (...args: ArgsOrCalldataWithOptions) => any;
diff --git a/src/types/index.ts b/src/types/index.ts
index 74ae6554..e62c87ee 100644
--- a/src/types/index.ts
+++ b/src/types/index.ts
@@ -1,7 +1,8 @@
-export * from './lib';
-export * from './signer';
-export * from './contract';
 export * from './account';
+export * from './contract';
+export * from './lib';
 export * from './provider';
+export * from './signer';
+export * from './typedData';
 export * from './api/sequencer';
 export * from './api/rpc';
diff --git a/src/types/lib/index.ts b/src/types/lib/index.ts
index 1a4b053e..dda5577f 100644
--- a/src/types/lib/index.ts
+++ b/src/types/lib/index.ts
@@ -1,13 +1,23 @@
 import { StarknetChainId } from '../../constants';
 import { weierstrass } from '../../utils/ec';
-import type { BigNumberish } from '../../utils/num';
-import { Uint256 } from '../../utils/uint256';
 import { CompiledContract, CompiledSierraCasm, ContractClass } from './contract';
 
 export type WeierstrassSignatureType = weierstrass.SignatureType;
 export type ArraySignatureType = string[];
 export type Signature = ArraySignatureType | WeierstrassSignatureType;
 
+export type BigNumberish = string | number | bigint;
+
+/**
+ * Represents an integer in the range [0, 2^256)
+ */
+export interface Uint256 {
+  // The low 128 bits of the value
+  low: BigNumberish;
+  // The high 128 bits of the value
+  high: BigNumberish;
+}
+
 /**
  * BigNumberish array
  * use CallData.compile() to convert to Calldata
@@ -158,8 +168,13 @@ export enum TransactionType {
 }
 
 export type Tupled = { element: any; type: string };
+
 export type BlockTag = 'pending' | 'latest';
 export type BlockNumber = BlockTag | null | number;
+// hex string and BN are detected as block hashes
+// decimal string and number are detected as block numbers
+// null appends nothing to the request url
+export type BlockIdentifier = BlockNumber | BigNumberish;
 
 export type Struct = {
   type: 'struct';
diff --git a/src/types/provider/configuration.ts b/src/types/provider/configuration.ts
new file mode 100644
index 00000000..743e6644
--- /dev/null
+++ b/src/types/provider/configuration.ts
@@ -0,0 +1,32 @@
+import { NetworkName, StarknetChainId } from '../../constants';
+import { BlockIdentifier } from '../lib';
+
+export interface ProviderOptions {
+  sequencer?: SequencerProviderOptions;
+  rpc?: RpcProviderOptions;
+}
+
+export type RpcProviderOptions = {
+  nodeUrl: string;
+  retries?: number;
+  headers?: object;
+  blockIdentifier?: BlockIdentifier;
+  chainId?: StarknetChainId;
+};
+
+export type SequencerHttpMethod = 'POST' | 'GET';
+
+export type SequencerProviderOptions = {
+  headers?: Record<string, string>;
+  blockIdentifier?: BlockIdentifier;
+  chainId?: StarknetChainId;
+} & (
+  | {
+      network: NetworkName | StarknetChainId;
+    }
+  | {
+      baseUrl: string;
+      feederGatewayUrl?: string;
+      gatewayUrl?: string;
+    }
+);
diff --git a/src/types/provider/index.ts b/src/types/provider/index.ts
new file mode 100644
index 00000000..57bf8d7e
--- /dev/null
+++ b/src/types/provider/index.ts
@@ -0,0 +1,2 @@
+export * from './configuration';
+export * from './response';
diff --git a/src/types/provider.ts b/src/types/provider/response.ts
similarity index 97%
rename from src/types/provider.ts
rename to src/types/provider/response.ts
index 39935561..efc9b213 100644
--- a/src/types/provider.ts
+++ b/src/types/provider/response.ts
@@ -3,8 +3,8 @@
  * Intersection (sequencer response ∩ (∪ rpc responses))
  */
 
-import { RPC } from './api/rpc';
-import { Sequencer, TransactionTraceResponse } from './api/sequencer';
+import { RPC } from '../api/rpc';
+import { Sequencer, TransactionTraceResponse } from '../api/sequencer';
 import {
   AllowArray,
   ByteCode,
@@ -16,7 +16,7 @@ import {
   Status,
   TransactionType,
   UniversalDeployerContractPayload,
-} from './lib';
+} from '../lib';
 
 export interface GetBlockResponse {
   timestamp: number;
diff --git a/src/types/signer.ts b/src/types/signer.ts
index 7da2a3b6..c1474f47 100644
--- a/src/types/signer.ts
+++ b/src/types/signer.ts
@@ -1,6 +1,10 @@
 import { StarknetChainId } from '../constants';
-import { BigNumberish } from '../utils/num';
-import { CairoVersion, DeployAccountContractPayload, InvocationsDetails } from './lib';
+import {
+  BigNumberish,
+  CairoVersion,
+  DeployAccountContractPayload,
+  InvocationsDetails,
+} from './lib';
 
 export interface InvocationsSignerDetails extends Required<InvocationsDetails> {
   walletAddress: string;
diff --git a/src/utils/typedData/types.ts b/src/types/typedData.ts
similarity index 100%
rename from src/utils/typedData/types.ts
rename to src/types/typedData.ts
diff --git a/src/utils/address.ts b/src/utils/address.ts
index eeb3d183..310bbfae 100644
--- a/src/utils/address.ts
+++ b/src/utils/address.ts
@@ -2,9 +2,10 @@
 import { hexToBytes } from '@noble/curves/abstract/utils';
 
 import { MASK_251, ZERO } from '../constants';
+import { BigNumberish } from '../types';
 import { addHexPrefix, removeHexPrefix } from './encode';
 import { keccakBn } from './hash';
-import { BigNumberish, assertInRange, toHex } from './num';
+import { assertInRange, toHex } from './num';
 
 export function addAddressPadding(address: BigNumberish): string {
   return addHexPrefix(removeHexPrefix(toHex(address)).padStart(64, '0'));
diff --git a/src/utils/calldata/cairo.ts b/src/utils/calldata/cairo.ts
index 9f17226e..20464926 100644
--- a/src/utils/calldata/cairo.ts
+++ b/src/utils/calldata/cairo.ts
@@ -1,7 +1,7 @@
-import { AbiStructs } from '../../types';
-import { BigNumberish, isBigInt, isHex, isStringWholeNumber } from '../num';
+import { AbiStructs, BigNumberish, Uint256 } from '../../types';
+import { isBigInt, isHex, isStringWholeNumber } from '../num';
 import { encodeShortString, isShortString, isText } from '../shortString';
-import { UINT_128_MAX, Uint256, isUint256 } from '../uint256';
+import { UINT_128_MAX, isUint256 } from '../uint256';
 
 export enum Uint {
   u8 = 'core::integer::u8',
diff --git a/src/utils/calldata/requestParser.ts b/src/utils/calldata/requestParser.ts
index 16c4bfe2..710cc750 100644
--- a/src/utils/calldata/requestParser.ts
+++ b/src/utils/calldata/requestParser.ts
@@ -1,5 +1,4 @@
-import { AbiEntry, AbiStructs, ParsedStruct, Tupled } from '../../types';
-import { BigNumberish } from '../num';
+import { AbiEntry, AbiStructs, BigNumberish, ParsedStruct, Tupled } from '../../types';
 import { isText, splitLongString } from '../shortString';
 import {
   felt,
diff --git a/src/utils/calldata/responseParser.ts b/src/utils/calldata/responseParser.ts
index fc48ce91..2d4c92f9 100644
--- a/src/utils/calldata/responseParser.ts
+++ b/src/utils/calldata/responseParser.ts
@@ -1,6 +1,5 @@
 /* eslint-disable no-case-declarations */
-import { AbiEntry, AbiStructs, Args, ParsedStruct } from '../../types';
-import { BigNumberish } from '../num';
+import { AbiEntry, AbiStructs, Args, BigNumberish, ParsedStruct } from '../../types';
 import { uint256ToBN } from '../uint256';
 import {
   getArrayType,
diff --git a/src/utils/calldata/validate.ts b/src/utils/calldata/validate.ts
index 86407300..51cd94bd 100644
--- a/src/utils/calldata/validate.ts
+++ b/src/utils/calldata/validate.ts
@@ -1,10 +1,10 @@
-import { AbiEntry, AbiStructs, FunctionAbi } from '../../types';
 /**
  * Validate cairo contract method arguments
  * Flow: Determine type from abi and than validate against parameter
  */
+import { AbiEntry, AbiStructs, BigNumberish, FunctionAbi } from '../../types';
 import assert from '../assert';
-import { BigNumberish, toBigInt } from '../num';
+import { toBigInt } from '../num';
 import { isLongText } from '../shortString';
 import { uint256ToBN } from '../uint256';
 import {
diff --git a/src/utils/hash.ts b/src/utils/hash.ts
index 7842b66b..2fcaabc2 100644
--- a/src/utils/hash.ts
+++ b/src/utils/hash.ts
@@ -4,6 +4,7 @@ import { poseidonHashMany } from 'micro-starknet';
 
 import { API_VERSION, StarknetChainId, TransactionHashPrefix } from '../constants';
 import {
+  BigNumberish,
   Builtins,
   CompiledContract,
   CompiledSierra,
@@ -13,13 +14,13 @@ import {
   RawArgs,
   RawCalldata,
   SierraContractEntryPointFields,
-} from '../types/lib';
+} from '../types';
 import { CallData } from './calldata';
 import { felt } from './calldata/cairo';
 import { starkCurve } from './ec';
 import { addHexPrefix, utf8ToArray } from './encode';
 import { parse, stringify } from './json';
-import { BigNumberish, toBigInt, toHex } from './num';
+import { toBigInt, toHex } from './num';
 import { getSelectorFromName } from './selector';
 import { encodeShortString } from './shortString';
 
diff --git a/src/utils/json.ts b/src/utils/json.ts
index 87a3ca3c..dbe313d3 100644
--- a/src/utils/json.ts
+++ b/src/utils/json.ts
@@ -16,5 +16,5 @@ export const parseAlwaysAsBig = (x: string): any =>
 // NOTE: the not-null assertion is used so the return type conforms to JSON.stringify()
 // which can also return undefined but is not represented in the default typing
 export const stringify = (...p: Parameters<typeof json.stringify>): string => json.stringify(...p)!;
-/** @deprecated */
+/** @deprecated equivalent to 'stringify', alias will be removed */
 export const stringifyAlwaysAsBig = stringify;
diff --git a/src/utils/num.ts b/src/utils/num.ts
index bfc6c351..05dea848 100644
--- a/src/utils/num.ts
+++ b/src/utils/num.ts
@@ -1,9 +1,11 @@
 import { hexToBytes as hexToBytesNoble } from '@noble/curves/abstract/utils';
 
+import { BigNumberish } from '../types';
 import assert from './assert';
 import { addHexPrefix, removeHexPrefix } from './encode';
 
-export type BigNumberish = string | number | bigint;
+/** @deprecated prefer importing from 'types' over 'num' */
+export type { BigNumberish };
 
 export function isHex(hex: string): boolean {
   return /^0x[0-9a-f]*$/i.test(hex);
diff --git a/src/utils/selector.ts b/src/utils/selector.ts
index 097a1188..9afc941d 100644
--- a/src/utils/selector.ts
+++ b/src/utils/selector.ts
@@ -1,8 +1,9 @@
 import { keccak } from 'micro-starknet';
 
 import { MASK_250 } from '../constants';
+import { BigNumberish } from '../types';
 import { addHexPrefix, removeHexPrefix, utf8ToArray } from './encode';
-import { BigNumberish, hexToBytes, isHex, isStringWholeNumber, toHex, toHexString } from './num';
+import { hexToBytes, isHex, isStringWholeNumber, toHex, toHexString } from './num';
 
 /**
  * Keccak hash BigNumberish value
diff --git a/src/utils/stark.ts b/src/utils/stark.ts
index 388596f8..9c4ba501 100644
--- a/src/utils/stark.ts
+++ b/src/utils/stark.ts
@@ -1,11 +1,10 @@
 import { getStarkKey, utils } from 'micro-starknet';
 import { gzip } from 'pako';
 
-import { ArraySignatureType, CompressedProgram, Program, Signature } from '../types';
+import { ArraySignatureType, BigNumberish, CompressedProgram, Program, Signature } from '../types';
 import { addHexPrefix, btoaUniversal } from './encode';
 import { stringify } from './json';
 import {
-  BigNumberish,
   bigNumberishArrayToDecimalStringArray,
   bigNumberishArrayToHexadecimalStringArray,
   toBigInt,
diff --git a/src/utils/transaction.ts b/src/utils/transaction.ts
index 95426e4d..cbda79ed 100644
--- a/src/utils/transaction.ts
+++ b/src/utils/transaction.ts
@@ -1,7 +1,7 @@
-import { CairoVersion, Call, CallStruct, Calldata, ParsedStruct } from '../types';
+import { BigNumberish, CairoVersion, Call, CallStruct, Calldata, ParsedStruct } from '../types';
 import { CallData } from './calldata';
 import { getSelectorFromName } from './hash';
-import { BigNumberish, toBigInt } from './num';
+import { toBigInt } from './num';
 
 /**
  * Transforms a list of Calls, each with their own calldata, into
diff --git a/src/utils/typedData/index.ts b/src/utils/typedData.ts
similarity index 89%
rename from src/utils/typedData/index.ts
rename to src/utils/typedData.ts
index b6cedf00..d3387bb8 100644
--- a/src/utils/typedData/index.ts
+++ b/src/utils/typedData.ts
@@ -1,11 +1,11 @@
-import { computeHashOnElements, getSelectorFromName } from '../hash';
-import { MerkleTree } from '../merkle';
-import { BigNumberish, isHex, toHex } from '../num';
-import { encodeShortString } from '../shortString';
-import { StarkNetMerkleType, StarkNetType, TypedData } from './types';
-import { validateTypedData } from './utils';
+import { BigNumberish, StarkNetMerkleType, StarkNetType, TypedData } from '../types';
+import { computeHashOnElements, getSelectorFromName } from './hash';
+import { MerkleTree } from './merkle';
+import { isHex, toHex } from './num';
+import { encodeShortString } from './shortString';
 
-export * from './types';
+/** @deprecated prefer importing from 'types' over 'typedData' */
+export * from '../types/typedData';
 
 function getHex(value: BigNumberish): string {
   try {
@@ -18,6 +18,21 @@ function getHex(value: BigNumberish): string {
   }
 }
 
+/**
+ * Validates that `data` matches the EIP-712 JSON schema.
+ *
+ * @param {any} data
+ * @return {boolean}
+ */
+const validateTypedData = (data: unknown): data is TypedData => {
+  const typedData = data as TypedData;
+
+  // Validate that the data matches the EIP-712 JSON schema
+  const valid = Boolean(typedData.types && typedData.primaryType && typedData.message);
+
+  return valid;
+};
+
 export function prepareSelector(selector: string): string {
   return isHex(selector) ? selector : getSelectorFromName(selector);
 }
diff --git a/src/utils/typedData/utils.ts b/src/utils/typedData/utils.ts
deleted file mode 100644
index 59d71473..00000000
--- a/src/utils/typedData/utils.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { TypedData } from './types';
-
-/**
- * Validates that `data` matches the EIP-712 JSON schema.
- *
- * @param {any} data
- * @return {boolean}
- */
-export const validateTypedData = (data: unknown): data is TypedData => {
-  const typedData = data as TypedData;
-
-  // Validate that the data matches the EIP-712 JSON schema
-  const valid = Boolean(typedData.types && typedData.primaryType && typedData.message);
-
-  return valid;
-};
diff --git a/src/utils/uint256.ts b/src/utils/uint256.ts
index 78bdfd1e..4cd9a206 100644
--- a/src/utils/uint256.ts
+++ b/src/utils/uint256.ts
@@ -1,14 +1,10 @@
 /* eslint-disable no-bitwise */
+import { BigNumberish, Uint256 } from '../types';
 import { addHexPrefix } from './encode';
-import { BigNumberish, toBigInt } from './num';
+import { toBigInt } from './num';
 
-// Represents an integer in the range [0, 2^256).
-export interface Uint256 {
-  // The low 128 bits of the value.
-  low: BigNumberish;
-  // The high 128 bits of the value.
-  high: BigNumberish;
-}
+/** @deprecated prefer importing from 'types' over 'uint256' */
+export type { Uint256 };
 
 // function to convert Uint256 to BN
 export function uint256ToBN(uint256: Uint256) {


Test patch:
diff --git a/__tests__/cairo1.test.ts b/__tests__/cairo1.test.ts
index 06683e23..b8940c73 100644
--- a/__tests__/cairo1.test.ts
+++ b/__tests__/cairo1.test.ts
@@ -1,5 +1,6 @@
 import {
   Account,
+  BigNumberish,
   CallData,
   Calldata,
   Contract,
@@ -260,8 +261,8 @@ describeIfDevnetSequencer('Cairo 1 Devnet Sequencer', () => {
     test('myCallData.compile for Cairo 1', async () => {
       const myFalseUint256 = { high: 1, low: 23456 }; // wrong order
       type Order2 = {
-        p1: num.BigNumberish;
-        p2: num.BigNumberish[];
+        p1: BigNumberish;
+        p2: BigNumberish[];
       };
 
       const myOrder2bis: Order2 = {
diff --git a/__tests__/contract.test.ts b/__tests__/contract.test.ts
index 525a7414..da2cdc31 100644
--- a/__tests__/contract.test.ts
+++ b/__tests__/contract.test.ts
@@ -1,8 +1,8 @@
-import { Contract, ContractFactory, RawArgs, json, stark } from '../src';
+import { BigNumberish, Contract, ContractFactory, RawArgs, json, stark } from '../src';
 import { CallData } from '../src/utils/calldata';
 import { felt, tuple, uint256 } from '../src/utils/calldata/cairo';
 import { getSelectorFromName } from '../src/utils/hash';
-import { BigNumberish, hexToDecimalString, toBigInt } from '../src/utils/num';
+import { hexToDecimalString, toBigInt } from '../src/utils/num';
 import { encodeShortString } from '../src/utils/shortString';
 import { uint256ToBN } from '../src/utils/uint256';
 import {
diff --git a/__tests__/utils/address.test.ts b/__tests__/utils/address.test.ts
index df8c48db..69687fda 100644
--- a/__tests__/utils/address.test.ts
+++ b/__tests__/utils/address.test.ts
@@ -4,7 +4,6 @@ import {
   validateAndParseAddress,
   validateChecksumAddress,
 } from '../../src/utils/address';
-// import { addHexPrefix, removeHexPrefix } from '../../src/utils/encode';
 
 describe('validateAndParseAddress', () => {
   test('should pass when correct starknet address is passed', () => {
diff --git a/__tests__/utils/typedData.test.ts b/__tests__/utils/typedData.test.ts
index 690408bc..e6b975bf 100644
--- a/__tests__/utils/typedData.test.ts
+++ b/__tests__/utils/typedData.test.ts
@@ -1,12 +1,10 @@
 import typedDataExample from '../../__mocks__/typedDataExample.json';
 import typedDataSessionExample from '../../__mocks__/typedDataSessionExample.json';
 import typedDataStructArrayExample from '../../__mocks__/typedDataStructArrayExample.json';
-import { num } from '../../src';
+import { BigNumberish, StarkNetDomain, num } from '../../src';
 import { getSelectorFromName } from '../../src/utils/hash';
 import { MerkleTree } from '../../src/utils/merkle';
-import { BigNumberish } from '../../src/utils/num';
 import {
-  StarkNetDomain,
   encodeType,
   encodeValue,
   getMessageHash,