Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor (chain = { network: networks.bitcoin }, mode = 'p2wsh') {
super()
this._network = chain.network
if (!['p2wsh', 'p2shSegwit', 'p2sh'].includes(mode)) {
throw new Error('Mode must be one of p2wsh, p2sSegwit, p2sh')
}
this._mode = mode
if (this._network.name === networks.bitcoin.name) {
this._bitcoinJsNetwork = bitcoin.networks.mainnet
} else if (this._network.name === networks.bitcoin_testnet.name) {
this._bitcoinJsNetwork = bitcoin.networks.testnet
} else if (this._network.name === networks.bitcoin_regtest.name) {
this._bitcoinJsNetwork = bitcoin.networks.regtest
}
}
import WalletProvider from '@liquality/wallet-provider'
import JsonRpcProvider from '@liquality/jsonrpc-provider'
import BitcoinNetworks from '@liquality/bitcoin-networks'
import { AddressTypes } from '@liquality/bitcoin-utils'
import * as bitcoin from 'bitcoinjs-lib'
import { sha256 } from '@liquality/crypto'
import { Address, addressToString } from '@liquality/utils'
import _ from 'lodash'
import { version } from '../package.json'
const BIP70_CHAIN_TO_NETWORK = {
'main': BitcoinNetworks.bitcoin,
'test': BitcoinNetworks.bitcoin_testnet,
'regtest': BitcoinNetworks.bitcoin_regtest
}
export default class BitcoinNodeWalletProvider extends WalletProvider {
constructor (network, uri, username, password, addressType = 'bech32') {
super()
if (!AddressTypes.includes(addressType)) {
throw new Error(`addressType must be one of ${AddressTypes.join(',')}`)
}
this._addressType = addressType
this._network = network
this._rpc = new JsonRpcProvider(uri, username, password)
}
async signMessage (message, from) {
from = addressToString(from)
return this._rpc.jsonrpc('signmessage', from, message).then(result => Buffer.from(result, 'base64').toString('hex'))