Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library generates same wallet with any mnemonic generated #2042

Closed
aditya-stb opened this issue Jul 14, 2022 · 3 comments · Fixed by #2046
Closed

Library generates same wallet with any mnemonic generated #2042

aditya-stb opened this issue Jul 14, 2022 · 3 comments · Fixed by #2046

Comments

@aditya-stb
Copy link

return xrpl.Wallet.fromMnemonic(secret, {
mnemonicEncoding: 'rfc1751',
algorithm: 'ecdsa-secp256k1',
})
}

// light maze exit awful hire ramp trigger will response offer throw hobby
// glue belt debris word submit clump provide organ waste group plunge glory
//frgrfge reer rere reer frerf ergre reer reter erert erret erwre ertrt

SAME Wallet address generated for all these mnemonics :rGzzsoiXsM3RmHU9Fu9eDQ6hoNoouyQiNT

These mnemonics were created using xrpl-accountlib.generate.mnemonic({strength:128})
( https://www.npmjs.com/package/xrpl-accountlib )

@mvadari
Copy link
Collaborator

mvadari commented Jul 14, 2022

Looks like fromMnemonic currently requires words to be all uppercase. This should probably be fixed - the code can just auto-capitalize. Because the lower-case words don't exist in the list of words, the code takes -1 as the index and uses that for all the math, which apparently works out to rGzzsoiXsM3RmHU9Fu9eDQ6hoNoouyQiNT. There should be some checks to ensure that this errors.

However, when these mnemonics are capitalized, it errors, because even the capitalized words are not in the list. I did some digging, and that's because xrpl-accountlib uses the bip39 mnemonic encoding, not the rfc1751 encoding. So that's the problem that you're having.

Are these the results you were expecting?

> secret = "light maze exit awful hire ramp trigger will response offer throw hobby"
> xrpl.Wallet.fromMnemonic(secret, {mnemonicEncoding: 'bip39', algorithm: 'secp256k1'})
Wallet {
  publicKey: '02862A0AEDA41CF3768D7FFA2EB9FA63BCF30E92688C7A977E0F29058C76AB3BB4',
  privateKey: '00F27165AA44A28328D3019943DF71C430D8373FB1050E3B6E7C065BAE21484E22',
  classicAddress: 'rGMY6pCthyTFuT8oW6DCE7v6nRYgiUoiT9',
  seed: undefined
}
###################################
> secret = "glue belt debris word submit clump provide organ waste group plunge glory"
> xrpl.Wallet.fromMnemonic(secret, {mnemonicEncoding: 'bip39', algorithm: 'secp256k1'})
Wallet {
  publicKey: '027F9E3E1B60524ABF02F062FCB09696D16F5401242E74299888CDCDF8127A06DD',
  privateKey: '00AC42D3D631D7602ED2812F03130844B643E9CEFED8F3D2F87446DF7CB0B572D3',
  classicAddress: 'rPWbEnrQr2syRfmb5kubcBukJ9cpjxnz7q',
  seed: undefined
}
###################################
> secret = "frgrfge reer rere reer frerf ergre reer reter erert erret erwre ertrt"
'frgrfge reer rere reer frerf ergre reer reter erert erret erwre ertrt'
> xrpl.Wallet.fromMnemonic(secret, {mnemonicEncoding: 'bip39', algorithm: 'secp256k1'})
Wallet {
  publicKey: '03B89D793961A48320424E95D6641D79102B458C2C19EC013C77CB36F9AC206FC6',
  privateKey: '00D186DB1B5FB757FE1F41BD79DFBCE81831C76AA312F3D3E486030EA085E2AA61',
  classicAddress: 'raLzQmiuDdgmoJzYPMSNck4sm2kXXttVS',
  seed: undefined
}

Action items to make this less opaque:
[ ] Allow lower-case mnemonics
[ ] Better error handling

@aditya-stb
Copy link
Author

aditya-stb commented Jul 15, 2022 via email

@JST5000 JST5000 mentioned this issue Jul 15, 2022
1 task
@JST5000
Copy link
Contributor

JST5000 commented Jul 15, 2022

Hey Aditya, you should be able to use keyToRFC1751Mnemonic to generate a Mnemonic in the same way rippled does. (It's in rfc1751.ts in xrpl.js - If that doesn't work, please let me know :)

I also created #2046 to address the issues around encoding/decoding using an incorrect method. It should now properly error out if you try decoding those keys using rfc1751 since those mnemonics don't follow that format.

@JST5000 JST5000 linked a pull request Jul 18, 2022 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants