Skip to content

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.

  • 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 via http-reqwest feature flag)
  • MockHttpClient — Configurable mock for testing with on_get(url, response) and on_post(url, response) builders
  • DIDCommTransport — Send packed DIDComm messages to service endpoints; HttpDIDCommTransport for 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
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 responses
let 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?;

The HttpClient trait is used by OID4VCI, OID4VP, SIOPv2, and DID resolution:

MethodDescription
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

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 JWM

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?;

Contactless exchange via NDEF records or ISO 7816 APDU:

use baseid_transport::nfc::*;
let transport = MockNfcTransport::new();
// NDEF mode: write/read records
transport.write_ndef(&NdefRecord {
record_type: "U".to_string(),
payload: b"https://issuer.example.com/offer".to_vec(),
}).await?;
// APDU mode: ISO 7816 command/response
let 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=0x00
FeatureDefaultDescription
http-reqwestYesEnables ReqwestHttpClient production backend
TypeDescription
HttpClientAsync HTTP trait for all protocol network requests
ReqwestHttpClientProduction HTTP client backed by reqwest
MockHttpClientTest mock with on_get/on_post response configuration
HttpResponseStatus, headers, body with json(), text(), is_success()
DIDCommTransportTrait for DIDComm message delivery and receive
HttpDIDCommTransportHTTP-based DIDComm delivery (application/didcomm-encrypted+json)
BleTransportTrait for BLE proximity exchange (start, send, receive, disconnect)
BleEngagementDevice engagement with service UUID, role, and CBOR bytes
NfcTransportTrait for NFC exchange (NDEF read/write, APDU transceive)
MockBleTransportTest BLE transport with queue_incoming/sent_data
MockNfcTransportTest NFC transport with queue_ndef/queue_apdu_response
  • baseid-oid4vci — Uses HttpClient for issuer metadata discovery and token exchange
  • baseid-didcomm — Message packing/signing, delivered via DIDCommTransport
  • baseid-siop — Uses HttpClient for cross-device direct_post flow
  • baseid-did — DID resolution over HTTP