keyer: New() to deal slightly better with hex secret keys.

This commit is contained in:
fiatjaf
2025-05-12 05:59:55 -03:00
parent 3f436d2a86
commit 9a0b263ecc

View File

@@ -2,7 +2,6 @@ package keyer
import ( import (
"context" "context"
"encoding/hex"
"fmt" "fmt"
"strings" "strings"
"time" "time"
@@ -91,12 +90,9 @@ func New(ctx context.Context, pool *nostr.Pool, input string, opts *SignerOption
sec := parsed.(nostr.SecretKey) sec := parsed.(nostr.SecretKey)
pk := nostr.GetPublicKey(sec) pk := nostr.GetPublicKey(sec)
return KeySigner{sec, pk, xsync.NewMapOf[nostr.PubKey, [32]byte]()}, nil return KeySigner{sec, pk, xsync.NewMapOf[nostr.PubKey, [32]byte]()}, nil
} else if _, err := hex.DecodeString(input); err == nil && len(input) <= 64 { } else if sk, err := nostr.SecretKeyFromHex(input); err == nil {
input := nostr.MustSecretKeyFromHex( pk := nostr.GetPublicKey(sk)
strings.Repeat("0", 64-len(input)) + input, // if the key is like '01', fill all the left zeroes return KeySigner{sk, pk, xsync.NewMapOf[nostr.PubKey, [32]byte]()}, nil
)
pk := nostr.GetPublicKey(input)
return KeySigner{input, pk, xsync.NewMapOf[nostr.PubKey, [32]byte]()}, nil
} }
return nil, fmt.Errorf("unsupported input '%s'", input) return nil, fmt.Errorf("unsupported input '%s'", input)