Skip to content

Commit 8754c55

Browse files
committed
verify: debug mode (-vv) prints useful info about event serialization.
1 parent 25d2045 commit 8754c55

2 files changed

Lines changed: 25 additions & 11 deletions

File tree

nsite.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"fiatjaf.com/nostr/nip19"
1414
"fiatjaf.com/nostr/nip5a"
1515
"fiatjaf.com/nostr/nipb0/blossom"
16+
"github.com/fatih/color"
1617
"github.com/urfave/cli/v3"
1718
)
1819

@@ -112,7 +113,7 @@ var nsite = &cli.Command{
112113
}
113114

114115
if !c.Bool("yes") {
115-
log("files:\n")
116+
log("%s\n", color.CyanString("files:"))
116117

117118
if err := filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error {
118119
if err != nil {
@@ -127,15 +128,15 @@ var nsite = &cli.Command{
127128
return fmt.Errorf("failed to get relative path for %s: %w", path, err)
128129
}
129130

130-
log(" /%s\n", filepath.ToSlash(relPath))
131+
log(" %s\n", color.GreenString("/%s", filepath.ToSlash(relPath)))
131132
return nil
132133
}); err != nil {
133134
return err
134135
}
135136

136-
log("blossom servers:\n")
137+
log("%s\n", color.CyanString("blossom servers:"))
137138
for _, server := range blossomServers {
138-
log(" %s\n", server)
139+
log(" %s\n", color.YellowString(server))
139140
}
140141
if !askConfirmation("upload nsite and publish manifest? [y/n] ") {
141142
return fmt.Errorf("aborted")
@@ -163,7 +164,7 @@ var nsite = &cli.Command{
163164
return fmt.Errorf("failed to upload %s to %s: %w", path, server, err)
164165
}
165166
hhash = bd.SHA256
166-
log("uploaded %s to %s as %s\n", path, server, hhash)
167+
log("uploaded %s to %s as %s\n", color.GreenString(path), color.YellowString(server), color.CyanString(hhash))
167168
}
168169

169170
var hash [32]byte

verify.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55

66
"fiatjaf.com/nostr"
7+
"github.com/fatih/color"
78
"github.com/urfave/cli/v3"
89
)
910

@@ -27,23 +28,35 @@ it outputs nothing if the verification is successful.`,
2728

2829
if err := json.Unmarshal([]byte(stdinEvent), &evt); err != nil {
2930
ctx = lineProcessingError(ctx, "invalid event: %s", err)
30-
logverbose("<>: invalid event.\n", evt.ID.Hex())
31+
logverbose("%s\n", color.RedString("<>: invalid event."))
3132
continue
3233
}
3334

34-
if evt.GetID() != evt.ID {
35-
ctx = lineProcessingError(ctx, "invalid .id, expected %s, got %s", evt.GetID(), evt.ID)
36-
logverbose("%s: invalid id.\n", evt.ID.Hex())
35+
impliedID := evt.GetID()
36+
idsMatch := impliedID == evt.ID
37+
logverbose(
38+
"%s\n%s %s\n%s %s\n%s %s\n%s %s\n%s %s\n",
39+
color.CyanString("verifying event:"),
40+
color.BlueString(" event: "), stdinEvent,
41+
color.BlueString(" given id: "), color.YellowString("%s", evt.ID),
42+
color.BlueString(" serialized:"), string(evt.Serialize()),
43+
color.BlueString(" implied id:"), color.YellowString("%s", impliedID),
44+
color.BlueString(" ids match: "), color.New(map[bool]color.Attribute{true: color.FgGreen, false: color.FgRed}[idsMatch]).Sprint(idsMatch),
45+
)
46+
47+
if impliedID != evt.ID {
48+
ctx = lineProcessingError(ctx, "invalid .id, expected %s, got %s", impliedID, evt.ID)
49+
logverbose("%s\n", color.RedString("invalid id: %s", evt.ID.Hex()))
3750
continue
3851
}
3952

4053
if !evt.VerifySignature() {
4154
ctx = lineProcessingError(ctx, "invalid signature")
42-
logverbose("%s: invalid signature.\n", evt.ID.Hex())
55+
logverbose("%s\n", color.RedString("invalid signature: %s", evt.ID.Hex()))
4356
continue
4457
}
4558

46-
logverbose("%s: valid.\n", evt.ID.Hex())
59+
logverbose("%s\n", color.GreenString("valid: %s", evt.ID.Hex()))
4760
}
4861

4962
exitIfLineProcessingError(ctx)

0 commit comments

Comments
 (0)