|
| 1 | +# SPDX-License-Identifier: PMPL-1.0-or-later |
| 2 | +# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> |
| 3 | +""" |
| 4 | + Verisim |
| 5 | +
|
| 6 | +Julia package wrapper for the VeriSim identity-core research prototype. |
| 7 | +
|
| 8 | +Exports the full VCL proof API (prove, parse_vcl), the VerisimCore store |
| 9 | +(enrich!, get_core, Store, Manager), and the tropical geometry types |
| 10 | +(Tropical, TropicalMatrix, TangleGraph). |
| 11 | +
|
| 12 | +# Design note — flat-include scaffold preserved |
| 13 | +The implementation lives in `impl/` as a set of independent modules that |
| 14 | +cross-reference each other via `Main.X` (the "flat-include scaffold" pattern). |
| 15 | +On package load, `__init__` injects each module into `Main` in dependency |
| 16 | +order, preserving all `Main.X` references without modifying any impl file. |
| 17 | +
|
| 18 | +This is intentional for the research prototype phase. A future |
| 19 | +`Verisim v0.2` refactor will move each impl module into `src/` with proper |
| 20 | +relative imports (`using ..Sibling`), removing the `Main` injection. |
| 21 | +See `PLAN.adoc §Phase-6-Package-Refactor`. |
| 22 | +
|
| 23 | +# Usage |
| 24 | +```julia |
| 25 | +using Verisim |
| 26 | +
|
| 27 | +store = Verisim.Store() |
| 28 | +manager = Verisim.Manager() |
| 29 | +id = Verisim.OctadId(fill(0x01, 16)) |
| 30 | +blob = Verisim.SemanticBlob(["http://example.org/Doc"], b"hello") |
| 31 | +
|
| 32 | +Verisim.enrich!(store, id, :semantic, blob, "alice") |
| 33 | +
|
| 34 | +v = Verisim.prove(Verisim.ProofIntegrity(id), store, manager) |
| 35 | +println(v) # VerdictPass(...) |
| 36 | +``` |
| 37 | +""" |
| 38 | +module Verisim |
| 39 | + |
| 40 | +# ----------------------------------------------------------------------- |
| 41 | +# Impl load order — must match the manual include order in test files and |
| 42 | +# examples. Each file defines its own module which __init__ injects into |
| 43 | +# Main so that all existing Main.X cross-references continue to work. |
| 44 | +# ----------------------------------------------------------------------- |
| 45 | + |
| 46 | +const _IMPL = joinpath(@__DIR__, "..", "impl") |
| 47 | + |
| 48 | +const _IMPL_FILES = [ |
| 49 | + joinpath(_IMPL, "Crypto.jl"), |
| 50 | + joinpath(_IMPL, "drift", "Metrics.jl"), |
| 51 | + joinpath(_IMPL, "VerisimCore.jl"), |
| 52 | + joinpath(_IMPL, "peers", "VectorPeer.jl"), |
| 53 | + joinpath(_IMPL, "FederationManager.jl"), |
| 54 | + joinpath(_IMPL, "tropical", "TropicalMatrix.jl"), |
| 55 | + joinpath(_IMPL, "tropical", "TangleGraph.jl"), |
| 56 | + joinpath(_IMPL, "tropical", "TropicalDeterminant.jl"), |
| 57 | + joinpath(_IMPL, "vcl", "Query.jl"), |
| 58 | + joinpath(_IMPL, "vcl", "Prover.jl"), |
| 59 | + joinpath(_IMPL, "vcl", "Parser.jl"), |
| 60 | +] |
| 61 | + |
| 62 | +""" |
| 63 | + __init__() |
| 64 | +
|
| 65 | +Load all impl modules into `Main` in dependency order. Called automatically |
| 66 | +by Julia when `using Verisim` is evaluated. |
| 67 | +""" |
| 68 | +function __init__() |
| 69 | + for f in _IMPL_FILES |
| 70 | + # Base.include(Main, f) loads the file in the Main module context, |
| 71 | + # making each defined module accessible as Main.<ModuleName>. |
| 72 | + Base.include(Main, f) |
| 73 | + end |
| 74 | +end |
| 75 | + |
| 76 | +# ----------------------------------------------------------------------- |
| 77 | +# Public API — thin delegators to the Main-level modules loaded by __init__ |
| 78 | +# ----------------------------------------------------------------------- |
| 79 | +# |
| 80 | +# Struct types cannot be forwarded by reference at precompile time, so we |
| 81 | +# expose factory functions and let users call the Main-level types directly |
| 82 | +# when they need the actual types (e.g. for dispatch / isa checks). |
| 83 | +# All functions are dispatched at call time via Main.<Module> to avoid |
| 84 | +# precompile-time binding issues. |
| 85 | + |
| 86 | +export prove, parse_vcl |
| 87 | +export Store, Manager, OctadId, SemanticBlob |
| 88 | +export enrich!, get_core |
| 89 | +export ProofIntegrity, ProofConsistency, ProofFreshness, ProofConsonance, |
| 90 | + ProofOptimalAssignment |
| 91 | +export VerdictPass, VerdictFail |
| 92 | +export Tropical, TROP_ZERO, TROP_ONE, trop_add, trop_mul, bellman_ford_matrix |
| 93 | + |
| 94 | +# VCL proof evaluation |
| 95 | +prove(args...; kw...) = Main.VCLProver.prove(args...; kw...) |
| 96 | +parse_vcl(s::AbstractString) = Main.VCLParser.parse_vcl(s) |
| 97 | + |
| 98 | +# Store lifecycle |
| 99 | +Store() = Main.VerisimCore.Store() |
| 100 | +Manager() = Main.FederationManager.Manager() |
| 101 | +OctadId(b) = Main.VerisimCore.OctadId(b) |
| 102 | +SemanticBlob(types, bytes) = Main.VerisimCore.SemanticBlob(types, bytes) |
| 103 | +enrich!(args...) = Main.VerisimCore.enrich!(args...) |
| 104 | +get_core(args...) = Main.VerisimCore.get_core(args...) |
| 105 | + |
| 106 | +# VCL clause constructors |
| 107 | +ProofIntegrity(id) = Main.VCLQuery.ProofIntegrity(id) |
| 108 | +ProofConsistency(args...) = Main.VCLQuery.ProofConsistency(args...) |
| 109 | +ProofFreshness(id, window) = Main.VCLQuery.ProofFreshness(id, window) |
| 110 | +ProofConsonance(args...) = Main.VCLQuery.ProofConsonance(args...) |
| 111 | +ProofOptimalAssignment(id, n, b) = Main.VCLQuery.ProofOptimalAssignment(id, n, b) |
| 112 | + |
| 113 | +# Tropical types |
| 114 | +Tropical(x) = Main.TropicalMatrix.Tropical(x) |
| 115 | +TROP_ZERO() = Main.TropicalMatrix.TROP_ZERO |
| 116 | +TROP_ONE() = Main.TropicalMatrix.TROP_ONE |
| 117 | +trop_add(a, b) = Main.TropicalMatrix.trop_add(a, b) |
| 118 | +trop_mul(a, b) = Main.TropicalMatrix.trop_mul(a, b) |
| 119 | +bellman_ford_matrix(A) = Main.TropicalMatrix.bellman_ford_matrix(A) |
| 120 | + |
| 121 | +end # module Verisim |
0 commit comments