Merge pull request #637 from cwaldron97/2019-07-16-remove-bitcoinj-dep

Remove BitcoinJ from dependencies
This commit is contained in:
Torkel Rogstad 2019-07-18 11:01:19 +02:00 committed by GitHub
commit 245a77b3db
5 changed files with 0 additions and 84 deletions

View File

@ -1,61 +1,12 @@
package org.bitcoins.core.crypto
import org.bitcoinj.core.Sha256Hash
import org.bitcoins.testkit.core.gen.CryptoGenerators
import org.bitcoins.testkit.util.BitcoinSUnitTest
import org.scalatest.prop.PropertyChecks
import org.scalatest.{FlatSpec, MustMatchers}
import scodec.bits._
class ECPublicKeyTest extends BitcoinSUnitTest {
"ECPublicKey" must "verify that a arbitrary piece of data was signed by the private key corresponding to a public key" in {
val privateKeyHex =
"180cb41c7c600be951b5d3d0a7334acc7506173875834f7a6c4c786a28fcbb19"
val key: ECPrivateKey = ECPrivateKey(privateKeyHex)
val hash = DoubleSha256Digest(ByteVector(Sha256Hash.ZERO_HASH.getBytes))
val signature: ECDigitalSignature = key.sign(hash)
val isValid: Boolean =
key.publicKey.verify(ByteVector(Sha256Hash.ZERO_HASH.getBytes), signature)
isValid must be(true)
}
it must "fail to verify a piece of data if the wrong public key is given" in {
val privateKeyHex =
"180cb41c7c600be951b5d3d0a7334acc7506173875834f7a6c4c786a28fcbb19"
val key: ECPrivateKey = ECPrivateKey(privateKeyHex)
val hash = DoubleSha256Digest(ByteVector(Sha256Hash.ZERO_HASH.getBytes))
val signature: ECDigitalSignature = key.sign(hash)
val wrongPublicKey = ECPublicKey.freshPublicKey
val isValid: Boolean = wrongPublicKey.verify(hash, signature)
isValid must be(false)
}
it must "verify a piece of data signed with a bitcoinj private key" in {
val bitcoinjPrivKey = new org.bitcoinj.core.ECKey
val bitcoinjSignature = bitcoinjPrivKey.sign(Sha256Hash.ZERO_HASH)
val bitcoinsSignature =
ECDigitalSignature(ByteVector(bitcoinjSignature.encodeToDER()))
val bitcoinsPublicKey = ECPublicKey(ByteVector(bitcoinjPrivKey.getPubKey))
bitcoinsPublicKey.verify(ByteVector(Sha256Hash.ZERO_HASH.getBytes),
bitcoinsSignature) must be(true)
}
it must "verify a piece of data was signed with a bitcoins private key inside of bitcoinj" in {
val bitcoinsPrivKey = ECPrivateKey.freshPrivateKey
val hash = DoubleSha256Digest(ByteVector(Sha256Hash.ZERO_HASH.getBytes))
val bitcoinsSignature = bitcoinsPrivKey.sign(hash)
val bitcoinjPublicKey = org.bitcoinj.core.ECKey
.fromPublicOnly(bitcoinsPrivKey.publicKey.bytes.toArray)
bitcoinjPublicKey.verify(Sha256Hash.ZERO_HASH.getBytes,
bitcoinsSignature.bytes.toArray) must be(true)
}
it must "be able to decompress keys" in {
val uncompressed =
ECPublicKey(

View File

@ -18,8 +18,6 @@ import scala.util.Try
class TransactionSignatureSerializerTest extends FlatSpec with MustMatchers {
private def logger = BitcoinSLogger.logger
val scriptPubKey =
BitcoinjConversions.toScriptPubKey(BitcoinJTestUtil.multiSigScript)
"TransactionSignatureSerializer" must "correctly serialize an input that is being checked where another input in the same tx is using SIGHASH_ANYONECANPAY" in {
//this is from a test case inside of tx_valid.json
//https://github.com/bitcoin/bitcoin/blob/master/src/test/data/tx_valid.json#L91

View File

@ -28,12 +28,6 @@ class Base58Test extends FlatSpec with MustMatchers {
Base58.decode("Z").head must be(32.toByte)
}
it must "decode and return same result as bitcoinj" in {
val address = "1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i"
val bitcoinj = org.bitcoinj.core.Base58.decode(address)
Base58.decode(address).toArray must be(bitcoinj)
}
it must "encode tests in base58_encode_decode.json" in {
Base58.encode("") must be("")
Base58.encode("61") must be("2g")
@ -69,25 +63,6 @@ class Base58Test extends FlatSpec with MustMatchers {
decodedBase58EncodeToHex("1111111111") must be("00000000000000000000")
}
it must "decode address into bytes, then encode bytes back to address the same as bitcoinj" in {
//1C4kYhyLftmkn48YarSoLupxHfYFo8kp64
val address = TestUtil.bitcoinAddress.get.value
val bitcoinj =
org.bitcoinj.core.Base58.encode(org.bitcoinj.core.Base58.decode(address))
Base58.encode(Base58.decode(address)) must be(bitcoinj)
Base58.encode(Base58.decode(address)) must be(
"1C4kYhyLftmkn48YarSoLupxHfYFo8kp64")
}
it must "decode multisig address into bytes then encode back to multisig" in {
val multi = TestUtil.multiSigAddress.get.value
val bitcoinj =
org.bitcoinj.core.Base58.encode(org.bitcoinj.core.Base58.decode(multi))
Base58.encode(Base58.decode(multi)) must be(
TestUtil.multiSigAddress.get.value)
Base58.encode(Base58.decode(multi)) must be(bitcoinj)
}
it must "read base58_keys_valid.json and validate each case" in {
import org.bitcoins.core.util.testprotocol.Base58ValidTestCaseProtocol._
val source =

View File

@ -1,6 +1,5 @@
package org.bitcoins.core.util
import org.bitcoinj.core.DumpedPrivateKey
import org.bitcoins.core.crypto.ECPrivateKey
/**
@ -9,9 +8,6 @@ import org.bitcoins.core.crypto.ECPrivateKey
trait CryptoTestUtil {
def privateKeyBase58 = "cVLwRLTvz3BxDAWkvS3yzT9pUcTCup7kQnfT2smRjvmmm1wAP6QT"
def bitcoinjDumpedPrivateKey =
new DumpedPrivateKey(BitcoinJTestUtil.params, privateKeyBase58)
def bitcoinjPrivateKey = bitcoinjDumpedPrivateKey.getKey
def privateKey = ECPrivateKey.fromWIFToPrivateKey(privateKeyBase58)
}

View File

@ -83,9 +83,6 @@ object Deps {
object Test {
val async = "org.scala-lang.modules" %% "scala-async" % V.asyncV % "test" withSources () withJavadoc ()
val bitcoinj = ("org.bitcoinj" % "bitcoinj-core" % "0.14.4" % "test")
.exclude("org.slf4j", "slf4j-api")
val junitInterface = "com.novocode" % "junit-interface" % V.junitV % "test" withSources () withJavadoc ()
val logback = Compile.logback % "test"
val scalacheck = Compile.scalacheck % "test"
@ -118,7 +115,6 @@ object Deps {
)
val coreTest = List(
Test.bitcoinj,
Test.junitInterface,
Test.logback,
Test.scalaTest,