fromContent static method
Creates a CID by hashing data with the given hashType.
The codec defaults to raw and version defaults to 1. Only
sha2-256 is currently supported as hashType.
Implementation
static Future<CID> fromContent(
Uint8List data, {
String codec = 'raw',
String hashType = 'sha2-256',
int version = 1,
}) async {
if (hashType != 'sha2-256') {
throw UnsupportedError('Hash type $hashType not supported');
}
final digest = sha256.convert(data).bytes;
final mh = MultihashUtils.encode(hashType, Uint8List.fromList(digest));
if (version == 0) {
return CID.v0(Uint8List.fromList(digest));
}
return CID.v1(codec, mh);
}