@toon-protocol/client 5.2.1 → 6.0.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/{chunk-IN75RK7V.js → chunk-UCCGUT6X.js} +2591 -2584
- package/dist/chunk-UCCGUT6X.js.map +1 -0
- package/dist/cli/main.js +1 -1
- package/dist/{client-LXLZVJV4.js → client-7TB2OPOY.js} +2 -2
- package/dist/index.d.ts +744 -661
- package/dist/index.js +11 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-IN75RK7V.js.map +0 -1
- /package/dist/{client-LXLZVJV4.js.map → client-7TB2OPOY.js.map} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1290,49 +1290,6 @@ declare function routePriceFor(desc: NodeSelfDescription, destination: string):
|
|
|
1290
1290
|
*/
|
|
1291
1291
|
declare function routeFor(desc: NodeSelfDescription, destination: string): RoutePrice | undefined;
|
|
1292
1292
|
|
|
1293
|
-
interface ChannelStoreEntry {
|
|
1294
|
-
nonce: number;
|
|
1295
|
-
cumulativeAmount: bigint;
|
|
1296
|
-
/**
|
|
1297
|
-
* The highest cumulative this client has ever SIGNED on the channel, which a
|
|
1298
|
-
* rollback deliberately does not lower. It is the ceiling on what the
|
|
1299
|
-
* connector can possibly have banked — nothing it never received a signature
|
|
1300
|
-
* for is claimable — and so the clamp on adopting the connector's own figure
|
|
1301
|
-
* (see `BatchChannelManager.adoptConnectorWatermark`).
|
|
1302
|
-
*/
|
|
1303
|
-
signedCeiling?: bigint;
|
|
1304
|
-
/**
|
|
1305
|
-
* The highest cumulative the connector is PROVEN to hold: what the chain
|
|
1306
|
-
* shows landed, a voucher it banked, or one it refused as not advancing. The
|
|
1307
|
-
* floor under adopting the connector's own figure, as `signedCeiling` is the
|
|
1308
|
-
* ceiling over it.
|
|
1309
|
-
*/
|
|
1310
|
-
provenFloor?: bigint;
|
|
1311
|
-
/**
|
|
1312
|
-
* Set when the connector refused a claim as not advancing its watermark
|
|
1313
|
-
* without saying where that watermark is. It means "our watermark and the
|
|
1314
|
-
* connector's disagree", and the next claim on this channel reconciles
|
|
1315
|
-
* against `POST /ilp/claim-state` before it is signed; adopting the
|
|
1316
|
-
* connector's figure clears it. Persisted because each `toon-client`
|
|
1317
|
-
* invocation is a new process, and the next one must resync first.
|
|
1318
|
-
*/
|
|
1319
|
-
watermarkUncertain?: boolean;
|
|
1320
|
-
/** Unix SECONDS when close was initiated (withdraw flow). */
|
|
1321
|
-
closedAt?: bigint;
|
|
1322
|
-
/** Unix SECONDS the channel becomes settleable (= closedAt + settlementTimeout). */
|
|
1323
|
-
settleableAt?: bigint;
|
|
1324
|
-
/** Unix SECONDS the channel was settled (collateral released). */
|
|
1325
|
-
settledAt?: bigint;
|
|
1326
|
-
}
|
|
1327
|
-
/** Where a channel lives: its chain, the x402 contract or program, and its token. */
|
|
1328
|
-
interface ChannelBindingContext {
|
|
1329
|
-
chainType: string;
|
|
1330
|
-
chainId: number;
|
|
1331
|
-
tokenNetworkAddress: string;
|
|
1332
|
-
tokenAddress?: string;
|
|
1333
|
-
/** Counterparty settlement address (required for Solana/Mina proofs). */
|
|
1334
|
-
recipient?: string;
|
|
1335
|
-
}
|
|
1336
1293
|
/**
|
|
1337
1294
|
* The config of an x402 `batch-settlement` channel (connector ADR 0074), in a
|
|
1338
1295
|
* JSON-safe spelling: every field a string or a number, so both stores persist
|
|
@@ -1372,144 +1329,138 @@ type BatchSettlementBinding = {
|
|
|
1372
1329
|
};
|
|
1373
1330
|
};
|
|
1374
1331
|
/**
|
|
1375
|
-
*
|
|
1376
|
-
*
|
|
1332
|
+
* Everything the payer keeps about one x402 `batch-settlement` channel: its
|
|
1333
|
+
* config, its deposit, its watermark, its last voucher and its exit
|
|
1334
|
+
* timestamps. One record per channel id.
|
|
1377
1335
|
*/
|
|
1378
|
-
interface
|
|
1379
|
-
/** On-chain payment channel id (EVM bytes32 / Solana PDA / Mina zkApp). */
|
|
1336
|
+
interface ChannelStoreEntry {
|
|
1380
1337
|
channelId: string;
|
|
1381
|
-
/**
|
|
1382
|
-
|
|
1383
|
-
/**
|
|
1384
|
-
|
|
1385
|
-
|
|
1338
|
+
/** The connector the channel pays. Part of how {@link ChannelStore.find} looks it up. */
|
|
1339
|
+
connector: string;
|
|
1340
|
+
/**
|
|
1341
|
+
* The channel's config, which names its network and token. Required: the id
|
|
1342
|
+
* travels in every voucher and is never derived, so a channel whose config
|
|
1343
|
+
* was not kept cannot be resumed (ADR 0003).
|
|
1344
|
+
*/
|
|
1345
|
+
batchSettlement: BatchSettlementBinding;
|
|
1346
|
+
/** On-chain collateral the channel holds, as far as this client knows. */
|
|
1347
|
+
depositTotal: bigint;
|
|
1348
|
+
/**
|
|
1349
|
+
* A deposit handed to a facilitator or a sponsor whose fate is not yet known.
|
|
1350
|
+
* Recorded BEFORE the deposit leaves, so a lost answer never loses the
|
|
1351
|
+
* channel: the next use reads the chain and settles it.
|
|
1352
|
+
*/
|
|
1353
|
+
pendingDeposit?: bigint;
|
|
1354
|
+
/** ISO timestamp the record was created. */
|
|
1386
1355
|
openedAt?: string;
|
|
1387
1356
|
/**
|
|
1388
|
-
* ISO timestamp
|
|
1389
|
-
*
|
|
1390
|
-
*
|
|
1391
|
-
* A superseded binding is never resumed again, but stays in
|
|
1392
|
-
* {@link ChannelStore.listBindings} so whatever it holds on-chain can still
|
|
1393
|
-
* be found and reclaimed.
|
|
1357
|
+
* ISO timestamp the channel was RETIRED because a newer channel took its
|
|
1358
|
+
* connector, network and asset. A retired channel is never resumed, but it
|
|
1359
|
+
* stays in {@link ChannelStore.list}: it may still hold a deposit.
|
|
1394
1360
|
*/
|
|
1395
1361
|
supersededAt?: string;
|
|
1362
|
+
/** The cumulative amount this client counts as signed. */
|
|
1363
|
+
cumulativeAmount: bigint;
|
|
1396
1364
|
/**
|
|
1397
|
-
*
|
|
1398
|
-
*
|
|
1399
|
-
*
|
|
1400
|
-
*
|
|
1365
|
+
* The highest cumulative this client has ever SIGNED on the channel, which a
|
|
1366
|
+
* rollback deliberately does not lower. It is the ceiling on what the
|
|
1367
|
+
* connector can possibly have banked, and so the clamp on adopting the
|
|
1368
|
+
* connector's own figure.
|
|
1401
1369
|
*/
|
|
1402
|
-
|
|
1370
|
+
signedCeiling?: bigint;
|
|
1403
1371
|
/**
|
|
1404
|
-
*
|
|
1405
|
-
*
|
|
1406
|
-
*
|
|
1407
|
-
* reads the chain and settles it.
|
|
1372
|
+
* The highest cumulative the connector is PROVEN to hold: what the chain
|
|
1373
|
+
* shows landed, a voucher it banked, or one it refused as not advancing. The
|
|
1374
|
+
* floor under adopting the connector's own figure.
|
|
1408
1375
|
*/
|
|
1409
|
-
|
|
1376
|
+
provenFloor?: bigint;
|
|
1410
1377
|
/**
|
|
1411
|
-
* The
|
|
1412
|
-
*
|
|
1413
|
-
*
|
|
1378
|
+
* The watermark is in doubt: a refusal said "not advancing" without saying
|
|
1379
|
+
* where the connector's watermark is. The next voucher resyncs against the
|
|
1380
|
+
* connector before it is signed. Persisted because each `toon-client`
|
|
1381
|
+
* invocation is a new process.
|
|
1382
|
+
*/
|
|
1383
|
+
watermarkUncertain?: boolean;
|
|
1384
|
+
/**
|
|
1385
|
+
* The watermark was not found when an older store was read, so
|
|
1386
|
+
* `cumulativeAmount` is a placeholder until it is rebuilt from the chain and
|
|
1387
|
+
* the connector.
|
|
1388
|
+
*/
|
|
1389
|
+
watermarkLost?: boolean;
|
|
1390
|
+
/**
|
|
1391
|
+
* The last voucher sent, as the JSON that travelled. A probe resends it byte
|
|
1392
|
+
* for byte, a retransmission the connector records nothing for.
|
|
1414
1393
|
*/
|
|
1415
1394
|
lastVoucher?: string;
|
|
1416
1395
|
/** The cumulative amount {@link lastVoucher} names. */
|
|
1417
1396
|
lastVoucherAmount?: bigint;
|
|
1397
|
+
/** Unix SECONDS when close was initiated (withdraw flow). */
|
|
1398
|
+
closedAt?: bigint;
|
|
1399
|
+
/** Unix SECONDS the withdraw delay ends and the deposit can be taken back. */
|
|
1400
|
+
settleableAt?: bigint;
|
|
1401
|
+
/** Unix SECONDS the channel was settled (collateral released). */
|
|
1402
|
+
settledAt?: bigint;
|
|
1418
1403
|
}
|
|
1419
1404
|
/**
|
|
1420
|
-
*
|
|
1421
|
-
*
|
|
1422
|
-
* The binding methods are OPTIONAL so a third-party `ChannelStore` written
|
|
1423
|
-
* against the pre-#489 surface still satisfies the type; a store that omits
|
|
1424
|
-
* them simply can't resume a peer's channel across restarts (it will open a
|
|
1425
|
-
* fresh one, the old behaviour). {@link JsonFileChannelStore} implements them.
|
|
1405
|
+
* The store the payer's channel records live in. Every method is required: a
|
|
1406
|
+
* store that cannot persist the channel config cannot resume a channel.
|
|
1426
1407
|
*/
|
|
1427
1408
|
interface ChannelStore {
|
|
1428
|
-
|
|
1409
|
+
/** Write the record for `entry.channelId`, replacing any earlier one. */
|
|
1410
|
+
save(entry: ChannelStoreEntry): void;
|
|
1429
1411
|
load(channelId: string): ChannelStoreEntry | undefined;
|
|
1430
|
-
list(): string[];
|
|
1431
|
-
delete(channelId: string): void;
|
|
1432
|
-
/** Persist the channel a peer key is bound to. */
|
|
1433
|
-
saveBinding?(key: string, binding: ChannelBinding): void;
|
|
1434
|
-
/** The channel a peer key is bound to, if any. */
|
|
1435
|
-
loadBinding?(key: string): ChannelBinding | undefined;
|
|
1436
|
-
/** Every persisted binding, keyed as {@link saveBinding} stored it. */
|
|
1437
|
-
listBindings?(): {
|
|
1438
|
-
key: string;
|
|
1439
|
-
binding: ChannelBinding;
|
|
1440
|
-
}[];
|
|
1441
|
-
/** Forget a binding (its nonce watermark is deliberately left intact). */
|
|
1442
|
-
deleteBinding?(key: string): void;
|
|
1443
1412
|
/**
|
|
1444
|
-
*
|
|
1445
|
-
*
|
|
1446
|
-
* node now answering (`F01 - claim rejected`) even though every key field
|
|
1447
|
-
* still matches.
|
|
1448
|
-
*
|
|
1449
|
-
* ARCHIVES rather than deletes: the retired channel may still hold an
|
|
1450
|
-
* on-chain deposit, so dropping it would strand those funds behind
|
|
1451
|
-
* hand-editing the JSON. It disappears from {@link loadBinding} (never
|
|
1452
|
-
* resumed again) and frees its live key for the re-resolved channel, while
|
|
1453
|
-
* {@link listBindings} still shows it. Idempotent; a no-op for an unknown
|
|
1454
|
-
* key. Optional, like the rest of the binding surface: a store that omits it
|
|
1455
|
-
* simply keeps the pre-validation behaviour of overwriting the stale record.
|
|
1413
|
+
* The live (not retired) channel for `connector` on `network` in `asset`, if
|
|
1414
|
+
* there is one.
|
|
1456
1415
|
*/
|
|
1457
|
-
|
|
1416
|
+
find(connector: string, network: string, asset: string): ChannelStoreEntry | undefined;
|
|
1417
|
+
/** Every record, live or retired. */
|
|
1418
|
+
list(): ChannelStoreEntry[];
|
|
1419
|
+
/** Forget a record. A retired channel is archived with `supersededAt`, never deleted. */
|
|
1420
|
+
delete(channelId: string): void;
|
|
1458
1421
|
}
|
|
1459
1422
|
/**
|
|
1460
|
-
* JSON file-backed ChannelStore
|
|
1461
|
-
*
|
|
1423
|
+
* JSON file-backed ChannelStore, with synchronous I/O to match
|
|
1424
|
+
* BatchChannelManager.
|
|
1425
|
+
*
|
|
1426
|
+
* One file, `{ [channelId]: record }`. Each record keeps `cumulativeAmount`
|
|
1427
|
+
* under its channel id, which rig reads directly.
|
|
1462
1428
|
*
|
|
1463
|
-
*
|
|
1464
|
-
*
|
|
1465
|
-
*
|
|
1466
|
-
*
|
|
1467
|
-
*
|
|
1468
|
-
* external readers.
|
|
1429
|
+
* A release that kept bindings in a sibling `channels.peers.json` is migrated
|
|
1430
|
+
* on first use: its bindings are joined with the watermarks in `filePath`, the
|
|
1431
|
+
* result is written to `filePath`, and the sibling is renamed to
|
|
1432
|
+
* `channels.peers.json.migrated`. Fields no longer used (`nonce`, the binding
|
|
1433
|
+
* context) are ignored on read and not written back.
|
|
1469
1434
|
*/
|
|
1470
1435
|
declare class JsonFileChannelStore implements ChannelStore {
|
|
1471
1436
|
private readonly filePath;
|
|
1472
|
-
private readonly
|
|
1437
|
+
private readonly legacyPath;
|
|
1438
|
+
/** `options.bindingsPath` is where an older release kept its bindings. */
|
|
1473
1439
|
constructor(filePath: string, options?: {
|
|
1474
1440
|
bindingsPath?: string;
|
|
1475
1441
|
});
|
|
1476
|
-
save(
|
|
1442
|
+
save(entry: ChannelStoreEntry): void;
|
|
1477
1443
|
load(channelId: string): ChannelStoreEntry | undefined;
|
|
1478
|
-
|
|
1444
|
+
find(connector: string, network: string, asset: string): ChannelStoreEntry | undefined;
|
|
1445
|
+
list(): ChannelStoreEntry[];
|
|
1479
1446
|
delete(channelId: string): void;
|
|
1480
|
-
saveBinding(key: string, binding: ChannelBinding): void;
|
|
1481
|
-
loadBinding(key: string): ChannelBinding | undefined;
|
|
1482
|
-
listBindings(): {
|
|
1483
|
-
key: string;
|
|
1484
|
-
binding: ChannelBinding;
|
|
1485
|
-
}[];
|
|
1486
|
-
deleteBinding(key: string): void;
|
|
1487
|
-
supersedeBinding(key: string): void;
|
|
1488
1447
|
private readFile;
|
|
1448
|
+
private migrate;
|
|
1489
1449
|
private writeFile;
|
|
1490
|
-
private readBindings;
|
|
1491
|
-
private writeBindings;
|
|
1492
1450
|
}
|
|
1493
1451
|
/**
|
|
1494
|
-
* In-memory {@link ChannelStore}
|
|
1495
|
-
*
|
|
1496
|
-
* touching disk.
|
|
1452
|
+
* In-memory {@link ChannelStore}. Handy for tests and for a process that wants
|
|
1453
|
+
* resume semantics within its own lifetime without touching disk.
|
|
1497
1454
|
*/
|
|
1498
1455
|
declare class InMemoryChannelStore implements ChannelStore {
|
|
1499
1456
|
private readonly entries;
|
|
1500
|
-
|
|
1501
|
-
|
|
1457
|
+
/** Live channel id by lookup key. */
|
|
1458
|
+
private readonly live;
|
|
1459
|
+
save(entry: ChannelStoreEntry): void;
|
|
1502
1460
|
load(channelId: string): ChannelStoreEntry | undefined;
|
|
1503
|
-
|
|
1461
|
+
find(connector: string, network: string, asset: string): ChannelStoreEntry | undefined;
|
|
1462
|
+
list(): ChannelStoreEntry[];
|
|
1504
1463
|
delete(channelId: string): void;
|
|
1505
|
-
saveBinding(key: string, binding: ChannelBinding): void;
|
|
1506
|
-
loadBinding(key: string): ChannelBinding | undefined;
|
|
1507
|
-
listBindings(): {
|
|
1508
|
-
key: string;
|
|
1509
|
-
binding: ChannelBinding;
|
|
1510
|
-
}[];
|
|
1511
|
-
deleteBinding(key: string): void;
|
|
1512
|
-
supersedeBinding(key: string): void;
|
|
1513
1464
|
}
|
|
1514
1465
|
|
|
1515
1466
|
/**
|
|
@@ -1519,7 +1470,7 @@ declare class InMemoryChannelStore implements ChannelStore {
|
|
|
1519
1470
|
*
|
|
1520
1471
|
* A voucher is not a balance proof, so the bookkeeping is its own:
|
|
1521
1472
|
*
|
|
1522
|
-
* - **
|
|
1473
|
+
* - **Only the amount is kept.** The connector orders vouchers by amount alone and
|
|
1523
1474
|
* accepts one only if it strictly exceeds the channel's watermark by at
|
|
1524
1475
|
* least the charge, so the one number to keep is the cumulative amount.
|
|
1525
1476
|
* - **Nothing is derived.** The channel id travels in every voucher, so the
|
|
@@ -1567,8 +1518,6 @@ type BatchChannel = {
|
|
|
1567
1518
|
declare class BatchChannelManager {
|
|
1568
1519
|
private readonly store;
|
|
1569
1520
|
constructor(store?: ChannelStore);
|
|
1570
|
-
/** Where the binding for `connector`'s channel on `network` in `asset` lives. */
|
|
1571
|
-
static bindingKey(connector: string, network: string, asset: string): string;
|
|
1572
1521
|
/**
|
|
1573
1522
|
* Record a channel this client just opened or deposited into (and so owns),
|
|
1574
1523
|
* with the deposit it holds. A new channel starts at a watermark of zero; a
|
|
@@ -1626,7 +1575,9 @@ declare class BatchChannelManager {
|
|
|
1626
1575
|
* next voucher is priced from it rather than refused the same way again;
|
|
1627
1576
|
* - **it did not advance** — the connector holds at least this much, and
|
|
1628
1577
|
* can hold no more than this client ever signed, so the count moves to
|
|
1629
|
-
* that ceiling and the next voucher clears whatever it holds
|
|
1578
|
+
* that ceiling and the next voucher clears whatever it holds — and,
|
|
1579
|
+
* with no figure named, the channel is in doubt until the connector's
|
|
1580
|
+
* own figure is adopted;
|
|
1630
1581
|
* - **anything else** banked nothing, and the charge is given back — but
|
|
1631
1582
|
* only if no later voucher has already superseded this one, since a
|
|
1632
1583
|
* concurrent send may have been banked above it.
|
|
@@ -1658,18 +1609,16 @@ declare class BatchChannelManager {
|
|
|
1658
1609
|
adoptConnectorWatermark(channelId: string, cumulativeClaimed: bigint, options?: {
|
|
1659
1610
|
recovering?: boolean;
|
|
1660
1611
|
}): void;
|
|
1661
|
-
/**
|
|
1662
|
-
* Mark `channelId`'s watermark as possibly out of step with the connector's.
|
|
1663
|
-
* Persisted, so the next invocation resyncs before it signs.
|
|
1664
|
-
*/
|
|
1665
|
-
markInDoubt(channelId: string): void;
|
|
1666
1612
|
/** Whether `channelId`'s watermark is in doubt, here or in an earlier invocation. */
|
|
1667
1613
|
inDoubt(channelId: string): boolean;
|
|
1668
|
-
/**
|
|
1614
|
+
/**
|
|
1615
|
+
* Whether this client still holds the watermark for `channelId`. A record
|
|
1616
|
+
* read from an older store that kept the config apart from the watermark can
|
|
1617
|
+
* come without one.
|
|
1618
|
+
*/
|
|
1669
1619
|
hasWatermark(channelId: string): boolean;
|
|
1670
1620
|
/**
|
|
1671
|
-
* Rebuild a
|
|
1672
|
-
* live in separate files — from what the chain shows landed. The connector
|
|
1621
|
+
* Rebuild a missing watermark from what the chain shows landed. The connector
|
|
1673
1622
|
* holds at least that much; the payer then asks `claim-state` for the
|
|
1674
1623
|
* connector's own figure (connector#1364), which replaces this floor.
|
|
1675
1624
|
*/
|
|
@@ -1709,219 +1658,116 @@ declare class BatchChannelManager {
|
|
|
1709
1658
|
* yet closing, whether live or archived by a newer one.
|
|
1710
1659
|
*/
|
|
1711
1660
|
openChannels(connector: string): BatchChannel[];
|
|
1712
|
-
private requireBinding;
|
|
1713
1661
|
private entry;
|
|
1714
|
-
/**
|
|
1715
|
-
* The binding that records `channelId`, live or archived: a channel retired by
|
|
1716
|
-
* a newer one on the same connector still holds its deposit, and still needs
|
|
1717
|
-
* its watermark to exit.
|
|
1718
|
-
*/
|
|
1719
|
-
private findBinding;
|
|
1720
1662
|
}
|
|
1721
1663
|
|
|
1722
1664
|
/**
|
|
1723
|
-
*
|
|
1724
|
-
*
|
|
1725
|
-
*
|
|
1726
|
-
* The contract's `deposit(config, amount, collector, collectorData)` is
|
|
1727
|
-
* callable by anyone: the payer's one signature — an ERC-3009 authorization or
|
|
1728
|
-
* a Permit2 witness transfer — binds the deposit to its channel. So the same
|
|
1729
|
-
* signed payload can be put on chain two ways:
|
|
1730
|
-
*
|
|
1731
|
-
* - **by a facilitator**, which pays the gas (`facilitator.ts`); or
|
|
1732
|
-
* - **by the payer itself**, from its own ETH ({@link depositDirectly}).
|
|
1733
|
-
*
|
|
1734
|
-
* Both spend the one authorization, and its nonce is single-use on chain — the
|
|
1735
|
-
* ERC-3009 nonce is `keccak256(channelId, salt)`, a Permit2 nonce is
|
|
1736
|
-
* unordered and random — so a direct deposit after a facilitator's answer was
|
|
1737
|
-
* lost can never land twice: whichever arrives second reverts.
|
|
1665
|
+
* A **settlement network**: one adapter per network this client pays on, which
|
|
1666
|
+
* owns everything chain-specific about an x402 `batch-settlement` channel
|
|
1667
|
+
* there (connector #1684, #1685; toon-client#777).
|
|
1738
1668
|
*
|
|
1739
|
-
*
|
|
1740
|
-
* payer's `approve(Permit2, …)`. That approval is gas too, and x402 defines
|
|
1741
|
-
* two extensions for a facilitator to cover it:
|
|
1669
|
+
* The payer asks it, and never asks "which chain is this?" itself:
|
|
1742
1670
|
*
|
|
1743
|
-
* -
|
|
1744
|
-
*
|
|
1745
|
-
*
|
|
1746
|
-
*
|
|
1747
|
-
*
|
|
1671
|
+
* - to open a channel from the connector's terms ({@link SettlementNetwork.open});
|
|
1672
|
+
* - to cover a charge the deposit cannot: an EVM channel is topped up, a
|
|
1673
|
+
* Solana one replaced (ADR 0003) — {@link SettlementNetwork.cover};
|
|
1674
|
+
* - to read a channel's escrow and what has landed ({@link SettlementNetwork.read});
|
|
1675
|
+
* - and, through its **voucher scheme**, to sign a voucher into the claim a
|
|
1676
|
+
* packet carries ({@link SettlementNetwork.voucher}) and to sign the
|
|
1677
|
+
* claim-state challenge ({@link SettlementNetwork.challenge}).
|
|
1748
1678
|
*
|
|
1749
|
-
*
|
|
1750
|
-
*
|
|
1751
|
-
* (`@x402/evm` 2.27.0, `batch-settlement/encoding.ts` and
|
|
1752
|
-
* `shared/extensions`), so a facilitator and a direct deposit read the same
|
|
1753
|
-
* bytes.
|
|
1679
|
+
* Each is built once, at client creation, from the chain's key and its RPC
|
|
1680
|
+
* route: `evm-network.ts` and `solana-network.ts`.
|
|
1754
1681
|
*/
|
|
1755
1682
|
|
|
1756
|
-
declare const EIP2612_GAS_SPONSORING = "eip2612GasSponsoring";
|
|
1757
|
-
declare const ERC20_APPROVAL_GAS_SPONSORING = "erc20ApprovalGasSponsoring";
|
|
1758
|
-
/** `x402BatchSettlement.deposit`. */
|
|
1759
|
-
declare const X402_BATCH_SETTLEMENT_DEPOSIT_ABI: readonly [{
|
|
1760
|
-
readonly type: "function";
|
|
1761
|
-
readonly name: "deposit";
|
|
1762
|
-
readonly stateMutability: "nonpayable";
|
|
1763
|
-
readonly inputs: readonly [{
|
|
1764
|
-
readonly name: "config";
|
|
1765
|
-
readonly type: "tuple";
|
|
1766
|
-
readonly components: readonly [{
|
|
1767
|
-
readonly name: "payer";
|
|
1768
|
-
readonly type: "address";
|
|
1769
|
-
}, {
|
|
1770
|
-
readonly name: "payerAuthorizer";
|
|
1771
|
-
readonly type: "address";
|
|
1772
|
-
}, {
|
|
1773
|
-
readonly name: "receiver";
|
|
1774
|
-
readonly type: "address";
|
|
1775
|
-
}, {
|
|
1776
|
-
readonly name: "receiverAuthorizer";
|
|
1777
|
-
readonly type: "address";
|
|
1778
|
-
}, {
|
|
1779
|
-
readonly name: "token";
|
|
1780
|
-
readonly type: "address";
|
|
1781
|
-
}, {
|
|
1782
|
-
readonly name: "withdrawDelay";
|
|
1783
|
-
readonly type: "uint40";
|
|
1784
|
-
}, {
|
|
1785
|
-
readonly name: "salt";
|
|
1786
|
-
readonly type: "bytes32";
|
|
1787
|
-
}];
|
|
1788
|
-
}, {
|
|
1789
|
-
readonly name: "amount";
|
|
1790
|
-
readonly type: "uint128";
|
|
1791
|
-
}, {
|
|
1792
|
-
readonly name: "collector";
|
|
1793
|
-
readonly type: "address";
|
|
1794
|
-
}, {
|
|
1795
|
-
readonly name: "collectorData";
|
|
1796
|
-
readonly type: "bytes";
|
|
1797
|
-
}];
|
|
1798
|
-
readonly outputs: readonly [];
|
|
1799
|
-
}];
|
|
1800
1683
|
/**
|
|
1801
|
-
*
|
|
1802
|
-
*
|
|
1803
|
-
*
|
|
1684
|
+
* A channel built and ready to open, not yet sent. The payer records it as
|
|
1685
|
+
* pending before {@link land} sends it: a facilitator or sponsor may land the
|
|
1686
|
+
* deposit and lose the answer, and a channel not recorded first is a deposit
|
|
1687
|
+
* lost.
|
|
1804
1688
|
*/
|
|
1805
|
-
interface
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
maxFeePerGas: bigint;
|
|
1812
|
-
maxPriorityFeePerGas: bigint;
|
|
1813
|
-
}>;
|
|
1814
|
-
/** Sign, without sending, a transaction from the payer's account. */
|
|
1815
|
-
signTransaction(transaction: never): Promise<Hex>;
|
|
1816
|
-
/** Send a contract call from the payer's account. */
|
|
1817
|
-
writeContract(params: never): Promise<Hex>;
|
|
1818
|
-
waitForTransactionReceipt(params: {
|
|
1819
|
-
hash: Hex;
|
|
1820
|
-
}): Promise<{
|
|
1821
|
-
status: string;
|
|
1822
|
-
}>;
|
|
1689
|
+
interface PlannedOpen {
|
|
1690
|
+
channel: BatchChannel;
|
|
1691
|
+
/** The deposit the open locks: what the payer records as pending. */
|
|
1692
|
+
deposit: bigint;
|
|
1693
|
+
/** Send the open. A throw leaves it pending unless it is a definite refusal. */
|
|
1694
|
+
land(): Promise<void>;
|
|
1823
1695
|
}
|
|
1824
|
-
/**
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
/** How much of `token` Permit2 may move for `owner`. */
|
|
1834
|
-
declare function permit2Allowance(reader: ContractReader, token: string, owner: string): Promise<bigint>;
|
|
1835
|
-
/**
|
|
1836
|
-
* `owner`'s EIP-2612 nonce on `token`, or `undefined` when the token has no
|
|
1837
|
-
* `nonces(address)` — and so, for this purpose, no permit.
|
|
1838
|
-
*/
|
|
1839
|
-
declare function eip2612Nonce(reader: ContractReader, token: string, owner: string): Promise<bigint | undefined>;
|
|
1840
|
-
/**
|
|
1841
|
-
* The extensions a facilitator's `GET /supported` advertises. `fetchImpl` defaults
|
|
1842
|
-
* to the global `fetch`, the clearnet behaviour for a direct caller; the client
|
|
1843
|
-
* always passes its own.
|
|
1844
|
-
*/
|
|
1845
|
-
declare function facilitatorExtensions(facilitatorUrl: string, fetchImpl?: typeof fetch): Promise<string[]>;
|
|
1846
|
-
/** `paymentPayload.extensions`, as a facilitator reads them. */
|
|
1847
|
-
type DepositExtensions = Record<string, {
|
|
1848
|
-
info: Record<string, unknown>;
|
|
1849
|
-
}>;
|
|
1850
|
-
/**
|
|
1851
|
-
* An EIP-2612 permit letting Permit2 move `amount` of the token, for the
|
|
1852
|
-
* facilitator to fold into the deposit (`eip2612GasSponsoring`).
|
|
1853
|
-
*/
|
|
1854
|
-
declare function signEip2612GasSponsoring(params: {
|
|
1855
|
-
payer: TypedDataSigner;
|
|
1856
|
-
token: string;
|
|
1857
|
-
/** The token's own EIP-712 domain. */
|
|
1858
|
-
name: string;
|
|
1859
|
-
version: string;
|
|
1860
|
-
chainId: number;
|
|
1861
|
-
nonce: bigint;
|
|
1696
|
+
/** What a charge, a deposit and the running total come to. */
|
|
1697
|
+
interface OpenAmounts {
|
|
1698
|
+
/** The deposit the client is configured to lock. */
|
|
1699
|
+
deposit: bigint;
|
|
1700
|
+
/** The charge of the packet the channel is opened for (`1` for an open on request). */
|
|
1701
|
+
charge: bigint;
|
|
1702
|
+
}
|
|
1703
|
+
interface TopUpAmounts {
|
|
1704
|
+
/** How much more to deposit. */
|
|
1862
1705
|
amount: bigint;
|
|
1863
|
-
/** The
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
* to fund and broadcast (`erc20ApprovalGasSponsoring`).
|
|
1869
|
-
*/
|
|
1870
|
-
declare function signErc20ApprovalGasSponsoring(params: {
|
|
1871
|
-
payerAddress: string;
|
|
1872
|
-
wallet: Pick<EvmWalletAccess, 'getTransactionCount' | 'estimateFeesPerGas' | 'signTransaction'>;
|
|
1873
|
-
token: string;
|
|
1874
|
-
chainId: number;
|
|
1875
|
-
}): Promise<DepositExtensions>;
|
|
1876
|
-
/**
|
|
1877
|
-
* Approve Permit2 for `token`, for the maximum, from the payer's own ETH.
|
|
1878
|
-
*
|
|
1879
|
-
* With `seen`, it also waits until the RPC shows the allowance: a public RPC is
|
|
1880
|
-
* load-balanced, and a receipt from one backend says nothing about the next.
|
|
1881
|
-
* On Base Sepolia, a deposit estimated straight after the receipt reverted
|
|
1882
|
-
* `TRANSFER_FROM_FAILED` (#695).
|
|
1883
|
-
*/
|
|
1884
|
-
declare function approvePermit2(wallet: EvmWalletAccess, token: string, seen?: {
|
|
1885
|
-
reader: ContractReader;
|
|
1886
|
-
owner: string;
|
|
1887
|
-
atLeast: bigint;
|
|
1888
|
-
}): Promise<Hex>;
|
|
1889
|
-
/** `collectorData` for the ERC-3009 deposit collector. */
|
|
1890
|
-
declare function erc3009CollectorData(payload: Eip3009DepositPayload): Hex;
|
|
1891
|
-
/**
|
|
1892
|
-
* `collectorData` for the Permit2 deposit collector, optionally carrying an
|
|
1893
|
-
* EIP-2612 permit for Permit2 (`eip2612PermitData`, else empty).
|
|
1894
|
-
*/
|
|
1895
|
-
declare function permit2CollectorData(payload: Permit2DepositPayload, eip2612PermitData?: Hex): Hex;
|
|
1896
|
-
/** An EIP-2612 permit as the Permit2 collector reads it. */
|
|
1897
|
-
declare function eip2612PermitData(info: {
|
|
1898
|
-
amount: string;
|
|
1899
|
-
deadline: string;
|
|
1900
|
-
signature: string;
|
|
1901
|
-
}): Hex;
|
|
1706
|
+
/** The running cumulative the deposit's voucher carries. */
|
|
1707
|
+
voucherAmount: bigint;
|
|
1708
|
+
/** The charge of the packet it is for (`1` for a top-up on request). */
|
|
1709
|
+
charge: bigint;
|
|
1710
|
+
}
|
|
1902
1711
|
/**
|
|
1903
|
-
*
|
|
1904
|
-
*
|
|
1712
|
+
* How a network covers a charge its channel's deposit cannot (ADR 0003):
|
|
1713
|
+
* `top-up` deposits more into the same channel; `replace` opens a fresh one
|
|
1714
|
+
* and archives the old, and refuses a top-up with `noTopUp`.
|
|
1905
1715
|
*/
|
|
1906
|
-
|
|
1716
|
+
type Cover = {
|
|
1717
|
+
kind: 'top-up';
|
|
1718
|
+
/** Deposit more into `channel`, carrying the voucher for `voucherAmount`. */
|
|
1719
|
+
deposit(channel: BatchChannel, terms: BatchSettlementTerms, amounts: TopUpAmounts): Promise<void>;
|
|
1720
|
+
} | {
|
|
1721
|
+
kind: 'replace';
|
|
1722
|
+
noTopUp: string;
|
|
1723
|
+
};
|
|
1724
|
+
interface SettlementNetwork {
|
|
1725
|
+
/** The kind of chain, which labels a voucher and names a missing key. */
|
|
1726
|
+
readonly chain: BatchChannel['chain'];
|
|
1727
|
+
/** Whether this adapter pays on `network`, a CAIP-2 id. */
|
|
1728
|
+
serves(network: string): boolean;
|
|
1729
|
+
/** Build a channel to the connector from its `terms`, ready to be recorded and sent. */
|
|
1730
|
+
open(terms: BatchSettlementTerms, amounts: OpenAmounts): Promise<PlannedOpen>;
|
|
1731
|
+
readonly cover: Cover;
|
|
1732
|
+
/**
|
|
1733
|
+
* What the chain holds for `channel`: its escrow (`undefined` when there is
|
|
1734
|
+
* no such channel yet), and what has landed — a floor under the connector's
|
|
1735
|
+
* watermark.
|
|
1736
|
+
*/
|
|
1737
|
+
read(channel: BatchChannel): Promise<{
|
|
1738
|
+
escrow: bigint | undefined;
|
|
1739
|
+
landed: bigint;
|
|
1740
|
+
}>;
|
|
1741
|
+
/** The voucher scheme: sign `cumulative` on `channel`, as the claim a packet carries. */
|
|
1742
|
+
voucher(channel: BatchChannel, cumulative: bigint): Promise<Record<string, unknown>>;
|
|
1743
|
+
/**
|
|
1744
|
+
* The voucher scheme's claim-state challenge for `channel`, signed by its
|
|
1745
|
+
* voucher signer (ADR 0075).
|
|
1746
|
+
*/
|
|
1747
|
+
challenge(channel: BatchChannel, expires: bigint): Promise<Record<string, unknown>>;
|
|
1748
|
+
}
|
|
1749
|
+
/** The adapter that pays on `network`, or `undefined` when this client holds none. */
|
|
1750
|
+
declare function settlementNetworkFor(networks: readonly SettlementNetwork[], network: string): SettlementNetwork | undefined;
|
|
1907
1751
|
|
|
1908
1752
|
/**
|
|
1909
1753
|
* Paying a connector from an x402 `batch-settlement` channel: the one object
|
|
1910
1754
|
* {@link ../../client/send.js!send} asks for a voucher — the only way this
|
|
1911
1755
|
* client pays (connector ADRs 0074, 0075; toon-client#689, #690, #692).
|
|
1912
1756
|
*
|
|
1913
|
-
*
|
|
1757
|
+
* The payer is chain-blind. Everything chain-specific — opening, covering,
|
|
1758
|
+
* reading the chain, and the voucher scheme — is the
|
|
1759
|
+
* {@link SettlementNetwork}'s for the channel's network. For each paid packet it:
|
|
1914
1760
|
*
|
|
1915
1761
|
* 1. finds the node's `batch-settlement` terms on the chain this client pays
|
|
1916
1762
|
* from — none, and it steps aside: the node cannot be paid there;
|
|
1917
1763
|
* 2. resolves the channel it holds with this node there — settling any
|
|
1918
1764
|
* deposit whose answer was lost, and rebuilding a lost or doubtful
|
|
1919
|
-
* watermark from the chain and the connector's `claim-state` — or
|
|
1920
|
-
*
|
|
1921
|
-
* 3.
|
|
1922
|
-
*
|
|
1765
|
+
* watermark from the chain and the connector's `claim-state` — or has the
|
|
1766
|
+
* network open one;
|
|
1767
|
+
* 3. covers a charge the channel's deposit cannot: the network tops it up,
|
|
1768
|
+
* or the payer replaces it with a fresh one (ADR 0003);
|
|
1923
1769
|
* 4. reserves the next cumulative amount — persisted before anything is
|
|
1924
|
-
* signed — and
|
|
1770
|
+
* signed — and has the network's voucher scheme sign it;
|
|
1925
1771
|
* 5. hands back the claim, and learns the packet's fate from the caller.
|
|
1926
1772
|
*
|
|
1927
1773
|
* **Nothing leaves before it is recorded.** A deposit or sponsored open is
|
|
@@ -1962,54 +1808,11 @@ interface BatchSettlementPayerConfig {
|
|
|
1962
1808
|
manager: BatchChannelManager;
|
|
1963
1809
|
/** Atomic units deposited on onboarding, and again on each top-up. */
|
|
1964
1810
|
deposit: bigint;
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
/**
|
|
1971
|
-
* The x402 facilitator that relays deposits and pays their gas. Defaults
|
|
1972
|
-
* to the devnet's own on Base Sepolia (`defaultFacilitatorFor`).
|
|
1973
|
-
*/
|
|
1974
|
-
facilitatorUrl?: string;
|
|
1975
|
-
/**
|
|
1976
|
-
* How a deposit moves the token: `eip3009` for a token with ERC-3009,
|
|
1977
|
-
* `permit2` for any other ERC-20. Defaults to what the connector's offer
|
|
1978
|
-
* names (`assetTransferMethod`), and to `eip3009` when it names nothing.
|
|
1979
|
-
*/
|
|
1980
|
-
depositMethod?: 'eip3009' | 'permit2';
|
|
1981
|
-
/**
|
|
1982
|
-
* Who pays a deposit's gas, and a Permit2 token's one-time approval's:
|
|
1983
|
-
*
|
|
1984
|
-
* - `auto` (the default): the facilitator, when there is one and it will;
|
|
1985
|
-
* otherwise the payer, when it holds ETH;
|
|
1986
|
-
* - `facilitator`: only ever the facilitator — the payer's ETH is never
|
|
1987
|
-
* spent;
|
|
1988
|
-
* - `self`: always the payer, and no facilitator is contacted at all.
|
|
1989
|
-
*/
|
|
1990
|
-
depositGas?: 'auto' | 'facilitator' | 'self';
|
|
1991
|
-
/**
|
|
1992
|
-
* The payer's own chain access: what a self-paid deposit or approval, and
|
|
1993
|
-
* an approval the facilitator sponsors, are signed and sent with. Without
|
|
1994
|
-
* it the payer can only use a facilitator, and only for tokens it needs no
|
|
1995
|
-
* approval for.
|
|
1996
|
-
*/
|
|
1997
|
-
wallet?: EvmWalletAccess;
|
|
1998
|
-
/**
|
|
1999
|
-
* Reads the escrow back, to settle a deposit whose answer was lost and to
|
|
2000
|
-
* rebuild a lost watermark. Without one, either of those is an error
|
|
2001
|
-
* rather than a guess.
|
|
2002
|
-
*/
|
|
2003
|
-
reader?: ContractReader;
|
|
2004
|
-
};
|
|
2005
|
-
solana?: {
|
|
2006
|
-
/** The funding wallet; also the channel's `authorized_signer`, which signs vouchers. */
|
|
2007
|
-
signer: Signer;
|
|
2008
|
-
/** The Solana JSON-RPC to read the slot, the blockhash and the accounts from. */
|
|
2009
|
-
rpc: SolanaRpcTarget;
|
|
2010
|
-
};
|
|
2011
|
-
/** How the connector's sponsor endpoint and the facilitator are reached. */
|
|
2012
|
-
fetch: typeof fetch;
|
|
1811
|
+
/**
|
|
1812
|
+
* The settlement networks this client pays on, one per network: each opens,
|
|
1813
|
+
* covers, reads and signs for its own channels.
|
|
1814
|
+
*/
|
|
1815
|
+
networks: readonly SettlementNetwork[];
|
|
2013
1816
|
/**
|
|
2014
1817
|
* The connector's own watermark for a channel (`POST /ilp/claim-state`),
|
|
2015
1818
|
* asked with the voucher challenge this payer signs. It recovers a lost
|
|
@@ -2062,13 +1865,16 @@ declare class BatchSettlementPayer {
|
|
|
2062
1865
|
*/
|
|
2063
1866
|
open(description: NodeSelfDescription, chain: 'evm' | 'solana'): Promise<BatchChannel | undefined>;
|
|
2064
1867
|
/**
|
|
2065
|
-
* Deposit `amount` more into the
|
|
2066
|
-
*
|
|
2067
|
-
*
|
|
1868
|
+
* Deposit `amount` more into the channel this client pays the node from, on a
|
|
1869
|
+
* network that tops channels up. One that replaces them instead (Solana's,
|
|
1870
|
+
* whose sponsor opens channels and nothing else) refuses.
|
|
2068
1871
|
*/
|
|
2069
1872
|
topUp(description: NodeSelfDescription, chain: 'evm' | 'solana', amount: bigint): Promise<BatchChannel>;
|
|
2070
|
-
|
|
2071
|
-
|
|
1873
|
+
/**
|
|
1874
|
+
* The channel to pay a packet charging `charge` from: the live one, covered
|
|
1875
|
+
* if its deposit falls short, or a fresh one.
|
|
1876
|
+
*/
|
|
1877
|
+
private channelFor;
|
|
2072
1878
|
/**
|
|
2073
1879
|
* The channel this client pays the node from on `network` in `asset`, once
|
|
2074
1880
|
* any deposit whose answer was lost is settled and any lost watermark is
|
|
@@ -2089,49 +1895,19 @@ declare class BatchSettlementPayer {
|
|
|
2089
1895
|
challenge(channel: BatchChannel, expires: bigint): Promise<Record<string, unknown>>;
|
|
2090
1896
|
/** Settle a pending deposit against the chain: kept if it landed, dropped if not. */
|
|
2091
1897
|
private reconcile;
|
|
2092
|
-
/**
|
|
2093
|
-
* What the chain holds for `channel`: its escrow (`undefined` when there is
|
|
2094
|
-
* no such channel yet), and what has landed — a floor under the connector's
|
|
2095
|
-
* watermark.
|
|
2096
|
-
*/
|
|
2097
|
-
private readChain;
|
|
2098
1898
|
/** Run one onboarding per network and asset at a time; concurrent callers share it. */
|
|
2099
1899
|
private onboard;
|
|
2100
|
-
private voucher;
|
|
2101
1900
|
/**
|
|
2102
|
-
*
|
|
2103
|
-
*
|
|
2104
|
-
* very same voucher (ADR 0074 prerequisite 1).
|
|
1901
|
+
* Have `network` build a channel, record it as pending, then send it: kept
|
|
1902
|
+
* pending if the answer is lost, forgotten only on a definite refusal.
|
|
2105
1903
|
*/
|
|
2106
|
-
private
|
|
1904
|
+
private openThrough;
|
|
2107
1905
|
/** Deposit `amount` more into `channel`, carrying the running cumulative `voucherAmount`. */
|
|
2108
|
-
private
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
*/
|
|
2114
|
-
private evmSettle;
|
|
2115
|
-
/**
|
|
2116
|
-
* One of x402's gas-sponsoring extensions for a Permit2 approval, when the
|
|
2117
|
-
* facilitator offers one this token can use; `undefined` otherwise.
|
|
2118
|
-
*/
|
|
2119
|
-
private sponsoredApproval;
|
|
2120
|
-
/** Refuse, naming what would work, unless the payer holds ETH to pay `what` with. */
|
|
2121
|
-
private payOwnGas;
|
|
2122
|
-
private requireReader;
|
|
2123
|
-
private requireWallet;
|
|
2124
|
-
/**
|
|
2125
|
-
* Open a channel the receiving connector sponsors: the connector pays the fee
|
|
2126
|
-
* and the rent, and the payer needs no SOL at all.
|
|
2127
|
-
*
|
|
2128
|
-
* The sponsor key is the one THIS connector published — the offer is read off
|
|
2129
|
-
* its own `GET /ilp` — so the refusal of any other sponsor that
|
|
2130
|
-
* {@link buildSponsoredOpen} enforces holds by construction here.
|
|
2131
|
-
*/
|
|
2132
|
-
private solanaOnboard;
|
|
2133
|
-
private requireEvm;
|
|
2134
|
-
private requireSolana;
|
|
1906
|
+
private deposit;
|
|
1907
|
+
private voucher;
|
|
1908
|
+
/** The settlement network for `network`, or a refusal naming the key this client lacks. */
|
|
1909
|
+
private network;
|
|
1910
|
+
private networkOf;
|
|
2135
1911
|
/** Refuse an open, top-up or replacement a packet needs, when that is not its to do. */
|
|
2136
1912
|
private assertMayOpen;
|
|
2137
1913
|
}
|
|
@@ -4577,6 +4353,196 @@ declare function buildResponseMeta(parts: {
|
|
|
4577
4353
|
*/
|
|
4578
4354
|
declare function decodeBase64Text(value: string): string | undefined;
|
|
4579
4355
|
|
|
4356
|
+
/**
|
|
4357
|
+
* ILP-over-HTTP (RFC-0035) transport for the TOON client — the `POST /ilp`
|
|
4358
|
+
* carriage of `client-edge-spec.md` §1.1.
|
|
4359
|
+
*
|
|
4360
|
+
* The connector serves this and BTP on the same port. This adapter does
|
|
4361
|
+
* stateless one-shot writes over HTTP and can upgrade to a duplex BTP session
|
|
4362
|
+
* when a client needs to receive server-initiated packets.
|
|
4363
|
+
*
|
|
4364
|
+
* Wire contract:
|
|
4365
|
+
* - One-shot write: `POST /ilp`
|
|
4366
|
+
* body: OER-encoded ILP PREPARE (`application/octet-stream`), in
|
|
4367
|
+
* TOON's own dialect (ADR 0063), not RFC-0027's bytes.
|
|
4368
|
+
* header: `ILP-Payment-Channel-Claim: base64(JSON of the claim)` — the
|
|
4369
|
+
* SAME claim JSON the BTP path attaches as the
|
|
4370
|
+
* `payment-channel-claim` protocolData entry, raw (§1.3, §1.9).
|
|
4371
|
+
* optional: `ILP-Peer-Id` + `Authorization: Bearer <secret>` identity —
|
|
4372
|
+
* sent as a PAIR or not at all (issue #565), since the connector
|
|
4373
|
+
* 401s a presented id it cannot authenticate.
|
|
4374
|
+
* response: `200 OK` with an OER FULFILL or REJECT body — an ILP-level
|
|
4375
|
+
* outcome is ALWAYS 200. A non-2xx is a transport-level failure
|
|
4376
|
+
* and never carries an OER body: 400 undecodable, 401 a
|
|
4377
|
+
* presented identity that failed to authenticate, 402 terms
|
|
4378
|
+
* instead of work, 413 over 2 MiB.
|
|
4379
|
+
* beside the packet: `toon-accumulated-cost`, `toon-claim-ack` and
|
|
4380
|
+
* `payment-required` response headers — see
|
|
4381
|
+
* {@link readResponseMeta}, and `../ilp/response-meta.js` for
|
|
4382
|
+
* why they are not part of the packet encoding.
|
|
4383
|
+
* - Upgrade to BTP: standard HTTP `Upgrade` with `Sec-WebSocket-Protocol: btp`
|
|
4384
|
+
* plus the same `ILP-Peer-Id` + `Authorization` headers. The connector
|
|
4385
|
+
* pre-authenticates the BTP session from those headers (continuity), so
|
|
4386
|
+
* after `101` we send BTP frames WITHOUT a separate in-band auth frame.
|
|
4387
|
+
* Omitting the auth headers falls back to the normal BTP auth-frame flow.
|
|
4388
|
+
*
|
|
4389
|
+
* Reuses `serializeIlpPrepare`/`deserializeIlpPacket` from `btp/protocol.ts` —
|
|
4390
|
+
* the SAME OER codec the BTP path uses. Claim signing/construction is owned by
|
|
4391
|
+
* the caller; this transport never builds or signs claims.
|
|
4392
|
+
*
|
|
4393
|
+
* **What this no longer does.** Up to 0.x a `401` or a `requiredTransport`
|
|
4394
|
+
* `402` was caught here and re-thrown as "retry this over BTP", because the
|
|
4395
|
+
* only way to learn a route's carriage was to be refused over the wrong one.
|
|
4396
|
+
* 1.0 reads the node's own self-description first and picks a carriage from it
|
|
4397
|
+
* (`../btp/transport-select.js`), so that fallback is gone: a `401` is an
|
|
4398
|
+
* ordinary transport error again, and a `402` is terms — thrown as
|
|
4399
|
+
* {@link PaymentRequiredError} carrying them.
|
|
4400
|
+
*/
|
|
4401
|
+
|
|
4402
|
+
/** Header carrying the base64(JSON) payment-channel claim. */
|
|
4403
|
+
declare const ILP_CLAIM_HEADER = "ILP-Payment-Channel-Claim";
|
|
4404
|
+
/** Header carrying the peer identity. */
|
|
4405
|
+
declare const ILP_PEER_ID_HEADER = "ILP-Peer-Id";
|
|
4406
|
+
/** Anything a response's headers can be handed over as. */
|
|
4407
|
+
type ResponseHeaderSource = Headers | Iterable<readonly [string, string]> | Record<string, string>;
|
|
4408
|
+
/**
|
|
4409
|
+
* Read the three facts that ride BESIDE the answer packet off an HTTP
|
|
4410
|
+
* response's headers (`client-edge-spec.md` §1.6, and connector
|
|
4411
|
+
* `connector_btp::CARRIAGE_NAMES` for the header/protocolData pairing).
|
|
4412
|
+
*
|
|
4413
|
+
* The BTP twin is `BtpRuntimeClient`'s `readResponseMeta(protocolData)`, and
|
|
4414
|
+
* the two MUST agree: the connector's vector set pins each value's two
|
|
4415
|
+
* spellings as a pair (`peer_carriage.reject_with_cost` carries
|
|
4416
|
+
* `toon-accumulated-cost: "4200"` as a header and the same `4200` as a
|
|
4417
|
+
* protocolData entry). Both funnel into the one decoder each in
|
|
4418
|
+
* `../ilp/response-meta.js`; the only thing this side adds is stripping the
|
|
4419
|
+
* base64 layer off the two JSON-valued headers, which is a header artefact and
|
|
4420
|
+
* nothing else.
|
|
4421
|
+
*
|
|
4422
|
+
* Header names are matched case-insensitively (RFC 9110); the canonical
|
|
4423
|
+
* lower-case spellings are the ones the vectors pin.
|
|
4424
|
+
*
|
|
4425
|
+
* Exported because the wire-vector replay reads a vector's `http_headers`
|
|
4426
|
+
* array straight into it — the same function the live transport uses, so a
|
|
4427
|
+
* vector cannot pass while the transport disagrees with it.
|
|
4428
|
+
*/
|
|
4429
|
+
declare function readResponseMeta$1(headers: ResponseHeaderSource): IlpResponseMeta;
|
|
4430
|
+
interface HttpIlpClientConfig {
|
|
4431
|
+
/** The peer's `POST /ilp` URL (the `httpEndpoint` from discovery). */
|
|
4432
|
+
httpEndpoint: string;
|
|
4433
|
+
/**
|
|
4434
|
+
* Where `httpEndpoint` came from, so a network failure can say so. Omit when
|
|
4435
|
+
* the caller supplied it.
|
|
4436
|
+
*/
|
|
4437
|
+
endpointSource?: EndpointSource;
|
|
4438
|
+
/**
|
|
4439
|
+
* Optional peer identity. With no `peerId`/`authToken` the connector treats
|
|
4440
|
+
* the request as an anonymous no-auth peer (permissionless default) and
|
|
4441
|
+
* derives an ephemeral id from the claim signer.
|
|
4442
|
+
*
|
|
4443
|
+
* NOTE (issue #565): this is only PRESENTED on the wire when an `authToken`
|
|
4444
|
+
* accompanies it — see {@link HttpIlpClient.authHeaders}.
|
|
4445
|
+
*/
|
|
4446
|
+
peerId?: string;
|
|
4447
|
+
/** Bearer secret for `Authorization`. Omit for the no-auth peer path. */
|
|
4448
|
+
authToken?: string;
|
|
4449
|
+
/** Request timeout in milliseconds (default: 30000). */
|
|
4450
|
+
timeout?: number;
|
|
4451
|
+
/** Max retry attempts for transport-level network failures (default: 3). */
|
|
4452
|
+
maxRetries?: number;
|
|
4453
|
+
/** Initial retry delay in milliseconds (default: 1000). */
|
|
4454
|
+
retryDelay?: number;
|
|
4455
|
+
/** Custom fetch implementation (for testing / custom transports). */
|
|
4456
|
+
httpClient?: typeof fetch;
|
|
4457
|
+
}
|
|
4458
|
+
/**
|
|
4459
|
+
* Stateless ILP-over-HTTP transport implementing `IlpClient`.
|
|
4460
|
+
*
|
|
4461
|
+
* Use this for pure one-shot consumers (publish-and-forget writes). When the
|
|
4462
|
+
* client needs a duplex session — to receive server-initiated packets or to act
|
|
4463
|
+
* as a peer — use `BtpRuntimeClient`.
|
|
4464
|
+
*/
|
|
4465
|
+
declare class HttpIlpClient implements IlpClient {
|
|
4466
|
+
private readonly httpEndpoint;
|
|
4467
|
+
private readonly endpointSource;
|
|
4468
|
+
private readonly peerId;
|
|
4469
|
+
private readonly authToken;
|
|
4470
|
+
private readonly timeout;
|
|
4471
|
+
private readonly retryConfig;
|
|
4472
|
+
private readonly httpClient;
|
|
4473
|
+
constructor(config: HttpIlpClientConfig);
|
|
4474
|
+
/**
|
|
4475
|
+
* The client edge this transport pays — the origin `GET /ilp/identity` and
|
|
4476
|
+
* `GET /ilp/routes/price` hang off (`ConnectorEdgeClient` normalizes the
|
|
4477
|
+
* trailing `/ilp` away). Exposed because a sealed write must ask the
|
|
4478
|
+
* connector it is ACTUALLY paying for its key, not a configured guess.
|
|
4479
|
+
*/
|
|
4480
|
+
get clientEdgeEndpoint(): string;
|
|
4481
|
+
/**
|
|
4482
|
+
* Send an ILP PREPARE via `POST /ilp` WITHOUT a claim. The connector accepts
|
|
4483
|
+
* this only on free/zero-amount routes; paid writes must use
|
|
4484
|
+
* {@link sendIlpPacketWithClaim}. Satisfies the IlpClient interface.
|
|
4485
|
+
*
|
|
4486
|
+
* `params` may carry an `expectedFulfillment` (the sender's end-to-end
|
|
4487
|
+
* check, ADR 0069), a `greeting` flag and an explicit `expiresAt`. With an
|
|
4488
|
+
* expected fulfilment the FULFILL preimage is compared against it and a
|
|
4489
|
+
* mismatch is surfaced as a failed result — see {@link mapIlpResponse}.
|
|
4490
|
+
*/
|
|
4491
|
+
sendIlpPacket(params: IlpSendParams): Promise<IlpSendResult>;
|
|
4492
|
+
/**
|
|
4493
|
+
* Send an ILP PREPARE via `POST /ilp` with the payment-channel claim attached
|
|
4494
|
+
* as the `ILP-Payment-Channel-Claim` header. `claim` is the SAME JSON object
|
|
4495
|
+
* the BTP path attaches as the `payment-channel-claim` protocolData entry —
|
|
4496
|
+
* we base64(JSON.stringify(claim)) it, byte-for-byte identical to BTP.
|
|
4497
|
+
*
|
|
4498
|
+
* `expectedFulfillment` / `greeting` / `expiresAt` semantics are identical
|
|
4499
|
+
* to {@link sendIlpPacket}.
|
|
4500
|
+
*/
|
|
4501
|
+
sendIlpPacketWithClaim(params: IlpSendParams, claim: unknown): Promise<IlpSendResult>;
|
|
4502
|
+
/**
|
|
4503
|
+
* The identity headers to present, if any.
|
|
4504
|
+
*
|
|
4505
|
+
* A peer id and its bearer secret are ONE credential, so both are sent or
|
|
4506
|
+
* neither is (issue #565). Presenting a `peerId` this client cannot back
|
|
4507
|
+
* with a secret is strictly WORSE than presenting nothing: the connector's
|
|
4508
|
+
* client edge resolves a PRESENTED identity first and answers `401` before
|
|
4509
|
+
* it ever looks at the route
|
|
4510
|
+
* (connector `crates/connector-client-edge/src/lib.rs`, whose own comment
|
|
4511
|
+
* reads "A request presenting no `ILP-Peer-Id` is unaffected here — it is
|
|
4512
|
+
* anonymous, resolved once the claim (if any) has been admitted"), whereas
|
|
4513
|
+
* anonymous + a valid payment-channel claim is the supported permissionless
|
|
4514
|
+
* path. The live devnet daemon shipped `ILP-Peer-Id: g.toon.client` with an
|
|
4515
|
+
* EMPTY token — an id no connector has a registration for — so every default
|
|
4516
|
+
* paid write over `POST /ilp` 401'd before the claim was read at all.
|
|
4517
|
+
*
|
|
4518
|
+
* An empty-string token is not a credential; `''` is falsy here on purpose.
|
|
4519
|
+
*
|
|
4520
|
+
* This REMOVES the 401 rather than recovering from it, which is why 1.0 can
|
|
4521
|
+
* drop the "a 401 means retry over BTP" fallback entirely: anonymous + a
|
|
4522
|
+
* valid claim is the supported permissionless path, so a 401 now means a
|
|
4523
|
+
* genuinely misconfigured credential and is surfaced as the transport error
|
|
4524
|
+
* it is.
|
|
4525
|
+
*/
|
|
4526
|
+
private authHeaders;
|
|
4527
|
+
/**
|
|
4528
|
+
* Single attempt: serialize the PREPARE, POST it, and map the response.
|
|
4529
|
+
* @throws {NetworkError} On connection/timeout failures (retried).
|
|
4530
|
+
* @throws {ConnectorError} On non-retryable transport errors (5xx / unexpected).
|
|
4531
|
+
*/
|
|
4532
|
+
private postPrepare;
|
|
4533
|
+
/**
|
|
4534
|
+
* Map a `200 OK` body (OER FULFILL/REJECT) to an IlpSendResult; map a non-2xx
|
|
4535
|
+
* to a transport error. Per the wire contract, ILP-level rejects arrive as a
|
|
4536
|
+
* 200 + REJECT body — only HTTP non-2xx means a transport-layer failure.
|
|
4537
|
+
*
|
|
4538
|
+
* When `expectedFulfillment` is given the FULFILL preimage is compared
|
|
4539
|
+
* against it; a mismatch yields `accepted: false` (shared `mapIlpResponse`
|
|
4540
|
+
* logic, identical to the BTP path).
|
|
4541
|
+
*/
|
|
4542
|
+
private mapResponse;
|
|
4543
|
+
private mapTransportError;
|
|
4544
|
+
}
|
|
4545
|
+
|
|
4580
4546
|
/**
|
|
4581
4547
|
* Isomorphic BTP client — works in both browser and Node.js.
|
|
4582
4548
|
* Uses native WebSocket (browser) or globalThis.WebSocket (Node 21+).
|
|
@@ -4815,7 +4781,7 @@ interface BtpRuntimeClientConfig {
|
|
|
4815
4781
|
* separate answers to separate questions and are never inferred from each
|
|
4816
4782
|
* other.
|
|
4817
4783
|
*/
|
|
4818
|
-
declare function readResponseMeta
|
|
4784
|
+
declare function readResponseMeta(protocolData: BTPProtocolData[]): IlpResponseMeta;
|
|
4819
4785
|
/**
|
|
4820
4786
|
* BTP transport implementing IlpClient.
|
|
4821
4787
|
* Uses IsomorphicBtpClient (browser-native, no Node.js dependencies).
|
|
@@ -4863,14 +4829,6 @@ declare class BtpRuntimeClient implements IlpClient {
|
|
|
4863
4829
|
* to {@link sendIlpPacket}.
|
|
4864
4830
|
*/
|
|
4865
4831
|
sendIlpPacketWithClaim(params: IlpSendParams, claim: Record<string, unknown>): Promise<IlpSendResult>;
|
|
4866
|
-
/**
|
|
4867
|
-
* Send a standalone `payment-channel-claim` BTP MESSAGE (no ILP packet
|
|
4868
|
-
* attached). The connector's ClaimReceiver consumes this fire-and-forget
|
|
4869
|
-
* to register cumulative claim state independently of the per-packet
|
|
4870
|
-
* forwarding path. Auto-reconnects on connection errors.
|
|
4871
|
-
*/
|
|
4872
|
-
sendClaimMessage(claim: Record<string, unknown>): Promise<void>;
|
|
4873
|
-
private _sendClaimMessageOnce;
|
|
4874
4832
|
/**
|
|
4875
4833
|
* Build the ILP PREPARE for a send, applying the
|
|
4876
4834
|
* explicit expiry when provided, carrying the `greeting` flag ADR 0069 put
|
|
@@ -4885,228 +4843,9 @@ declare class BtpRuntimeClient implements IlpClient {
|
|
|
4885
4843
|
private _sendIlpPacketOnce;
|
|
4886
4844
|
/**
|
|
4887
4845
|
* Single-attempt claim + ILP packet send. Reconnects if not connected.
|
|
4888
|
-
*/
|
|
4889
|
-
private _sendIlpPacketWithClaimOnce;
|
|
4890
|
-
}
|
|
4891
|
-
|
|
4892
|
-
/**
|
|
4893
|
-
* ILP-over-HTTP (RFC-0035) transport for the TOON client — the `POST /ilp`
|
|
4894
|
-
* carriage of `client-edge-spec.md` §1.1.
|
|
4895
|
-
*
|
|
4896
|
-
* The connector serves this and BTP on the same port. This adapter does
|
|
4897
|
-
* stateless one-shot writes over HTTP and can upgrade to a duplex BTP session
|
|
4898
|
-
* when a client needs to receive server-initiated packets.
|
|
4899
|
-
*
|
|
4900
|
-
* Wire contract:
|
|
4901
|
-
* - One-shot write: `POST /ilp`
|
|
4902
|
-
* body: OER-encoded ILP PREPARE (`application/octet-stream`), in
|
|
4903
|
-
* TOON's own dialect (ADR 0063), not RFC-0027's bytes.
|
|
4904
|
-
* header: `ILP-Payment-Channel-Claim: base64(JSON of the claim)` — the
|
|
4905
|
-
* SAME claim JSON the BTP path attaches as the
|
|
4906
|
-
* `payment-channel-claim` protocolData entry, raw (§1.3, §1.9).
|
|
4907
|
-
* optional: `ILP-Peer-Id` + `Authorization: Bearer <secret>` identity —
|
|
4908
|
-
* sent as a PAIR or not at all (issue #565), since the connector
|
|
4909
|
-
* 401s a presented id it cannot authenticate.
|
|
4910
|
-
* response: `200 OK` with an OER FULFILL or REJECT body — an ILP-level
|
|
4911
|
-
* outcome is ALWAYS 200. A non-2xx is a transport-level failure
|
|
4912
|
-
* and never carries an OER body: 400 undecodable, 401 a
|
|
4913
|
-
* presented identity that failed to authenticate, 402 terms
|
|
4914
|
-
* instead of work, 413 over 2 MiB.
|
|
4915
|
-
* beside the packet: `toon-accumulated-cost`, `toon-claim-ack` and
|
|
4916
|
-
* `payment-required` response headers — see
|
|
4917
|
-
* {@link readResponseMeta}, and `../ilp/response-meta.js` for
|
|
4918
|
-
* why they are not part of the packet encoding.
|
|
4919
|
-
* - Upgrade to BTP: standard HTTP `Upgrade` with `Sec-WebSocket-Protocol: btp`
|
|
4920
|
-
* plus the same `ILP-Peer-Id` + `Authorization` headers. The connector
|
|
4921
|
-
* pre-authenticates the BTP session from those headers (continuity), so
|
|
4922
|
-
* after `101` we send BTP frames WITHOUT a separate in-band auth frame.
|
|
4923
|
-
* Omitting the auth headers falls back to the normal BTP auth-frame flow.
|
|
4924
|
-
*
|
|
4925
|
-
* Reuses `serializeIlpPrepare`/`deserializeIlpPacket` from `btp/protocol.ts` —
|
|
4926
|
-
* the SAME OER codec the BTP path uses. Claim signing/construction is owned by
|
|
4927
|
-
* the caller; this transport never builds or signs claims.
|
|
4928
|
-
*
|
|
4929
|
-
* **What this no longer does.** Up to 0.x a `401` or a `requiredTransport`
|
|
4930
|
-
* `402` was caught here and re-thrown as "retry this over BTP", because the
|
|
4931
|
-
* only way to learn a route's carriage was to be refused over the wrong one.
|
|
4932
|
-
* 1.0 reads the node's own self-description first and picks a carriage from it
|
|
4933
|
-
* (`../btp/transport-select.js`), so that fallback is gone: a `401` is an
|
|
4934
|
-
* ordinary transport error again, and a `402` is terms — thrown as
|
|
4935
|
-
* {@link PaymentRequiredError} carrying them.
|
|
4936
|
-
*/
|
|
4937
|
-
|
|
4938
|
-
/** Header carrying the base64(JSON) payment-channel claim. */
|
|
4939
|
-
declare const ILP_CLAIM_HEADER = "ILP-Payment-Channel-Claim";
|
|
4940
|
-
/** Header carrying the peer identity. */
|
|
4941
|
-
declare const ILP_PEER_ID_HEADER = "ILP-Peer-Id";
|
|
4942
|
-
/** Anything a response's headers can be handed over as. */
|
|
4943
|
-
type ResponseHeaderSource = Headers | Iterable<readonly [string, string]> | Record<string, string>;
|
|
4944
|
-
/**
|
|
4945
|
-
* Read the three facts that ride BESIDE the answer packet off an HTTP
|
|
4946
|
-
* response's headers (`client-edge-spec.md` §1.6, and connector
|
|
4947
|
-
* `connector_btp::CARRIAGE_NAMES` for the header/protocolData pairing).
|
|
4948
|
-
*
|
|
4949
|
-
* The BTP twin is `BtpRuntimeClient`'s `readResponseMeta(protocolData)`, and
|
|
4950
|
-
* the two MUST agree: the connector's vector set pins each value's two
|
|
4951
|
-
* spellings as a pair (`peer_carriage.reject_with_cost` carries
|
|
4952
|
-
* `toon-accumulated-cost: "4200"` as a header and the same `4200` as a
|
|
4953
|
-
* protocolData entry). Both funnel into the one decoder each in
|
|
4954
|
-
* `../ilp/response-meta.js`; the only thing this side adds is stripping the
|
|
4955
|
-
* base64 layer off the two JSON-valued headers, which is a header artefact and
|
|
4956
|
-
* nothing else.
|
|
4957
|
-
*
|
|
4958
|
-
* Header names are matched case-insensitively (RFC 9110); the canonical
|
|
4959
|
-
* lower-case spellings are the ones the vectors pin.
|
|
4960
|
-
*
|
|
4961
|
-
* Exported because the wire-vector replay reads a vector's `http_headers`
|
|
4962
|
-
* array straight into it — the same function the live transport uses, so a
|
|
4963
|
-
* vector cannot pass while the transport disagrees with it.
|
|
4964
|
-
*/
|
|
4965
|
-
declare function readResponseMeta(headers: ResponseHeaderSource): IlpResponseMeta;
|
|
4966
|
-
interface HttpIlpClientConfig {
|
|
4967
|
-
/** The peer's `POST /ilp` URL (the `httpEndpoint` from discovery). */
|
|
4968
|
-
httpEndpoint: string;
|
|
4969
|
-
/**
|
|
4970
|
-
* Where `httpEndpoint` came from, so a network failure can say so. Omit when
|
|
4971
|
-
* the caller supplied it.
|
|
4972
|
-
*/
|
|
4973
|
-
endpointSource?: EndpointSource;
|
|
4974
|
-
/**
|
|
4975
|
-
* Optional peer identity. With no `peerId`/`authToken` the connector treats
|
|
4976
|
-
* the request as an anonymous no-auth peer (permissionless default) and
|
|
4977
|
-
* derives an ephemeral id from the claim signer.
|
|
4978
|
-
*
|
|
4979
|
-
* NOTE (issue #565): this is only PRESENTED on the wire when an `authToken`
|
|
4980
|
-
* accompanies it — see {@link HttpIlpClient.authHeaders}. It is still used
|
|
4981
|
-
* as the BTP auth-frame id on the {@link HttpIlpClient.upgradeToBtp} path.
|
|
4982
|
-
*/
|
|
4983
|
-
peerId?: string;
|
|
4984
|
-
/** Bearer secret for `Authorization`. Omit for the no-auth peer path. */
|
|
4985
|
-
authToken?: string;
|
|
4986
|
-
/** Request timeout in milliseconds (default: 30000). */
|
|
4987
|
-
timeout?: number;
|
|
4988
|
-
/** Max retry attempts for transport-level network failures (default: 3). */
|
|
4989
|
-
maxRetries?: number;
|
|
4990
|
-
/** Initial retry delay in milliseconds (default: 1000). */
|
|
4991
|
-
retryDelay?: number;
|
|
4992
|
-
/** Custom fetch implementation (for testing / custom transports). */
|
|
4993
|
-
httpClient?: typeof fetch;
|
|
4994
|
-
/**
|
|
4995
|
-
* Custom WebSocket constructor for the BTP upgrade path (for testing /
|
|
4996
|
-
* custom transports). Forwarded to the underlying BtpRuntimeClient.
|
|
4997
|
-
*/
|
|
4998
|
-
createWebSocket?: (url: string) => WebSocket;
|
|
4999
|
-
}
|
|
5000
|
-
/**
|
|
5001
|
-
* Stateless ILP-over-HTTP transport implementing `IlpClient`.
|
|
5002
|
-
*
|
|
5003
|
-
* Use this for pure one-shot consumers (publish-and-forget writes). When the
|
|
5004
|
-
* client needs a duplex session — to receive server-initiated packets or to act
|
|
5005
|
-
* as a peer — call {@link upgradeToBtp} to obtain a connected BtpRuntimeClient
|
|
5006
|
-
* that reuses the existing BTP code path.
|
|
5007
|
-
*/
|
|
5008
|
-
declare class HttpIlpClient implements IlpClient {
|
|
5009
|
-
private readonly httpEndpoint;
|
|
5010
|
-
private readonly endpointSource;
|
|
5011
|
-
private readonly peerId;
|
|
5012
|
-
private readonly authToken;
|
|
5013
|
-
private readonly timeout;
|
|
5014
|
-
private readonly retryConfig;
|
|
5015
|
-
private readonly httpClient;
|
|
5016
|
-
private readonly createWebSocket;
|
|
5017
|
-
constructor(config: HttpIlpClientConfig);
|
|
5018
|
-
/**
|
|
5019
|
-
* The client edge this transport pays — the origin `GET /ilp/identity` and
|
|
5020
|
-
* `GET /ilp/routes/price` hang off (`ConnectorEdgeClient` normalizes the
|
|
5021
|
-
* trailing `/ilp` away). Exposed because a sealed write must ask the
|
|
5022
|
-
* connector it is ACTUALLY paying for its key, not a configured guess.
|
|
5023
|
-
*/
|
|
5024
|
-
get clientEdgeEndpoint(): string;
|
|
5025
|
-
/**
|
|
5026
|
-
* Send an ILP PREPARE via `POST /ilp` WITHOUT a claim. The connector accepts
|
|
5027
|
-
* this only on free/zero-amount routes; paid writes must use
|
|
5028
|
-
* {@link sendIlpPacketWithClaim}. Satisfies the IlpClient interface.
|
|
5029
|
-
*
|
|
5030
|
-
* `params` may carry an `expectedFulfillment` (the sender's end-to-end
|
|
5031
|
-
* check, ADR 0069), a `greeting` flag and an explicit `expiresAt`. With an
|
|
5032
|
-
* expected fulfilment the FULFILL preimage is compared against it and a
|
|
5033
|
-
* mismatch is surfaced as a failed result — see {@link mapIlpResponse}.
|
|
5034
|
-
*/
|
|
5035
|
-
sendIlpPacket(params: IlpSendParams): Promise<IlpSendResult>;
|
|
5036
|
-
/**
|
|
5037
|
-
* Send an ILP PREPARE via `POST /ilp` with the payment-channel claim attached
|
|
5038
|
-
* as the `ILP-Payment-Channel-Claim` header. `claim` is the SAME JSON object
|
|
5039
|
-
* the BTP path attaches as the `payment-channel-claim` protocolData entry —
|
|
5040
|
-
* we base64(JSON.stringify(claim)) it, byte-for-byte identical to BTP.
|
|
5041
|
-
*
|
|
5042
|
-
* `expectedFulfillment` / `greeting` / `expiresAt` semantics are identical
|
|
5043
|
-
* to {@link sendIlpPacket}.
|
|
5044
|
-
*/
|
|
5045
|
-
sendIlpPacketWithClaim(params: IlpSendParams, claim: unknown): Promise<IlpSendResult>;
|
|
5046
|
-
/**
|
|
5047
|
-
* Upgrade to a duplex BTP session over the SAME endpoint.
|
|
5048
|
-
*
|
|
5049
|
-
* Derives the `ws(s)://` URL from `httpEndpoint`, opens a WebSocket with
|
|
5050
|
-
* `Sec-WebSocket-Protocol: btp` and the same `ILP-Peer-Id` + `Authorization`
|
|
5051
|
-
* headers, and returns a connected {@link BtpRuntimeClient}. When auth headers
|
|
5052
|
-
* are present the connector pre-authenticates the session (no in-band auth
|
|
5053
|
-
* frame); without them the BtpRuntimeClient falls back to the normal BTP
|
|
5054
|
-
* auth-frame flow.
|
|
5055
|
-
*
|
|
5056
|
-
* NOTE: passing per-connection headers + a subprotocol to a WebSocket is
|
|
5057
|
-
* Node-only (the `ws` package). Browsers cannot set arbitrary request headers
|
|
5058
|
-
* on a WebSocket handshake, so a browser consumer must use the gateway
|
|
5059
|
-
* transport or BTP-with-auth-frame instead.
|
|
5060
|
-
*/
|
|
5061
|
-
upgradeToBtp(): Promise<BtpRuntimeClient>;
|
|
5062
|
-
/**
|
|
5063
|
-
* The identity headers to present, if any.
|
|
5064
|
-
*
|
|
5065
|
-
* A peer id and its bearer secret are ONE credential, so both are sent or
|
|
5066
|
-
* neither is (issue #565). Presenting a `peerId` this client cannot back
|
|
5067
|
-
* with a secret is strictly WORSE than presenting nothing: the connector's
|
|
5068
|
-
* client edge resolves a PRESENTED identity first and answers `401` before
|
|
5069
|
-
* it ever looks at the route
|
|
5070
|
-
* (connector `crates/connector-client-edge/src/lib.rs`, whose own comment
|
|
5071
|
-
* reads "A request presenting no `ILP-Peer-Id` is unaffected here — it is
|
|
5072
|
-
* anonymous, resolved once the claim (if any) has been admitted"), whereas
|
|
5073
|
-
* anonymous + a valid payment-channel claim is the supported permissionless
|
|
5074
|
-
* path. The live devnet daemon shipped `ILP-Peer-Id: g.toon.client` with an
|
|
5075
|
-
* EMPTY token — an id no connector has a registration for — so every default
|
|
5076
|
-
* paid write over `POST /ilp` 401'd before the claim was read at all.
|
|
5077
|
-
*
|
|
5078
|
-
* An empty-string token is not a credential; `''` is falsy here on purpose.
|
|
5079
|
-
*
|
|
5080
|
-
* This REMOVES the 401 rather than recovering from it, which is why 1.0 can
|
|
5081
|
-
* drop the "a 401 means retry over BTP" fallback entirely: anonymous + a
|
|
5082
|
-
* valid claim is the supported permissionless path, so a 401 now means a
|
|
5083
|
-
* genuinely misconfigured credential and is surfaced as the transport error
|
|
5084
|
-
* it is.
|
|
5085
|
-
*/
|
|
5086
|
-
private authHeaders;
|
|
5087
|
-
/**
|
|
5088
|
-
* Single attempt: serialize the PREPARE, POST it, and map the response.
|
|
5089
|
-
* @throws {NetworkError} On connection/timeout failures (retried).
|
|
5090
|
-
* @throws {ConnectorError} On non-retryable transport errors (5xx / unexpected).
|
|
5091
|
-
*/
|
|
5092
|
-
private postPrepare;
|
|
5093
|
-
/**
|
|
5094
|
-
* Map a `200 OK` body (OER FULFILL/REJECT) to an IlpSendResult; map a non-2xx
|
|
5095
|
-
* to a transport error. Per the wire contract, ILP-level rejects arrive as a
|
|
5096
|
-
* 200 + REJECT body — only HTTP non-2xx means a transport-layer failure.
|
|
5097
|
-
*
|
|
5098
|
-
* When `expectedFulfillment` is given the FULFILL preimage is compared
|
|
5099
|
-
* against it; a mismatch yields `accepted: false` (shared `mapIlpResponse`
|
|
5100
|
-
* logic, identical to the BTP path).
|
|
5101
|
-
*/
|
|
5102
|
-
private mapResponse;
|
|
5103
|
-
private mapTransportError;
|
|
4846
|
+
*/
|
|
4847
|
+
private _sendIlpPacketWithClaimOnce;
|
|
5104
4848
|
}
|
|
5105
|
-
/**
|
|
5106
|
-
* Derive the BTP WebSocket URL from a `POST /ilp` HTTP endpoint. The connector
|
|
5107
|
-
* serves BTP on the SAME path, so we only swap the scheme (http→ws, https→wss).
|
|
5108
|
-
*/
|
|
5109
|
-
declare function httpEndpointToBtpUrl(httpEndpoint: string): string;
|
|
5110
4849
|
|
|
5111
4850
|
/**
|
|
5112
4851
|
* Persistent, strictly-ordered BTP transport for paid writes (issue #482).
|
|
@@ -5141,8 +4880,7 @@ declare function httpEndpointToBtpUrl(httpEndpoint: string): string;
|
|
|
5141
4880
|
* ─── What it adds over a bare `BtpRuntimeClient` ────────────────────────
|
|
5142
4881
|
* - **Persistent session**: the underlying session is connected once,
|
|
5143
4882
|
* lazily, on the first write, and stays open across every subsequent
|
|
5144
|
-
* write.
|
|
5145
|
-
* send one packet, immediately disconnect) — the whole point is to reuse
|
|
4883
|
+
* write. The whole point is to reuse
|
|
5146
4884
|
* one ordered socket across a burst.
|
|
5147
4885
|
* - **Strictly ordered dispatch**: every `sendIlpPacketWithClaim` call is
|
|
5148
4886
|
* appended to a FIFO queue; the next call is not dispatched onto the wire
|
|
@@ -6059,6 +5797,351 @@ declare function solanaVoucherClaim(voucher: SvmBatchVoucher, signer: string, en
|
|
|
6059
5797
|
*/
|
|
6060
5798
|
declare function nextVoucherAmount(signedSoFar: bigint, charge: bigint): bigint | undefined;
|
|
6061
5799
|
|
|
5800
|
+
/**
|
|
5801
|
+
* Who pays the gas for a deposit into an x402 `batch-settlement` channel on
|
|
5802
|
+
* EVM, and how (connector ADR 0074; toon-client#695).
|
|
5803
|
+
*
|
|
5804
|
+
* The contract's `deposit(config, amount, collector, collectorData)` is
|
|
5805
|
+
* callable by anyone: the payer's one signature — an ERC-3009 authorization or
|
|
5806
|
+
* a Permit2 witness transfer — binds the deposit to its channel. So the same
|
|
5807
|
+
* signed payload can be put on chain two ways:
|
|
5808
|
+
*
|
|
5809
|
+
* - **by a facilitator**, which pays the gas (`facilitator.ts`); or
|
|
5810
|
+
* - **by the payer itself**, from its own ETH ({@link depositDirectly}).
|
|
5811
|
+
*
|
|
5812
|
+
* Both spend the one authorization, and its nonce is single-use on chain — the
|
|
5813
|
+
* ERC-3009 nonce is `keccak256(channelId, salt)`, a Permit2 nonce is
|
|
5814
|
+
* unordered and random — so a direct deposit after a facilitator's answer was
|
|
5815
|
+
* lost can never land twice: whichever arrives second reverts.
|
|
5816
|
+
*
|
|
5817
|
+
* A token without ERC-3009 deposits through Permit2, which first needs the
|
|
5818
|
+
* payer's `approve(Permit2, …)`. That approval is gas too, and x402 defines
|
|
5819
|
+
* two extensions for a facilitator to cover it:
|
|
5820
|
+
*
|
|
5821
|
+
* - `eip2612GasSponsoring`, for a token with an EIP-2612 permit: the payer
|
|
5822
|
+
* signs a permit for Permit2 and the facilitator folds it into the deposit;
|
|
5823
|
+
* - `erc20ApprovalGasSponsoring`, for a token with neither: the payer signs
|
|
5824
|
+
* the `approve` transaction without sending it, and the facilitator funds
|
|
5825
|
+
* its gas and broadcasts it before the deposit.
|
|
5826
|
+
*
|
|
5827
|
+
* A payer holding ETH can instead send the approval itself
|
|
5828
|
+
* ({@link approvePermit2}). The encodings below are x402's own
|
|
5829
|
+
* (`@x402/evm` 2.27.0, `batch-settlement/encoding.ts` and
|
|
5830
|
+
* `shared/extensions`), so a facilitator and a direct deposit read the same
|
|
5831
|
+
* bytes.
|
|
5832
|
+
*/
|
|
5833
|
+
|
|
5834
|
+
declare const EIP2612_GAS_SPONSORING = "eip2612GasSponsoring";
|
|
5835
|
+
declare const ERC20_APPROVAL_GAS_SPONSORING = "erc20ApprovalGasSponsoring";
|
|
5836
|
+
/** `x402BatchSettlement.deposit`. */
|
|
5837
|
+
declare const X402_BATCH_SETTLEMENT_DEPOSIT_ABI: readonly [{
|
|
5838
|
+
readonly type: "function";
|
|
5839
|
+
readonly name: "deposit";
|
|
5840
|
+
readonly stateMutability: "nonpayable";
|
|
5841
|
+
readonly inputs: readonly [{
|
|
5842
|
+
readonly name: "config";
|
|
5843
|
+
readonly type: "tuple";
|
|
5844
|
+
readonly components: readonly [{
|
|
5845
|
+
readonly name: "payer";
|
|
5846
|
+
readonly type: "address";
|
|
5847
|
+
}, {
|
|
5848
|
+
readonly name: "payerAuthorizer";
|
|
5849
|
+
readonly type: "address";
|
|
5850
|
+
}, {
|
|
5851
|
+
readonly name: "receiver";
|
|
5852
|
+
readonly type: "address";
|
|
5853
|
+
}, {
|
|
5854
|
+
readonly name: "receiverAuthorizer";
|
|
5855
|
+
readonly type: "address";
|
|
5856
|
+
}, {
|
|
5857
|
+
readonly name: "token";
|
|
5858
|
+
readonly type: "address";
|
|
5859
|
+
}, {
|
|
5860
|
+
readonly name: "withdrawDelay";
|
|
5861
|
+
readonly type: "uint40";
|
|
5862
|
+
}, {
|
|
5863
|
+
readonly name: "salt";
|
|
5864
|
+
readonly type: "bytes32";
|
|
5865
|
+
}];
|
|
5866
|
+
}, {
|
|
5867
|
+
readonly name: "amount";
|
|
5868
|
+
readonly type: "uint128";
|
|
5869
|
+
}, {
|
|
5870
|
+
readonly name: "collector";
|
|
5871
|
+
readonly type: "address";
|
|
5872
|
+
}, {
|
|
5873
|
+
readonly name: "collectorData";
|
|
5874
|
+
readonly type: "bytes";
|
|
5875
|
+
}];
|
|
5876
|
+
readonly outputs: readonly [];
|
|
5877
|
+
}];
|
|
5878
|
+
/**
|
|
5879
|
+
* What paying gas from the payer's own wallet needs of the chain, bound to the
|
|
5880
|
+
* payer's account. A viem wallet client extended with public actions provides
|
|
5881
|
+
* all of it; `ToonClient` builds one lazily.
|
|
5882
|
+
*/
|
|
5883
|
+
interface EvmWalletAccess {
|
|
5884
|
+
/** The payer's native balance, wei. */
|
|
5885
|
+
getBalance(): Promise<bigint>;
|
|
5886
|
+
/** The payer's next transaction nonce. */
|
|
5887
|
+
getTransactionCount(): Promise<number>;
|
|
5888
|
+
estimateFeesPerGas(): Promise<{
|
|
5889
|
+
maxFeePerGas: bigint;
|
|
5890
|
+
maxPriorityFeePerGas: bigint;
|
|
5891
|
+
}>;
|
|
5892
|
+
/** Sign, without sending, a transaction from the payer's account. */
|
|
5893
|
+
signTransaction(transaction: never): Promise<Hex>;
|
|
5894
|
+
/** Send a contract call from the payer's account. */
|
|
5895
|
+
writeContract(params: never): Promise<Hex>;
|
|
5896
|
+
waitForTransactionReceipt(params: {
|
|
5897
|
+
hash: Hex;
|
|
5898
|
+
}): Promise<{
|
|
5899
|
+
status: string;
|
|
5900
|
+
}>;
|
|
5901
|
+
}
|
|
5902
|
+
/**
|
|
5903
|
+
* {@link EvmWalletAccess} for `account` over `rpcUrl`, on whichever chain the
|
|
5904
|
+
* RPC reports. Nothing connects until it is first used.
|
|
5905
|
+
*/
|
|
5906
|
+
declare function evmWalletAccess(params: {
|
|
5907
|
+
/** The route chain RPC takes, with the fetch it dials through. */
|
|
5908
|
+
rpc: ChainRpcRoute;
|
|
5909
|
+
account: LocalAccount;
|
|
5910
|
+
}): EvmWalletAccess;
|
|
5911
|
+
/** How much of `token` Permit2 may move for `owner`. */
|
|
5912
|
+
declare function permit2Allowance(reader: ContractReader, token: string, owner: string): Promise<bigint>;
|
|
5913
|
+
/**
|
|
5914
|
+
* `owner`'s EIP-2612 nonce on `token`, or `undefined` when the token has no
|
|
5915
|
+
* `nonces(address)` — and so, for this purpose, no permit.
|
|
5916
|
+
*/
|
|
5917
|
+
declare function eip2612Nonce(reader: ContractReader, token: string, owner: string): Promise<bigint | undefined>;
|
|
5918
|
+
/**
|
|
5919
|
+
* The extensions a facilitator's `GET /supported` advertises. `fetchImpl` defaults
|
|
5920
|
+
* to the global `fetch`, the clearnet behaviour for a direct caller; the client
|
|
5921
|
+
* always passes its own.
|
|
5922
|
+
*/
|
|
5923
|
+
declare function facilitatorExtensions(facilitatorUrl: string, fetchImpl?: typeof fetch): Promise<string[]>;
|
|
5924
|
+
/** `paymentPayload.extensions`, as a facilitator reads them. */
|
|
5925
|
+
type DepositExtensions = Record<string, {
|
|
5926
|
+
info: Record<string, unknown>;
|
|
5927
|
+
}>;
|
|
5928
|
+
/**
|
|
5929
|
+
* An EIP-2612 permit letting Permit2 move `amount` of the token, for the
|
|
5930
|
+
* facilitator to fold into the deposit (`eip2612GasSponsoring`).
|
|
5931
|
+
*/
|
|
5932
|
+
declare function signEip2612GasSponsoring(params: {
|
|
5933
|
+
payer: TypedDataSigner;
|
|
5934
|
+
token: string;
|
|
5935
|
+
/** The token's own EIP-712 domain. */
|
|
5936
|
+
name: string;
|
|
5937
|
+
version: string;
|
|
5938
|
+
chainId: number;
|
|
5939
|
+
nonce: bigint;
|
|
5940
|
+
amount: bigint;
|
|
5941
|
+
/** The Permit2 authorization's own deadline, unix seconds. */
|
|
5942
|
+
deadline: string;
|
|
5943
|
+
}): Promise<DepositExtensions>;
|
|
5944
|
+
/**
|
|
5945
|
+
* The payer's signed-but-unsent `approve(Permit2, max)`, for the facilitator
|
|
5946
|
+
* to fund and broadcast (`erc20ApprovalGasSponsoring`).
|
|
5947
|
+
*/
|
|
5948
|
+
declare function signErc20ApprovalGasSponsoring(params: {
|
|
5949
|
+
payerAddress: string;
|
|
5950
|
+
wallet: Pick<EvmWalletAccess, 'getTransactionCount' | 'estimateFeesPerGas' | 'signTransaction'>;
|
|
5951
|
+
token: string;
|
|
5952
|
+
chainId: number;
|
|
5953
|
+
}): Promise<DepositExtensions>;
|
|
5954
|
+
/**
|
|
5955
|
+
* Approve Permit2 for `token`, for the maximum, from the payer's own ETH.
|
|
5956
|
+
*
|
|
5957
|
+
* With `seen`, it also waits until the RPC shows the allowance: a public RPC is
|
|
5958
|
+
* load-balanced, and a receipt from one backend says nothing about the next.
|
|
5959
|
+
* On Base Sepolia, a deposit estimated straight after the receipt reverted
|
|
5960
|
+
* `TRANSFER_FROM_FAILED` (#695).
|
|
5961
|
+
*/
|
|
5962
|
+
declare function approvePermit2(wallet: EvmWalletAccess, token: string, seen?: {
|
|
5963
|
+
reader: ContractReader;
|
|
5964
|
+
owner: string;
|
|
5965
|
+
atLeast: bigint;
|
|
5966
|
+
}): Promise<Hex>;
|
|
5967
|
+
/** `collectorData` for the ERC-3009 deposit collector. */
|
|
5968
|
+
declare function erc3009CollectorData(payload: Eip3009DepositPayload): Hex;
|
|
5969
|
+
/**
|
|
5970
|
+
* `collectorData` for the Permit2 deposit collector, optionally carrying an
|
|
5971
|
+
* EIP-2612 permit for Permit2 (`eip2612PermitData`, else empty).
|
|
5972
|
+
*/
|
|
5973
|
+
declare function permit2CollectorData(payload: Permit2DepositPayload, eip2612PermitData?: Hex): Hex;
|
|
5974
|
+
/** An EIP-2612 permit as the Permit2 collector reads it. */
|
|
5975
|
+
declare function eip2612PermitData(info: {
|
|
5976
|
+
amount: string;
|
|
5977
|
+
deadline: string;
|
|
5978
|
+
signature: string;
|
|
5979
|
+
}): Hex;
|
|
5980
|
+
/**
|
|
5981
|
+
* Put a signed deposit on chain from the payer's own wallet: the same call a
|
|
5982
|
+
* facilitator makes, with the payer paying the gas.
|
|
5983
|
+
*/
|
|
5984
|
+
declare function depositDirectly(wallet: EvmWalletAccess, payload: BatchDepositPayload<unknown>, method: 'eip3009' | 'permit2'): Promise<Hex>;
|
|
5985
|
+
|
|
5986
|
+
/**
|
|
5987
|
+
* The EVM settlement network: x402's `batch-settlement` contract on an
|
|
5988
|
+
* `eip155:` network (connector ADR 0074; toon-client#689, #695).
|
|
5989
|
+
*
|
|
5990
|
+
* It opens a channel by depositing into it through an x402 facilitator — or
|
|
5991
|
+
* from the payer's own ETH, as `depositGas` and what is available decide —
|
|
5992
|
+
* covers a charge by depositing more into the same channel (ADR 0003), and
|
|
5993
|
+
* reads the escrow back from the contract.
|
|
5994
|
+
*
|
|
5995
|
+
* Its voucher scheme is EIP-712: a voucher signed by the channel's
|
|
5996
|
+
* `payerAuthorizer` over the channel id and the cumulative amount, carried as
|
|
5997
|
+
* {@link evmVoucherClaim}, and the claim-state challenge {@link signEvmChallenge}.
|
|
5998
|
+
*/
|
|
5999
|
+
|
|
6000
|
+
interface EvmSettlementNetworkConfig {
|
|
6001
|
+
/** The funding wallet; also signs vouchers unless `voucherSigner` is set. */
|
|
6002
|
+
account: TypedDataSigner;
|
|
6003
|
+
/** Signs vouchers as the channel's `payerAuthorizer`. */
|
|
6004
|
+
voucherSigner?: TypedDataSigner;
|
|
6005
|
+
/**
|
|
6006
|
+
* The x402 facilitator that relays deposits and pays their gas. Defaults
|
|
6007
|
+
* to the devnet's own on Base Sepolia (`defaultFacilitatorFor`).
|
|
6008
|
+
*/
|
|
6009
|
+
facilitatorUrl?: string;
|
|
6010
|
+
/**
|
|
6011
|
+
* How a deposit moves the token: `eip3009` for a token with ERC-3009,
|
|
6012
|
+
* `permit2` for any other ERC-20. Defaults to what the connector's offer
|
|
6013
|
+
* names (`assetTransferMethod`), and to `eip3009` when it names nothing.
|
|
6014
|
+
*/
|
|
6015
|
+
depositMethod?: 'eip3009' | 'permit2';
|
|
6016
|
+
/**
|
|
6017
|
+
* Who pays a deposit's gas, and a Permit2 token's one-time approval's:
|
|
6018
|
+
*
|
|
6019
|
+
* - `auto` (the default): the facilitator, when there is one and it will;
|
|
6020
|
+
* otherwise the payer, when it holds ETH;
|
|
6021
|
+
* - `facilitator`: only ever the facilitator — the payer's ETH is never
|
|
6022
|
+
* spent;
|
|
6023
|
+
* - `self`: always the payer, and no facilitator is contacted at all.
|
|
6024
|
+
*/
|
|
6025
|
+
depositGas?: 'auto' | 'facilitator' | 'self';
|
|
6026
|
+
/**
|
|
6027
|
+
* The payer's own chain access: what a self-paid deposit or approval, and
|
|
6028
|
+
* an approval the facilitator sponsors, are signed and sent with. Without
|
|
6029
|
+
* it the payer can only use a facilitator, and only for tokens it needs no
|
|
6030
|
+
* approval for.
|
|
6031
|
+
*/
|
|
6032
|
+
wallet?: EvmWalletAccess;
|
|
6033
|
+
/**
|
|
6034
|
+
* Reads the escrow back, to settle a deposit whose answer was lost and to
|
|
6035
|
+
* rebuild a lost watermark. Without one, either of those is an error
|
|
6036
|
+
* rather than a guess.
|
|
6037
|
+
*/
|
|
6038
|
+
reader?: ContractReader;
|
|
6039
|
+
/** How the facilitator is reached. */
|
|
6040
|
+
fetch: typeof fetch;
|
|
6041
|
+
}
|
|
6042
|
+
declare class EvmSettlementNetwork implements SettlementNetwork {
|
|
6043
|
+
private readonly config;
|
|
6044
|
+
readonly chain: "evm";
|
|
6045
|
+
readonly cover: Cover;
|
|
6046
|
+
constructor(config: EvmSettlementNetworkConfig);
|
|
6047
|
+
serves(network: string): boolean;
|
|
6048
|
+
/**
|
|
6049
|
+
* A channel opened by depositing into it through the facilitator. The
|
|
6050
|
+
* deposit's own voucher is the first packet's charge, so the first packet can
|
|
6051
|
+
* carry the very same voucher (ADR 0074 prerequisite 1).
|
|
6052
|
+
*/
|
|
6053
|
+
open(terms: BatchSettlementTerms, amounts: OpenAmounts): Promise<PlannedOpen>;
|
|
6054
|
+
read(channel: BatchChannel): Promise<{
|
|
6055
|
+
escrow: bigint | undefined;
|
|
6056
|
+
landed: bigint;
|
|
6057
|
+
}>;
|
|
6058
|
+
voucher(channel: BatchChannel, cumulative: bigint): Promise<Record<string, unknown>>;
|
|
6059
|
+
challenge(channel: BatchChannel, expires: bigint): Promise<Record<string, unknown>>;
|
|
6060
|
+
/** Deposit `amount` more into `channel`, carrying the running cumulative. */
|
|
6061
|
+
private topUp;
|
|
6062
|
+
private get voucherSigner();
|
|
6063
|
+
/** The connector's terms, priced for a charge, as the offer the greeting would carry. */
|
|
6064
|
+
private offer;
|
|
6065
|
+
private evmChannel;
|
|
6066
|
+
/**
|
|
6067
|
+
* Put a deposit of `amount`, carrying the voucher for `voucherAmount`, on
|
|
6068
|
+
* chain — through the facilitator, or from the payer's own ETH, as
|
|
6069
|
+
* `depositGas` and what is available decide (toon-client#695).
|
|
6070
|
+
*/
|
|
6071
|
+
private settle;
|
|
6072
|
+
/**
|
|
6073
|
+
* One of x402's gas-sponsoring extensions for a Permit2 approval, when the
|
|
6074
|
+
* facilitator offers one this token can use; `undefined` otherwise.
|
|
6075
|
+
*/
|
|
6076
|
+
private sponsoredApproval;
|
|
6077
|
+
/** Refuse, naming what would work, unless the payer holds ETH to pay `what` with. */
|
|
6078
|
+
private payOwnGas;
|
|
6079
|
+
private requireReader;
|
|
6080
|
+
private requireWallet;
|
|
6081
|
+
}
|
|
6082
|
+
/**
|
|
6083
|
+
* The EVM settlement network over the client's RPC route. Its reader opens the
|
|
6084
|
+
* RPC on first use, so a client that never reads a channel back opens no
|
|
6085
|
+
* connection.
|
|
6086
|
+
*/
|
|
6087
|
+
declare function evmSettlementNetwork(params: {
|
|
6088
|
+
account: LocalAccount;
|
|
6089
|
+
rpc: ChainRpcRoute;
|
|
6090
|
+
fetch: typeof fetch;
|
|
6091
|
+
facilitatorUrl?: string;
|
|
6092
|
+
depositMethod?: 'eip3009' | 'permit2';
|
|
6093
|
+
depositGas?: 'auto' | 'facilitator' | 'self';
|
|
6094
|
+
}): EvmSettlementNetwork;
|
|
6095
|
+
|
|
6096
|
+
/**
|
|
6097
|
+
* The Solana settlement network: solana-foundation's `payment-channels`
|
|
6098
|
+
* program on a `solana:` network (connector ADR 0074; toon-client#690).
|
|
6099
|
+
*
|
|
6100
|
+
* It opens a channel the receiving connector sponsors — the connector pays the
|
|
6101
|
+
* fee and the rent, and the payer needs no SOL at all — and, because that
|
|
6102
|
+
* sponsor opens channels and nothing else, covers a charge its deposit cannot
|
|
6103
|
+
* by replacing the channel with a fresh sponsored one (ADR 0003).
|
|
6104
|
+
*
|
|
6105
|
+
* Its voucher scheme is ed25519: a voucher signed by the channel's
|
|
6106
|
+
* `authorized_signer` over the channel and the cumulative amount, carried as
|
|
6107
|
+
* {@link solanaVoucherClaim}, and the claim-state challenge
|
|
6108
|
+
* {@link signSolanaChallenge}.
|
|
6109
|
+
*/
|
|
6110
|
+
|
|
6111
|
+
interface SolanaSettlementNetworkConfig {
|
|
6112
|
+
/** The funding wallet; also the channel's `authorized_signer`, which signs vouchers. */
|
|
6113
|
+
signer: Signer;
|
|
6114
|
+
/** The Solana JSON-RPC to read the slot, the blockhash and the accounts from. */
|
|
6115
|
+
rpc: SolanaRpcTarget;
|
|
6116
|
+
/** How the connector's sponsor endpoint is reached. */
|
|
6117
|
+
fetch: typeof fetch;
|
|
6118
|
+
/** The connector's client-edge URL, which a relative sponsor endpoint resolves against. */
|
|
6119
|
+
connector: string;
|
|
6120
|
+
}
|
|
6121
|
+
declare class SolanaSettlementNetwork implements SettlementNetwork {
|
|
6122
|
+
private readonly config;
|
|
6123
|
+
readonly chain: "solana";
|
|
6124
|
+
readonly cover: Cover;
|
|
6125
|
+
constructor(config: SolanaSettlementNetworkConfig);
|
|
6126
|
+
serves(network: string): boolean;
|
|
6127
|
+
/**
|
|
6128
|
+
* A channel the receiving connector sponsors.
|
|
6129
|
+
*
|
|
6130
|
+
* The sponsor key is the one THIS connector published — the terms are read
|
|
6131
|
+
* off its own `GET /ilp` — so the refusal of any other sponsor that
|
|
6132
|
+
* {@link buildSponsoredOpen} enforces holds by construction here.
|
|
6133
|
+
*/
|
|
6134
|
+
open(terms: BatchSettlementTerms, amounts: OpenAmounts): Promise<PlannedOpen>;
|
|
6135
|
+
read(channel: BatchChannel): Promise<{
|
|
6136
|
+
escrow: bigint | undefined;
|
|
6137
|
+
landed: bigint;
|
|
6138
|
+
}>;
|
|
6139
|
+
voucher(channel: BatchChannel, cumulative: bigint): Promise<Record<string, unknown>>;
|
|
6140
|
+
challenge(channel: BatchChannel, expires: bigint): Promise<Record<string, unknown>>;
|
|
6141
|
+
/** The connector's terms, priced for a charge, as the offer the greeting would carry. */
|
|
6142
|
+
private offer;
|
|
6143
|
+
}
|
|
6144
|
+
|
|
6062
6145
|
/**
|
|
6063
6146
|
* Asking the receiving connector to sponsor a Solana `open` (connector ADR 0074
|
|
6064
6147
|
* decision 9; connector #1346).
|
|
@@ -7128,4 +7211,4 @@ interface RetryOptions {
|
|
|
7128
7211
|
*/
|
|
7129
7212
|
declare function withRetry<T>(operation: () => Promise<T>, options: RetryOptions): Promise<T>;
|
|
7130
7213
|
|
|
7131
|
-
export { ACCUMULATED_COST_HEADER, ACCUMULATED_COST_PROTOCOL, ARNS_KIND, type AntSpawnOutcome, type AntSpawnParams, type AntSpawnRefused, type AntSpawnStep, type AntSpawned, type ArnsAntPrepareReceipt, type ArnsBuyOutcome, type ArnsBuyParams, type ArnsBuyReceipt, type ArnsNameType, type ArnsNameWithAntOutcome, type ArnsNetwork, type BTPMessage, BTPMessageType, type BTPProtocolData, type BatchChannel, type BatchChannelConfig, BatchChannelManager, type BatchChannelSummary, type BatchDepositPayload, type BatchExitResult, type BatchSettlementBinding, type BatchSettlementEvmOffer, type BatchSettlementOffer, BatchSettlementPayer, type BatchSettlementPayerConfig, type BatchSettlementSvmOffer, type BatchSettlementTerms, type BatchVoucher, BeforePayRefusedError, BtpAuthError, type BtpChannelDeclaration, BtpConnectionError, type BtpPacketResponse, BtpPaidWriteTransport, type BtpPaidWriteTransportConfig, BtpRuntimeClient, type BtpRuntimeClientConfig, CHANNEL_CHALLENGE_MAX_LIFETIME_SECONDS, CLAIM_ACK_HEADER, CLAIM_ACK_PROTOCOL, CLAIM_REJECT_REASONS, CONNECTOR_MAX_TIMEOUT_SECONDS, type CarriageEndpoints, ChainKind, type ChainRpcRoute, ChainUnavailableError, type
|
|
7214
|
+
export { ACCUMULATED_COST_HEADER, ACCUMULATED_COST_PROTOCOL, ARNS_KIND, type AntSpawnOutcome, type AntSpawnParams, type AntSpawnRefused, type AntSpawnStep, type AntSpawned, type ArnsAntPrepareReceipt, type ArnsBuyOutcome, type ArnsBuyParams, type ArnsBuyReceipt, type ArnsNameType, type ArnsNameWithAntOutcome, type ArnsNetwork, type BTPMessage, BTPMessageType, type BTPProtocolData, type BatchChannel, type BatchChannelConfig, BatchChannelManager, type BatchChannelSummary, type BatchDepositPayload, type BatchExitResult, type BatchSettlementBinding, type BatchSettlementEvmOffer, type BatchSettlementOffer, BatchSettlementPayer, type BatchSettlementPayerConfig, type BatchSettlementSvmOffer, type BatchSettlementTerms, type BatchVoucher, BeforePayRefusedError, BtpAuthError, type BtpChannelDeclaration, BtpConnectionError, type BtpPacketResponse, BtpPaidWriteTransport, type BtpPaidWriteTransportConfig, BtpRuntimeClient, type BtpRuntimeClientConfig, CHANNEL_CHALLENGE_MAX_LIFETIME_SECONDS, CLAIM_ACK_HEADER, CLAIM_ACK_PROTOCOL, CLAIM_REJECT_REASONS, CONNECTOR_MAX_TIMEOUT_SECONDS, type CarriageEndpoints, ChainKind, type ChainRpcRoute, ChainUnavailableError, type ChannelFacade, type ChannelFacadeDeps, ChannelFundingError, ChannelNotOpenError, ChannelResumeError, type ChannelState, type ChannelStore, type ChannelStoreEntry, type ClaimAck, type ClaimSendingTransport$1 as ClaimSendingTransport, type ClaimStateFailed, type ClaimStateOk, type ClaimStateRequestEntry, type ClaimStateResult, type ClaimSummary, ClientChannelFacade, ClientWalletFacade, ConfigError, ConnectorEdgeClient, type ConnectorEdgeClientConfig, ConnectorEdgeError, type ConnectorEdgeErrorCode, ConnectorError, type ConnectorIdentity, type ConnectorRoutePrice, type ConnectorRouteTerms, type ContractReader, type Cover, DEFAULT_DEPOSIT, DEFAULT_TIMEOUT_MS, DEVNET, type Decoded, type DepositExtensions, type DeriveIdentityOptions, type DerivedIdentity, type DevnetNode, EIP2612_GAS_SPONSORING, ERC20_APPROVAL_GAS_SPONSORING, ERC3009_DEPOSIT_COLLECTOR_ADDRESS, type EdgeIdentity, type Eip3009DepositPayload, type EncryptedKeystore, type EndpointSource, type Envelope, EnvelopeError, EnvelopeErrorKind, type EnvelopeHeader, type EnvelopeRequest, type EnvelopeResponse, type EvmBatchChannelState, type EvmExitClients, EvmSettlementNetwork, type EvmSettlementNetworkConfig, EvmSigner, type EvmWalletAccess, type ExchangeOutcome, FULFILLMENT_MISMATCH_CODE, FULFILLMENT_MISMATCH_MESSAGE, FacilitatorError, type FaucetChain, type FundWalletOptions, type FundWalletResult, GIFTWRAP_NONCE_LENGTH, GIFTWRAP_PUBLIC_KEY_LENGTH, GIFTWRAP_SECRET_LENGTH, GIFTWRAP_TYPE_REQUEST, GIFTWRAP_TYPE_RESPONSE, type GasStationExecuteReceipt, type GasStationFailureReason, type GasStationFailureReceipt, type GasStationQuoteReceipt, type GasStationReceipt, type GiftWrapEcdh, GiftWrapError, GiftWrapErrorKind, HS_HOSTNAME_MAX_LENGTH, HS_HOSTNAME_REGEX, HttpIlpClient, type HttpIlpClientConfig, type ILPFulfillPacket, ILPPacketType, type ILPPreparePacket, type ILPRejectPacket, type ILPResponsePacket, ILP_CLAIM_HEADER, ILP_PEER_ID_HEADER, type IlpClient, type IlpResponseMeta, type IlpSendParams, type IlpSendResult, type IlpSendResultWithFulfillment, InMemoryChannelStore, InsufficientBalanceError, InvalidAddressError, IsomorphicBtpClient, type JobAnswer, type JobEndpoint, type JobEvent, type JobEventParams, type JobSender, JsonFileChannelStore, KEYSTORE_VERSION, type KeyDerivationScheme, MAX_GRACE_PERIOD_SECONDS, MAX_WITHDRAW_DELAY_SECONDS, MIN_GRACE_PERIOD_SECONDS, MIN_WITHDRAW_DELAY_SECONDS, NetworkError, type NodeSelfDescription, OerError, OerErrorKind, type OpenAmounts, type OpenedKeystore, type OpenedRequest, PACKET_EXPIRY_HEADROOM_MS, PAYMENT_CHANNELS_PROGRAM_ID, PAYMENT_REQUIRED_HEADER, PAYMENT_REQUIRED_PROTOCOL, PERMIT2_ADDRESS, PERMIT2_DEPOSIT_COLLECTOR_ADDRESS, PROXIED_RPC_DEFAULTS, type PaidWriteTransport, type ParsedX402Challenge, PaymentRequiredError, type PaymentTerms, type Permit2DepositPayload, type PlannedOpen, type PreparedVoucher, type ProxiedChainRpc, type ProxiedPath, ProxyBypassError, type RequiredTransport, type ResolvedConfig, type ResolvedIdentity, type ResponseHeaderSource, type RetryOptions, type RouteCharge, RouteNotPricedError, type RoutePrice, type RpcTransportOptions, SOLANA_GAS_KIND, type SealedExchange, type SealedRequest, SealedResponseError, type SealedResponseErrorKind, type SendContext, type SendFulfilled, type SendOptions, type SendRefused, type SendRequest, type SendResult, type SendTransferParams, type SendTransferResult, type SettledDeposit, type SettlementNetwork, type Signer as SolanaKeypair, type SolanaNetwork, SolanaRpcTransportError, SolanaSettlementNetwork, type SolanaSettlementNetworkConfig, type SolanaWireTransaction, SponsorRefusedError, type SponsoredOpen, StaleRpcReadError, type SvmBatchChannelConfig, type SvmBatchChannelState, type SvmBatchVoucher, ToonClient, type ToonClientConfig, ToonClientError, type ToonClientLike, type ToonGreeting, type ToonIdentity, type ToonTermsInfo, type TopUpAmounts, TransactionOutcomeError, type TransferConfig, TransferNotDeliveredError, TransferUnsupportedError, type TransportChoice, type TransportPreference, TransportRequiredError, type TypedDataSigner, UnknownChainError, ValidationError, type VoucherClaimEnvelope, type VoucherOutcome, type VoucherSigner, type WalletBalance, type WalletBalanceSources, type WalletChainBalances, type WalletFacade, type WalletFacadeDeps, type WalletTokenAmount, type WriteKeystoreOptions, X402_BATCH_SETTLEMENT_ADDRESS, X402_BATCH_SETTLEMENT_DEPOSIT_ABI, X402_BATCH_SETTLEMENT_EXIT_ABI, X402_BATCH_SETTLEMENT_READ_ABI, addressFor, approvePermit2, assertRoutableHsHostname, batchChannelId, batchVoucherDigest, buildBatchChannelConfig, buildEip3009Deposit, buildJobEvent, buildPermit2Deposit, buildResponseMeta, buildSponsoredOpen, buildSvmBatchChannelConfig, buildSvmRequestCloseInstruction, buildSvmSealInstruction, buildSvmTopUpInstruction, buildSvmVoucherMessage, buildSvmWithdrawPayerInstruction, buyArnsName, buyArnsNameWithNewAnt, chainUnavailableMessage, chargeFor, chooseBatchSettlement, connectorEdgeBaseUrl, decodeAccumulatedCost, decodeBase64Text, decodeClaimAck, decodeEnvelope, decodeEnvelopeRequest, decodeEnvelopeResponse, decodePaymentRequired, decodeSvmBatchChannel, decodeVarOctetString, decodeVarUint, decryptMnemonic, defaultDestinationFor, defaultFacilitatorFor, defaultFaucetTimeout, defaultRpcUrl, depositDirectly, deriveFulfillment, deriveFullIdentity, describeEndpoint, deserializeIlpPacket, deserializeIlpPrepare, directFetch, eip2612Nonce, eip2612PermitData, encodeEnvelope, encodeEnvelopeRequest, encodeEnvelopeResponse, encodeVarOctetString, encodeVarUint, encryptMnemonic, envelopeHeader, erc3009CollectorData, evmChainIdOf, evmChallengeDigest, evmDerivationPath, evmIdentityFromKey, evmSettlementNetwork, evmVoucherClaim, evmWalletAccess, facilitatorExtensions, finalizeEvmBatchWithdraw, fundWallet, generateKeystore, generateMnemonic, generateRandomIdentity, generateSolanaKeypair, getSvmBatchChannel, giftWrapPublicKey, importKeystore, initiateEvmBatchWithdraw, isGasStationFailure, isHiddenServiceUrl, isInsufficientGasError, isRoutableHsHostname, jobEventParam, keystoreDerivation, loadKeystore, localGiftWrapEcdh, looksLikeSealedResponse, mapIlpResponse, nextVoucherAmount, offerFromTerms, openKeystore, openRequest, openResponse, parseBatchSettlementOffer, parseBatchSettlementTerms, parseBtpMessage, parsePaymentTerms, parseSelfDescription, parseSolanaWireTransaction, parseX402Body, parseX402Challenge, patchSolanaRecentBlockhash, paymentChannelsEventAuthority, permit2Allowance, permit2CollectorData, readBaseUnits, readResponseMeta as readBtpResponseMeta, readEvmBatchChannel, readEvmNativeBalance, readEvmTokenBalance, readExchangeOutcome, readResponseMeta$1 as readResponseMeta, readSolanaNativeBalance, readSolanaTokenBalance, readVoucherRefusal, readWalletBalances, requestSponsoredOpen, requestSvmBatchClose, resolveConfig, resolveExpectedFulfillment, resolveExpiresAt, routeFor, routePriceFor, rpcFetch, rpcTransport, sealExchange, sealRequest, sealRequestWithRandomness, sealResponse, sealResponseWithRandomness, selectTransport, send, sendJob, sendTransfer, serializeBtpMessage, serializeIlpFulfill, serializeIlpPrepare, serializeIlpReject, settleDeposit, settlementNetworkFor, signBatchVoucher, signEip2612GasSponsoring, signErc20ApprovalGasSponsoring, signEvmChallenge, signSolanaChallenge, signSolanaWireTransaction, signSvmVoucher, singleRecipientDistributionHash, solanaChallengeMessage, solanaKeypair, solanaVoucherClaim, spawnAnt, svmBatchChannelAddress, toEnvelopeRequest, trimTrailingSlashes, validateMnemonic, withRetry, withdrawSvmBatchChannel, writeKeystoreFile };
|