Skip to content

Commit

Permalink
Fixed testnet WIF format bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yfgeek committed Aug 8, 2017
1 parent 7356fdd commit 9eb7142
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/BitcoinPHP/BitcoinECDSA/BitcoinECDSA.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ public function getNetworkPrefix()
return $this->networkPrefix;
}

/**
* Returns the current network prefix for WIF, '80' = main network, 'ef' = test network.
*
* @return string (hexa)
*/
public function getPrivatePrefix(){
if($this->networkPrefix =='6f')
return 'ef';
else
return '80';
}

/***
* Permutation table used for Base58 encoding and decoding.
*
Expand Down Expand Up @@ -825,7 +837,7 @@ public function getWif($compressed = true)
while(strlen($k) < 64)
$k = '0' . $k;

$secretKey = '80' . $k;
$secretKey = $this->getPrivatePrefix() . $k;

if($compressed) {
$secretKey .= '01';
Expand Down

1 comment on commit 9eb7142

@AndreyArhipov
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok!
How can you achieve generation of these formats along with what you have implemented? good easy script
m/44'/0'/0'/0 m/49'/0'/0'/0 m/84'/0'/0'/0 Bip141 m/0

Please sign in to comment.