--connect-as to specify client pubkey when using --connect to bunker

This commit is contained in:
fiatjaf 2024-02-06 12:47:46 -03:00
parent b7a7e0504f
commit 6626001dd2
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
3 changed files with 16 additions and 1 deletions

View File

@ -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",

View File

@ -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
}

5
req.go
View File

@ -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 {