Feature request: p2sh (multisig) create and watch
Currently electrum supports setting up entire multisig wallets (with multiple master keys (xpub)). This is nice and useful for cases where the user and all the cosigners use electrum wallet, but very ugly when an electrum user tries to use a third party escrow service or something which doesn't use electrum.
It would be nice to have something like Armory provides (lockboxes). Simple implementation:
Add a link to "Tools" tab labeled "Create P2SH (Multisig)". When clicked, a pop-up will appear where the user can select:
- m of n signatures required (e.g. 2/3, 3/4, 3/5, etc)
- depending on n value selected, have fields to enter the pubkeys:
- signer[n-(n-1)]
with options: import from own wallet (where the user can select the pubkey of a certain address at user's choice and use it); import from file; paste from clipboard or have electrum generate a deterministic new pubkey (like newaddress) for this p2sh address for users who want to avoid using a non-fresh pubkey. When a pubkey is used in a p2sh address, mark that pubkey and move its normal address (ripemd160 p2pkh) to 'Used'. The participants in a P2SH address (not the creator) can simply right click on an address and click "Public Key" to get a pubkey that can be used with a third party, or we can add another link under the "Tools" tab labeled "Generate new P2SH pubkey". 3) export the p2sh entire address to a file or copy to clipboard and have a clear warning that in case wallet will be restored from seed, p2sh cannot be generated deterministic so separate backup is needed. 4) add option in electrum to export (save to file, copy to clipboard, etc.) the p2sh addresses (pubkeys in their order) only. These need to be backed up separately and who wants to use this feature will understand. The privkeys required for partially unlocking these p2sh addresses will be restored from the main seed along with the wallet, since they will be privkeys of electrum's deterministic addresses.
The P2Sh addresses will appear under a separate group in Addresses tab named "P2SH" with additional info which states the number of signatures required to spend from that address (m) and how many privkeys available for signing the wallet holds (most probably 1). They will be seen by the wallet as partially watch only and also be included in the history tab.
When an user wants to spend from a p2sh address, electrum will just allow to partially sign and copy to clipboard or save to file that tx so it can be sent to the cosigner(s). Electrum will read the number of signatures required and when last one required is there, it shows the option to broadcast tx.
Something which can achieve similar goals like this: https://youtu.be/B5E3WQjSB6w
There is already a createmultisig command.
I am not a big fan of having it in the GUI, because it's a recipe for disaster; it is really difficult not to screw up.
Right, but GUI is very important for the average user type. Multisig is almost unknown to some users, they just don't have a gui infrastructure available to generate addresses and mange them. I understand it can cause some confusions for those who don't use it right, but maybe we can add it only in a special mode (advanced mode) so that it won't be available by default for all the users. Only the users who explicitly enable it will see it, and those we can assume they know what they are doing.
well, it should not in the same wallet file as a seeded wallet, but a separate wallet type (eg ImportedWallet)
Note: with the current electrum, you can already:
- create a multisig address:
electrum createmultisig - create a watching-only wallet for that address:
electrum restore <address> - sign multisig transactions with the corresponding private key:
electrum signtransaction tx --privkey <privkey>
so, to sign transactions with the gui, we only need to extend ImportedWallet a little bit
I am fine with implementing this in a separate imported wallet. This way, an user can restore his standard wallet from seed, import it in a different wallet to use for p2sh.
electrum signtransaction tx --privkey
At least we should make all these features available via the python console included in the gui, until we extend the ImportedWallet gui a little bit. Does this sound like a good idea? restore() doesn't work in the python console currently.
- Create multisig addresses and defining the n-of-m signatures required to spend.
- Add a p2sh address as watch only.
- Sign partially signed or unsigned txes in p2sh, being able to track how many signers have signed, how many / which are left, etc.
yes, signtransaction --privkey needs the privkey to be passed as parameter. that's why a new type of wallet would be useful for that
Can we make all these available in the python console until we figure out what the best way to do it will be? I agree that having a separate imported wallet will be better, but how can we tie it with the standard wallet so that at lest users will have to remember a single seed to get their privkeys back, regardless the p2sh addresses can't be reproduced from that seed. If it's p2sh most probably it's an escrow or contract, so the user has the relevant info (p2sh address and script) from other sources and just needs the privkeys to unlock his part.
@ecdsa
Note: with the current electrum, you can already: create a multisig address:
electrum createmultisigcreate a watching-only wallet for that address:electrum restore <address>sign multisig transactions with the corresponding private key:electrum signtransaction tx --privkey <privkey>
Using electrum -w wallet.dat restore <address> throw errors:
e.g:
electrum -w wallet.dat restore '["2MugYq3NAxxE2MK7NxC2S9Bq7RTbd4WKDV6"]' --testnet
If wallet already exist:
Error: Seed or key not recognized
If wallet doesn't exist:
Error: Remove the existing wallet first!
electrum -w wallet.dat --testnet restore 2MugYq3NAxxE2MK7NxC2S9Bq7RTbd4WKDV6
@jmliz don't put all that junk around it
@dabura667 still the same errors came out.
@ecdsa https://github.com/spesmilo/electrum/blob/d99855f06072c33cef144edce68acded561e339a/electrum#L139
keystore.is_any_key() doesn't check if the text is an address or list of addresses.
Currently the only way to create a watch-only wallet from a list of addresses is through the GUI wizard.
@jmliz a workaround would be to create the wallet with all the addresses you need via the GUI and just load that wallet file.
@dabura667 @ecdsa thanks, but I need command line for backend dynamic stuff. It would be great to add that functionality. I created an issue btw. https://github.com/spesmilo/electrum/issues/2173
You can't restore a wallet with a list of private keys either. You get that same error "Seed or key not recognized".
Example:
$> electrum -w oldwallet listaddresses |electrum -w oldwallet getprivatekeys -| jq 'map(.[0])'| electrum -w privkey4 restore -
WARNING: ALL your private keys are secret.
Exposing a single private key can compromise your entire wallet!
In particular, DO NOT use 'redeem private key' services proposed by third parties.
Error: Seed or key not recognized
If i understand correctly we cannot restore multisig wallet from command line in watch only , beacause of this issue ?