From 1f0a54fb41636743315a4e798e20f42498795759 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 17 Jun 2014 00:26:16 +1000 Subject: [PATCH] ECSignature: rename parsing functions to parse* --- src/ecsignature.js | 4 ++-- src/message.js | 2 +- src/transaction.js | 2 +- test/ecdsa.js | 2 +- test/ecsignature.js | 12 ++++++------ 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ecsignature.js b/src/ecsignature.js index 3b5dd53..9bd345f 100644 --- a/src/ecsignature.js +++ b/src/ecsignature.js @@ -10,7 +10,7 @@ function ECSignature(r, s) { } // Import operations -ECSignature.fromCompact = function(buffer) { +ECSignature.parseCompact = function(buffer) { assert.equal(buffer.length, 65, 'Invalid signature length') var i = buffer.readUInt8(0) - 27 @@ -52,7 +52,7 @@ ECSignature.fromDER = function(buffer) { return new ECSignature(r, s) } -ECSignature.fromScriptSignature = function(buffer) { +ECSignature.parseScriptSignature = function(buffer) { return { signature: ECSignature.fromDER(buffer.slice(0, -1)), hashType: buffer.readUInt8(buffer.length - 1) diff --git a/src/message.js b/src/message.js index 2163fc8..ba5a57e 100644 --- a/src/message.js +++ b/src/message.js @@ -42,7 +42,7 @@ function verify(address, signatureBuffer, message, network) { network = network || networks.bitcoin var hash = magicHash(message, network) - var parsed = ECSignature.fromCompact(signatureBuffer) + var parsed = ECSignature.parseCompact(signatureBuffer) var e = BigInteger.fromBuffer(hash) var Q = ecdsa.recoverPubKey(ecparams, e, parsed.signature, parsed.i) diff --git a/src/transaction.js b/src/transaction.js index c9c3e08..6528adf 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -314,7 +314,7 @@ Transaction.prototype.setInputScript = function(index, script) { // FIXME: could be validateInput(index, prevTxOut, pub) 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) return pubKey.verify(hash, parsed.signature) diff --git a/test/ecdsa.js b/test/ecdsa.js index 84ec699..f025e5e 100644 --- a/test/ecdsa.js +++ b/test/ecdsa.js @@ -47,7 +47,7 @@ describe('ecdsa', function() { var e = BigInteger.fromBuffer(hash) var signatureBuffer = new Buffer('INcvXVVEFyIfHLbDX+xoxlKFn3Wzj9g0UbhObXdMq+YMKC252o5RHFr0/cKdQe1WsBLUBi4morhgZ77obDJVuV0=', 'base64') - var signature = ECSignature.fromCompact(signatureBuffer).signature + var signature = ECSignature.parseCompact(signatureBuffer).signature var points = [ '03e3a8c44a8bf712f1fbacee274fb19c0239b1a9e877eff0075ea335f2be8ff380', '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798', diff --git a/test/ecsignature.js b/test/ecsignature.js index f7c396b..dac7fb2 100644 --- a/test/ecsignature.js +++ b/test/ecsignature.js @@ -20,11 +20,11 @@ describe('ECSignature', function() { }) }) - describe('fromCompact', function() { + describe('parseCompact', function() { fixtures.valid.forEach(function(f) { it('imports ' + f.compact.hex + ' correctly', function() { 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.i, f.compact.i) @@ -38,7 +38,7 @@ describe('ECSignature', function() { var buffer = new Buffer(f.hex, 'hex') assert.throws(function() { - ECSignature.fromCompact(buffer) + ECSignature.parseCompact(buffer) }, new RegExp(f.exception)) }) }) @@ -94,11 +94,11 @@ describe('ECSignature', function() { }) }) - describe('fromScriptSignature', function() { + describe('parseScriptSignature', function() { fixtures.valid.forEach(function(f) { it('imports ' + f.scriptSignature.hex + ' correctly', function() { 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.s.toString(), f.signature.s) @@ -111,7 +111,7 @@ describe('ECSignature', function() { var buffer = new Buffer(f.hex + '01', 'hex') assert.throws(function() { - ECSignature.fromScriptSignature(buffer) + ECSignature.parseScriptSignature(buffer) }, new RegExp(f.exception)) }) })