dune: add mte library; + wip key jsont

This commit is contained in:
Swrup 2025-10-03 21:24:02 +02:00
parent d5eaf6d92f
commit a04e179c08
5 changed files with 47 additions and 34 deletions

View file

@ -21,4 +21,6 @@ let decode s =
| c -> c) | c -> c)
s s
in 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

View file

@ -1,13 +1,18 @@
(executable (executable
(public_name mte) (public_name mte)
(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 (libraries
json base_32
types
headers_lib
syntax
; ;
angstrom
zarith ;
mirage-crypto mirage-crypto
duration duration
vif vif
@ -15,29 +20,7 @@
jsont jsont
cohttp)) cohttp))
(library ; crockford base32, as a lib to use [Base32] by accident *)
(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))
(library (library
(name base_32) (name base_32)

View file

@ -75,3 +75,12 @@ end
let amount_jsont = let amount_jsont =
Jsont.of_of_string ~kind:"Amount" Amount.of_string ~enc:Amount.to_string 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

View file

@ -112,20 +112,39 @@ module Amount = struct
end end
module Eddsa = struct module Eddsa = struct
(* TODO test *)
(* EdDSA and ECDHE public keys always point on Curve25519 (* EdDSA and ECDHE public keys always point on Curve25519
and represented using the standard 256 bits Ed25519 compact format, and represented using the standard 256 bits Ed25519 compact format,
converted to Crockford Base32. *) converted to Crockford Base32. *)
type pub = string type pub = Mirage_crypto_ec.Ed25519.pub
type priv = string
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 (* EdDSA signatures are transmitted as 64-bytes base32
binary-encoded objects with just the R and S values (base32_ binary-only). *) binary-encoded objects with just the R and S values (base32_ binary-only). *)
type signature = string (*type signature = string*)
end end
module Rsa = struct module Rsa = struct
(* RSA public key converted to Crockford Base32. *) (* 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 end
module Hash_code = struct module Hash_code = struct

View file

@ -1,4 +1,4 @@
(test (test
(name test) (name test)
(modules test) (modules test)
(libraries types json)) (libraries mte fmt))