From f3b1c2d292b029f98d9f50918d8826de91401784 Mon Sep 17 00:00:00 2001 From: Eric Martindale Date: Sun, 13 Apr 2014 13:14:27 -0700 Subject: [PATCH 1/7] Cleanup main directory. --- Address.js => lib/Address.js | 0 BIP32.js => lib/BIP32.js | 0 Block.js => lib/Block.js | 0 Bloom.js => lib/Bloom.js | 0 Connection.js => lib/Connection.js | 0 Deserialize.js => lib/Deserialize.js | 0 Key.js => lib/Key.js | 0 Opcode.js => lib/Opcode.js | 0 Peer.js => lib/Peer.js | 0 PeerManager.js => lib/PeerManager.js | 0 Point.js => lib/Point.js | 0 PrivateKey.js => lib/PrivateKey.js | 0 RpcClient.js => lib/RpcClient.js | 0 SIN.js => lib/SIN.js | 0 SINKey.js => lib/SINKey.js | 0 Script.js => lib/Script.js | 0 ScriptInterpreter.js => lib/ScriptInterpreter.js | 0 Sign.js => lib/Sign.js | 0 Transaction.js => lib/Transaction.js | 0 TransactionBuilder.js => lib/TransactionBuilder.js | 0 Wallet.js => lib/Wallet.js | 0 WalletKey.js => lib/WalletKey.js | 0 Buffers.monkey.js => patches/Buffers.monkey.js | 0 Number.monkey.js => patches/Number.monkey.js | 0 24 files changed, 0 insertions(+), 0 deletions(-) rename Address.js => lib/Address.js (100%) rename BIP32.js => lib/BIP32.js (100%) rename Block.js => lib/Block.js (100%) rename Bloom.js => lib/Bloom.js (100%) rename Connection.js => lib/Connection.js (100%) rename Deserialize.js => lib/Deserialize.js (100%) rename Key.js => lib/Key.js (100%) rename Opcode.js => lib/Opcode.js (100%) rename Peer.js => lib/Peer.js (100%) rename PeerManager.js => lib/PeerManager.js (100%) rename Point.js => lib/Point.js (100%) rename PrivateKey.js => lib/PrivateKey.js (100%) rename RpcClient.js => lib/RpcClient.js (100%) rename SIN.js => lib/SIN.js (100%) rename SINKey.js => lib/SINKey.js (100%) rename Script.js => lib/Script.js (100%) rename ScriptInterpreter.js => lib/ScriptInterpreter.js (100%) rename Sign.js => lib/Sign.js (100%) rename Transaction.js => lib/Transaction.js (100%) rename TransactionBuilder.js => lib/TransactionBuilder.js (100%) rename Wallet.js => lib/Wallet.js (100%) rename WalletKey.js => lib/WalletKey.js (100%) rename Buffers.monkey.js => patches/Buffers.monkey.js (100%) rename Number.monkey.js => patches/Number.monkey.js (100%) diff --git a/Address.js b/lib/Address.js similarity index 100% rename from Address.js rename to lib/Address.js diff --git a/BIP32.js b/lib/BIP32.js similarity index 100% rename from BIP32.js rename to lib/BIP32.js diff --git a/Block.js b/lib/Block.js similarity index 100% rename from Block.js rename to lib/Block.js diff --git a/Bloom.js b/lib/Bloom.js similarity index 100% rename from Bloom.js rename to lib/Bloom.js diff --git a/Connection.js b/lib/Connection.js similarity index 100% rename from Connection.js rename to lib/Connection.js diff --git a/Deserialize.js b/lib/Deserialize.js similarity index 100% rename from Deserialize.js rename to lib/Deserialize.js diff --git a/Key.js b/lib/Key.js similarity index 100% rename from Key.js rename to lib/Key.js diff --git a/Opcode.js b/lib/Opcode.js similarity index 100% rename from Opcode.js rename to lib/Opcode.js diff --git a/Peer.js b/lib/Peer.js similarity index 100% rename from Peer.js rename to lib/Peer.js diff --git a/PeerManager.js b/lib/PeerManager.js similarity index 100% rename from PeerManager.js rename to lib/PeerManager.js diff --git a/Point.js b/lib/Point.js similarity index 100% rename from Point.js rename to lib/Point.js diff --git a/PrivateKey.js b/lib/PrivateKey.js similarity index 100% rename from PrivateKey.js rename to lib/PrivateKey.js diff --git a/RpcClient.js b/lib/RpcClient.js similarity index 100% rename from RpcClient.js rename to lib/RpcClient.js diff --git a/SIN.js b/lib/SIN.js similarity index 100% rename from SIN.js rename to lib/SIN.js diff --git a/SINKey.js b/lib/SINKey.js similarity index 100% rename from SINKey.js rename to lib/SINKey.js diff --git a/Script.js b/lib/Script.js similarity index 100% rename from Script.js rename to lib/Script.js diff --git a/ScriptInterpreter.js b/lib/ScriptInterpreter.js similarity index 100% rename from ScriptInterpreter.js rename to lib/ScriptInterpreter.js diff --git a/Sign.js b/lib/Sign.js similarity index 100% rename from Sign.js rename to lib/Sign.js diff --git a/Transaction.js b/lib/Transaction.js similarity index 100% rename from Transaction.js rename to lib/Transaction.js diff --git a/TransactionBuilder.js b/lib/TransactionBuilder.js similarity index 100% rename from TransactionBuilder.js rename to lib/TransactionBuilder.js diff --git a/Wallet.js b/lib/Wallet.js similarity index 100% rename from Wallet.js rename to lib/Wallet.js diff --git a/WalletKey.js b/lib/WalletKey.js similarity index 100% rename from WalletKey.js rename to lib/WalletKey.js diff --git a/Buffers.monkey.js b/patches/Buffers.monkey.js similarity index 100% rename from Buffers.monkey.js rename to patches/Buffers.monkey.js diff --git a/Number.monkey.js b/patches/Number.monkey.js similarity index 100% rename from Number.monkey.js rename to patches/Number.monkey.js From a2d616da5b52e421c1d290c978a6e518b32bb654 Mon Sep 17 00:00:00 2001 From: Eric Martindale Date: Sun, 13 Apr 2014 13:28:42 -0700 Subject: [PATCH 2/7] Project reorganization. --- bitcore.js | 44 +++++++++++++++++++-------------------- examples/PeerManager.js | 2 +- examples/SendTx.js | 2 +- lib/Address.js | 6 +++--- lib/BIP32.js | 4 ++-- lib/Block.js | 4 ++-- lib/Connection.js | 12 +++++------ lib/Key.js | 2 +- lib/PeerManager.js | 6 +++--- lib/Point.js | 10 ++++----- lib/PrivateKey.js | 4 ++-- lib/RpcClient.js | 2 +- lib/SIN.js | 2 +- lib/SINKey.js | 4 ++-- lib/Script.js | 8 +++---- lib/ScriptInterpreter.js | 8 +++---- lib/Transaction.js | 12 +++++------ lib/TransactionBuilder.js | 4 ++-- lib/Wallet.js | 6 +++--- lib/WalletKey.js | 4 ++-- 20 files changed, 73 insertions(+), 73 deletions(-) diff --git a/bitcore.js b/bitcore.js index 66eb47c..46d2854 100644 --- a/bitcore.js +++ b/bitcore.js @@ -14,40 +14,40 @@ requireWhenAccessed('bignum', 'bignum'); requireWhenAccessed('base58', 'base58-native'); requireWhenAccessed('bufferput', 'bufferput'); requireWhenAccessed('buffertools', 'buffertools'); -requireWhenAccessed('Buffers.monkey', './Buffers.monkey'); +requireWhenAccessed('Buffers.monkey', './patches/Buffers.monkey'); requireWhenAccessed('config', './config'); requireWhenAccessed('const', './const'); -requireWhenAccessed('Deserialize', './Deserialize'); +requireWhenAccessed('Deserialize', './lib/Deserialize'); requireWhenAccessed('log', './util/log'); requireWhenAccessed('networks', './networks'); requireWhenAccessed('util', './util/util'); requireWhenAccessed('EncodedData', './util/EncodedData'); requireWhenAccessed('VersionedData', './util/VersionedData'); requireWhenAccessed('BinaryParser', './util/BinaryParser'); -requireWhenAccessed('Address', './Address'); -requireWhenAccessed('BIP32', './BIP32'); -requireWhenAccessed('Point', './Point'); -requireWhenAccessed('Opcode', './Opcode'); -requireWhenAccessed('Script', './Script'); -requireWhenAccessed('Transaction', './Transaction'); -requireWhenAccessed('TransactionBuilder', './TransactionBuilder'); -requireWhenAccessed('Connection', './Connection'); -requireWhenAccessed('Peer', './Peer'); -requireWhenAccessed('Block', './Block'); -requireWhenAccessed('ScriptInterpreter', './ScriptInterpreter'); -requireWhenAccessed('Bloom', './Bloom'); -requireWhenAccessed('Key', './Key'); +requireWhenAccessed('Address', './lib/Address'); +requireWhenAccessed('BIP32', './lib/BIP32'); +requireWhenAccessed('Point', './lib/Point'); +requireWhenAccessed('Opcode', './lib/Opcode'); +requireWhenAccessed('Script', './lib/Script'); +requireWhenAccessed('Transaction', './lib/Transaction'); +requireWhenAccessed('TransactionBuilder', './lib/TransactionBuilder'); +requireWhenAccessed('Connection', './lib/Connection'); +requireWhenAccessed('Peer', './lib/Peer'); +requireWhenAccessed('Block', './lib/Block'); +requireWhenAccessed('ScriptInterpreter', './lib/ScriptInterpreter'); +requireWhenAccessed('Bloom', './lib/Bloom'); +requireWhenAccessed('Key', './lib/Key'); Object.defineProperty(module.exports, 'KeyModule', {get: function() { console.log('KeyModule is deprecated.'); return require('bindings')('KeyModule'); }}); -requireWhenAccessed('SINKey', './SINKey'); -requireWhenAccessed('SIN', './SIN'); -requireWhenAccessed('PrivateKey', './PrivateKey'); -requireWhenAccessed('RpcClient', './RpcClient'); -requireWhenAccessed('Wallet', './Wallet'); -requireWhenAccessed('WalletKey', './WalletKey'); -requireWhenAccessed('PeerManager', './PeerManager'); +requireWhenAccessed('SINKey', './lib/SINKey'); +requireWhenAccessed('SIN', './lib/SIN'); +requireWhenAccessed('PrivateKey', './lib/PrivateKey'); +requireWhenAccessed('RpcClient', './lib/RpcClient'); +requireWhenAccessed('Wallet', './lib/Wallet'); +requireWhenAccessed('WalletKey', './lib/WalletKey'); +requireWhenAccessed('PeerManager', './lib/PeerManager'); module.exports.Buffer = Buffer; if (typeof process.versions === 'undefined') { diff --git a/examples/PeerManager.js b/examples/PeerManager.js index 0d0bdba..69a58f7 100644 --- a/examples/PeerManager.js +++ b/examples/PeerManager.js @@ -5,7 +5,7 @@ var run = function() { var bitcore = require('../bitcore'); var networks = bitcore.networks; var Peer = bitcore.Peer; - var PeerManager = require('soop').load('../PeerManager', { + var PeerManager = require('soop').load('../lib/PeerManager', { network: networks.testnet }); diff --git a/examples/SendTx.js b/examples/SendTx.js index 3664660..6095a8e 100644 --- a/examples/SendTx.js +++ b/examples/SendTx.js @@ -9,7 +9,7 @@ var run = function() { var Address = bitcore.Address; var Script = bitcore.Script; var coinUtil = bitcore.util; - var PeerManager = require('soop').load('../PeerManager', { + var PeerManager = require('soop').load('../lib/PeerManager', { network: networks.testnet }); diff --git a/lib/Address.js b/lib/Address.js index c3bf0ee..8a0dd0b 100644 --- a/lib/Address.js +++ b/lib/Address.js @@ -1,8 +1,8 @@ 'use strict'; var imports = require('soop').imports(); -var coinUtil = imports.coinUtil || require('./util/util'); -var parent = imports.parent || require('./util/VersionedData'); -var networks = imports.networks || require('./networks'); +var coinUtil = imports.coinUtil || require('../util'); +var parent = imports.parent || require('../util/VersionedData'); +var networks = imports.networks || require('../networks'); var Script = imports.Script || require('./Script'); function Address() { diff --git a/lib/BIP32.js b/lib/BIP32.js index b01eec4..761e1f4 100644 --- a/lib/BIP32.js +++ b/lib/BIP32.js @@ -1,11 +1,11 @@ var imports = require('soop').imports(); var base58 = imports.base58 || require('base58-native').base58; -var coinUtil = imports.coinUtil || require('./util/util'); +var coinUtil = imports.coinUtil || require('../util'); var Key = imports.Key || require('./Key'); var Point = imports.Point || require('./Point'); var bignum = imports.bignum || require('bignum'); var crypto = require('crypto'); -var networks = require('./networks'); +var networks = require('../networks'); var secp256k1_n = new bignum("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 16); var secp256k1_Gx = new bignum("79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", 16); diff --git a/lib/Block.js b/lib/Block.js index 84be543..57c6d48 100644 --- a/lib/Block.js +++ b/lib/Block.js @@ -1,6 +1,6 @@ var imports = require('soop').imports(); -var util = imports.util || require('./util/util'); +var util = imports.util || require('../util'); var Debug1 = imports.Debug1 || function() {}; var Script = imports.Script || require('./Script'); var Bignum = imports.Bignum || require('bignum'); @@ -11,7 +11,7 @@ var Transaction = imports.Transaction || require('./Transaction'); var TransactionIn = Transaction.In; var TransactionOut = Transaction.Out; var COINBASE_OP = Transaction.COINBASE_OP; -var VerificationError = imports.VerificationError || require('./util/error').VerificationError; +var VerificationError = imports.VerificationError || require('../util/error').VerificationError; var BlockRules = { maxTimeOffset: 2 * 60 * 60, // How far block timestamps can be into the future largestHash: Bignum(2).pow(256) diff --git a/lib/Connection.js b/lib/Connection.js index 319a723..4b7dd05 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -1,8 +1,8 @@ var imports = require('soop').imports(); -var config = imports.config || require('./config'); -var log = imports.log || require('./util/log'); -var network = imports.network || require('./networks')[config.network]; +var config = imports.config || require('../config'); +var log = imports.log || require('../util/log'); +var network = imports.network || require('../networks')[config.network]; var MAX_RECEIVE_BUFFER = 10000000; var PROTOCOL_VERSION = 70000; @@ -10,12 +10,12 @@ var PROTOCOL_VERSION = 70000; var Binary = imports.Binary || require('binary'); var Put = imports.Put || require('bufferput'); var Buffers = imports.Buffers || require('buffers'); -require('./Buffers.monkey').patch(Buffers); +require('../patches/Buffers.monkey').patch(Buffers); var Block = require('./Block'); var Transaction = require('./Transaction'); -var util = imports.util || require('./util/util'); -var Parser = imports.Parser || require('./util/BinaryParser'); +var util = imports.util || require('../util'); +var Parser = imports.Parser || require('../util/BinaryParser'); var buffertools = imports.buffertools || require('buffertools'); var doubleSha256 = imports.doubleSha256 || util.twoSha256; var nonce = util.generateNonce(); diff --git a/lib/Key.js b/lib/Key.js index f386a7b..576495d 100644 --- a/lib/Key.js +++ b/lib/Key.js @@ -7,7 +7,7 @@ if (process.versions) { module.exports = Key; } else { // pure js version - var ECKey = require('./browser/vendor-bundle.js').ECKey; + var ECKey = require('../browser/vendor-bundle.js').ECKey; var buffertools = require('buffertools'); var kSpec = function() { diff --git a/lib/PeerManager.js b/lib/PeerManager.js index d822986..49265e0 100644 --- a/lib/PeerManager.js +++ b/lib/PeerManager.js @@ -1,8 +1,8 @@ var imports = require('soop').imports(); -var config = imports.config || require('./config'); -var log = imports.log || require('./util/log'); -var network = imports.network || require('./networks')[config.network]; +var config = imports.config || require('../config'); +var log = imports.log || require('../util/log'); +var network = imports.network || require('../networks')[config.network]; var Connection = imports.Connection || require('soop').load('./Connection', {config: config, network: network}) || diff --git a/lib/Point.js b/lib/Point.js index b18971d..424529f 100644 --- a/lib/Point.js +++ b/lib/Point.js @@ -7,11 +7,11 @@ var assert = require('assert'); //browser if (!process.versions) { - var ECKey = require('./browser/vendor-bundle.js').ECKey; - var ECPointFp = require('./browser/vendor-bundle.js').ECPointFp; - var ECFieldElementFp = require('./browser/vendor-bundle.js').ECFieldElementFp; - var getSECCurveByName = require('./browser/vendor-bundle.js').getSECCurveByName; - var BigInteger = require('./browser/vendor-bundle.js').BigInteger; + var ECKey = require('../browser/vendor-bundle.js').ECKey; + var ECPointFp = require('../browser/vendor-bundle.js').ECPointFp; + var ECFieldElementFp = require('../browser/vendor-bundle.js').ECFieldElementFp; + var getSECCurveByName = require('../browser/vendor-bundle.js').getSECCurveByName; + var BigInteger = require('../browser/vendor-bundle.js').BigInteger; var should = require('chai').should(); } diff --git a/lib/PrivateKey.js b/lib/PrivateKey.js index fc95f55..62929fc 100644 --- a/lib/PrivateKey.js +++ b/lib/PrivateKey.js @@ -1,7 +1,7 @@ var imports = require('soop').imports(); -var parent = imports.parent || require('./util/VersionedData'); -var networks= imports.networks || require('./networks'); +var parent = imports.parent || require('../util/VersionedData'); +var networks= imports.networks || require('../networks'); //compressed is true if public key is compressed; false otherwise function PrivateKey(version, buf, compressed) { diff --git a/lib/RpcClient.js b/lib/RpcClient.js index 54dff58..68cc16f 100644 --- a/lib/RpcClient.js +++ b/lib/RpcClient.js @@ -5,7 +5,7 @@ var imports = require('soop').imports(); var http = imports.http || require('http'); var https = imports.https || require('https'); -var log = imports.log || require('./util/log'); +var log = imports.log || require('../util/log'); function RpcClient(opts) { opts = opts || {}; diff --git a/lib/SIN.js b/lib/SIN.js index 5551bb1..e0ba4dc 100644 --- a/lib/SIN.js +++ b/lib/SIN.js @@ -1,5 +1,5 @@ var imports = require('soop').imports(); -var parent = imports.parent || require('./util/VersionedData'); +var parent = imports.parent || require('../util/VersionedData'); function SIN(type, payload) { if (typeof type != 'number') { diff --git a/lib/SINKey.js b/lib/SINKey.js index 83f7516..bb3d0e6 100644 --- a/lib/SINKey.js +++ b/lib/SINKey.js @@ -1,5 +1,5 @@ -var coinUtil = require('./util/util'); -var timeUtil = require('./util/time'); +var coinUtil = require('../util'); +var timeUtil = require('../util/time'); var Key = require('./Key'); var SIN = require('./SIN'); diff --git a/lib/Script.js b/lib/Script.js index c975538..d76e3b8 100644 --- a/lib/Script.js +++ b/lib/Script.js @@ -1,6 +1,6 @@ var imports = require('soop').imports(); -var config = imports.config || require('./config'); -var log = imports.log || require('./util/log'); +var config = imports.config || require('../config'); +var log = imports.log || require('../util/log'); var Opcode = imports.Opcode || require('./Opcode'); var buffertools = imports.buffertools || require('buffertools'); @@ -9,8 +9,8 @@ for (var i in Opcode.map) { eval(i + " = " + Opcode.map[i] + ";"); } -var util = imports.util || require('./util/util'); -var Parser = imports.Parser || require('./util/BinaryParser'); +var util = imports.util || require('../util/util'); +var Parser = imports.Parser || require('../util/BinaryParser'); var Put = imports.Put || require('bufferput'); var TX_UNKNOWN = 0; diff --git a/lib/ScriptInterpreter.js b/lib/ScriptInterpreter.js index d9a0c21..1cb5abd 100644 --- a/lib/ScriptInterpreter.js +++ b/lib/ScriptInterpreter.js @@ -1,11 +1,11 @@ var imports = require('soop').imports(); -var config = imports.config || require('./config'); -var log = imports.log || require('./util/log'); -var util = imports.util || require('./util/util'); +var config = imports.config || require('../config'); +var log = imports.log || require('../util/log'); +var util = imports.util || require('../util'); var Opcode = imports.Opcode || require('./Opcode'); var buffertools = imports.buffertools || require('buffertools'); var bignum = imports.bignum || require('bignum'); -var Util = imports.Util || require('./util/util'); +var Util = imports.Util || require('../util'); var Script = require('./Script'); var Key = require('./Key'); diff --git a/lib/Transaction.js b/lib/Transaction.js index 2a4e566..7b03cdf 100644 --- a/lib/Transaction.js +++ b/lib/Transaction.js @@ -1,17 +1,17 @@ var imports = require('soop').imports(); -var config = imports.config || require('./config'); -var log = imports.log || require('./util/log'); +var config = imports.config || require('../config'); +var log = imports.log || require('../util/log'); var Address = imports.Address || require('./Address'); var Script = imports.Script || require('./Script'); var ScriptInterpreter = imports.ScriptInterpreter || require('./ScriptInterpreter'); -var util = imports.util || require('./util/util'); +var util = imports.util || require('../util'); var bignum = imports.bignum || require('bignum'); var Put = imports.Put || require('bufferput'); -var Parser = imports.Parser || require('./util/BinaryParser'); +var Parser = imports.Parser || require('../util/BinaryParser'); var Step = imports.Step || require('step'); var buffertools = imports.buffertools || require('buffertools'); -var error = imports.error || require('./util/error'); -var networks = imports.networks || require('./networks'); +var error = imports.error || require('../util/error'); +var networks = imports.networks || require('../networks'); var WalletKey = imports.WalletKey || require('./WalletKey'); var PrivateKey = imports.PrivateKey || require('./PrivateKey'); diff --git a/lib/TransactionBuilder.js b/lib/TransactionBuilder.js index ebb3a6f..f0df5d1 100644 --- a/lib/TransactionBuilder.js +++ b/lib/TransactionBuilder.js @@ -82,10 +82,10 @@ var imports = require('soop').imports(); var Address = imports.Address || require('./Address'); var Script = imports.Script || require('./Script'); -var util = imports.util || require('./util/util'); +var util = imports.util || require('../util'); var bignum = imports.bignum || require('bignum'); var buffertools = imports.buffertools || require('buffertools'); -var networks = imports.networks || require('./networks'); +var networks = imports.networks || require('../networks'); var WalletKey = imports.WalletKey || require('./WalletKey'); var PrivateKey = imports.PrivateKey || require('./PrivateKey'); diff --git a/lib/Wallet.js b/lib/Wallet.js index e3ee5da..088c5aa 100644 --- a/lib/Wallet.js +++ b/lib/Wallet.js @@ -3,10 +3,10 @@ var imports = require('soop').imports(); var hex = function(hex) {return new Buffer(hex, 'hex');}; var fs = require('fs'); -var EncFile = require('./util/EncFile'); +var EncFile = require('../util/EncFile'); var Address = require('./Address'); -var networks = require('./networks'); -var util = imports.util || require('./util/util'); +var networks = require('../networks'); +var util = imports.util || require('../util'); var ENC_METHOD = 'aes-256-cbc'; var skeleton = { diff --git a/lib/WalletKey.js b/lib/WalletKey.js index d8c0334..4075393 100644 --- a/lib/WalletKey.js +++ b/lib/WalletKey.js @@ -1,7 +1,7 @@ var imports = require('soop').imports(); -var coinUtil = require('./util/util'); -var timeUtil = require('./util/time'); +var coinUtil = require('../util'); +var timeUtil = require('../util/time'); var Key = require('./Key'); var PrivateKey = require('./PrivateKey'); var Address = require('./Address'); From 198b811290ece20eb27570c84af02ed623d9d1be Mon Sep 17 00:00:00 2001 From: Eric Martindale Date: Wed, 16 Apr 2014 14:35:07 -0400 Subject: [PATCH 3/7] Add missing util/index.js --- util/index.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 util/index.js diff --git a/util/index.js b/util/index.js new file mode 100644 index 0000000..2c8b25e --- /dev/null +++ b/util/index.js @@ -0,0 +1 @@ +module.exports = require('./util'); \ No newline at end of file From 9771d8138dde49786fea8edf78c0e28a54a652bc Mon Sep 17 00:00:00 2001 From: Eric Martindale Date: Thu, 17 Apr 2014 18:05:43 -0400 Subject: [PATCH 4/7] Fix browser bundling with new architecture. --- browser/build.js | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/browser/build.js b/browser/build.js index 41280cf..a1635b4 100644 --- a/browser/build.js +++ b/browser/build.js @@ -23,31 +23,31 @@ var pack = function (params) { }; var modules = [ - 'Address', - 'BIP32', - 'Block', - 'Bloom', - 'Buffers.monkey', - 'Connection', - 'Deserialize', 'Gruntfile', - 'Number.monkey', - 'Opcode', - 'Peer', - 'PeerManager', - 'PrivateKey', - 'RpcClient', - 'Key', - 'Point', - 'SIN', - 'SINKey', - 'Script', - 'ScriptInterpreter', - 'Sign', - 'Transaction', - 'TransactionBuilder', - 'Wallet', - 'WalletKey', + 'lib/Address', + 'lib/BIP32', + 'lib/Block', + 'lib/Bloom', + 'lib/Connection', + 'lib/Deserialize', + 'lib/Opcode', + 'lib/Peer', + 'lib/PeerManager', + 'lib/PrivateKey', + 'lib/RpcClient', + 'lib/Key', + 'lib/Point', + 'lib/SIN', + 'lib/SINKey', + 'lib/Script', + 'lib/ScriptInterpreter', + 'lib/Sign', + 'lib/Transaction', + 'lib/TransactionBuilder', + 'lib/Wallet', + 'lib/WalletKey', + 'patches/Buffers.monkey', + 'patches/Number.monkey', 'config', 'const', 'networks', From 5a1d572a8d44c828ecb893a7f656bc49634ccc20 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Fri, 18 Apr 2014 16:51:20 -0300 Subject: [PATCH 5/7] add new constructor to Address (fromScriptPubKey) --- lib/Address.js | 43 +++++++++++++++++++++++++++++++++++++++++++ test/test.Address.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/lib/Address.js b/lib/Address.js index 8a0dd0b..5bc4abb 100644 --- a/lib/Address.js +++ b/lib/Address.js @@ -47,6 +47,10 @@ Address.fromScript = function(script, network) { if (!network) network = 'livenet'; + if (typeof script === 'string') { + script = new Script(new Buffer(script,'hex')); + } + var version = networks[network].P2SHVersion; var buf = script.getBuffer(); var hash = coinUtil.sha256ripe160(buf); @@ -54,6 +58,45 @@ Address.fromScript = function(script, network) { return new Address(version, hash); }; +//extract and address from scriptPubKey +Address.fromScriptPubKey = function(scriptPubKey, network) { + + if (typeof scriptPubKey === 'string') { + scriptPubKey = new Script(new Buffer(scriptPubKey,'hex')); + } + + if (!network) + network = 'livenet'; + + var ret=[], version; + var payload = scriptPubKey.capture(); + + if (payload) { + var txType = scriptPubKey.classify(); + switch (txType) { + case Script.TX_PUBKEY: + payload[0] = coinUtil.sha256ripe160(payload[0]); + version = networks[network].addressVersion; + break; + case Script.TX_PUBKEYHASH: + version = networks[network].addressVersion; + break; + case Script.TX_MULTISIG: + version = networks[network].addressVersion; + for(var i in payload) + payload[i] = coinUtil.sha256ripe160(payload[i]); + break; + case Script.TX_SCRIPTHASH: + version = networks[network].P2SHVersion; + break; + } + for(var i in payload) + ret.push(new Address(version,payload[i])); + } + return ret; +}; + + Address.prototype.validate = function() { this.doAsBinary(function() { Address.super(this, 'validate', arguments); diff --git a/test/test.Address.js b/test/test.Address.js index bffc08a..a712cbe 100644 --- a/test/test.Address.js +++ b/test/test.Address.js @@ -119,6 +119,13 @@ describe('Address', function() { var addr = Address.fromScript(script); var addr2 = Address.fromPubKeys(mReq, pubKeys); addr.toString().should.equal(addr2.toString()); + + // Same case, using HEX + var scriptHex = bitcore.Script.createMultisig(mReq, pubKeys).getBuffer().toString('hex'); + var addrB = Address.fromScript(scriptHex); + var addr2B = Address.fromPubKeys(mReq, pubKeys); + addrB.toString().should.equal(addr2B.toString()); + }); it('it should make this hand-crafted address', function() { @@ -137,5 +144,41 @@ describe('Address', function() { addr.toString().should.equal(addr2.toString()); }); }); + + + describe('#fromScriptPubKey', function() { + + // All examples checked againt bitcoind decodescript + var cases = [ + ['76a91423b7530a00dd7951e11791c529389421c0b8d83b88ac', 'mimoZNLcP2rrMRgdeX5PSnR7AjCqQveZZ4'], + ['a9147049be48e74a660157da3ed64569981592f7fa0587','2N3Ux1YTnt1ixofYvJfaabqZSj2MBF3jsmv'], + ['76a914774e603bafb717bd3f070e68bbcccfd907c77d1388ac', 'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE'], + ['76a914b00127584485a7cff0949ef0f6bc5575f06ce00d88ac', 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'], + ['532103bf025eb410407aec5a67c975ce222e363bb88c69bb1acce45d20d85602df2ec52103d76dd6d99127f4b733e772f0c0a09c573ac7e4d69b8bf50272292da2e093de2c2103dd9acd8dd1816c825d6b0739339c171ae2cb10efb53699680537865b07086e9b2102371cabbaf466c3a536034b4bda64ad515807bffd87488f44f93c2373d4d189c9210264cd444358f8d57f8637a7309f9736806f4883aebc4fe7da4bad1e4b37f2d12c55ae', [ + "n4JAZc4cJimQbky5wxZUEDeAFZtGaZrjWK", + "msge5muNmBSRDn5nsaRcHCU6dg2zimA8wQ", + "mvz9MjocpyXdgXqRcZYazsdE8iThdvjdhk", + "miQGZ2gybQe7UvUQDBYsgcctUteij5pTpm", + "mu9kmhGrzREKsWaXUEUrsRLLMG4UMPy1LF" + ]] + ]; + + for(var i in cases){ + var c=cases[i]; + it('it should generate the right address', function(){ + if (typeof c[1] === 'string') { + (new Address.fromScriptPubKey(c[0],'testnet')).toString().should.equal(c[1]); + var s = new bitcore.Script(new Buffer(c[0],'hex')); + (new Address.fromScriptPubKey(s,'testnet')).toString().should.equal(c[1]); + } + else { + var as=new Address.fromScriptPubKey(c[0],'testnet'); + for(var j in as){ + as[j].toString().should.equal(c[1][j]); + } + } + }); + } + }); }); From 659dc10f96e2d811604ed255cfc41e89113a7a6e Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Sat, 19 Apr 2014 11:28:19 -0300 Subject: [PATCH 6/7] add support for signing/verifying messages This adds a new Message class with static methods for signing and verifying a message the same way as bitcoind. (In a nutshell, messages a prepended with "Bitcoin Signed Message:" before being hashed and signed). There is one important piece missing ... verifying a signature with an address, and not a public key. I have not yet implemented this because the cryptography interface of bitcore does not allow me to derive the public key from a signature. This will need to be added before verifying from an address is possible. --- bitcore.js | 1 + lib/Message.js | 42 ++++++++++++++++++++++++++++++++ test/test.Message.js | 57 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 lib/Message.js create mode 100644 test/test.Message.js diff --git a/bitcore.js b/bitcore.js index 46d2854..4e2b370 100644 --- a/bitcore.js +++ b/bitcore.js @@ -48,6 +48,7 @@ requireWhenAccessed('RpcClient', './lib/RpcClient'); requireWhenAccessed('Wallet', './lib/Wallet'); requireWhenAccessed('WalletKey', './lib/WalletKey'); requireWhenAccessed('PeerManager', './lib/PeerManager'); +requireWhenAccessed('Message', './lib/Message'); module.exports.Buffer = Buffer; if (typeof process.versions === 'undefined') { diff --git a/lib/Message.js b/lib/Message.js new file mode 100644 index 0000000..018090c --- /dev/null +++ b/lib/Message.js @@ -0,0 +1,42 @@ +'use strict'; +var imports = require('soop').imports(); +var coinUtil = imports.coinUtil || require('../util'); +var Key = imports.Key || require('./Key'); + +var Message = function() { +}; + +Message.sign = function(str, key) { + var hash = Message.magicHash(str); + var sig = key.signSync(hash); + return sig; +}; + +Message.verifyWithPubKey = function(pubkey, message, sig) { + var hash = Message.magicHash(message); + var key = new Key(); + if (pubkey.length == 65) + key.compressed = false; + key.public = pubkey; + + return key.verifySignatureSync(hash, sig); +}; + +//TODO: Message.verify ... with address, not pubkey + +Message.magicBytes = new Buffer('Bitcoin Signed Message:\n'); + +Message.magicHash = function(str) { + var magicBytes = Message.magicBytes; + var prefix1 = coinUtil.varIntBuf(magicBytes.length); + var message = new Buffer(str); + var prefix2 = coinUtil.varIntBuf(message.length); + + var buf = Buffer.concat([prefix1, magicBytes, prefix2, message]); + + var hash = coinUtil.twoSha256(buf); + + return hash; +}; + +module.exports = require('soop')(Message); diff --git a/test/test.Message.js b/test/test.Message.js new file mode 100644 index 0000000..9ec581f --- /dev/null +++ b/test/test.Message.js @@ -0,0 +1,57 @@ +'use strict'; + +var chai = chai || require('chai'); +var should = chai.should(); +var bitcore = bitcore || require('../bitcore'); +var Message = bitcore.Message; +var coinUtil = bitcore.util; + +describe('Message', function() { + describe('sign', function() { + it('should return a signature', function() { + var key = bitcore.Key.generateSync(); + var sig = Message.sign('my message', key); + sig.length.should.be.greaterThan(0); + }); + }); + + describe('verifyWithPubKey', function() { + it('should verify a signed message', function() { + var message = 'my message'; + var key = bitcore.Key.generateSync(); + var sig = Message.sign(message, key); + Message.verifyWithPubKey(key.public, message, sig).should.equal(true); + }); + }); + + describe('magicBytes', function() { + it('should be "Bitcoin Signed Message:\\n"', function() { + Message.magicBytes.toString().should.equal('Bitcoin Signed Message:\n'); + }); + }); + + describe('magicHash', function() { + it('should hash the message with the magic bytes', function() { + var str = 'my message'; + var magicBytes = Message.magicBytes; + var prefix1 = coinUtil.varIntBuf(magicBytes.length); + var message = new Buffer(str); + var prefix2 = coinUtil.varIntBuf(message.length); + + var buf = Buffer.concat([prefix1, magicBytes, prefix2, message]); + + var hash = coinUtil.twoSha256(buf); + + var hash2 = Message.magicHash(str); + + hash.toString().should.equal(hash2.toString()); + }); + + it('should hash this message the same way as bitcoinjs-lib', function() { + var hashHex = '74eacdc6c04724869380907bf4aab561a1494a4a800fba266b29b8158c2c4cec'; + + var str = 'this is a test message'; + hashHex.should.equal(Message.magicHash(str).toString('hex')); + }); + }); +}); From 55061776acc1b868333a4860bd02133bd491e2aa Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Sat, 19 Apr 2014 11:41:00 -0300 Subject: [PATCH 7/7] add Message to browser build and tests --- browser/build.js | 1 + test/index-testling.html | 1 + test/index.html | 1 + 3 files changed, 3 insertions(+) diff --git a/browser/build.js b/browser/build.js index a1635b4..4680175 100644 --- a/browser/build.js +++ b/browser/build.js @@ -30,6 +30,7 @@ var modules = [ 'lib/Bloom', 'lib/Connection', 'lib/Deserialize', + 'lib/Message', 'lib/Opcode', 'lib/Peer', 'lib/PeerManager', diff --git a/test/index-testling.html b/test/index-testling.html index e6a9447..602ddd3 100644 --- a/test/index-testling.html +++ b/test/index-testling.html @@ -25,6 +25,7 @@ + diff --git a/test/index.html b/test/index.html index a3512d9..3e823e4 100644 --- a/test/index.html +++ b/test/index.html @@ -24,6 +24,7 @@ +