@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,179 @@
1
+ export { BtcClientConfig, ExactBtcScheme, registerExactBtcScheme as registerExactBtcClientScheme } from './exact/client/index.js';
2
+ export { LightningClientConfig, LightningScheme, registerLightningScheme as registerLightningClientScheme } from './lightning/client/index.js';
3
+ export { BtcResourceServerConfig, ExactBtcSchemeConfig, registerExactBtcScheme as registerExactBtcServerScheme } from './exact/server/index.js';
4
+ export { BtcFacilitatorConfig, FacilitatorBtcSigner, registerExactBtcScheme as registerExactBtcFacilitatorScheme } from './exact/facilitator/index.js';
5
+ export { InvoiceGenerator, LightningResourceServerConfig, LightningSchemeConfig, registerLightningScheme as registerLightningServerScheme } from './lightning/server/index.js';
6
+ export { FacilitatorLightningSigner, LightningFacilitatorConfig, registerLightningScheme as registerLightningFacilitatorScheme } from './lightning/facilitator/index.js';
7
+ export { C as ClientBtcSigner, a as ClientLightningSigner } from './signer-B_Z4WGLa.js';
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 };