1. 程式人生 > >區塊鏈輕錢包nodejs生成本地keystore

區塊鏈輕錢包nodejs生成本地keystore

以下函式接受使用者輸入密碼和傳入keystore的儲存路徑,返回私鑰

    var fs = require("fs");
    var keythereum = require("keythereum");

    function CreateAccount(passwd, path){
        var params = { keyBytes: 32, ivBytes: 16 };
        var dk = keythereum.create(params);
        var options = {
            kdf: "pbkdf2",
            cipher: "aes-128-ctr",
            kdfparams: {
                c: 262144,
                dklen: 32,
                prf: "hmac-sha256"
            }
        };
        var keyObject = keythereum.dump(passwd, dk.privateKey, dk.salt, dk.iv, options);
        keythereum.exportToFile(keyObject, path);
        return dk.privateKey.toString("hex");