Client refactor: simpler dependencies in tezos-crypto
This commit is contained in:
parent
2f295a3af8
commit
f22b3576d2
187
src/lib_base/blake2B.ml
Normal file
187
src/lib_base/blake2B.ml
Normal file
@ -0,0 +1,187 @@
|
|||||||
|
(**************************************************************************)
|
||||||
|
(* *)
|
||||||
|
(* Copyright (c) 2014 - 2018. *)
|
||||||
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
||||||
|
(* *)
|
||||||
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
||||||
|
(* *)
|
||||||
|
(**************************************************************************)
|
||||||
|
|
||||||
|
open Tezos_crypto
|
||||||
|
open Error_monad
|
||||||
|
|
||||||
|
module Extend(H : Tezos_crypto.S.HASH) = struct
|
||||||
|
|
||||||
|
include H
|
||||||
|
|
||||||
|
let encoding =
|
||||||
|
let open Data_encoding in
|
||||||
|
splitted
|
||||||
|
~binary:
|
||||||
|
(conv H.to_bytes H.of_bytes_exn (Fixed.bytes H.size))
|
||||||
|
~json:
|
||||||
|
(describe ~title: (H.title ^ " (Base58Check-encoded Blake2B hash)") @@
|
||||||
|
conv H.to_b58check (Data_encoding.Json.wrap_error H.of_b58check_exn) string)
|
||||||
|
|
||||||
|
let of_b58check s =
|
||||||
|
match H.of_b58check_opt s with
|
||||||
|
| Some x -> Ok x
|
||||||
|
| None ->
|
||||||
|
generic_error "Failed to read a base58-encoded hash (%s)" H.name
|
||||||
|
|
||||||
|
let of_bytes s =
|
||||||
|
match H.of_bytes_opt s with
|
||||||
|
| Some x -> Ok x
|
||||||
|
| None ->
|
||||||
|
generic_error "Failed to deserialize a hash (%s)" H.name
|
||||||
|
|
||||||
|
let rpc_arg =
|
||||||
|
RPC_arg.make
|
||||||
|
~name:(Format.asprintf "hash.%s" H.name)
|
||||||
|
~descr:(Format.asprintf "A b58check-encoded hash (%s)" H.name)
|
||||||
|
~destruct:
|
||||||
|
(fun s ->
|
||||||
|
match H.of_b58check_opt s with
|
||||||
|
| None ->
|
||||||
|
Error (Format.asprintf
|
||||||
|
"failed to decode b58check-encoded hash (%s): %S"
|
||||||
|
H.name s)
|
||||||
|
| Some v -> Ok v)
|
||||||
|
~construct:H.to_b58check
|
||||||
|
()
|
||||||
|
|
||||||
|
let param ?(name=H.name) ?(desc=H.title) t =
|
||||||
|
Cli_entries.param
|
||||||
|
~name
|
||||||
|
~desc (Cli_entries.parameter (fun _ str -> Lwt.return (of_b58check str))) t
|
||||||
|
|
||||||
|
module Set = struct
|
||||||
|
include Set.Make(struct type nonrec t = t let compare = compare end)
|
||||||
|
exception Found of elt
|
||||||
|
let random_elt s =
|
||||||
|
let n = Random.int (cardinal s) in
|
||||||
|
try
|
||||||
|
ignore
|
||||||
|
(fold (fun x i -> if i = n then raise (Found x) ; i+1) s 0 : int) ;
|
||||||
|
assert false
|
||||||
|
with Found x -> x
|
||||||
|
let encoding =
|
||||||
|
Data_encoding.conv
|
||||||
|
elements
|
||||||
|
(fun l -> List.fold_left (fun m x -> add x m) empty l)
|
||||||
|
Data_encoding.(list encoding)
|
||||||
|
end
|
||||||
|
|
||||||
|
module Table = struct
|
||||||
|
include Hashtbl.Make(struct
|
||||||
|
type t = H.t
|
||||||
|
let hash =
|
||||||
|
if H.size >= 64 then
|
||||||
|
fun h -> Int64.to_int (MBytes.get_int64 (H.to_bytes h) 0)
|
||||||
|
else if H.size >= 32 then
|
||||||
|
fun h -> Int32.to_int (MBytes.get_int32 (H.to_bytes h) 0)
|
||||||
|
else
|
||||||
|
fun h ->
|
||||||
|
let r = ref 0 in
|
||||||
|
let h = H.to_bytes h in
|
||||||
|
for i = 0 to H.size / 8 - 1 do
|
||||||
|
r := MBytes.get_uint8 h i + 8 * !r
|
||||||
|
done ;
|
||||||
|
!r
|
||||||
|
let equal = H.equal
|
||||||
|
end)
|
||||||
|
let encoding arg_encoding =
|
||||||
|
Data_encoding.conv
|
||||||
|
(fun h -> fold (fun k v l -> (k, v) :: l) h [])
|
||||||
|
(fun l ->
|
||||||
|
let h = create (List.length l) in
|
||||||
|
List.iter (fun (k,v) -> add h k v) l ;
|
||||||
|
h)
|
||||||
|
Data_encoding.(list (tup2 encoding arg_encoding))
|
||||||
|
end
|
||||||
|
|
||||||
|
module Map = struct
|
||||||
|
include Map.Make(struct type nonrec t = t let compare = compare end)
|
||||||
|
let encoding arg_encoding =
|
||||||
|
Data_encoding.conv
|
||||||
|
bindings
|
||||||
|
(fun l -> List.fold_left (fun m (k,v) -> add k v m) empty l)
|
||||||
|
Data_encoding.(list (tup2 encoding arg_encoding))
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
module Extend_merkle_tree(H : Tezos_crypto.S.MERKLE_TREE) = struct
|
||||||
|
|
||||||
|
include Extend(H)
|
||||||
|
|
||||||
|
type elt = H.elt
|
||||||
|
let elt_bytes = H.elt_bytes
|
||||||
|
|
||||||
|
let empty = hash_bytes []
|
||||||
|
|
||||||
|
include Tezos_crypto.Blake2B.Generic_Merkle_tree(struct
|
||||||
|
type nonrec t = t
|
||||||
|
type nonrec elt = elt
|
||||||
|
let empty = empty
|
||||||
|
let leaf x = hash_bytes [H.elt_bytes x]
|
||||||
|
let node x y = hash_bytes [to_bytes x; to_bytes y]
|
||||||
|
end)
|
||||||
|
|
||||||
|
let path_encoding =
|
||||||
|
let open Data_encoding in
|
||||||
|
mu "path"
|
||||||
|
(fun path_encoding ->
|
||||||
|
union [
|
||||||
|
case (Tag 240)
|
||||||
|
(obj2
|
||||||
|
(req "path" path_encoding)
|
||||||
|
(req "right" encoding))
|
||||||
|
(function Left (p, r) -> Some (p, r) | _ -> None)
|
||||||
|
(fun (p, r) -> Left (p, r)) ;
|
||||||
|
case (Tag 15)
|
||||||
|
(obj2
|
||||||
|
(req "left" encoding)
|
||||||
|
(req "path" path_encoding))
|
||||||
|
(function Right (r, p) -> Some (r, p) | _ -> None)
|
||||||
|
(fun (r, p) -> Right (r, p)) ;
|
||||||
|
case (Tag 0)
|
||||||
|
unit
|
||||||
|
(function Op -> Some () | _ -> None)
|
||||||
|
(fun () -> Op)
|
||||||
|
])
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
module type Name = Blake2B.Name
|
||||||
|
module type PrefixedName = Blake2B.PrefixedName
|
||||||
|
module Make_minimal = Blake2B.Make_minimal
|
||||||
|
module Make
|
||||||
|
(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)
|
||||||
|
(K : Blake2B.PrefixedName) =
|
||||||
|
Extend(Blake2B.Make(R)(K))
|
||||||
|
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)
|
||||||
|
(K : PrefixedName)
|
||||||
|
(Contents: sig
|
||||||
|
type t
|
||||||
|
val to_bytes: t -> MBytes.t
|
||||||
|
end) =
|
||||||
|
Extend_merkle_tree(Blake2B.Make_merkle_tree(R)(K)(Contents))
|
||||||
|
module Generic_Merkle_tree = Blake2B.Generic_Merkle_tree
|
75
src/lib_base/blake2B.mli
Normal file
75
src/lib_base/blake2B.mli
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
(**************************************************************************)
|
||||||
|
(* *)
|
||||||
|
(* Copyright (c) 2014 - 2018. *)
|
||||||
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
||||||
|
(* *)
|
||||||
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
||||||
|
(* *)
|
||||||
|
(**************************************************************************)
|
||||||
|
|
||||||
|
(** Builds a new Hash type using Blake2B. *)
|
||||||
|
|
||||||
|
(** 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
|
||||||
|
|
||||||
|
module Make_minimal (Name : Name) : S.MINIMAL_HASH
|
||||||
|
module Make
|
||||||
|
(Register : sig
|
||||||
|
val register_encoding:
|
||||||
|
prefix: string ->
|
||||||
|
length: int ->
|
||||||
|
to_raw: ('a -> string) ->
|
||||||
|
of_raw: (string -> 'a option) ->
|
||||||
|
wrap: ('a -> Tezos_crypto.Base58.data) ->
|
||||||
|
'a Tezos_crypto.Base58.encoding
|
||||||
|
end)
|
||||||
|
(Name : PrefixedName) : S.INTERNAL_HASH
|
||||||
|
|
||||||
|
module Make_merkle_tree
|
||||||
|
(R : sig
|
||||||
|
val register_encoding:
|
||||||
|
prefix: string ->
|
||||||
|
length:int ->
|
||||||
|
to_raw: ('a -> string) ->
|
||||||
|
of_raw: (string -> 'a option) ->
|
||||||
|
wrap: ('a -> Tezos_crypto.Base58.data) ->
|
||||||
|
'a Tezos_crypto.Base58.encoding
|
||||||
|
end)
|
||||||
|
(K : PrefixedName)
|
||||||
|
(Contents: sig
|
||||||
|
type t
|
||||||
|
val to_bytes: t -> MBytes.t
|
||||||
|
end) : S.INTERNAL_MERKLE_TREE with type elt = Contents.t
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
module Extend (H: Tezos_crypto.S.HASH)
|
||||||
|
: S.INTERNAL_HASH with type t = H.t
|
||||||
|
module Extend_merkle_tree (H: Tezos_crypto.S.MERKLE_TREE)
|
||||||
|
: S.INTERNAL_MERKLE_TREE with type t = H.t and type elt = H.elt
|
@ -7,12 +7,12 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
include Blake2B.Make (Base58) (struct
|
include Blake2B.Make (Tezos_crypto.Base58) (struct
|
||||||
let name = "Block_hash"
|
let name = "Block_hash"
|
||||||
let title = "A Tezos block ID"
|
let title = "A Tezos block ID"
|
||||||
let b58check_prefix = Base58.Prefix.block_hash
|
let b58check_prefix = Tezos_crypto.Base58.Prefix.block_hash
|
||||||
let size = None
|
let size = None
|
||||||
end)
|
end)
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
Base58.check_encoded_prefix b58check_encoding "B" 51
|
Tezos_crypto.Base58.check_encoded_prefix b58check_encoding "B" 51
|
||||||
|
@ -7,4 +7,4 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
include Tezos_crypto.S.INTERNAL_HASH
|
include S.INTERNAL_HASH
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
include Blake2B.Make (Base58) (struct
|
include Blake2B.Make (Tezos_crypto.Base58) (struct
|
||||||
let name = "Context_hash"
|
let name = "Context_hash"
|
||||||
let title = "A hash of context"
|
let title = "A hash of context"
|
||||||
let b58check_prefix = Base58.Prefix.context_hash
|
let b58check_prefix = Tezos_crypto.Base58.Prefix.context_hash
|
||||||
let size = None
|
let size = None
|
||||||
end)
|
end)
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
Base58.check_encoded_prefix b58check_encoding "Co" 52
|
Tezos_crypto.Base58.check_encoded_prefix b58check_encoding "Co" 52
|
||||||
|
@ -7,4 +7,4 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
include Tezos_crypto.S.INTERNAL_HASH
|
include S.INTERNAL_HASH
|
||||||
|
32
src/lib_base/crypto_box.ml
Normal file
32
src/lib_base/crypto_box.ml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
(**************************************************************************)
|
||||||
|
(* *)
|
||||||
|
(* Copyright (c) 2014 - 2018. *)
|
||||||
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
||||||
|
(* *)
|
||||||
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
||||||
|
(* *)
|
||||||
|
(**************************************************************************)
|
||||||
|
|
||||||
|
include Tezos_crypto.Crypto_box
|
||||||
|
|
||||||
|
let public_key_encoding =
|
||||||
|
let open Data_encoding in
|
||||||
|
conv
|
||||||
|
public_key_to_bigarray
|
||||||
|
public_key_of_bigarray
|
||||||
|
(Fixed.bytes public_key_size)
|
||||||
|
|
||||||
|
let secret_key_encoding =
|
||||||
|
let open Data_encoding in
|
||||||
|
conv
|
||||||
|
secret_key_to_bigarray
|
||||||
|
secret_key_of_bigarray
|
||||||
|
(Fixed.bytes secret_key_size)
|
||||||
|
|
||||||
|
let nonce_encoding =
|
||||||
|
let open Data_encoding in
|
||||||
|
conv
|
||||||
|
nonce_to_bigarray
|
||||||
|
nonce_of_bigarray
|
||||||
|
(Fixed.bytes nonce_size)
|
||||||
|
|
14
src/lib_base/crypto_box.mli
Normal file
14
src/lib_base/crypto_box.mli
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
(**************************************************************************)
|
||||||
|
(* *)
|
||||||
|
(* Copyright (c) 2014 - 2018. *)
|
||||||
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
||||||
|
(* *)
|
||||||
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
||||||
|
(* *)
|
||||||
|
(**************************************************************************)
|
||||||
|
|
||||||
|
include (module type of Tezos_crypto.Crypto_box)
|
||||||
|
|
||||||
|
val public_key_encoding : public_key Data_encoding.t
|
||||||
|
val secret_key_encoding : secret_key Data_encoding.t
|
||||||
|
val nonce_encoding : nonce Data_encoding.t
|
111
src/lib_base/ed25519.ml
Normal file
111
src/lib_base/ed25519.ml
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
|
||||||
|
module Public_key_hash = Blake2B.Extend (Tezos_crypto.Ed25519.Public_key_hash)
|
||||||
|
|
||||||
|
module Public_key = struct
|
||||||
|
include Tezos_crypto.Ed25519.Public_key
|
||||||
|
let encoding =
|
||||||
|
let open Data_encoding in
|
||||||
|
splitted
|
||||||
|
~json:
|
||||||
|
(describe
|
||||||
|
~title: "An Ed25519 public key (Tezos_crypto.Base58Check encoded)" @@
|
||||||
|
conv
|
||||||
|
(fun s -> to_b58check s)
|
||||||
|
(fun s ->
|
||||||
|
match of_b58check_opt s with
|
||||||
|
| Some x -> x
|
||||||
|
| None -> Data_encoding.Json.cannot_destruct
|
||||||
|
"Ed25519 public key: unexpected prefix.")
|
||||||
|
string)
|
||||||
|
~binary:
|
||||||
|
(conv
|
||||||
|
to_bytes
|
||||||
|
of_bytes_exn
|
||||||
|
(Fixed.bytes size))
|
||||||
|
let of_b58check s =
|
||||||
|
match of_b58check_opt s with
|
||||||
|
| Some x -> Ok x
|
||||||
|
| None ->
|
||||||
|
Error_monad.generic_error
|
||||||
|
"Failed to read a base58-encoded Ed25519 public key"
|
||||||
|
let param
|
||||||
|
?(name="ed25519-public")
|
||||||
|
?(desc="Ed25519 public key (b58check-encoded)") t =
|
||||||
|
Cli_entries.(param ~name ~desc
|
||||||
|
(parameter (fun _ str -> Lwt.return (of_b58check str))) t)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
module Secret_key = struct
|
||||||
|
include Tezos_crypto.Ed25519.Secret_key
|
||||||
|
let encoding =
|
||||||
|
let open Data_encoding in
|
||||||
|
splitted
|
||||||
|
~json:
|
||||||
|
(describe
|
||||||
|
~title: "An Ed25519 secret key (Tezos_crypto.Base58Check encoded)" @@
|
||||||
|
conv
|
||||||
|
(fun s -> to_b58check s)
|
||||||
|
(fun s ->
|
||||||
|
match of_b58check_opt s with
|
||||||
|
| Some x -> x
|
||||||
|
| None -> Data_encoding.Json.cannot_destruct
|
||||||
|
"Ed25519 secret key: unexpected prefix.")
|
||||||
|
string)
|
||||||
|
~binary:
|
||||||
|
(conv
|
||||||
|
to_bytes
|
||||||
|
of_bytes_exn
|
||||||
|
(Fixed.bytes size))
|
||||||
|
let of_b58check s =
|
||||||
|
match of_b58check_opt s with
|
||||||
|
| Some x -> Ok x
|
||||||
|
| None ->
|
||||||
|
Error_monad.generic_error
|
||||||
|
"Failed to read a base58-encoded Ed25519 secret key"
|
||||||
|
let param
|
||||||
|
?(name="ed25519-secret")
|
||||||
|
?(desc="Ed25519 secret key (b58check-encoded)") t =
|
||||||
|
Cli_entries.(param ~name ~desc
|
||||||
|
(parameter (fun _ str -> Lwt.return (of_b58check str))) t)
|
||||||
|
end
|
||||||
|
|
||||||
|
module Signature = struct
|
||||||
|
include Tezos_crypto.Ed25519.Signature
|
||||||
|
let encoding =
|
||||||
|
let open Data_encoding in
|
||||||
|
splitted
|
||||||
|
~json:
|
||||||
|
(describe
|
||||||
|
~title: "An Ed25519 signature (Base58Check encoded)" @@
|
||||||
|
conv
|
||||||
|
(fun s -> to_b58check s)
|
||||||
|
(fun s ->
|
||||||
|
match of_b58check_opt s with
|
||||||
|
| Some x -> x
|
||||||
|
| None -> Data_encoding.Json.cannot_destruct
|
||||||
|
"Ed25519 signature: unexpected prefix.")
|
||||||
|
string)
|
||||||
|
~binary:
|
||||||
|
(conv
|
||||||
|
to_bytes
|
||||||
|
of_bytes_exn
|
||||||
|
(Fixed.bytes size))
|
||||||
|
let of_b58check s =
|
||||||
|
match of_b58check_opt s with
|
||||||
|
| Some x -> Ok x
|
||||||
|
| None ->
|
||||||
|
Error_monad.generic_error
|
||||||
|
"Failed to read a base58-encoded Ed25519 signature"
|
||||||
|
let param
|
||||||
|
?(name="ed25519-signature")
|
||||||
|
?(desc="Ed25519 signature (b58check-encoded)") t =
|
||||||
|
Cli_entries.(param ~name ~desc
|
||||||
|
(parameter (fun _ str -> Lwt.return (of_b58check str))) t)
|
||||||
|
end
|
||||||
|
|
||||||
|
include (Tezos_crypto.Ed25519 : (module type of Tezos_crypto.Ed25519)
|
||||||
|
with module Public_key_hash := Public_key_hash
|
||||||
|
and module Public_key := Public_key
|
||||||
|
and module Secret_key := Secret_key
|
||||||
|
and module Signature := Signature)
|
44
src/lib_base/ed25519.mli
Normal file
44
src/lib_base/ed25519.mli
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
open Error_monad
|
||||||
|
|
||||||
|
module Public_key_hash :
|
||||||
|
S.INTERNAL_HASH with type t = Tezos_crypto.Ed25519.Public_key_hash.t
|
||||||
|
|
||||||
|
module Public_key : sig
|
||||||
|
include (module type of Tezos_crypto.Ed25519.Public_key)
|
||||||
|
val encoding: t Data_encoding.t
|
||||||
|
val param:
|
||||||
|
?name:string ->
|
||||||
|
?desc:string ->
|
||||||
|
('a, 'b, 'c) Cli_entries.params ->
|
||||||
|
(t -> 'a, 'b, 'c) Cli_entries.params
|
||||||
|
val of_b58check: string -> t tzresult
|
||||||
|
end
|
||||||
|
|
||||||
|
module Secret_key : sig
|
||||||
|
include (module type of Tezos_crypto.Ed25519.Secret_key)
|
||||||
|
val encoding: t Data_encoding.t
|
||||||
|
val param:
|
||||||
|
?name:string ->
|
||||||
|
?desc:string ->
|
||||||
|
('a, 'b, 'c) Cli_entries.params ->
|
||||||
|
(t -> 'a, 'b, 'c) Cli_entries.params
|
||||||
|
val of_b58check: string -> t tzresult
|
||||||
|
end
|
||||||
|
|
||||||
|
module Signature : sig
|
||||||
|
include (module type of Tezos_crypto.Ed25519.Signature)
|
||||||
|
val encoding: t Data_encoding.t
|
||||||
|
val param:
|
||||||
|
?name:string ->
|
||||||
|
?desc:string ->
|
||||||
|
('a, 'b, 'c) Cli_entries.params ->
|
||||||
|
(t -> 'a, 'b, 'c) Cli_entries.params
|
||||||
|
val of_b58check: string -> t tzresult
|
||||||
|
end
|
||||||
|
|
||||||
|
include (module type of Tezos_crypto.Ed25519)
|
||||||
|
with module Public_key_hash := Public_key_hash
|
||||||
|
and module Public_key := Public_key
|
||||||
|
and module Secret_key := Secret_key
|
||||||
|
and module Signature := Signature
|
@ -7,166 +7,104 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
open Error_monad
|
module Raw = struct
|
||||||
|
|
||||||
type t = string
|
type t = string
|
||||||
|
|
||||||
let name = "Net_id"
|
let name = "Net_id"
|
||||||
let title = "Network identifier"
|
let title = "Network identifier"
|
||||||
|
|
||||||
let size = 4
|
let extract bh =
|
||||||
|
MBytes.substring (Block_hash.to_bytes bh) 0 4
|
||||||
|
let hash_bytes l = extract (Block_hash.hash_bytes l)
|
||||||
|
let hash_string l = extract (Block_hash.hash_string l)
|
||||||
|
|
||||||
let extract bh =
|
let size = 4
|
||||||
MBytes.substring (Block_hash.to_bytes bh) 0 4
|
|
||||||
|
|
||||||
let hash_bytes l = extract (Block_hash.hash_bytes l)
|
let compare = String.compare
|
||||||
let hash_string l = extract (Block_hash.hash_string l)
|
let equal = String.equal
|
||||||
|
|
||||||
|
let of_string s =
|
||||||
|
if String.length s <> size then None else Some s
|
||||||
|
let of_string_exn s =
|
||||||
|
match of_string s with
|
||||||
|
| None ->
|
||||||
|
let msg =
|
||||||
|
Printf.sprintf "%s.of_string: wrong string size (%d)"
|
||||||
|
name (String.length s) in
|
||||||
|
raise (Invalid_argument msg)
|
||||||
|
| Some h -> h
|
||||||
|
|
||||||
|
let to_string s = s
|
||||||
|
let of_hex s = of_string (Hex.to_string (`Hex s))
|
||||||
|
let of_hex_exn s = of_string_exn (Hex.to_string (`Hex s))
|
||||||
|
let to_hex s =
|
||||||
|
let `Hex s = Hex.of_string (to_string s) in
|
||||||
|
s
|
||||||
|
|
||||||
|
|
||||||
|
let of_bytes_opt b =
|
||||||
|
if MBytes.length b <> size then
|
||||||
|
None
|
||||||
|
else
|
||||||
|
Some (MBytes.to_string b)
|
||||||
|
let of_bytes_exn b =
|
||||||
|
match of_bytes_opt b with
|
||||||
|
| None ->
|
||||||
|
let msg =
|
||||||
|
Printf.sprintf "%s.of_bytes: wrong string size (%d)"
|
||||||
|
name (MBytes.length b) in
|
||||||
|
raise (Invalid_argument msg)
|
||||||
|
| Some h -> h
|
||||||
|
let to_bytes = MBytes.of_string
|
||||||
|
|
||||||
|
let read src off = of_bytes_exn @@ MBytes.sub src off size
|
||||||
|
let write dst off h = MBytes.blit (to_bytes h) 0 dst off size
|
||||||
|
|
||||||
|
let path_length = 1
|
||||||
|
let to_path key l = to_hex key :: l
|
||||||
|
let of_path path =
|
||||||
|
let path = String.concat "" path in
|
||||||
|
of_hex path
|
||||||
|
let of_path_exn path =
|
||||||
|
let path = String.concat "" path in
|
||||||
|
of_hex_exn path
|
||||||
|
|
||||||
|
let prefix_path p =
|
||||||
|
let `Hex p = Hex.of_string p in
|
||||||
|
[ p ]
|
||||||
|
|
||||||
|
let zero =
|
||||||
|
match of_hex (String.make (size * 2) '0') with
|
||||||
|
| Some c -> c
|
||||||
|
| None -> assert false
|
||||||
|
|
||||||
|
type Tezos_crypto.Base58.data += Hash of t
|
||||||
|
|
||||||
|
let b58check_encoding =
|
||||||
|
Tezos_crypto.Base58.register_encoding
|
||||||
|
~prefix: Tezos_crypto.Base58.Prefix.net_id
|
||||||
|
~length: size
|
||||||
|
~wrap: (fun s -> Hash s)
|
||||||
|
~of_raw:of_string ~to_raw: (fun h -> h)
|
||||||
|
|
||||||
|
let of_b58check_opt s =
|
||||||
|
Tezos_crypto.Base58.simple_decode b58check_encoding s
|
||||||
|
let of_b58check_exn s =
|
||||||
|
match Tezos_crypto.Base58.simple_decode b58check_encoding s with
|
||||||
|
| Some x -> x
|
||||||
|
| None -> Format.kasprintf Pervasives.failwith "Unexpected hash (%s)" name
|
||||||
|
let to_b58check s = Tezos_crypto.Base58.simple_encode b58check_encoding s
|
||||||
|
let to_short_b58check = to_b58check
|
||||||
|
|
||||||
|
let pp ppf t =
|
||||||
|
Format.pp_print_string ppf (to_b58check t)
|
||||||
|
|
||||||
|
let pp_short ppf t =
|
||||||
|
Format.pp_print_string ppf (to_short_b58check t)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
include Blake2B.Extend(Raw)
|
||||||
|
|
||||||
let of_block_hash bh = hash_bytes [Block_hash.to_bytes bh]
|
let of_block_hash bh = hash_bytes [Block_hash.to_bytes bh]
|
||||||
|
|
||||||
type Base58.data += Hash of t
|
|
||||||
|
|
||||||
let of_string s =
|
|
||||||
if String.length s <> size then None else Some s
|
|
||||||
let of_string_exn s =
|
|
||||||
match of_string s with
|
|
||||||
| None ->
|
|
||||||
let msg =
|
|
||||||
Printf.sprintf "%s.of_string: wrong string size (%d)"
|
|
||||||
name (String.length s) in
|
|
||||||
raise (Invalid_argument msg)
|
|
||||||
| Some h -> h
|
|
||||||
let to_string s = s
|
|
||||||
|
|
||||||
let of_hex s = of_string (Hex.to_string (`Hex s))
|
|
||||||
let of_hex_exn s = of_string_exn (Hex.to_string (`Hex s))
|
|
||||||
let to_hex s =
|
|
||||||
let `Hex s = Hex.of_string (to_string s) in
|
|
||||||
s
|
|
||||||
|
|
||||||
let compare = String.compare
|
|
||||||
let equal = String.equal
|
|
||||||
|
|
||||||
let of_bytes b =
|
|
||||||
if MBytes.length b <> size then
|
|
||||||
None
|
|
||||||
else
|
|
||||||
Some (MBytes.to_string b)
|
|
||||||
let of_bytes_exn b =
|
|
||||||
match of_bytes b with
|
|
||||||
| None ->
|
|
||||||
let msg =
|
|
||||||
Printf.sprintf "%s.of_bytes: wrong string size (%d)"
|
|
||||||
name (MBytes.length b) in
|
|
||||||
raise (Invalid_argument msg)
|
|
||||||
| Some h -> h
|
|
||||||
let to_bytes = MBytes.of_string
|
|
||||||
|
|
||||||
let read src off = of_bytes_exn @@ MBytes.sub src off size
|
|
||||||
let write dst off h = MBytes.blit (to_bytes h) 0 dst off size
|
|
||||||
|
|
||||||
let b58check_encoding =
|
|
||||||
Base58.register_encoding
|
|
||||||
~prefix: Base58.Prefix.net_id
|
|
||||||
~length: size
|
|
||||||
~wrap: (fun s -> Hash s)
|
|
||||||
~of_raw:of_string ~to_raw: (fun h -> h)
|
|
||||||
|
|
||||||
let of_b58check_opt s =
|
|
||||||
Base58.simple_decode b58check_encoding s
|
|
||||||
let of_b58check_exn s =
|
|
||||||
match Base58.simple_decode b58check_encoding s with
|
|
||||||
| Some x -> x
|
|
||||||
| None -> Format.kasprintf Pervasives.failwith "Unexpected hash (%s)" name
|
|
||||||
let of_b58check s =
|
|
||||||
match Base58.simple_decode b58check_encoding s with
|
|
||||||
| Some x -> Ok x
|
|
||||||
| None -> generic_error "Unexpected hash (%s)" name
|
|
||||||
let to_b58check s = Base58.simple_encode b58check_encoding s
|
|
||||||
let to_short_b58check = to_b58check
|
|
||||||
|
|
||||||
let encoding =
|
|
||||||
let open Data_encoding in
|
|
||||||
splitted
|
|
||||||
~binary: (Fixed.string size)
|
|
||||||
~json:
|
|
||||||
(describe ~title: (title ^ " (Base58Check-encoded Blake2B hash)") @@
|
|
||||||
conv to_b58check (Data_encoding.Json.wrap_error of_b58check_exn) string)
|
|
||||||
|
|
||||||
let param ?(name=name) ?(desc=title) t =
|
|
||||||
Cli_entries.(param ~name ~desc (parameter (fun _ str -> Lwt.return (of_b58check str))) t)
|
|
||||||
|
|
||||||
let pp ppf t =
|
|
||||||
Format.pp_print_string ppf (to_b58check t)
|
|
||||||
|
|
||||||
let pp_short ppf t =
|
|
||||||
Format.pp_print_string ppf (to_short_b58check t)
|
|
||||||
|
|
||||||
module Set = struct
|
|
||||||
include Set.Make(struct type nonrec t = t let compare = compare end)
|
|
||||||
exception Found of elt
|
|
||||||
let random_elt s =
|
|
||||||
let n = Random.int (cardinal s) in
|
|
||||||
try
|
|
||||||
ignore
|
|
||||||
(fold (fun x i -> if i = n then raise (Found x) ; i+1) s 0 : int) ;
|
|
||||||
assert false
|
|
||||||
with Found x -> x
|
|
||||||
let encoding =
|
|
||||||
Data_encoding.conv
|
|
||||||
elements
|
|
||||||
(fun l -> List.fold_left (fun m x -> add x m) empty l)
|
|
||||||
Data_encoding.(list encoding)
|
|
||||||
end
|
|
||||||
let random_set_elt = Set.random_elt
|
|
||||||
|
|
||||||
module Map = struct
|
|
||||||
include Map.Make(struct type nonrec t = t let compare = compare end)
|
|
||||||
let encoding arg_encoding =
|
|
||||||
Data_encoding.conv
|
|
||||||
bindings
|
|
||||||
(fun l -> List.fold_left (fun m (k,v) -> add k v m) empty l)
|
|
||||||
Data_encoding.(list (tup2 encoding arg_encoding))
|
|
||||||
end
|
|
||||||
|
|
||||||
let path_length = 1
|
|
||||||
let to_path key l = to_hex key :: l
|
|
||||||
let of_path path =
|
|
||||||
let path = String.concat "" path in
|
|
||||||
of_hex path
|
|
||||||
let of_path_exn path =
|
|
||||||
let path = String.concat "" path in
|
|
||||||
of_hex_exn path
|
|
||||||
|
|
||||||
let prefix_path p =
|
|
||||||
let `Hex p = Hex.of_string p in
|
|
||||||
[ p ]
|
|
||||||
|
|
||||||
module Table = struct
|
|
||||||
include Hashtbl.Make(struct
|
|
||||||
type nonrec t = t
|
|
||||||
let hash = Hashtbl.hash
|
|
||||||
let equal = equal
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
let () =
|
|
||||||
Base58.check_encoded_prefix b58check_encoding "Net" 15
|
|
||||||
|
|
||||||
let zero =
|
|
||||||
match of_hex (String.make (size * 2) '0') with
|
|
||||||
| Some c -> c
|
|
||||||
| None -> assert false
|
|
||||||
|
|
||||||
|
|
||||||
let rpc_arg =
|
|
||||||
RPC_arg.make
|
|
||||||
~name:(Format.asprintf "hash.%s" name)
|
|
||||||
~descr:(Format.asprintf "A b58check-encoded hash (%s)" name)
|
|
||||||
~destruct:
|
|
||||||
(fun s ->
|
|
||||||
match of_b58check_opt s with
|
|
||||||
| None -> Error ""
|
|
||||||
| Some v -> Ok v)
|
|
||||||
~construct:to_b58check
|
|
||||||
()
|
|
||||||
|
@ -7,5 +7,6 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
include Tezos_crypto.S.INTERNAL_HASH
|
include S.INTERNAL_HASH
|
||||||
|
|
||||||
val of_block_hash: Block_hash.t -> t
|
val of_block_hash: Block_hash.t -> t
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
include Blake2B.Make (Base58) (struct
|
include Blake2B.Make (Tezos_crypto.Base58) (struct
|
||||||
let name = "Operation_hash"
|
let name = "Operation_hash"
|
||||||
let title = "A Tezos operation ID"
|
let title = "A Tezos operation ID"
|
||||||
let b58check_prefix = Base58.Prefix.operation_hash
|
let b58check_prefix = Tezos_crypto.Base58.Prefix.operation_hash
|
||||||
let size = None
|
let size = None
|
||||||
end)
|
end)
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
Base58.check_encoded_prefix b58check_encoding "o" 51
|
Tezos_crypto.Base58.check_encoded_prefix b58check_encoding "o" 51
|
||||||
|
|
||||||
|
@ -7,4 +7,4 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
include Tezos_crypto.S.INTERNAL_HASH
|
include S.INTERNAL_HASH
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
include Blake2B.Make_merkle_tree (Base58) (struct
|
include Blake2B.Make_merkle_tree (Tezos_crypto.Base58) (struct
|
||||||
let name = "Operation_list_hash"
|
let name = "Operation_list_hash"
|
||||||
let title = "A list of operations"
|
let title = "A list of operations"
|
||||||
let b58check_prefix = Base58.Prefix.operation_list_hash
|
let b58check_prefix = Tezos_crypto.Base58.Prefix.operation_list_hash
|
||||||
let size = None
|
let size = None
|
||||||
end) (Operation_hash)
|
end) (Operation_hash)
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
Base58.check_encoded_prefix b58check_encoding "Lo" 52
|
Tezos_crypto.Base58.check_encoded_prefix b58check_encoding "Lo" 52
|
||||||
|
@ -7,5 +7,5 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
include Tezos_crypto.S.INTERNAL_MERKLE_TREE with type elt = Operation_hash.t
|
include S.INTERNAL_MERKLE_TREE with type elt = Operation_hash.t
|
||||||
|
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
include Blake2B.Make_merkle_tree (Base58) (struct
|
include Blake2B.Make_merkle_tree (Tezos_crypto.Base58) (struct
|
||||||
let name = "Operation_list_list_hash"
|
let name = "Operation_list_list_hash"
|
||||||
let title = "A list of list of operations"
|
let title = "A list of list of operations"
|
||||||
let b58check_prefix = Base58.Prefix.operation_list_list_hash
|
let b58check_prefix = Tezos_crypto.Base58.Prefix.operation_list_list_hash
|
||||||
let size = None
|
let size = None
|
||||||
end) (Operation_list_hash)
|
end) (Operation_list_hash)
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
Base58.check_encoded_prefix b58check_encoding "LLo" 53 ;
|
Tezos_crypto.Base58.check_encoded_prefix b58check_encoding "LLo" 53 ;
|
||||||
|
@ -7,4 +7,4 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
include Tezos_crypto.S.INTERNAL_MERKLE_TREE with type elt = Operation_list_hash.t
|
include S.INTERNAL_MERKLE_TREE with type elt = Operation_list_hash.t
|
||||||
|
@ -27,3 +27,4 @@ val generate_with_animation :
|
|||||||
Format.formatter -> Crypto_box.target -> t
|
Format.formatter -> Crypto_box.target -> t
|
||||||
(** [generate_with_animation ppf target] is a freshly minted identity
|
(** [generate_with_animation ppf target] is a freshly minted identity
|
||||||
whose proof of work stamp difficulty is at least equal to [target]. *)
|
whose proof of work stamp difficulty is at least equal to [target]. *)
|
||||||
|
|
||||||
|
@ -7,5 +7,5 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
include Crypto_box.Public_key_hash
|
include Blake2B.Extend(Crypto_box.Public_key_hash)
|
||||||
|
|
||||||
|
@ -7,4 +7,4 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
include Tezos_crypto.S.INTERNAL_HASH with type t = Crypto_box.Public_key_hash.t
|
include S.INTERNAL_HASH with type t = Crypto_box.Public_key_hash.t
|
||||||
|
@ -96,7 +96,6 @@ module MakeV1
|
|||||||
module Time = Time
|
module Time = Time
|
||||||
module Ed25519 = Ed25519
|
module Ed25519 = Ed25519
|
||||||
module S = struct
|
module S = struct
|
||||||
include Tezos_crypto.S
|
|
||||||
include S
|
include S
|
||||||
end
|
end
|
||||||
module Block_hash = Block_hash
|
module Block_hash = Block_hash
|
||||||
@ -191,7 +190,7 @@ module MakeV1
|
|||||||
|
|
||||||
end
|
end
|
||||||
module Base58 = struct
|
module Base58 = struct
|
||||||
include Base58
|
include Tezos_crypto.Base58
|
||||||
let simple_encode enc s = simple_encode enc s
|
let simple_encode enc s = simple_encode enc s
|
||||||
let simple_decode enc s = simple_decode enc s
|
let simple_decode enc s = simple_decode enc s
|
||||||
include Make(struct type context = Context.t end)
|
include Make(struct type context = Context.t end)
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
include Blake2B.Make (Base58) (struct
|
include Blake2B.Make (Tezos_crypto.Base58) (struct
|
||||||
let name = "Protocol_hash"
|
let name = "Protocol_hash"
|
||||||
let title = "A Tezos protocol ID"
|
let title = "A Tezos protocol ID"
|
||||||
let b58check_prefix = Base58.Prefix.protocol_hash
|
let b58check_prefix = Tezos_crypto.Base58.Prefix.protocol_hash
|
||||||
let size = None
|
let size = None
|
||||||
end)
|
end)
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
Base58.check_encoded_prefix b58check_encoding "P" 51
|
Tezos_crypto.Base58.check_encoded_prefix b58check_encoding "P" 51
|
||||||
|
|
||||||
|
@ -7,4 +7,4 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
include Tezos_crypto.S.INTERNAL_HASH
|
include S.INTERNAL_HASH
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
|
open Error_monad
|
||||||
|
|
||||||
module type T = sig
|
module type T = sig
|
||||||
|
|
||||||
type t
|
type t
|
||||||
@ -40,3 +42,122 @@ module type HASHABLE = sig
|
|||||||
val hash_raw: MBytes.t -> hash
|
val hash_raw: MBytes.t -> hash
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module type MINIMAL_HASH = Tezos_crypto.S.MINIMAL_HASH
|
||||||
|
|
||||||
|
module type HASH = sig
|
||||||
|
|
||||||
|
include Tezos_crypto.S.MINIMAL_HASH
|
||||||
|
|
||||||
|
val encoding: t Data_encoding.t
|
||||||
|
|
||||||
|
val to_b58check: t -> string
|
||||||
|
val to_short_b58check: t -> string
|
||||||
|
type Tezos_crypto.Base58.data += Hash of t
|
||||||
|
val b58check_encoding: t Tezos_crypto.Base58.encoding
|
||||||
|
|
||||||
|
val of_b58check_exn: string -> t
|
||||||
|
val of_b58check_opt: string -> t option
|
||||||
|
|
||||||
|
val pp: Format.formatter -> t -> unit
|
||||||
|
val pp_short: Format.formatter -> t -> unit
|
||||||
|
|
||||||
|
val rpc_arg: t RPC_arg.t
|
||||||
|
|
||||||
|
module Set : sig
|
||||||
|
include Set.S with type elt = t
|
||||||
|
val encoding: t Data_encoding.t
|
||||||
|
end
|
||||||
|
|
||||||
|
module Map : sig
|
||||||
|
include Map.S with type key = t
|
||||||
|
val encoding: 'a Data_encoding.t -> 'a t Data_encoding.t
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
module type INTERNAL_HASH = sig
|
||||||
|
|
||||||
|
include Tezos_crypto.S.HASH
|
||||||
|
|
||||||
|
val zero: t
|
||||||
|
|
||||||
|
val of_b58check: string -> t tzresult
|
||||||
|
val of_bytes: MBytes.t -> t tzresult
|
||||||
|
|
||||||
|
val encoding: t Data_encoding.t
|
||||||
|
val rpc_arg: t RPC_arg.t
|
||||||
|
|
||||||
|
val param:
|
||||||
|
?name:string ->
|
||||||
|
?desc:string ->
|
||||||
|
('a, 'arg, 'ret) Cli_entries.params ->
|
||||||
|
(t -> 'a, 'arg, 'ret) Cli_entries.params
|
||||||
|
|
||||||
|
module Set : sig
|
||||||
|
include Set.S with type elt = t
|
||||||
|
val random_elt: t -> elt
|
||||||
|
val encoding: t Data_encoding.t
|
||||||
|
end
|
||||||
|
|
||||||
|
module Map : sig
|
||||||
|
include Map.S with type key = t
|
||||||
|
val encoding: 'a Data_encoding.t -> 'a t Data_encoding.t
|
||||||
|
end
|
||||||
|
|
||||||
|
module Table : sig
|
||||||
|
include Hashtbl.S with type key = t
|
||||||
|
val encoding: 'a Data_encoding.t -> 'a t Data_encoding.t
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
module type MERKLE_TREE = sig
|
||||||
|
type elt
|
||||||
|
include HASH
|
||||||
|
val compute: elt list -> t
|
||||||
|
val empty: t
|
||||||
|
type path =
|
||||||
|
| Left of path * t
|
||||||
|
| Right of t * path
|
||||||
|
| Op
|
||||||
|
val compute_path: elt list -> int -> path
|
||||||
|
val check_path: path -> elt -> t * int
|
||||||
|
val path_encoding: path Data_encoding.t
|
||||||
|
end
|
||||||
|
|
||||||
|
module type INTERNAL_MERKLE_TREE = sig
|
||||||
|
|
||||||
|
include Tezos_crypto.S.MERKLE_TREE
|
||||||
|
|
||||||
|
val path_encoding: path Data_encoding.t
|
||||||
|
|
||||||
|
val of_b58check: string -> t tzresult
|
||||||
|
val of_bytes: MBytes.t -> t tzresult
|
||||||
|
|
||||||
|
val encoding: t Data_encoding.t
|
||||||
|
val rpc_arg: t RPC_arg.t
|
||||||
|
|
||||||
|
val param:
|
||||||
|
?name:string ->
|
||||||
|
?desc:string ->
|
||||||
|
('a, 'arg, 'ret) Cli_entries.params ->
|
||||||
|
(t -> 'a, 'arg, 'ret) Cli_entries.params
|
||||||
|
|
||||||
|
module Set : sig
|
||||||
|
include Set.S with type elt = t
|
||||||
|
val random_elt: t -> elt
|
||||||
|
val encoding: t Data_encoding.t
|
||||||
|
end
|
||||||
|
|
||||||
|
module Map : sig
|
||||||
|
include Map.S with type key = t
|
||||||
|
val encoding: 'a Data_encoding.t -> 'a t Data_encoding.t
|
||||||
|
end
|
||||||
|
|
||||||
|
module Table : sig
|
||||||
|
include Hashtbl.S with type key = t
|
||||||
|
val encoding: 'a Data_encoding.t -> 'a t Data_encoding.t
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
@ -12,9 +12,13 @@ include Tezos_stdlib_lwt
|
|||||||
include Tezos_data_encoding
|
include Tezos_data_encoding
|
||||||
include Tezos_error_monad
|
include Tezos_error_monad
|
||||||
include Tezos_rpc
|
include Tezos_rpc
|
||||||
include Tezos_crypto
|
|
||||||
include Tezos_micheline
|
include Tezos_micheline
|
||||||
|
|
||||||
|
module Ed25519 = Ed25519
|
||||||
|
module Crypto_box = Crypto_box
|
||||||
|
module Base58 = Tezos_crypto.Base58
|
||||||
|
module Rand = Tezos_crypto.Rand
|
||||||
|
|
||||||
module List = struct
|
module List = struct
|
||||||
include List
|
include List
|
||||||
include Tezos_stdlib.TzList
|
include Tezos_stdlib.TzList
|
||||||
|
@ -9,10 +9,13 @@
|
|||||||
|
|
||||||
include (module type of (struct include Tezos_stdlib end))
|
include (module type of (struct include Tezos_stdlib end))
|
||||||
include (module type of (struct include Tezos_data_encoding end))
|
include (module type of (struct include Tezos_data_encoding end))
|
||||||
include (module type of (struct include Tezos_stdlib_lwt end))
|
|
||||||
include (module type of (struct include Tezos_error_monad end))
|
include (module type of (struct include Tezos_error_monad end))
|
||||||
include (module type of (struct include Tezos_rpc end))
|
include (module type of (struct include Tezos_rpc end))
|
||||||
include (module type of (struct include Tezos_crypto end))
|
|
||||||
|
module Ed25519 = Ed25519
|
||||||
|
module Crypto_box = Crypto_box
|
||||||
|
module Base58 = Tezos_crypto.Base58
|
||||||
|
module Rand = Tezos_crypto.Rand
|
||||||
|
|
||||||
module List : sig
|
module List : sig
|
||||||
include (module type of (struct include List end))
|
include (module type of (struct include List end))
|
||||||
|
@ -55,13 +55,13 @@ module Make_minimal (K : Name) = struct
|
|||||||
let compare (Blake2b.Hash h1) (Blake2b.Hash h2) = Cstruct.compare h1 h2
|
let compare (Blake2b.Hash h1) (Blake2b.Hash h2) = Cstruct.compare h1 h2
|
||||||
let equal x y = compare x y = 0
|
let equal x y = compare x y = 0
|
||||||
|
|
||||||
let of_bytes b =
|
let of_bytes_opt b =
|
||||||
if MBytes.length b <> size then
|
if MBytes.length b <> size then
|
||||||
None
|
None
|
||||||
else
|
else
|
||||||
Some (Blake2b.Hash (Cstruct.of_bigarray b))
|
Some (Blake2b.Hash (Cstruct.of_bigarray b))
|
||||||
let of_bytes_exn b =
|
let of_bytes_exn b =
|
||||||
match of_bytes b with
|
match of_bytes_opt b with
|
||||||
| None ->
|
| None ->
|
||||||
let msg =
|
let msg =
|
||||||
Printf.sprintf "%s.of_bytes: wrong string size (%d)"
|
Printf.sprintf "%s.of_bytes: wrong string size (%d)"
|
||||||
@ -107,14 +107,6 @@ module Make_minimal (K : Name) = struct
|
|||||||
and p6 = if len > 10 then String.sub p 10 (len - 10) else "" in
|
and p6 = if len > 10 then String.sub p 10 (len - 10) else "" in
|
||||||
[ p1 ; p2 ; p3 ; p4 ; p5 ; p6 ]
|
[ p1 ; p2 ; p3 ; p4 ; p5 ; p6 ]
|
||||||
|
|
||||||
module Table = struct
|
|
||||||
include Hashtbl.Make(struct
|
|
||||||
type nonrec t = t
|
|
||||||
let hash (Blake2b.Hash h) = Int64.to_int (Cstruct.BE.get_uint64 h 0)
|
|
||||||
let equal = equal
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Make (R : sig
|
module Make (R : sig
|
||||||
@ -129,6 +121,11 @@ module Make (R : sig
|
|||||||
|
|
||||||
include Make_minimal(K)
|
include Make_minimal(K)
|
||||||
|
|
||||||
|
let zero =
|
||||||
|
match of_hex (String.make (size * 2) '0') with
|
||||||
|
| Some c -> c
|
||||||
|
| None -> assert false
|
||||||
|
|
||||||
(* Serializers *)
|
(* Serializers *)
|
||||||
|
|
||||||
type Base58.data += Hash of t
|
type Base58.data += Hash of t
|
||||||
@ -146,89 +143,22 @@ module Make (R : sig
|
|||||||
match Base58.simple_decode b58check_encoding s with
|
match Base58.simple_decode b58check_encoding s with
|
||||||
| Some x -> x
|
| Some x -> x
|
||||||
| None -> Format.kasprintf Pervasives.failwith "Unexpected hash (%s)" K.name
|
| None -> Format.kasprintf Pervasives.failwith "Unexpected hash (%s)" K.name
|
||||||
let of_b58check s =
|
|
||||||
match Base58.simple_decode b58check_encoding s with
|
|
||||||
| Some x -> Ok x
|
|
||||||
| None -> generic_error "Unexpected hash (%s)" K.name
|
|
||||||
let to_b58check s = Base58.simple_encode b58check_encoding s
|
let to_b58check s = Base58.simple_encode b58check_encoding s
|
||||||
|
|
||||||
let to_short_b58check s =
|
let to_short_b58check s =
|
||||||
String.sub (to_b58check s) 0 (10 + 2 * String.length K.b58check_prefix)
|
String.sub (to_b58check s) 0 (10 + 2 * String.length K.b58check_prefix)
|
||||||
|
|
||||||
let rpc_arg =
|
|
||||||
RPC_arg.make
|
|
||||||
~name:(Format.asprintf "hash.%s" K.name)
|
|
||||||
~descr:(Format.asprintf "A b58check-encoded hash (%s)" K.name)
|
|
||||||
~destruct:
|
|
||||||
(fun s ->
|
|
||||||
match of_b58check_opt s with
|
|
||||||
| None ->
|
|
||||||
Error (Format.asprintf
|
|
||||||
"failed to decode b58check-encoded hash (%s): %S"
|
|
||||||
K.name s)
|
|
||||||
| Some v -> Ok v)
|
|
||||||
~construct:to_b58check
|
|
||||||
()
|
|
||||||
|
|
||||||
let encoding =
|
|
||||||
let open Data_encoding in
|
|
||||||
splitted
|
|
||||||
~binary:
|
|
||||||
(conv to_bytes of_bytes_exn (Fixed.bytes size))
|
|
||||||
~json:
|
|
||||||
(describe ~title: (K.title ^ " (Base58Check-encoded Blake2B hash)") @@
|
|
||||||
conv to_b58check (Data_encoding.Json.wrap_error of_b58check_exn) string)
|
|
||||||
|
|
||||||
let param ?(name=K.name) ?(desc=K.title) t =
|
|
||||||
Cli_entries.param
|
|
||||||
~name
|
|
||||||
~desc (Cli_entries.parameter (fun _ str -> Lwt.return (of_b58check str))) t
|
|
||||||
|
|
||||||
let pp ppf t =
|
let pp ppf t =
|
||||||
Format.pp_print_string ppf (to_b58check t)
|
Format.pp_print_string ppf (to_b58check t)
|
||||||
|
|
||||||
let pp_short ppf t =
|
let pp_short ppf t =
|
||||||
Format.pp_print_string ppf (to_short_b58check t)
|
Format.pp_print_string ppf (to_short_b58check t)
|
||||||
|
|
||||||
module Set = struct
|
|
||||||
include Set.Make(struct type nonrec t = t let compare = compare end)
|
|
||||||
exception Found of elt
|
|
||||||
let random_elt s =
|
|
||||||
let n = Random.int (cardinal s) in
|
|
||||||
try
|
|
||||||
ignore
|
|
||||||
(fold (fun x i -> if i = n then raise (Found x) ; i+1) s 0 : int) ;
|
|
||||||
assert false
|
|
||||||
with Found x -> x
|
|
||||||
let encoding =
|
|
||||||
Data_encoding.conv
|
|
||||||
elements
|
|
||||||
(fun l -> List.fold_left (fun m x -> add x m) empty l)
|
|
||||||
Data_encoding.(list encoding)
|
|
||||||
end
|
|
||||||
|
|
||||||
let random_set_elt = Set.random_elt
|
|
||||||
|
|
||||||
module Map = struct
|
|
||||||
include Map.Make(struct type nonrec t = t let compare = compare end)
|
|
||||||
let encoding arg_encoding =
|
|
||||||
Data_encoding.conv
|
|
||||||
bindings
|
|
||||||
(fun l -> List.fold_left (fun m (k,v) -> add k v m) empty l)
|
|
||||||
Data_encoding.(list (tup2 encoding arg_encoding))
|
|
||||||
end
|
|
||||||
|
|
||||||
let zero =
|
|
||||||
match of_hex (String.make (size * 2) '0') with
|
|
||||||
| Some c -> c
|
|
||||||
| None -> assert false
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Generic_Merkle_tree (H : sig
|
module Generic_Merkle_tree (H : sig
|
||||||
type t
|
type t
|
||||||
type elt
|
type elt
|
||||||
val encoding : t Data_encoding.t
|
|
||||||
val empty : t
|
val empty : t
|
||||||
val leaf : elt -> t
|
val leaf : elt -> t
|
||||||
val node : t -> t -> t
|
val node : t -> t -> t
|
||||||
@ -310,29 +240,6 @@ module Generic_Merkle_tree (H : sig
|
|||||||
let h, _, pos = check_path p h in
|
let h, _, pos = check_path p h in
|
||||||
h, pos
|
h, pos
|
||||||
|
|
||||||
let path_encoding =
|
|
||||||
let open Data_encoding in
|
|
||||||
mu "path"
|
|
||||||
(fun path_encoding ->
|
|
||||||
union [
|
|
||||||
case (Tag 240)
|
|
||||||
(obj2
|
|
||||||
(req "path" path_encoding)
|
|
||||||
(req "right" H.encoding))
|
|
||||||
(function Left (p, r) -> Some (p, r) | _ -> None)
|
|
||||||
(fun (p, r) -> Left (p, r)) ;
|
|
||||||
case (Tag 15)
|
|
||||||
(obj2
|
|
||||||
(req "left" H.encoding)
|
|
||||||
(req "path" path_encoding))
|
|
||||||
(function Right (r, p) -> Some (r, p) | _ -> None)
|
|
||||||
(fun (r, p) -> Right (r, p)) ;
|
|
||||||
case (Tag 0)
|
|
||||||
unit
|
|
||||||
(function Op -> Some () | _ -> None)
|
|
||||||
(fun () -> Op)
|
|
||||||
])
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Make_merkle_tree
|
module Make_merkle_tree
|
||||||
@ -354,13 +261,13 @@ module Make_merkle_tree
|
|||||||
include Make (R) (K)
|
include Make (R) (K)
|
||||||
|
|
||||||
type elt = Contents.t
|
type elt = Contents.t
|
||||||
|
let elt_bytes = Contents.to_bytes
|
||||||
|
|
||||||
let empty = hash_bytes []
|
let empty = hash_bytes []
|
||||||
|
|
||||||
include Generic_Merkle_tree(struct
|
include Generic_Merkle_tree(struct
|
||||||
type nonrec t = t
|
type nonrec t = t
|
||||||
type nonrec elt = elt
|
type nonrec elt = elt
|
||||||
let encoding = encoding
|
|
||||||
let empty = empty
|
let empty = empty
|
||||||
let leaf x = hash_bytes [Contents.to_bytes x]
|
let leaf x = hash_bytes [Contents.to_bytes x]
|
||||||
let node x y = hash_bytes [to_bytes x; to_bytes y]
|
let node x y = hash_bytes [to_bytes x; to_bytes y]
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
(** {2 Predefined Hashes } ****************************************************)
|
(** {2 Predefined Hashes } ****************************************************)
|
||||||
|
|
||||||
include S.INTERNAL_MINIMAL_HASH
|
include S.MINIMAL_HASH
|
||||||
|
|
||||||
(** {2 Building Hashes} *******************************************************)
|
(** {2 Building Hashes} *******************************************************)
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ module type PrefixedName = sig
|
|||||||
end
|
end
|
||||||
|
|
||||||
(** Builds a new Hash type using Blake2B. *)
|
(** Builds a new Hash type using Blake2B. *)
|
||||||
module Make_minimal (Name : Name) : S.INTERNAL_MINIMAL_HASH
|
module Make_minimal (Name : Name) : S.MINIMAL_HASH
|
||||||
module Make
|
module Make
|
||||||
(Register : sig
|
(Register : sig
|
||||||
val register_encoding:
|
val register_encoding:
|
||||||
@ -42,7 +42,7 @@ module Make
|
|||||||
wrap: ('a -> Base58.data) ->
|
wrap: ('a -> Base58.data) ->
|
||||||
'a Base58.encoding
|
'a Base58.encoding
|
||||||
end)
|
end)
|
||||||
(Name : PrefixedName) : S.INTERNAL_HASH
|
(Name : PrefixedName) : S.HASH
|
||||||
|
|
||||||
(**/**)
|
(**/**)
|
||||||
|
|
||||||
@ -60,24 +60,11 @@ module Make_merkle_tree
|
|||||||
(Contents: sig
|
(Contents: sig
|
||||||
type t
|
type t
|
||||||
val to_bytes: t -> MBytes.t
|
val to_bytes: t -> MBytes.t
|
||||||
end) : sig
|
end) : S.MERKLE_TREE with type elt = Contents.t
|
||||||
include S.INTERNAL_HASH
|
|
||||||
type elt = Contents.t
|
|
||||||
val empty: t
|
|
||||||
val compute: elt list -> t
|
|
||||||
type path =
|
|
||||||
| Left of path * t
|
|
||||||
| Right of t * path
|
|
||||||
| Op
|
|
||||||
val path_encoding: path Data_encoding.t
|
|
||||||
val compute_path: elt list -> int -> path
|
|
||||||
val check_path: path -> elt -> t * int
|
|
||||||
end
|
|
||||||
|
|
||||||
module Generic_Merkle_tree (H : sig
|
module Generic_Merkle_tree (H : sig
|
||||||
type t
|
type t
|
||||||
type elt
|
type elt
|
||||||
val encoding : t Data_encoding.t
|
|
||||||
val empty : t
|
val empty : t
|
||||||
val leaf : elt -> t
|
val leaf : elt -> t
|
||||||
val node : t -> t -> t
|
val node : t -> t -> t
|
||||||
|
@ -118,28 +118,14 @@ let generate_proof_of_work ?max pk target =
|
|||||||
loop (Nonce.increment nonce) (cpt + 1) in
|
loop (Nonce.increment nonce) (cpt + 1) in
|
||||||
loop (random_nonce ()) 0
|
loop (random_nonce ()) 0
|
||||||
|
|
||||||
let to_bigarray : type a. a Box.key -> MBytes.t = fun k ->
|
let public_key_to_bigarray x = Cstruct.to_bigarray (Box.to_cstruct x)
|
||||||
Cstruct.to_bigarray (Box.to_cstruct k)
|
let public_key_of_bigarray x = Box.pk_of_cstruct_exn (Cstruct.of_bigarray x)
|
||||||
|
let public_key_size = Box.pkbytes
|
||||||
|
|
||||||
let of_bigarray f s = f (Cstruct.of_bigarray s)
|
let secret_key_to_bigarray x = Cstruct.to_bigarray (Box.to_cstruct x)
|
||||||
|
let secret_key_of_bigarray x = Box.sk_of_cstruct_exn (Cstruct.of_bigarray x)
|
||||||
|
let secret_key_size = Box.skbytes
|
||||||
|
|
||||||
let public_key_encoding =
|
let nonce_to_bigarray x = Cstruct.to_bigarray (Nonce.to_cstruct x)
|
||||||
let open Data_encoding in
|
let nonce_of_bigarray x = Nonce.of_cstruct_exn (Cstruct.of_bigarray x)
|
||||||
conv
|
let nonce_size = Nonce.bytes
|
||||||
to_bigarray
|
|
||||||
(of_bigarray Box.pk_of_cstruct_exn)
|
|
||||||
(Fixed.bytes Box.pkbytes)
|
|
||||||
|
|
||||||
let secret_key_encoding =
|
|
||||||
let open Data_encoding in
|
|
||||||
conv
|
|
||||||
to_bigarray
|
|
||||||
(of_bigarray Box.sk_of_cstruct_exn)
|
|
||||||
(Fixed.bytes Box.skbytes)
|
|
||||||
|
|
||||||
let nonce_encoding =
|
|
||||||
let open Data_encoding in
|
|
||||||
conv
|
|
||||||
(fun nonce -> Cstruct.to_bigarray (Nonce.to_cstruct nonce))
|
|
||||||
(of_bigarray Nonce.of_cstruct_exn)
|
|
||||||
(Fixed.bytes Nonce.bytes)
|
|
||||||
|
@ -13,7 +13,6 @@ type nonce
|
|||||||
|
|
||||||
val random_nonce : unit -> nonce
|
val random_nonce : unit -> nonce
|
||||||
val increment_nonce : ?step:int -> nonce -> nonce
|
val increment_nonce : ?step:int -> nonce -> nonce
|
||||||
val nonce_encoding : nonce Data_encoding.t
|
|
||||||
|
|
||||||
type target
|
type target
|
||||||
val default_target : target
|
val default_target : target
|
||||||
@ -21,12 +20,9 @@ val make_target : float -> target
|
|||||||
|
|
||||||
type secret_key
|
type secret_key
|
||||||
type public_key
|
type public_key
|
||||||
module Public_key_hash : S.INTERNAL_HASH
|
module Public_key_hash : S.HASH
|
||||||
type channel_key
|
type channel_key
|
||||||
|
|
||||||
val public_key_encoding : public_key Data_encoding.t
|
|
||||||
val secret_key_encoding : secret_key Data_encoding.t
|
|
||||||
|
|
||||||
val hash : public_key -> Public_key_hash.t
|
val hash : public_key -> Public_key_hash.t
|
||||||
|
|
||||||
val zerobytes : int
|
val zerobytes : int
|
||||||
@ -51,4 +47,14 @@ val fast_box_open_noalloc : channel_key -> nonce -> MBytes.t -> bool
|
|||||||
val check_proof_of_work : public_key -> nonce -> target -> bool
|
val check_proof_of_work : public_key -> nonce -> target -> bool
|
||||||
val generate_proof_of_work : ?max:int -> public_key -> target -> nonce
|
val generate_proof_of_work : ?max:int -> public_key -> target -> nonce
|
||||||
|
|
||||||
|
val public_key_to_bigarray : public_key -> Cstruct.buffer
|
||||||
|
val public_key_of_bigarray : Cstruct.buffer -> public_key
|
||||||
|
val public_key_size : int
|
||||||
|
|
||||||
|
val secret_key_to_bigarray : secret_key -> Cstruct.buffer
|
||||||
|
val secret_key_of_bigarray : Cstruct.buffer -> secret_key
|
||||||
|
val secret_key_size : int
|
||||||
|
|
||||||
|
val nonce_to_bigarray : nonce -> Cstruct.buffer
|
||||||
|
val nonce_of_bigarray : Cstruct.buffer -> nonce
|
||||||
|
val nonce_size : int
|
||||||
|
@ -19,12 +19,6 @@ let () =
|
|||||||
|
|
||||||
open Tweetnacl
|
open Tweetnacl
|
||||||
|
|
||||||
let of_bigarray1 f x =
|
|
||||||
f (Cstruct.of_bigarray x)
|
|
||||||
|
|
||||||
let to_bigarray1 f x =
|
|
||||||
Cstruct.to_bigarray (f x)
|
|
||||||
|
|
||||||
module Public_key = struct
|
module Public_key = struct
|
||||||
|
|
||||||
type t = Sign.public Sign.key
|
type t = Sign.public Sign.key
|
||||||
@ -58,10 +52,6 @@ module Public_key = struct
|
|||||||
| Some x -> x
|
| Some x -> x
|
||||||
| None -> Pervasives.failwith
|
| None -> Pervasives.failwith
|
||||||
(Printf.sprintf "%s is not an ed25519 public key" s)
|
(Printf.sprintf "%s is not an ed25519 public key" s)
|
||||||
let of_b58check s =
|
|
||||||
match Base58.simple_decode b58check_encoding s with
|
|
||||||
| Some x -> Ok x
|
|
||||||
| None -> generic_error "%s is not an ed25519 public key" s
|
|
||||||
let to_b58check s = Base58.simple_encode b58check_encoding s
|
let to_b58check s = Base58.simple_encode b58check_encoding s
|
||||||
let pp ppf t = Format.fprintf ppf "%s" (to_b58check t)
|
let pp ppf t = Format.fprintf ppf "%s" (to_b58check t)
|
||||||
|
|
||||||
@ -75,49 +65,21 @@ module Public_key = struct
|
|||||||
let of_bytes_opt s =
|
let of_bytes_opt s =
|
||||||
Sign.pk_of_cstruct (Cstruct.of_bigarray s)
|
Sign.pk_of_cstruct (Cstruct.of_bigarray s)
|
||||||
|
|
||||||
let of_bytes s =
|
|
||||||
match of_bytes_opt s with
|
|
||||||
| None ->
|
|
||||||
generic_error "Could not deserialize Ed25519 public key (invalid format)"
|
|
||||||
| Some pk -> ok pk
|
|
||||||
|
|
||||||
let of_bytes_exn s =
|
let of_bytes_exn s =
|
||||||
match of_bytes_opt s with
|
match of_bytes_opt s with
|
||||||
| None ->
|
| None ->
|
||||||
Pervasives.invalid_arg "Ed25519.Public_key.of_bytes_exn: argument is not a serialized public key"
|
Pervasives.invalid_arg "Ed25519.Public_key.of_bytes_exn: argument is not a serialized public key"
|
||||||
| Some pk -> pk
|
| Some pk -> pk
|
||||||
|
let size = Sign.pkbytes
|
||||||
|
|
||||||
let to_bytes pk = Cstruct.to_bigarray (Sign.to_cstruct pk)
|
let to_bytes pk = Cstruct.to_bigarray (Sign.to_cstruct pk)
|
||||||
|
|
||||||
let param ?(name="ed25519-public") ?(desc="Ed25519 public key (b58check-encoded)") t =
|
|
||||||
Cli_entries.(param ~name ~desc (parameter (fun _ str -> Lwt.return (of_b58check str))) t)
|
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
Base58.check_encoded_prefix b58check_encoding "edpk" 54
|
Base58.check_encoded_prefix b58check_encoding "edpk" 54
|
||||||
|
|
||||||
let encoding =
|
|
||||||
let open Data_encoding in
|
|
||||||
splitted
|
|
||||||
~json:
|
|
||||||
(describe
|
|
||||||
~title: "An Ed25519 public key (Base58Check encoded)" @@
|
|
||||||
conv
|
|
||||||
(fun s -> Base58.simple_encode b58check_encoding s)
|
|
||||||
(fun s ->
|
|
||||||
match Base58.simple_decode b58check_encoding s with
|
|
||||||
| Some x -> x
|
|
||||||
| None -> Data_encoding.Json.cannot_destruct
|
|
||||||
"Ed25519 public key: unexpected prefix.")
|
|
||||||
string)
|
|
||||||
~binary:
|
|
||||||
(conv
|
|
||||||
(to_bigarray1 Sign.to_cstruct)
|
|
||||||
(of_bigarray1 Sign.pk_of_cstruct_exn)
|
|
||||||
(Fixed.bytes Sign.pkbytes))
|
|
||||||
|
|
||||||
let hash v =
|
let hash v =
|
||||||
Public_key_hash.hash_bytes
|
Public_key_hash.hash_bytes
|
||||||
[ to_bigarray1 Sign.to_cstruct v ]
|
[ Cstruct.to_bigarray (Sign.to_cstruct v) ]
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -160,10 +122,6 @@ module Secret_key = struct
|
|||||||
| Some x -> x
|
| Some x -> x
|
||||||
| None -> Pervasives.failwith
|
| None -> Pervasives.failwith
|
||||||
(Printf.sprintf "%s is not an ed25519 secret key" s)
|
(Printf.sprintf "%s is not an ed25519 secret key" s)
|
||||||
let of_b58check s =
|
|
||||||
match of_b58check_opt s with
|
|
||||||
| Some x -> Ok x
|
|
||||||
| None -> generic_error "%s is not an ed25519 secret key" s
|
|
||||||
let to_b58check s = Base58.simple_encode seed_encoding s
|
let to_b58check s = Base58.simple_encode seed_encoding s
|
||||||
let pp ppf t = Format.fprintf ppf "%s" (to_b58check t)
|
let pp ppf t = Format.fprintf ppf "%s" (to_b58check t)
|
||||||
|
|
||||||
@ -174,45 +132,19 @@ module Secret_key = struct
|
|||||||
| 64 -> Sign.sk_of_cstruct s
|
| 64 -> Sign.sk_of_cstruct s
|
||||||
| _ -> None
|
| _ -> None
|
||||||
|
|
||||||
let of_bytes s =
|
|
||||||
match of_bytes_opt s with
|
|
||||||
| None ->
|
|
||||||
generic_error "Could not deserialize Ed25519 seed (invalid format)"
|
|
||||||
| Some sk -> ok sk
|
|
||||||
|
|
||||||
let of_bytes_exn s =
|
let of_bytes_exn s =
|
||||||
match of_bytes_opt s with
|
match of_bytes_opt s with
|
||||||
| None ->
|
| None ->
|
||||||
Pervasives.invalid_arg "Ed25519.Secret_key.of_bytes_exn: argument is not a serialized seed"
|
Pervasives.invalid_arg "Ed25519.Secret_key.of_bytes_exn: argument is not a serialized seed"
|
||||||
| Some sk -> sk
|
| Some sk -> sk
|
||||||
|
|
||||||
let to_bytes = to_bigarray1 Sign.seed
|
let to_bytes x = Cstruct.to_bigarray (Sign.seed x)
|
||||||
|
let size = Sign.seedbytes
|
||||||
let param ?(name="ed25519-secret") ?(desc="Ed25519 secret key (b58check-encoded)") t =
|
|
||||||
Cli_entries.(param ~name ~desc (parameter (fun _ str -> Lwt.return (of_b58check str))) t)
|
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
Base58.check_encoded_prefix seed_encoding "edsk" 54 ;
|
Base58.check_encoded_prefix seed_encoding "edsk" 54 ;
|
||||||
Base58.check_encoded_prefix secret_key_encoding "edsk" 98
|
Base58.check_encoded_prefix secret_key_encoding "edsk" 98
|
||||||
|
|
||||||
let encoding =
|
|
||||||
let open Data_encoding in
|
|
||||||
splitted
|
|
||||||
~json:
|
|
||||||
(describe
|
|
||||||
~title: "An Ed25519 secret key (Base58Check encoded)" @@
|
|
||||||
conv
|
|
||||||
(fun s -> Base58.simple_encode seed_encoding s)
|
|
||||||
(fun s ->
|
|
||||||
match of_b58check_opt s with
|
|
||||||
| Some x -> x
|
|
||||||
| None -> Data_encoding.Json.cannot_destruct
|
|
||||||
"Ed25519 secret key: unexpected prefix.")
|
|
||||||
string)
|
|
||||||
~binary:
|
|
||||||
(conv to_bytes (fun buf -> of_bytes_exn buf)
|
|
||||||
(dynamic_size (Variable.bytes)))
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
let sign key msg =
|
let sign key msg =
|
||||||
@ -239,22 +171,12 @@ module Signature = struct
|
|||||||
| Some x -> x
|
| Some x -> x
|
||||||
| None -> Pervasives.failwith
|
| None -> Pervasives.failwith
|
||||||
(Printf.sprintf "%s is not an ed25519 signature" s)
|
(Printf.sprintf "%s is not an ed25519 signature" s)
|
||||||
let of_b58check s =
|
|
||||||
match Base58.simple_decode b58check_encoding s with
|
|
||||||
| Some x -> Ok x
|
|
||||||
| None -> generic_error "%s is not an ed25519 signature" s
|
|
||||||
let to_b58check s = Base58.simple_encode b58check_encoding s
|
let to_b58check s = Base58.simple_encode b58check_encoding s
|
||||||
let pp ppf t = Format.fprintf ppf "%s" (to_b58check t)
|
let pp ppf t = Format.fprintf ppf "%s" (to_b58check t)
|
||||||
|
|
||||||
let of_bytes_opt s =
|
let of_bytes_opt s =
|
||||||
if MBytes.length s = Sign.bytes then Some s else None
|
if MBytes.length s = Sign.bytes then Some s else None
|
||||||
|
|
||||||
let of_bytes s =
|
|
||||||
match of_bytes_opt s with
|
|
||||||
| None ->
|
|
||||||
generic_error "Could not deserialize Ed25519 signature (invalid format)"
|
|
||||||
| Some signature -> ok signature
|
|
||||||
|
|
||||||
let of_bytes_exn s =
|
let of_bytes_exn s =
|
||||||
match of_bytes_opt s with
|
match of_bytes_opt s with
|
||||||
| None ->
|
| None ->
|
||||||
@ -262,29 +184,11 @@ module Signature = struct
|
|||||||
| Some signature -> signature
|
| Some signature -> signature
|
||||||
|
|
||||||
let to_bytes x = x
|
let to_bytes x = x
|
||||||
|
let size = Sign.bytes
|
||||||
let param ?(name="signature") ?(desc="Signature (b58check-encoded)") t =
|
|
||||||
Cli_entries.(param ~name ~desc (parameter (fun _ str -> Lwt.return (of_b58check str))) t)
|
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
Base58.check_encoded_prefix b58check_encoding "edsig" 99
|
Base58.check_encoded_prefix b58check_encoding "edsig" 99
|
||||||
|
|
||||||
let encoding =
|
|
||||||
let open Data_encoding in
|
|
||||||
splitted
|
|
||||||
~json:
|
|
||||||
(describe
|
|
||||||
~title: "An Ed25519 signature (Base58Check encoded)" @@
|
|
||||||
conv
|
|
||||||
(fun s -> Base58.simple_encode b58check_encoding s)
|
|
||||||
(fun s ->
|
|
||||||
match Base58.simple_decode b58check_encoding s with
|
|
||||||
| Some x -> x
|
|
||||||
| None -> Data_encoding.Json.cannot_destruct
|
|
||||||
"Ed25519 signature: unexpected prefix.")
|
|
||||||
string)
|
|
||||||
~binary: (Fixed.bytes Sign.bytes)
|
|
||||||
|
|
||||||
let check public_key signature msg =
|
let check public_key signature msg =
|
||||||
Sign.verify_detached ~key:public_key
|
Sign.verify_detached ~key:public_key
|
||||||
~signature:(Cstruct.of_bigarray signature)
|
~signature:(Cstruct.of_bigarray signature)
|
||||||
|
@ -11,28 +11,20 @@
|
|||||||
|
|
||||||
(** {2 Hashed public keys for user ID} ***************************************)
|
(** {2 Hashed public keys for user ID} ***************************************)
|
||||||
|
|
||||||
module Public_key_hash : S.INTERNAL_HASH
|
module Public_key_hash : S.HASH
|
||||||
|
|
||||||
(** {2 Signature} ************************************************************)
|
(** {2 Signature} ************************************************************)
|
||||||
|
|
||||||
module Public_key : sig
|
module Public_key : sig
|
||||||
|
|
||||||
include Compare.S
|
include Compare.S
|
||||||
val encoding: t Data_encoding.t
|
|
||||||
val pp : Format.formatter -> t -> unit
|
val pp : Format.formatter -> t -> unit
|
||||||
|
|
||||||
val param:
|
|
||||||
?name:string ->
|
|
||||||
?desc:string ->
|
|
||||||
('a, 'b, 'c) Cli_entries.params ->
|
|
||||||
(t -> 'a, 'b, 'c) Cli_entries.params
|
|
||||||
|
|
||||||
val hash: t -> Public_key_hash.t
|
val hash: t -> Public_key_hash.t
|
||||||
|
|
||||||
type Base58.data +=
|
type Base58.data +=
|
||||||
| Public_key of t
|
| Public_key of t
|
||||||
|
|
||||||
val of_b58check: string -> t tzresult
|
|
||||||
val of_b58check_exn: string -> t
|
val of_b58check_exn: string -> t
|
||||||
val of_b58check_opt: string -> t option
|
val of_b58check_opt: string -> t option
|
||||||
val to_b58check: t -> string
|
val to_b58check: t -> string
|
||||||
@ -41,67 +33,54 @@ module Public_key : sig
|
|||||||
val of_hex: Hex.t -> t option
|
val of_hex: Hex.t -> t option
|
||||||
val of_hex_exn: Hex.t -> t
|
val of_hex_exn: Hex.t -> t
|
||||||
|
|
||||||
val of_bytes: MBytes.t -> t tzresult
|
|
||||||
val of_bytes_exn: MBytes.t -> t
|
val of_bytes_exn: MBytes.t -> t
|
||||||
val of_bytes_opt: MBytes.t -> t option
|
val of_bytes_opt: MBytes.t -> t option
|
||||||
val to_bytes: t -> MBytes.t
|
val to_bytes: t -> MBytes.t
|
||||||
|
|
||||||
|
val size: int
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Secret_key : sig
|
module Secret_key : sig
|
||||||
|
|
||||||
type t
|
type t
|
||||||
val encoding: t Data_encoding.t
|
|
||||||
val pp : Format.formatter -> t -> unit
|
val pp : Format.formatter -> t -> unit
|
||||||
|
|
||||||
val param:
|
|
||||||
?name:string ->
|
|
||||||
?desc:string ->
|
|
||||||
('a, 'b, 'c) Cli_entries.params ->
|
|
||||||
(t -> 'a, 'b, 'c) Cli_entries.params
|
|
||||||
|
|
||||||
val to_public_key: t -> Public_key.t
|
val to_public_key: t -> Public_key.t
|
||||||
|
|
||||||
type Base58.data +=
|
type Base58.data +=
|
||||||
| Secret_key of t
|
| Secret_key of t
|
||||||
|
|
||||||
val of_b58check: string -> t tzresult
|
|
||||||
val of_b58check_exn: string -> t
|
val of_b58check_exn: string -> t
|
||||||
val of_b58check_opt: string -> t option
|
val of_b58check_opt: string -> t option
|
||||||
val to_b58check: t -> string
|
val to_b58check: t -> string
|
||||||
|
|
||||||
val of_bytes: MBytes.t -> t tzresult
|
|
||||||
val of_bytes_exn: MBytes.t -> t
|
val of_bytes_exn: MBytes.t -> t
|
||||||
val of_bytes_opt: MBytes.t -> t option
|
val of_bytes_opt: MBytes.t -> t option
|
||||||
val to_bytes: t -> MBytes.t
|
val to_bytes: t -> MBytes.t
|
||||||
|
|
||||||
|
val size: int
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Signature : sig
|
module Signature : sig
|
||||||
|
|
||||||
type t
|
type t
|
||||||
val encoding: t Data_encoding.t
|
|
||||||
val pp : Format.formatter -> t -> unit
|
val pp : Format.formatter -> t -> unit
|
||||||
|
|
||||||
val param:
|
|
||||||
?name:string ->
|
|
||||||
?desc:string ->
|
|
||||||
('a, 'b, 'c) Cli_entries.params ->
|
|
||||||
(t -> 'a, 'b, 'c) Cli_entries.params
|
|
||||||
|
|
||||||
type Base58.data +=
|
type Base58.data +=
|
||||||
| Signature of t
|
| Signature of t
|
||||||
|
|
||||||
val of_b58check: string -> t tzresult
|
|
||||||
val of_b58check_exn: string -> t
|
val of_b58check_exn: string -> t
|
||||||
val of_b58check_opt: string -> t option
|
val of_b58check_opt: string -> t option
|
||||||
val to_b58check: t -> string
|
val to_b58check: t -> string
|
||||||
|
|
||||||
val of_bytes: MBytes.t -> t tzresult
|
|
||||||
val of_bytes_exn: MBytes.t -> t
|
val of_bytes_exn: MBytes.t -> t
|
||||||
val of_bytes_opt: MBytes.t -> t option
|
val of_bytes_opt: MBytes.t -> t option
|
||||||
val to_bytes: t -> MBytes.t
|
val to_bytes: t -> MBytes.t
|
||||||
|
|
||||||
|
val size: int
|
||||||
|
|
||||||
(** Check a signature *)
|
(** Check a signature *)
|
||||||
val check: Public_key.t -> t -> MBytes.t -> bool
|
val check: Public_key.t -> t -> MBytes.t -> bool
|
||||||
|
|
||||||
|
@ -3,17 +3,10 @@
|
|||||||
(library
|
(library
|
||||||
((name tezos_crypto)
|
((name tezos_crypto)
|
||||||
(public_name tezos-crypto)
|
(public_name tezos-crypto)
|
||||||
(flags (:standard -open Tezos_stdlib
|
(flags (:standard -safe-string
|
||||||
-open Tezos_data_encoding
|
-open Tezos_stdlib))
|
||||||
-open Tezos_stdlib_lwt
|
|
||||||
-open Tezos_rpc
|
|
||||||
-open Tezos_error_monad__Error_monad
|
|
||||||
-safe-string))
|
|
||||||
(libraries (tezos-stdlib
|
(libraries (tezos-stdlib
|
||||||
tezos-stdlib-lwt
|
lwt
|
||||||
tezos-data-encoding
|
|
||||||
tezos-error-monad
|
|
||||||
tezos-rpc
|
|
||||||
nocrypto
|
nocrypto
|
||||||
blake2
|
blake2
|
||||||
tweetnacl
|
tweetnacl
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
val generate : int -> MBytes.t
|
val generate : int -> Cstruct.buffer
|
||||||
(** [generate len] is [len] random bytes. *)
|
(** [generate len] is [len] random bytes. *)
|
||||||
|
|
||||||
val generate_into : ?pos:int -> ?len:int -> MBytes.t -> unit
|
val generate_into : ?pos:int -> ?len:int -> Cstruct.buffer -> unit
|
||||||
(** [generate_into ?pos ?len buf] writes [len] (default:
|
(** [generate_into ?pos ?len buf] writes [len] (default:
|
||||||
[MBytes.length buf]) bytes in [buf] starting at [pos] (default:
|
[MBytes.length buf]) bytes in [buf] starting at [pos] (default:
|
||||||
[0]). *)
|
[0]). *)
|
||||||
|
@ -23,7 +23,7 @@ module type MINIMAL_HASH = sig
|
|||||||
val name: string
|
val name: string
|
||||||
val title: string
|
val title: string
|
||||||
|
|
||||||
val hash_bytes: MBytes.t list -> t
|
val hash_bytes: Cstruct.buffer list -> t
|
||||||
val hash_string: string list -> t
|
val hash_string: string list -> t
|
||||||
val size: int (* in bytes *)
|
val size: int (* in bytes *)
|
||||||
val compare: t -> t -> int
|
val compare: t -> t -> int
|
||||||
@ -37,12 +37,12 @@ module type MINIMAL_HASH = sig
|
|||||||
val of_string: string -> t option
|
val of_string: string -> t option
|
||||||
val of_string_exn: string -> t
|
val of_string_exn: string -> t
|
||||||
|
|
||||||
val to_bytes: t -> MBytes.t
|
val to_bytes: t -> Cstruct.buffer
|
||||||
val of_bytes: MBytes.t -> t option
|
val of_bytes_opt: Cstruct.buffer -> t option
|
||||||
val of_bytes_exn: MBytes.t -> t
|
val of_bytes_exn: Cstruct.buffer -> t
|
||||||
|
|
||||||
val read: MBytes.t -> int -> t
|
val read: Cstruct.buffer -> int -> t
|
||||||
val write: MBytes.t -> int -> t -> unit
|
val write: Cstruct.buffer -> int -> t -> unit
|
||||||
|
|
||||||
val to_path: t -> string list -> string list
|
val to_path: t -> string list -> string list
|
||||||
val of_path: string list -> t option
|
val of_path: string list -> t option
|
||||||
@ -53,76 +53,42 @@ module type MINIMAL_HASH = sig
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module type INTERNAL_MINIMAL_HASH = sig
|
|
||||||
include MINIMAL_HASH
|
|
||||||
module Table : Hashtbl.S with type key = t
|
|
||||||
end
|
|
||||||
|
|
||||||
module type HASH = sig
|
module type HASH = sig
|
||||||
|
|
||||||
include MINIMAL_HASH
|
include MINIMAL_HASH
|
||||||
|
|
||||||
val of_b58check_exn: string -> t
|
val zero: t
|
||||||
val of_b58check_opt: string -> t option
|
|
||||||
val to_b58check: t -> string
|
val to_b58check: t -> string
|
||||||
val to_short_b58check: t -> string
|
val to_short_b58check: t -> string
|
||||||
val encoding: t Data_encoding.t
|
|
||||||
val pp: Format.formatter -> t -> unit
|
val of_b58check_exn: string -> t
|
||||||
val pp_short: Format.formatter -> t -> unit
|
val of_b58check_opt: string -> t option
|
||||||
|
|
||||||
type Base58.data += Hash of t
|
type Base58.data += Hash of t
|
||||||
val b58check_encoding: t Base58.encoding
|
val b58check_encoding: t Base58.encoding
|
||||||
|
|
||||||
val rpc_arg: t RPC_arg.t
|
val pp: Format.formatter -> t -> unit
|
||||||
|
val pp_short: Format.formatter -> t -> unit
|
||||||
|
|
||||||
module Set : sig
|
|
||||||
include Set.S with type elt = t
|
|
||||||
val encoding: t Data_encoding.t
|
|
||||||
end
|
|
||||||
|
|
||||||
module Map : sig
|
|
||||||
include Map.S with type key = t
|
|
||||||
val encoding: 'a Data_encoding.t -> 'a t Data_encoding.t
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
module type INTERNAL_HASH = sig
|
|
||||||
include HASH
|
|
||||||
val of_b58check: string -> t tzresult
|
|
||||||
val param:
|
|
||||||
?name:string ->
|
|
||||||
?desc:string ->
|
|
||||||
('a, 'arg, 'ret) Cli_entries.params ->
|
|
||||||
(t -> 'a, 'arg, 'ret) Cli_entries.params
|
|
||||||
val random_set_elt: Set.t -> t
|
|
||||||
module Table : Hashtbl.S with type key = t
|
|
||||||
val zero: t
|
|
||||||
end
|
|
||||||
|
|
||||||
module type INTERNAL_MERKLE_TREE = sig
|
|
||||||
type elt
|
|
||||||
include INTERNAL_HASH
|
|
||||||
val compute: elt list -> t
|
|
||||||
val empty: t
|
|
||||||
type path =
|
|
||||||
| Left of path * t
|
|
||||||
| Right of t * path
|
|
||||||
| Op
|
|
||||||
val compute_path: elt list -> int -> path
|
|
||||||
val check_path: path -> elt -> t * int
|
|
||||||
val path_encoding: path Data_encoding.t
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module type MERKLE_TREE = sig
|
module type MERKLE_TREE = sig
|
||||||
|
|
||||||
type elt
|
type elt
|
||||||
|
val elt_bytes: elt -> Cstruct.buffer
|
||||||
|
|
||||||
include HASH
|
include HASH
|
||||||
|
|
||||||
val compute: elt list -> t
|
val compute: elt list -> t
|
||||||
val empty: t
|
val empty: t
|
||||||
|
|
||||||
type path =
|
type path =
|
||||||
| Left of path * t
|
| Left of path * t
|
||||||
| Right of t * path
|
| Right of t * path
|
||||||
| Op
|
| Op
|
||||||
|
|
||||||
val compute_path: elt list -> int -> path
|
val compute_path: elt list -> int -> path
|
||||||
val check_path: path -> elt -> t * int
|
val check_path: path -> elt -> t * int
|
||||||
val path_encoding: path Data_encoding.t
|
|
||||||
end
|
end
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
((names (test_merkle))
|
((names (test_merkle))
|
||||||
(libraries (tezos-stdlib
|
(libraries (tezos-stdlib
|
||||||
tezos-error-monad
|
tezos-error-monad
|
||||||
tezos-data-encoding
|
|
||||||
tezos-crypto
|
tezos-crypto
|
||||||
tezos-test-helpers))
|
tezos-test-helpers))
|
||||||
(flags (:standard -w -9-32
|
(flags (:standard -w -9-32
|
||||||
@ -12,7 +11,6 @@
|
|||||||
-open Tezos_test_helpers
|
-open Tezos_test_helpers
|
||||||
-open Tezos_stdlib
|
-open Tezos_stdlib
|
||||||
-open Tezos_error_monad
|
-open Tezos_error_monad
|
||||||
-open Tezos_data_encoding
|
|
||||||
-open Tezos_crypto))))
|
-open Tezos_crypto))))
|
||||||
|
|
||||||
(alias
|
(alias
|
||||||
|
@ -30,9 +30,6 @@ module Merkle = Blake2B.Generic_Merkle_tree(struct
|
|||||||
let empty = Empty
|
let empty = Empty
|
||||||
let leaf i = Leaf i
|
let leaf i = Leaf i
|
||||||
let node x y = Node (x, y)
|
let node x y = Node (x, y)
|
||||||
let encoding =
|
|
||||||
(* Fake... *)
|
|
||||||
Data_encoding.conv (fun _ -> 0) (fun _ -> Empty) Data_encoding.int31
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
let rec compare_list xs ys =
|
let rec compare_list xs ys =
|
||||||
|
@ -11,14 +11,12 @@ depends: [
|
|||||||
"jbuilder" { build & >= "1.0+beta17" }
|
"jbuilder" { build & >= "1.0+beta17" }
|
||||||
"tezos-test-helpers" { test }
|
"tezos-test-helpers" { test }
|
||||||
"tezos-stdlib"
|
"tezos-stdlib"
|
||||||
"tezos-stdlib-lwt"
|
"lwt"
|
||||||
"tezos-data-encoding"
|
|
||||||
"tezos-error-monad"
|
|
||||||
"tezos-rpc"
|
|
||||||
"nocrypto"
|
"nocrypto"
|
||||||
"blake2"
|
"blake2"
|
||||||
"tweetnacl"
|
"tweetnacl"
|
||||||
"zarith"
|
"zarith"
|
||||||
|
"tezos-error-monad" { test }
|
||||||
]
|
]
|
||||||
build: [
|
build: [
|
||||||
[ "jbuilder" "build" "-p" name "-j" jobs ]
|
[ "jbuilder" "build" "-p" name "-j" jobs ]
|
||||||
|
@ -56,8 +56,7 @@ let () = Format.kasprintf Jbuild_plugin.V1.send {|
|
|||||||
(rule
|
(rule
|
||||||
((targets (tezos_protocol_%s.cmo
|
((targets (tezos_protocol_%s.cmo
|
||||||
tezos_protocol_%s_dummy_byte.ml))
|
tezos_protocol_%s_dummy_byte.ml))
|
||||||
(deps ((glob_files src/*.ml)
|
(deps ((glob_files src/*.ml*)
|
||||||
(glob_files src/*.mli)
|
|
||||||
src/TEZOS_PROTOCOL))
|
src/TEZOS_PROTOCOL))
|
||||||
(action (with-stdout-to ${path-no-dep:tezos_protocol_%s_dummy_byte.ml}
|
(action (with-stdout-to ${path-no-dep:tezos_protocol_%s_dummy_byte.ml}
|
||||||
(chdir ${ROOT}
|
(chdir ${ROOT}
|
||||||
|
@ -75,7 +75,7 @@ module type MINIMAL_HASH = sig
|
|||||||
val of_string_exn: string -> t
|
val of_string_exn: string -> t
|
||||||
|
|
||||||
val to_bytes: t -> MBytes.t
|
val to_bytes: t -> MBytes.t
|
||||||
val of_bytes: MBytes.t -> t option
|
val of_bytes_opt: MBytes.t -> t option
|
||||||
val of_bytes_exn: MBytes.t -> t
|
val of_bytes_exn: MBytes.t -> t
|
||||||
|
|
||||||
val read: MBytes.t -> int -> t
|
val read: MBytes.t -> int -> t
|
||||||
@ -94,16 +94,19 @@ module type HASH = sig
|
|||||||
|
|
||||||
include MINIMAL_HASH
|
include MINIMAL_HASH
|
||||||
|
|
||||||
val of_b58check_exn: string -> t
|
val encoding: t Data_encoding.t
|
||||||
val of_b58check_opt: string -> t option
|
|
||||||
val to_b58check: t -> string
|
val to_b58check: t -> string
|
||||||
val to_short_b58check: t -> string
|
val to_short_b58check: t -> string
|
||||||
val encoding: t Data_encoding.t
|
|
||||||
val pp: Format.formatter -> t -> unit
|
|
||||||
val pp_short: Format.formatter -> t -> unit
|
|
||||||
type Base58.data += Hash of t
|
type Base58.data += Hash of t
|
||||||
val b58check_encoding: t Base58.encoding
|
val b58check_encoding: t Base58.encoding
|
||||||
|
|
||||||
|
val of_b58check_exn: string -> t
|
||||||
|
val of_b58check_opt: string -> t option
|
||||||
|
|
||||||
|
val pp: Format.formatter -> t -> unit
|
||||||
|
val pp_short: Format.formatter -> t -> unit
|
||||||
|
|
||||||
val rpc_arg: t RPC_arg.t
|
val rpc_arg: t RPC_arg.t
|
||||||
|
|
||||||
module Set : sig
|
module Set : sig
|
||||||
|
@ -493,7 +493,7 @@ end = struct
|
|||||||
( Table.remove state.pending key ; acc )
|
( Table.remove state.pending key ; acc )
|
||||||
else
|
else
|
||||||
let requested_peer =
|
let requested_peer =
|
||||||
P2p_peer.Id.random_set_elt
|
P2p_peer.Id.Set.random_elt
|
||||||
(if P2p_peer.Set.is_empty remaining_peers
|
(if P2p_peer.Set.is_empty remaining_peers
|
||||||
then active_peers
|
then active_peers
|
||||||
else remaining_peers) in
|
else remaining_peers) in
|
||||||
|
@ -37,7 +37,7 @@ module IrminBlake2B : Irmin.Hash.S with type t = Context_hash.t = struct
|
|||||||
|
|
||||||
let to_raw t = Cstruct.of_bigarray (Context_hash.to_bytes t)
|
let to_raw t = Cstruct.of_bigarray (Context_hash.to_bytes t)
|
||||||
let of_raw t =
|
let of_raw t =
|
||||||
match Context_hash.of_bytes (Cstruct.to_bigarray t) with
|
match Context_hash.of_bytes_opt (Cstruct.to_bigarray t) with
|
||||||
| Some t -> t
|
| Some t -> t
|
||||||
| None ->
|
| None ->
|
||||||
let str = Cstruct.to_string t in
|
let str = Cstruct.to_string t in
|
||||||
|
Loading…
Reference in New Issue
Block a user