@wzrd_sol/eliza-plugin 0.1.2 → 0.3.0
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 +98 -26
- package/dist/actions/claim.d.ts +2 -5
- package/dist/actions/claim.js +33 -30
- package/dist/actions/earn.d.ts +8 -0
- package/dist/actions/earn.js +83 -0
- package/dist/actions/infer.d.ts +8 -0
- package/dist/actions/infer.js +41 -0
- package/dist/actions/intel-preflight.d.ts +5 -0
- package/dist/actions/intel-preflight.js +97 -0
- package/dist/actions/intel-trust.d.ts +7 -0
- package/dist/actions/intel-trust.js +82 -0
- package/dist/actions/report.d.ts +8 -0
- package/dist/actions/report.js +45 -0
- package/dist/actions/rewards.d.ts +5 -0
- package/dist/actions/rewards.js +31 -0
- package/dist/actions/verify-receipt.d.ts +7 -0
- package/dist/actions/verify-receipt.js +44 -0
- package/dist/client-factory.d.ts +14 -0
- package/dist/client-factory.js +40 -0
- package/dist/client.d.ts +91 -3
- package/dist/client.js +136 -16
- package/dist/index.d.ts +26 -9
- package/dist/index.js +25 -9
- package/dist/intel-helpers.d.ts +22 -0
- package/dist/intel-helpers.js +181 -0
- package/dist/paying-fetch.d.ts +9 -0
- package/dist/paying-fetch.js +27 -0
- package/dist/test/plugin-registration.intel.d.ts +1 -0
- package/dist/test/plugin-registration.intel.js +253 -0
- package/package.json +21 -10
- package/dist/actions/deposit.d.ts +0 -2
- package/dist/actions/deposit.js +0 -79
- package/dist/actions/leaderboard.d.ts +0 -3
- package/dist/actions/leaderboard.js +0 -25
- package/dist/actions/portfolio.d.ts +0 -3
- package/dist/actions/portfolio.js +0 -20
- package/dist/actions/velocity.d.ts +0 -3
- package/dist/actions/velocity.js +0 -57
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WZRD_VERIFY_RECEIPT — Offline leaf + Ed25519 verification (no network).
|
|
3
|
+
* Handles both V5 and V6 receipts; the SDK selects the leaf binding from the
|
|
4
|
+
* receipt's domain (V6 binds the reputation_* provenance fields into the leaf).
|
|
5
|
+
*/
|
|
6
|
+
import type { Action } from '@elizaos/core';
|
|
7
|
+
export declare const verifyReceiptAction: Action;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { verifyReceipt } from '@wzrd_sol/sdk';
|
|
2
|
+
import { getIntelBase, parseReceipt, withTimeout } from '../intel-helpers.js';
|
|
3
|
+
export const verifyReceiptAction = {
|
|
4
|
+
name: 'WZRD_VERIFY_RECEIPT',
|
|
5
|
+
similes: ['WZRD_VERIFY', 'VERIFY_TWZRD_RECEIPT', 'CHECK_RECEIPT'],
|
|
6
|
+
description: 'Offline verify a TwzrdReceipt (V5 or V6): recompute keccak leaf from preimage and check Ed25519 signature ' +
|
|
7
|
+
'against the published TWZRD key. No network required when trustedPubkey is known.',
|
|
8
|
+
examples: [
|
|
9
|
+
[
|
|
10
|
+
{ name: '{{user1}}', content: { text: 'Verify this receipt: {"version":"v5","leaf":"0x...","preimage":{...}}' } },
|
|
11
|
+
{ name: '{{agentName}}', content: { text: 'Receipt valid: leaf OK, signature OK.' } },
|
|
12
|
+
],
|
|
13
|
+
],
|
|
14
|
+
validate: async () => true,
|
|
15
|
+
handler: async (runtime, message, _state, _opt, callback) => {
|
|
16
|
+
const content = (message.content ?? {});
|
|
17
|
+
const receipt = parseReceipt(content);
|
|
18
|
+
if (!receipt) {
|
|
19
|
+
await callback?.({
|
|
20
|
+
text: 'Provide a TwzrdReceipt as JSON in text or as content.receipt.',
|
|
21
|
+
});
|
|
22
|
+
return { success: false, error: 'Missing receipt' };
|
|
23
|
+
}
|
|
24
|
+
const apiBase = getIntelBase(runtime);
|
|
25
|
+
const fetchPubkey = content.fetch_pubkey === true || content.fetchPubkey === true;
|
|
26
|
+
try {
|
|
27
|
+
const result = await withTimeout(() => verifyReceipt(receipt, { apiBase, fetchPubkey }));
|
|
28
|
+
const text = result.valid
|
|
29
|
+
? `Receipt VALID (leaf=${result.leafValid}, sig=${result.signatureValid}, key=${result.trustedPubkey})`
|
|
30
|
+
: `Receipt INVALID: ${result.errors.join('; ') || 'unknown error'}`;
|
|
31
|
+
await callback?.({ text });
|
|
32
|
+
return {
|
|
33
|
+
success: result.valid,
|
|
34
|
+
data: result,
|
|
35
|
+
error: result.valid ? undefined : result.errors.join('; '),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
40
|
+
await callback?.({ text: `Verify failed: ${msg}` });
|
|
41
|
+
return { success: false, error: msg };
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { WzrdClient } from './client.js';
|
|
2
|
+
import type { IAgentRuntime } from '@elizaos/core';
|
|
3
|
+
import { intelPreflight, verifyReceipt } from '@wzrd_sol/sdk';
|
|
4
|
+
/** Intel API base URL from runtime settings (default https://intel.twzrd.xyz). */
|
|
5
|
+
export declare function getIntelApiBase(runtime: IAgentRuntime): string;
|
|
6
|
+
export declare function getWzrdClient(runtime: IAgentRuntime): WzrdClient;
|
|
7
|
+
/** Reset client cache — useful for tests. */
|
|
8
|
+
export declare function clearClientCache(): void;
|
|
9
|
+
/** Intel client (per plan): reads WZRD_INTEL_URL + paying fetch; thin delegate to SDK. */
|
|
10
|
+
export declare function getIntelClient(runtime: IAgentRuntime): {
|
|
11
|
+
preflight: (input: Parameters<typeof intelPreflight>[0]) => Promise<import("@wzrd_sol/sdk").PreflightResponse>;
|
|
12
|
+
trust: (pubkey: string) => Promise<import("@wzrd_sol/sdk").IntelTrustResponse>;
|
|
13
|
+
verify: (receipt: Parameters<typeof verifyReceipt>[0], opts?: Parameters<typeof verifyReceipt>[1]) => Promise<import("@wzrd_sol/sdk").VerifyReceiptResult>;
|
|
14
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Extract keypair from ElizaOS runtime, return cached WzrdClient. */
|
|
2
|
+
import { Keypair } from '@solana/web3.js';
|
|
3
|
+
import { WzrdClient } from './client.js';
|
|
4
|
+
import { getIntelBase, withTimeout } from './intel-helpers.js';
|
|
5
|
+
import { resolvePayingFetch } from './paying-fetch.js';
|
|
6
|
+
import { intelPreflight, fetchIntelTrust, verifyReceipt } from '@wzrd_sol/sdk';
|
|
7
|
+
const cache = new Map();
|
|
8
|
+
/** Intel API base URL from runtime settings (default https://intel.twzrd.xyz). */
|
|
9
|
+
export function getIntelApiBase(runtime) {
|
|
10
|
+
return getIntelBase(runtime);
|
|
11
|
+
}
|
|
12
|
+
export function getWzrdClient(runtime) {
|
|
13
|
+
const sk = runtime.getSetting('SOLANA_PRIVATE_KEY');
|
|
14
|
+
if (!sk)
|
|
15
|
+
throw new Error('SOLANA_PRIVATE_KEY not configured in ElizaOS runtime');
|
|
16
|
+
const kp = Keypair.fromSecretKey(Uint8Array.from(JSON.parse(String(sk))));
|
|
17
|
+
const pub = kp.publicKey.toBase58();
|
|
18
|
+
if (!cache.has(pub)) {
|
|
19
|
+
const apiUrl = runtime.getSetting('WZRD_API_URL');
|
|
20
|
+
cache.set(pub, new WzrdClient(kp, typeof apiUrl === 'string' ? apiUrl : undefined));
|
|
21
|
+
}
|
|
22
|
+
return cache.get(pub);
|
|
23
|
+
}
|
|
24
|
+
/** Reset client cache — useful for tests. */
|
|
25
|
+
export function clearClientCache() {
|
|
26
|
+
cache.clear();
|
|
27
|
+
}
|
|
28
|
+
/** Intel client (per plan): reads WZRD_INTEL_URL + paying fetch; thin delegate to SDK. */
|
|
29
|
+
export function getIntelClient(runtime) {
|
|
30
|
+
const apiBase = getIntelApiBase(runtime);
|
|
31
|
+
return {
|
|
32
|
+
preflight: (input) => withTimeout(() => intelPreflight(input, apiBase)),
|
|
33
|
+
trust: (pubkey) => withTimeout((signal) => {
|
|
34
|
+
const f = resolvePayingFetch(runtime);
|
|
35
|
+
const abortingFetch = ((input, init) => f(input, { ...(init || {}), signal }));
|
|
36
|
+
return fetchIntelTrust(pubkey, { apiBase, fetchImpl: abortingFetch });
|
|
37
|
+
}),
|
|
38
|
+
verify: (receipt, opts) => withTimeout(() => verifyReceipt(receipt, { apiBase, ...(opts || {}) })),
|
|
39
|
+
};
|
|
40
|
+
}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,3 +1,91 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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, verifyReceipt as verifyReceiptClient, } from '@wzrd_sol/sdk';
|
package/dist/client.js
CHANGED
|
@@ -1,17 +1,137 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
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
|
+
}
|
|
17
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, verifyReceipt as verifyReceiptClient, } from '@wzrd_sol/sdk';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @wzrd_sol/eliza-plugin — WZRD
|
|
3
|
-
* Thin adapter wrapping @wzrd_sol/solana-agent-plugin's WzrdClient.
|
|
2
|
+
* @wzrd_sol/eliza-plugin — WZRD Agent Intel + Earn Loop for ElizaOS
|
|
4
3
|
*
|
|
5
|
-
*
|
|
4
|
+
* Intel lane (default https://intel.twzrd.xyz):
|
|
5
|
+
* WZRD_INTEL_PREFLIGHT → WZRD_INTEL_TRUST → WZRD_VERIFY_RECEIPT
|
|
6
|
+
* Paid intel requires caller-supplied x402 fetch via setPayingFetch().
|
|
7
|
+
*
|
|
8
|
+
* Earn lane (default https://api.twzrd.xyz):
|
|
9
|
+
* WZRD_INFER → WZRD_REPORT → WZRD_EARN → WZRD_CLAIM / WZRD_REWARDS
|
|
10
|
+
*
|
|
11
|
+
* Config (runtime.getSetting):
|
|
12
|
+
* SOLANA_PRIVATE_KEY — required for earn tx/auth
|
|
13
|
+
* WZRD_API_URL — optional, defaults to https://api.twzrd.xyz
|
|
14
|
+
* WZRD_INTEL_URL — optional, defaults to https://intel.twzrd.xyz
|
|
6
15
|
*/
|
|
7
16
|
import type { Plugin } from '@elizaos/core';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
17
|
+
import { inferAction } from './actions/infer.js';
|
|
18
|
+
import { reportAction } from './actions/report.js';
|
|
19
|
+
import { earnAction } from './actions/earn.js';
|
|
10
20
|
import { claimAction } from './actions/claim.js';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
21
|
+
import { rewardsAction } from './actions/rewards.js';
|
|
22
|
+
import { intelPreflightAction } from './actions/intel-preflight.js';
|
|
23
|
+
import { intelTrustAction } from './actions/intel-trust.js';
|
|
24
|
+
import { verifyReceiptAction } from './actions/verify-receipt.js';
|
|
13
25
|
export declare const wzrdPlugin: Plugin;
|
|
14
26
|
export default wzrdPlugin;
|
|
15
|
-
export {
|
|
16
|
-
export { getWzrdClient } from './client.js';
|
|
27
|
+
export { intelPreflightAction, intelTrustAction, verifyReceiptAction, earnAction, inferAction, reportAction, claimAction, rewardsAction, };
|
|
28
|
+
export { getWzrdClient, clearClientCache, getIntelApiBase, getIntelClient } from './client-factory.js';
|
|
29
|
+
export { setPayingFetch, clearPayingFetch, resolvePayingFetch } from './paying-fetch.js';
|
|
30
|
+
export { WzrdClient } from './client.js';
|
|
31
|
+
export type { InferResult, ReportResult, RewardsBalance, ClaimResult } from './client.js';
|
|
32
|
+
export { IntelPaymentRequiredError, intelPreflight, fetchIntelTrust, verifyReceipt, preSpendGate, intelTrustUrl, TRUSTED_RECEIPT_PUBKEY, INTEL_TRUST_PRICE_USDC, } from '@wzrd_sol/sdk';
|
|
33
|
+
export type { ReadinessCard, PreflightInput, PreflightResponse, TwzrdReceipt, IntelTrustResponse, VerifyReceiptResult, X402PaymentRequired, } from '@wzrd_sol/sdk';
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { inferAction } from './actions/infer.js';
|
|
2
|
+
import { reportAction } from './actions/report.js';
|
|
3
|
+
import { earnAction } from './actions/earn.js';
|
|
3
4
|
import { claimAction } from './actions/claim.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
5
|
+
import { rewardsAction } from './actions/rewards.js';
|
|
6
|
+
import { intelPreflightAction } from './actions/intel-preflight.js';
|
|
7
|
+
import { intelTrustAction } from './actions/intel-trust.js';
|
|
8
|
+
import { verifyReceiptAction } from './actions/verify-receipt.js';
|
|
6
9
|
export const wzrdPlugin = {
|
|
7
10
|
name: 'wzrd',
|
|
8
|
-
description: 'WZRD
|
|
9
|
-
'
|
|
10
|
-
|
|
11
|
+
description: 'WZRD Agent Intel — free ReadinessCard preflight (gates spends before paying), x402-paid trust receipts ' +
|
|
12
|
+
'(V5/V6), offline verification on intel.twzrd.xyz. Also ships the legacy earn loop (infer/report/claim) ' +
|
|
13
|
+
'on api.twzrd.xyz.',
|
|
14
|
+
actions: [
|
|
15
|
+
intelPreflightAction,
|
|
16
|
+
intelTrustAction,
|
|
17
|
+
verifyReceiptAction,
|
|
18
|
+
earnAction,
|
|
19
|
+
inferAction,
|
|
20
|
+
reportAction,
|
|
21
|
+
claimAction,
|
|
22
|
+
rewardsAction,
|
|
23
|
+
],
|
|
11
24
|
};
|
|
12
25
|
export default wzrdPlugin;
|
|
13
|
-
export {
|
|
14
|
-
export { getWzrdClient } from './client.js';
|
|
26
|
+
export { intelPreflightAction, intelTrustAction, verifyReceiptAction, earnAction, inferAction, reportAction, claimAction, rewardsAction, };
|
|
27
|
+
export { getWzrdClient, clearClientCache, getIntelApiBase, getIntelClient } from './client-factory.js';
|
|
28
|
+
export { setPayingFetch, clearPayingFetch, resolvePayingFetch } from './paying-fetch.js';
|
|
29
|
+
export { WzrdClient } from './client.js';
|
|
30
|
+
export { IntelPaymentRequiredError, intelPreflight, fetchIntelTrust, verifyReceipt, preSpendGate, intelTrustUrl, TRUSTED_RECEIPT_PUBKEY, INTEL_TRUST_PRICE_USDC, } from '@wzrd_sol/sdk';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IntelPaymentRequiredError, type PreflightInput, type TwzrdReceipt } from '@wzrd_sol/sdk';
|
|
2
|
+
export declare function getIntelBase(runtime: {
|
|
3
|
+
getSetting: (k: string) => string | boolean | number | null;
|
|
4
|
+
}): string;
|
|
5
|
+
/** Pull structured fields from Eliza message content (flat or JSON-in-text). */
|
|
6
|
+
export declare function parsePreflightInput(content: Record<string, unknown>): PreflightInput;
|
|
7
|
+
export declare function parseReceipt(content: Record<string, unknown>): TwzrdReceipt | null;
|
|
8
|
+
export declare function extractPubkey(content: Record<string, unknown>): string | null;
|
|
9
|
+
export declare function formatPaymentRequired(err: IntelPaymentRequiredError, apiBase: string, pubkey: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Timeout wrapper for SDK network calls (preflight/trust/verify).
|
|
12
|
+
* Supports two call forms for minimal change:
|
|
13
|
+
* - withTimeout(promise) for preflight (SDK does not expose fetchImpl/signal)
|
|
14
|
+
* - withTimeout((signal) => sdkCallWithFetchImpl(abortingFetch)) for trust/verify
|
|
15
|
+
* Uses AbortController + signal: abort() is called on timeout so that when caller
|
|
16
|
+
* wires the returned signal into fetchImpl, the underlying network request is aborted.
|
|
17
|
+
* Always clears timer in finally (no leak). Attaches rejection observer to the
|
|
18
|
+
* call promise (without altering settlement) to avoid unhandled rejections on the
|
|
19
|
+
* loser of the race.
|
|
20
|
+
* Applied to actions + getIntelClient delegates.
|
|
21
|
+
*/
|
|
22
|
+
export declare function withTimeout<T>(pOrMake: Promise<T> | ((signal?: AbortSignal) => Promise<T>), ms?: number): Promise<T>;
|