Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <?php
- require_once('vendor/autoload.php');
- use BitWasp\BitcoinLib\BitcoinLib;
- use BitcoinPHP\BitcoinECDSA\BitcoinECDSA;
- use Mdanter\Ecc\EccFactory;
- $bitcoinECDSA = new BitcoinECDSA();
- // Start BIP 39 Seed
- $password = "symptom display melt eight where universe prison vacuum convince garbage glance fork";
- $iterations = 2048;
- $salt = "mnemonic";
- $hash = hash_pbkdf2("sha512", $password, $salt, $iterations);
- echo $hash."<br>";
- // End BIP 39 Seed
- // Start BIP 32 Root Key (m)
- $hashdata = pack("H*" , $hash);
- $chaindata = "Bitcoin seed";
- $hash_m = hash_hmac("sha512" , $hashdata, $chaindata);
- $hash_m_l = substr($hash_m, 0, 64);
- $hash_m_r = substr($hash_m, 64, 64);
- $data_m = array(
- 'network' => '0488ade4',
- 'depth' => '00',
- 'fingerprint' => '00000000',
- 'i' => '00000000',
- 'chain_code' => $hash_m_r,
- 'key' => '00'.$hash_m_l,
- );
- $xprivkey_m = implode($data_m);
- $checksum_m = hash('sha256', pack("H*", hash('sha256', pack("H*", $xprivkey_m))));
- $checksum_m = substr($checksum_m, 0, 8);
- $xprivkey_m = $xprivkey_m . $checksum_m;
- $base58 = new StephenHill\Base58();
- echo $base58->encode(pack("H*", $xprivkey_m))."<br>";
- // End BIP 32 Root Key (m)
- // Start m/44' derivation
- $hashdata = pack("H*", "00" . $hash_m_l . "8000002C");
- $chaindata = pack("H*", $hash_m_r);
- $hash_m_44 = hash_hmac("sha512" , $hashdata, $chaindata);
- $hash_m_44_l = substr($hash_m_44, 0, 64);
- $hash_m_44_r = substr($hash_m_44, 64, 64);
- $bitcoinECDSA->setPrivateKey($hash_m_l);
- $finger_m = $bitcoinECDSA->getPubKey();
- $finger_m = hash('ripemd160', pack("H*", hash('sha256', pack("H*", $finger_m))));
- $finger_m = substr($finger_m, 0, 8);
- $math = EccFactory::getAdapter();
- $g = EccFactory::getSecgCurves($math)->generator256k1();
- $n = $g->getOrder();
- $Il_dec = $math->hexDec($hash_m_44_l);
- $private_key_dec = $math->hexDec($hash_m_l);
- $key_dec = $math->mod($math->add($Il_dec, $private_key_dec), $n);
- $keym44 = str_pad(BitcoinLib::hex_encode($key_dec), 64, '0', STR_PAD_LEFT);
- $data_m_44 = array(
- 'network' => '0488ade4',
- 'depth' => '01',
- 'fingerprint' => $finger_m,
- 'i' => '8000002C',
- 'chain_code' => $hash_m_44_r,
- 'key' => '00'.$keym44,
- );
- $xprivkey_m_44 = implode($data_m_44);
- $checksum_m_44 = hash('sha256', pack("H*", hash('sha256', pack("H*", $xprivkey_m_44))));
- $checksum_m_44 = substr($checksum_m_44, 0, 8);
- $xprivkey_m_44 = $xprivkey_m_44 . $checksum_m_44;
- $base58 = new StephenHill\Base58();
- echo $base58->encode(pack("H*", $xprivkey_m_44))."<br>";
- // End m/44' derivation
- // Start m/44'/0' derivation
- $hashdata = pack("H*", "00" . $keym44 . "80000000");
- $chaindata = pack("H*", $hash_m_44_r);
- $hash_m_44_0 = hash_hmac("sha512" , $hashdata, $chaindata);
- $hash_m_44_0_l = substr($hash_m_44_0, 0, 64);
- $hash_m_44_0_r = substr($hash_m_44_0, 64, 64);
- $bitcoinECDSA->setPrivateKey($keym44);
- $finger_m_44 = $bitcoinECDSA->getPubKey();
- $finger_m_44 = hash('ripemd160', pack("H*", hash('sha256', pack("H*", $finger_m_44))));
- $finger_m_44 = substr($finger_m_44, 0, 8);
- $math = EccFactory::getAdapter();
- $g = EccFactory::getSecgCurves($math)->generator256k1();
- $n = $g->getOrder();
- $Il_dec = $math->hexDec($hash_m_44_0_l);
- $private_key_dec = $math->hexDec($keym44);
- $key_dec = $math->mod($math->add($Il_dec, $private_key_dec), $n);
- $keym440 = str_pad(BitcoinLib::hex_encode($key_dec), 64, '0', STR_PAD_LEFT);
- $data_m_44_0 = array(
- 'network' => '0488ade4',
- 'depth' => '02',
- 'fingerprint' => $finger_m_44,
- 'i' => '80000000',
- 'chain_code' => $hash_m_44_0_r,
- 'key' => '00'.$keym440,
- );
- $xprivkey_m_44_0 = implode($data_m_44_0);
- $checksum_m_44_0 = hash('sha256', pack("H*", hash('sha256', pack("H*", $xprivkey_m_44_0))));
- $checksum_m_44_0 = substr($checksum_m_44_0, 0, 8);
- $xprivkey_m_44_0 = $xprivkey_m_44_0 . $checksum_m_44_0;
- $base58 = new StephenHill\Base58();
- echo $base58->encode(pack("H*", $xprivkey_m_44_0))."<br>";
- // End m/44'/0' derivation
- // Start m/44'/0'/0' derivation
- $hashdata = pack("H*", "00" . $keym440 . "80000000");
- $chaindata = pack("H*", $hash_m_44_0_r);
- $hash_m_44_0_0 = hash_hmac("sha512" , $hashdata, $chaindata);
- $hash_m_44_0_0_l = substr($hash_m_44_0_0, 0, 64);
- $hash_m_44_0_0_r = substr($hash_m_44_0_0, 64, 64);
- $bitcoinECDSA->setPrivateKey($keym440);
- $finger_m_44_0 = $bitcoinECDSA->getPubKey();
- $finger_m_44_0 = hash('ripemd160', pack("H*", hash('sha256', pack("H*", $finger_m_44_0))));
- $finger_m_44_0 = substr($finger_m_44_0, 0, 8);
- $math = EccFactory::getAdapter();
- $g = EccFactory::getSecgCurves($math)->generator256k1();
- $n = $g->getOrder();
- $Il_dec = $math->hexDec($hash_m_44_0_0_l);
- $private_key_dec = $math->hexDec($keym440);
- $key_dec = $math->mod($math->add($Il_dec, $private_key_dec), $n);
- $keym4400 = str_pad(BitcoinLib::hex_encode($key_dec), 64, '0', STR_PAD_LEFT);
- $data_m_44_0_0 = array(
- 'network' => '0488ade4',
- 'depth' => '03',
- 'fingerprint' => $finger_m_44_0,
- 'i' => '80000000',
- 'chain_code' => $hash_m_44_0_0_r,
- 'key' => '00'.$keym4400,
- );
- $xprivkey_m_44_0_0 = implode($data_m_44_0_0);
- $checksum_m_44_0_0 = hash('sha256', pack("H*", hash('sha256', pack("H*", $xprivkey_m_44_0_0))));
- $checksum_m_44_0_0 = substr($checksum_m_44_0_0, 0, 8);
- $xprivkey_m_44_0_0 = $xprivkey_m_44_0_0 . $checksum_m_44_0_0;
- $base58 = new StephenHill\Base58();
- echo $base58->encode(pack("H*", $xprivkey_m_44_0_0))."<br>";
- // End m/44'/0'/0' derivation
- ?>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement