baseid-transport
Transport-layer abstractions for BaseID credential exchange. Provides injectable, async transport traits for HTTP, DIDComm message delivery, BLE proximity presentation (ISO 18013-5), and NFC contactless exchange. All traits are designed for dependency injection so tests can swap in mock implementations without hitting real networks.
Key Features
Section titled “Key Features”- HttpClient Trait — Async HTTP with
get_json,post_form,post_json,post_json_bearer, and raw request methods - ReqwestHttpClient — Production backend powered by
reqwest(enabled viahttp-reqwestfeature flag) - MockHttpClient — Configurable mock for testing with
on_get(url, response)andon_post(url, response)builders - DIDCommTransport — Send packed DIDComm messages to service endpoints;
HttpDIDCommTransportfor HTTP delivery - BleTransport — ISO 18013-5 proximity presentation with Peripheral/Central roles, device engagement, and chunked data transfer
- NfcTransport — Contactless exchange via NDEF records or ISO 7816 APDU commands
Quick Start
Section titled “Quick Start”use baseid_transport::{HttpClient, MockHttpClient};use serde_json::json;
// Production: use ReqwestHttpClient#[cfg(feature = "http-reqwest")]let client = baseid_transport::ReqwestHttpClient::new();
// Testing: use MockHttpClient with pre-configured responseslet client = MockHttpClient::new() .on_get( "https://issuer.example.com/.well-known/openid-credential-issuer", json!({"credential_issuer": "https://issuer.example.com"}), ) .on_post( "https://issuer.example.com/token", json!({"access_token": "tok_123", "token_type": "bearer"}), );
// Protocol crates accept `impl HttpClient`let metadata = client.get_json( "https://issuer.example.com/.well-known/openid-credential-issuer").await?;HTTP Client
Section titled “HTTP Client”The HttpClient trait is used by OID4VCI, OID4VP, SIOPv2, and DID resolution:
| Method | Description |
|---|---|
get_json(url) | GET request, parse JSON response |
post_form(url, params) | POST with form-encoded body, parse JSON |
post_json(url, body) | POST with JSON body (no auth) |
post_json_bearer(url, body, token) | POST with JSON body and Bearer token |
get(url) | Raw GET returning HttpResponse |
post_raw(url, body, content_type) | Raw POST with bytes body |
DIDComm Transport
Section titled “DIDComm Transport”Deliver packed DIDComm messages to service endpoints:
use baseid_transport::didcomm::{HttpDIDCommTransport, DIDCommTransport};
let transport = HttpDIDCommTransport::new(client);let receipt = transport.send_message( "https://agent.example.com/didcomm", packed_message_bytes,).await?;// receipt.status == 202, receipt.message_id extracted from JWMBLE Transport (ISO 18013-5)
Section titled “BLE Transport (ISO 18013-5)”Proximity-based credential presentation over Bluetooth Low Energy:
use baseid_transport::ble::*;
let mut transport = MockBleTransport::new();let engagement = BleEngagement { service_uuid: "0000abcd-0000-1000-8000-00805f9b34fb".to_string(), role: BleRole::Peripheral, engagement_bytes: device_engagement_cbor,};
transport.start(&engagement).await?;transport.send(b"mdoc-request").await?;let response = transport.receive().await?;transport.disconnect().await?;NFC Transport
Section titled “NFC Transport”Contactless exchange via NDEF records or ISO 7816 APDU:
use baseid_transport::nfc::*;
let transport = MockNfcTransport::new();
// NDEF mode: write/read recordstransport.write_ndef(&NdefRecord { record_type: "U".to_string(), payload: b"https://issuer.example.com/offer".to_vec(),}).await?;
// APDU mode: ISO 7816 command/responselet cmd = ApduCommand { cla: 0x00, ins: 0xA4, p1: 0x04, p2: 0x00, data: vec![0xA0, 0x00, 0x00, 0x02, 0x48, 0x04, 0x00], le: 0 };let resp = transport.transceive_apdu(&cmd).await?;assert!(resp.is_success()); // SW1=0x90, SW2=0x00Feature Flags
Section titled “Feature Flags”| Feature | Default | Description |
|---|---|---|
http-reqwest | Yes | Enables ReqwestHttpClient production backend |
Key Types
Section titled “Key Types”| Type | Description |
|---|---|
HttpClient | Async HTTP trait for all protocol network requests |
ReqwestHttpClient | Production HTTP client backed by reqwest |
MockHttpClient | Test mock with on_get/on_post response configuration |
HttpResponse | Status, headers, body with json(), text(), is_success() |
DIDCommTransport | Trait for DIDComm message delivery and receive |
HttpDIDCommTransport | HTTP-based DIDComm delivery (application/didcomm-encrypted+json) |
BleTransport | Trait for BLE proximity exchange (start, send, receive, disconnect) |
BleEngagement | Device engagement with service UUID, role, and CBOR bytes |
NfcTransport | Trait for NFC exchange (NDEF read/write, APDU transceive) |
MockBleTransport | Test BLE transport with queue_incoming/sent_data |
MockNfcTransport | Test NFC transport with queue_ndef/queue_apdu_response |
Related Crates
Section titled “Related Crates”baseid-oid4vci— UsesHttpClientfor issuer metadata discovery and token exchangebaseid-didcomm— Message packing/signing, delivered viaDIDCommTransportbaseid-siop— UsesHttpClientfor cross-device direct_post flowbaseid-did— DID resolution over HTTP