calculateShareKey method

Future<List<int>> calculateShareKey(
  1. Map<String, Object?> KeySet
)

Implementation

Future<List<int>> calculateShareKey(Map<String, Object?>  KeySet) async {
  var xpub = KeySet["X"] as String;
  var ypub = KeySet["Y"] as String;

  var xpub1 = base64Decode(base64.normalize(xpub));
  var ypub1 = base64Decode(base64.normalize(ypub));

  var xpub2 = hex.encode(xpub1);
  var ypub2 = hex.encode(ypub1);

  var curve = getSecp256r1();
  var p = AffinePoint.fromXY(
      BigInt.parse(xpub2, radix: 16), BigInt.parse(ypub2, radix: 16));

  var publicServer = PublicKey.fromPoint(curve, p);
  var privateClient = KeySet["priv"] as PrivateKey;
  var secretKey = computeSecret(privateClient, publicServer);
  final algorithm = cry.Sha256();
  final hash = await algorithm.hash(secretKey);

  // print("SHAREDKEY => "+base64.encode(hash.bytes));

  return hash.bytes;
}