fromJSON static method
Implementation
static Ed25519KeyIdentity fromJSON(String json) {
final parsed = jsonDecode(json);
if ((parsed is List)) {
if (parsed[0] is String && parsed[1] is String) {
return Ed25519KeyIdentity.fromParsedJson([parsed[0], parsed[1]]);
} else {
throw 'Deserialization error: JSON must have at least 2 items.';
}
} else if (parsed is Map) {
final reParsed = Map<String, List>.from(jsonDecode(json));
var publicKey = reParsed["publicKey"];
var _publicKey = reParsed["_publicKey"];
var secretKey = reParsed["secretKey"];
var _privateKey = reParsed["_privateKey"];
final pk = publicKey != null
? Ed25519PublicKey.fromRaw(
Uint8List.fromList(List<int>.from(publicKey)))
: Ed25519PublicKey.fromDer(
Uint8List.fromList(List<int>.from(_publicKey!)));
if (publicKey != null && secretKey != null) {
return Ed25519KeyIdentity(
pk, Uint8List.fromList(List<int>.from(secretKey)));
} else if (_publicKey != null && _privateKey != null) {
return Ed25519KeyIdentity(
pk, Uint8List.fromList(List<int>.from(_privateKey)));
}
}
throw 'Deserialization error: Invalid JSON type for string: ${jsonEncode(json)}';
}