thunder-bridge 0.8.1 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,10 +12,11 @@ amount you asked for rather than the amount the gateway echoed back, and its
12
12
  settlement proof url belongs to the recipient. A gateway that substitutes an
13
13
  invoice is caught before a payer sees a QR code.
14
14
 
15
- Lightning is the rail it was built for, not the only one it can prove.
16
- `bankTransfer` derives a preimage and hands the gateway its hash, which puts money
17
- landing in a bank account behind the same watch and the same proof. `Statement` is
18
- the seam a bank plugs into and `fioStatement` is the first one.
15
+ Lightning is the rail it was built for, not the only one it can prove. A bank
16
+ transfer has no preimage, so `bankTransfer` derives one and hands the gateway its
17
+ hash, which puts money arriving in a bank account behind the same watch, the same
18
+ poll and the same proof. `Statement` is where a bank plugs in and `fioStatement`
19
+ is the first one.
19
20
 
20
21
  It touches only `fetch`, `crypto.subtle`, `URL` and `WebSocket`, so it runs in
21
22
  Node, Bun, Deno, Cloudflare Workers and the browser. The gateway it talks to is
@@ -36,7 +37,7 @@ CORS open, so the proof fetches work from a browser too.
36
37
  ```ts
37
38
  import { ThunderBridge, invoiceToSvg, type CreatePaymentParams } from "thunder-bridge";
38
39
 
39
- const gateway = new ThunderBridge("https://thunder-bridge-direct-production.up.railway.app");
40
+ const gateway = new ThunderBridge("https://thunder-bridge-production.up.railway.app");
40
41
 
41
42
  const request: CreatePaymentParams = {
42
43
  lnAddresses: ["alice@coinos.io", "alice@getalby.com"],
@@ -105,18 +106,39 @@ them and this table does not repeat them.
105
106
 
106
107
  | Export | What it does |
107
108
  |---|---|
108
- | `lnurlPayEndpoint(config)` | a whole LNURL-pay endpoint as one Fetch handler, so a static QR points at your domain |
109
- | `bankTransfer(params)` | register a Czech QR platba as a watched payment. Refuses a gateway with no token |
110
- | `bankVerifyEndpoint(config)` | the other half, the LUD-21 shape backed by your own statement |
111
- | `fioStatement(config)` | a `Statement` reading a Fio account, several tokens used strictly in turn |
109
+ | `lnurlPayEndpoint(config)` | a whole LNURL-pay endpoint as one Fetch handler, so a static QR points at your domain. From `thunder-bridge/server` |
112
110
  | `seal(secret, plaintext)`, `unseal` | the blob the gateway stores and cannot read |
113
111
  | `toLnurl(url)` | bech32-encode an endpoint url |
112
+ | `bankTransfer(params)` | register a Czech QR platba as a watched payment. Refuses a gateway that serves strangers |
113
+ | `bankVerifyEndpoint(config)` | the other half, the LUD-21 shape backed by your own statement |
114
+ | `fioStatement(config)` | a `Statement` reading a Fio account, several tokens used strictly in turn |
115
+
116
+ What your service answers once those handlers are mounted is written out in
117
+ [`openapi.yaml`](openapi.yaml), shipped with this package.
114
118
 
115
119
  `Statement` is a plain `(sinceUnix) => Promise<Credit[]>`, so another bank is
116
120
  another function of that shape and persistence wraps it from outside rather than
117
121
  living inside it. Nothing above it changes, and the package stays ignorant of
118
122
  whatever runtime you keep state in.
119
123
 
124
+ **One shape for every payment method** - [`src/rail.ts`](src/rail.ts)
125
+
126
+ | Export | What it does |
127
+ |---|---|
128
+ | `bankRail(config)` | a `Rail` selling for a bank transfer, reading back through any `Statement` |
129
+ | `lightningRail(config)` | a `Rail` where the gateway mints the invoice, so it learns the address and the amount |
130
+ | `blindLightningRail(config)` | a `Rail` that resolves the address itself and tells the gateway only a hash. From `thunder-bridge/server` |
131
+
132
+ `Rail` is `(order: Order) => Promise<Leg>`. Everything that differs between rails
133
+ is bound once when the rail is built, so the only thing passed per sale is which
134
+ sale it is: a reference, an amount in minor units and a currency. A `Leg` reads
135
+ the same whichever rail made it, which is what lets `firstToSettle` take a mixed
136
+ list without being told what is in it.
137
+
138
+ The gateway is already indifferent to all of this. It holds a payment hash, polls
139
+ a verify URL and reports what came back, so a rail is an SDK-side arrangement of
140
+ calls the gateway already answers, not a plugin it has to load.
141
+
120
142
  **Pricing a fiat order** - [`src/price.ts`](src/price.ts), [`src/currency.ts`](src/currency.ts)
121
143
 
122
144
  | Export | What it does |
@@ -129,10 +151,12 @@ whatever runtime you keep state in.
129
151
  **QR codes** - [`src/qr.ts`](src/qr.ts)
130
152
 
131
153
  Every renderer returns a string, so they work on a server, in a worker and in a
132
- browser with no canvas involved. `invoiceToSvg` takes an invoice or a lightning
133
- address, `lnurlToSvg` takes your own endpoint url, `spdToSvg` takes the `spd` from
134
- `bankTransfer`. Each has a `…ToDataUrl` twin for an `<img>` `src`. A BOLT12 offer
135
- is not handled, because this gateway never returns one.
154
+ browser with no canvas involved. `qrToSvg` takes any rail's `Leg.qr` and needs to
155
+ know nothing else, because a rail states its own payload. Below it sit the
156
+ format-named ones for calling directly: `invoiceToSvg` takes an invoice or a
157
+ lightning address, `lnurlToSvg` takes your own endpoint url, `spdToSvg` takes a
158
+ Short Payment Descriptor. Each has a `…ToDataUrl` twin for an `<img>` `src`. A
159
+ BOLT12 offer is not handled, because this gateway never returns one.
136
160
 
137
161
  ```ts
138
162
  import { invoiceToSvg, lnurlToSvg } from "thunder-bridge";