Rename packages to represent stakes (claims || supports) #84

Merged
tiger5226 merged 2 commits from stake_supports into master 2020-11-18 21:36:20 +01:00
Showing only changes of commit 69e03da94a - Show all commits

View file

@ -4,6 +4,7 @@ import (
"crypto/elliptic" "crypto/elliptic"
"crypto/x509/pkix" "crypto/x509/pkix"
"encoding/asn1" "encoding/asn1"
"encoding/pem"
"github.com/lbryio/lbry.go/v2/extras/errors" "github.com/lbryio/lbry.go/v2/extras/errors"
@ -16,6 +17,14 @@ type publicKeyInfo struct {
PublicKey asn1.BitString PublicKey asn1.BitString
} }
//This type provides compatibility with the btcec package
type ecPrivateKey struct {
Version int
PrivateKey []byte
NamedCurveOID asn1.ObjectIdentifier `asn1:"optional,explicit,tag:0"`
PublicKey asn1.BitString `asn1:"optional,explicit,tag:1"`
}
func PublicKeyToDER(publicKey *btcec.PublicKey) ([]byte, error) { func PublicKeyToDER(publicKey *btcec.PublicKey) ([]byte, error) {
var publicKeyBytes []byte var publicKeyBytes []byte
var publicKeyAlgorithm pkix.AlgorithmIdentifier var publicKeyAlgorithm pkix.AlgorithmIdentifier
@ -47,3 +56,12 @@ func GetPublicKeyFromBytes(pubKeyBytes []byte) (*btcec.PublicKey, error) {
pubkeyBytes1 := []byte(PKInfo.PublicKey.Bytes) pubkeyBytes1 := []byte(PKInfo.PublicKey.Bytes)
return btcec.ParsePubKey(pubkeyBytes1, btcec.S256()) return btcec.ParsePubKey(pubkeyBytes1, btcec.S256())
} }
//Returns a btec.Private key object if provided a correct secp256k1 encoded pem.
func ExtractKeyFromPem(pm string) (*btcec.PrivateKey, *btcec.PublicKey) {
byta := []byte(pm)
blck, _ := pem.Decode(byta)
var ecp ecPrivateKey
asn1.Unmarshal(blck.Bytes, &ecp)
return btcec.PrivKeyFromBytes(btcec.S256(), ecp.PrivateKey)
}