Bitcoin Forum
November 05, 2024, 08:30:35 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Any BIP32 implementation in PHP?  (Read 1196 times)
imrehg (OP)
Newbie
*
Offline Offline

Activity: 23
Merit: 0


View Profile WWW
January 22, 2014, 06:05:53 AM
 #1

Haven't seen any PHP implementations of BIP32 so far, I was wondering if anyone's working on it by chance?

I've seen bitcoin-php for general bitcoin support, and considering that bip32 could be added to that one, though that library hasn't seem to been touched for the last 7 months or so.
fbueller
Sr. Member
****
Offline Offline

Activity: 412
Merit: 287


View Profile
January 22, 2014, 02:23:02 PM
 #2

I'm currently working on it, but I've only barely scratched the surface. I need to do some more work on my CKD functions, and tidy the whole thing up in general, but it shouldn't take too long. I mainly need it so I can accept M/0'/0 keys from people, and generate M/0'/0/x whenever they create the x'th order.

I'm also working on a general library for bitcoin in PHP, that the BIP32 class will be a part of. It's was largely based on theymos' library, however I've rewritten most of it at this stage, and added functions for manipulating keys, generating electrum seeds, mpk's, public and private keys. It's dependent on php-ecc (Mathias Danters absolute godsend of a library on github), but my portion will strictly be coded using PHP's GMP extension.

Bitwasp Developer.
imrehg (OP)
Newbie
*
Offline Offline

Activity: 23
Merit: 0


View Profile WWW
January 23, 2014, 04:34:17 AM
 #3

Sounds cool, thanks! Would love to check it out whenever you share it/open it up on Github I guess.
fbueller
Sr. Member
****
Offline Offline

Activity: 412
Merit: 287


View Profile
February 05, 2014, 04:08:52 PM
Last edit: February 06, 2014, 02:18:39 AM by fbueller
 #4

I've finally gotten mine working. It's in a repo I have for demonstrating multi-signature transactions: https://github.com/Bit-Wasp/multisig

The class you want is https://github.com/Bit-Wasp/multisig/blob/master/application/libraries/BIP32.php and an example of this is here: https://github.com/Bit-Wasp/multisig/blob/master/examples/bip32.php. You'll need the BitcoinLib library too, and the contents of the ecc-lib folder.

Let me know how you get on!

Bitwasp Developer.
imrehg (OP)
Newbie
*
Offline Offline

Activity: 23
Merit: 0


View Profile WWW
February 06, 2014, 01:28:59 PM
 #5

Cool, thanks a lot! I understand things a lot more making a related service in the meantime that I wanted to use (BIP32 web wallet), but now this library will be mighty useful. Will let you know for sure when I make something with it, thanks!
fbueller
Sr. Member
****
Offline Offline

Activity: 412
Merit: 287


View Profile
February 06, 2014, 07:20:21 PM
 #6

Yeah awesome. I've just kept it simple, I'll mainly need to accept M/x' from people, so I can generate M/x'/0/i for receiving coins, and M/x'/1/i to yield keys for multisig. Let me know if there's anything else you need, or if there's a better way of doing things.

Bitwasp Developer.
imrehg (OP)
Newbie
*
Offline Offline

Activity: 23
Merit: 0


View Profile WWW
February 12, 2014, 06:07:27 AM
 #7

Yeah awesome. I've just kept it simple, I'll mainly need to accept M/x' from people, so I can generate M/x'/0/i for receiving coins, and M/x'/1/i to yield keys for multisig. Let me know if there's anything else you need, or if there's a better way of doing things.


In the original writeup M/x'/1/i was supposed to be the internal chain, used mostly for change addresses I guess, and other addresses that are not needed to be communicated outside. I wonder if multisig would be better on a different chain, maybe e.g. a-of-b multisig could be M/x'/b/i chain?

I'm asking generally from the interoperability point of view. BIP32 is great to be suitable for infinite amount if different arrangements, but some concepts are worth to be figured out on top of it - trying to think what would make more sense.
fbueller
Sr. Member
****
Offline Offline

Activity: 412
Merit: 287


View Profile
February 12, 2014, 01:04:00 PM
Last edit: February 12, 2014, 06:34:22 PM by fbueller
 #8

I don't mean creating a chain of multisig addresses directly on M/x'. I mean deriving subkeys from several different users M/x', that would be used to create an address.

I would ask 3 users (in a 2-of-3 escrow transaction) to give me an extended key for M/x' when they register.
So I could get M/1' from one users, M/34' from another, and M/9' from another. By giving me a key for an unused wallet chain, I can derive keys for receiving coin and signing. I don't necessarily have to use the internal one for creating signing keys.

Say it's their first transaction on the site. Generate M/1'/1/0, M/34'/1/0, M/9'/1/0 and create a multisig address from it.
The next time they transact, it would be generated from M/1'/1/1, M/34'/1/1, M/9'/1/1, and so on.

I have some code up here to go through an example of generating a multisig address using 3 different wallets keys. A chain of multisig addresses can be derived for each user.
https://github.com/Bit-Wasp/multisig/blob/master/application/controllers/examples.php#L48-96
(I need to look into an issue in this code, one of the final public keys generated in this example is being rejected by Bitcoind. It passes the test vectors put up on github, so not sure how this arose but I'll try update soon)

The output of this transaction could be to the address generated by first users M/1'/0/0, if the first user was receiving the funds. This time it's on the external chain. In fairness I could just keep popping from the external branch, a new child key each time.

There's a wallet called haskoin which allows you to create a wallet chain, M/0' like what I'm doing here, but that it is partially seeded. It supplies one key, you supply the other one/two/etc keys as needed. Each address in the chain is a new one derived from each of these keys. This should be interesting software when it's complete!

Bitwasp Developer.
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!