hashValue function
Implementation
BinaryBlob hashValue(dynamic value) {
if (value is String) {
return hashString(value);
} else if (value is num) {
return hash(lebEncode(value));
} else if (value is Uint8List) {
return hash(value);
} else if (value is Uint8Buffer) {
return hash(Uint8List.fromList(value));
} else if (value is List && (value is! Uint8List)) {
final vals = value.map(hashValue).toList();
return hash(concat(vals));
} else if (value is Principal) {
return hash(value.toUint8List());
} else if (value is ToHashable) {
return hashValue(value.toHash());
// TODO: This should be move to a specific async method as the webauthn flow required
// the flow to be synchronous to ensure Safari touch id works.
// } else if (value instanceof Promise) {
// return value.then(x => hashValue(x));
} else if (value is BigInt) {
// Do this check much later than the other bigint check because this one is much less
// type-safe.
// So we want to try all the high-assurance type guards before this 'probable' one.
return hash(lebEncode(value));
} else if (value is Expiry) {
return hashValue(value.toHash());
} else if (value is ByteBuffer) {
return hashValue(value.asUint8List());
}
throw UnsupportedError(
'Attempt to hash a value of unsupported type: $value.',
);
}