예제 #1
0
 /**
  * Private Keys To Wallet
  *
  * This function accepts $wallet - a reference to an array containing
  * wallet info, indexed by hash160 of expected address.
  * It will attempt to add each key to this wallet, as well as all the
  * details that could be needed later on: public key, uncompressed key,
  * address, an indicator for address compression. Type is always set
  * to pubkeyhash for private key entries in the wallet.
  *
  * @param array $wallet
  * @param array $wifs
  * @param string $magic_byte
  */
 public static function private_keys_to_wallet(&$wallet, array $wifs, $magic_byte = '00')
 {
     if (count($wifs) > 0) {
         foreach ($wifs as $wif) {
             $key = BitcoinLib::WIF_to_private_key($wif);
             $pubkey = BitcoinLib::private_key_to_public_key($key['key'], $key['is_compressed']);
             $pk_hash = BitcoinLib::hash160($pubkey);
             if ($key['is_compressed'] == TRUE) {
                 $uncompressed_key = BitcoinLib::decompress_public_key($pubkey);
                 $uncompressed_key = $uncompressed_key['public_key'];
             } else {
                 $uncompressed_key = $pubkey;
             }
             $wallet[$pk_hash] = array('type' => 'pubkeyhash', 'private_key' => $key['key'], 'public_key' => $pubkey, 'uncompressed_key' => $uncompressed_key, 'is_compressed' => $key['is_compressed'], 'address' => BitcoinLib::hash160_to_address($pk_hash, $magic_byte));
         }
     }
 }
예제 #2
0
 /**
  * Key To Address
  * 
  * This function accepts a bip32 extended key, and converts it to a 
  * bitcoin address. 
  * 
  * @param	string	$extended_key
  * @param	string	$address_version
  * return	string/FALSE
  */
 public static function key_to_address($extended_key)
 {
     $import = self::import($extended_key);
     if ($import['type'] == 'public') {
         $public = $import['key'];
     } else {
         if ($import['type'] == 'private') {
             $public = BitcoinLib::private_key_to_public_key($import['key'], TRUE);
         } else {
             return FALSE;
         }
     }
     // Convert the public key to the address.
     return BitcoinLib::public_key_to_address($public, $import['version']);
 }