/** * Calculates RIGTMOST160(SHA3(input)). This is used in address calculations. * * * * @param input - data * * @return - 20 right bytes of the hash keccak of the data */ public static byte[] sha3omit12(byte[] input) { byte[] hash = sha3(input); return copyOfRange(hash, 12, hash.length); }
/** * @param input - * * @return - * * @see #doubleDigest(byte[], int, int) */ public static byte[] doubleDigest(byte[] input) { return doubleDigest(input, 0, input.length); }
/** * Compute an address from an encoded public key. * * @param pubBytes an encoded (uncompressed) public key * * @return 20-byte address */ public static byte[] computeAddress(byte[] pubBytes) { return HashUtil.sha3omit12(Arrays.copyOfRange(pubBytes, 1, pubBytes.length)); }
public byte[] getContractAddress() { if (!isContractCreation()) return null; return HashUtil.calcNewAddr(this.getSender(), this.getNonce()); }
public byte[] encodeSignatureLong() { String signature = formatSignature(); byte[] sha3Fingerprint = sha3(signature.getBytes()); return sha3Fingerprint; }
/** * The way to calculate new address inside ethereum * * @param addr - creating addres * @param nonce - nonce of creating address * * @return new address */ public static byte[] calcNewAddr(byte[] addr, byte[] nonce) { byte[] encSender = RLP.encodeElement(addr); byte[] encNonce = RLP.encodeBigInteger(new BigInteger(1, nonce)); return sha3omit12(RLP.encodeList(encSender, encNonce)); }
public byte[] hash() { if (sha3 == null) sha3 = HashUtil.sha3(encode()); return sha3; }
public byte[] getHash() { if (!isEmpty(hash)) return hash; rlpParse(); byte[] plainMsg = this.getEncoded(); return HashUtil.sha3(plainMsg); }
public byte[] getRawHash() { rlpParse(); if (rawHash != null) return rawHash; byte[] plainMsg = this.getEncodedRaw(); return rawHash = HashUtil.sha3(plainMsg); } }
private byte[] createClosingMsgHashRaw(Address senderAddress, BigInteger openBlockNumber, BigInteger owedBalance, Address channelManagerAddr) { byte[] receiverAddressBytes = senderAddress.getBytes(); byte[] channelAddressBytes = channelManagerAddr.getBytes(); byte[] openBlockNumberBytes = ByteUtils.prependZeros(openBlockNumber.toByteArray(), 4); byte[] balanceBytes = ByteUtils.prependZeros(Hex.decode(prependZeroIfNeeded(owedBalance)), 24); byte[] dataTypeName = "string message_idaddress senderuint32 block_createduint192 balanceaddress contract".getBytes( Charset.forName("UTF-8")); byte[] dataValue = ByteUtils.concat("Receiver closing signature".getBytes(), receiverAddressBytes, openBlockNumberBytes, balanceBytes, channelAddressBytes); return HashUtil.sha3(ByteUtils.concat(HashUtil.sha3(dataTypeName), HashUtil.sha3(dataValue))); }
private byte[] createBalanceMsgHashRaw(Address receiverAddress, BigInteger openBlockNumber, BigInteger owedBalance, Address channelManagerAddr) { byte[] receiverAddressBytes = receiverAddress.getBytes(); byte[] channelAddressBytes = channelManagerAddr.getBytes(); byte[] openBlockNumberBytes = ByteUtils.prependZeros(openBlockNumber.toByteArray(), 4); byte[] balanceBytes = ByteUtils.prependZeros(Hex.decode(prependZeroIfNeeded(owedBalance)), 24); byte[] dataTypeName = "string message_idaddress receiveruint32 block_createduint192 balanceaddress contract".getBytes( Charset.forName("UTF-8")); byte[] dataValue = ByteUtils.concat("Sender balance proof signature".getBytes(), receiverAddressBytes, openBlockNumberBytes, balanceBytes, channelAddressBytes); return HashUtil.sha3(ByteUtils.concat(HashUtil.sha3(dataTypeName), HashUtil.sha3(dataValue))); }