text
stringlengths
0
601k
let deriver obj = Fields_derivers_zkapps . iso_string obj ~ name " : Memo " ~ js_type : String ~ to_string : to_base58_check ~ of_string : of_base58_check_exn ( module struct let data memo = String . sub memo ~ pos ( : length_index + 1 ) 1 ~ len ( : length memo ) memo let % test " digest string " = let s = " this is a ...
module Legacy_token_id = struct let default : ( Field . t , bool ) bool Random_oracle_input . Legacy . t = let one = true :: List . init 63 ~ f ( : fun _ -> false ) false in Random_oracle_input . Legacy . bitstring one [ %% ifdef consensus_mechanism ] consensus_mechanism let default_checked : ( Field . Var . t , Boolea...
module Common = struct module Poly = struct [ %% versioned module Stable = struct module V2 = struct type ( ' fee , ' public_key , ' nonce , ' global_slot , ' memo ) ' memo t = { fee : ' fee ; fee_payer_pk : ' public_key ; nonce : ' nonce ; valid_until : ' global_slot ; memo : ' memo } [ @@ deriving compare , equal , s...
module Body = struct module Binable_arg = struct [ %% versioned module Stable = struct module V2 = struct type t = | Payment of Payment_payload . Stable . V2 . t | Stake_delegation of Stake_delegation . Stable . V1 . t [ @@ deriving sexp ] sexp let to_latest = Fn . id end end ] end end [ %% versioned module Stable = st...
module Poly = struct [ %% versioned module Stable = struct module V1 = struct type ( ' common , ' body ) ' body t = { common : ' common ; body : ' body } [ @@ deriving equal , sexp , hash , yojson , compare , hlist ] hlist let of_latest common_latest body_latest { common ; body } = let open Result . Let_syntax in let %...
module Stable = struct module V2 = struct type t = ( Common . Stable . V2 . t , Body . Stable . V2 . t ) t Poly . Stable . V1 . t [ @@ deriving compare , equal , sexp , hash , yojson ] yojson let to_latest = Fn . id end end ] end
let create ~ fee ~ fee_payer_pk ~ nonce ~ valid_until ~ memo ~ body : t = { common = { fee ; fee_payer_pk ; nonce ; valid_until = Option . value valid_until ~ default : Global_slot . max_value ; memo } ; body }
let fee ( t : t ) t = t . common . fee
let fee_token ( _ : t ) t = Token_id . default
let fee_payer_pk ( t : t ) t = t . common . fee_payer_pk
let fee_payer ( t : t ) t = Account_id . create t . common . fee_payer_pk Token_id . default
let nonce ( t : t ) t = t . common . nonce
let valid_until ( t : t ) t = t . common . valid_until
let memo ( t : t ) t = t . common . memo
let body ( t : t ) t = t . body
let source_pk ( t : t ) t = Body . source_pk t . body
let source ( t : t ) t = Body . source t . body
let receiver_pk ( t : t ) t = Body . receiver_pk t . body
let receiver ( t : t ) t = Body . receiver t . body
let token ( t : t ) t = Body . token t . body
let tag ( t : t ) t = Body . tag t . body
let amount ( t : t ) t = match t . body with | Payment payload -> Some payload . Payment_payload . Poly . amount | Stake_delegation _ -> None
let fee_excess ( t : t ) t = Fee_excess . of_single ( fee_token t , Currency . Fee . Signed . of_unsigned ( fee t ) t ) t
let accounts_accessed ( t : t ) t = [ fee_payer t ; source t ; receiver t ]
let dummy : t = { common = { fee = Currency . Fee . zero ; fee_payer_pk = Public_key . Compressed . empty ; nonce = Account_nonce . zero ; valid_until = Global_slot . max_value ; memo = Memo . dummy } ; body = Payment Payment_payload . dummy }
let gen = let open Quickcheck . Generator . Let_syntax in let % bind common = Common . gen in let max_amount = Currency . Amount ( . sub max_int ( of_fee common . fee ) fee ) fee |> Option . value_exn ? here : None ? error : None ? message : None in let % map body = Body . gen ~ source_pk : common . fee_payer_pk ~ max_...
module Weight = struct let payment ( _payment_payload : Payment_payload . t ) t : int = 1 let stake_delegation ( _stake_delegation : Stake_delegation . t ) t : int = 1 let of_body : Body . t -> int = function | Payment payment_payload -> payment payment_payload | Stake_delegation stake_delegation_payload -> stake_deleg...
let weight ( signed_command_payload : t ) t : int = body signed_command_payload |> Weight . of_body
module Keys = struct type t = { keypair : Keypair . t ; public_key_hex_bytes : string } string let of_keypair keypair = { keypair ; public_key_hex_bytes = Coding . of_public_key keypair . public_key } public_key let to_private_key_bytes t = Coding . of_scalar t . keypair . private_key let of_private_key_bytes s = Codin...
let sign ( ~ keys : Keys . t ) t ~ unsigned_transaction_string = let open Result . Let_syntax in let % bind json = try return ( Yojson . Safe . from_string unsigned_transaction_string ) unsigned_transaction_string with _ -> Result . fail ( Errors . create ( ` Json_parse None ) None ) None in let % map unsigned_transact...
let verify ~ public_key_hex_bytes ~ signed_transaction_string = let open Result . Let_syntax in let % bind json = try return ( Yojson . Safe . from_string signed_transaction_string ) signed_transaction_string with _ -> Result . fail ( Errors . create ( ` Json_parse None ) None ) None in let % map signed_transaction = T...
let sign_command = let open Command . Let_syntax in let % map_open unsigned_transaction = flag " -- unsigned - transaction " ~ aliases [ " : unsigned - transaction ] " ~ doc " : Unsigned transaction string returned from Rosetta " ( required string ) string and private_key = flag " -- private - key " ~ aliases [ " : pri...
let verify_message_command = let open Command . Let_syntax in let % map_open signature = flag " -- signature " ~ doc " : Rosetta signature " ( required string ) string and message = flag " -- message " ~ doc " : Message that was signed " ( required string ) string and public_key = flag " -- public - key " ~ aliases [ "...
let verify_command = let open Command . Let_syntax in let % map_open signed_transaction = flag " -- signed - transaction " ~ aliases [ " : signed - transaction ] " ~ doc " : Signed transaction string returned from Rosetta " ( required string ) string and public_key = flag " -- public - key " ~ aliases [ " : public - ke...
let derive_command = let open Command . Let_syntax in let % map_open private_key = flag " -- private - key " ~ aliases [ " : private - key ] " ~ doc " : Private key hex bytes " ( required string ) string in let open Deferred . Let_syntax in fun ( ) -> let keys = try Signer . Keys . of_private_key_bytes private_key with...
let generate_command = let open Deferred . Let_syntax in Command . Param . return @@ fun ( ) -> let keypair = Keypair . create ( ) in printf " % s \ n " Signer . Keys ( . of_keypair keypair |> to_private_key_bytes ) to_private_key_bytes ; return ( )
let convert_signature_command = let open Command . Let_syntax in let % map_open field_str = flag " -- field " ~ doc " : Field string in decimal ( from client - sdk ) sdk " ( required string ) string and scalar_str = flag " -- scalar " ~ doc " : Scalar string in decimal ( from client - sdk ) sdk " ( required string ) st...
let commands = [ ( " sign " , Command . async ~ summary " : Sign an unsigned transaction " sign_command ) sign_command ; ( " verify " , Command . async ~ summary : " Verify the signature of a signed transaction . Exits 0 if the \ signature verifies . " verify_command ) ; ( " derive - public - key " , Command . async ~ ...
let section = [ " client " ; " signer " ; " socket " ]
let signer_timeout = declare_1 ~ section ~ name " : signer_timeout " ~ msg " : Remote signer timeout , retrying { retry } more time ( s ) " ~ level : Error ( " retry " , Data_encoding . int8 )
let ledger_not_tezos = declare_2 ~ section ~ name " : ledger_not_tezos " ~ msg " : The device at [ { position } ] is not a Tezos application { error } " ~ level : Warning ( " position " , Data_encoding . string ) ( " error " , Data_encoding . string )
let ledger_found_application = declare_3 ~ section ~ name " : ledger_found_application " ~ msg : " Found a { version } application at [ { position } ] ( git - description : \ { commit } ) " ~ level : Info ( " version " , Data_encoding . string ) ( " position " , Data_encoding . string ) ( " commit " , Data_encoding . s...
let ledger_found = declare_2 ~ section ~ name " : ledger_found " ~ msg " : Found { number } Ledger ( s ) { info } " ~ level : Debug ( " number " , Data_encoding . int8 ) ( " info " , Data_encoding . string )
let ledger_processing = declare_1 ~ section ~ name " : ledger_processing " ~ msg " : Processing Ledger at path [ { position } ] " ~ level : Info ( " position " , Data_encoding . string )
module type Authenticated_request = sig type t = { pkh : Signature . Public_key_hash . t ; data : Bytes . t ; signature : Signature . t option ; } val to_sign : pkh : Signature . Public_key_hash . t -> data : Bytes . t -> Bytes . t val encoding : t Data_encoding . t end
module type Tag = sig val tag : int end
module Make_authenticated_request ( T : Tag ) : Authenticated_request = struct type t = { pkh : Signature . Public_key_hash . t ; data : Bytes . t ; signature : Signature . t option ; } let x04 = Bytes . of_string " \ x04 " let to_sign ~ pkh ~ data = let tag = Bytes . make 1 ' 0 ' in TzEndian . set_int8 tag 0 T . tag ;...
module Sign = struct module Request = Make_authenticated_request ( struct let tag = 1 end ) module Response = struct type t = Signature . t let encoding = let open Data_encoding in def " signer_messages . sign . response " @@ obj1 ( req " signature " Signature . encoding ) end end
module Deterministic_nonce = struct module Request = Make_authenticated_request ( struct let tag = 2 end ) module Response = struct type t = Bytes . t let encoding = let open Data_encoding in def " signer_messages . deterministic_nonce . response " @@ obj1 ( req " deterministic_nonce " bytes ) end end
module Deterministic_nonce_hash = struct module Request = Make_authenticated_request ( struct let tag = 3 end ) module Response = struct type t = Bytes . t let encoding = let open Data_encoding in def " signer_messages . deterministic_nonce_hash . response " @@ obj1 ( req " deterministic_nonce_hash " bytes ) end end
module Supports_deterministic_nonces = struct module Request = struct type t = Signature . Public_key_hash . t let encoding = let open Data_encoding in def " signer_messages . supports_deterministic_nonces . request " @@ obj1 ( req " pkh " Signature . Public_key_hash . encoding ) end module Response = struct type t = b...
module Public_key = struct module Request = struct type t = Signature . Public_key_hash . t let encoding = let open Data_encoding in def " signer_messages . public_key . request " @@ obj1 ( req " pkh " Signature . Public_key_hash . encoding ) end module Response = struct type t = Signature . Public_key . t let encoding...
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...
module Request = struct type t = | Sign of Sign . Request . t | Public_key of Public_key . Request . t | Authorized_keys | Deterministic_nonce of Deterministic_nonce . Request . t | Deterministic_nonce_hash of Deterministic_nonce_hash . Request . t | Supports_deterministic_nonces of Supports_deterministic_nonces . Requ...
let ( ) = let open Data_encoding . Registration in register Request . encoding ; register Sign . Response . encoding ; register Deterministic_nonce . Response . encoding ; register Deterministic_nonce_hash . Response . encoding ; register Supports_deterministic_nonces . Response . encoding ; register Public_key . Respo...
let query = let open RPC_query in query ( fun signature -> signature ) |+ opt_field ~ descr : " Must be provided if the signer requires authentication . In this \ case , it must be the signature of the public key hash and message \ concatenated , by one of the keys authorized by the signer . " " authentication " Signat...
let sign = RPC_service . post_service ~ description " : Sign a piece of data with a given remote key " ~ query ~ input : Data_encoding . bytes ~ output : Data_encoding . ( obj1 ( req " signature " Signature . encoding ) ) RPC_path . ( root / " keys " /: Signature . Public_key_hash . rpc_arg )
let deterministic_nonce = RPC_service . post_service ~ description : " Obtain some random data generated deterministically from some piece of \ data with a given remote key " ~ query ~ input : Data_encoding . bytes ~ output : Data_encoding . ( obj1 ( req " deterministic_nonce " bytes ) ) RPC_path . ( root / " keys " /:...
let deterministic_nonce_hash = RPC_service . post_service ~ description : " Obtain the hash of some random data generated deterministically from \ some piece of data with a given remote key " ~ query ~ input : Data_encoding . bytes ~ output : Data_encoding . ( obj1 ( req " deterministic_nonce_hash " bytes ) ) RPC_path ...
let supports_deterministic_nonces = RPC_service . get_service ~ description : " Obtain whether the signing service supports the deterministic nonces \ functionality " ~ query : RPC_query . empty ~ output : Data_encoding . ( obj1 ( req " supports_deterministic_nonces " bool ) ) RPC_path . ( root / " keys " /: Signature ...
let public_key = RPC_service . get_service ~ description " : Retrieve the public key of a given remote key " ~ query : RPC_query . empty ~ output : Data_encoding . ( obj1 ( req " public_key " Signature . Public_key . encoding ) ) RPC_path . ( root / " keys " /: Signature . Public_key_hash . rpc_arg )
let authorized_keys = RPC_service . get_service ~ description : " Retrieve the public keys that can be used to authenticate signing \ commands . \ n \ If the empty object is returned , the signer has been set to accept \ unsigned commands . " ~ query : RPC_query . empty ~ output : Data_encoding . ( obj1 ( opt " authori...
let ( let * ) = Result . bind
module Ext = struct type _ k = | Password : string k | Name : string k | Extensions : Extension . t k module K = struct type ' a t = ' a k let compare : type a b . a t -> b t -> ( a , b ) Gmap . Order . t = fun t t ' -> let open Gmap . Order in match t , t ' with | Password , Password -> Eq | Password , _ -> Lt | _ , P...
type request_info = { subject : Distinguished_name . t ; public_key : Public_key . t ; extensions : Ext . t ; }
type request = { info : request_info ; signature_algorithm : Algorithm . t ; signature : Cstruct . t }
type t = { asn : request ; raw : Cstruct . t ; }
module Asn = struct open Asn_grammars open Asn . S open Registry let attributes = let f = function [ @ ocaml . warning " - 8 " ] | ( oid , [ ` C1 p ] ) when oid = PKCS9 . challenge_password -> Ext . B ( Password , p ) | ( oid , [ ` C1 n ] ) when oid = PKCS9 . unstructured_name -> Ext . B ( Name , n ) | ( oid , [ ` C2 e...
let info { asn ; _ } = asn . info
let signature_algorithm { asn ; _ } = Algorithm . to_signature_algorithm asn . signature_algorithm
let hostnames csr = let info = info csr in let subj = match Distinguished_name . common_name info . subject with | None -> Host . Set . empty | Some x -> match Host . host x with | Some ( typ , n ) -> Host . Set . singleton ( typ , n ) | None -> Host . Set . empty in match Ext . ( find Extensions info . extensions ) wi...
let validate_signature allowed_hashes { asn ; raw } = let raw_data = Validation . raw_cert_hack raw in Validation . validate_raw_signature asn . info . subject allowed_hashes raw_data asn . signature_algorithm asn . signature asn . info . public_key
let decode_der ( ? allowed_hashes = Validation . sha2 ) cs = let * csr = Asn_grammars . err_to_msg ( Asn . signing_request_of_cs cs ) in let csr = { raw = cs ; asn = csr } in let * ( ) = Result . map_error ( fun e -> ` Msg ( Fmt . to_to_string Validation . pp_signature_error e ) ) ( validate_signature allowed_hashes cs...
let encode_der { raw ; _ } = raw
let decode_pem cs = let * data = Pem . parse cs in let crs = List . filter ( fun ( t , _ ) -> String . equal " CERTIFICATE REQUEST " t ) data in let * csrs = Pem . foldM ( fun ( _ , cs ) -> decode_der cs ) crs in Pem . exactly_one ~ what " : certificate request " csrs
let encode_pem v = Pem . unparse ~ tag " : CERTIFICATE REQUEST " ( encode_der v )
let digest_of_key = function | ` RSA _ -> ` SHA256 | ` ED25519 _ -> ` SHA512 | ` P224 _ -> ` SHA224 | ` P256 _ -> ` SHA256 | ` P384 _ -> ` SHA384 | ` P521 _ -> ` SHA512
let default_digest digest key = match digest with None -> digest_of_key key | Some x -> x
let create subject ? digest ( ? extensions = Ext . empty ) ( key : Private_key . t ) = let hash = default_digest digest key in let public_key = Private_key . public key in let info : request_info = { subject ; public_key ; extensions } in let info_cs = Asn . request_info_to_cs info in let scheme = Key_type . x509_defau...
let sign signing_request ~ valid_from ~ valid_until ( ? allowed_hashes = Validation . sha2 ) ? digest ( ? serial = Mirage_crypto_pk . ( Z_extra . gen_r Z . one Z . ( one lsl 64 ) ) ) ( ? extensions = Extension . empty ) ( ? subject = signing_request . asn . info . subject ) key issuer = let hash = default_digest digest...
module Signs = struct include Printable . Std type t = Neg | Zero | Pos [ @@ deriving eq , ord , hash , to_yojson ] let name ( ) = " signs " let show x = match x with | Neg -> " " - | Zero -> " 0 " | Pos -> " " + include Printable . SimpleShow ( struct type nonrec t = t let show = show end ) let of_int i = if compare_c...
module SL = struct include Lattice . Flat ( Signs ) ( Printable . DefaultNames ) let of_int i = ` Lifted ( Signs . of_int i ) let gt x y = match x , y with | ` Lifted x , ` Lifted y -> Signs . gt x y | _ -> false end
module Spec : Analyses . MCPSpec = struct let name ( ) = " signs " module D = MapDomain . MapBot ( Basetype . Variables ) ( SL ) module C = D let startstate v = D . bot ( ) let exitstate = startstate include Analyses . IdentitySpec let eval ( d : D . t ) ( exp : exp ) : SL . t = match exp with | Const ( CInt ( i , _ , ...
let _ = MCP . register_analysis ( module Spec : MCPSpec )
module T = struct type t = | Neg | Zero | Pos | Nan [ @@ deriving_inline sexp , sexp_grammar , compare , hash , enumerate ] let t_of_sexp = ( let error_source__003_ = " sign_or_nan . ml . T . t " in function | Sexplib0 . Sexp . Atom ( " neg " | " Neg " ) -> Neg | Sexplib0 . Sexp . Atom ( " zero " | " Zero " ) -> Zero |...
module Replace_polymorphic_compare = struct let ( < ) ( x : T . t ) y = Poly . ( < ) x y let ( <= ) ( x : T . t ) y = Poly . ( <= ) x y let ( <> ) ( x : T . t ) y = Poly . ( <> ) x y let ( = ) ( x : T . t ) y = Poly . ( = ) x y let ( > ) ( x : T . t ) y = Poly . ( > ) x y let ( >= ) ( x : T . t ) y = Poly . ( >= ) x y ...
let of_sign = function | Sign . Neg -> Neg | Sign . Zero -> Zero | Sign . Pos -> Pos ; ;
let to_sign_exn = function | Neg -> Sign . Neg | Zero -> Sign . Zero | Pos -> Sign . Pos | Nan -> invalid_arg " Base . Sign_or_nan . to_sign_exn : Nan " ; ;
let of_int n = of_sign ( Sign . of_int n )
let to_int_exn t = Sign . to_int ( to_sign_exn t )
let flip = function | Neg -> Pos | Zero -> Zero | Pos -> Neg | Nan -> Nan ; ;
let ( * ) t t ' = match t , t ' with | Nan , _ | _ , Nan -> Nan | _ -> of_sign ( Sign . ( * ) ( to_sign_exn t ) ( to_sign_exn t ' ) ) ; ;
module type ExactDist = sig type ' a t val pdf : ' a t -> float -> float val cdf : ' a t -> float -> float val logpdf : ' a t -> float -> float val logcdf : ' a t -> float -> float end
module type ApproximateDist = sig type ' a t val pdf : ' a t -> float -> float val cdf : ' a t -> float -> float end
module type SampleDist = sig type ' a t val sample : ' a t -> ' a val sampler : ' a t -> unit -> ' a end
module type Primitive_Distributions = sig type ' a primitive val binomial : int -> float -> int primitive val normal : float -> float -> float primitive val categorical : ( ' a * float ) list -> ' a primitive val discrete_uniform : ' a list -> ' a primitive val beta : float -> float -> float primitive val gamma : float...
module type Primitives = sig type ' a t include Primitive_Distributions with type ' a primitive := ' a t type ' a support = | DiscreteFinite of ' a list | DiscreteInfinite | ContinuousFinite of ( ' a * ' a ) list | ContinuousInfinite | Merged of ' a support * ' a support val sample : ' a t -> ' a val pdf : ' a t -> ' a...
module type Ops = sig type ' a dist val ( +~ ) : int dist -> int dist -> int dist val ( -~ ) : int dist -> int dist -> int dist val ( *~ ) : int dist -> int dist -> int dist val ( /~ ) : int dist -> int dist -> int dist val ( . +~ ) : float dist -> float dist -> float dist val ( . -~ ) : float dist -> float dist -> flo...
module type Prob = sig type t val to_float : t -> float val of_float : float -> t val ( = ) : t -> t -> bool val ( . * ) : t -> t -> t val ( . / ) : t -> t -> t val ( + ) : t -> t -> t val min : t -> t -> t val one : t val zero : t end
module LogProb : Prob = struct type t = float let to_float p = let e = exp p in if Float . is_finite e then e else 1 . let of_float p = log p let ( = ) = Float . equal let ( . * ) = ( . + ) let ( . / ) = ( . - ) let ( + ) x y = if x = . - Float . infinity && y = . - Float . infinity then . - Float . infinity else let x...