2018-06-29 16:08:08 +04:00
|
|
|
(*****************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Open Source License *)
|
|
|
|
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* Permission is hereby granted, free of charge, to any person obtaining a *)
|
|
|
|
(* copy of this software and associated documentation files (the "Software"),*)
|
|
|
|
(* to deal in the Software without restriction, including without limitation *)
|
|
|
|
(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)
|
|
|
|
(* and/or sell copies of the Software, and to permit persons to whom the *)
|
|
|
|
(* Software is furnished to do so, subject to the following conditions: *)
|
|
|
|
(* *)
|
|
|
|
(* The above copyright notice and this permission notice shall be included *)
|
|
|
|
(* in all copies or substantial portions of the Software. *)
|
|
|
|
(* *)
|
|
|
|
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
|
|
|
|
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)
|
|
|
|
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)
|
|
|
|
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
|
|
|
|
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)
|
|
|
|
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)
|
|
|
|
(* DEALINGS IN THE SOFTWARE. *)
|
|
|
|
(* *)
|
|
|
|
(*****************************************************************************)
|
2017-11-27 09:13:12 +04:00
|
|
|
|
|
|
|
(** Tezos - Manipulation and creation of hashes *)
|
|
|
|
|
|
|
|
(** {2 Predefined Hashes } ****************************************************)
|
|
|
|
|
2018-02-08 13:51:01 +04:00
|
|
|
include S.MINIMAL_HASH
|
2018-04-05 18:07:05 +04:00
|
|
|
include S.RAW_DATA with type t := t
|
2017-11-27 09:13:12 +04:00
|
|
|
|
2018-01-30 14:25:14 +04:00
|
|
|
(** {2 Building Hashes} *******************************************************)
|
|
|
|
|
|
|
|
(** The parameters for creating a new Hash type using
|
|
|
|
{!Make_Blake2B}. Both {!name} and {!title} are only informative,
|
|
|
|
used in error messages and serializers. *)
|
|
|
|
|
|
|
|
module type Name = sig
|
|
|
|
val name : string
|
|
|
|
val title : string
|
|
|
|
val size : int option
|
|
|
|
end
|
|
|
|
|
|
|
|
module type PrefixedName = sig
|
|
|
|
include Name
|
|
|
|
val b58check_prefix : string
|
|
|
|
end
|
|
|
|
|
2017-11-27 09:13:12 +04:00
|
|
|
(** Builds a new Hash type using Blake2B. *)
|
2018-02-08 13:51:01 +04:00
|
|
|
module Make_minimal (Name : Name) : S.MINIMAL_HASH
|
2017-11-27 09:13:12 +04:00
|
|
|
module Make
|
|
|
|
(Register : sig
|
|
|
|
val register_encoding:
|
|
|
|
prefix: string ->
|
|
|
|
length: int ->
|
|
|
|
to_raw: ('a -> string) ->
|
|
|
|
of_raw: (string -> 'a option) ->
|
|
|
|
wrap: ('a -> Base58.data) ->
|
|
|
|
'a Base58.encoding
|
|
|
|
end)
|
2018-02-08 13:51:01 +04:00
|
|
|
(Name : PrefixedName) : S.HASH
|
2017-11-27 09:13:12 +04:00
|
|
|
|
|
|
|
(**/**)
|
|
|
|
|
|
|
|
module Make_merkle_tree
|
|
|
|
(R : sig
|
|
|
|
val register_encoding:
|
|
|
|
prefix: string ->
|
|
|
|
length:int ->
|
|
|
|
to_raw: ('a -> string) ->
|
|
|
|
of_raw: (string -> 'a option) ->
|
|
|
|
wrap: ('a -> Base58.data) ->
|
|
|
|
'a Base58.encoding
|
|
|
|
end)
|
2018-01-30 14:25:14 +04:00
|
|
|
(K : PrefixedName)
|
2017-11-27 09:13:12 +04:00
|
|
|
(Contents: sig
|
|
|
|
type t
|
|
|
|
val to_bytes: t -> MBytes.t
|
2018-02-08 13:51:01 +04:00
|
|
|
end) : S.MERKLE_TREE with type elt = Contents.t
|
2017-11-27 09:13:12 +04:00
|
|
|
|
|
|
|
module Generic_Merkle_tree (H : sig
|
|
|
|
type t
|
|
|
|
type elt
|
|
|
|
val empty : t
|
|
|
|
val leaf : elt -> t
|
|
|
|
val node : t -> t -> t
|
|
|
|
end) : sig
|
|
|
|
val compute : H.elt list -> H.t
|
|
|
|
type path =
|
|
|
|
| Left of path * H.t
|
|
|
|
| Right of H.t * path
|
|
|
|
| Op
|
|
|
|
val compute_path: H.elt list -> int -> path
|
|
|
|
val check_path: path -> H.elt -> H.t * int
|
|
|
|
end
|