loadWorldCertification function

WorldCertification? loadWorldCertification(
  1. String worldsDir,
  2. String scenario
)

Load the committed certification receipt for scenario under worldsDir. Returns null when absent (never certified).

Implementation

WorldCertification? loadWorldCertification(String worldsDir, String scenario) {
  final file = File(p.join(worldsDir, '$scenario.cert.json'));
  if (!file.existsSync()) return null;
  try {
    final doc = jsonDecode(file.readAsStringSync());
    if (doc is! Map<String, dynamic>) return null;
    return WorldCertification(
      scenario: doc['scenario'] as String? ?? '',
      worldHash: doc['world_hash'] as String? ?? '',
      certified: doc['certified'] as bool? ?? false,
      proofs: (doc['methods'] as List? ?? const [])
          .map(
            (m) => WorldMethodProof(
              touchpoint: (m as Map)['touchpoint'] as String? ?? '',
              method: m['method'] as String? ?? '',
              satisfied: m['satisfied'] as bool? ?? false,
              evidence: m['evidence'] as String? ?? '',
            ),
          )
          .toList(growable: false),
      at: doc['at'] as String? ?? '',
    );
  } on FormatException {
    return null;
  }
}