+ wip MasterSignatures
This commit is contained in:
parent
f3de6ea80d
commit
d760a54b61
7 changed files with 136 additions and 68 deletions
|
|
@ -88,3 +88,24 @@ let of_string =
|
|||
(char '.' *> parse_int32)
|
||||
in
|
||||
fun s -> parse_string ~consume:Consume.All parse_t s |> Result.join
|
||||
|
||||
let jsont = Jsont.of_of_string ~kind:"Amount" of_string ~enc:to_string
|
||||
let currency_len = 12
|
||||
|
||||
let bin =
|
||||
let open Bin in
|
||||
record (fun _value _fraction _currency ->
|
||||
(* no need to decode amount? *)
|
||||
assert false)
|
||||
|+ field neint64 (fun t -> t.value)
|
||||
|+ field neint32 (fun t -> t.fraction)
|
||||
|+ field (bytes currency_len) (fun t -> t.currency)
|
||||
|> sealr
|
||||
|
||||
let bin_nbo =
|
||||
let open Bin in
|
||||
record (fun _value _fraction _currency -> assert false)
|
||||
|+ field beint64 (fun t -> t.value)
|
||||
|+ field beint32 (fun t -> t.fraction)
|
||||
|+ field (bytes currency_len) (fun t -> t.currency)
|
||||
|> sealr
|
||||
|
|
|
|||
|
|
@ -19,3 +19,9 @@ val make :
|
|||
val pp : Format.formatter -> t -> unit
|
||||
val to_string : t -> string
|
||||
val of_string : string -> (t, string) result
|
||||
val currency_len : int
|
||||
val jsont : t Jsont.t
|
||||
|
||||
(* only for encoding *)
|
||||
val bin : t Bin.t
|
||||
val bin_nbo : t Bin.t
|
||||
|
|
|
|||
24
src/api.ml
24
src/api.ml
|
|
@ -29,23 +29,33 @@ module ErrorDetail = struct
|
|||
|> Jsont.Object.finish
|
||||
end
|
||||
|
||||
module HashCode = struct
|
||||
module HashCode : sig
|
||||
type t
|
||||
|
||||
val hash : string -> t
|
||||
val jsont : t Jsont.t
|
||||
end = struct
|
||||
type t = B32.t
|
||||
|
||||
let hash s =
|
||||
let open Digestif.SHA256 in
|
||||
s |> digest_string |> to_raw_string
|
||||
|
||||
let jsont = Jsont.of_of_string ~kind:"HashCode" B32.decode ~enc:B32.encode
|
||||
end
|
||||
|
||||
module Amount = struct
|
||||
include Amount
|
||||
|
||||
let jsont = Jsont.of_of_string ~kind:"Amount" of_string ~enc:to_string
|
||||
end
|
||||
|
||||
module Timestamp = struct
|
||||
type t =
|
||||
| Seconds of float
|
||||
| Never
|
||||
|
||||
(* TODO time
|
||||
- time.ml
|
||||
- check this
|
||||
- what value for never?
|
||||
- better way for conversion to bin_types? *)
|
||||
let to_int64 t = match t with Never -> 0_L | Seconds v -> Int64.of_float v
|
||||
let to_ptime t = Util.ptime_of_int64 @@ to_int64 t
|
||||
let of_ptime p = Seconds (Ptime.to_float_s p)
|
||||
|
||||
let number_or_never_jsont =
|
||||
|
|
|
|||
|
|
@ -65,13 +65,15 @@ module INT64 = struct
|
|||
|
||||
let bin = Bin.neint64
|
||||
let of_ptime v = Util.ptime_to_int64 v
|
||||
let of_int64 i = i
|
||||
end
|
||||
|
||||
module INT64_NBO = struct
|
||||
type t = int64
|
||||
|
||||
let bin = Bin.beint64
|
||||
let of_ptime = Util.ptime_to_int64
|
||||
let of_ptime v = Util.ptime_to_int64 v
|
||||
let of_int64 i = i
|
||||
end
|
||||
|
||||
(* -- Time -- *)
|
||||
|
|
@ -80,6 +82,7 @@ module type Time_S = sig
|
|||
|
||||
val bin : t Bin.t
|
||||
val of_ptime : Ptime.t -> t
|
||||
val of_int64 : int64 -> t
|
||||
end
|
||||
|
||||
module TimeAbsolute : Time_S = INT64
|
||||
|
|
@ -232,67 +235,14 @@ module AgeMask = struct
|
|||
record (fun mask -> { mask }) |+ field beint32 (fun t -> t.mask) |> sealr
|
||||
end
|
||||
|
||||
(* TODO
|
||||
- why is the non-NBO version only used in TALER_WithdrawRequestPS?
|
||||
- correctly do the padding and 0-termination
|
||||
- handle "invalid" values *)
|
||||
(* documentation: *)
|
||||
(* Number of characters (plus 1 for 0-termination) for currency names.
|
||||
typically an ISO 4217 currency code when an alphanumeric 3-digit code is used.
|
||||
For regional currencies, the first character should be a "*" followed
|
||||
by a region-specific name (i.e. "*BRETAGNEFR").
|
||||
Currency codes are compared case-insensitively.
|
||||
|
||||
Currency string, left adjusted and padded with zeros.
|
||||
All zeros for "invalid" values.
|
||||
|
||||
Name of the currency, using either a three-character ISO 4217 currency
|
||||
code, or a regional currency identifier between 4 and 11 characters,
|
||||
consisting of ASCII alphabetic characters ("a-zA-Z").
|
||||
Should be padded to 12 bytes with 0-characters.
|
||||
Currency codes are compared case-insensitively. *)
|
||||
let currency_len = 12
|
||||
|
||||
(* TODO missing doc
|
||||
found in src/include/taler/taler_amount_lib.h *)
|
||||
module AmountP = struct
|
||||
type t = {
|
||||
value: int64;
|
||||
fraction: int32;
|
||||
currency: string;
|
||||
}
|
||||
|
||||
(* TODO BE here? *)
|
||||
let bin =
|
||||
let open Bin in
|
||||
record (fun value fraction currency -> { value; fraction; currency })
|
||||
|+ field beint64 (fun t -> t.value)
|
||||
|+ field beint32 (fun t -> t.fraction)
|
||||
|+ field (bytes currency_len) (fun t -> t.currency)
|
||||
|> sealr
|
||||
end
|
||||
|
||||
module AmountNBO = struct
|
||||
type t = {
|
||||
value: int64;
|
||||
fraction: int32;
|
||||
currency: string;
|
||||
}
|
||||
|
||||
let bin =
|
||||
let open Bin in
|
||||
record (fun value fraction currency -> { value; fraction; currency })
|
||||
|+ field beint64 (fun t -> t.value)
|
||||
|+ field beint32 (fun t -> t.fraction)
|
||||
|+ field (bytes currency_len) (fun t -> t.currency)
|
||||
|> sealr
|
||||
end
|
||||
|
||||
(* TODO keep this?
|
||||
some of those are actuall ecdhe, or union of eddsa|ecdhe *)
|
||||
module Aliases = struct
|
||||
(* TODO add Amount.bin *)
|
||||
module Amount = AmountP
|
||||
module AmountNBO = struct
|
||||
type t = Amount.t
|
||||
|
||||
let bin = Amount.bin_nbo
|
||||
end
|
||||
|
||||
(* - Keys - *)
|
||||
module PursePublicKey = EddsaPublicKey
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ module EddsaPrivateKey = struct
|
|||
|
||||
type t = priv
|
||||
|
||||
let pub_of_priv = pub_of_priv
|
||||
let to_octets t = priv_to_octets t
|
||||
let of_octets t = priv_of_octets t |> Result.get_ok
|
||||
let bin = Bin.map (Bin.bytes 32) of_octets to_octets
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue