Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@getsafle/vault-bitcoin-controller

Package Overview
Dependencies
Maintainers
4
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@getsafle/vault-bitcoin-controller - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

6

CHANGELOG.md

@@ -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

2

package.json
{
"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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc