public function testValidatePublicKey()
 {
     $cnt = (getenv('BITCOINLIB_EXTENSIVE_TESTING') ?: 1) * 2;
     for ($i = 0; $i < $cnt; $i++) {
         $set = BitcoinLib::get_new_key_set($this->addressVersion);
         $this->assertTrue(BitcoinLib::validate_public_key($set['pubKey']));
     }
 }
 /**
  * Check Bitcoin Public Key
  *
  * Passes the input to the BitcoinLib library which tries to create
  * a valid point on the secp256k1 curve.
  *
  * @param        string $str
  * @return        boolean
  */
 public function check_bitcoin_public_key($str)
 {
     return \BitWasp\BitcoinLib\BitcoinLib::validate_public_key($str);
 }
예제 #3
0
 public static function import($ext_key)
 {
     $hex = BitcoinLib::base58_decode($ext_key);
     $key = [];
     $key['magic_bytes'] = substr($hex, 0, 8);
     $magic_byte_info = self::describe_magic_bytes($key['magic_bytes']);
     // Die if key type isn't supported by this library.
     if ($magic_byte_info == false) {
         throw new \InvalidArgumentException("Unsupported magic byte");
     }
     $key['type'] = $magic_byte_info['type'];
     $key['testnet'] = $magic_byte_info['testnet'];
     $key['network'] = $magic_byte_info['network'];
     $key['version'] = $magic_byte_info['version'];
     $key['depth'] = gmp_strval(gmp_init(substr($hex, 8, 2), 16), 10);
     $key['fingerprint'] = substr($hex, 10, 8);
     $key['i'] = substr($hex, 18, 8);
     $key['address_number'] = self::get_address_number($key['i']);
     $key['chain_code'] = substr($hex, 26, 64);
     $key['is_compressed'] = true;
     if ($key['type'] == 'public') {
         $key_start_position = 90;
         $offset = 66;
     } else {
         $key_start_position = 92;
         $offset = 64;
     }
     $key['key'] = substr($hex, $key_start_position, $offset);
     if (!in_array($key['type'], ['public', 'private'])) {
         throw new \InvalidArgumentException("Invalid type");
     }
     // Validate obtained key
     if ($key['type'] == 'public' && !BitcoinLib::validate_public_key($key['key'])) {
         throw new \InvalidArgumentException("Invalid public key");
     }
     if ($key['type'] == 'private' && !self::check_valid_hmac_key($key['key'])) {
         throw new \InvalidArgumentException("Invalid private key");
     }
     return $key;
 }