attest Docs

SDK

Recovery and helpers

Inspect, recover, and record witness pairs step by step, and handle SDK errors.

resumeWitness() #

attest.resumeWitness(pairId, { deliveryObservation }) inspects a pair after a crash or an AttestWitnessDeliveryError and finishes it only when that is safe. It never calls your operation and never invents a delivery.

Pair stateWhat resumeWitness does
Already finalizedReturns it unchanged.
Delivery recorded, not finalizedFinalizes and returns the result.
No delivery, no deliveryObservation passedReturns the pair with recoveryStatus: "delivery_required". The pair stays OPEN.
No delivery, deliveryObservation passedRecords that delivery, then finalizes.

To declare a pair whose delivery will never come incomplete, call finalizeWitness() explicitly.

Example · JavaScript (SDK)
import { Attest } from "@attestinfra/sdk";

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

const pairId = "pr_1b7c3e9d5a2f4c80";
const event = {
  pairId,
  eventType: "invoice.sent",
  action: "send",
  evidence: { invoiceId: "inv_5520" },
};
await attest.witnessAssembly(event);

// After a restart: inspect without running anything.
const pending = await attest.resumeWitness(pairId);
console.log(pending.lifecycle, pending.recoveryStatus);

// You confirmed the delivery happened and persisted its observation.
const done = await attest.resumeWitness(pairId, { deliveryObservation: event });
console.log(done.lifecycle, done.reconciliationStatus);
Output · Console
OPEN delivery_required
FINALIZED matched

getWitness() #

attest.getWitness(pairId) calls GET /v1/witness/{pairId} and returns the pair as stored. Reading never changes the pair.

Example · JavaScript (SDK)
const state = await attest.getWitness("pr_1b7c3e9d5a2f4c80");
console.log(state.lifecycle, state.assemblyObserved, state.deliveryObserved);

witnessAssembly() and witnessDelivery() #

These send one observation each to POST /v1/witness, for cases where assembly and delivery happen in different processes. The second argument overrides fields from the first: pairId, eventId, timestamp, source, destination, action, outcome, and evidence.

Each call resolves with the pair state plus accepted and duplicate. Neither call finalizes the pair.

Example · JavaScript (SDK)
// In the sending service
await attest.witnessAssembly(event, { destination: "payments" });

// In the receiving service
await attest.witnessDelivery(event, { source: "payments", outcome: "ok" });
await attest.finalizeWitness(event.pairId);

witness() #

attest.witness(event, operation) is shorthand for attest.prepareWitness(event).execute(operation).

SDK errors #

Every error extends AttestError and has a code. HTTP errors also have a status.

ClasscodeWhen
AttestValidationErrorVALIDATION_ERROR, WITNESS_INVALID_EVIDENCEInput failed a local check. Nothing was sent.
AttestAuthenticationErrorAUTHENTICATION_ERRORHTTP 401 or 403.
AttestServerErrorSERVER_ERROR, RATE_LIMIT_ERROR, or the server's witness codeAny other non-2xx response. For witness calls, code is the server's code when one is returned, for example WITNESS_CONFLICT.
AttestNetworkErrorNETWORK_ERROR, TIMEOUT_ERRORThe request failed or exceeded timeout.
AttestResponseErrorMALFORMED_RESPONSEThe response body was not the expected JSON.
AttestWitnessAssemblyExistsErrorWITNESS_ASSEMBLY_EXISTSexecute found the assembly already recorded and did not run your operation. Has pairId.
AttestWitnessDeliveryErrorWITNESS_DELIVERY_ERRORYour operation ran, then delivery or finalize failed. Has pairId and deliveryObservation.
AttestErrorWITNESS_ASSEMBLY_REJECTEDThe assembly response did not report accepted: true.