@agent-score/commerce 1.6.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 +8 -10
- 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 +73 -11
- package/dist/index.d.ts +73 -11
- package/dist/index.js +45 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -7
- 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
|
@@ -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 { FastifyRequest, FastifyReply, FastifyPluginAsync } from 'fastify';
|
|
5
5
|
|
|
6
6
|
interface AgentScoreGateOptions extends Omit<AgentScoreCoreOptions, 'createSessionOnMissing'> {
|
|
@@ -64,15 +64,16 @@ declare function captureWallet(request: FastifyRequest, options: {
|
|
|
64
64
|
idempotencyKey?: string;
|
|
65
65
|
}): Promise<void>;
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
67
|
+
* Synchronous read of the cached signer verdicts (`signer_match` + `signer_sanctions`).
|
|
68
|
+
* Both composed by the gate's primary /v1/assess in one round trip. Returns `undefined`
|
|
69
|
+
* for operator-token paths, discovery legs, or routes the gate didn't run on.
|
|
70
|
+
*
|
|
71
|
+
* Under `policy.require_sanctions_clear`, OFAC SDN wallet hits are already enforced by
|
|
72
|
+
* the gate (decision → deny before the handler runs); merchant code typically only needs
|
|
73
|
+
* this getter for the `signer_match` wallet-binding verdict.
|
|
70
74
|
*/
|
|
71
|
-
declare function
|
|
72
|
-
signer: string | null;
|
|
73
|
-
network?: 'evm' | 'solana';
|
|
74
|
-
}): Promise<VerifyWalletSignerResult>;
|
|
75
|
+
declare function getSignerVerdict(request: FastifyRequest): SignerVerdict | undefined;
|
|
75
76
|
|
|
76
77
|
declare const agentscoreGate: FastifyPluginAsync<AgentScoreGateOptions>;
|
|
77
78
|
|
|
78
|
-
export { type AgentScoreGateOptions, agentscoreGate, captureWallet, agentscoreGatePlugin as default, getAgentScoreData, getGateDegradedState, getGateQuotaInfo,
|
|
79
|
+
export { type AgentScoreGateOptions, agentscoreGate, captureWallet, agentscoreGatePlugin as default, getAgentScoreData, getGateDegradedState, getGateQuotaInfo, getSignerVerdict };
|
package/dist/identity/fastify.js
CHANGED
|
@@ -28,14 +28,13 @@ __export(fastify_exports, {
|
|
|
28
28
|
default: () => fastify_default,
|
|
29
29
|
denialReasonStatus: () => denialReasonStatus,
|
|
30
30
|
denialReasonToBody: () => denialReasonToBody,
|
|
31
|
-
extractPaymentSignerAddress: () => extractPaymentSignerAddress,
|
|
32
31
|
getAgentScoreData: () => getAgentScoreData,
|
|
33
32
|
getGateDegradedState: () => getGateDegradedState,
|
|
34
33
|
getGateQuotaInfo: () => getGateQuotaInfo,
|
|
34
|
+
getSignerVerdict: () => getSignerVerdict,
|
|
35
35
|
isFixableDenial: () => isFixableDenial,
|
|
36
36
|
readX402PaymentHeader: () => readX402PaymentHeader,
|
|
37
|
-
verificationAgentInstructions: () => verificationAgentInstructions
|
|
38
|
-
verifyWalletSignerMatch: () => verifyWalletSignerMatch
|
|
37
|
+
verificationAgentInstructions: () => verificationAgentInstructions
|
|
39
38
|
});
|
|
40
39
|
module.exports = __toCommonJS(fastify_exports);
|
|
41
40
|
|
|
@@ -56,7 +55,7 @@ function denialReasonStatus(reason) {
|
|
|
56
55
|
}
|
|
57
56
|
function buildSignerMismatchBody(input) {
|
|
58
57
|
const { result } = input;
|
|
59
|
-
if (result.kind === "pass"
|
|
58
|
+
if (result.kind === "pass") return null;
|
|
60
59
|
const learnMoreUrl = input.learnMoreUrl ?? "https://docs.agentscore.sh/guides/agent-identity";
|
|
61
60
|
if (result.kind === "wallet_signer_mismatch") {
|
|
62
61
|
const linkedWallets = result.linkedWallets ?? [];
|
|
@@ -366,7 +365,7 @@ function createAgentScoreCore(options) {
|
|
|
366
365
|
} = options;
|
|
367
366
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
368
367
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
369
|
-
const defaultUa = `@agent-score/commerce@${"1.
|
|
368
|
+
const defaultUa = `@agent-score/commerce@${"1.8.0"}`;
|
|
370
369
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
371
370
|
const sdk = new import_sdk.AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
|
|
372
371
|
const sessionSdkCache = /* @__PURE__ */ new Map();
|
|
@@ -440,7 +439,7 @@ function createAgentScoreCore(options) {
|
|
|
440
439
|
return void 0;
|
|
441
440
|
}
|
|
442
441
|
}
|
|
443
|
-
async function evaluate(identity, ctx) {
|
|
442
|
+
async function evaluate(identity, ctx, signer) {
|
|
444
443
|
if (!identity || !identity.address && !identity.operatorToken) {
|
|
445
444
|
if (failOpen) return { kind: "allow" };
|
|
446
445
|
const sessionReason = await tryMintSessionDenial(ctx);
|
|
@@ -500,7 +499,12 @@ function createAgentScoreCore(options) {
|
|
|
500
499
|
try {
|
|
501
500
|
const opts = {
|
|
502
501
|
chain: gateChain,
|
|
503
|
-
...Object.keys(policy).length > 0 ? { policy } : {}
|
|
502
|
+
...Object.keys(policy).length > 0 ? { policy } : {},
|
|
503
|
+
// Pre-extracted payment signer (by the adapter middleware). When present, the API
|
|
504
|
+
// composes BOTH signer_match (wallet-binding) and signer_sanctions (OFAC SDN wallet
|
|
505
|
+
// check) verdicts on the response in one round trip. Under
|
|
506
|
+
// policy.require_sanctions_clear, a signer_sanctions hit flips decision -> deny inline.
|
|
507
|
+
...signer && { signer: { address: signer.address, network: signer.network } }
|
|
504
508
|
};
|
|
505
509
|
const result = identity.address ? await sdk.assess(identity.address, { ...opts, operatorToken: identity.operatorToken }) : await sdk.assess(null, { ...opts, operatorToken: identity.operatorToken });
|
|
506
510
|
data = result;
|
|
@@ -608,36 +612,6 @@ function createAgentScoreCore(options) {
|
|
|
608
612
|
console.warn("[agentscore-commerce] captureWallet failed:", err instanceof Error ? err.message : err);
|
|
609
613
|
}
|
|
610
614
|
}
|
|
611
|
-
async function resolveWalletToOperator(walletAddress) {
|
|
612
|
-
const wallet = normalizeAddress(walletAddress);
|
|
613
|
-
const extractFromCached = (raw) => {
|
|
614
|
-
const op = raw.resolved_operator;
|
|
615
|
-
const links = raw.linked_wallets;
|
|
616
|
-
return {
|
|
617
|
-
operator: typeof op === "string" ? op : null,
|
|
618
|
-
linkedWallets: Array.isArray(links) ? links.filter((w) => typeof w === "string") : []
|
|
619
|
-
};
|
|
620
|
-
};
|
|
621
|
-
const plainCached = cache.get(wallet);
|
|
622
|
-
if (plainCached?.raw) {
|
|
623
|
-
return { ok: true, ...extractFromCached(plainCached.raw) };
|
|
624
|
-
}
|
|
625
|
-
const resolveCached = cache.get(`resolve:${wallet}`);
|
|
626
|
-
if (resolveCached?.raw) {
|
|
627
|
-
return { ok: true, ...extractFromCached(resolveCached.raw) };
|
|
628
|
-
}
|
|
629
|
-
try {
|
|
630
|
-
const data = await sdk.assess(walletAddress);
|
|
631
|
-
cache.set(`resolve:${wallet}`, { allow: true, raw: data });
|
|
632
|
-
return { ok: true, ...extractFromCached(data) };
|
|
633
|
-
} catch (err) {
|
|
634
|
-
console.warn("[gate] resolveWalletToOperator failed \u2014 returning { ok:false }:", err instanceof Error ? err.message : err);
|
|
635
|
-
return { ok: false };
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
function reportSignerEvent(kind) {
|
|
639
|
-
void sdk.telemetrySignerMatch({ kind });
|
|
640
|
-
}
|
|
641
615
|
function projectSignerMatch(sm, claimedNorm, signerNorm) {
|
|
642
616
|
const kind = sm.kind;
|
|
643
617
|
if (kind === "pass") {
|
|
@@ -665,77 +639,22 @@ function createAgentScoreCore(options) {
|
|
|
665
639
|
agentInstructions: sm.agent_instructions ?? WALLET_SIGNER_MISMATCH_INSTRUCTIONS
|
|
666
640
|
};
|
|
667
641
|
}
|
|
668
|
-
|
|
669
|
-
const
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
const claimedNorm = normalizeAddress(claimedWallet);
|
|
679
|
-
const signerNorm = normalizeAddress(signer);
|
|
680
|
-
if (claimedNorm === signerNorm) {
|
|
681
|
-
reportSignerEvent("pass");
|
|
682
|
-
return { kind: "pass", claimedOperator: null, signerOperator: null };
|
|
683
|
-
}
|
|
684
|
-
const cachedEntry = cache.get(claimedNorm);
|
|
685
|
-
const cachedMatch = cachedEntry?.signerMatchBySigner?.get(signerNorm);
|
|
686
|
-
if (cachedMatch) {
|
|
687
|
-
return projectSignerMatch(cachedMatch, claimedNorm, signerNorm);
|
|
688
|
-
}
|
|
689
|
-
const inferredNetwork = network ?? (signerNorm.startsWith("0x") ? "evm" : "solana");
|
|
690
|
-
let assessResponse;
|
|
691
|
-
try {
|
|
692
|
-
assessResponse = await sdk.assess(claimedNorm, {
|
|
693
|
-
resolveSigner: { address: signerNorm, network: inferredNetwork }
|
|
694
|
-
});
|
|
695
|
-
} catch (err) {
|
|
696
|
-
console.warn("[gate] verifyWalletSignerMatch assess failed:", err instanceof Error ? err.message : err);
|
|
697
|
-
reportSignerEvent("api_error");
|
|
698
|
-
return { kind: "api_error", claimedWallet: claimedNorm };
|
|
699
|
-
}
|
|
700
|
-
const signerMatch = assessResponse.signer_match;
|
|
701
|
-
if (signerMatch && typeof signerMatch === "object") {
|
|
702
|
-
if (cachedEntry) {
|
|
703
|
-
const map = cachedEntry.signerMatchBySigner ?? /* @__PURE__ */ new Map();
|
|
704
|
-
map.set(signerNorm, signerMatch);
|
|
705
|
-
cachedEntry.signerMatchBySigner = map;
|
|
706
|
-
} else {
|
|
707
|
-
const entry = { allow: true, raw: assessResponse };
|
|
708
|
-
entry.signerMatchBySigner = /* @__PURE__ */ new Map([[signerNorm, signerMatch]]);
|
|
709
|
-
cache.set(claimedNorm, entry);
|
|
710
|
-
}
|
|
711
|
-
return projectSignerMatch(signerMatch, claimedNorm, signerNorm);
|
|
712
|
-
}
|
|
713
|
-
const [claimedResolve, signerResolve] = await Promise.all([
|
|
714
|
-
resolveWalletToOperator(claimedNorm),
|
|
715
|
-
resolveWalletToOperator(signerNorm)
|
|
716
|
-
]);
|
|
717
|
-
if (!claimedResolve.ok || !signerResolve.ok) {
|
|
718
|
-
reportSignerEvent("api_error");
|
|
719
|
-
return { kind: "api_error", claimedWallet: claimedNorm };
|
|
720
|
-
}
|
|
721
|
-
const claimedOperator = claimedResolve.operator;
|
|
722
|
-
const signerOperator = signerResolve.operator;
|
|
723
|
-
if (claimedOperator && signerOperator && claimedOperator === signerOperator) {
|
|
724
|
-
reportSignerEvent("pass");
|
|
725
|
-
return { kind: "pass", claimedOperator, signerOperator };
|
|
726
|
-
}
|
|
727
|
-
reportSignerEvent("wallet_signer_mismatch");
|
|
642
|
+
function getSignerVerdict2(claimedAddress) {
|
|
643
|
+
const claimedNorm = normalizeAddress(claimedAddress);
|
|
644
|
+
const cached = cache.get(claimedNorm);
|
|
645
|
+
if (!cached) return void 0;
|
|
646
|
+
const raw = cached.raw;
|
|
647
|
+
if (!raw) return void 0;
|
|
648
|
+
const rawMatch = raw.signer_match;
|
|
649
|
+
const rawSanctions = raw.signer_sanctions;
|
|
650
|
+
if (!rawMatch && !rawSanctions) return void 0;
|
|
651
|
+
const signerNorm = rawMatch?.actual_signer ?? claimedNorm;
|
|
728
652
|
return {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
actualSignerOperator: signerOperator,
|
|
732
|
-
expectedSigner: claimedNorm,
|
|
733
|
-
actualSigner: signerNorm,
|
|
734
|
-
linkedWallets: claimedResolve.linkedWallets,
|
|
735
|
-
agentInstructions: WALLET_SIGNER_MISMATCH_INSTRUCTIONS
|
|
653
|
+
signer_match: rawMatch ? projectSignerMatch(rawMatch, claimedNorm, signerNorm) : null,
|
|
654
|
+
signer_sanctions: rawSanctions ?? null
|
|
736
655
|
};
|
|
737
656
|
}
|
|
738
|
-
return { evaluate, captureWallet: captureWallet2,
|
|
657
|
+
return { evaluate, captureWallet: captureWallet2, getSignerVerdict: getSignerVerdict2 };
|
|
739
658
|
}
|
|
740
659
|
|
|
741
660
|
// src/signer.ts
|
|
@@ -811,9 +730,11 @@ async function extractPaymentSigner(request, x402PaymentHeader) {
|
|
|
811
730
|
}
|
|
812
731
|
return null;
|
|
813
732
|
}
|
|
814
|
-
async function
|
|
815
|
-
const
|
|
816
|
-
|
|
733
|
+
async function extractPaymentSignerFromAuth(authHeader, x402PaymentHeader) {
|
|
734
|
+
const request = new Request("http://internal.gate/", {
|
|
735
|
+
headers: authHeader ? { authorization: authHeader } : {}
|
|
736
|
+
});
|
|
737
|
+
return extractPaymentSigner(request, x402PaymentHeader);
|
|
817
738
|
}
|
|
818
739
|
function readX402PaymentHeader(request) {
|
|
819
740
|
return request.headers.get("payment-signature") ?? request.headers.get("x-payment") ?? void 0;
|
|
@@ -843,7 +764,10 @@ var agentscoreGatePlugin = async (fastify, options) => {
|
|
|
843
764
|
operatorToken: identity?.operatorToken,
|
|
844
765
|
walletAddress: identity?.address
|
|
845
766
|
};
|
|
846
|
-
const
|
|
767
|
+
const authHeader = request.headers.authorization ?? null;
|
|
768
|
+
const x402Header = request.headers["payment-signature"] ?? request.headers["x-payment"];
|
|
769
|
+
const signer = await extractPaymentSignerFromAuth(authHeader, x402Header);
|
|
770
|
+
const outcome = await core.evaluate(identity, request, signer);
|
|
847
771
|
if (outcome.kind === "allow") {
|
|
848
772
|
const state = request[GATE_STATE_KEY];
|
|
849
773
|
if (state) {
|
|
@@ -880,16 +804,10 @@ async function captureWallet(request, options) {
|
|
|
880
804
|
idempotencyKey: options.idempotencyKey
|
|
881
805
|
});
|
|
882
806
|
}
|
|
883
|
-
|
|
807
|
+
function getSignerVerdict(request) {
|
|
884
808
|
const state = request[GATE_STATE_KEY];
|
|
885
|
-
if (!state?.walletAddress
|
|
886
|
-
|
|
887
|
-
}
|
|
888
|
-
return state.core.verifyWalletSignerMatch({
|
|
889
|
-
claimedWallet: state.walletAddress,
|
|
890
|
-
signer: options.signer,
|
|
891
|
-
network: options.network
|
|
892
|
-
});
|
|
809
|
+
if (!state?.walletAddress) return void 0;
|
|
810
|
+
return state.core.getSignerVerdict(state.walletAddress);
|
|
893
811
|
}
|
|
894
812
|
agentscoreGatePlugin[/* @__PURE__ */ Symbol.for("skip-override")] = true;
|
|
895
813
|
var agentscoreGate = agentscoreGatePlugin;
|
|
@@ -903,13 +821,12 @@ var fastify_default = agentscoreGatePlugin;
|
|
|
903
821
|
captureWallet,
|
|
904
822
|
denialReasonStatus,
|
|
905
823
|
denialReasonToBody,
|
|
906
|
-
extractPaymentSignerAddress,
|
|
907
824
|
getAgentScoreData,
|
|
908
825
|
getGateDegradedState,
|
|
909
826
|
getGateQuotaInfo,
|
|
827
|
+
getSignerVerdict,
|
|
910
828
|
isFixableDenial,
|
|
911
829
|
readX402PaymentHeader,
|
|
912
|
-
verificationAgentInstructions
|
|
913
|
-
verifyWalletSignerMatch
|
|
830
|
+
verificationAgentInstructions
|
|
914
831
|
});
|
|
915
832
|
//# sourceMappingURL=fastify.js.map
|