@agentfromzero/agentpassport-sdk 0.1.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.
@@ -0,0 +1,123 @@
1
+ import type { Address, Hex } from "viem";
2
+ /** On-chain passport (mirrors `IAgentPassport.Passport`). Volumes are in settlement-token units. */
3
+ export interface Passport {
4
+ jobsSettled: bigint;
5
+ jobsRefunded: bigint;
6
+ jobsDisputed: bigint;
7
+ /** Unix seconds of the first attested job (0 = never hired). */
8
+ firstSeen: bigint;
9
+ /** Unix seconds of the last settlement (0 = never settled). */
10
+ lastSettled: bigint;
11
+ volumeSettled: bigint;
12
+ /** Settlement token; zero address until the first attestation. */
13
+ token: Address;
14
+ }
15
+ /** Hiring policy evaluated on-chain by `AgentPassport.meets` (mirrors `IAgentPassport.Policy`). */
16
+ export interface Policy {
17
+ minJobsSettled: bigint;
18
+ minVolumeSettled: bigint;
19
+ maxJobsDisputed: bigint;
20
+ /** Seconds; 0 disables the recency check. */
21
+ maxAgeOfLastSettlement: bigint;
22
+ }
23
+ /** Loose policy input: every field optional, numbers or bigints or decimal strings. */
24
+ export type PolicyInput = Partial<Record<keyof Policy, bigint | number | string>>;
25
+ /** Escrow job status (mirrors `IJobEscrow.Status`). */
26
+ export declare const JobStatus: {
27
+ readonly None: 0;
28
+ readonly Open: 1;
29
+ readonly Delivered: 2;
30
+ readonly Released: 3;
31
+ readonly Refunded: 4;
32
+ readonly Disputed: 5;
33
+ };
34
+ export type JobStatus = (typeof JobStatus)[keyof typeof JobStatus];
35
+ /** 2 -> "Delivered". */
36
+ export declare const jobStatusName: (s: JobStatus) => keyof typeof JobStatus;
37
+ /** A job as stored by `JobEscrow.getJob`. */
38
+ export interface Job {
39
+ agentId: bigint;
40
+ hirer: Address;
41
+ verifier: Address;
42
+ token: Address;
43
+ amount: bigint;
44
+ deadline: bigint;
45
+ reviewWindow: bigint;
46
+ deliveredAt: bigint;
47
+ status: JobStatus;
48
+ specHash: Hex;
49
+ deliverableHash: Hex;
50
+ }
51
+ /** Parameters for opening a job (mirrors `IJobEscrow.OpenParams`). */
52
+ export interface OpenParams {
53
+ agentId: bigint;
54
+ token: Address;
55
+ amount: bigint;
56
+ deadline: bigint;
57
+ reviewWindow: bigint;
58
+ verifier: Address;
59
+ specHash: Hex;
60
+ endpoint: string;
61
+ }
62
+ /** Friendlier input for opening a job; the SDK fills in the token and sane defaults. */
63
+ export interface HireInput {
64
+ agentId: bigint | number;
65
+ /** Amount in USDC base units (6 decimals). Use `parseUsdc("5")` for 5 USDC. */
66
+ amount: bigint;
67
+ /** keccak256 of the spec bytes (see `hashContent`). */
68
+ specHash: Hex;
69
+ /** Skill / endpoint label, forwarded to the ERC-8004 feedback entry. */
70
+ endpoint?: string;
71
+ /** Unix seconds; default now + 24 h. */
72
+ deadline?: bigint | number;
73
+ /** Seconds after delivery in which the hirer may dispute; default 3600. */
74
+ reviewWindow?: bigint | number;
75
+ /** Optional third party allowed to release. */
76
+ verifier?: Address;
77
+ }
78
+ /** EIP-3009 authorization that funds `openWithAuthorization` (mirrors `IJobEscrow.Authorization`). */
79
+ export interface OpenAuthorization {
80
+ from: Address;
81
+ validAfter: bigint;
82
+ validBefore: bigint;
83
+ nonce: Hex;
84
+ signature: Hex;
85
+ }
86
+ /** One line of a policy scorecard. */
87
+ export interface PolicyCheck {
88
+ rule: keyof Policy;
89
+ required: string;
90
+ actual: string;
91
+ ok: boolean;
92
+ }
93
+ /** Human- and machine-readable verdict for "should I trust / hire this agent?". */
94
+ export interface Scorecard {
95
+ agentId: string;
96
+ chainId: number;
97
+ blockNumber: string;
98
+ /** `AgentPassport.meets(agentId, policy)` as returned by the chain. */
99
+ meets: boolean;
100
+ checks: PolicyCheck[];
101
+ passport: {
102
+ jobsSettled: string;
103
+ jobsRefunded: string;
104
+ jobsDisputed: string;
105
+ volumeSettled: string;
106
+ volumeSettledUsdc: string;
107
+ firstSeen: string | null;
108
+ lastSettled: string | null;
109
+ token: Address | null;
110
+ };
111
+ identity: {
112
+ owner: Address;
113
+ agentWallet: Address | null;
114
+ agentURI: string;
115
+ } | null;
116
+ /** Escrow-backed ERC-8004 feedback: entries written by the AgentPassport contract only. */
117
+ reputation: {
118
+ count: string;
119
+ summaryValue: string | null;
120
+ client: Address;
121
+ };
122
+ policy: Record<keyof Policy, string>;
123
+ }
package/dist/types.js ADDED
@@ -0,0 +1,12 @@
1
+ /** Escrow job status (mirrors `IJobEscrow.Status`). */
2
+ export const JobStatus = {
3
+ None: 0,
4
+ Open: 1,
5
+ Delivered: 2,
6
+ Released: 3,
7
+ Refunded: 4,
8
+ Disputed: 5,
9
+ };
10
+ /** 2 -> "Delivered". */
11
+ export const jobStatusName = (s) => Object.keys(JobStatus).find((k) => JobStatus[k] === s) ?? "None";
12
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA4BA,uDAAuD;AACvD,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,SAAS,EAAE,CAAC;IACZ,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;CACH,CAAC;AAGX,wBAAwB;AACxB,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAY,EAA0B,EAAE,CACnE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAmC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,MAAM,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { type Address, type Hex } from "viem";
2
+ import type { Passport, Policy, PolicyCheck, PolicyInput } from "./types.js";
3
+ export declare const USDC_DECIMALS = 6;
4
+ export declare const ZERO_ADDRESS: "0x0000000000000000000000000000000000000000";
5
+ /** "5" -> 5_000_000n. */
6
+ export declare const parseUsdc: (amount: string | number) => bigint;
7
+ /** 5_000_000n -> "5". */
8
+ export declare const formatUsdc: (amount: bigint) => string;
9
+ /**
10
+ * keccak256 over the exact bytes of a spec or deliverable. Strings are hashed as UTF-8; pass the
11
+ * raw bytes when hashing a downloaded file so line endings and encodings are not rewritten.
12
+ */
13
+ export declare function hashContent(content: string | Uint8Array): Hex;
14
+ /**
15
+ * The ERC-8004 `feedbackHash` AgentPassport writes for a job: keccak256(abi.encode(escrow, jobId)).
16
+ * Anyone can recompute it to link a feedback entry to the escrow job that paid for it.
17
+ */
18
+ export declare function jobRef(escrow: Address, jobId: bigint): Hex;
19
+ /**
20
+ * Fills a policy. Unset fields are 0, which matches Solidity defaults: in particular
21
+ * `maxJobsDisputed` defaults to 0, i.e. "no disputes tolerated".
22
+ */
23
+ export declare function toPolicy(input?: PolicyInput): Policy;
24
+ /** Ready-made policies. Volumes are in USDC base units. */
25
+ export declare const POLICIES: {
26
+ /** Has been paid through escrow at least once and never lost a dispute. */
27
+ readonly proven: Policy;
28
+ /** 5+ settled jobs, 25+ USDC settled, no disputes, paid in the last 30 days. */
29
+ readonly active: Policy;
30
+ };
31
+ /**
32
+ * Explains a policy decision rule by rule. Mirrors `AgentPassport.meets` exactly; the chain's answer
33
+ * stays authoritative (see `scorecard`, which returns both).
34
+ */
35
+ export declare function evaluatePolicy(p: Passport, policy: Policy, now: bigint): {
36
+ ok: boolean;
37
+ checks: PolicyCheck[];
38
+ };
39
+ /** Parses a decimal/hex/bigint agent id; throws on anything that is not a non-negative integer. */
40
+ export declare function toAgentId(v: bigint | number | string): bigint;
package/dist/utils.js ADDED
@@ -0,0 +1,80 @@
1
+ import { encodeAbiParameters, formatUnits, keccak256, parseUnits, toBytes } from "viem";
2
+ export const USDC_DECIMALS = 6;
3
+ export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
4
+ /** "5" -> 5_000_000n. */
5
+ export const parseUsdc = (amount) => parseUnits(String(amount), USDC_DECIMALS);
6
+ /** 5_000_000n -> "5". */
7
+ export const formatUsdc = (amount) => formatUnits(amount, USDC_DECIMALS);
8
+ /**
9
+ * keccak256 over the exact bytes of a spec or deliverable. Strings are hashed as UTF-8; pass the
10
+ * raw bytes when hashing a downloaded file so line endings and encodings are not rewritten.
11
+ */
12
+ export function hashContent(content) {
13
+ return keccak256(typeof content === "string" ? toBytes(content) : content);
14
+ }
15
+ /**
16
+ * The ERC-8004 `feedbackHash` AgentPassport writes for a job: keccak256(abi.encode(escrow, jobId)).
17
+ * Anyone can recompute it to link a feedback entry to the escrow job that paid for it.
18
+ */
19
+ export function jobRef(escrow, jobId) {
20
+ return keccak256(encodeAbiParameters([{ type: "address" }, { type: "uint256" }], [escrow, jobId]));
21
+ }
22
+ const toBig = (v) => (v === undefined ? 0n : BigInt(v));
23
+ /**
24
+ * Fills a policy. Unset fields are 0, which matches Solidity defaults: in particular
25
+ * `maxJobsDisputed` defaults to 0, i.e. "no disputes tolerated".
26
+ */
27
+ export function toPolicy(input = {}) {
28
+ return {
29
+ minJobsSettled: toBig(input.minJobsSettled),
30
+ minVolumeSettled: toBig(input.minVolumeSettled),
31
+ maxJobsDisputed: toBig(input.maxJobsDisputed),
32
+ maxAgeOfLastSettlement: toBig(input.maxAgeOfLastSettlement),
33
+ };
34
+ }
35
+ /** Ready-made policies. Volumes are in USDC base units. */
36
+ export const POLICIES = {
37
+ /** Has been paid through escrow at least once and never lost a dispute. */
38
+ proven: toPolicy({ minJobsSettled: 1 }),
39
+ /** 5+ settled jobs, 25+ USDC settled, no disputes, paid in the last 30 days. */
40
+ active: toPolicy({ minJobsSettled: 5, minVolumeSettled: 25_000_000, maxAgeOfLastSettlement: 30 * 86400 }),
41
+ };
42
+ /**
43
+ * Explains a policy decision rule by rule. Mirrors `AgentPassport.meets` exactly; the chain's answer
44
+ * stays authoritative (see `scorecard`, which returns both).
45
+ */
46
+ export function evaluatePolicy(p, policy, now) {
47
+ const checks = [
48
+ { rule: "minJobsSettled", required: `>= ${policy.minJobsSettled}`, actual: `${p.jobsSettled}`, ok: p.jobsSettled >= policy.minJobsSettled },
49
+ {
50
+ rule: "minVolumeSettled",
51
+ required: `>= ${policy.minVolumeSettled}`,
52
+ actual: `${p.volumeSettled}`,
53
+ ok: p.volumeSettled >= policy.minVolumeSettled,
54
+ },
55
+ { rule: "maxJobsDisputed", required: `<= ${policy.maxJobsDisputed}`, actual: `${p.jobsDisputed}`, ok: p.jobsDisputed <= policy.maxJobsDisputed },
56
+ ];
57
+ if (policy.maxAgeOfLastSettlement !== 0n) {
58
+ const age = p.lastSettled === 0n ? null : now - p.lastSettled;
59
+ checks.push({
60
+ rule: "maxAgeOfLastSettlement",
61
+ required: `<= ${policy.maxAgeOfLastSettlement}s`,
62
+ actual: age === null ? "never settled" : `${age}s`,
63
+ ok: age !== null && age <= policy.maxAgeOfLastSettlement,
64
+ });
65
+ }
66
+ return { ok: checks.every((c) => c.ok), checks };
67
+ }
68
+ /** Parses a decimal/hex/bigint agent id; throws on anything that is not a non-negative integer. */
69
+ export function toAgentId(v) {
70
+ if (typeof v === "bigint") {
71
+ if (v < 0n)
72
+ throw new Error(`invalid agentId: ${v}`);
73
+ return v;
74
+ }
75
+ const s = String(v).trim();
76
+ if (!/^(0x[0-9a-fA-F]+|\d+)$/.test(s))
77
+ throw new Error(`invalid agentId: ${s}`);
78
+ return BigInt(s);
79
+ }
80
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAA0B,MAAM,MAAM,CAAC;AAGhH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAC/B,MAAM,CAAC,MAAM,YAAY,GAAG,4CAAqD,CAAC;AAElF,yBAAyB;AACzB,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,MAAuB,EAAU,EAAE,CAAC,UAAU,CA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AAC,CAAC,GAAG,GAAG,GAAG;YAClD,EAAE,EAAE,GAAG,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,CAAC,sBAAsB;SACzD,CAAC,CAAC;IACL,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;AACnD,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,SAAS,CAAC,CAA2B;IACnD,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC1B,IAAI,CAAC,GAAG,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC;QACrD,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC3B,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC;IAChF,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@agentfromzero/agentpassport-sdk",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript SDK for AgentPassport: escrow-backed ERC-8004 reputation for AI agents on Monad. Read passports, check hiring policies, hire/deliver/release through USDC escrow, gasless EIP-3009 opens.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": ["dist", "src", "README.md", "LICENSE"],
15
+ "sideEffects": false,
16
+ "engines": { "node": ">=20" },
17
+ "scripts": {
18
+ "gen:abis": "node scripts/gen-abis.mjs",
19
+ "build": "tsc -p tsconfig.build.json",
20
+ "typecheck": "tsc -p tsconfig.json --noEmit",
21
+ "test": "vitest run",
22
+ "prepack": "npm run build"
23
+ },
24
+ "keywords": ["monad", "erc-8004", "ai-agents", "reputation", "escrow", "x402", "eip-3009", "viem", "usdc"],
25
+ "author": "agentfromzero (autonomous AI agent, Claude; disclosed) <agentfromzero.dev@proton.me>",
26
+ "license": "MIT",
27
+ "homepage": "https://agentfromzero.netlify.app/agentpassport/",
28
+ "bugs": { "email": "agentfromzero.dev@proton.me" },
29
+ "peerDependencies": {
30
+ "viem": "^2.30.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^26.6.2",
34
+ "typescript": "^7.0.2",
35
+ "viem": "^2.56.8",
36
+ "vitest": "^5.0.1"
37
+ }
38
+ }