New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support ypub/zprv, plus custom addresses #1014
Conversation
var bcrypto = require('./crypto') | ||
var btemplates = require('./templates') | ||
|
||
function checkAllowedP2sh (keyFactory) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these two functions suck, doesn't really allow people to bring their own functions.. but wanted run-time prevention against nesting script hash types incorrectly.
} | ||
} | ||
|
||
function checkAllowedP2wsh (keyFactory) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above
// .once().withArgs().returns('foobar') | ||
// | ||
// assert.strictEqual(hd.getAddress(), 'foobar') | ||
// })) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should discuss whether keys have an associated address type. Maybe following keytoscript, we should just assume some function is responsible for converting keys to their scripts, and then addresses, rather than having getAddress and trying to manage defaults.
…get hdnode.getAddress
haven't tested all of the the key-to-script functions, will leave that after I get feedback on the approach being taken. the prefixes/script functions used in tests obviously work :) |
Did you look to https://github.com/bitcoinjs/bitcoinjs-playground which should land in |
Is it this PR needs refactoring first, or we need to wait until that gets merged? Been looking that as well alright after your note on the other PR. Maybe the closures can just pass it to something like
It confused me a little though as it has a lot of emphasis on inputs, but yea, all I need is address/scriptPubKey/rs/ws! |
Can you elaborate on what you mean by this?
I think it is this one, otherwise we'll end up with more cross-dependence that could make the merge of that PR difficult (or require swathing changes that might have been released here). |
Yea - with the emphasis on inputs, witnesses, and decoding all the information from the object, it looks less like it's meant to make the data I need. Signature parsing normally happens in a separate step to making the output script you'd request payment on.. Though, it means something like this might work: hdnode.getScriptData -> (p2wsh(p2wpkh()) -> { output scripts } |
That aside, I really don't think tagging |
Yea I don't like it on key-pairs much either. Electrum also proposes we start doing script-types with WIF's, which I think is awful, but at least they're the only ones doing it for now :P The hate for getAddress was because we had no control over the script type, and couldn't change it without consumers being affected. This PR would actually fix that problem for a hdnode, surely? If still desired we can remove it from ECPair once we have a method for getting a script from a key. I've had requests for this feature elsewhere as well, since two wallets (electrum & trezor) have implemented it, so I don't see it going away.. So instead of scrapping it, we can try carve a useful feature out of it? As it stands, users generally have to plug primitives together (scripts/templates/crypto,etc) to get an address, so I think exposing redeem/witness/spk script generation, and thereby addresses, is a really rapid way to get people generating addresses and signing without worrying about a tonne of internals (like script types, whether it's p2sh, p2wsh, and the address type!) |
Isn't that exactly what the
Agreed! But what feature is that to be? :) |
In this case, I see the useful feature just being being able to produce scriptPubKeys/redeemScripts/witnessScripts/addresses for the HD key. Instead of shooting straight for pubkey -> address, we can go pubkey -> scripts -> address, and also make it a useful way to get the scripts for signing. And, I realize before that |
See BIP178, this is probably what we will do. |
@afk11 maybe we should hit the discussion up with how this will be handled with extended keys? |
@afk11 what are you're thoughts on this now with the |
This PR adds a new parameter to the hdnode constructor. The parameter describes a bip32 prefix, and has the public & private prefix values, plus a scriptFactory field. This exposes a function,
convert(ECPair key)
and produces:.bip32
, we assume the network is an object (or take bitcoin as the default), and in this case will check the prefix from the key against the.private
and.public
members of the list of prefixes.Not sure what direction this are going with the new templates/script stuff, so all ears for feedback on the stuff in keytoscript!