@agent-score/commerce 1.7.0 → 1.8.1
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-9yp6Fit2.d.mts} +13 -11
- package/dist/{_response-C2yFQoIA.d.ts → _response-CC6jNb8q.d.ts} +13 -11
- package/dist/challenge/index.d.mts +6 -5
- package/dist/challenge/index.d.ts +6 -5
- 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 +2 -2
- package/dist/payment/index.d.ts +2 -2
- 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/dist/stripe-multichain/index.d.mts +1 -1
- package/dist/stripe-multichain/index.d.ts +1 -1
- package/dist/stripe-multichain/index.js.map +1 -1
- package/dist/stripe-multichain/index.mjs.map +1 -1
- package/package.json +11 -9
package/dist/identity/express.js
CHANGED
|
@@ -27,14 +27,13 @@ __export(express_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(express_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.1"}`;
|
|
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,9 +729,11 @@ async function extractPaymentSigner(request, x402PaymentHeader) {
|
|
|
810
729
|
}
|
|
811
730
|
return null;
|
|
812
731
|
}
|
|
813
|
-
async function
|
|
814
|
-
const
|
|
815
|
-
|
|
732
|
+
async function extractPaymentSignerFromAuth(authHeader, x402PaymentHeader) {
|
|
733
|
+
const request = new Request("http://internal.gate/", {
|
|
734
|
+
headers: authHeader ? { authorization: authHeader } : {}
|
|
735
|
+
});
|
|
736
|
+
return extractPaymentSigner(request, x402PaymentHeader);
|
|
816
737
|
}
|
|
817
738
|
function readX402PaymentHeader(request) {
|
|
818
739
|
return request.headers.get("payment-signature") ?? request.headers.get("x-payment") ?? void 0;
|
|
@@ -842,7 +763,10 @@ function agentscoreGate(options) {
|
|
|
842
763
|
operatorToken: identity?.operatorToken,
|
|
843
764
|
walletAddress: identity?.address
|
|
844
765
|
};
|
|
845
|
-
const
|
|
766
|
+
const authHeader = req.headers.authorization ?? null;
|
|
767
|
+
const x402Header = req.headers["payment-signature"] ?? req.headers["x-payment"];
|
|
768
|
+
const signer = await extractPaymentSignerFromAuth(authHeader, x402Header);
|
|
769
|
+
const outcome = await core.evaluate(identity, req, signer);
|
|
846
770
|
if (outcome.kind === "allow") {
|
|
847
771
|
const state = req[GATE_STATE_KEY];
|
|
848
772
|
if (state) {
|
|
@@ -880,16 +804,10 @@ async function captureWallet(req, options) {
|
|
|
880
804
|
idempotencyKey: options.idempotencyKey
|
|
881
805
|
});
|
|
882
806
|
}
|
|
883
|
-
|
|
807
|
+
function getSignerVerdict(req) {
|
|
884
808
|
const state = req[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
|
// Annotate the CommonJS export names for ESM import in node:
|
|
895
813
|
0 && (module.exports = {
|
|
@@ -900,13 +818,12 @@ async function verifyWalletSignerMatch(req, options) {
|
|
|
900
818
|
captureWallet,
|
|
901
819
|
denialReasonStatus,
|
|
902
820
|
denialReasonToBody,
|
|
903
|
-
extractPaymentSignerAddress,
|
|
904
821
|
getAgentScoreData,
|
|
905
822
|
getGateDegradedState,
|
|
906
823
|
getGateQuotaInfo,
|
|
824
|
+
getSignerVerdict,
|
|
907
825
|
isFixableDenial,
|
|
908
826
|
readX402PaymentHeader,
|
|
909
|
-
verificationAgentInstructions
|
|
910
|
-
verifyWalletSignerMatch
|
|
827
|
+
verificationAgentInstructions
|
|
911
828
|
});
|
|
912
829
|
//# sourceMappingURL=express.js.map
|