Skip to content

Commit 5e18d0b

Browse files
committed
Rework recovery procedure
The current recovery process needed to be updated to derive the correct master priv key from the seed by specifying our custom BIP32 path (m/52h/0h/2h/0) when we create the wallet. We also export 2 descriptor methods: one to get the private swap-in wallet descriptor, which can be used as-is, and the other to get the public swap-in wallet descriptor, which can be used to create a watch-only wallet to monitor swap-in funds and to recovery funds using our recovery procedure. Both descriptor use the refund master key, and not the master key itself because we use hardened paths to derive the refund key, which means that it is not possible to compute the refund master public key from the master public: importing the descriptor would fail.
1 parent f963c21 commit 5e18d0b

File tree

4 files changed

+163
-107
lines changed

4 files changed

+163
-107
lines changed

RECOVERY.md

Lines changed: 86 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Funds recovery
22

3-
:warning: to recover swap-in funds sent to older versions of Phoenix (up to and including version 2.1.2) pleaser refer to [this guide](https://github.com/ACINQ/lightning-kmp/blob/v1.5.15/RECOVERY.md)
3+
:warning: to recover swap-in funds sent to older versions of Phoenix (up to and including version 2.1.2) please refer to [this guide](https://github.com/ACINQ/lightning-kmp/blob/v1.5.15/RECOVERY.md)
44

5-
The following steps lets you recover on-chain funds managed by `lightning-kmp`.
5+
The following steps let you recover on-chain funds managed by `lightning-kmp`.
66

77
## Closed channels
88

@@ -36,52 +36,75 @@ The swap transaction's output can be spent using either:
3636
Funds can be recovered using the second option and [Bitcoin Core](https://github.com/bitcoin/bitcoin).
3737
This process needs at least Bitcoin Core 26.0.
3838

39-
This process will become simpler once popular on-chain wallets (such as [electrum](https://electrum.org/)) add supports for output script descriptors.
39+
This process will become simpler once popular on-chain wallets (such as [electrum](https://electrum.org/)) add support for output script descriptors.
4040

41-
### Get your wallet descriptor
41+
### Create recovery wallet
4242

43-
lightning-kmp provides both a public descriptor and private descriptor for your swap-in wallet.
44-
The public descriptor can be used to create a watch-only wallet for your swap-in funds.
45-
The private descriptor can be used to recover your swap-in funds, after the refund delay has passed.
46-
:warning: Do not share this private descriptor with anyone !
43+
#### Compute your refund master private key
4744

48-
### Create recovery wallet
45+
For security reasons, we don't directly export the refund master private key used for swap-ins, so you will need to manually insert it in the descriptor.
46+
You can obtain your extended master private key in [electrum](https://electrum.org/).
4947

50-
Create a wallet to recover your funds using the following command:
48+
1. Create a new wallet, and choose `Standard wallet`
49+
2. Choose `I already have a seed`
50+
3. Enter your 12-word seed, and in the `Options` menu select `BIP39 seed`
51+
4. In the `Script type and Derivation path` dialog select `legacy(p2pkh)` and override the derivation path with `m/52h/0h/2h/0`
52+
5. In the `Console` tab, enter `wallet.keystore.xprv`. This will give you your refund master private key
5153

52-
```sh
53-
bitcoin-cli createwallet recovery
54-
```
54+
#### Create your refund wallet descriptor
5555

56-
### Import descriptor into the recovery wallet
56+
Copy the descriptor from the `SWAP_IN WALLET` section in the `Wallet Info` menu on your Phoenix wallet. It should look like this:
5757

58-
`lightning-kmp` provides a public and private descriptor for your swap-in wallet, which both use the following template:
58+
```txt
59+
tr(<extended_public_key>,and_v(v:pk(<refund_master_public_key>/<derivation_path>),older(<refund_delay>)))
60+
```
5961

62+
For example:
6063
```txt
61-
tr(<extended_public_key>,and_v(v:pk(<master_key>/<derivation_path>),older(<refund_delay>)))
64+
tr(1fc559d9c96c5953895d3150e64ebf3dd696a0b08e758650b48ff6251d7e60d1,and_v(v:pk(xpub6EE2N7jrues5kfjrsyFA5f7hknixqqAEKs8vyMN4QW9vDmYnChzpeBPkBYduBobbe4miQ34xHG4Jpwuq5bHXLZY1xixoGynW31ySUqqVvcU/*),older(2590)))#sv8ug44m
6265
```
6366

64-
For example, your public descriptor will look like this:
67+
You can check that the extended public key in this descriptor matches the extended public key of the wallet you created with Electrum to compute your refund master private key.
6568

69+
Replace the `refund master public key` with your refund master private key. For example:
6670
```txt
67-
tr(1fc559d9c96c5953895d3150e64ebf3dd696a0b08e758650b48ff6251d7e60d1,and_v(v:pk(tpubDDqzCA42sbCmnGBcuuiAeLGqB9XHU5Gy1n68omeKf4pwFKe2padzkdXAPsDMWMdee879oPYrGrTS8sioqyjv8b6TztunE526eo4Au9kTef3/*),older(25920)))#z6mq2a3u
71+
tr(1fc559d9c96c5953895d3150e64ebf3dd696a0b08e758650b48ff6251d7e60d1,and_v(v:pk(xprvA1EfxcCy5HJnYBfPmwi9iXAyCktUSNSNxeDLAxxSrAcwLyDdfAga6P5GLHNdq7EiXe8Pzu6Py6xGwT7UTkw824FYf3v6fbRStvYsWqFTu29/*),older(2590)))#sv8ug44m
6872
```
6973

70-
And your private descriptor will look like this:
74+
### Create a bitcoin core recovery wallet
7175

76+
Create a wallet to recover your funds using the following command:
77+
78+
```shell
79+
bitcoin-cli -named createwallet wallet_name=recovery
7280
```
73-
tr(1fc559d9c96c5953895d3150e64ebf3dd696a0b08e758650b48ff6251d7e60d1,and_v(v:pk(tprv8h9x3k1njDX6to9q2G3aEvcic81MJk64SUVMXFc2Eo2YQqPGCBpQa8uJDkTz3DMHVXEmvhuwf4ShjLQ7YaVr34x9DFT3y43cPzVKGB94r1n/*),older(25920)))#7dne06j5
74-
```
7581

76-
We can import our private descriptor into our recovery wallet:
82+
### Import your descriptor into the recovery wallet
83+
84+
We can import our private descriptor into our recovery wallet. Since your replaced you refund master public key with your refund master private key, the descriptor checksum is no longer valid, but bitcoin core will give you the correct checksum:
85+
86+
```shell
87+
bitcoin-cli -rpcwallet=recovery importdescriptors '[{ "desc": "tr(1fc559d9c96c5953895d3150e64ebf3dd696a0b08e758650b48ff6251d7e60d1,and_v(v:pk(xprvA1EfxcCy5HJnYBfPmwi9iXAyCktUSNSNxeDLAxxSrAcwLyDdfAga6P5GLHNdq7EiXe8Pzu6Py6xGwT7UTkw824FYf3v6fbRStvYsWqFTu29/*),older(2590)))#sv8ug44m", "timestamp":0}]'
88+
[
89+
{
90+
"success": false,
91+
"error": {
92+
"code": -5,
93+
"message": "Provided checksum 'sv8ug44m' does not match computed checksum 'ksphr9r4'"
94+
}
95+
}
96+
]
97+
```
7798

78-
```sh
79-
bitcoin-cli -rpcwallet=recovery importdescriptors '[{ "desc": "tr(1fc559d9c96c5953895d3150e64ebf3dd696a0b08e758650b48ff6251d7e60d1,and_v(v:pk(tprv8ZgxMBicQKsPdKRFLVct6VDpfmCxk6aC7iAF8tb6roQ7hv1zFCyGwDLBUUxMVJ95dTiQS5VvCbQ6J7CcGqguw5SbnDpNjbjpfVwcMwUtmjS/51h/0h/0h/*),older(25920)))#rn7cy7yr", "timestamp": 0 }]'
99+
Update the checksum and try again:
100+
```shell
101+
bitcoin-cli -rpcwallet=recovery importdescriptors '[{ "desc": "tr(1fc559d9c96c5953895d3150e64ebf3dd696a0b08e758650b48ff6251d7e60d1,and_v(v:pk(xprvA1EfxcCy5HJnYBfPmwi9iXAyCktUSNSNxeDLAxxSrAcwLyDdfAga6P5GLHNdq7EiXe8Pzu6Py6xGwT7UTkw824FYf3v6fbRStvYsWqFTu29/*),older(2590)))#ksphr9r4", "timestamp":0}]'
80102

81103
[
82104
{
83105
"success": true,
84106
"warnings": [
107+
"Range not given, using default keypool range",
85108
"Not all private keys provided. Some wallet functionality may return unexpected errors"
86109
]
87110
}
@@ -93,14 +116,14 @@ This is a slow process, which can be sped up by setting the `timestamp` field to
93116

94117
Once Bitcoin Core is done with the scanning process, the `getwalletinfo` command will return `"scanning": false`:
95118

96-
```sh
119+
```shell
97120
bitcoin-cli -rpcwallet=recovery getwalletinfo
98121

99122
{
100123
"walletname": "recovery",
101124
"walletversion": 169900,
102125
"format": "sqlite",
103-
"balance": 1.50000000,
126+
"balance": 0.00003000,
104127
"unconfirmed_balance": 0.00000000,
105128
"immature_balance": 0.00000000,
106129
"txcount": 1,
@@ -111,63 +134,70 @@ bitcoin-cli -rpcwallet=recovery getwalletinfo
111134
"avoid_reuse": false,
112135
"scanning": false,
113136
"descriptors": true,
114-
"external_signer": false
137+
"external_signer": false,
138+
"blank": false,
139+
"birthtime": 1707742312,
140+
"lastprocessedblock": {
141+
"hash": "00000000000000000001760b2e9b05c08275c664d78c1ae59093faa64b57b3b2",
142+
"height": 830146
143+
}
115144
}
116145
```
117146

118147
You can then find available funds matching the descriptor we imported:
119148

120-
```sh
121-
bitcoin-cli -rpcwallet=recovery listtransactions
122-
149+
```shell
150+
bitcoin-cli -rpcwallet=recovery listtransactions
123151
[
124152
{
125-
"address": "bcrt1pzz7rudhpqyy6zdnuwrg3dpnethckfzncma2urxghuc62dz49zenqv0p0q6",
153+
"address": "bc1p6pxx4mp43xkac222jmfy958gpxqn7duku6cka9ahdfmdp9aak74sza58es",
126154
"parent_descs": [
127-
"tr(1fc559d9c96c5953895d3150e64ebf3dd696a0b08e758650b48ff6251d7e60d1,and_v(v:pk(tpubDDqzCA42sbCmnGBcuuiAeLGqB9XHU5Gy1n68omeKf4pwFKe2padzkdXAPsDMWMdee879oPYrGrTS8sioqyjv8b6TztunE526eo4Au9kTef3/*),older(144)))#zqam8e56"
155+
"tr(1fc559d9c96c5953895d3150e64ebf3dd696a0b08e758650b48ff6251d7e60d1,and_v(v:pk(xpub6EE2N7jrues5kfjrsyFA5f7hknixqqAEKs8vyMN4QW9vDmYnChzpeBPkBYduBobbe4miQ34xHG4Jpwuq5bHXLZY1xixoGynW31ySUqqVvcU/*),older(2590)))#sv8ug44m"
128156
],
129157
"category": "receive",
130-
"amount": 0.10000000,
131-
"vout": 0,
158+
"amount": 0.00003000,
159+
"vout": 1,
132160
"abandoned": false,
133-
"confirmations": 1,
134-
"blockhash": "06361beb06e7d24bea80fc6800f4b5f374f09542a07fae77a7f8c26a9f7544b2",
135-
"blockheight": 146,
136-
"blockindex": 1,
137-
"blocktime": 1700670588,
138-
"txid": "4c3236b1fa1f3ed124ab83b1667be95f855952e68729eae54a9f511c8c8cb993",
139-
"wtxid": "16ab0b31f680e5bd4f149527148b542e16de96ce2d14db9c41552752f3d8e655",
161+
"confirmations": 0,
162+
"trusted": false,
163+
"txid": "a9e38fee226e3a598d035afdbecd99c5cb0a6039866cc29fd15d7b27c7d8dcff",
164+
"wtxid": "701989d4f18951ae757409ea948e4a9bc3de9bf37dd14a4dcd21ba5355df2401",
140165
"walletconflicts": [
141166
],
142-
"time": 1700670571,
143-
"timereceived": 1700670571,
144-
"bip125-replaceable": "no"
167+
"time": 1707745877,
168+
"timereceived": 1707745877,
169+
"bip125-replaceable": "yes"
145170
}
146171
]
147172
```
148173

149174
### Send funds to a different address
150175

151176
Once those funds have been recovered and the refund delay has expired (the `confirmations` field of the previous command exceeds `25920`), you can send them to your normal on-chain wallet.
152-
Compute the total amount received (in our example, 1.5 BTC), choose the address to send to (for example, `bcrt1q9ez7rt33wynwpah582lnqlj3u0tpzsrkj2flas`) and create a transaction using all of the received funds:
177+
For now, this process involves selecting the inputs that you want to spend and creating the spending transaction manually, as documented below, but future versions of Bitcoin Core will probably make this easier.
178+
179+
For example, if `listtransactions` lists a UTXO `5e9d2a387572fe0c8a4996c2f34373b3fbbdb19ff106b84fc91c2450eb27cbe7:0` of `0.002` Bitcoin, this is how you would send it to your on-chain address.
153180

154-
```sh
155-
bitcoin-cli -rpcwallet=recovery walletcreatefundedpsbt '[{"txid":"4c3236b1fa1f3ed124ab83b1667be95f855952e68729eae54a9f511c8c8cb993", "vout":0, "sequence":144}]' '[{"bcrt1qzy4h8dux6pjl8ys979632uynqffd53vjkzffjl":0.09}]'
181+
```shell
182+
bitcoin-cli -rpcwallet=recovery -named walletcreatefundedpsbt inputs='[{"txid":"5e9d2a387572fe0c8a4996c2f34373b3fbbdb19ff106b84fc91c2450eb27cbe7", "vout":0, "sequence":2590}]' outputs='[{"bcrt1q9qt02fkc2rfpm3w37uvec62kd7yh688uyf8v4w":0.002}]' subtractFeeFromOutputs='[0]'
156183
{
157-
"psbt": "cHNidP8BAHECAAAAAZO5jIwcUZ9K5eoph+ZSWYVf6XtmsYOrJNE+H/qxNjJMAAAAAACQAAAAAkBUiQAAAAAAFgAUEStzt4bQZfOSBfF1FXCTAlLaRZIEOA8AAAAAABYAFEx1yJgBL6kfpf2sybIL0WajM0rXAAAAAAABASuAlpgAAAAAACJRIBC8PjbhAQmhNnxw0RaGeV3xZIp431XBmRfmNKaKpRZmIhXBH8VZ2clsWVOJXTFQ5k6/PdaWoLCOdYZQtI/2JR1+YNEnIG0cAcgg4JAO3Y5ZtLOD5zp/WFAHJFWAT5z/6Z+k+FQbrQKQALLAIRYfxVnZyWxZU4ldMVDmTr891pagsI51hlC0j/YlHX5g0QUA0EkObyEWbRwByCDgkA7djlm0s4PnOn9YUAckVYBPnP/pn6T4VBspAWR9Jdbf5zHI25Gs69RTMJILBCLUX82cmJj59Bk4SZKgTHUGgQAAAAABFyAfxVnZyWxZU4ldMVDmTr891pagsI51hlC0j/YlHX5g0QEYIGR9Jdbf5zHI25Gs69RTMJILBCLUX82cmJj59Bk4SZKgAAAiAgMhzD3XSvW4p+oRyBAvB6rUHaOCIyjVxJV9tEin3sUiqxjpcZ0vVAAAgAEAAIAAAACAAQAAAAEAAAAA",
158-
"fee": 0.00002620,
159-
"changepos": 1
184+
"psbt": "cHNidP8BAFICAAAAAefLJ+tQJBzJT7gG8Z+xvfuzc0PzwpZJigz+cnU4Kp1eAAAAAAAeCgAAAXAFAwAAAAAAFgAUKBb1JthQ0h3F0fcZnGlWb4l9HPwAAAAAAAEBK0ANAwAAAAAAIlEgRsEcQhkAfS6VDjLeJZ2NJRqKVgaibPLHI6oN28AfRBwiFcAfxVnZyWxZU4ldMVDmTr891pagsI51hlC0j/YlHX5g0Scg6oyRJt9CuIzhFceFlxIolSJ/PTrrUxnVV4zHUivjR7WtAh4KssAhFh/FWdnJbFlTiV0xUOZOvz3WlqCwjnWGULSP9iUdfmDRBQDQSQ5vIRbqjJEm30K4jOEVx4WXEiiVIn89OutTGdVXjMdSK+NHtSkBorv4wrBqM9DCSo9s2yigvE2CbsIJiMCn0WW9crBila72QOqbAAAAAAEXIB/FWdnJbFlTiV0xUOZOvz3WlqCwjnWGULSP9iUdfmDRARggorv4wrBqM9DCSo9s2yigvE2CbsIJiMCn0WW9crBila4AAA==",
185+
"fee": 0.00002000,
186+
"changepos": -1
160187
}
188+
```
161189

162-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WlqCwjnWGULSP9iUdfmDRAAA=",
165194
"complete": true,
166-
"hex": "0200000000010193b98c8c1c519f4ae5ea2987e65259855fe97b66b183ab24d13e1ffab136324c000000000090000000024054890000000000160014112b73b786d065f39205f1751570930252da459204380f00000000001600144c75c898012fa91fa5fdacc9b20bd166a3334ad70340f9f7397a4cb9705e4da80a2a3715f7dff1da51426a585acecc698f9c524d597e5d37873c63d6fc0800705041bca1df73c25fb2680eb957c65a3f2def3a8cc8d026206d1c01c820e0900edd8e59b4b383e73a7f5850072455804f9cffe99fa4f8541bad029000b221c11fc559d9c96c5953895d3150e64ebf3dd696a0b08e758650b48ff6251d7e60d100000000"
195+
"hex": "02000000000101e7cb27eb50241cc94fb806f19fb1bdfbb37343f3c296498a0cfe7275382a9d5e00000000001e0a00000170050300000000001600142816f526d850d21dc5d1f7199c69566f897d1cfc03404b2d91cb8c875001d4d7f55e484152e153e967de5a6c7eed558e694356d6de7a005cfb77e408d6ff97cfb772413c3c62ecef7685976a3005cf263096e1dcdb2b2620ea8c9126df42b88ce115c78597122895227f3d3aeb5319d5578cc7522be347b5ad021e0ab221c01fc559d9c96c5953895d3150e64ebf3dd696a0b08e758650b48ff6251d7e60d100000000"
167196
}
168-
169-
bitcoin-cli sendrawtransaction 0200000000010193b98c8c1c519f4ae5ea2987e65259855fe97b66b183ab24d13e1ffab136324c000000000090000000024054890000000000160014112b73b786d065f39205f1751570930252da459204380f00000000001600144c75c898012fa91fa5fdacc9b20bd166a3334ad70340f9f7397a4cb9705e4da80a2a3715f7dff1da51426a585acecc698f9c524d597e5d37873c63d6fc0800705041bca1df73c25fb2680eb957c65a3f2def3a8cc8d026206d1c01c820e0900edd8e59b4b383e73a7f5850072455804f9cffe99fa4f8541bad029000b221c11fc559d9c96c5953895d3150e64ebf3dd696a0b08e758650b48ff6251d7e60d100000000
170-
09efe025805b2db8ae845a94639e5ad415756fb0d010aad54bf3f74ae71e015d
197+
```
198+
```shell
199+
bitcoin-cli sendrawtransaction 02000000000101e7cb27eb50241cc94fb806f19fb1bdfbb37343f3c296498a0cfe7275382a9d5e00000000001e0a00000170050300000000001600142816f526d850d21dc5d1f7199c69566f897d1cfc03404b2d91cb8c875001d4d7f55e484152e153e967de5a6c7eed558e694356d6de7a005cfb77e408d6ff97cfb772413c3c62ecef7685976a3005cf263096e1dcdb2b2620ea8c9126df42b88ce115c78597122895227f3d3aeb5319d5578cc7522be347b5ad021e0ab221c01fc559d9c96c5953895d3150e64ebf3dd696a0b08e758650b48ff6251d7e60d100000000
200+
16d5a43fe6260b1a5993d97d711cfb4323fb27b44c9d34c547fb1693bf1c8900
171201
```
172202

173203
Wait for that transaction to confirm, and your funds will have been successfully recovered!

src/commonMain/kotlin/fr/acinq/lightning/crypto/KeyManager.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,19 @@ interface KeyManager {
134134
fun localServerPrivateKey(remoteNodeId: PublicKey): PrivateKey = DeterministicWallet.derivePrivateKey(localServerExtendedPrivateKey, perUserPath(remoteNodeId)).privateKey
135135

136136
val swapInProtocol = SwapInProtocol(userPublicKey, remoteServerPublicKey, userRefundPublicKey, refundDelay)
137-
val descriptor = swapInProtocol.descriptor(chain, userRefundExtendedPrivateKey)
137+
138+
// this is a private descriptor that can be used as-is to recover swap-in funds once the refund delay has passed
139+
// it is compatible with address rotation as long as refund keys are derived directly from userRefundExtendedPrivateKey
140+
// README: it includes the user's master refund private key and is not safe to share !!
141+
val privateDescriptor = SwapInProtocol.privateDescriptor(chain, userPublicKey, remoteServerPublicKey, refundDelay, userRefundExtendedPrivateKey)
142+
143+
// this is the public version of the above descriptor. It can be used to monitor a user's swap-in transaction
144+
// README: it cannot be used to derive private keys, but it can be used to derive swap-in addresses
145+
val publicDescriptor = SwapInProtocol.publicDescriptor(chain, userPublicKey, remoteServerPublicKey, refundDelay, DeterministicWallet.publicKey(userRefundExtendedPrivateKey))
138146

139147
// legacy p2wsh-based swap-in protocol, with a fixed on-chain address
140148
val legacySwapInProtocol = SwapInProtocolLegacy(userPublicKey, remoteServerPublicKey, refundDelay)
141-
val legacyDescriptor = legacySwapInProtocol.descriptor(chain, master, userExtendedPrivateKey)
149+
val legacyDescriptor = SwapInProtocolLegacy.descriptor(chain, DeterministicWallet.publicKey(master), DeterministicWallet.publicKey(userExtendedPrivateKey), remoteServerPublicKey, refundDelay)
142150

143151
fun signSwapInputUserLegacy(fundingTx: Transaction, index: Int, parentTxOuts: List<TxOut>): ByteVector64 {
144152
return legacySwapInProtocol.signSwapInputUser(fundingTx, index, parentTxOuts[fundingTx.txIn[index].outPoint.index.toInt()], userPrivateKey)

0 commit comments

Comments
 (0)