Removes type coercion for a stricter TX API
This commit is contained in:
parent
9af8d95daf
commit
5546cae928
2 changed files with 11 additions and 16 deletions
|
@ -362,23 +362,20 @@ Transaction.prototype.signWithKeys = function(keys, outputs, type) {
|
|||
* Signs a P2SH output at some index with the given key
|
||||
*/
|
||||
Transaction.prototype.p2shsign = function(index, script, key, type) {
|
||||
script = new Script(script)
|
||||
key = new ECKey(key)
|
||||
type = type || SIGHASH_ALL
|
||||
var hash = this.hashTransactionForSignature(script, index, type),
|
||||
sig = key.sign(hash).concat([type])
|
||||
return sig
|
||||
var hash = this.hashTransactionForSignature(script, index, type)
|
||||
return key.sign(hash).concat([type])
|
||||
}
|
||||
|
||||
Transaction.prototype.setScriptSig = function(index, script) {
|
||||
this.ins[index].script = script
|
||||
}
|
||||
|
||||
Transaction.prototype.validateSig = function(index, script, sig, pub) {
|
||||
script = new Script(script)
|
||||
var hash = this.hashTransactionForSignature(script,index,1)
|
||||
return ecdsa.verify(hash, convert.coerceToBytes(sig),
|
||||
convert.coerceToBytes(pub))
|
||||
Transaction.prototype.validateSig = function(index, script, pub, sig, type) {
|
||||
type = type || SIGHASH_ALL
|
||||
var hash = this.hashTransactionForSignature(script, index, type)
|
||||
|
||||
return pub.verify(hash, sig)
|
||||
}
|
||||
|
||||
Transaction.feePerKb = 20000
|
||||
|
|
|
@ -171,11 +171,10 @@ describe('Transaction', function() {
|
|||
var key = ECKey.fromWIF('L44f7zxJ5Zw4EK9HZtyAnzCYz2vcZ5wiJf9AuwhJakiV4xVkxBeb')
|
||||
tx.sign(0, key)
|
||||
|
||||
var pub = key.pub.toBuffer()
|
||||
var script = prevTx.outs[0].script.buffer
|
||||
var script = prevTx.outs[0].script
|
||||
var sig = tx.ins[0].script.chunks[0]
|
||||
|
||||
assert.equal(tx.validateSig(0, script, sig, pub), true)
|
||||
assert.equal(tx.validateSig(0, script, key.pub, sig), true)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -188,11 +187,10 @@ describe('Transaction', function() {
|
|||
|
||||
it('returns true for valid signature', function(){
|
||||
var key = ECKey.fromWIF('L44f7zxJ5Zw4EK9HZtyAnzCYz2vcZ5wiJf9AuwhJakiV4xVkxBeb')
|
||||
var pub = key.pub.toBuffer()
|
||||
var script = prevTx.outs[0].script.buffer
|
||||
var script = prevTx.outs[0].script
|
||||
var sig = validTx.ins[0].script.chunks[0]
|
||||
|
||||
assert.equal(validTx.validateSig(0, script, sig, pub), true)
|
||||
assert.equal(validTx.validateSig(0, script, key.pub, sig), true)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue