deriveFrom static method

Uint8List deriveFrom(
  1. Uint8List message,
  2. ECPrivateKey privateKey,
  3. ECPublicKey publicKey
)

Implementation

static Uint8List deriveFrom(
  Uint8List message,
  ECPrivateKey privateKey,
  ECPublicKey publicKey,
) {
  final ecdsaSigner = ECDSASigner(null, HMac(SHA256Digest(), 64));
  final normalizedECDSASigner = NormalizedECDSASigner(
    ecdsaSigner,
    enforceNormalized: true,
  );
  normalizedECDSASigner.init(true, PrivateKeyParameter(privateKey));

  final ecSignature =
      normalizedECDSASigner.generateSignature(message) as ECSignature;

  const bigIntEndian = BigIntBigEndian();
  final encR = bigIntEndian.encode(ecSignature.r);
  final encS = bigIntEndian.encode(ecSignature.s);

  // TODO: should we emit only fixed-length signatures?
  /*if (encR.length == 31 && encS.length == 31) {
    return ptutils.concatUint8List([
      encR,
      Uint8List.fromList([0, 0]),
      encS
    ]);
  }*/

  return _concatUint8List([encR, encS]);
}