fromBytes static method

Secp256k1Point fromBytes(
  1. List<int> data
)

Implementation

static Secp256k1Point fromBytes(List<int> data) {
  if (data.length == 1 && data[0] == 0x00) return identity_;
  if (data.length == 33 && _isZeroEncoding(data)) return identity_;
  if (data.length == 65 && _isZeroEncoding(data)) return identity_;
  if (data.length == 33) return fromCompressed(data);
  if (data.length == 65) return fromUncompressed(data);
  if (data.length == 64) {
    // Raw x||y has no infinity encoding: (0, 0) is rejected even though
    // the affine identity shares those coordinates.
    final p = Secp256k1AffinePoint(
      x: Secp256k1Fp.fromBytes(data.sublist(0, 32)),
      y: Secp256k1Fp.fromBytes(data.sublist(32, 64)),
    );
    if (p.isIdentity() || !p.isOnCurve()) {
      throw CoreErrors.invalidOperationArguments(
        "fromBytes",
        reason: "Not on curve.",
      );
    }
    return p.toCurve();
  }
  throw CoreErrors.invalidOperationArguments(
    "fromBytes",
    reason: "Invalid point encoding bytes length.",
  );
}