@4mica/sdk 1.2.16 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -25
- package/dist/index.cjs +5513 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2730 -0
- package/dist/{src/abi/core4mica.d.ts → index.d.ts} +1032 -1
- package/dist/index.js +5439 -0
- package/dist/index.js.map +1 -0
- package/dist/models-B15ouNYG.d.cts +386 -0
- package/dist/models-B15ouNYG.d.ts +386 -0
- package/dist/server.cjs +172 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +119 -0
- package/dist/server.d.ts +119 -0
- package/dist/server.js +165 -0
- package/dist/server.js.map +1 -0
- package/package.json +52 -43
- package/dist/package.json +0 -80
- package/dist/src/abi/core4mica.js +0 -2200
- package/dist/src/abi/erc20.d.ts +0 -151
- package/dist/src/abi/erc20.js +0 -201
- package/dist/src/auth.d.ts +0 -62
- package/dist/src/auth.js +0 -218
- package/dist/src/bls.d.ts +0 -6
- package/dist/src/bls.js +0 -247
- package/dist/src/chain.d.ts +0 -2
- package/dist/src/chain.js +0 -26
- package/dist/src/client/index.d.ts +0 -71
- package/dist/src/client/index.js +0 -120
- package/dist/src/client/recipient.d.ts +0 -129
- package/dist/src/client/recipient.js +0 -257
- package/dist/src/client/shared.d.ts +0 -11
- package/dist/src/client/shared.js +0 -17
- package/dist/src/client/user.d.ts +0 -109
- package/dist/src/client/user.js +0 -147
- package/dist/src/config.d.ts +0 -103
- package/dist/src/config.js +0 -197
- package/dist/src/constants.d.ts +0 -4
- package/dist/src/constants.js +0 -7
- package/dist/src/contract.d.ts +0 -55
- package/dist/src/contract.js +0 -312
- package/dist/src/debug.d.ts +0 -2
- package/dist/src/debug.js +0 -5
- package/dist/src/errors.d.ts +0 -58
- package/dist/src/errors.js +0 -81
- package/dist/src/guarantee.d.ts +0 -25
- package/dist/src/guarantee.js +0 -272
- package/dist/src/http.d.ts +0 -11
- package/dist/src/http.js +0 -57
- package/dist/src/index.d.ts +0 -17
- package/dist/src/index.js +0 -33
- package/dist/src/models.d.ts +0 -259
- package/dist/src/models.js +0 -356
- package/dist/src/networks.d.ts +0 -40
- package/dist/src/networks.js +0 -57
- package/dist/src/payment.d.ts +0 -82
- package/dist/src/payment.js +0 -67
- package/dist/src/rpc.d.ts +0 -38
- package/dist/src/rpc.js +0 -161
- package/dist/src/serde.d.ts +0 -5
- package/dist/src/serde.js +0 -33
- package/dist/src/signing.d.ts +0 -170
- package/dist/src/signing.js +0 -311
- package/dist/src/utils.d.ts +0 -11
- package/dist/src/utils.js +0 -90
- package/dist/src/validation.d.ts +0 -32
- package/dist/src/validation.js +0 -84
- package/dist/src/wallet/cdp.d.ts +0 -13
- package/dist/src/wallet/cdp.js +0 -78
- package/dist/src/wallet/index.d.ts +0 -2
- package/dist/src/wallet/index.js +0 -5
- package/dist/src/x402/index.d.ts +0 -90
- package/dist/src/x402/index.js +0 -243
- package/dist/src/x402/models.d.ts +0 -75
- package/dist/src/x402/models.js +0 -2
package/dist/src/x402/index.d.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { PaymentGuaranteeRequestClaims, PaymentGuaranteeRequestClaimsV2, PaymentSignature, SigningScheme } from '../models';
|
|
2
|
-
import { PaymentRequirementsV1, TabResponse, X402SignedPayment, X402SettledPayment, PaymentRequirementsV2, X402PaymentRequired, X402ResourceInfo } from './models';
|
|
3
|
-
import type { FetchFn } from '../rpc';
|
|
4
|
-
export * from './models';
|
|
5
|
-
/**
|
|
6
|
-
* Minimal signing interface required by {@link X402Flow}.
|
|
7
|
-
* Implemented by {@link UserClient} from the main SDK client.
|
|
8
|
-
*/
|
|
9
|
-
export interface FlowSigner {
|
|
10
|
-
signPayment(claims: PaymentGuaranteeRequestClaims | PaymentGuaranteeRequestClaimsV2, scheme: SigningScheme): Promise<PaymentSignature>;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Handles the x402 HTTP 402 payment protocol for 4Mica.
|
|
14
|
-
*
|
|
15
|
-
* Orchestrates the full client-side x402 flow: resolving a tab from the recipient's
|
|
16
|
-
* tab endpoint, building and signing payment claims (V1 or V2), and optionally settling
|
|
17
|
-
* the payment against a facilitator service.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* const flow = X402Flow.fromClient(client);
|
|
22
|
-
* const signed = await flow.signPayment(paymentRequirements, userAddress);
|
|
23
|
-
* // attach signed.header as the X-PAYMENT header on the protected request
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export declare class X402Flow {
|
|
27
|
-
private signer;
|
|
28
|
-
private fetchFn;
|
|
29
|
-
/**
|
|
30
|
-
* @param signer - Payment signer, typically `client.user`.
|
|
31
|
-
* @param fetchFn - HTTP fetch implementation. Defaults to global `fetch`.
|
|
32
|
-
*/
|
|
33
|
-
constructor(signer: FlowSigner, fetchFn?: FetchFn);
|
|
34
|
-
/**
|
|
35
|
-
* Convenience factory — creates an `X402Flow` from the user sub-client of a `Client`.
|
|
36
|
-
*
|
|
37
|
-
* @param client - Any object with a `.user` property implementing {@link FlowSigner}.
|
|
38
|
-
*/
|
|
39
|
-
static fromClient(client: {
|
|
40
|
-
user: FlowSigner;
|
|
41
|
-
}): X402Flow;
|
|
42
|
-
/**
|
|
43
|
-
* Sign an x402 V1 payment.
|
|
44
|
-
*
|
|
45
|
-
* Resolves a tab from `paymentRequirements.extra.tabEndpoint`, builds V1 claims,
|
|
46
|
-
* signs them with EIP-712, and returns the base64-encoded payment header together
|
|
47
|
-
* with the raw payload and signature.
|
|
48
|
-
*
|
|
49
|
-
* @param paymentRequirements - V1 payment requirements from the `402 Payment Required` response.
|
|
50
|
-
* @param userAddress - Address of the paying user.
|
|
51
|
-
* @returns Signed payment ready to attach as the `X-PAYMENT` request header.
|
|
52
|
-
* @throws {@link X402Error} if the scheme is not a 4Mica scheme or the tab endpoint fails.
|
|
53
|
-
*/
|
|
54
|
-
signPayment(paymentRequirements: PaymentRequirementsV1, userAddress: string): Promise<X402SignedPayment>;
|
|
55
|
-
/**
|
|
56
|
-
* Sign an x402 V2 payment, optionally including a V2 validation policy.
|
|
57
|
-
*
|
|
58
|
-
* If `accepted.extra` contains all required validation policy fields
|
|
59
|
-
* (`validationRegistryAddress`, `validatorAddress`, `validatorAgentId`,
|
|
60
|
-
* `minValidationScore`, `validationChainId`, `jobHash`), the claims are built as V2 with
|
|
61
|
-
* the computed `validationSubjectHash` and `validationRequestHash`. Otherwise
|
|
62
|
-
* falls back to V1 claims.
|
|
63
|
-
*
|
|
64
|
-
* @param paymentRequired - The original `402 Payment Required` response object.
|
|
65
|
-
* @param accepted - The accepted V2 payment requirements.
|
|
66
|
-
* @param userAddress - Address of the paying user.
|
|
67
|
-
* @returns Signed payment ready to attach as the `X-PAYMENT` request header.
|
|
68
|
-
* @throws {@link X402Error} if the scheme is not a 4Mica scheme or the tab endpoint fails.
|
|
69
|
-
*/
|
|
70
|
-
signPaymentV2(paymentRequired: X402PaymentRequired, accepted: PaymentRequirementsV2, userAddress: string): Promise<X402SignedPayment>;
|
|
71
|
-
/**
|
|
72
|
-
* Submit a signed payment to a facilitator for on-chain settlement.
|
|
73
|
-
*
|
|
74
|
-
* Sends a POST request to `{facilitatorUrl}/settle` with the payment header,
|
|
75
|
-
* decoded payload, and payment requirements. Use this when the protected resource
|
|
76
|
-
* requires facilitator-confirmed settlement before granting access.
|
|
77
|
-
*
|
|
78
|
-
* @param payment - Signed payment returned by {@link signPayment} or {@link signPaymentV2}.
|
|
79
|
-
* @param paymentRequirements - V1 payment requirements included in the settlement request.
|
|
80
|
-
* @param facilitatorUrl - Base URL of the facilitator service.
|
|
81
|
-
* @returns The original payment plus the raw settlement response from the facilitator.
|
|
82
|
-
* @throws {@link X402Error} if the facilitator returns a non-2xx response.
|
|
83
|
-
*/
|
|
84
|
-
settlePayment(payment: X402SignedPayment, paymentRequirements: PaymentRequirementsV1, facilitatorUrl: string): Promise<X402SettledPayment>;
|
|
85
|
-
protected requestTab(x402Version: number, paymentRequirements: PaymentRequirementsV1 | PaymentRequirementsV2, userAddress: string, resource?: X402ResourceInfo): Promise<TabResponse>;
|
|
86
|
-
protected buildClaims(requirements: PaymentRequirementsV1 | PaymentRequirementsV2, tab: TabResponse, userAddress: string): PaymentGuaranteeRequestClaims;
|
|
87
|
-
protected buildClaimsV2(requirements: PaymentRequirementsV2, tab: TabResponse, userAddress: string): PaymentGuaranteeRequestClaimsV2;
|
|
88
|
-
private static validateScheme;
|
|
89
|
-
private static decodePaymentHeader;
|
|
90
|
-
}
|
package/dist/src/x402/index.js
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.X402Flow = void 0;
|
|
18
|
-
const models_1 = require("../models");
|
|
19
|
-
const utils_1 = require("../utils");
|
|
20
|
-
const errors_1 = require("../errors");
|
|
21
|
-
const payment_1 = require("../payment");
|
|
22
|
-
const validation_1 = require("../validation");
|
|
23
|
-
__exportStar(require("./models"), exports);
|
|
24
|
-
function hasValidationPolicy(extra) {
|
|
25
|
-
return !!(extra?.validationRegistryAddress &&
|
|
26
|
-
extra?.validatorAddress &&
|
|
27
|
-
extra?.validatorAgentId !== undefined &&
|
|
28
|
-
extra?.minValidationScore !== undefined &&
|
|
29
|
-
extra?.validationChainId !== undefined &&
|
|
30
|
-
extra?.jobHash);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Handles the x402 HTTP 402 payment protocol for 4Mica.
|
|
34
|
-
*
|
|
35
|
-
* Orchestrates the full client-side x402 flow: resolving a tab from the recipient's
|
|
36
|
-
* tab endpoint, building and signing payment claims (V1 or V2), and optionally settling
|
|
37
|
-
* the payment against a facilitator service.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* const flow = X402Flow.fromClient(client);
|
|
42
|
-
* const signed = await flow.signPayment(paymentRequirements, userAddress);
|
|
43
|
-
* // attach signed.header as the X-PAYMENT header on the protected request
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
class X402Flow {
|
|
47
|
-
signer;
|
|
48
|
-
fetchFn;
|
|
49
|
-
/**
|
|
50
|
-
* @param signer - Payment signer, typically `client.user`.
|
|
51
|
-
* @param fetchFn - HTTP fetch implementation. Defaults to global `fetch`.
|
|
52
|
-
*/
|
|
53
|
-
constructor(signer, fetchFn = fetch) {
|
|
54
|
-
this.signer = signer;
|
|
55
|
-
this.fetchFn = fetchFn;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Convenience factory — creates an `X402Flow` from the user sub-client of a `Client`.
|
|
59
|
-
*
|
|
60
|
-
* @param client - Any object with a `.user` property implementing {@link FlowSigner}.
|
|
61
|
-
*/
|
|
62
|
-
static fromClient(client) {
|
|
63
|
-
return new X402Flow(client.user);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Sign an x402 V1 payment.
|
|
67
|
-
*
|
|
68
|
-
* Resolves a tab from `paymentRequirements.extra.tabEndpoint`, builds V1 claims,
|
|
69
|
-
* signs them with EIP-712, and returns the base64-encoded payment header together
|
|
70
|
-
* with the raw payload and signature.
|
|
71
|
-
*
|
|
72
|
-
* @param paymentRequirements - V1 payment requirements from the `402 Payment Required` response.
|
|
73
|
-
* @param userAddress - Address of the paying user.
|
|
74
|
-
* @returns Signed payment ready to attach as the `X-PAYMENT` request header.
|
|
75
|
-
* @throws {@link X402Error} if the scheme is not a 4Mica scheme or the tab endpoint fails.
|
|
76
|
-
*/
|
|
77
|
-
async signPayment(paymentRequirements, userAddress) {
|
|
78
|
-
X402Flow.validateScheme(paymentRequirements.scheme);
|
|
79
|
-
const tab = await this.requestTab(1, paymentRequirements, userAddress);
|
|
80
|
-
const claims = this.buildClaims(paymentRequirements, tab, userAddress);
|
|
81
|
-
const signature = await this.signer.signPayment(claims, models_1.SigningScheme.EIP712);
|
|
82
|
-
const paymentPayload = (0, payment_1.buildPaymentPayload)(claims, signature);
|
|
83
|
-
const envelope = {
|
|
84
|
-
x402Version: 1,
|
|
85
|
-
scheme: paymentRequirements.scheme,
|
|
86
|
-
network: paymentRequirements.network,
|
|
87
|
-
payload: paymentPayload,
|
|
88
|
-
};
|
|
89
|
-
const header = Buffer.from(JSON.stringify(envelope)).toString('base64');
|
|
90
|
-
return { header, payload: paymentPayload, signature };
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Sign an x402 V2 payment, optionally including a V2 validation policy.
|
|
94
|
-
*
|
|
95
|
-
* If `accepted.extra` contains all required validation policy fields
|
|
96
|
-
* (`validationRegistryAddress`, `validatorAddress`, `validatorAgentId`,
|
|
97
|
-
* `minValidationScore`, `validationChainId`, `jobHash`), the claims are built as V2 with
|
|
98
|
-
* the computed `validationSubjectHash` and `validationRequestHash`. Otherwise
|
|
99
|
-
* falls back to V1 claims.
|
|
100
|
-
*
|
|
101
|
-
* @param paymentRequired - The original `402 Payment Required` response object.
|
|
102
|
-
* @param accepted - The accepted V2 payment requirements.
|
|
103
|
-
* @param userAddress - Address of the paying user.
|
|
104
|
-
* @returns Signed payment ready to attach as the `X-PAYMENT` request header.
|
|
105
|
-
* @throws {@link X402Error} if the scheme is not a 4Mica scheme or the tab endpoint fails.
|
|
106
|
-
*/
|
|
107
|
-
async signPaymentV2(paymentRequired, accepted, userAddress) {
|
|
108
|
-
X402Flow.validateScheme(accepted.scheme);
|
|
109
|
-
const isV2Claims = hasValidationPolicy(accepted.extra);
|
|
110
|
-
const tab = await this.requestTab(isV2Claims ? 2 : 1, accepted, userAddress, paymentRequired.resource);
|
|
111
|
-
const claims = isV2Claims
|
|
112
|
-
? this.buildClaimsV2(accepted, tab, userAddress)
|
|
113
|
-
: this.buildClaims(accepted, tab, userAddress);
|
|
114
|
-
const signature = await this.signer.signPayment(claims, models_1.SigningScheme.EIP712);
|
|
115
|
-
const paymentPayload = (0, payment_1.buildPaymentPayload)(claims, signature);
|
|
116
|
-
const envelope = {
|
|
117
|
-
x402Version: 2,
|
|
118
|
-
accepted: accepted,
|
|
119
|
-
payload: paymentPayload,
|
|
120
|
-
resource: paymentRequired.resource,
|
|
121
|
-
};
|
|
122
|
-
const header = Buffer.from(JSON.stringify(envelope)).toString('base64');
|
|
123
|
-
return { header, payload: paymentPayload, signature };
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Submit a signed payment to a facilitator for on-chain settlement.
|
|
127
|
-
*
|
|
128
|
-
* Sends a POST request to `{facilitatorUrl}/settle` with the payment header,
|
|
129
|
-
* decoded payload, and payment requirements. Use this when the protected resource
|
|
130
|
-
* requires facilitator-confirmed settlement before granting access.
|
|
131
|
-
*
|
|
132
|
-
* @param payment - Signed payment returned by {@link signPayment} or {@link signPaymentV2}.
|
|
133
|
-
* @param paymentRequirements - V1 payment requirements included in the settlement request.
|
|
134
|
-
* @param facilitatorUrl - Base URL of the facilitator service.
|
|
135
|
-
* @returns The original payment plus the raw settlement response from the facilitator.
|
|
136
|
-
* @throws {@link X402Error} if the facilitator returns a non-2xx response.
|
|
137
|
-
*/
|
|
138
|
-
async settlePayment(payment, paymentRequirements, facilitatorUrl) {
|
|
139
|
-
const url = `${facilitatorUrl.replace(/\/$/, '')}/settle`;
|
|
140
|
-
const paymentPayload = X402Flow.decodePaymentHeader(payment.header);
|
|
141
|
-
const x402Version = typeof paymentPayload === 'object' && paymentPayload && 'x402Version' in paymentPayload
|
|
142
|
-
? paymentPayload.x402Version
|
|
143
|
-
: undefined;
|
|
144
|
-
const response = await this.fetchFn(url, {
|
|
145
|
-
method: 'POST',
|
|
146
|
-
headers: { 'content-type': 'application/json' },
|
|
147
|
-
body: JSON.stringify({
|
|
148
|
-
...(x402Version ? { x402Version } : {}),
|
|
149
|
-
paymentHeader: payment.header,
|
|
150
|
-
paymentPayload,
|
|
151
|
-
paymentRequirements,
|
|
152
|
-
}),
|
|
153
|
-
});
|
|
154
|
-
const data = await response.text();
|
|
155
|
-
if (!response.ok) {
|
|
156
|
-
throw new errors_1.X402Error(`settlement failed with status ${response.status}: ${data}`);
|
|
157
|
-
}
|
|
158
|
-
const settlement = data ? JSON.parse(data) : {};
|
|
159
|
-
return { payment, settlement };
|
|
160
|
-
}
|
|
161
|
-
async requestTab(x402Version, paymentRequirements, userAddress, resource) {
|
|
162
|
-
const tabEndpoint = paymentRequirements.extra?.tabEndpoint;
|
|
163
|
-
if (!tabEndpoint || typeof tabEndpoint !== 'string') {
|
|
164
|
-
throw new errors_1.X402Error('missing tabEndpoint in paymentRequirements.extra');
|
|
165
|
-
}
|
|
166
|
-
const resp = await this.fetchFn(tabEndpoint, {
|
|
167
|
-
method: 'POST',
|
|
168
|
-
headers: { 'content-type': 'application/json' },
|
|
169
|
-
body: JSON.stringify({
|
|
170
|
-
x402Version,
|
|
171
|
-
userAddress,
|
|
172
|
-
paymentRequirements,
|
|
173
|
-
resource,
|
|
174
|
-
}),
|
|
175
|
-
});
|
|
176
|
-
if (!resp.ok) {
|
|
177
|
-
const text = await resp.text();
|
|
178
|
-
throw new errors_1.X402Error(`tab resolution failed: ${resp.status} ${text}`);
|
|
179
|
-
}
|
|
180
|
-
const body = await resp.json();
|
|
181
|
-
return {
|
|
182
|
-
tabId: body.tabId ?? body.tab_id,
|
|
183
|
-
userAddress: body.userAddress ?? body.user_address,
|
|
184
|
-
nextReqId: body.nextReqId ?? body.next_req_id ?? body.reqId ?? body.req_id,
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
buildClaims(requirements, tab, userAddress) {
|
|
188
|
-
const tabId = (0, utils_1.parseU256)(tab.tabId);
|
|
189
|
-
const reqId = tab.nextReqId !== undefined && tab.nextReqId !== null ? (0, utils_1.parseU256)(tab.nextReqId) : 0n;
|
|
190
|
-
const amount = (0, utils_1.parseU256)('maxAmountRequired' in requirements ? requirements.maxAmountRequired : requirements.amount);
|
|
191
|
-
if (tab.userAddress.toLowerCase() !== userAddress.toLowerCase()) {
|
|
192
|
-
throw new errors_1.X402Error(`user mismatch in paymentRequirements: found ${tab.userAddress}, expected ${userAddress}`);
|
|
193
|
-
}
|
|
194
|
-
const timestamp = Math.floor(Date.now() / 1000);
|
|
195
|
-
return models_1.PaymentGuaranteeRequestClaims.new(userAddress, (0, utils_1.normalizeAddress)(requirements.payTo), tabId, amount, timestamp, requirements.asset, reqId);
|
|
196
|
-
}
|
|
197
|
-
buildClaimsV2(requirements, tab, userAddress) {
|
|
198
|
-
const base = this.buildClaims(requirements, tab, userAddress);
|
|
199
|
-
const extra = requirements.extra;
|
|
200
|
-
const validationSubjectHash = (0, validation_1.computeValidationSubjectHash)(base);
|
|
201
|
-
const partialClaims = new models_1.PaymentGuaranteeRequestClaimsV2({
|
|
202
|
-
userAddress: base.userAddress,
|
|
203
|
-
recipientAddress: base.recipientAddress,
|
|
204
|
-
tabId: base.tabId,
|
|
205
|
-
reqId: base.reqId,
|
|
206
|
-
amount: base.amount,
|
|
207
|
-
timestamp: base.timestamp,
|
|
208
|
-
assetAddress: base.assetAddress,
|
|
209
|
-
validationRegistryAddress: extra.validationRegistryAddress,
|
|
210
|
-
validationRequestHash: '0x' + '00'.repeat(32),
|
|
211
|
-
validationChainId: extra.validationChainId,
|
|
212
|
-
validatorAddress: extra.validatorAddress,
|
|
213
|
-
validatorAgentId: (0, utils_1.parseU256)(extra.validatorAgentId),
|
|
214
|
-
minValidationScore: extra.minValidationScore,
|
|
215
|
-
validationSubjectHash,
|
|
216
|
-
jobHash: extra.jobHash,
|
|
217
|
-
requiredValidationTag: extra.requiredValidationTag ?? '',
|
|
218
|
-
});
|
|
219
|
-
const validationRequestHash = (0, validation_1.computeValidationRequestHash)(partialClaims);
|
|
220
|
-
return new models_1.PaymentGuaranteeRequestClaimsV2({
|
|
221
|
-
...partialClaims,
|
|
222
|
-
validationRequestHash,
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
static validateScheme(scheme) {
|
|
226
|
-
if (!scheme.toLowerCase().includes('4mica')) {
|
|
227
|
-
throw new errors_1.X402Error(`invalid scheme: ${scheme}`);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
static decodePaymentHeader(header) {
|
|
231
|
-
if (!header || typeof header !== 'string') {
|
|
232
|
-
throw new errors_1.X402Error('missing payment header');
|
|
233
|
-
}
|
|
234
|
-
try {
|
|
235
|
-
const decoded = Buffer.from(header, 'base64').toString('utf8');
|
|
236
|
-
return JSON.parse(decoded);
|
|
237
|
-
}
|
|
238
|
-
catch (err) {
|
|
239
|
-
throw new errors_1.X402Error(`invalid payment header: ${String(err)}`);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
exports.X402Flow = X402Flow;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { PaymentSignature } from '../models';
|
|
2
|
-
import type { PaymentPayload } from '../payment';
|
|
3
|
-
export interface PaymentRequirementsV1 {
|
|
4
|
-
scheme: string;
|
|
5
|
-
network: string;
|
|
6
|
-
maxAmountRequired: string;
|
|
7
|
-
payTo: string;
|
|
8
|
-
asset: string;
|
|
9
|
-
resource?: string;
|
|
10
|
-
description?: string;
|
|
11
|
-
mimeType?: string;
|
|
12
|
-
outputSchema?: unknown;
|
|
13
|
-
maxTimeoutSeconds?: number;
|
|
14
|
-
extra?: PaymentRequirementsExtra;
|
|
15
|
-
}
|
|
16
|
-
export interface PaymentRequirementsV2 {
|
|
17
|
-
scheme: string;
|
|
18
|
-
network: string;
|
|
19
|
-
asset: string;
|
|
20
|
-
amount: string;
|
|
21
|
-
payTo: string;
|
|
22
|
-
maxTimeoutSeconds?: number;
|
|
23
|
-
extra?: PaymentRequirementsExtra;
|
|
24
|
-
}
|
|
25
|
-
export type PaymentRequirements = PaymentRequirementsV2;
|
|
26
|
-
export interface PaymentRequirementsExtra {
|
|
27
|
-
tabEndpoint?: string;
|
|
28
|
-
validationRegistryAddress?: string;
|
|
29
|
-
validationChainId?: number;
|
|
30
|
-
validatorAddress?: string;
|
|
31
|
-
validatorAgentId?: string;
|
|
32
|
-
minValidationScore?: number;
|
|
33
|
-
jobHash?: string;
|
|
34
|
-
requiredValidationTag?: string;
|
|
35
|
-
}
|
|
36
|
-
export interface TabResponse {
|
|
37
|
-
tabId: string;
|
|
38
|
-
userAddress: string;
|
|
39
|
-
nextReqId?: string;
|
|
40
|
-
}
|
|
41
|
-
export type X402PaymentPayloadClaims = PaymentPayload['claims'];
|
|
42
|
-
export type X402PaymentPayload = PaymentPayload;
|
|
43
|
-
export interface X402PaymentEnvelopeV1 {
|
|
44
|
-
x402Version: number;
|
|
45
|
-
scheme: string;
|
|
46
|
-
network: string;
|
|
47
|
-
payload: X402PaymentPayload;
|
|
48
|
-
}
|
|
49
|
-
export interface X402ResourceInfo {
|
|
50
|
-
url: string;
|
|
51
|
-
description: string;
|
|
52
|
-
mimeType: string;
|
|
53
|
-
}
|
|
54
|
-
export interface X402PaymentEnvelopeV2 {
|
|
55
|
-
x402Version: number;
|
|
56
|
-
accepted: PaymentRequirementsV2;
|
|
57
|
-
payload: X402PaymentPayload;
|
|
58
|
-
resource: X402ResourceInfo;
|
|
59
|
-
}
|
|
60
|
-
export interface X402SignedPayment {
|
|
61
|
-
header: string;
|
|
62
|
-
payload: X402PaymentPayload;
|
|
63
|
-
signature: PaymentSignature;
|
|
64
|
-
}
|
|
65
|
-
export interface X402SettledPayment {
|
|
66
|
-
payment: X402SignedPayment;
|
|
67
|
-
settlement: unknown;
|
|
68
|
-
}
|
|
69
|
-
export interface X402PaymentRequired {
|
|
70
|
-
x402Version: number;
|
|
71
|
-
error?: string;
|
|
72
|
-
resource: X402ResourceInfo;
|
|
73
|
-
accepts: PaymentRequirementsV2[];
|
|
74
|
-
extensions?: Record<string, unknown>;
|
|
75
|
-
}
|
package/dist/src/x402/models.js
DELETED