Skip to content

Commit

Permalink
Add jwt verify cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
KendallWeihe committed Mar 19, 2024
1 parent 6888452 commit e0e2549
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions cmd/web5/cmd_jwt_verify.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion cmd/web5/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."`
Expand Down

0 comments on commit e0e2549

Please sign in to comment.