@getsafle/vault-bitcoin-controller
Advanced tools
Comparing version 1.2.3 to 2.0.0
@@ -41,2 +41,7 @@ ### 1.0.0 (2021-12-27) | ||
- UTXO.satoshi calculation and adding package `satoshi-bitcoin`. | ||
- UTXO.satoshi calculation and adding package `satoshi-bitcoin`. | ||
### 2.0.0 (2023-09-25) | ||
##### Sochain api update for UTXO calculation | ||
##### Derivation path update for the P2WPKH standard addresses |
{ | ||
"name": "@getsafle/vault-bitcoin-controller", | ||
"version": "1.2.3", | ||
"version": "2.0.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "engines": { |
module.exports = { | ||
bitcoin: { | ||
HD_PATH: `m/44'/0'/0'/0`, | ||
HD_PATH: `m/84'/0'/0'/0`, | ||
}, | ||
@@ -18,3 +18,4 @@ bitcoin_transaction: { | ||
}, | ||
SATOSHI: 100000000 | ||
SATOSHI: 100000000, | ||
SOCHAIN_API_KEY: 'F7RKphrzItSQV-MUoPY_S0XIuwTzxFpt' | ||
} |
@@ -5,3 +5,3 @@ const axios = require('axios') | ||
async function getFeeAndInput(URL, satPerByte) { | ||
async function getFeeAndInput(URL, satPerByte, headers) { | ||
@@ -11,3 +11,9 @@ let fee = 0; | ||
let outputCount = 2; | ||
const utxos = await axios.get(URL); | ||
const utxos = await axios({ | ||
url : `${URL}`, | ||
// url: 'https://sochain.com/api/v3/unspent_outputs/BTC/bc1q7cyrfmck2ffu2ud3rn5l5a8yv6f0chkp0zpemf', | ||
method: 'GET', | ||
headers: headers | ||
}); | ||
@@ -17,9 +23,9 @@ let totalAmountAvailable = 0; | ||
let inputs = []; | ||
utxos.data.data.txs.forEach(async (element) => { | ||
utxos.data.data.outputs.forEach(async (element) => { | ||
let utxo = {}; | ||
utxo.satoshis = sb.toSatoshi(parseFloat(element.value)); | ||
utxo.script = element.script_hex; | ||
utxo.address = utxos.data.data.address; | ||
utxo.txId = element.txid; | ||
utxo.outputIndex = element.output_no; | ||
utxo.script = element.script; | ||
utxo.address = element.address; | ||
utxo.txId = element.hash; | ||
utxo.outputIndex = element.index; | ||
totalAmountAvailable += utxo.satoshis; | ||
@@ -26,0 +32,0 @@ inputCount += 1; |
@@ -6,3 +6,3 @@ const bitcore = require("bitcore-lib") | ||
async function signTransaction(from, to, amountToSend, URL, privateKey, satPerByte) { | ||
async function signTransaction(from, to, amountToSend, URL, privateKey, satPerByte, headers) { | ||
@@ -13,3 +13,3 @@ const satoshiToSend = amountToSend * SATOSHI; | ||
const { totalAmountAvailable, inputs, fee } = await getFeeAndInput(URL, satPerByte) | ||
const { totalAmountAvailable, inputs, fee } = await getFeeAndInput(URL, satPerByte, headers) | ||
@@ -16,0 +16,0 @@ if (totalAmountAvailable - satoshiToSend - fee < 0) { |
@@ -11,3 +11,3 @@ const ObservableStore = require('obs-store') | ||
const { bitcoin: { HD_PATH }, bitcoin_transaction: { NATIVE_TRANSFER }, bitcoin_network: { MAINNET, TESTNET } } = require('./config/index') | ||
const { bitcoin: { HD_PATH }, bitcoin_transaction: { NATIVE_TRANSFER }, bitcoin_network: { MAINNET, TESTNET }, SOCHAIN_API_KEY } = require('./config/index') | ||
@@ -84,6 +84,7 @@ class KeyringController { | ||
throw "Invalid address, the address is not available in the wallet" | ||
const URL = `https://sochain.com/api/v2/get_tx_unspent/${networkType === TESTNET.NETWORK ? 'BTCTEST' : "BTC"}/${from}` | ||
const URL = `https://sochain.com/api/v3/unspent_outputs/${networkType === TESTNET.NETWORK ? 'BTCTEST' : "BTC"}/${from}` | ||
const headers = { "API-KEY": SOCHAIN_API_KEY} | ||
const { privkey } = helpers.utils.generateAddress(wallet, network, idx) | ||
try { | ||
const signedTransaction = await helpers.signTransaction(from, to, amount, URL, privkey, satPerByte) | ||
const signedTransaction = await helpers.signTransaction(from, to, amount, URL, privkey, satPerByte, headers) | ||
return { signedTransaction }; | ||
@@ -109,13 +110,15 @@ } catch (err) { | ||
async sendTransaction(rawTransaction) { | ||
async sendTransaction(TransactionHex) { | ||
const { networkType } = this.store.getState() | ||
try { | ||
const headers = { "API-KEY": SOCHAIN_API_KEY} | ||
const result = await axios({ | ||
method: "POST", | ||
url: `https://sochain.com/api/v2/send_tx/${networkType === TESTNET.NETWORK ? 'BTCTEST' : "BTC"}`, | ||
url: `https://chain.so/api/v3/broadcast_transaction/${networkType === TESTNET.NETWORK ? 'BTCTEST' : "BTC"}`, | ||
data: { | ||
tx_hex: rawTransaction, | ||
tx_hex: TransactionHex, | ||
}, | ||
headers: headers, | ||
}); | ||
return { transactionDetails: result && result.data && result.data.data ? result.data.data.txid : result } | ||
return { transactionDetails: result && result.data && result.data.data ? result.data.data.hash : result } | ||
} catch (err) { | ||
@@ -129,4 +132,5 @@ throw err | ||
try { | ||
const URL = `https://sochain.com/api/v2/get_tx_unspent/${networkType === TESTNET.NETWORK ? 'BTCTEST' : "BTC"}/${address}` | ||
const { totalAmountAvailable, inputs, fee } = await helpers.getFeeAndInput(URL, satPerByte) | ||
const URL = `https://sochain.com/api/v3/unspent_outputs/${networkType === TESTNET.NETWORK ? 'BTCTEST' : "BTC"}/${address}` | ||
const headers = { "API-KEY": SOCHAIN_API_KEY} | ||
const { totalAmountAvailable, inputs, fee } = await helpers.getFeeAndInput(URL, satPerByte, headers) | ||
return { transactionFees: fee } | ||
@@ -154,5 +158,10 @@ } catch (err) { | ||
try { | ||
const URL = `https://sochain.com/api/v2/get_address_balance/${networkType === TESTNET.NETWORK ? 'BTCTEST' : "BTC"}/${address}` | ||
const balance = await axios.get(URL) | ||
return { balance: balance.data.data.confirmed_balance } | ||
const URL = `https://sochain.com/api/v3/balance/${networkType === TESTNET.NETWORK ? 'BTCTEST' : "BTC"}/${address}` | ||
const headers = { "API-KEY": SOCHAIN_API_KEY} | ||
const balance = await axios({ | ||
url : `${URL}`, | ||
method: 'GET', | ||
headers: headers | ||
}); | ||
return { balance: balance.data.data.confirmed } | ||
} catch (err) { | ||
@@ -159,0 +168,0 @@ throw err |
module.exports = { | ||
HD_WALLET_12_MNEMONIC_TEST_OTHER: 'orange lecture tiger surround narrow much novel arrange sample balance weapon bacon', | ||
HD_WALLET_12_MNEMONIC: 'affair entry detect broom axis crawl found valve bamboo taste broken hundred', | ||
HD_WALLET_24_MNEMONIC: 'begin pyramid grit rigid mountain stamp legal item result peace wealth supply satoshi elegant roof identify furnace march west chicken pen gorilla spot excuse', | ||
EXTERNAL_ACCOUNT_PRIVATE_KEY_MAINNET: "KxF7H3kLetxkVG2545MhhW3vGi6NViLMAhhPfU9M6Qirdx8Thrnw", // works on MAINNET ONLY | ||
EXTERNAL_ACCOUNT_ADDRESS_MAINNET: "bc1qtqectlurn5uhgzdym8ehn8ssxu0vamwsm9he0v", | ||
EXTERNAL_ACCOUNT_PRIVATE_KEY: "cSmqQzpnXgQamBLsNqGXJXEbDx6X9Co1yuUTCpikXLtv8ChNssiY", // works on TESTNET ONLY | ||
EXTERNAL_ACCOUNT_ADDRESS: "tb1qfl644sg3vcyv3gk6h4e8yc8jsmndpclhgusm3p", | ||
HD_WALLET_12_MNEMONIC : 'uphold job voyage bunker attract similar ship pear soda security rubber offer', | ||
EXTERNAL_ACCOUNT_PRIVATE_KEY_MAINNET: "L51zqNpZY6pgVz8ggXFghXRSvuub8PvsHLhQy3w4uyX1CHQgurRb", // works on MAINNET ONLY | ||
EXTERNAL_ACCOUNT_ADDRESS_MAINNET: "bc1q7nv22l23wyu4vtq869sgzke3j9swetvytxxcla", | ||
EXTERNAL_ACCOUNT_PRIVATE_KEY: "L2dwGhW8XfBCiJw4GQ9nmumA4APwYZVNRDxXKdPQvAVQ8zHn3VAG", // works on MAINNET ONLY | ||
EXTERNAL_ACCOUNT_ADDRESS: "bc1q7e5yrgec5sq4xz80um9yp5kazahpu20tg9d3ta", | ||
EXTERNAL_ACCOUNT_WRONG_PRIVATE_KEY_1: "random_private_key", | ||
@@ -20,3 +19,3 @@ EXTERNAL_ACCOUNT_WRONG_PRIVATE_KEY_2: "0xbcb7a8680126610ca94440b020280f9ef829ad26637bfb5cc", | ||
TRANSFER_BTC: { | ||
BTC_RECEIVER: 'tb1qrgz6q6mmm6gxplyg00k5ehkhf76qlx7x083k38', // address at index 1 | ||
BTC_RECEIVER: 'bc1qgkw48n0d74krmvq7d50nechkeqf057p7gyyl7r', // address at index 1 | ||
BTC_AMOUNT: 0.00001 | ||
@@ -23,0 +22,0 @@ }, |
@@ -35,3 +35,3 @@ var assert = require('assert'); | ||
mnemonic: HD_WALLET_12_MNEMONIC, | ||
network: TESTNET | ||
network: MAINNET | ||
} | ||
@@ -38,0 +38,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23535
422
1