-
Notifications
You must be signed in to change notification settings - Fork 129
Description
Hello:
I want to port some old code to new code. I am trying to create some QTUM wallet, which has the derivePath of "m/88'/0'/0'".
The Wallet definition for QTUM looks like this:
export class Wallet {
public address: string
private insight: Insight
constructor(public keyPair: bip32.BIP32Interface,
public network: INetworkInfo)
{
this.address = this.keyPair.toBase58();
this.insight = Insight.forNetwork(this.network)
}
I want to use the following TS code:
import * as ecc from 'tiny-secp256k1';
import { BIP32Factory } from 'bip32';
export class Network {
constructor(public info: INetworkInfo) {}
/**
*/
public fromMnemonic(mnemonic: string, password?: string): Wallet {
const hdNode = ethers.HDNodeWallet.fromMnemonic(mnemonic, password);
const accountNode = hdNode.derivePath("m/88'/0'/0'");
const privateKey = accountNode.privateKey;
const bip32 = BIP32Factory(ecc);
const chainCode = accountNode.chainCode;
const node = bip32.fromPrivateKey(Buffer.from(privateKey), Buffer.from(chainCode));
const keyPair = KeyPair.fromPrivateKey(Buffer.from(privateKey));
return new Wallet(keyPair, this.info);
}
But the keyPair is not correct. I think keyPair is only one data type for private_key and public_key, right?
However, I don’t know how to get a public key from the private key.
Please let me know how can I make the code to work?
PS: I am using Node.js version 20.2 on Windows 10 (22H2)
Thanks,