diff --git a/src/generateWallet/generateWallet.ts b/src/generateWallet/generateWallet.ts index 14b8916a..eee68685 100644 --- a/src/generateWallet/generateWallet.ts +++ b/src/generateWallet/generateWallet.ts @@ -27,6 +27,7 @@ export enum CoinType { DOT = 354, ERD = 508, NEO = 888, + NEO3 = 888, POLYGON = 966, AVAXC = 9000 } @@ -99,6 +100,7 @@ export const coinTypeFromString = (s: string): CoinType => { eth: CoinType.ETH, ltc: CoinType.LTC, neo: CoinType.NEO, + neo3: CoinType.NEO3, polygon: CoinType.POLYGON } @@ -109,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 63afc77a..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,15 +11,47 @@ export async function generateAPIKeys(params: GenerateApiKeysParams): Promise = { [Blockchain.NEO]: 'Secp256r1', [Blockchain.AVAXC]: 'Secp256k1', [Blockchain.POLYGON]: 'Secp256k1', - [Blockchain.NEO3]: 'Secp256r1', + [Blockchain.NEO3]: 'Secp256r1' } export interface PallierPK { @@ -87,6 +87,7 @@ export enum BIP44 { BTC = "m/44'/0'/0'/0/0", ETH = "m/44'/60'/0'/0/0", NEO = "m/44'/888'/0'/0/0", + NEO3 = "m/44'/888'/1'/0/0", POLYGON = "m/44'/966'/0'/0/0", AVAXC = "m/44'/9000'/0'/0/0" } @@ -111,6 +112,7 @@ export interface APIKey { */ [BIP44.AVAXC]?: ChildKey [BIP44.POLYGON]?: ChildKey + [BIP44.NEO3]?: ChildKey } payload_signing_key: string payload_public_key: string