@wzrd_sol/eliza-plugin 0.7.1 → 0.8.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/README.md +16 -17
- package/dist/actions/intel-preflight.js +6 -3
- package/dist/actions/intel-trust.d.ts +14 -1
- package/dist/actions/intel-trust.js +63 -6
- package/dist/actions/merchant-card.d.ts +8 -0
- package/dist/actions/merchant-card.js +41 -9
- package/dist/client-factory.d.ts +1 -4
- package/dist/client-factory.js +7 -23
- package/dist/index.d.ts +9 -21
- package/dist/index.js +10 -27
- package/dist/paying-fetch.d.ts +17 -1
- package/dist/paying-fetch.js +43 -1
- package/package.json +3 -6
- package/dist/actions/claim.d.ts +0 -6
- package/dist/actions/claim.js +0 -48
- package/dist/actions/earn.d.ts +0 -8
- package/dist/actions/earn.js +0 -83
- package/dist/actions/infer.d.ts +0 -8
- package/dist/actions/infer.js +0 -41
- package/dist/actions/report.d.ts +0 -8
- package/dist/actions/report.js +0 -45
- package/dist/actions/rewards.d.ts +0 -5
- package/dist/actions/rewards.js +0 -31
- package/dist/client.d.ts +0 -92
- package/dist/client.js +0 -138
package/README.md
CHANGED
|
@@ -7,7 +7,8 @@ trust receipts, and offline verification. Default path (0.7+):
|
|
|
7
7
|
seller → preflight → merchant_card → policy → optional V7 trust receipt → sign or refuse
|
|
8
8
|
```
|
|
9
9
|
|
|
10
|
-
The default export registers **intel actions only**.
|
|
10
|
+
The default export registers **intel actions only**. 0.8.0 removed the retired AO/CCM earn actions
|
|
11
|
+
(`WZRD_INFER`, `WZRD_REPORT`, `WZRD_EARN`, `WZRD_CLAIM`, `WZRD_REWARDS`) and the `legacyEarnActions` option.
|
|
11
12
|
|
|
12
13
|
## Buyer sequence (marketplace default)
|
|
13
14
|
|
|
@@ -49,16 +50,15 @@ npm install @wzrd_sol/eliza-plugin
|
|
|
49
50
|
| Variable | Required | Default | Description |
|
|
50
51
|
|----------|----------|---------|-------------|
|
|
51
52
|
| `WZRD_INTEL_URL` | No | `https://intel.twzrd.xyz` | Agent Intel API (preflight, merchant_card, trust, verify) |
|
|
52
|
-
| `
|
|
53
|
-
| `SOLANA_PRIVATE_KEY` | Legacy earn only | - | JSON array of secret key bytes for agent Ed25519 auth |
|
|
53
|
+
| `WZRD_INTEL_ALLOW_PAID` | For paid lookups | unset (off) | `true` lets `WZRD_INTEL_TRUST` spend ~0.05 USDC without a per-message `confirm_spend: true` |
|
|
54
54
|
|
|
55
55
|
## Intel actions (primary)
|
|
56
56
|
|
|
57
57
|
| Action | Auth/Pay | Description |
|
|
58
58
|
|--------|----------|-------------|
|
|
59
59
|
| `WZRD_INTEL_PREFLIGHT` | Free | ReadinessCard: `decision`, `trust_score`, `can_spend`, `caveats`, `preflight_id` |
|
|
60
|
-
| `WZRD_MERCHANT_CARD` | Free | Graph card: `wash_flagged`, tier, catalog join; **
|
|
61
|
-
| `WZRD_INTEL_TRUST` | x402 (~0.05 USDC) | Paid trust payload + **V7** signed receipt + ERC-8004 `reputation_credential` |
|
|
60
|
+
| `WZRD_MERCHANT_CARD` | Free | Graph card: `wash_flagged`, coverage, tier, catalog join; **refuse if wash**; card unavailable = **refuse** (fail-closed) |
|
|
61
|
+
| `WZRD_INTEL_TRUST` | x402 (~0.05 USDC) | Paid trust payload + **V7** signed receipt + ERC-8004 `reputation_credential`. Needs `WZRD_INTEL_ALLOW_PAID=true` or `confirm_spend: true`; every refusal returns a zero-spend `twzrd.gate_eval_refuse.v1` record in `data.refuse` |
|
|
62
62
|
| `WZRD_VERIFY_RECEIPT` | Free (offline) | Leaf + Ed25519 verify via `twzrd-receipt-verifier`; V7 current, V6 labeled legacy |
|
|
63
63
|
|
|
64
64
|
### Receipt versions
|
|
@@ -122,6 +122,7 @@ const agent = new AgentRuntime({ plugins: [wzrdPlugin] });
|
|
|
122
122
|
```
|
|
123
123
|
|
|
124
124
|
`payWrap` receives the **guarded** fetch. Opt out with `TWZRD_AUTO_GATE=0` or `{ disabled: true }`.
|
|
125
|
+
Lookups carry `X-TWZRD-Integration: eliza-plugin/<version>` unless you pass your own `attribution`.
|
|
125
126
|
|
|
126
127
|
### Paid trust receipt
|
|
127
128
|
|
|
@@ -131,23 +132,21 @@ import { createAgentcashFetch } from 'agentcash';
|
|
|
131
132
|
|
|
132
133
|
setPayingFetch(createAgentcashFetch({ apiKey: process.env.AGENTCASH_API_KEY }));
|
|
133
134
|
const agent = new AgentRuntime({ plugins: [wzrdPlugin] });
|
|
134
|
-
// WZRD_INTEL_TRUST
|
|
135
|
-
// returns VC + V7 receipt, then offline-verifies
|
|
135
|
+
// WZRD_INTEL_TRUST (with WZRD_INTEL_ALLOW_PAID=true or confirm_spend: true): free preflight +
|
|
136
|
+
// merchant_card, then pays ~$0.05 USDC, returns VC + V7 receipt, then offline-verifies
|
|
137
|
+
// before labeling freshness=signed
|
|
136
138
|
```
|
|
137
139
|
|
|
138
140
|
Without a paying fetch, `WZRD_INTEL_TRUST` returns the HTTP 402 requirements.
|
|
139
141
|
|
|
140
|
-
##
|
|
142
|
+
## 0.8.0 changes (breaking)
|
|
141
143
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
plugins: [createWzrdPlugin({ legacyEarnActions: true })],
|
|
149
|
-
});
|
|
150
|
-
```
|
|
144
|
+
- Removed the retired earn actions, `legacyEarnActions`, `wzrdPluginWithLegacyEarn`, `WzrdClient`,
|
|
145
|
+
`getWzrdClient` and `clearClientCache`. The plugin no longer reads `SOLANA_PRIVATE_KEY` or `WZRD_API_URL`.
|
|
146
|
+
- `WZRD_INTEL_TRUST` spends only with `WZRD_INTEL_ALLOW_PAID=true` or `confirm_spend: true`.
|
|
147
|
+
- `WZRD_MERCHANT_CARD` is fail-closed when the card is unavailable (`refuse_pay: true`).
|
|
148
|
+
- A paid trust lookup also refuses, with no spend, when that card lookup does not answer. A card that answers with incomplete wash coverage is reported, not refused, on gate 0.12.5 (`refuseWashUnknown` stays opt-in until 0.13.0).
|
|
149
|
+
- Depends on `twzrd-x402-gate` exactly `0.12.5`. Fetches this plugin owns stamp `X-Twzrd-Caller: eliza-plugin/<version>@0.12.5`.
|
|
151
150
|
|
|
152
151
|
## Programmatic SDK usage
|
|
153
152
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { intelPreflight } from '@wzrd_sol/sdk';
|
|
2
2
|
import { getIntelBase, parsePreflightInput, withTimeout } from '../intel-helpers.js';
|
|
3
|
+
import { callerTag } from '../paying-fetch.js';
|
|
3
4
|
function isValidBase58Wallet(s) {
|
|
4
5
|
if (!s)
|
|
5
6
|
return false;
|
|
@@ -77,7 +78,7 @@ export const intelPreflightAction = {
|
|
|
77
78
|
}
|
|
78
79
|
const apiBase = getIntelBase(runtime);
|
|
79
80
|
try {
|
|
80
|
-
const res = await withTimeout(() => intelPreflight(input, apiBase));
|
|
81
|
+
const res = await withTimeout(() => intelPreflight(input, apiBase, callerTag()));
|
|
81
82
|
const card = res.readiness_card;
|
|
82
83
|
if (!card) {
|
|
83
84
|
const text = `Preflight OK (legacy). decision=${res.decision ?? 'unknown'}, score=${res.trust_score ?? 'n/a'}`;
|
|
@@ -91,8 +92,10 @@ export const intelPreflightAction = {
|
|
|
91
92
|
}
|
|
92
93
|
catch (err) {
|
|
93
94
|
const msg = err instanceof Error ? err.message : String(err);
|
|
94
|
-
await callback?.({
|
|
95
|
-
|
|
95
|
+
await callback?.({
|
|
96
|
+
text: `Preflight failed: ${msg}. The check could not finish; do not pay this pay_to (fail-closed).`,
|
|
97
|
+
});
|
|
98
|
+
return { success: false, error: msg, data: { refuse_pay: true, reason: 'preflight_unavailable' } };
|
|
96
99
|
}
|
|
97
100
|
},
|
|
98
101
|
};
|
|
@@ -6,5 +6,18 @@
|
|
|
6
6
|
* Current service surface is V7. Legacy V6/V5 payloads are labeled, not treated
|
|
7
7
|
* as the current receipt policy.
|
|
8
8
|
*/
|
|
9
|
-
import type { Action } from '@elizaos/core';
|
|
9
|
+
import type { Action, IAgentRuntime } from '@elizaos/core';
|
|
10
|
+
export type RefusePacket = {
|
|
11
|
+
schema: 'twzrd.gate_eval_refuse.v1';
|
|
12
|
+
rail: 'eliza-plugin';
|
|
13
|
+
subject: string;
|
|
14
|
+
reason: string;
|
|
15
|
+
signer_invocation_count: 0;
|
|
16
|
+
usdc_spent: 0;
|
|
17
|
+
at: string;
|
|
18
|
+
};
|
|
19
|
+
/** Zero-spend refusal record, the same shape monid-x402 writes before any signer exists. */
|
|
20
|
+
export declare function refusePacket(reason: string, subject: string): RefusePacket;
|
|
21
|
+
/** A paid lookup proceeds only with WZRD_INTEL_ALLOW_PAID (true/1) or content.confirm_spend === true. */
|
|
22
|
+
export declare function paidLookupConfirmed(runtime: Pick<IAgentRuntime, 'getSetting'>, content: Record<string, unknown>): boolean;
|
|
10
23
|
export declare const intelTrustAction: Action;
|
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
import { fetchIntelTrust, preSpendGate, IntelPaymentRequiredError } from '@wzrd_sol/sdk';
|
|
2
2
|
import { extractPubkey, formatPaymentRequired, getIntelBase, withTimeout } from '../intel-helpers.js';
|
|
3
|
-
import { resolvePayingFetch } from '../paying-fetch.js';
|
|
3
|
+
import { callerTag, resolvePayingFetch, withTracking } from '../paying-fetch.js';
|
|
4
4
|
import { classifyReceipt, describeReceiptSurface, freshnessFromVerify, verifyReceipt, } from '../receipt-verify.js';
|
|
5
|
+
/** Zero-spend refusal record, the same shape monid-x402 writes before any signer exists. */
|
|
6
|
+
export function refusePacket(reason, subject) {
|
|
7
|
+
return {
|
|
8
|
+
schema: 'twzrd.gate_eval_refuse.v1',
|
|
9
|
+
rail: 'eliza-plugin',
|
|
10
|
+
subject,
|
|
11
|
+
reason,
|
|
12
|
+
signer_invocation_count: 0,
|
|
13
|
+
usdc_spent: 0,
|
|
14
|
+
at: new Date().toISOString(),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** A paid lookup proceeds only with WZRD_INTEL_ALLOW_PAID (true/1) or content.confirm_spend === true. */
|
|
18
|
+
export function paidLookupConfirmed(runtime, content) {
|
|
19
|
+
if (content.confirm_spend === true)
|
|
20
|
+
return true;
|
|
21
|
+
const v = runtime.getSetting('WZRD_INTEL_ALLOW_PAID');
|
|
22
|
+
if (v === true || v === 1)
|
|
23
|
+
return true;
|
|
24
|
+
return typeof v === 'string' && ['true', '1'].includes(v.trim().toLowerCase());
|
|
25
|
+
}
|
|
5
26
|
export const intelTrustAction = {
|
|
6
27
|
name: 'WZRD_INTEL_TRUST',
|
|
7
28
|
similes: ['WZRD_TRUST_RECEIPT', 'INTEL_TRUST', 'GET_TRUST_RECEIPT'],
|
|
@@ -9,7 +30,8 @@ export const intelTrustAction = {
|
|
|
9
30
|
'twzrd_receipt (portable offline proof; freshness fields are leaf-bound). Runs free preflight + merchant_card ' +
|
|
10
31
|
'wash check first; aborts on decision=block or wash_flagged before any spend. ' +
|
|
11
32
|
'Legacy V6 receipts, if still returned, are labeled freshness=derived_from_timestamp. ' +
|
|
12
|
-
'Requires an x402-capable fetchImpl (setPayingFetch or host service)
|
|
33
|
+
'Requires an x402-capable fetchImpl (setPayingFetch or host service), and a spend confirmation: ' +
|
|
34
|
+
'runtime setting WZRD_INTEL_ALLOW_PAID=true or message content confirm_spend: true. Without one, nothing is paid.',
|
|
13
35
|
examples: [
|
|
14
36
|
[
|
|
15
37
|
{ name: '{{user1}}', content: { text: 'Get the trust receipt for seller JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4' } },
|
|
@@ -24,10 +46,22 @@ export const intelTrustAction = {
|
|
|
24
46
|
await callback?.({ text: 'Provide a seller pubkey (32-44 char base58) for trust lookup.' });
|
|
25
47
|
return { success: false, error: 'Missing pubkey' };
|
|
26
48
|
}
|
|
49
|
+
if (!paidLookupConfirmed(runtime, content)) {
|
|
50
|
+
await callback?.({
|
|
51
|
+
text: `Trust lookup for ${pubkey} costs ~0.05 USDC and was not confirmed. ` +
|
|
52
|
+
`Set WZRD_INTEL_ALLOW_PAID=true for this agent, or send the request with confirm_spend: true. ` +
|
|
53
|
+
`No payment was sent.`,
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
success: false,
|
|
57
|
+
error: 'spend_not_confirmed',
|
|
58
|
+
data: { refuse: refusePacket('spend_not_confirmed', pubkey) },
|
|
59
|
+
};
|
|
60
|
+
}
|
|
27
61
|
const apiBase = getIntelBase(runtime);
|
|
28
62
|
const baseFetchImpl = resolvePayingFetch(runtime);
|
|
29
63
|
try {
|
|
30
|
-
const gate = await preSpendGate({ seller_wallet: pubkey }, { apiBase, failOpen: false, refuseWashFlagged: true, fetchImpl: baseFetchImpl });
|
|
64
|
+
const gate = await preSpendGate({ seller_wallet: pubkey }, { apiBase, failOpen: false, refuseWashFlagged: true, fetchImpl: withTracking(baseFetchImpl) });
|
|
31
65
|
if (!gate.allow) {
|
|
32
66
|
const washLine = gate.washFlagged === true ? `Wash flagged: yes (merchant_card refuse default)\n` : '';
|
|
33
67
|
await callback?.({
|
|
@@ -37,27 +71,50 @@ export const intelTrustAction = {
|
|
|
37
71
|
`Reason: ${gate.reason}\n` +
|
|
38
72
|
`No payment was sent.`,
|
|
39
73
|
});
|
|
74
|
+
const error = gate.washFlagged === true ? 'wash_flagged' : 'preflight_block';
|
|
40
75
|
return {
|
|
41
76
|
success: false,
|
|
42
|
-
error
|
|
77
|
+
error,
|
|
43
78
|
data: {
|
|
44
79
|
decision: gate.decision,
|
|
45
80
|
trustScore: gate.trustScore,
|
|
46
81
|
reason: gate.reason,
|
|
47
82
|
washFlagged: gate.washFlagged ?? null,
|
|
83
|
+
refuse: refusePacket(error, pubkey),
|
|
48
84
|
},
|
|
49
85
|
};
|
|
50
86
|
}
|
|
87
|
+
// The SDK returns allow=true with merchantCard=null when the card lookup
|
|
88
|
+
// cannot finish. 0.12.x does not refuse unknown coverage; a missing card does.
|
|
89
|
+
if (gate.merchantCard == null) {
|
|
90
|
+
await callback?.({
|
|
91
|
+
text: `Merchant card unavailable for ${pubkey}, so the wash check could not finish. ` +
|
|
92
|
+
`Fail-closed: do not pay this pay_to. No payment was sent.`,
|
|
93
|
+
});
|
|
94
|
+
return {
|
|
95
|
+
success: false,
|
|
96
|
+
error: 'merchant_card_unavailable',
|
|
97
|
+
data: { refuse: refusePacket('merchant_card_unavailable', pubkey) },
|
|
98
|
+
};
|
|
99
|
+
}
|
|
51
100
|
}
|
|
52
101
|
catch (gateErr) {
|
|
53
102
|
const msg = gateErr instanceof Error ? gateErr.message : String(gateErr);
|
|
54
103
|
await callback?.({ text: `Preflight gate unavailable (${msg}); not spending. Try again shortly.` });
|
|
55
|
-
return {
|
|
104
|
+
return {
|
|
105
|
+
success: false,
|
|
106
|
+
error: 'preflight_unavailable',
|
|
107
|
+
data: { detail: msg, refuse: refusePacket('preflight_unavailable', pubkey) },
|
|
108
|
+
};
|
|
56
109
|
}
|
|
57
110
|
try {
|
|
58
111
|
const res = await withTimeout((signal) => {
|
|
59
112
|
const abortingFetch = ((input, init) => baseFetchImpl(input, { ...(init || {}), signal }));
|
|
60
|
-
return fetchIntelTrust(pubkey, {
|
|
113
|
+
return fetchIntelTrust(pubkey, {
|
|
114
|
+
apiBase,
|
|
115
|
+
fetchImpl: withTracking(abortingFetch),
|
|
116
|
+
caller: callerTag(),
|
|
117
|
+
});
|
|
61
118
|
});
|
|
62
119
|
const paid = res;
|
|
63
120
|
const receipt = paid.twzrd_receipt;
|
|
@@ -4,4 +4,12 @@
|
|
|
4
4
|
* file did not exist in the 98e4b78 historical source baseline.
|
|
5
5
|
*/
|
|
6
6
|
import type { Action } from '@elizaos/core';
|
|
7
|
+
import { type MerchantCard } from '@wzrd_sol/sdk';
|
|
8
|
+
type Coverage = {
|
|
9
|
+
washConfidence: string | null;
|
|
10
|
+
coverageFull: boolean;
|
|
11
|
+
};
|
|
12
|
+
/** Same coverage rule as twzrd-x402-gate isWashCoverageAdequate: full, ring evaluated, not stale. */
|
|
13
|
+
export declare function cardCoverage(card: MerchantCard): Coverage;
|
|
7
14
|
export declare const merchantCardAction: Action;
|
|
15
|
+
export {};
|
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
import { fetchMerchantCard } from '@wzrd_sol/sdk';
|
|
2
2
|
import { extractPubkey, getIntelBase, withTimeout } from '../intel-helpers.js';
|
|
3
|
-
|
|
3
|
+
import { withTracking } from '../paying-fetch.js';
|
|
4
|
+
/** Same coverage rule as twzrd-x402-gate isWashCoverageAdequate: full, ring evaluated, not stale. */
|
|
5
|
+
export function cardCoverage(card) {
|
|
6
|
+
const rec = card;
|
|
7
|
+
const raw = typeof rec.wash_confidence === 'string' && rec.wash_confidence.trim()
|
|
8
|
+
? rec.wash_confidence
|
|
9
|
+
: typeof rec.confidence === 'string' && rec.confidence.trim()
|
|
10
|
+
? rec.confidence
|
|
11
|
+
: null;
|
|
12
|
+
const washConfidence = raw ? raw.trim() : null;
|
|
13
|
+
const signals = rec.circular_flow_signals;
|
|
14
|
+
const ringEvaluated = typeof rec.ring_evaluated === 'boolean'
|
|
15
|
+
? rec.ring_evaluated
|
|
16
|
+
: typeof signals?.ring_evaluated === 'boolean'
|
|
17
|
+
? signals.ring_evaluated
|
|
18
|
+
: null;
|
|
19
|
+
const coverageFull = washConfidence?.toLowerCase() === 'full' && ringEvaluated !== false && rec.wash_stale !== true;
|
|
20
|
+
return { washConfidence, coverageFull };
|
|
21
|
+
}
|
|
22
|
+
function formatMerchantCard(card, coverage) {
|
|
4
23
|
const lines = [
|
|
5
24
|
`Merchant card for ${card.merchant ?? 'unknown'}`,
|
|
6
25
|
`In corpus: ${card.in_corpus ? 'yes' : 'no'}`,
|
|
7
26
|
`Wash flagged: ${card.wash_flagged === true ? 'YES — default refuse pay' : card.wash_flagged === false ? 'no' : 'unknown'}`,
|
|
27
|
+
`Wash coverage: ${coverage.washConfidence ?? 'none'}${coverage.coverageFull ? ' (full)' : ''}`,
|
|
8
28
|
];
|
|
9
29
|
if (card.wash_label)
|
|
10
30
|
lines.push(`Wash label: ${card.wash_label}`);
|
|
@@ -26,6 +46,9 @@ function formatMerchantCard(card) {
|
|
|
26
46
|
if (card.wash_flagged === true) {
|
|
27
47
|
lines.push('Policy: do not pay this pay_to (trustless default). Cap only if operator set washMaxUsdc.');
|
|
28
48
|
}
|
|
49
|
+
else if (card.wash_flagged !== false || !coverage.coverageFull) {
|
|
50
|
+
lines.push('Wash status unknown: not a clean bill. Strict hosts (twzrd-x402-gate refuseWashUnknown) refuse this pay_to.');
|
|
51
|
+
}
|
|
29
52
|
return lines.join('\n');
|
|
30
53
|
}
|
|
31
54
|
export const merchantCardAction = {
|
|
@@ -33,7 +56,7 @@ export const merchantCardAction = {
|
|
|
33
56
|
similes: ['WZRD_MERCHANT', 'MERCHANT_CARD', 'INTEL_MERCHANT_CARD', 'CHECK_WASH'],
|
|
34
57
|
description: 'Free GET merchant demand-quality card for a Solana receive wallet (no auth). ' +
|
|
35
58
|
'Returns wash_flagged, tier, unique payers, catalog join when listed. ' +
|
|
36
|
-
'Default: if wash_flagged is true, do not pay that pay_to.',
|
|
59
|
+
'Default: if wash_flagged is true, do not pay that pay_to. If the card is unavailable, do not pay (fail-closed).',
|
|
37
60
|
examples: [
|
|
38
61
|
[
|
|
39
62
|
{
|
|
@@ -58,28 +81,37 @@ export const merchantCardAction = {
|
|
|
58
81
|
}
|
|
59
82
|
const apiBase = getIntelBase(runtime);
|
|
60
83
|
try {
|
|
61
|
-
const card = await withTimeout(() => fetchMerchantCard(pubkey, { apiBase }));
|
|
84
|
+
const card = await withTimeout(() => fetchMerchantCard(pubkey, { apiBase, fetchImpl: withTracking(globalThis.fetch) }));
|
|
62
85
|
if (!card) {
|
|
63
86
|
await callback?.({
|
|
64
|
-
text: `Merchant card unavailable for ${pubkey} (network or invalid). ` +
|
|
65
|
-
`Fail-
|
|
87
|
+
text: `Merchant card unavailable for ${pubkey} (network or invalid), so the wash check could not run. ` +
|
|
88
|
+
`Fail-closed: do not pay this pay_to until a merchant card answers.`,
|
|
66
89
|
});
|
|
67
|
-
return {
|
|
90
|
+
return {
|
|
91
|
+
success: false,
|
|
92
|
+
error: 'merchant_card_unavailable',
|
|
93
|
+
data: { refuse_pay: true, reason: 'merchant_card_unavailable' },
|
|
94
|
+
};
|
|
68
95
|
}
|
|
69
|
-
const
|
|
96
|
+
const coverage = cardCoverage(card);
|
|
97
|
+
const text = formatMerchantCard(card, coverage);
|
|
70
98
|
await callback?.({ text });
|
|
71
99
|
return {
|
|
72
100
|
success: true,
|
|
73
101
|
data: {
|
|
74
102
|
...card,
|
|
103
|
+
wash_confidence: coverage.washConfidence,
|
|
104
|
+
coverage_full: coverage.coverageFull,
|
|
75
105
|
refuse_pay: card.wash_flagged === true,
|
|
76
106
|
},
|
|
77
107
|
};
|
|
78
108
|
}
|
|
79
109
|
catch (err) {
|
|
80
110
|
const msg = err instanceof Error ? err.message : String(err);
|
|
81
|
-
await callback?.({
|
|
82
|
-
|
|
111
|
+
await callback?.({
|
|
112
|
+
text: `Merchant card failed: ${msg}. The wash check could not run; do not pay this pay_to (fail-closed).`,
|
|
113
|
+
});
|
|
114
|
+
return { success: false, error: msg, data: { refuse_pay: true, reason: 'merchant_card_error' } };
|
|
83
115
|
}
|
|
84
116
|
},
|
|
85
117
|
};
|
package/dist/client-factory.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/** Intel client factory: reads WZRD_INTEL_URL + the host's paying fetch. */
|
|
2
2
|
import type { IAgentRuntime } from '@elizaos/core';
|
|
3
3
|
import { intelPreflight } from '@wzrd_sol/sdk';
|
|
4
4
|
import { verifyReceipt } from './receipt-verify.js';
|
|
5
5
|
/** Intel API base URL from runtime settings (default https://intel.twzrd.xyz). */
|
|
6
6
|
export declare function getIntelApiBase(runtime: IAgentRuntime): string;
|
|
7
|
-
export declare function getWzrdClient(runtime: IAgentRuntime): WzrdClient;
|
|
8
|
-
/** Reset client cache — useful for tests. */
|
|
9
|
-
export declare function clearClientCache(): void;
|
|
10
7
|
/** Intel client (per plan): reads WZRD_INTEL_URL + paying fetch; thin delegate to SDK. */
|
|
11
8
|
export declare function getIntelClient(runtime: IAgentRuntime): {
|
|
12
9
|
preflight: (input: Parameters<typeof intelPreflight>[0]) => Promise<import("@wzrd_sol/sdk").PreflightResponse>;
|
package/dist/client-factory.js
CHANGED
|
@@ -1,40 +1,24 @@
|
|
|
1
|
-
/** Extract keypair from ElizaOS runtime, return cached WzrdClient. */
|
|
2
|
-
import { Keypair } from '@solana/web3.js';
|
|
3
|
-
import { WzrdClient } from './client.js';
|
|
4
1
|
import { getIntelBase, withTimeout } from './intel-helpers.js';
|
|
5
|
-
import { resolvePayingFetch } from './paying-fetch.js';
|
|
2
|
+
import { callerTag, resolvePayingFetch, withTracking } from './paying-fetch.js';
|
|
6
3
|
import { intelPreflight, fetchIntelTrust } from '@wzrd_sol/sdk';
|
|
7
4
|
import { verifyReceipt } from './receipt-verify.js';
|
|
8
|
-
const cache = new Map();
|
|
9
5
|
/** Intel API base URL from runtime settings (default https://intel.twzrd.xyz). */
|
|
10
6
|
export function getIntelApiBase(runtime) {
|
|
11
7
|
return getIntelBase(runtime);
|
|
12
8
|
}
|
|
13
|
-
export function getWzrdClient(runtime) {
|
|
14
|
-
const sk = runtime.getSetting('SOLANA_PRIVATE_KEY');
|
|
15
|
-
if (!sk)
|
|
16
|
-
throw new Error('SOLANA_PRIVATE_KEY not configured in ElizaOS runtime');
|
|
17
|
-
const kp = Keypair.fromSecretKey(Uint8Array.from(JSON.parse(String(sk))));
|
|
18
|
-
const pub = kp.publicKey.toBase58();
|
|
19
|
-
if (!cache.has(pub)) {
|
|
20
|
-
const apiUrl = runtime.getSetting('WZRD_API_URL');
|
|
21
|
-
cache.set(pub, new WzrdClient(kp, typeof apiUrl === 'string' ? apiUrl : undefined));
|
|
22
|
-
}
|
|
23
|
-
return cache.get(pub);
|
|
24
|
-
}
|
|
25
|
-
/** Reset client cache — useful for tests. */
|
|
26
|
-
export function clearClientCache() {
|
|
27
|
-
cache.clear();
|
|
28
|
-
}
|
|
29
9
|
/** Intel client (per plan): reads WZRD_INTEL_URL + paying fetch; thin delegate to SDK. */
|
|
30
10
|
export function getIntelClient(runtime) {
|
|
31
11
|
const apiBase = getIntelApiBase(runtime);
|
|
32
12
|
return {
|
|
33
|
-
preflight: (input) => withTimeout(() => intelPreflight(input, apiBase)),
|
|
13
|
+
preflight: (input) => withTimeout(() => intelPreflight(input, apiBase, callerTag())),
|
|
34
14
|
trust: (pubkey) => withTimeout((signal) => {
|
|
35
15
|
const f = resolvePayingFetch(runtime);
|
|
36
16
|
const abortingFetch = ((input, init) => f(input, { ...(init || {}), signal }));
|
|
37
|
-
return fetchIntelTrust(pubkey, {
|
|
17
|
+
return fetchIntelTrust(pubkey, {
|
|
18
|
+
apiBase,
|
|
19
|
+
fetchImpl: withTracking(abortingFetch),
|
|
20
|
+
caller: callerTag(),
|
|
21
|
+
});
|
|
38
22
|
}),
|
|
39
23
|
verify: (receipt, opts) => verifyReceipt(receipt, opts),
|
|
40
24
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,41 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @wzrd_sol/eliza-plugin-source — V7-migrated
|
|
2
|
+
* @wzrd_sol/eliza-plugin-source — V7-migrated TWZRD Agent Intel for ElizaOS
|
|
3
3
|
*
|
|
4
4
|
* Intel lane (default https://intel.twzrd.xyz):
|
|
5
5
|
* WZRD_INTEL_PREFLIGHT → WZRD_MERCHANT_CARD → WZRD_INTEL_TRUST → WZRD_VERIFY_RECEIPT
|
|
6
6
|
* Paid intel requires a caller-supplied x402 fetch — either setPayingFetch(payingFetch)
|
|
7
7
|
* or installTwzrdAutoGate(payWrap). Current paid receipt surface is V7.
|
|
8
|
+
* Paid lookups need WZRD_INTEL_ALLOW_PAID=true or content.confirm_spend === true.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
* WZRD_INFER → WZRD_REPORT → WZRD_EARN → WZRD_CLAIM / WZRD_REWARDS on api.twzrd.xyz
|
|
10
|
+
* 0.8.0 removed the retired earn actions (infer/report/earn/claim/rewards).
|
|
11
11
|
*/
|
|
12
12
|
import type { Action, Plugin } from '@elizaos/core';
|
|
13
|
-
import { inferAction } from './actions/infer.js';
|
|
14
|
-
import { reportAction } from './actions/report.js';
|
|
15
|
-
import { earnAction } from './actions/earn.js';
|
|
16
|
-
import { claimAction } from './actions/claim.js';
|
|
17
|
-
import { rewardsAction } from './actions/rewards.js';
|
|
18
13
|
import { intelPreflightAction } from './actions/intel-preflight.js';
|
|
19
14
|
import { merchantCardAction } from './actions/merchant-card.js';
|
|
20
15
|
import { intelTrustAction } from './actions/intel-trust.js';
|
|
21
16
|
import { verifyReceiptAction } from './actions/verify-receipt.js';
|
|
22
17
|
export declare const intelActions: Action[];
|
|
23
|
-
export declare
|
|
24
|
-
export interface WzrdPluginOptions {
|
|
25
|
-
/** Register WZRD_INFER / REPORT / EARN / CLAIM / REWARDS (0.5.x default; off in 0.6+). */
|
|
26
|
-
legacyEarnActions?: boolean;
|
|
27
|
-
}
|
|
28
|
-
export declare function createWzrdPlugin(options?: WzrdPluginOptions): Plugin;
|
|
18
|
+
export declare function createWzrdPlugin(): Plugin;
|
|
29
19
|
/** Default plugin: intel actions only (0.6+). */
|
|
30
20
|
export declare const wzrdPlugin: Plugin;
|
|
31
|
-
/** Pre-0.6 compatibility: intel + legacy earn actions. */
|
|
32
|
-
export declare const wzrdPluginWithLegacyEarn: Plugin;
|
|
33
21
|
export default wzrdPlugin;
|
|
34
|
-
export { intelPreflightAction, merchantCardAction, intelTrustAction, verifyReceiptAction,
|
|
35
|
-
export {
|
|
36
|
-
export { setPayingFetch, clearPayingFetch, resolvePayingFetch, installTwzrdAutoGate, } from './paying-fetch.js';
|
|
37
|
-
export {
|
|
38
|
-
export type {
|
|
22
|
+
export { intelPreflightAction, merchantCardAction, intelTrustAction, verifyReceiptAction, };
|
|
23
|
+
export { getIntelApiBase, getIntelClient } from './client-factory.js';
|
|
24
|
+
export { setPayingFetch, clearPayingFetch, resolvePayingFetch, installTwzrdAutoGate, autoGateOptions, withTracking, callerTag, GATE_PIN, } from './paying-fetch.js';
|
|
25
|
+
export { refusePacket, paidLookupConfirmed } from './actions/intel-trust.js';
|
|
26
|
+
export type { RefusePacket } from './actions/intel-trust.js';
|
|
39
27
|
/** SDK intel helpers. TRUSTED_RECEIPT_PUBKEY is the v1 key — use CURRENT_RECEIPT_PUBKEY for V7 verify. */
|
|
40
28
|
export { IntelPaymentRequiredError, intelPreflight, fetchIntelTrust, fetchMerchantCard, preSpendGate, intelTrustUrl, TRUSTED_RECEIPT_PUBKEY, INTEL_TRUST_PRICE_USDC, } from '@wzrd_sol/sdk';
|
|
41
29
|
export { verifyReceipt, classifyReceipt, describeReceiptSurface, freshnessStatusFor, freshnessFromVerify, formatVerifyResult, CURRENT_RECEIPT_PUBKEY, CURRENT_RECEIPT_KEY_ID, REPUTATION_V5_DOMAIN, REPUTATION_V6_DOMAIN, REPUTATION_V7_DOMAIN, } from './receipt-verify.js';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import { inferAction } from './actions/infer.js';
|
|
2
|
-
import { reportAction } from './actions/report.js';
|
|
3
|
-
import { earnAction } from './actions/earn.js';
|
|
4
|
-
import { claimAction } from './actions/claim.js';
|
|
5
|
-
import { rewardsAction } from './actions/rewards.js';
|
|
6
1
|
import { intelPreflightAction } from './actions/intel-preflight.js';
|
|
7
2
|
import { merchantCardAction } from './actions/merchant-card.js';
|
|
8
3
|
import { intelTrustAction } from './actions/intel-trust.js';
|
|
@@ -13,37 +8,25 @@ export const intelActions = [
|
|
|
13
8
|
intelTrustAction,
|
|
14
9
|
verifyReceiptAction,
|
|
15
10
|
];
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
reportAction,
|
|
20
|
-
claimAction,
|
|
21
|
-
rewardsAction,
|
|
22
|
-
];
|
|
23
|
-
const INTEL_DESCRIPTION = 'WZRD Agent Intel — free ReadinessCard preflight + free merchant_card wash refuse (default), ' +
|
|
24
|
-
'then optional x402-paid V7 trust receipt (~0.05 USDC) + offline verify via twzrd-receipt-verifier. ' +
|
|
11
|
+
const INTEL_DESCRIPTION = 'TWZRD Agent Intel — free ReadinessCard preflight + free merchant_card wash refuse (default), ' +
|
|
12
|
+
'then optional x402-paid V7 trust receipt (~0.05 USDC, needs WZRD_INTEL_ALLOW_PAID or confirm_spend) + ' +
|
|
13
|
+
'offline verify via twzrd-receipt-verifier. ' +
|
|
25
14
|
'Legacy V6 verification is labeled freshness=derived_from_timestamp. ' +
|
|
26
15
|
'Buyer sequence is call-site / action-driven (not an auto-interceptor of all payments).';
|
|
27
|
-
|
|
28
|
-
export function createWzrdPlugin(options = {}) {
|
|
29
|
-
const actions = options.legacyEarnActions
|
|
30
|
-
? [...intelActions, ...legacyEarnActions]
|
|
31
|
-
: [...intelActions];
|
|
16
|
+
export function createWzrdPlugin() {
|
|
32
17
|
return {
|
|
33
18
|
name: 'wzrd',
|
|
34
|
-
description:
|
|
35
|
-
actions,
|
|
19
|
+
description: INTEL_DESCRIPTION,
|
|
20
|
+
actions: [...intelActions],
|
|
36
21
|
};
|
|
37
22
|
}
|
|
38
23
|
/** Default plugin: intel actions only (0.6+). */
|
|
39
24
|
export const wzrdPlugin = createWzrdPlugin();
|
|
40
|
-
/** Pre-0.6 compatibility: intel + legacy earn actions. */
|
|
41
|
-
export const wzrdPluginWithLegacyEarn = createWzrdPlugin({ legacyEarnActions: true });
|
|
42
25
|
export default wzrdPlugin;
|
|
43
|
-
export { intelPreflightAction, merchantCardAction, intelTrustAction, verifyReceiptAction,
|
|
44
|
-
export {
|
|
45
|
-
export { setPayingFetch, clearPayingFetch, resolvePayingFetch, installTwzrdAutoGate, } from './paying-fetch.js';
|
|
46
|
-
export {
|
|
26
|
+
export { intelPreflightAction, merchantCardAction, intelTrustAction, verifyReceiptAction, };
|
|
27
|
+
export { getIntelApiBase, getIntelClient } from './client-factory.js';
|
|
28
|
+
export { setPayingFetch, clearPayingFetch, resolvePayingFetch, installTwzrdAutoGate, autoGateOptions, withTracking, callerTag, GATE_PIN, } from './paying-fetch.js';
|
|
29
|
+
export { refusePacket, paidLookupConfirmed } from './actions/intel-trust.js';
|
|
47
30
|
/** SDK intel helpers. TRUSTED_RECEIPT_PUBKEY is the v1 key — use CURRENT_RECEIPT_PUBKEY for V7 verify. */
|
|
48
31
|
export { IntelPaymentRequiredError, intelPreflight, fetchIntelTrust, fetchMerchantCard, preSpendGate, intelTrustUrl, TRUSTED_RECEIPT_PUBKEY, INTEL_TRUST_PRICE_USDC, } from '@wzrd_sol/sdk';
|
|
49
32
|
export { verifyReceipt, classifyReceipt, describeReceiptSurface, freshnessStatusFor, freshnessFromVerify, formatVerifyResult, CURRENT_RECEIPT_PUBKEY, CURRENT_RECEIPT_KEY_ID, REPUTATION_V5_DOMAIN, REPUTATION_V6_DOMAIN, REPUTATION_V7_DOMAIN, } from './receipt-verify.js';
|
package/dist/paying-fetch.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
/** x402-capable fetch injection for paid intel actions. No embedded wallet. */
|
|
2
1
|
import type { IAgentRuntime } from '@elizaos/core';
|
|
3
2
|
import { type InstallAutoGateOptions, type PayWrap } from 'twzrd-x402-gate';
|
|
3
|
+
/** This package's version, stamped into X-TWZRD-Integration on gate lookups. */
|
|
4
|
+
export declare const PLUGIN_VERSION: string;
|
|
5
|
+
/** Exact twzrd-x402-gate pin. A caret would float onto a later line. */
|
|
6
|
+
export declare const GATE_PIN = "0.12.5";
|
|
7
|
+
export declare function integrationTag(): string;
|
|
8
|
+
/** Seat stamp: X-Twzrd-Caller eliza-plugin/<version>@0.12.5. */
|
|
9
|
+
export declare function callerTag(): string;
|
|
10
|
+
/**
|
|
11
|
+
* Stamp the four seat headers on an intel fetch. The SDK's own client header
|
|
12
|
+
* is replaced so the caller is this plugin, not wzrd-sdk.
|
|
13
|
+
*/
|
|
14
|
+
export declare function withTracking(base: typeof fetch, runId?: `${string}-${string}-${string}-${string}-${string}`): typeof fetch;
|
|
4
15
|
/** Host supplies an x402-capable fetch (agentcash, twzrd-x402-gate, etc.) before runtime creation. */
|
|
5
16
|
export declare function setPayingFetch(f: typeof fetch): void;
|
|
6
17
|
/**
|
|
@@ -8,6 +19,11 @@ export declare function setPayingFetch(f: typeof fetch): void;
|
|
|
8
19
|
* with the free TWZRD preflight BEFORE handing it to your x402 client's `payWrap`.
|
|
9
20
|
*/
|
|
10
21
|
export declare function installTwzrdAutoGate(payWrap: PayWrap, options?: InstallAutoGateOptions): void;
|
|
22
|
+
/**
|
|
23
|
+
* Gate options with a default run attribution, so lookups carry
|
|
24
|
+
* X-TWZRD-Integration: eliza-plugin/<version>. Caller-provided attribution wins.
|
|
25
|
+
*/
|
|
26
|
+
export declare function autoGateOptions(options?: InstallAutoGateOptions): InstallAutoGateOptions;
|
|
11
27
|
export declare function clearPayingFetch(): void;
|
|
12
28
|
type FetchLike = typeof fetch;
|
|
13
29
|
/** Resolve paying fetch: module setter > runtime service > runtime.fetch > global fetch. */
|
package/dist/paying-fetch.js
CHANGED
|
@@ -1,4 +1,34 @@
|
|
|
1
|
+
/** x402-capable fetch injection for paid intel actions. No embedded wallet. */
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
1
4
|
import { installTwzrdAutoGate as buildAutoGate, } from 'twzrd-x402-gate';
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
/** This package's version, stamped into X-TWZRD-Integration on gate lookups. */
|
|
7
|
+
export const PLUGIN_VERSION = require('../package.json').version;
|
|
8
|
+
/** Exact twzrd-x402-gate pin. A caret would float onto a later line. */
|
|
9
|
+
export const GATE_PIN = '0.12.5';
|
|
10
|
+
export function integrationTag() {
|
|
11
|
+
return `eliza-plugin/${PLUGIN_VERSION}`;
|
|
12
|
+
}
|
|
13
|
+
/** Seat stamp: X-Twzrd-Caller eliza-plugin/<version>@0.12.5. */
|
|
14
|
+
export function callerTag() {
|
|
15
|
+
return `${integrationTag()}@${GATE_PIN}`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Stamp the four seat headers on an intel fetch. The SDK's own client header
|
|
19
|
+
* is replaced so the caller is this plugin, not wzrd-sdk.
|
|
20
|
+
*/
|
|
21
|
+
export function withTracking(base, runId = randomUUID()) {
|
|
22
|
+
const integration = integrationTag();
|
|
23
|
+
return (async (input, init) => {
|
|
24
|
+
const headers = new Headers(init?.headers);
|
|
25
|
+
headers.set('X-TWZRD-Client', `twzrd-x402-gate/${GATE_PIN}`);
|
|
26
|
+
headers.set('X-Twzrd-Caller', `${integration}@${GATE_PIN}`);
|
|
27
|
+
headers.set('X-TWZRD-Integration', integration);
|
|
28
|
+
headers.set('X-TWZRD-Run-Id', runId);
|
|
29
|
+
return base(input, { ...init, headers });
|
|
30
|
+
});
|
|
31
|
+
}
|
|
2
32
|
let modulePayingFetch = null;
|
|
3
33
|
/** Host supplies an x402-capable fetch (agentcash, twzrd-x402-gate, etc.) before runtime creation. */
|
|
4
34
|
export function setPayingFetch(f) {
|
|
@@ -9,7 +39,19 @@ export function setPayingFetch(f) {
|
|
|
9
39
|
* with the free TWZRD preflight BEFORE handing it to your x402 client's `payWrap`.
|
|
10
40
|
*/
|
|
11
41
|
export function installTwzrdAutoGate(payWrap, options) {
|
|
12
|
-
setPayingFetch(buildAutoGate(payWrap, options));
|
|
42
|
+
setPayingFetch(buildAutoGate(payWrap, autoGateOptions(options)));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Gate options with a default run attribution, so lookups carry
|
|
46
|
+
* X-TWZRD-Integration: eliza-plugin/<version>. Caller-provided attribution wins.
|
|
47
|
+
*/
|
|
48
|
+
export function autoGateOptions(options) {
|
|
49
|
+
if (options?.attribution)
|
|
50
|
+
return options;
|
|
51
|
+
return {
|
|
52
|
+
...(options ?? {}),
|
|
53
|
+
attribution: { integration: integrationTag(), runId: randomUUID() },
|
|
54
|
+
};
|
|
13
55
|
}
|
|
14
56
|
export function clearPayingFetch() {
|
|
15
57
|
modulePayingFetch = null;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wzrd_sol/eliza-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.8.1",
|
|
4
|
+
"description": "TWZRD Agent Intel for ElizaOS. Free preflight ReadinessCard + merchant_card (wash_flagged refuse default), paid GET /v1/intel/trust (~0.05 USDC) V7 receipt, offline verify via twzrd-receipt-verifier. Paid lookups need WZRD_INTEL_ALLOW_PAID or confirm_spend; merchant_card outages fail closed.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -18,12 +18,9 @@
|
|
|
18
18
|
"typecheck": "echo 'eliza-plugin: typecheck ok'"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@solana/web3.js": "^1.95.0",
|
|
22
21
|
"@wzrd_sol/sdk": "^0.4.8",
|
|
23
|
-
"bs58": "^5.0.0",
|
|
24
|
-
"tweetnacl": "^1.0.3",
|
|
25
22
|
"twzrd-receipt-verifier": "^1.4.0",
|
|
26
|
-
"twzrd-x402-gate": "
|
|
23
|
+
"twzrd-x402-gate": "0.12.5"
|
|
27
24
|
},
|
|
28
25
|
"peerDependencies": {
|
|
29
26
|
"@elizaos/core": "^1.0.0"
|
package/dist/actions/claim.d.ts
DELETED
package/dist/actions/claim.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { getWzrdClient } from '../client-factory.js';
|
|
2
|
-
export const claimAction = {
|
|
3
|
-
name: 'WZRD_CLAIM',
|
|
4
|
-
similes: ['WZRD_HARVEST', 'CLAIM_CCM', 'COLLECT_REWARDS'],
|
|
5
|
-
description: 'Claim accrued CCM tokens via gasless relay. Server pays tx fees — agent needs 0 SOL.',
|
|
6
|
-
examples: [
|
|
7
|
-
[
|
|
8
|
-
{ name: '{{user1}}', content: { text: 'Claim my WZRD rewards' } },
|
|
9
|
-
{ name: '{{agentName}}', content: { text: 'Claimed 142.5 CCM via gasless relay. Tx: 5S7L...' } },
|
|
10
|
-
],
|
|
11
|
-
],
|
|
12
|
-
validate: async () => true,
|
|
13
|
-
handler: async (runtime, _msg, _state, _opt, callback) => {
|
|
14
|
-
const client = getWzrdClient(runtime);
|
|
15
|
-
try {
|
|
16
|
-
// Check if there's anything to claim
|
|
17
|
-
const status = await client.getClaimStatus();
|
|
18
|
-
if (status.claimable <= 0) {
|
|
19
|
-
const text = `No CCM to claim right now.\n` +
|
|
20
|
-
`Cumulative: ${(status.cumulative_total / 1e9).toFixed(2)} CCM\n` +
|
|
21
|
-
`Already claimed: ${(status.claimed_total / 1e9).toFixed(2)} CCM\n` +
|
|
22
|
-
`Run WZRD_EARN first to accrue rewards.`;
|
|
23
|
-
await callback?.({ text });
|
|
24
|
-
return { success: true, data: status };
|
|
25
|
-
}
|
|
26
|
-
const result = await client.claimRelay();
|
|
27
|
-
if (result.status === 'already_claimed') {
|
|
28
|
-
await callback?.({ text: `Already claimed through root ${result.root_seq}.` });
|
|
29
|
-
return { success: true, data: result };
|
|
30
|
-
}
|
|
31
|
-
const text = `Claimed CCM via gasless relay.\n` +
|
|
32
|
-
`Amount: ${(result.cumulative_total / 1e9).toFixed(2)} CCM (cumulative)\n` +
|
|
33
|
-
`Root: ${result.root_seq}\n` +
|
|
34
|
-
`Tx: ${result.tx_sig?.slice(0, 20)}...`;
|
|
35
|
-
await callback?.({ text });
|
|
36
|
-
return { success: true, data: result };
|
|
37
|
-
}
|
|
38
|
-
catch (err) {
|
|
39
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
40
|
-
if (msg.includes('404')) {
|
|
41
|
-
await callback?.({ text: 'No claims found yet. Run WZRD_EARN to start accruing CCM.' });
|
|
42
|
-
return { success: true, data: {} };
|
|
43
|
-
}
|
|
44
|
-
await callback?.({ text: `Claim failed: ${msg}` });
|
|
45
|
-
return { success: false, error: msg };
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
};
|
package/dist/actions/earn.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WZRD_EARN — Full earn cycle: infer → report → check rewards.
|
|
3
|
-
*
|
|
4
|
-
* Single action that runs the complete server-witnessed earn loop.
|
|
5
|
-
* For agents that want one-shot earning without managing execution_ids.
|
|
6
|
-
*/
|
|
7
|
-
import type { Action } from '@elizaos/core';
|
|
8
|
-
export declare const earnAction: Action;
|
package/dist/actions/earn.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { getWzrdClient } from '../client-factory.js';
|
|
2
|
-
const EVAL_PROMPTS = {
|
|
3
|
-
code: [
|
|
4
|
-
'Write a Python function that checks if a binary tree is balanced. Include time complexity analysis.',
|
|
5
|
-
'Implement a thread-safe LRU cache in Rust with O(1) get and put operations.',
|
|
6
|
-
'Write a TypeScript generic function that deep-merges two objects, handling arrays and nested objects.',
|
|
7
|
-
],
|
|
8
|
-
chat: [
|
|
9
|
-
'Explain the difference between TCP and UDP to someone who has never programmed before.',
|
|
10
|
-
'What are the tradeoffs between microservices and monolithic architecture?',
|
|
11
|
-
'Describe how consensus works in proof-of-stake blockchains.',
|
|
12
|
-
],
|
|
13
|
-
reasoning: [
|
|
14
|
-
'A farmer has a fox, a chicken, and a bag of grain. He must cross a river in a boat that can only carry him and one item. How does he do it?',
|
|
15
|
-
'If it takes 5 machines 5 minutes to make 5 widgets, how long does it take 100 machines to make 100 widgets?',
|
|
16
|
-
'Three people check into a hotel room that costs $30. They each pay $10. The manager realizes the room should cost $25 and gives $5 to the bellboy to return. The bellboy keeps $2 and gives $1 back to each person. So each person paid $9 (total $27) plus the bellboy kept $2 (total $29). Where is the missing dollar?',
|
|
17
|
-
],
|
|
18
|
-
};
|
|
19
|
-
function pickPrompt(taskType) {
|
|
20
|
-
const prompts = EVAL_PROMPTS[taskType] || EVAL_PROMPTS.chat;
|
|
21
|
-
return prompts[Math.floor(Math.random() * prompts.length)];
|
|
22
|
-
}
|
|
23
|
-
export const earnAction = {
|
|
24
|
-
name: 'WZRD_EARN',
|
|
25
|
-
similes: ['WZRD_EARN_CCM', 'EARN_REWARDS', 'RUN_EARN_LOOP'],
|
|
26
|
-
description: 'Run the full WZRD earn cycle: pick a prompt, run server-witnessed inference, ' +
|
|
27
|
-
'report the outcome, and check pending rewards. One action, complete loop.',
|
|
28
|
-
examples: [
|
|
29
|
-
[
|
|
30
|
-
{ name: '{{user1}}', content: { text: 'Earn some CCM on WZRD' } },
|
|
31
|
-
{
|
|
32
|
-
name: '{{agentName}}',
|
|
33
|
-
content: {
|
|
34
|
-
text: 'Earn cycle complete. Model: gemini-2.5-flash, quality: 0.85, verified. Pending: 142.5 CCM.',
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
],
|
|
39
|
-
validate: async () => true,
|
|
40
|
-
handler: async (runtime, message, _state, _opt, callback) => {
|
|
41
|
-
const content = message.content;
|
|
42
|
-
const taskType = content.task_type || 'code';
|
|
43
|
-
const prompt = content.prompt || pickPrompt(taskType);
|
|
44
|
-
const client = getWzrdClient(runtime);
|
|
45
|
-
const steps = [];
|
|
46
|
-
try {
|
|
47
|
-
// Step 1: Pick model + Infer
|
|
48
|
-
steps.push('→ Picking model from leaderboard...');
|
|
49
|
-
const model = await client.pickModel(taskType);
|
|
50
|
-
steps.push(`→ Running inference: ${model} (${taskType})...`);
|
|
51
|
-
const infer = await client.infer(prompt, model, taskType);
|
|
52
|
-
steps.push(`✓ Inference: ${infer.executed_model} (${infer.provider}), quality ${infer.quality_score.toFixed(2)}, ${infer.latency_ms}ms`);
|
|
53
|
-
// Step 2: Report with execution_id
|
|
54
|
-
steps.push('→ Reporting outcome...');
|
|
55
|
-
const report = await client.report({
|
|
56
|
-
model_id: infer.requested_model,
|
|
57
|
-
execution_id: infer.execution_id,
|
|
58
|
-
task_type: taskType,
|
|
59
|
-
quality_score: infer.quality_score,
|
|
60
|
-
latency_ms: infer.latency_ms,
|
|
61
|
-
});
|
|
62
|
-
steps.push(`✓ Reported: ${report.verification_state}, contribution #${report.contribution_id}, pending ${(report.pending_ccm / 1e9).toFixed(2)} CCM`);
|
|
63
|
-
// Step 3: Check rewards
|
|
64
|
-
steps.push('→ Checking rewards...');
|
|
65
|
-
const rewards = await client.getRewards();
|
|
66
|
-
steps.push(`✓ Rewards: ${(rewards.pending_ccm / 1e9).toFixed(2)} CCM pending, ` +
|
|
67
|
-
`${(rewards.total_rewarded_ccm / 1e9).toFixed(2)} CCM lifetime` +
|
|
68
|
-
(rewards.rank ? `, rank #${rewards.rank}` : ''));
|
|
69
|
-
const text = `Earn cycle complete:\n${steps.join('\n')}`;
|
|
70
|
-
await callback?.({ text });
|
|
71
|
-
return {
|
|
72
|
-
success: true,
|
|
73
|
-
data: { infer, report, rewards },
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
catch (err) {
|
|
77
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
78
|
-
steps.push(`✗ Failed: ${msg}`);
|
|
79
|
-
await callback?.({ text: `Earn cycle failed:\n${steps.join('\n')}` });
|
|
80
|
-
return { success: false, error: msg };
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
};
|
package/dist/actions/infer.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WZRD_INFER — Server-witnessed inference through WZRD.
|
|
3
|
-
*
|
|
4
|
-
* WZRD calls the AI provider (Gemini/Nous/OpenRouter), grades the response,
|
|
5
|
-
* and returns an execution_id receipt. Pass this to WZRD_REPORT for verified rewards.
|
|
6
|
-
*/
|
|
7
|
-
import type { Action } from '@elizaos/core';
|
|
8
|
-
export declare const inferAction: Action;
|
package/dist/actions/infer.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { getWzrdClient } from '../client-factory.js';
|
|
2
|
-
export const inferAction = {
|
|
3
|
-
name: 'WZRD_INFER',
|
|
4
|
-
similes: ['WZRD_RUN_INFERENCE', 'ASK_MODEL', 'RUN_MODEL'],
|
|
5
|
-
description: 'Run inference through WZRD. The server calls the AI provider, grades quality, ' +
|
|
6
|
-
'and returns an execution receipt. Use the execution_id with WZRD_REPORT to earn CCM.',
|
|
7
|
-
examples: [
|
|
8
|
-
[
|
|
9
|
-
{ name: '{{user1}}', content: { text: 'Run inference through WZRD: explain quicksort in Python' } },
|
|
10
|
-
{ name: '{{agentName}}', content: { text: 'Inference complete. Model: gemini-2.5-flash, quality: 0.85. execution_id: abc-123...' } },
|
|
11
|
-
],
|
|
12
|
-
],
|
|
13
|
-
validate: async () => true,
|
|
14
|
-
handler: async (runtime, message, _state, _opt, callback) => {
|
|
15
|
-
const content = message.content;
|
|
16
|
-
const prompt = content.prompt || content.text || '';
|
|
17
|
-
if (!prompt) {
|
|
18
|
-
await callback?.({ text: 'No prompt provided. Include a prompt or text to run inference.' });
|
|
19
|
-
return { success: false, error: 'No prompt' };
|
|
20
|
-
}
|
|
21
|
-
const taskType = content.task_type || 'chat';
|
|
22
|
-
const model = content.model;
|
|
23
|
-
const client = getWzrdClient(runtime);
|
|
24
|
-
try {
|
|
25
|
-
const result = await client.infer(prompt, model, taskType);
|
|
26
|
-
const text = `Inference complete.\n` +
|
|
27
|
-
`Model: ${result.executed_model} (${result.provider})\n` +
|
|
28
|
-
`Quality: ${result.quality_score.toFixed(2)}\n` +
|
|
29
|
-
`Latency: ${result.latency_ms}ms\n` +
|
|
30
|
-
`execution_id: ${result.execution_id}\n\n` +
|
|
31
|
-
`Response: ${result.response_preview}`;
|
|
32
|
-
await callback?.({ text });
|
|
33
|
-
return { success: true, data: result };
|
|
34
|
-
}
|
|
35
|
-
catch (err) {
|
|
36
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
37
|
-
await callback?.({ text: `Inference failed: ${msg}` });
|
|
38
|
-
return { success: false, error: msg };
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
};
|
package/dist/actions/report.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WZRD_REPORT — Report a model pick with execution receipt for verified CCM rewards.
|
|
3
|
-
*
|
|
4
|
-
* Must be called after WZRD_INFER. Pass the execution_id from the infer result
|
|
5
|
-
* to get server-verified status and quality-weighted rewards.
|
|
6
|
-
*/
|
|
7
|
-
import type { Action } from '@elizaos/core';
|
|
8
|
-
export declare const reportAction: Action;
|
package/dist/actions/report.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { getWzrdClient } from '../client-factory.js';
|
|
2
|
-
export const reportAction = {
|
|
3
|
-
name: 'WZRD_REPORT',
|
|
4
|
-
similes: ['WZRD_REPORT_OUTCOME', 'REPORT_MODEL_PICK', 'SUBMIT_SIGNAL'],
|
|
5
|
-
description: 'Report a model pick to WZRD with an execution_id from WZRD_INFER. ' +
|
|
6
|
-
'Verified reports earn CCM rewards with quality multiplier.',
|
|
7
|
-
examples: [
|
|
8
|
-
[
|
|
9
|
-
{ name: '{{user1}}', content: { text: 'Report the inference result to earn CCM' } },
|
|
10
|
-
{ name: '{{agentName}}', content: { text: 'Reported. Verification: verified, contribution #4521.' } },
|
|
11
|
-
],
|
|
12
|
-
],
|
|
13
|
-
validate: async () => true,
|
|
14
|
-
handler: async (runtime, message, _state, _opt, callback) => {
|
|
15
|
-
const content = message.content;
|
|
16
|
-
if (!content.execution_id || !content.model_id) {
|
|
17
|
-
await callback?.({
|
|
18
|
-
text: 'Missing required: execution_id and model_id. Run WZRD_INFER first to get an execution receipt.',
|
|
19
|
-
});
|
|
20
|
-
return { success: false, error: 'Missing execution_id or model_id' };
|
|
21
|
-
}
|
|
22
|
-
const client = getWzrdClient(runtime);
|
|
23
|
-
try {
|
|
24
|
-
const result = await client.report({
|
|
25
|
-
model_id: content.model_id,
|
|
26
|
-
execution_id: content.execution_id,
|
|
27
|
-
task_type: content.task_type,
|
|
28
|
-
quality_score: content.quality_score,
|
|
29
|
-
latency_ms: content.latency_ms,
|
|
30
|
-
});
|
|
31
|
-
const text = `Reported to WZRD.\n` +
|
|
32
|
-
`Verification: ${result.verification_state}\n` +
|
|
33
|
-
`Contribution: #${result.contribution_id}\n` +
|
|
34
|
-
`Pending CCM: ${(result.pending_ccm / 1e9).toFixed(2)}\n` +
|
|
35
|
-
`Pipeline: ${result.pipeline_state}`;
|
|
36
|
-
await callback?.({ text });
|
|
37
|
-
return { success: true, data: result };
|
|
38
|
-
}
|
|
39
|
-
catch (err) {
|
|
40
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
41
|
-
await callback?.({ text: `Report failed: ${msg}` });
|
|
42
|
-
return { success: false, error: msg };
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
};
|
package/dist/actions/rewards.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { getWzrdClient } from '../client-factory.js';
|
|
2
|
-
export const rewardsAction = {
|
|
3
|
-
name: 'WZRD_REWARDS',
|
|
4
|
-
similes: ['WZRD_BALANCE', 'CHECK_REWARDS', 'MY_CCM'],
|
|
5
|
-
description: 'Check your pending CCM rewards, lifetime total, rank, and contribution count.',
|
|
6
|
-
examples: [
|
|
7
|
-
[
|
|
8
|
-
{ name: '{{user1}}', content: { text: 'How much CCM have I earned?' } },
|
|
9
|
-
{ name: '{{agentName}}', content: { text: 'Pending: 142.5 CCM. Lifetime: 326,000 CCM. Rank #3.' } },
|
|
10
|
-
],
|
|
11
|
-
],
|
|
12
|
-
validate: async () => true,
|
|
13
|
-
handler: async (runtime, _msg, _state, _opt, callback) => {
|
|
14
|
-
const client = getWzrdClient(runtime);
|
|
15
|
-
try {
|
|
16
|
-
const rewards = await client.getRewards();
|
|
17
|
-
const text = `WZRD Rewards:\n` +
|
|
18
|
-
`Pending: ${(rewards.pending_ccm / 1e9).toFixed(2)} CCM\n` +
|
|
19
|
-
`Lifetime: ${(rewards.total_rewarded_ccm / 1e9).toFixed(2)} CCM\n` +
|
|
20
|
-
`Contributions: ${rewards.contribution_count}\n` +
|
|
21
|
-
(rewards.rank ? `Rank: #${rewards.rank}` : 'Rank: unranked');
|
|
22
|
-
await callback?.({ text });
|
|
23
|
-
return { success: true, data: rewards };
|
|
24
|
-
}
|
|
25
|
-
catch (err) {
|
|
26
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
27
|
-
await callback?.({ text: `Failed to fetch rewards: ${msg}` });
|
|
28
|
-
return { success: false, error: msg };
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
};
|
package/dist/client.d.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Standalone WZRD API client for ElizaOS agents.
|
|
3
|
-
* No external dependencies beyond @solana/web3.js for Ed25519 signing.
|
|
4
|
-
*
|
|
5
|
-
* Auth flow: challenge → sign → verify → Bearer token (24h TTL)
|
|
6
|
-
* Earn flow: infer → report(execution_id) → claim
|
|
7
|
-
*/
|
|
8
|
-
import { Keypair } from '@solana/web3.js';
|
|
9
|
-
export interface InferResult {
|
|
10
|
-
execution_id: string;
|
|
11
|
-
executed_model: string;
|
|
12
|
-
requested_model: string;
|
|
13
|
-
provider: string;
|
|
14
|
-
quality_score: number;
|
|
15
|
-
response_preview: string;
|
|
16
|
-
latency_ms: number;
|
|
17
|
-
cost_usd?: number;
|
|
18
|
-
}
|
|
19
|
-
export interface ReportResult {
|
|
20
|
-
contribution_id: number;
|
|
21
|
-
verification_state: string;
|
|
22
|
-
lifetime_contributions: number;
|
|
23
|
-
pending_ccm: number;
|
|
24
|
-
pipeline_state: string;
|
|
25
|
-
idempotent: boolean;
|
|
26
|
-
provider_receipt_present: boolean;
|
|
27
|
-
}
|
|
28
|
-
export interface RewardsBalance {
|
|
29
|
-
pending_ccm: number;
|
|
30
|
-
total_rewarded_ccm: number;
|
|
31
|
-
rank: number | null;
|
|
32
|
-
contribution_count: number;
|
|
33
|
-
}
|
|
34
|
-
export interface ClaimResult {
|
|
35
|
-
tx_sig: string | null;
|
|
36
|
-
root_seq: number;
|
|
37
|
-
cumulative_total: number;
|
|
38
|
-
status: string;
|
|
39
|
-
}
|
|
40
|
-
export interface LeaderboardResult {
|
|
41
|
-
market_count: number;
|
|
42
|
-
total_tvl: number;
|
|
43
|
-
root: {
|
|
44
|
-
root_seq: number;
|
|
45
|
-
};
|
|
46
|
-
markets: Array<{
|
|
47
|
-
market_id: number;
|
|
48
|
-
metric: string;
|
|
49
|
-
platform: string;
|
|
50
|
-
velocity_ema: number;
|
|
51
|
-
multiplier_bps: number;
|
|
52
|
-
snapshot_count: number;
|
|
53
|
-
}>;
|
|
54
|
-
}
|
|
55
|
-
export declare class WzrdClient {
|
|
56
|
-
private keypair;
|
|
57
|
-
private apiUrl;
|
|
58
|
-
private token;
|
|
59
|
-
private tokenExpiry;
|
|
60
|
-
constructor(keypair: Keypair, apiUrl?: string);
|
|
61
|
-
get pubkey(): string;
|
|
62
|
-
/** Ed25519 challenge → sign → verify → Bearer token */
|
|
63
|
-
private authenticate;
|
|
64
|
-
/** Authenticated fetch helper */
|
|
65
|
-
private authedFetch;
|
|
66
|
-
/** Pick a model from the momentum signal — returns top model's channel_id */
|
|
67
|
-
pickModel(taskType?: string): Promise<string>;
|
|
68
|
-
/** Server-witnessed inference — WZRD calls the provider, grades quality */
|
|
69
|
-
infer(prompt: string, model?: string, taskType?: string): Promise<InferResult>;
|
|
70
|
-
/** Report model pick with execution_id for verified rewards */
|
|
71
|
-
report(params: {
|
|
72
|
-
model_id: string;
|
|
73
|
-
execution_id: string;
|
|
74
|
-
task_type?: string;
|
|
75
|
-
quality_score?: number;
|
|
76
|
-
latency_ms?: number;
|
|
77
|
-
}): Promise<ReportResult>;
|
|
78
|
-
/** Check pending + total rewards (flattens nested /v1/agent/earned response) */
|
|
79
|
-
getRewards(): Promise<RewardsBalance>;
|
|
80
|
-
/** Gasless CCM claim via server relay */
|
|
81
|
-
claimRelay(): Promise<ClaimResult>;
|
|
82
|
-
/** Public: fetch leaderboard (no auth) */
|
|
83
|
-
getLeaderboard(limit?: number): Promise<LeaderboardResult>;
|
|
84
|
-
/** Public: fetch claims status */
|
|
85
|
-
getClaimStatus(): Promise<{
|
|
86
|
-
cumulative_total: number;
|
|
87
|
-
claimed_total: number;
|
|
88
|
-
claimable: number;
|
|
89
|
-
}>;
|
|
90
|
-
}
|
|
91
|
-
export { intelPreflight as intelPreflightClient, fetchIntelTrust as fetchIntelTrustClient, } from '@wzrd_sol/sdk';
|
|
92
|
-
export { verifyReceipt as verifyReceiptClient } from './receipt-verify.js';
|
package/dist/client.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import nacl from 'tweetnacl';
|
|
2
|
-
import bs58 from 'bs58';
|
|
3
|
-
const DEFAULT_API = 'https://api.twzrd.xyz';
|
|
4
|
-
export class WzrdClient {
|
|
5
|
-
keypair;
|
|
6
|
-
apiUrl;
|
|
7
|
-
token = null;
|
|
8
|
-
tokenExpiry = 0;
|
|
9
|
-
constructor(keypair, apiUrl) {
|
|
10
|
-
this.keypair = keypair;
|
|
11
|
-
this.apiUrl = apiUrl || DEFAULT_API;
|
|
12
|
-
}
|
|
13
|
-
get pubkey() {
|
|
14
|
-
return this.keypair.publicKey.toBase58();
|
|
15
|
-
}
|
|
16
|
-
/** Ed25519 challenge → sign → verify → Bearer token */
|
|
17
|
-
async authenticate() {
|
|
18
|
-
if (this.token && Date.now() < this.tokenExpiry)
|
|
19
|
-
return this.token;
|
|
20
|
-
// 1. Get challenge
|
|
21
|
-
const challengeRes = await fetch(`${this.apiUrl}/v1/agent/challenge`);
|
|
22
|
-
if (!challengeRes.ok)
|
|
23
|
-
throw new Error(`Challenge failed: ${challengeRes.status}`);
|
|
24
|
-
const { nonce } = await challengeRes.json();
|
|
25
|
-
// 2. Construct message locally (must match server's agent_auth_message format)
|
|
26
|
-
const message = `wzrd-agent-auth v1 | wallet:${this.pubkey} | nonce:${nonce}`;
|
|
27
|
-
const messageBytes = new TextEncoder().encode(message);
|
|
28
|
-
const signature = nacl.sign.detached(messageBytes, this.keypair.secretKey);
|
|
29
|
-
// 3. Verify — signature must be base58-encoded (Solana Signature format)
|
|
30
|
-
const verifyRes = await fetch(`${this.apiUrl}/v1/agent/verify`, {
|
|
31
|
-
method: 'POST',
|
|
32
|
-
headers: { 'Content-Type': 'application/json' },
|
|
33
|
-
body: JSON.stringify({
|
|
34
|
-
pubkey: this.pubkey,
|
|
35
|
-
nonce,
|
|
36
|
-
signature: bs58.encode(signature),
|
|
37
|
-
}),
|
|
38
|
-
});
|
|
39
|
-
if (!verifyRes.ok)
|
|
40
|
-
throw new Error(`Verify failed: ${verifyRes.status}`);
|
|
41
|
-
const { token } = await verifyRes.json();
|
|
42
|
-
this.token = token;
|
|
43
|
-
this.tokenExpiry = Date.now() + 23 * 60 * 60 * 1000; // refresh 1h before 24h expiry
|
|
44
|
-
return token;
|
|
45
|
-
}
|
|
46
|
-
/** Authenticated fetch helper */
|
|
47
|
-
async authedFetch(path, init) {
|
|
48
|
-
const token = await this.authenticate();
|
|
49
|
-
const headers = new Headers(init?.headers);
|
|
50
|
-
headers.set('Authorization', `Bearer ${token}`);
|
|
51
|
-
headers.set('Content-Type', 'application/json');
|
|
52
|
-
return fetch(`${this.apiUrl}${path}`, { ...init, headers });
|
|
53
|
-
}
|
|
54
|
-
/** Pick a model from the momentum signal — returns top model's channel_id */
|
|
55
|
-
async pickModel(taskType) {
|
|
56
|
-
const res = await fetch(`${this.apiUrl}/v1/signals/momentum?limit=10&trending=true`);
|
|
57
|
-
if (!res.ok)
|
|
58
|
-
throw new Error(`Momentum fetch failed: ${res.status}`);
|
|
59
|
-
const data = await res.json();
|
|
60
|
-
if (!data.models?.length)
|
|
61
|
-
throw new Error('No models available in momentum feed');
|
|
62
|
-
// Return the top-ranked model's channel_id (e.g. "moonshotai/Kimi-K2.5")
|
|
63
|
-
return data.models[0].model;
|
|
64
|
-
}
|
|
65
|
-
/** Server-witnessed inference — WZRD calls the provider, grades quality */
|
|
66
|
-
async infer(prompt, model, taskType) {
|
|
67
|
-
const resolvedModel = model || await this.pickModel(taskType);
|
|
68
|
-
const res = await this.authedFetch('/v1/agent/infer', {
|
|
69
|
-
method: 'POST',
|
|
70
|
-
body: JSON.stringify({ model: resolvedModel, prompt, task_type: taskType || 'chat' }),
|
|
71
|
-
});
|
|
72
|
-
if (!res.ok) {
|
|
73
|
-
const body = await res.text().catch(() => '');
|
|
74
|
-
throw new Error(`Infer failed (${res.status}): ${body}`);
|
|
75
|
-
}
|
|
76
|
-
return res.json();
|
|
77
|
-
}
|
|
78
|
-
/** Report model pick with execution_id for verified rewards */
|
|
79
|
-
async report(params) {
|
|
80
|
-
const res = await this.authedFetch('/v1/agent/report', {
|
|
81
|
-
method: 'POST',
|
|
82
|
-
body: JSON.stringify(params),
|
|
83
|
-
});
|
|
84
|
-
if (!res.ok) {
|
|
85
|
-
const body = await res.text().catch(() => '');
|
|
86
|
-
throw new Error(`Report failed (${res.status}): ${body}`);
|
|
87
|
-
}
|
|
88
|
-
return res.json();
|
|
89
|
-
}
|
|
90
|
-
/** Check pending + total rewards (flattens nested /v1/agent/earned response) */
|
|
91
|
-
async getRewards() {
|
|
92
|
-
const res = await this.authedFetch('/v1/agent/earned');
|
|
93
|
-
if (!res.ok)
|
|
94
|
-
throw new Error(`Rewards check failed: ${res.status}`);
|
|
95
|
-
const data = await res.json();
|
|
96
|
-
const economy = data.economy;
|
|
97
|
-
const routing = data.routing;
|
|
98
|
-
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),
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
/** Gasless CCM claim via server relay */
|
|
106
|
-
async claimRelay() {
|
|
107
|
-
const res = await this.authedFetch(`/v1/claims/${this.pubkey}/relay`, {
|
|
108
|
-
method: 'POST',
|
|
109
|
-
});
|
|
110
|
-
if (!res.ok) {
|
|
111
|
-
const body = await res.text().catch(() => '');
|
|
112
|
-
throw new Error(`Claim relay failed (${res.status}): ${body}`);
|
|
113
|
-
}
|
|
114
|
-
return res.json();
|
|
115
|
-
}
|
|
116
|
-
/** Public: fetch leaderboard (no auth) */
|
|
117
|
-
async getLeaderboard(limit = 20) {
|
|
118
|
-
const res = await fetch(`${this.apiUrl}/v1/leaderboard?limit=${limit}`);
|
|
119
|
-
if (!res.ok)
|
|
120
|
-
throw new Error(`Leaderboard failed: ${res.status}`);
|
|
121
|
-
return res.json();
|
|
122
|
-
}
|
|
123
|
-
/** Public: fetch claims status */
|
|
124
|
-
async getClaimStatus() {
|
|
125
|
-
const res = await this.authedFetch(`/v1/claims/${this.pubkey}`);
|
|
126
|
-
if (!res.ok) {
|
|
127
|
-
if (res.status === 404)
|
|
128
|
-
return { cumulative_total: 0, claimed_total: 0, claimable: 0 };
|
|
129
|
-
throw new Error(`Claim status failed: ${res.status}`);
|
|
130
|
-
}
|
|
131
|
-
const data = await res.json();
|
|
132
|
-
return { ...data, claimable: data.cumulative_total - data.claimed_total };
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
// Thin wrappers delegating to @wzrd_sol/sdk intel surface (preflight/trust/verify) per plan.
|
|
136
|
-
// Kept in client.ts alongside earn WzrdClient. Actual runtime client for intel is via getIntelClient() in factory.
|
|
137
|
-
export { intelPreflight as intelPreflightClient, fetchIntelTrust as fetchIntelTrustClient, } from '@wzrd_sol/sdk';
|
|
138
|
-
export { verifyReceipt as verifyReceiptClient } from './receipt-verify.js';
|