@sd-jwt/decode 0.1.2-alpha.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 (50) hide show
  1. package/README.md +97 -0
  2. package/build/disclosures/calculateDigest.d.ts +5 -0
  3. package/build/disclosures/calculateDigest.js +14 -0
  4. package/build/disclosures/calculateDigest.js.map +1 -0
  5. package/build/disclosures/fromArray.d.ts +2 -0
  6. package/build/disclosures/fromArray.js +8 -0
  7. package/build/disclosures/fromArray.js.map +1 -0
  8. package/build/disclosures/fromString.d.ts +2 -0
  9. package/build/disclosures/fromString.js +11 -0
  10. package/build/disclosures/fromString.js.map +1 -0
  11. package/build/disclosures/index.d.ts +4 -0
  12. package/build/disclosures/index.js +21 -0
  13. package/build/disclosures/index.js.map +1 -0
  14. package/build/disclosures/toArray.d.ts +2 -0
  15. package/build/disclosures/toArray.js +6 -0
  16. package/build/disclosures/toArray.js.map +1 -0
  17. package/build/index.d.ts +5 -0
  18. package/build/index.js +18 -0
  19. package/build/index.js.map +1 -0
  20. package/build/jwt/fromCompact.d.ts +5 -0
  21. package/build/jwt/fromCompact.js +26 -0
  22. package/build/jwt/fromCompact.js.map +1 -0
  23. package/build/jwt/index.d.ts +1 -0
  24. package/build/jwt/index.js +18 -0
  25. package/build/jwt/index.js.map +1 -0
  26. package/build/keyBinding/assertValid.d.ts +0 -0
  27. package/build/keyBinding/assertValid.js +2 -0
  28. package/build/keyBinding/assertValid.js.map +1 -0
  29. package/build/keyBinding/fromCompact.d.ts +5 -0
  30. package/build/keyBinding/fromCompact.js +24 -0
  31. package/build/keyBinding/fromCompact.js.map +1 -0
  32. package/build/keyBinding/index.d.ts +1 -0
  33. package/build/keyBinding/index.js +18 -0
  34. package/build/keyBinding/index.js.map +1 -0
  35. package/build/sdJwt/fromCompact.d.ts +17 -0
  36. package/build/sdJwt/fromCompact.js +39 -0
  37. package/build/sdJwt/fromCompact.js.map +1 -0
  38. package/build/sdJwt/index.d.ts +1 -0
  39. package/build/sdJwt/index.js +18 -0
  40. package/build/sdJwt/index.js.map +1 -0
  41. package/build/sdJwtVc/decode.d.ts +18 -0
  42. package/build/sdJwtVc/decode.js +29 -0
  43. package/build/sdJwtVc/decode.js.map +1 -0
  44. package/build/sdJwtVc/fromCompact.d.ts +17 -0
  45. package/build/sdJwtVc/fromCompact.js +25 -0
  46. package/build/sdJwtVc/fromCompact.js.map +1 -0
  47. package/build/sdJwtVc/index.d.ts +2 -0
  48. package/build/sdJwtVc/index.js +19 -0
  49. package/build/sdJwtVc/index.js.map +1 -0
  50. package/package.json +51 -0
package/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # Selective Disclosure JWT (SD-JWT) Draft 06 & Selective Disclosure JWT VC 01
2
+
3
+ ## Compliant with
4
+
5
+ - [sd-jwt
6
+ 06](https://datatracker.ietf.org/doc/draft-ietf-oauth-selective-disclosure-jwt/06/)
7
+ - [sd-jwt-vc
8
+ 01](https://datatracker.ietf.org/doc/draft-ietf-oauth-sd-jwt-vc/01/)
9
+
10
+ ## Design decisions
11
+
12
+ ### Bring your own crypto
13
+
14
+ This library does not provide any of the cryptographic primitives required for
15
+ encryption, decryption, signing, verification and hashing. It is expected that
16
+ the user of this library provides this. The main reason for this is that most
17
+ libraries have their own library and KMS. Providing private keys to this
18
+ library adds another layer of insecurity which should be avoided. Hashing has
19
+ not been added for platform compatibility between node,js, browser and React
20
+ Native. In the future a platform-independent sha2-256 may be provided.
21
+
22
+ ### Specification backwards compatibility
23
+
24
+ Since these specifications are in early drafts, no time will be spend in
25
+ supporting earlier versions of the specifications. This library may work for
26
+ older versions, e.g. the addition of selectively disclosable items in an array
27
+ does not break previous implementations. Once a non-draft specification is
28
+ released it will stay up-to-date with that version.
29
+
30
+ ### Dependencies
31
+
32
+ This library only has one dependency on `buffer` which makes sure this library
33
+ works in Node.js, the browser and React Native. Buffer is used internally for
34
+ `base64-url-no-pad` encoding.
35
+
36
+ ### Usage
37
+
38
+ I'd highly recommend to check out the [examples folder](example) to see how
39
+ this library can be leveraged.
40
+
41
+ ### Issuance API
42
+
43
+ The issuance API takes an object called a `disclosureFrame`. This
44
+ `disclosureFrame` is a Boolean Map of the payload which allows you to specify
45
+ which attributes of the payload may be selectively disclosed. If an attribute is not provided in the `disclosureFrame`, it will be included in the clear-text payload. For example:
46
+
47
+ ```jsonc
48
+ // The payload
49
+ {
50
+ "iss": "https://example.org/issuer",
51
+ "is_age_over_21": true,
52
+ "is_age_over_24": true,
53
+ "is_age_over_65": false,
54
+ "date_of_birth": "1990-01-01",
55
+ "address": {
56
+ "street": "some street",
57
+ "house_number": 200,
58
+ "zipcode": "2344GH"
59
+ }
60
+ }
61
+ ```
62
+
63
+ ```jsonc
64
+ // The disclosure frame
65
+ {
66
+ "is_age_over_21": true,
67
+ "is_age_over_24": true,
68
+ "is_age_over_65": true,
69
+ "date_of_birth": true,
70
+ "address": {
71
+ "street": true,
72
+ "house_number": true,
73
+ "zipcode": true
74
+ }
75
+ }
76
+
77
+ // or to only disclose the address as a group
78
+ {
79
+ "is_age_over_21": true,
80
+ "is_age_over_24": true,
81
+ "is_age_over_65": true,
82
+ "date_of_birth": true,
83
+ "address": true
84
+ }
85
+ ```
86
+
87
+ ### Presentation and verification API
88
+
89
+ Since there is officially standardized way to request and present a
90
+ presentation, [High Assurance Interoperability
91
+ Profile](https://vcstuff.github.io/oid4vc-haip-sd-jwt-vc/draft-oid4vc-haip-sd-jwt-vc.html)
92
+ may be used, the API is defined in a way which works in a primitive manner for
93
+ now. For example, to present you can provide a list of indices of the
94
+ disclosures which will be included. Examples of this can be found in the
95
+ [examples folder](example). For verification a list of keys or required
96
+ claims can be provided. It does not matter whether these are selectively
97
+ disclosable claims, or if they are included inside the payload.
@@ -0,0 +1,5 @@
1
+ import type { AsyncHasher, Hasher } from '@sd-jwt/types';
2
+ import type { Disclosure, DisclosureWithDigest } from '@sd-jwt/types';
3
+ import { HasherAlgorithm } from '@sd-jwt/utils';
4
+ export type CalculateDigestReturnType<HasherImplementation extends Hasher | AsyncHasher> = ReturnType<HasherImplementation> extends Promise<any> ? Promise<DisclosureWithDigest> : DisclosureWithDigest;
5
+ export declare const disclosureCalculateDigest: <HI extends Hasher | AsyncHasher>(disclosure: Disclosure, algorithm: HasherAlgorithm, hasher: HI) => CalculateDigestReturnType<HI>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.disclosureCalculateDigest = void 0;
4
+ const utils_1 = require("@sd-jwt/utils");
5
+ const toArray_1 = require("./toArray");
6
+ const disclosureCalculateDigest = (disclosure, algorithm, hasher) => {
7
+ const encoded = utils_1.Base64url.encodeFromJson((0, toArray_1.disclosureToArray)(disclosure));
8
+ const digest = hasher(encoded, algorithm);
9
+ return ((0, utils_1.isPromise)(digest)
10
+ ? digest.then(utils_1.Base64url.encode)
11
+ : utils_1.Base64url.encode(digest));
12
+ };
13
+ exports.disclosureCalculateDigest = disclosureCalculateDigest;
14
+ //# sourceMappingURL=calculateDigest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculateDigest.js","sourceRoot":"","sources":["../../src/disclosures/calculateDigest.ts"],"names":[],"mappings":";;;AAEA,yCAAqE;AACrE,uCAA6C;AAQtC,MAAM,yBAAyB,GAAG,CACrC,UAAsB,EACtB,SAA0B,EAC1B,MAAU,EACmB,EAAE;IAC/B,MAAM,OAAO,GAAG,iBAAS,CAAC,cAAc,CAAC,IAAA,2BAAiB,EAAC,UAAU,CAAC,CAAC,CAAA;IACvE,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;IAEzC,OAAO,CACH,IAAA,iBAAS,EAAC,MAAM,CAAC;QACb,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAS,CAAC,MAAM,CAAC;QAC/B,CAAC,CAAC,iBAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CACA,CAAA;AACtC,CAAC,CAAA;AAbY,QAAA,yBAAyB,6BAarC"}
@@ -0,0 +1,2 @@
1
+ import { Disclosure, DisclosureArray } from '@sd-jwt/types';
2
+ export declare const disclosureFromArray: (a: DisclosureArray) => Disclosure;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.disclosureFromArray = void 0;
4
+ const disclosureFromArray = (a) => a[2]
5
+ ? { salt: a[0], key: a[1], value: a[2] }
6
+ : { salt: a[0], value: a[1] };
7
+ exports.disclosureFromArray = disclosureFromArray;
8
+ //# sourceMappingURL=fromArray.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromArray.js","sourceRoot":"","sources":["../../src/disclosures/fromArray.ts"],"names":[],"mappings":";;;AAEO,MAAM,mBAAmB,GAAG,CAAC,CAAkB,EAAc,EAAE,CAClE,CAAC,CAAC,CAAC,CAAC;IACA,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAW,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE;IAClD,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;AAHxB,QAAA,mBAAmB,uBAGK"}
@@ -0,0 +1,2 @@
1
+ import type { Disclosure } from '@sd-jwt/types';
2
+ export declare const disclosureFromString: (s: string) => Disclosure;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.disclosureFromString = void 0;
4
+ const utils_1 = require("@sd-jwt/utils");
5
+ const fromArray_1 = require("./fromArray");
6
+ const disclosureFromString = (s) => {
7
+ const item = utils_1.Base64url.decodeToJson(s);
8
+ return (0, fromArray_1.disclosureFromArray)(item);
9
+ };
10
+ exports.disclosureFromString = disclosureFromString;
11
+ //# sourceMappingURL=fromString.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromString.js","sourceRoot":"","sources":["../../src/disclosures/fromString.ts"],"names":[],"mappings":";;;AACA,yCAAyC;AACzC,2CAAiD;AAE1C,MAAM,oBAAoB,GAAG,CAAC,CAAS,EAAc,EAAE;IAC1D,MAAM,IAAI,GAAG,iBAAS,CAAC,YAAY,CAAkB,CAAC,CAAC,CAAA;IACvD,OAAO,IAAA,+BAAmB,EAAC,IAAI,CAAC,CAAA;AACpC,CAAC,CAAA;AAHY,QAAA,oBAAoB,wBAGhC"}
@@ -0,0 +1,4 @@
1
+ export * from './toArray';
2
+ export * from './fromArray';
3
+ export * from './fromString';
4
+ export * from './calculateDigest';
@@ -0,0 +1,21 @@
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("./toArray"), exports);
18
+ __exportStar(require("./fromArray"), exports);
19
+ __exportStar(require("./fromString"), exports);
20
+ __exportStar(require("./calculateDigest"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/disclosures/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAAyB;AACzB,8CAA2B;AAC3B,+CAA4B;AAC5B,oDAAiC"}
@@ -0,0 +1,2 @@
1
+ import { Disclosure, DisclosureArray } from '@sd-jwt/types';
2
+ export declare const disclosureToArray: (d: Disclosure) => DisclosureArray;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.disclosureToArray = void 0;
4
+ const disclosureToArray = (d) => d.key ? [d.salt, d.key, d.value] : [d.salt, d.value];
5
+ exports.disclosureToArray = disclosureToArray;
6
+ //# sourceMappingURL=toArray.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toArray.js","sourceRoot":"","sources":["../../src/disclosures/toArray.ts"],"names":[],"mappings":";;;AAEO,MAAM,iBAAiB,GAAG,CAAC,CAAa,EAAmB,EAAE,CAChE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAA;AAD3C,QAAA,iBAAiB,qBAC0B"}
@@ -0,0 +1,5 @@
1
+ export { jwtFromCompact } from './jwt';
2
+ export { sdJwtFromCompact } from './sdJwt';
3
+ export { decodeSdJwtVc, sdJwtVcFromCompact } from './sdJwtVc';
4
+ export { keyBindingFromCompact } from './keyBinding';
5
+ export { disclosureCalculateDigest, disclosureToArray, disclosureFromArray, disclosureFromString } from './disclosures';
package/build/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.disclosureFromString = exports.disclosureFromArray = exports.disclosureToArray = exports.disclosureCalculateDigest = exports.keyBindingFromCompact = exports.sdJwtVcFromCompact = exports.decodeSdJwtVc = exports.sdJwtFromCompact = exports.jwtFromCompact = void 0;
4
+ var jwt_1 = require("./jwt");
5
+ Object.defineProperty(exports, "jwtFromCompact", { enumerable: true, get: function () { return jwt_1.jwtFromCompact; } });
6
+ var sdJwt_1 = require("./sdJwt");
7
+ Object.defineProperty(exports, "sdJwtFromCompact", { enumerable: true, get: function () { return sdJwt_1.sdJwtFromCompact; } });
8
+ var sdJwtVc_1 = require("./sdJwtVc");
9
+ Object.defineProperty(exports, "decodeSdJwtVc", { enumerable: true, get: function () { return sdJwtVc_1.decodeSdJwtVc; } });
10
+ Object.defineProperty(exports, "sdJwtVcFromCompact", { enumerable: true, get: function () { return sdJwtVc_1.sdJwtVcFromCompact; } });
11
+ var keyBinding_1 = require("./keyBinding");
12
+ Object.defineProperty(exports, "keyBindingFromCompact", { enumerable: true, get: function () { return keyBinding_1.keyBindingFromCompact; } });
13
+ var disclosures_1 = require("./disclosures");
14
+ Object.defineProperty(exports, "disclosureCalculateDigest", { enumerable: true, get: function () { return disclosures_1.disclosureCalculateDigest; } });
15
+ Object.defineProperty(exports, "disclosureToArray", { enumerable: true, get: function () { return disclosures_1.disclosureToArray; } });
16
+ Object.defineProperty(exports, "disclosureFromArray", { enumerable: true, get: function () { return disclosures_1.disclosureFromArray; } });
17
+ Object.defineProperty(exports, "disclosureFromString", { enumerable: true, get: function () { return disclosures_1.disclosureFromString; } });
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6BAAsC;AAA7B,qGAAA,cAAc,OAAA;AACvB,iCAA0C;AAAjC,yGAAA,gBAAgB,OAAA;AACzB,qCAA6D;AAApD,wGAAA,aAAa,OAAA;AAAE,6GAAA,kBAAkB,OAAA;AAC1C,2CAAoD;AAA3C,mHAAA,qBAAqB,OAAA;AAE9B,6CAKsB;AAJlB,wHAAA,yBAAyB,OAAA;AACzB,gHAAA,iBAAiB,OAAA;AACjB,kHAAA,mBAAmB,OAAA;AACnB,mHAAA,oBAAoB,OAAA"}
@@ -0,0 +1,5 @@
1
+ export declare const jwtFromCompact: <Header extends Record<string, unknown> = Record<string, unknown>, Payload extends Record<string, unknown> = Record<string, unknown>>(compact: string) => {
2
+ header: Header;
3
+ payload: Payload;
4
+ signature: Uint8Array;
5
+ };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.jwtFromCompact = void 0;
4
+ const utils_1 = require("@sd-jwt/utils");
5
+ const jwtFromCompact = (compact) => {
6
+ if (compact.includes('~')) {
7
+ throw new Error('compact JWT includes `~` which is only allowed in an sd-jwt. Please use sdJwtFromCompact() instead.');
8
+ }
9
+ if ((compact.match(/\./g) || []).length !== 2) {
10
+ throw new Error('compact JWT must include two periods (.)');
11
+ }
12
+ const [compactHeader, compactPayload, encodedSignature] = compact.split('.');
13
+ if (!encodedSignature || encodedSignature.length === 0) {
14
+ throw new Error('A signature must be provided within the context of sd-jwt');
15
+ }
16
+ const header = utils_1.Base64url.decodeToJson(compactHeader);
17
+ const payload = utils_1.Base64url.decodeToJson(compactPayload);
18
+ const signature = utils_1.Base64url.decode(encodedSignature);
19
+ return {
20
+ header,
21
+ payload,
22
+ signature
23
+ };
24
+ };
25
+ exports.jwtFromCompact = jwtFromCompact;
26
+ //# sourceMappingURL=fromCompact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromCompact.js","sourceRoot":"","sources":["../../src/jwt/fromCompact.ts"],"names":[],"mappings":";;;AAAA,yCAAyC;AAElC,MAAM,cAAc,GAAG,CAI1B,OAAe,EACjB,EAAE;IACA,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACX,qGAAqG,CACxG,CAAA;IACL,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAA;IAC/D,CAAC;IAED,MAAM,CAAC,aAAa,EAAE,cAAc,EAAE,gBAAgB,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAE5E,IAAI,CAAC,gBAAgB,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CACX,2DAA2D,CAC9D,CAAA;IACL,CAAC;IAED,MAAM,MAAM,GAAG,iBAAS,CAAC,YAAY,CAAS,aAAa,CAAC,CAAA;IAC5D,MAAM,OAAO,GAAG,iBAAS,CAAC,YAAY,CAAU,cAAc,CAAC,CAAA;IAC/D,MAAM,SAAS,GAAG,iBAAS,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA;IAEpD,OAAO;QACH,MAAM;QACN,OAAO;QACP,SAAS;KACZ,CAAA;AACL,CAAC,CAAA;AAjCY,QAAA,cAAc,kBAiC1B"}
@@ -0,0 +1 @@
1
+ export * from './fromCompact';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./fromCompact"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/jwt/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B"}
File without changes
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=assertValid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertValid.js","sourceRoot":"","sources":["../../src/keyBinding/assertValid.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export declare const keyBindingFromCompact: <Header extends Record<string, unknown> = Record<string, unknown>, Payload extends Record<string, unknown> = Record<string, unknown>>(compact: string) => {
2
+ header: Header;
3
+ payload: Payload;
4
+ signature: Uint8Array;
5
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.keyBindingFromCompact = void 0;
4
+ const utils_1 = require("@sd-jwt/utils");
5
+ const jwt_1 = require("../jwt");
6
+ const keyBindingFromCompact = (compact) => {
7
+ const jwt = (0, jwt_1.jwtFromCompact)(compact);
8
+ try {
9
+ (0, utils_1.assertClaimInObject)(jwt.header, 'typ', 'kb+jwt');
10
+ (0, utils_1.assertClaimInObject)(jwt.header, 'alg');
11
+ (0, utils_1.assertClaimInObject)(jwt.payload, 'iat');
12
+ (0, utils_1.assertClaimInObject)(jwt.payload, 'nonce');
13
+ (0, utils_1.assertClaimInObject)(jwt.payload, 'aud');
14
+ }
15
+ catch (e) {
16
+ if (e instanceof Error) {
17
+ e.message = `jwt is not valid for usage with key binding. Error: ${e.message}`;
18
+ }
19
+ throw e;
20
+ }
21
+ return jwt;
22
+ };
23
+ exports.keyBindingFromCompact = keyBindingFromCompact;
24
+ //# sourceMappingURL=fromCompact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromCompact.js","sourceRoot":"","sources":["../../src/keyBinding/fromCompact.ts"],"names":[],"mappings":";;;AAAA,yCAAmD;AACnD,gCAAuC;AAEhC,MAAM,qBAAqB,GAAG,CAIjC,OAAe,EACjB,EAAE;IACA,MAAM,GAAG,GAAG,IAAA,oBAAc,EAAkB,OAAO,CAAC,CAAA;IAEpD,IAAI,CAAC;QACD,IAAA,2BAAmB,EAAC,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAA;QAChD,IAAA,2BAAmB,EAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QAEtC,IAAA,2BAAmB,EAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QACvC,IAAA,2BAAmB,EAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACzC,IAAA,2BAAmB,EAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAC3C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;YACrB,CAAC,CAAC,OAAO,GAAG,uDAAuD,CAAC,CAAC,OAAO,EAAE,CAAA;QAClF,CAAC;QAED,MAAM,CAAC,CAAA;IACX,CAAC;IAED,OAAO,GAAG,CAAA;AACd,CAAC,CAAA;AAxBY,QAAA,qBAAqB,yBAwBjC"}
@@ -0,0 +1 @@
1
+ export * from './fromCompact';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./fromCompact"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/keyBinding/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B"}
@@ -0,0 +1,17 @@
1
+ export declare const sdJwtFromCompact: <Header extends Record<string, unknown> = Record<string, unknown>, Payload extends Record<string, unknown> = Record<string, unknown>>(compact: string) => {
2
+ header: Header;
3
+ payload: Payload;
4
+ signature: Uint8Array;
5
+ keyBinding?: undefined;
6
+ disclosures?: undefined;
7
+ } | {
8
+ header: Header;
9
+ payload: Payload;
10
+ signature: Uint8Array;
11
+ keyBinding: {
12
+ header: Record<string, unknown>;
13
+ payload: Record<string, unknown>;
14
+ signature: Uint8Array;
15
+ } | undefined;
16
+ disclosures: import("@sd-jwt/types").Disclosure[];
17
+ };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sdJwtFromCompact = void 0;
4
+ const fromString_1 = require("../disclosures/fromString");
5
+ const jwt_1 = require("../jwt");
6
+ const keyBinding_1 = require("../keyBinding");
7
+ const sdJwtFromCompact = (compact) => {
8
+ const [jwtWithoutDisclosures, ...encodedDisclosures] = compact.split('~');
9
+ const { header, payload, signature } = (0, jwt_1.jwtFromCompact)(jwtWithoutDisclosures);
10
+ if (encodedDisclosures.length === 0) {
11
+ return {
12
+ header,
13
+ payload,
14
+ signature
15
+ };
16
+ }
17
+ const hasKeyBinding = !compact.endsWith('~');
18
+ // If the disclosure array ends with an `~` we do not have
19
+ // a key binding and `String.split` takes it as an empty string
20
+ // as element which we would not like to include in the disclosures.
21
+ if (!hasKeyBinding)
22
+ encodedDisclosures.pop();
23
+ const compactKeyBinding = hasKeyBinding
24
+ ? encodedDisclosures.pop()
25
+ : undefined;
26
+ const keyBinding = compactKeyBinding
27
+ ? (0, keyBinding_1.keyBindingFromCompact)(compactKeyBinding)
28
+ : undefined;
29
+ const disclosures = encodedDisclosures.map(fromString_1.disclosureFromString);
30
+ return {
31
+ header,
32
+ payload,
33
+ signature,
34
+ keyBinding,
35
+ disclosures
36
+ };
37
+ };
38
+ exports.sdJwtFromCompact = sdJwtFromCompact;
39
+ //# sourceMappingURL=fromCompact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromCompact.js","sourceRoot":"","sources":["../../src/sdJwt/fromCompact.ts"],"names":[],"mappings":";;;AAAA,0DAAgE;AAChE,gCAAuC;AACvC,8CAAqD;AAE9C,MAAM,gBAAgB,GAAG,CAI5B,OAAe,EACjB,EAAE;IACA,MAAM,CAAC,qBAAqB,EAAE,GAAG,kBAAkB,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAEzE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,IAAA,oBAAc,EACjD,qBAAqB,CACxB,CAAA;IAED,IAAI,kBAAkB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO;YACH,MAAM;YACN,OAAO;YACP,SAAS;SACZ,CAAA;IACL,CAAC;IAED,MAAM,aAAa,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;IAE5C,0DAA0D;IAC1D,+DAA+D;IAC/D,oEAAoE;IACpE,IAAI,CAAC,aAAa;QAAE,kBAAkB,CAAC,GAAG,EAAE,CAAA;IAE5C,MAAM,iBAAiB,GAAG,aAAa;QACnC,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE;QAC1B,CAAC,CAAC,SAAS,CAAA;IAEf,MAAM,UAAU,GAAG,iBAAiB;QAChC,CAAC,CAAC,IAAA,kCAAqB,EAAC,iBAAiB,CAAC;QAC1C,CAAC,CAAC,SAAS,CAAA;IAEf,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,iCAAoB,CAAC,CAAA;IAEhE,OAAO;QACH,MAAM;QACN,OAAO;QACP,SAAS;QACT,UAAU;QACV,WAAW;KACd,CAAA;AACL,CAAC,CAAA;AA5CY,QAAA,gBAAgB,oBA4C5B"}
@@ -0,0 +1 @@
1
+ export * from './fromCompact';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./fromCompact"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sdJwt/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B"}
@@ -0,0 +1,18 @@
1
+ import type { AsyncHasher, Hasher } from '@sd-jwt/types';
2
+ export declare const decodeSdJwtVc: <HI extends Hasher | AsyncHasher>(compact: string, hasher: HI) => {
3
+ compactSdJwtVc: string;
4
+ signedPayload: Record<string, unknown>;
5
+ header: Record<string, unknown>;
6
+ signature: Uint8Array;
7
+ keyBinding: {
8
+ header: Record<string, unknown>;
9
+ payload: Record<string, unknown>;
10
+ signature: Uint8Array;
11
+ } | undefined;
12
+ disclosures: {
13
+ digest: import("../disclosures/calculateDigest").CalculateDigestReturnType<HI>;
14
+ decoded: import("@sd-jwt/types").Disclosure;
15
+ encoded: import("@sd-jwt/types").DisclosureArray;
16
+ }[];
17
+ decodedPayload: Record<string, unknown>;
18
+ };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeSdJwtVc = void 0;
4
+ const utils_1 = require("@sd-jwt/utils");
5
+ const fromCompact_1 = require("./fromCompact");
6
+ const utils_2 = require("@sd-jwt/utils");
7
+ const calculateDigest_1 = require("../disclosures/calculateDigest");
8
+ const toArray_1 = require("../disclosures/toArray");
9
+ const decodeSdJwtVc = (compact, hasher) => {
10
+ var _a, _b;
11
+ const { header, payload, signature, keyBinding, disclosures } = (0, fromCompact_1.sdJwtVcFromCompact)(compact);
12
+ const hasherAlgorithm = (_a = (0, utils_2.getValueByKeyAnyLevel)(payload, '_sd_alg')) !== null && _a !== void 0 ? _a : utils_1.HasherAlgorithm.Sha256;
13
+ const disclosureWithDigests = (_b = disclosures === null || disclosures === void 0 ? void 0 : disclosures.map((d) => ({
14
+ digest: (0, calculateDigest_1.disclosureCalculateDigest)(d, hasherAlgorithm, hasher),
15
+ decoded: d,
16
+ encoded: (0, toArray_1.disclosureToArray)(d)
17
+ }))) !== null && _b !== void 0 ? _b : [];
18
+ return {
19
+ compactSdJwtVc: compact,
20
+ signedPayload: payload,
21
+ header,
22
+ signature,
23
+ keyBinding,
24
+ disclosures: disclosureWithDigests,
25
+ decodedPayload: (0, utils_2.swapClaims)(payload, disclosureWithDigests.map((d) => (Object.assign(Object.assign({}, d.decoded), { digest: d.digest }))))
26
+ };
27
+ };
28
+ exports.decodeSdJwtVc = decodeSdJwtVc;
29
+ //# sourceMappingURL=decode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.js","sourceRoot":"","sources":["../../src/sdJwtVc/decode.ts"],"names":[],"mappings":";;;AAEA,yCAA+C;AAC/C,+CAAkD;AAClD,yCAAiE;AACjE,oEAA0E;AAC1E,oDAA0D;AAEnD,MAAM,aAAa,GAAG,CACzB,OAAe,EACf,MAAU,EACZ,EAAE;;IACA,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,GACzD,IAAA,gCAAkB,EAAC,OAAO,CAAC,CAAA;IAE/B,MAAM,eAAe,GACjB,MAAA,IAAA,6BAAqB,EAAkB,OAAO,EAAE,SAAS,CAAC,mCAC1D,uBAAe,CAAC,MAAM,CAAA;IAE1B,MAAM,qBAAqB,GACvB,MAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACrB,MAAM,EAAE,IAAA,2CAAyB,EAAC,CAAC,EAAE,eAAe,EAAE,MAAM,CAAC;QAC7D,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,IAAA,2BAAiB,EAAC,CAAC,CAAC;KAChC,CAAC,CAAC,mCAAI,EAAE,CAAA;IAEb,OAAO;QACH,cAAc,EAAE,OAAO;QACvB,aAAa,EAAE,OAAO;QACtB,MAAM;QACN,SAAS;QACT,UAAU;QACV,WAAW,EAAE,qBAAqB;QAClC,cAAc,EAAE,IAAA,kBAAU,EACtB,OAAO,EACP,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,iCAC1B,CAAC,CAAC,OAAO,KACZ,MAAM,EAAE,CAAC,CAAC,MAAM,IAClB,CAA2C,CAChD;KACJ,CAAA;AACL,CAAC,CAAA;AAjCY,QAAA,aAAa,iBAiCzB"}
@@ -0,0 +1,17 @@
1
+ export declare const sdJwtVcFromCompact: <Header extends Record<string, unknown> = Record<string, unknown>, Payload extends Record<string, unknown> = Record<string, unknown>>(compact: string) => {
2
+ header: Header;
3
+ payload: Payload;
4
+ signature: Uint8Array;
5
+ keyBinding?: undefined;
6
+ disclosures?: undefined;
7
+ } | {
8
+ header: Header;
9
+ payload: Payload;
10
+ signature: Uint8Array;
11
+ keyBinding: {
12
+ header: Record<string, unknown>;
13
+ payload: Record<string, unknown>;
14
+ signature: Uint8Array;
15
+ } | undefined;
16
+ disclosures: import("@sd-jwt/types").Disclosure[];
17
+ };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sdJwtVcFromCompact = void 0;
4
+ const utils_1 = require("@sd-jwt/utils");
5
+ const fromCompact_1 = require("../sdJwt/fromCompact");
6
+ const sdJwtVcFromCompact = (compact) => {
7
+ const sdJwt = (0, fromCompact_1.sdJwtFromCompact)(compact);
8
+ try {
9
+ (0, utils_1.assertClaimInObject)(sdJwt.header, 'typ', 'vc+sd-jwt');
10
+ (0, utils_1.assertClaimInObject)(sdJwt.header, 'alg');
11
+ (0, utils_1.assertClaimInObject)(sdJwt.payload, 'iss');
12
+ (0, utils_1.assertClaimInObject)(sdJwt.payload, 'vct');
13
+ (0, utils_1.assertClaimInObject)(sdJwt.payload, 'iat');
14
+ (0, utils_1.assertClaimInObject)(sdJwt.payload, 'cnf');
15
+ }
16
+ catch (e) {
17
+ if (e instanceof Error) {
18
+ e.message = `jwt is not valid for usage with sd-jwt-vc. Error: ${e.message}`;
19
+ }
20
+ throw e;
21
+ }
22
+ return sdJwt;
23
+ };
24
+ exports.sdJwtVcFromCompact = sdJwtVcFromCompact;
25
+ //# sourceMappingURL=fromCompact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromCompact.js","sourceRoot":"","sources":["../../src/sdJwtVc/fromCompact.ts"],"names":[],"mappings":";;;AAAA,yCAAmD;AACnD,sDAAuD;AAEhD,MAAM,kBAAkB,GAAG,CAI9B,OAAe,EACjB,EAAE;IACA,MAAM,KAAK,GAAG,IAAA,8BAAgB,EAAkB,OAAO,CAAC,CAAA;IAExD,IAAI,CAAC;QACD,IAAA,2BAAmB,EAAC,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,CAAA;QACrD,IAAA,2BAAmB,EAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QACxC,IAAA,2BAAmB,EAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QACzC,IAAA,2BAAmB,EAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QACzC,IAAA,2BAAmB,EAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QACzC,IAAA,2BAAmB,EAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAC7C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;YACrB,CAAC,CAAC,OAAO,GAAG,qDAAqD,CAAC,CAAC,OAAO,EAAE,CAAA;QAChF,CAAC;QAED,MAAM,CAAC,CAAA;IACX,CAAC;IAED,OAAO,KAAK,CAAA;AAChB,CAAC,CAAA;AAxBY,QAAA,kBAAkB,sBAwB9B"}
@@ -0,0 +1,2 @@
1
+ export * from './decode';
2
+ export * from './fromCompact';
@@ -0,0 +1,19 @@
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("./decode"), exports);
18
+ __exportStar(require("./fromCompact"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sdJwtVc/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,gDAA6B"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@sd-jwt/decode",
3
+ "version": "0.1.2-alpha.0",
4
+ "description": "Decode implementation of sd-jwt Draft 06 and sd-jwt-vc Draft 01",
5
+ "license": "(MIT OR Apache-2.0)",
6
+ "author": "Berend Sliedrecht <sliedrecht@berend.io>",
7
+ "readme": "../../README.md",
8
+ "keywords": [
9
+ "jwt",
10
+ "jwt-sd",
11
+ "sd-jwt",
12
+ "sd-jwt-vc",
13
+ "decentralized-identity",
14
+ "ssi",
15
+ "oauth",
16
+ "oauth2",
17
+ "openid-connect"
18
+ ],
19
+ "repository": {
20
+ "url": "https://github.com/berendsliedrecht/sd-jwt-ts",
21
+ "type": "git"
22
+ },
23
+ "homepage": "https://github.com/berendsliedrecht/sd-jwt-ts",
24
+ "bugs": {
25
+ "url": "https://github.com/berendsliedrecht/sd-jwt-ts/issues",
26
+ "email": "sliedrecht@berend.io"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "main": "build/index.js",
32
+ "files": [
33
+ "build",
34
+ "../../LICENSE-MIT",
35
+ "../../LICENSE-APACHE-2.0"
36
+ ],
37
+ "scripts": {
38
+ "build": "tsc",
39
+ "test": "node --require ts-node/register --test ./tests/*.test.ts",
40
+ "release": "release-it"
41
+ },
42
+ "dependencies": {
43
+ "@sd-jwt/types": "workspace:*",
44
+ "@sd-jwt/utils": "workspace:*"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "*",
48
+ "ts-node": "*",
49
+ "typescript": "*"
50
+ }
51
+ }