Adding CryptoOperations

This commit is contained in:
Chris Stewart 2016-01-06 13:14:16 -06:00
parent 4d63c44e13
commit 349ac1b1aa
2 changed files with 140 additions and 0 deletions

View File

@ -0,0 +1,91 @@
package org.scalacoin.script.crypto
import org.scalacoin.script.ScriptOperation
/**
* Created by chris on 1/6/16.
*/
sealed trait CryptoOperation extends ScriptOperation
/**
* The input is hashed using RIPEMD-160.
*/
case object OP_RIPEMD160 extends CryptoOperation {
override def opCode = 166
}
/**
* The input is hashed using SHA-1.
*/
case object OP_SHA1 extends CryptoOperation {
override def opCode = 167
}
/**
* The input is hashed using SHA-256.
*/
case object OP_SHA256 extends CryptoOperation {
override def opCode = 168
}
/**
* The input is hashed twice: first with SHA-256 and then with RIPEMD-160.
*/
case object OP_HASH160 extends CryptoOperation {
override def opCode = 169
}
/**
* The input is hashed two times with SHA-256.
*/
case object OP_HASH256 extends CryptoOperation {
override def opCode = 170
}
/**
* All of the signature checking words will only match signatures to
* the data after the most recently-executed OP_CODESEPARATOR.
*/
case object OP_CODESEPARATOR extends CryptoOperation {
override def opCode = 171
}
/**
* The entire transaction's outputs, inputs, and script
* (from the most recently-executed OP_CODESEPARATOR to the end) are hashed.
* The signature used by OP_CHECKSIG must be a valid signature for this hash and public key.
* If it is, 1 is returned, 0 otherwise.
*/
case object OP_CHECKSIG extends CryptoOperation {
override def opCode = 172
}
/**
* Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.
*/
case object OP_CHECKSIGVERIFY extends CryptoOperation {
override def opCode = 173
}
/**
* Compares the first signature against each public key until it finds an ECDSA match.
* Starting with the subsequent public key, it compares the second signature against each remaining public key
* until it finds an ECDSA match.
* The process is repeated until all signatures have been checked or not enough public keys remain to produce a successful result.
* All signatures need to match a public key.
* Because public keys are not checked again if they fail any signature comparison,
* signatures must be placed in the scriptSig using the same order as their corresponding public keys
* were placed in the scriptPubKey or redeemScript. If all signatures are valid, 1 is returned, 0 otherwise.
* Due to a bug, one extra unused value is removed from the stack.
*/
case object OP_CHECKMULTISIG extends CryptoOperation {
override def opCode = 174
}
/**
* Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward.
*/
case object OP_CHECKMULTISIGVERIFY extends CryptoOperation {
override def opCode = 175
}

View File

@ -0,0 +1,49 @@
package org.scalacoin.script.crypto
import org.scalatest.{FlatSpec, MustMatchers}
/**
* Created by chris on 1/6/16.
*/
class CryptoOperationsTest extends FlatSpec with MustMatchers {
"CryptoOperations" must "define OP_RIPEMD160" in {
OP_RIPEMD160.opCode must be (166)
}
it must "define OP_SHA1" in {
OP_SHA1.opCode must be (167)
}
it must "define OP_SHA256" in {
OP_SHA256.opCode must be (168)
}
it must "define OP_HASH160" in {
OP_HASH160.opCode must be (169)
}
it must "define OP_HASH256" in {
OP_HASH256.opCode must be (170)
}
it must "define OP_CODESEPARATOR" in {
OP_CODESEPARATOR.opCode must be (171)
}
it must "define OP_CHECKSIG" in {
OP_CHECKSIG.opCode must be (172)
}
it must "define OP_CHECKSIGVERIFY" in {
OP_CHECKSIGVERIFY.opCode must be (173)
}
it must "define OP_CHECKMULTISIG" in {
OP_CHECKMULTISIG.opCode must be (174)
}
it must "define OP_CHECKMULTISIGVERIFY" in {
OP_CHECKMULTISIGVERIFY.opCode must be (175)
}
}