nip46

package
v0.47.2 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: MIT Imports: 16 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidBunkerURL added in v0.29.0

func IsValidBunkerURL(input string) bool

Types

type BunkerClient added in v0.28.4

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 added in v0.28.4

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 added in v0.29.0

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

func (*BunkerClient) GetPublicKey added in v0.28.4

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

func (*BunkerClient) NIP04Decrypt added in v0.36.3

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

func (*BunkerClient) NIP04Encrypt added in v0.36.3

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

func (*BunkerClient) NIP44Decrypt added in v0.36.0

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

func (*BunkerClient) NIP44Encrypt added in v0.36.0

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

func (*BunkerClient) Ping added in v0.28.4

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

func (*BunkerClient) RPC added in v0.28.4

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

func (*BunkerClient) SignEvent added in v0.28.4

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

type DynamicSigner added in v0.28.0

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

func NewDynamicSigner added in v0.28.0

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 added in v0.28.0

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

func (*DynamicSigner) HandleRequest added in v0.28.0

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

type RelayReadWrite added in v0.28.0

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 added in v0.39.0

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 added in v0.39.0

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 added in v0.28.0

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 added in v0.28.0

func NewStaticKeySigner(secretKey string) StaticKeySigner

func (*StaticKeySigner) GetSession added in v0.28.0

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

func (*StaticKeySigner) HandleRequest added in v0.28.0

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