Documentation
¶
Overview ¶
Package commcid provides helpers to convert between Piece/Data/Replica Commitments and their CID representation
Index ¶
- Constants
- Variables
- func CIDToCommitment(c cid.Cid) (multicodec.Code, multicodec.Code, []byte, error)deprecated
- func CIDToDataCommitmentV1(c cid.Cid) ([]byte, error)
- func CIDToReplicaCommitmentV1(c cid.Cid) ([]byte, error)
- func CommitmentToCID(mc multicodec.Code, mh multicodec.Code, commX []byte) (cid.Cid, error)
- func DataCommitmentToPieceCidv2(commD []byte, PayloadSize uint64) (cid.Cid, error)
- func DataCommitmentV1ToCID(commD []byte) (cid.Cid, error)
- func PayloadSizeToV1TreeHeightAndPadding(dataSize uint64) (uint8, uint64, error)
- func PieceCidV1FromV2(pcidV2 cid.Cid) (cid.Cid, uint64, error)
- func PieceCidV2FromV1(v1PieceCid cid.Cid, payloadsize uint64) (cid.Cid, error)
- func PieceCidV2ToDataCommitment(c cid.Cid) ([]byte, uint64, error)
- func ReplicaCommitmentV1ToCID(commR []byte) (cid.Cid, error)
- type FilMultiCodec
- type FilMultiHash
Constants ¶
const FILCODEC_UNDEFINED = FilMultiCodec(0)
FILCODEC_UNDEFINED is just a signifier for "no codec determined
const FILMULTIHASH_UNDEFINED = FilMultiHash(0)
FILMULTIHASH_UNDEFINED is a signifier for "no multihash etermined"
Variables ¶
var ( // ErrIncorrectCodec means the codec for a CID is a block format that does not match // a commitment hash ErrIncorrectCodec = errors.New("unexpected commitment codec") // ErrIncorrectHash means the hash function for this CID does not match the expected // hash for this type of commitment ErrIncorrectHash = errors.New("incorrect hashing function for data commitment") )
var CIDToPieceCommitmentV1 = CIDToDataCommitmentV1
CIDToPieceCommitmentV1 converts a CID to a commP -- it is just a helper function that is equivalent to CIDToDataCommitmentV1.
var PieceCommitmentV1ToCID = DataCommitmentV1ToCID
PieceCommitmentV1ToCID converts a commP to a CID -- it is just a helper function that is equivalent to DataCommitmentV1ToCID.
Functions ¶
func CIDToCommitment
deprecated
func CIDToCommitment(c cid.Cid) (multicodec.Code, multicodec.Code, []byte, error)
CIDToCommitment extracts the raw commitment bytes, the FilMultiCodec and FilMultiHash from a CID, after validating that the codec and hash type are consistent
Deprecated: Use the alternatives like CIDToReplicaCommitmentV1, CIDToDataCommitmentV1 or PieceCidV2ToDataCommitment
func CIDToDataCommitmentV1 ¶
CIDToDataCommitmentV1 extracts the raw data commitment from a CID after checking for the correct codec and hash types.
func CIDToReplicaCommitmentV1 ¶
CIDToReplicaCommitmentV1 extracts the raw replica commitment from a CID after checking for the correct codec and hash types.
func CommitmentToCID ¶
func CommitmentToCID(mc multicodec.Code, mh multicodec.Code, commX []byte) (cid.Cid, error)
CommitmentToCID converts a raw commitment hash to a CID by adding: - the given filecoin codec type - the given filecoin hash type Deprecated: Use the alternatives like ReplicaCommitmentV1ToCID, DataCommitmentV1ToCID or DataCommitmentV1ToCID
func DataCommitmentToPieceCidv2 ¶ added in v0.3.0
DataCommitmentToPieceCidv2 converts a raw data commitment and the height of the commitment tree (i.e. log_2(padded data size in bytes) - 5, because 2^5 is 32 bytes which is the leaf node size) to a CID by adding: - codec: cid.Raw - hash type: multihash.SHA2_256_TRUNC254_PADDED_BINARY_TREE
The helpers payloadsizeToV1TreeHeight and Fr32PaddedSizeToV1TreeHeight may help in computing tree height
func DataCommitmentV1ToCID ¶
DataCommitmentV1ToCID converts a raw data commitment to a CID by adding: - codec: cid.FilCommitmentUnsealed - hash type: multihash.SHA2_256_TRUNC254_PADDED
func PayloadSizeToV1TreeHeightAndPadding ¶ added in v0.3.0
PayloadSizeToV1TreeHeightAndPadding calculates the height of the piece tree given the data that's meant to be encoded in the tree before any FR32 padding is applied. Because pieces are only defined on binary trees of FR32 encoded data if the size is not a power of 2 after the FR32 padding is applied it will be rounded up to the next one under the assumption that the rest of the tree will be padded out (e.g. with zeros). The amount of data padding that is needed to be applied is returned alongside the tree height.
func PieceCidV1FromV2 ¶ added in v0.3.0
PieceCidV1FromV2 takes a piece multihash CID and produces a v1 piece CID along with the payloadsize
func PieceCidV2FromV1 ¶ added in v0.3.0
PieceCidV2FromV1 takes a v1 piece CID and the CommP tree height and produces a piece multihash CID
The helpers payloadsizeToV1TreeHeight and Fr32PaddedSizeToV1TreeHeight may help in computing tree height
func PieceCidV2ToDataCommitment ¶ added in v0.3.0
PieceCidV2ToDataCommitment extracts the raw data commitment and payloadsize data size from the CID
Types ¶
type FilMultiCodec ¶
type FilMultiCodec uint64
FilMultiCodec is a uint64-sized type representing a Filecoin-specific codec
type FilMultiHash ¶
type FilMultiHash uint64
FilMultiHash is a uint64-sized type representing a Filecoin-specific multihash