<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="rfc7991bis.rnc"?>
<!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">
]>
<rfc xmlns:xi="http://www.w3.org/2001/XInclude"
     category="info"
     docName="draft-greicodex-fidex-protocol-02"
     ipr="trust200902"
     submissionType="independent"
     version="3">
  <!-- FRONT MATTER -->
  <front>
    <title abbrev="FideX AS5 Protocol">FideX Application Statement 5 (AS5) Protocol</title>
    <seriesInfo name="Internet-Draft" value="draft-greicodex-fidex-protocol-02"/>
    <author fullname="Javier Munoz" initials="J." surname="Munoz">
      <organization>Greicodex Software</organization>
      <address>
        <email>javier@greicodex.com</email>
        <uri>https://greicodex.com</uri>
      </address>
    </author>
    <date year="2026" month="December" day="4"/>
    <area>Applications and Real-Time Area (art)</area>
    <workgroup>Individual Submission</workgroup>
    <keyword>EDI</keyword>
    <keyword>B2B</keyword>
    <keyword>JOSE</keyword>
    <keyword>JWS</keyword>
    <keyword>JWE</keyword>
    <keyword>AS5</keyword>
    <keyword>electronic data interchange</keyword>
    <keyword>JSON Web Signature</keyword>
    <keyword>JSON Web Encryption</keyword>
    <keyword>CloudEvents</keyword>
    <keyword>events</keyword>
    <abstract>
      <t>
        This document specifies the FideX Protocol (AS5), a modern application-layer protocol
        for secure Business-to-Business (B2B) message exchange. FideX provides cryptographic
        non-repudiation, data integrity, and confidentiality using JOSE (JSON Object Signing
        and Encryption) over HTTPS, replacing legacy AS2 and AS4 standards with a REST-oriented
        approach accessible to modern web developers.
      </t>
      <t>
        FideX adopts the "AS" naming lineage: AS2 (<xref target="RFC4130"/>) used
        S/MIME over HTTP; AS4 (<xref target="OASIS-ebMS"/>) used SOAP/WS-Security;
        AS5 (FideX) uses REST/JSON/JOSE over HTTPS.
        This document defines the message format, cryptographic operations, partner discovery,
        state management, acknowledgment receipts (J-MDN), and error handling.
      </t>
      <t>
        This revision adds an optional event capability. Events are represented as
        CNCF CloudEvents version 1.0 and are exchanged between partners
        inside the existing FideX envelope, with the same signature, encryption,
        and receipt guarantees as business documents.
      </t>
    </abstract>
    <note title="Status of This Document">
      <t>
        This Internet-Draft is submitted in full conformance with the provisions of BCP 78
        and BCP 79. This document is a work in progress and represents the current thinking
        of the FideX Protocol Working Group at Greicodex Software.
      </t>
    </note>
  </front>

  <!-- MIDDLE: MAIN BODY -->
  <middle>

    <!-- SECTION 1: INTRODUCTION -->
    <section anchor="introduction" numbered="true" toc="default">
      <name>Introduction</name>
      <section anchor="purpose" numbered="true" toc="default">
        <name>Purpose</name>
        <t>
          FideX (Fast Integration for Digital Enterprises eXchange) defines a secure,
          reliable message exchange protocol for B2B electronic data interchange. The
          protocol ensures:
        </t>
        <ul spacing="normal">
          <li><strong>Non-repudiation:</strong> Cryptographic proof of message origin</li>
          <li><strong>Integrity:</strong> Detection of message tampering</li>
          <li><strong>Confidentiality:</strong> End-to-end encryption</li>
          <li><strong>Reliability:</strong> Asynchronous acknowledgments with retry semantics</li>
        </ul>
      </section>
      <section anchor="scope" numbered="true" toc="default">
        <name>Scope</name>
        <t>This specification defines:</t>
        <ul spacing="normal">
          <li>Message format and structure</li>
          <li>Cryptographic operations (sign-then-encrypt using JOSE)</li>
          <li>Partner discovery and registration</li>
          <li>State management and acknowledgments (J-MDN)</li>
          <li>Error codes and handling</li>
          <li>Optional exchange of events represented as CloudEvents
          (<xref target="events"/>)</li>
        </ul>
        <t>This specification does NOT define:</t>
        <ul spacing="normal">
          <li>Business document formats (the protocol is payload-agnostic)</li>
          <li>Application-specific processing logic</li>
          <li>Event types and event data for business occurrences, event
          subscription management, or command (request/response) semantics</li>
          <li>Implementation details or code examples</li>
          <li>Deployment or operational procedures</li>
        </ul>
      </section>
      <section anchor="as-naming" numbered="true" toc="default">
        <name>AS Naming Lineage</name>
        <t>
          FideX adopts the "AS" (Application Statement) naming lineage from established
          B2B interchange standards:
        </t>
        <ul spacing="normal">
          <li><strong>AS2</strong> (<xref target="RFC4130"/>) --
          MIME/S/MIME over HTTP (2005)</li>
          <li><strong>AS4</strong> (<xref target="OASIS-ebMS"/>) --
          SOAP/WS-Security over HTTP (2013)</li>
          <li><strong>AS5</strong> (FideX) --
          REST/JSON/JOSE over HTTPS (2026)</li>
        </ul>
        <t>
          The designation signals evolutionary continuity while marking a generational
          leap to modern web-native architecture. AS5 is implementable by any developer
          with knowledge of REST APIs and standard JOSE libraries, without requiring
          specialized B2B middleware.
        </t>
      </section>
      <section anchor="terminology" numbered="true" toc="default">
        <name>Terminology</name>
        <t>
          The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
          "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
          "OPTIONAL" 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>
        <t>Additional terms used in this document:</t>
        <dl newline="false" spacing="normal">
          <dt>Node</dt>
          <dd>A FideX-compliant server capable of sending and receiving messages.</dd>
          <dt>Partner</dt>
          <dd>A trading partner with an established trust relationship.</dd>
          <dt>Message</dt>
          <dd>A business document wrapped in a FideX envelope.</dd>
          <dt>J-MDN</dt>
          <dd>JSON Message Disposition Notification  -- a signed receipt acknowledging
          receipt and processing of a FideX message.</dd>
          <dt>JWKS</dt>
          <dd>JSON Web Key Set  -- a JSON structure representing a set of public keys.</dd>
          <dt>AS5 Configuration</dt>
          <dd>A JSON document published by a node describing its endpoints, supported
          algorithms, and identity.</dd>
          <dt>Event</dt>
          <dd>A record stating that something happened (an occurrence), expressed
          as a CloudEvent as defined in <xref target="CloudEvents"/>. An event
          states a fact; it is not a request for the consumer to act.</dd>
          <dt>Event Message</dt>
          <dd>A FideX message whose business payload is a single CloudEvent
          (see <xref target="event-messages"/>).</dd>
          <dt>Protocol Event</dt>
          <dd>An event, defined by this document, that a node emits about the
          life cycle of a FideX message (see <xref target="protocol-events"/>).</dd>
          <dt>Producer / Consumer</dt>
          <dd>The party that creates an event, and a party that receives and
          acts on it, as in <xref target="CloudEvents"/>.</dd>
        </dl>
      </section>
    </section>

    <!-- SECTION 2: TRANSPORT LAYER -->
    <section anchor="transport" numbered="true" toc="default">
      <name>Transport Layer</name>
      <section anchor="required-transport" numbered="true" toc="default">
        <name>Required Transport</name>
        <t>
          Nodes MUST support HTTP/1.1 over TLS 1.3 as defined in <xref target="RFC8446"/>.
          TLS 1.2 (<xref target="RFC5246"/>) MAY be supported with Perfect Forward Secrecy
          (ECDHE key exchange) as fallback for backward compatibility.
        </t>
        <t>Transport requirements:</t>
        <ul spacing="normal">
          <li>Port 443 (HTTPS)</li>
          <li>Valid certificate from a trusted Certificate Authority (CA)</li>
          <li>Server Name Indication (SNI) per <xref target="RFC6066"/></li>
          <li>Full certificate chain validation</li>
        </ul>
      </section>
      <section anchor="optional-transports" numbered="true" toc="default">
        <name>Optional Transports</name>
        <t>Nodes MAY additionally support:</t>
        <ul spacing="normal">
          <li><strong>HTTP/2</strong> (<xref target="RFC9113"/>):
          For multiplexed connections and improved throughput.</li>
          <li><strong>HTTP/3</strong> (<xref target="RFC9114"/>): For connection resilience using QUIC.</li>
        </ul>
      </section>
      <section anchor="request-method" numbered="true" toc="default">
        <name>Request Method</name>
        <t>
          All FideX message transmissions MUST use the HTTP POST method to the receiving
          endpoint specified in the partner's AS5 configuration (see <xref target="discovery"/>).
        </t>
      </section>
      <section anchor="content-type" numbered="true" toc="default">
        <name>Content Type</name>
        <t>
          FideX message envelopes MUST use <tt>Content-Type: application/json</tt>.
          Registration requests MUST use <tt>Content-Type: application/jose</tt>
          (see <xref target="discovery-handshake"/>).
        </t>
      </section>
      <section anchor="message-size" numbered="true" toc="default">
        <name>Message Size Limits</name>
        <t>
          Implementations MUST accept messages up to 10 megabytes (10,000,000 octets
          in the complete HTTP request body, including the JSON envelope and all JOSE
          serialization overhead). This is not a limit on the unencoded business document.
          Implementations MAY accept larger messages by prior bilateral agreement.
          Senders MUST NOT assume support above 10 MB without prior explicit agreement.
          Implementations SHOULD reject oversized messages with HTTP 413 and the error
          code <tt>PAYLOAD_TOO_LARGE</tt> (see <xref target="error-codes"/>).
        </t>
      </section>
    </section>

    <!-- SECTION 3: MESSAGE STRUCTURE -->
    <section anchor="message-structure" numbered="true" toc="default">
      <name>Message Structure</name>
      <section anchor="envelope" numbered="true" toc="default">
        <name>Message Envelope</name>
        <t>
          A FideX message envelope consists of exactly two top-level JSON fields:
        </t>
        <sourcecode name="envelope-structure" type="json"><![CDATA[
{
  "routing_header": { ... },
  "encrypted_payload": "eyJhbGc..."
}
        ]]></sourcecode>
        <t>
          The <tt>routing_header</tt> is cleartext JSON containing message metadata
          readable by intermediate infrastructure without decryption. The
          <tt>encrypted_payload</tt> is a JWE compact serialization that wraps the
          signed business document. These two fields are the ONLY top-level fields
          in a FideX message envelope.
        </t>
      </section>
      <section anchor="routing-header" numbered="true" toc="default">
        <name>Routing Header</name>
        <t>
          The routing header is a cleartext JSON object conveying message routing
          metadata. It MUST contain the following fields:
        </t>
        <dl newline="false" spacing="normal">
          <dt>fidex_version</dt>
          <dd>
            (string, REQUIRED) Protocol version in semantic "major.minor" format, e.g., "1.0".
          </dd>
          <dt>message_id</dt>
          <dd>
            (string, REQUIRED) Globally unique message identifier. UUID v4
            (<xref target="RFC9562"/>) with an "fdx-" prefix is RECOMMENDED
            (e.g., "fdx-550e8400-e29b-41d4-a716-446655440000").
          </dd>
          <dt>sender_id</dt>
          <dd>
            (string, REQUIRED) URN of the sending organization. See
            <xref target="identifier-format"/> for valid formats.
          </dd>
          <dt>receiver_id</dt>
          <dd>
            (string, REQUIRED) URN of the receiving organization. See
            <xref target="identifier-format"/> for valid formats.
          </dd>
          <dt>document_type</dt>
          <dd>
            (string, REQUIRED) Business document type identifier. MUST match the pattern
            <tt>^[A-Z0-9_]+$</tt>. See <xref target="document-type-registry"/>.
          </dd>
          <dt>timestamp</dt>
          <dd>
            (string, REQUIRED) ISO 8601 UTC timestamp with millisecond precision.
            Format: <tt>YYYY-MM-DDTHH:mm:ss.SSSZ</tt>. The UTC designator "Z" MUST
            be used; no local timezone offsets are permitted.
          </dd>
          <dt>receipt_webhook</dt>
          <dd>
            (string, OPTIONAL) HTTPS URL where the J-MDN receipt SHOULD be delivered.
            HTTP (non-TLS) is NOT allowed. When omitted, the receiver MUST deliver
            the J-MDN to the sender's <tt>receive_receipt</tt> endpoint from the
            sender's AS5 configuration (see <xref target="jmdn-delivery"/>).
          </dd>
          <dt>payload_digest</dt>
          <dd>
            (string, OPTIONAL) SHA-256 digest of the <tt>encrypted_payload</tt> field
            value. Computed as "sha256:" followed by the lowercase hexadecimal encoding
            of SHA-256 applied to the UTF-8 byte representation of the
            <tt>encrypted_payload</tt> string as it appears in the JSON envelope.
            Enables routing-layer integrity checks without decryption.
          </dd>
        </dl>
        <t>
          Extension fields MAY be included and MUST use the prefix "x-" to avoid
          collision with future standard fields. Implementations MUST ignore unknown
          extension fields without error.
        </t>
        <section anchor="identifier-format" numbered="true" toc="default">
          <name>Identifier Format</name>
          <t>
            The <tt>sender_id</tt> and <tt>receiver_id</tt> fields MUST use URN format.
            The following URN namespaces are recognized:
          </t>
          <ul spacing="normal">
            <li><tt>urn:gln:{gln}</tt>  -- GS1 Global Location Number</li>
            <li><tt>urn:duns:{duns}</tt>  -- D-U-N-S Number</li>
            <li><tt>urn:lei:{lei}</tt>  -- Legal Entity Identifier (ISO 17442)</li>
            <li><tt>urn:tin:{tin}</tt>  -- Tax Identification Number</li>
            <li><tt>urn:custom:{identifier}</tt>  -- Organization-defined identifier</li>
          </ul>
        </section>
      </section>
      <section anchor="document-type-registry" numbered="true" toc="default">
        <name>Document Type Registry</name>
        <t>
          The <tt>document_type</tt> field uses a two-tier naming system to accommodate
          both standardized inter-organization document types and organization-specific
          custom types.
        </t>
        <section anchor="standard-document-types" numbered="true" toc="default">
          <name>Standard Document Types</name>
          <t>
            The following standard document types are defined by the FideX Working Group.
            Standard types use uppercase alphanumeric characters and underscores, matching
            the pattern <tt>^[A-Z0-9_]+$</tt>. GS1 document types are defined in
            <xref target="GS1-JSON"/>.
          </t>
          <table align="center">
            <name>Standard FideX Document Types</name>
            <thead>
              <tr><th>Type Identifier</th><th>Standard</th><th>Description</th></tr>
            </thead>
            <tbody>
              <tr><td>GS1_ORDER_JSON</td><td>GS1</td><td>Purchase order (JSON binding)</td></tr>
              <tr><td>GS1_INVOICE_JSON</td><td>GS1</td><td>Commercial invoice (JSON binding)</td></tr>
              <tr><td>GS1_DESADV_JSON</td><td>GS1</td><td>Despatch advice (JSON binding)</td></tr>
              <tr><td>GS1_RECADV_JSON</td><td>GS1</td><td>Receiving advice (JSON binding)</td></tr>
              <tr><td>GS1_CATALOG_JSON</td><td>GS1</td><td>Product catalog (JSON binding)</td></tr>
              <tr><td>X12_850</td><td>ANSI X12</td><td>Purchase order</td></tr>
              <tr><td>X12_810</td><td>ANSI X12</td><td>Invoice</td></tr>
              <tr><td>X12_856</td><td>ANSI X12</td><td>Advance ship notice</td></tr>
              <tr><td>EDIFACT_ORDERS</td><td>UN/EDIFACT</td><td>Purchase order message</td></tr>
              <tr><td>EDIFACT_INVOIC</td><td>UN/EDIFACT</td><td>Invoice message</td></tr>
              <tr><td>EDIFACT_DESADV</td><td>UN/EDIFACT</td><td>Despatch advice message</td></tr>
              <tr><td>UBL_ORDER_21</td><td>OASIS UBL 2.1</td><td>Order document</td></tr>
              <tr><td>UBL_INVOICE_21</td><td>OASIS UBL 2.1</td><td>Invoice document</td></tr>
              <tr><td>CLOUDEVENTS_JSON</td><td>CNCF CloudEvents 1.0</td><td>Single event in the JSON Event Format (see <xref target="event-messages"/>)</td></tr>
            </tbody>
          </table>
        </section>
        <section anchor="custom-document-types" numbered="true" toc="default">
          <name>Custom Document Types</name>
          <t>
            Organizations MAY define custom document types using reverse domain notation
            to avoid collision with standard types and with other organizations' custom types.
          </t>
          <t>
            Custom types MUST follow the pattern: <tt>{TLD}_{ORG}_{DOCTYPE}_{VERSION}</tt>,
            for example: <tt>COM_ACME_WAREHOUSE_RECEIPT_V2</tt>.
          </t>
          <t>
            Custom types MUST NOT use the reserved prefixes: <tt>GS1_</tt>,
            <tt>X12_</tt>, <tt>EDIFACT_</tt>, <tt>UBL_</tt>, or
            <tt>CLOUDEVENTS_</tt>.
          </t>
        </section>
        <section anchor="receiver-document-type-behavior" numbered="true" toc="default">
          <name>Receiver Behavior for Document Types</name>
          <t>Receiver nodes:</t>
          <ul spacing="normal">
            <li>MUST accept messages with any syntactically valid <tt>document_type</tt>.</li>
            <li>SHOULD return a J-MDN with error code <tt>UNKNOWN_DOCUMENT_TYPE</tt>
            for types they cannot process.</li>
            <li>MUST NOT reject messages at the HTTP level solely because of an
            unknown <tt>document_type</tt>. The J-MDN mechanism MUST be used instead.</li>
          </ul>
        </section>
      </section>
      <section anchor="encrypted-payload-field" numbered="true" toc="default">
        <name>Encrypted Payload</name>
        <t>
          The <tt>encrypted_payload</tt> field contains a JWE (JSON Web Encryption)
          token in compact serialization as defined in <xref target="RFC7516"/>. The
          JWE encrypts a JWS (JSON Web Signature) token as defined in
          <xref target="RFC7515"/>, creating a nested "sign-then-encrypt" structure:
        </t>
        <sourcecode name="nested-structure" type="text"><![CDATA[
JWE( JWS( business_document ) )
        ]]></sourcecode>
        <t>
          This pattern ensures both authenticity (the signature is inside the
          encryption envelope, protecting it from substitution) and confidentiality
          (the business content is encrypted end-to-end).
        </t>
      </section>
    </section>

    <!-- SECTION 4: CRYPTOGRAPHIC REQUIREMENTS -->
    <section anchor="cryptography" numbered="true" toc="default">
      <name>Cryptographic Requirements</name>
      <section anchor="jws-signature" numbered="true" toc="default">
        <name>Signature (JWS)</name>
        <t>
          Messages MUST be signed using the sender's private key before encryption.
        </t>
        <t>
          The REQUIRED signing algorithm is <strong>RS256</strong>
          (RSASSA-PKCS1-v1_5 with SHA-256) as defined in <xref target="RFC7518"/>.
        </t>
        <t>The following signing algorithms are OPTIONAL:</t>
        <ul spacing="normal">
          <li>RS384, RS512  -- stronger RSA variants</li>
          <li>PS256, PS384, PS512  -- RSA-PSS variants</li>
          <li>ES256 (ECDSA with P-256 and SHA-256)  -- RECOMMENDED for new deployments</li>
          <li>ES384 (ECDSA with P-384 and SHA-384)</li>
        </ul>
        <t>
          Minimum key sizes: 2048 bits for RSA (4096 bits RECOMMENDED); P-256 minimum
          for ECDSA (P-384 RECOMMENDED).
        </t>
        <t>The JWS Protected Header MUST include:</t>
        <sourcecode name="jws-header" type="json"><![CDATA[
{
  "alg": "RS256",
  "kid": "{sender-key-id}"
}
        ]]></sourcecode>
      </section>
      <section anchor="jwe-encryption" numbered="true" toc="default">
        <name>Encryption (JWE)</name>
        <t>
          Signed messages MUST be encrypted using the receiver's public key.
        </t>
        <t>The REQUIRED algorithms are:</t>
        <ul spacing="normal">
          <li><strong>Key Encryption:</strong> RSA-OAEP as defined in <xref target="RFC7518"/></li>
          <li><strong>Content Encryption:</strong> A256GCM (AES-256-GCM)</li>
        </ul>
        <t>
          Implementations SHOULD also support RSA-OAEP-256, which uses SHA-256
          for both OAEP and MGF1, as defined in <xref target="RFC7518"/>,
          Section 4.3. Algorithm selection follows
          <xref target="encryption-negotiation"/>. RSA-OAEP remains the REQUIRED
          interoperability baseline for protocol version 1.0.
        </t>
        <t>The JWE Protected Header MUST include:</t>
        <sourcecode name="jwe-header" type="json"><![CDATA[
{
  "alg": "RSA-OAEP",
  "enc": "A256GCM",
  "cty": "JWT",
  "kid": "{receiver-key-id}"
}
        ]]></sourcecode>
        <t>
          The <tt>cty</tt> (content type) header parameter MUST be set to "JWT" to indicate
          the JWE payload contains a nested JWS/JWT token, per <xref target="RFC7516"/>
          Section 4.1.12. This is required for correct processing of nested tokens.
        </t>
      </section>
      <section anchor="payload-encoding" numbered="true" toc="default">
        <name>Payload Encoding</name>
        <t>
          The JWS payload MUST be the UTF-8 encoding of the JSON-serialized business document.
          Binary payloads (images, PDFs, etc.) MUST be base64-encoded before JWS signing.
        </t>
      </section>
      <section anchor="sender-identity" numbered="true" toc="default">
        <name>Sender Identity Verification</name>
        <t>
          Receivers MUST verify that the JWS signing key identified by <tt>kid</tt> in the
          JWS header belongs to the partner identified by <tt>sender_id</tt> in the routing
          header. Specifically:
        </t>
        <ul spacing="normal">
          <li>The <tt>kid</tt> MUST resolve to a public key in the sender's JWKS.</li>
          <li>The sender's JWKS MUST be fetched from the <tt>public_domain</tt> associated
          with the <tt>sender_id</tt> in the local partner registry.</li>
        </ul>
        <t>
          This prevents cross-partner key substitution attacks where an attacker uses a
          valid key from one partner to impersonate another.
        </t>
      </section>
      <section anchor="prohibited-algorithms" numbered="true" toc="default">
        <name>Prohibited Algorithms</name>
        <t>Implementations MUST NOT use:</t>
        <ul spacing="normal">
          <li>The <tt>none</tt> algorithm (unsigned tokens)</li>
          <li>Symmetric signature algorithms (HS256, HS384, HS512)</li>
          <li>RSA keys smaller than 2048 bits</li>
          <li>Deprecated algorithms: MD5, SHA-1-based signatures</li>
        </ul>
      </section>
    </section>

    <!-- SECTION 5: KEY DISTRIBUTION -->
    <section anchor="key-distribution" numbered="true" toc="default">
      <name>Key Distribution</name>
      <section anchor="jwks-endpoint" numbered="true" toc="default">
        <name>JSON Web Key Set (JWKS) Endpoint</name>
        <t>
          Nodes MUST publish their public keys via a JWKS endpoint at the well-known URI:
        </t>
        <sourcecode name="jwks-uri" type="text"><![CDATA[
https://{public_domain}/.well-known/jwks.json
        ]]></sourcecode>
        <t>This endpoint:</t>
        <ul spacing="normal">
          <li>MUST be publicly accessible without authentication.</li>
          <li>MUST return <tt>Content-Type: application/json</tt>.</li>
          <li>SHOULD include <tt>Cache-Control</tt> headers (1 hour RECOMMENDED).</li>
        </ul>
      </section>
      <section anchor="jwks-format" numbered="true" toc="default">
        <name>JWKS Format</name>
        <t>
          Per <xref target="RFC7517"/>, keys MUST include at minimum the following fields.
          An RSA signing key example:
        </t>
        <sourcecode name="jwks-rsa-example" type="json"><![CDATA[
{
  "keys": [
    {
      "kty": "RSA",
      "use": "sig",
      "kid": "acme-sign-rsa-2026-01",
      "alg": "RS256",
      "n": "{base64url-encoded-modulus}",
      "e": "AQAB"
    }
  ]
}
        ]]></sourcecode>
        <t>An EC signing key example:</t>
        <sourcecode name="jwks-ec-example" type="json"><![CDATA[
{
  "keys": [
    {
      "kty": "EC",
      "use": "sig",
      "kid": "acme-sign-ec-2026-01",
      "alg": "ES256",
      "crv": "P-256",
      "x": "{base64url-x-coordinate}",
      "y": "{base64url-y-coordinate}"
    }
  ]
}
        ]]></sourcecode>
        <t>Field semantics:</t>
        <dl newline="false" spacing="normal">
          <dt>kty</dt><dd>Key type: "RSA" or "EC".</dd>
          <dt>use</dt><dd>"sig" for signing keys; "enc" for encryption keys.</dd>
          <dt>kid</dt><dd>Unique key identifier used in JWS/JWE headers.</dd>
          <dt>alg</dt><dd>Algorithm for this key (RS256, ES256, RSA-OAEP, etc.).</dd>
        </dl>
      </section>
      <section anchor="key-rotation" numbered="true" toc="default">
        <name>Key Rotation</name>
        <t>
          Implementations SHOULD rotate keys annually. During rotation, the following
          procedure MUST be followed to ensure uninterrupted partner communication:
        </t>
        <ol spacing="normal">
          <li>Publish the new key alongside the old key in the JWKS.</li>
          <li>Maintain both keys for a transition period (30-60 days RECOMMENDED).</li>
          <li>Begin signing new outbound messages with the new key after partners
          have had time to cache it.</li>
          <li>Remove the old key from the JWKS after the transition period.</li>
        </ol>
        <t>
          The <tt>kid</tt> value SHOULD encode the purpose and date to aid key management,
          e.g., "org-sign-rsa-2026-01".
        </t>
      </section>
    </section>

    <!-- SECTION 6: PARTNER DISCOVERY -->
    <section anchor="discovery" numbered="true" toc="default">
      <name>Partner Discovery</name>
      <section anchor="discovery-overview" numbered="true" toc="default">
        <name>Discovery Overview</name>
        <t>
          Partner discovery enables automated trading partner onboarding without manual
          certificate exchange. The process consists of four phases:
        </t>
        <ol spacing="normal">
          <li>Configuration discovery</li>
          <li>Key retrieval</li>
          <li>Signed registration</li>
          <li>Mutual confirmation</li>
        </ol>
        <t>
          The AS5 configuration URL MAY be distributed via QR code, email, or a trading
          partner portal. The protocol is designed so that scanning a QR code initiates
          fully automated mutual trust establishment.
        </t>
      </section>
      <section anchor="as5-config" numbered="true" toc="default">
        <name>AS5 Configuration Endpoint</name>
        <t>
          Nodes MUST expose an AS5 configuration document at an HTTPS URL. This URL:
        </t>
        <ul spacing="normal">
          <li>MAY be at any path (no required well-known location).</li>
          <li>MAY include a single-use security token as a query parameter.</li>
          <li>SHOULD be shareable via QR code.</li>
        </ul>
        <t>The AS5 configuration document structure:</t>
        <sourcecode name="as5-config-example" type="json"><![CDATA[
{
  "fidex_version": "1.0",
  "supported_versions": ["1.0"],
  "conformance_profile": "core",
  "node_id": "urn:gln:1234567890123",
  "organization_name": "Example Corp",
  "public_domain": "fidex.example.com",
  "supported_document_types": ["GS1_ORDER_JSON", "GS1_INVOICE_JSON"],
  "endpoints": {
    "receive_message": "https://fidex.example.com/api/v1/receive",
    "receive_receipt": "https://fidex.example.com/api/v1/receipt",
    "register": "https://fidex.example.com/api/v1/register",
    "jwks": "https://fidex.example.com/.well-known/jwks.json"
  },
  "security": {
    "signature_algorithm": "RS256",
    "encryption_algorithm": "RSA-OAEP",
    "supported_encryption_algorithms": ["RSA-OAEP", "RSA-OAEP-256"],
    "content_encryption": "A256GCM",
    "minimum_key_size": 2048
  }
}
        ]]></sourcecode>
        <t>Required fields in the AS5 configuration:</t>
        <dl newline="false" spacing="normal">
          <dt>fidex_version</dt><dd>Current active protocol version (string, REQUIRED).</dd>
          <dt>supported_versions</dt><dd>Array of all protocol versions this node supports (array, REQUIRED).</dd>
          <dt>node_id</dt><dd>URN identifier for this node (string, REQUIRED).</dd>
          <dt>organization_name</dt><dd>Human-readable organization name (string, REQUIRED).</dd>
          <dt>public_domain</dt><dd>Public-facing domain name hosting JWKS and endpoints (string, REQUIRED).</dd>
          <dt>endpoints</dt><dd>Object containing service endpoint URLs (object, REQUIRED). MUST include: receive_message, receive_receipt, register, jwks.</dd>
          <dt>security</dt><dd>Cryptographic algorithm declarations (object, REQUIRED).</dd>
          <dt>conformance_profile</dt><dd>"core", "enhanced", or "edge" (string, OPTIONAL).</dd>
          <dt>supported_document_types</dt><dd>Array of document_type identifiers this node processes (array, OPTIONAL).</dd>
          <dt>events</dt><dd>Event capability declaration (object, OPTIONAL). See <xref target="event-discovery"/>.</dd>
        </dl>
        <section anchor="encryption-negotiation" numbered="true" toc="default">
          <name>Encryption Algorithm Negotiation</name>
          <t>
            The REQUIRED <tt>security.encryption_algorithm</tt> string identifies
            an algorithm the node accepts from legacy peers. The OPTIONAL
            <tt>security.supported_encryption_algorithms</tt> array declares all
            accepted JWE key-management algorithms. When present, the array MUST
            be non-empty, contain unique algorithm names, and include the value
            of <tt>encryption_algorithm</tt>. Nodes MUST NOT advertise algorithms
            they cannot accept. Version 1.0 nodes MUST continue to support RSA-OAEP.
          </t>
          <t>Before encrypting a message, the sender MUST:</t>
          <ol spacing="normal">
            <li>Obtain the receiver's capabilities from its HTTPS AS5 configuration
            associated with the established partner record. If the array is absent,
            use the single <tt>encryption_algorithm</tt> value as a one-element list.
            A missing or malformed required declaration is a configuration error,
            not permission to assume an algorithm.</li>
            <li>Intersect that list with the sender's implemented and locally
            permitted algorithms and the algorithms compatible with the receiver's
            encryption key. If a JWK declares <tt>alg</tt>, the selected algorithm
            MUST match that declaration.</li>
            <li>Select RSA-OAEP-256 when it is in the intersection; otherwise select
            RSA-OAEP when it is in the intersection. If neither is available,
            do not transmit and report a local incompatibility error.</li>
            <li>Set the JWE Protected Header <tt>alg</tt> to the selected algorithm.
            Receivers MUST enforce their own algorithm allowlist when decrypting.</li>
          </ol>
          <t>
            Senders MUST NOT retry with a different algorithm solely because
            decryption or delivery failed. Cached capabilities MUST remain associated
            with the partner record. If they are unavailable after a restart,
            refresh discovery before sending instead of treating that loss as a
            legacy advertisement. Local policy MAY prohibit an algorithm; a node
            that disables RSA-OAEP cannot claim the version 1.0 Core baseline.
          </t>
        </section>
        <section anchor="version-negotiation" numbered="true" toc="default">
          <name>Version Negotiation</name>
          <t>
            When two nodes with different supported versions communicate, the sender MUST:
          </t>
          <ol spacing="normal">
            <li>Retrieve the receiver's <tt>supported_versions</tt> from their AS5 configuration.</li>
            <li>Select the highest version present in BOTH <tt>supported_versions</tt> arrays.</li>
            <li>Set <tt>fidex_version</tt> in the routing header to the negotiated version.</li>
          </ol>
          <t>
            The receiver MUST reject messages with a <tt>fidex_version</tt> not present in its
            <tt>supported_versions</tt>.
          </t>
          <t>
            If no common version exists, the sender MUST NOT transmit and SHOULD report
            an incompatibility error to the local system.
          </t>
        </section>
      </section>
      <section anchor="discovery-handshake" numbered="true" toc="default">
        <name>Discovery Handshake</name>
        <t>
          The four-phase discovery handshake proceeds as follows:
        </t>
        <t><strong>Phase 1  -- Initiator Discovers Responder:</strong></t>
        <ol spacing="normal">
          <li>Initiator obtains the responder's AS5 configuration URL.</li>
          <li>Initiator fetches the responder's AS5 configuration document.</li>
          <li>Initiator fetches the responder's JWKS from the well-known endpoint.</li>
        </ol>
        <t><strong>Phase 2  -- Initiator Registers:</strong></t>
        <t>The initiator constructs and submits a signed registration payload:</t>
        <sourcecode name="registration-payload" type="json"><![CDATA[
{
  "fidex_version": "1.0",
  "initiator_node_id": "urn:gln:...",
  "initiator_as5_config_url": "https://...",
  "security_token": "...",
  "timestamp": "2026-03-09T19:00:00.000Z"
}
        ]]></sourcecode>
        <ol spacing="normal">
          <li>Initiator constructs the registration payload as shown above.</li>
          <li>Initiator signs the payload with its private key (JWS compact serialization).</li>
          <li>Initiator POSTs the JWS to the responder's <tt>register</tt> endpoint with
          <tt>Content-Type: application/jose</tt>.</li>
        </ol>
        <t><strong>Phase 3  -- Responder Validates:</strong></t>
        <ol spacing="normal">
          <li>Responder validates the security token (if configured).</li>
          <li>Responder fetches the initiator's AS5 configuration from the URL in the request.</li>
          <li>Responder fetches the initiator's JWKS and verifies the JWS signature.</li>
          <li>Responder stores the initiator's details and returns HTTP 200.</li>
        </ol>
        <t><strong>Phase 4  -- Completion:</strong></t>
        <ol spacing="normal">
          <li>Initiator receives HTTP 200 confirmation.</li>
          <li>Initiator stores the responder's details.</li>
          <li>Both parties MAY immediately exchange FideX messages.</li>
        </ol>
      </section>
      <section anchor="registration-security" numbered="true" toc="default">
        <name>Registration Security Requirements</name>
        <t>Registration requests MUST:</t>
        <ul spacing="normal">
          <li>Be signed with the initiator's private key (RS256 minimum).</li>
          <li>Be transmitted with <tt>Content-Type: application/jose</tt>.</li>
          <li>Include a timestamp within +/-15 minutes of current time.</li>
          <li>Include the security token if the responder has configured one.</li>
        </ul>
        <t>
          Security tokens MUST contain at least 128 bits of entropy, generated using a
          cryptographically secure pseudo-random number generator (CSPRNG).
          For example, encode 16 CSPRNG-generated octets as 32 hexadecimal characters
          or 22 unpadded base64url characters. A UUID v4 has only 122 random bits
          and does not meet this security-token requirement.
        </t>
        <t>Responders MUST:</t>
        <ul spacing="normal">
          <li>Validate the JWS signature before trusting any payload content.</li>
          <li>Reject registrations with timestamps outside +/-15 minutes.</li>
          <li>Reject invalid or previously used security tokens.</li>
        </ul>
      </section>
      <section anchor="partner-deregistration" numbered="true" toc="default">
        <name>Partner De-Registration</name>
        <t>
          De-registration is a local, unilateral operation. There is no protocol-level
          de-registration handshake.
        </t>
        <t>Partner states:</t>
        <table align="center">
          <name>Partner States</name>
          <thead>
            <tr><th>State</th><th>Description</th></tr>
          </thead>
          <tbody>
            <tr><td>ACTIVE</td><td>Normal operation  -- messages accepted</td></tr>
            <tr><td>SUSPENDED</td><td>Temporarily paused  -- messages rejected with HTTP 503</td></tr>
            <tr><td>INACTIVE</td><td>De-registered  -- messages rejected with HTTP 401</td></tr>
          </tbody>
        </table>
        <t>De-registration procedure:</t>
        <ol spacing="normal">
          <li>The initiating party sets partner status to INACTIVE locally.</li>
          <li>The initiating party SHOULD notify the partner via out-of-band channel.</li>
          <li>The initiating party MUST continue accepting J-MDNs for in-flight messages.</li>
          <li>After a 24-hour grace period, new inbound messages MUST be rejected with HTTP 401.</li>
          <li>Partner records SHOULD be retained for audit purposes (7 years RECOMMENDED).</li>
        </ol>
      </section>
    </section>

    <!-- SECTION 7: MESSAGE STATES AND RECEIPTS -->
    <section anchor="message-states" numbered="true" toc="default">
      <name>Message States and Receipts</name>
      <section anchor="states" numbered="true" toc="default">
        <name>Message State Machine</name>
        <t>Messages transition through the following states:</t>
        <table align="center">
          <name>Message States</name>
          <thead>
            <tr><th>State</th><th>Description</th></tr>
          </thead>
          <tbody>
            <tr><td>QUEUED</td><td>Created locally, awaiting transmission</td></tr>
            <tr><td>SENT</td><td>Transmitted to receiver, awaiting J-MDN receipt</td></tr>
            <tr><td>DELIVERED</td><td>Positive J-MDN received, verified, and matched to the original message</td></tr>
            <tr><td>FAILED</td><td>Permanent failure or maximum retries exceeded</td></tr>
          </tbody>
        </table>
        <t>
          These are protocol state semantics. Implementations MAY use different
          internal database or API labels, such as ACKNOWLEDGED for DELIVERED,
          provided they preserve these semantics. The <tt>status</tt> field in a
          transmitted J-MDN MUST still use DELIVERED or FAILED. A verified FAILED
          receipt MUST NOT transition the original message to DELIVERED.
          Conformance assessment MUST check receipt verification and correlation,
          not require a particular internal storage label.
        </t>
      </section>
      <section anchor="sync-response" numbered="true" toc="default">
        <name>Synchronous HTTP Response</name>
        <t>
          Upon receiving a message, nodes MUST perform structural validation and return:
        </t>
        <ul spacing="normal">
          <li><strong>HTTP 202 Accepted:</strong> Message is structurally valid and queued for processing.</li>
          <li><strong>HTTP 4xx/5xx:</strong> Immediate rejection (see <xref target="error-handling"/>).</li>
        </ul>
        <t>
          HTTP 202 indicates structural acceptance only. It does NOT indicate successful
          decryption, business document processing, or J-MDN generation.
        </t>
        <t>
          <strong>Idempotency:</strong> Receivers MUST handle duplicate <tt>message_id</tt>
          values idempotently. If a receiver encounters a <tt>message_id</tt> it has already
          accepted, it MUST return HTTP 202 again and MUST NOT process the message a second
          time. This ensures safe sender retries when HTTP responses are lost.
        </t>
      </section>
      <section anchor="jmdn" numbered="true" toc="default">
        <name>Asynchronous Receipt: J-MDN</name>
        <t>
          The J-MDN (JSON Message Disposition Notification) is the legally most significant
          artifact in the FideX protocol. It provides cryptographic proof that a specific
          message was received, decrypted, and accepted or rejected by the trading partner.
        </t>
        <t>
          After processing a message, the receiver MUST send a J-MDN to the sender.
          The delivery target is determined as follows:
        </t>
        <ol spacing="normal">
          <li>If <tt>receipt_webhook</tt> is present in the routing header, deliver to that URL.</li>
          <li>Otherwise, deliver to the sender's <tt>receive_receipt</tt> endpoint from the sender's AS5 configuration.</li>
          <li>If neither is available, the J-MDN MUST be stored and the failure logged; J-MDNs MUST NOT be discarded.</li>
        </ol>
        <section anchor="jmdn-schema" numbered="true" toc="default">
          <name>J-MDN Payload Schema</name>
          <t>The J-MDN JSON object contains the following fields:</t>
          <dl newline="false" spacing="normal">
            <dt>original_message_id</dt>
            <dd>(string, REQUIRED) The <tt>message_id</tt> from the original message's routing_header.</dd>
            <dt>status</dt>
            <dd>(string, REQUIRED) Either "DELIVERED" or "FAILED".</dd>
            <dt>receiver_id</dt>
            <dd>(string, REQUIRED) URN of the receiver generating this J-MDN. MUST match the <tt>receiver_id</tt> in the original routing_header.</dd>
            <dt>hash_verification</dt>
            <dd>(string, REQUIRED) SHA-256 hash of the raw business payload bytes before JWS signing. Format: "sha256:{64 hex characters}". See <xref target="hash-verification"/>.</dd>
            <dt>timestamp</dt>
            <dd>(string, REQUIRED) ISO 8601 UTC timestamp when the J-MDN was created. Format: YYYY-MM-DDTHH:mm:ss.SSSZ.</dd>
            <dt>error_log</dt>
            <dd>(object|null, REQUIRED) MUST be null when status is "DELIVERED". MUST be an error object when status is "FAILED".</dd>
            <dt>signature</dt>
            <dd>(string, REQUIRED) JWS compact serialization covering all other J-MDN fields. See <xref target="jmdn-signature"/>.</dd>
          </dl>
          <t>Positive J-MDN example (DELIVERED):</t>
          <sourcecode name="jmdn-positive" type="json"><![CDATA[
{
  "original_message_id": "fdx-a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "DELIVERED",
  "receiver_id": "urn:gln:9876543210987",
  "hash_verification": "sha256:9f86d08...b0f00a08",
  "timestamp": "2026-03-09T19:30:02.000Z",
  "error_log": null,
  "signature": "eyJhbGciOiJSUzI1NiIs..."
}
          ]]></sourcecode>
          <t>Negative J-MDN example (FAILED):</t>
          <sourcecode name="jmdn-negative" type="json"><![CDATA[
{
  "original_message_id": "fdx-a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "FAILED",
  "receiver_id": "urn:gln:9876543210987",
  "hash_verification": "sha256:0000...0000",
  "timestamp": "2026-03-09T19:30:02.000Z",
  "error_log": {
    "error_code": "DECRYPTION_FAILED",
    "error_message": "Unable to decrypt payload",
    "details": "Key ID mismatch"
  },
  "signature": "eyJhbGciOiJSUzI1NiIs..."
}
          ]]></sourcecode>
        </section>
        <section anchor="hash-verification" numbered="true" toc="default">
          <name>Hash Verification</name>
          <t>
            The <tt>hash_verification</tt> field proves that the receiver decrypted exactly
            the payload the sender signed.
          </t>
          <t>Definition:</t>
          <sourcecode name="hash-definition" type="text"><![CDATA[
hash_verification =
    "sha256:" || hex( SHA-256( raw_business_payload_bytes ) )
          ]]></sourcecode>
          <t>
            Where <tt>raw_business_payload_bytes</tt> is the UTF-8 encoded bytes of the
            business JSON payload BEFORE JWS signing (i.e., the exact cleartext that was
            the input to the JWS sign operation).
          </t>
          <t>
            When <tt>status</tt> is "FAILED" and the receiver could NOT decrypt the
            payload, <tt>hash_verification</tt> MUST be set to a string of 64 zero
            hex digits: "sha256:" followed by 64 ASCII "0" characters.
          </t>
        </section>
        <section anchor="jmdn-signature" numbered="true" toc="default">
          <name>J-MDN Signature Requirements</name>
          <t>
            The <tt>signature</tt> field MUST contain a JWS compact serialization covering
            all other J-MDN fields (i.e., all fields except <tt>signature</tt> itself).
          </t>
          <t>JWS Protected Header for J-MDN signing:</t>
          <sourcecode name="jmdn-jws-header" type="json"><![CDATA[
{
  "alg": "RS256",
  "kid": "{receiver-signing-key-id}"
}
          ]]></sourcecode>
          <t>Signing procedure:</t>
          <ol spacing="normal">
            <li>Construct a JSON object with all J-MDN fields EXCEPT <tt>signature</tt>.</li>
            <li>Serialize to canonical JSON: no extra whitespace; keys in alphabetical order
            (error_log, hash_verification, original_message_id, receiver_id, status, timestamp).</li>
            <li>Sign using RS256 with the receiver's private signing key.</li>
            <li>Set <tt>signature</tt> to the resulting JWS compact serialization.</li>
          </ol>
          <t>Verification procedure (sender side):</t>
          <ol spacing="normal">
            <li>Extract <tt>signature</tt> from the received J-MDN.</li>
            <li>Parse JWS; extract <tt>kid</tt> from the JWS header.</li>
            <li>Look up the receiver's public key from their JWKS using <tt>kid</tt>.</li>
            <li>Verify the JWS signature.</li>
            <li>Compare the JWS payload with the remaining J-MDN fields for consistency.</li>
          </ol>
        </section>
        <section anchor="jmdn-error-codes" numbered="true" toc="default">
          <name>J-MDN Error Codes</name>
          <t>
            When <tt>status</tt> is "FAILED", the <tt>error_log</tt> object MUST contain:
          </t>
          <dl newline="false" spacing="normal">
            <dt>error_code</dt><dd>(string, REQUIRED) Machine-readable code from the table below.</dd>
            <dt>error_message</dt><dd>(string, REQUIRED) Human-readable description.</dd>
            <dt>details</dt><dd>(string, OPTIONAL) Additional diagnostic info. MUST NOT contain sensitive data.</dd>
          </dl>
          <table align="center">
            <name>Standard J-MDN Error Codes</name>
            <thead>
              <tr><th>Code</th><th>Description</th></tr>
            </thead>
            <tbody>
              <tr><td>DECRYPTION_FAILED</td><td>Cannot decrypt JWE (wrong key or corrupted ciphertext)</td></tr>
              <tr><td>SIGNATURE_INVALID</td><td>JWS signature verification failed</td></tr>
              <tr><td>UNKNOWN_DOCUMENT_TYPE</td><td>The document_type is not supported by the receiver</td></tr>
              <tr><td>PAYLOAD_TOO_LARGE</td><td>Message exceeds receiver's processing limits</td></tr>
              <tr><td>INTERNAL_ERROR</td><td>Receiver encountered an internal processing error</td></tr>
              <tr><td>INVALID_EVENT</td><td>The payload of an Event Message is not a valid CloudEvent or violates <xref target="event-attributes"/></td></tr>
              <tr><td>UNKNOWN_EVENT_TYPE</td><td>The event <tt>type</tt> is not accepted by the receiver from this partner</td></tr>
            </tbody>
          </table>
        </section>
        <section anchor="jmdn-delivery" numbered="true" toc="default">
          <name>J-MDN Delivery Protocol</name>
          <t>The J-MDN is delivered via HTTP POST:</t>
          <sourcecode name="jmdn-http-request" type="http"><![CDATA[
POST {receipt_webhook} HTTP/1.1
Host: {sender_host}
Content-Type: application/json
X-FideX-Original-Message-ID: {original_message_id}

{J-MDN JSON body}
          ]]></sourcecode>
          <t>Expected response:</t>
          <sourcecode name="jmdn-http-response" type="json"><![CDATA[
{
  "receipt_acknowledged": true
}
          ]]></sourcecode>
          <t>Timing requirements:</t>
          <ul spacing="normal">
            <li>Receivers SHOULD send J-MDN within 5 minutes of receiving the original message.</li>
            <li>If processing takes longer, the J-MDN MUST still be sent when processing completes.</li>
            <li>There is no strict upper time limit; delivery is asynchronous by design.</li>
          </ul>
        </section>
        <section anchor="jmdn-retry" numbered="true" toc="default">
          <name>J-MDN Delivery Retry Schedule</name>
          <t>
            If the J-MDN delivery endpoint is unreachable, the receiver SHOULD retry
            according to the following schedule:
          </t>
          <ul spacing="normal">
            <li>Attempt 1: Immediate</li>
            <li>Attempt 2: +1 minute</li>
            <li>Attempt 3: +5 minutes</li>
            <li>Attempt 4: +15 minutes</li>
            <li>Attempt 5: +1 hour</li>
          </ul>
          <t>
            After 5 failed attempts, the receiver SHOULD log the failure and store the
            J-MDN for manual retrieval. The J-MDN MUST NOT be discarded.
          </t>
        </section>
      </section>
      <section anchor="sender-retry" numbered="true" toc="default">
        <name>Sender Retry Semantics</name>
        <t>
          Senders SHOULD retry failed transmissions with exponential backoff:
        </t>
        <ul spacing="normal">
          <li>Attempt 1: Immediate</li>
          <li>Attempt 2: +1 minute</li>
          <li>Attempt 3: +5 minutes</li>
          <li>Attempt 4: +15 minutes</li>
          <li>Attempt 5: +30 minutes</li>
          <li>Attempt 6: +1 hour</li>
        </ul>
        <t>
          After 5-6 failed attempts, the message SHOULD transition to FAILED state
          requiring manual operator intervention.
        </t>
      </section>
      <section anchor="non-fidex-evidence" numbered="true" toc="default">
        <name>Evidence Delivery to Non-FideX Participants</name>
        <t>
          A business participant need not operate a FideX node to obtain evidence
          about its transactions. For example, a pharmaceutical distributor without
          FideX support can receive transaction evidence through email, a management
          portal, or an HTTPS webhook. A FideX node or application gateway MAY provide
          this capability. When it serves a non-FideX participant, it MUST provide
          at least one evidence delivery or retrieval channel agreed with that
          participant. Support for all three channels is not required.
        </t>
        <t>
          This capability distributes evidence already held by the node and records
          additional channel events. It does not change the J-MDN wire format or
          require the non-FideX participant to implement JOSE. Business document
          delivery over a non-FideX channel is a separate application function;
          delivering evidence alone does not establish delivery of that document.
        </t>
        <section anchor="external-evidence-record" numbered="true" toc="default">
          <name>Evidence Content and Attribution</name>
          <t>
            Evidence made available through these channels MUST identify the original
            transaction or FideX message, the business parties, the evidence issuer,
            the observed event and its timestamp, and the relevant document digest
            when available. Each digest MUST identify its algorithm and the bytes
            it covers, such as the business payload or encrypted envelope. If no
            digest is available, that limitation MUST be explicit.
          </t>
          <t>
            When the evidence includes a J-MDN, the service MUST retain the original
            signed artifact and make it retrievable by the authorized participant.
            A human-readable rendering MUST identify the signer, verification result,
            and whether the asserted event concerns the FideX node, an intermediary,
            or the ultimate business recipient. Channel event records MUST identify
            their source and be correlated with the original evidence. A gateway's
            own observation MUST NOT be represented as a statement signed by the
            non-FideX participant.
          </t>
        </section>
        <section anchor="external-evidence-channels" numbered="true" toc="default">
          <name>Delivery Channels</name>
          <ul spacing="normal">
            <li><strong>Email:</strong> The service MAY send an evidence summary,
            an authorized attachment, or a link to retrieve the evidence. Acceptance
            by an email service MUST be recorded as a channel event, not as proof
            that the business recipient read or accepted the document.</li>
            <li><strong>Management portal:</strong> The service MAY expose a
            transaction history, evidence downloads, and explicit acknowledgment
            actions. It MUST distinguish evidence availability, authenticated access,
            and an explicit acknowledgment, recording the actor and timestamp for
            the latter two events.</li>
            <li><strong>HTTPS webhook:</strong> The service MAY notify an endpoint
            authorized by the participant. Notifications MUST be authenticated under
            the agreed channel mechanism and carry a stable event identifier and
            transaction correlation identifier. Retries MUST retain the event
            identifier so consumers can process them idempotently. An HTTP success
            response establishes endpoint acceptance only, unless an explicit
            application acknowledgment is separately defined and verified.
            Notifications that report the life cycle of a FideX message SHOULD
            be expressed as the Protocol Events of <xref target="protocol-events"/>,
            in which case the CloudEvents <tt>source</tt> and <tt>id</tt>
            attributes together form the stable event identifier and the
            <tt>subject</tt> attribute carries the transaction correlation
            identifier.</li>
          </ul>
          <t>
            Destinations and access rights MUST be established through authorized
            participant configuration, not accepted solely from an inbound message's
            routing header. The service MUST restrict evidence access to authorized
            parties and protect confidential content in transit. Retrieval links
            MUST use HTTPS and enforce authorization; possession of a transaction
            identifier alone MUST NOT grant access. Delivery failures MUST be
            recorded, and the evidence MUST remain available for authorized retrieval
            under the agreed retention policy. Retrying a notification MUST NOT
            reprocess the original business document.
          </t>
        </section>
        <section anchor="external-evidence-semantics" numbered="true" toc="default">
          <name>Relationship to FideX Receipts</name>
          <t>
            Notification delivery, portal access, and application acknowledgment
            MUST be recorded separately from the FideX message state. These events
            MUST NOT by themselves transition a FideX message to DELIVERED; that
            transition requires the verified positive J-MDN described in
            <xref target="states"/>. If an intermediary is the FideX receiver,
            its J-MDN establishes the intermediary's disposition, not an acknowledgment
            by the ultimate non-FideX recipient. Any downstream acknowledgment MUST
            identify its actor, authentication method, scope, and original transaction.
          </t>
          <t>
            Email templates, portal interfaces, and downstream business acceptance
            workflows are outside this specification. Webhook payloads are outside
            this specification except for the Protocol Events defined in
            <xref target="protocol-events"/>. All of them MUST preserve the
            evidence attribution and event distinctions above.
          </t>
        </section>
      </section>
    </section>

    <!-- SECTION 8: ERROR HANDLING -->
    <section anchor="error-handling" numbered="true" toc="default">
      <name>Error Handling</name>
      <section anchor="http-status-codes" numbered="true" toc="default">
        <name>HTTP Status Codes</name>
        <table align="center">
          <name>HTTP Status Code Semantics</name>
          <thead>
            <tr><th>Code</th><th>Meaning</th><th>Sender Action</th></tr>
          </thead>
          <tbody>
            <tr><td>202</td><td>Accepted for processing</td><td>Wait for J-MDN</td></tr>
            <tr><td>400</td><td>Invalid message structure</td><td>Do not retry (permanent error)</td></tr>
            <tr><td>401</td><td>Authentication failed or partner INACTIVE</td><td>Do not retry (permanent error)</td></tr>
            <tr><td>413</td><td>Payload too large</td><td>Do not retry (permanent error)</td></tr>
            <tr><td>429</td><td>Rate limit exceeded</td><td>Retry with backoff; honor Retry-After header</td></tr>
            <tr><td>500</td><td>Server internal error</td><td>Retry with backoff</td></tr>
            <tr><td>503</td><td>Service unavailable or partner SUSPENDED</td><td>Retry with backoff</td></tr>
          </tbody>
        </table>
        <t>
          Implementations SHOULD include a <tt>Retry-After</tt> header on HTTP 429 responses,
          per <xref target="RFC9110"/> Section 10.2.3.
        </t>
      </section>
      <section anchor="error-format" numbered="true" toc="default">
        <name>Error Response Format</name>
        <t>All error responses MUST use the following JSON structure:</t>
        <sourcecode name="error-response" type="json"><![CDATA[
{
  "error": {
    "code": "INVALID_ROUTING_HEADER",
    "message": "Missing required field: message_id",
    "timestamp": "2026-03-09T19:00:00.000Z"
  }
}
        ]]></sourcecode>
      </section>
      <section anchor="error-codes" numbered="true" toc="default">
        <name>Standard Error Codes</name>
        <t>Message transmission errors:</t>
        <ul spacing="normal">
          <li><tt>INVALID_ROUTING_HEADER</tt>  -- Missing or malformed routing header</li>
          <li><tt>UNKNOWN_RECEIVER</tt>  -- receiver_id not recognized in partner registry</li>
          <li><tt>UNKNOWN_DOCUMENT_TYPE</tt>  -- document_type not supported</li>
          <li><tt>PAYLOAD_TOO_LARGE</tt>  -- Message exceeds the 10 MB size limit</li>
        </ul>
        <t>Cryptographic errors:</t>
        <ul spacing="normal">
          <li><tt>DECRYPTION_FAILED</tt>  -- Cannot decrypt JWE</li>
          <li><tt>SIGNATURE_INVALID</tt>  -- JWS signature verification failed</li>
          <li><tt>UNKNOWN_KEY_ID</tt>  -- Key ID not found in JWKS</li>
        </ul>
        <t>Event errors (reported in the J-MDN <tt>error_log</tt>; see <xref target="event-receiver"/>):</t>
        <ul spacing="normal">
          <li><tt>INVALID_EVENT</tt>  -- Event Message payload is not a valid CloudEvent</li>
          <li><tt>UNKNOWN_EVENT_TYPE</tt>  -- Event type not accepted from this partner</li>
        </ul>
        <t>Discovery errors:</t>
        <ul spacing="normal">
          <li><tt>INVALID_TOKEN</tt>  -- Security token invalid or expired</li>
          <li><tt>DUPLICATE_REGISTRATION</tt>  -- Partner already registered</li>
          <li><tt>CONFIG_UNREACHABLE</tt>  -- Cannot fetch AS5 configuration</li>
        </ul>
      </section>
    </section>

    <!-- SECTION 9: EVENTS -->
    <section anchor="events" numbered="true" toc="default">
      <name>Events</name>
      <section anchor="event-model" numbered="true" toc="default">
        <name>Event Model</name>
        <t>
          The preceding sections describe the exchange of business documents.
          Trading partners also need to tell each other that something happened:
          a shipment left a warehouse, a payment was settled, a stock level
          changed, or a document reached a processing stage. Such a statement
          is an event. An event records an occurrence that has already taken
          place. Its producer does not address a request to the consumer and
          does not expect a reply.
        </t>
        <t>
          FideX does not define its own event structure. Events are CloudEvents
          as specified in <xref target="CloudEvents"/>, version 1.0, serialized
          in the JSON Event Format <xref target="CE-JSON"/>. Implementations can
          therefore use existing CloudEvents libraries, brokers, and tools on
          either side of a FideX exchange.
        </t>
        <t>This document uses events in two ways:</t>
        <ul spacing="normal">
          <li><strong>Event Messages</strong> (<xref target="event-messages"/>):
          a partner sends a CloudEvent to another partner as the payload of a
          FideX message. The event is signed, encrypted, and receipted exactly
          like a business document.</li>
          <li><strong>Protocol Events</strong> (<xref target="protocol-events"/>):
          a node reports the life cycle of FideX messages to authorized
          consumers, such as local applications or the webhook channel of
          <xref target="non-fidex-evidence"/>.</li>
        </ul>
        <t>
          Event support is OPTIONAL and is not part of any conformance profile
          (see Appendix C). It does not change the message envelope, the
          cryptographic requirements, the J-MDN structure, or the protocol
          version: a node that supports events continues to use
          <tt>fidex_version</tt> "1.0". A node that does not support events
          handles an Event Message like any other message with an unsupported
          <tt>document_type</tt>
          (<xref target="receiver-document-type-behavior"/>).
        </t>
        <t>
          This document does not define commands, that is, messages that request
          a partner to perform an action and that expect a correlated result.
          An event MUST NOT be interpreted as obliging its consumer to act. Any
          obligation to react to an event arises from agreement between the
          partners, not from this protocol.
        </t>
      </section>
      <section anchor="event-messages" numbered="true" toc="default">
        <name>Event Messages</name>
        <t>
          An Event Message is a FideX message whose routing header carries the
          <tt>document_type</tt> value <tt>CLOUDEVENTS_JSON</tt>. All requirements
          of Sections 2 through 8 apply to it without change.
        </t>
        <t>
          The JWS payload (<xref target="payload-encoding"/>) MUST be the UTF-8
          encoding of exactly one CloudEvent serialized according to the JSON
          Event Format <xref target="CE-JSON"/>, that is, the representation
          identified by the media type <tt>application/cloudevents+json</tt>.
          The JSON Batch Format MUST NOT be used: each event is carried in its
          own message so that each event has its own J-MDN.
        </t>
        <t>
          The complete CloudEvent, including its context attributes, is inside
          the encrypted payload. The cleartext routing header reveals only that
          the message carries an event. Senders SHOULD NOT copy event attributes
          into routing header extension fields.
        </t>
        <t>
          The routing header <tt>timestamp</tt> is the time of transmission and
          is subject to the validation window of
          <xref target="impl-requirements"/>. The event <tt>time</tt> attribute
          is the time of the occurrence and can be much earlier. Receivers
          MUST NOT apply the transmission window to the <tt>time</tt> attribute.
        </t>
        <section anchor="event-attributes" numbered="true" toc="default">
          <name>Event Attributes</name>
          <t>
            The CloudEvent in an Event Message MUST satisfy
            <xref target="CloudEvents"/> and the following additional
            requirements:
          </t>
          <dl newline="false" spacing="normal">
            <dt>specversion</dt>
            <dd>(REQUIRED) MUST be "1.0".</dd>
            <dt>id</dt>
            <dd>
              (REQUIRED) A non-empty string. The producer MUST ensure that
              <tt>source</tt> and <tt>id</tt> together are unique for each
              distinct event. A UUID (<xref target="RFC9562"/>) is RECOMMENDED.
              A producer that sends the same event again, for example in a new
              FideX message after a failed delivery, MUST reuse the same
              <tt>source</tt> and <tt>id</tt>.
            </dd>
            <dt>source</dt>
            <dd>
              (REQUIRED) MUST be an absolute URI (<xref target="RFC3986"/>). It
              identifies the context, within the sending organization, in which
              the occurrence happened. It SHOULD be an <tt>https</tt> URI whose
              host is the sender's <tt>public_domain</tt>, or the sender's node
              identifier URN.
            </dd>
            <dt>type</dt>
            <dd>
              (REQUIRED) SHOULD be prefixed with the reverse-DNS name of the
              organization that defines the event type and SHOULD end with a
              version suffix, for example
              <tt>com.example.shipment.departed.v1</tt>. The prefix
              <tt>org.fidex-protocol.</tt> is reserved for event types defined
              by this document.
            </dd>
            <dt>time</dt>
            <dd>
              (REQUIRED in Event Messages; OPTIONAL in CloudEvents) Timestamp of
              the occurrence in the format of <xref target="RFC3339"/>. UTC
              ("Z") is RECOMMENDED.
            </dd>
            <dt>subject</dt>
            <dd>
              (OPTIONAL) SHOULD identify the business object the event concerns,
              such as an order or despatch advice number, when one exists.
            </dd>
            <dt>datacontenttype, dataschema</dt>
            <dd>
              (OPTIONAL) As defined in <xref target="CloudEvents"/>. When
              <tt>datacontenttype</tt> is absent, the event data is JSON.
            </dd>
            <dt>data, data_base64</dt>
            <dd>
              (OPTIONAL) Event data, encoded as specified in
              <xref target="CE-JSON"/>.
            </dd>
          </dl>
          <t>
            Receivers MUST accept events that contain extension attributes they
            do not recognize.
          </t>
          <t>
            Events SHOULD be compact. It is RECOMMENDED that a serialized event
            not exceed 64 kilobytes, the size that
            <xref target="CloudEvents"/> expects intermediaries to forward.
            Larger content SHOULD be sent as a business document and referenced
            from the event. The message size limit of
            <xref target="message-size"/> applies in all cases.
          </t>
        </section>
        <section anchor="event-extensions" numbered="true" toc="default">
          <name>FideX Extension Attributes</name>
          <t>
            This document defines the following CloudEvents extension attributes.
            Their names follow the CloudEvents attribute naming convention, and
            their values are of the CloudEvents type String.
          </t>
          <table align="center">
            <name>FideX CloudEvents Extension Attributes</name>
            <thead>
              <tr><th>Attribute</th><th>Value</th><th>Use</th></tr>
            </thead>
            <tbody>
              <tr><td>fidexmsgid</td><td>The <tt>message_id</tt> of a FideX message that the event refers to</td><td>OPTIONAL in Event Messages</td></tr>
              <tr><td>fidexsender</td><td>The <tt>sender_id</tt> of the FideX message that a Protocol Event describes</td><td>Protocol Events</td></tr>
              <tr><td>fidexreceiver</td><td>The <tt>receiver_id</tt> of the FideX message that a Protocol Event describes</td><td>Protocol Events</td></tr>
              <tr><td>fidexdoctype</td><td>The <tt>document_type</tt> of the FideX message that a Protocol Event describes</td><td>Protocol Events</td></tr>
            </tbody>
          </table>
          <t>
            The <tt>fidexmsgid</tt> attribute lets a producer relate a business
            event to a document previously exchanged over FideX, for example
            relating a "shipment departed" event to the message that carried
            the despatch advice. It identifies a message other than the Event
            Message that carries the event.
          </t>
        </section>
        <section anchor="event-receiver" numbered="true" toc="default">
          <name>Receiver Processing</name>
          <t>A receiver that supports events processes an Event Message as follows:</t>
          <ol spacing="normal">
            <li>Process the envelope as for any message: structural validation
            and synchronous response (<xref target="sync-response"/>),
            decryption, signature verification, and sender identity
            verification (<xref target="cryptography"/>).</li>
            <li>Parse the JWS payload as a CloudEvent in the JSON Event Format
            and check the requirements of <xref target="event-attributes"/>.
            On failure, send a negative J-MDN with error code
            <tt>INVALID_EVENT</tt>.</li>
            <li>Determine whether the event <tt>type</tt> is accepted from the
            authenticated sender. If it is not, send a negative J-MDN with
            error code <tt>UNKNOWN_EVENT_TYPE</tt>. A receiver MUST NOT report
            DELIVERED for an event that it discards because it does not accept
            its type.</li>
            <li>Check for a duplicate. The event identity is the combination of
            the authenticated <tt>sender_id</tt>, <tt>source</tt>, and
            <tt>id</tt>. If the receiver has already accepted an event with the
            same identity, it MUST NOT make the event available to consumers
            again and SHOULD send a positive J-MDN.</li>
            <li>Otherwise, make the event available to its consumers and send a
            positive J-MDN.</li>
          </ol>
          <t>
            Receivers MUST retain event identities for at least the replay cache
            period required by <xref target="impl-requirements"/> and SHOULD
            retain them for as long as the partners agree that an event can be
            re-sent.
          </t>
          <t>
            The <tt>hash_verification</tt> value of the J-MDN is computed as
            specified in <xref target="hash-verification"/> over the JWS payload
            octets as received, that is, over the serialized CloudEvent.
            Receivers MUST NOT re-serialize the event before computing it.
          </t>
          <t>
            Delivery is at-least-once: a consumer can observe an event more than
            once after the receiver's duplicate records expire, so consumers
            SHOULD process events idempotently. FideX does not guarantee that
            Event Messages arrive in the order in which the occurrences
            happened. A producer whose consumers need to reconstruct an order
            has to convey it in the event, for example through <tt>time</tt> or
            through a sequence value carried in the event data or in an agreed
            extension attribute.
          </t>
        </section>
        <section anchor="event-semantics" numbered="true" toc="default">
          <name>Meaning of Receipts for Events</name>
          <t>
            A positive J-MDN for an Event Message proves that the receiver
            decrypted the payload, verified the sender's signature, validated
            the payload as a CloudEvent, and accepted the event for handling.
            It does not prove that any consumer acted on the event, nor that the
            receiver agrees that the occurrence took place as stated. The signed
            event is evidence that the sender asserted the occurrence.
          </t>
          <t>
            Events complement business documents. Where agreement or regulation
            requires a specific business document, such as an invoice, an event
            that announces it does not replace that document.
          </t>
          <t>
            A partner that reacts to an event does so by sending its own
            business document or its own event. The reaction can reference the
            FideX message that carried the original event through the
            <tt>fidexmsgid</tt> attribute.
          </t>
        </section>
      </section>
      <section anchor="event-discovery" numbered="true" toc="default">
        <name>Discovery of Event Support</name>
        <t>
          A node that accepts Event Messages MUST list <tt>CLOUDEVENTS_JSON</tt>
          in the <tt>supported_document_types</tt> array of its AS5
          configuration (<xref target="as5-config"/>). It MAY also publish an
          <tt>events</tt> object:
        </t>
        <sourcecode name="as5-config-events" type="json"><![CDATA[
{
  "supported_document_types": [
    "GS1_ORDER_JSON", "CLOUDEVENTS_JSON"
  ],
  "events": {
    "accepted_types": [
      "com.example.shipment.departed.v1",
      "com.example.payment.settled.v1"
    ],
    "published_types": [
      "com.example.stock.level-changed.v1"
    ]
  }
}
        ]]></sourcecode>
        <dl newline="false" spacing="normal">
          <dt>accepted_types</dt>
          <dd>
            (array of strings, OPTIONAL) The CloudEvents <tt>type</tt> values
            that the node accepts in Event Messages. When absent, the accepted
            types are established by agreement between the partners.
          </dd>
          <dt>published_types</dt>
          <dd>
            (array of strings, OPTIONAL) The CloudEvents <tt>type</tt> values
            that the node is able to send. This member is informational:
            listing a type does not oblige the node to send those events to
            any particular partner.
          </dd>
        </dl>
        <t>
          A sender SHOULD NOT transmit an Event Message to a partner whose AS5
          configuration does not list <tt>CLOUDEVENTS_JSON</tt>, unless the
          partners have agreed otherwise. When the receiver's configuration
          contains <tt>events.accepted_types</tt>, the sender SHOULD NOT
          transmit an event whose <tt>type</tt> is not listed. A receiver MAY
          accept from a given partner a narrower set of types than it
          advertises.
        </t>
        <t>
          Which events a node sends to which partner is established by
          agreement between the partners. This document does not define a
          subscription interface.
        </t>
      </section>
      <section anchor="protocol-events" numbered="true" toc="default">
        <name>Protocol Events</name>
        <t>
          A node MAY emit Protocol Events to report the life cycle of the FideX
          messages it sends or receives. Protocol Events let applications and
          authorized external consumers follow a transaction without polling
          the node and without implementing JOSE.
        </t>
        <section anchor="protocol-event-types" numbered="true" toc="default">
          <name>Event Types</name>
          <t>The following Protocol Event types are defined:</t>
          <dl newline="true" spacing="normal">
            <dt>org.fidex-protocol.message.sent.v1</dt>
            <dd>Emitted by the sender. The receiver accepted the transmission with HTTP 202; the message is in state SENT.</dd>
            <dt>org.fidex-protocol.message.delivered.v1</dt>
            <dd>Emitted by the sender. A positive J-MDN was received, verified, and matched; the message is in state DELIVERED.</dd>
            <dt>org.fidex-protocol.message.failed.v1</dt>
            <dd>Emitted by the sender. The message reached state FAILED: a negative J-MDN was verified, a permanent error was returned, or retries were exhausted.</dd>
            <dt>org.fidex-protocol.message.received.v1</dt>
            <dd>Emitted by the receiver. An inbound message was decrypted, its signature was verified, and it was accepted for processing.</dd>
            <dt>org.fidex-protocol.message.rejected.v1</dt>
            <dd>Emitted by the receiver. An inbound message failed processing and a negative J-MDN was generated.</dd>
            <dt>org.fidex-protocol.receipt.undeliverable.v1</dt>
            <dd>Emitted by the receiver. Delivery of a J-MDN failed after the retry schedule of <xref target="jmdn-retry"/>; the J-MDN is stored.</dd>
          </dl>
          <t>
            An incompatible change to the data of a Protocol Event type will be
            published under a new version suffix. Implementations MUST NOT
            define their own event types under the <tt>org.fidex-protocol.</tt>
            prefix.
          </t>
        </section>
        <section anchor="protocol-event-attributes" numbered="true" toc="default">
          <name>Attributes and Data</name>
          <t>A Protocol Event is a CloudEvent with the following attributes:</t>
          <dl newline="false" spacing="normal">
            <dt>specversion</dt>
            <dd>(REQUIRED) MUST be "1.0".</dd>
            <dt>id</dt>
            <dd>
              (REQUIRED) Unique, together with <tt>source</tt>, for each
              distinct occurrence. Redeliveries of the same Protocol Event
              MUST keep the same <tt>id</tt>.
            </dd>
            <dt>source</dt>
            <dd>
              (REQUIRED) An absolute URI that identifies the emitting node. It
              SHOULD be <tt>https://{public_domain}</tt> of that node.
            </dd>
            <dt>type</dt>
            <dd>(REQUIRED) One of the types defined in <xref target="protocol-event-types"/>.</dd>
            <dt>time</dt>
            <dd>
              (REQUIRED) The time of the occurrence, for example of the state
              transition, in the format of <xref target="RFC3339"/>.
            </dd>
            <dt>subject</dt>
            <dd>(REQUIRED) The <tt>message_id</tt> of the FideX message.</dd>
            <dt>fidexsender, fidexreceiver, fidexdoctype</dt>
            <dd>
              (REQUIRED) The <tt>sender_id</tt>, <tt>receiver_id</tt>, and
              <tt>document_type</tt> from the routing header of the FideX
              message (<xref target="event-extensions"/>).
            </dd>
            <dt>datacontenttype</dt>
            <dd>(OPTIONAL) When present, MUST be "application/json".</dd>
          </dl>
          <t>The event data is a JSON object with the following members:</t>
          <dl newline="false" spacing="normal">
            <dt>message_state</dt>
            <dd>
              (string, OPTIONAL) The protocol state of the message
              (<xref target="states"/>) after the occurrence, in events emitted
              by the sender.
            </dd>
            <dt>hash_verification</dt>
            <dd>
              (string, OPTIONAL) The digest defined in
              <xref target="hash-verification"/>, when known to the emitter.
            </dd>
            <dt>jmdn</dt>
            <dd>
              (object, OPTIONAL) The complete J-MDN that was verified (events
              emitted by the sender) or generated (events emitted by the
              receiver), unmodified and including its <tt>signature</tt>
              member. It lets a consumer retain and verify the original signed
              evidence (<xref target="external-evidence-record"/>).
            </dd>
            <dt>error</dt>
            <dd>
              (object) REQUIRED in <tt>message.failed</tt>,
              <tt>message.rejected</tt>, and <tt>receipt.undeliverable</tt>
              events; MUST NOT be present otherwise. It contains
              <tt>error_code</tt> (string, REQUIRED) and
              <tt>error_message</tt> (string, REQUIRED). The
              <tt>error_code</tt> is a code from
              <xref target="jmdn-error-codes"/> or <xref target="error-codes"/>
              when one applies, and an implementation-defined code otherwise.
            </dd>
          </dl>
          <t>
            The event data MUST NOT contain the business document, any part of
            its content, or key material. Consumers MUST ignore members they do
            not recognize.
          </t>
          <t>Example:</t>
          <sourcecode name="protocol-event-example" type="json"><![CDATA[
{
  "specversion": "1.0",
  "id": "c2f6a4de-0b7e-4d41-8a55-3f1f0d9a6e02",
  "source": "https://fidex.example.com",
  "type": "org.fidex-protocol.message.delivered.v1",
  "time": "2026-03-09T19:30:03.250Z",
  "subject": "fdx-a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "datacontenttype": "application/json",
  "fidexsender": "urn:gln:1234567890123",
  "fidexreceiver": "urn:gln:9876543210987",
  "fidexdoctype": "GS1_ORDER_JSON",
  "data": {
    "message_state": "DELIVERED",
    "hash_verification": "sha256:9f86d08...b0f00a08",
    "jmdn": {
      "original_message_id":
        "fdx-a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "status": "DELIVERED",
      "receiver_id": "urn:gln:9876543210987",
      "hash_verification": "sha256:9f86d08...b0f00a08",
      "timestamp": "2026-03-09T19:30:02.000Z",
      "error_log": null,
      "signature": "eyJhbGciOiJSUzI1NiIs..."
    }
  }
}
          ]]></sourcecode>
        </section>
        <section anchor="protocol-event-delivery" numbered="true" toc="default">
          <name>Delivery of Protocol Events</name>
          <t>
            Delivery to the node's own applications is an implementation matter.
          </t>
          <t>
            When a Protocol Event is delivered to an HTTPS endpoint, including
            the webhook channel of <xref target="external-evidence-channels"/>,
            the node SHOULD use the HTTP Protocol Binding for CloudEvents
            <xref target="CE-HTTP"/> in structured content mode: an HTTP POST
            request whose <tt>Content-Type</tt> is
            <tt>application/cloudevents+json</tt> and whose body is the event.
            The destination, authentication, and authorization requirements of
            <xref target="external-evidence-channels"/> apply. A successful
            HTTP response establishes endpoint acceptance only. Nodes MAY
            additionally implement the delivery and abuse-protection
            conventions of <xref target="CE-WEBHOOK"/>.
          </t>
          <t>
            By agreement, a node MAY send Protocol Events to a partner as Event
            Messages (<xref target="event-messages"/>). In that case:
          </t>
          <ul spacing="normal">
            <li>A Protocol Event is not a receipt. Its recipient MUST NOT change
            the state of a FideX message because of it; only a verified J-MDN
            does so (<xref target="states"/>).</li>
            <li>The receiver MUST verify that the authenticated sender of the
            Event Message is the party identified by <tt>fidexsender</tt> or by
            <tt>fidexreceiver</tt>. Otherwise it MUST send a negative J-MDN
            with error code <tt>INVALID_EVENT</tt>.</li>
            <li>To prevent notification loops, a node MUST NOT send a partner
            Protocol Events about Event Messages whose payload is itself a
            Protocol Event.</li>
          </ul>
        </section>
      </section>
    </section>

    <!-- SECTION 10: SECURITY CONSIDERATIONS -->
    <section anchor="security" numbered="true" toc="default">
      <name>Security Considerations</name>
      <section anchor="threat-model" numbered="true" toc="default">
        <name>Threat Model</name>
        <t>FideX addresses the following threats:</t>
        <dl newline="false" spacing="normal">
          <dt>Man-in-the-Middle (MitM)</dt>
          <dd>Mitigated by TLS 1.3 transport encryption combined with JWE application-layer encryption. An attacker who intercepts the TLS session cannot read the encrypted payload.</dd>
          <dt>Message Tampering</dt>
          <dd>Mitigated by JWS digital signatures. Any modification to the signed payload invalidates the signature, detected during verification.</dd>
          <dt>Replay Attacks</dt>
          <dd>Mitigated by unique message IDs combined with timestamp validation. Receivers MUST maintain a replay cache and reject duplicate message_id values.</dd>
          <dt>Repudiation</dt>
          <dd>Mitigated by cryptographic signatures on both messages (JWS) and receipts (J-MDN signature), creating a legally auditable chain of custody.</dd>
          <dt>Key Compromise</dt>
          <dd>Mitigated by key rotation procedures and JWKS-based distribution. Compromised keys can be revoked by removing them from the JWKS.</dd>
          <dt>Cross-Partner Key Substitution</dt>
          <dd>Mitigated by sender identity verification (Section 4.4): the receiver verifies the signing key belongs to the claimed sender_id.</dd>
        </dl>
      </section>
      <section anchor="impl-requirements" numbered="true" toc="default">
        <name>Implementation Security Requirements</name>
        <t>Implementations MUST:</t>
        <ul spacing="normal">
          <li>Validate TLS certificates against a trusted CA store on all outbound connections.</li>
          <li>Use constant-time comparison for signature verification to prevent timing attacks.</li>
          <li>Maintain a cache of recently seen message IDs to detect replay attacks.</li>
          <li>Reject messages with timestamps outside a +/-15-minute window of current time.</li>
          <li>Maintain the message ID replay cache for at least 24 hours.</li>
          <li>Synchronize system clocks using NTP (<xref target="RFC5905"/>) or equivalent.</li>
          <li>Generate cryptographically secure random message IDs using a CSPRNG.</li>
          <li>Never expose private keys in logs, error messages, or API responses.</li>
        </ul>
        <t>Implementations SHOULD:</t>
        <ul spacing="normal">
          <li>Implement per-partner rate limiting on all endpoints.</li>
          <li>Use separate key pairs for signing and encryption (different <tt>use</tt> values).</li>
          <li>Rotate keys annually following the procedure in <xref target="key-rotation"/>.</li>
          <li>Monitor for anomalous patterns (repeated authentication failures, invalid signatures).</li>
        </ul>
      </section>
      <section anchor="key-management" numbered="true" toc="default">
        <name>Key Management</name>
        <t>Private keys:</t>
        <ul spacing="normal">
          <li>MUST be generated using a cryptographically secure random number generator.</li>
          <li>MUST be stored encrypted at rest.</li>
          <li>MUST NOT be transmitted over any network.</li>
          <li>SHOULD be stored in a Hardware Security Module (HSM) for high-security deployments.</li>
        </ul>
        <t>Public keys:</t>
        <ul spacing="normal">
          <li>MUST be distributed exclusively via the JWKS endpoint.</li>
          <li>SHOULD include a <tt>kid</tt> value encoding purpose and date (e.g., "org-sign-rsa-2026-01").</li>
          <li>MAY be cached by consuming parties for up to 24 hours.</li>
        </ul>
      </section>
      <section anchor="event-security" numbered="true" toc="default">
        <name>Event Considerations</name>
        <dl newline="true" spacing="normal">
          <dt>Origin of events</dt>
          <dd>
            The authenticity of an event derives from the JWS signature and
            the sender identity verification of <xref target="sender-identity"/>,
            not from its <tt>source</tt> or <tt>type</tt> attributes. Receivers
            MUST treat those attributes as claims made by the authenticated
            sender and MUST scope event identity to the <tt>sender_id</tt>
            (<xref target="event-receiver"/>). Receivers SHOULD maintain, for
            each partner, the list of event types accepted from that partner,
            and SHOULD reject an event whose type implies an authority the
            sender does not have, such as a Protocol Event about a message to
            which the sender is not a party.
          </dd>
          <dt>Automated reactions</dt>
          <dd>
            Events commonly trigger automated processing. Receivers SHOULD
            validate event data against the schema agreed for its type before
            making the event available to consumers, and SHOULD subject the
            resulting actions to the same authorization as actions triggered
            by business documents.
          </dd>
          <dt>Replay and duplication</dt>
          <dd>
            A valid Event Message cannot be created without the sender's
            signing key. The replay of a captured envelope is detected through
            the <tt>message_id</tt> replay cache
            (<xref target="impl-requirements"/>). An event re-sent by its
            producer in a new message is detected through the event identity
            (<xref target="event-receiver"/>).
          </dd>
          <dt>Asserted time</dt>
          <dd>
            The <tt>time</tt> attribute is asserted by the producer and is not
            verified by the protocol. A consumer that relies on it for
            contractual or regulatory deadlines can corroborate it with the
            routing header <tt>timestamp</tt> and with the J-MDN
            <tt>timestamp</tt>.
          </dd>
          <dt>Confidentiality outside the envelope</dt>
          <dd>
            Between partners, the complete event is encrypted. When a node
            forwards an event to webhooks, brokers, or logs, its context
            attributes commonly become visible to intermediaries. As
            recommended by <xref target="CloudEvents"/>, sensitive information
            SHOULD NOT be placed in context attributes, including
            <tt>subject</tt> and extension attributes.
          </dd>
          <dt>Disclosure through Protocol Events</dt>
          <dd>
            Protocol Events reveal trading relationships, document types, and
            timing, and can embed signed receipts. They MUST be delivered only
            to consumers authorized for the transaction, under the access
            rules of <xref target="external-evidence-channels"/>.
          </dd>
          <dt>Volume</dt>
          <dd>
            Events can be small and numerous. The rate limiting recommended
            above applies to Event Messages, and receivers MAY respond with
            HTTP 429 as described in <xref target="http-status-codes"/>.
          </dd>
        </dl>
      </section>
      <section anchor="compliance" numbered="true" toc="default">
        <name>Compliance Considerations</name>
        <t>FideX is designed to support compliance with:</t>
        <ul spacing="normal">
          <li>Non-repudiation requirements for legally binding electronic transactions.</li>
          <li>FDA 21 CFR Part 11 (electronic signatures in regulated industries).</li>
          <li>GDPR and similar data protection frameworks (via encrypted payloads).</li>
          <li>GS1 and UN/CEFACT EDI standards (via payload-agnostic design).</li>
        </ul>
        <t>Recommended audit trail retention periods:</t>
        <ul spacing="normal">
          <li>Message metadata: 7 years</li>
          <li>Cryptographic signatures (JWS): 7 years</li>
          <li>J-MDN receipts: 7 years</li>
        </ul>
      </section>
      <section anchor="deployment-note" numbered="true" toc="default">
        <name>Deployment Note</name>
        <t>
          FideX is designed to operate on standard web infrastructure. A conforming node
          can be implemented as a standard HTTPS web application behind any reverse proxy
          (Nginx, Apache, Caddy, cloud load balancers). No specialized B2B middleware,
          message broker, or gateway software is required. This is a key differentiator
          from AS2 (which required dedicated gateway software) and AS4 (which required
          SOAP stacks and ebMS processing engines).
        </t>
      </section>
    </section>

    <!-- SECTION 11: IANA CONSIDERATIONS -->
    <section anchor="iana-considerations" numbered="true" toc="default">
      <name>IANA Considerations</name>
      <t>
        This document has no IANA actions. The media type
        <tt>application/cloudevents+json</tt> referenced in
        <xref target="events"/> is defined by <xref target="CE-JSON"/> and is
        not registered by this document.
      </t>
    </section>

  </middle>

  <!-- BACK MATTER: REFERENCES AND APPENDICES -->
  <back>

    <references>
      <name>References</name>

      <references anchor="normative-references">
        <name>Normative References</name>

        <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="BCP" value="14"/>
          <seriesInfo name="RFC" value="2119"/>
          <seriesInfo name="DOI" value="10.17487/RFC2119"/>
        </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="BCP" value="14"/>
          <seriesInfo name="RFC" value="8174"/>
          <seriesInfo name="DOI" value="10.17487/RFC8174"/>
        </reference>

        <reference anchor="RFC8446" target="https://www.rfc-editor.org/info/rfc8446">
          <front>
            <title>The Transport Layer Security (TLS) Protocol Version 1.3</title>
            <author initials="E." surname="Rescorla" fullname="E. Rescorla"/>
            <date year="2018" month="August"/>
          </front>
          <seriesInfo name="RFC" value="8446"/>
          <seriesInfo name="DOI" value="10.17487/RFC8446"/>
        </reference>

        <reference anchor="RFC6066" target="https://www.rfc-editor.org/info/rfc6066">
          <front>
            <title>Transport Layer Security (TLS) Extensions: Extension Definitions</title>
            <author initials="D." surname="Eastlake 3rd" fullname="D. Eastlake 3rd"/>
            <date year="2011" month="January"/>
          </front>
          <seriesInfo name="RFC" value="6066"/>
          <seriesInfo name="DOI" value="10.17487/RFC6066"/>
        </reference>

        <reference anchor="RFC7515" target="https://www.rfc-editor.org/info/rfc7515">
          <front>
            <title>JSON Web Signature (JWS)</title>
            <author initials="M." surname="Jones" fullname="M. Jones"/>
            <author initials="J." surname="Bradley" fullname="J. Bradley"/>
            <author initials="N." surname="Sakimura" fullname="N. Sakimura"/>
            <date year="2015" month="May"/>
          </front>
          <seriesInfo name="RFC" value="7515"/>
          <seriesInfo name="DOI" value="10.17487/RFC7515"/>
        </reference>

        <reference anchor="RFC7516" target="https://www.rfc-editor.org/info/rfc7516">
          <front>
            <title>JSON Web Encryption (JWE)</title>
            <author initials="M." surname="Jones" fullname="M. Jones"/>
            <author initials="J." surname="Hildebrand" fullname="J. Hildebrand"/>
            <date year="2015" month="May"/>
          </front>
          <seriesInfo name="RFC" value="7516"/>
          <seriesInfo name="DOI" value="10.17487/RFC7516"/>
        </reference>

        <reference anchor="RFC7517" target="https://www.rfc-editor.org/info/rfc7517">
          <front>
            <title>JSON Web Key (JWK)</title>
            <author initials="M." surname="Jones" fullname="M. Jones"/>
            <date year="2015" month="May"/>
          </front>
          <seriesInfo name="RFC" value="7517"/>
          <seriesInfo name="DOI" value="10.17487/RFC7517"/>
        </reference>

        <reference anchor="RFC7518" target="https://www.rfc-editor.org/info/rfc7518">
          <front>
            <title>JSON Web Algorithms (JWA)</title>
            <author initials="M." surname="Jones" fullname="M. Jones"/>
            <date year="2015" month="May"/>
          </front>
          <seriesInfo name="RFC" value="7518"/>
          <seriesInfo name="DOI" value="10.17487/RFC7518"/>
        </reference>

        <reference anchor="RFC9562" target="https://www.rfc-editor.org/info/rfc9562">
          <front>
            <title>Universally Unique IDentifiers (UUIDs)</title>
            <author initials="K." surname="Davis" fullname="K. Davis"/>
            <author initials="B." surname="Peabody" fullname="B. Peabody"/>
            <author initials="P." surname="Leach" fullname="P. Leach"/>
            <date year="2024" month="May"/>
          </front>
          <seriesInfo name="RFC" value="9562"/>
          <seriesInfo name="DOI" value="10.17487/RFC9562"/>
        </reference>

        <reference anchor="RFC5905" target="https://www.rfc-editor.org/info/rfc5905">
          <front>
            <title>Network Time Protocol Version 4: Protocol and Algorithms Specification</title>
            <author initials="D." surname="Mills" fullname="D. Mills"/>
            <author initials="J." surname="Martin" fullname="J. Martin"/>
            <author initials="J." surname="Burbank" fullname="J. Burbank"/>
            <author initials="W." surname="Kasch" fullname="W. Kasch"/>
            <date year="2010" month="June"/>
          </front>
          <seriesInfo name="RFC" value="5905"/>
          <seriesInfo name="DOI" value="10.17487/RFC5905"/>
        </reference>

        <reference anchor="RFC9110" target="https://www.rfc-editor.org/info/rfc9110">
          <front>
            <title>HTTP Semantics</title>
            <author initials="R." surname="Fielding" fullname="R. Fielding"
                    role="editor"/>
            <author initials="M." surname="Nottingham" fullname="M. Nottingham"
                    role="editor"/>
            <author initials="J." surname="Reschke" fullname="J. Reschke"
                    role="editor"/>
            <date year="2022" month="June"/>
          </front>
          <seriesInfo name="STD" value="97"/>
          <seriesInfo name="RFC" value="9110"/>
          <seriesInfo name="DOI" value="10.17487/RFC9110"/>
        </reference>

        <reference anchor="RFC3339" target="https://www.rfc-editor.org/info/rfc3339">
          <front>
            <title>Date and Time on the Internet: Timestamps</title>
            <author initials="G." surname="Klyne" fullname="G. Klyne"/>
            <author initials="C." surname="Newman" fullname="C. Newman"/>
            <date year="2002" month="July"/>
          </front>
          <seriesInfo name="RFC" value="3339"/>
          <seriesInfo name="DOI" value="10.17487/RFC3339"/>
        </reference>

        <reference anchor="RFC3986" target="https://www.rfc-editor.org/info/rfc3986">
          <front>
            <title>Uniform Resource Identifier (URI): Generic Syntax</title>
            <author initials="T." surname="Berners-Lee" fullname="T. Berners-Lee"/>
            <author initials="R." surname="Fielding" fullname="R. Fielding"/>
            <author initials="L." surname="Masinter" fullname="L. Masinter"/>
            <date year="2005" month="January"/>
          </front>
          <seriesInfo name="STD" value="66"/>
          <seriesInfo name="RFC" value="3986"/>
          <seriesInfo name="DOI" value="10.17487/RFC3986"/>
        </reference>

        <reference anchor="CloudEvents" target="https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md">
          <front>
            <title>CloudEvents - Version 1.0.2</title>
            <author>
              <organization>Cloud Native Computing Foundation</organization>
            </author>
            <date year="2022" month="February"/>
          </front>
        </reference>

        <reference anchor="CE-JSON" target="https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/formats/json-format.md">
          <front>
            <title>JSON Event Format for CloudEvents - Version 1.0.2</title>
            <author>
              <organization>Cloud Native Computing Foundation</organization>
            </author>
            <date year="2022" month="February"/>
          </front>
        </reference>

      </references>

      <references anchor="informative-references">
        <name>Informative References</name>

        <reference anchor="RFC5246" target="https://www.rfc-editor.org/info/rfc5246">
          <front>
            <title>The Transport Layer Security (TLS) Protocol Version 1.2</title>
            <author initials="T." surname="Dierks" fullname="T. Dierks"/>
            <author initials="E." surname="Rescorla" fullname="E. Rescorla"/>
            <date year="2008" month="August"/>
          </front>
          <seriesInfo name="RFC" value="5246"/>
          <seriesInfo name="DOI" value="10.17487/RFC5246"/>
        </reference>

        <reference anchor="RFC4130" target="https://www.rfc-editor.org/info/rfc4130">
          <front>
            <title>MIME-Based Secure Peer-to-Peer Business Data Interchange Using HTTP, Applicability Statement 2 (AS2)</title>
            <author initials="D." surname="Moberg" fullname="D. Moberg"/>
            <author initials="R." surname="Drummond" fullname="R. Drummond"/>
            <date year="2005" month="July"/>
          </front>
          <seriesInfo name="RFC" value="4130"/>
          <seriesInfo name="DOI" value="10.17487/RFC4130"/>
        </reference>

        <reference anchor="RFC9113" target="https://www.rfc-editor.org/info/rfc9113">
          <front>
            <title>HTTP/2</title>
            <author initials="M." surname="Thomson" fullname="M. Thomson"
                    role="editor"/>
            <author initials="C." surname="Benfield" fullname="C. Benfield"
                    role="editor"/>
            <date year="2022" month="June"/>
          </front>
          <seriesInfo name="RFC" value="9113"/>
          <seriesInfo name="DOI" value="10.17487/RFC9113"/>
        </reference>

        <reference anchor="RFC9114" target="https://www.rfc-editor.org/info/rfc9114">
          <front>
            <title>HTTP/3</title>
            <author initials="M." surname="Bishop" fullname="M. Bishop" role="editor"/>
            <date year="2022" month="June"/>
          </front>
          <seriesInfo name="RFC" value="9114"/>
          <seriesInfo name="DOI" value="10.17487/RFC9114"/>
        </reference>

        <reference anchor="OASIS-ebMS" target="https://docs.oasis-open.org/ebxml-msg/ebms/v3.0/core/os/">
          <front>
            <title>OASIS ebXML Messaging Services Version 3.0: Part 1, Core Features</title>
            <author>
              <organization>OASIS</organization>
            </author>
            <date year="2007" month="October"/>
          </front>
        </reference>

        <reference anchor="GS1-JSON" target="https://www.gs1.org/voc/">
          <front>
            <title>GS1 Web Vocabulary</title>
            <author>
              <organization>GS1</organization>
            </author>
            <date year="2023"/>
          </front>
        </reference>

        <reference anchor="CE-HTTP" target="https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/bindings/http-protocol-binding.md">
          <front>
            <title>HTTP Protocol Binding for CloudEvents - Version 1.0.2</title>
            <author>
              <organization>Cloud Native Computing Foundation</organization>
            </author>
            <date year="2022" month="February"/>
          </front>
        </reference>

        <reference anchor="CE-WEBHOOK" target="https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/http-webhook.md">
          <front>
            <title>HTTP 1.1 Web Hooks for Event Delivery - Version 1.0.2</title>
            <author>
              <organization>Cloud Native Computing Foundation</organization>
            </author>
            <date year="2022" month="February"/>
          </front>
        </reference>

      </references>
    </references>

    <!-- APPENDIX A: COMPLETE MESSAGE EXAMPLE -->
    <section anchor="appendix-example" numbered="false" toc="default">
      <name>Appendix A: Complete Message Example</name>
      <t>The following illustrates a complete FideX message exchange.</t>
      <t>HTTP request (sender to receiver):</t>
      <sourcecode name="complete-request" type="http"><![CDATA[
POST /api/v1/receive HTTP/1.1
Host: partner.example.com
Content-Type: application/json

{
  "routing_header": {
    "fidex_version": "1.0",
    "message_id": "fdx-a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "sender_id": "urn:gln:1234567890123",
    "receiver_id": "urn:gln:9876543210987",
    "document_type": "GS1_ORDER_JSON",
    "timestamp": "2026-03-09T19:30:00.000Z",
    "receipt_webhook": "https://sender.example.com/api/v1/receipt"
  },
  "encrypted_payload": "eyJhbGciOiJSU0EtT0FFUCIs..."
}
      ]]></sourcecode>
      <t>HTTP 202 response (receiver accepts):</t>
      <sourcecode name="complete-response" type="json"><![CDATA[
{
  "status": "accepted",
  "message_id": "fdx-a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "timestamp": "2026-03-09T19:30:00.500Z"
}
      ]]></sourcecode>
      <t>J-MDN receipt (receiver delivers to sender's webhook):</t>
      <sourcecode name="complete-jmdn" type="http"><![CDATA[
POST /api/v1/receipt HTTP/1.1
Host: sender.example.com
Content-Type: application/json
X-FideX-Original-Message-ID: fdx-a1b2c3d4-e5f6-7890-abcd-ef1234567890

{
  "original_message_id": "fdx-a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "DELIVERED",
  "receiver_id": "urn:gln:9876543210987",
  "hash_verification": "sha256:9f86d08...b0f00a08",
  "timestamp": "2026-03-09T19:30:02.000Z",
  "error_log": null,
  "signature": "eyJhbGciOiJSUzI1NiIs..."
}
      ]]></sourcecode>
      <t>
        Event Message example (<xref target="event-messages"/>). The routing
        header identifies the payload as an event:
      </t>
      <sourcecode name="event-routing-header" type="json"><![CDATA[
{
  "fidex_version": "1.0",
  "message_id": "fdx-7c9e6679-7425-40de-944b-e07fc1f90ae7",
  "sender_id": "urn:gln:1234567890123",
  "receiver_id": "urn:gln:9876543210987",
  "document_type": "CLOUDEVENTS_JSON",
  "timestamp": "2026-03-10T08:15:00.000Z"
}
      ]]></sourcecode>
      <t>
        The CloudEvent below is the JWS payload before signing. It relates a
        shipment departure to the FideX message that carried the despatch
        advice:
      </t>
      <sourcecode name="event-payload" type="json"><![CDATA[
{
  "specversion": "1.0",
  "id": "5f0c1e5e-7a3b-4c57-9d0e-2b6a8f1c9d11",
  "source": "https://fidex.example.com/warehouse/01",
  "type": "com.example.shipment.departed.v1",
  "time": "2026-03-10T08:14:52Z",
  "subject": "DA-2026-004512",
  "datacontenttype": "application/json",
  "fidexmsgid": "fdx-a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "data": {
    "despatch_advice": "DA-2026-004512",
    "carrier": "Example Logistics",
    "estimated_arrival": "2026-03-11T16:00:00Z"
  }
}
      ]]></sourcecode>
    </section>

    <!-- APPENDIX B: GLOSSARY -->
    <section anchor="appendix-glossary" numbered="false" toc="default">
      <name>Appendix B: Glossary</name>
      <dl newline="false" spacing="normal">
        <dt>AS5</dt><dd>Application Statement 5  -- the formal designation of the FideX protocol.</dd>
        <dt>B2B</dt><dd>Business-to-Business electronic commerce.</dd>
        <dt>CloudEvent</dt><dd>An event expressed according to the CNCF CloudEvents specification.</dd>
        <dt>CNCF</dt><dd>Cloud Native Computing Foundation.</dd>
        <dt>CSPRNG</dt><dd>Cryptographically Secure Pseudo-Random Number Generator.</dd>
        <dt>EDI</dt><dd>Electronic Data Interchange.</dd>
        <dt>GLN</dt><dd>Global Location Number  -- GS1 standard organization identifier.</dd>
        <dt>HSM</dt><dd>Hardware Security Module  -- tamper-resistant hardware for key storage.</dd>
        <dt>J-MDN</dt><dd>JSON Message Disposition Notification  -- the FideX signed delivery receipt.</dd>
        <dt>JOSE</dt><dd>JSON Object Signing and Encryption  -- the IETF framework comprising JWS, JWE, JWK, and JWA.</dd>
        <dt>JWE</dt><dd>JSON Web Encryption (RFC 7516).</dd>
        <dt>JWK</dt><dd>JSON Web Key (RFC 7517).</dd>
        <dt>JWKS</dt><dd>JSON Web Key Set  -- a JSON document containing a set of public keys.</dd>
        <dt>JWS</dt><dd>JSON Web Signature (RFC 7515).</dd>
        <dt>Node</dt><dd>A FideX-compliant server capable of sending and receiving messages.</dd>
        <dt>URN</dt><dd>Uniform Resource Name  -- a persistent, location-independent identifier.</dd>
      </dl>
    </section>

    <!-- APPENDIX C: CONFORMANCE PROFILES -->
    <section anchor="appendix-conformance" numbered="false" toc="default">
      <name>Appendix C: Conformance Profiles</name>
      <t>
        FideX defines three conformance profiles to enable progressive adoption.
        Implementations MUST declare which profile(s) they conform to via the
        <tt>conformance_profile</tt> field in their AS5 configuration.
      </t>
      <t>
        Core conformance includes signed J-MDN generation, delivery, and verification,
        as well as the mandatory security requirements of this document. A test suite
        that omits these checks establishes only partial implementation coverage;
        it does not establish Core conformance.
      </t>
      <section anchor="conformance-core" numbered="false" toc="default">
        <name>C.1 FideX Core</name>
        <t>
          An implementation claiming <strong>FideX Core</strong> conformance MUST support
          all requirements listed in Sections 2 through 8 of this specification, including:
        </t>
        <ul spacing="normal">
          <li>HTTP/1.1 over TLS 1.3</li>
          <li>Sign-then-encrypt: JWE(JWS(payload))</li>
          <li>RS256 signatures; RSA-OAEP + A256GCM encryption</li>
          <li>RSA key size >= 2048 bits</li>
          <li>JWKS endpoint at /.well-known/jwks.json</li>
          <li>AS5 configuration endpoint</li>
          <li>4-phase discovery handshake</li>
          <li>Message state machine (QUEUED, SENT, DELIVERED, FAILED)</li>
          <li>J-MDN generation, signing, and delivery</li>
          <li>J-MDN fallback delivery via AS5 config receive_receipt endpoint</li>
          <li>Standard error codes and HTTP status codes</li>
          <li>Replay detection via message_id cache (>= 24 hours)</li>
          <li>Timestamp validation (+/-15-minute window)</li>
        </ul>
      </section>
      <section anchor="conformance-enhanced" numbered="false" toc="default">
        <name>C.2 FideX Enhanced</name>
        <t>
          An implementation claiming <strong>FideX Enhanced</strong> conformance MUST satisfy
          FideX Core AND additionally support:
        </t>
        <ul spacing="normal">
          <li>HTTP/2 for multiplexed connections</li>
          <li>Separate signing and encryption key pairs (different kid and use values)</li>
          <li>RSA key size >= 4096 bits</li>
          <li>Key rotation support (overlapping key publication)</li>
          <li>J-MDN delivery retry per the schedule in Section 7.3.6</li>
          <li>Per-partner rate limiting on all endpoints</li>
          <li>Structured JSON logging with security event correlation IDs</li>
          <li>Health endpoints (/health and /ready)</li>
        </ul>
      </section>
      <section anchor="conformance-edge" numbered="false" toc="default">
        <name>C.3 FideX Edge</name>
        <t>
          An implementation claiming <strong>FideX Edge</strong> conformance MUST satisfy
          FideX Enhanced AND additionally support:
        </t>
        <ul spacing="normal">
          <li>HTTP/3 over QUIC for connection resilience</li>
          <li>Mutual TLS (mTLS)  -- client certificate authentication</li>
          <li>HSM-based private key storage</li>
        </ul>
      </section>
      <section anchor="conformance-events" numbered="false" toc="default">
        <name>C.4 Events (Optional Capability)</name>
        <t>
          Event support is an optional capability that is independent of the
          three profiles above. It is advertised through the AS5 configuration
          (<xref target="event-discovery"/>), not through the
          <tt>conformance_profile</tt> field. An implementation that claims
          event support MUST satisfy FideX Core AND additionally:
        </t>
        <ul spacing="normal">
          <li>Carry exactly one CloudEvent in the JSON Event Format in each
          <tt>CLOUDEVENTS_JSON</tt> message it sends</li>
          <li>Meet the attribute requirements of
          <xref target="event-attributes"/> in events it produces, and enforce
          them on events it receives</li>
          <li>Process received Event Messages as specified in
          <xref target="event-receiver"/>, including the
          <tt>INVALID_EVENT</tt> and <tt>UNKNOWN_EVENT_TYPE</tt> negative
          receipts and duplicate detection by sender, <tt>source</tt>, and
          <tt>id</tt></li>
          <li>List <tt>CLOUDEVENTS_JSON</tt> in
          <tt>supported_document_types</tt> when it accepts Event Messages</li>
        </ul>
        <t>
          Emitting Protocol Events is a further option. An implementation that
          emits them MUST use the types, attributes, and data of
          <xref target="protocol-events"/>.
        </t>
      </section>
    </section>

    <!-- APPENDIX D: TEST VECTORS -->
    <section anchor="appendix-test-vectors" numbered="false" toc="default">
      <name>Appendix D: Interoperability Test Vectors</name>
      <t>
        This appendix provides known-answer test vectors to allow implementers to verify
        their JOSE cryptographic operations produce correct output.
      </t>
      <t>
        <strong>WARNING:</strong> The key material in this appendix is public and MUST NOT
        be used for any production traffic.
      </t>
      <t>Test payload (UTF-8 bytes):</t>
      <sourcecode name="test-payload" type="json"><![CDATA[
{"order_id":"PO-TEST-001","amount":100.00,"currency":"USD"}
      ]]></sourcecode>
      <t>SHA-256 hash of test payload:</t>
      <sourcecode name="test-hash" type="text"><![CDATA[
sha256:
  bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f9a69e4c98b7b0f09cb281e71
      ]]></sourcecode>
      <t>Expected JWS header for signing:</t>
      <sourcecode name="test-jws-header" type="json"><![CDATA[
{"alg":"RS256","kid":"test-sign-2026-01"}
      ]]></sourcecode>
      <t>Expected JWE header for encryption:</t>
      <sourcecode name="test-jwe-header" type="json"><![CDATA[
{
  "alg": "RSA-OAEP",
  "enc": "A256GCM",
  "cty": "JWT",
  "kid": "test-enc-2026-01"
}
      ]]></sourcecode>
      <t>Test routing header:</t>
      <sourcecode name="test-routing-header" type="json"><![CDATA[
{
  "fidex_version": "1.0",
  "message_id": "fdx-00000000-0000-0000-0000-000000000001",
  "sender_id": "urn:gln:0000000000001",
  "receiver_id": "urn:gln:0000000000002",
  "document_type": "GS1_ORDER_JSON",
  "timestamp": "2026-01-01T00:00:00.000Z",
  "receipt_webhook": "https://test.sender.example.com/receipt"
}
      ]]></sourcecode>
      <t>Verification procedure:</t>
      <ol spacing="normal">
        <li><strong>Sign Test:</strong> Sign the test payload using RS256. Verify using the test public key. Verified payload MUST match original.</li>
        <li><strong>Encrypt Test:</strong> Encrypt the JWS using RSA-OAEP/A256GCM. Decrypt using the test private key. Decrypted content MUST match the JWS.</li>
        <li><strong>Hash Test:</strong> Compute SHA-256 of the raw payload bytes. Result MUST equal bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f9a69e4c98b7b0f09cb281e71.</li>
        <li><strong>Round-Trip Test:</strong> Construct a complete envelope, parse it, decrypt, verify signature, and extract payload. Result MUST match original test payload.</li>
        <li><strong>J-MDN Test:</strong> Construct a J-MDN for the test message. Sign with receiver's key. Verify the J-MDN signature.</li>
      </ol>
    </section>

    <!-- APPENDIX E: JSON SCHEMAS -->
    <section anchor="appendix-schemas" numbered="false" toc="default">
      <name>Appendix E: JSON Schema Definitions</name>
      <t>
        The following JSON Schema (Draft-07) definitions provide machine-readable validation
        rules for FideX structures.
      </t>
      <section anchor="schema-routing-header" numbered="false" toc="default">
        <name>E.1 Routing Header Schema</name>
        <sourcecode name="schema-routing" type="json"><![CDATA[
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://fidex-protocol.org/schemas/v1/routing-header.json",
  "title": "FideX Routing Header",
  "type": "object",
  "required": [
    "fidex_version", "message_id", "sender_id",
    "receiver_id", "document_type", "timestamp"
  ],
  "additionalProperties": true,
  "properties": {
    "fidex_version": {
      "type": "string", "pattern": "^\\d+\\.\\d+$"
    },
    "message_id": {
      "type": "string", "minLength": 1, "maxLength": 256
    },
    "sender_id": {
      "type": "string",
      "pattern": "^urn:(gln|duns|lei|tin|custom):.+$"
    },
    "receiver_id": {
      "type": "string",
      "pattern": "^urn:(gln|duns|lei|tin|custom):.+$"
    },
    "document_type": {
      "type": "string", "pattern": "^[A-Z0-9_]+$",
      "minLength": 1, "maxLength": 128
    },
    "timestamp": { "type": "string", "format": "date-time" },
    "receipt_webhook": {
      "type": "string", "format": "uri",
      "pattern": "^https://"
    },
    "payload_digest": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    }
  },
  "patternProperties": { "^x-": {} }
}
        ]]></sourcecode>
      </section>
      <section anchor="schema-jmdn" numbered="false" toc="default">
        <name>E.2 J-MDN Schema</name>
        <sourcecode name="schema-jmdn" type="json"><![CDATA[
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://fidex-protocol.org/schemas/v1/jmdn.json",
  "title": "FideX J-MDN",
  "type": "object",
  "required": [
    "original_message_id", "status", "receiver_id",
    "hash_verification", "timestamp", "error_log", "signature"
  ],
  "additionalProperties": false,
  "properties": {
    "original_message_id": { "type": "string", "minLength": 1 },
    "status": {
      "type": "string", "enum": ["DELIVERED", "FAILED"]
    },
    "receiver_id": {
      "type": "string",
      "pattern": "^urn:(gln|duns|lei|tin|custom):.+$"
    },
    "hash_verification": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "timestamp": { "type": "string", "format": "date-time" },
    "error_log": {
      "oneOf": [
        { "type": "null" },
        {
          "type": "object",
          "required": ["error_code", "error_message"],
          "properties": {
            "error_code": {
              "type": "string",
              "enum": [
                "DECRYPTION_FAILED",
                "SIGNATURE_INVALID",
                "UNKNOWN_DOCUMENT_TYPE",
                "PAYLOAD_TOO_LARGE",
                "INTERNAL_ERROR",
                "INVALID_EVENT",
                "UNKNOWN_EVENT_TYPE"
              ]
            },
            "error_message": { "type": "string" },
            "details": { "type": "string" }
          }
        }
      ]
    },
    "signature": { "type": "string", "minLength": 1 }
  }
}
        ]]></sourcecode>
      </section>
      <section anchor="schema-as5-config" numbered="false" toc="default">
        <name>E.3 AS5 Configuration Schema</name>
        <sourcecode name="schema-as5-config" type="json"><![CDATA[
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://fidex-protocol.org/schemas/v1/as5-config.json",
  "title": "FideX AS5 Configuration",
  "type": "object",
  "required": [
    "fidex_version", "supported_versions", "node_id",
    "organization_name", "public_domain",
    "endpoints", "security"
  ],
  "properties": {
    "fidex_version": {
      "type": "string", "pattern": "^\\d+\\.\\d+$"
    },
    "supported_versions": {
      "type": "array",
      "items": { "type": "string" },
      "minItems": 1
    },
    "conformance_profile": {
      "type": "string",
      "enum": ["core", "enhanced", "edge"]
    },
    "node_id": { "type": "string", "pattern": "^urn:" },
    "organization_name": { "type": "string", "minLength": 1 },
    "public_domain": { "type": "string" },
    "supported_document_types": {
      "type": "array",
      "items": {
        "type": "string", "pattern": "^[A-Z0-9_]+$"
      }
    },
    "events": {
      "type": "object",
      "properties": {
        "accepted_types": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        },
        "published_types": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        }
      }
    },
    "endpoints": {
      "type": "object",
      "required": [
        "receive_message", "receive_receipt",
        "register", "jwks"
      ],
      "properties": {
        "receive_message": { "type": "string", "format": "uri" },
        "receive_receipt": { "type": "string", "format": "uri" },
        "register": { "type": "string", "format": "uri" },
        "jwks": { "type": "string", "format": "uri" }
      }
    },
    "security": {
      "type": "object",
      "required": [
        "signature_algorithm", "encryption_algorithm",
        "content_encryption", "minimum_key_size"
      ],
      "properties": {
        "signature_algorithm": { "type": "string" },
        "encryption_algorithm": { "type": "string", "minLength": 1 },
        "supported_encryption_algorithms": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "minItems": 1,
          "uniqueItems": true
        },
        "content_encryption": { "type": "string" },
        "minimum_key_size": {
          "type": "integer", "minimum": 2048
        }
      }
    }
  }
}
        ]]></sourcecode>
      </section>
      <section anchor="schema-event" numbered="false" toc="default">
        <name>E.4 Event Message Payload Schema</name>
        <t>
          This schema expresses the additional requirements of
          <xref target="event-attributes"/>. It does not replace validation
          against <xref target="CloudEvents"/>.
        </t>
        <sourcecode name="schema-event" type="json"><![CDATA[
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://fidex-protocol.org/schemas/v1/event.json",
  "title": "FideX Event Message Payload (CloudEvent)",
  "type": "object",
  "required": ["specversion", "id", "source", "type", "time"],
  "additionalProperties": true,
  "properties": {
    "specversion": { "const": "1.0" },
    "id": { "type": "string", "minLength": 1 },
    "source": {
      "type": "string", "format": "uri", "minLength": 1
    },
    "type": { "type": "string", "minLength": 1 },
    "time": { "type": "string", "format": "date-time" },
    "subject": { "type": "string", "minLength": 1 },
    "datacontenttype": { "type": "string", "minLength": 1 },
    "dataschema": {
      "type": "string", "format": "uri", "minLength": 1
    },
    "data_base64": { "type": "string" },
    "fidexmsgid": { "type": "string", "minLength": 1 },
    "fidexsender": {
      "type": "string",
      "pattern": "^urn:(gln|duns|lei|tin|custom):.+$"
    },
    "fidexreceiver": {
      "type": "string",
      "pattern": "^urn:(gln|duns|lei|tin|custom):.+$"
    },
    "fidexdoctype": {
      "type": "string", "pattern": "^[A-Z0-9_]+$"
    }
  }
}
        ]]></sourcecode>
      </section>
    </section>

    <section anchor="implementation-plans" numbered="false" toc="default">
      <name>Appendix F: Implementation Plans and Interoperability</name>
      <t>
        This appendix is informative and records development plans, not claims
        of implementation availability or demonstrated conformance. Full Java
        and C#/.NET implementations are planned to broaden deployment options
        and provide additional independent interoperability coverage. Language
        examples alone do not constitute a complete protocol implementation.
      </t>
      <t>
        Each implementation is intended to support the complete Core profile,
        including discovery and registration, JOSE message exchange, signed
        J-MDN generation and verification, algorithm negotiation, retry handling,
        and the mandatory security requirements. Evidence delivery to non-FideX
        participants can be provided through the application integration described
        in <xref target="non-fidex-evidence"/>.
      </t>
      <t>
        Interoperability evaluation is planned in both directions between Java,
        C#/.NET, Go, and PHP implementations, using shared positive and negative
        test vectors. Results should identify the exact draft revision, software
        versions, tested capabilities, and known limitations. No Java or C#/.NET
        implementation or successful interoperability result is asserted by this
        document at the time of this revision.
      </t>
      <t>
        The event capability of <xref target="events"/> is specified in this
        revision. No implementation of it, and no interoperability result for
        it, is asserted by this document.
      </t>
    </section>

    <section anchor="changes" numbered="false" toc="default">
      <name>Appendix G: Changes from Revision -01</name>
      <ul spacing="normal">
        <li>Added <xref target="events"/> (Events): an optional capability to
        exchange events represented as CloudEvents 1.0, as Event Messages
        between partners and as Protocol Events about the message life
        cycle.</li>
        <li>Added the standard document type <tt>CLOUDEVENTS_JSON</tt> and
        reserved the <tt>CLOUDEVENTS_</tt> prefix.</li>
        <li>Added the optional <tt>events</tt> object to the AS5 configuration
        and to its schema.</li>
        <li>Added the J-MDN error codes <tt>INVALID_EVENT</tt> and
        <tt>UNKNOWN_EVENT_TYPE</tt>.</li>
        <li>Aligned the webhook channel for non-FideX participants with
        Protocol Events and the CloudEvents HTTP binding.</li>
        <li>Added security considerations for events, an optional conformance
        capability (C.4), an Event Message example, and a payload schema
        (E.4).</li>
        <li>Added references to CloudEvents, RFC 3339, and RFC 3986.</li>
        <li>No change to the message envelope, the cryptographic requirements,
        the J-MDN structure, or the protocol version. Commands
        (request/response messages) are not defined.</li>
      </ul>
    </section>

  </back>
</rfc>
