@valiron/sdk 2.0.0 → 2.1.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 +12 -0
- package/bin/valiron-card.mjs +211 -0
- package/dist/card.d.ts +565 -0
- package/dist/card.js +722 -0
- package/dist/clients.js +2 -2
- package/dist/edge.d.ts +87 -0
- package/dist/edge.js +164 -0
- package/dist/edgeGate.d.ts +146 -0
- package/dist/edgeGate.js +230 -0
- package/dist/edgeGateVerify.d.ts +146 -0
- package/dist/edgeGateVerify.js +243 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/middleware.d.ts +2 -0
- package/dist/middleware.js +6 -3
- package/dist/operatorSdk.d.ts +8 -0
- package/dist/operatorSdk.js +8 -0
- package/docs/API-REFERENCE.md +59 -80
- package/docs/CLOUDFLARE-GATE-MIDDLEWARE.md +196 -0
- package/docs/CRAWLER-PROTECTION.md +509 -25
- package/docs/DASHBOARD.md +72 -214
- package/docs/E2E-MIDDLEWARE-INTEGRATION.md +9 -46
- package/docs/ERRORS.md +3 -11
- package/docs/PROVIDER-IDENTITY.md +1 -1
- package/docs/QUICKSTART.md +7 -22
- package/docs/README.md +10 -9
- package/docs/SDK-REFERENCE.md +51 -7
- package/docs/SECURITY-UPGRADE-2026-10-31.md +3 -3
- package/docs/llms.txt +19 -14
- package/examples/cloudflare-gate-worker/README.md +198 -0
- package/examples/cloudflare-gate-worker/package.json +20 -0
- package/examples/cloudflare-gate-worker/worker.ts +309 -0
- package/examples/cloudflare-gate-worker/wrangler.toml +46 -0
- package/examples/cloudflare-worker/package.json +8 -0
- package/examples/cloudflare-worker/worker.ts +495 -0
- package/examples/cloudflare-worker/wrangler.toml +57 -0
- package/package.json +34 -4
- package/docs/AGENT-READY-APIS.md +0 -294
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Application-owned wallet proof verification for the Cloudflare trust gate.
|
|
3
|
+
*
|
|
4
|
+
* This is the edge (workerd-safe) verify side of the `valiron-wallet-request-v2`
|
|
5
|
+
* signed-request contract documented in docs/SECURITY-UPGRADE-2026-10-31.md and
|
|
6
|
+
* implemented server-side in services/edge-proxy requestProof.ts. It lets an API
|
|
7
|
+
* seller verify an ordinary (non-ANS) agent's ownership proof locally in a
|
|
8
|
+
* Cloudflare Worker, bound to the agent's current registry owner wallet from the
|
|
9
|
+
* live Valiron profile.
|
|
10
|
+
*
|
|
11
|
+
* Contract mirrored exactly:
|
|
12
|
+
* - headers: x-agent-timestamp (13-digit ms), x-agent-nonce (24-128 URL-safe
|
|
13
|
+
* chars), x-agent-request-signature
|
|
14
|
+
* - payload lines joined with "\n":
|
|
15
|
+
* valiron-wallet-request-v2
|
|
16
|
+
* agent:<exact-request-agent-id>
|
|
17
|
+
* chain:<network string, as resolved for the agent>
|
|
18
|
+
* method:<UPPERCASE method>
|
|
19
|
+
* url:<absolute public request URL (request.url verbatim)>
|
|
20
|
+
* body-sha256:<lowercase hex sha256 of ("" for no body, else
|
|
21
|
+
* JSON.stringify(JSON.parse(rawBody)))>
|
|
22
|
+
* timestamp:<ms>
|
|
23
|
+
* nonce:<fresh nonce>
|
|
24
|
+
* - timestamp window: |now - timestamp| <= 60_000 ms
|
|
25
|
+
* - nonce consumed exactly once per wallet+network+nonce scope
|
|
26
|
+
* (sha256 hex of `<wallet|wallet.toLowerCase()>:<network>:<nonce>`), TTL 121s
|
|
27
|
+
* - EVM: EIP-191 personal_sign over the UTF-8 payload, recovered address must
|
|
28
|
+
* equal the registry owner wallet (case-insensitive)
|
|
29
|
+
* - Solana: Ed25519 over the UTF-8 payload, signature base64url, wallet is the
|
|
30
|
+
* base58 public key
|
|
31
|
+
*
|
|
32
|
+
* Replay protection is MANDATORY: pass a durable `nonceStore`. In Cloudflare
|
|
33
|
+
* Workers use a Durable Object (see examples/cloudflare-gate-worker). Without a
|
|
34
|
+
* store this module fails closed.
|
|
35
|
+
*/
|
|
36
|
+
/** Durable, atomic nonce claimer. Implementations must be atomic across all
|
|
37
|
+
* isolates that serve the gate (a Durable Object or equivalent shared store). */
|
|
38
|
+
export interface NonceStore {
|
|
39
|
+
/** Returns true exactly once per `scope` within `ttlSeconds`; false on replay
|
|
40
|
+
* or when the store is unavailable (callers fail closed). */
|
|
41
|
+
claim(scope: string, ttlSeconds: number): Promise<boolean>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* TEST/LOCAL ONLY. Atomic within a single isolate; NOT safe as a production
|
|
45
|
+
* replay control across Cloudflare isolates or restarts. The deployable
|
|
46
|
+
* template binds a Durable Object instead.
|
|
47
|
+
*/
|
|
48
|
+
export declare class MemoryNonceStore implements NonceStore {
|
|
49
|
+
private seen;
|
|
50
|
+
claim(scope: string, ttlSeconds: number): Promise<boolean>;
|
|
51
|
+
}
|
|
52
|
+
/** Chain-specific cryptographic primitives, supplied by the integrating app so
|
|
53
|
+
* the SDK stays dependency-free. The Cloudflare template ships ready-made
|
|
54
|
+
* adapters (viem for EVM, WebCrypto Ed25519 for Solana). */
|
|
55
|
+
export interface WalletProofCrypto {
|
|
56
|
+
/** EIP-191: recover the signer address of `message` (UTF-8) from a 0x-hex
|
|
57
|
+
* signature. Return lowercase hex. */
|
|
58
|
+
recoverEvmAddress(message: string, signature: string): Promise<string>;
|
|
59
|
+
/** Ed25519: verify a base64url signature over the UTF-8 `message` against the
|
|
60
|
+
* base58 Solana public key. */
|
|
61
|
+
verifySolanaSignature(message: string, signatureBase64url: string, publicKeyBase58: string): Promise<boolean>;
|
|
62
|
+
}
|
|
63
|
+
export interface WalletProofVerificationConfig {
|
|
64
|
+
/** Exact agent id as the request claims it (gate-resolved identifier). */
|
|
65
|
+
agentId: string;
|
|
66
|
+
/** Network/chain string the proof signs over - the same string the gate used
|
|
67
|
+
* to resolve the agent (e.g. the profile's chain.network value). */
|
|
68
|
+
network: string;
|
|
69
|
+
/** Current registry owner wallet from the live profile (EVM 0x address, or
|
|
70
|
+
* base58 Solana public key). For key-based agents: the agent's own address. */
|
|
71
|
+
registryWallet: string;
|
|
72
|
+
/** True when `network` is a Solana network (wallet is base58, Ed25519). */
|
|
73
|
+
isSolana: boolean;
|
|
74
|
+
/** Durable nonce store. REQUIRED - verification fails closed without it. */
|
|
75
|
+
nonceStore: NonceStore;
|
|
76
|
+
crypto: WalletProofCrypto;
|
|
77
|
+
/** Timestamp tolerance in ms (default 60_000, matching the server). */
|
|
78
|
+
maxAgeMs?: number;
|
|
79
|
+
/** Injectable clock for tests. */
|
|
80
|
+
now?: number;
|
|
81
|
+
}
|
|
82
|
+
export type WalletProofResult = {
|
|
83
|
+
ok: true;
|
|
84
|
+
} | {
|
|
85
|
+
ok: false;
|
|
86
|
+
reason: string;
|
|
87
|
+
};
|
|
88
|
+
declare function base64urlToBytes(value: string): Uint8Array;
|
|
89
|
+
/** Build the exact canonical payload the agent signed. Exported for tests and
|
|
90
|
+
* for the sign-side recipe; the layout must stay byte-identical with the
|
|
91
|
+
* server implementation. */
|
|
92
|
+
export declare function buildWalletProofPayload(input: {
|
|
93
|
+
agentId: string;
|
|
94
|
+
network: string;
|
|
95
|
+
method: string;
|
|
96
|
+
url: string;
|
|
97
|
+
bodySha256: string;
|
|
98
|
+
timestamp: string;
|
|
99
|
+
nonce: string;
|
|
100
|
+
}): string;
|
|
101
|
+
/**
|
|
102
|
+
* Verify one inbound request's wallet proof headers against the live registry
|
|
103
|
+
* owner. `rawBody` is the exact request body text ("" when none); JSON bodies
|
|
104
|
+
* are canonicalized exactly as the server does (parse then stringify), and a
|
|
105
|
+
* body that fails to parse can never produce a valid proof.
|
|
106
|
+
*/
|
|
107
|
+
export declare function verifyWalletRequestProof(request: {
|
|
108
|
+
method: string;
|
|
109
|
+
url: string;
|
|
110
|
+
headers: {
|
|
111
|
+
get(name: string): string | null;
|
|
112
|
+
};
|
|
113
|
+
}, rawBody: string, config: WalletProofVerificationConfig): Promise<WalletProofResult>;
|
|
114
|
+
/** Decode a base58 Solana public key to its 32 raw bytes. Shipped so templates
|
|
115
|
+
* need no dependency for the Ed25519 path. Throws on invalid input. */
|
|
116
|
+
export declare function base58Decode(value: string): Uint8Array;
|
|
117
|
+
/** WebCrypto Ed25519 adapter for Solana wallets - ready to use in Workers.
|
|
118
|
+
* Builds the SPKI wrapper around the raw 32-byte key exactly like the server's
|
|
119
|
+
* Node verifier does. */
|
|
120
|
+
export declare const webCryptoSolanaVerifier: WalletProofCrypto["verifySolanaSignature"];
|
|
121
|
+
/** base64urlToBytes exported for adapters/tests. */
|
|
122
|
+
export { base64urlToBytes };
|
|
123
|
+
/** Owner resolution for one gate identifier: the current registry owner wallet
|
|
124
|
+
* plus the network string the proof signs over, from the LIVE Valiron profile.
|
|
125
|
+
* Return null when the identifier is unknown (verification fails closed). */
|
|
126
|
+
export type WalletProofOwnerResolver = (identifier: string) => Promise<{
|
|
127
|
+
wallet: string;
|
|
128
|
+
network: string;
|
|
129
|
+
isSolana: boolean;
|
|
130
|
+
} | null>;
|
|
131
|
+
/**
|
|
132
|
+
* Ready-to-use `verifyRequest` for `runValironEdgeGate`: verifies the
|
|
133
|
+
* application-owned wallet proof (x-agent-timestamp / x-agent-nonce /
|
|
134
|
+
* x-agent-request-signature) of every identified request against the live
|
|
135
|
+
* registry owner, with mandatory durable replay protection.
|
|
136
|
+
*
|
|
137
|
+
* This is the default verifier for ordinary non-ANS agents. Valiron's hosted
|
|
138
|
+
* ANS provider-identity verification remains available via
|
|
139
|
+
* createEdgeIdentityVerifier for ans:// identities.
|
|
140
|
+
*/
|
|
141
|
+
export declare function createEdgeWalletProofVerifier(config: {
|
|
142
|
+
resolveOwner: WalletProofOwnerResolver;
|
|
143
|
+
nonceStore: NonceStore;
|
|
144
|
+
crypto: WalletProofCrypto;
|
|
145
|
+
maxAgeMs?: number;
|
|
146
|
+
}): (request: Request, identifier: string) => Promise<boolean>;
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Application-owned wallet proof verification for the Cloudflare trust gate.
|
|
4
|
+
*
|
|
5
|
+
* This is the edge (workerd-safe) verify side of the `valiron-wallet-request-v2`
|
|
6
|
+
* signed-request contract documented in docs/SECURITY-UPGRADE-2026-10-31.md and
|
|
7
|
+
* implemented server-side in services/edge-proxy requestProof.ts. It lets an API
|
|
8
|
+
* seller verify an ordinary (non-ANS) agent's ownership proof locally in a
|
|
9
|
+
* Cloudflare Worker, bound to the agent's current registry owner wallet from the
|
|
10
|
+
* live Valiron profile.
|
|
11
|
+
*
|
|
12
|
+
* Contract mirrored exactly:
|
|
13
|
+
* - headers: x-agent-timestamp (13-digit ms), x-agent-nonce (24-128 URL-safe
|
|
14
|
+
* chars), x-agent-request-signature
|
|
15
|
+
* - payload lines joined with "\n":
|
|
16
|
+
* valiron-wallet-request-v2
|
|
17
|
+
* agent:<exact-request-agent-id>
|
|
18
|
+
* chain:<network string, as resolved for the agent>
|
|
19
|
+
* method:<UPPERCASE method>
|
|
20
|
+
* url:<absolute public request URL (request.url verbatim)>
|
|
21
|
+
* body-sha256:<lowercase hex sha256 of ("" for no body, else
|
|
22
|
+
* JSON.stringify(JSON.parse(rawBody)))>
|
|
23
|
+
* timestamp:<ms>
|
|
24
|
+
* nonce:<fresh nonce>
|
|
25
|
+
* - timestamp window: |now - timestamp| <= 60_000 ms
|
|
26
|
+
* - nonce consumed exactly once per wallet+network+nonce scope
|
|
27
|
+
* (sha256 hex of `<wallet|wallet.toLowerCase()>:<network>:<nonce>`), TTL 121s
|
|
28
|
+
* - EVM: EIP-191 personal_sign over the UTF-8 payload, recovered address must
|
|
29
|
+
* equal the registry owner wallet (case-insensitive)
|
|
30
|
+
* - Solana: Ed25519 over the UTF-8 payload, signature base64url, wallet is the
|
|
31
|
+
* base58 public key
|
|
32
|
+
*
|
|
33
|
+
* Replay protection is MANDATORY: pass a durable `nonceStore`. In Cloudflare
|
|
34
|
+
* Workers use a Durable Object (see examples/cloudflare-gate-worker). Without a
|
|
35
|
+
* store this module fails closed.
|
|
36
|
+
*/
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.webCryptoSolanaVerifier = exports.MemoryNonceStore = void 0;
|
|
39
|
+
exports.buildWalletProofPayload = buildWalletProofPayload;
|
|
40
|
+
exports.verifyWalletRequestProof = verifyWalletRequestProof;
|
|
41
|
+
exports.base58Decode = base58Decode;
|
|
42
|
+
exports.base64urlToBytes = base64urlToBytes;
|
|
43
|
+
exports.createEdgeWalletProofVerifier = createEdgeWalletProofVerifier;
|
|
44
|
+
/**
|
|
45
|
+
* TEST/LOCAL ONLY. Atomic within a single isolate; NOT safe as a production
|
|
46
|
+
* replay control across Cloudflare isolates or restarts. The deployable
|
|
47
|
+
* template binds a Durable Object instead.
|
|
48
|
+
*/
|
|
49
|
+
class MemoryNonceStore {
|
|
50
|
+
constructor() {
|
|
51
|
+
this.seen = new Map();
|
|
52
|
+
}
|
|
53
|
+
async claim(scope, ttlSeconds) {
|
|
54
|
+
const now = Date.now();
|
|
55
|
+
for (const [k, exp] of this.seen)
|
|
56
|
+
if (exp <= now)
|
|
57
|
+
this.seen.delete(k);
|
|
58
|
+
if (this.seen.has(scope))
|
|
59
|
+
return false;
|
|
60
|
+
this.seen.set(scope, now + ttlSeconds * 1000);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.MemoryNonceStore = MemoryNonceStore;
|
|
65
|
+
const encoder = new TextEncoder();
|
|
66
|
+
async function sha256Hex(input) {
|
|
67
|
+
const digest = await crypto.subtle.digest("SHA-256", encoder.encode(input));
|
|
68
|
+
return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
69
|
+
}
|
|
70
|
+
function base64urlToBytes(value) {
|
|
71
|
+
const b64 = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
72
|
+
const bin = atob(b64 + "=".repeat((4 - (b64.length % 4)) % 4));
|
|
73
|
+
const out = new Uint8Array(bin.length);
|
|
74
|
+
for (let i = 0; i < bin.length; i++)
|
|
75
|
+
out[i] = bin.charCodeAt(i);
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
/** Build the exact canonical payload the agent signed. Exported for tests and
|
|
79
|
+
* for the sign-side recipe; the layout must stay byte-identical with the
|
|
80
|
+
* server implementation. */
|
|
81
|
+
function buildWalletProofPayload(input) {
|
|
82
|
+
return [
|
|
83
|
+
"valiron-wallet-request-v2",
|
|
84
|
+
`agent:${input.agentId}`,
|
|
85
|
+
`chain:${input.network}`,
|
|
86
|
+
`method:${input.method.toUpperCase()}`,
|
|
87
|
+
`url:${input.url}`,
|
|
88
|
+
`body-sha256:${input.bodySha256.toLowerCase()}`,
|
|
89
|
+
`timestamp:${input.timestamp}`,
|
|
90
|
+
`nonce:${input.nonce}`,
|
|
91
|
+
].join("\n");
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Verify one inbound request's wallet proof headers against the live registry
|
|
95
|
+
* owner. `rawBody` is the exact request body text ("" when none); JSON bodies
|
|
96
|
+
* are canonicalized exactly as the server does (parse then stringify), and a
|
|
97
|
+
* body that fails to parse can never produce a valid proof.
|
|
98
|
+
*/
|
|
99
|
+
async function verifyWalletRequestProof(request, rawBody, config) {
|
|
100
|
+
const timestamp = request.headers.get("x-agent-timestamp") ?? "";
|
|
101
|
+
const nonce = request.headers.get("x-agent-nonce") ?? "";
|
|
102
|
+
const signature = request.headers.get("x-agent-request-signature") ?? "";
|
|
103
|
+
const now = config.now ?? Date.now();
|
|
104
|
+
const maxAge = config.maxAgeMs ?? 60000;
|
|
105
|
+
// Custom windows may tighten freshness, never extend it beyond the durable
|
|
106
|
+
// store's retention horizon. Include the future-skew boundary in retention.
|
|
107
|
+
if (!Number.isFinite(maxAge) || maxAge <= 0 || maxAge > 60000)
|
|
108
|
+
return { ok: false, reason: "invalid_timestamp_window" };
|
|
109
|
+
if (!/^\d{13}$/.test(timestamp) || Math.abs(now - Number(timestamp)) > maxAge) {
|
|
110
|
+
return { ok: false, reason: "stale_or_invalid_timestamp" };
|
|
111
|
+
}
|
|
112
|
+
if (!/^[A-Za-z0-9_-]{24,128}$/.test(nonce) || !signature) {
|
|
113
|
+
return { ok: false, reason: "missing_or_invalid_proof_headers" };
|
|
114
|
+
}
|
|
115
|
+
// Canonical body digest: empty string for no body, otherwise
|
|
116
|
+
// JSON.stringify of the parsed JSON body (mirrors the server exactly).
|
|
117
|
+
let bodyForDigest = "";
|
|
118
|
+
if (rawBody !== "") {
|
|
119
|
+
try {
|
|
120
|
+
bodyForDigest = JSON.stringify(JSON.parse(rawBody));
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return { ok: false, reason: "body_not_canonical_json" };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const bodySha256 = await sha256Hex(bodyForDigest);
|
|
127
|
+
const payload = buildWalletProofPayload({
|
|
128
|
+
agentId: config.agentId,
|
|
129
|
+
network: config.network,
|
|
130
|
+
method: request.method,
|
|
131
|
+
url: request.url,
|
|
132
|
+
bodySha256,
|
|
133
|
+
timestamp,
|
|
134
|
+
nonce,
|
|
135
|
+
});
|
|
136
|
+
let valid = false;
|
|
137
|
+
try {
|
|
138
|
+
if (config.isSolana) {
|
|
139
|
+
valid = await config.crypto.verifySolanaSignature(payload, signature, config.registryWallet);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
const recovered = await config.crypto.recoverEvmAddress(payload, signature);
|
|
143
|
+
valid = recovered.toLowerCase() === config.registryWallet.toLowerCase();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return { ok: false, reason: "signature_verification_error" };
|
|
148
|
+
}
|
|
149
|
+
if (!valid)
|
|
150
|
+
return { ok: false, reason: "ownership_proof_invalid" };
|
|
151
|
+
const scopeWallet = config.isSolana ? config.registryWallet : config.registryWallet.toLowerCase();
|
|
152
|
+
const scope = await sha256Hex(`${scopeWallet}:${config.network}:${nonce}`);
|
|
153
|
+
if (!config.nonceStore)
|
|
154
|
+
return { ok: false, reason: "replay_store_unavailable" };
|
|
155
|
+
let claimed = false;
|
|
156
|
+
try {
|
|
157
|
+
claimed = await config.nonceStore.claim(scope, 121);
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
claimed = false;
|
|
161
|
+
}
|
|
162
|
+
if (!claimed)
|
|
163
|
+
return { ok: false, reason: "proof_replay_or_store_unavailable" };
|
|
164
|
+
return { ok: true };
|
|
165
|
+
}
|
|
166
|
+
/** Decode a base58 Solana public key to its 32 raw bytes. Shipped so templates
|
|
167
|
+
* need no dependency for the Ed25519 path. Throws on invalid input. */
|
|
168
|
+
function base58Decode(value) {
|
|
169
|
+
const ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
170
|
+
let num = 0n;
|
|
171
|
+
for (const ch of value) {
|
|
172
|
+
const idx = ALPHABET.indexOf(ch);
|
|
173
|
+
if (idx < 0)
|
|
174
|
+
throw new Error("invalid base58");
|
|
175
|
+
num = num * 58n + BigInt(idx);
|
|
176
|
+
}
|
|
177
|
+
let hex = num.toString(16);
|
|
178
|
+
if (hex.length % 2)
|
|
179
|
+
hex = "0" + hex;
|
|
180
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
181
|
+
for (let i = 0; i < bytes.length; i++)
|
|
182
|
+
bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
183
|
+
// Restore leading zero bytes (base58 '1's).
|
|
184
|
+
let leading = 0;
|
|
185
|
+
for (const ch of value) {
|
|
186
|
+
if (ch === "1")
|
|
187
|
+
leading++;
|
|
188
|
+
else
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
const out = new Uint8Array(leading + bytes.length);
|
|
192
|
+
out.set(bytes, leading);
|
|
193
|
+
return out;
|
|
194
|
+
}
|
|
195
|
+
/** WebCrypto Ed25519 adapter for Solana wallets - ready to use in Workers.
|
|
196
|
+
* Builds the SPKI wrapper around the raw 32-byte key exactly like the server's
|
|
197
|
+
* Node verifier does. */
|
|
198
|
+
const webCryptoSolanaVerifier = async (message, signatureBase64url, publicKeyBase58) => {
|
|
199
|
+
const SPKI_ED25519_PREFIX = base64urlToBytes("MCowBQYDK2VwAyEA"); // 302a300506032b6570032100
|
|
200
|
+
const rawKey = base58Decode(publicKeyBase58);
|
|
201
|
+
if (rawKey.length !== 32)
|
|
202
|
+
return false;
|
|
203
|
+
const spki = new Uint8Array(SPKI_ED25519_PREFIX.length + 32);
|
|
204
|
+
spki.set(SPKI_ED25519_PREFIX, 0);
|
|
205
|
+
spki.set(rawKey, SPKI_ED25519_PREFIX.length);
|
|
206
|
+
const key = await crypto.subtle.importKey("spki", spki, { name: "Ed25519" }, false, ["verify"]);
|
|
207
|
+
return crypto.subtle.verify("Ed25519", key, base64urlToBytes(signatureBase64url), encoder.encode(message));
|
|
208
|
+
};
|
|
209
|
+
exports.webCryptoSolanaVerifier = webCryptoSolanaVerifier;
|
|
210
|
+
/**
|
|
211
|
+
* Ready-to-use `verifyRequest` for `runValironEdgeGate`: verifies the
|
|
212
|
+
* application-owned wallet proof (x-agent-timestamp / x-agent-nonce /
|
|
213
|
+
* x-agent-request-signature) of every identified request against the live
|
|
214
|
+
* registry owner, with mandatory durable replay protection.
|
|
215
|
+
*
|
|
216
|
+
* This is the default verifier for ordinary non-ANS agents. Valiron's hosted
|
|
217
|
+
* ANS provider-identity verification remains available via
|
|
218
|
+
* createEdgeIdentityVerifier for ans:// identities.
|
|
219
|
+
*/
|
|
220
|
+
function createEdgeWalletProofVerifier(config) {
|
|
221
|
+
return async (request, identifier) => {
|
|
222
|
+
let owner;
|
|
223
|
+
try {
|
|
224
|
+
owner = await config.resolveOwner(identifier);
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
if (!owner || !owner.wallet || !owner.network)
|
|
230
|
+
return false;
|
|
231
|
+
const rawBody = await request.clone().text();
|
|
232
|
+
const result = await verifyWalletRequestProof(request, rawBody, {
|
|
233
|
+
agentId: identifier,
|
|
234
|
+
network: owner.network,
|
|
235
|
+
registryWallet: owner.wallet,
|
|
236
|
+
isSolana: owner.isSolana,
|
|
237
|
+
nonceStore: config.nonceStore,
|
|
238
|
+
crypto: config.crypto,
|
|
239
|
+
...(config.maxAgeMs !== undefined ? { maxAgeMs: config.maxAgeMs } : {}),
|
|
240
|
+
});
|
|
241
|
+
return result.ok;
|
|
242
|
+
};
|
|
243
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -438,5 +438,6 @@ export { createValironIdentityGate, valironIdentityFastifyPlugin, createValironI
|
|
|
438
438
|
export type { ValironIdentityGateConfig, ValironIdentityFastifyConfig, ValironIdentityNextConfig, ValironIdentityGateCheckResult, } from "./identityMiddleware";
|
|
439
439
|
export { isValidAddress, generateChallenge, sha256RequestDigest, buildAgentIdentitySigningPayload, createAgentIdentityProof, agentIdentityProofHeaders, agentIdentityProofFromHeaders, AGENT_IDENTITY_HEADERS, } from "./identity";
|
|
440
440
|
export type { ChallengeResponse, AgentIdentityBody, CreateAgentIdentityProofInput, } from "./identity";
|
|
441
|
+
/** @deprecated Per-call charging is no longer offered; see `createValironGate`. */
|
|
441
442
|
export { ValironOperator } from "./operatorSdk";
|
|
442
443
|
export type { ValironOperatorConfig, PaywallConfig } from "./operatorSdk";
|
package/dist/index.js
CHANGED
|
@@ -497,5 +497,6 @@ Object.defineProperty(exports, "createAgentIdentityProof", { enumerable: true, g
|
|
|
497
497
|
Object.defineProperty(exports, "agentIdentityProofHeaders", { enumerable: true, get: function () { return identity_1.agentIdentityProofHeaders; } });
|
|
498
498
|
Object.defineProperty(exports, "agentIdentityProofFromHeaders", { enumerable: true, get: function () { return identity_1.agentIdentityProofFromHeaders; } });
|
|
499
499
|
Object.defineProperty(exports, "AGENT_IDENTITY_HEADERS", { enumerable: true, get: function () { return identity_1.AGENT_IDENTITY_HEADERS; } });
|
|
500
|
+
/** @deprecated Per-call charging is no longer offered; see `createValironGate`. */
|
|
500
501
|
var operatorSdk_1 = require("./operatorSdk");
|
|
501
502
|
Object.defineProperty(exports, "ValironOperator", { enumerable: true, get: function () { return operatorSdk_1.ValironOperator; } });
|
package/dist/middleware.d.ts
CHANGED
|
@@ -272,6 +272,8 @@ export interface ValironGateCheckResult {
|
|
|
272
272
|
* ```
|
|
273
273
|
*/
|
|
274
274
|
export declare function valironGateCheck(sdk: ValironSDK, opts: {
|
|
275
|
+
/** Retain automatic evaluation work after an edge response. */
|
|
276
|
+
waitUntil?: (pending: Promise<unknown>) => void;
|
|
275
277
|
/** On-chain agent ID (ERC-8004 / Solana). */
|
|
276
278
|
agentId?: string | null;
|
|
277
279
|
/** Key-based agent hash (web2). Checked if agentId is not provided. */
|
package/dist/middleware.js
CHANGED
|
@@ -71,7 +71,8 @@ function keyProfileToGateResult(profile, minScore) {
|
|
|
71
71
|
const tier = (profile.tier ?? "C");
|
|
72
72
|
const riskLevel = (profile.riskLevel ?? "RED");
|
|
73
73
|
const route = (profile.route ?? "sandbox_only");
|
|
74
|
-
const
|
|
74
|
+
const isProductionRoute = route === "prod" || route === "prod_throttled";
|
|
75
|
+
const allow = profile.verified && isProductionRoute && score >= minScore;
|
|
75
76
|
return {
|
|
76
77
|
allow,
|
|
77
78
|
score,
|
|
@@ -813,7 +814,8 @@ async function valironGateCheck(sdk, opts) {
|
|
|
813
814
|
result = profileToGateResult(profile, effectiveMinScore);
|
|
814
815
|
// Detect brand-new agent: on-chain identity exists but zero reputation.
|
|
815
816
|
if (!result.allow && (profile.onchainReputation?.totalFeedback ?? 0) === 0) {
|
|
816
|
-
sdk.triggerSandboxTest(agentId).catch(() => { });
|
|
817
|
+
const pending = sdk.triggerSandboxTest(agentId).catch(() => { });
|
|
818
|
+
opts.waitUntil?.(pending);
|
|
817
819
|
pendingEvaluation = true;
|
|
818
820
|
}
|
|
819
821
|
}
|
|
@@ -823,7 +825,8 @@ async function valironGateCheck(sdk, opts) {
|
|
|
823
825
|
// Detect brand-new key agent: verified but never scored.
|
|
824
826
|
if (!result.allow && profile.verified && profile.score == null) {
|
|
825
827
|
if (typeof sdk.triggerKeyAgentSandbox === "function") {
|
|
826
|
-
sdk.triggerKeyAgentSandbox(agentAddress).catch(() => { });
|
|
828
|
+
const pending = sdk.triggerKeyAgentSandbox(agentAddress).catch(() => { });
|
|
829
|
+
opts.waitUntil?.(pending);
|
|
827
830
|
}
|
|
828
831
|
pendingEvaluation = true;
|
|
829
832
|
}
|
package/dist/operatorSdk.d.ts
CHANGED
|
@@ -51,6 +51,10 @@ export interface PaywallConfig {
|
|
|
51
51
|
/**
|
|
52
52
|
* Valiron Operator SDK — for API sellers who want to monetize their endpoints.
|
|
53
53
|
*
|
|
54
|
+
* @deprecated Valiron no longer offers per-call charging of agents. Use `createValironGate`,
|
|
55
|
+
* `valironFastifyPlugin` or `createValironNextMiddleware` to gate routes; this export
|
|
56
|
+
* will be removed in a future major version.
|
|
57
|
+
*
|
|
54
58
|
* @example
|
|
55
59
|
* ```typescript
|
|
56
60
|
* import { ValironOperator } from '@valiron/sdk';
|
|
@@ -87,6 +91,8 @@ export declare class ValironOperator {
|
|
|
87
91
|
/**
|
|
88
92
|
* Create Express/Connect middleware that gates access + tracks usage.
|
|
89
93
|
*
|
|
94
|
+
* @deprecated Use `createValironGate` or `valironFastifyPlugin`. Per-call charging is no longer offered.
|
|
95
|
+
*
|
|
90
96
|
* Extracts `X-Agent-Id` from request, runs trust gate, and attaches
|
|
91
97
|
* `req.valiron` with the gate result + pricing info.
|
|
92
98
|
*
|
|
@@ -109,6 +115,8 @@ export declare class ValironOperator {
|
|
|
109
115
|
/**
|
|
110
116
|
* Create a Fastify plugin that gates access + tracks usage.
|
|
111
117
|
*
|
|
118
|
+
* @deprecated Use `createValironGate` or `valironFastifyPlugin`. Per-call charging is no longer offered.
|
|
119
|
+
*
|
|
112
120
|
* @example
|
|
113
121
|
* ```typescript
|
|
114
122
|
* app.register(operator.fastifyPaywall({
|
package/dist/operatorSdk.js
CHANGED
|
@@ -6,6 +6,10 @@ const middleware_js_1 = require("./middleware.js");
|
|
|
6
6
|
/**
|
|
7
7
|
* Valiron Operator SDK — for API sellers who want to monetize their endpoints.
|
|
8
8
|
*
|
|
9
|
+
* @deprecated Valiron no longer offers per-call charging of agents. Use `createValironGate`,
|
|
10
|
+
* `valironFastifyPlugin` or `createValironNextMiddleware` to gate routes; this export
|
|
11
|
+
* will be removed in a future major version.
|
|
12
|
+
*
|
|
9
13
|
* @example
|
|
10
14
|
* ```typescript
|
|
11
15
|
* import { ValironOperator } from '@valiron/sdk';
|
|
@@ -113,6 +117,8 @@ class ValironOperator {
|
|
|
113
117
|
/**
|
|
114
118
|
* Create Express/Connect middleware that gates access + tracks usage.
|
|
115
119
|
*
|
|
120
|
+
* @deprecated Use `createValironGate` or `valironFastifyPlugin`. Per-call charging is no longer offered.
|
|
121
|
+
*
|
|
116
122
|
* Extracts `X-Agent-Id` from request, runs trust gate, and attaches
|
|
117
123
|
* `req.valiron` with the gate result + pricing info.
|
|
118
124
|
*
|
|
@@ -208,6 +214,8 @@ class ValironOperator {
|
|
|
208
214
|
/**
|
|
209
215
|
* Create a Fastify plugin that gates access + tracks usage.
|
|
210
216
|
*
|
|
217
|
+
* @deprecated Use `createValironGate` or `valironFastifyPlugin`. Per-call charging is no longer offered.
|
|
218
|
+
*
|
|
211
219
|
* @example
|
|
212
220
|
* ```typescript
|
|
213
221
|
* app.register(operator.fastifyPaywall({
|