inamprotocol 0.15.0 → 0.16.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 CHANGED
@@ -70,6 +70,22 @@ await verifierClient.getVerification(verification.verificationId);
70
70
  await verifierClient.listReceiptVerifications(receipt.receiptId);
71
71
  ```
72
72
 
73
+ ### Deciding whether to deal with an agent
74
+
75
+ `checkTrust` turns an agent's reputation into `allow`, `escrow` (deal, but hold payment until delivery is confirmed), or `deny`, with the reasons. It runs on your side: the registry's numbers are a hint (SPEC.md §5.4), and the thresholds are yours.
76
+
77
+ ```ts
78
+ import { checkTrust } from "inamprotocol";
79
+
80
+ const d = await checkTrust(did, client, {
81
+ allow: { minEvidence: "independently_verified", minTrustScore: 5 }, // default: independently_verified, any score
82
+ escrow: { minEvidence: "none" }, // below this: deny
83
+ });
84
+ // { decision: "escrow", reasons: ["evidence countersigned is below independently_verified"], ... }
85
+ ```
86
+
87
+ A revoked ID or one the registry doesn't know is `deny`. Warning flags (`in_dispute`, `attestation_rejected`, `nonperformance_reported`, `concentrated_counterparty`) cap the decision at `escrow`; pass `escrowFlags` to change that list. Use it to fill a wallet's merchant allow list, or to choose between paying upfront and paying on delivery.
88
+
73
89
  ## What's exported
74
90
 
75
91
  `InamClient`, `generateKeypair`/`keypairFromPrivateKey`/`publicKeyToDid`/`didToPublicKey`/`sign`/`verify`/`verifyRawEd25519`/`sha256Hex`, `generateP256Keypair`/`p256Sign`/`p256Verify` (used for external-identity link-challenge proofs, SPEC.md §2.1), `canonicalize` (the canonical-JSON serializer every INAM signature is computed over), `computeReceiptId`/`buildSignableContent`, `computeVerificationId`/`buildSignableVerificationContent`, and the full set of wire-format types (`AgentRecord`, `ExecutionReceipt`, `JobRecord`, `JobOffer`, `ReputationResult`, `LinkChallenge`, `VerificationRecord`, ...).
package/dist/index.d.ts CHANGED
@@ -15,3 +15,5 @@ export { INAM_X402_EXTENSION, inamX402Extension, decideX402, withInamX402Gate, X
15
15
  export type { X402Policy, X402Decision } from "./x402.js";
16
16
  export { INAM_A2A_EXTENSION_URI, inamA2AExtension, decideA2A, verifyA2ACard, cardEndpoints } from "./a2a.js";
17
17
  export type { A2APolicy, A2ADecision, A2AAgentCardLike } from "./a2a.js";
18
+ export { decideTrust, checkTrust, DEFAULT_ESCROW_FLAGS } from "./trust.js";
19
+ export type { TrustPolicy, TrustDecision, TrustDecisionKind } from "./trust.js";
package/dist/index.js CHANGED
@@ -22,4 +22,5 @@ export { payloadHash } from "./core/transparencyLog.js";
22
22
  export { registerAgentSchema, linkChallengeSchema, linkSchema, postJobSchema, offerSchema, acceptOfferSchema, draftReceiptSchema, countersignSchema, disputeSchema, submitVerificationSchema, setVerifierStatusSchema, } from "./core/schemas.js";
23
23
  export { INAM_X402_EXTENSION, inamX402Extension, decideX402, withInamX402Gate, X402PaymentBlocked } from "./x402.js";
24
24
  export { INAM_A2A_EXTENSION_URI, inamA2AExtension, decideA2A, verifyA2ACard, cardEndpoints } from "./a2a.js";
25
+ export { decideTrust, checkTrust, DEFAULT_ESCROW_FLAGS } from "./trust.js";
25
26
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,IAAI,EACJ,MAAM,EACN,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,UAAU,EACV,KAAK,EACL,OAAO,GAER,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,UAAU,EAAoB,MAAM,kBAAkB,CAAC;AAE/F,OAAO,EACL,wBAAwB,EACxB,aAAa,EACb,eAAe,EACf,mCAAmC,EACnC,qBAAqB,GAEtB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,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, ReputationResult } from "./types.js";
3
+ import { type X402Policy } from "./x402.js";
4
+ /** A decision-ready trust check: allow, escrow, or deny, with the reasons.
5
+ *
6
+ * Runs on the caller's side from the registry's appraisal, which is a hint
7
+ * (SPEC.md §5.4); the registry never decides for you. "escrow" means: deal,
8
+ * but don't release payment until delivery is confirmed. INAM holds no money,
9
+ * so the escrow itself is the caller's rail (x402, a wallet allow list, etc.). */
10
+ export type TrustDecisionKind = "allow" | "escrow" | "deny";
11
+ export interface TrustPolicy {
12
+ /** Bar for "allow". Default: independently verified evidence, any score. Countersigned-only history is the two parties' own word (THREAT-MODEL.md), so by default it gets escrow. */
13
+ allow?: X402Policy;
14
+ /** Bar for "escrow"; below it is "deny". Default: no evidence needed, so unknown agents get escrow. */
15
+ escrow?: X402Policy;
16
+ /** Reputation flags that cap the decision at "escrow" (prefix match, so `concentrated_counterparty` matches its `:did` suffix). */
17
+ escrowFlags?: string[];
18
+ }
19
+ export interface TrustDecision {
20
+ decision: TrustDecisionKind;
21
+ reasons: string[];
22
+ did: string;
23
+ reputation?: ReputationResult;
24
+ }
25
+ export declare const DEFAULT_ESCROW_FLAGS: string[];
26
+ /** Pure policy check, for callers that already fetched the agent and its reputation. */
27
+ export declare function decideTrust(agent: AgentRecord, reputation: ReputationResult, policy?: TrustPolicy): TrustDecision;
28
+ /** Fetches `did` from the registry `inam` points at and decides. An ID the registry doesn't know is "deny". */
29
+ export declare function checkTrust(did: string, inam: InamClient, policy?: TrustPolicy): Promise<TrustDecision>;
package/dist/trust.js ADDED
@@ -0,0 +1,34 @@
1
+ import { policyFailure } from "./x402.js";
2
+ export const DEFAULT_ESCROW_FLAGS = ["in_dispute", "attestation_rejected", "nonperformance_reported", "concentrated_counterparty"];
3
+ /** Pure policy check, for callers that already fetched the agent and its reputation. */
4
+ export function decideTrust(agent, reputation, policy = {}) {
5
+ const base = { did: agent.id, reputation };
6
+ if (agent.revokedAt)
7
+ return { ...base, decision: "deny", reasons: ["INAM ID is revoked"] };
8
+ const escrowMiss = policyFailure(reputation, { minEvidence: "none", ...policy.escrow });
9
+ if (escrowMiss)
10
+ return { ...base, decision: "deny", reasons: [escrowMiss] };
11
+ const reasons = [];
12
+ const allowMiss = policyFailure(reputation, { minEvidence: "independently_verified", ...policy.allow });
13
+ if (allowMiss)
14
+ reasons.push(allowMiss);
15
+ const watch = policy.escrowFlags ?? DEFAULT_ESCROW_FLAGS;
16
+ for (const f of reputation.flags ?? [])
17
+ if (watch.some((w) => f === w || f.startsWith(`${w}:`)))
18
+ reasons.push(`flag ${f}`);
19
+ if (reasons.length)
20
+ return { ...base, decision: "escrow", reasons };
21
+ return { ...base, decision: "allow", reasons: [`evidence ${reputation.evidenceLevel}, trustScore ${reputation.trustScore}`] };
22
+ }
23
+ /** Fetches `did` from the registry `inam` points at and decides. An ID the registry doesn't know is "deny". */
24
+ export async function checkTrust(did, inam, policy = {}) {
25
+ let agent, reputation;
26
+ try {
27
+ [agent, reputation] = await Promise.all([inam.getAgent(did), inam.getReputation(did)]);
28
+ }
29
+ catch {
30
+ return { did, decision: "deny", reasons: ["INAM ID not found in the registry"] };
31
+ }
32
+ return decideTrust(agent, reputation, policy);
33
+ }
34
+ //# sourceMappingURL=trust.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trust.js","sourceRoot":"","sources":["../src/trust.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAmB,MAAM,WAAW,CAAC;AA2B3D,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,YAAY,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,2BAA2B,CAAC,CAAC;AAEnI,wFAAwF;AACxF,MAAM,UAAU,WAAW,CAAC,KAAkB,EAAE,UAA4B,EAAE,SAAsB,EAAE;IACpG,MAAM,IAAI,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,UAAU,EAAE,CAAC;IAC3C,IAAI,KAAK,CAAC,SAAS;QAAE,OAAO,EAAE,GAAG,IAAI,EAAE,QA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,EAAE;IACtF,IAAI,KAAkB,EAAE,UAA4B,CAAC;IACrD,IAAI,CAAC;QACH,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACzF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,mCAAmC,CAAC,EAAE,CAAC;IACnF,CAAC;IACD,OAAO,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;AAChD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inamprotocol",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "Reference TypeScript/JavaScript SDK for the INAM Protocol — agent identity, execution receipts, jobs, and reputation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",