All Downloads are FREE. Search and download functionalities are using the official Maven repository.

vite.WalletClient Maven / Gradle / Ivy

The newest version!
package vite;

import com.alibaba.fastjson.JSONObject;
import com.rotilho.jnano.commons.NanoMnemonics;
import org.apache.commons.lang3.StringUtils;
import vite.bean.Key;
import vite.bean.ViteMnemonics;

import java.util.Arrays;
import java.util.List;

public class WalletClient {

    public static Key getKeyPairFromMnemonics(String mnemonics, int index) {

        if (StringUtils.isEmpty(mnemonics)) {
            throw new RuntimeException("mnemonics cannpt be empty!");
        }

        List mnemonicList = Arrays.asList(mnemonics.split(" "));


        boolean flag = ViteMnemonics.isValid(mnemonicList, ViteMnemonics.ViteMnemonicLanguage.ENGLISH);
        if (!flag) {
            throw new RuntimeException("mnemonics is not right for bip39!");
        }
        return Wallet.generateKeyPairsFromMnemonics(mnemonics, index, 0);
    }


    public static void main(String[] args) {
        Key key = getKeyPairFromMnemonics("alarm canal scheme actor left length bracket slush tuna garage prepare scout school pizza invest rose fork scorpion make enact false kidney mixed vast", 0);

        System.out.println(key.getHexAddress() + "\t" + key.getHexPriKey());


        List list = Wallet.createBip39Mnemonic();

        System.out.println(JSONObject.toJSONString(list));
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy