Author

Topic: determine valid bitcoin address (Read 5519 times)

newbie
Activity: 47
Merit: 0
December 19, 2010, 03:30:54 AM
#15
Here's my PHP version:
http://pastebin.com/vmRQC7ha

I have a web interface to that:
http://theymos.ath.cx:64150/q/checkaddress

Thanks for this, I'm working on a Drupal module to accept Bitcoin addresses as a CCK field type and validate them with this. 

--Darrell
sr. member
Activity: 360
Merit: 250
November 23, 2010, 02:29:34 AM
#14
This topic contains an explanation of why is undesirable to use such functions:
https://www.bitcoin.org/smf/index.php?topic=1267.msg13897

As theymos writes, versioning can be taken care of with a check.

Additionally, I want verification of an address's validity external to the bitcoind I'm talking to because I do not want to hand bogus addresses generated by a malfunctioning or impostor bitcoind over to customers as payment addresses. And, since I'm not talking to it with a regular bitcoin client, I can't use those functions.
administrator
Activity: 5166
Merit: 12850
November 22, 2010, 10:39:24 PM
#13
This topic contains an explanation of why is undesirable to use such functions:
https://www.bitcoin.org/smf/index.php?topic=1267.msg13897

If something changes in Bitcoin, then all old Bitcoin clients will also screw up. My PHP code checks the address version number in the same way as Bitcoin, so it should be future-proof.
sr. member
Activity: 350
Merit: 252
probiwon.com
November 22, 2010, 10:11:52 PM
#12
Thanks for this, but checkAddress() appears to be broken for some addresses:

Those are all correct.

Quote
1MU97wyf7msCVdaapneW2dW1uXP7oEQsFA  bool(false) ** Actually valid **

I just tested this and checkAddress() returned true. Maybe you had some spaces or something: it does no "cleanup" at all.

Okay, now I feel like a jackass. Somehow a space snuck itself in to the end of that string.

Sorry. Thanks for the function! I'm going to incorporate it into what I'm doing.

Peace,
Mike

This topic contains an explanation of why is undesirable to use such functions:
https://www.bitcoin.org/smf/index.php?topic=1267.msg13897
sr. member
Activity: 360
Merit: 250
November 21, 2010, 10:35:49 PM
#11
Thanks for this, but checkAddress() appears to be broken for some addresses:

Those are all correct.

Quote
1MU97wyf7msCVdaapneW2dW1uXP7oEQsFA  bool(false) ** Actually valid **

I just tested this and checkAddress() returned true. Maybe you had some spaces or something: it does no "cleanup" at all.

Okay, now I feel like a jackass. Somehow a space snuck itself in to the end of that string.

Sorry. Thanks for the function! I'm going to incorporate it into what I'm doing.

Peace,
Mike
lfm
full member
Activity: 196
Merit: 104
November 21, 2010, 07:06:23 PM
#10
You should probably have some test cases both good and bad with multiple leading "1"s. They are valid and part of the error checking in some cases.

for instance :

11111111111111111111114oLvT2 bad
1111111111111111111114oLvT2 good
111111111111111111114oLvT2 bad

administrator
Activity: 5166
Merit: 12850
November 21, 2010, 02:09:43 PM
#9
Thanks for this, but checkAddress() appears to be broken for some addresses:

Those are all correct. Nothing can tell you whether someone actually owns an address. It simply checks that the address is in the correct form and contains a valid checksum.

Try to send bitcoins to any of the addresses you listed. Bitcoin will either prevent you from doing so if checkAddress() is false, or it will show a green checkmark if checkAddress() is true.

Quote
1MU97wyf7msCVdaapneW2dW1uXP7oEQsFA  bool(false) ** Actually valid **

I just tested this and checkAddress() returned true. Maybe you had some spaces or something: it does no "cleanup" at all.
sr. member
Activity: 360
Merit: 250
November 21, 2010, 01:19:18 PM
#8
Here's my PHP version:
http://pastebin.com/vmRQC7ha

Thanks for this, but checkAddress() appears to be broken for some addresses:

1F417eczAAbh41V4oLGNf3DqXLY72hsM73 bool(true)
12uJ8qf82vbD76JYxSC38wqXo6QpPdRWbh bool(true)
1F417eczAAbh41V4oLGNf3DqXLY72hsM7 bool(false)
1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD bool(true)
17NdbrSGoUotzeGCcMMCqnFkEvLymoou9j bool(true)
1MU97wyf7msCVdaapneW2dW1uXP7oEQsFA  bool(false) ** Actually valid ** Edit: I'm a dumbass, nevermind.
1N3QX79szMKAJm35NLRSfSpD9DmpQTbNLR bool(true)
1Jcbeg2VjLLJrVztBrsk2UgyEDeLPfk5Q bool(true)
1F417eczAAbh41V4oLGNf3DqXLY72hsM73 bool(true)
F417eczAAbh41V4oLGNf3DqXLY72hsM73 bool(false)
1417eczAAbh41V4oLGNf3DqXLY72hsM73 bool(false)
1F17eczAAbh41V4oLGNf3DqXLY72hsM73 bool(false)
1F4AAbh41V4oLGNf3DqXLY72hsM73 bool(false)
1F417eczAAbDqXLY72hsM73 bool(false)
1F417eczAAbh0000 bool(false)
1F417eczAAbhNf3DqXL72hsM73 bool(false)

[Edit:] This refers to the PHP version
administrator
Activity: 5166
Merit: 12850
November 19, 2010, 12:10:23 PM
#7
Here's my PHP version:
http://pastebin.com/vmRQC7ha

I have a web interface to that:
http://theymos.ath.cx:64150/q/checkaddress
legendary
Activity: 1372
Merit: 1007
1davout
November 19, 2010, 12:04:56 PM
#6
daveout's code isn't quite right (because he based it on an earlier version of my python code).

Corrected version of the python code is in this thread.

Thank you for pointing it out!
I'll drop this piece of code anyway, I'd much rather rely on the bitcoin client implementation of the check.

Was fun to learn some Python while porting it to Ruby =)
legendary
Activity: 1652
Merit: 2216
Chief Scientist
November 19, 2010, 11:55:34 AM
#5
daveout's code isn't quite right (because he based it on an earlier version of my python code).

Corrected version of the python code is in this thread.
legendary
Activity: 1372
Merit: 1007
1davout
November 19, 2010, 09:52:16 AM
#4
Yeah I wanted to do it in javascript. But I can just port this. Thanks.
You'll probably end up writing way less code and get upgrade/bugfixes for free with an Ajax call.
full member
Activity: 185
Merit: 102
November 19, 2010, 09:06:09 AM
#3
Yeah I wanted to do it in javascript. But I can just port this. Thanks.
legendary
Activity: 1372
Merit: 1007
1davout
November 19, 2010, 08:56:18 AM
#2
You get it for free as JSON-RPC call in new versions of the client.
Otherwise see https://github.com/davout/bitcoin-bank/blob/master/lib/bitcoin/util.rb which is a shameless port of some python bit of code I found lying around in the forums, if you find that thread i'll add some comment giving credit.

I would, however, rely on the JSON-RPC call now that it is implementes, gonna drop this snippet in favor of this simple call.
full member
Activity: 185
Merit: 102
November 19, 2010, 08:47:02 AM
#1
Can someone point me to code somewhere that determines if a string is a valid bitcoin address?
Jump to: