Skip to content
Permalink
Browse files

[DEVOPS-1195] make the wallet-extractor more verbose

  • Loading branch information...
cleverca22 committed Mar 12, 2019
1 parent d7ff59c commit c43888adde4a19f7f2054eb8b92fec09632aedc8
Showing with 40 additions and 6 deletions.
  1. +1 −0 nix/.stack.nix/cardano-sl-tools.nix
  2. +6 −2 tools/cardano-sl-tools.cabal
  3. +33 −4 tools/src/wallet-extractor/Main.hs

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -383,10 +383,14 @@ executable wallet-extractor
-Wall
-O2
build-depends: base
, universum
, text
, bytestring
, cardano-crypto
, cardano-sl
, cardano-sl-crypto
, cardano-sl-util
, formatting
, text
, universum

test-suite cardano-sl-tools-test
main-is: Test.hs
@@ -1,11 +1,36 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}

module Main (main) where

import qualified Data.Text as T
import Pos.Util.Trace (fromTypeclassWlog)
import Pos.Util.UserSecret
import Universum
import Pos.Crypto (EncryptedSecretKey(eskPayload, eskHash), getEncryptedPass)
import Cardano.Crypto.Wallet (unXPrv)
import Formatting (bprint, hex, shown, (%), fprint, Format, later)
import qualified Data.ByteString as BS
import qualified Data.Text.Lazy.Builder as T
import Formatting.Internal.Raw (left)

hexString :: Format r (ByteString -> r)
hexString = later f
where
f :: ByteString -> T.Builder
f bs = foldl' f2 "" $ BS.unpack bs
f2 :: T.Builder -> Word8 -> T.Builder
f2 str byte = str <> (left 2 '0' (bprint hex byte))

extract :: EncryptedSecretKey -> FilePath -> IO ()
extract esk path = do
let
(epriv,remain) = BS.splitAt 64 $ unXPrv $ eskPayload esk
(pub,chaincode) = BS.splitAt 32 remain
fprint ("XPrv: " % hexString % ", pub: " % hexString % ", CC: " % hexString % "\n") epriv pub chaincode
fprint ("pass hash: " % shown % "\n") (getEncryptedPass $ eskHash esk)
let
newkey = (defaultUserSecret & usWallet .~ Just (WalletUserSecret esk "exported key" [] [])) & usPath .~ path
writeUserSecret newkey

main :: IO ()
main = do
@@ -15,6 +40,10 @@ main = do
zero :: Int
zero = 0
forM_ (zip (view usKeys originalKey) [zero..]) $ \(key, x) -> do
let
newkey = (defaultUserSecret & usWallet .~ Just (WalletUserSecret key (T.pack "head key") [] [])) & usPath .~ ("output-" <> show x <> ".key")
writeUserSecret newkey
fprint ("extracting key#" % shown % "\n") x
extract key ("output-" <> show x <> ".key")
case (view usWallet originalKey) of
Nothing -> fprint "no wallet key"
Just key -> do
fprint "extracting wallet key"
extract (view wusRootKey key) "output-wallet.key"

0 comments on commit c43888a

Please sign in to comment.
You can’t perform that action at this time.