diff --git a/composer.json b/composer.json index 14c765a..fa22209 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "block_io-php/block_io-php", "license": "MIT", - "version": "1.1.1", + "version": "1.1.2", "description": "Block.io is the easiest way to create wallets, send, and accept payments through Bitcoin, Litecoin, and Dogecoin. This is its PHP library.", "keywords": ["block.io", "dogecoin", "bitcoin", "litecoin", "block_io"], "homepage": "https://block.io", diff --git a/lib/block_io.php b/lib/block_io.php index db18ed2..8174c3e 100644 --- a/lib/block_io.php +++ b/lib/block_io.php @@ -311,6 +311,7 @@ class BlockKey public $n; public $G; public $networkPrefix; + public $c = true; //compressed or not public function __construct() { @@ -992,12 +993,21 @@ public function getPublicKey() */ public function getPubKey() { - $pubKey = $this->getPubKeyPoints(); + $pubKey = ""; - if(gmp_strval(gmp_mod(gmp_init($pubKey['y'], 16), gmp_init(2, 10))) == 0) - $pubKey = '02' . $pubKey['x']; //if $pubKey['y'] is even - else - $pubKey = '03' . $pubKey['x']; //if $pubKey['y'] is odd + if ($this->c) + { // compressed + $pubKey = $this->getPubKeyPoints(); + + if(gmp_strval(gmp_mod(gmp_init($pubKey['y'], 16), gmp_init(2, 10))) == 0) + $pubKey = '02' . $pubKey['x']; //if $pubKey['y'] is even + else + $pubKey = '03' . $pubKey['x']; //if $pubKey['y'] is odd + } + else + { // uncompressed + $pubKey = $this->getUncompressedPubKey(); + } return $pubKey; } @@ -1093,6 +1103,15 @@ public function fromWif($pp) $this->setPrivateKey($withoutChecksumAndVersion); + if (substr($withoutVersion,64,2) == '01') + { // is compressed + $this->c = true; + } + else + { // is not compressed + $this->c = false; + } + return $this; }