1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00
any-sync/util/cidutil/cid.go
2023-01-05 15:34:09 +03:00

22 lines
470 B
Go

package cidutil
import (
"github.com/ipfs/go-cid"
mh "github.com/multiformats/go-multihash"
)
func NewCidFromBytes(data []byte) (string, error) {
hash, err := mh.Sum(data, mh.SHA2_256, -1)
if err != nil {
return "", err
}
return cid.NewCidV1(cid.DagCBOR, hash).String(), nil
}
func VerifyCid(data []byte, id string) bool {
hash, err := mh.Sum(data, mh.SHA2_256, -1)
if err != nil {
return false
}
return cid.NewCidV1(cid.DagCBOR, hash).String() == id
}