constructSetFingerprint function
Stable identity for a set of constructs (ignores absolute package paths).
Implementation
String constructSetFingerprint(
List<ConstructYaml> constructs, {
String? sdkVersion,
}) {
final parts = <String>[
for (final yaml in constructs)
[
yaml.packageName,
yaml.packageUri,
for (final c in yaml.constructs)
'${c.name}:${c.method}:${c.isServer}:${c.isBuild}:${c.optIn}',
].join(';'),
]..sort();
final payload = '${parts.join('|')}|${sdkVersion ?? io.Platform.version}';
// FNV-1a 64-bit — stable across isolates, no crypto dependency.
// Use BigInt so the offset/prime are exact (avoid_js_rounded_ints).
var hash = BigInt.parse('cbf29ce484222325', radix: 16);
final prime = BigInt.parse('100000001b3', radix: 16);
final mask = (BigInt.one << 64) - BigInt.one;
for (final unit in utf8.encode(payload)) {
hash ^= BigInt.from(unit);
hash = (hash * prime) & mask;
}
return hash.toRadixString(16).padLeft(16, '0');
}