mirror of
https://github.com/fiatjaf/nak.git
synced 2024-12-22 10:05:52 -05:00
fix lineProcessingError() -- it wasn't returning a ctx so it was a noop.
This commit is contained in:
parent
2ca6bb0940
commit
316d94166e
|
@ -50,7 +50,7 @@ var decode = &cli.Command{
|
|||
decodeResult.HexResult.PrivateKey = hex.EncodeToString(b)
|
||||
decodeResult.HexResult.PublicKey = hex.EncodeToString(b)
|
||||
} else {
|
||||
lineProcessingError(ctx, "hex string with invalid number of bytes: %d", len(b))
|
||||
ctx = lineProcessingError(ctx, "hex string with invalid number of bytes: %d", len(b))
|
||||
continue
|
||||
}
|
||||
} else if evp := sdk.InputToEventPointer(input); evp != nil {
|
||||
|
@ -64,7 +64,7 @@ var decode = &cli.Command{
|
|||
decodeResult.PrivateKey.PrivateKey = value.(string)
|
||||
decodeResult.PrivateKey.PublicKey, _ = nostr.GetPublicKey(value.(string))
|
||||
} else {
|
||||
lineProcessingError(ctx, "couldn't decode input '%s': %s", input, err)
|
||||
ctx = lineProcessingError(ctx, "couldn't decode input '%s': %s", input, err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
12
encode.go
12
encode.go
|
@ -32,7 +32,7 @@ var encode = &cli.Command{
|
|||
Action: func(ctx context.Context, c *cli.Command) error {
|
||||
for target := range getStdinLinesOrArguments(c.Args()) {
|
||||
if ok := nostr.IsValidPublicKey(target); !ok {
|
||||
lineProcessingError(ctx, "invalid public key: %s", target)
|
||||
ctx = lineProcessingError(ctx, "invalid public key: %s", target)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ var encode = &cli.Command{
|
|||
Action: func(ctx context.Context, c *cli.Command) error {
|
||||
for target := range getStdinLinesOrArguments(c.Args()) {
|
||||
if ok := nostr.IsValid32ByteHex(target); !ok {
|
||||
lineProcessingError(ctx, "invalid private key: %s", target)
|
||||
ctx = lineProcessingError(ctx, "invalid private key: %s", target)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ var encode = &cli.Command{
|
|||
Action: func(ctx context.Context, c *cli.Command) error {
|
||||
for target := range getStdinLinesOrArguments(c.Args()) {
|
||||
if ok := nostr.IsValid32ByteHex(target); !ok {
|
||||
lineProcessingError(ctx, "invalid public key: %s", target)
|
||||
ctx = lineProcessingError(ctx, "invalid public key: %s", target)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ var encode = &cli.Command{
|
|||
Action: func(ctx context.Context, c *cli.Command) error {
|
||||
for target := range getStdinLinesOrArguments(c.Args()) {
|
||||
if ok := nostr.IsValid32ByteHex(target); !ok {
|
||||
lineProcessingError(ctx, "invalid event id: %s", target)
|
||||
ctx = lineProcessingError(ctx, "invalid event id: %s", target)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,7 @@ var encode = &cli.Command{
|
|||
if d == "" {
|
||||
d = c.String("identifier")
|
||||
if d == "" {
|
||||
lineProcessingError(ctx, "\"d\" tag identifier can't be empty")
|
||||
ctx = lineProcessingError(ctx, "\"d\" tag identifier can't be empty")
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ var encode = &cli.Command{
|
|||
Action: func(ctx context.Context, c *cli.Command) error {
|
||||
for target := range getStdinLinesOrArguments(c.Args()) {
|
||||
if ok := nostr.IsValid32ByteHex(target); !ok {
|
||||
lineProcessingError(ctx, "invalid event id: %s", target)
|
||||
ctx = lineProcessingError(ctx, "invalid event id: %s", target)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
2
event.go
2
event.go
|
@ -176,7 +176,7 @@ example:
|
|||
|
||||
if stdinEvent != "" {
|
||||
if err := easyjson.Unmarshal([]byte(stdinEvent), &evt); err != nil {
|
||||
lineProcessingError(ctx, "invalid event received from stdin: %s", err)
|
||||
ctx = lineProcessingError(ctx, "invalid event received from stdin: %s", err)
|
||||
continue
|
||||
}
|
||||
kindWasSupplied = strings.Contains(stdinEvent, `"kind"`)
|
||||
|
|
4
fetch.go
4
fetch.go
|
@ -38,7 +38,7 @@ var fetch = &cli.Command{
|
|||
|
||||
prefix, value, err := nip19.Decode(code)
|
||||
if err != nil {
|
||||
lineProcessingError(ctx, "failed to decode: %s", err)
|
||||
ctx = lineProcessingError(ctx, "failed to decode: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ var fetch = &cli.Command{
|
|||
}
|
||||
|
||||
if len(relays) == 0 {
|
||||
lineProcessingError(ctx, "no relay hints found")
|
||||
ctx = lineProcessingError(ctx, "no relay hints found")
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -169,9 +169,9 @@ relayLoop:
|
|||
return pool, relays
|
||||
}
|
||||
|
||||
func lineProcessingError(ctx context.Context, msg string, args ...any) {
|
||||
ctx = context.WithValue(ctx, LINE_PROCESSING_ERROR, true)
|
||||
func lineProcessingError(ctx context.Context, msg string, args ...any) context.Context {
|
||||
log(msg+"\n", args...)
|
||||
return context.WithValue(ctx, LINE_PROCESSING_ERROR, true)
|
||||
}
|
||||
|
||||
func exitIfLineProcessingError(ctx context.Context) {
|
||||
|
|
10
key.go
10
key.go
|
@ -50,7 +50,7 @@ var public = &cli.Command{
|
|||
for sec := range getSecretKeysFromStdinLinesOrSlice(ctx, c, c.Args().Slice()) {
|
||||
pubkey, err := nostr.GetPublicKey(sec)
|
||||
if err != nil {
|
||||
lineProcessingError(ctx, "failed to derive public key: %s", err)
|
||||
ctx = lineProcessingError(ctx, "failed to derive public key: %s", err)
|
||||
continue
|
||||
}
|
||||
stdout(pubkey)
|
||||
|
@ -88,7 +88,7 @@ var encrypt = &cli.Command{
|
|||
for sec := range getSecretKeysFromStdinLinesOrSlice(ctx, c, keys) {
|
||||
ncryptsec, err := nip49.Encrypt(sec, password, uint8(c.Int("logn")), 0x02)
|
||||
if err != nil {
|
||||
lineProcessingError(ctx, "failed to encrypt: %s", err)
|
||||
ctx = lineProcessingError(ctx, "failed to encrypt: %s", err)
|
||||
continue
|
||||
}
|
||||
stdout(ncryptsec)
|
||||
|
@ -133,7 +133,7 @@ var decrypt = &cli.Command{
|
|||
for ncryptsec := range getStdinLinesOrArgumentsFromSlice([]string{ncryptsec}) {
|
||||
sec, err := nip49.Decrypt(ncryptsec, password)
|
||||
if err != nil {
|
||||
lineProcessingError(ctx, "failed to decrypt: %s", err)
|
||||
ctx = lineProcessingError(ctx, "failed to decrypt: %s", err)
|
||||
continue
|
||||
}
|
||||
nsec, _ := nip19.EncodePrivateKey(sec)
|
||||
|
@ -264,13 +264,13 @@ func getSecretKeysFromStdinLinesOrSlice(ctx context.Context, c *cli.Command, key
|
|||
if strings.HasPrefix(sec, "nsec1") {
|
||||
_, data, err := nip19.Decode(sec)
|
||||
if err != nil {
|
||||
lineProcessingError(ctx, "invalid nsec code: %s", err)
|
||||
ctx = lineProcessingError(ctx, "invalid nsec code: %s", err)
|
||||
continue
|
||||
}
|
||||
sec = data.(string)
|
||||
}
|
||||
if !nostr.IsValid32ByteHex(sec) {
|
||||
lineProcessingError(ctx, "invalid hex key")
|
||||
ctx = lineProcessingError(ctx, "invalid hex key")
|
||||
continue
|
||||
}
|
||||
ch <- sec
|
||||
|
|
2
relay.go
2
relay.go
|
@ -23,7 +23,7 @@ var relay = &cli.Command{
|
|||
|
||||
info, err := nip11.Fetch(ctx, url)
|
||||
if err != nil {
|
||||
lineProcessingError(ctx, "failed to fetch '%s' information document: %w", url, err)
|
||||
ctx = lineProcessingError(ctx, "failed to fetch '%s' information document: %w", url, err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
2
req.go
2
req.go
|
@ -182,7 +182,7 @@ example:
|
|||
filter := nostr.Filter{}
|
||||
if stdinFilter != "" {
|
||||
if err := easyjson.Unmarshal([]byte(stdinFilter), &filter); err != nil {
|
||||
lineProcessingError(ctx, "invalid filter '%s' received from stdin: %s", stdinFilter, err)
|
||||
ctx = lineProcessingError(ctx, "invalid filter '%s' received from stdin: %s", stdinFilter, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,18 +20,18 @@ it outputs nothing if the verification is successful.`,
|
|||
evt := nostr.Event{}
|
||||
if stdinEvent != "" {
|
||||
if err := json.Unmarshal([]byte(stdinEvent), &evt); err != nil {
|
||||
lineProcessingError(ctx, "invalid event: %s", err)
|
||||
ctx = lineProcessingError(ctx, "invalid event: %s", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if evt.GetID() != evt.ID {
|
||||
lineProcessingError(ctx, "invalid .id, expected %s, got %s", evt.GetID(), evt.ID)
|
||||
ctx = lineProcessingError(ctx, "invalid .id, expected %s, got %s", evt.GetID(), evt.ID)
|
||||
continue
|
||||
}
|
||||
|
||||
if ok, err := evt.CheckSignature(); !ok {
|
||||
lineProcessingError(ctx, "invalid signature: %s", err)
|
||||
ctx = lineProcessingError(ctx, "invalid signature: %s", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user