const AdoracoreLib = require('@adora-wallet/adoracore-lib-btc'); import { IDeriver } from '..'; export abstract class AbstractAdoracoreLibDeriver implements IDeriver { public abstract adoracoreLib; deriveAddress(network, pubKey, addressIndex, isChange) { const xpub = new this.adoracoreLib.HDPublicKey(pubKey, network); const changeNum = isChange ? 1 : 0; const path = `m/${changeNum}/${addressIndex}`; return this.adoracoreLib.Address(xpub.derive(path).publicKey, network).toString(); } derivePrivateKey(network, xPriv, addressIndex, isChange) { const xpriv = new this.adoracoreLib.HDPrivateKey(xPriv, network); const changeNum = isChange ? 1 : 0; const path = `m/${changeNum}/${addressIndex}`; const privKey = xpriv.deriveChild(path).privateKey; const pubKey = privKey.publicKey; const address = this.adoracoreLib.Address(pubKey, network).toString(); return { address, privKey: privKey.toString(), pubKey: pubKey.toString() }; } } export class BtcDeriver extends AbstractAdoracoreLibDeriver { adoracoreLib = AdoracoreLib; }