@mikeargento/bitgraph 1.2.0 → 1.4.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/dist/__tests__/audit-memory-ingest.test.js +15 -0
- package/dist/__tests__/audit-memory-ingest.test.js.map +1 -1
- package/dist/__tests__/fuse-placement.test.d.ts +2 -0
- package/dist/__tests__/fuse-placement.test.d.ts.map +1 -0
- package/dist/__tests__/fuse-placement.test.js +31 -0
- package/dist/__tests__/fuse-placement.test.js.map +1 -0
- package/dist/__tests__/fuse-set-sdk.test.d.ts +2 -0
- package/dist/__tests__/fuse-set-sdk.test.d.ts.map +1 -0
- package/dist/__tests__/fuse-set-sdk.test.js +513 -0
- package/dist/__tests__/fuse-set-sdk.test.js.map +1 -0
- package/dist/__tests__/fuse-set.test.d.ts +2 -0
- package/dist/__tests__/fuse-set.test.d.ts.map +1 -0
- package/dist/__tests__/fuse-set.test.js +863 -0
- package/dist/__tests__/fuse-set.test.js.map +1 -0
- package/dist/canonical.d.ts +54 -0
- package/dist/canonical.d.ts.map +1 -0
- package/dist/canonical.js +119 -0
- package/dist/canonical.js.map +1 -0
- package/dist/fuse-cli.js +111 -32
- package/dist/fuse-cli.js.map +1 -1
- package/dist/fuse.d.ts +94 -3
- package/dist/fuse.d.ts.map +1 -1
- package/dist/fuse.js +275 -48
- package/dist/fuse.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/proof-hash.d.ts +9 -0
- package/dist/proof-hash.d.ts.map +1 -0
- package/dist/proof-hash.js +75 -0
- package/dist/proof-hash.js.map +1 -0
- package/dist/types.d.ts +705 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/verifier.d.ts +27 -0
- package/dist/verifier.d.ts.map +1 -0
- package/dist/verifier.js +844 -0
- package/dist/verifier.js.map +1 -0
- package/package.json +2 -2
- package/src/__tests__/audit-memory-ingest.test.ts +16 -0
- package/src/__tests__/fuse-placement.test.ts +32 -0
- package/src/__tests__/fuse-set-sdk.test.ts +638 -0
- package/src/__tests__/fuse-set.test.ts +1000 -0
- package/src/fuse-cli.ts +97 -27
- package/src/fuse.ts +356 -46
- package/src/index.ts +4 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Copyright (c) Mike Argento. All rights reserved. See LICENSE.
|
|
2
|
+
/**
|
|
3
|
+
* bitgraph-core proof hash
|
|
4
|
+
*
|
|
5
|
+
* Canonical, deterministic proof hash computation.
|
|
6
|
+
*
|
|
7
|
+
* The proof hash covers the SIGNED BODY — the fields that are
|
|
8
|
+
* cryptographically signed by the enclave. This matches what the
|
|
9
|
+
* Ed25519 signature covers, making the hash verifiable.
|
|
10
|
+
*
|
|
11
|
+
* Signed body fields:
|
|
12
|
+
* - version, artifact, commit
|
|
13
|
+
* - publicKeyB64 (from signer)
|
|
14
|
+
* - enforcement, measurement (from environment)
|
|
15
|
+
* - attribution (if present)
|
|
16
|
+
* - attestationFormat (if attestation present)
|
|
17
|
+
*
|
|
18
|
+
* This hash is used for:
|
|
19
|
+
* - prevB64 chain linking
|
|
20
|
+
* - S3 ledger key generation
|
|
21
|
+
* - Ethereum anchor binding
|
|
22
|
+
* - Proof deduplication and verification
|
|
23
|
+
*
|
|
24
|
+
* Algorithm:
|
|
25
|
+
* 1. Extract signed body fields
|
|
26
|
+
* 2. canonicalize(signedBody) — recursive key sort, compact JSON, UTF-8
|
|
27
|
+
* 3. SHA-256 of canonical bytes
|
|
28
|
+
* 4. Base64-standard encode (RFC 4648 §4)
|
|
29
|
+
*
|
|
30
|
+
* IMPORTANT: All call sites MUST use this function. Do NOT compute
|
|
31
|
+
* proof hashes ad-hoc with JSON.stringify or Object.keys().sort().
|
|
32
|
+
* Non-recursive key sorting diverges on nested objects.
|
|
33
|
+
*/
|
|
34
|
+
import { canonicalize } from "./canonical.js";
|
|
35
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
36
|
+
/**
|
|
37
|
+
* Compute the canonical hash of a BitGraph proof's signed body.
|
|
38
|
+
*
|
|
39
|
+
* @param proof - The full BitGraphProof object (or equivalent Record)
|
|
40
|
+
* @returns Base64-standard encoded SHA-256 hash
|
|
41
|
+
*/
|
|
42
|
+
export function computeProofHash(proof) {
|
|
43
|
+
const p = proof;
|
|
44
|
+
const signer = p.signer;
|
|
45
|
+
const env = p.environment;
|
|
46
|
+
const signedBody = {
|
|
47
|
+
version: p.version,
|
|
48
|
+
artifact: p.artifact,
|
|
49
|
+
commit: p.commit,
|
|
50
|
+
publicKeyB64: signer?.publicKeyB64,
|
|
51
|
+
enforcement: env?.enforcement,
|
|
52
|
+
measurement: env?.measurement,
|
|
53
|
+
};
|
|
54
|
+
// Include attribution if present
|
|
55
|
+
if (p.attribution) {
|
|
56
|
+
signedBody.attribution = p.attribution;
|
|
57
|
+
}
|
|
58
|
+
// Include attestation format if present
|
|
59
|
+
if (env?.attestation) {
|
|
60
|
+
signedBody.attestationFormat = env.attestation.format;
|
|
61
|
+
}
|
|
62
|
+
const bytes = canonicalize(signedBody);
|
|
63
|
+
const hash = sha256(bytes);
|
|
64
|
+
// Base64 encode (works in both Node.js and browser)
|
|
65
|
+
if (typeof Buffer !== "undefined") {
|
|
66
|
+
return Buffer.from(hash).toString("base64");
|
|
67
|
+
}
|
|
68
|
+
// Browser fallback
|
|
69
|
+
let binary = "";
|
|
70
|
+
for (let i = 0; i < hash.length; i++) {
|
|
71
|
+
binary += String.fromCharCode(hash[i]);
|
|
72
|
+
}
|
|
73
|
+
return btoa(binary);
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=proof-hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof-hash.js","sourceRoot":"","sources":["../src/proof-hash.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;A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