Java Code Examples for org.web3j.crypto.ECKeyPair#create()

The following examples show how to use org.web3j.crypto.ECKeyPair#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImportWalletActivity.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
@Override
public void onPrivateKey(String privateKey)
{
    try
    {
        BigInteger key = new BigInteger(privateKey, 16);
        if (!WalletUtils.isValidPrivateKey(privateKey)) throw new Exception(getString(R.string.invalid_private_key));
        ECKeyPair keypair = ECKeyPair.create(key);
        String address = Numeric.prependHexPrefix(Keys.getAddress(keypair));

        if (importWalletViewModel.keystoreExists(address))
        {
            queryReplaceWalletPrivateKey(address);
        }
        else
        {
            importWalletViewModel.importPrivateKeyWallet(address, this, this);
        }
    }
    catch (Exception e)
    {
        keyImportError(e.getMessage());
    }
}
 
Example 2
Source File: MarketOrderTest.java    From alpha-wallet-android with MIT License 4 votes vote down vote up
public MarketOrderTest()
{
    //roll a new key
    testKey = ECKeyPair.create("Test Key".getBytes());

    transactionRepository = new TransactionRepositoryType() {

        @Override
        public Observable<Transaction[]> fetchCachedTransactions(Wallet wallet, int maxTransactions, List<Integer> networkFilters) {
            return null;
        }

        @Override
        public Observable<Transaction[]> fetchNetworkTransaction(NetworkInfo network, String tokenAddress, long lastBlock, String userAddress)
        {
            return null;
        }

        @Override
        public Single<String> createTransaction(Wallet from, String toAddress, BigInteger subunitAmount, BigInteger gasPrice, BigInteger gasLimit, byte[] data, int chainId) {
            return null;
        }

        @Override
        public Single<TransactionData> createTransactionWithSig(Wallet from, String toAddress, BigInteger subunitAmount, BigInteger gasPrice, BigInteger gasLimit, byte[] data, int chainId)
        {
            return null;
        }

        @Override
        public Single<TransactionData> createTransactionWithSig(Wallet from, BigInteger gasPrice, BigInteger gasLimit, String data, int chainId)
        {
            return null;
        }

        @Override
        public Single<SignatureFromKey> getSignature(Wallet wallet, byte[] message, int chainId) {
            return null;
        }

        @Override
        public Single<byte[]> getSignatureFast(Wallet wallet, String password, byte[] message, int chainId) {
            return Single.fromCallable(() -> {
                //sign using the local key
                Sign.SignatureData sigData = Sign.signMessage(message, testKey);

                byte[] sig = new byte[65];

                try {
                    System.arraycopy(sigData.getR(), 0, sig, 0, 32);
                    System.arraycopy(sigData.getS(), 0, sig, 32, 32);
                    System.arraycopy(sigData.getV(), 0, sig, 64, 1);
                }
                catch (IndexOutOfBoundsException e)
                {
                    throw new SalesOrderMalformed("Signature shorter than expected 256");
                }

                return sig;
            });
        }

        @Override
        public Single<Transaction[]> storeTransactions(Wallet wallet, Transaction[] txList)
        {
            return null;
        }

        @Override
        public Single<Transaction[]> fetchTransactionsFromStorage(Wallet wallet, Token token, int count)
        {
            return null;
        }

        @Override
        public Single<ContractType> queryInterfaceSpec(String address, TokenInfo tokenInfo)
        {
            return null;
        }

        @Override
        public Transaction fetchCachedTransaction(String walletAddr, String hash)
        {
            return null;
        }
    };

    marketService = new MarketQueueService(null, null, transactionRepository);
}
 
Example 3
Source File: EdconLinkGenerator.java    From alpha-wallet-android with MIT License 4 votes vote down vote up
private byte[] signMagicLink(byte[] signData) {
    ECKeyPair ecKeyPair  = ECKeyPair.create(privateKey);
    Sign.SignatureData signatureData = Sign.signMessage(signData, ecKeyPair);
    return bytesFromSignature(signatureData);
}
 
Example 4
Source File: SpawnableLinkGenerator.java    From alpha-wallet-android with MIT License 4 votes vote down vote up
private byte[] signMagicLink(byte[] signData) {
    ECKeyPair ecKeyPair  = ECKeyPair.create(privateKey);
    Sign.SignatureData signatureData = Sign.signMessage(signData, ecKeyPair);
    return bytesFromSignature(signatureData);
}
 
Example 5
Source File: ETHWalletUtils.java    From Upchain-wallet with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * 通过明文私钥导入钱包
 *
 * @param privateKey
 * @param pwd
 * @return
 */
public static ETHWallet loadWalletByPrivateKey(String privateKey, String pwd) {
    Credentials credentials = null;
    ECKeyPair ecKeyPair = ECKeyPair.create(Numeric.toBigInt(privateKey));
    return generateWallet(generateNewWalletName(), pwd, ecKeyPair);
}