@agent-score/commerce 1.0.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/LICENSE +21 -0
- package/README.md +306 -0
- package/dist/_response-DmziuJz6.d.mts +137 -0
- package/dist/_response-rbK0zM7y.d.ts +137 -0
- package/dist/api/index.d.mts +1 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +37 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/index.mjs +14 -0
- package/dist/api/index.mjs.map +1 -0
- package/dist/challenge/index.d.mts +523 -0
- package/dist/challenge/index.d.ts +523 -0
- package/dist/challenge/index.js +354 -0
- package/dist/challenge/index.js.map +1 -0
- package/dist/challenge/index.mjs +318 -0
- package/dist/challenge/index.mjs.map +1 -0
- package/dist/core.d.mts +252 -0
- package/dist/core.d.ts +252 -0
- package/dist/core.js +500 -0
- package/dist/core.js.map +1 -0
- package/dist/core.mjs +472 -0
- package/dist/core.mjs.map +1 -0
- package/dist/discovery/index.d.mts +382 -0
- package/dist/discovery/index.d.ts +382 -0
- package/dist/discovery/index.js +675 -0
- package/dist/discovery/index.js.map +1 -0
- package/dist/discovery/index.mjs +630 -0
- package/dist/discovery/index.mjs.map +1 -0
- package/dist/identity/express.d.mts +44 -0
- package/dist/identity/express.d.ts +44 -0
- package/dist/identity/express.js +777 -0
- package/dist/identity/express.js.map +1 -0
- package/dist/identity/express.mjs +738 -0
- package/dist/identity/express.mjs.map +1 -0
- package/dist/identity/fastify.d.mts +63 -0
- package/dist/identity/fastify.d.ts +63 -0
- package/dist/identity/fastify.js +780 -0
- package/dist/identity/fastify.js.map +1 -0
- package/dist/identity/fastify.mjs +741 -0
- package/dist/identity/fastify.mjs.map +1 -0
- package/dist/identity/hono.d.mts +83 -0
- package/dist/identity/hono.d.ts +83 -0
- package/dist/identity/hono.js +779 -0
- package/dist/identity/hono.js.map +1 -0
- package/dist/identity/hono.mjs +740 -0
- package/dist/identity/hono.mjs.map +1 -0
- package/dist/identity/nextjs.d.mts +62 -0
- package/dist/identity/nextjs.d.ts +62 -0
- package/dist/identity/nextjs.js +784 -0
- package/dist/identity/nextjs.js.map +1 -0
- package/dist/identity/nextjs.mjs +747 -0
- package/dist/identity/nextjs.mjs.map +1 -0
- package/dist/identity/policy.d.mts +115 -0
- package/dist/identity/policy.d.ts +115 -0
- package/dist/identity/policy.js +81 -0
- package/dist/identity/policy.js.map +1 -0
- package/dist/identity/policy.mjs +53 -0
- package/dist/identity/policy.mjs.map +1 -0
- package/dist/identity/web.d.mts +82 -0
- package/dist/identity/web.d.ts +82 -0
- package/dist/identity/web.js +775 -0
- package/dist/identity/web.js.map +1 -0
- package/dist/identity/web.mjs +738 -0
- package/dist/identity/web.mjs.map +1 -0
- package/dist/index.d.mts +252 -0
- package/dist/index.d.ts +252 -0
- package/dist/index.js +432 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +388 -0
- package/dist/index.mjs.map +1 -0
- package/dist/payment/index.d.mts +716 -0
- package/dist/payment/index.d.ts +716 -0
- package/dist/payment/index.js +691 -0
- package/dist/payment/index.js.map +1 -0
- package/dist/payment/index.mjs +639 -0
- package/dist/payment/index.mjs.map +1 -0
- package/dist/signer-Cvdwn6Cs.d.mts +48 -0
- package/dist/signer-Cvdwn6Cs.d.ts +48 -0
- package/dist/stripe-multichain/index.d.mts +221 -0
- package/dist/stripe-multichain/index.d.ts +221 -0
- package/dist/stripe-multichain/index.js +243 -0
- package/dist/stripe-multichain/index.js.map +1 -0
- package/dist/stripe-multichain/index.mjs +199 -0
- package/dist/stripe-multichain/index.mjs.map +1 -0
- package/dist/wwwauthenticate-CU1eNvMQ.d.mts +37 -0
- package/dist/wwwauthenticate-CU1eNvMQ.d.ts +37 -0
- package/package.json +172 -0
package/dist/core.d.mts
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
interface AgentIdentity {
|
|
2
|
+
address?: string;
|
|
3
|
+
operatorToken?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Session metadata returned from `POST /v1/sessions`. Surfaced to the `onBeforeSession`
|
|
7
|
+
* hook so merchants can correlate an AgentScore session with their own resume token
|
|
8
|
+
* (e.g. a pending-order id).
|
|
9
|
+
*/
|
|
10
|
+
interface SessionMetadata {
|
|
11
|
+
session_id: string;
|
|
12
|
+
verify_url: string;
|
|
13
|
+
poll_secret: string;
|
|
14
|
+
poll_url: string;
|
|
15
|
+
expires_at?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Configuration for auto-creating a verification session when no identity is present.
|
|
19
|
+
*
|
|
20
|
+
* The static `context` / `productName` options are sent on every session request. For
|
|
21
|
+
* per-request context (e.g. the specific product the agent was trying to buy), pass
|
|
22
|
+
* a `getSessionOptions` callback that returns dynamic values; its return is merged
|
|
23
|
+
* over the static defaults.
|
|
24
|
+
*
|
|
25
|
+
* `onBeforeSession` is a side-effect hook that runs after the session is minted but
|
|
26
|
+
* before the 403 is built. Use it to pre-create a reservation/draft/pending-order
|
|
27
|
+
* row in your DB so agents can resume via a merchant-specific id. Return value is
|
|
28
|
+
* merged into `DenialReason.extra`, so it surfaces in both the default 403 body and
|
|
29
|
+
* in a custom `onDenied` handler.
|
|
30
|
+
*/
|
|
31
|
+
interface CreateSessionOnMissing<TCtx = unknown> {
|
|
32
|
+
apiKey: string;
|
|
33
|
+
baseUrl?: string;
|
|
34
|
+
context?: string;
|
|
35
|
+
productName?: string;
|
|
36
|
+
/** Per-request override of `context` / `productName`. Invoked with the framework context. */
|
|
37
|
+
getSessionOptions?: (ctx: TCtx) => Promise<{
|
|
38
|
+
context?: string;
|
|
39
|
+
productName?: string;
|
|
40
|
+
}> | {
|
|
41
|
+
context?: string;
|
|
42
|
+
productName?: string;
|
|
43
|
+
};
|
|
44
|
+
/** Side-effect hook that runs after the session is minted. Return value is merged
|
|
45
|
+
* into `DenialReason.extra` so custom `onDenied` handlers can include merchant-specific
|
|
46
|
+
* fields (e.g. `order_id`) in the 403 response. Hook errors are logged and swallowed —
|
|
47
|
+
* a failing side effect should not block the 403 from reaching the agent. */
|
|
48
|
+
onBeforeSession?: (ctx: TCtx, session: SessionMetadata) => Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
interface AgentScoreCoreOptions {
|
|
51
|
+
/** AgentScore API key. Required. */
|
|
52
|
+
apiKey: string;
|
|
53
|
+
/** Require KYC verification. */
|
|
54
|
+
requireKyc?: boolean;
|
|
55
|
+
/** Require operator to be clear of sanctions. */
|
|
56
|
+
requireSanctionsClear?: boolean;
|
|
57
|
+
/** Minimum operator age bracket (18 or 21). */
|
|
58
|
+
minAge?: number;
|
|
59
|
+
/** List of blocked jurisdictions (blocklist). */
|
|
60
|
+
blockedJurisdictions?: string[];
|
|
61
|
+
/** List of allowed jurisdictions (allowlist — only these pass). */
|
|
62
|
+
allowedJurisdictions?: string[];
|
|
63
|
+
/** If true, allow the request through when the API is unreachable. Defaults to false. */
|
|
64
|
+
failOpen?: boolean;
|
|
65
|
+
/** How long to cache results, in seconds. Defaults to 300. */
|
|
66
|
+
cacheSeconds?: number;
|
|
67
|
+
/** AgentScore API base URL. Defaults to "https://api.agentscore.sh". */
|
|
68
|
+
baseUrl?: string;
|
|
69
|
+
/** Optional chain to filter scoring to. */
|
|
70
|
+
chain?: string;
|
|
71
|
+
/** Prepended to the default User-Agent as `"{userAgent} (@agent-score/commerce@{version})"`. Use to attribute API calls to your app. */
|
|
72
|
+
userAgent?: string;
|
|
73
|
+
/** When set and no identity is found, create a verification session instead of denying immediately. */
|
|
74
|
+
createSessionOnMissing?: CreateSessionOnMissing;
|
|
75
|
+
}
|
|
76
|
+
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';
|
|
77
|
+
/**
|
|
78
|
+
* Cross-merchant pattern hint emitted on bootstrap denials and session-create responses.
|
|
79
|
+
* LLM-hosted agents should persist this to long-term memory so future AgentScore encounters skip
|
|
80
|
+
* the cold-start session flow. Contents are the pattern, not secrets.
|
|
81
|
+
*/
|
|
82
|
+
interface AgentMemoryHint {
|
|
83
|
+
save_for_future_agentscore_gates: true;
|
|
84
|
+
pattern_summary: string;
|
|
85
|
+
quickstart: string;
|
|
86
|
+
identity_check_endpoint: string;
|
|
87
|
+
list_wallets_endpoint?: string;
|
|
88
|
+
identity_paths: {
|
|
89
|
+
wallet: string;
|
|
90
|
+
operator_token: string;
|
|
91
|
+
};
|
|
92
|
+
bootstrap: string;
|
|
93
|
+
do_not_persist_in_memory: string[];
|
|
94
|
+
persist_in_credential_store: string[];
|
|
95
|
+
}
|
|
96
|
+
interface DenialReason {
|
|
97
|
+
code: DenialCode;
|
|
98
|
+
/** Human-readable explanation. When omitted, `denialReasonToBody` substitutes a per-code default. */
|
|
99
|
+
message?: string;
|
|
100
|
+
decision?: string;
|
|
101
|
+
reasons?: string[];
|
|
102
|
+
verify_url?: string;
|
|
103
|
+
session_id?: string;
|
|
104
|
+
poll_secret?: string;
|
|
105
|
+
poll_url?: string;
|
|
106
|
+
agent_instructions?: string;
|
|
107
|
+
/** Cross-merchant memory hint. Emitted on bootstrap denials only by default. */
|
|
108
|
+
agent_memory?: AgentMemoryHint;
|
|
109
|
+
/** Full assess response when the denial came from `/v1/assess`. Lets consumers access fields
|
|
110
|
+
* not promoted to first-class DenialReason properties (e.g., `policy_result`). Undefined for
|
|
111
|
+
* denials that did not originate from an assess call (missing_identity, api_error,
|
|
112
|
+
* payment_required, identity_verification_required). */
|
|
113
|
+
data?: AgentScoreData;
|
|
114
|
+
/** Extra fields returned from the `createSessionOnMissing.onBeforeSession` hook. Merged
|
|
115
|
+
* into the default 403 body; custom `onDenied` handlers can spread these into their own
|
|
116
|
+
* response shape (e.g. to include a merchant-minted `order_id`). */
|
|
117
|
+
extra?: Record<string, unknown>;
|
|
118
|
+
/** Operator id resolved from `X-Wallet-Address`. */
|
|
119
|
+
claimed_operator?: string;
|
|
120
|
+
/** Operator id the actual payment signer resolves to. `null` when the signer wallet isn't
|
|
121
|
+
* linked to any operator (treat as a different identity). */
|
|
122
|
+
actual_signer_operator?: string | null;
|
|
123
|
+
/** The wallet the agent claimed via header. Echoed back for self-correction. */
|
|
124
|
+
expected_signer?: string;
|
|
125
|
+
/** The wallet that actually signed the payment. */
|
|
126
|
+
actual_signer?: string;
|
|
127
|
+
/** Wallets the claimed operator could sign with (if enumerable). Present when non-empty. */
|
|
128
|
+
linked_wallets?: string[];
|
|
129
|
+
}
|
|
130
|
+
interface AgentScoreData {
|
|
131
|
+
decision: string | null;
|
|
132
|
+
decision_reasons: string[];
|
|
133
|
+
identity_method?: string;
|
|
134
|
+
operator_verification?: {
|
|
135
|
+
level: string;
|
|
136
|
+
operator_type: string | null;
|
|
137
|
+
verified_at: string | null;
|
|
138
|
+
};
|
|
139
|
+
/** Account-level KYC facts that apply to every operator under the same account.
|
|
140
|
+
* Populated when the API returns account_verification (post-KYC operator). */
|
|
141
|
+
account_verification?: {
|
|
142
|
+
kyc_level?: string;
|
|
143
|
+
sanctions_clear?: boolean;
|
|
144
|
+
age_bracket?: string;
|
|
145
|
+
jurisdiction?: string;
|
|
146
|
+
verified_at?: string | null;
|
|
147
|
+
};
|
|
148
|
+
resolved_operator?: string | null;
|
|
149
|
+
/** Wallets linked to the same operator as the resolved identity. Capped at 100 entries
|
|
150
|
+
* by the API. Useful for advertising in 402 challenges so wallet-auth agents know which
|
|
151
|
+
* alt-signers will satisfy `wallet_signer_mismatch`. */
|
|
152
|
+
linked_wallets?: string[];
|
|
153
|
+
verify_url?: string;
|
|
154
|
+
policy_result?: {
|
|
155
|
+
all_passed: boolean;
|
|
156
|
+
checks: Array<{
|
|
157
|
+
rule: string;
|
|
158
|
+
passed: boolean;
|
|
159
|
+
required?: unknown;
|
|
160
|
+
actual?: unknown;
|
|
161
|
+
}>;
|
|
162
|
+
} | null;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Outcome from `AgentScoreCore.evaluate()`. Adapters map this to framework-specific responses.
|
|
166
|
+
*
|
|
167
|
+
* - `{ kind: 'allow', data }` — the request passed the policy. `data` is present on a normal
|
|
168
|
+
* allow; `undefined` when fail-open short-circuited (identity missing, API unreachable,
|
|
169
|
+
* timeout, or 402 paid-tier required).
|
|
170
|
+
* - `{ kind: 'deny', reason }` — the request was denied. Adapters should render a 403 with the
|
|
171
|
+
* reason, or invoke the caller's custom denial handler.
|
|
172
|
+
*/
|
|
173
|
+
type EvaluateOutcome = {
|
|
174
|
+
kind: 'allow';
|
|
175
|
+
data?: AgentScoreData;
|
|
176
|
+
} | {
|
|
177
|
+
kind: 'deny';
|
|
178
|
+
reason: DenialReason;
|
|
179
|
+
};
|
|
180
|
+
interface CaptureWalletOptions {
|
|
181
|
+
/** Operator credential (`opc_...`) that the agent authenticated with. */
|
|
182
|
+
operatorToken: string;
|
|
183
|
+
/** Signer wallet recovered from the payment payload. */
|
|
184
|
+
walletAddress: string;
|
|
185
|
+
/** Key-derivation family — `"evm"` for any EVM chain, `"solana"` for Solana. */
|
|
186
|
+
network: 'evm' | 'solana';
|
|
187
|
+
/** Optional stable key for the logical payment (e.g., payment intent id, tx hash). When the
|
|
188
|
+
* same key is seen again for the same (credential, wallet, network), the server no-ops —
|
|
189
|
+
* prevents agent retries from inflating transaction_count. */
|
|
190
|
+
idempotencyKey?: string;
|
|
191
|
+
}
|
|
192
|
+
interface VerifyWalletSignerMatchOptions {
|
|
193
|
+
/** The wallet claimed via `X-Wallet-Address`. */
|
|
194
|
+
claimedWallet: string;
|
|
195
|
+
/** The signer wallet recovered from the payment credential. `null` means the rail carries
|
|
196
|
+
* no wallet signer (SPT, card) — the helper returns `wallet_auth_requires_wallet_signing`. */
|
|
197
|
+
signer: string | null;
|
|
198
|
+
/** Network of the signer. EVM covers every EVM chain; `solana` lives in its own namespace. */
|
|
199
|
+
network?: 'evm' | 'solana';
|
|
200
|
+
}
|
|
201
|
+
type VerifyWalletSignerResult = {
|
|
202
|
+
kind: 'pass';
|
|
203
|
+
claimedOperator: string | null;
|
|
204
|
+
signerOperator: string | null;
|
|
205
|
+
} | {
|
|
206
|
+
kind: 'wallet_signer_mismatch';
|
|
207
|
+
claimedOperator: string | null;
|
|
208
|
+
actualSignerOperator: string | null;
|
|
209
|
+
expectedSigner: string;
|
|
210
|
+
actualSigner: string;
|
|
211
|
+
linkedWallets: string[];
|
|
212
|
+
/** JSON-encoded action copy (action + steps + user_message). Spread into the 403 body
|
|
213
|
+
* verbatim so agents get a concrete recovery path inside the denial response itself. */
|
|
214
|
+
agentInstructions: string;
|
|
215
|
+
} | {
|
|
216
|
+
kind: 'wallet_auth_requires_wallet_signing';
|
|
217
|
+
claimedWallet: string;
|
|
218
|
+
agentInstructions: string;
|
|
219
|
+
} | {
|
|
220
|
+
kind: 'api_error';
|
|
221
|
+
claimedWallet: string;
|
|
222
|
+
};
|
|
223
|
+
interface AgentScoreCore {
|
|
224
|
+
/**
|
|
225
|
+
* Evaluate the request's identity against the configured policy.
|
|
226
|
+
* @param identity - extracted identity (wallet address and/or operator token)
|
|
227
|
+
* @param ctx - optional framework-specific context (Hono c, Express req, etc.) passed
|
|
228
|
+
* through to `createSessionOnMissing` hooks. Opaque to core.
|
|
229
|
+
*/
|
|
230
|
+
evaluate(identity: AgentIdentity | undefined, ctx?: unknown): Promise<EvaluateOutcome>;
|
|
231
|
+
/** Report a wallet seen paying under an operator credential. Fire-and-forget; silently
|
|
232
|
+
* swallows non-fatal errors because capture is informational, not on the critical path. */
|
|
233
|
+
captureWallet(options: CaptureWalletOptions): Promise<void>;
|
|
234
|
+
/**
|
|
235
|
+
* Verify the payment signer resolves to the same operator as the claimed `X-Wallet-Address`.
|
|
236
|
+
*
|
|
237
|
+
* Returns `pass` when the signer is linked to the same operator as the claimed wallet
|
|
238
|
+
* (byte-equal wallets pass trivially; other wallets linked to the same operator also pass —
|
|
239
|
+
* multi-wallet agents work without ergonomic pain). Returns `wallet_signer_mismatch` when
|
|
240
|
+
* the signer resolves to a different (or no) operator. Returns `wallet_auth_requires_wallet_signing`
|
|
241
|
+
* when the signer is `null` (SPT, card — rails that carry no wallet signature).
|
|
242
|
+
*
|
|
243
|
+
* Call this AFTER the gate evaluates (so the claimed wallet's operator is cached) and
|
|
244
|
+
* AFTER the payment credential is parsed (so the signer is known). Merchants should call
|
|
245
|
+
* it before settling payment.
|
|
246
|
+
*/
|
|
247
|
+
verifyWalletSignerMatch(options: VerifyWalletSignerMatchOptions): Promise<VerifyWalletSignerResult>;
|
|
248
|
+
}
|
|
249
|
+
declare function buildAgentMemoryHint(): AgentMemoryHint;
|
|
250
|
+
declare function createAgentScoreCore(options: AgentScoreCoreOptions): AgentScoreCore;
|
|
251
|
+
|
|
252
|
+
export { type AgentIdentity, type AgentMemoryHint, type AgentScoreCore, type AgentScoreCoreOptions, type AgentScoreData, type CaptureWalletOptions, type CreateSessionOnMissing, type DenialCode, type DenialReason, type EvaluateOutcome, type SessionMetadata, type VerifyWalletSignerMatchOptions, type VerifyWalletSignerResult, buildAgentMemoryHint, createAgentScoreCore };
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
interface AgentIdentity {
|
|
2
|
+
address?: string;
|
|
3
|
+
operatorToken?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Session metadata returned from `POST /v1/sessions`. Surfaced to the `onBeforeSession`
|
|
7
|
+
* hook so merchants can correlate an AgentScore session with their own resume token
|
|
8
|
+
* (e.g. a pending-order id).
|
|
9
|
+
*/
|
|
10
|
+
interface SessionMetadata {
|
|
11
|
+
session_id: string;
|
|
12
|
+
verify_url: string;
|
|
13
|
+
poll_secret: string;
|
|
14
|
+
poll_url: string;
|
|
15
|
+
expires_at?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Configuration for auto-creating a verification session when no identity is present.
|
|
19
|
+
*
|
|
20
|
+
* The static `context` / `productName` options are sent on every session request. For
|
|
21
|
+
* per-request context (e.g. the specific product the agent was trying to buy), pass
|
|
22
|
+
* a `getSessionOptions` callback that returns dynamic values; its return is merged
|
|
23
|
+
* over the static defaults.
|
|
24
|
+
*
|
|
25
|
+
* `onBeforeSession` is a side-effect hook that runs after the session is minted but
|
|
26
|
+
* before the 403 is built. Use it to pre-create a reservation/draft/pending-order
|
|
27
|
+
* row in your DB so agents can resume via a merchant-specific id. Return value is
|
|
28
|
+
* merged into `DenialReason.extra`, so it surfaces in both the default 403 body and
|
|
29
|
+
* in a custom `onDenied` handler.
|
|
30
|
+
*/
|
|
31
|
+
interface CreateSessionOnMissing<TCtx = unknown> {
|
|
32
|
+
apiKey: string;
|
|
33
|
+
baseUrl?: string;
|
|
34
|
+
context?: string;
|
|
35
|
+
productName?: string;
|
|
36
|
+
/** Per-request override of `context` / `productName`. Invoked with the framework context. */
|
|
37
|
+
getSessionOptions?: (ctx: TCtx) => Promise<{
|
|
38
|
+
context?: string;
|
|
39
|
+
productName?: string;
|
|
40
|
+
}> | {
|
|
41
|
+
context?: string;
|
|
42
|
+
productName?: string;
|
|
43
|
+
};
|
|
44
|
+
/** Side-effect hook that runs after the session is minted. Return value is merged
|
|
45
|
+
* into `DenialReason.extra` so custom `onDenied` handlers can include merchant-specific
|
|
46
|
+
* fields (e.g. `order_id`) in the 403 response. Hook errors are logged and swallowed —
|
|
47
|
+
* a failing side effect should not block the 403 from reaching the agent. */
|
|
48
|
+
onBeforeSession?: (ctx: TCtx, session: SessionMetadata) => Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
interface AgentScoreCoreOptions {
|
|
51
|
+
/** AgentScore API key. Required. */
|
|
52
|
+
apiKey: string;
|
|
53
|
+
/** Require KYC verification. */
|
|
54
|
+
requireKyc?: boolean;
|
|
55
|
+
/** Require operator to be clear of sanctions. */
|
|
56
|
+
requireSanctionsClear?: boolean;
|
|
57
|
+
/** Minimum operator age bracket (18 or 21). */
|
|
58
|
+
minAge?: number;
|
|
59
|
+
/** List of blocked jurisdictions (blocklist). */
|
|
60
|
+
blockedJurisdictions?: string[];
|
|
61
|
+
/** List of allowed jurisdictions (allowlist — only these pass). */
|
|
62
|
+
allowedJurisdictions?: string[];
|
|
63
|
+
/** If true, allow the request through when the API is unreachable. Defaults to false. */
|
|
64
|
+
failOpen?: boolean;
|
|
65
|
+
/** How long to cache results, in seconds. Defaults to 300. */
|
|
66
|
+
cacheSeconds?: number;
|
|
67
|
+
/** AgentScore API base URL. Defaults to "https://api.agentscore.sh". */
|
|
68
|
+
baseUrl?: string;
|
|
69
|
+
/** Optional chain to filter scoring to. */
|
|
70
|
+
chain?: string;
|
|
71
|
+
/** Prepended to the default User-Agent as `"{userAgent} (@agent-score/commerce@{version})"`. Use to attribute API calls to your app. */
|
|
72
|
+
userAgent?: string;
|
|
73
|
+
/** When set and no identity is found, create a verification session instead of denying immediately. */
|
|
74
|
+
createSessionOnMissing?: CreateSessionOnMissing;
|
|
75
|
+
}
|
|
76
|
+
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';
|
|
77
|
+
/**
|
|
78
|
+
* Cross-merchant pattern hint emitted on bootstrap denials and session-create responses.
|
|
79
|
+
* LLM-hosted agents should persist this to long-term memory so future AgentScore encounters skip
|
|
80
|
+
* the cold-start session flow. Contents are the pattern, not secrets.
|
|
81
|
+
*/
|
|
82
|
+
interface AgentMemoryHint {
|
|
83
|
+
save_for_future_agentscore_gates: true;
|
|
84
|
+
pattern_summary: string;
|
|
85
|
+
quickstart: string;
|
|
86
|
+
identity_check_endpoint: string;
|
|
87
|
+
list_wallets_endpoint?: string;
|
|
88
|
+
identity_paths: {
|
|
89
|
+
wallet: string;
|
|
90
|
+
operator_token: string;
|
|
91
|
+
};
|
|
92
|
+
bootstrap: string;
|
|
93
|
+
do_not_persist_in_memory: string[];
|
|
94
|
+
persist_in_credential_store: string[];
|
|
95
|
+
}
|
|
96
|
+
interface DenialReason {
|
|
97
|
+
code: DenialCode;
|
|
98
|
+
/** Human-readable explanation. When omitted, `denialReasonToBody` substitutes a per-code default. */
|
|
99
|
+
message?: string;
|
|
100
|
+
decision?: string;
|
|
101
|
+
reasons?: string[];
|
|
102
|
+
verify_url?: string;
|
|
103
|
+
session_id?: string;
|
|
104
|
+
poll_secret?: string;
|
|
105
|
+
poll_url?: string;
|
|
106
|
+
agent_instructions?: string;
|
|
107
|
+
/** Cross-merchant memory hint. Emitted on bootstrap denials only by default. */
|
|
108
|
+
agent_memory?: AgentMemoryHint;
|
|
109
|
+
/** Full assess response when the denial came from `/v1/assess`. Lets consumers access fields
|
|
110
|
+
* not promoted to first-class DenialReason properties (e.g., `policy_result`). Undefined for
|
|
111
|
+
* denials that did not originate from an assess call (missing_identity, api_error,
|
|
112
|
+
* payment_required, identity_verification_required). */
|
|
113
|
+
data?: AgentScoreData;
|
|
114
|
+
/** Extra fields returned from the `createSessionOnMissing.onBeforeSession` hook. Merged
|
|
115
|
+
* into the default 403 body; custom `onDenied` handlers can spread these into their own
|
|
116
|
+
* response shape (e.g. to include a merchant-minted `order_id`). */
|
|
117
|
+
extra?: Record<string, unknown>;
|
|
118
|
+
/** Operator id resolved from `X-Wallet-Address`. */
|
|
119
|
+
claimed_operator?: string;
|
|
120
|
+
/** Operator id the actual payment signer resolves to. `null` when the signer wallet isn't
|
|
121
|
+
* linked to any operator (treat as a different identity). */
|
|
122
|
+
actual_signer_operator?: string | null;
|
|
123
|
+
/** The wallet the agent claimed via header. Echoed back for self-correction. */
|
|
124
|
+
expected_signer?: string;
|
|
125
|
+
/** The wallet that actually signed the payment. */
|
|
126
|
+
actual_signer?: string;
|
|
127
|
+
/** Wallets the claimed operator could sign with (if enumerable). Present when non-empty. */
|
|
128
|
+
linked_wallets?: string[];
|
|
129
|
+
}
|
|
130
|
+
interface AgentScoreData {
|
|
131
|
+
decision: string | null;
|
|
132
|
+
decision_reasons: string[];
|
|
133
|
+
identity_method?: string;
|
|
134
|
+
operator_verification?: {
|
|
135
|
+
level: string;
|
|
136
|
+
operator_type: string | null;
|
|
137
|
+
verified_at: string | null;
|
|
138
|
+
};
|
|
139
|
+
/** Account-level KYC facts that apply to every operator under the same account.
|
|
140
|
+
* Populated when the API returns account_verification (post-KYC operator). */
|
|
141
|
+
account_verification?: {
|
|
142
|
+
kyc_level?: string;
|
|
143
|
+
sanctions_clear?: boolean;
|
|
144
|
+
age_bracket?: string;
|
|
145
|
+
jurisdiction?: string;
|
|
146
|
+
verified_at?: string | null;
|
|
147
|
+
};
|
|
148
|
+
resolved_operator?: string | null;
|
|
149
|
+
/** Wallets linked to the same operator as the resolved identity. Capped at 100 entries
|
|
150
|
+
* by the API. Useful for advertising in 402 challenges so wallet-auth agents know which
|
|
151
|
+
* alt-signers will satisfy `wallet_signer_mismatch`. */
|
|
152
|
+
linked_wallets?: string[];
|
|
153
|
+
verify_url?: string;
|
|
154
|
+
policy_result?: {
|
|
155
|
+
all_passed: boolean;
|
|
156
|
+
checks: Array<{
|
|
157
|
+
rule: string;
|
|
158
|
+
passed: boolean;
|
|
159
|
+
required?: unknown;
|
|
160
|
+
actual?: unknown;
|
|
161
|
+
}>;
|
|
162
|
+
} | null;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Outcome from `AgentScoreCore.evaluate()`. Adapters map this to framework-specific responses.
|
|
166
|
+
*
|
|
167
|
+
* - `{ kind: 'allow', data }` — the request passed the policy. `data` is present on a normal
|
|
168
|
+
* allow; `undefined` when fail-open short-circuited (identity missing, API unreachable,
|
|
169
|
+
* timeout, or 402 paid-tier required).
|
|
170
|
+
* - `{ kind: 'deny', reason }` — the request was denied. Adapters should render a 403 with the
|
|
171
|
+
* reason, or invoke the caller's custom denial handler.
|
|
172
|
+
*/
|
|
173
|
+
type EvaluateOutcome = {
|
|
174
|
+
kind: 'allow';
|
|
175
|
+
data?: AgentScoreData;
|
|
176
|
+
} | {
|
|
177
|
+
kind: 'deny';
|
|
178
|
+
reason: DenialReason;
|
|
179
|
+
};
|
|
180
|
+
interface CaptureWalletOptions {
|
|
181
|
+
/** Operator credential (`opc_...`) that the agent authenticated with. */
|
|
182
|
+
operatorToken: string;
|
|
183
|
+
/** Signer wallet recovered from the payment payload. */
|
|
184
|
+
walletAddress: string;
|
|
185
|
+
/** Key-derivation family — `"evm"` for any EVM chain, `"solana"` for Solana. */
|
|
186
|
+
network: 'evm' | 'solana';
|
|
187
|
+
/** Optional stable key for the logical payment (e.g., payment intent id, tx hash). When the
|
|
188
|
+
* same key is seen again for the same (credential, wallet, network), the server no-ops —
|
|
189
|
+
* prevents agent retries from inflating transaction_count. */
|
|
190
|
+
idempotencyKey?: string;
|
|
191
|
+
}
|
|
192
|
+
interface VerifyWalletSignerMatchOptions {
|
|
193
|
+
/** The wallet claimed via `X-Wallet-Address`. */
|
|
194
|
+
claimedWallet: string;
|
|
195
|
+
/** The signer wallet recovered from the payment credential. `null` means the rail carries
|
|
196
|
+
* no wallet signer (SPT, card) — the helper returns `wallet_auth_requires_wallet_signing`. */
|
|
197
|
+
signer: string | null;
|
|
198
|
+
/** Network of the signer. EVM covers every EVM chain; `solana` lives in its own namespace. */
|
|
199
|
+
network?: 'evm' | 'solana';
|
|
200
|
+
}
|
|
201
|
+
type VerifyWalletSignerResult = {
|
|
202
|
+
kind: 'pass';
|
|
203
|
+
claimedOperator: string | null;
|
|
204
|
+
signerOperator: string | null;
|
|
205
|
+
} | {
|
|
206
|
+
kind: 'wallet_signer_mismatch';
|
|
207
|
+
claimedOperator: string | null;
|
|
208
|
+
actualSignerOperator: string | null;
|
|
209
|
+
expectedSigner: string;
|
|
210
|
+
actualSigner: string;
|
|
211
|
+
linkedWallets: string[];
|
|
212
|
+
/** JSON-encoded action copy (action + steps + user_message). Spread into the 403 body
|
|
213
|
+
* verbatim so agents get a concrete recovery path inside the denial response itself. */
|
|
214
|
+
agentInstructions: string;
|
|
215
|
+
} | {
|
|
216
|
+
kind: 'wallet_auth_requires_wallet_signing';
|
|
217
|
+
claimedWallet: string;
|
|
218
|
+
agentInstructions: string;
|
|
219
|
+
} | {
|
|
220
|
+
kind: 'api_error';
|
|
221
|
+
claimedWallet: string;
|
|
222
|
+
};
|
|
223
|
+
interface AgentScoreCore {
|
|
224
|
+
/**
|
|
225
|
+
* Evaluate the request's identity against the configured policy.
|
|
226
|
+
* @param identity - extracted identity (wallet address and/or operator token)
|
|
227
|
+
* @param ctx - optional framework-specific context (Hono c, Express req, etc.) passed
|
|
228
|
+
* through to `createSessionOnMissing` hooks. Opaque to core.
|
|
229
|
+
*/
|
|
230
|
+
evaluate(identity: AgentIdentity | undefined, ctx?: unknown): Promise<EvaluateOutcome>;
|
|
231
|
+
/** Report a wallet seen paying under an operator credential. Fire-and-forget; silently
|
|
232
|
+
* swallows non-fatal errors because capture is informational, not on the critical path. */
|
|
233
|
+
captureWallet(options: CaptureWalletOptions): Promise<void>;
|
|
234
|
+
/**
|
|
235
|
+
* Verify the payment signer resolves to the same operator as the claimed `X-Wallet-Address`.
|
|
236
|
+
*
|
|
237
|
+
* Returns `pass` when the signer is linked to the same operator as the claimed wallet
|
|
238
|
+
* (byte-equal wallets pass trivially; other wallets linked to the same operator also pass —
|
|
239
|
+
* multi-wallet agents work without ergonomic pain). Returns `wallet_signer_mismatch` when
|
|
240
|
+
* the signer resolves to a different (or no) operator. Returns `wallet_auth_requires_wallet_signing`
|
|
241
|
+
* when the signer is `null` (SPT, card — rails that carry no wallet signature).
|
|
242
|
+
*
|
|
243
|
+
* Call this AFTER the gate evaluates (so the claimed wallet's operator is cached) and
|
|
244
|
+
* AFTER the payment credential is parsed (so the signer is known). Merchants should call
|
|
245
|
+
* it before settling payment.
|
|
246
|
+
*/
|
|
247
|
+
verifyWalletSignerMatch(options: VerifyWalletSignerMatchOptions): Promise<VerifyWalletSignerResult>;
|
|
248
|
+
}
|
|
249
|
+
declare function buildAgentMemoryHint(): AgentMemoryHint;
|
|
250
|
+
declare function createAgentScoreCore(options: AgentScoreCoreOptions): AgentScoreCore;
|
|
251
|
+
|
|
252
|
+
export { type AgentIdentity, type AgentMemoryHint, type AgentScoreCore, type AgentScoreCoreOptions, type AgentScoreData, type CaptureWalletOptions, type CreateSessionOnMissing, type DenialCode, type DenialReason, type EvaluateOutcome, type SessionMetadata, type VerifyWalletSignerMatchOptions, type VerifyWalletSignerResult, buildAgentMemoryHint, createAgentScoreCore };
|