public static String getAddress(BigInteger publicKey) { return getAddress( Numeric.toHexStringWithPrefixZeroPadded(publicKey, PUBLIC_KEY_LENGTH_IN_HEX)); }
public static String getAddress(ECKeyPair ecKeyPair) { return getAddress(ecKeyPair.getPublicKey()); }
public static Credentials create(ECKeyPair ecKeyPair) { String address = Numeric.prependHexPrefix(Keys.getAddress(ecKeyPair)); return new Credentials(ecKeyPair, address); }
@Test public void testGetAddressString() { assertThat(Keys.getAddress(SampleKeys.PUBLIC_KEY_STRING), is(SampleKeys.ADDRESS_NO_PREFIX)); }
@Test public void testGetAddressZeroPaddedAddress() { String publicKey = "0xa1b31be4d58a7ddd24b135db0da56a90fb5382077ae26b250e1dc9cd6232ce22" + "70f4c995428bc76aa78e522316e95d7834d725efc9ca754d043233af6ca90113"; assertThat(Keys.getAddress(publicKey), is("01c52b08330e05d731e38c856c1043288f7d9744")); }
@Test public void testGetAddressSmallPublicKey() { byte[] address = Keys.getAddress( Numeric.toBytesPadded(BigInteger.valueOf(0x1234), Keys.PUBLIC_KEY_SIZE)); String expected = Numeric.toHexStringNoPrefix(address); assertThat(Keys.getAddress("0x1234"), equalTo(expected)); }
@Test public void testGetAddressBigInteger() { assertThat(Keys.getAddress(SampleKeys.PUBLIC_KEY), is(SampleKeys.ADDRESS_NO_PREFIX)); }
@Test public void testGetAddressZeroPadded() { byte[] address = Keys.getAddress( Numeric.toBytesPadded(BigInteger.valueOf(0x1234), Keys.PUBLIC_KEY_SIZE)); String expected = Numeric.toHexStringNoPrefix(address); String value = "1234"; assertThat(Keys.getAddress("0x" + Strings.zeros(Keys.PUBLIC_KEY_LENGTH_IN_HEX - value.length()) + value), equalTo(expected)); }
public String getFrom() throws SignatureException { Integer chainId = getChainId(); byte[] encodedTransaction; if (null == chainId) { encodedTransaction = TransactionEncoder.encode(this); } else { encodedTransaction = TransactionEncoder.encode(this, chainId.byteValue()); } byte v = signatureData.getV(); byte[] r = signatureData.getR(); byte[] s = signatureData.getS(); Sign.SignatureData signatureDataV = new Sign.SignatureData(getRealV(v), r, s); BigInteger key = Sign.signedMessageToKey(encodedTransaction, signatureDataV); return "0x" + Keys.getAddress(key); }
addressRecovered = "0x" + Keys.getAddress(publicKey);
private static WalletFile createWalletFile( ECKeyPair ecKeyPair, byte[] cipherText, byte[] iv, byte[] salt, byte[] mac, int n, int p) { WalletFile walletFile = new WalletFile(); walletFile.setAddress(Keys.getAddress(ecKeyPair)); WalletFile.Crypto crypto = new WalletFile.Crypto(); crypto.setCipher(CIPHER); crypto.setCiphertext(Numeric.toHexStringNoPrefix(cipherText)); WalletFile.CipherParams cipherParams = new WalletFile.CipherParams(); cipherParams.setIv(Numeric.toHexStringNoPrefix(iv)); crypto.setCipherparams(cipherParams); crypto.setKdf(SCRYPT); WalletFile.ScryptKdfParams kdfParams = new WalletFile.ScryptKdfParams(); kdfParams.setDklen(DKLEN); kdfParams.setN(n); kdfParams.setP(p); kdfParams.setR(R); kdfParams.setSalt(Numeric.toHexStringNoPrefix(salt)); crypto.setKdfparams(kdfParams); crypto.setMac(Numeric.toHexStringNoPrefix(mac)); walletFile.setCrypto(crypto); walletFile.setId(UUID.randomUUID().toString()); walletFile.setVersion(CURRENT_VERSION); return walletFile; }
private static String encode(BigInteger number) { // TODO check that this is the desired encoding... return Keys.getAddress(number); }
public static String getAddressFromPrivateKey(BigInteger privateKey) { final BigInteger publicKey = Sign.publicKeyFromPrivate(privateKey); return getAddress(publicKey); }
public static String getAddress(BigInteger publicKey) { return getAddress( Numeric.toHexStringWithPrefixZeroPadded(publicKey, PUBLIC_KEY_LENGTH_IN_HEX)); }
public static String getAddress(BigInteger publicKey) { return getAddress( Numeric.toHexStringWithPrefixZeroPadded(publicKey, PUBLIC_KEY_LENGTH_IN_HEX)); }
public static String getAddress(ECKeyPair ecKeyPair) { return getAddress(ecKeyPair.getPublicKey()); }
/** * generate ETH privatekey, publickey and address. * * @param childPrivateKey * @param keyPair */ private static List<String> EthAddress(ExtendedPrivateKey childPrivateKey, ECKeyPair keyPair) { String privateKey = childPrivateKey.getPrivateKey(); String publicKey = childPrivateKey.neuter().getPublicKey(); String address = Keys.getAddress(keyPair); System.out.println("ETH privateKey:" + privateKey); System.out.println("ETH publicKey:" + publicKey); System.out.println("ETH address:" + address); List<String> returnList = new ArrayList<>(); returnList.add(privateKey); returnList.add(publicKey); returnList.add(address); return returnList; }
public static Credentials create(ECKeyPair ecKeyPair) { String address = Numeric.prependHexPrefix(Keys.getAddress(ecKeyPair)); return new Credentials(ecKeyPair, address); }
private static void decodeMessage(String signedData) { //样例 https://ropsten.etherscan.io/tx/0xfd8acd10d72127f29f0a01d8bcaf0165665b5598781fe01ca4bceaa6ab9f2cb0 try { System.out.println(signedData); System.out.println("解密 start " + System.currentTimeMillis()); RlpList rlpList = RlpDecoder.decode(Numeric.hexStringToByteArray(signedData)); List<RlpType> values = ((RlpList) rlpList.getValues().get(0)).getValues(); BigInteger nonce = Numeric.toBigInt(((RlpString) values.get(0)).getBytes()); BigInteger gasPrice = Numeric.toBigInt(((RlpString) values.get(1)).getBytes()); BigInteger gasLimit = Numeric.toBigInt(((RlpString) values.get(2)).getBytes()); String to = Numeric.toHexString(((RlpString) values.get(3)).getBytes()); BigInteger value = Numeric.toBigInt(((RlpString) values.get(4)).getBytes()); String data = Numeric.toHexString(((RlpString) values.get(5)).getBytes()); RawTransaction rawTransaction = RawTransaction.createTransaction(nonce, gasPrice, gasLimit, to, value, data); RlpString v = (RlpString) values.get(6); RlpString r = (RlpString) values.get(7); RlpString s = (RlpString) values.get(8); Sign.SignatureData signatureData = new Sign.SignatureData( v.getBytes()[0], Numeric.toBytesPadded(Numeric.toBigInt(r.getBytes()), 32), Numeric.toBytesPadded(Numeric.toBigInt(s.getBytes()), 32)); BigInteger pubKey = Sign.signedMessageToKey(TransactionEncoder.encode(rawTransaction), signatureData); System.out.println("publicKey " + pubKey.toString(16)); String address = Numeric.prependHexPrefix(Keys.getAddress(pubKey)); System.out.println("address " + address); System.out.println("解密 end " + System.currentTimeMillis()); } catch (Exception e) { e.printStackTrace(); } }
public String getFrom() throws SignatureException { Integer chainId = getChainId(); byte[] encodedTransaction; if (null == chainId) { encodedTransaction = TransactionEncoder.encode(this); } else { encodedTransaction = TransactionEncoder.encode(this, chainId.byteValue()); } byte v = signatureData.getV(); byte[] r = signatureData.getR(); byte[] s = signatureData.getS(); Sign.SignatureData signatureDataV = new Sign.SignatureData(getRealV(v), r, s); BigInteger key = Sign.signedMessageToKey(encodedTransaction, signatureDataV); return "0x" + Keys.getAddress(key); }