nip46

package
v0.0.0-...-2ba5295 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BUNKER_REGEX = regexp.MustCompile(`^bunker:\/\/([0-9a-f]{64})\??([?\/\w:.=&%]*)$`)

Functions

func CheckNameAvailability

func CheckNameAvailability(ctx context.Context, name, domain string) bool

func IsValidBunkerURL

func IsValidBunkerURL(input string) bool

Types

type BunkerClient

type BunkerClient struct {
	// 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 CreateAccount

func CreateAccount(
	ctx context.Context,
	clientSecretKey string,
	name string,
	domain string,
	pool *nostr.SimplePool,
	extraOpts *CreateAccountOptions,
	onAuth func(string),
) (*BunkerClient, error)

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) 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 CreateAccountOptions

type CreateAccountOptions struct {
	Email string
}

type DynamicSigner

type DynamicSigner struct {
	sync.Mutex

	RelaysToAdvertise map[string]RelayReadWrite
	// contains filtered or unexported fields
}

func NewDynamicSigner

func NewDynamicSigner(
	getPrivateKey func(pubkey string) (string, error),
	authorizeSigning func(event nostr.Event) bool,
	onEventSigned func(event nostr.Event),
	authorizeNIP04 func() bool,
) DynamicSigner

func (*DynamicSigner) GetSession

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

func (*DynamicSigner) HandleRequest

func (p *DynamicSigner) HandleRequest(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"`
}

type Response

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

type Session

type Session struct {
	SharedKey []byte
}

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(event *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) 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(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