dune: add mte library; + wip key jsont
This commit is contained in:
parent
d5eaf6d92f
commit
a04e179c08
5 changed files with 47 additions and 34 deletions
|
|
@ -21,4 +21,6 @@ let decode s =
|
|||
| c -> c)
|
||||
s
|
||||
in
|
||||
Base32.decode ~alphabet ~off:0 ~len:(String.length s) s
|
||||
match Base32.decode ~alphabet ~off:0 ~len:(String.length s) s with
|
||||
| Error (`Msg e) -> Error e
|
||||
| Ok v -> Ok v
|
||||
|
|
|
|||
39
src/dune
39
src/dune
|
|
@ -1,13 +1,18 @@
|
|||
(executable
|
||||
(public_name mte)
|
||||
(name mte)
|
||||
(modules assets assets_crunch headers mte config util management)
|
||||
(modules mte)
|
||||
(libraries mte))
|
||||
|
||||
(library
|
||||
(name mte)
|
||||
(wrapped false)
|
||||
(modules :standard \ mte base_32)
|
||||
(libraries
|
||||
json
|
||||
types
|
||||
headers_lib
|
||||
syntax
|
||||
base_32
|
||||
;
|
||||
angstrom
|
||||
zarith ;
|
||||
mirage-crypto
|
||||
duration
|
||||
vif
|
||||
|
|
@ -15,29 +20,7 @@
|
|||
jsont
|
||||
cohttp))
|
||||
|
||||
(library
|
||||
(name json)
|
||||
(modules json)
|
||||
(libraries jsont jsont.bytesrw fmt syntax types))
|
||||
|
||||
(library
|
||||
(name types)
|
||||
(modules types)
|
||||
(libraries
|
||||
angstrom
|
||||
zarith ;
|
||||
fmt
|
||||
syntax))
|
||||
|
||||
(library
|
||||
(name headers_lib)
|
||||
(modules headers_lib)
|
||||
(libraries fmt syntax))
|
||||
|
||||
(library
|
||||
(name syntax)
|
||||
(modules syntax)
|
||||
(libraries))
|
||||
; crockford base32, as a lib to use [Base32] by accident *)
|
||||
|
||||
(library
|
||||
(name base_32)
|
||||
|
|
|
|||
|
|
@ -75,3 +75,12 @@ end
|
|||
|
||||
let amount_jsont =
|
||||
Jsont.of_of_string ~kind:"Amount" Amount.of_string ~enc:Amount.to_string
|
||||
|
||||
module Eddsa = struct
|
||||
open Eddsa
|
||||
|
||||
let pub_jsont =
|
||||
let dec = Jsont.Base.dec_result pub_of_string in
|
||||
let enc = Jsont.Base.enc pub_to_string in
|
||||
Jsont.Base.string (Jsont.Base.map ~kind:"EddsaPublicKey" ~dec ~enc ())
|
||||
end
|
||||
|
|
|
|||
27
src/types.ml
27
src/types.ml
|
|
@ -112,20 +112,39 @@ module Amount = struct
|
|||
end
|
||||
|
||||
module Eddsa = struct
|
||||
(* TODO test *)
|
||||
(* EdDSA and ECDHE public keys always point on Curve25519
|
||||
and represented using the standard 256 bits Ed25519 compact format,
|
||||
converted to Crockford Base32. *)
|
||||
type pub = string
|
||||
type priv = string
|
||||
type pub = Mirage_crypto_ec.Ed25519.pub
|
||||
|
||||
let pub_of_string s =
|
||||
let open Mirage_crypto_ec in
|
||||
match Base_32.decode s with
|
||||
| Error _ as err -> err
|
||||
| Ok octets -> (
|
||||
match Ed25519.pub_of_octets octets with
|
||||
| Error e -> Fmt.error "%a" pp_error e
|
||||
| Ok pub -> Ok pub)
|
||||
|
||||
let pub_to_string pub =
|
||||
pub |> Mirage_crypto_ec.Ed25519.pub_to_octets |> Base_32.encode
|
||||
|
||||
(*type priv = string*)
|
||||
(* EdDSA signatures are transmitted as 64-bytes base32
|
||||
binary-encoded objects with just the R and S values (base32_ binary-only). *)
|
||||
type signature = string
|
||||
(*type signature = string*)
|
||||
end
|
||||
|
||||
module Rsa = struct
|
||||
(* RSA public key converted to Crockford Base32. *)
|
||||
type pub = string
|
||||
type pub = Mirage_crypto_pk.Rsa.pub
|
||||
|
||||
(* TODO
|
||||
how to read/write pub rsa key
|
||||
what format is used? *)
|
||||
let pub_of_string _s = assert false
|
||||
let pub_to_string _pub = assert false
|
||||
end
|
||||
|
||||
module Hash_code = struct
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue