@getsafle/vault-bitcoin-controller
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -46,2 +46,6 @@ ### 1.0.0 (2021-12-27) | ||
##### Sochain api update for UTXO calculation | ||
##### Derivation path update for the P2WPKH standard addresses | ||
##### Derivation path update for the P2WPKH standard addresses | ||
### 2.0.1 (2023-10-04) | ||
##### Enabled message and transaction signing for imported accounts |
{ | ||
"name": "@getsafle/vault-bitcoin-controller", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -77,13 +77,20 @@ const ObservableStore = require('obs-store') | ||
*/ | ||
async signTransaction(transaction) { | ||
async signTransaction(transaction, _privateKey = null) { | ||
const { wallet, network, address, networkType } = this.store.getState() | ||
const { from, to, amount, satPerByte } = transaction | ||
const idx = address.indexOf(from) | ||
if (idx < 0) | ||
throw "Invalid address, the address is not available in the wallet" | ||
let privateKey = _privateKey | ||
if (!privateKey) { | ||
const idx = address.indexOf(from) | ||
if (idx < 0) | ||
throw "Invalid address, the address is not available in the wallet" | ||
let res = helpers.utils.generateAddress(wallet, network, idx) | ||
privateKey = res.privkey | ||
} | ||
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, headers) | ||
const signedTransaction = await helpers.signTransaction(from, to, amount, URL, privateKey, satPerByte, headers) | ||
return { signedTransaction }; | ||
@@ -95,14 +102,27 @@ } catch (err) { | ||
async signMessage(message, _address) { | ||
async signMessage(message, _address, privateKey = null) { | ||
const { wallet, network, address } = this.store.getState() | ||
const idx = address.indexOf(_address); | ||
if (idx < 0) | ||
throw "Invalid address, the address is not available in the wallet" | ||
try { | ||
const { wallet: _wallet } = helpers.utils.generateAddress(wallet, network, idx) | ||
var signature = bitcoinMessage.sign(message, _wallet.privateKey, _wallet.compressed, { segwitType: 'p2wpkh', extraEntropy: randomBytes(32) }) | ||
if (!privateKey) { | ||
const idx = address.indexOf(_address); | ||
if (idx < 0) | ||
throw "Invalid address, the address is not available in the wallet" | ||
try { | ||
const { wallet: _wallet } = helpers.utils.generateAddress(wallet, network, idx) | ||
var signature = bitcoinMessage.sign(message, _wallet.privateKey, _wallet.compressed, { segwitType: 'p2wpkh', extraEntropy: randomBytes(32) }) | ||
return { signedMessage: signature.toString('base64') }; | ||
} catch (err) { | ||
throw err | ||
} | ||
} | ||
else { | ||
const ec_pair = bitcoinjs.ECPair.fromWIF(privateKey) | ||
var signature = bitcoinMessage.sign(message, ec_pair.privateKey, ec_pair.compressed, { segwitType: 'p2wpkh', extraEntropy: randomBytes(32) }) | ||
return { signedMessage: signature.toString('base64') }; | ||
} catch (err) { | ||
throw err | ||
} | ||
} | ||
@@ -109,0 +129,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
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
24142
433
0