ecluse
Safe HaskellNone
LanguageGHC2021

Ecluse.Package

Description

The package domain model — ecosystem-agnostic vocabulary for the rules engine.

These types capture everything the proxy needs to reason about a package version while staying decoupled from any registry's wire format. Registry adapters (npm, PyPI, RubyGems) are responsible for projecting their responses into these types; nothing above the registry layer sees registry-specific structures.

Two pieces of this vocabulary earn their own sibling module: the Ecosystem tag lives in Ecluse.Ecosystem (shared with the version engine and the registry adapters), and version identity and ordering live in Ecluse.Version (a Version is embedded here in PackageDetails). Import those modules directly when you need to name or build their types.

The design follows two principles synthesised from the protocol research (see docs/research/synthesis.md):

  • Rules consume normalised signals, not raw fields. The risky behaviours differ on the wire (npm install scripts, PyPI sdist builds, RubyGems native extensions) but collapse to one signal — CodeExecSignal. Trust likewise collapses to Trust. A rule never learns which ecosystem it is looking at.
  • Signal availability is explicit. A signal the adapter has not (or cannot cheaply) determine is CodeExecUnknown / TrustUnknown / Nothing, so a pure rule abstains rather than guessing and the effectful tier can resolve it later (see docs/architecture.md → "Rules Engine").
Synopsis

Scopes

data Scope Source #

An npm scope, stored without its leading '@' (the scope of @myorg/pkg is "myorg"). Construct via mkScope, which normalises away a leading '@' so equality is independent of how the scope was written.

Instances

Instances details
Show Scope Source # 
Instance details

Defined in Ecluse.Package

Methods

showsPrec :: Int -> Scope -> ShowS #

show :: Scope -> String #

showList :: [Scope] -> ShowS #

Eq Scope Source # 
Instance details

Defined in Ecluse.Package

Methods

(==) :: Scope -> Scope -> Bool #

(/=) :: Scope -> Scope -> Bool #

Ord Scope Source # 
Instance details

Defined in Ecluse.Package

Methods

compare :: Scope -> Scope -> Ordering #

(<) :: Scope -> Scope -> Bool #

(<=) :: Scope -> Scope -> Bool #

(>) :: Scope -> Scope -> Bool #

(>=) :: Scope -> Scope -> Bool #

max :: Scope -> Scope -> Scope #

min :: Scope -> Scope -> Scope #

mkScope :: Text -> Scope Source #

Build a Scope, tolerating an optional leading '@'.

unScope :: Scope -> Text Source #

The bare scope text, without the leading '@'.

renderScope :: Scope -> Text Source #

Render a scope in npm wire form, with the leading '@'.

Package identity

data PackageName Source #

A package identity, decoupled from any registry's wire format.

Identity differs by ecosystem — npm has scopes and is case-sensitive, PyPI normalises per PEP 503, RubyGems is verbatim — so the type is opaque: build it with mkPackageName, which records the ecosystem, computes a pkgCanonical key used for equality/matching, and keeps a pkgDisplay form for faithful rendering. Equality and ordering are on (pkgEcosystem, pkgNamespace, pkgCanonical) only — never the display form — so Flask and flask are the same PyPI package but different npm ones.

mkPackageName :: Ecosystem -> Maybe Scope -> Text -> PackageName Source #

Build a PackageName, normalising the canonical key for the ecosystem.

The display form is the scope-joined raw name (@scope/name when scoped); the canonical key is that form normalised: PEP 503 lower-casing and [-_.]+- collapsing for PyPI, verbatim for npm and RubyGems.

pkgEcosystem :: PackageName -> Ecosystem Source #

The ecosystem this name belongs to.

pkgNamespace :: PackageName -> Maybe Scope Source #

The scope, if scoped (npm @scope/name). Nothing for PyPI/RubyGems.

pkgCanonical :: PackageName -> Text Source #

The normalised key for equality and matching (PEP 503 for PyPI; verbatim for npm/RubyGems).

pkgDisplay :: PackageName -> Text Source #

The name as published, for rendering and round-tripping.

renderPackageName :: PackageName -> Text Source #

Render a package name in its native wire form (the display name).

Normalised signals

data CodeExecSignal Source #

Whether installing a version executes code (the cross-ecosystem unification of npm install scripts, PyPI sdist builds, and RubyGems native extensions).

Constructors

NoCodeOnInstall

Determined: installation runs no code.

RunsCodeOnInstall Text

Determined: installation runs code; the text says how (audit trail).

CodeExecUnknown

Not yet determined (e.g. the RubyGems gemspec has not been fetched). Pure rules abstain; the effectful tier may resolve it.

Instances

Instances details
Show CodeExecSignal Source # 
Instance details

Defined in Ecluse.Package

Eq CodeExecSignal Source # 
Instance details

Defined in Ecluse.Package

data Trust Source #

The trust/provenance signal for a version. The how of trust differs by ecosystem (npm dist.signatures, PyPI PEP 740 attestations, RubyGems signed gems/MFA) but is captured as TrustEvidence so rules stay ecosystem-blind.

Constructors

Trusted (NonEmpty TrustEvidence)

Determined trusted, with the evidence supporting it.

Untrusted

Determined: no trust signal established.

TrustUnknown

Not yet determined (e.g. signature verification needs a fetch).

Instances

Instances details
Show Trust Source # 
Instance details

Defined in Ecluse.Package

Methods

showsPrec :: Int -> Trust -> ShowS #

show :: Trust -> String #

showList :: [Trust] -> ShowS #

Eq Trust Source # 
Instance details

Defined in Ecluse.Package

Methods

(==) :: Trust -> Trust -> Bool #

(/=) :: Trust -> Trust -> Bool #

data TrustEvidence Source #

A normalised reason a version is trusted; the adapter maps its ecosystem's mechanism onto this vocabulary.

Constructors

Signed

The artifact is cryptographically signed.

Attested

The artifact carries a provenance attestation (e.g. Sigstore).

MfaPublished

The version was published under enforced multi-factor auth.

OtherEvidence Text

An ecosystem mechanism not yet in this vocabulary (escape hatch).

Instances

Instances details
Show TrustEvidence Source # 
Instance details

Defined in Ecluse.Package

Eq TrustEvidence Source # 
Instance details

Defined in Ecluse.Package

data Availability Source #

Whether a version is offered, advisory-deprecated, or withdrawn.

Constructors

Available

Offered normally.

Deprecated Text

Advisory deprecation (npm); still resolvable. Carries the message.

Yanked (Maybe Text)

Withdrawn from resolution (PyPI yank keeps the file; RubyGems yank removes it). Carries the reason, if given.

Instances

Instances details
Show Availability Source # 
Instance details

Defined in Ecluse.Package

Eq Availability Source # 
Instance details

Defined in Ecluse.Package

Artifacts

data Artifact Source #

One distribution file for a version. A version owns a NonEmpty list of these: npm has exactly one, PyPI has an sdist plus many wheels, RubyGems has one per platform.

Constructors

Artifact 

Fields

Instances

Instances details
Show Artifact Source # 
Instance details

Defined in Ecluse.Package

Eq Artifact Source # 
Instance details

Defined in Ecluse.Package

data ArtifactKind Source #

What kind of distribution file an artifact is.

Constructors

Tarball

An npm tarball.

Sdist

A PyPI source distribution (building it may execute code).

Wheel Text

A PyPI wheel; carries its compatibility tag (e.g. "cp310-…").

Gem Text

A RubyGems gem; carries its platform ("ruby" = pure).

Instances

Instances details
Show ArtifactKind Source # 
Instance details

Defined in Ecluse.Package

Eq ArtifactKind Source # 
Instance details

Defined in Ecluse.Package

data Hash Source #

An integrity digest of an artifact. Opaque: a Hash is built only through mkHash, which validates that the digest is well-formed, so every value of this type carries the proof that its digest could be a real digest of its algorithm. Read it back through hashAlg and hashValue.

Instances

Instances details
Show Hash Source # 
Instance details

Defined in Ecluse.Package

Methods

showsPrec :: Int -> Hash -> ShowS #

show :: Hash -> String #

showList :: [Hash] -> ShowS #

Eq Hash Source # 
Instance details

Defined in Ecluse.Package

Methods

(==) :: Hash -> Hash -> Bool #

(/=) :: Hash -> Hash -> Bool #

hashAlg :: Hash -> HashAlg Source #

The algorithm the digest was computed with.

hashValue :: Hash -> Text Source #

The digest itself, in the algorithm's wire encoding (e.g. hex, or the whole sha512-… string for SRI).

mkHash :: HashAlg -> Text -> Either Text Hash Source #

Build a Hash, validating that the digest is structurally well-formed: cleanly encoded and exactly the byte length its algorithm specifies. This is the only way to construct a Hash, so the type itself is the proof that the digest could be a real digest of that algorithm — an empty, truncated, over-long, non-hex, or bad-base64 value is unconstructable and so can never reach an integrity gate as a degenerate digest (the fail-open this closes is docs/architecture/security.md invariant 5).

Well-formedness is not admissibility: a well-formed but weak SHA-1 digest builds fine; whether it clears the public-integrity floor is the separate decision of Ecluse.Package.Integrity. mkHash rejects a malformed digest, never a merely weak one.

A hex-tagged algorithm (everything but SRI) takes lower- or upper-case hex of the algorithm's digest length. An SRI takes one or more whitespace-separated <alg>-<base64> components, each naming a Subresource-Integrity algorithm (sha256, sha384, sha512) whose base64 body decodes to that algorithm's digest length; every component must be well-formed.

>>> import Ecluse.Package (HashAlg (SHA1))
>>> fmap hashAlg (mkHash SHA1 "0a4d55a8d778e5022fab701977c5d840bbc486d0")
Right SHA1
>>> mkHash SHA1 "deadbeef"
Left "malformed sha1 digest"

data HashAlg Source #

A hash algorithm an integrity digest is computed with.

Constructors

SHA1 
SHA256 
SHA384 
SHA512 
MD5 
Blake2b 
SRI

A Subresource-Integrity string (npm dist.integrity), e.g. "sha512-…", carried whole.

Instances

Instances details
Show HashAlg Source # 
Instance details

Defined in Ecluse.Package

Eq HashAlg Source # 
Instance details

Defined in Ecluse.Package

Methods

(==) :: HashAlg -> HashAlg -> Bool #

(/=) :: HashAlg -> HashAlg -> Bool #

Ord HashAlg Source # 
Instance details

Defined in Ecluse.Package

Algorithm vocabulary

renderHashAlg :: HashAlg -> Text Source #

The lower-case wire name of an algorithm — the canonical spelling parseHashAlg reads back. Total and injective, so it doubles as config rendering and error text.

>>> renderHashAlg SHA256
"sha256"

parseHashAlg :: Text -> Either Text HashAlg Source #

Parse an algorithm name, tolerating case and an optional internal '-' (so "SHA-256" and "sha256" both parse). An unrecognised name is reported as such, distinct from a recognised-but-too-weak floor. This admits only the named hash algorithms; the sri wrapper is not a config-selectable algorithm and is rejected.

>>> parseHashAlg "SHA-256"
Right SHA256
>>> parseHashAlg "frobnicate"
Left "unknown integrity algorithm: frobnicate"

sriPrefix :: Text -> Text Source #

The algorithm-name token of a Subresource-Integrity string — the <alg> before the first '-' in <alg>-<base64>. A string with no '-' is all prefix.

>>> sriPrefix "sha512-Zm9vYmFy"
"sha512"

sriBody :: Text -> Text Source #

The base64 digest body of a Subresource-Integrity string — the <base64> after the first '-' in <alg>-<base64>. A string with no '-' has an empty body.

>>> sriBody "sha512-Zm9vYmFy"
"Zm9vYmFy"

sriAlgorithm :: Text -> Maybe HashAlg Source #

The HashAlg a Subresource-Integrity string names, read from its <alg> prefix. The prefixes resolved are the Subresource-Integrity set sha256, sha384 and sha512 (every long digest the model represents and a registry serves); an unrecognised or malformed prefix yields Nothing, so the string asserts no algorithm and clears no floor (the fail-closed reading).

>>> sriAlgorithm "sha512-Zm9vYmFy"
Just SHA512
>>> sriAlgorithm "sha384-Zm9vYmFy"
Just SHA384

Dependencies

data Dependency Source #

A declared dependency. The constraint is kept as raw text (semver range / PEP 508 / Gem::Requirement) — lossless and ecosystem-agnostic — and is parsed only if a rule ever needs to compare it.

Constructors

Dependency 

Fields

Instances

Instances details
Show Dependency Source # 
Instance details

Defined in Ecluse.Package

Eq Dependency Source # 
Instance details

Defined in Ecluse.Package

data DepKind Source #

The role a dependency plays.

Constructors

Runtime 
Dev 
Optional 
Peer 

Instances

Instances details
Show DepKind Source # 
Instance details

Defined in Ecluse.Package

Eq DepKind Source # 
Instance details

Defined in Ecluse.Package

Methods

(==) :: DepKind -> DepKind -> Bool #

(/=) :: DepKind -> DepKind -> Bool #

People

data Person Source #

A person associated with a package (author, maintainer, or publisher).

Constructors

Person 

Fields

Instances

Instances details
Show Person Source # 
Instance details

Defined in Ecluse.Package

Eq Person Source # 
Instance details

Defined in Ecluse.Package

Methods

(==) :: Person -> Person -> Bool #

(/=) :: Person -> Person -> Bool #

Ord Person Source # 
Instance details

Defined in Ecluse.Package

Per-version details

data PackageDetails Source #

The ecosystem-agnostic snapshot of a single package version that the rules engine evaluates. A registry adapter projects its wire format into this; the rules engine never sees anything else, and never branches on the ecosystem.

Constructors

PackageDetails 

Fields

Instances

Instances details
Show PackageDetails Source # 
Instance details

Defined in Ecluse.Package

Eq PackageDetails Source # 
Instance details

Defined in Ecluse.Package

Packument-level view

data PackageInfo Source #

The packument-level view of a package: the whole-package metadata document (PackageDetails is the per-version snapshot embedded within it). A registry adapter projects a registry's packument (the npm full-metadata document) into this; the proxy core reasons over it without ever seeing the wire format.

Constructors

PackageInfo 

Fields

Instances

Instances details
Show PackageInfo Source # 
Instance details

Defined in Ecluse.Package

Eq PackageInfo Source # 
Instance details

Defined in Ecluse.Package