Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update btcec to v2.3.4 #77

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions coins/avax/avax.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"crypto/sha256"
"encoding/hex"
"errors"
"strings"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/btcutil/bech32"
"github.com/okx/go-wallet-sdk/crypto/base58"
"strings"
)

func NewAddress(chainId string, hrp string, publicKey *btcec.PublicKey) (string, error) {
Expand Down Expand Up @@ -67,10 +68,7 @@ func NewTransferTransaction(netWorkId uint32, blockchainId string, inputs *[]Tra
return "", err
}
privateKey, _ := btcec.PrivKeyFromBytes(pk)
sig2, err := ecdsa.SignCompact(privateKey, hash[:], false)
if err != nil {
return "", err
}
sig2 := ecdsa.SignCompact(privateKey, hash[:], false)
sig := make([]byte, len(sig2))
copy(sig, sig2[1:])
sig[64] = sig2[0] - 27
Expand Down
4 changes: 2 additions & 2 deletions coins/avax/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/okx/go-wallet-sdk/coins/avax
go 1.19

require (
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/btcsuite/btcd/btcec/v2 v2.3.4
github.com/btcsuite/btcd/btcutil v1.1.3
github.com/okx/go-wallet-sdk/crypto v0.0.1
github.com/stretchr/testify v1.8.4
Expand All @@ -14,7 +14,7 @@ require (
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
github.com/btcsuite/btcutil v1.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/sys v0.11.0 // indirect
Expand Down
6 changes: 3 additions & 3 deletions coins/bitcoin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
github.com/btcsuite/btcd v0.23.4
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/btcsuite/btcd/btcec/v2 v2.3.4
github.com/btcsuite/btcd/btcutil v1.1.3
github.com/btcsuite/btcd/btcutil/psbt v1.1.8
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2
Expand All @@ -22,8 +22,8 @@ require (
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/crate-crypto/go-kzg-4844 v0.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/ethereum/c-kzg-4844 v0.3.1 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
Expand Down
9 changes: 5 additions & 4 deletions coins/bitcoin/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"encoding/hex"
"errors"
"fmt"
"io"
"math/big"
"reflect"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
Expand All @@ -17,9 +21,6 @@ import (
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/okx/go-wallet-sdk/crypto"
"io"
"math/big"
"reflect"
)

const (
Expand Down Expand Up @@ -534,7 +535,7 @@ func SignMessage(wif string, prefix, message string) (string, error) {
if err != nil {
return "", err
}
sig, err := ecdsa.SignCompact(w.PrivKey, messageHash, true)
sig := ecdsa.SignCompact(w.PrivKey, messageHash, true)
if err != nil {
return "", err
}
Expand Down
8 changes: 3 additions & 5 deletions coins/cosmos/atom/atom.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"math/big"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/btcutil/bech32"
"github.com/okx/go-wallet-sdk/coins/cosmos/tx"
"github.com/okx/go-wallet-sdk/coins/cosmos/types"
"math/big"
)

const (
Expand Down Expand Up @@ -89,10 +90,7 @@ func Sign(rawHex string, privateKey *btcec.PrivateKey) (string, error) {
return "", err
}
hash := sha256.Sum256(signDocBytes)
signature, err := ecdsa.SignCompact(privateKey, hash[:], false)
if err != nil {
return "", err
}
signature := ecdsa.SignCompact(privateKey, hash[:], false)
return hex.EncodeToString(signature[1:]), nil
}

Expand Down
49 changes: 12 additions & 37 deletions coins/cosmos/cosmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"encoding/json"
"errors"
"fmt"
"math/big"
"sort"
"strconv"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/btcsuite/btcd/btcutil"
Expand All @@ -17,9 +21,6 @@ import (
"github.com/okx/go-wallet-sdk/coins/cosmos/types/ethsecp256k1"
"github.com/okx/go-wallet-sdk/coins/cosmos/types/ibc"
"golang.org/x/crypto/sha3"
"math/big"
"sort"
"strconv"
)

const (
Expand Down Expand Up @@ -259,10 +260,7 @@ func SignRawTransaction(signDoc string, privateKey *btcec.PrivateKey) (string, e
return "", err
}
hash := sha256.Sum256(signDocBtyes)
signature, err := ecdsa.SignCompact(privateKey, hash[:], false)
if err != nil {
return "", err
}
signature := ecdsa.SignCompact(privateKey, hash[:], false)
return hex.EncodeToString(signature[1:]), nil
}

Expand Down Expand Up @@ -400,10 +398,7 @@ func BuildTxAction(param CommonParam, messages []*types.Any, privateKeyHex strin
var signBytes []byte
if useEthSecp256k1 {
m := HashMessage(signDocBtyes)
result, err := ecdsa.SignCompact(privateKey, m, false)
if err != nil {
return "", err
}
result := ecdsa.SignCompact(privateKey, m, false)
V := result[0]
R := result[1:33]
S := result[33:65]
Expand All @@ -413,11 +408,7 @@ func BuildTxAction(param CommonParam, messages []*types.Any, privateKeyHex strin
signBytes = append(signBytes, V-27)
} else {
hash := sha256.Sum256(signDocBtyes)
var err error
signBytes, err = ecdsa.SignCompact(privateKey, hash[:], false)
if err != nil {
return "", err
}
signBytes = ecdsa.SignCompact(privateKey, hash[:], false)
signBytes = signBytes[1:]
}

Expand Down Expand Up @@ -471,10 +462,7 @@ func BuildTxActionForSignMessage(param CommonParam, messages []*types.Any, priva
var signBytes []byte
if useEthSecp256k1 {
m := HashMessage(signDocBtyes)
result, err := ecdsa.SignCompact(privateKey, m, false)
if err != nil {
return "", "", err
}
result := ecdsa.SignCompact(privateKey, m, false)
V := result[0]
R := result[1:33]
S := result[33:65]
Expand All @@ -484,11 +472,7 @@ func BuildTxActionForSignMessage(param CommonParam, messages []*types.Any, priva
signBytes = append(signBytes, V-27)
} else {
hash := sha256.Sum256(signDocBtyes)
var err error
signBytes, err = ecdsa.SignCompact(privateKey, hash[:], false)
if err != nil {
return "", "", err
}
signBytes = ecdsa.SignCompact(privateKey, hash[:], false)
signBytes = signBytes[1:]
}

Expand Down Expand Up @@ -544,10 +528,7 @@ func SignDoc(body string, auth string, privateKeyHex string, ChainId string, Acc

var signBytes []byte
hash := sha256.Sum256(signDocBtyes)
signature, err := ecdsa.SignCompact(privateKey, hash[:], false)
if err != nil {
return "", "", err
}
signature := ecdsa.SignCompact(privateKey, hash[:], false)
signBytes = signature[1:]

signatures := make([][]byte, 0)
Expand Down Expand Up @@ -601,10 +582,7 @@ func SignAminoMessage(data string, privateKeyHex string) (string, error) {
}

privateKey, _ := btcec.PrivKeyFromBytes(pkBytes)
signature, err := ecdsa.SignCompact(privateKey, hash[:], false)
if err != nil {
return "", err
}
signature := ecdsa.SignCompact(privateKey, hash[:], false)
return base64.StdEncoding.EncodeToString(signature[1:]), nil
}

Expand Down Expand Up @@ -836,9 +814,6 @@ func GetSigningHash(rawTxByte string) (string, error) {
}
func SignRawJsonTransaction(signDoc string, privateKey *btcec.PrivateKey) (string, error) {
hash := sha256.Sum256([]byte(signDoc))
signature, err := ecdsa.SignCompact(privateKey, hash[:], false)
if err != nil {
return "", err
}
signature := ecdsa.SignCompact(privateKey, hash[:], false)
return hex.EncodeToString(signature[1:]), nil
}
4 changes: 2 additions & 2 deletions coins/cosmos/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
cosmossdk.io/math v1.1.2
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/btcsuite/btcd/btcec/v2 v2.3.4
github.com/btcsuite/btcd/btcutil v1.1.3
github.com/ethereum/go-ethereum v1.12.2
github.com/okx/go-wallet-sdk/crypto v0.0.1
Expand All @@ -19,7 +19,7 @@ require (
github.com/btcsuite/btcd v0.23.0 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
golang.org/x/exp v0.0.0-20230810033253-352e893a4cad // indirect
Expand Down
6 changes: 2 additions & 4 deletions coins/cosmos/okc/tx/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/base64"
"encoding/hex"
"errors"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/okx/go-wallet-sdk/coins/cosmos/okc/tx/amino"
Expand All @@ -30,10 +31,7 @@ func MakeSignature(privateKeyHex string, msg authtypes.StdSignMsg) (sig authtype
}
ecPriv, ecPub := btcec.PrivKeyFromBytes(pkBytes)

result, err := ecdsa.SignCompact(ecPriv, m, false)
if err != nil {
return
}
result := ecdsa.SignCompact(ecPriv, m, false)

V := result[0]
R := result[1:33]
Expand Down
8 changes: 3 additions & 5 deletions coins/cosmos/terra/terra.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"math/big"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/btcsuite/btcd/btcutil/bech32"
"github.com/okx/go-wallet-sdk/coins/cosmos/tx"
"github.com/okx/go-wallet-sdk/coins/cosmos/types"
"golang.org/x/crypto/ripemd160"
"math/big"
)

type TransactionInput struct {
Expand Down Expand Up @@ -176,10 +177,7 @@ func Sign(rawHex string, privateKeyHex string) string {

signDocBtyes, _ := hex.DecodeString(rawHex)
hash := sha256.Sum256(signDocBtyes)
b, err := ecdsa.SignCompact(privateKey, hash[:], false)
if err != nil {
return ""
}
b := ecdsa.SignCompact(privateKey, hash[:], false)
return hex.EncodeToString(b[1:])
}

Expand Down
8 changes: 3 additions & 5 deletions coins/ethereum/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/btcsuite/btcd/btcec/v2"
"math/big"

"github.com/btcsuite/btcd/btcec/v2"

"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/ethereum/go-ethereum/rlp"
"github.com/okx/go-wallet-sdk/crypto"
Expand Down Expand Up @@ -174,10 +175,7 @@ func NewTransactionFromRaw(raw string) (*EthTransaction, error) {
}

func SignAsRecoverable(value []byte, prvKey *btcec.PrivateKey) (*SignatureData, error) {
sig, err := ecdsa.SignCompact(prvKey, value, false)
if err != nil {
return nil, err
}
sig := ecdsa.SignCompact(prvKey, value, false)
V := sig[0]
R := sig[1:33]
S := sig[33:65]
Expand Down
4 changes: 2 additions & 2 deletions coins/ethereum/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/okx/go-wallet-sdk/coins/ethereum
go 1.19

require (
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/btcsuite/btcd/btcec/v2 v2.3.4
github.com/ethereum/go-ethereum v1.12.2
github.com/okx/go-wallet-sdk/crypto v0.0.1
github.com/okx/go-wallet-sdk/util v0.0.1
Expand All @@ -13,7 +13,7 @@ require (

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
12 changes: 5 additions & 7 deletions coins/filecoin/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import (
"encoding/hex"
"errors"
"fmt"
"math/bits"
"strconv"
"strings"

"github.com/btcsuite/btcd/btcec/v2"
ecdsa2 "github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/dchest/blake2b"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
"github.com/okx/go-wallet-sdk/util"
"math/bits"
"strconv"
"strings"
)

var (
Expand Down Expand Up @@ -163,10 +164,7 @@ func SignTx(message *Message, privateKeyHex string) (*SignedMessage, error) {
}
privateKey, _ := btcec.PrivKeyFromBytes(privKeyBytes)

sig, err := ecdsa2.SignCompact(privateKey, message.Hash(), false)
if err != nil {
return nil, err
}
sig := ecdsa2.SignCompact(privateKey, message.Hash(), false)
V := sig[0]
R := sig[1:33]
S := sig[33:65]
Expand Down
4 changes: 2 additions & 2 deletions coins/filecoin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/okx/go-wallet-sdk/coins/filecoin
go 1.19

require (
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/btcsuite/btcd/btcec/v2 v2.3.4
github.com/dchest/blake2b v1.0.0
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
github.com/fxamacker/cbor v1.5.1
github.com/okx/go-wallet-sdk/util v0.0.1
github.com/stretchr/testify v1.8.4
Expand Down
Loading