Class HashCash

    • Method Detail

      • mintCash

        public static HashCash mintCash​(String resource,
                                        int value,
                                        int version)
                                 throws NoSuchAlgorithmException
        Mints a HashCash using now as the date
        Parameters:
        resource - the string to be encoded in the HashCash
        version - Which version to mint. Only valid values are 0 and 1
        Throws:
        NoSuchAlgorithmException - If SHA1 is not a supported Message Digest
      • mintCash

        public static HashCash mintCash​(String resource,
                                        Calendar date,
                                        int value,
                                        int version)
                                 throws NoSuchAlgorithmException
        Mints a HashCash
        Parameters:
        resource - the string to be encoded in the HashCash
        version - Which version to mint. Only valid values are 0 and 1
        Throws:
        NoSuchAlgorithmException - If SHA1 is not a supported Message Digest
      • mintCash

        public static HashCash mintCash​(String resource,
                                        Map<String,​List<String>> extensions,
                                        int value,
                                        int version)
                                 throws NoSuchAlgorithmException
        Mints a HashCash using now as the date
        Parameters:
        resource - the string to be encoded in the HashCash
        extensions - Extra data to be encoded in the HashCash
        version - Which version to mint. Only valid values are 0 and 1
        Throws:
        NoSuchAlgorithmException - If SHA1 is not a supported Message Digest
      • mintCash

        public static HashCash mintCash​(String resource,
                                        Map<String,​List<String>> extensions,
                                        Calendar date,
                                        int value,
                                        int version)
                                 throws NoSuchAlgorithmException
        Mints a HashCash
        Parameters:
        resource - the string to be encoded in the HashCash
        extensions - Extra data to be encoded in the HashCash
        version - Which version to mint. Only valid values are 0 and 1
        Throws:
        NoSuchAlgorithmException - If SHA1 is not a supported Message Digest
      • equals

        public boolean equals​(Object obj)
        Two objects are considered equal if they are both of type HashCash and have an identical string representation
        Overrides:
        equals in class Object
      • hashCode

        public int hashCode()
        Implemented based on definition of equals()
        Overrides:
        hashCode in class Object
      • toString

        public String toString()
        Returns the canonical string representation of the HashCash
        Overrides:
        toString in class Object
      • getExtensions

        public Map<String,​List<String>> getExtensions()
        Extra data encoded in the HashCash
      • getResource

        public String getResource()
        The primary resource being protected
      • getDate

        public Calendar getDate()
        The minting date
      • getValue

        public int getValue()
        The value of the HashCash (e.g. how many leading zero bits it has)
      • getVersion

        public int getVersion()
        Which version of HashCash is used here
      • estimateTime

        public static long estimateTime​(int value)
                                 throws NoSuchAlgorithmException
        Estimates how many milliseconds it would take to mint a cash of the specified value.
        • NOTE1: Minting time can vary greatly in fact, half of the time it will take half as long)
        • NOTE2: The first time that an estimation function is called it is expensive (on the order of seconds). After that, it is very quick.
        Throws:
        NoSuchAlgorithmException - If SHA1 is not a supported Message Digest
      • estimateValue

        public static int estimateValue​(int secs)
                                 throws NoSuchAlgorithmException
        Estimates what value (e.g. how many bits of collision) are required for the specified length of time.
        • NOTE1: Minting time can vary greatly in fact, half of the time it will take half as long)
        • NOTE2: The first time that an estimation function is called it is expensive (on the order of seconds). After that, it is very quick.
        Throws:
        NoSuchAlgorithmException - If SHA1 is not a supported Message Digest