Compare commits

...

6 Commits

Author SHA1 Message Date
fiatjaf
c90e61dbec set .DisableSliceFlagSeparator to true.
fixes nostr:nevent1qqs9qwgwnr2rzguzrgt99hhhyv8e84mcdr4mnk86uvm6ndjvzl4rjxqpzpmhxue69uhkztnwdaejumr0dshsz9mhwden5te0vf5hgcm0d9hx2u3wwdhkx6tpdshszxnhwden5te0vfhhxarj9ekx2cm5w4exjene9ehx2ap0j8u0fj
2024-08-07 11:46:08 -03:00
fiatjaf
d226cd6ce4 fix password input lowercasing characters.
fixes https://github.com/fiatjaf/nak/issues/28
2024-08-06 11:05:08 -03:00
fiatjaf
3d78e91f62 bunker: deny getPublicKey() even though it's harmless.
fixes https://github.com/fiatjaf/nak/issues/27
2024-08-06 10:56:08 -03:00
fiatjaf
84965f2253 don't set limit to zero on --stream 2024-08-03 10:52:46 -03:00
fiatjaf
928c73513c just move imports around. 2024-07-30 11:43:14 -03:00
fiatjaf
a36142604d compile to riscv64. 2024-07-27 10:32:32 -03:00
17 changed files with 82 additions and 62 deletions

View File

@@ -25,10 +25,14 @@ jobs:
strategy: strategy:
matrix: matrix:
goos: [linux, freebsd, darwin, windows] goos: [linux, freebsd, darwin, windows]
goarch: [amd64, arm64] goarch: [amd64, arm64, riscv64]
exclude: exclude:
- goarch: arm64 - goarch: arm64
goos: windows goos: windows
- goarch: riscv64
goos: windows
- goarch: riscv64
goos: darwin
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: wangyoucao577/go-release-action@v1.40 - uses: wangyoucao577/go-release-action@v1.40

View File

@@ -11,18 +11,19 @@ import (
"time" "time"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/fiatjaf/cli/v3"
"github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nip19" "github.com/nbd-wtf/go-nostr/nip19"
"github.com/nbd-wtf/go-nostr/nip46" "github.com/nbd-wtf/go-nostr/nip46"
"github.com/fiatjaf/cli/v3"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
) )
var bunker = &cli.Command{ var bunker = &cli.Command{
Name: "bunker", Name: "bunker",
Usage: "starts a NIP-46 signer daemon with the given --sec key", Usage: "starts a NIP-46 signer daemon with the given --sec key",
ArgsUsage: "[relay...]", ArgsUsage: "[relay...]",
Description: ``, Description: ``,
DisableSliceFlagSeparator: true,
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "sec", Name: "sec",
@@ -177,7 +178,7 @@ var bunker = &cli.Command{
}() }()
} }
return harmless || slices.Contains(authorizedKeys, from) || slices.Contains(authorizedSecrets, secret) return slices.Contains(authorizedKeys, from) || slices.Contains(authorizedSecrets, secret)
} }
for ie := range events { for ie := range events {

View File

@@ -7,14 +7,15 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/nbd-wtf/go-nostr"
"github.com/fiatjaf/cli/v3" "github.com/fiatjaf/cli/v3"
"github.com/nbd-wtf/go-nostr"
) )
var count = &cli.Command{ var count = &cli.Command{
Name: "count", Name: "count",
Usage: "generates encoded COUNT messages and optionally use them to talk to relays", Usage: "generates encoded COUNT messages and optionally use them to talk to relays",
Description: `outputs a NIP-45 request (the flags are mostly the same as 'nak req').`, Description: `outputs a NIP-45 request (the flags are mostly the same as 'nak req').`,
DisableSliceFlagSeparator: true,
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: "author", Name: "author",

View File

@@ -6,10 +6,10 @@ import (
"encoding/json" "encoding/json"
"strings" "strings"
"github.com/fiatjaf/cli/v3"
"github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nip19" "github.com/nbd-wtf/go-nostr/nip19"
sdk "github.com/nbd-wtf/nostr-sdk" sdk "github.com/nbd-wtf/nostr-sdk"
"github.com/fiatjaf/cli/v3"
) )
var decode = &cli.Command{ var decode = &cli.Command{
@@ -20,6 +20,7 @@ var decode = &cli.Command{
nak decode nevent1qqs29yet5tp0qq5xu5qgkeehkzqh5qu46739axzezcxpj4tjlkx9j7gpr4mhxue69uhkummnw3ez6ur4vgh8wetvd3hhyer9wghxuet5sh59ud nak decode nevent1qqs29yet5tp0qq5xu5qgkeehkzqh5qu46739axzezcxpj4tjlkx9j7gpr4mhxue69uhkummnw3ez6ur4vgh8wetvd3hhyer9wghxuet5sh59ud
nak decode nprofile1qqsrhuxx8l9ex335q7he0f09aej04zpazpl0ne2cgukyawd24mayt8gpz4mhxue69uhk2er9dchxummnw3ezumrpdejqz8thwden5te0dehhxarj94c82c3wwajkcmr0wfjx2u3wdejhgqgcwaehxw309aex2mrp0yhxummnw3exzarf9e3k7mgnp0sh5 nak decode nprofile1qqsrhuxx8l9ex335q7he0f09aej04zpazpl0ne2cgukyawd24mayt8gpz4mhxue69uhk2er9dchxummnw3ezumrpdejqz8thwden5te0dehhxarj94c82c3wwajkcmr0wfjx2u3wdejhgqgcwaehxw309aex2mrp0yhxummnw3exzarf9e3k7mgnp0sh5
nak decode nsec1jrmyhtjhgd9yqalps8hf9mayvd58852gtz66m7tqpacjedkp6kxq4dyxsr`, nak decode nsec1jrmyhtjhgd9yqalps8hf9mayvd58852gtz66m7tqpacjedkp6kxq4dyxsr`,
DisableSliceFlagSeparator: true,
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.BoolFlag{ &cli.BoolFlag{
Name: "id", Name: "id",

View File

@@ -4,9 +4,9 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/fiatjaf/cli/v3"
"github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nip19" "github.com/nbd-wtf/go-nostr/nip19"
"github.com/fiatjaf/cli/v3"
) )
var encode = &cli.Command{ var encode = &cli.Command{
@@ -25,10 +25,12 @@ var encode = &cli.Command{
} }
return nil return nil
}, },
DisableSliceFlagSeparator: true,
Commands: []*cli.Command{ Commands: []*cli.Command{
{ {
Name: "npub", Name: "npub",
Usage: "encode a hex public key into bech32 'npub' format", Usage: "encode a hex public key into bech32 'npub' format",
DisableSliceFlagSeparator: true,
Action: func(ctx context.Context, c *cli.Command) error { Action: func(ctx context.Context, c *cli.Command) error {
for target := range getStdinLinesOrArguments(c.Args()) { for target := range getStdinLinesOrArguments(c.Args()) {
if ok := nostr.IsValidPublicKey(target); !ok { if ok := nostr.IsValidPublicKey(target); !ok {
@@ -48,8 +50,9 @@ var encode = &cli.Command{
}, },
}, },
{ {
Name: "nsec", Name: "nsec",
Usage: "encode a hex private key into bech32 'nsec' format", Usage: "encode a hex private key into bech32 'nsec' format",
DisableSliceFlagSeparator: true,
Action: func(ctx context.Context, c *cli.Command) error { Action: func(ctx context.Context, c *cli.Command) error {
for target := range getStdinLinesOrArguments(c.Args()) { for target := range getStdinLinesOrArguments(c.Args()) {
if ok := nostr.IsValid32ByteHex(target); !ok { if ok := nostr.IsValid32ByteHex(target); !ok {
@@ -78,6 +81,7 @@ var encode = &cli.Command{
Usage: "attach relay hints to nprofile code", Usage: "attach relay hints to nprofile code",
}, },
}, },
DisableSliceFlagSeparator: true,
Action: func(ctx context.Context, c *cli.Command) error { Action: func(ctx context.Context, c *cli.Command) error {
for target := range getStdinLinesOrArguments(c.Args()) { for target := range getStdinLinesOrArguments(c.Args()) {
if ok := nostr.IsValid32ByteHex(target); !ok { if ok := nostr.IsValid32ByteHex(target); !ok {
@@ -116,6 +120,7 @@ var encode = &cli.Command{
Usage: "attach an author pubkey as a hint to the nevent code", Usage: "attach an author pubkey as a hint to the nevent code",
}, },
}, },
DisableSliceFlagSeparator: true,
Action: func(ctx context.Context, c *cli.Command) error { Action: func(ctx context.Context, c *cli.Command) error {
for target := range getStdinLinesOrArguments(c.Args()) { for target := range getStdinLinesOrArguments(c.Args()) {
if ok := nostr.IsValid32ByteHex(target); !ok { if ok := nostr.IsValid32ByteHex(target); !ok {
@@ -174,6 +179,7 @@ var encode = &cli.Command{
Usage: "attach relay hints to naddr code", Usage: "attach relay hints to naddr code",
}, },
}, },
DisableSliceFlagSeparator: true,
Action: func(ctx context.Context, c *cli.Command) error { Action: func(ctx context.Context, c *cli.Command) error {
for d := range getStdinLinesOrBlank() { for d := range getStdinLinesOrBlank() {
pubkey := c.String("pubkey") pubkey := c.String("pubkey")
@@ -211,8 +217,9 @@ var encode = &cli.Command{
}, },
}, },
{ {
Name: "note", Name: "note",
Usage: "generate note1 event codes (not recommended)", Usage: "generate note1 event codes (not recommended)",
DisableSliceFlagSeparator: true,
Action: func(ctx context.Context, c *cli.Command) error { Action: func(ctx context.Context, c *cli.Command) error {
for target := range getStdinLinesOrArguments(c.Args()) { for target := range getStdinLinesOrArguments(c.Args()) {
if ok := nostr.IsValid32ByteHex(target); !ok { if ok := nostr.IsValid32ByteHex(target); !ok {

View File

@@ -8,10 +8,10 @@ import (
"strings" "strings"
"time" "time"
"github.com/fiatjaf/cli/v3"
"github.com/mailru/easyjson" "github.com/mailru/easyjson"
"github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nip19" "github.com/nbd-wtf/go-nostr/nip19"
"github.com/fiatjaf/cli/v3"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
) )
@@ -31,6 +31,7 @@ if an event -- or a partial event -- is given on stdin, the flags can be used to
example: example:
echo '{"id":"a889df6a387419ff204305f4c2d296ee328c3cd4f8b62f205648a541b4554dfb","pubkey":"c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5","created_at":1698623783,"kind":1,"tags":[],"content":"hello from the nostr army knife","sig":"84876e1ee3e726da84e5d195eb79358b2b3eaa4d9bd38456fde3e8a2af3f1cd4cda23f23fda454869975b3688797d4c66e12f4c51c1b43c6d2997c5e61865661"}' | nak event wss://offchain.pub echo '{"id":"a889df6a387419ff204305f4c2d296ee328c3cd4f8b62f205648a541b4554dfb","pubkey":"c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5","created_at":1698623783,"kind":1,"tags":[],"content":"hello from the nostr army knife","sig":"84876e1ee3e726da84e5d195eb79358b2b3eaa4d9bd38456fde3e8a2af3f1cd4cda23f23fda454869975b3688797d4c66e12f4c51c1b43c6d2997c5e61865661"}' | nak event wss://offchain.pub
echo '{"tags": [["t", "spam"]]}' | nak event -c 'this is spam'`, echo '{"tags": [["t", "spam"]]}' | nak event -c 'this is spam'`,
DisableSliceFlagSeparator: true,
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "sec", Name: "sec",

View File

@@ -3,10 +3,10 @@ package main
import ( import (
"context" "context"
"github.com/fiatjaf/cli/v3"
"github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nip19" "github.com/nbd-wtf/go-nostr/nip19"
sdk "github.com/nbd-wtf/nostr-sdk" sdk "github.com/nbd-wtf/nostr-sdk"
"github.com/fiatjaf/cli/v3"
) )
var fetch = &cli.Command{ var fetch = &cli.Command{
@@ -15,6 +15,7 @@ var fetch = &cli.Command{
Description: `example usage: Description: `example usage:
nak fetch nevent1qqsxrwm0hd3s3fddh4jc2574z3xzufq6qwuyz2rvv3n087zvym3dpaqprpmhxue69uhhqatzd35kxtnjv4kxz7tfdenju6t0xpnej4 nak fetch nevent1qqsxrwm0hd3s3fddh4jc2574z3xzufq6qwuyz2rvv3n087zvym3dpaqprpmhxue69uhhqatzd35kxtnjv4kxz7tfdenju6t0xpnej4
echo npub1h8spmtw9m2huyv6v2j2qd5zv956z2zdugl6mgx02f2upffwpm3nqv0j4ps | nak fetch --relay wss://relay.nostr.band`, echo npub1h8spmtw9m2huyv6v2j2qd5zv956z2zdugl6mgx02f2upffwpm3nqv0j4ps | nak fetch --relay wss://relay.nostr.band`,
DisableSliceFlagSeparator: true,
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: "relay", Name: "relay",

View File

@@ -6,9 +6,9 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/fiatjaf/cli/v3"
"github.com/markusmobius/go-dateparser" "github.com/markusmobius/go-dateparser"
"github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr"
"github.com/fiatjaf/cli/v3"
) )
type NaturalTimeFlag = cli.FlagBase[nostr.Timestamp, struct{}, naturalTimeValue] type NaturalTimeFlag = cli.FlagBase[nostr.Timestamp, struct{}, naturalTimeValue]

2
go.mod
View File

@@ -9,6 +9,7 @@ require (
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
github.com/fatih/color v1.16.0 github.com/fatih/color v1.16.0
github.com/fiatjaf/cli/v3 v3.0.0-20240723181502-e7dd498b16ae
github.com/mailru/easyjson v0.7.7 github.com/mailru/easyjson v0.7.7
github.com/markusmobius/go-dateparser v1.2.3 github.com/markusmobius/go-dateparser v1.2.3
github.com/nbd-wtf/go-nostr v0.34.2 github.com/nbd-wtf/go-nostr v0.34.2
@@ -23,7 +24,6 @@ require (
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
github.com/elliotchance/pie/v2 v2.7.0 // indirect github.com/elliotchance/pie/v2 v2.7.0 // indirect
github.com/fiatjaf/cli/v3 v3.0.0-20240723181502-e7dd498b16ae // indirect
github.com/fiatjaf/eventstore v0.2.16 // indirect github.com/fiatjaf/eventstore v0.2.16 // indirect
github.com/gobwas/httphead v0.1.0 // indirect github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect github.com/gobwas/pool v0.2.1 // indirect

2
go.sum
View File

@@ -44,8 +44,6 @@ github.com/elliotchance/pie/v2 v2.7.0 h1:FqoIKg4uj0G/CrLGuMS9ejnFKa92lxE1dEgBD3p
github.com/elliotchance/pie/v2 v2.7.0/go.mod h1:18t0dgGFH006g4eVdDtWfgFZPQEgl10IoEO8YWEq3Og= github.com/elliotchance/pie/v2 v2.7.0/go.mod h1:18t0dgGFH006g4eVdDtWfgFZPQEgl10IoEO8YWEq3Og=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fiatjaf/cli/v3 v3.0.0-20240714232133-bb036558919f h1:SQ5W4q4HfpAPA8e8uPADqs4dhI6VvVwUq00DtlpHIt0=
github.com/fiatjaf/cli/v3 v3.0.0-20240714232133-bb036558919f/go.mod h1:Z1ItyMma7t6I7zHG9OpbExhHQOSkFf/96n+mAZ9MtVI=
github.com/fiatjaf/cli/v3 v3.0.0-20240723181502-e7dd498b16ae h1:0B/1dU3YECIbPoBIRTQ4c0scZCNz9TVHtQpiODGrTTo= github.com/fiatjaf/cli/v3 v3.0.0-20240723181502-e7dd498b16ae h1:0B/1dU3YECIbPoBIRTQ4c0scZCNz9TVHtQpiODGrTTo=
github.com/fiatjaf/cli/v3 v3.0.0-20240723181502-e7dd498b16ae/go.mod h1:aAWPO4bixZZxPtOnH6K3q4GbQ0jftUNDW9Oa861IRew= github.com/fiatjaf/cli/v3 v3.0.0-20240723181502-e7dd498b16ae/go.mod h1:aAWPO4bixZZxPtOnH6K3q4GbQ0jftUNDW9Oa861IRew=
github.com/fiatjaf/eventstore v0.2.16 h1:NR64mnyUT5nJR8Sj2AwJTd1Hqs5kKJcCFO21ggUkvWg= github.com/fiatjaf/eventstore v0.2.16 h1:NR64mnyUT5nJR8Sj2AwJTd1Hqs5kKJcCFO21ggUkvWg=

View File

@@ -13,11 +13,11 @@ import (
"github.com/chzyer/readline" "github.com/chzyer/readline"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/fiatjaf/cli/v3"
"github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nip19" "github.com/nbd-wtf/go-nostr/nip19"
"github.com/nbd-wtf/go-nostr/nip46" "github.com/nbd-wtf/go-nostr/nip46"
"github.com/nbd-wtf/go-nostr/nip49" "github.com/nbd-wtf/go-nostr/nip49"
"github.com/fiatjaf/cli/v3"
) )
const ( const (
@@ -261,22 +261,18 @@ func askPassword(msg string, shouldAskAgain func(answer string) bool) (string, e
EnableMask: true, EnableMask: true,
MaskRune: '*', MaskRune: '*',
} }
return _ask(config, msg, "", shouldAskAgain)
}
func _ask(config *readline.Config, msg string, defaultValue string, shouldAskAgain func(answer string) bool) (string, error) {
rl, err := readline.NewEx(config) rl, err := readline.NewEx(config)
if err != nil { if err != nil {
return "", err return "", err
} }
rl.WriteStdin([]byte(defaultValue))
for { for {
answer, err := rl.Readline() answer, err := rl.Readline()
if err != nil { if err != nil {
return "", err return "", err
} }
answer = strings.TrimSpace(strings.ToLower(answer)) answer = strings.TrimSpace(answer)
if shouldAskAgain != nil && shouldAskAgain(answer) { if shouldAskAgain != nil && shouldAskAgain(answer) {
continue continue
} }

46
key.go
View File

@@ -11,16 +11,17 @@ import (
"github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr/musig2" "github.com/btcsuite/btcd/btcec/v2/schnorr/musig2"
"github.com/decred/dcrd/dcrec/secp256k1/v4" "github.com/decred/dcrd/dcrec/secp256k1/v4"
"github.com/fiatjaf/cli/v3"
"github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nip19" "github.com/nbd-wtf/go-nostr/nip19"
"github.com/nbd-wtf/go-nostr/nip49" "github.com/nbd-wtf/go-nostr/nip49"
"github.com/fiatjaf/cli/v3"
) )
var key = &cli.Command{ var key = &cli.Command{
Name: "key", Name: "key",
Usage: "operations on secret keys: generate, derive, encrypt, decrypt.", Usage: "operations on secret keys: generate, derive, encrypt, decrypt.",
Description: ``, Description: ``,
DisableSliceFlagSeparator: true,
Commands: []*cli.Command{ Commands: []*cli.Command{
generate, generate,
public, public,
@@ -31,9 +32,10 @@ var key = &cli.Command{
} }
var generate = &cli.Command{ var generate = &cli.Command{
Name: "generate", Name: "generate",
Usage: "generates a secret key", Usage: "generates a secret key",
Description: ``, Description: ``,
DisableSliceFlagSeparator: true,
Action: func(ctx context.Context, c *cli.Command) error { Action: func(ctx context.Context, c *cli.Command) error {
sec := nostr.GeneratePrivateKey() sec := nostr.GeneratePrivateKey()
stdout(sec) stdout(sec)
@@ -42,10 +44,11 @@ var generate = &cli.Command{
} }
var public = &cli.Command{ var public = &cli.Command{
Name: "public", Name: "public",
Usage: "computes a public key from a secret key", Usage: "computes a public key from a secret key",
Description: ``, Description: ``,
ArgsUsage: "[secret]", ArgsUsage: "[secret]",
DisableSliceFlagSeparator: true,
Action: func(ctx context.Context, c *cli.Command) error { Action: func(ctx context.Context, c *cli.Command) error {
for sec := range getSecretKeysFromStdinLinesOrSlice(ctx, c, c.Args().Slice()) { for sec := range getSecretKeysFromStdinLinesOrSlice(ctx, c, c.Args().Slice()) {
pubkey, err := nostr.GetPublicKey(sec) pubkey, err := nostr.GetPublicKey(sec)
@@ -60,10 +63,11 @@ var public = &cli.Command{
} }
var encrypt = &cli.Command{ var encrypt = &cli.Command{
Name: "encrypt", Name: "encrypt",
Usage: "encrypts a secret key and prints an ncryptsec code", Usage: "encrypts a secret key and prints an ncryptsec code",
Description: `uses the NIP-49 standard.`, Description: `uses the NIP-49 standard.`,
ArgsUsage: "<secret> <password>", ArgsUsage: "<secret> <password>",
DisableSliceFlagSeparator: true,
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.IntFlag{ &cli.IntFlag{
Name: "logn", Name: "logn",
@@ -98,10 +102,11 @@ var encrypt = &cli.Command{
} }
var decrypt = &cli.Command{ var decrypt = &cli.Command{
Name: "decrypt", Name: "decrypt",
Usage: "takes an ncrypsec and a password and decrypts it into an nsec", Usage: "takes an ncrypsec and a password and decrypts it into an nsec",
Description: `uses the NIP-49 standard.`, Description: `uses the NIP-49 standard.`,
ArgsUsage: "<ncryptsec-code> <password>", ArgsUsage: "<ncryptsec-code> <password>",
DisableSliceFlagSeparator: true,
Action: func(ctx context.Context, c *cli.Command) error { Action: func(ctx context.Context, c *cli.Command) error {
var ncryptsec string var ncryptsec string
var password string var password string
@@ -151,7 +156,8 @@ var combine = &cli.Command{
Description: `The public keys must have 33 bytes (66 characters hex), with the 02 or 03 prefix. It is common in Nostr to drop that first byte, so you'll have to derive the public keys again from the private keys in order to get it back. Description: `The public keys must have 33 bytes (66 characters hex), with the 02 or 03 prefix. It is common in Nostr to drop that first byte, so you'll have to derive the public keys again from the private keys in order to get it back.
However, if the intent is to check if two existing Nostr pubkeys match a given combined pubkey, then it might be sufficient to calculate the combined key for all the possible combinations of pubkeys in the input.`, However, if the intent is to check if two existing Nostr pubkeys match a given combined pubkey, then it might be sufficient to calculate the combined key for all the possible combinations of pubkeys in the input.`,
ArgsUsage: "[pubkey...]", ArgsUsage: "[pubkey...]",
DisableSliceFlagSeparator: true,
Action: func(ctx context.Context, c *cli.Command) error { Action: func(ctx context.Context, c *cli.Command) error {
type Combination struct { type Combination struct {
Variants []string `json:"input_variants"` Variants []string `json:"input_variants"`

11
main.go
View File

@@ -8,11 +8,12 @@ import (
) )
var app = &cli.Command{ var app = &cli.Command{
Name: "nak", Name: "nak",
Suggest: true, Suggest: true,
UseShortOptionHandling: true, UseShortOptionHandling: true,
AllowFlagsAfterArguments: true, AllowFlagsAfterArguments: true,
Usage: "the nostr army knife command-line tool", Usage: "the nostr army knife command-line tool",
DisableSliceFlagSeparator: true,
Commands: []*cli.Command{ Commands: []*cli.Command{
req, req,
count, count,

View File

@@ -16,7 +16,7 @@ import (
) )
func performMusig( func performMusig(
ctx context.Context, _ context.Context,
sec string, sec string,
evt *nostr.Event, evt *nostr.Event,
numSigners int, numSigners int,

View File

@@ -11,10 +11,10 @@ import (
"io" "io"
"net/http" "net/http"
"github.com/fiatjaf/cli/v3"
"github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nip11" "github.com/nbd-wtf/go-nostr/nip11"
"github.com/nbd-wtf/go-nostr/nip86" "github.com/nbd-wtf/go-nostr/nip86"
"github.com/fiatjaf/cli/v3"
) )
var relay = &cli.Command{ var relay = &cli.Command{
@@ -22,7 +22,8 @@ var relay = &cli.Command{
Usage: "gets the relay information document for the given relay, as JSON", Usage: "gets the relay information document for the given relay, as JSON",
Description: `example: Description: `example:
nak relay nostr.wine`, nak relay nostr.wine`,
ArgsUsage: "<relay-url>", ArgsUsage: "<relay-url>",
DisableSliceFlagSeparator: true,
Action: func(ctx context.Context, c *cli.Command) error { Action: func(ctx context.Context, c *cli.Command) error {
for url := range getStdinLinesOrArguments(c.Args()) { for url := range getStdinLinesOrArguments(c.Args()) {
if url == "" { if url == "" {

5
req.go
View File

@@ -7,9 +7,9 @@ import (
"os" "os"
"strings" "strings"
"github.com/fiatjaf/cli/v3"
"github.com/mailru/easyjson" "github.com/mailru/easyjson"
"github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr"
"github.com/fiatjaf/cli/v3"
) )
const CATEGORY_FILTER_ATTRIBUTES = "FILTER ATTRIBUTES" const CATEGORY_FILTER_ATTRIBUTES = "FILTER ATTRIBUTES"
@@ -27,6 +27,7 @@ it can also take a filter from stdin, optionally modify it with flags and send i
example: example:
echo '{"kinds": [1], "#t": ["test"]}' | nak req -l 5 -k 4549 --tag t=spam wss://nostr-pub.wellorder.net`, echo '{"kinds": [1], "#t": ["test"]}' | nak req -l 5 -k 4549 --tag t=spam wss://nostr-pub.wellorder.net`,
DisableSliceFlagSeparator: true,
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: "author", Name: "author",
@@ -240,7 +241,7 @@ example:
if limit := c.Uint("limit"); limit != 0 { if limit := c.Uint("limit"); limit != 0 {
filter.Limit = int(limit) filter.Limit = int(limit)
} else if c.IsSet("limit") || c.Bool("stream") { } else if c.IsSet("limit") {
filter.LimitZero = true filter.LimitZero = true
} }

View File

@@ -4,8 +4,8 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"github.com/nbd-wtf/go-nostr"
"github.com/fiatjaf/cli/v3" "github.com/fiatjaf/cli/v3"
"github.com/nbd-wtf/go-nostr"
) )
var verify = &cli.Command{ var verify = &cli.Command{
@@ -15,6 +15,7 @@ var verify = &cli.Command{
echo '{"id":"a889df6a387419ff204305f4c2d296ee328c3cd4f8b62f205648a541b4554dfb","pubkey":"c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5","created_at":1698623783,"kind":1,"tags":[],"content":"hello from the nostr army knife","sig":"84876e1ee3e726da84e5d195eb79358b2b3eaa4d9bd38456fde3e8a2af3f1cd4cda23f23fda454869975b3688797d4c66e12f4c51c1b43c6d2997c5e61865661"}' | nak verify echo '{"id":"a889df6a387419ff204305f4c2d296ee328c3cd4f8b62f205648a541b4554dfb","pubkey":"c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5","created_at":1698623783,"kind":1,"tags":[],"content":"hello from the nostr army knife","sig":"84876e1ee3e726da84e5d195eb79358b2b3eaa4d9bd38456fde3e8a2af3f1cd4cda23f23fda454869975b3688797d4c66e12f4c51c1b43c6d2997c5e61865661"}' | nak verify
it outputs nothing if the verification is successful.`, it outputs nothing if the verification is successful.`,
DisableSliceFlagSeparator: true,
Action: func(ctx context.Context, c *cli.Command) error { Action: func(ctx context.Context, c *cli.Command) error {
for stdinEvent := range getStdinLinesOrArguments(c.Args()) { for stdinEvent := range getStdinLinesOrArguments(c.Args()) {
evt := nostr.Event{} evt := nostr.Event{}