Skip to content

Commit

Permalink
shed: Util for creating ID CIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Nov 6, 2020
1 parent d421274 commit ee9df63
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions cmd/lotus-shed/cid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"encoding/base64"
"encoding/hex"
"fmt"

"github.com/urfave/cli/v2"

"github.com/ipfs/go-cid"
mh "github.com/multiformats/go-multihash"
)

var cidCmd = &cli.Command{
Name: "cid",
Subcommands: cli.Commands{
cidIdCmd,
},
}

var cidIdCmd = &cli.Command{
Name: "id",
Usage: "create identity CID from hex or base64 data",
Action: func(cctx *cli.Context) error {
if !cctx.Args().Present() {
return fmt.Errorf("must specify data")
}

dec, err := hex.DecodeString(cctx.Args().First())
if err != nil {
dec, err = base64.StdEncoding.DecodeString(cctx.Args().First())
if err != nil {
return err
}

}

builder := cid.V1Builder{Codec: cid.Raw, MhType: mh.IDENTITY}

c, err := builder.Sum(dec)
if err != nil {
return err
}

fmt.Println(c)
return nil
},
}
1 change: 1 addition & 0 deletions cmd/lotus-shed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func main() {
msgCmd,
electionCmd,
rpcCmd,
cidCmd,
}

app := &cli.App{
Expand Down

0 comments on commit ee9df63

Please sign in to comment.