6

Checking the official documentation from cardano-wallet I can see that there are options to get wallets from mnemonics and extended public keys, but not private keys.

Even public libs don't have that option. And as far as I know it's not possible to restore a wallet from a private key in Daedalus or Yoroi.

It's a somewhat simple functionality that I can't find any info about!

1 Answer 1

6

A robust way to do that is to use cardano-wallet CLI.

First of all, run cardano-wallet serve and cardano-node.

Root Key

The command that helps us writing a root private key into a file should look like this:

cardano-wallet recovery-phrase generate --size 18 \ 
    | cardano-wallet key from-recovery-phrase Shelley > secretKey.prv

It results in private key creation that might look like this:

root_xsk1vrv54w0rpg6j9qz54ed48hjf99k0qt7p4wu5l3y55tlpk8684dphx6a8xw82u3vsgwcv6n8mdxwczhfhusy22eknmdpjn9lnyram0alqaa7mwjx4rg0eyh3ckv0el34j5vswquzhvrpaze6ju6s623fs4ylx346v

Derivation Path

m / purpose' / coin_type' / account_index' / role / address_index

If you tap a 20th receiving address in Daedalus wallet you'll see the following path:

m / 1852H / 1815H / 0H / 0 / 19

where 1852 is a hardened Shelley-era address type, and 1815 is hardened ADA's index.

Account Keys

According to this scheme let's create account private key and account public key:

cat secretKey.prv \
    | cardano-wallet key child 1852H/1815H/0H \
    | tee account.prv \
    | cardano-wallet key public --with-chain-code > account.pub

These results are:

acct_xsk10ra048lvz7le0y5pkmqmceuf492u64nv8edk9qsh3036jtz84dp3xqns35edmhag0nke3xmhm87368v8mtr5d2ryd3ucjgg6e5vjf7r8eu4ejhpyax2us59c73pt7sduvddy934k8p925xxsqvc2hh8nnug24fq6

...

acct_xvk1fpqtkwf8yy5rn3f79a4vr4fpd9rxxfheursjzqw8kgj0qf3q98ux0netn9wzf6v4epgt3azzhaqmcc66gtrtvwz24gvdqqes40w088c36lqsu

Create a wallet

cardano-wallet wallet create from-public-key < 128-bit hash of acct pub key >

Additional reading

If you need more details on Cardano CLI, please read my Medium stories:

2
  • 1
    That's for sure helpful. So I'd just start from the second step since I already have the private key. However, the question was geared towards achieving the same result programmatically, without the necessity of running a node or bash commands.
    – Tengu
    Oct 6, 2021 at 15:49
  • It entirely depends on the framework for the language in which you are developing. Many frameworks are in development at the moment. I personally use Swift – there are no any Cardano libs for Swift, except this one: thecardanofund.com/product/cardano-swift-sdk
    – Andy Jazz
    Oct 6, 2021 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.