@sewdn/registry-artifacts
v1.0.1
Published
Verified artifact reads and portable archives for the Lemonaid toolkit registry
Readme
@sewdn/registry-artifacts
Read and verify toolkit registry artifacts, work with portable gzip tar file maps, and inspect npm packages in Bun or Node.js 20+. The ESM package uses ArtifactRef and the portable path rules from @sewdn/registry-contract.
npm install @sewdn/registry-artifactsimport {
inspectNpmPackage,
readGzipTar,
readVerifiedArtifact,
verifyArtifactBytes,
} from "@sewdn/registry-artifacts";
const archive = await readVerifiedArtifact(releaseRef, new URL("https://owner.example/releases"));
const release = readGzipTar(archive);
const packageBytes = release.get(packageRef.location);
if (!packageBytes) throw new Error("Missing " + packageRef.location);
const pkg = inspectNpmPackage(await verifyArtifactBytes(packageRef, packageBytes));
console.log(pkg.name, pkg.version);Artifact references
resolveArtifactLocation(base, location) returns an absolute local path or a URL. The base denotes a directory, including an HTTP base without a trailing slash. Absolute artifact locations must be HTTP(S) URLs with a portable path. Credentials, query strings, fragments, percent-encoded path segments, and absolute filesystem locations are rejected.
readVerifiedArtifact(ref, base, { maxBytes? }) returns bytes only after SHA-256 verification. Local reads use a canonical base directory and accept real directory components and regular files beneath it. Use a stable directory under the caller's control during reads. HTTP reads require a complete successful response with identity content encoding and a 30-second deadline. Supply the final artifact URL because redirects are rejected. Reads are capped at 64 MiB, with an optional lower per-read limit.
readArtifactBytes(location, base, { maxBytes? }) uses the same bounded reader for mutable metadata at an explicitly trusted location. Parse the document and verify any artifact references it advertises. HTTP transport failures and missing or temporarily unavailable responses produce ArtifactUnavailableError. Rejected redirects, invalid responses and digest failures remain validation errors.
verifyArtifactBytes(ref, bytes) verifies the digest of an already buffered artifact, such as a member of a verified release archive. It returns the supplied bytes after the same 64 MiB bound and digest check.
File maps and npm manifests
readGzipTar(bytes) accepts gzip-compressed POSIX ustar archives, including Bun's ustar prefix fields. It returns a Map<string, Uint8Array> of regular file paths. Directory headers are validated and left out of the map. Links, special entries, PAX and GNU extensions, duplicated or case-colliding paths, file/directory conflicts, and malformed headers or padding are rejected. Bounds are 64 MiB compressed, 128 MiB decompressed, 32 MiB per file, and 20,000 file and directory entries.
writeGzipTar(files) accepts a readonly file map and writes paths in ascending order with zero timestamps and numeric ownership. It uses regular-file mode 0644 and implicit directories. Use a separately packed npm distribution archive for packages that require executable modes. Paths must fit the 100-byte name and 155-byte prefix fields of ustar.
inspectNpmPackage(bytes) checks the package/ archive root, parses package/package.json, and returns the exact package name and version, explicit public export subpaths, ordinary and optional dependencies, peer dependencies, optional peer names, the full manifest, and a file map relative to package/. Legacy manifests without exports return an empty list of explicit subpaths. Export resolution and entry-point checks belong to consumers. Run digest verification before parsing untrusted archive bytes. File maps let downstream consumers apply their own confinement and write preconditions.
From the Kit workspace, run bun run registry:prepare at the root, then bun run typecheck and bun run test from this package. The HTTP tests use a loopback listener.
