attest Docs

Guides

Witness a round-trip

Record an observation on each side of a boundary and get a reconciled result.

How it works #

A witness pair records one operation as it crosses a boundary, for example a transfer leaving checkout and arriving at the payment service:

  1. Assembly. Before the operation runs, you record what is about to be sent.
  2. Your operation runs. attest does not run it, proxy it, or block it.
  3. Delivery. After the operation, you record what arrived on the other side.
  4. Finalize. attest compares the two observations and fixes the result as matched, divergent, incomplete, or orphaned.

The SDK's prepareWitness() and execute() perform steps 1, 3, and 4 around your function. Over plain HTTP you make the three calls yourself.

With the SDK #

prepareWitness() is synchronous and makes no network call. It fixes the pair ID, event ID, and timestamp up front so you can persist them before anything happens.

execute(operation) then:

  1. records the assembly observation;
  2. calls your operation once;
  3. records a delivery observation whose source is your destination and whose outcome is ok;
  4. finalizes the pair and returns { result, witness }.
Request · JavaScript (SDK)
import { Attest } from "@attestinfra/sdk";

const attest = new Attest({ apiKey: process.env.ATTEST_API_KEY });

// Your operation. Replace with the real call.
async function transferFunds() {
  return { transferId: "tr_82" };
}

const prepared = attest.prepareWitness({
  eventType: "transfer.requested",
  eventId: "transfer_82",
  source: "checkout",
  destination: "payments",
  action: "transfer",
  evidence: { actionId: "transfer_82", amount: 500, currency: "USD" },
});

// Persist prepared.pairId and prepared.assemblyIdentity here.

const { result, witness } = await prepared.execute(() => transferFunds());
console.log(result, witness.lifecycle, witness.reconciliationStatus);
Output · Console
{ transferId: 'tr_82' } FINALIZED matched

With HTTP #

Send the assembly observation before the operation and the delivery observation after it. Each newly accepted observation returns 201.

The timestamp is part of each observation's identity. If you retry an observation, resend it byte-for-byte with the same timestamp. A retry with a different timestamp or different evidence is a conflict (409).

Request · cURL · Assembly
curl -X POST https://attestinfra.com/v1/witness \
  -H "Authorization: Bearer $ATTEST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "pairId": "pr_4f8a2c6e1b9d3a70",
    "stage": "assembly",
    "eventType": "transfer.requested",
    "eventId": "transfer_83",
    "timestamp": "2026-10-19T14:05:00.000Z",
    "source": "checkout",
    "destination": "payments",
    "action": "transfer",
    "evidence": { "actionId": "transfer_83", "amount": 500, "currency": "USD" }
  }'
Request · cURL · Delivery
curl -X POST https://attestinfra.com/v1/witness \
  -H "Authorization: Bearer $ATTEST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "pairId": "pr_4f8a2c6e1b9d3a70",
    "stage": "delivery",
    "eventType": "transfer.requested",
    "eventId": "transfer_83",
    "timestamp": "2026-10-19T14:05:00.850Z",
    "source": "payments",
    "action": "transfer",
    "outcome": "ok",
    "evidence": { "actionId": "transfer_83", "amount": 500, "currency": "USD" }
  }'
Request · cURL · Finalize
curl -X POST https://attestinfra.com/v1/witness/pr_4f8a2c6e1b9d3a70/finalize \
  -H "Authorization: Bearer $ATTEST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'

Read the result #

The pair matches when eventType, action, and evidence are identical on both sides and, if both are sent, the assembly destination equals the delivery source. timestamp, eventId, and outcome are not compared.

Any compared field that differs is listed in divergences and the pair is divergent. A pair finalized with only one observation is incomplete (assembly only) or orphaned (delivery only). All states are in Witness states.

executionState is always unknown. Observations show what attest received, not whether your operation actually ran.

Response · 200 · Finalize
{
  "pairId": "pr_4f8a2c6e1b9d3a70",
  "lifecycle": "FINALIZED",
  "reconciliationStatus": "matched",
  "assemblyObserved": true,
  "deliveryObserved": true,
  "finalized": true,
  "executionState": "unknown",
  "divergences": [],
  "assembly": {
    "accepted": true,
    "evidenceHash": "dc4a324b60863617a6cfbeb842de5bfb31e3e393e6cad20ac097b94478c5426b",
    "receiptId": "moni_wit_390bba43-843a-43b8-9fa2-40ba9d4f6e2f",
    "outcome": null
  },
  "delivery": {
    "accepted": true,
    "evidenceHash": "dc4a324b60863617a6cfbeb842de5bfb31e3e393e6cad20ac097b94478c5426b",
    "receiptId": "moni_wit_330ad43c-3d20-4922-aa3a-245f58eb6738",
    "outcome": "ok"
  },
  "finalizedAt": "2026-10-19T14:05:01.204Z",
  "reconciliationFormat": "attest-witness-reconciliation-v1",
  "reconciliationDigest": "74cacb226d10cd9cf8d77ebe0aa16fe8c6c786bf74ed117bc8168a26fdb9c66f"
}

When something fails #

SituationWhat the SDK doesWhat you do
Your operation throwsRecords a delivery with outcome: "error" and finalizes, both best-effort, then rethrows your original error unchanged.Handle your error as usual.
Delivery or finalize fails after your operation succeededThrows AttestWitnessDeliveryError with pairId and deliveryObservation.Do not rerun the operation. Call resumeWitness(error.pairId, { deliveryObservation: error.deliveryObservation }).
The assembly for this pair already existsThrows AttestWitnessAssemblyExistsError and does not call your operation.Inspect with resumeWitness(pairId).
Your process dies mid-operationNothing; the pair stays OPEN.On restart, call resumeWitness(pairId) with the persisted ID.