ic_data_hash function
Computes the representation-independent-hash of the data.
Implementation
Uint8List ic_data_hash(dynamic datastructure) {
//print(datastructure);
//print(datastructure.runtimeType);
var valueforthehash = <int>[];
if (datastructure is String) {
valueforthehash = utf8.encode(datastructure); }
else if (datastructure is int || datastructure is BigInt) {
valueforthehash = leb128.encodeUnsigned(datastructure); }
else if (datastructure is Uint8List) {
valueforthehash= datastructure; }
else if (datastructure is List) {
valueforthehash= datastructure.fold(<int>[], (p,c)=> p + ic_data_hash(c)); }
else if (datastructure is Map) {
List<List<int>> datafieldshashs = [];
for (String key in datastructure.keys) {
List<int> fieldhash = [];
fieldhash.addAll(sha256.convert(ascii.encode(key)).bytes);
fieldhash.addAll(ic_data_hash(datastructure[key]));
datafieldshashs.add(fieldhash);
}
datafieldshashs.sort((a,b) => bytes_as_the_bitstring(a).compareTo(bytes_as_the_bitstring(b)));
valueforthehash = datafieldshashs.fold(<int>[],(p,c)=>p+c); }
else {
throw Exception('ic_data_hash: check: type of the datastructure: ${datastructure.runtimeType}');
}
return Uint8List.fromList(sha256.convert(valueforthehash).bytes);
}