Renames variables to be more verbose
This commit is contained in:
parent
b860daf70b
commit
02013beda9
3 changed files with 23 additions and 22 deletions
|
@ -179,8 +179,8 @@ HDWallet.prototype.toBase58 = function(priv) {
|
|||
}
|
||||
|
||||
HDWallet.prototype.derive = function(i) {
|
||||
var IB = new Buffer(4)
|
||||
IB.writeUInt32BE(i, 0)
|
||||
var iBuffer = new Buffer(4)
|
||||
iBuffer.writeUInt32BE(i, 0)
|
||||
|
||||
var cPar = this.chaincode
|
||||
var usePriv = i >= HDWallet.HIGHEST_BIT
|
||||
|
@ -192,21 +192,20 @@ HDWallet.prototype.derive = function(i) {
|
|||
// If 1, private derivation is used:
|
||||
// let I = HMAC-SHA512(Key = cpar, Data = 0x00 || kpar || i) [Note:]
|
||||
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
|
||||
I = HmacFromBytesToBytes(CJS.algo.SHA512, Array.prototype.slice.call(IB), cPar)
|
||||
I = HmacFromBytesToBytes(CJS.algo.SHA512, Array.prototype.slice.call(iBuffer), cPar)
|
||||
} else {
|
||||
// If 0, public derivation is used:
|
||||
// let I = HMAC-SHA512(Key = cpar, Data = χ(kpar*G) || i)
|
||||
var KPar = this.pub.toBuffer()
|
||||
IB = Buffer.concat([KPar, IB])
|
||||
iBuffer = Buffer.concat([KPar, iBuffer])
|
||||
|
||||
// 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
|
||||
I = new Buffer(I)
|
||||
|
||||
|
|
|
@ -7,14 +7,16 @@ var ecdsa = require('./ecdsa')
|
|||
var ECPubKey = require('./eckey').ECPubKey
|
||||
|
||||
// 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) {
|
||||
var mB = new Buffer(message)
|
||||
var mVI = new Buffer(BufferExt.varIntSize(mB.length))
|
||||
BufferExt.writeVarInt(mVI, mB.length, 0)
|
||||
var messageBuffer = new Buffer(message)
|
||||
var lengthBuffer = new Buffer(BufferExt.varIntSize(messageBuffer.length))
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -153,13 +153,13 @@ Transaction.prototype.serialize = function () {
|
|||
BufferExt.writeUInt64LE(buffer, i, offset)
|
||||
offset += 8
|
||||
}
|
||||
function writeVI(i) {
|
||||
function writeVarInt(i) {
|
||||
var n = BufferExt.writeVarInt(buffer, i, offset)
|
||||
offset += n
|
||||
}
|
||||
|
||||
writeUInt32(this.version)
|
||||
writeVI(this.ins.length)
|
||||
writeVarInt(this.ins.length)
|
||||
|
||||
this.ins.forEach(function(txin, i) {
|
||||
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)
|
||||
writeUInt32(txin.outpoint.index)
|
||||
writeVI(txin.script.buffer.length)
|
||||
writeVarInt(txin.script.buffer.length)
|
||||
writeSlice(txin.script.buffer)
|
||||
writeUInt32(txin.sequence)
|
||||
})
|
||||
|
||||
writeVI(this.outs.length)
|
||||
writeVarInt(this.outs.length)
|
||||
this.outs.forEach(function(txout) {
|
||||
writeUInt64(txout.value)
|
||||
writeVI(txout.script.buffer.length)
|
||||
writeVarInt(txout.script.buffer.length)
|
||||
writeSlice(txout.script.buffer)
|
||||
})
|
||||
|
||||
|
@ -297,7 +297,7 @@ Transaction.deserialize = function(buffer) {
|
|||
offset += 8
|
||||
return i
|
||||
}
|
||||
function readVI() {
|
||||
function readVarInt() {
|
||||
var vi = BufferExt.readVarInt(buffer, offset)
|
||||
offset += vi.size
|
||||
return vi.number
|
||||
|
@ -307,7 +307,7 @@ Transaction.deserialize = function(buffer) {
|
|||
var outs = []
|
||||
|
||||
var version = readUInt32()
|
||||
var vinLen = readVI()
|
||||
var vinLen = readVarInt()
|
||||
|
||||
for (var i = 0; i < vinLen; ++i) {
|
||||
var hash = readSlice(32)
|
||||
|
@ -316,7 +316,7 @@ Transaction.deserialize = function(buffer) {
|
|||
Array.prototype.reverse.call(hash)
|
||||
|
||||
var vout = readUInt32()
|
||||
var scriptLen = readVI()
|
||||
var scriptLen = readVarInt()
|
||||
var script = readSlice(scriptLen)
|
||||
var sequence = readUInt32()
|
||||
|
||||
|
@ -330,11 +330,11 @@ Transaction.deserialize = function(buffer) {
|
|||
})
|
||||
}
|
||||
|
||||
var voutLen = readVI()
|
||||
var voutLen = readVarInt()
|
||||
|
||||
for (i = 0; i < voutLen; ++i) {
|
||||
var value = readUInt64()
|
||||
var scriptLen = readVI()
|
||||
var scriptLen = readVarInt()
|
||||
var script = readSlice(scriptLen)
|
||||
|
||||
outs.push({
|
||||
|
|
Loading…
Reference in a new issue