Documentation
Build a test lookup service with Trust Decisions, Agent Attribution, and Agent Paid Access.
On this page
- Set up a test lookup service
- 1. Screen a signup before granting access
- Complete step-up when challenged
- Report a real signup outcome
- 2. Recognize an agent at two sites
- Check recognition and revocation
- 3. Configure a seller and quote a lookup
- Complete test checkout and check capture
- Authorize, reserve, and fulfill one lookup
- Verify the result and rehearse failures
Imagine an API that sells one company lookup for $1. You will screen a signup before granting access, recognize the same enrolled agent at two sites, then sell and fulfill one lookup in Stripe test mode. You can run each checkpoint independently.
In the dashboard, select Test and create scoped API keys. Keep every bearer key on the server. Use the default Chitmark API URL or set CHITMARK_API_BASE_URL to your deployment. For Attribution and Paid Access, use two separate test workspaces. One can be the enrolling workspace and seller, and the other can be the second recipient and buyer.
| Checkpoint | Credential or setup |
|---|---|
| Trust Decisions | A test key with verify:write, challenge:write, and feedback:write. |
| Agent Attribution | An enrolled principal, an Ed25519 agent key, an attribution:write key in the enrolling workspace, and a separate attribution:read key at each recipient. |
| Agent Paid Access | A Stripe test-connected seller with an enabled $1 API-call resource, a buyer key with charge:buy, a buyer owner key with charge:budget, and a seller key with charge:fulfill. |
Run the TypeScript snippets on Node.js 24 or later. The Python SDK can run the same requests on Python 3.10 or later. Install the package for your runtime.
npm install @chitmark/sdkSet CHITMARK_TRUST_KEY to your test key. Run this from your backend or a test script. In your application, generate the session on the server and persist it with the pending signup. Reuse the session and idempotency key for retries of this verify request. Use a fresh session for a new signup.
import { randomUUID } from "node:crypto";
import { Chitmark, isEligibleAllow } from "@chitmark/sdk";
const trust = new Chitmark({
apiKey: process.env.CHITMARK_TRUST_KEY!,
baseUrl: process.env.CHITMARK_API_BASE_URL,
});
const session = randomUUID();
const signup = {
action: "signup" as const,
session,
surface: "app.example.com/signup",
subject: { email: "[email protected]" },
};
let verdict = await trust.verify({ ...signup, idempotencyKey: "signup:" + session });
console.log({ session, eventId: verdict.eventId, decision: verdict.decision,
degraded: verdict.degraded,
canProceed: isEligibleAllow(verdict) && verdict.enforcementMode === "enforce" });Persist each returned eventId on the pending attempt before branching. For a non-degraded challenge, issue step-up with eventId and session. Branch on the returned method, collect its proof, and complete using the same eventId and session plus challengeId and proof. The challenge reference shows issue and completion requests for the supported methods.
The proof-of-work snippets below are for a test script. In your integration, let the requester solve the proof away from the server request thread. If the proof expires or fails, hold the signup and return to step-up.
After a successful completion, verify again with the original signup inputs, context: { challengeId }, and a new idempotency key for this verify step. Store the new verdict's eventId. A deny stops the signup. A degraded verdict or unavailable service holds it until you can verify again. Create the account only on an explicit, non-degraded allow in enforce mode.
// Continue the test signup script. Production clients solve their own proof.
import { createHash } from "node:crypto";
if (verdict.decision === "challenge" && !verdict.degraded) {
const issued = await trust.challenge({
eventId: verdict.eventId, session, prefer: ["proof_of_work"],
});
if (issued.instructions.type !== "pow") throw new Error("Use the issued method");
const { difficulty, seed } = issued.instructions;
const prefix = "0".repeat(difficulty);
const deadline = Math.min(Date.parse(issued.expiresAt), Date.now() + 15_000);
let nonce: string | undefined;
for (let i = 0; Date.now() < deadline; i += 1) {
const digest = createHash("sha256")
.update([issued.challengeId, seed, i].join(":"))
.digest("hex");
if (digest.startsWith(prefix)) {
nonce = String(i);
break;
}
}
if (nonce === undefined) throw new Error("Keep the signup pending");
const cleared = await trust.completeChallenge({
eventId: verdict.eventId, session, challengeId: issued.challengeId,
proof: { type: "proof_of_work", nonce },
});
if (!cleared.ok) throw new Error("Step-up incomplete");
verdict = await trust.verify({
...signup,
context: { challengeId: issued.challengeId },
idempotencyKey: "signup-cleared:" + issued.challengeId,
});
// Persist the new event ID before enforcing this decision.
console.log({ eventId: verdict.eventId,
canProceed: isEligibleAllow(verdict) && verdict.enforcementMode === "enforce" });
}Once your test signup actually converts, report converted against the stored event that authorized the signup. Use a stable idempotency key for this outcome. The checkpoint is a verify result with an eventId and, after conversion, feedback returning ok: true.
// In your conversion handler, use the eventId persisted on the account.
await trust.feedback({
eventId,
outcome: "converted",
idempotencyKey: "converted:" + eventId,
});Enroll one principal under Agent Attribution → Enrollment and bind a separate Ed25519 agent key once. Follow Bind the agent key for the signed request and keep the returned agent ID for revocation. Use two HTTPS origins under different workspaces and a distinct test read key for each.
For Site A, have the agent sign a fresh proof for A's workspace, read key ID, and origin. Repeat for Site B with B's values and a new nonce. The default purpose is identity_attribution and the default data mode is hashed. Use the same enrolled agent key both times. The two site servers each use their own bearer credential to resolve the inbound request.
In your route handler, pass the inbound request directly. To try the SDK from a script, set CHITMARK_ATTRIBUTION_KEY, CHITMARK_SITE, and CHITMARK_AGENT_PROOF for the site you are testing. The last variable is the fresh JSON proof header value.
import { Chitmark } from "@chitmark/sdk";
const reader = new Chitmark({
apiKey: process.env.CHITMARK_ATTRIBUTION_KEY!,
baseUrl: process.env.CHITMARK_API_BASE_URL,
});
const request = new Request(process.env.CHITMARK_SITE!, {
headers: { "Chitmark-Agent-Proof": process.env.CHITMARK_AGENT_PROOF! },
});
const result = await reader.attribution.resolve({ request });
console.log(result.identity, result.principal.status);Both sites should return identity.match: verified_agent_account and scope: site. Compare the two subject_id values. They should differ. Without a disclosure grant, expect principal.status: withheld and email: null. Your own access policy still controls the lookup.
Repeat using a request without the proof header or send A's proof to B. Without separate site session evidence, expect identity.recognized: false. A site session can establish recurrence at one site. It carries no network identity or principal claims.
To remove the test binding, call writer.attribution.revokeLink(agentId) in TypeScript or writer.attribution.revoke_link(agent_id) in Python using the enrolling workspace's attribution:write key. Fresh proofs from the revoked agent should then resolve as unknown at both sites. See the Attribution quickstart for site links and historical observations.
In the seller workspace, select Test and complete test payment setup. Under Resources, create an enabled API-call resource priced at 100 USD cents for one call. Save its ID and both workspace IDs. Test checkout uses the seller's test payment account.
Use the same server-side values throughout the purchase. Save the lookup inputs, operation ID and digest with the purchase before handing off to checkout. Keep the intent and each mutation's idempotency key stable across retries. A retry uses the same key and exact payload. The examples below use TypeScript. In Python, pass the same request dictionaries to client.charge(...) and read the same response fields.
import { createHash } from "node:crypto";
import { Chitmark } from "@chitmark/sdk";
function api(name: string) {
const apiKey = process.env[name];
if (!apiKey?.startsWith("ck_test_")) throw new Error(name + " requires a Test key");
return new Chitmark({ apiKey, baseUrl: process.env.CHITMARK_API_BASE_URL });
}
const owner = api("CHITMARK_BUYER_BUDGET_KEY"); // charge:budget
const buyer = api("CHITMARK_BUYER_KEY"); // charge:buy
const sellerTenantId = process.env.CHITMARK_SELLER_ID!;
const buyerTenantId = process.env.CHITMARK_BUYER_ID!;
const resourceId = process.env.CHITMARK_RESOURCE_ID!;
// Assign and persist this ID in your application before the first request.
const operationId = process.env.CHITMARK_OPERATION_ID!;
const lookup = "acme";
const operationDigest = createHash("sha256")
.update(JSON.stringify([operationId, sellerTenantId, buyerTenantId, resourceId, lookup]))
.digest("hex");
await owner.charge({
operation: "budget", sellerTenantId, buyerTenantId, limit: 500,
idempotencyKey: "budget:" + operationId,
});
const quoted = await buyer.charge({
operation: "quote", sellerTenantId, resourceId, quantity: 1, operationDigest,
idempotencyKey: "quote:" + operationId,
});
if (!("purchase" in quoted)) throw new Error("Quote unavailable");
const { purchaseId, quote } = quoted.purchase;
if (quote.amount !== 100 || quote.currency !== "usd") throw new Error("Unexpected terms");
const accepted = await buyer.charge({
operation: "accept", sellerTenantId, purchaseId, quoteVersion: quote.version,
maxAmount: quote.amount, currency: quote.currency,
idempotencyKey: "accept:" + purchaseId,
});
if (!("purchase" in accepted)) throw new Error("Purchase unavailable");
// Save the purchase ID and digest in your application.
console.log({ purchaseId, operationDigest, next: accepted.next });
if (accepted.next === "pay" && accepted.purchase.checkoutUrl) {
// Test script only. In your app, pass the URL to the authorized payer.
console.log(accepted.purchase.checkoutUrl);
}Open the returned purchase.checkoutUrl for the authorized test payer and complete checkout. If next is wait, read status for the same purchase instead of starting another. Use status to recover the current checkout URL or payment state after an interruption.
After checkout, run the status request with the same buyer key and purchase ID. Keep waiting while payment is pending or authorized. Continue only when payment.state is settled. A checkout redirect or a Trust Decisions allow carries no payment authorization.
const status = await buyer.charge({ operation: "status", sellerTenantId, purchaseId });
if (!("purchase" in status)) throw new Error("Purchase unavailable");
if (status.next === "pay" && status.purchase.checkoutUrl) {
console.log(status.purchase.checkoutUrl); // Test script only
}
if (status.purchase.payment.state !== "settled") {
throw new Error("Hold fulfillment until payment is settled");
}Run fulfillment on the seller backend using CHITMARK_SELLER_FULFILL_KEY. Load the saved purchase and operation digest. Check that the authenticated buyer may access this lookup under your own policy. If a Trust Decisions verdict justified this specific permission, include its stored eventId when you record permission.
Persist a unique execution ID before requesting the reservation. The example uses an application-provided deliverOnce function for the actual lookup. Implement it so the output or business effect and the execution ID commit together. Reuse the ID on retry. If you lose the reserve response, read the current purchase and reconcile instead of executing without a fresh granted lease.
const seller = api("CHITMARK_SELLER_FULFILL_KEY"); // charge:fulfill
// Application values loaded from durable state after checking local policy.
if (!localPermission) throw new Error("Lookup not authorized");
await seller.charge({
operation: "permission", sellerTenantId, purchaseId, allowed: true,
idempotencyKey: "permission:" + executionId,
});
const reserved = await seller.charge({
operation: "reserve", sellerTenantId, purchaseId, executionId, operationDigest, units: 1,
idempotencyKey: "reserve:" + executionId,
});
if (
!("purchase" in reserved) ||
reserved.purchase.payment.state !== "settled" ||
!reserved.purchase.permission.allowed ||
!reserved.reservation?.granted ||
reserved.reservation.executionId !== executionId ||
Date.now() >= reserved.reservation.leaseUntil
) {
throw new Error("Hold delivery");
}
await deliverOnce({ purchaseId, executionId, lookup, leaseUntil: reserved.reservation.leaseUntil });
await seller.charge({
operation: "usage", sellerTenantId, purchaseId, executionId,
sequence: 1, usedUnits: 1, result: "delivered",
idempotencyKey: "usage:" + executionId + ":1",
});Read the purchase again with the buyer key, or open Agent Paid Access → Purchases in the seller workspace. The execution should show state: delivered and usedUnits: 1. If usage reporting fails after delivery, retry the same usage payload. If delivery is uncertain, keep the units reserved and reconcile before trying again.
Try the three hold paths in Test. Keep a challenged signup pending, resolve an agent request with no proof, and attempt to fulfill before payment settles. Confirm that your application withholds the action or resource at the right boundary.
Trust Decisions quickstart · Network proof integration · Agent Paid Access quickstart · Charge API reference