SeedSigner / seedsigner

Use an air-gapped Raspberry Pi Zero to sign for Bitcoin transactions! (and do other cool stuff)
MIT License
720 stars 168 forks source link

[New Feature] Support bip45 nonsegwit legacy multisig p2sh #540

Closed kdmukai closed 4 months ago

kdmukai commented 7 months ago

Description

Adds p2sh nonsegwit legacy multisig support.

The intention is to at least support bip45 (m/45') p2sh multisig, which is the format used by Unchained. There may be some assumptions baked in here that might not fully support all arbitrary p2sh scripts.

Additional tests:

Misc:


To aid testing, here is the p2sh multisig descriptor used in the psbt_parser test:

legacy_multisig_p2sh_test_descriptor
sh(sortedmulti(2,[0f889044/45h]tpubD8NkS3Gngj7L4FJRYrwojKhsx2seBhrNrXVdvqaUyvtVe1YDCVcziZVa9g3KouXz7FN5CkGBkoC16nmNu2HcG9ubTdtCbSW8DEXSMHmmu62/<0;1>/*,[03cd0a2b/45h]tpubD8HkLLgkdJkVitn1i9CN4HpFKJdom48iKm9PyiXYz5hivn1cGz6H3VeS6ncmCEgamvzQA2Qofu2YSTwWzvuaYWbJDEnvTUtj5R96vACdV6L/<0;1>/*,[769f695c/45h]tpubD98hRDKvtATTM8hy5Vvt5ZrvDXwJvrUZm1p1mTKDmd7FqUHY9Wj2k4X1CvxjjtTf3JoChWqYbnWjfkRJ65GQnpVJKbbMfjnGzCwoBUXafyM/<0;1>/*))#uardwtq4

The descriptor from the test can also be imported into Sparrow for more interactive testing / sanity checking:


Additional resources:


This pull request is categorized as a:

Checklist

If you modified or added functionality/workflow, did you add new unit tests?

I have tested this PR on the following platforms/os:

newtonick commented 4 months ago

Did some testing on this. One issue I ran into is there does not appear to be a way to export a p2sh multisig xpub. At least I could not get it to work in Sparrow until I added:

            elif origin.components[0].index == 45: # P2SH Multisig
                ur_outputs.append(Output([SCRIPT_EXPRESSION_TAG_MAP[400]],self.ur_hdkey))

to src/seedsigner/models/encode_qr.py on line 514.

newtonick commented 4 months ago

The additions here LGTM. Tested with the only issue being xpub export. This can be added/corrected in a separate PR.