Package convex.core.data
Class SignedData<T extends ACell>
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.data.SignedData<T>
- Type Parameters:
T- The type of the signed object
- All Implemented Interfaces:
IValidated,IWriteable
Node representing a signed data object.
A signed data object encapsulates:
- An Address that identifies the signer
- A digital signature
- An underlying Cell that has been signed.
- 1 byte - Tag.SIGNED_DATA tag
- 32 bytes - Public Key of signer
- 64 bytes - raw Signature data
- 1+ bytes - Data Value Ref (may be embedded)
-
Field Summary
Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY -
Method Summary
Modifier and TypeMethodDescriptionbooleanValidates the signature in this SignedData instance.static SignedData<ATransaction>create(AKeyPair kp, ASignature sig, Ref<ATransaction> ref)static <T extends ACell>
SignedData<T>static <T extends ACell>
SignedData<T>create(AccountKey address, ASignature sig, Ref<T> ref)Creates a SignedData object with the given parameters.static <T extends ACell>
SignedData<T>createWithRef(AKeyPair keyPair, Ref<T> ref)Signs a data value Ref with the given keypair.intencode(byte[] bs, int pos)Writes this Cell's encoding to a byte array, including a tag byte which will be written firstintencodeRaw(byte[] bs, int pos)Writes this Cell's encoding to a byte array, excluding the tag byteintEstimate the encoded data size for this Cell.Gets the public key of the signer.getRef(int i)Gets a numbered child Ref from within this Cell.intGets the number of Refs contained within this Cell.Gets the Signature that formed part of this SignedData objectbytegetTag()Gets the tag byte for this cell.getValue()Gets the signed value object encapsulated by this SignedData object.booleanReturns true if this Cell is in a canonical format for message writing.booleanReturns true if this object represents a first class CVM Value.booleanSignedData is not embedded.booleanChecks if the signature has already gone through verification.voidprint(StringBuilder sb)Prints this Object to a readable String Representationstatic <T extends ACell>
SignedData<T>read(ByteBuffer data)Reads a SignedData instance from the given ByteBufferConverts this Cell to its canonical version.toString()Returns the String representation of this Cell.updateRefs(IRefFunction func)Updates all Refs in this object using the given function.voidvalidate()Validates the complete structure of this object.voidValidates the local structure and invariants of this cell.voidMethods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, equals, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getType, hashCode, writeMethods inherited from class convex.core.data.AObject
attachEncoding, print
-
Method Details
-
createWithRef
Signs a data value Ref with the given keypair. SECURITY: Marks as already validated, since we just signed it.- Parameters:
keyPair- The public/private key pair of the signer.ref- Ref to the data to sign- Returns:
- SignedData object signed with the given key-pair
-
create
-
create
public static <T extends ACell> SignedData<T> create(AccountKey address, ASignature sig, Ref<T> ref)Creates a SignedData object with the given parameters. SECURITY: Not assumed to be valid.- Parameters:
address- Public Address of the signersig- Signature of the supplied dataref- Ref to the data that has been signed- Returns:
- A new SignedData object
-
create
-
getValue
Gets the signed value object encapsulated by this SignedData object. Does not check Signature.- Returns:
- Data value that has been signed
-
getAccountKey
Gets the public key of the signer. If the signature is valid, this represents a cryptographic proof that the signer was in possession of the private key of this address.- Returns:
- Public Key of signer.
-
getSignature
Gets the Signature that formed part of this SignedData object- Returns:
- Signature instance
-
encode
public int encode(byte[] bs, int pos)Description copied from class:ACellWrites this Cell's encoding to a byte array, including a tag byte which will be written first- Specified by:
encodein interfaceIWriteable- Specified by:
encodein 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:ACellWrites this Cell's encoding to a byte array, excluding the tag byte -
estimatedEncodingSize
public int estimatedEncodingSize()Description copied from interface:IWriteableEstimate 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.
-
read
Reads a SignedData instance from the given ByteBuffer- Parameters:
data- A ByteBuffer containing- Returns:
- A SignedData object
- Throws:
BadFormatException- If encoding is invalid
-
checkSignature
public boolean checkSignature()Validates the signature in this SignedData instance. Caches result- Returns:
- true if valid, false otherwise
-
isSignatureChecked
public boolean isSignatureChecked()Checks if the signature has already gone through verification. MAy or may not be a valid signature.- Returns:
- true if valid, false otherwise
-
validateSignature
- Throws:
BadSignatureException
-
isCanonical
public boolean isCanonical()Description copied from class:ACellReturns true if this Cell is in a canonical format for message writing. Reading or writing a non-canonical value should be considered illegal, but non-canonical objects may be used on a temporary internal basis.- Specified by:
isCanonicalin classACell- Returns:
- true if the object is in canonical format, false otherwise
-
isCVMValue
public final boolean isCVMValue()Description copied from class:ACellReturns true if this object represents a first class CVM Value. Sub-structural cells that are not themselves first class values should return false. CVM values might not be in a canonical format, e.g. temporary data structures- Specified by:
isCVMValuein classACell- Returns:
- true if the object is a CVM Value, false otherwise
-
getRefCount
public int getRefCount()Description copied from class:ACellGets the number of Refs contained within this Cell. This number is final / immutable for any given instance. Contained Refs may be either external or embedded.- Specified by:
getRefCountin classACell- Returns:
- The number of Refs in this Cell
-
getRef
Description copied from class:ACellGets a numbered child Ref from within this Cell. -
updateRefs
Description copied from class:ACellUpdates all Refs in this object using the given function. The function *must not* change the hash value of Refs, in order to ensure structural integrity of modified data structures. This is a building block for a very sneaky trick that enables use to do a lot of efficient operations on large trees of smart references. Must return the same object if no Refs are altered.- Overrides:
updateRefsin classACell- Parameters:
func- Ref update function- Returns:
- Cell with updated Refs
-
print
Description copied from class:AObjectPrints this Object to a readable String Representation -
validate
Description copied from interface:IValidatedValidates the complete structure of this object. It is necessary to ensure all child Refs are validated, so the general contract for validate is:- Call super.validate() - which will indirectly call validateCell()
- Call validate() on any contained cells in this class
- Specified by:
validatein interfaceIValidated- Overrides:
validatein classACell- Throws:
InvalidDataException- If the data Valie is invalid in any way
-
validateCell
Description copied from class:ACellValidates 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:
validateCellin classACell- Throws:
InvalidDataException- If the Cell is invalid
-
getDataRef
-
isEmbedded
public boolean isEmbedded()SignedData is not embedded. We want to persist in store always to cache verification status- Overrides:
isEmbeddedin classACell- Returns:
- Always false
-
toString
Description copied from class:ACellReturns the String representation of this Cell. The String representation is intended to be a easy-to-read textual representation of the Cell's data content. -
getTag
public byte getTag()Description copied from class:ACellGets the tag byte for this cell. The tag byte will be the first byte of the encoding -
toCanonical
Description copied from class:ACellConverts this Cell to its canonical version. Returns this if already canonical- Specified by:
toCanonicalin classACell- Returns:
- Canonical version of Cell
-