0

Is there a easy javascript way to convert a private key into a 24 word mnemonic seed? I understand that Monero private keys are generated using Base58, but where in code does it show me how to convert a private key to a mnemonic seed? I'm guessing I also need Monero's mnemonic seed dictionary list?

1

1 Answer 1

1

https://github.com/moneromooo-monero/monero-wallet-generator includes Javascript code to create a 25 word seed from a secret key. You can then chop off the last word to get a 24 word seed, since the last word is the checksum and is optional.

Specifically, you want the mn_encode function:

function mn_encode(str, wordset_name) {
    'use strict';
    wordset_name = wordset_name || mn_default_wordset;
    var wordset = mn_words[wordset_name];
    var out = [];
    var n = wordset.words.length;
    for (var j = 0; j < str.length; j += 8) {
        str = str.slice(0, j) + mn_swap_endian_4byte(str.slice(j, j + 8)) + str.slice(j + 8);
    }
    for (var i = 0; i < str.length; i += 8) {
        var x = parseInt(str.substr(i, 8), 16);
        var w1 = (x % n);
        var w2 = (Math.floor(x / n) + w1) % n;
        var w3 = (Math.floor(Math.floor(x / n) / n) + w2) % n;
        out = out.concat([wordset.words[w1], wordset.words[w2], wordset.words[w3]]);
    }
    if (wordset.prefix_len > 0) {
        out.push(out[mn_get_checksum_index(out, wordset.prefix_len)]);
    }
    return out.join(' ');
}

The words list and the helper functions it calls are in the same file.

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.