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 :
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
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
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
composer require bitwasp/bitcoin
and i make new file HD.php :
link for HD.php :
https://gist.githubusercontent.com/mariodian/5b67a1f315a74a7753a6f23d0198ec48/raw/2742a7909dd2621381de53209e85348a078df470/HD.phpOR
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, $sequences, TRUE);
$child_key = $hd->derivePath($path);
return $child_key->getAddress()->getAddress($this->network);
}
}
after that i include HD.php in my project like this :
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