<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc [
  <!ENTITY nbsp "&#160;">
  <!ENTITY zwsp "&#8203;">
  <!ENTITY nbhy "&#8209;">
  <!ENTITY wj "&#8288;">
]>
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" category="std" docName="draft-johnson-mda1-protocol-00" ipr="trust200902" consensus="true" submissionType="IETF" xml:lang="en" tocInclude="true" tocDepth="2" symRefs="true" sortRefs="true" version="3">
  <front>
    <title abbrev="MDA/1">Flat Data Artifact Format, Version 1 (MDA/1) Protocol</title>
    <seriesInfo name="Internet-Draft" value="draft-johnson-mda1-protocol-00"/>
    <author fullname="Septimus Johnson" initials="S." surname="Johnson">
      <organization>TTI-Simplenet Software Solutions</organization>
      <address>
        <email>septimus.johnson@simplenet-solutions.de</email>
        <uri>https://simplenet-solutions.de/</uri>
      </address>
    </author>
    <date year="2026" month="November" day="23"/>
    <area>Applications and Real-Time</area>
    <workgroup>Network Working Group</workgroup>
    <keyword>binary format</keyword>
    <keyword>zero-copy</keyword>
    <keyword>health data</keyword>
    <keyword>offline</keyword>
    <keyword>Ed25519</keyword>
    <keyword>ML-DSA</keyword>
    <keyword>HPKE</keyword>
    <keyword>decentralized identifiers</keyword>
    <abstract>
      <t>This document specifies the Flat Data Artifact Format Version 1 (MDA/1), a fixed-layout, zero-copy binary container for exchanging and storing signed data artifacts in resource-constrained, intermittently connected, and offline environments. MDA/1 artifacts have one canonical encoding and a stable content identifier, can be parsed without dynamic memory allocation, and are validated by a strictly ordered pipeline whose limits are enforced from a 64-byte header. Every byte except the signature values is covered by Ed25519, ML-DSA-44, or hybrid signatures, and signers are bound to the principals they speak for. The document also defines VB01, a key-committing, length-bucketed AEAD frame for payloads at rest, and an HPKE profile, including the X-Wing post-quantum KEM, for delivering frame keys. MDA/1 is intended as a compact edge transport and storage envelope alongside HL7 FHIR.</t>
    </abstract>
  </front>
  <middle>
<section anchor="sec-1" numbered="true" toc="default">
  <name>Introduction</name>
<section anchor="sec-1-1" numbered="true" toc="default">
  <name>Scope</name>
    <t>This document defines MDA/1, a single flat, fixed-layout binary container for data artifacts that edge systems exchange or store: control messages (request, consent, grant, receipt, revocation, error), asset metadata, append-only log records, provenance commitments, ledger anchor receipts, snapshots, emergency profiles, break-glass audit receipts, trust bundles, and DID document envelopes. It also defines VB01, a length-hiding encrypted frame for asset payloads at rest, and the HPKE key-wrapping profile used to deliver frame keys.</t>
    <t>The target environment is low-end mobile hardware, intermittent power and connectivity, offline verification, and parsers that fit in a few kilobytes of compiled code and run without dynamic memory allocation.</t>
</section>
<section anchor="sec-1-2" numbered="true" toc="default">
  <name>Design Goals</name>
    <ul spacing="normal">
      <li>Zero-copy access: every fixed field is found by offset arithmetic on the input buffer. Every multi-byte integer is naturally aligned relative to the start of the artifact.</li>
      <li>Bounded parsing: no recursion, no pointer chasing, no input-dependent allocation. All limits are checked against the 64-byte header before any other byte is interpreted.</li>
      <li>One canonical encoding: for a given logical artifact, every byte that contributes to its identity is uniquely determined, and receivers reject every other encoding. An artifact therefore has exactly one ArtifactID (Section <xref target="sec-8-3" format="counter"/>).</li>
      <li>Complete authentication: a signature covers every byte of the artifact except the signature values themselves and the CRC field, including the signature metadata and the Blob section.</li>
      <li>Algorithm agility: classical (Ed25519, X25519) and post-quantum or hybrid (ML-DSA-44, X-Wing) algorithms share one layout. Large post-quantum values live in variable-length sections, so fixed strides do not change.</li>
      <li>Unified parsing: one container parser handles every artifact type; type-specific code reads fields at known offsets.</li>
    </ul>
</section>
<section anchor="sec-1-3" numbered="true" toc="default">
  <name>Non-Goals</name>
    <ul spacing="normal">
      <li>MDA/1 is not a general-purpose serialization format and has no nesting, maps, or schema language.</li>
      <li>MDA/1 does not define DID methods, verifiable credential formats, or online resolution protocols. It defines how keys are resolved offline from material that is itself carried in MDA/1 artifacts (Section <xref target="sec-8-7" format="counter"/>).</li>
      <li>MDA/1 does not provide transport security, confidentiality of control artifacts, or traffic-flow confidentiality. Control artifacts are signed, not encrypted; see Section <xref target="sec-20" format="counter"/>.</li>
      <li>EMERGENCY_PROFILE artifacts are deliberately readable without keys. Break-glass auditing in MDA/1 is a detective control, not a preventive one (Section <xref target="sec-19-11" format="counter"/>).</li>
    </ul>
</section>
<section anchor="sec-1-4" numbered="true" toc="default">
  <name>Relationship to HL7 FHIR</name>
    <t>MDA/1 does not replace HL7 FHIR <xref target="FHIR"/>. It is an offline-first binary transport and edge-storage envelope used alongside FHIR systems. Gateways convert between FHIR resources and MDA/1 artifacts at the boundary between a connected FHIR server and disconnected edge devices.</t>
    <t>The conversion is a lossy profile, not an isomorphism. Only the elements listed below are carried. A gateway <bcp14>MUST</bcp14> reject, rather than silently truncate, a FHIR resource whose meaning depends on elements that the profile cannot carry. Examples are nested or "deny" Consent provisions, and Composition sections outside the list below. A resource reconstituted from MDA/1 <bcp14>MUST</bcp14> be marked as derived (for example, with a meta.tag) and <bcp14>MUST NOT</bcp14> be presented as the original resource.</t>
    <table anchor="tbl-fhir-mapping-profile">
      <name>FHIR mapping profile</name>
      <thead>
        <tr>
          <th>FHIR R4 resource</th>
          <th>MDA/1 artifact</th>
          <th>Elements carried</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Consent</td>
          <td>CONSENT (0x02)</td>
          <td>patient, one permit provision: actor, purpose, period, data (as scopes)</td>
        </tr>
        <tr>
          <td>Composition (IPS)</td>
          <td>EMERGENCY_PROFILE (0x20)</td>
          <td>allergies, meds, problems, contacts, advance directive</td>
        </tr>
        <tr>
          <td>AuditEvent</td>
          <td>EMERGENCY_ACCESS_RECEIPT (0x21)</td>
          <td>agent, entity, recorded, source</td>
        </tr>
        <tr>
          <td>Provenance</td>
          <td>PROVENANCE_COMMITMENT (0x12)</td>
          <td>target, agent, recorded</td>
        </tr>
        <tr>
          <td>DocumentReference +</td>
          <td>ASSET_MANIFEST (0x10)</td>
          <td>identifier, type,</td>
        </tr>
        <tr>
          <td>Binary</td>
          <td>+ VB01 frame</td>
          <td>date, content</td>
        </tr>
      </tbody>
    </table>
    <t>The EMERGENCY_PROFILE row follows the International Patient Summary <xref target="IPS"/>. Coded concepts are carried as two strings: a code and a code-system URI. Text longer than 256 bytes (for example, medication instructions) is carried in the record text span (Section <xref target="sec-7-2" format="counter"/>).</t>
</section>
</section>
<section anchor="sec-2" numbered="true" toc="default">
  <name>Conventions and Terminology</name>
<section anchor="sec-2-1" numbered="true" toc="default">
  <name>Requirements Language</name>
    <t>The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>", "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL NOT</bcp14>", "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>", "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>", "<bcp14>MAY</bcp14>", and "<bcp14>OPTIONAL</bcp14>" in this document are to be interpreted as described in BCP 14 <xref target="RFC2119"/> <xref target="RFC8174"/> when, and only when, they appear in all capitals, as shown here.</t>
</section>
<section anchor="sec-2-2" numbered="true" toc="default">
  <name>Terminology</name>
    <dl newline="false" spacing="normal">
      <dt>Artifact:</dt>
      <dd>A complete MDA/1 byte string, from the first byte of the header to the last byte of the signature value section.</dd>
      <dt>Encoder:</dt>
      <dd>An implementation that produces artifacts.</dd>
      <dt>Receiver:</dt>
      <dd>An implementation that consumes artifacts and runs the validation pipeline (Section <xref target="sec-15" format="counter"/>).</dd>
      <dt>ArtifactID:</dt>
      <dd>The SHA-256 digest that identifies an artifact (Section <xref target="sec-8-3" format="counter"/>). Every hash32 field in this document whose name ends in "Ref" holds an ArtifactID, unless its definition says otherwise.</dd>
      <dt>Principal field:</dt>
      <dd>The body field naming the party that must sign an artifact (Section <xref target="sec-8-6" format="counter"/>).</dd>
      <dt>Absent:</dt>
      <dd>The reserved encoding meaning "no value": 0xFFFFFFFF for str_ref, {0, 0} for span, and 32 zero bytes for an <bcp14>OPTIONAL</bcp14> hash32 field.</dd>
      <dt>Supported minor version:</dt>
      <dd>The highest minor version a receiver implements. This document defines minor version 0.</dd>
      <dt>Closed / open enumeration:</dt>
      <dd>Defined in Section <xref target="sec-13-1" format="counter"/>.</dd>
    </dl>
</section>
<section anchor="sec-2-3" numbered="true" toc="default">
  <name>Normative Encoding Rules</name>
    <table anchor="tbl-normative-encoding-rules">
      <name>Normative encoding rules</name>
      <thead>
        <tr>
          <th>Rule</th>
          <th>Statement</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>C-1</td>
          <td>All multi-byte integers are little-endian.</td>
        </tr>
        <tr>
          <td>C-2</td>
          <td>Timestamps (ts) are unsigned milliseconds since the Unix epoch, UTC. Durations named *Sec are seconds. The value 0 means "unbounded" only where a field definition says so.</td>
        </tr>
        <tr>
          <td>C-3</td>
          <td>Reserved fields, reserved flag bits, and all padding <bcp14>MUST</bcp14> be zero on emission. Receivers <bcp14>MUST</bcp14> reject non-zero values unless Section <xref target="sec-17" format="counter"/> permits them.</td>
        </tr>
        <tr>
          <td>C-4</td>
          <td>Every section starts at an offset that is a multiple of 16 and has a length that is a multiple of 16. No bytes follow the signature value section.</td>
        </tr>
        <tr>
          <td>C-5</td>
          <td>Absent str_ref = 0xFFFFFFFF; absent span = {0, 0}; absent <bcp14>OPTIONAL</bcp14> hash32 or raw16 = all zero bytes.</td>
        </tr>
        <tr>
          <td>C-6</td>
          <td>The string table is sorted, unique, fully referenced, and well-formed UTF-8 (Section <xref target="sec-5" format="counter"/>).</td>
        </tr>
        <tr>
          <td>C-7</td>
          <td>Records appear in canonical order (Section <xref target="sec-7-1" format="counter"/>).</td>
        </tr>
        <tr>
          <td>C-8</td>
          <td>Signature entries and values appear in canonical order (Section <xref target="sec-8" format="counter"/>).</td>
        </tr>
        <tr>
          <td>C-9</td>
          <td>Blob items appear in canonical layout (Section <xref target="sec-6-2" format="counter"/>).</td>
        </tr>
        <tr>
          <td>C-10</td>
          <td>The CRC-32 is verified before any byte outside the header is interpreted (Section <xref target="sec-15-1" format="counter"/>).</td>
        </tr>
        <tr>
          <td>C-11</td>
          <td>Size bounds (Section <xref target="sec-14" format="counter"/>) are enforced from the header before any input-dependent memory allocation.</td>
        </tr>
        <tr>
          <td>C-12</td>
          <td>Offset and length arithmetic <bcp14>MUST NOT</bcp14> wrap: it uses at least 64-bit unsigned integers or checked arithmetic.</td>
        </tr>
      </tbody>
    </table>
    <t>Rules C-3 through C-9 make the encoding canonical. For a given logical artifact, meaning a given value for every field, including identifiers, nonces, and timestamps, the bytes from offset 0 to sigValOff are uniquely determined. Encoders <bcp14>MUST</bcp14> normalize every string to Unicode Normalization Form C <xref target="UAX15"/> before encoding. Receivers are not required to check NFC, because doing so needs Unicode tables that a minimal parser cannot carry; Section <xref target="sec-19-6" format="counter"/> explains why this does not create malleability.</t>
    <t>Signature values (Section <xref target="sec-8-2" format="counter"/>) and VB01 frames (Section <xref target="sec-9" format="counter"/>) may be randomized. Neither contributes to the ArtifactID, so the ArtifactID stays stable.</t>
</section>
</section>
<section anchor="sec-3" numbered="true" toc="default">
  <name>Primitive Types</name>
    <table anchor="tbl-primitive-types">
      <name>Primitive types</name>
      <thead>
        <tr>
          <th>Name</th>
          <th>Size</th>
          <th>Definition</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>u8</td>
          <td>1</td>
          <td>Unsigned 8-bit integer</td>
        </tr>
        <tr>
          <td>u16</td>
          <td>2</td>
          <td>Unsigned 16-bit integer, little-endian</td>
        </tr>
        <tr>
          <td>u32</td>
          <td>4</td>
          <td>Unsigned 32-bit integer, little-endian</td>
        </tr>
        <tr>
          <td>u64</td>
          <td>8</td>
          <td>Unsigned 64-bit integer, little-endian</td>
        </tr>
        <tr>
          <td>i32</td>
          <td>4</td>
          <td>Two's-complement signed 32-bit, little-endian</td>
        </tr>
        <tr>
          <td>ts</td>
          <td>8</td>
          <td>u64 milliseconds since Unix epoch, UTC</td>
        </tr>
        <tr>
          <td>enum8</td>
          <td>1</td>
          <td>Enumerated value (Section <xref target="sec-13" format="counter"/>)</td>
        </tr>
        <tr>
          <td>raw16</td>
          <td>16</td>
          <td>Identifier or nonce: 128 bits from a CSPRNG</td>
        </tr>
        <tr>
          <td>hash32</td>
          <td>32</td>
          <td>SHA-256 digest <xref target="FIPS180-4"/></td>
        </tr>
        <tr>
          <td>str_ref</td>
          <td>4</td>
          <td>u32 absolute offset of a string table entry, or 0xFFFFFFFF (absent)</td>
        </tr>
        <tr>
          <td>span</td>
          <td>8</td>
          <td>{u32 off, u32 len}: absolute offset and length of a Blob item, or {0, 0} (absent)</td>
        </tr>
        <tr>
          <td>bytes</td>
          <td>n</td>
          <td>Opaque octets</td>
        </tr>
      </tbody>
    </table>
    <t>Every identifier and nonce field is a raw16 generated by a cryptographically secure random number generator. Encoders <bcp14>MUST NOT</bcp14> derive identifiers from counters, timestamps, or personal data. Where text is needed, an identifier is written as 32 lowercase hexadecimal characters ("canonical ID text").</t>
</section>
<section anchor="sec-4" numbered="true" toc="default">
  <name>Container Format</name>
<section anchor="sec-4-1" numbered="true" toc="default">
  <name>Section Layout</name>
    <t>Every artifact is a sequence of seven contiguous, non-overlapping sections, in this fixed order:</t>
    <figure>
      <name>Section layout</name>
    <artwork type="ascii-art" align="left"><![CDATA[
0      64         recOff     sigOff     strOff   blobOff  sigValOff
+------+----------+----------+----------+--------+--------+--------+
|Header|   Body   | Records  |Signature | String |  Blob  |Sig     |
| 64 B | bodyLen  |rc * rs   | entries  | table  |        |values  |
|      |          |          | sc * 32  | strLen | blobLen|sigValLn|
+------+----------+----------+----------+--------+--------+--------+
|<-------------- ArtifactID and signature coverage ------>|
|<-------------------------- CRC-32 coverage ---------------------->|
]]></artwork>
    </figure>
    <t>Signature values come last, so every signature covers every other section, the signature entries included (Section <xref target="sec-8-4" format="counter"/>).</t>
</section>
<section anchor="sec-4-2" numbered="true" toc="default">
  <name>Header</name>
    <table anchor="tbl-header">
      <name>MDA/1 header (64 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>4</td><td>magic</td><td>bytes</td><td>ASCII "MDA1" (4D 44 41 31)</td></tr>
        <tr><td>4</td><td>1</td><td>major</td><td>u8</td><td>Major version; this spec = 1</td></tr>
        <tr><td>5</td><td>1</td><td>minor</td><td>u8</td><td>Minor version; this spec = 0</td></tr>
        <tr><td>6</td><td>1</td><td>type</td><td>u8</td><td>Artifact type (Section <xref target="sec-11" format="counter"/>)</td></tr>
        <tr><td>7</td><td>1</td><td>(rsv)</td><td>u8</td><td>Reserved</td></tr>
        <tr><td>8</td><td>2</td><td>flags</td><td>u16</td><td>Header flags (Section <xref target="sec-4-3" format="counter"/>)</td></tr>
        <tr><td>10</td><td>2</td><td>strCount</td><td>u16</td><td>Number of string entries</td></tr>
        <tr><td>12</td><td>4</td><td>totalLen</td><td>u32</td><td>Artifact size in bytes</td></tr>
        <tr><td>16</td><td>4</td><td>bodyLen</td><td>u32</td><td><bcp14>MUST</bcp14> equal type body size</td></tr>
        <tr><td>20</td><td>2</td><td>recCount</td><td>u16</td><td>Number of records</td></tr>
        <tr><td>22</td><td>2</td><td>recStride</td><td>u16</td><td>Record stride, 0 if none</td></tr>
        <tr><td>24</td><td>2</td><td>sigCount</td><td>u16</td><td>Number of signature entries</td></tr>
        <tr><td>26</td><td>2</td><td>sigStride</td><td>u16</td><td>32 if sigCount &gt; 0, else 0</td></tr>
        <tr><td>28</td><td>4</td><td>strOff</td><td>u32</td><td>String table offset</td></tr>
        <tr><td>32</td><td>4</td><td>strLen</td><td>u32</td><td>String table length</td></tr>
        <tr><td>36</td><td>4</td><td>blobOff</td><td>u32</td><td>Blob section offset</td></tr>
        <tr><td>40</td><td>4</td><td>blobLen</td><td>u32</td><td>Blob section length</td></tr>
        <tr><td>44</td><td>4</td><td>sigValOff</td><td>u32</td><td>Signature value offset</td></tr>
        <tr><td>48</td><td>4</td><td>sigValLen</td><td>u32</td><td>Signature value length</td></tr>
        <tr><td>52</td><td>4</td><td>crc32</td><td>u32</td><td>CRC-32 (Section <xref target="sec-4-5" format="counter"/>)</td></tr>
        <tr><td>56</td><td>8</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
      </tbody>
    </table>
</section>
<section anchor="sec-4-3" numbered="true" toc="default">
  <name>Header Flags</name>
    <table anchor="tbl-header-flags">
      <name>Header flags</name>
      <thead>
        <tr>
          <th>Bit</th>
          <th>Name</th>
          <th>Meaning</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>0</td>
          <td>FLAG_SIGNED</td>
          <td><bcp14>MUST</bcp14> be 1 if sigCount &gt; 0, else 0.</td>
        </tr>
        <tr>
          <td>1..7</td>
          <td>(non-critical)</td>
          <td>Reserved for minor-version extensions that receivers may ignore.</td>
        </tr>
        <tr>
          <td>8..15</td>
          <td>(critical)</td>
          <td>Reserved for extensions that change how the artifact must be processed.</td>
        </tr>
      </tbody>
    </table>
    <t>FLAG_SIGNED only describes the artifact's structure. Whether an artifact must be signed is decided by its type (Section <xref target="sec-8-6" format="counter"/>), never by this flag. In minor version 0, every bit except bit 0 <bcp14>MUST</bcp14> be zero. A receiver <bcp14>MUST</bcp14> reject an artifact that sets a critical bit it does not implement (UNKNOWN_CRITICAL_FLAG), whatever the artifact's minor version.</t>
</section>
<section anchor="sec-4-4" numbered="true" toc="default">
  <name>Section Topology</name>
    <t>Receivers derive every section offset from lengths, using arithmetic that cannot overflow (C-12):</t>
    <artwork type="ascii-art" align="left"><![CDATA[
recOff    = 64 + bodyLen
sigOff    = recOff + recCount * recStride
strOff    = sigOff + sigCount * sigStride
blobOff   = strOff + strLen
sigValOff = blobOff + blobLen
totalLen  = sigValOff + sigValLen
]]></artwork>
    <t>The header's strOff, blobOff, sigValOff, and totalLen <bcp14>MUST</bcp14> equal these values. In addition:</t>
    <ul spacing="normal">
      <li>bodyLen <bcp14>MUST</bcp14> equal the body size the Type Registry gives for the type (Section <xref target="sec-11" format="counter"/>).</li>
      <li>recStride <bcp14>MUST</bcp14> equal the registered stride if recCount &gt; 0, and <bcp14>MUST</bcp14> be 0 if recCount = 0. For types with registered stride 0, recCount <bcp14>MUST</bcp14> be 0.</li>
      <li>sigStride <bcp14>MUST</bcp14> be 32 if sigCount &gt; 0, and <bcp14>MUST</bcp14> be 0 if sigCount = 0.</li>
      <li>strLen, blobLen, and sigValLen <bcp14>MUST</bcp14> each be a multiple of 16.</li>
      <li>totalLen <bcp14>MUST</bcp14> equal the number of octets received. An artifact always arrives as a discrete unit whose length the transport or storage layer knows. Receivers <bcp14>MUST NOT</bcp14> read totalLen bytes from a buffer before checking this equality.</li>
    </ul>
</section>
<section anchor="sec-4-5" numbered="true" toc="default">
  <name>CRC-32</name>
    <t>crc32 is CRC-32/ISO-HDLC <xref target="ISO13239"/>: polynomial 0x04C11DB7, reflected, initial value and final XOR 0xFFFFFFFF (the CRC used by zlib). It is computed over [0, totalLen) with the crc32 field treated as four zero bytes. It is written last.</t>
    <t>The CRC only detects accidental corruption cheaply, before more expensive work. It offers no protection against deliberate modification (Section <xref target="sec-19-2" format="counter"/>).</t>
</section>
</section>
<section anchor="sec-5" numbered="true" toc="default">
  <name>String Table</name>
<section anchor="sec-5-1" numbered="true" toc="default">
  <name>Entry Format</name>
    <t>The string table holds exactly strCount entries, followed by zero padding up to strLen. Each entry is:</t>
    <artwork type="ascii-art" align="left"><![CDATA[
u16 len || len octets of UTF-8 || 0x00 if len is odd
]]></artwork>
    <t>Every entry therefore starts at an even offset. The padding after the last entry <bcp14>MUST</bcp14> be zero and shorter than 16 octets.</t>
</section>
<section anchor="sec-5-2" numbered="true" toc="default">
  <name>Ordering and Uniqueness</name>
    <t>Entries <bcp14>MUST</bcp14> be in strictly ascending order of their UTF-8 octets, compared as unsigned bytes. A proper prefix sorts before any longer string that starts with it, as with memcmp() followed by a length comparison. Strict order also means duplicates are forbidden.</t>
    <t>Because entries are sorted, entry offsets increase in the same order as entry contents. Within one artifact, comparing two present str_ref values as unsigned integers gives the same result as comparing the strings they point to. The absent value 0xFFFFFFFF sorts after every present value. Section <xref target="sec-7-1" format="counter"/> relies on this.</t>
</section>
<section anchor="sec-5-3" numbered="true" toc="default">
  <name>Content Rules</name>
    <ul spacing="normal">
      <li>len <bcp14>MUST</bcp14> be in the range 1..256. Empty strings are forbidden; an absent value uses str_ref 0xFFFFFFFF.</li>
      <li>The octets <bcp14>MUST</bcp14> be well-formed UTF-8 <xref target="RFC3629"/>: no overlong forms, no surrogates, nothing above U+10FFFF. They <bcp14>MUST NOT</bcp14> contain U+0000.</li>
      <li>Every entry <bcp14>MUST</bcp14> be referenced by at least one str_ref somewhere in the artifact: body, records, or signature entries. Orphan entries are forbidden.</li>
      <li>Text longer than 256 octets is not a string. It is carried in the Blob section through a text span (Section <xref target="sec-7-2" format="counter"/>), or in a type-specific span.</li>
    </ul>
</section>
<section anchor="sec-5-4" numbered="true" toc="default">
  <name>String References</name>
    <t>A present str_ref <bcp14>MUST</bcp14> equal the absolute offset of the len field of one of the strCount entries. Receivers check this against the set of entry start offsets found while walking the table in step B1 (Section <xref target="sec-15-2" format="counter"/>).</t>
</section>
</section>
<section anchor="sec-6" numbered="true" toc="default">
  <name>Blob Section and Spans</name>
<section anchor="sec-6-1" numbered="true" toc="default">
  <name>Spans</name>
    <t>A present span {off, len} names the octets [off, off + len) inside the Blob section. len <bcp14>MUST</bcp14> be at least 1, so {0, 0} is the only way to encode absence. Spans <bcp14>MUST NOT</bcp14> overlap. Two span fields <bcp14>MUST NOT</bcp14> reference the same octets, even when the content is identical.</t>
</section>
<section anchor="sec-6-2" numbered="true" toc="default">
  <name>Canonical Blob Layout</name>
    <t>Blob items are laid out in "span order". Body span fields come first, in increasing field offset. Record span fields follow, in record order, and within a record in increasing field offset. The first present span starts at blobOff. Each later present span starts at the smallest multiple of 16 that is at or past the end of the previous item. The bytes between items <bcp14>MUST</bcp14> be zero. blobLen <bcp14>MUST</bcp14> equal the end of the last item rounded up to a multiple of 16, or 0 if there are no items.</t>
    <t>This rule leaves no unreferenced or ambiguous octets in the Blob section. A receiver checks it in one pass with no allocation (Section <xref target="sec-15-2" format="counter"/>, step B5).</t>
    <t>Signature values are not blob items. They have their own section (Section <xref target="sec-8-2" format="counter"/>).</t>
</section>
</section>
<section anchor="sec-7" numbered="true" toc="default">
  <name>Record Tables</name>
    <t>A record table holds recCount fixed-stride records. MDA/1 defines three record layouts: the Generic Record (stride 48, Section <xref target="sec-7-2" format="counter"/>), the Trust Record (stride 96, Section <xref target="sec-12-14" format="counter"/>), and the Proof Record (stride 32, Section <xref target="sec-12-10" format="counter"/>). The Type Registry (Section <xref target="sec-11" format="counter"/>) gives each type's layout.</t>
<section anchor="sec-7-1" numbered="true" toc="default">
  <name>Canonical Record Order</name>
    <t>Except in ANCHOR_RECEIPT (Section <xref target="sec-12-10" format="counter"/>), records <bcp14>MUST</bcp14> appear in strictly ascending order under this comparison. Duplicate records are therefore forbidden.</t>
    <ol spacing="normal">
      <li>Fields are compared one at a time in the order the record layout lists them. Reserved fields are skipped.</li>
      <li>Integer and enumerated fields compare numerically. ts fields are integers.</li>
      <li>str_ref fields compare by the octets they reference (Section <xref target="sec-5-2" format="counter"/>), and absent sorts after every present value. Within one artifact this is the same as comparing the u32 values numerically.</li>
      <li>span fields compare by the octets they reference, with the same prefix rule, and absent sorts after every present value.</li>
      <li>hash32 and raw16 fields compare as unsigned byte strings.</li>
    </ol>
    <t>This order depends only on logical values, never on where strings or blob items happen to sit. The same set of records therefore sorts identically in every artifact that carries it.</t>
    <t>The order is compared field by field, not byte by byte over the record, because little-endian integers and absolute offsets do not sort correctly as raw bytes.</t>
</section>
<section anchor="sec-7-2" numbered="true" toc="default">
  <name>Generic Record (RS 48)</name>
    <table anchor="tbl-genericrecord">
      <name>Generic record (48 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>1</td><td>reckind</td><td>enum8</td><td>Record kind, closed</td></tr>
        <tr><td>1</td><td>1</td><td>subkind</td><td>enum8</td><td>Per-kind subtype</td></tr>
        <tr><td>2</td><td>2</td><td>flags</td><td>u16</td><td>Reserved in minor 0</td></tr>
        <tr><td>4</td><td>4</td><td>field1</td><td>str_ref</td><td>Primary string</td></tr>
        <tr><td>8</td><td>4</td><td>field2</td><td>str_ref</td><td>Secondary string</td></tr>
        <tr><td>12</td><td>4</td><td>field3</td><td>str_ref</td><td>Tertiary string</td></tr>
        <tr><td>16</td><td>8</td><td>ts1</td><td>ts</td><td>Start / primary time</td></tr>
        <tr><td>24</td><td>8</td><td>ts2</td><td>ts</td><td>End / secondary time</td></tr>
        <tr><td>32</td><td>4</td><td>num</td><td>u32</td><td>Numeric value</td></tr>
        <tr><td>36</td><td>4</td><td>(rsv)</td><td>u32</td><td>Reserved</td></tr>
        <tr><td>40</td><td>8</td><td>text</td><td>span</td><td>Long UTF-8 text in Blob</td></tr>
      </tbody>
    </table>
    <t>flags <bcp14>MUST</bcp14> be zero in minor version 0. The text span holds UTF-8 text of 1 to 65536 octets that does not fit in a string; it follows Section <xref target="sec-5-3" format="counter"/>, except for the length limit and the reference rule. Record kinds that do not use text <bcp14>MUST</bcp14> set it absent. A record field that a kind does not use <bcp14>MUST</bcp14> be zero or absent.</t>
</section>
<section anchor="sec-7-3" numbered="true" toc="default">
  <name>Generic Record Kinds</name>
    <table anchor="tbl-generic-record-kinds">
      <name>Generic record kinds</name>
      <thead>
        <tr>
          <th>kind</th>
          <th>Meaning</th>
          <th>field1</th>
          <th>field2</th>
          <th>field3</th>
          <th>subkind</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>0x01</td>
          <td>Allergy</td>
          <td>substance</td>
          <td>reaction</td>
          <td>code</td>
          <td>severity</td>
        </tr>
        <tr>
          <td>0x02</td>
          <td>Medication</td>
          <td>name</td>
          <td>dose</td>
          <td>frequency</td>
          <td>route</td>
        </tr>
        <tr>
          <td>0x03</td>
          <td>Condition</td>
          <td>name</td>
          <td>code</td>
          <td>codeSystem</td>
          <td>status</td>
        </tr>
        <tr>
          <td>0x04</td>
          <td>Contact</td>
          <td>name</td>
          <td>relation</td>
          <td>phone</td>
          <td>priority</td>
        </tr>
        <tr>
          <td>0x05</td>
          <td>Scope</td>
          <td>assetId</td>
          <td>assetType</td>
          <td>category</td>
          <td>versOp</td>
        </tr>
        <tr>
          <td>0x06</td>
          <td>Tag</td>
          <td>tag</td>
          <td>(absent)</td>
          <td>(absent)</td>
          <td>0</td>
        </tr>
      </tbody>
    </table>
    <ul spacing="normal">
      <li>Allergy (0x01): field3 is an <bcp14>OPTIONAL</bcp14> coded substance in token form, "system|code". ts1 is the onset time, or 0 if unknown. text holds <bcp14>OPTIONAL</bcp14> notes. subkind is a severity value (Section <xref target="sec-13-23" format="counter"/>).</li>
      <li>Medication (0x02): ts1 and ts2 bound the medication period, where 0 means unbounded. text holds <bcp14>OPTIONAL</bcp14> full instructions. subkind is a route value (Section <xref target="sec-13-23" format="counter"/>).</li>
      <li>Condition (0x03): field2 and field3 together carry the coded concept, a code and the URI of its code system. ts1 is the onset time. subkind is a clinical status value (Section <xref target="sec-13-23" format="counter"/>).</li>
      <li>Contact (0x04): field3 is an E.164 telephone number. subkind is the contact priority: 1 is highest, and 0 means unspecified.</li>
      <li>Scope (0x05): see Section <xref target="sec-7-4" format="counter"/>.</li>
      <li>Tag (0x06): field1 is a tag string. Every other field is zero or absent.</li>
    </ul>
    <t>Section <xref target="sec-13-22" format="counter"/> lists which record kinds each type allows. A record kind the type does not allow <bcp14>MUST</bcp14> be rejected (UNKNOWN_ENUM).</t>
</section>
<section anchor="sec-7-4" numbered="true" toc="default">
  <name>Scope Records and Matching</name>
    <t>A Scope record describes a set of assets. field1, when present, is the canonical ID text (Section <xref target="sec-3" format="counter"/>) of one ASSET_MANIFEST assetId. field2, when present, is the name of a contentType value (Section <xref target="sec-13-11" format="counter"/>), such as "lab". field3, when present, is a category that <bcp14>MUST</bcp14> equal the tag of one of the asset's Tag records. ts1 and ts2 bound the asset's capturedAt; 0 means unbounded and both bounds are inclusive. subkind is versionOp (Section <xref target="sec-13-21" format="counter"/>), and num holds the version operand.</t>
    <t>An asset with ASSET_MANIFEST m matches a Scope record s when every one of the following holds:</t>
    <ul spacing="normal">
      <li>s.field1 is absent, or it equals the canonical ID text of m.assetId.</li>
      <li>s.field2 is absent, or it equals the name of m.contentType.</li>
      <li>s.field3 is absent, or m has a Tag record whose field1 equals s.field3.</li>
      <li>s.ts1 = 0 or s.ts1 &lt;= m.capturedAt, and s.ts2 = 0 or m.capturedAt &lt;= s.ts2.</li>
      <li>versionOp is satisfied. Under 0x01 (exact), m.version = num. Under 0x02 (at-least), m.version &gt;= num. Under 0x03 (latest), num <bcp14>MUST</bcp14> be 0, and m is the highest version of its assetId that the evaluator holds.</li>
    </ul>
    <t>A set of Scope records matches an asset if any one of them matches.</t>
</section>
<section anchor="sec-7-5" numbered="true" toc="default">
  <name>ScopeDigest</name>
    <t>ScopeDigest commits to a set of Scope records in a form that does not depend on where strings sit in the artifact, so it can be compared across artifacts:</t>
    <artwork type="ascii-art" align="left"><![CDATA[
ScopeDigest = SHA-256( "MDA1SCP\0" || u32 n ||
                       for each Scope record in canonical order:
                         u8 subkind || S(field1) || S(field2) ||
                         S(field3) || u64 ts1 || u64 ts2 || u32 num )

S(x) = u16 len || octets   (len = 0 when x is absent)
]]></artwork>
    <t>All integers are little-endian, and n is the number of Scope records. Appendix <xref target="app-a-2" format="counter"/> gives a test vector.</t>
</section>
</section>
<section anchor="sec-8" numbered="true" toc="default">
  <name>Signatures and Artifact Identity</name>
<section anchor="sec-8-1" numbered="true" toc="default">
  <name>Signature Entry</name>
    <table anchor="tbl-sigentry">
      <name>Signature entry (32 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>4</td><td>signerDID</td><td>str_ref</td><td>Signer DID</td></tr>
        <tr><td>4</td><td>1</td><td>alg</td><td>enum8</td><td>Algorithm (13.2), closed</td></tr>
        <tr><td>5</td><td>1</td><td>purpose</td><td>enum8</td><td>Purpose (13.3), closed</td></tr>
        <tr><td>6</td><td>2</td><td>(rsv)</td><td>u16</td><td>Reserved</td></tr>
        <tr><td>8</td><td>8</td><td>signedAt</td><td>ts</td><td>Signing time</td></tr>
        <tr><td>16</td><td>4</td><td>keyRef</td><td>str_ref</td><td>Verification method id</td></tr>
        <tr><td>20</td><td>4</td><td>valOff</td><td>u32</td><td>Absolute offset of value</td></tr>
        <tr><td>24</td><td>4</td><td>valLen</td><td>u32</td><td>Value length (8.2)</td></tr>
        <tr><td>28</td><td>4</td><td>(rsv)</td><td>u32</td><td>Reserved</td></tr>
      </tbody>
    </table>
    <t>Signature entries <bcp14>MUST</bcp14> appear in strictly ascending order of (purpose, octets of the signerDID string). Two entries therefore never share the same purpose and signer. signerDID <bcp14>MUST</bcp14> be present.</t>
    <t>keyRef is a DID URL fragment, including the leading "#", that identifies the verification method within the signer's DID document. It <bcp14>MAY</bcp14> be absent only when the signer is a did:key DID; the key is then the one encoded in the DID itself (Section <xref target="sec-8-7" format="counter"/>).</t>
</section>
<section anchor="sec-8-2" numbered="true" toc="default">
  <name>Signature Values</name>
    <table anchor="tbl-signature-value-sizes">
      <name>Signature value sizes</name>
      <thead>
        <tr>
          <th>alg</th>
          <th>Algorithm</th>
          <th>valLen</th>
          <th>Value</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>0x01</td>
          <td>Ed25519 <xref target="RFC8032"/></td>
          <td>64</td>
          <td>Ed25519 signature</td>
        </tr>
        <tr>
          <td>0x02</td>
          <td>ML-DSA-44 <xref target="FIPS204"/></td>
          <td>2420</td>
          <td>ML-DSA signature</td>
        </tr>
        <tr>
          <td>0x03</td>
          <td>Ed25519 + ML-DSA-44 (hybrid)</td>
          <td>2484</td>
          <td>Ed25519 signature</td>
        </tr>
      </tbody>
    </table>
    <t>|, |, | || ML-DSA sig.</t>
    <t>valLen <bcp14>MUST</bcp14> equal the size in the table for the entry's alg. Values sit in the signature value section in signature-entry order. The first starts at sigValOff, and each later one starts at the next multiple of 16 after the end of the previous value. valOff <bcp14>MUST</bcp14> equal that computed position. The padding between values and after the last value <bcp14>MUST</bcp14> be zero, and sigValLen <bcp14>MUST</bcp14> equal the padded total.</t>
</section>
<section anchor="sec-8-3" numbered="true" toc="default">
  <name>ArtifactID</name>
    <artwork type="ascii-art" align="left"><![CDATA[
ArtifactID = SHA-256( A[0 .. sigValOff) )
]]></artwork>
    <t>A is the artifact with octets [52, 56), the crc32 field, set to zero. The ArtifactID covers every section except the signature values. That includes the header (and with it every length), the signature entries (signer, algorithm, purpose, signedAt, key reference, and value placement), and the Blob section.</t>
    <t>Every hash32 field defined as an ArtifactID <bcp14>MUST</bcp14> hold exactly this value. Section <xref target="sec-15" format="counter"/> rejects every non-canonical encoding, and the signature values are excluded, so two artifacts with the same ArtifactID are the same logical artifact.</t>
</section>
<section anchor="sec-8-4" numbered="true" toc="default">
  <name>Signing Procedure</name>
    <ol spacing="normal">
      <li>The encoder builds the complete artifact with every field final, the signature value section filled with zeros, and crc32 set to zero. Every signer and its signature entry must be known at this point (Section <xref target="sec-8-8" format="counter"/>).</li>
      <li>It computes the ArtifactID.</li>
      <li>It forms TBS = "MDA1SIG\0" || ArtifactID, 40 octets. The 8-octet domain tag is 4D 44 41 31 53 49 47 00.</li>
      <li><t>Each signer signs TBS:</t>
        <ul spacing="normal">
          <li>Ed25519: the signature over TBS from Ed25519 as defined in <xref target="RFC8032" section="5.1.6" sectionFormat="comma"/> (pure Ed25519, no prehash, no context).</li>
          <li>ML-DSA-44: ML-DSA.Sign(sk, TBS, ctx) as defined in Algorithm 2 of <xref target="FIPS204"/>, with ctx = "MDA1" (4 octets). Either the hedged or the deterministic variant <bcp14>MAY</bcp14> be used.</li>
          <li>Hybrid: the Ed25519 signature over TBS, followed by the ML-DSA-44 signature over TBS. Both <bcp14>MUST</bcp14> verify. alg is part of the ArtifactID, so removing one component changes TBS and is detected (Section <xref target="sec-19-5" format="counter"/>).</li>
        </ul>
      </li>
      <li>The encoder writes each value at its valOff.</li>
      <li>It computes the CRC-32 (Section <xref target="sec-4-5" format="counter"/>) and writes it last.</li>
    </ol>
</section>
<section anchor="sec-8-5" numbered="true" toc="default">
  <name>Verification Procedure</name>
    <t>For each signature entry, the receiver resolves the verification key (Section <xref target="sec-8-7" format="counter"/>) and verifies the value over TBS with the algorithm the entry names. Ed25519 verification <bcp14>MUST</bcp14> be strict: reject S &gt;= L, reject non-canonical encodings of R and A, reject small-order A, and use the cofactorless equation [S]B = R + [k]A. A receiver <bcp14>MUST</bcp14> reject the artifact if any signature entry fails to verify, including entries that are not required (Section <xref target="sec-8-6" format="counter"/>).</t>
</section>
<section anchor="sec-8-6" numbered="true" toc="default">
  <name>Signature Requirements and Signer Binding</name>
    <t>The type decides whether an artifact must be signed, never FLAG_SIGNED. Each type has a required purpose and a principal field. A conforming artifact of a "<bcp14>MUST</bcp14>"-signed type has at least one signature entry with the required purpose whose signerDID equals the principal field's string. An artifact may also carry counter-signatures (purpose 0x02) from other DIDs, up to the overall limit of four signatures.</t>
    <table anchor="tbl-signature-requirements-per-type">
      <name>Signature requirements per type</name>
      <thead>
        <tr>
          <th>Type</th>
          <th>Signed</th>
          <th>Required purpose</th>
          <th>Signer <bcp14>MUST</bcp14> be (principal)</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>REQUEST</td>
          <td><bcp14>MUST</bcp14></td>
          <td>author</td>
          <td>requesterDID</td>
        </tr>
        <tr>
          <td>CONSENT</td>
          <td><bcp14>MUST</bcp14></td>
          <td>author</td>
          <td>patientDID</td>
        </tr>
        <tr>
          <td>GRANT</td>
          <td><bcp14>MUST</bcp14></td>
          <td>author</td>
          <td>grantorDID</td>
        </tr>
        <tr>
          <td>RECEIPT</td>
          <td><bcp14>MUST</bcp14></td>
          <td>author</td>
          <td>receiverDID</td>
        </tr>
        <tr>
          <td>REVOKE</td>
          <td><bcp14>MUST</bcp14></td>
          <td>revocation</td>
          <td>revokerDID</td>
        </tr>
        <tr>
          <td>ERROR</td>
          <td><bcp14>MAY</bcp14></td>
          <td>author</td>
          <td>reporterDID</td>
        </tr>
        <tr>
          <td>ASSET_MANIFEST</td>
          <td><bcp14>MUST</bcp14></td>
          <td>author</td>
          <td>ownerDID</td>
        </tr>
        <tr>
          <td>METALOG_RECORD</td>
          <td><bcp14>MAY</bcp14></td>
          <td>author</td>
          <td>log owner (12.8)</td>
        </tr>
        <tr>
          <td>PROVENANCE_COMMITMENT</td>
          <td><bcp14>MUST</bcp14></td>
          <td>author</td>
          <td>originatorDID</td>
        </tr>
        <tr>
          <td>ANCHOR_RECEIPT</td>
          <td><bcp14>MUST</bcp14></td>
          <td>anchor-service</td>
          <td>key authorized in TRUST_BUNDLE</td>
        </tr>
        <tr>
          <td>SNAPSHOT_MANIFEST</td>
          <td><bcp14>MUST</bcp14></td>
          <td>author</td>
          <td>ownerDID</td>
        </tr>
        <tr>
          <td>EMERGENCY_PROFILE</td>
          <td><bcp14>MUST</bcp14></td>
          <td>author</td>
          <td>issuerDID</td>
        </tr>
        <tr>
          <td>EMERGENCY_ACCESS_RECEIPT</td>
          <td><bcp14>MUST</bcp14></td>
          <td>responder</td>
          <td>responderDID</td>
        </tr>
        <tr>
          <td>TRUST_BUNDLE</td>
          <td><bcp14>MUST</bcp14></td>
          <td>bundle-issuer</td>
          <td>issuerDID</td>
        </tr>
        <tr>
          <td>DID_DOCUMENT</td>
          <td><bcp14>MUST</bcp14></td>
          <td>author</td>
          <td>see 12.15</td>
        </tr>
      </tbody>
    </table>
    <ul spacing="normal">
      <li>Allowed purposes: an entry's purpose <bcp14>MUST</bcp14> be either the type's required purpose or counter-signature (0x02). No other purpose may appear.</li>
      <li>Counter-signatures: a counter-signer's DID <bcp14>MUST</bcp14> differ from the principal's. A counter-signature is an endorsement of the content. It does not give the counter-signer any authority defined by this document.</li>
      <li>Stripping: an artifact of a <bcp14>MUST</bcp14>-signed type that lacks a valid required signature is rejected (MISSING_SIGNATURE or SIGNER_NOT_AUTHORIZED). Removing signatures and clearing FLAG_SIGNED therefore never yields an acceptable artifact.</li>
      <li>Optional signatures: if an ERROR or METALOG_RECORD carries any signature, the rules above apply to it in full.</li>
    </ul>
</section>
<section anchor="sec-8-7" numbered="true" toc="default">
  <name>Key Resolution</name>
    <t>Verifying a signature requires a public key bound to (signerDID, keyRef, alg). Receivers resolve keys offline, from these sources only:</t>
    <ol spacing="normal">
      <li>did:key <xref target="DIDKEY"/>. The receiver decodes the multibase/multicodec value. Ed25519 (multicodec 0xed) support is <bcp14>REQUIRED</bcp14>. Other key types <bcp14>MAY</bcp14> be supported once multicodec code points for them are registered. If keyRef is present, it <bcp14>MUST</bcp14> equal "#" followed by the method-specific identifier.</li>
      <li>TRUST_BUNDLE issuer records (Section <xref target="sec-12-14" format="counter"/>) from a bundle chain that the receiver has verified. Such a record binds a DID, a keyRef, an alg, a public key, a validity interval, and a bitmask of the purposes the key may be used for.</li>
      <li>DID_DOCUMENT envelopes (Section <xref target="sec-12-15" format="counter"/>) that the receiver has verified. A verification method qualifies only if it appears in the document's "assertionMethod" relationship (for signing) or "keyAgreement" relationship (for HPKE, Section <xref target="sec-10-2" format="counter"/>), and is encoded as a Multikey with publicKeyMultibase.</li>
    </ol>
    <t>When a key comes from a TRUST_BUNDLE, the receiver <bcp14>MUST</bcp14> also check that signedAt falls within the issuer record's validity interval, that the record's purpose bitmask includes the entry's purpose, and that no revocation record in the most recent verified bundle names the key (Section <xref target="sec-16-4" format="counter"/>). A failure is reported as KEY_UNRESOLVED, SIGNER_NOT_AUTHORIZED, or REVOKED.</t>
    <table anchor="tbl-signature-public-key-encodings">
      <name>Signature public key encodings</name>
      <thead>
        <tr>
          <th>alg</th>
          <th>Public key encoding</th>
          <th>Key length</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>0x01</td>
          <td>Ed25519 public key <xref target="RFC8032"/></td>
          <td>32</td>
        </tr>
        <tr>
          <td>0x02</td>
          <td>ML-DSA-44 public key <xref target="FIPS204"/></td>
          <td>1312</td>
        </tr>
      </tbody>
    </table>
    <t>0x03 | Ed25519 key || ML-DSA-44 key, | 1344.</t>
    <t>A receiver <bcp14>MAY</bcp14> require hybrid or post-quantum signatures for some types or principals. If an artifact meets every structural rule but not that policy, the receiver reports UNSUPPORTED_ALGORITHM.</t>
</section>
<section anchor="sec-8-8" numbered="true" toc="default">
  <name>Co-Signing and Later Endorsement</name>
    <t>Every signature covers every signature entry, so all signers of one artifact must agree on the complete artifact, the signedAt of each entry included, before anyone signs. A coordinator assembles the unsigned artifact, sends it to each signer, and collects the values.</t>
    <t>To endorse an artifact that has already been issued, a party issues a separate PROVENANCE_COMMITMENT (Section <xref target="sec-12-9" format="counter"/>) whose artifactRef is the target's ArtifactID. Appending a signature to an artifact that has already been issued changes its ArtifactID, and is therefore not an endorsement of it.</t>
</section>
</section>
<section anchor="sec-9" numbered="true" toc="default">
  <name>At-Rest Encrypted Blob Frame (VB01)</name>
    <t>A VB01 frame stores one encrypted asset payload. A frame is a stand-alone file, or the payload of a METALOG_RECORD. It is not an MDA/1 artifact and has its own magic number.</t>
<section anchor="sec-9-1" numbered="true" toc="default">
  <name>Frame Layout</name>
    <table anchor="tbl-vb01">
      <name>VB01 frame header (64 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>4</td><td>magic</td><td>bytes</td><td>ASCII "VB01"</td></tr>
        <tr><td>4</td><td>1</td><td>ver</td><td>u8</td><td>Frame version = 1</td></tr>
        <tr><td>5</td><td>1</td><td>aead</td><td>enum8</td><td>(13.25), closed</td></tr>
        <tr><td>6</td><td>1</td><td>bucketExp</td><td>u8</td><td>8..21</td></tr>
        <tr><td>7</td><td>1</td><td>flags</td><td>u8</td><td>Reserved, zero</td></tr>
        <tr><td>8</td><td>12</td><td>nonce</td><td>bytes</td><td>Random AEAD nonce</td></tr>
        <tr><td>20</td><td>12</td><td>(rsv)</td><td>bytes</td><td>Reserved, zero</td></tr>
        <tr><td>32</td><td>32</td><td>keyCommit</td><td>hash32</td><td>Key commitment</td></tr>
      </tbody>
    </table>
    <t>The header is followed by the AEAD ciphertext, including its 16-octet tag, which runs to the end of the frame. The frame's total size <bcp14>MUST</bcp14> be exactly 2^bucketExp octets, with 8 &lt;= bucketExp &lt;= 21. The frame size, and nothing else, reveals the bucket.</t>
</section>
<section anchor="sec-9-2" numbered="true" toc="default">
  <name>Key Derivation and Key Commitment</name>
    <t>Each asset version has a fresh 32-octet Data Encryption Key (DEK) from a CSPRNG. The nonce is 12 octets from a CSPRNG. Frame keys come from HKDF-SHA256 <xref target="RFC5869"/>:</t>
    <artwork type="ascii-art" align="left"><![CDATA[
PRK       = HKDF-Extract(salt = nonce, IKM = DEK)
K_enc     = HKDF-Expand(PRK, "MDA1 VB01 enc", 32)
keyCommit = HKDF-Expand(PRK, "MDA1 VB01 commit", 32)
]]></artwork>
    <t>The encryption key is AES-256-GCM <xref target="SP800-38D"/> under K_enc, with the header nonce, and with AAD equal to the 64-octet header exactly as written, keyCommit included. A receiver <bcp14>MUST</bcp14> recompute keyCommit from its DEK and compare it, in constant time, with the header before decrypting (KEY_COMMITMENT_MISMATCH). AES-GCM alone does not commit to its key; the keyCommit check makes the frame key-committing, which defeats key-partitioning and "invisible salamander" attacks when one DEK is wrapped for several recipients.</t>
    <t>The per-frame key derivation means that reusing a DEK across frames is safe as long as nonces differ. A DEK <bcp14>MUST NOT</bcp14> be used for more than 2^32 frames.</t>
</section>
<section anchor="sec-9-3" numbered="true" toc="default">
  <name>Plaintext Framing</name>
    <artwork type="ascii-art" align="left"><![CDATA[
plaintext = u32 plaintextLen || payload || zero padding
|plaintext| = 2^bucketExp - 64 - 16
]]></artwork>
    <t>plaintextLen <bcp14>MUST NOT</bcp14> exceed 2^bucketExp - 84. The padding <bcp14>MUST</bcp14> be zero; a receiver <bcp14>MUST</bcp14> check this after decryption. The true length exists only inside the ciphertext. No artifact defined in this document carries it in the clear.</t>
</section>
<section anchor="sec-9-4" numbered="true" toc="default">
  <name>Size Buckets</name>
    <t>An encoder <bcp14>MUST</bcp14> pick a bucketExp large enough to hold the payload. It <bcp14>MAY</bcp14> pick a larger one to hide the length better. How a deployment chooses buckets is policy; picking the smallest bucket that fits is <bcp14>RECOMMENDED</bcp14> unless the deployment has a stronger policy. Bucketing hides lengths only to within a factor of two (Section <xref target="sec-20-3" format="counter"/>).</t>
</section>
<section anchor="sec-9-5" numbered="true" toc="default">
  <name>Storage Naming</name>
    <t>A frame's blobHash is SHA-256 over the entire frame. Implementations that store frames as files <bcp14>SHOULD</bcp14> name each file with the lowercase hexadecimal blobHash and use two levels of directory fan-out taken from the first two octets: "ab/cd/abcd...". Before decrypting, a receiver <bcp14>MUST</bcp14> check that a retrieved frame's SHA-256 equals the blobHash it expects.</t>
</section>
</section>
<section anchor="sec-10" numbered="true" toc="default">
  <name>Key Wrapping for GRANT (HPKE)</name>
    <t>A GRANT gives one recipient the DEK of one asset version, wrapped with HPKE <xref target="RFC9180"/> in single-shot mode.</t>
<section anchor="sec-10-1" numbered="true" toc="default">
  <name>Suites and Modes</name>
    <table anchor="tbl-hpke-suites">
      <name>HPKE suites</name>
      <thead>
        <tr>
          <th>Suite</th>
          <th>KEM / KDF / AEAD</th>
          <th>enc</th>
          <th>Modes</th>
          <th>pk len</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>0x01</td>
          <td>DHKEM(X25519, HKDF-SHA256) / HKDF-SHA256 / AES-256-GCM (RFC 9180 ids 0x0020/0x0001/0x0002)</td>
          <td>32</td>
          <td>base, auth</td>
          <td>32</td>
        </tr>
        <tr>
          <td>0x02</td>
          <td>X-Wing <xref target="XWING"/> (X25519 + ML-KEM-768) / HKDF-SHA256 /AES-256-GCM</td>
          <td>1120</td>
          <td>base only</td>
          <td>1216</td>
        </tr>
      </tbody>
    </table>
    <t>hpkeMode uses the RFC 9180 mode values: 0x00 for base and 0x02 for auth. Suite 0x02 <bcp14>MUST</bcp14> use mode 0x00. ML-KEM <xref target="FIPS203"/> has no authenticated encapsulation, so a combination of auth mode with suite 0x02 is invalid and rejected (SEMANTIC_VIOLATION). In every mode, the GRANT signature (Section <xref target="sec-8-6" format="counter"/>) is what authenticates the sender. Auth mode only adds a binding between the KEM shared secret and the grantor's key-agreement key.</t>
</section>
<section anchor="sec-10-2" numbered="true" toc="default">
  <name>Recipient and Sender Keys</name>
    <t>granteeKeyRef <bcp14>MUST</bcp14> be present. It names a keyAgreement verification method of granteeDID, resolved as in Section <xref target="sec-8-7" format="counter"/> from a DID_DOCUMENT or a TRUST_BUNDLE issuer record whose subkind is the matching KEM key type (Section <xref target="sec-12-14" format="counter"/>). In auth mode, grantorKeyRef <bcp14>MUST</bcp14> be present and names a keyAgreement method of grantorDID. In base mode it <bcp14>MUST</bcp14> be absent. Encoders <bcp14>MUST NOT</bcp14> derive key-agreement keys from signing keys.</t>
</section>
<section anchor="sec-10-3" numbered="true" toc="default">
  <name>Encapsulation and AAD</name>
    <t>The encoder assembles the complete GRANT with wrappedDek set to zero, the HPKE enc already in place in the Blob section at encSpan, and crc32 set to zero. Because enc is an output of encapsulation, the encoder first runs SetupBaseS or SetupAuthS to obtain enc and the context, places enc, and then computes:</t>
    <artwork type="ascii-art" align="left"><![CDATA[
info = "MDA1 GRANT v1"
aad  = SHA-256( "MDA1GAD\0" || G[0 .. sigValOff) )
wrappedDek = Seal(ctx, aad, DEK)            ; 32 + 16 = 48 octets
]]></artwork>
    <t>G is the artifact with crc32 and wrappedDek zeroed. The AAD thus authenticates the whole GRANT, strings and blob included, except the wrapped key itself. encSpan.len <bcp14>MUST</bcp14> equal the suite's enc length. Signing (Section <xref target="sec-8-4" format="counter"/>) happens after wrappedDek is written.</t>
</section>
<section anchor="sec-10-4" numbered="true" toc="default">
  <name>Decryption</name>
    <t>A recipient <bcp14>MUST</bcp14> complete validation phases A through D (Section <xref target="sec-15" format="counter"/>) on the GRANT, and on the CONSENT and ASSET_MANIFEST it references, before decapsulating. It then runs SetupBaseR or SetupAuthR with enc and the same info, opens wrappedDek with the same aad (DECRYPTION_FAILED on failure), checks the frame's blobHash against the ASSET_MANIFEST, verifies keyCommit, and decrypts the frame.</t>
</section>
</section>
<section anchor="sec-11" numbered="true" toc="default">
  <name>Type Registry</name>
    <table anchor="tbl-type-registry">
      <name>Type registry</name>
      <thead>
        <tr>
          <th>Code</th>
          <th>Artifact</th>
          <th>Body</th>
          <th>Stride</th>
          <th>Record</th>
          <th>Class</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>0x00</td>
          <td>(reserved, invalid)</td>
          <td>-</td>
          <td>-</td>
          <td>-</td>
          <td>-</td>
        </tr>
        <tr>
          <td>0x01</td>
          <td>REQUEST</td>
          <td>128</td>
          <td>48</td>
          <td>Generic</td>
          <td>control</td>
        </tr>
        <tr>
          <td>0x02</td>
          <td>CONSENT</td>
          <td>192</td>
          <td>48</td>
          <td>Generic</td>
          <td>control</td>
        </tr>
        <tr>
          <td>0x03</td>
          <td>GRANT</td>
          <td>256</td>
          <td>0</td>
          <td>-</td>
          <td>control</td>
        </tr>
        <tr>
          <td>0x04</td>
          <td>RECEIPT</td>
          <td>144</td>
          <td>0</td>
          <td>-</td>
          <td>control</td>
        </tr>
        <tr>
          <td>0x05</td>
          <td>REVOKE</td>
          <td>128</td>
          <td>0</td>
          <td>-</td>
          <td>control</td>
        </tr>
        <tr>
          <td>0x06</td>
          <td>ERROR</td>
          <td>96</td>
          <td>0</td>
          <td>-</td>
          <td>control</td>
        </tr>
        <tr>
          <td>0x10</td>
          <td>ASSET_MANIFEST</td>
          <td>192</td>
          <td>48</td>
          <td>Generic</td>
          <td>card</td>
        </tr>
        <tr>
          <td>0x11</td>
          <td>METALOG_RECORD</td>
          <td>112</td>
          <td>0</td>
          <td>-</td>
          <td>bundle</td>
        </tr>
        <tr>
          <td>0x12</td>
          <td>PROVENANCE_COMMITMENT</td>
          <td>192</td>
          <td>0</td>
          <td>-</td>
          <td>card</td>
        </tr>
        <tr>
          <td>0x13</td>
          <td>ANCHOR_RECEIPT</td>
          <td>160</td>
          <td>32</td>
          <td>Proof</td>
          <td>bundle</td>
        </tr>
        <tr>
          <td>0x14</td>
          <td>SNAPSHOT_MANIFEST</td>
          <td>128</td>
          <td>0</td>
          <td>-</td>
          <td>bundle</td>
        </tr>
        <tr>
          <td>0x20</td>
          <td>EMERGENCY_PROFILE</td>
          <td>208</td>
          <td>48</td>
          <td>Generic</td>
          <td>card</td>
        </tr>
        <tr>
          <td>0x21</td>
          <td>EMERGENCY_ACCESS_RECEIPT</td>
          <td>160</td>
          <td>0</td>
          <td>-</td>
          <td>card</td>
        </tr>
        <tr>
          <td>0x30</td>
          <td>TRUST_BUNDLE</td>
          <td>128</td>
          <td>96</td>
          <td>Trust</td>
          <td>bundle</td>
        </tr>
        <tr>
          <td>0x31</td>
          <td>DID_DOCUMENT</td>
          <td>128</td>
          <td>0</td>
          <td>-</td>
          <td>card</td>
        </tr>
        <tr>
          <td>0x80-0xBF</td>
          <td>Experimental Use</td>
          <td>any</td>
          <td>any</td>
          <td>opaque</td>
          <td>bundle</td>
        </tr>
        <tr>
          <td>0xC0-0xFF</td>
          <td>Private Use</td>
          <td>any</td>
          <td>any</td>
          <td>opaque</td>
          <td>bundle</td>
        </tr>
      </tbody>
    </table>
    <t>Code points not listed (0x07-0x0F, 0x15-0x1F, 0x22-0x2F, 0x32-0x7F) are unassigned. Receivers <bcp14>MUST</bcp14> reject them (UNKNOWN_TYPE). For experimental and private types, "any" means bodyLen is any multiple of 16 and recStride is any non-zero multiple of 16 when recCount &gt; 0. Section <xref target="sec-15-6" format="counter"/> gives the processing rules for them. VB01 frames are not MDA/1 artifacts and have no type code.</t>
    <t>Experimental codes <bcp14>MUST NOT</bcp14> appear in production deployments. Private codes <bcp14>MUST NOT</bcp14> appear in artifacts exchanged outside the organization that assigned them.</t>
</section>
<section anchor="sec-12" numbered="true" toc="default">
  <name>Artifact Definitions</name>
    <t>Body field offsets are relative to the start of the body, which is absolute offset 64. Each subsection lists the semantic rules that step D2 of the pipeline enforces (Section <xref target="sec-15-4" format="counter"/>). Where a rule needs another artifact (a "dependency") that the receiver does not hold, the receiver <bcp14>MUST NOT</bcp14> treat the artifact as authorizing anything (DEPENDENCY_MISSING). It <bcp14>MAY</bcp14> store the artifact and evaluate it again once the dependency arrives.</t>
<section anchor="sec-12-1" numbered="true" toc="default">
  <name>REQUEST (0x01)</name>
    <table anchor="tbl-request">
      <name>REQUEST body (128 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>16</td><td>requestId</td><td>raw16</td><td>Request identifier</td></tr>
        <tr><td>16</td><td>16</td><td>sessionId</td><td>raw16</td><td>Session identifier</td></tr>
        <tr><td>32</td><td>16</td><td>nonce</td><td>raw16</td><td>Replay nonce</td></tr>
        <tr><td>48</td><td>8</td><td>issuedAt</td><td>ts</td><td>Issuance time</td></tr>
        <tr><td>56</td><td>8</td><td>expiresAt</td><td>ts</td><td>Expiry time</td></tr>
        <tr><td>64</td><td>4</td><td>requesterDID</td><td>str_ref</td><td>Requester (signer)</td></tr>
        <tr><td>68</td><td>4</td><td>purpose</td><td>str_ref</td><td>Purpose of use</td></tr>
        <tr><td>72</td><td>2</td><td>requestedActions</td><td>u16</td><td>Bitmask (13.4)</td></tr>
        <tr><td>74</td><td>2</td><td>(rsv)</td><td>u16</td><td>Reserved</td></tr>
        <tr><td>76</td><td>4</td><td>(rsv)</td><td>u32</td><td>Reserved</td></tr>
        <tr><td>80</td><td>32</td><td>requesterVCHash</td><td>hash32</td><td>Requester VC digest</td></tr>
        <tr><td>112</td><td>16</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
      </tbody>
    </table>
    <ul spacing="normal">
      <li>recCount &gt;= 1. Every record is a Scope record (reckind 0x05).</li>
      <li>issuedAt &lt; expiresAt, and expiresAt - issuedAt &lt;= 30 days.</li>
      <li>requestedActions <bcp14>MUST</bcp14> be non-zero, and its undefined bits <bcp14>MUST</bcp14> be zero.</li>
      <li>requesterVCHash is the SHA-256 of the octets of the requester's verifiable credential <xref target="VC"/> exactly as presented (for example, the compact serialization of a VC-JWT), or zero if no credential is presented. Validating the credential is outside the scope of this document. If a credential is presented, its digest <bcp14>MUST</bcp14> match.</li>
    </ul>
</section>
<section anchor="sec-12-2" numbered="true" toc="default">
  <name>CONSENT (0x02)</name>
    <table anchor="tbl-consent">
      <name>CONSENT body (192 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>16</td><td>consentId</td><td>raw16</td><td>Consent identifier</td></tr>
        <tr><td>16</td><td>32</td><td>requestRef</td><td>hash32</td><td>REQUEST ArtifactID or 0</td></tr>
        <tr><td>48</td><td>2</td><td>consentVersion</td><td>u16</td><td>Starts at 1</td></tr>
        <tr><td>50</td><td>2</td><td>allowedActions</td><td>u16</td><td>Bitmask (13.4)</td></tr>
        <tr><td>52</td><td>4</td><td>(rsv)</td><td>u32</td><td>Reserved</td></tr>
        <tr><td>56</td><td>8</td><td>validFrom</td><td>ts</td><td>Validity start</td></tr>
        <tr><td>64</td><td>8</td><td>validUntil</td><td>ts</td><td>Validity end</td></tr>
        <tr><td>72</td><td>4</td><td>patientDID</td><td>str_ref</td><td>Patient (signer)</td></tr>
        <tr><td>76</td><td>4</td><td>granteeDID</td><td>str_ref</td><td>Grantee</td></tr>
        <tr><td>80</td><td>4</td><td>granteeDisplay</td><td>str_ref</td><td>Display name</td></tr>
        <tr><td>84</td><td>4</td><td>purpose</td><td>str_ref</td><td>Purpose of use</td></tr>
        <tr><td>88</td><td>4</td><td>delegateDID</td><td>str_ref</td><td>May issue GRANTs</td></tr>
        <tr><td>92</td><td>4</td><td>maxGrantTtlSec</td><td>u32</td><td>Max GRANT lifetime, s</td></tr>
        <tr><td>96</td><td>32</td><td>scopeDigest</td><td>hash32</td><td>ScopeDigest (7.5)</td></tr>
        <tr><td>128</td><td>32</td><td>supersedesRef</td><td>hash32</td><td>Prior version ArtifactID</td></tr>
        <tr><td>160</td><td>32</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
      </tbody>
    </table>
    <ul spacing="normal">
      <li>recCount &gt;= 1. Every record is a Scope record. scopeDigest <bcp14>MUST</bcp14> equal the ScopeDigest (Section <xref target="sec-7-5" format="counter"/>) of the records.</li>
      <li>patientDID and granteeDID <bcp14>MUST</bcp14> be present. delegateDID is <bcp14>OPTIONAL</bcp14>. When present, it names a party that may issue GRANTs under this CONSENT on the patient's behalf.</li>
      <li>validFrom &lt; validUntil. maxGrantTtlSec &gt;= 1.</li>
      <li>allowedActions <bcp14>MUST</bcp14> include read (bit 0). Its undefined bits <bcp14>MUST</bcp14> be zero.</li>
      <li>consentVersion &gt;= 1. supersedesRef is zero if and only if consentVersion = 1. Otherwise it is the ArtifactID of the CONSENT with the same consentId and patientDID and version consentVersion - 1. A receiver holding that earlier version <bcp14>MUST</bcp14> check this link. Among the versions it holds, the highest valid one is in force.</li>
      <li>requestRef, when non-zero, is the ArtifactID of the REQUEST that led to this CONSENT.</li>
    </ul>
</section>
<section anchor="sec-12-3" numbered="true" toc="default">
  <name>GRANT (0x03)</name>
    <table anchor="tbl-grant">
      <name>GRANT body (256 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>16</td><td>grantId</td><td>raw16</td><td>Grant identifier</td></tr>
        <tr><td>16</td><td>16</td><td>sessionId</td><td>raw16</td><td>Session identifier</td></tr>
        <tr><td>32</td><td>16</td><td>nonce</td><td>raw16</td><td>Replay nonce</td></tr>
        <tr><td>48</td><td>8</td><td>issuedAt</td><td>ts</td><td>Issuance time</td></tr>
        <tr><td>56</td><td>8</td><td>expiresAt</td><td>ts</td><td>Expiry time</td></tr>
        <tr><td>64</td><td>8</td><td>grantSeq</td><td>u64</td><td>Per-pair sequence</td></tr>
        <tr><td>72</td><td>4</td><td>granteeDID</td><td>str_ref</td><td>Recipient</td></tr>
        <tr><td>76</td><td>4</td><td>grantorDID</td><td>str_ref</td><td>Grantor (signer)</td></tr>
        <tr><td>80</td><td>4</td><td>purpose</td><td>str_ref</td><td>Purpose of use</td></tr>
        <tr><td>84</td><td>2</td><td>assetVersion</td><td>u16</td><td>Asset version</td></tr>
        <tr><td>86</td><td>1</td><td>hpkeMode</td><td>enum8</td><td>RFC 9180 mode, closed</td></tr>
        <tr><td>87</td><td>1</td><td>hpkeSuite</td><td>enum8</td><td>Suite (13.6), closed</td></tr>
        <tr><td>88</td><td>16</td><td>assetId</td><td>raw16</td><td>Asset identifier</td></tr>
        <tr><td>104</td><td>32</td><td>consentRef</td><td>hash32</td><td>CONSENT ArtifactID</td></tr>
        <tr><td>136</td><td>32</td><td>manifestRef</td><td>hash32</td><td>ASSET_MANIFEST ArtifactID</td></tr>
        <tr><td>168</td><td>8</td><td>encSpan</td><td>span</td><td>HPKE enc in Blob</td></tr>
        <tr><td>176</td><td>48</td><td>wrappedDek</td><td>bytes</td><td>HPKE ciphertext of DEK</td></tr>
        <tr><td>224</td><td>4</td><td>granteeKeyRef</td><td>str_ref</td><td>Recipient key id</td></tr>
        <tr><td>228</td><td>4</td><td>grantorKeyRef</td><td>str_ref</td><td>Sender key id (auth)</td></tr>
        <tr><td>232</td><td>24</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
      </tbody>
    </table>
    <t>Given the referenced CONSENT c and ASSET_MANIFEST m, every one of the following <bcp14>MUST</bcp14> hold. c and m are dependencies.</t>
    <ul spacing="normal">
      <li>c and m have both passed validation and are not revoked.</li>
      <li>grantorDID equals c.patientDID, or equals c.delegateDID when that field is present.</li>
      <li>granteeDID equals c.granteeDID, and purpose equals c.purpose.</li>
      <li>c.validFrom &lt;= issuedAt, expiresAt &lt;= c.validUntil, issuedAt &lt; expiresAt, and expiresAt - issuedAt &lt;= c.maxGrantTtlSec * 1000.</li>
      <li>assetId and assetVersion equal m.assetId and m.version, and m matches c's Scope records (Section <xref target="sec-7-4" format="counter"/>).</li>
      <li>hpkeMode, hpkeSuite, encSpan, granteeKeyRef, and grantorKeyRef follow Section <xref target="sec-10" format="counter"/>.</li>
    </ul>
    <t>grantSeq orders the GRANTs between one grantor and one grantee. When two valid GRANTs from the same pair cover the same assetId, the one with the higher grantSeq takes precedence.</t>
</section>
<section anchor="sec-12-4" numbered="true" toc="default">
  <name>RECEIPT (0x04)</name>
    <table anchor="tbl-receipt">
      <name>RECEIPT body (144 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>16</td><td>receiptId</td><td>raw16</td><td>Receipt identifier</td></tr>
        <tr><td>16</td><td>16</td><td>sessionId</td><td>raw16</td><td>Session identifier</td></tr>
        <tr><td>32</td><td>16</td><td>nonce</td><td>raw16</td><td>Replay nonce</td></tr>
        <tr><td>48</td><td>8</td><td>receivedAt</td><td>ts</td><td>Delivery time</td></tr>
        <tr><td>56</td><td>4</td><td>receiverDID</td><td>str_ref</td><td>Receiver (signer)</td></tr>
        <tr><td>60</td><td>1</td><td>channel</td><td>enum8</td><td>Channel (13.7), open</td></tr>
        <tr><td>61</td><td>1</td><td>outcome</td><td>enum8</td><td>Outcome (13.8), open</td></tr>
        <tr><td>62</td><td>2</td><td>(rsv)</td><td>u16</td><td>Reserved</td></tr>
        <tr><td>64</td><td>32</td><td>grantRef</td><td>hash32</td><td>GRANT ArtifactID</td></tr>
        <tr><td>96</td><td>32</td><td>assetRef</td><td>hash32</td><td>SHA-256 of VB01 file</td></tr>
        <tr><td>128</td><td>16</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
      </tbody>
    </table>
    <ul spacing="normal">
      <li>grantRef is the ArtifactID of the GRANT being acknowledged (a dependency). receiverDID <bcp14>MUST</bcp14> equal that GRANT's granteeDID.</li>
      <li>assetRef is the blobHash of the frame received, or zero when outcome is rejected (0x03) or deferred (0x04).</li>
    </ul>
</section>
<section anchor="sec-12-5" numbered="true" toc="default">
  <name>REVOKE (0x05)</name>
    <table anchor="tbl-revoke">
      <name>REVOKE body (128 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>16</td><td>revokeId</td><td>raw16</td><td>Revocation identifier</td></tr>
        <tr><td>16</td><td>16</td><td>nonce</td><td>raw16</td><td>Replay nonce</td></tr>
        <tr><td>32</td><td>8</td><td>revokedAt</td><td>ts</td><td>Time of revocation</td></tr>
        <tr><td>40</td><td>8</td><td>effectiveAt</td><td>ts</td><td>Effective time</td></tr>
        <tr><td>48</td><td>4</td><td>revokerDID</td><td>str_ref</td><td>Revoker (signer)</td></tr>
        <tr><td>52</td><td>4</td><td>reasonText</td><td>str_ref</td><td>Explanation</td></tr>
        <tr><td>56</td><td>1</td><td>targetKind</td><td>enum8</td><td>Kind (13.9), closed</td></tr>
        <tr><td>57</td><td>1</td><td>reasonCode</td><td>enum8</td><td>Reason (13.10), open</td></tr>
        <tr><td>58</td><td>6</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
        <tr><td>64</td><td>32</td><td>targetRef</td><td>hash32</td><td>Target ArtifactID/key</td></tr>
        <tr><td>96</td><td>32</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
      </tbody>
    </table>
    <t>targetRef is the ArtifactID of the target artifact. For targetKind key (0x07) it is instead the SHA-256 of the public key encoding (Section <xref target="sec-8-7" format="counter"/>). The revoker must hold authority over the target:</t>
    <table anchor="tbl-revocation-authority">
      <name>Revocation authority</name>
      <thead>
        <tr>
          <th>targetKind</th>
          <th>revokerDID <bcp14>MUST</bcp14> equal</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>consent (0x01)</td>
          <td>the CONSENT's patientDID</td>
        </tr>
        <tr>
          <td>grant (0x02)</td>
          <td>the GRANT's grantorDID, or the patientDID of the CONSENT it references</td>
        </tr>
        <tr>
          <td>emergency profile</td>
          <td>the profile's patientDID or issuerDID</td>
        </tr>
        <tr>
          <td>(0x03)</td>
          <td></td>
        </tr>
        <tr>
          <td>DID document (0x04)</td>
          <td>the document's targetDID</td>
        </tr>
        <tr>
          <td>asset manifest (0x05)</td>
          <td>the manifest's ownerDID</td>
        </tr>
        <tr>
          <td>provenance (0x08)</td>
          <td>the commitment's originatorDID</td>
        </tr>
        <tr>
          <td>trust bundle (0x06),</td>
          <td>not revocable by REVOKE; use TRUST_BUNDLE</td>
        </tr>
        <tr>
          <td>key (0x07)</td>
          <td>revocation records (Section <xref target="sec-12-14" format="counter"/>), unless revokerDID is the key's own DID</td>
        </tr>
      </tbody>
    </table>
    <ul spacing="normal">
      <li>effectiveAt <bcp14>MAY</bcp14> be earlier than revokedAt, which makes the revocation retroactive (for example, for a lost device). From effectiveAt on, the target is invalid. Artifacts that depend on the target and were signed at or after effectiveAt are invalid too.</li>
      <li>A revocation is final. Nothing un-revokes a target; a new artifact replaces it. Checking authority needs the target, so the target is a dependency. A receiver that does not hold the target <bcp14>MUST</bcp14> still keep the REVOKE and apply it if the target arrives later.</li>
    </ul>
</section>
<section anchor="sec-12-6" numbered="true" toc="default">
  <name>ERROR (0x06)</name>
    <table anchor="tbl-error">
      <name>ERROR body (96 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>16</td><td>errorId</td><td>raw16</td><td>Error identifier</td></tr>
        <tr><td>16</td><td>16</td><td>sessionId</td><td>raw16</td><td>Session, or 0</td></tr>
        <tr><td>32</td><td>32</td><td>relatesTo</td><td>hash32</td><td>SHA-256 of input octets</td></tr>
        <tr><td>64</td><td>8</td><td>occurredAt</td><td>ts</td><td>Detection time</td></tr>
        <tr><td>72</td><td>2</td><td>errorCode</td><td>u16</td><td>Code (13.24), open</td></tr>
        <tr><td>74</td><td>1</td><td>failedStep</td><td>u8</td><td>Pipeline step (15)</td></tr>
        <tr><td>75</td><td>1</td><td>(rsv)</td><td>u8</td><td>Reserved</td></tr>
        <tr><td>76</td><td>4</td><td>detailOffset</td><td>u32</td><td>Byte offset or ~0</td></tr>
        <tr><td>80</td><td>4</td><td>message</td><td>str_ref</td><td>Human-readable text</td></tr>
        <tr><td>84</td><td>4</td><td>reporterDID</td><td>str_ref</td><td>Reporter</td></tr>
        <tr><td>88</td><td>8</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
      </tbody>
    </table>
    <ul spacing="normal">
      <li>relatesTo is SHA-256 over the raw octets received. It is not an ArtifactID, because the input may not parse. failedStep encodes the pipeline step (Section <xref target="sec-15" format="counter"/>) as phase * 16 + step, where A = 1, B = 2, C = 3, and D = 4; step B3, for example, is 0x23. detailOffset is the octet offset where the failure was detected, or 0xFFFFFFFF if none applies.</li>
      <li>message <bcp14>MUST NOT</bcp14> contain personal or health data.</li>
      <li>An ERROR <bcp14>MUST NOT</bcp14> be sent in response to an ERROR. A receiver <bcp14>MUST NOT</bcp14> change any authorization or stored state on the strength of an unsigned ERROR. It may only display the error, log it, or retry.</li>
    </ul>
</section>
<section anchor="sec-12-7" numbered="true" toc="default">
  <name>ASSET_MANIFEST (0x10)</name>
    <table anchor="tbl-asset-manifest">
      <name>ASSET_MANIFEST body (192 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>16</td><td>assetId</td><td>raw16</td><td>Asset identifier</td></tr>
        <tr><td>16</td><td>2</td><td>version</td><td>u16</td><td>Starts at 1</td></tr>
        <tr><td>18</td><td>1</td><td>contentType</td><td>enum8</td><td>Type (13.11), open</td></tr>
        <tr><td>19</td><td>1</td><td>bucketExp</td><td>u8</td><td>VB01 bucket exponent</td></tr>
        <tr><td>20</td><td>4</td><td>(rsv)</td><td>u32</td><td>Reserved</td></tr>
        <tr><td>24</td><td>8</td><td>capturedAt</td><td>ts</td><td>Acquisition time</td></tr>
        <tr><td>32</td><td>4</td><td>ownerDID</td><td>str_ref</td><td>Owner (signer)</td></tr>
        <tr><td>36</td><td>4</td><td>title</td><td>str_ref</td><td>Title, <bcp14>OPTIONAL</bcp14></td></tr>
        <tr><td>40</td><td>4</td><td>source</td><td>str_ref</td><td>Origin hint, <bcp14>OPTIONAL</bcp14></td></tr>
        <tr><td>44</td><td>4</td><td>(rsv)</td><td>u32</td><td>Reserved</td></tr>
        <tr><td>48</td><td>32</td><td>blobHash</td><td>hash32</td><td>SHA-256 of VB01 file</td></tr>
        <tr><td>80</td><td>32</td><td>priorVersionRef</td><td>hash32</td><td>Prior ArtifactID or 0</td></tr>
        <tr><td>112</td><td>32</td><td>provenanceRef</td><td>hash32</td><td>PROVENANCE ArtifactID/0</td></tr>
        <tr><td>144</td><td>48</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
      </tbody>
    </table>
    <ul spacing="normal">
      <li>Records, if any, are Tag records (reckind 0x06).</li>
      <li>blobHash is SHA-256 over the asset's VB01 frame. bucketExp <bcp14>MUST</bcp14> equal the frame's bucketExp.</li>
      <li>version &gt;= 1. priorVersionRef is zero if and only if version = 1.</li>
      <li>The manifest is signed but not encrypted. title, source, Tag records, and contentType are visible to anyone who holds it. For sensitive assets, encoders <bcp14>SHOULD</bcp14> leave title and source absent, <bcp14>SHOULD</bcp14> use contentType undisclosed (0x00), and <bcp14>SHOULD</bcp14> put descriptive metadata inside the encrypted payload (Section <xref target="sec-20-2" format="counter"/>). The manifest deliberately carries no plaintext length and no plaintext hash.</li>
    </ul>
</section>
<section anchor="sec-12-8" numbered="true" toc="default">
  <name>METALOG_RECORD (0x11)</name>
    <table anchor="tbl-metalog-record">
      <name>METALOG_RECORD body (112 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>8</td><td>seq</td><td>u64</td><td>Sequence, genesis = 0</td></tr>
        <tr><td>8</td><td>2</td><td>recordType</td><td>u16</td><td>Payload type code or 0</td></tr>
        <tr><td>10</td><td>2</td><td>flags</td><td>u16</td><td>Reserved in minor 0</td></tr>
        <tr><td>12</td><td>4</td><td>payloadLen</td><td>u32</td><td><bcp14>MUST</bcp14> equal span len</td></tr>
        <tr><td>16</td><td>32</td><td>prevHash</td><td>hash32</td><td>Previous recordHash</td></tr>
        <tr><td>48</td><td>32</td><td>payloadHash</td><td>hash32</td><td>SHA-256 of payload</td></tr>
        <tr><td>80</td><td>8</td><td>payloadSpan</td><td>span</td><td>VB01 frame in Blob</td></tr>
        <tr><td>88</td><td>8</td><td>loggedAt</td><td>ts</td><td>Append time</td></tr>
        <tr><td>96</td><td>16</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
      </tbody>
    </table>
    <t>The payload is one VB01 frame at payloadSpan, so payloadLen = payloadSpan.len = 2^bucketExp. payloadHash = SHA-256(payload). recordType is the type code of the MDA/1 artifact encrypted in the payload, or 0 if the payload is opaque. The record's chain hash is:</t>
    <artwork type="ascii-art" align="left"><![CDATA[
recordHash = SHA-256( "MDA1LOG\0" || prevHash || u64 seq ||
                      u16 recordType || u16 flags ||
                      u32 payloadLen || u64 loggedAt || payloadHash )
]]></artwork>
    <t>The genesis record has seq = 0 and a prevHash of 32 zero octets. Each later record has seq = previous seq + 1 and prevHash = previous recordHash. The chain commits to ciphertext, so anyone can audit it without keys. Integrity is relative to a trusted chain head: one from a verified SNAPSHOT_MANIFEST, or from a final ANCHOR_RECEIPT with valueKind chain-head. A METALOG_RECORD <bcp14>MAY</bcp14> be signed by the log owner, whom deployment policy identifies.</t>
</section>
<section anchor="sec-12-9" numbered="true" toc="default">
  <name>PROVENANCE_COMMITMENT (0x12)</name>
    <table anchor="tbl-provenance-commitment">
      <name>PROVENANCE_COMMITMENT body (192 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>16</td><td>commitmentId</td><td>raw16</td><td>Commitment identifier</td></tr>
        <tr><td>16</td><td>8</td><td>createdAt</td><td>ts</td><td>Creation time</td></tr>
        <tr><td>24</td><td>1</td><td>targetType</td><td>u8</td><td>Target type code</td></tr>
        <tr><td>25</td><td>1</td><td>issuerKind</td><td>enum8</td><td>Kind (13.12), open</td></tr>
        <tr><td>26</td><td>2</td><td>(rsv)</td><td>u16</td><td>Reserved</td></tr>
        <tr><td>28</td><td>4</td><td>originatorDID</td><td>str_ref</td><td>Originator (signer)</td></tr>
        <tr><td>32</td><td>4</td><td>subjectDID</td><td>str_ref</td><td>Subject, <bcp14>OPTIONAL</bcp14></td></tr>
        <tr><td>36</td><td>4</td><td>displayHint</td><td>str_ref</td><td>Display hint, <bcp14>OPTIONAL</bcp14></td></tr>
        <tr><td>40</td><td>4</td><td>(rsv)</td><td>u32</td><td>Reserved</td></tr>
        <tr><td>44</td><td>4</td><td>(rsv)</td><td>u32</td><td>Reserved</td></tr>
        <tr><td>48</td><td>32</td><td>artifactRef</td><td>hash32</td><td>Target ArtifactID</td></tr>
        <tr><td>80</td><td>32</td><td>originatorVCHash</td><td>hash32</td><td>Originator VC digest</td></tr>
        <tr><td>112</td><td>32</td><td>priorVersionRef</td><td>hash32</td><td>Prior ArtifactID or 0</td></tr>
        <tr><td>144</td><td>32</td><td>consentRef</td><td>hash32</td><td>CONSENT ArtifactID or 0</td></tr>
        <tr><td>176</td><td>16</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
      </tbody>
    </table>
    <ul spacing="normal">
      <li>artifactRef <bcp14>MUST</bcp14> be non-zero, and targetType <bcp14>MUST</bcp14> be the type code of the artifact it references. A receiver that holds the target <bcp14>MUST</bcp14> check targetType. Provenance for asset content references the content's ASSET_MANIFEST.</li>
      <li>A PROVENANCE_COMMITMENT also serves as a later, detached endorsement of an artifact (Section <xref target="sec-8-8" format="counter"/>).</li>
    </ul>
</section>
<section anchor="sec-12-10" numbered="true" toc="default">
  <name>ANCHOR_RECEIPT (0x13)</name>
    <table anchor="tbl-anchor-receipt">
      <name>ANCHOR_RECEIPT body (160 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>16</td><td>anchorId</td><td>raw16</td><td>Anchor identifier</td></tr>
        <tr><td>16</td><td>8</td><td>anchoredAt</td><td>ts</td><td>Anchoring time</td></tr>
        <tr><td>24</td><td>1</td><td>backend</td><td>enum8</td><td>Ledger (13.13), open</td></tr>
        <tr><td>25</td><td>1</td><td>status</td><td>enum8</td><td>Status (13.14), closed</td></tr>
        <tr><td>26</td><td>1</td><td>valueKind</td><td>enum8</td><td>Kind (13.15), closed</td></tr>
        <tr><td>27</td><td>1</td><td>(rsv)</td><td>u8</td><td>Reserved</td></tr>
        <tr><td>28</td><td>4</td><td>checkpointRef</td><td>str_ref</td><td>Log/checkpoint label</td></tr>
        <tr><td>32</td><td>8</td><td>leafIndex</td><td>u64</td><td>RFC 9162 leaf index</td></tr>
        <tr><td>40</td><td>8</td><td>treeSize</td><td>u64</td><td>RFC 9162 tree size</td></tr>
        <tr><td>48</td><td>32</td><td>anchoredValue</td><td>hash32</td><td>Value committed as leaf</td></tr>
        <tr><td>80</td><td>32</td><td>rootHash</td><td>hash32</td><td>RFC 9162 root hash</td></tr>
        <tr><td>112</td><td>8</td><td>txRef</td><td>span</td><td>Ledger tx reference</td></tr>
        <tr><td>120</td><td>8</td><td>blockRef</td><td>span</td><td>Ledger block reference</td></tr>
        <tr><td>128</td><td>8</td><td>evidenceSpan</td><td>span</td><td>Backend evidence</td></tr>
        <tr><td>136</td><td>24</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
      </tbody>
    </table>
    <table anchor="tbl-proofrecord">
      <name>Proof record (RS 32) (32 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>32</td><td>node</td><td>hash32</td><td>Audit path node</td></tr>
      </tbody>
    </table>
    <t>The anchored leaf is the RFC 9162 <xref target="RFC9162"/> Merkle leaf over anchoredValue, the 32-octet value itself:</t>
    <artwork type="ascii-art" align="left"><![CDATA[
leafHash = SHA-256( 0x00 || anchoredValue )
]]></artwork>
    <t>Proof records form the RFC 9162 inclusion proof (audit path), in path order from the leaf toward the root. They are exempt from Section <xref target="sec-7-1" format="counter"/> sorting and may repeat. If status is final (0x02), these <bcp14>MUST</bcp14> hold:</t>
    <ul spacing="normal">
      <li>leafIndex &lt; treeSize.</li>
      <li>recCount equals the audit path length for (leafIndex, treeSize).</li>
      <li>Running the verification algorithm of <xref target="RFC9162" section="2.1.3.2" sectionFormat="comma"/>, with leafHash, leafIndex, treeSize, and the proof yields rootHash.</li>
    </ul>
    <t>If status is pending (0x01) or failed (0x03), leafIndex, treeSize, and rootHash <bcp14>MUST</bcp14> be zero and recCount <bcp14>MUST</bcp14> be 0. Only a final receipt provides any assurance.</t>
    <t>txRef and blockRef, when present, hold ASCII identifiers chosen by the backend (for example, a hexadecimal transaction hash). evidenceSpan holds the backend's evidence. For backend RFC 3161 TSA (0x05) it is <bcp14>REQUIRED</bcp14> and holds a DER-encoded TimeStampToken <xref target="RFC3161"/> whose messageImprint is SHA-256 over rootHash. All three are covered by the signature. The anchor-service signer <bcp14>MUST</bcp14> be authorized for purpose anchor-service by a TRUST_BUNDLE issuer record.</t>
</section>
<section anchor="sec-12-11" numbered="true" toc="default">
  <name>SNAPSHOT_MANIFEST (0x14)</name>
    <table anchor="tbl-snapshot-manifest">
      <name>SNAPSHOT_MANIFEST body (128 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>16</td><td>snapshotId</td><td>raw16</td><td>Snapshot identifier</td></tr>
        <tr><td>16</td><td>8</td><td>createdAt</td><td>ts</td><td>Snapshot time</td></tr>
        <tr><td>24</td><td>8</td><td>watermarkSeq</td><td>u64</td><td>Highest included seq</td></tr>
        <tr><td>32</td><td>32</td><td>chainHead</td><td>hash32</td><td>recordHash at watermark</td></tr>
        <tr><td>64</td><td>32</td><td>indexHash</td><td>hash32</td><td>Index state digest</td></tr>
        <tr><td>96</td><td>4</td><td>logRecordCount</td><td>u32</td><td>Records retained</td></tr>
        <tr><td>100</td><td>2</td><td>segmentCount</td><td>u16</td><td>Segment file count</td></tr>
        <tr><td>102</td><td>2</td><td>(rsv)</td><td>u16</td><td>Reserved</td></tr>
        <tr><td>104</td><td>4</td><td>ownerDID</td><td>str_ref</td><td>Log owner (signer)</td></tr>
        <tr><td>108</td><td>20</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
      </tbody>
    </table>
    <ul spacing="normal">
      <li>chainHead is the recordHash (Section <xref target="sec-12-8" format="counter"/>) of the record whose seq is watermarkSeq.</li>
      <li>logRecordCount &lt;= watermarkSeq + 1, since records before a pruning point need not be kept.</li>
      <li>indexHash is an implementation-defined digest of the local index state. It has meaning only to the implementation that produced it and <bcp14>MUST NOT</bcp14> be used for interoperable decisions.</li>
    </ul>
</section>
<section anchor="sec-12-12" numbered="true" toc="default">
  <name>EMERGENCY_PROFILE (0x20)</name>
    <table anchor="tbl-emergency-profile">
      <name>EMERGENCY_PROFILE body (208 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>16</td><td>profileId</td><td>raw16</td><td>Profile identifier</td></tr>
        <tr><td>16</td><td>2</td><td>profileVersion</td><td>u16</td><td>Starts at 1</td></tr>
        <tr><td>18</td><td>1</td><td>bloodType</td><td>enum8</td><td>(13.16), open</td></tr>
        <tr><td>19</td><td>1</td><td>issuerKind</td><td>enum8</td><td>(13.12), open</td></tr>
        <tr><td>20</td><td>1</td><td>resuscitation</td><td>enum8</td><td>(13.17), open</td></tr>
        <tr><td>21</td><td>1</td><td>organDonor</td><td>enum8</td><td>(13.18), open</td></tr>
        <tr><td>22</td><td>2</td><td>(rsv)</td><td>u16</td><td>Reserved</td></tr>
        <tr><td>24</td><td>8</td><td>validFrom</td><td>ts</td><td>Validity start</td></tr>
        <tr><td>32</td><td>8</td><td>validUntil</td><td>ts</td><td>Validity end</td></tr>
        <tr><td>40</td><td>4</td><td>patientDID</td><td>str_ref</td><td>Patient</td></tr>
        <tr><td>44</td><td>4</td><td>issuerDID</td><td>str_ref</td><td>Issuer (signer)</td></tr>
        <tr><td>48</td><td>4</td><td>displayName</td><td>str_ref</td><td>Patient name</td></tr>
        <tr><td>52</td><td>4</td><td>preferredLanguage</td><td>str_ref</td><td>BCP 47 tag</td></tr>
        <tr><td>56</td><td>4</td><td>clinicianName</td><td>str_ref</td><td><bcp14>OPTIONAL</bcp14></td></tr>
        <tr><td>60</td><td>4</td><td>clinicianInstitution</td><td>str_ref</td><td><bcp14>OPTIONAL</bcp14></td></tr>
        <tr><td>64</td><td>32</td><td>issuerVCHash</td><td>hash32</td><td>Issuer VC digest</td></tr>
        <tr><td>96</td><td>32</td><td>directiveRef</td><td>hash32</td><td>Directive manifest or 0</td></tr>
        <tr><td>128</td><td>32</td><td>anchorReceiptRef</td><td>hash32</td><td>ANCHOR ArtifactID or 0</td></tr>
        <tr><td>160</td><td>32</td><td>priorVersionRef</td><td>hash32</td><td>Prior ArtifactID or 0</td></tr>
        <tr><td>192</td><td>16</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
      </tbody>
    </table>
    <ul spacing="normal">
      <li>Records are Allergy, Medication, Condition, or Contact records (Section <xref target="sec-7-3" format="counter"/>).</li>
      <li>patientDID, issuerDID, and displayName <bcp14>MUST</bcp14> be present. When issuerKind is patient (0x01), issuerDID <bcp14>MUST</bcp14> equal patientDID.</li>
      <li>preferredLanguage, when present, is a BCP 47 language tag <xref target="RFC5646"/>.</li>
      <li>directiveRef, when non-zero, is the ArtifactID of an ASSET_MANIFEST with contentType directive (0x07).</li>
      <li>profileVersion and priorVersionRef follow the versioning rule in Section <xref target="sec-12-7" format="counter"/>.</li>
      <li>For safety, a receiver <bcp14>MUST</bcp14> display an unknown value of an open enumeration (bloodType, resuscitation, organDonor, record subkinds) as "unrecognized value". It <bcp14>MUST NOT</bcp14> map such a value to a default or to "unknown".</li>
      <li>An expired or not-yet-valid profile <bcp14>MAY</bcp14> be displayed in an emergency, but only with a prominent indication of its status (Section <xref target="sec-16-2" format="counter"/>).</li>
    </ul>
    <t>A profile is deliberately readable by anyone who holds it. Deployments that need to control who can read it <bcp14>MUST</bcp14> carry the profile content as an encrypted asset (ASSET_MANIFEST plus VB01) with GRANTs, and <bcp14>MUST NOT</bcp14> rely on EMERGENCY_PROFILE for confidentiality.</t>
</section>
<section anchor="sec-12-13" numbered="true" toc="default">
  <name>EMERGENCY_ACCESS_RECEIPT (0x21)</name>
    <table anchor="tbl-emergency-access-receipt">
      <name>EMERGENCY_ACCESS_RECEIPT body (160 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>16</td><td>receiptId</td><td>raw16</td><td>Receipt identifier</td></tr>
        <tr><td>16</td><td>16</td><td>profileId</td><td>raw16</td><td>Accessed profile id</td></tr>
        <tr><td>32</td><td>8</td><td>accessedAt</td><td>ts</td><td>Access time</td></tr>
        <tr><td>40</td><td>4</td><td>responderDID</td><td>str_ref</td><td>Responder (signer)</td></tr>
        <tr><td>44</td><td>4</td><td>responderRole</td><td>str_ref</td><td>Role, <bcp14>OPTIONAL</bcp14></td></tr>
        <tr><td>48</td><td>32</td><td>profileRef</td><td>hash32</td><td>Profile ArtifactID</td></tr>
        <tr><td>80</td><td>32</td><td>responderVCHash</td><td>hash32</td><td>Responder VC digest</td></tr>
        <tr><td>112</td><td>1</td><td>channel</td><td>enum8</td><td>(13.7), open</td></tr>
        <tr><td>113</td><td>1</td><td>profileCheck</td><td>enum8</td><td>(13.19), open</td></tr>
        <tr><td>114</td><td>1</td><td>positionSource</td><td>enum8</td><td>(13.20), open</td></tr>
        <tr><td>115</td><td>1</td><td>(rsv)</td><td>u8</td><td>Reserved</td></tr>
        <tr><td>116</td><td>4</td><td>lat</td><td>i32</td><td>Latitude, 1e-7 degree</td></tr>
        <tr><td>120</td><td>4</td><td>lon</td><td>i32</td><td>Longitude, 1e-7 degree</td></tr>
        <tr><td>124</td><td>2</td><td>accuracyM</td><td>u16</td><td>Accuracy, metres</td></tr>
        <tr><td>126</td><td>2</td><td>(rsv)</td><td>u16</td><td>Reserved</td></tr>
        <tr><td>128</td><td>16</td><td>nonce</td><td>raw16</td><td>Replay nonce</td></tr>
        <tr><td>144</td><td>16</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
      </tbody>
    </table>
    <ul spacing="normal">
      <li>profileRef <bcp14>MUST</bcp14> be the ArtifactID of the profile accessed, and profileId <bcp14>MUST</bcp14> equal that profile's profileId.</li>
      <li>When positionSource is none (0x00), lat, lon, and accuracyM <bcp14>MUST</bcp14> be zero. Otherwise -900000000 &lt;= lat &lt;= 900000000 and -1800000000 &lt;= lon &lt;= 1800000000.</li>
      <li>profileCheck records what the responder's device concluded about the profile. The responder asserts it; it is not independent evidence.</li>
    </ul>
    <t>A receipt is responder-signed evidence of access, collected after the fact (Section <xref target="sec-19-11" format="counter"/>). The position comes from the responder's device and is not attested.</t>
</section>
<section anchor="sec-12-14" numbered="true" toc="default">
  <name>TRUST_BUNDLE (0x30)</name>
    <table anchor="tbl-trust-bundle">
      <name>TRUST_BUNDLE body (128 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>16</td><td>bundleId</td><td>raw16</td><td>Bundle identifier</td></tr>
        <tr><td>16</td><td>8</td><td>issuedAt</td><td>ts</td><td>Issuance time</td></tr>
        <tr><td>24</td><td>8</td><td>expiresAt</td><td>ts</td><td>Expiry time</td></tr>
        <tr><td>32</td><td>4</td><td>bundleVersion</td><td>u32</td><td>Starts at 1</td></tr>
        <tr><td>36</td><td>4</td><td>issuerDID</td><td>str_ref</td><td>Bundle issuer (signer)</td></tr>
        <tr><td>40</td><td>2</td><td>issuerCount</td><td>u16</td><td>Issuer records</td></tr>
        <tr><td>42</td><td>2</td><td>revocationCount</td><td>u16</td><td>Revocation records</td></tr>
        <tr><td>44</td><td>2</td><td>checkpointCount</td><td>u16</td><td>Checkpoint records</td></tr>
        <tr><td>46</td><td>2</td><td>minAppVersion</td><td>u16</td><td>Minimum app version</td></tr>
        <tr><td>48</td><td>32</td><td>prevBundleRef</td><td>hash32</td><td>Prior ArtifactID or 0</td></tr>
        <tr><td>80</td><td>48</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
      </tbody>
    </table>
    <table anchor="tbl-trustrecord">
      <name>Trust record (RS 96) (96 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>1</td><td>reckind</td><td>enum8</td><td>0x01/0x02/0x03, closed</td></tr>
        <tr><td>1</td><td>1</td><td>subkind</td><td>enum8</td><td>Per-kind subtype</td></tr>
        <tr><td>2</td><td>2</td><td>flags</td><td>u16</td><td>Reserved in minor 0</td></tr>
        <tr><td>4</td><td>4</td><td>field1</td><td>str_ref</td><td>Primary string</td></tr>
        <tr><td>8</td><td>4</td><td>field2</td><td>str_ref</td><td>Secondary string</td></tr>
        <tr><td>12</td><td>4</td><td>field3</td><td>str_ref</td><td>Tertiary string</td></tr>
        <tr><td>16</td><td>8</td><td>ts1</td><td>ts</td><td>Valid from / revoked at</td></tr>
        <tr><td>24</td><td>8</td><td>ts2</td><td>ts</td><td>Valid until</td></tr>
        <tr><td>32</td><td>4</td><td>num</td><td>u32</td><td>Mask / reason / height</td></tr>
        <tr><td>36</td><td>4</td><td>(rsv)</td><td>u32</td><td>Reserved</td></tr>
        <tr><td>40</td><td>32</td><td>hashVal</td><td>hash32</td><td>Key hash or ArtifactID</td></tr>
        <tr><td>72</td><td>8</td><td>keySpan</td><td>span</td><td>Raw public key in Blob</td></tr>
        <tr><td>80</td><td>16</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
      </tbody>
    </table>
    <t>The canonical record order sorts on reckind first, so the records fall into groups by kind. issuerCount, revocationCount, and checkpointCount <bcp14>MUST</bcp14> equal the number of records of kind 0x01, 0x02, and 0x03, and their sum, computed without overflow, <bcp14>MUST</bcp14> equal recCount (COUNT_MISMATCH).</t>
    <t>Issuer record (0x01):</t>
    <ul spacing="normal">
      <li>subkind is the key algorithm (Section <xref target="sec-13-22" format="counter"/>). The values 0x01-0x03 are the signature algorithms of Section <xref target="sec-13-2" format="counter"/>; 0x10 is an X25519 key-agreement key and 0x11 an X-Wing key-agreement key.</li>
      <li>field1 is the DID (<bcp14>REQUIRED</bcp14>), field2 the keyRef (<bcp14>REQUIRED</bcp14> unless field1 is a did:key), and field3 an <bcp14>OPTIONAL</bcp14> display label.</li>
      <li>ts1 and ts2 are the key's validity interval. ts2 = 0 means the key is valid until the bundle expires.</li>
      <li>num is the bitmask of permitted signature purposes, with bit (p - 1) for purpose p. It <bcp14>MUST</bcp14> be 0 for key-agreement keys.</li>
      <li>keySpan holds the raw public key, whose length depends on the algorithm (Sections <xref target="sec-8-7" format="counter"/> and <xref target="sec-10-1" format="counter"/>). hashVal = SHA-256 of that key.</li>
    </ul>
    <t>Revocation record (0x02):</t>
    <ul spacing="normal">
      <li>subkind is a targetKind (Section <xref target="sec-13-9" format="counter"/>). hashVal is the revoked ArtifactID, or the revoked key's hash for targetKind key.</li>
      <li>ts1 is the time the revocation takes effect. num is a reasonCode. field1 is <bcp14>OPTIONAL</bcp14> and names the affected DID. keySpan is absent.</li>
    </ul>
    <t>Checkpoint record (0x03):</t>
    <ul spacing="normal">
      <li>subkind is a backend (Section <xref target="sec-13-13" format="counter"/>). hashVal is a root hash or chain head that the bundle issuer has verified.</li>
      <li>ts1 is the checkpoint time and num the block height, modulo 2^32. field1 is a log or ledger label; field2 is an <bcp14>OPTIONAL</bcp14> transaction identifier.</li>
    </ul>
    <t>Bundle rules:</t>
    <ul spacing="normal">
      <li>bundleVersion &gt;= 1. prevBundleRef is zero if and only if bundleVersion = 1. Otherwise it is the ArtifactID of the bundle with version bundleVersion - 1.</li>
      <li>issuedAt &lt; expiresAt.</li>
      <li>The bundle-issuer signer <bcp14>MUST</bcp14> be either a root key pinned in the receiver's configuration (provisioned out of band) or a key with purpose bundle-issuer in the previous verified bundle. This is how bundle-issuer keys rotate.</li>
      <li>A receiver <bcp14>MUST NOT</bcp14> accept a bundle whose bundleVersion is lower than or equal to the latest it has verified, unless it is the same bundle (Section <xref target="sec-16-4" format="counter"/>).</li>
    </ul>
</section>
<section anchor="sec-12-15" numbered="true" toc="default">
  <name>DID_DOCUMENT (0x31)</name>
    <table anchor="tbl-did-document">
      <name>DID_DOCUMENT body (128 octets)</name>
      <thead>
        <tr><th>Off</th><th>Size</th><th>Field</th><th>Type</th><th>Notes</th></tr>
      </thead>
      <tbody>
        <tr><td>0</td><td>16</td><td>documentId</td><td>raw16</td><td>Envelope identifier</td></tr>
        <tr><td>16</td><td>8</td><td>updatedAt</td><td>ts</td><td>Update time</td></tr>
        <tr><td>24</td><td>4</td><td>version</td><td>u32</td><td>Starts at 1</td></tr>
        <tr><td>28</td><td>4</td><td>targetDID</td><td>str_ref</td><td>DID described</td></tr>
        <tr><td>32</td><td>32</td><td>documentHash</td><td>hash32</td><td>SHA-256 of JSON bytes</td></tr>
        <tr><td>64</td><td>8</td><td>jsonSpan</td><td>span</td><td>DID document JSON</td></tr>
        <tr><td>72</td><td>8</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
        <tr><td>80</td><td>32</td><td>prevVersionRef</td><td>hash32</td><td>Prior ArtifactID or 0</td></tr>
        <tr><td>112</td><td>16</td><td>(rsv)</td><td>bytes</td><td>Reserved</td></tr>
      </tbody>
    </table>
    <ul spacing="normal">
      <li>jsonSpan <bcp14>MUST</bcp14> be present. It holds the W3C DID document <xref target="DID-CORE"/> as uncompressed UTF-8 JSON, which <bcp14>MUST</bcp14> be no longer than 49152 octets. Its "id" member <bcp14>MUST</bcp14> equal targetDID. documentHash = SHA-256 of those octets.</li>
      <li>version 1: the document <bcp14>MUST</bcp14> be signed (author) by a key that is already resolvable for targetDID through a did:key or TRUST_BUNDLE source (Section <xref target="sec-8-7" format="counter"/>). A DID document cannot vouch for itself.</li>
      <li>version n &gt; 1: prevVersionRef <bcp14>MUST</bcp14> be the ArtifactID of version n - 1, and the signing key <bcp14>MUST</bcp14> be an assertionMethod key of version n - 1. This is how keys rotate.</li>
      <li>updatedAt <bcp14>MUST</bcp14> be greater than the updatedAt of version n - 1.</li>
    </ul>
</section>
</section>
<section anchor="sec-13" numbered="true" toc="default">
  <name>Enumerations</name>
<section anchor="sec-13-1" numbered="true" toc="default">
  <name>Policy for Unknown Values</name>
    <t>Every enumeration is either closed or open:</t>
    <ul spacing="normal">
      <li>Closed: a value changes how an artifact must be processed or what it authorizes. A receiver <bcp14>MUST</bcp14> reject an artifact that contains an unknown closed value (UNKNOWN_ENUM, or UNSUPPORTED_ALGORITHM for sigAlg).</li>
      <li>Open: a value is informational. A receiver <bcp14>MUST</bcp14> accept unknown open values, keep them unchanged, and report them to the application as "unrecognized". It <bcp14>MUST NOT</bcp14> substitute a default.</li>
    </ul>
    <t>Values not listed below are unassigned. Bitmask fields (Section <xref target="sec-13-4" format="counter"/>) are closed: in minor version 0, undefined bits <bcp14>MUST</bcp14> be zero.</t>
</section>
<section anchor="sec-13-2" numbered="true" toc="default">
  <name>sigAlg (closed)</name>
    <ul spacing="normal">
      <li>0x01 = Ed25519; 0x02 = ML-DSA-44; 0x03 = Ed25519 + ML-DSA-44 hybrid (Section <xref target="sec-8-2" format="counter"/>).</li>
    </ul>
</section>
<section anchor="sec-13-3" numbered="true" toc="default">
  <name>sigPurpose (closed)</name>
    <ul spacing="normal">
      <li>0x01 = author; 0x02 = counter-signature; 0x03 = responder; 0x04 = anchor-service; 0x05 = revocation; 0x06 = bundle-issuer.</li>
    </ul>
</section>
<section anchor="sec-13-4" numbered="true" toc="default">
  <name>actions (closed bitmask)</name>
    <ul spacing="normal">
      <li>Bit 0 (0x0001) = read: decrypt and view.</li>
      <li>Bit 1 (0x0002) = export: persist or transmit the plaintext outside the MDA/1 store.</li>
    </ul>
</section>
<section anchor="sec-13-5" numbered="true" toc="default">
  <name>hpkeMode (closed)</name>
    <ul spacing="normal">
      <li>0x00 = base; 0x02 = auth. These are the RFC 9180 values (Section <xref target="sec-10-1" format="counter"/>).</li>
    </ul>
</section>
<section anchor="sec-13-6" numbered="true" toc="default">
  <name>hpkeSuite (closed)</name>
    <ul spacing="normal">
      <li>0x01 = DHKEM(X25519, HKDF-SHA256) / HKDF-SHA256 / AES-256-GCM.</li>
      <li>0x02 = X-Wing / HKDF-SHA256 / AES-256-GCM.</li>
    </ul>
</section>
<section anchor="sec-13-7" numbered="true" toc="default">
  <name>channel (open)</name>
    <ul spacing="normal">
      <li>0x00 = unspecified; 0x01 = QR code; 0x02 = NFC; 0x03 = BLE; 0x04 = Wi-Fi Direct; 0x05 = relay server; 0x06 = web reader; 0x07 = removable media.</li>
    </ul>
</section>
<section anchor="sec-13-8" numbered="true" toc="default">
  <name>outcome (open)</name>
    <ul spacing="normal">
      <li>0x01 = delivered; 0x02 = decrypted; 0x03 = rejected; 0x04 = deferred.</li>
    </ul>
</section>
<section anchor="sec-13-9" numbered="true" toc="default">
  <name>targetKind (closed)</name>
    <ul spacing="normal">
      <li>0x01 = consent; 0x02 = grant; 0x03 = emergency profile; 0x04 = DID document; 0x05 = asset manifest; 0x06 = trust bundle; 0x07 = key; 0x08 = provenance commitment.</li>
    </ul>
</section>
<section anchor="sec-13-10" numbered="true" toc="default">
  <name>reasonCode (open)</name>
    <ul spacing="normal">
      <li>0x01 = patient request; 0x02 = superseded; 0x03 = credential revoked; 0x04 = device lost; 0x05 = clinical correction; 0x06 = expiry; 0x07 = key compromise.</li>
    </ul>
</section>
<section anchor="sec-13-11" numbered="true" toc="default">
  <name>contentType (open)</name>
    <t>The name in quotes is the string that Scope records use (Section <xref target="sec-7-4" format="counter"/>).</t>
    <ul spacing="normal">
      <li>0x00 = "undisclosed"; 0x01 = "lab"; 0x02 = "prescription"; 0x03 = "summary"; 0x04 = "immunization"; 0x05 = "imaging-thumb"; 0x06 = "vitals"; 0x07 = "directive"; 0x08 = "provenance"; 0xFF = "other".</li>
    </ul>
</section>
<section anchor="sec-13-12" numbered="true" toc="default">
  <name>issuerKind (open)</name>
    <ul spacing="normal">
      <li>0x01 = patient; 0x02 = clinician; 0x03 = institution.</li>
    </ul>
</section>
<section anchor="sec-13-13" numbered="true" toc="default">
  <name>backend (open)</name>
    <ul spacing="normal">
      <li>0x01 = Hedera HCS; 0x02 = IOTA; 0x03 = Hyperledger Fabric; 0x04 = Ethereum L2; 0x05 = RFC 3161 TSA.</li>
    </ul>
</section>
<section anchor="sec-13-14" numbered="true" toc="default">
  <name>anchorStatus (closed)</name>
    <ul spacing="normal">
      <li>0x01 = pending; 0x02 = final; 0x03 = failed.</li>
    </ul>
</section>
<section anchor="sec-13-15" numbered="true" toc="default">
  <name>valueKind (closed)</name>
    <ul spacing="normal">
      <li>0x01 = METALOG chain head (a recordHash); 0x02 = ArtifactID.</li>
    </ul>
</section>
<section anchor="sec-13-16" numbered="true" toc="default">
  <name>bloodType (open)</name>
    <ul spacing="normal">
      <li>0x00 = unknown; 0x01 = A+; 0x02 = A-; 0x03 = B+; 0x04 = B-; 0x05 = AB+; 0x06 = AB-; 0x07 = O+; 0x08 = O-.</li>
    </ul>
</section>
<section anchor="sec-13-17" numbered="true" toc="default">
  <name>resuscitation (open)</name>
    <ul spacing="normal">
      <li>0x00 = unknown; 0x01 = full resuscitation; 0x02 = limited; 0x03 = do not resuscitate.</li>
    </ul>
</section>
<section anchor="sec-13-18" numbered="true" toc="default">
  <name>organDonor (open)</name>
    <ul spacing="normal">
      <li>0x00 = unknown; 0x01 = yes; 0x02 = no.</li>
    </ul>
</section>
<section anchor="sec-13-19" numbered="true" toc="default">
  <name>profileCheck (open)</name>
    <ul spacing="normal">
      <li>0x01 = verified; 0x02 = verified, anchor finality pending; 0x03 = unverified; 0x04 = expired; 0x05 = revoked; 0x06 = tampered.</li>
    </ul>
</section>
<section anchor="sec-13-20" numbered="true" toc="default">
  <name>positionSource (open)</name>
    <ul spacing="normal">
      <li>0x00 = none; 0x01 = GNSS; 0x02 = network; 0x03 = manual entry.</li>
    </ul>
</section>
<section anchor="sec-13-21" numbered="true" toc="default">
  <name>versionOp (closed)</name>
    <ul spacing="normal">
      <li>0x01 = exact; 0x02 = at least; 0x03 = latest.</li>
    </ul>
</section>
<section anchor="sec-13-22" numbered="true" toc="default">
  <name>Record Kinds and Key Algorithms (closed)</name>
    <table anchor="tbl-permitted-record-kinds">
      <name>Permitted record kinds</name>
      <thead>
        <tr>
          <th>Type</th>
          <th>Permitted reckind values</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>REQUEST, CONSENT</td>
          <td>0x05 Scope</td>
        </tr>
        <tr>
          <td>ASSET_MANIFEST</td>
          <td>0x06 Tag</td>
        </tr>
        <tr>
          <td>EMERGENCY_PROFILE</td>
          <td>0x01 Allergy, 0x02 Medication, 0x03 Condition, 0x04 Contact</td>
        </tr>
        <tr>
          <td>TRUST_BUNDLE</td>
          <td>0x01 Issuer, 0x02 Revocation, 0x03 Checkpoint</td>
        </tr>
      </tbody>
    </table>
    <t>Record kind values are scoped to the record layout. Generic records and Trust records use separate namespaces.</t>
    <t>The subkind of a Trust issuer record is a key algorithm: 0x01, 0x02, 0x03 (Section <xref target="sec-13-2" format="counter"/>), 0x10 = X25519 (32-octet key), or 0x11 = X-Wing (1216-octet key). A Trust revocation record's subkind is a targetKind (Section <xref target="sec-13-9" format="counter"/>), which is closed. A Trust checkpoint record's subkind is a backend (Section <xref target="sec-13-13" format="counter"/>), which is open.</t>
</section>
<section anchor="sec-13-23" numbered="true" toc="default">
  <name>Generic Record Subkinds (open)</name>
    <ul spacing="normal">
      <li>Allergy severity: 0x00 = unknown; 0x01 = mild; 0x02 = moderate; 0x03 = severe; 0x04 = life-threatening.</li>
      <li>Medication route: 0x00 = unknown; 0x01 = oral; 0x02 = intravenous; 0x03 = intramuscular; 0x04 = subcutaneous; 0x05 = topical; 0x06 = inhaled; 0x07 = other.</li>
      <li>Condition status: 0x00 = unknown; 0x01 = active; 0x02 = recurrence; 0x03 = remission; 0x04 = resolved; 0x05 = inactive.</li>
      <li>Contact priority: an integer. 0 means unspecified and 1 is the highest priority.</li>
      <li>Scope (0x05): the subkind is versionOp (Section <xref target="sec-13-21" format="counter"/>), which is closed. Tag (0x06): the subkind <bcp14>MUST</bcp14> be 0.</li>
    </ul>
</section>
<section anchor="sec-13-24" numbered="true" toc="default">
  <name>errorCode (open)</name>
    <table anchor="tbl-error-codes">
      <name>Error codes</name>
      <thead>
        <tr>
          <th>Code</th>
          <th>Name</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>0x0001</td>
          <td>INVALID_CRC32</td>
        </tr>
        <tr>
          <td>0x0002</td>
          <td>UNKNOWN_VERSION</td>
        </tr>
        <tr>
          <td>0x0003</td>
          <td>BOUNDS_EXCEEDED</td>
        </tr>
        <tr>
          <td>0x0004</td>
          <td>OFFSET_MISMATCH</td>
        </tr>
        <tr>
          <td>0x0005</td>
          <td>STRING_TABLE_INVALID</td>
        </tr>
        <tr>
          <td>0x0006</td>
          <td>INVALID_SIGNATURE</td>
        </tr>
        <tr>
          <td>0x0007</td>
          <td>EXPIRED</td>
        </tr>
        <tr>
          <td>0x0008</td>
          <td>COUNT_MISMATCH</td>
        </tr>
        <tr>
          <td>0x0009</td>
          <td>UNSUPPORTED_ALGORITHM</td>
        </tr>
        <tr>
          <td>0x000A</td>
          <td>BAD_MAGIC</td>
        </tr>
        <tr>
          <td>0x000B</td>
          <td>LENGTH_MISMATCH</td>
        </tr>
        <tr>
          <td>0x000C</td>
          <td>UNKNOWN_TYPE</td>
        </tr>
        <tr>
          <td>0x000D</td>
          <td>UNKNOWN_CRITICAL_FLAG</td>
        </tr>
        <tr>
          <td>0x000E</td>
          <td>NON_CANONICAL</td>
        </tr>
        <tr>
          <td>0x000F</td>
          <td>INVALID_REFERENCE</td>
        </tr>
        <tr>
          <td>0x0010</td>
          <td>UNKNOWN_ENUM</td>
        </tr>
        <tr>
          <td>0x0011</td>
          <td>MISSING_SIGNATURE</td>
        </tr>
        <tr>
          <td>0x0012</td>
          <td>SIGNER_NOT_AUTHORIZED</td>
        </tr>
        <tr>
          <td>0x0013</td>
          <td>KEY_UNRESOLVED</td>
        </tr>
        <tr>
          <td>0x0014</td>
          <td>REVOKED</td>
        </tr>
        <tr>
          <td>0x0015</td>
          <td>NOT_YET_VALID</td>
        </tr>
        <tr>
          <td>0x0016</td>
          <td>REPLAY</td>
        </tr>
        <tr>
          <td>0x0017</td>
          <td>SEMANTIC_VIOLATION</td>
        </tr>
        <tr>
          <td>0x0018</td>
          <td>DEPENDENCY_MISSING</td>
        </tr>
        <tr>
          <td>0x0019</td>
          <td>DECRYPTION_FAILED</td>
        </tr>
        <tr>
          <td>0x001A</td>
          <td>KEY_COMMITMENT_MISMATCH</td>
        </tr>
      </tbody>
    </table>
</section>
<section anchor="sec-13-25" numbered="true" toc="default">
  <name>VB01 aead (closed)</name>
    <ul spacing="normal">
      <li>0x01 = AES-256-GCM with the key derivation of Section <xref target="sec-9-2" format="counter"/>.</li>
    </ul>
</section>
</section>
<section anchor="sec-14" numbered="true" toc="default">
  <name>Size Bounds</name>
    <t>Receivers <bcp14>MUST</bcp14> enforce these limits using only header fields (step A4), before any input-dependent allocation:</t>
    <table anchor="tbl-size-bounds">
      <name>Size bounds</name>
      <thead>
        <tr>
          <th>Limit</th>
          <th>control</th>
          <th>card</th>
          <th>bundle</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>totalLen (maximum)</td>
          <td>8 KiB</td>
          <td>64 KiB</td>
          <td>4 MiB</td>
        </tr>
        <tr>
          <td>recCount (maximum)</td>
          <td>64</td>
          <td>512</td>
          <td>16384</td>
        </tr>
      </tbody>
    </table>
    <t>All classes: sigCount &lt;= 4, strLen &lt;= 65536, strCount &lt;= 16384, blobLen &lt;= 3 MiB, sigValLen &lt;= 9984, string len &lt;= 256, text span len &lt;= 65536, DID JSON &lt;= 49152.</t>
    <t>"KiB" is 1024 octets and "MiB" is 1048576 octets. Every bound is inclusive. Control-class bounds leave room for post-quantum material: a GRANT with suite 0x02 and one hybrid signature takes about 4.1 KiB. The bundle class covers METALOG_RECORDs that carry the largest VB01 frame (2 MiB).</t>
</section>
<section anchor="sec-15" numbered="true" toc="default">
  <name>Validation Pipeline</name>
    <t>A conforming receiver <bcp14>MUST</bcp14> run these steps in order and stop at the first failure, reporting the error code given. No body, record, string, or blob value may reach the application unless every step has passed, except as Section <xref target="sec-16-2" format="counter"/> permits for emergency profiles. The phases are arranged so that phase A reads only the 64-octet header and the CRC, and phases A and B together need only fixed-size scratch memory (Appendix <xref target="app-b" format="counter"/>).</t>
<section anchor="sec-15-1" numbered="true" toc="default">
  <name>Phase A: Framing</name>
    <dl newline="false" spacing="normal">
      <dt>A1.</dt>
      <dd>Input length &gt;= 64 (BOUNDS_EXCEEDED). magic = "MDA1" (BAD_MAGIC). major = 1 (UNKNOWN_VERSION).</dd>
      <dt>A2.</dt>
      <dd>totalLen = input length (LENGTH_MISMATCH). totalLen &lt;= 4 MiB and totalLen mod 16 = 0 (BOUNDS_EXCEEDED).</dd>
      <dt>A3.</dt>
      <dd>type is registered, or lies in the Experimental or Private Use range (UNKNOWN_TYPE). Determine the class (Section <xref target="sec-11" format="counter"/>). A production receiver <bcp14>MUST</bcp14> reject Experimental types unless its configuration explicitly allows them.</dd>
      <dt>A4.</dt>
      <dd>Class and global bounds (Section <xref target="sec-14" format="counter"/>) on totalLen, recCount, sigCount, strCount, strLen, blobLen, and sigValLen (BOUNDS_EXCEEDED).</dd>
      <dt>A5.</dt>
      <dd>No unknown critical flag bit (UNKNOWN_CRITICAL_FLAG). FLAG_SIGNED = (sigCount &gt; 0), and header reserved fields and non-critical flag bits are zero unless Section <xref target="sec-17" format="counter"/> permits otherwise (NON_CANONICAL).</dd>
      <dt>A6.</dt>
      <dd>Topology (Section <xref target="sec-4-4" format="counter"/>), with 64-bit arithmetic: bodyLen, recStride, sigStride, and recCount = 0 for stride-0 types (COUNT_MISMATCH); every offset equality, every length multiple, and totalLen = sigValOff + sigValLen (OFFSET_MISMATCH).</dd>
      <dt>A7.</dt>
      <dd>The CRC-32 matches (INVALID_CRC32).</dd>
    </dl>
</section>
<section anchor="sec-15-2" numbered="true" toc="default">
  <name>Phase B: Structure</name>
    <dl newline="false" spacing="normal">
      <dt>B1.</dt>
      <dd>Walk the string table: exactly strCount entries, each lying entirely within the table, 1 &lt;= len &lt;= 256, well-formed UTF-8 with no U+0000, a zero pad byte after odd lengths, strictly ascending order, and fewer than 16 zero octets at the end (STRING_TABLE_INVALID or NON_CANONICAL). Record the set of entry starts.</dd>
      <dt>B2.</dt>
      <dd>Records: reckind is permitted for the type, and record subkinds that are closed are known (UNKNOWN_ENUM); reserved fields and flags are zero, and unused fields are zero or absent (NON_CANONICAL); records are in canonical order, except Proof records (NON_CANONICAL). For TRUST_BUNDLE, check the per-kind counts (COUNT_MISMATCH).</dd>
      <dt>B3.</dt>
      <dd>Signature entries: alg is known (UNSUPPORTED_ALGORITHM); purpose is known (UNKNOWN_ENUM) and permitted for the type (SIGNER_NOT_AUTHORIZED); signerDID is present (INVALID_REFERENCE); reserved fields are zero, valLen matches alg, valOff is at its canonical position, value padding is zero, and entries are strictly ordered (NON_CANONICAL).</dd>
      <dt>B4.</dt>
      <dd>Every str_ref in the body, records, and signature entries is absent or one of the entry starts from B1 (INVALID_REFERENCE). Every entry is referenced at least once (NON_CANONICAL).</dd>
      <dt>B5.</dt>
      <dd>Every present span follows the canonical blob layout of Section <xref target="sec-6-2" format="counter"/> and stays within the Blob section, and gap and tail octets are zero (INVALID_REFERENCE or NON_CANONICAL).</dd>
      <dt>B6.</dt>
      <dd>Body: reserved fields are zero (NON_CANONICAL); closed enumerations and bitmasks are valid (UNKNOWN_ENUM or NON_CANONICAL); every field the type marks as required is present (SEMANTIC_VIOLATION).</dd>
    </dl>
</section>
<section anchor="sec-15-3" numbered="true" toc="default">
  <name>Phase C: Cryptographic</name>
    <dl newline="false" spacing="normal">
      <dt>C1.</dt>
      <dd>Compute the ArtifactID (Section <xref target="sec-8-3" format="counter"/>).</dd>
      <dt>C2.</dt>
      <dd>If the type <bcp14>MUST</bcp14> be signed, an entry with the required purpose is present (MISSING_SIGNATURE).</dd>
      <dt>C3.</dt>
      <dd>Resolve every signature entry's key (Section <xref target="sec-8-7" format="counter"/>), checking validity, purpose permission, revocation, and the local algorithm policy (KEY_UNRESOLVED, SIGNER_NOT_AUTHORIZED, REVOKED, UNSUPPORTED_ALGORITHM).</dd>
      <dt>C4.</dt>
      <dd>Verify every signature (INVALID_SIGNATURE).</dd>
      <dt>C5.</dt>
      <dd>Signer binding: an entry with the required purpose has signerDID equal to the principal field (Section <xref target="sec-8-6" format="counter"/>), and counter-signers differ from the principal (SIGNER_NOT_AUTHORIZED). ANCHOR_RECEIPT has no principal field; its anchor-service signer is bound through the TRUST_BUNDLE purpose permission checked in C3. A signed METALOG_RECORD is bound to the log owner by deployment policy.</dd>
    </dl>
</section>
<section anchor="sec-15-4" numbered="true" toc="default">
  <name>Phase D: Semantic</name>
    <dl newline="false" spacing="normal">
      <dt>D1.</dt>
      <dd>Time windows (Section <xref target="sec-16-2" format="counter"/>) (NOT_YET_VALID, EXPIRED).</dd>
      <dt>D2.</dt>
      <dd>The type-specific rules of Section <xref target="sec-12" format="counter"/> (SEMANTIC_VIOLATION).</dd>
      <dt>D3.</dt>
      <dd>Dependencies and revocation: referenced artifacts are present and valid where Section <xref target="sec-12" format="counter"/> requires them, and the artifact itself has not been revoked (DEPENDENCY_MISSING, REVOKED).</dd>
      <dt>D4.</dt>
      <dd>Replay (Section <xref target="sec-16-3" format="counter"/>) (REPLAY).</dd>
    </dl>
</section>
<section anchor="sec-15-5" numbered="true" toc="default">
  <name>Error Reporting</name>
    <t>A receiver that sends an error back to the originator does so with an ERROR artifact (Section <xref target="sec-12-6" format="counter"/>), filling in errorCode, failedStep, and detailOffset. Receivers <bcp14>MAY</bcp14> coarsen what they report, for example sending only "rejected", so as not to give an attacker an oracle (Section <xref target="sec-19-10" format="counter"/>).</t>
</section>
<section anchor="sec-15-6" numbered="true" toc="default">
  <name>Experimental and Private Types</name>
    <t>For an experimental or private type, steps A1-A7, B1, B3, C1, and C4 apply. A receiver cannot locate the str_ref and span fields in an opaque body, so B4 is limited to signerDID and keyRef, and the rule against orphan entries and step B5 are skipped. A receiver that does not implement the type <bcp14>MUST NOT</bcp14> expose body fields to the application. It <bcp14>MUST</bcp14> preserve the octets exactly if it stores or forwards the artifact. A receiver that does implement the type applies its full rules.</t>
</section>
</section>
<section anchor="sec-16" numbered="true" toc="default">
  <name>Time, Freshness, and Replay</name>
<section anchor="sec-16-1" numbered="true" toc="default">
  <name>Clock Model</name>
    <t>An offline device's clock may be wrong. A receiver keeps a trusted time floor F: the highest issuedAt of any TRUST_BUNDLE it has verified, and the highest anchoredAt of any final ANCHOR_RECEIPT it has verified. It uses now = max(device clock, F). Timestamps from other signers never raise F. The skew allowance is a policy parameter: 5 minutes by default, and at most 24 hours. Receivers <bcp14>MUST</bcp14> reject any signedAt later than now + skew (NOT_YET_VALID).</t>
</section>
<section anchor="sec-16-2" numbered="true" toc="default">
  <name>Validity Windows</name>
    <t>An interval [start, end] is satisfied if start &lt;= now + skew and either end = 0 (where the field permits that) or now - skew &lt;= end. The intervals are: issuedAt..expiresAt for REQUEST, GRANT, and TRUST_BUNDLE; validFrom..validUntil for CONSENT and EMERGENCY_PROFILE; and, for keys from a TRUST_BUNDLE, the issuer record's ts1..ts2.</t>
    <t>An EMERGENCY_PROFILE that fails D1 <bcp14>MAY</bcp14> still be shown to a responder, with profileCheck expired (0x04) and a prominent warning. It <bcp14>MUST NOT</bcp14> be presented as current, and it <bcp14>MUST NOT</bcp14> be used for any authorization decision.</t>
</section>
<section anchor="sec-16-3" numbered="true" toc="default">
  <name>Replay Protection</name>
    <t>REQUEST, GRANT, RECEIPT, REVOKE, and EMERGENCY_ACCESS_RECEIPT carry a nonce. A receiver <bcp14>MUST</bcp14> remember (type, principal, nonce, ArtifactID) for every artifact of these types it accepts. For REQUEST and GRANT it keeps the entry until expiresAt + skew; for the other types, for at least 30 days. Receiving the same nonce again with the same ArtifactID is an idempotent redelivery: no new action is taken, and no error is raised. Receiving the same nonce with a different ArtifactID <bcp14>MUST</bcp14> be rejected (REPLAY). raw16 nonces make an accidental collision negligible.</t>
</section>
<section anchor="sec-16-4" numbered="true" toc="default">
  <name>Revocation Freshness</name>
    <t>Offline receivers learn of revocations only from REVOKE artifacts and TRUST_BUNDLE revocation records they have received. A receiver <bcp14>MUST NOT</bcp14> resolve keys from a TRUST_BUNDLE that has expired (expiresAt + skew &lt; now). Deployment policy <bcp14>MAY</bcp14> allow a "stale" mode for break-glass display only. In that mode the stale status <bcp14>MUST</bcp14> be shown, and the artifacts accepted <bcp14>MUST NOT</bcp14> authorize decryption or export. Bundles are accepted only in increasing bundleVersion order along the prevBundleRef chain, so a stale bundle cannot be replayed to resurrect a revoked key.</t>
</section>
</section>
<section anchor="sec-17" numbered="true" toc="default">
  <name>Versioning and Extensibility</name>
    <ul spacing="normal">
      <li>major identifies an incompatible format. Receivers <bcp14>MUST</bcp14> reject unknown major versions. A new major version <bcp14>MUST</bcp14> use a new signature domain tag and a new magic number or major value.</li>
      <li>A minor version can only give meaning to reserved fields, reserved flag bits, and new enumerated values. It never changes body sizes, strides, or the meaning of existing fields.</li>
      <li>An artifact whose minor version is at most the receiver's supported minor version <bcp14>MUST</bcp14> have all reserved octets zero (C-3). An artifact with a higher minor version <bcp14>MAY</bcp14> have non-zero reserved octets in the body, the records, the header's non-critical flag bits, and the header reserved fields. A receiver ignores those octets, but they remain covered by the ArtifactID and the signatures. If such an extension changes how the artifact must be processed, it <bcp14>MUST</bcp14> set a critical flag bit, so that receivers that do not implement it reject the artifact (Section <xref target="sec-4-3" format="counter"/>).</li>
      <li>New artifact types take unassigned codes from the registry (Section <xref target="sec-21-2" format="counter"/>). New types <bcp14>MUST</bcp14> follow the container rules of this document.</li>
      <li>New enumerated values follow the policy of Section <xref target="sec-13-1" format="counter"/>.</li>
    </ul>
</section>
<section anchor="sec-18" numbered="true" toc="default">
  <name>Conformance</name>
<section anchor="sec-18-1" numbered="true" toc="default">
  <name>Encoders</name>
    <t>An encoder conforms if every artifact it emits:</t>
    <ul spacing="normal">
      <li>E1: satisfies every rule in Sections <xref target="sec-4" format="counter"/> to 12 and every bound in Section <xref target="sec-14" format="counter"/>;</li>
      <li>E2: uses NFC for every string and a CSPRNG for every raw16, DEK, and nonce;</li>
      <li>E3: re-encodes to the same octets in [0, sigValOff) when decoded and encoded again;</li>
      <li>E4: reproduces the vectors of Appendix <xref target="app-a" format="counter"/> exactly.</li>
    </ul>
</section>
<section anchor="sec-18-2" numbered="true" toc="default">
  <name>Receivers</name>
    <t>A receiver conforms if it:</t>
    <ul spacing="normal">
      <li>R1: implements every step of Section <xref target="sec-15" format="counter"/> in order, with the error codes given;</li>
      <li>R2: never reads outside [0, input length) and never allocates memory in proportion to the input before step A4 completes;</li>
      <li>R3: accepts the vectors of Appendix <xref target="app-a" format="counter"/> and rejects their negative variants (Appendix <xref target="app-a-4" format="counter"/>);</li>
      <li>R4: preserves unknown open-enumeration values and unknown experimental or private artifacts octet for octet;</li>
      <li>R5: survives at least 10^6 mutated artifacts derived from the Appendix <xref target="app-a" format="counter"/> vectors, run under memory-safety instrumentation, without a crash, a hang, an out-of-bounds access, or a false acceptance of an artifact that fails any rule;</li>
      <li>R6: implements Ed25519 signing and verification and suite 0x01. Implementing ML-DSA-44, the hybrid algorithm, and suite 0x02 is <bcp14>RECOMMENDED</bcp14>.</li>
    </ul>
</section>
</section>
<section anchor="sec-19" numbered="true" toc="default">
  <name>Security Considerations</name>
<section anchor="sec-19-1" numbered="true" toc="default">
  <name>Parser Safety</name>
    <t>Every limit is checked from header fields before anything is allocated (A4). The topology is checked with arithmetic that cannot wrap (A6). totalLen must equal the octets actually received (A2), so no step can read past the input. Each of phases A and B is one linear pass. Strings and spans are checked against bitmaps of fixed size (Appendix <xref target="app-b" format="counter"/>), and there is no recursion. Taken together, a malformed artifact costs at most O(totalLen) work and a constant amount of memory.</t>
</section>
<section anchor="sec-19-2" numbered="true" toc="default">
  <name>CRC Is Not Integrity</name>
    <t>The CRC-32 only screens out accidental corruption cheaply. An attacker can recompute it at will. All protection against deliberate modification comes from the signatures (Section <xref target="sec-8" format="counter"/>). Types that <bcp14>MAY</bcp14> be unsigned (ERROR, METALOG_RECORD) have no integrity protection beyond what Sections <xref target="sec-12-6" format="counter"/> and <xref target="sec-12-8" format="counter"/> provide.</t>
</section>
<section anchor="sec-19-3" numbered="true" toc="default">
  <name>Signature Coverage and Stripping</name>
    <t>A signature covers the ArtifactID, and the ArtifactID covers every octet except the signature values and the CRC field. Signature metadata (purpose, algorithm, signedAt, key reference, and value placement), the string table, and the Blob section are therefore all authenticated. Each type has its own requirement for which signatures must be present (Section <xref target="sec-8-6" format="counter"/>), so removing signatures and clearing FLAG_SIGNED produces an artifact that is rejected. Appendix <xref target="app-a-4" format="counter"/> includes vectors for both attacks.</t>
</section>
<section anchor="sec-19-4" numbered="true" toc="default">
  <name>Signer Binding and Key Resolution</name>
    <t>A valid signature proves nothing unless the signer is entitled to make the statement. Section <xref target="sec-8-6" format="counter"/> binds each type's required signature to its principal field, and Section <xref target="sec-12" format="counter"/> binds authority across artifacts: who may grant under a consent, and who may revoke what. Key resolution is offline, and it comes from sources the receiver has authenticated: self-certifying did:key identifiers, a chain of trust bundles rooted in pinned keys, and DID documents bootstrapped from those. A DID document cannot vouch for itself (Section <xref target="sec-12-15" format="counter"/>). How the root keys are provisioned is the deployment's main trust decision.</t>
</section>
<section anchor="sec-19-5" numbered="true" toc="default">
  <name>Post-Quantum and Hybrid Signatures</name>
    <t>A hybrid signature (alg 0x03) is valid only if both components verify. Each component signs the same TBS, and the TBS commits to alg through the ArtifactID. Rewriting alg to remove the post-quantum component therefore invalidates the signature. Receivers can require hybrid signatures as a matter of policy (Section <xref target="sec-8-7" format="counter"/>). ML-DSA-44 targets NIST security category 2, while ML-KEM-768 in X-Wing targets category 3. Deployments that need category 3 signatures need an ML-DSA-65 code point, which a future document can define.</t>
</section>
<section anchor="sec-19-6" numbered="true" toc="default">
  <name>Canonical Encoding and Identity</name>
    <t>Receivers reject every non-canonical encoding. That covers non-zero reserved or padding octets, unsorted or orphaned strings, misordered records, signature entries or blob items, and trailing octets. An artifact therefore has exactly one ArtifactID, and references between artifacts cannot be broken by re-encoding. Strict Ed25519 verification (Section <xref target="sec-8-5" format="counter"/>) makes signature values non-malleable, and in any case signature values are not part of the ArtifactID. NFC is enforced only on the encoder side. A non-NFC string encodes differently, so it gives a different ArtifactID, and it carries the signer's signature over exactly those octets. It is a different signed statement, not a malleable version of an existing one. Applications that compare strings across artifacts <bcp14>SHOULD</bcp14> apply NFC when they compare.</t>
</section>
<section anchor="sec-19-7" numbered="true" toc="default">
  <name>Key Wrapping and Content Encryption</name>
    <t>The HPKE AAD (Section <xref target="sec-10-3" format="counter"/>) authenticates the whole GRANT. VB01 derives a separate key for each frame and carries a key commitment, which makes AES-GCM key-committing and defeats partitioning-oracle attacks. It also tolerates DEK reuse across frames. DEKs and nonces <bcp14>MUST</bcp14> come from a CSPRNG. Auth mode is not defined for the post-quantum suite. Sender authentication always comes from the GRANT signature, so a recipient <bcp14>MUST NOT</bcp14> decapsulate before the GRANT has passed phases A through D.</t>
</section>
<section anchor="sec-19-8" numbered="true" toc="default">
  <name>Identifiers, Nonces, and Replay</name>
    <t>Every identifier and nonce is 128 random bits, so accidental collisions are negligible; shorter values, such as 32 bits, would collide after about 2^16 values. Section <xref target="sec-16-3" format="counter"/> defines replay caching; idempotent redelivery is distinguished from replay by the ArtifactID.</t>
</section>
<section anchor="sec-19-9" numbered="true" toc="default">
  <name>Time and Revocation</name>
    <t>Offline clocks can be wrong, and revocation information reaches offline devices late. The trusted time floor (Section <xref target="sec-16-1" format="counter"/>) keeps a device from being rolled back to before trust material it has already seen. Monotonic bundle versions keep a revoked key from coming back. Neither mechanism can reveal a revocation the device has not yet received. Deployments <bcp14>SHOULD</bcp14> keep TRUST_BUNDLE lifetimes short, matched to how often their devices synchronize.</t>
</section>
<section anchor="sec-19-10" numbered="true" toc="default">
  <name>Denial of Service and Oracles</name>
    <t>Verifying signatures is the most expensive step. It happens only after every structural check has passed, and at most four signatures are verified per artifact. Post-quantum verification costs more than Ed25519 but stays well within mobile-class budgets. Detailed error codes are useful for debugging, but they can act as a validation oracle. Receivers facing untrusted peers <bcp14>MAY</bcp14> report only a generic rejection (Section <xref target="sec-15-5" format="counter"/>).</t>
</section>
<section anchor="sec-19-11" numbered="true" toc="default">
  <name>Break-Glass Access</name>
    <t>EMERGENCY_PROFILE is readable without keys by design, because an unconscious patient cannot authorize access. EMERGENCY_ACCESS_RECEIPT is responder-signed evidence collected after the fact. It deters and attributes misuse; it does not prevent it. Nothing in this document can force a responder to issue a receipt. Its position comes from the responder's device, which can spoof it, and its profileCheck is the responder's own assertion. Deployments that need preventive control <bcp14>MUST</bcp14> encrypt the profile content (Section <xref target="sec-12-12" format="counter"/>).</t>
</section>
<section anchor="sec-19-12" numbered="true" toc="default">
  <name>Ledger Anchoring</name>
    <t>An ANCHOR_RECEIPT is only as trustworthy as its anchor-service key and the receiver's ability to verify the inclusion proof. Receivers <bcp14>MUST</bcp14> verify the RFC 9162 proof against rootHash, and <bcp14>MUST</bcp14> obtain rootHash or a later checkpoint independently, from a TRUST_BUNDLE checkpoint record, before relying on finality. Pending and failed receipts provide no assurance.</t>
</section>
<section anchor="sec-19-13" numbered="true" toc="default">
  <name>Side Channels</name>
    <t>Comparisons of key commitments, MACs, and HPKE outputs <bcp14>MUST</bcp14> run in constant time. Implementations of Ed25519, ML-DSA, and X-Wing <bcp14>SHOULD</bcp14> resist timing and fault attacks. The hedged ML-DSA variant is <bcp14>RECOMMENDED</bcp14> where fault injection is a concern.</t>
</section>
</section>
<section anchor="sec-20" numbered="true" toc="default">
  <name>Privacy Considerations</name>
<section anchor="sec-20-1" numbered="true" toc="default">
  <name>Plaintext Artifacts</name>
    <t>Control artifacts, manifests, provenance commitments, and emergency profiles are signed but not encrypted. They can reveal DIDs, display names, purposes of use, and the existence of relationships. Encoders <bcp14>SHOULD</bcp14> leave out every <bcp14>OPTIONAL</bcp14> field that is not needed. Transports <bcp14>SHOULD</bcp14> provide confidentiality where it is available.</t>
</section>
<section anchor="sec-20-2" numbered="true" toc="default">
  <name>Asset Metadata</name>
    <t>ASSET_MANIFEST deliberately leaves out the plaintext length and the plaintext hash. A plaintext hash would let anyone holding a manifest confirm a guess at low-entropy documents. contentType, title, source, and tags are visible to anyone holding the manifest, and Section <xref target="sec-12-7" format="counter"/> recommends minimizing them.</t>
</section>
<section anchor="sec-20-3" numbered="true" toc="default">
  <name>Limits of Length Hiding</name>
    <t>VB01 hides lengths to within a power of two. An observer can still see the bucket size, how many frames exist and when, the access pattern, and the METALOG recordType of each entry. Deployments needing more than that should pad to larger buckets, add cover frames, and set recordType to 0.</t>
</section>
<section anchor="sec-20-4" numbered="true" toc="default">
  <name>Identifier Correlation</name>
    <t>DIDs and raw16 identifiers can link activity across contexts. Patients <bcp14>SHOULD</bcp14> use a separate DID for each relationship (pairwise DIDs) where the DID method supports it. Identifiers <bcp14>MUST</bcp14> be random (Section <xref target="sec-3" format="counter"/>).</t>
</section>
<section anchor="sec-20-5" numbered="true" toc="default">
  <name>Location Data</name>
    <t>EMERGENCY_ACCESS_RECEIPT can carry precise coordinates of a patient's location. Encoders <bcp14>SHOULD</bcp14> reduce precision to what accountability needs, and <bcp14>SHOULD</bcp14> set positionSource none when no position is required.</t>
</section>
</section>
<section anchor="sec-21" numbered="true" toc="default">
  <name>IANA Considerations</name>
<section anchor="sec-21-1" numbered="true" toc="default">
  <name>Media Types</name>
    <t>IANA is requested to register two media types in the "Media Types" registry <xref target="RFC6838"/>.</t>
    <dl newline="false" spacing="compact">
      <dt>Type name:</dt><dd>application</dd>
      <dt>Subtype name:</dt><dd>mda1-artifact</dd>
      <dt>Required parameters:</dt><dd>N/A</dd>
      <dt>Optional parameters:</dt><dd>N/A</dd>
      <dt>Encoding considerations:</dt><dd>binary</dd>
      <dt>Security considerations:</dt><dd>See <xref target="sec-19"/> of this document.</dd>
      <dt>Interoperability considerations:</dt><dd>See <xref target="sec-18"/> of this document.</dd>
      <dt>Published specification:</dt><dd>This document</dd>
      <dt>Applications that use this media type:</dt><dd>Offline health data exchange and storage.</dd>
      <dt>Fragment identifier considerations:</dt><dd>N/A</dd>
      <dt>Additional information:</dt><dd><t>Magic number(s): 4D 44 41 31 at offset 0</t>
        <t>File extension(s): .mda1</t><t>Macintosh file type code(s): N/A</t></dd>
      <dt>Person and email address to contact for further information:</dt><dd>Septimus Johnson &lt;septimus.johnson@simplenet-solutions.de&gt;</dd>
      <dt>Intended usage:</dt><dd>COMMON</dd>
      <dt>Restrictions on usage:</dt><dd>None</dd>
      <dt>Author:</dt><dd>Septimus Johnson</dd>
      <dt>Change controller:</dt><dd>IETF</dd>
    </dl>
    <t>The second registration, application/mda1-vb01, uses the same template, except: Subtype name: mda1-vb01; Magic number(s): 56 42 30 31 at offset 0; File extension(s): .vb01; Security considerations: <xref target="sec-9"/>, <xref target="sec-19-7"/>, and <xref target="sec-20-3"/> of this document.</t>
</section>
<section anchor="sec-21-2" numbered="true" toc="default">
  <name>MDA/1 Registries</name>
    <t>IANA is requested to create a "Flat Data Artifact Format (MDA/1)" registry group with the following registries, using the policies of <xref target="RFC8126"/>. Their initial contents are the values in Sections <xref target="sec-4-3" format="counter"/>, <xref target="sec-11" format="counter"/>, and <xref target="sec-13" format="counter"/>.</t>
    <table anchor="tbl-mda-1-registries">
      <name>MDA/1 registries</name>
      <thead>
        <tr>
          <th>Registry</th>
          <th>Registration policy</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Artifact Types</td>
          <td>0x01-0x7F Specification Required; 0x80-0xBF Experimental Use; 0xC0-0xFF Private Use; 0x00 reserved</td>
        </tr>
        <tr>
          <td>Header Flags</td>
          <td>Standards Action</td>
        </tr>
        <tr>
          <td>Signature Algorithms</td>
          <td>Specification Required</td>
        </tr>
        <tr>
          <td>Signature Purposes</td>
          <td>Standards Action</td>
        </tr>
        <tr>
          <td>Key Algorithms (13.22)</td>
          <td>Specification Required</td>
        </tr>
        <tr>
          <td>HPKE Suites</td>
          <td>Specification Required</td>
        </tr>
        <tr>
          <td>Record Kinds</td>
          <td>Specification Required (per layout)</td>
        </tr>
        <tr>
          <td>Closed enumerations</td>
          <td>Specification Required</td>
        </tr>
        <tr>
          <td>Open enumerations</td>
          <td>Expert Review</td>
        </tr>
        <tr>
          <td>Error Codes</td>
          <td>Expert Review</td>
        </tr>
        <tr>
          <td>VB01 AEAD Identifiers</td>
          <td>Specification Required</td>
        </tr>
      </tbody>
    </table>
    <t>Designated experts <bcp14>SHOULD</bcp14> check that a new closed value comes with complete processing rules, and that a new artifact type meets the container rules and the alignment and canonicalization requirements of this document.</t>
</section>
</section>
  </middle>
  <back>
    <references anchor="sec-22">
      <name>References</name>
      <references anchor="sec-22-1">
        <name>Normative References</name>
        <reference anchor="DID-CORE" target="https://www.w3.org/TR/did-core/">
          <front>
            <title>Decentralized Identifiers (DIDs) v1.0</title>
            <author initials="M." surname="Sporny" fullname="M. Sporny"/>
            <author initials="D." surname="Longley" fullname="D. Longley"/>
            <author initials="M." surname="Sabadello" fullname="M. Sabadello"/>
            <author initials="D." surname="Reed" fullname="D. Reed"/>
            <author initials="O." surname="Steele" fullname="O. Steele"/>
            <author initials="C." surname="Allen" fullname="C. Allen"/>
            <date year="2022" month="July"/>
          </front>
          <seriesInfo name="W3C REC" value="did-core"/>
          <refcontent>W3C</refcontent>
        </reference>
        <reference anchor="DIDKEY" target="https://w3c-ccg.github.io/did-method-key/">
          <front>
            <title>The did:key Method</title>
            <author initials="D." surname="Longley" fullname="D. Longley"/>
            <author initials="D." surname="Zagidulin" fullname="D. Zagidulin"/>
            <author initials="M." surname="Sporny" fullname="M. Sporny"/>
            <date/>
          </front>
          <refcontent>W3C Credentials Community Group</refcontent>
        </reference>
        <reference anchor="FIPS180-4" target="https://doi.org/10.6028/NIST.FIPS.180-4">
          <front>
            <title>Secure Hash Standard (SHS)</title>
            <author><organization>NIST</organization></author>
            <date year="2015" month="August"/>
          </front>
          <seriesInfo name="FIPS PUB" value="180-4"/>
          <seriesInfo name="DOI" value="10.6028/NIST.FIPS.180-4"/>
        </reference>
        <reference anchor="FIPS203" target="https://doi.org/10.6028/NIST.FIPS.203">
          <front>
            <title>Module-Lattice-Based Key-Encapsulation Mechanism Standard</title>
            <author><organization>NIST</organization></author>
            <date year="2024" month="August"/>
          </front>
          <seriesInfo name="FIPS PUB" value="203"/>
          <seriesInfo name="DOI" value="10.6028/NIST.FIPS.203"/>
        </reference>
        <reference anchor="FIPS204" target="https://doi.org/10.6028/NIST.FIPS.204">
          <front>
            <title>Module-Lattice-Based Digital Signature Standard</title>
            <author><organization>NIST</organization></author>
            <date year="2024" month="August"/>
          </front>
          <seriesInfo name="FIPS PUB" value="204"/>
          <seriesInfo name="DOI" value="10.6028/NIST.FIPS.204"/>
        </reference>
        <reference anchor="ISO13239">
          <front>
            <title>Information technology - Telecommunications and information exchange between systems - High-level data link control (HDLC) procedures</title>
            <author><organization>ISO/IEC</organization></author>
            <date year="2002"/>
          </front>
          <seriesInfo name="ISO/IEC" value="13239:2002"/>
        </reference>
        <reference anchor="RFC2119" target="https://www.rfc-editor.org/info/rfc2119">
          <front>
            <title>Key words for use in RFCs to Indicate Requirement Levels</title>
            <author initials="S." surname="Bradner" fullname="S. Bradner"/>
            <date year="1997" month="March"/>
          </front>
          <seriesInfo name="RFC" value="2119"/>
          <seriesInfo name="DOI" value="10.17487/RFC2119"/>
          <seriesInfo name="BCP" value="14"/>
        </reference>
        <reference anchor="RFC3161" target="https://www.rfc-editor.org/info/rfc3161">
          <front>
            <title>Internet X.509 Public Key Infrastructure Time-Stamp Protocol (TSP)</title>
            <author initials="C." surname="Adams" fullname="C. Adams"/>
            <author initials="P." surname="Cain" fullname="P. Cain"/>
            <author initials="D." surname="Pinkas" fullname="D. Pinkas"/>
            <author initials="R." surname="Zuccherato" fullname="R. Zuccherato"/>
            <date year="2001" month="August"/>
          </front>
          <seriesInfo name="RFC" value="3161"/>
          <seriesInfo name="DOI" value="10.17487/RFC3161"/>
        </reference>
        <reference anchor="RFC3629" target="https://www.rfc-editor.org/info/rfc3629">
          <front>
            <title>UTF-8, a transformation format of ISO 10646</title>
            <author initials="F." surname="Yergeau" fullname="F. Yergeau"/>
            <date year="2003" month="November"/>
          </front>
          <seriesInfo name="RFC" value="3629"/>
          <seriesInfo name="DOI" value="10.17487/RFC3629"/>
          <seriesInfo name="STD" value="63"/>
        </reference>
        <reference anchor="RFC5646" target="https://www.rfc-editor.org/info/rfc5646">
          <front>
            <title>Tags for Identifying Languages</title>
            <author initials="A." surname="Phillips" fullname="A. Phillips" role="editor"/>
            <author initials="M." surname="Davis" fullname="M. Davis" role="editor"/>
            <date year="2009" month="September"/>
          </front>
          <seriesInfo name="RFC" value="5646"/>
          <seriesInfo name="DOI" value="10.17487/RFC5646"/>
          <seriesInfo name="BCP" value="47"/>
        </reference>
        <reference anchor="RFC5869" target="https://www.rfc-editor.org/info/rfc5869">
          <front>
            <title>HMAC-based Extract-and-Expand Key Derivation Function (HKDF)</title>
            <author initials="H." surname="Krawczyk" fullname="H. Krawczyk"/>
            <author initials="P." surname="Eronen" fullname="P. Eronen"/>
            <date year="2010" month="May"/>
          </front>
          <seriesInfo name="RFC" value="5869"/>
          <seriesInfo name="DOI" value="10.17487/RFC5869"/>
        </reference>
        <reference anchor="RFC6838" target="https://www.rfc-editor.org/info/rfc6838">
          <front>
            <title>Media Type Specifications and Registration Procedures</title>
            <author initials="N." surname="Freed" fullname="N. Freed"/>
            <author initials="J." surname="Klensin" fullname="J. Klensin"/>
            <author initials="T." surname="Hansen" fullname="T. Hansen"/>
            <date year="2013" month="January"/>
          </front>
          <seriesInfo name="RFC" value="6838"/>
          <seriesInfo name="DOI" value="10.17487/RFC6838"/>
          <seriesInfo name="BCP" value="13"/>
        </reference>
        <reference anchor="RFC8032" target="https://www.rfc-editor.org/info/rfc8032">
          <front>
            <title>Edwards-Curve Digital Signature Algorithm (EdDSA)</title>
            <author initials="S." surname="Josefsson" fullname="S. Josefsson"/>
            <author initials="I." surname="Liusvaara" fullname="I. Liusvaara"/>
            <date year="2017" month="January"/>
          </front>
          <seriesInfo name="RFC" value="8032"/>
          <seriesInfo name="DOI" value="10.17487/RFC8032"/>
        </reference>
        <reference anchor="RFC8126" target="https://www.rfc-editor.org/info/rfc8126">
          <front>
            <title>Guidelines for Writing an IANA Considerations Section in RFCs</title>
            <author initials="M." surname="Cotton" fullname="M. Cotton"/>
            <author initials="B." surname="Leiba" fullname="B. Leiba"/>
            <author initials="T." surname="Narten" fullname="T. Narten"/>
            <date year="2017" month="June"/>
          </front>
          <seriesInfo name="RFC" value="8126"/>
          <seriesInfo name="DOI" value="10.17487/RFC8126"/>
          <seriesInfo name="BCP" value="26"/>
        </reference>
        <reference anchor="RFC8174" target="https://www.rfc-editor.org/info/rfc8174">
          <front>
            <title>Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words</title>
            <author initials="B." surname="Leiba" fullname="B. Leiba"/>
            <date year="2017" month="May"/>
          </front>
          <seriesInfo name="RFC" value="8174"/>
          <seriesInfo name="DOI" value="10.17487/RFC8174"/>
          <seriesInfo name="BCP" value="14"/>
        </reference>
        <reference anchor="RFC9162" target="https://www.rfc-editor.org/info/rfc9162">
          <front>
            <title>Certificate Transparency Version 2.0</title>
            <author initials="B." surname="Laurie" fullname="B. Laurie"/>
            <author initials="E." surname="Messeri" fullname="E. Messeri"/>
            <author initials="R." surname="Stradling" fullname="R. Stradling"/>
            <date year="2021" month="December"/>
          </front>
          <seriesInfo name="RFC" value="9162"/>
          <seriesInfo name="DOI" value="10.17487/RFC9162"/>
        </reference>
        <reference anchor="RFC9180" target="https://www.rfc-editor.org/info/rfc9180">
          <front>
            <title>Hybrid Public Key Encryption</title>
            <author initials="R." surname="Barnes" fullname="R. Barnes"/>
            <author initials="K." surname="Bhargavan" fullname="K. Bhargavan"/>
            <author initials="B." surname="Lipp" fullname="B. Lipp"/>
            <author initials="C." surname="Wood" fullname="C. Wood"/>
            <date year="2022" month="February"/>
          </front>
          <seriesInfo name="RFC" value="9180"/>
          <seriesInfo name="DOI" value="10.17487/RFC9180"/>
        </reference>
        <reference anchor="SP800-38D" target="https://doi.org/10.6028/NIST.SP.800-38D">
          <front>
            <title>Recommendation for Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC</title>
            <author initials="M." surname="Dworkin" fullname="M. Dworkin"/>
            <date year="2007" month="November"/>
          </front>
          <seriesInfo name="NIST SP" value="800-38D"/>
          <seriesInfo name="DOI" value="10.6028/NIST.SP.800-38D"/>
        </reference>
        <reference anchor="UAX15" target="https://www.unicode.org/reports/tr15/">
          <front>
            <title>Unicode Normalization Forms</title>
            <author><organization>Unicode Consortium</organization></author>
            <date/>
          </front>
          <seriesInfo name="Unicode Standard Annex" value="15"/>
        </reference>
        <reference anchor="XWING" target="https://datatracker.ietf.org/doc/draft-connolly-cfrg-xwing-kem/">
          <front>
            <title>X-Wing: general-purpose hybrid post-quantum KEM</title>
            <author initials="D." surname="Connolly" fullname="D. Connolly"/>
            <author initials="P." surname="Schwabe" fullname="P. Schwabe"/>
            <author initials="B." surname="Westerbaan" fullname="B. Westerbaan"/>
            <date/>
          </front>
          <seriesInfo name="Internet-Draft" value="draft-connolly-cfrg-xwing-kem"/>
        </reference>
      </references>
      <references anchor="sec-22-2">
        <name>Informative References</name>
        <reference anchor="FHIR" target="https://hl7.org/fhir/R4/">
          <front>
            <title>Fast Healthcare Interoperability Resources (FHIR) Release 4</title>
            <author><organization>HL7</organization></author>
            <date/>
          </front>
        </reference>
        <reference anchor="IPS" target="https://hl7.org/fhir/uv/ips/">
          <front>
            <title>International Patient Summary Implementation Guide</title>
            <author><organization>HL7</organization></author>
            <date/>
          </front>
        </reference>
        <reference anchor="VC" target="https://www.w3.org/TR/vc-data-model-2.0/">
          <front>
            <title>Verifiable Credentials Data Model v2.0</title>
            <author initials="M." surname="Sporny" fullname="M. Sporny"/>
            <date/>
          </front>
          <refcontent>W3C</refcontent>
        </reference>
      </references>
    </references>
<section anchor="app-a" numbered="true" toc="default">
  <name>Test Vectors</name>
    <t>All values are hexadecimal unless noted otherwise. The vectors were produced by an independent reference encoder, and the reference validator accepts them.</t>
<section anchor="app-a-1" numbered="true" toc="default">
  <name>Keys and Identifiers</name>
    <t>The signing key is <xref target="RFC8032" section="7.1" sectionFormat="comma"/> TEST 1:</t>
    <artwork type="ascii-art" align="left"><![CDATA[
secret seed: 9d61b19deffd5a60ba844af492ec2cc4
             4449c5697b326919703bac031cae7f60
public key:  d75a980182b10ab7d54bfed3c964073a
             0ee172f3daa62325af021a68f707511a
did:key:     did:key:z6MktwupdmLXVVqTzCw4i46r4uGyosGXRnR3XjN4Zq7oMMsw
T0 = 1795305600000 (2026-11-22T00:00:00Z, decimal)
requestId = 000102...0f; sessionId = 101112...1f;
nonce     = 202122...2f
]]></artwork>
</section>
<section anchor="app-a-2" numbered="true" toc="default">
  <name>ScopeDigest</name>
    <t>The single Scope record is subkind = 0x03 (latest), field1 absent, field2 = "lab", field3 = "hematology", and ts1 = ts2 = num = 0:</t>
    <artwork type="ascii-art" align="left"><![CDATA[
ScopeDigest = 6071d110d4bc57295cdef4589f6aa9ae
              a523bebf913546720c534acc392a5a10
]]></artwork>
</section>
<section anchor="app-a-3" numbered="true" toc="default">
  <name>Signed REQUEST</name>
    <t>A REQUEST with that Scope record and one Ed25519 author signature. requesterDID is the did:key above, purpose = "treatment", requestedActions = 0x0001 (read), issuedAt = T0, expiresAt = T0 + 86400000, signedAt = T0, and keyRef absent.</t>
    <artwork type="ascii-art" align="left"><![CDATA[
totalLen  = 432   bodyLen   = 128   recCount  = 1
recStride = 48    sigCount  = 1     sigStride = 32
strCount  = 4     strOff    = 272   strLen    = 96
blobOff   = 368   blobLen   = 0     sigValOff = 368
sigValLen = 64
strings (in table order): the did:key (56 octets), "hematology",
"lab", "treatment"
]]></artwork>
    <artwork type="ascii-art" align="left"><![CDATA[
0000: 4d 44 41 31 01 00 01 00 01 00 04 00 b0 01 00 00
0010: 80 00 00 00 01 00 30 00 01 00 20 00 10 01 00 00
0020: 60 00 00 00 70 01 00 00 00 00 00 00 70 01 00 00
0030: 40 00 00 00 37 87 dc 29 00 00 00 00 00 00 00 00
0040: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
0050: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
0060: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
0070: 00 74 8d 00 a2 01 00 00 00 d0 b3 05 a2 01 00 00
0080: 10 01 00 00 5c 01 00 00 01 00 00 00 00 00 00 00
0090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00c0: 05 03 00 00 ff ff ff ff 56 01 00 00 4a 01 00 00
00d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00f0: 10 01 00 00 01 01 00 00 00 74 8d 00 a2 01 00 00
0100: ff ff ff ff 70 01 00 00 40 00 00 00 00 00 00 00
0110: 38 00 64 69 64 3a 6b 65 79 3a 7a 36 4d 6b 74 77
0120: 75 70 64 6d 4c 58 56 56 71 54 7a 43 77 34 69 34
0130: 36 72 34 75 47 79 6f 73 47 58 52 6e 52 33 58 6a
0140: 4e 34 5a 71 37 6f 4d 4d 73 77 0a 00 68 65 6d 61
0150: 74 6f 6c 6f 67 79 03 00 6c 61 62 00 09 00 74 72
0160: 65 61 74 6d 65 6e 74 00 00 00 00 00 00 00 00 00
0170: fd 97 2d c0 67 17 fd 1d 98 5a 03 c4 84 8a 3b 96
0180: ac 82 2b e0 da ac d0 89 d1 5a 60 18 c8 7d 07 61
0190: b7 7d 73 3a 63 89 ec 8f b7 c2 7b b2 42 64 ee 6d
01a0: 63 0d 2f 14 0f 5d 1b b4 66 7d df 1a 95 77 a2 09
]]></artwork>
    <artwork type="ascii-art" align="left"><![CDATA[
ArtifactID = 1b62d25af0d87deeed4ca1a6880f21b5
             07a55fe9c1a3dc036fb8f28bd7ca5c00
TBS        = 4d44413153494700 || ArtifactID
Signature  = fd972dc06717fd1d985a03c4848a3b96
             ac822be0daacd089d15a6018c87d0761
             b77d733a6389ec8fb7c27bb24264ee6d
             630d2f140f5d1bb4667ddf1a9577a209
crc32      = 0x29dc8737
]]></artwork>
</section>
<section anchor="app-a-4" numbered="true" toc="default">
  <name>Negative Variants</name>
    <t>Each variant below is derived from A.3. Where noted, the CRC is recomputed after the change. A conforming receiver <bcp14>MUST</bcp14> reject every one, with the code shown.</t>
    <table anchor="tbl-negative-test-variants">
      <name>Negative test variants</name>
      <thead>
        <tr>
          <th>Variant</th>
          <th>Expected rejection</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>16 zero octets appended</td>
          <td>LENGTH_MISMATCH</td>
        </tr>
        <tr>
          <td>last 16 octets removed</td>
          <td>LENGTH_MISMATCH</td>
        </tr>
        <tr>
          <td>totalLen field + 16</td>
          <td>LENGTH_MISMATCH</td>
        </tr>
        <tr>
          <td>type = 0x07 (CRC recomputed)</td>
          <td>UNKNOWN_TYPE</td>
        </tr>
        <tr>
          <td>FLAG_SIGNED cleared (CRC recomputed)</td>
          <td>NON_CANONICAL</td>
        </tr>
        <tr>
          <td>re-encoded with no signature</td>
          <td>MISSING_SIGNATURE</td>
        </tr>
        <tr>
          <td>purpose author -&gt; counter-signature (CRC)</td>
          <td>MISSING_SIGNATURE</td>
        </tr>
        <tr>
          <td>signedAt + 1 (CRC recomputed)</td>
          <td>INVALID_SIGNATURE</td>
        </tr>
        <tr>
          <td>same content signed by another did:key</td>
          <td>SIGNER_NOT_AUTHORIZED</td>
        </tr>
        <tr>
          <td>any single-bit flip</td>
          <td>rejected (INVALID_CRC32 or earlier)</td>
        </tr>
        <tr>
          <td>any single-octet change outside crc32,</td>
          <td>rejected (no octet</td>
        </tr>
        <tr>
          <td>CRC recomputed</td>
          <td>is malleable)</td>
        </tr>
      </tbody>
    </table>
</section>
<section anchor="app-a-5" numbered="true" toc="default">
  <name>VB01 Frame</name>
    <t>The frame uses bucketExp = 8 (a 256-octet frame). The plaintext is the ASCII string "MDA1 VB01 test vector" followed by a line feed (22 octets).</t>
    <artwork type="ascii-art" align="left"><![CDATA[
DEK       = 404142434445464748494a4b4c4d4e4f
            505152535455565758595a5b5c5d5e5f
nonce     = a0a1a2a3a4a5a6a7a8a9aaab
K_enc     = 1ac919a7a01e269cb7c65f8bc6c9f561
            8ac8f44822e54e41cacbcbb814b1fb49
keyCommit = 37c974687a922fb022000b241931a04d
            1a4a01070bb0bfb7f3d7bec38ced9e5b
]]></artwork>
    <artwork type="ascii-art" align="left"><![CDATA[
0000: 56 42 30 31 01 01 08 00 a0 a1 a2 a3 a4 a5 a6 a7
0010: a8 a9 aa ab 00 00 00 00 00 00 00 00 00 00 00 00
0020: 37 c9 74 68 7a 92 2f b0 22 00 0b 24 19 31 a0 4d
0030: 1a 4a 01 07 0b b0 bf b7 f3 d7 be c3 8c ed 9e 5b
0040: af 50 19 d5 e1 d3 aa b0 49 08 87 46 02 eb ed bb
0050: 7d 48 8f b8 b9 45 7e 55 cd 1c 87 1b f1 83 5f 9f
0060: f0 2c 07 95 fc 57 1d b2 72 32 9f 88 90 07 e7 42
0070: 6f 90 98 d6 42 7a 8a 37 66 d0 d9 18 32 50 66 01
0080: bc 4d 5b b9 c4 56 65 2e bd 1e 79 a6 c9 4e 9c f7
0090: f9 29 66 a4 29 7a 0e b0 4e 6f 88 10 90 a1 6a 39
00a0: f9 12 b7 65 40 56 63 61 8e 59 3e 7a b9 92 73 50
00b0: 37 2b ec ce c0 91 f1 94 71 88 5a 10 89 51 5f ec
00c0: 09 71 dc 67 98 6a a8 64 48 e6 e8 d7 ea ba 1b 22
00d0: 61 d4 40 4e c3 3e fc ce d3 4c ad 48 57 cc 82 9f
00e0: a7 6e ff 4f fc 3e 9b ce d4 c5 1c 8b 2e 2d 44 dd
00f0: a7 35 ec 09 d3 ae 28 7b 17 13 9f 70 62 d8 7b f0
]]></artwork>
    <artwork type="ascii-art" align="left"><![CDATA[
blobHash  = 54fbe6ae5ad5b159689bb3defbd11de0
            2027d81d3471ddf8d2926c6be5eb980d
]]></artwork>
    <t>Opening the frame with any other DEK <bcp14>MUST</bcp14> fail at the keyCommit check (KEY_COMMITMENT_MISMATCH) before AES-GCM is run.</t>
</section>
</section>
<section anchor="app-b" numbered="true" toc="default">
  <name>Implementation Guidance for C and C++ (Informative)</name>
    <ul spacing="normal">
      <li>Read fields through accessor functions that use memcpy() and an explicit little-endian conversion. Do not use casts to packed structs. Every multi-byte field is naturally aligned relative to the artifact base, but input buffers are not always aligned, and big-endian hosts still need byte swapping.</li>
      <li>If you mirror layouts as structs for documentation or tests, pin them with static_assert(sizeof(T) == N) and static_assert(offsetof(T, f) == k).</li>
      <li>Do offset arithmetic in uint64_t (C-12). The u16 by u16 product recCount * recStride fits in 32 bits, but sums of such products with u32 lengths do not.</li>
      <li>Phase B needs at most two 4096-octet bitmaps. One marks the string entry starts (strLen &lt;= 65536, and entries start at even offsets); the other marks which entries are referenced. The span placement check needs only a running cursor. Neither needs heap memory.</li>
      <li>Compute ArtifactID and the CRC in a streaming pass that substitutes zeros for octets 52-55, without copying the buffer.</li>
      <li>Use a constant-time comparison (for example, CRYPTO_memcmp or sodium_memcmp) for keyCommit and other secret-dependent checks.</li>
      <li>Fuzz the validator with libFuzzer or AFL++ under AddressSanitizer and UndefinedBehaviorSanitizer, seeded with the Appendix <xref target="app-a" format="counter"/> vectors. Requirement R5 asks for at least 10^6 executions.</li>
    </ul>
    <t>A topology check for phase A could look like this:</t>
    <sourcecode type="c" markers="true"><![CDATA[
static inline uint32_t ld32(const uint8_t *p) {
    uint32_t v; memcpy(&v, p, 4); return le32toh(v);
}
static inline uint16_t ld16(const uint8_t *p) {
    uint16_t v; memcpy(&v, p, 2); return le16toh(v);
}

mda_err mda_frame(const uint8_t *b, size_t n, const mda_type **t)
{
    if (n < 64)                       return MDA_BOUNDS_EXCEEDED;
    if (memcmp(b, "MDA1", 4) != 0)    return MDA_BAD_MAGIC;
    if (b[4] != 1)                    return MDA_UNKNOWN_VERSION;
    uint64_t total = ld32(b + 12);
    if (total != n)                   return MDA_LENGTH_MISMATCH;
    if (total > (4u << 20) || (total & 15))
                                      return MDA_BOUNDS_EXCEEDED;
    if (!(*t = mda_type_lookup(b[6]))) return MDA_UNKNOWN_TYPE;
    /* A4, A5 omitted for brevity */
    uint64_t body = ld32(b + 16);
    uint64_t rc = ld16(b + 20), rs = ld16(b + 22);
    uint64_t sc = ld16(b + 24), ss = ld16(b + 26);
    if (body != (*t)->body_len ||
        rs != (rc ? (*t)->stride : 0) || ss != (sc ? 32 : 0) ||
        (rc && (*t)->stride == 0))    return MDA_COUNT_MISMATCH;
    uint64_t str = 64 + body + rc * rs + sc * ss;
    uint64_t sl = ld32(b + 32), bl = ld32(b + 40);
    uint64_t vl = ld32(b + 48);
    if (ld32(b + 28) != str || ld32(b + 36) != str + sl ||
        ld32(b + 44) != str + sl + bl ||
        ((sl | bl | vl) & 15) || str + sl + bl + vl != total)
                                      return MDA_OFFSET_MISMATCH;
    return mda_crc_ok(b, n) ? MDA_OK : MDA_INVALID_CRC32;
}
]]></sourcecode>
</section>
  </back>
</rfc>
