mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-10-10 04:44:02 +02:00
keyer: add ReadOnlySigner.
This commit is contained in:
@@ -8,8 +8,7 @@ import (
|
|||||||
"github.com/puzpuzpuz/xsync/v3"
|
"github.com/puzpuzpuz/xsync/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// KeySigner is a signer that holds the private key in memory and can perform
|
// KeySigner is a signer that holds the private key in memory
|
||||||
// all operations instantly and easily.
|
|
||||||
type KeySigner struct {
|
type KeySigner struct {
|
||||||
sk string
|
sk string
|
||||||
pk string
|
pk string
|
||||||
@@ -32,7 +31,7 @@ func NewPlainKeySigner(sec string) (KeySigner, error) {
|
|||||||
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) }
|
||||||
|
|
||||||
// GetPublicKey returns the public key associated with this signer.
|
// GetPublicKey returns the public key associated with this signer.
|
||||||
func (ks KeySigner) GetPublicKey(ctx context.Context) (string, error) { return ks.pk, nil }
|
func (ks KeySigner) GetPublicKey(ctx context.Context) (string, error) { return ks.pk, nil }
|
||||||
|
|
||||||
// Encrypt encrypts a plaintext message for a recipient using NIP-44.
|
// Encrypt encrypts a plaintext message for a recipient using NIP-44.
|
||||||
// It caches conversation keys for efficiency in repeated operations.
|
// It caches conversation keys for efficiency in repeated operations.
|
||||||
|
27
keyer/readonly.go
Normal file
27
keyer/readonly.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package keyer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/nbd-wtf/go-nostr"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ReadOnlySigner is a Signer that holds a public key in memory and cannot sign anything
|
||||||
|
type ReadOnlySigner struct {
|
||||||
|
pk string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewReadOnlySigner(pk string) ReadOnlySigner {
|
||||||
|
return ReadOnlySigner{pk}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SignEvent returns an error.
|
||||||
|
func (ros ReadOnlySigner) SignEvent(context.Context, *nostr.Event) error {
|
||||||
|
return fmt.Errorf("read-only, we don't have the secret key, cannot sign")
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPublicKey returns the public key associated with this signer.
|
||||||
|
func (ros ReadOnlySigner) GetPublicKey(context.Context) (string, error) {
|
||||||
|
return ros.pk, nil
|
||||||
|
}
|
Reference in New Issue
Block a user