diff --git a/crypt/common.go b/crypt/common.go index a89a8f7..84a371d 100644 --- a/crypt/common.go +++ b/crypt/common.go @@ -114,19 +114,10 @@ func NewPublicKey(pub tz.PublicKey) (PublicKey, error) { default: panic("unreachable") } - x, y, err := unmarshalCompressed(data, curve) - if err != nil { - return nil, err - } - return (*ECDSAPublicKey)(&ecdsa.PublicKey{ - Curve: curve, - X: x, - Y: y, - }), nil + return UnmarshalECDSAPublicKey(data, curve) case *tz.BLSPublicKey: p, err := minpk.PublicKeyFromBytes(pub[:]) - if err != nil { return nil, err } diff --git a/crypt/ecdsa.go b/crypt/ecdsa.go index 7a2bf7d..651bc67 100644 --- a/crypt/ecdsa.go +++ b/crypt/ecdsa.go @@ -74,6 +74,18 @@ func (priv *ECDSAPrivateKey) Unwrap() crypto.PrivateKey { type ECDSAPublicKey ecdsa.PublicKey +func UnmarshalECDSAPublicKey(data []byte, curve elliptic.Curve) (*ECDSAPublicKey, error) { + x, y, err := unmarshalCompressed(data, curve) + if err != nil { + return nil, err + } + return (*ECDSAPublicKey)(&ecdsa.PublicKey{ + Curve: curve, + X: x, + Y: y, + }), nil +} + func (pub *ECDSAPublicKey) Hash() PublicKeyHash { return pub.ToProtocol().Hash() }