Class CrumTrail

java.lang.Object
io.crums.util.mrkl.Proof
io.crums.model.CrumTrail
All Implemented Interfaces:
io.crums.io.Serial

public class CrumTrail
extends io.crums.util.mrkl.Proof
implements io.crums.io.Serial
A Merkle proof of a crum. Since the root hash is timestamped at multiple public locations, this object proves a hash was witnessed within some error bars of that recording. Note this has nothing to do with the crum's utc value.
See Also:
crum(), Proof
  • Constructor Summary

    Constructors
    Constructor Description
    CrumTrail​(int leafCount, int leafIndex, byte[][] chain, Crum crum)  
    CrumTrail​(io.crums.util.mrkl.Proof proof, Crum crum)  
    CrumTrail​(io.crums.util.mrkl.Tree tree, int leafIndex, Crum crum)  
  • Method Summary

    Modifier and Type Method Description
    Crum crum()
    Returns the crum in this proof.
    java.nio.ByteBuffer hashedCrum()
    Returns the SHA-256 hash of the crum.
    static CrumTrail load​(java.nio.ByteBuffer in)  
    static CrumTrail load​(java.nio.channels.ReadableByteChannel in)
    Loads and returns an instance from the given stream.
    static CrumTrail load​(java.nio.channels.ReadableByteChannel in, java.nio.ByteBuffer work)
    Loads and returns an instance from the given stream.
    int serialSize()  
    Statement toStatement()
    Returns this Merkle proof as a hash statement.
    boolean verify()  
    boolean verifyTrail​(java.security.MessageDigest digest)
    Verifies this crum trail.
    java.nio.ByteBuffer writeTo​(java.nio.ByteBuffer buffer)  

    Methods inherited from class io.crums.util.mrkl.Proof

    chainLength, equals, getHashAlgo, hashChain, hashCode, item, leafCount, leafIndex, rootHash, verify

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.crums.io.Serial

    serialize
  • Constructor Details

    • CrumTrail

      public CrumTrail​(io.crums.util.mrkl.Tree tree, int leafIndex, Crum crum)
    • CrumTrail

      public CrumTrail​(int leafCount, int leafIndex, byte[][] chain, Crum crum)
    • CrumTrail

      public CrumTrail​(io.crums.util.mrkl.Proof proof, Crum crum)
  • Method Details

    • load

      public static CrumTrail load​(java.nio.channels.ReadableByteChannel in) throws java.io.IOException
      Loads and returns an instance from the given stream. Does not read beyond the crumtrail's data (which is of variable length).
      Parameters:
      in - the steam to load from
      Throws:
      java.io.IOException
      See Also:
      writeTo(ByteBuffer)
    • load

      public static CrumTrail load​(java.nio.channels.ReadableByteChannel in, java.nio.ByteBuffer work) throws java.io.IOException
      Loads and returns an instance from the given stream. Does not read beyond the crumtrail's data (which is of variable length).
      Parameters:
      in - the steam to load from
      work - work buffer with at least 8 bytes capacity (2k recommended)
      Throws:
      java.io.IOException
      See Also:
      writeTo(ByteBuffer)
    • load

      public static CrumTrail load​(java.nio.ByteBuffer in) throws java.nio.BufferUnderflowException
      Throws:
      java.nio.BufferUnderflowException
    • verify

      public final boolean verify()
    • crum

      public final Crum crum()
      Returns the crum in this proof. The first element of the Proof.hashChain() is the hash of the returned crum.
      Returns:
      the crum this proof is about
    • hashedCrum

      public final java.nio.ByteBuffer hashedCrum()
      Returns the SHA-256 hash of the crum. This is just a synonym for Proof.item().
    • verifyTrail

      public final boolean verifyTrail​(java.security.MessageDigest digest)
      Verifies this crum trail. This involves both verifying the hash pointers that make up the Merkle proof and also checking that the leaf hash indeed matches the hash of the crum.
    • writeTo

      public java.nio.ByteBuffer writeTo​(java.nio.ByteBuffer buffer) throws java.nio.BufferOverflowException
      Specified by:
      writeTo in interface io.crums.io.Serial
      Throws:
      java.nio.BufferOverflowException
    • serialSize

      public int serialSize()
      Specified by:
      serialSize in interface io.crums.io.Serial
    • toStatement

      public Statement toStatement()
      Returns this Merkle proof as a hash statement. On inspecting its LHS, the first literals a human user sees are the hex of the crum's hash and the hex of the crum's UTC expressed as an 8-byte sequence (size of long), seperated by a space character. On the RHS, the user finds the value of the root of the Merkle tree. This serves as a "full" hash pointer: it can be used to construct a URL to reference the tree's permanent record at https://crums.io.
      Returns:
      a statement that evaluates to true