XRPLF / xrpl.js

A JavaScript/TypeScript API for interacting with the XRP Ledger in Node.js and the browser
https://xrpl.org/
1.2k stars 511 forks source link

How do I generate ripple secret from mnemonic seed words ? #1025

Closed rahuldamodar94 closed 4 years ago

rahuldamodar94 commented 5 years ago

How do I generate ripple secret from mnemonic seed words ? I am able to generate the public and private key pair. I am also able to do payment. But how do I retrieve the secret ? I need this secret so that I can import my ripple account to another wallet.

const RippleAPI = require('ripple-lib').RippleAPI; const bip39 = require("bip39"); const bip32 = require("ripple-bip32"); const ripple = require('ripplelib')

var generate = function() { mnemonic = bip39.generateMnemonic()

const seed = bip39.mnemonicToSeed(mnemonic)
const m = bip32.fromSeedBuffer(seed)
const keyPair = m.derivePath("m/44'/144'/0'/0/0").keyPair.getKeyPairs()
const key = ripple.KeyPair.from_json(keyPair.privateKey.substring(2))
console.log('privateKey: ' + keyPair.privateKey)
console.log('privateKeyWif: ' + key.to_pri_string()) // to_wif
console.log('publicKey: ' + keyPair.publicKey)
console.log('address: ' + key.to_address_string())

}

generate();

intelliot commented 5 years ago

If you generated your key pair from mnemonic seed words, you probably do not have a secret. Thus, it is unlikely that you'll be able to import your account to another wallet if that wallet requires a secret. The wallet may need to add support for importing a private key (or mnemonic).

Which wallet is it?

Learn more: https://xrpcommunity.blog/keys-are-key-secret-keys-signing-transactions/

rahuldamodar94 commented 5 years ago

If you generated your key pair from mnemonic seed words, you probably do not have a secret. Thus, it is unlikely that you'll be able to import your account to another wallet if that wallet requires a secret. The wallet may need to add support for importing a private key (or mnemonic).

Which wallet is it?

Learn more: https://xrpcommunity.blog/keys-are-key-secret-keys-signing-transactions/

I am creating a wallet in which addresses are generated for users using the seed words. So its not possible to get the secret key if i am creating key pairs using mnemonic seed words ?

intelliot commented 5 years ago

There is no secret (starting with s...), so the wallet that you want to use must have support for importing a private key instead. Which wallet is it?

Alternatively, you can generate a new secret and use it to generate a public key to use as your account's regular key, but then the wallet must have support for regular keys.