Beispiel #1
0
 /**
  * Encode
  * 
  * This function accepts an array of information describing the 
  * extended key. It will determine the magic bytes depending on the
  * network, testnet, and type indexes. The fingerprint is accepted
  * as-is, because the CKD() and master_key() functions work that out
  * themselves. The child number is fixed at '00000000'. Private key's 
  * are padded with \x00 to ensure they are 33 bytes. This information
  * is concatenated and converted to base58check encoding.
  * The input array has the same indexes as the output from the import() 
  * function to ensure compatibility.
  * 
  * @param	array	$data
  * @return	string
  */
 public static function encode($data)
 {
     // Magic Byte - 4 bytes / 8 characters - left out for now
     $magic_byte_var = strtolower($data['network']) . "_" . ($data['testnet'] == TRUE ? 'testnet' : 'mainnet') . "_{$data['type']}";
     $magic_byte = self::${$magic_byte_var};
     $fingerprint = $data['fingerprint'];
     $child_number = $data['i'];
     $depth = str_pad(gmp_strval(gmp_init($data['depth'], 10), 16), 2, '0', STR_PAD_LEFT);
     $chain_code = $data['chain_code'];
     $key_data = $data['type'] == 'public' ? $data['key'] : '00' . $data['key'];
     $string = $magic_byte . $depth . $fingerprint . $child_number . $chain_code . $key_data;
     return BitcoinLib::base58_encode_checksum($string);
 }