From 588e415440bcdc00a8afe5f2107aaf47e7bbd12e Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Fri, 24 Oct 2025 00:12:25 -0300 Subject: [PATCH] small fixes in hex parsing. --- keys.go | 10 +++++++--- types.go | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/keys.go b/keys.go index e16abbe..3256116 100644 --- a/keys.go +++ b/keys.go @@ -50,7 +50,9 @@ func SecretKeyFromHex(skh string) (SecretKey, error) { func MustSecretKeyFromHex(idh string) SecretKey { id := SecretKey{} - hex.Decode(id[:], unsafe.Slice(unsafe.StringData(idh), 64)) + if _, err := hex.Decode(id[:], unsafe.Slice(unsafe.StringData(idh), 64)); err != nil { + panic(err) + } return id } @@ -77,11 +79,13 @@ func (pk *PubKey) UnmarshalJSON(buf []byte) error { if len(buf) != 66 { return fmt.Errorf("must be a hex string of 64 characters") } - _, err := hex.Decode(pk[:], buf[1:65]) + if _, err := hex.Decode(pk[:], buf[1:65]); err != nil { + return err + } if _, err := schnorr.ParsePubKey(pk[:]); err != nil { return fmt.Errorf("pubkey is not valid %w", err) } - return err + return nil } func PubKeyFromHex(pkh string) (PubKey, error) { diff --git a/types.go b/types.go index 62985c6..05befc2 100644 --- a/types.go +++ b/types.go @@ -51,7 +51,9 @@ func IDFromHex(idh string) (ID, error) { func MustIDFromHex(idh string) ID { id := ID{} - hex.Decode(id[:], unsafe.Slice(unsafe.StringData(idh), 64)) + if _, err := hex.Decode(id[:], unsafe.Slice(unsafe.StringData(idh), 64)); err != nil { + panic(err) + } return id }