From 557892050758d9d7762faf740de343079657f511 Mon Sep 17 00:00:00 2001 From: swrup Date: Wed, 8 Oct 2025 21:38:30 +0200 Subject: [PATCH] functor for Time --- src/binary_formats.ml | 219 +++++++++++++++++------------------------- 1 file changed, 89 insertions(+), 130 deletions(-) diff --git a/src/binary_formats.ml b/src/binary_formats.ml index a71bd535..6cc012ad 100644 --- a/src/binary_formats.ml +++ b/src/binary_formats.ml @@ -12,71 +12,30 @@ let int64_size = 8 (* -- Time -- *) -module Time = struct - module Absolute = struct - type t = { timestamp_us: int64 } +module MK_TIME () = struct + type t = { v: int64 } - (* not BE here? never used? *) - let bin = - let open Bin in - record (fun timestamp_us -> { timestamp_us }) - |+ field neint64 (fun t -> t.timestamp_us) - |> sealr - end - - module AbsoluteNBO = struct - type t = { abs_value_us__: int64 } - - let bin = - let open Bin in - record (fun abs_value_us__ -> { abs_value_us__ }) - |+ field beint64 (fun t -> t.abs_value_us__) - |> sealr - end - - module Relative = struct - type t = { timestamp_us: int64 } - - let bin = - let open Bin in - record (fun timestamp_us -> { timestamp_us }) - |+ field neint64 (fun t -> t.timestamp_us) - |> sealr - end - - module RelativeNBO = struct - type t = { rel_value_us__: int64 } - - let bin = - let open Bin in - record (fun rel_value_us__ -> { rel_value_us__ }) - |+ field beint64 (fun t -> t.rel_value_us__) - |> sealr - end - - (* TODO Taler doc: missing Timestamp(NBO) *) - module Timestamp = struct - type t = { timestamp_us: int64 } - - (* not BE here? never used? *) - let bin = - let open Bin in - record (fun timestamp_us -> { timestamp_us }) - |+ field neint64 (fun t -> t.timestamp_us) - |> sealr - end - - module TimestampNBO = struct - type t = { abs_value_us__: int64 } - - let bin = - let open Bin in - record (fun abs_value_us__ -> { abs_value_us__ }) - |+ field beint64 (fun t -> t.abs_value_us__) - |> sealr - end + (* not BE (?) *) + let bin = + let open Bin in + record (fun v -> { v }) |+ field neint64 (fun t -> t.v) |> sealr end +module MK_TIME_NBO () = struct + type t = { v: int64 } + + let bin = + let open Bin in + record (fun v -> { v }) |+ field beint64 (fun t -> t.v) |> sealr +end + +module TimeAbsolute = MK_TIME () +module TimeAbsoluteNBO = MK_TIME_NBO () +module TimeRelative = MK_TIME () +module TimeRelativeNBO = MK_TIME_NBO () +module TimeTimestamp = MK_TIME () +module TimeTimestampNBO = MK_TIME_NBO () + (* -- Cryptographic primitives -- *) (* MK_BASIC_XX functor for structs like: @@ -520,8 +479,8 @@ module DepositRequestPS = struct h_policy: ExtensionsPolicyHash.t; h_wire: MerchantWireHash.t; h_denom_pub: DenominationHash.t; - timestamp: Time.AbsoluteNBO.t; - refund_deadline: Time.AbsoluteNBO.t; + timestamp: TimeAbsoluteNBO.t; + refund_deadline: TimeAbsoluteNBO.t; amount_with_fee: AmountNBO.t; deposit_fee: AmountNBO.t; merchant: MerchantPublicKeyP.t; @@ -535,8 +494,8 @@ module DepositConfirmationPS = struct h_contract_terms: PrivateContractHash.t; h_wire: MerchantWireHash.t; h_policy: ExtensionsPolicyHash.t; - timestamp: Time.AbsoluteNBO.t; - refund_deadline: Time.AbsoluteNBO.t; + timestamp: TimeAbsoluteNBO.t; + refund_deadline: TimeAbsoluteNBO.t; amount_without_fee: AmountNBO.t; coin_pub: CoinSpendPublicKeyP.t; merchant: MerchantPublicKeyP.t; @@ -574,9 +533,9 @@ end module ExchangeSigningKeyValidityPS = struct (* purpose.purpose = TALER_SIGNATURE_MASTER_SIGNING_KEY_VALIDITY *) type t = { - start: Time.AbsoluteNBO.t; - expire: Time.AbsoluteNBO.t; - end_: Time.AbsoluteNBO.t; (* "end" renamed to end_ *) + start: TimeAbsoluteNBO.t; + expire: TimeAbsoluteNBO.t; + end_: TimeAbsoluteNBO.t; (* "end" renamed to end_ *) signkey_pub: ExchangePublicKeyP.t; } end @@ -584,7 +543,7 @@ end module ExchangeKeySetPS = struct (* purpose.purpose = TALER_SIGNATURE_EXCHANGE_KEY_SET *) type t = { - list_issue_date: Time.AbsoluteNBO.t; + list_issue_date: TimeAbsoluteNBO.t; hc: HashCode.t; } end @@ -593,10 +552,10 @@ module DenominationKeyValidityPS = struct (* purpose.purpose = TALER_SIGNATURE_MASTER_DENOMINATION_KEY_VALIDITY *) type t = { master: MasterPublicKeyP.t; - start: Time.AbsoluteNBO.t; - expire_withdraw: Time.AbsoluteNBO.t; - expire_spend: Time.AbsoluteNBO.t; - expire_legal: Time.AbsoluteNBO.t; + start: TimeAbsoluteNBO.t; + expire_withdraw: TimeAbsoluteNBO.t; + expire_spend: TimeAbsoluteNBO.t; + expire_legal: TimeAbsoluteNBO.t; value: AmountNBO.t; fee_withdraw: AmountNBO.t; fee_deposit: AmountNBO.t; @@ -619,8 +578,8 @@ module MasterWireFeePS = struct (* purpose.purpose = TALER_SIGNATURE_MASTER_WIRE_FEES *) type t = { h_wire_method: HashCode.t; - start_date: Time.AbsoluteNBO.t; - end_date: Time.AbsoluteNBO.t; + start_date: TimeAbsoluteNBO.t; + end_date: TimeAbsoluteNBO.t; wire_fee: AmountNBO.t; closing_fee: AmountNBO.t; } @@ -629,11 +588,11 @@ end module GlobalFeesPS = struct (* purpose.purpose = TALER_SIGNATURE_MASTER_GLOBAL_FEES *) type t = { - start_date: Time.AbsoluteNBO.t; - end_date: Time.AbsoluteNBO.t; - purse_timeout: Time.RelativeNBO.t; - kyc_timeout: Time.RelativeNBO.t; - history_expiration: Time.RelativeNBO.t; + start_date: TimeAbsoluteNBO.t; + end_date: TimeAbsoluteNBO.t; + purse_timeout: TimeRelativeNBO.t; + kyc_timeout: TimeRelativeNBO.t; + history_expiration: TimeRelativeNBO.t; history_fee: AmountNBO.t; kyc_fee: AmountNBO.t; account_fee: AmountNBO.t; @@ -646,7 +605,7 @@ module MasterDrainProfitPS = struct (* purpose.purpose = TALER_SIGNATURE_MASTER_DRAIN_PROFITS *) type t = { wtid: WireTransferIdentifierRawP.t; - date: Time.AbsoluteNBO.t; + date: TimeAbsoluteNBO.t; amount: AmountNBO.t; h_section: HashCode.t; h_payto: FullPaytoHash.t; @@ -665,7 +624,7 @@ end module WireDepositDetailP = struct type t = { h_contract_terms: PrivateContractHash.t; - execution_time: Time.AbsoluteNBO.t; + execution_time: TimeAbsoluteNBO.t; coin_pub: CoinSpendPublicKeyP.t; deposit_value: AmountNBO.t; deposit_fee: AmountNBO.t; @@ -688,10 +647,10 @@ module ExchangeKeyValidityPS = struct type t = { auditor_url_hash: HashCode.t; master: MasterPublicKeyP.t; - start: Time.AbsoluteNBO.t; - expire_withdraw: Time.AbsoluteNBO.t; - expire_spend: Time.AbsoluteNBO.t; - expire_legal: Time.AbsoluteNBO.t; + start: TimeAbsoluteNBO.t; + expire_withdraw: TimeAbsoluteNBO.t; + expire_spend: TimeAbsoluteNBO.t; + expire_legal: TimeAbsoluteNBO.t; value: AmountNBO.t; fee_withdraw: AmountNBO.t; fee_deposit: AmountNBO.t; @@ -717,7 +676,7 @@ module ConfirmWirePS = struct h_contract_terms: PrivateContractHash.t; wtid: WireTransferIdentifierRawP.t; coin_pub: CoinSpendPublicKeyP.t; - execution_time: Time.AbsoluteNBO.t; + execution_time: TimeAbsoluteNBO.t; coin_contribution: AmountNBO.t; } end @@ -771,7 +730,7 @@ end module RecoupRefreshConfirmationPS = struct (* purpose.purpose = TALER_SIGNATURE_EXCHANGE_CONFIRM_RECOUP_REFRESH *) type t = { - timestamp: Time.AbsoluteNBO.t; + timestamp: TimeAbsoluteNBO.t; recoup_amount: AmountNBO.t; coin_pub: CoinSpendPublicKeyP.t; old_coin_pub: CoinSpendPublicKeyP.t; @@ -781,7 +740,7 @@ end module RecoupConfirmationPS = struct (* purpose.purpose = TALER_SIGNATURE_EXCHANGE_CONFIRM_RECOUP *) type t = { - timestamp: Time.AbsoluteNBO.t; + timestamp: TimeAbsoluteNBO.t; recoup_amount: AmountNBO.t; coin_pub: CoinSpendPublicKeyP.t; reserve_pub: ReservePublicKeyP.t; @@ -791,7 +750,7 @@ end module DenominationUnknownAffirmationPS = struct (* purpose.purpose = TALER_SIGNATURE_EXCHANGE_AFFIRM_DENOM_UNKNOWN *) type t = { - timestamp: Time.AbsoluteNBO.t; + timestamp: TimeAbsoluteNBO.t; h_denom_pub: DenominationHash.t; } end @@ -799,7 +758,7 @@ end module DenominationExpiredAffirmationPS = struct (* purpose.purpose = TALER_SIGNATURE_EXCHANGE_GENERIC_DENOMINATIN_EXPIRED *) type t = { - timestamp: Time.AbsoluteNBO.t; + timestamp: TimeAbsoluteNBO.t; operation: string; (* char[8] → string *) h_denom_pub: DenominationHash.t; } @@ -808,7 +767,7 @@ end module ReserveCloseConfirmationPS = struct (* purpose.purpose = TALER_SIGNATURE_EXCHANGE_RESERVE_CLOSED *) type t = { - timestamp: Time.AbsoluteNBO.t; + timestamp: TimeAbsoluteNBO.t; closing_amount: AmountNBO.t; reserve_pub: ReservePublicKeyP.t; h_wire: FullPaytoHash.t; @@ -832,14 +791,14 @@ end module ReserveStatusRequestSignaturePS = struct (* purpose.purpose = TALER_SIGNATURE_RESERVE_STATUS_REQUEST *) - type t = { request_timestamp: Time.AbsoluteNBO.t } + type t = { request_timestamp: TimeAbsoluteNBO.t } end module ReserveHistoryRequestSignaturePS = struct (* purpose.purpose = TALER_SIGNATURE_RESERVE_HISTORY_REQUEST *) type t = { history_fee: AmountNBO.t; - request_timestamp: Time.AbsoluteNBO.t; + request_timestamp: TimeAbsoluteNBO.t; } end @@ -854,8 +813,8 @@ module PurseStatusResponseSignaturePS = struct total_purse_amount: AmountNBO.t; total_deposit_amount: AmountNBO.t; max_deposit_fees: AmountNBO.t; - purse_expiration: Time.AbsoluteNBO.t; - status_timestamp: Time.AbsoluteNBO.t; + purse_expiration: TimeAbsoluteNBO.t; + status_timestamp: TimeAbsoluteNBO.t; h_contract_terms: PrivateContractHash.t; } end @@ -868,7 +827,7 @@ end module PurseRequestSignaturePS = struct (* purpose.purpose = TALER_SIGNATURE_WALLET_PURSE_CREATE *) type t = { - purse_expiration: Time.AbsoluteNBO.t; + purse_expiration: TimeAbsoluteNBO.t; merge_value_after_fees: AmountNBO.t; h_contract_terms: PrivateContractHash.t; min_age: int; @@ -900,7 +859,7 @@ module PurseDepositConfirmedSignaturePS = struct total_purse_amount: AmountNBO.t; total_deposit_fees: AmountNBO.t; purse_pub: PursePublicKey.t; - purse_expiration: Time.AbsoluteNBO.t; + purse_expiration: TimeAbsoluteNBO.t; h_contract_terms: PrivateContractHash.t; } end @@ -908,7 +867,7 @@ end module PurseMergeSignaturePS = struct (* purpose.purpose = TALER_SIGNATURE_WALLET_PURSE_MERGE *) type t = { - merge_timestamp: Time.AbsoluteNBO.t; + merge_timestamp: TimeAbsoluteNBO.t; h_wire: NormalizedPaytoHash.t; } end @@ -919,8 +878,8 @@ module AccountMergeSignaturePS = struct reserve_pub: ReservePublicKeyP.t; purse_pub: PursePublicKey.t; merge_amount_after_fees: AmountNBO.t; - merge_timestamp: Time.AbsoluteNBO.t; - purse_expiration: Time.AbsoluteNBO.t; + merge_timestamp: TimeAbsoluteNBO.t; + purse_expiration: TimeAbsoluteNBO.t; h_contract_terms: PrivateContractHash.t; min_age: int; } @@ -937,7 +896,7 @@ module PurseMergeSuccessSignaturePS = struct reserve_pub: ReservePublicKeyP.t; purse_pub: PursePublicKey.t; merge_amount_after_fees: AmountNBO.t; - contract_time: Time.AbsoluteNBO.t; + contract_time: TimeAbsoluteNBO.t; h_contract_terms: PrivateContractHash.t; h_wire: NormalizedPaytoHash.t; min_age: int; @@ -947,7 +906,7 @@ end module WadDataSignaturePS = struct (* purpose.purpose = TALER_SIGNATURE_WAD_DATA *) type t = { - wad_execution_time: Time.AbsoluteNBO.t; + wad_execution_time: TimeAbsoluteNBO.t; total_amount: AmountNBO.t; h_items: HashCode.t; wad_id: WadId.t; @@ -959,24 +918,24 @@ module WadPartnerSignaturePS = struct type t = { h_partner_base_url: HashCode.t; master_public_key: MasterPublicKeyP.t; - start_date: Time.AbsoluteNBO.t; - end_date: Time.AbsoluteNBO.t; + start_date: TimeAbsoluteNBO.t; + end_date: TimeAbsoluteNBO.t; wad_fee: AmountNBO.t; - wad_frequency: Time.RelativeNBO.t; + wad_frequency: TimeRelativeNBO.t; } end module P2PFeesPS = struct (* purpose.purpose = TALER_SIGNATURE_P2P_FEES *) type t = { - start_date: Time.AbsoluteNBO.t; - end_date: Time.AbsoluteNBO.t; + start_date: TimeAbsoluteNBO.t; + end_date: TimeAbsoluteNBO.t; kyc_fee: AmountNBO.t; purse_fee: AmountNBO.t; account_history_fee: AmountNBO.t; account_annual_fee: AmountNBO.t; - account_kyc_timeout: Time.RelativeNBO.t; - purse_timeout: Time.RelativeNBO.t; + account_kyc_timeout: TimeRelativeNBO.t; + purse_timeout: TimeRelativeNBO.t; purse_account_limit: int; } end @@ -996,8 +955,8 @@ module DenominationKeyAnnouncementPS = struct type t = { h_denom_pub: DenominationHash.t; h_section_name: HashCode.t; - anchor_time: Time.AbsoluteNBO.t; - duration_withdraw: Time.RelativeNBO.t; + anchor_time: TimeAbsoluteNBO.t; + duration_withdraw: TimeRelativeNBO.t; } end @@ -1005,8 +964,8 @@ module SigningKeyAnnouncementPS = struct (* purpose.purpose = TALER_SIGNATURE_SM_SIGNING_KEY *) type t = { exchange_pub: ExchangePublicKeyP.t; - anchor_time: Time.AbsoluteNBO.t; - duration: Time.RelativeNBO.t; + anchor_time: TimeAbsoluteNBO.t; + duration: TimeRelativeNBO.t; } end @@ -1023,7 +982,7 @@ end module MasterAddAuditorPS = struct (* purpose.purpose = TALER_SIGNATURE_MASTER_ADD_AUDITOR *) type t = { - start_date: Time.AbsoluteNBO.t; + start_date: TimeAbsoluteNBO.t; auditor_pub: AuditorPublicKeyP.t; h_auditor_url: HashCode.t; } @@ -1032,7 +991,7 @@ end module MasterDelAuditorPS = struct (* purpose.purpose = TALER_SIGNATURE_MASTER_DEL_AUDITOR *) type t = { - end_date: Time.AbsoluteNBO.t; + end_date: TimeAbsoluteNBO.t; auditor_pub: AuditorPublicKeyP.t; } end @@ -1040,7 +999,7 @@ end module MasterAddWirePS = struct (* purpose.purpose = TALER_SIGNATURE_MASTER_ADD_WIRE *) type t = { - start_date: Time.AbsoluteNBO.t; + start_date: TimeAbsoluteNBO.t; h_wire: FullPaytoHash.t; h_conversion_url: HashCode.t; h_credit_restrictions: HashCode.t; @@ -1051,7 +1010,7 @@ end module MasterDelWirePS = struct (* purpose.purpose = TALER_SIGNATURE_MASTER_DEL_WIRE *) type t = { - end_date: Time.AbsoluteNBO.t; + end_date: TimeAbsoluteNBO.t; h_wire: FullPaytoHash.t; } end @@ -1059,7 +1018,7 @@ end module MasterAmlOfficerStatusPS = struct (* purpose.purpose = TALER_SIGNATURE_MASTER_AML_KEY *) type t = { - change_date: Time.TimestampNBO.t; + change_date: TimeTimestampNBO.t; officer_pub: AmlOfficerPublicKeyP.t; h_officer_name: HashCode.t; is_active: int; @@ -1070,7 +1029,7 @@ module AmlDecisionPS = struct (* purpose.purpose = TALER_SIGNATURE_AML_DECISION *) type t = { h_justification: HashCode.t; - decision_time: Time.TimestampNBO.t; + decision_time: TimeTimestampNBO.t; new_threshold: AmountNBO.t; h_payto: NormalizedPaytoHash.t; h_kyc_requirements: HashCode.t; @@ -1082,9 +1041,9 @@ module PartnerConfigurationPS = struct (* purpose.purpose = TALER_SIGNATURE_MASTER_PARNTER_DETAILS *) type t = { partner_pub: MasterPublicKeyP.t; - start_date: Time.TimestampNBO.t; - end_date: Time.TimestampNBO.t; - wad_frequency: Time.RelativeNBO.t; + start_date: TimeTimestampNBO.t; + end_date: TimeTimestampNBO.t; + wad_frequency: TimeRelativeNBO.t; wad_fee: AmountNBO.t; h_url: HashCode.t; } @@ -1094,8 +1053,8 @@ module ReserveOpenPS = struct (* purpose.purpose = TALER_SIGNATURE_WALLET_RESERVE_OPEN *) type t = { reserve_payment: AmountNBO.t; - request_timestamp: Time.TimestampNBO.t; - reserve_expiration: Time.TimestampNBO.t; + request_timestamp: TimeTimestampNBO.t; + reserve_expiration: TimeTimestampNBO.t; purse_limit: int; } end @@ -1103,7 +1062,7 @@ end module ReserveClosePS = struct (* purpose.purpose = TALER_SIGNATURE_WALLET_RESERVE_CLOSE *) type t = { - request_timestamp: Time.TimestampNBO.t; + request_timestamp: TimeTimestampNBO.t; target_account_h_payto: FullPaytoHash.t; } end @@ -1111,7 +1070,7 @@ end module ReserveAttestRequestPS = struct (* purpose.purpose = TALER_SIGNATURE_WALLET_ATTEST_REQUEST *) type t = { - request_timestamp: Time.TimestampNBO.t; + request_timestamp: TimeTimestampNBO.t; h_details: HashCode.t; } end @@ -1119,8 +1078,8 @@ end module ExchangeAttestPS = struct (* purpose.purpose = TALER_SIGNATURE_EXCHANGE_RESERVE_ATTEST_DETAILS *) type t = { - attest_timestamp: Time.TimestampNBO.t; - expiration_time: Time.TimestampNBO.t; + attest_timestamp: TimeTimestampNBO.t; + expiration_time: TimeTimestampNBO.t; reserve_pub: ReservePublicKeyP.t; h_attributes: HashCode.t; }