Browse Source

Makes ECDSA capitalization consistent

hk-custom-address
Daniel Cousens 11 years ago
parent
commit
6de94856e3
  1. 14
      src/ecdsa.js
  2. 4
      src/transaction.js
  3. 2
      test/ec.js

14
src/ecdsa.js

@ -51,7 +51,7 @@ function deterministicGenerateK(hash,key) {
return BigInteger.fromByteArrayUnsigned(vArr) return BigInteger.fromByteArrayUnsigned(vArr)
} }
var ECDSA = { var ecdsa = {
getBigRandom: function (limit) { getBigRandom: function (limit) {
return new BigInteger(limit.bitLength(), rng). return new BigInteger(limit.bitLength(), rng).
mod(limit.subtract(BigInteger.ONE)). mod(limit.subtract(BigInteger.ONE)).
@ -69,13 +69,13 @@ var ECDSA = {
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)
return ECDSA.serializeSig(r, s) return ecdsa.serializeSig(r, s)
}, },
verify: function (hash, sig, pubkey) { verify: function (hash, sig, pubkey) {
var r,s var r,s
if (Array.isArray(sig)) { if (Array.isArray(sig)) {
var obj = ECDSA.parseSig(sig) var obj = ecdsa.parseSig(sig)
r = obj.r r = obj.r
s = obj.s s = obj.s
} else if ("object" === typeof sig && sig.r && sig.s) { } else if ("object" === typeof sig && sig.r && sig.s) {
@ -95,7 +95,7 @@ var ECDSA = {
} }
var e = BigInteger.fromByteArrayUnsigned(hash) var e = BigInteger.fromByteArrayUnsigned(hash)
return ECDSA.verifyRaw(e, r, s, Q) return ecdsa.verifyRaw(e, r, s, Q)
}, },
verifyRaw: function (e, r, s, Q) { verifyRaw: function (e, r, s, Q) {
@ -265,7 +265,7 @@ var ECDSA = {
var Q = implShamirsTrick(R, s, G, eNeg).multiply(rInv) var Q = implShamirsTrick(R, s, G, eNeg).multiply(rInv)
Q.validate() Q.validate()
if (!ECDSA.verifyRaw(e, r, s, Q)) { if (!ecdsa.verifyRaw(e, r, s, Q)) {
throw new Error("Pubkey recovery unsuccessful") throw new Error("Pubkey recovery unsuccessful")
} }
@ -285,7 +285,7 @@ var ECDSA = {
*/ */
calcPubKeyRecoveryParam: function (origPubKey, r, s, hash) { calcPubKeyRecoveryParam: function (origPubKey, r, s, hash) {
for (var i = 0; i < 4; i++) { for (var i = 0; i < 4; i++) {
var pubKey = ECDSA.recoverPubKey(r, s, hash, i) var pubKey = ecdsa.recoverPubKey(r, s, hash, i)
if (pubKey.equals(origPubKey)) { if (pubKey.equals(origPubKey)) {
return i return i
@ -296,4 +296,4 @@ var ECDSA = {
} }
} }
module.exports = ECDSA module.exports = ecdsa

4
src/transaction.js

@ -6,7 +6,7 @@ var Script = require('./script')
var convert = require('./convert') var convert = require('./convert')
var crypto = require('./crypto') var crypto = require('./crypto')
var ECKey = require('./eckey').ECKey var ECKey = require('./eckey').ECKey
var ECDSA = require('./ecdsa') var ecdsa = require('./ecdsa')
var Transaction = function (doc) { var Transaction = function (doc) {
if (!(this instanceof Transaction)) { return new Transaction(doc) } if (!(this instanceof Transaction)) { return new Transaction(doc) }
@ -364,7 +364,7 @@ Transaction.prototype.applyMultisigs = function(index, script, sigs/*, type*/) {
Transaction.prototype.validateSig = function(index, script, sig, pub) { Transaction.prototype.validateSig = function(index, script, sig, pub) {
script = new Script(script) script = new Script(script)
var hash = this.hashTransactionForSignature(script,index,1) var hash = this.hashTransactionForSignature(script,index,1)
return ECDSA.verify(hash, convert.coerceToBytes(sig), return ecdsa.verify(hash, convert.coerceToBytes(sig),
convert.coerceToBytes(pub)) convert.coerceToBytes(pub))
} }

2
test/ec.js

@ -4,7 +4,7 @@ var ecdsa = require('../').ecdsa
var ecparams = sec('secp256k1') var ecparams = sec('secp256k1')
describe('ec', function() { describe('EC', function() {
it('handles point multiplication', function() { it('handles point multiplication', function() {
var G = ecparams.getG() var G = ecparams.getG()
var n = ecparams.getN() var n = ecparams.getN()

Loading…
Cancel
Save