Bitcoin Forum
April 19, 2024, 12:48:20 PM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Completed: [Bounty] PHP function to generate bitcoin addr from Electrum mpk  (Read 5831 times)
Tungsten (OP)
Member
**
Offline Offline

Activity: 73
Merit: 10



View Profile WWW
April 01, 2013, 02:16:43 PM
Last edit: April 05, 2013, 01:53:58 PM by Tungsten
 #1

-= Project completed =-

Current bounty: 1 BTC.

I need one standalone PHP function created that takes as a parameter Electrum wallet's Master Public Key to generate Bitcoin addresses:

$new_bitcoin_address = generate_bitcoin_address ($master_public_key);

There is an open source project - acceptbit.com (sources are here) that already utilizes this functionality, but it is written on Python, just like all other Electrum software.
Here are sources for Electrum client

I neither good at math nor at Python and need this function written in PHP to utilize it within Wordpress plugin.

So someone who knows both Python and PHP would likely be able to do that.

Here's more description of the project I working on.

• 188888888qZ5Mv4u5C2Bve6eyVJBFR5EEj • Get personalized bitcoin address like that at http://vanitycoin.com/
1713530900
Hero Member
*
Offline Offline

Posts: 1713530900

View Profile Personal Message (Offline)

Ignore
1713530900
Reply with quote  #2

1713530900
Report to moderator
1713530900
Hero Member
*
Offline Offline

Posts: 1713530900

View Profile Personal Message (Offline)

Ignore
1713530900
Reply with quote  #2

1713530900
Report to moderator
1713530900
Hero Member
*
Offline Offline

Posts: 1713530900

View Profile Personal Message (Offline)

Ignore
1713530900
Reply with quote  #2

1713530900
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713530900
Hero Member
*
Offline Offline

Posts: 1713530900

View Profile Personal Message (Offline)

Ignore
1713530900
Reply with quote  #2

1713530900
Report to moderator
Ditto
Sr. Member
****
Offline Offline

Activity: 330
Merit: 250


View Profile
April 02, 2013, 03:01:03 AM
 #2

An easier way would be to run an electrum client on the server and use the command line interface to get addresses.

Or just use this - http://bitfreak.info/?page=tools&t=bitsci
Tungsten (OP)
Member
**
Offline Offline

Activity: 73
Merit: 10



View Profile WWW
April 02, 2013, 02:09:17 PM
 #3

An easier way would be to run an electrum client on the server and use the command line interface to get addresses.

Or just use this - http://bitfreak.info/?page=tools&t=bitsci

Thanks, bitfreak.info link sounds interesting. I contacted their people for possible help.

• 188888888qZ5Mv4u5C2Bve6eyVJBFR5EEj • Get personalized bitcoin address like that at http://vanitycoin.com/
bitfreak!
Legendary
*
Offline Offline

Activity: 1536
Merit: 1000


electronic [r]evolution


View Profile WWW
April 02, 2013, 02:44:34 PM
 #4

Got your message. I can't imagine it would be too hard to do what you require, but I don't really have a clue how Electrum generates the addresses from the "master public key". I assume the master pub key is basically created from the secret seed phrase is it? I don't really know Python at all but if there's some Python code I could refer to I could probably get the general idea of what needs to be done.

XCN: CYsvPpb2YuyAib5ay9GJXU8j3nwohbttTz | BTC: 18MWPVJA9mFLPFT3zht5twuNQmZBDzHoWF
Cryptonite - 1st mini-blockchain altcoin | BitShop - digital shop script
Web Developer - PHP, SQL, JS, AJAX, JSON, XML, RSS, HTML, CSS
BkkCoins
Hero Member
*****
Offline Offline

Activity: 784
Merit: 1009


firstbits:1MinerQ


View Profile WWW
April 04, 2013, 06:04:54 AM
 #5

I can do this for you. I'm familiar with both languages.

I have the code already in Python distilled and simplified from the Electrum code (as a cmd line utility that gens address from mpk) and just need an ECDSA and Hash PHP lib to convert it for you. I can research and do this but don't want to bother if it's in vain because you already paid someone else.

BTW your function will need an increasing index value as well as MPK. The address cannot be gen'd from an MPK alone. A sequence value N is needed. But you just supply a static increasing counter value.

Also, note that using a wallet with these addresses you will need a high gap value to ensure that any addresses generated but never used do not stop the wallet from "seeing" past the empty addresses.

Also, if you're ok with running a shell command from php then an easy way would be to call my python cmd util to provide the address. Slower no doubt, but easy.

Tungsten (OP)
Member
**
Offline Offline

Activity: 73
Merit: 10



View Profile WWW
April 04, 2013, 01:50:51 PM
 #6

I can do this for you. I'm familiar with both languages.

I have the code already in Python distilled and simplified from the Electrum code (as a cmd line utility that gens address from mpk) and just need an ECDSA and Hash PHP lib to convert it for you. I can research and do this but don't want to bother if it's in vain because you already paid someone else.

No, i haven't paid anyone else yet - so if you want to go ahead - I reserve the bounty for you.
If you'd give me time estimate - that would be great.

BTW your function will need an increasing index value as well as MPK. The address cannot be gen'd from an MPK alone. A sequence value N is needed. But you just supply a static increasing counter value.

Also, note that using a wallet with these addresses you will need a high gap value to ensure that any addresses generated but never used do not stop the wallet from "seeing" past the empty addresses.

Sure - let just add an extra param - "$index" to it. Let assume calling code will take care of index tracking.
And no problem with high gap value at wallet (although I just personally need to learn what it really is).

Also, if you're ok with running a shell command from php then an easy way would be to call my python cmd util to provide the address. Slower no doubt, but easy.

I want PHP code to be compatible with hosting accounts that do not allow shell commands or do not have python installed.
So pure PHP would be preferred. But python utility would still be useful to have to test final PHP code against.

Feel free to email me directly at: gleb/at/bitcoinway.com

Gleb

• 188888888qZ5Mv4u5C2Bve6eyVJBFR5EEj • Get personalized bitcoin address like that at http://vanitycoin.com/
BkkCoins
Hero Member
*****
Offline Offline

Activity: 784
Merit: 1009


firstbits:1MinerQ


View Profile WWW
April 04, 2013, 02:41:09 PM
 #7

I went ahead earlier and I've almost got this working now. I'm just debugging some issues with number conversion. I thought it would be fairly easy but turns out php and python offer very different ways of dealing with binary string data and hashing. So, just tracking the raw data thru and making sure it works right.

I expect in an hour or two to have a working function. It uses a PHP ECC library I found on GitHub. It says it is under the MIT license. It supports using bcmath or gmp for doing the bigint math. I have bcmath on my php install here and it's very slow. gmp is apparently much faster so that would be much preferable for doing this kind of math. I think openssl may have the abilities needed but the ssl functions in PHP did not seem to support ECC math.

I'll keep you posted shortly.

BkkCoins
Hero Member
*****
Offline Offline

Activity: 784
Merit: 1009


firstbits:1MinerQ


View Profile WWW
April 04, 2013, 03:18:07 PM
 #8

I've sent you an email. Have completed and tested code. Just waiting upon reply.

Tungsten (OP)
Member
**
Offline Offline

Activity: 73
Merit: 10



View Profile WWW
April 05, 2013, 01:52:30 PM
 #9

Thanks to BkkCoins for great work - Bounty sent.

Gleb
http://www.bitcoinway.com/

• 188888888qZ5Mv4u5C2Bve6eyVJBFR5EEj • Get personalized bitcoin address like that at http://vanitycoin.com/
BkkCoins
Hero Member
*****
Offline Offline

Activity: 784
Merit: 1009


firstbits:1MinerQ


View Profile WWW
April 06, 2013, 04:54:23 AM
 #10

Thanks Gleb. Bounty received.

I've also now incorporated the mpkgen scripts into my misc repo on GitHub. I made a few small changes to function names and added an attribution to vanitygen for some code.

https://github.com/bkkcoins/misc

There are several separate things in the mpkgen update.

1. Python script
2. C program (uses openssl library, fast)
3. PHP script (uses phpecc library and bcmath, quite slow)
3. PHP extension (written in C, uses openssl library, fast)

Anyone generating addresses outside Electrum should be aware of the gap limit value and have it set higher than the number of addresses generated that could be discarded/unused when given out.

It would also be wise (more safe) to store the index number of generated addresses, or at least a count of addresses given out. Along with the seed this would allow creating the private key for any of these addresses even if they cannot be detected by Electrum in the wallet.

This also would allow using these scripts for non-Electrum based payment discovery and management. eg. store index values given out and then generate keys and sign transactions on a safe computer to combine payments to an offline wallet.

If anyone is interested in such a sweep utility please contact me. I might work on that if useful.

scintill
Sr. Member
****
Offline Offline

Activity: 448
Merit: 252


View Profile WWW
April 13, 2013, 12:53:26 AM
 #11

3. PHP script (uses phpecc library and bcmath, quite slow)

from the github code:
Quote
// bcmath module in php seems to be very slow
// apparently the gmp module is much faster
// base2dec needs to be written for gmp as phpecc is missing it

This is all true, but if you define ('USE_EXT', 'GMP'); the EC math is still noticeably faster, in my experience, even if you're relying on the bcmath base2dec.  I don't know if doing a gmp implementation of the conversion utilities would make even more of a difference, but if you don't mind using both extensions, this "mixed" configuration was acceptable enough speed for my experiments.

1SCiN5kqkAbxxwesKMsH9GvyWnWP5YK2W | donations
BkkCoins
Hero Member
*****
Offline Offline

Activity: 784
Merit: 1009


firstbits:1MinerQ


View Profile WWW
April 13, 2013, 02:39:52 AM
 #12

3. PHP script (uses phpecc library and bcmath, quite slow)

from the github code:
Quote
// bcmath module in php seems to be very slow
// apparently the gmp module is much faster
// base2dec needs to be written for gmp as phpecc is missing it

This is all true, but if you define ('USE_EXT', 'GMP'); the EC math is still noticeably faster, in my experience, even if you're relying on the bcmath base2dec.  I don't know if doing a gmp implementation of the conversion utilities would make even more of a difference, but if you don't mind using both extensions, this "mixed" configuration was acceptable enough speed for my experiments.
GMP is faster but it's not available in a default install of PHP. So you're saying you can use an extension for GMP? I would need to code the two base conversion routines in bcmath to support GMP as right now they aren't there. But if you can dynamically load GMP without recompiling PHP then this may be worthwhile as bcmath is painfully slow.

My PHP extension (using openssl) is very fast. Much faster than using GMP and it's a loadable extension so that's probably just as good or better a choice. But I likely wouldn't have written it if I could have used GMP easily.

scintill
Sr. Member
****
Offline Offline

Activity: 448
Merit: 252


View Profile WWW
April 14, 2013, 03:42:06 AM
 #13

GMP is faster but it's not available in a default install of PHP. So you're saying you can use an extension for GMP? I would need to code the two base conversion routines in bcmath to support GMP as right now they aren't there. But if you can dynamically load GMP without recompiling PHP then this may be worthwhile as bcmath is painfully slow.

My PHP extension (using openssl) is very fast. Much faster than using GMP and it's a loadable extension so that's probably just as good or better a choice. But I likely wouldn't have written it if I could have used GMP easily.

Well, on Ubuntu I just have to install the php5-gmp package to get the extension working.  It installs a .so file and adds it to php.ini.  The package distributors may still have to compile the PHP core in a certain way beforehand to make this work, I don't know.  Similar convenience may be available in other Linux/PHP distributions.

Your extension looks nice and convenient as a one-step all-C function.  There is also a patch to expose some raw OpenSSL elliptic curve stuff to PHP, though I haven't tested it.

1SCiN5kqkAbxxwesKMsH9GvyWnWP5YK2W | donations
BkkCoins
Hero Member
*****
Offline Offline

Activity: 784
Merit: 1009


firstbits:1MinerQ


View Profile WWW
April 14, 2013, 05:09:10 AM
 #14

Well, on Ubuntu I just have to install the php5-gmp package to get the extension working.  It installs a .so file and adds it to php.ini.  The package distributors may still have to compile the PHP core in a certain way beforehand to make this work, I don't know.  Similar convenience may be available in other Linux/PHP distributions.
I didn't realize that. I'm using Ubuntu as well but didn't see php5-gmp. That's definitely an option then.

stick
Sr. Member
****
Offline Offline

Activity: 441
Merit: 266



View Profile
June 21, 2013, 05:35:12 PM
Last edit: June 21, 2013, 06:02:05 PM by stick
 #15

I created a minimalistic version of MPK address generator in PHP. It requires GMP extension to be installed on the system.

See this thread for more details: https://bitcointalk.org/index.php?topic=240018

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!