Skip to content

Commit 67617d7

Browse files
committed
fix: use function consistently
1 parent e08e4b5 commit 67617d7

File tree

12 files changed

+50
-42
lines changed

12 files changed

+50
-42
lines changed

__tests__/ec.test.ts renamed to __tests__/ellipticalCurve.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getKeyPair, getStarkKey, hashCalldata, hashMessage, pedersen, sign } from '../src';
2-
import { removeHexPrefix } from '../src/utils/enc';
2+
import { removeHexPrefix } from '../src/utils/encode';
33
import { toBN, toHex } from '../src/utils/number';
44

55
test('does work with package', () => {

__tests__/wallet.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
utils,
1212
waitForTx,
1313
} from '../src';
14-
import { addHexPrefix } from '../src/utils/enc';
14+
import { addHexPrefix } from '../src/utils/encode';
1515
import { toBN } from '../src/utils/number';
1616

1717
const {

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { toBN } from './utils/number';
22

3-
export { IS_BROWSER } from './utils/enc';
3+
export { IS_BROWSER } from './utils/encode';
44

55
export const ZERO = toBN(0);
66
export const ONE = toBN(1);

src/contract.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ import { getSelectorFromName } from './utils/starknet';
99
type Args = { [inputName: string]: string | string[] };
1010
type Calldata = string[];
1111

12-
const parseFelt = (candidate: string): BN => {
12+
function parseFelt(candidate: string): BN {
1313
try {
1414
return toBN(candidate);
1515
} catch (e) {
1616
throw Error('Couldnt parse felt');
1717
}
18-
};
18+
}
1919

20-
const isFelt = (candidate: string): boolean => {
20+
function isFelt(candidate: string): boolean {
2121
try {
2222
parseFelt(candidate);
2323
return true;
2424
} catch (e) {
2525
return false;
2626
}
27-
};
27+
}
2828

2929
export class Contract {
3030
connectedTo: string | null = null;

src/ec.ts renamed to src/ellipticalCurve.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import hashJS from 'hash.js';
33
import assert from 'minimalistic-assert';
44

55
import { CONSTANT_POINTS, EC_ORDER, FIELD_PRIME, MAX_ECDSA_VAL, ONE, ZERO } from './constants';
6-
import { addHexPrefix, removeHexPrefix, sanitizeBytes } from './utils/enc';
6+
import { addHexPrefix, removeHexPrefix, sanitizeBytes } from './utils/encode';
77
import { BigNumberish, assertInRange, toBN, toHex } from './utils/number';
88

99
export const ec = new EC(
@@ -40,17 +40,17 @@ function fixMessage(msg: string) {
4040

4141
export const genKeyPair = ec.genKeyPair.bind(ec);
4242

43-
export const getKeyPair = (pk: BigNumberish): EC.KeyPair => {
43+
export function getKeyPair(pk: BigNumberish): EC.KeyPair {
4444
const pkBn = toBN(pk);
4545
return ec.keyFromPrivate(removeHexPrefix(toHex(pkBn)), 'hex');
46-
};
46+
}
4747

48-
export const getStarkKey = (keyPair: EC.KeyPair): string => {
48+
export function getStarkKey(keyPair: EC.KeyPair): string {
4949
// this method needs to be run to generate the .pub property used below
5050
// the result can be dumped
5151
keyPair.getPublic(true, 'hex');
5252
return addHexPrefix(sanitizeBytes((keyPair as any).pub.getX().toString(16), 2));
53-
};
53+
}
5454

5555
/*
5656
Signs a message using the provided key.

src/starknet.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ export function deployContract(
213213
});
214214
}
215215

216-
const wait = (delay: number) => new Promise((res) => setTimeout(res, delay));
216+
function wait(delay: number) {
217+
return new Promise((res) => setTimeout(res, delay));
218+
}
217219
export async function waitForTx(txId: number, retryInterval: number = 2000) {
218220
let onchain = false;
219221
while (!onchain) {

src/utils/enc.ts renamed to src/utils/encode.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ export const IS_BROWSER = typeof window !== 'undefined';
33

44
const STRING_ZERO = '0';
55

6-
export const arrayBufferToString = (array: ArrayBuffer): string =>
7-
String.fromCharCode.apply(null, array as unknown as number[]);
6+
export function arrayBufferToString(array: ArrayBuffer): string {
7+
return String.fromCharCode.apply(null, array as unknown as number[]);
8+
}
89

9-
export const btoaUniversal = (b: ArrayBuffer): string =>
10-
IS_BROWSER ? btoa(arrayBufferToString(b)) : Buffer.from(b).toString('base64');
10+
export function btoaUniversal(b: ArrayBuffer): string {
11+
return IS_BROWSER ? btoa(arrayBufferToString(b)) : Buffer.from(b).toString('base64');
12+
}
1113

12-
export const buf2hex = (buffer: Uint8Array) =>
13-
[...buffer].map((x) => x.toString(16).padStart(2, '0')).join('');
14+
export function buf2hex(buffer: Uint8Array) {
15+
return [...buffer].map((x) => x.toString(16).padStart(2, '0')).join('');
16+
}
1417

1518
/**
1619
* Some function imported from https://github.com/pedrouid/enc-utils/blob/master/src/index.ts

src/utils/hash.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { keccak256 } from 'ethereum-cryptography/keccak';
33
import assert from 'minimalistic-assert';
44

55
import { CONSTANT_POINTS, FIELD_PRIME, MASK_250, ONE, ZERO } from '../constants';
6-
import { ec } from '../ec';
7-
import { addHexPrefix, buf2hex, utf8ToArray } from './enc';
6+
import { ec } from '../ellipticalCurve';
7+
import { addHexPrefix, buf2hex, utf8ToArray } from './encode';
88
import { BigNumberish, toBN } from './number';
99

10-
const keccakHex = (value: string): string => addHexPrefix(buf2hex(keccak256(utf8ToArray(value))));
10+
function keccakHex(value: string): string {
11+
return addHexPrefix(buf2hex(keccak256(utf8ToArray(value))));
12+
}
1113

1214
/**
1315
* Function to get the starknet keccak hash from a string

src/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * as enc from './enc';
1+
export * as enc from './encode';
22
export * as hash from './hash';
33
export * as json from './json';
44
export * as number from './number';

src/utils/number.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
import BN from 'bn.js';
22
import assert from 'minimalistic-assert';
33

4-
import { addHexPrefix, removeHexPrefix } from './enc';
4+
import { addHexPrefix, removeHexPrefix } from './encode';
55

66
export type BigNumberish = string | number | BN;
77

8-
export const isHex = (hex: string): boolean => {
8+
export function isHex(hex: string): boolean {
99
return hex.startsWith('0x');
10-
};
10+
}
1111

12-
export const toBN = (number: BigNumberish, base?: number | 'hex') => {
12+
export function toBN(number: BigNumberish, base?: number | 'hex') {
1313
if (typeof number === 'string' && isHex(number) && !base)
1414
return new BN(removeHexPrefix(number), 'hex');
1515
return new BN(number, base);
16-
};
16+
}
1717

18-
export const toHex = (number: BN): string => {
18+
export function toHex(number: BN): string {
1919
return addHexPrefix(number.toString('hex'));
20-
};
20+
}
2121

22-
export const hexToDecimalString = (hex: string): string =>
23-
toBN(`0x${hex.replace(/^0x/, '')}`).toString();
22+
export function hexToDecimalString(hex: string): string {
23+
return toBN(`0x${hex.replace(/^0x/, '')}`).toString();
24+
}
2425

2526
/*
2627
Asserts input is equal to or greater then lowerBound and lower then upperBound.

0 commit comments

Comments
 (0)