Skip to content

Commit 3420f1f

Browse files
committed
refacto crypto helpers
1 parent 06db80f commit 3420f1f

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

evm-tests/src/substrate.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import * as assert from "assert";
21
import { devnet, MultiAddress } from '@polkadot-api/descriptors';
3-
import { createClient, TypedApi, Transaction, PolkadotSigner, Binary } from 'polkadot-api';
4-
import { getWsProvider } from 'polkadot-api/ws-provider/web';
2+
import { TypedApi, Transaction, PolkadotSigner, Binary } from 'polkadot-api';
53
import { sr25519CreateDerive } from "@polkadot-labs/hdkd"
6-
import { convertPublicKeyToSs58 } from "../src/address-utils"
74
import { DEV_PHRASE, entropyToMiniSecret, mnemonicToEntropy, KeyPair } from "@polkadot-labs/hdkd-helpers"
85
import { getPolkadotSigner } from "polkadot-api/signer"
96
import { randomBytes } from 'crypto';
107
import { Keyring } from '@polkadot/keyring';
118
import { SS58_PREFIX, TX_TIMEOUT } from "./config";
129
import { getClient } from "./setup"
10+
1311
let api: TypedApi<typeof devnet> | undefined = undefined
1412

1513
// define url string as type to extend in the future
@@ -24,26 +22,36 @@ export async function getDevnetApi() {
2422
return api
2523
}
2624

27-
export function getAlice() {
25+
export function getKeypairFromPath(path: string) {
2826
const entropy = mnemonicToEntropy(DEV_PHRASE)
2927
const miniSecret = entropyToMiniSecret(entropy)
3028
const derive = sr25519CreateDerive(miniSecret)
31-
const hdkdKeyPair = derive("//Alice")
29+
const hdkdKeyPair = derive(path)
3230

3331
return hdkdKeyPair
3432
}
3533

36-
export function getAliceSigner() {
37-
const alice = getAlice()
34+
export const getAlice = () => getKeypairFromPath("//Alice")
35+
export const getBob = () => getKeypairFromPath("//Bob")
36+
export const getCharlie = () => getKeypairFromPath("//Charlie")
37+
export const getDave = () => getKeypairFromPath("//Dave")
38+
39+
export function getSignerFromPath(path: string) {
40+
const keypair = getKeypairFromPath(path)
3841
const polkadotSigner = getPolkadotSigner(
39-
alice.publicKey,
42+
keypair.publicKey,
4043
"Sr25519",
41-
alice.sign,
44+
keypair.sign,
4245
)
4346

4447
return polkadotSigner
4548
}
4649

50+
export const getAliceSigner = () => getSignerFromPath("//Alice")
51+
export const getBobSigner = () => getSignerFromPath("//Bob")
52+
export const getCharlieSigner = () => getSignerFromPath("//Charlie")
53+
export const getDaveSigner = () => getSignerFromPath("//Dave")
54+
4755
export function getRandomSubstrateSigner() {
4856
const keypair = getRandomSubstrateKeypair();
4957
return getSignerFromKeypair(keypair)

0 commit comments

Comments
 (0)