all: rename D to d as per SEC convention
This commit is contained in:
parent
6b55ab4d04
commit
eb3a6bcb31
12 changed files with 70 additions and 69 deletions
12
src/ecdsa.js
12
src/ecdsa.js
|
@ -4,12 +4,12 @@ var crypto = require('./crypto')
|
|||
var BigInteger = require('bigi')
|
||||
var ECPointFp = require('./ec').ECPointFp
|
||||
|
||||
function deterministicGenerateK(ecparams, hash, D) {
|
||||
function deterministicGenerateK(ecparams, hash, d) {
|
||||
assert(Buffer.isBuffer(hash), 'Hash must be a Buffer, not ' + hash)
|
||||
assert.equal(hash.length, 32, 'Hash must be 256 bit')
|
||||
assert(D instanceof BigInteger, 'Private key must be a BigInteger')
|
||||
assert(d instanceof BigInteger, 'Private key must be a BigInteger')
|
||||
|
||||
var x = D.toBuffer(32)
|
||||
var x = d.toBuffer(32)
|
||||
var k = new Buffer(32)
|
||||
var v = new Buffer(32)
|
||||
k.fill(0)
|
||||
|
@ -30,8 +30,8 @@ function deterministicGenerateK(ecparams, hash, D) {
|
|||
return kB
|
||||
}
|
||||
|
||||
function sign(ecparams, hash, D) {
|
||||
var k = deterministicGenerateK(ecparams, hash, D)
|
||||
function sign(ecparams, hash, d) {
|
||||
var k = deterministicGenerateK(ecparams, hash, d)
|
||||
|
||||
var n = ecparams.getN()
|
||||
var G = ecparams.getG()
|
||||
|
@ -41,7 +41,7 @@ function sign(ecparams, hash, D) {
|
|||
var r = Q.getX().toBigInteger().mod(n)
|
||||
assert.notEqual(r.signum(), 0, 'Invalid R value')
|
||||
|
||||
var s = k.modInverse(n).multiply(e.add(D.multiply(r))).mod(n)
|
||||
var s = k.modInverse(n).multiply(e.add(d.multiply(r))).mod(n)
|
||||
assert.notEqual(s.signum(), 0, 'Invalid S value')
|
||||
|
||||
var N_OVER_TWO = n.shiftRight(1)
|
||||
|
|
24
src/eckey.js
24
src/eckey.js
|
@ -10,13 +10,13 @@ var ECPubKey = require('./ecpubkey')
|
|||
var sec = require('./sec')
|
||||
var ecparams = sec('secp256k1')
|
||||
|
||||
function ECKey(D, compressed) {
|
||||
assert(D.signum() > 0, 'Private key must be greater than 0')
|
||||
assert(D.compareTo(ecparams.getN()) < 0, 'Private key must be less than the curve order')
|
||||
function ECKey(d, compressed) {
|
||||
assert(d.signum() > 0, 'Private key must be greater than 0')
|
||||
assert(d.compareTo(ecparams.getN()) < 0, 'Private key must be less than the curve order')
|
||||
|
||||
var Q = ecparams.getG().multiply(D)
|
||||
var Q = ecparams.getG().multiply(d)
|
||||
|
||||
this.D = D
|
||||
this.d = d
|
||||
this.pub = new ECPubKey(Q, compressed)
|
||||
}
|
||||
|
||||
|
@ -38,18 +38,18 @@ ECKey.fromWIF = function(string) {
|
|||
|
||||
assert.equal(payload.length, 32, 'Invalid WIF payload length')
|
||||
|
||||
var D = BigInteger.fromBuffer(payload)
|
||||
return new ECKey(D, compressed)
|
||||
var d = BigInteger.fromBuffer(payload)
|
||||
return new ECKey(d, compressed)
|
||||
}
|
||||
|
||||
ECKey.makeRandom = function(compressed, rng) {
|
||||
rng = rng || secureRandom
|
||||
|
||||
var buffer = new Buffer(rng(32))
|
||||
var D = BigInteger.fromBuffer(buffer)
|
||||
D = D.mod(ecparams.getN())
|
||||
var d = BigInteger.fromBuffer(buffer)
|
||||
d = d.mod(ecparams.getN())
|
||||
|
||||
return new ECKey(D, compressed)
|
||||
return new ECKey(d, compressed)
|
||||
}
|
||||
|
||||
// Export functions
|
||||
|
@ -60,7 +60,7 @@ ECKey.prototype.toWIF = function(network) {
|
|||
var buffer = new Buffer(bufferLen)
|
||||
|
||||
buffer.writeUInt8(network.wif, 0)
|
||||
this.D.toBuffer(32).copy(buffer, 1)
|
||||
this.d.toBuffer(32).copy(buffer, 1)
|
||||
|
||||
if (this.pub.compressed) {
|
||||
buffer.writeUInt8(0x01, 33)
|
||||
|
@ -71,7 +71,7 @@ ECKey.prototype.toWIF = function(network) {
|
|||
|
||||
// Operations
|
||||
ECKey.prototype.sign = function(hash) {
|
||||
return ecdsa.sign(ecparams, hash, this.D)
|
||||
return ecdsa.sign(ecparams, hash, this.d)
|
||||
}
|
||||
|
||||
module.exports = ECKey
|
||||
|
|
|
@ -174,7 +174,7 @@ HDNode.prototype.toBuffer = function(isPrivate) {
|
|||
|
||||
// 0x00 + k for private keys
|
||||
buffer.writeUInt8(0, 45)
|
||||
this.privKey.D.toBuffer(32).copy(buffer, 46)
|
||||
this.privKey.d.toBuffer(32).copy(buffer, 46)
|
||||
} else {
|
||||
|
||||
// X9.62 encoding for public keys
|
||||
|
@ -202,7 +202,7 @@ HDNode.prototype.derive = function(index) {
|
|||
|
||||
// data = 0x00 || ser256(kpar) || ser32(index)
|
||||
data = Buffer.concat([
|
||||
this.privKey.D.toBuffer(33),
|
||||
this.privKey.d.toBuffer(33),
|
||||
indexBuffer
|
||||
])
|
||||
|
||||
|
@ -231,7 +231,7 @@ HDNode.prototype.derive = function(index) {
|
|||
var hd
|
||||
if (this.privKey) {
|
||||
// ki = parse256(IL) + kpar (mod n)
|
||||
var ki = pIL.add(this.privKey.D).mod(ecparams.getN())
|
||||
var ki = pIL.add(this.privKey.d).mod(ecparams.getN())
|
||||
|
||||
// In case ki == 0, proceed with the next value for i
|
||||
if (ki.signum() === 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue