Browse Source

all: rename D to d as per SEC convention

hk-custom-address
Daniel Cousens 11 years ago
parent
commit
eb3a6bcb31
  1. 12
      src/ecdsa.js
  2. 24
      src/eckey.js
  3. 6
      src/hdnode.js
  4. 2
      test/bitcoin.core.js
  5. 4
      test/ec.js
  6. 20
      test/ecdsa.js
  7. 13
      test/eckey.js
  8. 24
      test/fixtures/ecdsa.json
  9. 16
      test/fixtures/eckey.json
  10. 4
      test/fixtures/message.json
  11. 10
      test/hdnode.js
  12. 4
      test/message.js

12
src/ecdsa.js

@ -4,12 +4,12 @@ var crypto = require('./crypto')
var BigInteger = require('bigi') var BigInteger = require('bigi')
var ECPointFp = require('./ec').ECPointFp 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(Buffer.isBuffer(hash), 'Hash must be a Buffer, not ' + hash)
assert.equal(hash.length, 32, 'Hash must be 256 bit') 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 k = new Buffer(32)
var v = new Buffer(32) var v = new Buffer(32)
k.fill(0) k.fill(0)
@ -30,8 +30,8 @@ function deterministicGenerateK(ecparams, hash, D) {
return kB return kB
} }
function sign(ecparams, hash, D) { function sign(ecparams, hash, d) {
var k = deterministicGenerateK(ecparams, hash, D) var k = deterministicGenerateK(ecparams, hash, d)
var n = ecparams.getN() var n = ecparams.getN()
var G = ecparams.getG() var G = ecparams.getG()
@ -41,7 +41,7 @@ function sign(ecparams, hash, D) {
var r = Q.getX().toBigInteger().mod(n) var r = Q.getX().toBigInteger().mod(n)
assert.notEqual(r.signum(), 0, 'Invalid R value') 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') assert.notEqual(s.signum(), 0, 'Invalid S value')
var N_OVER_TWO = n.shiftRight(1) var N_OVER_TWO = n.shiftRight(1)

24
src/eckey.js

@ -10,13 +10,13 @@ var ECPubKey = require('./ecpubkey')
var sec = require('./sec') var sec = require('./sec')
var ecparams = sec('secp256k1') var ecparams = sec('secp256k1')
function ECKey(D, compressed) { function ECKey(d, compressed) {
assert(D.signum() > 0, 'Private key must be greater than 0') 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') 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) this.pub = new ECPubKey(Q, compressed)
} }
@ -38,18 +38,18 @@ ECKey.fromWIF = function(string) {
assert.equal(payload.length, 32, 'Invalid WIF payload length') assert.equal(payload.length, 32, 'Invalid WIF payload length')
var D = BigInteger.fromBuffer(payload) var d = BigInteger.fromBuffer(payload)
return new ECKey(D, compressed) return new ECKey(d, compressed)
} }
ECKey.makeRandom = function(compressed, rng) { ECKey.makeRandom = function(compressed, rng) {
rng = rng || secureRandom rng = rng || secureRandom
var buffer = new Buffer(rng(32)) var buffer = new Buffer(rng(32))
var D = BigInteger.fromBuffer(buffer) var d = BigInteger.fromBuffer(buffer)
D = D.mod(ecparams.getN()) d = d.mod(ecparams.getN())
return new ECKey(D, compressed) return new ECKey(d, compressed)
} }
// Export functions // Export functions
@ -60,7 +60,7 @@ ECKey.prototype.toWIF = function(network) {
var buffer = new Buffer(bufferLen) var buffer = new Buffer(bufferLen)
buffer.writeUInt8(network.wif, 0) buffer.writeUInt8(network.wif, 0)
this.D.toBuffer(32).copy(buffer, 1) this.d.toBuffer(32).copy(buffer, 1)
if (this.pub.compressed) { if (this.pub.compressed) {
buffer.writeUInt8(0x01, 33) buffer.writeUInt8(0x01, 33)
@ -71,7 +71,7 @@ ECKey.prototype.toWIF = function(network) {
// Operations // Operations
ECKey.prototype.sign = function(hash) { ECKey.prototype.sign = function(hash) {
return ecdsa.sign(ecparams, hash, this.D) return ecdsa.sign(ecparams, hash, this.d)
} }
module.exports = ECKey module.exports = ECKey

6
src/hdnode.js

@ -174,7 +174,7 @@ HDNode.prototype.toBuffer = function(isPrivate) {
// 0x00 + k for private keys // 0x00 + k for private keys
buffer.writeUInt8(0, 45) buffer.writeUInt8(0, 45)
this.privKey.D.toBuffer(32).copy(buffer, 46) this.privKey.d.toBuffer(32).copy(buffer, 46)
} else { } else {
// X9.62 encoding for public keys // X9.62 encoding for public keys
@ -202,7 +202,7 @@ HDNode.prototype.derive = function(index) {
// data = 0x00 || ser256(kpar) || ser32(index) // data = 0x00 || ser256(kpar) || ser32(index)
data = Buffer.concat([ data = Buffer.concat([
this.privKey.D.toBuffer(33), this.privKey.d.toBuffer(33),
indexBuffer indexBuffer
]) ])
@ -231,7 +231,7 @@ HDNode.prototype.derive = function(index) {
var hd var hd
if (this.privKey) { if (this.privKey) {
// ki = parse256(IL) + kpar (mod n) // 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 // In case ki == 0, proceed with the next value for i
if (ki.signum() === 0) { if (ki.signum() === 0) {

2
test/bitcoin.core.js

@ -101,7 +101,7 @@ describe('Bitcoin-core', function() {
it('imports ' + string + ' correctly', function() { it('imports ' + string + ' correctly', function() {
var privKey = ECKey.fromWIF(string) var privKey = ECKey.fromWIF(string)
assert.equal(privKey.D.toHex(), hex) assert.equal(privKey.d.toHex(), hex)
assert.equal(privKey.pub.compressed, params.isCompressed) assert.equal(privKey.pub.compressed, params.isCompressed)
}) })
}) })

4
test/ec.js

@ -70,8 +70,8 @@ describe('ec', function() {
var ecparams2 = sec('secp256r1') var ecparams2 = sec('secp256r1')
var curve = ecparams2.getCurve() var curve = ecparams2.getCurve()
var D = BigInteger.ONE var d = BigInteger.ONE
var Q = ecparams2.getG().multiply(D) var Q = ecparams2.getG().multiply(d)
var buffer = Q.getEncoded(true) var buffer = Q.getEncoded(true)
var decoded = ECPointFp.decodeFrom(curve, buffer) var decoded = ECPointFp.decodeFrom(curve, buffer)

20
test/ecdsa.js

@ -15,10 +15,10 @@ describe('ecdsa', function() {
describe('deterministicGenerateK', function() { describe('deterministicGenerateK', function() {
it('matches the test vectors', function() { it('matches the test vectors', function() {
fixtures.valid.forEach(function(f) { fixtures.valid.forEach(function(f) {
var D = BigInteger.fromHex(f.D) var d = BigInteger.fromHex(f.d)
var h1 = crypto.sha256(f.message) var h1 = crypto.sha256(f.message)
var k = ecdsa.deterministicGenerateK(ecparams, h1, D) var k = ecdsa.deterministicGenerateK(ecparams, h1, d)
assert.equal(k.toHex(), f.k) assert.equal(k.toHex(), f.k)
}) })
}) })
@ -26,10 +26,10 @@ describe('ecdsa', function() {
describe('recoverPubKey', function() { describe('recoverPubKey', function() {
it('succesfully recovers a public key', function() { it('succesfully recovers a public key', function() {
var D = BigInteger.ONE var d = BigInteger.ONE
var signature = new Buffer('INcvXVVEFyIfHLbDX+xoxlKFn3Wzj9g0UbhObXdMq+YMKC252o5RHFr0/cKdQe1WsBLUBi4morhgZ77obDJVuV0=', 'base64') var signature = new Buffer('INcvXVVEFyIfHLbDX+xoxlKFn3Wzj9g0UbhObXdMq+YMKC252o5RHFr0/cKdQe1WsBLUBi4morhgZ77obDJVuV0=', 'base64')
var Q = ecparams.getG().multiply(D) var Q = ecparams.getG().multiply(d)
var hash = message.magicHash('1111', networks.bitcoin) var hash = message.magicHash('1111', networks.bitcoin)
var e = BigInteger.fromBuffer(hash) var e = BigInteger.fromBuffer(hash)
var parsed = ecdsa.parseSigCompact(signature) var parsed = ecdsa.parseSigCompact(signature)
@ -42,9 +42,9 @@ describe('ecdsa', function() {
describe('sign', function() { describe('sign', function() {
it('matches the test vectors', function() { it('matches the test vectors', function() {
fixtures.valid.forEach(function(f) { fixtures.valid.forEach(function(f) {
var D = BigInteger.fromHex(f.D) var d = BigInteger.fromHex(f.d)
var hash = crypto.sha256(f.message) var hash = crypto.sha256(f.message)
var signature = ecdsa.sign(ecparams, hash, D) var signature = ecdsa.sign(ecparams, hash, d)
assert.equal(signature.r.toString(), f.signature.r) assert.equal(signature.r.toString(), f.signature.r)
assert.equal(signature.s.toString(), f.signature.s) assert.equal(signature.s.toString(), f.signature.s)
@ -64,8 +64,8 @@ describe('ecdsa', function() {
describe('verifyRaw', function() { describe('verifyRaw', function() {
it('verifies valid signatures', function() { it('verifies valid signatures', function() {
fixtures.valid.forEach(function(f) { fixtures.valid.forEach(function(f) {
var D = BigInteger.fromHex(f.D) var d = BigInteger.fromHex(f.d)
var Q = ecparams.getG().multiply(D) var Q = ecparams.getG().multiply(d)
var signature = { var signature = {
r: new BigInteger(f.signature.r), r: new BigInteger(f.signature.r),
@ -79,13 +79,13 @@ describe('ecdsa', function() {
fixtures.invalid.verifyRaw.forEach(function(f) { fixtures.invalid.verifyRaw.forEach(function(f) {
it('fails to verify with ' + f.description, function() { it('fails to verify with ' + f.description, function() {
var D = BigInteger.fromHex(f.D) var d = BigInteger.fromHex(f.d)
var e = BigInteger.fromHex(f.e) var e = BigInteger.fromHex(f.e)
var signature = { var signature = {
r: new BigInteger(f.signature.r), r: new BigInteger(f.signature.r),
s: new BigInteger(f.signature.s) s: new BigInteger(f.signature.s)
} }
var Q = ecparams.getG().multiply(D) var Q = ecparams.getG().multiply(d)
assert.equal(ecdsa.verifyRaw(ecparams, e, signature, Q), false) assert.equal(ecdsa.verifyRaw(ecparams, e, signature, Q), false)
}) })

13
test/eckey.js

@ -22,19 +22,20 @@ describe('ECKey', function() {
}) })
fixtures.valid.forEach(function(f) { fixtures.valid.forEach(function(f) {
it('calculates the matching pubKey for ' + f.D, function() { it('calculates the matching pubKey for ' + f.d, function() {
var privKey = new ECKey(new BigInteger(f.D)) var d = new BigInteger(f.d)
var privKey = new ECKey(d)
assert.equal(privKey.pub.Q.toString(), f.Q.toString()) assert.equal(privKey.pub.Q.toString(), f.Q.toString())
}) })
}) })
fixtures.invalid.constructor.forEach(function(f) { fixtures.invalid.constructor.forEach(function(f) {
it('throws on ' + f.D, function() { it('throws on ' + f.d, function() {
var D = new BigInteger(f.D) var d = new BigInteger(f.d)
assert.throws(function() { assert.throws(function() {
new ECKey(D) new ECKey(d)
}, new RegExp(f.exception)) }, new RegExp(f.exception))
}) })
}) })
@ -46,7 +47,7 @@ describe('ECKey', function() {
it('imports ' + wif.string + ' correctly', function() { it('imports ' + wif.string + ' correctly', function() {
var privKey = ECKey.fromWIF(wif.string) var privKey = ECKey.fromWIF(wif.string)
assert.equal(privKey.D.toString(), f.D) assert.equal(privKey.d.toString(), f.d)
assert.equal(privKey.pub.compressed, wif.compressed) assert.equal(privKey.pub.compressed, wif.compressed)
}) })
}) })

24
test/fixtures/ecdsa.json

@ -1,7 +1,7 @@
{ {
"valid": [ "valid": [
{ {
"D": "01", "d": "01",
"k": "ec633bd56a5774a0940cb97e27a9e4e51dc94af737596a0c5cbb3d30332d92a5", "k": "ec633bd56a5774a0940cb97e27a9e4e51dc94af737596a0c5cbb3d30332d92a5",
"message": "Everything should be made as simple as possible, but not simpler.", "message": "Everything should be made as simple as possible, but not simpler.",
"compact": { "compact": {
@ -16,7 +16,7 @@
} }
}, },
{ {
"D": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140", "d": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",
"k": "9dc74cbfd383980fb4ae5d2680acddac9dac956dca65a28c80ac9c847c2374e4", "k": "9dc74cbfd383980fb4ae5d2680acddac9dac956dca65a28c80ac9c847c2374e4",
"message": "Equations are more important to me, because politics is for the present, but an equation is something for eternity.", "message": "Equations are more important to me, because politics is for the present, but an equation is something for eternity.",
"compact": { "compact": {
@ -31,7 +31,7 @@
} }
}, },
{ {
"D": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140", "d": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",
"k": "fd27071f01648ebbdd3e1cfbae48facc9fa97edc43bbbc9a7fdc28eae13296f5", "k": "fd27071f01648ebbdd3e1cfbae48facc9fa97edc43bbbc9a7fdc28eae13296f5",
"message": "Not only is the Universe stranger than we think, it is stranger than we can think.", "message": "Not only is the Universe stranger than we think, it is stranger than we can think.",
"compact": { "compact": {
@ -46,7 +46,7 @@
} }
}, },
{ {
"D": "0000000000000000000000000000000000000000000000000000000000000001", "d": "0000000000000000000000000000000000000000000000000000000000000001",
"k": "f0cd2ba5fc7c183de589f6416220a36775a146740798756d8d949f7166dcc87f", "k": "f0cd2ba5fc7c183de589f6416220a36775a146740798756d8d949f7166dcc87f",
"message": "How wonderful that we have met with a paradox. Now we have some hope of making progress.", "message": "How wonderful that we have met with a paradox. Now we have some hope of making progress.",
"compact": { "compact": {
@ -61,7 +61,7 @@
} }
}, },
{ {
"D": "69ec59eaa1f4f2e36b639716b7c30ca86d9a5375c7b38d8918bd9c0ebc80ba64", "d": "69ec59eaa1f4f2e36b639716b7c30ca86d9a5375c7b38d8918bd9c0ebc80ba64",
"k": "6bb4a594ad57c1aa22dbe991a9d8501daf4688bf50a4892ef21bd7c711afda97", "k": "6bb4a594ad57c1aa22dbe991a9d8501daf4688bf50a4892ef21bd7c711afda97",
"message": "Computer science is no more about computers than astronomy is about telescopes.", "message": "Computer science is no more about computers than astronomy is about telescopes.",
"compact": { "compact": {
@ -76,7 +76,7 @@
} }
}, },
{ {
"D": "00000000000000000000000000007246174ab1e92e9149c6e446fe194d072637", "d": "00000000000000000000000000007246174ab1e92e9149c6e446fe194d072637",
"k": "097b5c8ee22c3ea78a4d3635e0ff6fe85a1eb92ce317ded90b9e71aab2b861cb", "k": "097b5c8ee22c3ea78a4d3635e0ff6fe85a1eb92ce317ded90b9e71aab2b861cb",
"message": "...if you aren't, at any given time, scandalized by code you wrote five or even three years ago, you're not learning anywhere near enough", "message": "...if you aren't, at any given time, scandalized by code you wrote five or even three years ago, you're not learning anywhere near enough",
"compact": { "compact": {
@ -91,7 +91,7 @@
} }
}, },
{ {
"D": "000000000000000000000000000000000000000000056916d0f9b31dc9b637f3", "d": "000000000000000000000000000000000000000000056916d0f9b31dc9b637f3",
"k": "19355c36c8cbcdfb2382e23b194b79f8c97bf650040fc7728dfbf6b39a97c25b", "k": "19355c36c8cbcdfb2382e23b194b79f8c97bf650040fc7728dfbf6b39a97c25b",
"message": "The question of whether computers can think is like the question of whether submarines can swim.", "message": "The question of whether computers can think is like the question of whether submarines can swim.",
"compact": { "compact": {
@ -146,7 +146,7 @@
"verifyRaw": [ "verifyRaw": [
{ {
"description": "The wrong signature", "description": "The wrong signature",
"D": "01", "d": "01",
"e": "06ef2b193b83b3d701f765f1db34672ab84897e1252343cc2197829af3a30456", "e": "06ef2b193b83b3d701f765f1db34672ab84897e1252343cc2197829af3a30456",
"signature": { "signature": {
"r": "38341707918488238920692284707283974715538935465589664377561695343399725051885", "r": "38341707918488238920692284707283974715538935465589664377561695343399725051885",
@ -155,7 +155,7 @@
}, },
{ {
"description": "Invalid r value (== 0)", "description": "Invalid r value (== 0)",
"D": "01", "d": "01",
"e": "01", "e": "01",
"signature": { "signature": {
"r": "00", "r": "00",
@ -164,7 +164,7 @@
}, },
{ {
"description": "Invalid r value (>= n)", "description": "Invalid r value (>= n)",
"D": "01", "d": "01",
"e": "01", "e": "01",
"signature": { "signature": {
"r": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", "r": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",
@ -173,7 +173,7 @@
}, },
{ {
"description": "Invalid s value (== 0)", "description": "Invalid s value (== 0)",
"D": "01", "d": "01",
"e": "01", "e": "01",
"signature": { "signature": {
"r": "02", "r": "02",
@ -182,7 +182,7 @@
}, },
{ {
"description": "Invalid s value (>= n)", "description": "Invalid s value (>= n)",
"D": "01", "d": "01",
"e": "01", "e": "01",
"signature": { "signature": {
"r": "02", "r": "02",

16
test/fixtures/eckey.json

@ -1,7 +1,7 @@
{ {
"valid": [ "valid": [
{ {
"D": "1", "d": "1",
"Q": "(55066263022277343669578718895168534326250603453777594175500187360389116729240,32670510020758816978083085130507043184471273380659243275938904335757337482424)", "Q": "(55066263022277343669578718895168534326250603453777594175500187360389116729240,32670510020758816978083085130507043184471273380659243275938904335757337482424)",
"WIFs": [ "WIFs": [
{ {
@ -17,7 +17,7 @@
] ]
}, },
{ {
"D": "19898843618908353587043383062236220484949425084007183071220218307100305431102", "d": "19898843618908353587043383062236220484949425084007183071220218307100305431102",
"Q": "(83225686012142088543596389522774768397204444195709443235253141114409346958144,23739058578904784236915560265041168694780215705543362357495033621678991351768)", "Q": "(83225686012142088543596389522774768397204444195709443235253141114409346958144,23739058578904784236915560265041168694780215705543362357495033621678991351768)",
"WIFs": [ "WIFs": [
{ {
@ -28,7 +28,7 @@
] ]
}, },
{ {
"D": "48968302285117906840285529799176770990048954789747953886390402978935544927851", "d": "48968302285117906840285529799176770990048954789747953886390402978935544927851",
"Q": "(30095590000961171681152428142595206241714764354580127609094760797518133922356,93521207164355458151597931319591130635754976513751247168472016818884561919702)", "Q": "(30095590000961171681152428142595206241714764354580127609094760797518133922356,93521207164355458151597931319591130635754976513751247168472016818884561919702)",
"WIFs": [ "WIFs": [
{ {
@ -54,7 +54,7 @@
] ]
}, },
{ {
"D": "115792089237316195423570985008687907852837564279074904382605163141518161494336", "d": "115792089237316195423570985008687907852837564279074904382605163141518161494336",
"Q": "(55066263022277343669578718895168534326250603453777594175500187360389116729240,83121579216557378445487899878180864668798711284981320763518679672151497189239)", "Q": "(55066263022277343669578718895168534326250603453777594175500187360389116729240,83121579216557378445487899878180864668798711284981320763518679672151497189239)",
"WIFs": [ "WIFs": [
{ {
@ -69,19 +69,19 @@
"constructor": [ "constructor": [
{ {
"exception": "Private key must be greater than 0", "exception": "Private key must be greater than 0",
"D": "-1" "d": "-1"
}, },
{ {
"exception": "Private key must be greater than 0", "exception": "Private key must be greater than 0",
"D": "0" "d": "0"
}, },
{ {
"exception": "Private key must be less than the curve order", "exception": "Private key must be less than the curve order",
"D": "115792089237316195423570985008687907852837564279074904382605163141518161494337" "d": "115792089237316195423570985008687907852837564279074904382605163141518161494337"
}, },
{ {
"exception": "Private key must be less than the curve order", "exception": "Private key must be less than the curve order",
"D": "115792089237316195423570985008687907853269984665640564039457584007913129639935" "d": "115792089237316195423570985008687907853269984665640564039457584007913129639935"
} }
], ],
"WIF": [ "WIF": [

4
test/fixtures/message.json

@ -40,7 +40,7 @@
"description": "gives equal r, s values irrespective of point compression", "description": "gives equal r, s values irrespective of point compression",
"message": "vires is numeris", "message": "vires is numeris",
"network": "bitcoin", "network": "bitcoin",
"D": "1", "d": "1",
"signature": "HF8nHqFr3K2UKYahhX3soVeoW8W1ECNbr0wfck7lzyXjCS5Q16Ek45zyBuy1Fiy9sTPKVgsqqOuPvbycuVSSVl8=", "signature": "HF8nHqFr3K2UKYahhX3soVeoW8W1ECNbr0wfck7lzyXjCS5Q16Ek45zyBuy1Fiy9sTPKVgsqqOuPvbycuVSSVl8=",
"compressed": { "compressed": {
"signature": "IF8nHqFr3K2UKYahhX3soVeoW8W1ECNbr0wfck7lzyXjCS5Q16Ek45zyBuy1Fiy9sTPKVgsqqOuPvbycuVSSVl8=" "signature": "IF8nHqFr3K2UKYahhX3soVeoW8W1ECNbr0wfck7lzyXjCS5Q16Ek45zyBuy1Fiy9sTPKVgsqqOuPvbycuVSSVl8="
@ -50,7 +50,7 @@
"description": "supports alternative networks", "description": "supports alternative networks",
"message": "vires is numeris", "message": "vires is numeris",
"network": "dogecoin", "network": "dogecoin",
"D": "1", "d": "1",
"signature": "G6k+dZwJ8oOei3PCSpdj603fDvhlhQ+sqaFNIDvo/bI+Xh6zyIKGzZpyud6YhZ1a5mcrwMVtTWL+VXq/hC5Zj7s=" "signature": "G6k+dZwJ8oOei3PCSpdj603fDvhlhQ+sqaFNIDvo/bI+Xh6zyIKGzZpyud6YhZ1a5mcrwMVtTWL+VXq/hC5Zj7s="
} }
] ]

10
test/hdnode.js

@ -10,20 +10,20 @@ var fixtures = require('./fixtures/hdnode.json')
describe('HDNode', function() { describe('HDNode', function() {
describe('Constructor', function() { describe('Constructor', function() {
var D = BigInteger.ONE var d = BigInteger.ONE
var Q = ecparams.getG().multiply(D) var Q = ecparams.getG().multiply(d)
var chainCode = new Buffer(32) var chainCode = new Buffer(32)
chainCode.fill(1) chainCode.fill(1)
it('calculates the publicKey from a BigInteger', function() { it('calculates the publicKey from a BigInteger', function() {
var hd = new HDNode(D, chainCode) var hd = new HDNode(d, chainCode)
assert(hd.pubKey.Q.equals(Q)) assert(hd.pubKey.Q.equals(Q))
}) })
it('only uses compressed points', function() { it('only uses compressed points', function() {
var hd = new HDNode(Q, chainCode) var hd = new HDNode(Q, chainCode)
var hdP = new HDNode(D, chainCode) var hdP = new HDNode(d, chainCode)
assert.strictEqual(hd.pubKey.compressed, true) assert.strictEqual(hd.pubKey.compressed, true)
assert.strictEqual(hdP.pubKey.compressed, true) assert.strictEqual(hdP.pubKey.compressed, true)
@ -50,7 +50,7 @@ describe('HDNode', function() {
it('throws an exception when an unknown network is given', function() { it('throws an exception when an unknown network is given', function() {
assert.throws(function() { assert.throws(function() {
new HDNode(D, chainCode, {}) new HDNode(d, chainCode, {})
}, /Unknown BIP32 constants for network/) }, /Unknown BIP32 constants for network/)
}) })
}) })

4
test/message.js

@ -48,12 +48,12 @@ describe('Message', function() {
it(f.description, function() { it(f.description, function() {
var network = networks[f.network] var network = networks[f.network]
var privKey = new ECKey(new BigInteger(f.D), false) var privKey = new ECKey(new BigInteger(f.d), false)
var signature = Message.sign(privKey, f.message, network) var signature = Message.sign(privKey, f.message, network)
assert.equal(signature.toString('base64'), f.signature) assert.equal(signature.toString('base64'), f.signature)
if (f.compressed) { if (f.compressed) {
var compressedPrivKey = new ECKey(new BigInteger(f.D)) var compressedPrivKey = new ECKey(new BigInteger(f.d))
var compressedSignature = Message.sign(compressedPrivKey, f.message) var compressedSignature = Message.sign(compressedPrivKey, f.message)
assert.equal(compressedSignature.toString('base64'), f.compressed.signature) assert.equal(compressedSignature.toString('base64'), f.compressed.signature)

Loading…
Cancel
Save