You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Matias Alejo Garcia 9630ba906c remove vim files 11 years ago
browser Added some tests for Script 11 years ago
examples remove vim files 11 years ago
src Rename compiled binding to KeyModule. 11 years ago
test fix Transaction for node 11 years ago
util remove strict 11 years ago
.gitignore remove vim files 11 years ago
.jshintrc tests work in browser and node 11 years ago
Address.js remove use strict 11 years ago
Block.js replace tabs with 2 spaces using "expand" 11 years ago
Bloom.js replace tabs with 2 spaces using "expand" 11 years ago
Buffers.monkey.js add some needed monkey patches 11 years ago
Connection.js add reject message handler 11 years ago
Deserialize.js replace tabs with 2 spaces using "expand" 11 years ago
Gruntfile.js add Readme.md compilation in grunt 11 years ago
Key.js Add PrivateKey, Key classes. Update test to enc/dec private key test vectors. 11 years ago
LICENSE Update LICENSE 11 years ago
Number.monkey.js add some needed monkey patches 11 years ago
Opcode.js bunch of interim (broken) stuff 11 years ago
Peer.js bunch of interim (broken) stuff 11 years ago
PeerManager.js pass network param from PeerManager to Connection 11 years ago
PrivateKey.js fix validate math error 11 years ago
README.md add some examples to README and examples/ path 11 years ago
RpcClient.js Merge pull request #28 from matiu/feature/handle-403-HTTP 11 years ago
SIN.js replace tabs with 2 spaces using "expand" 11 years ago
SINKey.js replace tabs with 2 spaces using "expand" 11 years ago
Script.js replace tabs with 2 spaces using "expand" 11 years ago
ScriptInterpreter.js replace tabs with 2 spaces using "expand" 11 years ago
Sign.js replace tabs with 2 spaces using "expand" 11 years ago
Transaction.js remove "use strict" which is causing problems. 11 years ago
Wallet.js replace tabs with 2 spaces using "expand" 11 years ago
WalletKey.js replace tabs with 2 spaces using "expand" 11 years ago
binding.gyp Rename compiled binding to KeyModule. 11 years ago
bitcore.js fix Transaction for node 11 years ago
config.js fix logger variable name 11 years ago
const.js replace tabs with 2 spaces using "expand" 11 years ago
networks.js Normalized object notation 11 years ago
package.json Merge branch 'bug/fix-node-Transaction' of github.com:maraoz/bitcore into feature/better-docs 11 years ago

README.md

Bitcore

A pure, powerful core for your bitcoin project.

Bitcore is a complete, native interface to the Bitcoin network, and provides the core functionality needed to develop apps for bitcoin.

#Principles Bitcoin is a powerful new peer-to-peer platform for the next generation of financial technology. The decentralized nature of the Bitcoin network allows for highly resilient bitcoin infrastructure, and the developer community needs reliable, open-source tools to implement bitcoin apps and services.

Bitcore unchains developers from fallible, centralized APIs, and provides the tools to interact with the real Bitcoin network.

#Get Started

Bitcore runs on node, and can be installed via npm:

npm install bitcore

It is a collection of objects useful to bitcoin applications; class-like idioms are enabled via Classtool. In most cases, a developer will require the object's class directly:

var Address = require('bitcore/Address').class();

#Examples

Some examples are provided at the examples path. Here are some snippets:

Address handling

Validating a Bitcoin address:

var Address = require('bitcore/Address').class();
var addr = new Address("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa");

try {
  addr.validate();
  console.log("Address is valid.");
} catch(e) {
  console.log(addr.data + " is not a valid address. " + e);
}

Monitoring Blocks and Transactions

var networks    = require('bitcore/networks');
var Peer        = require('bitcore/Peer').class();
var PeerManager = require('bitcore/PeerManager').createClass({
  network: networks.livenet
});

var handleBlock = function(b) {
  console.log('block received:', b);
};
var handleTx = function(b) {
  console.log('block tx:', b);
};
var peerman = new PeerManager();
peerman.addPeer( new Peer('62.75.216.13',8333) );
peerman.addPeer( new Peer('62.75.253.91',8333) );
peerman.on('connection', function(conn) {
  conn.on('block', handleBlock);
  conn.on('tx', handleTx);
});
peerman.start();

PeerManager will emit the following events: 'version', 'verack', 'addr', 'getaddr', 'error' 'disconnect'; and will relay events like: 'tx', 'block', 'inv'. Please see PeerManager.js, Peer.js and Connection.js

Create and send a Transaction thought P2P

var networks    = require('bitcore/networks');
var Peer        = require('bitcore/Peer').class();
var Transaction = require('bitcore/Transaction').class();
var Address     = require('bitcore/Address').class();
var Script      = require('bitcore/Script').class();
var coinUtil    = require('bitcore/util/util');
var PeerManager = require('bitcore/PeerManager').createClass({
  network: networks.testnet
});

var createTx = function() {
  var TXIN='d05f35e0bbc495f6dcab03e599c8f5e32a07cdb4bc76964de201d06a2a7d8265';
  var TXIN_N=0;
  var ADDR='muHct3YZ9Nd5Pq7uLYYhXRAxeW4EnpcaLz';
  var VAL='1.234';
  var txobj = {};
  txobj.version = 1;
  txobj.lock_time = 0;
  txobj.ins = [];
  txobj.outs = [];
  var txin = {};
  txin.s = coinUtil.EMPTY_BUFFER;   //Add signature
  txin.q = 0xffffffff;

  var hash = new Buffer(TXIN, 'hex');
  hash.reverse();
  var vout = parseInt(TXIN_N);
  var voutBuf = new Buffer(4);
  voutBuf.writeUInt32LE(vout, 0);
  txin.o = Buffer.concat([hash, voutBuf]);
  txobj.ins.push(txin);

  var addr = new Address(ADDR);
  var script = Script.createPubKeyHashOut(addr.payload());
  var valueNum = coinUtil.parseValue(VAL);
  var value = coinUtil.bigIntToValue(valueNum);

  var txout = {
    v: value,
    s: script.getBuffer(),
  };
  txobj.outs.push(txout);

  return new Transaction(txobj);
};

var peerman = new PeerManager();
peerman.addPeer( new Peer('127.0.0.1',18333) );
peerman.on('connect', function(conn) {
  var conn = peerman.getActiveConnection();
  if (conn)
    conn.sendTx(createTx());
  conn.on('reject', function () { console.log('Transaction Rejected'); } );
});
peerman.start();

RPC Client

var RpcClient = require('../RpcClient').class();
var config =  {   
   protocol:  'http',
   user:  'user',
   pass:  'pass',
   host:  '127.0.0.1',
   port:  '18332',
};
var rpc   = new RpcClient(config);
rpc.getBlock( hash,  function(err, ret) {
  console.log(err);
  console.log(util.inspect(ret, { depth: 10} ));
});

Check the list of all supported RPC call at RpcClient.js

Script Parsing

Gets an address strings from a ScriptPubKey Buffer

  var Address = require('bitcore/Address').class();
  var coinUtil= require('bitcore/util/util');

  var getAddrStr = function(s) {
    var addrStrs = [];
    var type = s.classify();
    var addr;

    switch (type) {
      case Script.TX_PUBKEY:
        var chunk = s.captureOne();
        addr = new Address(network.addressPubkey, coinUtil.sha256ripe160(chunk));
        addrStrs.push(addr.toString());
        break;
      case Script.TX_PUBKEYHASH:
        addr = new Address(network.addressPubkey, s.captureOne());
        addrStrs.push(addr.toString());
        break;
      case Script.TX_SCRIPTHASH:
        addr = new Address(network.addressScript, s.captureOne());
        addrStrs.push(addr.toString());
        break;
      case Script.TX_MULTISIG:
        var chunks = s.capture();
        chunks.forEach(function(chunk) {
          var a = new Address(network.addressPubkey, coinUtil.sha256ripe160(chunk));
          addrStrs.push(a.toString());
        });
        break;
      case Script.TX_UNKNOWN:
        break;
    }
    return addrStrs;
  };

  var s = new Script(scriptBuffer);
  console.log(getAddrStr(s);
  

#Security Please use at your own risk.

Bitcore is still under heavy development and not quite ready for "drop-in" production use. If you find a security issue, please email security@bitcore.io.

#Contributing Bitcore needs some developer love. Please send pull requests for bug fixes, code optimization, and ideas for improvement.

Work to enable Bitcore for use in the browser is ongoing. To build bitcore for the browser:

npm install -g grunt-cli
grunt browserify

#License

Code released under the MIT license.

Copyright 2013-2014 BitPay, Inc. Bitcore is a trademark maintained by BitPay, Inc.

Bitdeli Badge