Merge pull request #4726 from filecoin-project/feat/shed-id-cid

shed: Util for creating ID CIDs
This commit is contained in:
Łukasz Magiera 2020-11-06 16:03:45 +01:00 committed by GitHub
commit 2f9d19c42c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 0 deletions

48
cmd/lotus-shed/cid.go Normal file
View File

@ -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
},
}

View File

@ -48,6 +48,7 @@ func main() {
msgCmd,
electionCmd,
rpcCmd,
cidCmd,
}
app := &cli.App{