How to use the bitsharesjs.PrivateKey.fromSeed 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 bitshares / bitshares-ui / app / stores / WalletDb.js View on Github external
let old_password_aes = Aes.fromSeed(old_password);
            let new_password_aes = Aes.fromSeed(new_password);

            if (!wallet.encryption_key)
                // This change pre-dates the live chain..
                throw new Error(
                    "This wallet does not support the change password feature."
                );
            let encryption_plainbuffer = old_password_aes.decryptHexToBuffer(
                wallet.encryption_key
            );
            wallet.encryption_key = new_password_aes.encryptToHex(
                encryption_plainbuffer
            );

            let new_password_private = PrivateKey.fromSeed(new_password);
            wallet.password_pubkey = new_password_private
                .toPublicKey()
                .toPublicKeyString();

            if (unlock) {
                aes_private = Aes.fromSeed(encryption_plainbuffer);
            } else {
                // new password, make sure the wallet gets locked
                aes_private = null;
            }
            resolve(this.setWalletModified());
        });
    }
github bitshares / bitshares-ui / app / stores / WalletDb.js View on Github external
Notification.success({
                        message: counterpart.translate("wallet.local_switch")
                    });
                    SettingsActions.changeSetting({
                        setting: "passwordLogin",
                        value: false
                    });
                    return {success: true, cloudMode: false};
                }
            }

            return {success: !!_passwordKey, cloudMode: true};
        } else {
            let wallet = this.state.wallet;
            try {
                let password_private = PrivateKey.fromSeed(password);
                let password_pubkey = password_private
                    .toPublicKey()
                    .toPublicKeyString();
                if (wallet.password_pubkey !== password_pubkey) return false;
                if (unlock) {
                    let password_aes = Aes.fromSeed(password);
                    let encryption_plainbuffer = password_aes.decryptHexToBuffer(
                        wallet.encryption_key
                    );
                    aes_private = Aes.fromSeed(encryption_plainbuffer);
                }
                return {success: true, cloudMode: false};
            } catch (e) {
                console.error(e);
                return {success: false, cloudMode: false};
            }
github bitshares / bitshares-ui / app / components / Wallet / Backup.jsx View on Github external
onPassword(e) {
        if (e) e.preventDefault();
        let private_key = PrivateKey.fromSeed(this.state.backup_password || "");
        let contents = this.props.backup.contents;
        decryptWalletBackup(private_key.toWif(), contents)
            .then(wallet_object => {
                this.setState({verified: true});
                if (this.props.saveWalletObject)
                    BackupStore.setWalletObjct(wallet_object);
            })
            .catch(error => {
                console.error(
                    "Error verifying wallet " + this.props.backup.name,
                    error,
                    error.stack
                );
                if (error === "invalid_decryption_key") {
                    Notification.error({
                        message: counterpart.translate(
github bitshares / bitshares-ui / app / components / Wallet / WalletUnlockModal.jsx View on Github external
restoreBackup = (password, callback) => {
        const {backup} = this.props;
        const privateKey = PrivateKey.fromSeed(password || "");
        const walletName = backup.name.split(".")[0];
        restore(privateKey.toWif(), backup.contents, walletName)
            .then(() => {
                return WalletActions.setWallet(walletName)
                    .then(() => {
                        BackupActions.reset();
                        callback();
                    })
                    .catch(e => this.setState({customError: e.message}));
            })
            .catch(e => {
                const message = typeof e === "string" ? e : e.message;
                const invalidBackupPassword =
                    message === "invalid_decryption_key";
                this.setState({
                    customError: invalidBackupPassword ? null : message,
github GamechainSystem / GameChainBase / GameChainBlockWallet / app / components / wallet / ImportBackup.js View on Github external
let ls_sha1s=localStorage.getItem("sha1s");
        let isExist=false;
        if(ls_sha1s){
            ls_sha1s=JSON.parse(ls_sha1s);
            isExist=ls_sha1s.some(item=>{
                return item.sha1==backup.sha1;
            })
        }else{
            ls_sha1s=[];
        }

    

        let pass = this.refs.password.value;
        let private_key = PrivateKey.fromSeed(pass || "");
        let contents = this.props.backup.contents;

        decryptWalletBackup(private_key.toWif(), contents).then(wallet_object => {
            if(isExist){
                warning("该钱包已经导入,请勿重复导入");
                return;
            }else{
                ls_sha1s.push({
                    wallet_name:wallet_name,
                    sha1:backup.sha1
                })
    
                localStorage.setItem("sha1s",JSON.stringify(ls_sha1s));
            }
            
            BackupStore.setWalletObjct(wallet_object);
github bitshares / bitshares-ui / app / stores / WalletDb.js View on Github external
generateKeyFromPassword(accountName, role, password) {
        let seed = accountName + role + password;
        let privKey = PrivateKey.fromSeed(seed);
        let pubKey = privKey.toPublicKey().toString();

        return {privKey, pubKey};
    }
github bitshares / bitshares-ui / app / stores / WalletDb.js View on Github external
getBrainKeyPrivate(brainkey_plaintext = this.getBrainKey()) {
        if (!brainkey_plaintext) throw new Error("missing brainkey");
        return PrivateKey.fromSeed(key.normalize_brainKey(brainkey_plaintext));
    }
github bitshares / bitshares-ui / app / stores / WalletDb.js View on Github external
brainkey_plaintext = key.suggest_brain_key(dictionary.en);
                else
                    brainkey_plaintext = key.normalize_brainKey(
                        brainkey_plaintext
                    );
                let brainkey_private = this.getBrainKeyPrivate(
                    brainkey_plaintext
                );
                let brainkey_pubkey = brainkey_private
                    .toPublicKey()
                    .toPublicKeyString();
                let encrypted_brainkey = local_aes_private.encryptToHex(
                    brainkey_plaintext
                );

                let password_private = PrivateKey.fromSeed(password_plaintext);
                let password_pubkey = password_private
                    .toPublicKey()
                    .toPublicKeyString();

                let wallet = {
                    public_name,
                    password_pubkey,
                    encryption_key,
                    encrypted_brainkey,
                    brainkey_pubkey,
                    brainkey_sequence: 0,
                    brainkey_backup_date,
                    created: new Date(),
                    last_modified: new Date(),
                    chain_id: Apis.instance().chain_id
                };