ECSignature: rename parsing functions to parse*
This commit is contained in:
parent
f42993297c
commit
1f0a54fb41
5 changed files with 11 additions and 11 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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))
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue