BitcoinPHP / BitcoinECDSA.php

PHP library to generate BTC addresses and signatures from private keys.
222 stars 106 forks source link

WIF is not readable by Mycelium wallet #32

Closed gaurav-chandra closed 7 years ago

gaurav-chandra commented 7 years ago

Here are the details of the wallet:

ADDRESS : 1GRTPtfbTk2oTfnrDhXajvmCHpEeJxWr7H
WIF : nvcAtj5QiQprwWQk6LW6gDVMxQGmvJsXjZU5qmndRjL83ZJGEK5
Private Key : ba24185ce261850993e13ff7f0ad2ab01d418b0f48534880ea33e304cb388b9d

When I am entering or scanning the qr code for WIF, the mycelium wallet app is not detecting it as valid.

I imported the Private Key in blockchain.info wallet, it was a success. Then I generated the WIF from their interface, the WIF generated was different:

L3TYYUQPQ6FjP2sCkfUjF48JP2jKRYwZJTJNaoB8tFfisYYmNJHp

and mycelium could read this format successfully.

What am I missing? Thanks.

rgex commented 7 years ago

I'll take a look at it later today.

gaurav-chandra commented 7 years ago

I did some tweaking and found:

public function getWif()
    {
        if(!isset($this->k))
        {
            throw new \Exception('No Private Key was defined');
        }

        $k              = $this->k;
        $secretKey      = '80' . $k;
        $secretKey     .= substr($this->hash256(hex2bin($secretKey)), 0, 8);

        //return strrev($this->base58_encode($secretKey));
// if I remove strrev, then the WIF generated is readable by Mycelium
        return ($this->base58_encode($secretKey));
    }

But the above change, changes the Bitcoin address from

13GZGS96Ui9CuudonrfuQ1CeCcSkHQkt2v

to Uncompressed Address

1HxrEkR2wpoyVVT9QgmkhjCihSCVYoWiPo

in mycelium app.