From dedb856cd9b550cdd8bde7e1d4b1c5b6b62ea215 Mon Sep 17 00:00:00 2001 From: Mateus Dal Bianco Date: Mon, 11 Jul 2022 19:26:54 -0300 Subject: [PATCH 1/4] feat(neo3): add types --- src/generateWallet/generateWallet.ts | 12 ++++++++++++ src/mpc/generateAPIKeys.ts | 13 +++++++++++++ src/types/MPC.ts | 4 +++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/generateWallet/generateWallet.ts b/src/generateWallet/generateWallet.ts index 14b8916a..d821e261 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 } @@ -180,6 +182,16 @@ function generateWalletForCoinType(key: bip32.BIP32Interface, coinType: CoinType privateKey: neoPrivKey, publicKey } + case CoinType.NEO3: { + const neoPrivKey = key.privateKey.toString('hex') + // TODO: figure out private key -> public key -> address + return { + address: '', + index, + privateKey: neoPrivKey, + publicKey: '' + } + } case CoinType.ETH: case CoinType.ETC: case CoinType.AVAXC: diff --git a/src/mpc/generateAPIKeys.ts b/src/mpc/generateAPIKeys.ts index 63afc77a..48e42221 100644 --- a/src/mpc/generateAPIKeys.ts +++ b/src/mpc/generateAPIKeys.ts @@ -21,12 +21,14 @@ 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 From ce96d575a89084bac2965dd412ffd3ea4f54eff2 Mon Sep 17 00:00:00 2001 From: Mateus Dal Bianco Date: Mon, 11 Jul 2022 19:35:07 -0300 Subject: [PATCH 2/4] chore(generateWallet): change shadowed variable name --- src/generateWallet/generateWallet.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/generateWallet/generateWallet.ts b/src/generateWallet/generateWallet.ts index d821e261..6fa808c2 100644 --- a/src/generateWallet/generateWallet.ts +++ b/src/generateWallet/generateWallet.ts @@ -182,16 +182,15 @@ function generateWalletForCoinType(key: bip32.BIP32Interface, coinType: CoinType privateKey: neoPrivKey, publicKey } - case CoinType.NEO3: { - const neoPrivKey = key.privateKey.toString('hex') + case CoinType.NEO3: + const neo3PrivKey = key.privateKey.toString('hex') // TODO: figure out private key -> public key -> address return { address: '', index, - privateKey: neoPrivKey, + privateKey: neo3PrivKey, publicKey: '' } - } case CoinType.ETH: case CoinType.ETC: case CoinType.AVAXC: From 120e9623fadb8ba7d549560abf4c7c1c04eb7039 Mon Sep 17 00:00:00 2001 From: Mateus Dal Bianco Date: Mon, 18 Jul 2022 15:14:38 -0300 Subject: [PATCH 3/4] fix(generateWallet): remove NEO3 case --- src/generateWallet/generateWallet.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/generateWallet/generateWallet.ts b/src/generateWallet/generateWallet.ts index 6fa808c2..c5a3ceaa 100644 --- a/src/generateWallet/generateWallet.ts +++ b/src/generateWallet/generateWallet.ts @@ -182,15 +182,6 @@ function generateWalletForCoinType(key: bip32.BIP32Interface, coinType: CoinType privateKey: neoPrivKey, publicKey } - case CoinType.NEO3: - const neo3PrivKey = key.privateKey.toString('hex') - // TODO: figure out private key -> public key -> address - return { - address: '', - index, - privateKey: neo3PrivKey, - publicKey: '' - } case CoinType.ETH: case CoinType.ETC: case CoinType.AVAXC: From 8282e2feeb8ec6e0c06d61eef48d48617977e8ff Mon Sep 17 00:00:00 2001 From: Mateus Dal Bianco Date: Tue, 26 Jul 2022 11:13:35 -0300 Subject: [PATCH 4/4] 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