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.
Resources
Here are some resources I found on the community:
- How can I decrypt a Monero wallet to get a private key?
- What data do the wallet files contain?
- 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:
- generate()
- load
- information initially wasn't stored as JSON
- generate_chacha_key_from_secret_keys and generate_chacha_key_from_password
- ChaCha8 is still supported, but ChaCha20 is the new default
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):
- https://cr.yp.to/snuffle/salsafamily-20071225.pdf
- https://cr.yp.to/chacha/chacha-20080128.pdf
- Salsa20 - Wikipedia (has ChaCha as well)
- ChaCha test vectors
- Chacha Cipher - Computerphile
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:
- How is the nonce is generated?
- Is the nonce stored? If so, where?
- 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?
- How is the JSON of the decryted file structured?
PS: I can move it to the cryptographic stackexchange if admins find it more fitting.