Package convex.core.data
Class SignedData<T extends ACell>
- Type Parameters:
T
- The type of the signed object
- All Implemented Interfaces:
IAssociative<Keyword,
,ACell> IValidated
,IWriteable
,Map<Keyword,
ACell>
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)
-
Nested Class Summary
-
Field Summary
Fields inherited from class convex.core.data.ARecord
DEFAULT_VALUE
Fields inherited from class convex.core.data.ADataStructure
count
Fields inherited from class convex.core.data.ACell
cachedRef, memorySize
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Validates the signature in this SignedData instance.boolean
checkSignature
(AccountKey publicKey) Validates the signature in this SignedData instance.static <T extends ACell>
SignedData<T> create
(ASignature sig, Ref<T> ref) Creates a SignedData object with the given parameters.static <T extends ACell>
SignedData<T> create
(AccountKey address, ASignature sig, Ref<T> ref) Creates a SignedData object with the given parameters.int
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.boolean
Checks for equality with another Cell.int
Estimate the encoded data size for this Cell.Gets the record field content for a given key, or null if not found.Gets the public key of the signer.Gets the RecordFormat instance that describes this Record's layoutgetMessageForRef
(Ref<T> ref) getRef
(int i) Gets a numbered child Ref from within this Cell.final int
Gets the number of Refs contained within this Cell.Gets the Signature that formed part of this SignedData objectbyte
getTag()
Gets the tag byte for this record type.getValue()
Gets the signed value object encapsulated by this SignedData object.boolean
Returns true if this Cell is in a canonical representation.final boolean
Returns true if this cell is a first class CVM Value allowable in the CVM state Sub-structural cells that are not themselves first class values should return false Records and types that are not permissible on the CVM should return false.boolean
SignedData is not embedded.boolean
Checks if the signature has already gone through verification.static <T extends ACell>
SignedData<T> Reads a SignedData instance from the given Blob encodingstatic <T extends ACell>
SignedData<T> Create a SignedData by signing a value with the given key pairstatic <T extends ACell>
SignedData<T> Signs a data value Ref with the given keypair.updateRefs
(IRefFunction func) Updates all Refs in this object using the given function.void
validate()
Validates the complete structure of this object.void
Validates the local structure and invariants of this cell.void
Methods inherited from class convex.core.data.ARecord
accumulateEntrySet, accumulateKeySet, accumulateValues, assoc, assocEntry, containsKey, containsValue, dissoc, dissoc, empty, entryAt, entrySet, forEach, get, getEntry, getEntryByHash, getKeyRefEntry, getKeys, getType, getValuesArray, keySet, reduceEntries, reduceValues, toCanonical, toHashMap, values
Methods inherited from class convex.core.data.AMap
clear, conj, containsKey, containsKeyRef, containsValue, entryVector, filterValues, get, get, get, getElementRef, merge, print, put, putAll, remove, slice, slice
Methods inherited from class convex.core.data.ADataStructure
checkIndex, conjAll, count, isDataValue, isEmpty, size, toCVMString
Methods inherited from class convex.core.data.ACell
attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createEncoding, createRef, equals, genericEquals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, hashCode, toString
Methods inherited from class convex.core.data.AObject
attachEncoding, print, print
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, getOrDefault, hashCode, isEmpty, merge, putIfAbsent, remove, replace, replace, replaceAll, size
-
Method Details
-
signRef
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
-
getMessageForRef
-
sign
Create a SignedData by signing a value with the given key pair- Type Parameters:
T
- Type of value to sign- Parameters:
keyPair
- Key pair to sign withvalue
- Any cell value to sign- Returns:
- A new SignedData instance
-
create
Creates a SignedData object with the given parameters. The resulting SignedData will be a short version without the public key.- Type Parameters:
T
- Type of value to sign- Parameters:
sig
- Signature of the supplied dataref
- Ref to the data that has been signed- Returns:
- A new SignedData instance
-
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.- Type Parameters:
T
- Type of value to sign- Parameters:
address
- Public key of the signersig
- Signature of the supplied dataref
- Ref to the data that has been signed- Returns:
- A new SignedData instance
-
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
-
get
-
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. -
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 highly likely to contain the entire object when encoded, including the tag byte. Should not traverse soft Refs, i.e. must be usable on arbitrary partial data structures- Specified by:
estimatedEncodingSize
in interfaceIWriteable
- Overrides:
estimatedEncodingSize
in classARecord
- Returns:
- The estimated size for the binary representation of this object.
-
read
public static <T extends ACell> SignedData<T> read(Blob b, int pos, boolean includeKey) throws BadFormatException Reads a SignedData instance from the given Blob encoding- Parameters:
b
- Blob to read frompos
- Start position in Blob (location of tag byte)- Returns:
- New decoded instance
- Throws:
BadFormatException
- In the event of any encoding error
-
checkSignature
public boolean checkSignature()Validates the signature in this SignedData instance. Caches result- Returns:
- true if valid, false otherwise
-
checkSignature
Validates the signature in this SignedData instance. Caches result- Parameters:
publicKey
- Public key to check against this signature- 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:ACell
Returns true if this Cell is in a canonical representation. Non-canonical objects may be used on a temporary internal basis, they should be converted to canonical representations for general purpose use.- Overrides:
isCanonical
in classARecord
- Returns:
- true if the object is in canonical format, false otherwise
-
isCVMValue
public final boolean isCVMValue()Description copied from class:ACell
Returns true if this cell is a first class CVM Value allowable in the CVM state Sub-structural cells that are not themselves first class values should return false Records and types that are not permissible on the CVM 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- Overrides:
isCVMValue
in classARecord
- Returns:
- true if the object is a CVM Value, false otherwise
-
getRefCount
public final 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.- Overrides:
getRefCount
in classACell
- Returns:
- The number of Refs in this Cell
-
getRef
Description copied from class:ACell
Gets a numbered child Ref from within this Cell. WARNING: May need to convert to a canonical instance -
updateRefs
Description copied from class:ACell
Updates 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. The implementation *should* re-attach any original encoding in order to prevent re-encoding or surplus hashing 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:
updateRefs
in classACell
- Parameters:
func
- Ref update function- Returns:
- Cell with updated Refs
-
validate
Description copied from interface:IValidated
Validates 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:
validate
in interfaceIValidated
- Overrides:
validate
in classACell
- Throws:
InvalidDataException
- If the data Value is invalid in any way
-
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
-
getValueRef
-
isEmbedded
public boolean isEmbedded()SignedData is not embedded. main reason: We always want to persist in store to cache verification status- Overrides:
isEmbedded
in classACell
- Returns:
- Always false
-
getTag
-
getFormat
Description copied from class:ARecord
Gets the RecordFormat instance that describes this Record's layout -
equals
Description copied from class:ACell
Checks for equality with another Cell. In general, Cells are considered equal if they have the same canonical representation, i.e. an identical encoding with the same hash value. Subclasses SHOULD override this if they have a more efficient equals implementation. MUST NOT require reads from Store.
-