Tšepo lets your exchange accept payments from AI agents and know who each agent works for. Every Tšepo agent holds a credential on the XRP Ledger, issued by Tšepo, that proves its spending rules.
In three steps on your own XRP Ledger account, you set up a deposit address that accepts only those agents. Each step below shows the code of a script that runs it on Testnet.
You need Node.js 24 with the xrpl and zod packages. The script creates a Testnet account for you from the faucet.
- Tšepo issuer on Testnet
- rpS8npJd8eyU7jr1pn2owuUxd5vnM2J66C
- Credential type
- AGENT_MANDATE
- The sample exchange’s agent deposit address
- rw5QcoNLQM9Zn1GN79GfB6DM5qsX4RxfDZ
Try it yourself.
Clone the repository, run npm install, then run the command below. It needs no keys of yours and no access code.
The script is examples/exchange-integration.ts (opens in a new tab). It makes its keys in memory, prints only addresses, hashes and results, and stops at any result other than tesSUCCESS. Your output looks like this, with different addresses and hashes.
npm run example:integrationTšepo exchange integration on the XRP Ledger Testnet
Step 0. Create a test exchange account
funded rBwftNZXYXeUZm41E7dWwthf7nPzdDoi5Z from the Testnet faucet
Step 1. Turn on credential-based Deposit Authorization
submitting AccountSet 6BEB0D24...0A69B4
tesSUCCESS
submitting DepositPreauth 19D47B89...3F57A1
tesSUCCESS
Check: an account without a Tšepo credential pays 1 XRP to the deposit address
submitting Payment 281057EC...58831C
rejected with tecNO_PERMISSION, as expected
Step 2. Check an agent’s Tšepo credential
rMQqusFUcxkKhbETdS7nMF4ELhJ9QciiPp: Verified. Rules fingerprint sha256:7506c19b...179b52
rwAppV9jGbEv5tfmp1Tz1629uzrF5E77a6: Not verified, no Tšepo credential
Step 3. Match the Travel Rule details by fingerprint
payment F862AD64...786800: matched. The InvoiceID is the fingerprint of the details, and the sender, the deposit address and the rules agree.
Done. Every step passed.Before you start
Name Tšepo, and submit every transaction safely.
The first two lines name the Tšepo issuer and the credential type. Your exchange trusts credentials from this issuer only.
Every transaction goes through one function. It signs locally, lets autofill set the fee and sequence, records the hash before it submits, and stops at any result other than tesSUCCESS. Never retry a failed result blindly.
// Tšepo's credential issuer on Testnet, as the Integrate page publishes it.
const TSEPO_ISSUER = 'rpS8npJd8eyU7jr1pn2owuUxd5vnM2J66C';
// The credential type Tšepo issues to agents, hex-encoded as the ledger stores it.
const AGENT_MANDATE = convertStringToHex('AGENT_MANDATE');const SubmitResultSchema = z.object({ result: z.object({ meta: z.object({ TransactionResult: z.string() }).loose() }).loose() });
/**
* Signs locally and submits one transaction. autofill sets Fee, Sequence and
* LastLedgerSequence; the hash is recorded before anything is sent; and any
* result other than tesSUCCESS stops the script instead of being retried.
*/
async function submit(client: Client, wallet: Wallet, transaction: SubmittableTransaction): Promise<string> {
const signed = wallet.sign(await client.autofill(transaction));
console.log(` submitting ${transaction.TransactionType} ${signed.hash}`);
const { result } = SubmitResultSchema.parse(await client.submitAndWait(signed.tx_blob));
const code = result.meta.TransactionResult;
if (code !== 'tesSUCCESS') throw new Error(`${transaction.TransactionType} ended with ${code}, so the script stopped.`);
console.log(` ${code}`);
return signed.hash;
}Step 1 of 3
Accept payments only from Tšepo agents.
Make one address your and turn on Deposit Authorization for it. The XRP Ledger then rejects every payment to it, except from senders that present an accepted AGENT_MANDATE credential from Tšepo.
The script then checks it: a new account with no credential sends 1 XRP to the deposit address. The ledger itself rejects the payment with tecNO_PERMISSION, so it never reaches your account.
/** Only senders that present an accepted AGENT_MANDATE credential from Tšepo can pay this address. */
async function acceptOnlyTsepoAgents(client: Client, exchange: Wallet): Promise<void> {
// Deposit Authorization: the ledger rejects every payment that is not preauthorised.
await submit(client, exchange, { TransactionType: 'AccountSet', Account: exchange.address, SetFlag: AccountSetAsfFlags.asfDepositAuth });
// Preauthorise any sender that holds an accepted AGENT_MANDATE credential from Tšepo.
await submit(client, exchange, {
TransactionType: 'DepositPreauth',
Account: exchange.address,
AuthorizeCredentials: [{ Credential: { Issuer: TSEPO_ISSUER, CredentialType: AGENT_MANDATE } }],
});
}/** A sender without a credential tries to pay: the ledger itself must reject it with tecNO_PERMISSION. */
async function expectRejected(client: Client, sender: Wallet, depositAddress: string): Promise<string> {
const signed = sender.sign(await client.autofill({ TransactionType: 'Payment', Account: sender.address, Destination: depositAddress, Amount: xrpToDrops('1') }));
console.log(` submitting Payment ${signed.hash}`);
const { result } = SubmitResultSchema.parse(await client.submitAndWait(signed.tx_blob));
return result.meta.TransactionResult;
}Step 2 of 3
Check the agent’s Tšepo credential.
Before you credit a deposit, read the sender’s credential from the validated ledger. It is Verified only when Tšepo issued it, the agent accepted it and it has not expired.
Its URI holds the fingerprint of the agent’s spending rules, never personal data. Keep the fingerprint for step 3. In the script, Lesedi’s agent is Verified and a new account is Not verified. You can also check any address on Verify an agent.
const CredentialsSchema = z.object({
result: z.object({
account_objects: z.array(
z.object({ Issuer: z.string(), CredentialType: z.string(), Flags: z.number(), Expiration: z.number().optional(), URI: z.string().optional() }).loose(),
),
}),
});
const ACCEPTED = 0x00010000; // lsfAccepted: the agent accepted the credential
type AgentCheck = { verified: true; rulesFingerprint: string } | { verified: false; reason: string };
/** Reads the agent's Tšepo credential from the validated ledger. It counts only when Tšepo issued it, the agent accepted it and it has not expired. */
async function checkAgent(client: Client, agentAddress: string): Promise<AgentCheck> {
const response = await client.request({ command: 'account_objects', account: agentAddress, type: 'credential', ledger_index: 'validated' });
const credential = CredentialsSchema.parse(response).result.account_objects.find(
(entry) => entry.Issuer === TSEPO_ISSUER && entry.CredentialType === AGENT_MANDATE,
);
if (credential === undefined) return { verified: false, reason: 'no Tšepo credential' };
if ((credential.Flags & ACCEPTED) === 0) return { verified: false, reason: 'not accepted by the agent' };
if (credential.Expiration === undefined || credential.Expiration <= unixTimeToRippleTime(Date.now())) return { verified: false, reason: 'expired' };
if (credential.URI === undefined) return { verified: false, reason: 'no rules fingerprint' };
// The URI holds the fingerprint of the agent's spending rules, never personal data.
return { verified: true, rulesFingerprint: convertHexToString(credential.URI) };
}Step 3 of 3
Match each payment to its Travel Rule details.
Before each payment, the agent sends you its details off the ledger, as FIC Directive 9 requires: the originator, the beneficiary, the amount, the purpose and the agent’s spending rules.
The payment’s InvoiceID is the SHA-256 fingerprint of those details in canonical JSON, so you can match them exactly. In this sandbox, the sample exchange receives the details inside Tšepo, and the script reads a real set from examples/sample-travel-rule-details.json (opens in a new tab).
const TravelRuleDetailsSchema = z.object({
beneficiary: z.object({ ledgerAddress: z.string() }).loose(),
agent: z.object({ ledgerAddress: z.string(), mandateFingerprint: z.string() }).loose(),
}).loose();
type Json = string | number | boolean | null | Json[] | { [key: string]: Json };
/** JSON with object keys sorted at every level, so the same details always give the same text. */
function canonicalJson(value: Json): string {
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(',')}]`;
if (value !== null && typeof value === 'object') {
const members = Object.entries(value)
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
.map(([key, member]) => `${JSON.stringify(key)}:${canonicalJson(member)}`);
return `{${members.join(',')}}`;
}
return JSON.stringify(value);
}
const PaymentSchema = z.object({
result: z.object({ tx_json: z.object({ Account: z.string(), Destination: z.string(), InvoiceID: z.string().optional() }).loose() }).loose(),
});
/**
* Matches a payment to the Travel Rule details the agent sent before it. The
* payment's InvoiceID is the SHA-256 fingerprint of those details, so a match
* proves the payment carries exactly these details.
*/
async function matchTravelRule(client: Client, paymentHash: string, details: Json, depositAddress: string, rulesFingerprint: string): Promise<string[]> {
const payment = PaymentSchema.parse(await client.request({ command: 'tx', transaction: paymentHash })).result.tx_json;
const facts = TravelRuleDetailsSchema.parse(details);
const expected = createHash('sha256').update(canonicalJson(details)).digest('hex').toUpperCase();
const problems: string[] = [];
if (payment.InvoiceID !== expected) problems.push('the InvoiceID is not the fingerprint of these details');
if (payment.Destination !== depositAddress || facts.beneficiary.ledgerAddress !== depositAddress) problems.push('it was not paid to this deposit address');
if (payment.Account !== facts.agent.ledgerAddress) problems.push('it was sent by a different account');
if (facts.agent.mandateFingerprint !== rulesFingerprint) problems.push('the rules do not match the agent credential');
return problems; // Hold the payment for review unless this list is empty.
}What to do with each result.
- When the agent is Verified and the payment matches its details, credit the deposit.
- When the agent is Not verified, or any match check fails, hold the deposit for review and do not credit it.
- When the details arrived after the payment, or never arrived, hold the deposit for review as well.
- A payment the ledger rejected never reaches your account, so there is nothing to credit or return.
