@sd-jwt/utils 0.2.1-alpha.0 → 0.2.1

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.
@@ -0,0 +1,70 @@
1
+ export declare enum HasherAlgorithm {
2
+ /**
3
+ * Sha-256: 256 bits. [RFC6920] (current)
4
+ */
5
+ Sha256 = "sha-256",
6
+ /**
7
+ * Sha-256-128: 128 bits. [RFC6920] (current)
8
+ */
9
+ Sha256_128 = "sha-256-128",
10
+ /**
11
+ * Sha-256-120: 120 bits. [RFC6920] (current)
12
+ */
13
+ Sha256_120 = "sha-256-120",
14
+ /**
15
+ * Sha-256-96: 96 bits. [RFC6920] (current)
16
+ */
17
+ Sha256_96 = "sha-256-96",
18
+ /**
19
+ * Sha-256-64: 64 bits. [RFC6920] (current)
20
+ */
21
+ Sha256_64 = "sha-256-64",
22
+ /**
23
+ * Sha-256-32: 32 bits. [RFC6920] (current)
24
+ */
25
+ Sha256_32 = "sha-256-32",
26
+ /**
27
+ * Sha-384: 384 bits. [FIPS 180-4] (current)
28
+ */
29
+ Sha384 = "sha-384",
30
+ /**
31
+ * Sha-512: 512 bits. [FIPS 180-4] (current)
32
+ */
33
+ Sha512 = "sha-512",
34
+ /**
35
+ * Sha3-224: 224 bits. [FIPS 202] (current)
36
+ */
37
+ Sha3_224 = "sha3-224",
38
+ /**
39
+ * Sha3-256: 256 bits. [FIPS 202] (current)
40
+ */
41
+ Sha3_256 = "sha3-256",
42
+ /**
43
+ * Sha3-384: 384 bits. [FIPS 202] (current)
44
+ */
45
+ Sha3_384 = "sha3-384",
46
+ /**
47
+ * Sha3-512: 512 bits. [FIPS 202] (current)
48
+ */
49
+ Sha3_512 = "sha3-512",
50
+ /**
51
+ * Blake2s-256: 256 bits. [RFC7693] (current)
52
+ */
53
+ Blake2s_256 = "blake2s-256",
54
+ /**
55
+ * Blake2b-256: 256 bits. [RFC7693] (current)
56
+ */
57
+ Blake2b_256 = "blake2b-256",
58
+ /**
59
+ * Blake2b-512: 512 bits. [RFC7693] (current)
60
+ */
61
+ Blake2b_512 = "blake2b-512",
62
+ /**
63
+ * K12-256: 256 bits. [draft-irtf-cfrg-kangarootwelve-06] (current)
64
+ */
65
+ K12_256 = "k12-256",
66
+ /**
67
+ * K12-512: 512 bits. [draft-irtf-cfrg-kangarootwelve-06] (current)
68
+ */
69
+ K12_512 = "k12-512"
70
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HasherAlgorithm = void 0;
4
+ var HasherAlgorithm;
5
+ (function (HasherAlgorithm) {
6
+ /**
7
+ * Sha-256: 256 bits. [RFC6920] (current)
8
+ */
9
+ HasherAlgorithm["Sha256"] = "sha-256";
10
+ /**
11
+ * Sha-256-128: 128 bits. [RFC6920] (current)
12
+ */
13
+ HasherAlgorithm["Sha256_128"] = "sha-256-128";
14
+ /**
15
+ * Sha-256-120: 120 bits. [RFC6920] (current)
16
+ */
17
+ HasherAlgorithm["Sha256_120"] = "sha-256-120";
18
+ /**
19
+ * Sha-256-96: 96 bits. [RFC6920] (current)
20
+ */
21
+ HasherAlgorithm["Sha256_96"] = "sha-256-96";
22
+ /**
23
+ * Sha-256-64: 64 bits. [RFC6920] (current)
24
+ */
25
+ HasherAlgorithm["Sha256_64"] = "sha-256-64";
26
+ /**
27
+ * Sha-256-32: 32 bits. [RFC6920] (current)
28
+ */
29
+ HasherAlgorithm["Sha256_32"] = "sha-256-32";
30
+ /**
31
+ * Sha-384: 384 bits. [FIPS 180-4] (current)
32
+ */
33
+ HasherAlgorithm["Sha384"] = "sha-384";
34
+ /**
35
+ * Sha-512: 512 bits. [FIPS 180-4] (current)
36
+ */
37
+ HasherAlgorithm["Sha512"] = "sha-512";
38
+ /**
39
+ * Sha3-224: 224 bits. [FIPS 202] (current)
40
+ */
41
+ HasherAlgorithm["Sha3_224"] = "sha3-224";
42
+ /**
43
+ * Sha3-256: 256 bits. [FIPS 202] (current)
44
+ */
45
+ HasherAlgorithm["Sha3_256"] = "sha3-256";
46
+ /**
47
+ * Sha3-384: 384 bits. [FIPS 202] (current)
48
+ */
49
+ HasherAlgorithm["Sha3_384"] = "sha3-384";
50
+ /**
51
+ * Sha3-512: 512 bits. [FIPS 202] (current)
52
+ */
53
+ HasherAlgorithm["Sha3_512"] = "sha3-512";
54
+ /**
55
+ * Blake2s-256: 256 bits. [RFC7693] (current)
56
+ */
57
+ HasherAlgorithm["Blake2s_256"] = "blake2s-256";
58
+ /**
59
+ * Blake2b-256: 256 bits. [RFC7693] (current)
60
+ */
61
+ HasherAlgorithm["Blake2b_256"] = "blake2b-256";
62
+ /**
63
+ * Blake2b-512: 512 bits. [RFC7693] (current)
64
+ */
65
+ HasherAlgorithm["Blake2b_512"] = "blake2b-512";
66
+ /**
67
+ * K12-256: 256 bits. [draft-irtf-cfrg-kangarootwelve-06] (current)
68
+ */
69
+ HasherAlgorithm["K12_256"] = "k12-256";
70
+ /**
71
+ * K12-512: 512 bits. [draft-irtf-cfrg-kangarootwelve-06] (current)
72
+ */
73
+ HasherAlgorithm["K12_512"] = "k12-512";
74
+ })(HasherAlgorithm || (exports.HasherAlgorithm = HasherAlgorithm = {}));
75
+ //# sourceMappingURL=hasherAlgorithm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasherAlgorithm.js","sourceRoot":"","sources":["../src/hasherAlgorithm.ts"],"names":[],"mappings":";;;AAAA,IAAY,eAqEX;AArED,WAAY,eAAe;IACvB;;OAEG;IACH,qCAAkB,CAAA;IAClB;;OAEG;IACH,6CAA0B,CAAA;IAC1B;;OAEG;IACH,6CAA0B,CAAA;IAC1B;;OAEG;IACH,2CAAwB,CAAA;IACxB;;OAEG;IACH,2CAAwB,CAAA;IACxB;;OAEG;IACH,2CAAwB,CAAA;IACxB;;OAEG;IACH,qCAAkB,CAAA;IAClB;;OAEG;IACH,qCAAkB,CAAA;IAClB;;OAEG;IACH,wCAAqB,CAAA;IACrB;;OAEG;IACH,wCAAqB,CAAA;IACrB;;OAEG;IACH,wCAAqB,CAAA;IACrB;;OAEG;IACH,wCAAqB,CAAA;IACrB;;OAEG;IACH,8CAA2B,CAAA;IAC3B;;OAEG;IACH,8CAA2B,CAAA;IAC3B;;OAEG;IACH,8CAA2B,CAAA;IAC3B;;OAEG;IACH,sCAAmB,CAAA;IACnB;;OAEG;IACH,sCAAmB,CAAA;AACvB,CAAC,EArEW,eAAe,+BAAf,eAAe,QAqE1B"}
@@ -0,0 +1,2 @@
1
+ import { DisclosureWithDigest } from '@sd-jwt/types';
2
+ export declare const swapClaims: (payload: Record<string, unknown>, disclosures: Array<DisclosureWithDigest>, newPayload?: Record<string, unknown>) => Record<string, unknown>;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.swapClaims = void 0;
4
+ const shouldInsertDisclosure = (key, value, disclosures) => {
5
+ if (key !== '_sd')
6
+ return [];
7
+ if (!Array.isArray(value))
8
+ return [];
9
+ const filteredDisclosures = [];
10
+ for (const d of disclosures) {
11
+ if (value.includes(d.digest)) {
12
+ filteredDisclosures.push(d);
13
+ }
14
+ }
15
+ return filteredDisclosures;
16
+ };
17
+ const shouldIncludeCleartextClaim = (key, value) => key !== '_sd' && key !== '_sd_alg' && typeof value !== 'object';
18
+ const swapClaims = (payload, disclosures, newPayload = {}) => {
19
+ const entries = Object.entries(payload);
20
+ // Loop over de payload
21
+ for (let i = 0; i < entries.length; i++) {
22
+ const [key, value] = entries[i];
23
+ // See whether we have an `_sd` key with an array of disclosures.
24
+ const foundDisclosures = shouldInsertDisclosure(key, value, disclosures);
25
+ // Add the disclosed items to the pretty payload
26
+ foundDisclosures.forEach((d) => {
27
+ newPayload[d.key] = d.value;
28
+ });
29
+ // Skip the rest as `_sd` is a special case
30
+ if (key === '_sd') {
31
+ continue;
32
+ }
33
+ // Include all the primitive claims into the new payload
34
+ if (shouldIncludeCleartextClaim(key, value)) {
35
+ newPayload[key] = value;
36
+ continue;
37
+ }
38
+ if (typeof value === 'object' && Array.isArray(value)) {
39
+ newPayload[key] = swapClaimsInsideArray(value, disclosures);
40
+ continue;
41
+ }
42
+ if (typeof value === 'object' &&
43
+ value !== null &&
44
+ !Array.isArray(value)) {
45
+ newPayload[key] = (0, exports.swapClaims)(value, disclosures);
46
+ }
47
+ }
48
+ return newPayload;
49
+ };
50
+ exports.swapClaims = swapClaims;
51
+ const swapClaimsInsideArray = (array, disclosures) => {
52
+ const processedArray = [];
53
+ for (const el of array) {
54
+ if (typeof el === 'object' && el !== null && '...' in el) {
55
+ const hash = el['...'];
56
+ let disclosureFound = false;
57
+ let disclosureValue;
58
+ disclosureLoop: for (const d of disclosures) {
59
+ if (d.digest === hash && d.key === undefined) {
60
+ disclosureValue = d.value;
61
+ disclosureFound = true;
62
+ break disclosureLoop;
63
+ }
64
+ }
65
+ processedArray.push(disclosureFound ? disclosureValue : el);
66
+ }
67
+ else {
68
+ processedArray.push(el);
69
+ }
70
+ }
71
+ return processedArray;
72
+ };
73
+ //# sourceMappingURL=swapClaims.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swapClaims.js","sourceRoot":"","sources":["../src/swapClaims.ts"],"names":[],"mappings":";;;AAEA,MAAM,sBAAsB,GAAG,CAC3B,GAAW,EACX,KAAc,EACd,WAAwC,EAC1C,EAAE;IACA,IAAI,GAAG,KAAK,KAAK;QAAE,OAAO,EAAE,CAAA;IAC5B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IAEpC,MAAM,mBAAmB,GAAG,EAAE,CAAA;IAE9B,KAAK,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC;QAC1B,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3B,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAC/B,CAAC;IACL,CAAC;IAED,OAAO,mBAAmB,CAAA;AA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0",
3
+ "version": "0.2.1",
4
4
  "description": "Utility functions for sd-jwt Draft 06 and sd-jwt-vc Draft 01",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "author": "Berend Sliedrecht <sliedrecht@berend.io>",
@@ -37,7 +37,7 @@
37
37
  "test": "node --require ts-node/register --test ./tests/*.test.ts"
38
38
  },
39
39
  "dependencies": {
40
- "@sd-jwt/types": "0.2.1-alpha.0",
40
+ "@sd-jwt/types": "0.2.1",
41
41
  "buffer": "*"
42
42
  },
43
43
  "devDependencies": {
@@ -45,5 +45,5 @@
45
45
  "ts-node": "*",
46
46
  "typescript": "*"
47
47
  },
48
- "gitHead": "97e9d3699113bb04fb99d6421797cbd404e4a626"
48
+ "gitHead": "a1fb5fad0b938081e033233bae5569ae3b9fe8cb"
49
49
  }