Skip to content
Exchange Protocol

Exchange Protocol

"BSP defines the format of the conversation. What each system does with it is their responsibility."

Overview

The Exchange Protocol defines how biological data moves between systems — the format of requests and responses, the full set of typed operations (intents), error handling, and the double authentication model.

The Exchange Protocol defines:

  • Schema of BSPRequest and BSPResponse
  • Types of BSPIntent and their parameters
  • Authentication via ConsentToken + IEO signature
  • All error codes

The Exchange Protocol does NOT define:

  • What systems do with received data
  • Analysis or scoring algorithms (e.g., AVA, SVA)
  • Transport infrastructure (HTTP, WebSocket, etc.)

Request / Response Model

Every interaction is a BSPRequestBSPResponse cycle.

BSPRequest Schema

typescript
interface BSPRequest {
  request_id:  string      // UUID v4 — unique per request (idempotency)
  bsp_version: string      // Protocol version (semver) — e.g., "1.0.0"
  timestamp:   string      // ISO8601

  requester: {
    ieo_id:    string      // Institution's UUID
    ieo_domain:string      // e.g., "fleury.bsp"
    signature: string      // Ed25519 signature of (request_id + timestamp + beo_id)
  }

  intent:      BSPIntent   // SUBMIT_RECORD | READ_RECORDS | ANALYZE_VITALITY | ...

  target: {
    beo_id:    string      // Target BEO UUID
    beo_domain:string      // e.g., "andre.bsp"
  }

  auth: {
    consent_token_id: string
  }

  payload:     object      // Intent-specific (see below)
}

BSPResponse Schema

typescript
interface BSPResponse {
  request_id:  string                    // Echo of original request_id
  status:      "SUCCESS" | "ERROR" | "PARTIAL" | "PENDING"
  timestamp:   string

  payload:     object | null             // Intent-specific response

  error: {
    code:      string                    // Machine-readable error code
    message:   string                    // Human-readable description
    field:     string | null             // Specific field (validation errors)
    retryable: boolean
  } | null
}

Double Authentication

Every BSPRequest is authenticated twice:

  1. ConsentToken — Proof from the blockchain that the BEO holder authorized this IEO for this intent and category
  2. IEO Signature — The institution's cryptographic signature on the request — proves the actual institution sent it, not an impostor
AccessControl.verify(consent_token_id, ieo_id, beo_id, intent, category)
  → VALID: proceed  |  → INVALID: reject with specific error code

IEO Signature.verify(request_id + timestamp + beo_id, ieo_public_key)
  → VALID: proceed  |  → INVALID: reject with IEO_SIGNATURE_INVALID

Intent Reference

SUBMIT_RECORD — Write a BioRecord

javascript
// Request payload
{
  records: [{
    biomarker:    "BSP-HM-001",
    value:        13.8,
    unit:         "g/dL",
    collected_at: "2026-02-26T08:00:00Z",
    ref_range: {
      optimal:    "13.5-17.5",
      functional: "12.0-17.5",
      deficiency: "<12.0",
      toxicity:   null
    }
  }]
}

// Response: record_ids (Arweave TX IDs), submitted to Arweave permanently

Batch submissions are supported — multiple BioRecords in one request lower Arweave transaction costs.

READ_RECORDS — Read BioRecords

javascript
// Request payload
{
  filters: {
    categories: ["BSP-LA", "BSP-HM"],
    period: { from: "2025-01-01", to: null },
    limit:  100,
    offset: 0
  }
}

// Response: paginated records with source IEO, status, reference ranges

ANALYZE_VITALITY — Request AVA Analysis

Available only to PLATFORM IEOs integrated with AVA. Returns the full multi-dimensional SVA score (biological age by system, aging velocity, reserve percentile).

REQUEST_SCORE — Request SVA Score

Returns only the SVA composite score. Used mainly by opt-in insurers. Does not trigger a full AVA analysis.

EXPORT_DATA — Export All Data

IMPORTANT

EXPORT_DATA cannot be blocked, restricted, or denied by any BSP-compliant system. Any system that refuses this violates the BSP specification.

Returns all BioRecords in BSP format, fully decrypted, in the user's choice of JSON, CSV, or FHIR_R4.

SYNC_PROTOCOL — Version Negotiation

Used to negotiate BSP version compatibility between client and server at session start.


Complete Error Code Reference

CodeCategoryDescriptionRetryable
TOKEN_NOT_FOUNDAuthConsentToken ID does not existNo
TOKEN_REVOKEDAuthRevoked by BEO holderNo
TOKEN_EXPIREDAuthexpires_at has passedNo
INTENT_NOT_AUTHORIZEDAuthIntent not in token scopeNo
CATEGORY_NOT_AUTHORIZEDAuthCategory not in token scopeNo
IEO_SIGNATURE_INVALIDAuthIEO signature verification failedNo
IEO_NOT_FOUNDAuthIEO domain not in registryNo
BEO_LOCKEDStateBEO is in LOCKED stateNo
SCHEMA_VALIDATION_FAILEDDataBioRecord failed schema validationFix data
BIOMARKER_CODE_INVALIDDataBSP code does not exist in taxonomyFix code
UNIT_INVALIDDataUnit not valid for this biomarkerFix unit
DUPLICATE_RECORDDataIdentical record already existsNo
ARWEAVE_WRITE_FAILEDInfraTemporary Arweave write failureYes
RATE_LIMIT_EXCEEDEDInfraToo many requests per minuteYes
BSP_VERSION_MISMATCHProtocolClient version incompatibleUpdate SDK

SDK Example

python
from bsp_sdk import BSPClient

client = BSPClient(
    ieo_domain  = "yourlaboratory.bsp",
    private_key = YOUR_PRIVATE_KEY,
)

# Submit BioRecord
result = client.submit_biorecord(
    beo_domain    = "patient.bsp",
    consent_token = token_id,
    biomarker     = "BSP-HM-001",
    value         = 13.8,
    unit          = "g/dL",
    collected_at  = "2026-02-26T08:00:00Z",
    ref_range     = { "optimal": "13.5-17.5", "functional": "12.0-17.5" }
)
print(result.submission.record_ids)  # Permanent IDs on Arweave

# Read Records
records = client.read_records(
    beo_domain    = "patient.bsp",
    consent_token = token_id,
    filters       = {
        "categories": ["BSP-HM"],
        "period": { "from": "2025-01-01" }
    }
)