diff --git a/src/util.js b/src/crypto.js similarity index 100% rename from src/util.js rename to src/crypto.js diff --git a/src/eckey.js b/src/eckey.js index 190e6de..c6acd4c 100644 --- a/src/eckey.js +++ b/src/eckey.js @@ -7,7 +7,7 @@ var ecdsa = require('./ecdsa') var ECPointFp = require('./jsbn/ec').ECPointFp var sec = require('./jsbn/sec') var Network = require('./network') -var util = require('./util') +var crypto = require('./crypto') var ecparams = sec("secp256k1") // input can be nothing, array of bytes, hex string, or base58 string @@ -175,7 +175,7 @@ ECPubKey.prototype.toString = ECPubKey.prototype.toHex ECPubKey.prototype.getAddress = function(version) { version = version || Network.mainnet.addressVersion - return new Address(util.sha256ripe160(this.toBytes()), version) + return new Address(crypto.sha256ripe160(this.toBytes()), version) } ECPubKey.prototype.verify = function(hash, sig) { diff --git a/src/hdwallet.js b/src/hdwallet.js index a6998b5..9bfabd8 100644 --- a/src/hdwallet.js +++ b/src/hdwallet.js @@ -2,7 +2,7 @@ var convert = require('./convert.js') var base58 = require('./base58.js') var assert = require('assert') var format = require('util').format -var util = require('./util.js') +var crypto = require('./crypto') var Crypto = require('crypto-js') var HmacSHA512 = Crypto.HmacSHA512 var HMAC= Crypto.algo.HMAC @@ -11,10 +11,10 @@ var ECPubKey = require('./eckey.js').ECPubKey var Address = require('./address.js') var Network = require('./network') -var crypto = require('crypto') +var crypto2 = require('crypto') function sha256(buf) { - var hash = crypto.createHash('sha256') + var hash = crypto2.createHash('sha256') hash.update(buf) return hash.digest() @@ -131,7 +131,7 @@ HDWallet.fromBytes = function(input) { } HDWallet.prototype.getIdentifier = function() { - return util.sha256ripe160(this.pub.toBytes()) + return crypto.sha256ripe160(this.pub.toBytes()) } HDWallet.prototype.getFingerprint = function() { @@ -139,7 +139,7 @@ HDWallet.prototype.getFingerprint = function() { } HDWallet.prototype.getAddress = function() { - return new Address(util.sha256ripe160(this.pub.toBytes()), this.getKeyVersion()) + return new Address(crypto.sha256ripe160(this.pub.toBytes()), this.getKeyVersion()) } HDWallet.prototype.toBytes = function(priv) { diff --git a/src/index.js b/src/index.js index 52fd4f4..040216b 100644 --- a/src/index.js +++ b/src/index.js @@ -12,7 +12,7 @@ module.exports = { Script: require('./script'), Opcode: require('./opcode'), Transaction: T.Transaction, - Util: require('./util'), + crypto: require('./crypto'), TransactionIn: T.TransactionIn, TransactionOut: T.TransactionOut, ECPointFp: require('./jsbn/ec').ECPointFp, diff --git a/src/script.js b/src/script.js index 49d78fa..1a21484 100644 --- a/src/script.js +++ b/src/script.js @@ -1,5 +1,5 @@ var Opcode = require('./opcode') -var util = require('./util') +var crypto = require('./crypto') var convert = require('./convert') var Address = require('./address') var network = require('./network') @@ -144,10 +144,10 @@ Script.prototype.toScriptHash = function() { } if (outType == 'P2SH') { - return util.sha256ripe160(this.buffer) + return crypto.sha256ripe160(this.buffer) } - return util.sha256ripe160(this.buffer) + return crypto.sha256ripe160(this.buffer) } //TODO: support testnet @@ -257,7 +257,7 @@ Script.prototype.simpleInPubKey = function() { * This method is useful for indexing transactions. */ Script.prototype.simpleInHash = function() { - return util.sha256ripe160(this.simpleInPubKey()) + return crypto.sha256ripe160(this.simpleInPubKey()) } /** diff --git a/src/transaction.js b/src/transaction.js index 55e9954..2edec9c 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -1,6 +1,6 @@ var BigInteger = require('./jsbn/jsbn') var Script = require('./script') -var util = require('./util') +var crypto = require('./crypto') var convert = require('./convert') var ECKey = require('./eckey').ECKey var ECDSA = require('./ecdsa') @@ -303,7 +303,7 @@ Transaction.prototype.sign = function(index, key, type) { // TODO: getPub is slow, sha256ripe160 probably is too. // This could be sped up a lot by providing these as inputs. var pub = key.getPub().toBytes(), - hash160 = util.sha256ripe160(pub), + hash160 = crypto.sha256ripe160(pub), script = Script.createOutputScript(new Address(hash160)), hash = this.hashTransactionForSignature(script, index, type), sig = key.sign(hash).concat([type]) diff --git a/test/script.js b/test/script.js index b6ce5e9..ddf0101 100644 --- a/test/script.js +++ b/test/script.js @@ -2,8 +2,8 @@ var Script = require('../src/script.js') var assert = require('assert') var Address = require('../src/address.js') var Network = require('../src/network.js') -var Util = require('../src/util.js') -var sha256ripe160 = Util.sha256ripe160 +var crypto = require('../').crypto +var sha256ripe160 = crypto.sha256ripe160 var Convert = require('../src/convert.js') var bytesToHex = Convert.bytesToHex var hexToBytes = Convert.hexToBytes