Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ async function handleJavascriptPort(arg) {
case "generateKeys": {
const userLang = getUserLanguage();
const [randomWords, hexRandomWords] = mnemonic.generateRandom(userLang);
const privateKey = ecc.seedPrivate(hexRandomWords);
const privateKey = mnemonic.seedPrivate(hexRandomWords);
const publicKey = ecc.privateToPublic(privateKey);

return {
Expand All @@ -690,7 +690,7 @@ async function handleJavascriptPort(arg) {
}
case "getAccountFrom12Words": {
const { passphrase } = arg.data;
const privateKey = ecc.seedPrivate(mnemonic.toSeedHex(passphrase));
const privateKey = mnemonic.seedPrivate(mnemonic.toSeedHex(passphrase));

if (!ecc.isValidPrivate(privateKey)) {
return { error: "error.invalidKey" };
Expand Down
18 changes: 18 additions & 0 deletions src/scripts/mnemonic.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as bip39 from 'bip39'
import { sha256, PrivateKey } from 'eosjs/dist/eosjs-key-conversions'
import { KeyType, privateKeyToString } from 'eosjs/dist/eosjs-numeric'

/***
* Generates a random mnemonic
Expand Down Expand Up @@ -28,11 +30,27 @@ function toSeedHex (mnemonic) {
return bip39.mnemonicToSeedSync(mnemonic).toString('hex')
}

/**
* Derive an EOS private key from a seed string.
*
* Replaces ecc.seedPrivate, which is a no-op stub in eosjs-ecc-migration
* (it only logs "Method deprecated" and returns undefined). Reproduces the
* legacy eosjs-ecc behaviour exactly: PrivateKey(sha256(seed)), returned as a
* legacy WIF string, so keys match what existing accounts registered with.
* @param {string} seed
* @returns {string} legacy WIF private key
*/
function seedPrivate (seed) {
const data = Uint8Array.from(sha256(seed))
return PrivateKey.fromString(privateKeyToString({ type: KeyType.k1, data })).toLegacyString()
}

// =========================================
// Exports
// =========================================

export default {
generateRandom,
toSeedHex,
seedPrivate,
}
Loading