@agenttrust-sdk/mcp 0.2.6 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/embedded-data/devnet-smoke.json +4 -4
- package/dist/embedded-docs/architecture.mdx +174 -0
- package/dist/embedded-docs/getting-started/quickstart.mdx +79 -56
- package/dist/embedded-docs/index.mdx +54 -37
- package/dist/embedded-docs/integration-guides/capability-namespaces.mdx +135 -8
- package/dist/embedded-docs/integration-guides/custom-attestor.mdx +169 -8
- package/dist/embedded-docs/integration-guides/dexter-adapter.mdx +76 -0
- package/dist/embedded-docs/integration-guides/facilitator-adapters.mdx +85 -41
- package/dist/embedded-docs/integration-guides/pay-sh-adapter.mdx +90 -54
- package/dist/embedded-docs/integration-guides/x402-facilitator.mdx +55 -24
- package/dist/embedded-docs/mcp/hosted-endpoint.mdx +197 -0
- package/dist/embedded-docs/mcp/index.mdx +108 -0
- package/dist/embedded-docs/mcp/install.mdx +183 -0
- package/dist/embedded-docs/mcp/prompts.mdx +90 -0
- package/dist/embedded-docs/mcp/resources.mdx +115 -0
- package/dist/embedded-docs/mcp/tools.mdx +156 -0
- package/dist/embedded-docs/programs/policy-vault/composer.mdx +117 -0
- package/dist/embedded-docs/programs/policy-vault/counterparty-tier-policy.mdx +81 -9
- package/dist/embedded-docs/programs/policy-vault/index.mdx +77 -47
- package/dist/embedded-docs/programs/policy-vault/kill-switch-policy.mdx +65 -8
- package/dist/embedded-docs/programs/policy-vault/require-validation-policy.mdx +76 -8
- package/dist/embedded-docs/programs/policy-vault/spending-policy.mdx +83 -8
- package/dist/embedded-docs/programs/policy-vault/velocity-policy.mdx +85 -8
- package/dist/embedded-docs/programs/trustgate.mdx +112 -30
- package/dist/embedded-docs/programs/validation-registry.mdx +139 -32
- package/dist/embedded-docs/reference/byte-offset-reference.mdx +102 -13
- package/dist/embedded-docs/reference/capability-namespaces.mdx +56 -0
- package/dist/embedded-docs/reference/changelog.mdx +230 -13
- package/dist/embedded-docs/reference/deny-reason-codes.mdx +86 -0
- package/dist/embedded-docs/reference/devnet-program-ids.mdx +50 -8
- package/dist/embedded-docs/reference/discriminator-constants.mdx +104 -10
- package/dist/embedded-docs/reference/mainnet-program-ids.mdx +89 -5
- package/dist/embedded-docs/reference/quantu-agent-registry.mdx +104 -9
- package/dist/embedded-docs/sdk/exports-reference.mdx +239 -0
- package/dist/embedded-docs/sdk/gate-payment.mdx +99 -14
- package/dist/embedded-docs/sdk/index.mdx +141 -40
- package/dist/embedded-docs/sdk/mount-trustgate.mdx +178 -8
- package/dist/embedded-docs/verification/adversarial-harness.mdx +88 -0
- package/dist/embedded-docs/verification/atomic-tx-invariant.mdx +141 -0
- package/dist/embedded-docs/verification/chained-validation.mdx +87 -0
- package/dist/embedded-docs/verification/devnet-smoke.mdx +85 -0
- package/dist/embedded-docs/verification/index.mdx +31 -0
- package/dist/embedded-docs/verification/kani-proofs.mdx +144 -0
- package/dist/embedded-docs/verification/live-evidence.mdx +180 -0
- package/dist/tools/write/emit-feedback.d.ts +6 -0
- package/dist/tools/write/emit-feedback.js +12 -1
- package/dist/tools/write/emit-feedback.js.map +1 -1
- package/package.json +16 -15
- package/scripts/install-claude-desktop.sh +0 -0
|
@@ -1,15 +1,110 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: Quantu
|
|
3
|
-
description: Quantu
|
|
2
|
+
title: Quantu agent registry
|
|
3
|
+
description: The Quantu CPI surface AgentTrust consumes — give_feedback discriminator, AgentAccount + AtomStats accounts, byte-offset reads, pinned commit.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
AgentTrust reads two Quantu programs from `8004-solana`:
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
- `agent-registry-8004` — agent identity + the `give_feedback` instruction TrustGate CPIs into.
|
|
9
|
+
- `atom-engine` — confidence-weighted reputation aggregation. `AtomStats` PDA carries the `tier_immediate` byte PolicyVault gates against.
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
| --- | --- |
|
|
12
|
-
| feedback CPI | [`programs/trustgate/src/ext/agent_registry.rs`](https://github.com/agenttrust-labs/agenttrust/blob/main/programs/trustgate/src/ext/agent_registry.rs) |
|
|
13
|
-
| AtomStats parser | [`programs/policy-vault/src/ext/atom_engine.rs`](https://github.com/agenttrust-labs/agenttrust/blob/main/programs/policy-vault/src/ext/atom_engine.rs) |
|
|
14
|
-
| research notes | [`docs/plan/research/02-quantu-erc8004-archaeology.md`](https://github.com/agenttrust-labs/agenttrust/blob/main/docs/plan/research/02-quantu-erc8004-archaeology.md) |
|
|
11
|
+
Both pinned to commit `bfb09ad`.
|
|
15
12
|
|
|
13
|
+
## `give_feedback` CPI
|
|
14
|
+
|
|
15
|
+
Discriminator: `[145, 136, 123, 3, 215, 165, 98, 41]`.
|
|
16
|
+
|
|
17
|
+
```rust
|
|
18
|
+
pub struct GiveFeedbackArgs {
|
|
19
|
+
pub value: u64,
|
|
20
|
+
pub value_decimals: u8,
|
|
21
|
+
pub score: Option<u8>, // 0..=100
|
|
22
|
+
pub feedback_file_hash: Option<[u8; 32]>, // dispute_reason_hash for disputes
|
|
23
|
+
pub tag1: String, // ≤ 32 bytes
|
|
24
|
+
pub tag2: String, // ≤ 32 bytes
|
|
25
|
+
pub endpoint: String, // ≤ 64 bytes
|
|
26
|
+
pub feedback_uri: String, // ≤ 256 bytes
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`remaining_accounts` ordering for the CPI:
|
|
31
|
+
|
|
32
|
+
| Index | Account | Notes |
|
|
33
|
+
|---:|---|---|
|
|
34
|
+
| 0 | `agent_account` | payee's `AgentAccount` PDA |
|
|
35
|
+
| 1 | `asset` | payee's Metaplex Core asset |
|
|
36
|
+
| 2 | `collection` | Quantu's collection asset |
|
|
37
|
+
| 3 | `system_program` | for AtomStats init rent |
|
|
38
|
+
| 4 | `atom_config` (optional) | Quantu's `AtomConfig` PDA |
|
|
39
|
+
| 5 | `atom_stats` (optional) | payee's `AtomStats` PDA |
|
|
40
|
+
| 6 | `atom_engine_program` (optional) | Quantu's `atom-engine` |
|
|
41
|
+
| 7 | `registry_authority` (optional) | Quantu's registry authority PDA |
|
|
42
|
+
|
|
43
|
+
Indexes 0..=3 are required; 4..=7 come as a group of 4 (all four or none). TrustGate's `emit_feedback` handler validates this in [`programs/trustgate/src/instructions/emit_feedback.rs`](https://github.com/agenttrust-labs/agenttrust/blob/main/programs/trustgate/src/instructions/emit_feedback.rs).
|
|
44
|
+
|
|
45
|
+
The SDK's [`deriveQuantuFeedbackAccounts`](/sdk/exports-reference#quantu-helpers) returns this account bundle correctly ordered.
|
|
46
|
+
|
|
47
|
+
## `AtomStats` byte-offset reads
|
|
48
|
+
|
|
49
|
+
PolicyVault's [CounterpartyTier](/programs/policy-vault/counterparty-tier-policy) policy reads `AtomStats` via a manual byte-offset parser pinned to commit `bfb09ad`. Schema-version canary at byte 560 catches drift.
|
|
50
|
+
|
|
51
|
+
| Offset | Width | Field |
|
|
52
|
+
|---:|---:|---|
|
|
53
|
+
| 549 | u8 | `risk_score` |
|
|
54
|
+
| 551 | u8 | `tier_immediate` (v1 demo default) |
|
|
55
|
+
| 555 | u8 | `tier_confirmed` (production) |
|
|
56
|
+
| 557 | u16 LE | `confidence` (basis points) |
|
|
57
|
+
| 560 | u8 | `schema_version` (must equal 1) |
|
|
58
|
+
|
|
59
|
+
Account size: 561 bytes. Tier domain: `0..=4` (`ATOM_TIER_MAX = 4`).
|
|
60
|
+
|
|
61
|
+
Full table: [Reference → Byte offsets](/reference/byte-offset-reference).
|
|
62
|
+
|
|
63
|
+
## Mainnet vs devnet program IDs
|
|
64
|
+
|
|
65
|
+
| Program | Mainnet | Devnet |
|
|
66
|
+
|---|---|---|
|
|
67
|
+
| `agent-registry-8004` | `8oo4dC4JvBLwy5tGgiH3WwK4B9PWxL9Z4XjA2jzkQMbQ` | `8oo4J9tBB3Hna1jRQ3rWvJjojqM5DYTDJo5cejUuJy3C` |
|
|
68
|
+
| `atom-engine` | `AToMw53aiPQ8j7iHVb4fGt6nzUNxUhcPc3tbPBZuzVVb` | `AToMufS4QD6hEXvcvBDg9m1AHeCLpmZQsyfYa5h9MwAF` |
|
|
69
|
+
|
|
70
|
+
The SDK's `MAINNET_QUANTU_IDS` and `DEFAULT_DEVNET_QUANTU_IDS` carry these. `NETWORK` env on the MCP server drives the right pair: [MCP → Install](/mcp/install).
|
|
71
|
+
|
|
72
|
+
## Why byte-offset and not Borsh?
|
|
73
|
+
|
|
74
|
+
Two reasons:
|
|
75
|
+
|
|
76
|
+
1. **Zero Cargo dep on Quantu's crate.** AgentTrust would otherwise pin to Quantu's published Anchor IDL or workspace package. A Quantu version bump that re-orders fields would silently change PolicyVault's reads through Borsh's positional encoding. The byte-offset parser is fragile against layout changes — but fragile-with-canary, not fragile-silent. The `schema_version` byte at 560 fails loud rather than silently misread.
|
|
77
|
+
2. **Bounded compute.** Borsh deserialization allocates and walks the full struct. The byte-offset parser reads exactly the five bytes PolicyVault gates against — `risk_score`, `tier_immediate`, `tier_confirmed`, `confidence`, `schema_version`. Cheaper compute units, smaller stack frame.
|
|
78
|
+
|
|
79
|
+
Trade-off: the parser must be re-pinned manually if Quantu bumps its layout. The pinned-commit comment in [`policy-vault/src/ext/atom_engine.rs`](https://github.com/agenttrust-labs/agenttrust/blob/main/programs/policy-vault/src/ext/atom_engine.rs) documents the bump procedure.
|
|
80
|
+
|
|
81
|
+
## TrustGate's CPI wrapper
|
|
82
|
+
|
|
83
|
+
TrustGate's `emit_feedback` PDA-signs the CPI:
|
|
84
|
+
|
|
85
|
+
```rust
|
|
86
|
+
let signer_seeds: &[&[u8]] = &[
|
|
87
|
+
TrustGateAuthority::SEED_PREFIX, // b"trustgate_auth"
|
|
88
|
+
facilitator.as_ref(),
|
|
89
|
+
&[bump],
|
|
90
|
+
];
|
|
91
|
+
invoke_give_feedback(&cpi_accounts, &args, signer_seeds)?;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Quantu's `give_feedback` instruction expects the caller to be the agent's owner. TrustGate's PDA is registered as the feedback authority via Quantu's identity flow on first use (the `set_agent_wallet` instruction at `identity/instructions.rs:506-541` in Quantu's source). The `client` account in the CPI is set to `authority.to_account_info()`, so Quantu sees a PDA-signed call rather than the facilitator's wallet directly.
|
|
95
|
+
|
|
96
|
+
CPI source: [`programs/trustgate/src/ext/agent_registry.rs`](https://github.com/agenttrust-labs/agenttrust/blob/main/programs/trustgate/src/ext/agent_registry.rs).
|
|
97
|
+
|
|
98
|
+
## Read next
|
|
99
|
+
|
|
100
|
+
<Cards>
|
|
101
|
+
<Card title="TrustGate" href="/programs/trustgate">
|
|
102
|
+
The program that owns the CPI.
|
|
103
|
+
</Card>
|
|
104
|
+
<Card title="CounterpartyTier policy" href="/programs/policy-vault/counterparty-tier-policy">
|
|
105
|
+
What consumes the AtomStats reads.
|
|
106
|
+
</Card>
|
|
107
|
+
<Card title="Byte-offset reference" href="/reference/byte-offset-reference">
|
|
108
|
+
Per-account byte-offset tables.
|
|
109
|
+
</Card>
|
|
110
|
+
</Cards>
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Exports reference
|
|
3
|
+
description: Every public export from @agenttrust-sdk/trustgate, grouped by concern.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
The SDK ships three import surfaces. The `/express` and `/client` subpaths are tree-shake-friendly entry points; the root namespace re-exports everything else.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { mountTrustGate } from "@agenttrust-sdk/trustgate/express";
|
|
10
|
+
import { gatePayment, settle, dispute } from "@agenttrust-sdk/trustgate/client";
|
|
11
|
+
import { /* everything else */ } from "@agenttrust-sdk/trustgate";
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Source: [`trustgate/sdk/src/index.ts`](https://github.com/agenttrust-labs/agenttrust/blob/main/trustgate/sdk/src/index.ts).
|
|
15
|
+
|
|
16
|
+
## Atomicity guard
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import {
|
|
20
|
+
AtomicityEnforced,
|
|
21
|
+
AtomicityNotEnforcedError,
|
|
22
|
+
assertAtomicityEnforced,
|
|
23
|
+
composeAtomicSettleTx,
|
|
24
|
+
deriveStandardAta,
|
|
25
|
+
} from "@agenttrust-sdk/trustgate";
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
| Export | Kind | Purpose |
|
|
29
|
+
|---|---|---|
|
|
30
|
+
| `AtomicityEnforced` | type | `{ atomicityEnforced: true }` literal-type marker |
|
|
31
|
+
| `AtomicityNotEnforcedError` | class | thrown by runtime guard on non-`true` value |
|
|
32
|
+
| `assertAtomicityEnforced(cfg, siteName)` | fn | runtime check; call at top of every settle/dispute entry point |
|
|
33
|
+
| `composeAtomicSettleTx(args)` | async fn | builds a 3-ix `Transaction` (gate strict + transferChecked + emit_feedback) |
|
|
34
|
+
| `deriveStandardAta(owner, mint, tokenProgram?)` | fn | standard ATA helper |
|
|
35
|
+
| `AtomicSettleQuantuAccounts` | type | the Quantu account bundle `composeAtomicSettleTx` threads through `remaining_accounts` |
|
|
36
|
+
| `ComposeAtomicSettleArgs` | type | full arg shape, `extends AtomicityEnforced` |
|
|
37
|
+
| `ComposedAtomicSettle` | type | return shape: `{ tx, instructions, accounts }` |
|
|
38
|
+
|
|
39
|
+
Source: [`trustgate/sdk/src/atomicity.ts`](https://github.com/agenttrust-labs/agenttrust/blob/main/trustgate/sdk/src/atomicity.ts).
|
|
40
|
+
|
|
41
|
+
## SPL helpers
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import {
|
|
45
|
+
TOKEN_PROGRAM_ID,
|
|
46
|
+
TOKEN_2022_PROGRAM_ID,
|
|
47
|
+
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
48
|
+
buildTransferCheckedIx,
|
|
49
|
+
deriveAssociatedTokenAddress,
|
|
50
|
+
} from "@agenttrust-sdk/trustgate";
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`buildTransferCheckedIx` accepts an optional `tokenProgram` to switch between legacy SPL and Token-2022. The atomic-tx invariant applies to both — Token-2022's `TransferHook` extension is the canonical corruption vector that motivates the invariant; legacy SPL's `MissingRequiredSignature` revert produces the same atomicity behaviour.
|
|
54
|
+
|
|
55
|
+
Source: [`trustgate/sdk/src/spl.ts`](https://github.com/agenttrust-labs/agenttrust/blob/main/trustgate/sdk/src/spl.ts).
|
|
56
|
+
|
|
57
|
+
## On-chain validator factory
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import {
|
|
61
|
+
makeValidateOnChainTx,
|
|
62
|
+
type OnChainTxValidation,
|
|
63
|
+
type OnChainTxRejection,
|
|
64
|
+
type ValidateOnChainTxFn,
|
|
65
|
+
type MakeValidateOnChainTxOptions,
|
|
66
|
+
} from "@agenttrust-sdk/trustgate";
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`makeValidateOnChainTx({ connection, … })` returns a function the facilitator's `/settle` route plugs into the adapter's `validatePaymentProof` slot. Parses a confirmed SPL transfer transaction from RPC, cross-checks amount / mint / recipient / authority against the verify-time `VerifyContext`, and rejects mismatches with typed errors.
|
|
70
|
+
|
|
71
|
+
Source: [`trustgate/sdk/src/onchain-validator.ts`](https://github.com/agenttrust-labs/agenttrust/blob/main/trustgate/sdk/src/onchain-validator.ts).
|
|
72
|
+
|
|
73
|
+
## Quantu helpers
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import {
|
|
77
|
+
DEFAULT_DEVNET_QUANTU_IDS,
|
|
78
|
+
MAINNET_QUANTU_IDS,
|
|
79
|
+
type QuantuProgramIds,
|
|
80
|
+
type QuantuFeedbackAccounts,
|
|
81
|
+
type QuantuFeedbackAccountsArgs,
|
|
82
|
+
deriveAgentAccountPda,
|
|
83
|
+
deriveAtomConfigPda,
|
|
84
|
+
deriveAtomStatsPda,
|
|
85
|
+
deriveAtomRegistryAuthorityPda,
|
|
86
|
+
deriveQuantuFeedbackAccounts,
|
|
87
|
+
} from "@agenttrust-sdk/trustgate";
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The `Quantu*` helpers derive Quantu PDAs without depending on Quantu's TypeScript package. Pinned to commit `bfb09ad` per [Reference → Mainnet program IDs](/reference/mainnet-program-ids). `deriveQuantuFeedbackAccounts` returns the full account bundle the `give_feedback` CPI needs in `remaining_accounts` order.
|
|
91
|
+
|
|
92
|
+
Source: [`trustgate/sdk/src/quantu.ts`](https://github.com/agenttrust-labs/agenttrust/blob/main/trustgate/sdk/src/quantu.ts).
|
|
93
|
+
|
|
94
|
+
## emit_feedback factory
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import {
|
|
98
|
+
makeEmitFeedbackCpi,
|
|
99
|
+
makePriorEmissionLookup,
|
|
100
|
+
type EmitFeedbackCpiFn,
|
|
101
|
+
type EmitFeedbackCpiInput,
|
|
102
|
+
type EmitFeedbackResult,
|
|
103
|
+
type MakeEmitFeedbackCpiOptions,
|
|
104
|
+
type PriorEmissionLookupFn,
|
|
105
|
+
type PriorEmissionResult,
|
|
106
|
+
type MakePriorEmissionLookupOptions,
|
|
107
|
+
} from "@agenttrust-sdk/trustgate";
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`makeEmitFeedbackCpi({ connection, … })` returns the function adapters plug into their `emitFeedback` slot. `makePriorEmissionLookup({ connection, … })` returns the `priorEmissionLookup` function — looks up `FeedbackEmissionLog` by `payment_id_hash` so retries return a stable receipt instead of double-emitting.
|
|
111
|
+
|
|
112
|
+
Source: [`trustgate/sdk/src/emit-feedback.ts`](https://github.com/agenttrust-labs/agenttrust/blob/main/trustgate/sdk/src/emit-feedback.ts).
|
|
113
|
+
|
|
114
|
+
## ValidationRegistry
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import {
|
|
118
|
+
VALIDATION_REGISTRY_DEVNET_ID,
|
|
119
|
+
deriveCapabilityNamespacePda,
|
|
120
|
+
deriveAttestorProfilePda,
|
|
121
|
+
deriveValidationRequestPda,
|
|
122
|
+
deriveValidationAttestationPda,
|
|
123
|
+
computeNamespaceHash,
|
|
124
|
+
computeCapabilityHash,
|
|
125
|
+
loadValidationRegistry,
|
|
126
|
+
buildRegisterNamespaceIx,
|
|
127
|
+
buildRegisterAttestorIx,
|
|
128
|
+
buildRequestValidationIx,
|
|
129
|
+
buildRespondToValidationIx,
|
|
130
|
+
buildRevokeValidationIx,
|
|
131
|
+
fetchValidationAttestation,
|
|
132
|
+
fetchValidationRequest,
|
|
133
|
+
fetchAttestorProfile,
|
|
134
|
+
fetchCapabilityNamespace,
|
|
135
|
+
type BuildRegisterNamespaceArgs,
|
|
136
|
+
type BuildRegisterAttestorArgs,
|
|
137
|
+
type BuildRequestValidationArgs,
|
|
138
|
+
type BuildRespondToValidationArgs,
|
|
139
|
+
type BuildRevokeValidationArgs,
|
|
140
|
+
} from "@agenttrust-sdk/trustgate";
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Full instruction-builder set for the third leg of ERC-8004. `computeCapabilityHash(name)` returns `SHA-256(name)`; `computeNamespaceHash(name)` is an alias kept for clarity. `fetch*` helpers return decoded views of each PDA.
|
|
144
|
+
|
|
145
|
+
Source: [`trustgate/sdk/src/validation-registry.ts`](https://github.com/agenttrust-labs/agenttrust/blob/main/trustgate/sdk/src/validation-registry.ts).
|
|
146
|
+
|
|
147
|
+
## PDA derivers + Anchor loaders
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import {
|
|
151
|
+
derivePolicyPda,
|
|
152
|
+
deriveVelocityPda,
|
|
153
|
+
deriveKillSwitchPda,
|
|
154
|
+
deriveFeedbackLogPda,
|
|
155
|
+
deriveTrustGateAuthorityPda,
|
|
156
|
+
loadPolicyVault,
|
|
157
|
+
loadTrustGate,
|
|
158
|
+
makeProvider,
|
|
159
|
+
simulateGatePayment,
|
|
160
|
+
parseGateDecision,
|
|
161
|
+
} from "@agenttrust-sdk/trustgate";
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
`load*` helpers fetch the IDL from chain by default (`anchor idl fetch <programId>`). Pass an explicit `idl` argument to use a bundled snapshot — useful for latency-sensitive paths or freshly redeployed programs before `anchor idl upgrade`.
|
|
165
|
+
|
|
166
|
+
Source: [`trustgate/sdk/src/chain.ts`](https://github.com/agenttrust-labs/agenttrust/blob/main/trustgate/sdk/src/chain.ts).
|
|
167
|
+
|
|
168
|
+
## x402 headers
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
import {
|
|
172
|
+
buildHeadersForDecision,
|
|
173
|
+
denyReasonName,
|
|
174
|
+
X_PAYMENT_REQUIRED,
|
|
175
|
+
X_PAYMENT_NETWORK,
|
|
176
|
+
X_PAYMENT_REASON_CODE,
|
|
177
|
+
X_PAYMENT_REASON_NAME,
|
|
178
|
+
X_CAPABILITY_REQUIRED,
|
|
179
|
+
X_AGENT_TRUST_DECISION,
|
|
180
|
+
} from "@agenttrust-sdk/trustgate";
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
`buildHeadersForDecision(decision, network)` returns the header map for `Allow` / `Deny` / `RequireValidation`. `denyReasonName(code)` maps `1..=15` to the canonical name (e.g., `6` → `CounterpartyTierBelowMin`).
|
|
184
|
+
|
|
185
|
+
Source: [`trustgate/sdk/src/x402.ts`](https://github.com/agenttrust-labs/agenttrust/blob/main/trustgate/sdk/src/x402.ts).
|
|
186
|
+
|
|
187
|
+
## Types + constants
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
import {
|
|
191
|
+
GateDecision,
|
|
192
|
+
DenyReasonCode,
|
|
193
|
+
ProgramIds,
|
|
194
|
+
DEFAULT_DEVNET_PROGRAM_IDS,
|
|
195
|
+
} from "@agenttrust-sdk/trustgate";
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
type GateDecision =
|
|
200
|
+
| { kind: "Allow" }
|
|
201
|
+
| { kind: "Deny"; reasonCode: DenyReasonCode; reasonName: string }
|
|
202
|
+
| { kind: "RequireValidation"; capabilityHash: Uint8Array };
|
|
203
|
+
|
|
204
|
+
interface ProgramIds {
|
|
205
|
+
policyVault: PublicKey;
|
|
206
|
+
trustGate: PublicKey; // camelCase as of 0.2.0
|
|
207
|
+
validationRegistry: PublicKey; // new in 0.2.0
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
`DEFAULT_DEVNET_PROGRAM_IDS` carries the deployed-devnet IDs. Override via `ProgramIds` for mainnet redeploys. Source: [`trustgate/sdk/src/types.ts`](https://github.com/agenttrust-labs/agenttrust/blob/main/trustgate/sdk/src/types.ts).
|
|
212
|
+
|
|
213
|
+
## Express + client subpaths
|
|
214
|
+
|
|
215
|
+
These have their own dedicated entry points and don't re-export through the root namespace:
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
// Express middleware (peer dep: express ^4.21)
|
|
219
|
+
import { mountTrustGate } from "@agenttrust-sdk/trustgate/express";
|
|
220
|
+
|
|
221
|
+
// Client helpers
|
|
222
|
+
import { gatePayment, settle, dispute } from "@agenttrust-sdk/trustgate/client";
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
References: [mountTrustGate](/sdk/mount-trustgate), [gatePayment](/sdk/gate-payment).
|
|
226
|
+
|
|
227
|
+
## Read next
|
|
228
|
+
|
|
229
|
+
<Cards>
|
|
230
|
+
<Card title="Atomic-tx invariant" href="/verification/atomic-tx-invariant">
|
|
231
|
+
Three layers of proof + the on-chain Kani strict-correctness binding.
|
|
232
|
+
</Card>
|
|
233
|
+
<Card title="Pay.sh adapter" href="/integration-guides/pay-sh-adapter">
|
|
234
|
+
Canonical FacilitatorAdapter implementation, end to end.
|
|
235
|
+
</Card>
|
|
236
|
+
<Card title="MCP server" href="/mcp">
|
|
237
|
+
Eighteen tools that surface every SDK helper to Claude Desktop and Cursor.
|
|
238
|
+
</Card>
|
|
239
|
+
</Cards>
|
|
@@ -1,22 +1,107 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: gatePayment
|
|
3
|
-
description: Read-only policy decision call
|
|
3
|
+
description: Read-only policy decision call. Simulates PolicyVault's gate_payment instruction and returns the typed GateDecision union.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
`
|
|
6
|
+
`gatePayment()` is the read-only entry point. It builds an Anchor simulation of `gate_payment`, parses the return-data channel into the TypeScript union, and never sends a transaction.
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Use it when your facilitator already owns its x402 routing and only needs the AgentTrust decision. For atomic settlement (gate + transfer + feedback in one tx), use [`mountTrustGate`](/sdk/mount-trustgate) or [`composeAtomicSettleTx`](/sdk/exports-reference).
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Source: [`trustgate/sdk/src/client.ts`](https://github.com/agenttrust-labs/agenttrust/blob/main/trustgate/sdk/src/client.ts).
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
2. SERVICE signature verification
|
|
14
|
-
3. proof validation
|
|
15
|
-
4. feedback emission
|
|
12
|
+
## Signature
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
```ts
|
|
15
|
+
import { gatePayment } from "@agenttrust-sdk/trustgate/client";
|
|
16
|
+
|
|
17
|
+
export function gatePayment(req: GatePaymentRequest): Promise<GateDecision>;
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## `GatePaymentRequest`
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
interface GatePaymentRequest {
|
|
24
|
+
rpcUrl: string;
|
|
25
|
+
caller: Keypair; // facilitator keypair (signs simulate-tx)
|
|
26
|
+
payerAgentAsset: PublicKey; // payer's Metaplex Core asset (Quantu agent identity)
|
|
27
|
+
payeeAgentAsset: PublicKey; // payee's Metaplex Core asset
|
|
28
|
+
amount: bigint | number; // base units (1_000_000n = 1 USDC at 6 decimals)
|
|
29
|
+
mint: PublicKey; // USDC devnet: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
|
|
30
|
+
policyId: number; // PolicyAccount.policy_id (u32)
|
|
31
|
+
programIds?: ProgramIds; // defaults to DEFAULT_DEVNET_PROGRAM_IDS
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The `caller` keypair signs the simulation transaction; the result is never committed, so the keypair is only used to satisfy the simulate-tx fee-payer. Pass any funded devnet keypair.
|
|
36
|
+
|
|
37
|
+
## `GateDecision`
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
type GateDecision =
|
|
41
|
+
| { kind: "Allow" }
|
|
42
|
+
| { kind: "Deny"; reasonCode: number; reasonName: string }
|
|
43
|
+
| { kind: "RequireValidation"; capabilityHash: Uint8Array /* 32 bytes */ };
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
| Decision | Next step |
|
|
47
|
+
|---|---|
|
|
48
|
+
| `Allow` | Proceed to settlement (build / sign / submit the atomic tx). |
|
|
49
|
+
| `Deny` | Return 402 to the user with `reasonName`. Surface `reasonCode` for machine consumers. |
|
|
50
|
+
| `RequireValidation` | Route the user to the attestation flow for `capabilityHash`. After the attestor responds, re-call `gatePayment` — the gate now sees the new `ValidationAttestation` and flips to `Allow`. |
|
|
51
|
+
|
|
52
|
+
`reasonCode` is decoupled from Borsh wire-format ordering. Full table: [Reference → DenyReason codes](/reference/deny-reason-codes).
|
|
53
|
+
|
|
54
|
+
## Example
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { Keypair, PublicKey } from "@solana/web3.js";
|
|
58
|
+
import { gatePayment } from "@agenttrust-sdk/trustgate/client";
|
|
59
|
+
|
|
60
|
+
const facilitatorKey = Keypair.fromSecretKey(new Uint8Array(JSON.parse(process.env.FACILITATOR_KEY!)));
|
|
61
|
+
|
|
62
|
+
const decision = await gatePayment({
|
|
63
|
+
rpcUrl: "https://api.devnet.solana.com",
|
|
64
|
+
caller: facilitatorKey,
|
|
65
|
+
payerAgentAsset: new PublicKey("5PfaofvEUf3adtJwMho7zzbfvgxwxbvp2V5moqhtLK8y"),
|
|
66
|
+
payeeAgentAsset: new PublicKey("5PfaofvEUf3adtJwMho7zzbfvgxwxbvp2V5moqhtLK8y"),
|
|
67
|
+
amount: 1_000_000n, // 1 USDC
|
|
68
|
+
mint: new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),
|
|
69
|
+
policyId: 1,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
switch (decision.kind) {
|
|
73
|
+
case "Allow":
|
|
74
|
+
console.log("gate=Allow — proceed to settle");
|
|
75
|
+
break;
|
|
76
|
+
case "Deny":
|
|
77
|
+
console.log(`gate=Deny ${decision.reasonCode} (${decision.reasonName})`);
|
|
78
|
+
break;
|
|
79
|
+
case "RequireValidation":
|
|
80
|
+
const hex = Buffer.from(decision.capabilityHash).toString("hex");
|
|
81
|
+
console.log(`gate=RequireValidation capability=${hex}`);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Implementation note — return-data channel
|
|
87
|
+
|
|
88
|
+
PolicyVault's `gate_payment` (lazy variant) returns the decision via Anchor's `set_return_data` so simulation can decode it. The strict variant — used by [`composeAtomicSettleTx`](/sdk/exports-reference) — instead returns `Err` on non-`Allow`, which is what makes the atomic tx revert as a unit.
|
|
89
|
+
|
|
90
|
+
`gatePayment()` simulates the lazy variant and parses the return-data via `parseGateDecision`. The wire format is documented in [`programs/policy-vault/src/state/decision.rs`](https://github.com/agenttrust-labs/agenttrust/blob/main/programs/policy-vault/src/state/decision.rs).
|
|
91
|
+
|
|
92
|
+
## Errors
|
|
93
|
+
|
|
94
|
+
| Error | Cause |
|
|
95
|
+
|---|---|
|
|
96
|
+
| `AccountNotFound` | `PolicyAccount` PDA missing for `(payerAgentAsset, policyId)` — call `init_policy` first. |
|
|
97
|
+
| `RPC error: insufficient funds` | `caller` keypair has zero SOL. Fund via `solana airdrop 1 <pubkey> --url devnet`. |
|
|
98
|
+
| `IdlAccountUnsupported` | Program IDL not yet published on the cluster. Run `anchor idl init <programId> --provider.cluster <cluster>`. |
|
|
99
|
+
|
|
100
|
+
For the atomic-settle path (which can also return `AtomicityNotEnforcedError`), see [`composeAtomicSettleTx`](/sdk/exports-reference).
|
|
101
|
+
|
|
102
|
+
## Source
|
|
103
|
+
|
|
104
|
+
- Client: [`trustgate/sdk/src/client.ts`](https://github.com/agenttrust-labs/agenttrust/blob/main/trustgate/sdk/src/client.ts)
|
|
105
|
+
- Simulation: [`trustgate/sdk/src/chain.ts`](https://github.com/agenttrust-labs/agenttrust/blob/main/trustgate/sdk/src/chain.ts) (`simulateGatePayment`, `parseGateDecision`)
|
|
106
|
+
- Types: [`trustgate/sdk/src/types.ts`](https://github.com/agenttrust-labs/agenttrust/blob/main/trustgate/sdk/src/types.ts)
|
|
107
|
+
- Tests: [`trustgate/sdk/test/`](https://github.com/agenttrust-labs/agenttrust/tree/main/trustgate/sdk/test)
|