@blamejs/core 0.12.42 → 0.12.44

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 CHANGED
@@ -8,6 +8,10 @@ upgrading across more than a few patches at a time.
8
8
 
9
9
  ## v0.12.x
10
10
 
11
+ - v0.12.44 (2026-05-25) — **`b.did` adds the did:jwk method.** Completes b.did's method set with did:jwk alongside did:key and did:web. did:jwk encodes a public key as a base64url-encoded JWK directly in the identifier, so resolution is deterministic and offline — the same self-contained shape as did:key but in JWK form, which is what OpenID4VCI and the EU Digital Identity Wallet ecosystem commonly use. b.did.resolve("did:jwk:…") returns the verification key as a node:crypto KeyObject (kty/crv allowlisted — Ed25519 / P-256 / P-384 / secp256k1 — so an unexpected key type is refused, not blindly imported), and b.did.keyToDid(publicKey, { method: "jwk" }) produces a did:jwk from a key (the private member is stripped). No new runtime dependency. **Added:** *did:jwk in `b.did.resolve` / `b.did.keyToDid`* — `resolve` decodes the base64url JWK (bounded via `b.safeJson`), allowlists its `kty`/`crv`, and returns `{ didDocument, verificationMethods: [{ publicKey, … }] }` with the key as a KeyObject ready for `b.vc` / `b.mdoc` / `b.scitt`; `keyToDid(publicKey, { method: "jwk" })` encodes a public key as `did:jwk:<base64url-JWK>` (default remains `did:key`). Malformed base64url-JSON is refused with `did/bad-jwk` and an unsupported key type with `did/unsupported-key`.
12
+
13
+ - v0.12.43 (2026-05-25) — **`b.crypto.selfTest` — FIPS 140-3-style power-on self-test for the crypto stack.** A power-on self-test over the framework's cryptographic primitives — the integrity check a FIPS 140-3-validated module runs at start-up. The hash / XOF checks are known-answer tests against NIST FIPS 202 published vectors (SHA3-256 / SHA3-512 / SHAKE256), so they confirm the framework's hashing matches the standard rather than merely itself; the AEAD check round-trips XChaCha20-Poly1305 and confirms a tampered ciphertext is rejected; and the post-quantum checks run a pairwise-consistency + negative test for ML-KEM-1024, ML-DSA-87, and SLH-DSA-SHAKE-256f (a fresh keypair must encaps/decaps and sign/verify consistently and reject a tampered signature — FIPS 140-3 §10.3 pairwise consistency, since the runtime exposes no seed-injection API for a fixed-seed KAT). selfTest returns a structured report and, by default, throws on any failure so a broken crypto stack fails closed at boot rather than silently producing bad output. Operators in regulated deployments can run it at start-up as a self-integrity gate. **Added:** *`b.crypto.selfTest(opts?)`* — Runs eight checks — SHA3-512 / SHA3-256 / SHAKE256 known-answer tests (NIST FIPS 202), HMAC-SHA3-512 determinism, XChaCha20-Poly1305 round-trip + tamper-detect, and ML-KEM-1024 / ML-DSA-87 / SLH-DSA-SHAKE-256f pairwise-consistency + negative tests — and returns `{ ok, results: [{ name, ok, detail? }], failures, ranAt }`. Throws `crypto/self-test-failed` (with the report attached) on any failure unless `opts.throwOnFailure` is `false`. Exercises the framework's real primitive paths so a self-test failure means the shipped crypto is broken.
14
+
11
15
  - v0.12.42 (2026-05-24) — **`b.vc.present` / `b.vc.verifyPresentation` — W3C Verifiable Presentations.** Completes b.vc with the holder side: a Verifiable Presentation is a holder-signed envelope wrapping one or more credentials, proving the presenter controls the key the credentials were issued to. b.vc.present builds and signs a VerifiablePresentation (each credential enveloped per VC-JOSE-COSE) as a compact JWS (vp+jwt) or COSE_Sign1 (application/vp+cose), matching b.vc.issue's algorithms; an optional nonce / audience is embedded in the signed presentation for holder-binding and replay protection. b.vc.verifyPresentation verifies the holder signature (auto-detected jose/cose, mandatory algorithm allowlist, JOSE none refused), the VCDM structure, and the embedded nonce / audience / expectedHolder when given, and — with verifyCredentials: true — verifies each enveloped credential through b.vc.verify and returns them. The holder is typically a DID, resolved to a key via b.did. Composes b.cose; no new runtime dependency. **Added:** *`b.vc.present(opts)` / `b.vc.verifyPresentation(secured, opts)`* — `present` wraps `opts.credentials` (secured VCs — compact-JWS strings or COSE_Sign1 bytes, each enveloped as an `EnvelopedVerifiableCredential` data: URI) in a `VerifiablePresentation` signed by the holder, with optional `nonce` / `audience` embedded for binding. `verifyPresentation` verifies the holder signature against the mandatory `opts.algorithms` allowlist (JOSE `none` always refused), re-checks the VCDM structure, enforces `expectedHolder` / `nonce` / `audience` when supplied, and with `verifyCredentials: true` verifies each enveloped credential through `b.vc.verify` (using `opts.credentialOpts`), returning `{ presentation, holder, credentials, securing, alg }`. The enveloped-credential count is bounded. A `vp+jwt` presentation is refused by `b.vc.verify` and a `vc+jwt` credential is refused by `verifyPresentation` — the media-type binding keeps the two surfaces distinct.
12
16
 
13
17
  - v0.12.41 (2026-05-24) — **`b.did` — W3C DID resolution (did:key + did:web) feeding the credential verifiers.** Resolve W3C Decentralized Identifiers (DID Core 1.0) to verification keys — the link that lets a credential's issuer be named by a DID rather than a raw key. Resolve the issuer DID of a b.vc / b.mdoc / b.scitt credential to a node:crypto KeyObject and hand it to the verifier. did:key encodes the public key in the identifier (multicodec + base58btc), so resolution is deterministic and offline — Ed25519, P-256, P-384, and secp256k1 round-trip; did:web places the DID document at an HTTPS URL derived from the identifier, with the network fetch left to the operator (the framework parses the operator-fetched document and extracts its verification methods, as publicKeyMultibase or publicKeyJwk). b.did.keyToDid encodes a KeyObject as a did:key (an issuer naming itself), b.did.parse splits the identifier (and returns the did:web URL to fetch), and b.did.resolve returns the document and verification keys. DID Core 1.0 is a W3C Recommendation; the method specs (did:key W3C CCG report, did:web DID method registry — EUDI-mandated) are deployed-stable. Composes node:crypto; no new runtime dependency. **Added:** *`b.did.resolve(did, opts?)` / `b.did.keyToDid(publicKey)` / `b.did.parse(did)`* — `resolve` returns `{ didDocument, verificationMethods: [{ id, controller, type, publicKey }] }` with each `publicKey` a `node:crypto` KeyObject ready for `b.vc.verify` / `b.mdoc.verifyIssuerSigned` / `b.scitt.verifyStatement`. did:key resolves deterministically and offline (base58btc + multicodec → Ed25519 raw key or EC compressed point, rebuilt via SPKI); did:web requires the operator to pass the fetched DID document as `opts.document` (the URL to GET is on `b.did.parse(did).url`) and the document `id` must match the requested DID. A publicKeyJwk in a DID document is imported only after its `kty`/`crv` is allowlisted (Ed25519 / P-256 / P-384 / secp256k1) — an unexpected key type from an untrusted document is refused, not blindly imported. `keyToDid` encodes an Ed25519 / P-256 / P-384 / secp256k1 KeyObject as a did:key; `parse` derives the did:web HTTPS URL (`host[:port][:path]` → `https://host/path/did.json`, or `/.well-known/did.json`). Unknown methods, malformed base58, unsupported multicodec codes, and unsupported key types are each refused.
package/README.md CHANGED
@@ -92,6 +92,7 @@ The framework bundles the surface a typical Node app reaches for. Every primitiv
92
92
  ### Crypto
93
93
 
94
94
  - **At-rest envelope** — envelope-versioned PQC (ML-KEM-1024 + P-384 hybrid, XChaCha20-Poly1305, SHAKE256); vault sealing (`b.crypto`, `b.vault`)
95
+ - **Power-on self-test** — `b.crypto.selfTest()` runs FIPS 140-3-style integrity checks: NIST FIPS 202 known-answer tests (SHA3-256/512, SHAKE256), AEAD round-trip + tamper-detect, and ML-KEM-1024 / ML-DSA-87 / SLH-DSA-SHAKE-256f pairwise-consistency + negative tests; fails closed (throws) on any mismatch
95
96
  - **Field-level + crypto-shred** — `b.cryptoField.eraseRow`; per-column data residency tagging + per-row keys (`K_row = HKDF(K_table, rowId)`) so erasing the per-row key makes WAL / replica residuals undecryptable (`b.cryptoField.declareColumnResidency`, `b.cryptoField.declarePerRowKey`)
96
97
  - **AAD-bound sealed columns** — AEAD tag tied to `(table, rowId, column, schemaVersion)`; copy-paste between rows or schema-version replay surfaces as refused decrypt (`b.vault.aad`)
97
98
  - **Signed webhooks + API encryption** — SLH-DSA-SHAKE-256f default; ML-DSA-65 opt-in; ECIES API encryption (`b.webhook`, `b.crypto`)
@@ -133,7 +134,7 @@ The framework bundles the surface a typical Node app reaches for. Every primitiv
133
134
  - **Trusted timestamping** — `b.tsa` RFC 3161 timestamp client: `buildRequest` a TimeStampReq, `parseResponse`, and `verifyToken` against your data — the message imprint, sent nonce, critical/sole `id-kp-timeStamping` EKU, and CMS signature are all checked, with optional certificate-chain verification. Timestamp a release artifact, audit checkpoint, or signed statement against any RFC 3161 TSA. Composes `b.cms` + the in-tree ASN.1 DER codec
134
135
  - **Verifiable Credentials** — `b.vc` W3C Verifiable Credentials Data Model 2.0 (VC-JOSE-COSE): `issue` / `verify` a signed credential, and `present` / `verifyPresentation` a holder-signed Verifiable Presentation wrapping credentials (with `nonce`/`audience` holder-binding) — as a compact JWS (`vc+jwt` / `vp+jwt`, ES256/384/512 + EdDSA) or a COSE_Sign1 (`vc+cose` / `vp+cose`, + ML-DSA-87) over `b.cose`. VCDM structural + `validFrom`/`validUntil` checks; the JOSE `none` algorithm is always refused. The W3C model, distinct from the IETF SD-JWT VC at `b.auth.sdJwtVc`
135
136
  - **Mobile credentials (mDL)** — `b.mdoc` ISO/IEC 18013-5 issuer-data verification: `verifyIssuerSigned` checks the COSE_Sign1 IssuerAuth (issuer cert from the `x5chain` header), the Mobile Security Object validity window, and every disclosed element's digest against the MSO `valueDigests` (the selective-disclosure integrity check), with optional issuer-chain verification. The ISO credential ecosystem alongside `b.vc` and `b.auth.sdJwtVc`. Composes `b.cose` + `b.cbor`
136
- - **Decentralized Identifiers** — `b.did` W3C DID resolution (DID Core 1.0): `resolve` a `did:key` (deterministic, offline — Ed25519 / P-256 / P-384 / secp256k1) or `did:web` (operator-fetched document) to `node:crypto` verification keys, so a credential's issuer DID resolves to the key that verifies it (`b.vc` / `b.mdoc` / `b.scitt`). `keyToDid` names a key as a `did:key`; document JWKs are kty/crv-allowlisted before import
137
+ - **Decentralized Identifiers** — `b.did` W3C DID resolution (DID Core 1.0): `resolve` a `did:key` / `did:jwk` (deterministic, offline — Ed25519 / P-256 / P-384 / secp256k1) or `did:web` (operator-fetched document) to `node:crypto` verification keys, so a credential's issuer DID resolves to the key that verifies it (`b.vc` / `b.mdoc` / `b.scitt`). `keyToDid` names a key as a `did:key` or `did:jwk`; document/JWK keys are kty/crv-allowlisted before import
137
138
  - **Document parsers** — `b.parsers` (XML / TOML / YAML / .env); `b.config` (schema-validated env)
138
139
  - **File-type detection** — `b.fileType` magic-byte content classification with deny-on-upload categories (image / document / archive / executable / etc.)
139
140
  ### Content-safety gates
package/lib/crypto.js CHANGED
@@ -62,6 +62,9 @@ var audit = lazyRequire(function () { return require("./audit"); });
62
62
  // loaded because safe-buffer.js itself imports b.crypto for
63
63
  // hex-compare helpers (circular).
64
64
  var safeBuffer = lazyRequire(function () { return require("./safe-buffer"); });
65
+ // pqc-software requires this module (b.crypto) — lazy-load to break the
66
+ // cycle. Only the power-on self-test needs it here.
67
+ var pqcSoftware = lazyRequire(function () { return require("./pqc-software"); });
65
68
 
66
69
  // Streaming-hash algorithm allowlist. Mirrors the framework's PQC-
67
70
  // first crypto policy: SHA3 / SHAKE family is the default surface;
@@ -1873,8 +1876,124 @@ var SUPPORTED_KEM_ALGORITHMS = Object.freeze([
1873
1876
  // var fixtures = require("blamejs/lib/_test/crypto-fixtures");
1874
1877
  // var blob = fixtures.mintLegacyEnvelope0xE1(plaintext, recipient);
1875
1878
 
1879
+ // ---- FIPS 140-3-style power-on self-test ----
1880
+ //
1881
+ // Known-answer tests (KATs) for the deterministic primitives — the
1882
+ // hash / XOF digests are NIST FIPS 202 published vectors, so this
1883
+ // confirms the framework's hashing matches the standard, not merely
1884
+ // itself. The PQC algorithms have no seed-injection API (node generates
1885
+ // the keypair randomness internally), so they get FIPS 140-3 §10.3
1886
+ // pairwise-consistency + negative tests (a fresh keypair must
1887
+ // sign->verify / encaps->decaps consistently, and a tampered signature
1888
+ // must be rejected) rather than a fixed-seed KAT.
1889
+ var KAT_SHA3_512_ABC = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0";
1890
+ var KAT_SHA3_256_ABC = "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532";
1891
+ var KAT_SHAKE256_ABC_32 = "483366601360a8771c6863080cc4114d8db44530f8f1e1ee4f94ea37e78b5739";
1892
+
1893
+ /**
1894
+ * @primitive b.crypto.selfTest
1895
+ * @signature b.crypto.selfTest(opts?)
1896
+ * @since 0.12.43
1897
+ * @status stable
1898
+ * @compliance soc2, hipaa, pci-dss
1899
+ * @related b.crypto.sha3Hash, b.crypto.encrypt
1900
+ *
1901
+ * Run a power-on self-test over the framework's cryptographic
1902
+ * primitives — the integrity check FIPS 140-3 requires of a validated
1903
+ * module. The hash / XOF checks are known-answer tests against NIST FIPS
1904
+ * 202 vectors (SHA3-256 / SHA3-512 / SHAKE256); the AEAD check
1905
+ * round-trips XChaCha20-Poly1305 and confirms a tampered ciphertext is
1906
+ * rejected; the post-quantum checks run a pairwise-consistency +
1907
+ * negative test for ML-KEM-1024, ML-DSA-87, and SLH-DSA-SHAKE-256f.
1908
+ * Returns a structured report and, by default, throws on any failure so
1909
+ * a broken crypto stack fails closed at boot rather than silently
1910
+ * producing bad output.
1911
+ *
1912
+ * @opts
1913
+ * {
1914
+ * throwOnFailure?: boolean, // default true — throw if any check fails
1915
+ * }
1916
+ *
1917
+ * @example
1918
+ * var report = b.crypto.selfTest();
1919
+ * // -> { ok: true, results: [ { name, ok }, ... ], failures: [], ranAt }
1920
+ */
1921
+ function selfTest(opts) {
1922
+ opts = opts || {};
1923
+ var results = [];
1924
+ function record(name, fn) {
1925
+ try { fn(); results.push({ name: name, ok: true }); }
1926
+ catch (e) { results.push({ name: name, ok: false, detail: (e && e.message) || String(e) }); }
1927
+ }
1928
+ function assert(cond, msg) { if (!cond) throw new Error(msg); }
1929
+
1930
+ record("SHA3-512 KAT (FIPS 202)", function () {
1931
+ assert(sha3Hash("abc") === KAT_SHA3_512_ABC, "SHA3-512(\"abc\") does not match the FIPS 202 vector");
1932
+ });
1933
+ record("SHA3-256 KAT (FIPS 202)", function () {
1934
+ assert(hash("abc", "sha3-256").toString("hex") === KAT_SHA3_256_ABC, "SHA3-256(\"abc\") does not match the FIPS 202 vector");
1935
+ });
1936
+ record("SHAKE256 KAT (FIPS 202)", function () {
1937
+ assert(hash("abc", "shake256", C.BYTES.bytes(32)).toString("hex") === KAT_SHAKE256_ABC_32, "SHAKE256(\"abc\") does not match the FIPS 202 vector");
1938
+ });
1939
+ record("HMAC-SHA3-512 determinism", function () {
1940
+ var k = Buffer.from("self-test-hmac-key", "utf8");
1941
+ assert(timingSafeEqual(hmacSha3(k, "abc"), hmacSha3(k, "abc")), "HMAC-SHA3-512 is not deterministic");
1942
+ assert(!timingSafeEqual(hmacSha3(k, "abc"), hmacSha3(k, "abd")), "HMAC-SHA3-512 collided on distinct inputs");
1943
+ });
1944
+ record("XChaCha20-Poly1305 round-trip + tamper-detect", function () {
1945
+ var key = generateBytes(C.BYTES.bytes(32));
1946
+ var pt = Buffer.from("blamejs crypto self-test plaintext", "utf8");
1947
+ var packed = encryptPacked(pt, key);
1948
+ assert(decryptPacked(packed, key).equals(pt), "AEAD round-trip did not recover the plaintext");
1949
+ var bad = Buffer.from(packed); bad[bad.length - 1] ^= 0xff;
1950
+ var rejected = false;
1951
+ try { decryptPacked(bad, key); } catch (_e) { rejected = true; }
1952
+ assert(rejected, "AEAD accepted a tampered ciphertext");
1953
+ });
1954
+
1955
+ // Post-quantum pairwise-consistency + negative tests. PQC is an
1956
+ // optional vendored dependency — a load failure surfaces as a failed
1957
+ // check rather than a silent skip.
1958
+ var pqc = pqcSoftware();
1959
+ record("ML-KEM-1024 encaps/decaps pairwise consistency", function () {
1960
+ var kp = pqc.ml_kem_1024.keygen();
1961
+ var enc = pqc.ml_kem_1024.encapsulate(kp.publicKey);
1962
+ var ss = pqc.ml_kem_1024.decapsulate(enc.cipherText, kp.secretKey);
1963
+ assert(timingSafeEqual(Buffer.from(ss), Buffer.from(enc.sharedSecret)), "ML-KEM-1024 decapsulated secret does not match");
1964
+ });
1965
+ record("ML-DSA-87 sign/verify + negative", function () {
1966
+ var kp = pqc.ml_dsa_87.keygen();
1967
+ var msg = Buffer.from("blamejs ML-DSA self-test", "utf8");
1968
+ var sig = pqc.ml_dsa_87.sign(msg, kp.secretKey);
1969
+ assert(pqc.ml_dsa_87.verify(sig, msg, kp.publicKey), "ML-DSA-87 rejected a valid signature");
1970
+ var bad = Buffer.from(sig); bad[0] ^= 0xff;
1971
+ assert(!pqc.ml_dsa_87.verify(bad, msg, kp.publicKey), "ML-DSA-87 accepted a tampered signature");
1972
+ });
1973
+ record("SLH-DSA-SHAKE-256f sign/verify + negative", function () {
1974
+ var kp = pqc.slh_dsa_shake_256f.keygen();
1975
+ var msg = Buffer.from("blamejs SLH-DSA self-test", "utf8");
1976
+ var sig = pqc.slh_dsa_shake_256f.sign(msg, kp.secretKey);
1977
+ assert(pqc.slh_dsa_shake_256f.verify(sig, msg, kp.publicKey), "SLH-DSA-SHAKE-256f rejected a valid signature");
1978
+ var bad = Buffer.from(sig); bad[0] ^= 0xff;
1979
+ assert(!pqc.slh_dsa_shake_256f.verify(bad, msg, kp.publicKey), "SLH-DSA-SHAKE-256f accepted a tampered signature");
1980
+ });
1981
+
1982
+ var failures = results.filter(function (r) { return !r.ok; });
1983
+ var report = { ok: failures.length === 0, results: results, failures: failures, ranAt: new Date().toISOString() };
1984
+ if (failures.length && opts.throwOnFailure !== false) {
1985
+ var err = new Error("crypto.selfTest: " + failures.length + " self-test(s) failed: " +
1986
+ failures.map(function (f) { return f.name; }).join("; "));
1987
+ err.code = "crypto/self-test-failed";
1988
+ err.report = report;
1989
+ throw err;
1990
+ }
1991
+ return report;
1992
+ }
1993
+
1876
1994
  module.exports = {
1877
1995
  sri: sri,
1996
+ selfTest: selfTest,
1878
1997
  // Hashing
1879
1998
  sha3Hash: sha3Hash,
1880
1999
  hmacSha3: hmacSha3,
package/lib/did.js CHANGED
@@ -12,14 +12,16 @@
12
12
  * <code>b.scitt</code> credential to a <code>node:crypto</code>
13
13
  * KeyObject, then hand that key to the verifier.
14
14
  *
15
- * Two methods are supported. <strong>did:key</strong> encodes a public
16
- * key directly in the identifier (multicodec + base58btc multibase),
17
- * so resolution is deterministic and offline Ed25519, P-256, P-384,
18
- * and secp256k1 keys round-trip. <strong>did:web</strong> places the
19
- * DID document at an HTTPS URL derived from the identifier; the network
20
- * fetch is the operator's to make (the same operator-supplied-input
21
- * stance as the rest of the framework), and <code>resolve</code> takes
22
- * the fetched document and extracts its verification methods.
15
+ * Three methods are supported. <strong>did:key</strong> encodes a
16
+ * public key directly in the identifier (multicodec + base58btc
17
+ * multibase) and <strong>did:jwk</strong> encodes it as a base64url
18
+ * public JWK both resolve deterministically and offline (Ed25519,
19
+ * P-256, P-384, and secp256k1 round-trip). <strong>did:web</strong>
20
+ * places the DID document at an HTTPS URL derived from the identifier;
21
+ * the network fetch is the operator's to make (the same
22
+ * operator-supplied-input stance as the rest of the framework), and
23
+ * <code>resolve</code> takes the fetched document and extracts its
24
+ * verification methods.
23
25
  *
24
26
  * <code>b.did.keyToDid(publicKey)</code> produces a did:key from a
25
27
  * KeyObject (an issuer naming itself); <code>b.did.parse(did)</code>
@@ -36,13 +38,15 @@
36
38
  * deployed and interoperable today; pin the dependency deliberately.
37
39
  *
38
40
  * @card
39
- * W3C DID resolution (did:key + did:web) → verification KeyObjects for
40
- * the credential verifiers. did:key is deterministic + offline
41
- * (Ed25519 / P-256 / P-384 / secp256k1); did:web parses an
42
- * operator-fetched DID document. Composes node:crypto; no new dep.
41
+ * W3C DID resolution (did:key + did:jwk + did:web) → verification
42
+ * KeyObjects for the credential verifiers. did:key + did:jwk are
43
+ * deterministic + offline (Ed25519 / P-256 / P-384 / secp256k1);
44
+ * did:web parses an operator-fetched DID document. Composes
45
+ * node:crypto; no new dep.
43
46
  */
44
47
 
45
48
  var nodeCrypto = require("node:crypto");
49
+ var safeJson = require("./safe-json");
46
50
  var validateOpts = require("./validate-opts");
47
51
  var { defineClass } = require("./framework-error");
48
52
 
@@ -55,6 +59,7 @@ var B58_MAP = (function () {
55
59
  return m;
56
60
  })();
57
61
  var MAX_MULTIBASE_CHARS = 1024; // allow:raw-byte-literal — bounded did:key multibase length (DoS cap)
62
+ var MAX_JWK_B64_CHARS = 8192; // allow:raw-byte-literal — bounded did:jwk encoded-JWK length (DoS cap)
58
63
 
59
64
  // multicodec public-key codes (unsigned-varint) → curve descriptor.
60
65
  // keyLen is the multicodec payload: Ed25519 raw 32; EC compressed point.
@@ -224,23 +229,43 @@ function _didWebUrl(id) {
224
229
 
225
230
  /**
226
231
  * @primitive b.did.keyToDid
227
- * @signature b.did.keyToDid(publicKey)
232
+ * @signature b.did.keyToDid(publicKey, opts?)
228
233
  * @since 0.12.41
229
234
  * @status experimental
230
235
  * @related b.did.resolve
231
236
  *
232
237
  * Encode a public key (a <code>node:crypto</code> KeyObject or PEM) as a
233
- * <code>did:key</code> — the inverse of resolution, for an issuer that
234
- * names itself by its key. Ed25519, P-256, P-384, and secp256k1 are
235
- * supported.
238
+ * DID — the inverse of resolution, for an issuer that names itself by
239
+ * its key. Defaults to <code>did:key</code> (multicodec + base58btc);
240
+ * pass <code>opts.method = "jwk"</code> for <code>did:jwk</code>
241
+ * (base64url-encoded public JWK). Ed25519, P-256, P-384, and secp256k1
242
+ * are supported.
243
+ *
244
+ * @opts
245
+ * {
246
+ * method: string, // "key" (default) | "jwk"
247
+ * }
236
248
  *
237
249
  * @example
238
- * var did = b.did.keyToDid(issuerPublicKey); // → "did:key:z6Mk…"
250
+ * var did = b.did.keyToDid(issuerPublicKey); // → "did:key:z6Mk…"
251
+ * var dj = b.did.keyToDid(issuerPublicKey, { method: "jwk" }); // → "did:jwk:eyJr…"
239
252
  */
240
- function keyToDid(publicKey) {
253
+ function keyToDid(publicKey, opts) {
241
254
  var key = (publicKey && typeof publicKey === "object" && publicKey.asymmetricKeyType)
242
255
  ? publicKey : nodeCrypto.createPublicKey(publicKey);
243
256
  var jwk = key.export({ format: "jwk" });
257
+ if (opts && opts.method === "jwk") {
258
+ // did:jwk — base64url(UTF-8(JSON of the PUBLIC JWK)). Strip any
259
+ // private member defensively (a public KeyObject has none, but a
260
+ // caller could pass a private key by mistake).
261
+ var pub = {};
262
+ Object.keys(jwk).forEach(function (k) { if (k !== "d") pub[k] = jwk[k]; });
263
+ // Gate on the same kty/crv allowlist resolution enforces, so a
264
+ // produced did:jwk always round-trips (no generate-succeeds /
265
+ // resolve-fails RSA-style identifiers).
266
+ _jwkToKey(pub);
267
+ return "did:jwk:" + Buffer.from(JSON.stringify(pub), "utf8").toString("base64url");
268
+ }
244
269
  var code, payload;
245
270
  if (jwk.kty === "OKP" && jwk.crv === "Ed25519") {
246
271
  code = NAME_TO_CODE["Ed25519"];
@@ -266,8 +291,8 @@ function keyToDid(publicKey) {
266
291
  *
267
292
  * Resolve a DID to its document and verification methods (each with a
268
293
  * <code>node:crypto</code> public KeyObject ready for a verifier).
269
- * <code>did:key</code> resolves deterministically and offline.
270
- * <code>did:web</code> requires the operator to supply the fetched DID
294
+ * <code>did:key</code> and <code>did:jwk</code> resolve deterministically
295
+ * and offline. <code>did:web</code> requires the operator to supply the fetched DID
271
296
  * document as <code>opts.document</code> (the network fetch is the
272
297
  * operator's; the URL to fetch is on <code>b.did.parse(did).url</code>).
273
298
  *
@@ -304,6 +329,30 @@ function resolve(did, opts) {
304
329
  return { didDocument: doc, verificationMethods: [vm] };
305
330
  }
306
331
 
332
+ if (parsed.method === "jwk") {
333
+ if (parsed.id.length > MAX_JWK_B64_CHARS) {
334
+ throw new DidError("did/too-long", "did:jwk: encoded JWK exceeds the " + MAX_JWK_B64_CHARS + "-char cap");
335
+ }
336
+ var jwkJson = Buffer.from(parsed.id, "base64url").toString("utf8");
337
+ var jwk;
338
+ try { jwk = safeJson.parse(jwkJson, { maxBytes: MAX_JWK_B64_CHARS }); } catch (_e) {
339
+ throw new DidError("did/bad-jwk", "did:jwk: method-specific id is not base64url-encoded JSON");
340
+ }
341
+ if (!jwk || typeof jwk !== "object" || Array.isArray(jwk)) {
342
+ throw new DidError("did/bad-jwk", "did:jwk: decoded value is not a JWK object");
343
+ }
344
+ var jwkKey = _jwkToKey(jwk); // kty/crv allowlisted
345
+ var jwkVmId = did + "#0";
346
+ var jwkVm = { id: jwkVmId, controller: did, type: "JsonWebKey2020", publicKey: jwkKey };
347
+ var jwkDoc = {
348
+ "@context": ["https://www.w3.org/ns/did/v1"],
349
+ id: did,
350
+ verificationMethod: [{ id: jwkVmId, controller: did, type: "JsonWebKey2020", publicKeyJwk: jwk }],
351
+ assertionMethod: [jwkVmId], authentication: [jwkVmId],
352
+ };
353
+ return { didDocument: jwkDoc, verificationMethods: [jwkVm] };
354
+ }
355
+
307
356
  if (parsed.method === "web") {
308
357
  if (!opts.document || typeof opts.document !== "object") {
309
358
  throw new DidError("did/document-required",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blamejs/core",
3
- "version": "0.12.42",
3
+ "version": "0.12.44",
4
4
  "description": "The Node framework that owns its stack.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "blamejs contributors",
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:313dd43c-bb3f-4c16-a801-2af63046b56f",
5
+ "serialNumber": "urn:uuid:645939ff-86bb-46c2-a5af-52ac1e920cb5",
6
6
  "version": 1,
7
7
  "metadata": {
8
- "timestamp": "2026-05-25T06:48:54.423Z",
8
+ "timestamp": "2026-05-25T08:20:43.623Z",
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.42",
22
+ "bom-ref": "@blamejs/core@0.12.44",
23
23
  "type": "application",
24
24
  "name": "blamejs",
25
- "version": "0.12.42",
25
+ "version": "0.12.44",
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.42",
29
+ "purl": "pkg:npm/%40blamejs/core@0.12.44",
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.42",
57
+ "ref": "@blamejs/core@0.12.44",
58
58
  "dependsOn": []
59
59
  }
60
60
  ]