-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Address: consistent namespacing and decode/encode functionality #306
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
Conversation
|
+1 for If all you wanted is to check the address' version, why not provide |
function validateAddress(address, network) {
var decode
try {
decode = bitcoin.address.decode(address)
} catch (e) {
return false
}
return decode.network === network
}If you just have a version, the user then needs to search over the network space themselves to see if it is a version they accept, in a network they know. |
|
Indeed, it does force one to explicitly whitelist the versions they'd like to accept which isn't necessarily a bad thing. They can implement their own network validation function easily with function validateAddress(addr, network) {
var version = address.getVersion(addr)
return [network.pubKeyHash, network.scriptHash].indexOf(version) >= 0
} |
|
Is that ideal though? It does mean they suddenly have to be more aware than before of address versions. I agree a |
|
The main reason I don't quite like |
|
The fact is though, that its a parsing operation, it will have arbitrary On Mon, Oct 27, 2014 at 1:11 PM, Wei Lu notifications@github.com wrote:
|
|
@weilu further thoughts on this? |
|
I still think |
|
I think that's a good solution. I'll iterate on this a bit more today see
|
This is a
3.0.0PR.Mostly looking for feedback on the naming and structure behind the
bitcoin.address.[decode/encode]use cases.I included the network search inside
decoderather than intoOutputScriptbecause it is very useful to be able to check whether a particular address is on the same network as yourself when verifying it.