requestIdOf function

RequestId requestIdOf(
  1. Map<String, dynamic> request
)

Get the RequestId of the provided ic-ref request. RequestId is the result of the representation-independent-hash function. https://sdk.dfinity.org/docs/interface-spec/index.html#hash-of-map @param request - ic-ref request to hash into RequestId

Implementation

RequestId requestIdOf(Map<String, dynamic> request) {
  final hashed =
      request.entries.where((element) => element.value != null).map((e) {
    final hashedKey = hashString(e.key);
    final hashedValue = hashValue(e.value);
    return [hashedKey, hashedValue];
  }).toList();

  hashed.sort((k1, k2) {
    return k1.compare(k2, (a, b) => a.compare(b, (c, d) => c - d));
  });

  var concatenated = u8aConcat(hashed.map((d) => u8aConcat(d)).toList());

  return RequestId.fromList(hash(concatenated));
}