mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-23 14:50:42 +01:00
Adding some scaladocs for ECFactory - removing redudant factory functions
This commit is contained in:
parent
4b9a203786
commit
69fd641b87
3 changed files with 9 additions and 2 deletions
|
@ -3,6 +3,8 @@ package org.scalacoin.crypto
|
|||
import org.scalacoin.protocol.script.ScriptPubKey
|
||||
import org.scalacoin.protocol.transaction.{Transaction, TransactionInput}
|
||||
import org.scalacoin.script.crypto.HashType
|
||||
import org.scalacoin.util.BitcoinSUtil
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
/**
|
||||
* Created by chris on 2/16/16.
|
||||
|
@ -10,6 +12,7 @@ import org.scalacoin.script.crypto.HashType
|
|||
trait TransactionSignatureChecker {
|
||||
|
||||
|
||||
private def logger = LoggerFactory.getLogger(this.getClass())
|
||||
/**
|
||||
* Checks the signature of a scriptSig in the spending transaction against the
|
||||
* given scriptPubKey
|
||||
|
@ -24,6 +27,8 @@ trait TransactionSignatureChecker {
|
|||
def checkSignature(spendingTransaction : Transaction, inputIndex : Int, scriptPubKey : ScriptPubKey,
|
||||
signature : ECDigitalSignature, pubKey: ECPublicKey, hashType : HashType) : Boolean = {
|
||||
val hashForSignature = TransactionSignatureSerializer.hashForSignature(spendingTransaction,inputIndex,scriptPubKey,hashType)
|
||||
logger.info("Hash for signature: " + BitcoinSUtil.encodeHex(hashForSignature))
|
||||
|
||||
val isValid = pubKey.verify(hashForSignature,signature)
|
||||
isValid
|
||||
}
|
||||
|
|
|
@ -16,9 +16,10 @@ class TransactionSignatureCheckerTest extends FlatSpec with MustMatchers {
|
|||
TransactionTestUtil.transactionWithSpendingInputAndCreditingOutput
|
||||
val scriptSig : ScriptSignature = spendingInput.scriptSignature
|
||||
val pubKey : ECPublicKey = ECFactory.publicKey(scriptSig.asm.last.bytes)
|
||||
require("30450221008337ce3ce0c6ac0ab72509f889c1d52701817a2362d6357457b63e3bdedc0c0602202908963b9cf1a095ab3b34b95ce2bc0d67fb0f19be1cc5f7b3de0b3a325629bf01" == scriptSig.signatures.head.hex)
|
||||
require("0241d746ca08da0a668735c3e01c1fa02045f2f399c5937079b6434b5a31dfe353" == pubKey.hex)
|
||||
|
||||
val hashType = scriptSig.hashType(scriptSig.signatures.head)
|
||||
require(scriptSig.signatures.head.hex == "30450221008337ce3ce0c6ac0ab72509f889c1d52701817a2362d6357457b63e3bdedc0c0602202908963b9cf1a095ab3b34b95ce2bc0d67fb0f19be1cc5f7b3de0b3a325629bf01")
|
||||
require(pubKey.hex == "0241d746ca08da0a668735c3e01c1fa02045f2f399c5937079b6434b5a31dfe353" )
|
||||
require(hashType == SIGHASH_ALL)
|
||||
TransactionSignatureChecker.checkSignature(spendingTx,0,creditingOutput.scriptPubKey,
|
||||
scriptSig.signatures.head,pubKey,hashType) must be (true)
|
||||
|
|
|
@ -55,6 +55,7 @@ trait TransactionTestUtil {
|
|||
val creditingOutput = TestUtil.parentSimpleTransaction.outputs(creditingTx.inputs.head.previousOutput.vout)
|
||||
//make sure the outpoint index and the outpoint txid are correct
|
||||
require(spendingTx.inputs.head.previousOutput.txId == creditingTx.txId)
|
||||
require(spendingTx.inputs.head.previousOutput.vout == 0)
|
||||
(spendingTx,spendingTx.inputs.head, creditingOutput)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue