Key generation
The minimal JavaScript code used to generate a private key from password and passcode inputs is shown below. You can generate your private key directly without using mybucks.online.
Here, the password is a traditional input that must be at least 12 characters long and include a combination of lowercase letters, uppercase letters, numbers, and special characters. The passcode is a shorter input, at least 6 characters long, used to prevent account duplication due to password reuse and also as a confirmation for secure areas.
import { Buffer } from "buffer";
import { ethers } from "ethers";
import { scrypt } from "scrypt-js";
const HASH_OPTIONS = {
N: 32768, // CPU/memory cost parameter, 2^15
r: 8, // block size parameter
p: 5, // parallelization parameter
keyLen: 64,
};
async function generatePrivateKey(password, passcode) {
const salt = password.slice(-4) + passcode
const passwordBuffer = Buffer.from(password);
const saltBuffer = Buffer.from(salt);
const hashBuffer = await scrypt(
passwordBuffer,
saltBuffer,
HASH_OPTIONS.N,
HASH_OPTIONS.r,
HASH_OPTIONS.p,
HASH_OPTIONS.keyLen,
(p) => console.log(Math.floor(p * 100))
);
const hashHex = Buffer.from(hashBuffer).toString("hex");
const privateKey = ethers.keccak256(abi.encode(["string"], [hashHex]));
return privateKey;
}
Find on Github
You can find the code here. You can download the repository and execute it on your local machine as a backup for account generation.
Last updated