Bitcoin Forum
May 23, 2024, 04:29:36 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to securely sign and publish Bitcoin transaction (using Bitcore JS library)?  (Read 163 times)
Anonymous Kid (OP)
Member
**
Offline Offline

Activity: 183
Merit: 25


View Profile
May 04, 2018, 01:51:22 PM
Last edit: May 04, 2018, 04:41:22 PM by Anonymous Kid
 #1

Is this a secure way to sign and publish a transaction or can the node intercept the private key?

Code:
var bitcore = require('bitcore');

let privateKey = "11111111111111111111111111";
let address = "1aaaaaaaaaaaaaaaaaaaa";
let amount = 100;

//creates transaction
var transaction = new bitcore.Transaction();
var transaction.from(<insert UTXO>).to(address, amount);
transaction.sign(privateKey);
transaction.serialize();

//Bitpay's tools
var Insight = require('bitcore-explorers').Insight;
var insight = new Insight('testnet');

//broadcasts transaction using bitpay's server
insight.broadcast(transaction, function (err, id) {
    if (err) {
      console.log(err);
    } else {
      console.log("Transaction Id: " + id);
    }
};

hatshepsut93
Legendary
*
Offline Offline

Activity: 2968
Merit: 2147


View Profile
May 06, 2018, 10:15:30 AM
Last edit: May 06, 2018, 04:09:20 PM by hatshepsut93
Merited by ABCbits (1)
 #2

It's generally a bad practice to have crypto keys in your source code, because often times developers forget about them and then accidentally expose them by commiting their code on github or sharing the it through other means. The solutions is environmental variables, there are plenty of guides of how to use them for Javascript developers, like this one: https://www.twilio.com/blog/2017/08/working-with-environment-variables-in-node-js.html

Is this a secure way to sign and publish a transaction or can the node intercept the private key?

What do you mean "intercept private key"? In that example the key is in the code, so your node process obviously knows it. If you are working on backend, then your whole codebase should be perfect and you need to always check the news for potential zero-day vulnerabilities, it's often enough to have just one vulnerability to give attackers full access to your servers and steal everything from hot wallets. This is why Bitcoin services keep most of their funds in cold wallets.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!