Renames util.js to crypto.js

This commit is contained in:
Daniel Cousens 2014-04-08 22:00:28 +10:00
parent a4c2cc6dd4
commit 81d9c8e759
7 changed files with 16 additions and 16 deletions

View file

@ -7,7 +7,7 @@ var ecdsa = require('./ecdsa')
var ECPointFp = require('./jsbn/ec').ECPointFp var ECPointFp = require('./jsbn/ec').ECPointFp
var sec = require('./jsbn/sec') var sec = require('./jsbn/sec')
var Network = require('./network') var Network = require('./network')
var util = require('./util') var crypto = require('./crypto')
var ecparams = sec("secp256k1") var ecparams = sec("secp256k1")
// input can be nothing, array of bytes, hex string, or base58 string // 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) { ECPubKey.prototype.getAddress = function(version) {
version = version || Network.mainnet.addressVersion 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) { ECPubKey.prototype.verify = function(hash, sig) {

View file

@ -2,7 +2,7 @@ var convert = require('./convert.js')
var base58 = require('./base58.js') var base58 = require('./base58.js')
var assert = require('assert') var assert = require('assert')
var format = require('util').format var format = require('util').format
var util = require('./util.js') var crypto = require('./crypto')
var Crypto = require('crypto-js') var Crypto = require('crypto-js')
var HmacSHA512 = Crypto.HmacSHA512 var HmacSHA512 = Crypto.HmacSHA512
var HMAC= Crypto.algo.HMAC var HMAC= Crypto.algo.HMAC
@ -11,10 +11,10 @@ var ECPubKey = require('./eckey.js').ECPubKey
var Address = require('./address.js') var Address = require('./address.js')
var Network = require('./network') var Network = require('./network')
var crypto = require('crypto') var crypto2 = require('crypto')
function sha256(buf) { function sha256(buf) {
var hash = crypto.createHash('sha256') var hash = crypto2.createHash('sha256')
hash.update(buf) hash.update(buf)
return hash.digest() return hash.digest()
@ -131,7 +131,7 @@ HDWallet.fromBytes = function(input) {
} }
HDWallet.prototype.getIdentifier = function() { HDWallet.prototype.getIdentifier = function() {
return util.sha256ripe160(this.pub.toBytes()) return crypto.sha256ripe160(this.pub.toBytes())
} }
HDWallet.prototype.getFingerprint = function() { HDWallet.prototype.getFingerprint = function() {
@ -139,7 +139,7 @@ HDWallet.prototype.getFingerprint = function() {
} }
HDWallet.prototype.getAddress = 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) { HDWallet.prototype.toBytes = function(priv) {

View file

@ -12,7 +12,7 @@ module.exports = {
Script: require('./script'), Script: require('./script'),
Opcode: require('./opcode'), Opcode: require('./opcode'),
Transaction: T.Transaction, Transaction: T.Transaction,
Util: require('./util'), crypto: require('./crypto'),
TransactionIn: T.TransactionIn, TransactionIn: T.TransactionIn,
TransactionOut: T.TransactionOut, TransactionOut: T.TransactionOut,
ECPointFp: require('./jsbn/ec').ECPointFp, ECPointFp: require('./jsbn/ec').ECPointFp,

View file

@ -1,5 +1,5 @@
var Opcode = require('./opcode') var Opcode = require('./opcode')
var util = require('./util') var crypto = require('./crypto')
var convert = require('./convert') var convert = require('./convert')
var Address = require('./address') var Address = require('./address')
var network = require('./network') var network = require('./network')
@ -144,10 +144,10 @@ Script.prototype.toScriptHash = function() {
} }
if (outType == 'P2SH') { 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 //TODO: support testnet
@ -257,7 +257,7 @@ Script.prototype.simpleInPubKey = function() {
* This method is useful for indexing transactions. * This method is useful for indexing transactions.
*/ */
Script.prototype.simpleInHash = function() { Script.prototype.simpleInHash = function() {
return util.sha256ripe160(this.simpleInPubKey()) return crypto.sha256ripe160(this.simpleInPubKey())
} }
/** /**

View file

@ -1,6 +1,6 @@
var BigInteger = require('./jsbn/jsbn') var BigInteger = require('./jsbn/jsbn')
var Script = require('./script') var Script = require('./script')
var util = require('./util') var crypto = require('./crypto')
var convert = require('./convert') var convert = require('./convert')
var ECKey = require('./eckey').ECKey var ECKey = require('./eckey').ECKey
var ECDSA = require('./ecdsa') var ECDSA = require('./ecdsa')
@ -303,7 +303,7 @@ Transaction.prototype.sign = function(index, key, type) {
// TODO: getPub is slow, sha256ripe160 probably is too. // TODO: getPub is slow, sha256ripe160 probably is too.
// This could be sped up a lot by providing these as inputs. // This could be sped up a lot by providing these as inputs.
var pub = key.getPub().toBytes(), var pub = key.getPub().toBytes(),
hash160 = util.sha256ripe160(pub), hash160 = crypto.sha256ripe160(pub),
script = Script.createOutputScript(new Address(hash160)), script = Script.createOutputScript(new Address(hash160)),
hash = this.hashTransactionForSignature(script, index, type), hash = this.hashTransactionForSignature(script, index, type),
sig = key.sign(hash).concat([type]) sig = key.sign(hash).concat([type])

View file

@ -2,8 +2,8 @@ var Script = require('../src/script.js')
var assert = require('assert') var assert = require('assert')
var Address = require('../src/address.js') var Address = require('../src/address.js')
var Network = require('../src/network.js') var Network = require('../src/network.js')
var Util = require('../src/util.js') var crypto = require('../').crypto
var sha256ripe160 = Util.sha256ripe160 var sha256ripe160 = crypto.sha256ripe160
var Convert = require('../src/convert.js') var Convert = require('../src/convert.js')
var bytesToHex = Convert.bytesToHex var bytesToHex = Convert.bytesToHex
var hexToBytes = Convert.hexToBytes var hexToBytes = Convert.hexToBytes