Package convex.core.crypto
Class Ed25519Signature
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.crypto.ASignature
convex.core.crypto.Ed25519Signature
- All Implemented Interfaces:
IValidated
,IWriteable
Immutable data value class representing an Ed25519 digital signature.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Length in bytes of an Ed25519 signaturestatic final Ed25519Signature
A Signature containing zero bytes (not valid)Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Method Summary
Modifier and TypeMethodDescriptionint
encode
(byte[] bs, int pos) Writes this Cell's encoding to a byte array, including a tag byte which will be written first.int
encodeRaw
(byte[] bs, int pos) Writes this Cell's encoding to a byte array, excluding the tag byte.int
Estimate the encoded data size for this Cell.int
Gets the number of Refs contained within this Cell.Gets a Blob containing the raw bytes of this digital signatureboolean
Returns true if this Cell is in a canonical representation for message writing.final boolean
Returns true if this Cell represents a first class CVM Value.boolean
print
(BlobBuilder bb, long limit) Prints this Object to a readable String Representation.static Ed25519Signature
read
(ByteBuffer bb) Read a signature from a ByteBuffer.Converts this Cell to its canonical version.toCVMString
(long limit) Returns the CVM String representation of this Cell.Gets the content of this Signature as a hex stringvoid
Validates the local structure and invariants of this cell.boolean
verify
(ABlob message, AccountKey publicKey) Checks if the signature is valid for a given message hashstatic Ed25519Signature
wrap
(byte[] signature) Creates a Signature instance with specific bytesMethods inherited from class convex.core.crypto.ASignature
fromBlob, fromHex, getTag, isEmbedded
Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, getType, hashCode, isCompletelyEncoded, mark, mark, toString, updateRefs, validate, write
Methods inherited from class convex.core.data.AObject
attachEncoding, print, print
-
Field Details
-
SIGNATURE_LENGTH
public static final int SIGNATURE_LENGTHLength in bytes of an Ed25519 signature- See Also:
-
ZERO
A Signature containing zero bytes (not valid)
-
-
Method Details
-
wrap
Creates a Signature instance with specific bytes- Parameters:
signature
- Bytes for signature- Returns:
- Signature instance
-
isCanonical
public boolean isCanonical()Description copied from class:ACell
Returns true if this Cell is in a canonical representation for message writing. Non-canonical objects may be used on a temporary internal basis, they must always be converted to canonical representations for external use (e.g. Encoding).- Specified by:
isCanonical
in classACell
- Returns:
- true if the object is in canonical format, false otherwise
-
toCanonical
Description copied from class:ACell
Converts this Cell to its canonical version. Returns this Cell if already canonical, may be O(n) in size of value otherwise.- Specified by:
toCanonical
in classACell
- Returns:
- Canonical version of Cell
-
isCVMValue
public final boolean isCVMValue()Description copied from class:ACell
Returns true if this Cell represents a first class CVM Value. Sub-structural cells that are not themselves first class values should return false, pretty much everything else should return true. Note: CVM values might not be in a canonical format, e.g. temporary data structures- Specified by:
isCVMValue
in classACell
- Returns:
- true if the object is a CVM Value, false otherwise
-
read
Read a signature from a ByteBuffer. Assumes tag already read.- Parameters:
bb
- ByteBuffer to read from- Returns:
- Signature instance
- Throws:
BadFormatException
- If encoding is invalid
-
encode
public int encode(byte[] bs, int pos) Description copied from class:ACell
Writes this Cell's encoding to a byte array, including a tag byte which will be written first. Cell must be canonical, or else an error may occur.- Specified by:
encode
in interfaceIWriteable
- Specified by:
encode
in classACell
- Parameters:
bs
- A byte array to which to write the encodingpos
- The offset into the byte array- Returns:
- New position after writing
-
encodeRaw
public int encodeRaw(byte[] bs, int pos) Description copied from class:ACell
Writes this Cell's encoding to a byte array, excluding the tag byte. -
print
Description copied from class:AObject
Prints this Object to a readable String Representation. SECURITY: Must halt and return false in O(1) time if limit of printing is exceeded otherwise DoS attacks may be possible. -
toCVMString
Description copied from class:ACell
Returns the CVM String representation of this Cell. Normally, this is as printed, but may be different for some types. MUST return null in O(1) time if the length of the CVM String would exceed limit. The String representation is intended to be a easy-to-read textual representation of the Cell's data content.- Overrides:
toCVMString
in classACell
- Parameters:
limit
- Limit of CVM String length in UTF-8 bytes- Returns:
- CVM String, or null if limit exceeded
-
verify
Description copied from class:ASignature
Checks if the signature is valid for a given message hash- Specified by:
verify
in classASignature
- Parameters:
message
- Message to verifypublicKey
- Public key of signer- Returns:
- True if signature is valid, false otherwise
-
validateCell
Description copied from class:ACell
Validates the local structure and invariants of this cell. Called by validate() super implementation. Should validate directly contained data, but should not validate all other structure of this cell. In particular, should not traverse potentially missing child Refs.- Specified by:
validateCell
in classACell
- Throws:
InvalidDataException
- If the Cell is invalid
-
estimatedEncodingSize
public int estimatedEncodingSize()Description copied from interface:IWriteable
Estimate the encoded data size for this Cell. Used for quickly sizing buffers. Implementations should try to return a size that is likely to contain the entire object when represented in binary format, including the tag byte.- Returns:
- The estimated size for the binary representation of this object.
-
getRefCount
public int getRefCount()Description copied from class:ACell
Gets the number of Refs contained within this Cell. This number is final / immutable for any given instance and is defined by the Cell encoding rules. Contained Refs may be either external or embedded.- Specified by:
getRefCount
in classACell
- Returns:
- The number of Refs in this Cell
-
toHexString
Description copied from class:ASignature
Gets the content of this Signature as a hex string- Specified by:
toHexString
in classASignature
- Returns:
- Hex String representation of Signature
-
getSignatureBlob
Description copied from class:ASignature
Gets a Blob containing the raw bytes of this digital signature- Specified by:
getSignatureBlob
in classASignature
- Returns:
- Blob containing signature bytes
-