mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-05-11 03:00:22 +02:00
a User interface that is like a Signer but can't sign.
This commit is contained in:
parent
fa17e4003f
commit
94e8b6790a
13
keyer.go
13
keyer.go
@ -15,15 +15,20 @@ type Keyer interface {
|
|||||||
Cipher
|
Cipher
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signer is an interface for signing events.
|
// User is an entity that has a public key (although they can't sign anything).
|
||||||
|
type User interface {
|
||||||
|
// GetPublicKey returns the public key associated with this user.
|
||||||
|
GetPublicKey(ctx context.Context) (string, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Signer is a User that can also sign events.
|
||||||
type Signer interface {
|
type Signer interface {
|
||||||
|
User
|
||||||
|
|
||||||
// SignEvent signs the provided event, setting its ID, PubKey, and Sig fields.
|
// SignEvent signs the provided event, setting its ID, PubKey, and Sig fields.
|
||||||
// The context can be used for operations that may require user interaction or
|
// The context can be used for operations that may require user interaction or
|
||||||
// network access, such as with remote signers.
|
// network access, such as with remote signers.
|
||||||
SignEvent(ctx context.Context, evt *Event) error
|
SignEvent(ctx context.Context, evt *Event) error
|
||||||
|
|
||||||
// GetPublicKey returns the public key associated with this signer.
|
|
||||||
GetPublicKey(ctx context.Context) (string, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cipher is an interface for encrypting and decrypting messages with NIP-44
|
// Cipher is an interface for encrypting and decrypting messages with NIP-44
|
||||||
|
@ -9,6 +9,8 @@ import (
|
|||||||
"github.com/nbd-wtf/go-nostr/nip46"
|
"github.com/nbd-wtf/go-nostr/nip46"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ nostr.Keyer = (*BunkerSigner)(nil)
|
||||||
|
|
||||||
// BunkerSigner is a signer that delegates operations to a remote bunker using NIP-46.
|
// BunkerSigner is a signer that delegates operations to a remote bunker using NIP-46.
|
||||||
// It communicates with the bunker for all cryptographic operations rather than
|
// It communicates with the bunker for all cryptographic operations rather than
|
||||||
// handling the private key locally.
|
// handling the private key locally.
|
||||||
|
@ -9,6 +9,8 @@ import (
|
|||||||
"github.com/nbd-wtf/go-nostr/nip49"
|
"github.com/nbd-wtf/go-nostr/nip49"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ nostr.Keyer = (*EncryptedKeySigner)(nil)
|
||||||
|
|
||||||
// EncryptedKeySigner is a signer that must ask the user for a password before every operation.
|
// EncryptedKeySigner is a signer that must ask the user for a password before every operation.
|
||||||
// It stores the private key in encrypted form (NIP-49) and uses a callback to request the password
|
// It stores the private key in encrypted form (NIP-49) and uses a callback to request the password
|
||||||
// when needed for operations.
|
// when needed for operations.
|
||||||
|
@ -6,6 +6,8 @@ import (
|
|||||||
"github.com/nbd-wtf/go-nostr"
|
"github.com/nbd-wtf/go-nostr"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ nostr.Keyer = (*ManualSigner)(nil)
|
||||||
|
|
||||||
// ManualSigner is a signer that delegates all operations to user-provided functions.
|
// ManualSigner is a signer that delegates all operations to user-provided functions.
|
||||||
// It can be used when an app wants to ask the user or some custom server to manually provide a
|
// It can be used when an app wants to ask the user or some custom server to manually provide a
|
||||||
// signed event or an encrypted or decrypted payload by copy-and-paste, for example, or when the
|
// signed event or an encrypted or decrypted payload by copy-and-paste, for example, or when the
|
||||||
|
@ -8,6 +8,8 @@ import (
|
|||||||
"github.com/puzpuzpuz/xsync/v3"
|
"github.com/puzpuzpuz/xsync/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ nostr.Keyer = (*KeySigner)(nil)
|
||||||
|
|
||||||
// KeySigner is a signer that holds the private key in memory
|
// KeySigner is a signer that holds the private key in memory
|
||||||
type KeySigner struct {
|
type KeySigner struct {
|
||||||
sk string
|
sk string
|
||||||
|
@ -7,7 +7,26 @@ import (
|
|||||||
"github.com/nbd-wtf/go-nostr"
|
"github.com/nbd-wtf/go-nostr"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ReadOnlySigner is a Signer that holds a public key in memory and cannot sign anything
|
var (
|
||||||
|
_ nostr.User = (*ReadOnlyUser)(nil)
|
||||||
|
_ nostr.Signer = (*ReadOnlySigner)(nil)
|
||||||
|
)
|
||||||
|
|
||||||
|
// ReadOnlyUser is a nostr.User that has this public key
|
||||||
|
type ReadOnlyUser struct {
|
||||||
|
pk string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewReadOnlyUser(pk string) ReadOnlyUser {
|
||||||
|
return ReadOnlyUser{pk}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPublicKey returns the public key associated with this signer.
|
||||||
|
func (ros ReadOnlyUser) GetPublicKey(context.Context) (string, error) {
|
||||||
|
return ros.pk, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadOnlySigner is like a ReadOnlyUser, but has a fake GetPublicKey method that doesn't work.
|
||||||
type ReadOnlySigner struct {
|
type ReadOnlySigner struct {
|
||||||
pk string
|
pk string
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user