ligo/src/lib_signer_services/signer_messages.ml

131 lines
3.4 KiB
OCaml
Raw Normal View History

2018-05-22 20:04:37 +04:00
(**************************************************************************)
(* *)
(* Copyright (c) 2014 - 2018. *)
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)
module Sign = struct
2018-05-22 20:04:37 +04:00
module Request = struct
2018-05-22 20:04:37 +04:00
type t = {
pkh: Signature.Public_key_hash.t ;
2018-05-22 20:04:37 +04:00
data: MBytes.t ;
2018-06-06 12:49:53 +04:00
signature: Signature.t option ;
2018-05-22 20:04:37 +04:00
}
2018-06-06 12:49:53 +04:00
let to_sign ~pkh ~data =
MBytes.concat ""
[ MBytes.of_hex (`Hex "04") ;
Signature.Public_key_hash.to_bytes pkh ;
data ]
2018-05-22 20:04:37 +04:00
let encoding =
let open Data_encoding in
conv
2018-06-06 12:49:53 +04:00
(fun { pkh ; data ; signature } ->
(pkh, data, signature))
(fun (pkh, data, signature) ->
{ pkh ; data ; signature })
(obj3
(req "pkh" Signature.Public_key_hash.encoding)
2018-06-06 12:49:53 +04:00
(req "data" bytes)
(opt "signature" Signature.encoding))
2018-05-22 20:04:37 +04:00
end
module Response = struct
type t = Signature.t
2018-05-22 20:04:37 +04:00
let encoding =
Data_encoding.(obj1 (req "signature" Signature.encoding))
2018-05-22 20:04:37 +04:00
end
2018-05-22 20:04:37 +04:00
end
module Public_key = struct
2018-05-22 20:04:37 +04:00
module Request = struct
type t = Signature.Public_key_hash.t
2018-05-22 20:04:37 +04:00
let encoding =
Data_encoding.(obj1 (req "pkh" Signature.Public_key_hash.encoding))
2018-05-22 20:04:37 +04:00
end
module Response = struct
type t = Signature.Public_key.t
2018-05-22 20:04:37 +04:00
let encoding =
Data_encoding.(obj1 (req "pubkey" Signature.Public_key.encoding))
2018-05-22 20:04:37 +04:00
end
2018-05-22 20:04:37 +04:00
end
2018-06-06 12:49:53 +04:00
module Authorized_keys = struct
module Response = struct
type t =
| No_authentication
| Authorized_keys of Signature.Public_key_hash.t list
let encoding =
let open Data_encoding in
union
[ case (Tag 0)
~title: "No_authentication"
(constant "no_authentication_required")
(function No_authentication -> Some () | _ -> None)
(fun () -> No_authentication) ;
case (Tag 1)
~title: "Authorized_keys"
(list Signature.Public_key_hash.encoding)
(function Authorized_keys l -> Some l | _ -> None)
(fun l -> Authorized_keys l) ]
end
end
2018-05-22 20:04:37 +04:00
module Request = struct
2018-05-22 20:04:37 +04:00
type t =
| Sign of Sign.Request.t
| Public_key of Public_key.Request.t
2018-06-06 12:49:53 +04:00
| Authorized_keys
2018-05-22 20:04:37 +04:00
let encoding =
let open Data_encoding in
union [
case (Tag 0)
~title:"Sign"
(merge_objs
(obj1 (req "kind" (constant "sign")))
Sign.Request.encoding)
(function Sign req -> Some ((), req) | _ -> None)
(fun ((), req) -> Sign req) ;
case (Tag 1)
~title:"Public_key"
(merge_objs
(obj1 (req "kind" (constant "public_key")))
Public_key.Request.encoding)
(function Public_key req -> Some ((), req) | _ -> None)
(fun ((), req) -> Public_key req) ;
2018-06-06 12:49:53 +04:00
case (Tag 2)
~title:"Authorized_keys"
(obj1 (req "kind" (constant "authorized_keys")))
(function Authorized_keys -> Some () | _ -> None)
(fun () -> Authorized_keys) ;
]
2018-05-22 20:04:37 +04:00
end