mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-18 13:53:03 +01:00
- make BatchedSubManyEose() use a single duplicate id index and use it for replaceable loaders; - fixes parsing follow entry from kind:3 events (and others); - adds a "cause" to most cancelation errors in relay/pool; - remove the inherent cache from dataloader (we have our own hopefully); - increase max frame size we can read from any websocket to 2**18 (262k), which gives over 2000 item lists.
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package keyer
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/nbd-wtf/go-nostr"
|
|
"github.com/nbd-wtf/go-nostr/nip46"
|
|
)
|
|
|
|
// BunkerSigner is a signer that asks a bunker using NIP-46 every time it needs to do an operation.
|
|
type BunkerSigner struct {
|
|
bunker *nip46.BunkerClient
|
|
}
|
|
|
|
func NewBunkerSignerFromBunkerClient(bc *nip46.BunkerClient) BunkerSigner {
|
|
return BunkerSigner{bc}
|
|
}
|
|
|
|
func (bs BunkerSigner) GetPublicKey(ctx context.Context) (string, error) {
|
|
ctx, cancel := context.WithTimeoutCause(ctx, time.Second*30, errors.New("get_public_key took too long"))
|
|
defer cancel()
|
|
pk, err := bs.bunker.GetPublicKey(ctx)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return pk, nil
|
|
}
|
|
|
|
func (bs BunkerSigner) SignEvent(ctx context.Context, evt *nostr.Event) error {
|
|
ctx, cancel := context.WithTimeoutCause(ctx, time.Second*30, errors.New("sign_event took too long"))
|
|
defer cancel()
|
|
return bs.bunker.SignEvent(ctx, evt)
|
|
}
|
|
|
|
func (bs BunkerSigner) Encrypt(ctx context.Context, plaintext string, recipient string) (string, error) {
|
|
return bs.bunker.NIP44Encrypt(ctx, recipient, plaintext)
|
|
}
|
|
|
|
func (bs BunkerSigner) Decrypt(ctx context.Context, base64ciphertext string, sender string) (plaintext string, err error) {
|
|
return bs.bunker.NIP44Encrypt(ctx, sender, base64ciphertext)
|
|
}
|