Skip to content

Conversation

@kallewoof
Copy link
Contributor

@kallewoof kallewoof commented Mar 16, 2018

Partially addresses #12703.
Fully addresses #9694.

This implementation simply uses the existing importprivkey code (moved into a separate ImportPrivateKey method), and does not support redeem scripts, internal, pubkeys, or keys options.

One question is if this should be simplified to where a user can put private keys in keys and leave scriptPubKey empty, or if it makes more sense to add a new field as I do here.

Another question is whether this should be incorporated more into how importmulti works, rather than basing it off of importprivkey (although with the timestamp argument, it seems like it does all we want it to).

(I was initially planning on deriving the arguments for ProcessImport and letting it do its thing, but realized there can be multiple scriptPubKeys for one private key, so I'd have to call ProcessImport multiple times, with the same private key.. which will trigger an error.)

@kallewoof kallewoof force-pushed the importmulti-wif-support branch 2 times, most recently from 6c839f8 to 32e70ab Compare March 16, 2018 07:52
Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK. Light review.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "Importmulti private key support",

Also fix default=true to be consistent with most of the code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "[wallet] [rpc] Move private key import functionality out of importprivkey",

Remove this scope?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "[wallet] [rpc] Move private key import functionality out of importprivkey",

Nit, move throw to new line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, because of the other one below. Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "[wallet] [rpc] Move private key import functionality out of importprivkey",

static bool ...?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "[wallet] [rpc] Add privkey support to importmulti",

Nit, UniValue result(UniValue::VOBJ);

@meshcollider
Copy link
Contributor

Concept ACK

1 similar comment
@jonasschnelli
Copy link
Contributor

Concept ACK

@sipa
Copy link
Member

sipa commented Mar 18, 2018

Thank you for working on this!

I think we should be careful here though. importprivkey has a number a quirks that are for historical or compatibility reasons, that we shouldn't maintain:

  • importprivkey does not know what the corresponding address is, and thus can't know what type to use (p2pkh, p2sh-p2wpkh, p2wpkh), and thus has to assume all are possible (which results in at least labelling all 3). For importmulti we generally do have the address available. The goal here could be to provide a default address type (or explicitly name the type); not keep assuming it can be any.
  • Relatedly, we don't have an encoding for "private key whose address is supposed to be P2SH-P2WPKH". My suggestion would be to add one (I believe Electrum has some sort of standard for this). importprivkey can't really use these, because it already has to assume it can be any type, but importmulti does not need to repeat this. It could assume just P2PKH for a legacy WIP encoding, and P2SH/P2WPKH when one of those novel encodings is used.
  • importprivkey doesn't support key birth times; but this is not inherent, keys can have birth times.

@sipa
Copy link
Member

sipa commented Mar 18, 2018

One question is if this should be simplified to where a user can put private keys in keys and leave scriptPubKey empty, or if it makes more sense to add a new field as I do here.

I think it should absolutely use keys - there is no need to add new fields to just provide the same functionality in a different way.

The way it should work IMO is that it integrates into all the functionality that exists (including labels, birth times), but simply permit the scriptpubkey/address (and for p2sh-p2wpkh, also the redeemscript) to be omitted and computed by default from the private key - provided we have figured out how to deal with the encoding of different types of address derivation.

@kallewoof
Copy link
Contributor Author

kallewoof commented Mar 19, 2018

@sipa It seems Electrum 3.0 included an extension to WIF for segwit stuff:

https://github.com/spesmilo/electrum/blob/5fef1e7980e6c9811448ad7d9fb6afa4460ac7fc/RELEASE-NOTES#L181-L194

A good starting point might be to rework this PR to adopt that and see what people think?

@kallewoof
Copy link
Contributor Author

@promag Thanks for the feedback, see e896ba0, 6408244.

@kallewoof
Copy link
Contributor Author

@sipa Small note:

importprivkey doesn't support key birth times; but this is not inherent, keys can have birth times.

The method implementation does support birth times, in the timestamp argument which is always 1 for importprivkey, but uses the provided timestamp for importmulti.

@kallewoof kallewoof changed the title Importmulti private key support [WIP] Importmulti private key support Mar 19, 2018
@cdecker
Copy link
Contributor

cdecker commented Mar 26, 2018

Concept ACK

Other than the quirks that importprivkey has to support mentioned by @sipa, which would be nice to avoid for a new call.

@kallewoof kallewoof force-pushed the importmulti-wif-support branch from da1e008 to 1582698 Compare June 15, 2018 04:39
@DrahtBot
Copy link
Contributor

Needs rebase

@kallewoof
Copy link
Contributor Author

Closing as too many aspects of this are up in the air.

@kallewoof kallewoof closed this Aug 10, 2018
@kallewoof kallewoof deleted the importmulti-wif-support branch October 17, 2019 08:55
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants