Skip to content

Commit

Permalink
Added a test case and error case
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Sep 30, 2020
1 parent 868b8f2 commit bf1cd57
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions private_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ package bitcoin
import (
"crypto/ecdsa"
"encoding/hex"
"errors"
"math/big"

"github.com/bitcoinsv/bsvd/bsvec"
)

// PrivateKeyFromString turns a private key (hex encoded string) into an bsvec.PrivateKey
func PrivateKeyFromString(privateKey string) (*bsvec.PrivateKey, error) {
if len(privateKey) == 0 {
return nil, errors.New("privateKey is missing")
}
privateKeyBytes, err := hex.DecodeString(privateKey)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions private_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func TestPrivateKeyFromString(t *testing.T) {
{"E83385AF76B2B1997326B567461FB73DD9C27EAB9E1E86D26779F", "", true, true},
{"1234567", "", true, true},
{"0", "", true, true},
{"", "", true, true},
}

// Run tests
Expand Down

0 comments on commit bf1cd57

Please sign in to comment.