Browse Source

ECSignature: rename parsing functions to parse*

hk-custom-address
Daniel Cousens 11 years ago
parent
commit
1f0a54fb41
  1. 4
      src/ecsignature.js
  2. 2
      src/message.js
  3. 2
      src/transaction.js
  4. 2
      test/ecdsa.js
  5. 12
      test/ecsignature.js

4
src/ecsignature.js

@ -10,7 +10,7 @@ function ECSignature(r, s) {
} }
// Import operations // Import operations
ECSignature.fromCompact = function(buffer) { ECSignature.parseCompact = function(buffer) {
assert.equal(buffer.length, 65, 'Invalid signature length') assert.equal(buffer.length, 65, 'Invalid signature length')
var i = buffer.readUInt8(0) - 27 var i = buffer.readUInt8(0) - 27
@ -52,7 +52,7 @@ ECSignature.fromDER = function(buffer) {
return new ECSignature(r, s) return new ECSignature(r, s)
} }
ECSignature.fromScriptSignature = function(buffer) { ECSignature.parseScriptSignature = function(buffer) {
return { return {
signature: ECSignature.fromDER(buffer.slice(0, -1)), signature: ECSignature.fromDER(buffer.slice(0, -1)),
hashType: buffer.readUInt8(buffer.length - 1) hashType: buffer.readUInt8(buffer.length - 1)

2
src/message.js

@ -42,7 +42,7 @@ function verify(address, signatureBuffer, message, network) {
network = network || networks.bitcoin network = network || networks.bitcoin
var hash = magicHash(message, network) var hash = magicHash(message, network)
var parsed = ECSignature.fromCompact(signatureBuffer) var parsed = ECSignature.parseCompact(signatureBuffer)
var e = BigInteger.fromBuffer(hash) var e = BigInteger.fromBuffer(hash)
var Q = ecdsa.recoverPubKey(ecparams, e, parsed.signature, parsed.i) var Q = ecdsa.recoverPubKey(ecparams, e, parsed.signature, parsed.i)

2
src/transaction.js

@ -314,7 +314,7 @@ Transaction.prototype.setInputScript = function(index, script) {
// FIXME: could be validateInput(index, prevTxOut, pub) // FIXME: could be validateInput(index, prevTxOut, pub)
Transaction.prototype.validateInput = function(index, prevOutScript, pubKey, buffer) { Transaction.prototype.validateInput = function(index, prevOutScript, pubKey, buffer) {
var parsed = ECSignature.fromScriptSignature(buffer) var parsed = ECSignature.parseScriptSignature(buffer)
var hash = this.hashForSignature(prevOutScript, index, parsed.hashType) var hash = this.hashForSignature(prevOutScript, index, parsed.hashType)
return pubKey.verify(hash, parsed.signature) return pubKey.verify(hash, parsed.signature)

2
test/ecdsa.js

@ -47,7 +47,7 @@ describe('ecdsa', function() {
var e = BigInteger.fromBuffer(hash) var e = BigInteger.fromBuffer(hash)
var signatureBuffer = new Buffer('INcvXVVEFyIfHLbDX+xoxlKFn3Wzj9g0UbhObXdMq+YMKC252o5RHFr0/cKdQe1WsBLUBi4morhgZ77obDJVuV0=', 'base64') var signatureBuffer = new Buffer('INcvXVVEFyIfHLbDX+xoxlKFn3Wzj9g0UbhObXdMq+YMKC252o5RHFr0/cKdQe1WsBLUBi4morhgZ77obDJVuV0=', 'base64')
var signature = ECSignature.fromCompact(signatureBuffer).signature var signature = ECSignature.parseCompact(signatureBuffer).signature
var points = [ var points = [
'03e3a8c44a8bf712f1fbacee274fb19c0239b1a9e877eff0075ea335f2be8ff380', '03e3a8c44a8bf712f1fbacee274fb19c0239b1a9e877eff0075ea335f2be8ff380',
'0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798', '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',

12
test/ecsignature.js

@ -20,11 +20,11 @@ describe('ECSignature', function() {
}) })
}) })
describe('fromCompact', function() { describe('parseCompact', function() {
fixtures.valid.forEach(function(f) { fixtures.valid.forEach(function(f) {
it('imports ' + f.compact.hex + ' correctly', function() { it('imports ' + f.compact.hex + ' correctly', function() {
var buffer = new Buffer(f.compact.hex, 'hex') var buffer = new Buffer(f.compact.hex, 'hex')
var parsed = ECSignature.fromCompact(buffer) var parsed = ECSignature.parseCompact(buffer)
assert.equal(parsed.compressed, f.compact.compressed) assert.equal(parsed.compressed, f.compact.compressed)
assert.equal(parsed.i, f.compact.i) assert.equal(parsed.i, f.compact.i)
@ -38,7 +38,7 @@ describe('ECSignature', function() {
var buffer = new Buffer(f.hex, 'hex') var buffer = new Buffer(f.hex, 'hex')
assert.throws(function() { assert.throws(function() {
ECSignature.fromCompact(buffer) ECSignature.parseCompact(buffer)
}, new RegExp(f.exception)) }, new RegExp(f.exception))
}) })
}) })
@ -94,11 +94,11 @@ describe('ECSignature', function() {
}) })
}) })
describe('fromScriptSignature', function() { describe('parseScriptSignature', function() {
fixtures.valid.forEach(function(f) { fixtures.valid.forEach(function(f) {
it('imports ' + f.scriptSignature.hex + ' correctly', function() { it('imports ' + f.scriptSignature.hex + ' correctly', function() {
var buffer = new Buffer(f.scriptSignature.hex, 'hex') var buffer = new Buffer(f.scriptSignature.hex, 'hex')
var parsed = ECSignature.fromScriptSignature(buffer) var parsed = ECSignature.parseScriptSignature(buffer)
assert.equal(parsed.signature.r.toString(), f.signature.r) assert.equal(parsed.signature.r.toString(), f.signature.r)
assert.equal(parsed.signature.s.toString(), f.signature.s) assert.equal(parsed.signature.s.toString(), f.signature.s)
@ -111,7 +111,7 @@ describe('ECSignature', function() {
var buffer = new Buffer(f.hex + '01', 'hex') var buffer = new Buffer(f.hex + '01', 'hex')
assert.throws(function() { assert.throws(function() {
ECSignature.fromScriptSignature(buffer) ECSignature.parseScriptSignature(buffer)
}, new RegExp(f.exception)) }, new RegExp(f.exception))
}) })
}) })

Loading…
Cancel
Save