@wzrd_sol/eliza-plugin 0.3.1 → 0.3.2

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/README.md CHANGED
@@ -1,8 +1,15 @@
1
1
  # @wzrd_sol/eliza-plugin
2
2
 
3
- ElizaOS plugin for WZRD Agent Intel and the legacy earn loop on Solana.
3
+ ElizaOS plugin for WZRD Agent Intel x402 firewall, free preflight checks before spends,
4
+ paid trust receipts (V6 + ERC-8004), and the earn loop on Solana.
4
5
 
5
- **Before any x402 spend:** run `WZRD_INTEL_PREFLIGHT` (free ReadinessCard). Escalate to `WZRD_INTEL_TRUST` only when you need a signed V5 receipt. Verify offline with `WZRD_VERIFY_RECEIPT`.
6
+ ## 3-line quickstart
7
+
8
+ ```typescript
9
+ import wzrdPlugin from '@wzrd_sol/eliza-plugin';
10
+ const agent = new AgentRuntime({ plugins: [wzrdPlugin] });
11
+ // "Preflight seller JUP6Lkb... at 0.25 USDC" → allow/warn/block, free, no wallet
12
+ ```
6
13
 
7
14
  ## Install
8
15
 
@@ -15,93 +22,185 @@ npm install @wzrd_sol/eliza-plugin
15
22
  | Variable | Required | Default | Description |
16
23
  |----------|----------|---------|-------------|
17
24
  | `WZRD_INTEL_URL` | No | `https://intel.twzrd.xyz` | Agent Intel API (preflight, trust, verify) |
18
- | `WZRD_API_URL` | No | `https://api.twzrd.xyz` | Legacy earn API (infer/report/claim) |
25
+ | `WZRD_API_URL` | No | `https://api.twzrd.xyz` | Earn API (infer/report/claim) |
19
26
  | `SOLANA_PRIVATE_KEY` | Earn lane only | — | JSON array of secret key bytes for agent Ed25519 auth |
20
27
 
21
- ### Wiring a paying fetch (intel paid actions)
28
+ ## Intel actions (primary)
22
29
 
23
- The plugin does **not** embed a wallet. Paid `WZRD_INTEL_TRUST` needs an x402-capable `fetch` from the host:
30
+ | Action | Auth/Pay | Description |
31
+ |--------|----------|-------------|
32
+ | `WZRD_INTEL_PREFLIGHT` | Free | ReadinessCard: `decision`, `trust_score`, `can_spend`, `caveats`, `preflight_id` |
33
+ | `WZRD_INTEL_TRUST` | x402 (~0.05 USDC) | Paid trust payload + V6 signed receipt + ERC-8004 `reputation_credential` |
34
+ | `WZRD_VERIFY_RECEIPT` | Free (offline) | Recompute leaf + Ed25519 verify; no network when pubkey is known |
24
35
 
25
- ```typescript
26
- import { AgentRuntime } from '@elizaos/core';
27
- import wzrdPlugin, { setPayingFetch } from '@wzrd_sol/eliza-plugin';
28
- import { agentcashFetch } from 'your-x402-wrapper'; // agentcash, twzrd-x402-gate, etc.
36
+ ### Preflight (free, no wallet)
29
37
 
30
- setPayingFetch(agentcashFetch);
38
+ ```typescript
39
+ import { intelPreflightAction } from '@wzrd_sol/eliza-plugin';
31
40
 
32
- const agent = new AgentRuntime({
33
- plugins: [wzrdPlugin],
34
- settings: {
35
- WZRD_INTEL_URL: 'https://intel.twzrd.xyz',
36
- SOLANA_PRIVATE_KEY: process.env.SOLANA_PRIVATE_KEY,
41
+ // Reads seller_wallet / price_usdc / agent_intent from message content.
42
+ await intelPreflightAction.handler(runtime, {
43
+ content: {
44
+ seller_wallet: 'JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4',
45
+ price_usdc: 0.25,
46
+ agent_intent: 'quote preview',
37
47
  },
38
- });
48
+ }, state, opts, callback);
39
49
  ```
40
50
 
41
- Without a paying fetch, `WZRD_INTEL_TRUST` returns the HTTP 402 requirements and an `npx agentcash@latest fetch ...` one-liner.
51
+ Response (formatted text returned to agent):
42
52
 
43
- ## Usage
53
+ ```
54
+ ReadinessCard v1
55
+ Decision: allow
56
+ Trust score: 72
57
+ Can spend: yes
58
+ Preflight ID: pf_abc123
59
+ Paid deep dive available (0.05 USDC) — use WZRD_INTEL_TRUST
60
+ ```
44
61
 
45
- ```typescript
46
- import { wzrdPlugin } from '@wzrd_sol/eliza-plugin';
62
+ ### Guard pattern: fire-before-pay with `withTwzrdGuard`
63
+
64
+ For agents that call x402-gated URLs directly (not via pre-known seller wallet), pair this
65
+ plugin with `twzrd-x402-gate` to intercept 402s before any spend:
47
66
 
48
- const agent = new AgentRuntime({
49
- plugins: [wzrdPlugin],
67
+ ```typescript
68
+ import wzrdPlugin from '@wzrd_sol/eliza-plugin';
69
+ import { withTwzrdGuard } from 'twzrd-x402-gate';
70
+ import { createAgentcashFetch } from 'agentcash';
71
+
72
+ // Wrap the paying fetch — guard runs preflight on every 402 before USDC moves.
73
+ const x402Fetch = createAgentcashFetch({ apiKey: process.env.AGENTCASH_API_KEY });
74
+ const safeFetch = withTwzrdGuard(x402Fetch, {
75
+ autoReceipt: true, // auto-buy $0.05 TWZRD receipt on warn/allow
76
+ x402Fetch,
50
77
  });
78
+
79
+ // Wire safeFetch into any tool or skill that calls paid resources:
80
+ const response = await safeFetch('https://api.exa.ai/search');
81
+ // → decision=block throws before payment
82
+ // → decision=warn/allow: payment proceeds, TWZRD receipt captured
51
83
  ```
52
84
 
53
- Programmatic SDK calls (same types as the plugin) are re-exported:
85
+ Guard flow:
86
+ 1. `safeFetch` hits the resource, gets HTTP 402.
87
+ 2. `withTwzrdGuard` reads `accepts[0].payTo` (seller wallet).
88
+ 3. Calls `POST /v1/intel/preflight` — free, no auth.
89
+ 4. `block` - throws, no payment made.
90
+ 5. `warn/allow` - returns the 402 for the x402 client to pay.
91
+
92
+ ### Pre-spend gate (programmatic)
54
93
 
55
94
  ```typescript
56
- import { intelPreflight, fetchIntelTrust, verifyReceipt, IntelPaymentRequiredError } from '@wzrd_sol/eliza-plugin';
95
+ import { preSpendGate, fetchIntelTrust } from '@wzrd_sol/eliza-plugin';
96
+
97
+ // Gate before paying:
98
+ const gate = await preSpendGate({ seller_wallet: sellerPubkey });
99
+ if (!gate.allow) return `Blocked (${gate.decision}): ${gate.reason}`;
100
+
101
+ // Then pay and get the receipt:
102
+ const trust = await fetchIntelTrust(sellerPubkey, { fetchImpl: myX402Fetch });
57
103
  ```
58
104
 
59
- ## Intel actions (primary)
105
+ ### Paid trust receipt (agentcash)
60
106
 
61
- | Action | Auth/Pay | Description |
62
- |--------|----------|-------------|
63
- | `WZRD_INTEL_PREFLIGHT` | Free | ReadinessCard: decision, trust_score, can_spend, caveats, paid upsell |
64
- | `WZRD_INTEL_TRUST` | x402 (~0.05 USDC) | Paid trust payload + V5 `twzrd_receipt` (needs `setPayingFetch`) |
65
- | `WZRD_VERIFY_RECEIPT` | Free (offline) | Recompute leaf + Ed25519 verify; no network when pubkey is known |
107
+ ```typescript
108
+ import wzrdPlugin, { setPayingFetch } from '@wzrd_sol/eliza-plugin';
109
+ import { createAgentcashFetch } from 'agentcash';
66
110
 
67
- ### Example prompts
111
+ setPayingFetch(createAgentcashFetch({ apiKey: process.env.AGENTCASH_API_KEY }));
68
112
 
69
- - "Preflight Jupiter Quote Preview before I pay 0.25 USDC to 6EF8rrect..."
70
- - "Get the trust receipt for seller JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"
71
- - "Verify this receipt: {leaf, preimage, signature...}"
72
- - "Is it safe to call the paid intel endpoint on this seller?"
113
+ const agent = new AgentRuntime({ plugins: [wzrdPlugin] });
114
+ // "Get the trust receipt for seller JUP6LkbZ..."
115
+ // WZRD_INTEL_TRUST: runs free preflight, pays $0.05 USDC, returns VC
116
+ ```
73
117
 
74
- ### Free preflight (no wallet)
118
+ ### Paid trust receipt (PayAI)
75
119
 
76
120
  ```typescript
77
- import { intelPreflightAction } from '@wzrd_sol/eliza-plugin';
121
+ import wzrdPlugin, { setPayingFetch } from '@wzrd_sol/eliza-plugin';
122
+ import { PayAIClient } from '@payai/client';
78
123
 
79
- // Handler reads seller_wallet / price_usdc / agent_intent from message content
80
- await intelPreflightAction.handler(runtime, {
81
- content: {
82
- seller_wallet: 'JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4',
83
- price_usdc: 0.25,
84
- agent_intent: 'quote preview',
85
- },
86
- }, ...);
124
+ const payai = new PayAIClient({ keypairPath: '~/.config/solana/id.json' });
125
+ setPayingFetch((url, init) => payai.fetch(url, init));
126
+
127
+ const agent = new AgentRuntime({ plugins: [wzrdPlugin] });
87
128
  ```
88
129
 
130
+ Without a paying fetch, `WZRD_INTEL_TRUST` returns the HTTP 402 requirements and an
131
+ `npx agentcash@latest fetch ...` one-liner to pay manually.
132
+
133
+ **`WZRD_INTEL_TRUST` response fields:**
134
+
135
+ ```
136
+ Trust payload for JUP6Lkb...
137
+ Score: 61.8 Paid: yes
138
+ Settlement tx: 4xK3n...
139
+ Reputation credential (ERC-8004 AgentReputationCredential):
140
+ effectiveTrustScore: 62 <- route on this (wash-adjusted)
141
+ trustScore: 72 washFactor: 0.86
142
+ distinctCounterparties: 14 <- cross-facilitator breadth
143
+ corpusScope: cross-facilitator
144
+ version: intel_renorm_v1
145
+ Routing gate: effectiveTrustScore < 30 -> block, 30-60 -> warn, > 60 -> allow
146
+ Receipt v6, leaf: 0x3a4f...
147
+ Use WZRD_VERIFY_RECEIPT to verify offline.
148
+ ```
149
+
150
+ **Routing logic:**
151
+
152
+ ```typescript
153
+ const vc = trust.reputation_credential.credentialSubject;
154
+ if (vc.effectiveTrustScore < 30) return 'block';
155
+ if (vc.distinctCounterparties < 3) return 'warn'; // thin history
156
+ if (vc.washFactor < 0.5) return 'warn'; // suspicious ring
157
+ ```
158
+
159
+ `effectiveTrustScore` is the cross-facilitator wash-adjusted score — computed across all known
160
+ x402 facilitators, not just one settlement path.
161
+
162
+ ### Example agent prompts (trust)
163
+
164
+ - `"Preflight Jupiter Quote Preview before I pay 0.25 USDC to 6EF8rrect..."`
165
+ - `"Get the trust receipt for seller JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"`
166
+ - `"Is it safe to call the paid intel endpoint on this seller?"`
167
+ - `"Verify this receipt: {leaf, preimage, signature...}"`
168
+
89
169
  ## Legacy earn actions
90
170
 
91
171
  | Action | Auth | Description |
92
172
  |--------|------|-------------|
93
173
  | `WZRD_INFER` | Agent Ed25519 | Server-witnessed inference; returns `execution_id` |
94
174
  | `WZRD_REPORT` | Agent Ed25519 | Report outcome with `execution_id` for verified rewards |
95
- | `WZRD_EARN` | Agent Ed25519 | Full infer report rewards check in one action |
175
+ | `WZRD_EARN` | Agent Ed25519 | Full infer -> report -> rewards check in one action |
96
176
  | `WZRD_CLAIM` | Agent Ed25519 | Gasless CCM claim via relay |
97
177
  | `WZRD_REWARDS` | Agent Ed25519 | Pending and lifetime CCM balance |
98
178
 
99
179
  ### Example prompts (earn)
100
180
 
101
- - "Run inference through WZRD: explain quicksort in Python"
102
- - "Earn some CCM on WZRD"
103
- - "Check my WZRD rewards"
104
- - "Claim my CCM"
181
+ - `"Run inference through WZRD: explain quicksort in Python"`
182
+ - `"Earn some CCM on WZRD"`
183
+ - `"Check my WZRD rewards"`
184
+ - `"Claim my CCM"`
185
+
186
+ ## Programmatic SDK usage
187
+
188
+ ```typescript
189
+ import {
190
+ intelPreflight,
191
+ fetchIntelTrust,
192
+ verifyReceipt,
193
+ preSpendGate,
194
+ IntelPaymentRequiredError,
195
+ } from '@wzrd_sol/eliza-plugin';
196
+
197
+ import type {
198
+ ReadinessCard,
199
+ PreflightResponse,
200
+ IntelTrustResponse,
201
+ TwzrdReceipt,
202
+ } from '@wzrd_sol/eliza-plugin';
203
+ ```
105
204
 
106
205
  ## Test
107
206
 
@@ -112,7 +211,8 @@ npm run build
112
211
  npm test
113
212
  ```
114
213
 
115
- `npm test` loads the plugin into a real `@elizaos/core` `AgentRuntime`, runs live free preflight against `intel.twzrd.xyz`, offline receipt verify, and a mocked paid trust path.
214
+ `npm test` runs live free preflight against `intel.twzrd.xyz`, offline receipt verify, and a
215
+ mocked paid trust path.
116
216
 
117
217
  Manual earn smoke (requires `SOLANA_PRIVATE_KEY`):
118
218
 
@@ -123,11 +223,11 @@ npx tsx test/earn-e2e.ts
123
223
  ## Links
124
224
 
125
225
  - [Agent Intel API](https://intel.twzrd.xyz)
126
- - [Legacy API](https://api.twzrd.xyz)
127
- - [SDK](https://www.npmjs.com/package/@wzrd_sol/sdk)
128
- - [twzrd-agent-intel (Python/MCP)](https://github.com/twzrd-sol/wzrd-final/tree/main/packages/twzrd-agent-intel)
129
- - [Agent discovery](https://twzrd.xyz/llms.txt)
226
+ - [API docs / llms.txt](https://intel.twzrd.xyz/llms.txt)
227
+ - [x402 gate (standalone firewall)](https://www.npmjs.com/package/twzrd-x402-gate)
228
+ - [GOAT plugin](https://www.npmjs.com/package/@wzrd_sol/goat-plugin)
229
+ - [TWZRD trust quickstart](https://intel.twzrd.xyz/docs/QUICKSTART.md)
130
230
 
131
231
  ## License
132
232
 
133
- MIT
233
+ MIT
@@ -62,9 +62,9 @@ export const intelPreflightAction = {
62
62
  handler: async (runtime, message, _state, _opt, callback) => {
63
63
  const content = (message.content ?? {});
64
64
  const input = parsePreflightInput(content);
65
- if (!input.seller_wallet && !input.resource_name && !input.resource_url && !input.agent_intent) {
65
+ if (!input.seller_wallet && !input.resource_name && !input.resource_url) {
66
66
  await callback?.({
67
- text: 'Provide seller_wallet, resource_name, resource_url, or agent_intent for preflight. ' +
67
+ text: 'Provide seller_wallet, resource_name, or resource_url for preflight. ' +
68
68
  'Example: "Preflight seller JUP6Lkb... at 0.25 USDC"',
69
69
  });
70
70
  return { success: false, error: 'Missing preflight input' };
@@ -57,14 +57,21 @@ export const intelTrustAction = {
57
57
  return fetchIntelTrust(pubkey, { apiBase, fetchImpl: abortingFetch });
58
58
  });
59
59
  const receipt = res.twzrd_receipt;
60
- const text = `Trust payload for ${pubkey}\n` +
61
- `Score: ${res.trust?.score ?? 'n/a'}\n` +
62
- `Paid: ${res.paid ? 'yes' : 'no'}\n` +
63
- (res.tx ? `Settlement tx: ${res.tx}\n` : '') +
64
- (receipt
65
- ? `Receipt v${receipt.version}, leaf: ${receipt.leaf}\n` +
66
- `Use WZRD_VERIFY_RECEIPT to verify offline.`
67
- : 'No twzrd_receipt in response.');
60
+ const vc = res.reputation_credential?.credentialSubject;
61
+ const lines = [
62
+ `Trust payload for ${pubkey}`,
63
+ `Score: ${res.trust?.score ?? 'n/a'} Paid: ${res.paid ? 'yes' : 'no'}`,
64
+ ];
65
+ const settleTx = res.tx ?? res.tx_pending;
66
+ if (settleTx)
67
+ lines.push(`Settlement tx${res.tx ? '' : ' (pending)'}: ${settleTx}`);
68
+ if (vc) {
69
+ lines.push(`Reputation credential (ERC-8004 AgentReputationCredential):`, ` effectiveTrustScore: ${vc.effectiveTrustScore ?? 'n/a'}`, ` trustScore: ${vc.trustScore ?? 'n/a'} washFactor: ${vc.washFactor ?? 'n/a'}`, ` distinctCounterparties: ${vc.distinctCounterparties ?? 'n/a'}`, ` corpusScope: ${vc.corpusScope ?? 'n/a'}`, ` version: ${vc.trustScoreVersion ?? 'n/a'}`, `Routing gate: effectiveTrustScore < 30 → block, 30-60 → warn, > 60 → allow`);
70
+ }
71
+ lines.push(receipt
72
+ ? `Receipt v${receipt.version}, leaf: ${receipt.leaf}\nUse WZRD_VERIFY_RECEIPT to verify offline.`
73
+ : 'No twzrd_receipt in response.');
74
+ const text = lines.join('\n');
68
75
  await callback?.({ text });
69
76
  return { success: true, data: res };
70
77
  }
package/dist/client.d.ts CHANGED
@@ -75,7 +75,7 @@ export declare class WzrdClient {
75
75
  quality_score?: number;
76
76
  latency_ms?: number;
77
77
  }): Promise<ReportResult>;
78
- /** Check pending + total rewards (flattens nested /v1/agent/earned response) */
78
+ /** Check pending + total rewards (reads flat /v1/agent/earned response) */
79
79
  getRewards(): Promise<RewardsBalance>;
80
80
  /** Gasless CCM claim via server relay */
81
81
  claimRelay(): Promise<ClaimResult>;
package/dist/client.js CHANGED
@@ -87,19 +87,17 @@ export class WzrdClient {
87
87
  }
88
88
  return res.json();
89
89
  }
90
- /** Check pending + total rewards (flattens nested /v1/agent/earned response) */
90
+ /** Check pending + total rewards (reads flat /v1/agent/earned response) */
91
91
  async getRewards() {
92
92
  const res = await this.authedFetch('/v1/agent/earned');
93
93
  if (!res.ok)
94
94
  throw new Error(`Rewards check failed: ${res.status}`);
95
95
  const data = await res.json();
96
- const economy = data.economy;
97
- const routing = data.routing;
98
96
  return {
99
- pending_ccm: Number(economy?.pending_ccm ?? 0),
100
- total_rewarded_ccm: Number(economy?.earned_ccm ?? 0),
101
- rank: null, // rank not in this endpoint
102
- contribution_count: Number(routing?.lifetime_contributions ?? 0),
97
+ pending_ccm: Number(data.pending_ccm ?? 0),
98
+ total_rewarded_ccm: Number(data.total_earned_ccm ?? 0),
99
+ rank: data.rank == null ? null : Number(data.rank),
100
+ contribution_count: Number(data.lifetime_contributions ?? 0),
103
101
  };
104
102
  }
105
103
  /** Gasless CCM claim via server relay */
@@ -41,9 +41,10 @@ export function parseReceipt(content) {
41
41
  }
42
42
  return null;
43
43
  }
44
+ const SOLANA_PUBKEY_RE = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
44
45
  export function extractPubkey(content) {
45
46
  const direct = str(content.pubkey ?? content.seller_wallet ?? content.wallet);
46
- if (direct)
47
+ if (direct && SOLANA_PUBKEY_RE.test(direct))
47
48
  return direct;
48
49
  const text = str(content.text);
49
50
  if (!text)
@@ -51,7 +52,7 @@ export function extractPubkey(content) {
51
52
  const fromJson = tryParseJson(text);
52
53
  if (fromJson) {
53
54
  const w = str(fromJson.pubkey ?? fromJson.seller_wallet ?? fromJson.wallet);
54
- if (w)
55
+ if (w && SOLANA_PUBKEY_RE.test(w))
55
56
  return w;
56
57
  }
57
58
  return extractWallet(text);
@@ -71,7 +72,10 @@ export function formatPaymentRequired(err, apiBase, pubkey) {
71
72
  `No paying fetch configured. Wire one before runtime creation:\n` +
72
73
  ` import { setPayingFetch } from '@wzrd_sol/eliza-plugin';\n` +
73
74
  ` setPayingFetch(myAgentcashFetch);\n\n` +
74
- `Or pay out of band:\n` +
75
+ `Pay out of band only with an x402 client that preserves the sponsored fee-payer slot.\n` +
76
+ `Caveat: npx agentcash@latest fetch is not currently a green TWZRD repro; ` +
77
+ `it failed closed with payment_invalid / fee_payer_slot_already_signed on 2026-06-23.\n` +
78
+ `Known-bad compatibility command:\n` +
75
79
  ` npx agentcash@latest fetch ${url}`);
76
80
  }
77
81
  function str(v) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wzrd_sol/eliza-plugin",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "WZRD Agent Intel for ElizaOS — preflight ReadinessCards, x402-paid signed trust receipts (V6 reputation leaf), offline verification on intel.twzrd.xyz. Also ships the legacy earn loop.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -59,8 +59,8 @@
59
59
  },
60
60
  "repository": {
61
61
  "type": "git",
62
- "url": "git+https://github.com/twzrd-sol/twzrd-trust.git",
63
- "directory": "eliza-plugin"
62
+ "url": "git+https://github.com/twzrd-sol/wzrd-final.git",
63
+ "directory": "agents/eliza-plugin"
64
64
  },
65
65
  "bugs": {
66
66
  "url": "https://github.com/twzrd-sol/twzrd-trust/issues"