sign function

Future sign(
  1. dynamic data,
  2. PairReturnType pair, [
  3. DefaultOptSignType? opt
])

Implementation

Future<dynamic> sign(dynamic data, PairReturnType pair,
    [DefaultOptSignType? opt]) async {
  opt ??= DEFAULT_OPTS;

  final json = parse(data);

  final encoding = opt.encode ?? DEFAULT_OPTS.encode;

  final checkData = opt.check ?? json;

  if (json != null &&
      (json.runtimeType == {}.runtimeType &&
          ((json.containsKey('s') && json.containsKey('m')) ||
              (json.containsKey(':') && json.containsKey('~')))) &&
      (await verify(data, pair) != null)) {
    final parsed = parse(checkData);
    if (opt.raw != null && opt.raw!) {
      return parsed;
    }

    return 'SEA${jsonEncode(parsed)}';
  }

  final hash = await hashForSignature(json);

  final sig = await signHash(hash, pair, encoding);

  final r = {'m': json, 's': sig};
  if (opt.raw != null && opt.raw!) {
    return r;
  }

  return 'SEA${jsonEncode(r)}';
}