From 8282e2feeb8ec6e0c06d61eef48d48617977e8ff Mon Sep 17 00:00:00 2001 From: Mateus Dal Bianco Date: Tue, 26 Jul 2022 11:13:35 -0300 Subject: [PATCH] feat: use blockchain parameter in relevant generateWallet occurrences --- src/generateWallet/generateWallet.ts | 19 ++++++++++++ src/initialize/initialize.ts | 9 ++++-- src/mpc/generateAPIKeys.ts | 45 +++++++++++++++++++++++----- 3 files changed, 64 insertions(+), 9 deletions(-) diff --git a/src/generateWallet/generateWallet.ts b/src/generateWallet/generateWallet.ts index c5a3ceaa..eee68685 100644 --- a/src/generateWallet/generateWallet.ts +++ b/src/generateWallet/generateWallet.ts @@ -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') diff --git a/src/initialize/initialize.ts b/src/initialize/initialize.ts index 60ce3eed..c9e21855 100644 --- a/src/initialize/initialize.ts +++ b/src/initialize/initialize.ts @@ -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 @@ -17,7 +22,7 @@ export default async function initialize(params: InitParams): Promise { // 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) diff --git a/src/mpc/generateAPIKeys.ts b/src/mpc/generateAPIKeys.ts index 48e42221..b815d4b5 100644 --- a/src/mpc/generateAPIKeys.ts +++ b/src/mpc/generateAPIKeys.ts @@ -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' @@ -11,17 +11,48 @@ export async function generateAPIKeys(params: GenerateApiKeysParams): Promise