rename crockford
This commit is contained in:
parent
34b979a9bc
commit
10df5181a0
14 changed files with 80 additions and 70 deletions
11
src/api.ml
11
src/api.ml
|
|
@ -54,15 +54,16 @@ module Account_operation = struct
|
|||
|> Jsont.enum ~kind:"account operation type"
|
||||
end
|
||||
|
||||
module B32 = struct
|
||||
include B32
|
||||
module Crockford = struct
|
||||
include Crockford
|
||||
|
||||
let jsont = Jsont.of_of_string ~kind:"B32" B32.decode ~enc:B32.encode
|
||||
let jsont =
|
||||
Jsont.of_of_string ~kind:"Crockford" Crockford.decode ~enc:Crockford.encode
|
||||
|
||||
let caqti =
|
||||
Caqti_type.custom
|
||||
~encode:(fun v -> Ok (B32.encode v))
|
||||
~decode:B32.decode Caqti_type.string
|
||||
~encode:(fun v -> Ok (Crockford.encode v))
|
||||
~decode:Crockford.decode Caqti_type.string
|
||||
end
|
||||
|
||||
module ErrorDetail = struct
|
||||
|
|
|
|||
|
|
@ -209,4 +209,4 @@ let rsa_keysize s =
|
|||
(* because of [kdf_mod_n] *)
|
||||
failure "RSA keysize must be multiple of 8, found `%d`" nbits
|
||||
|
||||
let ed25519 s = Eddsa.pub_of_b32 s |> unwrap_or_failure
|
||||
let ed25519 s = Eddsa.pub_of_crockford s |> unwrap_or_failure
|
||||
|
|
|
|||
8
src/dune
8
src/dune
|
|
@ -65,7 +65,7 @@
|
|||
signatures
|
||||
api)
|
||||
(libraries
|
||||
(re_export b32)
|
||||
(re_export crockford)
|
||||
(re_export taler_signature_purpose_codes)
|
||||
;
|
||||
angstrom
|
||||
|
|
@ -89,9 +89,9 @@
|
|||
;
|
||||
))
|
||||
|
||||
(library ; crockford base32
|
||||
(name b32)
|
||||
(modules b32)
|
||||
(library
|
||||
(name crockford)
|
||||
(modules crockford)
|
||||
(libraries base32))
|
||||
|
||||
(rule
|
||||
|
|
|
|||
29
src/eddsa.ml
29
src/eddsa.ml
|
|
@ -25,14 +25,15 @@ module Priv = struct
|
|||
Mirage_eddsa.priv_of_octets o
|
||||
|> Result.map_error (Fmt.str "%a" pp_mirage_error)
|
||||
|
||||
let priv_to_b32 t = priv_to_octets t |> B32.encode
|
||||
let priv_to_crockford t = priv_to_octets t |> Crockford.encode
|
||||
|
||||
let priv_of_b32 s =
|
||||
let* octets = B32.decode s in
|
||||
let priv_of_crockford s =
|
||||
let* octets = Crockford.decode s in
|
||||
priv_of_octets octets
|
||||
|
||||
let priv_jsont =
|
||||
Jsont.of_of_string ~kind:"EddsaPrivateKey" priv_of_b32 ~enc:priv_to_b32
|
||||
Jsont.of_of_string ~kind:"EddsaPrivateKey" priv_of_crockford
|
||||
~enc:priv_to_crockford
|
||||
|
||||
let priv_bin =
|
||||
let priv_of_octets_exn t =
|
||||
|
|
@ -48,14 +49,15 @@ module Pub = struct
|
|||
Mirage_eddsa.pub_of_octets t
|
||||
|> Result.map_error (Fmt.str "%a" pp_mirage_error)
|
||||
|
||||
let pub_to_b32 t = pub_to_octets t |> B32.encode
|
||||
let pub_to_crockford t = pub_to_octets t |> Crockford.encode
|
||||
|
||||
let pub_of_b32 s =
|
||||
let* octets = B32.decode s in
|
||||
let pub_of_crockford s =
|
||||
let* octets = Crockford.decode s in
|
||||
pub_of_octets octets
|
||||
|
||||
let pub_jsont =
|
||||
Jsont.of_of_string ~kind:"EddsaPublicKey" pub_of_b32 ~enc:pub_to_b32
|
||||
Jsont.of_of_string ~kind:"EddsaPublicKey" pub_of_crockford
|
||||
~enc:pub_to_crockford
|
||||
|
||||
let pub_bin =
|
||||
let pub_of_octets_exn t =
|
||||
|
|
@ -77,14 +79,15 @@ module Sig_ = struct
|
|||
| false -> Error "invalid eddsa signature length"
|
||||
| true -> Ok (S s)
|
||||
|
||||
let sig_of_b32 s =
|
||||
let* s = B32.decode s in
|
||||
let sig_of_crockford s =
|
||||
let* s = Crockford.decode s in
|
||||
sig_of_octets s
|
||||
|
||||
let sig_to_b32 (S s) = B32.encode s
|
||||
let sig_to_crockford (S s) = Crockford.encode s
|
||||
|
||||
let sig_jsont =
|
||||
Jsont.of_of_string ~kind:"EddsaSignature" sig_of_b32 ~enc:sig_to_b32
|
||||
Jsont.of_of_string ~kind:"EddsaSignature" sig_of_crockford
|
||||
~enc:sig_to_crockford
|
||||
|
||||
let sig_bin =
|
||||
let sig_of_octets_exn t =
|
||||
|
|
@ -102,4 +105,4 @@ include Priv
|
|||
include Pub
|
||||
include Sig_
|
||||
|
||||
let pp_pub ppf pub = Fmt.pf ppf "%s" (pub_to_b32 pub)
|
||||
let pp_pub ppf pub = Fmt.pf ppf "%s" (pub_to_crockford pub)
|
||||
|
|
|
|||
14
src/hash.ml
14
src/hash.ml
|
|
@ -5,8 +5,8 @@ module type S = sig
|
|||
|
||||
val hash : string -> t
|
||||
val to_octets : t -> string
|
||||
val to_b32 : t -> B32.t
|
||||
val of_b32 : B32.t -> (t, string) result
|
||||
val to_crockford : t -> Crockford.t
|
||||
val of_crockford : Crockford.t -> (t, string) result
|
||||
val pp_hex : Format.formatter -> t -> unit
|
||||
val pp : Format.formatter -> t -> unit
|
||||
val bin : t Bin.t
|
||||
|
|
@ -25,14 +25,14 @@ module MK (H : Digestif.S) : S = struct
|
|||
| Some t -> Ok t
|
||||
|
||||
let to_octets = H.to_raw_string
|
||||
let to_b32 t = B32.encode (to_octets t)
|
||||
let to_crockford t = Crockford.encode (to_octets t)
|
||||
|
||||
let of_b32 s =
|
||||
let* o = B32.decode s in
|
||||
let of_crockford s =
|
||||
let* o = Crockford.decode s in
|
||||
of_octets o
|
||||
|
||||
let pp_hex = H.pp
|
||||
let pp ppf t = Fmt.pf ppf "%s" (to_b32 t)
|
||||
let pp ppf t = Fmt.pf ppf "%s" (to_crockford t)
|
||||
|
||||
let bin =
|
||||
let of_octets_exn s =
|
||||
|
|
@ -45,7 +45,7 @@ module MK (H : Digestif.S) : S = struct
|
|||
let open Caqti_type in
|
||||
custom ~encode:(fun v -> Ok (to_octets v)) ~decode:of_octets octets
|
||||
|
||||
let jsont = Jsont.of_of_string ~kind:"hash" of_b32 ~enc:to_b32
|
||||
let jsont = Jsont.of_of_string ~kind:"hash" of_crockford ~enc:to_crockford
|
||||
end
|
||||
|
||||
module H32 = MK (Digestif.SHA256)
|
||||
|
|
|
|||
|
|
@ -63,7 +63,8 @@ module Denom_revoke = struct
|
|||
@@
|
||||
let keys = Vifu.Server.device Mte_device.keys server in
|
||||
let* h_denom_pub =
|
||||
DenominationHash.of_b32 h_denom_pub |> Result.map_error (fun e -> `Msg e)
|
||||
DenominationHash.of_crockford h_denom_pub
|
||||
|> Result.map_error (fun e -> `Msg e)
|
||||
in
|
||||
let* v = request_of_json req in
|
||||
let* () = verify keys h_denom_pub v in
|
||||
|
|
@ -90,7 +91,7 @@ module Signkey_revoke = struct
|
|||
@@
|
||||
let keys = Vifu.Server.device Mte_device.keys server in
|
||||
let* exchange_pub =
|
||||
Eddsa.pub_of_b32 exchange_pub |> Result.map_error (fun e -> `Msg e)
|
||||
Eddsa.pub_of_crockford exchange_pub |> Result.map_error (fun e -> `Msg e)
|
||||
in
|
||||
let* v = request_of_json req in
|
||||
let* () = verify keys exchange_pub v in
|
||||
|
|
@ -186,7 +187,7 @@ module Auditors_disable = struct
|
|||
let keys = Vifu.Server.device Mte_device.keys server in
|
||||
let db_conn = Vifu.Server.device Mte_device.db_conn server in
|
||||
let* auditor_pub =
|
||||
Eddsa.pub_of_b32 auditor_pub |> Result.map_error (fun e -> `Msg e)
|
||||
Eddsa.pub_of_crockford auditor_pub |> Result.map_error (fun e -> `Msg e)
|
||||
in
|
||||
let* v = request_of_json req in
|
||||
let* () = verify keys auditor_pub v in
|
||||
|
|
|
|||
22
src/rsa.ml
22
src/rsa.ml
|
|
@ -90,23 +90,24 @@ module Priv = struct
|
|||
let priv_of_octets = RSA_BIN.priv_of_octets
|
||||
let priv_to_octets = RSA_BIN.priv_to_octets
|
||||
|
||||
let priv_of_b32 s =
|
||||
let* s = B32.decode s in
|
||||
let priv_of_crockford s =
|
||||
let* s = Crockford.decode s in
|
||||
priv_of_octets s
|
||||
|
||||
let priv_to_b32 t = B32.encode (priv_to_octets t)
|
||||
let priv_to_crockford t = Crockford.encode (priv_to_octets t)
|
||||
|
||||
let priv_jsont =
|
||||
Jsont.of_of_string ~kind:"RsaPrivateKey" priv_of_b32 ~enc:priv_to_b32
|
||||
Jsont.of_of_string ~kind:"RsaPrivateKey" priv_of_crockford
|
||||
~enc:priv_to_crockford
|
||||
end
|
||||
|
||||
module Pub = struct
|
||||
let pub_to_octets = RSA_BIN.pub_to_octets
|
||||
let pub_of_octets = RSA_BIN.pub_of_octets
|
||||
let pub_to_b32 t = B32.encode (pub_to_octets t)
|
||||
let pub_to_crockford t = Crockford.encode (pub_to_octets t)
|
||||
|
||||
let pub_of_b32 s =
|
||||
let* s = B32.decode s in
|
||||
let pub_of_crockford s =
|
||||
let* s = Crockford.decode s in
|
||||
pub_of_octets s
|
||||
|
||||
let pub_caqti =
|
||||
|
|
@ -115,14 +116,15 @@ module Pub = struct
|
|||
~decode:pub_of_octets Caqti_type.octets
|
||||
|
||||
let pub_jsont =
|
||||
Jsont.of_of_string ~kind:"RsaPublicKey" pub_of_b32 ~enc:pub_to_b32
|
||||
Jsont.of_of_string ~kind:"RsaPublicKey" pub_of_crockford
|
||||
~enc:pub_to_crockford
|
||||
end
|
||||
|
||||
include Priv
|
||||
include Pub
|
||||
|
||||
let sig_jsont =
|
||||
Jsont.of_of_string ~kind:"RsaSignature" B32.decode ~enc:B32.encode
|
||||
Jsont.of_of_string ~kind:"RsaSignature" Crockford.decode ~enc:Crockford.encode
|
||||
|
||||
(* ---- *)
|
||||
|
||||
|
|
@ -208,4 +210,4 @@ let sign ~key bmsg : sig_ =
|
|||
let sig_ = Mirage_rsa.decrypt ~crt_hardening:true ~key bmsg in
|
||||
S sig_
|
||||
|
||||
let pp_pub ppf pub = Fmt.pf ppf "%s" (pub_to_b32 pub)
|
||||
let pp_pub ppf pub = Fmt.pf ppf "%s" (pub_to_crockford pub)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ let write_eddsa fs spath priv =
|
|||
Fat.write fs spath data
|
||||
|
||||
let key_spath k =
|
||||
let sfn = String.sub (Eddsa.pub_to_b32 k.pub) 0 8 in
|
||||
let sfn = String.sub (Eddsa.pub_to_crockford k.pub) 0 8 in
|
||||
Fat.Path.add Cfg.key_dir sfn
|
||||
|
||||
let read_key fs spath =
|
||||
|
|
|
|||
|
|
@ -48,9 +48,9 @@ let find_exn h_pub section_name =
|
|||
rsa keysize is not known and then we have to escape '\x00' *)
|
||||
let rsa_private_key_bin =
|
||||
let decode_exn o =
|
||||
Rsa.priv_of_b32 o |> function Error e -> invalid_arg e | Ok v -> v
|
||||
Rsa.priv_of_crockford o |> function Error e -> invalid_arg e | Ok v -> v
|
||||
in
|
||||
let encode o = Rsa.priv_to_b32 o in
|
||||
let encode o = Rsa.priv_to_crockford o in
|
||||
Bin.map Bin.cstring decode_exn encode
|
||||
|
||||
let key_bin =
|
||||
|
|
@ -67,7 +67,7 @@ let key_bin =
|
|||
|> sealr
|
||||
|
||||
let key_spath k =
|
||||
let sfn = String.sub (DenominationHash.to_b32 k.h_pub) 0 8 in
|
||||
let sfn = String.sub (DenominationHash.to_crockford k.h_pub) 0 8 in
|
||||
Fat.Path.add Cfg.key_dir sfn
|
||||
|
||||
let read_eddsa fs spath =
|
||||
|
|
|
|||
|
|
@ -72,8 +72,8 @@ module Bytes32 : BYTES = struct
|
|||
| true -> Ok s
|
||||
|
||||
let jsont =
|
||||
let decode s = Result.bind (B32.decode s) of_octets in
|
||||
let encode b = to_octets b |> B32.encode in
|
||||
let decode s = Result.bind (Crockford.decode s) of_octets in
|
||||
let encode b = to_octets b |> Crockford.encode in
|
||||
Jsont.of_of_string ~kind:"Bytes32" decode ~enc:encode
|
||||
|
||||
let caqti =
|
||||
|
|
@ -101,8 +101,8 @@ module Bytes64 : BYTES = struct
|
|||
| true -> Ok s
|
||||
|
||||
let jsont =
|
||||
let decode s = Result.bind (B32.decode s) of_octets in
|
||||
let encode b = to_octets b |> B32.encode in
|
||||
let decode s = Result.bind (Crockford.decode s) of_octets in
|
||||
let encode b = to_octets b |> Crockford.encode in
|
||||
Jsont.of_of_string ~kind:"Bytes64" decode ~enc:encode
|
||||
|
||||
let caqti =
|
||||
|
|
|
|||
14
test/test.ml
14
test/test.ml
|
|
@ -1,6 +1,6 @@
|
|||
let get_ok = Result.get_ok
|
||||
let encode = B32.encode
|
||||
let decode s = B32.decode s |> get_ok
|
||||
let encode = Crockford.encode
|
||||
let decode s = Crockford.decode s |> get_ok
|
||||
|
||||
let test_b32 () =
|
||||
let round_trip s =
|
||||
|
|
@ -84,7 +84,7 @@ module Test_crypto = struct
|
|||
|> Eddsa.priv_of_octets
|
||||
|> get_ok
|
||||
|> Eddsa.pub_of_priv
|
||||
|> Eddsa.pub_to_b32
|
||||
|> Eddsa.pub_to_crockford
|
||||
in
|
||||
assert (pub = pub')
|
||||
|
||||
|
|
@ -139,8 +139,8 @@ module Test_crypto = struct
|
|||
let blinded_message =
|
||||
"3KHKZJZ30ABB4E56MA2V0EQWGCWH0QQG9P2ZHYHR186C5HZXJMM4N9WXAQTKS94QSV9Y17GGNXN5MB1PZZFG7Q0FY88QPKKRG4MYCPSMTZK5W59R0MJVNJ4P4AQM96TDG5W7RV8GSNR1QQZ1GNHW3CX6D6ZRTMXB2NKB5SSYTDJS79F5ZFBRZ4HVED9JBBPWSR79KVV5QQ4APBGHBCKGMF9NJJS53A1BVYHDEVYAGFYF2SNEP827ZP50FKJ5GKGV8NQ15ESEZ69AT7GJG0T3TZVENY2YN9CVR98W3BKEZ53J7VTANARG8SJS8AMJQ7S23P5HRJ7XE9KTNRNXKH49MXV9JHHYE5535N7AGWEKR47SBCGNF44Z7XJ9RV5BQV12ZRJKN4HBZQHDNCMH3QKX9Z6G64"
|
||||
in
|
||||
let pub = rsa_public_key |> Rsa.pub_of_b32 |> get_ok in
|
||||
assert (Rsa.pub_to_b32 pub = rsa_public_key);
|
||||
let pub = rsa_public_key |> Rsa.pub_of_crockford |> get_ok in
|
||||
assert (Rsa.pub_to_crockford pub = rsa_public_key);
|
||||
let bks = blinding_key_secret |> decode in
|
||||
let msg = decode message_hash in
|
||||
let bmsg = Rsa.blind_msg pub ~bks msg |> encode in
|
||||
|
|
@ -169,10 +169,10 @@ module Test_crypto = struct
|
|||
in
|
||||
let h_pub' =
|
||||
rsa_pub
|
||||
|> Rsa.pub_of_b32
|
||||
|> Rsa.pub_of_crockford
|
||||
|> get_ok
|
||||
|> DenominationHash.hash
|
||||
|> DenominationHash.to_b32
|
||||
|> DenominationHash.to_crockford
|
||||
in
|
||||
assert (h_pub' = h_pub)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -47,25 +47,26 @@ module Arg = struct
|
|||
Arg.Conv.make ~docv:"amount argument" ~parser:Amount.of_string ~pp:Amount.pp
|
||||
()
|
||||
|
||||
let b32 =
|
||||
let pp fmt v = Fmt.pf fmt "%s" (B32.encode v) in
|
||||
Arg.Conv.make ~docv:"Crockford's Base32 encoded argument" ~parser:B32.decode
|
||||
~pp ()
|
||||
let crockford =
|
||||
let pp fmt v = Fmt.pf fmt "%s" (Crockford.encode v) in
|
||||
Arg.Conv.make ~docv:"Crockford's Base32 encoded argument"
|
||||
~parser:Crockford.decode ~pp ()
|
||||
|
||||
let eddsa_pub =
|
||||
let pp fmt key =
|
||||
let s = Eddsa.pub_to_b32 key in
|
||||
let s = Eddsa.pub_to_crockford key in
|
||||
Fmt.pf fmt "%s" s
|
||||
in
|
||||
Arg.Conv.make ~docv:"eddsa public key argument" ~parser:Eddsa.pub_of_b32 ~pp
|
||||
()
|
||||
Arg.Conv.make ~docv:"eddsa public key argument"
|
||||
~parser:Eddsa.pub_of_crockford ~pp ()
|
||||
|
||||
let rsa_pub =
|
||||
let pp fmt key =
|
||||
let s = Rsa.pub_to_b32 key in
|
||||
let s = Rsa.pub_to_crockford key in
|
||||
Fmt.pf fmt "%s" s
|
||||
in
|
||||
Arg.Conv.make ~docv:"rsa public key argument" ~parser:Rsa.pub_of_b32 ~pp ()
|
||||
Arg.Conv.make ~docv:"rsa public key argument" ~parser:Rsa.pub_of_crockford
|
||||
~pp ()
|
||||
end
|
||||
|
||||
let master_key =
|
||||
|
|
@ -310,7 +311,7 @@ let drain_cmd =
|
|||
let credit_payto_uri =
|
||||
Arg.(required & opt (some string) None & info [ "credit_payto_uri" ])
|
||||
in
|
||||
let wtid = Arg.(required & opt (some b32) None & info [ "wtid" ]) in
|
||||
let wtid = Arg.(required & opt (some crockford) None & info [ "wtid" ]) in
|
||||
let date = Arg.(required & opt (some timestamp) None & info [ "date" ]) in
|
||||
let amount = Arg.(required & opt (some amount) None & info [ "amount" ]) in
|
||||
Cmd.make (Cmd.info "drain" ~doc)
|
||||
|
|
|
|||
|
|
@ -202,7 +202,9 @@ let setup ~output ~output_pubkey =
|
|||
@@
|
||||
let priv, pub = Mirage_crypto_ec.Ed25519.generate () in
|
||||
let priv_data = Mirage_crypto_ec.Ed25519.priv_to_octets priv in
|
||||
let pub_data = Mirage_crypto_ec.Ed25519.pub_to_octets pub |> B32.encode in
|
||||
let pub_data =
|
||||
Mirage_crypto_ec.Ed25519.pub_to_octets pub |> Crockford.encode
|
||||
in
|
||||
let* () = write_file output priv_data in
|
||||
let* () = write_file output_pubkey pub_data in
|
||||
Ok ()
|
||||
|
|
@ -223,7 +225,7 @@ let revoke_denom ~output ~master_key ~h_denom =
|
|||
@@
|
||||
let* key = read_master_key_file master_key in
|
||||
let* h_denom_pub =
|
||||
DenominationHash.of_b32 h_denom |> Result.map_error (fun e -> `Msg e)
|
||||
DenominationHash.of_crockford h_denom |> Result.map_error (fun e -> `Msg e)
|
||||
in
|
||||
let denom_revoke =
|
||||
let master_sig =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue