public static Credentials loadBip44Credentials(String password, String mnemonic, boolean testNet) { byte[] seed = MnemonicUtils.generateSeed(mnemonic, password); Bip32ECKeyPair masterKeypair = Bip32ECKeyPair.generateKeyPair(seed); Bip32ECKeyPair bip44Keypair = generateBip44KeyPair(masterKeypair, testNet); return Credentials.create(bip44Keypair); } }
public static byte[] signMessage(RawTransaction rawTransaction, Credentials credentials) { byte[] encodedTransaction = encode(rawTransaction); Sign.SignatureData signatureData = Sign.signMessage( encodedTransaction, credentials.getEcKeyPair()); return encode(rawTransaction, signatureData); }
public static byte[] signMessage( RawTransaction rawTransaction, byte chainId, Credentials credentials) { byte[] encodedTransaction = encode(rawTransaction, chainId); Sign.SignatureData signatureData = Sign.signMessage( encodedTransaction, credentials.getEcKeyPair()); Sign.SignatureData eip155SignatureData = createEip155SignatureData(signatureData, chainId); return encode(rawTransaction, eip155SignatureData); }
public static Credentials loadBip39Credentials(String password, String mnemonic) { byte[] seed = MnemonicUtils.generateSeed(mnemonic, password); return Credentials.create(ECKeyPair.create(sha256(seed))); }
@Test public void testGenerateBip39Wallets() throws Exception { Bip39Wallet wallet = WalletUtils.generateBip39Wallet(PASSWORD, tempDir); byte[] seed = MnemonicUtils.generateSeed(wallet.getMnemonic(), PASSWORD); Credentials credentials = Credentials.create(ECKeyPair.create(sha256(seed))); assertEquals(credentials, WalletUtils.loadBip39Credentials(PASSWORD, wallet.getMnemonic())); }
/** * Utility method to provide the transaction hash for a given transaction. * * @param rawTransaction we wish to send * @param credentials of the sender * @return encoded transaction hash */ public static byte[] generateTransactionHash( RawTransaction rawTransaction, Credentials credentials) { byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials); return Hash.sha3(signedMessage); }
@Test public void testGenerateBip44Wallets() throws Exception { Bip39Wallet wallet = Bip44WalletUtils.generateBip44Wallet(PASSWORD, tempDir); byte[] seed = MnemonicUtils.generateSeed(wallet.getMnemonic(), PASSWORD); Bip32ECKeyPair masterKeypair = Bip32ECKeyPair.generateKeyPair(seed); Bip32ECKeyPair bip44Keypair = Bip44WalletUtils.generateBip44KeyPair(masterKeypair); Credentials credentials = Credentials.create(bip44Keypair); assertEquals(credentials, Bip44WalletUtils.loadBip44Credentials(PASSWORD, wallet.getMnemonic())); }
public static ECKeyPair createEcKeyPair(SecureRandom random) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException { KeyPair keyPair = createSecp256k1KeyPair(random); return ECKeyPair.create(keyPair); }
public static String generateNewWalletFile( String password, File destinationDirectory, boolean useFullScrypt) throws CipherException, IOException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException { ECKeyPair ecKeyPair = Keys.createEcKeyPair(); return generateWalletFile(password, ecKeyPair, destinationDirectory, useFullScrypt); }
public static ECKeyPair createEcKeyPair() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException { return createEcKeyPair(secureRandom()); }
public static byte[] encode(RawTransaction rawTransaction, byte chainId) { Sign.SignatureData signatureData = new Sign.SignatureData( chainId, new byte[] {}, new byte[] {}); return encode(rawTransaction, signatureData); }
public RawTransactionManager(Web3j web3j, Credentials credentials, byte chainId) { super(web3j, credentials.getAddress()); this.web3j = web3j; this.credentials = credentials; this.chainId = chainId; }
/** * Create a keypair using SECP-256k1 curve. * * <p>Private keypairs are encoded using PKCS8 * * <p>Private keys are encoded using X.509 */ static KeyPair createSecp256k1KeyPair() throws NoSuchProviderException, NoSuchAlgorithmException, InvalidAlgorithmParameterException { return createSecp256k1KeyPair(secureRandom()); }
public ECPoint getPublicKeyPoint() { if (publicKeyPoint == null) { publicKeyPoint = Sign.publicPointFromPrivate(getPrivateKey()); } return publicKeyPoint; }
public static Bip32ECKeyPair create(BigInteger privateKey, byte[] chainCode) { return new Bip32ECKeyPair(privateKey, Sign.publicKeyFromPrivate(privateKey), 0, chainCode, null); }
public static byte calculateChecksum(byte[] initialEntropy) { int ent = initialEntropy.length * 8; byte mask = (byte) (0xff << 8 - ent / 32); byte[] bytes = sha256(initialEntropy); return (byte) (bytes[0] & mask); }
static void validate(WalletFile walletFile) throws CipherException { WalletFile.Crypto crypto = walletFile.getCrypto(); if (walletFile.getVersion() != CURRENT_VERSION) { throw new CipherException("Wallet version is not supported"); } if (!crypto.getCipher().equals(CIPHER)) { throw new CipherException("Wallet cipher is not supported"); } if (!crypto.getKdf().equals(AES_128_CTR) && !crypto.getKdf().equals(SCRYPT)) { throw new CipherException("KDF type is not supported"); } }
public static String generateLightNewWalletFile(String password, File destinationDirectory) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, CipherException, IOException { return generateNewWalletFile(password, destinationDirectory, false); }
public static RawTransaction createContractTransaction( BigInteger nonce, BigInteger gasPrice, BigInteger gasLimit, BigInteger value, String init) { return new RawTransaction(nonce, gasPrice, gasLimit, "", value, init); }
/** * Utility method to provide the transaction hash for a given transaction. * * @param rawTransaction we wish to send * @param chainId of the intended chain * @param credentials of the sender * @return encoded transaction hash */ public static byte[] generateTransactionHash( RawTransaction rawTransaction, byte chainId, Credentials credentials) { byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, chainId, credentials); return Hash.sha3(signedMessage); }