Skip to content
Integra Protocol

Refusals

Every refusal is a value with a code.

For AI agents: this page as Markdown, and llms.txt, the index of every page.

Failures are values. A function in this package whose type carries a refusal returns its result, or a refusal: a plain object that names what is wrong with its input. A status answers a state and its reason instead (Readers), and the writers that only encode a value you supply throw (What throws).

type Refusal = { refused: true; code: string };

A code is <namespace>/<reason>, such as core/slot-name, x402/link-not-https or svm/memo-not-lcp. The namespace is the entry point or rail that refused. The same reason means the same thing on every surface: link-not-https is always a link that is not https (any such link given to advertise or place, and a link of another scheme that a read finds, except card's, ACK's and AP2's, which give legal-context-malformed to every link that is not https), and legal-context-malformed is always a hash, link or agreement URL that does not read.

The refusal code reference lists every code with its meaning.

Checking a result

isRefusal(result) is how a caller tells a refusal from a result: it is true only for a refusal a copy of this package made, and false for every result, the hashes bound returns included. Every installed copy of the package recognises the refusals of every other, as when two installs serve one process. Test it before using a result:

import { , ,  } from "@integraledger/lcp";

const  = await ((), ["bind", {}], [["id", new ().("{}")]]);
if (()) {
  .(.);
} else {
  .(.);
}
core/slot-reserved

Where a refusal comes from

Only the package makes refusals. isRefusal, which the package's own entry points use as well, recognises a refusal by a mark the package sets on it, not by its members: a non-enumerable own property keyed by the registered symbol Symbol.for("@integraledger/lcp/refusal"). JSON carries no symbol, and a spread or a structuredClone copy holds no non-enumerable property, so a value read from JSON or copied is not a refusal, and a value you pass in is never returned to you as a refusal, whatever members it holds. JSON.stringify and canonicalJson write a refusal as its two members. A presented payment or credential that the package would otherwise hand back to you unchanged is refused as malformed when it carries a refused member: mpp/credential-malformed for an MPP credential, x402/payload-malformed for an x402 EIP-3009 payment and casper/payload-malformed for a Casper payment. unplaced, which gives back the option or challenge you pass or a copy of it without the pairing's carrier, and each placement, which gives back a copy of the seller's document with the carrier placed (advertise and advertiseBeforeCarrier on the x402, MPP, ACP, AP2 and UCP pairings, and MPP's and A2A's place), refuse a value that carries a refused member before they remove or place anything: with x402/option-malformed on x402 (for a document, when it or an option in its accepts carries one), with mpp/challenge-malformed on MPP (for a list of challenges, when any of them carries one), and elsewhere with the malformed code of what they are given: the pairing's option-malformed code for an option given to unplaced on the ACK, ACP, AP2, card and UCP pairings, and acp/session-malformed, ap2/jws-malformed, ucp/checkout-malformed or a2a/legal-context-malformed for the session, checkout payload, checkout or task a placement is given. Every other entry point reads a presented value only for the members its pairing defines, and returns either a value it built or its own refusal.

What throws

A writer encodes a value you supply, and its type carries no refusal: it throws a TypeError on an argument outside its type. In the core, hash rejects with one when its argument is not a Uint8Array: a Buffer or a Uint8Array from another realm is hashed, and a string, an array, an ArrayBuffer, another typed array or a Proxy is not. toLcpString, toLegalContext and toRawBytes throw when the hash is not 32 bytes, and toLegalContext also when the link is not an https URL. Their from… counterparts return null instead of throwing. agreementValue, which is asynchronous, rejects when the hash is not 32 bytes.

The rails' writers throw the same way (x402InvoiceId and svmDigest, which are asynchronous, reject):

  • on a hash that is not 32 bytes: ccdMemo and pltMemo, and mppInvoiceId and x402InvoiceId;
  • on a Hedera value outside its type: txIdText and txIdMirror (an id that is not an account shard.realm.num, a non-negative bigint seconds and nanos from 0 to 999,999,999), hederaChannelId (an address that is not 0x and 40 hex digits, a salt that is not a 32-byte hash, a chain id other than 295 and 296) and hederaVoucher (the same for the channel, and a cumulative that is not a bigint that fits a uint128);
  • on a field of the wrong type: encodeTronRaw, encodeProfileCall (a call decodeProfileCall would not give back), openInstructionData and channelVoucherMessage, and sessionProof on a null or missing argument or a channelId, payer or challengeId that is not a well-formed string, so that it never returns a message you did not write;
  • on bytes that are not a Uint8Array: extrinsicHash, stacksTxid, and svmDigest on a transaction whose message is not one;
  • on a network other than starknet:SN_MAIN and starknet:SN_SEPOLIA: chainIdFelt.

Every other function answers a caller's input with a value, never a throw: a refusal, a status answer, false or { complete: false } from a read, or, for unplaced, its argument itself when that is not an option.

Readers

The functions that read a rail (status, recover, fetchPresented) take a reader you supply, so the network calls are yours. status refuses nothing: it answers settled, pending, failed or unreadable, each with a reason, as the read-status profile states them. A reader that fails or times out is never a failed payment: a read that did not complete answers unreadable with the reason transport, and a later read can settle it. A reader that declares a network other than the one the reference names is never a failed payment either, and nothing is read through it: status answers unreadable with the reason chain-mismatch on every read, so no later read settles it, and recover refuses <namespace>/wrong-reader. A ref or reader that is not an object is answered with nothing read: status answers unreadable, and recover refuses with the code it gives a reader for another network. So does a recover given a ref whose transaction id is not in its rail's form, which can name no transaction. Check reader.network against the reference's network before you poll, and give every polling loop a deadline of its own.

Reads to repeat

A refusal from a read is a verdict or a read to repeat. readToRepeat(code) is true for a read to repeat: the answer rests on a read of the rail that may answer differently later, with nothing for you to change, so ask again later. The payment may already have moved, so do not ask the buyer to pay again. These are each reader's <rail>/unreadable (the reader failed, or answered out of its documented form) and <rail>/not-found (no landed transaction for the reference yet), and the codes of a transaction that is not final yet: casper/not-executed, ccd/not-finalized, xrpl/not-validated, evm/not-final (a revert, or a receipt without what the read looks for, above the reader's finalized mark), polkadot/not-final (an extrinsic not dispatched as the payment, in a block above the finalized height), stacks/not-final (a failure in a block fewer than two tenures below the tip), starknet/not-final (a revert, or no single matching transfer, in a pre-confirmed block), svm/not-final (a transaction the read at Solana's confirmed holds and the read at finalized does not, with an error or none) and tempo/not-final (as evm/not-final, on Tempo). The refusal code reference marks each of them.

Every other code is false. A verdict, such as evm/reverted, gives the same answer on every read. A call you must change before it can succeed gives the same answer too, so it is not a read to repeat: <rail>/wrong-reader (a reader for another network, or a ref the rail cannot read), <rail>/read-first (bound or reference on a push credential before fetchPresented has read it), a missing peer dependency, and malformed input. A code the package does not return is false, whatever its reason.

import {  } from "@integraledger/lcp";

const  = ["xrpl/not-validated", "tempo/not-final", "evm/unreadable", "evm/reverted", "evm/wrong-reader", "svm/read-first", "server/unreadable"];
for (const  of ) .(, ());
xrpl/not-validated true
tempo/not-final true
evm/unreadable true
evm/reverted false
evm/wrong-reader false
svm/read-first false
server/unreadable false

Next

Edit on GitHub

Last updated on

On this page