TrustKey.fromJson constructor
TrustKey.fromJson(
- Map value
Implementation
factory TrustKey.fromJson(Map value) {
final encoded = value['publicKey'];
if (encoded is! String) {
throw const FormatException('Trust key publicKey missing');
}
final bytes = base64Decode(encoded);
if (bytes.length != 32 || value['algorithm'] != 'Ed25519') {
throw const FormatException('Invalid Ed25519 trust key');
}
final expected = 'sha256:${sha256.convert(bytes)}';
if (value['fingerprint'] != expected) {
throw const FormatException('Trust key fingerprint mismatch');
}
final status = value['status'];
if (status != 'active' && status != 'revoked') {
throw const FormatException('Invalid trust key status');
}
return TrustKey(
signerId: value['signerId'] as String,
keyId: value['keyId'] as String,
algorithm: value['algorithm'] as String,
publicKey: bytes,
fingerprint: value['fingerprint'] as String,
usages: (value['usages'] as List? ?? const [])
.whereType<String>()
.toSet(),
status: status as String,
);
}