@agenticprimitives/privacy-credentials 0.0.0-alpha.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Agentic Trust Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # @agenticprimitives/privacy-credentials
2
+
3
+ **The privacy presentation layer** — turns vault-held credentials into selectively-disclosed,
4
+ pairwise-pseudonymous presentations a verifier can check without learning more than the
5
+ transaction requires.
6
+
7
+ Spec: [`specs/305-privacy-credentials.md`](../../specs/305-privacy-credentials.md) · Issuer keys:
8
+ [`specs/304-issuer-key-facets.md`](../../specs/304-issuer-key-facets.md) · Doctrine: the ADR-0010
9
+ amendment ("the Smart Agent address is the accountability root, not the default presentation
10
+ identifier") and the [alignment audit](../../docs/architecture/acting-on-behalf-alignment-audit.md)
11
+ §6.2 (eIDAS 2.0 Art 5a makes selective disclosure + unlinkability EU market-access requirements).
12
+
13
+ ## What it does
14
+
15
+ ```ts
16
+ import {
17
+ issueSdJwt, presentSdJwt, verifyPresentation,
18
+ generateHolderSecret, pairwiseHandle,
19
+ createIssuerKeyResolver,
20
+ } from '@agenticprimitives/privacy-credentials';
21
+
22
+ // ISSUER (an org SA with a spec-304 facet key; sign = injected KMS ES256):
23
+ const credential = await issueSdJwt({
24
+ issuer: orgCaip10, keyId: 'issuer-key:sd-jwt:2026-07', vct: 'ap:procurement-delegate',
25
+ sdClaims: { authorizedRole: 'procurement.delegate', counterpartyClass: 'approved.vendor' },
26
+ holderPublicKeyJwk, sign: kmsEs256Signer,
27
+ });
28
+ // → into the holder's vault.
29
+
30
+ // HOLDER (presents to ONE verifier, revealing ONE claim):
31
+ const handle = await pairwiseHandle(holderSecret, 'vendor.example'); // stable HERE, unlinkable elsewhere
32
+ const payload = await presentSdJwt({
33
+ sdJwt: credential, discloseClaims: ['authorizedRole'],
34
+ audience: request.audience, nonce: request.nonce, holderSign,
35
+ });
36
+
37
+ // VERIFIER (no AP runtime needed — chain checks injected):
38
+ const resolveIssuerKey = createIssuerKeyResolver(lookupSignedFacet, {
39
+ verifySaSignature, // UniversalSignatureValidator read
40
+ checkAttestation, // AttestationRegistry liveness read
41
+ });
42
+ const res = await verifyPresentation(
43
+ { type: 'PrivatePresentationV1', suite: 'sd-jwt', relationshipHandle: handle, payload },
44
+ request,
45
+ { resolveIssuerKey },
46
+ );
47
+ // res.claims === { authorizedRole: 'procurement.delegate' } — and nothing else.
48
+ ```
49
+
50
+ The verifier learns: the claim it asked for, that a custody-governed Smart Agent issued it (via
51
+ the spec-304 facet binding), and that the presenter holds the credential (key binding bound to
52
+ this audience + nonce). It does **not** learn the holder's SA, the other claims, or anything that
53
+ links this presentation to the same holder's presentations elsewhere.
54
+
55
+ ## Design rules
56
+
57
+ - **One suite per proof request** (ADR-0013): `sd-jwt` today; `bbs-bls12381-g2`, `anoncreds-v1`,
58
+ `zk-predicate` are reserved enum slots that reject, never a fallback ladder.
59
+ - **Predicates reject on sd-jwt** — the suite can't prove `amount <= limit`; refusing beats
60
+ silently revealing the field. Predicate proofs arrive with the W2+ suites.
61
+ - **Issuer facet first**: a revoked or unresolvable spec-304 facet fails the whole presentation.
62
+ - Dependency-free (WebCrypto only — Node ≥ 20 and workerd); chain reads and KMS signing are
63
+ injected ports.
64
+
65
+ ## Status
66
+
67
+ `w1-sdjwt-pseudonyms` — port types, pairwise pseudonyms, the self-contained SD-JWT VC suite,
68
+ spec-304 facet verification, 11-test suite (unlinkability, forgery, replay, revoked-facet,
69
+ claim-exactness). W2: demo wiring + BBS decision + decoy digests + credential status lists.
@@ -0,0 +1,9 @@
1
+ export declare const PACKAGE_NAME = "@agenticprimitives/privacy-credentials";
2
+ export declare const PACKAGE_STATUS = "w1-sdjwt-pseudonyms";
3
+ export declare const SPEC_REF = "specs/305-privacy-credentials.md";
4
+ export type { Hex, Sha256, PresentationSuite, PredicateClaimV1, ProofRequestV1, PrivatePresentationV1, PresentationVerifyReason, PresentationVerifyResult, IssuerKeyFacetV1, SignedIssuerKeyFacetV1, IssuerKeyBindingChecks, IssuerKeyResolveResult, IssuerKeyResolver, SuiteSigner, } from './types.js';
5
+ export { generateHolderSecret, pairwiseHandle } from './pseudonym.js';
6
+ export { b64u, b64uDecode, generateEs256KeyPair, es256Signer, issueSdJwt, presentSdJwt, verifySdJwtPresentation, type IssueSdJwtInput, type PresentSdJwtInput, type VerifySdJwtInput, } from './sdjwt.js';
7
+ export { canonicalize, computeFacetHash, verifyIssuerKeyBinding, createIssuerKeyResolver, } from './issuer-key.js';
8
+ export { validateProofRequest, verifyPresentation, type ProofRequestValidation } from './request.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,YAAY,2CAA2C,CAAC;AACrE,eAAO,MAAM,cAAc,wBAAwB,CAAC;AACpD,eAAO,MAAM,QAAQ,qCAAqC,CAAC;AAE3D,YAAY,EACV,GAAG,EACH,MAAM,EACN,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,wBAAwB,EACxB,wBAAwB,EACxB,gBAAgB,EAChB,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,EACjB,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEtE,OAAO,EACL,IAAI,EACJ,UAAU,EACV,oBAAoB,EACpB,WAAW,EACX,UAAU,EACV,YAAY,EACZ,uBAAuB,EACvB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,GACtB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,KAAK,sBAAsB,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ // @agenticprimitives/privacy-credentials — spec 305 W1 (G-6).
2
+ // The privacy presentation layer: vault-held credentials → selectively-
3
+ // disclosed, pairwise-pseudonymous presentations. One suite per request,
4
+ // never a fallback ladder. Issuer keys are custody-rotated SA facets
5
+ // (spec 304); NEVER a raw person SA in a subject or presentation.
6
+ export const PACKAGE_NAME = '@agenticprimitives/privacy-credentials';
7
+ export const PACKAGE_STATUS = 'w1-sdjwt-pseudonyms';
8
+ export const SPEC_REF = 'specs/305-privacy-credentials.md';
9
+ export { generateHolderSecret, pairwiseHandle } from './pseudonym.js';
10
+ export { b64u, b64uDecode, generateEs256KeyPair, es256Signer, issueSdJwt, presentSdJwt, verifySdJwtPresentation, } from './sdjwt.js';
11
+ export { canonicalize, computeFacetHash, verifyIssuerKeyBinding, createIssuerKeyResolver, } from './issuer-key.js';
12
+ export { validateProofRequest, verifyPresentation } from './request.js';
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,wEAAwE;AACxE,yEAAyE;AACzE,qEAAqE;AACrE,kEAAkE;AAElE,MAAM,CAAC,MAAM,YAAY,GAAG,wCAAwC,CAAC;AACrE,MAAM,CAAC,MAAM,cAAc,GAAG,qBAAqB,CAAC;AACpD,MAAM,CAAC,MAAM,QAAQ,GAAG,kCAAkC,CAAC;AAmB3D,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEtE,OAAO,EACL,IAAI,EACJ,UAAU,EACV,oBAAoB,EACpB,WAAW,EACX,UAAU,EACV,YAAY,EACZ,uBAAuB,GAIxB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAA+B,MAAM,cAAc,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { IssuerKeyBindingChecks, IssuerKeyFacetV1, IssuerKeyResolveResult, IssuerKeyResolver, Sha256, SignedIssuerKeyFacetV1 } from './types.js';
2
+ /** Deterministic JSON (sorted keys, undefined dropped) — the repo-wide canonical form. */
3
+ export declare function canonicalize(v: unknown): string;
4
+ export declare function computeFacetHash(facet: IssuerKeyFacetV1): Promise<Sha256>;
5
+ /**
6
+ * Spec 304 §verification, steps 1–3 (fail-closed): recompute the facet hash,
7
+ * verify the SA signature over it, confirm attestation liveness. Step 4 —
8
+ * the format-native signature — is the suite's job (sd-jwt does it against
9
+ * `facet.publicKeyJwk`).
10
+ */
11
+ export declare function verifyIssuerKeyBinding(doc: SignedIssuerKeyFacetV1, checks: IssuerKeyBindingChecks): Promise<IssuerKeyResolveResult>;
12
+ /** Build an IssuerKeyResolver over a keyId → signed-facet lookup (agent card
13
+ * claim slot, cache, …) with the binding fully re-verified per resolve. */
14
+ export declare function createIssuerKeyResolver(lookup: (keyId: string) => Promise<SignedIssuerKeyFacetV1 | null>, checks: IssuerKeyBindingChecks): IssuerKeyResolver;
15
+ //# sourceMappingURL=issuer-key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issuer-key.d.ts","sourceRoot":"","sources":["../src/issuer-key.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,sBAAsB,EACtB,gBAAgB,EAChB,sBAAsB,EACtB,iBAAiB,EACjB,MAAM,EACN,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAIpB,0FAA0F;AAC1F,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAS/C;AAED,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAS/E;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,sBAAsB,EAC3B,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,sBAAsB,CAAC,CAgBjC;AAED;4EAC4E;AAC5E,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,EACjE,MAAM,EAAE,sBAAsB,GAC7B,iBAAiB,CAOnB"}
@@ -0,0 +1,65 @@
1
+ // Spec 304 W1 — issuer-key facet digest + injected binding verification.
2
+ // The facet document is SA-signed (ERC-1271/6492) and anchored on the
3
+ // AttestationRegistry; both checks are INJECTED chain reads — this package
4
+ // never picks an RPC mechanism (INV-305-5 / ADR-0013).
5
+ const enc = new TextEncoder();
6
+ /** Deterministic JSON (sorted keys, undefined dropped) — the repo-wide canonical form. */
7
+ export function canonicalize(v) {
8
+ if (v === null || typeof v !== 'object')
9
+ return JSON.stringify(v) ?? 'null';
10
+ if (Array.isArray(v))
11
+ return `[${v.map(canonicalize).join(',')}]`;
12
+ const o = v;
13
+ return `{${Object.keys(o)
14
+ .sort()
15
+ .filter((k) => o[k] !== undefined)
16
+ .map((k) => `${JSON.stringify(k)}:${canonicalize(o[k])}`)
17
+ .join(',')}}`;
18
+ }
19
+ export async function computeFacetHash(facet) {
20
+ const digest = await globalThis.crypto.subtle.digest('SHA-256', enc.encode(canonicalize(facet)));
21
+ const hex = Array.from(new Uint8Array(digest))
22
+ .map((b) => b.toString(16).padStart(2, '0'))
23
+ .join('');
24
+ return `sha256:${hex}`;
25
+ }
26
+ /**
27
+ * Spec 304 §verification, steps 1–3 (fail-closed): recompute the facet hash,
28
+ * verify the SA signature over it, confirm attestation liveness. Step 4 —
29
+ * the format-native signature — is the suite's job (sd-jwt does it against
30
+ * `facet.publicKeyJwk`).
31
+ */
32
+ export async function verifyIssuerKeyBinding(doc, checks) {
33
+ if (doc.facet.type !== 'IssuerKeyFacetV1')
34
+ return { ok: false, reason: 'issuer_binding_invalid' };
35
+ const recomputed = await computeFacetHash(doc.facet);
36
+ if (recomputed !== doc.facetHash)
37
+ return { ok: false, reason: 'issuer_binding_invalid' };
38
+ const sigOk = await checks.verifySaSignature({
39
+ signer: doc.facet.subjectAgent,
40
+ facetHash: doc.facetHash,
41
+ signature: doc.signature,
42
+ });
43
+ if (!sigOk)
44
+ return { ok: false, reason: 'issuer_binding_invalid' };
45
+ const anchored = await checks.checkAttestation({
46
+ subjectAgent: doc.facet.subjectAgent,
47
+ facetHash: doc.facetHash,
48
+ });
49
+ if (!anchored)
50
+ return { ok: false, reason: 'issuer_binding_invalid' };
51
+ return { ok: true, facet: doc.facet };
52
+ }
53
+ /** Build an IssuerKeyResolver over a keyId → signed-facet lookup (agent card
54
+ * claim slot, cache, …) with the binding fully re-verified per resolve. */
55
+ export function createIssuerKeyResolver(lookup, checks) {
56
+ return async (keyId) => {
57
+ const doc = await lookup(keyId);
58
+ if (!doc)
59
+ return { ok: false, reason: 'issuer_key_unresolved' };
60
+ if (doc.facet.keyId !== keyId)
61
+ return { ok: false, reason: 'issuer_binding_invalid' };
62
+ return verifyIssuerKeyBinding(doc, checks);
63
+ };
64
+ }
65
+ //# sourceMappingURL=issuer-key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issuer-key.js","sourceRoot":"","sources":["../src/issuer-key.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,sEAAsE;AACtE,2EAA2E;AAC3E,uDAAuD;AAWvD,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;AAE9B,0FAA0F;AAC1F,MAAM,UAAU,YAAY,CAAC,CAAU;IACrC,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC;IAC5E,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAClE,MAAM,CAAC,GAAG,CAA4B,CAAC;IACvC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;SACtB,IAAI,EAAE;SACN,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;SACjC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;SACxD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAClB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,KAAuB;IAC5D,MAAM,MAAM,GAAG,MAAM,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,YAAY;QACpC,SAAS,EAAE,GAAG,CAAC,SAAS;KACzB,CAAC,CAAC;IACH,IAAI,CAAC,QAAQ;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,wBAAwB,EAAE,CAAC;IACtE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC;AACxC,CAAC;AAED;4EAC4E;AAC5E,MAAM,UAAU,uBAAuB,CACrC,MAAiE,EACjE,MAA8B;IAE9B,OAAO,KAAK,EAAE,KAAK,EAAE,EAAE;QACrB,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC;QAChC,IAAI,CAAC,GAAG;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,uBAAuB,EAAE,CAAC;QAChE,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,KAAK,KAAK;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,wBAAwB,EAAE,CAAC;QACtF,OAAO,sBAAsB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { Hex } from './types.js';
2
+ /** Fresh 32-byte holder secret — mint once per holder, store in the vault. */
3
+ export declare function generateHolderSecret(): Hex;
4
+ /**
5
+ * The pairwise relationship handle for (holder, verifier):
6
+ * `HMAC-SHA256(holderSecret, verifierId)` truncated to an address-shaped
7
+ * 20-byte hex. Deterministic within the relationship (a verifier sees ONE
8
+ * stable pseudonym), unlinkable across verifiers (INV-305-1), and
9
+ * underivable without the vault-held secret.
10
+ */
11
+ export declare function pairwiseHandle(holderSecret: Hex, verifierId: string): Promise<Hex>;
12
+ //# sourceMappingURL=pseudonym.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pseudonym.d.ts","sourceRoot":"","sources":["../src/pseudonym.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAiBtC,8EAA8E;AAC9E,wBAAgB,oBAAoB,IAAI,GAAG,CAI1C;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,YAAY,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAUxF"}
@@ -0,0 +1,39 @@
1
+ // Mode-2 pairwise pseudonyms (spec 305; ADR-0010 amendment). Port of
2
+ // smart-agent's anti-correlation `pairwiseHandle(holderWalletId, verifierId)`,
3
+ // keyed (HMAC) so a handle is only derivable by the secret holder.
4
+ //
5
+ // The holderSecret is VAULT-RESIDENT (the holder's own vault; never on-chain,
6
+ // never in a credential). Binding holderSecret → SA is vault evidence opened
7
+ // only under a dispute rule — routine counterparties see the handle alone.
8
+ const enc = new TextEncoder();
9
+ function toHex(bytes) {
10
+ return Array.from(bytes)
11
+ .map((b) => b.toString(16).padStart(2, '0'))
12
+ .join('');
13
+ }
14
+ function hexToBytes(hex) {
15
+ const clean = hex.startsWith('0x') ? hex.slice(2) : hex;
16
+ const out = new Uint8Array(clean.length / 2);
17
+ for (let i = 0; i < out.length; i++)
18
+ out[i] = parseInt(clean.slice(i * 2, i * 2 + 2), 16);
19
+ return out;
20
+ }
21
+ /** Fresh 32-byte holder secret — mint once per holder, store in the vault. */
22
+ export function generateHolderSecret() {
23
+ const b = new Uint8Array(32);
24
+ globalThis.crypto.getRandomValues(b);
25
+ return `0x${toHex(b)}`;
26
+ }
27
+ /**
28
+ * The pairwise relationship handle for (holder, verifier):
29
+ * `HMAC-SHA256(holderSecret, verifierId)` truncated to an address-shaped
30
+ * 20-byte hex. Deterministic within the relationship (a verifier sees ONE
31
+ * stable pseudonym), unlinkable across verifiers (INV-305-1), and
32
+ * underivable without the vault-held secret.
33
+ */
34
+ export async function pairwiseHandle(holderSecret, verifierId) {
35
+ const key = await globalThis.crypto.subtle.importKey('raw', hexToBytes(holderSecret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
36
+ const mac = await globalThis.crypto.subtle.sign('HMAC', key, enc.encode(verifierId));
37
+ return `0x${toHex(new Uint8Array(mac)).slice(0, 40)}`;
38
+ }
39
+ //# sourceMappingURL=pseudonym.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pseudonym.js","sourceRoot":"","sources":["../src/pseudonym.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,+EAA+E;AAC/E,mEAAmE;AACnE,EAAE;AACF,8EAA8E;AAC9E,6EAA6E;AAC7E,2EAA2E;AAI3E,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;AAE9B,SAAS,KAAK,CAAC,KAAiB;IAC9B,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;SACrB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SAC3C,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC;AAED,SAAS,UAAU,CAAC,GAAW;IAC7B,MAAM,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACxD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,GAAG,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC1F,OAAO,GAAG,CAAC;AACb,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,oBAAoB;IAClC,MAAM,CAAC,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IAC7B,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IACrC,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AACzB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,YAAiB,EAAE,UAAkB;IACxE,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAClD,KAAK,EACL,UAAU,CAAC,YAAY,CAA2B,EAClD,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,EACjC,KAAK,EACL,CAAC,MAAM,CAAC,CACT,CAAC;IACF,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,UAAU,CAA2B,CAAC,CAAC;IAC/G,OAAO,KAAK,KAAK,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;AACxD,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { PresentationVerifyResult, PrivatePresentationV1, ProofRequestV1, IssuerKeyResolver } from './types.js';
2
+ export type ProofRequestValidation = {
3
+ ok: true;
4
+ } | {
5
+ ok: false;
6
+ reason: 'predicates_unsupported_by_suite' | 'suite_unsupported' | 'malformed';
7
+ };
8
+ /** W1 suite support: sd-jwt only; predicates on sd-jwt REJECT (fail-closed
9
+ * honesty — never silently downgrade a predicate to a field reveal). */
10
+ export declare function validateProofRequest(req: ProofRequestV1): ProofRequestValidation;
11
+ /**
12
+ * Verify a presentation against ITS request. ONE suite, declared by the
13
+ * request; a presentation in any other suite rejects (ADR-0013 — no ladder).
14
+ */
15
+ export declare function verifyPresentation(presentation: PrivatePresentationV1, request: ProofRequestV1, opts: {
16
+ resolveIssuerKey: IssuerKeyResolver;
17
+ }): Promise<PresentationVerifyResult>;
18
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,wBAAwB,EACxB,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAGpB,MAAM,MAAM,sBAAsB,GAC9B;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GACZ;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,iCAAiC,GAAG,mBAAmB,GAAG,WAAW,CAAA;CAAE,CAAC;AAEjG;yEACyE;AACzE,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,cAAc,GAAG,sBAAsB,CAMhF;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,YAAY,EAAE,qBAAqB,EACnC,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE;IAAE,gBAAgB,EAAE,iBAAiB,CAAA;CAAE,GAC5C,OAAO,CAAC,wBAAwB,CAAC,CAWnC"}
@@ -0,0 +1,32 @@
1
+ // Proof-request validation + presentation dispatch (spec 305).
2
+ import { verifySdJwtPresentation } from './sdjwt.js';
3
+ /** W1 suite support: sd-jwt only; predicates on sd-jwt REJECT (fail-closed
4
+ * honesty — never silently downgrade a predicate to a field reveal). */
5
+ export function validateProofRequest(req) {
6
+ if (req.type !== 'ProofRequestV1' || !req.nonce || !req.audience)
7
+ return { ok: false, reason: 'malformed' };
8
+ if (req.suite !== 'sd-jwt')
9
+ return { ok: false, reason: 'suite_unsupported' };
10
+ if (req.predicates && req.predicates.length > 0)
11
+ return { ok: false, reason: 'predicates_unsupported_by_suite' };
12
+ return { ok: true };
13
+ }
14
+ /**
15
+ * Verify a presentation against ITS request. ONE suite, declared by the
16
+ * request; a presentation in any other suite rejects (ADR-0013 — no ladder).
17
+ */
18
+ export async function verifyPresentation(presentation, request, opts) {
19
+ const reqCheck = validateProofRequest(request);
20
+ if (!reqCheck.ok)
21
+ return { valid: false, reason: reqCheck.reason };
22
+ if (presentation.suite !== request.suite)
23
+ return { valid: false, reason: 'suite_mismatch' };
24
+ return verifySdJwtPresentation({
25
+ presentation: presentation.payload,
26
+ audience: request.audience,
27
+ nonce: request.nonce,
28
+ requestedClaims: request.requestedClaims,
29
+ resolveIssuerKey: opts.resolveIssuerKey,
30
+ });
31
+ }
32
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAQ/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAMrD;yEACyE;AACzE,MAAM,UAAU,oBAAoB,CAAC,GAAmB;IACtD,IAAI,GAAG,CAAC,IAAI,KAAK,gBAAgB,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,GAAG,CAAC,QAAQ;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;IAC5G,IAAI,GAAG,CAAC,KAAK,KAAK,QAAQ;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC;IAC9E,IAAI,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;QAC7C,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,iCAAiC,EAAE,CAAC;IAClE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,YAAmC,EACnC,OAAuB,EACvB,IAA6C;IAE7C,MAAM,QAAQ,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC/C,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IACnE,IAAI,YAAY,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK;QAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC5F,OAAO,uBAAuB,CAAC;QAC7B,YAAY,EAAE,YAAY,CAAC,OAAO;QAClC,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,eAAe,EAAE,OAAO,CAAC,eAAe;QACxC,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;KACxC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,50 @@
1
+ import type { IssuerKeyResolver, PresentationVerifyResult, SuiteSigner } from './types.js';
2
+ export declare function b64u(bytes: Uint8Array): string;
3
+ export declare function b64uDecode(s: string): Uint8Array;
4
+ /** Dev/test keypair helper. Production issuers inject a KMS signer instead. */
5
+ export declare function generateEs256KeyPair(): Promise<{
6
+ publicKeyJwk: Record<string, unknown>;
7
+ privateKeyJwk: Record<string, unknown>;
8
+ }>;
9
+ /** Wrap a private JWK as a SuiteSigner (dev/test; production = KMS). */
10
+ export declare function es256Signer(privateKeyJwk: Record<string, unknown>): SuiteSigner;
11
+ export interface IssueSdJwtInput {
12
+ /** Issuer identity string (e.g. the org SA's CAIP-10 or card URL) — Mode-1 public. */
13
+ issuer: string;
14
+ /** The spec-304 facet keyId this credential is signed under (JWS `kid`). */
15
+ keyId: string;
16
+ /** Credential type (`vct`) — NOTE: not selectively disclosable; choose a
17
+ * non-leaking type string (the SD-JWT VC caveat the thesis flagged). */
18
+ vct: string;
19
+ /** Selectively-disclosable claims. NEVER a raw person SA (INV-305-3). */
20
+ sdClaims: Record<string, unknown>;
21
+ /** Always-visible claims (use sparingly). */
22
+ plainClaims?: Record<string, unknown>;
23
+ /** The HOLDER's public key (JWK) — pinned via `cnf` for key binding. */
24
+ holderPublicKeyJwk: Record<string, unknown>;
25
+ issuedAt?: string;
26
+ sign: SuiteSigner;
27
+ }
28
+ /** → compact `jwt~disclosure~disclosure~` (no KB-JWT yet — that's presentation). */
29
+ export declare function issueSdJwt(input: IssueSdJwtInput): Promise<string>;
30
+ export interface PresentSdJwtInput {
31
+ sdJwt: string;
32
+ /** The claim NAMES to disclose — everything else stays digest-only. */
33
+ discloseClaims: string[];
34
+ audience: string;
35
+ nonce: string;
36
+ /** Signs the KB-JWT with the holder key the credential's `cnf` pins. */
37
+ holderSign: SuiteSigner;
38
+ }
39
+ export declare function presentSdJwt(input: PresentSdJwtInput): Promise<string>;
40
+ export interface VerifySdJwtInput {
41
+ presentation: string;
42
+ audience: string;
43
+ nonce: string;
44
+ /** The claims the proof request asked for — the presentation must disclose
45
+ * EXACTLY this set (missing → claim_not_disclosed; extra → leaked). */
46
+ requestedClaims: string[];
47
+ resolveIssuerKey: IssuerKeyResolver;
48
+ }
49
+ export declare function verifySdJwtPresentation(input: VerifySdJwtInput): Promise<PresentationVerifyResult>;
50
+ //# sourceMappingURL=sdjwt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdjwt.d.ts","sourceRoot":"","sources":["../src/sdjwt.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAO3F,wBAAgB,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAI9C;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU,CAIhD;AAYD,+EAA+E;AAC/E,wBAAsB,oBAAoB,IAAI,OAAO,CAAC;IACpD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC,CAAC,CA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AAG,OAAO,CAAC,wBAAwB,CAAC,CA2DxG"}
package/dist/sdjwt.js ADDED
@@ -0,0 +1,190 @@
1
+ // Minimal, self-contained SD-JWT VC suite (spec 305 W1) — WebCrypto ES256 only.
2
+ //
3
+ // Issuance: selectively-disclosable claims become salted disclosures
4
+ // `base64url(JSON [salt, name, value])`; the signed payload carries only their
5
+ // digests (`_sd`, `_sd_alg: 'sha-256'`). Presentation: the holder forwards the
6
+ // issuer JWS + a CHOSEN disclosure subset + a key-binding JWT over
7
+ // (aud, nonce, sd_hash) signed with the holder key the credential's `cnf`
8
+ // pins. Verification: issuer JWS (spec-304 facet key) → digest recompute →
9
+ // key binding → exactly-the-requested-claims. Fail-closed, typed reasons.
10
+ //
11
+ // Deliberately small: no decoy digests, no nested structures, no JWT `exp`
12
+ // semantics beyond the facet's own validity (W2 items). Correct on the parts
13
+ // it ships; silent on nothing (unsupported inputs reject).
14
+ const enc = new TextEncoder();
15
+ const dec = new TextDecoder();
16
+ // ─── base64url + hashing ──────────────────────────────────────────────
17
+ export function b64u(bytes) {
18
+ let s = '';
19
+ for (const b of bytes)
20
+ s += String.fromCharCode(b);
21
+ return btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
22
+ }
23
+ export function b64uDecode(s) {
24
+ const pad = s.length % 4 === 0 ? '' : '='.repeat(4 - (s.length % 4));
25
+ const raw = atob(s.replace(/-/g, '+').replace(/_/g, '/') + pad);
26
+ return Uint8Array.from(raw, (c) => c.charCodeAt(0));
27
+ }
28
+ async function sha256(bytes) {
29
+ return new Uint8Array(await globalThis.crypto.subtle.digest('SHA-256', bytes));
30
+ }
31
+ async function digestOfDisclosure(disclosure) {
32
+ return b64u(await sha256(enc.encode(disclosure)));
33
+ }
34
+ // ─── ES256 (WebCrypto) ────────────────────────────────────────────────
35
+ /** Dev/test keypair helper. Production issuers inject a KMS signer instead. */
36
+ export async function generateEs256KeyPair() {
37
+ const kp = await globalThis.crypto.subtle.generateKey({ name: 'ECDSA', namedCurve: 'P-256' }, true, ['sign', 'verify']);
38
+ return {
39
+ publicKeyJwk: (await globalThis.crypto.subtle.exportKey('jwk', kp.publicKey)),
40
+ privateKeyJwk: (await globalThis.crypto.subtle.exportKey('jwk', kp.privateKey)),
41
+ };
42
+ }
43
+ /** Wrap a private JWK as a SuiteSigner (dev/test; production = KMS). */
44
+ export function es256Signer(privateKeyJwk) {
45
+ return async (signingInput) => {
46
+ const key = await globalThis.crypto.subtle.importKey('jwk', privateKeyJwk, { name: 'ECDSA', namedCurve: 'P-256' }, false, ['sign']);
47
+ const sig = await globalThis.crypto.subtle.sign({ name: 'ECDSA', hash: 'SHA-256' }, key, signingInput);
48
+ return b64u(new Uint8Array(sig));
49
+ };
50
+ }
51
+ async function es256Verify(publicKeyJwk, signingInput, sigB64u) {
52
+ try {
53
+ const key = await globalThis.crypto.subtle.importKey('jwk', publicKeyJwk, { name: 'ECDSA', namedCurve: 'P-256' }, false, ['verify']);
54
+ return await globalThis.crypto.subtle.verify({ name: 'ECDSA', hash: 'SHA-256' }, key, b64uDecode(sigB64u), signingInput);
55
+ }
56
+ catch {
57
+ return false;
58
+ }
59
+ }
60
+ async function signJwt(header, payload, sign) {
61
+ const h = b64u(enc.encode(JSON.stringify(header)));
62
+ const p = b64u(enc.encode(JSON.stringify(payload)));
63
+ const sig = await sign(enc.encode(`${h}.${p}`));
64
+ return `${h}.${p}.${sig}`;
65
+ }
66
+ function decodeJwt(jwt) {
67
+ const [h, p, sig] = jwt.split('.');
68
+ if (!h || !p || !sig)
69
+ return null;
70
+ try {
71
+ return {
72
+ header: JSON.parse(dec.decode(b64uDecode(h))),
73
+ payload: JSON.parse(dec.decode(b64uDecode(p))),
74
+ signingInput: enc.encode(`${h}.${p}`),
75
+ signature: sig,
76
+ };
77
+ }
78
+ catch {
79
+ return null;
80
+ }
81
+ }
82
+ /** → compact `jwt~disclosure~disclosure~` (no KB-JWT yet — that's presentation). */
83
+ export async function issueSdJwt(input) {
84
+ const disclosures = [];
85
+ const sdDigests = [];
86
+ for (const [name, value] of Object.entries(input.sdClaims)) {
87
+ const salt = b64u(globalThis.crypto.getRandomValues(new Uint8Array(16)));
88
+ const disclosure = b64u(enc.encode(JSON.stringify([salt, name, value])));
89
+ disclosures.push(disclosure);
90
+ sdDigests.push(await digestOfDisclosure(disclosure));
91
+ }
92
+ const payload = {
93
+ iss: input.issuer,
94
+ vct: input.vct,
95
+ iat: input.issuedAt ?? new Date().toISOString(),
96
+ _sd: sdDigests,
97
+ _sd_alg: 'sha-256',
98
+ cnf: { jwk: input.holderPublicKeyJwk },
99
+ ...(input.plainClaims ?? {}),
100
+ };
101
+ const jwt = await signJwt({ alg: 'ES256', typ: 'vc+sd-jwt', kid: input.keyId }, payload, input.sign);
102
+ return `${jwt}~${disclosures.join('~')}~`;
103
+ }
104
+ export async function presentSdJwt(input) {
105
+ const segments = input.sdJwt.split('~');
106
+ const jwt = segments[0] ?? '';
107
+ const all = segments.slice(1).filter((s) => s.length > 0);
108
+ const selected = [];
109
+ for (const d of all) {
110
+ try {
111
+ const [, name] = JSON.parse(dec.decode(b64uDecode(d)));
112
+ if (input.discloseClaims.includes(name))
113
+ selected.push(d);
114
+ }
115
+ catch {
116
+ /* skip malformed */
117
+ }
118
+ }
119
+ const prefix = `${jwt}~${selected.map((d) => `${d}~`).join('')}`;
120
+ const sdHash = b64u(await sha256(enc.encode(prefix)));
121
+ const kb = await signJwt({ alg: 'ES256', typ: 'kb+jwt' }, { aud: input.audience, nonce: input.nonce, iat: new Date().toISOString(), sd_hash: sdHash }, input.holderSign);
122
+ return `${prefix}${kb}`;
123
+ }
124
+ export async function verifySdJwtPresentation(input) {
125
+ const segments = input.presentation.split('~');
126
+ if (segments.length < 2)
127
+ return { valid: false, reason: 'malformed' };
128
+ const jwt = segments[0] ?? '';
129
+ const kbJwt = segments[segments.length - 1] ?? '';
130
+ const disclosures = segments.slice(1, -1).filter((s) => s.length > 0);
131
+ if (!kbJwt)
132
+ return { valid: false, reason: 'key_binding_invalid' };
133
+ const issuerJwt = decodeJwt(jwt);
134
+ if (!issuerJwt)
135
+ return { valid: false, reason: 'malformed' };
136
+ const keyId = issuerJwt.header.kid;
137
+ if (typeof keyId !== 'string')
138
+ return { valid: false, reason: 'issuer_key_unresolved' };
139
+ // 1. The spec-304 facet: resolved + BINDING-VERIFIED before any trust in the key.
140
+ const resolved = await input.resolveIssuerKey(keyId);
141
+ if (!resolved.ok)
142
+ return { valid: false, reason: resolved.reason };
143
+ const issuerJwk = resolved.facet.publicKeyJwk;
144
+ if (!issuerJwk)
145
+ return { valid: false, reason: 'issuer_key_unresolved' };
146
+ // 2. Issuer signature.
147
+ if (!(await es256Verify(issuerJwk, issuerJwt.signingInput, issuerJwt.signature)))
148
+ return { valid: false, reason: 'signature_invalid' };
149
+ // 3. Disclosures: every presented disclosure's digest MUST be in `_sd`.
150
+ const sd = issuerJwt.payload._sd;
151
+ if (!Array.isArray(sd))
152
+ return { valid: false, reason: 'malformed' };
153
+ const claims = {};
154
+ for (const d of disclosures) {
155
+ if (!sd.includes(await digestOfDisclosure(d)))
156
+ return { valid: false, reason: 'disclosure_digest_mismatch' };
157
+ try {
158
+ const [, name, value] = JSON.parse(dec.decode(b64uDecode(d)));
159
+ claims[name] = value;
160
+ }
161
+ catch {
162
+ return { valid: false, reason: 'malformed' };
163
+ }
164
+ }
165
+ // 4. Key binding: holder key from `cnf`, sd_hash over the exact prefix, aud+nonce.
166
+ const cnf = issuerJwt.payload.cnf?.jwk;
167
+ if (!cnf)
168
+ return { valid: false, reason: 'key_binding_invalid' };
169
+ const kb = decodeJwt(kbJwt);
170
+ if (!kb)
171
+ return { valid: false, reason: 'key_binding_invalid' };
172
+ if (!(await es256Verify(cnf, kb.signingInput, kb.signature)))
173
+ return { valid: false, reason: 'key_binding_invalid' };
174
+ if (kb.payload.aud !== input.audience || kb.payload.nonce !== input.nonce)
175
+ return { valid: false, reason: 'nonce_or_audience_mismatch' };
176
+ const prefix = `${jwt}~${disclosures.map((d) => `${d}~`).join('')}`;
177
+ if (kb.payload.sd_hash !== b64u(await sha256(enc.encode(prefix))))
178
+ return { valid: false, reason: 'key_binding_invalid' };
179
+ // 5. Exactly the requested claims (INV-305-2).
180
+ for (const c of input.requestedClaims) {
181
+ if (!(c in claims))
182
+ return { valid: false, reason: 'claim_not_disclosed' };
183
+ }
184
+ for (const c of Object.keys(claims)) {
185
+ if (!input.requestedClaims.includes(c))
186
+ return { valid: false, reason: 'undisclosed_claim_leaked' };
187
+ }
188
+ return { valid: true, reason: 'ok', claims, issuerKeyId: keyId };
189
+ }
190
+ //# sourceMappingURL=sdjwt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdjwt.js","sourceRoot":"","sources":["../src/sdjwt.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,EAAE;AACF,qEAAqE;AACrE,+EAA+E;AAC/E,+EAA+E;AAC/E,mEAAmE;AACnE,0EAA0E;AAC1E,2EAA2E;AAC3E,0EAA0E;AAC1E,EAAE;AACF,2EAA2E;AAC3E,6EAA6E;AAC7E,2DAA2D;AAI3D,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;AAC9B,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;AAE9B,yEAAyE;AAEzE,MAAM,UAAU,IAAI,CAAC,KAAiB;IACpC,IAAI,CAAC,GAAG,EAAE,CAAC;IACX,KAAK,MAAM,CAAC,IAAI,KAAK;QAAE,CAAC,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IACnD,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,CAAS;IAClC,MAAM,GAAG,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,C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KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACpC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC;YAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,0BAA0B,EAAE,CAAC;IACtG,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;AACnE,CAAC"}
@@ -0,0 +1,90 @@
1
+ export type Hex = `0x${string}`;
2
+ export type Sha256 = `sha256:${string}`;
3
+ /** ONE suite per proof request (ADR-0013) — never a runtime ladder. */
4
+ export type PresentationSuite = 'sd-jwt' | 'bbs-bls12381-g2' | 'anoncreds-v1' | 'zk-predicate';
5
+ /** Predicate vocabulary — SHAPES ship in W1; only W2+ suites can PROVE them.
6
+ * A W1 sd-jwt request carrying predicates rejects at validation (INV-305-4). */
7
+ export interface PredicateClaimV1 {
8
+ claim: string;
9
+ op: 'gte' | 'lte' | 'in-set' | 'before' | 'after';
10
+ value: string | number | Array<string | number>;
11
+ }
12
+ /** Verifier → holder. */
13
+ export interface ProofRequestV1 {
14
+ type: 'ProofRequestV1';
15
+ suite: PresentationSuite;
16
+ /** The verifier's identity/domain the pairwise handle + KB-JWT bind to. */
17
+ verifierId: string;
18
+ /** Claims the verifier asks to see in the clear. */
19
+ requestedClaims: string[];
20
+ predicates?: PredicateClaimV1[];
21
+ /** Replay binding for the key-binding JWT. */
22
+ nonce: string;
23
+ audience: string;
24
+ }
25
+ /** Holder → verifier. `payload` is suite-native (for sd-jwt: the compact
26
+ * `jwt~disclosure…~kbjwt` serialization). */
27
+ export interface PrivatePresentationV1 {
28
+ type: 'PrivatePresentationV1';
29
+ suite: PresentationSuite;
30
+ /** Pairwise pseudonym for THIS verifier — never the person SA (INV-305-3). */
31
+ relationshipHandle?: Hex;
32
+ payload: string;
33
+ }
34
+ export type PresentationVerifyReason = 'ok' | 'suite_mismatch' | 'suite_unsupported' | 'predicates_unsupported_by_suite' | 'issuer_key_unresolved' | 'issuer_binding_invalid' | 'signature_invalid' | 'disclosure_digest_mismatch' | 'key_binding_invalid' | 'nonce_or_audience_mismatch' | 'claim_not_disclosed' | 'undisclosed_claim_leaked' | 'malformed';
35
+ export interface PresentationVerifyResult {
36
+ valid: boolean;
37
+ reason: PresentationVerifyReason;
38
+ /** The disclosed claims, ONLY when valid. */
39
+ claims?: Record<string, unknown>;
40
+ /** The issuer facet keyId the presentation verified under. */
41
+ issuerKeyId?: string;
42
+ }
43
+ export interface IssuerKeyFacetV1 {
44
+ type: 'IssuerKeyFacetV1';
45
+ /** The Smart Agent this key speaks for (accountability root, ADR-0010). */
46
+ subjectAgent: Hex;
47
+ keyId: string;
48
+ /** ONE suite per facet (INV-304-3). */
49
+ suite: 'es256-sd-jwt' | 'bbs-bls12381-g2' | 'ed25519-di' | 'anoncreds-cl';
50
+ publicKeyJwk?: Record<string, unknown>;
51
+ publicKeyMultibase?: string;
52
+ validFrom: string;
53
+ validUntil?: string;
54
+ }
55
+ /** The SA-signed facet document (the binding credential, spec 304 §binding). */
56
+ export interface SignedIssuerKeyFacetV1 {
57
+ facet: IssuerKeyFacetV1;
58
+ /** Canonical sha256 over the facet (same canonical form as receipts/grants). */
59
+ facetHash: Sha256;
60
+ /** ERC-1271/6492-verifiable SA signature over the facetHash digest. */
61
+ signature: Hex;
62
+ }
63
+ /** Injected chain-side checks — this package never picks an RPC mechanism. */
64
+ export interface IssuerKeyBindingChecks {
65
+ /** Verify the SA signature over the facetHash (UniversalSignatureValidator). */
66
+ verifySaSignature(input: {
67
+ signer: Hex;
68
+ facetHash: Sha256;
69
+ signature: Hex;
70
+ }): Promise<boolean>;
71
+ /** Attestation liveness: anchored, subject matches, not revoked (chain-state freshness). */
72
+ checkAttestation(input: {
73
+ subjectAgent: Hex;
74
+ facetHash: Sha256;
75
+ }): Promise<boolean>;
76
+ }
77
+ export type IssuerKeyResolveResult = {
78
+ ok: true;
79
+ facet: IssuerKeyFacetV1;
80
+ } | {
81
+ ok: false;
82
+ reason: 'issuer_key_unresolved' | 'issuer_binding_invalid';
83
+ };
84
+ /** Resolves a credential's issuer keyId to a VERIFIED facet. Injected into
85
+ * presentation verification so a stale/revoked facet fails closed. */
86
+ export type IssuerKeyResolver = (keyId: string) => Promise<IssuerKeyResolveResult>;
87
+ /** Injected signers (KMS ES256 in production; dev keypairs in tests). Signs
88
+ * the JWS signing input, returns the raw signature bytes base64url-encoded. */
89
+ export type SuiteSigner = (signingInput: Uint8Array) => Promise<string>;
90
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAChC,MAAM,MAAM,MAAM,GAAG,UAAU,MAAM,EAAE,CAAC;AAExC,uEAAuE;AACvE,MAAM,MAAM,iBAAiB,GACzB,QAAQ,GACR,iBAAiB,GACjB,cAAc,GACd,cAAc,CAAC;AAEnB;iFACiF;AACjF,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;IAClD,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;CACjD;AAED,yBAAyB;AACzB,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,EAAE,iBAAiB,CAAC;IACzB,2EAA2E;IAC3E,UAAU,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,UAAU,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAChC,8CAA8C;IAC9C,KAAK,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AAS,EAAE,GAAG,CAAC;CAChB;AAED,8EAA8E;AAC9E,MAAM,WAAW,sBAAsB;IACrC,gFAAgF;IAChF,iBAAiB,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,GAAG,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,GAAG,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/F,4FAA4F;IAC5F,gBAAgB,CAAC,KAAK,EAAE;QAAE,YAAY,EAAE,GAAG,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACrF;AAED,MAAM,MAAM,sBAAsB,GAC9B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAA;CAAE,GACrC;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,uBAAuB,GAAG,wBAAwB,CAAA;CAAE,CAAC;AAE9E;uEACuE;AACvE,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAEnF;gFACgF;AAChF,MAAM,MAAM,WAAW,GAAG,CAAC,YAAY,EAAE,UAAU,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,5 @@
1
+ // The privacy presentation layer (spec 305 / G-6): the port that turns
2
+ // vault-held credentials into privacy-preserving presentations, plus the
3
+ // spec-304 issuer-key facet shapes it consumes.
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yEAAyE;AACzE,gDAAgD"}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@agenticprimitives/privacy-credentials",
3
+ "version": "0.0.0-alpha.1",
4
+ "description": "Privacy presentation layer (spec 305 / G-6): selectively-disclosed SD-JWT VC presentations, pairwise relationship pseudonyms, spec-304 issuer-key facet verification. One suite per request, never a fallback ladder.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/agentictrustlabs/agenticprimitives.git",
9
+ "directory": "packages/privacy-credentials"
10
+ },
11
+ "homepage": "https://github.com/agentictrustlabs/agenticprimitives/tree/master/packages/privacy-credentials",
12
+ "bugs": {
13
+ "url": "https://github.com/agentictrustlabs/agenticprimitives/issues"
14
+ },
15
+ "type": "module",
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "LICENSE",
26
+ "dist",
27
+ "README.md"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "devDependencies": {
33
+ "vitest": "^4.1.8",
34
+ "@types/node": "^22.7.0"
35
+ },
36
+ "keywords": [
37
+ "agentic",
38
+ "primitives",
39
+ "privacy",
40
+ "sd-jwt",
41
+ "selective-disclosure",
42
+ "pseudonym"
43
+ ],
44
+ "scripts": {
45
+ "build": "tsc -p tsconfig.build.json",
46
+ "typecheck": "tsc -p tsconfig.json --noEmit",
47
+ "test": "vitest run",
48
+ "test:unit": "vitest run test/unit --passWithNoTests",
49
+ "test:watch": "vitest",
50
+ "clean": "rm -rf dist"
51
+ }
52
+ }