crypto-ducatus-wallet-core
Version:
A multi-currency support library for address derivation, private key creation, and transaction creation
22 lines (20 loc) • 978 B
text/typescript
const BitcoreLibCash = require('bitcore-lib-cash');
import { AbstractBitcoreLibDeriver } from '../btc';
export class BchDeriver extends AbstractBitcoreLibDeriver {
bitcoreLib = BitcoreLibCash;
deriveAddress(network, pubKey, addressIndex, isChange) {
const xpub = new this.bitcoreLib.HDPublicKey(pubKey, network);
const changeNum = isChange ? 1 : 0;
const path = `m/${changeNum}/${addressIndex}`;
return this.bitcoreLib.Address(xpub.derive(path).publicKey, network).toString(true);
}
derivePrivateKey(network, xPriv, addressIndex, isChange) {
const xpriv = new this.bitcoreLib.HDPrivateKey(xPriv, network);
const changeNum = isChange ? 1 : 0;
const path = `m/${changeNum}/${addressIndex}`;
const privKey = xpriv.derive(path).privateKey;
const pubKey = privKey.publicKey;
const address = this.bitcoreLib.Address(pubKey, network).toString(true);
return { address, privKey: privKey.toString(), pubKey: pubKey.toString() };
}
}