I'm trying to implement a wallet reader in node.js. My goal is to move the core wallet RPC server to the node.js server, by implementing the monero-cli wallet decryption code.


Here are some resources I found on the community:

  1. How can I decrypt a Monero wallet to get a private key?
  2. What data do the wallet files contain?
  3. What encryption algorithm is used for the wallet.keys file?

I also looked into the old and current source of the src/wallet/wallet2.cpp file, here are some important lines:

The RPC creates two files (assuming sample is the wallet name):

  • sample (~410 KB)
  • sample.keys (~1.6 KB)
  • They're both encrypted with ChaCha20

Here are some resources on the ChaCha/Salsa algorithms (there aren't plenty online):

Actual question

I'd like to be able to decrypt both files and read the information inside. I currently have only implemented the quarter round and a Buffer to UInt32Array to easily create the constant.

I've made a list of questions I have about the monero/boost implementation:

  1. How is the nonce is generated?
  2. Is the nonce stored? If so, where?
  3. If the key is less then 32 bytes is it padded with 0s, is it repeated/truncated or is it hashed to 32 bytes? If it's hashed, what algorithm is it used?
  4. How is the JSON of the decryted file structured?

PS: I can move it to the cryptographic stackexchange if admins find it more fitting.

1 Answer 1

  1. crypto::rand<crypto::chacha_iv>();
  2. Yes. In the wallet keys file, right at the start (ref).
  3. The chacha key used is a 32 byte hash (ref).
  4. See wallet2::load_keys_buf.

Your Answer

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

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