@asgcard/pay 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.
- package/CHANGELOG.md +90 -0
- package/LICENSE +21 -0
- package/README.md +393 -0
- package/dist/cjs/adapters/base.js +174 -0
- package/dist/cjs/adapters/base.js.map +1 -0
- package/dist/cjs/adapters/evm.js +263 -0
- package/dist/cjs/adapters/evm.js.map +1 -0
- package/dist/cjs/adapters/index.js +13 -0
- package/dist/cjs/adapters/index.js.map +1 -0
- package/dist/cjs/adapters/stellar.js +173 -0
- package/dist/cjs/adapters/stellar.js.map +1 -0
- package/dist/cjs/adapters/stripe.js +338 -0
- package/dist/cjs/adapters/stripe.js.map +1 -0
- package/dist/cjs/adapters/types.js +3 -0
- package/dist/cjs/adapters/types.js.map +1 -0
- package/dist/cjs/client.js +309 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/logger.js +7 -0
- package/dist/cjs/logger.js.map +1 -0
- package/dist/cjs/mpp.js +187 -0
- package/dist/cjs/mpp.js.map +1 -0
- package/dist/cjs/policy.js +71 -0
- package/dist/cjs/policy.js.map +1 -0
- package/dist/cjs/stellar.js +87 -0
- package/dist/cjs/stellar.js.map +1 -0
- package/dist/esm/adapters/base.js +170 -0
- package/dist/esm/adapters/base.js.map +1 -0
- package/dist/esm/adapters/evm.js +258 -0
- package/dist/esm/adapters/evm.js.map +1 -0
- package/dist/esm/adapters/index.js +5 -0
- package/dist/esm/adapters/index.js.map +1 -0
- package/dist/esm/adapters/stellar.js +136 -0
- package/dist/esm/adapters/stellar.js.map +1 -0
- package/dist/esm/adapters/stripe.js +334 -0
- package/dist/esm/adapters/stripe.js.map +1 -0
- package/dist/esm/adapters/types.js +2 -0
- package/dist/esm/adapters/types.js.map +1 -0
- package/dist/esm/client.js +302 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/logger.js +3 -0
- package/dist/esm/logger.js.map +1 -0
- package/dist/esm/mpp.js +175 -0
- package/dist/esm/mpp.js.map +1 -0
- package/dist/esm/policy.js +67 -0
- package/dist/esm/policy.js.map +1 -0
- package/dist/esm/stellar.js +50 -0
- package/dist/esm/stellar.js.map +1 -0
- package/dist/types/adapters/base.d.ts +53 -0
- package/dist/types/adapters/base.d.ts.map +1 -0
- package/dist/types/adapters/evm.d.ts +81 -0
- package/dist/types/adapters/evm.d.ts.map +1 -0
- package/dist/types/adapters/index.d.ts +6 -0
- package/dist/types/adapters/index.d.ts.map +1 -0
- package/dist/types/adapters/stellar.d.ts +67 -0
- package/dist/types/adapters/stellar.d.ts.map +1 -0
- package/dist/types/adapters/stripe.d.ts +206 -0
- package/dist/types/adapters/stripe.d.ts.map +1 -0
- package/dist/types/adapters/types.d.ts +35 -0
- package/dist/types/adapters/types.d.ts.map +1 -0
- package/dist/types/client.d.ts +89 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger.d.ts +10 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/types/mpp.d.ts +153 -0
- package/dist/types/mpp.d.ts.map +1 -0
- package/dist/types/policy.d.ts +40 -0
- package/dist/types/policy.d.ts.map +1 -0
- package/dist/types/stellar.d.ts +27 -0
- package/dist/types/stellar.d.ts.map +1 -0
- package/package.json +86 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { PaymentAdapter } from './types';
|
|
2
|
+
import { Logger } from '../logger';
|
|
3
|
+
import { MppChallenge } from '../mpp';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for the Stripe MPP adapter.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const adapter = new StripePaymentAdapter({
|
|
10
|
+
* stripeSecretKey: process.env.STRIPE_SECRET_KEY!,
|
|
11
|
+
* networkId: 'my-business-network',
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export interface StripeAdapterOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Stripe secret key (sk_test_... or sk_live_...).
|
|
18
|
+
* Used to create SPTs and PaymentIntents.
|
|
19
|
+
*/
|
|
20
|
+
stripeSecretKey: string;
|
|
21
|
+
/**
|
|
22
|
+
* Stripe Business Network ID.
|
|
23
|
+
* Found in Dashboard → Settings → Business profile.
|
|
24
|
+
*/
|
|
25
|
+
networkId?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Accepted payment method types.
|
|
28
|
+
* @default ['card']
|
|
29
|
+
*/
|
|
30
|
+
paymentMethodTypes?: string[];
|
|
31
|
+
/**
|
|
32
|
+
* Default payment method ID for autonomous agents.
|
|
33
|
+
* e.g. 'pm_card_visa' for test mode.
|
|
34
|
+
* If set, the adapter can create SPTs autonomously.
|
|
35
|
+
*/
|
|
36
|
+
paymentMethodId?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Default currency for payments.
|
|
39
|
+
* @default 'usd'
|
|
40
|
+
*/
|
|
41
|
+
currency?: string;
|
|
42
|
+
/**
|
|
43
|
+
* SPT expiration window in seconds.
|
|
44
|
+
* @default 300 (5 minutes)
|
|
45
|
+
*/
|
|
46
|
+
sptExpirySeconds?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Stripe API base URL.
|
|
49
|
+
* @default 'https://api.stripe.com'
|
|
50
|
+
*/
|
|
51
|
+
stripeApiBase?: string;
|
|
52
|
+
/** Optional logger. SDK is silent by default. */
|
|
53
|
+
logger?: Logger;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Result of creating a Shared Payment Token.
|
|
57
|
+
*/
|
|
58
|
+
interface SptResult {
|
|
59
|
+
id: string;
|
|
60
|
+
object: string;
|
|
61
|
+
expires_at?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Result of creating/confirming a PaymentIntent.
|
|
65
|
+
*/
|
|
66
|
+
interface PaymentIntentResult {
|
|
67
|
+
id: string;
|
|
68
|
+
status: string;
|
|
69
|
+
amount: number;
|
|
70
|
+
currency: string;
|
|
71
|
+
next_action?: {
|
|
72
|
+
crypto_display_details?: {
|
|
73
|
+
deposit_addresses?: Record<string, {
|
|
74
|
+
address: string;
|
|
75
|
+
supported_tokens?: Array<{
|
|
76
|
+
token_currency: string;
|
|
77
|
+
token_contract_address: string;
|
|
78
|
+
}>;
|
|
79
|
+
}>;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* StripePaymentAdapter — Machine Payments Protocol (MPP) settlement.
|
|
85
|
+
*
|
|
86
|
+
* Implements the full MPP flow for Stripe:
|
|
87
|
+
* 1. Receives 402 + `WWW-Authenticate: Payment` challenge
|
|
88
|
+
* 2. Creates a Shared Payment Token (SPT) via Stripe API
|
|
89
|
+
* 3. Builds MPP Credential with SPT
|
|
90
|
+
* 4. Returns credential for `Authorization: Payment` header
|
|
91
|
+
*
|
|
92
|
+
* Works in two modes:
|
|
93
|
+
* - **Autonomous** (with paymentMethodId): Creates SPTs automatically
|
|
94
|
+
* - **Delegated** (without): Requires external SPT provisioning via `setSptToken()`
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* // Autonomous mode — agent has a payment method on file
|
|
99
|
+
* const adapter = new StripePaymentAdapter({
|
|
100
|
+
* stripeSecretKey: 'sk_test_...',
|
|
101
|
+
* networkId: 'my-network',
|
|
102
|
+
* paymentMethodId: 'pm_card_visa', // test card
|
|
103
|
+
* });
|
|
104
|
+
*
|
|
105
|
+
* // Delegated mode — external system provides SPTs
|
|
106
|
+
* const adapter = new StripePaymentAdapter({
|
|
107
|
+
* stripeSecretKey: 'sk_test_...',
|
|
108
|
+
* });
|
|
109
|
+
* adapter.setSptToken('spt_...');
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* @see https://mpp.dev/payment-methods/stripe — MPP Stripe method spec
|
|
113
|
+
* @see https://docs.stripe.com/agentic-commerce/concepts/shared-payment-tokens
|
|
114
|
+
*/
|
|
115
|
+
export declare class StripePaymentAdapter implements PaymentAdapter {
|
|
116
|
+
readonly chainName = "Stripe MPP";
|
|
117
|
+
readonly caip2Id: string;
|
|
118
|
+
private secretKey;
|
|
119
|
+
private networkId;
|
|
120
|
+
private paymentMethodTypes;
|
|
121
|
+
private paymentMethodId;
|
|
122
|
+
private currency;
|
|
123
|
+
private sptExpirySeconds;
|
|
124
|
+
private stripeApiBase;
|
|
125
|
+
private log;
|
|
126
|
+
/** Externally-provided SPT for delegated mode */
|
|
127
|
+
private externalSpt;
|
|
128
|
+
/** Last MPP challenge processed (for credential building) */
|
|
129
|
+
private lastChallenge;
|
|
130
|
+
constructor(options: StripeAdapterOptions);
|
|
131
|
+
/**
|
|
132
|
+
* Set or update an externally-provided SPT token.
|
|
133
|
+
* Used in delegated mode when an external system provides the SPT.
|
|
134
|
+
*/
|
|
135
|
+
setSptToken(token: string): void;
|
|
136
|
+
/**
|
|
137
|
+
* Store a parsed MPP challenge for credential building.
|
|
138
|
+
* Called by OwsClient when a 402 with `WWW-Authenticate: Payment method="stripe"` is received.
|
|
139
|
+
*/
|
|
140
|
+
setMppChallenge(challenge: MppChallenge): void;
|
|
141
|
+
/**
|
|
142
|
+
* Get the last built MPP credential (base64url-encoded).
|
|
143
|
+
* Used by OwsClient to populate the `Authorization: Payment` header.
|
|
144
|
+
*/
|
|
145
|
+
getLastCredential(): string | null;
|
|
146
|
+
private _lastCredential;
|
|
147
|
+
getAddress(): string;
|
|
148
|
+
/**
|
|
149
|
+
* Execute a Stripe MPP payment.
|
|
150
|
+
*
|
|
151
|
+
* This method handles the full SPT lifecycle:
|
|
152
|
+
* 1. If an external SPT is set → use it directly
|
|
153
|
+
* 2. If paymentMethodId is set → create SPT autonomously via Stripe API
|
|
154
|
+
* 3. Build MPP Credential with the SPT
|
|
155
|
+
* 4. Return credential string (used as "tx hash" equivalent)
|
|
156
|
+
*
|
|
157
|
+
* @param destination - Recipient (Stripe account or payment endpoint)
|
|
158
|
+
* @param amount - Amount in smallest currency unit (e.g. cents)
|
|
159
|
+
* @param network - Network identifier (ignored for Stripe, kept for interface compat)
|
|
160
|
+
* @returns Base64url-encoded MPP credential string, or null on failure
|
|
161
|
+
*/
|
|
162
|
+
pay(destination: string, amount: string, network: string): Promise<string | null>;
|
|
163
|
+
/**
|
|
164
|
+
* Create a Shared Payment Token (SPT) via Stripe API.
|
|
165
|
+
*
|
|
166
|
+
* Test mode: POST /v1/test_helpers/shared_payment/granted_tokens
|
|
167
|
+
* Live mode: POST /v1/shared_payment/issued_tokens (TBD by Stripe)
|
|
168
|
+
*/
|
|
169
|
+
createSpt(amount: number, currency: string): Promise<SptResult | null>;
|
|
170
|
+
/**
|
|
171
|
+
* Create and confirm a PaymentIntent using an SPT.
|
|
172
|
+
* Used in fallback mode (no MPP challenge, direct Stripe API).
|
|
173
|
+
*/
|
|
174
|
+
createPaymentIntent(sptId: string, amount: number, currency: string): Promise<PaymentIntentResult | null>;
|
|
175
|
+
/**
|
|
176
|
+
* Create a crypto deposit-mode PaymentIntent.
|
|
177
|
+
* This is the verified-working flow for MPP on Stripe.
|
|
178
|
+
* Uses Tempo network + USDC stablecoins.
|
|
179
|
+
*
|
|
180
|
+
* @param amount - Amount in cents (e.g. 100 = $1.00)
|
|
181
|
+
* @param currency - Currency code (default: 'usd')
|
|
182
|
+
* @returns PaymentIntentResult with deposit address, or null on failure
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* const pi = await adapter.createCryptoPaymentIntent(100, 'usd');
|
|
187
|
+
* // pi.next_action.crypto_display_details.deposit_addresses.tempo.address
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
createCryptoPaymentIntent(amount: number, currency?: string): Promise<PaymentIntentResult | null>;
|
|
191
|
+
/**
|
|
192
|
+
* Build and return a fully-formed MPP Challenge for server-side use.
|
|
193
|
+
* Useful if you want to GATE your own API with MPP 402.
|
|
194
|
+
*
|
|
195
|
+
* @param amount - Amount to charge (in smallest unit)
|
|
196
|
+
* @param options - Challenge options
|
|
197
|
+
* @returns WWW-Authenticate header value
|
|
198
|
+
*/
|
|
199
|
+
buildServerChallenge(amount: string, options?: {
|
|
200
|
+
currency?: string;
|
|
201
|
+
description?: string;
|
|
202
|
+
expiresInSeconds?: number;
|
|
203
|
+
}): string;
|
|
204
|
+
}
|
|
205
|
+
export {};
|
|
206
|
+
//# sourceMappingURL=stripe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe.d.ts","sourceRoot":"","sources":["../../../src/adapters/stripe.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PaymentAdapter — generic interface for on-chain settlement.
|
|
3
|
+
*
|
|
4
|
+
* Adapters implement this interface to provide settlement on different
|
|
5
|
+
* chains (Base, Stellar, Arbitrum, Solana, etc.) while the OwsClient
|
|
6
|
+
* remains chain-agnostic.
|
|
7
|
+
*
|
|
8
|
+
* @see OWS §07 — Supported Chains (CAIP-2 identifiers)
|
|
9
|
+
*/
|
|
10
|
+
export interface PaymentAdapter {
|
|
11
|
+
/**
|
|
12
|
+
* Execute an on-chain payment.
|
|
13
|
+
* @param destination - Recipient address (chain-native format)
|
|
14
|
+
* @param amount - Amount in atomic units (wei, stroops, lamports)
|
|
15
|
+
* @param network - Network identifier ('mainnet' | 'testnet' | CAIP-2 ID)
|
|
16
|
+
* @returns Transaction hash on success, null on failure
|
|
17
|
+
*/
|
|
18
|
+
pay(destination: string, amount: string, network: string): Promise<string | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Get the public address of this adapter's signing account.
|
|
21
|
+
*/
|
|
22
|
+
getAddress(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Human-readable chain name for logging.
|
|
25
|
+
*/
|
|
26
|
+
readonly chainName: string;
|
|
27
|
+
/**
|
|
28
|
+
* CAIP-2 chain identifier.
|
|
29
|
+
* @example "eip155:8453" (Base Mainnet)
|
|
30
|
+
* @example "eip155:84532" (Base Sepolia)
|
|
31
|
+
* @example "stellar:pubnet"
|
|
32
|
+
*/
|
|
33
|
+
readonly caip2Id: string;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapters/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAElF;;OAEG;IACH,UAAU,IAAI,MAAM,CAAC;IAErB;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { PaymentAdapter } from './adapters/types';
|
|
3
|
+
import { BudgetPolicy, PolicyEngine } from './policy';
|
|
4
|
+
import { Logger } from './logger';
|
|
5
|
+
export interface OWSClientOptions {
|
|
6
|
+
/** Base URL of the API that returns 402 challenges. */
|
|
7
|
+
baseURL: string;
|
|
8
|
+
/** Budget policy for the agent. */
|
|
9
|
+
policy: BudgetPolicy;
|
|
10
|
+
/** Any chain adapter implementing PaymentAdapter (EVM, Stellar, Stripe, etc.) */
|
|
11
|
+
adapter: PaymentAdapter;
|
|
12
|
+
/**
|
|
13
|
+
* Optional logger function. If omitted, SDK is silent.
|
|
14
|
+
* Pass `console.log` for verbose output.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const client = new OwsClient({
|
|
19
|
+
* baseURL: 'https://api.example.com',
|
|
20
|
+
* policy: { monthlyBudget: 10, maxAmountPerTransaction: 1 },
|
|
21
|
+
* adapter: new EvmPaymentAdapter({ chain: 'base' }),
|
|
22
|
+
* logger: console.log,
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
logger?: Logger;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* OwsClient — Dual-protocol autonomous HTTP client for AI agents.
|
|
30
|
+
*
|
|
31
|
+
* Supports BOTH payment protocols:
|
|
32
|
+
* - **x402** (Coinbase/Cloudflare): JSON body challenges + X-PAYMENT header
|
|
33
|
+
* - **MPP** (Stripe/Tempo): WWW-Authenticate challenges + Authorization: Payment header
|
|
34
|
+
*
|
|
35
|
+
* Wraps Axios with an interceptor that automatically detects the protocol,
|
|
36
|
+
* validates spend against PolicyEngine, settles via pluggable adapter,
|
|
37
|
+
* and retries — all without human interaction.
|
|
38
|
+
*
|
|
39
|
+
* @see https://openwallet.sh — Open Wallet Standard specification
|
|
40
|
+
* @see https://x402.org — x402 payment protocol
|
|
41
|
+
* @see https://mpp.dev — Machine Payments Protocol
|
|
42
|
+
* @see https://pay.asgcard.dev — Production ASG Pay infrastructure
|
|
43
|
+
*/
|
|
44
|
+
export declare class OwsClient {
|
|
45
|
+
readonly api: AxiosInstance;
|
|
46
|
+
readonly policyEngine: PolicyEngine;
|
|
47
|
+
private adapter;
|
|
48
|
+
private log;
|
|
49
|
+
constructor(options: OWSClientOptions);
|
|
50
|
+
/**
|
|
51
|
+
* Handle a 402 Payment Required challenge.
|
|
52
|
+
* Auto-detects protocol (MPP vs x402) and routes accordingly.
|
|
53
|
+
*/
|
|
54
|
+
private handle402;
|
|
55
|
+
/**
|
|
56
|
+
* Handle an MPP 402: parse WWW-Authenticate, create credential, retry.
|
|
57
|
+
*/
|
|
58
|
+
private handleMpp402;
|
|
59
|
+
/**
|
|
60
|
+
* Handle an x402 402: parse JSON body, settle on-chain, retry with X-PAYMENT.
|
|
61
|
+
*/
|
|
62
|
+
private handleX402;
|
|
63
|
+
/**
|
|
64
|
+
* Select the best challenge when multiple are offered.
|
|
65
|
+
* Prefers the method matching the current adapter.
|
|
66
|
+
*/
|
|
67
|
+
private selectChallenge;
|
|
68
|
+
/**
|
|
69
|
+
* Extract USD amount from MPP request object.
|
|
70
|
+
*/
|
|
71
|
+
private extractMppUsdAmount;
|
|
72
|
+
/**
|
|
73
|
+
* Extract USD amount from x402 challenge.
|
|
74
|
+
* Priority: resource.usdAmount → accepts[].maxAmountRequired → heuristic from description.
|
|
75
|
+
*/
|
|
76
|
+
private extractUsdAmount;
|
|
77
|
+
private isStripeAdapter;
|
|
78
|
+
/**
|
|
79
|
+
* High-level helper for AI agents.
|
|
80
|
+
* The agent simply calls performTask() — the interceptor handles
|
|
81
|
+
* everything else (payment, policy, retry) transparently.
|
|
82
|
+
*/
|
|
83
|
+
performTask(endpoint: string, data?: any): Promise<any>;
|
|
84
|
+
/**
|
|
85
|
+
* GET request with autonomous 402 handling.
|
|
86
|
+
*/
|
|
87
|
+
get(endpoint: string): Promise<any>;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAA6B,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,MAAM,EAAc,MAAM,UAAU,CAAC;AAU9C,MAAM,WAAW,gBAAgB;IAC/B,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,mCAAmC;IACnC,MAAM,EAAE,YAAY,CAAC;IACrB,iFAAiF;IACjF,OAAO,EAAE,cAAc,CAAC;IACxB;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAuBD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,SAAS;IACpB,SAAgB,GAAG,EAAE,aAAa,CAAC;IACnC,SAAgB,YAAY,EAAE,YAAY,CAAC;IAC3C,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,GAAG,CAAS;gBAER,OAAO,EAAE,gBAAgB;IAqBrC;;;OAGG;YACW,SAAS;IAsBvB;;OAEG;YACW,YAAY;IAuG1B;;OAEG;YACW,UAAU;IA8ExB;;;OAGG;IACH,OAAO,CAAC,eAAe;IAavB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAW3B;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IA6BxB,OAAO,CAAC,eAAe;IAMvB;;;;OAIG;IACG,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAO7D;;OAEG;IACG,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;CAI1C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { OwsClient, OWSClientOptions } from './client';
|
|
2
|
+
export { PolicyEngine, BudgetPolicy } from './policy';
|
|
3
|
+
export type { Logger } from './logger';
|
|
4
|
+
export { parseMppChallenge, parseMppChallenges, decodeChallengeRequest, buildMppCredential, buildAuthorizationHeader, parseMppReceipt, detectProtocol, extractMppChallenges, base64urlEncode, base64urlDecode, } from './mpp';
|
|
5
|
+
export type { MppChallenge, MppCredential, MppRequestObject, MppStripePayload, MppTempoPayload, MppReceipt, MppMethod, MppIntent, } from './mpp';
|
|
6
|
+
export { EvmPaymentAdapter, listEvmChains } from './adapters/evm';
|
|
7
|
+
export type { EvmAdapterOptions, EvmChainName } from './adapters/evm';
|
|
8
|
+
export { StripePaymentAdapter } from './adapters/stripe';
|
|
9
|
+
export type { StripeAdapterOptions } from './adapters/stripe';
|
|
10
|
+
export { StellarPaymentAdapter } from './adapters/stellar';
|
|
11
|
+
export type { StellarPaymentAdapterOptions } from './adapters/stellar';
|
|
12
|
+
export { BasePaymentAdapter } from './adapters/base';
|
|
13
|
+
export type { BaseAdapterOptions } from './adapters/base';
|
|
14
|
+
export type { PaymentAdapter } from './adapters/types';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACtD,YAAY,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGvC,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,EACf,cAAc,EACd,oBAAoB,EACpB,eAAe,EACf,eAAe,GAChB,MAAM,OAAO,CAAC;AACf,YAAY,EACV,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,SAAS,EACT,SAAS,GACV,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAClE,YAAY,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAG9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,YAAY,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAGvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAG1D,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger type for @asgcard/pay SDK.
|
|
3
|
+
*
|
|
4
|
+
* Pass `console.log` for verbose output, or provide a custom logger.
|
|
5
|
+
* If omitted, the SDK is silent — no stdout pollution.
|
|
6
|
+
*/
|
|
7
|
+
export type Logger = (message: string, ...args: any[]) => void;
|
|
8
|
+
/** No-op logger — used when no logger is provided. */
|
|
9
|
+
export declare const noopLogger: Logger;
|
|
10
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAE/D,sDAAsD;AACtD,eAAO,MAAM,UAAU,EAAE,MAAiB,CAAC"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MPP — Machine Payments Protocol utilities.
|
|
3
|
+
*
|
|
4
|
+
* Handles parsing/building of MPP-standard headers:
|
|
5
|
+
* - WWW-Authenticate: Payment (Challenge)
|
|
6
|
+
* - Authorization: Payment (Credential)
|
|
7
|
+
* - Payment-Receipt (Receipt)
|
|
8
|
+
*
|
|
9
|
+
* @see https://mpp.dev/protocol/challenges
|
|
10
|
+
* @see https://mpp.dev/protocol/credentials
|
|
11
|
+
* @see https://mpp.dev/protocol/receipts
|
|
12
|
+
* @see https://paymentauth.org — IETF specification
|
|
13
|
+
*/
|
|
14
|
+
/** Supported MPP payment methods */
|
|
15
|
+
export type MppMethod = 'stripe' | 'tempo' | 'card' | 'lightning' | 'solana' | 'stellar' | string;
|
|
16
|
+
/** Payment intent types */
|
|
17
|
+
export type MppIntent = 'charge' | 'session';
|
|
18
|
+
/**
|
|
19
|
+
* Parsed MPP Challenge from `WWW-Authenticate: Payment` header.
|
|
20
|
+
*/
|
|
21
|
+
export interface MppChallenge {
|
|
22
|
+
/** Unique challenge ID (cryptographically bound to parameters) */
|
|
23
|
+
id: string;
|
|
24
|
+
/** Server realm (e.g. "mpp.dev", "pay.asgcard.dev") */
|
|
25
|
+
realm: string;
|
|
26
|
+
/** Payment method identifier */
|
|
27
|
+
method: MppMethod;
|
|
28
|
+
/** Payment intent type */
|
|
29
|
+
intent: MppIntent;
|
|
30
|
+
/** Base64url-encoded JSON with method-specific payment details */
|
|
31
|
+
request: string;
|
|
32
|
+
/** ISO 8601 expiration timestamp (optional) */
|
|
33
|
+
expires?: string;
|
|
34
|
+
/** Human-readable description (optional) */
|
|
35
|
+
description?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Decoded request object from Challenge.
|
|
39
|
+
*/
|
|
40
|
+
export interface MppRequestObject {
|
|
41
|
+
/** Amount in smallest currency unit (string for precision) */
|
|
42
|
+
amount: string;
|
|
43
|
+
/** Currency code (e.g. "usd") or token address */
|
|
44
|
+
currency: string;
|
|
45
|
+
/** Recipient address or Stripe account */
|
|
46
|
+
recipient?: string;
|
|
47
|
+
/** Decimal places for the currency */
|
|
48
|
+
decimals?: number;
|
|
49
|
+
/** Human-readable description */
|
|
50
|
+
description?: string;
|
|
51
|
+
/** External reference ID */
|
|
52
|
+
externalId?: string;
|
|
53
|
+
/** Method-specific details */
|
|
54
|
+
methodDetails?: {
|
|
55
|
+
networkId?: string;
|
|
56
|
+
paymentMethodTypes?: string[];
|
|
57
|
+
metadata?: Record<string, string>;
|
|
58
|
+
[key: string]: unknown;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* MPP Credential — sent in `Authorization: Payment` header.
|
|
63
|
+
*/
|
|
64
|
+
export interface MppCredential {
|
|
65
|
+
/** Echo of the original challenge */
|
|
66
|
+
challenge: MppChallenge;
|
|
67
|
+
/** DID or identifier of the paying entity */
|
|
68
|
+
source: string;
|
|
69
|
+
/** Method-specific payload */
|
|
70
|
+
payload: MppStripePayload | MppTempoPayload | Record<string, unknown>;
|
|
71
|
+
}
|
|
72
|
+
/** Stripe-specific credential payload */
|
|
73
|
+
export interface MppStripePayload {
|
|
74
|
+
/** Shared Payment Token ID */
|
|
75
|
+
spt: string;
|
|
76
|
+
/** Optional external reference ID */
|
|
77
|
+
externalId?: string;
|
|
78
|
+
}
|
|
79
|
+
/** Tempo-specific credential payload */
|
|
80
|
+
export interface MppTempoPayload {
|
|
81
|
+
type: 'transaction' | 'hash' | 'proof';
|
|
82
|
+
signature?: string;
|
|
83
|
+
hash?: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* MPP Receipt — returned in `Payment-Receipt` header.
|
|
87
|
+
*/
|
|
88
|
+
export interface MppReceipt {
|
|
89
|
+
/** Receipt data (base64url-decoded JSON) */
|
|
90
|
+
[key: string]: unknown;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Encode string to base64url (RFC 4648 §5).
|
|
94
|
+
* No padding, URL-safe alphabet.
|
|
95
|
+
*/
|
|
96
|
+
export declare function base64urlEncode(str: string): string;
|
|
97
|
+
/**
|
|
98
|
+
* Decode base64url string.
|
|
99
|
+
*/
|
|
100
|
+
export declare function base64urlDecode(str: string): string;
|
|
101
|
+
/**
|
|
102
|
+
* Parse a `WWW-Authenticate: Payment` header value into an MppChallenge.
|
|
103
|
+
*
|
|
104
|
+
* Format:
|
|
105
|
+
* ```
|
|
106
|
+
* Payment id="abc", realm="mpp.dev", method="stripe", intent="charge",
|
|
107
|
+
* expires="2025-01-15T12:05:00Z", request="eyJhbW91bnQ..."
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @param header — Raw header value (with or without "Payment " prefix)
|
|
111
|
+
* @returns Parsed challenge object
|
|
112
|
+
* @throws Error if required fields are missing
|
|
113
|
+
*/
|
|
114
|
+
export declare function parseMppChallenge(header: string): MppChallenge;
|
|
115
|
+
/**
|
|
116
|
+
* Parse multiple `WWW-Authenticate: Payment` headers.
|
|
117
|
+
* Servers can offer multiple payment options.
|
|
118
|
+
*/
|
|
119
|
+
export declare function parseMppChallenges(headers: string[]): MppChallenge[];
|
|
120
|
+
/**
|
|
121
|
+
* Decode the `request` field of a Challenge into a structured object.
|
|
122
|
+
*/
|
|
123
|
+
export declare function decodeChallengeRequest(challenge: MppChallenge): MppRequestObject;
|
|
124
|
+
/**
|
|
125
|
+
* Build an MPP Credential for the `Authorization: Payment` header.
|
|
126
|
+
*
|
|
127
|
+
* @param challenge — The challenge being responded to
|
|
128
|
+
* @param source — DID or identifier of the payer
|
|
129
|
+
* @param payload — Method-specific proof (SPT for Stripe, tx for Tempo)
|
|
130
|
+
* @returns Base64url-encoded credential string
|
|
131
|
+
*/
|
|
132
|
+
export declare function buildMppCredential(challenge: MppChallenge, source: string, payload: MppCredential['payload']): string;
|
|
133
|
+
/**
|
|
134
|
+
* Build the full `Authorization` header value.
|
|
135
|
+
*/
|
|
136
|
+
export declare function buildAuthorizationHeader(challenge: MppChallenge, source: string, payload: MppCredential['payload']): string;
|
|
137
|
+
/**
|
|
138
|
+
* Parse a `Payment-Receipt` header.
|
|
139
|
+
*/
|
|
140
|
+
export declare function parseMppReceipt(header: string): MppReceipt;
|
|
141
|
+
/**
|
|
142
|
+
* Detect whether a 402 response uses MPP or x402 protocol.
|
|
143
|
+
*
|
|
144
|
+
* MPP: has `WWW-Authenticate: Payment` header
|
|
145
|
+
* x402: has JSON body with `x402Version` and `accepts[]`
|
|
146
|
+
*/
|
|
147
|
+
export declare function detectProtocol(headers: Record<string, string | string[] | undefined>, body?: unknown): 'mpp' | 'x402' | 'unknown';
|
|
148
|
+
/**
|
|
149
|
+
* Extract all MPP challenges from response headers.
|
|
150
|
+
* Handles both single and multiple WWW-Authenticate headers.
|
|
151
|
+
*/
|
|
152
|
+
export declare function extractMppChallenges(headers: Record<string, string | string[] | undefined>): MppChallenge[];
|
|
153
|
+
//# sourceMappingURL=mpp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mpp.d.ts","sourceRoot":"","sources":["../../src/mpp.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PolicyEngine — On-device budget controller for autonomous AI agents.
|
|
3
|
+
*
|
|
4
|
+
* Enforces per-transaction caps, monthly rolling budgets, and optional
|
|
5
|
+
* destination whitelists so that an agent can never overspend without
|
|
6
|
+
* explicit human approval.
|
|
7
|
+
*
|
|
8
|
+
* Fail-closed: if any check fails, the payment is rejected.
|
|
9
|
+
*/
|
|
10
|
+
import { Logger } from './logger';
|
|
11
|
+
export interface BudgetPolicy {
|
|
12
|
+
/** Maximum USD amount the agent may spend in a single transaction. */
|
|
13
|
+
maxAmountPerTransaction: number;
|
|
14
|
+
/** Maximum USD the agent may spend within a calendar month. */
|
|
15
|
+
monthlyBudget: number;
|
|
16
|
+
/** Optional whitelist of addresses the agent is allowed to pay. */
|
|
17
|
+
allowedDestinations?: string[];
|
|
18
|
+
}
|
|
19
|
+
export declare class PolicyEngine {
|
|
20
|
+
private policy;
|
|
21
|
+
private currentMonthSpent;
|
|
22
|
+
private log;
|
|
23
|
+
constructor(policy: BudgetPolicy, logger?: Logger);
|
|
24
|
+
/**
|
|
25
|
+
* Returns `true` if the proposed spend passes every policy gate.
|
|
26
|
+
* Fail-closed: any unrecognised state returns `false`.
|
|
27
|
+
*/
|
|
28
|
+
checkPolicy(amountUsd: number, destination?: string): boolean;
|
|
29
|
+
/** Record a successful spend against the rolling budget. */
|
|
30
|
+
recordSpend(amountUsd: number): void;
|
|
31
|
+
/** Get total USD spent in the current period. */
|
|
32
|
+
getSpent(): number;
|
|
33
|
+
/** Get remaining USD budget. */
|
|
34
|
+
getRemainingBudget(): number;
|
|
35
|
+
/** Reset the spend counter (e.g. on month rollover or for testing). */
|
|
36
|
+
resetBudget(): void;
|
|
37
|
+
/** Get a snapshot of the current policy configuration. */
|
|
38
|
+
getPolicy(): Readonly<BudgetPolicy>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,MAAM,EAAc,MAAM,UAAU,CAAC;AAE9C,MAAM,WAAW,YAAY;IAC3B,sEAAsE;IACtE,uBAAuB,EAAE,MAAM,CAAC;IAChC,+DAA+D;IAC/D,aAAa,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;CAChC;AAED,qBAAa,YAAY;IAKrB,OAAO,CAAC,MAAM;IAJhB,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,GAAG,CAAS;gBAGV,MAAM,EAAE,YAAY,EAC5B,MAAM,CAAC,EAAE,MAAM;IAKjB;;;OAGG;IACI,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO;IAiCpE,4DAA4D;IACrD,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAO3C,iDAAiD;IAC1C,QAAQ,IAAI,MAAM;IAIzB,gCAAgC;IACzB,kBAAkB,IAAI,MAAM;IAInC,uEAAuE;IAChE,WAAW,IAAI,IAAI;IAI1B,0DAA0D;IACnD,SAAS,IAAI,QAAQ,CAAC,YAAY,CAAC;CAG3C"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface StellarPaymentAdapterOptions {
|
|
2
|
+
/** Stellar secret key for the agent's wallet. */
|
|
3
|
+
secretKey: string;
|
|
4
|
+
/** Override the network passphrase (default: Testnet). */
|
|
5
|
+
networkPassphrase?: string;
|
|
6
|
+
/** Override the Horizon URL (default: Testnet Horizon). */
|
|
7
|
+
horizonUrl?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* StellarPaymentAdapter — Executes on-chain Stellar payments.
|
|
11
|
+
*
|
|
12
|
+
* In the production ASG Pay stack the adapter targets USDC on Stellar
|
|
13
|
+
* mainnet (see https://pay.asgcard.dev). For hackathon purposes it
|
|
14
|
+
* defaults to Stellar Testnet with native XLM.
|
|
15
|
+
*/
|
|
16
|
+
export declare class StellarPaymentAdapter {
|
|
17
|
+
private keypair;
|
|
18
|
+
private server;
|
|
19
|
+
private networkPassphrase;
|
|
20
|
+
constructor(options: StellarPaymentAdapterOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Send `amount` (in stroops) of native XLM to `destination`.
|
|
23
|
+
* Returns the transaction hash on success, or `null` on failure.
|
|
24
|
+
*/
|
|
25
|
+
pay(destination: string, amount: string, network: string): Promise<string | null>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=stellar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stellar.d.ts","sourceRoot":"","sources":["../../src/stellar.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,4BAA4B;IAC3C,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;GAMG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,iBAAiB,CAAS;gBAEtB,OAAO,EAAE,4BAA4B;IASjD;;;OAGG;IACU,GAAG,CACd,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAuC1B"}
|