How to use the bitsharesjs.PrivateKey.fromWif function in bitsharesjs

To help you get started, we’ve selected a few bitsharesjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GamechainSystem / GameChainBase / GameChainBlockWallet / app / components / wallet / ImportKey.js View on Github external
addByPattern(contents) {
        if (!contents)
            return false

        var count = 0, invalid_count = 0
        var wif_regex = /5[HJK][1-9A-Za-z]{49}/g
        for (let wif of contents.match(wif_regex) || []) {
            try {
                var private_key = PrivateKey.fromWif(wif) //could throw and error
                var private_plainhex = private_key.toBuffer().toString('hex')
                var public_key = private_key.toPublicKey() // S L O W
                var public_key_string = public_key.toPublicKeyString()
                this.state.imported_keys_public[public_key_string] = true
                this.state.keys_to_account[private_plainhex] = {
                    account_names: [], public_key_string
                }
                count++
            } catch (e) {
                console.error('addByPattern:', e);
                invalid_count++
            }
        }
        this.setState({
            key_text_message: 'Found ' +
            (!count ? "" : count + " valid") +
github bitshares / bitshares-ui / app / lib / common / trxHelper.js View on Github external
]);
    currentFees = currentFees.toJS();

    let fee = 0;
    if (currentFees.fee) {
        fee += currentFees.fee;
    }

    if (options) {
        for (let option of options) {
            const optionFee = currentFees[option];

            if (option === "price_per_kbyte") {
                if (data.type === "memo" && !!data.content) {
                    /* Dummy priv key */
                    let pKey = _privKey || PrivateKey.fromWif(privKey);
                    if (_privKey) _privKey = pKey;
                    let memoFromKey =
                        "BTS6B1taKXkDojuC1qECjvC7g186d8AdeGtz8wnqWAsoRGC6RY8Rp";

                    // Memos are optional, but if you have one you need to encrypt it
                    let memoToKey =
                        "BTS8eLeqSZZtB1YHdw7KjQxRSRmaKAseCxhUSqaLxUdqvdGpp6nck";

                    /* Encryption is very expensive so we cache the result for reuse */
                    let message;
                    if (data.content === _prevContent && _cachedMessage) {
                        message = _cachedMessage;
                    } else {
                        message = _cachedMessage = Aes.encrypt_with_checksum(
                            pKey,
                            memoToKey,
github bitshares / bitshares-ui / app / components / Wallet / ImportKeys.jsx View on Github external
return false;
        }
        if (contents.length !== WIF_KEY_LENGTH) {
            this.setState({
                errorTextMessage: counterpart.translate(
                    "wallet.wif_length_error"
                )
            });
            return false;
        }
        let count = 0,
            invalid_count = 0;
        let wif_regex = /5[HJK][1-9A-Za-z]{49}/g;
        for (let wif of contents.match(wif_regex) || []) {
            try {
                let private_key = PrivateKey.fromWif(wif); //could throw and error
                let private_plainhex = private_key.toBuffer().toString("hex");
                let public_key = private_key.toPublicKey(); // S L O W
                let public_key_string = public_key.toPublicKeyString();
                this.state.imported_keys_public[public_key_string] = true;
                this.state.keys_to_account[private_plainhex] = {
                    account_names: [],
                    public_key_string
                };

                let accountName = [];
                AccountApi.lookupAccountByPublicKey(public_key_string).then(
                    async result => {
                        let batch;
                        batch = result[0].map(value => {
                            return FetchChain("getAccount", value);
                        });
github bitshares / bitshares-ui / app / stores / WalletDb.js View on Github external
_passwordKey[pub] = priv;

                id++;
                PrivateKeyStore.setPasswordLoginKey({
                    pubkey: pub,
                    import_account_names: [account],
                    encrypted_key: null,
                    id,
                    brainkey_sequence: null
                });
            }

            /* Check if the user tried to login with a private key */
            let fromWif;
            try {
                fromWif = PrivateKey.fromWif(password);
            } catch (err) {}
            let acc = ChainStore.getAccount(account, false);
            let key;
            if (fromWif) {
                key = {
                    privKey: fromWif,
                    pubKey: fromWif.toPublicKey().toString()
                };
            }

            /* Test the pubkey for each role against either the wif key, or the password generated keys */
            roles.forEach(role => {
                if (!fromWif) {
                    key = this.generateKeyFromPassword(account, role, password);
                }
github OpensourceBooks / write-a-blockchain-use-javascript / showuser.js View on Github external
fs.readFile('./key', 'utf-8', function (err, data) {
    if (err) {
        throw err;
    }
    let privateKey = PrivateKey.fromWif(data);
    let publicKey = privateKey.toPublicKey();
    let address = Address.fromPublic(publicKey);
    console.log("\n 这是你的信息 \n");
    console.log("+--------------+---------------------------------------------------------------------------------------+");
    console.log("|  Privatekey  |", privateKey.toWif().toString(),"                                  |");
    console.log("|  Publickey   |", publicKey.toString(), "                                |");
    console.log("|  Address     |", address.toString(),"                                                 |");
    console.log("+------------  +---------------------------------------------------------------------------------------+");
});