@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
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.WalletInstanceAttestationIssuingError = exports.ValidationFailed = exports.IoWalletError = void 0;
7
+ /**
8
+ * A generic Error that all other io-wallet specific Error subclasses extend.
9
+ *
10
+ * @example Checking thrown error is a io-wallet one
11
+ *
12
+ * ```js
13
+ * if (err instanceof errors.IoWalletError) {
14
+ * // ...
15
+ * }
16
+ * ```
17
+ */
18
+ class IoWalletError extends Error {
19
+ /** A unique error code for the particular error subclass. */
20
+ static get code() {
21
+ return "ERR_IO_WALLET_GENERIC";
22
+ }
23
+
24
+ /** A unique error code for the particular error subclass. */
25
+ code = "ERR_IO_WALLET_GENERIC";
26
+ constructor(message) {
27
+ var _Error$captureStackTr;
28
+ super(message);
29
+ this.name = this.constructor.name;
30
+ // @ts-ignore
31
+ (_Error$captureStackTr = Error.captureStackTrace) === null || _Error$captureStackTr === void 0 ? void 0 : _Error$captureStackTr.call(Error, this, this.constructor);
32
+ }
33
+ }
34
+ /**
35
+ * An error subclass thrown when validation fail
36
+ *
37
+ */
38
+ exports.IoWalletError = IoWalletError;
39
+ class ValidationFailed extends IoWalletError {
40
+ static get code() {
41
+ return "ERR_IO_WALLET_VALIDATION_FAILED";
42
+ }
43
+ code = "ERR_IO_WALLET_VALIDATION_FAILED";
44
+
45
+ /** The Claim for which the validation failed. */
46
+
47
+ /** Reason code for the validation failure. */
48
+
49
+ constructor(message) {
50
+ let claim = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "unspecified";
51
+ let reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "unspecified";
52
+ super(message);
53
+ this.claim = claim;
54
+ this.reason = reason;
55
+ }
56
+ }
57
+
58
+ /**
59
+ * An error subclass thrown when validation fail
60
+ *
61
+ */
62
+ exports.ValidationFailed = ValidationFailed;
63
+ class WalletInstanceAttestationIssuingError extends IoWalletError {
64
+ static get code() {
65
+ return "ERR_IO_WALLET_INSTANCE_ATTESTATION_ISSUING_FAILED";
66
+ }
67
+ code = "ERR_IO_WALLET_INSTANCE_ATTESTATION_ISSUING_FAILED";
68
+
69
+ /** The Claim for which the validation failed. */
70
+
71
+ /** Reason code for the validation failure. */
72
+
73
+ constructor(message) {
74
+ let claim = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "unspecified";
75
+ let reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "unspecified";
76
+ super(message);
77
+ this.claim = claim;
78
+ this.reason = reason;
79
+ }
80
+ }
81
+ exports.WalletInstanceAttestationIssuingError = WalletInstanceAttestationIssuingError;
82
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["IoWalletError","Error","code","constructor","message","_Error$captureStackTr","name","captureStackTrace","call","exports","ValidationFailed","claim","arguments","length","undefined","reason","WalletInstanceAttestationIssuingError"],"sourceRoot":"../../../src","sources":["utils/errors.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,aAAa,SAASC,KAAK,CAAC;EACvC;EACA,WAAWC,IAAIA,CAAA,EAAW;IACxB,O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AAF,SAAA,MAAG,aAAa;IAAA,IAAEG,MAAM,GAAAH,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,aAAa;IACxE,KAAK,CAACR,OAAO,CAAC;IACd,IAAI,CAACO,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACI,MAAM,GAAGA,MAAM;EACtB;AACF;AAACN,OAAA,CAAAO,qCAAA,GAAAA,qCAAA"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.JWK = void 0;
7
+ var _zod = require("zod");
8
+ const JWK = _zod.z.object({
9
+ /** JWK "alg" (Algorithm) Parameter. */
10
+ alg: _zod.z.string().optional(),
11
+ crv: _zod.z.string().optional(),
12
+ d: _zod.z.string().optional(),
13
+ dp: _zod.z.string().optional(),
14
+ dq: _zod.z.string().optional(),
15
+ e: _zod.z.string().optional(),
16
+ /** JWK "ext" (Extractable) Parameter. */
17
+ ext: _zod.z.boolean().optional(),
18
+ k: _zod.z.string().optional(),
19
+ /** JWK "key_ops" (Key Operations) Parameter. */
20
+ key_ops: _zod.z.array(_zod.z.string()).optional(),
21
+ /** JWK "kid" (Key ID) Parameter. */
22
+ kid: _zod.z.string().optional(),
23
+ /** JWK "kty" (Key Type) Parameter.
24
+ * This attribute is required to discriminate the
25
+ * type of EC/RSA algorithm */
26
+ kty: _zod.z.union([_zod.z.literal("RSA"), _zod.z.literal("EC")]),
27
+ n: _zod.z.string().optional(),
28
+ p: _zod.z.string().optional(),
29
+ q: _zod.z.string().optional(),
30
+ qi: _zod.z.string().optional(),
31
+ /** JWK "use" (Public Key Use) Parameter. */
32
+ use: _zod.z.string().optional(),
33
+ x: _zod.z.string().optional(),
34
+ y: _zod.z.string().optional(),
35
+ /** JWK "x5c" (X.509 Certificate Chain) Parameter. */
36
+ x5c: _zod.z.array(_zod.z.string()).optional(),
37
+ /** JWK "x5t" (X.509 Certificate SHA-1 Thumbprint) Parameter. */
38
+ x5t: _zod.z.string().optional(),
39
+ /** "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Parameter. */
40
+ "x5t#S256": _zod.z.string().optional(),
41
+ /** JWK "x5u" (X.509 URL) Parameter. */
42
+ x5u: _zod.z.string().optional()
43
+ });
44
+ exports.JWK = JWK;
45
+ //# sourceMappingURL=jwk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_zod","require","JWK","z","object","alg","string","optional","crv","d","dp","dq","e","ext","boolean","k","key_ops","array","kid","kty","union","literal","n","p","q","qi","use","x","y","x5c","x5t","x5u","exports"],"sourceRoot":"../../../src","sources":["utils/jwk.ts"],"mappings":";;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA;AAGO,MAAMC,GAAG,GAAGC,MAAC,CAACC,MAAM,CAAC;EAC1B;EACAC,GAAG,EAAEF,MAAC,CAACG,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EAC1BC,GAAG,EAAEL,MAAC,CAACG,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EAC1BE,CAAC,EAAEN,MAAC,CAACG,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EACxBG,EAAE,EAAEP,MAAC,CAACG,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EACzBI,EAAE,EAAER,MAAC,CAACG,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EACzBK,CAAC,EAAET,MAAC,CAACG,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EACxB;EACAM,GAAG,EAAEV,MAAC,CAACW,OAAO,CAAC,CAAC,CAACP,QAAQ,CAAC,CAAC;EAC3BQ,CAAC,EAAEZ,MAAC,CAACG,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EACxB;EACAS,OAAO,EAAEb,MAAC,CAACc,KAAK,CAACd,MAAC,CAACG,MAAM,CAAC,CAAC,CAAC,CAACC,QAA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0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Issuing", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _issuing.Issuing;
10
+ }
11
+ });
12
+ exports.decode = decode;
13
+ exports.verify = verify;
14
+ var _types = require("./types");
15
+ var _ioReactNativeJwt = require("@pagopa/io-react-native-jwt");
16
+ var _issuing = require("./issuing");
17
+ /**
18
+ * Decode a given JWT to get the parsed Wallet Instance Attestation object they define.
19
+ * It ensures provided data is in a valid shape.
20
+ *
21
+ * It DOES NOT verify token signature nor check disclosures are correctly referenced by the JWT.
22
+ * Use {@link verify} instead
23
+ *
24
+ * @function
25
+ * @param token The encoded token that represents a valid jwt for Wallet Instance Attestation
26
+ *
27
+ * @returns The validated Wallet Instance Attestation object
28
+ * @throws A decoding error if the token doesn't resolve in a valid JWT
29
+ * @throws A validation error if the provided data doesn't result in a valid Wallet Instance Attestation
30
+ *
31
+ */
32
+ function decode(token) {
33
+ // decode JWT parts
34
+ const decodedJwt = (0, _ioReactNativeJwt.decode)(token);
35
+ // parse JWT to ensure it has the shape of a WalletInstanceAttestationJwt
36
+ return _types.WalletInstanceAttestationJwt.parse({
37
+ header: decodedJwt.protectedHeader,
38
+ payload: decodedJwt.payload
39
+ });
40
+ }
41
+
42
+ /**
43
+ * Verify a given JWT to get the parsed Wallet Instance Attestation object they define.
44
+ * Same as {@link decode} plus token signature verification
45
+ *
46
+ * @async @function
47
+ *
48
+ *
49
+ * @param token The encoded token that represents a valid jwt
50
+ *
51
+ * @returns {WalletInstanceAttestationJwt} The validated Wallet Instance Attestation object
52
+ * @throws A decoding error if the token doesn't resolve in a valid JWT
53
+ * @throws A validation error if the provided data doesn't result in a valid Wallet Instance Attestation
54
+ * @throws Invalid signature error if the token signature is not valid
55
+ *
56
+ */
57
+ async function verify(token) {
58
+ const decoded = decode(token);
59
+ const pubKey = decoded.payload.cnf.jwk;
60
+ await (0, _ioReactNativeJwt.verify)(token, pubKey);
61
+ return decoded;
62
+ }
63
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_types","require","_ioReactNativeJwt","_issuing","decode","token","decodedJwt","decodeJwt","WalletInstanceAttestationJwt","parse","header","protectedHeader","payload","verify","decoded","pubKey","cnf","jwk","verifyJwt"],"sourceRoot":"../../../src","sources":["wallet-instance-attestation/index.ts"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AAGA,IAAAE,QAAA,GAAAF,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,MAAMA,CAACC,KAAa,EAAgC;EAClE;EACA,MAAMC,UAAU,GAAG,IAAAC,wBAAS,EAACF,KAAK,CAAC;EACnC;EACA,OAAOG,mCAA4B,CAACC,KAAK,CAAC;IACxCC,MAAM,EAAEJ,UAAU,CAACK,eAAe;IAClCC,OAAO,EAAEN,UAAU,CAACM;EACtB,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeC,MAAMA,CAC1BR,KAAa,EAC0B;EACvC,MAAMS,OAAO,GAAGV,MAAM,CAACC,KAAK,CAAC;EAC7B,MAAMU,MAAM,GAAGD,OAAO,CAACF,OAAO,CAACI,GAAG,CAACC,GAAG;EAEtC,MAAM,IAAAC,wBAAS,EAACb,KAAK,EAAEU,MAAM,CAAC;EAE9B,OAAOD,OAAO;AAChB"}
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Issuing = void 0;
7
+ var _ioReactNativeJwt = require("@pagopa/io-react-native-jwt");
8
+ var _jwk = require("../utils/jwk");
9
+ var _types = require("./types");
10
+ var _reactNativeUuid = _interopRequireDefault(require("react-native-uuid"));
11
+ var _errors = require("../utils/errors");
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ class Issuing {
14
+ constructor(walletProviderBaseUrl) {
15
+ this.walletProviderBaseUrl = walletProviderBaseUrl;
16
+ }
17
+
18
+ /**
19
+ * Get the Wallet Instance Attestation Request to sign
20
+ *
21
+ * @async @function
22
+ *
23
+ * @param jwk Public key of the wallet instance
24
+ *
25
+ * @returns {string} Wallet Instance Attestation Request to sign
26
+ *
27
+ */
28
+ async getAttestationRequestToSign(jwk) {
29
+ const parsedJwk = _jwk.JWK.parse(jwk);
30
+ const keyThumbprint = await (0, _ioReactNativeJwt.thumbprint)(parsedJwk);
31
+ const publicKey = {
32
+ ...parsedJwk,
33
+ kid: keyThumbprint
34
+ };
35
+ const walletInstanceAttestationRequest = new _ioReactNativeJwt.SignJWT({
36
+ iss: keyThumbprint,
37
+ sub: this.walletProviderBaseUrl,
38
+ jti: `${_reactNativeUuid.default.v4()}`,
39
+ type: "WalletInstanceAttestationRequest",
40
+ cnf: {
41
+ jwk: publicKey
42
+ }
43
+ }).setProtectedHeader({
44
+ alg: "ES256",
45
+ kid: publicKey.kid,
46
+ typ: "var+jwt"
47
+ }).setIssuedAt().setExpirationTime("1h").toSign();
48
+ return walletInstanceAttestationRequest;
49
+ }
50
+
51
+ /**
52
+ * Get the Wallet Instance Attestation given a
53
+ * Wallet Instance Attestation Request and signature
54
+ *
55
+ * @async @function
56
+ *
57
+ * @param attestationRequest Wallet Instance Attestaion Request
58
+ * obtained with {@link getAttestationRequestToSign}
59
+ * @param signature Signature of the Wallet Instance Attestaion Request
60
+ * @param appFetch Optional object with fetch function to use
61
+ *
62
+ * @returns {string} Wallet Instance Attestation
63
+ *
64
+ */
65
+ async getAttestation(attestationRequest, signature) {
66
+ let appFetch = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
67
+ fetch
68
+ };
69
+ const signedAttestationRequest = await _ioReactNativeJwt.SignJWT.appendSignature(attestationRequest, signature);
70
+ const decodedRequest = (0, _ioReactNativeJwt.decode)(signedAttestationRequest);
71
+ const parsedRequest = _types.WalletInstanceAttestationRequestJwt.parse({
72
+ payload: decodedRequest.payload,
73
+ header: decodedRequest.protectedHeader
74
+ });
75
+ const publicKey = parsedRequest.payload.cnf.jwk;
76
+ await (0, _ioReactNativeJwt.verify)(signedAttestationRequest, publicKey);
77
+ const tokenUrl = new URL("token", this.walletProviderBaseUrl).href;
78
+ const requestBody = {
79
+ grant_type: "urn:ietf:params:oauth:client-assertion-type:jwt-key-attestation",
80
+ assertion: signedAttestationRequest
81
+ };
82
+ const response = await appFetch.fetch(tokenUrl, {
83
+ method: "POST",
84
+ headers: {
85
+ "Content-Type": "application/json"
86
+ },
87
+ body: JSON.stringify(requestBody)
88
+ });
89
+ if (response.status === 201) {
90
+ return await response.text();
91
+ }
92
+ throw new _errors.WalletInstanceAttestationIssuingError("Unable to obtain wallet instance attestation from wallet provider", `Response code: ${response.status}`);
93
+ }
94
+ }
95
+ exports.Issuing = Issuing;
96
+ //# sourceMappingURL=issuing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_ioReactNativeJwt","require","_jwk","_types","_reactNativeUuid","_interopRequireDefault","_errors","obj","__esModule","default","Issuing","constructor","walletProviderBaseUrl","getAttestationRequestToSign","jwk","parsedJwk","JWK","parse","keyThumbprint","thumbprint","publicKey","kid","walletInstanceAttestationRequest","SignJWT","iss","sub","jti","uuid","v4","type","cnf","setProtectedHeader","alg","typ","setIssuedAt","setExpirationTime","toSign","getAttestation","attestationRequest","signature","appFetch","arguments","length","undefined","fetch","signedAttestationRequest","appendSignature","decodedRequest","decodeJwt","parsedRequest","WalletInstanceAttestationRequestJwt","payload","header","protectedHeader","verifyJwt","tokenUrl","URL","href","requestBody","grant_type","assertion","response","method","headers","body","JSON","stringify","status","text","WalletInstanceAttestationIssuingError","exports"],"sourceRoot":"../../../src","sources":["wallet-instance-attestation/issuing.ts"],"mappings":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EACpC,CAAC;EACH;AACF;AAACG,OAAA,CAAA5D,OAAA,GAAAA,OAAA"}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.WalletInstanceAttestationRequestJwt = exports.WalletInstanceAttestationJwt = void 0;
7
+ var _jwk = require("../utils/jwk");
8
+ var z = _interopRequireWildcard(require("zod"));
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
+ const UnixTime = z.number().min(0).max(2147483647000);
12
+ const Jwt = z.object({
13
+ header: z.object({
14
+ alg: z.string(),
15
+ kid: z.string(),
16
+ typ: z.string(),
17
+ x5c: z.array(z.string()).optional(),
18
+ trust_chain: z.array(z.string()).optional()
19
+ }),
20
+ payload: z.object({
21
+ iss: z.string(),
22
+ sub: z.string(),
23
+ iat: UnixTime,
24
+ exp: UnixTime,
25
+ cnf: z.object({
26
+ jwk: _jwk.JWK
27
+ })
28
+ })
29
+ });
30
+ const WalletInstanceAttestationRequestJwt = z.object({
31
+ header: z.intersection(Jwt.shape.header, z.object({
32
+ typ: z.literal("var+jwt")
33
+ })),
34
+ payload: z.intersection(Jwt.shape.payload, z.object({
35
+ jti: z.string(),
36
+ type: z.literal("WalletInstanceAttestationRequest")
37
+ }))
38
+ });
39
+ exports.WalletInstanceAttestationRequestJwt = WalletInstanceAttestationRequestJwt;
40
+ const WalletInstanceAttestationJwt = z.object({
41
+ header: z.intersection(Jwt.shape.header, z.object({
42
+ typ: z.literal("va+jwt")
43
+ })),
44
+ payload: z.intersection(Jwt.shape.payload, z.object({
45
+ type: z.literal("WalletInstanceAttestation"),
46
+ policy_uri: z.string().url(),
47
+ tos_uri: z.string().url(),
48
+ logo_uri: z.string().url(),
49
+ asc: z.string(),
50
+ authorization_endpoint: z.string().url(),
51
+ response_types_supported: z.array(z.string()),
52
+ vp_formats_supported: z.object({
53
+ jwt_vp_json: z.object({
54
+ alg_values_supported: z.array(z.string())
55
+ }),
56
+ jwt_vc_json: z.object({
57
+ alg_values_supported: z.array(z.string())
58
+ })
59
+ }),
60
+ request_object_signing_alg_values_supported: z.array(z.string()),
61
+ presentation_definition_uri_supported: z.boolean()
62
+ }))
63
+ });
64
+ exports.WalletInstanceAttestationJwt = WalletInstanceAttestationJwt;
65
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_jwk","require","z","_interopRequireWildcard","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","UnixTime","number","min","max","Jwt","object","header","alg","string","kid","typ","x5c","array","optional","trust_chain","payload","iss","sub","iat","exp","cnf","jwk","JWK","WalletInstanceAttestationRequestJwt","intersection","shape","literal","jti","type","exports","WalletInstanceAttestationJwt","policy_uri","url","tos_uri","logo_uri","asc","authorization_endpoint","response_types_supported","vp_formats_supported","jwt_vp_json","alg_values_supported","jwt_vc_json","request_object_signing_al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AC6B,MAAM,CAAC;QACpBmC,oBAAoB,EAAEhE,CAAC,CAACoC,KAAK,CAACpC,CAAC,CAACgC,MAAM,CAAC,CAAC;MAC1C,CAAC,CAAC;MACFiC,WAAW,EAAEjE,CAAC,CAAC6B,MAAM,CAAC;QACpBmC,oBAAoB,EAAEhE,CAAC,CAACoC,KAAK,CAACpC,CAAC,CAACgC,MAAM,CAAC,CAAC;MAC1C,CAAC;IACH,CAAC,CAAC;IACFkC,2CAA2C,EAAElE,CAAC,CAACoC,KAAK,CAACpC,CAAC,CAACgC,MAAM,CAAC,CAAC,CAAC;IAChEmC,qCAAqC,EAAEnE,CAAC,CAACoE,OAAO,CAAC;EACnD,CAAC,CACH;AACF,CAAC,CAAC;AAACf,OAAA,CAAAC,4BAAA,GAAAA,4BAAA"}
@@ -0,0 +1,7 @@
1
+ import * as PID from "./pid";
2
+ import * as WalletInstanceAttestation from "./wallet-instance-attestation";
3
+ export function multiply(a, b) {
4
+ return Promise.resolve(a * b);
5
+ }
6
+ export { PID, WalletInstanceAttestation };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["PID","WalletInstanceAttestation","multiply","a","b","Promise","resolve"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,OAAO,KAAKA,GAAG,MAAM,OAAO;AAC5B,OAAO,KAAKC,yBAAyB,MAAM,+BAA+B;AAE1E,OAAO,SAASC,QAAQA,CAACC,CAAS,EAAEC,CAAS,EAAmB;EAC9D,OAAOC,OAAO,CAACC,OAAO,CAACH,CAAC,GAAGC,CAAC,CAAC;AAC/B;AAEA,SAASJ,GAAG,EAAEC,yBAAyB"}
@@ -0,0 +1,3 @@
1
+ import * as SdJwt from "./sd-jwt";
2
+ export { SdJwt };
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["SdJwt"],"sourceRoot":"../../../src","sources":["pid/index.ts"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,UAAU;AACjC,SAASA,KAAK"}
@@ -0,0 +1,23 @@
1
+ import { getValueFromDisclosures } from "../../sd-jwt/converters";
2
+ import { PID } from "./types";
3
+ export function pidFromToken(sdJwt, disclosures) {
4
+ return PID.parse({
5
+ issuer: sdJwt.payload.iss,
6
+ issuedAt: new Date(sdJwt.payload.iat * 1000),
7
+ expiration: new Date(sdJwt.payload.exp * 1000),
8
+ verification: {
9
+ trustFramework: sdJwt.payload.verified_claims.verification.trust_framework,
10
+ assuranceLevel: sdJwt.payload.verified_claims.verification.assurance_level,
11
+ evidence: getValueFromDisclosures(disclosures, "evidence")
12
+ },
13
+ claims: {
14
+ uniqueId: getValueFromDisclosures(disclosures, "unique_id"),
15
+ givenName: getValueFromDisclosures(disclosures, "given_name"),
16
+ familyName: getValueFromDisclosures(disclosures, "family_name"),
17
+ birthdate: getValueFromDisclosures(disclosures, "birthdate"),
18
+ placeOfBirth: getValueFromDisclosures(disclosures, "place_of_birth"),
19
+ taxIdCode: getValueFromDisclosures(disclosures, "tax_id_number")
20
+ }
21
+ });
22
+ }
23
+ //# sourceMappingURL=converters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getValueFromDisclosures","PID","pidFromToken","sdJwt","disclosures","parse","issuer","payload","iss","issuedAt","Date","iat","expiration","exp","verification","trustFramework","verified_claims","trust_framework","assuranceLevel","assurance_level","evidence","claims","uniqueId","givenName","familyName","birthdate","placeOfBirth","taxIdCode"],"sourceRoot":"../../../../src","sources":["pid/sd-jwt/converters.ts"],"mappings":"AAAA,SAASA,uBAAuB,QAAQ,yBAAyB;AAEjE,SAASC,GAAG,QAAQ,SAAS;AAE7B,OAAO,SAASC,YAAYA,CAACC,KAAe,EAAEC,WAAyB,EAAO;EAC5E,OAAOH,GAAG,CAACI,KAAK,CAAC;IACfC,MAAM,EAAEH,KAAK,CAACI,OAAO,CAACC,GAAG;IACzBC,QAAQ,EAAE,IAAIC,IAAI,CAACP,KAAK,CAACI,OAAO,CAACI,GAAG,GAAG,IAAI,CAAC;IAC5CC,UAAU,EAAE,IAAIF,IAAI,CAACP,KAAK,CAACI,OAAO,CAACM,GAAG,GAAG,IAAI,CAAC;IAC9CC,YAAY,EAAE;MACZC,cAAc,EACZZ,KAAK,CAACI,OAAO,CAACS,eAAe,CAACF,YAAY,CAACG,eAAe;MAC5DC,cAAc,EACZf,KAAK,CAACI,OAAO,CAACS,eAAe,CAACF,YAAY,CAACK,eAAe;MAC5DC,QAAQ,EAAEpB,uBAAuB,CAACI,WAAW,EAAE,UAAU;IAC3D,CAAC;IACDiB,MAAM,EAAE;MACNC,QAAQ,EAAEtB,uBAAuB,CAACI,WAAW,EAAE,WAAW,CAAC;MAC3DmB,SAAS,EAAEvB,uBAAuB,CAACI,WAAW,EAAE,YAAY,CAAC;MAC7DoB,UAAU,EAAExB,uBAAuB,CAACI,WAAW,EAAE,aAAa,CAAC;MAC/DqB,SAAS,EAAEzB,uBAAuB,CAACI,WAAW,EAAE,WAAW,CAAC;MAC5DsB,YAAY,EAAE1B,uBAAuB,CAACI,WAAW,EAAE,gBAAgB,CAAC;MACpEuB,SAAS,EAAE3B,uBAAuB,CAACI,WAAW,EAAE,eAAe;IACjE;EACF,CAAC,CAAC;AACJ"}
@@ -0,0 +1,66 @@
1
+ import { decode as decodeJwt } from "../../sd-jwt";
2
+ import { verify as verifyJwt } from "../../sd-jwt";
3
+ import { pidFromToken } from "./converters";
4
+ import { SdJwt4VC } from "../../sd-jwt/types";
5
+
6
+ /**
7
+ * Decode a given SD-JWT with Disclosures to get the parsed PID object they define.
8
+ * It ensures provided data is in a valid shape.
9
+ *
10
+ * It DOES NOT verify token signature nor check disclosures are correctly referenced by the SD-JWT.
11
+ * Use {@link verify} instead
12
+ *
13
+ * @function
14
+ * @param token The encoded token that represents a valid sd-jwt for verifiable credentials
15
+ *
16
+ * @returns The validated PID object along with the parsed SD-JWT token and the parsed disclosures
17
+ * @throws A decoding error if the token doesn't resolve in a valid SD-JWT
18
+ * @throws A validation error if the provided data doesn't result in a valid PID
19
+ *
20
+ */
21
+ export function decode(token) {
22
+ let {
23
+ sdJwt,
24
+ disclosures
25
+ } = decodeJwt(token, SdJwt4VC);
26
+ const pid = pidFromToken(sdJwt, disclosures);
27
+ return {
28
+ pid,
29
+ sdJwt,
30
+ disclosures
31
+ };
32
+ }
33
+
34
+ /**
35
+ * Verify a given SD-JWT with Disclosures to get the parsed PID object they define.
36
+ * Same as {@link decode} plus:
37
+ * - token signature verification
38
+ * - ensure disclosures are well-defined inside the SD-JWT
39
+ *
40
+ * @async @function
41
+ *
42
+ * @todo implement signature validation
43
+ * @todo check disclosures in sd-jwt
44
+ *
45
+ * @param token The encoded token that represents a valid sd-jwt for verifiable credentials
46
+ *
47
+ * @returns {VerifyResult} The validated PID object along with the parsed SD-JWT token and the parsed disclosures
48
+ * @throws A decoding error if the token doesn't resolve in a valid SD-JWT
49
+ * @throws A validation error if the provided data doesn't result in a valid PID
50
+ * @throws A validation error if the provided disclosures are not defined in the SD-JWT
51
+ * @throws Invalid signature error if the token signature is not valid
52
+ *
53
+ */
54
+ export async function verify(token) {
55
+ const decoded = decode(token);
56
+ const publicKey = decoded.sdJwt.payload.cnf.jwk;
57
+ await verifyJwt(token, publicKey, SdJwt4VC);
58
+ return decoded;
59
+ }
60
+
61
+ /**
62
+ * Result object for {@link verify}
63
+ */
64
+
65
+ export { PID } from "./types";
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["decode","decodeJwt","verify","verifyJwt","pidFromToken","SdJwt4VC","token","sdJwt","disclosures","pid","decoded","publicKey","payload","cnf","jwk","PID"],"sourceRoot":"../../../../src","sources":["pid/sd-jwt/index.ts"],"mappings":"AAAA,SAASA,MAAM,IAAIC,SAAS,QAAQ,cAAc;AAClD,SAASC,MAAM,IAAIC,SAAS,QAAQ,cAAc;AAElD,SAASC,YAAY,QAAQ,cAAc;AAC3C,SAAqBC,QAAQ,QAAQ,oBAAoB;;AAEzD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASL,MAAMA,CAACM,KAAa,EAAgB;EAClD,IAAI;IAAEC,KAAK;IAAEC;EAAY,CAAC,GAAGP,SAAS,CAACK,KAAK,EAAED,QAAQ,CAAC;EACvD,MAAMI,GAAG,GAAGL,YAAY,CAACG,KAAK,EAAEC,WAAW,CAAC;EAE5C,OAAO;IAAEC,GAAG;IAAEF,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;AACA,OAAO,eAAeN,MAAMA,CAACI,KAAa,EAAyB;EACjE,MAAMI,OAAO,GAAGV,MAAM,CAACM,KAAK,CAAC;EAC7B,MAAMK,SAAS,GAAGD,OAAO,CAACH,KAAK,CAACK,OAAO,CAACC,GAAG,CAACC,GAAG;EAC/C,MAAMX,SAAS,CAACG,KAAK,EAAEK,SAAS,EAAEN,QAAQ,CAAC;EAE3C,OAAOK,OAAO;AAChB;;AAWA;AACA;AACA;;AAGA,SAASK,GAAG,QAAQ,SAAS"}
@@ -0,0 +1,43 @@
1
+ import { z } from "zod";
2
+ const VerificationEvidence = z.object({
3
+ type: z.string(),
4
+ record: z.object({
5
+ type: z.string(),
6
+ source: z.object({
7
+ organization_name: z.string(),
8
+ organization_id: z.string(),
9
+ country_code: z.string()
10
+ })
11
+ })
12
+ });
13
+ const Verification = z.object({
14
+ trustFramework: z.literal("eidas"),
15
+ assuranceLevel: z.string(),
16
+ evidence: z.array(VerificationEvidence)
17
+ });
18
+
19
+ /**
20
+ * Data structure for the PID.
21
+ * It contains PID claims in plain text as well as verification data with the issuer's information
22
+ *
23
+ * @see https://italia.github.io/eidas-it-wallet-docs/en/pid-data-model.html
24
+ */
25
+
26
+ export const PID = z.object({
27
+ issuer: z.string(),
28
+ issuedAt: z.date(),
29
+ expiration: z.date(),
30
+ verification: Verification,
31
+ claims: z.object({
32
+ uniqueId: z.string(),
33
+ givenName: z.string(),
34
+ familyName: z.string(),
35
+ birthdate: z.string(),
36
+ placeOfBirth: z.object({
37
+ country: z.string(),
38
+ locality: z.string()
39
+ }),
40
+ taxIdCode: z.string()
41
+ })
42
+ });
43
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["z","VerificationEvidence","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"],"sourceRoot":"../../../../src","sources":["pid/sd-jwt/types.ts"],"mappings":"AAAA,SAASA,CAAC,QAAQ,KAAK;AAEvB,MAAMC,oBAAoB,GAAGD,CAAC,CAACE,MAAM,CAAC;EACpCC,IAAI,EAAEH,CAAC,CAACI,MAAM,CAAC,CAAC;EAChBC,MAAM,EAAEL,CAAC,CAACE,MAAM,CAAC;IACfC,IAAI,EAAEH,CAAC,CAACI,MAAM,CAAC,CAAC;IAChBE,MAAM,EAAEN,CAAC,CAACE,MAAM,CAAC;MACfK,iBAAiB,EAAEP,CAAC,CAACI,MAAM,CAAC,CAAC;MAC7BI,eAAe,EAAER,CAAC,CAACI,MAAM,CAAC,CAAC;MAC3BK,YAAY,EAAET,CAAC,CAACI,MAAM,CAAC;IACzB,CAAC;EACH,CAAC;AACH,CAAC,CAAC;AAEF,MAAMM,YAAY,GAAGV,CAAC,CAACE,MAAM,CAAC;EAC5BS,cAAc,EAAEX,CAAC,CAACY,OAAO,CAAC,OAAO,CAAC;EAClCC,cAAc,EAAEb,CAAC,CAACI,MAAM,CAAC,CAAC;EAC1BU,QAAQ,EAAEd,CAAC,CAACe,KAAK,CAACd,oBAAoB;AACxC,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMe,GAAG,GAAGhB,CAAC,CAACE,MAAM,CAAC;EAC1Be,MAAM,EAAEjB,CAAC,CAACI,MAAM,CAAC,CAAC;EAClBc,QAAQ,EAAElB,CAAC,CAACmB,IAAI,CAAC,CAAC;EAClBC,UAAU,EAAEpB,CAAC,CAACmB,IAAI,CAAC,CAAC;EACpBE,YAAY,EAAEX,YAAY;EAC1BY,MAAM,EAAEtB,CAAC,CAACE,MAAM,CAAC;IACfqB,QAAQ,EAAEvB,CAAC,CAACI,MAAM,CAAC,CAAC;IACpBoB,SAAS,EAAExB,CAAC,CAACI,MAAM,CAAC,CAAC;IACrBqB,UAAU,EAAEzB,CAAC,CAACI,MAAM,CAAC,CAAC;IACtBsB,SAAS,EAAE1B,CAAC,CAACI,MAAM,CAAC,CAAC;IACrBuB,YAAY,EAAE3B,CAAC,CAACE,MAAM,CAAC;MACrB0B,OAAO,EAAE5B,CAAC,CAACI,MAAM,CAAC,CAAC;MACnByB,QAAQ,EAAE7B,CAAC,CAACI,MAAM,CAAC;IACrB,CAAC,CAAC;IACF0B,SAAS,EAAE9B,CAAC,CAACI,MAAM,CAAC;EACtB,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { getValueFromDisclosures } from "../converters";
2
+ const disclosures = [["6w1_soRXFgaHKfpYn3cvfQ", "given_name", "Mario"], ["fuNp97Hf3wV6y48y-QZhIg", "birthdate", "1980-10-01"], ["p-9LzyWHZBVDvhXDWkN2xA", "place_of_birth", {
3
+ country: "IT",
4
+ locality: "Rome"
5
+ }]];
6
+ describe("getValueFromDisclosures", () => {
7
+ it("should return correct value for given_name", () => {
8
+ const success = getValueFromDisclosures(disclosures, "given_name");
9
+ expect(success).toBe("Mario");
10
+ });
11
+ it("should return correct value for place_of_birth", () => {
12
+ const success = getValueFromDisclosures(disclosures, "place_of_birth");
13
+ expect(success).toEqual({
14
+ country: "IT",
15
+ locality: "Rome"
16
+ });
17
+ });
18
+ it("should fail", () => {
19
+ const success = getValueFromDisclosures(disclosures, "given_surname");
20
+ expect(success).toBeUndefined();
21
+ });
22
+ });
23
+ //# sourceMappingURL=converters.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getValueFromDisclosures","disclosures","country","locality","describe","it","success","expect","toBe","toEqual","toBeUndefined"],"sourceRoot":"../../../../src","sources":["sd-jwt/__test__/converters.test.ts"],"mappings":"AAAA,SAASA,uBAAuB,QAAQ,eAAe;AAGvD,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,GAAGN,uBAAuB,CAACC,WAAW,EAAE,YAAY,CAAC;IAClEM,MAAM,CAACD,OAAO,CAAC,CAACE,IAAI,CAAC,OAAO,CAAC;EAC/B,CAAC,CAAC;EACFH,EAAE,CAAC,gDAAgD,EAAE,MAAM;IACzD,MAAMC,OAAO,GAAGN,uBAAuB,CAACC,WAAW,EAAE,gBAAgB,CAAC;IACtEM,MAAM,CAACD,OAAO,CAAC,CAACG,OAAO,CAAC;MAAEP,OAAO,EAAE,IAAI;MAAEC,QAAQ,EAAE;IAAO,CAAC,CAAC;EAC9D,CAAC,CAAC;EACFE,EAAE,CAAC,aAAa,EAAE,MAAM;IACtB,MAAMC,OAAO,GAAGN,uBAAuB,CAACC,WAAW,EAAE,eAAe,CAAC;IACrEM,MAAM,CAACD,OAAO,CAAC,CAACI,aAAa,CAAC,CAAC;EACjC,CAAC,CAAC;AACJ,CAAC,CAAC"}