2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2018-02-06 00:17:03 +04:00
|
|
|
(* Copyright (c) 2014 - 2018. *)
|
2016-09-08 21:13:10 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2017-02-19 21:22:32 +04:00
|
|
|
(** {1 Prefixed Base58Check encodings} *)
|
2016-10-06 20:30:04 +04:00
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
module Prefix : sig
|
2016-11-14 19:26:34 +04:00
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
val block_hash: string
|
|
|
|
val operation_hash: string
|
2017-03-16 20:17:06 +04:00
|
|
|
val operation_list_hash: string
|
|
|
|
val operation_list_list_hash: string
|
2016-09-08 21:13:10 +04:00
|
|
|
val protocol_hash: string
|
2017-12-05 18:17:54 +04:00
|
|
|
val context_hash: string
|
2016-11-14 19:26:34 +04:00
|
|
|
val ed25519_public_key_hash: string
|
2017-01-14 16:13:49 +04:00
|
|
|
val cryptobox_public_key_hash: string
|
2018-01-08 20:21:29 +04:00
|
|
|
val ed25519_seed: string
|
2016-11-14 19:26:34 +04:00
|
|
|
val ed25519_public_key: string
|
|
|
|
val ed25519_secret_key: string
|
|
|
|
val ed25519_signature: string
|
2018-02-16 04:26:24 +04:00
|
|
|
val chain_id: string
|
2016-11-14 19:26:34 +04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
(** An extensible sum-type for decoded data: one case per known
|
|
|
|
"prefix". See for instance [Hash.Block_hash.Hash] or
|
|
|
|
[Environment.Ed25519.Public_key_hash]. *)
|
|
|
|
type data = ..
|
|
|
|
|
2018-03-13 14:13:12 +04:00
|
|
|
(** Abstract representation of registered encodings. The type paramater
|
2016-11-14 19:26:34 +04:00
|
|
|
is the type of the encoded data, for instance [Hash.Block_hash.t]. *)
|
|
|
|
type 'a encoding = private {
|
2017-02-19 21:22:32 +04:00
|
|
|
prefix: string ;
|
|
|
|
length: int ;
|
|
|
|
encoded_prefix: string ;
|
|
|
|
encoded_length: int ;
|
2016-11-14 19:26:34 +04:00
|
|
|
to_raw: 'a -> string ;
|
|
|
|
of_raw: string -> 'a option ;
|
|
|
|
wrap: 'a -> data ;
|
|
|
|
}
|
|
|
|
|
|
|
|
(** Register a new encoding. The function might raise `Invalid_arg` if
|
2018-03-13 14:13:12 +04:00
|
|
|
the provided [prefix] overlap with a previously registered
|
2016-11-14 19:26:34 +04:00
|
|
|
prefix. The [to_raw] and [of_raw] are the ad-hoc
|
|
|
|
serialisation/deserialisation for the data. The [wrap] should wrap
|
|
|
|
the deserialised value into the extensible sum-type [data] (see
|
|
|
|
the generic function [decode]). *)
|
|
|
|
val register_encoding:
|
|
|
|
prefix: string ->
|
2017-02-19 21:22:32 +04:00
|
|
|
length: int ->
|
2016-11-14 19:26:34 +04:00
|
|
|
to_raw: ('a -> string) ->
|
|
|
|
of_raw: (string -> 'a option) ->
|
|
|
|
wrap: ('a -> data) ->
|
|
|
|
'a encoding
|
|
|
|
|
2017-02-19 21:22:32 +04:00
|
|
|
val check_encoded_prefix: 'a encoding -> string -> int -> unit
|
|
|
|
|
|
|
|
module Alphabet : sig
|
|
|
|
type t
|
|
|
|
val bitcoin: t
|
|
|
|
val ripple: t
|
|
|
|
val flickr: t
|
|
|
|
val make: string -> t
|
2017-10-15 14:42:58 +04:00
|
|
|
val all_in_alphabet : t -> string -> bool
|
|
|
|
val pp : Format.formatter -> t -> unit
|
2017-02-19 21:22:32 +04:00
|
|
|
end
|
|
|
|
|
2016-11-14 19:26:34 +04:00
|
|
|
(** Encoder for a given kind of data. *)
|
2017-02-19 21:22:32 +04:00
|
|
|
val simple_encode: ?alphabet:Alphabet.t -> 'a encoding -> 'a -> string
|
2016-11-14 19:26:34 +04:00
|
|
|
|
|
|
|
(** Decoder for a given kind of data. It returns [None] when
|
|
|
|
the decoded data does not start with the expected prefix. *)
|
2017-02-19 21:22:32 +04:00
|
|
|
val simple_decode: ?alphabet:Alphabet.t -> 'a encoding -> string -> 'a option
|
2016-11-14 19:26:34 +04:00
|
|
|
|
|
|
|
(** Generic decoder. It returns [None] when the decoded data does
|
2018-03-13 14:13:12 +04:00
|
|
|
not start with a registered prefix. *)
|
2017-02-19 21:22:32 +04:00
|
|
|
val decode: ?alphabet:Alphabet.t -> string -> data option
|
2016-11-14 19:26:34 +04:00
|
|
|
|
2017-02-19 21:22:32 +04:00
|
|
|
(** {2 Completion of partial Base58Check value} *)
|
2016-11-14 19:26:34 +04:00
|
|
|
|
|
|
|
(** Register a (global) resolver for a previsously
|
2018-03-13 14:13:12 +04:00
|
|
|
registered kind af data. *)
|
2016-11-14 19:26:34 +04:00
|
|
|
val register_resolver: 'a encoding -> (string -> 'a list Lwt.t) -> unit
|
|
|
|
|
2017-02-19 21:22:32 +04:00
|
|
|
(** Try to complete a prefix of a Base58Check encoded data, by using
|
2016-11-14 19:26:34 +04:00
|
|
|
the previously registered resolver associated to this kind of
|
2017-02-19 21:22:32 +04:00
|
|
|
data. Note that a prefix of [n] characters of a Base58-encoded
|
2016-11-14 19:26:34 +04:00
|
|
|
value provides at least [n/2] bytes of a prefix of the original value. *)
|
2017-02-19 21:22:32 +04:00
|
|
|
val complete: ?alphabet:Alphabet.t -> string -> string list Lwt.t
|
2016-11-14 19:26:34 +04:00
|
|
|
|
2017-03-15 19:00:53 +04:00
|
|
|
(** {1 Low-level: distinct registering function for economic protocol} *)
|
2016-11-14 19:26:34 +04:00
|
|
|
|
2017-11-11 14:40:20 +04:00
|
|
|
(** See [src/environment/v1/base58.mli] for an inlined
|
2016-11-14 19:26:34 +04:00
|
|
|
documentation. *)
|
|
|
|
module Make(C: sig type context end) : sig
|
|
|
|
|
|
|
|
val register_encoding:
|
|
|
|
prefix: string ->
|
2017-02-19 21:22:32 +04:00
|
|
|
length: int ->
|
2016-11-14 19:26:34 +04:00
|
|
|
to_raw: ('a -> string) ->
|
|
|
|
of_raw: (string -> 'a option) ->
|
|
|
|
wrap: ('a -> data) ->
|
|
|
|
'a encoding
|
|
|
|
|
2017-02-19 21:22:32 +04:00
|
|
|
val decode: ?alphabet:Alphabet.t -> string -> data option
|
2016-11-14 19:26:34 +04:00
|
|
|
|
|
|
|
val register_resolver:
|
|
|
|
'a encoding -> (C.context -> string -> 'a list Lwt.t) -> unit
|
|
|
|
|
|
|
|
val complete:
|
2017-02-19 21:22:32 +04:00
|
|
|
?alphabet:Alphabet.t -> C.context -> string -> string list Lwt.t
|
2016-11-14 19:26:34 +04:00
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
2016-11-14 19:26:34 +04:00
|
|
|
|
2017-02-19 21:22:32 +04:00
|
|
|
(** {2 Low-level Base58Check encodings} *)
|
|
|
|
|
|
|
|
(** Base58Check-encoding/decoding functions (with error detections). *)
|
|
|
|
val safe_encode: ?alphabet:Alphabet.t -> string -> string
|
2018-01-04 20:11:13 +04:00
|
|
|
val safe_decode: ?alphabet:Alphabet.t -> string -> string option
|
2016-11-14 19:26:34 +04:00
|
|
|
|
2017-02-19 21:22:32 +04:00
|
|
|
(** Base58-encoding/decoding functions (without error detections). *)
|
|
|
|
val raw_encode: ?alphabet:Alphabet.t -> string -> string
|
2018-01-04 20:11:13 +04:00
|
|
|
val raw_decode: ?alphabet:Alphabet.t -> string -> string option
|
2016-11-14 19:26:34 +04:00
|
|
|
|
2017-02-19 21:22:32 +04:00
|
|
|
(**/**)
|
2016-11-14 19:26:34 +04:00
|
|
|
|
2018-01-04 20:11:13 +04:00
|
|
|
val partial_decode: ?alphabet:Alphabet.t -> string -> int -> string option
|
2017-02-19 21:22:32 +04:00
|
|
|
val make_encoded_prefix: string -> int -> string * int
|
2018-04-03 13:44:11 +04:00
|
|
|
val prefix: 'a encoding -> string
|