public function testMnemonicDecode()
 {
     $mnemonic = trim('teach start paradise collect blade chill gay childhood creek picture creator branch');
     $known_seed = 'dcb85458ec2fcaaac54b71fba90bd4a5';
     $known_secexp = '74b1f6c0caae485b4aeb2f26bab3cabdec4f0b432751bd454fe11b2d2907cbda';
     $known_mpk = '819519e966729f31e1855eb75133d9e7f0c31abaadd8f184870d62771c62c2e759406ace1dee933095d15e4c719617e252f32dc0465393055f867aee9357cd52';
     $known_addresses = ["", "", "", "", ""];
     $seed = Electrum::decode_mnemonic($mnemonic);
     $this->assertEquals($seed, $known_seed);
     $mpk = Electrum::generate_mpk($seed);
     $this->assertEquals($mpk, $known_mpk);
     $secexp = Electrum::stretch_seed($seed);
     $secexp = $secexp['seed'];
     $this->assertEquals($secexp, $known_secexp);
     $count_known_addresses = count($known_addresses);
     for ($i = 0; $i < $count_known_addresses; $i++) {
         $privkey = Electrum::generate_private_key($secexp, $i, 0);
         $address_private_deriv = BitcoinLib::private_key_to_address($privkey, $this->magic_byte);
         $public_deriv = Electrum::public_key_from_mpk($mpk, $i);
         $address_private_deriv = BitcoinLib::public_key_to_address($public_deriv, $this->magic_byte);
     }
 }
Exemplo n.º 2
0
 /**
  * Get Next Key
  *
  * Loads the next electrum public key from the MPK, and updates the
  * config details.
  *
  * @return    $array
  * @deprecated
  */
 public function get_next_key()
 {
     // Deprecated!
     $i = $this->bw_config->electrum_iteration;
     $public_key = Electrum::public_key_from_mpk($this->bw_config->electrum_mpk, $this->bw_config->electrum_iteration, 0, FALSE);
     if ($public_key == FALSE) {
         return FALSE;
     }
     $this->config_model->update(array('electrum_iteration' => $this->bw_config->electrum_iteration + 1));
     return array('public_key' => $public_key, 'iteration' => $this->bw_config->electrum_iteration);
 }
Exemplo n.º 3
0
<?php

use BitWasp\BitcoinLib\BitcoinLib;
use BitWasp\BitcoinLib\Electrum;
require_once __DIR__ . '/../vendor/autoload.php';
$magic_byte = '00';
$string = trim('teach start paradise collect blade chill gay childhood creek picture creator branch');
$seed = Electrum::decode_mnemonic($string);
echo "Words: {$string}\n";
echo "Seed:  {$seed}\n";
$secexp = Electrum::stretch_seed($seed);
$secexp = $secexp['seed'];
echo "Secret Exponent: {$secexp}\n";
$mpk = Electrum::generate_mpk($seed);
echo "MPK: {$mpk}\n";
for ($i = 0; $i < 5; $i++) {
    $privkey = Electrum::generate_private_key($secexp, $i, 0);
    echo "Private key: {$privkey}\n";
    echo "Private WIF: " . BitcoinLib::private_key_to_WIF($privkey, FALSE, $magic_byte) . "\n";
    $public_key = Electrum::public_key_from_mpk($mpk, $i);
    echo "Public Key: {$public_key}\n";
    $address = BitcoinLib::public_key_to_address($public_key, $magic_byte);
    echo "Public derivation: {$address}.\n";
    $address = BitcoinLib::private_key_to_address($privkey, $magic_byte);
    echo "Private derivation: {$address}.\n";
    echo "-----------\n";
}
$seed = $seed['seed'];
$master_public_key = Electrum::generate_mpk($seed);
$private_keys = array();
$have_keys = 0;
$done = FALSE;
// Loop until the user is satisfied they have found all keys.
$j = 0;
$offset = 30;
while ($done == FALSE) {
    $start = $offset * $j;
    echo "Trying keys {$start} to " . ($start + $offset) . "\n";
    // Do public derivation to learn which private keys to derive.
    for ($i = $start; $i < $start + $offset; $i++) {
        $pubkey = Electrum::public_key_from_mpk($master_public_key, $i);
        if (in_array($pubkey, $decode_redeem_script['keys'])) {
            $private_keys[] = BitcoinLib::private_key_to_WIF(Electrum::generate_private_key($seed, $i), FALSE, '00');
            $have_keys++;
        }
        if ($have_keys == $decode_redeem_script['m']) {
            $done = TRUE;
            break;
        }
    }
    $j++;
    // See if we should continue searching.
    $ask = FALSE;
    if ($done == FALSE) {
        echo "Have " . count($private_keys) . " private keys we can sign with. Look for more? (y/n) ";
        while ($ask == FALSE) {
            switch (trim(fgets(STDIN))) {
                case 'y':
<?php

use BitWasp\BitcoinLib\Electrum;
require_once __DIR__ . '/vendor/autoload.php';
$mpk = 'eee6754303a65aa693a459269c8deb55e02e2d03ed427ae4ac498d7ab18f30844e53c10cd84faf2d1cac68da135279a6076c5770934e20651624db6bd72f1670';
echo "Uncompressed Keys: \n";
for ($i = 0; $i < 40; $i++) {
    echo "- " . Electrum::address_from_mpk($mpk, $i, '00', 0, FALSE) . "\n";
}
echo "\n";
echo "Compressed Keys: \n";
for ($i = 0; $i < 40; $i++) {
    echo "- " . Electrum::address_from_mpk($mpk, $i, '00', 0, TRUE) . "\n";
}