@gramota/issuer 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # @gramota/issuer
2
+
3
+ > EUDIW credential issuer — sign SD-JWT-VC credentials with selective disclosure and key binding.
4
+
5
+ Part of [Gramota](https://github.com/gramota-org/gramota) — the TypeScript
6
+ SDK for the EU Digital Identity Wallet (EUDIW).
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ pnpm add @gramota/issuer
12
+ # or: npm install @gramota/issuer
13
+ # or: yarn add @gramota/issuer
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```ts
19
+ import { Issuer } from "@gramota/issuer";
20
+
21
+ const issuer = new Issuer({ signer, issuerUri });
22
+ const credential = await issuer.issue({ vct, claims, holderKey });
23
+ ```
24
+
25
+ For full docs, examples, and the high-level Verifier/Issuer/Holder API,
26
+ see the [main repo](https://github.com/gramota-org/gramota).
27
+
28
+ ## License
29
+
30
+ [Apache 2.0](https://github.com/gramota-org/gramota/blob/main/LICENSE)
@@ -0,0 +1,3 @@
1
+ export { Issuer } from "./issuer.js";
2
+ export { IssuerError, type IssuerConfig, type IssuerErrorCode, type IssueOptions, type IssueResult, } from "./types.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,WAAW,EACX,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,WAAW,GACjB,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { Issuer } from "./issuer.js";
2
+ export { IssuerError, } from "./types.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,WAAW,GAKZ,MAAM,YAAY,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { type JsonWebKey } from "@gramota/jose";
2
+ import { type IssueOptions, type IssueResult, type IssuerConfig } from "./types.js";
3
+ /**
4
+ * The issuer role per IETF SD-JWT-VC §3.
5
+ *
6
+ * Wraps `issueSdJwt` (the low-level primitive in `@gramota/sd-jwt`) with:
7
+ * - stateful config (signer, issuer id, optional kid/typ/hashAlg),
8
+ * - holder-binding (cnf.jwk),
9
+ * - sensible expiry handling (`expiresIn` or `expiresAt`),
10
+ * - validation: every claim listed in `selectivelyDisclosable` must
11
+ * appear in `subject`,
12
+ * - {@link Signer} Strategy for signing — accepts raw JWKs (shorthand)
13
+ * or production-grade Signers (HSM, KMS, custom backends).
14
+ */
15
+ export declare class Issuer {
16
+ /** The issuer's signer. Either supplied directly via `config.signer`
17
+ * (production: HSM/KMS) or built from raw JWKs via {@link asSigner}. */
18
+ private readonly signer;
19
+ /** Stable issuer id (`iss` claim). */
20
+ private readonly issuerIdValue;
21
+ private readonly kid;
22
+ private readonly typ;
23
+ private readonly hashAlg;
24
+ constructor(config: IssuerConfig);
25
+ /** Issue a single SD-JWT-VC credential bound to a holder. */
26
+ issue(options: IssueOptions): Promise<IssueResult>;
27
+ /** The issuer's public JWK — useful to publish at /.well-known/jwks.json. */
28
+ get publicKey(): JsonWebKey;
29
+ /** The issuer's identifier — useful for downstream URLs. */
30
+ get issuerId(): string;
31
+ }
32
+ //# sourceMappingURL=issuer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issuer.d.ts","sourceRoot":"","sources":["../src/issuer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,UAAU,EAAe,MAAM,eAAe,CAAC;AACvE,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,YAAY,CAAC;AAKpB;;;;;;;;;;;GAWG;AACH,qBAAa,MAAM;IACjB;4EACwE;IACxE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,sCAAsC;IACtC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAqB;IACzC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAqB;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;gBAElC,MAAM,EAAE,YAAY;IAWhC,6DAA6D;IACvD,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;IAsDxD,6EAA6E;IAC7E,IAAI,SAAS,IAAI,UAAU,CAE1B;IAED,4DAA4D;IAC5D,IAAI,QAAQ,IAAI,MAAM,CAErB;CACF"}
package/dist/issuer.js ADDED
@@ -0,0 +1,171 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { issueSdJwt } from "@gramota/sd-jwt";
3
+ import { asSigner } from "@gramota/jose";
4
+ import { IssuerError, } from "./types.js";
5
+ const DEFAULT_TYP = "vc+sd-jwt";
6
+ const DEFAULT_HASH_ALG = "sha-256";
7
+ /**
8
+ * The issuer role per IETF SD-JWT-VC §3.
9
+ *
10
+ * Wraps `issueSdJwt` (the low-level primitive in `@gramota/sd-jwt`) with:
11
+ * - stateful config (signer, issuer id, optional kid/typ/hashAlg),
12
+ * - holder-binding (cnf.jwk),
13
+ * - sensible expiry handling (`expiresIn` or `expiresAt`),
14
+ * - validation: every claim listed in `selectivelyDisclosable` must
15
+ * appear in `subject`,
16
+ * - {@link Signer} Strategy for signing — accepts raw JWKs (shorthand)
17
+ * or production-grade Signers (HSM, KMS, custom backends).
18
+ */
19
+ export class Issuer {
20
+ /** The issuer's signer. Either supplied directly via `config.signer`
21
+ * (production: HSM/KMS) or built from raw JWKs via {@link asSigner}. */
22
+ signer;
23
+ /** Stable issuer id (`iss` claim). */
24
+ issuerIdValue;
25
+ kid;
26
+ typ;
27
+ hashAlg;
28
+ constructor(config) {
29
+ if (typeof config.issuerId !== "string" || config.issuerId.length === 0) {
30
+ throw new TypeError("Issuer: issuerId is required (a stable URL)");
31
+ }
32
+ this.signer = normalizeIssuerSigner(config);
33
+ this.issuerIdValue = config.issuerId;
34
+ this.kid = config.kid;
35
+ this.typ = config.typ;
36
+ this.hashAlg = config.hashAlg;
37
+ }
38
+ /** Issue a single SD-JWT-VC credential bound to a holder. */
39
+ async issue(options) {
40
+ validate(options);
41
+ const issuedAt = options.issuedAt ?? Math.floor(Date.now() / 1000);
42
+ const expiresAt = computeExpiry(options, issuedAt);
43
+ const credentialId = options.credentialId ?? randomUUID();
44
+ // Split subject claims: SD ones become `sdClaims`, the rest are inlined
45
+ // directly in the JWT payload.
46
+ const sdNames = new Set(options.selectivelyDisclosable ?? []);
47
+ const sdClaims = {};
48
+ const directClaims = {};
49
+ for (const [k, v] of Object.entries(options.subject)) {
50
+ if (sdNames.has(k))
51
+ sdClaims[k] = v;
52
+ else
53
+ directClaims[k] = v;
54
+ }
55
+ const payload = {
56
+ iss: this.issuerIdValue,
57
+ iat: issuedAt,
58
+ vct: options.vct,
59
+ cnf: { jwk: options.holderKey },
60
+ ...directClaims,
61
+ };
62
+ if (expiresAt !== undefined)
63
+ payload["exp"] = expiresAt;
64
+ if (options.notBefore !== undefined)
65
+ payload["nbf"] = options.notBefore;
66
+ if (options.status !== undefined)
67
+ payload["status"] = options.status;
68
+ // Adapt the Signer to issueSdJwt's `signer: (s) => Promise<sig>` shape.
69
+ const signFn = (signedPayload) => this.signer.sign(signedPayload);
70
+ const issueOpts = {
71
+ payload,
72
+ sdClaims,
73
+ alg: this.signer.alg,
74
+ typ: this.typ ?? DEFAULT_TYP,
75
+ signer: signFn,
76
+ hashAlg: this.hashAlg ?? DEFAULT_HASH_ALG,
77
+ };
78
+ if (this.kid !== undefined) {
79
+ issueOpts.extraHeader = { kid: this.kid };
80
+ }
81
+ const result = await issueSdJwt(issueOpts);
82
+ return {
83
+ token: result.token,
84
+ credentialId,
85
+ disclosures: result.disclosures,
86
+ expiresAt,
87
+ };
88
+ }
89
+ /** The issuer's public JWK — useful to publish at /.well-known/jwks.json. */
90
+ get publicKey() {
91
+ return this.signer.publicKey;
92
+ }
93
+ /** The issuer's identifier — useful for downstream URLs. */
94
+ get issuerId() {
95
+ return this.issuerIdValue;
96
+ }
97
+ }
98
+ /**
99
+ * Normalize the Issuer config into a Signer (raw JWKs OR Signer).
100
+ */
101
+ function normalizeIssuerSigner(config) {
102
+ if ("signer" in config &&
103
+ config.signer !== undefined &&
104
+ typeof config.signer.sign === "function") {
105
+ return config.signer;
106
+ }
107
+ if ("privateKey" in config &&
108
+ "publicKey" in config &&
109
+ "alg" in config &&
110
+ config.privateKey !== null &&
111
+ typeof config.privateKey === "object" &&
112
+ config.publicKey !== null &&
113
+ typeof config.publicKey === "object" &&
114
+ typeof config.alg === "string" &&
115
+ config.alg.length > 0) {
116
+ return asSigner({
117
+ publicKey: config.publicKey,
118
+ privateKey: config.privateKey,
119
+ alg: config.alg,
120
+ });
121
+ }
122
+ throw new TypeError("Issuer: pass either { privateKey, publicKey, alg } (raw shorthand) or { signer } (production)");
123
+ }
124
+ // ---------------------------------------------------------------------------
125
+ // validation
126
+ // ---------------------------------------------------------------------------
127
+ function validate(options) {
128
+ if (options.subject === null ||
129
+ typeof options.subject !== "object" ||
130
+ Array.isArray(options.subject)) {
131
+ throw new IssuerError("issuer.subject_invalid", "issue: subject must be a non-null object");
132
+ }
133
+ if (options.holderKey === null || typeof options.holderKey !== "object") {
134
+ throw new IssuerError("issuer.holder_key_required", "issue: holderKey is required (a JsonWebKey)");
135
+ }
136
+ if (typeof options.vct !== "string" || options.vct.length === 0) {
137
+ throw new IssuerError("issuer.vct_required", "issue: vct is required per IETF SD-JWT-VC §3.2.2.1");
138
+ }
139
+ if (options.expiresIn !== undefined && options.expiresAt !== undefined) {
140
+ throw new IssuerError("issuer.expiry_conflict", "issue: expiresIn and expiresAt are mutually exclusive");
141
+ }
142
+ if (options.selectivelyDisclosable !== undefined) {
143
+ for (const name of options.selectivelyDisclosable) {
144
+ if (!Object.prototype.hasOwnProperty.call(options.subject, name)) {
145
+ throw new IssuerError("issuer.disclosable_missing", `issue: selectively disclosable claim '${name}' is not present in subject`);
146
+ }
147
+ }
148
+ }
149
+ // Reserved payload claims must NOT come from the subject.
150
+ for (const reserved of ["iss", "iat", "exp", "nbf", "cnf", "vct", "status"]) {
151
+ if (Object.prototype.hasOwnProperty.call(options.subject, reserved)) {
152
+ throw new IssuerError("issuer.reserved_claim_in_subject", `issue: subject must not contain reserved JWT claim '${reserved}' — pass via options instead`);
153
+ }
154
+ }
155
+ }
156
+ function computeExpiry(options, issuedAt) {
157
+ if (options.expiresAt !== undefined) {
158
+ if (options.expiresAt <= issuedAt) {
159
+ throw new IssuerError("issuer.expiry_invalid", `issue: expiresAt (${options.expiresAt}) must be > issuedAt (${issuedAt})`);
160
+ }
161
+ return options.expiresAt;
162
+ }
163
+ if (options.expiresIn !== undefined) {
164
+ if (options.expiresIn <= 0) {
165
+ throw new IssuerError("issuer.expiry_invalid", "issue: expiresIn must be > 0 seconds");
166
+ }
167
+ return issuedAt + options.expiresIn;
168
+ }
169
+ return undefined;
170
+ }
171
+ //# sourceMappingURL=issuer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issuer.js","sourceRoot":"","sources":["../src/issuer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAgB,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAgC,MAAM,eAAe,CAAC;AACvE,OAAO,EACL,WAAW,GAIZ,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,GAA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,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC;QAC5E,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC;YACpE,MAAM,IAAI,WAAW,CACnB,kCAAkC,EAClC,uDAAuD,QAAQ,8BAA8B,CAC9F,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CACpB,OAAqB,EACrB,QAAgB;IAEhB,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACpC,IAAI,OAAO,CAAC,SAAS,IAAI,QAAQ,EAAE,CAAC;YAClC,MAAM,IAAI,WAAW,CACnB,uBAAuB,EACvB,qBAAqB,OAAO,CAAC,SAAS,yBAAyB,QAAQ,GAAG,CAC3E,CAAC;QACJ,CAAC;QACD,OAAO,OAAO,CAAC,SAAS,CAAC;IAC3B,CAAC;IACD,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACpC,IAAI,OAAO,CAAC,SAAS,IAAI,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,WAAW,CAAC,uBAAuB,EAAE,sCAAsC,CAAC,CAAC;QACzF,CAAC;QACD,OAAO,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;IACtC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,85 @@
1
+ import type { JsonWebKey, Signer, SupportedAlg } from "@gramota/jose";
2
+ import type { HashAlg, SdJwtDisclosure } from "@gramota/sd-jwt";
3
+ /**
4
+ * Two equivalent ways to give the Issuer its signing capability:
5
+ *
6
+ * - Raw form (shorthand for tests/dev):
7
+ * { privateKey, publicKey, alg }
8
+ * - Signer form (production with KMS / HSM / signing service):
9
+ * { signer: Signer }
10
+ *
11
+ * Production issuers nearly always use the Signer form: their root-of-
12
+ * trust private key lives in an HSM / KMS and is RPC-signed.
13
+ */
14
+ export type IssuerSignerInput = {
15
+ /** Issuer's PRIVATE JWK used to sign credentials. */
16
+ privateKey: JsonWebKey;
17
+ /** Issuer's PUBLIC JWK — used by holders to verify. */
18
+ publicKey: JsonWebKey;
19
+ /** JWS algorithm. Must be compatible with `privateKey`. */
20
+ alg: SupportedAlg;
21
+ } | {
22
+ /** Production-grade signer Strategy (KMS, HSM, custom). */
23
+ signer: Signer;
24
+ };
25
+ /** Configuration for an Issuer instance — set once, used per `issue()`. */
26
+ export type IssuerConfig = IssuerSignerInput & {
27
+ /** Issuer identifier (a stable URL). Becomes the `iss` claim. */
28
+ issuerId: string;
29
+ /** Hash algorithm for selective-disclosure digests. Default `sha-256`. */
30
+ hashAlg?: HashAlg;
31
+ /** JOSE `kid` header to set on every issued credential. Optional. */
32
+ kid?: string;
33
+ /** JOSE `typ` header. Default `vc+sd-jwt` (per SD-JWT-VC spec). */
34
+ typ?: string;
35
+ };
36
+ export interface IssueOptions {
37
+ /** All claims that will go into the credential. Top-level keys become
38
+ * either selectively-disclosable disclosures or directly-visible payload
39
+ * claims, controlled by `selectivelyDisclosable`. */
40
+ subject: Readonly<Record<string, unknown>>;
41
+ /** Names of `subject` keys to make selectively disclosable. Names that
42
+ * don't appear in `subject` cause an error. Default: empty (no SD). */
43
+ selectivelyDisclosable?: readonly string[];
44
+ /** Holder's PUBLIC JWK — bound into `cnf.jwk`. Required by SD-JWT-VC for
45
+ * holder-binding (the security model collapses without it). */
46
+ holderKey: JsonWebKey;
47
+ /** SD-JWT-VC credential type identifier — required by the spec. Customers
48
+ * who really know what they're doing can pass an empty string to skip,
49
+ * but the default behaviour rejects missing `vct`. */
50
+ vct: string;
51
+ /** Seconds-until-expiry, relative to `issuedAt`. Mutually exclusive with
52
+ * `expiresAt`. */
53
+ expiresIn?: number;
54
+ /** Absolute expiry as Unix seconds. Mutually exclusive with `expiresIn`. */
55
+ expiresAt?: number;
56
+ /** Optional `nbf` (not-before) claim. */
57
+ notBefore?: number;
58
+ /** Override `iat` — defaults to `floor(Date.now()/1000)` at call time. */
59
+ issuedAt?: number;
60
+ /** Optional `status` claim for revocation tracking (Token Status List). */
61
+ status?: Readonly<Record<string, unknown>>;
62
+ /** Override the generated credential ID (default: random UUID v4). */
63
+ credentialId?: string;
64
+ }
65
+ /** Result of `issuer.issue()`. */
66
+ export interface IssueResult {
67
+ /** The compact-serialised SD-JWT-VC token to send to the holder. */
68
+ token: string;
69
+ /** Issuer-side identifier for tracking. */
70
+ credentialId: string;
71
+ /** Disclosure objects — useful for the issuer's own records / audit logs. */
72
+ disclosures: readonly SdJwtDisclosure[];
73
+ /** Computed expiry (if `expiresIn` or `expiresAt` was set). */
74
+ expiresAt: number | undefined;
75
+ }
76
+ /** Stable codes for `IssuerError`. */
77
+ export type IssuerErrorCode = "issuer.subject_invalid" | "issuer.holder_key_required" | "issuer.vct_required" | "issuer.expiry_conflict" | "issuer.expiry_invalid" | "issuer.disclosable_missing" | "issuer.reserved_claim_in_subject";
78
+ export declare class IssuerError extends Error {
79
+ readonly name = "IssuerError";
80
+ readonly code: IssuerErrorCode;
81
+ constructor(code: IssuerErrorCode, message: string, options?: {
82
+ cause?: unknown;
83
+ });
84
+ }
85
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEhE;;;;;;;;;;GAUG;AACH,MAAM,MAAM,iBAAiB,GACzB;IACE,qDAAqD;IACrD,UAAU,EAAE,UAAU,CAAC;IACvB,uDAAuD;IACvD,SAAS,EAAE,UAAU,CAAC;IACtB,2DAA2D;IAC3D,GAAG,EAAE,YAAY,CAAC;CACnB,GACD;IACE,2DAA2D;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AM,eAAe,GACvB,wBAAwB,GACxB,4BAA4B,GAC5B,qBAAqB,GACrB,wBAAwB,GACxB,uBAAuB,GACvB,4BAA4B,GAC5B,kCAAkC,CAAC;AAEvC,qBAAa,WAAY,SAAQ,KAAK;IACpC,SAAkB,IAAI,iBAAiB;IACvC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;gBAE7B,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAQhC"}
package/dist/types.js ADDED
@@ -0,0 +1,12 @@
1
+ export class IssuerError extends Error {
2
+ name = "IssuerError";
3
+ code;
4
+ constructor(code, message, options) {
5
+ super(message);
6
+ this.code = code;
7
+ if (options?.cause !== undefined) {
8
+ this.cause = options.cause;
9
+ }
10
+ }
11
+ }
12
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA4FA,MAAM,OAAO,WAAY,SAAQ,KAAK;IAClB,IAAI,GAAG,aAAa,CAAC;IAC9B,IAAI,CAAkB;IAC/B,YACE,IAAqB,EACrB,OAAe,EACf,OAA6B;QAE7B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,OAAO,EAAE,KAAK,KAAK,SAAS,EAAE,CAAC;YAChC,IAA4B,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QACtD,CAAC;IACH,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@gramota/issuer",
3
+ "version": "0.1.0",
4
+ "description": "EUDIW credential issuer — sign SD-JWT-VC credentials with selective disclosure and key binding.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "@gramota/jose": "0.1.0",
20
+ "@gramota/sd-jwt": "0.1.0"
21
+ },
22
+ "devDependencies": {
23
+ "jose": "^5.9.6"
24
+ },
25
+ "author": "Petromil Pavlov <petromilpavlov@gmail.com>",
26
+ "homepage": "https://github.com/gramota-org/gramota#readme",
27
+ "bugs": {
28
+ "url": "https://github.com/gramota-org/gramota/issues"
29
+ },
30
+ "engines": {
31
+ "node": ">=20"
32
+ },
33
+ "sideEffects": false,
34
+ "publishConfig": {
35
+ "access": "public",
36
+ "registry": "https://registry.npmjs.org/"
37
+ },
38
+ "keywords": [
39
+ "issuer",
40
+ "oid4vci",
41
+ "sd-jwt-vc",
42
+ "eudi",
43
+ "verifiable-credentials",
44
+ "credential-issuance"
45
+ ],
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/gramota-org/gramota.git",
49
+ "directory": "packages/issuer"
50
+ },
51
+ "scripts": {
52
+ "build": "tsc -p tsconfig.json",
53
+ "typecheck": "tsc -p tsconfig.json --noEmit"
54
+ }
55
+ }