@arkade-os/boltz-swap 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.
Files changed (2) hide show
  1. package/README.md +180 -0
  2. package/package.json +67 -0
package/README.md ADDED
@@ -0,0 +1,180 @@
1
+ # Lightning Swaps
2
+
3
+ > Integrate Lightning Network with Arkade using Submarine Swaps
4
+
5
+ Arkade provides seamless integration with the Lightning Network through Boltz submarine swaps, allowing users to move funds between Arkade and Lightning channels.
6
+
7
+ ## Overview
8
+
9
+ The `BoltzSwapProvider` library extends Arkade's functionality by enabling:
10
+
11
+ 1. **Lightning to Arkade swaps** - Receive funds from Lightning payments into your Arkade wallet
12
+ 2. **Arkade to Lightning swaps** - Send funds from your Arkade wallet to Lightning invoices
13
+
14
+ This integration is built on top of the Boltz submarine swap protocol, providing a reliable and secure way to bridge the gap between Arkade and the Lightning Network.
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @arkade-os/sdk @arkade-os/boltz-swap
20
+ ```
21
+
22
+ ## Basic Usage
23
+
24
+ ### Initializing the Lightning Swap Provider
25
+
26
+ ```typescript
27
+ import { Wallet } from '@arkade-os/sdk';
28
+ import { ArkadeLightning, BoltzSwapProvider } from '@arkade-os/boltz-swap';
29
+
30
+ // Initialize your Arkade wallet
31
+ const wallet = await Wallet.create({
32
+ identity,
33
+ arkServerUrl: 'https://mutinynet.arkade.sh',
34
+ });
35
+
36
+ // Initialize the Lightning swap provider
37
+ const swapProvider = new BoltzSwapProvider({
38
+ apiUrl: 'https://api.boltz.mutinynet.arkade.sh',
39
+ network: 'mutinynet',
40
+ });
41
+
42
+ // Optionaly: initialize a storage provider
43
+ const storageProvider = StorageProvider.create();
44
+
45
+ // Create the ArkadeLightning instance
46
+ const arkadeLightning = new ArkadeLightning({
47
+ wallet,
48
+ swapProvider,
49
+ storageProvider, // optional
50
+ });
51
+ ```
52
+
53
+ ## Storage
54
+
55
+ By default this library doesn't store pending swaps.
56
+
57
+ If you need it you must initialize a storageProvider:
58
+
59
+ ```typescript
60
+ const storageProvider = StorageProvider.create({ storagePath: './storage.json' });
61
+
62
+ const arkadeLightning = new ArkadeLightning({
63
+ wallet,
64
+ swapProvider,
65
+ storageProvider,
66
+ });
67
+
68
+ // you now are able to use the following methods
69
+ const pendingPaymentsToLightning = arkadeLightning.getPendingSubmarineSwaps();
70
+ const pendingPaymentsFromLightning = arkadeLightning.getPendingReverseSwaps();
71
+ ```
72
+
73
+ ## Receiving Lightning Payments
74
+
75
+ To receive a Lightning payment into your Arkade wallet:
76
+
77
+ ```typescript
78
+ // Create a Lightning invoice that will deposit funds to your Arkade wallet
79
+ const result = await arkadeLightning.createLightningInvoice({
80
+ amount: 50000, // 50,000 sats
81
+ description: 'Payment to my Arkade wallet',
82
+ });
83
+
84
+ console.log('Receive amount:', result.amount);
85
+ console.log('Expiry (seconds):', result.expiry);
86
+ console.log('Lightning Invoice:', result.invoice);
87
+ console.log('Payment Hash:', result.paymentHash);
88
+ console.log('Pending swap', result.pendingSwap);
89
+ console.log('Preimage', result.preimage);
90
+
91
+ // The invoice can now be shared with the payer
92
+ // When paid, funds will appear in your Arkade wallet
93
+ ```
94
+
95
+ ### Monitoring Incoming Lightning Payments
96
+
97
+ You must monitor the status of incoming Lightning payments.
98
+ It will automatically claim the payment when it's available.
99
+
100
+ ```typescript
101
+ // Monitor the payment, it will resolve when the payment is received
102
+ const receivalResult = await arkadeLightning.waitAndClaim(result.pendingSwap);
103
+ console.log('Receival successful!');
104
+ console.log('Transaction ID:', receivalResult.txid);
105
+ ```
106
+
107
+ ## Sending Lightning Payments
108
+
109
+ To send a payment from your Arkade wallet to a Lightning invoice:
110
+
111
+ ```typescript
112
+ // Parse a Lightning invoice
113
+ const invoiceDetails = await arkadeLightning.decodeInvoice(
114
+ 'lnbc500u1pj...' // Lightning invoice string
115
+ );
116
+
117
+ console.log('Invoice amount:', invoiceDetails.amountSats, 'sats');
118
+ console.log('Description:', invoiceDetails.description);
119
+ console.log('Destination:', invoiceDetails.destination);
120
+
121
+ // Pay the Lightning invoice from your Arkade wallet
122
+ const paymentResult = await arkadeLightning.sendLightningPayment({
123
+ invoice: 'lnbc500u1pj...', // Lightning invoice string
124
+ maxFeeSats: 1000, // Optional: Maximum fee you're willing to pay (in sats)
125
+ });
126
+
127
+ console.log('Payment successful!');
128
+ console.log('Amount:', paymentResult.amount);
129
+ console.log('Preimage:', paymentResult.preimage);
130
+ console.log('Transaction ID:', paymentResult.txid);
131
+ ```
132
+
133
+ ## Error Handling
134
+
135
+ The library provides detailed error types to help you handle different failure scenarios:
136
+
137
+ ```typescript
138
+ import {
139
+ SwapError,
140
+ SchemaError,
141
+ NetworkError,
142
+ SwapExpiredError,
143
+ InvoiceExpiredError,
144
+ InvoiceFailedToPayError,
145
+ InsufficientFundsError,
146
+ TransactionFailedError,
147
+ } from '@arkade-os/boltz-swap';
148
+
149
+ try {
150
+ await arkadeLightning.sendLightningPayment({
151
+ invoice: 'lnbc500u1pj...',
152
+ });
153
+ } catch (error) {
154
+ if (error instanceof InvoiceExpiredError) {
155
+ console.error('The invoice has expired. Please request a new one.');
156
+ } else if (error instanceof InvoiceFailedToPayError) {
157
+ console.error('The provider failed to pay the invoice. Please request a new one.');
158
+ } else if (error instanceof InsufficientFundsError) {
159
+ console.error('Not enough funds available:', error.message);
160
+ } else if (error instanceof NetworkError) {
161
+ console.error('Network issue. Please try again later:', error.message);
162
+ } else if (error instanceof SchemaError) {
163
+ console.error('Invalid response from API. Please try again later.');
164
+ } else if (error instanceof SwapExpiredError) {
165
+ console.error('The swap has expired. Please request a new invoice.');
166
+ } else if (error instanceof SwapError) {
167
+ console.error('Swap failed:', error.message);
168
+ } else if (error instanceof TransactionFailedError) {
169
+ console.error('Transaction failed. Please try again later');
170
+ } else {
171
+ console.error('Unknown error:', error);
172
+ }
173
+
174
+ // You might be able to claim a refund
175
+ if (error.isRefundable && error.pendingSwap) {
176
+ const refundResult = await arkadeLightning.refundVHTLC(error.pendingSwap);
177
+ console.log('Refund claimed:', refundResult.txid);
178
+ }
179
+ }
180
+ ```
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@arkade-os/boltz-swap",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "A production-ready TypeScript package that brings Boltz submarine-swaps to Arkade.",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.mjs"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "keywords": [
25
+ "arkade",
26
+ "boltz",
27
+ "swap",
28
+ "lightning",
29
+ "bitcoin"
30
+ ],
31
+ "author": "Arkade-OS",
32
+ "license": "MIT",
33
+ "dependencies": {
34
+ "@arkade-os/sdk": "^0.2.1",
35
+ "@noble/hashes": "^1.3.3",
36
+ "@scure/btc-signer": "^1.2.1",
37
+ "light-bolt11-decoder": "^3.2.0"
38
+ },
39
+ "devDependencies": {
40
+ "@eslint/js": "^9.29.0",
41
+ "@noble/curves": "^1.9.4",
42
+ "@types/node": "^24.0.4",
43
+ "@types/ws": "^8.18.1",
44
+ "@typescript-eslint/eslint-plugin": "^8.35.0",
45
+ "@typescript-eslint/parser": "^8.35.0",
46
+ "eslint": "^9.29.0",
47
+ "eslint-define-config": "^2.1.0",
48
+ "tsup": "^8.0.2",
49
+ "typescript": "^5.3.3",
50
+ "vite": "^7.0.0",
51
+ "vitest": "^3.2.4"
52
+ },
53
+ "engines": {
54
+ "node": ">=22"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ },
59
+ "scripts": {
60
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean",
61
+ "test": "vitest run",
62
+ "lint": "eslint src --ext .ts",
63
+ "release": "bash scripts/release.sh",
64
+ "release:dry-run": "bash scripts/release.sh --dry-run",
65
+ "release:cleanup": "bash scripts/release.sh --cleanup"
66
+ }
67
+ }