@sd-jwt/core 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.
Files changed (109) hide show
  1. package/build/base64url.d.ts +28 -0
  2. package/build/base64url.js +40 -0
  3. package/build/base64url.js.map +1 -0
  4. package/build/hasherAlgorithm.d.ts +70 -0
  5. package/build/hasherAlgorithm.js +75 -0
  6. package/build/hasherAlgorithm.js.map +1 -0
  7. package/build/index.d.ts +11 -0
  8. package/build/index.js +20 -0
  9. package/build/index.js.map +1 -0
  10. package/build/jwt/compact.d.ts +6 -0
  11. package/build/jwt/compact.js +27 -0
  12. package/build/jwt/compact.js.map +1 -0
  13. package/build/jwt/error.d.ts +2 -0
  14. package/build/jwt/error.js +7 -0
  15. package/build/jwt/error.js.map +1 -0
  16. package/build/jwt/index.d.ts +3 -0
  17. package/build/jwt/index.js +20 -0
  18. package/build/jwt/index.js.map +1 -0
  19. package/build/jwt/jwt.d.ts +204 -0
  20. package/build/jwt/jwt.js +324 -0
  21. package/build/jwt/jwt.js.map +1 -0
  22. package/build/keyBinding/index.d.ts +1 -0
  23. package/build/keyBinding/index.js +18 -0
  24. package/build/keyBinding/index.js.map +1 -0
  25. package/build/keyBinding/keyBinding.d.ts +56 -0
  26. package/build/keyBinding/keyBinding.js +99 -0
  27. package/build/keyBinding/keyBinding.js.map +1 -0
  28. package/build/sdJwt/compact.d.ts +8 -0
  29. package/build/sdJwt/compact.js +39 -0
  30. package/build/sdJwt/compact.js.map +1 -0
  31. package/build/sdJwt/decoys.d.ts +2 -0
  32. package/build/sdJwt/decoys.js +35 -0
  33. package/build/sdJwt/decoys.js.map +1 -0
  34. package/build/sdJwt/disclosureFrame.d.ts +7 -0
  35. package/build/sdJwt/disclosureFrame.js +89 -0
  36. package/build/sdJwt/disclosureFrame.js.map +1 -0
  37. package/build/sdJwt/disclosureMapping.d.ts +44 -0
  38. package/build/sdJwt/disclosureMapping.js +289 -0
  39. package/build/sdJwt/disclosureMapping.js.map +1 -0
  40. package/build/sdJwt/disclosures.d.ts +14 -0
  41. package/build/sdJwt/disclosures.js +59 -0
  42. package/build/sdJwt/disclosures.js.map +1 -0
  43. package/build/sdJwt/error.d.ts +2 -0
  44. package/build/sdJwt/error.js +7 -0
  45. package/build/sdJwt/error.js.map +1 -0
  46. package/build/sdJwt/index.d.ts +7 -0
  47. package/build/sdJwt/index.js +24 -0
  48. package/build/sdJwt/index.js.map +1 -0
  49. package/build/sdJwt/presentationFrame.d.ts +4 -0
  50. package/build/sdJwt/presentationFrame.js +73 -0
  51. package/build/sdJwt/presentationFrame.js.map +1 -0
  52. package/build/sdJwt/sdJwt.d.ts +204 -0
  53. package/build/sdJwt/sdJwt.js +383 -0
  54. package/build/sdJwt/sdJwt.js.map +1 -0
  55. package/build/sdJwt/swapClaim.d.ts +3 -0
  56. package/build/sdJwt/swapClaim.js +90 -0
  57. package/build/sdJwt/swapClaim.js.map +1 -0
  58. package/build/sdJwt/types.d.ts +5 -0
  59. package/build/sdJwt/types.js +3 -0
  60. package/build/sdJwt/types.js.map +1 -0
  61. package/build/sdJwtVc/error.d.ts +2 -0
  62. package/build/sdJwtVc/error.js +7 -0
  63. package/build/sdJwtVc/error.js.map +1 -0
  64. package/build/sdJwtVc/index.d.ts +2 -0
  65. package/build/sdJwtVc/index.js +19 -0
  66. package/build/sdJwtVc/index.js.map +1 -0
  67. package/build/sdJwtVc/sdJwtVc.d.ts +47 -0
  68. package/build/sdJwtVc/sdJwtVc.js +125 -0
  69. package/build/sdJwtVc/sdJwtVc.js.map +1 -0
  70. package/build/signatureAndEncryptionAlgorithm.d.ts +105 -0
  71. package/build/signatureAndEncryptionAlgorithm.js +110 -0
  72. package/build/signatureAndEncryptionAlgorithm.js.map +1 -0
  73. package/build/types/disclosure.d.ts +5 -0
  74. package/build/types/disclosure.js +3 -0
  75. package/build/types/disclosure.js.map +1 -0
  76. package/build/types/frame.d.ts +5 -0
  77. package/build/types/frame.js +3 -0
  78. package/build/types/frame.js.map +1 -0
  79. package/build/types/hasher.d.ts +14 -0
  80. package/build/types/hasher.js +3 -0
  81. package/build/types/hasher.js.map +1 -0
  82. package/build/types/index.d.ts +6 -0
  83. package/build/types/index.js +23 -0
  84. package/build/types/index.js.map +1 -0
  85. package/build/types/present.d.ts +2 -0
  86. package/build/types/present.js +3 -0
  87. package/build/types/present.js.map +1 -0
  88. package/build/types/saltGenerator.d.ts +17 -0
  89. package/build/types/saltGenerator.js +3 -0
  90. package/build/types/saltGenerator.js.map +1 -0
  91. package/build/types/signer.d.ts +2 -0
  92. package/build/types/signer.js +3 -0
  93. package/build/types/signer.js.map +1 -0
  94. package/build/types/utils.d.ts +5 -0
  95. package/build/types/utils.js +3 -0
  96. package/build/types/utils.js.map +1 -0
  97. package/build/types/verifier.d.ts +14 -0
  98. package/build/types/verifier.js +3 -0
  99. package/build/types/verifier.js.map +1 -0
  100. package/build/utils/index.d.ts +2 -0
  101. package/build/utils/index.js +19 -0
  102. package/build/utils/index.js.map +1 -0
  103. package/build/utils/traverse.d.ts +8 -0
  104. package/build/utils/traverse.js +29 -0
  105. package/build/utils/traverse.js.map +1 -0
  106. package/build/utils/utils.d.ts +7 -0
  107. package/build/utils/utils.js +109 -0
  108. package/build/utils/utils.js.map +1 -0
  109. package/package.json +50 -0
@@ -0,0 +1,324 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Jwt = void 0;
13
+ const base64url_1 = require("../base64url");
14
+ const error_1 = require("./error");
15
+ const compact_1 = require("./compact");
16
+ const utils_1 = require("../utils");
17
+ class Jwt {
18
+ constructor(options, additionalOptions) {
19
+ this.header = options === null || options === void 0 ? void 0 : options.header;
20
+ this.payload = options === null || options === void 0 ? void 0 : options.payload;
21
+ this.signature = options === null || options === void 0 ? void 0 : options.signature;
22
+ this.signer = additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.signer;
23
+ }
24
+ /**
25
+ *
26
+ * Instantiate a JWT from a compact format.
27
+ *
28
+ * Two generics may be supplied for typing on the Header and Payload. These are not enforced.
29
+ *
30
+ * Defined in: {@link https://datatracker.ietf.org/doc/html/rfc7519#section-3 | RFC 7519 }
31
+ *
32
+ */
33
+ static fromCompact(compact) {
34
+ const { header, payload, signature } = (0, compact_1.jwtFromCompact)(compact);
35
+ const jwt = new Jwt({
36
+ header,
37
+ payload,
38
+ signature
39
+ });
40
+ return jwt;
41
+ }
42
+ /**
43
+ *
44
+ * Replaces the current Header a new one.
45
+ *
46
+ */
47
+ withHeader(header) {
48
+ this.header = header;
49
+ return this;
50
+ }
51
+ /**
52
+ *
53
+ * Add a new claim to the Header, overriding the old one if it already is on there.
54
+ *
55
+ */
56
+ addHeaderClaim(item, value) {
57
+ var _a;
58
+ (_a = this.header) !== null && _a !== void 0 ? _a : (this.header = {});
59
+ if (value !== undefined && item !== null) {
60
+ this.header = Object.assign(Object.assign({}, this.header), { [item]: value });
61
+ }
62
+ return this;
63
+ }
64
+ /**
65
+ *
66
+ * Replaces the current Payload a new one.
67
+ *
68
+ */
69
+ withPayload(payload) {
70
+ this.payload = payload;
71
+ return this;
72
+ }
73
+ /**
74
+ *
75
+ * Add a new claim to the Payload, overriding the old one if it already is on there.
76
+ *
77
+ */
78
+ addPayloadClaim(item, value) {
79
+ var _a;
80
+ (_a = this.payload) !== null && _a !== void 0 ? _a : (this.payload = {});
81
+ if (value !== undefined && item !== null) {
82
+ this.payload = Object.assign(Object.assign({}, this.payload), { [item]: value });
83
+ }
84
+ return this;
85
+ }
86
+ /**
87
+ *
88
+ * Manually append a signature to the JWT. This signature is not validated.
89
+ *
90
+ * @note Only use this if the supplying a signing callback does not fit your use case.
91
+ *
92
+ */
93
+ withSignature(signature) {
94
+ this.signature = signature;
95
+ return this;
96
+ }
97
+ /**
98
+ *
99
+ * Add a signing callback to the JWT that will be used for creating the signature.
100
+ *
101
+ */
102
+ withSigner(signer) {
103
+ this.signer = signer;
104
+ return this;
105
+ }
106
+ /**
107
+ *
108
+ * Assert that there is a Header on the JWT.
109
+ *
110
+ * @throws when the Header is not defined
111
+ *
112
+ */
113
+ assertHeader() {
114
+ if (this.header)
115
+ return;
116
+ throw new error_1.JwtError('Header must be defined');
117
+ }
118
+ /**
119
+ *
120
+ * Assert that there is a Payload on the JWT.
121
+ *
122
+ * @throws when the Payload is not defined
123
+ *
124
+ */
125
+ assertPayload() {
126
+ if (this.payload)
127
+ return;
128
+ throw new error_1.JwtError('Payload must be defined');
129
+ }
130
+ /**
131
+ *
132
+ * Assert that there is a Signature on the JWT.
133
+ *
134
+ * @throws when the Signature is not defined
135
+ *
136
+ */
137
+ assertSignature() {
138
+ if (this.signature)
139
+ return;
140
+ throw new error_1.JwtError('Signature must be defined');
141
+ }
142
+ /**
143
+ *
144
+ * Assert that there is a Signing callback on the JWT.
145
+ *
146
+ * @throws when the Signer is not defined
147
+ *
148
+ */
149
+ assertSigner() {
150
+ if (this.signer)
151
+ return;
152
+ throw new error_1.JwtError('A signer must be provided to create a signature. You can set it with this.withSigner()');
153
+ }
154
+ /**
155
+ *
156
+ * Assert that there is a specific claim, possibly with value, in the Header.
157
+ *
158
+ */
159
+ assertClaimInHeader(claimKey, claimValue) {
160
+ this.assertHeader();
161
+ try {
162
+ this.assertClaimInObject(this.header, claimKey, claimValue);
163
+ }
164
+ catch (e) {
165
+ if (e instanceof error_1.JwtError) {
166
+ e.message += ' within the header';
167
+ }
168
+ throw e;
169
+ }
170
+ }
171
+ /**
172
+ *
173
+ * Assert that there is a specific claim, possibly with value, in the Payload.
174
+ *
175
+ */
176
+ assertClaimInPayload(claimKey, claimValue) {
177
+ this.assertPayload();
178
+ try {
179
+ this.assertClaimInObject(this.payload, claimKey, claimValue);
180
+ }
181
+ catch (e) {
182
+ if (e instanceof error_1.JwtError) {
183
+ e.message += ' within the payload';
184
+ }
185
+ throw e;
186
+ }
187
+ }
188
+ assertClaimInObject(object, claimKey, claimValue) {
189
+ const value = (0, utils_1.getValueByKeyAnyLevel)(object, claimKey);
190
+ if (!value) {
191
+ throw new error_1.JwtError(`Claim key '${claimKey}' not found in any level`);
192
+ }
193
+ if (claimValue && !(0, utils_1.simpleDeepEqual)(value, claimValue)) {
194
+ throw new error_1.JwtError(`Claim key '${claimKey}' was found, but values did not match`);
195
+ }
196
+ }
197
+ /**
198
+ *
199
+ * Get a claim within the payload.
200
+ *
201
+ * @throws when the payload is not defined
202
+ * @throws when the claim could not be found at any level
203
+ *
204
+ */
205
+ getClaimInPayload(claimKey) {
206
+ this.assertPayload();
207
+ return this.getClaimInObject(this.payload, claimKey);
208
+ }
209
+ /**
210
+ *
211
+ * Get a claim within the payload.
212
+ *
213
+ * @throws when the payload is not defined
214
+ * @throws when the claim could not be found at any level
215
+ *
216
+ */
217
+ getClaimInHeader(claimKey) {
218
+ this.assertHeader();
219
+ return this.getClaimInObject(this.header, claimKey);
220
+ }
221
+ getClaimInObject(object, claimKey) {
222
+ const value = (0, utils_1.getValueByKeyAnyLevel)(object, claimKey);
223
+ if (!value) {
224
+ throw new error_1.JwtError(`Claim key '${claimKey}' not found in any level`);
225
+ }
226
+ return value;
227
+ }
228
+ /**
229
+ *
230
+ * Returns a string of what needs to be signed.
231
+ *
232
+ * Defined in: {@link https://datatracker.ietf.org/doc/html/rfc7519#section-3 | RFC 7519}
233
+ *
234
+ */
235
+ get signableInput() {
236
+ this.assertHeader();
237
+ this.assertPayload();
238
+ return `${this.compactHeader}.${this.compactPayload}`;
239
+ }
240
+ /**
241
+ *
242
+ * Sign the Header and Payload and append the signature to the JWT.
243
+ *
244
+ */
245
+ signAndAdd() {
246
+ return __awaiter(this, void 0, void 0, function* () {
247
+ this.assertSigner();
248
+ const signature = yield this.signer(this.signableInput, this.header);
249
+ this.withSignature(signature);
250
+ return this;
251
+ });
252
+ }
253
+ get compactHeader() {
254
+ this.assertHeader();
255
+ return base64url_1.Base64url.encodeFromJson(this.header);
256
+ }
257
+ get compactPayload() {
258
+ this.assertPayload();
259
+ return base64url_1.Base64url.encodeFromJson(this.payload);
260
+ }
261
+ /**
262
+ *
263
+ * Create a compact format of the JWT.
264
+ *
265
+ * This will add a signature if there is none.
266
+ *
267
+ * @throws When the signature and signer are not defined
268
+ *
269
+ */
270
+ toCompact() {
271
+ return __awaiter(this, void 0, void 0, function* () {
272
+ this.assertHeader();
273
+ this.assertPayload();
274
+ if (!this.signature) {
275
+ yield this.signAndAdd();
276
+ }
277
+ const encodedSignature = base64url_1.Base64url.encode(this.signature);
278
+ return `${this.compactHeader}.${this.compactPayload}.${encodedSignature}`;
279
+ });
280
+ }
281
+ /**
282
+ *
283
+ * Verify the JWT.
284
+ *
285
+ * - Check the nbf claim with `now`
286
+ * - Check the exp claim with `now`
287
+ * - Additionally validate any required claims
288
+ * - Additionally pass in a specific publicKeyJwk to validate the signature
289
+ *
290
+ */
291
+ verify(verifySignature, requiredClaims, publicKeyJwk) {
292
+ return __awaiter(this, void 0, void 0, function* () {
293
+ this.assertHeader();
294
+ this.assertPayload();
295
+ this.assertSignature();
296
+ const ret = {};
297
+ ret.isSignatureValid = yield verifySignature({
298
+ header: this.header,
299
+ signature: this.signature,
300
+ message: this.signableInput,
301
+ publicKeyJwk
302
+ });
303
+ if ('nbf' in this.payload) {
304
+ const now = new Date();
305
+ const notBefore = new Date(this.payload.nbf * 1000);
306
+ ret.isNotBeforeValid = notBefore < now;
307
+ }
308
+ if ('exp' in this.payload) {
309
+ const now = new Date();
310
+ const expiryTime = new Date(this.payload.exp * 1000);
311
+ ret.isExpiryTimeValid = expiryTime > now;
312
+ }
313
+ if (requiredClaims) {
314
+ ret.areRequiredClaimsIncluded = requiredClaims.every((claim) => claim in this.payload);
315
+ }
316
+ ret.isValid = Object.values(ret)
317
+ .filter((i) => typeof i === 'boolean')
318
+ .every((i) => !!i);
319
+ return ret;
320
+ });
321
+ }
322
+ }
323
+ exports.Jwt = Jwt;
324
+ //# sourceMappingURL=jwt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt.js","sourceRoot":"","sources":["../../src/jwt/jwt.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAwC;AACxC,mCAAkC;AAElC,uCAA0C;AAE1C,oCAAiE;AAiDjE,MAAa,GAAG;IAsCZ,YACI,OAAqC,EACrC,iBAAwC;QAExC,IAAI,CAAC,MAAM,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAA;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAA;QAC/B,IAAI,CAAC,SAAS,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,CAAA;QAEnC,IAAI,CAAC,MAAM,GAAG,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,MAAM,CAAA;IAC3C,CAAC;IAED;;;;;;;;OAQG;IACI,MAAM,CAAC,WAAW,CAGvB,OAAe;QACb,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAc,EACjD,OAAO,CACV,CAAA;QAED,MAAM,GAAG,GAAG,IAAI,GAAG,CAAkB;YACjC,MAAM;YACN,OAAO;YACP,SAAS;SACZ,CAAC,CAAA;QAEF,OAAO,GAAiE,CAAA;IAC5E,CAAC;IAED;;;;OAIG;IACI,UAAU,CACb,MAAc;QAEd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,OAAO,IAAkD,CAAA;IAC7D,CAAC;IAED;;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,IAAI,IAAI,CAAC,OAAQ,EAAE,CAAC;gBACzB,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;gBACtB,MAAM,SAAS,GAAG,IAAI,IAAI,CAAE,IAAI,CAAC,OAAQ,CAAC,GAAc,GAAG,IAAI,CAAC,CAAA;gBAEhE,GAAG,CAAC,gBAAgB,GAAG,SAAS,GAAG,GAAG,CAAA;YAC1C,CAAC;YAED,IAAI,KAAK,IAAI,IAAI,CAAC,OAAQ,EAAE,CAAC;gBACzB,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;gBACtB,MAAM,UAAU,GAAG,IAAI,IAAI,CAAE,IAAI,CAAC,OAAQ,CAAC,GAAc,GAAG,IAAI,CAAC,CAAA;gBAEjE,GAAG,CAAC,iBAAiB,GAAG,UAAU,GAAG,GAAG,CAAA;YAC5C,CAAC;YAED,IAAI,cAAc,EAAE,CAAC;gBACjB,GAAG,CAAC,yBAAyB,GAAG,cAAc,CAAC,KAAK,CAChD,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC,OAAQ,CACpC,CAAA;YACL,CAAC;YAED,GAAG,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;iBAC3B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,SAAS,CAAC;iBACrC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YAEtB,OAAO,GAA4B,CAAA;QACvC,CAAC;KAAA;CACJ;AA/aD,kBA+aC"}
@@ -0,0 +1 @@
1
+ export * from './keyBinding';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./keyBinding"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/keyBinding/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B"}
@@ -0,0 +1,56 @@
1
+ import { Jwt, JwtAdditionalOptions, JwtOptions, JwtVerificationResult } from '../jwt';
2
+ import { SignatureAndEncryptionAlgorithm } from '../signatureAndEncryptionAlgorithm';
3
+ import { MakePropertyRequired, Signer, Verifier } from '../types';
4
+ type ReturnKeyBindingWithHeaderAndPayload<H extends Record<string, unknown>, P extends Record<string, unknown>, T extends KeyBinding<H, P>> = MakePropertyRequired<T, 'header' | 'payload'>;
5
+ export type KeyBindingHeader<H extends Record<string, unknown> = Record<string, unknown>> = H & {
6
+ typ: 'kb+jwt';
7
+ alg: SignatureAndEncryptionAlgorithm | string;
8
+ };
9
+ export type KeyBindingPayload<P extends Record<string, unknown> = Record<string, unknown>> = P & {
10
+ iat: number;
11
+ aud: string;
12
+ nonce: string;
13
+ };
14
+ export type KeyBindingOptions<Header extends Record<string, unknown> = Record<string, unknown>, Payload extends Record<string, unknown> = Record<string, unknown>> = JwtOptions<KeyBindingHeader<Header>, KeyBindingPayload<Payload>>;
15
+ export type KeyBindingAdditionalOptions<Header extends Record<string, unknown> = Record<string, unknown>> = JwtAdditionalOptions<KeyBindingHeader<Header>>;
16
+ export type KeyBindingVerificationResult = JwtVerificationResult;
17
+ export declare class KeyBinding<Header extends Record<string, unknown> = Record<string, unknown>, Payload extends Record<string, unknown> = Record<string, unknown>> extends Jwt<Header, Payload> {
18
+ signer?: Signer<Header>;
19
+ constructor(options?: KeyBindingOptions<Header, Payload>, additionalOptions?: KeyBindingAdditionalOptions<Header>);
20
+ /**
21
+ *
22
+ * Convert a standard `JWT` to an instance of `KeyBinding`.
23
+ *
24
+ * @throws when the claims are not valid for key binding
25
+ *
26
+ */
27
+ static fromJwt<Header extends Record<string, unknown> = Record<string, unknown>, Payload extends Record<string, unknown> = Record<string, unknown>>(jwt: Jwt<Header, Payload>): KeyBinding<Header, Payload>;
28
+ /**
29
+ *
30
+ * Verify the jwt as a valid `KeyBinding` jwt.
31
+ *
32
+ * Invalid when:
33
+ * - The required claims for key binding are not included
34
+ * - The signature is invalid
35
+ * - The optional required additional claims are not included
36
+ *
37
+ */
38
+ verify(verifySignature: Verifier<Header>, requiredClaims?: Array<keyof Payload | string>, publicKeyJwk?: Record<string, unknown>): Promise<KeyBindingVerificationResult>;
39
+ /**
40
+ *
41
+ * Convert a compact `JWT` into an instance of `KeyBinding`.
42
+ *
43
+ * @throws when the claims are not valid for key binding
44
+ *
45
+ */
46
+ static fromCompact<Header extends Record<string, unknown> = Record<string, unknown>, Payload extends Record<string, unknown> = Record<string, unknown>>(compact: string): ReturnKeyBindingWithHeaderAndPayload<Header, Payload, KeyBinding<Header, Payload>>;
47
+ /**
48
+ *
49
+ * Asserts the required properties for valid key binding.
50
+ *
51
+ * @throws when a claim in the header, or payload, is invalid
52
+ *
53
+ */
54
+ assertValidForKeyBinding(): Promise<void>;
55
+ }
56
+ export {};
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.KeyBinding = void 0;
13
+ const jwt_1 = require("../jwt");
14
+ class KeyBinding extends jwt_1.Jwt {
15
+ constructor(options, additionalOptions) {
16
+ super(options);
17
+ this.signer = additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.signer;
18
+ }
19
+ /**
20
+ *
21
+ * Convert a standard `JWT` to an instance of `KeyBinding`.
22
+ *
23
+ * @throws when the claims are not valid for key binding
24
+ *
25
+ */
26
+ static fromJwt(jwt) {
27
+ const keyBinding = new KeyBinding({
28
+ header: jwt.header,
29
+ payload: jwt.payload,
30
+ signature: jwt.signature
31
+ }, { signer: jwt.signer });
32
+ keyBinding.assertValidForKeyBinding();
33
+ return keyBinding;
34
+ }
35
+ /**
36
+ *
37
+ * Verify the jwt as a valid `KeyBinding` jwt.
38
+ *
39
+ * Invalid when:
40
+ * - The required claims for key binding are not included
41
+ * - The signature is invalid
42
+ * - The optional required additional claims are not included
43
+ *
44
+ */
45
+ verify(verifySignature, requiredClaims, publicKeyJwk) {
46
+ const _super = Object.create(null, {
47
+ verify: { get: () => super.verify }
48
+ });
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ this.assertValidForKeyBinding();
51
+ const jwtVerificationResult = yield _super.verify.call(this, verifySignature, requiredClaims, publicKeyJwk);
52
+ return jwtVerificationResult;
53
+ });
54
+ }
55
+ /**
56
+ *
57
+ * Convert a compact `JWT` into an instance of `KeyBinding`.
58
+ *
59
+ * @throws when the claims are not valid for key binding
60
+ *
61
+ */
62
+ static fromCompact(compact) {
63
+ const jwt = jwt_1.Jwt.fromCompact(compact);
64
+ const keyBinding = KeyBinding.fromJwt(jwt);
65
+ return keyBinding;
66
+ }
67
+ /**
68
+ *
69
+ * Asserts the required properties for valid key binding.
70
+ *
71
+ * @throws when a claim in the header, or payload, is invalid
72
+ *
73
+ */
74
+ assertValidForKeyBinding() {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ try {
77
+ this.assertHeader();
78
+ this.assertPayload();
79
+ if (!this.signature) {
80
+ yield this.signAndAdd();
81
+ }
82
+ this.assertSignature();
83
+ this.assertClaimInHeader('typ', 'kb+jwt');
84
+ this.assertClaimInHeader('alg');
85
+ this.assertClaimInPayload('iat');
86
+ this.assertClaimInPayload('nonce');
87
+ this.assertClaimInPayload('aud');
88
+ }
89
+ catch (e) {
90
+ if (e instanceof Error) {
91
+ e.message = `jwt is not valid for usage with key binding. Error: ${e.message}`;
92
+ }
93
+ throw e;
94
+ }
95
+ });
96
+ }
97
+ }
98
+ exports.KeyBinding = KeyBinding;
99
+ //# sourceMappingURL=keyBinding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyBinding.js","sourceRoot":"","sources":["../../src/keyBinding/keyBinding.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gCAKe;AAoCf,MAAa,UAGX,SAAQ,SAAoB;IAG1B,YACI,OAA4C,EAC5C,iBAAuD;QAEvD,KAAK,CAAC,OAAO,CAAC,CAAA;QAEd,IAAI,CAAC,MAAM,GAAG,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,MAAwB,CAAA;IAC7D,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,OAAO,CAGnB,GAAyB;QACvB,MAAM,UAAU,GAAG,IAAI,UAAU,CAC7B;YACI,MAAM,EAAE,GAAG,CAAC,MAAkC;YAC9C,OAAO,EAAE,GAAG,CAAC,OAAqC;YAClD,SAAS,EAAE,GAAG,CAAC,SAAS;SAC3B,EACD,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CACzB,CAAA;QAED,UAAU,CAAC,wBAAwB,EAAE,CAAA;QAErC,OAAO,UAAU,CAAA;IACrB,CAAC;IAED;;;;;;;;;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,gCAuHC"}
@@ -0,0 +1,8 @@
1
+ import { KeyBinding } from '../keyBinding';
2
+ import { Disclosure } from './disclosures';
3
+ import { ExpandedJwt } from '../jwt';
4
+ export type ExpandedSdJwt<H extends Record<string, unknown> = Record<string, unknown>, P extends Record<string, unknown> = Record<string, unknown>> = ExpandedJwt<H, P> & {
5
+ disclosures?: Array<Disclosure>;
6
+ keyBinding?: KeyBinding;
7
+ };
8
+ export declare const sdJwtFromCompact: <H extends Record<string, unknown> = Record<string, unknown>, P extends Record<string, unknown> = Record<string, unknown>>(compact: string) => ExpandedSdJwt<H, P>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sdJwtFromCompact = void 0;
4
+ const keyBinding_1 = require("../keyBinding");
5
+ const disclosures_1 = require("./disclosures");
6
+ const jwt_1 = require("../jwt");
7
+ const sdJwtFromCompact = (compact) => {
8
+ const [jwtWithoutDisclosures, ...encodedDisclosures] = compact.split('~');
9
+ const { header, payload, signature } = (0, jwt_1.jwtFromCompact)(jwtWithoutDisclosures);
10
+ if (encodedDisclosures.length === 0) {
11
+ return {
12
+ header,
13
+ payload,
14
+ signature
15
+ };
16
+ }
17
+ const hasKeyBinding = !compact.endsWith('~');
18
+ // If the disclosure array ends with an `~` we do not have
19
+ // a key binding and `String.split` takes it as an empty string
20
+ // as element which we would not like to include in the disclosures.
21
+ if (!hasKeyBinding)
22
+ encodedDisclosures.pop();
23
+ const compactKeyBinding = hasKeyBinding
24
+ ? encodedDisclosures.pop()
25
+ : undefined;
26
+ const keyBinding = compactKeyBinding
27
+ ? keyBinding_1.KeyBinding.fromCompact(compactKeyBinding)
28
+ : undefined;
29
+ const disclosures = encodedDisclosures.map(disclosures_1.Disclosure.fromString);
30
+ return {
31
+ header,
32
+ payload,
33
+ signature,
34
+ keyBinding,
35
+ disclosures
36
+ };
37
+ };
38
+ exports.sdJwtFromCompact = sdJwtFromCompact;
39
+ //# sourceMappingURL=compact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compact.js","sourceRoot":"","sources":["../../src/sdJwt/compact.ts"],"names":[],"mappings":";;;AAAA,8CAA0C;AAC1C,+CAA0C;AAC1C,gCAAoD;AAU7C,MAAM,gBAAgB,GAAG,CAI5B,OAAe,EACI,EAAE;IACrB,MAAM,CAAC,qBAAqB,EAAE,GAAG,kBAAkB,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAEzE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,IAAA,oBAAc,EACjD,qBAAqB,CACxB,CAAA;IAED,IAAI,kBAAkB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO;YACH,MAAM;YACN,OAAO;YACP,SAAS;SACZ,CAAA;IACL,CAAC;IAED,MAAM,aAAa,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;IAE5C,0DAA0D;IAC1D,+DAA+D;IAC/D,oEAAoE;IACpE,IAAI,CAAC,aAAa;QAAE,kBAAkB,CAAC,GAAG,EAAE,CAAA;IAE5C,MAAM,iBAAiB,GAAG,aAAa;QACnC,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE;QAC1B,CAAC,CAAC,SAAS,CAAA;IAEf,MAAM,UAAU,GAAG,iBAAiB;QAChC,CAAC,CAAC,uBAAU,CAAC,WAAW,CAAC,iBAAiB,CAAC;QAC3C,CAAC,CAAC,SAAS,CAAA;IAEf,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,wBAAU,CAAC,UAAU,CAAC,CAAA;IAEjE,OAAO;QACH,MAAM;QACN,OAAO;QACP,SAAS;QACT,UAAU;QACV,WAAW;KACd,CAAA;AACL,CAAC,CAAA;AA5CY,QAAA,gBAAgB,oBA4C5B"}
@@ -0,0 +1,2 @@
1
+ import { SaltGenerator, Hasher } from '../types';
2
+ export declare const createDecoys: (count: number, saltGenerator: SaltGenerator, hasher: Hasher) => Promise<string[]>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createDecoys = void 0;
13
+ const error_1 = require("./error");
14
+ const base64url_1 = require("../base64url");
15
+ const createDecoys = (count, saltGenerator, hasher) => __awaiter(void 0, void 0, void 0, function* () {
16
+ if (count < 0) {
17
+ throw new error_1.SdJwtError(`Negative count of ${count} is not allowed.`);
18
+ }
19
+ if (isNaN(count)) {
20
+ throw new error_1.SdJwtError(`NaN is not allowed for count.`);
21
+ }
22
+ if (!isFinite(count)) {
23
+ throw new error_1.SdJwtError(`Infinite is not allopwed for count.`);
24
+ }
25
+ const decoys = [];
26
+ for (let i = 0; i < count; i++) {
27
+ const salt = yield saltGenerator();
28
+ const decoy = yield hasher(salt);
29
+ const encodedDecoy = base64url_1.Base64url.encode(decoy);
30
+ decoys.push(encodedDecoy);
31
+ }
32
+ return decoys;
33
+ });
34
+ exports.createDecoys = createDecoys;
35
+ //# sourceMappingURL=decoys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decoys.js","sourceRoot":"","sources":["../../src/sdJwt/decoys.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,mCAAoC;AACpC,4CAAwC;AAEjC,MAAM,YAAY,GAAG,CACxB,KAAa,EACb,aAA4B,EAC5B,MAAc,EAChB,EAAE;IACA,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACZ,MAAM,IAAI,kBAAU,CAAC,qBAAqB,KAAK,kBAAkB,CAAC,CAAA;IACtE,CAAC;IAED,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACf,MAAM,IAAI,kBAAU,CAAC,+BAA+B,CAAC,CAAA;IACzD,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,kBAAU,CAAC,qCAAqC,CAAC,CAAA;IAC/D,CAAC;IAED,MAAM,MAAM,GAAkB,EAAE,CAAA;IAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,MAAM,aAAa,EAAE,CAAA;QAClC,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAA;QAChC,MAAM,YAAY,GAAG,qBAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAC5C,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IAC7B,CAAC;IACD,OAAO,MAAM,CAAA;AACjB,CAAC,CAAA,CAAA;AAzBY,QAAA,YAAY,gBAyBxB"}
@@ -0,0 +1,7 @@
1
+ import { DisclosureFrame } from '../types';
2
+ import { Disclosure } from './disclosures';
3
+ import { SaltGenerator, Hasher } from '../types';
4
+ export declare const applyDisclosureFrame: <Payload extends Record<string, unknown> = Record<string, unknown>>(saltGenerator: SaltGenerator, hasher: Hasher, payload: Payload, frame: DisclosureFrame<Payload>, keys?: Array<string>, cleanup?: Array<Array<string>>, disclosures?: Array<Disclosure>) => Promise<{
5
+ payload: Record<string, unknown>;
6
+ disclosures: Array<Disclosure>;
7
+ }>;