@reinconsole/mock-rails 0.1.0 → 0.2.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/README.md +1 -1
- package/dist/index.d.ts +178 -7
- package/dist/index.js +433 -13
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The simulated payment world for **[Rein](https://github.com/bugiiiii11/rein)** — a fully offline twin of the real [x402](https://www.x402.org) rails. Try the whole guard loop — budgets, caps, kill switch, shadow-spend detection — with no accounts, no chain, no funds.
|
|
4
4
|
|
|
5
|
-
> **Status: v0.
|
|
5
|
+
> **Status: v0.2 — early open-source infrastructure.** APIs may change before 1.0. See it running (the live console world runs on these rails): [Rein console](https://app.reinconsole.com).
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
package/dist/index.d.ts
CHANGED
|
@@ -132,8 +132,169 @@ declare const MockPaymentHeader: z.ZodObject<{
|
|
|
132
132
|
};
|
|
133
133
|
}>;
|
|
134
134
|
type MockPaymentHeader = z.infer<typeof MockPaymentHeader>;
|
|
135
|
+
/**
|
|
136
|
+
* The v2 envelope (PAYMENT-SIGNATURE header): scheme/network live inside
|
|
137
|
+
* `accepted` — the requirement the payer chose — around the SAME scheme
|
|
138
|
+
* payload. `.passthrough()` keeps resource/extensions intact.
|
|
139
|
+
*/
|
|
140
|
+
declare const MockPaymentHeaderV2: z.ZodObject<{
|
|
141
|
+
x402Version: z.ZodLiteral<2>;
|
|
142
|
+
accepted: z.ZodObject<{
|
|
143
|
+
scheme: z.ZodString;
|
|
144
|
+
network: z.ZodString;
|
|
145
|
+
amount: z.ZodString;
|
|
146
|
+
asset: z.ZodString;
|
|
147
|
+
payTo: z.ZodString;
|
|
148
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
149
|
+
scheme: z.ZodString;
|
|
150
|
+
network: z.ZodString;
|
|
151
|
+
amount: z.ZodString;
|
|
152
|
+
asset: z.ZodString;
|
|
153
|
+
payTo: z.ZodString;
|
|
154
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
155
|
+
scheme: z.ZodString;
|
|
156
|
+
network: z.ZodString;
|
|
157
|
+
amount: z.ZodString;
|
|
158
|
+
asset: z.ZodString;
|
|
159
|
+
payTo: z.ZodString;
|
|
160
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
161
|
+
payload: z.ZodObject<{
|
|
162
|
+
from: z.ZodString;
|
|
163
|
+
to: z.ZodString;
|
|
164
|
+
/** Atomic-unit amount, mirroring the requirement's maxAmountRequired. */
|
|
165
|
+
value: z.ZodString;
|
|
166
|
+
asset: z.ZodString;
|
|
167
|
+
/**
|
|
168
|
+
* Rein linkage: the guard's payer stamps the intent id here, the facilitator
|
|
169
|
+
* memos it onto the ledger entry, and the indexer reconciles exactly. A real
|
|
170
|
+
* x402 transfer authorization carries a nonce that serves the same role.
|
|
171
|
+
*/
|
|
172
|
+
intentId: z.ZodOptional<z.ZodString>;
|
|
173
|
+
nonce: z.ZodOptional<z.ZodString>;
|
|
174
|
+
}, "strip", z.ZodTypeAny, {
|
|
175
|
+
from: string;
|
|
176
|
+
to: string;
|
|
177
|
+
value: string;
|
|
178
|
+
asset: string;
|
|
179
|
+
intentId?: string | undefined;
|
|
180
|
+
nonce?: string | undefined;
|
|
181
|
+
}, {
|
|
182
|
+
from: string;
|
|
183
|
+
to: string;
|
|
184
|
+
value: string;
|
|
185
|
+
asset: string;
|
|
186
|
+
intentId?: string | undefined;
|
|
187
|
+
nonce?: string | undefined;
|
|
188
|
+
}>;
|
|
189
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
190
|
+
x402Version: z.ZodLiteral<2>;
|
|
191
|
+
accepted: z.ZodObject<{
|
|
192
|
+
scheme: z.ZodString;
|
|
193
|
+
network: z.ZodString;
|
|
194
|
+
amount: z.ZodString;
|
|
195
|
+
asset: z.ZodString;
|
|
196
|
+
payTo: z.ZodString;
|
|
197
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
198
|
+
scheme: z.ZodString;
|
|
199
|
+
network: z.ZodString;
|
|
200
|
+
amount: z.ZodString;
|
|
201
|
+
asset: z.ZodString;
|
|
202
|
+
payTo: z.ZodString;
|
|
203
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
204
|
+
scheme: z.ZodString;
|
|
205
|
+
network: z.ZodString;
|
|
206
|
+
amount: z.ZodString;
|
|
207
|
+
asset: z.ZodString;
|
|
208
|
+
payTo: z.ZodString;
|
|
209
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
210
|
+
payload: z.ZodObject<{
|
|
211
|
+
from: z.ZodString;
|
|
212
|
+
to: z.ZodString;
|
|
213
|
+
/** Atomic-unit amount, mirroring the requirement's maxAmountRequired. */
|
|
214
|
+
value: z.ZodString;
|
|
215
|
+
asset: z.ZodString;
|
|
216
|
+
/**
|
|
217
|
+
* Rein linkage: the guard's payer stamps the intent id here, the facilitator
|
|
218
|
+
* memos it onto the ledger entry, and the indexer reconciles exactly. A real
|
|
219
|
+
* x402 transfer authorization carries a nonce that serves the same role.
|
|
220
|
+
*/
|
|
221
|
+
intentId: z.ZodOptional<z.ZodString>;
|
|
222
|
+
nonce: z.ZodOptional<z.ZodString>;
|
|
223
|
+
}, "strip", z.ZodTypeAny, {
|
|
224
|
+
from: string;
|
|
225
|
+
to: string;
|
|
226
|
+
value: string;
|
|
227
|
+
asset: string;
|
|
228
|
+
intentId?: string | undefined;
|
|
229
|
+
nonce?: string | undefined;
|
|
230
|
+
}, {
|
|
231
|
+
from: string;
|
|
232
|
+
to: string;
|
|
233
|
+
value: string;
|
|
234
|
+
asset: string;
|
|
235
|
+
intentId?: string | undefined;
|
|
236
|
+
nonce?: string | undefined;
|
|
237
|
+
}>;
|
|
238
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
239
|
+
x402Version: z.ZodLiteral<2>;
|
|
240
|
+
accepted: z.ZodObject<{
|
|
241
|
+
scheme: z.ZodString;
|
|
242
|
+
network: z.ZodString;
|
|
243
|
+
amount: z.ZodString;
|
|
244
|
+
asset: z.ZodString;
|
|
245
|
+
payTo: z.ZodString;
|
|
246
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
247
|
+
scheme: z.ZodString;
|
|
248
|
+
network: z.ZodString;
|
|
249
|
+
amount: z.ZodString;
|
|
250
|
+
asset: z.ZodString;
|
|
251
|
+
payTo: z.ZodString;
|
|
252
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
253
|
+
scheme: z.ZodString;
|
|
254
|
+
network: z.ZodString;
|
|
255
|
+
amount: z.ZodString;
|
|
256
|
+
asset: z.ZodString;
|
|
257
|
+
payTo: z.ZodString;
|
|
258
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
259
|
+
payload: z.ZodObject<{
|
|
260
|
+
from: z.ZodString;
|
|
261
|
+
to: z.ZodString;
|
|
262
|
+
/** Atomic-unit amount, mirroring the requirement's maxAmountRequired. */
|
|
263
|
+
value: z.ZodString;
|
|
264
|
+
asset: z.ZodString;
|
|
265
|
+
/**
|
|
266
|
+
* Rein linkage: the guard's payer stamps the intent id here, the facilitator
|
|
267
|
+
* memos it onto the ledger entry, and the indexer reconciles exactly. A real
|
|
268
|
+
* x402 transfer authorization carries a nonce that serves the same role.
|
|
269
|
+
*/
|
|
270
|
+
intentId: z.ZodOptional<z.ZodString>;
|
|
271
|
+
nonce: z.ZodOptional<z.ZodString>;
|
|
272
|
+
}, "strip", z.ZodTypeAny, {
|
|
273
|
+
from: string;
|
|
274
|
+
to: string;
|
|
275
|
+
value: string;
|
|
276
|
+
asset: string;
|
|
277
|
+
intentId?: string | undefined;
|
|
278
|
+
nonce?: string | undefined;
|
|
279
|
+
}, {
|
|
280
|
+
from: string;
|
|
281
|
+
to: string;
|
|
282
|
+
value: string;
|
|
283
|
+
asset: string;
|
|
284
|
+
intentId?: string | undefined;
|
|
285
|
+
nonce?: string | undefined;
|
|
286
|
+
}>;
|
|
287
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
288
|
+
type MockPaymentHeaderV2 = z.infer<typeof MockPaymentHeaderV2>;
|
|
289
|
+
/** A payment as the facilitator sees it, whichever dialect it arrived in. */
|
|
290
|
+
interface DecodedPayment {
|
|
291
|
+
version: 1 | 2;
|
|
292
|
+
scheme: string;
|
|
293
|
+
network: string;
|
|
294
|
+
payload: MockExactPayload;
|
|
295
|
+
}
|
|
135
296
|
declare function encodePaymentHeader(header: MockPaymentHeader): string;
|
|
136
|
-
declare function decodePaymentHeader(raw: string):
|
|
297
|
+
declare function decodePaymentHeader(raw: string): DecodedPayment;
|
|
137
298
|
/** What the facilitator returns on settle; the vendor base64s it into X-PAYMENT-RESPONSE. */
|
|
138
299
|
declare const SettlementResponse: z.ZodObject<{
|
|
139
300
|
success: z.ZodBoolean;
|
|
@@ -188,8 +349,9 @@ declare class MockFacilitator {
|
|
|
188
349
|
* the plug-in point the real x402 signer replaces.
|
|
189
350
|
*/
|
|
190
351
|
payerFor(fromAddress: string): Payer;
|
|
191
|
-
/** Verify
|
|
192
|
-
|
|
352
|
+
/** Verify a payment header (either dialect) against the requirement it
|
|
353
|
+
* claims to satisfy. */
|
|
354
|
+
verify(paymentHeader: string, requirement: PaymentRequirement): DecodedPayment;
|
|
193
355
|
/**
|
|
194
356
|
* Verify, then settle: write the transfer on the mock chain and return the
|
|
195
357
|
* settlement response the vendor relays via X-PAYMENT-RESPONSE.
|
|
@@ -263,6 +425,15 @@ interface MockVendorOptions {
|
|
|
263
425
|
scheme?: string;
|
|
264
426
|
/** JSON body served once payment settles. */
|
|
265
427
|
body?: unknown;
|
|
428
|
+
/**
|
|
429
|
+
* Which x402 dialect the vendor's 402s advertise. 'v1' (default) is the
|
|
430
|
+
* classic JSON body; 'dual' adds the v2 PAYMENT-REQUIRED header beside it;
|
|
431
|
+
* 'v2' advertises ONLY the header (the body is not x402) — a strict v2
|
|
432
|
+
* vendor for proving clients need no v1 fallback. Payments are ACCEPTED in
|
|
433
|
+
* both dialects (PAYMENT-SIGNATURE or X-PAYMENT) regardless of this option,
|
|
434
|
+
* mirroring the gate.
|
|
435
|
+
*/
|
|
436
|
+
advertise?: 'v1' | 'dual' | 'v2';
|
|
266
437
|
}
|
|
267
438
|
interface VendorCall {
|
|
268
439
|
url: string;
|
|
@@ -278,10 +449,10 @@ interface MockVendor {
|
|
|
278
449
|
}
|
|
279
450
|
/**
|
|
280
451
|
* An in-process x402 vendor wired to the mock facilitator: quotes a 402 with
|
|
281
|
-
* payment requirements until the request carries
|
|
452
|
+
* payment requirements until the request carries a payment, then settles
|
|
282
453
|
* through the facilitator (writing the transfer on the mock ledger) and serves
|
|
283
|
-
* the content with the settlement in
|
|
284
|
-
* mock rails — guard pays it, indexer watches the ledger behind it.
|
|
454
|
+
* the content with the settlement in the response headers. The third leg of
|
|
455
|
+
* the mock rails — guard pays it, indexer watches the ledger behind it.
|
|
285
456
|
*/
|
|
286
457
|
declare function createMockVendor(options: MockVendorOptions): MockVendor;
|
|
287
458
|
|
|
@@ -292,4 +463,4 @@ declare class FacilitatorError extends Error {
|
|
|
292
463
|
constructor(code: FacilitatorErrorCode, message: string);
|
|
293
464
|
}
|
|
294
465
|
|
|
295
|
-
export { type EngineEvents, FacilitatorError, type FacilitatorErrorCode, type LedgerEntry, MockExactPayload, MockFacilitator, type MockFacilitatorOptions, MockIndexer, type MockIndexerOptions, MockLedger, MockPaymentHeader, type MockVendor, type MockVendorOptions, type SettleResult, SettlementResponse, type ShadowSpend, type TransferInput, type VendorCall, createMockVendor, decodePaymentHeader, encodePaymentHeader, encodeSettlementHeader };
|
|
466
|
+
export { type DecodedPayment, type EngineEvents, FacilitatorError, type FacilitatorErrorCode, type LedgerEntry, MockExactPayload, MockFacilitator, type MockFacilitatorOptions, MockIndexer, type MockIndexerOptions, MockLedger, MockPaymentHeader, MockPaymentHeaderV2, type MockVendor, type MockVendorOptions, type SettleResult, SettlementResponse, type ShadowSpend, type TransferInput, type VendorCall, createMockVendor, decodePaymentHeader, encodePaymentHeader, encodeSettlementHeader };
|