nip46

package
v0.0.0-...-3d1c7b5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidBunkerURL

func IsValidBunkerURL(input string) bool

Types

type BunkerClient

type BunkerClient struct {

	// SkipSignatureCheck can be set if you don't want to double-check incoming signatures
	SkipSignatureCheck bool
	// contains filtered or unexported fields
}

func ConnectBunker

func ConnectBunker(
	ctx context.Context,
	clientSecretKey string,
	bunkerURLOrNIP05 string,
	pool *nostr.SimplePool,
	onAuth func(string),
) (*BunkerClient, error)

ConnectBunker establishes an RPC connection to a NIP-46 signer using the relays and secret provided in the bunkerURL. pool can be passed to reuse an existing pool, otherwise a new pool will be created.

func NewBunker

func NewBunker(
	ctx context.Context,
	clientSecretKey string,
	targetPublicKey string,
	relays []string,
	pool *nostr.SimplePool,
	onAuth func(string),
) *BunkerClient

func (*BunkerClient) GetPublicKey

func (bunker *BunkerClient) GetPublicKey(ctx context.Context) (string, error)

func (*BunkerClient) NIP04Decrypt

func (bunker *BunkerClient) NIP04Decrypt(
	ctx context.Context,
	targetPublicKey string,
	ciphertext string,
) (string, error)

func (*BunkerClient) NIP04Encrypt

func (bunker *BunkerClient) NIP04Encrypt(
	ctx context.Context,
	targetPublicKey string,
	plaintext string,
) (string, error)

func (*BunkerClient) NIP44Decrypt

func (bunker *BunkerClient) NIP44Decrypt(
	ctx context.Context,
	targetPublicKey string,
	ciphertext string,
) (string, error)

func (*BunkerClient) NIP44Encrypt

func (bunker *BunkerClient) NIP44Encrypt(
	ctx context.Context,
	targetPublicKey string,
	plaintext string,
) (string, error)

func (*BunkerClient) Ping

func (bunker *BunkerClient) Ping(ctx context.Context) error

func (*BunkerClient) RPC

func (bunker *BunkerClient) RPC(ctx context.Context, method string, params []string) (string, error)

func (*BunkerClient) SignEvent

func (bunker *BunkerClient) SignEvent(ctx context.Context, evt *nostr.Event) error

type DynamicSigner

type DynamicSigner struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewDynamicSigner

func NewDynamicSigner(

	getHandlerSecretKey func(handlerPubkey string) (string, error),

	getUserKeyer func(handlerPubkey string) (nostr.Keyer, error),

	authorizeSigning func(event nostr.Event, from string, secret string) bool,

	authorizeEncryption func(from string, secret string) bool,

	onEventSigned func(event nostr.Event),

	getRelays func(pubkey string) map[string]RelayReadWrite,
) DynamicSigner

func (*DynamicSigner) GetSession

func (p *DynamicSigner) GetSession(clientPubkey string) (Session, bool)

func (*DynamicSigner) HandleRequest

func (p *DynamicSigner) HandleRequest(ctx context.Context, event *nostr.Event) (
	req Request,
	resp Response,
	eventResponse nostr.Event,
	err error,
)

type RelayReadWrite

type RelayReadWrite struct {
	Read  bool `json:"read"`
	Write bool `json:"write"`
}

type Request

type Request struct {
	ID     string   `json:"id"`
	Method string   `json:"method"`
	Params []string `json:"params"`
}

func (Request) String

func (r Request) String() string

type Response

type Response struct {
	ID     string `json:"id"`
	Error  string `json:"error,omitempty"`
	Result string `json:"result,omitempty"`
}

func (Response) String

func (r Response) String() string

type Session

type Session struct {
	PublicKey       string
	SharedKey       []byte   // nip04
	ConversationKey [32]byte // nip44
}

func (Session) MakeResponse

func (s Session) MakeResponse(
	id string,
	requester string,
	result string,
	err error,
) (resp Response, evt nostr.Event, error error)

func (Session) ParseRequest

func (s Session) ParseRequest(event *nostr.Event) (Request, error)

type Signer

type Signer interface {
	GetSession(clientPubkey string) (Session, bool)
	HandleRequest(context.Context, *nostr.Event) (req Request, resp Response, eventResponse nostr.Event, err error)
}

type StaticKeySigner

type StaticKeySigner struct {
	sync.Mutex

	RelaysToAdvertise map[string]RelayReadWrite
	AuthorizeRequest  func(harmless bool, from string, secret string) bool
	// contains filtered or unexported fields
}

func NewStaticKeySigner

func NewStaticKeySigner(secretKey string) StaticKeySigner

func (*StaticKeySigner) GetSession

func (p *StaticKeySigner) GetSession(clientPubkey string) (Session, bool)

func (*StaticKeySigner) HandleRequest

func (p *StaticKeySigner) HandleRequest(_ context.Context, event *nostr.Event) (
	req Request,
	resp Response,
	eventResponse nostr.Event,
	err error,
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL