/** * Verifies the given ASN.1 encoded ECDSA signature against a hash using the public key. * * @param data Hash of the data to verify. * @param signature signature. * @param pub The public key bytes to use. * * @return - */ public static boolean verify(byte[] data, byte[] signature, byte[] pub) { return verify(data, ECDSASignature.decodeFromDER(signature), pub); }
/** * Compute the address of the key that signed the given signature. * * @param messageHash 32-byte hash of message * @param signatureBase64 Base-64 encoded signature * * @return 20-byte address */ public static byte[] signatureToAddress(byte[] messageHash, String signatureBase64) throws SignatureException { return computeAddress(signatureToKeyBytes(messageHash, signatureBase64)); }
public Transaction(byte[] nonce, byte[] gasPrice, byte[] gasLimit, byte[] receiveAddress, byte[] value, byte[] data, byte[] r, byte[] s, byte v, Integer chainId) { this(nonce, gasPrice, gasLimit, receiveAddress, value, data, chainId); this.signature = ECDSASignature.fromComponents(r, s, v); }
private byte[] createClosingMsgHash(Address senderAddress, BigInteger openBlockNumber, BigInteger owedBalance, ECKey receiverECKey, Address channelManagerAddr) { byte[] closingMsgHash = createClosingMsgHashRaw(senderAddress, openBlockNumber, owedBalance, channelManagerAddr); return receiverECKey.sign(closingMsgHash) .toByteArray(); }
public byte[] getRawHash() { rlpParse(); if (rawHash != null) return rawHash; byte[] plainMsg = this.getEncodedRaw(); return rawHash = HashUtil.sha3(plainMsg); } }
/** * Compute the key that signed the given signature. * * @param messageHash 32-byte hash of message * @param signatureBase64 Base-64 encoded signature * * @return ECKey */ public static ECKey signatureToKey(byte[] messageHash, String signatureBase64) throws SignatureException { byte[] keyBytes = signatureToKeyBytes(messageHash, signatureBase64); return fromPublicOnly(keyBytes); }
/** * Creates an ECKey that cannot be used for signing, only verifying signatures, from the given point. The * compression state of pub will be preserved. * * @param pub - * * @return - */ public static ECKey fromPublicOnly(ECPoint pub) { return new ECKey(null, pub); }
/** * Gets the address form of the public key. * * @return 20-byte address */ public byte[] getAddress() { if (pubKeyHash == null) { pubKeyHash = computeAddress(this.pub); } return pubKeyHash; }
/** * Generates the NodeID based on this key, that is the public key without first format byte */ public byte[] getNodeId() { if (nodeId == null) { nodeId = pubBytesWithoutFormat(this.pub); } return nodeId; }
/** * @param input - * * @return - * * @see #doubleDigest(byte[], int, int) */ public static byte[] doubleDigest(byte[] input) { return doubleDigest(input, 0, input.length); }
public boolean validateComponents() { return validateComponents(r, s, v); }
@Override public int hashCode() { return Arrays.hashCode(getPubKey()); } }
private byte[] createBalanceMsgHash(Address receiverAddress, BigInteger openBlockNumber, BigInteger owedBalance, ECKey senderECKey, Address channelManagerAddr) { byte[] balanceMsgHash = createBalanceMsgHashRaw(receiverAddress, openBlockNumber, owedBalance, channelManagerAddr); return senderECKey.sign(balanceMsgHash) .toByteArray(); }
/** * Compute the address of the key that signed the given signature. * * @param messageHash 32-byte hash of message * @param sig - * * @return 20-byte address */ public static byte[] signatureToAddress(byte[] messageHash, ECDSASignature sig) throws SignatureException { return computeAddress(signatureToKeyBytes(messageHash, sig)); }
/** * Compute the key that signed the given signature. * * @param messageHash 32-byte hash of message * @param sig - * * @return ECKey */ public static ECKey signatureToKey(byte[] messageHash, ECDSASignature sig) throws SignatureException { byte[] keyBytes = signatureToKeyBytes(messageHash, sig); return fromPublicOnly(keyBytes); }
/** * @param r - * @param s - * @param v - * * @return - */ public static ECDSASignature fromComponents(byte[] r, byte[] s, byte v) { ECDSASignature signature = fromComponents(r, s); signature.v = v; return signature; }
/** * Creates an ECKey that simply trusts the caller to ensure that point is really the result of multiplying the * generator point by the private key. This is used to speed things up when you know you have the right values * already. The compression state of pub will be preserved. * * @param priv - * @param pub - * * @return - */ public static ECKey fromPrivateAndPrecalculatedPublic(BigInteger priv, ECPoint pub) { return new ECKey(priv, pub); }
/** * Compute an address from a public point. * * @param pubPoint a public point * * @return 20-byte address */ public static byte[] computeAddress(ECPoint pubPoint) { return computeAddress(pubPoint.getEncoded(/* uncompressed */ false)); }