@sd-jwt/core 0.2.1 → 2.0.2-next.26

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 (146) hide show
  1. package/LICENSE +201 -0
  2. package/dist/index.d.mts +106 -0
  3. package/dist/index.d.ts +106 -0
  4. package/dist/index.js +606 -0
  5. package/dist/index.mjs +586 -0
  6. package/package.json +60 -48
  7. package/src/decoy.ts +15 -0
  8. package/src/index.ts +235 -0
  9. package/src/jwt.ts +107 -0
  10. package/src/kbjwt.ts +45 -0
  11. package/src/sdjwt.ts +318 -0
  12. package/src/test/decoy.spec.ts +30 -0
  13. package/src/test/index.spec.ts +379 -0
  14. package/src/test/jwt.spec.ts +141 -0
  15. package/src/test/kbjwt.spec.ts +275 -0
  16. package/src/test/pass.spec.ts +6 -0
  17. package/src/test/sdjwt.spec.ts +382 -0
  18. package/test/app-e2e.spec.ts +248 -0
  19. package/test/array_data_types.json +29 -0
  20. package/test/array_full_sd.json +21 -0
  21. package/test/array_in_sd.json +13 -0
  22. package/test/array_nested_in_plain.json +20 -0
  23. package/test/array_none_disclosed.json +17 -0
  24. package/test/array_of_nulls.json +15 -0
  25. package/test/array_of_objects.json +58 -0
  26. package/test/array_of_scalars.json +15 -0
  27. package/test/array_recursive_sd.json +35 -0
  28. package/test/array_recursive_sd_some_disclosed.json +55 -0
  29. package/test/complex.json +43 -0
  30. package/test/header_mod.json +44 -0
  31. package/test/json_serialization.json +44 -0
  32. package/test/key_binding.json +44 -0
  33. package/test/no_sd.json +36 -0
  34. package/test/object_data_types.json +60 -0
  35. package/test/recursions.json +98 -0
  36. package/tsconfig.json +7 -0
  37. package/vitest.config.mts +4 -0
  38. package/README.md +0 -97
  39. package/build/base64url.d.ts +0 -28
  40. package/build/base64url.js +0 -40
  41. package/build/base64url.js.map +0 -1
  42. package/build/hasherAlgorithm.d.ts +0 -70
  43. package/build/hasherAlgorithm.js +0 -75
  44. package/build/hasherAlgorithm.js.map +0 -1
  45. package/build/index.d.ts +0 -13
  46. package/build/index.js +0 -20
  47. package/build/index.js.map +0 -1
  48. package/build/jwt/compact.d.ts +0 -6
  49. package/build/jwt/compact.js +0 -27
  50. package/build/jwt/compact.js.map +0 -1
  51. package/build/jwt/error.d.ts +0 -2
  52. package/build/jwt/error.js +0 -7
  53. package/build/jwt/error.js.map +0 -1
  54. package/build/jwt/index.d.ts +0 -2
  55. package/build/jwt/index.js +0 -19
  56. package/build/jwt/index.js.map +0 -1
  57. package/build/jwt/jwt.d.ts +0 -208
  58. package/build/jwt/jwt.js +0 -325
  59. package/build/jwt/jwt.js.map +0 -1
  60. package/build/keyBinding/index.d.ts +0 -1
  61. package/build/keyBinding/index.js +0 -18
  62. package/build/keyBinding/index.js.map +0 -1
  63. package/build/keyBinding/keyBinding.d.ts +0 -64
  64. package/build/keyBinding/keyBinding.js +0 -119
  65. package/build/keyBinding/keyBinding.js.map +0 -1
  66. package/build/sdJwt/compact.d.ts +0 -8
  67. package/build/sdJwt/compact.js +0 -39
  68. package/build/sdJwt/compact.js.map +0 -1
  69. package/build/sdJwt/decoys.d.ts +0 -3
  70. package/build/sdJwt/decoys.js +0 -35
  71. package/build/sdJwt/decoys.js.map +0 -1
  72. package/build/sdJwt/disclosureFrame.d.ts +0 -8
  73. package/build/sdJwt/disclosureFrame.js +0 -87
  74. package/build/sdJwt/disclosureFrame.js.map +0 -1
  75. package/build/sdJwt/disclosureMapping.d.ts +0 -43
  76. package/build/sdJwt/disclosureMapping.js +0 -278
  77. package/build/sdJwt/disclosureMapping.js.map +0 -1
  78. package/build/sdJwt/disclosures.d.ts +0 -33
  79. package/build/sdJwt/disclosures.js +0 -114
  80. package/build/sdJwt/disclosures.js.map +0 -1
  81. package/build/sdJwt/error.d.ts +0 -2
  82. package/build/sdJwt/error.js +0 -7
  83. package/build/sdJwt/error.js.map +0 -1
  84. package/build/sdJwt/index.d.ts +0 -6
  85. package/build/sdJwt/index.js +0 -23
  86. package/build/sdJwt/index.js.map +0 -1
  87. package/build/sdJwt/presentationFrame.d.ts +0 -3
  88. package/build/sdJwt/presentationFrame.js +0 -64
  89. package/build/sdJwt/presentationFrame.js.map +0 -1
  90. package/build/sdJwt/sdJwt.d.ts +0 -206
  91. package/build/sdJwt/sdJwt.js +0 -442
  92. package/build/sdJwt/sdJwt.js.map +0 -1
  93. package/build/sdJwt/swapClaim.d.ts +0 -2
  94. package/build/sdJwt/swapClaim.js +0 -79
  95. package/build/sdJwt/swapClaim.js.map +0 -1
  96. package/build/sdJwt/types.d.ts +0 -5
  97. package/build/sdJwt/types.js +0 -3
  98. package/build/sdJwt/types.js.map +0 -1
  99. package/build/sdJwtVc/error.d.ts +0 -2
  100. package/build/sdJwtVc/error.js +0 -7
  101. package/build/sdJwtVc/error.js.map +0 -1
  102. package/build/sdJwtVc/index.d.ts +0 -2
  103. package/build/sdJwtVc/index.js +0 -19
  104. package/build/sdJwtVc/index.js.map +0 -1
  105. package/build/sdJwtVc/sdJwtVc.d.ts +0 -47
  106. package/build/sdJwtVc/sdJwtVc.js +0 -149
  107. package/build/sdJwtVc/sdJwtVc.js.map +0 -1
  108. package/build/signatureAndEncryptionAlgorithm.d.ts +0 -105
  109. package/build/signatureAndEncryptionAlgorithm.js +0 -110
  110. package/build/signatureAndEncryptionAlgorithm.js.map +0 -1
  111. package/build/types/disclosure.d.ts +0 -5
  112. package/build/types/disclosure.js +0 -3
  113. package/build/types/disclosure.js.map +0 -1
  114. package/build/types/frame.d.ts +0 -5
  115. package/build/types/frame.js +0 -3
  116. package/build/types/frame.js.map +0 -1
  117. package/build/types/hasher.d.ts +0 -14
  118. package/build/types/hasher.js +0 -3
  119. package/build/types/hasher.js.map +0 -1
  120. package/build/types/index.d.ts +0 -5
  121. package/build/types/index.js +0 -22
  122. package/build/types/index.js.map +0 -1
  123. package/build/types/present.d.ts +0 -2
  124. package/build/types/present.js +0 -3
  125. package/build/types/present.js.map +0 -1
  126. package/build/types/saltGenerator.d.ts +0 -17
  127. package/build/types/saltGenerator.js +0 -3
  128. package/build/types/saltGenerator.js.map +0 -1
  129. package/build/types/signer.d.ts +0 -2
  130. package/build/types/signer.js +0 -3
  131. package/build/types/signer.js.map +0 -1
  132. package/build/types/utils.d.ts +0 -2
  133. package/build/types/utils.js +0 -3
  134. package/build/types/utils.js.map +0 -1
  135. package/build/types/verifier.d.ts +0 -14
  136. package/build/types/verifier.js +0 -3
  137. package/build/types/verifier.js.map +0 -1
  138. package/build/utils/index.d.ts +0 -2
  139. package/build/utils/index.js +0 -19
  140. package/build/utils/index.js.map +0 -1
  141. package/build/utils/traverse.d.ts +0 -8
  142. package/build/utils/traverse.js +0 -29
  143. package/build/utils/traverse.js.map +0 -1
  144. package/build/utils/utils.d.ts +0 -8
  145. package/build/utils/utils.js +0 -118
  146. package/build/utils/utils.js.map +0 -1
@@ -1,87 +0,0 @@
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.applyDisclosureFrame = void 0;
13
- const utils_1 = require("@sd-jwt/utils");
14
- const decoys_1 = require("./decoys");
15
- const disclosures_1 = require("./disclosures");
16
- const error_1 = require("./error");
17
- const applyDisclosureFrame = (saltGenerator, hasherAndAlgorithm, payload, frame, keys = [], cleanup = [], disclosures = []) => __awaiter(void 0, void 0, void 0, function* () {
18
- var _a, _b;
19
- for (const [key, frameValue] of Object.entries(frame)) {
20
- const newKeys = [...keys, key];
21
- if (key === '__decoyCount' && typeof frameValue === 'number') {
22
- const sd = Array.from((_a = payload._sd) !== null && _a !== void 0 ? _a : []);
23
- const decoys = yield (0, decoys_1.createDecoys)(frameValue, saltGenerator, hasherAndAlgorithm);
24
- decoys.forEach((digest) => sd.push(digest));
25
- // @ts-ignore
26
- payload._sd = sd.sort();
27
- }
28
- else if (typeof frameValue === 'boolean') {
29
- if (frameValue === true) {
30
- if (!(key in payload)) {
31
- throw new error_1.SdJwtError(`key, ${key}, is not inside the payload (${JSON.stringify(payload)}), but it was supplied inside the frame.`);
32
- }
33
- const salt = yield saltGenerator();
34
- const disclosure = yield new disclosures_1.Disclosure(salt, payload[key], key).withCalculateDigest(hasherAndAlgorithm);
35
- disclosures.push(disclosure);
36
- const sd = Array.from((_b = payload._sd) !== null && _b !== void 0 ? _b : []);
37
- sd.push(disclosure.digest);
38
- //@ts-ignore
39
- payload._sd = sd.sort();
40
- cleanup.push(newKeys);
41
- }
42
- }
43
- else if (typeof frameValue === 'object' &&
44
- !Array.isArray(frameValue)) {
45
- yield (0, exports.applyDisclosureFrame)(saltGenerator, hasherAndAlgorithm, payload[key], frameValue, newKeys, cleanup, disclosures);
46
- }
47
- else if (typeof frameValue === 'object' &&
48
- Array.isArray(frameValue)) {
49
- const payloadArray = payload[key];
50
- const frameValueArray = frameValue;
51
- if (!Array.isArray(payloadArray)) {
52
- throw new error_1.SdJwtError(`Frame expected array, but received ${typeof payload[key]} for key '${key}'.`);
53
- }
54
- if (frameValueArray.length > payloadArray.length) {
55
- throw new error_1.SdJwtError(`Frame array is longer than the payload array for ${key}`);
56
- }
57
- // Fill the frame with `false` if the payloadArray is longer than the frame value array
58
- if (payloadArray.length > frameValueArray.length) {
59
- payloadArray.forEach((_, index) => { var _a; return ((_a = frameValueArray[index]) !== null && _a !== void 0 ? _a : (frameValueArray[index] = false)); });
60
- }
61
- const newPayloadArray = [];
62
- for (let i = 0; i < payloadArray.length; i++) {
63
- const payloadValue = payloadArray[i];
64
- const frameValue = frameValueArray[i];
65
- if (frameValue) {
66
- const salt = yield saltGenerator();
67
- const disclosure = yield new disclosures_1.Disclosure(salt, payloadValue).withCalculateDigest(hasherAndAlgorithm);
68
- disclosures.push(disclosure);
69
- newPayloadArray.push({ '...': disclosure.digest });
70
- }
71
- else {
72
- newPayloadArray.push(payloadValue);
73
- }
74
- }
75
- // @ts-ignore
76
- payload[key] = newPayloadArray;
77
- }
78
- else {
79
- throw new error_1.SdJwtError(`Invalid type in frame with key '${key}' and type '${typeof frameValue}'. Only Record<string, unknown>, arrays<boolean> and boolean are allowed.`);
80
- }
81
- }
82
- const payloadClone = Object.assign({}, payload);
83
- cleanup.forEach((path) => (0, utils_1.deleteByPath)(payloadClone, path));
84
- return { payload: payloadClone, disclosures };
85
- });
86
- exports.applyDisclosureFrame = applyDisclosureFrame;
87
- //# sourceMappingURL=disclosureFrame.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"disclosureFrame.js","sourceRoot":"","sources":["../../src/sdJwt/disclosureFrame.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,yCAA4C;AAC5C,qCAAuC;AACvC,+CAAgE;AAChE,mCAAoC;AAI7B,MAAM,oBAAoB,GAAG,CAGhC,aAA4B,EAC5B,kBAAsC,EACtC,OAAgB,EAChB,KAA+B,EAC/B,OAAsB,EAAE,EACxB,UAAgC,EAAE,EAClC,cAA2C,EAAE,EAI9C,EAAE;;IACD,KAAK,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACpD,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,CAAA;QAE9B,IAAI,GAAG,KAAK,cAAc,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;YAC3D,MAAM,EAAE,GAAkB,KAAK,CAAC,IAAI,CAChC,MAAC,OAAO,CAAC,GAAgB,mCAAI,EAAE,CAClC,CAAA;YAED,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAY,EAC7B,UAAU,E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,YAAY,CACf,CAAC,mBAAmB,CAAC,kBAAkB,CAAC,CAAA;oBACzC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;oBAE5B,eAAe,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAA;gBACtD,CAAC;qBAAM,CAAC;oBACJ,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;gBACtC,CAAC;YACL,CAAC;YAED,aAAa;YACb,OAAO,CAAC,GAAG,CAAC,GAAG,eAAe,CAAA;QAClC,CAAC;aAAM,CAAC;YACJ,MAAM,IAAI,kBAAU,CAChB,mCAAmC,GAAG,eAAe,OAAO,UAAU,2EAA2E,CACpJ,CAAA;QACL,CAAC;IACL,CAAC;IAED,MAAM,YAAY,qBAAQ,OAAO,CAAE,CAAA;IACnC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,oBAAY,EAAC,YAAY,EAAE,IAAI,CAAC,CAAC,CAAA;IAE3D,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,CAAA;AACjD,CAAC,CAAA,CAAA;AArIY,QAAA,oBAAoB,wBAqIhC"}
@@ -1,43 +0,0 @@
1
- import { DisclosureWithDigest } from './disclosures';
2
- /**
3
- * Mapping from a digest to the corresponding disclosure and its parent disclosures.
4
- */
5
- export type DisclosureMap = {
6
- [digest: string]: {
7
- disclosure: DisclosureWithDigest;
8
- parentDisclosures: DisclosureWithDigest[];
9
- };
10
- };
11
- /**
12
- * Get a mapping in the structure of the pretty payload, to indicate which digests should be disclosed for a
13
- * given entry.
14
- *
15
- * For example if you call this method with the following payload:
16
- * ```ts
17
- * {
18
- * _sd: ['iss_digest', 'nested_field_digest'],
19
- * }
20
- * ```
21
- *
22
- * It can return the following mapping:
23
- * ```ts
24
- * {
25
- * iss: 'iss_digest',
26
- * nested_field: {
27
- * __digest: 'nested_field_digest',
28
- * more_nested_field: {
29
- * // index 1 is null, as it's always in the payload, so doesn't need to be disclosed
30
- * // separately
31
- * a: ['a_0_digest', null, 'a_2_digest'],
32
- * }
33
- * }
34
- * }
35
- * ```
36
- *
37
- * This method will recursively call itself and `getArrayPayloadDisclosureMapping` if the value of a property is an object or array.
38
- */
39
- export declare function getPayloadDisclosureMapping(payload: any, map: DisclosureMap): any[] | Record<string, unknown> | null;
40
- /**
41
- * Get a mapping from a digest to the corresponding disclosure and its parent disclosures.
42
- */
43
- export declare const getDisclosureMap: (disclosures: DisclosureWithDigest[]) => DisclosureMap;
@@ -1,278 +0,0 @@
1
- "use strict";
2
- // This file contains helpers functions for mapping between disclosures entries and the payload of an SD-JWT.
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getDisclosureMap = exports.getPayloadDisclosureMapping = void 0;
5
- const utils_1 = require("../utils");
6
- const error_1 = require("./error");
7
- /**
8
- * Returns an array that includes the digests that should be disclosed for each item in the array.
9
- *
10
- * E.g. if the following array is passed:
11
- * ```ts
12
- * [ { '...': <SD_HASH_DIGEST_1> }, 'string_value', { '...': <SD_HASH_DIGEST_2> } ]
13
- * ```
14
- *
15
- * The return value will be:
16
- * ```ts
17
- * ['<SD_HASH_DIGEST_1>', null, '<SD_HASH_DIGEST_2>']
18
- * ```
19
- *
20
- * The second value will be null, as it's already disclosed, and thus there's no digests that
21
- * need to be disclosed to reveal it. For the other values, it will include the digest that needs
22
- * to be disclosed to reveal that array entry.
23
- *
24
- * In the case the array entry contains nested disclosures, the value will not be a digest, but rather
25
- * the structure of the nested disclosures.
26
- *
27
- * Let's say the `<SD_HASH_DIGEST_1>` is the digest of the following disclosure:
28
- * ```ts
29
- * {
30
- * // `<SD_HASH_DIGEST_3>` is the digest of the dateOfBirth property
31
- * _sd: ['<SD_HASH_DIGEST_3>'],
32
- * name: 'Jane Doe',
33
- * }
34
- * ```
35
- *
36
- * In this case the return value will be:
37
- * ```ts
38
- * [{ __digest: '<SD_HASH_DIGEST_1>', dateOfBirth: '<SD_HASH_DIGEST_3>' }, null, '<SD_HASH_DIGEST_2>']
39
- * ```
40
- * The `__digest` property indicates the digest of the encapsulating disclosure, and it being an object
41
- * indicates that there's nested disclosures that need to be revealed.
42
- *
43
- * In the end the result value is an array, and all the string values in the return value are the digests.
44
- * This allows you to easily build a path of digests to disclose to reveal a certain value.
45
- *
46
- * The return value can be endlessly nested, and will also call `getPayloadDisclosureMapping` recursively
47
- * if the inner values are not arrays, but objects. That method in turn can call this method if the value
48
- * of an object property is an array.
49
- */
50
- function getArrayPayloadDisclosureMapping(array, map) {
51
- const arrayPayloadDisclosureMapping = [];
52
- // Loop through all the payload values of the array
53
- for (const item of array) {
54
- // If the item is an object, (both array and object are objects)
55
- // it means there may be some values in here that need to be disclosed to
56
- // reveal this array entry
57
- if (item instanceof Object) {
58
- // if Array item is { '...': <SD_HASH_DIGEST> }
59
- // It means this item can be disclosed.
60
- if ('...' in item) {
61
- const digest = item['...'];
62
- if (typeof digest !== 'string') {
63
- throw new error_1.SdJwtError(`Expected value of key '...' to be of type string, but found ${typeof digest}`);
64
- }
65
- // Look up disclosure. It's valid that the disclosure is not present (decoy digests)
66
- const disclosed = map[digest];
67
- if (disclosed) {
68
- // value is always the last item in the disclosure array
69
- const value = [...disclosed.disclosure.decoded].pop();
70
- // Recursively look if the disclosed value contains any disclosure references
71
- // of itself. Based on the type we can decide how to handle it.
72
- if ((0, utils_1.isObject)(value)) {
73
- // Get nested disclosures for the object value
74
- const unpacked = getPayloadDisclosureMapping(value, map);
75
- // If there's any nested disclosures, we need to include both this item's
76
- // disclosure, as well as the nested disclosures
77
- if (unpacked && Object.keys(unpacked).length > 0) {
78
- arrayPayloadDisclosureMapping.push(Object.assign(Object.assign({}, unpacked), { __digest: digest }));
79
- }
80
- else {
81
- arrayPayloadDisclosureMapping.push(digest);
82
- }
83
- }
84
- else if (Array.isArray(value)) {
85
- // Get nested disclosures for the array value
86
- const nestedUnpackedArray = getArrayPayloadDisclosureMapping(value, map);
87
- // If all entries are null, it means there's no nested disclosures
88
- // And thus we push the digest directly
89
- if (nestedUnpackedArray.every((item) => item === null)) {
90
- arrayPayloadDisclosureMapping.push(digest);
91
- }
92
- else {
93
- arrayPayloadDisclosureMapping.push(Object.assign(Object.assign({}, nestedUnpackedArray), {
94
- // __digest is for encapsulating disclosure
95
- __digest: digest }));
96
- }
97
- }
98
- // If the value is not an object or a array, it means there's no nested disclosures
99
- // and thus we can push the digest directly
100
- else {
101
- arrayPayloadDisclosureMapping.push(digest);
102
- }
103
- }
104
- else {
105
- // Value is not a disclosure for an array ('...') so we unpack the object recursively
106
- const claims = getPayloadDisclosureMapping(item, map);
107
- if (claims && Object.keys(claims).length > 0) {
108
- arrayPayloadDisclosureMapping.push(claims);
109
- }
110
- else {
111
- arrayPayloadDisclosureMapping.push(null);
112
- }
113
- }
114
- }
115
- }
116
- // If the value is not an Object it means the actual value is disclosed
117
- // in the array directly (so we don't need to disclose anything to reveal it)
118
- else {
119
- arrayPayloadDisclosureMapping.push(null);
120
- }
121
- }
122
- return arrayPayloadDisclosureMapping;
123
- }
124
- /**
125
- * Get a mapping in the structure of the pretty payload, to indicate which digests should be disclosed for a
126
- * given entry.
127
- *
128
- * For example if you call this method with the following payload:
129
- * ```ts
130
- * {
131
- * _sd: ['iss_digest', 'nested_field_digest'],
132
- * }
133
- * ```
134
- *
135
- * It can return the following mapping:
136
- * ```ts
137
- * {
138
- * iss: 'iss_digest',
139
- * nested_field: {
140
- * __digest: 'nested_field_digest',
141
- * more_nested_field: {
142
- * // index 1 is null, as it's always in the payload, so doesn't need to be disclosed
143
- * // separately
144
- * a: ['a_0_digest', null, 'a_2_digest'],
145
- * }
146
- * }
147
- * }
148
- * ```
149
- *
150
- * This method will recursively call itself and `getArrayPayloadDisclosureMapping` if the value of a property is an object or array.
151
- */
152
- function getPayloadDisclosureMapping(payload, map) {
153
- // Handle array
154
- if (payload instanceof Array) {
155
- return getArrayPayloadDisclosureMapping(payload, map);
156
- }
157
- // Not an array or object, so it means the top-level value is already disclosed
158
- if (!(0, utils_1.isObject)(payload)) {
159
- return null;
160
- }
161
- const payloadDisclosureMapping = {};
162
- for (const key in payload) {
163
- // if obj property value is an object or array
164
- // recursively unpack
165
- if (key !== '_sd' && key !== '...' && payload[key] instanceof Object) {
166
- const claim = getPayloadDisclosureMapping(payload[key], map);
167
- if (claim && Object.keys(claim).length > 0) {
168
- payloadDisclosureMapping[key] = claim;
169
- }
170
- }
171
- }
172
- // If the payload contains a _sd property, it means there's disclosures
173
- if (payload._sd) {
174
- if (!Array.isArray(payload._sd)) {
175
- throw new error_1.SdJwtError(`Expect value of '_sd' to be of type array, but found ${typeof payload._sd}`);
176
- }
177
- // We are going to resolve all digests
178
- for (const digest of payload._sd) {
179
- if (typeof digest !== 'string') {
180
- throw new error_1.SdJwtError(`Expected entries in '_sd' property to be of type string, found ${typeof digest}`);
181
- }
182
- // Look up disclosure. It's valid that the disclosure is not present (decoy digests)
183
- const disclosed = map[digest];
184
- if (disclosed) {
185
- // value is always the last item in the disclosure array
186
- // We know this is an object, so the associated disclosure MUST have length 3
187
- const value = [...disclosed.disclosure.decoded].pop();
188
- if (disclosed.disclosure.decoded.length !== 3) {
189
- throw new error_1.SdJwtError(`Expected disclosure for value ${value} to have 3 items, but found ${disclosed.disclosure.decoded.length}`);
190
- }
191
- const key = disclosed.disclosure.decoded[1];
192
- // This checks if there's a nested disclosure anywhere down the tree
193
- // So when a disclosure value is an object or array, it can contain disclosures
194
- // of itself (using `_sd` and `...` keys)
195
- if ((0, utils_1.isObject)(value)) {
196
- const unpacked = getPayloadDisclosureMapping(value, map);
197
- if (unpacked && Object.keys(unpacked).length > 0) {
198
- payloadDisclosureMapping[key] = Object.assign(Object.assign({}, unpacked), { __digest: digest });
199
- }
200
- // If there's no nested disclosures, we add the digest directly
201
- else {
202
- payloadDisclosureMapping[key] = digest;
203
- }
204
- }
205
- else if (Array.isArray(value)) {
206
- // Get nested disclosures for the array value
207
- const nestedUnpackedArray = getArrayPayloadDisclosureMapping(value, map);
208
- // If all entries are null, it means there's no nested disclosures
209
- // And thus we push the digest directly
210
- if (nestedUnpackedArray.every((item) => item === null)) {
211
- payloadDisclosureMapping[key] = digest;
212
- }
213
- else {
214
- payloadDisclosureMapping[key] = Object.assign(Object.assign({}, nestedUnpackedArray), {
215
- // __digest is for encapsulating disclosure
216
- __digest: digest });
217
- }
218
- }
219
- else {
220
- payloadDisclosureMapping[key] = digest;
221
- }
222
- }
223
- }
224
- }
225
- return payloadDisclosureMapping;
226
- }
227
- exports.getPayloadDisclosureMapping = getPayloadDisclosureMapping;
228
- const getParentDisclosure = (disclosure, digestMap) => {
229
- const parent = digestMap[disclosure.digest];
230
- if (!parent) {
231
- return [];
232
- }
233
- if (digestMap[disclosure.digest]) {
234
- return [parent].concat(getParentDisclosure(parent, digestMap));
235
- }
236
- return [parent];
237
- };
238
- /**
239
- * Get a mapping from a digest to the corresponding disclosure and its parent disclosures.
240
- */
241
- const getDisclosureMap = (disclosures) => {
242
- const map = {};
243
- const parentMap = {};
244
- for (const disclosure of disclosures) {
245
- // value is always the last item in the disclosure array
246
- const value = [...disclosure.decoded].pop();
247
- (0, utils_1.traverseNodes)(value).forEach(({ path, value }) => {
248
- const lastPathItem = path[path.length - 1];
249
- if (lastPathItem === '_sd') {
250
- if (!Array.isArray(value)) {
251
- throw new error_1.SdJwtError(`Expect value of '_sd' to be of type array, but found ${typeof value}`);
252
- }
253
- value.forEach((digest) => {
254
- if (typeof digest !== 'string') {
255
- throw new error_1.SdJwtError(`Expected entries in '_sd' property to be of type string, found ${typeof digest}`);
256
- }
257
- parentMap[digest] = disclosure;
258
- });
259
- }
260
- else if (lastPathItem === '...') {
261
- if (typeof value !== 'string') {
262
- throw new error_1.SdJwtError(`Expected value of '...' to be of type string, but found ${typeof value}`);
263
- }
264
- parentMap[value] = disclosure;
265
- }
266
- });
267
- }
268
- for (const disclosure of disclosures) {
269
- const parent = getParentDisclosure(disclosure, parentMap);
270
- map[disclosure.digest] = {
271
- disclosure,
272
- parentDisclosures: parent
273
- };
274
- }
275
- return map;
276
- };
277
- exports.getDisclosureMap = getDisclosureMap;
278
- //# sourceMappingURL=disclosureMapping.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"disclosureMapping.js","sourceRoot":"","sources":["../../src/sdJwt/disclosureMapping.ts"],"names":[],"mappings":";AAAA,6GAA6G;;;AAE7G,oCAAkD;AAElD,mCAAoC;AAYpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,SAAS,gCAAgC,CACrC,KAAqB,EACrB,GAAkB;IAElB,MAAM,6BAA6B,GAAU,EAAE,CAAA;IAE/C,mDAAmD;IACnD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,gEAAgE;QAChE,yEAAyE;QACzE,0BAA0B;QAC1B,IAAI,IAAI,YAAY,MAAM,EAAE,CAAC;YACzB,+CAA+C;YAC/C,uCAAuC;YACvC,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;gBAChB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;gBAC1B,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;oBAC7B,MAAM,IAAI,kBAAU,CAChB,+DAA+D,OAAO,MAAM,EAAE,CACjF,CAAA;gBACL,CAAC;gBAED,oFAAoF;gBACpF,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC,CAAA;gBAC7B,IAAI,SAAS,EAAE,CAAC;oBACZ,wDAAwD;oBACxD,MAAM,KAAK,GAAG,CAAC,GAAG,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAA;oBAErD,6EAA6E;oBAC7E,+DAA+D;oBAC/D,IAAI,IAAA,gBAAQ,EAAC,KAAK,CAAC,EAAE,CAAC;wBAClB,8CAA8C;wBAC9C,MAAM,QAAQ,GAAG,2BAA2B,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;wBAExD,yEAAyE;wBACzE,gDAA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AAiB,EAAE,MAAM;SAC5B,CAAA;IACL,CAAC;IAED,OAAO,GAAG,CAAA;AACd,CAAC,CAAA;AAjDY,QAAA,gBAAgB,oBAiD5B"}
@@ -1,33 +0,0 @@
1
- import { AsyncHasher, Hasher, HasherAndAlgorithm } from '@sd-jwt/types';
2
- import { DisclosureItem } from '../types';
3
- import { DisclosureWithDigest as DisclosureWithDigestJson, Disclosure as DisclosureJson } from '@sd-jwt/types';
4
- export type DisclosureWithDigest = Disclosure & {
5
- digest: string;
6
- };
7
- export declare class Disclosure {
8
- #private;
9
- private salt;
10
- private key?;
11
- private value;
12
- constructor(salt: string, value: unknown, key?: string);
13
- static fromString(s: string): Disclosure;
14
- static fromArray(item: DisclosureItem): Disclosure;
15
- get encoded(): string;
16
- get decoded(): DisclosureItem;
17
- get digest(): string | undefined;
18
- /**
19
- * Set the digest of the disclosure.
20
- *
21
- * NOTE: this method statically sets the digest, and does not verify whether the digest is correct.
22
- * If you want to calculate the digest, use the `withCalculateDigest` method instead.
23
- */
24
- withDigest(digest: string): DisclosureWithDigest;
25
- withCalculateDigest<HasherImplementation extends Hasher | AsyncHasher>(hasherAndAlgorithm: HasherAndAlgorithm<HasherImplementation>, { recalculate }?: {
26
- recalculate?: boolean;
27
- }): WithCalculateDigestReturnType<HasherImplementation>;
28
- toString(): string;
29
- asJson(): this extends DisclosureWithDigest ? DisclosureWithDigestJson : DisclosureJson;
30
- static fromJson<D extends DisclosureJson | DisclosureWithDigestJson>(disclosureJson: D): D extends DisclosureWithDigestJson ? DisclosureWithDigest : Disclosure;
31
- }
32
- export type WithCalculateDigestReturnType<HasherImplementation extends Hasher | AsyncHasher> = ReturnType<HasherImplementation> extends Promise<any> ? Promise<DisclosureWithDigest> : DisclosureWithDigest;
33
- export declare function isDisclosureWithDigest(disclosure: Disclosure): disclosure is DisclosureWithDigest;
@@ -1,114 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
- if (kind === "m") throw new TypeError("Private method is not writable");
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
- };
13
- var _Disclosure_digest;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.isDisclosureWithDigest = exports.Disclosure = void 0;
16
- const decode_1 = require("@sd-jwt/decode");
17
- const utils_1 = require("@sd-jwt/utils");
18
- const error_1 = require("./error");
19
- class Disclosure {
20
- constructor(salt, value, key) {
21
- _Disclosure_digest.set(this, void 0);
22
- if (typeof value === 'number' && isNaN(value)) {
23
- throw new error_1.SdJwtError('NaN is not allowed to be used in a disclosure.');
24
- }
25
- if (typeof value === 'number' && !isFinite(value)) {
26
- throw new error_1.SdJwtError('Infinite is not allowed to be used in a disclosure.');
27
- }
28
- this.salt = salt;
29
- this.key = key;
30
- this.value = value;
31
- }
32
- static fromString(s) {
33
- const item = utils_1.Base64url.decodeToJson(s);
34
- return Disclosure.fromArray(item);
35
- }
36
- static fromArray(item) {
37
- return item[2] === undefined
38
- ? new Disclosure(item[0], item[1])
39
- : new Disclosure(item[0], item[2], item[1]);
40
- }
41
- get encoded() {
42
- return utils_1.Base64url.encodeFromJson(this.decoded);
43
- }
44
- get decoded() {
45
- return this.key
46
- ? [this.salt, this.key, this.value]
47
- : [this.salt, this.value];
48
- }
49
- get digest() {
50
- return __classPrivateFieldGet(this, _Disclosure_digest, "f");
51
- }
52
- /**
53
- * Set the digest of the disclosure.
54
- *
55
- * NOTE: this method statically sets the digest, and does not verify whether the digest is correct.
56
- * If you want to calculate the digest, use the `withCalculateDigest` method instead.
57
- */
58
- withDigest(digest) {
59
- __classPrivateFieldSet(this, _Disclosure_digest, digest, "f");
60
- return this;
61
- }
62
- withCalculateDigest(hasherAndAlgorithm,
63
- // Whether to recalculate the digest, even if it is already set
64
- { recalculate = false } = {}) {
65
- // NOTE: the implementation of this method seems overly complex, but it allows
66
- // us to return a promise if the hasher returns a promise, and a value otherwise.
67
- // This allows this method to be used in environments where the calling scope
68
- // is not async, as long as the hasher is not async either.
69
- if (!recalculate && isDisclosureWithDigest(this)) {
70
- return this;
71
- }
72
- const digestResult = (0, decode_1.disclosureCalculateDigest)(this.asJson(),
73
- // TODO: string vs HasherAlgorithm
74
- hasherAndAlgorithm.algorithm, hasherAndAlgorithm.hasher);
75
- if ((0, utils_1.isPromise)(digestResult)) {
76
- return digestResult.then((digest) => {
77
- __classPrivateFieldSet(this, _Disclosure_digest, digest, "f");
78
- // We know for sure that digest is defined now
79
- return this;
80
- });
81
- }
82
- else {
83
- __classPrivateFieldSet(this, _Disclosure_digest, digestResult, "f");
84
- // We know for sure that digest is defined now
85
- return this;
86
- }
87
- }
88
- toString() {
89
- return this.encoded;
90
- }
91
- asJson() {
92
- return {
93
- encoded: this.encoded,
94
- salt: this.salt,
95
- value: this.value,
96
- key: this.key,
97
- digest: this.digest
98
- };
99
- }
100
- static fromJson(disclosureJson) {
101
- const disclosure = new Disclosure(disclosureJson.salt, disclosureJson.value, disclosureJson.key);
102
- if ('digest' in disclosureJson) {
103
- disclosure.withDigest(disclosureJson.digest);
104
- }
105
- return disclosure;
106
- }
107
- }
108
- exports.Disclosure = Disclosure;
109
- _Disclosure_digest = new WeakMap();
110
- function isDisclosureWithDigest(disclosure) {
111
- return disclosure.digest !== undefined;
112
- }
113
- exports.isDisclosureWithDigest = isDisclosureWithDigest;
114
- //# sourceMappingURL=disclosures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Q;QACX,OAAO,IAAI,CAAC,OAAO,CAAA;IACvB,CAAC;IAEM,MAAM;QACT,OAAO;YACH,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,MAAM,EAAE,IAAI,CAAC,MAAM;SAGH,CAAA;IACxB,CAAC;IAEM,MAAM,CAAC,QAAQ,CAClB,cAAiB;QAEjB,MAAM,UAAU,GAAG,IAAI,UAAU,CAC7B,cAAc,CAAC,IAAI,EACnB,cAAc,CAAC,KAAK,EACpB,cAAc,CAAC,GAAG,CACrB,CAAA;QAED,IAAI,QAAQ,IAAI,cAAc,EAAE,CAAC;YAC7B,UAAU,CAAC,UAAU,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;QAChD,CAAC;QAED,OAAO,UAES,CAAA;IACpB,CAAC;CACJ;AAnID,gCAmIC;;AAQD,SAAgB,sBAAsB,CAClC,UAAsB;IAEtB,OAAO,UAAU,CAAC,MAAM,KAAK,SAAS,CAAA;AAC1C,CAAC;AAJD,wDAIC"}
@@ -1,2 +0,0 @@
1
- export declare class SdJwtError extends Error {
2
- }
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SdJwtError = void 0;
4
- class SdJwtError extends Error {
5
- }
6
- exports.SdJwtError = SdJwtError;
7
- //# sourceMappingURL=error.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/sdJwt/error.ts"],"names":[],"mappings":";;;AAAA,MAAa,UAAW,SAAQ,KAAK;CAAG;AAAxC,gCAAwC"}
@@ -1,6 +0,0 @@
1
- export * from './error';
2
- export * from './sdJwt';
3
- export * from './disclosures';
4
- export * from './decoys';
5
- export * from './disclosureFrame';
6
- export * from './types';
@@ -1,23 +0,0 @@
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("./error"), exports);
18
- __exportStar(require("./sdJwt"), exports);
19
- __exportStar(require("./disclosures"), exports);
20
- __exportStar(require("./decoys"), exports);
21
- __exportStar(require("./disclosureFrame"), exports);
22
- __exportStar(require("./types"), exports);
23
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sdJwt/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,0CAAuB;AACvB,gDAA6B;AAC7B,2CAAwB;AACxB,oDAAiC;AACjC,0CAAuB"}
@@ -1,3 +0,0 @@
1
- import { DisclosureWithDigest } from './disclosures';
2
- import { PresentationFrame } from '../types/present';
3
- export declare const getDisclosuresForPresentationFrame: <Payload extends Record<string, unknown> = Record<string, unknown>>(signedPayload: Payload, presentationFrame: PresentationFrame<Payload>, prettyClaims: Payload, disclosures?: Array<DisclosureWithDigest>) => Array<DisclosureWithDigest>;