mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-10-09 20:33:27 +02:00
keyer: fix KeySigner and add a method for making one from scratch.
This commit is contained in:
@@ -83,7 +83,7 @@ func New(ctx context.Context, pool *nostr.SimplePool, input string, opts *Signer
|
|||||||
sec := parsed.(string)
|
sec := parsed.(string)
|
||||||
pk, _ := nostr.GetPublicKey(sec)
|
pk, _ := nostr.GetPublicKey(sec)
|
||||||
return KeySigner{sec, pk, xsync.NewMapOf[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 {
|
} 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
|
input = strings.Repeat("0", 64-len(input)) + input // if the key is like '01', fill all the left zeroes
|
||||||
pk, _ := nostr.GetPublicKey(input)
|
pk, _ := nostr.GetPublicKey(input)
|
||||||
return KeySigner{input, pk, xsync.NewMapOf[string, [32]byte]()}, nil
|
return KeySigner{input, pk, xsync.NewMapOf[string, [32]byte]()}, nil
|
||||||
|
@@ -16,6 +16,11 @@ type KeySigner struct {
|
|||||||
conversationKeys *xsync.MapOf[string, [32]byte]
|
conversationKeys *xsync.MapOf[string, [32]byte]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewPlainKeySigner(sec string) KeySigner {
|
||||||
|
pk, _ := nostr.GetPublicKey(sec)
|
||||||
|
return KeySigner{sec, pk, xsync.NewMapOf[string, [32]byte]()}
|
||||||
|
}
|
||||||
|
|
||||||
func (ks KeySigner) SignEvent(ctx context.Context, evt *nostr.Event) error { return evt.Sign(ks.sk) }
|
func (ks KeySigner) SignEvent(ctx context.Context, evt *nostr.Event) error { return evt.Sign(ks.sk) }
|
||||||
func (ks KeySigner) GetPublicKey(ctx context.Context) string { return ks.pk }
|
func (ks KeySigner) GetPublicKey(ctx context.Context) string { return ks.pk }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user