@obbyx/x402-obyte 0.0.0-stage → 0.1.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.
Files changed (123) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +65 -2
  3. package/dist/batch/client-store.d.ts +50 -0
  4. package/dist/batch/client-store.d.ts.map +1 -0
  5. package/dist/batch/client-store.js +93 -0
  6. package/dist/batch/client-store.js.map +1 -0
  7. package/dist/batch/client.d.ts +63 -0
  8. package/dist/batch/client.d.ts.map +1 -0
  9. package/dist/batch/client.js +222 -0
  10. package/dist/batch/client.js.map +1 -0
  11. package/dist/batch/facilitator.d.ts +73 -0
  12. package/dist/batch/facilitator.d.ts.map +1 -0
  13. package/dist/batch/facilitator.js +350 -0
  14. package/dist/batch/facilitator.js.map +1 -0
  15. package/dist/batch/gateway.d.ts +19 -0
  16. package/dist/batch/gateway.d.ts.map +1 -0
  17. package/dist/batch/gateway.js +2 -0
  18. package/dist/batch/gateway.js.map +1 -0
  19. package/dist/batch/requirements.d.ts +52 -0
  20. package/dist/batch/requirements.d.ts.map +1 -0
  21. package/dist/batch/requirements.js +80 -0
  22. package/dist/batch/requirements.js.map +1 -0
  23. package/dist/batch/store.d.ts +104 -0
  24. package/dist/batch/store.d.ts.map +1 -0
  25. package/dist/batch/store.js +192 -0
  26. package/dist/batch/store.js.map +1 -0
  27. package/dist/batch/watcher-protocol.d.ts +89 -0
  28. package/dist/batch/watcher-protocol.d.ts.map +1 -0
  29. package/dist/batch/watcher-protocol.js +80 -0
  30. package/dist/batch/watcher-protocol.js.map +1 -0
  31. package/dist/binding/binding.d.ts +32 -0
  32. package/dist/binding/binding.d.ts.map +1 -0
  33. package/dist/binding/binding.js +19 -0
  34. package/dist/binding/binding.js.map +1 -0
  35. package/dist/coins/composer.d.ts +58 -0
  36. package/dist/coins/composer.d.ts.map +1 -0
  37. package/dist/coins/composer.js +102 -0
  38. package/dist/coins/composer.js.map +1 -0
  39. package/dist/coins/index.d.ts +4 -0
  40. package/dist/coins/index.d.ts.map +1 -0
  41. package/dist/coins/index.js +4 -0
  42. package/dist/coins/index.js.map +1 -0
  43. package/dist/coins/reservations.d.ts +37 -0
  44. package/dist/coins/reservations.d.ts.map +1 -0
  45. package/dist/coins/reservations.js +102 -0
  46. package/dist/coins/reservations.js.map +1 -0
  47. package/dist/coins/selection.d.ts +42 -0
  48. package/dist/coins/selection.d.ts.map +1 -0
  49. package/dist/coins/selection.js +60 -0
  50. package/dist/coins/selection.js.map +1 -0
  51. package/dist/exact/client.d.ts +33 -0
  52. package/dist/exact/client.d.ts.map +1 -0
  53. package/dist/exact/client.js +93 -0
  54. package/dist/exact/client.js.map +1 -0
  55. package/dist/exact/facilitator-v1.d.ts +48 -0
  56. package/dist/exact/facilitator-v1.d.ts.map +1 -0
  57. package/dist/exact/facilitator-v1.js +81 -0
  58. package/dist/exact/facilitator-v1.js.map +1 -0
  59. package/dist/exact/facilitator.d.ts +77 -0
  60. package/dist/exact/facilitator.d.ts.map +1 -0
  61. package/dist/exact/facilitator.js +331 -0
  62. package/dist/exact/facilitator.js.map +1 -0
  63. package/dist/exact/finality.d.ts +18 -0
  64. package/dist/exact/finality.d.ts.map +1 -0
  65. package/dist/exact/finality.js +45 -0
  66. package/dist/exact/finality.js.map +1 -0
  67. package/dist/exact/ledger-checks.d.ts +15 -0
  68. package/dist/exact/ledger-checks.d.ts.map +1 -0
  69. package/dist/exact/ledger-checks.js +85 -0
  70. package/dist/exact/ledger-checks.js.map +1 -0
  71. package/dist/exact/reasons.d.ts +29 -0
  72. package/dist/exact/reasons.d.ts.map +1 -0
  73. package/dist/exact/reasons.js +21 -0
  74. package/dist/exact/reasons.js.map +1 -0
  75. package/dist/exact/requirements.d.ts +37 -0
  76. package/dist/exact/requirements.d.ts.map +1 -0
  77. package/dist/exact/requirements.js +80 -0
  78. package/dist/exact/requirements.js.map +1 -0
  79. package/dist/exact/store.d.ts +133 -0
  80. package/dist/exact/store.d.ts.map +1 -0
  81. package/dist/exact/store.js +212 -0
  82. package/dist/exact/store.js.map +1 -0
  83. package/dist/hub/heartbeat.d.ts +12 -0
  84. package/dist/hub/heartbeat.d.ts.map +1 -0
  85. package/dist/hub/heartbeat.js +17 -0
  86. package/dist/hub/heartbeat.js.map +1 -0
  87. package/dist/hub/hub-call.d.ts +20 -0
  88. package/dist/hub/hub-call.d.ts.map +1 -0
  89. package/dist/hub/hub-call.js +30 -0
  90. package/dist/hub/hub-call.js.map +1 -0
  91. package/dist/hub/schemas.d.ts +41 -0
  92. package/dist/hub/schemas.d.ts.map +1 -0
  93. package/dist/hub/schemas.js +71 -0
  94. package/dist/hub/schemas.js.map +1 -0
  95. package/dist/index.d.ts +18 -0
  96. package/dist/index.d.ts.map +1 -0
  97. package/dist/index.js +18 -0
  98. package/dist/index.js.map +1 -0
  99. package/package.json +51 -3
  100. package/src/batch/client-store.ts +167 -0
  101. package/src/batch/client.ts +314 -0
  102. package/src/batch/facilitator.ts +469 -0
  103. package/src/batch/gateway.ts +20 -0
  104. package/src/batch/requirements.ts +108 -0
  105. package/src/batch/store.ts +343 -0
  106. package/src/batch/watcher-protocol.ts +87 -0
  107. package/src/binding/binding.ts +50 -0
  108. package/src/coins/composer.ts +159 -0
  109. package/src/coins/index.ts +9 -0
  110. package/src/coins/reservations.ts +139 -0
  111. package/src/coins/selection.ts +93 -0
  112. package/src/exact/client.ts +144 -0
  113. package/src/exact/facilitator-v1.ts +137 -0
  114. package/src/exact/facilitator.ts +451 -0
  115. package/src/exact/finality.ts +56 -0
  116. package/src/exact/ledger-checks.ts +113 -0
  117. package/src/exact/reasons.ts +25 -0
  118. package/src/exact/requirements.ts +109 -0
  119. package/src/exact/store.ts +391 -0
  120. package/src/hub/heartbeat.ts +18 -0
  121. package/src/hub/hub-call.ts +46 -0
  122. package/src/hub/schemas.ts +89 -0
  123. package/src/index.ts +110 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alexander Ponomarev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,66 @@
1
- # Temporary Holding Version
1
+ # @obbyx/x402-obyte
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [x402](https://x402.org) payment mechanisms for the [Obyte](https://obyte.org)
4
+ network, for the official `@x402/*` packages and for obbyx.
5
+
6
+ - **`exact`** — the client signs one Obyte unit per request; the facilitator verifies and broadcasts it.
7
+ - **`batch-settlement`** — instant, fee-free per call over Obyte AA payment channels (cumulative vouchers).
8
+
9
+ Networks: `obyte:livenet`, `obyte:testnet` (v1: `obyte-livenet`, `obyte-testnet`).
10
+
11
+ ```sh
12
+ npm i @obbyx/x402-obyte obyte @x402/fetch
13
+ ```
14
+
15
+ ## Pay with the official `@x402/fetch`
16
+
17
+ ```ts
18
+ import obyte from 'obyte';
19
+ import { wrapFetchWithPayment, x402Client } from '@x402/fetch';
20
+ import { ExactObyteClient } from '@obbyx/x402-obyte';
21
+ import { createLogger } from '@obbyx/obyte/logger';
22
+ import { loadWallet } from '@obbyx/obyte/wallet';
23
+ import { OBYTE_NETWORKS } from '@obbyx/obyte';
24
+
25
+ const network = OBYTE_NETWORKS.testnet;
26
+ const wallet = loadWallet(network); // ~/.obbyx/wallet-testnet.json (create it with `obbyx init`)
27
+ const client = new obyte.Client(network.defaultHubUrl, { testnet: true, reconnect: true });
28
+
29
+ const paidFetch = wrapFetchWithPayment(
30
+ fetch,
31
+ new x402Client()
32
+ // GBYTE is not a default USD asset: allow it explicitly, with a cap per payment
33
+ .setSpendControls({
34
+ allowedAssets: [{ network: 'obyte:testnet', asset: 'base', maxAmountPerPayment: '50000' }],
35
+ })
36
+ .register(
37
+ 'obyte:testnet',
38
+ new ExactObyteClient({
39
+ client,
40
+ network: 'obyte:testnet',
41
+ privateKey: wallet.privateKey,
42
+ logger: createLogger(),
43
+ }),
44
+ ),
45
+ );
46
+ const res = await paidFetch('https://api.example/paid');
47
+ ```
48
+
49
+ Add a `ReservingComposer` (`composer` option) when one wallet pays concurrently:
50
+ it guarantees two payments never pick the same coins.
51
+
52
+ ## What is inside
53
+
54
+ | Export | Role |
55
+ | --------------------------------------------------------------------------- | -------------------------------------------------------- |
56
+ | `ExactObyteClient`, `BatchObyteClient` | x402 client mechanisms (`SchemeNetworkClient`) |
57
+ | `ExactObyteFacilitator`, `ExactObyteFacilitatorV1`, `BatchObyteFacilitator` | facilitator mechanisms (`SchemeNetworkFacilitator`) |
58
+ | `SettlementStore`, `BatchStore`, `WatcherGateway` | storage / watcher ports (+ node:sqlite reference stores) |
59
+ | `ReservingComposer`, `CoinReservations` | coin reservation for concurrent payments |
60
+ | `computeBinding`, `bindingsEqual` | binding of a payment to one request |
61
+ | `hubCall`, `startHeartbeat`, `parseHistory`, … | hub access with timeouts and validated answers |
62
+
63
+ Scheme specs, the facilitator, the seller SDK and the CLI:
64
+ [github.com/Taump/obbyx](https://github.com/Taump/obbyx).
65
+
66
+ Node.js ≥ 24. MIT.
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Buyer-side channel state (node:sqlite, lightweight; used by the SDK/CLI).
3
+ *
4
+ * Per channel: the AA params, the current period, the last amount the
5
+ * facilitator confirmed (`committed`) and at most ONE pending voucher whose
6
+ * outcome is unknown. While a voucher is pending, no new voucher is signed
7
+ * (invariant I7); retrying the same operation resends the same voucher.
8
+ */
9
+ export interface ClientChannel {
10
+ readonly network: string;
11
+ readonly aa: string;
12
+ readonly payTo: string;
13
+ readonly asset: string;
14
+ readonly timeout: number;
15
+ readonly salt: string;
16
+ readonly period: number;
17
+ readonly committed: bigint;
18
+ readonly pending: PendingVoucher | null;
19
+ readonly openedUnit: string | null;
20
+ }
21
+ export interface PendingVoucher {
22
+ readonly binding: string;
23
+ readonly period: number;
24
+ readonly amountSpent: string;
25
+ readonly signedPackage: Record<string, unknown>;
26
+ }
27
+ export declare class ClientChannelStore {
28
+ private readonly db;
29
+ constructor(path: string);
30
+ close(): void;
31
+ add(c: Omit<ClientChannel, 'pending' | 'committed' | 'period'> & {
32
+ period?: number;
33
+ }): void;
34
+ get(aa: string): ClientChannel | undefined;
35
+ /** The newest channel to `payTo` in `asset` on `network`. */
36
+ find(network: string, payTo: string, asset: string): ClientChannel | undefined;
37
+ list(): ClientChannel[];
38
+ /** Records a signed voucher BEFORE it is sent (compare-and-set: fails if one is pending). */
39
+ setPending(aa: string, pending: PendingVoucher): boolean;
40
+ /** The facilitator confirmed `amountSpent` for `period`. */
41
+ confirm(aa: string, period: number, amountSpent: bigint): void;
42
+ /** The voucher was definitely refused; optionally resync to the facilitator's committed amount. */
43
+ dropPending(aa: string, resync?: {
44
+ period: number;
45
+ committed: bigint;
46
+ }): void;
47
+ /** A new period started on-chain (the channel was closed and reopened). */
48
+ newPeriod(aa: string, period: number): void;
49
+ }
50
+ //# sourceMappingURL=client-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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M,GAAG,aAAa,GAAG,SAAS;IAS9E,IAAI,IAAI,aAAa,EAAE;IAMvB,6FAA6F;IAC7F,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO;IAOxD,4DAA4D;IAC5D,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;IAQ9D,mGAAmG;IACnG,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAY7E,2EAA2E;IAC3E,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;CAO5C"}
@@ -0,0 +1,93 @@
1
+ import { DatabaseSync } from 'node:sqlite';
2
+ export class ClientChannelStore {
3
+ db;
4
+ constructor(path) {
5
+ this.db = new DatabaseSync(path);
6
+ this.db.exec(`
7
+ PRAGMA journal_mode = WAL;
8
+ PRAGMA synchronous = FULL;
9
+ PRAGMA busy_timeout = 5000;
10
+ CREATE TABLE IF NOT EXISTS client_channels (
11
+ aa TEXT PRIMARY KEY,
12
+ network TEXT NOT NULL,
13
+ pay_to TEXT NOT NULL,
14
+ asset TEXT NOT NULL,
15
+ timeout INTEGER NOT NULL,
16
+ salt TEXT NOT NULL,
17
+ period INTEGER NOT NULL,
18
+ committed TEXT NOT NULL,
19
+ pending_json TEXT,
20
+ opened_unit TEXT,
21
+ created_at INTEGER NOT NULL
22
+ ) STRICT;
23
+ `);
24
+ }
25
+ close() {
26
+ this.db.close();
27
+ }
28
+ add(c) {
29
+ this.db
30
+ .prepare(`INSERT INTO client_channels (aa, network, pay_to, asset, timeout, salt, period, committed, opened_unit, created_at)
31
+ VALUES (?, ?, ?, ?, ?, ?, ?, '0', ?, ?) ON CONFLICT(aa) DO NOTHING`)
32
+ .run(c.aa, c.network, c.payTo, c.asset, c.timeout, c.salt, c.period ?? 1, c.openedUnit, Math.floor(Date.now() / 1000));
33
+ }
34
+ get(aa) {
35
+ const row = this.db.prepare('SELECT * FROM client_channels WHERE aa = ?').get(aa);
36
+ return row === undefined ? undefined : toChannel(row);
37
+ }
38
+ /** The newest channel to `payTo` in `asset` on `network`. */
39
+ find(network, payTo, asset) {
40
+ const row = this.db
41
+ .prepare('SELECT * FROM client_channels WHERE network = ? AND pay_to = ? AND asset = ? ORDER BY created_at DESC LIMIT 1')
42
+ .get(network, payTo, asset);
43
+ return row === undefined ? undefined : toChannel(row);
44
+ }
45
+ list() {
46
+ return this.db.prepare('SELECT * FROM client_channels ORDER BY created_at').all().map(toChannel);
47
+ }
48
+ /** Records a signed voucher BEFORE it is sent (compare-and-set: fails if one is pending). */
49
+ setPending(aa, pending) {
50
+ const res = this.db
51
+ .prepare('UPDATE client_channels SET pending_json = ? WHERE aa = ? AND pending_json IS NULL')
52
+ .run(JSON.stringify(pending), aa);
53
+ return Number(res.changes) === 1;
54
+ }
55
+ /** The facilitator confirmed `amountSpent` for `period`. */
56
+ confirm(aa, period, amountSpent) {
57
+ this.db
58
+ .prepare('UPDATE client_channels SET period = ?, committed = ?, pending_json = NULL WHERE aa = ?')
59
+ .run(period, amountSpent.toString(), aa);
60
+ }
61
+ /** The voucher was definitely refused; optionally resync to the facilitator's committed amount. */
62
+ dropPending(aa, resync) {
63
+ if (resync === undefined) {
64
+ this.db.prepare('UPDATE client_channels SET pending_json = NULL WHERE aa = ?').run(aa);
65
+ }
66
+ else {
67
+ this.db
68
+ .prepare('UPDATE client_channels SET pending_json = NULL, period = ?, committed = ? WHERE aa = ?')
69
+ .run(resync.period, resync.committed.toString(), aa);
70
+ }
71
+ }
72
+ /** A new period started on-chain (the channel was closed and reopened). */
73
+ newPeriod(aa, period) {
74
+ this.db
75
+ .prepare("UPDATE client_channels SET period = ?, committed = '0', pending_json = NULL WHERE aa = ? AND period < ?")
76
+ .run(period, aa, period);
77
+ }
78
+ }
79
+ function toChannel(r) {
80
+ return {
81
+ network: r.network,
82
+ aa: r.aa,
83
+ payTo: r.pay_to,
84
+ asset: r.asset,
85
+ timeout: r.timeout,
86
+ salt: r.salt,
87
+ period: r.period,
88
+ committed: BigInt(r.committed),
89
+ pending: r.pending_json === null ? null : JSON.parse(r.pending_json),
90
+ openedUnit: r.opened_unit,
91
+ };
92
+ }
93
+ //# sourceMappingURL=client-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-store.js","sourceRoot":"","sources":["../../src/batch/client-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AA2C3C,MAAM,OAAO,kBAAkB;IACZ,EAAE,CAAe;IAElC,YAAY,IAAY;QACtB,IAAI,CAAC,EAAE,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;KAiBZ,CAAC,CAAC;IACL,CAAC;IAED,KAAK;QACH,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;IAED,GAAG,CAAC,CAAgF;QAClF,IAAI,CAAC,EAAE;aACJ,OAAO,CACN;4EACoE,CACrE;aACA,GAAG,CACF,CAAC,CAAC,EAAE,EACJ,CAAC,CAAC,OAAO,EACT,CAAC,CAAC,KAAK,EACP,CAAC,CAAC,KAAK,EACP,CAAC,CAAC,OAAO,EACT,CAAC,CAAC,IAAI,EACN,CAAC,CAAC,MAAM,IAAI,CAAC,EACb,CAAC,CAAC,UAAU,EACZ,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAC9B,CAAC;IACN,CAAC;IAED,GAAG,CAAC,EAAU;QACZ,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,4CAA4C,CAAC,CAAC,GAAG,CAAC,EAAE,CAC/D,CAAC;QAClB,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AAC;QACzF,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,EAAE;iBACJ,OAAO,CACN,wFAAwF,CACzF;iBACA,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAED,2EAA2E;IAC3E,SAAS,CAAC,EAAU,EAAE,MAAc;QAClC,IAAI,CAAC,EAAE;aACJ,OAAO,CACN,yGAAyG,CAC1G;aACA,GAAG,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC;CACF;AAED,SAAS,SAAS,CAAC,CAAM;IACvB,OAAO;QACL,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,EAAE,EAAE,CAAC,CAAC,EAAE;QACR,KAAK,EAAE,CAAC,CAAC,MAAM;QACf,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9B,OAAO,EAAE,CAAC,CAAC,YAAY,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAoB;QACxF,UAAU,EAAE,CAAC,CAAC,WAAW;KAC1B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,63 @@
1
+ import type { PaymentPayloadResult, PaymentRequirements, SchemeNetworkClient, SettleResponse } from '@x402/core/types';
2
+ import { type ChannelParams, type ObyteNetwork } from '@obbyx/obyte';
3
+ import { type Logger } from '@obbyx/obyte/logger';
4
+ import obyte from 'obyte';
5
+ import type { ReservingComposer } from '../coins/index.js';
6
+ import type { ClientChannelStore } from './client-store.js';
7
+ /**
8
+ * Buyer side of `batch-settlement` on Obyte (party B of an AA channel).
9
+ * obyte.js is used directly: `compose.message` + `api.postJoint` for on-chain
10
+ * actions, `utils.signMessage` for vouchers, `api.getAaStateVars` for state.
11
+ */
12
+ export declare const MIN_DEPOSIT = 10001n;
13
+ export declare const TRIGGER_FEE = 10000;
14
+ export interface BatchClientOptions {
15
+ readonly client: obyte.Client;
16
+ readonly network: ObyteNetwork;
17
+ readonly privateKey: Uint8Array;
18
+ readonly store: ClientChannelStore;
19
+ readonly logger: Logger;
20
+ readonly hubTimeoutMs?: number;
21
+ /** Refuse prices above this per call (atomic units per asset). */
22
+ readonly maxAmount?: ReadonlyMap<string, bigint>;
23
+ /** Reserves inputs for on-chain actions (open, deposit, close). */
24
+ readonly composer?: ReservingComposer;
25
+ }
26
+ /** My address (party B) from the key, via obyte.js public API. */
27
+ export declare function addressOfKey(privateKey: Uint8Array, network: ObyteNetwork): string;
28
+ /**
29
+ * Opens a channel to `payTo`: publishes the parameterized AA definition and the
30
+ * first deposit in ONE unit (as aa-channels-lib does). The deposit is credited
31
+ * by the AA once the unit is stable.
32
+ */
33
+ export declare function openChannel(options: BatchClientOptions, input: {
34
+ payTo: string;
35
+ deposit: bigint;
36
+ timeout: number;
37
+ asset?: string;
38
+ }): Promise<{
39
+ aa: string;
40
+ unit: string;
41
+ params: ChannelParams;
42
+ }>;
43
+ export declare function deposit(options: BatchClientOptions, aa: string, amount: bigint): Promise<string>;
44
+ /**
45
+ * The client (B) starts closing: declares what it spent (the last confirmed
46
+ * cumulative amount). The seller's watcher confirms at once if honest, or
47
+ * answers with a fraud proof if B under-declares.
48
+ */
49
+ export declare function closeChannel(options: BatchClientOptions, aa: string, period: number, spent: bigint): Promise<string>;
50
+ /** Confirms our own close after the dispute window. */
51
+ export declare function confirmClose(options: BatchClientOptions, aa: string, period: number): Promise<string>;
52
+ export declare class BatchObyteClient implements SchemeNetworkClient {
53
+ private readonly options;
54
+ readonly scheme = "batch-settlement";
55
+ private readonly log;
56
+ constructor(options: BatchClientOptions);
57
+ /** Is there a usable channel for these requirements? */
58
+ hasChannel(req: PaymentRequirements): boolean;
59
+ createPaymentPayload(x402Version: number, requirements: PaymentRequirements): Promise<PaymentPayloadResult>;
60
+ /** Updates local state from the seller's PAYMENT-RESPONSE (settlement result). */
61
+ onSettled(requirements: PaymentRequirements, settle: SettleResponse | undefined): void;
62
+ }
63
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/batch/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,YAAY,EAIlB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,qBAAqB,CAAC;AAChE,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAG3D,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,mBAAmB,CAAC;AAG5E;;;;GAIG;AACH,eAAO,MAAM,WAAW,SAAU,CAAC;AACnC,eAAO,MAAM,WAAW,QAAS,CAAC;AAElC,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,kEAAkE;IAClE,QAAQ,CAAC,SAAS,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,mEAAmE;IACnE,QAAQ,CAAC,Q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E,mBAAmB,GAChC,OAAO,CAAC,oBAAoB,CAAC;IA0FhC,kFAAkF;IAClF,SAAS,CAAC,YAAY,EAAE,mBAAmB,EAAE,MAAM,EAAE,cAAc,GAAG,SAAS,GAAG,IAAI;CA+CvF"}
@@ -0,0 +1,222 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { ObbyxError, channelAddress, channelDefinition, toSafeNumber, } from '@obbyx/obyte';
3
+ import { moduleLogger } from '@obbyx/obyte/logger';
4
+ import obyte from 'obyte';
5
+ import { hubCall } from '../hub/hub-call.js';
6
+ import { parseStateVars } from '../hub/schemas.js';
7
+ import { BATCH_REASONS, BATCH_SCHEME, parseBatchRequirements } from './requirements.js';
8
+ /**
9
+ * Buyer side of `batch-settlement` on Obyte (party B of an AA channel).
10
+ * obyte.js is used directly: `compose.message` + `api.postJoint` for on-chain
11
+ * actions, `utils.signMessage` for vouchers, `api.getAaStateVars` for state.
12
+ */
13
+ export const MIN_DEPOSIT = 10001n; // the AA treats ≤ 10000 bytes as a bounce-fee-only trigger
14
+ export const TRIGGER_FEE = 10_000;
15
+ /** My address (party B) from the key, via obyte.js public API. */
16
+ export function addressOfKey(privateKey, network) {
17
+ const signed = obyte.utils.signMessage('obbyx', {
18
+ privateKey,
19
+ testnet: network.testnet,
20
+ });
21
+ const address = signed.authors[0]?.address;
22
+ if (address === undefined)
23
+ throw new ObbyxError('bad_key', 'Cannot derive address');
24
+ return address;
25
+ }
26
+ async function broadcast(options, messages) {
27
+ const compose = () => options.client.compose.message('multi', messages, {
28
+ privateKey: options.privateKey,
29
+ testnet: options.network.testnet,
30
+ });
31
+ const unit = await (options.composer ? options.composer.compose(compose) : compose());
32
+ const res = await hubCall(() => options.client.api.postJoint({ unit }), options.hubTimeoutMs ?? 15_000);
33
+ if (res.kind === 'hub_error')
34
+ throw new ObbyxError('broadcast_rejected', `Hub rejected the unit: ${res.error}`);
35
+ // ok or unknown: the unit hash identifies it either way; callers can check it later.
36
+ return String(unit['unit']);
37
+ }
38
+ /**
39
+ * Opens a channel to `payTo`: publishes the parameterized AA definition and the
40
+ * first deposit in ONE unit (as aa-channels-lib does). The deposit is credited
41
+ * by the AA once the unit is stable.
42
+ */
43
+ export async function openChannel(options, input) {
44
+ const asset = input.asset ?? 'base';
45
+ if (asset !== 'base')
46
+ throw new ObbyxError('unsupported', 'Only bytes channels are supported by the CLI for now');
47
+ if (input.deposit < MIN_DEPOSIT)
48
+ throw new ObbyxError('deposit_too_small', `Deposit must be at least ${MIN_DEPOSIT} bytes`);
49
+ const params = {
50
+ addressA: input.payTo,
51
+ addressB: addressOfKey(options.privateKey, options.network),
52
+ asset,
53
+ salt: randomBytes(12).toString('hex'),
54
+ timeout: input.timeout,
55
+ };
56
+ const aa = channelAddress(params);
57
+ const unit = await broadcast(options, [
58
+ { app: 'definition', payload: { address: aa, definition: channelDefinition(params) } },
59
+ {
60
+ app: 'payment',
61
+ payload: { outputs: [{ address: aa, amount: toSafeNumber(input.deposit) }] },
62
+ },
63
+ ]);
64
+ options.store.add({
65
+ network: options.network.caip2,
66
+ aa,
67
+ payTo: input.payTo,
68
+ asset,
69
+ timeout: input.timeout,
70
+ salt: params.salt ?? '',
71
+ openedUnit: unit,
72
+ });
73
+ moduleLogger(options.logger, 'x402.batch.client').info({ aa, unit, deposit: input.deposit.toString() }, 'channel opened');
74
+ return { aa, unit, params };
75
+ }
76
+ export function deposit(options, aa, amount) {
77
+ if (amount < MIN_DEPOSIT)
78
+ throw new ObbyxError('deposit_too_small', `Deposit must be at least ${MIN_DEPOSIT} bytes`);
79
+ return broadcast(options, [
80
+ { app: 'payment', payload: { outputs: [{ address: aa, amount: toSafeNumber(amount) }] } },
81
+ ]);
82
+ }
83
+ /**
84
+ * The client (B) starts closing: declares what it spent (the last confirmed
85
+ * cumulative amount). The seller's watcher confirms at once if honest, or
86
+ * answers with a fraud proof if B under-declares.
87
+ */
88
+ export function closeChannel(options, aa, period, spent) {
89
+ return broadcast(options, [
90
+ { app: 'payment', payload: { outputs: [{ address: aa, amount: TRIGGER_FEE }] } },
91
+ { app: 'data', payload: { close: 1, period, transferredFromMe: toSafeNumber(spent) } },
92
+ ]);
93
+ }
94
+ /** Confirms our own close after the dispute window. */
95
+ export function confirmClose(options, aa, period) {
96
+ return broadcast(options, [
97
+ { app: 'payment', payload: { outputs: [{ address: aa, amount: TRIGGER_FEE }] } },
98
+ { app: 'data', payload: { confirm: 1, period } },
99
+ ]);
100
+ }
101
+ export class BatchObyteClient {
102
+ options;
103
+ scheme = BATCH_SCHEME;
104
+ log;
105
+ constructor(options) {
106
+ this.options = options;
107
+ this.log = moduleLogger(options.logger, 'x402.batch.client');
108
+ }
109
+ /** Is there a usable channel for these requirements? */
110
+ hasChannel(req) {
111
+ return this.options.store.find(req.network, req.payTo, req.asset) !== undefined;
112
+ }
113
+ async createPaymentPayload(x402Version, requirements) {
114
+ if (x402Version !== 2)
115
+ throw new ObbyxError('invalid_x402_version', 'Only x402 v2 is supported');
116
+ const parsed = parseBatchRequirements(requirements);
117
+ if (!parsed.ok)
118
+ throw new ObbyxError(parsed.reason, parsed.message);
119
+ const req = parsed.value;
120
+ const cap = this.options.maxAmount?.get(req.asset);
121
+ if (cap !== undefined && req.amount > cap) {
122
+ throw new ObbyxError('amount_over_limit', `Price ${req.amount} exceeds the limit ${cap}`);
123
+ }
124
+ const store = this.options.store;
125
+ const channel = store.find(req.network.caip2, req.payTo, req.asset);
126
+ if (channel === undefined) {
127
+ throw new ObbyxError('no_channel', `No channel to ${req.payTo}; open one with: obbyx channel open ${req.payTo}`);
128
+ }
129
+ if (channel.timeout < req.extra.minTimeout) {
130
+ throw new ObbyxError('channel_timeout', `The seller requires a channel timeout ≥ ${req.extra.minTimeout} s`);
131
+ }
132
+ // Same operation retried: resend the same voucher (never sign a second one).
133
+ if (channel.pending !== null) {
134
+ if (channel.pending.binding === req.extra.binding)
135
+ return { x402Version: 2, payload: { signedPackage: channel.pending.signedPackage } };
136
+ throw new ObbyxError('payment_pending', `A previous voucher on channel ${channel.aa} has an unknown outcome; retry that request first`);
137
+ }
138
+ const vars = await hubCall(() => this.options.client.api.getAaStateVars({ address: channel.aa }), this.options.hubTimeoutMs ?? 15_000);
139
+ if (vars.kind !== 'ok')
140
+ throw new ObbyxError('ledger_unavailable', `Cannot read channel state: ${vars.error}`);
141
+ const state = parseStateVars(vars.value);
142
+ if (state === undefined)
143
+ throw new ObbyxError('ledger_unavailable', 'Cannot read channel state: malformed hub answer');
144
+ const period = typeof state['period'] === 'number' ? state['period'] : undefined;
145
+ if (period === undefined)
146
+ throw new ObbyxError('channel_not_funded', 'The channel has no confirmed deposit yet (wait until stable)');
147
+ if (state['close_initiated_by'] !== undefined)
148
+ throw new ObbyxError('channel_closing', 'The channel is being closed');
149
+ if (period > channel.period)
150
+ store.newPeriod(channel.aa, period);
151
+ const committed = period > channel.period ? 0n : channel.committed;
152
+ const amountSpent = committed + req.amount;
153
+ const balance = BigInt(typeof state['balanceB'] === 'number' ? state['balanceB'] : 0);
154
+ if (amountSpent > balance) {
155
+ throw new ObbyxError('channel_exhausted', `Channel balance ${balance} is not enough; deposit more with: obbyx channel deposit ${channel.aa}`);
156
+ }
157
+ const message = {
158
+ aa_address: channel.aa,
159
+ period,
160
+ amount_spent: toSafeNumber(amountSpent),
161
+ payment_amount: toSafeNumber(req.amount),
162
+ binding: req.extra.binding,
163
+ };
164
+ const signedPackage = obyte.utils.signMessage(message, {
165
+ privateKey: this.options.privateKey,
166
+ testnet: this.options.network.testnet,
167
+ });
168
+ const pending = {
169
+ binding: req.extra.binding,
170
+ period,
171
+ amountSpent: amountSpent.toString(),
172
+ signedPackage,
173
+ };
174
+ if (!store.setPending(channel.aa, pending)) {
175
+ throw new ObbyxError('payment_pending', 'Another voucher on this channel is in flight');
176
+ }
177
+ this.log.info({ aa: channel.aa, period, amountSpent: amountSpent.toString(), binding: req.extra.binding }, 'voucher signed');
178
+ return { x402Version: 2, payload: { signedPackage } };
179
+ }
180
+ /** Updates local state from the seller's PAYMENT-RESPONSE (settlement result). */
181
+ onSettled(requirements, settle) {
182
+ const channel = this.options.store.find(requirements.network, requirements.payTo, requirements.asset);
183
+ const pending = channel?.pending;
184
+ if (channel === undefined || pending == null)
185
+ return;
186
+ if (settle?.success === true) {
187
+ this.options.store.confirm(channel.aa, pending.period, BigInt(pending.amountSpent));
188
+ return;
189
+ }
190
+ const reason = settle?.errorReason;
191
+ const charged = settle?.extra
192
+ ?.chargedCumulativeAmount;
193
+ if (reason === BATCH_REASONS.cumulative &&
194
+ typeof charged === 'string' &&
195
+ /^\d+$/.test(charged)) {
196
+ // PAYMENT-RESPONSE is NOT authenticated: never raise our committed amount
197
+ // to an arbitrary value (a malicious seller could make us sign a voucher
198
+ // for the whole deposit). Accept only:
199
+ // - exactly the amount of the voucher WE signed (it was committed earlier), or
200
+ // - a lower amount (signing less than before cannot hurt us).
201
+ const claimed = BigInt(charged);
202
+ if (claimed === BigInt(pending.amountSpent)) {
203
+ this.options.store.confirm(channel.aa, pending.period, claimed);
204
+ }
205
+ else if (pending.period === channel.period && claimed <= channel.committed) {
206
+ this.options.store.dropPending(channel.aa, { period: pending.period, committed: claimed });
207
+ }
208
+ else {
209
+ this.options.store.dropPending(channel.aa);
210
+ this.log.error({ aa: channel.aa, claimed: charged, local: channel.committed.toString() }, 'seller claimed a committed amount we never signed; refusing to resync');
211
+ }
212
+ }
213
+ else if (reason !== undefined &&
214
+ reason !== 'settlement_pending' &&
215
+ reason !== BATCH_REASONS.busy) {
216
+ // Definitely refused (incl. watcher_unavailable at verification): nothing was stored.
217
+ this.options.store.dropPending(channel.aa);
218
+ }
219
+ // settlement_pending / busy / no answer: keep the voucher pending; retry the same operation.
220
+ }
221
+ }
222
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/batch/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAO1C,OAAO,EAEL,UAAU,EAEV,c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aymentRequirements, SchemeNetworkFacilitator, SettleResponse, VerifyResponse } from '@x402/core/types';
2
+ import { type Logger } from '@obbyx/obyte/logger';
3
+ import type obyte from 'obyte';
4
+ import type { WatcherGateway } from './gateway.js';
5
+ import type { SettlementEvent } from '../exact/store.js';
6
+ import type { BatchStore } from './store.js';
7
+ /**
8
+ * x402 `batch-settlement` facilitator for Obyte AA payment channels
9
+ * (ADR-0003, facilitator-managed vouchers).
10
+ *
11
+ * The client (party B) signs cumulative vouchers `amount_spent` for the
12
+ * channel AA with the seller (party A = payTo). `/settle` stores the voucher;
13
+ * it succeeds only after the SELLER'S WATCHER has durably stored it (sync ack),
14
+ * so the component that defends the channel always holds the latest proof.
15
+ * No value moves on-chain here; the watcher closes channels later.
16
+ *
17
+ * MVP rules: unidirectional channel, one in-flight voucher per channel,
18
+ * `amount_spent == committed + price`, `payment_amount == price`.
19
+ */
20
+ export interface BatchObyteFacilitatorOptions {
21
+ readonly clients: ReadonlyMap<string, obyte.Client>;
22
+ readonly store: BatchStore;
23
+ readonly gateway: WatcherGateway;
24
+ readonly logger: Logger;
25
+ readonly allowedAssets: ReadonlyMap<string, ReadonlySet<string>>;
26
+ /** Lowest channel timeout accepted (also advertised in /supported). */
27
+ readonly minChannelTimeoutSeconds: number;
28
+ readonly hubTimeoutMs?: number;
29
+ readonly ackTimeoutMs?: number;
30
+ /** Payment event journal (logging stream 2); e.g. the facilitator's `events` table. */
31
+ readonly events?: (event: SettlementEvent) => Promise<void>;
32
+ readonly now?: () => number;
33
+ }
34
+ export declare class BatchObyteFacilitator implements SchemeNetworkFacilitator {
35
+ private readonly options;
36
+ readonly scheme = "batch-settlement";
37
+ readonly caipFamily: "obyte:*";
38
+ private readonly log;
39
+ private readonly hubTimeoutMs;
40
+ private readonly ackTimeoutMs;
41
+ private readonly now;
42
+ /** Channel definitions are immutable: cache them. */
43
+ private readonly definitions;
44
+ /** One settle at a time per channel inside this process. */
45
+ private readonly locks;
46
+ constructor(options: BatchObyteFacilitatorOptions);
47
+ getExtra(network: Network): Record<string, unknown>;
48
+ /** The facilitator never signs channel triggers (ADR-0001). */
49
+ getSigners(): string[];
50
+ verify(payload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;
51
+ settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
52
+ private newVoucherChecks;
53
+ private settleLocked;
54
+ private success;
55
+ /** Stateless checks: shape, signature, binding, price, the channel's on-chain parameters. */
56
+ private authenticate;
57
+ /**
58
+ * Checks that depend on time and live state: offer validity, channel period,
59
+ * closing flag, confirmed deposit, the seller's watcher. Applied only to a
60
+ * NEW voucher: one already stored is re-delivered regardless, because its
61
+ * outcome is decided by the watcher's ack (refusing it now would report a
62
+ * definite failure for a voucher the seller may still redeem).
63
+ */
64
+ private liveChecks;
65
+ /** Full verification of a new voucher. */
66
+ private check;
67
+ private channelParams;
68
+ /** The journal must never break a payment: failures are logged, not thrown. */
69
+ private emit;
70
+ private channelKey;
71
+ private withChannelLock;
72
+ }
73
+ //# sourceMappingURL=facilitator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facilitator.d.ts","sourceRoot":"","sources":["../../src/batch/facilitator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,mBAAmB,EACnB,wBAAwB,EACxB,cAAc,EACd,cAAc,EACf,MAAM,kBAAkB,CAAC;AAS1B,OAAO,EAAE,KAAK,MAAM,EAAgC,MAAM,qBAAqB,CAAC;AAChF,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AASnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,YAAY,CAAC;AAE5D;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,M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