Renames variables to be more verbose

This commit is contained in:
Daniel Cousens 2014-05-05 07:44:51 +10:00
parent b860daf70b
commit 02013beda9
3 changed files with 23 additions and 22 deletions

View file

@ -179,8 +179,8 @@ HDWallet.prototype.toBase58 = function(priv) {
} }
HDWallet.prototype.derive = function(i) { HDWallet.prototype.derive = function(i) {
var IB = new Buffer(4) var iBuffer = new Buffer(4)
IB.writeUInt32BE(i, 0) iBuffer.writeUInt32BE(i, 0)
var cPar = this.chaincode var cPar = this.chaincode
var usePriv = i >= HDWallet.HIGHEST_BIT var usePriv = i >= HDWallet.HIGHEST_BIT
@ -192,21 +192,20 @@ HDWallet.prototype.derive = function(i) {
// If 1, private derivation is used: // If 1, private derivation is used:
// let I = HMAC-SHA512(Key = cpar, Data = 0x00 || kpar || i) [Note:] // let I = HMAC-SHA512(Key = cpar, Data = 0x00 || kpar || i) [Note:]
var kPar = this.priv.toBuffer().slice(0, 32) var kPar = this.priv.toBuffer().slice(0, 32)
IB = Buffer.concat([new Buffer([0]), kPar, IB], 37) iBuffer = Buffer.concat([new Buffer([0]), kPar, iBuffer], 37)
// FIXME: Dislikes buffers // FIXME: Dislikes buffers
I = HmacFromBytesToBytes(CJS.algo.SHA512, Array.prototype.slice.call(IB), cPar) I = HmacFromBytesToBytes(CJS.algo.SHA512, Array.prototype.slice.call(iBuffer), cPar)
} else { } else {
// If 0, public derivation is used: // If 0, public derivation is used:
// let I = HMAC-SHA512(Key = cpar, Data = χ(kpar*G) || i) // let I = HMAC-SHA512(Key = cpar, Data = χ(kpar*G) || i)
var KPar = this.pub.toBuffer() var KPar = this.pub.toBuffer()
IB = Buffer.concat([KPar, IB]) iBuffer = Buffer.concat([KPar, iBuffer])
// FIXME: Dislikes buffers // FIXME: Dislikes buffers
I = HmacFromBytesToBytes(CJS.algo.SHA512, Array.prototype.slice.call(IB), cPar) I = HmacFromBytesToBytes(CJS.algo.SHA512, Array.prototype.slice.call(iBuffer), cPar)
} }
// FIXME: Boo, CSJ.algo.SHA512 uses byte arrays // FIXME: Boo, CSJ.algo.SHA512 uses byte arrays
I = new Buffer(I) I = new Buffer(I)

View file

@ -7,14 +7,16 @@ var ecdsa = require('./ecdsa')
var ECPubKey = require('./eckey').ECPubKey var ECPubKey = require('./eckey').ECPubKey
// FIXME: incompatible with other networks (Litecoin etc) // FIXME: incompatible with other networks (Litecoin etc)
var magicBuffer = new Buffer('\x18Bitcoin Signed Message:\n') var MAGIC_PREFIX = new Buffer('\x18Bitcoin Signed Message:\n')
function magicHash(message) { function magicHash(message) {
var mB = new Buffer(message) var messageBuffer = new Buffer(message)
var mVI = new Buffer(BufferExt.varIntSize(mB.length)) var lengthBuffer = new Buffer(BufferExt.varIntSize(messageBuffer.length))
BufferExt.writeVarInt(mVI, mB.length, 0) BufferExt.writeVarInt(lengthBuffer, messageBuffer.length, 0)
var buffer = Buffer.concat([magicBuffer, mVI, mB]) var buffer = Buffer.concat([
MAGIC_PREFIX, lengthBuffer, messageBuffer
])
return crypto.hash256(buffer) return crypto.hash256(buffer)
} }

View file

@ -153,13 +153,13 @@ Transaction.prototype.serialize = function () {
BufferExt.writeUInt64LE(buffer, i, offset) BufferExt.writeUInt64LE(buffer, i, offset)
offset += 8 offset += 8
} }
function writeVI(i) { function writeVarInt(i) {
var n = BufferExt.writeVarInt(buffer, i, offset) var n = BufferExt.writeVarInt(buffer, i, offset)
offset += n offset += n
} }
writeUInt32(this.version) writeUInt32(this.version)
writeVI(this.ins.length) writeVarInt(this.ins.length)
this.ins.forEach(function(txin, i) { this.ins.forEach(function(txin, i) {
var hash = new Buffer(txin.outpoint.hash, 'hex') // FIXME: Performance: convert on tx.addInput instead var hash = new Buffer(txin.outpoint.hash, 'hex') // FIXME: Performance: convert on tx.addInput instead
@ -169,15 +169,15 @@ Transaction.prototype.serialize = function () {
writeSlice(hash) writeSlice(hash)
writeUInt32(txin.outpoint.index) writeUInt32(txin.outpoint.index)
writeVI(txin.script.buffer.length) writeVarInt(txin.script.buffer.length)
writeSlice(txin.script.buffer) writeSlice(txin.script.buffer)
writeUInt32(txin.sequence) writeUInt32(txin.sequence)
}) })
writeVI(this.outs.length) writeVarInt(this.outs.length)
this.outs.forEach(function(txout) { this.outs.forEach(function(txout) {
writeUInt64(txout.value) writeUInt64(txout.value)
writeVI(txout.script.buffer.length) writeVarInt(txout.script.buffer.length)
writeSlice(txout.script.buffer) writeSlice(txout.script.buffer)
}) })
@ -297,7 +297,7 @@ Transaction.deserialize = function(buffer) {
offset += 8 offset += 8
return i return i
} }
function readVI() { function readVarInt() {
var vi = BufferExt.readVarInt(buffer, offset) var vi = BufferExt.readVarInt(buffer, offset)
offset += vi.size offset += vi.size
return vi.number return vi.number
@ -307,7 +307,7 @@ Transaction.deserialize = function(buffer) {
var outs = [] var outs = []
var version = readUInt32() var version = readUInt32()
var vinLen = readVI() var vinLen = readVarInt()
for (var i = 0; i < vinLen; ++i) { for (var i = 0; i < vinLen; ++i) {
var hash = readSlice(32) var hash = readSlice(32)
@ -316,7 +316,7 @@ Transaction.deserialize = function(buffer) {
Array.prototype.reverse.call(hash) Array.prototype.reverse.call(hash)
var vout = readUInt32() var vout = readUInt32()
var scriptLen = readVI() var scriptLen = readVarInt()
var script = readSlice(scriptLen) var script = readSlice(scriptLen)
var sequence = readUInt32() var sequence = readUInt32()
@ -330,11 +330,11 @@ Transaction.deserialize = function(buffer) {
}) })
} }
var voutLen = readVI() var voutLen = readVarInt()
for (i = 0; i < voutLen; ++i) { for (i = 0; i < voutLen; ++i) {
var value = readUInt64() var value = readUInt64()
var scriptLen = readVI() var scriptLen = readVarInt()
var script = readSlice(scriptLen) var script = readSlice(scriptLen)
outs.push({ outs.push({