generateSignature method

String generateSignature(
  1. DateTime now
)

Generate signature required to authenticate with API using current datetime in UTC as now

Implementation

String generateSignature(DateTime now) {
  /// Generate the first set of SHA256 hmac from transaction token
  /// using the secret key as key
  var hmacSha256 = Hmac(sha256, utf8.encode(secretKey));
  var hash1 = hmacSha256.convert(utf8.encode(txToken));

  /// Generate the second set of SHA256 hmac from the account identifier
  /// using the fisrt hash as key
  var hmacSha256_2 = Hmac(sha256, hash1.bytes);
  var hash2 = hmacSha256_2.convert(utf8.encode(identifier));

  /// The epoch time which is used in generating the signature
  var epochTimeStamp = (now.millisecondsSinceEpoch / 1000).floor().toString();

  /// Generate the third and last set of SHA256 hmac from the epoch time
  /// using the second hash as key.
  /// Return hash as string
  var hmacSha256_3 = Hmac(sha256, hash2.bytes);
  var signature =
      hmacSha256_3.convert(utf8.encode(epochTimeStamp)).toString();

  return signature;
}