import { createEvidence } from "../domain/evidence.js"; import { artifactInventoryResultSchema, type ArtifactNode, type ArtifactOccurrence, } from "../domain/artifactGraph.js"; import { artifactGraphDigest, artifactIdForContent, artifactManifestId, occurrenceIdForLocation, } from "../domain/artifactIdentity.js"; const provider = { id: "rea-artifact-graph", name: "REA safe artifact graph provider", version: "1", } as const; const inventoryExample = ( path: string, format: "apk" | "ipa" | "directory" | "hap", digit: string, ) => { const sha = digit.repeat(64); const artifactId = artifactIdForContent(sha); const rootEntryKind = format === "directory" ? "directory" : "file"; const occurrenceId = occurrenceIdForLocation({ rootArtifactId: artifactId, logicalPath: ".", entryKind: rootEntryKind, }); const nodes: ArtifactNode[] = [ { artifact_id: artifactId, format: format === "directory" ? "directory" : "zip", sha256: sha, size: 1, media_type: null, architecture: null, content_state: "materialized", limitations: [], }, ]; const occurrences: ArtifactOccurrence[] = [ { occurrence_id: occurrenceId, artifact_id: artifactId, parent_occurrence_id: null, logical_path: ".", entry_kind: rootEntryKind, artifact_kind: "resource", artifact_format: format, declared_size: 1, compressed_size: null, executable: false, encrypted: false, hash_status: "verified", source_location: null, limitations: [], }, ]; const graphSha256 = artifactGraphDigest({ nodes, occurrences, edges: [], contradictions: [], }); const result = artifactInventoryResultSchema.parse({ manifest: { manifest_id: artifactManifestId(artifactId, graphSha256), root_artifact_id: artifactId, root_sha256: sha, root_format: format, graph_sha256: graphSha256, node_count: nodes.length, occurrence_count: occurrences.length, edge_count: 0, }, nodes, occurrences, edges: [], provenance: [], integrity_contradictions: [], coverage: { scope: "root", status: "complete" }, limitations: [], }); const evidence = createEvidence( { path, sha256: result.manifest.root_sha256, format }, provider, { operation: "inventory_artifact", parameters: {}, result, confidence: "observed", authority: "shipped-artifact", }, ); return { inventory_evidence: [evidence] }; }; /** Catalog example for Android application inventory projection. */ export const ANDROID_APPLICATION_GRAPH_EXAMPLE = inventoryExample( "Fixture.apk", "apk", "a", ); /** Catalog example for Apple application inventory projection. */ export const APPLE_APPLICATION_GRAPH_EXAMPLE = inventoryExample( "Fixture.ipa", "ipa", "b", ); /** Catalog example for a macOS application bundle inventoried as a directory. */ export const MACOS_APPLICATION_GRAPH_EXAMPLE = inventoryExample( "Fixture.app", "directory", "c", ); /** Catalog example for HarmonyOS application inventory projection. */ export const HARMONY_APPLICATION_GRAPH_EXAMPLE = inventoryExample( "Fixture.hap", "hap", "d", );