public class Sign
extends java.lang.Object
Transaction signing logic.
Originally adapted from the
BitcoinJ ECKey implementation.
Class from web3j project, and adapted to neow3j project (with NEO requirements).
| Modifier and Type | Class and Description |
|---|---|
static class |
Sign.SignatureData |
| Constructor and Description |
|---|
Sign() |
| Modifier and Type | Method and Description |
|---|---|
static ECKeyPair.ECPublicKey |
publicKeyFromPrivate(ECKeyPair.ECPrivateKey privKey)
Returns public key from the given private key.
|
static org.bouncycastle.math.ec.ECPoint |
publicPointFromPrivateKey(ECKeyPair.ECPrivateKey privKey)
Returns public key point from the given private key.
|
static ECKeyPair.ECPublicKey |
recoverFromSignature(int recId,
ECDSASignature sig,
byte[] message)
Given the components of a signature and a selector value, recover and return the public
key that generated the signature according to the algorithm in SEC1v2 section 4.1.6.
|
static java.lang.String |
recoverSigningAddress(byte[] message,
Sign.SignatureData signatureData)
Recovers the address that created the given signature on the given message.
|
static ECKeyPair.ECPublicKey |
signedMessageToKey(byte[] message,
Sign.SignatureData signatureData)
Given an arbitrary piece of text and an NEO message signature encoded in bytes, returns the
public key that was used to sign it.
|
static Sign.SignatureData |
signMessage(byte[] message,
ECKeyPair keyPair) |
static Sign.SignatureData |
signMessage(byte[] message,
ECKeyPair keyPair,
boolean needToHash) |
public static Sign.SignatureData signMessage(byte[] message, ECKeyPair keyPair)
public static Sign.SignatureData signMessage(byte[] message, ECKeyPair keyPair, boolean needToHash)
public static ECKeyPair.ECPublicKey recoverFromSignature(int recId, ECDSASignature sig, byte[] message)
Given the components of a signature and a selector value, recover and return the public key that generated the signature according to the algorithm in SEC1v2 section 4.1.6.
The recId is an index from 0 to 3 which indicates which of the 4 possible keys is the correct one. Because the key recovery operation yields multiple potential keys, the correct key must either be stored alongside the signature, or you must be willing to try each recId in turn until you find one that outputs the key you are expecting.
If this method returns null it means recovery was not possible and recId should be iterated.
Given the above two points, a correct usage of this method is inside a for loop from 0 to 3, and if the output is null OR a key that is not the one you expect, you try again with the next recId.
recId - Which possible key to recover.sig - the R and S components of the signature, wrapped.message - Hash of the data that was signed.public static ECKeyPair.ECPublicKey signedMessageToKey(byte[] message, Sign.SignatureData signatureData) throws java.security.SignatureException
message - encoded message.signatureData - The message signature componentsjava.security.SignatureException - If the public key could not be recovered or if there was a
signature format error.public static ECKeyPair.ECPublicKey publicKeyFromPrivate(ECKeyPair.ECPrivateKey privKey)
privKey - the private key to derive the public key frompublic static org.bouncycastle.math.ec.ECPoint publicPointFromPrivateKey(ECKeyPair.ECPrivateKey privKey)
privKey - The private key as BigIntegerpublic static java.lang.String recoverSigningAddress(byte[] message,
Sign.SignatureData signatureData)
throws java.security.SignatureException
If the message is a Neo transaction, then make sure that it was serialized without the verification and invocation script attached (i.e. without the signature).
signatureData - The signature.message - The message for which the signature was created.java.security.SignatureException - throws if the signature is invalid.