newFromCompressed static method

Signature newFromCompressed(
  1. Uint8List buf
)

Create a Signature from a compressed Signature Buffer @param {Uint8List} buf - Buffer containing a signature @returns {Signature} Object signature

Implementation

static Signature newFromCompressed(Uint8List buf) {
  if (buf.length != 64) {
    throw new ArgumentError('buf must be 64 bytes');
  }
  CircomLib circomLib = CircomLib();
  final signature =
      circomLib.unpackSignature(Uint8ArrayUtils.uint8ListToString(buf));
  final bufSignature = Uint8ArrayUtils.uint8ListfromString(signature);
  final xList = bufSignature.sublist(0, 16);
  final yList = bufSignature.sublist(16, 32);
  final rSList = bufSignature.sublist(32, 64);
  final xPtr = Uint8ArrayUtils.toPointer(xList);
  final yPtr = Uint8ArrayUtils.toPointer(yList);
  final sPtr = Uint8ArrayUtils.toPointer(rSList);
  final Structs.Point point = Structs.Point.allocate(xPtr, yPtr);

  final pointPtr = point.address;
  final Structs.Signature sig = Structs.Signature.allocate(pointPtr, sPtr);
  if (sig.r_b8 == null) {
    throw new ArgumentError('unpackSignature failed');
  }
  BigInt x = Uint8ArrayUtils.leBuff2int(xList);
  BigInt y = Uint8ArrayUtils.leBuff2int(yList);
  List<BigInt> r8 = [];
  r8.add(x);
  r8.add(y);

  BigInt s =
      Uint8ArrayUtils.leBuff2int(Uint8ArrayUtils.fromPointer(sig.s!, 32));
  //calloc.free(pointPtr);
  return new Signature(r8, s);
}