@lntpay/sdk 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.
- package/CHANGELOG.md +4 -0
- package/LICENSE +21 -0
- package/README.md +100 -0
- package/dist/index.cjs +260 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +111 -0
- package/dist/index.d.ts +111 -0
- package/dist/index.js +229 -0
- package/dist/index.js.map +1 -0
- package/package.json +32 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LNTPay
|
|
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
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# @lntpay/sdk
|
|
2
|
+
|
|
3
|
+
Official LNTPay SDK for Node.js (TypeScript-first).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @lntpay/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Authentication
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import LNTPay from "@lntpay/sdk";
|
|
15
|
+
|
|
16
|
+
const client = new LNTPay({
|
|
17
|
+
apiKey: process.env.LNTPAY_API_KEY!
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Create a charge (BOLT11)
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
const charge = await client.charges.create({
|
|
25
|
+
amount: 2500,
|
|
26
|
+
currency: "USD",
|
|
27
|
+
memo: "Coffee"
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
console.log(charge.bolt11);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Create a withdrawal
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
const withdrawal = await client.withdrawals.create({
|
|
37
|
+
amount: 5000,
|
|
38
|
+
currency: "USD",
|
|
39
|
+
description: "Refund"
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Webhook signature validation
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import type { WebhookEvent } from "@lntpay/sdk";
|
|
47
|
+
|
|
48
|
+
const rawBody = req.body; // Buffer
|
|
49
|
+
const signatureHeader = req.headers["lntpay-signature"] as string;
|
|
50
|
+
|
|
51
|
+
const event = client.webhooks.constructEvent<WebhookEvent>(
|
|
52
|
+
rawBody,
|
|
53
|
+
signatureHeader,
|
|
54
|
+
process.env.LNTPAY_WEBHOOK_SECRET!
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
console.log(event.type);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Idempotency
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
await client.charges.create(
|
|
64
|
+
{ amount: 1000, currency: "USD" },
|
|
65
|
+
{ idempotencyKey: "charge-2026-02-02-0001" }
|
|
66
|
+
);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Request options and retries
|
|
70
|
+
|
|
71
|
+
`RequestOptions` supports `retries` for GET requests only. POST retries are ignored.
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
const charge = await client.charges.retrieve("ch_123", { retries: 2 });
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Examples
|
|
78
|
+
|
|
79
|
+
Examples live in `/examples`.
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
export LNTPAY_API_KEY="..."
|
|
83
|
+
export LNTPAY_WEBHOOK_SECRET="..."
|
|
84
|
+
# optional
|
|
85
|
+
export LNTPAY_BASE_URL="https://api.lntpay.com"
|
|
86
|
+
|
|
87
|
+
npm install
|
|
88
|
+
npm run build
|
|
89
|
+
node examples/node-pay-per-request.mjs
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Webhook receiver example:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
node examples/webhook-receiver.mjs
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
LNTPay: () => LNTPay,
|
|
24
|
+
LNTPayAPIError: () => LNTPayAPIError,
|
|
25
|
+
LNTPayError: () => LNTPayError,
|
|
26
|
+
LNTPayNetworkError: () => LNTPayNetworkError,
|
|
27
|
+
LNTPayWebhookSignatureError: () => LNTPayWebhookSignatureError,
|
|
28
|
+
default: () => index_default
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(index_exports);
|
|
31
|
+
|
|
32
|
+
// src/errors.ts
|
|
33
|
+
var LNTPayError = class extends Error {
|
|
34
|
+
constructor(message) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = "LNTPayError";
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var LNTPayAPIError = class extends LNTPayError {
|
|
40
|
+
status;
|
|
41
|
+
code;
|
|
42
|
+
type;
|
|
43
|
+
requestId;
|
|
44
|
+
raw;
|
|
45
|
+
constructor(message, status, opts) {
|
|
46
|
+
super(message);
|
|
47
|
+
this.name = "LNTPayAPIError";
|
|
48
|
+
this.status = status;
|
|
49
|
+
this.code = opts?.code;
|
|
50
|
+
this.type = opts?.type;
|
|
51
|
+
this.requestId = opts?.requestId;
|
|
52
|
+
this.raw = opts?.raw;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var LNTPayNetworkError = class extends LNTPayError {
|
|
56
|
+
constructor(message) {
|
|
57
|
+
super(message);
|
|
58
|
+
this.name = "LNTPayNetworkError";
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var LNTPayWebhookSignatureError = class extends LNTPayError {
|
|
62
|
+
constructor(message) {
|
|
63
|
+
super(message);
|
|
64
|
+
this.name = "LNTPayWebhookSignatureError";
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/internal/request.ts
|
|
69
|
+
async function request(config, method, path, body, options = {}) {
|
|
70
|
+
const url = buildUrl(config.baseUrl, path);
|
|
71
|
+
const retries = method.toUpperCase() === "GET" ? Math.max(0, options.retries ?? 0) : 0;
|
|
72
|
+
let lastError;
|
|
73
|
+
for (let attempt = 0; attempt <= retries; attempt += 1) {
|
|
74
|
+
try {
|
|
75
|
+
return await doFetch(config, method, url, body, options);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
if (err instanceof LNTPayNetworkError && attempt < retries) {
|
|
78
|
+
lastError = err;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
throw lastError instanceof Error ? lastError : new LNTPayNetworkError("Network error");
|
|
85
|
+
}
|
|
86
|
+
function buildUrl(baseUrl, path) {
|
|
87
|
+
const normalizedBase = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
88
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
89
|
+
return `${normalizedBase}${normalizedPath}`;
|
|
90
|
+
}
|
|
91
|
+
async function doFetch(config, method, url, body, options) {
|
|
92
|
+
const controller = new AbortController();
|
|
93
|
+
const timeoutMs = options.timeoutMs ?? config.timeoutMs;
|
|
94
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
95
|
+
const headers = {
|
|
96
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
97
|
+
"Content-Type": "application/json",
|
|
98
|
+
"User-Agent": config.userAgent,
|
|
99
|
+
...options.headers
|
|
100
|
+
};
|
|
101
|
+
if (options.idempotencyKey) {
|
|
102
|
+
headers["Idempotency-Key"] = options.idempotencyKey;
|
|
103
|
+
}
|
|
104
|
+
if (options.requestId) {
|
|
105
|
+
headers["X-Request-Id"] = options.requestId;
|
|
106
|
+
}
|
|
107
|
+
const hasBody = body !== void 0 && method.toUpperCase() !== "GET";
|
|
108
|
+
const init = {
|
|
109
|
+
method,
|
|
110
|
+
headers,
|
|
111
|
+
signal: controller.signal
|
|
112
|
+
};
|
|
113
|
+
if (hasBody) {
|
|
114
|
+
init.body = JSON.stringify(body);
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const response = await fetch(url, init);
|
|
118
|
+
clearTimeout(timeout);
|
|
119
|
+
if (!response.ok) {
|
|
120
|
+
const errorPayload = await safeJson(response);
|
|
121
|
+
const { message, code, type, request_id } = normalizeError(errorPayload);
|
|
122
|
+
throw new LNTPayAPIError(message ?? `HTTP ${response.status}`, response.status, {
|
|
123
|
+
code,
|
|
124
|
+
type,
|
|
125
|
+
requestId: request_id,
|
|
126
|
+
raw: errorPayload
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
if (response.status === 204) {
|
|
130
|
+
return void 0;
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
return await response.json();
|
|
134
|
+
} catch {
|
|
135
|
+
return void 0;
|
|
136
|
+
}
|
|
137
|
+
} catch (err) {
|
|
138
|
+
clearTimeout(timeout);
|
|
139
|
+
if (err instanceof LNTPayAPIError) {
|
|
140
|
+
throw err;
|
|
141
|
+
}
|
|
142
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
143
|
+
throw new LNTPayNetworkError(`Request timed out after ${timeoutMs}ms`);
|
|
144
|
+
}
|
|
145
|
+
throw new LNTPayNetworkError("Network error");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async function safeJson(response) {
|
|
149
|
+
try {
|
|
150
|
+
return await response.json();
|
|
151
|
+
} catch {
|
|
152
|
+
return void 0;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function normalizeError(payload) {
|
|
156
|
+
const typed = payload;
|
|
157
|
+
if (typed?.error) {
|
|
158
|
+
return {
|
|
159
|
+
message: typed.error.message,
|
|
160
|
+
code: typed.error.code,
|
|
161
|
+
type: typed.error.type,
|
|
162
|
+
request_id: typed.error.request_id
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
return {};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/webhooks.ts
|
|
169
|
+
var import_node_crypto = require("crypto");
|
|
170
|
+
function verifySignature(rawBody, signatureHeader, secret) {
|
|
171
|
+
if (!signatureHeader || !secret) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
const payload = typeof rawBody === "string" ? Buffer.from(rawBody, "utf8") : rawBody;
|
|
175
|
+
const expected = (0, import_node_crypto.createHmac)("sha256", secret).update(payload).digest("hex");
|
|
176
|
+
const candidates = extractSignatures(signatureHeader);
|
|
177
|
+
for (const candidate of candidates) {
|
|
178
|
+
if (safeEqual(candidate, expected)) {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
function constructEvent(rawBody, signatureHeader, secret) {
|
|
185
|
+
if (!verifySignature(rawBody, signatureHeader, secret)) {
|
|
186
|
+
throw new LNTPayWebhookSignatureError("Invalid webhook signature");
|
|
187
|
+
}
|
|
188
|
+
const body = typeof rawBody === "string" ? rawBody : rawBody.toString("utf8");
|
|
189
|
+
return JSON.parse(body);
|
|
190
|
+
}
|
|
191
|
+
function extractSignatures(signatureHeader) {
|
|
192
|
+
const trimmed = signatureHeader.trim();
|
|
193
|
+
if (trimmed.includes("v1=")) {
|
|
194
|
+
return trimmed.split(",").map((part) => part.trim()).filter((part) => part.startsWith("v1=")).map((part) => part.slice(3)).filter(Boolean);
|
|
195
|
+
}
|
|
196
|
+
return [trimmed];
|
|
197
|
+
}
|
|
198
|
+
function safeEqual(a, b) {
|
|
199
|
+
const aBuf = Buffer.from(a, "utf8");
|
|
200
|
+
const bBuf = Buffer.from(b, "utf8");
|
|
201
|
+
if (aBuf.length !== bBuf.length) {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
return (0, import_node_crypto.timingSafeEqual)(aBuf, bBuf);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// src/index.ts
|
|
208
|
+
var LNTPay = class {
|
|
209
|
+
apiKey;
|
|
210
|
+
baseUrl;
|
|
211
|
+
timeoutMs;
|
|
212
|
+
userAgent;
|
|
213
|
+
charges;
|
|
214
|
+
withdrawals;
|
|
215
|
+
webhooks;
|
|
216
|
+
constructor(config) {
|
|
217
|
+
if (!config?.apiKey) {
|
|
218
|
+
throw new LNTPayError("apiKey is required");
|
|
219
|
+
}
|
|
220
|
+
this.apiKey = config.apiKey;
|
|
221
|
+
this.baseUrl = config.baseUrl ?? "https://api.lntpay.com";
|
|
222
|
+
this.timeoutMs = config.timeoutMs ?? 3e4;
|
|
223
|
+
this.userAgent = config.userAgent ?? "@lntpay/sdk";
|
|
224
|
+
this.charges = {
|
|
225
|
+
create: (params, options) => this.request("POST", "/v0/charges", params, options),
|
|
226
|
+
retrieve: (chargeId, options) => this.request("GET", `/v0/charges/${encodeURIComponent(chargeId)}`, void 0, options)
|
|
227
|
+
};
|
|
228
|
+
this.withdrawals = {
|
|
229
|
+
create: (params, options) => this.request("POST", "/v0/withdrawals", params, options)
|
|
230
|
+
};
|
|
231
|
+
this.webhooks = {
|
|
232
|
+
verifySignature,
|
|
233
|
+
constructEvent
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
async request(method, path, body, options = {}) {
|
|
237
|
+
return request(
|
|
238
|
+
{
|
|
239
|
+
apiKey: this.apiKey,
|
|
240
|
+
baseUrl: this.baseUrl,
|
|
241
|
+
timeoutMs: this.timeoutMs,
|
|
242
|
+
userAgent: this.userAgent
|
|
243
|
+
},
|
|
244
|
+
method,
|
|
245
|
+
path,
|
|
246
|
+
body,
|
|
247
|
+
options
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
var index_default = LNTPay;
|
|
252
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
253
|
+
0 && (module.exports = {
|
|
254
|
+
LNTPay,
|
|
255
|
+
LNTPayAPIError,
|
|
256
|
+
LNTPayError,
|
|
257
|
+
LNTPayNetworkError,
|
|
258
|
+
LNTPayWebhookSignatureError
|
|
259
|
+
});
|
|
260
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/internal/request.ts","../src/webhooks.ts"],"sourcesContent":["import { request } from \"./internal/request\";\nimport { constructEvent, verifySignature } from \"./webhooks\";\nimport type {\n Charge,\n ChargeCreateParams,\n LNTPayErrorResponse,\n RequestOptions,\n Withdrawal,\n WithdrawalCreateParams,\n WebhookEvent\n} from \"./types\";\nimport {\n LNTPayAPIError,\n LNTPayError,\n LNTPayNetworkError,\n LNTPayWebhookSignatureError\n} from \"./errors\";\n\nexport interface LNTPayConfig {\n apiKey: string;\n baseUrl?: string;\n timeoutMs?: number;\n userAgent?: string;\n}\n\nexport class LNTPay {\n private apiKey: string;\n private baseUrl: string;\n private timeoutMs: number;\n private userAgent: string;\n\n charges: {\n create: (params: ChargeCreateParams, options?: RequestOptions) => Promise<Charge>;\n retrieve: (chargeId: string, options?: RequestOptions) => Promise<Charge>;\n };\n\n withdrawals: {\n create: (params: WithdrawalCreateParams, options?: RequestOptions) => Promise<Withdrawal>;\n };\n\n webhooks: {\n verifySignature: (rawBody: string | Buffer, signatureHeader: string, secret: string) => boolean;\n constructEvent: <T = WebhookEvent>(\n rawBody: string | Buffer,\n signatureHeader: string,\n secret: string\n ) => T;\n };\n\n constructor(config: LNTPayConfig) {\n if (!config?.apiKey) {\n throw new LNTPayError(\"apiKey is required\");\n }\n\n this.apiKey = config.apiKey;\n this.baseUrl = config.baseUrl ?? \"https://api.lntpay.com\";\n this.timeoutMs = config.timeoutMs ?? 30_000;\n this.userAgent = config.userAgent ?? \"@lntpay/sdk\";\n\n this.charges = {\n create: (params, options) => this.request<Charge>(\"POST\", \"/v0/charges\", params, options),\n retrieve: (chargeId, options) =>\n this.request<Charge>(\"GET\", `/v0/charges/${encodeURIComponent(chargeId)}`, undefined, options)\n };\n\n this.withdrawals = {\n create: (params, options) => this.request<Withdrawal>(\"POST\", \"/v0/withdrawals\", params, options)\n };\n\n this.webhooks = {\n verifySignature,\n constructEvent\n };\n }\n\n private async request<T>(\n method: string,\n path: string,\n body?: unknown,\n options: RequestOptions = {}\n ): Promise<T> {\n return request<T>(\n {\n apiKey: this.apiKey,\n baseUrl: this.baseUrl,\n timeoutMs: this.timeoutMs,\n userAgent: this.userAgent\n },\n method,\n path,\n body,\n options\n );\n }\n}\n\nexport {\n Charge,\n ChargeCreateParams,\n RequestOptions,\n LNTPayErrorResponse,\n Withdrawal,\n WithdrawalCreateParams,\n WebhookEvent,\n LNTPayAPIError,\n LNTPayError,\n LNTPayNetworkError,\n LNTPayWebhookSignatureError\n};\n\nexport default LNTPay;\n","export class LNTPayError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"LNTPayError\";\n }\n}\n\nexport class LNTPayAPIError extends LNTPayError {\n status: number;\n code?: string;\n type?: string;\n requestId?: string;\n raw?: unknown;\n\n constructor(message: string, status: number, opts?: { code?: string; type?: string; requestId?: string; raw?: unknown }) {\n super(message);\n this.name = \"LNTPayAPIError\";\n this.status = status;\n this.code = opts?.code;\n this.type = opts?.type;\n this.requestId = opts?.requestId;\n this.raw = opts?.raw;\n }\n}\n\nexport class LNTPayNetworkError extends LNTPayError {\n constructor(message: string) {\n super(message);\n this.name = \"LNTPayNetworkError\";\n }\n}\n\nexport class LNTPayWebhookSignatureError extends LNTPayError {\n constructor(message: string) {\n super(message);\n this.name = \"LNTPayWebhookSignatureError\";\n }\n}\n","import { LNTPayAPIError, LNTPayNetworkError } from \"../errors\";\nimport type { LNTPayErrorResponse, RequestOptions } from \"../types\";\n\nexport interface ClientConfig {\n apiKey: string;\n baseUrl: string;\n timeoutMs: number;\n userAgent: string;\n}\n\nexport async function request<T>(\n config: ClientConfig,\n method: string,\n path: string,\n body?: unknown,\n options: RequestOptions = {}\n): Promise<T> {\n const url = buildUrl(config.baseUrl, path);\n const retries = method.toUpperCase() === \"GET\" ? Math.max(0, options.retries ?? 0) : 0;\n\n let lastError: unknown;\n for (let attempt = 0; attempt <= retries; attempt += 1) {\n try {\n return await doFetch<T>(config, method, url, body, options);\n } catch (err) {\n if (err instanceof LNTPayNetworkError && attempt < retries) {\n lastError = err;\n continue;\n }\n throw err;\n }\n }\n\n throw lastError instanceof Error ? lastError : new LNTPayNetworkError(\"Network error\");\n}\n\nfunction buildUrl(baseUrl: string, path: string): string {\n const normalizedBase = baseUrl.endsWith(\"/\") ? baseUrl.slice(0, -1) : baseUrl;\n const normalizedPath = path.startsWith(\"/\") ? path : `/${path}`;\n return `${normalizedBase}${normalizedPath}`;\n}\n\nasync function doFetch<T>(\n config: ClientConfig,\n method: string,\n url: string,\n body: unknown,\n options: RequestOptions\n): Promise<T> {\n const controller = new AbortController();\n const timeoutMs = options.timeoutMs ?? config.timeoutMs;\n const timeout = setTimeout(() => controller.abort(), timeoutMs);\n\n const headers: Record<string, string> = {\n Authorization: `Bearer ${config.apiKey}`,\n \"Content-Type\": \"application/json\",\n \"User-Agent\": config.userAgent,\n ...options.headers\n };\n\n if (options.idempotencyKey) {\n headers[\"Idempotency-Key\"] = options.idempotencyKey;\n }\n\n if (options.requestId) {\n headers[\"X-Request-Id\"] = options.requestId;\n }\n\n const hasBody = body !== undefined && method.toUpperCase() !== \"GET\";\n const init: RequestInit = {\n method,\n headers,\n signal: controller.signal\n };\n\n if (hasBody) {\n init.body = JSON.stringify(body);\n }\n\n try {\n const response = await fetch(url, init);\n clearTimeout(timeout);\n\n if (!response.ok) {\n const errorPayload = await safeJson(response);\n const { message, code, type, request_id } = normalizeError(errorPayload);\n throw new LNTPayAPIError(message ?? `HTTP ${response.status}`, response.status, {\n code,\n type,\n requestId: request_id,\n raw: errorPayload\n });\n }\n\n if (response.status === 204) {\n return undefined as T;\n }\n\n try {\n return (await response.json()) as T;\n } catch {\n return undefined as T;\n }\n } catch (err) {\n clearTimeout(timeout);\n if (err instanceof LNTPayAPIError) {\n throw err;\n }\n if (err instanceof Error && err.name === \"AbortError\") {\n throw new LNTPayNetworkError(`Request timed out after ${timeoutMs}ms`);\n }\n throw new LNTPayNetworkError(\"Network error\");\n }\n}\n\nasync function safeJson(response: Response): Promise<unknown> {\n try {\n return await response.json();\n } catch {\n return undefined;\n }\n}\n\nfunction normalizeError(payload: unknown): {\n message?: string;\n code?: string;\n type?: string;\n request_id?: string;\n} {\n const typed = payload as LNTPayErrorResponse | undefined;\n if (typed?.error) {\n return {\n message: typed.error.message,\n code: typed.error.code,\n type: typed.error.type,\n request_id: typed.error.request_id\n };\n }\n return {};\n}\n","import { timingSafeEqual, createHmac } from \"node:crypto\";\nimport { LNTPayWebhookSignatureError } from \"./errors\";\n\nexport function verifySignature(rawBody: string | Buffer, signatureHeader: string, secret: string): boolean {\n if (!signatureHeader || !secret) {\n return false;\n }\n\n const payload = typeof rawBody === \"string\" ? Buffer.from(rawBody, \"utf8\") : rawBody;\n const expected = createHmac(\"sha256\", secret).update(payload).digest(\"hex\");\n const candidates = extractSignatures(signatureHeader);\n\n for (const candidate of candidates) {\n if (safeEqual(candidate, expected)) {\n return true;\n }\n }\n\n return false;\n}\n\nexport function constructEvent<T>(\n rawBody: string | Buffer,\n signatureHeader: string,\n secret: string\n): T {\n if (!verifySignature(rawBody, signatureHeader, secret)) {\n throw new LNTPayWebhookSignatureError(\"Invalid webhook signature\");\n }\n\n const body = typeof rawBody === \"string\" ? rawBody : rawBody.toString(\"utf8\");\n return JSON.parse(body) as T;\n}\n\nfunction extractSignatures(signatureHeader: string): string[] {\n const trimmed = signatureHeader.trim();\n if (trimmed.includes(\"v1=\")) {\n return trimmed\n .split(\",\")\n .map((part) => part.trim())\n .filter((part) => part.startsWith(\"v1=\"))\n .map((part) => part.slice(3))\n .filter(Boolean);\n }\n return [trimmed];\n}\n\nfunction safeEqual(a: string, b: string): boolean {\n const aBuf = Buffer.from(a, \"utf8\");\n const bBuf = Buffer.from(b, \"utf8\");\n if (aBuf.length !== bBuf.length) {\n return false;\n }\n return timingSafeEqual(aBuf, bBuf);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,cAAN,cAA0B,MAAM;AAAA,EACrC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,iBAAN,cAA6B,YAAY;AAAA,EAC9C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY,SAAiB,QAAgB,MAA4E;AACvH,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO,MAAM;AAClB,SAAK,OAAO,MAAM;AAClB,SAAK,YAAY,MAAM;AACvB,SAAK,MAAM,MAAM;AAAA,EACnB;AACF;AAEO,IAAM,qBAAN,cAAiC,YAAY;AAAA,EAClD,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,8BAAN,cAA0C,YAAY;AAAA,EAC3D,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;AC3BA,eAAsB,QACpB,QACA,QACA,MACA,MACA,UAA0B,CAAC,GACf;AACZ,QAAM,MAAM,SAAS,OAAO,SAAS,IAAI;AACzC,QAAM,UAAU,OAAO,YAAY,MAAM,QAAQ,KAAK,IAAI,GAAG,QAAQ,WAAW,CAAC,IAAI;AAErF,MAAI;AACJ,WAAS,UAA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AK,YAAY,OAAO,aAAa;AACrC,SAAK,YAAY,OAAO,aAAa;AAErC,SAAK,UAAU;AAAA,MACb,QAAQ,CAAC,QAAQ,YAAY,KAAK,QAAgB,QAAQ,eAAe,QAAQ,OAAO;AAAA,MACxF,UAAU,CAAC,UAAU,YACnB,KAAK,QAAgB,OAAO,eAAe,mBAAmB,QAAQ,CAAC,IAAI,QAAW,OAAO;AAAA,IACjG;AAEA,SAAK,cAAc;AAAA,MACjB,QAAQ,CAAC,QAAQ,YAAY,KAAK,QAAoB,QAAQ,mBAAmB,QAAQ,OAAO;AAAA,IAClG;AAEA,SAAK,WAAW;AAAA,MACd;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAc,QACZ,QACA,MACA,MACA,UAA0B,CAAC,GACf;AACZ,WAAO;AAAA,MACL;AAAA,QACE,QAAQ,KAAK;AAAA,QACb,SAAS,KAAK;AAAA,QACd,WAAW,KAAK;AAAA,QAChB,WAAW,KAAK;AAAA,MAClB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAgBA,IAAO,gBAAQ;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
interface RequestOptions {
|
|
2
|
+
idempotencyKey?: string;
|
|
3
|
+
requestId?: string;
|
|
4
|
+
timeoutMs?: number;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
retries?: number;
|
|
7
|
+
}
|
|
8
|
+
interface LNTPayErrorResponse {
|
|
9
|
+
error: {
|
|
10
|
+
code: string;
|
|
11
|
+
message: string;
|
|
12
|
+
type?: string;
|
|
13
|
+
request_id?: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
type ChargeStatus = "pending" | "paid" | "expired" | "canceled" | string;
|
|
17
|
+
interface Charge {
|
|
18
|
+
id: string;
|
|
19
|
+
amount?: number;
|
|
20
|
+
currency?: string;
|
|
21
|
+
status?: ChargeStatus;
|
|
22
|
+
bolt11?: string;
|
|
23
|
+
created_at?: string;
|
|
24
|
+
expires_at?: string;
|
|
25
|
+
metadata?: Record<string, unknown>;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
interface ChargeCreateParams {
|
|
29
|
+
amount: number;
|
|
30
|
+
currency?: string;
|
|
31
|
+
memo?: string;
|
|
32
|
+
metadata?: Record<string, unknown>;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
}
|
|
35
|
+
type WithdrawalStatus = "pending" | "paid" | "expired" | "canceled" | string;
|
|
36
|
+
interface Withdrawal {
|
|
37
|
+
id: string;
|
|
38
|
+
amount?: number;
|
|
39
|
+
currency?: string;
|
|
40
|
+
status?: WithdrawalStatus;
|
|
41
|
+
lnurl?: string;
|
|
42
|
+
created_at?: string;
|
|
43
|
+
expires_at?: string;
|
|
44
|
+
metadata?: Record<string, unknown>;
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
}
|
|
47
|
+
interface WithdrawalCreateParams {
|
|
48
|
+
amount: number;
|
|
49
|
+
currency?: string;
|
|
50
|
+
description?: string;
|
|
51
|
+
metadata?: Record<string, unknown>;
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
}
|
|
54
|
+
interface WebhookEvent<T = unknown> {
|
|
55
|
+
id: string;
|
|
56
|
+
type: string;
|
|
57
|
+
data: T;
|
|
58
|
+
created_at?: string;
|
|
59
|
+
[key: string]: unknown;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
declare class LNTPayError extends Error {
|
|
63
|
+
constructor(message: string);
|
|
64
|
+
}
|
|
65
|
+
declare class LNTPayAPIError extends LNTPayError {
|
|
66
|
+
status: number;
|
|
67
|
+
code?: string;
|
|
68
|
+
type?: string;
|
|
69
|
+
requestId?: string;
|
|
70
|
+
raw?: unknown;
|
|
71
|
+
constructor(message: string, status: number, opts?: {
|
|
72
|
+
code?: string;
|
|
73
|
+
type?: string;
|
|
74
|
+
requestId?: string;
|
|
75
|
+
raw?: unknown;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
declare class LNTPayNetworkError extends LNTPayError {
|
|
79
|
+
constructor(message: string);
|
|
80
|
+
}
|
|
81
|
+
declare class LNTPayWebhookSignatureError extends LNTPayError {
|
|
82
|
+
constructor(message: string);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface LNTPayConfig {
|
|
86
|
+
apiKey: string;
|
|
87
|
+
baseUrl?: string;
|
|
88
|
+
timeoutMs?: number;
|
|
89
|
+
userAgent?: string;
|
|
90
|
+
}
|
|
91
|
+
declare class LNTPay {
|
|
92
|
+
private apiKey;
|
|
93
|
+
private baseUrl;
|
|
94
|
+
private timeoutMs;
|
|
95
|
+
private userAgent;
|
|
96
|
+
charges: {
|
|
97
|
+
create: (params: ChargeCreateParams, options?: RequestOptions) => Promise<Charge>;
|
|
98
|
+
retrieve: (chargeId: string, options?: RequestOptions) => Promise<Charge>;
|
|
99
|
+
};
|
|
100
|
+
withdrawals: {
|
|
101
|
+
create: (params: WithdrawalCreateParams, options?: RequestOptions) => Promise<Withdrawal>;
|
|
102
|
+
};
|
|
103
|
+
webhooks: {
|
|
104
|
+
verifySignature: (rawBody: string | Buffer, signatureHeader: string, secret: string) => boolean;
|
|
105
|
+
constructEvent: <T = WebhookEvent>(rawBody: string | Buffer, signatureHeader: string, secret: string) => T;
|
|
106
|
+
};
|
|
107
|
+
constructor(config: LNTPayConfig);
|
|
108
|
+
private request;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { type Charge, type ChargeCreateParams, LNTPay, LNTPayAPIError, type LNTPayConfig, LNTPayError, type LNTPayErrorResponse, LNTPayNetworkError, LNTPayWebhookSignatureError, type RequestOptions, type WebhookEvent, type Withdrawal, type WithdrawalCreateParams, LNTPay as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
interface RequestOptions {
|
|
2
|
+
idempotencyKey?: string;
|
|
3
|
+
requestId?: string;
|
|
4
|
+
timeoutMs?: number;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
retries?: number;
|
|
7
|
+
}
|
|
8
|
+
interface LNTPayErrorResponse {
|
|
9
|
+
error: {
|
|
10
|
+
code: string;
|
|
11
|
+
message: string;
|
|
12
|
+
type?: string;
|
|
13
|
+
request_id?: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
type ChargeStatus = "pending" | "paid" | "expired" | "canceled" | string;
|
|
17
|
+
interface Charge {
|
|
18
|
+
id: string;
|
|
19
|
+
amount?: number;
|
|
20
|
+
currency?: string;
|
|
21
|
+
status?: ChargeStatus;
|
|
22
|
+
bolt11?: string;
|
|
23
|
+
created_at?: string;
|
|
24
|
+
expires_at?: string;
|
|
25
|
+
metadata?: Record<string, unknown>;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
interface ChargeCreateParams {
|
|
29
|
+
amount: number;
|
|
30
|
+
currency?: string;
|
|
31
|
+
memo?: string;
|
|
32
|
+
metadata?: Record<string, unknown>;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
}
|
|
35
|
+
type WithdrawalStatus = "pending" | "paid" | "expired" | "canceled" | string;
|
|
36
|
+
interface Withdrawal {
|
|
37
|
+
id: string;
|
|
38
|
+
amount?: number;
|
|
39
|
+
currency?: string;
|
|
40
|
+
status?: WithdrawalStatus;
|
|
41
|
+
lnurl?: string;
|
|
42
|
+
created_at?: string;
|
|
43
|
+
expires_at?: string;
|
|
44
|
+
metadata?: Record<string, unknown>;
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
}
|
|
47
|
+
interface WithdrawalCreateParams {
|
|
48
|
+
amount: number;
|
|
49
|
+
currency?: string;
|
|
50
|
+
description?: string;
|
|
51
|
+
metadata?: Record<string, unknown>;
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
}
|
|
54
|
+
interface WebhookEvent<T = unknown> {
|
|
55
|
+
id: string;
|
|
56
|
+
type: string;
|
|
57
|
+
data: T;
|
|
58
|
+
created_at?: string;
|
|
59
|
+
[key: string]: unknown;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
declare class LNTPayError extends Error {
|
|
63
|
+
constructor(message: string);
|
|
64
|
+
}
|
|
65
|
+
declare class LNTPayAPIError extends LNTPayError {
|
|
66
|
+
status: number;
|
|
67
|
+
code?: string;
|
|
68
|
+
type?: string;
|
|
69
|
+
requestId?: string;
|
|
70
|
+
raw?: unknown;
|
|
71
|
+
constructor(message: string, status: number, opts?: {
|
|
72
|
+
code?: string;
|
|
73
|
+
type?: string;
|
|
74
|
+
requestId?: string;
|
|
75
|
+
raw?: unknown;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
declare class LNTPayNetworkError extends LNTPayError {
|
|
79
|
+
constructor(message: string);
|
|
80
|
+
}
|
|
81
|
+
declare class LNTPayWebhookSignatureError extends LNTPayError {
|
|
82
|
+
constructor(message: string);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface LNTPayConfig {
|
|
86
|
+
apiKey: string;
|
|
87
|
+
baseUrl?: string;
|
|
88
|
+
timeoutMs?: number;
|
|
89
|
+
userAgent?: string;
|
|
90
|
+
}
|
|
91
|
+
declare class LNTPay {
|
|
92
|
+
private apiKey;
|
|
93
|
+
private baseUrl;
|
|
94
|
+
private timeoutMs;
|
|
95
|
+
private userAgent;
|
|
96
|
+
charges: {
|
|
97
|
+
create: (params: ChargeCreateParams, options?: RequestOptions) => Promise<Charge>;
|
|
98
|
+
retrieve: (chargeId: string, options?: RequestOptions) => Promise<Charge>;
|
|
99
|
+
};
|
|
100
|
+
withdrawals: {
|
|
101
|
+
create: (params: WithdrawalCreateParams, options?: RequestOptions) => Promise<Withdrawal>;
|
|
102
|
+
};
|
|
103
|
+
webhooks: {
|
|
104
|
+
verifySignature: (rawBody: string | Buffer, signatureHeader: string, secret: string) => boolean;
|
|
105
|
+
constructEvent: <T = WebhookEvent>(rawBody: string | Buffer, signatureHeader: string, secret: string) => T;
|
|
106
|
+
};
|
|
107
|
+
constructor(config: LNTPayConfig);
|
|
108
|
+
private request;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { type Charge, type ChargeCreateParams, LNTPay, LNTPayAPIError, type LNTPayConfig, LNTPayError, type LNTPayErrorResponse, LNTPayNetworkError, LNTPayWebhookSignatureError, type RequestOptions, type WebhookEvent, type Withdrawal, type WithdrawalCreateParams, LNTPay as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var LNTPayError = class extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "LNTPayError";
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
var LNTPayAPIError = class extends LNTPayError {
|
|
9
|
+
status;
|
|
10
|
+
code;
|
|
11
|
+
type;
|
|
12
|
+
requestId;
|
|
13
|
+
raw;
|
|
14
|
+
constructor(message, status, opts) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "LNTPayAPIError";
|
|
17
|
+
this.status = status;
|
|
18
|
+
this.code = opts?.code;
|
|
19
|
+
this.type = opts?.type;
|
|
20
|
+
this.requestId = opts?.requestId;
|
|
21
|
+
this.raw = opts?.raw;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var LNTPayNetworkError = class extends LNTPayError {
|
|
25
|
+
constructor(message) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.name = "LNTPayNetworkError";
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var LNTPayWebhookSignatureError = class extends LNTPayError {
|
|
31
|
+
constructor(message) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = "LNTPayWebhookSignatureError";
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/internal/request.ts
|
|
38
|
+
async function request(config, method, path, body, options = {}) {
|
|
39
|
+
const url = buildUrl(config.baseUrl, path);
|
|
40
|
+
const retries = method.toUpperCase() === "GET" ? Math.max(0, options.retries ?? 0) : 0;
|
|
41
|
+
let lastError;
|
|
42
|
+
for (let attempt = 0; attempt <= retries; attempt += 1) {
|
|
43
|
+
try {
|
|
44
|
+
return await doFetch(config, method, url, body, options);
|
|
45
|
+
} catch (err) {
|
|
46
|
+
if (err instanceof LNTPayNetworkError && attempt < retries) {
|
|
47
|
+
lastError = err;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
throw lastError instanceof Error ? lastError : new LNTPayNetworkError("Network error");
|
|
54
|
+
}
|
|
55
|
+
function buildUrl(baseUrl, path) {
|
|
56
|
+
const normalizedBase = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
57
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
58
|
+
return `${normalizedBase}${normalizedPath}`;
|
|
59
|
+
}
|
|
60
|
+
async function doFetch(config, method, url, body, options) {
|
|
61
|
+
const controller = new AbortController();
|
|
62
|
+
const timeoutMs = options.timeoutMs ?? config.timeoutMs;
|
|
63
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
64
|
+
const headers = {
|
|
65
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
66
|
+
"Content-Type": "application/json",
|
|
67
|
+
"User-Agent": config.userAgent,
|
|
68
|
+
...options.headers
|
|
69
|
+
};
|
|
70
|
+
if (options.idempotencyKey) {
|
|
71
|
+
headers["Idempotency-Key"] = options.idempotencyKey;
|
|
72
|
+
}
|
|
73
|
+
if (options.requestId) {
|
|
74
|
+
headers["X-Request-Id"] = options.requestId;
|
|
75
|
+
}
|
|
76
|
+
const hasBody = body !== void 0 && method.toUpperCase() !== "GET";
|
|
77
|
+
const init = {
|
|
78
|
+
method,
|
|
79
|
+
headers,
|
|
80
|
+
signal: controller.signal
|
|
81
|
+
};
|
|
82
|
+
if (hasBody) {
|
|
83
|
+
init.body = JSON.stringify(body);
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const response = await fetch(url, init);
|
|
87
|
+
clearTimeout(timeout);
|
|
88
|
+
if (!response.ok) {
|
|
89
|
+
const errorPayload = await safeJson(response);
|
|
90
|
+
const { message, code, type, request_id } = normalizeError(errorPayload);
|
|
91
|
+
throw new LNTPayAPIError(message ?? `HTTP ${response.status}`, response.status, {
|
|
92
|
+
code,
|
|
93
|
+
type,
|
|
94
|
+
requestId: request_id,
|
|
95
|
+
raw: errorPayload
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (response.status === 204) {
|
|
99
|
+
return void 0;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
return await response.json();
|
|
103
|
+
} catch {
|
|
104
|
+
return void 0;
|
|
105
|
+
}
|
|
106
|
+
} catch (err) {
|
|
107
|
+
clearTimeout(timeout);
|
|
108
|
+
if (err instanceof LNTPayAPIError) {
|
|
109
|
+
throw err;
|
|
110
|
+
}
|
|
111
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
112
|
+
throw new LNTPayNetworkError(`Request timed out after ${timeoutMs}ms`);
|
|
113
|
+
}
|
|
114
|
+
throw new LNTPayNetworkError("Network error");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function safeJson(response) {
|
|
118
|
+
try {
|
|
119
|
+
return await response.json();
|
|
120
|
+
} catch {
|
|
121
|
+
return void 0;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function normalizeError(payload) {
|
|
125
|
+
const typed = payload;
|
|
126
|
+
if (typed?.error) {
|
|
127
|
+
return {
|
|
128
|
+
message: typed.error.message,
|
|
129
|
+
code: typed.error.code,
|
|
130
|
+
type: typed.error.type,
|
|
131
|
+
request_id: typed.error.request_id
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return {};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/webhooks.ts
|
|
138
|
+
import { timingSafeEqual, createHmac } from "crypto";
|
|
139
|
+
function verifySignature(rawBody, signatureHeader, secret) {
|
|
140
|
+
if (!signatureHeader || !secret) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
const payload = typeof rawBody === "string" ? Buffer.from(rawBody, "utf8") : rawBody;
|
|
144
|
+
const expected = createHmac("sha256", secret).update(payload).digest("hex");
|
|
145
|
+
const candidates = extractSignatures(signatureHeader);
|
|
146
|
+
for (const candidate of candidates) {
|
|
147
|
+
if (safeEqual(candidate, expected)) {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
function constructEvent(rawBody, signatureHeader, secret) {
|
|
154
|
+
if (!verifySignature(rawBody, signatureHeader, secret)) {
|
|
155
|
+
throw new LNTPayWebhookSignatureError("Invalid webhook signature");
|
|
156
|
+
}
|
|
157
|
+
const body = typeof rawBody === "string" ? rawBody : rawBody.toString("utf8");
|
|
158
|
+
return JSON.parse(body);
|
|
159
|
+
}
|
|
160
|
+
function extractSignatures(signatureHeader) {
|
|
161
|
+
const trimmed = signatureHeader.trim();
|
|
162
|
+
if (trimmed.includes("v1=")) {
|
|
163
|
+
return trimmed.split(",").map((part) => part.trim()).filter((part) => part.startsWith("v1=")).map((part) => part.slice(3)).filter(Boolean);
|
|
164
|
+
}
|
|
165
|
+
return [trimmed];
|
|
166
|
+
}
|
|
167
|
+
function safeEqual(a, b) {
|
|
168
|
+
const aBuf = Buffer.from(a, "utf8");
|
|
169
|
+
const bBuf = Buffer.from(b, "utf8");
|
|
170
|
+
if (aBuf.length !== bBuf.length) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
return timingSafeEqual(aBuf, bBuf);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/index.ts
|
|
177
|
+
var LNTPay = class {
|
|
178
|
+
apiKey;
|
|
179
|
+
baseUrl;
|
|
180
|
+
timeoutMs;
|
|
181
|
+
userAgent;
|
|
182
|
+
charges;
|
|
183
|
+
withdrawals;
|
|
184
|
+
webhooks;
|
|
185
|
+
constructor(config) {
|
|
186
|
+
if (!config?.apiKey) {
|
|
187
|
+
throw new LNTPayError("apiKey is required");
|
|
188
|
+
}
|
|
189
|
+
this.apiKey = config.apiKey;
|
|
190
|
+
this.baseUrl = config.baseUrl ?? "https://api.lntpay.com";
|
|
191
|
+
this.timeoutMs = config.timeoutMs ?? 3e4;
|
|
192
|
+
this.userAgent = config.userAgent ?? "@lntpay/sdk";
|
|
193
|
+
this.charges = {
|
|
194
|
+
create: (params, options) => this.request("POST", "/v0/charges", params, options),
|
|
195
|
+
retrieve: (chargeId, options) => this.request("GET", `/v0/charges/${encodeURIComponent(chargeId)}`, void 0, options)
|
|
196
|
+
};
|
|
197
|
+
this.withdrawals = {
|
|
198
|
+
create: (params, options) => this.request("POST", "/v0/withdrawals", params, options)
|
|
199
|
+
};
|
|
200
|
+
this.webhooks = {
|
|
201
|
+
verifySignature,
|
|
202
|
+
constructEvent
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
async request(method, path, body, options = {}) {
|
|
206
|
+
return request(
|
|
207
|
+
{
|
|
208
|
+
apiKey: this.apiKey,
|
|
209
|
+
baseUrl: this.baseUrl,
|
|
210
|
+
timeoutMs: this.timeoutMs,
|
|
211
|
+
userAgent: this.userAgent
|
|
212
|
+
},
|
|
213
|
+
method,
|
|
214
|
+
path,
|
|
215
|
+
body,
|
|
216
|
+
options
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
var index_default = LNTPay;
|
|
221
|
+
export {
|
|
222
|
+
LNTPay,
|
|
223
|
+
LNTPayAPIError,
|
|
224
|
+
LNTPayError,
|
|
225
|
+
LNTPayNetworkError,
|
|
226
|
+
LNTPayWebhookSignatureError,
|
|
227
|
+
index_default as default
|
|
228
|
+
};
|
|
229
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/internal/request.ts","../src/webhooks.ts","../src/index.ts"],"sourcesContent":["export class LNTPayError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"LNTPayError\";\n }\n}\n\nexport class LNTPayAPIError extends LNTPayError {\n status: number;\n code?: string;\n type?: string;\n requestId?: string;\n raw?: unknown;\n\n constructor(message: string, status: number, opts?: { code?: string; type?: string; requestId?: string; raw?: unknown }) {\n super(message);\n this.name = \"LNTPayAPIError\";\n this.status = status;\n this.code = opts?.code;\n this.type = opts?.type;\n this.requestId = opts?.requestId;\n this.raw = opts?.raw;\n }\n}\n\nexport class LNTPayNetworkError extends LNTPayError {\n constructor(message: string) {\n super(message);\n this.name = \"LNTPayNetworkError\";\n }\n}\n\nexport class LNTPayWebhookSignatureError extends LNTPayError {\n constructor(message: string) {\n super(message);\n this.name = \"LNTPayWebhookSignatureError\";\n }\n}\n","import { LNTPayAPIError, LNTPayNetworkError } from \"../errors\";\nimport type { LNTPayErrorResponse, RequestOptions } from \"../types\";\n\nexport interface ClientConfig {\n apiKey: string;\n baseUrl: string;\n timeoutMs: number;\n userAgent: string;\n}\n\nexport async function request<T>(\n config: ClientConfig,\n method: string,\n path: string,\n body?: unknown,\n options: RequestOptions = {}\n): Promise<T> {\n const url = buildUrl(config.baseUrl, path);\n const retries = method.toUpperCase() === \"GET\" ? Math.max(0, options.retries ?? 0) : 0;\n\n let lastError: unknown;\n for (let attempt = 0; attempt <= retries; attempt += 1) {\n try {\n return await doFetch<T>(config, method, url, body, options);\n } catch (err) {\n if (err instanceof LNTPayNetworkError && attempt < retries) {\n lastError = err;\n continue;\n }\n throw err;\n }\n }\n\n throw lastError instanceof Error ? lastError : new LNTPayNetworkError(\"Network error\");\n}\n\nfunction buildUrl(baseUrl: string, path: string): string {\n const normalizedBase = baseUrl.endsWith(\"/\") ? baseUrl.slice(0, -1) : baseUrl;\n const normalizedPath = path.startsWith(\"/\") ? path : `/${path}`;\n return `${normalizedBase}${normalizedPath}`;\n}\n\nasync function doFetch<T>(\n config: ClientConfig,\n method: string,\n url: string,\n body: unknown,\n options: RequestOptions\n): Promise<T> {\n const controller = new AbortController();\n const timeoutMs = options.timeoutMs ?? config.timeoutMs;\n const timeout = setTimeout(() => controller.abort(), timeoutMs);\n\n const headers: Record<string, string> = {\n Authorization: `Bearer ${config.apiKey}`,\n \"Content-Type\": \"application/json\",\n \"User-Agent\": config.userAgent,\n ...options.headers\n };\n\n if (options.idempotencyKey) {\n headers[\"Idempotency-Key\"] = options.idempotencyKey;\n }\n\n if (options.requestId) {\n headers[\"X-Request-Id\"] = options.requestId;\n }\n\n const hasBody = body !== undefined && method.toUpperCase() !== \"GET\";\n const init: RequestInit = {\n method,\n headers,\n signal: controller.signal\n };\n\n if (hasBody) {\n init.body = JSON.stringify(body);\n }\n\n try {\n const response = await fetch(url, init);\n clearTimeout(timeout);\n\n if (!response.ok) {\n const errorPayload = await safeJson(response);\n const { message, code, type, request_id } = normalizeError(errorPayload);\n throw new LNTPayAPIError(message ?? `HTTP ${response.status}`, response.status, {\n code,\n type,\n requestId: request_id,\n raw: errorPayload\n });\n }\n\n if (response.status === 204) {\n return undefined as T;\n }\n\n try {\n return (await response.json()) as T;\n } catch {\n return undefined as T;\n }\n } catch (err) {\n clearTimeout(timeout);\n if (err instanceof LNTPayAPIError) {\n throw err;\n }\n if (err instanceof Error && err.name === \"AbortError\") {\n throw new LNTPayNetworkError(`Request timed out after ${timeoutMs}ms`);\n }\n throw new LNTPayNetworkError(\"Network error\");\n }\n}\n\nasync function safeJson(response: Response): Promise<unknown> {\n try {\n return await response.json();\n } catch {\n return undefined;\n }\n}\n\nfunction normalizeError(payload: unknown): {\n message?: string;\n code?: string;\n type?: string;\n request_id?: string;\n} {\n const typed = payload as LNTPayErrorResponse | undefined;\n if (typed?.error) {\n return {\n message: typed.error.message,\n code: typed.error.code,\n type: typed.error.type,\n request_id: typed.error.request_id\n };\n }\n return {};\n}\n","import { timingSafeEqual, createHmac } from \"node:crypto\";\nimport { LNTPayWebhookSignatureError } from \"./errors\";\n\nexport function verifySignature(rawBody: string | Buffer, signatureHeader: string, secret: string): boolean {\n if (!signatureHeader || !secret) {\n return false;\n }\n\n const payload = typeof rawBody === \"string\" ? Buffer.from(rawBody, \"utf8\") : rawBody;\n const expected = createHmac(\"sha256\", secret).update(payload).digest(\"hex\");\n const candidates = extractSignatures(signatureHeader);\n\n for (const candidate of candidates) {\n if (safeEqual(candidate, expected)) {\n return true;\n }\n }\n\n return false;\n}\n\nexport function constructEvent<T>(\n rawBody: string | Buffer,\n signatureHeader: string,\n secret: string\n): T {\n if (!verifySignature(rawBody, signatureHeader, secret)) {\n throw new LNTPayWebhookSignatureError(\"Invalid webhook signature\");\n }\n\n const body = typeof rawBody === \"string\" ? rawBody : rawBody.toString(\"utf8\");\n return JSON.parse(body) as T;\n}\n\nfunction extractSignatures(signatureHeader: string): string[] {\n const trimmed = signatureHeader.trim();\n if (trimmed.includes(\"v1=\")) {\n return trimmed\n .split(\",\")\n .map((part) => part.trim())\n .filter((part) => part.startsWith(\"v1=\"))\n .map((part) => part.slice(3))\n .filter(Boolean);\n }\n return [trimmed];\n}\n\nfunction safeEqual(a: string, b: string): boolean {\n const aBuf = Buffer.from(a, \"utf8\");\n const bBuf = Buffer.from(b, \"utf8\");\n if (aBuf.length !== bBuf.length) {\n return false;\n }\n return timingSafeEqual(aBuf, bBuf);\n}\n","import { request } from \"./internal/request\";\nimport { constructEvent, verifySignature } from \"./webhooks\";\nimport type {\n Charge,\n ChargeCreateParams,\n LNTPayErrorResponse,\n RequestOptions,\n Withdrawal,\n WithdrawalCreateParams,\n WebhookEvent\n} from \"./types\";\nimport {\n LNTPayAPIError,\n LNTPayError,\n LNTPayNetworkError,\n LNTPayWebhookSignatureError\n} from \"./errors\";\n\nexport interface LNTPayConfig {\n apiKey: string;\n baseUrl?: string;\n timeoutMs?: number;\n userAgent?: string;\n}\n\nexport class LNTPay {\n private apiKey: string;\n private baseUrl: string;\n private timeoutMs: number;\n private userAgent: string;\n\n charges: {\n create: (params: ChargeCreateParams, options?: RequestOptions) => Promise<Charge>;\n retrieve: (chargeId: string, options?: RequestOptions) => Promise<Charge>;\n };\n\n withdrawals: {\n create: (params: WithdrawalCreateParams, options?: RequestOptions) => Promise<Withdrawal>;\n };\n\n webhooks: {\n verifySignature: (rawBody: string | Buffer, signatureHeader: string, secret: string) => boolean;\n constructEvent: <T = WebhookEvent>(\n rawBody: string | Buffer,\n signatureHeader: string,\n secret: string\n ) => T;\n };\n\n constructor(config: LNTPayConfig) {\n if (!config?.apiKey) {\n throw new LNTPayError(\"apiKey is required\");\n }\n\n this.apiKey = config.apiKey;\n this.baseUrl = config.baseUrl ?? \"https://api.lntpay.com\";\n this.timeoutMs = config.timeoutMs ?? 30_000;\n this.userAgent = config.userAgent ?? \"@lntpay/sdk\";\n\n this.charges = {\n create: (params, options) => this.request<Charge>(\"POST\", \"/v0/charges\", params, options),\n retrieve: (chargeId, options) =>\n this.request<Charge>(\"GET\", `/v0/charges/${encodeURIComponent(chargeId)}`, undefined, options)\n };\n\n this.withdrawals = {\n create: (params, options) => this.request<Withdrawal>(\"POST\", \"/v0/withdrawals\", params, options)\n };\n\n this.webhooks = {\n verifySignature,\n constructEvent\n };\n }\n\n private async request<T>(\n method: string,\n path: string,\n body?: unknown,\n options: RequestOptions = {}\n ): Promise<T> {\n return request<T>(\n {\n apiKey: this.apiKey,\n baseUrl: this.baseUrl,\n timeoutMs: this.timeoutMs,\n userAgent: this.userAgent\n },\n method,\n path,\n body,\n options\n );\n }\n}\n\nexport {\n Charge,\n ChargeCreateParams,\n RequestOptions,\n LNTPayErrorResponse,\n Withdrawal,\n WithdrawalCreateParams,\n WebhookEvent,\n LNTPayAPIError,\n LNTPayError,\n LNTPayNetworkError,\n LNTPayWebhookSignatureError\n};\n\nexport default LNTPay;\n"],"mappings":";AAAO,IAAM,cAAN,cAA0B,MAAM;AAAA,EACrC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK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MACA,UAA0B,CAAC,GACf;AACZ,WAAO;AAAA,MACL;AAAA,QACE,QAAQ,KAAK;AAAA,QACb,SAAS,KAAK;AAAA,QACd,WAAW,KAAK;AAAA,QAChB,WAAW,KAAK;AAAA,MAClB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAgBA,IAAO,gBAAQ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lntpay/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official LNTPay SDK for Node.js",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": { "type": "git", "url": "git+https://github.com/lntpay/lntpay-sdk.git" },
|
|
7
|
+
"homepage": "https://github.com/lntpay/lntpay-sdk#readme",
|
|
8
|
+
"bugs": { "url": "https://github.com/lntpay/lntpay-sdk/issues" },
|
|
9
|
+
"keywords": ["lightning", "bitcoin", "payments", "ln", "lntpay", "sdk"],
|
|
10
|
+
"publishConfig": { "access": "public" },
|
|
11
|
+
"type": "module",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"require": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": ["dist", "README.md", "LICENSE", "CHANGELOG.md"],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"test": "npm run build && node -e \"const m=require('./dist/index.cjs'); if(!(m.LNTPay||m.default)) process.exit(1); console.log('ok');\"",
|
|
24
|
+
"lint": "tsc -p tsconfig.json --noEmit"
|
|
25
|
+
},
|
|
26
|
+
"engines": { "node": ">=18" },
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^20.11.30",
|
|
29
|
+
"tsup": "^8.0.1",
|
|
30
|
+
"typescript": "^5.4.5"
|
|
31
|
+
}
|
|
32
|
+
}
|