@run402/sdk 4.113.0 → 4.114.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/node/lightning-paid-fetch.d.ts +2 -0
- package/dist/node/lightning-paid-fetch.d.ts.map +1 -1
- package/dist/node/lightning-paid-fetch.js +44 -10
- package/dist/node/lightning-paid-fetch.js.map +1 -1
- package/dist/node/lightning-x402-lnbtc.d.ts +62 -0
- package/dist/node/lightning-x402-lnbtc.d.ts.map +1 -0
- package/dist/node/lightning-x402-lnbtc.js +170 -0
- package/dist/node/lightning-x402-lnbtc.js.map +1 -0
- package/dist/node/vendor/x402-lnbtc/LICENSE +201 -0
- package/dist/node/vendor/x402-lnbtc/VENDORED.md +25 -0
- package/dist/node/vendor/x402-lnbtc/binding.d.ts +80 -0
- package/dist/node/vendor/x402-lnbtc/binding.d.ts.map +1 -0
- package/dist/node/vendor/x402-lnbtc/binding.js +268 -0
- package/dist/node/vendor/x402-lnbtc/binding.js.map +1 -0
- package/dist/node/vendor/x402-lnbtc/bolt11.d.ts +39 -0
- package/dist/node/vendor/x402-lnbtc/bolt11.d.ts.map +1 -0
- package/dist/node/vendor/x402-lnbtc/bolt11.js +209 -0
- package/dist/node/vendor/x402-lnbtc/bolt11.js.map +1 -0
- package/dist/node/vendor/x402-lnbtc/constants.d.ts +75 -0
- package/dist/node/vendor/x402-lnbtc/constants.d.ts.map +1 -0
- package/dist/node/vendor/x402-lnbtc/constants.js +81 -0
- package/dist/node/vendor/x402-lnbtc/constants.js.map +1 -0
- package/dist/node/vendor/x402-lnbtc/exact/client/scheme.d.ts +58 -0
- package/dist/node/vendor/x402-lnbtc/exact/client/scheme.d.ts.map +1 -0
- package/dist/node/vendor/x402-lnbtc/exact/client/scheme.js +108 -0
- package/dist/node/vendor/x402-lnbtc/exact/client/scheme.js.map +1 -0
- package/dist/node/vendor/x402-lnbtc/jcs.d.ts +19 -0
- package/dist/node/vendor/x402-lnbtc/jcs.d.ts.map +1 -0
- package/dist/node/vendor/x402-lnbtc/jcs.js +81 -0
- package/dist/node/vendor/x402-lnbtc/jcs.js.map +1 -0
- package/dist/node/vendor/x402-lnbtc/types.d.ts +81 -0
- package/dist/node/vendor/x402-lnbtc/types.d.ts.map +1 -0
- package/dist/node/vendor/x402-lnbtc/types.js +2 -0
- package/dist/node/vendor/x402-lnbtc/types.js.map +1 -0
- package/dist/node/vendor/x402-lnbtc/validation.d.ts +94 -0
- package/dist/node/vendor/x402-lnbtc/validation.d.ts.map +1 -0
- package/dist/node/vendor/x402-lnbtc/validation.js +165 -0
- package/dist/node/vendor/x402-lnbtc/validation.js.map +1 -0
- package/package.json +1 -1
|
@@ -41,6 +41,8 @@ export interface LightningFetchOptions {
|
|
|
41
41
|
onPaid?: (paymentHash: string) => void;
|
|
42
42
|
/** The wait between post-settlement retries; tests pass an instant one. */
|
|
43
43
|
sleep?: (ms: number) => Promise<void>;
|
|
44
|
+
/** Unix seconds for x402 Lightning invoice checks; tests pin it. */
|
|
45
|
+
clock?: () => number;
|
|
44
46
|
}
|
|
45
47
|
export declare class LightningPaymentError extends Error {
|
|
46
48
|
readonly code: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lightning-paid-fetch.d.ts","sourceRoot":"","sources":["../../src/node/lightning-paid-fetch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lightning-paid-fetch.d.ts","sourceRoot":"","sources":["../../src/node/lightning-paid-fetch.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAS3E,KAAK,OAAO,GAAG,OAAO,UAAU,CAAC,KAAK,CAAC;AAEvC,eAAO,MAAM,4BAA4B,kDAAkD,CAAC;AAI5F,gHAAgH;AAChH,eAAO,MAAM,wBAAwB,SAAU,CAAC;AAehD,4GAA4G;AAC5G,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAK7C,MAAM,WAAW,mBAAmB;IAClC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,KAAK;aAClB,IAAI,EAAE,MAAM;aAAmC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAA/E,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAkB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;CAIjH;AAED,UAAU,kBAAkB;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,iFAAiF;AACjF,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,cAAc,GAAG,kBAAkB,GAAG,IAAI,CAkB3G;AAyBD;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,EAAE,IAAI,EAAE,WAAW,GAAG,SAAS,GAAG,OAAO,CAS1G;AA0BD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAuG5E"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The Lightning rail's buyer
|
|
3
|
-
*
|
|
2
|
+
* The Lightning rail's buyer. Where the seller offers the x402 `exact` scheme
|
|
3
|
+
* on Lightning (`lightning-x402-lnbtc.ts`) it pays that; otherwise it is a
|
|
4
|
+
* `fetch` that selects Run402's MPP Lightning safety profile on every request, pays the one fixed BOLT11 challenge a 402
|
|
4
5
|
* carries from the agent's own wallet (the budgeted sub-wallet on Run402's
|
|
5
6
|
* Hub, over NWC), presents the preimage as the credential on a byte-identical
|
|
6
7
|
* retry, and falls back to the x402 buyer when the seller offers no Lightning
|
|
@@ -20,6 +21,7 @@
|
|
|
20
21
|
*/
|
|
21
22
|
import { createHash } from "node:crypto";
|
|
22
23
|
import { loadLightningStack } from "./_paid-stack.js";
|
|
24
|
+
import { explicitRequestHeaders, isX402LightningCandidate, payX402Lightning, readX402LightningOffer, } from "./lightning-x402-lnbtc.js";
|
|
23
25
|
import { NwcError, NwcWallet } from "./nwc.js";
|
|
24
26
|
export const RUN402_MPP_LIGHTNING_PROFILE = "run402-mpp-lightning-charge-draft00-safety-v1";
|
|
25
27
|
const ACCEPT_PAYMENT = `lightning/charge;profile=${RUN402_MPP_LIGHTNING_PROFILE}, tempo/charge;q=0.5`;
|
|
@@ -166,6 +168,21 @@ function defaultIdempotencyKey(input, init) {
|
|
|
166
168
|
const digest = createHash("sha256").update(`${method}\n${url}\n${body}`).digest("hex");
|
|
167
169
|
return `lnc_${digest.slice(0, 32)}`;
|
|
168
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* The all-in debit cap, shared by both Lightning protocols: the charge plus
|
|
173
|
+
* routing-fee headroom must fit the rail's ceiling and the wallet's remaining
|
|
174
|
+
* budget. Throws before anything is paid.
|
|
175
|
+
*/
|
|
176
|
+
async function checkLightningCaps(wallet, amountSats) {
|
|
177
|
+
const allIn = amountSats + FEE_HEADROOM_SATS;
|
|
178
|
+
if (allIn > LIGHTNING_MAX_DEBIT_SATS) {
|
|
179
|
+
throw new LightningPaymentError("LIGHTNING_DEBIT_ABOVE_CAP", `A Lightning charge of ${amountSats} sats exceeds the ${LIGHTNING_MAX_DEBIT_SATS}-sat ceiling.`, { amount_sats: amountSats, cap_sats: LIGHTNING_MAX_DEBIT_SATS, next_action: "pay over x402 (run402 init --switch-rail)" });
|
|
180
|
+
}
|
|
181
|
+
const budget = await wallet.getBudgetSats().catch(() => null);
|
|
182
|
+
if (budget && budget.totalSats !== null && budget.totalSats - budget.usedSats < allIn) {
|
|
183
|
+
throw new LightningPaymentError("LIGHTNING_BUDGET_EXHAUSTED", `The Lightning wallet's remaining budget (${budget.totalSats - budget.usedSats} sats) cannot cover ${allIn} sats.`, { remaining_sats: budget.totalSats - budget.usedSats, required_sats: allIn, next_action: "pay over x402 (run402 init --switch-rail), or ask the platform for a new wallet" });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
169
186
|
export function createLightningFetch(options) {
|
|
170
187
|
const baseFetch = options.baseFetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
171
188
|
const wallet = options.wallet ?? new NwcWallet(options.pairingUri);
|
|
@@ -183,6 +200,30 @@ export function createLightningFetch(options) {
|
|
|
183
200
|
const other = (await fallback()) ?? baseFetch;
|
|
184
201
|
return other(input, init);
|
|
185
202
|
}
|
|
203
|
+
// x402 `exact` on Lightning first where the seller offers it: a request
|
|
204
|
+
// without the MPP profile reaches the seller's x402 paywall, whose 402
|
|
205
|
+
// names an `lnbtc` entry while its Hub can issue. No entry (the Hub is
|
|
206
|
+
// paused, or this surface has none) falls through to MPP Lightning.
|
|
207
|
+
if (isX402LightningCandidate(input, init)) {
|
|
208
|
+
const probe = await baseFetch(input, { ...init, headers: explicitRequestHeaders(init) });
|
|
209
|
+
if (probe.status !== 402)
|
|
210
|
+
return probe;
|
|
211
|
+
const offer = readX402LightningOffer(probe);
|
|
212
|
+
await probe.body?.cancel().catch(() => undefined);
|
|
213
|
+
if (offer) {
|
|
214
|
+
return payX402Lightning({
|
|
215
|
+
input,
|
|
216
|
+
init,
|
|
217
|
+
offer,
|
|
218
|
+
wallet,
|
|
219
|
+
baseFetch,
|
|
220
|
+
fail: (code, message, details) => new LightningPaymentError(code, message, details),
|
|
221
|
+
checkCaps: (amountSats) => checkLightningCaps(wallet, amountSats),
|
|
222
|
+
onPaid: options.onPaid,
|
|
223
|
+
...(options.clock ? { clock: options.clock } : {}),
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
186
227
|
// Deterministic over the request bytes: a retry of the identical call
|
|
187
228
|
// (after a crash, a timeout, or a gateway hiccup between payment and
|
|
188
229
|
// fulfilment) lands on the same payment intent and is fulfilled without
|
|
@@ -204,14 +245,7 @@ export function createLightningFetch(options) {
|
|
|
204
245
|
return x402(input, init);
|
|
205
246
|
}
|
|
206
247
|
await first.body?.cancel().catch(() => undefined);
|
|
207
|
-
|
|
208
|
-
if (allIn > LIGHTNING_MAX_DEBIT_SATS) {
|
|
209
|
-
throw new LightningPaymentError("LIGHTNING_DEBIT_ABOVE_CAP", `A Lightning charge of ${challenge.amountSats} sats exceeds the ${LIGHTNING_MAX_DEBIT_SATS}-sat ceiling.`, { amount_sats: challenge.amountSats, cap_sats: LIGHTNING_MAX_DEBIT_SATS, next_action: "pay over x402 (run402 init --switch-rail)" });
|
|
210
|
-
}
|
|
211
|
-
const budget = await wallet.getBudgetSats().catch(() => null);
|
|
212
|
-
if (budget && budget.totalSats !== null && budget.totalSats - budget.usedSats < allIn) {
|
|
213
|
-
throw new LightningPaymentError("LIGHTNING_BUDGET_EXHAUSTED", `The Lightning wallet's remaining budget (${budget.totalSats - budget.usedSats} sats) cannot cover ${allIn} sats.`, { remaining_sats: budget.totalSats - budget.usedSats, required_sats: allIn, next_action: "pay over x402 (run402 init --switch-rail), or ask the platform for a new wallet" });
|
|
214
|
-
}
|
|
248
|
+
await checkLightningCaps(wallet, challenge.amountSats);
|
|
215
249
|
let preimage;
|
|
216
250
|
try {
|
|
217
251
|
preimage = (await wallet.payInvoice(challenge.invoice)).preimage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lightning-paid-fetch.js","sourceRoot":"","sources":["../../src/node/lightning-paid-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,kBAAkB,EAAuB,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAI/C,MAAM,CAAC,MAAM,4BAA4B,GAAG,+CAA+C,CAAC;AAC5F,MAAM,cAAc,GAAG,4BAA4B,4BAA4B,sBAAsB,CAAC;AACtG,0FAA0F;AAC1F,MAAM,iBAAiB,GAAG,EAAE,CA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AAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
type FetchFn = typeof globalThis.fetch;
|
|
2
|
+
export interface X402LnbtcRequirements {
|
|
3
|
+
scheme: string;
|
|
4
|
+
network: string;
|
|
5
|
+
amount: string;
|
|
6
|
+
asset: string;
|
|
7
|
+
payTo: string;
|
|
8
|
+
maxTimeoutSeconds: number;
|
|
9
|
+
extra: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
export interface X402LnbtcOffer {
|
|
12
|
+
paymentRequired: {
|
|
13
|
+
x402Version: number;
|
|
14
|
+
resource?: {
|
|
15
|
+
url?: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
mimeType?: string;
|
|
18
|
+
};
|
|
19
|
+
accepts: X402LnbtcRequirements[];
|
|
20
|
+
};
|
|
21
|
+
requirements: X402LnbtcRequirements;
|
|
22
|
+
}
|
|
23
|
+
/** The thrown error type, shared with the MPP Lightning buyer. */
|
|
24
|
+
export interface X402LnbtcErrorFactory {
|
|
25
|
+
(code: string, message: string, details?: Record<string, unknown>): Error;
|
|
26
|
+
}
|
|
27
|
+
export interface X402LnbtcWallet {
|
|
28
|
+
payInvoice(bolt11: string): Promise<{
|
|
29
|
+
preimage: string;
|
|
30
|
+
}>;
|
|
31
|
+
lookupInvoice(paymentHash: string): Promise<{
|
|
32
|
+
state: string | null;
|
|
33
|
+
preimage: string | null;
|
|
34
|
+
} | null>;
|
|
35
|
+
}
|
|
36
|
+
/** A POST to a Run402 surface that offers x402 on Lightning. */
|
|
37
|
+
export declare function isX402LightningCandidate(input: RequestInfo | URL, init: RequestInit | undefined): boolean;
|
|
38
|
+
/** The x402 v2 challenge's `exact` entry on an `lnbtc:` network with an invoice, or null. */
|
|
39
|
+
export declare function readX402LightningOffer(response: Response): X402LnbtcOffer | null;
|
|
40
|
+
/**
|
|
41
|
+
* The request headers made explicit: a string body without a content type is
|
|
42
|
+
* sent by fetch as `text/plain;charset=UTF-8`, and the request hash must bind
|
|
43
|
+
* the value actually sent, so it is set here rather than left to fetch.
|
|
44
|
+
*/
|
|
45
|
+
export declare function explicitRequestHeaders(init: RequestInit | undefined): Headers;
|
|
46
|
+
export interface PayX402LightningOptions {
|
|
47
|
+
input: RequestInfo | URL;
|
|
48
|
+
init: RequestInit | undefined;
|
|
49
|
+
offer: X402LnbtcOffer;
|
|
50
|
+
wallet: X402LnbtcWallet;
|
|
51
|
+
baseFetch: FetchFn;
|
|
52
|
+
fail: X402LnbtcErrorFactory;
|
|
53
|
+
/** Checks the all-in cost (sats) against the rail's ceiling and the wallet's budget; throws to refuse. */
|
|
54
|
+
checkCaps: (amountSats: number) => Promise<void>;
|
|
55
|
+
onPaid?: (paymentHash: string) => void;
|
|
56
|
+
/** Unix seconds; the invoice checks' clock. Tests pin it; production uses the system clock. */
|
|
57
|
+
clock?: () => number;
|
|
58
|
+
}
|
|
59
|
+
/** Pay the offer and send the paid retry. */
|
|
60
|
+
export declare function payX402Lightning(options: PayX402LightningOptions): Promise<Response>;
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=lightning-x402-lnbtc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lightning-x402-lnbtc.d.ts","sourceRoot":"","sources":["../../src/node/lightning-x402-lnbtc.ts"],"names":[],"mappings":"AAsBA,KAAK,OAAO,GAAG,OAAO,UAAU,CAAC,KAAK,CAAC;AAQvC,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,MAAM,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,cAAc;IAC7B,eAAe,EAAE;QACf,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,EAAE;YA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qB,CAAC;IAC5B,0GAA0G;IAC1G,SAAS,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,+FAA+F;IAC/F,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;CACtB;AAED,6CAA6C;AAC7C,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuF1F"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Lightning rail's x402 buyer: pays the x402 Foundation's `exact` scheme on
|
|
3
|
+
* Bitcoin Lightning (`lnbtc`) from the agent's own Lightning wallet.
|
|
4
|
+
*
|
|
5
|
+
* The seller's 402 carries an `accepts[]` entry on an `lnbtc:` network whose
|
|
6
|
+
* `extra.invoice` is a BOLT11 invoice committing (by description hash) to the
|
|
7
|
+
* exact request. The vendored client scheme recomputes that request hash from
|
|
8
|
+
* the request this buyer is about to send, refuses to pay anything bound to
|
|
9
|
+
* another request or signed by another key, pays, and checks the preimage.
|
|
10
|
+
* The paid retry is the same request plus `PAYMENT-SIGNATURE`.
|
|
11
|
+
*
|
|
12
|
+
* Run402 offers it on `POST /generate-image/v1` (spec `x402-lightning-exact`);
|
|
13
|
+
* the Lightning fetch prefers it there over MPP Lightning. The preimage and the
|
|
14
|
+
* pairing secret never reach a log or an error.
|
|
15
|
+
*/
|
|
16
|
+
import { decodeInvoice } from "./vendor/x402-lnbtc/bolt11.js";
|
|
17
|
+
import { httpRequestBinding } from "./vendor/x402-lnbtc/binding.js";
|
|
18
|
+
import { LnbtcError } from "./vendor/x402-lnbtc/constants.js";
|
|
19
|
+
import { ExactLnbtcScheme } from "./vendor/x402-lnbtc/exact/client/scheme.js";
|
|
20
|
+
import { NwcError } from "./nwc.js";
|
|
21
|
+
/** Run402 surfaces that offer x402 `exact` on `lnbtc`. */
|
|
22
|
+
const X402_LNBTC_PATHS = [/^\/generate-image\/v1$/];
|
|
23
|
+
/** The fetch default for a string body without an explicit content type. */
|
|
24
|
+
const STRING_BODY_CONTENT_TYPE = "text/plain;charset=UTF-8";
|
|
25
|
+
function requestUrl(input) {
|
|
26
|
+
return typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
|
27
|
+
}
|
|
28
|
+
/** A POST to a Run402 surface that offers x402 on Lightning. */
|
|
29
|
+
export function isX402LightningCandidate(input, init) {
|
|
30
|
+
const method = (init?.method ?? (typeof input === "object" && "method" in input ? input.method : "GET")).toUpperCase();
|
|
31
|
+
if (method !== "POST")
|
|
32
|
+
return false;
|
|
33
|
+
try {
|
|
34
|
+
return X402_LNBTC_PATHS.some((pattern) => pattern.test(new URL(requestUrl(input)).pathname));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** The x402 v2 challenge's `exact` entry on an `lnbtc:` network with an invoice, or null. */
|
|
41
|
+
export function readX402LightningOffer(response) {
|
|
42
|
+
if (response.status !== 402)
|
|
43
|
+
return null;
|
|
44
|
+
const header = response.headers.get("payment-required");
|
|
45
|
+
if (!header)
|
|
46
|
+
return null;
|
|
47
|
+
let decoded;
|
|
48
|
+
try {
|
|
49
|
+
decoded = JSON.parse(Buffer.from(header, "base64").toString("utf8"));
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const paymentRequired = decoded;
|
|
55
|
+
if (!paymentRequired || paymentRequired.x402Version !== 2 || !Array.isArray(paymentRequired.accepts))
|
|
56
|
+
return null;
|
|
57
|
+
const requirements = paymentRequired.accepts.find((entry) => entry?.scheme === "exact" &&
|
|
58
|
+
typeof entry.network === "string" && entry.network.startsWith("lnbtc:") &&
|
|
59
|
+
typeof entry.extra?.invoice === "string" && entry.extra.invoice.length > 0);
|
|
60
|
+
return requirements ? { paymentRequired, requirements } : null;
|
|
61
|
+
}
|
|
62
|
+
/** The body bytes exactly as fetch will send them, or null when they cannot be known up front. */
|
|
63
|
+
function bodyBytes(body) {
|
|
64
|
+
if (body === undefined || body === null)
|
|
65
|
+
return new Uint8Array(0);
|
|
66
|
+
if (typeof body === "string")
|
|
67
|
+
return new TextEncoder().encode(body);
|
|
68
|
+
if (body instanceof Uint8Array)
|
|
69
|
+
return body;
|
|
70
|
+
if (body instanceof ArrayBuffer)
|
|
71
|
+
return new Uint8Array(body);
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The request headers made explicit: a string body without a content type is
|
|
76
|
+
* sent by fetch as `text/plain;charset=UTF-8`, and the request hash must bind
|
|
77
|
+
* the value actually sent, so it is set here rather than left to fetch.
|
|
78
|
+
*/
|
|
79
|
+
export function explicitRequestHeaders(init) {
|
|
80
|
+
const headers = new Headers(init?.headers ?? {});
|
|
81
|
+
if (typeof init?.body === "string" && !headers.has("content-type")) {
|
|
82
|
+
headers.set("content-type", STRING_BODY_CONTENT_TYPE);
|
|
83
|
+
}
|
|
84
|
+
return headers;
|
|
85
|
+
}
|
|
86
|
+
/** Pay the offer and send the paid retry. */
|
|
87
|
+
export async function payX402Lightning(options) {
|
|
88
|
+
const { input, init, offer, wallet, fail } = options;
|
|
89
|
+
const url = requestUrl(input);
|
|
90
|
+
const method = (init?.method ?? "POST").toUpperCase();
|
|
91
|
+
const bytes = bodyBytes(init?.body);
|
|
92
|
+
if (!bytes) {
|
|
93
|
+
throw fail("LIGHTNING_BODY_NOT_REPLAYABLE", "An x402 Lightning payment binds the exact body bytes; a streamed body cannot be paid for.");
|
|
94
|
+
}
|
|
95
|
+
const headers = explicitRequestHeaders(init);
|
|
96
|
+
const params = offer.requirements.extra.requestBindingParams;
|
|
97
|
+
const boundHeaders = Array.isArray(params?.headers) ? params.headers.filter((name) => typeof name === "string") : [];
|
|
98
|
+
const amountMsat = BigInt(offer.requirements.amount);
|
|
99
|
+
await options.checkCaps(Number((amountMsat + 999n) / 1000n));
|
|
100
|
+
const payer = {
|
|
101
|
+
payInvoice: async (invoice) => {
|
|
102
|
+
const decoded = decodeInvoice(invoice);
|
|
103
|
+
let preimage;
|
|
104
|
+
try {
|
|
105
|
+
preimage = (await wallet.payInvoice(invoice)).preimage;
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
// Unknown outcome: resolve by hash before ever paying again.
|
|
109
|
+
if (error instanceof NwcError && (error.code === "TIMEOUT" || error.code === "RELAY_CLOSED" || error.code === "RELAY_UNREACHABLE")) {
|
|
110
|
+
const looked = await wallet.lookupInvoice(decoded.paymentHash).catch(() => null);
|
|
111
|
+
if (!looked?.preimage) {
|
|
112
|
+
throw fail("LIGHTNING_PAYMENT_OUTCOME_UNKNOWN", "The Lightning payment's outcome is unknown; check the wallet before paying again.", { payment_hash: decoded.paymentHash });
|
|
113
|
+
}
|
|
114
|
+
preimage = looked.preimage;
|
|
115
|
+
}
|
|
116
|
+
else if (error instanceof NwcError) {
|
|
117
|
+
throw fail(`LIGHTNING_${error.code}`, `The Lightning wallet refused the payment (${error.code}).`, { payment_hash: decoded.paymentHash, next_action: "pay over x402 (run402 init --switch-rail)" });
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return { invoice, paymentHash: decoded.paymentHash, amountMsat: decoded.amountMsat, status: "paid", preimage };
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
const scheme = new ExactLnbtcScheme({
|
|
127
|
+
payer,
|
|
128
|
+
...(options.clock ? { clock: options.clock } : {}),
|
|
129
|
+
requestBinding: () => httpRequestBinding({
|
|
130
|
+
method,
|
|
131
|
+
url,
|
|
132
|
+
body: bytes,
|
|
133
|
+
boundHeaders,
|
|
134
|
+
getHeader: (name) => (headers.has(name) ? [headers.get(name)] : undefined),
|
|
135
|
+
}),
|
|
136
|
+
});
|
|
137
|
+
let payload;
|
|
138
|
+
try {
|
|
139
|
+
const abort = await scheme.schemeHooks.onBeforePaymentCreation?.({
|
|
140
|
+
paymentRequired: offer.paymentRequired,
|
|
141
|
+
selectedRequirements: offer.requirements,
|
|
142
|
+
});
|
|
143
|
+
if (abort && "abort" in abort && abort.abort) {
|
|
144
|
+
throw new LnbtcError(abort.reason);
|
|
145
|
+
}
|
|
146
|
+
const result = await scheme.createPaymentPayload(2, offer.requirements);
|
|
147
|
+
payload = result.payload;
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
if (error instanceof LnbtcError) {
|
|
151
|
+
const mismatch = error.reason === "invalid_exact_lnbtc_request_mismatch" ||
|
|
152
|
+
error.reason === "invalid_exact_lnbtc_invoice_request_mismatch";
|
|
153
|
+
throw fail(mismatch ? "LIGHTNING_REQUEST_BINDING_MISMATCH" : "LIGHTNING_X402_INVOICE_REFUSED", mismatch
|
|
154
|
+
? "The seller's Lightning invoice is bound to a different request than the one being sent; nothing was paid."
|
|
155
|
+
: `The seller's x402 Lightning offer failed validation (${error.reason}); nothing was paid.`, { reason: error.reason });
|
|
156
|
+
}
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
const paymentHash = decodeInvoice(String(offer.requirements.extra.invoice)).paymentHash;
|
|
160
|
+
options.onPaid?.(paymentHash);
|
|
161
|
+
const signature = Buffer.from(JSON.stringify({
|
|
162
|
+
x402Version: 2,
|
|
163
|
+
resource: offer.paymentRequired.resource,
|
|
164
|
+
accepted: offer.requirements,
|
|
165
|
+
payload,
|
|
166
|
+
})).toString("base64");
|
|
167
|
+
headers.set("payment-signature", signature);
|
|
168
|
+
return options.baseFetch(input, { ...init, headers });
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=lightning-x402-lnbtc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lightning-x402-lnbtc.js","sourceRoot":"","sources":["../../src/node/lightning-x402-lnbtc.ts"],"names":[],"mappings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AC,CAAC;IACvB,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,SAAS,CAAC,CAAC;IAC5C,OAAO,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Vendored: x402 `exact` on Lightning (`lnbtc`), client side
|
|
2
|
+
|
|
3
|
+
- Source: https://github.com/x402-foundation/x402, pull request #3688
|
|
4
|
+
(`typescript/packages/mechanisms/lnbtc/src`)
|
|
5
|
+
- Commit: `896a7bd0ce3093d8ae5a4401b96468e37c4a6204`
|
|
6
|
+
- License: Apache-2.0 (`LICENSE` in this directory)
|
|
7
|
+
|
|
8
|
+
`@x402/lnbtc` is not on npm yet, so the Node SDK carries the part its Lightning
|
|
9
|
+
buyer needs: the request binding, the BOLT11 decoder, the validation rules, and
|
|
10
|
+
the `exact` client scheme. The server and facilitator halves live in the Run402
|
|
11
|
+
gateway. Remove this directory and import `@x402/lnbtc` once it is published.
|
|
12
|
+
The change that added it is `x402-lnbtc-image-demo` (run402-private).
|
|
13
|
+
|
|
14
|
+
Local modifications, and nothing else:
|
|
15
|
+
|
|
16
|
+
- Relative imports carry `.js` (`./binding` → `./binding.js`).
|
|
17
|
+
- `@noble/curves` and `@noble/hashes` imports carry `.js`, the subpath form of
|
|
18
|
+
the v2 packages the SDK depends on.
|
|
19
|
+
- `@noble/curves` v2 API names: `Signature.fromBytes(sig, "compact")` for
|
|
20
|
+
`Signature.fromCompact(sig)`, `Point` for `ProjectivePoint`, and
|
|
21
|
+
`prehash: false` on `verify`, because v2 hashes the message by default and
|
|
22
|
+
the BOLT11 digest is already a hash.
|
|
23
|
+
|
|
24
|
+
`shared-vectors.test.ts` runs the upstream binding and client vectors
|
|
25
|
+
(`exact_lnbtc.vectors.json`, fixture version 1) against this copy.
|