From 9eb71426cb8602aaaa0be9c7f809eed78a658014 Mon Sep 17 00:00:00 2001 From: Ivan Date: Tue, 8 Aug 2017 21:07:20 +0100 Subject: [PATCH] Fixed testnet WIF format bug --- src/BitcoinPHP/BitcoinECDSA/BitcoinECDSA.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/BitcoinPHP/BitcoinECDSA/BitcoinECDSA.php b/src/BitcoinPHP/BitcoinECDSA/BitcoinECDSA.php index 8cce560..61da0f2 100644 --- a/src/BitcoinPHP/BitcoinECDSA/BitcoinECDSA.php +++ b/src/BitcoinPHP/BitcoinECDSA/BitcoinECDSA.php @@ -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. * @@ -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';