@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,73 @@
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.getDisclosuresForPresentationFrame = void 0;
13
+ const utils_1 = require("../utils");
14
+ const error_1 = require("./error");
15
+ const disclosureMapping_1 = require("./disclosureMapping");
16
+ const getDisclosuresForPresentationFrame = (signedPayload, presentationFrame, prettyClaims, hasher, disclosures = []) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const requiredDisclosureDigests = new Set();
18
+ const disclosureMap = yield (0, disclosureMapping_1.getDisclosureMap)(disclosures, hasher);
19
+ const payloadDisclosureMapping = (0, disclosureMapping_1.getPayloadDisclosureMapping)(signedPayload, disclosureMap);
20
+ // No disclosures needed
21
+ if (payloadDisclosureMapping === null) {
22
+ if (disclosures.length > 0) {
23
+ throw new error_1.SdJwtError('Payload disclosure mapping is null, but disclosures are present.');
24
+ }
25
+ return [];
26
+ }
27
+ for (const node of (0, utils_1.traverseNodes)(presentationFrame)) {
28
+ // We only want to process leaf nodes here
29
+ if (!node.isLeaf)
30
+ continue;
31
+ if (typeof node.value !== 'boolean') {
32
+ throw new error_1.SdJwtError(`Expected leaf value in presentation frame to be of type boolean, but found ${typeof node.value}`);
33
+ }
34
+ // If the value is false, it means we don't want to disclose it
35
+ if (node.value === false)
36
+ continue;
37
+ if (!(0, utils_1.hasByPath)(prettyClaims, node.path)) {
38
+ throw new error_1.SdJwtError(`Path ${node.path.join('.')} from presentation frame is not present in pretty SD-JWT payload. The presentation frame may only include properties that are present in the SD-JWT payload.`);
39
+ }
40
+ let path = [...node.path];
41
+ while (!(0, utils_1.hasByPath)(payloadDisclosureMapping, path)) {
42
+ if (path.pop() === undefined)
43
+ break;
44
+ }
45
+ // There are no disclosures on this path, meaning the property is disclosed by default in the signed payload
46
+ if (path.length === 0)
47
+ continue;
48
+ const disclosure = (0, utils_1.getByPath)(payloadDisclosureMapping, path);
49
+ // If disclosure is string, it means it's already the digest
50
+ if (typeof disclosure === 'string')
51
+ requiredDisclosureDigests.add(disclosure);
52
+ // Otherwise we want to get all the child digests as well
53
+ else {
54
+ for (const nestedItem of (0, utils_1.traverseNodes)(disclosure)) {
55
+ if (!nestedItem.isLeaf ||
56
+ typeof nestedItem.value !== 'string') {
57
+ continue;
58
+ }
59
+ requiredDisclosureDigests.add(nestedItem.value);
60
+ }
61
+ }
62
+ }
63
+ for (const disclosureDigest of requiredDisclosureDigests.values()) {
64
+ const disclosure = disclosureMap[disclosureDigest];
65
+ if (!disclosure) {
66
+ throw new Error('disclosure not found');
67
+ }
68
+ yield Promise.all(disclosure.parentDisclosures.map((d) => __awaiter(void 0, void 0, void 0, function* () { return requiredDisclosureDigests.add(yield d.digest(hasher)); })));
69
+ }
70
+ return Array.from(requiredDisclosureDigests).map((digest) => disclosureMap[digest].disclosure);
71
+ });
72
+ exports.getDisclosuresForPresentationFrame = getDisclosuresForPresentationFrame;
73
+ //# sourceMappingURL=presentationFrame.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentationFrame.js","sourceRoot":"","sources":["../../src/sdJwt/presentationFrame.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAA8D;AAE9D,mCAAoC;AAGpC,2DAG4B;AAErB,MAAM,kCAAkC,GAAG,CAG9C,aAAsB,EACtB,iBAA6C,EAC7C,YAAqB,EACrB,MAAc,EACd,cAAiC,EAAE,EACT,EAAE;IAC5B,MAAM,yBAAyB,GAAG,IAAI,GAAG,EAAU,CAAA;IACnD,MAAM,aAAa,GAAG,MAAM,IAAA,oCAAgB,EAAC,WAAW,EAAE,MAAM,CAAC,CAAA;IACjE,MAAM,wBAAwB,GAAG,IAAA,+CAA2B,EACxD,aAAa,EACb,aAAa,CAChB,CAAA;IAED,wBAAwB;IACxB,IAAI,wBAAwB,KAAK,IAAI,EAAE,CAAC;QACpC,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,kBAAU,CAChB,kEAAkE,CACrE,CAAA;QACL,CAAC;QAED,OAAO,EAAE,CAAA;IACb,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,IAAA,qBAAa,EAAC,iBAAiB,CAAC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C,KAAK,CAAC,CAAA;YACnD,CAAC;QACL,CAAC;IACL,CAAC;IAED,KAAK,MAAM,gBAAgB,IAAI,yBAAyB,CAAC,MAAM,EAAE,EAAE,CAAC;QAChE,MAAM,UAAU,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAAA;QAElD,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;QAC3C,CAAC;QAED,MAAM,OAAO,CAAC,GAAG,CACb,UAAU,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAO,CAAC,EAAE,EAAE,kDACzC,OAAA,yBAAyB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA,GAAA,CACxD,CACJ,CAAA;IACL,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC,GAAG,CAC5C,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,UAAU,CAC/C,CAAA;AACL,CAAC,CAAA,CAAA;AA3FY,QAAA,kCAAkC,sCA2F9C"}
@@ -0,0 +1,204 @@
1
+ import { DisclosureFrame, HasherAndAlgorithm, SaltGenerator, Verifier } from '../types';
2
+ import { Jwt, JwtAdditionalOptions, JwtVerificationResult } from '../jwt/jwt';
3
+ import { KeyBinding } from '../keyBinding';
4
+ import { ReturnSdJwtWithHeaderAndPayload, ReturnSdJwtWithKeyBinding, ReturnSdJwtWithPayload } from './types';
5
+ import { Disclosure } from './disclosures';
6
+ import { HasherAlgorithm } from '../hasherAlgorithm';
7
+ import { PresentationFrame } from '../types/present';
8
+ export type SdJwtToCompactOptions<DisclosablePayload extends Record<string, unknown>> = {
9
+ disclosureFrame?: DisclosureFrame<DisclosablePayload>;
10
+ shouldApplyFrame?: boolean;
11
+ };
12
+ export type SdJwtOptions<Header extends Record<string, unknown>, Payload extends Record<string, unknown>> = {
13
+ header?: Header;
14
+ payload?: Payload;
15
+ signature?: Uint8Array;
16
+ keyBinding?: KeyBinding;
17
+ disclosures?: Array<Disclosure>;
18
+ };
19
+ export type SdJwtAdditionalOptions<Payload extends Record<string, unknown>> = JwtAdditionalOptions & {
20
+ hasherAndAlgorithm?: HasherAndAlgorithm;
21
+ saltGenerator?: SaltGenerator;
22
+ disclosureFrame?: DisclosureFrame<Payload>;
23
+ };
24
+ export type SdJwtVerificationResult = JwtVerificationResult & {
25
+ isKeyBindingValid?: boolean;
26
+ };
27
+ export declare class SdJwt<Header extends Record<string, unknown> = Record<string, unknown>, Payload extends Record<string, unknown> = Record<string, unknown>> extends Jwt<Header, Payload> {
28
+ disclosures?: Array<Disclosure>;
29
+ keyBinding?: KeyBinding;
30
+ private saltGenerator?;
31
+ private hasherAndAlgorithm?;
32
+ disclosureFrame?: DisclosureFrame<Payload>;
33
+ constructor(options?: SdJwtOptions<Header, Payload>, additionalOptions?: SdJwtAdditionalOptions<Payload>);
34
+ /**
35
+ *
36
+ * Create an sd-jwt from a compact format. This will succeed for a normal jwt as well.
37
+ *
38
+ */
39
+ static fromCompact<Header extends Record<string, unknown> = Record<string, unknown>, Payload extends Record<string, unknown> = Record<string, unknown>>(compact: string): ReturnSdJwtWithHeaderAndPayload<Header, Payload, SdJwt<Header, Payload>>;
40
+ /**
41
+ *
42
+ * Add a salt generator.
43
+ *
44
+ * Recommended size is 128 bits (i.e. 16 bytes).
45
+ *
46
+ * Salts will not be seeded and a new one will be used for each claim.
47
+ *
48
+ * @example
49
+ *
50
+ * Node.js: `crypto.randomBytes(128 / 8)`
51
+ *
52
+ * React Native: `expo-standard-web-crypto`
53
+ *
54
+ * Browser: `crypto.getRandomValues(new Uint8Array(128 / 8))`
55
+ *
56
+ */
57
+ withSaltGenerator(saltGenerator: SaltGenerator): this;
58
+ /**
59
+ *
60
+ * Add a hasher that will be used to hash the disclosures.
61
+ *
62
+ * @note Make sure to return a base64url encoded version of the hash.
63
+ *
64
+ * @example
65
+ *
66
+ * Node.js: `createHash('sha256').update(input).digest().toString('base64url')`
67
+ *
68
+ */
69
+ withHasher(hasherAndAlgorithm: HasherAndAlgorithm): ReturnSdJwtWithPayload<Header, Payload, this>;
70
+ /**
71
+ *
72
+ * Adds the algorithm of the hasher to the payload.
73
+ *
74
+ * For convience, this also allows you to set the hasher.
75
+ *
76
+ * @throws when the hasher and algorithm are not set.
77
+ *
78
+ */
79
+ addHasherAlgorithmToPayload(hasherAndAlgorithm?: HasherAndAlgorithm): ReturnSdJwtWithPayload<Header, Payload, this>;
80
+ /**
81
+ *
82
+ * Set the `KeyBinding` jwt.
83
+ *
84
+ * This can be done as a holder to provide proof of possession of key material
85
+ *
86
+ */
87
+ withKeyBinding(keyBinding: Jwt | KeyBinding | string): ReturnSdJwtWithKeyBinding<Header, Payload, this>;
88
+ /**
89
+ *
90
+ * Set the disclosure frame which will be applied via `SdJwt.applyDisclosureFrame` or when `SdJwt.toCompact` is called.
91
+ *
92
+ */
93
+ withDisclosureFrame(disclosureFrame: DisclosureFrame<Payload>): this;
94
+ /**
95
+ *
96
+ * Apply the disclosure frame.
97
+ *
98
+ * @throws when the salt generator is not set
99
+ * @throws when the hasher and algorithm is not set
100
+ * @throws when the payload is not set
101
+ * @throws when no disclosure frame is set
102
+ * @throws when disclosures are included and a signature is set, but no signer is provided `*`
103
+ * @throws when the disclosure frame is inconsistent with the payload
104
+ *
105
+ * * This is done as removing items from the payload alters the signature and it has to be resigned.
106
+ *
107
+ */
108
+ applyDisclosureFrame(): Promise<void>;
109
+ /**
110
+ *
111
+ * Assert that the disclosure frame is set.
112
+ *
113
+ */
114
+ assertDisclosureFrame(): void;
115
+ /**
116
+ *
117
+ * Assert that the salt generator is set.
118
+ *
119
+ */
120
+ private assertSaltGenerator;
121
+ /**
122
+ *
123
+ * Assert that the hasher and algorithm is set.
124
+ *
125
+ */
126
+ private assertHashAndAlgorithm;
127
+ /**
128
+ *
129
+ * Assert that a certain claim is included in the disclosure frame.
130
+ *
131
+ * @throws when the disclosure frame is not set
132
+ *
133
+ */
134
+ assertClaimInDisclosureFrame(claimKey: string): void;
135
+ /**
136
+ * This function creates a presentation of an SD-JWT, based on the presentation frame. The
137
+ * presentation frame is similar to the disclosure frame, and allows you to present a subset
138
+ * of the disclosures.
139
+ *
140
+ * If no `presentationFrame` is passed, the entire SD-JWT will be presented.
141
+ * To create a presentation without any of the disclosures, pass an empty object as the `presentationFrame`.
142
+ *
143
+ * @example
144
+ * The following example will expose `name`, `a.nested`, and `orderItems[0]` and `orderItems[2]`.
145
+ * Based on the disclosures it will also expose the parent and child disclosures when needed.
146
+ * E.g. if `a` can only be disclosed as a whole, disclosing `a.nested` will also disclose `a`.
147
+ * The same is true for child disclosures. If you expose `name`, and it potentially contains recursive
148
+ * disclosures, all disclosures under name will be disclosed as well.
149
+ * ```ts
150
+ * await sdJwt.present({
151
+ * name: true,
152
+ * a: {
153
+ * nested: 'property'
154
+ * }
155
+ * orderItems: [true, false, true]
156
+ * })
157
+ * ```
158
+ *
159
+ * @throws when the presentation frame does not match the decoded/pretty payload of the sd-jwt
160
+ * @throws when the presentation frame contains fields other than object, array or boolean
161
+ *
162
+ */
163
+ present(presentationFrame?: PresentationFrame<Payload>): Promise<string>;
164
+ /**
165
+ *
166
+ * Verify the sd-jwt.
167
+ *
168
+ * It validates the following properties:
169
+ * - sd-jwt issuer signature
170
+ * - Optionally, the required claims
171
+ * - The `nbf` and `exp` claims
172
+ * - Whether the key binding is valid
173
+ *
174
+ */
175
+ verify(verifier: Verifier<Header>, requiredClaimKeys?: Array<keyof Payload | string>, publicKeyJwk?: Record<string, unknown>): Promise<SdJwtVerificationResult>;
176
+ /**
177
+ *
178
+ * Utility method to check whether the expected hasher algorithm is used.
179
+ *
180
+ */
181
+ checkHasher(expectedHasher: HasherAlgorithm | string): boolean;
182
+ assertNonSelectivelyDisclosableClaim(claimKey: string): void;
183
+ assertNonSelectivelyDisclosableClaims(): void;
184
+ /**
185
+ *
186
+ * Return all claims from the payload and the disclosures on their original place.
187
+ *
188
+ */
189
+ getPrettyClaims<Claims extends Record<string, unknown> = Payload>(): Promise<Claims>;
190
+ /**
191
+ *
192
+ * Create a compact format of the sd-jwt.
193
+ *
194
+ * This will
195
+ * - Apply the disclosure frame
196
+ * - Add a signature if there is none
197
+ *
198
+ * @throws When the signature and signer are not defined
199
+ * @throws When a claim is requested to be selectively disclosable, but it was not found in the payload
200
+ *
201
+ */
202
+ toCompact(): Promise<string>;
203
+ private __toCompact;
204
+ }
@@ -0,0 +1,383 @@
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.SdJwt = void 0;
13
+ const base64url_1 = require("../base64url");
14
+ const error_1 = require("./error");
15
+ const jwt_1 = require("../jwt/jwt");
16
+ const keyBinding_1 = require("../keyBinding");
17
+ const compact_1 = require("./compact");
18
+ const disclosureFrame_1 = require("./disclosureFrame");
19
+ const swapClaim_1 = require("./swapClaim");
20
+ const utils_1 = require("../utils");
21
+ const presentationFrame_1 = require("./presentationFrame");
22
+ class SdJwt extends jwt_1.Jwt {
23
+ constructor(options, additionalOptions) {
24
+ super(options, additionalOptions);
25
+ this.header = options === null || options === void 0 ? void 0 : options.header;
26
+ this.payload = options === null || options === void 0 ? void 0 : options.payload;
27
+ this.signature = options === null || options === void 0 ? void 0 : options.signature;
28
+ this.disclosures = options === null || options === void 0 ? void 0 : options.disclosures;
29
+ this.keyBinding = options === null || options === void 0 ? void 0 : options.keyBinding;
30
+ if (additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.hasherAndAlgorithm) {
31
+ this.withHasher(additionalOptions.hasherAndAlgorithm);
32
+ }
33
+ if (additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.saltGenerator) {
34
+ this.withSaltGenerator(additionalOptions.saltGenerator);
35
+ }
36
+ if (additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.disclosureFrame) {
37
+ this.withDisclosureFrame(additionalOptions.disclosureFrame);
38
+ }
39
+ if (additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.signer) {
40
+ this.withSigner(additionalOptions.signer);
41
+ }
42
+ }
43
+ /**
44
+ *
45
+ * Create an sd-jwt from a compact format. This will succeed for a normal jwt as well.
46
+ *
47
+ */
48
+ static fromCompact(compact) {
49
+ const { disclosures, keyBinding, signature, payload, header } = (0, compact_1.sdJwtFromCompact)(compact);
50
+ const sdJwt = new SdJwt({
51
+ header,
52
+ payload,
53
+ signature,
54
+ disclosures,
55
+ keyBinding
56
+ });
57
+ return sdJwt;
58
+ }
59
+ /**
60
+ *
61
+ * Add a salt generator.
62
+ *
63
+ * Recommended size is 128 bits (i.e. 16 bytes).
64
+ *
65
+ * Salts will not be seeded and a new one will be used for each claim.
66
+ *
67
+ * @example
68
+ *
69
+ * Node.js: `crypto.randomBytes(128 / 8)`
70
+ *
71
+ * React Native: `expo-standard-web-crypto`
72
+ *
73
+ * Browser: `crypto.getRandomValues(new Uint8Array(128 / 8))`
74
+ *
75
+ */
76
+ withSaltGenerator(saltGenerator) {
77
+ this.saltGenerator = saltGenerator;
78
+ return this;
79
+ }
80
+ /**
81
+ *
82
+ * Add a hasher that will be used to hash the disclosures.
83
+ *
84
+ * @note Make sure to return a base64url encoded version of the hash.
85
+ *
86
+ * @example
87
+ *
88
+ * Node.js: `createHash('sha256').update(input).digest().toString('base64url')`
89
+ *
90
+ */
91
+ withHasher(hasherAndAlgorithm) {
92
+ this.hasherAndAlgorithm = hasherAndAlgorithm;
93
+ return this;
94
+ }
95
+ /**
96
+ *
97
+ * Adds the algorithm of the hasher to the payload.
98
+ *
99
+ * For convience, this also allows you to set the hasher.
100
+ *
101
+ * @throws when the hasher and algorithm are not set.
102
+ *
103
+ */
104
+ addHasherAlgorithmToPayload(hasherAndAlgorithm) {
105
+ if (hasherAndAlgorithm)
106
+ this.withHasher(hasherAndAlgorithm);
107
+ this.assertHashAndAlgorithm();
108
+ this.addPayloadClaim('_sd_alg', this.hasherAndAlgorithm.algorithm);
109
+ return this;
110
+ }
111
+ /**
112
+ *
113
+ * Set the `KeyBinding` jwt.
114
+ *
115
+ * This can be done as a holder to provide proof of possession of key material
116
+ *
117
+ */
118
+ withKeyBinding(keyBinding) {
119
+ const kb = typeof keyBinding === 'string'
120
+ ? keyBinding_1.KeyBinding.fromCompact(keyBinding)
121
+ : keyBinding instanceof keyBinding_1.KeyBinding
122
+ ? keyBinding
123
+ : keyBinding_1.KeyBinding.fromJwt(keyBinding);
124
+ this.keyBinding = kb;
125
+ return this;
126
+ }
127
+ /**
128
+ *
129
+ * Set the disclosure frame which will be applied via `SdJwt.applyDisclosureFrame` or when `SdJwt.toCompact` is called.
130
+ *
131
+ */
132
+ withDisclosureFrame(disclosureFrame) {
133
+ this.disclosureFrame = disclosureFrame;
134
+ return this;
135
+ }
136
+ /**
137
+ *
138
+ * Apply the disclosure frame.
139
+ *
140
+ * @throws when the salt generator is not set
141
+ * @throws when the hasher and algorithm is not set
142
+ * @throws when the payload is not set
143
+ * @throws when no disclosure frame is set
144
+ * @throws when disclosures are included and a signature is set, but no signer is provided `*`
145
+ * @throws when the disclosure frame is inconsistent with the payload
146
+ *
147
+ * * This is done as removing items from the payload alters the signature and it has to be resigned.
148
+ *
149
+ */
150
+ applyDisclosureFrame() {
151
+ return __awaiter(this, void 0, void 0, function* () {
152
+ this.assertSaltGenerator();
153
+ this.assertHashAndAlgorithm();
154
+ this.assertPayload();
155
+ this.assertDisclosureFrame();
156
+ if (this.disclosures &&
157
+ this.disclosures.length > 0 &&
158
+ this.signature &&
159
+ !this.signer) {
160
+ throw new error_1.SdJwtError('Signature is already set by the user when selectively disclosable items still have to be removed. This will invalidate the signature. Try to provide a signer on SdJwt.withSigner and SdJwt.toCompact will call it at the correct time.');
161
+ }
162
+ const { payload: framedPayload, disclosures } = yield (0, disclosureFrame_1.applyDisclosureFrame)(this.saltGenerator, this.hasherAndAlgorithm.hasher, this.addHasherAlgorithmToPayload().payload, this.disclosureFrame);
163
+ this.disclosures = disclosures;
164
+ this.payload = framedPayload;
165
+ });
166
+ }
167
+ /**
168
+ *
169
+ * Assert that the disclosure frame is set.
170
+ *
171
+ */
172
+ assertDisclosureFrame() {
173
+ if (this.disclosureFrame)
174
+ return;
175
+ throw new error_1.SdJwtError('Disclosureframe must be defined');
176
+ }
177
+ /**
178
+ *
179
+ * Assert that the salt generator is set.
180
+ *
181
+ */
182
+ assertSaltGenerator() {
183
+ if (!this.saltGenerator) {
184
+ throw new error_1.SdJwtError('Cannot create a disclosure without a salt generator. You can set it with this.withSaltGenerator()');
185
+ }
186
+ }
187
+ /**
188
+ *
189
+ * Assert that the hasher and algorithm is set.
190
+ *
191
+ */
192
+ assertHashAndAlgorithm() {
193
+ if (!this.hasherAndAlgorithm) {
194
+ throw new error_1.SdJwtError('A hasher and algorithm must be set in order to create a digest of a disclosure. You can set it with this.withHasherAndAlgorithm()');
195
+ }
196
+ }
197
+ /**
198
+ *
199
+ * Assert that a certain claim is included in the disclosure frame.
200
+ *
201
+ * @throws when the disclosure frame is not set
202
+ *
203
+ */
204
+ assertClaimInDisclosureFrame(claimKey) {
205
+ this.assertDisclosureFrame();
206
+ const value = (0, utils_1.getValueByKeyAnyLevel)(this.disclosureFrame, claimKey);
207
+ if (!value) {
208
+ throw new error_1.SdJwtError(`Claim key '${claimKey}' not found in any level of the disclosureFrame`);
209
+ }
210
+ }
211
+ /**
212
+ * This function creates a presentation of an SD-JWT, based on the presentation frame. The
213
+ * presentation frame is similar to the disclosure frame, and allows you to present a subset
214
+ * of the disclosures.
215
+ *
216
+ * If no `presentationFrame` is passed, the entire SD-JWT will be presented.
217
+ * To create a presentation without any of the disclosures, pass an empty object as the `presentationFrame`.
218
+ *
219
+ * @example
220
+ * The following example will expose `name`, `a.nested`, and `orderItems[0]` and `orderItems[2]`.
221
+ * Based on the disclosures it will also expose the parent and child disclosures when needed.
222
+ * E.g. if `a` can only be disclosed as a whole, disclosing `a.nested` will also disclose `a`.
223
+ * The same is true for child disclosures. If you expose `name`, and it potentially contains recursive
224
+ * disclosures, all disclosures under name will be disclosed as well.
225
+ * ```ts
226
+ * await sdJwt.present({
227
+ * name: true,
228
+ * a: {
229
+ * nested: 'property'
230
+ * }
231
+ * orderItems: [true, false, true]
232
+ * })
233
+ * ```
234
+ *
235
+ * @throws when the presentation frame does not match the decoded/pretty payload of the sd-jwt
236
+ * @throws when the presentation frame contains fields other than object, array or boolean
237
+ *
238
+ */
239
+ present(presentationFrame) {
240
+ var _a;
241
+ return __awaiter(this, void 0, void 0, function* () {
242
+ if (!this.disclosures && this.disclosureFrame) {
243
+ yield this.applyDisclosureFrame();
244
+ }
245
+ // TODO: wouldn't it be easier if this returned the value so we don't have to use !
246
+ this.assertHashAndAlgorithm();
247
+ this.assertPayload();
248
+ // If no presentationFrame is passed, we want to disclose everything
249
+ if (!presentationFrame) {
250
+ return yield this.__toCompact(this.disclosures, false);
251
+ }
252
+ if ((Object.keys(presentationFrame).length > 0 && !this.disclosures) ||
253
+ ((_a = this.disclosures) === null || _a === void 0 ? void 0 : _a.length) === 0) {
254
+ throw new error_1.SdJwtError('Cannot create a presentation with disclosures while no disclosures are on the sd-jwt');
255
+ }
256
+ const requiredDisclosures = yield (0, presentationFrame_1.getDisclosuresForPresentationFrame)(this.payload, presentationFrame, yield this.getPrettyClaims(), this.hasherAndAlgorithm.hasher, this.disclosures);
257
+ return yield this.__toCompact(requiredDisclosures, false);
258
+ });
259
+ }
260
+ /**
261
+ *
262
+ * Verify the sd-jwt.
263
+ *
264
+ * It validates the following properties:
265
+ * - sd-jwt issuer signature
266
+ * - Optionally, the required claims
267
+ * - The `nbf` and `exp` claims
268
+ * - Whether the key binding is valid
269
+ *
270
+ */
271
+ verify(verifier, requiredClaimKeys, publicKeyJwk) {
272
+ const _super = Object.create(null, {
273
+ verify: { get: () => super.verify }
274
+ });
275
+ var _a;
276
+ return __awaiter(this, void 0, void 0, function* () {
277
+ this.assertSignature();
278
+ const jwtVerificationResult = (yield _super.verify.call(this, verifier, requiredClaimKeys));
279
+ if (this.keyBinding) {
280
+ const { isValid } = yield this.keyBinding.verify(verifier, [], publicKeyJwk);
281
+ jwtVerificationResult.isKeyBindingValid = isValid;
282
+ }
283
+ const claimKeys = (0, utils_1.getAllKeys)(this.payload).concat(((_a = this.disclosures) !== null && _a !== void 0 ? _a : []).map((d) => d.decoded[1]));
284
+ if (requiredClaimKeys) {
285
+ jwtVerificationResult.areRequiredClaimsIncluded =
286
+ requiredClaimKeys.every((key) => claimKeys.includes(key));
287
+ }
288
+ return Object.assign(Object.assign({}, jwtVerificationResult), { isValid: Object.entries(jwtVerificationResult)
289
+ .filter(([key, value]) => typeof value === 'boolean' && key !== 'isValid')
290
+ .every(([, value]) => !!value) });
291
+ });
292
+ }
293
+ /**
294
+ *
295
+ * Utility method to check whether the expected hasher algorithm is used.
296
+ *
297
+ */
298
+ checkHasher(expectedHasher) {
299
+ try {
300
+ this.assertPayload();
301
+ this.assertClaimInPayload('_sd_alg', expectedHasher.toString());
302
+ return true;
303
+ }
304
+ catch (e) {
305
+ console.error(e);
306
+ return false;
307
+ }
308
+ }
309
+ assertNonSelectivelyDisclosableClaim(claimKey) {
310
+ try {
311
+ this.assertClaimInDisclosureFrame(claimKey);
312
+ }
313
+ catch (_a) {
314
+ return;
315
+ }
316
+ throw new error_1.SdJwtError(`Claim key '${claimKey}' was found in the disclosure frame. This claim is not allowed to be selectively disclosed`);
317
+ }
318
+ assertNonSelectivelyDisclosableClaims() {
319
+ if (!this.disclosureFrame)
320
+ return;
321
+ ['_sd', '_sd_alg', '...'].forEach(this.assertNonSelectivelyDisclosableClaim);
322
+ }
323
+ /**
324
+ *
325
+ * Return all claims from the payload and the disclosures on their original place.
326
+ *
327
+ */
328
+ getPrettyClaims() {
329
+ var _a;
330
+ return __awaiter(this, void 0, void 0, function* () {
331
+ this.assertPayload();
332
+ this.assertHashAndAlgorithm();
333
+ const newPayload = yield (0, swapClaim_1.swapClaims)(this.hasherAndAlgorithm.hasher, this.payload, (_a = this.disclosures) !== null && _a !== void 0 ? _a : []);
334
+ return newPayload;
335
+ });
336
+ }
337
+ /**
338
+ *
339
+ * Create a compact format of the sd-jwt.
340
+ *
341
+ * This will
342
+ * - Apply the disclosure frame
343
+ * - Add a signature if there is none
344
+ *
345
+ * @throws When the signature and signer are not defined
346
+ * @throws When a claim is requested to be selectively disclosable, but it was not found in the payload
347
+ *
348
+ */
349
+ toCompact() {
350
+ return __awaiter(this, void 0, void 0, function* () {
351
+ return this.__toCompact();
352
+ });
353
+ }
354
+ __toCompact(disclosures = this.disclosures, shouldApplyFrame = true) {
355
+ var _a, _b;
356
+ return __awaiter(this, void 0, void 0, function* () {
357
+ this.assertHeader();
358
+ this.assertPayload();
359
+ yield ((_a = this.keyBinding) === null || _a === void 0 ? void 0 : _a.assertValidForKeyBinding());
360
+ if (this.disclosureFrame && shouldApplyFrame) {
361
+ yield this.applyDisclosureFrame();
362
+ }
363
+ disclosures !== null && disclosures !== void 0 ? disclosures : (disclosures = this.disclosures);
364
+ const compactHeader = base64url_1.Base64url.encode(JSON.stringify(this.header));
365
+ const compactPayload = base64url_1.Base64url.encode(JSON.stringify(this.payload));
366
+ const sSignature = this.signature
367
+ ? base64url_1.Base64url.encode(this.signature)
368
+ : base64url_1.Base64url.encode((yield this.signAndAdd()).signature);
369
+ const sDisclosures = disclosures && disclosures.length > 0
370
+ ? `~${disclosures.join('~')}~`
371
+ : '';
372
+ const kb = yield ((_b = this.keyBinding) === null || _b === void 0 ? void 0 : _b.toCompact());
373
+ const sKeyBinding = this.keyBinding
374
+ ? sDisclosures.length > 0
375
+ ? kb
376
+ : `~${kb}`
377
+ : '';
378
+ return `${compactHeader}.${compactPayload}.${sSignature}${sDisclosures}${sKeyBinding}`;
379
+ });
380
+ }
381
+ }
382
+ exports.SdJwt = SdJwt;
383
+ //# sourceMappingURL=sdJwt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdJwt.js","sourceRoot":"","sources":["../../src/sdJwt/sdJwt.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAwC;AACxC,mCAAoC;AAOpC,oCAA6E;AAC7E,8CAA0C;AAM1C,uCAA4C;AAE5C,uDAAwD;AACxD,2CAAwC;AACxC,oCAA4D;AAG5D,2DAAwE;AA+BxE,MAAa,KAGX,SAAQ,SAAoB;IAQ1B,YACI,OAAuC,EACvC,iBAAmD;QAEnD,KAAK,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAA;QACjC,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;QACnC,IAAI,CAAC,WAAW,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAA;QACvC,IAAI,CAAC,UAAU,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,CAAA;QAErC,IAAI,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,kBAAkB,EAAE,CAAC;YACxC,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAA;QACzD,CAAC;QAED,IAAI,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,aAAa,EAAE,CAAC;YACnC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