@bitcoinerlab/discovery
Version:
A TypeScript library for retrieving Bitcoin funds from ranged descriptors, leveraging @bitcoinerlab/explorer for standardized access to multiple blockchain explorers.
41 lines (40 loc) • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNetwork = exports.getNetworkId = void 0;
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
const types_1 = require("./types");
const getNetworkId = (network) => {
if (network.bech32 === 'bc')
return types_1.NetworkId.BITCOIN;
if (network.bech32 === 'bcrt')
return types_1.NetworkId.REGTEST;
if (network.bech32 === 'tb')
return types_1.NetworkId.TESTNET;
if (network.bech32 === 'sb')
return types_1.NetworkId.SIGNET;
throw new Error('Unknown network');
};
exports.getNetworkId = getNetworkId;
const getNetwork = (networkId) => {
if (networkId === types_1.NetworkId.BITCOIN) {
return bitcoinjs_lib_1.networks.bitcoin;
}
else if (networkId === types_1.NetworkId.REGTEST) {
return bitcoinjs_lib_1.networks.regtest;
}
else if (networkId === types_1.NetworkId.TESTNET) {
return bitcoinjs_lib_1.networks.testnet;
}
else if (networkId === types_1.NetworkId.SIGNET) {
//As of June 2023 not part of bitcoinjs-lib
if (!('signet' in bitcoinjs_lib_1.networks)) {
throw new Error('Signet not implemented yet in bitcoinjs-lib');
}
else
return bitcoinjs_lib_1.networks.signet;
}
else {
throw new Error(`Invalid networkId ${networkId}`);
}
};
exports.getNetwork = getNetwork;