Spend permissions

Let an app's key pay for services from a person's account, within limits every XE wallet shows the same way and XE's nodes enforce. Grants, delegates, limits, expiry and revoking.

A spend permission lets an app pay for services from a person's XE account without asking each time. The app holds a key of its own, K. The person approves one text in their wallet; the wallet turns it into a grant on their account that makes K a delegate with limits. From then on, K signs service requests that the person's account pays for, and every node checks each one against the grant. The person can end it at any time.

ERC-7715 (wallet_grantPermissions) is the model. The difference is where the limits live: on XE they are part of the account's chain and the nodes enforce them, with no contract in between.

#The permission text

The wallet shows, signs and enforces one plain text, xe-permission:v1. The app writes it; the wallet builds the grant from it and from nothing else.

text
xe-permission:v1issuer your.appid 4b2nrancre4phmu46bkdhjs6owname Your Appnetwork xe-sim-0002key 9a41…(64 hex)asset XEtotal 2000000period 86400 1000000per-request 250000scope kinds llmgrade zero_retentionexpires 1795000000

Lines are fixed, in this order, separated by LF, in ASCII, at most 1024 bytes in all. Anything else under this prefix is refused.

LineMeaning
issuerYour site's host. It must equal the host of the origin that asks, or the wallet refuses with wrong-site
id26 characters of lower-case base32 (a-z, 2-7), random
nameYour app's name, 1 to 64 printable characters. The wallet shows it as your claim, not as a fact
networkThe network id, xe-sim-0002 for XE Sim Interop
keyK's public key, 64 lower-case hex. The app keeps the private half
assetXE or XUSD
totalThe most K may spend over the permission's whole life, in micro-units
period-, or seconds and an amount: at most that much in each period. A period is 60 seconds to 366 days, and its amount lies between per-request and total
per-requestThe most one request may hold, in micro-units
scopekinds and up to 8 service kinds (llm, vision, embedding, judgment, speech, web_check, zk_proof, pipeline, feed), or services and up to 11 service ids
gradeOptional. The least privacy grade a provider must hold: standard, zero_retention or private. See Private inference
expiresUnix seconds. After it, K can't spend

#Two assets

One permission can cover XE and XUSD, so the app can pay with whatever the person holds. The five lines key, asset, total, period and per-request then appear twice, XE first, each asset with its own key and its own limits. The wallet shows both in one review, makes one grant per asset and ends both on revoke. A wallet that accepts two assets says so in xe_getInfo: permissions: { assets: ["XE", "XUSD"], multi: true }.

#Writing the text

typescript
function permissionText(p) {  const assets = [p, ...(p.more ?? [])].flatMap((a) => [    `key ${a.key}`,    `asset ${a.asset}`,    `total ${a.total}`,    `period ${a.period ? `${a.period.seconds} ${a.period.amount}` : "-"}`,    `per-request ${a.perRequest}`,  ]);  return [    "xe-permission:v1",    `issuer ${p.issuer}`,    `id ${p.id}`,    `name ${p.name}`,    `network ${p.network}`,    ...assets,    `scope ${"kinds" in p.scope ? `kinds ${p.scope.kinds.join(" ")}` : `services ${p.scope.services.join(" ")}`}`,    ...(p.grade ? [`grade ${p.grade}`] : []),    `expires ${p.expires}`,  ].join("\n");} const newId = () =>  Array.from(crypto.getRandomValues(new Uint8Array(26)), (b) => "abcdefghijklmnopqrstuvwxyz234567"[b & 31]).join(""); const text = permissionText({  issuer: location.host,  id: newId(),  name: "Your App",  network: "xe-sim-0002",  key: K, // 64 hex  asset: "XE",  total: 2_000_000,  period: { seconds: 86_400, amount: 1_000_000 }, // 1 XE a day  perRequest: 250_000,  scope: { kinds: ["llm"] },  grade: "zero_retention",  expires: Math.floor(Date.now() / 1000) + 30 * 86_400,});

The output is byte for byte what XE's kit (composePermission in @xe-network/protocol/permissions) and every wallet parse.

#Asking for it

FromHow
A web appXE Connect: connect with xe:permissions@2 in request, then grantPermissions(config, { network, key, permission, label })
A native appOne wallet visit by link, kind: "grant". See XE Connect for native apps
Wallets that only sign (Ledger, XE Vault, MetaMask's XE snap)grantPermissionsLocal in @xe-network/connect/permissions does in the page what a full wallet does: reads the network, builds the grant from the text, has the device sign it, then publishes and checks it
typescript
import { connect, grantPermissions } from "@xe-network/connect"; await connect(config, { request: ["xe:permissions@1", "xe:permissions@2"] });const grant = await grantPermissions(config, {  network: "xenet:xe-sim-0002",  key: K,  permission: text,  label: "Your App",});// grant: { id, proof, grantBlock, expiresAt, mode, payFrom, enforced, grants? }

A wallet without spend permissions answers 4200. Fall back to asking for approval of each request.

#What the person sees

Every XE wallet shows the same rows, from one function in XE's kit:

text
Let your.app pay for services from your account  It says it is    Your App  Pays for         AI inference  Up to            1 XE a day, 2 XE in all  Per request      at most 0.25 XE  Privacy grade    at least zero retention  Until            1 Nov, 13:00  Key              9a41…7c2e  Network          XE Sim InteropHold to approve

#How the network carries it

The wallet reads the network's features (GET /network/activations), never its name. XE Sim Interop runs delegate_services and delegate_periods, so permissions there are v2:

json
{  "type": "delegate_set",  "account": "<the person's account>",  "grant": {    "key": "<K>",    "permissions": ["services"],    "max_per_send": 250000,    "budget": 2000000,    "window": 2592000,    "expires_at": 1795000000000000000,    "services": { "kinds": ["llm"], "max_price": 250000, "min_grade": "zero_retention" },    "period": { "secs": 86400, "budget": 1000000 }  }}
TextGrantThe nodes check
per-requestmax_per_send, services.max_priceNo request holds more
totalbudget over window (the permission's remaining life)K never spends more in all
periodperiodK never spends more in one period
scopeservices.kinds or services.idsK pays only for those services
gradeservices.min_gradeOnly providers at that grade or higher are paid
expiresexpires_at (nanoseconds)Nothing is accepted from K after it

Requests are paid from the person's account (payFrom is their address), with K signing each service_request as a delegate. Unused holds and refunds go back to the person's account and to the budget.

On a network without delegate_services, a permission is v1: K gets its own spend account, topped up from the person's account within the grant, and the nodes enforce the amounts and expiry but not the scope or the grade. The result's mode, payFrom and enforced say which applies, so the app and the review never claim more than the network does.

#Checking a grant

Before an app relies on a grant, it reads it back from XE:

typescript
const NODE = "https://xe-sim-interop.enter-38b.workers.dev"; async function checkGrant({ owner, key, grantBlock, perRequest, total }) {  const block = await (await fetch(`${NODE}/blocks/${grantBlock}`)).json();  if (block.type !== "delegate_set" || block.account !== owner || block.grant.key !== key || !block.finalized)    throw new Error("The grant block isn't a final delegate_set for this key");  const { delegates } = await (await fetch(`${NODE}/accounts/${owner}/delegates`)).json();  const d = delegates.find((x) => x.key === key);  if (!d?.active) throw new Error("The key isn't an active delegate");  if (d.grant.max_per_send !== perRequest || d.grant.budget !== total)    throw new Error("The limits aren't the ones the person approved");  return { spent: d.spent, remaining: d.remaining, expiresAt: new Date(d.grant.expires_at / 1e6) };}

GET /accounts/{address}/delegates lists every key the account has granted:

json
{  "account": "024fef11…a175",  "delegates": [    {      "key": "19cc0fe7…15aa",      "asset": "XE",      "active": true,      "spent": 0,      "remaining": 1000000,      "set_at": 1792501992486000000,      "set_block": "6d650c6e…49ef",      "grant": { "key": "19cc0fe7…15aa", "permissions": ["services"], "max_per_send": 250000, "budget": 1000000, "window": 86400, "expires_at": 1792588392486000000, "services": { "kinds": ["llm"], "max_price": 250000 } },      "as_of": 1792568246111361183    }  ]}

Also check grant.proof: the account's signature over the exact text you sent, with the xe/message/v1 scheme.

#Paying with the key

Each paid request is a service_request that K signs as the person's delegate, holding at most per-request. The provider answers, the request is settled, and the rest of the hold comes back. XE's kit does this in one call, payPerRequest in @xe-network/protocol/metered: it checks the allowance first and stops before anything is sent when the grant doesn't cover the request, so the app can ask the person to raise or renew it. Every node refuses a request outside the grant, whatever the app does.

#Expiry

After expires, the nodes refuse anything K signs. Nothing needs to be revoked: ask the person for a new permission, with a new id. Pick an expiry that matches how long the app is useful without asking again.

#Revoking

The person can end a permission in two places:

  • In the wallet. Every XE wallet lists the permissions it granted, per site, under Connected apps, with what is left, the expiry and Revoke.
  • From the app. xe_revokePermissions with { address, network, id, key }, or kind: "revoke" by link from a native app.

Revoking signs a delegate_revoke block (one per key, so both keys of a two-asset permission) and an xe-permission-revoke:v1 text with the permission's id. It applies from the next block on. Before the app forgets a grant, it checks that GET /accounts/{address}/delegates no longer shows K as active.

The app should also drop K itself when the person signs out or deletes their account.