createCid static method
Creates a cid
v1
that is compliant with IPFS standards
The returned cid
consists of a sha2-256
multihash, a raw
multicodec and base encoded either 32 or 58.
Implementation
static CIDInfo createCid(String text, Multibase base) {
// Create multihash
MultihashInfo multihashInfo = createMultihash(text);
Uint8List multihashBytesArray = multihashInfo.toBytes();
// Adding suffixes to multihash
// Currently, the suffix consists of version 1 and `raw` multicodec.
int version = 0x01;
int codecCode = 0x55;
Uint8List suffixedMultihash = addSuffixToMultihash(multihashBytesArray, version, codecCode);
var codecObj = MultiCodecs.list().where((element) => element.code == codecCode).first;
String cidString = encodeInputMultihashWithBase(base, suffixedMultihash);
// Creating CIDInfo object to return
CIDInfo cidInfo = CIDInfo(
multihashInfo: multihashInfo, multicodecName: codecObj.name, multicodecCode: codecCode, multibase: base, version: version, cid: cidString);
return cidInfo;
}