moon_webhook_guard

    MoonBit Webhook signature verification, replay protection, idempotency, and event routing toolkit.

    webhook
    signature
    security
    idempotency
    moonbit
    Download zip
    Author
    Version
    0.2.0
    License
    MIT
    Last updated
    2 months ago
    Downloads
    30

    #moon_webhook_guard

    moon_webhook_guard is a MoonBit toolkit for building safer Webhook receivers. It focuses on the receiving side: canonical payloads, signature verification, timestamp windows, nonce replay checks, idempotency keys, event routing, provider profiles, diagnostics, fixtures, and test helpers.

    #Why This Project

    MoonBit already has cryptographic and HTTP-related building blocks, but Webhook receivers still need a reusable security workflow. This project does not try to replace crypto libraries or web servers. It wraps the Webhook verification process into a MoonBit-native package that can be embedded by services, CLI tools, workers, and demos.

    #Features

    • Request, header, provider, event, verification policy, and diagnostic models.
    • Canonical string builders for raw body, timestamp, provider, event type, and id.
    • HMAC-SHA256 verification backed by moonbitlang/x/crypto.
    • Timestamp tolerance, nonce replay protection, idempotency, and duplicate event checks.
    • Event router with provider, event type, path, and method matching.
    • GitHub raw-body HMAC, Stripe timestamped HMAC, Feishu callback digest, and generic HMAC profiles.
    • Structured JSON parsing, nested metadata extraction, schema validation, and provider cookbooks.
    • Fixture builders, batch verification, reports, risk scoring, audit logs, and Markdown/CSV export.
    • Response planning, endpoint documentation generation, admission decisions, and debug snapshots.
    • Runnable example in cmd/main and MoonBit regression tests.

    #Quick Start

    moon check moon test moon run cmd/main

    let request = example_github_request()
    let output = run_guard_pipeline(request, GuardConfig::default())
    println(pipeline_output_text(output))

    #Scope

    The security path uses SHA-256 and HMAC-SHA256 primitives from the official moonbitlang/x/crypto package. GitHub signatures cover the unmodified raw body; Stripe signatures cover timestamp.raw_body and support multiple v1 values during secret rotation. Secrets must be supplied by the host application and must not be committed to source control.

    The MVP intentionally focuses on reusable Webhook receiver workflow rather than being an HTTP server, a general HMAC package, or a rate limiter. It covers the guard layer that sits between an HTTP framework and application handlers.

    Current MVP status:

    • 4,000+ lines of effective MoonBit source.
    • 74 regression tests covering official HMAC vectors, signature tampering, provider metadata, structured JSON, replay protection, routing, provider profiles, reports, risk scoring, payload validation, audit logs, receiver workflow, and generated integration docs.
    • No mechanically generated repeated sample set is used to inflate size.

    #MVP Modules

    • model.mbt, canonical.mbt, signing.mbt, signature_header.mbt: request model, provider profile, canonical payload, HMAC-SHA256, signature parsing, and timing-resistant comparison.
    • verifier.mbt, store.mbt: signature verification, timestamp window, replay store, idempotency store, and batch verification.
    • router.mbt, pipeline.mbt, plan.mbt, response.mbt: event routing, stateful guard pipeline, handler action plan, and response mapping.
    • providers.mbt, provider_adapter.mbt, parser.mbt, payload.mbt, schema.mbt: provider normalization, Stripe signature parsing, structured JSON navigation, and event schema validation.
    • risk.mbt, quality.mbt, audit.mbt, errors.mbt, debug.mbt: risk scoring, config quality checks, audit chain, remediation text, and debug snapshots.
    • reports.mbt, manifest.mbt, endpoint.mbt, cookbook.mbt, testkit.mbt: reports, manifest, endpoint docs, provider cookbook, and scenario tests.
    • receiver.mbt, integration.mbt: end-to-end receiver workflow and generated integration guide.

    #License

    MIT License.

    See THIRD_PARTY.md for dependency provenance and SECURITY.md for the supported security boundary.

    ActionKind

    pub(all) enum ActionKind {
    Acknowledge
    Reject
    Ignore
    Dispatch
    RetryLater
    } derive(Eq,
    Debug
    )

    AdmissionCounter

    pub struct AdmissionCounter {
    provider : String
    window_start : Int
    count : Int
    } derive(Eq,
    Debug
    )

    AdmissionCounter::new

    fn AdmissionCounter::new(provider : String, window_start : Int, count : Int) -> AdmissionCounter

    AdmissionDecision

    pub struct AdmissionDecision {
    allowed : Bool
    reason : String
    state : AdmissionState
    } derive(Eq,
    Debug
    )

    AdmissionDecision::new

    fn AdmissionDecision::new(allowed : Bool, reason : String, state : AdmissionState) -> AdmissionDecision

    AdmissionRule

    pub struct AdmissionRule {
    provider : String
    max_events_per_window : Int
    window_seconds : Int
    } derive(Eq,
    Debug
    )

    AdmissionRule::new

    fn AdmissionRule::new(provider : String, max_events_per_window : Int, window_seconds : Int) -> AdmissionRule

    AdmissionState

    pub struct AdmissionState {
    counters : Array[AdmissionCounter]
    } derive(Eq,
    Debug
    )

    AdmissionState::empty

    AuditRecord

    pub struct AuditRecord {
    sequence : Int
    event_id : String
    provider : String
    status : String
    risk_level : String
    route_handler : String
    digest : String
    } derive(Eq,
    Debug
    )

    AuditRecord::new

    fn AuditRecord::new(sequence : Int, event_id : String, provider : String, status : String, risk_level : String, route_handler : String, digest : String) -> AuditRecord

    BatchReport

    pub struct BatchReport {
    results : Array[VerificationResult]
    } derive(Eq,
    Debug
    )

    BatchReport::acceptance_rate

    fn BatchReport::acceptance_rate(self : BatchReport) -> Double

    BatchReport::accepted

    fn BatchReport::accepted(self : BatchReport) -> Int

    BatchReport::new

    BatchReport::rejected

    fn BatchReport::rejected(self : BatchReport) -> Int

    BatchReport::total

    fn BatchReport::total(self : BatchReport) -> Int

    DebugSnapshot

    pub struct DebugSnapshot {
    canonical : String
    expected_signature : String
    actual_signature : String
    masked_secret : String
    headers : String
    } derive(Eq,
    Debug
    )

    DebugSnapshot::new

    fn DebugSnapshot::new(canonical : String, expected_signature : String, actual_signature : String, masked_secret : String, headers : String) -> DebugSnapshot

    DiagnosticCode

    pub(all) enum DiagnosticCode {
    MissingSignature
    SignatureMismatch
    MissingTimestamp
    TimestampOutsideWindow
    MissingEventId
    ReplayDetected
    DuplicateIdempotencyKey
    UnknownEvent
    ProviderMismatch
    AcceptedDiagnostic
    } derive(Eq,
    Debug
    )

    DispatchOutcome

    pub struct DispatchOutcome {
    verification : VerificationResult
    route : RouteDecision
    } derive(Eq,
    Debug
    )

    DuplicateGroup

    pub struct DuplicateGroup {
    event_id : String
    count : Int
    } derive(Eq,
    Debug
    )

    DuplicateGroup::new

    fn DuplicateGroup::new(event_id : String, count : Int) -> DuplicateGroup

    EndpointSpec

    pub struct EndpointSpec {
    provider : String
    path : String
    http_method : HttpMethod
    headers : Array[String]
    events : Array[String]
    } derive(Eq,
    Debug
    )

    EndpointSpec::new

    fn EndpointSpec::new(provider : String, path : String, http_method : HttpMethod, headers : Array[String], events : Array[String]) -> EndpointSpec

    ErrorCategory

    pub(all) enum ErrorCategory {
    Authentication
    Freshness
    Identity
    Routing
    ProviderConfig
    Replay
    UnknownCategory
    } derive(Eq,
    Debug
    )

    EventRouter

    pub struct EventRouter {
    rules : Array[RouteRule]
    } derive(Eq,
    Debug
    )

    EventRouter::add

    fn EventRouter::add(self : EventRouter, rule : RouteRule) -> EventRouter

    EventRouter::empty

    fn EventRouter::empty() -> EventRouter

    EventRouter::enabled_count

    fn EventRouter::enabled_count(self : EventRouter) -> Int

    EventRouter::handlers

    fn EventRouter::handlers(self : EventRouter) -> Array[String]

    EventRouter::route

    fn EventRouter::route(self : EventRouter, request : WebhookRequest, profile : ProviderProfile) -> RouteDecision

    GateStatus

    pub(all) enum GateStatus {
    Pass
    Warn
    Fail
    } derive(Eq,
    Debug
    )

    GuardConfig

    pub struct GuardConfig {
    policy : VerificationPolicy
    router : EventRouter
    state : GuardState
    } derive(Eq,
    Debug
    )

    GuardConfig::default

    fn GuardConfig::default() -> GuardConfig

    GuardConfig::for_provider

    fn GuardConfig::for_provider(provider_name : String, secret : String, now : Int) -> GuardConfig

    GuardConfig::new

    fn GuardConfig::new(policy : VerificationPolicy, router : EventRouter, state? : GuardState) -> GuardConfig

    GuardConfig::with_policy

    fn GuardConfig::with_policy(self : GuardConfig, policy : VerificationPolicy) -> GuardConfig

    GuardConfig::with_router

    fn GuardConfig::with_router(self : GuardConfig, router : EventRouter) -> GuardConfig

    GuardConfig::with_state

    fn GuardConfig::with_state(self : GuardConfig, state : GuardState) -> GuardConfig

    GuardDiagnostic

    pub struct GuardDiagnostic {
    code : DiagnosticCode
    message : String
    } derive(Eq,
    Debug
    )

    GuardDiagnostic::new

    fn GuardDiagnostic::new(code : DiagnosticCode, message : String) -> GuardDiagnostic

    GuardManifest

    pub struct GuardManifest {
    name : String
    version : String
    providers : Array[String]
    routes : Int
    checks : Array[String]
    } derive(Eq,
    Debug
    )

    GuardManifest::new

    fn GuardManifest::new(name : String, version : String, providers : Array[String], routes : Int, checks : Array[String]) -> GuardManifest

    GuardPipelineOutput

    pub struct GuardPipelineOutput {
    verification : VerificationResult
    route : RouteDecision
    risk : RiskScore
    state : GuardState
    } derive(Eq,
    Debug
    )

    GuardQualityReport

    pub struct GuardQualityReport {
    gates : Array[QualityGate]
    } derive(Eq,
    Debug
    )

    GuardQualityReport::fail_count

    fn GuardQualityReport::fail_count(self : GuardQualityReport) -> Int

    GuardQualityReport::is_ready

    fn GuardQualityReport::is_ready(self : GuardQualityReport) -> Bool

    GuardQualityReport::pass_count

    fn GuardQualityReport::pass_count(self : GuardQualityReport) -> Int

    GuardState

    pub struct GuardState {
    replay_store : ReplayStore
    idempotency_store : IdempotencyStore
    } derive(Eq,
    Debug
    )

    GuardState::empty

    fn GuardState::empty() -> GuardState

    GuardState::remember

    fn GuardState::remember(self : GuardState, request : WebhookRequest, policy : VerificationPolicy) -> GuardState

    HandlerAction

    pub struct HandlerAction {
    kind : ActionKind
    handler : String
    reason : String
    } derive(Eq,
    Debug
    )

    HandlerAction::new

    fn HandlerAction::new(kind : ActionKind, handler : String, reason : String) -> HandlerAction

    HandlingPlan

    pub struct HandlingPlan {
    actions : Array[HandlerAction]
    response : WebhookResponse
    } derive(Eq,
    Debug
    )

    HandlingPlan::new

    fn HandlingPlan::new(actions : Array[HandlerAction], response : WebhookResponse) -> HandlingPlan

    pub struct Header {
    name : String
    value : String
    } derive(Eq,
    Debug
    )

    Header::new

    fn Header::new(name : String, value : String) -> Header

    Header::normalized_name

    fn Header::normalized_name(self : Header) -> String

    HttpMethod

    pub(all) enum HttpMethod {
    Get
    Post
    Put
    Patch
    Delete
    Unknown(String)
    } derive(Eq,
    Debug
    )

    IdempotencyStore

    pub struct IdempotencyStore {
    entries : Array[SeenEntry]
    } derive(Eq,
    Debug
    )

    IdempotencyStore::contains

    fn IdempotencyStore::contains(self : IdempotencyStore, key : String, now : Int) -> Bool

    IdempotencyStore::empty

    IdempotencyStore::remember

    fn IdempotencyStore::remember(self : IdempotencyStore, key : String, now : Int, ttl_seconds : Int) -> IdempotencyStore

    IntegrationGuide

    pub struct IntegrationGuide {
    manifest : String
    endpoints : String
    cookbook : String
    quality : String
    scenarios : String
    } derive(Eq,
    Debug
    )

    IntegrationGuide::new

    fn IntegrationGuide::new(manifest : String, endpoints : String, cookbook : String, quality : String, scenarios : String) -> IntegrationGuide

    PayloadDocument

    pub struct PayloadDocument {
    body : String
    json : Json?
    kind : PayloadKind
    error : String
    } derive(Eq,
    Debug
    )

    PayloadDocument::invalid

    fn PayloadDocument::invalid(body : String, error : String) -> PayloadDocument

    PayloadDocument::valid

    fn PayloadDocument::valid(body : String, json : Json) -> PayloadDocument

    PayloadField

    pub struct PayloadField {
    key : String
    value : String
    } derive(Eq,
    Debug
    )

    PayloadField::new

    fn PayloadField::new(key : String, value : String) -> PayloadField

    PayloadKind

    pub(all) enum PayloadKind {
    ObjectPayload
    ArrayPayload
    ScalarPayload
    InvalidPayload
    } derive(Eq,
    Debug
    )

    PayloadRule

    pub struct PayloadRule {
    key : String
    required : Bool
    expected_value : String
    } derive(Eq,
    Debug
    )

    PayloadRule::new

    fn PayloadRule::new(key : String, required? : Bool, expected_value? : String) -> PayloadRule

    PayloadSchema

    pub struct PayloadSchema {
    name : String
    rules : Array[PayloadRule]
    } derive(Eq,
    Debug
    )

    PayloadSchema::new

    fn PayloadSchema::new(name : String, rules : Array[PayloadRule]) -> PayloadSchema

    PayloadValidationError

    pub struct PayloadValidationError {
    key : String
    message : String
    } derive(Eq,
    Debug
    )

    PayloadValidationError::new

    fn PayloadValidationError::new(key : String, message : String) -> PayloadValidationError

    ProviderCapabilities

    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
    )

    ProviderCapabilities::new

    fn ProviderCapabilities::new(profile : ProviderProfile, supports_timestamp : Bool, supports_event_id : Bool, supports_event_type : Bool, recommended_window_seconds : Int, notes : String) -> ProviderCapabilities

    ProviderProfile

    pub struct ProviderProfile {
    name : String
    signature_header : String
    timestamp_header : String
    event_type_header : String
    event_id_header : String
    signature_prefix : String
    timestamp_tolerance_seconds : Int
    } derive(Eq,
    Debug
    )

    ProviderProfile::feishu

    ProviderProfile::generic

    ProviderProfile::github

    ProviderProfile::new

    fn 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) -> ProviderProfile

    ProviderProfile::stripe

    ProviderRequestMetadata

    pub struct ProviderRequestMetadata {
    provider : String
    event_type : String
    event_id : String
    timestamp : Int
    nonce : String
    signature_present : Bool
    } derive(Eq,
    Debug
    )

    ProviderRequestMetadata::new

    fn ProviderRequestMetadata::new(provider : String, event_type : String, event_id : String, timestamp : Int, nonce : String, signature_present : Bool) -> ProviderRequestMetadata

    QualityGate

    pub struct QualityGate {
    name : String
    status : GateStatus
    detail : String
    } derive(Eq,
    Debug
    )

    QualityGate::new

    fn QualityGate::new(name : String, status : GateStatus, detail : String) -> QualityGate

    ReceiverConfig

    pub struct ReceiverConfig {
    guard_config : GuardConfig
    admission_rule : AdmissionRule
    validate_payload : Bool
    } derive(Eq,
    Debug
    )

    ReceiverConfig::default

    ReceiverOutput

    pub struct ReceiverOutput {
    pipeline : GuardPipelineOutput
    plan : HandlingPlan
    payload_errors : Array[PayloadValidationError]
    admission : AdmissionDecision
    state : ReceiverState
    } derive(Eq,
    Debug
    )

    ReceiverState

    pub struct ReceiverState {
    guard_state : GuardState
    admission_state : AdmissionState
    audit_records : Array[AuditRecord]
    } derive(Eq,
    Debug
    )

    ReceiverState::empty

    ReplayStore

    pub struct ReplayStore {
    entries : Array[SeenEntry]
    } derive(Eq,
    Debug
    )

    ReplayStore::contains

    fn ReplayStore::contains(self : ReplayStore, key : String, now : Int) -> Bool

    ReplayStore::empty

    fn ReplayStore::empty() -> ReplayStore

    ReplayStore::prune

    fn ReplayStore::prune(self : ReplayStore, now : Int) -> ReplayStore

    ReplayStore::remember

    fn ReplayStore::remember(self : ReplayStore, key : String, now : Int, ttl_seconds : Int) -> ReplayStore

    RiskScore

    pub struct RiskScore {
    score : Int
    level : String
    reasons : Array[String]
    } derive(Eq,
    Debug
    )

    RiskScore::new

    fn RiskScore::new(score : Int, reasons : Array[String]) -> RiskScore

    RouteDecision

    pub struct RouteDecision {
    matched : Bool
    rule_name : String
    handler : String
    reason : String
    } derive(Eq,
    Debug
    )

    RouteDecision::matched

    fn RouteDecision::matched(rule : RouteRule) -> RouteDecision

    RouteDecision::miss

    fn RouteDecision::miss(reason : String) -> RouteDecision

    RouteRule

    pub struct RouteRule {
    name : String
    provider : String
    event_type : String
    path : String
    http_method : HttpMethod
    handler : String
    enabled : Bool
    } derive(Eq,
    Debug
    )

    RouteRule::matches

    fn RouteRule::matches(self : RouteRule, request : WebhookRequest, profile : ProviderProfile) -> Bool

    RouteRule::new

    fn RouteRule::new(name : String, provider : String, event_type : String, path : String, http_method : HttpMethod, handler : String, enabled? : Bool) -> RouteRule

    Scenario

    pub struct Scenario {
    name : String
    request : WebhookRequest
    expect_ok : Bool
    expected_route : String
    } derive(Eq,
    Debug
    )

    Scenario::new

    fn Scenario::new(name : String, request : WebhookRequest, expect_ok : Bool, expected_route : String) -> Scenario

    ScenarioResult

    pub struct ScenarioResult {
    name : String
    passed : Bool
    detail : String
    } derive(Eq,
    Debug
    )

    SeenEntry

    pub struct SeenEntry {
    key : String
    expires_at : Int
    } derive(Eq,
    Debug
    )

    SeenEntry::new

    fn SeenEntry::new(key : String, expires_at : Int) -> SeenEntry

    SignatureComponent

    pub struct SignatureComponent {
    key : String
    value : String
    } derive(Eq,
    Debug
    )

    SignatureComponent::new

    fn SignatureComponent::new(key : String, value : String) -> SignatureComponent

    StableSignature

    pub struct StableSignature {
    value : String
    } derive(Eq,
    Debug
    )

    StableSignature::new

    fn StableSignature::new(value : String) -> StableSignature

    StripeSignature

    pub struct StripeSignature {
    timestamp : Int
    timestamp_text : String
    v1_signatures : Array[String]
    legacy_signatures : Array[String]
    unknown_components : Array[SignatureComponent]
    } derive(Eq,
    Debug
    )

    StripeSignature::empty

    StripeSignature::is_well_formed

    fn StripeSignature::is_well_formed(self : StripeSignature) -> Bool

    VerificationPolicy

    pub 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
    )

    VerificationPolicy::default

    VerificationPolicy::for_provider

    fn VerificationPolicy::for_provider(provider : ProviderProfile) -> VerificationPolicy

    VerificationPolicy::with_clock

    fn VerificationPolicy::with_clock(self : VerificationPolicy, now : Int) -> VerificationPolicy

    VerificationPolicy::with_secret

    fn VerificationPolicy::with_secret(self : VerificationPolicy, secret : String) -> VerificationPolicy

    VerificationPolicy::with_unknown_events

    fn VerificationPolicy::with_unknown_events(self : VerificationPolicy, allowed : Bool) -> VerificationPolicy

    VerificationResult

    pub struct VerificationResult {
    status : VerificationStatus
    provider : String
    event_type : String
    event_id : String
    diagnostics : Array[GuardDiagnostic]
    } derive(Eq,
    Debug
    )

    VerificationResult::accepted

    fn VerificationResult::accepted(provider : String, event_type : String, event_id : String) -> VerificationResult

    VerificationResult::is_ok

    fn VerificationResult::is_ok(self : VerificationResult) -> Bool

    VerificationResult::new

    fn VerificationResult::new(status : VerificationStatus, provider : String, event_type : String, event_id : String, diagnostics? : Array[GuardDiagnostic]) -> VerificationResult

    VerificationResult::rejected

    fn VerificationResult::rejected(provider : String, event_type : String, event_id : String, diagnostics : Array[GuardDiagnostic]) -> VerificationResult

    VerificationResult::to_text

    fn VerificationResult::to_text(self : VerificationResult) -> String

    VerificationStatus

    pub(all) enum VerificationStatus {
    Accepted
    Rejected
    Skipped
    } derive(Eq,
    Debug
    )

    WebhookRequest

    pub struct WebhookRequest {
    provider : String
    http_method : HttpMethod
    path : String
    body : String
    headers : Array[Header]
    received_at : Int
    remote_ip : String
    } derive(Eq,
    Debug
    )

    WebhookRequest::event_id

    fn WebhookRequest::event_id(self : WebhookRequest, header_name : String) -> String

    WebhookRequest::event_type

    fn WebhookRequest::event_type(self : WebhookRequest, header_name : String) -> String

    WebhookRequest::header

    fn WebhookRequest::header(self : WebhookRequest, name : String) -> String?

    WebhookRequest::new

    fn WebhookRequest::new(provider : String, http_method : HttpMethod, path : String, body : String, received_at : Int, headers? : Array[Header], remote_ip? : String) -> WebhookRequest

    WebhookRequest::signature

    fn WebhookRequest::signature(self : WebhookRequest, header_name : String) -> String

    WebhookRequest::timestamp

    fn WebhookRequest::timestamp(self : WebhookRequest, header_name : String) -> Int

    WebhookRequest::with_header

    fn WebhookRequest::with_header(self : WebhookRequest, name : String, value : String) -> WebhookRequest

    WebhookRequest::with_replaced_header

    fn WebhookRequest::with_replaced_header(self : WebhookRequest, name : String, value : String) -> WebhookRequest

    WebhookRequest::without_header

    fn WebhookRequest::without_header(self : WebhookRequest, name : String) -> WebhookRequest

    WebhookResponse

    pub struct WebhookResponse {
    status_code : Int
    body : String
    retryable : Bool
    } derive(Eq,
    Debug
    )

    WebhookResponse::new

    fn WebhookResponse::new(status_code : Int, body : String, retryable : Bool) -> WebhookResponse

    abs_int

    fn abs_int(value : Int) -> Int

    accepted_count

    fn accepted_count(results : Array[VerificationResult]) -> Int

    accepted_response

    fn accepted_response() -> WebhookResponse

    admission_rule_for

    fn admission_rule_for(provider : String) -> AdmissionRule

    ascii_lower

    fn ascii_lower(input : String) -> String

    audit_digest

    fn audit_digest(previous : String, output : GuardPipelineOutput) -> String

    audit_log_markdown

    fn audit_log_markdown(records : Array[AuditRecord]) -> String

    audit_record

    fn audit_record(sequence : Int, previous_digest : String, output : GuardPipelineOutput) -> AuditRecord

    bad_signature_request

    fn bad_signature_request() -> WebhookRequest

    bad_signature_scenario

    fn bad_signature_scenario() -> Scenario

    base_github_request

    fn base_github_request(body? : String) -> WebhookRequest

    batch_report_csv

    fn batch_report_csv(report : BatchReport) -> String

    batch_report_markdown

    fn batch_report_markdown(report : BatchReport) -> String

    batch_risk_scores

    fn batch_risk_scores(results : Array[VerificationResult]) -> Array[RiskScore]

    build_audit_log

    fn build_audit_log(outputs : Array[GuardPipelineOutput]) -> Array[AuditRecord]

    build_integration_guide

    fn build_integration_guide(config : GuardConfig) -> IntegrationGuide

    canonical_base

    fn canonical_base(request : WebhookRequest, profile : ProviderProfile) -> String

    canonical_body

    fn canonical_body(request : WebhookRequest) -> String

    canonical_debug_lines

    fn canonical_debug_lines(request : WebhookRequest, profile : ProviderProfile) -> Array[String]

    canonical_debug_text

    fn canonical_debug_text(request : WebhookRequest, profile : ProviderProfile) -> String

    canonical_event

    fn canonical_event(request : WebhookRequest, profile : ProviderProfile) -> String

    canonical_id

    fn canonical_id(request : WebhookRequest, profile : ProviderProfile) -> String

    canonical_timestamp

    fn canonical_timestamp(request : WebhookRequest, profile : ProviderProfile) -> String

    capabilities_catalog

    fn capabilities_catalog() -> Array[ProviderCapabilities]

    capability_for

    fn capability_for(name : String) -> ProviderCapabilities

    categorize

    fn categorize(code : DiagnosticCode) -> ErrorCategory

    category_name

    fn category_name(category : ErrorCategory) -> String

    check_admission

    fn check_admission(provider : String, now : Int, rule : AdmissionRule, state : AdmissionState) -> AdmissionDecision

    clone_with_body

    fn clone_with_body(request : WebhookRequest, body : String) -> WebhookRequest

    clone_with_received_at

    fn clone_with_received_at(request : WebhookRequest, received_at : Int) -> WebhookRequest

    combined_cookbook

    fn combined_cookbook() -> String

    config_summary

    fn config_summary(config : GuardConfig) -> String

    constant_time_equal

    fn constant_time_equal(left : String, right : String) -> Bool

    contains_string

    fn contains_string(items : Array[String], value : String) -> Bool

    cookbook_for

    fn cookbook_for(provider : String) -> String

    debug_snapshot

    fn debug_snapshot(request : WebhookRequest, policy : VerificationPolicy) -> DebugSnapshot

    debug_snapshot_text

    fn debug_snapshot_text(snapshot : DebugSnapshot) -> String

    default_admission_rules

    fn default_admission_rules() -> Array[AdmissionRule]

    default_integration_guide

    fn default_integration_guide() -> String

    default_manifest

    fn default_manifest(config : GuardConfig) -> GuardManifest

    default_router

    fn default_router() -> EventRouter

    describe_provider

    fn describe_provider(provider_name : String) -> String

    diagnostic_name

    fn diagnostic_name(code : DiagnosticCode) -> String

    diagnostic_to_help

    fn diagnostic_to_help(diagnostic : GuardDiagnostic) -> String

    dispatch_request

    fn dispatch_request(request : WebhookRequest, policy : VerificationPolicy, router : EventRouter) -> DispatchOutcome

    dispatch_text

    fn dispatch_text(outcome : DispatchOutcome) -> String

    duplicate_groups

    fn duplicate_groups(results : Array[VerificationResult]) -> Array[DuplicateGroup]

    duplicate_report

    fn duplicate_report(groups : Array[DuplicateGroup]) -> String

    endpoint_catalog_markdown

    fn endpoint_catalog_markdown(router : EventRouter) -> String

    endpoint_for_profile

    fn endpoint_for_profile(profile : ProviderProfile, path : String) -> EndpointSpec

    endpoint_from_router

    fn endpoint_from_router(profile : ProviderProfile, router : EventRouter, path : String) -> EndpointSpec

    endpoint_markdown

    fn endpoint_markdown(spec : EndpointSpec) -> String

    evaluate_guard_config

    fn evaluate_guard_config(policy : VerificationPolicy, router : EventRouter) -> GuardQualityReport

    example_github_request

    fn example_github_request() -> WebhookRequest

    expected_signature

    fn expected_signature(request : WebhookRequest, policy : VerificationPolicy) -> String

    expired_request

    fn expired_request() -> WebhookRequest

    expired_scenario

    fn expired_scenario() -> Scenario

    explain_risk

    fn explain_risk(score : RiskScore) -> String

    explain_verification

    fn explain_verification(request : WebhookRequest, policy : VerificationPolicy) -> String

    feishu_capabilities

    fn feishu_capabilities() -> ProviderCapabilities

    feishu_cookbook

    fn feishu_cookbook() -> String

    feishu_message_scenario

    fn feishu_message_scenario() -> Scenario

    feishu_message_schema

    fn feishu_message_schema() -> PayloadSchema

    feishu_request

    fn feishu_request() -> WebhookRequest

    find_provider

    fn find_provider(name : String) -> ProviderProfile

    first_signature_value

    fn first_signature_value(components : Array[SignatureComponent], key : String) -> String?

    generic_capabilities

    fn generic_capabilities() -> ProviderCapabilities

    github_capabilities

    fn github_capabilities() -> ProviderCapabilities

    github_cookbook

    fn github_cookbook() -> String

    github_issue_schema

    fn github_issue_schema() -> PayloadSchema

    has_category

    fn has_category(result : VerificationResult, category : ErrorCategory) -> Bool

    headers_to_text

    fn headers_to_text(headers : Array[Header]) -> String

    hmac_sha256_hex

    fn hmac_sha256_hex(secret : String, message : String) -> String

    idempotency_key

    fn idempotency_key(request : WebhookRequest, policy : VerificationPolicy) -> String

    ignored_response

    fn ignored_response(reason : String) -> WebhookResponse

    integration_guide_markdown

    fn integration_guide_markdown(guide : IntegrationGuide) -> String

    integration_summary

    fn integration_summary(config : GuardConfig) -> String

    join_lines

    fn join_lines(lines : Array[String]) -> String

    json_path_text

    fn json_path_text(json : Json, path : Array[String]) -> String?

    json_path_value

    fn json_path_value(json : Json, path : Array[String]) -> Json?

    manifest_json_like

    fn manifest_json_like(manifest : GuardManifest) -> String

    manifest_markdown

    fn manifest_markdown(manifest : GuardManifest) -> String

    mask_secret

    fn mask_secret(secret : String) -> String

    max_risk

    fn max_risk(scores : Array[RiskScore]) -> RiskScore

    method_name

    fn method_name(http_method : HttpMethod) -> String

    normalize_provider_request

    fn normalize_provider_request(request : WebhookRequest, provider_name : String) -> WebhookRequest

    package_name

    fn package_name() -> String

    parse_headers

    fn parse_headers(text : String) -> Array[Header]

    parse_method

    fn parse_method(value : String) -> HttpMethod

    parse_payload_document

    fn parse_payload_document(body : String) -> PayloadDocument

    parse_payload_fields

    fn parse_payload_fields(body : String) -> Array[PayloadField]

    parse_positive_int

    fn parse_positive_int(input : String) -> Int

    parse_signature_header

    fn parse_signature_header(input : String) -> Array[SignatureComponent]

    parse_stripe_signature

    fn parse_stripe_signature(input : String) -> StripeSignature

    payload_contains_path

    fn payload_contains_path(body : String, path : Array[String]) -> Bool

    payload_document_summary

    fn payload_document_summary(document : PayloadDocument) -> String

    payload_error_text

    fn payload_error_text(errors : Array[PayloadValidationError]) -> String

    payload_first_path

    fn payload_first_path(body : String, paths : Array[Array[String]]) -> String?

    payload_has_key

    fn payload_has_key(fields : Array[PayloadField], key : String) -> Bool

    payload_is_valid_json

    fn payload_is_valid_json(body : String) -> Bool

    payload_keys

    fn payload_keys(body : String) -> Array[String]

    payload_path_text

    fn payload_path_text(body : String, path : Array[String]) -> String?

    payload_summary

    fn payload_summary(fields : Array[PayloadField]) -> String

    payload_value

    fn payload_value(fields : Array[PayloadField], key : String) -> String?

    pipeline_batch_text

    fn pipeline_batch_text(outputs : Array[GuardPipelineOutput]) -> String

    pipeline_output_text

    fn pipeline_output_text(output : GuardPipelineOutput) -> String

    plan_for_output

    fn plan_for_output(output : GuardPipelineOutput) -> HandlingPlan

    plan_text

    fn plan_text(plan : HandlingPlan) -> String

    plans_for_outputs

    fn plans_for_outputs(outputs : Array[GuardPipelineOutput]) -> Array[HandlingPlan]

    policy_for_provider

    fn policy_for_provider(provider_name : String, secret : String, now : Int) -> VerificationPolicy

    provider_catalog

    fn provider_catalog() -> Array[ProviderProfile]

    provider_event_id

    fn provider_event_id(request : WebhookRequest, profile : ProviderProfile) -> String

    provider_event_type

    fn provider_event_type(request : WebhookRequest, profile : ProviderProfile) -> String

    provider_markdown_table

    fn provider_markdown_table() -> String

    provider_metadata

    fn provider_metadata(request : WebhookRequest, profile : ProviderProfile) -> ProviderRequestMetadata

    provider_metadata_is_complete

    fn provider_metadata_is_complete(metadata : ProviderRequestMetadata, require_timestamp : Bool, require_event_id : Bool) -> Bool

    provider_metadata_text

    fn provider_metadata_text(metadata : ProviderRequestMetadata) -> String

    provider_nonce

    fn provider_nonce(request : WebhookRequest, profile : ProviderProfile) -> String

    provider_signature_algorithm

    fn provider_signature_algorithm(profile : ProviderProfile) -> String

    provider_timestamp

    fn provider_timestamp(request : WebhookRequest, profile : ProviderProfile) -> Int

    provider_timestamp_text

    fn provider_timestamp_text(request : WebhookRequest, profile : ProviderProfile) -> String

    quality_text

    fn quality_text(report : GuardQualityReport) -> String

    raw_request_summary

    fn raw_request_summary(request : WebhookRequest, profile : ProviderProfile) -> String

    receive_batch

    fn receive_batch(requests : Array[WebhookRequest], config : ReceiverConfig) -> Array[ReceiverOutput]

    receive_webhook

    fn receive_webhook(request : WebhookRequest, config : ReceiverConfig, state : ReceiverState) -> ReceiverOutput

    receiver_batch_report

    fn receiver_batch_report(outputs : Array[ReceiverOutput]) -> String

    receiver_output_text

    fn receiver_output_text(output : ReceiverOutput) -> String

    rejected_count

    fn rejected_count(results : Array[VerificationResult]) -> Int

    rejected_response

    fn rejected_response(reason : String) -> WebhookResponse

    remediation

    fn remediation(code : DiagnosticCode) -> String

    replay_key

    fn replay_key(request : WebhookRequest, policy : VerificationPolicy) -> String

    request_from_parts

    fn request_from_parts(provider : String, method_text : String, path : String, body : String, received_at : Int, header_text : String) -> WebhookRequest

    response_for_output

    fn response_for_output(output : GuardPipelineOutput) -> WebhookResponse

    response_text

    fn response_text(response : WebhookResponse) -> String

    result_help

    fn result_help(result : VerificationResult) -> String

    result_to_markdown

    fn result_to_markdown(result : VerificationResult) -> String

    retry_response

    fn retry_response(reason : String) -> WebhookResponse

    risk_table

    fn risk_table(scores : Array[RiskScore]) -> String

    route_demo_events

    fn route_demo_events() -> String

    run_guard_pipeline

    fn run_guard_pipeline(request : WebhookRequest, config : GuardConfig) -> GuardPipelineOutput

    run_scenario

    fn run_scenario(scenario : Scenario, config : GuardConfig) -> ScenarioResult

    run_scenarios

    fn run_scenarios(scenarios : Array[Scenario], config : GuardConfig) -> Array[ScenarioResult]

    run_stateful_batch

    fn run_stateful_batch(requests : Array[WebhookRequest], config : GuardConfig) -> Array[GuardPipelineOutput]

    sample_requests

    fn sample_requests() -> Array[WebhookRequest]

    scenario_pass_count

    fn scenario_pass_count(results : Array[ScenarioResult]) -> Int

    scenario_report

    fn scenario_report(results : Array[ScenarioResult]) -> String

    scenario_suite

    fn scenario_suite() -> Array[Scenario]

    schema_for_event

    fn schema_for_event(provider : String, event_type : String) -> PayloadSchema?

    schema_is_valid

    fn schema_is_valid(schema : PayloadSchema, body : String) -> Bool

    score_result

    fn score_result(result : VerificationResult) -> RiskScore

    sha256_hex

    fn sha256_hex(message : String) -> String

    sign_request

    fn sign_request(request : WebhookRequest, policy : VerificationPolicy) -> WebhookRequest

    signature_values

    fn signature_values(components : Array[SignatureComponent], key : String) -> Array[String]

    signature_without_prefix

    fn signature_without_prefix(signature : String, prefix : String) -> String

    stable_sign

    fn stable_sign(secret : String, canonical : String) -> StableSignature

    Compatibility helper for deterministic audit and idempotency digests.

    starts_with

    fn starts_with(input : String, prefix : String) -> Bool

    strip_prefix

    fn strip_prefix(input : String, prefix : String) -> String

    stripe_capabilities

    fn stripe_capabilities() -> ProviderCapabilities

    stripe_cookbook

    fn stripe_cookbook() -> String

    stripe_request

    fn stripe_request() -> WebhookRequest

    stripe_signature_summary

    fn stripe_signature_summary(signature : StripeSignature) -> String

    summarize_results

    fn summarize_results(results : Array[VerificationResult]) -> String

    trim_ascii

    fn trim_ascii(input : String) -> String

    valid_github_issue_scenario

    fn valid_github_issue_scenario() -> Scenario

    validate_config

    fn validate_config(config : GuardConfig) -> GuardQualityReport

    validate_payload_schema

    fn validate_payload_schema(schema : PayloadSchema, fields : Array[PayloadField]) -> Array[PayloadValidationError]

    validate_request_payload

    fn validate_request_payload(request : WebhookRequest, profile : ProviderProfile) -> Array[PayloadValidationError]

    verify_audit_chain

    fn verify_audit_chain(records : Array[AuditRecord], outputs : Array[GuardPipelineOutput]) -> Bool

    verify_batch

    fn verify_batch(requests : Array[WebhookRequest], policy : VerificationPolicy) -> Array[VerificationResult]

    verify_batch_report

    fn verify_batch_report(requests : Array[WebhookRequest], policy : VerificationPolicy) -> BatchReport

    verify_request

    fn verify_request(request : WebhookRequest, policy : VerificationPolicy) -> VerificationResult

    verify_request_with_state

    fn verify_request_with_state(request : WebhookRequest, policy : VerificationPolicy, state : GuardState) -> (VerificationResult, GuardState)

    verify_signature

    fn verify_signature(request : WebhookRequest, policy : VerificationPolicy) -> Bool

    version

    fn version() -> String