Tabnine Logo
org.web3j.crypto
Code IndexAdd Tabnine to your IDE (free)

How to use org.web3j.crypto

Best Java code snippets using org.web3j.crypto (Showing top 20 results out of 315)

origin: web3j/web3j

  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);
  }
}
origin: web3j/web3j

public static byte[] signMessage(RawTransaction rawTransaction, Credentials credentials) {
  byte[] encodedTransaction = encode(rawTransaction);
  Sign.SignatureData signatureData = Sign.signMessage(
      encodedTransaction, credentials.getEcKeyPair());
  return encode(rawTransaction, signatureData);
}
origin: web3j/web3j

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);
}
origin: web3j/web3j

public static Credentials loadBip39Credentials(String password, String mnemonic) {
  byte[] seed = MnemonicUtils.generateSeed(mnemonic, password);
  return Credentials.create(ECKeyPair.create(sha256(seed)));
}
origin: web3j/web3j

@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()));
}
origin: web3j/web3j

/**
 * 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);
}
origin: web3j/web3j

@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()));
}
origin: web3j/web3j

public static ECKeyPair createEcKeyPair(SecureRandom random) throws
    InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException {
  KeyPair keyPair = createSecp256k1KeyPair(random);
  return ECKeyPair.create(keyPair);
}
origin: web3j/web3j

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);
}
origin: web3j/web3j

public static ECKeyPair createEcKeyPair() throws InvalidAlgorithmParameterException,
    NoSuchAlgorithmException, NoSuchProviderException {
  return createEcKeyPair(secureRandom());
}
origin: web3j/web3j

public static byte[] encode(RawTransaction rawTransaction, byte chainId) {
  Sign.SignatureData signatureData = new Sign.SignatureData(
      chainId, new byte[] {}, new byte[] {});
  return encode(rawTransaction, signatureData);
}
origin: web3j/web3j

public RawTransactionManager(Web3j web3j, Credentials credentials, byte chainId) {
  super(web3j, credentials.getAddress());
  this.web3j = web3j;
  this.credentials = credentials;
  this.chainId = chainId;
}
origin: web3j/web3j

/**
 * 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());
}
origin: web3j/web3j

public ECPoint getPublicKeyPoint() {
  if (publicKeyPoint == null) {
    publicKeyPoint = Sign.publicPointFromPrivate(getPrivateKey());
  }
  return publicKeyPoint;
}
origin: web3j/web3j

public static Bip32ECKeyPair create(BigInteger privateKey, byte[] chainCode) {
  return new Bip32ECKeyPair(privateKey, Sign.publicKeyFromPrivate(privateKey),
      0, chainCode, null);
}
origin: web3j/web3j

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);
}
origin: web3j/web3j

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");
  }
}
origin: web3j/web3j

public static String generateLightNewWalletFile(String password, File destinationDirectory)
    throws NoSuchAlgorithmException, NoSuchProviderException,
    InvalidAlgorithmParameterException, CipherException, IOException {
  return generateNewWalletFile(password, destinationDirectory, false);
}
origin: web3j/web3j

public static RawTransaction createContractTransaction(
    BigInteger nonce, BigInteger gasPrice, BigInteger gasLimit, BigInteger value,
    String init) {
  return new RawTransaction(nonce, gasPrice, gasLimit, "", value, init);
}
origin: web3j/web3j

/**
 * 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);
}
org.web3j.crypto

Most used classes

  • Credentials
    Credentials wrapper.
  • Hash
    Crypto related functions.
  • ECKeyPair
    Elliptic Curve SECP-256k1 generated key pair.
  • TransactionEncoder
    Create RLP encoded transaction, implementation as per p4 of theyellow paper [http://gavwood.com/pape
  • RawTransaction
    Transaction class used for signing transactions locally. For the specification, refer to p4 of the y
  • WalletUtils,
  • Wallet,
  • Sign$SignatureData,
  • Sign,
  • Bip32ECKeyPair,
  • MnemonicUtils,
  • WalletFile,
  • SecureRandomUtils,
  • SignedRawTransaction,
  • CipherException,
  • ContractUtils,
  • ECDSASignature,
  • TransactionUtils,
  • Base58
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now