open<T> function

T open<T>({
  1. required Uint8List msgToOpen,
  2. required Object? msgToAuth,
  3. required SecretKey recipient,
  4. required PublicKey sender,
  5. required Uint8List domain,
  6. int? maxDriftSecs,
})

Decrypts and verifies a sealed message.

Uses the current system time for drift checking, and openAt takes it from the caller instead.

  • msgToOpen: The serialized COSE_Encrypt0 structure
  • msgToAuth: The same additional authenticated data used during sealing
  • recipient: The xHPKE secret key to decrypt with
  • sender: The xDSA public key to verify the signature against
  • domain: Application domain for HPKE key derivation
  • maxDriftSecs: Maximum allowed timestamp difference in seconds, past or future. A value of n accepts differences up to and including n; null skips the check.

Returns the payload decoded by the cbor package, cast to T. Throws if maxDriftSecs is negative, if decryption fails as in decrypt, or if verification fails as in verify.

Implementation

T open<T>({
  required Uint8List msgToOpen,
  required Object? msgToAuth,
  required xhpke.SecretKey recipient,
  required xdsa.PublicKey sender,
  required Uint8List domain,
  int? maxDriftSecs,
}) =>
    _decode(
          ffi.coseOpen(
            msgToOpen: msgToOpen,
            msgToAuth: _encode(msgToAuth),
            recipient: recipient.inner,
            sender: sender.inner,
            domain: domain,
            maxDriftSecs: _drift(maxDriftSecs),
          ),
        )
        as T;