Skip to content

Commit

Permalink
feat: rename number utility namespace to num
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv authored Mar 3, 2023
1 parent 5a7a473 commit 032aadc
Show file tree
Hide file tree
Showing 47 changed files with 65 additions and 56 deletions.
2 changes: 1 addition & 1 deletion __tests__/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Account, Contract, Provider, TransactionStatus, ec, stark } from '../sr
import { uint256 } from '../src/utils/calldata/cairo';
import { parseUDCEvent } from '../src/utils/events';
import { calculateContractAddressFromHash, feeTransactionVersion } from '../src/utils/hash';
import { cleanHex, hexToDecimalString, toBigInt, toHex } from '../src/utils/number';
import { cleanHex, hexToDecimalString, toBigInt, toHex } from '../src/utils/num';
import { encodeShortString } from '../src/utils/shortString';
import { randomAddress } from '../src/utils/stark';
import {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Contract, ContractFactory, 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/number';
import { BigNumberish, hexToDecimalString, toBigInt } from '../src/utils/num';
import { encodeShortString } from '../src/utils/shortString';
import { compileCalldata } from '../src/utils/stark';
import { uint256ToBN } from '../src/utils/uint256';
Expand Down
2 changes: 1 addition & 1 deletion __tests__/defaultProvider.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BlockNumber, GetBlockResponse, LibraryError, Provider, stark } from '../src';
import { toBigInt } from '../src/utils/number';
import { toBigInt } from '../src/utils/num';
import { encodeShortString } from '../src/utils/shortString';
import {
compiledErc20,
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path';

import { Account, ProviderInterface, RpcProvider, SequencerProvider, json } from '../src';
import { CompiledContract, waitForTransactionOptions } from '../src/types';
import { toHex } from '../src/utils/number';
import { toHex } from '../src/utils/num';

const readContract = (name: string): CompiledContract =>
json.parse(
Expand Down
2 changes: 1 addition & 1 deletion __tests__/utils/stark.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';

import { RawArgs, json, stark } from '../../src';
import { toBigInt, toHex } from '../../src/utils/number';
import { toBigInt, toHex } from '../../src/utils/num';

const compiledAccount = json.parse(fs.readFileSync('./__mocks__/Account.json').toString('ascii'));

Expand Down
6 changes: 3 additions & 3 deletions __tests__/utils/typedData.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import typedDataExample from '../../__mocks__/typedDataExample.json';
import typedDataSessionExample from '../../__mocks__/typedDataSessionExample.json';
import typedDataStructArrayExample from '../../__mocks__/typedDataStructArrayExample.json';
import { number } from '../../src';
import { num } from '../../src';
import { getSelectorFromName } from '../../src/utils/hash';
import { MerkleTree } from '../../src/utils/merkle';
import { BigNumberish } from '../../src/utils/number';
import { BigNumberish } from '../../src/utils/num';
import {
StarkNetDomain,
encodeType,
Expand Down Expand Up @@ -155,7 +155,7 @@ describe('typedData', () => {
}
function stringToStringStruct(str: string): StringStruct {
const len = str.length;
const data = str.split('').map((char) => number.toHex(char.charCodeAt(0)));
const data = str.split('').map((char) => num.toHex(char.charCodeAt(0)));
return { len, data };
}

Expand Down
16 changes: 8 additions & 8 deletions __tests__/utils/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { constants, ec, hash, number, stark } from '../../src';
import { constants, ec, hash, num, stark } from '../../src';
import { Block } from '../../src/provider/utils';

const { IS_BROWSER } = constants;
Expand All @@ -9,15 +9,15 @@ test('isNode', () => {

describe('hexToDecimalString()', () => {
test('parse 0xa23', () => {
expect(number.hexToDecimalString('0xa23')).toBe('2595');
expect(num.hexToDecimalString('0xa23')).toBe('2595');
});
});

describe('cleanHex()', () => {
test('parse 0xa23', () => {
expect(number.cleanHex('0x023Ab')).toBe('0x23ab');
expect(number.cleanHex('0x000023Ab')).toBe('0x23ab');
expect(number.cleanHex('0x23Ab')).toBe('0x23ab');
expect(num.cleanHex('0x023Ab')).toBe('0x23ab');
expect(num.cleanHex('0x000023Ab')).toBe('0x23ab');
expect(num.cleanHex('0x23Ab')).toBe('0x23ab');
});
});

Expand Down Expand Up @@ -57,9 +57,9 @@ describe('computeHashOnElements()', () => {
});
test('should return valid hash for valid array', () => {
const res = hash.computeHashOnElements([
number.toBigInt(123782376),
number.toBigInt(213984),
number.toBigInt(128763521321),
num.toBigInt(123782376),
num.toBigInt(213984),
num.toBigInt(128763521321),
]);
expect(res).toMatchInlineSnapshot(
`"0x7b422405da6571242dfc245a43de3b0fe695e7021c148b918cd9cdb462cac59"`
Expand Down
2 changes: 1 addition & 1 deletion src/account/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
feeTransactionVersion,
transactionVersion,
} from '../utils/hash';
import { BigNumberish, toBigInt, toCairoBool, toHex } from '../utils/number';
import { BigNumberish, toBigInt, toCairoBool, toHex } from '../utils/num';
import { parseContract } from '../utils/provider';
import { compileCalldata, estimatedFeeToMaxFee, randomAddress } from '../utils/stark';
import { fromCallsToExecuteCalldata } from '../utils/transaction';
Expand Down
2 changes: 1 addition & 1 deletion src/account/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
TransactionSimulation,
UniversalDeployerContractPayload,
} from '../types';
import { BigNumberish } from '../utils/number';
import { BigNumberish } from '../utils/num';
import { TypedData } from '../utils/typedData/types';

export abstract class AccountInterface extends ProviderInterface {
Expand Down
11 changes: 10 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export * as constants from './constants';
export * as encode from './utils/encode';
export * as hash from './utils/hash';
export * as json from './utils/json';
export * as number from './utils/number';
export * as num from './utils/num';
export * as transaction from './utils/transaction';
export * as stark from './utils/stark';
export * as merkle from './utils/merkle';
Expand All @@ -24,3 +24,12 @@ export * as typedData from './utils/typedData';
export * as ec from './utils/ec';
export * from './utils/address';
export * from './utils/url';

/**
* Deprecated
*/
/* eslint-disable import/first */
import * as num from './utils/num';

/** @deprecated prefer the 'num' naming */
export const number = num;
2 changes: 1 addition & 1 deletion src/provider/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
TransactionSimulationResponse,
waitForTransactionOptions,
} from '../types';
import { BigNumberish } from '../utils/number';
import { BigNumberish } from '../utils/num';
import { ProviderInterface } from './interface';
import { RpcProvider, RpcProviderOptions } from './rpc';
import { SequencerProvider, SequencerProviderOptions } from './sequencer';
Expand Down
2 changes: 1 addition & 1 deletion src/provider/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type {
TransactionSimulationResponse,
waitForTransactionOptions,
} from '../types';
import type { BigNumberish } from '../utils/number';
import type { BigNumberish } from '../utils/num';
import { BlockIdentifier } from './utils';

export abstract class ProviderInterface {
Expand Down
2 changes: 1 addition & 1 deletion src/provider/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import fetch from '../utils/fetchPonyfill';
import { getSelectorFromName } from '../utils/hash';
import { stringify } from '../utils/json';
import { BigNumberish, bigNumberishArrayToHexadecimalStringArray, toHex } from '../utils/number';
import { BigNumberish, bigNumberishArrayToHexadecimalStringArray, toHex } from '../utils/num';
import { parseCalldata, wait } from '../utils/provider';
import { RPCResponseParser } from '../utils/responseParser/rpc';
import { signatureToHexArray } from '../utils/stark';
Expand Down
2 changes: 1 addition & 1 deletion src/provider/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
getHexStringArray,
toBigInt,
toHex,
} from '../utils/number';
} from '../utils/num';
import { parseContract, wait } from '../utils/provider';
import { SequencerAPIResponseParser } from '../utils/responseParser/sequencer';
import { formatSignature, randomAddress, signatureToDecimalArray } from '../utils/stark';
Expand Down
2 changes: 1 addition & 1 deletion src/provider/starknetId.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumberish } from '../utils/number';
import { BigNumberish } from '../utils/num';
import { compileCalldata } from '../utils/stark';
import { getStarknetIdContract, useDecoded, useEncoded } from '../utils/starknetId';
import { ProviderInterface } from './interface';
Expand Down
2 changes: 1 addition & 1 deletion src/provider/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable max-classes-per-file */
import type { BlockNumber, SequencerIdentifier } from '../types';
import { BigNumberish, isHex, toHex } from '../utils/number';
import { BigNumberish, isHex, toHex } from '../utils/num';

/**
*
Expand Down
2 changes: 1 addition & 1 deletion src/signer/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
calculateDeployAccountTransactionHash,
calculateTransactionHash,
} from '../utils/hash';
import { toHex } from '../utils/number';
import { toHex } from '../utils/num';
import { fromCallsToExecuteCalldata } from '../utils/transaction';
import { TypedData, getMessageHash } from '../utils/typedData';
import { SignerInterface } from './interface';
Expand Down
2 changes: 1 addition & 1 deletion src/types/account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BlockIdentifier } from '../provider/utils';
import { BigNumberish } from '../utils/number';
import { BigNumberish } from '../utils/num';
import {
DeclareTransactionReceiptResponse,
EstimateFeeResponse,
Expand Down
2 changes: 1 addition & 1 deletion src/types/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumberish } from '../../utils/number';
import { BigNumberish } from '../../utils/num';
import { Signature } from '../lib';

export type Calldata = string[];
Expand Down
2 changes: 1 addition & 1 deletion src/types/api/sequencer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BlockIdentifier } from '../../provider/utils';
import { BigNumberish } from '../../utils/number';
import { BigNumberish } from '../../utils/num';
import {
Abi,
AllowArray,
Expand Down
2 changes: 1 addition & 1 deletion src/types/lib.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { weierstrass } from '../utils/ec';
import type { BigNumberish } from '../utils/number';
import type { BigNumberish } from '../utils/num';
import { RPC } from './api/rpc';

// Common Signature Type which needs to be imported from weierstrass
Expand Down
2 changes: 1 addition & 1 deletion src/types/signer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StarknetChainId } from '../constants';
import { BigNumberish } from '../utils/number';
import { BigNumberish } from '../utils/num';
import { DeployAccountContractPayload, InvocationsDetails } from './lib';

export interface InvocationsSignerDetails extends Required<InvocationsDetails> {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { arrayify } from '@ethersproject/bytes';
import { MASK_251, ZERO } from '../constants';
import { addHexPrefix, removeHexPrefix } from './encode';
import { keccakBn } from './hash';
import { BigNumberish, assertInRange, toHex } from './number';
import { BigNumberish, assertInRange, toHex } from './num';

export function addAddressPadding(address: BigNumberish): string {
return addHexPrefix(removeHexPrefix(toHex(address)).padStart(64, '0'));
Expand Down
2 changes: 1 addition & 1 deletion src/utils/calldata/cairo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { abiStructs } from '../../types';
import { BigNumberish, isBigInt, isHex, isStringWholeNumber } from '../number';
import { BigNumberish, isBigInt, isHex, isStringWholeNumber } from '../num';
import { encodeShortString, isShortString, isText } from '../shortString';
import { UINT_128_MAX, Uint256, isUint256 } from '../uint256';

Expand Down
2 changes: 1 addition & 1 deletion src/utils/calldata/formatter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isBigInt } from '../number';
import { isBigInt } from '../num';
import { decodeShortString } from '../shortString';

const guard = {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/calldata/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Abi, AbiEntry, Args, Calldata, FunctionAbi, abiStructs } from '../../types';
import assert from '../assert';
import { isBigInt } from '../number';
import { isBigInt } from '../num';
import { isLongText, splitLongString } from '../shortString';
import { felt, isLen } from './cairo';
import formatter from './formatter';
Expand Down
2 changes: 1 addition & 1 deletion src/utils/calldata/requestParser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbiEntry, ParsedStruct, Tupled, abiStructs } from '../../types';
import { BigNumberish } from '../number';
import { BigNumberish } from '../num';
import { isText, splitLongString } from '../shortString';
import { felt, isTypeArray, isTypeFeltArray, isTypeStruct, isTypeTuple } from './cairo';
import extractTupleMemberTypes from './tuple';
Expand Down
2 changes: 1 addition & 1 deletion src/utils/calldata/responseParser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbiEntry, Args, ParsedStruct, abiStructs } from '../../types';
import { BigNumberish } from '../number';
import { BigNumberish } from '../num';
import { isLen, isTypeArray, isTypeTuple } from './cairo';
import extractTupleMemberTypes from './tuple';

Expand Down
2 changes: 1 addition & 1 deletion src/utils/calldata/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AbiEntry, FunctionAbi, abiStructs } from '../../types';
* Flow: Determine type from abi and than validate against parameter
*/
import assert from '../assert';
import { BigNumberish } from '../number';
import { BigNumberish } from '../num';
import { isLongText } from '../shortString';
import { isLen, isTypeArray, isTypeFelt, isTypeStruct, isTypeTuple } from './cairo';

Expand Down
2 changes: 1 addition & 1 deletion src/utils/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UDC } from '../constants';
import { InvokeTransactionReceiptResponse } from '../types/provider';
import { cleanHex } from './number';
import { cleanHex } from './num';

/**
* Parse Transaction Receipt Event from UDC invoke transaction and
Expand Down
2 changes: 1 addition & 1 deletion src/utils/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { felt } from './calldata/cairo';
import { starkCurve } from './ec';
import { addHexPrefix, buf2hex, removeHexPrefix, utf8ToArray } from './encode';
import { parse, stringify } from './json';
import { BigNumberish, isHex, isStringWholeNumber, toBigInt, toHex, toHexString } from './number';
import { BigNumberish, isHex, isStringWholeNumber, toBigInt, toHex, toHexString } from './num';
import { encodeShortString } from './shortString';

export const transactionVersion = 1n;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/merkle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { starkCurve } from './ec';
import { toBigInt } from './number';
import { toBigInt } from './num';

export class MerkleTree {
public leaves: string[];
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/utils/provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CompiledContract, ContractClass, RawCalldata } from '../types';
import { parse } from './json';
import { isHex, toHex } from './number';
import { isHex, toHex } from './num';
import { compressProgram } from './stark';

export function wait(delay: number) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/responseParser/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
GetTransactionResponse,
RPC,
} from '../../types';
import { toBigInt } from '../number';
import { toBigInt } from '../num';
import { ResponseParser } from '.';

type RpcGetBlockResponse = RPC.GetBlockWithTxHashesResponse & {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/responseParser/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
StateUpdateResponse,
TransactionSimulationResponse,
} from '../../types';
import { toBigInt } from '../number';
import { toBigInt } from '../num';
import { parseSignature } from '../stark';
import { ResponseParser } from '.';

Expand Down
2 changes: 1 addition & 1 deletion src/utils/shortString.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addHexPrefix, removeHexPrefix } from './encode';
import { isHex, isStringWholeNumber } from './number';
import { isHex, isStringWholeNumber } from './num';

const TEXT_TO_FELT_MAX_LEN = 31;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/stark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
bigNumberishArrayToHexadecimalStringArray,
toBigInt,
toHex,
} from './number';
} from './num';

/**
* Function to compress compiled cairo program
Expand Down
2 changes: 1 addition & 1 deletion src/utils/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Call, ParsedStruct } from '../types';
import { getSelectorFromName } from './hash';
import { BigNumberish, bigNumberishArrayToDecimalStringArray, toBigInt } from './number';
import { BigNumberish, bigNumberishArrayToDecimalStringArray, toBigInt } from './num';

/**
* Transforms a list of Calls, each with their own calldata, into
Expand Down
2 changes: 1 addition & 1 deletion src/utils/typedData/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { computeHashOnElements, getSelectorFromName } from '../hash';
import { MerkleTree } from '../merkle';
import { BigNumberish, isHex, toHex } from '../number';
import { BigNumberish, isHex, toHex } from '../num';
import { encodeShortString } from '../shortString';
import { StarkNetMerkleType, StarkNetType, TypedData } from './types';
import { validateTypedData } from './utils';
Expand Down
2 changes: 1 addition & 1 deletion src/utils/uint256.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-bitwise */
import { addHexPrefix } from './encode';
import { BigNumberish, toBigInt } from './number';
import { BigNumberish, toBigInt } from './num';

// Represents an integer in the range [0, 2^256).
export interface Uint256 {
Expand Down
2 changes: 1 addition & 1 deletion www/code-examples/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as starknet from 'starknet';

const keyPair = starknet.ec.genKeyPair();
const starkKey = starknet.ec.getStarkKey(keyPair);
const starkKeyInt = starknet.number.toBigInt(starknet.encode.removeHexPrefix(starkKey), 16);
const starkKeyInt = starknet.num.toBigInt(starknet.encode.removeHexPrefix(starkKey), 16);

const { address: walletAddressLocal } = await provider.deployContract({
contract: COMPILED_WALLET_CONTRACT_JSON,
Expand Down
2 changes: 1 addition & 1 deletion www/code-examples/erc20.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as starknet from 'starknet';

const keyPair = starknet.ec.genKeyPair();
const starkKey = starknet.ec.getStarkKey(keyPair);
const starkKeyInt = starknet.number.toBigInt(starknet.encode.removeHexPrefix(starkKey), 16);
const starkKeyInt = starknet.num.toBigInt(starknet.encode.removeHexPrefix(starkKey), 16);

const deployWalletTx = await provider.deployContract({
contract: COMPILED_WALLET_CONTRACT_JSON,
Expand Down
Loading

0 comments on commit 032aadc

Please sign in to comment.