seal static method

Future<Envelope> seal(
  1. RecordBase rec,
  2. PrivateKey privateKey
)

Creates a new envelope by marshaling the given RecordBase, placing the marshaled bytes inside an Envelope, and signing with the given private key.

Implementation

static Future<Envelope> seal(RecordBase rec, PrivateKey privateKey) async {
  final payload = await rec.marshalRecord();
  final domain = rec.domain();
  final payloadType = rec.codec();

  if (domain.isEmpty) {
    throw Exception('envelope domain must not be empty');
  }

  if (payloadType.isEmpty) {
    throw Exception('payloadType must not be empty');
  }

  final unsigned = _makeUnsigned(domain, Uint8List.fromList(payloadType), Uint8List.fromList(payload));
  final sig = await privateKey.sign(unsigned);

  return Envelope(
    publicKey: privateKey.publicKey,
    payloadType: Uint8List.fromList(payloadType),
    rawPayload: Uint8List.fromList(payload),
    signature: sig,
  );
}