@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.
- package/build/base64url.d.ts +28 -0
- package/build/base64url.js +40 -0
- package/build/base64url.js.map +1 -0
- package/build/hasherAlgorithm.d.ts +70 -0
- package/build/hasherAlgorithm.js +75 -0
- package/build/hasherAlgorithm.js.map +1 -0
- package/build/index.d.ts +11 -0
- package/build/index.js +20 -0
- package/build/index.js.map +1 -0
- package/build/jwt/compact.d.ts +6 -0
- package/build/jwt/compact.js +27 -0
- package/build/jwt/compact.js.map +1 -0
- package/build/jwt/error.d.ts +2 -0
- package/build/jwt/error.js +7 -0
- package/build/jwt/error.js.map +1 -0
- package/build/jwt/index.d.ts +3 -0
- package/build/jwt/index.js +20 -0
- package/build/jwt/index.js.map +1 -0
- package/build/jwt/jwt.d.ts +204 -0
- package/build/jwt/jwt.js +324 -0
- package/build/jwt/jwt.js.map +1 -0
- package/build/keyBinding/index.d.ts +1 -0
- package/build/keyBinding/index.js +18 -0
- package/build/keyBinding/index.js.map +1 -0
- package/build/keyBinding/keyBinding.d.ts +56 -0
- package/build/keyBinding/keyBinding.js +99 -0
- package/build/keyBinding/keyBinding.js.map +1 -0
- package/build/sdJwt/compact.d.ts +8 -0
- package/build/sdJwt/compact.js +39 -0
- package/build/sdJwt/compact.js.map +1 -0
- package/build/sdJwt/decoys.d.ts +2 -0
- package/build/sdJwt/decoys.js +35 -0
- package/build/sdJwt/decoys.js.map +1 -0
- package/build/sdJwt/disclosureFrame.d.ts +7 -0
- package/build/sdJwt/disclosureFrame.js +89 -0
- package/build/sdJwt/disclosureFrame.js.map +1 -0
- package/build/sdJwt/disclosureMapping.d.ts +44 -0
- package/build/sdJwt/disclosureMapping.js +289 -0
- package/build/sdJwt/disclosureMapping.js.map +1 -0
- package/build/sdJwt/disclosures.d.ts +14 -0
- package/build/sdJwt/disclosures.js +59 -0
- package/build/sdJwt/disclosures.js.map +1 -0
- package/build/sdJwt/error.d.ts +2 -0
- package/build/sdJwt/error.js +7 -0
- package/build/sdJwt/error.js.map +1 -0
- package/build/sdJwt/index.d.ts +7 -0
- package/build/sdJwt/index.js +24 -0
- package/build/sdJwt/index.js.map +1 -0
- package/build/sdJwt/presentationFrame.d.ts +4 -0
- package/build/sdJwt/presentationFrame.js +73 -0
- package/build/sdJwt/presentationFrame.js.map +1 -0
- package/build/sdJwt/sdJwt.d.ts +204 -0
- package/build/sdJwt/sdJwt.js +383 -0
- package/build/sdJwt/sdJwt.js.map +1 -0
- package/build/sdJwt/swapClaim.d.ts +3 -0
- package/build/sdJwt/swapClaim.js +90 -0
- package/build/sdJwt/swapClaim.js.map +1 -0
- package/build/sdJwt/types.d.ts +5 -0
- package/build/sdJwt/types.js +3 -0
- package/build/sdJwt/types.js.map +1 -0
- package/build/sdJwtVc/error.d.ts +2 -0
- package/build/sdJwtVc/error.js +7 -0
- package/build/sdJwtVc/error.js.map +1 -0
- package/build/sdJwtVc/index.d.ts +2 -0
- package/build/sdJwtVc/index.js +19 -0
- package/build/sdJwtVc/index.js.map +1 -0
- package/build/sdJwtVc/sdJwtVc.d.ts +47 -0
- package/build/sdJwtVc/sdJwtVc.js +125 -0
- package/build/sdJwtVc/sdJwtVc.js.map +1 -0
- package/build/signatureAndEncryptionAlgorithm.d.ts +105 -0
- package/build/signatureAndEncryptionAlgorithm.js +110 -0
- package/build/signatureAndEncryptionAlgorithm.js.map +1 -0
- package/build/types/disclosure.d.ts +5 -0
- package/build/types/disclosure.js +3 -0
- package/build/types/disclosure.js.map +1 -0
- package/build/types/frame.d.ts +5 -0
- package/build/types/frame.js +3 -0
- package/build/types/frame.js.map +1 -0
- package/build/types/hasher.d.ts +14 -0
- package/build/types/hasher.js +3 -0
- package/build/types/hasher.js.map +1 -0
- package/build/types/index.d.ts +6 -0
- package/build/types/index.js +23 -0
- package/build/types/index.js.map +1 -0
- package/build/types/present.d.ts +2 -0
- package/build/types/present.js +3 -0
- package/build/types/present.js.map +1 -0
- package/build/types/saltGenerator.d.ts +17 -0
- package/build/types/saltGenerator.js +3 -0
- package/build/types/saltGenerator.js.map +1 -0
- package/build/types/signer.d.ts +2 -0
- package/build/types/signer.js +3 -0
- package/build/types/signer.js.map +1 -0
- package/build/types/utils.d.ts +5 -0
- package/build/types/utils.js +3 -0
- package/build/types/utils.js.map +1 -0
- package/build/types/verifier.d.ts +14 -0
- package/build/types/verifier.js +3 -0
- package/build/types/verifier.js.map +1 -0
- package/build/utils/index.d.ts +2 -0
- package/build/utils/index.js +19 -0
- package/build/utils/index.js.map +1 -0
- package/build/utils/traverse.d.ts +8 -0
- package/build/utils/traverse.js +29 -0
- package/build/utils/traverse.js.map +1 -0
- package/build/utils/utils.d.ts +7 -0
- package/build/utils/utils.js +109 -0
- package/build/utils/utils.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,89 @@
|
|
|
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("../utils");
|
|
14
|
+
const decoys_1 = require("./decoys");
|
|
15
|
+
const disclosures_1 = require("./disclosures");
|
|
16
|
+
const error_1 = require("./error");
|
|
17
|
+
const applyDisclosureFrame = (saltGenerator, hasher, 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, hasher);
|
|
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 = new disclosures_1.Disclosure(salt, payload[key], key);
|
|
35
|
+
disclosures.push(disclosure);
|
|
36
|
+
const digest = yield disclosure.digest(hasher);
|
|
37
|
+
const sd = Array.from((_b = payload._sd) !== null && _b !== void 0 ? _b : []);
|
|
38
|
+
sd.push(digest);
|
|
39
|
+
//@ts-ignore
|
|
40
|
+
payload._sd = sd.sort();
|
|
41
|
+
cleanup.push(newKeys);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else if (typeof frameValue === 'object' &&
|
|
45
|
+
!Array.isArray(frameValue)) {
|
|
46
|
+
yield (0, exports.applyDisclosureFrame)(saltGenerator, hasher, payload[key], frameValue, newKeys, cleanup, disclosures);
|
|
47
|
+
}
|
|
48
|
+
else if (typeof frameValue === 'object' &&
|
|
49
|
+
Array.isArray(frameValue)) {
|
|
50
|
+
const payloadArray = payload[key];
|
|
51
|
+
const frameValueArray = frameValue;
|
|
52
|
+
if (!Array.isArray(payloadArray)) {
|
|
53
|
+
throw new error_1.SdJwtError(`Frame expected array, but received ${typeof payload[key]} for key '${key}'.`);
|
|
54
|
+
}
|
|
55
|
+
if (frameValueArray.length > payloadArray.length) {
|
|
56
|
+
throw new error_1.SdJwtError(`Frame array is longer than the payload array for ${key}`);
|
|
57
|
+
}
|
|
58
|
+
// Fill the frame with `false` if the payloadArray is longer than the frame value array
|
|
59
|
+
if (payloadArray.length > frameValueArray.length) {
|
|
60
|
+
payloadArray.forEach((_, index) => { var _a; return ((_a = frameValueArray[index]) !== null && _a !== void 0 ? _a : (frameValueArray[index] = false)); });
|
|
61
|
+
}
|
|
62
|
+
const newPayloadArray = [];
|
|
63
|
+
for (let i = 0; i < payloadArray.length; i++) {
|
|
64
|
+
const payloadValue = payloadArray[i];
|
|
65
|
+
const frameValue = frameValueArray[i];
|
|
66
|
+
if (frameValue) {
|
|
67
|
+
const salt = yield saltGenerator();
|
|
68
|
+
const disclosure = new disclosures_1.Disclosure(salt, payloadValue);
|
|
69
|
+
disclosures.push(disclosure);
|
|
70
|
+
const digest = yield disclosure.digest(hasher);
|
|
71
|
+
newPayloadArray.push({ '...': digest });
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
newPayloadArray.push(payloadValue);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
payload[key] = newPayloadArray;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
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.`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const payloadClone = Object.assign({}, payload);
|
|
85
|
+
cleanup.forEach((path) => (0, utils_1.deleteByPath)(payloadClone, path));
|
|
86
|
+
return { payload: payloadClone, disclosures };
|
|
87
|
+
});
|
|
88
|
+
exports.applyDisclosureFrame = applyDisclosureFrame;
|
|
89
|
+
//# sourceMappingURL=disclosureFrame.js.map
|
|
@@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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;AA5HY,QAAA,oBAAoB,wBA4HhC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Hasher } from '../types';
|
|
2
|
+
import { Disclosure } from './disclosures';
|
|
3
|
+
/**
|
|
4
|
+
* Mapping from a digest to the corresponding disclosure and its parent disclosures.
|
|
5
|
+
*/
|
|
6
|
+
export type DisclosureMap = {
|
|
7
|
+
[digest: string]: {
|
|
8
|
+
disclosure: Disclosure;
|
|
9
|
+
parentDisclosures: Disclosure[];
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Get a mapping in the structure of the pretty payload, to indicate which digests should be disclosed for a
|
|
14
|
+
* given entry.
|
|
15
|
+
*
|
|
16
|
+
* For example if you call this method with the following payload:
|
|
17
|
+
* ```ts
|
|
18
|
+
* {
|
|
19
|
+
* _sd: ['iss_digest', 'nested_field_digest'],
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* It can return the following mapping:
|
|
24
|
+
* ```ts
|
|
25
|
+
* {
|
|
26
|
+
* iss: 'iss_digest',
|
|
27
|
+
* nested_field: {
|
|
28
|
+
* __digest: 'nested_field_digest',
|
|
29
|
+
* more_nested_field: {
|
|
30
|
+
* // index 1 is null, as it's always in the payload, so doesn't need to be disclosed
|
|
31
|
+
* // separately
|
|
32
|
+
* a: ['a_0_digest', null, 'a_2_digest'],
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* This method will recursively call itself and `getArrayPayloadDisclosureMapping` if the value of a property is an object or array.
|
|
39
|
+
*/
|
|
40
|
+
export declare function getPayloadDisclosureMapping(payload: any, map: DisclosureMap): any[] | Record<string, unknown> | null;
|
|
41
|
+
/**
|
|
42
|
+
* Get a mapping from a digest to the corresponding disclosure and its parent disclosures.
|
|
43
|
+
*/
|
|
44
|
+
export declare const getDisclosureMap: (disclosures: Disclosure[], hasher: Hasher) => Promise<DisclosureMap>;
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file contains helpers functions for mapping between disclosures entries and the payload of an SD-JWT.
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.getDisclosureMap = exports.getPayloadDisclosureMapping = void 0;
|
|
14
|
+
const utils_1 = require("../utils");
|
|
15
|
+
const error_1 = require("./error");
|
|
16
|
+
/**
|
|
17
|
+
* Returns an array that includes the digests that should be disclosed for each item in the array.
|
|
18
|
+
*
|
|
19
|
+
* E.g. if the following array is passed:
|
|
20
|
+
* ```ts
|
|
21
|
+
* [ { '...': <SD_HASH_DIGEST_1> }, 'string_value', { '...': <SD_HASH_DIGEST_2> } ]
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* The return value will be:
|
|
25
|
+
* ```ts
|
|
26
|
+
* ['<SD_HASH_DIGEST_1>', null, '<SD_HASH_DIGEST_2>']
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* The second value will be null, as it's already disclosed, and thus there's no digests that
|
|
30
|
+
* need to be disclosed to reveal it. For the other values, it will include the digest that needs
|
|
31
|
+
* to be disclosed to reveal that array entry.
|
|
32
|
+
*
|
|
33
|
+
* In the case the array entry contains nested disclosures, the value will not be a digest, but rather
|
|
34
|
+
* the structure of the nested disclosures.
|
|
35
|
+
*
|
|
36
|
+
* Let's say the `<SD_HASH_DIGEST_1>` is the digest of the following disclosure:
|
|
37
|
+
* ```ts
|
|
38
|
+
* {
|
|
39
|
+
* // `<SD_HASH_DIGEST_3>` is the digest of the dateOfBirth property
|
|
40
|
+
* _sd: ['<SD_HASH_DIGEST_3>'],
|
|
41
|
+
* name: 'Jane Doe',
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* In this case the return value will be:
|
|
46
|
+
* ```ts
|
|
47
|
+
* [{ __digest: '<SD_HASH_DIGEST_1>', dateOfBirth: '<SD_HASH_DIGEST_3>' }, null, '<SD_HASH_DIGEST_2>']
|
|
48
|
+
* ```
|
|
49
|
+
* The `__digest` property indicates the digest of the encapsulating disclosure, and it being an object
|
|
50
|
+
* indicates that there's nested disclosures that need to be revealed.
|
|
51
|
+
*
|
|
52
|
+
* In the end the result value is an array, and all the string values in the return value are the digests.
|
|
53
|
+
* This allows you to easily build a path of digests to disclose to reveal a certain value.
|
|
54
|
+
*
|
|
55
|
+
* The return value can be endlessly nested, and will also call `getPayloadDisclosureMapping` recursively
|
|
56
|
+
* if the inner values are not arrays, but objects. That method in turn can call this method if the value
|
|
57
|
+
* of an object property is an array.
|
|
58
|
+
*/
|
|
59
|
+
function getArrayPayloadDisclosureMapping(array, map) {
|
|
60
|
+
const arrayPayloadDisclosureMapping = [];
|
|
61
|
+
// Loop through all the payload values of the array
|
|
62
|
+
for (const item of array) {
|
|
63
|
+
// If the item is an object, (both array and object are objects)
|
|
64
|
+
// it means there may be some values in here that need to be disclosed to
|
|
65
|
+
// reveal this array entry
|
|
66
|
+
if (item instanceof Object) {
|
|
67
|
+
// if Array item is { '...': <SD_HASH_DIGEST> }
|
|
68
|
+
// It means this item can be disclosed.
|
|
69
|
+
if ('...' in item) {
|
|
70
|
+
const digest = item['...'];
|
|
71
|
+
if (typeof digest !== 'string') {
|
|
72
|
+
throw new error_1.SdJwtError(`Expected value of key '...' to be of type string, but found ${typeof digest}`);
|
|
73
|
+
}
|
|
74
|
+
// Look up disclosure. It's valid that the disclosure is not present (decoy digests)
|
|
75
|
+
const disclosed = map[digest];
|
|
76
|
+
if (disclosed) {
|
|
77
|
+
// value is always the last item in the disclosure array
|
|
78
|
+
const value = [...disclosed.disclosure.decoded].pop();
|
|
79
|
+
// Recursively look if the disclosed value contains any disclosure references
|
|
80
|
+
// of itself. Based on the type we can decide how to handle it.
|
|
81
|
+
if ((0, utils_1.isObject)(value)) {
|
|
82
|
+
// Get nested disclosures for the object value
|
|
83
|
+
const unpacked = getPayloadDisclosureMapping(value, map);
|
|
84
|
+
// If there's any nested disclosures, we need to include both this item's
|
|
85
|
+
// disclosure, as well as the nested disclosures
|
|
86
|
+
if (unpacked && Object.keys(unpacked).length > 0) {
|
|
87
|
+
arrayPayloadDisclosureMapping.push(Object.assign(Object.assign({}, unpacked), { __digest: digest }));
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
arrayPayloadDisclosureMapping.push(digest);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (Array.isArray(value)) {
|
|
94
|
+
// Get nested disclosures for the array value
|
|
95
|
+
const nestedUnpackedArray = getArrayPayloadDisclosureMapping(value, map);
|
|
96
|
+
// If all entries are null, it means there's no nested disclosures
|
|
97
|
+
// And thus we push the digest directly
|
|
98
|
+
if (nestedUnpackedArray.every((item) => item === null)) {
|
|
99
|
+
arrayPayloadDisclosureMapping.push(digest);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
arrayPayloadDisclosureMapping.push(Object.assign(Object.assign({}, nestedUnpackedArray), {
|
|
103
|
+
// __digest is for encapsulating disclosure
|
|
104
|
+
__digest: digest }));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// If the value is not an object or a array, it means there's no nested disclosures
|
|
108
|
+
// and thus we can push the digest directly
|
|
109
|
+
else {
|
|
110
|
+
arrayPayloadDisclosureMapping.push(digest);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
// Value is not a disclosure for an array ('...') so we unpack the object recursively
|
|
115
|
+
const claims = getPayloadDisclosureMapping(item, map);
|
|
116
|
+
if (claims && Object.keys(claims).length > 0) {
|
|
117
|
+
arrayPayloadDisclosureMapping.push(claims);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
arrayPayloadDisclosureMapping.push(null);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// If the value is not an Object it means the actual value is disclosed
|
|
126
|
+
// in the array directly (so we don't need to disclose anything to reveal it)
|
|
127
|
+
else {
|
|
128
|
+
arrayPayloadDisclosureMapping.push(null);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return arrayPayloadDisclosureMapping;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get a mapping in the structure of the pretty payload, to indicate which digests should be disclosed for a
|
|
135
|
+
* given entry.
|
|
136
|
+
*
|
|
137
|
+
* For example if you call this method with the following payload:
|
|
138
|
+
* ```ts
|
|
139
|
+
* {
|
|
140
|
+
* _sd: ['iss_digest', 'nested_field_digest'],
|
|
141
|
+
* }
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* It can return the following mapping:
|
|
145
|
+
* ```ts
|
|
146
|
+
* {
|
|
147
|
+
* iss: 'iss_digest',
|
|
148
|
+
* nested_field: {
|
|
149
|
+
* __digest: 'nested_field_digest',
|
|
150
|
+
* more_nested_field: {
|
|
151
|
+
* // index 1 is null, as it's always in the payload, so doesn't need to be disclosed
|
|
152
|
+
* // separately
|
|
153
|
+
* a: ['a_0_digest', null, 'a_2_digest'],
|
|
154
|
+
* }
|
|
155
|
+
* }
|
|
156
|
+
* }
|
|
157
|
+
* ```
|
|
158
|
+
*
|
|
159
|
+
* This method will recursively call itself and `getArrayPayloadDisclosureMapping` if the value of a property is an object or array.
|
|
160
|
+
*/
|
|
161
|
+
function getPayloadDisclosureMapping(payload, map) {
|
|
162
|
+
// Handle array
|
|
163
|
+
if (payload instanceof Array) {
|
|
164
|
+
return getArrayPayloadDisclosureMapping(payload, map);
|
|
165
|
+
}
|
|
166
|
+
// Not an array or object, so it means the top-level value is already disclosed
|
|
167
|
+
if (!(0, utils_1.isObject)(payload)) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
const payloadDisclosureMapping = {};
|
|
171
|
+
for (const key in payload) {
|
|
172
|
+
// if obj property value is an object or array
|
|
173
|
+
// recursively unpack
|
|
174
|
+
if (key !== '_sd' && key !== '...' && payload[key] instanceof Object) {
|
|
175
|
+
const claim = getPayloadDisclosureMapping(payload[key], map);
|
|
176
|
+
if (claim && Object.keys(claim).length > 0) {
|
|
177
|
+
payloadDisclosureMapping[key] = claim;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// If the payload contains a _sd property, it means there's disclosures
|
|
182
|
+
if (payload._sd) {
|
|
183
|
+
if (!Array.isArray(payload._sd)) {
|
|
184
|
+
throw new error_1.SdJwtError(`Expect value of '_sd' to be of type array, but found ${typeof payload._sd}`);
|
|
185
|
+
}
|
|
186
|
+
// We are going to resolve all digests
|
|
187
|
+
for (const digest of payload._sd) {
|
|
188
|
+
if (typeof digest !== 'string') {
|
|
189
|
+
throw new error_1.SdJwtError(`Expected entries in '_sd' property to be of type string, found ${typeof digest}`);
|
|
190
|
+
}
|
|
191
|
+
// Look up disclosure. It's valid that the disclosure is not present (decoy digests)
|
|
192
|
+
const disclosed = map[digest];
|
|
193
|
+
if (disclosed) {
|
|
194
|
+
// value is always the last item in the disclosure array
|
|
195
|
+
// We know this is an object, so the associated disclosure MUST have length 3
|
|
196
|
+
const value = [...disclosed.disclosure.decoded].pop();
|
|
197
|
+
if (disclosed.disclosure.decoded.length !== 3) {
|
|
198
|
+
throw new error_1.SdJwtError(`Expected disclosure for value ${value} to have 3 items, but found ${disclosed.disclosure.decoded.length}`);
|
|
199
|
+
}
|
|
200
|
+
const key = disclosed.disclosure.decoded[1];
|
|
201
|
+
// This checks if there's a nested disclosure anywhere down the tree
|
|
202
|
+
// So when a disclosure value is an object or array, it can contain disclosures
|
|
203
|
+
// of itself (using `_sd` and `...` keys)
|
|
204
|
+
if ((0, utils_1.isObject)(value)) {
|
|
205
|
+
const unpacked = getPayloadDisclosureMapping(value, map);
|
|
206
|
+
if (unpacked && Object.keys(unpacked).length > 0) {
|
|
207
|
+
payloadDisclosureMapping[key] = Object.assign(Object.assign({}, unpacked), { __digest: digest });
|
|
208
|
+
}
|
|
209
|
+
// If there's no nested disclosures, we add the digest directly
|
|
210
|
+
else {
|
|
211
|
+
payloadDisclosureMapping[key] = digest;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
else if (Array.isArray(value)) {
|
|
215
|
+
// Get nested disclosures for the array value
|
|
216
|
+
const nestedUnpackedArray = getArrayPayloadDisclosureMapping(value, map);
|
|
217
|
+
// If all entries are null, it means there's no nested disclosures
|
|
218
|
+
// And thus we push the digest directly
|
|
219
|
+
if (nestedUnpackedArray.every((item) => item === null)) {
|
|
220
|
+
payloadDisclosureMapping[key] = digest;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
payloadDisclosureMapping[key] = Object.assign(Object.assign({}, nestedUnpackedArray), {
|
|
224
|
+
// __digest is for encapsulating disclosure
|
|
225
|
+
__digest: digest });
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
payloadDisclosureMapping[key] = digest;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return payloadDisclosureMapping;
|
|
235
|
+
}
|
|
236
|
+
exports.getPayloadDisclosureMapping = getPayloadDisclosureMapping;
|
|
237
|
+
// @todo it would ben nice if we don't have to pass hasher around everywhere
|
|
238
|
+
// but have a Disclosure type that includes the digest
|
|
239
|
+
const getParentDisclosure = (disclosure, digestMap, hasher) => __awaiter(void 0, void 0, void 0, function* () {
|
|
240
|
+
const parent = digestMap[yield disclosure.digest(hasher)];
|
|
241
|
+
if (!parent) {
|
|
242
|
+
return [];
|
|
243
|
+
}
|
|
244
|
+
if (digestMap[yield parent.digest(hasher)]) {
|
|
245
|
+
return [parent].concat(yield getParentDisclosure(parent, digestMap, hasher));
|
|
246
|
+
}
|
|
247
|
+
return [parent];
|
|
248
|
+
});
|
|
249
|
+
/**
|
|
250
|
+
* Get a mapping from a digest to the corresponding disclosure and its parent disclosures.
|
|
251
|
+
*/
|
|
252
|
+
const getDisclosureMap = (disclosures, hasher) => __awaiter(void 0, void 0, void 0, function* () {
|
|
253
|
+
const map = {};
|
|
254
|
+
const parentMap = {};
|
|
255
|
+
for (const disclosure of disclosures) {
|
|
256
|
+
// value is always the last item in the disclosure array
|
|
257
|
+
const value = [...disclosure.decoded].pop();
|
|
258
|
+
(0, utils_1.traverseNodes)(value).forEach(({ path, value }) => {
|
|
259
|
+
const lastPathItem = path[path.length - 1];
|
|
260
|
+
if (lastPathItem === '_sd') {
|
|
261
|
+
if (!Array.isArray(value)) {
|
|
262
|
+
throw new error_1.SdJwtError(`Expect value of '_sd' to be of type array, but found ${typeof value}`);
|
|
263
|
+
}
|
|
264
|
+
value.forEach((digest) => {
|
|
265
|
+
if (typeof digest !== 'string') {
|
|
266
|
+
throw new error_1.SdJwtError(`Expected entries in '_sd' property to be of type string, found ${typeof digest}`);
|
|
267
|
+
}
|
|
268
|
+
parentMap[digest] = disclosure;
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
else if (lastPathItem === '...') {
|
|
272
|
+
if (typeof value !== 'string') {
|
|
273
|
+
throw new error_1.SdJwtError(`Expected value of '...' to be of type string, but found ${typeof value}`);
|
|
274
|
+
}
|
|
275
|
+
parentMap[value] = disclosure;
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
for (const disclosure of disclosures) {
|
|
280
|
+
const parent = yield getParentDisclosure(disclosure, parentMap, hasher);
|
|
281
|
+
map[yield disclosure.digest(hasher)] = {
|
|
282
|
+
disclosure,
|
|
283
|
+
parentDisclosures: parent
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
return map;
|
|
287
|
+
});
|
|
288
|
+
exports.getDisclosureMap = getDisclosureMap;
|
|
289
|
+
//# sourceMappingURL=disclosureMapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disclosureMapping.js","sourceRoot":"","sources":["../../src/sdJwt/disclosureMapping.ts"],"names":[],"mappings":";AAAA,6GAA6G;;;;;;;;;;;;AAG7G,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;g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AA;oBACL,CAAC;oBACD,SAAS,CAAC,MAAM,CAAC,GAAG,UAAU,CAAA;gBAClC,CAAC,CAAC,CAAA;YACN,CAAC;iBAAM,IAAI,YAAY,KAAK,KAAK,EAAE,CAAC;gBAChC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;oBAC5B,MAAM,IAAI,kBAAU,CAChB,2DAA2D,OAAO,KAAK,EAAE,CAC5E,CAAA;gBACL,CAAC;gBACD,SAAS,CAAC,KAAK,CAAC,GAAG,UAAU,CAAA;YACjC,CAAC;QACL,CAAC,CAAC,CAAA;IACN,CAAC;IAED,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACnC,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAA;QAEvE,GAAG,CAAC,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG;YACnC,UAAU;YACV,iBAAiB,EAAE,MAAM;SAC5B,CAAA;IACL,CAAC;IAED,OAAO,GAAG,CAAA;AACd,CAAC,CAAA,CAAA;AAlDY,QAAA,gBAAgB,oBAkD5B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DisclosureItem, Hasher } from '../types';
|
|
2
|
+
export declare class Disclosure {
|
|
3
|
+
private salt;
|
|
4
|
+
private key?;
|
|
5
|
+
private value;
|
|
6
|
+
private _digest;
|
|
7
|
+
constructor(salt: string, value: unknown, key?: string);
|
|
8
|
+
static fromString(s: string): Disclosure;
|
|
9
|
+
static fromArray(item: DisclosureItem): Disclosure;
|
|
10
|
+
get encoded(): string;
|
|
11
|
+
get decoded(): DisclosureItem;
|
|
12
|
+
digest(hasher: Hasher): Promise<string>;
|
|
13
|
+
toString(): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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.Disclosure = void 0;
|
|
13
|
+
const base64url_1 = require("../base64url");
|
|
14
|
+
const error_1 = require("./error");
|
|
15
|
+
class Disclosure {
|
|
16
|
+
constructor(salt, value, key) {
|
|
17
|
+
if (typeof value === 'number' && isNaN(value)) {
|
|
18
|
+
throw new error_1.SdJwtError('NaN is not allowed to be used in a disclosure.');
|
|
19
|
+
}
|
|
20
|
+
if (typeof value === 'number' && !isFinite(value)) {
|
|
21
|
+
throw new error_1.SdJwtError('Infinite is not allowed to be used in a disclosure.');
|
|
22
|
+
}
|
|
23
|
+
this.salt = salt;
|
|
24
|
+
this.key = key;
|
|
25
|
+
this.value = value;
|
|
26
|
+
}
|
|
27
|
+
static fromString(s) {
|
|
28
|
+
const item = base64url_1.Base64url.decodeToJson(s);
|
|
29
|
+
return Disclosure.fromArray(item);
|
|
30
|
+
}
|
|
31
|
+
static fromArray(item) {
|
|
32
|
+
return item[2] === undefined
|
|
33
|
+
? new Disclosure(item[0], item[1])
|
|
34
|
+
: new Disclosure(item[0], item[2], item[1]);
|
|
35
|
+
}
|
|
36
|
+
get encoded() {
|
|
37
|
+
return base64url_1.Base64url.encodeFromJson(this.decoded);
|
|
38
|
+
}
|
|
39
|
+
get decoded() {
|
|
40
|
+
return this.key
|
|
41
|
+
? [this.salt, this.key, this.value]
|
|
42
|
+
: [this.salt, this.value];
|
|
43
|
+
}
|
|
44
|
+
digest(hasher) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
// Memoize value so we don't have to re-compute
|
|
47
|
+
if (!this._digest) {
|
|
48
|
+
const hash = yield hasher(this.encoded);
|
|
49
|
+
this._digest = base64url_1.Base64url.encode(hash);
|
|
50
|
+
}
|
|
51
|
+
return this._digest;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
toString() {
|
|
55
|
+
return this.encoded;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.Disclosure = Disclosure;
|
|
59
|
+
//# sourceMappingURL=disclosures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disclosures.js","sourceRoot":"","sources":["../../src/sdJwt/disclosures.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,4CAAwC;AACxC,mCAAoC;AAEpC,MAAa,UAAU;IAMnB,YAAmB,IAAY,EAAE,KAAc,EAAE,GAAY;QACzD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,kBAAU,CAChB,gDAAgD,CACnD,CAAA;QACL,CAAC;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAChD,MAAM,IAAI,kBAAU,CAChB,qDAAqD,CACxD,CAAA;QACL,CAAC;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACtB,CAAC;IAEM,MAAM,CAAC,UAAU,CAAC,CAAS;QAC9B,MAAM,IAAI,GAAG,qBAAS,CAAC,YAAY,CAAiB,CAAC,CAAC,CAAA;QAEtD,OAAO,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IACrC,CAAC;IAEM,MAAM,CAAC,SAAS,C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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("./compact"), exports);
|
|
23
|
+
__exportStar(require("./types"), exports);
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,4CAAyB;AACzB,0CAAuB"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Disclosure } from './disclosures';
|
|
2
|
+
import { Hasher } from '../types';
|
|
3
|
+
import { PresentationFrame } from '../types/present';
|
|
4
|
+
export declare const getDisclosuresForPresentationFrame: <Payload extends Record<string, unknown> = Record<string, unknown>>(signedPayload: Payload, presentationFrame: PresentationFrame<Payload>, prettyClaims: Payload, hasher: Hasher, disclosures?: Array<Disclosure>) => Promise<Array<Disclosure>>;
|