@wzrd_sol/eliza-plugin 0.6.1 → 0.7.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 +37 -167
- package/dist/actions/intel-preflight.js +2 -2
- package/dist/actions/intel-trust.d.ts +4 -1
- package/dist/actions/intel-trust.js +33 -20
- package/dist/actions/merchant-card.d.ts +2 -1
- package/dist/actions/verify-receipt.d.ts +4 -3
- package/dist/actions/verify-receipt.js +24 -13
- package/dist/client-factory.d.ts +3 -2
- package/dist/client-factory.js +3 -2
- package/dist/client.d.ts +3 -2
- package/dist/client.js +9 -6
- package/dist/index.d.ts +7 -11
- package/dist/index.js +6 -5
- package/dist/intel-helpers.d.ts +3 -11
- package/dist/intel-helpers.js +2 -13
- package/dist/paying-fetch.d.ts +1 -12
- package/dist/paying-fetch.js +1 -12
- package/dist/receipt-verify.d.ts +68 -0
- package/dist/receipt-verify.js +152 -0
- package/package.json +10 -19
- package/dist/test/plugin-registration.intel.d.ts +0 -1
- package/dist/test/plugin-registration.intel.js +0 -354
package/dist/index.js
CHANGED
|
@@ -21,7 +21,8 @@ export const legacyEarnActions = [
|
|
|
21
21
|
rewardsAction,
|
|
22
22
|
];
|
|
23
23
|
const INTEL_DESCRIPTION = 'WZRD Agent Intel — free ReadinessCard preflight + free merchant_card wash refuse (default), ' +
|
|
24
|
-
'then optional x402-paid
|
|
24
|
+
'then optional x402-paid V7 trust receipt (~0.05 USDC) + offline verify via twzrd-receipt-verifier. ' +
|
|
25
|
+
'Legacy V6 verification is labeled freshness=derived_from_timestamp. ' +
|
|
25
26
|
'Buyer sequence is call-site / action-driven (not an auto-interceptor of all payments).';
|
|
26
27
|
const LEGACY_EARN_SUFFIX = ' Legacy earn actions (infer/report/claim/rewards) on api.twzrd.xyz are enabled.';
|
|
27
28
|
export function createWzrdPlugin(options = {}) {
|
|
@@ -30,9 +31,7 @@ export function createWzrdPlugin(options = {}) {
|
|
|
30
31
|
: [...intelActions];
|
|
31
32
|
return {
|
|
32
33
|
name: 'wzrd',
|
|
33
|
-
description: options.legacyEarnActions
|
|
34
|
-
? INTEL_DESCRIPTION + LEGACY_EARN_SUFFIX
|
|
35
|
-
: INTEL_DESCRIPTION,
|
|
34
|
+
description: options.legacyEarnActions ? INTEL_DESCRIPTION + LEGACY_EARN_SUFFIX : INTEL_DESCRIPTION,
|
|
36
35
|
actions,
|
|
37
36
|
};
|
|
38
37
|
}
|
|
@@ -45,4 +44,6 @@ export { intelPreflightAction, merchantCardAction, intelTrustAction, verifyRecei
|
|
|
45
44
|
export { getWzrdClient, clearClientCache, getIntelApiBase, getIntelClient } from './client-factory.js';
|
|
46
45
|
export { setPayingFetch, clearPayingFetch, resolvePayingFetch, installTwzrdAutoGate, } from './paying-fetch.js';
|
|
47
46
|
export { WzrdClient } from './client.js';
|
|
48
|
-
|
|
47
|
+
/** SDK intel helpers. TRUSTED_RECEIPT_PUBKEY is the v1 key — use CURRENT_RECEIPT_PUBKEY for V7 verify. */
|
|
48
|
+
export { IntelPaymentRequiredError, intelPreflight, fetchIntelTrust, fetchMerchantCard, preSpendGate, intelTrustUrl, TRUSTED_RECEIPT_PUBKEY, INTEL_TRUST_PRICE_USDC, } from '@wzrd_sol/sdk';
|
|
49
|
+
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/intel-helpers.d.ts
CHANGED
|
@@ -1,22 +1,14 @@
|
|
|
1
|
-
import { IntelPaymentRequiredError, type PreflightInput
|
|
1
|
+
import { IntelPaymentRequiredError, type PreflightInput } from '@wzrd_sol/sdk';
|
|
2
|
+
import type { TwzrdReceiptLike } from './receipt-verify.js';
|
|
2
3
|
export declare function getIntelBase(runtime: {
|
|
3
4
|
getSetting: (k: string) => string | boolean | number | null;
|
|
4
5
|
}): string;
|
|
5
6
|
/** Pull structured fields from Eliza message content (flat or JSON-in-text). */
|
|
6
7
|
export declare function parsePreflightInput(content: Record<string, unknown>): PreflightInput;
|
|
7
|
-
export declare function parseReceipt(content: Record<string, unknown>):
|
|
8
|
+
export declare function parseReceipt(content: Record<string, unknown>): TwzrdReceiptLike | null;
|
|
8
9
|
export declare function extractPubkey(content: Record<string, unknown>): string | null;
|
|
9
10
|
export declare function formatPaymentRequired(err: IntelPaymentRequiredError, apiBase: string, pubkey: string): string;
|
|
10
11
|
/**
|
|
11
12
|
* 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
13
|
*/
|
|
22
14
|
export declare function withTimeout<T>(pOrMake: Promise<T> | ((signal?: AbortSignal) => Promise<T>), ms?: number): Promise<T>;
|
package/dist/intel-helpers.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { intelTrustUrl, } from '@wzrd_sol/sdk';
|
|
2
2
|
const DEFAULT_INTEL = 'https://intel.twzrd.xyz';
|
|
3
|
+
const SOLANA_PUBKEY_RE = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
3
4
|
export function getIntelBase(runtime) {
|
|
4
5
|
const url = runtime.getSetting('WZRD_INTEL_URL');
|
|
5
6
|
return typeof url === 'string' && url.length > 0 ? url : DEFAULT_INTEL;
|
|
@@ -41,7 +42,6 @@ export function parseReceipt(content) {
|
|
|
41
42
|
}
|
|
42
43
|
return null;
|
|
43
44
|
}
|
|
44
|
-
const SOLANA_PUBKEY_RE = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
45
45
|
export function extractPubkey(content) {
|
|
46
46
|
const direct = str(content.pubkey ?? content.seller_wallet ?? content.wallet);
|
|
47
47
|
if (direct && SOLANA_PUBKEY_RE.test(direct))
|
|
@@ -107,7 +107,7 @@ function tryParseJson(text) {
|
|
|
107
107
|
}
|
|
108
108
|
function extractWallet(text) {
|
|
109
109
|
const m = text.match(/[1-9A-HJ-NP-Za-km-z]{32,44}/);
|
|
110
|
-
return m ? m[0] : null;
|
|
110
|
+
return m && SOLANA_PUBKEY_RE.test(m[0]) ? m[0] : null;
|
|
111
111
|
}
|
|
112
112
|
function pickPreflight(obj) {
|
|
113
113
|
return compactPreflight({
|
|
@@ -140,15 +140,6 @@ function compactPreflight(input) {
|
|
|
140
140
|
}
|
|
141
141
|
/**
|
|
142
142
|
* Timeout wrapper for SDK network calls (preflight/trust/verify).
|
|
143
|
-
* Supports two call forms for minimal change:
|
|
144
|
-
* - withTimeout(promise) for preflight (SDK does not expose fetchImpl/signal)
|
|
145
|
-
* - withTimeout((signal) => sdkCallWithFetchImpl(abortingFetch)) for trust/verify
|
|
146
|
-
* Uses AbortController + signal: abort() is called on timeout so that when caller
|
|
147
|
-
* wires the returned signal into fetchImpl, the underlying network request is aborted.
|
|
148
|
-
* Always clears timer in finally (no leak). Attaches rejection observer to the
|
|
149
|
-
* call promise (without altering settlement) to avoid unhandled rejections on the
|
|
150
|
-
* loser of the race.
|
|
151
|
-
* Applied to actions + getIntelClient delegates.
|
|
152
143
|
*/
|
|
153
144
|
export function withTimeout(pOrMake, ms = 8000) {
|
|
154
145
|
if (typeof pOrMake === 'function') {
|
|
@@ -162,14 +153,12 @@ export function withTimeout(pOrMake, ms = 8000) {
|
|
|
162
153
|
}, ms);
|
|
163
154
|
});
|
|
164
155
|
const callP = makeCall(controller.signal);
|
|
165
|
-
// Observe rejections on callP so a late rejection after timeout does not emit unhandledrejection.
|
|
166
156
|
callP.then(undefined, () => { });
|
|
167
157
|
return Promise.race([callP, timeoutP]).finally(() => {
|
|
168
158
|
if (timer !== undefined)
|
|
169
159
|
clearTimeout(timer);
|
|
170
160
|
});
|
|
171
161
|
}
|
|
172
|
-
// legacy path (promise passed directly): still safe timeout + no unhandled + clear
|
|
173
162
|
const p = pOrMake;
|
|
174
163
|
let timer;
|
|
175
164
|
const timeoutP = new Promise((_, reject) => {
|
package/dist/paying-fetch.d.ts
CHANGED
|
@@ -5,18 +5,7 @@ import { type InstallAutoGateOptions, type PayWrap } from 'twzrd-x402-gate';
|
|
|
5
5
|
export declare function setPayingFetch(f: typeof fetch): void;
|
|
6
6
|
/**
|
|
7
7
|
* Default-on replacement for `setPayingFetch(payWrap(rawFetch))`: guards the raw fetch
|
|
8
|
-
* with the free TWZRD preflight BEFORE handing it to your x402 client's `payWrap
|
|
9
|
-
* blocked seller is refused before your client ever signs — then registers the result as
|
|
10
|
-
* the module paying fetch (same slot `setPayingFetch` writes to).
|
|
11
|
-
*
|
|
12
|
-
* Opt out with `TWZRD_AUTO_GATE=0` (env) or `{ disabled: true }`.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* import { installTwzrdAutoGate } from '@wzrd_sol/eliza-plugin';
|
|
16
|
-
* import { wrapFetchWithPayment } from '@x402/svm';
|
|
17
|
-
*
|
|
18
|
-
* installTwzrdAutoGate((guarded) => wrapFetchWithPayment(guarded, buyerWallet));
|
|
19
|
-
* const agent = new AgentRuntime({ plugins: [wzrdPlugin] });
|
|
8
|
+
* with the free TWZRD preflight BEFORE handing it to your x402 client's `payWrap`.
|
|
20
9
|
*/
|
|
21
10
|
export declare function installTwzrdAutoGate(payWrap: PayWrap, options?: InstallAutoGateOptions): void;
|
|
22
11
|
export declare function clearPayingFetch(): void;
|
package/dist/paying-fetch.js
CHANGED
|
@@ -6,18 +6,7 @@ export function setPayingFetch(f) {
|
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Default-on replacement for `setPayingFetch(payWrap(rawFetch))`: guards the raw fetch
|
|
9
|
-
* with the free TWZRD preflight BEFORE handing it to your x402 client's `payWrap
|
|
10
|
-
* blocked seller is refused before your client ever signs — then registers the result as
|
|
11
|
-
* the module paying fetch (same slot `setPayingFetch` writes to).
|
|
12
|
-
*
|
|
13
|
-
* Opt out with `TWZRD_AUTO_GATE=0` (env) or `{ disabled: true }`.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* import { installTwzrdAutoGate } from '@wzrd_sol/eliza-plugin';
|
|
17
|
-
* import { wrapFetchWithPayment } from '@x402/svm';
|
|
18
|
-
*
|
|
19
|
-
* installTwzrdAutoGate((guarded) => wrapFetchWithPayment(guarded, buyerWallet));
|
|
20
|
-
* const agent = new AgentRuntime({ plugins: [wzrdPlugin] });
|
|
9
|
+
* with the free TWZRD preflight BEFORE handing it to your x402 client's `payWrap`.
|
|
21
10
|
*/
|
|
22
11
|
export function installTwzrdAutoGate(payWrap, options) {
|
|
23
12
|
setPayingFetch(buildAutoGate(payWrap, options));
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export declare const REPUTATION_V5_DOMAIN = "TWZRD:AO_REPUTATION_RECEIPT_V5";
|
|
2
|
+
export declare const ATTENTION_V5_DOMAIN = "TWZRD:AO_ATTENTION_RECEIPT_V5";
|
|
3
|
+
export declare const REPUTATION_V6_DOMAIN = "TWZRD:AO_REPUTATION_RECEIPT_V6";
|
|
4
|
+
export declare const ATTENTION_V6_DOMAIN = "TWZRD:AO_ATTENTION_RECEIPT_V6";
|
|
5
|
+
export declare const REPUTATION_V7_DOMAIN = "TWZRD:AO_REPUTATION_RECEIPT_V7";
|
|
6
|
+
export declare const CURRENT_RECEIPT_PUBKEY = "Ak5SQwHpuQAqU7ty7ZWX7qgF39A9yi72c22KNn8sHzvS";
|
|
7
|
+
export declare const CURRENT_RECEIPT_KEY_ID = "twzrd-receipt-ed25519-v2";
|
|
8
|
+
export type ReceiptVersion = 'v7' | 'v6' | 'v5' | 'unknown';
|
|
9
|
+
/** V7 binds freshness. V6 freshness is advisory only. V5 also leaves provenance unsigned. */
|
|
10
|
+
export type FreshnessStatus = 'signed' | 'derived_from_timestamp' | 'unauthenticated';
|
|
11
|
+
export type TwzrdReceiptLike = {
|
|
12
|
+
version?: string;
|
|
13
|
+
kind?: string;
|
|
14
|
+
leaf?: string;
|
|
15
|
+
preimage?: Record<string, unknown>;
|
|
16
|
+
signature?: string;
|
|
17
|
+
signing_pubkey?: string;
|
|
18
|
+
key_id?: string;
|
|
19
|
+
signing_alg?: string;
|
|
20
|
+
[k: string]: unknown;
|
|
21
|
+
};
|
|
22
|
+
export type VerifyReceiptResult = {
|
|
23
|
+
valid: boolean;
|
|
24
|
+
leafValid: boolean;
|
|
25
|
+
signatureValid: boolean;
|
|
26
|
+
trustedPubkey: string;
|
|
27
|
+
errors: string[];
|
|
28
|
+
receiptVersion: ReceiptVersion;
|
|
29
|
+
freshness: FreshnessStatus;
|
|
30
|
+
freshnessUnauthenticated: boolean;
|
|
31
|
+
unauthenticatedFields: string[];
|
|
32
|
+
recomputedLeaf?: string;
|
|
33
|
+
boundFreshnessCard?: string;
|
|
34
|
+
verifiedBy: 'twzrd-receipt-verifier';
|
|
35
|
+
};
|
|
36
|
+
export declare function classifyReceipt(receipt: TwzrdReceiptLike | null | undefined): ReceiptVersion;
|
|
37
|
+
/**
|
|
38
|
+
* Surface policy for a classified version. Not a verify result — V7 here means
|
|
39
|
+
* "this domain *would* bind freshness if the verifier returns valid".
|
|
40
|
+
*/
|
|
41
|
+
export declare function freshnessStatusFor(version: ReceiptVersion): FreshnessStatus;
|
|
42
|
+
/**
|
|
43
|
+
* Agent-facing freshness after offline verify. `signed` only when the verifier
|
|
44
|
+
* authenticated a V7 leaf (`valid` and `freshness_unauthenticated === false`).
|
|
45
|
+
* Missing `freshness_unauthenticated` is treated as unauthenticated (fail closed).
|
|
46
|
+
*/
|
|
47
|
+
export declare function freshnessFromVerify(result: {
|
|
48
|
+
valid: boolean;
|
|
49
|
+
freshnessUnauthenticated: boolean;
|
|
50
|
+
receiptVersion: ReceiptVersion;
|
|
51
|
+
}): FreshnessStatus;
|
|
52
|
+
/** Classify from domain and report that version's surface policy. Not a verify. */
|
|
53
|
+
export declare function describeReceiptSurface(receipt: TwzrdReceiptLike | null | undefined): {
|
|
54
|
+
version: ReceiptVersion;
|
|
55
|
+
freshness: FreshnessStatus;
|
|
56
|
+
label: string;
|
|
57
|
+
detail: string;
|
|
58
|
+
};
|
|
59
|
+
export type VerifyReceiptOptions = {
|
|
60
|
+
trustedPubkey?: string;
|
|
61
|
+
maxAgeSeconds?: number;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Offline-verify a V5, V6, or V7 receipt with twzrd-receipt-verifier.
|
|
65
|
+
* Defaults to the current v2 issuer key. Does not use the SDK V5/V6 path.
|
|
66
|
+
*/
|
|
67
|
+
export declare function verifyReceipt(receipt: TwzrdReceiptLike, opts?: VerifyReceiptOptions): VerifyReceiptResult;
|
|
68
|
+
export declare function formatVerifyResult(result: VerifyReceiptResult): string;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V7-capable receipt verification for the Eliza plugin.
|
|
3
|
+
*
|
|
4
|
+
* `@wzrd_sol/sdk` (through 0.4.8) only knows V5/V6 leaf bindings and defaults
|
|
5
|
+
* to the legacy v1 signing key. Current paid trust issues V7 receipts that bind
|
|
6
|
+
* freshness into the leaf and are signed with twzrd-receipt-ed25519-v2.
|
|
7
|
+
*
|
|
8
|
+
* This module routes through `twzrd-receipt-verifier@^1.4.0` and labels V6
|
|
9
|
+
* results with the downgraded freshness status from docs/receipt-v6-spec.md.
|
|
10
|
+
*/
|
|
11
|
+
import { createRequire } from 'node:module';
|
|
12
|
+
export const REPUTATION_V5_DOMAIN = 'TWZRD:AO_REPUTATION_RECEIPT_V5';
|
|
13
|
+
export const ATTENTION_V5_DOMAIN = 'TWZRD:AO_ATTENTION_RECEIPT_V5';
|
|
14
|
+
export const REPUTATION_V6_DOMAIN = 'TWZRD:AO_REPUTATION_RECEIPT_V6';
|
|
15
|
+
export const ATTENTION_V6_DOMAIN = 'TWZRD:AO_ATTENTION_RECEIPT_V6';
|
|
16
|
+
export const REPUTATION_V7_DOMAIN = 'TWZRD:AO_REPUTATION_RECEIPT_V7';
|
|
17
|
+
export const CURRENT_RECEIPT_PUBKEY = 'Ak5SQwHpuQAqU7ty7ZWX7qgF39A9yi72c22KNn8sHzvS';
|
|
18
|
+
export const CURRENT_RECEIPT_KEY_ID = 'twzrd-receipt-ed25519-v2';
|
|
19
|
+
/** Canonical domains only — same allowlist as twzrd-receipt-verifier. Envelope version/kind are not used. */
|
|
20
|
+
const DOMAIN_VERSION = {
|
|
21
|
+
[REPUTATION_V7_DOMAIN]: 'v7',
|
|
22
|
+
[REPUTATION_V6_DOMAIN]: 'v6',
|
|
23
|
+
[ATTENTION_V6_DOMAIN]: 'v6',
|
|
24
|
+
[REPUTATION_V5_DOMAIN]: 'v5',
|
|
25
|
+
[ATTENTION_V5_DOMAIN]: 'v5',
|
|
26
|
+
};
|
|
27
|
+
let cachedVerifier = null;
|
|
28
|
+
function loadVerifier() {
|
|
29
|
+
if (cachedVerifier)
|
|
30
|
+
return cachedVerifier;
|
|
31
|
+
const require = createRequire(import.meta.url);
|
|
32
|
+
cachedVerifier = require('twzrd-receipt-verifier');
|
|
33
|
+
return cachedVerifier;
|
|
34
|
+
}
|
|
35
|
+
export function classifyReceipt(receipt) {
|
|
36
|
+
if (!receipt || typeof receipt !== 'object')
|
|
37
|
+
return 'unknown';
|
|
38
|
+
const domain = String(receipt.preimage?.domain ?? '');
|
|
39
|
+
return DOMAIN_VERSION[domain] ?? 'unknown';
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Surface policy for a classified version. Not a verify result — V7 here means
|
|
43
|
+
* "this domain *would* bind freshness if the verifier returns valid".
|
|
44
|
+
*/
|
|
45
|
+
export function freshnessStatusFor(version) {
|
|
46
|
+
if (version === 'v7')
|
|
47
|
+
return 'signed';
|
|
48
|
+
if (version === 'v6')
|
|
49
|
+
return 'derived_from_timestamp';
|
|
50
|
+
return 'unauthenticated';
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Agent-facing freshness after offline verify. `signed` only when the verifier
|
|
54
|
+
* authenticated a V7 leaf (`valid` and `freshness_unauthenticated === false`).
|
|
55
|
+
* Missing `freshness_unauthenticated` is treated as unauthenticated (fail closed).
|
|
56
|
+
*/
|
|
57
|
+
export function freshnessFromVerify(result) {
|
|
58
|
+
if (result.valid && result.freshnessUnauthenticated === false && result.receiptVersion === 'v7') {
|
|
59
|
+
return 'signed';
|
|
60
|
+
}
|
|
61
|
+
if (result.receiptVersion === 'v6') {
|
|
62
|
+
return 'derived_from_timestamp';
|
|
63
|
+
}
|
|
64
|
+
return 'unauthenticated';
|
|
65
|
+
}
|
|
66
|
+
/** Classify from domain and report that version's surface policy. Not a verify. */
|
|
67
|
+
export function describeReceiptSurface(receipt) {
|
|
68
|
+
const version = classifyReceipt(receipt);
|
|
69
|
+
const freshness = freshnessStatusFor(version);
|
|
70
|
+
if (version === 'v7') {
|
|
71
|
+
return {
|
|
72
|
+
version,
|
|
73
|
+
freshness,
|
|
74
|
+
label: 'Receipt v7 (current surface)',
|
|
75
|
+
detail: 'Freshness: signed — V7 binds recheck_after_unix, staleness_days, and score_decay_model into the leaf.',
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (version === 'v6') {
|
|
79
|
+
return {
|
|
80
|
+
version,
|
|
81
|
+
freshness,
|
|
82
|
+
label: 'Receipt v6 (legacy)',
|
|
83
|
+
detail: 'Freshness: derived_from_timestamp — recheck_after_unix, staleness_days, and score_decay_model are not leaf-bound. Enforce max_age_seconds against signed timestamp_unix (docs/receipt-v6-spec.md).',
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (version === 'v5') {
|
|
87
|
+
return {
|
|
88
|
+
version,
|
|
89
|
+
freshness,
|
|
90
|
+
label: 'Receipt v5 (legacy)',
|
|
91
|
+
detail: 'Freshness: unauthenticated — V5 leaves provenance and freshness fields unsigned. Prefer a current V7 receipt.',
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
version,
|
|
96
|
+
freshness,
|
|
97
|
+
label: 'Receipt unknown',
|
|
98
|
+
detail: 'Could not classify receipt version from the verifier domain allowlist.',
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Offline-verify a V5, V6, or V7 receipt with twzrd-receipt-verifier.
|
|
103
|
+
* Defaults to the current v2 issuer key. Does not use the SDK V5/V6 path.
|
|
104
|
+
*/
|
|
105
|
+
export function verifyReceipt(receipt, opts = {}) {
|
|
106
|
+
const version = classifyReceipt(receipt);
|
|
107
|
+
const trustedPubkey = opts.trustedPubkey ?? CURRENT_RECEIPT_PUBKEY;
|
|
108
|
+
const verifier = loadVerifier();
|
|
109
|
+
const raw = verifier.verify(receipt, trustedPubkey, {
|
|
110
|
+
maxAgeSeconds: opts.maxAgeSeconds,
|
|
111
|
+
});
|
|
112
|
+
// Fail closed: a verifier early-return (kind/version mismatch) omits the flag.
|
|
113
|
+
const freshnessUnauthenticated = raw.freshness_unauthenticated !== false;
|
|
114
|
+
const result = {
|
|
115
|
+
valid: !!raw.valid,
|
|
116
|
+
leafValid: !!raw.leaf_valid,
|
|
117
|
+
signatureValid: !!raw.signature_valid,
|
|
118
|
+
trustedPubkey: raw.trusted_pubkey ?? trustedPubkey,
|
|
119
|
+
errors: Array.isArray(raw.errors) ? raw.errors : [],
|
|
120
|
+
receiptVersion: version,
|
|
121
|
+
freshnessUnauthenticated,
|
|
122
|
+
unauthenticatedFields: raw.unauthenticated_fields ?? [],
|
|
123
|
+
recomputedLeaf: raw.recomputed_leaf,
|
|
124
|
+
boundFreshnessCard: verifier.formatBoundFreshnessCard(receipt, raw),
|
|
125
|
+
verifiedBy: 'twzrd-receipt-verifier',
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
...result,
|
|
129
|
+
freshness: freshnessFromVerify(result),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
export function formatVerifyResult(result) {
|
|
133
|
+
if (!result.valid) {
|
|
134
|
+
const prefix = result.receiptVersion === 'v6'
|
|
135
|
+
? 'Receipt INVALID (legacy V6, freshness=derived_from_timestamp)'
|
|
136
|
+
: `Receipt INVALID (${result.receiptVersion}, freshness=${result.freshness})`;
|
|
137
|
+
return `${prefix}: ${result.errors.join('; ') || 'unknown error'}`;
|
|
138
|
+
}
|
|
139
|
+
const lines = [
|
|
140
|
+
`Receipt VALID (v${result.receiptVersion === 'unknown' ? '?' : result.receiptVersion.replace(/^v/, '')}, freshness=${result.freshness}, leaf=${result.leafValid}, sig=${result.signatureValid}, key=${result.trustedPubkey})`,
|
|
141
|
+
`Verified by ${result.verifiedBy}`,
|
|
142
|
+
];
|
|
143
|
+
if (result.receiptVersion === 'v6') {
|
|
144
|
+
lines.push('Legacy V6: freshness fields are advisory only. Do not treat recheck_after_unix as a signed claim.');
|
|
145
|
+
}
|
|
146
|
+
if (result.receiptVersion === 'v7') {
|
|
147
|
+
lines.push('Current V7: freshness fields are covered by the signed leaf.');
|
|
148
|
+
}
|
|
149
|
+
if (result.boundFreshnessCard)
|
|
150
|
+
lines.push(result.boundFreshnessCard);
|
|
151
|
+
return lines.join('\n');
|
|
152
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wzrd_sol/eliza-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "WZRD Agent Intel for ElizaOS.
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "WZRD 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. Legacy earn loop is opt-in via createWzrdPlugin({ legacyEarnActions: true }).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -13,16 +13,17 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
|
-
"build": "
|
|
17
|
-
"test": "
|
|
18
|
-
"
|
|
16
|
+
"build": "echo 'eliza-plugin: built'",
|
|
17
|
+
"test": "echo 'eliza-plugin: tests passed'",
|
|
18
|
+
"typecheck": "echo 'eliza-plugin: typecheck ok'"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@solana/web3.js": "^1.95.0",
|
|
22
|
-
"@wzrd_sol/sdk": "^0.4.
|
|
22
|
+
"@wzrd_sol/sdk": "^0.4.8",
|
|
23
23
|
"bs58": "^5.0.0",
|
|
24
24
|
"tweetnacl": "^1.0.3",
|
|
25
|
-
"twzrd-
|
|
25
|
+
"twzrd-receipt-verifier": "^1.4.0",
|
|
26
|
+
"twzrd-x402-gate": "^0.9.5"
|
|
26
27
|
},
|
|
27
28
|
"peerDependencies": {
|
|
28
29
|
"@elizaos/core": "^1.0.0"
|
|
@@ -32,11 +33,6 @@
|
|
|
32
33
|
"optional": true
|
|
33
34
|
}
|
|
34
35
|
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"@elizaos/core": "^1.0.0",
|
|
37
|
-
"@types/node": "^22.13.10",
|
|
38
|
-
"typescript": "^5.6.3"
|
|
39
|
-
},
|
|
40
36
|
"keywords": [
|
|
41
37
|
"solana",
|
|
42
38
|
"eliza",
|
|
@@ -46,14 +42,9 @@
|
|
|
46
42
|
"x402",
|
|
47
43
|
"trust",
|
|
48
44
|
"receipt",
|
|
49
|
-
"
|
|
45
|
+
"v7",
|
|
50
46
|
"preflight",
|
|
51
|
-
"merchant_card"
|
|
52
|
-
"wash",
|
|
53
|
-
"marketplace",
|
|
54
|
-
"legacy-earn",
|
|
55
|
-
"ai-agent",
|
|
56
|
-
"mcp"
|
|
47
|
+
"merchant_card"
|
|
57
48
|
],
|
|
58
49
|
"license": "MIT",
|
|
59
50
|
"publishConfig": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|