@agent-score/commerce 2.0.1 → 2.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.
- package/README.md +26 -11
- package/dist/_core-kI7FRAiZ.d.mts +10 -0
- package/dist/_core-kI7FRAiZ.d.ts +10 -0
- package/dist/challenge/index.d.mts +3 -3
- package/dist/challenge/index.d.ts +3 -3
- package/dist/challenge/index.js +21 -14
- package/dist/challenge/index.js.map +1 -1
- package/dist/challenge/index.mjs +21 -14
- package/dist/challenge/index.mjs.map +1 -1
- package/dist/{checkout-B1JuEcbx.d.ts → checkout-BH-I_Ns8.d.ts} +19 -12
- package/dist/{checkout-BN5i1Fi7.d.mts → checkout-Bd_4aQ6c.d.mts} +19 -12
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +1 -1
- package/dist/core.mjs.map +1 -1
- package/dist/default_rails-BWAquZeu.d.mts +188 -0
- package/dist/default_rails-BxBzcCA1.d.ts +188 -0
- package/dist/discovery/index.d.mts +5 -5
- package/dist/discovery/index.d.ts +5 -5
- package/dist/discovery/index.js +14 -1
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/index.mjs +14 -1
- package/dist/discovery/index.mjs.map +1 -1
- package/dist/identity/express.d.mts +7 -3
- package/dist/identity/express.d.ts +7 -3
- package/dist/identity/express.js +39 -96
- package/dist/identity/express.js.map +1 -1
- package/dist/identity/express.mjs +37 -87
- package/dist/identity/express.mjs.map +1 -1
- package/dist/identity/fastify.d.mts +4 -4
- package/dist/identity/fastify.d.ts +4 -4
- package/dist/identity/fastify.js +60 -96
- package/dist/identity/fastify.js.map +1 -1
- package/dist/identity/fastify.mjs +58 -87
- package/dist/identity/fastify.mjs.map +1 -1
- package/dist/identity/hono.d.mts +11 -3
- package/dist/identity/hono.d.ts +11 -3
- package/dist/identity/hono.js +39 -93
- package/dist/identity/hono.js.map +1 -1
- package/dist/identity/hono.mjs +37 -84
- package/dist/identity/hono.mjs.map +1 -1
- package/dist/identity/nextjs.d.mts +10 -3
- package/dist/identity/nextjs.d.ts +10 -3
- package/dist/identity/nextjs.js +49 -93
- package/dist/identity/nextjs.js.map +1 -1
- package/dist/identity/nextjs.mjs +46 -84
- package/dist/identity/nextjs.mjs.map +1 -1
- package/dist/identity/policy.js +220 -129
- package/dist/identity/policy.js.map +1 -1
- package/dist/identity/policy.mjs +222 -131
- package/dist/identity/policy.mjs.map +1 -1
- package/dist/identity/web.d.mts +9 -3
- package/dist/identity/web.d.ts +9 -3
- package/dist/identity/web.js +45 -93
- package/dist/identity/web.js.map +1 -1
- package/dist/identity/web.mjs +42 -84
- package/dist/identity/web.mjs.map +1 -1
- package/dist/index.d.mts +554 -90
- package/dist/index.d.ts +554 -90
- package/dist/index.js +951 -152
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +939 -152
- package/dist/index.mjs.map +1 -1
- package/dist/middleware/express.d.mts +10 -0
- package/dist/middleware/express.d.ts +10 -0
- package/dist/middleware/express.js +128 -0
- package/dist/middleware/express.js.map +1 -0
- package/dist/middleware/express.mjs +91 -0
- package/dist/middleware/express.mjs.map +1 -0
- package/dist/middleware/fastify.d.mts +10 -0
- package/dist/middleware/fastify.d.ts +10 -0
- package/dist/middleware/fastify.js +127 -0
- package/dist/middleware/fastify.js.map +1 -0
- package/dist/middleware/fastify.mjs +90 -0
- package/dist/middleware/fastify.mjs.map +1 -0
- package/dist/middleware/hono.d.mts +10 -0
- package/dist/middleware/hono.d.ts +10 -0
- package/dist/middleware/hono.js +122 -0
- package/dist/middleware/hono.js.map +1 -0
- package/dist/middleware/hono.mjs +85 -0
- package/dist/middleware/hono.mjs.map +1 -0
- package/dist/middleware/nextjs.d.mts +22 -0
- package/dist/middleware/nextjs.d.ts +22 -0
- package/dist/middleware/nextjs.js +143 -0
- package/dist/middleware/nextjs.js.map +1 -0
- package/dist/middleware/nextjs.mjs +105 -0
- package/dist/middleware/nextjs.mjs.map +1 -0
- package/dist/middleware/web.d.mts +25 -0
- package/dist/middleware/web.d.ts +25 -0
- package/dist/middleware/web.js +128 -0
- package/dist/middleware/web.js.map +1 -0
- package/dist/middleware/web.mjs +91 -0
- package/dist/middleware/web.mjs.map +1 -0
- package/dist/payment/index.d.mts +21 -6
- package/dist/payment/index.d.ts +21 -6
- package/dist/payment/index.js +136 -9
- package/dist/payment/index.js.map +1 -1
- package/dist/payment/index.mjs +127 -9
- package/dist/payment/index.mjs.map +1 -1
- package/dist/{pricing-CxzwyiO6.d.mts → pricing-4n5Ota0D.d.mts} +14 -4
- package/dist/{pricing-CQ9DIFaw.d.ts → pricing-DHfH3ogG.d.ts} +14 -4
- package/dist/{rail_spec-XP0wKgJV.d.mts → rail_spec-D6qzh3J0.d.mts} +1 -1
- package/dist/{rail_spec-XP0wKgJV.d.ts → rail_spec-D6qzh3J0.d.ts} +1 -1
- package/dist/stripe-multichain/index.d.mts +150 -47
- package/dist/stripe-multichain/index.d.ts +150 -47
- package/dist/stripe-multichain/index.js +19749 -42
- package/dist/stripe-multichain/index.js.map +1 -1
- package/dist/stripe-multichain/index.mjs +19758 -27
- package/dist/stripe-multichain/index.mjs.map +1 -1
- package/dist/{x402_server-hgQzWQwB.d.mts → x402_server-Ciz2mls2.d.mts} +1 -1
- package/dist/{x402_server-hgQzWQwB.d.ts → x402_server-Ciz2mls2.d.ts} +1 -1
- package/package.json +43 -5
- package/dist/_response-BFYN3b6i.d.mts +0 -142
- package/dist/_response-_iPD5AIj.d.ts +0 -142
- package/dist/solana-Cds87OTu.d.mts +0 -67
- package/dist/solana-Cds87OTu.d.ts +0 -67
package/dist/identity/hono.js
CHANGED
|
@@ -20,20 +20,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/identity/hono.ts
|
|
21
21
|
var hono_exports = {};
|
|
22
22
|
__export(hono_exports, {
|
|
23
|
-
FIXABLE_DENIAL_REASONS: () => FIXABLE_DENIAL_REASONS,
|
|
24
23
|
agentscoreGate: () => agentscoreGate,
|
|
25
|
-
buildContactSupportNextSteps: () => buildContactSupportNextSteps,
|
|
26
|
-
buildSignerMismatchBody: () => buildSignerMismatchBody,
|
|
27
24
|
captureWallet: () => captureWallet,
|
|
28
|
-
|
|
29
|
-
denialReasonToBody: () => denialReasonToBody,
|
|
25
|
+
conditionalAgentscoreGate: () => conditionalAgentscoreGate,
|
|
30
26
|
getAgentScoreData: () => getAgentScoreData,
|
|
31
27
|
getGateDegradedState: () => getGateDegradedState,
|
|
32
28
|
getGateQuotaInfo: () => getGateQuotaInfo,
|
|
33
|
-
getSignerVerdict: () => getSignerVerdict
|
|
34
|
-
isFixableDenial: () => isFixableDenial,
|
|
35
|
-
readX402PaymentHeader: () => readX402PaymentHeader,
|
|
36
|
-
verificationAgentInstructions: () => verificationAgentInstructions
|
|
29
|
+
getSignerVerdict: () => getSignerVerdict
|
|
37
30
|
});
|
|
38
31
|
module.exports = __toCommonJS(hono_exports);
|
|
39
32
|
|
|
@@ -52,80 +45,6 @@ function denialReasonStatus(reason) {
|
|
|
52
45
|
if (reason.code === "api_error") return 503;
|
|
53
46
|
return 403;
|
|
54
47
|
}
|
|
55
|
-
function buildSignerMismatchBody({
|
|
56
|
-
result,
|
|
57
|
-
userMessage,
|
|
58
|
-
learnMoreUrl
|
|
59
|
-
}) {
|
|
60
|
-
if (result.kind === "pass") return null;
|
|
61
|
-
const learnMoreUrlResolved = learnMoreUrl ?? "https://docs.agentscore.sh/guides/agent-identity";
|
|
62
|
-
if (result.kind === "wallet_signer_mismatch") {
|
|
63
|
-
const linkedWallets = result.linkedWallets ?? [];
|
|
64
|
-
const userMessageResolved = userMessage ?? (linkedWallets.length > 0 ? `Sign the payment with one of the wallets linked to this operator: ${linkedWallets.join(", ")}. Then retry.` : "Sign the payment with the same wallet you claimed via X-Wallet-Address, or switch to X-Operator-Token for rail-independent identity.");
|
|
65
|
-
return {
|
|
66
|
-
error: {
|
|
67
|
-
code: "wallet_signer_mismatch",
|
|
68
|
-
message: "Payment signer does not match the wallet claimed via X-Wallet-Address. The signer and the claimed wallet must both resolve to the same AgentScore operator."
|
|
69
|
-
},
|
|
70
|
-
claimed_operator: result.claimedOperator,
|
|
71
|
-
actual_signer_operator: result.actualSignerOperator ?? null,
|
|
72
|
-
expected_signer: result.expectedSigner,
|
|
73
|
-
actual_signer: result.actualSigner,
|
|
74
|
-
linked_wallets: linkedWallets,
|
|
75
|
-
next_steps: {
|
|
76
|
-
action: "regenerate_payment_from_linked_wallet",
|
|
77
|
-
user_message: userMessageResolved,
|
|
78
|
-
learn_more_url: learnMoreUrlResolved
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
error: {
|
|
84
|
-
code: "wallet_auth_requires_wallet_signing",
|
|
85
|
-
message: "Wallet-auth requires a payment rail that carries a wallet signature (Tempo MPP, x402). Stripe SPT and card rails have no wallet signer; switch to X-Operator-Token to use those."
|
|
86
|
-
},
|
|
87
|
-
next_steps: {
|
|
88
|
-
action: "switch_to_operator_token",
|
|
89
|
-
user_message: userMessage ?? "Drop the X-Wallet-Address header and retry with X-Operator-Token (works on every payment rail).",
|
|
90
|
-
learn_more_url: learnMoreUrlResolved
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
function buildContactSupportNextSteps(supportEmail, message) {
|
|
95
|
-
return {
|
|
96
|
-
action: "contact_support",
|
|
97
|
-
support_email: supportEmail,
|
|
98
|
-
user_message: message ?? `If you believe this denial is in error, contact support at ${supportEmail} with the details of your request.`
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
function verificationAgentInstructions({
|
|
102
|
-
userAction,
|
|
103
|
-
retryStep,
|
|
104
|
-
extraSteps,
|
|
105
|
-
pollIntervalSeconds = 5,
|
|
106
|
-
timeoutSeconds = 3600,
|
|
107
|
-
orderTtl,
|
|
108
|
-
extra
|
|
109
|
-
} = {}) {
|
|
110
|
-
const baseSteps = [
|
|
111
|
-
"Present the verify_url directly to the user \u2014 it is a complete, ready-to-open URL with the session token already embedded (e.g. https://agentscore.sh/verify?session=sess_...). Do NOT modify or construct the URL yourself.",
|
|
112
|
-
`Immediately begin polling poll_url every ${pollIntervalSeconds} seconds with header X-Poll-Secret set to poll_secret. The user will complete verification in their browser while you poll in the background.`,
|
|
113
|
-
"The user visits the URL, signs in, completes identity verification (photo ID + selfie via Stripe Identity), and closes the tab. They do NOT need to copy or paste anything back to you.",
|
|
114
|
-
'When your poll returns status "verified", extract operator_token from the response. This is a one-time value \u2014 save it immediately. Subsequent polls return status "consumed" without the token.',
|
|
115
|
-
retryStep ?? "Retry the original merchant request with header X-Operator-Token set to the operator_token value."
|
|
116
|
-
];
|
|
117
|
-
return {
|
|
118
|
-
action: "poll_for_credential",
|
|
119
|
-
user_action: userAction ?? "The user must visit verify_url to complete identity verification before this request can proceed",
|
|
120
|
-
steps: extraSteps ? [...baseSteps, ...extraSteps] : baseSteps,
|
|
121
|
-
poll_interval_seconds: pollIntervalSeconds,
|
|
122
|
-
poll_secret_header: "X-Poll-Secret",
|
|
123
|
-
retry_token_header: "X-Operator-Token",
|
|
124
|
-
timeout_seconds: timeoutSeconds,
|
|
125
|
-
...orderTtl ? { order_ttl: orderTtl } : {},
|
|
126
|
-
...extra ?? {}
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
48
|
|
|
130
49
|
// src/_response.ts
|
|
131
50
|
var WALLET_NOT_TRUSTED_INSTRUCTIONS = JSON.stringify({
|
|
@@ -375,7 +294,7 @@ function createAgentScoreCore(options) {
|
|
|
375
294
|
} = options;
|
|
376
295
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
377
296
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
378
|
-
const defaultUa = `@agent-score/commerce@${"2.0
|
|
297
|
+
const defaultUa = `@agent-score/commerce@${"2.1.0"}`;
|
|
379
298
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
380
299
|
const sdk = new import_sdk.AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
|
|
381
300
|
const sessionSdkCache = /* @__PURE__ */ new Map();
|
|
@@ -667,6 +586,30 @@ function createAgentScoreCore(options) {
|
|
|
667
586
|
return { evaluate, captureWallet: captureWallet2, getSignerVerdict: getSignerVerdict2 };
|
|
668
587
|
}
|
|
669
588
|
|
|
589
|
+
// src/payment/payment_header.ts
|
|
590
|
+
function toTitleCase(name) {
|
|
591
|
+
return name.replace(/(^|-)([a-z])/g, (_m, sep, c) => sep + c.toUpperCase());
|
|
592
|
+
}
|
|
593
|
+
function readHeader(headers, name) {
|
|
594
|
+
if (typeof headers.get === "function") {
|
|
595
|
+
return headers.get(name);
|
|
596
|
+
}
|
|
597
|
+
const rec = headers;
|
|
598
|
+
const v = rec[name] ?? rec[name.toLowerCase()] ?? rec[toTitleCase(name)];
|
|
599
|
+
if (typeof v === "string") return v;
|
|
600
|
+
if (Array.isArray(v) && typeof v[0] === "string") return v[0];
|
|
601
|
+
return null;
|
|
602
|
+
}
|
|
603
|
+
function asHeaders(input) {
|
|
604
|
+
return typeof input.headers === "object" && input instanceof Request ? input.headers : input;
|
|
605
|
+
}
|
|
606
|
+
function hasPaymentHeader(input) {
|
|
607
|
+
const headers = asHeaders(input);
|
|
608
|
+
return Boolean(
|
|
609
|
+
readHeader(headers, "payment-signature") || readHeader(headers, "x-payment") || readHeader(headers, "authorization")?.startsWith("Payment ")
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
|
|
670
613
|
// src/signer.ts
|
|
671
614
|
var TOKEN_PROGRAM = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
672
615
|
var TOKEN_2022_PROGRAM = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
|
|
@@ -813,21 +756,24 @@ function getSignerVerdict(c) {
|
|
|
813
756
|
if (!state?.walletAddress) return void 0;
|
|
814
757
|
return state.core.getSignerVerdict(state.walletAddress);
|
|
815
758
|
}
|
|
759
|
+
function conditionalAgentscoreGate(options) {
|
|
760
|
+
const gate = agentscoreGate(options);
|
|
761
|
+
return async (c, next) => {
|
|
762
|
+
if (!hasPaymentHeader(c.req.raw)) {
|
|
763
|
+
await next();
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
return gate(c, next);
|
|
767
|
+
};
|
|
768
|
+
}
|
|
816
769
|
// Annotate the CommonJS export names for ESM import in node:
|
|
817
770
|
0 && (module.exports = {
|
|
818
|
-
FIXABLE_DENIAL_REASONS,
|
|
819
771
|
agentscoreGate,
|
|
820
|
-
buildContactSupportNextSteps,
|
|
821
|
-
buildSignerMismatchBody,
|
|
822
772
|
captureWallet,
|
|
823
|
-
|
|
824
|
-
denialReasonToBody,
|
|
773
|
+
conditionalAgentscoreGate,
|
|
825
774
|
getAgentScoreData,
|
|
826
775
|
getGateDegradedState,
|
|
827
776
|
getGateQuotaInfo,
|
|
828
|
-
getSignerVerdict
|
|
829
|
-
isFixableDenial,
|
|
830
|
-
readX402PaymentHeader,
|
|
831
|
-
verificationAgentInstructions
|
|
777
|
+
getSignerVerdict
|
|
832
778
|
});
|
|
833
779
|
//# sourceMappingURL=hono.js.map
|