seal method

String seal({
  1. required Map<String, Object?> bundle,
  2. String? channel,
  3. DVDevClientManifest? requires,
  4. int? sequence,
})

bundle sealed into an envelope.

A bundle with no version is given its content version. channel is the branch a dev server serves, or the OTA channel. sequence increases with every seal from the same key, so a device can refuse an older bundle replayed after a newer one.

Implementation

String seal({
  required Map<String, Object?> bundle,
  String? channel,
  DVDevClientManifest? requires,
  int? sequence,
}) {
  final Map<String, Object?> sealed = <String, Object?>{
    'version': bundle['version'] ?? dvDevClientBundleVersion(bundle),
    for (final MapEntry<String, Object?> e in bundle.entries)
      if (e.key != 'version') e.key: e.value,
  };
  final String payload = jsonEncode(<String, Object?>{
    'format': dvSignedBundleFormat,
    if (channel != null) 'channel': channel,
    if (sequence != null) 'sequence': sequence,
    if (requires != null) 'requires': requires.toJson(),
    'bundle': sealed,
  });
  final List<int> bytes = utf8.encode(payload);
  return jsonEncode(<String, Object?>{
    'format': dvSignedBundleFormat,
    'payload': dvWebPushBase64Encode(bytes),
    'signature': dvWebPushBase64Encode(sign(bytes)),
  });
}