@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,81 @@
|
|
|
1
|
+
export const SCHEME = "exact";
|
|
2
|
+
export const ASSET = "BTC";
|
|
3
|
+
export const ASSET_TRANSFER_METHOD = "bolt11";
|
|
4
|
+
export const PAYMENT_FLOW = "upfront";
|
|
5
|
+
export const CAIP_FAMILY = "lnbtc:*";
|
|
6
|
+
export const LNBTC_MAINNET = "lnbtc:000000000019d6689c085ae165831e93";
|
|
7
|
+
export const LNBTC_TESTNET = "lnbtc:000000000933ea01ad0ee984209779ba";
|
|
8
|
+
/**
|
|
9
|
+
* Concrete lnbtc networks mapped to their BOLT11 currency prefix.
|
|
10
|
+
*/
|
|
11
|
+
export const LNBTC_NETWORKS = Object.freeze({
|
|
12
|
+
[LNBTC_MAINNET]: "bc",
|
|
13
|
+
[LNBTC_TESTNET]: "tb",
|
|
14
|
+
});
|
|
15
|
+
export const DEFAULT_CLOCK_SKEW_SECONDS = 60;
|
|
16
|
+
/** Replay entries are retained at least this long after `invoice_end + skew`. */
|
|
17
|
+
export const REPLAY_RETENTION_SECONDS = 3600;
|
|
18
|
+
export const BINDING_DOMAIN_PREFIX = "x402:exact:lnbtc:bolt11:";
|
|
19
|
+
export const HTTP_PROFILE = "http:1";
|
|
20
|
+
export const MCP_PROFILE = "mcp:1";
|
|
21
|
+
export const DYNAMIC_EXTRA_FIELDS = ["invoice"];
|
|
22
|
+
/** Error reasons returned by the facilitator, verbatim from the specification. */
|
|
23
|
+
export const Errors = {
|
|
24
|
+
unsupportedScheme: "unsupported_scheme",
|
|
25
|
+
networkMismatch: "network_mismatch",
|
|
26
|
+
unsupportedNetwork: "unsupported_network",
|
|
27
|
+
duplicateSettlement: "duplicate_settlement",
|
|
28
|
+
asset: "invalid_exact_lnbtc_asset",
|
|
29
|
+
amount: "invalid_exact_lnbtc_amount",
|
|
30
|
+
amountMismatch: "invalid_exact_lnbtc_amount_mismatch",
|
|
31
|
+
payToMismatch: "invalid_exact_lnbtc_pay_to_mismatch",
|
|
32
|
+
payToMalformed: "invalid_exact_lnbtc_pay_to_malformed",
|
|
33
|
+
maxTimeoutMismatch: "invalid_exact_lnbtc_max_timeout_mismatch",
|
|
34
|
+
maxTimeout: "invalid_exact_lnbtc_max_timeout",
|
|
35
|
+
extraMismatch: "invalid_exact_lnbtc_extra_mismatch",
|
|
36
|
+
requestBinding: "invalid_exact_lnbtc_request_binding",
|
|
37
|
+
requestMismatch: "invalid_exact_lnbtc_request_mismatch",
|
|
38
|
+
assetTransferMethod: "invalid_exact_lnbtc_asset_transfer_method",
|
|
39
|
+
paymentFlow: "invalid_exact_lnbtc_payment_flow",
|
|
40
|
+
invoiceMissing: "invalid_exact_lnbtc_invoice_missing",
|
|
41
|
+
invoiceDecodeFailed: "invalid_exact_lnbtc_invoice_decode_failed",
|
|
42
|
+
invoiceDescription: "invalid_exact_lnbtc_invoice_description",
|
|
43
|
+
invoiceRequestMismatch: "invalid_exact_lnbtc_invoice_request_mismatch",
|
|
44
|
+
invoicePayeeMismatch: "invalid_exact_lnbtc_invoice_payee_mismatch",
|
|
45
|
+
invoiceCurrencyMismatch: "invalid_exact_lnbtc_invoice_currency_mismatch",
|
|
46
|
+
invoiceAmountMismatch: "invalid_exact_lnbtc_invoice_amount_mismatch",
|
|
47
|
+
invoiceExpiryMismatch: "invalid_exact_lnbtc_invoice_expiry_mismatch",
|
|
48
|
+
invoiceCreatedInFuture: "invalid_exact_lnbtc_invoice_created_in_future",
|
|
49
|
+
invoiceExpired: "invalid_exact_lnbtc_invoice_expired",
|
|
50
|
+
preimageMissing: "invalid_exact_lnbtc_preimage_missing",
|
|
51
|
+
preimageMalformed: "invalid_exact_lnbtc_preimage_malformed",
|
|
52
|
+
preimageLength: "invalid_exact_lnbtc_preimage_length",
|
|
53
|
+
preimageHashMismatch: "invalid_exact_lnbtc_preimage_hash_mismatch",
|
|
54
|
+
// Local client/server reasons (not facilitator responses).
|
|
55
|
+
issuanceDenied: "exact_lnbtc_invoice_issuance_denied",
|
|
56
|
+
payerInvoiceMismatch: "invalid_exact_lnbtc_payer_invoice_mismatch",
|
|
57
|
+
payerPaymentHashMismatch: "invalid_exact_lnbtc_payer_payment_hash_mismatch",
|
|
58
|
+
payerAmountMismatch: "invalid_exact_lnbtc_payer_amount_mismatch",
|
|
59
|
+
paymentInFlight: "exact_lnbtc_payment_in_flight",
|
|
60
|
+
paymentNotPaid: "exact_lnbtc_payment_not_paid",
|
|
61
|
+
payerPreimageRequired: "invalid_exact_lnbtc_payer_preimage_required",
|
|
62
|
+
payerPreimageMalformed: "invalid_exact_lnbtc_payer_preimage_malformed",
|
|
63
|
+
payerPreimageHashMismatch: "invalid_exact_lnbtc_payer_preimage_hash_mismatch",
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Error carrying a stable lnbtc reason string.
|
|
67
|
+
*/
|
|
68
|
+
export class LnbtcError extends Error {
|
|
69
|
+
reason;
|
|
70
|
+
/**
|
|
71
|
+
* Creates an error whose message is the stable reason.
|
|
72
|
+
*
|
|
73
|
+
* @param reason - Stable reason string from {@link Errors}
|
|
74
|
+
*/
|
|
75
|
+
constructor(reason) {
|
|
76
|
+
super(reason);
|
|
77
|
+
this.reason = reason;
|
|
78
|
+
this.name = "LnbtcError";
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/node/vendor/x402-lnbtc/constants.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC;AAC9B,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,CAAC;AAC3B,MAAM,CAAC,MAAM,qBAAqB,GAAG,QAAQ,CAAC;AAC9C,MAAM,CAAC,MAAM,YAAY,GAAG,SAAS,CAAC;AACtC,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC;AAErC,MAAM,CAAC,MAAM,aAAa,GAAY,wCAAwC,CAAC;AAC/E,MAAM,CAAC,MAAM,aAAa,GAAY,wCAAwC,CAAC;AAE/E;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAqC,MAAM,CAAC,MAAM,CAAC;IAC5E,CAAC,aAAa,CAAC,EAAE,IAAI;IACrB,CAAC,aAAa,CAAC,EAAE,IAAI;CACtB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAE7C,iFAAiF;AACjF,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAC;AAE7C,MAAM,CAAC,MAAM,qBAAqB,GAAG,0BAA0B,CAAC;AAChE,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;AACrC,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AAEnC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,SAAS,CAAC,CAAC;AAEhD,kFAAkF;AAClF,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,iBAAiB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C;QADK,WAAM,GAAN,MAAM,CAAkB;QAE3C,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { PaymentPayloadContext, PaymentPayloadResult, PaymentRequirements, SchemeClientHooks, SchemeNetworkClient } from "@x402/core/types";
|
|
2
|
+
import type { Clock, LightningPayer, RequestBindingProvider } from "../../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Options for the lnbtc client.
|
|
5
|
+
*/
|
|
6
|
+
export interface ExactLnbtcClientOptions {
|
|
7
|
+
/** Payer node adapter; must return the preimage for paid invoices. */
|
|
8
|
+
payer: LightningPayer;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the binding of the request being paid for, computed by the
|
|
11
|
+
* application from the intended request (`httpRequestBinding` or
|
|
12
|
+
* `mcpToolCallBinding`), never from the payment challenge.
|
|
13
|
+
*/
|
|
14
|
+
requestBinding: RequestBindingProvider;
|
|
15
|
+
/** Clock-skew allowance in seconds (default 60). */
|
|
16
|
+
clockSkewSeconds?: number;
|
|
17
|
+
/** Clock returning Unix seconds. */
|
|
18
|
+
clock?: Clock;
|
|
19
|
+
/** Supported networks mapped to BOLT11 currency (default: mainnet and testnet). */
|
|
20
|
+
networks?: Readonly<Record<string, string>>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Client for `exact` on `lnbtc`: validates the request-bound invoice, pays it,
|
|
24
|
+
* and returns the verified preimage.
|
|
25
|
+
*/
|
|
26
|
+
export declare class ExactLnbtcScheme implements SchemeNetworkClient {
|
|
27
|
+
readonly scheme = "exact";
|
|
28
|
+
readonly schemeHooks: SchemeClientHooks;
|
|
29
|
+
private readonly options;
|
|
30
|
+
private readonly skew;
|
|
31
|
+
private readonly clock;
|
|
32
|
+
private readonly networks;
|
|
33
|
+
/**
|
|
34
|
+
* Creates the client scheme.
|
|
35
|
+
*
|
|
36
|
+
* @param options - Payer adapter, request binding provider, clock, and skew
|
|
37
|
+
*/
|
|
38
|
+
constructor(options: ExactLnbtcClientOptions);
|
|
39
|
+
/**
|
|
40
|
+
* Validates the challenge against the intended request, pays the invoice,
|
|
41
|
+
* and verifies the returned preimage.
|
|
42
|
+
*
|
|
43
|
+
* @param x402Version - Protocol version
|
|
44
|
+
* @param requirements - Selected payment requirements
|
|
45
|
+
* @param context - Spend cap from the client's spend controls, if any
|
|
46
|
+
* @returns The payload carrying the preimage
|
|
47
|
+
*/
|
|
48
|
+
createPaymentPayload(x402Version: number, requirements: PaymentRequirements, context?: PaymentPayloadContext): Promise<PaymentPayloadResult>;
|
|
49
|
+
/**
|
|
50
|
+
* For `http:1`, requires `PaymentRequired.resource.url` to equal the
|
|
51
|
+
* intended request URL before any payment.
|
|
52
|
+
*
|
|
53
|
+
* @param ctx - Payment creation context
|
|
54
|
+
* @returns An abort result on mismatch
|
|
55
|
+
*/
|
|
56
|
+
private checkResource;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=scheme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheme.d.ts","sourceRoot":"","sources":["../../../../../../src/node/vendor/x402-lnbtc/exact/client/scheme.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAW1B,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAUpF;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,sEAAsE;IACtE,KAAK,EAAE,cAAc,CAAC;IACtB;;;;OAIG;IACH,cAAc,EAAE,sBAAsB,CAAC;IACvC,oDAAoD;IACpD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oCAAoC;IACpC,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,mFAAmF;IACnF,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC7C;AAED;;;GAGG;AACH,qBAAa,gBAAiB,YAAW,mBAAmB;IAC1D,QAAQ,CAAC,MAAM,WAAU;IACzB,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAC;IACxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0B;IAClD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;IAC9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmC;IAE5D;;;;OAIG;gBACS,OAAO,EAAE,uBAAuB;IAU5C;;;;;;;;OAQG;IACG,oBAAoB,CACxB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,mBAAmB,EACjC,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,oBAAoB,CAAC;IAkChC;;;;;;OAMG;YACW,aAAa;CAgB5B"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
2
|
+
import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
|
|
3
|
+
import { bindingsEqual } from "../../binding.js";
|
|
4
|
+
import { DEFAULT_CLOCK_SKEW_SECONDS, Errors, HTTP_PROFILE, LNBTC_NETWORKS, LnbtcError, SCHEME, } from "../../constants.js";
|
|
5
|
+
import { checkExpiry, reject, unixNow, validateInvoice, validateRequirements, validateSkew, } from "../../validation.js";
|
|
6
|
+
/**
|
|
7
|
+
* Client for `exact` on `lnbtc`: validates the request-bound invoice, pays it,
|
|
8
|
+
* and returns the verified preimage.
|
|
9
|
+
*/
|
|
10
|
+
export class ExactLnbtcScheme {
|
|
11
|
+
scheme = SCHEME;
|
|
12
|
+
schemeHooks;
|
|
13
|
+
options;
|
|
14
|
+
skew;
|
|
15
|
+
clock;
|
|
16
|
+
networks;
|
|
17
|
+
/**
|
|
18
|
+
* Creates the client scheme.
|
|
19
|
+
*
|
|
20
|
+
* @param options - Payer adapter, request binding provider, clock, and skew
|
|
21
|
+
*/
|
|
22
|
+
constructor(options) {
|
|
23
|
+
const skew = options.clockSkewSeconds ?? DEFAULT_CLOCK_SKEW_SECONDS;
|
|
24
|
+
validateSkew(skew);
|
|
25
|
+
this.options = options;
|
|
26
|
+
this.skew = skew;
|
|
27
|
+
this.clock = options.clock ?? unixNow;
|
|
28
|
+
this.networks = options.networks ?? LNBTC_NETWORKS;
|
|
29
|
+
this.schemeHooks = { onBeforePaymentCreation: ctx => this.checkResource(ctx) };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Validates the challenge against the intended request, pays the invoice,
|
|
33
|
+
* and verifies the returned preimage.
|
|
34
|
+
*
|
|
35
|
+
* @param x402Version - Protocol version
|
|
36
|
+
* @param requirements - Selected payment requirements
|
|
37
|
+
* @param context - Spend cap from the client's spend controls, if any
|
|
38
|
+
* @returns The payload carrying the preimage
|
|
39
|
+
*/
|
|
40
|
+
async createPaymentPayload(x402Version, requirements, context) {
|
|
41
|
+
const advertised = validateRequirements(requirements, this.networks);
|
|
42
|
+
assertWithinCap(requirements.amount, context?.maxAmountPerPayment);
|
|
43
|
+
const intended = await this.options.requestBinding();
|
|
44
|
+
if (!bindingsEqual(intended, advertised))
|
|
45
|
+
reject(Errors.requestMismatch);
|
|
46
|
+
const invoiceText = requirements.extra.invoice;
|
|
47
|
+
const options = { now: this.clock(), skew: this.skew };
|
|
48
|
+
const invoice = validateInvoice(invoiceText, requirements, intended.requestHash, this.networks, options);
|
|
49
|
+
checkExpiry(invoice, options, "unexpired");
|
|
50
|
+
const payment = await this.options.payer.payInvoice(invoiceText, requirements.network);
|
|
51
|
+
if (payment.invoice !== invoiceText)
|
|
52
|
+
reject(Errors.payerInvoiceMismatch);
|
|
53
|
+
if (payment.paymentHash !== invoice.paymentHash)
|
|
54
|
+
reject(Errors.payerPaymentHashMismatch);
|
|
55
|
+
if (payment.amountMsat !== invoice.amountMsat)
|
|
56
|
+
reject(Errors.payerAmountMismatch);
|
|
57
|
+
if (payment.status === "in_flight")
|
|
58
|
+
reject(Errors.paymentInFlight);
|
|
59
|
+
if (payment.status !== "paid")
|
|
60
|
+
reject(Errors.paymentNotPaid);
|
|
61
|
+
const preimage = payment.preimage;
|
|
62
|
+
if (preimage === undefined || preimage === null)
|
|
63
|
+
reject(Errors.payerPreimageRequired);
|
|
64
|
+
if (typeof preimage !== "string" || !/^[0-9a-f]{64}$/.test(preimage)) {
|
|
65
|
+
reject(Errors.payerPreimageMalformed);
|
|
66
|
+
}
|
|
67
|
+
if (bytesToHex(sha256(hexToBytes(preimage))) !== invoice.paymentHash) {
|
|
68
|
+
reject(Errors.payerPreimageHashMismatch);
|
|
69
|
+
}
|
|
70
|
+
return { x402Version, payload: { preimage } };
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* For `http:1`, requires `PaymentRequired.resource.url` to equal the
|
|
74
|
+
* intended request URL before any payment.
|
|
75
|
+
*
|
|
76
|
+
* @param ctx - Payment creation context
|
|
77
|
+
* @returns An abort result on mismatch
|
|
78
|
+
*/
|
|
79
|
+
async checkResource(ctx) {
|
|
80
|
+
try {
|
|
81
|
+
const intended = await this.options.requestBinding();
|
|
82
|
+
if (intended.requestBindingProfile === HTTP_PROFILE &&
|
|
83
|
+
ctx.paymentRequired.resource?.url !== intended.resourceUrl) {
|
|
84
|
+
return { abort: true, reason: Errors.requestMismatch };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (error instanceof LnbtcError)
|
|
89
|
+
return { abort: true, reason: error.reason };
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Refuses an amount above the client's atomic spend cap. Core spend controls
|
|
96
|
+
* already filter requirements; this keeps the scheme safe on its own.
|
|
97
|
+
*
|
|
98
|
+
* @param amount - Required millisatoshis (validated positive integer)
|
|
99
|
+
* @param cap - Atomic cap from spend controls, if any
|
|
100
|
+
*/
|
|
101
|
+
function assertWithinCap(amount, cap) {
|
|
102
|
+
if (cap === undefined)
|
|
103
|
+
return;
|
|
104
|
+
if (!/^[0-9]+$/.test(cap) || BigInt(amount) > BigInt(cap)) {
|
|
105
|
+
throw new Error(`lnbtc amount ${amount} msat exceeds maxAmountPerPayment ${cap}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=scheme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheme.js","sourceRoot":"","sources":["../../../../../../src/node/vendor/x402-lnbtc/exact/client/scheme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAShE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EACL,0BAA0B,EAC1B,MAAM,EACN,YAAY,EACZ,cAAc,EACd,UAAU,EACV,MAAM,GACP,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,WAAW,EACX,MAAM,EACN,OAAO,EACP,eAAe,EACf,oBAAoB,EACpB,YAAY,GACb,MAAM,qBAAqB,CAAC;AAsB7B;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IAClB,MAAM,GAAG,MAAM,CAAC;IAChB,WAAW,CAAoB;IACvB,OAAO,CAA0B;IACjC,IAAI,CAAS;IACb,KAAK,CAAQ;IACb,QAAQ,CAAmC;IAE5D;;;;OAIG;IACH,YAAY,OAAgC;QAC1C,MAAM,IAAI,GAAG,OAAO,CAAC,gBAAgB,IAAI,0BAA0B,CAAC;QACpE,YAAY,CAAC,IAAI,CAAC,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GA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AAC,WAAW,EAC1D,CAAC;gBACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,eAAe,EAAE,CAAC;YACzD,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,UAAU;gBAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;YAC9E,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAED;;;;;;GAMG;AACH,SAAS,eAAe,CAAC,MAAc,EAAE,GAAuB;IAC9D,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO;IAC9B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,gBAAgB,MAAM,qCAAqC,GAAG,EAAE,CAAC,CAAC;IACpF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serializes a value with the JSON Canonicalization Scheme (RFC 8785).
|
|
3
|
+
*
|
|
4
|
+
* Rejects values outside the I-JSON data model: non-finite numbers, lone
|
|
5
|
+
* surrogates, and non-plain values (undefined, functions, symbols, bigints,
|
|
6
|
+
* class instances).
|
|
7
|
+
*
|
|
8
|
+
* @param value - The value to serialize
|
|
9
|
+
* @returns The canonical JSON text
|
|
10
|
+
*/
|
|
11
|
+
export declare function canonicalize(value: unknown): string;
|
|
12
|
+
/**
|
|
13
|
+
* Checks a string for lone UTF-16 surrogates.
|
|
14
|
+
*
|
|
15
|
+
* @param value - The string to check
|
|
16
|
+
* @returns Whether every surrogate is paired
|
|
17
|
+
*/
|
|
18
|
+
export declare function isWellFormed(value: string): boolean;
|
|
19
|
+
//# sourceMappingURL=jcs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jcs.d.ts","sourceRoot":"","sources":["../../../../src/node/vendor/x402-lnbtc/jcs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAgBnD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEnD"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serializes a value with the JSON Canonicalization Scheme (RFC 8785).
|
|
3
|
+
*
|
|
4
|
+
* Rejects values outside the I-JSON data model: non-finite numbers, lone
|
|
5
|
+
* surrogates, and non-plain values (undefined, functions, symbols, bigints,
|
|
6
|
+
* class instances).
|
|
7
|
+
*
|
|
8
|
+
* @param value - The value to serialize
|
|
9
|
+
* @returns The canonical JSON text
|
|
10
|
+
*/
|
|
11
|
+
export function canonicalize(value) {
|
|
12
|
+
if (value === null)
|
|
13
|
+
return "null";
|
|
14
|
+
switch (typeof value) {
|
|
15
|
+
case "boolean":
|
|
16
|
+
return value ? "true" : "false";
|
|
17
|
+
case "number":
|
|
18
|
+
if (!Number.isFinite(value))
|
|
19
|
+
throw new TypeError("JCS: non-finite number");
|
|
20
|
+
return JSON.stringify(value);
|
|
21
|
+
case "string":
|
|
22
|
+
return serializeString(value);
|
|
23
|
+
case "object":
|
|
24
|
+
if (Array.isArray(value))
|
|
25
|
+
return serializeArray(value);
|
|
26
|
+
return serializeObject(value);
|
|
27
|
+
default:
|
|
28
|
+
throw new TypeError(`JCS: unsupported value of type ${typeof value}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Checks a string for lone UTF-16 surrogates.
|
|
33
|
+
*
|
|
34
|
+
* @param value - The string to check
|
|
35
|
+
* @returns Whether every surrogate is paired
|
|
36
|
+
*/
|
|
37
|
+
export function isWellFormed(value) {
|
|
38
|
+
return !/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/.test(value);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Serializes a string per ECMAScript JSON.stringify, rejecting lone surrogates.
|
|
42
|
+
*
|
|
43
|
+
* @param value - The string to serialize
|
|
44
|
+
* @returns The quoted, escaped string
|
|
45
|
+
*/
|
|
46
|
+
function serializeString(value) {
|
|
47
|
+
if (!isWellFormed(value))
|
|
48
|
+
throw new TypeError("JCS: invalid Unicode string");
|
|
49
|
+
return JSON.stringify(value);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Serializes an array, rejecting holes (they have no JSON value).
|
|
53
|
+
*
|
|
54
|
+
* @param value - The array to serialize
|
|
55
|
+
* @returns The canonical array text
|
|
56
|
+
*/
|
|
57
|
+
function serializeArray(value) {
|
|
58
|
+
const items = [];
|
|
59
|
+
for (let i = 0; i < value.length; i++) {
|
|
60
|
+
if (!(i in value))
|
|
61
|
+
throw new TypeError("JCS: sparse array");
|
|
62
|
+
items.push(canonicalize(value[i]));
|
|
63
|
+
}
|
|
64
|
+
return `[${items.join(",")}]`;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Serializes a plain object with members sorted by UTF-16 code units.
|
|
68
|
+
*
|
|
69
|
+
* @param value - The object to serialize
|
|
70
|
+
* @returns The canonical object text
|
|
71
|
+
*/
|
|
72
|
+
function serializeObject(value) {
|
|
73
|
+
const proto = Object.getPrototypeOf(value);
|
|
74
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
75
|
+
throw new TypeError("JCS: only plain objects are supported");
|
|
76
|
+
}
|
|
77
|
+
const keys = Object.keys(value).sort();
|
|
78
|
+
const members = keys.map(key => `${serializeString(key)}:${canonicalize(value[key])}`);
|
|
79
|
+
return `{${members.join(",")}}`;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=jcs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC;YAAE,MAAM,IAAI,SAAS,CAAC,mBAAmB,CAAC,CAAC;QAC5D,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAChC,CAAC;AAED;;;;;GAKG;AACH,SAAS,eAAe,CAAC,KAA8B;IACrD,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC3C,IAAI,KAAK,KAAK,MAAM,CAAC,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACjD,MAAM,IAAI,SAAS,CAAC,uCAAuC,CAAC,CAAC;IAC/D,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IACvC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,eAAe,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IACvF,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Network } from "@x402/core/types";
|
|
2
|
+
import type { RequestBinding } from "./binding.js";
|
|
3
|
+
/**
|
|
4
|
+
* Scheme-specific payment payload: the 32-byte preimage as lowercase hex.
|
|
5
|
+
*/
|
|
6
|
+
export interface ExactLnbtcPayload {
|
|
7
|
+
preimage: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Result of asking a payer node to pay an invoice.
|
|
11
|
+
*/
|
|
12
|
+
export interface LightningPayment {
|
|
13
|
+
/** The invoice that was paid, byte-identical to the one requested. */
|
|
14
|
+
invoice: string;
|
|
15
|
+
/** Payment hash, 64 lowercase hex characters. */
|
|
16
|
+
paymentHash: string;
|
|
17
|
+
/** Invoice amount in millisatoshis, excluding routing fees. */
|
|
18
|
+
amountMsat: bigint;
|
|
19
|
+
status: "paid" | "unpaid" | "in_flight";
|
|
20
|
+
/** Preimage, 64 lowercase hex characters; required when `status` is `paid`. */
|
|
21
|
+
preimage?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Client-side Lightning node adapter. Credentials stay in the application.
|
|
25
|
+
*/
|
|
26
|
+
export interface LightningPayer {
|
|
27
|
+
/**
|
|
28
|
+
* Pays a BOLT11 invoice for exactly its amount and returns the result.
|
|
29
|
+
*
|
|
30
|
+
* @param invoice - BOLT11 invoice to pay
|
|
31
|
+
* @param network - Concrete lnbtc network
|
|
32
|
+
* @returns The payment result; `paid` must carry the preimage
|
|
33
|
+
*/
|
|
34
|
+
payInvoice(invoice: string, network: Network): Promise<LightningPayment>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Parameters for creating a request-bound invoice.
|
|
38
|
+
*/
|
|
39
|
+
export interface CreateInvoiceParams {
|
|
40
|
+
amountMsat: bigint;
|
|
41
|
+
/** Request hash to sign as the BOLT11 description hash, lowercase hex. */
|
|
42
|
+
descriptionHash: string;
|
|
43
|
+
expirySeconds: number;
|
|
44
|
+
network: Network;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Server-side Lightning node adapter. The resource server must have exclusive
|
|
48
|
+
* invoice-issuance authority for the node key used as `payTo`.
|
|
49
|
+
*/
|
|
50
|
+
export interface LightningReceiver {
|
|
51
|
+
/**
|
|
52
|
+
* Creates a fresh invoice with a new preimage and payment hash.
|
|
53
|
+
*
|
|
54
|
+
* @param params - Exact amount, description hash, expiry, and network
|
|
55
|
+
* @returns The BOLT11 invoice
|
|
56
|
+
*/
|
|
57
|
+
createInvoice(params: CreateInvoiceParams): Promise<string>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Restart-durable, atomic store of consumed `network:payment_hash` keys. Every
|
|
61
|
+
* facilitator instance settling for the same receiver must share one store.
|
|
62
|
+
*/
|
|
63
|
+
export interface ReplayStore {
|
|
64
|
+
/**
|
|
65
|
+
* Atomically records a key as consumed.
|
|
66
|
+
*
|
|
67
|
+
* @param key - Canonical consumption key `network:payment_hash`
|
|
68
|
+
* @param retainUntil - Unix seconds the entry must be kept until, at least
|
|
69
|
+
* @returns `true` if inserted, `false` if the key already existed
|
|
70
|
+
*/
|
|
71
|
+
consume(key: string, retainUntil: number): Promise<boolean>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Returns the binding for the request currently being paid for or served.
|
|
75
|
+
*/
|
|
76
|
+
export type RequestBindingProvider = () => RequestBinding | Promise<RequestBinding>;
|
|
77
|
+
/**
|
|
78
|
+
* Clock returning Unix seconds.
|
|
79
|
+
*/
|
|
80
|
+
export type Clock = () => number;
|
|
81
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/node/vendor/x402-lnbtc/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,WAAW,CAAC;IACxC,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC1E;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,0EAA0E;IAC1E,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;OAKG;IACH,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7D;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;OAMG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7D;AAED;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAEpF;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/node/vendor/x402-lnbtc/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { PaymentRequirements } from "@x402/core/types";
|
|
2
|
+
import { type RequestBindingExtra } from "./binding.js";
|
|
3
|
+
import { type DecodedInvoice } from "./bolt11.js";
|
|
4
|
+
import { type LnbtcErrorReason } from "./constants.js";
|
|
5
|
+
/**
|
|
6
|
+
* Throws an {@link LnbtcError} with the given reason.
|
|
7
|
+
*
|
|
8
|
+
* @param reason - Stable reason
|
|
9
|
+
* @returns Never returns
|
|
10
|
+
*/
|
|
11
|
+
export declare function reject(reason: LnbtcErrorReason): never;
|
|
12
|
+
/**
|
|
13
|
+
* Validates the core requirement terms (step 2 of facilitator validation).
|
|
14
|
+
*
|
|
15
|
+
* @param req - Payment requirements
|
|
16
|
+
* @param networks - Supported networks mapped to BOLT11 currency
|
|
17
|
+
*/
|
|
18
|
+
export declare function validateCoreTerms(req: PaymentRequirements, networks: Readonly<Record<string, string>>): void;
|
|
19
|
+
/**
|
|
20
|
+
* Validates the transfer method and payment flow of an `extra` object.
|
|
21
|
+
*
|
|
22
|
+
* @param extra - Requirements `extra`
|
|
23
|
+
*/
|
|
24
|
+
export declare function validateMethodAndFlow(extra: Record<string, unknown> | undefined): void;
|
|
25
|
+
/**
|
|
26
|
+
* Validates every requirement field a client or server checks before paying or
|
|
27
|
+
* issuing: core terms, method, flow, and binding fields.
|
|
28
|
+
*
|
|
29
|
+
* @param req - Payment requirements
|
|
30
|
+
* @param networks - Supported networks mapped to BOLT11 currency
|
|
31
|
+
* @returns The validated binding fields
|
|
32
|
+
*/
|
|
33
|
+
export declare function validateRequirements(req: PaymentRequirements, networks: Readonly<Record<string, string>>): RequestBindingExtra;
|
|
34
|
+
/**
|
|
35
|
+
* Options for invoice validation.
|
|
36
|
+
*/
|
|
37
|
+
export interface InvoiceCheckOptions {
|
|
38
|
+
/** Validation time, Unix seconds. */
|
|
39
|
+
now: number;
|
|
40
|
+
/** Non-negative clock-skew allowance, seconds. */
|
|
41
|
+
skew: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Strictly decodes an invoice and checks it against the requirements: the
|
|
45
|
+
* facilitator's step 5, and the client and server pre-payment checks except
|
|
46
|
+
* expiry (see {@link checkExpiry}).
|
|
47
|
+
*
|
|
48
|
+
* @param invoice - BOLT11 invoice text
|
|
49
|
+
* @param req - Requirements whose terms the invoice must match
|
|
50
|
+
* @param expectedRequestHash - The expected request hash, lowercase hex
|
|
51
|
+
* @param networks - Supported networks mapped to BOLT11 currency
|
|
52
|
+
* @param options - Time and expiry policy
|
|
53
|
+
* @returns The decoded invoice
|
|
54
|
+
*/
|
|
55
|
+
export declare function validateInvoice(invoice: unknown, req: PaymentRequirements, expectedRequestHash: string, networks: Readonly<Record<string, string>>, options: InvoiceCheckOptions): DecodedInvoice;
|
|
56
|
+
/**
|
|
57
|
+
* Applies an expiry policy to a decoded invoice.
|
|
58
|
+
*
|
|
59
|
+
* @param invoice - Decoded invoice
|
|
60
|
+
* @param options - Validation time and skew
|
|
61
|
+
* @param policy - `unexpired`: the invoice must not have expired at `now`
|
|
62
|
+
* (client, server). `settlement`: the paid-but-expired window, valid through
|
|
63
|
+
* `invoice_end + skew` inclusive (facilitator).
|
|
64
|
+
*/
|
|
65
|
+
export declare function checkExpiry(invoice: DecodedInvoice, options: InvoiceCheckOptions, policy: "unexpired" | "settlement"): void;
|
|
66
|
+
/**
|
|
67
|
+
* Checks that a network is one of the configured networks (own keys only, so
|
|
68
|
+
* names such as `constructor` never match).
|
|
69
|
+
*
|
|
70
|
+
* @param network - Candidate network
|
|
71
|
+
* @param networks - Supported networks mapped to BOLT11 currency
|
|
72
|
+
* @returns Whether the network is supported
|
|
73
|
+
*/
|
|
74
|
+
export declare function isSupportedNetwork(network: unknown, networks: Readonly<Record<string, string>>): network is string;
|
|
75
|
+
/**
|
|
76
|
+
* Validates a clock-skew allowance.
|
|
77
|
+
*
|
|
78
|
+
* @param skew - Seconds
|
|
79
|
+
*/
|
|
80
|
+
export declare function validateSkew(skew: number): void;
|
|
81
|
+
/**
|
|
82
|
+
* Checks for a lowercase compressed secp256k1 public key on the curve.
|
|
83
|
+
*
|
|
84
|
+
* @param value - Candidate
|
|
85
|
+
* @returns Whether it is valid
|
|
86
|
+
*/
|
|
87
|
+
export declare function isCompressedPubkey(value: unknown): value is string;
|
|
88
|
+
/**
|
|
89
|
+
* Current Unix time in whole seconds.
|
|
90
|
+
*
|
|
91
|
+
* @returns Seconds since the epoch
|
|
92
|
+
*/
|
|
93
|
+
export declare function unixNow(): number;
|
|
94
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../../src/node/vendor/x402-lnbtc/validation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAqB,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAKL,KAAK,gBAAgB,EAGtB,MAAM,gBAAgB,CAAC;AAKxB;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,KAAK,CAEtD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,mBAAmB,EACxB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACzC,IAAI,CASN;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,IAAI,CAMtF;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,mBAAmB,EACxB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACzC,mBAAmB,CAIrB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,mBAAmB,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