@agent-score/commerce 1.7.0 → 1.8.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 +3 -3
- package/dist/{_response-DpB-cm2c.d.mts → _response-BMt2y4Or.d.mts} +11 -8
- package/dist/{_response-C2yFQoIA.d.ts → _response-DyJ3mWI3.d.ts} +11 -8
- package/dist/challenge/index.d.mts +2 -1
- package/dist/challenge/index.d.ts +2 -1
- package/dist/challenge/index.js.map +1 -1
- package/dist/challenge/index.mjs.map +1 -1
- package/dist/core.d.mts +36 -27
- package/dist/core.d.ts +36 -27
- package/dist/core.js +21 -101
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +21 -101
- package/dist/core.mjs.map +1 -1
- package/dist/identity/express.d.mts +12 -13
- package/dist/identity/express.d.ts +12 -13
- package/dist/identity/express.js +38 -121
- package/dist/identity/express.js.map +1 -1
- package/dist/identity/express.mjs +36 -118
- package/dist/identity/express.mjs.map +1 -1
- package/dist/identity/fastify.d.mts +12 -11
- package/dist/identity/fastify.d.ts +12 -11
- package/dist/identity/fastify.js +38 -121
- package/dist/identity/fastify.js.map +1 -1
- package/dist/identity/fastify.mjs +36 -118
- package/dist/identity/fastify.mjs.map +1 -1
- package/dist/identity/hono.d.mts +13 -28
- package/dist/identity/hono.d.ts +13 -28
- package/dist/identity/hono.js +31 -123
- package/dist/identity/hono.js.map +1 -1
- package/dist/identity/hono.mjs +29 -120
- package/dist/identity/hono.mjs.map +1 -1
- package/dist/identity/nextjs.d.mts +8 -7
- package/dist/identity/nextjs.d.ts +8 -7
- package/dist/identity/nextjs.js +27 -119
- package/dist/identity/nextjs.js.map +1 -1
- package/dist/identity/nextjs.mjs +27 -118
- package/dist/identity/nextjs.mjs.map +1 -1
- package/dist/identity/policy.d.mts +1 -0
- package/dist/identity/policy.d.ts +1 -0
- package/dist/identity/web.d.mts +12 -14
- package/dist/identity/web.d.ts +12 -14
- package/dist/identity/web.js +27 -119
- package/dist/identity/web.js.map +1 -1
- package/dist/identity/web.mjs +27 -118
- package/dist/identity/web.mjs.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -6
- 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.map +1 -1
- package/dist/payment/index.mjs.map +1 -1
- package/dist/{signer-kCAJUZwp.d.mts → signer-CFVQsWjL.d.mts} +1 -6
- package/dist/{signer-kCAJUZwp.d.ts → signer-CFVQsWjL.d.ts} +1 -6
- package/package.json +6 -6
package/dist/identity/hono.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { F as FIXABLE_DENIAL_REASONS, b as buildContactSupportNextSteps, a as buildSignerMismatchBody, d as denialReasonStatus, c as denialReasonToBody, i as isFixableDenial, v as verificationAgentInstructions } from '../_response-
|
|
2
|
-
export {
|
|
3
|
-
import { AgentScoreCoreOptions, AgentIdentity, DenialReason, CreateSessionOnMissing, AssessResult, FailOpenInfraReason, GateQuotaInfo,
|
|
1
|
+
export { F as FIXABLE_DENIAL_REASONS, b as buildContactSupportNextSteps, a as buildSignerMismatchBody, d as denialReasonStatus, c as denialReasonToBody, i as isFixableDenial, v as verificationAgentInstructions } from '../_response-DyJ3mWI3.js';
|
|
2
|
+
export { r as readX402PaymentHeader } from '../signer-CFVQsWjL.js';
|
|
3
|
+
import { AgentScoreCoreOptions, AgentIdentity, DenialReason, CreateSessionOnMissing, AssessResult, FailOpenInfraReason, GateQuotaInfo, SignerVerdict } from '../core.js';
|
|
4
4
|
import { Context, MiddlewareHandler } from 'hono';
|
|
5
5
|
|
|
6
6
|
interface AgentScoreGateOptions extends Omit<AgentScoreCoreOptions, 'createSessionOnMissing'> {
|
|
@@ -72,32 +72,17 @@ declare function captureWallet(c: Context, options: {
|
|
|
72
72
|
idempotencyKey?: string;
|
|
73
73
|
}): Promise<void>;
|
|
74
74
|
/**
|
|
75
|
-
*
|
|
75
|
+
* Synchronous read of the cached signer verdicts (`signer_match` wallet-binding +
|
|
76
|
+
* `signer_sanctions` OFAC SDN wallet-address check). Both verdicts were composed by the
|
|
77
|
+
* gate's primary `/v1/assess` call on this request — single round trip, no extra API call.
|
|
76
78
|
*
|
|
77
|
-
*
|
|
79
|
+
* Returns `undefined` when the gate didn't run, the request was operator-token-only, or
|
|
80
|
+
* no payment credential was attached (discovery legs).
|
|
78
81
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* agent should switch to `X-Operator-Token`
|
|
83
|
-
*
|
|
84
|
-
* No-ops (returns `pass` with `claimedOperator: null`) when the request was operator-token
|
|
85
|
-
* authenticated — signer-match only applies to wallet-auth.
|
|
86
|
-
*
|
|
87
|
-
* The helper auto-extracts the signer from MPP (`Authorization: Payment`) or x402
|
|
88
|
-
* (`payment-signature` / `x-payment`) headers. Pass `options.signer` explicitly to override.
|
|
89
|
-
*
|
|
90
|
-
* ```ts
|
|
91
|
-
* app.post('/purchase', async (c) => {
|
|
92
|
-
* const result = await verifyWalletSignerMatch(c);
|
|
93
|
-
* if (result.kind !== 'pass') return c.json({ error: result.kind, ...result }, 403);
|
|
94
|
-
* // ... proceed with settlement ...
|
|
95
|
-
* });
|
|
96
|
-
* ```
|
|
82
|
+
* Under `policy.require_sanctions_clear`, an OFAC SDN hit (or unavailable lookup) is
|
|
83
|
+
* already enforced by the gate (decision → deny before the handler runs); merchant code
|
|
84
|
+
* typically only needs this getter for the `signer_match` wallet-binding verdict.
|
|
97
85
|
*/
|
|
98
|
-
declare function
|
|
99
|
-
signer?: string | null;
|
|
100
|
-
network?: 'evm' | 'solana';
|
|
101
|
-
}): Promise<VerifyWalletSignerResult>;
|
|
86
|
+
declare function getSignerVerdict(c: Context): SignerVerdict | undefined;
|
|
102
87
|
|
|
103
|
-
export { type AgentScoreGateOptions, agentscoreGate, captureWallet, getAgentScoreData, getGateDegradedState, getGateQuotaInfo,
|
|
88
|
+
export { type AgentScoreGateOptions, agentscoreGate, captureWallet, getAgentScoreData, getGateDegradedState, getGateQuotaInfo, getSignerVerdict };
|
package/dist/identity/hono.js
CHANGED
|
@@ -27,14 +27,13 @@ __export(hono_exports, {
|
|
|
27
27
|
captureWallet: () => captureWallet,
|
|
28
28
|
denialReasonStatus: () => denialReasonStatus,
|
|
29
29
|
denialReasonToBody: () => denialReasonToBody,
|
|
30
|
-
extractPaymentSignerAddress: () => extractPaymentSignerAddress,
|
|
31
30
|
getAgentScoreData: () => getAgentScoreData,
|
|
32
31
|
getGateDegradedState: () => getGateDegradedState,
|
|
33
32
|
getGateQuotaInfo: () => getGateQuotaInfo,
|
|
33
|
+
getSignerVerdict: () => getSignerVerdict,
|
|
34
34
|
isFixableDenial: () => isFixableDenial,
|
|
35
35
|
readX402PaymentHeader: () => readX402PaymentHeader,
|
|
36
|
-
verificationAgentInstructions: () => verificationAgentInstructions
|
|
37
|
-
verifyWalletSignerMatch: () => verifyWalletSignerMatch
|
|
36
|
+
verificationAgentInstructions: () => verificationAgentInstructions
|
|
38
37
|
});
|
|
39
38
|
module.exports = __toCommonJS(hono_exports);
|
|
40
39
|
|
|
@@ -55,7 +54,7 @@ function denialReasonStatus(reason) {
|
|
|
55
54
|
}
|
|
56
55
|
function buildSignerMismatchBody(input) {
|
|
57
56
|
const { result } = input;
|
|
58
|
-
if (result.kind === "pass"
|
|
57
|
+
if (result.kind === "pass") return null;
|
|
59
58
|
const learnMoreUrl = input.learnMoreUrl ?? "https://docs.agentscore.sh/guides/agent-identity";
|
|
60
59
|
if (result.kind === "wallet_signer_mismatch") {
|
|
61
60
|
const linkedWallets = result.linkedWallets ?? [];
|
|
@@ -365,7 +364,7 @@ function createAgentScoreCore(options) {
|
|
|
365
364
|
} = options;
|
|
366
365
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
367
366
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
368
|
-
const defaultUa = `@agent-score/commerce@${"1.
|
|
367
|
+
const defaultUa = `@agent-score/commerce@${"1.8.0"}`;
|
|
369
368
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
370
369
|
const sdk = new import_sdk.AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
|
|
371
370
|
const sessionSdkCache = /* @__PURE__ */ new Map();
|
|
@@ -439,7 +438,7 @@ function createAgentScoreCore(options) {
|
|
|
439
438
|
return void 0;
|
|
440
439
|
}
|
|
441
440
|
}
|
|
442
|
-
async function evaluate(identity, ctx) {
|
|
441
|
+
async function evaluate(identity, ctx, signer) {
|
|
443
442
|
if (!identity || !identity.address && !identity.operatorToken) {
|
|
444
443
|
if (failOpen) return { kind: "allow" };
|
|
445
444
|
const sessionReason = await tryMintSessionDenial(ctx);
|
|
@@ -499,7 +498,12 @@ function createAgentScoreCore(options) {
|
|
|
499
498
|
try {
|
|
500
499
|
const opts = {
|
|
501
500
|
chain: gateChain,
|
|
502
|
-
...Object.keys(policy).length > 0 ? { policy } : {}
|
|
501
|
+
...Object.keys(policy).length > 0 ? { policy } : {},
|
|
502
|
+
// Pre-extracted payment signer (by the adapter middleware). When present, the API
|
|
503
|
+
// composes BOTH signer_match (wallet-binding) and signer_sanctions (OFAC SDN wallet
|
|
504
|
+
// check) verdicts on the response in one round trip. Under
|
|
505
|
+
// policy.require_sanctions_clear, a signer_sanctions hit flips decision -> deny inline.
|
|
506
|
+
...signer && { signer: { address: signer.address, network: signer.network } }
|
|
503
507
|
};
|
|
504
508
|
const result = identity.address ? await sdk.assess(identity.address, { ...opts, operatorToken: identity.operatorToken }) : await sdk.assess(null, { ...opts, operatorToken: identity.operatorToken });
|
|
505
509
|
data = result;
|
|
@@ -607,36 +611,6 @@ function createAgentScoreCore(options) {
|
|
|
607
611
|
console.warn("[agentscore-commerce] captureWallet failed:", err instanceof Error ? err.message : err);
|
|
608
612
|
}
|
|
609
613
|
}
|
|
610
|
-
async function resolveWalletToOperator(walletAddress) {
|
|
611
|
-
const wallet = normalizeAddress(walletAddress);
|
|
612
|
-
const extractFromCached = (raw) => {
|
|
613
|
-
const op = raw.resolved_operator;
|
|
614
|
-
const links = raw.linked_wallets;
|
|
615
|
-
return {
|
|
616
|
-
operator: typeof op === "string" ? op : null,
|
|
617
|
-
linkedWallets: Array.isArray(links) ? links.filter((w) => typeof w === "string") : []
|
|
618
|
-
};
|
|
619
|
-
};
|
|
620
|
-
const plainCached = cache.get(wallet);
|
|
621
|
-
if (plainCached?.raw) {
|
|
622
|
-
return { ok: true, ...extractFromCached(plainCached.raw) };
|
|
623
|
-
}
|
|
624
|
-
const resolveCached = cache.get(`resolve:${wallet}`);
|
|
625
|
-
if (resolveCached?.raw) {
|
|
626
|
-
return { ok: true, ...extractFromCached(resolveCached.raw) };
|
|
627
|
-
}
|
|
628
|
-
try {
|
|
629
|
-
const data = await sdk.assess(walletAddress);
|
|
630
|
-
cache.set(`resolve:${wallet}`, { allow: true, raw: data });
|
|
631
|
-
return { ok: true, ...extractFromCached(data) };
|
|
632
|
-
} catch (err) {
|
|
633
|
-
console.warn("[gate] resolveWalletToOperator failed \u2014 returning { ok:false }:", err instanceof Error ? err.message : err);
|
|
634
|
-
return { ok: false };
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
function reportSignerEvent(kind) {
|
|
638
|
-
void sdk.telemetrySignerMatch({ kind });
|
|
639
|
-
}
|
|
640
614
|
function projectSignerMatch(sm, claimedNorm, signerNorm) {
|
|
641
615
|
const kind = sm.kind;
|
|
642
616
|
if (kind === "pass") {
|
|
@@ -664,77 +638,22 @@ function createAgentScoreCore(options) {
|
|
|
664
638
|
agentInstructions: sm.agent_instructions ?? WALLET_SIGNER_MISMATCH_INSTRUCTIONS
|
|
665
639
|
};
|
|
666
640
|
}
|
|
667
|
-
|
|
668
|
-
const
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
const claimedNorm = normalizeAddress(claimedWallet);
|
|
678
|
-
const signerNorm = normalizeAddress(signer);
|
|
679
|
-
if (claimedNorm === signerNorm) {
|
|
680
|
-
reportSignerEvent("pass");
|
|
681
|
-
return { kind: "pass", claimedOperator: null, signerOperator: null };
|
|
682
|
-
}
|
|
683
|
-
const cachedEntry = cache.get(claimedNorm);
|
|
684
|
-
const cachedMatch = cachedEntry?.signerMatchBySigner?.get(signerNorm);
|
|
685
|
-
if (cachedMatch) {
|
|
686
|
-
return projectSignerMatch(cachedMatch, claimedNorm, signerNorm);
|
|
687
|
-
}
|
|
688
|
-
const inferredNetwork = network ?? (signerNorm.startsWith("0x") ? "evm" : "solana");
|
|
689
|
-
let assessResponse;
|
|
690
|
-
try {
|
|
691
|
-
assessResponse = await sdk.assess(claimedNorm, {
|
|
692
|
-
resolveSigner: { address: signerNorm, network: inferredNetwork }
|
|
693
|
-
});
|
|
694
|
-
} catch (err) {
|
|
695
|
-
console.warn("[gate] verifyWalletSignerMatch assess failed:", err instanceof Error ? err.message : err);
|
|
696
|
-
reportSignerEvent("api_error");
|
|
697
|
-
return { kind: "api_error", claimedWallet: claimedNorm };
|
|
698
|
-
}
|
|
699
|
-
const signerMatch = assessResponse.signer_match;
|
|
700
|
-
if (signerMatch && typeof signerMatch === "object") {
|
|
701
|
-
if (cachedEntry) {
|
|
702
|
-
const map = cachedEntry.signerMatchBySigner ?? /* @__PURE__ */ new Map();
|
|
703
|
-
map.set(signerNorm, signerMatch);
|
|
704
|
-
cachedEntry.signerMatchBySigner = map;
|
|
705
|
-
} else {
|
|
706
|
-
const entry = { allow: true, raw: assessResponse };
|
|
707
|
-
entry.signerMatchBySigner = /* @__PURE__ */ new Map([[signerNorm, signerMatch]]);
|
|
708
|
-
cache.set(claimedNorm, entry);
|
|
709
|
-
}
|
|
710
|
-
return projectSignerMatch(signerMatch, claimedNorm, signerNorm);
|
|
711
|
-
}
|
|
712
|
-
const [claimedResolve, signerResolve] = await Promise.all([
|
|
713
|
-
resolveWalletToOperator(claimedNorm),
|
|
714
|
-
resolveWalletToOperator(signerNorm)
|
|
715
|
-
]);
|
|
716
|
-
if (!claimedResolve.ok || !signerResolve.ok) {
|
|
717
|
-
reportSignerEvent("api_error");
|
|
718
|
-
return { kind: "api_error", claimedWallet: claimedNorm };
|
|
719
|
-
}
|
|
720
|
-
const claimedOperator = claimedResolve.operator;
|
|
721
|
-
const signerOperator = signerResolve.operator;
|
|
722
|
-
if (claimedOperator && signerOperator && claimedOperator === signerOperator) {
|
|
723
|
-
reportSignerEvent("pass");
|
|
724
|
-
return { kind: "pass", claimedOperator, signerOperator };
|
|
725
|
-
}
|
|
726
|
-
reportSignerEvent("wallet_signer_mismatch");
|
|
641
|
+
function getSignerVerdict2(claimedAddress) {
|
|
642
|
+
const claimedNorm = normalizeAddress(claimedAddress);
|
|
643
|
+
const cached = cache.get(claimedNorm);
|
|
644
|
+
if (!cached) return void 0;
|
|
645
|
+
const raw = cached.raw;
|
|
646
|
+
if (!raw) return void 0;
|
|
647
|
+
const rawMatch = raw.signer_match;
|
|
648
|
+
const rawSanctions = raw.signer_sanctions;
|
|
649
|
+
if (!rawMatch && !rawSanctions) return void 0;
|
|
650
|
+
const signerNorm = rawMatch?.actual_signer ?? claimedNorm;
|
|
727
651
|
return {
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
actualSignerOperator: signerOperator,
|
|
731
|
-
expectedSigner: claimedNorm,
|
|
732
|
-
actualSigner: signerNorm,
|
|
733
|
-
linkedWallets: claimedResolve.linkedWallets,
|
|
734
|
-
agentInstructions: WALLET_SIGNER_MISMATCH_INSTRUCTIONS
|
|
652
|
+
signer_match: rawMatch ? projectSignerMatch(rawMatch, claimedNorm, signerNorm) : null,
|
|
653
|
+
signer_sanctions: rawSanctions ?? null
|
|
735
654
|
};
|
|
736
655
|
}
|
|
737
|
-
return { evaluate, captureWallet: captureWallet2,
|
|
656
|
+
return { evaluate, captureWallet: captureWallet2, getSignerVerdict: getSignerVerdict2 };
|
|
738
657
|
}
|
|
739
658
|
|
|
740
659
|
// src/signer.ts
|
|
@@ -810,10 +729,6 @@ async function extractPaymentSigner(request, x402PaymentHeader) {
|
|
|
810
729
|
}
|
|
811
730
|
return null;
|
|
812
731
|
}
|
|
813
|
-
async function extractPaymentSignerAddress(request, x402PaymentHeader) {
|
|
814
|
-
const result = await extractPaymentSigner(request, x402PaymentHeader);
|
|
815
|
-
return result?.address ?? null;
|
|
816
|
-
}
|
|
817
732
|
function readX402PaymentHeader(request) {
|
|
818
733
|
return request.headers.get("payment-signature") ?? request.headers.get("x-payment") ?? void 0;
|
|
819
734
|
}
|
|
@@ -843,7 +758,8 @@ function agentscoreGate(options) {
|
|
|
843
758
|
operatorToken: identity?.operatorToken,
|
|
844
759
|
walletAddress: identity?.address
|
|
845
760
|
});
|
|
846
|
-
const
|
|
761
|
+
const signer = await extractPaymentSigner(c.req.raw, readX402PaymentHeader(c.req.raw));
|
|
762
|
+
const outcome = await core.evaluate(identity, c, signer);
|
|
847
763
|
if (outcome.kind === "allow") {
|
|
848
764
|
if (outcome.degraded || outcome.quota) {
|
|
849
765
|
const prev = c.get(GATE_STATE_KEY);
|
|
@@ -881,17 +797,10 @@ async function captureWallet(c, options) {
|
|
|
881
797
|
idempotencyKey: options.idempotencyKey
|
|
882
798
|
});
|
|
883
799
|
}
|
|
884
|
-
|
|
800
|
+
function getSignerVerdict(c) {
|
|
885
801
|
const state = c.get(GATE_STATE_KEY);
|
|
886
|
-
if (!state?.walletAddress
|
|
887
|
-
|
|
888
|
-
}
|
|
889
|
-
const signer = options?.signer !== void 0 ? options.signer : await extractPaymentSignerAddress(c.req.raw, readX402PaymentHeader(c.req.raw));
|
|
890
|
-
return state.core.verifyWalletSignerMatch({
|
|
891
|
-
claimedWallet: state.walletAddress,
|
|
892
|
-
signer,
|
|
893
|
-
network: options?.network
|
|
894
|
-
});
|
|
802
|
+
if (!state?.walletAddress) return void 0;
|
|
803
|
+
return state.core.getSignerVerdict(state.walletAddress);
|
|
895
804
|
}
|
|
896
805
|
// Annotate the CommonJS export names for ESM import in node:
|
|
897
806
|
0 && (module.exports = {
|
|
@@ -902,13 +811,12 @@ async function verifyWalletSignerMatch(c, options) {
|
|
|
902
811
|
captureWallet,
|
|
903
812
|
denialReasonStatus,
|
|
904
813
|
denialReasonToBody,
|
|
905
|
-
extractPaymentSignerAddress,
|
|
906
814
|
getAgentScoreData,
|
|
907
815
|
getGateDegradedState,
|
|
908
816
|
getGateQuotaInfo,
|
|
817
|
+
getSignerVerdict,
|
|
909
818
|
isFixableDenial,
|
|
910
819
|
readX402PaymentHeader,
|
|
911
|
-
verificationAgentInstructions
|
|
912
|
-
verifyWalletSignerMatch
|
|
820
|
+
verificationAgentInstructions
|
|
913
821
|
});
|
|
914
822
|
//# sourceMappingURL=hono.js.map
|