Pages:
Author

Topic: REWARD $200: Funds not visible after using XPub to receive money in my store - page 2. (Read 418 times)

legendary
Activity: 2310
Merit: 4313
🔐BitcoinMessage.Tools🔑
If you insert a variable ($client_id) in place of account, then the XPub key will change all the time. To keep XPub unchanged, you can change only the last two fields (change and address_index).
It all depends on which branch's xpub you are taking to derive addresses. For example, you can use xpub of m / 44' / 0' branch to derive as many accounts as you want, or you can use the master public key to derive all public keys from all branches.

The chief point is that you must use a different account for each customer if you want to keep them completely separated from each other.
full member
Activity: 336
Merit: 161
BIP44 derivation path has five levels:

m / purpose' / coin_type' / account' / change / address_index


But it should be this:

m / 44' / 0' / $client_id.' / 0 / 0 for receive addresses

m / 44' / 0' / $client_id.' / 1 / 0 for change addresses



If you insert a variable ($client_id) in place of account, then the XPub key will change all the time. To keep XPub unchanged, you can change only the last two fields (change and address_index).

I previously accepted BTC payments through the blockchain.com service.
https://www.blockchain.com/en/api/api_receive
There you need to give a request for an API key for your site: https://www.blockchain.com/api/request
There are also examples of PHP scripts to insert into your site.
legendary
Activity: 2212
Merit: 5622
Non-custodial BTC Wallet
Get a Linux LIVE DVD, boot from it, don't give it internet access, close the curtains, copy IanColeman's site on a USB stick, don't give it access to any hard drives, run from RAM only, and play around with it until you have the private keys you need. Then turn off the PC and wipe it's memory.

Or just move the bitcoins to a fresh new wallet with a new after if you are successful in recovering the private keys.

Consider your seed exposed and create a new wallet after inserting private keys in any computer.
legendary
Activity: 2310
Merit: 4313
🔐BitcoinMessage.Tools🔑
BIP44 derivation path has five levels:

m / purpose' / coin_type' / account' / change / address_index

In your case the derivation path is the following:

m / 44' / 0' / 0' / $client_id.' / 0

or

m / 44' / 0' / 0' / $client_id.' / 0'

But it should be this:

m / 44' / 0' / $client_id.' / 0 / 0 for receive addresses

m / 44' / 0' / $client_id.' / 1 / 0 for change addresses

The code you have presented in the OP is not suitable for changing an "account" part of the BIP44 derivation path, it only generates receive and change addresses (albeit with non-standard derivation paths) for one account.

Try changing it to something like this, but I am not sure it will work out:

Code:
require_once('./HD.php');

$xpub = 'xpub......';
$path = '$client_id.'/0/0';
$hd = new HD();
$hd->set_xpub($xpub);
$address = $hd->address_from_master_pub($path);


Also try the following paths to find your coins:

m / 44' / 0' / 0' / 526' / 0
m / 44' / 0' / 0' / 527' / 0
m / 44' / 0' / 0' / 528' / 0
m / 44' / 0' / 0' / 526' / 0'
m / 44' / 0' / 0' / 527' / 0'
m / 44' / 0' / 0' / 528' / 0'
These are all non-standard derivation paths since you used hardened derivation on "change" and "address_index" levels, whereas they should be non-hardened (without ').



I guess I found the error (pay attention to quotation marks):


require_once('./HD.php');

$xpub = 'xpub661MyMwAqRbcGYcu6n1FmV1TbE8EwnSKecRZLvKAMyj4qLf15qXsoNryiKNvCkRq3z5kBCeZG81 15jj28eVqmeKBJZPqjAfwRD3TGx1w5hY';
$path = '0/0'; // 1st receiving address
// $path = '0/2'; // 3rd receiving address
// $path = '1/0'; // 1st change address
// $path = '1/1'; // 2nd change address

$hd = new HD();
$hd->set_xpub($xpub);
$address = $hd->address_from_master_pub($path);

echo $address;




Your code:

Quote
require_once('./HD.php');

$xpub = 'xpub......';
$path = $client_id.'/0';
$hd = new HD();
$hd->set_xpub($xpub);
$address = $hd->address_from_master_pub($path);
legendary
Activity: 3290
Merit: 16489
Thick-Skinned Gang Leader and Golden Feather 2021
When using https://iancoleman.io/bip39/ with the seed words from your hardware wallet, taking your computer offline is not enough: it should never go online again!
Get a Linux LIVE DVD, boot from it, don't give it internet access, close the curtains, copy IanColeman's site on a USB stick, don't give it access to any hard drives, run from RAM only, and play around with it until you have the private keys you need. Then turn off the PC and wipe it's memory.
copper member
Activity: 2856
Merit: 3071
https://bit.ly/387FXHi lightning theory
Since m/44'/0'/0' worked and the code you gave above, I think it goes:
m/44'/client_id'/0'
(either that or m/44'/0'/clientid'/0' -but that may be less likely)

How do you know the addresses generated have actually been funded though? I think you need a script thst goes through and checks from an api (such as a block explorer) as to whether an address you control has been funded or not.

The problem is that m/44/2 is litecoin
The third level will go to different altcoins. I don't know how to handle that (an altcoin path) in a bitcoin wallet.

Just take a look at iancoleman and you will see.

It's just replay protection and there are tools to convert litecoin public keys to bitcoin ones and vice versa (they just add an offset to the public key to make it different - the private key will be the same).

legendary
Activity: 2212
Merit: 5622
Non-custodial BTC Wallet
Since m/44'/0'/0' worked and the code you gave above, I think it goes:
m/44'/client_id'/0'
(either that or m/44'/0'/clientid'/0' -but that may be less likely)

How do you know the addresses generated have actually been funded though? I think you need a script thst goes through and checks from an api (such as a block explorer) as to whether an address you control has been funded or not.

The problem is that m/44/2 is litecoin
The third level will go to different altcoins. I don't know how to handle that (an altcoin path) in a bitcoin wallet.

Just take a look at iancoleman and you will see.


is iancoleman safe ?
Does iancoleman  have offline copy ?

Yes
 You can download it and run offline. It is safe.
jr. member
Activity: 107
Merit: 8
Yes, you can use it offline..
copper member
Activity: 12
Merit: 51
It seems like Electrum is treating each 'client id' as a change path. Your best bet may be to use the seed to manually recover the coins using iancoleman.
thanx

is iancoleman safe ?
Does iancoleman  have offline copy ?
jr. member
Activity: 107
Merit: 8
It seems like Electrum is treating each 'client id' as a change path. Your best bet may be to use the seed to manually recover the coins using iancoleman.
copper member
Activity: 12
Merit: 51
i try to search  here :
https://blockpath.com/wallets/local/101?action=appxpub


i find my btc :






now how i can make electrum  generate the same path ?


t

The screenshot makes it easier then, you can do this;

1. Go to electrum, in the derivation path, tick legacy and put m/clientid (m/489) underneath or

2. Use iancoleman.io/bip39 listed above(beware, using this may compromise your seed)


put the seed in the mnemonic box and change the derivation path to bip32, select custom path and put m/client id (m/489).



i try it , gave me different addresses and no btc







jr. member
Activity: 107
Merit: 8
i try to search  here :
https://blockpath.com/wallets/local/101?action=appxpub


i find my btc :






now how i can make electrum  generate the same path ?


t

The screenshot makes it easier then, you can do this;

1. Go to electrum, in the derivation path, tick legacy and put m/clientid (m/489) underneath or

2. Use iancoleman.io/bip39 listed above(beware, using this may compromise your seed)


put the seed in the mnemonic box and change the derivation path to bip32, select custom path and put m/client id (m/489).

copper member
Activity: 12
Merit: 51
Your xpub should be the extended master public key. Why do you believe that your derivation path is formed according to BIP44?
Why do you believe that your provided per user path is hardened (like you tried with m/44'/client_id'/0' and m/44'/0'/clientid'/0')? I don't see any clue for that in your code. Is that somewhere implicitly used in the modules of that Bit-Wasp/bitcoin-phpLibrary?

Probably you'd need to dig in the code there further. You will have to find out what full derivation path for a client user address is used.

To narrow it down, print some log line for $pubPrefix, $config and add some log lines for function derivePath(), maybe you can see there how the derivation path is assembled.


here is the log when i use 0/0 in my script :


$config :

Code:
BitWasp\Bitcoin\Key\Deterministic\HdPrefix\GlobalPrefixConfig Object
(
    [networkConfigs:BitWasp\Bitcoin\Key\Deterministic\HdPrefix\GlobalPrefixConfig:private] => Array
        (
            [BitWasp\Bitcoin\Network\Networks\Bitcoin] => BitWasp\Bitcoin\Key\Deterministic\HdPrefix\NetworkConfig Object
                (
                    [network:BitWasp\Bitcoin\Key\Deterministic\HdPrefix\NetworkConfig:private] => BitWasp\Bitcoin\Network\Networks\Bitcoin Object
                        (
                            [base58PrefixMap:protected] => Array
                                (
                                    [p2pkh] => 00
                                    [p2sh] => 05
                                    [wif] => 80
                                )

                            [bech32PrefixMap:protected] => Array
                                (
                                    [segwit] => bc
                                )

                            [bip32PrefixMap:protected] => Array
                                (
                                    [xpub] => 0488b21e
                                    [xprv] => 0488ade4
                                )

                            [bip32ScriptTypeMap:protected] => Array
                                (
                                    [xpub] => pubkeyhash
                                    [xprv] => pubkeyhash
                                )

                            [signedMessagePrefix:protected] => Bitcoin Signed Message
                            [p2pMagic:protected] => d9b4bef9
                        )

                    [scriptPrefixMap:BitWasp\Bitcoin\Key\Deterministic\HdPrefix\NetworkConfig:private] => Array
                        (
                            [0488ade4] => BitWasp\Bitcoin\Key\Deterministic\HdPrefix\ScriptPrefix Object
                                (
                                    [privatePrefix:BitWasp\Bitcoin\Key\Deterministic\HdPrefix\ScriptPrefix:private] => 0488ade4
                                    [publicPrefix:BitWasp\Bitcoin\Key\Deterministic\HdPrefix\ScriptPrefix:private] => 0488b21e
                                    [scriptDataFactory:BitWasp\Bitcoin\Key\Deterministic\HdPrefix\ScriptPrefix:private] => BitWasp\Bitcoin\Key\KeyToScript\Factory\P2pkhScriptDataFactory Object
                                        (
                                            [pubKeySerializer:protected] => BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Serializer\Key\PublicKeySerializer Object
                                                (
                                                    [ecAdapter:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Serializer\Key\PublicKeySerializer:private] => BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter Object
                                                        (
                                                            [math:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter:private] => BitWasp\Bitcoin\Math\Math Object
                                                                (
                                                                )

                                                            [generator:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter:private] => Mdanter\Ecc\Primitives\GeneratorPoint Object
                                                                (
                                                                    [x] => 55066263022277343669578718895168534326250603453777594175500187360389116729240
                                                                    [y] => 32670510020758816978083085130507043184471273380659243275938904335757337482424
                                                                    [z] => 115792089237316195423570985008687907852837564279074904382605163141518161494337
                                                                    [curve] => Mdanter\Ecc\Curves\NamedCurveFp Object
                                                                        (
                                                                            [a] => 0
                                                                            [b] => 7
                                                                            [prime] => 115792089237316195423570985008687907853269984665640564039457584007908834671663
                                                                        )

                                                                )

                                                        )

                                                )

                                        )

                                )

                            [0488b21e] => BitWasp\Bitcoin\Key\Deterministic\HdPrefix\ScriptPrefix Object
                                (
                                    [privatePrefix:BitWasp\Bitcoin\Key\Deterministic\HdPrefix\ScriptPrefix:private] => 0488ade4
                                    [publicPrefix:BitWasp\Bitcoin\Key\Deterministic\HdPrefix\ScriptPrefix:private] => 0488b21e
                                    [scriptDataFactory:BitWasp\Bitcoin\Key\Deterministic\HdPrefix\ScriptPrefix:private] => BitWasp\Bitcoin\Key\KeyToScript\Factory\P2pkhScriptDataFactory Object
                                        (
                                            [pubKeySerializer:protected] => BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Serializer\Key\PublicKeySerializer Object
                                                (
                                                    [ecAdapter:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Serializer\Key\PublicKeySerializer:private] => BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter Object
                                                        (
                                                            [math:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter:private] => BitWasp\Bitcoin\Math\Math Object
                                                                (
                                                                )

                                                            [generator:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter:private] => Mdanter\Ecc\Primitives\GeneratorPoint Object
                                                                (
                                                                    [x] => 55066263022277343669578718895168534326250603453777594175500187360389116729240
                                                                    [y] => 32670510020758816978083085130507043184471273380659243275938904335757337482424
                                                                    [z] => 115792089237316195423570985008687907852837564279074904382605163141518161494337
                                                                    [curve] => Mdanter\Ecc\Curves\NamedCurveFp Object
                                                                        (
                                                                            [a] => 0
                                                                            [b] => 7
                                                                            [prime] => 115792089237316195423570985008687907853269984665640564039457584007908834671663
                                                                        )

                                                                )

                                                        )

                                                )

                                        )

                                )

                        )

                    [scriptTypeMap:BitWasp\Bitcoin\Key\Deterministic\HdPrefix\NetworkConfig:private] => Array
                        (
                            [pubkeyhash] => BitWasp\Bitcoin\Key\Deterministic\HdPrefix\ScriptPrefix Object
                                (
                                    [privatePrefix:BitWasp\Bitcoin\Key\Deterministic\HdPrefix\ScriptPrefix:private] => 0488ade4
                                    [publicPrefix:BitWasp\Bitcoin\Key\Deterministic\HdPrefix\ScriptPrefix:private] => 0488b21e
                                    [scriptDataFactory:BitWasp\Bitcoin\Key\Deterministic\HdPrefix\ScriptPrefix:private] => BitWasp\Bitcoin\Key\KeyToScript\Factory\P2pkhScriptDataFactory Object
                                        (
                                            [pubKeySerializer:protected] => BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Serializer\Key\PublicKeySerializer Object
                                                (
                                                    [ecAdapter:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Serializer\Key\PublicKeySerializer:private] => BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter Object
                                                        (
                                                            [math:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter:private] => BitWasp\Bitcoin\Math\Math Object
                                                                (
                                                                )

                                                            [generator:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter:private] => Mdanter\Ecc\Primitives\GeneratorPoint Object
                                                                (
                                                                    [x] => 55066263022277343669578718895168534326250603453777594175500187360389116729240
                                                                    [y] => 32670510020758816978083085130507043184471273380659243275938904335757337482424
                                                                    [z] => 115792089237316195423570985008687907852837564279074904382605163141518161494337
                                                                    [curve] => Mdanter\Ecc\Curves\NamedCurveFp Object
                                                                        (
                                                                            [a] => 0
                                                                            [b] => 7
                                                                            [prime] => 115792089237316195423570985008687907853269984665640564039457584007908834671663
                                                                        )

                                                                )

                                                        )

                                                )

                                        )

                                )

                        )

                )

        )

)


derivePath() /$child_key :

Code:
BitWasp\Bitcoin\Key\Deterministic\HierarchicalKey Object
(
    [ecAdapter:protected] => BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter Object
        (
            [math:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter:private] => BitWasp\Bitcoin\Math\Math Object
                (
                )

            [generator:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter:private] => Mdanter\Ecc\Primitives\GeneratorPoint Object
                (
                    [x] => 55066263022277343669578718895168534326250603453777594175500187360389116729240
                    [y] => 32670510020758816978083085130507043184471273380659243275938904335757337482424
                    [z] => 115792089237316195423570985008687907852837564279074904382605163141518161494337
                    [curve] => Mdanter\Ecc\Curves\NamedCurveFp Object
                        (
                            [a] => 0
                            [b] => 7
                            [prime] => 115792089237316195423570985008687907853269984665640564039457584007908834671663
                        )

                )

        )

    [depth:BitWasp\Bitcoin\Key\Deterministic\HierarchicalKey:private] => 5
    [parentFingerprint:BitWasp\Bitcoin\Key\Deterministic\HierarchicalKey:private] => 723835999
    [sequence:BitWasp\Bitcoin\Key\Deterministic\HierarchicalKey:private] => 0
    [chainCode:BitWasp\Bitcoin\Key\Deterministic\HierarchicalKey:private] => BitWasp\Buffertools\Buffer Object
        (
            [size] => 32
            [buffer] => 0xfb02983db7403c801564ac0282bec2be39722325968b530fc3505898e3b346da
        )

    [key:BitWasp\Bitcoin\Key\Deterministic\HierarchicalKey:private] => BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Key\PublicKey Object
        (
            [ecAdapter:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Key\PublicKey:private] => BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter Object
                (
                    [math:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter:private] => BitWasp\Bitcoin\Math\Math Object
                        (
                        )

                    [generator:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter:private] => Mdanter\Ecc\Primitives\GeneratorPoint Object
                        (
                            [x] => 55066263022277343669578718895168534326250603453777594175500187360389116729240
                            [y] => 32670510020758816978083085130507043184471273380659243275938904335757337482424
                            [z] => 115792089237316195423570985008687907852837564279074904382605163141518161494337
                            [curve] => Mdanter\Ecc\Curves\NamedCurveFp Object
                                (
                                    [a] => 0
                                    [b] => 7
                                    [prime] => 115792089237316195423570985008687907853269984665640564039457584007908834671663
                                )

                        )

                )

            [point:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Key\PublicKey:private] => Mdanter\Ecc\Primitives\Point Object
                (
                    [x] => 109756113754416006883068144059295232931743649784206556207715924624422608984554
                    [y] => 30336686192482416354579004682961920948817072959615255523669782145222377339335
                    [z] => 0
                    [curve] => Mdanter\Ecc\Curves\NamedCurveFp Object
                        (
                            [a] => 0
                            [b] => 7
                            [prime] => 115792089237316195423570985008687907853269984665640564039457584007908834671663
                        )

                )

            [prefix:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Key\PublicKey:private] =>
            [compressed:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Key\PublicKey:private] => 1
            [pubKeyHash:protected] =>
        )

    [scriptDataFactory:BitWasp\Bitcoin\Key\Deterministic\HierarchicalKey:private] => BitWasp\Bitcoin\Key\KeyToScript\Factory\P2pkhScriptDataFactory Object
        (
            [pubKeySerializer:protected] => BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Serializer\Key\PublicKeySerializer Object
                (
                    [ecAdapter:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Serializer\Key\PublicKeySerializer:private] => BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter Object
                        (
                            [math:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter:private] => BitWasp\Bitcoin\Math\Math Object
                                (
                                )

                            [generator:BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter:private] => Mdanter\Ecc\Primitives\GeneratorPoint Object
                                (
                                    [x] => 55066263022277343669578718895168534326250603453777594175500187360389116729240
                                    [y] => 32670510020758816978083085130507043184471273380659243275938904335757337482424
                                    [z] => 115792089237316195423570985008687907852837564279074904382605163141518161494337
                                    [curve] => Mdanter\Ecc\Curves\NamedCurveFp Object
                                        (
                                            [a] => 0
                                            [b] => 7
                                            [prime] => 115792089237316195423570985008687907853269984665640564039457584007908834671663
                                        )

                                )

                        )

                )

        )

    [scriptAndSignData:BitWasp\Bitcoin\Key\Deterministic\HierarchicalKey:private] =>
)
hero member
Activity: 714
Merit: 1010
Crypto Swap Exchange
Your xpub should be the extended master public key. Why do you believe that your derivation path is formed according to BIP44?
Why do you believe that your provided per user path is hardened (like you tried with m/44'/client_id'/0' and m/44'/0'/clientid'/0')? I don't see any clue for that in your code. Is that somewhere implicitly used in the modules of that Bit-Wasp/bitcoin-phpLibrary?

Probably you'd need to dig in the code there further. You will have to find out what full derivation path for a client user address is used.

To narrow it down, print some log line for $pubPrefix, $config and add some log lines for function derivePath(), maybe you can see there how the derivation path is assembled.
copper member
Activity: 12
Merit: 51
Code:
$path = $client_id.'/0';

Since m/44'/0'/0' worked and the code you gave above, I think it goes:
m/44'/client_id'/0'
(either that or m/44'/0'/clientid'/0' -but that may be less likely)



i try m/44'/client_id'/0' and m/44'/0'/clientid'/0' not working

 
Code:
How do you know the addresses generated have actually been funded though? .
i see the money on btc explorer
copper member
Activity: 12
Merit: 51

but that not helping me because the path is different .

when i try login to electrum  with  different path it will give me another XPub
i try those paths :
Code:
m/44'/0'/0'
m/44'/0'/1'
m/44'/1'/0'
m/44'/0'/0'/0'
...

You made quite a mess here.

The third level of the derivation path is the coin type. (Details here: https://www.oreilly.com/library/view/mastering-bitcoin/9781491902639/ch04.html)
For example, m/44/1 is a test network branch

Your script should be creating a new account for each user, then it ahould be m/44/0/username


Quote
the only one give me right XPub is m/44'/0'/0'

now how i can make electrum  generate  addresses with the same path i use in my php script

Code:

527/0
528/0
.
.


Each time you change the derivation path after the third level you will get a new xpub. This is why electrum is showing a different xpub.
 You can see it in action here: https://iancoleman.io/bip39/

You can change de derivation path and see how the xpub changes.

An xpub will derive all public keys in that branch.
I think that as you generated an xpub in the top level, it contains all those child ones. You are just getting an xpub of child branches.  You have those keys in your xpub.

You just need to figure out in which derivation path they are.

Can you give us more information about this script you made?



In your next payments, you should definitely use a professional solution like btcpayserver.org
They have hardware wallet integration and it is free to use

https://docs.btcpayserver.org/HardwareWalletIntegration/

thanks for explaining

about the script :
 i install Bit-Wasp/bitcoin-phpLibrary
Code:
composer require bitwasp/bitcoin


and i make new file HD.php :
link for HD.php :
https://gist.githubusercontent.com/mariodian/5b67a1f315a74a7753a6f23d0198ec48/raw/2742a7909dd2621381de53209e85348a078df470/HD.php
OR

Code:

require_once('vendor/autoload.php');

use 
BitWasp\Bitcoin\Bitcoin;
use 
BitWasp\Bitcoin\Address\AddressCreator;
use 
BitWasp\Bitcoin\Key\Deterministic\HdPrefix\GlobalPrefixConfig;
use 
BitWasp\Bitcoin\Key\Deterministic\HdPrefix\NetworkConfig;
use 
BitWasp\Bitcoin\Network\Slip132\BitcoinRegistry;
use 
BitWasp\Bitcoin\Key\Deterministic\Slip132\Slip132;
use 
BitWasp\Bitcoin\Key\KeyToScript\KeyToScriptHelper;
use 
BitWasp\Bitcoin\Key\Deterministic\HierarchicalKeyFactory;
use 
BitWasp\Bitcoin\Key\Deterministic\HierarchicalKeySequence;
use 
BitWasp\Bitcoin\Key\Deterministic\MultisigHD;
use 
BitWasp\Bitcoin\Network\NetworkFactory;
use 
BitWasp\Bitcoin\Serializer\Key\HierarchicalKey\Base58ExtendedKeySerializer;
use 
BitWasp\Bitcoin\Serializer\Key\HierarchicalKey\ExtendedKeySerializer;

class 
HD {
  private 
$network NULL;
  private 
$xpub NULL;
  private 
$ypub NULL;
  private 
$zpub NULL;
  private 
$multisig_xpubs NULL;

  public function 
__construct($network 'bitcoin') {
    if (
version_compare(PHP_VERSION'5.3') >= 0) {
      
$this->network NetworkFactory::$network();
    } elseif (
version_compare(PHP_VERSION'5.2.3') >= 0) {
      
$this->network call_user_func("NetworkFactory::$network");
    } else {
      
$this->network call_user_func('NetworkFactory'$network);
    }
  }

  public function 
set_xpub($xpub) {
    
$this->xpub $xpub;
  }

  public function 
set_ypub($ypub) {
    
$this->ypub $ypub;
  }

  public function 
set_zpub($zpub) {
    
$this->zpub $zpub;
  }

  public function 
set_multisig_xpubs($xpubs) {
    
$this->multisig_xpubs $xpubs;
  }

  public function 
address_from_master_pub($path '0/0') {
    if (
$this->xpub === NULL && $this->ypub === NULL && $this->zpub === NULL) {
      throw new 
Exception("XPUB, YPUB or ZPUB key is not present!");
    }

    
$adapter Bitcoin::getEcAdapter();
    
$slip132 = new Slip132(new KeyToScriptHelper($adapter));
    
$bitcoin_prefixes = new BitcoinRegistry();

    if (
$this->xpub !== NULL) {
      
$pubPrefix $slip132->p2pkh($bitcoin_prefixes);
      
$pub $this->xpub;
    } else if (
$this->ypub !== NULL) {
      
$pubPrefix $slip132->p2shP2wpkh($bitcoin_prefixes);
      
$pub $this->ypub;
    } else if (
$this->zpub !== NULL) {
      
$pubPrefix $slip132->p2wpkh($bitcoin_prefixes);
      
$pub $this->zpub;
    }

    
$config = new GlobalPrefixConfig([
      new 
NetworkConfig($this->network, [
        
$pubPrefix,
      ])
    ]);

    
$serializer = new Base58ExtendedKeySerializer(
      new 
ExtendedKeySerializer($adapter$config)
    );

    
$key $serializer->parse($this->network$pub);
    
$child_key $key->derivePath($path);

    return 
$child_key->getAddress(new AddressCreator())->getAddress();
  }

  public function 
multisig_address_from_xpub($m$path '0/0') {
    if (
count($this->multisig_xpubs) < 2) {
      throw new 
Exception("XPUB keys are not present!");
    }

    
$keys = array();

    foreach (
$this->multisig_xpubs as $xpub) {
      
$keys[] = HierarchicalKeyFactory::fromExtended($xpub$this->network);
    }

    
$sequences = new HierarchicalKeySequence();
    
$hd = new MultisigHD($m'm'$keys$sequencesTRUE);

    
$child_key $hd->derivePath($path);

    return 
$child_key->getAddress()->getAddress($this->network);
  }
}


after that i include HD.php in my project like this :

Code:
require_once('./HD.php');

$xpub = 'xpub......';
$path = $client_id.'/0';
$hd = new HD();
$hd->set_xpub($xpub);
$address = $hd->address_from_master_pub($path);

where $client_id is client id  number


copper member
Activity: 2856
Merit: 3071
https://bit.ly/387FXHi lightning theory
Code:
$path = $client_id.'/0';

Since m/44'/0'/0' worked and the code you gave above, I think it goes:
m/44'/client_id'/0'
(either that or m/44'/0'/clientid'/0' -but that may be less likely)

How do you know the addresses generated have actually been funded though? I think you need a script thst goes through and checks from an api (such as a block explorer) as to whether an address you control has been funded or not.
legendary
Activity: 2212
Merit: 5622
Non-custodial BTC Wallet

but that not helping me because the path is different .

when i try login to electrum  with  different path it will give me another XPub
i try those paths :
Code:
m/44'/0'/0'
m/44'/0'/1'
m/44'/1'/0'
m/44'/0'/0'/0'
...

You made quite a mess here.

The third level of the derivation path is the coin type. (Details here: https://www.oreilly.com/library/view/mastering-bitcoin/9781491902639/ch04.html)
For example, m/44/1 is a test network branch

Your script should be creating a new account for each user, then it ahould be m/44/0/username


Quote
the only one give me right XPub is m/44'/0'/0'

now how i can make electrum  generate  addresses with the same path i use in my php script

Code:

527/0
528/0
.
.


Each time you change the derivation path after the third level you will get a new xpub. This is why electrum is showing a different xpub.
 You can see it in action here: https://iancoleman.io/bip39/

You can change de derivation path and see how the xpub changes.

An xpub will derive all public keys in that branch.
I think that as you generated an xpub in the top level, it contains all those child ones. You are just getting an xpub of child branches.  You have those keys in your xpub.

You just need to figure out in which derivation path they are.

Can you give us more information about this script you made?



In your next payments, you should definitely use a professional solution like btcpayserver.org
They have hardware wallet integration and it is free to use

https://docs.btcpayserver.org/HardwareWalletIntegration/
copper member
Activity: 12
Merit: 51
use m/44'/0'/client id', try that first and see if you'd get the address.

same thing electrum  gave me different XPub
any change  to this path 

Code:
m/44'/0'/0'

electrum   will gave me different XPub
jr. member
Activity: 107
Merit: 8
use m/44'/0'/client id', try that first and see if you'd get the address.
Pages:
Jump to: