PatchbayCatalogDigest.ofCommands constructor
PatchbayCatalogDigest.ofCommands(
- Object? commands
Digests the commands array of a catalog.
commands is whatever the catalog carries under that key; anything that
is not a list digests as an empty surface, because an App that declares
no commands and an App whose commands key is absent have the same
declared surface. A malformed list never reaches here: the host validates
the array before serving it, and a violated catalog gets no digest at
all.
Entries are canonicalised individually and then sorted as strings, so the digest is independent of the order the composition root happened to register in — reordering a registration list is not a capability change.
Implementation
factory PatchbayCatalogDigest.ofCommands(Object? commands) {
final List<Object?> rows = commands is List<Object?>
? commands
: const <Object?>[];
final List<String> canonical = <String>[
for (final Object? row in rows) patchbayCanonicalJson(row),
]..sort();
return PatchbayCatalogDigest(
algorithm: patchbayDigestAlgorithmSha256,
covers: const <String>[patchbayCatalogDigestScopeCommands],
value: crypto.sha256
.convert(utf8.encode('[${canonical.join(',')}]'))
.toString(),
);
}