@mikeargento/bitgraph 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -40
- package/dist/__tests__/audit-anchors.test.d.ts +2 -0
- package/dist/__tests__/audit-anchors.test.d.ts.map +1 -0
- package/dist/__tests__/audit-anchors.test.js +152 -0
- package/dist/__tests__/audit-anchors.test.js.map +1 -0
- package/dist/__tests__/audit-anomalies.test.d.ts +2 -0
- package/dist/__tests__/audit-anomalies.test.d.ts.map +1 -0
- package/dist/__tests__/audit-anomalies.test.js +663 -0
- package/dist/__tests__/audit-anomalies.test.js.map +1 -0
- package/dist/__tests__/audit-attestation.test.d.ts +2 -0
- package/dist/__tests__/audit-attestation.test.d.ts.map +1 -0
- package/dist/__tests__/audit-attestation.test.js +403 -0
- package/dist/__tests__/audit-attestation.test.js.map +1 -0
- package/dist/__tests__/audit-bench-smoke.test.d.ts +2 -0
- package/dist/__tests__/audit-bench-smoke.test.d.ts.map +1 -0
- package/dist/__tests__/audit-bench-smoke.test.js +87 -0
- package/dist/__tests__/audit-bench-smoke.test.js.map +1 -0
- package/dist/__tests__/audit-boundary.test.d.ts +20 -0
- package/dist/__tests__/audit-boundary.test.d.ts.map +1 -0
- package/dist/__tests__/audit-boundary.test.js +84 -0
- package/dist/__tests__/audit-boundary.test.js.map +1 -0
- package/dist/__tests__/audit-cli.test.d.ts +2 -0
- package/dist/__tests__/audit-cli.test.d.ts.map +1 -0
- package/dist/__tests__/audit-cli.test.js +239 -0
- package/dist/__tests__/audit-cli.test.js.map +1 -0
- package/dist/__tests__/audit-dependencies.test.d.ts +2 -0
- package/dist/__tests__/audit-dependencies.test.d.ts.map +1 -0
- package/dist/__tests__/audit-dependencies.test.js +116 -0
- package/dist/__tests__/audit-dependencies.test.js.map +1 -0
- package/dist/__tests__/audit-fixtures.d.ts +265 -0
- package/dist/__tests__/audit-fixtures.d.ts.map +1 -0
- package/dist/__tests__/audit-fixtures.js +511 -0
- package/dist/__tests__/audit-fixtures.js.map +1 -0
- package/dist/__tests__/audit-ingest.test.d.ts +2 -0
- package/dist/__tests__/audit-ingest.test.d.ts.map +1 -0
- package/dist/__tests__/audit-ingest.test.js +473 -0
- package/dist/__tests__/audit-ingest.test.js.map +1 -0
- package/dist/__tests__/audit-memory-ingest.test.d.ts +12 -0
- package/dist/__tests__/audit-memory-ingest.test.d.ts.map +1 -0
- package/dist/__tests__/audit-memory-ingest.test.js +120 -0
- package/dist/__tests__/audit-memory-ingest.test.js.map +1 -0
- package/dist/__tests__/audit-property.test.d.ts +2 -0
- package/dist/__tests__/audit-property.test.d.ts.map +1 -0
- package/dist/__tests__/audit-property.test.js +771 -0
- package/dist/__tests__/audit-property.test.js.map +1 -0
- package/dist/__tests__/audit-real-fixtures.test.d.ts +2 -0
- package/dist/__tests__/audit-real-fixtures.test.d.ts.map +1 -0
- package/dist/__tests__/audit-real-fixtures.test.js +132 -0
- package/dist/__tests__/audit-real-fixtures.test.js.map +1 -0
- package/dist/__tests__/audit-real-live.test.d.ts +2 -0
- package/dist/__tests__/audit-real-live.test.d.ts.map +1 -0
- package/dist/__tests__/audit-real-live.test.js +107 -0
- package/dist/__tests__/audit-real-live.test.js.map +1 -0
- package/dist/__tests__/audit-reconstruct.test.d.ts +2 -0
- package/dist/__tests__/audit-reconstruct.test.d.ts.map +1 -0
- package/dist/__tests__/audit-reconstruct.test.js +287 -0
- package/dist/__tests__/audit-reconstruct.test.js.map +1 -0
- package/dist/__tests__/audit-report.test.d.ts +2 -0
- package/dist/__tests__/audit-report.test.d.ts.map +1 -0
- package/dist/__tests__/audit-report.test.js +186 -0
- package/dist/__tests__/audit-report.test.js.map +1 -0
- package/dist/__tests__/audit-roundtrip.test.d.ts +2 -0
- package/dist/__tests__/audit-roundtrip.test.d.ts.map +1 -0
- package/dist/__tests__/audit-roundtrip.test.js +368 -0
- package/dist/__tests__/audit-roundtrip.test.js.map +1 -0
- package/dist/__tests__/audit-temporal.test.d.ts +2 -0
- package/dist/__tests__/audit-temporal.test.d.ts.map +1 -0
- package/dist/__tests__/audit-temporal.test.js +364 -0
- package/dist/__tests__/audit-temporal.test.js.map +1 -0
- package/dist/__tests__/audit-tiers.test.d.ts +2 -0
- package/dist/__tests__/audit-tiers.test.d.ts.map +1 -0
- package/dist/__tests__/audit-tiers.test.js +282 -0
- package/dist/__tests__/audit-tiers.test.js.map +1 -0
- package/dist/__tests__/audit-witness-real.test.d.ts +19 -0
- package/dist/__tests__/audit-witness-real.test.d.ts.map +1 -0
- package/dist/__tests__/audit-witness-real.test.js +82 -0
- package/dist/__tests__/audit-witness-real.test.js.map +1 -0
- package/dist/__tests__/audit-witness.test.d.ts +2 -0
- package/dist/__tests__/audit-witness.test.d.ts.map +1 -0
- package/dist/__tests__/audit-witness.test.js +308 -0
- package/dist/__tests__/audit-witness.test.js.map +1 -0
- package/dist/__tests__/chain-hash-anchor.test.d.ts +22 -0
- package/dist/__tests__/chain-hash-anchor.test.d.ts.map +1 -0
- package/dist/__tests__/chain-hash-anchor.test.js +55 -0
- package/dist/__tests__/chain-hash-anchor.test.js.map +1 -0
- package/dist/__tests__/declared-proof-fixture.d.ts +66 -0
- package/dist/__tests__/declared-proof-fixture.d.ts.map +1 -0
- package/dist/__tests__/declared-proof-fixture.js +66 -0
- package/dist/__tests__/declared-proof-fixture.js.map +1 -0
- package/dist/__tests__/fuse-roundtrip.test.d.ts +2 -0
- package/dist/__tests__/fuse-roundtrip.test.d.ts.map +1 -0
- package/dist/__tests__/fuse-roundtrip.test.js +172 -0
- package/dist/__tests__/fuse-roundtrip.test.js.map +1 -0
- package/dist/__tests__/fuse-sdk.test.d.ts +2 -0
- package/dist/__tests__/fuse-sdk.test.d.ts.map +1 -0
- package/dist/__tests__/fuse-sdk.test.js +117 -0
- package/dist/__tests__/fuse-sdk.test.js.map +1 -0
- package/dist/__tests__/fuse-vectors.test.d.ts +2 -0
- package/dist/__tests__/fuse-vectors.test.d.ts.map +1 -0
- package/dist/__tests__/fuse-vectors.test.js +175 -0
- package/dist/__tests__/fuse-vectors.test.js.map +1 -0
- package/dist/__tests__/fuse-verify.test.d.ts +2 -0
- package/dist/__tests__/fuse-verify.test.d.ts.map +1 -0
- package/dist/__tests__/fuse-verify.test.js +250 -0
- package/dist/__tests__/fuse-verify.test.js.map +1 -0
- package/dist/__tests__/mock-proof-fixture.d.ts +15 -0
- package/dist/__tests__/mock-proof-fixture.d.ts.map +1 -0
- package/dist/__tests__/mock-proof-fixture.js +34 -0
- package/dist/__tests__/mock-proof-fixture.js.map +1 -0
- package/dist/__tests__/proof-hash-regression.test.js +4 -43
- package/dist/__tests__/proof-hash-regression.test.js.map +1 -1
- package/dist/__tests__/proof-hash.test.js +3 -21
- package/dist/__tests__/proof-hash.test.js.map +1 -1
- package/dist/__tests__/proof-integrity.test.d.ts +2 -0
- package/dist/__tests__/proof-integrity.test.d.ts.map +1 -0
- package/dist/__tests__/proof-integrity.test.js +426 -0
- package/dist/__tests__/proof-integrity.test.js.map +1 -0
- package/dist/__tests__/realistic-proof-fixture.d.ts +56 -0
- package/dist/__tests__/realistic-proof-fixture.d.ts.map +1 -0
- package/dist/__tests__/realistic-proof-fixture.js +57 -0
- package/dist/__tests__/realistic-proof-fixture.js.map +1 -0
- package/dist/__tests__/verifier.test.js +74 -0
- package/dist/__tests__/verifier.test.js.map +1 -1
- package/dist/fuse-cli.d.ts +3 -0
- package/dist/fuse-cli.d.ts.map +1 -0
- package/dist/fuse-cli.js +210 -0
- package/dist/fuse-cli.js.map +1 -0
- package/dist/fuse.d.ts +75 -0
- package/dist/fuse.d.ts.map +1 -0
- package/dist/fuse.js +273 -0
- package/dist/fuse.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +19 -9
- package/src/__tests__/audit-anchors.test.ts +188 -0
- package/src/__tests__/audit-anomalies.test.ts +815 -0
- package/src/__tests__/audit-attestation.test.ts +529 -0
- package/src/__tests__/audit-bench-smoke.test.ts +108 -0
- package/src/__tests__/audit-boundary.test.ts +96 -0
- package/src/__tests__/audit-cli.test.ts +288 -0
- package/src/__tests__/audit-dependencies.test.ts +141 -0
- package/src/__tests__/audit-fixtures.ts +736 -0
- package/src/__tests__/audit-ingest.test.ts +575 -0
- package/src/__tests__/audit-memory-ingest.test.ts +140 -0
- package/src/__tests__/audit-property.test.ts +892 -0
- package/src/__tests__/audit-real-fixtures.test.ts +153 -0
- package/src/__tests__/audit-real-live.test.ts +128 -0
- package/src/__tests__/audit-reconstruct.test.ts +353 -0
- package/src/__tests__/audit-report.test.ts +222 -0
- package/src/__tests__/audit-roundtrip.test.ts +464 -0
- package/src/__tests__/audit-temporal.test.ts +446 -0
- package/src/__tests__/audit-tiers.test.ts +343 -0
- package/src/__tests__/audit-witness-real.test.ts +92 -0
- package/src/__tests__/audit-witness.test.ts +345 -0
- package/src/__tests__/chain-hash-anchor.test.ts +67 -0
- package/src/__tests__/declared-proof-fixture.ts +65 -0
- package/src/__tests__/fuse-roundtrip.test.ts +174 -0
- package/src/__tests__/fuse-sdk.test.ts +142 -0
- package/src/__tests__/fuse-vectors.test.ts +218 -0
- package/src/__tests__/fuse-verify.test.ts +278 -0
- package/src/__tests__/mock-proof-fixture.ts +36 -0
- package/src/__tests__/proof-hash-regression.test.ts +4 -44
- package/src/__tests__/proof-hash.test.ts +3 -22
- package/src/__tests__/proof-integrity.test.ts +541 -0
- package/src/__tests__/real-fixtures/anchor-after-112762.json +47 -0
- package/src/__tests__/real-fixtures/anchor-with-ethereum-112758.json +47 -0
- package/src/__tests__/real-fixtures/live-proof-0.json +42 -0
- package/src/__tests__/real-fixtures/live-proof-1.json +43 -0
- package/src/__tests__/real-fixtures/live-proof-2.json +43 -0
- package/src/__tests__/real-fixtures/successor-112760.json +38 -0
- package/src/__tests__/real-fixtures/witness-25525146.json +6 -0
- package/src/__tests__/real-fixtures/witness-25525147.json +6 -0
- package/src/__tests__/realistic-proof-fixture.ts +57 -0
- package/src/__tests__/verifier.test.ts +83 -0
- package/src/fuse-cli.ts +187 -0
- package/src/fuse.ts +356 -0
- package/src/index.ts +6 -0
- package/dist/canonical.d.ts +0 -54
- package/dist/canonical.d.ts.map +0 -1
- package/dist/canonical.js +0 -119
- package/dist/canonical.js.map +0 -1
- package/dist/proof-hash.d.ts +0 -9
- package/dist/proof-hash.d.ts.map +0 -1
- package/dist/proof-hash.js +0 -75
- package/dist/proof-hash.js.map +0 -1
- package/dist/types.d.ts +0 -705
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
- package/dist/verifier.d.ts +0 -27
- package/dist/verifier.d.ts.map +0 -1
- package/dist/verifier.js +0 -844
- package/dist/verifier.js.map +0 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ingestEntries() and auditIngest(): the filesystem-free path.
|
|
3
|
+
*
|
|
4
|
+
* A browser cannot call ingestBundle(path); it hands over bytes. This suite
|
|
5
|
+
* pins that the in-memory ingest classifies, hashes, and matches exactly
|
|
6
|
+
* as the directory ingest does over the same files at the same paths, and
|
|
7
|
+
* that auditIngest() over either produces the same audit (less the run
|
|
8
|
+
* stamp and the container label). It also pins AUDIT_VERSION to
|
|
9
|
+
* package.json, since the constant replaced a runtime file read.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { describe, it, before, after } from "node:test";
|
|
13
|
+
import * as assert from "node:assert/strict";
|
|
14
|
+
import { readFile, readdir, rm } from "node:fs/promises";
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import {
|
|
18
|
+
auditIngest,
|
|
19
|
+
auditToolVersion,
|
|
20
|
+
AUDIT_VERSION,
|
|
21
|
+
ingestBundle,
|
|
22
|
+
ingestEntries,
|
|
23
|
+
runAudit,
|
|
24
|
+
streamMatchedArtifacts,
|
|
25
|
+
} from "@mikeargento/bitgraph-audit";
|
|
26
|
+
import type { AuditResult, BundleEntrySource, IngestResult } from "@mikeargento/bitgraph-audit";
|
|
27
|
+
import { makeStandardAuditBundle } from "./audit-fixtures.js";
|
|
28
|
+
|
|
29
|
+
async function walk(root: string, rel = ""): Promise<string[]> {
|
|
30
|
+
const out: string[] = [];
|
|
31
|
+
const dir = rel === "" ? root : join(root, rel);
|
|
32
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
33
|
+
for (const entry of entries) {
|
|
34
|
+
const r = rel === "" ? entry.name : `${rel}/${entry.name}`;
|
|
35
|
+
if (entry.isDirectory()) out.push(...(await walk(root, r)));
|
|
36
|
+
else if (entry.isFile()) out.push(r);
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function entriesOf(root: string): Promise<BundleEntrySource[]> {
|
|
42
|
+
return (await walk(root)).map((p) => ({
|
|
43
|
+
path: p,
|
|
44
|
+
open: () => readFile(join(root, ...p.split("/"))).then((b) => new Uint8Array(b)),
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Everything in an IngestResult that must agree between containers. */
|
|
49
|
+
function comparableIngest(r: IngestResult): unknown {
|
|
50
|
+
const { bundlePath: _p, container: _c, ...rest } = r;
|
|
51
|
+
return JSON.parse(JSON.stringify(rest));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function comparableAudit(a: AuditResult): unknown {
|
|
55
|
+
const { runMetadata: _m, ingest, ...rest } = a;
|
|
56
|
+
return JSON.parse(JSON.stringify({ ingest: comparableIngest(ingest), ...rest }));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
describe("audit: AUDIT_VERSION is a source constant that tracks package.json", () => {
|
|
60
|
+
it("equals the version in packages/audit/package.json", async () => {
|
|
61
|
+
const pkgPath = fileURLToPath(new URL("../../packages/audit/package.json", import.meta.url));
|
|
62
|
+
const pkg = JSON.parse(await readFile(pkgPath, "utf8")) as { version: string };
|
|
63
|
+
assert.equal(AUDIT_VERSION, pkg.version);
|
|
64
|
+
assert.equal(auditToolVersion(), pkg.version);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("audit: ingestEntries mirrors ingestBundle over the same files", () => {
|
|
69
|
+
let dir: string;
|
|
70
|
+
let fromDisk: IngestResult;
|
|
71
|
+
let fromMemory: IngestResult;
|
|
72
|
+
|
|
73
|
+
before(async () => {
|
|
74
|
+
const bundle = await makeStandardAuditBundle();
|
|
75
|
+
dir = bundle.dir;
|
|
76
|
+
fromDisk = await ingestBundle(dir);
|
|
77
|
+
fromMemory = await ingestEntries(await entriesOf(dir));
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
after(async () => {
|
|
81
|
+
if (dir !== undefined) await rm(dir, { recursive: true, force: true });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("labels the container and keeps the label the caller gave", async () => {
|
|
85
|
+
assert.equal(fromMemory.container, "memory");
|
|
86
|
+
assert.equal(fromMemory.bundlePath, "");
|
|
87
|
+
const labeled = await ingestEntries([], { label: "dropped files" });
|
|
88
|
+
assert.equal(labeled.bundlePath, "dropped files");
|
|
89
|
+
assert.equal(labeled.entriesScanned, 0);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("classifies and matches identically: proofs, artifacts, witnesses, findings, counts, contents hash", () => {
|
|
93
|
+
assert.deepEqual(comparableIngest(fromMemory), comparableIngest(fromDisk));
|
|
94
|
+
assert.ok(fromDisk.proofs.length > 0, "the standard bundle has proofs");
|
|
95
|
+
assert.equal(fromMemory.computedContentsHashB64, fromDisk.computedContentsHashB64);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("re-reads matched artifact bytes through the registered sources", async () => {
|
|
99
|
+
const disk: string[] = [];
|
|
100
|
+
for await (const m of streamMatchedArtifacts(fromDisk)) disk.push(`${m.path}:${m.sha256Hex}:${m.bytes.length}`);
|
|
101
|
+
const mem: string[] = [];
|
|
102
|
+
for await (const m of streamMatchedArtifacts(fromMemory)) mem.push(`${m.path}:${m.sha256Hex}:${m.bytes.length}`);
|
|
103
|
+
assert.deepEqual(mem, disk);
|
|
104
|
+
assert.ok(mem.length > 0, "the standard bundle has matched artifacts");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("yields no artifact bytes for a structurally cloned result (sources are keyed by identity), never throws", async () => {
|
|
108
|
+
const clone = JSON.parse(JSON.stringify(fromMemory)) as IngestResult;
|
|
109
|
+
const seen: string[] = [];
|
|
110
|
+
for await (const m of streamMatchedArtifacts(clone)) seen.push(m.path);
|
|
111
|
+
assert.deepEqual(seen, []);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("skips and reports unsafe paths exactly as archive ingest does", async () => {
|
|
115
|
+
const bad = await ingestEntries([
|
|
116
|
+
{ path: "../escape.json", open: () => new Uint8Array([1]) },
|
|
117
|
+
{ path: "/abs.json", open: () => new Uint8Array([2]) },
|
|
118
|
+
{ path: "ok.bin", open: () => new Uint8Array([3]) },
|
|
119
|
+
]);
|
|
120
|
+
assert.equal(bad.counts.skippedUnsafePaths, 2);
|
|
121
|
+
assert.equal(bad.entriesScanned, 3);
|
|
122
|
+
assert.deepEqual(
|
|
123
|
+
bad.findings.map((f) => f.code),
|
|
124
|
+
["unsafe-path", "unsafe-path"]
|
|
125
|
+
);
|
|
126
|
+
assert.equal(bad.artifacts.length, 1);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("auditIngest over either ingest matches runAudit over the directory, less the run stamp", async () => {
|
|
130
|
+
const viaRun = await runAudit(dir);
|
|
131
|
+
const viaMemory = await auditIngest(await ingestEntries(await entriesOf(dir)), { startedAt: "" });
|
|
132
|
+
assert.deepEqual(comparableAudit(viaMemory), comparableAudit(viaRun));
|
|
133
|
+
assert.equal(viaMemory.runMetadata.startedAt, "");
|
|
134
|
+
assert.equal(viaMemory.runMetadata.container, "memory");
|
|
135
|
+
assert.equal(viaRun.runMetadata.toolVersion, AUDIT_VERSION);
|
|
136
|
+
// The full-tier pass ran in memory too: matched artifacts verified with bytes.
|
|
137
|
+
assert.equal(viaMemory.verification.verified, viaRun.verification.verified);
|
|
138
|
+
assert.ok(viaMemory.verification.verified > 0);
|
|
139
|
+
});
|
|
140
|
+
});
|