--- /dev/null
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+source setup.sh
+
+mkdir "$TEST_DIR"
+cd "$TEST_DIR"
+
+(echo "YYYYYYYYYYYYYYYYYYYYY" | multisig_create_interactive > result 2>&1)
+cat > expected << EOF
+Creating multi-signature descriptors...
+create output file 'main.descriptors':
+
+ echo -n "wsh(sortedmulti(3," > main.descriptors
+
+
+added descriptors from wallet1 to main.descriptors
+
+ bitcoin-cli -rpcwallet=wallet1 listdescriptors | jq -j '.descriptors | map(select(.desc | startswith("wpkh"))) | map(select(.internal == false)) | map(.desc | ltrimstr("wpkh(")) | .[] | split(")") | .[0]' >> main.descriptors
+
+
+added descriptors from wallet2 to main.descriptors
+
+ bitcoin-cli -rpcwallet=wallet2 listdescriptors | jq -j '.descriptors | map(select(.desc | startswith("wpkh"))) | map(select(.internal == false)) | map(.desc | ltrimstr("wpkh(")) | .[] | split(")") | .[0]' >> main.descriptors
+
+
+added descriptors from wallet3 to main.descriptors
+
+ bitcoin-cli -rpcwallet=wallet3 listdescriptors | jq -j '.descriptors | map(select(.desc | startswith("wpkh"))) | map(select(.internal == false)) | map(.desc | ltrimstr("wpkh(")) | .[] | split(")") | .[0]' >> main.descriptors
+
+
+added descriptors from wallet4 to main.descriptors
+
+ bitcoin-cli -rpcwallet=wallet4 listdescriptors | jq -j '.descriptors | map(select(.desc | startswith("wpkh"))) | map(select(.internal == false)) | map(.desc | ltrimstr("wpkh(")) | .[] | split(")") | .[0]' >> main.descriptors
+
+
+added descriptors from wallet5 to main.descriptors
+
+ bitcoin-cli -rpcwallet=wallet5 listdescriptors | jq -j '.descriptors | map(select(.desc | startswith("wpkh"))) | map(select(.internal == false)) | map(.desc | ltrimstr("wpkh(")) | .[] | split(")") | .[0]' >> main.descriptors
+
+
+added descriptors from wallet6 to main.descriptors
+
+ bitcoin-cli -rpcwallet=wallet6 listdescriptors | jq -j '.descriptors | map(select(.desc | startswith("wpkh"))) | map(select(.internal == false)) | map(.desc | ltrimstr("wpkh(")) | .[] | split(")") | .[0]' >> main.descriptors
+
+
+added descriptors from wallet7 to main.descriptors
+
+ bitcoin-cli -rpcwallet=wallet7 listdescriptors | jq -j '.descriptors | map(select(.desc | startswith("wpkh"))) | map(select(.internal == false)) | map(.desc | ltrimstr("wpkh(")) | .[] | split(")") | .[0]' >> main.descriptors
+
+
+finish formatting for main.descriptors:
+
+ echo "))" >> main.descriptors
+
+
+Use bitcoin core to get information on fully formed descriptors and output result to descriptors.txt:
+
+ cat main.descriptors | bitcoin-cli -stdin getdescriptorinfo | jq -j '.descriptor' >> descriptors.txt
+
+
+create output file 'change.descriptors':
+
+ echo -n "wsh(sortedmulti(3," > change.descriptors
+
+
+added change descriptors from wallet1 to change.descriptors
+
+ bitcoin-cli -rpcwallet=wallet1 listdescriptors | jq -j '.descriptors | map(select(.desc | startswith("wpkh"))) | map(select(.internal == true)) | map(.desc | ltrimstr("wpkh(")) | .[] | split(")") | .[0]' >> change.descriptors
+
+
+added change descriptors from wallet2 to change.descriptors
+
+ bitcoin-cli -rpcwallet=wallet2 listdescriptors | jq -j '.descriptors | map(select(.desc | startswith("wpkh"))) | map(select(.internal == true)) | map(.desc | ltrimstr("wpkh(")) | .[] | split(")") | .[0]' >> change.descriptors
+
+
+added change descriptors from wallet3 to change.descriptors
+
+ bitcoin-cli -rpcwallet=wallet3 listdescriptors | jq -j '.descriptors | map(select(.desc | startswith("wpkh"))) | map(select(.internal == true)) | map(.desc | ltrimstr("wpkh(")) | .[] | split(")") | .[0]' >> change.descriptors
+
+
+added change descriptors from wallet4 to change.descriptors
+
+ bitcoin-cli -rpcwallet=wallet4 listdescriptors | jq -j '.descriptors | map(select(.desc | startswith("wpkh"))) | map(select(.internal == true)) | map(.desc | ltrimstr("wpkh(")) | .[] | split(")") | .[0]' >> change.descriptors
+
+
+added change descriptors from wallet5 to change.descriptors
+
+ bitcoin-cli -rpcwallet=wallet5 listdescriptors | jq -j '.descriptors | map(select(.desc | startswith("wpkh"))) | map(select(.internal == true)) | map(.desc | ltrimstr("wpkh(")) | .[] | split(")") | .[0]' >> change.descriptors
+
+
+added change descriptors from wallet6 to change.descriptors
+
+ bitcoin-cli -rpcwallet=wallet6 listdescriptors | jq -j '.descriptors | map(select(.desc | startswith("wpkh"))) | map(select(.internal == true)) | map(.desc | ltrimstr("wpkh(")) | .[] | split(")") | .[0]' >> change.descriptors
+
+
+added change descriptors from wallet7 to change.descriptors
+
+ bitcoin-cli -rpcwallet=wallet7 listdescriptors | jq -j '.descriptors | map(select(.desc | startswith("wpkh"))) | map(select(.internal == true)) | map(.desc | ltrimstr("wpkh(")) | .[] | split(")") | .[0]' >> change.descriptors
+
+
+finish formatting for change.descriptors:
+
+ echo "))" >> change.descriptors
+
+
+Format descriptors.txt to be ready to append change descriptors:
+
+ echo -n ',{"desc": "' >> descriptors.txt
+
+
+Use bitcoin core to get information on fully formed change descriptors and output result to descriptors.txt:
+
+ cat change.descriptors | bitcoin-cli -stdin getdescriptorinfo | jq -j '.descriptor' >> descriptors.txt
+EOF
+assert "$(<expected)" "$(<result)"
+
+cd ..
+rm -rf "$TEST_DIR"
+
+test_succeeded
--- /dev/null
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+source setup.sh
+
+mkdir "$TEST_DIR"
+cd "$TEST_DIR"
+
+usb_detect() {
+ echo "/dev/sdzzzzz"
+}
+
+(echo "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY" | usbs_interactive > result 2>&1)
+cat > expected << EOF
+make directory to mount usb:
+
+ mkdir -p .data/.usb
+
+
+insert usb drive to use for wallet1...
+usb drive detected at /dev/sdzzzzz
+
+
+wipe filesystem on /dev/sdzzzzz
+
+ wipefs -a /dev/sdzzzzz
+
+
+format usb device for encryption:
+
+ cryptsetup luksFormat --type luks2 /dev/sdzzzzz
+
+
+open encrypted drive:
+
+ cryptsetup luksOpen /dev/sdzzzzz cold-usb
+
+
+fill drive with zeros:
+
+ dd if=/dev/zero of=/dev/mapper/cold-usb
+
+
+make filesystem on usb drive:
+
+ mkfs.ext4 /dev/mapper/cold-usb
+
+
+mount usb drive:
+
+ mount /dev/mapper/cold-usb .data/.usb
+
+
+dump descriptors for wallet1:
+
+ bitcoin-cli -named -rpcwallet=wallet1 listdescriptors private=true > wallet1.descriptors
+
+
+copy descriptors for wallet1 to .data/.usb:
+
+ cp wallet1.descriptors .data/.usb/
+
+
+copy multi-signature descriptors to .data/.usb:
+
+ cp descriptors.txt .data/.usb/
+
+
+verify integrity sum of copied files matches:
+
+ b2sum wallet1.descriptors .data/.usb/wallet1.descriptors descriptors.txt .data/.usb/descriptors.txt
+
+
+shred wallet1.descriptors:
+
+ shred -u wallet1.descriptors
+
+
+unmount usb drive:
+
+ umount .data/.usb
+
+
+eject device:
+
+ eject /dev/mapper/cold-usb
+
+
+insert usb drive to use for wallet2...
+usb drive detected at /dev/sdzzzzz
+
+
+wipe filesystem on /dev/sdzzzzz
+
+ wipefs -a /dev/sdzzzzz
+
+
+format usb device for encryption:
+
+ cryptsetup luksFormat --type luks2 /dev/sdzzzzz
+
+
+open encrypted drive:
+
+ cryptsetup luksOpen /dev/sdzzzzz cold-usb
+
+
+fill drive with zeros:
+
+ dd if=/dev/zero of=/dev/mapper/cold-usb
+
+
+make filesystem on usb drive:
+
+ mkfs.ext4 /dev/mapper/cold-usb
+
+
+mount usb drive:
+
+ mount /dev/mapper/cold-usb .data/.usb
+
+
+dump descriptors for wallet2:
+
+ bitcoin-cli -named -rpcwallet=wallet2 listdescriptors private=true > wallet2.descriptors
+
+
+copy descriptors for wallet2 to .data/.usb:
+
+ cp wallet2.descriptors .data/.usb/
+
+
+copy multi-signature descriptors to .data/.usb:
+
+ cp descriptors.txt .data/.usb/
+
+
+verify integrity sum of copied files matches:
+
+ b2sum wallet2.descriptors .data/.usb/wallet2.descriptors descriptors.txt .data/.usb/descriptors.txt
+
+
+shred wallet2.descriptors:
+
+ shred -u wallet2.descriptors
+
+
+unmount usb drive:
+
+ umount .data/.usb
+
+
+eject device:
+
+ eject /dev/mapper/cold-usb
+
+
+insert usb drive to use for wallet3...
+usb drive detected at /dev/sdzzzzz
+
+
+wipe filesystem on /dev/sdzzzzz
+
+ wipefs -a /dev/sdzzzzz
+
+
+format usb device for encryption:
+
+ cryptsetup luksFormat --type luks2 /dev/sdzzzzz
+
+
+open encrypted drive:
+
+ cryptsetup luksOpen /dev/sdzzzzz cold-usb
+
+
+fill drive with zeros:
+
+ dd if=/dev/zero of=/dev/mapper/cold-usb
+
+
+make filesystem on usb drive:
+
+ mkfs.ext4 /dev/mapper/cold-usb
+
+
+mount usb drive:
+
+ mount /dev/mapper/cold-usb .data/.usb
+
+
+dump descriptors for wallet3:
+
+ bitcoin-cli -named -rpcwallet=wallet3 listdescriptors private=true > wallet3.descriptors
+
+
+copy descriptors for wallet3 to .data/.usb:
+
+ cp wallet3.descriptors .data/.usb/
+
+
+copy multi-signature descriptors to .data/.usb:
+
+ cp descriptors.txt .data/.usb/
+
+
+verify integrity sum of copied files matches:
+
+ b2sum wallet3.descriptors .data/.usb/wallet3.descriptors descriptors.txt .data/.usb/descriptors.txt
+
+
+shred wallet3.descriptors:
+
+ shred -u wallet3.descriptors
+
+
+unmount usb drive:
+
+ umount .data/.usb
+
+
+eject device:
+
+ eject /dev/mapper/cold-usb
+
+
+insert usb drive to use for wallet4...
+usb drive detected at /dev/sdzzzzz
+
+
+wipe filesystem on /dev/sdzzzzz
+
+ wipefs -a /dev/sdzzzzz
+
+
+format usb device for encryption:
+
+ cryptsetup luksFormat --type luks2 /dev/sdzzzzz
+
+
+open encrypted drive:
+
+ cryptsetup luksOpen /dev/sdzzzzz cold-usb
+
+
+fill drive with zeros:
+
+ dd if=/dev/zero of=/dev/mapper/cold-usb
+
+
+make filesystem on usb drive:
+
+ mkfs.ext4 /dev/mapper/cold-usb
+
+
+mount usb drive:
+
+ mount /dev/mapper/cold-usb .data/.usb
+
+
+dump descriptors for wallet4:
+
+ bitcoin-cli -named -rpcwallet=wallet4 listdescriptors private=true > wallet4.descriptors
+
+
+copy descriptors for wallet4 to .data/.usb:
+
+ cp wallet4.descriptors .data/.usb/
+
+
+copy multi-signature descriptors to .data/.usb:
+
+ cp descriptors.txt .data/.usb/
+
+
+verify integrity sum of copied files matches:
+
+ b2sum wallet4.descriptors .data/.usb/wallet4.descriptors descriptors.txt .data/.usb/descriptors.txt
+
+
+shred wallet4.descriptors:
+
+ shred -u wallet4.descriptors
+
+
+unmount usb drive:
+
+ umount .data/.usb
+
+
+eject device:
+
+ eject /dev/mapper/cold-usb
+
+
+insert usb drive to use for wallet5...
+usb drive detected at /dev/sdzzzzz
+
+
+wipe filesystem on /dev/sdzzzzz
+
+ wipefs -a /dev/sdzzzzz
+
+
+format usb device for encryption:
+
+ cryptsetup luksFormat --type luks2 /dev/sdzzzzz
+
+
+open encrypted drive:
+
+ cryptsetup luksOpen /dev/sdzzzzz cold-usb
+
+
+fill drive with zeros:
+
+ dd if=/dev/zero of=/dev/mapper/cold-usb
+
+
+make filesystem on usb drive:
+
+ mkfs.ext4 /dev/mapper/cold-usb
+
+
+mount usb drive:
+
+ mount /dev/mapper/cold-usb .data/.usb
+
+
+dump descriptors for wallet5:
+
+ bitcoin-cli -named -rpcwallet=wallet5 listdescriptors private=true > wallet5.descriptors
+
+
+copy descriptors for wallet5 to .data/.usb:
+
+ cp wallet5.descriptors .data/.usb/
+
+
+copy multi-signature descriptors to .data/.usb:
+
+ cp descriptors.txt .data/.usb/
+
+
+verify integrity sum of copied files matches:
+
+ b2sum wallet5.descriptors .data/.usb/wallet5.descriptors descriptors.txt .data/.usb/descriptors.txt
+
+
+shred wallet5.descriptors:
+
+ shred -u wallet5.descriptors
+
+
+unmount usb drive:
+
+ umount .data/.usb
+
+
+eject device:
+
+ eject /dev/mapper/cold-usb
+
+
+insert usb drive to use for wallet6...
+usb drive detected at /dev/sdzzzzz
+
+
+wipe filesystem on /dev/sdzzzzz
+
+ wipefs -a /dev/sdzzzzz
+
+
+format usb device for encryption:
+
+ cryptsetup luksFormat --type luks2 /dev/sdzzzzz
+
+
+open encrypted drive:
+
+ cryptsetup luksOpen /dev/sdzzzzz cold-usb
+
+
+fill drive with zeros:
+
+ dd if=/dev/zero of=/dev/mapper/cold-usb
+
+
+make filesystem on usb drive:
+
+ mkfs.ext4 /dev/mapper/cold-usb
+
+
+mount usb drive:
+
+ mount /dev/mapper/cold-usb .data/.usb
+
+
+dump descriptors for wallet6:
+
+ bitcoin-cli -named -rpcwallet=wallet6 listdescriptors private=true > wallet6.descriptors
+
+
+copy descriptors for wallet6 to .data/.usb:
+
+ cp wallet6.descriptors .data/.usb/
+
+
+copy multi-signature descriptors to .data/.usb:
+
+ cp descriptors.txt .data/.usb/
+
+
+verify integrity sum of copied files matches:
+
+ b2sum wallet6.descriptors .data/.usb/wallet6.descriptors descriptors.txt .data/.usb/descriptors.txt
+
+
+shred wallet6.descriptors:
+
+ shred -u wallet6.descriptors
+
+
+unmount usb drive:
+
+ umount .data/.usb
+
+
+eject device:
+
+ eject /dev/mapper/cold-usb
+
+
+insert usb drive to use for wallet7...
+usb drive detected at /dev/sdzzzzz
+
+
+wipe filesystem on /dev/sdzzzzz
+
+ wipefs -a /dev/sdzzzzz
+
+
+format usb device for encryption:
+
+ cryptsetup luksFormat --type luks2 /dev/sdzzzzz
+
+
+open encrypted drive:
+
+ cryptsetup luksOpen /dev/sdzzzzz cold-usb
+
+
+fill drive with zeros:
+
+ dd if=/dev/zero of=/dev/mapper/cold-usb
+
+
+make filesystem on usb drive:
+
+ mkfs.ext4 /dev/mapper/cold-usb
+
+
+mount usb drive:
+
+ mount /dev/mapper/cold-usb .data/.usb
+
+
+dump descriptors for wallet7:
+
+ bitcoin-cli -named -rpcwallet=wallet7 listdescriptors private=true > wallet7.descriptors
+
+
+copy descriptors for wallet7 to .data/.usb:
+
+ cp wallet7.descriptors .data/.usb/
+
+
+copy multi-signature descriptors to .data/.usb:
+
+ cp descriptors.txt .data/.usb/
+
+
+verify integrity sum of copied files matches:
+
+ b2sum wallet7.descriptors .data/.usb/wallet7.descriptors descriptors.txt .data/.usb/descriptors.txt
+
+
+shred wallet7.descriptors:
+
+ shred -u wallet7.descriptors
+
+
+unmount usb drive:
+
+ umount .data/.usb
+
+
+eject device:
+
+ eject /dev/mapper/cold-usb
+EOF
+assert "$(<expected)" "$(<result)"
+
+cd ..
+rm -rf "$TEST_DIR"
+
+test_succeeded