This commit is contained in:
parent
3fad00a611
commit
84ca3b252b
4 changed files with 11 additions and 41 deletions
29
src/api.ml
29
src/api.ml
|
|
@ -72,27 +72,6 @@ module B32 = struct
|
|||
~decode:B32.decode Caqti_type.string
|
||||
end
|
||||
|
||||
(* TODO use DenominationHash directly *)
|
||||
module HashCode : sig
|
||||
type t
|
||||
|
||||
val hash : string -> t
|
||||
val of_b32 : B32.t -> (t, string) result
|
||||
val to_denomination_hash : t -> Bin_type.DenominationHash.t
|
||||
val jsont : t Jsont.t
|
||||
end = struct
|
||||
type t = B32.t
|
||||
|
||||
let to_denomination_hash s = Bin_type.DenominationHash.of_octets s
|
||||
|
||||
let hash s =
|
||||
let open Digestif.SHA512 in
|
||||
s |> digest_string |> to_raw_string
|
||||
|
||||
let of_b32 = B32.decode
|
||||
let jsont = B32.jsont
|
||||
end
|
||||
|
||||
(* TODO error response
|
||||
- use GANA error codes
|
||||
https://git.gnunet.org/gana.git/tree/gnu-taler-error-codes/registry.rec *)
|
||||
|
|
@ -886,7 +865,7 @@ end
|
|||
|
||||
module AuditorDenominationKey = struct
|
||||
type t = {
|
||||
denom_pub_h: HashCode.t;
|
||||
denom_pub_h: DenominationHash.t;
|
||||
auditor_sig: ExchangeKeyValidity.t;
|
||||
}
|
||||
|
||||
|
|
@ -895,7 +874,7 @@ module AuditorDenominationKey = struct
|
|||
let denom_pub_h v = v.denom_pub_h in
|
||||
let auditor_sig v = v.auditor_sig in
|
||||
map ~kind:"AuditorDenominationKey" make
|
||||
|> mem "denom_pub_h" HashCode.jsont ~enc:denom_pub_h
|
||||
|> mem "denom_pub_h" DenominationHash.jsont ~enc:denom_pub_h
|
||||
|> mem "auditor_sig" ExchangeKeyValidity.jsont ~enc:auditor_sig
|
||||
|> finish
|
||||
end
|
||||
|
|
@ -954,13 +933,13 @@ module SignKey = struct
|
|||
end
|
||||
|
||||
module RecoupDenoms = struct
|
||||
type t = { h_denom_pub: HashCode.t }
|
||||
type t = { h_denom_pub: DenominationHash.t }
|
||||
|
||||
let jsont =
|
||||
let make h_denom_pub = { h_denom_pub } in
|
||||
let h_denom_pub v = v.h_denom_pub in
|
||||
map ~kind:"RecoupDenoms" make
|
||||
|> mem "h_denom_pub" HashCode.jsont ~enc:h_denom_pub
|
||||
|> mem "h_denom_pub" DenominationHash.jsont ~enc:h_denom_pub
|
||||
|> finish
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ module Hash_32 = struct
|
|||
| true -> Digestif.SHA256.of_raw_string s
|
||||
|
||||
let to_octets = Digestif.SHA256.to_raw_string
|
||||
let of_b32 s = Result.map of_octets (B32.decode s)
|
||||
|
||||
let bin =
|
||||
let open Bin in
|
||||
|
|
@ -111,9 +112,8 @@ module Hash_32 = struct
|
|||
octets
|
||||
|
||||
let jsont =
|
||||
let dec s = Result.map of_octets (B32.decode s) in
|
||||
let enc v = B32.encode (to_octets v) in
|
||||
Jsont.of_of_string ~kind:"Hash 32" dec ~enc
|
||||
Jsont.of_of_string ~kind:"Hash 32" of_b32 ~enc
|
||||
end
|
||||
|
||||
module Hash_64 = struct
|
||||
|
|
@ -132,6 +132,8 @@ module Hash_64 = struct
|
|||
| false -> Fmt.failwith "Hash.to_octets failure: data is not 64 bytes"
|
||||
| true -> s
|
||||
|
||||
let of_b32 s = Result.map of_octets (B32.decode s)
|
||||
|
||||
let bin =
|
||||
let open Bin in
|
||||
map (bytes 64) of_octets to_octets
|
||||
|
|
@ -145,9 +147,8 @@ module Hash_64 = struct
|
|||
octets
|
||||
|
||||
let jsont =
|
||||
let dec s = Result.map of_octets (B32.decode s) in
|
||||
let enc v = B32.encode (to_octets v) in
|
||||
Jsont.of_of_string ~kind:"Hash 64" dec ~enc
|
||||
Jsont.of_of_string ~kind:"Hash 64" of_b32 ~enc
|
||||
end
|
||||
|
||||
(* Hash over string + '\0' *)
|
||||
|
|
@ -176,6 +177,7 @@ module type Hash_S = sig
|
|||
val hash : string -> t
|
||||
val of_octets : string -> t
|
||||
val to_octets : t -> string
|
||||
val of_b32 : B32.t -> (t, string) result
|
||||
end
|
||||
|
||||
module FullPaytoHash : Hash_S = Hash_32
|
||||
|
|
|
|||
|
|
@ -236,8 +236,7 @@ module Denom_revoke = struct
|
|||
let db_conn = Vif.Server.device Devices.db_connection server in
|
||||
let sm = Vif.Server.device Devices.secmod server in
|
||||
let res =
|
||||
let* h_denom_pub = HashCode.of_b32 h_denom_pub in
|
||||
let h_denom_pub = HashCode.to_denomination_hash h_denom_pub in
|
||||
let* h_denom_pub = DenominationHash.of_b32 h_denom_pub in
|
||||
let* v = Vif.Request.of_json req |> unwrap_err_msg in
|
||||
let* () = verify h_denom_pub v in
|
||||
let* () = do_ ~db_conn ~sm h_denom_pub v in
|
||||
|
|
|
|||
10
src/pg.ml
10
src/pg.ml
|
|
@ -220,16 +220,6 @@ let get_auditor_keys =
|
|||
fun (module Conn : CONN) () ->
|
||||
let open Syntax in
|
||||
let* l = Conn.collect_list get_auditor_keys () |> unwrap_err_caqti in
|
||||
let* l =
|
||||
(* TODO improve DenominationHash/HashCode situation
|
||||
conversion here is probably bad *)
|
||||
list_map
|
||||
(fun (pub, url, name, denom_pub_h, auditor_sig) ->
|
||||
let denom_pub_h = Bin_type.DenominationHash.to_octets denom_pub_h in
|
||||
let* denom_pub_h = HashCode.of_b32 denom_pub_h in
|
||||
Ok (pub, url, name, denom_pub_h, auditor_sig))
|
||||
l
|
||||
in
|
||||
let ht = Hashtbl.create 0xff in
|
||||
List.iter
|
||||
(fun (pub, url, name, denom_pub_h, auditor_sig) ->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue