@synoi/sraid 0.2.0 → 0.3.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 +51 -6
- package/dist/attestation.d.ts +8 -49
- package/dist/attestation.d.ts.map +1 -1
- package/dist/attestation.js +15 -46
- package/dist/attestation.js.map +1 -1
- package/dist/internal/attestation-core.d.ts +85 -0
- package/dist/internal/attestation-core.d.ts.map +1 -0
- package/dist/internal/attestation-core.js +78 -0
- package/dist/internal/attestation-core.js.map +1 -0
- package/dist/internal/base64-browser.d.ts +31 -0
- package/dist/internal/base64-browser.d.ts.map +1 -0
- package/dist/internal/base64-browser.js +39 -0
- package/dist/internal/base64-browser.js.map +1 -0
- package/dist/internal/base64-validate.d.ts +19 -0
- package/dist/internal/base64-validate.d.ts.map +1 -0
- package/dist/internal/base64-validate.js +33 -0
- package/dist/internal/base64-validate.js.map +1 -0
- package/dist/internal/base64.d.ts +7 -5
- package/dist/internal/base64.d.ts.map +1 -1
- package/dist/internal/base64.js +7 -19
- package/dist/internal/base64.js.map +1 -1
- package/dist/internal/content-core.d.ts +68 -0
- package/dist/internal/content-core.d.ts.map +1 -0
- package/dist/internal/content-core.js +87 -0
- package/dist/internal/content-core.js.map +1 -0
- package/dist/internal/ed25519-browser.d.ts +33 -0
- package/dist/internal/ed25519-browser.d.ts.map +1 -0
- package/dist/internal/ed25519-browser.js +79 -0
- package/dist/internal/ed25519-browser.js.map +1 -0
- package/dist/internal/mldsa-browser.d.ts +27 -0
- package/dist/internal/mldsa-browser.d.ts.map +1 -0
- package/dist/internal/mldsa-browser.js +35 -0
- package/dist/internal/mldsa-browser.js.map +1 -0
- package/dist/internal/sha256-browser.d.ts +17 -0
- package/dist/internal/sha256-browser.d.ts.map +1 -0
- package/dist/internal/sha256-browser.js +27 -0
- package/dist/internal/sha256-browser.js.map +1 -0
- package/dist/oid.d.ts +2 -52
- package/dist/oid.d.ts.map +1 -1
- package/dist/oid.js +9 -71
- package/dist/oid.js.map +1 -1
- package/dist/verify-browser.d.ts +80 -0
- package/dist/verify-browser.d.ts.map +1 -0
- package/dist/verify-browser.js +157 -0
- package/dist/verify-browser.js.map +1 -0
- package/package.json +21 -2
- package/src/attestation.ts +29 -88
- package/src/internal/attestation-core.ts +122 -0
- package/src/internal/base64-browser.ts +39 -0
- package/src/internal/base64-validate.ts +31 -0
- package/src/internal/base64.ts +7 -16
- package/src/internal/content-core.ts +88 -0
- package/src/internal/ed25519-browser.ts +85 -0
- package/src/internal/mldsa-browser.ts +39 -0
- package/src/internal/sha256-browser.ts +28 -0
- package/src/oid.ts +10 -73
- package/src/verify-browser.ts +185 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/internal/base64.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/internal/base64.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAEnD,OAAO,EAAE,YAAY,EAAE,CAAA;AAEvB;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,CAAS;IAC1C,YAAY,CAAC,CAAC,CAAC,CAAA;IACf,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAA;AACjD,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synoi/sraid — internal/content-core.ts
|
|
3
|
+
*
|
|
4
|
+
* The CDRO OID content-core projection: the normative strip-set and the
|
|
5
|
+
* field-removal function that together define WHAT bytes an OID is computed
|
|
6
|
+
* over. This is a PURE module — no hashing, no node:crypto, no Buffer — so it
|
|
7
|
+
* is safe to import from both the node default entry (via oid.ts) and the
|
|
8
|
+
* browser verify surface (via verify-browser.ts) without dragging node
|
|
9
|
+
* builtins into a browser bundle.
|
|
10
|
+
*
|
|
11
|
+
* This is the SINGLE NORMATIVE SOURCE of the CDRO OID projection (ADR_019).
|
|
12
|
+
* oid.ts re-exports these symbols and layers the SHA-256 hashing on top; every
|
|
13
|
+
* other surface (GAP SDKs, the gateway signer, IMPLEMENTING.md) derives from
|
|
14
|
+
* THIS set, never re-lists it.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The detached-signature / envelope fields removed by `cdroContentCore`
|
|
18
|
+
* before hashing. This is the SINGLE NORMATIVE strip-set for the CDRO OID
|
|
19
|
+
* projection (ADR_019 decision 1); every other surface (GAP SDKs, the
|
|
20
|
+
* gateway signer, IMPLEMENTING.md) derives from THIS set, never re-lists it.
|
|
21
|
+
*
|
|
22
|
+
* The set is defined SEMANTICALLY: it is "every field produced BY the signer
|
|
23
|
+
* after canonicalization, plus the OID output itself." Concretely:
|
|
24
|
+
*
|
|
25
|
+
* oid — the projection OUTPUT (cannot be an input to itself).
|
|
26
|
+
* signature — legacy hybrid SignatureEnvelope (attaches after hash).
|
|
27
|
+
* ml_dsa_signature — detached PQ signature (attaches after hash).
|
|
28
|
+
* signature_key_id — signer-stamped key id (produced by the signer).
|
|
29
|
+
* signature_algorithm — signer-stamped alg id (produced by the signer).
|
|
30
|
+
* attestation — DSSE AttestationEnvelope (attaches after hash).
|
|
31
|
+
*
|
|
32
|
+
* EVERYTHING ELSE IS KEPT and hashed into the OID, including in particular:
|
|
33
|
+
* - `gap_version` — IN identity so a protocol downgrade is OID-detectable.
|
|
34
|
+
* - `supersedes` — IN identity because the SRAID Merkle-DAG head-proves-
|
|
35
|
+
* history property requires every lineage edge inside the
|
|
36
|
+
* hash. Superseding mints a NEW object; it never mutates
|
|
37
|
+
* the old one's bytes, so keeping it here is safe and
|
|
38
|
+
* makes the lineage edge tamper-evident.
|
|
39
|
+
* - `type`, `sraid_version`, `tenant_id`, `created_at_ms`, `created_by`,
|
|
40
|
+
* `body`, `authority`, `sensitivity`, `prev`, `links`, and any other
|
|
41
|
+
* content field.
|
|
42
|
+
*
|
|
43
|
+
* This is the ONE projection that yields the SAME OID whether the object is
|
|
44
|
+
* pre- or post-attestation: attaching an `attestation` (or `signature`,
|
|
45
|
+
* `ml_dsa_signature`, `signature_key_id`, `signature_algorithm`) after hashing
|
|
46
|
+
* is stripped back out here, so `cdroOid(obj)` is invariant across signing.
|
|
47
|
+
*
|
|
48
|
+
* It is FROZEN so no caller can mutate the normative set at runtime.
|
|
49
|
+
*/
|
|
50
|
+
export declare const CDRO_ENVELOPE_FIELDS: readonly string[];
|
|
51
|
+
/**
|
|
52
|
+
* Build the OID content core of a full CDRO: the object with EXACTLY the six
|
|
53
|
+
* detached-signature / envelope fields in `CDRO_ENVELOPE_FIELDS` removed at
|
|
54
|
+
* the top level, and everything else kept.
|
|
55
|
+
*
|
|
56
|
+
* This is the mechanism that makes the L4 `authority` block, the L3 lineage
|
|
57
|
+
* edges (`prev`, `links`, `supersedes`), the propagating `sensitivity` tier,
|
|
58
|
+
* and `gap_version` tamper-evident: they are hashed into identity by
|
|
59
|
+
* construction, so a field cannot be added, stripped, re-pointed, or
|
|
60
|
+
* downgraded without producing a different OID (and invalidating the
|
|
61
|
+
* signature, which is computed over these same bytes). Because `prev`/`links`/
|
|
62
|
+
* `supersedes` OIDs are inside the hash, a node's OID transitively commits its
|
|
63
|
+
* whole reachable history (the Merkle-DAG "head proves history" property).
|
|
64
|
+
*
|
|
65
|
+
* Returns a plain object suitable for `canonicalize` / `oidOf`.
|
|
66
|
+
*/
|
|
67
|
+
export declare function cdroContentCore(cdro: unknown): Record<string, unknown>;
|
|
68
|
+
//# sourceMappingURL=content-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-core.d.ts","sourceRoot":"","sources":["../../src/internal/content-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EAOhD,CAAA;AAIF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAUtE"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synoi/sraid — internal/content-core.ts
|
|
3
|
+
*
|
|
4
|
+
* The CDRO OID content-core projection: the normative strip-set and the
|
|
5
|
+
* field-removal function that together define WHAT bytes an OID is computed
|
|
6
|
+
* over. This is a PURE module — no hashing, no node:crypto, no Buffer — so it
|
|
7
|
+
* is safe to import from both the node default entry (via oid.ts) and the
|
|
8
|
+
* browser verify surface (via verify-browser.ts) without dragging node
|
|
9
|
+
* builtins into a browser bundle.
|
|
10
|
+
*
|
|
11
|
+
* This is the SINGLE NORMATIVE SOURCE of the CDRO OID projection (ADR_019).
|
|
12
|
+
* oid.ts re-exports these symbols and layers the SHA-256 hashing on top; every
|
|
13
|
+
* other surface (GAP SDKs, the gateway signer, IMPLEMENTING.md) derives from
|
|
14
|
+
* THIS set, never re-lists it.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The detached-signature / envelope fields removed by `cdroContentCore`
|
|
18
|
+
* before hashing. This is the SINGLE NORMATIVE strip-set for the CDRO OID
|
|
19
|
+
* projection (ADR_019 decision 1); every other surface (GAP SDKs, the
|
|
20
|
+
* gateway signer, IMPLEMENTING.md) derives from THIS set, never re-lists it.
|
|
21
|
+
*
|
|
22
|
+
* The set is defined SEMANTICALLY: it is "every field produced BY the signer
|
|
23
|
+
* after canonicalization, plus the OID output itself." Concretely:
|
|
24
|
+
*
|
|
25
|
+
* oid — the projection OUTPUT (cannot be an input to itself).
|
|
26
|
+
* signature — legacy hybrid SignatureEnvelope (attaches after hash).
|
|
27
|
+
* ml_dsa_signature — detached PQ signature (attaches after hash).
|
|
28
|
+
* signature_key_id — signer-stamped key id (produced by the signer).
|
|
29
|
+
* signature_algorithm — signer-stamped alg id (produced by the signer).
|
|
30
|
+
* attestation — DSSE AttestationEnvelope (attaches after hash).
|
|
31
|
+
*
|
|
32
|
+
* EVERYTHING ELSE IS KEPT and hashed into the OID, including in particular:
|
|
33
|
+
* - `gap_version` — IN identity so a protocol downgrade is OID-detectable.
|
|
34
|
+
* - `supersedes` — IN identity because the SRAID Merkle-DAG head-proves-
|
|
35
|
+
* history property requires every lineage edge inside the
|
|
36
|
+
* hash. Superseding mints a NEW object; it never mutates
|
|
37
|
+
* the old one's bytes, so keeping it here is safe and
|
|
38
|
+
* makes the lineage edge tamper-evident.
|
|
39
|
+
* - `type`, `sraid_version`, `tenant_id`, `created_at_ms`, `created_by`,
|
|
40
|
+
* `body`, `authority`, `sensitivity`, `prev`, `links`, and any other
|
|
41
|
+
* content field.
|
|
42
|
+
*
|
|
43
|
+
* This is the ONE projection that yields the SAME OID whether the object is
|
|
44
|
+
* pre- or post-attestation: attaching an `attestation` (or `signature`,
|
|
45
|
+
* `ml_dsa_signature`, `signature_key_id`, `signature_algorithm`) after hashing
|
|
46
|
+
* is stripped back out here, so `cdroOid(obj)` is invariant across signing.
|
|
47
|
+
*
|
|
48
|
+
* It is FROZEN so no caller can mutate the normative set at runtime.
|
|
49
|
+
*/
|
|
50
|
+
export const CDRO_ENVELOPE_FIELDS = Object.freeze([
|
|
51
|
+
'oid',
|
|
52
|
+
'signature',
|
|
53
|
+
'ml_dsa_signature',
|
|
54
|
+
'signature_key_id',
|
|
55
|
+
'signature_algorithm',
|
|
56
|
+
'attestation',
|
|
57
|
+
]);
|
|
58
|
+
const CDRO_ENVELOPE_FIELD_SET = new Set(CDRO_ENVELOPE_FIELDS);
|
|
59
|
+
/**
|
|
60
|
+
* Build the OID content core of a full CDRO: the object with EXACTLY the six
|
|
61
|
+
* detached-signature / envelope fields in `CDRO_ENVELOPE_FIELDS` removed at
|
|
62
|
+
* the top level, and everything else kept.
|
|
63
|
+
*
|
|
64
|
+
* This is the mechanism that makes the L4 `authority` block, the L3 lineage
|
|
65
|
+
* edges (`prev`, `links`, `supersedes`), the propagating `sensitivity` tier,
|
|
66
|
+
* and `gap_version` tamper-evident: they are hashed into identity by
|
|
67
|
+
* construction, so a field cannot be added, stripped, re-pointed, or
|
|
68
|
+
* downgraded without producing a different OID (and invalidating the
|
|
69
|
+
* signature, which is computed over these same bytes). Because `prev`/`links`/
|
|
70
|
+
* `supersedes` OIDs are inside the hash, a node's OID transitively commits its
|
|
71
|
+
* whole reachable history (the Merkle-DAG "head proves history" property).
|
|
72
|
+
*
|
|
73
|
+
* Returns a plain object suitable for `canonicalize` / `oidOf`.
|
|
74
|
+
*/
|
|
75
|
+
export function cdroContentCore(cdro) {
|
|
76
|
+
if (cdro === null || typeof cdro !== 'object' || Array.isArray(cdro)) {
|
|
77
|
+
throw new TypeError('cdroContentCore: argument must be a CDRO object');
|
|
78
|
+
}
|
|
79
|
+
const core = {};
|
|
80
|
+
for (const [k, v] of Object.entries(cdro)) {
|
|
81
|
+
if (CDRO_ENVELOPE_FIELD_SET.has(k))
|
|
82
|
+
continue;
|
|
83
|
+
core[k] = v;
|
|
84
|
+
}
|
|
85
|
+
return core;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=content-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-core.js","sourceRoot":"","sources":["../../src/internal/content-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAsB,MAAM,CAAC,MAAM,CAAC;IACnE,KAAK;IACL,WAAW;IACX,kBAAkB;IAClB,kBAAkB;IAClB,qBAAqB;IACrB,aAAa;CACd,CAAC,CAAA;AAEF,MAAM,uBAAuB,GAAwB,IAAI,GAAG,CAAC,oBAAoB,CAAC,CAAA;AAElF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,eAAe,CAAC,IAAa;IAC3C,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACrE,MAAM,IAAI,SAAS,CAAC,iDAAiD,CAAC,CAAA;IACxE,CAAC;IACD,MAAM,IAAI,GAA4B,EAAE,CAAA;IACxC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAA+B,CAAC,EAAE,CAAC;QACrE,IAAI,uBAAuB,CAAC,GAAG,CAAC,CAAC,CAAC;YAAE,SAAQ;QAC5C,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IACb,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synoi/sraid — internal/ed25519-browser.ts
|
|
3
|
+
*
|
|
4
|
+
* Browser-safe Ed25519 verification. NO node:crypto.
|
|
5
|
+
*
|
|
6
|
+
* Primary path: WebCrypto (`globalThis.crypto.subtle`), which uses RFC 8032
|
|
7
|
+
* cofactored verification — the SAME rule OpenSSL/node:crypto uses on the node
|
|
8
|
+
* default entry, so the browser verifier accepts/rejects exactly what the node
|
|
9
|
+
* verifier does for every real signature.
|
|
10
|
+
*
|
|
11
|
+
* Fallback path: `@noble/curves` ed25519 (pure JS), used only when WebCrypto
|
|
12
|
+
* Ed25519 is unavailable (older embedded webviews / Chrome extensions below the
|
|
13
|
+
* WebCrypto-Ed25519 support floor, ~Chrome 137). @noble defaults to ZIP-215
|
|
14
|
+
* verification rules, which agree with cofactored on every well-formed
|
|
15
|
+
* signature and can differ only on deliberately malformed/malleable points that
|
|
16
|
+
* real signers never produce (see ed25519.ts for the same note). SynOI signs
|
|
17
|
+
* canonically, so the fallback is behavior-equivalent for legitimate inputs.
|
|
18
|
+
*
|
|
19
|
+
* ASYNC: WebCrypto verify is Promise-based, so this returns a Promise<boolean>.
|
|
20
|
+
* The browser attestation verifier is async as a result; the node path stays
|
|
21
|
+
* synchronous and unchanged.
|
|
22
|
+
*
|
|
23
|
+
* Returns false (never throws) on any malformed input or verification failure,
|
|
24
|
+
* matching the node `verifyEd25519` contract, so callers get a clean boolean.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Verify a raw 64-byte Ed25519 signature over `message` against a raw 32-byte
|
|
28
|
+
* public key. Prefers WebCrypto (cofactored, matching the node path); falls
|
|
29
|
+
* back to @noble/curves only when WebCrypto Ed25519 is not supported. Returns
|
|
30
|
+
* false on any malformed input or verification failure; never throws.
|
|
31
|
+
*/
|
|
32
|
+
export declare function verifyEd25519Browser(signature: Uint8Array, message: Uint8Array, publicKeyRaw: Uint8Array): Promise<boolean>;
|
|
33
|
+
//# sourceMappingURL=ed25519-browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ed25519-browser.d.ts","sourceRoot":"","sources":["../../src/internal/ed25519-browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AA8BH;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,UAAU,EACrB,OAAO,EAAE,UAAU,EACnB,YAAY,EAAE,UAAU,GACvB,OAAO,CAAC,OAAO,CAAC,CAoBlB"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synoi/sraid — internal/ed25519-browser.ts
|
|
3
|
+
*
|
|
4
|
+
* Browser-safe Ed25519 verification. NO node:crypto.
|
|
5
|
+
*
|
|
6
|
+
* Primary path: WebCrypto (`globalThis.crypto.subtle`), which uses RFC 8032
|
|
7
|
+
* cofactored verification — the SAME rule OpenSSL/node:crypto uses on the node
|
|
8
|
+
* default entry, so the browser verifier accepts/rejects exactly what the node
|
|
9
|
+
* verifier does for every real signature.
|
|
10
|
+
*
|
|
11
|
+
* Fallback path: `@noble/curves` ed25519 (pure JS), used only when WebCrypto
|
|
12
|
+
* Ed25519 is unavailable (older embedded webviews / Chrome extensions below the
|
|
13
|
+
* WebCrypto-Ed25519 support floor, ~Chrome 137). @noble defaults to ZIP-215
|
|
14
|
+
* verification rules, which agree with cofactored on every well-formed
|
|
15
|
+
* signature and can differ only on deliberately malformed/malleable points that
|
|
16
|
+
* real signers never produce (see ed25519.ts for the same note). SynOI signs
|
|
17
|
+
* canonically, so the fallback is behavior-equivalent for legitimate inputs.
|
|
18
|
+
*
|
|
19
|
+
* ASYNC: WebCrypto verify is Promise-based, so this returns a Promise<boolean>.
|
|
20
|
+
* The browser attestation verifier is async as a result; the node path stays
|
|
21
|
+
* synchronous and unchanged.
|
|
22
|
+
*
|
|
23
|
+
* Returns false (never throws) on any malformed input or verification failure,
|
|
24
|
+
* matching the node `verifyEd25519` contract, so callers get a clean boolean.
|
|
25
|
+
*/
|
|
26
|
+
import { ed25519 } from '@noble/curves/ed25519.js';
|
|
27
|
+
// Fixed DER prefix for an Ed25519 SubjectPublicKeyInfo (RFC 8410):
|
|
28
|
+
// SEQUENCE { SEQUENCE { OID 1.3.101.112 } BIT STRING (32 raw bytes) }
|
|
29
|
+
// A plain Uint8Array literal (NOT Buffer, which is undefined in browsers). Used
|
|
30
|
+
// only for the SPKI import fallback below.
|
|
31
|
+
const ED25519_SPKI_PREFIX = new Uint8Array([
|
|
32
|
+
0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x03, 0x21, 0x00,
|
|
33
|
+
]);
|
|
34
|
+
const ED25519_ALG = { name: 'Ed25519' };
|
|
35
|
+
// Return type is inferred (webcrypto.CryptoKey); the bare `CryptoKey` global is
|
|
36
|
+
// not declared by @types/node ^20, so it is deliberately left un-annotated.
|
|
37
|
+
async function importPublicKey(publicKeyRaw) {
|
|
38
|
+
const subtle = globalThis.crypto.subtle;
|
|
39
|
+
try {
|
|
40
|
+
// Preferred: raw 32-byte import (Secure Curves spec).
|
|
41
|
+
return await subtle.importKey('raw', publicKeyRaw, ED25519_ALG, false, ['verify']);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// Some engines only accept SPKI for Ed25519 import; wrap the raw key.
|
|
45
|
+
const spki = new Uint8Array(ED25519_SPKI_PREFIX.length + publicKeyRaw.length);
|
|
46
|
+
spki.set(ED25519_SPKI_PREFIX, 0);
|
|
47
|
+
spki.set(publicKeyRaw, ED25519_SPKI_PREFIX.length);
|
|
48
|
+
return await subtle.importKey('spki', spki, ED25519_ALG, false, ['verify']);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Verify a raw 64-byte Ed25519 signature over `message` against a raw 32-byte
|
|
53
|
+
* public key. Prefers WebCrypto (cofactored, matching the node path); falls
|
|
54
|
+
* back to @noble/curves only when WebCrypto Ed25519 is not supported. Returns
|
|
55
|
+
* false on any malformed input or verification failure; never throws.
|
|
56
|
+
*/
|
|
57
|
+
export async function verifyEd25519Browser(signature, message, publicKeyRaw) {
|
|
58
|
+
if (publicKeyRaw.length !== 32)
|
|
59
|
+
return false;
|
|
60
|
+
const subtle = globalThis.crypto?.subtle;
|
|
61
|
+
if (subtle) {
|
|
62
|
+
try {
|
|
63
|
+
const key = await importPublicKey(publicKeyRaw);
|
|
64
|
+
return await subtle.verify(ED25519_ALG, key, signature, message);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// Fall through to @noble. A WebCrypto throw here is either an
|
|
68
|
+
// unsupported-algorithm signal or a malformed input; @noble resolves both
|
|
69
|
+
// correctly (a real bad signature/key verifies as false there too).
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
return ed25519.verify(signature, message, publicKeyRaw);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=ed25519-browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ed25519-browser.js","sourceRoot":"","sources":["../../src/internal/ed25519-browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAElD,mEAAmE;AACnE,wEAAwE;AACxE,gFAAgF;AAChF,2CAA2C;AAC3C,MAAM,mBAAmB,GAAG,IAAI,UAAU,CAAC;IACzC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;CACvE,CAAC,CAAA;AAEF,MAAM,WAAW,GAAG,EAAE,IAAI,EAAE,SAAS,EAAW,CAAA;AAEhD,gFAAgF;AAChF,4EAA4E;AAC5E,KAAK,UAAU,eAAe,CAAC,YAAwB;IACrD,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,CAAA;IACvC,IAAI,CAAC;QACH,sDAAsD;QACtD,OAAO,MAAM,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAA;IACpF,CAAC;IAAC,MAAM,CAAC;QACP,sEAAsE;QACtE,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,mBAAmB,CAAC,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CAAA;QAC7E,IAAI,CAAC,GAAG,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAA;QAChC,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAA;QAClD,OAAO,MAAM,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAA;IAC7E,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,SAAqB,EACrB,OAAmB,EACnB,YAAwB;IAExB,IAAI,YAAY,CAAC,MAAM,KAAK,EAAE;QAAE,OAAO,KAAK,CAAA;IAE5C,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,MAAM,CAAA;IACxC,IAAI,MAAM,EAAE,CAAC;QACX,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,eAAe,CAAC,YAAY,CAAC,CAAA;YAC/C,OAAO,MAAM,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;QAClE,CAAC;QAAC,MAAM,CAAC;YACP,8DAA8D;YAC9D,0EAA0E;YAC1E,oEAAoE;QACtE,CAAC;IACH,CAAC;IAED,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,YAAY,CAAC,CAAA;IACzD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synoi/sraid — internal/mldsa-browser.ts
|
|
3
|
+
*
|
|
4
|
+
* Browser-safe ML-DSA-65 (FIPS 204) verification. NO node:crypto.
|
|
5
|
+
*
|
|
6
|
+
* Browsers ship no native ML-DSA, so there is only one path here: the pure-JS
|
|
7
|
+
* `@noble/post-quantum` implementation, which is fully browser-safe. The node
|
|
8
|
+
* default entry (mldsa.ts) uses a native OpenSSL fast path with this same
|
|
9
|
+
* @noble impl as its fallback, so both entries are byte-for-byte interoperable.
|
|
10
|
+
*
|
|
11
|
+
* IMPORTANT: import `ml_dsa65` DIRECTLY from `@noble/post-quantum/ml-dsa.js`,
|
|
12
|
+
* NOT from ./mldsa.ts — that module statically imports `node:crypto` (for its
|
|
13
|
+
* native fast path and the globalThis.crypto polyfill), which would poison a
|
|
14
|
+
* browser bundle. No globalThis.crypto polyfill is needed here: browsers,
|
|
15
|
+
* workers, and MV3 service workers all provide it natively, and ml_dsa65.verify
|
|
16
|
+
* is deterministic (it never calls getRandomValues; only keygen/sign do).
|
|
17
|
+
*
|
|
18
|
+
* Verification is SYNCHRONOUS. Returns false (never throws) on any malformed
|
|
19
|
+
* input or verification failure, matching the node `verifyMlDsa65` contract.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Verify a raw ML-DSA-65 signature over `message` against a raw 1952-byte
|
|
23
|
+
* public key using @noble/post-quantum. Returns false on any malformed input or
|
|
24
|
+
* verification failure; never throws.
|
|
25
|
+
*/
|
|
26
|
+
export declare function verifyMlDsa65Browser(signature: Uint8Array, message: Uint8Array, publicKeyRaw: Uint8Array): boolean;
|
|
27
|
+
//# sourceMappingURL=mldsa-browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mldsa-browser.d.ts","sourceRoot":"","sources":["../../src/internal/mldsa-browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,UAAU,EACrB,OAAO,EAAE,UAAU,EACnB,YAAY,EAAE,UAAU,GACvB,OAAO,CAMT"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synoi/sraid — internal/mldsa-browser.ts
|
|
3
|
+
*
|
|
4
|
+
* Browser-safe ML-DSA-65 (FIPS 204) verification. NO node:crypto.
|
|
5
|
+
*
|
|
6
|
+
* Browsers ship no native ML-DSA, so there is only one path here: the pure-JS
|
|
7
|
+
* `@noble/post-quantum` implementation, which is fully browser-safe. The node
|
|
8
|
+
* default entry (mldsa.ts) uses a native OpenSSL fast path with this same
|
|
9
|
+
* @noble impl as its fallback, so both entries are byte-for-byte interoperable.
|
|
10
|
+
*
|
|
11
|
+
* IMPORTANT: import `ml_dsa65` DIRECTLY from `@noble/post-quantum/ml-dsa.js`,
|
|
12
|
+
* NOT from ./mldsa.ts — that module statically imports `node:crypto` (for its
|
|
13
|
+
* native fast path and the globalThis.crypto polyfill), which would poison a
|
|
14
|
+
* browser bundle. No globalThis.crypto polyfill is needed here: browsers,
|
|
15
|
+
* workers, and MV3 service workers all provide it natively, and ml_dsa65.verify
|
|
16
|
+
* is deterministic (it never calls getRandomValues; only keygen/sign do).
|
|
17
|
+
*
|
|
18
|
+
* Verification is SYNCHRONOUS. Returns false (never throws) on any malformed
|
|
19
|
+
* input or verification failure, matching the node `verifyMlDsa65` contract.
|
|
20
|
+
*/
|
|
21
|
+
import { ml_dsa65 } from '@noble/post-quantum/ml-dsa.js';
|
|
22
|
+
/**
|
|
23
|
+
* Verify a raw ML-DSA-65 signature over `message` against a raw 1952-byte
|
|
24
|
+
* public key using @noble/post-quantum. Returns false on any malformed input or
|
|
25
|
+
* verification failure; never throws.
|
|
26
|
+
*/
|
|
27
|
+
export function verifyMlDsa65Browser(signature, message, publicKeyRaw) {
|
|
28
|
+
try {
|
|
29
|
+
return ml_dsa65.verify(signature, message, publicKeyRaw);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=mldsa-browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mldsa-browser.js","sourceRoot":"","sources":["../../src/internal/mldsa-browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAA;AAExD;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAClC,SAAqB,EACrB,OAAmB,EACnB,YAAwB;IAExB,IAAI,CAAC;QACH,OAAO,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,YAAY,CAAC,CAAA;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synoi/sraid — internal/sha256-browser.ts
|
|
3
|
+
*
|
|
4
|
+
* Browser-safe SHA-256 via WebCrypto (`globalThis.crypto.subtle.digest`). NO
|
|
5
|
+
* node:crypto. Used by the browser OID helpers in verify-browser.ts.
|
|
6
|
+
*
|
|
7
|
+
* ASYNC: subtle.digest is Promise-based, so the browser OID helpers are async
|
|
8
|
+
* (the node oid.ts helpers stay synchronous via node:crypto createHash and are
|
|
9
|
+
* unchanged). SHA-256 is byte-identical across any conformant implementation,
|
|
10
|
+
* so a browser-computed OID equals the node-computed one for the same input.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Compute `sha256:` + lowercase hex of SHA-256(bytes) using WebCrypto. Mirrors
|
|
14
|
+
* the `sha256:`-prefixed output of the node oid.ts helpers.
|
|
15
|
+
*/
|
|
16
|
+
export declare function sha256HexPrefixed(bytes: Uint8Array): Promise<string>;
|
|
17
|
+
//# sourceMappingURL=sha256-browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sha256-browser.d.ts","sourceRoot":"","sources":["../../src/internal/sha256-browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAUH;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAG1E"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synoi/sraid — internal/sha256-browser.ts
|
|
3
|
+
*
|
|
4
|
+
* Browser-safe SHA-256 via WebCrypto (`globalThis.crypto.subtle.digest`). NO
|
|
5
|
+
* node:crypto. Used by the browser OID helpers in verify-browser.ts.
|
|
6
|
+
*
|
|
7
|
+
* ASYNC: subtle.digest is Promise-based, so the browser OID helpers are async
|
|
8
|
+
* (the node oid.ts helpers stay synchronous via node:crypto createHash and are
|
|
9
|
+
* unchanged). SHA-256 is byte-identical across any conformant implementation,
|
|
10
|
+
* so a browser-computed OID equals the node-computed one for the same input.
|
|
11
|
+
*/
|
|
12
|
+
function toHex(bytes) {
|
|
13
|
+
let out = '';
|
|
14
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
15
|
+
out += bytes[i].toString(16).padStart(2, '0');
|
|
16
|
+
}
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Compute `sha256:` + lowercase hex of SHA-256(bytes) using WebCrypto. Mirrors
|
|
21
|
+
* the `sha256:`-prefixed output of the node oid.ts helpers.
|
|
22
|
+
*/
|
|
23
|
+
export async function sha256HexPrefixed(bytes) {
|
|
24
|
+
const digest = await globalThis.crypto.subtle.digest('SHA-256', bytes);
|
|
25
|
+
return 'sha256:' + toHex(new Uint8Array(digest));
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=sha256-browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sha256-browser.js","sourceRoot":"","sources":["../../src/internal/sha256-browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,SAAS,KAAK,CAAC,KAAiB;IAC9B,IAAI,GAAG,GAAG,EAAE,CAAA;IACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,GAAG,IAAK,KAAK,CAAC,CAAC,CAAY,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IAC3D,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,KAAiB;IACvD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;IACtE,OAAO,SAAS,GAAG,KAAK,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAA;AAClD,CAAC"}
|
package/dist/oid.d.ts
CHANGED
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
* This matches the gateway's `computeGapOid` (src/gap/oid.ts) and
|
|
20
20
|
* `payloadOid` (src/inference/receipts.ts) byte-for-byte.
|
|
21
21
|
*/
|
|
22
|
+
import { CDRO_ENVELOPE_FIELDS, cdroContentCore } from './internal/content-core.js';
|
|
23
|
+
export { CDRO_ENVELOPE_FIELDS, cdroContentCore };
|
|
22
24
|
/**
|
|
23
25
|
* Compute an OID over an arbitrary canonical-compatible value.
|
|
24
26
|
*
|
|
@@ -38,58 +40,6 @@ export declare function oidOf(canonical: unknown): string;
|
|
|
38
40
|
* canonicalizing twice.
|
|
39
41
|
*/
|
|
40
42
|
export declare function oidOfCanonical(canonical: string | Uint8Array): string;
|
|
41
|
-
/**
|
|
42
|
-
* The detached-signature / envelope fields removed by `cdroContentCore`
|
|
43
|
-
* before hashing. This is the SINGLE NORMATIVE strip-set for the CDRO OID
|
|
44
|
-
* projection (ADR_019 decision 1); every other surface (GAP SDKs, the
|
|
45
|
-
* gateway signer, IMPLEMENTING.md) derives from THIS set, never re-lists it.
|
|
46
|
-
*
|
|
47
|
-
* The set is defined SEMANTICALLY: it is "every field produced BY the signer
|
|
48
|
-
* after canonicalization, plus the OID output itself." Concretely:
|
|
49
|
-
*
|
|
50
|
-
* oid — the projection OUTPUT (cannot be an input to itself).
|
|
51
|
-
* signature — legacy hybrid SignatureEnvelope (attaches after hash).
|
|
52
|
-
* ml_dsa_signature — detached PQ signature (attaches after hash).
|
|
53
|
-
* signature_key_id — signer-stamped key id (produced by the signer).
|
|
54
|
-
* signature_algorithm — signer-stamped alg id (produced by the signer).
|
|
55
|
-
* attestation — DSSE AttestationEnvelope (attaches after hash).
|
|
56
|
-
*
|
|
57
|
-
* EVERYTHING ELSE IS KEPT and hashed into the OID, including in particular:
|
|
58
|
-
* - `gap_version` — IN identity so a protocol downgrade is OID-detectable.
|
|
59
|
-
* - `supersedes` — IN identity because the SRAID Merkle-DAG head-proves-
|
|
60
|
-
* history property requires every lineage edge inside the
|
|
61
|
-
* hash. Superseding mints a NEW object; it never mutates
|
|
62
|
-
* the old one's bytes, so keeping it here is safe and
|
|
63
|
-
* makes the lineage edge tamper-evident.
|
|
64
|
-
* - `type`, `sraid_version`, `tenant_id`, `created_at_ms`, `created_by`,
|
|
65
|
-
* `body`, `authority`, `sensitivity`, `prev`, `links`, and any other
|
|
66
|
-
* content field.
|
|
67
|
-
*
|
|
68
|
-
* This is the ONE projection that yields the SAME OID whether the object is
|
|
69
|
-
* pre- or post-attestation: attaching an `attestation` (or `signature`,
|
|
70
|
-
* `ml_dsa_signature`, `signature_key_id`, `signature_algorithm`) after hashing
|
|
71
|
-
* is stripped back out here, so `cdroOid(obj)` is invariant across signing.
|
|
72
|
-
*
|
|
73
|
-
* It is FROZEN so no caller can mutate the normative set at runtime.
|
|
74
|
-
*/
|
|
75
|
-
export declare const CDRO_ENVELOPE_FIELDS: readonly string[];
|
|
76
|
-
/**
|
|
77
|
-
* Build the OID content core of a full CDRO: the object with EXACTLY the six
|
|
78
|
-
* detached-signature / envelope fields in `CDRO_ENVELOPE_FIELDS` removed at
|
|
79
|
-
* the top level, and everything else kept.
|
|
80
|
-
*
|
|
81
|
-
* This is the mechanism that makes the L4 `authority` block, the L3 lineage
|
|
82
|
-
* edges (`prev`, `links`, `supersedes`), the propagating `sensitivity` tier,
|
|
83
|
-
* and `gap_version` tamper-evident: they are hashed into identity by
|
|
84
|
-
* construction, so a field cannot be added, stripped, re-pointed, or
|
|
85
|
-
* downgraded without producing a different OID (and invalidating the
|
|
86
|
-
* signature, which is computed over these same bytes). Because `prev`/`links`/
|
|
87
|
-
* `supersedes` OIDs are inside the hash, a node's OID transitively commits its
|
|
88
|
-
* whole reachable history (the Merkle-DAG "head proves history" property).
|
|
89
|
-
*
|
|
90
|
-
* Returns a plain object suitable for `canonicalize` / `oidOf`.
|
|
91
|
-
*/
|
|
92
|
-
export declare function cdroContentCore(cdro: unknown): Record<string, unknown>;
|
|
93
43
|
/**
|
|
94
44
|
* Compute the OID of a full CDRO over its content core (see
|
|
95
45
|
* `cdroContentCore`). This is the correct way to derive identity for a
|
package/dist/oid.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oid.d.ts","sourceRoot":"","sources":["../src/oid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;
|
|
1
|
+
{"version":3,"file":"oid.d.ts","sourceRoot":"","sources":["../src/oid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AASlF,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,CAAA;AAEhD;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM,CAGhD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAMrE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAE7C"}
|
package/dist/oid.js
CHANGED
|
@@ -21,6 +21,15 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import { createHash } from 'node:crypto';
|
|
23
23
|
import { canonicalize } from './canonicalize.js';
|
|
24
|
+
import { CDRO_ENVELOPE_FIELDS, cdroContentCore } from './internal/content-core.js';
|
|
25
|
+
// The CDRO strip-set and its content-core projection are the SINGLE NORMATIVE
|
|
26
|
+
// SOURCE (ADR_019) and live in the PURE ./internal/content-core module (no
|
|
27
|
+
// node:crypto), so the browser verify surface can share them byte-for-byte.
|
|
28
|
+
// oid.ts re-exports them and layers the SHA-256 hashing (below) on top; this
|
|
29
|
+
// keeps the public surface (`import { cdroContentCore, CDRO_ENVELOPE_FIELDS }
|
|
30
|
+
// from '@synoi/sraid'`) unchanged. See ./internal/content-core.ts for the
|
|
31
|
+
// normative strip-set documentation; do not re-list it here.
|
|
32
|
+
export { CDRO_ENVELOPE_FIELDS, cdroContentCore };
|
|
24
33
|
/**
|
|
25
34
|
* Compute an OID over an arbitrary canonical-compatible value.
|
|
26
35
|
*
|
|
@@ -48,77 +57,6 @@ export function oidOfCanonical(canonical) {
|
|
|
48
57
|
: canonical;
|
|
49
58
|
return 'sha256:' + createHash('sha256').update(bytes).digest('hex');
|
|
50
59
|
}
|
|
51
|
-
/**
|
|
52
|
-
* The detached-signature / envelope fields removed by `cdroContentCore`
|
|
53
|
-
* before hashing. This is the SINGLE NORMATIVE strip-set for the CDRO OID
|
|
54
|
-
* projection (ADR_019 decision 1); every other surface (GAP SDKs, the
|
|
55
|
-
* gateway signer, IMPLEMENTING.md) derives from THIS set, never re-lists it.
|
|
56
|
-
*
|
|
57
|
-
* The set is defined SEMANTICALLY: it is "every field produced BY the signer
|
|
58
|
-
* after canonicalization, plus the OID output itself." Concretely:
|
|
59
|
-
*
|
|
60
|
-
* oid — the projection OUTPUT (cannot be an input to itself).
|
|
61
|
-
* signature — legacy hybrid SignatureEnvelope (attaches after hash).
|
|
62
|
-
* ml_dsa_signature — detached PQ signature (attaches after hash).
|
|
63
|
-
* signature_key_id — signer-stamped key id (produced by the signer).
|
|
64
|
-
* signature_algorithm — signer-stamped alg id (produced by the signer).
|
|
65
|
-
* attestation — DSSE AttestationEnvelope (attaches after hash).
|
|
66
|
-
*
|
|
67
|
-
* EVERYTHING ELSE IS KEPT and hashed into the OID, including in particular:
|
|
68
|
-
* - `gap_version` — IN identity so a protocol downgrade is OID-detectable.
|
|
69
|
-
* - `supersedes` — IN identity because the SRAID Merkle-DAG head-proves-
|
|
70
|
-
* history property requires every lineage edge inside the
|
|
71
|
-
* hash. Superseding mints a NEW object; it never mutates
|
|
72
|
-
* the old one's bytes, so keeping it here is safe and
|
|
73
|
-
* makes the lineage edge tamper-evident.
|
|
74
|
-
* - `type`, `sraid_version`, `tenant_id`, `created_at_ms`, `created_by`,
|
|
75
|
-
* `body`, `authority`, `sensitivity`, `prev`, `links`, and any other
|
|
76
|
-
* content field.
|
|
77
|
-
*
|
|
78
|
-
* This is the ONE projection that yields the SAME OID whether the object is
|
|
79
|
-
* pre- or post-attestation: attaching an `attestation` (or `signature`,
|
|
80
|
-
* `ml_dsa_signature`, `signature_key_id`, `signature_algorithm`) after hashing
|
|
81
|
-
* is stripped back out here, so `cdroOid(obj)` is invariant across signing.
|
|
82
|
-
*
|
|
83
|
-
* It is FROZEN so no caller can mutate the normative set at runtime.
|
|
84
|
-
*/
|
|
85
|
-
export const CDRO_ENVELOPE_FIELDS = Object.freeze([
|
|
86
|
-
'oid',
|
|
87
|
-
'signature',
|
|
88
|
-
'ml_dsa_signature',
|
|
89
|
-
'signature_key_id',
|
|
90
|
-
'signature_algorithm',
|
|
91
|
-
'attestation',
|
|
92
|
-
]);
|
|
93
|
-
const CDRO_ENVELOPE_FIELD_SET = new Set(CDRO_ENVELOPE_FIELDS);
|
|
94
|
-
/**
|
|
95
|
-
* Build the OID content core of a full CDRO: the object with EXACTLY the six
|
|
96
|
-
* detached-signature / envelope fields in `CDRO_ENVELOPE_FIELDS` removed at
|
|
97
|
-
* the top level, and everything else kept.
|
|
98
|
-
*
|
|
99
|
-
* This is the mechanism that makes the L4 `authority` block, the L3 lineage
|
|
100
|
-
* edges (`prev`, `links`, `supersedes`), the propagating `sensitivity` tier,
|
|
101
|
-
* and `gap_version` tamper-evident: they are hashed into identity by
|
|
102
|
-
* construction, so a field cannot be added, stripped, re-pointed, or
|
|
103
|
-
* downgraded without producing a different OID (and invalidating the
|
|
104
|
-
* signature, which is computed over these same bytes). Because `prev`/`links`/
|
|
105
|
-
* `supersedes` OIDs are inside the hash, a node's OID transitively commits its
|
|
106
|
-
* whole reachable history (the Merkle-DAG "head proves history" property).
|
|
107
|
-
*
|
|
108
|
-
* Returns a plain object suitable for `canonicalize` / `oidOf`.
|
|
109
|
-
*/
|
|
110
|
-
export function cdroContentCore(cdro) {
|
|
111
|
-
if (cdro === null || typeof cdro !== 'object' || Array.isArray(cdro)) {
|
|
112
|
-
throw new TypeError('cdroContentCore: argument must be a CDRO object');
|
|
113
|
-
}
|
|
114
|
-
const core = {};
|
|
115
|
-
for (const [k, v] of Object.entries(cdro)) {
|
|
116
|
-
if (CDRO_ENVELOPE_FIELD_SET.has(k))
|
|
117
|
-
continue;
|
|
118
|
-
core[k] = v;
|
|
119
|
-
}
|
|
120
|
-
return core;
|
|
121
|
-
}
|
|
122
60
|
/**
|
|
123
61
|
* Compute the OID of a full CDRO over its content core (see
|
|
124
62
|
* `cdroContentCore`). This is the correct way to derive identity for a
|
package/dist/oid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oid.js","sourceRoot":"","sources":["../src/oid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,KAAK,CAAC,SAAkB;IACtC,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAA;IAC/D,OAAO,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACrE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,SAA8B;IAC3D,MAAM,KAAK,GACT,OAAO,SAAS,KAAK,QAAQ;QAC3B,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC;QACrC,CAAC,CAAC,SAAS,CAAA;IACf,OAAO,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACrE,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"oid.js","sourceRoot":"","sources":["../src/oid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAElF,8EAA8E;AAC9E,2EAA2E;AAC3E,4EAA4E;AAC5E,6EAA6E;AAC7E,8EAA8E;AAC9E,0EAA0E;AAC1E,6DAA6D;AAC7D,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,CAAA;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,KAAK,CAAC,SAAkB;IACtC,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAA;IAC/D,OAAO,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACrE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,SAA8B;IAC3D,MAAM,KAAK,GACT,OAAO,SAAS,KAAK,QAAQ;QAC3B,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC;QACrC,CAAC,CAAC,SAAS,CAAA;IACf,OAAO,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACrE,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,OAAO,CAAC,IAAa;IACnC,OAAO,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAA;AACrC,CAAC"}
|