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. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2018-05-24 04:26:10 +04:00
|
|
|
type error += Unkwnon_alias_key of string
|
2018-05-22 20:04:37 +04:00
|
|
|
|
|
|
|
let () =
|
|
|
|
register_error_kind `Permanent
|
|
|
|
~id: "signer.unknown_alias_key"
|
|
|
|
~title: "Unkwnon_alias_key"
|
|
|
|
~description: "A remote key does not exists"
|
|
|
|
~pp: (fun ppf s ->
|
|
|
|
Format.fprintf ppf "The key %s does not is not known on the remote signer" s)
|
|
|
|
Data_encoding.(obj1 (req "value" string))
|
|
|
|
(function Unkwnon_alias_key s -> Some s | _ -> None)
|
2018-05-24 04:26:10 +04:00
|
|
|
(fun s -> Unkwnon_alias_key s)
|
2018-05-22 20:04:37 +04:00
|
|
|
|
|
|
|
type key = string
|
|
|
|
|
|
|
|
module Sign = struct
|
|
|
|
module Request = struct
|
|
|
|
type t = {
|
2018-05-24 04:26:10 +04:00
|
|
|
key : key ;
|
2018-05-22 20:04:37 +04:00
|
|
|
data: MBytes.t ;
|
|
|
|
}
|
|
|
|
|
|
|
|
let encoding =
|
|
|
|
let open Data_encoding in
|
|
|
|
conv
|
|
|
|
(fun { key ; data } ->
|
|
|
|
( key, data))
|
|
|
|
(fun (key, data) ->
|
|
|
|
{ key ; data })
|
|
|
|
(obj2
|
|
|
|
(req "key" string)
|
|
|
|
(req "data" bytes))
|
|
|
|
end
|
|
|
|
|
|
|
|
module Response = struct
|
|
|
|
type t = {
|
|
|
|
signature : Signature.t
|
|
|
|
}
|
|
|
|
|
|
|
|
let encoding =
|
|
|
|
let open Data_encoding in
|
|
|
|
conv
|
|
|
|
(fun { signature } -> (signature))
|
|
|
|
(fun (signature) -> { signature })
|
|
|
|
(obj1 (req "signature" Signature.encoding))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module Public_key = struct
|
|
|
|
module Request = struct
|
|
|
|
type t = {
|
2018-05-24 04:26:10 +04:00
|
|
|
key : key ;
|
2018-05-22 20:04:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
let encoding =
|
|
|
|
let open Data_encoding in
|
|
|
|
conv
|
|
|
|
(fun { key } -> key)
|
|
|
|
(fun key -> { key })
|
|
|
|
(obj1 (req "key" string))
|
|
|
|
end
|
|
|
|
|
|
|
|
module Response = struct
|
|
|
|
type t = {
|
2018-05-24 04:26:10 +04:00
|
|
|
public_key : Signature.Public_key.t ;
|
2018-05-22 20:04:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
let encoding =
|
|
|
|
let open Data_encoding in
|
|
|
|
conv
|
|
|
|
(fun { public_key } -> public_key)
|
|
|
|
(fun public_key -> { public_key })
|
|
|
|
(obj1 (req "pubkey" Signature.Public_key.encoding))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module Request = struct
|
|
|
|
type t =
|
|
|
|
| Sign of Sign.Request.t
|
|
|
|
| Public_key of Public_key.Request.t
|
|
|
|
|
|
|
|
let encoding =
|
|
|
|
let open Data_encoding in
|
|
|
|
union
|
|
|
|
[ case (Tag 0) (merge_objs (obj1 (req "kind" (constant "sign"))) Sign.Request.encoding)
|
|
|
|
(function Sign req -> Some ((), req) | _ -> None)
|
|
|
|
(fun ((), req) -> Sign req) ;
|
|
|
|
case (Tag 1) (merge_objs (obj1 (req "kind" (constant "public_key"))) Public_key.Request.encoding)
|
|
|
|
(function Public_key req -> Some ((), req) | _ -> None)
|
|
|
|
(fun ((), req) -> Public_key req) ]
|
|
|
|
end
|