コード例 #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 = null)
 {
     $magic_byte = BitcoinLib::magicByte($magic_byte);
     if (count($wifs) > 0) {
         foreach ($wifs as $wif) {
             if (is_array($wif) && isset($wif['key'], $wif['is_compressed'])) {
                 $key = $wif;
             } else {
                 $key = BitcoinLib::WIF_to_private_key($wif);
             }
             $pubkey = BitcoinLib::private_key_to_public_key($key['key'], $key['is_compressed']);
             if ($pubkey !== false) {
                 $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
 /**
  * BIP32 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       $wallet
  * @param array $keys
  * @param null  $magic_byte
  */
 public static function bip32_keys_to_wallet(&$wallet, array $keys, $magic_byte = null)
 {
     $magic_byte = BitcoinLib::magicByte($magic_byte);
     RawTransaction::private_keys_to_wallet($wallet, array_map(function ($key) {
         return BIP32::import($key[0]);
     }, $keys), $magic_byte);
 }