Skip to content

Commit

Permalink
handle uncompressed keys properly
Browse files Browse the repository at this point in the history
  • Loading branch information
doersf committed Jan 20, 2015
1 parent 5719a07 commit 7cc8051
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
29 changes: 24 additions & 5 deletions lib/block_io.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ class BlockKey
public $n;
public $G;
public $networkPrefix;
public $c = true; //compressed or not

public function __construct()
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 7cc8051

Please sign in to comment.