Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
"require": "./dist/cjs/x402.cjs",
"types": "./dist/types/x402.d.ts"
},
"./mpp": {
"import": "./dist/esm/mpp.js",
"require": "./dist/cjs/mpp.cjs",
"types": "./dist/types/mpp.d.ts"
},
"./lnurl": {
"import": "./dist/esm/lnurl.js",
"require": "./dist/cjs/lnurl.cjs",
Expand Down
1 change: 1 addition & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const entries = [
{ name: "402", input: "src/402/index.ts" },
{ name: "l402", input: "src/402/l402/index.ts" },
{ name: "x402", input: "src/402/x402/index.ts" },
{ name: "mpp", input: "src/402/mpp/index.ts" },
{ name: "lnurl", input: "src/lnurl/index.ts" },
{ name: "podcasting2", input: "src/podcasting2/index.ts" },
];
Expand Down
16 changes: 13 additions & 3 deletions src/402/fetch402.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { KVStorage, NoStorage, Wallet } from "./utils";
import { buildX402PaymentSignature } from "./x402/utils";
import { HEADER_KEY, handleL402Payment } from "./l402/l402";
import { handleX402Payment } from "./x402/x402";
import { handleMppChargePayment } from "./mpp/mpp";

const noStorage = new NoStorage();

Expand Down Expand Up @@ -59,10 +60,19 @@ export const fetch402 = async (
headers.set("Accept-Authenticate", HEADER_KEY);
const initResp = await fetch(url, fetchArgs);

const l402Header = initResp.headers.get("www-authenticate");
if (l402Header) {
const wwwAuthHeader = initResp.headers.get("www-authenticate");
if (wwwAuthHeader) {
if (wwwAuthHeader.trimStart().toLowerCase().startsWith("payment")) {
return handleMppChargePayment(
wwwAuthHeader,
url,
fetchArgs,
headers,
wallet,
);
}
return handleL402Payment(
l402Header,
wwwAuthHeader,
url,
fetchArgs,
headers,
Expand Down
2 changes: 2 additions & 0 deletions src/402/mpp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./mpp";
export * from "./utils";
Loading
Loading