@agent-score/commerce 2.4.0 → 2.6.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 +19 -17
- package/dist/challenge/index.d.mts +31 -3
- package/dist/challenge/index.d.ts +31 -3
- package/dist/challenge/index.js +25 -9
- package/dist/challenge/index.js.map +1 -1
- package/dist/challenge/index.mjs +25 -9
- package/dist/challenge/index.mjs.map +1 -1
- package/dist/{checkout-B-MIzYzW.d.ts → checkout-C4RD7M0Z.d.ts} +117 -13
- package/dist/{checkout-Bn7ZKIBD.d.mts → checkout-CzB9f_jf.d.mts} +117 -13
- package/dist/core.d.mts +40 -7
- package/dist/core.d.ts +40 -7
- package/dist/core.js +52 -27
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +52 -27
- package/dist/core.mjs.map +1 -1
- package/dist/discovery/index.d.mts +33 -3
- package/dist/discovery/index.d.ts +33 -3
- package/dist/discovery/index.js +50 -16
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/index.mjs +49 -16
- package/dist/discovery/index.mjs.map +1 -1
- package/dist/gate-D2RP6bZg.d.ts +307 -0
- package/dist/gate-GCXy4FHI.d.mts +307 -0
- package/dist/identity/express.d.mts +28 -1
- package/dist/identity/express.d.ts +28 -1
- package/dist/identity/express.js +714 -31
- package/dist/identity/express.js.map +1 -1
- package/dist/identity/express.mjs +710 -30
- package/dist/identity/express.mjs.map +1 -1
- package/dist/identity/fastify.d.mts +14 -2
- package/dist/identity/fastify.d.ts +14 -2
- package/dist/identity/fastify.js +727 -31
- package/dist/identity/fastify.js.map +1 -1
- package/dist/identity/fastify.mjs +723 -30
- package/dist/identity/fastify.mjs.map +1 -1
- package/dist/identity/hono.d.mts +28 -1
- package/dist/identity/hono.d.ts +28 -1
- package/dist/identity/hono.js +696 -33
- package/dist/identity/hono.js.map +1 -1
- package/dist/identity/hono.mjs +692 -32
- package/dist/identity/hono.mjs.map +1 -1
- package/dist/identity/nextjs.d.mts +5 -0
- package/dist/identity/nextjs.d.ts +5 -0
- package/dist/identity/nextjs.js +695 -30
- package/dist/identity/nextjs.js.map +1 -1
- package/dist/identity/nextjs.mjs +691 -29
- package/dist/identity/nextjs.mjs.map +1 -1
- package/dist/identity/policy.d.mts +21 -2
- package/dist/identity/policy.d.ts +21 -2
- package/dist/identity/policy.js +22 -1
- package/dist/identity/policy.js.map +1 -1
- package/dist/identity/policy.mjs +21 -1
- package/dist/identity/policy.mjs.map +1 -1
- package/dist/identity/web.d.mts +26 -1
- package/dist/identity/web.d.ts +26 -1
- package/dist/identity/web.js +695 -30
- package/dist/identity/web.js.map +1 -1
- package/dist/identity/web.mjs +691 -29
- package/dist/identity/web.mjs.map +1 -1
- package/dist/index.d.mts +165 -4
- package/dist/index.d.ts +165 -4
- package/dist/index.js +3103 -534
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3086 -545
- package/dist/index.mjs.map +1 -1
- package/dist/payment/index.d.mts +1 -1
- package/dist/payment/index.d.ts +1 -1
- package/dist/payment/index.js +10 -2
- package/dist/payment/index.js.map +1 -1
- package/dist/payment/index.mjs +10 -2
- package/dist/payment/index.mjs.map +1 -1
- package/dist/stripe-multichain/index.js +1614 -266
- package/dist/stripe-multichain/index.js.map +1 -1
- package/dist/stripe-multichain/index.mjs +1614 -266
- package/dist/stripe-multichain/index.mjs.map +1 -1
- package/dist/types-D1slMt0H.d.mts +137 -0
- package/dist/types-D1slMt0H.d.ts +137 -0
- package/dist/{wwwauthenticate-CVaGUMjU.d.mts → wwwauthenticate-Dgm-_af9.d.mts} +11 -1
- package/dist/{wwwauthenticate-CVaGUMjU.d.ts → wwwauthenticate-Dgm-_af9.d.ts} +11 -1
- package/package.json +26 -21
package/dist/core.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
+
import { AipSignatureMaterial } from '@agent-score/sdk';
|
|
1
2
|
import { P as PaymentSigner } from './signer-3FAit11j.js';
|
|
2
3
|
|
|
3
4
|
interface AgentIdentity {
|
|
4
5
|
address?: string;
|
|
5
6
|
operatorToken?: string;
|
|
7
|
+
/** Raw AIP Agent Identity Token (a JWT). When set, the gate has verified the token's RFC 9421
|
|
8
|
+
* proof-of-possession at the edge as a fail-fast filter; `evaluate` forwards it to `/v1/assess`
|
|
9
|
+
* as `aip_token` (with {@link aipSignature}) for AUTHORITATIVE server-side re-verification of the
|
|
10
|
+
* IdP signature + proof-of-possession + policy. */
|
|
11
|
+
aipToken?: string;
|
|
12
|
+
/** RFC 9421 signature material accompanying {@link aipToken}, forwarded to `/v1/assess` as
|
|
13
|
+
* `aip_signature` so the API re-verifies proof-of-possession itself (the edge is not trusted as
|
|
14
|
+
* the authority). Always set together with `aipToken`. */
|
|
15
|
+
aipSignature?: AipSignatureMaterial;
|
|
6
16
|
}
|
|
7
17
|
/**
|
|
8
18
|
* Session metadata returned from `POST /v1/sessions`. Surfaced to the `onBeforeSession`
|
|
@@ -66,7 +76,7 @@ interface AgentScoreCoreOptions {
|
|
|
66
76
|
failOpen?: boolean;
|
|
67
77
|
/** How long to cache results, in seconds. Defaults to 300. */
|
|
68
78
|
cacheSeconds?: number;
|
|
69
|
-
/** AgentScore API base URL. Defaults to "https://api.agentscore.
|
|
79
|
+
/** AgentScore API base URL. Defaults to "https://api.agentscore.com". */
|
|
70
80
|
baseUrl?: string;
|
|
71
81
|
/** Optional chain to filter scoring to. */
|
|
72
82
|
chain?: string;
|
|
@@ -74,6 +84,11 @@ interface AgentScoreCoreOptions {
|
|
|
74
84
|
userAgent?: string;
|
|
75
85
|
/** When set and no identity is found, create a verification session instead of denying immediately. */
|
|
76
86
|
createSessionOnMissing?: CreateSessionOnMissing;
|
|
87
|
+
/** Issuers whose AIP Agent Identity Tokens this gate accepts. When set, the missing-identity
|
|
88
|
+
* recovery instructions and the `agent_memory` hint advertise the AIT path so agents holding
|
|
89
|
+
* one can present it. Set by Checkout from `gate.aip.trustedIssuers`; the actual AIT
|
|
90
|
+
* verification happens at the edge (Checkout) before `evaluate`. */
|
|
91
|
+
aipTrustedIssuers?: string[];
|
|
77
92
|
}
|
|
78
93
|
type DenialCode = 'wallet_not_trusted' | 'missing_identity' | 'api_error' | 'payment_required' | 'identity_verification_required' | 'wallet_signer_mismatch' | 'wallet_auth_requires_wallet_signing' | 'token_expired' | 'invalid_credential';
|
|
79
94
|
/**
|
|
@@ -90,7 +105,12 @@ interface AgentMemoryHint {
|
|
|
90
105
|
identity_paths: {
|
|
91
106
|
wallet: string;
|
|
92
107
|
operator_token: string;
|
|
108
|
+
agent_identity?: string;
|
|
93
109
|
};
|
|
110
|
+
/** Issuers whose AIP Agent Identity Tokens this merchant accepts. Present only when the
|
|
111
|
+
* merchant opted into AIP; an agent holding an AIT from one of these can present it via an
|
|
112
|
+
* `Agent-Identity` header + RFC 9421 signature instead of bootstrapping a fresh credential. */
|
|
113
|
+
aip_trusted_issuers?: string[];
|
|
94
114
|
bootstrap: string;
|
|
95
115
|
do_not_persist_in_memory: string[];
|
|
96
116
|
persist_in_credential_store: string[];
|
|
@@ -169,6 +189,16 @@ interface AssessResult {
|
|
|
169
189
|
linked_wallets?: string[];
|
|
170
190
|
verify_url?: string;
|
|
171
191
|
policy_result?: PolicyResult | null;
|
|
192
|
+
/** IdP provenance, present only when `identity_method === 'aip_token'` — which issuer attested
|
|
193
|
+
* the identity and the trust level it asserted. Mirrors the SDK's `AssessResponse.aip`. */
|
|
194
|
+
aip?: {
|
|
195
|
+
issuer: string;
|
|
196
|
+
subject: string;
|
|
197
|
+
trust_level?: 'autonomous' | 'human_present' | 'human_confirmed';
|
|
198
|
+
agent_provider?: string;
|
|
199
|
+
/** True when /v1/assess re-verified the RFC 9421 proof-of-possession (always true on success). */
|
|
200
|
+
pop_verified?: boolean;
|
|
201
|
+
};
|
|
172
202
|
}
|
|
173
203
|
/**
|
|
174
204
|
* Reason a failOpen allow short-circuited an evaluate call due to AgentScore-side
|
|
@@ -200,6 +230,12 @@ interface GateQuotaInfo {
|
|
|
200
230
|
* merchants can alert/log without parsing console output.
|
|
201
231
|
* - `quota` propagates the SDK's per-request quota observability when the API emits the
|
|
202
232
|
* `X-Quota-*` headers. Optional; absent on Enterprise / unlimited tiers.
|
|
233
|
+
* - `signerVerdict` carries the per-request wallet-signer verdicts (signer_match + signer_sanctions)
|
|
234
|
+
* composed by this evaluate's assess call. It rides on the RETURN VALUE (not a shared slot on the
|
|
235
|
+
* core) so concurrent same-wallet/different-signer requests can't read each other's verdict —
|
|
236
|
+
* the adapter stashes it on its per-request state for `getSignerVerdict(ctx)` to read back.
|
|
237
|
+
* Present only on wallet-only identity when the response carried either signer block; `undefined`
|
|
238
|
+
* otherwise (operator-token / AIT paths, discovery legs with no signer).
|
|
203
239
|
* - `{ kind: 'deny', reason }` — the request was denied. Adapters should render a 403 with the
|
|
204
240
|
* reason, or invoke the caller's custom denial handler.
|
|
205
241
|
*/
|
|
@@ -209,9 +245,11 @@ type EvaluateOutcome = {
|
|
|
209
245
|
degraded?: boolean;
|
|
210
246
|
infraReason?: FailOpenInfraReason;
|
|
211
247
|
quota?: GateQuotaInfo;
|
|
248
|
+
signerVerdict?: SignerVerdict;
|
|
212
249
|
} | {
|
|
213
250
|
kind: 'deny';
|
|
214
251
|
reason: DenialReason;
|
|
252
|
+
signerVerdict?: SignerVerdict;
|
|
215
253
|
};
|
|
216
254
|
interface CaptureWalletOptions {
|
|
217
255
|
/** Operator credential (`opc_...`) that the agent authenticated with. */
|
|
@@ -280,16 +318,11 @@ interface AgentScoreCore {
|
|
|
280
318
|
* it and the response includes `signer_match` + `signer_sanctions` verdicts in one
|
|
281
319
|
* round trip. */
|
|
282
320
|
signer?: PaymentSigner | null): Promise<EvaluateOutcome>;
|
|
283
|
-
/** Synchronous read of the cached signer verdicts (signer_match + signer_sanctions)
|
|
284
|
-
* populated when the gate's evaluate call was made with a pre-extracted signer. Returns
|
|
285
|
-
* `undefined` when the gate didn't run, the request was operator-token-authenticated,
|
|
286
|
-
* or no signer was extractable (discovery legs). */
|
|
287
|
-
getSignerVerdict(claimedAddress: string): SignerVerdict | undefined;
|
|
288
321
|
/** Report a wallet seen paying under an operator credential. Fire-and-forget; silently
|
|
289
322
|
* swallows non-fatal errors because capture is informational, not on the critical path. */
|
|
290
323
|
captureWallet(options: CaptureWalletOptions): Promise<void>;
|
|
291
324
|
}
|
|
292
|
-
declare function buildAgentMemoryHint(): AgentMemoryHint;
|
|
325
|
+
declare function buildAgentMemoryHint(aipTrustedIssuers?: string[]): AgentMemoryHint;
|
|
293
326
|
declare function createAgentScoreCore(options: AgentScoreCoreOptions): AgentScoreCore;
|
|
294
327
|
|
|
295
328
|
export { type AccountVerification, type AgentIdentity, type AgentMemoryHint, type AgentScoreCore, type AgentScoreCoreOptions, type AssessResult, type CreateSessionOnMissing, type DenialCode, type DenialReason, type EvaluateOutcome, type FailOpenInfraReason, type GateQuotaInfo, type OperatorVerification, type PolicyCheck, type PolicyResult, type SessionMetadata, type SignerVerdict, type VerifyWalletSignerResult, buildAgentMemoryHint, createAgentScoreCore };
|
package/dist/core.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(core_exports, {
|
|
|
24
24
|
createAgentScoreCore: () => createAgentScoreCore
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(core_exports);
|
|
27
|
+
var import_node_crypto = require("crypto");
|
|
27
28
|
var import_sdk = require("@agent-score/sdk");
|
|
28
29
|
|
|
29
30
|
// src/_denial.ts
|
|
@@ -67,7 +68,7 @@ var IDENTITY_VERIFICATION_REQUIRED_FALLBACK_INSTRUCTIONS = JSON.stringify({
|
|
|
67
68
|
var API_ERROR_INSTRUCTIONS = JSON.stringify({
|
|
68
69
|
action: "retry_with_backoff",
|
|
69
70
|
steps: [
|
|
70
|
-
"Verification is temporarily unavailable. Retry the request after 5
|
|
71
|
+
"Verification is temporarily unavailable. Retry the request after 5-30 seconds with exponential backoff.",
|
|
71
72
|
"This is NOT a compliance denial \u2014 the user does not need to re-verify their identity. Send the same identity headers (X-Wallet-Address or X-Operator-Token) on retry.",
|
|
72
73
|
"If the request continues to fail after 3+ retries (~60 seconds total), surface the error to the user with the merchant's support contact."
|
|
73
74
|
],
|
|
@@ -158,7 +159,7 @@ function stripTrailingSlashes(s) {
|
|
|
158
159
|
while (end > 0 && s.charCodeAt(end - 1) === 47) end--;
|
|
159
160
|
return end === s.length ? s : s.slice(0, end);
|
|
160
161
|
}
|
|
161
|
-
var CANONICAL_AGENTSCORE_API = "https://api.agentscore.
|
|
162
|
+
var CANONICAL_AGENTSCORE_API = "https://api.agentscore.com";
|
|
162
163
|
var WALLET_SIGNER_MISMATCH_INSTRUCTIONS = JSON.stringify({
|
|
163
164
|
action: "resign_or_switch_to_operator_token",
|
|
164
165
|
steps: [
|
|
@@ -184,17 +185,22 @@ var INVALID_CREDENTIAL_INSTRUCTIONS = JSON.stringify({
|
|
|
184
185
|
],
|
|
185
186
|
user_message: "The operator_token is not recognized. Use a different stored token, or restart the verification session flow to mint a new one."
|
|
186
187
|
});
|
|
187
|
-
function buildAgentMemoryHint() {
|
|
188
|
+
function buildAgentMemoryHint(aipTrustedIssuers) {
|
|
188
189
|
const api = CANONICAL_AGENTSCORE_API;
|
|
190
|
+
const acceptsAip = aipTrustedIssuers !== void 0 && aipTrustedIssuers.length > 0;
|
|
189
191
|
return {
|
|
190
192
|
save_for_future_agentscore_gates: true,
|
|
191
193
|
pattern_summary: "AgentScore is a cross-merchant identity substrate for agent commerce. Any endpoint that returns 403 missing_identity / identity_verification_required or 402 challenges referencing AgentScore uses the same identity system. One KYC works across all AgentScore merchants \u2014 no re-verification per site. Save this pattern (and the endpoints below) to persistent memory so future AgentScore encounters skip the cold-start session flow.",
|
|
192
|
-
quickstart: "https://docs.agentscore.
|
|
194
|
+
quickstart: "https://docs.agentscore.com/guides/agent-identity",
|
|
193
195
|
identity_check_endpoint: `${api}/v1/credentials`,
|
|
194
196
|
identity_paths: {
|
|
195
197
|
wallet: "If paying from a crypto wallet you have used before on any AgentScore merchant, send `X-Wallet-Address: 0x...`. Shortest path; no token lifecycle to manage.",
|
|
196
|
-
operator_token: "For any rail (Stripe SPT, card, or a wallet you have not linked yet), send `X-Operator-Token: opc_...`. Reusable across merchants until the token expires."
|
|
198
|
+
operator_token: "For any rail (Stripe SPT, card, or a wallet you have not linked yet), send `X-Operator-Token: opc_...`. Reusable across merchants until the token expires.",
|
|
199
|
+
...acceptsAip && {
|
|
200
|
+
agent_identity: 'If you hold an AIP Agent Identity Token from a trusted issuer (see aip_trusted_issuers), present it: send the JWT in an `Agent-Identity` header plus an RFC 9421 HTTP Message Signature (Signature-Input + Signature over @method @authority @path agent-identity, tag="agent-identity") signed with the token-bound cnf key. The merchant verifies it and applies its policy \u2014 no separate AgentScore credential needed.'
|
|
201
|
+
}
|
|
197
202
|
},
|
|
203
|
+
...acceptsAip && { aip_trusted_issuers: aipTrustedIssuers },
|
|
198
204
|
bootstrap: "If you have neither a linked wallet nor a valid operator_token, follow the session/verify flow in the per-request `agent_instructions` block. This happens at most once per agent identity \u2014 after first verification, the operator_token and any subsequently used wallet are reusable everywhere.",
|
|
199
205
|
do_not_persist_in_memory: ["operator_token", "poll_secret"],
|
|
200
206
|
persist_in_credential_store: ["operator_token"]
|
|
@@ -202,7 +208,7 @@ function buildAgentMemoryHint() {
|
|
|
202
208
|
}
|
|
203
209
|
function createAgentScoreCore(options) {
|
|
204
210
|
if (!options.apiKey) {
|
|
205
|
-
throw new Error("AgentScore API key is required. Get one at https://agentscore.
|
|
211
|
+
throw new Error("AgentScore API key is required. Get one at https://www.agentscore.com/sign-up");
|
|
206
212
|
}
|
|
207
213
|
const {
|
|
208
214
|
apiKey,
|
|
@@ -213,14 +219,15 @@ function createAgentScoreCore(options) {
|
|
|
213
219
|
allowedJurisdictions,
|
|
214
220
|
failOpen = false,
|
|
215
221
|
cacheSeconds = 300,
|
|
216
|
-
baseUrl: rawBaseUrl = "https://api.agentscore.
|
|
222
|
+
baseUrl: rawBaseUrl = "https://api.agentscore.com",
|
|
217
223
|
chain: gateChain,
|
|
218
224
|
userAgent,
|
|
219
|
-
createSessionOnMissing
|
|
225
|
+
createSessionOnMissing,
|
|
226
|
+
aipTrustedIssuers
|
|
220
227
|
} = options;
|
|
221
228
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
222
|
-
const agentMemoryHint = buildAgentMemoryHint();
|
|
223
|
-
const defaultUa = `@agent-score/commerce@${"2.
|
|
229
|
+
const agentMemoryHint = buildAgentMemoryHint(aipTrustedIssuers);
|
|
230
|
+
const defaultUa = `@agent-score/commerce@${"2.6.0"}`;
|
|
224
231
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
225
232
|
const sdk = new import_sdk.AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
|
|
226
233
|
const sessionSdkCache = /* @__PURE__ */ new Map();
|
|
@@ -295,16 +302,21 @@ function createAgentScoreCore(options) {
|
|
|
295
302
|
}
|
|
296
303
|
}
|
|
297
304
|
async function evaluate(identity, ctx, signer) {
|
|
298
|
-
if (!identity || !identity.address && !identity.operatorToken) {
|
|
305
|
+
if (!identity || !identity.address?.trim() && !identity.operatorToken?.trim() && !identity.aipToken?.trim()) {
|
|
299
306
|
if (failOpen) return { kind: "allow" };
|
|
300
307
|
const sessionReason = await tryMintSessionDenial(ctx);
|
|
301
308
|
if (sessionReason) return { kind: "deny", reason: sessionReason };
|
|
309
|
+
const acceptsAip = aipTrustedIssuers !== void 0 && aipTrustedIssuers.length > 0;
|
|
310
|
+
const aipStep = acceptsAip ? [
|
|
311
|
+
`If you hold an AIP Agent Identity Token from a trusted issuer (${aipTrustedIssuers.join(", ")}): present it \u2014 send the JWT in an Agent-Identity header plus an RFC 9421 HTTP Message Signature (Signature-Input + Signature over @method @authority @path agent-identity, tag="agent-identity") signed with the token-bound cnf key. This satisfies identity in one round trip without an AgentScore credential.`
|
|
312
|
+
] : [];
|
|
302
313
|
const missingIdentityInstructions = JSON.stringify({
|
|
303
314
|
action: "probe_identity_then_session",
|
|
304
315
|
steps: [
|
|
316
|
+
...aipStep,
|
|
305
317
|
"If you have a wallet AND this merchant accepts a wallet-signing rail (Tempo MPP or x402 \u2014 see openapi.json x-payment-info): send X-Wallet-Address and retry. If the wallet is already linked to an AgentScore operator (via prior SIWE claim or prior captureWallet), this passes in one round trip. If the wallet is unlinked or the account has no KYC, the 403 will include a verify_url \u2014 share it with the user to claim the wallet + complete KYC, then retry.",
|
|
306
318
|
"If step 1 is denied or you already have a stored operator_token (valid + not expired): send X-Operator-Token: opc_... and retry.",
|
|
307
|
-
"If neither applies: retry with NO identity header. Merchants that auto-create verification sessions (most AgentScore merchants do) return verify_url + session_id + poll_secret in the 403 body \u2014 share verify_url with the user, then poll poll_url every 5s with the X-Poll-Secret header until status=verified (the poll returns a one-time operator_token). If the retry returns the same bare 403, this merchant does not support self-service session bootstrapping \u2014 direct the user to https://agentscore.
|
|
319
|
+
"If neither applies: retry with NO identity header. Merchants that auto-create verification sessions (most AgentScore merchants do) return verify_url + session_id + poll_secret in the 403 body \u2014 share verify_url with the user, then poll poll_url every 5s with the X-Poll-Secret header until status=verified (the poll returns a one-time operator_token). If the retry returns the same bare 403, this merchant does not support self-service session bootstrapping \u2014 direct the user to https://www.agentscore.com/sign-up to create an AgentScore identity and mint an operator_token from their dashboard (https://www.agentscore.com/dashboard/verify). The user hands the opc_... to you, and you retry with X-Operator-Token."
|
|
308
320
|
],
|
|
309
321
|
user_message: "Try X-Wallet-Address first if you have a wallet and the merchant accepts Tempo/x402; fall back to a stored X-Operator-Token, then to the session/verify flow described in agent_memory.bootstrap."
|
|
310
322
|
});
|
|
@@ -317,21 +329,26 @@ function createAgentScoreCore(options) {
|
|
|
317
329
|
}
|
|
318
330
|
};
|
|
319
331
|
}
|
|
320
|
-
const
|
|
332
|
+
const identityKey = identity.aipToken ? `aip:${(0, import_node_crypto.createHash)("sha256").update(identity.aipToken).digest("hex")}` : identity.operatorToken?.toLowerCase() ?? (identity.address ? normalizeAddress(identity.address) : "");
|
|
333
|
+
const cacheKey = signer ? JSON.stringify([identityKey, signer.network, normalizeAddress(signer.address)]) : JSON.stringify([identityKey]);
|
|
321
334
|
const cached = cache.get(cacheKey);
|
|
322
335
|
if (cached) {
|
|
336
|
+
const cachedVerdict = cached.raw ? buildSignerVerdict(identity, cached.raw) : void 0;
|
|
323
337
|
if (cached.allow) {
|
|
324
338
|
const cachedRaw = cached.raw;
|
|
325
339
|
const cachedQuota = cachedRaw?.quota;
|
|
326
340
|
return {
|
|
327
341
|
kind: "allow",
|
|
328
342
|
data: cachedRaw,
|
|
329
|
-
...cachedQuota !== void 0 && { quota: cachedQuota }
|
|
343
|
+
...cachedQuota !== void 0 && { quota: cachedQuota },
|
|
344
|
+
...cachedVerdict !== void 0 && { signerVerdict: cachedVerdict }
|
|
330
345
|
};
|
|
331
346
|
}
|
|
332
347
|
if (isFixableDenial(cached.reasons)) {
|
|
333
348
|
const sessionReason = await tryMintSessionDenial(ctx);
|
|
334
|
-
if (sessionReason)
|
|
349
|
+
if (sessionReason) {
|
|
350
|
+
return { kind: "deny", reason: sessionReason, ...cachedVerdict !== void 0 && { signerVerdict: cachedVerdict } };
|
|
351
|
+
}
|
|
335
352
|
}
|
|
336
353
|
return {
|
|
337
354
|
kind: "deny",
|
|
@@ -341,7 +358,8 @@ function createAgentScoreCore(options) {
|
|
|
341
358
|
reasons: cached.reasons,
|
|
342
359
|
verify_url: cached.raw?.verify_url,
|
|
343
360
|
data: cached.raw
|
|
344
|
-
}
|
|
361
|
+
},
|
|
362
|
+
...cachedVerdict !== void 0 && { signerVerdict: cachedVerdict }
|
|
345
363
|
};
|
|
346
364
|
}
|
|
347
365
|
const policy = {};
|
|
@@ -362,7 +380,10 @@ function createAgentScoreCore(options) {
|
|
|
362
380
|
// regardless of policy.require_sanctions_clear (which gates the separate NAME screen).
|
|
363
381
|
...signer && { signer: { address: signer.address, network: signer.network } }
|
|
364
382
|
};
|
|
365
|
-
|
|
383
|
+
if (identity.aipToken !== void 0 && identity.aipSignature === void 0) {
|
|
384
|
+
throw new Error("AgentScoreCore.evaluate: aipToken requires aipSignature (RFC 9421 proof-of-possession material).");
|
|
385
|
+
}
|
|
386
|
+
const result = identity.aipToken !== void 0 && identity.aipSignature !== void 0 ? await sdk.assess(null, { ...opts, aipToken: identity.aipToken, aipSignature: identity.aipSignature }) : identity.address ? await sdk.assess(identity.address, { ...opts, operatorToken: identity.operatorToken }) : await sdk.assess(null, { ...opts, operatorToken: identity.operatorToken });
|
|
366
387
|
data = result;
|
|
367
388
|
} catch (err) {
|
|
368
389
|
if (err instanceof import_sdk.PaymentRequiredError) {
|
|
@@ -433,17 +454,21 @@ function createAgentScoreCore(options) {
|
|
|
433
454
|
const decisionReasons = data.decision_reasons ?? [];
|
|
434
455
|
const allow = decision === "allow" || decision == null;
|
|
435
456
|
cache.set(cacheKey, { allow, decision: decision ?? void 0, reasons: decisionReasons, raw: data });
|
|
457
|
+
const signerVerdict = buildSignerVerdict(identity, data);
|
|
436
458
|
if (allow) {
|
|
437
459
|
const quota = data.quota;
|
|
438
460
|
return {
|
|
439
461
|
kind: "allow",
|
|
440
462
|
data,
|
|
441
|
-
...quota !== void 0 && { quota }
|
|
463
|
+
...quota !== void 0 && { quota },
|
|
464
|
+
...signerVerdict !== void 0 && { signerVerdict }
|
|
442
465
|
};
|
|
443
466
|
}
|
|
444
467
|
if (isFixableDenial(decisionReasons)) {
|
|
445
468
|
const sessionReason = await tryMintSessionDenial(ctx);
|
|
446
|
-
if (sessionReason)
|
|
469
|
+
if (sessionReason) {
|
|
470
|
+
return { kind: "deny", reason: sessionReason, ...signerVerdict !== void 0 && { signerVerdict } };
|
|
471
|
+
}
|
|
447
472
|
}
|
|
448
473
|
return {
|
|
449
474
|
kind: "deny",
|
|
@@ -453,7 +478,8 @@ function createAgentScoreCore(options) {
|
|
|
453
478
|
reasons: decisionReasons,
|
|
454
479
|
verify_url: data.verify_url,
|
|
455
480
|
data
|
|
456
|
-
}
|
|
481
|
+
},
|
|
482
|
+
...signerVerdict !== void 0 && { signerVerdict }
|
|
457
483
|
};
|
|
458
484
|
}
|
|
459
485
|
async function captureWallet(options2) {
|
|
@@ -495,22 +521,21 @@ function createAgentScoreCore(options) {
|
|
|
495
521
|
agentInstructions: sm.agent_instructions ?? WALLET_SIGNER_MISMATCH_INSTRUCTIONS
|
|
496
522
|
};
|
|
497
523
|
}
|
|
498
|
-
function
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
const raw = cached.raw;
|
|
503
|
-
if (!raw) return void 0;
|
|
524
|
+
function buildSignerVerdict(identity, raw) {
|
|
525
|
+
if (identity.address === void 0 || identity.operatorToken !== void 0 || identity.aipToken !== void 0) {
|
|
526
|
+
return void 0;
|
|
527
|
+
}
|
|
504
528
|
const rawMatch = raw.signer_match;
|
|
505
529
|
const rawSanctions = raw.signer_sanctions;
|
|
506
530
|
if (!rawMatch && !rawSanctions) return void 0;
|
|
531
|
+
const claimedNorm = normalizeAddress(identity.address);
|
|
507
532
|
const signerNorm = rawMatch?.actual_signer ?? claimedNorm;
|
|
508
533
|
return {
|
|
509
534
|
signer_match: rawMatch ? projectSignerMatch(rawMatch, claimedNorm, signerNorm) : null,
|
|
510
535
|
signer_sanctions: rawSanctions ?? null
|
|
511
536
|
};
|
|
512
537
|
}
|
|
513
|
-
return { evaluate, captureWallet
|
|
538
|
+
return { evaluate, captureWallet };
|
|
514
539
|
}
|
|
515
540
|
// Annotate the CommonJS export names for ESM import in node:
|
|
516
541
|
0 && (module.exports = {
|