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>

public final class SignedData<T extends ACell> extends ARecord
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.
The SignedData instance is considered valid if the signature can be successfully validated for the given Address and data value, and if so can be taken as a cryptographic proof that the signature was created by someone in possession of the corresponding private key. Note we currently go via a Ref here for a few reasons: - It guarantees we have a hash for signing - It makes the SignedData object implementation/representation independent of the value type - It creates a possibility of structural sharing for transaction values excluding signatures Binary representation:
  1. 1 byte - Tag.SIGNED_DATA tag
  2. 32 bytes - Public Key of signer
  3. 64 bytes - raw Signature data
  4. 1+ bytes - Data Value Ref (may be embedded)
SECURITY: signing requires presence of a local keypair TODO: SECURITY: any persistence forces validation of Signature??
  • Method Details

    • createWithRef

      public static <T extends ACell> SignedData<T> createWithRef(AKeyPair keyPair, Ref<T> ref)
      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

      public static <T extends ACell> SignedData<T> create(AKeyPair keyPair, T value2)
    • 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 signer
      sig - Signature of the supplied data
      ref - Ref to the data that has been signed
      Returns:
      A new SignedData object
    • create

      public static SignedData<ATransaction> create(AKeyPair kp, ASignature sig, Ref<ATransaction> ref)
    • getValue

      public T getValue()
      Gets the signed value object encapsulated by this SignedData object. Does not check Signature.
      Returns:
      Data value that has been signed
    • getAccountKey

      public AccountKey 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

      public ASignature getSignature()
      Gets the Signature that formed part of this SignedData object
      Returns:
      Signature instance
    • get

      public ACell get(Keyword key)
      Description copied from class: ARecord
      Gets the record field content for a given key, or null if not found.
      Specified by:
      get in class ARecord
      Parameters:
      key - Key to look up in this record
      Returns:
      Field value for the given key
    • 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 interface IWriteable
      Specified by:
      encode in class ACell
      Parameters:
      bs - A byte array to which to write the encoding
      pos - The offset into the byte array
      Returns:
      New position after writing
    • encodeRaw

      public int encodeRaw(byte[] bs, int pos)
      Description copied from class: ARecord
      Writes the raw fields of this record in declared order
      Overrides:
      encodeRaw in class ARecord
      Parameters:
      bs - Array to write to
      pos - The offset into the byte array
      Returns:
      New position after writing
    • 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 interface IWriteable
      Overrides:
      estimatedEncodingSize in class ARecord
      Returns:
      The estimated size for the binary representation of this object.
    • read

      public static <T extends ACell> SignedData<T> read(Blob b, int pos) throws BadFormatException
      Reads a SignedData instance from the given Blob encoding
      Parameters:
      b - Blob to read from
      pos - 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
    • 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

      public void validateSignature() throws BadSignatureException
      Throws:
      BadSignatureException
    • 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).
      Overrides:
      isCanonical in class ARecord
      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 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
      Overrides:
      isCVMValue in class ARecord
      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. WARNING: may not be valid id Cell is not canonical Contained Refs may be either external or embedded.
      Specified by:
      getRefCount in class ACell
      Returns:
      The number of Refs in this Cell
    • getRef

      public <R extends ACell> Ref<R> getRef(int i)
      Description copied from class: ACell
      Gets a numbered child Ref from within this Cell. WARNING: May be unreliable is cell is not canonical
      Overrides:
      getRef in class ACell
      Type Parameters:
      R - Type of referenced Cell
      Parameters:
      i - Index of ref to get
      Returns:
      The Ref at the specified index
    • updateRefs

      public SignedData<T> updateRefs(IRefFunction func)
      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 class ACell
      Parameters:
      func - Ref update function
      Returns:
      Cell with updated Refs
    • validate

      public void validate() throws InvalidDataException
      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:
      1. Call super.validate() - which will indirectly call validateCell()
      2. Call validate() on any contained cells in this class
      Specified by:
      validate in interface IValidated
      Overrides:
      validate in class ACell
      Throws:
      InvalidDataException - If the data Value is invalid in any way
    • validateCell

      public void validateCell() throws InvalidDataException
      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 class ACell
      Throws:
      InvalidDataException - If the Cell is invalid
    • getValueRef

      public Ref<T> getValueRef()
    • isEmbedded

      public boolean isEmbedded()
      SignedData is not embedded. We want to persist in store always to cache verification status
      Overrides:
      isEmbedded in class ACell
      Returns:
      Always false
    • getTag

      public byte getTag()
      Description copied from class: ARecord
      Gets the tag byte for this record type. The Tag is the byte used to identify the record in the binary encoding.
      Specified by:
      getTag in class ARecord
      Returns:
      Record tag byte
    • getFormat

      public RecordFormat getFormat()
      Description copied from class: ARecord
      Gets the RecordFormat instance that describes this Record's layout
      Specified by:
      getFormat in class ARecord
      Returns:
      RecordFormat instance