2024-10-14 16:25:24 -03:00
|
|
|
package nostr
|
|
|
|
|
2025-03-04 11:08:31 -03:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
2024-10-14 16:25:24 -03:00
|
|
|
|
2025-03-04 11:08:31 -03:00
|
|
|
// Keyer is an interface for signing events and performing cryptographic operations.
|
|
|
|
// It abstracts away the details of key management, allowing for different implementations
|
|
|
|
// such as in-memory keys, hardware wallets, or remote signing services (bunker).
|
2024-10-14 16:25:24 -03:00
|
|
|
type Keyer interface {
|
2025-03-04 11:08:31 -03:00
|
|
|
// Signer provides event signing capabilities
|
2024-10-14 16:25:24 -03:00
|
|
|
Signer
|
2025-03-04 11:08:31 -03:00
|
|
|
|
|
|
|
// Cipher provides encryption and decryption capabilities (NIP-44)
|
2024-10-14 16:25:24 -03:00
|
|
|
Cipher
|
|
|
|
}
|
|
|
|
|
2025-03-10 02:25:57 -03:00
|
|
|
// 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.
|
2024-10-14 16:25:24 -03:00
|
|
|
type Signer interface {
|
2025-03-10 02:25:57 -03:00
|
|
|
User
|
|
|
|
|
2025-03-04 11:08:31 -03:00
|
|
|
// 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
|
|
|
|
// network access, such as with remote signers.
|
|
|
|
SignEvent(ctx context.Context, evt *Event) error
|
2024-10-14 16:25:24 -03:00
|
|
|
}
|
|
|
|
|
2025-03-04 11:08:31 -03:00
|
|
|
// Cipher is an interface for encrypting and decrypting messages with NIP-44
|
2024-10-14 16:25:24 -03:00
|
|
|
type Cipher interface {
|
2025-03-04 11:08:31 -03:00
|
|
|
// Encrypt encrypts a plaintext message for a recipient.
|
|
|
|
// Returns the encrypted message as a base64-encoded string.
|
2024-10-14 16:25:24 -03:00
|
|
|
Encrypt(ctx context.Context, plaintext string, recipientPublicKey string) (base64ciphertext string, err error)
|
2025-03-04 11:08:31 -03:00
|
|
|
|
|
|
|
// Decrypt decrypts a base64-encoded ciphertext from a sender.
|
|
|
|
// Returns the decrypted plaintext.
|
2024-10-14 16:25:24 -03:00
|
|
|
Decrypt(ctx context.Context, base64ciphertext string, senderPublicKey string) (plaintext string, err error)
|
|
|
|
}
|