1 package nostr
2 3 import (
4 "context"
5 )
6 7 // Keyer is an interface for signing events and performing cryptographic operations.
8 // It abstracts away the details of key management, allowing for different implementations
9 // such as in-memory keys, hardware wallets, or remote signing services (bunker).
10 type Keyer interface {
11 // Signer provides event signing capabilities
12 Signer
13 14 // Cipher provides encryption and decryption capabilities (NIP-44)
15 Cipher
16 }
17 18 // User is an entity that has a public key (although they can't sign anything).
19 type User interface {
20 // GetPublicKey returns the public key associated with this user.
21 GetPublicKey(ctx context.Context) (string, error)
22 }
23 24 // Signer is a User that can also sign events.
25 type Signer interface {
26 User
27 28 // SignEvent signs the provided event, setting its ID, PubKey, and Sig fields.
29 // The context can be used for operations that may require user interaction or
30 // network access, such as with remote signers.
31 SignEvent(ctx context.Context, evt *Event) error
32 }
33 34 // Cipher is an interface for encrypting and decrypting messages with NIP-44
35 type Cipher interface {
36 // Encrypt encrypts a plaintext message for a recipient.
37 // Returns the encrypted message as a base64-encoded string.
38 Encrypt(ctx context.Context, plaintext string, recipientPublicKey string) (base64ciphertext string, err error)
39 40 // Decrypt decrypts a base64-encoded ciphertext from a sender.
41 // Returns the decrypted plaintext.
42 Decrypt(ctx context.Context, base64ciphertext string, senderPublicKey string) (plaintext string, err error)
43 }
44