diff --git a/cmd/web5/cmd_jwt_verify.go b/cmd/web5/cmd_jwt_verify.go new file mode 100644 index 0000000..04d3ba2 --- /dev/null +++ b/cmd/web5/cmd_jwt_verify.go @@ -0,0 +1,42 @@ +package main + +import ( + "encoding/json" + "fmt" + + "github.com/tbd54566975/web5-go/jwt" +) + +type jwtVerifyCMD struct { + JWT string `arg:"" help:"The base64 encoded JWT"` + Claims bool `help:"Only print the JWT Claims." default:"false"` + NoIndent bool `help:"Print the decoded VC-JWT without indentation." default:"false"` +} + +func (c *jwtVerifyCMD) Run() error { + decoded, err := jwt.Verify(c.JWT) + if err != nil { + return err + } + + var partToPrint any + if c.Claims { + partToPrint = decoded.Claims + } else { + partToPrint = decoded + } + + var bytes []byte + if c.NoIndent { + bytes, err = json.Marshal(partToPrint) + } else { + bytes, err = json.MarshalIndent(partToPrint, "", " ") + } + if err != nil { + return err + } + + fmt.Println(string(bytes)) + + return nil +} diff --git a/cmd/web5/main.go b/cmd/web5/main.go index 91148c6..219bb9c 100644 --- a/cmd/web5/main.go +++ b/cmd/web5/main.go @@ -14,7 +14,7 @@ type CLI struct { JWT struct { Sign jwtSignCMD `cmd:"" help:"Sign a JWT."` Decode jwtDecodeCMD `cmd:"" help:"Decode a JWT."` - // todo verify + Verify jwtVerifyCMD `cmd:"" help:"Verify a JWT."` } `cmd:"" help:"Interface with JWT's."` DID struct { Resolve didResolveCMD `cmd:"" help:"Resolve a DID."`