Skip to content

Commit

Permalink
UnmarshalECDSAPublicKey func
Browse files Browse the repository at this point in the history
  • Loading branch information
e-asphyx committed Jan 23, 2025
1 parent 94c7ae3 commit 22d7e23
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
11 changes: 1 addition & 10 deletions crypt/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions crypt/ecdsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 22d7e23

Please sign in to comment.