P256Identity.fromJSON constructor
P256Identity.fromJSON(
- String json
Implementation
factory P256Identity.fromJSON(String json) {
final parsed = jsonDecode(json);
if (parsed is List) {
if (parsed[0] is String && parsed[1] is String) {
return P256Identity.fromParsedJson([parsed[0], parsed[1]]);
}
throw ArgumentError.value(
json,
'json',
'JSON must have at least 2 elements',
);
} else if (parsed is Map) {
final publicKey = parsed['publicKey'];
final dashPublicKey = parsed['_publicKey'];
final secretKey = parsed['secretKey'];
final dashPrivateKey = parsed['_privateKey'];
final pk = publicKey != null
? P256PublicKey.fromRaw(Uint8List.fromList(publicKey.data))
: P256PublicKey.fromDer(Uint8List.fromList(dashPublicKey.data));
if (publicKey && secretKey && secretKey.data) {
return P256Identity(pk, Uint8List.fromList(secretKey.data));
}
if (dashPublicKey && dashPrivateKey && dashPrivateKey.data) {
return P256Identity(
pk,
Uint8List.fromList(dashPrivateKey.data),
);
}
}
throw ArgumentError.value(jsonEncode(json), 'json', 'Invalid json');
}