Forum Home
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Popular

    Import private key

    Technical Development
    4
    6
    4184
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      Kevlar Spammer last edited by

      It seems like it would be a really good idea to incorporate re-versioning of private keys via the importprivkey directly into the client.

      I’ve written this code in python, but it should be pretty straight forward for someone to reproduce it in C++ and the QT client.

      The problem is the private key format has the wrong version. But this can be fixed.

      The code in python is here:
      https://github.com/hank/life/blob/master/code/python/cryptcoin_addr_convert/convert.py

      And the relevant steps in plain English are as follows:

      Goal: Turn the privkey import format back into the private key.
      Step 1: b58decode(wifpriv)
      Step 2: strip the last 4 characters off the end of step 1 (checksum).
      Step 3: strip the first character off the end of step 2 (version).

      Goal: Turn the private key back into an importable private key format with correct version
      Step 1: Concatenate version and private key. (0x8E for FTC). (version)
      Step 2: sha256(step1)
      Step 3: sha256(step2)
      Step 4: Concatenate step 1 and the last 4 characters of step 3. (checksum)
      Step 5: b58encode(step4)

      Since this code is all already in the C++ QT client, it should be pretty easy to adopt it while removing the check on the version. Or maybe just do that: remove the check on the version, since that would accomplish the same thing.

      Thoughts?

      1 Reply Last reply Reply Quote 0
      • kris_davison
        kris_davison last edited by

        yes good idea I guess if the first pass at importprivkey fails with a code 5 (Invalid KEY) then you could give it another go after passing through your code.

        1 Reply Last reply Reply Quote 0
        • wrapper
          wrapper Moderators last edited by

          Sounds great, I’d like to look into that, once I get my head round it.

          1 Reply Last reply Reply Quote 0
          • K
            Kevlar Spammer last edited by

            The code that’s throwing the error is here:
            https://github.com/FeatherCoin/Feathercoin-0.8.5/blob/6c960b106c1f17c61d1860a45010188b169398e4/src/base58.h

            There’s an enum of version numbers there, and when CBase58Data::SetString is called the version gets coppied…

            [quote]
            bool SetString(const char* pszSecret)
            {
            return CBase58Data::SetString(pszSecret) && IsValid();
            }
            [/quote]

            and because the version is wrong IsValid returns false.

            But I think it should be handled at a higher level, namely in src/rpcdump.cpp, line 35, importprivkey(…).

            Am I close?

            1 Reply Last reply Reply Quote 0
            • Wellenreiter
              Wellenreiter Moderators last edited by

              I’d go for a simple warning, when the version isn’t correct and give the user a selection whether to import or not.

              Another possibility could be to validate against a list of valid versions?

              This would have the advantage, that in future times, privated keys with very old versions could be rejected, e.g. if they are known to be vulnerable.

              I’m not deep into the code, so I’m not sure if this can be implemented easy

              Feathercoin development donation address: 6p8u3wtct7uxRGmvWr2xvPxqRzbpbcd82A
              Openpgp key: 0x385C34E77F0D74D7 (at keyserver.ubuntu.com)/fingerprint: C7B4 E9EA 17E1 3D12 07AB 1FDB 385C 34E7 7F0D 74D7

              1 Reply Last reply Reply Quote 0
              • wrapper
                wrapper Moderators last edited by

                Bitcoin Worth £4.6 Million Is Buried Under A Landfill In South Wales

                [url=http://www.huffingtonpost.co.uk/2013/11/27/bitcoin-buried-wales-46-million_n_4350267.html]http://www.huffingtonpost.co.uk/2013/11/27/bitcoin-buried-wales-46-million_n_4350267.html[/url]

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post