wcDeserialize function

WcEnvelope wcDeserialize(
  1. String encoded
)

Parse a base64 WC envelope into its components.

Implementation

WcEnvelope wcDeserialize(String encoded) {
  final bytes = base64.decode(_padBase64(encoded));
  final type = bytes[0];
  var index = 1;
  Uint8List? senderPublicKey;
  if (type == 1) {
    senderPublicKey =
        Uint8List.fromList(bytes.sublist(index, index + _keyLength));
    index += _keyLength;
  }
  final iv = Uint8List.fromList(bytes.sublist(index, index + _ivLength));
  final sealed = Uint8List.fromList(bytes.sublist(index + _ivLength));
  return WcEnvelope(
    type: type,
    senderPublicKey: senderPublicKey,
    iv: iv,
    sealed: sealed,
  );
}