From fa1da2cb917cf4dfccbe49d44c5741eec0e0bb65 Mon Sep 17 00:00:00 2001 From: Anastasia Prasolova Date: Wed, 5 Dec 2018 22:04:31 +0300 Subject: [PATCH] Function to get private key from ASN.1 serialized structure (#109) * func to get privkey from raw bytes * comments fix * review fixes; version * version --- VERSION | 2 +- pkg/wallet/private_key.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index cbb488ee2..00de776e1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.45.12 +0.45.14 diff --git a/pkg/wallet/private_key.go b/pkg/wallet/private_key.go index 42ba4e483..ff05bb8e6 100644 --- a/pkg/wallet/private_key.go +++ b/pkg/wallet/private_key.go @@ -6,6 +6,7 @@ import ( "crypto/elliptic" "crypto/rand" "crypto/sha256" + "crypto/x509" "encoding/hex" "errors" "fmt" @@ -57,6 +58,15 @@ func NewPrivateKeyFromBytes(b []byte) (*PrivateKey, error) { return &PrivateKey{b}, nil } +// NewPrivateKeyFromRawBytes returns a NEO PrivateKey from the ASN.1 serialized keys. +func NewPrivateKeyFromRawBytes(b []byte) (*PrivateKey, error) { + privkey, err := x509.ParseECPrivateKey(b) + if err != nil { + return nil, err + } + return NewPrivateKeyFromBytes(privkey.D.Bytes()) +} + // PublicKey derives the public key from the private key. func (p *PrivateKey) PublicKey() ([]byte, error) { var (