Foundational interfaces for the thesmos ecosystem.
core is a stdlib-first Go module that defines the contract
seams every other thesmos library and framework depends on:
- Clock — abstracts
time.Now,time.Sleep, and timers so libraries remain deterministic under simulation and test. Returns Hybrid Logical Clock instants for distributed callers and a stdlibtime.Timeprojection for the common case. Implementations:clock/hlc(production HLC),clock/fake(virtual time).UTCSourcereturns a UTC reading with a bound on its error, andclock/kernelreads the bound from the Linux kernel. See RFC-0001 and RFC-0036. - Rand — unified randomness seam exposing both
Uint64andRead([]byte). Implementations:rand/pcg(non-crypto PCG),rand/crypto(CSPRNG overcrypto/rand),rand/seeded(HMAC-SHA-256 deterministic CSPRNG),rand/constant(constant for tests). See RFC-0002. - Crypto — cryptographic-hash seam producing comparable
fixed-shape digests covering 256/384/512-bit outputs in one
type, with a stable per-implementation
IDand long-termAlgorithmidentifier so receipts and audit chains survive algorithm rotation.Hashcomputes a content address.HashTaggedandCombineTaggedhash the leaves and interior nodes of a tree or chain under a one-byte role whose high bit gives the arity, so a leaf hash cannot equal a node hash.Streamhashes inputs that do not fit in memory. Implementations:crypto/sha256,crypto/sha512(SHA-384, SHA-512),crypto/sha3(SHA3-256, SHA3-384, SHA3-512). See RFC-0003 and RFC-0029. - HMAC — keyed-authentication peer of the hash seam.
crypto.MACmirrorscrypto.Hasher's shape (sameDigestoutput, sameID+Algorithmmodel, sameStream) with first-class constant-timeVerifyand aDigest.ConstantTimeEqualhelper for streaming verification. Implementations:crypto/hmac/sha256,crypto/hmac/sha512(HMAC-SHA-384, HMAC-SHA-512),crypto/hmac/sha3(HMAC-SHA3-{256,384,512}). See RFC-0012. - Sign — asymmetric-signing seam.
crypto/sign.Signer/Verifiersplit (verifier-only consumers don't construct a signer),KeyIDvalue type with canonical per-algorithm derivation, optionalStreamingSigner/StreamingVerifiercapability interfaces for hash-then-sign algorithms. Implementations:crypto/sign/ed25519(Ed25519 PureEdDSA per RFC 8032 §5.1.6),crypto/sign/ecdsap384(ECDSA P-384 + SHA-384 per FIPS 186-5, ASN.1 DER signatures, also satisfies the streaming interfaces),crypto/sign/mldsa(ML-DSA-44, ML-DSA-65 and ML-DSA-87 per FIPS 204, with the context string fixed per signer).SignContextbounds a signer that crosses a process boundary with a context.Resolverbuilds a verifier from a stored algorithm name out of a table the caller writes, andPolicyrequires valid signatures from k of n parties, counting each key once. See RFC-0013, RFC-0033, RFC-0035 and RFC-0039. - Framer — unambiguous domain separation for hashed and
signed inputs.
Domain(name + version) plus aFramerbuilder that length-prefixes every part, so no two distinct inputs can encode to the same bytes.HashDomainis built on it. See RFC-0016. - AEAD — authenticated-encryption seam.
crypto.AEADembeds stdlibcipher.AEADand adds the sameID+Algorithmidentity model as the hash and signing seams, so a ciphertext at rest records what produced it.Seal/Openhelpers carry the nonce with the ciphertext. Implementation:crypto/aesgcm(AES-128-GCM, AES-256-GCM). See RFC-0017. - Keeper — key-custody seam.
Keeperwraps and unwraps data keys without exposing the root key, with optionalDestroyerandKeyGeneratorcapability interfaces. The shape is the one a KMS or HSM already has, so a consumer swaps custody without touching call sites.Destroyschedules the destruction of a wrapping key and returns the time at which it becomes irreversible. Implementation:crypto/localkey(in-process, for development and tests). See RFC-0018 and RFC-0034. - XOF — extendable-output-function seam.
crypto.XOF/XOFStreamproduce arbitrary-length output for key derivation and deterministic padding, where a fixed-sizeDigestcannot. Implementation:crypto/shake(SHAKE128, SHAKE256). See RFC-0019. - Telemetry — metric and trace seams for hot-path
observability emission, with attribute pre-binding via
.With([]Attr)keeping the emit path zero-allocation while preservingcontext.Contextfor OTel exemplar correlation, baggage, and trace-stitching. Kind-taggedAttrbridges to stdliblog/slog.Propagator/Carriercarry aSpanContextacross a process boundary, withMapCarrierfor the common case. Implementations:telemetry/noop,telemetry/w3c(W3C Trace Contexttraceparent/tracestate). See RFC-0004 and RFC-0020. - Epoch — in-process strictly-monotonic 64-bit counter for
leader generations, schema versions, optimistic-concurrency
tokens.
epoch.Epochvalue type plus thread-safeepoch.Counter.AdmissibleandWatermarkadmit a write whose fence epoch is at or above the scope's watermark, andErrFencedreports revoked authority. See RFC-0005 and RFC-0026. - Tag — snapshot-immutable string key/value pairs used in
place of
map[string]stringon value-type structs that cross async-buffered, cached, or cross-goroutine boundaries. See RFC-0006. - Version — opaque CAS token (
Version),WriteOptionswith IfMatch / IfNoneMatch preconditions, andVersioned[T]for read-your-writes optimistic-concurrency loops. AVersionproves identity, never order. See RFC-0007 and RFC-0026. - Page — pagination request (
PagewithWithDefaulthelper) and response (Cursor[T]) shape withSliceCursor[T]andMapCursor[K, V]generic helpers. Range-over-func iteration makes "forgot to check err" syntactically impossible. See RFC-0008. - ID — fixed-max-size identifier value type (
id.ID) covering 128-, 160-, and 256-bit shapes in one comparable type, with four generator subpackages:id/ulid(128-bit time-sortable Crockford base32),id/uuidv4(128-bit random RFC 4122),id/ksuid(160-bit K-sortable base62 — alphanumeric encoding and 128-bit entropy floor for gov / defense / fintech / health consumers),id/constant(constant for fixtures). Every subpackage shipsFormatandParsefor canonical serialization. See RFC-0009. - Pool — typed
sync.Poolwrappers:Pool[T any]for arbitrary values,ResetPool[T Resettable]that auto-clears state onPut(preventing cross-tenant data leaks at the type level), andNewBufferPoolfor byte buffers, whosepool.Bufferzeroes its whole capacity onReset.Bounded[T]is the fixed-capacity peer for objects that are scarce rather than merely reusable — a connection, a decoder, a hardware handle — where exhaustion must be reported (ErrLimit) rather than allocated around. See RFC-0010 and RFC-0021. - Arena — bump allocator for hot-path variable-length
output.
Append/Allocreturn three-index-capped sub-slices into a contiguous backing buffer; epoch-taggedMarker+SliceSincecapture multi-call regions safely. Pool integration viaReset(satisfiespool.Resettable) keeps the backing buffer warm across requests. See RFC-0011. - Errs — error-classification seam: a closed eight-value
taxonomy of what a caller should do about a failure, not
what went wrong.
Classifywalks an error tree zero-allocation and recognises stdlib sentinels, so a producer that has never heard of the package still classifies usefully;Retryableis the shorthand a retry loop or a circuit breaker asks for. See RFC-0015. - Resilience — the algorithms every caller of a remote
dependency needs:
Breaker(per-target circuit, single-probe half-open, injectable failure judgement for transports where failure is not an error),Bulkhead(concurrency limit with optional queue, rejection / timeout / cancellation kept distinct), andRetrier(attempt count and a sliding-window budget, full-jitterBackoff). All read time throughclock.Clock, so their transitions are exact under a virtual clock. See RFC-0023. - Batch — request coalescing:
Loader[K, V]accumulates concurrent single-key loads into one batched call and deduplicates concurrent loads of the same key. Not a cache — results are not retained past the in-flight window. See RFC-0024. - Fixed —
fixed.Fixed64, a decimal at eight places stored as oneint64.Add,Sub,MulandDivreturn an error on overflow instead of wrapping. The text form renders all eight places and round-trips exactly, and the package has no conversion fromfloat64. See RFC-0025. - CAS — content-addressed storage. A
cas.Storeis bound to one hasher.Putverifies that the data hashes to its address, stores nothing when it does not, and reports exactly one write per address under concurrency.cas.Storehas noDelete. Implementation:cas/memory. See RFC-0027. - Blob — named object storage, streamed in both directions, with
conditional writes through the
versionvocabulary. A failedPutleaves the key as it was, an open reader returns one version of the object, and a listing walked to the end over an unchanging store returns every object once. Implementation:blob/memory. See RFC-0028. - Conformance —
coretest/castestandcoretest/blobtestcheck any store against the rules of its package, across a restart and a crash when the adapter supplies them. Core's tests run each suite against a broken store for every case.cas.AsStreamer,crypto.AsDestroyerand the otherAsfunctions find a capability behind decorators that implementUnwrap, orUnwrapKeeperfor acrypto.Keeper. See RFC-0038. - Task — structured concurrency:
All,Each,Map,StreamandRunreturn only after every goroutine they started has returned. The first error cancels the other tasks and is the result, and a task that panics crashes the process from its own goroutine.Each,MapandStreamrun on a fixed set of workers and do not allocate per element.Everycalls a function repeatedly with a delay and jitter between calls, andQuorumreturns as soon as k of n calls succeed. See RFC-0030 and RFC-0037. - FSM — finite state machines over small integer states and
events. A
Specis a transition table, built once and validated at construction: unreachable states, states that cannot be left and edges that can never be taken are errors.Allowschecks a stored status change before a compare-and-swap, and aMachineruns guards and exit, edge and entry actions for one event at a time. Neither allocates per event. See RFC-0031. - Tlog — the Merkle tree of RFC 9162 over any
crypto.Hasher, stored as the 256-hash tiles of C2SP tlog-tiles. With SHA-256 the bytes match RFC 6962, so C2SP witnesses verify the tree.Builderintegrates batches of leaves with at most 96 KiB of state, andProveInclusionandProveConsistencybuild a proof from one batched read of at most two tiles per level. Hashing, verification and integration into a reusedUpdatedo not allocate. See RFC-0032.
These interfaces — and the others added over time — share three properties:
- Stdlib first. Production code imports the Go standard library, the module itself, and golang.org/x modules that have no module requirements, each listed by name in the dependency guard. The guard fails CI on any other import. Test code may draw on a closed allow-list. Extending either list takes an ADR. (ADR-0015)
- Single module. One
go.mod. Submodules are not needed because there are no heavy deps to isolate. (ADR-0002) - Apache 2.0. Unencumbered for production and downstream redistribution. (ADR-0003)
Pre-1.0. The primitive set is chosen for coherence of the layer model
rather than per-item demand, and lands incrementally. Breaking changes
are possible until v1.0.0; once tagged, the standard Go module
versioning rules apply. (ADR-0005)
go get go.thesmos.sh/coreModule path: go.thesmos.sh/core · Repo: github.com/thesmos-ai/core
- ADRs — accepted architectural decisions
- RFCs — proposals under discussion or accepted as direction
- Contributing — local setup, conventions, PR flow
- Security — vulnerability disclosure policy