1- import * as assert from "assert" ;
21import { 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' ;
53import { sr25519CreateDerive } from "@polkadot-labs/hdkd"
6- import { convertPublicKeyToSs58 } from "../src/address-utils"
74import { DEV_PHRASE , entropyToMiniSecret , mnemonicToEntropy , KeyPair } from "@polkadot-labs/hdkd-helpers"
85import { getPolkadotSigner } from "polkadot-api/signer"
96import { randomBytes } from 'crypto' ;
107import { Keyring } from '@polkadot/keyring' ;
118import { SS58_PREFIX , TX_TIMEOUT } from "./config" ;
129import { getClient } from "./setup"
10+
1311let 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+
4755export function getRandomSubstrateSigner ( ) {
4856 const keypair = getRandomSubstrateKeypair ( ) ;
4957 return getSignerFromKeypair ( keypair )
0 commit comments