@sparkysolutions/agentrail 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +249 -3
- package/dist/cli/mcp-stdio.d.ts +8 -0
- package/dist/cli/mcp-stdio.js +454 -0
- package/dist/cli/pipeline.d.ts +40 -0
- package/dist/cli/pipeline.js +114 -0
- package/dist/cli/sandbox.d.ts +55 -0
- package/dist/cli/sandbox.js +107 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +39 -0
- package/dist/lib/agent-badge-issuer.d.ts +36 -0
- package/dist/lib/agent-badge-issuer.js +166 -0
- package/dist/lib/agent-registry.d.ts +136 -0
- package/dist/lib/agent-registry.js +124 -0
- package/dist/lib/agenthustle-pipeline.d.ts +68 -0
- package/dist/lib/agenthustle-pipeline.js +143 -0
- package/dist/lib/agentpass-pipeline.d.ts +44 -0
- package/dist/lib/agentpass-pipeline.js +84 -0
- package/dist/lib/audit-trail-provider.d.ts +24 -0
- package/dist/lib/audit-trail-provider.js +60 -0
- package/dist/lib/axis-clob-provider.d.ts +50 -0
- package/dist/lib/axis-clob-provider.js +150 -0
- package/dist/lib/circuit-breaker.d.ts +60 -0
- package/dist/lib/circuit-breaker.js +136 -0
- package/dist/lib/conditional-escrow.d.ts +42 -0
- package/dist/lib/conditional-escrow.js +126 -0
- package/dist/lib/mcp-server.d.ts +29 -0
- package/dist/lib/mcp-server.js +165 -0
- package/dist/lib/micro-stream.d.ts +21 -0
- package/dist/lib/micro-stream.js +41 -0
- package/dist/lib/proof-of-task.d.ts +12 -0
- package/dist/lib/proof-of-task.js +32 -0
- package/dist/lib/receipts.d.ts +153 -0
- package/dist/lib/receipts.js +173 -0
- package/dist/lib/reflector-oracle-adapter.d.ts +44 -0
- package/dist/lib/reflector-oracle-adapter.js +173 -0
- package/dist/lib/scoped-allowance.d.ts +15 -0
- package/dist/lib/scoped-allowance.js +116 -0
- package/dist/lib/ttl-keeper.d.ts +10 -0
- package/dist/lib/ttl-keeper.js +36 -0
- package/dist/lib/universal-adapters.d.ts +42 -0
- package/dist/lib/universal-adapters.js +69 -0
- package/dist/lib/x402-gateway.d.ts +86 -0
- package/dist/lib/x402-gateway.js +128 -0
- package/dist/lib/x402-pipeline.d.ts +51 -0
- package/dist/lib/x402-pipeline.js +105 -0
- package/dist/sdk/agent-client.d.ts +26 -0
- package/dist/sdk/agent-client.js +53 -0
- package/dist/types.d.ts +181 -0
- package/dist/types.js +5 -0
- package/glama.json +12 -0
- package/package.json +56 -6
- package/smithery.json +43 -0
- package/smithery.yaml +29 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SANDBOX_RECEIPT_TAG = exports.SANDBOX_CONTRACT_ID = void 0;
|
|
4
|
+
exports.provisionSandbox = provisionSandbox;
|
|
5
|
+
exports.inspectBalance = inspectBalance;
|
|
6
|
+
exports.executeSandboxSpend = executeSandboxSpend;
|
|
7
|
+
exports.anchorSandboxReceipt = anchorSandboxReceipt;
|
|
8
|
+
const agent_client_js_1 = require("../sdk/agent-client.js");
|
|
9
|
+
const micro_stream_js_1 = require("../lib/micro-stream.js");
|
|
10
|
+
const receipts_js_1 = require("../lib/receipts.js");
|
|
11
|
+
/** AgentRail's testnet deployment (deployment.testnet.json). */
|
|
12
|
+
exports.SANDBOX_CONTRACT_ID = "CBSWWN2CLUPW4VLYTGVJTT4XWXKF6LLJFQXEC7KK2KTAW3A26WIBZIN6";
|
|
13
|
+
/** Tag on sandbox receipts, so nobody reads them as a real on-chain spend. */
|
|
14
|
+
exports.SANDBOX_RECEIPT_TAG = "agentrail-sandbox";
|
|
15
|
+
/**
|
|
16
|
+
* Provision a sandboxed environment for autonomous AI agent micro-spend simulation.
|
|
17
|
+
*/
|
|
18
|
+
function provisionSandbox(agentName = "Gemini-Soroban-Worker-01", budgetUsdc = "50.00", feeBps = 20) {
|
|
19
|
+
const client = new agent_client_js_1.AgentRailClient();
|
|
20
|
+
const ownerAddress = "GDDJH64X5VEXI7UWZMJA3YUG7ANYHKRRRFHLD2SF5OWEETNFBVYMRXZT";
|
|
21
|
+
const treasuryAddress = "GDDJH64X5VEXI7UWZMJA3YUG7ANYHKRRRFHLD2SF5OWEETNFBVYMRXZT";
|
|
22
|
+
// Placeholder keys in valid Stellar format (no funds, secret discarded) so receipts can validate them.
|
|
23
|
+
const agentKey = "GAA5MW7J4KPUBC6S7T7K72VF6N4M34X4B5WT4QTKNNI7WNU37PG2H2I5";
|
|
24
|
+
const now = Math.floor(Date.now() / 1000);
|
|
25
|
+
const agent = {
|
|
26
|
+
id: `agent_${Date.now()}`,
|
|
27
|
+
name: agentName,
|
|
28
|
+
publicKey: agentKey,
|
|
29
|
+
role: "Autonomous Inference & Data Processing",
|
|
30
|
+
};
|
|
31
|
+
const limitStroops = (0, micro_stream_js_1.usdcToStroops)(budgetUsdc);
|
|
32
|
+
const allowance = {
|
|
33
|
+
id: `allowance_${agent.id}`,
|
|
34
|
+
ownerPublicKey: ownerAddress,
|
|
35
|
+
agentPublicKey: agent.publicKey,
|
|
36
|
+
maxStroops: limitStroops,
|
|
37
|
+
spentStroops: 0n,
|
|
38
|
+
validFrom: now - 60,
|
|
39
|
+
validUntil: now + 86400, // 24h
|
|
40
|
+
active: true,
|
|
41
|
+
protocolFeeBps: feeBps,
|
|
42
|
+
treasuryPublicKey: treasuryAddress,
|
|
43
|
+
};
|
|
44
|
+
client.registerAllowance(allowance);
|
|
45
|
+
return {
|
|
46
|
+
client,
|
|
47
|
+
ownerAddress,
|
|
48
|
+
treasuryAddress,
|
|
49
|
+
agent,
|
|
50
|
+
allowance,
|
|
51
|
+
protocolFeeBps: feeBps,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Inspect live allowance balance and capacity for an agent.
|
|
56
|
+
*/
|
|
57
|
+
function inspectBalance(env, allowanceId, currentTimeSec = Math.floor(Date.now() / 1000)) {
|
|
58
|
+
const allowance = env.client.allowances.get(allowanceId);
|
|
59
|
+
if (!allowance) {
|
|
60
|
+
throw new Error(`Allowance ${allowanceId} does not exist in sandbox.`);
|
|
61
|
+
}
|
|
62
|
+
const remaining = allowance.maxStroops - allowance.spentStroops;
|
|
63
|
+
const isExpired = currentTimeSec > allowance.validUntil;
|
|
64
|
+
return {
|
|
65
|
+
allowanceId: allowance.id,
|
|
66
|
+
totalLimitStroops: allowance.maxStroops.toString(),
|
|
67
|
+
spentStroops: allowance.spentStroops.toString(),
|
|
68
|
+
remainingStroops: remaining.toString(),
|
|
69
|
+
remainingUsdc: (0, micro_stream_js_1.stroopsToUsdc)(remaining),
|
|
70
|
+
active: allowance.active && !isExpired,
|
|
71
|
+
isExpired,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Execute an automated micro-spend within the sandbox.
|
|
76
|
+
*/
|
|
77
|
+
function executeSandboxSpend(env, amountUsdc, memo = "inference:gemini-pro-1.5") {
|
|
78
|
+
const amountStroops = (0, micro_stream_js_1.usdcToStroops)(amountUsdc);
|
|
79
|
+
const feeStroops = (amountStroops * BigInt(env.protocolFeeBps)) / 10000n;
|
|
80
|
+
const netStroops = amountStroops - feeStroops;
|
|
81
|
+
const request = {
|
|
82
|
+
allowanceId: env.allowance.id,
|
|
83
|
+
agentPublicKey: env.agent.publicKey,
|
|
84
|
+
destination: "GDWPTOV25IQE2DFW7UYCBAQ4VF5D6HYSRDBPMNFPHL7S5SSAN7WFCO2X",
|
|
85
|
+
amountStroops,
|
|
86
|
+
timestamp: Math.floor(Date.now() / 1000),
|
|
87
|
+
memo,
|
|
88
|
+
};
|
|
89
|
+
const result = env.client.spend(request);
|
|
90
|
+
return { result, feeStroops, netStroops, request };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Opt-in: anchor a public receipt for a sandbox spend (only its SHA-256 leaves AgentRail).
|
|
94
|
+
* Tagged `agentrail-sandbox`, since the spend is simulated. Never throws.
|
|
95
|
+
*/
|
|
96
|
+
async function anchorSandboxReceipt(spend, provider, contractId = exports.SANDBOX_CONTRACT_ID) {
|
|
97
|
+
if (!spend.result.ok) {
|
|
98
|
+
return { ok: false, contentSha256: "", error: `Spend was rejected (${spend.result.code}); no receipt to anchor` };
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
const receipt = (0, receipts_js_1.buildSpendReceipt)(spend.request, spend.result, { contractId });
|
|
102
|
+
return await (0, receipts_js_1.anchorReceipt)(receipt, provider, { tag: exports.SANDBOX_RECEIPT_TAG });
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
return { ok: false, contentSha256: "", error: err instanceof Error ? err.message : String(err) };
|
|
106
|
+
}
|
|
107
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentRail Protocol Entrypoint.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./types.js";
|
|
5
|
+
export * from "./lib/scoped-allowance.js";
|
|
6
|
+
export * from "./lib/micro-stream.js";
|
|
7
|
+
export * from "./lib/ttl-keeper.js";
|
|
8
|
+
export * from "./lib/proof-of-task.js";
|
|
9
|
+
export * from "./lib/receipts.js";
|
|
10
|
+
export * from "./lib/audit-trail-provider.js";
|
|
11
|
+
export * from "./lib/axis-clob-provider.js";
|
|
12
|
+
export * from "./lib/agent-registry.js";
|
|
13
|
+
export * from "./lib/x402-gateway.js";
|
|
14
|
+
export * from "./lib/mcp-server.js";
|
|
15
|
+
export * from "./lib/conditional-escrow.js";
|
|
16
|
+
export * from "./lib/reflector-oracle-adapter.js";
|
|
17
|
+
export * from "./lib/agent-badge-issuer.js";
|
|
18
|
+
export * from "./lib/universal-adapters.js";
|
|
19
|
+
export * from "./lib/agentpass-pipeline.js";
|
|
20
|
+
export * from "./lib/x402-pipeline.js";
|
|
21
|
+
export * from "./lib/agenthustle-pipeline.js";
|
|
22
|
+
export * from "./sdk/agent-client.js";
|
|
23
|
+
export * from "./cli/sandbox.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AgentRail Protocol Entrypoint.
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./types.js"), exports);
|
|
21
|
+
__exportStar(require("./lib/scoped-allowance.js"), exports);
|
|
22
|
+
__exportStar(require("./lib/micro-stream.js"), exports);
|
|
23
|
+
__exportStar(require("./lib/ttl-keeper.js"), exports);
|
|
24
|
+
__exportStar(require("./lib/proof-of-task.js"), exports);
|
|
25
|
+
__exportStar(require("./lib/receipts.js"), exports);
|
|
26
|
+
__exportStar(require("./lib/audit-trail-provider.js"), exports);
|
|
27
|
+
__exportStar(require("./lib/axis-clob-provider.js"), exports);
|
|
28
|
+
__exportStar(require("./lib/agent-registry.js"), exports);
|
|
29
|
+
__exportStar(require("./lib/x402-gateway.js"), exports);
|
|
30
|
+
__exportStar(require("./lib/mcp-server.js"), exports);
|
|
31
|
+
__exportStar(require("./lib/conditional-escrow.js"), exports);
|
|
32
|
+
__exportStar(require("./lib/reflector-oracle-adapter.js"), exports);
|
|
33
|
+
__exportStar(require("./lib/agent-badge-issuer.js"), exports);
|
|
34
|
+
__exportStar(require("./lib/universal-adapters.js"), exports);
|
|
35
|
+
__exportStar(require("./lib/agentpass-pipeline.js"), exports);
|
|
36
|
+
__exportStar(require("./lib/x402-pipeline.js"), exports);
|
|
37
|
+
__exportStar(require("./lib/agenthustle-pipeline.js"), exports);
|
|
38
|
+
__exportStar(require("./sdk/agent-client.js"), exports);
|
|
39
|
+
__exportStar(require("./cli/sandbox.js"), exports);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentRail - SEP-50 Compliant Autonomous Agent Verification Badge Issuer
|
|
3
|
+
*
|
|
4
|
+
* Implements Stellar Ecosystem Proposal 50 (SEP-50) for On-Chain AI Agent Badges:
|
|
5
|
+
* - Soulbound Non-Transferable verifiable credentials.
|
|
6
|
+
* - Proof-of-Task and Nirium Attestation Binding.
|
|
7
|
+
* - Dynamic Reputation Scoring (0-100) & Automatic Revocation Engine.
|
|
8
|
+
* - Native metadata export for XOXNO & Stellar NFT Marketplaces.
|
|
9
|
+
*/
|
|
10
|
+
import { AgentBadgeMetadata, IssueBadgeRequest, BadgeVerificationResult, XoxnoListingMetadata } from "../types.js";
|
|
11
|
+
export declare class AgentBadgeIssuer {
|
|
12
|
+
private badgesByAgent;
|
|
13
|
+
private badgesById;
|
|
14
|
+
/**
|
|
15
|
+
* Issues a SEP-50 compliant verification badge to an autonomous AI agent.
|
|
16
|
+
*/
|
|
17
|
+
issueBadge(request: IssueBadgeRequest, issuerPublicKey: string): AgentBadgeMetadata;
|
|
18
|
+
/**
|
|
19
|
+
* Verifies the authenticity, validity, and active status of an agent's badge.
|
|
20
|
+
*/
|
|
21
|
+
verifyBadge(agentPublicKey: string): BadgeVerificationResult;
|
|
22
|
+
/**
|
|
23
|
+
* Revokes an agent's badge immediately (e.g. on circuit-breaker trip or malicious behavior).
|
|
24
|
+
*/
|
|
25
|
+
revokeBadge(agentPublicKey: string, reason: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Formats the badge into canonical SEP-50 on-chain JSON schema for Stellar wallets.
|
|
28
|
+
*/
|
|
29
|
+
formatSep50Metadata(badge: AgentBadgeMetadata): Record<string, unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* Exports official listing payload for Mihai Eremia's XOXNO NFT & Agent Marketplace.
|
|
32
|
+
*/
|
|
33
|
+
exportXoxnoListing(badge: AgentBadgeMetadata, treasuryAddress: string): XoxnoListingMetadata;
|
|
34
|
+
private computeTier;
|
|
35
|
+
private computeReputationScore;
|
|
36
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AgentRail - SEP-50 Compliant Autonomous Agent Verification Badge Issuer
|
|
4
|
+
*
|
|
5
|
+
* Implements Stellar Ecosystem Proposal 50 (SEP-50) for On-Chain AI Agent Badges:
|
|
6
|
+
* - Soulbound Non-Transferable verifiable credentials.
|
|
7
|
+
* - Proof-of-Task and Nirium Attestation Binding.
|
|
8
|
+
* - Dynamic Reputation Scoring (0-100) & Automatic Revocation Engine.
|
|
9
|
+
* - Native metadata export for XOXNO & Stellar NFT Marketplaces.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AgentBadgeIssuer = void 0;
|
|
13
|
+
const crypto_1 = require("crypto");
|
|
14
|
+
class AgentBadgeIssuer {
|
|
15
|
+
badgesByAgent = new Map();
|
|
16
|
+
badgesById = new Map();
|
|
17
|
+
/**
|
|
18
|
+
* Issues a SEP-50 compliant verification badge to an autonomous AI agent.
|
|
19
|
+
*/
|
|
20
|
+
issueBadge(request, issuerPublicKey) {
|
|
21
|
+
if (!request.agentPublicKey || !request.agentPublicKey.startsWith("G")) {
|
|
22
|
+
throw new Error(`Invalid agent public key format: ${request.agentPublicKey}`);
|
|
23
|
+
}
|
|
24
|
+
const tier = this.computeTier(request.auditScore, request.completedTasksCount);
|
|
25
|
+
const reputationScore = this.computeReputationScore(request.auditScore, request.completedTasksCount);
|
|
26
|
+
const now = Math.floor(Date.now() / 1000);
|
|
27
|
+
const validitySeconds = (request.validityDays ?? 365) * 86400;
|
|
28
|
+
const expiresAt = now + validitySeconds;
|
|
29
|
+
// Deterministic Badge ID based on Agent Address, Type, and Issuer
|
|
30
|
+
const badgeRaw = `${request.agentPublicKey}:${request.badgeType}:${issuerPublicKey}:${now}`;
|
|
31
|
+
const badgeHash = (0, crypto_1.createHash)("sha256").update(badgeRaw).digest("hex").slice(0, 16);
|
|
32
|
+
const badgeId = `sep50-agt-${badgeHash}`;
|
|
33
|
+
const badge = {
|
|
34
|
+
badgeId,
|
|
35
|
+
agentPublicKey: request.agentPublicKey,
|
|
36
|
+
agentName: request.agentName,
|
|
37
|
+
badgeType: request.badgeType,
|
|
38
|
+
tier,
|
|
39
|
+
reputationScore,
|
|
40
|
+
issuedAt: now,
|
|
41
|
+
expiresAt,
|
|
42
|
+
taskCommitmentHash: request.latestTaskCommitmentHash,
|
|
43
|
+
ipfsAuditCid: request.ipfsAuditCid,
|
|
44
|
+
revoked: false,
|
|
45
|
+
issuerPublicKey,
|
|
46
|
+
sep50Standard: "SEP-0050-v1",
|
|
47
|
+
};
|
|
48
|
+
this.badgesByAgent.set(request.agentPublicKey, badge);
|
|
49
|
+
this.badgesById.set(badgeId, badge);
|
|
50
|
+
return badge;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Verifies the authenticity, validity, and active status of an agent's badge.
|
|
54
|
+
*/
|
|
55
|
+
verifyBadge(agentPublicKey) {
|
|
56
|
+
const badge = this.badgesByAgent.get(agentPublicKey);
|
|
57
|
+
if (!badge) {
|
|
58
|
+
return {
|
|
59
|
+
valid: false,
|
|
60
|
+
code: "BADGE_NOT_FOUND",
|
|
61
|
+
message: `No SEP-50 verification badge found for agent address ${agentPublicKey}.`,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (badge.revoked) {
|
|
65
|
+
return {
|
|
66
|
+
valid: false,
|
|
67
|
+
code: "BADGE_REVOKED",
|
|
68
|
+
message: `Badge ${badge.badgeId} has been revoked! Reason: ${badge.revocationReason || "Security rule violation"}`,
|
|
69
|
+
badge,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const now = Math.floor(Date.now() / 1000);
|
|
73
|
+
if (now > badge.expiresAt) {
|
|
74
|
+
return {
|
|
75
|
+
valid: false,
|
|
76
|
+
code: "BADGE_EXPIRED",
|
|
77
|
+
message: `Badge ${badge.badgeId} expired at timestamp ${badge.expiresAt}.`,
|
|
78
|
+
badge,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
valid: true,
|
|
83
|
+
code: "BADGE_VERIFIED_ACTIVE",
|
|
84
|
+
message: `Agent holds valid ${badge.tier.toUpperCase()} SEP-50 badge (${badge.badgeType}) with reputation score ${badge.reputationScore}/100.`,
|
|
85
|
+
badge,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Revokes an agent's badge immediately (e.g. on circuit-breaker trip or malicious behavior).
|
|
90
|
+
*/
|
|
91
|
+
revokeBadge(agentPublicKey, reason) {
|
|
92
|
+
const badge = this.badgesByAgent.get(agentPublicKey);
|
|
93
|
+
if (!badge)
|
|
94
|
+
return false;
|
|
95
|
+
badge.revoked = true;
|
|
96
|
+
badge.revocationReason = reason;
|
|
97
|
+
this.badgesByAgent.set(agentPublicKey, badge);
|
|
98
|
+
this.badgesById.set(badge.badgeId, badge);
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Formats the badge into canonical SEP-50 on-chain JSON schema for Stellar wallets.
|
|
103
|
+
*/
|
|
104
|
+
formatSep50Metadata(badge) {
|
|
105
|
+
return {
|
|
106
|
+
sep: 50,
|
|
107
|
+
version: "1.0.0",
|
|
108
|
+
standard: "Stellar Agentic Non-Transferable Attestation (Soulbound)",
|
|
109
|
+
id: badge.badgeId,
|
|
110
|
+
issuer: badge.issuerPublicKey,
|
|
111
|
+
subject: badge.agentPublicKey,
|
|
112
|
+
name: `AgentRail Verified Agent: ${badge.agentName}`,
|
|
113
|
+
description: `Cryptographically verified autonomous agent on Stellar Soroban. Tier: ${badge.tier}, Score: ${badge.reputationScore}.`,
|
|
114
|
+
type: badge.badgeType,
|
|
115
|
+
tier: badge.tier,
|
|
116
|
+
reputation_score: badge.reputationScore,
|
|
117
|
+
issued_at: badge.issuedAt,
|
|
118
|
+
expires_at: badge.expiresAt,
|
|
119
|
+
is_transferable: false,
|
|
120
|
+
attestation: {
|
|
121
|
+
task_commitment_hash: badge.taskCommitmentHash || null,
|
|
122
|
+
ipfs_audit_cid: badge.ipfsAuditCid || null,
|
|
123
|
+
audited_by: "AgentRail Autonomous Protocol v0.1.0",
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Exports official listing payload for Mihai Eremia's XOXNO NFT & Agent Marketplace.
|
|
129
|
+
*/
|
|
130
|
+
exportXoxnoListing(badge, treasuryAddress) {
|
|
131
|
+
return {
|
|
132
|
+
id: badge.badgeId,
|
|
133
|
+
name: `${badge.agentName} [AgentRail Verified - ${badge.tier.toUpperCase()}]`,
|
|
134
|
+
description: `Official Verified Autonomous Agent badge issued under SEP-50 by AgentRail. Non-transferable Soulbound credential representing verified uptime, proof-of-task, and zero-drain security score of ${badge.reputationScore}/100.`,
|
|
135
|
+
image: `https://agentrail.org/badges/${badge.tier}.png`,
|
|
136
|
+
external_url: `https://agentrail.org/agents/${badge.agentPublicKey}`,
|
|
137
|
+
attributes: [
|
|
138
|
+
{ trait_type: "Badge Standard", value: "SEP-50" },
|
|
139
|
+
{ trait_type: "Badge Type", value: badge.badgeType },
|
|
140
|
+
{ trait_type: "Tier", value: badge.tier.toUpperCase() },
|
|
141
|
+
{ trait_type: "Reputation Score", value: badge.reputationScore },
|
|
142
|
+
{ trait_type: "Transferable", value: "Soulbound (No)" },
|
|
143
|
+
{ trait_type: "IPFS Audit CID", value: badge.ipfsAuditCid || "verified-onchain" },
|
|
144
|
+
{ trait_type: "Protocol Fee BPS", value: 20 },
|
|
145
|
+
],
|
|
146
|
+
seller_fee_basis_points: 20, // 20 BPS protocol revenue
|
|
147
|
+
fee_recipient: treasuryAddress,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
computeTier(auditScore, tasksCount) {
|
|
151
|
+
if (auditScore >= 95 && tasksCount >= 100)
|
|
152
|
+
return "diamond";
|
|
153
|
+
if (auditScore >= 85 && tasksCount >= 50)
|
|
154
|
+
return "gold";
|
|
155
|
+
if (auditScore >= 70 && tasksCount >= 10)
|
|
156
|
+
return "silver";
|
|
157
|
+
return "bronze";
|
|
158
|
+
}
|
|
159
|
+
computeReputationScore(auditScore, tasksCount) {
|
|
160
|
+
// 60% weight on audit score, 40% weight on task execution volume (max 100 tasks)
|
|
161
|
+
const taskFactor = Math.min(tasksCount, 100);
|
|
162
|
+
const score = Math.round((auditScore * 0.6) + (taskFactor * 0.4));
|
|
163
|
+
return Math.max(0, Math.min(100, score));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.AgentBadgeIssuer = AgentBadgeIssuer;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentRail - Decentralized Agent Registry & Service Discovery
|
|
3
|
+
*
|
|
4
|
+
* Provides an on-chain/cryptographic registry protocol where autonomous AI agents
|
|
5
|
+
* publish service capabilities, endpoint schemas, pricing (USDC stroops), and public keys,
|
|
6
|
+
* enabling dynamic multi-agent peer discovery and negotiation on Stellar Soroban.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
export declare const AgentServiceSchema: z.ZodObject<{
|
|
10
|
+
serviceId: z.ZodString;
|
|
11
|
+
name: z.ZodString;
|
|
12
|
+
description: z.ZodString;
|
|
13
|
+
tags: z.ZodArray<z.ZodString, "many">;
|
|
14
|
+
endpointUrl: z.ZodString;
|
|
15
|
+
costStroops: z.ZodBigInt;
|
|
16
|
+
settlementAsset: z.ZodDefault<z.ZodString>;
|
|
17
|
+
slaLatencyMs: z.ZodDefault<z.ZodNumber>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
serviceId: string;
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
tags: string[];
|
|
23
|
+
endpointUrl: string;
|
|
24
|
+
costStroops: bigint;
|
|
25
|
+
settlementAsset: string;
|
|
26
|
+
slaLatencyMs: number;
|
|
27
|
+
}, {
|
|
28
|
+
serviceId: string;
|
|
29
|
+
name: string;
|
|
30
|
+
description: string;
|
|
31
|
+
tags: string[];
|
|
32
|
+
endpointUrl: string;
|
|
33
|
+
costStroops: bigint;
|
|
34
|
+
settlementAsset?: string | undefined;
|
|
35
|
+
slaLatencyMs?: number | undefined;
|
|
36
|
+
}>;
|
|
37
|
+
export declare const AgentRegistrationRecordSchema: z.ZodObject<{
|
|
38
|
+
agentPublicKey: z.ZodString;
|
|
39
|
+
service: z.ZodObject<{
|
|
40
|
+
serviceId: z.ZodString;
|
|
41
|
+
name: z.ZodString;
|
|
42
|
+
description: z.ZodString;
|
|
43
|
+
tags: z.ZodArray<z.ZodString, "many">;
|
|
44
|
+
endpointUrl: z.ZodString;
|
|
45
|
+
costStroops: z.ZodBigInt;
|
|
46
|
+
settlementAsset: z.ZodDefault<z.ZodString>;
|
|
47
|
+
slaLatencyMs: z.ZodDefault<z.ZodNumber>;
|
|
48
|
+
}, "strip", z.ZodTypeAny, {
|
|
49
|
+
serviceId: string;
|
|
50
|
+
name: string;
|
|
51
|
+
description: string;
|
|
52
|
+
tags: string[];
|
|
53
|
+
endpointUrl: string;
|
|
54
|
+
costStroops: bigint;
|
|
55
|
+
settlementAsset: string;
|
|
56
|
+
slaLatencyMs: number;
|
|
57
|
+
}, {
|
|
58
|
+
serviceId: string;
|
|
59
|
+
name: string;
|
|
60
|
+
description: string;
|
|
61
|
+
tags: string[];
|
|
62
|
+
endpointUrl: string;
|
|
63
|
+
costStroops: bigint;
|
|
64
|
+
settlementAsset?: string | undefined;
|
|
65
|
+
slaLatencyMs?: number | undefined;
|
|
66
|
+
}>;
|
|
67
|
+
registeredAt: z.ZodNumber;
|
|
68
|
+
ttlEpochSeconds: z.ZodNumber;
|
|
69
|
+
reputationScore: z.ZodDefault<z.ZodNumber>;
|
|
70
|
+
active: z.ZodDefault<z.ZodBoolean>;
|
|
71
|
+
registrationHash: z.ZodString;
|
|
72
|
+
}, "strip", z.ZodTypeAny, {
|
|
73
|
+
agentPublicKey: string;
|
|
74
|
+
service: {
|
|
75
|
+
serviceId: string;
|
|
76
|
+
name: string;
|
|
77
|
+
description: string;
|
|
78
|
+
tags: string[];
|
|
79
|
+
endpointUrl: string;
|
|
80
|
+
costStroops: bigint;
|
|
81
|
+
settlementAsset: string;
|
|
82
|
+
slaLatencyMs: number;
|
|
83
|
+
};
|
|
84
|
+
registeredAt: number;
|
|
85
|
+
ttlEpochSeconds: number;
|
|
86
|
+
reputationScore: number;
|
|
87
|
+
active: boolean;
|
|
88
|
+
registrationHash: string;
|
|
89
|
+
}, {
|
|
90
|
+
agentPublicKey: string;
|
|
91
|
+
service: {
|
|
92
|
+
serviceId: string;
|
|
93
|
+
name: string;
|
|
94
|
+
description: string;
|
|
95
|
+
tags: string[];
|
|
96
|
+
endpointUrl: string;
|
|
97
|
+
costStroops: bigint;
|
|
98
|
+
settlementAsset?: string | undefined;
|
|
99
|
+
slaLatencyMs?: number | undefined;
|
|
100
|
+
};
|
|
101
|
+
registeredAt: number;
|
|
102
|
+
ttlEpochSeconds: number;
|
|
103
|
+
registrationHash: string;
|
|
104
|
+
reputationScore?: number | undefined;
|
|
105
|
+
active?: boolean | undefined;
|
|
106
|
+
}>;
|
|
107
|
+
export type AgentService = z.infer<typeof AgentServiceSchema>;
|
|
108
|
+
export type AgentRegistrationRecord = z.infer<typeof AgentRegistrationRecordSchema>;
|
|
109
|
+
export declare class AgentRegistry {
|
|
110
|
+
private records;
|
|
111
|
+
/**
|
|
112
|
+
* Register a new agent service on the registry.
|
|
113
|
+
*/
|
|
114
|
+
registerService(agentPublicKey: string, service: AgentService, ttlSeconds?: number): AgentRegistrationRecord;
|
|
115
|
+
/**
|
|
116
|
+
* Discover agents by tags or keywords with budget filtering.
|
|
117
|
+
*/
|
|
118
|
+
discover(query: {
|
|
119
|
+
tag?: string;
|
|
120
|
+
keyword?: string;
|
|
121
|
+
maxCostStroops?: bigint;
|
|
122
|
+
activeOnly?: boolean;
|
|
123
|
+
}): AgentRegistrationRecord[];
|
|
124
|
+
/**
|
|
125
|
+
* Lookup a specific service by agent key and serviceId.
|
|
126
|
+
*/
|
|
127
|
+
getService(agentPublicKey: string, serviceId: string): AgentRegistrationRecord | null;
|
|
128
|
+
/**
|
|
129
|
+
* Deactivate an agent service.
|
|
130
|
+
*/
|
|
131
|
+
deactivateService(agentPublicKey: string, serviceId: string): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Export all active registry state for on-chain anchoring / IPFS synchronization.
|
|
134
|
+
*/
|
|
135
|
+
exportCanonicalState(): string;
|
|
136
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AgentRail - Decentralized Agent Registry & Service Discovery
|
|
4
|
+
*
|
|
5
|
+
* Provides an on-chain/cryptographic registry protocol where autonomous AI agents
|
|
6
|
+
* publish service capabilities, endpoint schemas, pricing (USDC stroops), and public keys,
|
|
7
|
+
* enabling dynamic multi-agent peer discovery and negotiation on Stellar Soroban.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.AgentRegistry = exports.AgentRegistrationRecordSchema = exports.AgentServiceSchema = void 0;
|
|
11
|
+
const node_crypto_1 = require("node:crypto");
|
|
12
|
+
const zod_1 = require("zod");
|
|
13
|
+
exports.AgentServiceSchema = zod_1.z.object({
|
|
14
|
+
serviceId: zod_1.z.string().min(3),
|
|
15
|
+
name: zod_1.z.string().min(2),
|
|
16
|
+
description: zod_1.z.string(),
|
|
17
|
+
tags: zod_1.z.array(zod_1.z.string()),
|
|
18
|
+
endpointUrl: zod_1.z.string().url(),
|
|
19
|
+
costStroops: zod_1.z.bigint(),
|
|
20
|
+
settlementAsset: zod_1.z.string().default("USDC"),
|
|
21
|
+
slaLatencyMs: zod_1.z.number().int().positive().default(2000),
|
|
22
|
+
});
|
|
23
|
+
exports.AgentRegistrationRecordSchema = zod_1.z.object({
|
|
24
|
+
agentPublicKey: zod_1.z.string().regex(/^G[A-Z2-7]{55}$/),
|
|
25
|
+
service: exports.AgentServiceSchema,
|
|
26
|
+
registeredAt: zod_1.z.number().int(),
|
|
27
|
+
ttlEpochSeconds: zod_1.z.number().int(),
|
|
28
|
+
reputationScore: zod_1.z.number().min(0).max(100).default(100),
|
|
29
|
+
active: zod_1.z.boolean().default(true),
|
|
30
|
+
registrationHash: zod_1.z.string(),
|
|
31
|
+
});
|
|
32
|
+
class AgentRegistry {
|
|
33
|
+
records = new Map();
|
|
34
|
+
/**
|
|
35
|
+
* Register a new agent service on the registry.
|
|
36
|
+
*/
|
|
37
|
+
registerService(agentPublicKey, service, ttlSeconds = 86400 * 30 // 30 days default
|
|
38
|
+
) {
|
|
39
|
+
const parsedService = exports.AgentServiceSchema.parse(service);
|
|
40
|
+
const now = Math.floor(Date.now() / 1000);
|
|
41
|
+
const rawPayload = `${agentPublicKey}:${parsedService.serviceId}:${parsedService.costStroops.toString()}:${now}`;
|
|
42
|
+
const registrationHash = (0, node_crypto_1.createHash)("sha256").update(rawPayload).digest("hex");
|
|
43
|
+
const record = {
|
|
44
|
+
agentPublicKey,
|
|
45
|
+
service: parsedService,
|
|
46
|
+
registeredAt: now,
|
|
47
|
+
ttlEpochSeconds: now + ttlSeconds,
|
|
48
|
+
reputationScore: 100,
|
|
49
|
+
active: true,
|
|
50
|
+
registrationHash,
|
|
51
|
+
};
|
|
52
|
+
exports.AgentRegistrationRecordSchema.parse(record);
|
|
53
|
+
const key = `${agentPublicKey}:${parsedService.serviceId}`;
|
|
54
|
+
this.records.set(key, record);
|
|
55
|
+
return record;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Discover agents by tags or keywords with budget filtering.
|
|
59
|
+
*/
|
|
60
|
+
discover(query) {
|
|
61
|
+
const now = Math.floor(Date.now() / 1000);
|
|
62
|
+
const results = [];
|
|
63
|
+
for (const record of this.records.values()) {
|
|
64
|
+
if (query.activeOnly !== false && (!record.active || record.ttlEpochSeconds <= now)) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (query.tag && !record.service.tags.some(t => t.toLowerCase() === query.tag?.toLowerCase())) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (query.keyword) {
|
|
71
|
+
const kw = query.keyword.toLowerCase();
|
|
72
|
+
const matchName = record.service.name.toLowerCase().includes(kw);
|
|
73
|
+
const matchDesc = record.service.description.toLowerCase().includes(kw);
|
|
74
|
+
if (!matchName && !matchDesc)
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (query.maxCostStroops !== undefined && record.service.costStroops > query.maxCostStroops) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
results.push(record);
|
|
81
|
+
}
|
|
82
|
+
// Sort by reputation score descending, then cost ascending
|
|
83
|
+
return results.sort((a, b) => {
|
|
84
|
+
if (b.reputationScore !== a.reputationScore) {
|
|
85
|
+
return b.reputationScore - a.reputationScore;
|
|
86
|
+
}
|
|
87
|
+
return a.service.costStroops < b.service.costStroops ? -1 : 1;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Lookup a specific service by agent key and serviceId.
|
|
92
|
+
*/
|
|
93
|
+
getService(agentPublicKey, serviceId) {
|
|
94
|
+
const key = `${agentPublicKey}:${serviceId}`;
|
|
95
|
+
return this.records.get(key) || null;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Deactivate an agent service.
|
|
99
|
+
*/
|
|
100
|
+
deactivateService(agentPublicKey, serviceId) {
|
|
101
|
+
const key = `${agentPublicKey}:${serviceId}`;
|
|
102
|
+
const rec = this.records.get(key);
|
|
103
|
+
if (!rec)
|
|
104
|
+
return false;
|
|
105
|
+
rec.active = false;
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Export all active registry state for on-chain anchoring / IPFS synchronization.
|
|
110
|
+
*/
|
|
111
|
+
exportCanonicalState() {
|
|
112
|
+
const sorted = Array.from(this.records.values())
|
|
113
|
+
.filter(r => r.active)
|
|
114
|
+
.sort((a, b) => a.registrationHash.localeCompare(b.registrationHash))
|
|
115
|
+
.map(r => ({
|
|
116
|
+
agent: r.agentPublicKey,
|
|
117
|
+
serviceId: r.service.serviceId,
|
|
118
|
+
costStroops: r.service.costStroops.toString(),
|
|
119
|
+
hash: r.registrationHash,
|
|
120
|
+
}));
|
|
121
|
+
return JSON.stringify(sorted);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.AgentRegistry = AgentRegistry;
|