@pagopa/io-react-native-wallet 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. package/README.md +91 -0
  2. package/lib/commonjs/index.js +17 -0
  3. package/lib/commonjs/index.js.map +1 -0
  4. package/lib/commonjs/pid/index.js +11 -0
  5. package/lib/commonjs/pid/index.js.map +1 -0
  6. package/lib/commonjs/pid/sd-jwt/converters.js +29 -0
  7. package/lib/commonjs/pid/sd-jwt/converters.js.map +1 -0
  8. package/lib/commonjs/pid/sd-jwt/index.js +76 -0
  9. package/lib/commonjs/pid/sd-jwt/index.js.map +1 -0
  10. package/lib/commonjs/pid/sd-jwt/types.js +50 -0
  11. package/lib/commonjs/pid/sd-jwt/types.js.map +1 -0
  12. package/lib/commonjs/sd-jwt/__test__/converters.test.js +25 -0
  13. package/lib/commonjs/sd-jwt/__test__/converters.test.js.map +1 -0
  14. package/lib/commonjs/sd-jwt/__test__/types.test.js +70 -0
  15. package/lib/commonjs/sd-jwt/__test__/types.test.js.map +1 -0
  16. package/lib/commonjs/sd-jwt/converters.js +30 -0
  17. package/lib/commonjs/sd-jwt/converters.js.map +1 -0
  18. package/lib/commonjs/sd-jwt/index.js +77 -0
  19. package/lib/commonjs/sd-jwt/index.js.map +1 -0
  20. package/lib/commonjs/sd-jwt/types.js +53 -0
  21. package/lib/commonjs/sd-jwt/types.js.map +1 -0
  22. package/lib/commonjs/sd-jwt/verifier.js +18 -0
  23. package/lib/commonjs/sd-jwt/verifier.js.map +1 -0
  24. package/lib/commonjs/utils/errors.js +82 -0
  25. package/lib/commonjs/utils/errors.js.map +1 -0
  26. package/lib/commonjs/utils/jwk.js +45 -0
  27. package/lib/commonjs/utils/jwk.js.map +1 -0
  28. package/lib/commonjs/wallet-instance-attestation/index.js +63 -0
  29. package/lib/commonjs/wallet-instance-attestation/index.js.map +1 -0
  30. package/lib/commonjs/wallet-instance-attestation/issuing.js +96 -0
  31. package/lib/commonjs/wallet-instance-attestation/issuing.js.map +1 -0
  32. package/lib/commonjs/wallet-instance-attestation/types.js +65 -0
  33. package/lib/commonjs/wallet-instance-attestation/types.js.map +1 -0
  34. package/lib/module/index.js +7 -0
  35. package/lib/module/index.js.map +1 -0
  36. package/lib/module/pid/index.js +3 -0
  37. package/lib/module/pid/index.js.map +1 -0
  38. package/lib/module/pid/sd-jwt/converters.js +23 -0
  39. package/lib/module/pid/sd-jwt/converters.js.map +1 -0
  40. package/lib/module/pid/sd-jwt/index.js +66 -0
  41. package/lib/module/pid/sd-jwt/index.js.map +1 -0
  42. package/lib/module/pid/sd-jwt/types.js +43 -0
  43. package/lib/module/pid/sd-jwt/types.js.map +1 -0
  44. package/lib/module/sd-jwt/__test__/converters.test.js +23 -0
  45. package/lib/module/sd-jwt/__test__/converters.test.js.map +1 -0
  46. package/lib/module/sd-jwt/__test__/types.test.js +68 -0
  47. package/lib/module/sd-jwt/__test__/types.test.js.map +1 -0
  48. package/lib/module/sd-jwt/converters.js +24 -0
  49. package/lib/module/sd-jwt/converters.js.map +1 -0
  50. package/lib/module/sd-jwt/index.js +71 -0
  51. package/lib/module/sd-jwt/index.js.map +1 -0
  52. package/lib/module/sd-jwt/types.js +44 -0
  53. package/lib/module/sd-jwt/types.js.map +1 -0
  54. package/lib/module/sd-jwt/verifier.js +11 -0
  55. package/lib/module/sd-jwt/verifier.js.map +1 -0
  56. package/lib/module/utils/errors.js +73 -0
  57. package/lib/module/utils/errors.js.map +1 -0
  58. package/lib/module/utils/jwk.js +38 -0
  59. package/lib/module/utils/jwk.js.map +1 -0
  60. package/lib/module/wallet-instance-attestation/index.js +52 -0
  61. package/lib/module/wallet-instance-attestation/index.js.map +1 -0
  62. package/lib/module/wallet-instance-attestation/issuing.js +90 -0
  63. package/lib/module/wallet-instance-attestation/issuing.js.map +1 -0
  64. package/lib/module/wallet-instance-attestation/types.js +55 -0
  65. package/lib/module/wallet-instance-attestation/types.js.map +1 -0
  66. package/lib/typescript/index.d.ts +5 -0
  67. package/lib/typescript/index.d.ts.map +1 -0
  68. package/lib/typescript/pid/index.d.ts +3 -0
  69. package/lib/typescript/pid/index.d.ts.map +1 -0
  70. package/lib/typescript/pid/sd-jwt/converters.d.ts +4 -0
  71. package/lib/typescript/pid/sd-jwt/converters.d.ts.map +1 -0
  72. package/lib/typescript/pid/sd-jwt/index.d.ts +50 -0
  73. package/lib/typescript/pid/sd-jwt/index.d.ts.map +1 -0
  74. package/lib/typescript/pid/sd-jwt/types.d.ts +196 -0
  75. package/lib/typescript/pid/sd-jwt/types.d.ts.map +1 -0
  76. package/lib/typescript/sd-jwt/__test__/converters.test.d.ts +2 -0
  77. package/lib/typescript/sd-jwt/__test__/converters.test.d.ts.map +1 -0
  78. package/lib/typescript/sd-jwt/__test__/types.test.d.ts +2 -0
  79. package/lib/typescript/sd-jwt/__test__/types.test.d.ts.map +1 -0
  80. package/lib/typescript/sd-jwt/converters.d.ts +3 -0
  81. package/lib/typescript/sd-jwt/converters.d.ts.map +1 -0
  82. package/lib/typescript/sd-jwt/index.d.ts +42 -0
  83. package/lib/typescript/sd-jwt/index.d.ts.map +1 -0
  84. package/lib/typescript/sd-jwt/types.d.ts +416 -0
  85. package/lib/typescript/sd-jwt/types.d.ts.map +1 -0
  86. package/lib/typescript/sd-jwt/verifier.d.ts +3 -0
  87. package/lib/typescript/sd-jwt/verifier.d.ts.map +1 -0
  88. package/lib/typescript/utils/errors.d.ts +45 -0
  89. package/lib/typescript/utils/errors.d.ts.map +1 -0
  90. package/lib/typescript/utils/jwk.d.ts +85 -0
  91. package/lib/typescript/utils/jwk.d.ts.map +1 -0
  92. package/lib/typescript/wallet-instance-attestation/index.d.ts +36 -0
  93. package/lib/typescript/wallet-instance-attestation/index.d.ts.map +1 -0
  94. package/lib/typescript/wallet-instance-attestation/issuing.d.ts +32 -0
  95. package/lib/typescript/wallet-instance-attestation/issuing.d.ts.map +1 -0
  96. package/lib/typescript/wallet-instance-attestation/types.d.ts +733 -0
  97. package/lib/typescript/wallet-instance-attestation/types.d.ts.map +1 -0
  98. package/package.json +108 -0
  99. package/src/index.ts +8 -0
  100. package/src/pid/index.ts +2 -0
  101. package/src/pid/sd-jwt/converters.ts +26 -0
  102. package/src/pid/sd-jwt/index.ts +71 -0
  103. package/src/pid/sd-jwt/types.ts +44 -0
  104. package/src/sd-jwt/__test__/converters.test.ts +27 -0
  105. package/src/sd-jwt/__test__/types.test.ts +85 -0
  106. package/src/sd-jwt/converters.ts +24 -0
  107. package/src/sd-jwt/index.ts +92 -0
  108. package/src/sd-jwt/types.ts +54 -0
  109. package/src/sd-jwt/verifier.ts +20 -0
  110. package/src/utils/errors.ts +74 -0
  111. package/src/utils/jwk.ts +39 -0
  112. package/src/wallet-instance-attestation/index.ts +56 -0
  113. package/src/wallet-instance-attestation/issuing.ts +107 -0
  114. package/src/wallet-instance-attestation/types.ts +77 -0
package/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # 🪪 @pagopa/io-react-native-wallet
2
+
3
+ 📲 Provide data structures, helpers, and API to Wallet Instance.
4
+
5
+ Depends on [@pagopa/io-react-native-jwt](https://github.com/pagopa/io-react-native-jwt)
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ # First install JWT dependency if you don't have it
11
+ npm install @pagopa/io-react-native-jwt
12
+
13
+ npm install @pagopa/io-react-native-wallet
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ### PID
19
+
20
+ #### Encode and Decode
21
+
22
+ ```ts
23
+ import { PID } from "@pagopa/io-react-native-wallet";
24
+
25
+ //Only for decode
26
+ PID.SdJwt.decode("<token>");
27
+
28
+ //Decode and verification
29
+ PID.SdJwt.verify("<token>");
30
+
31
+ ```
32
+
33
+ ### Wallet Instance Attestation
34
+
35
+ #### Issuing
36
+
37
+ ```ts
38
+ import { WalletInstanceAttestation } from "@pagopa/io-react-native-wallet";
39
+
40
+ const issuing = new WalletInstanceAttestation.Issuing(
41
+ yourWalletProviderUrl
42
+ );
43
+
44
+ // Genrate keys
45
+ const publicKey = await yourCustomPublicKey("TEE_KEY_TAG");
46
+
47
+ const walletInstanceAttestationRequest =
48
+ await issuing.getAttestationRequestToSign(
49
+ publicKey
50
+ );
51
+
52
+ //Sign with TEE
53
+ const signature = await yourCustomSignatureFunction(
54
+ walletInstanceAttestationRequest,
55
+ "TEE_KEY_TAG"
56
+ );
57
+
58
+ const walletInstanceAttestation =
59
+ await issuing.getAttestation(
60
+ walletInstanceAttestationRequest,
61
+ signature
62
+ );
63
+
64
+ console.log(walletInstanceAttestation);
65
+
66
+ ```
67
+
68
+ #### Encode and Decode
69
+
70
+ ```ts
71
+ import { WalletInstanceAttestation } from "io-react-native-wallet";
72
+
73
+ WalletInstanceAttestation.decode("<token>");
74
+ ```
75
+
76
+ ## Example
77
+
78
+ You can use the [sample app](example) to test and understand how to use the library.
79
+
80
+ ```sh
81
+ cd example
82
+
83
+ yarn install
84
+
85
+ # To use iOS
86
+ yarn ios
87
+
88
+ # To use Android
89
+ yarn android
90
+
91
+ ```
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.WalletInstanceAttestation = exports.PID = void 0;
7
+ exports.multiply = multiply;
8
+ var PID = _interopRequireWildcard(require("./pid"));
9
+ exports.PID = PID;
10
+ var WalletInstanceAttestation = _interopRequireWildcard(require("./wallet-instance-attestation"));
11
+ exports.WalletInstanceAttestation = WalletInstanceAttestation;
12
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
+ function multiply(a, b) {
15
+ return Promise.resolve(a * b);
16
+ }
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["PID","_interopRequireWildcard","require","exports","WalletInstanceAttestation","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","multiply","a","b","Promise","resolve"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;AAAA,IAAAA,GAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA6BC,OAAA,CAAAH,GAAA,GAAAA,GAAA;AAC7B,IAAAI,yBAAA,GAAAH,uBAAA,CAAAC,OAAA;AAA2EC,OAAA,CAAAC,yBAAA,GAAAA,yBAAA;AAAA,SAAAC,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAL,wBAAAS,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YAAAT,MAAA,CAAAK,GAAA,IAAAX,GAAA,CAAAW,GAAA,SAAAL,MAAA,CAAAJ,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAa,GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA;AAEpE,SAASW,QAAQA,CAACC,CAAS,EAAEC,CAAS,EAAmB;EAC9D,OAAOC,OAAO,CAACC,OAAO,CAACH,CAAC,GAAGC,CAAC,CAAC;AAC/B"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SdJwt = void 0;
7
+ var SdJwt = _interopRequireWildcard(require("./sd-jwt"));
8
+ exports.SdJwt = SdJwt;
9
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
10
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["SdJwt","_interopRequireWildcard","require","exports","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set"],"sourceRoot":"../../../src","sources":["pid/index.ts"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAkCC,OAAA,CAAAH,KAAA,GAAAA,KAAA;AAAA,SAAAI,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YAAAT,MAAA,CAAAK,GAAA,IAAAX,GAAA,CAAAW,GAAA,SAAAL,MAAA,CAAAJ,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAa,GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.pidFromToken = pidFromToken;
7
+ var _converters = require("../../sd-jwt/converters");
8
+ var _types = require("./types");
9
+ function pidFromToken(sdJwt, disclosures) {
10
+ return _types.PID.parse({
11
+ issuer: sdJwt.payload.iss,
12
+ issuedAt: new Date(sdJwt.payload.iat * 1000),
13
+ expiration: new Date(sdJwt.payload.exp * 1000),
14
+ verification: {
15
+ trustFramework: sdJwt.payload.verified_claims.verification.trust_framework,
16
+ assuranceLevel: sdJwt.payload.verified_claims.verification.assurance_level,
17
+ evidence: (0, _converters.getValueFromDisclosures)(disclosures, "evidence")
18
+ },
19
+ claims: {
20
+ uniqueId: (0, _converters.getValueFromDisclosures)(disclosures, "unique_id"),
21
+ givenName: (0, _converters.getValueFromDisclosures)(disclosures, "given_name"),
22
+ familyName: (0, _converters.getValueFromDisclosures)(disclosures, "family_name"),
23
+ birthdate: (0, _converters.getValueFromDisclosures)(disclosures, "birthdate"),
24
+ placeOfBirth: (0, _converters.getValueFromDisclosures)(disclosures, "place_of_birth"),
25
+ taxIdCode: (0, _converters.getValueFromDisclosures)(disclosures, "tax_id_number")
26
+ }
27
+ });
28
+ }
29
+ //# sourceMappingURL=converters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_converters","require","_types","pidFromToken","sdJwt","disclosures","PID","parse","issuer","payload","iss","issuedAt","Date","iat","expiration","exp","verification","trustFramework","verified_claims","trust_framework","assuranceLevel","assurance_level","evidence","getValueFromDisclosures","claims","uniqueId","givenName","familyName","birthdate","placeOfBirth","taxIdCode"],"sourceRoot":"../../../../src","sources":["pid/sd-jwt/converters.ts"],"mappings":";;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAEO,SAASE,YAAYA,CAACC,KAAe,EAAEC,WAAyB,EAAO;EAC5E,OAAOC,UAAG,CAACC,KAAK,CAAC;IACfC,MAAM,EAAEJ,KAAK,CAACK,OAAO,CAACC,GAAG;IACzBC,QAAQ,EAAE,IAAIC,IAAI,CAACR,KAAK,CAACK,OAAO,CAACI,GAAG,GAAG,IAAI,CAAC;IAC5CC,UAAU,EAAE,IAAIF,IAAI,CAACR,KAAK,CAACK,OAAO,CAACM,GAAG,GAAG,IAAI,CAAC;IAC9CC,YAAY,EAAE;MACZC,cAAc,EACZb,KAAK,CAACK,OAAO,CAACS,eAAe,CAACF,YAAY,CAACG,eAAe;MAC5DC,cAAc,EACZhB,KAAK,CAACK,OAAO,CAACS,eAAe,CAACF,YAAY,CAACK,eAAe;MAC5DC,QAAQ,EAAE,IAAAC,mCAAuB,EAAClB,WAAW,EAAE,UAAU;IAC3D,CAAC;IACDmB,MAAM,EAAE;MACNC,QAAQ,EAAE,IAAAF,mCAAuB,EAAClB,WAAW,EAAE,WAAW,CAAC;MAC3DqB,SAAS,EAAE,IAAAH,mCAAuB,EAAClB,WAAW,EAAE,YAAY,CAAC;MAC7DsB,UAAU,EAAE,IAAAJ,mCAAuB,EAAClB,WAAW,EAAE,aAAa,CAAC;MAC/DuB,SAAS,EAAE,IAAAL,mCAAuB,EAAClB,WAAW,EAAE,WAAW,CAAC;MAC5DwB,YAAY,EAAE,IAAAN,mCAAuB,EAAClB,WAAW,EAAE,gBAAgB,CAAC;MACpEyB,SAAS,EAAE,IAAAP,mCAAuB,EAAClB,WAAW,EAAE,eAAe;IACjE;EACF,CAAC,CAAC;AACJ"}
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "PID", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _types2.PID;
10
+ }
11
+ });
12
+ exports.decode = decode;
13
+ exports.verify = verify;
14
+ var _sdJwt = require("../../sd-jwt");
15
+ var _converters = require("./converters");
16
+ var _types = require("../../sd-jwt/types");
17
+ var _types2 = require("./types");
18
+ /**
19
+ * Decode a given SD-JWT with Disclosures to get the parsed PID object they define.
20
+ * It ensures provided data is in a valid shape.
21
+ *
22
+ * It DOES NOT verify token signature nor check disclosures are correctly referenced by the SD-JWT.
23
+ * Use {@link verify} instead
24
+ *
25
+ * @function
26
+ * @param token The encoded token that represents a valid sd-jwt for verifiable credentials
27
+ *
28
+ * @returns The validated PID object along with the parsed SD-JWT token and the parsed disclosures
29
+ * @throws A decoding error if the token doesn't resolve in a valid SD-JWT
30
+ * @throws A validation error if the provided data doesn't result in a valid PID
31
+ *
32
+ */
33
+ function decode(token) {
34
+ let {
35
+ sdJwt,
36
+ disclosures
37
+ } = (0, _sdJwt.decode)(token, _types.SdJwt4VC);
38
+ const pid = (0, _converters.pidFromToken)(sdJwt, disclosures);
39
+ return {
40
+ pid,
41
+ sdJwt,
42
+ disclosures
43
+ };
44
+ }
45
+
46
+ /**
47
+ * Verify a given SD-JWT with Disclosures to get the parsed PID object they define.
48
+ * Same as {@link decode} plus:
49
+ * - token signature verification
50
+ * - ensure disclosures are well-defined inside the SD-JWT
51
+ *
52
+ * @async @function
53
+ *
54
+ * @todo implement signature validation
55
+ * @todo check disclosures in sd-jwt
56
+ *
57
+ * @param token The encoded token that represents a valid sd-jwt for verifiable credentials
58
+ *
59
+ * @returns {VerifyResult} The validated PID object along with the parsed SD-JWT token and the parsed disclosures
60
+ * @throws A decoding error if the token doesn't resolve in a valid SD-JWT
61
+ * @throws A validation error if the provided data doesn't result in a valid PID
62
+ * @throws A validation error if the provided disclosures are not defined in the SD-JWT
63
+ * @throws Invalid signature error if the token signature is not valid
64
+ *
65
+ */
66
+ async function verify(token) {
67
+ const decoded = decode(token);
68
+ const publicKey = decoded.sdJwt.payload.cnf.jwk;
69
+ await (0, _sdJwt.verify)(token, publicKey, _types.SdJwt4VC);
70
+ return decoded;
71
+ }
72
+
73
+ /**
74
+ * Result object for {@link verify}
75
+ */
76
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_sdJwt","require","_converters","_types","_types2","decode","token","sdJwt","disclosures","decodeJwt","SdJwt4VC","pid","pidFromToken","verify","decoded","publicKey","payload","cnf","jwk","verifyJwt"],"sourceRoot":"../../../../src","sources":["pid/sd-jwt/index.ts"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAkEA,IAAAG,OAAA,GAAAH,OAAA;AAhEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASI,MAAMA,CAACC,KAAa,EAAgB;EAClD,IAAI;IAAEC,KAAK;IAAEC;EAAY,CAAC,GAAG,IAAAC,aAAS,EAACH,KAAK,EAAEI,eAAQ,CAAC;EACvD,MAAMC,GAAG,GAAG,IAAAC,wBAAY,EAACL,KAAK,EAAEC,WAAW,CAAC;EAE5C,OAAO;IAAEG,GAAG;IAAEJ,KAAK;IAAEC;EAAY,CAAC;AACpC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeK,MAAMA,CAACP,KAAa,EAAyB;EACjE,MAAMQ,OAAO,GAAGT,MAAM,CAACC,KAAK,CAAC;EAC7B,MAAMS,SAAS,GAAGD,OAAO,CAACP,KAAK,CAACS,OAAO,CAACC,GAAG,CAACC,GAAG;EAC/C,MAAM,IAAAC,aAAS,EAACb,KAAK,EAAES,SAAS,EAAEL,eAAQ,CAAC;EAE3C,OAAOI,OAAO;AAChB;;AAWA;AACA;AACA"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PID = void 0;
7
+ var _zod = require("zod");
8
+ const VerificationEvidence = _zod.z.object({
9
+ type: _zod.z.string(),
10
+ record: _zod.z.object({
11
+ type: _zod.z.string(),
12
+ source: _zod.z.object({
13
+ organization_name: _zod.z.string(),
14
+ organization_id: _zod.z.string(),
15
+ country_code: _zod.z.string()
16
+ })
17
+ })
18
+ });
19
+ const Verification = _zod.z.object({
20
+ trustFramework: _zod.z.literal("eidas"),
21
+ assuranceLevel: _zod.z.string(),
22
+ evidence: _zod.z.array(VerificationEvidence)
23
+ });
24
+
25
+ /**
26
+ * Data structure for the PID.
27
+ * It contains PID claims in plain text as well as verification data with the issuer's information
28
+ *
29
+ * @see https://italia.github.io/eidas-it-wallet-docs/en/pid-data-model.html
30
+ */
31
+
32
+ const PID = _zod.z.object({
33
+ issuer: _zod.z.string(),
34
+ issuedAt: _zod.z.date(),
35
+ expiration: _zod.z.date(),
36
+ verification: Verification,
37
+ claims: _zod.z.object({
38
+ uniqueId: _zod.z.string(),
39
+ givenName: _zod.z.string(),
40
+ familyName: _zod.z.string(),
41
+ birthdate: _zod.z.string(),
42
+ placeOfBirth: _zod.z.object({
43
+ country: _zod.z.string(),
44
+ locality: _zod.z.string()
45
+ }),
46
+ taxIdCode: _zod.z.string()
47
+ })
48
+ });
49
+ exports.PID = PID;
50
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_zod","require","VerificationEvidence","z","object","type","string","record","source","organization_name","organization_id","country_code","Verification","trustFramework","literal","assuranceLevel","evidence","array","PID","issuer","issuedAt","date","expiration","verification","claims","uniqueId","givenName","familyName","birthdate","placeOfBirth","country","locality","taxIdCode","exports"],"sourceRoot":"../../../../src","sources":["pid/sd-jwt/types.ts"],"mappings":";;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA;AAEA,MAAMC,oBAAoB,GAAGC,MAAC,CAACC,MAAM,CAAC;EACpCC,IAAI,EAAEF,MAAC,CAACG,MAAM,CAAC,CAAC;EAChBC,MAAM,EAAEJ,MAAC,CAACC,MAAM,CAAC;IACfC,IAAI,EAAEF,MAAC,CAACG,MAAM,CAAC,CAAC;IAChBE,MAAM,EAAEL,MAAC,CAACC,MAAM,CAAC;MACfK,iBAAiB,EAAEN,MAAC,CAACG,MAAM,CAAC,CAAC;MAC7BI,eAAe,EAAEP,MAAC,CAACG,MAAM,CAAC,CAAC;MAC3BK,YAAY,EAAER,MAAC,CAACG,MAAM,CAAC;IACzB,CAAC;EACH,CAAC;AACH,CAAC,CAAC;AAEF,MAAMM,YAAY,GAAGT,MAAC,CAACC,MAAM,CAAC;EAC5BS,cAAc,EAAEV,MAAC,CAACW,OAAO,CAAC,OAAO,CAAC;EAClCC,cAAc,EAAEZ,MAAC,CAACG,MAAM,CAAC,CAAC;EAC1BU,QAAQ,EAAEb,MAAC,CAACc,KAAK,CAACf,oBAAoB;AACxC,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;;AAEO,MAAMgB,GAAG,GAAGf,MAAC,CAACC,MAAM,CAAC;EAC1Be,MAAM,EAAEhB,MAAC,CAACG,MAAM,CAAC,CAAC;EAClBc,QAAQ,EAAEjB,MAAC,CAACkB,IAAI,CAAC,CAAC;EAClBC,UAAU,EAAEnB,MAAC,CAACkB,IAAI,CAAC,CAAC;EACpBE,YAAY,EAAEX,YAAY;EAC1BY,MAAM,EAAErB,MAAC,CAACC,MAAM,CAAC;IACfqB,QAAQ,EAAEtB,MAAC,CAACG,MAAM,CAAC,CAAC;IACpBoB,SAAS,EAAEvB,MAAC,CAACG,MAAM,CAAC,CAAC;IACrBqB,UAAU,EAAExB,MAAC,CAACG,MAAM,CAAC,CAAC;IACtBsB,SAAS,EAAEzB,MAAC,CAACG,MAAM,CAAC,CAAC;IACrBuB,YAAY,EAAE1B,MAAC,CAACC,MAAM,CAAC;MACrB0B,OAAO,EAAE3B,MAAC,CAACG,MAAM,CAAC,CAAC;MACnByB,QAAQ,EAAE5B,MAAC,CAACG,MAAM,CAAC;IACrB,CAAC,CAAC;IACF0B,SAAS,EAAE7B,MAAC,CAACG,MAAM,CAAC;EACtB,CAAC;AACH,CAAC,CAAC;AAAC2B,OAAA,CAAAf,GAAA,GAAAA,GAAA"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var _converters = require("../converters");
4
+ const disclosures = [["6w1_soRXFgaHKfpYn3cvfQ", "given_name", "Mario"], ["fuNp97Hf3wV6y48y-QZhIg", "birthdate", "1980-10-01"], ["p-9LzyWHZBVDvhXDWkN2xA", "place_of_birth", {
5
+ country: "IT",
6
+ locality: "Rome"
7
+ }]];
8
+ describe("getValueFromDisclosures", () => {
9
+ it("should return correct value for given_name", () => {
10
+ const success = (0, _converters.getValueFromDisclosures)(disclosures, "given_name");
11
+ expect(success).toBe("Mario");
12
+ });
13
+ it("should return correct value for place_of_birth", () => {
14
+ const success = (0, _converters.getValueFromDisclosures)(disclosures, "place_of_birth");
15
+ expect(success).toEqual({
16
+ country: "IT",
17
+ locality: "Rome"
18
+ });
19
+ });
20
+ it("should fail", () => {
21
+ const success = (0, _converters.getValueFromDisclosures)(disclosures, "given_surname");
22
+ expect(success).toBeUndefined();
23
+ });
24
+ });
25
+ //# sourceMappingURL=converters.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_converters","require","disclosures","country","locality","describe","it","success","getValueFromDisclosures","expect","toBe","toEqual","toBeUndefined"],"sourceRoot":"../../../../src","sources":["sd-jwt/__test__/converters.test.ts"],"mappings":";;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAGA,MAAMC,WAAyB,GAAG,CAChC,CAAC,wBAAwB,EAAE,YAAY,EAAE,OAAO,CAAC,EACjD,CAAC,wBAAwB,EAAE,WAAW,EAAE,YAAY,CAAC,EACrD,CACE,wBAAwB,EACxB,gBAAgB,EAChB;EAAEC,OAAO,EAAE,IAAI;EAAEC,QAAQ,EAAE;AAAO,CAAC,CACpC,CACF;AAEDC,QAAQ,CAAC,yBAAyB,EAAE,MAAM;EACxCC,EAAE,CAAC,4CAA4C,EAAE,MAAM;IACrD,MAAMC,OAAO,GAAG,IAAAC,mCAAuB,EAACN,WAAW,EAAE,YAAY,CAAC;IAClEO,MAAM,CAACF,OAAO,CAAC,CAACG,IAAI,CAAC,OAAO,CAAC;EAC/B,CAAC,CAAC;EACFJ,EAAE,CAAC,gDAAgD,EAAE,MAAM;IACzD,MAAMC,OAAO,GAAG,IAAAC,mCAAuB,EAACN,WAAW,EAAE,gBAAgB,CAAC;IACtEO,MAAM,CAACF,OAAO,CAAC,CAACI,OAAO,CAAC;MAAER,OAAO,EAAE,IAAI;MAAEC,QAAQ,EAAE;IAAO,CAAC,CAAC;EAC9D,CAAC,CAAC;EACFE,EAAE,CAAC,aAAa,EAAE,MAAM;IACtB,MAAMC,OAAO,GAAG,IAAAC,mCAAuB,EAACN,WAAW,EAAE,eAAe,CAAC;IACrEO,MAAM,CAACF,OAAO,CAAC,CAACK,aAAa,CAAC,CAAC;EACjC,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ var _types = require("../types");
4
+ describe("SdJwt4VC", () => {
5
+ it("should accept a valid token", () => {
6
+ // example provided at https://italia.github.io/eidas-it-wallet-docs/en/pid-data-model.html
7
+ const token = {
8
+ header: {
9
+ typ: "vc+sd-jwt",
10
+ alg: "RS512",
11
+ kid: "dB67gL7ck3TFiIAf7N6_7SHvqk0MDYMEQcoGGlkUAAw",
12
+ trust_chain: ["NEhRdERpYnlHY3M5WldWTWZ2aUhm ...", "eyJhbGciOiJSUzI1NiIsImtpZCI6 ...", "IkJYdmZybG5oQU11SFIwN2FqVW1B ..."]
13
+ },
14
+ payload: {
15
+ iss: "https://pidprovider.example.org",
16
+ sub: "NzbLsXh8uDCcd7noWXFZAfHkxZsRGC9Xs...",
17
+ jti: "urn:uuid:6c5c0a49-b589-431d-bae7-219122a9ec2c",
18
+ iat: 1541493724,
19
+ exp: 1541493724,
20
+ status: "https://pidprovider.example.org/status",
21
+ cnf: {
22
+ jwk: {
23
+ kty: "RSA",
24
+ use: "sig",
25
+ n: "1Ta-sE …",
26
+ e: "AQAB",
27
+ kid: "YhNFS3YnC9tjiCaivhWLVUJ3AxwGGz_98uRFaqMEEs"
28
+ }
29
+ },
30
+ type: "PersonIdentificationData",
31
+ verified_claims: {
32
+ verification: {
33
+ _sd: ["OGm7ryXgt5Xzlevp-Hu-UTk0a-TxAaPAobqv1pIWMfw"],
34
+ trust_framework: "eidas",
35
+ assurance_level: "high"
36
+ },
37
+ claims: {
38
+ _sd: ["8JjozBfovMNvQ3HflmPWy4O19Gpxs61FWHjZebU589E", "BoMGktW1rbikntw8Fzx_BeL4YbAndr6AHsdgpatFCig", "CFLGzentGNRFngnLVVQVcoAFi05r6RJUX-rdbLdEfew", "JU_sTaHCngS32X-0ajHrd1-HCLCkpT5YqgcfQme168w", "VQI-S1mT1Kxfq2o8J9io7xMMX2MIxaG9M9PeJVqrMcA", "zVdghcmClMVWlUgGsGpSkCPkEHZ4u9oWj1SlIBlCc1o"]
39
+ }
40
+ },
41
+ _sd_alg: "sha-256"
42
+ }
43
+ };
44
+ const {
45
+ success
46
+ } = _types.SdJwt4VC.safeParse(token);
47
+ expect(success).toBe(true);
48
+ });
49
+ });
50
+ describe("Disclosure", () => {
51
+ it("should accept a valid disclosure", () => {
52
+ // example provided at https://italia.github.io/eidas-it-wallet-docs/en/pid-data-model.html
53
+ const value = ["2GLC42sKQveCfGfryNRN9w", "evidence", [{
54
+ type: "electronic_record",
55
+ record: {
56
+ type: "eidas.it.cie",
57
+ source: {
58
+ organization_name: "Ministero dell'Interno",
59
+ organization_id: "m_it",
60
+ country_code: "IT"
61
+ }
62
+ }
63
+ }]];
64
+ const {
65
+ success
66
+ } = _types.Disclosure.safeParse(value);
67
+ expect(success).toBe(true);
68
+ });
69
+ });
70
+ //# sourceMappingURL=types.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_types","require","describe","it","token","header","typ","alg","kid","trust_chain","payload","iss","sub","jti","iat","exp","status","cnf","jwk","kty","use","n","e","type","verified_claims","verification","_sd","trust_framework","assurance_level","claims","_sd_alg","success","SdJwt4VC","safeParse","expect","toBe","value","record","source","organization_name","organization_id","country_code","Disclosure"],"sourceRoot":"../../../../src","sources":["sd-jwt/__test__/types.test.ts"],"mappings":";;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEAC,QAAQ,CAAC,UAAU,EAAE,MAAM;EACzBC,EAAE,CAAC,6BAA6B,EAAE,MAAM;IACtC;IACA,MAAMC,KAAK,GAAG;MACZC,MAAM,EAAE;QACNC,GAAG,EAAE,WAAW;QAChBC,GAAG,EAAE,OAAO;QACZC,GAAG,EAAE,6CAA6C;QAClDC,WAAW,EAAE,CACX,kCAAkC,EAClC,kCAAkC,EAClC,kCAAkC;MAEtC,CAAC;MACDC,OAAO,EAAE;QACPC,GAAG,EAAE,iCAAiC;QACtCC,GAAG,EAAE,sCAAsC;QAC3CC,GAAG,EAAE,+CAA+C;QACpDC,GAAG,EAAE,UAAU;QACfC,GAAG,EAAE,UAAU;QACfC,MAAM,EAAE,wCAAwC;QAChDC,GAAG,EAAE;UACHC,GAAG,EAAE;YACHC,GAAG,EAAE,KAAK;YACVC,GAAG,EAAE,KAAK;YACVC,CAAC,EAAE,UAAU;YACbC,CAAC,EAAE,MAAM;YACTd,GAAG,EAAE;UACP;QACF,CAAC;QACDe,IAAI,EAAE,0BAA0B;QAChCC,eAAe,EAAE;UACfC,YAAY,EAAE;YACZC,GAAG,EAAE,CAAC,6CAA6C,CAAC;YACpDC,eAAe,EAAE,OAAO;YACxBC,eAAe,EAAE;UACnB,CAAC;UACDC,MAAM,EAAE;YACNH,GAAG,EAAE,CACH,6CAA6C,EAC7C,6CAA6C,EAC7C,6CAA6C,EAC7C,6CAA6C,EAC7C,6CAA6C,EAC7C,6CAA6C;UAEjD;QACF,CAAC;QACDI,OAAO,EAAE;MACX;IACF,CAAC;IAED,MAAM;MAAEC;IAAQ,CAAC,GAAGC,eAAQ,CAACC,SAAS,CAAC7B,KAAK,CAAC;IAE7C8B,MAAM,CAACH,OAAO,CAAC,CAACI,IAAI,CAAC,IAAI,CAAC;EAC5B,CAAC,CAAC;AACJ,CAAC,CAAC;AAEFjC,QAAQ,CAAC,YAAY,EAAE,MAAM;EAC3BC,EAAE,CAAC,kCAAkC,EAAE,MAAM;IAC3C;IACA,MAAMiC,KAAK,GAAG,CACZ,wBAAwB,EACxB,UAAU,EACV,CACE;MACEb,IAAI,EAAE,mBAAmB;MACzBc,MAAM,EAAE;QACNd,IAAI,EAAE,cAAc;QACpBe,MAAM,EAAE;UACNC,iBAAiB,EAAE,wBAAwB;UAC3CC,eAAe,EAAE,MAAM;UACvBC,YAAY,EAAE;QAChB;MACF;IACF,CAAC,CACF,CACF;IAED,MAAM;MAAEV;IAAQ,CAAC,GAAGW,iBAAU,CAACT,SAAS,CAACG,KAAK,CAAC;IAC/CF,MAAM,CAACH,OAAO,CAAC,CAACI,IAAI,CAAC,IAAI,CAAC;EAC5B,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getValueFromDisclosures = getValueFromDisclosures;
7
+ function getValueFromDisclosures(disclosures, claimName) {
8
+ var _disclosures$find;
9
+ const value = (_disclosures$find = disclosures.find(_ref => {
10
+ let [, name] = _ref;
11
+ return name === claimName;
12
+ })) === null || _disclosures$find === void 0 ? void 0 : _disclosures$find[2];
13
+ // value didn't found, we return nothing
14
+ if (!value) {
15
+ return undefined;
16
+ }
17
+ // value is not a string, it's probably fine
18
+ if (typeof value !== "string") {
19
+ return value;
20
+ }
21
+ // value is a string, we try to parse it
22
+ // maybe it's a serialized object
23
+ try {
24
+ return JSON.parse(value);
25
+ } catch (error) {
26
+ // It's definitely a string
27
+ return value;
28
+ }
29
+ }
30
+ //# sourceMappingURL=converters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getValueFromDisclosures","disclosures","claimName","_disclosures$find","value","find","_ref","name","undefined","JSON","parse","error"],"sourceRoot":"../../../src","sources":["sd-jwt/converters.ts"],"mappings":";;;;;;AAEO,SAASA,uBAAuBA,CACrCC,WAAyB,EACzBC,SAAiB,EACjB;EAAA,IAAAC,iBAAA;EACA,MAAMC,KAAK,IAAAD,iBAAA,GAAGF,WAAW,CAACI,IAAI,CAACC,IAAA;IAAA,IAAC,GAAGC,IAAI,CAAC,GAAAD,IAAA;IAAA,OAAKC,IAAI,KAAKL,SAAS;EAAA,EAAC,cAAAC,iBAAA,uBAAlDA,iBAAA,CAAqD,CAAC,CAAC;EACrE;EACA,IAAI,CAACC,KAAK,EAAE;IACV,OAAOI,SAAS;EAClB;EACA;EACA,IAAI,OAAOJ,KAAK,KAAK,QAAQ,EAAE;IAC7B,OAAOA,KAAK;EACd;EACA;EACA;EACA,IAAI;IACF,OAAOK,IAAI,CAACC,KAAK,CAACN,KAAK,CAAC;EAC1B,CAAC,CAAC,OAAOO,KAAK,EAAE;IACd;IACA,OAAOP,KAAK;EACd;AACF"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.verify = exports.decode = void 0;
7
+ var _ioReactNativeJwt = require("@pagopa/io-react-native-jwt");
8
+ var _types = require("./types");
9
+ var _verifier = require("./verifier");
10
+ /**
11
+ * Decode a given SD-JWT with Disclosures to get the parsed SD-JWT object they define.
12
+ * It ensures provided data is in a valid shape.
13
+ *
14
+ * It DOES NOT verify token signature nor check disclosures are correctly referenced by the SD-JWT.
15
+ * Use {@link verify} instead
16
+ *
17
+ * @function
18
+ * @param token The encoded token that represents a valid sd-jwt for verifiable credentials
19
+ * @param schema Schema to use to parse the SD-JWT
20
+ *
21
+ * @returns The parsed SD-JWT token and the parsed disclosures
22
+ *
23
+ */
24
+ const decode = (token, schema) => {
25
+ // token are expected in the form "sd-jwt~disclosure0~disclosure1~...~disclosureN"
26
+ const [rawSdJwt = "", ...rawDisclosures] = token.split("~");
27
+
28
+ // get the sd-jwt as object
29
+ // validate it's a valid SD-JWT for Verifiable Credentials
30
+ const decodedJwt = (0, _ioReactNativeJwt.decode)(rawSdJwt);
31
+ const sdJwt = schema.parse({
32
+ header: decodedJwt.protectedHeader,
33
+ payload: decodedJwt.payload
34
+ });
35
+
36
+ // get disclosures as list of triples
37
+ // validate each triple
38
+ // throw a validation error if at least one fails to parse
39
+ const disclosures = rawDisclosures.map(_ioReactNativeJwt.decodeBase64).map(e => JSON.parse(e)).map(e => _types.Disclosure.parse(e));
40
+ return {
41
+ sdJwt,
42
+ disclosures
43
+ };
44
+ };
45
+
46
+ /**
47
+ * Verify a given SD-JWT with Disclosures
48
+ * Same as {@link decode} plus:
49
+ * - token signature verification
50
+ * - ensure disclosures are well-defined inside the SD-JWT
51
+ *
52
+ * @async @function
53
+ *
54
+ *
55
+ * @param token The encoded token that represents a valid sd-jwt for verifiable credentials
56
+ * @param publicKey The public key to validate the signature
57
+ * @param schema Schema to use to parse the SD-JWT
58
+ *
59
+ * @returns The parsed SD-JWT token and the parsed disclosures
60
+ *
61
+ */
62
+ exports.decode = decode;
63
+ const verify = async (token, publicKey, schema) => {
64
+ // get decoded data
65
+ const [rawSdJwt = ""] = token.split("~");
66
+ const decoded = decode(token, schema);
67
+
68
+ //Check signature
69
+ await (0, _ioReactNativeJwt.verify)(rawSdJwt, publicKey);
70
+
71
+ //Check disclosures in sd-jwt
72
+ const claims = [...decoded.sdJwt.payload.verified_claims.verification._sd, ...decoded.sdJwt.payload.verified_claims.claims._sd];
73
+ await Promise.all(decoded.disclosures.map(async disclosure => await (0, _verifier.verifyDisclosure)(disclosure, claims)));
74
+ return decoded;
75
+ };
76
+ exports.verify = verify;
77
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_ioReactNativeJwt","require","_types","_verifier","decode","token","schema","rawSdJwt","rawDisclosures","split","decodedJwt","decodeJwt","sdJwt","parse","header","protectedHeader","payload","disclosures","map","decodeBase64","e","JSON","Disclosure","exports","verify","publicKey","decoded","verifyJwt","claims","verified_claims","verification","_sd","Promise","all","disclosure","verifyDisclosure"],"sourceRoot":"../../../src","sources":["sd-jwt/index.ts"],"mappings":";;;;;;AAEA,IAAAA,iBAAA,GAAAC,OAAA;AAIA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMG,MAAM,GAAGA,CACpBC,KAAa,EACbC,MAAS,KAC4C;EACrD;EACA,MAAM,CAACC,QAAQ,GAAG,EAAE,EAAE,GAAGC,cAAc,CAAC,GAAGH,KAAK,CAACI,KAAK,CAAC,GAAG,CAAC;;EAE3D;EACA;EACA,MAAMC,UAAU,GAAG,IAAAC,wBAAS,EAACJ,QAAQ,CAAC;EACtC,MAAMK,KAAK,GAAGN,MAAM,CAACO,KAAK,CAAC;IACzBC,MAAM,EAAEJ,UAAU,CAACK,eAAe;IAClCC,OAAO,EAAEN,UAAU,CAACM;EACtB,CAAC,CAAC;;EAEF;EACA;EACA;EACA,MAAMC,WAAW,GAAGT,cAAc,CAC/BU,GAAG,CAACC,8BAAY,CAAC,CACjBD,GAAG,CAAEE,CAAC,IAAKC,IAAI,CAACR,KAAK,CAACO,CAAC,CAAC,CAAC,CACzBF,GAAG,CAAEE,CAAC,IAAKE,iBAAU,CAACT,KAAK,CAACO,CAAC,CAAC,CAAC;EAElC,OAAO;IAAER,KAAK;IAAEK;EAAY,CAAC;AAC/B,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAfAM,OAAA,CAAAnB,MAAA,GAAAA,MAAA;AAgBO,MAAMoB,MAAM,GAAG,MAAAA,CACpBnB,KAAa,EACboB,SAAc,EACdnB,MAAS,KACqD;EAC9D;EACA,MAAM,CAACC,QAAQ,GAAG,EAAE,CAAC,GAAGF,KAAK,CAACI,KAAK,CAAC,GAAG,CAAC;EACxC,MAAMiB,OAAO,GAAGtB,MAAM,CAACC,KAAK,EAAEC,MAAM,CAAC;;EAErC;EACA,MAAM,IAAAqB,wBAAS,EAACpB,QAAQ,EAAEkB,SAAS,CAAC;;EAEpC;EACA,MAAMG,MAAM,GAAG,CACb,GAAGF,OAAO,CAACd,KAAK,CAACI,OAAO,CAACa,eAAe,CAACC,YAAY,CAACC,GAAG,EACzD,GAAGL,OAAO,CAACd,KAAK,CAACI,OAAO,CAACa,eAAe,CAACD,MAAM,CAACG,GAAG,CACpD;EAED,MAAMC,OAAO,CAACC,GAAG,CACfP,OAAO,CAACT,WAAW,CAACC,GAAG,CACrB,MAAOgB,UAAU,IAAK,MAAM,IAAAC,0BAAgB,EAACD,UAAU,EAAEN,MAAM,CACjE,CACF,CAAC;EAED,OAAOF,OAAO;AAChB,CAAC;AAACH,OAAA,CAAAC,MAAA,GAAAA,MAAA"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.UnixTime = exports.SdJwt4VC = exports.ObfuscatedDisclosures = exports.Disclosure = void 0;
7
+ var _jwk = require("../utils/jwk");
8
+ var _zod = require("zod");
9
+ const UnixTime = _zod.z.number().min(0).max(2147483647000);
10
+ exports.UnixTime = UnixTime;
11
+ const ObfuscatedDisclosures = _zod.z.object({
12
+ _sd: _zod.z.array(_zod.z.string())
13
+ });
14
+
15
+ /**
16
+ * A triple of values in the form of {salt, claim name, claim value} that represent a parsed disclosure.
17
+ *
18
+ * @see https://datatracker.ietf.org/doc/html/draft-ietf-oauth-selective-disclosure-jwt-04
19
+ * @see https://vcstuff.github.io/draft-terbu-sd-jwt-vc/draft-terbu-oauth-sd-jwt-vc.html
20
+ */
21
+ exports.ObfuscatedDisclosures = ObfuscatedDisclosures;
22
+ const Disclosure = _zod.z.tuple([/* salt */_zod.z.string(), /* claim name */_zod.z.string(), /* claim value */_zod.z.unknown()]);
23
+ exports.Disclosure = Disclosure;
24
+ const SdJwt4VC = _zod.z.object({
25
+ header: _zod.z.object({
26
+ typ: _zod.z.literal("vc+sd-jwt"),
27
+ alg: _zod.z.string(),
28
+ kid: _zod.z.string(),
29
+ trust_chain: _zod.z.array(_zod.z.string())
30
+ }),
31
+ payload: _zod.z.object({
32
+ iss: _zod.z.string(),
33
+ sub: _zod.z.string(),
34
+ jti: _zod.z.string(),
35
+ iat: UnixTime,
36
+ exp: UnixTime,
37
+ status: _zod.z.string(),
38
+ cnf: _zod.z.object({
39
+ jwk: _jwk.JWK
40
+ }),
41
+ type: _zod.z.literal("PersonIdentificationData"),
42
+ verified_claims: _zod.z.object({
43
+ verification: _zod.z.intersection(_zod.z.object({
44
+ trust_framework: _zod.z.literal("eidas"),
45
+ assurance_level: _zod.z.string()
46
+ }), ObfuscatedDisclosures),
47
+ claims: ObfuscatedDisclosures
48
+ }),
49
+ _sd_alg: _zod.z.literal("sha-256")
50
+ })
51
+ });
52
+ exports.SdJwt4VC = SdJwt4VC;
53
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_jwk","require","_zod","UnixTime","z","number","min","max","exports","ObfuscatedDisclosures","object","_sd","array","string","Disclosure","tuple","unknown","SdJwt4VC","header","typ","literal","alg","kid","trust_chain","payload","iss","sub","jti","iat","exp","status","cnf","jwk","JWK","type","verified_claims","verification","intersection","trust_framework","assurance_level","claims","_sd_alg"],"sourceRoot":"../../../src","sources":["sd-jwt/types.ts"],"mappings":";;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AAEO,MAAME,QAAQ,GAAGC,MAAC,CAACC,MAAM,CAAC,CAAC,CAACC,GAAG,CAAC,CAAC,CAAC,CAACC,GAAG,CAAC,aAAa,CAAC;AAACC,OAAA,CAAAL,QAAA,GAAAA,QAAA;AAItD,MAAMM,qBAAqB,GAAGL,MAAC,CAACM,MAAM,CAAC;EAAEC,GAAG,EAAEP,MAAC,CAACQ,KAAK,CAACR,MAAC,CAACS,MAAM,CAAC,CAAC;AAAE,CAAC,CAAC;;AAE3E;AACA;AACA;AACA;AACA;AACA;AALAL,OAAA,CAAAC,qBAAA,GAAAA,qBAAA;AAOO,MAAMK,UAAU,GAAGV,MAAC,CAACW,KAAK,CAAC,CAChC,UAAWX,MAAC,CAACS,MAAM,CAAC,CAAC,EACrB,gBAAiBT,MAAC,CAACS,MAAM,CAAC,CAAC,EAC3B,iBAAkBT,MAAC,CAACY,OAAO,CAAC,CAAC,CAC9B,CAAC;AAACR,OAAA,CAAAM,UAAA,GAAAA,UAAA;AAGI,MAAMG,QAAQ,GAAGb,MAAC,CAACM,MAAM,CAAC;EAC/BQ,MAAM,EAAEd,MAAC,CAACM,MAAM,CAAC;IACfS,GAAG,EAAEf,MAAC,CAACgB,OAAO,CAAC,WAAW,CAAC;IAC3BC,GAAG,EAAEjB,MAAC,CAACS,MAAM,CAAC,CAAC;IACfS,GAAG,EAAElB,MAAC,CAACS,MAAM,CAAC,CAAC;IACfU,WAAW,EAAEnB,MAAC,CAACQ,KAAK,CAACR,MAAC,CAACS,MAAM,CAAC,CAAC;EACjC,CAAC,CAAC;EACFW,OAAO,EAAEpB,MAAC,CAACM,MAAM,CAAC;IAChBe,GAAG,EAAErB,MAAC,CAACS,MAAM,CAAC,CAAC;IACfa,GAAG,EAAEtB,MAAC,CAACS,MAAM,CAAC,CAAC;IACfc,GAAG,EAAEvB,MAAC,CAACS,MAAM,CAAC,CAAC;IACfe,GAAG,EAAEzB,QAAQ;IACb0B,GAAG,EAAE1B,QAAQ;IACb2B,MAAM,EAAE1B,MAAC,CAACS,MAAM,CAAC,CAAC;IAClBkB,GAAG,EAAE3B,MAAC,CAACM,MAAM,CAAC;MACZsB,GAAG,EAAEC;IACP,CAAC,CAAC;IACFC,IAAI,EAAE9B,MAAC,CAACgB,OAAO,CAAC,0BAA0B,CAAC;IAC3Ce,eAAe,EAAE/B,MAAC,CAACM,MAAM,CAAC;MACxB0B,YAAY,EAAEhC,MAAC,CAACiC,YAAY,CAC1BjC,MAAC,CAACM,MAAM,CAAC;QACP4B,eAAe,EAAElC,MAAC,CAACgB,OAAO,CAAC,OAAO,CAAC;QACnCmB,eAAe,EAAEnC,MAAC,CAACS,MAAM,CAAC;MAC5B,CAAC,CAAC,EACFJ,qBACF,CAAC;MACD+B,MAAM,EAAE/B;IACV,CAAC,CAAC;IACFgC,OAAO,EAAErC,MAAC,CAACgB,OAAO,CAAC,SAAS;EAC9B,CAAC;AACH,CAAC,CAAC;AAACZ,OAAA,CAAAS,QAAA,GAAAA,QAAA"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.verifyDisclosure = void 0;
7
+ var _ioReactNativeJwt = require("@pagopa/io-react-native-jwt");
8
+ var _errors = require("../utils/errors");
9
+ const verifyDisclosure = async (disclosure, claims) => {
10
+ let disclosureString = JSON.stringify(disclosure);
11
+ let encodedDisclosure = (0, _ioReactNativeJwt.encodeBase64)(disclosureString);
12
+ let hash = await (0, _ioReactNativeJwt.sha256ToBase64)(encodedDisclosure);
13
+ if (!claims.includes(hash)) {
14
+ throw new _errors.ValidationFailed("Validation of disclosure failed", `${disclosure}`, "Disclosure hash not found in claims");
15
+ }
16
+ };
17
+ exports.verifyDisclosure = verifyDisclosure;
18
+ //# sourceMappingURL=verifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_ioReactNativeJwt","require","_errors","verifyDisclosure","disclosure","claims","disclosureString","JSON","stringify","encodedDisclosure","encodeBase64","hash","sha256ToBase64","includes","ValidationFailed","exports"],"sourceRoot":"../../../src","sources":["sd-jwt/verifier.ts"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAGO,MAAME,gBAAgB,GAAG,MAAAA,CAC9BC,UAAsB,EACtBC,MAAoC,KACjC;EACH,IAAIC,gBAAgB,GAAGC,IAAI,CAACC,SAAS,CAACJ,UAAU,CAAC;EACjD,IAAIK,iBAAiB,GAAG,IAAAC,8BAAY,EAACJ,gBAAgB,CAAC;EACtD,IAAIK,IAAI,GAAG,MAAM,IAAAC,gCAAc,EAACH,iBAAiB,CAAC;EAClD,IAAI,CAACJ,MAAM,CAACQ,QAAQ,CAACF,IAAI,CAAC,EAAE;IAC1B,MAAM,IAAIG,wBAAgB,CACxB,iCAAiC,EAChC,GAAEV,UAAW,EAAC,EACf,qCACF,CAAC;EACH;AACF,CAAC;AAACW,OAAA,CAAAZ,gBAAA,GAAAA,gBAAA"}