@atxp/client 0.10.7 → 0.10.10
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/dist/_virtual/index10.js +2 -2
- package/dist/_virtual/index11.js +2 -2
- package/dist/_virtual/index17.js +2 -2
- package/dist/_virtual/index18.js +2 -2
- package/dist/_virtual/index8.js +2 -2
- package/dist/_virtual/index9.js +2 -2
- package/dist/atxpClient.d.ts +1 -1
- package/dist/atxpClient.d.ts.map +1 -1
- package/dist/atxpFetcher.d.ts +18 -1
- package/dist/atxpFetcher.d.ts.map +1 -1
- package/dist/atxpFetcher.js +65 -2
- package/dist/atxpFetcher.js.map +1 -1
- package/dist/atxpProtocolHandler.d.ts +17 -0
- package/dist/atxpProtocolHandler.d.ts.map +1 -0
- package/dist/atxpProtocolHandler.js +77 -0
- package/dist/atxpProtocolHandler.js.map +1 -0
- package/dist/destinationMakers/index.d.ts.map +1 -1
- package/dist/destinationMakers/index.js +6 -0
- package/dist/destinationMakers/index.js.map +1 -1
- package/dist/index.cjs +558 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +183 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +555 -4
- package/dist/index.js.map +1 -1
- package/dist/mppProtocolHandler.d.ts +46 -0
- package/dist/mppProtocolHandler.d.ts.map +1 -0
- package/dist/mppProtocolHandler.js +182 -0
- package/dist/mppProtocolHandler.js.map +1 -0
- package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/ajv/dist/vocabularies/applicator/index.js +1 -1
- package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/ajv/dist/vocabularies/core/index.js +1 -1
- package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/ajv/dist/vocabularies/format/index.js +1 -1
- package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/ajv/dist/vocabularies/validation/index.js +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/core/index.js +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/validation/index.js +1 -1
- package/dist/paymentClient.d.ts +55 -0
- package/dist/paymentClient.d.ts.map +1 -0
- package/dist/paymentClient.js +75 -0
- package/dist/paymentClient.js.map +1 -0
- package/dist/protocolHandler.d.ts +41 -0
- package/dist/protocolHandler.d.ts.map +1 -0
- package/dist/types.d.ts +6 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/x402ProtocolHandler.d.ts +22 -0
- package/dist/x402ProtocolHandler.d.ts.map +1 -0
- package/dist/x402ProtocolHandler.js +166 -0
- package/dist/x402ProtocolHandler.js.map +1 -0
- package/package.json +5 -3
- package/dist/atxpLocalAccount.d.ts +0 -50
- package/dist/clientTestHelpers.d.ts +0 -6
- package/dist/destinationMakers/atxpDestinationMaker.d.ts +0 -15
- package/dist/destinationMakers/index.d.ts +0 -9
- package/dist/destinationMakers/passthroughDestinationMaker.d.ts +0 -8
- package/dist/errors.d.ts +0 -117
- package/dist/polygonConstants.d.ts +0 -53
- package/dist/setup.expo.d.ts +0 -2
- package/dist/worldConstants.d.ts +0 -53
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ProtocolHandler, ProtocolConfig } from './protocolHandler.js';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for MPP protocol handler.
|
|
4
|
+
*/
|
|
5
|
+
export interface MPPProtocolHandlerConfig {
|
|
6
|
+
accountsServer?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Protocol handler for MPP (Machine Payments Protocol) payment challenges.
|
|
10
|
+
*
|
|
11
|
+
* Detects MPP challenges in two forms:
|
|
12
|
+
* 1. HTTP level: HTTP 402 with WWW-Authenticate: Payment header
|
|
13
|
+
* 2. MCP level: JSON-RPC error with code -32042 containing MPP data
|
|
14
|
+
*
|
|
15
|
+
* Handles the challenge by calling /authorize/mpp on the accounts service
|
|
16
|
+
* and retrying with an Authorization: Payment header.
|
|
17
|
+
*/
|
|
18
|
+
export declare class MPPProtocolHandler implements ProtocolHandler {
|
|
19
|
+
readonly protocol = "mpp";
|
|
20
|
+
private accountsServer;
|
|
21
|
+
constructor(config?: MPPProtocolHandlerConfig);
|
|
22
|
+
canHandle(response: Response): Promise<boolean>;
|
|
23
|
+
handlePaymentChallenge(response: Response, originalRequest: {
|
|
24
|
+
url: string | URL;
|
|
25
|
+
init?: RequestInit;
|
|
26
|
+
}, config: ProtocolConfig): Promise<Response | null>;
|
|
27
|
+
/**
|
|
28
|
+
* Extract MPP challenge from response - tries HTTP header first, then MCP error body.
|
|
29
|
+
* Returns both the challenge and the body text to avoid double-consumption.
|
|
30
|
+
*/
|
|
31
|
+
private extractChallenge;
|
|
32
|
+
/**
|
|
33
|
+
* Build a ProspectivePayment from an MPP challenge.
|
|
34
|
+
*/
|
|
35
|
+
private buildProspectivePayment;
|
|
36
|
+
/**
|
|
37
|
+
* Report a payment failure via the onPaymentFailure callback.
|
|
38
|
+
*/
|
|
39
|
+
private reportFailure;
|
|
40
|
+
/**
|
|
41
|
+
* Call /authorize/mpp on accounts service and retry the original request with the credential.
|
|
42
|
+
*/
|
|
43
|
+
private authorizeAndRetry;
|
|
44
|
+
private reconstructResponse;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=mppProtocolHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mppProtocolHandler.d.ts","sourceRoot":"","sources":["../src/mppProtocolHandler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAa5E;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;GASG;AACH,qBAAa,kBAAmB,YAAW,eAAe;IACxD,QAAQ,CAAC,QAAQ,SAAS;IAC1B,OAAO,CAAC,cAAc,CAAS;gBAEnB,MAAM,CAAC,EAAE,wBAAwB;IAIvC,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAK/C,sBAAsB,CAC1B,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE;QAAE,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;QAAC,IAAI,CAAC,EAAE,WAAW,CAAA;KAAE,EAC1D,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IA8B3B;;;OAGG;YACW,gBAAgB;IA2C9B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAY/B;;OAEG;YACW,aAAa;IAiB3B;;OAEG;YACW,iBAAiB;IA6D/B,OAAO,CAAC,mBAAmB;CAQ5B"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { AuthorizationError } from '@atxp/common';
|
|
2
|
+
import { hasMPPChallenge, hasMPPMCPError, parseMPPHeader, MPP_ERROR_CODE, parseMPPFromMCPError } from '@atxp/mpp';
|
|
3
|
+
import { BigNumber } from 'bignumber.js';
|
|
4
|
+
import { PaymentClient, buildPaymentHeaders } from './paymentClient.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Protocol handler for MPP (Machine Payments Protocol) payment challenges.
|
|
8
|
+
*
|
|
9
|
+
* Detects MPP challenges in two forms:
|
|
10
|
+
* 1. HTTP level: HTTP 402 with WWW-Authenticate: Payment header
|
|
11
|
+
* 2. MCP level: JSON-RPC error with code -32042 containing MPP data
|
|
12
|
+
*
|
|
13
|
+
* Handles the challenge by calling /authorize/mpp on the accounts service
|
|
14
|
+
* and retrying with an Authorization: Payment header.
|
|
15
|
+
*/
|
|
16
|
+
class MPPProtocolHandler {
|
|
17
|
+
constructor(config) {
|
|
18
|
+
this.protocol = 'mpp';
|
|
19
|
+
this.accountsServer = config?.accountsServer ?? 'https://accounts.atxp.ai';
|
|
20
|
+
}
|
|
21
|
+
async canHandle(response) {
|
|
22
|
+
if (hasMPPChallenge(response))
|
|
23
|
+
return true;
|
|
24
|
+
return hasMPPMCPError(response);
|
|
25
|
+
}
|
|
26
|
+
async handlePaymentChallenge(response, originalRequest, config) {
|
|
27
|
+
const { account, logger, approvePayment } = config;
|
|
28
|
+
// Extract the challenge and body text from the response
|
|
29
|
+
const extracted = await this.extractChallenge(response, logger);
|
|
30
|
+
if (!extracted) {
|
|
31
|
+
logger.error('MPP: failed to extract challenge from response');
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const { challenge, bodyText } = extracted;
|
|
35
|
+
const url = typeof originalRequest.url === 'string'
|
|
36
|
+
? originalRequest.url
|
|
37
|
+
: originalRequest.url.toString();
|
|
38
|
+
// Build prospective payment for approval
|
|
39
|
+
const accountId = await account.getAccountId();
|
|
40
|
+
const prospectivePayment = this.buildProspectivePayment(challenge, url, accountId);
|
|
41
|
+
// Ask for approval
|
|
42
|
+
const approved = await approvePayment(prospectivePayment);
|
|
43
|
+
if (!approved) {
|
|
44
|
+
logger.info('MPP: payment not approved');
|
|
45
|
+
await this.reportFailure(config, prospectivePayment, new Error('Payment not approved'), challenge.network, true);
|
|
46
|
+
return this.reconstructResponse(bodyText, response);
|
|
47
|
+
}
|
|
48
|
+
return this.authorizeAndRetry(challenge, prospectivePayment, originalRequest, config, bodyText, response);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Extract MPP challenge from response - tries HTTP header first, then MCP error body.
|
|
52
|
+
* Returns both the challenge and the body text to avoid double-consumption.
|
|
53
|
+
*/
|
|
54
|
+
async extractChallenge(response, logger) {
|
|
55
|
+
// Read body once upfront to avoid double consumption (response.text() can only be called once)
|
|
56
|
+
let bodyText = '';
|
|
57
|
+
try {
|
|
58
|
+
bodyText = await response.text();
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// Body may not be available
|
|
62
|
+
}
|
|
63
|
+
// Try HTTP header first
|
|
64
|
+
const header = response.headers.get('WWW-Authenticate');
|
|
65
|
+
if (header) {
|
|
66
|
+
const challenge = parseMPPHeader(header);
|
|
67
|
+
if (challenge) {
|
|
68
|
+
logger.debug('MPP: parsed challenge from WWW-Authenticate header');
|
|
69
|
+
return { challenge, bodyText };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Try MCP error body (use clone since response body may have been consumed above)
|
|
73
|
+
try {
|
|
74
|
+
const parsed = JSON.parse(bodyText);
|
|
75
|
+
if (typeof parsed === 'object' &&
|
|
76
|
+
parsed !== null &&
|
|
77
|
+
typeof parsed.error === 'object' &&
|
|
78
|
+
parsed.error !== null &&
|
|
79
|
+
parsed.error.code === MPP_ERROR_CODE) {
|
|
80
|
+
const challenge = parseMPPFromMCPError(parsed.error.data);
|
|
81
|
+
if (challenge) {
|
|
82
|
+
logger.debug('MPP: parsed challenge from MCP error body');
|
|
83
|
+
return { challenge, bodyText };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// Not JSON or malformed
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Build a ProspectivePayment from an MPP challenge.
|
|
94
|
+
*/
|
|
95
|
+
buildProspectivePayment(challenge, url, accountId) {
|
|
96
|
+
const amountNum = Number(challenge.amount) / (10 ** 6);
|
|
97
|
+
return {
|
|
98
|
+
accountId,
|
|
99
|
+
resourceUrl: url,
|
|
100
|
+
resourceName: url,
|
|
101
|
+
currency: challenge.currency,
|
|
102
|
+
amount: new BigNumber(amountNum),
|
|
103
|
+
iss: challenge.recipient,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Report a payment failure via the onPaymentFailure callback.
|
|
108
|
+
*/
|
|
109
|
+
async reportFailure(config, payment, error, network, retryable) {
|
|
110
|
+
await config.onPaymentFailure({
|
|
111
|
+
payment,
|
|
112
|
+
error,
|
|
113
|
+
attemptedNetworks: [network],
|
|
114
|
+
failureReasons: new Map([[network, error]]),
|
|
115
|
+
retryable,
|
|
116
|
+
timestamp: new Date(),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Call /authorize/mpp on accounts service and retry the original request with the credential.
|
|
121
|
+
*/
|
|
122
|
+
async authorizeAndRetry(challenge, prospectivePayment, originalRequest, config, bodyText, originalResponse) {
|
|
123
|
+
const { account, logger, fetchFn, onPayment } = config;
|
|
124
|
+
try {
|
|
125
|
+
logger.debug('MPP: calling /authorize/mpp on accounts service');
|
|
126
|
+
const client = new PaymentClient({
|
|
127
|
+
accountsServer: this.accountsServer,
|
|
128
|
+
logger,
|
|
129
|
+
fetchFn,
|
|
130
|
+
});
|
|
131
|
+
const accountId = await account.getAccountId();
|
|
132
|
+
let authorizeResult;
|
|
133
|
+
try {
|
|
134
|
+
authorizeResult = await client.authorize({
|
|
135
|
+
account,
|
|
136
|
+
userId: accountId,
|
|
137
|
+
destination: typeof originalRequest.url === 'string' ? originalRequest.url : originalRequest.url.toString(),
|
|
138
|
+
protocol: 'mpp',
|
|
139
|
+
challenge,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
catch (authorizeError) {
|
|
143
|
+
// AuthorizationError = server rejected the request (HTTP error from accounts)
|
|
144
|
+
// Other errors = data validation or network failure
|
|
145
|
+
if (authorizeError instanceof AuthorizationError) {
|
|
146
|
+
logger.debug(`MPP: /authorize/mpp rejected (${authorizeError.statusCode}), returning original response`);
|
|
147
|
+
return this.reconstructResponse(bodyText, originalResponse);
|
|
148
|
+
}
|
|
149
|
+
throw authorizeError;
|
|
150
|
+
}
|
|
151
|
+
const retryHeaders = buildPaymentHeaders(authorizeResult, originalRequest.init?.headers);
|
|
152
|
+
const retryInit = { ...originalRequest.init, headers: retryHeaders };
|
|
153
|
+
logger.info('MPP: retrying request with Authorization: Payment header');
|
|
154
|
+
const retryResponse = await fetchFn(originalRequest.url, retryInit);
|
|
155
|
+
if (retryResponse.ok) {
|
|
156
|
+
logger.info('MPP: payment accepted');
|
|
157
|
+
await onPayment({ payment: prospectivePayment, transactionHash: challenge.id, network: challenge.network });
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
logger.warn(`MPP: request failed after payment with status ${retryResponse.status}`);
|
|
161
|
+
await this.reportFailure(config, prospectivePayment, new Error(`Request failed with status ${retryResponse.status}`), challenge.network, false);
|
|
162
|
+
}
|
|
163
|
+
return retryResponse;
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
logger.error(`MPP: failed to handle payment challenge: ${error}`);
|
|
167
|
+
const cause = error instanceof Error ? error : new Error(String(error));
|
|
168
|
+
await this.reportFailure(config, prospectivePayment, cause, challenge.network, true);
|
|
169
|
+
return this.reconstructResponse(bodyText, originalResponse);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
reconstructResponse(body, original) {
|
|
173
|
+
return new Response(body || null, {
|
|
174
|
+
status: original.status,
|
|
175
|
+
statusText: original.statusText,
|
|
176
|
+
headers: original.headers,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export { MPPProtocolHandler };
|
|
182
|
+
//# sourceMappingURL=mppProtocolHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mppProtocolHandler.js","sources":["../src/mppProtocolHandler.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAsBA;;;;;;;;;AASG;MACU,kBAAkB,CAAA;AAI7B,IAAA,WAAA,CAAY,MAAiC,EAAA;QAHpC,IAAA,CAAA,QAAQ,GAAG,KAAK;QAIvB,IAAI,CAAC,cAAc,GAAG,MAAM,EAAE,cAAc,IAAI,0BAA0B;IAC5E;IAEA,MAAM,SAAS,CAAC,QAAkB,EAAA;QAChC,IAAI,eAAe,CAAC,QAAQ,CAAC;AAAE,YAAA,OAAO,IAAI;AAC1C,QAAA,OAAO,cAAc,CAAC,QAAQ,CAAC;IACjC;AAEA,IAAA,MAAM,sBAAsB,CAC1B,QAAkB,EAClB,eAA0D,EAC1D,MAAsB,EAAA;QAEtB,MAAM,EAAE,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jE,MAAM,KAAK,GAAG,KAAK,YAAY,KAAK,GAAG,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACvE,YAAA,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC;YACpF,OAAO,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,CAAC;QAC7D;IACF;IAEQ,mBAAmB,CAAC,IAAY,EAAE,QAAkB,EAAA;AAC1D,QAAA,OAAO,IAAI,QAAQ,CAAC,IAAI,IAAI,IAAI,EAAE;YAChC,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,OAAO,EAAE,QAAQ,CAAC,OAAO;AAC1B,SAAA,CAAC;IACJ;AAED;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __exports as applicator } from '../../../../../../../../_virtual/
|
|
1
|
+
import { __exports as applicator } from '../../../../../../../../_virtual/index10.js';
|
|
2
2
|
import { __require as requireAdditionalItems } from './additionalItems.js';
|
|
3
3
|
import { __require as requirePrefixItems } from './prefixItems.js';
|
|
4
4
|
import { __require as requireItems } from './items.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __exports as validation } from '../../../../../../../../_virtual/
|
|
1
|
+
import { __exports as validation } from '../../../../../../../../_virtual/index9.js';
|
|
2
2
|
import { __require as requireLimitNumber } from './limitNumber.js';
|
|
3
3
|
import { __require as requireMultipleOf } from './multipleOf.js';
|
|
4
4
|
import { __require as requireLimitLength } from './limitLength.js';
|
package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/validation/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __exports as validation } from '../../../../../../../_virtual/
|
|
1
|
+
import { __exports as validation } from '../../../../../../../_virtual/index17.js';
|
|
2
2
|
import { __require as requireLimitNumber } from './limitNumber.js';
|
|
3
3
|
import { __require as requireMultipleOf } from './multipleOf.js';
|
|
4
4
|
import { __require as requireLimitLength } from './limitLength.js';
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { PaymentProtocol, ProtocolFlag, FetchLike, Logger, Account, AuthorizeResult } from '@atxp/common';
|
|
2
|
+
export type { AuthorizeResult } from '@atxp/common';
|
|
3
|
+
/**
|
|
4
|
+
* Build protocol-specific payment headers for retrying a request after authorization.
|
|
5
|
+
*
|
|
6
|
+
* @param result - The authorization result containing protocol and credential
|
|
7
|
+
* @param originalHeaders - Optional original request headers to preserve
|
|
8
|
+
* @returns New Headers object with protocol-specific payment headers added
|
|
9
|
+
*/
|
|
10
|
+
export declare function buildPaymentHeaders(result: AuthorizeResult, originalHeaders?: HeadersInit): Headers;
|
|
11
|
+
/**
|
|
12
|
+
* Client for authorizing payments.
|
|
13
|
+
*
|
|
14
|
+
* Resolves the payment protocol via protocolFlag, then delegates to
|
|
15
|
+
* account.authorize() for the actual authorization logic.
|
|
16
|
+
*/
|
|
17
|
+
export declare class PaymentClient {
|
|
18
|
+
private protocolFlag?;
|
|
19
|
+
private logger;
|
|
20
|
+
constructor(config: {
|
|
21
|
+
protocolFlag?: ProtocolFlag;
|
|
22
|
+
logger: Logger;
|
|
23
|
+
/** @deprecated No longer used — authorization delegates to account.authorize() */
|
|
24
|
+
accountsServer?: string;
|
|
25
|
+
/** @deprecated No longer used — authorization delegates to account.authorize() */
|
|
26
|
+
fetchFn?: FetchLike;
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Authorize a payment by delegating to the account's authorize method.
|
|
30
|
+
*
|
|
31
|
+
* PaymentClient resolves the protocol (via explicit param or protocolFlag),
|
|
32
|
+
* then delegates all protocol-specific logic to account.authorize().
|
|
33
|
+
*
|
|
34
|
+
* @param params.account - The account to authorize the payment through
|
|
35
|
+
* @param params.userId - Passed to protocolFlag for protocol selection
|
|
36
|
+
* @param params.destination - Payment destination address
|
|
37
|
+
* @param params.protocol - Explicit protocol override (skips protocolFlag)
|
|
38
|
+
* @param params.amount - Payment amount
|
|
39
|
+
* @param params.memo - Payment memo
|
|
40
|
+
* @param params.paymentRequirements - X402 payment requirements
|
|
41
|
+
* @param params.challenge - MPP challenge object
|
|
42
|
+
* @returns AuthorizeResult with protocol and opaque credential
|
|
43
|
+
*/
|
|
44
|
+
authorize(params: {
|
|
45
|
+
account: Account;
|
|
46
|
+
userId: string;
|
|
47
|
+
destination: string;
|
|
48
|
+
protocol?: PaymentProtocol;
|
|
49
|
+
amount?: BigNumber;
|
|
50
|
+
memo?: string;
|
|
51
|
+
paymentRequirements?: unknown;
|
|
52
|
+
challenge?: unknown;
|
|
53
|
+
}): Promise<AuthorizeResult>;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=paymentClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paymentClient.d.ts","sourceRoot":"","sources":["../src/paymentClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAI/G,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe,EAAE,eAAe,CAAC,EAAE,WAAW,GAAG,OAAO,CAwBnG;AAED;;;;;GAKG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,YAAY,CAAC,CAAe;IACpC,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE;QAClB,YAAY,CAAC,EAAE,YAAY,CAAC;QAC5B,MAAM,EAAE,MAAM,CAAC;QACf,kFAAkF;QAClF,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,kFAAkF;QAClF,OAAO,CAAC,EAAE,SAAS,CAAC;KACrB;IAKD;;;;;;;;;;;;;;;OAeG;IACG,SAAS,CAAC,MAAM,EAAE;QACtB,OAAO,EAAE,OAAO,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,EAAE,eAAe,CAAC;QAC3B,MAAM,CAAC,EAAE,SAAS,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,mBAAmB,CAAC,EAAE,OAAO,CAAC;QAC9B,SAAS,CAAC,EAAE,OAAO,CAAC;KACrB,GAAG,OAAO,CAAC,eAAe,CAAC;CAiB7B"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build protocol-specific payment headers for retrying a request after authorization.
|
|
3
|
+
*
|
|
4
|
+
* @param result - The authorization result containing protocol and credential
|
|
5
|
+
* @param originalHeaders - Optional original request headers to preserve
|
|
6
|
+
* @returns New Headers object with protocol-specific payment headers added
|
|
7
|
+
*/
|
|
8
|
+
function buildPaymentHeaders(result, originalHeaders) {
|
|
9
|
+
let headers;
|
|
10
|
+
if (originalHeaders instanceof Headers) {
|
|
11
|
+
headers = new Headers(originalHeaders);
|
|
12
|
+
}
|
|
13
|
+
else if (originalHeaders) {
|
|
14
|
+
headers = new Headers(originalHeaders);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
headers = new Headers();
|
|
18
|
+
}
|
|
19
|
+
switch (result.protocol) {
|
|
20
|
+
case 'x402':
|
|
21
|
+
headers.set('X-PAYMENT', result.credential);
|
|
22
|
+
headers.set('Access-Control-Expose-Headers', 'X-PAYMENT-RESPONSE');
|
|
23
|
+
break;
|
|
24
|
+
case 'mpp':
|
|
25
|
+
headers.set('Authorization', `Payment ${result.credential}`);
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
return headers;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Client for authorizing payments.
|
|
32
|
+
*
|
|
33
|
+
* Resolves the payment protocol via protocolFlag, then delegates to
|
|
34
|
+
* account.authorize() for the actual authorization logic.
|
|
35
|
+
*/
|
|
36
|
+
class PaymentClient {
|
|
37
|
+
constructor(config) {
|
|
38
|
+
this.protocolFlag = config.protocolFlag;
|
|
39
|
+
this.logger = config.logger;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Authorize a payment by delegating to the account's authorize method.
|
|
43
|
+
*
|
|
44
|
+
* PaymentClient resolves the protocol (via explicit param or protocolFlag),
|
|
45
|
+
* then delegates all protocol-specific logic to account.authorize().
|
|
46
|
+
*
|
|
47
|
+
* @param params.account - The account to authorize the payment through
|
|
48
|
+
* @param params.userId - Passed to protocolFlag for protocol selection
|
|
49
|
+
* @param params.destination - Payment destination address
|
|
50
|
+
* @param params.protocol - Explicit protocol override (skips protocolFlag)
|
|
51
|
+
* @param params.amount - Payment amount
|
|
52
|
+
* @param params.memo - Payment memo
|
|
53
|
+
* @param params.paymentRequirements - X402 payment requirements
|
|
54
|
+
* @param params.challenge - MPP challenge object
|
|
55
|
+
* @returns AuthorizeResult with protocol and opaque credential
|
|
56
|
+
*/
|
|
57
|
+
async authorize(params) {
|
|
58
|
+
const { account, userId, destination } = params;
|
|
59
|
+
// Determine protocol
|
|
60
|
+
const protocol = params.protocol
|
|
61
|
+
?? (this.protocolFlag ? this.protocolFlag(userId, destination) : 'atxp');
|
|
62
|
+
// Delegate to the account's authorize method
|
|
63
|
+
return account.authorize({
|
|
64
|
+
protocol,
|
|
65
|
+
amount: params.amount,
|
|
66
|
+
destination,
|
|
67
|
+
memo: params.memo,
|
|
68
|
+
paymentRequirements: params.paymentRequirements,
|
|
69
|
+
challenge: params.challenge,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { PaymentClient, buildPaymentHeaders };
|
|
75
|
+
//# sourceMappingURL=paymentClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paymentClient.js","sources":["../src/paymentClient.ts"],"sourcesContent":[null],"names":[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E,MAAM,CAAC,MAAO;YACtB,WAAW;YACX,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,mBAAmB,EAAE,MAAM,CAAC,mBAAmB;YAC/C,SAAS,EAAE,MAAM,CAAC,SAAS;AAC5B,SAAA,CAAC;IACJ;AACD;;;;"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Account, Logger, FetchLike } from '@atxp/common';
|
|
2
|
+
import type { ProspectivePayment, PaymentFailureContext } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration passed to protocol handlers.
|
|
5
|
+
*/
|
|
6
|
+
export interface ProtocolConfig {
|
|
7
|
+
account: Account;
|
|
8
|
+
logger: Logger;
|
|
9
|
+
fetchFn: FetchLike;
|
|
10
|
+
approvePayment: (payment: ProspectivePayment) => Promise<boolean>;
|
|
11
|
+
onPayment: (args: {
|
|
12
|
+
payment: ProspectivePayment;
|
|
13
|
+
transactionHash: string;
|
|
14
|
+
network: string;
|
|
15
|
+
}) => Promise<void>;
|
|
16
|
+
onPaymentFailure: (context: PaymentFailureContext) => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Strategy interface for handling different payment protocol challenges.
|
|
20
|
+
*
|
|
21
|
+
* Implementations detect whether a response contains a payment challenge
|
|
22
|
+
* they can handle, and execute the payment flow if so.
|
|
23
|
+
*/
|
|
24
|
+
export interface ProtocolHandler {
|
|
25
|
+
/** Unique protocol identifier */
|
|
26
|
+
readonly protocol: string;
|
|
27
|
+
/**
|
|
28
|
+
* Check if this handler can handle the given response.
|
|
29
|
+
* Must not consume the response body (use clone if needed).
|
|
30
|
+
*/
|
|
31
|
+
canHandle(response: Response): Promise<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* Handle a payment challenge from the response.
|
|
34
|
+
* Returns the retry response after payment, or null if the challenge couldn't be handled.
|
|
35
|
+
*/
|
|
36
|
+
handlePaymentChallenge(response: Response, originalRequest: {
|
|
37
|
+
url: string | URL;
|
|
38
|
+
init?: RequestInit;
|
|
39
|
+
}, config: ProtocolConfig): Promise<Response | null>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=protocolHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocolHandler.d.ts","sourceRoot":"","sources":["../src/protocolHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,SAAS,CAAC;IACnB,cAAc,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAClE,SAAS,EAAE,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,kBAAkB,CAAC;QAAC,eAAe,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9G,gBAAgB,EAAE,CAAC,OAAO,EAAE,qBAAqB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACrE;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,iCAAiC;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEhD;;;OAGG;IACH,sBAAsB,CACpB,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE;QAAE,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;QAAC,IAAI,CAAC,EAAE,WAAW,CAAA;KAAE,EAC1D,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;CAC7B"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { AuthorizationServerUrl, Currency, Logger, Network, OAuthDb, FetchLike, Account, PaymentMaker, AccountId, DestinationMaker } from "@atxp/common";
|
|
1
|
+
import { AuthorizationServerUrl, Currency, Logger, Network, OAuthDb, FetchLike, Account, PaymentMaker, AccountId, DestinationMaker, type ProtocolFlag } from "@atxp/common";
|
|
2
2
|
import { ClientOptions } from "@modelcontextprotocol/sdk/client/index.js";
|
|
3
3
|
import { Implementation } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
import type { ProtocolHandler } from "./protocolHandler.js";
|
|
4
5
|
export type Hex = `0x${string}`;
|
|
5
6
|
type AccountPrefix = Network;
|
|
6
7
|
export type AccountIdString = `${AccountPrefix}${string}`;
|
|
@@ -64,6 +65,10 @@ export type ClientConfig = {
|
|
|
64
65
|
error: Error;
|
|
65
66
|
remainingNetworks: string[];
|
|
66
67
|
}) => Promise<void>;
|
|
68
|
+
/** Optional protocol handlers for multi-protocol support (strategy pattern) */
|
|
69
|
+
protocolHandlers?: ProtocolHandler[];
|
|
70
|
+
/** Optional protocol flag function to select protocol for omni-challenges */
|
|
71
|
+
protocolFlag?: ProtocolFlag;
|
|
67
72
|
};
|
|
68
73
|
type RequiredClientConfigFields = 'mcpServer' | 'account';
|
|
69
74
|
type RequiredClientConfig = Pick<ClientConfig, RequiredClientConfigFields>;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","s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,eAAe,EAAE,CAAC;IACrC,6EAA6E;IAC7E,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAA;AAGD,KAAK,0BAA0B,GAAG,WAAW,GAAG,SAAS,CAAC;AAC1D,KAAK,oBAAoB,GAAG,IAAI,CAAC,YAAY,EAAE,0BAA0B,CAAC,CAAC;AAC3E,KAAK,oBAAoB,GAAG,IAAI,CAAC,YAAY,EAAE,0BAA0B,CAAC,CAAC;AAC3E,MAAM,MAAM,UAAU,GAAG,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAG9E,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,UAAU,KAAK,SAAS,CAAC;AAG7D,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,kBAAkB,EAClB,QAAQ,EACR,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAGrB,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ProtocolHandler, ProtocolConfig } from './protocolHandler.js';
|
|
2
|
+
export interface X402ProtocolHandlerConfig {
|
|
3
|
+
accountsServer?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Protocol handler for X402 payment challenges.
|
|
7
|
+
*
|
|
8
|
+
* Detects HTTP 402 responses with x402Version in the JSON body.
|
|
9
|
+
* Creates payment headers using the x402 library and retries the request.
|
|
10
|
+
*/
|
|
11
|
+
export declare class X402ProtocolHandler implements ProtocolHandler {
|
|
12
|
+
readonly protocol = "x402";
|
|
13
|
+
private accountsServer;
|
|
14
|
+
constructor(config?: X402ProtocolHandlerConfig);
|
|
15
|
+
canHandle(response: Response): Promise<boolean>;
|
|
16
|
+
handlePaymentChallenge(response: Response, originalRequest: {
|
|
17
|
+
url: string | URL;
|
|
18
|
+
init?: RequestInit;
|
|
19
|
+
}, config: ProtocolConfig): Promise<Response | null>;
|
|
20
|
+
private reconstructResponse;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=x402ProtocolHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402ProtocolHandler.d.ts","sourceRoot":"","sources":["../src/x402ProtocolHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AA6B5E,MAAM,WAAW,yBAAyB;IACxC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,YAAW,eAAe;IACzD,QAAQ,CAAC,QAAQ,UAAU;IAC3B,OAAO,CAAC,cAAc,CAAS;gBAEnB,MAAM,CAAC,EAAE,yBAAyB;IAIxC,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAa/C,sBAAsB,CAC1B,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE;QAAE,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;QAAC,IAAI,CAAC,EAAE,WAAW,CAAA;KAAE,EAC1D,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IA8I3B,OAAO,CAAC,mBAAmB;CAQ5B"}
|