@stellar-agent-services/payment-client 0.0.0-stage → 0.1.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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +97 -2
  3. package/dist/browser-storage.d.ts +4 -0
  4. package/dist/browser-storage.d.ts.map +1 -0
  5. package/dist/browser-storage.js +77 -0
  6. package/dist/browser-storage.js.map +1 -0
  7. package/dist/cli.d.ts +3 -0
  8. package/dist/cli.d.ts.map +1 -0
  9. package/dist/cli.js +336 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/client.d.ts +138 -0
  12. package/dist/client.d.ts.map +1 -0
  13. package/dist/client.js +522 -0
  14. package/dist/client.js.map +1 -0
  15. package/dist/conformance.d.ts +21 -0
  16. package/dist/conformance.d.ts.map +1 -0
  17. package/dist/conformance.js +106 -0
  18. package/dist/conformance.js.map +1 -0
  19. package/dist/file-storage.d.ts +4 -0
  20. package/dist/file-storage.d.ts.map +1 -0
  21. package/dist/file-storage.js +54 -0
  22. package/dist/file-storage.js.map +1 -0
  23. package/dist/index.d.ts +10 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +20 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/journal.d.ts +49 -0
  28. package/dist/journal.d.ts.map +1 -0
  29. package/dist/journal.js +100 -0
  30. package/dist/journal.js.map +1 -0
  31. package/dist/local-key-signer.d.ts +4 -0
  32. package/dist/local-key-signer.d.ts.map +1 -0
  33. package/dist/local-key-signer.js +8 -0
  34. package/dist/local-key-signer.js.map +1 -0
  35. package/dist/manifest.d.ts +11 -0
  36. package/dist/manifest.d.ts.map +1 -0
  37. package/dist/manifest.js +50 -0
  38. package/dist/manifest.js.map +1 -0
  39. package/dist/onchain.d.ts +17 -0
  40. package/dist/onchain.d.ts.map +1 -0
  41. package/dist/onchain.js +75 -0
  42. package/dist/onchain.js.map +1 -0
  43. package/dist/policy.d.ts +63 -0
  44. package/dist/policy.d.ts.map +1 -0
  45. package/dist/policy.js +78 -0
  46. package/dist/policy.js.map +1 -0
  47. package/dist/strategies.d.ts +40 -0
  48. package/dist/strategies.d.ts.map +1 -0
  49. package/dist/strategies.js +12 -0
  50. package/dist/strategies.js.map +1 -0
  51. package/dist/verification.d.ts +29 -0
  52. package/dist/verification.d.ts.map +1 -0
  53. package/dist/verification.js +26 -0
  54. package/dist/verification.js.map +1 -0
  55. package/dist/x402-exact-stellar.d.ts +11 -0
  56. package/dist/x402-exact-stellar.d.ts.map +1 -0
  57. package/dist/x402-exact-stellar.js +17 -0
  58. package/dist/x402-exact-stellar.js.map +1 -0
  59. package/package.json +52 -4
@@ -0,0 +1,75 @@
1
+ // On-chain settlement proof: a receipt is a claim until the transaction is confirmed [J16].
2
+ //
3
+ // The transaction must have succeeded, and its token `transfer` event must move exactly what the user
4
+ // approved: the approved asset contract, from the payer, to payTo, for the amount. The expected values
5
+ // come from the journal, never from the provider's receipt.
6
+ import { SOROBAN_RPC_URL } from "@stellar-agent-services/protocol";
7
+ import { rpc, scValToNative, StrKey } from "@stellar/stellar-sdk";
8
+ export function rpcConfirmPayment(options = {}) {
9
+ return async (transaction, expected) => {
10
+ let server = options.server;
11
+ if (server === undefined) {
12
+ const url = options.rpcUrl ?? SOROBAN_RPC_URL[expected.network];
13
+ if (url === undefined)
14
+ return { confirmed: false, reason: `no RPC URL for ${expected.network}; pass rpcUrl` };
15
+ server = new rpc.Server(url);
16
+ }
17
+ // The provider may answer before the RPC node has ingested the ledger.
18
+ for (let attempt = 0; attempt < 10; attempt++) {
19
+ let result;
20
+ try {
21
+ result = await server.getTransaction(transaction);
22
+ }
23
+ catch (error) {
24
+ return { confirmed: false, reason: `the RPC lookup failed: ${error.message}` };
25
+ }
26
+ if (result.status === rpc.Api.GetTransactionStatus.SUCCESS)
27
+ return checkTransfer(result.events.contractEventsXdr.flat(), expected);
28
+ if (result.status === rpc.Api.GetTransactionStatus.FAILED)
29
+ return { confirmed: false, reason: "the transaction failed on chain" };
30
+ await new Promise((resolve) => setTimeout(resolve, 1500));
31
+ }
32
+ return { confirmed: false, reason: "the transaction is not on chain yet" };
33
+ };
34
+ }
35
+ /**
36
+ * Matches a transaction's contract events to the approved payment. The payer must send exactly one
37
+ * transfer of the approved asset, and it must go to payTo for the approved amount.
38
+ */
39
+ export function checkTransfer(events, expected) {
40
+ const transfers = events.flatMap((event) => {
41
+ const contractId = event.contractId();
42
+ // Typed as Opaque[], but the SDK's own Buffer at runtime, in Node and in the browser.
43
+ if (contractId === null || StrKey.encodeContract(contractId) !== expected.asset)
44
+ return [];
45
+ const topics = event.body().v0().topics().map((topic) => scValToNative(topic));
46
+ if (topics[0] !== "transfer" || topics[1] !== expected.payer)
47
+ return [];
48
+ return [{ to: topics[2], amount: transferAmount(event.body().v0().data()) }];
49
+ });
50
+ if (transfers.length === 0)
51
+ return { confirmed: false, reason: "the transaction has no transfer of the approved asset from the payer" };
52
+ if (transfers.length > 1)
53
+ return { confirmed: false, reason: `the transaction has ${transfers.length} transfers from the payer, expected one` };
54
+ const [transfer] = transfers;
55
+ if (transfer.to !== expected.payTo)
56
+ return { confirmed: false, reason: `the transfer went to ${String(transfer.to)}, not ${expected.payTo}` };
57
+ if (transfer.amount !== BigInt(expected.amount)) {
58
+ return { confirmed: false, reason: `the transfer moved ${String(transfer.amount)}, not ${expected.amount} base units` };
59
+ }
60
+ return { confirmed: true };
61
+ }
62
+ // The data is an i128, or a map with `amount` when the payee is a muxed account (CAP-67).
63
+ function transferAmount(data) {
64
+ const value = scValToNative(data);
65
+ if (typeof value === "bigint")
66
+ return value;
67
+ if (typeof value === "object" && value !== null && typeof value.amount === "bigint") {
68
+ return value.amount;
69
+ }
70
+ return undefined;
71
+ }
72
+ export function explorerUrl(network, transaction) {
73
+ return `https://stellar.expert/explorer/${network === "stellar:pubnet" ? "public" : "testnet"}/tx/${transaction}`;
74
+ }
75
+ //# sourceMappingURL=onchain.js.map
@@ -0,0 +1 @@
1
+ {"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MAAM,UAAU,WAAW,CAAC,OAAuB,EAAE,WAAmB;IACtE,OAAO,mCAAmC,OAAO,KAAK,gBAAgB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,OAAO,WAAW,EAAE,CAAC;AACpH,CAAC"}
@@ -0,0 +1,63 @@
1
+ import { type StellarNetwork } from "@stellar-agent-services/protocol";
2
+ export interface SpendingPolicy {
3
+ /** Format version of this document, so a later format can migrate it. */
4
+ version: 1;
5
+ policyId: string;
6
+ /** The human who set the policy, when known. */
7
+ ownerAddress?: string;
8
+ /** The key that pays under this policy. */
9
+ agentAddress: string;
10
+ agentId?: number;
11
+ allowedActions: string[];
12
+ /** Asset contracts that may be paid with. */
13
+ allowedContracts: string[];
14
+ blockedContracts: string[];
15
+ maxValuePerTx: string;
16
+ maxValuePerDay: string;
17
+ /** Unix seconds. */
18
+ validAfter: number;
19
+ validUntil: number;
20
+ /** ERC-8196 name: the maximum allowed provider risk score, 0–100, lower is safer (erc-compatibility.md T4). */
21
+ minVerificationScore?: number;
22
+ stellar: {
23
+ network: StellarNetwork;
24
+ /** Payee lists, since the real payee is an argument of `transfer`, not the called contract. */
25
+ payees: {
26
+ allow?: string[];
27
+ block: string[];
28
+ };
29
+ minProviderLevel?: number;
30
+ /** Payments at or below this amount, and inside every limit, need no prompt. "0": approve every payment. */
31
+ autoApproveUpTo: string;
32
+ };
33
+ }
34
+ export interface PaymentRequest {
35
+ action: string;
36
+ network: string;
37
+ asset: string;
38
+ amount: string;
39
+ payTo: string;
40
+ /** What this policy already paid in the last 24 hours. */
41
+ spentLast24h: bigint;
42
+ /** Already authenticated by the caller's trusted verification source [V1]. */
43
+ verification?: {
44
+ riskScore?: number;
45
+ level?: number;
46
+ };
47
+ now?: Date;
48
+ }
49
+ export interface PolicyViolation {
50
+ field: string;
51
+ message: string;
52
+ }
53
+ export interface PolicyDecision {
54
+ allowed: boolean;
55
+ violations: PolicyViolation[];
56
+ /** Allowed, but above autoApproveUpTo: a human must approve this exact payment. */
57
+ needsApproval: boolean;
58
+ }
59
+ export declare const PAY_ACTION = "x402.pay";
60
+ export declare function defaultPolicy(agentAddress: string, network: StellarNetwork, now?: Date): SpendingPolicy;
61
+ export declare function policyHash(policy: SpendingPolicy): Promise<string>;
62
+ export declare function checkPolicy(policy: SpendingPolicy, request: PaymentRequest): PolicyDecision;
63
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAOA,OAAO,EAA+B,KAAK,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAEpG,MAAM,WAAW,cAAc;IAC7B,yEAAyE;IACzE,OAAO,EAAE,CAAC,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2CAA2C;IAC3C,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,6CAA6C;IAC7C,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,+GAA+G;IAC/G,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,OAAO,EAAE;QACP,OAAO,EAAE,cAAc,CAAC;QACxB,+FAA+F;QAC/F,MAAM,EAAE;YAAE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;YAAC,KAAK,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC;QAC9C,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,4GAA4G;QAC5G,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;CACH;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,YAAY,EAAE,MAAM,CAAC;IACrB,8EAA8E;IAC9E,YAAY,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACtD,GAAG,CAAC,EAAE,IAAI,CAAC;CACZ;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,mFAAmF;IACnF,aAAa,EAAE,OAAO,CAAC;CACxB;AAED,eAAO,MAAM,UAAU,aAAa,CAAC;AAIrC,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAa,GAAG,cAAc,CAe7G;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAElE;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,GAAG,cAAc,CAqC3F"}
package/dist/policy.js ADDED
@@ -0,0 +1,78 @@
1
+ // Spending policy: ERC-8196 field names plus named Stellar extensions (docs/payment-client.md).
2
+ //
3
+ // A failed check blocks the payment; it never passes silently. Amounts are in the asset's base
4
+ // units (USDC: 7 decimals), not a native value.
5
+ //
6
+ // Configured verification limits require trusted evidence [V1], including when set to zero.
7
+ import { canonicalSha256, USDC_ASSET } from "@stellar-agent-services/protocol";
8
+ export const PAY_ACTION = "x402.pay";
9
+ const DAY_SECONDS = 86400;
10
+ export function defaultPolicy(agentAddress, network, now = new Date()) {
11
+ const seconds = Math.floor(now.getTime() / 1000);
12
+ return {
13
+ version: 1,
14
+ policyId: crypto.randomUUID(),
15
+ agentAddress,
16
+ allowedActions: [PAY_ACTION],
17
+ allowedContracts: [USDC_ASSET[network]],
18
+ blockedContracts: [],
19
+ maxValuePerTx: "1000000", // 0.10 USDC
20
+ maxValuePerDay: "10000000", // 1.00 USDC
21
+ validAfter: seconds,
22
+ validUntil: seconds + 30 * DAY_SECONDS,
23
+ stellar: { network, payees: { block: [] }, autoApproveUpTo: "0" },
24
+ };
25
+ }
26
+ export function policyHash(policy) {
27
+ return canonicalSha256(policy);
28
+ }
29
+ export function checkPolicy(policy, request) {
30
+ const violations = [];
31
+ const refuse = (field, message) => violations.push({ field, message });
32
+ const now = Math.floor((request.now ?? new Date()).getTime() / 1000);
33
+ const amount = BigInt(request.amount);
34
+ if (now < policy.validAfter)
35
+ refuse("validAfter", "the policy is not active yet");
36
+ if (now >= policy.validUntil)
37
+ refuse("validUntil", "the policy has expired");
38
+ if (!policy.allowedActions.includes(request.action))
39
+ refuse("allowedActions", `"${request.action}" is not an allowed action`);
40
+ if (request.network !== policy.stellar.network)
41
+ refuse("stellar.network", `the policy is for ${policy.stellar.network}, not ${request.network}`);
42
+ if (!policy.allowedContracts.includes(request.asset))
43
+ refuse("allowedContracts", "this asset is not allowed");
44
+ if (policy.blockedContracts.includes(request.asset))
45
+ refuse("blockedContracts", "this asset is blocked");
46
+ if (policy.stellar.payees.block.includes(request.payTo))
47
+ refuse("stellar.payees.block", "this payee is blocked");
48
+ const allow = policy.stellar.payees.allow;
49
+ if (allow !== undefined && !allow.includes(request.payTo))
50
+ refuse("stellar.payees.allow", "this payee is not on the allow list");
51
+ if (amount <= 0n)
52
+ refuse("amount", "the amount must be above zero");
53
+ if (amount > BigInt(policy.maxValuePerTx))
54
+ refuse("maxValuePerTx", "the amount is above the per-payment limit");
55
+ if (request.spentLast24h + amount > BigInt(policy.maxValuePerDay))
56
+ refuse("maxValuePerDay", "the payment would exceed the 24-hour limit");
57
+ for (const [field, limit, observed, maximum] of [
58
+ ["minVerificationScore", policy.minVerificationScore, request.verification?.riskScore, 100],
59
+ ["stellar.minProviderLevel", policy.stellar.minProviderLevel, request.verification?.level, 3],
60
+ ]) {
61
+ if (limit === undefined)
62
+ continue;
63
+ if (!Number.isInteger(limit) || limit < 0 || limit > maximum) {
64
+ refuse(field, `[V1] the verification limit must be an integer from 0 to ${maximum}`);
65
+ }
66
+ else if (observed === undefined || !Number.isInteger(observed) || observed < 0 || observed > maximum) {
67
+ refuse(field, "[V1] trusted verification evidence is missing or invalid");
68
+ }
69
+ else if (field === "minVerificationScore" ? observed > limit : observed < limit) {
70
+ refuse(field, field === "minVerificationScore"
71
+ ? "[V1] the provider exceeds the permitted risk score"
72
+ : "[V1] the provider is below the required verification level");
73
+ }
74
+ }
75
+ const allowed = violations.length === 0;
76
+ return { allowed, violations, needsApproval: allowed && amount > BigInt(policy.stellar.autoApproveUpTo) };
77
+ }
78
+ //# sourceMappingURL=policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,EAAE;AACF,+FAA+F;AAC/F,gDAAgD;AAChD,EAAE;AACF,4FAA4F;AAE5F,OAAO,EAAE,eAAe,EAAE,UAAU,EAAuB,MAAM,kCAAkC,CAAC;AAyDpG,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC;AAErC,MAAM,WAAW,GAAG,KAAK,CAAC;AAE1B,MAAM,UAAU,aAAa,CAAC,YAAoB,EAAE,OAAuB,EAAE,GAAG,GAAG,IAAI,IAAI,EAAE;IAC3F,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,OAAO;QACL,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,MAAM,CAAC,UAAU,EAA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ent-services/protocol";
2
+ import type { PaymentPayload, PaymentRequirements } from "@x402/core/types";
3
+ import type { ClientStellarSigner } from "@x402/stellar";
4
+ /** Who holds the key: the SEP-43 shape @x402/stellar signs with. */
5
+ export interface Signer extends ClientStellarSigner {
6
+ /**
7
+ * For a wallet that enforces its own limits on chain: what it can still pay of `asset`, in base units.
8
+ * Undefined when it sets no limit. The core refuses a payment above it, and refuses when it throws.
9
+ */
10
+ budget?(network: StellarNetwork, asset: string): Promise<string | undefined>;
11
+ }
12
+ /** A challenge entry's payment, signed and ready for the PAYMENT-SIGNATURE header. */
13
+ export type SignedPayload = Pick<PaymentPayload, "x402Version" | "payload">;
14
+ /** What the user approved, as journaled in `sending`. */
15
+ export interface ExpectedPayment {
16
+ network: StellarNetwork;
17
+ /** The asset's contract address (C...), as in the challenge. */
18
+ asset: string;
19
+ /** Base units. */
20
+ amount: string;
21
+ payTo: string;
22
+ payer: string;
23
+ }
24
+ export interface Confirmation {
25
+ confirmed: boolean;
26
+ /** Why the payment is not confirmed. */
27
+ reason?: string;
28
+ }
29
+ /** How an x402 challenge entry is paid, and how that payment is proven. */
30
+ export interface PaymentMethod {
31
+ /** A stable name. It is journaled with each payment, so recovery confirms with the same method. */
32
+ readonly id: string;
33
+ /** Whether this method can pay the entry. False for any scheme or network it does not know. */
34
+ matches(requirements: PaymentRequirements): boolean;
35
+ /** Signs the payment. The only step that uses the signer; the core runs it once per job. */
36
+ createPayload(requirements: PaymentRequirements, signer: Signer): Promise<SignedPayload>;
37
+ /** Checks the transaction against what the user approved, never against the provider's receipt [J16]. */
38
+ confirm(transaction: string, expected: ExpectedPayment): Promise<Confirmation>;
39
+ }
40
+ //# sourceMappingURL=strategies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategies.d.ts","sourceRoot":"","sources":["../src/strategies.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEzD,oEAAoE;AACpE,MAAM,WAAW,MAAO,SAAQ,mBAAmB;IACjD;;;OAGG;IACH,MAAM,CAAC,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CAC9E;AAED,sFAAsF;AACtF,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,EAAE,aAAa,GAAG,SAAS,CAAC,CAAC;AAE5E,yDAAyD;AACzD,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,cAAc,CAAC;IACxB,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,kBAAkB;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,OAAO,CAAC;IACnB,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,2EAA2E;AAC3E,MAAM,WAAW,aAAa;IAC5B,mGAAmG;IACnG,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,+FAA+F;IAC/F,OAAO,CAAC,YAAY,EAAE,mBAAmB,GAAG,OAAO,CAAC;IACpD,4FAA4F;IAC5F,aAAa,CAAC,YAAY,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACzF,yGAAyG;IACzG,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAChF"}
@@ -0,0 +1,12 @@
1
+ // The two strategies the core plugs in (docs/payment-client.md, "Strategies"):
2
+ //
3
+ // Signer who holds the key: the built-in local key, later browser wallets, passkey smart
4
+ // accounts or other policy wallets
5
+ // PaymentMethod how an x402 challenge entry is paid and proven: the built-in x402 `exact` on Stellar
6
+ //
7
+ // The core keeps every safety step whatever is plugged in. The terms the user approves come from the
8
+ // challenge, never from an adapter. Policy and approval run before any signing, `sending` is journaled
9
+ // before anything is sent, and confirmation runs against the journal. Adapters can add capabilities,
10
+ // but they can't skip any of these steps.
11
+ export {};
12
+ //# sourceMappingURL=strategies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategies.js","sourceRoot":"","sources":["../src/strategies.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,EAAE;AACF,mGAAmG;AACnG,oDAAoD;AACpD,wGAAwG;AACxG,EAAE;AACF,qGAAqG;AACrG,uGAAuG;AACvG,qGAAqG;AACrG,0CAA0C"}
@@ -0,0 +1,29 @@
1
+ import type { ConformanceLevel, StellarNetwork } from "@stellar-agent-services/protocol";
2
+ export interface VerificationSubject {
3
+ network: StellarNetwork;
4
+ payTo: string;
5
+ manifestUrl: string;
6
+ /** SHA-256 of the approved manifest's RFC 8785 canonical JSON. */
7
+ manifestSha256: string;
8
+ agentId?: number;
9
+ }
10
+ export interface ProviderVerification extends VerificationSubject {
11
+ /** RFC 3339: when the source checked this provider, and when its evidence becomes too old to use. */
12
+ checkedAt: string;
13
+ expiresAt: string;
14
+ /** ERC-8126 risk score, 0–100, lower is better. Separate from the §8 conformance score. */
15
+ riskScore?: number;
16
+ /** Provider Standard §8: 0, Described (1), Payable (2), Recoverable (3). */
17
+ level?: ConformanceLevel;
18
+ }
19
+ /**
20
+ * Installed by the application, never selected by a provider. A source must authenticate its trusted
21
+ * validators, verify receipt hashes against registry records when used, and apply bounded network timeouts.
22
+ * Return undefined when there is no trustworthy evidence. Do not copy a manifest's claims into an answer.
23
+ */
24
+ export interface VerificationSource {
25
+ read(subject: VerificationSubject): Promise<ProviderVerification | undefined>;
26
+ }
27
+ /** Unknown, stale or mismatched evidence never satisfies a configured minimum [V1]. */
28
+ export declare function matchesVerification(evidence: ProviderVerification | undefined, subject: VerificationSubject, now?: number): evidence is ProviderVerification;
29
+ //# sourceMappingURL=verification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verification.d.ts","sourceRoot":"","sources":["../src/verification.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAEzF,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,kEAAkE;IAClE,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAC/D,qGAAqG;IACrG,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,2FAA2F;IAC3F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,KAAK,CAAC,EAAE,gBAAgB,CAAC;CAC1B;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAC;CAC/E;AAED,uFAAuF;AACvF,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,oBAAoB,GAAG,SAAS,EAC1C,OAAO,EAAE,mBAAmB,EAC5B,GAAG,SAAa,GACf,QAAQ,IAAI,oBAAoB,CAgBlC"}
@@ -0,0 +1,26 @@
1
+ // The application's trusted verification source [V1]. Provider-supplied badges or receipts alone are not proof.
2
+ // Sources authenticate their validator and receipt/registry data; the core binds their answer to this payment.
3
+ /** Unknown, stale or mismatched evidence never satisfies a configured minimum [V1]. */
4
+ export function matchesVerification(evidence, subject, now = Date.now()) {
5
+ if (evidence === undefined || evidence === null || typeof evidence !== "object")
6
+ return false;
7
+ if (evidence.network !== subject.network || evidence.payTo !== subject.payTo ||
8
+ evidence.manifestUrl !== subject.manifestUrl || evidence.manifestSha256 !== subject.manifestSha256 ||
9
+ evidence.agentId !== subject.agentId)
10
+ return false;
11
+ if (evidence.riskScore !== undefined &&
12
+ (!Number.isInteger(evidence.riskScore) || evidence.riskScore < 0 || evidence.riskScore > 100))
13
+ return false;
14
+ if (evidence.level !== undefined &&
15
+ (!Number.isInteger(evidence.level) || evidence.level < 0 || evidence.level > 3))
16
+ return false;
17
+ // Requiring an explicit time zone avoids interpreting a source's dates in the machine's local zone.
18
+ const timestamp = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
19
+ if (typeof evidence.checkedAt !== "string" || typeof evidence.expiresAt !== "string" ||
20
+ !timestamp.test(evidence.checkedAt) || !timestamp.test(evidence.expiresAt))
21
+ return false;
22
+ const checkedAt = Date.parse(evidence.checkedAt);
23
+ const expiresAt = Date.parse(evidence.expiresAt);
24
+ return Number.isFinite(checkedAt) && Number.isFinite(expiresAt) && checkedAt <= now && now < expiresAt;
25
+ }
26
+ //# sourceMappingURL=verification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verification.js","sourceRoot":"","sources":["../src/verification.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,+GAA+G;AAgC/G,uFAAuF;AACvF,MAAM,UAAU,mBAAmB,CACjC,QAA0C,EAC1C,OAA4B,EAC5B,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;IAEhB,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,IAAI,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC9F,IAAI,QAAQ,CAAC,OAAO,KAAK,OAAO,CAAC,OAAO,IAAI,QAAQ,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK;QACxE,QAAQ,CAAC,WAAW,KAAK,OAAO,CAAC,WAAW,IAAI,QAAQ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.js";
3
+ export declare const X402_EXACT_STELLAR = "x402-exact-stellar";
4
+ export interface X402ExactStellarOptions {
5
+ /** Soroban RPC for signing and confirmation. Defaults to the public testnet RPC. */
6
+ rpcUrl?: string;
7
+ /** Reads transactions for confirmation. Defaults to an rpc.Server; tests pass a fake chain. */
8
+ server?: TransactionReader;
9
+ }
10
+ export declare function x402ExactStellar(options?: X402ExactStellarOptions): PaymentMethod;
11
+ //# sourceMappingURL=x402-exact-stellar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x402-exact-stellar.d.ts","sourceRoot":"","sources":["../src/x402-exact-stellar.ts"],"names":[],"mappings":"AAMA,OAAO,EAAqB,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AAEvD,MAAM,WAAW,uBAAuB;IACtC,oFAAoF;IACpF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+FAA+F;IAC/F,MAAM,CAAC,EAAE,iBAAiB,CAAC;CAC5B;AAED,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,uBAA4B,GAAG,aAAa,CAQrF"}
@@ -0,0 +1,17 @@
1
+ // The built-in payment method, and the only one Provider Standard v1 allows: x402 `exact` on Stellar.
2
+ // The signer authorizes one SAC `transfer(payer, payTo, amount)`, the provider's facilitator submits
3
+ // it, and the `transfer` event proves it (onchain.ts).
4
+ import { STELLAR_NETWORKS } from "@stellar-agent-services/protocol";
5
+ import { ExactStellarScheme } from "@x402/stellar/exact/client";
6
+ import { rpcConfirmPayment } from "./onchain.js";
7
+ export const X402_EXACT_STELLAR = "x402-exact-stellar";
8
+ export function x402ExactStellar(options = {}) {
9
+ const rpcConfig = options.rpcUrl === undefined ? undefined : { url: options.rpcUrl };
10
+ return {
11
+ id: X402_EXACT_STELLAR,
12
+ matches: (requirements) => requirements.scheme === "exact" && STELLAR_NETWORKS.includes(requirements.network),
13
+ createPayload: (requirements, signer) => new ExactStellarScheme(signer, rpcConfig).createPaymentPayload(2, requirements),
14
+ confirm: rpcConfirmPayment(options),
15
+ };
16
+ }
17
+ //# sourceMappingURL=x402-exact-stellar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x402-exact-stellar.js","sourceRoot":"","sources":["../src/x402-exact-stellar.ts"],"names":[],"mappings":"AAAA,sGAAsG;AACtG,qGAAqG;AACrG,uDAAuD;AAEvD,OAAO,EAAE,gBAAgB,EAAuB,MAAM,kCAAkC,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAA0B,MAAM,cAAc,CAAC;AAGzE,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAC;AASvD,MAAM,UAAU,gBAAgB,CAAC,UAAmC,EAAE;IACpE,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;IACrF,OAAO;QACL,EAAE,EAAE,kBAAkB;QACtB,OAAO,EAAE,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,KAAK,OAAO,IAAI,gBAAgB,CAAC,QAAQ,CAAC,YAAY,CAAC,OAAyB,CAAC;QAC/H,aAAa,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,kBAAkB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,oBAAoB,CAAC,CAAC,EAAE,YAAY,CAAC;QACxH,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC;KACpC,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
1
  {
2
2
  "name": "@stellar-agent-services/payment-client",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Buyer-side payment client: approval, spending policy, hash-chained journal, payment and job recovery (PoC).",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/AlgoriaLabs/stellar-agent-services.git",
10
+ "directory": "packages/payment-client"
11
+ },
12
+ "engines": {
13
+ "node": ">=22.13"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ },
20
+ "./conformance": {
21
+ "types": "./dist/conformance.d.ts",
22
+ "default": "./dist/conformance.js"
23
+ },
24
+ "./node": {
25
+ "types": "./dist/file-storage.d.ts",
26
+ "default": "./dist/file-storage.js"
27
+ },
28
+ "./browser": {
29
+ "types": "./dist/browser-storage.d.ts",
30
+ "default": "./dist/browser-storage.js"
31
+ }
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "!dist/.tsbuildinfo"
36
+ ],
37
+ "scripts": {
38
+ "build": "tsc -b"
39
+ },
40
+ "dependencies": {
41
+ "@stellar-agent-services/protocol": "0.1.1",
42
+ "@stellar/stellar-sdk": "16.4.1",
43
+ "@x402/core": "2.28.0",
44
+ "@x402/stellar": "2.28.0",
45
+ "ajv": "8.20.0"
46
+ },
47
+ "bin": {
48
+ "stellar-pay": "./dist/cli.js"
49
+ },
50
+ "devDependencies": {
51
+ "@stellar-agent-services/provider-kit": "0.1.1",
52
+ "fake-indexeddb": "6.2.5"
53
+ }
54
+ }