@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
package/dist/identity/nextjs.js
CHANGED
|
@@ -26,7 +26,6 @@ __export(nextjs_exports, {
|
|
|
26
26
|
buildSignerMismatchBody: () => buildSignerMismatchBody,
|
|
27
27
|
denialReasonStatus: () => denialReasonStatus,
|
|
28
28
|
denialReasonToBody: () => denialReasonToBody,
|
|
29
|
-
extractPaymentSignerAddress: () => extractPaymentSignerAddress,
|
|
30
29
|
isFixableDenial: () => isFixableDenial,
|
|
31
30
|
readX402PaymentHeader: () => readX402PaymentHeader,
|
|
32
31
|
verificationAgentInstructions: () => verificationAgentInstructions,
|
|
@@ -51,7 +50,7 @@ function denialReasonStatus(reason) {
|
|
|
51
50
|
}
|
|
52
51
|
function buildSignerMismatchBody(input) {
|
|
53
52
|
const { result } = input;
|
|
54
|
-
if (result.kind === "pass"
|
|
53
|
+
if (result.kind === "pass") return null;
|
|
55
54
|
const learnMoreUrl = input.learnMoreUrl ?? "https://docs.agentscore.sh/guides/agent-identity";
|
|
56
55
|
if (result.kind === "wallet_signer_mismatch") {
|
|
57
56
|
const linkedWallets = result.linkedWallets ?? [];
|
|
@@ -361,7 +360,7 @@ function createAgentScoreCore(options) {
|
|
|
361
360
|
} = options;
|
|
362
361
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
363
362
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
364
|
-
const defaultUa = `@agent-score/commerce@${"1.
|
|
363
|
+
const defaultUa = `@agent-score/commerce@${"1.8.0"}`;
|
|
365
364
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
366
365
|
const sdk = new import_sdk.AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
|
|
367
366
|
const sessionSdkCache = /* @__PURE__ */ new Map();
|
|
@@ -435,7 +434,7 @@ function createAgentScoreCore(options) {
|
|
|
435
434
|
return void 0;
|
|
436
435
|
}
|
|
437
436
|
}
|
|
438
|
-
async function evaluate(identity, ctx) {
|
|
437
|
+
async function evaluate(identity, ctx, signer) {
|
|
439
438
|
if (!identity || !identity.address && !identity.operatorToken) {
|
|
440
439
|
if (failOpen) return { kind: "allow" };
|
|
441
440
|
const sessionReason = await tryMintSessionDenial(ctx);
|
|
@@ -495,7 +494,12 @@ function createAgentScoreCore(options) {
|
|
|
495
494
|
try {
|
|
496
495
|
const opts = {
|
|
497
496
|
chain: gateChain,
|
|
498
|
-
...Object.keys(policy).length > 0 ? { policy } : {}
|
|
497
|
+
...Object.keys(policy).length > 0 ? { policy } : {},
|
|
498
|
+
// Pre-extracted payment signer (by the adapter middleware). When present, the API
|
|
499
|
+
// composes BOTH signer_match (wallet-binding) and signer_sanctions (OFAC SDN wallet
|
|
500
|
+
// check) verdicts on the response in one round trip. Under
|
|
501
|
+
// policy.require_sanctions_clear, a signer_sanctions hit flips decision -> deny inline.
|
|
502
|
+
...signer && { signer: { address: signer.address, network: signer.network } }
|
|
499
503
|
};
|
|
500
504
|
const result = identity.address ? await sdk.assess(identity.address, { ...opts, operatorToken: identity.operatorToken }) : await sdk.assess(null, { ...opts, operatorToken: identity.operatorToken });
|
|
501
505
|
data = result;
|
|
@@ -603,36 +607,6 @@ function createAgentScoreCore(options) {
|
|
|
603
607
|
console.warn("[agentscore-commerce] captureWallet failed:", err instanceof Error ? err.message : err);
|
|
604
608
|
}
|
|
605
609
|
}
|
|
606
|
-
async function resolveWalletToOperator(walletAddress) {
|
|
607
|
-
const wallet = normalizeAddress(walletAddress);
|
|
608
|
-
const extractFromCached = (raw) => {
|
|
609
|
-
const op = raw.resolved_operator;
|
|
610
|
-
const links = raw.linked_wallets;
|
|
611
|
-
return {
|
|
612
|
-
operator: typeof op === "string" ? op : null,
|
|
613
|
-
linkedWallets: Array.isArray(links) ? links.filter((w) => typeof w === "string") : []
|
|
614
|
-
};
|
|
615
|
-
};
|
|
616
|
-
const plainCached = cache.get(wallet);
|
|
617
|
-
if (plainCached?.raw) {
|
|
618
|
-
return { ok: true, ...extractFromCached(plainCached.raw) };
|
|
619
|
-
}
|
|
620
|
-
const resolveCached = cache.get(`resolve:${wallet}`);
|
|
621
|
-
if (resolveCached?.raw) {
|
|
622
|
-
return { ok: true, ...extractFromCached(resolveCached.raw) };
|
|
623
|
-
}
|
|
624
|
-
try {
|
|
625
|
-
const data = await sdk.assess(walletAddress);
|
|
626
|
-
cache.set(`resolve:${wallet}`, { allow: true, raw: data });
|
|
627
|
-
return { ok: true, ...extractFromCached(data) };
|
|
628
|
-
} catch (err) {
|
|
629
|
-
console.warn("[gate] resolveWalletToOperator failed \u2014 returning { ok:false }:", err instanceof Error ? err.message : err);
|
|
630
|
-
return { ok: false };
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
function reportSignerEvent(kind) {
|
|
634
|
-
void sdk.telemetrySignerMatch({ kind });
|
|
635
|
-
}
|
|
636
610
|
function projectSignerMatch(sm, claimedNorm, signerNorm) {
|
|
637
611
|
const kind = sm.kind;
|
|
638
612
|
if (kind === "pass") {
|
|
@@ -660,77 +634,22 @@ function createAgentScoreCore(options) {
|
|
|
660
634
|
agentInstructions: sm.agent_instructions ?? WALLET_SIGNER_MISMATCH_INSTRUCTIONS
|
|
661
635
|
};
|
|
662
636
|
}
|
|
663
|
-
|
|
664
|
-
const
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
const claimedNorm = normalizeAddress(claimedWallet);
|
|
674
|
-
const signerNorm = normalizeAddress(signer);
|
|
675
|
-
if (claimedNorm === signerNorm) {
|
|
676
|
-
reportSignerEvent("pass");
|
|
677
|
-
return { kind: "pass", claimedOperator: null, signerOperator: null };
|
|
678
|
-
}
|
|
679
|
-
const cachedEntry = cache.get(claimedNorm);
|
|
680
|
-
const cachedMatch = cachedEntry?.signerMatchBySigner?.get(signerNorm);
|
|
681
|
-
if (cachedMatch) {
|
|
682
|
-
return projectSignerMatch(cachedMatch, claimedNorm, signerNorm);
|
|
683
|
-
}
|
|
684
|
-
const inferredNetwork = network ?? (signerNorm.startsWith("0x") ? "evm" : "solana");
|
|
685
|
-
let assessResponse;
|
|
686
|
-
try {
|
|
687
|
-
assessResponse = await sdk.assess(claimedNorm, {
|
|
688
|
-
resolveSigner: { address: signerNorm, network: inferredNetwork }
|
|
689
|
-
});
|
|
690
|
-
} catch (err) {
|
|
691
|
-
console.warn("[gate] verifyWalletSignerMatch assess failed:", err instanceof Error ? err.message : err);
|
|
692
|
-
reportSignerEvent("api_error");
|
|
693
|
-
return { kind: "api_error", claimedWallet: claimedNorm };
|
|
694
|
-
}
|
|
695
|
-
const signerMatch = assessResponse.signer_match;
|
|
696
|
-
if (signerMatch && typeof signerMatch === "object") {
|
|
697
|
-
if (cachedEntry) {
|
|
698
|
-
const map = cachedEntry.signerMatchBySigner ?? /* @__PURE__ */ new Map();
|
|
699
|
-
map.set(signerNorm, signerMatch);
|
|
700
|
-
cachedEntry.signerMatchBySigner = map;
|
|
701
|
-
} else {
|
|
702
|
-
const entry = { allow: true, raw: assessResponse };
|
|
703
|
-
entry.signerMatchBySigner = /* @__PURE__ */ new Map([[signerNorm, signerMatch]]);
|
|
704
|
-
cache.set(claimedNorm, entry);
|
|
705
|
-
}
|
|
706
|
-
return projectSignerMatch(signerMatch, claimedNorm, signerNorm);
|
|
707
|
-
}
|
|
708
|
-
const [claimedResolve, signerResolve] = await Promise.all([
|
|
709
|
-
resolveWalletToOperator(claimedNorm),
|
|
710
|
-
resolveWalletToOperator(signerNorm)
|
|
711
|
-
]);
|
|
712
|
-
if (!claimedResolve.ok || !signerResolve.ok) {
|
|
713
|
-
reportSignerEvent("api_error");
|
|
714
|
-
return { kind: "api_error", claimedWallet: claimedNorm };
|
|
715
|
-
}
|
|
716
|
-
const claimedOperator = claimedResolve.operator;
|
|
717
|
-
const signerOperator = signerResolve.operator;
|
|
718
|
-
if (claimedOperator && signerOperator && claimedOperator === signerOperator) {
|
|
719
|
-
reportSignerEvent("pass");
|
|
720
|
-
return { kind: "pass", claimedOperator, signerOperator };
|
|
721
|
-
}
|
|
722
|
-
reportSignerEvent("wallet_signer_mismatch");
|
|
637
|
+
function getSignerVerdict(claimedAddress) {
|
|
638
|
+
const claimedNorm = normalizeAddress(claimedAddress);
|
|
639
|
+
const cached = cache.get(claimedNorm);
|
|
640
|
+
if (!cached) return void 0;
|
|
641
|
+
const raw = cached.raw;
|
|
642
|
+
if (!raw) return void 0;
|
|
643
|
+
const rawMatch = raw.signer_match;
|
|
644
|
+
const rawSanctions = raw.signer_sanctions;
|
|
645
|
+
if (!rawMatch && !rawSanctions) return void 0;
|
|
646
|
+
const signerNorm = rawMatch?.actual_signer ?? claimedNorm;
|
|
723
647
|
return {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
actualSignerOperator: signerOperator,
|
|
727
|
-
expectedSigner: claimedNorm,
|
|
728
|
-
actualSigner: signerNorm,
|
|
729
|
-
linkedWallets: claimedResolve.linkedWallets,
|
|
730
|
-
agentInstructions: WALLET_SIGNER_MISMATCH_INSTRUCTIONS
|
|
648
|
+
signer_match: rawMatch ? projectSignerMatch(rawMatch, claimedNorm, signerNorm) : null,
|
|
649
|
+
signer_sanctions: rawSanctions ?? null
|
|
731
650
|
};
|
|
732
651
|
}
|
|
733
|
-
return { evaluate, captureWallet,
|
|
652
|
+
return { evaluate, captureWallet, getSignerVerdict };
|
|
734
653
|
}
|
|
735
654
|
|
|
736
655
|
// src/signer.ts
|
|
@@ -806,10 +725,6 @@ async function extractPaymentSigner(request, x402PaymentHeader) {
|
|
|
806
725
|
}
|
|
807
726
|
return null;
|
|
808
727
|
}
|
|
809
|
-
async function extractPaymentSignerAddress(request, x402PaymentHeader) {
|
|
810
|
-
const result = await extractPaymentSigner(request, x402PaymentHeader);
|
|
811
|
-
return result?.address ?? null;
|
|
812
|
-
}
|
|
813
728
|
function readX402PaymentHeader(request) {
|
|
814
729
|
return request.headers.get("payment-signature") ?? request.headers.get("x-payment") ?? void 0;
|
|
815
730
|
}
|
|
@@ -835,22 +750,16 @@ function createAgentScoreGate(options) {
|
|
|
835
750
|
const core = createAgentScoreCore(coreOptions);
|
|
836
751
|
return async (req) => {
|
|
837
752
|
const identity = extractIdentity(req);
|
|
838
|
-
const
|
|
753
|
+
const signer = await extractPaymentSigner(req, readX402PaymentHeader(req));
|
|
754
|
+
const outcome = await core.evaluate(identity, req, signer);
|
|
839
755
|
if (outcome.kind === "allow") {
|
|
840
756
|
const captureWallet = identity?.operatorToken ? (opts) => core.captureWallet({ operatorToken: identity.operatorToken, ...opts }) : void 0;
|
|
841
|
-
const
|
|
842
|
-
const signer = opts?.signer !== void 0 ? opts.signer : await extractPaymentSignerAddress(req, readX402PaymentHeader(req));
|
|
843
|
-
return core.verifyWalletSignerMatch({
|
|
844
|
-
claimedWallet: identity.address,
|
|
845
|
-
signer,
|
|
846
|
-
network: opts?.network
|
|
847
|
-
});
|
|
848
|
-
} : void 0;
|
|
757
|
+
const getSignerVerdictBound = identity?.address && !identity?.operatorToken ? () => core.getSignerVerdict(identity.address) : void 0;
|
|
849
758
|
return {
|
|
850
759
|
allowed: true,
|
|
851
760
|
data: outcome.data,
|
|
852
761
|
captureWallet,
|
|
853
|
-
|
|
762
|
+
getSignerVerdict: getSignerVerdictBound,
|
|
854
763
|
...outcome.degraded ? { degraded: true, infraReason: outcome.infraReason } : {},
|
|
855
764
|
...outcome.quota ? { quota: outcome.quota } : {}
|
|
856
765
|
};
|
|
@@ -871,7 +780,7 @@ function withAgentScoreGate(options, handler) {
|
|
|
871
780
|
{
|
|
872
781
|
data: result.data,
|
|
873
782
|
captureWallet: result.captureWallet,
|
|
874
|
-
|
|
783
|
+
getSignerVerdict: result.getSignerVerdict,
|
|
875
784
|
...result.degraded ? { degraded: true, infraReason: result.infraReason } : {},
|
|
876
785
|
...result.quota ? { quota: result.quota } : {}
|
|
877
786
|
},
|
|
@@ -894,7 +803,6 @@ function agentscoreMiddleware(options) {
|
|
|
894
803
|
buildSignerMismatchBody,
|
|
895
804
|
denialReasonStatus,
|
|
896
805
|
denialReasonToBody,
|
|
897
|
-
extractPaymentSignerAddress,
|
|
898
806
|
isFixableDenial,
|
|
899
807
|
readX402PaymentHeader,
|
|
900
808
|
verificationAgentInstructions,
|