chaingate
Version:
A complete TypeScript library for connecting to and making transactions on different blockchains
48 lines • 2.45 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BitcoinCash = void 0;
const Utils_1 = require("../../../../../Utils/Utils");
const bitcore_lib_cash_1 = __importDefault(require("bitcore-lib-cash"));
const bchaddrjs_1 = require("bchaddrjs");
const Utxo_1 = require("../../abstract/Utxo/Utxo");
const BitcoinCashPreparedTransaction_1 = require("./BitcoinCashPreparedTransaction");
Object.defineProperty(global, '_bitcoreCash', { get() { return undefined; }, set() { }, configurable: true });
class BitcoinCash extends Utxo_1.Utxo {
constructor(api, currencyProviders) {
super({
symbol: 'BCH',
id: 'bitcoin-cash',
name: 'Bitcoin Cash',
svgLogoUrl: (0, Utils_1.buildUrlWithApiKey)('https://api.chaingate.dev/bitcoincash/logo'),
decimals: 8,
defaultDerivationPath: 'm/44\'/145\'/0\'/0/0',
minimalUnitSymbol: 'satoshi',
commonDerivationPaths: ['m/44\'/145\'/0\'/0/0']
}, api, currencyProviders, {
bech32: 'bc',
pubKeyHash: 0x00,
scriptHash: 0x05,
wif: 0x80
});
}
async getAddress(addressType = 'cashaddr') {
const publicKey = await (await this.currencyProviders.getPublicKeyProvider(this.currencyInfo))();
const publicKeyRaw = publicKey.raw;
const publicKeyBch = new bitcore_lib_cash_1.default.PublicKey((0, Utils_1.bytesToHex)(publicKeyRaw, false));
const bchAddr = bitcore_lib_cash_1.default.Address.fromPublicKey(publicKeyBch, bitcore_lib_cash_1.default.Networks.mainnet).toCashAddress();
switch (addressType) {
case 'legacy': return (0, bchaddrjs_1.toLegacyAddress)(bchAddr);
case 'cashaddr': return bchAddr;
case 'bitpay': return (0, bchaddrjs_1.toCashAddress)(bchAddr);
}
}
async createTransfer(toAddress, amount) {
const privateKeyProvider = await this.currencyProviders.getPrivateKeyProvider(this.currencyInfo);
return new BitcoinCashPreparedTransaction_1.BitcoinCashPreparedTransaction(this.api, this.currencyProviders, this.currencyInfo, await this.getAddress(), toAddress, amount, privateKeyProvider);
}
}
exports.BitcoinCash = BitcoinCash;
//# sourceMappingURL=BitcoinCash.js.map