Documentation

Guides and reference for OutLayer verifiable compute and agent custody.

Docs navigation

On-chain Custody

On testnet now (https://testnet-api.outlayer.ai); on mainnet with the next release. Until then api.outlayer.ai answers 404 on every route below.

An agent with on-chain custody keeps its main balance in a wallet contract: a NEAR account that runs the two-key variant of the NEAR Intents wallet contract. The wallet contract executes a request only under two signatures: one by the agent’s own Ed25519 key and one by a key held in OutLayer’s Intel TDX enclave, which signs only an operation the owner’s policy allows.

Two modes of custody#

Every OutLayer wallet keeps its keys in the enclave and signs within its owner’s policy: that is TEE custody, described on Agent Custody, and it is what an agent gets when it registers. On-chain custody is a second place for an agent’s funds, added to the same wallet by its owner. An agent with on-chain custody uses both: the wallet contract holds the main balance, and the OutLayer wallet is its working account.

TEE custodyOn-chain custody
Where the balance liesthe wallet’s own addresses: NEAR, NEAR Intents, EVM, Solana, a confidential balance, venue accountsthe wallet contract: a NEAR account, with its NEAR and its balance inside NEAR Intents
Who signs a movethe enclave, within the owner’s policythe agent’s key and the enclave’s key; the wallet contract verifies both
What the agent holdsan API key; no private keyits own Ed25519 key, and the API key of its working account
Cost of a movethe operation’s own cost; nothing is added per operationone NEAR transaction to the wallet contract per move, with its gas, paid by the working account
Operationsevery wallet operation: transfers, calls, swaps, withdrawals, limit orders, confidential intents, signing on NEAR, EVM and Solana, connectorsNEAR transfer, contract call, transfer inside NEAR Intents, swap and withdrawal to another chain through 1Click, withdrawal to NEAR
What the owner does at setupnothing is required; a policy and the registration for the owner’s exit are the owner’s choiceregisters for the owner’s exit, installs the wallet contract on an account, stores a policy
Leavingthe owner’s exit yields the wallet’s keysthe owner’s exit yields the enclave’s key of the wallet contract; the owner derives the agent’s key with their own signature and signs for both sides

What on-chain custody adds

  • The chain itself requires both signatures for anything to leave the wallet contract.
  • The policy engine cannot move those funds by itself: the enclave’s key is one of two.
  • The owner can leave and sign for both sides, with no OutLayer service.

What it costs

  • A NEAR transaction and its gas for every move.
  • A signature made on the agent’s side, with a key the agent keeps.
  • A setup by the owner.
  • A narrower set of operations; the rest run from the working account.

Choose on-chain custody when the owner wants that rule held by the chain for the agent’s main balance. An agent that needs every operation, no key of its own and no transaction per operation uses its OutLayer wallet alone.

On-chain custody is for a wallet with an owner: an account registered for the owner’s exit. Operations inside NEAR Intents (intents_transfer, withdraw, swap, cross_chain_withdraw) work on mainnet only.

Who holds what#

PartyHoldsAlone it can
Agentits Ed25519 key: it signs the agent’s requests to the API and the agent’s half of every movemove nothing
Enclave (Intel TDX)nothing at rest; it derives its key for a wallet contract when it signsmove nothing out of the wallet contract
Owner accountthe right to store the policy, approve, freeze and start an exitmove nothing out of the wallet contract before an exit completes
Wallet contractthe agent’s main balance; the pair of public keys in its statenothing: it executes a request that carries both signatures
The account’s own NEAR access keysone key of the owner’s by default; none, if the owner removed them at setupeverything on the account, past both signatures and past the policy
The agent’s OutLayer wallet (working account)a key in the enclave, as every OutLayer walletrelay a transaction and pay its gas; hold what the agent took out to work with
  • The enclave’s key is derived from the owner’s master and the wallet’s id when the enclave signs. Nothing per wallet is stored, and the key leaves with the owner’s exit.
  • The agent’s key is derived from one signature of the owner’s own key over a fixed message that names the owner account and the wallet. The owner’s wallet makes the same signature again on request, so the key needs no backup. Whoever is given that signature holds the agent’s key: it is signed on app.outlayer.ai only.
  • The wallet contract has no extension and takes no other signer. The enclave reads the account’s code hash, its pair of keys and its extensions from the chain before every signature.

Set it up#

The agent opens a setup and hands its owner a link. The owner finishes it on the setup page, which opens from that link. The agent then collects its account and its key.

1. The agent opens a setup

import { openSetup, collectSetup } from '@outlayer/sdk';

const options = { apiKey: process.env.OUTLAYER_API_KEY! }; // the wallet's API key

const setup = await openSetup(options);
// setup.url       → the link for the owner: https://app.outlayer.ai/wallet/custody#setup=…
// setup.expiresAt → the link works for 24 hours
// setup.key       → a one-time key; keep it in memory until the setup is collected

The wallet has to have an owner. Opening a setup again ends the earlier link. The link ends when the setup is finished. Whoever holds it can name this wallet’s wallet contract once, and only as the owner account or a sub-account of it; an account is taken only when its pair of keys on chain holds this wallet’s enclave key.

2. The owner finishes it

  1. Connects the owner account. The page shows the owner, the agent’s OutLayer wallet, the enclave’s key and the network.
  2. Chooses the agent’s account: a sub-account of theirs created for the agent with 0.5 NEAR for its storage (the page offers agent.<owner>), or the owner account itself.
  3. For a sub-account, chooses what happens to the account’s own keys (below).
  4. Signs one message. The page turns the signature into the agent’s key; the signature is not sent anywhere.
  5. Installs the wallet contract. The owner’s wallet signs one plain transaction: the creation of the sub-account, or one key added to the owner’s own account for this step alone. The page then points the account at the published build by its code hash (no code is uploaded), initialises it with the pair of keys and removes its own key.
  6. Hands the agent its key, sealed to the agent’s one-time key. OutLayer carries the sealed key and cannot open it.
  7. Stores a policy for the wallet in Wallets. The enclave signs for a wallet contract only under a policy its owner stored.

A NEAR account’s own access key acts on the account directly: it moves the balance and replaces the code with no signature of the agent or of the enclave, and no policy applies to it. For a sub-account the owner chooses:

ChoiceWhat it means
Keep the owner’s key on it (the default)The owner acts on the account at any time with their own wallet. Whoever holds that key moves everything on the account at once, and no policy applies to it.
Remove every key from itNothing moves without the agent’s signature and the enclave’s. The owner alone acts on it only through the owner’s exit, after its window. It cannot be undone.

With the owner account itself as the agent’s account, the owner’s key stays on it. While the owner holds a key of the account, the setup is undone from the owner’s own wallet: another contract deployed on the account, or the account deleted.

An agent on the owner’s own account acts as that account toward every contract its policy lets it call: what the account may do there, a vote in a DAO included, the agent does in its name. Calls to OutLayer’s own contracts are refused, so the agent cannot store the policy it is held to.

A key registered for an account in NEAR Intents is an access key for what the account holds there: it signs intents for the account with no signature of the agent or of the enclave. A sub-account the setup creates has none. An owner account that has used NEAR Intents has its own, as it has its NEAR key.

3. The agent collects its account and its key

const collected = await collectSetup(options, setup.key);
if (collected === null) {
  // the owner has not finished; ask again later
} else {
  const { account, key, teePublicKey } = collected;
  // account      → the wallet contract's account: the agent's address for its main balance
  // key          → an AgentKey: it signs the agent's requests and its half of every move
  // teePublicKey → the enclave's key in the contract's pair: its half is verified against it
}

collectSetup opens the sealed key and refuses one whose public key is not the agent’s key in the contract’s pair. The key is the agent’s own secret. AgentKey.fromSeed(seed) builds the same key from its 32-byte seed.

Run an operation#

The agent asks for an operation in the words every wallet uses. The enclave judges it by the owner’s policy and, if it passes, builds the wallet contract’s request and signs its half. The agent checks that the request is the operation it asked for, signs its half last, and the working account relays both to the wallet contract and pays the gas.

import { WalletContract } from '@outlayer/sdk';

const contract = new WalletContract({ account, key, teePublicKey });

const op = { kind: 'transfer', to: 'bob.near', amount: '1000000000000000000000000' } as const;
const state = await contract.run('pay-1', op); // 'pay-1' is the agent's own id of the operation

if (state.status === 'pending_approval') {
  // The policy asks for approvers: they vote on state.approval_id.
  // An approval starts nothing. After they voted, ask again under the same id:
  await contract.run('pay-1', op);
}
  • The id is the agent’s idempotency key: 1 to 64 letters, digits, - and _. Asking again under the same id continues the same operation; the same id with another operation is refused.
  • The agent signs last, and checks first. run signs only a request that is the operation that was asked for, from this wallet contract: the receiver, the method, the arguments and the amounts. It verifies the enclave’s half against teePublicKey, and signs one request under an id. A refused or a waiting operation leaves no half of a move anywhere.
  • The operation routes take no API key. Each request is signed by the agent’s key. ask, relay and get are the steps of run, for an agent that drives them itself.
  • A refusal is a CustodyError: one of the API’s, with its code and status (policy_denied, wallet_frozen, wallet_busy, below_min_amount_out, …), or one of the client’s own checks, in which case nothing was signed.

Operations and statuses#

Amounts are decimal strings in the smallest unit. A token is its id inside NEAR Intents (nep141:<account>).

kindFieldsWhat it does
transferto, amountSends NEAR from the wallet contract
callto, method, args_base64, gas, depositA function call from the wallet contract, with at most 250 Tgas
intents_transferto, amount, tokenA token to another account inside NEAR Intents
withdrawto, amount, tokenA NEP-141 token out of NEAR Intents to a NEAR account
swaptoken_in, amount_in, token_out, min_outA swap through 1Click; the output arrives in the wallet contract’s balance inside NEAR Intents
cross_chain_withdrawto, amount, token, chainA withdrawal to another chain through 1Click; a refund arrives in the wallet contract’s balance inside NEAR Intents

A call to a NEAR Intents contract, to the keystore DAO contract or to the OutLayer contract, and a call of a method whose name starts with w_execute_, are refused. For a swap and a withdrawal to another chain the state carries quote, what 1Click quoted; the quote waits ten minutes for its input, and an input that arrives later is returned by 1Click to the wallet contract.

statusMeaningWhat the agent does
pending_approvalThe policy asks for approvers; approval_id names the voteWait, then call run again with the same id and the same operation
awaiting_signaturePrepared and counted; the request and the enclave’s half are presentrun checks the request, signs and relays; with ask, call relay
relayedThe transaction was sent and its outcome is not recordedRead it with get(id); the read settles it
successThe request executed on chain. For a swap or a withdrawal to another chain the input reached 1Click; route_status on a read follows the route—
failedThe chain refused; result carries its failureRead the failure; the same thing again is another operation under another id
closedEnded with nothing sent, for reason: the vote was rejected or expired, an approval was not used within its 24 hours, a prepared request was not relayed within ten minutes, its transaction never reached the chain in that time, or the node refused it three timesRead the reason; the same thing again is another operation under another id

Approvals#

  • The policy’s approval rules apply to a wallet contract’s operation as they do to the same kind of operation of any wallet. An operation that needs approvers is answered pending_approval with approval_id; the vote lives 24 hours, and the agent asks again within them or the operation is closed.
  • The policy’s webhook_url receives approval_needed with operation_id (the agent’s id), approval_id, type (wallet_contract) and required.
  • An approval starts nothing. Once the approvers have voted, the agent asks again under the same id with the same operation. An approved operation is then prepared; a vote that ended any other way closes it with the reason.

Limits and usage#

  • The limits are the wallet’s. The policy’s limits count one set of counters for the working account and the wallet contract together.
  • Usage is counted when the request is prepared, with the answer that hands out the enclave’s half. It is not given back: not when the request is never relayed, and not when it fails on chain.
  • A prepared request that is not relayed within ten minutes is closed. The wallet contract accepts a request for ten minutes.
  • A freeze stops new requests, not the one already prepared. A prepared request carries the enclave’s half, and the wallet contract accepts it with the agent’s half until its ten minutes end. One operation runs at a time, so that is one request at most.
  • One operation of a wallet runs at a time; a second one is refused with wallet_busy.
  • The working account pays the gas of every relay and keeps 0.5 NEAR for it. Before a relay runs, the node checks that the account could pay the relay's 300 Tgas at ten times the current gas price: 0.3 NEAR today, checked and not spent. A transfer burns about 0.0004 NEAR, a call at most 0.03 NEAR; the 0.2 above the check pays for some 500 transfers. Top it up to 0.5 once it is under 0.35 NEAR; a relay it cannot cover answers 402 wallet_underfunded.

The working account#

Two signatures guard what lies in the wallet contract. Work that needs a key that signs by itself runs from the agent’s OutLayer wallet, whose key is in the enclave like every OutLayer wallet’s.

In the wallet contractOn the working account
Whatthe main balance: NEAR on the account and tokens inside NEAR Intentsa confidential balance; a venue’s trading account (Hyperliquid, Polymarket); a balance kept for limit orders; NEAR for gas
Signed bythe agent and the enclavethe enclave, within the policy
Asked for witha request signed by the agent’s keythe wallet’s API key

Funds reach the working account by a move out of the wallet contract, under both signatures, and return to the wallet contract by an ordinary operation of the working account. How much stays on the working account is the agent’s choice.

Running a program as the wallet contract’s account. A call that sets use_bound_identity, over HTTPS or in request_execution on chain, runs the program with NEAR_SENDER_ID set to the caller’s wallet contract; NEAR_USER_ACCOUNT_ID stays the account that paid. Before the program is given the name, the enclave confirms that the caller’s wallet is the wallet of that wallet contract. A call from a wallet with no wallet contract is refused with no_bound_identity. The flag changes a name: a move out of the wallet contract is still an operation under both signatures.

Leaving#

  • The owner’s exit yields the owner’s master, and the enclave’s key of every wallet contract of that owner is derived under it. The agent’s key comes from the owner’s own signature. After the exit the owner holds both keys.
  • customer-recovery wallet-contract builds a request with both signatures and prints the near-cli command that sends it. It talks to no service and to no chain, and any NEAR account sends the call. See scripts/customer-recovery/README.md.
  • The pair of a wallet contract is set once, when it is installed, and both keys are derived for the owner and the wallet: the same wallet always has the same pair. Another agent key is another agent: a new OutLayer wallet with a wallet contract on another account. The owner moves the assets there with their key of the old account, or through the exit where the keys were removed.
  • An owner who keeps a key on the account acts on it at any time with that key, without an exit.

What a compromise reaches#

What is compromisedWhat it reaches
The enclave (memory read)The enclave’s key. No signature of the agent, so no move out of a wallet contract; and no move signed by the agent that the policy did not pass, since the agent signs last. What lies on the working account is under the enclave’s key
OutLayer’s governance: a hostile build, a hostile upgrade of OutLayer’s own contractsThe enclave’s key, and still no move out of a wallet contract without the agent’s signature. No contract OutLayer can change is on the path of the funds in a wallet contract
The API in front of the enclaveNo move of its own and no request in the agent’s name: the enclave verifies the agent’s signature and reads the wallet contract itself. The API supplies the 1Click deposit address, the request’s nonce and the counters of what was spent; the agent checks the request before it signs
The agent’s machineThe agent’s key. Every operation still passes the enclave’s policy; the owner freezes the wallet, sets up another agent on another account and moves the assets there
A prompt injection into the agentAn operation request, which the enclave judges by the policy
A setup linkThe right to name this wallet’s wallet contract once, within 24 hours, and only as the owner account or a sub-account of it, which nobody but the owner can make; the account is taken only when its pair holds this wallet’s enclave key. The link ends when the setup is finished. The sealed agent key opens with the agent’s one-time key alone
The owner account’s keyThe agent’s key, by the setup’s signature. With a locked policy: what the policy allows as it stands, since a change of policy and an exit both need the approvers. Without a lock the owner’s key is the whole authority
An access key of the wallet contract’s account, where the owner kept oneEverything on that account, at once: the key is above the contract, and neither the policy nor its lock applies
NEAR MPCThe enclave’s key, through the master; not the agent’s, which comes from the owner’s own signature. No move out of a wallet contract

Reference#