@t402/core 2.4.0 → 2.6.0
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/cjs/client/index.d.ts +2 -2
- package/dist/cjs/client/index.js +43 -5
- package/dist/cjs/client/index.js.map +1 -1
- package/dist/cjs/facilitator/index.d.ts +1 -1
- package/dist/cjs/facilitator/index.js.map +1 -1
- package/dist/cjs/http/index.d.ts +3 -3
- package/dist/cjs/http/index.js +63 -10
- package/dist/cjs/http/index.js.map +1 -1
- package/dist/cjs/index.d.ts +23 -1
- package/dist/cjs/index.js +38 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/{mechanisms-C7yK91d4.d.ts → mechanisms-dYCiYgko.d.ts} +76 -7
- package/dist/cjs/server/index.d.ts +2 -2
- package/dist/cjs/server/index.js +54 -6
- package/dist/cjs/server/index.js.map +1 -1
- package/dist/cjs/{t402HTTPClient-DmkFydNG.d.ts → t402HTTPClient-CHaMMGBY.d.ts} +2 -2
- package/dist/cjs/{t402HTTPResourceServer-CybruqCk.d.ts → t402HTTPResourceServer-CGZh_p2c.d.ts} +2 -3
- package/dist/cjs/types/index.d.ts +1 -1
- package/dist/cjs/types/index.js +2 -1
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/v1/index.d.ts +1 -1
- package/dist/cjs/utils/index.d.ts +1 -1
- package/dist/esm/{chunk-KPNYZYDS.mjs → chunk-STKQDKUH.mjs} +3 -2
- package/dist/esm/chunk-STKQDKUH.mjs.map +1 -0
- package/dist/esm/chunk-YM7W5RG3.mjs +44 -0
- package/dist/esm/chunk-YM7W5RG3.mjs.map +1 -0
- package/dist/esm/{chunk-REMGOG6C.mjs → chunk-Z5HFSNZZ.mjs} +33 -12
- package/dist/esm/chunk-Z5HFSNZZ.mjs.map +1 -0
- package/dist/esm/client/index.d.mts +2 -2
- package/dist/esm/client/index.mjs +3 -3
- package/dist/esm/facilitator/index.d.mts +1 -1
- package/dist/esm/facilitator/index.mjs +1 -1
- package/dist/esm/http/index.d.mts +3 -3
- package/dist/esm/http/index.mjs +3 -3
- package/dist/esm/index.d.mts +23 -1
- package/dist/esm/index.mjs +3 -1
- package/dist/esm/{mechanisms-C7yK91d4.d.mts → mechanisms-dYCiYgko.d.mts} +76 -7
- package/dist/esm/server/index.d.mts +2 -2
- package/dist/esm/server/index.mjs +3 -3
- package/dist/esm/{t402HTTPClient-Bgjn3TRU.d.mts → t402HTTPClient-DbIXpGXL.d.mts} +2 -2
- package/dist/esm/{t402HTTPResourceServer-DuZIzhRI.d.mts → t402HTTPResourceServer-DDxVMmS2.d.mts} +2 -3
- package/dist/esm/types/index.d.mts +1 -1
- package/dist/esm/types/index.mjs +1 -1
- package/dist/esm/types/index.mjs.map +1 -1
- package/dist/esm/types/v1/index.d.mts +1 -1
- package/dist/esm/utils/index.d.mts +1 -1
- package/package.json +31 -15
- package/dist/esm/chunk-3VTYR43U.mjs +0 -7
- package/dist/esm/chunk-3VTYR43U.mjs.map +0 -1
- package/dist/esm/chunk-KPNYZYDS.mjs.map +0 -1
- package/dist/esm/chunk-REMGOG6C.mjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { C as CompiledRoute, D as DynamicPayTo,
|
|
3
|
-
export { f as t402HTTPClient } from '../t402HTTPClient-
|
|
1
|
+
import { c as PaymentRequired, S as SettleResponse, a as PaymentPayload, P as PaymentRequirements } from '../mechanisms-dYCiYgko.mjs';
|
|
2
|
+
export { C as CompiledRoute, D as DynamicPayTo, a as DynamicPrice, F as FacilitatorClient, b as FacilitatorConfig, H as HTTPAdapter, c as HTTPFacilitatorClient, d as HTTPProcessResult, e as HTTPRequestContext, f as HTTPResponseInstructions, P as PaymentOption, g as PaywallConfig, h as PaywallProvider, i as ProcessSettleFailureResponse, j as ProcessSettleResultResponse, k as ProcessSettleSuccessResponse, R as RouteConfig, l as RouteConfigurationError, m as RouteValidationError, n as RoutesConfig, U as UnpaidResponseBody, o as UnpaidResponseResult, t as t402HTTPResourceServer } from '../t402HTTPResourceServer-DDxVMmS2.mjs';
|
|
3
|
+
export { f as t402HTTPClient } from '../t402HTTPClient-DbIXpGXL.mjs';
|
|
4
4
|
import 'zod';
|
|
5
5
|
|
|
6
6
|
type QueryParamMethods = "GET" | "HEAD" | "DELETE";
|
package/dist/esm/http/index.mjs
CHANGED
|
@@ -9,9 +9,9 @@ import {
|
|
|
9
9
|
encodePaymentSignatureHeader,
|
|
10
10
|
t402HTTPClient,
|
|
11
11
|
t402HTTPResourceServer
|
|
12
|
-
} from "../chunk-
|
|
13
|
-
import "../chunk-
|
|
14
|
-
import "../chunk-
|
|
12
|
+
} from "../chunk-Z5HFSNZZ.mjs";
|
|
13
|
+
import "../chunk-YM7W5RG3.mjs";
|
|
14
|
+
import "../chunk-STKQDKUH.mjs";
|
|
15
15
|
import "../chunk-LJ4M5Z5U.mjs";
|
|
16
16
|
import "../chunk-4W2Y3RJM.mjs";
|
|
17
17
|
export {
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T402PaymentError - Structured error class for the T402 payment protocol.
|
|
3
|
+
*
|
|
4
|
+
* Wraps upstream errors with payment-specific context: phase, retryability,
|
|
5
|
+
* and optional HTTP status code.
|
|
6
|
+
*/
|
|
7
|
+
type PaymentPhase = "signing" | "submission" | "verification" | "settlement" | "unknown";
|
|
8
|
+
declare class T402PaymentError extends Error {
|
|
9
|
+
readonly cause?: Error;
|
|
10
|
+
readonly phase: PaymentPhase;
|
|
11
|
+
readonly retryable: boolean;
|
|
12
|
+
readonly code?: number;
|
|
13
|
+
constructor(message: string, options?: {
|
|
14
|
+
cause?: Error;
|
|
15
|
+
phase?: PaymentPhase;
|
|
16
|
+
retryable?: boolean;
|
|
17
|
+
code?: number;
|
|
18
|
+
});
|
|
19
|
+
isRetryable(): boolean;
|
|
20
|
+
toJSON(): Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
|
|
1
23
|
declare const t402Version = 2;
|
|
2
24
|
|
|
3
|
-
export { t402Version };
|
|
25
|
+
export { type PaymentPhase, T402PaymentError, t402Version };
|
package/dist/esm/index.mjs
CHANGED
|
@@ -240,42 +240,77 @@ declare const T402_A2A_EXTENSION_URI = "https://github.com/google-a2a/a2a-t402/v
|
|
|
240
240
|
declare const A2A_EXTENSIONS_HEADER = "X-A2A-Extensions";
|
|
241
241
|
/**
|
|
242
242
|
* Check if a task is in a payment-required state
|
|
243
|
+
*
|
|
244
|
+
* @param task - The A2A task to check
|
|
245
|
+
* @returns Whether the task requires payment
|
|
243
246
|
*/
|
|
244
247
|
declare function isPaymentRequired(task: A2ATask): boolean;
|
|
245
248
|
/**
|
|
246
249
|
* Check if a task has completed payment
|
|
250
|
+
*
|
|
251
|
+
* @param task - The A2A task to check
|
|
252
|
+
* @returns Whether the task has completed payment
|
|
247
253
|
*/
|
|
248
254
|
declare function isPaymentCompleted(task: A2ATask): boolean;
|
|
249
255
|
/**
|
|
250
256
|
* Check if a task has failed payment
|
|
257
|
+
*
|
|
258
|
+
* @param task - The A2A task to check
|
|
259
|
+
* @returns Whether the task has failed payment
|
|
251
260
|
*/
|
|
252
261
|
declare function isPaymentFailed(task: A2ATask): boolean;
|
|
253
262
|
/**
|
|
254
263
|
* Extract payment requirements from a task
|
|
264
|
+
*
|
|
265
|
+
* @param task - The A2A task to extract requirements from
|
|
266
|
+
* @returns The payment requirements if the task requires payment
|
|
255
267
|
*/
|
|
256
268
|
declare function getPaymentRequired(task: A2ATask): PaymentRequired | undefined;
|
|
257
269
|
/**
|
|
258
270
|
* Extract payment receipts from a task
|
|
271
|
+
*
|
|
272
|
+
* @param task - The A2A task to extract receipts from
|
|
273
|
+
* @returns The settlement receipts if available
|
|
259
274
|
*/
|
|
260
275
|
declare function getPaymentReceipts(task: A2ATask): SettleResponse[] | undefined;
|
|
261
276
|
/**
|
|
262
277
|
* Create a payment-required message
|
|
278
|
+
*
|
|
279
|
+
* @param paymentRequired - The payment requirements
|
|
280
|
+
* @param text - Optional message text
|
|
281
|
+
* @returns An A2A message with payment-required metadata
|
|
263
282
|
*/
|
|
264
283
|
declare function createPaymentRequiredMessage(paymentRequired: PaymentRequired, text?: string): A2AMessage;
|
|
265
284
|
/**
|
|
266
285
|
* Create a payment submission message
|
|
286
|
+
*
|
|
287
|
+
* @param paymentPayload - The payment payload to submit
|
|
288
|
+
* @param text - Optional message text
|
|
289
|
+
* @returns An A2A message with payment-submitted metadata
|
|
267
290
|
*/
|
|
268
291
|
declare function createPaymentSubmissionMessage(paymentPayload: PaymentPayload, text?: string): A2AMessage;
|
|
269
292
|
/**
|
|
270
293
|
* Create a payment completed message
|
|
294
|
+
*
|
|
295
|
+
* @param receipts - The settlement receipts
|
|
296
|
+
* @param text - Optional message text
|
|
297
|
+
* @returns An A2A message with payment-completed metadata
|
|
271
298
|
*/
|
|
272
299
|
declare function createPaymentCompletedMessage(receipts: SettleResponse[], text?: string): A2AMessage;
|
|
273
300
|
/**
|
|
274
301
|
* Create a payment failed message
|
|
302
|
+
*
|
|
303
|
+
* @param receipts - The settlement receipts
|
|
304
|
+
* @param errorCode - The error code
|
|
305
|
+
* @param text - Optional message text
|
|
306
|
+
* @returns An A2A message with payment-failed metadata
|
|
275
307
|
*/
|
|
276
308
|
declare function createPaymentFailedMessage(receipts: SettleResponse[], errorCode: string, text?: string): A2AMessage;
|
|
277
309
|
/**
|
|
278
310
|
* Create a T402 extension declaration for agent cards
|
|
311
|
+
*
|
|
312
|
+
* @param required - Whether the extension is required
|
|
313
|
+
* @returns An A2A extension declaration
|
|
279
314
|
*/
|
|
280
315
|
declare function createT402Extension(required?: boolean): A2AExtension;
|
|
281
316
|
|
|
@@ -564,17 +599,47 @@ interface APIError {
|
|
|
564
599
|
details?: string;
|
|
565
600
|
retry?: boolean;
|
|
566
601
|
}
|
|
567
|
-
/**
|
|
602
|
+
/**
|
|
603
|
+
* Returns the HTTP status code for a given error code
|
|
604
|
+
*
|
|
605
|
+
* @param code - The T402 error code
|
|
606
|
+
* @returns The corresponding HTTP status code
|
|
607
|
+
*/
|
|
568
608
|
declare function httpStatusForCode(code: ErrorCode): number;
|
|
569
|
-
/**
|
|
609
|
+
/**
|
|
610
|
+
* Returns true if the error code is a client error (T402-1xxx)
|
|
611
|
+
*
|
|
612
|
+
* @param code - The T402 error code
|
|
613
|
+
* @returns Whether the error is a client error
|
|
614
|
+
*/
|
|
570
615
|
declare function isClientError(code: ErrorCode): boolean;
|
|
571
|
-
/**
|
|
616
|
+
/**
|
|
617
|
+
* Returns true if the error code is a server error (T402-2xxx)
|
|
618
|
+
*
|
|
619
|
+
* @param code - The T402 error code
|
|
620
|
+
* @returns Whether the error is a server error
|
|
621
|
+
*/
|
|
572
622
|
declare function isServerError(code: ErrorCode): boolean;
|
|
573
|
-
/**
|
|
623
|
+
/**
|
|
624
|
+
* Returns true if the error code is a facilitator error (T402-3xxx)
|
|
625
|
+
*
|
|
626
|
+
* @param code - The T402 error code
|
|
627
|
+
* @returns Whether the error is a facilitator error
|
|
628
|
+
*/
|
|
574
629
|
declare function isFacilitatorError(code: ErrorCode): boolean;
|
|
575
|
-
/**
|
|
630
|
+
/**
|
|
631
|
+
* Returns true if the error code is a chain error (T402-4xxx)
|
|
632
|
+
*
|
|
633
|
+
* @param code - The T402 error code
|
|
634
|
+
* @returns Whether the error is a chain error
|
|
635
|
+
*/
|
|
576
636
|
declare function isChainError(code: ErrorCode): boolean;
|
|
577
|
-
/**
|
|
637
|
+
/**
|
|
638
|
+
* Returns true if the error code is a bridge error (T402-5xxx)
|
|
639
|
+
*
|
|
640
|
+
* @param code - The T402 error code
|
|
641
|
+
* @returns Whether the error is a bridge error
|
|
642
|
+
*/
|
|
578
643
|
declare function isBridgeError(code: ErrorCode): boolean;
|
|
579
644
|
|
|
580
645
|
/**
|
|
@@ -797,18 +862,21 @@ declare const SettleResponseSchema: z.ZodObject<{
|
|
|
797
862
|
network: z.ZodString;
|
|
798
863
|
errorReason: z.ZodOptional<z.ZodString>;
|
|
799
864
|
payer: z.ZodOptional<z.ZodString>;
|
|
865
|
+
confirmations: z.ZodOptional<z.ZodString>;
|
|
800
866
|
}, "strip", z.ZodTypeAny, {
|
|
801
867
|
network: string;
|
|
802
868
|
success: boolean;
|
|
803
869
|
transaction: string;
|
|
804
870
|
payer?: string | undefined;
|
|
805
871
|
errorReason?: string | undefined;
|
|
872
|
+
confirmations?: string | undefined;
|
|
806
873
|
}, {
|
|
807
874
|
network: string;
|
|
808
875
|
success: boolean;
|
|
809
876
|
transaction: string;
|
|
810
877
|
payer?: string | undefined;
|
|
811
878
|
errorReason?: string | undefined;
|
|
879
|
+
confirmations?: string | undefined;
|
|
812
880
|
}>;
|
|
813
881
|
declare const PaymentRequirementsV1Schema: z.ZodObject<{
|
|
814
882
|
scheme: z.ZodString;
|
|
@@ -996,6 +1064,7 @@ type SettleResponse = {
|
|
|
996
1064
|
payer?: string;
|
|
997
1065
|
transaction: string;
|
|
998
1066
|
network: Network;
|
|
1067
|
+
confirmations?: string;
|
|
999
1068
|
};
|
|
1000
1069
|
type SupportedKind = {
|
|
1001
1070
|
t402Version: number;
|
|
@@ -1123,4 +1192,4 @@ interface SchemeNetworkServer {
|
|
|
1123
1192
|
}, facilitatorExtensions: string[]): Promise<PaymentRequirements>;
|
|
1124
1193
|
}
|
|
1125
1194
|
|
|
1126
|
-
export {
|
|
1195
|
+
export { ERR_GAS_ESTIMATION_FAILED as $, type A2AAgentCard as A, type A2AResponse as B, type A2ASkill as C, type A2ATask as D, type A2ATaskState as E, type A2ATaskStatus as F, type A2ATextPart as G, A2A_EXTENSIONS_HEADER as H, type APIError as I, type AssetAmount as J, ERR_ALLOWANCE_INSUFFICIENT as K, ERR_BRIDGE_QUOTE_FAILED as L, ERR_BRIDGE_TIMEOUT as M, type Network as N, ERR_BRIDGE_TRANSFER_FAILED as O, type PaymentRequirements as P, ERR_BRIDGE_UNAVAILABLE as Q, type ResourceServerExtension as R, type SettleResponse as S, ERR_CACHE_UNAVAILABLE as T, ERR_CHAIN_CONGESTED as U, type VerifyResponse as V, ERR_CHAIN_UNAVAILABLE as W, ERR_CONTRACT_ERROR as X, ERR_DATABASE_UNAVAILABLE as Y, ERR_DUPLICATE_PAYMENT as Z, ERR_EXPIRED_PAYMENT as _, type PaymentPayload as a, type SettleRequest as a$, ERR_IDEMPOTENCY_CONFLICT as a0, ERR_IDEMPOTENCY_UNAVAILABLE as a1, ERR_INSUFFICIENT_AMOUNT as a2, ERR_INSUFFICIENT_BALANCE as a3, ERR_INTENT_ALREADY_EXECUTED as a4, ERR_INTENT_CANCELLED as a5, ERR_INTENT_EXPIRED as a6, ERR_INTENT_INVALID_STATE as a7, ERR_INTENT_NOT_FOUND as a8, ERR_INTERNAL as a9, ERR_SERVICE_UNAVAILABLE as aA, ERR_SETTLEMENT_FAILED as aB, ERR_SETTLEMENT_PENDING as aC, ERR_SETTLEMENT_TIMEOUT as aD, ERR_SIGNATURE_EXPIRED as aE, ERR_STREAM_ALREADY_CLOSED as aF, ERR_STREAM_ALREADY_PAUSED as aG, ERR_STREAM_AMOUNT_EXCEEDED as aH, ERR_STREAM_EXPIRED as aI, ERR_STREAM_INVALID_STATE as aJ, ERR_STREAM_NOT_FOUND as aK, ERR_STREAM_NOT_PAUSED as aL, ERR_STREAM_RATE_LIMITED as aM, ERR_TRANSACTION_FAILED as aN, ERR_TRANSACTION_REVERTED as aO, ERR_UNSUPPORTED_ROUTE as aP, ERR_VERIFICATION_FAILED as aQ, type ErrorCode as aR, type Money as aS, type MoneyParser as aT, NetworkSchema as aU, PaymentPayloadSchema as aV, PaymentPayloadV1Schema as aW, PaymentRequiredSchema as aX, PaymentRequirementsSchema as aY, PaymentRequirementsV1Schema as aZ, ResourceInfoSchema as a_, ERR_INVALID_ADDRESS as aa, ERR_INVALID_AMOUNT as ab, ERR_INVALID_IDEMPOTENCY_KEY as ac, ERR_INVALID_NETWORK as ad, ERR_INVALID_NONCE as ae, ERR_INVALID_PARAMETERS as af, ERR_INVALID_PAYLOAD as ag, ERR_INVALID_REQUEST as ah, ERR_INVALID_REQUIREMENTS as ai, ERR_INVALID_SCHEME as aj, ERR_INVALID_SIGNATURE as ak, ERR_MISSING_PAYLOAD as al, ERR_MISSING_REQUIREMENTS as am, ERR_NONCE_CONFLICT as an, ERR_NONCE_REPLAY as ao, ERR_NOT_AUTHORIZED as ap, ERR_NO_ROUTES_AVAILABLE as aq, ERR_PAYMENT_MISMATCH as ar, ERR_PREVIOUS_REQUEST_FAILED as as, ERR_RATE_LIMITED as at, ERR_REQUEST_IN_PROGRESS as au, ERR_RESOURCE_ALREADY_EXISTS as av, ERR_RESOURCE_NOT_FOUND as aw, ERR_ROUTE_EXPIRED as ax, ERR_ROUTE_NOT_SELECTED as ay, ERR_RPC_UNAVAILABLE as az, type SchemeNetworkFacilitator as b, SettleResponseSchema as b0, T402_A2A_EXTENSION_URI as b1, UPTO_DEFAULTS as b2, UPTO_SCHEME as b3, type UptoEvmPayload as b4, type UptoEvmPayloadCompact as b5, type UptoExtra as b6, type UptoPayloadBase as b7, type UptoPaymentRequirements as b8, type UptoSettlement as b9, isServerError as bA, isUptoEvmPayload as bB, isUptoPaymentRequirements as bC, parsePaymentPayload as bD, parsePaymentRequired as bE, parsePaymentRequirements as bF, safeParsePaymentPayload as bG, safeParsePaymentRequired as bH, safeParsePaymentRequirements as bI, type UptoSettlementResponse as ba, type UptoUnit as bb, type UptoUsageDetails as bc, type UptoValidationResult as bd, type ValidatedPaymentPayload as be, type ValidatedPaymentRequired as bf, type ValidatedPaymentRequirements as bg, type ValidatedSettleResponse as bh, type ValidatedVerifyResponse as bi, type VerifyRequest as bj, VerifyResponseSchema as bk, createPaymentCompletedMessage as bl, createPaymentFailedMessage as bm, createPaymentRequiredMessage as bn, createPaymentSubmissionMessage as bo, createT402Extension as bp, getPaymentReceipts as bq, getPaymentRequired as br, httpStatusForCode as bs, isBridgeError as bt, isChainError as bu, isClientError as bv, isFacilitatorError as bw, isPaymentCompleted as bx, isPaymentFailed as by, isPaymentRequired as bz, type PaymentRequired as c, type SchemeNetworkClient as d, type SupportedResponse as e, type SchemeNetworkServer as f, type SupportedKind as g, type Price as h, type PaymentPayloadV1 as i, type PaymentRequiredV1 as j, type PaymentRequirementsV1 as k, type SettleRequestV1 as l, type SettleResponseV1 as m, type SupportedResponseV1 as n, type VerifyRequestV1 as o, type A2AArtifact as p, type A2ACapabilities as q, type A2ADataPart as r, type A2AError as s, type A2AExtension as t, type A2AFilePart as u, type A2AMessage as v, type A2AMessagePart as w, type A2APaymentMetadata as x, type A2APaymentStatus as y, type A2ARequest as z };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { C as CompiledRoute, F as FacilitatorClient,
|
|
2
|
-
import '../mechanisms-
|
|
1
|
+
export { C as CompiledRoute, F as FacilitatorClient, b as FacilitatorConfig, H as HTTPAdapter, c as HTTPFacilitatorClient, d as HTTPProcessResult, e as HTTPRequestContext, f as HTTPResponseInstructions, g as PaywallConfig, h as PaywallProvider, i as ProcessSettleFailureResponse, j as ProcessSettleResultResponse, k as ProcessSettleSuccessResponse, p as ResourceConfig, q as ResourceInfo, R as RouteConfig, l as RouteConfigurationError, m as RouteValidationError, n as RoutesConfig, U as UnpaidResponseBody, o as UnpaidResponseResult, t as t402HTTPResourceServer, r as t402ResourceServer } from '../t402HTTPResourceServer-DDxVMmS2.mjs';
|
|
2
|
+
import '../mechanisms-dYCiYgko.mjs';
|
|
3
3
|
import 'zod';
|
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
HTTPFacilitatorClient,
|
|
3
3
|
RouteConfigurationError,
|
|
4
4
|
t402HTTPResourceServer
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-Z5HFSNZZ.mjs";
|
|
6
6
|
import {
|
|
7
7
|
t402Version
|
|
8
|
-
} from "../chunk-
|
|
9
|
-
import "../chunk-
|
|
8
|
+
} from "../chunk-YM7W5RG3.mjs";
|
|
9
|
+
import "../chunk-STKQDKUH.mjs";
|
|
10
10
|
import {
|
|
11
11
|
deepEqual,
|
|
12
12
|
findByNetworkAndScheme
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as PaymentRequired, P as PaymentRequirements, a as PaymentPayload, N as Network, d as SchemeNetworkClient, S as SettleResponse } from './mechanisms-
|
|
1
|
+
import { c as PaymentRequired, P as PaymentRequirements, a as PaymentPayload, N as Network, d as SchemeNetworkClient, S as SettleResponse } from './mechanisms-dYCiYgko.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Client Hook Context Interfaces
|
|
@@ -240,4 +240,4 @@ declare class t402HTTPClient {
|
|
|
240
240
|
createPaymentPayload(paymentRequired: PaymentRequired): Promise<PaymentPayload>;
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
-
export { type AfterPaymentCreationHook as A, type BeforePaymentCreationHook as B, type OnPaymentCreationFailureHook as O, type
|
|
243
|
+
export { type AfterPaymentCreationHook as A, type BeforePaymentCreationHook as B, type OnPaymentCreationFailureHook as O, type PaymentCreatedContext as P, type SchemeRegistration as S, type PaymentCreationContext as a, type PaymentCreationFailureContext as b, type PaymentPolicy as c, type SelectPaymentRequirements as d, type t402ClientConfig as e, t402HTTPClient as f, t402Client as t };
|
package/dist/esm/{t402HTTPResourceServer-DuZIzhRI.d.mts → t402HTTPResourceServer-DDxVMmS2.d.mts}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as PaymentPayload, P as PaymentRequirements, V as VerifyResponse, S as SettleResponse, e as SupportedResponse, N as Network, f as SchemeNetworkServer, R as ResourceServerExtension, g as SupportedKind, h as Price, c as PaymentRequired } from './mechanisms-
|
|
1
|
+
import { a as PaymentPayload, P as PaymentRequirements, V as VerifyResponse, S as SettleResponse, e as SupportedResponse, N as Network, f as SchemeNetworkServer, R as ResourceServerExtension, g as SupportedKind, h as Price, c as PaymentRequired } from './mechanisms-dYCiYgko.mjs';
|
|
2
2
|
|
|
3
3
|
interface FacilitatorConfig {
|
|
4
4
|
url?: string;
|
|
@@ -467,7 +467,6 @@ interface RouteConfig {
|
|
|
467
467
|
*
|
|
468
468
|
* If not provided, defaults to { contentType: 'application/json', body: {} }.
|
|
469
469
|
*
|
|
470
|
-
* @param context - The HTTP request context
|
|
471
470
|
* @returns An object containing both contentType and body for the 402 response
|
|
472
471
|
*/
|
|
473
472
|
unpaidResponseBody?: UnpaidResponseBody;
|
|
@@ -716,4 +715,4 @@ declare class t402HTTPResourceServer {
|
|
|
716
715
|
private getDisplayAmount;
|
|
717
716
|
}
|
|
718
717
|
|
|
719
|
-
export { type CompiledRoute as C, type DynamicPayTo as D, type FacilitatorClient as F,
|
|
718
|
+
export { type CompiledRoute as C, type DynamicPayTo as D, type FacilitatorClient as F, type HTTPAdapter as H, type PaymentOption as P, type RouteConfig as R, type UnpaidResponseBody as U, type DynamicPrice as a, type FacilitatorConfig as b, HTTPFacilitatorClient as c, type HTTPProcessResult as d, type HTTPRequestContext as e, type HTTPResponseInstructions as f, type PaywallConfig as g, type PaywallProvider as h, type ProcessSettleFailureResponse as i, type ProcessSettleResultResponse as j, type ProcessSettleSuccessResponse as k, RouteConfigurationError as l, type RouteValidationError as m, type RoutesConfig as n, type UnpaidResponseResult as o, type ResourceConfig as p, type ResourceInfo as q, t402ResourceServer as r, t402HTTPResourceServer as t };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { A as A2AAgentCard, p as A2AArtifact, q as A2ACapabilities, r as A2ADataPart, s as A2AError, t as A2AExtension, u as A2AFilePart, v as A2AMessage, w as A2AMessagePart, x as A2APaymentMetadata, y as A2APaymentStatus, z as A2ARequest, B as A2AResponse, C as A2ASkill, D as A2ATask, E as A2ATaskState, F as A2ATaskStatus, G as A2ATextPart, H as A2A_EXTENSIONS_HEADER, I as APIError, J as AssetAmount, K as ERR_ALLOWANCE_INSUFFICIENT, L as ERR_BRIDGE_QUOTE_FAILED, M as ERR_BRIDGE_TIMEOUT, O as ERR_BRIDGE_TRANSFER_FAILED, Q as ERR_BRIDGE_UNAVAILABLE, T as ERR_CACHE_UNAVAILABLE, U as ERR_CHAIN_CONGESTED, W as ERR_CHAIN_UNAVAILABLE, X as ERR_CONTRACT_ERROR, Y as ERR_DATABASE_UNAVAILABLE, Z as ERR_DUPLICATE_PAYMENT, _ as ERR_EXPIRED_PAYMENT, $ as ERR_GAS_ESTIMATION_FAILED, a0 as ERR_IDEMPOTENCY_CONFLICT, a1 as ERR_IDEMPOTENCY_UNAVAILABLE, a2 as ERR_INSUFFICIENT_AMOUNT, a3 as ERR_INSUFFICIENT_BALANCE, a4 as ERR_INTENT_ALREADY_EXECUTED, a5 as ERR_INTENT_CANCELLED, a6 as ERR_INTENT_EXPIRED, a7 as ERR_INTENT_INVALID_STATE, a8 as ERR_INTENT_NOT_FOUND, a9 as ERR_INTERNAL, aa as ERR_INVALID_ADDRESS, ab as ERR_INVALID_AMOUNT, ac as ERR_INVALID_IDEMPOTENCY_KEY, ad as ERR_INVALID_NETWORK, ae as ERR_INVALID_NONCE, af as ERR_INVALID_PARAMETERS, ag as ERR_INVALID_PAYLOAD, ah as ERR_INVALID_REQUEST, ai as ERR_INVALID_REQUIREMENTS, aj as ERR_INVALID_SCHEME, ak as ERR_INVALID_SIGNATURE, al as ERR_MISSING_PAYLOAD, am as ERR_MISSING_REQUIREMENTS, an as ERR_NONCE_CONFLICT, ao as ERR_NONCE_REPLAY, ap as ERR_NOT_AUTHORIZED, aq as ERR_NO_ROUTES_AVAILABLE, ar as ERR_PAYMENT_MISMATCH, as as ERR_PREVIOUS_REQUEST_FAILED, at as ERR_RATE_LIMITED, au as ERR_REQUEST_IN_PROGRESS, av as ERR_RESOURCE_ALREADY_EXISTS, aw as ERR_RESOURCE_NOT_FOUND, ax as ERR_ROUTE_EXPIRED, ay as ERR_ROUTE_NOT_SELECTED, az as ERR_RPC_UNAVAILABLE, aA as ERR_SERVICE_UNAVAILABLE, aB as ERR_SETTLEMENT_FAILED, aC as ERR_SETTLEMENT_PENDING, aD as ERR_SETTLEMENT_TIMEOUT, aE as ERR_SIGNATURE_EXPIRED, aF as ERR_STREAM_ALREADY_CLOSED, aG as ERR_STREAM_ALREADY_PAUSED, aH as ERR_STREAM_AMOUNT_EXCEEDED, aI as ERR_STREAM_EXPIRED, aJ as ERR_STREAM_INVALID_STATE, aK as ERR_STREAM_NOT_FOUND, aL as ERR_STREAM_NOT_PAUSED, aM as ERR_STREAM_RATE_LIMITED, aN as ERR_TRANSACTION_FAILED, aO as ERR_TRANSACTION_REVERTED, aP as ERR_UNSUPPORTED_ROUTE, aQ as ERR_VERIFICATION_FAILED, aR as ErrorCode, aS as Money, aT as MoneyParser, N as Network, aU as NetworkSchema, a as PaymentPayload, aV as PaymentPayloadSchema, i as PaymentPayloadV1, aW as PaymentPayloadV1Schema, c as PaymentRequired, aX as PaymentRequiredSchema, j as PaymentRequiredV1, P as PaymentRequirements, aY as PaymentRequirementsSchema, k as PaymentRequirementsV1, aZ as PaymentRequirementsV1Schema, h as Price, a_ as ResourceInfoSchema, R as ResourceServerExtension, d as SchemeNetworkClient, b as SchemeNetworkFacilitator, f as SchemeNetworkServer, a$ as SettleRequest, S as SettleResponse, b0 as SettleResponseSchema, e as SupportedResponse, b1 as T402_A2A_EXTENSION_URI, b2 as UPTO_DEFAULTS, b3 as UPTO_SCHEME, b4 as UptoEvmPayload, b5 as UptoEvmPayloadCompact, b6 as UptoExtra, b7 as UptoPayloadBase, b8 as UptoPaymentRequirements, b9 as UptoSettlement, ba as UptoSettlementResponse, bb as UptoUnit, bc as UptoUsageDetails, bd as UptoValidationResult, be as ValidatedPaymentPayload, bf as ValidatedPaymentRequired, bg as ValidatedPaymentRequirements, bh as ValidatedSettleResponse, bi as ValidatedVerifyResponse, bj as VerifyRequest, V as VerifyResponse, bk as VerifyResponseSchema, bl as createPaymentCompletedMessage, bm as createPaymentFailedMessage, bn as createPaymentRequiredMessage, bo as createPaymentSubmissionMessage, bp as createT402Extension, bq as getPaymentReceipts, br as getPaymentRequired, bs as httpStatusForCode, bt as isBridgeError, bu as isChainError, bv as isClientError, bw as isFacilitatorError, bx as isPaymentCompleted, by as isPaymentFailed, bz as isPaymentRequired, bA as isServerError, bB as isUptoEvmPayload, bC as isUptoPaymentRequirements, bD as parsePaymentPayload, bE as parsePaymentRequired, bF as parsePaymentRequirements, bG as safeParsePaymentPayload, bH as safeParsePaymentRequired, bI as safeParsePaymentRequirements } from '../mechanisms-dYCiYgko.mjs';
|
|
2
2
|
import 'zod';
|
package/dist/esm/types/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/a2a.ts","../../../src/types/schemes/upto.ts","../../../src/types/errors.ts"],"sourcesContent":["/**\n * A2A (Agent-to-Agent) Transport Types\n *\n * Implements t402 payment flows over the Agent-to-Agent protocol\n * using JSON-RPC messages and task-based state management.\n *\n * @see https://github.com/google-a2a/a2a-t402/v0.1\n */\n\nimport type { PaymentPayload, PaymentRequired } from \"./payments\";\nimport type { SettleResponse } from \"./facilitator\";\n\n// ============================================================================\n// A2A Payment Status\n// ============================================================================\n\n/**\n * Payment status values used in A2A metadata\n */\nexport type A2APaymentStatus =\n | \"payment-required\" // Payment requirements sent to client\n | \"payment-rejected\" // Client rejected payment requirements\n | \"payment-submitted\" // Payment payload received by server\n | \"payment-verified\" // Payment payload verified by server\n | \"payment-completed\" // Payment settled on-chain successfully\n | \"payment-failed\"; // Payment verification or settlement failed\n\n/**\n * A2A task states that correspond to payment states\n */\nexport type A2ATaskState =\n | \"submitted\"\n | \"working\"\n | \"input-required\"\n | \"completed\"\n | \"canceled\"\n | \"failed\"\n | \"unknown\";\n\n// ============================================================================\n// A2A Message Types\n// ============================================================================\n\n/**\n * A2A message part - text content\n */\nexport interface A2ATextPart {\n kind: \"text\";\n text: string;\n}\n\n/**\n * A2A message part - file content\n */\nexport interface A2AFilePart {\n kind: \"file\";\n file: {\n name?: string;\n mimeType?: string;\n bytes?: string; // base64 encoded\n uri?: string;\n };\n}\n\n/**\n * A2A message part - data content\n */\nexport interface A2ADataPart {\n kind: \"data\";\n data: Record<string, unknown>;\n}\n\nexport type A2AMessagePart = A2ATextPart | A2AFilePart | A2ADataPart;\n\n/**\n * A2A payment metadata fields\n */\nexport interface A2APaymentMetadata {\n /** Current payment status */\n \"t402.payment.status\"?: A2APaymentStatus;\n\n /** Payment requirements (when status is payment-required) */\n \"t402.payment.required\"?: PaymentRequired;\n\n /** Payment payload (when status is payment-submitted) */\n \"t402.payment.payload\"?: PaymentPayload;\n\n /** Settlement receipts (when status is payment-completed or payment-failed) */\n \"t402.payment.receipts\"?: SettleResponse[];\n\n /** Error code (when status is payment-failed) */\n \"t402.payment.error\"?: string;\n}\n\n/**\n * A2A message with payment metadata\n */\nexport interface A2AMessage {\n kind: \"message\";\n messageId?: string;\n role: \"user\" | \"agent\";\n parts: A2AMessagePart[];\n metadata?: A2APaymentMetadata & Record<string, unknown>;\n}\n\n// ============================================================================\n// A2A Task Types\n// ============================================================================\n\n/**\n * A2A artifact (output from completed task)\n */\nexport interface A2AArtifact {\n kind: string;\n name?: string;\n mimeType?: string;\n data?: string; // base64 encoded\n uri?: string;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * A2A task status\n */\nexport interface A2ATaskStatus {\n state: A2ATaskState;\n message?: A2AMessage;\n timestamp?: string;\n}\n\n/**\n * A2A task\n */\nexport interface A2ATask {\n kind: \"task\";\n id: string;\n sessionId?: string;\n status: A2ATaskStatus;\n artifacts?: A2AArtifact[];\n history?: A2AMessage[];\n metadata?: Record<string, unknown>;\n}\n\n// ============================================================================\n// A2A JSON-RPC Types\n// ============================================================================\n\n/**\n * A2A JSON-RPC request\n */\nexport interface A2ARequest<T = unknown> {\n jsonrpc: \"2.0\";\n method: string;\n id: string | number;\n params?: T;\n}\n\n/**\n * A2A JSON-RPC response\n */\nexport interface A2AResponse<T = unknown> {\n jsonrpc: \"2.0\";\n id: string | number;\n result?: T;\n error?: A2AError;\n}\n\n/**\n * A2A JSON-RPC error\n */\nexport interface A2AError {\n code: number;\n message: string;\n data?: unknown;\n}\n\n// ============================================================================\n// A2A Extension Types\n// ============================================================================\n\n/**\n * A2A extension declaration\n */\nexport interface A2AExtension {\n uri: string;\n description?: string;\n required?: boolean;\n}\n\n/**\n * A2A agent capabilities\n */\nexport interface A2ACapabilities {\n streaming?: boolean;\n pushNotifications?: boolean;\n stateTransitionHistory?: boolean;\n extensions?: A2AExtension[];\n}\n\n/**\n * A2A agent card (service advertisement)\n */\nexport interface A2AAgentCard {\n name: string;\n description?: string;\n url: string;\n provider?: {\n organization?: string;\n url?: string;\n };\n version?: string;\n documentationUrl?: string;\n capabilities?: A2ACapabilities;\n authentication?: {\n schemes: string[];\n credentials?: string;\n };\n defaultInputModes?: string[];\n defaultOutputModes?: string[];\n skills?: A2ASkill[];\n}\n\n/**\n * A2A skill definition\n */\nexport interface A2ASkill {\n id: string;\n name: string;\n description?: string;\n tags?: string[];\n examples?: string[];\n inputModes?: string[];\n outputModes?: string[];\n}\n\n// ============================================================================\n// T402-A2A Constants\n// ============================================================================\n\n/**\n * T402 A2A extension URI\n */\nexport const T402_A2A_EXTENSION_URI = \"https://github.com/google-a2a/a2a-t402/v0.1\";\n\n/**\n * HTTP header for A2A extension activation\n */\nexport const A2A_EXTENSIONS_HEADER = \"X-A2A-Extensions\";\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n/**\n * Check if a task is in a payment-required state\n */\nexport function isPaymentRequired(task: A2ATask): boolean {\n return (\n task.status.state === \"input-required\" &&\n task.status.message?.metadata?.[\"t402.payment.status\"] === \"payment-required\"\n );\n}\n\n/**\n * Check if a task has completed payment\n */\nexport function isPaymentCompleted(task: A2ATask): boolean {\n return (\n task.status.state === \"completed\" &&\n task.status.message?.metadata?.[\"t402.payment.status\"] === \"payment-completed\"\n );\n}\n\n/**\n * Check if a task has failed payment\n */\nexport function isPaymentFailed(task: A2ATask): boolean {\n return (\n task.status.state === \"failed\" &&\n task.status.message?.metadata?.[\"t402.payment.status\"] === \"payment-failed\"\n );\n}\n\n/**\n * Extract payment requirements from a task\n */\nexport function getPaymentRequired(task: A2ATask): PaymentRequired | undefined {\n if (isPaymentRequired(task)) {\n return task.status.message?.metadata?.[\"t402.payment.required\"];\n }\n return undefined;\n}\n\n/**\n * Extract payment receipts from a task\n */\nexport function getPaymentReceipts(task: A2ATask): SettleResponse[] | undefined {\n return task.status.message?.metadata?.[\"t402.payment.receipts\"];\n}\n\n/**\n * Create a payment-required message\n */\nexport function createPaymentRequiredMessage(\n paymentRequired: PaymentRequired,\n text: string = \"Payment is required to complete this request.\",\n): A2AMessage {\n return {\n kind: \"message\",\n role: \"agent\",\n parts: [{ kind: \"text\", text }],\n metadata: {\n \"t402.payment.status\": \"payment-required\",\n \"t402.payment.required\": paymentRequired,\n },\n };\n}\n\n/**\n * Create a payment submission message\n */\nexport function createPaymentSubmissionMessage(\n paymentPayload: PaymentPayload,\n text: string = \"Here is the payment authorization.\",\n): A2AMessage {\n return {\n kind: \"message\",\n role: \"user\",\n parts: [{ kind: \"text\", text }],\n metadata: {\n \"t402.payment.status\": \"payment-submitted\",\n \"t402.payment.payload\": paymentPayload,\n },\n };\n}\n\n/**\n * Create a payment completed message\n */\nexport function createPaymentCompletedMessage(\n receipts: SettleResponse[],\n text: string = \"Payment successful.\",\n): A2AMessage {\n return {\n kind: \"message\",\n role: \"agent\",\n parts: [{ kind: \"text\", text }],\n metadata: {\n \"t402.payment.status\": \"payment-completed\",\n \"t402.payment.receipts\": receipts,\n },\n };\n}\n\n/**\n * Create a payment failed message\n */\nexport function createPaymentFailedMessage(\n receipts: SettleResponse[],\n errorCode: string,\n text: string = \"Payment failed.\",\n): A2AMessage {\n return {\n kind: \"message\",\n role: \"agent\",\n parts: [{ kind: \"text\", text }],\n metadata: {\n \"t402.payment.status\": \"payment-failed\",\n \"t402.payment.error\": errorCode,\n \"t402.payment.receipts\": receipts,\n },\n };\n}\n\n/**\n * Create a T402 extension declaration for agent cards\n */\nexport function createT402Extension(required: boolean = false): A2AExtension {\n return {\n uri: T402_A2A_EXTENSION_URI,\n description: \"Supports payments using the t402 protocol for on-chain settlement.\",\n required,\n };\n}\n","/**\n * Up-To Scheme Types\n *\n * The `upto` scheme authorizes transfer of up to a maximum amount,\n * enabling usage-based billing where the final settlement amount\n * is determined by actual usage.\n *\n * @example\n * ```typescript\n * // Client authorizes up to $1.00\n * const requirements: UptoPaymentRequirements = {\n * scheme: 'upto',\n * network: 'eip155:8453',\n * maxAmount: '1000000', // $1.00 in USDC\n * minAmount: '10000', // $0.01 minimum\n * asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',\n * payTo: '0x...',\n * maxTimeoutSeconds: 300,\n * extra: {\n * unit: 'token',\n * unitPrice: '100',\n * },\n * };\n *\n * // Server settles for actual usage ($0.15)\n * const settlement: UptoSettlement = {\n * settleAmount: '150000',\n * usageDetails: {\n * tokensGenerated: 1500,\n * unitPrice: '100',\n * },\n * };\n * ```\n */\n\nimport type { Network, PaymentRequirements } from \"../\";\n\n/**\n * Extended payment requirements for the upto scheme.\n */\nexport interface UptoPaymentRequirements extends Omit<PaymentRequirements, \"scheme\" | \"amount\"> {\n /** Scheme identifier - always 'upto' */\n scheme: \"upto\";\n\n /** Network identifier (CAIP-2 format) */\n network: Network;\n\n /** Maximum amount the client authorizes (in smallest denomination) */\n maxAmount: string;\n\n /** Minimum settlement amount (prevents dust payments) */\n minAmount?: string;\n\n /** Asset contract address or identifier */\n asset: string;\n\n /** Recipient address */\n payTo: string;\n\n /** Maximum time in seconds before payment expires */\n maxTimeoutSeconds: number;\n\n /** Additional scheme-specific data */\n extra: UptoExtra;\n}\n\n/**\n * Extra fields specific to the upto scheme.\n */\nexport interface UptoExtra extends Record<string, unknown> {\n /** Billing unit (e.g., 'token', 'request', 'second', 'byte') */\n unit?: string;\n\n /** Price per unit in smallest denomination */\n unitPrice?: string;\n\n /** EIP-712 domain name (for EVM) */\n name?: string;\n\n /** EIP-712 domain version (for EVM) */\n version?: string;\n\n /** Router contract address (for EVM) */\n routerAddress?: string;\n}\n\n/**\n * Base payload structure for upto scheme.\n */\nexport interface UptoPayloadBase {\n /** Unique nonce to prevent replay attacks */\n nonce: string;\n}\n\n/**\n * EVM-specific upto payload using EIP-2612 Permit.\n */\nexport interface UptoEvmPayload extends UptoPayloadBase {\n /** EIP-2612 permit signature components */\n signature: {\n v: number;\n r: `0x${string}`;\n s: `0x${string}`;\n };\n\n /** Permit authorization parameters */\n authorization: {\n /** Token owner address */\n owner: `0x${string}`;\n\n /** Spender address (router contract) */\n spender: `0x${string}`;\n\n /** Maximum authorized value */\n value: string;\n\n /** Permit deadline (unix timestamp) */\n deadline: string;\n\n /** Permit nonce (from token contract) */\n nonce: number;\n };\n}\n\n/**\n * Alternative EVM payload with combined signature.\n */\nexport interface UptoEvmPayloadCompact extends UptoPayloadBase {\n /** Combined EIP-2612 permit signature */\n signature: `0x${string}`;\n\n /** Permit authorization parameters */\n authorization: {\n owner: `0x${string}`;\n spender: `0x${string}`;\n value: string;\n deadline: string;\n nonce: number;\n };\n}\n\n/**\n * Settlement request for upto scheme.\n */\nexport interface UptoSettlement {\n /** Actual amount to settle (must be <= maxAmount) */\n settleAmount: string;\n\n /** Optional usage details for auditing */\n usageDetails?: UptoUsageDetails;\n}\n\n/**\n * Usage details for settlement auditing.\n */\nexport interface UptoUsageDetails {\n /** Number of units consumed */\n unitsConsumed?: number;\n\n /** Price per unit used */\n unitPrice?: string;\n\n /** Type of unit */\n unitType?: string;\n\n /** Start timestamp of usage period */\n startTime?: number;\n\n /** End timestamp of usage period */\n endTime?: number;\n\n /** Additional metadata */\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Settlement response for upto scheme.\n */\nexport interface UptoSettlementResponse {\n /** Whether settlement was successful */\n success: boolean;\n\n /** Transaction hash (if on-chain) */\n transactionHash?: string;\n\n /** Actual amount settled */\n settledAmount: string;\n\n /** Maximum amount that was authorized */\n maxAmount: string;\n\n /** Block number (if on-chain) */\n blockNumber?: number;\n\n /** Gas used (if on-chain) */\n gasUsed?: string;\n\n /** Error message if failed */\n error?: string;\n}\n\n/**\n * Validation result for upto payment.\n */\nexport interface UptoValidationResult {\n /** Whether the payment is valid */\n isValid: boolean;\n\n /** Reason if invalid */\n invalidReason?: string;\n\n /** Validated maximum amount */\n validatedMaxAmount?: string;\n\n /** Payer address */\n payer?: string;\n\n /** Expiration timestamp */\n expiresAt?: number;\n}\n\n/**\n * Type guard for UptoPaymentRequirements.\n *\n * @param requirements - The value to check\n * @returns True if the value is UptoPaymentRequirements\n */\nexport function isUptoPaymentRequirements(\n requirements: unknown,\n): requirements is UptoPaymentRequirements {\n if (typeof requirements !== \"object\" || requirements === null) return false;\n const req = requirements as Record<string, unknown>;\n return req.scheme === \"upto\" && \"maxAmount\" in req;\n}\n\n/**\n * Type guard for UptoEvmPayload.\n *\n * @param payload - The value to check\n * @returns True if the value is UptoEvmPayload\n */\nexport function isUptoEvmPayload(payload: unknown): payload is UptoEvmPayload {\n if (typeof payload !== \"object\" || payload === null) return false;\n const p = payload as Record<string, unknown>;\n return (\n \"signature\" in p &&\n \"authorization\" in p &&\n typeof p.authorization === \"object\" &&\n p.authorization !== null &&\n \"owner\" in (p.authorization as Record<string, unknown>) &&\n \"spender\" in (p.authorization as Record<string, unknown>) &&\n \"value\" in (p.authorization as Record<string, unknown>) &&\n \"deadline\" in (p.authorization as Record<string, unknown>)\n );\n}\n\n/**\n * Constants for upto scheme.\n */\nexport const UPTO_SCHEME = \"upto\" as const;\n\nexport const UPTO_DEFAULTS = {\n /** Default minimum settlement amount (prevents dust) */\n MIN_AMOUNT: \"1000\",\n\n /** Default maximum timeout in seconds (5 minutes) */\n MAX_TIMEOUT_SECONDS: 300,\n\n /** Supported billing units */\n UNITS: [\"token\", \"request\", \"second\", \"minute\", \"byte\", \"kb\", \"mb\"] as const,\n} as const;\n\nexport type UptoUnit = (typeof UPTO_DEFAULTS.UNITS)[number];\n","/**\n * Standardized T402 error codes returned by the facilitator API.\n * Error codes follow the format T402-XYYY where X is the category (1-8)\n * and YYY is the specific error within that category.\n */\n\n// Client Errors (T402-1xxx): Invalid input, malformed requests\nexport const ERR_INVALID_REQUEST = \"T402-1001\" as const;\nexport const ERR_MISSING_PAYLOAD = \"T402-1002\" as const;\nexport const ERR_MISSING_REQUIREMENTS = \"T402-1003\" as const;\nexport const ERR_INVALID_PAYLOAD = \"T402-1004\" as const;\nexport const ERR_INVALID_REQUIREMENTS = \"T402-1005\" as const;\nexport const ERR_INVALID_SIGNATURE = \"T402-1006\" as const;\nexport const ERR_INVALID_NETWORK = \"T402-1007\" as const;\nexport const ERR_INVALID_SCHEME = \"T402-1008\" as const;\nexport const ERR_INVALID_AMOUNT = \"T402-1009\" as const;\nexport const ERR_INVALID_ADDRESS = \"T402-1010\" as const;\nexport const ERR_EXPIRED_PAYMENT = \"T402-1011\" as const;\nexport const ERR_INVALID_NONCE = \"T402-1012\" as const;\nexport const ERR_INSUFFICIENT_AMOUNT = \"T402-1013\" as const;\nexport const ERR_INVALID_IDEMPOTENCY_KEY = \"T402-1014\" as const;\nexport const ERR_SIGNATURE_EXPIRED = \"T402-1015\" as const;\n\n// Server Errors (T402-2xxx): Internal failures, dependency issues\nexport const ERR_INTERNAL = \"T402-2001\" as const;\nexport const ERR_DATABASE_UNAVAILABLE = \"T402-2002\" as const;\nexport const ERR_CACHE_UNAVAILABLE = \"T402-2003\" as const;\nexport const ERR_RPC_UNAVAILABLE = \"T402-2004\" as const;\nexport const ERR_RATE_LIMITED = \"T402-2005\" as const;\nexport const ERR_SERVICE_UNAVAILABLE = \"T402-2006\" as const;\n\n// Facilitator Errors (T402-3xxx): Verification and settlement failures\nexport const ERR_VERIFICATION_FAILED = \"T402-3001\" as const;\nexport const ERR_SETTLEMENT_FAILED = \"T402-3002\" as const;\nexport const ERR_INSUFFICIENT_BALANCE = \"T402-3003\" as const;\nexport const ERR_ALLOWANCE_INSUFFICIENT = \"T402-3004\" as const;\nexport const ERR_PAYMENT_MISMATCH = \"T402-3005\" as const;\nexport const ERR_DUPLICATE_PAYMENT = \"T402-3006\" as const;\nexport const ERR_SETTLEMENT_PENDING = \"T402-3007\" as const;\nexport const ERR_SETTLEMENT_TIMEOUT = \"T402-3008\" as const;\nexport const ERR_NONCE_REPLAY = \"T402-3009\" as const;\nexport const ERR_IDEMPOTENCY_CONFLICT = \"T402-3010\" as const;\nexport const ERR_IDEMPOTENCY_UNAVAILABLE = \"T402-3011\" as const;\nexport const ERR_PREVIOUS_REQUEST_FAILED = \"T402-3012\" as const;\nexport const ERR_REQUEST_IN_PROGRESS = \"T402-3013\" as const;\n\n// Chain-Specific Errors (T402-4xxx): Network and transaction issues\nexport const ERR_CHAIN_UNAVAILABLE = \"T402-4001\" as const;\nexport const ERR_TRANSACTION_FAILED = \"T402-4002\" as const;\nexport const ERR_TRANSACTION_REVERTED = \"T402-4003\" as const;\nexport const ERR_GAS_ESTIMATION_FAILED = \"T402-4004\" as const;\nexport const ERR_NONCE_CONFLICT = \"T402-4005\" as const;\nexport const ERR_CHAIN_CONGESTED = \"T402-4006\" as const;\nexport const ERR_CONTRACT_ERROR = \"T402-4007\" as const;\n\n// Bridge Errors (T402-5xxx): Cross-chain operation failures\nexport const ERR_BRIDGE_UNAVAILABLE = \"T402-5001\" as const;\nexport const ERR_BRIDGE_QUOTE_FAILED = \"T402-5002\" as const;\nexport const ERR_BRIDGE_TRANSFER_FAILED = \"T402-5003\" as const;\nexport const ERR_BRIDGE_TIMEOUT = \"T402-5004\" as const;\nexport const ERR_UNSUPPORTED_ROUTE = \"T402-5005\" as const;\n\n// Streaming Errors (T402-6xxx): Payment stream issues\nexport const ERR_STREAM_NOT_FOUND = \"T402-6001\" as const;\nexport const ERR_STREAM_ALREADY_CLOSED = \"T402-6002\" as const;\nexport const ERR_STREAM_ALREADY_PAUSED = \"T402-6003\" as const;\nexport const ERR_STREAM_NOT_PAUSED = \"T402-6004\" as const;\nexport const ERR_STREAM_AMOUNT_EXCEEDED = \"T402-6005\" as const;\nexport const ERR_STREAM_EXPIRED = \"T402-6006\" as const;\nexport const ERR_STREAM_INVALID_STATE = \"T402-6007\" as const;\nexport const ERR_STREAM_RATE_LIMITED = \"T402-6008\" as const;\n\n// Intent Errors (T402-7xxx): Payment intent issues\nexport const ERR_INTENT_NOT_FOUND = \"T402-7001\" as const;\nexport const ERR_INTENT_ALREADY_EXECUTED = \"T402-7002\" as const;\nexport const ERR_INTENT_CANCELLED = \"T402-7003\" as const;\nexport const ERR_INTENT_EXPIRED = \"T402-7004\" as const;\nexport const ERR_NO_ROUTES_AVAILABLE = \"T402-7005\" as const;\nexport const ERR_ROUTE_EXPIRED = \"T402-7006\" as const;\nexport const ERR_ROUTE_NOT_SELECTED = \"T402-7007\" as const;\nexport const ERR_INTENT_INVALID_STATE = \"T402-7008\" as const;\n\n// Discovery Errors (T402-8xxx): Resource marketplace issues\nexport const ERR_RESOURCE_NOT_FOUND = \"T402-8001\" as const;\nexport const ERR_RESOURCE_ALREADY_EXISTS = \"T402-8002\" as const;\nexport const ERR_INVALID_PARAMETERS = \"T402-8003\" as const;\nexport const ERR_NOT_AUTHORIZED = \"T402-8004\" as const;\n\n/** Union type of all T402 error codes */\nexport type ErrorCode =\n | typeof ERR_INVALID_REQUEST | typeof ERR_MISSING_PAYLOAD | typeof ERR_MISSING_REQUIREMENTS\n | typeof ERR_INVALID_PAYLOAD | typeof ERR_INVALID_REQUIREMENTS | typeof ERR_INVALID_SIGNATURE\n | typeof ERR_INVALID_NETWORK | typeof ERR_INVALID_SCHEME | typeof ERR_INVALID_AMOUNT\n | typeof ERR_INVALID_ADDRESS | typeof ERR_EXPIRED_PAYMENT | typeof ERR_INVALID_NONCE\n | typeof ERR_INSUFFICIENT_AMOUNT | typeof ERR_INVALID_IDEMPOTENCY_KEY | typeof ERR_SIGNATURE_EXPIRED\n | typeof ERR_INTERNAL | typeof ERR_DATABASE_UNAVAILABLE | typeof ERR_CACHE_UNAVAILABLE\n | typeof ERR_RPC_UNAVAILABLE | typeof ERR_RATE_LIMITED | typeof ERR_SERVICE_UNAVAILABLE\n | typeof ERR_VERIFICATION_FAILED | typeof ERR_SETTLEMENT_FAILED | typeof ERR_INSUFFICIENT_BALANCE\n | typeof ERR_ALLOWANCE_INSUFFICIENT | typeof ERR_PAYMENT_MISMATCH | typeof ERR_DUPLICATE_PAYMENT\n | typeof ERR_SETTLEMENT_PENDING | typeof ERR_SETTLEMENT_TIMEOUT | typeof ERR_NONCE_REPLAY\n | typeof ERR_IDEMPOTENCY_CONFLICT | typeof ERR_IDEMPOTENCY_UNAVAILABLE\n | typeof ERR_PREVIOUS_REQUEST_FAILED | typeof ERR_REQUEST_IN_PROGRESS\n | typeof ERR_CHAIN_UNAVAILABLE | typeof ERR_TRANSACTION_FAILED | typeof ERR_TRANSACTION_REVERTED\n | typeof ERR_GAS_ESTIMATION_FAILED | typeof ERR_NONCE_CONFLICT | typeof ERR_CHAIN_CONGESTED\n | typeof ERR_CONTRACT_ERROR\n | typeof ERR_BRIDGE_UNAVAILABLE | typeof ERR_BRIDGE_QUOTE_FAILED | typeof ERR_BRIDGE_TRANSFER_FAILED\n | typeof ERR_BRIDGE_TIMEOUT | typeof ERR_UNSUPPORTED_ROUTE\n | typeof ERR_STREAM_NOT_FOUND | typeof ERR_STREAM_ALREADY_CLOSED | typeof ERR_STREAM_ALREADY_PAUSED\n | typeof ERR_STREAM_NOT_PAUSED | typeof ERR_STREAM_AMOUNT_EXCEEDED | typeof ERR_STREAM_EXPIRED\n | typeof ERR_STREAM_INVALID_STATE | typeof ERR_STREAM_RATE_LIMITED\n | typeof ERR_INTENT_NOT_FOUND | typeof ERR_INTENT_ALREADY_EXECUTED | typeof ERR_INTENT_CANCELLED\n | typeof ERR_INTENT_EXPIRED | typeof ERR_NO_ROUTES_AVAILABLE | typeof ERR_ROUTE_EXPIRED\n | typeof ERR_ROUTE_NOT_SELECTED | typeof ERR_INTENT_INVALID_STATE\n | typeof ERR_RESOURCE_NOT_FOUND | typeof ERR_RESOURCE_ALREADY_EXISTS\n | typeof ERR_INVALID_PARAMETERS | typeof ERR_NOT_AUTHORIZED;\n\n/** Structured error response from the facilitator API */\nexport interface APIError {\n code: ErrorCode;\n message: string;\n details?: string;\n retry?: boolean;\n}\n\n/** Returns the HTTP status code for a given error code */\nexport function httpStatusForCode(code: ErrorCode): number {\n const category = code.charAt(5);\n switch (category) {\n case \"1\":\n return 400;\n case \"2\":\n if (code === ERR_RATE_LIMITED) return 429;\n return 500;\n case \"3\":\n if (code === ERR_VERIFICATION_FAILED || code === ERR_PAYMENT_MISMATCH) return 422;\n return 500;\n case \"4\":\n return 502;\n case \"5\":\n return 502;\n case \"6\":\n if (code === ERR_STREAM_NOT_FOUND) return 404;\n return 400;\n case \"7\":\n if (code === ERR_INTENT_NOT_FOUND) return 404;\n return 400;\n case \"8\":\n if (code === ERR_RESOURCE_NOT_FOUND) return 404;\n if (code === ERR_RESOURCE_ALREADY_EXISTS) return 409;\n if (code === ERR_NOT_AUTHORIZED) return 403;\n return 400;\n default:\n return 500;\n }\n}\n\n/** Returns true if the error code is a client error (T402-1xxx) */\nexport function isClientError(code: ErrorCode): boolean {\n return code.charAt(5) === \"1\";\n}\n\n/** Returns true if the error code is a server error (T402-2xxx) */\nexport function isServerError(code: ErrorCode): boolean {\n return code.charAt(5) === \"2\";\n}\n\n/** Returns true if the error code is a facilitator error (T402-3xxx) */\nexport function isFacilitatorError(code: ErrorCode): boolean {\n return code.charAt(5) === \"3\";\n}\n\n/** Returns true if the error code is a chain error (T402-4xxx) */\nexport function isChainError(code: ErrorCode): boolean {\n return code.charAt(5) === \"4\";\n}\n\n/** Returns true if the error code is a bridge error (T402-5xxx) */\nexport function isBridgeError(code: ErrorCode): boolean {\n return code.charAt(5) === \"5\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkPO,IAAM,yBAAyB;AAK/B,IAAM,wBAAwB;AAS9B,SAAS,kBAAkB,MAAwB;AACxD,SACE,KAAK,OAAO,U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B,SAAS,qBAAsB,QAAO;AAC9E,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,UAAI,SAAS,qBAAsB,QAAO;AAC1C,aAAO;AAAA,IACT,KAAK;AACH,UAAI,SAAS,qBAAsB,QAAO;AAC1C,aAAO;AAAA,IACT,KAAK;AACH,UAAI,SAAS,uBAAwB,QAAO;AAC5C,UAAI,SAAS,4BAA6B,QAAO;AACjD,UAAI,SAAS,mBAAoB,QAAO;AACxC,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAGO,SAAS,cAAc,MAA0B;AACtD,SAAO,KAAK,OAAO,CAAC,MAAM;AAC5B;AAGO,SAAS,cAAc,MAA0B;AACtD,SAAO,KAAK,OAAO,CAAC,MAAM;AAC5B;AAGO,SAAS,mBAAmB,MAA0B;AAC3D,SAAO,KAAK,OAAO,CAAC,MAAM;AAC5B;AAGO,SAAS,aAAa,MAA0B;AACrD,SAAO,KAAK,OAAO,CAAC,MAAM;AAC5B;AAGO,SAAS,cAAc,MAA0B;AACtD,SAAO,KAAK,OAAO,CAAC,MAAM;AAC5B;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/types/a2a.ts","../../../src/types/schemes/upto.ts","../../../src/types/errors.ts"],"sourcesContent":["/**\n * A2A (Agent-to-Agent) Transport Types\n *\n * Implements t402 payment flows over the Agent-to-Agent protocol\n * using JSON-RPC messages and task-based state management.\n *\n * @see https://github.com/google-a2a/a2a-t402/v0.1\n */\n\nimport type { PaymentPayload, PaymentRequired } from \"./payments\";\nimport type { SettleResponse } from \"./facilitator\";\n\n// ============================================================================\n// A2A Payment Status\n// ============================================================================\n\n/**\n * Payment status values used in A2A metadata\n */\nexport type A2APaymentStatus =\n | \"payment-required\" // Payment requirements sent to client\n | \"payment-rejected\" // Client rejected payment requirements\n | \"payment-submitted\" // Payment payload received by server\n | \"payment-verified\" // Payment payload verified by server\n | \"payment-completed\" // Payment settled on-chain successfully\n | \"payment-failed\"; // Payment verification or settlement failed\n\n/**\n * A2A task states that correspond to payment states\n */\nexport type A2ATaskState =\n | \"submitted\"\n | \"working\"\n | \"input-required\"\n | \"completed\"\n | \"canceled\"\n | \"failed\"\n | \"unknown\";\n\n// ============================================================================\n// A2A Message Types\n// ============================================================================\n\n/**\n * A2A message part - text content\n */\nexport interface A2ATextPart {\n kind: \"text\";\n text: string;\n}\n\n/**\n * A2A message part - file content\n */\nexport interface A2AFilePart {\n kind: \"file\";\n file: {\n name?: string;\n mimeType?: string;\n bytes?: string; // base64 encoded\n uri?: string;\n };\n}\n\n/**\n * A2A message part - data content\n */\nexport interface A2ADataPart {\n kind: \"data\";\n data: Record<string, unknown>;\n}\n\nexport type A2AMessagePart = A2ATextPart | A2AFilePart | A2ADataPart;\n\n/**\n * A2A payment metadata fields\n */\nexport interface A2APaymentMetadata {\n /** Current payment status */\n \"t402.payment.status\"?: A2APaymentStatus;\n\n /** Payment requirements (when status is payment-required) */\n \"t402.payment.required\"?: PaymentRequired;\n\n /** Payment payload (when status is payment-submitted) */\n \"t402.payment.payload\"?: PaymentPayload;\n\n /** Settlement receipts (when status is payment-completed or payment-failed) */\n \"t402.payment.receipts\"?: SettleResponse[];\n\n /** Error code (when status is payment-failed) */\n \"t402.payment.error\"?: string;\n}\n\n/**\n * A2A message with payment metadata\n */\nexport interface A2AMessage {\n kind: \"message\";\n messageId?: string;\n role: \"user\" | \"agent\";\n parts: A2AMessagePart[];\n metadata?: A2APaymentMetadata & Record<string, unknown>;\n}\n\n// ============================================================================\n// A2A Task Types\n// ============================================================================\n\n/**\n * A2A artifact (output from completed task)\n */\nexport interface A2AArtifact {\n kind: string;\n name?: string;\n mimeType?: string;\n data?: string; // base64 encoded\n uri?: string;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * A2A task status\n */\nexport interface A2ATaskStatus {\n state: A2ATaskState;\n message?: A2AMessage;\n timestamp?: string;\n}\n\n/**\n * A2A task\n */\nexport interface A2ATask {\n kind: \"task\";\n id: string;\n sessionId?: string;\n status: A2ATaskStatus;\n artifacts?: A2AArtifact[];\n history?: A2AMessage[];\n metadata?: Record<string, unknown>;\n}\n\n// ============================================================================\n// A2A JSON-RPC Types\n// ============================================================================\n\n/**\n * A2A JSON-RPC request\n */\nexport interface A2ARequest<T = unknown> {\n jsonrpc: \"2.0\";\n method: string;\n id: string | number;\n params?: T;\n}\n\n/**\n * A2A JSON-RPC response\n */\nexport interface A2AResponse<T = unknown> {\n jsonrpc: \"2.0\";\n id: string | number;\n result?: T;\n error?: A2AError;\n}\n\n/**\n * A2A JSON-RPC error\n */\nexport interface A2AError {\n code: number;\n message: string;\n data?: unknown;\n}\n\n// ============================================================================\n// A2A Extension Types\n// ============================================================================\n\n/**\n * A2A extension declaration\n */\nexport interface A2AExtension {\n uri: string;\n description?: string;\n required?: boolean;\n}\n\n/**\n * A2A agent capabilities\n */\nexport interface A2ACapabilities {\n streaming?: boolean;\n pushNotifications?: boolean;\n stateTransitionHistory?: boolean;\n extensions?: A2AExtension[];\n}\n\n/**\n * A2A agent card (service advertisement)\n */\nexport interface A2AAgentCard {\n name: string;\n description?: string;\n url: string;\n provider?: {\n organization?: string;\n url?: string;\n };\n version?: string;\n documentationUrl?: string;\n capabilities?: A2ACapabilities;\n authentication?: {\n schemes: string[];\n credentials?: string;\n };\n defaultInputModes?: string[];\n defaultOutputModes?: string[];\n skills?: A2ASkill[];\n}\n\n/**\n * A2A skill definition\n */\nexport interface A2ASkill {\n id: string;\n name: string;\n description?: string;\n tags?: string[];\n examples?: string[];\n inputModes?: string[];\n outputModes?: string[];\n}\n\n// ============================================================================\n// T402-A2A Constants\n// ============================================================================\n\n/**\n * T402 A2A extension URI\n */\nexport const T402_A2A_EXTENSION_URI = \"https://github.com/google-a2a/a2a-t402/v0.1\";\n\n/**\n * HTTP header for A2A extension activation\n */\nexport const A2A_EXTENSIONS_HEADER = \"X-A2A-Extensions\";\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n/**\n * Check if a task is in a payment-required state\n *\n * @param task - The A2A task to check\n * @returns Whether the task requires payment\n */\nexport function isPaymentRequired(task: A2ATask): boolean {\n return (\n task.status.state === \"input-required\" &&\n task.status.message?.metadata?.[\"t402.payment.status\"] === \"payment-required\"\n );\n}\n\n/**\n * Check if a task has completed payment\n *\n * @param task - The A2A task to check\n * @returns Whether the task has completed payment\n */\nexport function isPaymentCompleted(task: A2ATask): boolean {\n return (\n task.status.state === \"completed\" &&\n task.status.message?.metadata?.[\"t402.payment.status\"] === \"payment-completed\"\n );\n}\n\n/**\n * Check if a task has failed payment\n *\n * @param task - The A2A task to check\n * @returns Whether the task has failed payment\n */\nexport function isPaymentFailed(task: A2ATask): boolean {\n return (\n task.status.state === \"failed\" &&\n task.status.message?.metadata?.[\"t402.payment.status\"] === \"payment-failed\"\n );\n}\n\n/**\n * Extract payment requirements from a task\n *\n * @param task - The A2A task to extract requirements from\n * @returns The payment requirements if the task requires payment\n */\nexport function getPaymentRequired(task: A2ATask): PaymentRequired | undefined {\n if (isPaymentRequired(task)) {\n return task.status.message?.metadata?.[\"t402.payment.required\"];\n }\n return undefined;\n}\n\n/**\n * Extract payment receipts from a task\n *\n * @param task - The A2A task to extract receipts from\n * @returns The settlement receipts if available\n */\nexport function getPaymentReceipts(task: A2ATask): SettleResponse[] | undefined {\n return task.status.message?.metadata?.[\"t402.payment.receipts\"];\n}\n\n/**\n * Create a payment-required message\n *\n * @param paymentRequired - The payment requirements\n * @param text - Optional message text\n * @returns An A2A message with payment-required metadata\n */\nexport function createPaymentRequiredMessage(\n paymentRequired: PaymentRequired,\n text: string = \"Payment is required to complete this request.\",\n): A2AMessage {\n return {\n kind: \"message\",\n role: \"agent\",\n parts: [{ kind: \"text\", text }],\n metadata: {\n \"t402.payment.status\": \"payment-required\",\n \"t402.payment.required\": paymentRequired,\n },\n };\n}\n\n/**\n * Create a payment submission message\n *\n * @param paymentPayload - The payment payload to submit\n * @param text - Optional message text\n * @returns An A2A message with payment-submitted metadata\n */\nexport function createPaymentSubmissionMessage(\n paymentPayload: PaymentPayload,\n text: string = \"Here is the payment authorization.\",\n): A2AMessage {\n return {\n kind: \"message\",\n role: \"user\",\n parts: [{ kind: \"text\", text }],\n metadata: {\n \"t402.payment.status\": \"payment-submitted\",\n \"t402.payment.payload\": paymentPayload,\n },\n };\n}\n\n/**\n * Create a payment completed message\n *\n * @param receipts - The settlement receipts\n * @param text - Optional message text\n * @returns An A2A message with payment-completed metadata\n */\nexport function createPaymentCompletedMessage(\n receipts: SettleResponse[],\n text: string = \"Payment successful.\",\n): A2AMessage {\n return {\n kind: \"message\",\n role: \"agent\",\n parts: [{ kind: \"text\", text }],\n metadata: {\n \"t402.payment.status\": \"payment-completed\",\n \"t402.payment.receipts\": receipts,\n },\n };\n}\n\n/**\n * Create a payment failed message\n *\n * @param receipts - The settlement receipts\n * @param errorCode - The error code\n * @param text - Optional message text\n * @returns An A2A message with payment-failed metadata\n */\nexport function createPaymentFailedMessage(\n receipts: SettleResponse[],\n errorCode: string,\n text: string = \"Payment failed.\",\n): A2AMessage {\n return {\n kind: \"message\",\n role: \"agent\",\n parts: [{ kind: \"text\", text }],\n metadata: {\n \"t402.payment.status\": \"payment-failed\",\n \"t402.payment.error\": errorCode,\n \"t402.payment.receipts\": receipts,\n },\n };\n}\n\n/**\n * Create a T402 extension declaration for agent cards\n *\n * @param required - Whether the extension is required\n * @returns An A2A extension declaration\n */\nexport function createT402Extension(required: boolean = false): A2AExtension {\n return {\n uri: T402_A2A_EXTENSION_URI,\n description: \"Supports payments using the t402 protocol for on-chain settlement.\",\n required,\n };\n}\n","/**\n * Up-To Scheme Types\n *\n * The `upto` scheme authorizes transfer of up to a maximum amount,\n * enabling usage-based billing where the final settlement amount\n * is determined by actual usage.\n *\n * @example\n * ```typescript\n * // Client authorizes up to $1.00\n * const requirements: UptoPaymentRequirements = {\n * scheme: 'upto',\n * network: 'eip155:8453',\n * maxAmount: '1000000', // $1.00 in USDC\n * minAmount: '10000', // $0.01 minimum\n * asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',\n * payTo: '0x...',\n * maxTimeoutSeconds: 300,\n * extra: {\n * unit: 'token',\n * unitPrice: '100',\n * },\n * };\n *\n * // Server settles for actual usage ($0.15)\n * const settlement: UptoSettlement = {\n * settleAmount: '150000',\n * usageDetails: {\n * tokensGenerated: 1500,\n * unitPrice: '100',\n * },\n * };\n * ```\n */\n\nimport type { Network, PaymentRequirements } from \"../\";\n\n/**\n * Extended payment requirements for the upto scheme.\n */\nexport interface UptoPaymentRequirements extends Omit<PaymentRequirements, \"scheme\" | \"amount\"> {\n /** Scheme identifier - always 'upto' */\n scheme: \"upto\";\n\n /** Network identifier (CAIP-2 format) */\n network: Network;\n\n /** Maximum amount the client authorizes (in smallest denomination) */\n maxAmount: string;\n\n /** Minimum settlement amount (prevents dust payments) */\n minAmount?: string;\n\n /** Asset contract address or identifier */\n asset: string;\n\n /** Recipient address */\n payTo: string;\n\n /** Maximum time in seconds before payment expires */\n maxTimeoutSeconds: number;\n\n /** Additional scheme-specific data */\n extra: UptoExtra;\n}\n\n/**\n * Extra fields specific to the upto scheme.\n */\nexport interface UptoExtra extends Record<string, unknown> {\n /** Billing unit (e.g., 'token', 'request', 'second', 'byte') */\n unit?: string;\n\n /** Price per unit in smallest denomination */\n unitPrice?: string;\n\n /** EIP-712 domain name (for EVM) */\n name?: string;\n\n /** EIP-712 domain version (for EVM) */\n version?: string;\n\n /** Router contract address (for EVM) */\n routerAddress?: string;\n}\n\n/**\n * Base payload structure for upto scheme.\n */\nexport interface UptoPayloadBase {\n /** Unique nonce to prevent replay attacks */\n nonce: string;\n}\n\n/**\n * EVM-specific upto payload using EIP-2612 Permit.\n */\nexport interface UptoEvmPayload extends UptoPayloadBase {\n /** EIP-2612 permit signature components */\n signature: {\n v: number;\n r: `0x${string}`;\n s: `0x${string}`;\n };\n\n /** Permit authorization parameters */\n authorization: {\n /** Token owner address */\n owner: `0x${string}`;\n\n /** Spender address (router contract) */\n spender: `0x${string}`;\n\n /** Maximum authorized value */\n value: string;\n\n /** Permit deadline (unix timestamp) */\n deadline: string;\n\n /** Permit nonce (from token contract) */\n nonce: number;\n };\n}\n\n/**\n * Alternative EVM payload with combined signature.\n */\nexport interface UptoEvmPayloadCompact extends UptoPayloadBase {\n /** Combined EIP-2612 permit signature */\n signature: `0x${string}`;\n\n /** Permit authorization parameters */\n authorization: {\n owner: `0x${string}`;\n spender: `0x${string}`;\n value: string;\n deadline: string;\n nonce: number;\n };\n}\n\n/**\n * Settlement request for upto scheme.\n */\nexport interface UptoSettlement {\n /** Actual amount to settle (must be <= maxAmount) */\n settleAmount: string;\n\n /** Optional usage details for auditing */\n usageDetails?: UptoUsageDetails;\n}\n\n/**\n * Usage details for settlement auditing.\n */\nexport interface UptoUsageDetails {\n /** Number of units consumed */\n unitsConsumed?: number;\n\n /** Price per unit used */\n unitPrice?: string;\n\n /** Type of unit */\n unitType?: string;\n\n /** Start timestamp of usage period */\n startTime?: number;\n\n /** End timestamp of usage period */\n endTime?: number;\n\n /** Additional metadata */\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Settlement response for upto scheme.\n */\nexport interface UptoSettlementResponse {\n /** Whether settlement was successful */\n success: boolean;\n\n /** Transaction hash (if on-chain) */\n transactionHash?: string;\n\n /** Actual amount settled */\n settledAmount: string;\n\n /** Maximum amount that was authorized */\n maxAmount: string;\n\n /** Block number (if on-chain) */\n blockNumber?: number;\n\n /** Gas used (if on-chain) */\n gasUsed?: string;\n\n /** Error message if failed */\n error?: string;\n}\n\n/**\n * Validation result for upto payment.\n */\nexport interface UptoValidationResult {\n /** Whether the payment is valid */\n isValid: boolean;\n\n /** Reason if invalid */\n invalidReason?: string;\n\n /** Validated maximum amount */\n validatedMaxAmount?: string;\n\n /** Payer address */\n payer?: string;\n\n /** Expiration timestamp */\n expiresAt?: number;\n}\n\n/**\n * Type guard for UptoPaymentRequirements.\n *\n * @param requirements - The value to check\n * @returns True if the value is UptoPaymentRequirements\n */\nexport function isUptoPaymentRequirements(\n requirements: unknown,\n): requirements is UptoPaymentRequirements {\n if (typeof requirements !== \"object\" || requirements === null) return false;\n const req = requirements as Record<string, unknown>;\n return req.scheme === \"upto\" && \"maxAmount\" in req;\n}\n\n/**\n * Type guard for UptoEvmPayload.\n *\n * @param payload - The value to check\n * @returns True if the value is UptoEvmPayload\n */\nexport function isUptoEvmPayload(payload: unknown): payload is UptoEvmPayload {\n if (typeof payload !== \"object\" || payload === null) return false;\n const p = payload as Record<string, unknown>;\n return (\n \"signature\" in p &&\n \"authorization\" in p &&\n typeof p.authorization === \"object\" &&\n p.authorization !== null &&\n \"owner\" in (p.authorization as Record<string, unknown>) &&\n \"spender\" in (p.authorization as Record<string, unknown>) &&\n \"value\" in (p.authorization as Record<string, unknown>) &&\n \"deadline\" in (p.authorization as Record<string, unknown>)\n );\n}\n\n/**\n * Constants for upto scheme.\n */\nexport const UPTO_SCHEME = \"upto\" as const;\n\nexport const UPTO_DEFAULTS = {\n /** Default minimum settlement amount (prevents dust) */\n MIN_AMOUNT: \"1000\",\n\n /** Default maximum timeout in seconds (5 minutes) */\n MAX_TIMEOUT_SECONDS: 300,\n\n /** Supported billing units */\n UNITS: [\"token\", \"request\", \"second\", \"minute\", \"byte\", \"kb\", \"mb\"] as const,\n} as const;\n\nexport type UptoUnit = (typeof UPTO_DEFAULTS.UNITS)[number];\n","/**\n * Standardized T402 error codes returned by the facilitator API.\n * Error codes follow the format T402-XYYY where X is the category (1-8)\n * and YYY is the specific error within that category.\n */\n\n// Client Errors (T402-1xxx): Invalid input, malformed requests\nexport const ERR_INVALID_REQUEST = \"T402-1001\" as const;\nexport const ERR_MISSING_PAYLOAD = \"T402-1002\" as const;\nexport const ERR_MISSING_REQUIREMENTS = \"T402-1003\" as const;\nexport const ERR_INVALID_PAYLOAD = \"T402-1004\" as const;\nexport const ERR_INVALID_REQUIREMENTS = \"T402-1005\" as const;\nexport const ERR_INVALID_SIGNATURE = \"T402-1006\" as const;\nexport const ERR_INVALID_NETWORK = \"T402-1007\" as const;\nexport const ERR_INVALID_SCHEME = \"T402-1008\" as const;\nexport const ERR_INVALID_AMOUNT = \"T402-1009\" as const;\nexport const ERR_INVALID_ADDRESS = \"T402-1010\" as const;\nexport const ERR_EXPIRED_PAYMENT = \"T402-1011\" as const;\nexport const ERR_INVALID_NONCE = \"T402-1012\" as const;\nexport const ERR_INSUFFICIENT_AMOUNT = \"T402-1013\" as const;\nexport const ERR_INVALID_IDEMPOTENCY_KEY = \"T402-1014\" as const;\nexport const ERR_SIGNATURE_EXPIRED = \"T402-1015\" as const;\n\n// Server Errors (T402-2xxx): Internal failures, dependency issues\nexport const ERR_INTERNAL = \"T402-2001\" as const;\nexport const ERR_DATABASE_UNAVAILABLE = \"T402-2002\" as const;\nexport const ERR_CACHE_UNAVAILABLE = \"T402-2003\" as const;\nexport const ERR_RPC_UNAVAILABLE = \"T402-2004\" as const;\nexport const ERR_RATE_LIMITED = \"T402-2005\" as const;\nexport const ERR_SERVICE_UNAVAILABLE = \"T402-2006\" as const;\n\n// Facilitator Errors (T402-3xxx): Verification and settlement failures\nexport const ERR_VERIFICATION_FAILED = \"T402-3001\" as const;\nexport const ERR_SETTLEMENT_FAILED = \"T402-3002\" as const;\nexport const ERR_INSUFFICIENT_BALANCE = \"T402-3003\" as const;\nexport const ERR_ALLOWANCE_INSUFFICIENT = \"T402-3004\" as const;\nexport const ERR_PAYMENT_MISMATCH = \"T402-3005\" as const;\nexport const ERR_DUPLICATE_PAYMENT = \"T402-3006\" as const;\nexport const ERR_SETTLEMENT_PENDING = \"T402-3007\" as const;\nexport const ERR_SETTLEMENT_TIMEOUT = \"T402-3008\" as const;\nexport const ERR_NONCE_REPLAY = \"T402-3009\" as const;\nexport const ERR_IDEMPOTENCY_CONFLICT = \"T402-3010\" as const;\nexport const ERR_IDEMPOTENCY_UNAVAILABLE = \"T402-3011\" as const;\nexport const ERR_PREVIOUS_REQUEST_FAILED = \"T402-3012\" as const;\nexport const ERR_REQUEST_IN_PROGRESS = \"T402-3013\" as const;\n\n// Chain-Specific Errors (T402-4xxx): Network and transaction issues\nexport const ERR_CHAIN_UNAVAILABLE = \"T402-4001\" as const;\nexport const ERR_TRANSACTION_FAILED = \"T402-4002\" as const;\nexport const ERR_TRANSACTION_REVERTED = \"T402-4003\" as const;\nexport const ERR_GAS_ESTIMATION_FAILED = \"T402-4004\" as const;\nexport const ERR_NONCE_CONFLICT = \"T402-4005\" as const;\nexport const ERR_CHAIN_CONGESTED = \"T402-4006\" as const;\nexport const ERR_CONTRACT_ERROR = \"T402-4007\" as const;\n\n// Bridge Errors (T402-5xxx): Cross-chain operation failures\nexport const ERR_BRIDGE_UNAVAILABLE = \"T402-5001\" as const;\nexport const ERR_BRIDGE_QUOTE_FAILED = \"T402-5002\" as const;\nexport const ERR_BRIDGE_TRANSFER_FAILED = \"T402-5003\" as const;\nexport const ERR_BRIDGE_TIMEOUT = \"T402-5004\" as const;\nexport const ERR_UNSUPPORTED_ROUTE = \"T402-5005\" as const;\n\n// Streaming Errors (T402-6xxx): Payment stream issues\nexport const ERR_STREAM_NOT_FOUND = \"T402-6001\" as const;\nexport const ERR_STREAM_ALREADY_CLOSED = \"T402-6002\" as const;\nexport const ERR_STREAM_ALREADY_PAUSED = \"T402-6003\" as const;\nexport const ERR_STREAM_NOT_PAUSED = \"T402-6004\" as const;\nexport const ERR_STREAM_AMOUNT_EXCEEDED = \"T402-6005\" as const;\nexport const ERR_STREAM_EXPIRED = \"T402-6006\" as const;\nexport const ERR_STREAM_INVALID_STATE = \"T402-6007\" as const;\nexport const ERR_STREAM_RATE_LIMITED = \"T402-6008\" as const;\n\n// Intent Errors (T402-7xxx): Payment intent issues\nexport const ERR_INTENT_NOT_FOUND = \"T402-7001\" as const;\nexport const ERR_INTENT_ALREADY_EXECUTED = \"T402-7002\" as const;\nexport const ERR_INTENT_CANCELLED = \"T402-7003\" as const;\nexport const ERR_INTENT_EXPIRED = \"T402-7004\" as const;\nexport const ERR_NO_ROUTES_AVAILABLE = \"T402-7005\" as const;\nexport const ERR_ROUTE_EXPIRED = \"T402-7006\" as const;\nexport const ERR_ROUTE_NOT_SELECTED = \"T402-7007\" as const;\nexport const ERR_INTENT_INVALID_STATE = \"T402-7008\" as const;\n\n// Discovery Errors (T402-8xxx): Resource marketplace issues\nexport const ERR_RESOURCE_NOT_FOUND = \"T402-8001\" as const;\nexport const ERR_RESOURCE_ALREADY_EXISTS = \"T402-8002\" as const;\nexport const ERR_INVALID_PARAMETERS = \"T402-8003\" as const;\nexport const ERR_NOT_AUTHORIZED = \"T402-8004\" as const;\n\n/** Union type of all T402 error codes */\nexport type ErrorCode =\n | typeof ERR_INVALID_REQUEST\n | typeof ERR_MISSING_PAYLOAD\n | typeof ERR_MISSING_REQUIREMENTS\n | typeof ERR_INVALID_PAYLOAD\n | typeof ERR_INVALID_REQUIREMENTS\n | typeof ERR_INVALID_SIGNATURE\n | typeof ERR_INVALID_NETWORK\n | typeof ERR_INVALID_SCHEME\n | typeof ERR_INVALID_AMOUNT\n | typeof ERR_INVALID_ADDRESS\n | typeof ERR_EXPIRED_PAYMENT\n | typeof ERR_INVALID_NONCE\n | typeof ERR_INSUFFICIENT_AMOUNT\n | typeof ERR_INVALID_IDEMPOTENCY_KEY\n | typeof ERR_SIGNATURE_EXPIRED\n | typeof ERR_INTERNAL\n | typeof ERR_DATABASE_UNAVAILABLE\n | typeof ERR_CACHE_UNAVAILABLE\n | typeof ERR_RPC_UNAVAILABLE\n | typeof ERR_RATE_LIMITED\n | typeof ERR_SERVICE_UNAVAILABLE\n | typeof ERR_VERIFICATION_FAILED\n | typeof ERR_SETTLEMENT_FAILED\n | typeof ERR_INSUFFICIENT_BALANCE\n | typeof ERR_ALLOWANCE_INSUFFICIENT\n | typeof ERR_PAYMENT_MISMATCH\n | typeof ERR_DUPLICATE_PAYMENT\n | typeof ERR_SETTLEMENT_PENDING\n | typeof ERR_SETTLEMENT_TIMEOUT\n | typeof ERR_NONCE_REPLAY\n | typeof ERR_IDEMPOTENCY_CONFLICT\n | typeof ERR_IDEMPOTENCY_UNAVAILABLE\n | typeof ERR_PREVIOUS_REQUEST_FAILED\n | typeof ERR_REQUEST_IN_PROGRESS\n | typeof ERR_CHAIN_UNAVAILABLE\n | typeof ERR_TRANSACTION_FAILED\n | typeof ERR_TRANSACTION_REVERTED\n | typeof ERR_GAS_ESTIMATION_FAILED\n | typeof ERR_NONCE_CONFLICT\n | typeof ERR_CHAIN_CONGESTED\n | typeof ERR_CONTRACT_ERROR\n | typeof ERR_BRIDGE_UNAVAILABLE\n | typeof ERR_BRIDGE_QUOTE_FAILED\n | typeof ERR_BRIDGE_TRANSFER_FAILED\n | typeof ERR_BRIDGE_TIMEOUT\n | typeof ERR_UNSUPPORTED_ROUTE\n | typeof ERR_STREAM_NOT_FOUND\n | typeof ERR_STREAM_ALREADY_CLOSED\n | typeof ERR_STREAM_ALREADY_PAUSED\n | typeof ERR_STREAM_NOT_PAUSED\n | typeof ERR_STREAM_AMOUNT_EXCEEDED\n | typeof ERR_STREAM_EXPIRED\n | typeof ERR_STREAM_INVALID_STATE\n | typeof ERR_STREAM_RATE_LIMITED\n | typeof ERR_INTENT_NOT_FOUND\n | typeof ERR_INTENT_ALREADY_EXECUTED\n | typeof ERR_INTENT_CANCELLED\n | typeof ERR_INTENT_EXPIRED\n | typeof ERR_NO_ROUTES_AVAILABLE\n | typeof ERR_ROUTE_EXPIRED\n | typeof ERR_ROUTE_NOT_SELECTED\n | typeof ERR_INTENT_INVALID_STATE\n | typeof ERR_RESOURCE_NOT_FOUND\n | typeof ERR_RESOURCE_ALREADY_EXISTS\n | typeof ERR_INVALID_PARAMETERS\n | typeof ERR_NOT_AUTHORIZED;\n\n/** Structured error response from the facilitator API */\nexport interface APIError {\n code: ErrorCode;\n message: string;\n details?: string;\n retry?: boolean;\n}\n\n/**\n * Returns the HTTP status code for a given error code\n *\n * @param code - The T402 error code\n * @returns The corresponding HTTP status code\n */\nexport function httpStatusForCode(code: ErrorCode): number {\n const category = code.charAt(5);\n switch (category) {\n case \"1\":\n return 400;\n case \"2\":\n if (code === ERR_RATE_LIMITED) return 429;\n return 500;\n case \"3\":\n if (code === ERR_VERIFICATION_FAILED || code === ERR_PAYMENT_MISMATCH) return 422;\n return 500;\n case \"4\":\n return 502;\n case \"5\":\n return 502;\n case \"6\":\n if (code === ERR_STREAM_NOT_FOUND) return 404;\n return 400;\n case \"7\":\n if (code === ERR_INTENT_NOT_FOUND) return 404;\n return 400;\n case \"8\":\n if (code === ERR_RESOURCE_NOT_FOUND) return 404;\n if (code === ERR_RESOURCE_ALREADY_EXISTS) return 409;\n if (code === ERR_NOT_AUTHORIZED) return 403;\n return 400;\n default:\n return 500;\n }\n}\n\n/**\n * Returns true if the error code is a client error (T402-1xxx)\n *\n * @param code - The T402 error code\n * @returns Whether the error is a client error\n */\nexport function isClientError(code: ErrorCode): boolean {\n return code.charAt(5) === \"1\";\n}\n\n/**\n * Returns true if the error code is a server error (T402-2xxx)\n *\n * @param code - The T402 error code\n * @returns Whether the error is a server error\n */\nexport function isServerError(code: ErrorCode): boolean {\n return code.charAt(5) === \"2\";\n}\n\n/**\n * Returns true if the error code is a facilitator error (T402-3xxx)\n *\n * @param code - The T402 error code\n * @returns Whether the error is a facilitator error\n */\nexport function isFacilitatorError(code: ErrorCode): boolean {\n return code.charAt(5) === \"3\";\n}\n\n/**\n * Returns true if the error code is a chain error (T402-4xxx)\n *\n * @param code - The T402 error code\n * @returns Whether the error is a chain error\n */\nexport function isChainError(code: ErrorCode): boolean {\n return code.charAt(5) === \"4\";\n}\n\n/**\n * Returns true if the error code is a bridge error (T402-5xxx)\n *\n * @param code - The T402 error code\n * @returns Whether the error is a bridge error\n */\nexport function isBridgeError(code: ErrorCode): boolean {\n return code.charAt(5) === \"5\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkPO,IAAM,yBAAyB;AAK/B,IAAM,wBAAwB;AAY9B,SAAS,kBAAkB,MAAwB;AACx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AAI,SAAS,2BAA2B,SAAS,qBAAsB,QAAO;AAC9E,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,UAAI,SAAS,qBAAsB,QAAO;AAC1C,aAAO;AAAA,IACT,KAAK;AACH,UAAI,SAAS,qBAAsB,QAAO;AAC1C,aAAO;AAAA,IACT,KAAK;AACH,UAAI,SAAS,uBAAwB,QAAO;AAC5C,UAAI,SAAS,4BAA6B,QAAO;AACjD,UAAI,SAAS,mBAAoB,QAAO;AACxC,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAQO,SAAS,cAAc,MAA0B;AACtD,SAAO,KAAK,OAAO,CAAC,MAAM;AAC5B;AAQO,SAAS,cAAc,MAA0B;AACtD,SAAO,KAAK,OAAO,CAAC,MAAM;AAC5B;AAQO,SAAS,mBAAmB,MAA0B;AAC3D,SAAO,KAAK,OAAO,CAAC,MAAM;AAC5B;AAQO,SAAS,aAAa,MAA0B;AACrD,SAAO,KAAK,OAAO,CAAC,MAAM;AAC5B;AAQO,SAAS,cAAc,MAA0B;AACtD,SAAO,KAAK,OAAO,CAAC,MAAM;AAC5B;","names":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { i as PaymentPayloadV1, j as PaymentRequiredV1, k as PaymentRequirementsV1, l as SettleRequestV1, m as SettleResponseV1, n as SupportedResponseV1, o as VerifyRequestV1 } from '../../mechanisms-dYCiYgko.mjs';
|
|
2
2
|
import 'zod';
|
package/package.json
CHANGED
|
@@ -1,30 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t402/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"main": "./dist/cjs/index.js",
|
|
5
5
|
"module": "./dist/esm/index.js",
|
|
6
6
|
"types": "./dist/cjs/index.d.ts",
|
|
7
|
-
"keywords": [
|
|
7
|
+
"keywords": [
|
|
8
|
+
"t402",
|
|
9
|
+
"payment",
|
|
10
|
+
"protocol",
|
|
11
|
+
"types",
|
|
12
|
+
"http-402",
|
|
13
|
+
"stablecoin",
|
|
14
|
+
"usdt"
|
|
15
|
+
],
|
|
8
16
|
"license": "Apache-2.0",
|
|
9
17
|
"author": "T402 Team",
|
|
10
|
-
"repository":
|
|
11
|
-
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/t402-io/t402.git",
|
|
21
|
+
"directory": "sdks/typescript/packages/core"
|
|
22
|
+
},
|
|
23
|
+
"description": "Core types, schemas, and constants for the T402 payment protocol",
|
|
12
24
|
"devDependencies": {
|
|
13
|
-
"@eslint/js": "^9.
|
|
14
|
-
"@types/node": "^25.2.
|
|
15
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
16
|
-
"@typescript-eslint/parser": "^8.
|
|
25
|
+
"@eslint/js": "^9.39.2",
|
|
26
|
+
"@types/node": "^25.2.3",
|
|
27
|
+
"@typescript-eslint/eslint-plugin": "^8.56.0",
|
|
28
|
+
"@typescript-eslint/parser": "^8.56.0",
|
|
17
29
|
"eslint": "^9.24.0",
|
|
18
30
|
"eslint-plugin-import": "^2.31.0",
|
|
19
|
-
"eslint-plugin-jsdoc": "^62.
|
|
20
|
-
"eslint-plugin-prettier": "^5.
|
|
21
|
-
"glob": "^13.0.
|
|
22
|
-
"prettier": "3.
|
|
23
|
-
"tsup": "^8.
|
|
31
|
+
"eslint-plugin-jsdoc": "^62.6.0",
|
|
32
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
33
|
+
"glob": "^13.0.5",
|
|
34
|
+
"prettier": "3.8.1",
|
|
35
|
+
"tsup": "^8.5.1",
|
|
24
36
|
"tsx": "^4.21.0",
|
|
25
|
-
"typescript": "^5.
|
|
37
|
+
"typescript": "^5.9.3",
|
|
26
38
|
"vite": "^7.3.1",
|
|
27
|
-
"vite-tsconfig-paths": "^
|
|
39
|
+
"vite-tsconfig-paths": "^6.1.1",
|
|
28
40
|
"vitest": "^3.2.4"
|
|
29
41
|
},
|
|
30
42
|
"dependencies": {
|
|
@@ -115,6 +127,10 @@
|
|
|
115
127
|
"files": [
|
|
116
128
|
"dist"
|
|
117
129
|
],
|
|
130
|
+
"homepage": "https://t402.io",
|
|
131
|
+
"publishConfig": {
|
|
132
|
+
"access": "public"
|
|
133
|
+
},
|
|
118
134
|
"scripts": {
|
|
119
135
|
"start": "tsx --env-file=.env index.ts",
|
|
120
136
|
"build": "tsup",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export const t402Version = 2;\n"],"mappings":";AAAO,IAAM,cAAc;","names":[]}
|