sign static method

String sign({
  1. required String secret,
  2. required String appKey,
  3. required String userToken,
  4. required int timestamp,
  5. Map<String, dynamic>? raw,
  6. bool? isPaying,
  7. String? plan,
  8. num? mrr,
  9. String? currency,
})

Signs the payload using HMAC-SHA256 with secret.

Returns a 64-character lowercase hexadecimal digest.

Implementation

static String sign({
  required String secret,
  required String appKey,
  required String userToken,
  required int timestamp,
  Map<String, dynamic>? raw,
  bool? isPaying,
  String? plan,
  num? mrr,
  String? currency,
}) {
  if (secret.isEmpty) {
    throw ArgumentError.value(secret, 'secret', 'SDK signing secret cannot be empty');
  }
  final canonical = canonicalize(
    appKey: appKey,
    userToken: userToken,
    timestamp: timestamp,
    raw: raw,
    isPaying: isPaying,
    plan: plan,
    mrr: mrr,
    currency: currency,
  );
  final hmac = Hmac(sha256, utf8.encode(secret));
  final digest = hmac.convert(utf8.encode(canonical));
  return digest.toString();
}