示例#1
0
function pubkeyHashToAddress($pubkey, $addrver = 73)
{
    $pubkey = $addrver . $pubkey;
    $pubkeybs = pack("H*", $pubkey);
    $checksum = hash("sha256", hash("sha256", $pubkeybs, true));
    $checksum = substr($checksum, 0, 8);
    $pubkey .= $checksum;
    return BaseConvert::hex_base58($pubkey);
}
 /**
  * @depends testDec_hex
  * @depends testBase58_dec
  */
 public function testHex_base58()
 {
     $hex = "11FD6";
     $result = BaseConvert::hex_base58($hex);
     $this->assertEquals($result, "NuT");
 }
示例#3
0
 public static function pubkeyHashToAddress($pubkey)
 {
     $pubkey = self::$addrver . $pubkey;
     // Prepend version byte
     $pubkeybs = pack("H*", $pubkey);
     // Pack to raw bytestring
     $checksum = hash("sha256", hash("sha256", $pubkeybs, true));
     // Calculate checksum
     $checksum = substr($checksum, 0, 8);
     // Shorten to 4 bytes
     $pubkey .= $checksum;
     // Append checksum to pubkey hash
     return BaseConvert::hex_base58($pubkey);
     // Convert to base 58 and return
 }