@t402/btc 2.7.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.
Files changed (62) hide show
  1. package/README.md +120 -0
  2. package/dist/cjs/exact/client/index.d.ts +89 -0
  3. package/dist/cjs/exact/client/index.js +145 -0
  4. package/dist/cjs/exact/client/index.js.map +1 -0
  5. package/dist/cjs/exact/facilitator/index.d.ts +114 -0
  6. package/dist/cjs/exact/facilitator/index.js +218 -0
  7. package/dist/cjs/exact/facilitator/index.js.map +1 -0
  8. package/dist/cjs/exact/server/index.d.ts +101 -0
  9. package/dist/cjs/exact/server/index.js +161 -0
  10. package/dist/cjs/exact/server/index.js.map +1 -0
  11. package/dist/cjs/index.d.ts +179 -0
  12. package/dist/cjs/index.js +849 -0
  13. package/dist/cjs/index.js.map +1 -0
  14. package/dist/cjs/lightning/client/index.d.ts +82 -0
  15. package/dist/cjs/lightning/client/index.js +114 -0
  16. package/dist/cjs/lightning/client/index.js.map +1 -0
  17. package/dist/cjs/lightning/facilitator/index.d.ts +93 -0
  18. package/dist/cjs/lightning/facilitator/index.js +211 -0
  19. package/dist/cjs/lightning/facilitator/index.js.map +1 -0
  20. package/dist/cjs/lightning/server/index.d.ts +96 -0
  21. package/dist/cjs/lightning/server/index.js +157 -0
  22. package/dist/cjs/lightning/server/index.js.map +1 -0
  23. package/dist/cjs/signer-B_Z4WGLa.d.ts +64 -0
  24. package/dist/esm/chunk-2DEKJ7ER.mjs +123 -0
  25. package/dist/esm/chunk-2DEKJ7ER.mjs.map +1 -0
  26. package/dist/esm/chunk-3IOPLDQH.mjs +74 -0
  27. package/dist/esm/chunk-3IOPLDQH.mjs.map +1 -0
  28. package/dist/esm/chunk-7IU3Z36R.mjs +103 -0
  29. package/dist/esm/chunk-7IU3Z36R.mjs.map +1 -0
  30. package/dist/esm/chunk-HNFWDITA.mjs +170 -0
  31. package/dist/esm/chunk-HNFWDITA.mjs.map +1 -0
  32. package/dist/esm/chunk-MX3PAUPJ.mjs +65 -0
  33. package/dist/esm/chunk-MX3PAUPJ.mjs.map +1 -0
  34. package/dist/esm/chunk-YJYTK2QQ.mjs +127 -0
  35. package/dist/esm/chunk-YJYTK2QQ.mjs.map +1 -0
  36. package/dist/esm/chunk-YWZC2RR7.mjs +38 -0
  37. package/dist/esm/chunk-YWZC2RR7.mjs.map +1 -0
  38. package/dist/esm/chunk-ZOL5R3HZ.mjs +177 -0
  39. package/dist/esm/chunk-ZOL5R3HZ.mjs.map +1 -0
  40. package/dist/esm/exact/client/index.d.mts +89 -0
  41. package/dist/esm/exact/client/index.mjs +11 -0
  42. package/dist/esm/exact/client/index.mjs.map +1 -0
  43. package/dist/esm/exact/facilitator/index.d.mts +114 -0
  44. package/dist/esm/exact/facilitator/index.mjs +11 -0
  45. package/dist/esm/exact/facilitator/index.mjs.map +1 -0
  46. package/dist/esm/exact/server/index.d.mts +101 -0
  47. package/dist/esm/exact/server/index.mjs +10 -0
  48. package/dist/esm/exact/server/index.mjs.map +1 -0
  49. package/dist/esm/index.d.mts +179 -0
  50. package/dist/esm/index.mjs +77 -0
  51. package/dist/esm/index.mjs.map +1 -0
  52. package/dist/esm/lightning/client/index.d.mts +82 -0
  53. package/dist/esm/lightning/client/index.mjs +11 -0
  54. package/dist/esm/lightning/client/index.mjs.map +1 -0
  55. package/dist/esm/lightning/facilitator/index.d.mts +93 -0
  56. package/dist/esm/lightning/facilitator/index.mjs +11 -0
  57. package/dist/esm/lightning/facilitator/index.mjs.map +1 -0
  58. package/dist/esm/lightning/server/index.d.mts +96 -0
  59. package/dist/esm/lightning/server/index.mjs +10 -0
  60. package/dist/esm/lightning/server/index.mjs.map +1 -0
  61. package/dist/esm/signer-B_Z4WGLa.d.mts +64 -0
  62. package/package.json +142 -0
@@ -0,0 +1,101 @@
1
+ import { SchemeNetworkServer, MoneyParser, Price, Network, AssetAmount, PaymentRequirements } from '@t402/core/types';
2
+ import { t402ResourceServer } from '@t402/core/server';
3
+
4
+ /**
5
+ * Bitcoin On-chain Server Scheme Implementation
6
+ *
7
+ * Handles price parsing and payment requirement enhancement for
8
+ * Bitcoin on-chain payments using the exact scheme.
9
+ */
10
+
11
+ /**
12
+ * Configuration options for ExactBtcScheme server
13
+ */
14
+ interface ExactBtcSchemeConfig {
15
+ /**
16
+ * The Bitcoin address to receive payments
17
+ */
18
+ payTo: string;
19
+ }
20
+ /**
21
+ * Bitcoin server implementation for the Exact payment scheme.
22
+ * Handles price parsing and converts user-friendly amounts to satoshis.
23
+ *
24
+ * For Bitcoin, the asset is always "BTC" and amounts are in satoshis.
25
+ */
26
+ declare class ExactBtcScheme implements SchemeNetworkServer {
27
+ readonly scheme = "exact";
28
+ private moneyParsers;
29
+ private config;
30
+ constructor(config: ExactBtcSchemeConfig);
31
+ /**
32
+ * Register a custom money parser in the parser chain.
33
+ *
34
+ * @param parser - Custom function to convert amount to AssetAmount (or null to skip)
35
+ * @returns The server instance for chaining
36
+ */
37
+ registerMoneyParser(parser: MoneyParser): ExactBtcScheme;
38
+ /**
39
+ * Parses a price into an asset amount in satoshis.
40
+ *
41
+ * Accepts:
42
+ * - Number: treated as USD, converted to satoshis at a default rate
43
+ * - String with $: treated as USD
44
+ * - AssetAmount: returned directly
45
+ *
46
+ * For Bitcoin, amounts are always in satoshis and the asset is "BTC".
47
+ *
48
+ * @param price - The price to parse
49
+ * @param network - The network to use
50
+ * @returns Promise that resolves to the parsed asset amount
51
+ */
52
+ parsePrice(price: Price, network: Network): Promise<AssetAmount>;
53
+ /**
54
+ * Build payment requirements for this scheme/network combination.
55
+ *
56
+ * @param paymentRequirements - Base payment requirements with amount/asset already set
57
+ * @param supportedKind - The supported kind from facilitator
58
+ * @param extensionKeys - Extensions supported by the facilitator
59
+ * @returns Enhanced payment requirements
60
+ */
61
+ enhancePaymentRequirements(paymentRequirements: PaymentRequirements, supportedKind: {
62
+ t402Version: number;
63
+ scheme: string;
64
+ network: Network;
65
+ extra?: Record<string, unknown>;
66
+ }, extensionKeys: string[]): Promise<PaymentRequirements>;
67
+ /**
68
+ * Parse Money (string | number) to a decimal number.
69
+ */
70
+ private parseMoneyToDecimal;
71
+ /**
72
+ * Default money conversion: treat amount as satoshis.
73
+ * For direct satoshi amounts, the amount is used as-is.
74
+ */
75
+ private defaultMoneyConversion;
76
+ }
77
+
78
+ /**
79
+ * Configuration options for registering BTC schemes to an t402ResourceServer
80
+ */
81
+ interface BtcResourceServerConfig {
82
+ /**
83
+ * Optional specific networks to register
84
+ * If not provided, registers wildcard support (bip122:*)
85
+ */
86
+ networks?: Network[];
87
+ /**
88
+ * Scheme configuration (payTo address, etc.)
89
+ */
90
+ schemeConfig: ExactBtcSchemeConfig;
91
+ }
92
+ /**
93
+ * Registers Bitcoin exact payment schemes to an t402ResourceServer instance.
94
+ *
95
+ * @param server - The t402ResourceServer instance to register schemes to
96
+ * @param config - Configuration for BTC resource server registration
97
+ * @returns The server instance for chaining
98
+ */
99
+ declare function registerExactBtcScheme(server: t402ResourceServer, config: BtcResourceServerConfig): t402ResourceServer;
100
+
101
+ export { type BtcResourceServerConfig, ExactBtcScheme, type ExactBtcSchemeConfig, registerExactBtcScheme };
@@ -0,0 +1,10 @@
1
+ import {
2
+ ExactBtcScheme,
3
+ registerExactBtcScheme
4
+ } from "../../chunk-YJYTK2QQ.mjs";
5
+ import "../../chunk-YWZC2RR7.mjs";
6
+ export {
7
+ ExactBtcScheme,
8
+ registerExactBtcScheme
9
+ };
10
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,179 @@
1
+ export { BtcClientConfig, ExactBtcScheme, registerExactBtcScheme as registerExactBtcClientScheme } from './exact/client/index.mjs';
2
+ export { LightningClientConfig, LightningScheme, registerLightningScheme as registerLightningClientScheme } from './lightning/client/index.mjs';
3
+ export { BtcResourceServerConfig, ExactBtcSchemeConfig, registerExactBtcScheme as registerExactBtcServerScheme } from './exact/server/index.mjs';
4
+ export { BtcFacilitatorConfig, FacilitatorBtcSigner, registerExactBtcScheme as registerExactBtcFacilitatorScheme } from './exact/facilitator/index.mjs';
5
+ export { InvoiceGenerator, LightningResourceServerConfig, LightningSchemeConfig, registerLightningScheme as registerLightningServerScheme } from './lightning/server/index.mjs';
6
+ export { FacilitatorLightningSigner, LightningFacilitatorConfig, registerLightningScheme as registerLightningFacilitatorScheme } from './lightning/facilitator/index.mjs';
7
+ export { C as ClientBtcSigner, a as ClientLightningSigner } from './signer-B_Z4WGLa.mjs';
8
+ import '@t402/core/types';
9
+ import '@t402/core/client';
10
+ import '@t402/core/server';
11
+ import '@t402/core/facilitator';
12
+
13
+ /**
14
+ * Bitcoin & Lightning Network Payment Payload Types
15
+ *
16
+ * Defines the payload structures for BTC on-chain and Lightning payments
17
+ * in the t402 protocol.
18
+ */
19
+ /**
20
+ * Bitcoin on-chain payment payload for the exact scheme (V2)
21
+ * Contains a signed PSBT (Partially Signed Bitcoin Transaction)
22
+ */
23
+ type BtcOnchainPayload = {
24
+ /**
25
+ * Base64-encoded signed PSBT
26
+ * Contains the complete transaction ready for finalization and broadcast
27
+ */
28
+ signedPsbt: string;
29
+ /**
30
+ * Optional transaction ID (available after broadcast)
31
+ */
32
+ txId?: string;
33
+ };
34
+ /**
35
+ * Lightning Network payment payload
36
+ * Contains proof of payment via preimage
37
+ */
38
+ type LightningPayload = {
39
+ /**
40
+ * SHA-256 payment hash (hex-encoded)
41
+ * Identifies the payment on the Lightning Network
42
+ */
43
+ paymentHash: string;
44
+ /**
45
+ * Payment preimage (hex-encoded)
46
+ * Proof that the payment was completed (SHA-256(preimage) === paymentHash)
47
+ */
48
+ preimage: string;
49
+ /**
50
+ * BOLT11 invoice string that was paid
51
+ */
52
+ bolt11Invoice: string;
53
+ };
54
+
55
+ /**
56
+ * Bitcoin & Lightning Network Constants
57
+ *
58
+ * CAIP-2 network identifiers, dust limits, and fee constants.
59
+ */
60
+ /**
61
+ * CAIP-2 Network Identifiers for Bitcoin
62
+ * Uses BIP-122 chain genesis block hashes
63
+ */
64
+ declare const BTC_MAINNET = "bip122:000000000019d6689c085ae165831e93";
65
+ declare const BTC_TESTNET = "bip122:000000000933ea01ad0ee984209779ba";
66
+ /**
67
+ * CAIP-2 Network Identifiers for Lightning Network
68
+ */
69
+ declare const LIGHTNING_MAINNET = "lightning:mainnet";
70
+ declare const LIGHTNING_TESTNET = "lightning:testnet";
71
+ /**
72
+ * All supported BTC on-chain networks
73
+ */
74
+ declare const BTC_NETWORKS: readonly ["bip122:000000000019d6689c085ae165831e93", "bip122:000000000933ea01ad0ee984209779ba"];
75
+ /**
76
+ * All supported Lightning networks
77
+ */
78
+ declare const LIGHTNING_NETWORKS: readonly ["lightning:mainnet", "lightning:testnet"];
79
+ /**
80
+ * All supported networks (on-chain + Lightning)
81
+ */
82
+ declare const ALL_NETWORKS: readonly ["bip122:000000000019d6689c085ae165831e93", "bip122:000000000933ea01ad0ee984209779ba", "lightning:mainnet", "lightning:testnet"];
83
+ type BtcNetwork = (typeof BTC_NETWORKS)[number];
84
+ type LightningNetwork = (typeof LIGHTNING_NETWORKS)[number];
85
+ /**
86
+ * Dust limit in satoshis - minimum viable output value
87
+ * Outputs below this threshold are rejected by Bitcoin nodes
88
+ */
89
+ declare const DUST_LIMIT = 546;
90
+ /**
91
+ * Minimum relay fee in satoshis
92
+ * Transactions with fees below this are not relayed by default
93
+ */
94
+ declare const MIN_RELAY_FEE = 1000;
95
+ /**
96
+ * Satoshis per BTC
97
+ */
98
+ declare const SATS_PER_BTC = 100000000;
99
+ /**
100
+ * Scheme identifiers
101
+ */
102
+ declare const SCHEME_EXACT = "exact";
103
+ /**
104
+ * Default timeout for payment validity (in seconds)
105
+ */
106
+ declare const DEFAULT_VALIDITY_DURATION = 3600;
107
+ /**
108
+ * Bitcoin address prefixes for basic validation
109
+ */
110
+ declare const MAINNET_ADDRESS_PREFIXES: string[];
111
+ declare const TESTNET_ADDRESS_PREFIXES: string[];
112
+
113
+ /**
114
+ * Bitcoin & Lightning Utility Functions
115
+ *
116
+ * Helper functions for address validation, unit conversion,
117
+ * and invoice validation.
118
+ */
119
+ /**
120
+ * Convert satoshis to BTC
121
+ *
122
+ * @param sats - Amount in satoshis
123
+ * @returns Amount in BTC as string (to avoid floating point issues)
124
+ */
125
+ declare function satoshisToBtc(sats: bigint | number | string): string;
126
+ /**
127
+ * Convert BTC to satoshis
128
+ *
129
+ * @param btc - Amount in BTC (string or number)
130
+ * @returns Amount in satoshis as bigint
131
+ */
132
+ declare function btcToSatoshis(btc: string | number): bigint;
133
+ /**
134
+ * Validate a Bitcoin address (basic format validation)
135
+ *
136
+ * Checks address prefix against known formats:
137
+ * - Mainnet: bc1 (bech32), 1 (P2PKH), 3 (P2SH)
138
+ * - Testnet: tb1 (bech32), m/n (P2PKH), 2 (P2SH)
139
+ *
140
+ * @param address - Bitcoin address to validate
141
+ * @returns true if the address has a valid format
142
+ */
143
+ declare function validateBitcoinAddress(address: string): boolean;
144
+ /**
145
+ * Check if a Bitcoin address is for mainnet
146
+ *
147
+ * @param address - Bitcoin address
148
+ * @returns true if mainnet address
149
+ */
150
+ declare function isMainnetAddress(address: string): boolean;
151
+ /**
152
+ * Check if a Bitcoin address is for testnet
153
+ *
154
+ * @param address - Bitcoin address
155
+ * @returns true if testnet address
156
+ */
157
+ declare function isTestnetAddress(address: string): boolean;
158
+ /**
159
+ * Validate a BOLT11 Lightning invoice (basic format validation)
160
+ *
161
+ * BOLT11 invoices follow the format:
162
+ * - lnbc... for mainnet
163
+ * - lntb... for testnet
164
+ * - lnbcrt... for regtest
165
+ *
166
+ * @param invoice - BOLT11 invoice string
167
+ * @returns true if the invoice has a valid format
168
+ */
169
+ declare function validateBolt11Invoice(invoice: string): boolean;
170
+ /**
171
+ * Validate a hex-encoded string
172
+ *
173
+ * @param hex - String to validate
174
+ * @param expectedLength - Expected byte length (hex length / 2)
175
+ * @returns true if valid hex of expected length
176
+ */
177
+ declare function isValidHex(hex: string, expectedLength?: number): boolean;
178
+
179
+ export { ALL_NETWORKS, BTC_MAINNET, BTC_NETWORKS, BTC_TESTNET, type BtcNetwork, type BtcOnchainPayload, DEFAULT_VALIDITY_DURATION, DUST_LIMIT, LIGHTNING_MAINNET, LIGHTNING_NETWORKS, LIGHTNING_TESTNET, type LightningNetwork, type LightningPayload, MAINNET_ADDRESS_PREFIXES, MIN_RELAY_FEE, SATS_PER_BTC, SCHEME_EXACT, TESTNET_ADDRESS_PREFIXES, btcToSatoshis, isMainnetAddress, isTestnetAddress, isValidHex, satoshisToBtc, validateBitcoinAddress, validateBolt11Invoice };
@@ -0,0 +1,77 @@
1
+ import {
2
+ ExactBtcScheme,
3
+ registerExactBtcScheme
4
+ } from "./chunk-7IU3Z36R.mjs";
5
+ import {
6
+ registerExactBtcScheme as registerExactBtcScheme2
7
+ } from "./chunk-YJYTK2QQ.mjs";
8
+ import {
9
+ registerExactBtcScheme as registerExactBtcScheme3
10
+ } from "./chunk-ZOL5R3HZ.mjs";
11
+ import {
12
+ LightningScheme,
13
+ registerLightningScheme
14
+ } from "./chunk-3IOPLDQH.mjs";
15
+ import {
16
+ registerLightningScheme as registerLightningScheme2
17
+ } from "./chunk-2DEKJ7ER.mjs";
18
+ import {
19
+ registerLightningScheme as registerLightningScheme3
20
+ } from "./chunk-HNFWDITA.mjs";
21
+ import {
22
+ btcToSatoshis,
23
+ isMainnetAddress,
24
+ isTestnetAddress,
25
+ isValidHex,
26
+ satoshisToBtc,
27
+ validateBitcoinAddress,
28
+ validateBolt11Invoice
29
+ } from "./chunk-MX3PAUPJ.mjs";
30
+ import {
31
+ ALL_NETWORKS,
32
+ BTC_MAINNET,
33
+ BTC_NETWORKS,
34
+ BTC_TESTNET,
35
+ DEFAULT_VALIDITY_DURATION,
36
+ DUST_LIMIT,
37
+ LIGHTNING_MAINNET,
38
+ LIGHTNING_NETWORKS,
39
+ LIGHTNING_TESTNET,
40
+ MAINNET_ADDRESS_PREFIXES,
41
+ MIN_RELAY_FEE,
42
+ SATS_PER_BTC,
43
+ SCHEME_EXACT,
44
+ TESTNET_ADDRESS_PREFIXES
45
+ } from "./chunk-YWZC2RR7.mjs";
46
+ export {
47
+ ALL_NETWORKS,
48
+ BTC_MAINNET,
49
+ BTC_NETWORKS,
50
+ BTC_TESTNET,
51
+ DEFAULT_VALIDITY_DURATION,
52
+ DUST_LIMIT,
53
+ ExactBtcScheme,
54
+ LIGHTNING_MAINNET,
55
+ LIGHTNING_NETWORKS,
56
+ LIGHTNING_TESTNET,
57
+ LightningScheme,
58
+ MAINNET_ADDRESS_PREFIXES,
59
+ MIN_RELAY_FEE,
60
+ SATS_PER_BTC,
61
+ SCHEME_EXACT,
62
+ TESTNET_ADDRESS_PREFIXES,
63
+ btcToSatoshis,
64
+ isMainnetAddress,
65
+ isTestnetAddress,
66
+ isValidHex,
67
+ registerExactBtcScheme as registerExactBtcClientScheme,
68
+ registerExactBtcScheme3 as registerExactBtcFacilitatorScheme,
69
+ registerExactBtcScheme2 as registerExactBtcServerScheme,
70
+ registerLightningScheme as registerLightningClientScheme,
71
+ registerLightningScheme3 as registerLightningFacilitatorScheme,
72
+ registerLightningScheme2 as registerLightningServerScheme,
73
+ satoshisToBtc,
74
+ validateBitcoinAddress,
75
+ validateBolt11Invoice
76
+ };
77
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,82 @@
1
+ import { SchemeNetworkClient, PaymentRequirements, PaymentPayload, Network } from '@t402/core/types';
2
+ import { a as ClientLightningSigner } from '../../signer-B_Z4WGLa.mjs';
3
+ import { PaymentPolicy, t402Client } from '@t402/core/client';
4
+
5
+ /**
6
+ * Lightning Network Client Scheme Implementation
7
+ *
8
+ * Creates payment payloads for Lightning Network payments.
9
+ * Pays BOLT11 invoices and returns preimage as proof of payment.
10
+ */
11
+
12
+ /**
13
+ * Lightning Network client implementation for the Exact payment scheme.
14
+ *
15
+ * Pays BOLT11 invoices using a Lightning node and returns the
16
+ * payment preimage as proof of payment.
17
+ *
18
+ * Note: The scheme is 'exact' because Lightning payments are always
19
+ * for the exact invoice amount.
20
+ */
21
+ declare class LightningScheme implements SchemeNetworkClient {
22
+ private readonly signer;
23
+ readonly scheme = "exact";
24
+ /**
25
+ * Creates a new LightningScheme instance.
26
+ *
27
+ * @param signer - The Lightning signer for client operations
28
+ */
29
+ constructor(signer: ClientLightningSigner);
30
+ /**
31
+ * Creates a payment payload for the Lightning scheme.
32
+ *
33
+ * 1. Extracts the BOLT11 invoice from requirements.extra.bolt11Invoice
34
+ * 2. Pays the invoice using the Lightning signer
35
+ * 3. Returns the preimage and payment hash as proof of payment
36
+ *
37
+ * @param t402Version - The t402 protocol version
38
+ * @param paymentRequirements - The payment requirements
39
+ * @returns Promise resolving to a payment payload
40
+ */
41
+ createPaymentPayload(t402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, 't402Version' | 'payload'>>;
42
+ }
43
+
44
+ /**
45
+ * Configuration options for registering Lightning schemes to an t402Client
46
+ */
47
+ interface LightningClientConfig {
48
+ /**
49
+ * The Lightning signer to use for paying invoices
50
+ */
51
+ signer: ClientLightningSigner;
52
+ /**
53
+ * Optional policies to apply to the client
54
+ */
55
+ policies?: PaymentPolicy[];
56
+ /**
57
+ * Optional specific networks to register
58
+ * If not provided, registers wildcard support (lightning:*)
59
+ */
60
+ networks?: Network[];
61
+ }
62
+ /**
63
+ * Registers Lightning payment schemes to an t402Client instance.
64
+ *
65
+ * @param client - The t402Client instance to register schemes to
66
+ * @param config - Configuration for Lightning client registration
67
+ * @returns The client instance for chaining
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * import { registerLightningScheme } from "@t402/btc/lightning/client";
72
+ * import { t402Client } from "@t402/core/client";
73
+ *
74
+ * const client = new t402Client();
75
+ * registerLightningScheme(client, {
76
+ * signer: myLnSigner,
77
+ * });
78
+ * ```
79
+ */
80
+ declare function registerLightningScheme(client: t402Client, config: LightningClientConfig): t402Client;
81
+
82
+ export { type LightningClientConfig, LightningScheme, registerLightningScheme };
@@ -0,0 +1,11 @@
1
+ import {
2
+ LightningScheme,
3
+ registerLightningScheme
4
+ } from "../../chunk-3IOPLDQH.mjs";
5
+ import "../../chunk-MX3PAUPJ.mjs";
6
+ import "../../chunk-YWZC2RR7.mjs";
7
+ export {
8
+ LightningScheme,
9
+ registerLightningScheme
10
+ };
11
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,93 @@
1
+ import { SchemeNetworkFacilitator, PaymentPayload, PaymentRequirements, VerifyResponse, SettleResponse, Network } from '@t402/core/types';
2
+ import { t402Facilitator } from '@t402/core/facilitator';
3
+
4
+ /**
5
+ * Lightning Network Facilitator Scheme Implementation
6
+ *
7
+ * Verifies Lightning Network payments using preimage verification.
8
+ * Lightning payments are atomic (settle-on-pay), so settlement is a no-op.
9
+ */
10
+
11
+ /**
12
+ * Facilitator Lightning signer interface
13
+ */
14
+ interface FacilitatorLightningSigner {
15
+ /**
16
+ * Get all node public keys this facilitator manages
17
+ */
18
+ getAddresses(): readonly string[];
19
+ /**
20
+ * Look up a payment by its payment hash
21
+ *
22
+ * @param paymentHash - Hex-encoded payment hash
23
+ * @returns Payment status
24
+ */
25
+ lookupPayment(paymentHash: string): Promise<{
26
+ settled: boolean;
27
+ amountSats?: string;
28
+ preimage?: string;
29
+ }>;
30
+ }
31
+ /**
32
+ * Lightning Network facilitator implementation for the Exact payment scheme.
33
+ *
34
+ * Verification is done by checking that SHA-256(preimage) === paymentHash.
35
+ * Lightning payments are atomic, so settle is a confirmation-only operation.
36
+ */
37
+ declare class LightningScheme implements SchemeNetworkFacilitator {
38
+ private readonly signer;
39
+ readonly scheme = "exact";
40
+ readonly caipFamily = "lightning:*";
41
+ constructor(signer: FacilitatorLightningSigner);
42
+ /**
43
+ * Get mechanism-specific extra data for the supported kinds endpoint.
44
+ * Lightning has no extra data.
45
+ */
46
+ getExtra(_network: string): Record<string, unknown> | undefined;
47
+ /**
48
+ * Get signer addresses (node public keys) for this facilitator.
49
+ */
50
+ getSigners(_network: string): string[];
51
+ /**
52
+ * Verifies a Lightning payment payload.
53
+ *
54
+ * Validates:
55
+ * 1. Payload structure (paymentHash, preimage, bolt11Invoice)
56
+ * 2. Preimage verification: SHA-256(preimage) === paymentHash
57
+ * 3. Payment lookup on the Lightning node
58
+ */
59
+ verify(payload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;
60
+ /**
61
+ * Settles a Lightning payment.
62
+ *
63
+ * Lightning payments are atomic (settle-on-pay), so this is effectively
64
+ * a confirmation that the payment was already completed. The actual
65
+ * settlement happened when the client paid the invoice.
66
+ */
67
+ settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
68
+ }
69
+
70
+ /**
71
+ * Configuration options for registering Lightning schemes to an t402Facilitator
72
+ */
73
+ interface LightningFacilitatorConfig {
74
+ /**
75
+ * The Lightning signer for facilitator operations
76
+ */
77
+ signer: FacilitatorLightningSigner;
78
+ /**
79
+ * Networks to register (single network or array of networks)
80
+ * Examples: "lightning:mainnet", ["lightning:mainnet", "lightning:testnet"]
81
+ */
82
+ networks: Network | Network[];
83
+ }
84
+ /**
85
+ * Registers Lightning payment schemes to an t402Facilitator instance.
86
+ *
87
+ * @param facilitator - The t402Facilitator instance to register schemes to
88
+ * @param config - Configuration for Lightning facilitator registration
89
+ * @returns The facilitator instance for chaining
90
+ */
91
+ declare function registerLightningScheme(facilitator: t402Facilitator, config: LightningFacilitatorConfig): t402Facilitator;
92
+
93
+ export { type FacilitatorLightningSigner, type LightningFacilitatorConfig, LightningScheme, registerLightningScheme };
@@ -0,0 +1,11 @@
1
+ import {
2
+ LightningScheme,
3
+ registerLightningScheme
4
+ } from "../../chunk-HNFWDITA.mjs";
5
+ import "../../chunk-MX3PAUPJ.mjs";
6
+ import "../../chunk-YWZC2RR7.mjs";
7
+ export {
8
+ LightningScheme,
9
+ registerLightningScheme
10
+ };
11
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,96 @@
1
+ import { SchemeNetworkServer, MoneyParser, Price, Network, AssetAmount, PaymentRequirements } from '@t402/core/types';
2
+ import { t402ResourceServer } from '@t402/core/server';
3
+
4
+ /**
5
+ * Lightning Network Server Scheme Implementation
6
+ *
7
+ * Handles price parsing and payment requirement enhancement for
8
+ * Lightning Network payments.
9
+ */
10
+
11
+ /**
12
+ * Lightning invoice generator function
13
+ * Used to create BOLT11 invoices for payment requirements
14
+ */
15
+ type InvoiceGenerator = (amountSats: string, description: string, expiry: number) => Promise<{
16
+ bolt11Invoice: string;
17
+ paymentHash: string;
18
+ }>;
19
+ /**
20
+ * Configuration options for Lightning server scheme
21
+ */
22
+ interface LightningSchemeConfig {
23
+ /**
24
+ * Function to generate BOLT11 invoices
25
+ */
26
+ generateInvoice: InvoiceGenerator;
27
+ }
28
+ /**
29
+ * Lightning Network server implementation for the Exact payment scheme.
30
+ * Generates BOLT11 invoices and enhances payment requirements.
31
+ */
32
+ declare class LightningScheme implements SchemeNetworkServer {
33
+ readonly scheme = "exact";
34
+ private moneyParsers;
35
+ private config;
36
+ constructor(config: LightningSchemeConfig);
37
+ /**
38
+ * Register a custom money parser in the parser chain.
39
+ *
40
+ * @param parser - Custom function to convert amount to AssetAmount (or null to skip)
41
+ * @returns The server instance for chaining
42
+ */
43
+ registerMoneyParser(parser: MoneyParser): LightningScheme;
44
+ /**
45
+ * Parses a price into an asset amount in satoshis.
46
+ *
47
+ * @param price - The price to parse
48
+ * @param network - The network to use
49
+ * @returns Promise that resolves to the parsed asset amount
50
+ */
51
+ parsePrice(price: Price, network: Network): Promise<AssetAmount>;
52
+ /**
53
+ * Build payment requirements for Lightning Network.
54
+ *
55
+ * Generates a BOLT11 invoice and adds it to the extra field.
56
+ */
57
+ enhancePaymentRequirements(paymentRequirements: PaymentRequirements, supportedKind: {
58
+ t402Version: number;
59
+ scheme: string;
60
+ network: Network;
61
+ extra?: Record<string, unknown>;
62
+ }, extensionKeys: string[]): Promise<PaymentRequirements>;
63
+ /**
64
+ * Parse Money (string | number) to a decimal number.
65
+ */
66
+ private parseMoneyToDecimal;
67
+ /**
68
+ * Default money conversion: treat amount as BTC, convert to satoshis.
69
+ */
70
+ private defaultMoneyConversion;
71
+ }
72
+
73
+ /**
74
+ * Configuration options for registering Lightning schemes to an t402ResourceServer
75
+ */
76
+ interface LightningResourceServerConfig {
77
+ /**
78
+ * Optional specific networks to register
79
+ * If not provided, registers wildcard support (lightning:*)
80
+ */
81
+ networks?: Network[];
82
+ /**
83
+ * Scheme configuration (invoice generator, etc.)
84
+ */
85
+ schemeConfig: LightningSchemeConfig;
86
+ }
87
+ /**
88
+ * Registers Lightning payment schemes to an t402ResourceServer instance.
89
+ *
90
+ * @param server - The t402ResourceServer instance to register schemes to
91
+ * @param config - Configuration for Lightning resource server registration
92
+ * @returns The server instance for chaining
93
+ */
94
+ declare function registerLightningScheme(server: t402ResourceServer, config: LightningResourceServerConfig): t402ResourceServer;
95
+
96
+ export { type InvoiceGenerator, type LightningResourceServerConfig, LightningScheme, type LightningSchemeConfig, registerLightningScheme };
@@ -0,0 +1,10 @@
1
+ import {
2
+ LightningScheme,
3
+ registerLightningScheme
4
+ } from "../../chunk-2DEKJ7ER.mjs";
5
+ import "../../chunk-YWZC2RR7.mjs";
6
+ export {
7
+ LightningScheme,
8
+ registerLightningScheme
9
+ };
10
+ //# sourceMappingURL=index.mjs.map