Secp256k1KeyIdentity.fromJSON constructor

Secp256k1KeyIdentity.fromJSON(
  1. String json
)

Implementation

factory Secp256k1KeyIdentity.fromJSON(String json) {
  final parsed = jsonDecode(json);
  if (parsed is List) {
    if (parsed[0] is String && parsed[1] is String) {
      return Secp256k1KeyIdentity.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
        ? Secp256k1PublicKey.fromRaw(Uint8List.fromList(publicKey.data))
        : Secp256k1PublicKey.fromDer(Uint8List.fromList(dashPublicKey.data));

    if (publicKey && secretKey && secretKey.data) {
      return Secp256k1KeyIdentity(pk, Uint8List.fromList(secretKey.data));
    }
    if (dashPublicKey && dashPrivateKey && dashPrivateKey.data) {
      return Secp256k1KeyIdentity(
        pk,
        Uint8List.fromList(dashPrivateKey.data),
      );
    }
  }
  throw ArgumentError.value(jsonEncode(json), 'json', 'Invalid json');
}