@run402/sdk 4.112.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/README.md +1 -1
- package/dist/namespaces/deploy.d.ts.map +1 -1
- package/dist/namespaces/deploy.js +9 -0
- package/dist/namespaces/deploy.js.map +1 -1
- package/dist/namespaces/deploy.types.d.ts +28 -0
- package/dist/namespaces/deploy.types.d.ts.map +1 -1
- package/dist/namespaces/deploy.types.js.map +1 -1
- 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
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
2
|
+
import { parseBindingExtra } from "./binding.js";
|
|
3
|
+
import { decodeInvoice } from "./bolt11.js";
|
|
4
|
+
import { ASSET, ASSET_TRANSFER_METHOD, Errors, LnbtcError, PAYMENT_FLOW, SCHEME, } from "./constants.js";
|
|
5
|
+
const POSITIVE_INTEGER = /^[1-9][0-9]*$/;
|
|
6
|
+
const COMPRESSED_PUBKEY = /^0[23][0-9a-f]{64}$/;
|
|
7
|
+
/**
|
|
8
|
+
* Throws an {@link LnbtcError} with the given reason.
|
|
9
|
+
*
|
|
10
|
+
* @param reason - Stable reason
|
|
11
|
+
* @returns Never returns
|
|
12
|
+
*/
|
|
13
|
+
export function reject(reason) {
|
|
14
|
+
throw new LnbtcError(reason);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Validates the core requirement terms (step 2 of facilitator validation).
|
|
18
|
+
*
|
|
19
|
+
* @param req - Payment requirements
|
|
20
|
+
* @param networks - Supported networks mapped to BOLT11 currency
|
|
21
|
+
*/
|
|
22
|
+
export function validateCoreTerms(req, networks) {
|
|
23
|
+
if (req.scheme !== SCHEME)
|
|
24
|
+
reject(Errors.unsupportedScheme);
|
|
25
|
+
if (!isSupportedNetwork(req.network, networks))
|
|
26
|
+
reject(Errors.unsupportedNetwork);
|
|
27
|
+
if (req.asset !== ASSET)
|
|
28
|
+
reject(Errors.asset);
|
|
29
|
+
if (typeof req.amount !== "string" || !POSITIVE_INTEGER.test(req.amount))
|
|
30
|
+
reject(Errors.amount);
|
|
31
|
+
if (!Number.isSafeInteger(req.maxTimeoutSeconds) || req.maxTimeoutSeconds <= 0) {
|
|
32
|
+
reject(Errors.maxTimeout);
|
|
33
|
+
}
|
|
34
|
+
if (!isCompressedPubkey(req.payTo))
|
|
35
|
+
reject(Errors.payToMalformed);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Validates the transfer method and payment flow of an `extra` object.
|
|
39
|
+
*
|
|
40
|
+
* @param extra - Requirements `extra`
|
|
41
|
+
*/
|
|
42
|
+
export function validateMethodAndFlow(extra) {
|
|
43
|
+
// Only an omitted method defaults; an explicit value (even null) must be "bolt11".
|
|
44
|
+
const method = extra?.assetTransferMethod === undefined ? ASSET_TRANSFER_METHOD : extra.assetTransferMethod;
|
|
45
|
+
if (method !== ASSET_TRANSFER_METHOD)
|
|
46
|
+
reject(Errors.assetTransferMethod);
|
|
47
|
+
if (extra?.paymentFlow !== PAYMENT_FLOW)
|
|
48
|
+
reject(Errors.paymentFlow);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Validates every requirement field a client or server checks before paying or
|
|
52
|
+
* issuing: core terms, method, flow, and binding fields.
|
|
53
|
+
*
|
|
54
|
+
* @param req - Payment requirements
|
|
55
|
+
* @param networks - Supported networks mapped to BOLT11 currency
|
|
56
|
+
* @returns The validated binding fields
|
|
57
|
+
*/
|
|
58
|
+
export function validateRequirements(req, networks) {
|
|
59
|
+
validateCoreTerms(req, networks);
|
|
60
|
+
validateMethodAndFlow(req.extra);
|
|
61
|
+
return parseBindingExtra(req.extra);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Strictly decodes an invoice and checks it against the requirements: the
|
|
65
|
+
* facilitator's step 5, and the client and server pre-payment checks except
|
|
66
|
+
* expiry (see {@link checkExpiry}).
|
|
67
|
+
*
|
|
68
|
+
* @param invoice - BOLT11 invoice text
|
|
69
|
+
* @param req - Requirements whose terms the invoice must match
|
|
70
|
+
* @param expectedRequestHash - The expected request hash, lowercase hex
|
|
71
|
+
* @param networks - Supported networks mapped to BOLT11 currency
|
|
72
|
+
* @param options - Time and expiry policy
|
|
73
|
+
* @returns The decoded invoice
|
|
74
|
+
*/
|
|
75
|
+
export function validateInvoice(invoice, req, expectedRequestHash, networks, options) {
|
|
76
|
+
if (invoice === undefined || invoice === null || invoice === "")
|
|
77
|
+
reject(Errors.invoiceMissing);
|
|
78
|
+
if (typeof invoice !== "string")
|
|
79
|
+
reject(Errors.invoiceDecodeFailed);
|
|
80
|
+
let decoded;
|
|
81
|
+
try {
|
|
82
|
+
decoded = decodeInvoice(invoice);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
reject(Errors.invoiceDecodeFailed);
|
|
86
|
+
}
|
|
87
|
+
if (decoded.descriptionHashes.length !== 1 || decoded.inlineDescriptionCount !== 0) {
|
|
88
|
+
reject(Errors.invoiceDescription);
|
|
89
|
+
}
|
|
90
|
+
if (decoded.descriptionHashes[0] !== expectedRequestHash)
|
|
91
|
+
reject(Errors.invoiceRequestMismatch);
|
|
92
|
+
if (decoded.payee !== req.payTo)
|
|
93
|
+
reject(Errors.invoicePayeeMismatch);
|
|
94
|
+
if (decoded.currency !== networks[req.network])
|
|
95
|
+
reject(Errors.invoiceCurrencyMismatch);
|
|
96
|
+
if (decoded.amountMsat !== BigInt(req.amount))
|
|
97
|
+
reject(Errors.invoiceAmountMismatch);
|
|
98
|
+
if (decoded.expirySeconds !== req.maxTimeoutSeconds)
|
|
99
|
+
reject(Errors.invoiceExpiryMismatch);
|
|
100
|
+
if (decoded.timestamp > options.now + options.skew)
|
|
101
|
+
reject(Errors.invoiceCreatedInFuture);
|
|
102
|
+
return decoded;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Applies an expiry policy to a decoded invoice.
|
|
106
|
+
*
|
|
107
|
+
* @param invoice - Decoded invoice
|
|
108
|
+
* @param options - Validation time and skew
|
|
109
|
+
* @param policy - `unexpired`: the invoice must not have expired at `now`
|
|
110
|
+
* (client, server). `settlement`: the paid-but-expired window, valid through
|
|
111
|
+
* `invoice_end + skew` inclusive (facilitator).
|
|
112
|
+
*/
|
|
113
|
+
export function checkExpiry(invoice, options, policy) {
|
|
114
|
+
const end = invoice.timestamp + invoice.expirySeconds;
|
|
115
|
+
const expired = policy === "settlement" ? options.now > end + options.skew : options.now >= end;
|
|
116
|
+
if (expired)
|
|
117
|
+
reject(Errors.invoiceExpired);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Checks that a network is one of the configured networks (own keys only, so
|
|
121
|
+
* names such as `constructor` never match).
|
|
122
|
+
*
|
|
123
|
+
* @param network - Candidate network
|
|
124
|
+
* @param networks - Supported networks mapped to BOLT11 currency
|
|
125
|
+
* @returns Whether the network is supported
|
|
126
|
+
*/
|
|
127
|
+
export function isSupportedNetwork(network, networks) {
|
|
128
|
+
return typeof network === "string" && Object.prototype.hasOwnProperty.call(networks, network);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Validates a clock-skew allowance.
|
|
132
|
+
*
|
|
133
|
+
* @param skew - Seconds
|
|
134
|
+
*/
|
|
135
|
+
export function validateSkew(skew) {
|
|
136
|
+
if (!Number.isSafeInteger(skew) || skew < 0) {
|
|
137
|
+
throw new RangeError("clock skew must be a non-negative integer number of seconds");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Checks for a lowercase compressed secp256k1 public key on the curve.
|
|
142
|
+
*
|
|
143
|
+
* @param value - Candidate
|
|
144
|
+
* @returns Whether it is valid
|
|
145
|
+
*/
|
|
146
|
+
export function isCompressedPubkey(value) {
|
|
147
|
+
if (typeof value !== "string" || !COMPRESSED_PUBKEY.test(value))
|
|
148
|
+
return false;
|
|
149
|
+
try {
|
|
150
|
+
secp256k1.Point.fromHex(value).assertValidity();
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Current Unix time in whole seconds.
|
|
159
|
+
*
|
|
160
|
+
* @returns Seconds since the epoch
|
|
161
|
+
*/
|
|
162
|
+
export function unixNow() {
|
|
163
|
+
return Math.floor(Date.now() / 1000);
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../../src/node/vendor/x402-lnbtc/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEvD,OAAO,EAAE,iBAAiB,EAA4B,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAuB,MAAM,aAAa,CAAC;AACjE,OAAO,EACL,KAAK,EACL,qBAAqB,EACrB,MAAM,EACN,UAAU,EAEV,YAAY,EACZ,MAAM,GACP,MAAM,gBAAgB,CAAC;AAExB,MAAM,gBAAgB,GAAG,eAAe,CAAC;AACzC,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,MAAwB;IAC7C,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,GAAwB,EACxB,QAA0C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C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9E,IAAI,CAAC;QACH,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,cAAc,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO;IACrB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AACvC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@run402/sdk",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.114.0",
|
|
4
4
|
"description": "Typed TypeScript client for the Run402 API. Kernel shared by the run402-mcp server, the run402 CLI, and user-deployed run402 functions.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|