From 6626001dd2d691193c6055ceb8bbb4424adb2b99 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 6 Feb 2024 12:47:46 -0300 Subject: [PATCH] --connect-as to specify client pubkey when using --connect to bunker --- event.go | 5 +++++ helpers.go | 7 ++++++- req.go | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/event.go b/event.go index eb8cd05..319ed38 100644 --- a/event.go +++ b/event.go @@ -48,6 +48,11 @@ example: Name: "connect", Usage: "sign event using NIP-46, expects a bunker://... URL", }, + &cli.StringFlag{ + Name: "connect-as", + Usage: "private key to when communicating with the bunker given on --connect", + DefaultText: "a random key", + }, &cli.BoolFlag{ Name: "envelope", Usage: "print the event enveloped in a [\"EVENT\", ...] message ready to be sent to a relay", diff --git a/helpers.go b/helpers.go index 6a2ce76..3b8f015 100644 --- a/helpers.go +++ b/helpers.go @@ -134,7 +134,12 @@ func gatherSecretKeyOrBunkerFromArguments(c *cli.Context) (string, *nip46.Bunker var err error if bunkerURL := c.String("connect"); bunkerURL != "" { - clientKey := nostr.GeneratePrivateKey() + clientKey := c.String("connect-as") + if clientKey != "" { + clientKey = strings.Repeat("0", 64-len(clientKey)) + clientKey + } else { + clientKey = nostr.GeneratePrivateKey() + } bunker, err := nip46.ConnectBunker(c.Context, clientKey, bunkerURL, nil) return "", bunker, err } diff --git a/req.go b/req.go index 5801b39..aceb9ff 100644 --- a/req.go +++ b/req.go @@ -117,6 +117,11 @@ example: Name: "connect", Usage: "sign AUTH using NIP-46, expects a bunker://... URL", }, + &cli.StringFlag{ + Name: "connect-as", + Usage: "private key to when communicating with the bunker given on --connect", + DefaultText: "a random key", + }, }, ArgsUsage: "[relay...]", Action: func(c *cli.Context) error {