-
Notifications
You must be signed in to change notification settings - Fork 33
/
genSigners.ts
35 lines (31 loc) · 1.02 KB
/
genSigners.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { BigNumber, Wallet } from "ethers";
import { ec, number } from "starknet-410";
import { BASE_DERIVATION_PATHS } from "./getAccounts";
import { getPathForIndex, getStarkPair } from "./keyDerivation";
export function equalSigner(a: string, b: string): boolean {
return BigNumber.from(a).eq(b);
}
interface Signer {
signer: string;
privateKey: string;
derivationPath?: string;
}
const amountOfSignersToGenerate = 20;
export function getDefaultSigners(seedPhrase?: string): Array<Signer> {
if (!seedPhrase) {
return [];
}
const privateKey = Wallet.fromMnemonic(seedPhrase).privateKey;
const arr = new Array(amountOfSignersToGenerate).fill(0);
const keypairs = BASE_DERIVATION_PATHS.flatMap((p) =>
arr.map((_, i) => ({
keyPair: getStarkPair(i, privateKey, p),
derivationPath: getPathForIndex(i, p),
}))
);
return keypairs.map(({ keyPair, ...rest }) => ({
...rest,
signer: ec.getStarkKey(keyPair),
privateKey: number.toHex(number.toBN(keyPair.getPrivate().toString())),
}));
}