Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is private key and signing key for cardano (ada)?

I'm trying to generate address and create transaction using nodejs and @emurgo/cardano-serialization-lib-nodejs lib (CardanoWasm). Following the docs I'm trying this:

const rootkey = CardanoWasm.Bip32PrivateKey.from_bip39_entropy(
  Buffer.from(someEntropy, 'hex'), // entropy is generated from mnemonic
  Buffer.from('')
);

const account = rootkey
  .derive(harden(1852)) // harden is a function returning 0x80000000+arg
  .derive(harden(1815))
  .derive(harden(0));

const utxokey = account
  .derive(0)
  .derive(0)
  .to_public();

const stake1 = account
  .derive(2)
  .derive(0)
  .to_public();

const address = CardanoWasm.BaseAddress.new(
   CardanoWasm.NetworkInfo.mainnet().network_id(),
   CardanoWasm.StakeCredential.from_keyhash(utxokey.to_raw_key().hash()),
   CardanoWasm.StakeCredential.from_keyhash(stakekey.to_raw_key().hash())
);

const addressBech32 = address.to_address().to_bech32();

So in my example addressBech32 is an actual public address of a wallet. When I import the wallet to the guarda (for example) by mnemonic it works fine. But what is actually rootkey and account? What is private key and signing key in my example? What key should i use to sign the transaction and how to get that key using cardano wasm? What private key should I use to import the wallet (if I don't want to use mnemonic for some reason)?

like image 895
stphddl Avatar asked Feb 09 '21 10:02

stphddl


People also ask

Is signing key same as private key?

They're basically the same. If you can sign-off on transactions on your pool using a variety of keys, then you don't want the public to get hold of those keys, so you want to keep them private. Public keys, on the other hand, cannot be used to sign transactions with. You want to keep signing keys private.

What is the Cardano wallet public key?

The public key is used as an address on which some ADA can be sent. The corresponding paired private key is used to spend the ADA coins from the address. You can imagine that a public key is an account and a private key is a password needed to spend coins.

What are Cardano keys and addresses?

Creating keys and addresses In the Shelley era of Cardano, every stakeholder can have two sets of keys and addresses: Payment Keys and addresses: To send and receive transactions Stake Keys and addresses: To control protocol participation, create a stake pool, delegate and receive rewards.

What is Cardano (Ada)?

Cardano has a difference from Bitcoin, which public node uses the Proof of Work algorithm , and Ethereum, which public node uses a combination of Proof of Work and Proof of Stake algorithms. Cardano node confirms transactions by relying on the Proof of Stake algorithm.

How do epochs work in Cardano (Ada)?

Each epoch takes about 5 days. Each time it is a randomly determined ADA node which receives a reward. To do this, the ADA node is selected among the participants of one slot. The size of the reward for the Cardano node, which to date is 2000 ADA, will be gradually reduced to zero.

How does Cardano node confirm transactions?

Cardano node confirms transactions by relying on the Proof of Stake algorithm. Cardano has two levels: on the first level, free nodes united in a blockchain, on the second level, decentralized smart contracts.


2 Answers

When I import the wallet to the guarda (for example) by mnemonic it works fine. But what is actually rootkey and account?

rootKey is a representation of your xpriv, your master private key from which all staking and spending, private and public keys are generated from.

The process for generating staking and signing keys is described in CIP-0003, basically piggybacking off the Bitcoin BIP32 and BIP44 standard.

In short, the scheme allows a master key to be used to generate a number of separate wallet 'accounts'. In your example:

const account = rootkey
  .derive(harden(1852)) // harden is a function returning 0x80000000+arg
  .derive(harden(1815))
  .derive(harden(0));

generates the private key for Cardano account zero.

Going further:

account
  .derive(0)     # external chain (designated for receive addresses)
  .derive(0);    # index (the first address)

would generate a private key for receive address zero in that account.

What is private key and signing key in my example? What key should i use to sign the transaction and how to get that key using cardano wasm?

Your example creates a bech32 address for (Cardano account 0) receive address 0. So the private key to spend from this address would be the same as the above:

const utxo_privkey = account
  .derive(0)
  .derive(0); 

What private key should I use to import the wallet (if I don't want to use mnemonic for some reason)?

You can supply the entropy as bytes, as you have done in your example for rootKey, or you can use a bech32 encoded private key like so:

const rootKey = CardanoWasm.BIP32PrivateKey.from_bech32("xprv17qx9vxm6060qjn5fgazfue9nwyf448w7upk60c3epln82vumg9r9kxzsud9uv5rfscxp382j2aku254zj3qfx9fx39t6hjwtmwq85uunsd8x0st3j66lzf5yn30hwq5n75zeuplepx8vxc502txx09ygjgx06n0p");
like image 139
soccer193 Avatar answered Oct 22 '22 04:10

soccer193


May look at the Cardano Shelley address style documentation https://input-output-hk.github.io/cardano-addresses/haddock/cardano-addresses-3.2.0/Cardano-Address-Style-Shelley.html#g:2

like image 25
Markus G Avatar answered Oct 22 '22 05:10

Markus G