Bit-Wasp / bitcoin-lib-php

PHP libraries implementing bitcoin key functions, as well as BIP32 and electrum.
The Unlicense
136 stars 86 forks source link

Generating change address from publicKey Bip44, Bip43 #116

Closed AdamSEY closed 6 years ago

AdamSEY commented 6 years ago

I would like to generate change address from public key that's my code:


$masterPriv = 'xprv9s21ZrQH143K2p33tm4NEgsJwb2sc2WQ6VHauuaMXqSnYfcQ66Q1WUTg8543XpSKZA3pKkfT9XrWT9yTCipj7rurAEkAKLrDnv2rQ4P7jic';
       $masterPub = 'xpub661MyMwAqRbcFJ7WznbNbpp3VcsN1VEFTiDBiHyy6AymRTwYddiG4Gn9yLoTFunHYrwwAEh4jA8XTeyVCwiWwkE4aNJzU8A5QvujoEy1bpN';
        $masterkey2 = HierarchicalKeyFactory::fromExtended($masterPriv);
        $public =  $masterkey2->derivePath("m/44'/0'/0'")->toExtendedPublicKey();
        $test =  HierarchicalKeyFactory::fromExtended($public);
        $address2 = $test->derivePath("m/0/0")->getPublicKey()->getAddress()->getAddress();

is changing 0 to 1 in the last line will return me "change address"?