@blamejs/core 0.12.36 → 0.12.37
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/CHANGELOG.md +2 -0
- package/README.md +1 -0
- package/index.js +1 -0
- package/lib/cose.js +30 -4
- package/lib/scitt.js +243 -0
- package/package.json +1 -1
- package/sbom.cdx.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,8 @@ upgrading across more than a few patches at a time.
|
|
|
8
8
|
|
|
9
9
|
## v0.12.x
|
|
10
10
|
|
|
11
|
+
- v0.12.37 (2026-05-24) — **`b.scitt.signStatement` / `b.scitt.verifyStatement` — SCITT signed statements over COSE (RFC 9052 + RFC 9597).** A SCITT signed statement is a signed, attributable claim about an artifact — a signed SBOM, a build attestation, a release approval. It is a COSE_Sign1 (b.cose) whose integrity-protected CWT_Claims header (label 15, RFC 9597) binds the issuer (who makes the statement) and the subject (the artifact it is about); the artifact, or a hash/reference to it, is the payload. signStatement places iss/sub in the protected header and declares the payload media type; verifyStatement checks the COSE signature (the algorithm allowlist is mandatory) and refuses any statement that lacks the iss/sub binding, with optional expected-issuer/subject matching. Signing uses the same algorithms as b.cose — classical ES256/384/512 + EdDSA (final COSE ids, interoperable today) plus ML-DSA-87 (PQC-forward). This is the issuer side of SCITT, buildable today on finalized RFCs; the transparency receipt (an inclusion proof from a transparency service, the COSE Receipts draft) is not yet shipped — a statement produced here is the input a transparency service registers, and the receipt format is the part still in flux. It opts in when COSE Receipts publishes. **Added:** *`b.scitt.signStatement(payload, opts)` / `b.scitt.verifyStatement(statement, opts)`* — `signStatement` produces a COSE_Sign1 whose protected CWT_Claims header (label 15) carries `iss` (`opts.issuer`) and `sub` (`opts.subject`), with the payload media type declared via `opts.contentType` and extra CWT claims allowed by integer label (iss/sub cannot be overridden through `opts.claims`). `verifyStatement` verifies the signature through `b.cose.verify` (passing `opts.algorithms` as the mandatory allowlist), then requires a CWT_Claims header with both `iss` and `sub` — a bare COSE_Sign1 with no such binding is refused with `scitt/missing-cwt-claims` — and enforces `expectedIssuer` / `expectedSubject` when given. Returns `{ payload, issuer, subject, cwtClaims, alg, protectedHeaders, unprotectedHeaders }`. Because the identity binding lives in the integrity-protected header it is covered by the signature and cannot be substituted without detection. **Changed:** *`b.cose.sign` accepts `protectedHeaders` and a media-type-string `contentType`* — `opts.protectedHeaders` (a numeric-keyed object or Map) adds extra integrity-protected header parameters — the CWT_Claims map (label 15) is the SCITT case. Label 1 (alg) is reserved and managed via `opts.alg`; setting it through `protectedHeaders` is refused with `cose/reserved-header`. `opts.contentType` now accepts a media-type string (RFC 9052 §3.1 tstr form, e.g. `"application/spdx+json"`) in addition to a CoAP Content-Format uint; a string was previously dropped.
|
|
12
|
+
|
|
11
13
|
- v0.12.36 (2026-05-24) — **`b.cose.encrypt0` / `b.cose.decrypt0` — COSE_Encrypt0 single-recipient AEAD (RFC 9052 §5.2).** Completes the COSE family with encryption alongside the v0.12.33 signing: COSE_Encrypt0 is the single-recipient AEAD container where the recipient already holds the symmetric key (direct mode). The default algorithm is ChaCha20/Poly1305 (COSE alg 24) — AES-GCM stays opt-in, since hard-rule #2 forbids AES-GCM as a default. The Enc_structure (`["Encrypt0", protected, external_aad]`) is bound as the AEAD associated data so the algorithm + any external context are authenticated, and the authentication tag is appended to the ciphertext per COSE. Composes the in-tree `b.cbor` codec and `node:crypto` AEAD. **Added:** *`b.cose.encrypt0(plaintext, opts)` / `b.cose.decrypt0(coseEncrypt0, opts)`* — `encrypt0` produces a tagged COSE_Encrypt0 with `alg` in the protected header and a random 12-byte IV in the unprotected header (label 5); `alg` is `"ChaCha20-Poly1305"` (default), `"A256GCM"`, or `"A128GCM"`, with the key length enforced (32 / 16 bytes). `decrypt0` reads the algorithm from the protected header (must be in the required `opts.algorithms` allowlist), reconstructs the Enc_structure as the AEAD AAD, and returns `{ plaintext, alg, protectedHeaders, unprotectedHeaders }`; a wrong key, tampered ciphertext, or `external_aad` mismatch fails AEAD authentication and is refused with `cose/decrypt-failed`. `external_aad` binds request context into the tag.
|
|
12
14
|
|
|
13
15
|
- v0.12.35 (2026-05-24) — **`b.eat` — Entity Attestation Token (RFC 9711) over `b.cwt`.** An EAT is the token a Relying Party asks a device or software entity to produce to prove what it is and what state it is in — a freshness nonce, a Universal Entity ID, OEM / hardware identifiers, debug status, software measurements, and nested submodule attestations. `b.eat` is the RFC 9711 profile over the v0.12.34 `b.cwt`: it maps the EAT claim names to their IANA CWT claim-key integer labels and adds the attestation-specific verification on top of the CWT signature + time checks. The central control is the verifier-nonce binding: when the Relying Party supplies a fresh `expectedNonce`, the token's `eat_nonce` (claim 10) must match it (constant-time compare) — without it a captured attestation replays forever. `verify` also enforces a debug-status policy (`requireDebugDisabled` refuses an `enabled` or absent `dbgstat`) and pins the `eat_profile`. RFC 9711 is a finalized standard; signing follows `b.cwt` / `b.cose` (ES256/384/512 + EdDSA interoperable today, ML-DSA-87 PQC-forward). **Added:** *`b.eat.sign(claims, opts)` / `b.eat.verify(eat, opts)`* — `sign` maps EAT claim names (`nonce`, `ueid`, `oemid`, `hwmodel`, `dbgstat`, `eat_profile`, `swname`/`swversion`, `measurements`, `submods`, …) to their RFC 9711 integer labels and accepts the `dbgstat` enum by name (`disabled-since-boot` → 2); standard CWT claims (`iss` / `exp` / …) pass through. `verify` returns `{ claims, raw, alg, protectedHeaders }` with the labels mapped back to friendly names and `dbgstat` decoded to its enum name. Attestation enforcement: `expectedNonce` requires a matching `eat_nonce` (refused `eat/nonce-mismatch`, missing `eat/nonce-missing` — `eat_nonce` may be a single byte string or an array for multiple verifiers), `requireDebugDisabled` refuses a non-disabled `dbgstat` (`eat/debug-not-disabled`), and `expectedProfile` pins `eat_profile`. The signature, algorithm allowlist, and `exp`/`nbf` checks delegate to `b.cwt` / `b.cose`. · *`b.cwt.sign` accepts a `Map`* — `b.cwt.sign` now takes either a plain object (string keys, standard claims mapped by name) or a `Map`, which preserves integer claim keys verbatim — profiles like `b.eat` resolve their claim names to integer labels and pass them through without the keys being stringified. The plain-object path is unchanged.
|
package/README.md
CHANGED
|
@@ -129,6 +129,7 @@ The framework bundles the surface a typical Node app reaches for. Every primitiv
|
|
|
129
129
|
- **COSE signing + encryption** — `b.cose` COSE_Sign1 sign/verify + COSE_Encrypt0 (RFC 9052) over `b.cbor`: classical ES256/384/512 + EdDSA (final COSE ids, interoperable today) plus ML-DSA-87 (PQC-forward, draft id); bounded + alg-allowlisted + crit-bypass-checked verification; single-recipient AEAD (ChaCha20/Poly1305 default, AES-GCM opt-in) with Enc_structure-bound AAD; the signed-statement substrate under SCITT / CWT / C2PA
|
|
130
130
|
- **CBOR Web Token** — `b.cwt` CWT sign/verify (RFC 8392) over `b.cose`: standard-claim mapping (iss/sub/aud/exp/nbf/iat/cti) + `exp`/`nbf` clock-skew enforcement + `iss`/`aud` matching; the CBOR-native JWT for constrained / IoT / FIDO / verifiable-credential contexts
|
|
131
131
|
- **Entity Attestation Token** — `b.eat` EAT sign/verify (RFC 9711) over `b.cwt`: device + software attestation claims (ueid / oemid / hwmodel / measurements / submods) with verifier-nonce freshness binding, `dbgstat` debug-status policy, and `eat_profile` pinning
|
|
132
|
+
- **SCITT signed statements** — `b.scitt` sign/verify a signed, attributable claim about an artifact (signed SBOM, build attestation, release approval) over `b.cose`: the issuer + subject bind in the integrity-protected CWT_Claims header (RFC 9597); verification refuses any statement missing the iss/sub binding. The issuer side, on finalized RFCs; the transparency receipt (COSE Receipts draft) opts in on publication
|
|
132
133
|
- **Document parsers** — `b.parsers` (XML / TOML / YAML / .env); `b.config` (schema-validated env)
|
|
133
134
|
- **File-type detection** — `b.fileType` magic-byte content classification with deny-on-upload categories (image / document / archive / executable / etc.)
|
|
134
135
|
### Content-safety gates
|
package/index.js
CHANGED
package/lib/cose.js
CHANGED
|
@@ -63,6 +63,7 @@ var HDR_ALG = 1;
|
|
|
63
63
|
var HDR_CRIT = 2; // header label: crit
|
|
64
64
|
var HDR_CONTENT_TYPE = 3; // header label: content type
|
|
65
65
|
var HDR_KID = 4; // header label: kid
|
|
66
|
+
var HDR_CWT_CLAIMS = 15; // allow:raw-byte-literal — RFC 9597 CWT Claims header label (carries SCITT iss/sub)
|
|
66
67
|
|
|
67
68
|
// COSE algorithm identifiers. ML-DSA-87 is a NON-FINAL requested
|
|
68
69
|
// assignment (draft-ietf-cose-dilithium) — pinned deliberately, re-open
|
|
@@ -83,7 +84,7 @@ var SIGNABLE = ["ML-DSA-87", "ES256", "ES384", "ES512", "EdDSA"];
|
|
|
83
84
|
|
|
84
85
|
// Header labels this verifier understands — a `crit` entry naming any
|
|
85
86
|
// other label is refused (RFC 9052 §3.1 crit-bypass defense).
|
|
86
|
-
var UNDERSTOOD_LABELS = [HDR_ALG, HDR_CRIT, HDR_CONTENT_TYPE, HDR_KID];
|
|
87
|
+
var UNDERSTOOD_LABELS = [HDR_ALG, HDR_CRIT, HDR_CONTENT_TYPE, HDR_KID, HDR_CWT_CLAIMS];
|
|
87
88
|
|
|
88
89
|
function _toKeyObject(key, kind) {
|
|
89
90
|
if (key && typeof key === "object" && typeof key.asymmetricKeyType === "string") return key;
|
|
@@ -138,9 +139,10 @@ function _toBeSigned(protectedBstr, externalAad, payload) {
|
|
|
138
139
|
* alg: string, // "ES256" | "ES384" | "ES512" | "EdDSA" | "ML-DSA-87"
|
|
139
140
|
* privateKey: object, // matching KeyObject or PEM
|
|
140
141
|
* kid?: string, // → unprotected header label 4
|
|
141
|
-
* contentType?: number,
|
|
142
|
+
* contentType?: number|string, // → protected header label 3 (CoAP Content-Format uint or media-type string)
|
|
142
143
|
* externalAad?: Buffer, // default empty — bound into the signature
|
|
143
144
|
* unprotectedHeaders?: object, // extra unprotected map entries (numeric keys)
|
|
145
|
+
* protectedHeaders?: object, // extra INTEGRITY-PROTECTED map entries (numeric keys); label 1 (alg) is reserved
|
|
144
146
|
* }
|
|
145
147
|
*
|
|
146
148
|
* @example
|
|
@@ -150,7 +152,7 @@ function _toBeSigned(protectedBstr, externalAad, payload) {
|
|
|
150
152
|
*/
|
|
151
153
|
async function sign(payload, opts) {
|
|
152
154
|
validateOpts.requireObject(opts, "cose.sign", CoseError);
|
|
153
|
-
validateOpts(opts, ["alg", "privateKey", "kid", "contentType", "externalAad", "unprotectedHeaders"], "cose.sign");
|
|
155
|
+
validateOpts(opts, ["alg", "privateKey", "kid", "contentType", "externalAad", "unprotectedHeaders", "protectedHeaders"], "cose.sign");
|
|
154
156
|
if (SIGNABLE.indexOf(opts.alg) === -1) {
|
|
155
157
|
throw new CoseError("cose/unsignable-alg",
|
|
156
158
|
"cose.sign: alg must be one of " + SIGNABLE.join(" / ") +
|
|
@@ -165,7 +167,31 @@ async function sign(payload, opts) {
|
|
|
165
167
|
|
|
166
168
|
var protMap = new Map();
|
|
167
169
|
protMap.set(HDR_ALG, algId);
|
|
168
|
-
|
|
170
|
+
// Content type (RFC 9052 §3.1): a uint (CoAP Content-Format) or a
|
|
171
|
+
// media-type string (tstr) — a SCITT signed statement declares its
|
|
172
|
+
// payload media type as a string here.
|
|
173
|
+
if (typeof opts.contentType === "number" || typeof opts.contentType === "string") {
|
|
174
|
+
protMap.set(HDR_CONTENT_TYPE, opts.contentType);
|
|
175
|
+
}
|
|
176
|
+
// Extra integrity-protected headers (e.g. CWT_Claims label 15 for a
|
|
177
|
+
// SCITT signed statement). alg (label 1) is managed via opts.alg and
|
|
178
|
+
// cannot be overridden here — a caller that needs a different alg
|
|
179
|
+
// names it in opts.alg.
|
|
180
|
+
if (opts.protectedHeaders && typeof opts.protectedHeaders === "object") {
|
|
181
|
+
var pk = opts.protectedHeaders instanceof Map
|
|
182
|
+
? Array.from(opts.protectedHeaders.keys())
|
|
183
|
+
: Object.keys(opts.protectedHeaders);
|
|
184
|
+
for (var pi = 0; pi < pk.length; pi++) {
|
|
185
|
+
var plabel = Number(pk[pi]);
|
|
186
|
+
if (plabel === HDR_ALG) {
|
|
187
|
+
throw new CoseError("cose/reserved-header",
|
|
188
|
+
"cose.sign: protectedHeaders must not set label 1 (alg) — pass opts.alg instead");
|
|
189
|
+
}
|
|
190
|
+
var pval = opts.protectedHeaders instanceof Map
|
|
191
|
+
? opts.protectedHeaders.get(pk[pi]) : opts.protectedHeaders[pk[pi]];
|
|
192
|
+
protMap.set(plabel, pval);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
169
195
|
var protectedBstr = cbor.encode(protMap);
|
|
170
196
|
|
|
171
197
|
var unprot = new Map();
|
package/lib/scitt.js
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module b.scitt
|
|
4
|
+
* @nav Crypto
|
|
5
|
+
* @title SCITT signed statements
|
|
6
|
+
*
|
|
7
|
+
* @intro
|
|
8
|
+
* A SCITT (Supply Chain Integrity, Transparency, and Trust) signed
|
|
9
|
+
* statement is a <code>b.cose</code> COSE_Sign1 that makes a signed,
|
|
10
|
+
* attributable claim <em>about an artifact</em> — a signed SBOM, a
|
|
11
|
+
* build attestation, a release approval. The artifact (or a hash /
|
|
12
|
+
* reference to it) is the payload; the issuer and the subject are
|
|
13
|
+
* carried in the integrity-protected <strong>CWT_Claims</strong>
|
|
14
|
+
* header (label 15, RFC 9597): <code>iss</code> (label 1) is who
|
|
15
|
+
* makes the statement, <code>sub</code> (label 2) is the artifact the
|
|
16
|
+
* statement is about. This module builds and verifies that envelope
|
|
17
|
+
* over <code>b.cose</code> + <code>b.cbor</code>.
|
|
18
|
+
*
|
|
19
|
+
* <code>b.scitt.signStatement(payload, opts)</code> produces the
|
|
20
|
+
* COSE_Sign1, placing <code>iss</code> / <code>sub</code> (plus any
|
|
21
|
+
* extra CWT claims) in the protected CWT_Claims header and declaring
|
|
22
|
+
* the payload media type as the COSE content type.
|
|
23
|
+
* <code>b.scitt.verifyStatement(statement, opts)</code> verifies the
|
|
24
|
+
* signature (delegating the mandatory algorithm allowlist to
|
|
25
|
+
* <code>b.cose.verify</code>), then enforces that a CWT_Claims header
|
|
26
|
+
* with both <code>iss</code> and <code>sub</code> is present —
|
|
27
|
+
* refusing a statement that omits the issuer/subject binding — and
|
|
28
|
+
* optionally checks them against expected values.
|
|
29
|
+
*
|
|
30
|
+
* The signing algorithms are exactly <code>b.cose</code>'s: the
|
|
31
|
+
* classical ES256/384/512 + EdDSA (final COSE ids, interoperable
|
|
32
|
+
* today) and ML-DSA-87 (PQC-forward, draft COSE id). Because the
|
|
33
|
+
* identity binding lives in the protected header it is covered by the
|
|
34
|
+
* signature and cannot be substituted without detection.
|
|
35
|
+
*
|
|
36
|
+
* <strong>Scope.</strong> This is the <em>issuer half</em> of SCITT —
|
|
37
|
+
* producing and verifying signed statements, which is buildable today
|
|
38
|
+
* on finalized RFCs (RFC 9052 COSE, RFC 9597 CWT_Claims header, RFC
|
|
39
|
+
* 8392 iss/sub). The <em>transparency receipt</em> (an inclusion proof
|
|
40
|
+
* from an append-only transparency service, COSE Receipts /
|
|
41
|
+
* draft-ietf-cose-merkle-tree-proofs) and the transparency-service
|
|
42
|
+
* registration protocol (draft-ietf-scitt-*) are deferred until those
|
|
43
|
+
* drafts publish — a signed statement produced here is the input a
|
|
44
|
+
* transparency service registers, and the receipt format is the part
|
|
45
|
+
* still in flux. Re-open on COSE-Receipts publication.
|
|
46
|
+
*
|
|
47
|
+
* @card
|
|
48
|
+
* SCITT signed statements (RFC 9052 COSE + RFC 9597 CWT_Claims) — a
|
|
49
|
+
* signed, issuer/subject-bound claim about an artifact (SBOM /
|
|
50
|
+
* attestation / approval). Composes b.cose; transparency receipts
|
|
51
|
+
* deferred to the COSE-Receipts draft.
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
var cose = require("./cose");
|
|
55
|
+
var validateOpts = require("./validate-opts");
|
|
56
|
+
var { defineClass } = require("./framework-error");
|
|
57
|
+
|
|
58
|
+
var ScittError = defineClass("ScittError", { alwaysPermanent: true });
|
|
59
|
+
|
|
60
|
+
// CWT_Claims header label (RFC 9597) and the two SCITT-required claim
|
|
61
|
+
// labels inside it (RFC 8392 §3.1.1): iss = who states, sub = about what.
|
|
62
|
+
var HDR_CWT_CLAIMS = 15;
|
|
63
|
+
var CLAIM_ISS = 1;
|
|
64
|
+
var CLAIM_SUB = 2;
|
|
65
|
+
|
|
66
|
+
function _requireNonEmptyString(v, name) {
|
|
67
|
+
if (typeof v !== "string" || v.length === 0) {
|
|
68
|
+
throw new ScittError("scitt/bad-" + name,
|
|
69
|
+
"scitt.signStatement: opts." + name + " is required and must be a non-empty string");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @primitive b.scitt.signStatement
|
|
75
|
+
* @signature b.scitt.signStatement(payload, opts)
|
|
76
|
+
* @since 0.12.37
|
|
77
|
+
* @status experimental
|
|
78
|
+
* @compliance soc2, cra
|
|
79
|
+
* @related b.scitt.verifyStatement, b.cose.sign
|
|
80
|
+
*
|
|
81
|
+
* Produce a SCITT signed statement: a COSE_Sign1 over
|
|
82
|
+
* <code>payload</code> (the artifact bytes, or a hash / reference to
|
|
83
|
+
* it) whose integrity-protected CWT_Claims header (label 15) binds the
|
|
84
|
+
* issuer (<code>iss</code>) and subject (<code>sub</code>). Declare the
|
|
85
|
+
* payload media type via <code>contentType</code> so a consumer knows
|
|
86
|
+
* how to interpret it.
|
|
87
|
+
*
|
|
88
|
+
* @opts
|
|
89
|
+
* {
|
|
90
|
+
* alg: string, // b.cose alg: "ES256" | … | "ML-DSA-87"
|
|
91
|
+
* privateKey: object, // matching KeyObject or PEM
|
|
92
|
+
* issuer: string, // → CWT_Claims iss (label 1) — who makes the statement
|
|
93
|
+
* subject: string, // → CWT_Claims sub (label 2) — the artifact the statement is about
|
|
94
|
+
* contentType?: number|string, // payload media type (e.g. "application/spdx+json")
|
|
95
|
+
* claims?: object, // extra CWT claims by integer label, merged into CWT_Claims
|
|
96
|
+
* kid?: string, // → unprotected header label 4
|
|
97
|
+
* externalAad?: Buffer, // bound into the signature
|
|
98
|
+
* }
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* var stmt = await b.scitt.signStatement(sbomBytes, {
|
|
102
|
+
* alg: "ES256", privateKey: issuerKey,
|
|
103
|
+
* issuer: "https://builder.example", subject: "pkg:npm/widget@1.2.3",
|
|
104
|
+
* contentType: "application/spdx+json",
|
|
105
|
+
* });
|
|
106
|
+
*/
|
|
107
|
+
async function signStatement(payload, opts) {
|
|
108
|
+
validateOpts.requireObject(opts, "scitt.signStatement", ScittError);
|
|
109
|
+
validateOpts(opts,
|
|
110
|
+
["alg", "privateKey", "issuer", "subject", "contentType", "claims", "kid", "externalAad"],
|
|
111
|
+
"scitt.signStatement");
|
|
112
|
+
_requireNonEmptyString(opts.issuer, "issuer");
|
|
113
|
+
_requireNonEmptyString(opts.subject, "subject");
|
|
114
|
+
|
|
115
|
+
var cwtClaims = new Map();
|
|
116
|
+
cwtClaims.set(CLAIM_ISS, opts.issuer);
|
|
117
|
+
cwtClaims.set(CLAIM_SUB, opts.subject);
|
|
118
|
+
// Extra CWT claims (e.g. iat = 6, a registration-policy claim) keyed
|
|
119
|
+
// by their integer label. iss / sub are managed via opts.issuer /
|
|
120
|
+
// opts.subject and cannot be overridden here.
|
|
121
|
+
if (opts.claims && typeof opts.claims === "object") {
|
|
122
|
+
var ck = opts.claims instanceof Map ? Array.from(opts.claims.keys()) : Object.keys(opts.claims);
|
|
123
|
+
for (var i = 0; i < ck.length; i++) {
|
|
124
|
+
var label = Number(ck[i]);
|
|
125
|
+
if (!Number.isInteger(label)) {
|
|
126
|
+
throw new ScittError("scitt/bad-claim-label",
|
|
127
|
+
"scitt.signStatement: claims keys must be integer CWT claim labels");
|
|
128
|
+
}
|
|
129
|
+
if (label === CLAIM_ISS || label === CLAIM_SUB) {
|
|
130
|
+
throw new ScittError("scitt/reserved-claim",
|
|
131
|
+
"scitt.signStatement: set iss / sub via opts.issuer / opts.subject, not opts.claims");
|
|
132
|
+
}
|
|
133
|
+
var val = opts.claims instanceof Map ? opts.claims.get(ck[i]) : opts.claims[ck[i]];
|
|
134
|
+
cwtClaims.set(label, val);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
var protectedHeaders = {};
|
|
139
|
+
protectedHeaders[HDR_CWT_CLAIMS] = cwtClaims;
|
|
140
|
+
|
|
141
|
+
return cose.sign(payload, {
|
|
142
|
+
alg: opts.alg,
|
|
143
|
+
privateKey: opts.privateKey,
|
|
144
|
+
kid: opts.kid,
|
|
145
|
+
contentType: opts.contentType,
|
|
146
|
+
externalAad: opts.externalAad,
|
|
147
|
+
protectedHeaders: protectedHeaders,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @primitive b.scitt.verifyStatement
|
|
153
|
+
* @signature b.scitt.verifyStatement(statement, opts)
|
|
154
|
+
* @since 0.12.37
|
|
155
|
+
* @status experimental
|
|
156
|
+
* @compliance soc2, cra
|
|
157
|
+
* @related b.scitt.signStatement, b.cose.verify
|
|
158
|
+
*
|
|
159
|
+
* Verify a SCITT signed statement and return its payload + identity
|
|
160
|
+
* binding. The COSE signature is checked through
|
|
161
|
+
* <code>b.cose.verify</code> (the algorithm allowlist is mandatory); a
|
|
162
|
+
* statement that does not carry a CWT_Claims header with both
|
|
163
|
+
* <code>iss</code> and <code>sub</code> is refused — that binding is
|
|
164
|
+
* what makes it a SCITT statement rather than a bare COSE_Sign1.
|
|
165
|
+
* <code>expectedIssuer</code> / <code>expectedSubject</code>, when
|
|
166
|
+
* given, must match.
|
|
167
|
+
*
|
|
168
|
+
* @opts
|
|
169
|
+
* {
|
|
170
|
+
* algorithms: string[], // required — accepted alg names (allowlist)
|
|
171
|
+
* publicKey?: object, // verification key (KeyObject / PEM)
|
|
172
|
+
* keyResolver?: function, // (protectedHeaders, unprotectedHeaders) → key
|
|
173
|
+
* expectedIssuer?: string, // require iss === this
|
|
174
|
+
* expectedSubject?: string, // require sub === this
|
|
175
|
+
* externalAad?: Buffer, // must match what was signed
|
|
176
|
+
* maxBytes?: number, // forwarded to b.cose.verify → b.cbor.decode
|
|
177
|
+
* maxDepth?: number,
|
|
178
|
+
* }
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* var out = await b.scitt.verifyStatement(stmt, {
|
|
182
|
+
* algorithms: ["ES256"], publicKey: issuerPub,
|
|
183
|
+
* expectedSubject: "pkg:npm/widget@1.2.3",
|
|
184
|
+
* });
|
|
185
|
+
* // → { payload: <Buffer>, issuer, subject, cwtClaims: Map, alg, protectedHeaders, unprotectedHeaders }
|
|
186
|
+
*/
|
|
187
|
+
async function verifyStatement(statement, opts) {
|
|
188
|
+
validateOpts.requireObject(opts, "scitt.verifyStatement", ScittError);
|
|
189
|
+
validateOpts(opts,
|
|
190
|
+
["algorithms", "publicKey", "keyResolver", "expectedIssuer", "expectedSubject",
|
|
191
|
+
"externalAad", "maxBytes", "maxDepth"],
|
|
192
|
+
"scitt.verifyStatement");
|
|
193
|
+
|
|
194
|
+
var out = await cose.verify(statement, {
|
|
195
|
+
algorithms: opts.algorithms,
|
|
196
|
+
publicKey: opts.publicKey,
|
|
197
|
+
keyResolver: opts.keyResolver,
|
|
198
|
+
externalAad: opts.externalAad,
|
|
199
|
+
maxBytes: opts.maxBytes,
|
|
200
|
+
maxDepth: opts.maxDepth,
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
var cwtClaims = out.protectedHeaders.get(HDR_CWT_CLAIMS);
|
|
204
|
+
if (!(cwtClaims instanceof Map)) {
|
|
205
|
+
throw new ScittError("scitt/missing-cwt-claims",
|
|
206
|
+
"scitt.verifyStatement: no CWT_Claims header (label 15) — not a SCITT signed statement");
|
|
207
|
+
}
|
|
208
|
+
var issuer = cwtClaims.get(CLAIM_ISS);
|
|
209
|
+
var subject = cwtClaims.get(CLAIM_SUB);
|
|
210
|
+
if (issuer === undefined || issuer === null) {
|
|
211
|
+
throw new ScittError("scitt/missing-issuer",
|
|
212
|
+
"scitt.verifyStatement: CWT_Claims has no iss (label 1)");
|
|
213
|
+
}
|
|
214
|
+
if (subject === undefined || subject === null) {
|
|
215
|
+
throw new ScittError("scitt/missing-subject",
|
|
216
|
+
"scitt.verifyStatement: CWT_Claims has no sub (label 2)");
|
|
217
|
+
}
|
|
218
|
+
if (opts.expectedIssuer !== undefined && issuer !== opts.expectedIssuer) {
|
|
219
|
+
throw new ScittError("scitt/issuer-mismatch",
|
|
220
|
+
"scitt.verifyStatement: iss does not match expectedIssuer");
|
|
221
|
+
}
|
|
222
|
+
if (opts.expectedSubject !== undefined && subject !== opts.expectedSubject) {
|
|
223
|
+
throw new ScittError("scitt/subject-mismatch",
|
|
224
|
+
"scitt.verifyStatement: sub does not match expectedSubject");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
payload: out.payload,
|
|
229
|
+
issuer: issuer,
|
|
230
|
+
subject: subject,
|
|
231
|
+
cwtClaims: cwtClaims,
|
|
232
|
+
alg: out.alg,
|
|
233
|
+
protectedHeaders: out.protectedHeaders,
|
|
234
|
+
unprotectedHeaders: out.unprotectedHeaders,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
module.exports = {
|
|
239
|
+
signStatement: signStatement,
|
|
240
|
+
verifyStatement: verifyStatement,
|
|
241
|
+
CWT_CLAIMS_LABEL: HDR_CWT_CLAIMS,
|
|
242
|
+
ScittError: ScittError,
|
|
243
|
+
};
|
package/package.json
CHANGED
package/sbom.cdx.json
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
|
|
3
3
|
"bomFormat": "CycloneDX",
|
|
4
4
|
"specVersion": "1.5",
|
|
5
|
-
"serialNumber": "urn:uuid:
|
|
5
|
+
"serialNumber": "urn:uuid:06167082-579c-4ea8-9d7e-30209b1be393",
|
|
6
6
|
"version": 1,
|
|
7
7
|
"metadata": {
|
|
8
|
-
"timestamp": "2026-05-
|
|
8
|
+
"timestamp": "2026-05-25T01:10:14.224Z",
|
|
9
9
|
"lifecycles": [
|
|
10
10
|
{
|
|
11
11
|
"phase": "build"
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
}
|
|
20
20
|
],
|
|
21
21
|
"component": {
|
|
22
|
-
"bom-ref": "@blamejs/core@0.12.
|
|
22
|
+
"bom-ref": "@blamejs/core@0.12.37",
|
|
23
23
|
"type": "application",
|
|
24
24
|
"name": "blamejs",
|
|
25
|
-
"version": "0.12.
|
|
25
|
+
"version": "0.12.37",
|
|
26
26
|
"scope": "required",
|
|
27
27
|
"author": "blamejs contributors",
|
|
28
28
|
"description": "The Node framework that owns its stack.",
|
|
29
|
-
"purl": "pkg:npm/%40blamejs/core@0.12.
|
|
29
|
+
"purl": "pkg:npm/%40blamejs/core@0.12.37",
|
|
30
30
|
"properties": [],
|
|
31
31
|
"externalReferences": [
|
|
32
32
|
{
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"components": [],
|
|
55
55
|
"dependencies": [
|
|
56
56
|
{
|
|
57
|
-
"ref": "@blamejs/core@0.12.
|
|
57
|
+
"ref": "@blamejs/core@0.12.37",
|
|
58
58
|
"dependsOn": []
|
|
59
59
|
}
|
|
60
60
|
]
|