ClientEnvelope class abstract interface

Seals requests and opens responses for one service (ADR 0006).

All crypto, the canonical query and the binding are cratestack-cose's one Rust implementation, reached over flutter_rust_bridge on native platforms and a wasm-bindgen build on the web. There is no Dart reimplementation.

final envelope = await ClientEnvelope.create(
  signer: HmacSigner(CoseAlg.hmac256x64, secret),
  serverKeys: [CoseServerKey.hmac(CoseAlg.hmac256x64, secret)],
  audience: 'payments',
);
final sealed = await envelope.sealRequest(payload, binding);
// POST `sealed` with Content-Type: envelope.mediaType and
// Cratestack-Contract: ClientEnvelope.contractHeaderValue(sha) ...
final opened = await envelope.openResponse(
  responseBody,
  binding: binding,
  sealedRequest: sealed,
  status: 200,
);

Every failure is a CoseException.

Available extensions

Properties

hashCode → int
The hash code for this object.
no setterinherited
kid → Uint8List
The signer's 8-byte kid.
no setter
mediaType → String
The Content-Type (and Accept) of sealed bodies.
no setter
mode → CoseMode
COSE_Sign1 or COSE_Mac0.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
openResponse(Uint8List body, {required CallBinding binding, required Uint8List sealedRequest, required int status}) → Future<Opened>
Opens the response body to sealedRequest (the exact bytes that were sent), which came back with HTTP status.
sealRequest(Uint8List payload, CallBinding binding) → Future<Uint8List>
Seals payload (already CBOR) as the request binding describes. Resolves to the bytes to send.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

contractHeaderValue(Uint8List contractSha) → String
The Cratestack-Contract header value for an op contract digest (32 bytes): 11 characters of unpadded base64url. The header is not bound; it tells a server that accepts several digests which one the request was sealed under.
create({required CoseSigner signer, required List<CoseServerKey> serverKeys, required String audience}) → Future<ClientEnvelope>
An envelope for audience (the configured name of the service, never its host) that signs with signer and opens responses with serverKeys, and starts the backend if nothing has yet.