Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
createScript (address) {
address = addressToString(address)
const type = base58.decode(address).toString('hex').substring(0, 2).toUpperCase()
const pubKeyHash = addressToPubKeyHash(address)
if (type === networks.bitcoin_testnet.pubKeyHash) {
return [
'76', // OP_DUP
'a9', // OP_HASH160
'14', // data size to be pushed
pubKeyHash, //
'88', // OP_EQUALVERIFY
'ac' // OP_CHECKSIG
].join('')
} else if (type === networks.bitcoin_testnet.scriptHash) {
return [
'a9', // OP_HASH160
'14', // data size to be pushed
pubKeyHash, //
'87' // OP_EQUAL
].join('')
} else {
createScript (address) {
address = addressToString(address)
const type = base58.decode(address).toString('hex').substring(0, 2).toUpperCase()
const pubKeyHash = addressToPubKeyHash(address)
if (type === networks.bitcoin_testnet.pubKeyHash) {
return [
'76', // OP_DUP
'a9', // OP_HASH160
'14', // data size to be pushed
pubKeyHash, //
'88', // OP_EQUALVERIFY
'ac' // OP_CHECKSIG
].join('')
} else if (type === networks.bitcoin_testnet.scriptHash) {
return [
'a9', // OP_HASH160
'14', // data size to be pushed
pubKeyHash, //
'87' // OP_EQUAL
].join('')
} else {
throw new Error('Not a valid address:', address)
}
}
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)
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
}
}