Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CommP CID generation (official & correct!) #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ commp
lambda/lambda
lambda/deployment.zip
commp_lambda
commp-cid
30 changes: 30 additions & 0 deletions commp-cid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"encoding/hex"
"fmt"
"github.com/ipfs/go-cid"
"github.com/multiformats/go-multihash"
"os"
)

func main() {
if len(os.Args) != 2 {
fmt.Println("Usage: commp-cid <file>")
os.Exit(1)
}

commp, err := hex.DecodeString(os.Args[1])
if err != nil {
panic(err)
}

mh, err := multihash.Encode(commp, multihash.SHA2_256_TRUNC254_PADDED)
if err != nil {
panic(err)
}

ccid := cid.NewCidV1(cid.FilCommitmentUnsealed, mh)

println(ccid.String())
Comment on lines +22 to +29

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rvagg this can now be replaced entirely with (untested)

Suggested change
mh, err := multihash.Encode(commp, multihash.SHA2_256_TRUNC254_PADDED)
if err != nil {
panic(err)
}
ccid := cid.NewCidV1(cid.FilCommitmentUnsealed, mh)
println(ccid.String())
ccid, err := commcid.DataCommitmentV1ToCID(commp)
if err != nil {
panic(err)
}
println(ccid.String())

}
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ require (
github.com/filecoin-project/filecoin-ffi v0.0.0-20191219131535-bb699517a590
github.com/filecoin-project/go-fil-markets v0.0.0-20200118022459-68964015978c
github.com/filecoin-project/go-sectorbuilder v0.0.1
github.com/ipfs/go-cid v0.0.5 // indirect
github.com/ipfs/go-cid v0.0.5
github.com/multiformats/go-multihash v0.0.14-0.20200513002122-6f1ea18f1da5
)

replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi

replace github.com/ipfs/go-cid => ../../ipfs/go-cid
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ github.com/multiformats/go-multihash v0.0.10 h1:lMoNbh2Ssd9PUF74Nz008KGzGPlfeV6w
github.com/multiformats/go-multihash v0.0.10/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
github.com/multiformats/go-multihash v0.0.13 h1:06x+mk/zj1FoMsgNejLpy6QTvJqlSt/BhLEy87zidlc=
github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
github.com/multiformats/go-multihash v0.0.14-0.20200513002122-6f1ea18f1da5 h1:uXE5KEUAQE+i1hAfEMbkWsdKrYv+bFJ7pHTH/OME2io=
github.com/multiformats/go-multihash v0.0.14-0.20200513002122-6f1ea18f1da5/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
github.com/multiformats/go-multistream v0.0.1/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg=
github.com/multiformats/go-multistream v0.1.0/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg=
github.com/multiformats/go-varint v0.0.1/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
Expand Down