Skip to content

An old secp256k1 keypair string created by ver ^1.0.1 can not parse to key in ver 4.0.0 #255

Description

@ipconfiger

compressed public key: "02abd0411432f201a5dbc3320f9a3ea1a99f15ca90431c147c11dde9f8da4c5029"
got Exception:"Invalid point compression"

Invalid point compression pubkey=02abd0411432f201a5dbc3320f9a3ea1a99f15ca90431c147c11dde9f8da4c5029
flutter: #0      ECCurve.decompressPoint (package:pointycastle/ecc/ecc_fp.dart:356:7)
flutter: #1      ECCurveBase.decodePoint (package:pointycastle/ecc/ecc_base.dart:215:13)
flutter: #2      loadPublicKey (package:secp256k1cipher/src/secp256k1Cipher.dart:158:27)

I use next code to make hex String pubkey to an ECPublicKey.

ECPublicKey loadPublicKey(String storedkey) {
  final param = ECCurve_secp256k1();
  if (storedkey.length < 120) {
    var code_list = <int>[];
    for (var _idx = 0; _idx < storedkey.length - 1; _idx += 2) {
      final hex_str = storedkey.substring(_idx, _idx + 2);
      code_list.add(int.parse(hex_str, radix: 16));
    }
    final Q = param.curve.decodePoint(code_list);
    return ECPublicKey(Q, param);
  } else {
    final x = BigInt.parse(storedkey.substring(0, 64), radix: 16);
    final y = BigInt.parse(storedkey.substring(64), radix: 16);
    final Q = param.curve.createPoint(x, y);
    return ECPublicKey(Q, param);
  }
}

it works fine on old version, and new version, but if pass a pub key string in parameter storedkey, it comes an Exception

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions