Esempio n. 1
0
 public function recurse_until_unique_bip32_key($bip32_key_row)
 {
     $this->load->model('used_pubkeys_model');
     // Loop until a unique key is found.
     $valid = FALSE;
     while ($valid == FALSE) {
         $new_key = \BitWasp\BitcoinLib\BIP32::build_key($bip32_key_row['key'], $bip32_key_row['key_index']);
         $public_key = \BitWasp\BitcoinLib\BIP32::extract_public_key($new_key);
         // Check that when previously used keys are removed, result is still one (never used before)
         if (count($this->used_pubkeys_model->remove_used_keys(array($public_key))) == 1) {
             $valid = TRUE;
         } else {
             $bip32_key_row['key_index']++;
         }
     }
     return array('parent_extended_public_key' => $bip32_key_row['key'], 'provider' => isset($bip32_key_row['provider']) ? $bip32_key_row['provider'] : 'Manual', 'extended_public_key' => $new_key[0], 'public_key' => $public_key, 'key_index' => $bip32_key_row['key_index']);
 }
 /**
  * get the plain public key for the current BIP32 key
  *
  * @return string
  */
 public function publicKey()
 {
     // if this is a BIP32 Private key then we first build the public key
     //  that way it will be cached nicely
     if (!$this->path->isPublicPath()) {
         return $this->buildKey($this->path->publicPath())->publicKey();
     } else {
         if (is_null($this->publicKey)) {
             $this->publicKey = BIP32::extract_public_key($this->tuple());
         }
         return $this->publicKey;
     }
 }
$wallet[1] = BIP32::master_key('b861e093a58718e145b9791af35fb222');
$wallet[2] = BIP32::master_key('b861e093a58718e145b9791af35fb333');
print_r($wallet);
echo "Now we will generate a m/0' extended key. These will yield a private key\n";
$user[0] = BIP32::build_key($wallet[0][0], "3'");
$user[1] = BIP32::build_key($wallet[1][0], "23'");
$user[2] = BIP32::build_key($wallet[2][0], "9'");
print_r($user);
// As the previous is a private key, we should convert to the corresponding
// public key: M/0'
echo "As the previous is a private key, we should convert it to the corresponding\n";
echo "public key: M/0' \n";
$pub[0] = BIP32::extended_private_to_public($user[0]);
$pub[1] = BIP32::extended_private_to_public($user[1]);
$pub[2] = BIP32::extended_private_to_public($user[2]);
print_r($pub);
echo "This is the key you will ask your users for. For repeated transactions\n";
echo "BIP32 allows you to deterministically generate public keys, meaning less\n";
echo "effort for everyone involved\n\n";
echo "Now we can generate many multisignature addresses from what we have here: \n";
for ($i = 0; $i < 3; $i++) {
    $bip32key[0] = BIP32::build_key($pub[0], "0/{$i}");
    $bip32key[1] = BIP32::build_key($pub[1], "0/{$i}");
    $bip32key[2] = BIP32::build_key($pub[2], "0/{$i}");
    print_r($bip32key);
    $pubkey[0] = BIP32::extract_public_key($bip32key[0]);
    $pubkey[1] = BIP32::extract_public_key($bip32key[1]);
    $pubkey[2] = BIP32::extract_public_key($bip32key[2]);
    print_r($pubkey);
    print_r(RawTransaction::create_multisig(2, $pubkey));
}