@agent-score/commerce 1.5.1 → 1.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.
Files changed (52) hide show
  1. package/README.md +27 -15
  2. package/dist/challenge/index.js.map +1 -1
  3. package/dist/challenge/index.mjs.map +1 -1
  4. package/dist/core.d.mts +36 -27
  5. package/dist/core.d.ts +36 -27
  6. package/dist/core.js +1 -1
  7. package/dist/core.js.map +1 -1
  8. package/dist/core.mjs +1 -1
  9. package/dist/core.mjs.map +1 -1
  10. package/dist/identity/express.d.mts +2 -2
  11. package/dist/identity/express.d.ts +2 -2
  12. package/dist/identity/express.js +1 -1
  13. package/dist/identity/express.js.map +1 -1
  14. package/dist/identity/express.mjs +1 -1
  15. package/dist/identity/express.mjs.map +1 -1
  16. package/dist/identity/fastify.d.mts +2 -2
  17. package/dist/identity/fastify.d.ts +2 -2
  18. package/dist/identity/fastify.js +1 -1
  19. package/dist/identity/fastify.js.map +1 -1
  20. package/dist/identity/fastify.mjs +1 -1
  21. package/dist/identity/fastify.mjs.map +1 -1
  22. package/dist/identity/hono.d.mts +2 -2
  23. package/dist/identity/hono.d.ts +2 -2
  24. package/dist/identity/hono.js +1 -1
  25. package/dist/identity/hono.js.map +1 -1
  26. package/dist/identity/hono.mjs +1 -1
  27. package/dist/identity/hono.mjs.map +1 -1
  28. package/dist/identity/nextjs.d.mts +2 -2
  29. package/dist/identity/nextjs.d.ts +2 -2
  30. package/dist/identity/nextjs.js +1 -1
  31. package/dist/identity/nextjs.js.map +1 -1
  32. package/dist/identity/nextjs.mjs +1 -1
  33. package/dist/identity/nextjs.mjs.map +1 -1
  34. package/dist/identity/policy.d.mts +3 -3
  35. package/dist/identity/policy.d.ts +3 -3
  36. package/dist/identity/policy.js +3 -3
  37. package/dist/identity/policy.js.map +1 -1
  38. package/dist/identity/policy.mjs +2 -2
  39. package/dist/identity/policy.mjs.map +1 -1
  40. package/dist/identity/web.d.mts +3 -3
  41. package/dist/identity/web.d.ts +3 -3
  42. package/dist/identity/web.js +1 -1
  43. package/dist/identity/web.js.map +1 -1
  44. package/dist/identity/web.mjs +1 -1
  45. package/dist/identity/web.mjs.map +1 -1
  46. package/dist/index.d.mts +286 -130
  47. package/dist/index.d.ts +286 -130
  48. package/dist/index.js +130 -72
  49. package/dist/index.js.map +1 -1
  50. package/dist/index.mjs +124 -69
  51. package/dist/index.mjs.map +1 -1
  52. package/package.json +2 -2
package/README.md CHANGED
@@ -23,10 +23,12 @@ npm install hono mppx @x402/core @x402/evm @solana/mpp @solana/kit stripe # wh
23
23
 
24
24
  | Subpath | What it provides |
25
25
  |---|---|
26
- | `/identity/{hono,express,fastify,nextjs,web}` | Trust gate middleware: KYC, sanctions, age, jurisdiction. `agentscoreGate(...)`, `getAgentScoreData(c)`, `captureWallet(...)`, `verifyWalletSignerMatch(...)`. Plus shared denial helpers: `denialReasonStatus`, `denialReasonToBody`, `buildSignerMismatchBody`, `buildContactSupportNextSteps`, `verificationAgentInstructions`, `isFixableDenial`, `FIXABLE_DENIAL_REASONS`. |
26
+ | `/identity/{hono,express,fastify}` | Trust gate middleware: KYC, sanctions, age, jurisdiction. Context-getter pattern: `agentscoreGate(opts)` middleware + `getAgentScoreData(ctx)` / `getGateDegradedState(ctx)` / `getGateQuotaInfo(ctx)` accessors, `captureWallet(...)`, `verifyWalletSignerMatch(...)`. Plus shared denial helpers: `denialReasonStatus`, `denialReasonToBody`, `buildSignerMismatchBody`, `buildContactSupportNextSteps`, `verificationAgentInstructions`, `isFixableDenial`, `FIXABLE_DENIAL_REASONS`. |
27
+ | `/identity/policy` | Per-product compliance helpers for multi-product merchants (each product carries its own policy: hard gate vs soft vs none, per-product shipping allowlists): `PolicyBlock`, `GateResult`, `EnforcementMode`, `IdentityStatus`, `buildGateOptionsFromPolicy`, `runGateWithEnforcement`, `shippingCountryAllowed`, `shippingStateAllowed`. |
28
+ | `/identity/{nextjs,web}` | Same gate, wrapper pattern: `withAgentScoreGate(opts, handler)` / `createAgentScoreGate(opts) => guard(req)`. The `data` + `degraded` + `infraReason` fields land directly on the handler arg / guard result (no separate getter). Plus shared `captureWallet`, `verifyWalletSignerMatch`. |
27
29
  | `/payment` | `networks`, `USDC`, `rails` registries; `paymentDirective`, `buildPaymentDirective`, `wwwAuthenticateHeader`, `paymentRequiredHeader`, `aliasAmountFields` (v1↔v2 amount field shim: emits both `amount` and `maxAmountRequired` so v1-only x402 parsers like Coinbase awal can read v2 bodies), `settlementOverrideHeader`, `dispatchSettlementByNetwork`, `extractPaymentSigner` (returns `{address, network}`); `createX402Server`, `createMppxServer`; drop-in x402 helpers: `validateX402NetworkConfig` (boot-time guard), `verifyX402Request` (parse + validate inbound X-Payment), `processX402Settle` (verify-then-settle with one call), `classifyX402SettleResult` (maps the tagged settle result to a recommended HTTP status / code / nextSteps so merchants get a controlled envelope without coupling to facilitator-specific error text). |
28
30
  | `/discovery` | `isDiscoveryProbeRequest`, `buildDiscoveryProbeResponse` (with optional `x402Sample` for x402-aware crawlers, e.g. `awal x402 details`), `sampleX402AcceptForNetwork` (USDC sample-accept builder for known CAIP-2 networks), `buildWellKnownMpp`, `buildLlmsTxt` + `llmsTxtIdentitySection` + `llmsTxtPaymentSection` (compact + verbose modes), `buildSkillMd` (Claude-Skill-compatible `/skill.md` agent-discovery manifest; strictly agent-facing data only, no internal posture), `agentscoreOpenApiSnippets`, `createBazaarDiscovery`, `noindexNonDiscoveryPaths` (Hono middleware that emits `X-Robots-Tag: noindex` on every path except the agent-discovery surfaces; defaults cover `/openapi.json`, `/llms.txt`, `/skill.md`, `/.well-known/{mpp.json,agent-card.json,ucp,jwks.json}`, `/favicon.{png,ico}`; pure helpers `isDiscoveryPath` + `defaultDiscoveryPaths` for non-Hono frameworks). |
29
- | `/challenge` | `build402Body`, `buildAcceptedMethods`, `buildIdentityMetadata`, `buildHowToPay`, `buildAgentInstructions` (auto-emits per-rail `compatible_clients`: smoke-verified CLIs the agent should use; vendor override supported), `buildPricingBlock`, `firstEncounterAgentMemory`, `OrderReceipt`; `respond402`, a drop-in 402 emit that preserves mppx's `WWW-Authenticate` and layers x402's `PAYMENT-REQUIRED`. `buildValidationError`: structured 4xx body builder (`{error: {code, message}, required_fields?, example_body?, next_steps?, ...extra}`) so vendors compose body shapes by name instead of inlining at every validation site. |
31
+ | `/challenge` | `build402Body`, `buildAcceptedMethods`, `buildIdentityMetadata`, `buildHowToPay`, `buildAgentInstructions` (auto-emits per-rail `compatible_clients`: smoke-verified CLIs the agent should use; vendor override supported; pure helper `compatibleClientsByRails(rails)` returns the same map for vendors building custom 402s), `buildPricingBlock`, `firstEncounterAgentMemory`, `OrderReceipt`; `respond402`, a drop-in 402 emit that preserves mppx's `WWW-Authenticate` and layers x402's `PAYMENT-REQUIRED`. `buildValidationError`: structured 4xx body builder (`{error: {code, message}, required_fields?, example_body?, next_steps?, ...extra}`) so vendors compose body shapes by name instead of inlining at every validation site. |
30
32
  | `/stripe-multichain` | `createMultichainPaymentIntent`, `getDepositAddress`, `simulateCryptoDeposit`, `createMppxStripe`; `createPiCache` (TTL'd PI / deposit-address cache, Redis-backed when `redisUrl` set, in-memory otherwise), `simulateDepositIfTestMode` (gates on `sk_test_` and looks up the PI for you), `STRIPE_TEST_TX_HASH_SUCCESS` / `STRIPE_TEST_TX_HASH_FAILED` constants. Peer dep on `stripe`. |
31
33
  | `/api` | Everything from `@agent-score/sdk` re-exported in one place: `AgentScore` + `AgentScoreError`, `AGENTSCORE_TEST_ADDRESSES` + `isAgentScoreTestAddress`. **Don't add `@agent-score/sdk` as a separate dep**; the two can drift versions and cause subtle type mismatches. |
32
34
 
@@ -193,10 +195,19 @@ return new Response(JSON.stringify(responseBody), { status: 402, headers });
193
195
  import { buildA2AAgentCard, buildUCPProfile, ucpA2AExtension } from "@agent-score/commerce";
194
196
 
195
197
  // Google A2A v1.0 Signed Agent Card; publish at /.well-known/agent-card.json.
196
- // Per UCP §A2A binding, the card MUST declare the canonical UCP extension URI;
197
- // pass `ucpA2AExtension()` with empty capabilities until you bind formal UCP
198
- // capabilities (dev.ucp.shopping.checkout, etc.).
199
- const card = buildA2AAgentCard({ name, url, capabilities, extensions: [ucpA2AExtension()], data: assess });
198
+ // Per UCP §A2A binding, the card MUST declare the canonical UCP extension URI in
199
+ // `capabilities.extensions[]`; pass `ucpA2AExtension()` with empty capabilities
200
+ // until you bind formal UCP capabilities (dev.ucp.shopping.checkout, etc.).
201
+ // Skills are top-level AgentSkill objects; identity claims live in a separate
202
+ // AgentCardSignature (RFC 7515 JWS) wrapping the serialized card.
203
+ const card = buildA2AAgentCard({
204
+ name,
205
+ description,
206
+ url,
207
+ version: "1.0.0",
208
+ skills: [{ id: "purchase", name: "Purchase", description: "Buy products via agent payments.", tags: ["commerce", "payment"] }],
209
+ extensions: [ucpA2AExtension()],
210
+ });
200
211
 
201
212
  // Google Universal Commerce Protocol; publish at /.well-known/ucp
202
213
  // Output shape: { ucp: { version, services, capabilities, payment_handlers,
@@ -209,18 +220,19 @@ const profile = buildUCPProfile({
209
220
  'dev.ucp.shopping': [
210
221
  { version: '2026-04-08', spec: 'https://ucp.dev/2026-04-08/specification/overview',
211
222
  transport: 'mcp', endpoint: 'https://merchant.example/api/ucp/mcp',
212
- schema: 'https://ucp.dev/services/shopping/openrpc.json' },
223
+ schema: 'https://ucp.dev/services/shopping/mcp.openrpc.json' },
213
224
  ],
214
225
  },
215
226
  payment_handlers: {
216
- 'sh.agentscore.payment.tempo': [{
217
- id: 'tempo', version: '2026-04-08',
218
- spec: 'https://agentscore.sh/specification/payment-handlers/tempo',
219
- schema: 'https://agentscore.sh/schemas/payment-handlers/tempo.json',
220
- config: { recipient: TEMPO_ADDR },
221
- }],
227
+ ...mppPaymentHandler({ networks: [{ network: 'tempo-mainnet', chain_id: 4217, recipient: TEMPO_ADDR }] }),
228
+ ...x402PaymentHandler({ networks: [{ network: 'base-8453', recipient: BASE_ADDR }] }),
229
+ ...stripeSptPaymentHandler({ profile_id: 'profile_5xKvNqM9BaH' }),
222
230
  },
223
- signing_keys, data: assess,
231
+ signing_keys,
232
+ // Optional: declare the merchant's gate policy as an `sh.agentscore.identity` capability
233
+ // binding inside the public profile. Static policy declaration only — no per-operator data.
234
+ // Per-operator identity attestation lives on the AP2 risk-signal endpoint, not here.
235
+ agentscore_gate: { require_kyc: true, min_age: 21, allowed_jurisdictions: ['US'] },
224
236
  });
225
237
  ```
226
238
 
@@ -379,7 +391,7 @@ When `failOpen: true` AND the failure is infra-shape, the gate carries `degraded
379
391
 
380
392
  For regulated commerce (alcohol, age-gated, sanctioned-jurisdiction-relevant) keep the default `failOpen: false`: outage is the correct posture, and bypassing compliance on infra failure is a compliance gap. For low-stakes commerce or high-uptime SLAs, opt in and use the `degraded` flag as the audit trail.
381
393
 
382
- The `getGateDegradedState` helper is exported by every framework adapter (Hono, Express, Fastify, Next.js, Web Fetch). For `withAgentScoreGate` (Next.js / Web Fetch), the `degraded` + `infraReason` fields land directly on the `gate` object passed to your handler.
394
+ The `getGateDegradedState` helper is exported by the context-getter adapters (Hono, Express, Fastify). For the wrapper-pattern adapters (Next.js, Web Fetch via `withAgentScoreGate` / `createAgentScoreGate`), the `degraded` + `infraReason` fields land directly on the `gate` object passed to your handler — no separate getter.
383
395
 
384
396
  ## Examples
385
397