Emurgo / csl-mobile-bridge

React-native bindings for Emurgo's cardano-serialization-lib (Cardano haskell Shelley)
MIT License
23 stars 12 forks source link

Mnemonics to Shelley Address #87

Closed munishantier closed 1 year ago

munishantier commented 1 year ago

How can I create a shelley address from mnemonics using react-native-haskell-shelley npm? I can't see any test case related to mnemonics.

lisicky commented 1 year ago

Hi @munishantier! CSL does not provide a function for a creation address from mnemonic phrase. But you can use third party lib, you can find an example on this page (see BIP39 Entropy) https://github.com/Emurgo/cardano-serialization-lib/blob/master/doc/getting-started/generating-keys.md

munishantier commented 1 year ago

var lib = require('cardano-crypto.js')

var mnemonic = 'logic easily waste eager injury oval sentence wine bomb embrace gossip supreme' var parentWalletSecret = lib.mnemonicToRootKeypair(mnemonic, 1) var parentWalletPublicKey = parentWalletSecret.slice(64, 128) var childWalletSecret = lib.derivePublic(parentWalletPublicKey, 1, 1)

I have used above code to create a key pair but I am not sure how to proceed further. How to create a base address from it?

lisicky commented 1 year ago

@munishantier are you sure that you use react-native-haskell-shelley or cardano serialization lib ? By the link above there are examples how you can create root key from mnemonic phrase, how you can derive it and how you can create different addresses types

munishantier commented 1 year ago

Thank you @lisicky, But now problem with address. Trust wallet generate different address from our address with same mnemonics. I'm using networkId: 764824073

lisicky commented 1 year ago

@munishantier Could you provide code examples of generating the address in both cases? Actual network id you can get from NetworkInfo, there are testnet_preview(), testnet_preprod(), mainnet() functions that returns an actual version of NetworkInfo. From NetworkInfo you can get protocol magic and network id by network_id and protocol_magic. 764824073 is protocol magic for the mainnet in our codebase. Depending on which address you are creating, you should use protocol magic or network id (you can see examples in the link that I already gave).

munishantier commented 1 year ago

Yes i found thanks for your help