|
1 | | -import { probe402 } from "./probe402.js"; |
| 1 | +import { probe402, wsToHttp } from "./util.js"; |
2 | 2 |
|
3 | 3 | export interface MppxClient { |
4 | | - fetch: typeof globalThis.fetch; |
5 | | - transport: { |
6 | | - setCredential(request: Request, credential: string): Request; |
7 | | - }; |
8 | | - createCredential(response: Response): Promise<string>; |
| 4 | + fetch: typeof globalThis.fetch; |
| 5 | + transport: { |
| 6 | + setCredential(request: Request, credential: string): Request; |
| 7 | + }; |
| 8 | + createCredential(response: Response): Promise<string>; |
9 | 9 | } |
10 | 10 |
|
11 | | -export async function getPaymentCredentials(wsUrl: string, mppx: MppxClient): Promise<Record<string, string>> { |
12 | | - const response = await probe402(wsUrl); |
| 11 | +export async function getPaymentCredentials( |
| 12 | + wsUrl: string, |
| 13 | + mppx: MppxClient |
| 14 | +): Promise<Record<string, string>> { |
| 15 | + const response = await probe402(wsUrl); |
13 | 16 |
|
14 | | - const credential = await mppx.createCredential(response); |
15 | | - const signed = mppx.transport.setCredential(new Request(wsUrl), credential); |
| 17 | + const credential = await mppx.createCredential(response); |
| 18 | + const signed = mppx.transport.setCredential( |
| 19 | + new Request(wsToHttp(wsUrl)), |
| 20 | + credential |
| 21 | + ); |
16 | 22 |
|
17 | | - const headers: Record<string, string> = {}; |
18 | | - signed.headers.forEach((value: string, key: string) => { |
19 | | - headers[key] = value; |
20 | | - }); |
21 | | - return headers; |
| 23 | + const headers: Record<string, string> = {}; |
| 24 | + signed.headers.forEach((value: string, key: string) => { |
| 25 | + headers[key] = value; |
| 26 | + }); |
| 27 | + return headers; |
22 | 28 | } |
0 commit comments