Bitcoin-Core

將多重簽名錢包導入比特幣核心,Vpub 密鑰無效。如何?

  • March 12, 2021

我正在嘗試將使用 Electrum 創建的 HD 多重簽名錢包導入比特幣核心 v0.21.0.0。

我設法通過出色的cryptoadvance.specter伺服器做到了這一點,但我也想使用標準的 bitcoin-cli 命令導入它。

到目前為止,這是我設法做到的,只有當我pub 鍵 Vpub轉換Multi-signature P2WSH為 tpub 時它才有效P2PKH,例如:

Vpub5fRxfoprsHS9Vnhq1grZcJrWSRmSeBZbLCbnTJcvSDXr3xoBurx8MUt8UmHCsTVPXqk1rNpgt3X3KAvcJzCZvwn9yQymrWhwMJpEYysLqQV

變成

tpubD8a2g9FwJxvC3c7YBvwvQL35Ph7jJTN4PnarTPCJAND6HGXSizk4ew1JxWKgqLXZuZSZ6KXZTFfgem2ar1itGNUywE1XJTY9azG4WBr25hn

然後我可以執行這個程序,它似乎工作正常,除非不是因為結果地址非常不同。(使用 Spectre 創建的錢包與 Electrum 中的錢包完美匹配,它也能找到正確的交易)

#!/bin/sh

wallet=$1
pub1=$2
pub2=$3

echo "Making wallet '${wallet}' from ${pub1} ${pub2}"

rawdescriptor="wsh(sortedmulti(2,${pub1}/*,${pub2}/*))"
descriptor=$(bitcoin-cli getdescriptorinfo $rawdescriptor | jq -r '.descriptor')
bitcoin-cli deriveaddresses  ${descriptor} "[0,0]"

bitcoin-cli createwallet $wallet true
bitcoin-cli -rpcwallet=$1  importmulti '[{"desc": "'$descriptor'", "internal": false, "range": [0, 1000], "timestamp": 1609459200, "keypool": true, "watchonly": true, "label": "lol"}]' '{ "rescan": true}'
# bitcoin-cli -rpcwallet=$1 rescanblockchain

我不能使用 Vpub 密鑰,因為 bitcoin-cli (v0.21.0.0) 會拋出此消息:

key 'vpub5UXsYa6RJKsn5DYT52PanEWhidjBRpt11vx7Y3MP4ShSRnEH9TZrGN2Cg4KjK2GVJNg2ynpZzq8YC1Jr1m3cnTfV8wsNT7EwTaYMy4PCDAg' is not valid.

在這個階段我只對手錶錢包感興趣,所以我不需要使用私鑰。

另外,我在測試網中,並且testnet=1在我的 bitcoin.conf 上

我已經盡可能多地閱讀,但我想我現在碰壁了,我不知道如何繼續。任何幫助將不勝感激

這是一個適合我的腳本,它導入了一個 2of3 HD 多重簽名錢包。

我對 bash 有非常基本的了解,因此您可能需要在執行它之前仔細檢查它,無論如何,最終對我有用的是了解我必須wsh(sortedmulti(2,${pub1}/0/*,${pub2}/0/*,${pub3}/0/*))導出接收描述符和wsh(sortedmulti(2,${pub1}/1/*,${pub2}/0/*,${pub3}/0/*))接收器。

我還在這裡找到了這個不錯的轉換器: https ://jlopp.github.io/xpub-converter/

#!/bin/sh

wallet=$1
pub1=$2
pub2=$3
pub3=$4
startfrom=$5
range=$6

wallet="${wallet:=test}"
pub1="${pub1:=Vpub1...}"
pub2="${pub2:=Vpub2...}"
pub3="${pub3:=Vpub3...}"
rescanblockchain="${startfrom:=1934907}"
range="${range:=[0,100]}"

p1=$(echo $pub1 | cut -c1-10)
p2=$(echo $pub2 | cut -c1-10)
p3=$(echo $pub3 | cut -c1-10)

printf "\n\nWorking on '${wallet}' from ${p1}... ${p2}... ${p3} starting from ${rescanblockchain}\n\n"

# create wallet if needed
if [[ $(bitcoin-cli listwallets | jq '. | index("'$wallet'")' ) == "null" ]]; then
   echo "Making wallet '${wallet}' from ${pub1} ${pub2} ${pub3}"
   bitcoin-cli createwallet $wallet  true
fi

# convert keys format from vpub to tpub https://jlopp.github.io/xpub-converter/
pub1=$(node converter.js ${pub1})
pub2=$(node converter.js ${pub2})
pub3=$(node converter.js ${pub3})

# get descriptor for receive addresses
raw_receive_descriptor="wsh(sortedmulti(2,${pub1}/0/*,${pub2}/0/*,${pub3}/0/*))"
receive_descriptor=$(bitcoin-cli getdescriptorinfo $raw_receive_descriptor | jq -r '.descriptor')

# get descriptor for change addresses
raw_change_descriptor="wsh(sortedmulti(2,${pub1}/1/*,${pub2}/0/*,${pub3}/0/*))"
change_descriptor=$(bitcoin-cli getdescriptorinfo $raw_change_descriptor | jq -r '.descriptor')

# import receive addresses
bitcoin-cli -rpcwallet=$wallet importmulti  '[{"desc": "'$receive_descriptor'", "internal": false, "range": '${range}', "timestamp": "now", "keypool": true, "watchonly": true}]'  '{"rescan": false}' | jq .

# import change addresses
bitcoin-cli -rpcwallet=$wallet importmulti  '[{"desc": "'$change_descriptor'", "internal": true, "range": '${range}', "timestamp": "now", "keypool": true, "watchonly": true}]'  '{"rescan": false}' | jq .

# rescan blockchain
bitcoin-cli -rpcwallet=$wallet rescanblockchain "${rescanblockchain}" | jq .

# just print out few receive addresses
bitcoin-cli deriveaddresses  ${receive_descriptor} "${range}" | jq .

# print out balance
bitcoin-cli -rpcwallet=$wallet getbalance

引用自:https://bitcoin.stackexchange.com/questions/102502