keyer, nip17, nip44, nip59: this time is different!

This commit is contained in:
fiatjaf
2024-09-15 11:06:42 -03:00
parent f976296e01
commit db023e12e9
5 changed files with 67 additions and 55 deletions

View File

@@ -12,6 +12,7 @@ import (
"github.com/nbd-wtf/go-nostr/nip19"
"github.com/nbd-wtf/go-nostr/nip46"
"github.com/nbd-wtf/go-nostr/nip49"
"github.com/puzpuzpuz/xsync/v3"
)
type Keyer interface {
@@ -61,7 +62,7 @@ func New(ctx context.Context, pool *nostr.SimplePool, input string, opts *Signer
return nil, fmt.Errorf("failed to decrypt with given password: %w", err)
}
pk, _ := nostr.GetPublicKey(sec)
return KeySigner{sec, pk, make(map[string][32]byte)}, nil
return KeySigner{sec, pk, xsync.NewMapOf[string, [32]byte]()}, nil
} else if nip46.IsValidBunkerURL(input) || nip05.IsValidIdentifier(input) {
bcsk := nostr.GeneratePrivateKey()
oa := func(url string) { println("auth_url received but not handled") }
@@ -81,11 +82,11 @@ func New(ctx context.Context, pool *nostr.SimplePool, input string, opts *Signer
} else if prefix, parsed, err := nip19.Decode(input); err == nil && prefix == "nsec" {
sec := parsed.(string)
pk, _ := nostr.GetPublicKey(sec)
return KeySigner{sec, pk, make(map[string][32]byte)}, nil
return KeySigner{sec, pk, xsync.NewMapOf[string, [32]byte]()}, nil
} else if _, err := hex.DecodeString(input); err == nil && len(input) < 64 {
input = strings.Repeat("0", 64-len(input)) + input // if the key is like '01', fill all the left zeroes
pk, _ := nostr.GetPublicKey(input)
return KeySigner{input, pk, make(map[string][32]byte)}, nil
return KeySigner{input, pk, xsync.NewMapOf[string, [32]byte]()}, nil
}
return nil, fmt.Errorf("unsupported input '%s'", input)