Skip to content

Commit

Permalink
feat: use blockchain parameter in relevant generateWallet occurrences
Browse files Browse the repository at this point in the history
  • Loading branch information
dlbnco committed Jul 26, 2022
1 parent 120e962 commit 8282e2f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 9 deletions.
19 changes: 19 additions & 0 deletions src/generateWallet/generateWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ export const coinTypeFromString = (s: string): CoinType => {
return m[s]
}

export const blockchainFromString = (name: string): Blockchain => {
switch (name) {
case 'btc':
return Blockchain.BTC
case 'eth':
return Blockchain.ETH
case 'neo':
return Blockchain.NEO
case 'avaxc':
return Blockchain.AVAXC
case 'polygon':
return Blockchain.POLYGON
case 'neo3':
return Blockchain.NEO3
default:
throw new Error('Unsupported name')
}
}

export function neoGetPublicKeyFromPrivateKey(privateKey: string, encode: boolean = true): string {
const privateKeyBuffer = Buffer.from(privateKey, 'hex')
const keypair = curve.keyFromPrivate(privateKeyBuffer, 'hex')
Expand Down
9 changes: 7 additions & 2 deletions src/initialize/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { Wallet, Config, InitParams } from '../types'
import decryptSecretKey from '../decryptSecretKey'
import secretKeyToMnemonic from '../secretKeyToMnemonic'
import mnemonicToMasterSeed from '../mnemonicToMasterSeed'
import { generateNashPayloadSigningKey, generateWallet, coinTypeFromString } from '../generateWallet'
import {
generateNashPayloadSigningKey,
generateWallet,
coinTypeFromString,
blockchainFromString
} from '../generateWallet'
// import { cryptoWaitReady } from '@polkadot/util-crypto'

// initialize takes in the init parameters and returns a Config object with all the
Expand All @@ -17,7 +22,7 @@ export default async function initialize(params: InitParams): Promise<Config> {
// if (name.toLowerCase() === 'dot') {
// await cryptoWaitReady()
// }
wallets[name] = generateWallet(masterSeed, coinTypeFromString(name), index, params.net)
wallets[name] = generateWallet(masterSeed, coinTypeFromString(name), index, params.net, blockchainFromString(name))
}

const payloadSigningKey = generateNashPayloadSigningKey(masterSeed, 1)
Expand Down
45 changes: 38 additions & 7 deletions src/mpc/generateAPIKeys.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createAPIKey } from './createAPIKey'
import { GenerateApiKeysParams, BIP44, APIKey } from '../types/MPC'
import { GenerateApiKeysParams, BIP44, APIKey, Blockchain } from '../types/MPC'
import secretKeyToMnemonic from '../secretKeyToMnemonic'
import bufferize from '../bufferize'
import mnemonicToMasterSeed from '../mnemonicToMasterSeed'
Expand All @@ -11,17 +11,48 @@ export async function generateAPIKeys(params: GenerateApiKeysParams): Promise<AP
const masterSeed = mnemonicToMasterSeed(secretKeyToMnemonic(secretBuff))
const payloadSigningKey = generateNashPayloadSigningKey(masterSeed, 1)

const btcWallet = generateWallet(masterSeed, coinTypeFromString('btc'), params.walletIndices.btc, params.net)
const ethWallet = generateWallet(masterSeed, coinTypeFromString('eth'), params.walletIndices.eth, params.net)
const neoWallet = generateWallet(masterSeed, coinTypeFromString('neo'), params.walletIndices.neo, params.net)
const avaxcWallet = generateWallet(masterSeed, coinTypeFromString('avaxc'), params.walletIndices.avaxc, params.net)
const btcWallet = generateWallet(
masterSeed,
coinTypeFromString('btc'),
params.walletIndices.btc,
params.net,
Blockchain.BTC
)
const ethWallet = generateWallet(
masterSeed,
coinTypeFromString('eth'),
params.walletIndices.eth,
params.net,
Blockchain.ETH
)
const neoWallet = generateWallet(
masterSeed,
coinTypeFromString('neo'),
params.walletIndices.neo,
params.net,
Blockchain.NEO
)
const avaxcWallet = generateWallet(
masterSeed,
coinTypeFromString('avaxc'),
params.walletIndices.avaxc,
params.net,
Blockchain.AVAXC
)
const polygonWallet = generateWallet(
masterSeed,
coinTypeFromString('polygon'),
params.walletIndices.polygon,
params.net
params.net,
Blockchain.POLYGON
)
const neo3Wallet = generateWallet(
masterSeed,
coinTypeFromString('neo3'),
params.walletIndices.neo3,
params.net,
Blockchain.NEO3
)
const neo3Wallet = generateWallet(masterSeed, coinTypeFromString('neo3'), params.walletIndices.neo3, params.net)

const btcSecret = btcWallet.privateKey
const ethSecret = ethWallet.privateKey
Expand Down

0 comments on commit 8282e2f

Please sign in to comment.