MoonBit Webhook signature verification, replay protection, idempotency, and event routing toolkit.
moon check
moon test
moon run cmd/mainlet request = example_github_request()
let output = run_guard_pipeline(request, GuardConfig::default())
println(pipeline_output_text(output))pub struct AdmissionDecision {
allowed : Bool
reason : String
state : AdmissionState
} derive(Eq, Debug)fn AdmissionDecision::new(allowed : Bool, reason : String, state : AdmissionState) -> AdmissionDecisionfn AdmissionRule::new(provider : String, max_events_per_window : Int, window_seconds : Int) -> AdmissionRulefn AuditRecord::new(sequence : Int, event_id : String, provider : String, status : String, risk_level : String, route_handler : String, digest : String) -> AuditRecordfn DebugSnapshot::new(canonical : String, expected_signature : String, actual_signature : String, masked_secret : String, headers : String) -> DebugSnapshotpub struct DispatchOutcome {
verification : VerificationResult
route : RouteDecision
} derive(Eq, Debug)pub struct EndpointSpec {
provider : String
path : String
http_method : HttpMethod
headers : Array[String]
events : Array[String]
} derive(Eq, Debug)fn EndpointSpec::new(provider : String, path : String, http_method : HttpMethod, headers : Array[String], events : Array[String]) -> EndpointSpecfn EventRouter::route(self : EventRouter, request : WebhookRequest, profile : ProviderProfile) -> RouteDecisionpub struct GuardConfig {
policy : VerificationPolicy
router : EventRouter
state : GuardState
} derive(Eq, Debug)fn GuardConfig::new(policy : VerificationPolicy, router : EventRouter, state? : GuardState) -> GuardConfigfn GuardManifest::new(name : String, version : String, providers : Array[String], routes : Int, checks : Array[String]) -> GuardManifestpub struct GuardPipelineOutput {
verification : VerificationResult
route : RouteDecision
risk : RiskScore
state : GuardState
} derive(Eq, Debug)pub struct GuardState {
replay_store : ReplayStore
idempotency_store : IdempotencyStore
} derive(Eq, Debug)fn GuardState::remember(self : GuardState, request : WebhookRequest, policy : VerificationPolicy) -> GuardStatepub struct HandlingPlan {
actions : Array[HandlerAction]
response : WebhookResponse
} derive(Eq, Debug)fn IdempotencyStore::remember(self : IdempotencyStore, key : String, now : Int, ttl_seconds : Int) -> IdempotencyStorefn IntegrationGuide::new(manifest : String, endpoints : String, cookbook : String, quality : String, scenarios : String) -> IntegrationGuidepub struct PayloadDocument {
body : String
json : Json?
kind : PayloadKind
error : String
} derive(Eq, Debug)pub struct ProviderCapabilities {
profile : ProviderProfile
supports_timestamp : Bool
supports_event_id : Bool
supports_event_type : Bool
recommended_window_seconds : Int
notes : String
} derive(Eq, Debug)fn ProviderCapabilities::new(profile : ProviderProfile, supports_timestamp : Bool, supports_event_id : Bool, supports_event_type : Bool, recommended_window_seconds : Int, notes : String) -> ProviderCapabilitiesfn ProviderProfile::new(name : String, signature_header : String, timestamp_header : String, event_type_header : String, event_id_header : String, signature_prefix? : String, timestamp_tolerance_seconds? : Int) -> ProviderProfilefn ProviderRequestMetadata::new(provider : String, event_type : String, event_id : String, timestamp : Int, nonce : String, signature_present : Bool) -> ProviderRequestMetadatapub struct ReceiverConfig {
guard_config : GuardConfig
admission_rule : AdmissionRule
validate_payload : Bool
} derive(Eq, Debug)pub struct ReceiverOutput {
pipeline : GuardPipelineOutput
plan : HandlingPlan
payload_errors : Array[PayloadValidationError]
admission : AdmissionDecision
state : ReceiverState
} derive(Eq, Debug)pub struct ReceiverState {
guard_state : GuardState
admission_state : AdmissionState
audit_records : Array[AuditRecord]
} derive(Eq, Debug)fn ReplayStore::remember(self : ReplayStore, key : String, now : Int, ttl_seconds : Int) -> ReplayStorepub struct RouteRule {
name : String
provider : String
event_type : String
path : String
http_method : HttpMethod
handler : String
enabled : Bool
} derive(Eq, Debug)fn RouteRule::matches(self : RouteRule, request : WebhookRequest, profile : ProviderProfile) -> Boolfn RouteRule::new(name : String, provider : String, event_type : String, path : String, http_method : HttpMethod, handler : String, enabled? : Bool) -> RouteRulepub struct Scenario {
name : String
request : WebhookRequest
expect_ok : Bool
expected_route : String
} derive(Eq, Debug)fn Scenario::new(name : String, request : WebhookRequest, expect_ok : Bool, expected_route : String) -> Scenariopub struct VerificationPolicy {
provider : ProviderProfile
secret : String
now : Int
require_signature : Bool
require_timestamp : Bool
require_event_id : Bool
allow_unknown_event : Bool
} derive(Eq, Debug)fn VerificationPolicy::with_secret(self : VerificationPolicy, secret : String) -> VerificationPolicyfn VerificationPolicy::with_unknown_events(self : VerificationPolicy, allowed : Bool) -> VerificationPolicypub struct VerificationResult {
status : VerificationStatus
provider : String
event_type : String
event_id : String
diagnostics : Array[GuardDiagnostic]
} derive(Eq, Debug)fn VerificationResult::accepted(provider : String, event_type : String, event_id : String) -> VerificationResultfn VerificationResult::new(status : VerificationStatus, provider : String, event_type : String, event_id : String, diagnostics? : Array[GuardDiagnostic]) -> VerificationResultfn VerificationResult::rejected(provider : String, event_type : String, event_id : String, diagnostics : Array[GuardDiagnostic]) -> VerificationResultpub struct WebhookRequest {
provider : String
http_method : HttpMethod
path : String
body : String
headers : Array[Header]
received_at : Int
remote_ip : String
} derive(Eq, Debug)fn WebhookRequest::new(provider : String, http_method : HttpMethod, path : String, body : String, received_at : Int, headers? : Array[Header], remote_ip? : String) -> WebhookRequestfn WebhookRequest::with_header(self : WebhookRequest, name : String, value : String) -> WebhookRequestfn WebhookRequest::with_replaced_header(self : WebhookRequest, name : String, value : String) -> WebhookRequestfn audit_record(sequence : Int, previous_digest : String, output : GuardPipelineOutput) -> AuditRecordfn check_admission(provider : String, now : Int, rule : AdmissionRule, state : AdmissionState) -> AdmissionDecisionfn dispatch_request(request : WebhookRequest, policy : VerificationPolicy, router : EventRouter) -> DispatchOutcomefn endpoint_from_router(profile : ProviderProfile, router : EventRouter, path : String) -> EndpointSpecfn provider_metadata(request : WebhookRequest, profile : ProviderProfile) -> ProviderRequestMetadatafn provider_metadata_is_complete(metadata : ProviderRequestMetadata, require_timestamp : Bool, require_event_id : Bool) -> Boolfn receive_batch(requests : Array[WebhookRequest], config : ReceiverConfig) -> Array[ReceiverOutput]fn receive_webhook(request : WebhookRequest, config : ReceiverConfig, state : ReceiverState) -> ReceiverOutputfn request_from_parts(provider : String, method_text : String, path : String, body : String, received_at : Int, header_text : String) -> WebhookRequestfn run_stateful_batch(requests : Array[WebhookRequest], config : GuardConfig) -> Array[GuardPipelineOutput]fn signature_without_prefix(signature : String, prefix : String) -> Stringfn validate_payload_schema(schema : PayloadSchema, fields : Array[PayloadField]) -> Array[PayloadValidationError]fn validate_request_payload(request : WebhookRequest, profile : ProviderProfile) -> Array[PayloadValidationError]fn verify_batch(requests : Array[WebhookRequest], policy : VerificationPolicy) -> Array[VerificationResult]fn verify_batch_report(requests : Array[WebhookRequest], policy : VerificationPolicy) -> BatchReportfn verify_request_with_state(request : WebhookRequest, policy : VerificationPolicy, state : GuardState) -> (VerificationResult, GuardState)Install
Download zipMoonBit Webhook signature verification, replay protection, idempotency, and event routing toolkit.