From 9db9e0de1dbae948023308b6ea33b2af8178a206 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 18 Nov 2021 18:43:53 -0800 Subject: [PATCH] multi: switch project over to using btcec/v2 --- blockchain/compress.go | 2 +- blockchain/fullblocktests/generate.go | 2 +- btcec/example_test.go | 94 ++------------------------- go.mod | 5 +- integration/csv_fork_test.go | 3 +- integration/rpctest/memwallet.go | 2 +- mempool/mempool_test.go | 2 +- mempool/policy_test.go | 2 +- rpcserver.go | 2 +- txscript/engine.go | 2 +- txscript/example_test.go | 2 +- txscript/opcode.go | 2 +- txscript/pkscript.go | 2 +- txscript/sigcache.go | 2 +- txscript/sigcache_test.go | 2 +- txscript/sign.go | 2 +- txscript/sign_test.go | 2 +- 17 files changed, 25 insertions(+), 105 deletions(-) diff --git a/blockchain/compress.go b/blockchain/compress.go index 611b9f09923..977a971e045 100644 --- a/blockchain/compress.go +++ b/blockchain/compress.go @@ -5,7 +5,7 @@ package blockchain import ( - "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/txscript" ) diff --git a/blockchain/fullblocktests/generate.go b/blockchain/fullblocktests/generate.go index 82d3a036e9d..595bc39282a 100644 --- a/blockchain/fullblocktests/generate.go +++ b/blockchain/fullblocktests/generate.go @@ -19,7 +19,7 @@ import ( "time" "github.com/btcsuite/btcd/blockchain" - "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/txscript" diff --git a/btcec/example_test.go b/btcec/example_test.go index ca51ee87cc4..b73f102c325 100644 --- a/btcec/example_test.go +++ b/btcec/example_test.go @@ -8,7 +8,7 @@ import ( "encoding/hex" "fmt" - "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/chaincfg/chainhash" ) @@ -22,16 +22,12 @@ func Example_signMessage() { fmt.Println(err) return } - privKey, pubKey := btcec.PrivKeyFromBytes(btcec.S256(), pkBytes) + privKey, pubKey := btcec.PrivKeyFromBytes(pkBytes) // Sign a message using the private key. message := "test message" messageHash := chainhash.DoubleHashB([]byte(message)) - signature, err := privKey.Sign(messageHash) - if err != nil { - fmt.Println(err) - return - } + signature := btcec.Sign(privKey, messageHash) // Serialize and display the signature. fmt.Printf("Serialized Signature: %x\n", signature.Serialize()) @@ -56,7 +52,7 @@ func Example_verifySignature() { fmt.Println(err) return } - pubKey, err := btcec.ParsePubKey(pubKeyBytes, btcec.S256()) + pubKey, err := btcec.ParsePubKey(pubKeyBytes) if err != nil { fmt.Println(err) return @@ -71,7 +67,7 @@ func Example_verifySignature() { fmt.Println(err) return } - signature, err := btcec.ParseSignature(sigBytes, btcec.S256()) + signature, err := btcec.ParseSignature(sigBytes) if err != nil { fmt.Println(err) return @@ -86,83 +82,3 @@ func Example_verifySignature() { // Output: // Signature Verified? true } - -// This example demonstrates encrypting a message for a public key that is first -// parsed from raw bytes, then decrypting it using the corresponding private key. -func Example_encryptMessage() { - // Decode the hex-encoded pubkey of the recipient. - pubKeyBytes, err := hex.DecodeString("04115c42e757b2efb7671c578530ec191a1" + - "359381e6a71127a9d37c486fd30dae57e76dc58f693bd7e7010358ce6b165e483a29" + - "21010db67ac11b1b51b651953d2") // uncompressed pubkey - if err != nil { - fmt.Println(err) - return - } - pubKey, err := btcec.ParsePubKey(pubKeyBytes, btcec.S256()) - if err != nil { - fmt.Println(err) - return - } - - // Encrypt a message decryptable by the private key corresponding to pubKey - message := "test message" - ciphertext, err := btcec.Encrypt(pubKey, []byte(message)) - if err != nil { - fmt.Println(err) - return - } - - // Decode the hex-encoded private key. - pkBytes, err := hex.DecodeString("a11b0a4e1a132305652ee7a8eb7848f6ad" + - "5ea381e3ce20a2c086a2e388230811") - if err != nil { - fmt.Println(err) - return - } - // note that we already have corresponding pubKey - privKey, _ := btcec.PrivKeyFromBytes(btcec.S256(), pkBytes) - - // Try decrypting and verify if it's the same message. - plaintext, err := btcec.Decrypt(privKey, ciphertext) - if err != nil { - fmt.Println(err) - return - } - - fmt.Println(string(plaintext)) - - // Output: - // test message -} - -// This example demonstrates decrypting a message using a private key that is -// first parsed from raw bytes. -func Example_decryptMessage() { - // Decode the hex-encoded private key. - pkBytes, err := hex.DecodeString("a11b0a4e1a132305652ee7a8eb7848f6ad" + - "5ea381e3ce20a2c086a2e388230811") - if err != nil { - fmt.Println(err) - return - } - - privKey, _ := btcec.PrivKeyFromBytes(btcec.S256(), pkBytes) - - ciphertext, err := hex.DecodeString("35f644fbfb208bc71e57684c3c8b437402ca" + - "002047a2f1b38aa1a8f1d5121778378414f708fe13ebf7b4a7bb74407288c1958969" + - "00207cf4ac6057406e40f79961c973309a892732ae7a74ee96cd89823913b8b8d650" + - "a44166dc61ea1c419d47077b748a9c06b8d57af72deb2819d98a9d503efc59fc8307" + - "d14174f8b83354fac3ff56075162") - - // Try decrypting the message. - plaintext, err := btcec.Decrypt(privKey, ciphertext) - if err != nil { - fmt.Println(err) - return - } - - fmt.Println(string(plaintext)) - - // Output: - // test message -} diff --git a/go.mod b/go.mod index 7722564f57a..6e0bc3ff2ce 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,7 @@ module github.com/btcsuite/btcd require ( + github.com/btcsuite/btcec/v2 v2.0.0 github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd @@ -14,4 +15,6 @@ require ( golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 ) -go 1.16 +replace github.com/btcsuite/btcec/v2 => ./btcec + +go 1.17 diff --git a/integration/csv_fork_test.go b/integration/csv_fork_test.go index 31466349669..6750fd090f0 100644 --- a/integration/csv_fork_test.go +++ b/integration/csv_fork_test.go @@ -3,6 +3,7 @@ // license that can be found in the LICENSE file. // This file is ignored during the regular tests due to the following build tag. +//go:build rpctest // +build rpctest package integration @@ -15,7 +16,7 @@ import ( "time" "github.com/btcsuite/btcd/blockchain" - "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/integration/rpctest" diff --git a/integration/rpctest/memwallet.go b/integration/rpctest/memwallet.go index 59b0ef4c08a..76b4aa6045c 100644 --- a/integration/rpctest/memwallet.go +++ b/integration/rpctest/memwallet.go @@ -11,7 +11,7 @@ import ( "sync" "github.com/btcsuite/btcd/blockchain" - "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/rpcclient" diff --git a/mempool/mempool_test.go b/mempool/mempool_test.go index 96d50544176..a401155d03a 100644 --- a/mempool/mempool_test.go +++ b/mempool/mempool_test.go @@ -13,7 +13,7 @@ import ( "time" "github.com/btcsuite/btcd/blockchain" - "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/txscript" diff --git a/mempool/policy_test.go b/mempool/policy_test.go index b9cdbac47aa..b7cfba86ace 100644 --- a/mempool/policy_test.go +++ b/mempool/policy_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/txscript" diff --git a/rpcserver.go b/rpcserver.go index d184072942f..d0556bec874 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -29,7 +29,7 @@ import ( "github.com/btcsuite/btcd/blockchain" "github.com/btcsuite/btcd/blockchain/indexers" - "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" diff --git a/txscript/engine.go b/txscript/engine.go index 0814e7eb961..1550579d289 100644 --- a/txscript/engine.go +++ b/txscript/engine.go @@ -12,7 +12,7 @@ import ( "math/big" "strings" - "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/wire" ) diff --git a/txscript/example_test.go b/txscript/example_test.go index 6e17341c4a6..817b3273c68 100644 --- a/txscript/example_test.go +++ b/txscript/example_test.go @@ -9,7 +9,7 @@ import ( "encoding/hex" "fmt" - "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/txscript" diff --git a/txscript/opcode.go b/txscript/opcode.go index 4c31be3f75f..fa62a927ec6 100644 --- a/txscript/opcode.go +++ b/txscript/opcode.go @@ -15,7 +15,7 @@ import ( "golang.org/x/crypto/ripemd160" - "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" ) diff --git a/txscript/pkscript.go b/txscript/pkscript.go index f5b11e6d531..bee83127657 100644 --- a/txscript/pkscript.go +++ b/txscript/pkscript.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" diff --git a/txscript/sigcache.go b/txscript/sigcache.go index d9e4fa6ce10..959240c04da 100644 --- a/txscript/sigcache.go +++ b/txscript/sigcache.go @@ -7,7 +7,7 @@ package txscript import ( "sync" - "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/chaincfg/chainhash" ) diff --git a/txscript/sigcache_test.go b/txscript/sigcache_test.go index 5413ea3b2c2..e31e49a4500 100644 --- a/txscript/sigcache_test.go +++ b/txscript/sigcache_test.go @@ -8,7 +8,7 @@ import ( "crypto/rand" "testing" - "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/chaincfg/chainhash" ) diff --git a/txscript/sign.go b/txscript/sign.go index 138e31cdd4d..4358c311775 100644 --- a/txscript/sign.go +++ b/txscript/sign.go @@ -8,7 +8,7 @@ import ( "errors" "fmt" - "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" diff --git a/txscript/sign_test.go b/txscript/sign_test.go index b97a8a64d42..316b0667727 100644 --- a/txscript/sign_test.go +++ b/txscript/sign_test.go @@ -9,7 +9,7 @@ import ( "fmt" "testing" - "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire"