fromJSON static method

Secp256k1KeyIdentity fromJSON(
  1. String json
)

Implementation

static Secp256k1KeyIdentity fromJSON(String json) {
  final parsed = jsonDecode(json);
  if (parsed is List) {
    if (parsed[0] is String && parsed[1] is String) {
      return fromParsedJson([parsed[0], parsed[1]]);
    }
    throw 'Deserialization error: JSON must have at least 2 items.';
  } else if (parsed is Map) {
    var publicKey = parsed["publicKey"];
    var _publicKey = parsed["_publicKey"];
    var secretKey = parsed["secretKey"];
    var _privateKey = parsed["_privateKey"];
    final pk = publicKey != null
        ? Secp256k1PublicKey.fromRaw(Uint8List.fromList(publicKey.data))
        : Secp256k1PublicKey.fromDer(Uint8List.fromList(_publicKey.data));

    if (publicKey && secretKey && secretKey.data) {
      return Secp256k1KeyIdentity(pk, Uint8List.fromList(secretKey.data));
    }
    if (_publicKey && _privateKey && _privateKey.data) {
      return Secp256k1KeyIdentity(pk, Uint8List.fromList(_privateKey.data));
    }
  }
  throw "Deserialization error: Invalid JSON type for string: ${jsonEncode(json)}";
}