newFromCompressed static method

PublicKey newFromCompressed(
  1. BigInt compressedBigInt
)

Create a PublicKey from a bigInt compressed pubKey

@param {BigInt} compressedBigInt - compressed public key in a bigInt

@returns {PublicKey} public key class

Implementation

static PublicKey newFromCompressed(BigInt compressedBigInt) {
  final Uint8List compressedBuffLE =
      Uint8ArrayUtils.leInt2Buff(compressedBigInt, 32);
  if (compressedBuffLE.length != 32) {
    throw new ArgumentError('buf must be 32 bytes');
  }
  CircomLib circomLib = CircomLib();
  final p = circomLib
      .unpackPoint(Uint8ArrayUtils.uint8ListToString(compressedBuffLE));
  if (p == null) {
    throw new ArgumentError('unpackPoint failed');
  }
  BigInt x = BigInt.parse(p[0]);
  BigInt y = BigInt.parse(p[1]);
  List<BigInt> point = [];
  point.add(x);
  point.add(y);
  return new PublicKey(point);
}