@motebit/crypto 2.0.0 → 3.0.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 +11 -0
- package/dist/agent-settlement-anchor.d.ts +122 -0
- package/dist/agent-settlement-anchor.d.ts.map +1 -0
- package/dist/artifacts.d.ts +110 -2
- package/dist/artifacts.d.ts.map +1 -1
- package/dist/credential-anchor.d.ts +8 -1
- package/dist/credential-anchor.d.ts.map +1 -1
- package/dist/deletion-certificate.d.ts +2 -2
- package/dist/deletion-certificate.d.ts.map +1 -1
- package/dist/federation-settlement-anchor.d.ts +138 -0
- package/dist/federation-settlement-anchor.d.ts.map +1 -0
- package/dist/hardware-attestation.d.ts.map +1 -1
- package/dist/index.d.ts +34 -48
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3944 -2351
- package/dist/merkle.d.ts +57 -1
- package/dist/merkle.d.ts.map +1 -1
- package/dist/signing.d.ts.map +1 -1
- package/dist/suite-dispatch.d.ts.map +1 -1
- package/dist/suite-dispatch.js +1715 -1871
- package/package.json +7 -7
package/dist/merkle.d.ts
CHANGED
|
@@ -13,6 +13,54 @@
|
|
|
13
13
|
* - `witness-omission-dispute.ts` — `inclusion_proof` evidence
|
|
14
14
|
* against a horizon cert's `federation_graph_anchor.merkle_root`.
|
|
15
15
|
*/
|
|
16
|
+
import type { MerkleTreeVersion } from "@motebit/protocol";
|
|
17
|
+
/**
|
|
18
|
+
* Hash a Merkle leaf under a tree-hash version — the single dispatch point for
|
|
19
|
+
* the RFC 6962 §2.1 leaf-domain `0x00` tag, the leaf-side mirror of the
|
|
20
|
+
* interior-node `0x01` tag applied in {@link verifyMerkleInclusion}'s combine
|
|
21
|
+
* step. v1 = `SHA-256(entry)`; v2 = `SHA-256(0x00 ‖ entry)`. Every leaf builder
|
|
22
|
+
* (settlement, credential, identity-log, consolidation) routes its leaf hash
|
|
23
|
+
* through here, so the leaf tag lives in exactly one place — the
|
|
24
|
+
* `check-suite-dispatch` shape applied to the Merkle axis (locked by
|
|
25
|
+
* `check-merkle-tree-hash-canonical`).
|
|
26
|
+
*
|
|
27
|
+
* Producer-side contract: THROWS on a version this primitive does not implement
|
|
28
|
+
* (a builder asking for an unregistered version is a programming error, not
|
|
29
|
+
* untrusted input — unlike the verifier path, which returns `false`). The
|
|
30
|
+
* high-level verifiers validate the proof's `tree_hash_version` at their own
|
|
31
|
+
* boundary before threading it down, so an unhandled value never reaches here
|
|
32
|
+
* from untrusted input.
|
|
33
|
+
*
|
|
34
|
+
* @param entry - the leaf's entry bytes (e.g. encoded `canonicalJson(record)`)
|
|
35
|
+
* @param treeHashVersion - tree-hash recipe; default `merkle-sha256-plain-v1`
|
|
36
|
+
* @returns hex-encoded SHA-256 leaf hash
|
|
37
|
+
*/
|
|
38
|
+
export declare function hashLeaf(entry: Uint8Array, treeHashVersion?: MerkleTreeVersion): Promise<string>;
|
|
39
|
+
/**
|
|
40
|
+
* JCS-canonicalize a value, then leaf-hash it via {@link hashLeaf}.
|
|
41
|
+
* `canonicalLeaf(x)` (v1 default) is byte-identical to `canonicalSha256(x)` —
|
|
42
|
+
* the leaf builders that used the latter keep their v1 output unchanged while
|
|
43
|
+
* gaining the v2 path for free. The shared canonicalization means a producer
|
|
44
|
+
* and a holder who hold the same object derive the identical leaf.
|
|
45
|
+
*
|
|
46
|
+
* @param value - the object the leaf commits to (signature included for signed artifacts)
|
|
47
|
+
* @param treeHashVersion - tree-hash recipe; default `merkle-sha256-plain-v1`
|
|
48
|
+
* @returns hex-encoded SHA-256 leaf hash
|
|
49
|
+
*/
|
|
50
|
+
export declare function canonicalLeaf(value: unknown, treeHashVersion?: MerkleTreeVersion): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Resolve a proof's wire `tree_hash_version` string to a `MerkleTreeVersion` at
|
|
53
|
+
* a verifier boundary. **Absent ⇒ `merkle-sha256-plain-v1`** (never silently
|
|
54
|
+
* upgraded — threat-model rule a); a known value passes through; an UNKNOWN
|
|
55
|
+
* string returns `null` so the caller fails closed and REJECTS (never downgrades
|
|
56
|
+
* to v1 — threat-model rule b). The leaf-builder + Merkle-inclusion calls
|
|
57
|
+
* downstream then receive a narrow, supported version. Mirrors the
|
|
58
|
+
* `verifyBySuite` suite-resolution contract, one axis over. The two string
|
|
59
|
+
* literals here are the verifier-side dispatch arms the closed-registry gate
|
|
60
|
+
* (`check-merkle-tree-hash-canonical`) keeps aligned with
|
|
61
|
+
* `ALL_MERKLE_TREE_VERSIONS`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function resolveTreeHashVersion(raw: string | undefined): MerkleTreeVersion | null;
|
|
16
64
|
/**
|
|
17
65
|
* Verify a Merkle inclusion proof against an expected root.
|
|
18
66
|
*
|
|
@@ -24,11 +72,19 @@
|
|
|
24
72
|
* Returns `false` on any malformed input or hash mismatch — never
|
|
25
73
|
* throws. Same fail-closed contract as `verifyBySuite`.
|
|
26
74
|
*
|
|
75
|
+
* The `leaf` is the already-computed bottom-layer leaf HASH; the leaf-domain
|
|
76
|
+
* `0x00` tag (RFC 6962 §2.1) lives in the leaf builders that produce it, so this
|
|
77
|
+
* primitive applies only the interior-node `0x01` tag (under v2). `absent ⇒ v1`
|
|
78
|
+
* is resolved by the caller (the high-level verifier reads the proof's
|
|
79
|
+
* `tree_hash_version`); the default here keeps the ~dozen existing 5-arg callers
|
|
80
|
+
* byte-identical (v1) until they thread a version.
|
|
81
|
+
*
|
|
27
82
|
* @param leaf - hex-encoded SHA-256 leaf hash
|
|
28
83
|
* @param index - leaf position in the bottom layer (0-based)
|
|
29
84
|
* @param siblings - hex-encoded sibling hashes, leaf-to-root order
|
|
30
85
|
* @param layerSizes - bottom-up layer cardinalities
|
|
31
86
|
* @param expectedRoot - hex-encoded SHA-256 root the proof must reconstruct
|
|
87
|
+
* @param treeHashVersion - tree-hash recipe; default `merkle-sha256-plain-v1`
|
|
32
88
|
*/
|
|
33
|
-
export declare function verifyMerkleInclusion(leaf: string, index: number, siblings: string[], layerSizes: number[], expectedRoot: string): Promise<boolean>;
|
|
89
|
+
export declare function verifyMerkleInclusion(leaf: string, index: number, siblings: string[], layerSizes: number[], expectedRoot: string, treeHashVersion?: MerkleTreeVersion): Promise<boolean>;
|
|
34
90
|
//# sourceMappingURL=merkle.d.ts.map
|
package/dist/merkle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merkle.d.ts","sourceRoot":"","sources":["../src/merkle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;
|
|
1
|
+
{"version":3,"file":"merkle.d.ts","sourceRoot":"","sources":["../src/merkle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AA0B3D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,UAAU,EACjB,eAAe,GAAE,iBAA4C,GAC5D,OAAO,CAAC,MAAM,CAAC,CAQjB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,OAAO,EACd,eAAe,GAAE,iBAA4C,GAC5D,OAAO,CAAC,MAAM,CAAC,CAEjB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,iBAAiB,GAAG,IAAI,CAIxF;AAiCD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAAE,EAClB,UAAU,EAAE,MAAM,EAAE,EACpB,YAAY,EAAE,MAAM,EACpB,eAAe,GAAE,iBAA4C,GAC5D,OAAO,CAAC,OAAO,CAAC,CA8ClB"}
|
package/dist/signing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../src/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../src/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAgBH,MAAM,WAAW,OAAO;IACtB,SAAS,EAAE,UAAU,CAAC;IACtB,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,wFAAwF;IACxF,GAAG,EAAE,MAAM,CAAC;IACZ,qGAAqG;IACrG,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;OAMG;IACH,KAAK,EAAE,wBAAwB,CAAC;CACjC;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAG,wBAAiC,CAAC;AAIpE;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAclD;AAID,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIpD;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAMlD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAMpD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAQrD;AAMD,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAczD;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAoBvD;AAID;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAezD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM,CAS/D;AAED,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAEjE;AAID,wBAAsB,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAM5D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAEnE;AAED,gEAAgE;AAChE,wBAAsB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAGlE;AAaD,OAAO,EACL,WAAW,EACX,aAAa,EACb,sBAAsB,EACtB,mBAAmB,EACnB,WAAW,EACX,aAAa,GACd,MAAM,qBAAqB,CAAC;AAE7B,wBAAsB,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC,CAExD;AAID;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,IAAI,CAAC,kBAAkB,EAAE,OAAO,CAAC,EAC1C,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,MAAM,CAAC,CAOjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,UAAU,GACpB,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAoCpC;AAID;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAQxD;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAehF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suite-dispatch.d.ts","sourceRoot":"","sources":["../src/suite-dispatch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;
|
|
1
|
+
{"version":3,"file":"suite-dispatch.d.ts","sourceRoot":"","sources":["../src/suite-d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