@wasit-dev/core 0.6.0 → 0.8.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +12 -4
  2. package/dist/baseline.d.ts +109 -0
  3. package/dist/baseline.js +351 -0
  4. package/dist/catalogue.d.ts +10 -0
  5. package/dist/catalogue.js +69 -3
  6. package/dist/check.d.ts +78 -2
  7. package/dist/check.js +69 -10
  8. package/dist/ci-report.d.ts +74 -0
  9. package/dist/ci-report.js +391 -0
  10. package/dist/config.d.ts +205 -0
  11. package/dist/config.js +1011 -0
  12. package/dist/denied-env.d.ts +33 -0
  13. package/dist/denied-env.js +86 -0
  14. package/dist/errors.d.ts +44 -1
  15. package/dist/errors.js +151 -2
  16. package/dist/guard/budget.d.ts +135 -0
  17. package/dist/guard/budget.js +199 -0
  18. package/dist/guard/ci-event.d.ts +50 -0
  19. package/dist/guard/ci-event.js +125 -0
  20. package/dist/guard/mainnet-optin.d.ts +58 -0
  21. package/dist/guard/mainnet-optin.js +95 -0
  22. package/dist/guard/networks.d.ts +50 -0
  23. package/dist/guard/networks.js +80 -0
  24. package/dist/guard/rpc-identity.d.ts +45 -0
  25. package/dist/guard/rpc-identity.js +156 -0
  26. package/dist/guard/rpc-in-use.d.ts +48 -0
  27. package/dist/guard/rpc-in-use.js +84 -0
  28. package/dist/index.d.ts +34 -3
  29. package/dist/index.js +31 -2
  30. package/dist/mpp/channel-commitment.d.ts +48 -2
  31. package/dist/mpp/channel-commitment.js +80 -4
  32. package/dist/mpp/channel-credential.js +3 -0
  33. package/dist/mpp/channel.js +29 -0
  34. package/dist/mpp/charge.d.ts +25 -2
  35. package/dist/mpp/charge.js +100 -8
  36. package/dist/mpp/network.js +4 -1
  37. package/dist/mpp/suite.js +10 -2
  38. package/dist/report.d.ts +163 -0
  39. package/dist/report.js +282 -0
  40. package/dist/sanitize.d.ts +52 -0
  41. package/dist/sanitize.js +106 -0
  42. package/dist/settlement.d.ts +14 -0
  43. package/dist/settlement.js +1 -1
  44. package/dist/verdict.d.ts +24 -0
  45. package/dist/verdict.js +46 -0
  46. package/dist/versions.d.ts +50 -0
  47. package/dist/versions.js +123 -0
  48. package/dist/x402/chains/evm.d.ts +65 -0
  49. package/dist/x402/chains/evm.js +237 -0
  50. package/dist/x402/chains/index.d.ts +18 -0
  51. package/dist/x402/chains/index.js +28 -0
  52. package/dist/x402/chains/stellar.d.ts +38 -0
  53. package/dist/x402/chains/stellar.js +277 -0
  54. package/dist/x402/chains/svm.d.ts +69 -0
  55. package/dist/x402/chains/svm.js +333 -0
  56. package/dist/x402/chains/types.d.ts +152 -0
  57. package/dist/x402/chains/types.js +10 -0
  58. package/dist/x402/chains/wait.d.ts +36 -0
  59. package/dist/x402/chains/wait.js +42 -0
  60. package/dist/x402/plan.d.ts +82 -0
  61. package/dist/x402/plan.js +146 -0
  62. package/dist/x402/rejected-request.d.ts +146 -0
  63. package/dist/x402/rejected-request.js +269 -0
  64. package/dist/x402/requirements.d.ts +46 -0
  65. package/dist/x402/requirements.js +359 -0
  66. package/dist/x402/simulator.d.ts +74 -17
  67. package/dist/x402/simulator.js +907 -246
  68. package/package.json +11 -6
@@ -1,4 +1,8 @@
1
1
  import { type CheckResult } from "../check.js";
2
+ import { ConfigurationError } from "../errors.js";
3
+ import { RunBudget, type PinTerms } from "../guard/budget.js";
4
+ import type { EndpointPlan } from "./plan.js";
5
+ import { type RejectCase } from "./rejected-request.js";
2
6
  export type { CheckResult };
3
7
  /**
4
8
  * How to address the target's paid endpoint.
@@ -43,6 +47,9 @@ export declare function readV1BodyChallenge(body: string): Record<string, unknow
43
47
  * be evaluated, so one broken challenge produces one finding.
44
48
  */
45
49
  export declare function runX402ReadChecks(options: X402SimulatorOptions): Promise<CheckResult[]>;
50
+ import type { PaymentRequirements } from "@x402/core/types";
51
+ import { type PaymentChain } from "./chains/index.js";
52
+ export { corruptAuthSignature } from "./chains/stellar.js";
46
53
  export interface X402PaymentCheckOptions extends RequestShape {
47
54
  readonly target: string;
48
55
  readonly network: string;
@@ -51,7 +58,53 @@ export interface X402PaymentCheckOptions extends RequestShape {
51
58
  readonly rpcUrl?: string;
52
59
  /** See {@link X402SimulatorOptions.onResult} — same contract. */
53
60
  readonly onResult?: (result: CheckResult) => void;
61
+ /**
62
+ * The run's budget, shared by every endpoint of one run. Without one, these
63
+ * checks get their own: $5, of which they sign at most 3.5 times a $1 price.
64
+ */
65
+ readonly budget?: RunBudget;
66
+ /** Every `exact` option on the run's network must pay this `payTo` in this asset. */
67
+ readonly pin?: PinTerms;
68
+ /** This endpoint's entry of the run's plan (L1): no signature beyond it. */
69
+ readonly plan?: EndpointPlan;
70
+ /** The request the service must refuse (`endpoints[].reject`), for X402-11. Absent: X402-11 is skipped. */
71
+ readonly reject?: RejectCase;
72
+ /**
73
+ * Called with one line when a check starts a long wait on the chain (X402-11
74
+ * waits up to six minutes), so a log does not look stuck. The line holds no
75
+ * text from the service.
76
+ */
77
+ readonly onProgress?: (line: string) => void;
54
78
  }
79
+ /**
80
+ * No payment adapter pays on this network, so the payment checks cannot be
81
+ * graded here. A `ConfigurationError`, so a caller that does not know the class
82
+ * still reads it as no verdict; preflight turns it into a skip of kind
83
+ * `unsupported` (spec A3). It is not the guard's refusal: `stellar:pubnet` has
84
+ * an adapter and is refused by `assertPaymentNetworkAllowed`, as an error.
85
+ */
86
+ export declare class UnsupportedPaymentNetworkError extends ConfigurationError {
87
+ readonly network: string;
88
+ constructor(network: string);
89
+ }
90
+ /**
91
+ * What a payment check reads before it can pay: the challenge, the URL to pay
92
+ * at, and the one option it would pay. Shared by `preparePayment` and the plan
93
+ * (L1), so both judge the same option by the same rules.
94
+ *
95
+ * Throws `PaymentNotAttemptedError` when there is nothing to pay: an
96
+ * unreadable or v1 challenge, no option on the run's network, or none in the
97
+ * `exact` scheme.
98
+ */
99
+ export declare function readPaymentChallenge(options: RequestShape & {
100
+ readonly target: string;
101
+ readonly network: string;
102
+ }): Promise<{
103
+ payUrl: string;
104
+ paymentRequired: import("@x402/fetch").PaymentRequired;
105
+ selected: PaymentRequirements;
106
+ idempotent: boolean;
107
+ }>;
55
108
  /**
56
109
  * Reads the settlement a paid response reports, before anything is looked up.
57
110
  *
@@ -63,29 +116,33 @@ export declare function readSettlementReference(status: number, readSettlement:
63
116
  readonly success: boolean;
64
117
  readonly transaction?: string;
65
118
  readonly errorReason?: string;
66
- }): {
119
+ }, chain?: PaymentChain): {
67
120
  readonly reference: string;
68
121
  } | {
69
122
  readonly failure: string;
123
+ readonly hint: string;
70
124
  };
71
125
  /**
72
- * Corrupts the client's authorization signature, and nothing else.
73
- *
74
- * In the `exact` scheme on Stellar the client signs a Soroban authorization
75
- * entry, not the envelope: the facilitator signs the envelope later. So the
76
- * signature that proves the payer consented is the address credential's
77
- * `signature`, a `Vec<{ public_key, signature }>`. Flipping one byte of it
78
- * leaves a transaction that still decodes, carries the same amount, payer and
79
- * recipient, and fails only signature verification. A target can refuse it
80
- * only by verifying the signature.
81
- *
82
- * Throws {@link CheckSetupError} if the payload carries no such signature, so
83
- * the check reports no verdict rather than one it did not establish.
126
+ * X402-07's verdict from the status a corrupted payment drew. Split out so
127
+ * the verdict can be tested without building a payment.
128
+ */
129
+ export declare function signatureRejectionVerdict(status: number, reason?: string): CheckResult;
130
+ /** X402-08's verdict from the status the replayed payment drew. */
131
+ export declare function replayVerdict(status: number, reason?: string): CheckResult;
132
+ /** X402-09's verdict from the status the underpaid payment drew. */
133
+ export declare function underpaymentVerdict(status: number, offered: bigint, advertised: bigint, reason?: string): CheckResult;
134
+ /** X402-10's verdict from the status the expired payment drew. */
135
+ export declare function expiredVerdict(status: number, reason?: string): CheckResult;
136
+ /**
137
+ * Every check `runX402PaymentChecks` reports, in order. Front ends that list
138
+ * checks before a run use it, so a read-only run never shows these as pending.
84
139
  */
85
- export declare function corruptAuthSignature(transaction: string): string;
140
+ export declare const X402_PAYMENT_CHECK_IDS: readonly string[];
86
141
  /**
87
- * Runs X402-06 and X402-07 against a target.
142
+ * Runs X402-06 through X402-10 against a target.
88
143
  *
89
- * Both settle real payments when the target accepts them; see docs/CHECKS.md.
144
+ * X402-06 settles a real payment. The negative checks send payments the
145
+ * target must refuse; a target that accepts the underpaid one may settle it.
146
+ * See docs/CHECKS.md.
90
147
  */
91
- export declare function runX402PaymentChecks(options: X402PaymentCheckOptions): Promise<CheckResult[]>;
148
+ export declare function runX402PaymentChecks(input: X402PaymentCheckOptions): Promise<CheckResult[]>;