secp256k1ECkeyPubkeySerialize static method

List<int>? secp256k1ECkeyPubkeySerialize(
  1. Secp256k1Ge elem,
  2. bool compressed
)

convert ge to public key

Implementation

static List<int>? secp256k1ECkeyPubkeySerialize(
    Secp256k1Ge elem, bool compressed) {
  if (Secp256k1.secp256k1GeIsInfinity(elem) == 1) {
    return null;
  }
  List<int> pub = List<int>.filled(32, 0);
  Secp256k1.secp256k1FeNormalizeVar(elem.x);
  Secp256k1.secp256k1FeNormalizeVar(elem.y);
  Secp256k1.secp256k1FeGetB32(pub, elem.x);
  const int tagPkeyEven = 0x02;
  const int tagPkeyOdd = 0x03;
  const int tagPkeyUncompressed = 0x04;
  int tag;
  if (compressed) {
    final tag =
        Secp256k1.secp256k1FeIsOdd(elem.y) == 1 ? tagPkeyOdd : tagPkeyEven;
    return [tag, ...pub];
  } else {
    tag = tagPkeyUncompressed;
    List<int> unCompressedPart = List<int>.filled(32, 0);
    Secp256k1.secp256k1FeGetB32(unCompressedPart, elem.y);
    return [tag, ...pub, ...unCompressedPart];
  }
}