@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,68 @@
1
+ import { Disclosure, SdJwt4VC } from "../types";
2
+ describe("SdJwt4VC", () => {
3
+ it("should accept a valid token", () => {
4
+ // example provided at https://italia.github.io/eidas-it-wallet-docs/en/pid-data-model.html
5
+ const token = {
6
+ header: {
7
+ typ: "vc+sd-jwt",
8
+ alg: "RS512",
9
+ kid: "dB67gL7ck3TFiIAf7N6_7SHvqk0MDYMEQcoGGlkUAAw",
10
+ trust_chain: ["NEhRdERpYnlHY3M5WldWTWZ2aUhm ...", "eyJhbGciOiJSUzI1NiIsImtpZCI6 ...", "IkJYdmZybG5oQU11SFIwN2FqVW1B ..."]
11
+ },
12
+ payload: {
13
+ iss: "https://pidprovider.example.org",
14
+ sub: "NzbLsXh8uDCcd7noWXFZAfHkxZsRGC9Xs...",
15
+ jti: "urn:uuid:6c5c0a49-b589-431d-bae7-219122a9ec2c",
16
+ iat: 1541493724,
17
+ exp: 1541493724,
18
+ status: "https://pidprovider.example.org/status",
19
+ cnf: {
20
+ jwk: {
21
+ kty: "RSA",
22
+ use: "sig",
23
+ n: "1Ta-sE …",
24
+ e: "AQAB",
25
+ kid: "YhNFS3YnC9tjiCaivhWLVUJ3AxwGGz_98uRFaqMEEs"
26
+ }
27
+ },
28
+ type: "PersonIdentificationData",
29
+ verified_claims: {
30
+ verification: {
31
+ _sd: ["OGm7ryXgt5Xzlevp-Hu-UTk0a-TxAaPAobqv1pIWMfw"],
32
+ trust_framework: "eidas",
33
+ assurance_level: "high"
34
+ },
35
+ claims: {
36
+ _sd: ["8JjozBfovMNvQ3HflmPWy4O19Gpxs61FWHjZebU589E", "BoMGktW1rbikntw8Fzx_BeL4YbAndr6AHsdgpatFCig", "CFLGzentGNRFngnLVVQVcoAFi05r6RJUX-rdbLdEfew", "JU_sTaHCngS32X-0ajHrd1-HCLCkpT5YqgcfQme168w", "VQI-S1mT1Kxfq2o8J9io7xMMX2MIxaG9M9PeJVqrMcA", "zVdghcmClMVWlUgGsGpSkCPkEHZ4u9oWj1SlIBlCc1o"]
37
+ }
38
+ },
39
+ _sd_alg: "sha-256"
40
+ }
41
+ };
42
+ const {
43
+ success
44
+ } = SdJwt4VC.safeParse(token);
45
+ expect(success).toBe(true);
46
+ });
47
+ });
48
+ describe("Disclosure", () => {
49
+ it("should accept a valid disclosure", () => {
50
+ // example provided at https://italia.github.io/eidas-it-wallet-docs/en/pid-data-model.html
51
+ const value = ["2GLC42sKQveCfGfryNRN9w", "evidence", [{
52
+ type: "electronic_record",
53
+ record: {
54
+ type: "eidas.it.cie",
55
+ source: {
56
+ organization_name: "Ministero dell'Interno",
57
+ organization_id: "m_it",
58
+ country_code: "IT"
59
+ }
60
+ }
61
+ }]];
62
+ const {
63
+ success
64
+ } = Disclosure.safeParse(value);
65
+ expect(success).toBe(true);
66
+ });
67
+ });
68
+ //# sourceMappingURL=types.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Disclosure","SdJwt4VC","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","safeParse","expect","toBe","value","record","source","organization_name","organization_id","country_code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CAAC,CAAC;AAEFhC,QAAQ,CAAC,YAAY,EAAE,MAAM;EAC3BC,EAAE,CAAC,kCAAkC,EAAE,MAAM;IAC3C;IACA,MAAMgC,KAAK,GAAG,CACZ,wBAAwB,EACxB,UAAU,EACV,CACE;MACEZ,IAAI,EAAE,mBAAmB;MACzBa,MAAM,EAAE;QACNb,IAAI,EAAE,cAAc;QACpBc,MAAM,EAAE;UACNC,iBAAiB,EAAE,wBAAwB;UAC3CC,eAAe,EAAE,MAAM;UACvBC,YAAY,EAAE;QAChB;MACF;IACF,CAAC,CACF,CACF;IAED,MAAM;MAAET;IAAQ,CAAC,GAAG/B,UAAU,CAACgC,SAAS,CAACG,KAAK,CAAC;IAC/CF,MAAM,CAACF,OAAO,CAAC,CAACG,IAAI,CAAC,IAAI,CAAC;EAC5B,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,24 @@
1
+ export function getValueFromDisclosures(disclosures, claimName) {
2
+ var _disclosures$find;
3
+ const value = (_disclosures$find = disclosures.find(_ref => {
4
+ let [, name] = _ref;
5
+ return name === claimName;
6
+ })) === null || _disclosures$find === void 0 ? void 0 : _disclosures$find[2];
7
+ // value didn't found, we return nothing
8
+ if (!value) {
9
+ return undefined;
10
+ }
11
+ // value is not a string, it's probably fine
12
+ if (typeof value !== "string") {
13
+ return value;
14
+ }
15
+ // value is a string, we try to parse it
16
+ // maybe it's a serialized object
17
+ try {
18
+ return JSON.parse(value);
19
+ } catch (error) {
20
+ // It's definitely a string
21
+ return value;
22
+ }
23
+ }
24
+ //# 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":"AAEA,OAAO,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,71 @@
1
+ import { decode as decodeJwt } from "@pagopa/io-react-native-jwt";
2
+ import { verify as verifyJwt } from "@pagopa/io-react-native-jwt";
3
+ import { decodeBase64 } from "@pagopa/io-react-native-jwt";
4
+ import { Disclosure } from "./types";
5
+ import { verifyDisclosure } from "./verifier";
6
+ /**
7
+ * Decode a given SD-JWT with Disclosures to get the parsed SD-JWT 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
+ * @param schema Schema to use to parse the SD-JWT
16
+ *
17
+ * @returns The parsed SD-JWT token and the parsed disclosures
18
+ *
19
+ */
20
+ export const decode = (token, schema) => {
21
+ // token are expected in the form "sd-jwt~disclosure0~disclosure1~...~disclosureN"
22
+ const [rawSdJwt = "", ...rawDisclosures] = token.split("~");
23
+
24
+ // get the sd-jwt as object
25
+ // validate it's a valid SD-JWT for Verifiable Credentials
26
+ const decodedJwt = decodeJwt(rawSdJwt);
27
+ const sdJwt = schema.parse({
28
+ header: decodedJwt.protectedHeader,
29
+ payload: decodedJwt.payload
30
+ });
31
+
32
+ // get disclosures as list of triples
33
+ // validate each triple
34
+ // throw a validation error if at least one fails to parse
35
+ const disclosures = rawDisclosures.map(decodeBase64).map(e => JSON.parse(e)).map(e => Disclosure.parse(e));
36
+ return {
37
+ sdJwt,
38
+ disclosures
39
+ };
40
+ };
41
+
42
+ /**
43
+ * Verify a given SD-JWT with Disclosures
44
+ * Same as {@link decode} plus:
45
+ * - token signature verification
46
+ * - ensure disclosures are well-defined inside the SD-JWT
47
+ *
48
+ * @async @function
49
+ *
50
+ *
51
+ * @param token The encoded token that represents a valid sd-jwt for verifiable credentials
52
+ * @param publicKey The public key to validate the signature
53
+ * @param schema Schema to use to parse the SD-JWT
54
+ *
55
+ * @returns The parsed SD-JWT token and the parsed disclosures
56
+ *
57
+ */
58
+ export const verify = async (token, publicKey, schema) => {
59
+ // get decoded data
60
+ const [rawSdJwt = ""] = token.split("~");
61
+ const decoded = decode(token, schema);
62
+
63
+ //Check signature
64
+ await verifyJwt(rawSdJwt, publicKey);
65
+
66
+ //Check disclosures in sd-jwt
67
+ const claims = [...decoded.sdJwt.payload.verified_claims.verification._sd, ...decoded.sdJwt.payload.verified_claims.claims._sd];
68
+ await Promise.all(decoded.disclosures.map(async disclosure => await verifyDisclosure(disclosure, claims)));
69
+ return decoded;
70
+ };
71
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["decode","decodeJwt","verify","verifyJwt","decodeBase64","Disclosure","verifyDisclosure","token","schema","rawSdJwt","rawDisclosures","split","decodedJwt","sdJwt","parse","header","protectedHeader","payload","disclosures","map","e","JSON","publicKey","decoded","claims","verified_claims","verification","_sd","Promise","all","disclosure"],"sourceRoot":"../../../src","sources":["sd-jwt/index.ts"],"mappings":"AAEA,SAASA,MAAM,IAAIC,SAAS,QAAQ,6BAA6B;AACjE,SAASC,MAAM,IAAIC,SAAS,QAAQ,6BAA6B;AAEjE,SAASC,YAAY,QAAQ,6BAA6B;AAC1D,SAASC,UAAU,QAAQ,SAAS;A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CAACC,YAAY,CAACC,GAAG,EACzD,GAAGJ,OAAO,CAACV,KAAK,CAACI,OAAO,CAACQ,eAAe,CAACD,MAAM,CAACG,GAAG,CACpD;EAED,MAAMC,OAAO,CAACC,GAAG,CACfN,OAAO,CAACL,WAAW,CAACC,GAAG,CACrB,MAAOW,UAAU,IAAK,MAAMxB,gBAAgB,CAACwB,UAAU,EAAEN,MAAM,CACjE,CACF,CAAC;EAED,OAAOD,OAAO;AAChB,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { JWK } from "../utils/jwk";
2
+ import { z } from "zod";
3
+ export const UnixTime = z.number().min(0).max(2147483647000);
4
+ export const ObfuscatedDisclosures = z.object({
5
+ _sd: z.array(z.string())
6
+ });
7
+
8
+ /**
9
+ * A triple of values in the form of {salt, claim name, claim value} that represent a parsed disclosure.
10
+ *
11
+ * @see https://datatracker.ietf.org/doc/html/draft-ietf-oauth-selective-disclosure-jwt-04
12
+ * @see https://vcstuff.github.io/draft-terbu-sd-jwt-vc/draft-terbu-oauth-sd-jwt-vc.html
13
+ */
14
+
15
+ export const Disclosure = z.tuple([/* salt */z.string(), /* claim name */z.string(), /* claim value */z.unknown()]);
16
+ export const SdJwt4VC = z.object({
17
+ header: z.object({
18
+ typ: z.literal("vc+sd-jwt"),
19
+ alg: z.string(),
20
+ kid: z.string(),
21
+ trust_chain: z.array(z.string())
22
+ }),
23
+ payload: z.object({
24
+ iss: z.string(),
25
+ sub: z.string(),
26
+ jti: z.string(),
27
+ iat: UnixTime,
28
+ exp: UnixTime,
29
+ status: z.string(),
30
+ cnf: z.object({
31
+ jwk: JWK
32
+ }),
33
+ type: z.literal("PersonIdentificationData"),
34
+ verified_claims: z.object({
35
+ verification: z.intersection(z.object({
36
+ trust_framework: z.literal("eidas"),
37
+ assurance_level: z.string()
38
+ }), ObfuscatedDisclosures),
39
+ claims: ObfuscatedDisclosures
40
+ }),
41
+ _sd_alg: z.literal("sha-256")
42
+ })
43
+ });
44
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["JWK","z","UnixTime","number","min","max","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","type","verified_claims","verification","intersection","trust_framework","assurance_level","claims","_sd_alg"],"sourceRoot":"../../../src","sources":["sd-jwt/types.ts"],"mappings":"AAAA,SAASA,GAAG,QAAQ,cAAc;AAClC,SAASC,CAAC,QAAQ,KAAK;AAEvB,OAAO,MAAMC,QAAQ,GAAGD,CAAC,CAACE,MAAM,CAAC,CAAC,CAACC,GAAG,CAAC,CAAC,CAAC,CAACC,GAAG,CAAC,aAAa,CAAC;AAI5D,OAAO,MAAMC,qBAAqB,GAAGL,CAAC,CAACM,MAAM,CAAC;EAAEC,GAAG,EAAEP,CAAC,CAACQ,KAAK,CAACR,CAAC,CAACS,MAAM,CAAC,CAAC;AAAE,CAAC,CAAC;;AAE3E;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMC,UAAU,GAAGV,CAAC,CAACW,KAAK,CAAC,CAChC,UAAWX,CAAC,CAACS,MAAM,CAAC,CAAC,EACrB,gBAAiBT,CAAC,CAACS,MAAM,CAAC,CAAC,EAC3B,iBAAkBT,CAAC,CAACY,OAAO,CAAC,CAAC,CAC9B,CAAC;AAGF,OAAO,MAAMC,QAAQ,GAAGb,CAAC,CAACM,MAAM,CAAC;EAC/BQ,MAAM,EAAEd,CAAC,CAACM,MAAM,CAAC;IACfS,GAAG,EAAEf,CAAC,CAACgB,OAAO,CAAC,WAAW,CAAC;IAC3BC,GAAG,EAAEjB,CAAC,CAACS,MAAM,CAAC,CAAC;IACfS,GAAG,EAAElB,CAAC,CAACS,MAAM,CAAC,CAAC;IACfU,WAAW,EAAEnB,CAAC,CAACQ,KAAK,CAACR,CAAC,CAACS,MAAM,CAAC,CAAC;EACjC,CAAC,CAAC;EACFW,OAAO,EAAEpB,CAAC,CAACM,MAAM,CAAC;IAChBe,GAAG,EAAErB,CAAC,CAACS,MAAM,CAAC,CAAC;IACfa,GAAG,EAAEtB,CAAC,CAACS,MAAM,CAAC,CAAC;IACfc,GAAG,EAAEvB,CAAC,CAACS,MAAM,CAAC,CAAC;IACfe,GAAG,EAAEvB,QAAQ;IACbwB,GAAG,EAAExB,QAAQ;IACbyB,MAAM,EAAE1B,CAAC,CAACS,MAAM,CAAC,CAAC;IAClBkB,GAAG,EAAE3B,CAAC,CAACM,MAAM,CAAC;MACZsB,GAAG,EAAE7B;IACP,CAAC,CAAC;IACF8B,IAAI,EAAE7B,CAAC,CAACgB,OAAO,CAAC,0BAA0B,CAAC;IAC3Cc,eAAe,EAAE9B,CAAC,CAACM,MAAM,CAAC;MACxByB,YAAY,EAAE/B,CAAC,CAACgC,YAAY,CAC1BhC,CAAC,CAACM,MAAM,CAAC;QACP2B,eAAe,EAAEjC,CAAC,CAACgB,OAAO,CAAC,OAAO,CAAC;QACnCkB,eAAe,EAAElC,CAAC,CAACS,MAAM,CAAC;MAC5B,CAAC,CAAC,EACFJ,qBACF,CAAC;MACD8B,MAAM,EAAE9B;IACV,CAAC,CAAC;IACF+B,OAAO,EAAEpC,CAAC,CAACgB,OAAO,CAAC,SAAS;EAC9B,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { encodeBase64, sha256ToBase64 } from "@pagopa/io-react-native-jwt";
2
+ import { ValidationFailed } from "../utils/errors";
3
+ export const verifyDisclosure = async (disclosure, claims) => {
4
+ let disclosureString = JSON.stringify(disclosure);
5
+ let encodedDisclosure = encodeBase64(disclosureString);
6
+ let hash = await sha256ToBase64(encodedDisclosure);
7
+ if (!claims.includes(hash)) {
8
+ throw new ValidationFailed("Validation of disclosure failed", `${disclosure}`, "Disclosure hash not found in claims");
9
+ }
10
+ };
11
+ //# sourceMappingURL=verifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["encodeBase64","sha256ToBase64","ValidationFailed","verifyDisclosure","disclosure","claims","disclosureString","JSON","stringify","encodedDisclosure","hash","includes"],"sourceRoot":"../../../src","sources":["sd-jwt/verifier.ts"],"mappings":"AAAA,SAASA,YAAY,EAAEC,cAAc,QAAQ,6BAA6B;AAE1E,SAASC,gBAAgB,QAAQ,iBAAiB;AAGlD,OAAO,MAAMC,gBAAgB,GAAG,MAAAA,CAC9BC,UAAsB,EACtBC,MAAoC,KACjC;EACH,IAAIC,gBAAgB,GAAGC,IAAI,CAACC,SAAS,CAACJ,UAAU,CAAC;EACjD,IAAIK,iBAAiB,GAAGT,YAAY,CAACM,gBAAgB,CAAC;EACtD,IAAII,IAAI,GAAG,MAAMT,cAAc,CAACQ,iBAAiB,CAAC;EAClD,IAAI,CAACJ,MAAM,CAACM,QAAQ,CAACD,IAAI,CAAC,EAAE;IAC1B,MAAM,IAAIR,gBAAgB,CACxB,iCAAiC,EAChC,GAAEE,UAAW,EAAC,EACf,qCACF,CAAC;EACH;AACF,CAAC"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * A generic Error that all other io-wallet specific Error subclasses extend.
3
+ *
4
+ * @example Checking thrown error is a io-wallet one
5
+ *
6
+ * ```js
7
+ * if (err instanceof errors.IoWalletError) {
8
+ * // ...
9
+ * }
10
+ * ```
11
+ */
12
+ export class IoWalletError extends Error {
13
+ /** A unique error code for the particular error subclass. */
14
+ static get code() {
15
+ return "ERR_IO_WALLET_GENERIC";
16
+ }
17
+
18
+ /** A unique error code for the particular error subclass. */
19
+ code = "ERR_IO_WALLET_GENERIC";
20
+ constructor(message) {
21
+ var _Error$captureStackTr;
22
+ super(message);
23
+ this.name = this.constructor.name;
24
+ // @ts-ignore
25
+ (_Error$captureStackTr = Error.captureStackTrace) === null || _Error$captureStackTr === void 0 ? void 0 : _Error$captureStackTr.call(Error, this, this.constructor);
26
+ }
27
+ }
28
+ /**
29
+ * An error subclass thrown when validation fail
30
+ *
31
+ */
32
+ export class ValidationFailed extends IoWalletError {
33
+ static get code() {
34
+ return "ERR_IO_WALLET_VALIDATION_FAILED";
35
+ }
36
+ code = "ERR_IO_WALLET_VALIDATION_FAILED";
37
+
38
+ /** The Claim for which the validation failed. */
39
+
40
+ /** Reason code for the validation failure. */
41
+
42
+ constructor(message) {
43
+ let claim = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "unspecified";
44
+ let reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "unspecified";
45
+ super(message);
46
+ this.claim = claim;
47
+ this.reason = reason;
48
+ }
49
+ }
50
+
51
+ /**
52
+ * An error subclass thrown when validation fail
53
+ *
54
+ */
55
+ export class WalletInstanceAttestationIssuingError extends IoWalletError {
56
+ static get code() {
57
+ return "ERR_IO_WALLET_INSTANCE_ATTESTATION_ISSUING_FAILED";
58
+ }
59
+ code = "ERR_IO_WALLET_INSTANCE_ATTESTATION_ISSUING_FAILED";
60
+
61
+ /** The Claim for which the validation failed. */
62
+
63
+ /** Reason code for the validation failure. */
64
+
65
+ constructor(message) {
66
+ let claim = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "unspecified";
67
+ let reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "unspecified";
68
+ super(message);
69
+ this.claim = claim;
70
+ this.reason = reason;
71
+ }
72
+ }
73
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["IoWalletError","Error","code","constructor","message","_Error$captureStackTr","name","captureStackTrace","call","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;AACA,OAAO,MAAMA,aAAa,SAASC,KAAK,CAAC;EACvC;EACA,WAAWC,IAAIA,CAAA,EAAW;IACxB,OAAO,uBAAuB;EAChC;;EAEA;EACAA,IAAI,GAAW,uBAAuB;EAEtCC,WAAWA,CAACC,OAAgB,EAAE;IAAA,IAAAC,qBAAA;IAC5B,KAAK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AAI,CAACI,MAAM,GAAGA,MAAM;EACtB;AACF"}
@@ -0,0 +1,38 @@
1
+ import { z } from "zod";
2
+ export const JWK = z.object({
3
+ /** JWK "alg" (Algorithm) Parameter. */
4
+ alg: z.string().optional(),
5
+ crv: z.string().optional(),
6
+ d: z.string().optional(),
7
+ dp: z.string().optional(),
8
+ dq: z.string().optional(),
9
+ e: z.string().optional(),
10
+ /** JWK "ext" (Extractable) Parameter. */
11
+ ext: z.boolean().optional(),
12
+ k: z.string().optional(),
13
+ /** JWK "key_ops" (Key Operations) Parameter. */
14
+ key_ops: z.array(z.string()).optional(),
15
+ /** JWK "kid" (Key ID) Parameter. */
16
+ kid: z.string().optional(),
17
+ /** JWK "kty" (Key Type) Parameter.
18
+ * This attribute is required to discriminate the
19
+ * type of EC/RSA algorithm */
20
+ kty: z.union([z.literal("RSA"), z.literal("EC")]),
21
+ n: z.string().optional(),
22
+ p: z.string().optional(),
23
+ q: z.string().optional(),
24
+ qi: z.string().optional(),
25
+ /** JWK "use" (Public Key Use) Parameter. */
26
+ use: z.string().optional(),
27
+ x: z.string().optional(),
28
+ y: z.string().optional(),
29
+ /** JWK "x5c" (X.509 Certificate Chain) Parameter. */
30
+ x5c: z.array(z.string()).optional(),
31
+ /** JWK "x5t" (X.509 Certificate SHA-1 Thumbprint) Parameter. */
32
+ x5t: z.string().optional(),
33
+ /** "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Parameter. */
34
+ "x5t#S256": z.string().optional(),
35
+ /** JWK "x5u" (X.509 URL) Parameter. */
36
+ x5u: z.string().optional()
37
+ });
38
+ //# sourceMappingURL=jwk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["z","JWK","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"],"sourceRoot":"../../../src","sources":["utils/jwk.ts"],"mappings":"AAAA,SAASA,CAAC,QAAQ,KAAK;AAGvB,OAAO,MAAM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AQ,CAAC,CAAC;EACxBkB,EAAE,EAAEvB,CAAC,CAACI,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EACzB;EACAmB,GAAG,EAAExB,CAAC,CAACI,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EAC1BoB,CAAC,EAAEzB,CAAC,CAACI,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EACxBqB,CAAC,EAAE1B,CAAC,CAACI,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EACxB;EACAsB,GAAG,EAAE3B,CAAC,CAACe,KAAK,CAACf,CAAC,CAACI,MAAM,CAAC,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EACnC;EACAuB,GAAG,EAAE5B,CAAC,CAACI,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EAC1B;EACA,UAAU,EAAEL,CAAC,CAACI,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;EACjC;EACAwB,GAAG,EAAE7B,CAAC,CAACI,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC;AAC3B,CAAC,CAAC"}
@@ -0,0 +1,52 @@
1
+ import { WalletInstanceAttestationJwt } from "./types";
2
+ import { decode as decodeJwt } from "@pagopa/io-react-native-jwt";
3
+ import { verify as verifyJwt } from "@pagopa/io-react-native-jwt";
4
+ import { Issuing } from "./issuing";
5
+ export { Issuing };
6
+ /**
7
+ * Decode a given JWT to get the parsed Wallet Instance Attestation 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 JWT.
11
+ * Use {@link verify} instead
12
+ *
13
+ * @function
14
+ * @param token The encoded token that represents a valid jwt for Wallet Instance Attestation
15
+ *
16
+ * @returns The validated Wallet Instance Attestation object
17
+ * @throws A decoding error if the token doesn't resolve in a valid JWT
18
+ * @throws A validation error if the provided data doesn't result in a valid Wallet Instance Attestation
19
+ *
20
+ */
21
+ export function decode(token) {
22
+ // decode JWT parts
23
+ const decodedJwt = decodeJwt(token);
24
+ // parse JWT to ensure it has the shape of a WalletInstanceAttestationJwt
25
+ return WalletInstanceAttestationJwt.parse({
26
+ header: decodedJwt.protectedHeader,
27
+ payload: decodedJwt.payload
28
+ });
29
+ }
30
+
31
+ /**
32
+ * Verify a given JWT to get the parsed Wallet Instance Attestation object they define.
33
+ * Same as {@link decode} plus token signature verification
34
+ *
35
+ * @async @function
36
+ *
37
+ *
38
+ * @param token The encoded token that represents a valid jwt
39
+ *
40
+ * @returns {WalletInstanceAttestationJwt} The validated Wallet Instance Attestation object
41
+ * @throws A decoding error if the token doesn't resolve in a valid JWT
42
+ * @throws A validation error if the provided data doesn't result in a valid Wallet Instance Attestation
43
+ * @throws Invalid signature error if the token signature is not valid
44
+ *
45
+ */
46
+ export async function verify(token) {
47
+ const decoded = decode(token);
48
+ const pubKey = decoded.payload.cnf.jwk;
49
+ await verifyJwt(token, pubKey);
50
+ return decoded;
51
+ }
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["WalletInstanceAttestationJwt","decode","decodeJwt","verify","verifyJwt","Issuing","token","decodedJwt","parse","header","protectedHeader","payload","decoded","pubKey","cnf","jwk"],"sourceRoot":"../../../src","sources":["wallet-instance-attestation/index.ts"],"mappings":"AAAA,SAASA,4BAA4B,QAAQ,SAAS;AACtD,SAASC,MAAM,IAAIC,SAAS,QAAQ,6BAA6B;AACjE,SAASC,MAAM,IAAIC,SAAS,QAAQ,6BAA6B;AAEjE,SAASC,OAAO,QAAQ,WAAW;AACnC,SAASA,OAAO;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASJ,MAAMA,CAACK,KAAa,EAAgC;EAClE;EACA,MAAMC,UAAU,GAAGL,SAAS,CAACI,KAAK,CAAC;EACnC;EACA,OAAON,4BAA4B,CAACQ,KAAK,CAAC;IACxCC,MAAM,EAAEF,UAAU,CAACG,eAAe;IAClCC,OAAO,EAAEJ,UAAU,CAACI;EACtB,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeR,MAAMA,CAC1BG,KAAa,EAC0B;EACvC,MAAMM,OAAO,GAAGX,MAAM,CAACK,KAAK,CAAC;EAC7B,MAAMO,MAAM,GAAGD,OAAO,CAACD,OAAO,CAACG,GAAG,CAACC,GAAG;EAEtC,MAAMX,SAAS,CAACE,KAAK,EAAEO,MAAM,CAAC;EAE9B,OAAOD,OAAO;AAChB"}
@@ -0,0 +1,90 @@
1
+ import { decode as decodeJwt } from "@pagopa/io-react-native-jwt";
2
+ import { verify as verifyJwt } from "@pagopa/io-react-native-jwt";
3
+ import { SignJWT, thumbprint } from "@pagopa/io-react-native-jwt";
4
+ import { JWK } from "../utils/jwk";
5
+ import { WalletInstanceAttestationRequestJwt } from "./types";
6
+ import uuid from "react-native-uuid";
7
+ import { WalletInstanceAttestationIssuingError } from "../utils/errors";
8
+ export class Issuing {
9
+ constructor(walletProviderBaseUrl) {
10
+ this.walletProviderBaseUrl = walletProviderBaseUrl;
11
+ }
12
+
13
+ /**
14
+ * Get the Wallet Instance Attestation Request to sign
15
+ *
16
+ * @async @function
17
+ *
18
+ * @param jwk Public key of the wallet instance
19
+ *
20
+ * @returns {string} Wallet Instance Attestation Request to sign
21
+ *
22
+ */
23
+ async getAttestationRequestToSign(jwk) {
24
+ const parsedJwk = JWK.parse(jwk);
25
+ const keyThumbprint = await thumbprint(parsedJwk);
26
+ const publicKey = {
27
+ ...parsedJwk,
28
+ kid: keyThumbprint
29
+ };
30
+ const walletInstanceAttestationRequest = new SignJWT({
31
+ iss: keyThumbprint,
32
+ sub: this.walletProviderBaseUrl,
33
+ jti: `${uuid.v4()}`,
34
+ type: "WalletInstanceAttestationRequest",
35
+ cnf: {
36
+ jwk: publicKey
37
+ }
38
+ }).setProtectedHeader({
39
+ alg: "ES256",
40
+ kid: publicKey.kid,
41
+ typ: "var+jwt"
42
+ }).setIssuedAt().setExpirationTime("1h").toSign();
43
+ return walletInstanceAttestationRequest;
44
+ }
45
+
46
+ /**
47
+ * Get the Wallet Instance Attestation given a
48
+ * Wallet Instance Attestation Request and signature
49
+ *
50
+ * @async @function
51
+ *
52
+ * @param attestationRequest Wallet Instance Attestaion Request
53
+ * obtained with {@link getAttestationRequestToSign}
54
+ * @param signature Signature of the Wallet Instance Attestaion Request
55
+ * @param appFetch Optional object with fetch function to use
56
+ *
57
+ * @returns {string} Wallet Instance Attestation
58
+ *
59
+ */
60
+ async getAttestation(attestationRequest, signature) {
61
+ let appFetch = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
62
+ fetch
63
+ };
64
+ const signedAttestationRequest = await SignJWT.appendSignature(attestationRequest, signature);
65
+ const decodedRequest = decodeJwt(signedAttestationRequest);
66
+ const parsedRequest = WalletInstanceAttestationRequestJwt.parse({
67
+ payload: decodedRequest.payload,
68
+ header: decodedRequest.protectedHeader
69
+ });
70
+ const publicKey = parsedRequest.payload.cnf.jwk;
71
+ await verifyJwt(signedAttestationRequest, publicKey);
72
+ const tokenUrl = new URL("token", this.walletProviderBaseUrl).href;
73
+ const requestBody = {
74
+ grant_type: "urn:ietf:params:oauth:client-assertion-type:jwt-key-attestation",
75
+ assertion: signedAttestationRequest
76
+ };
77
+ const response = await appFetch.fetch(tokenUrl, {
78
+ method: "POST",
79
+ headers: {
80
+ "Content-Type": "application/json"
81
+ },
82
+ body: JSON.stringify(requestBody)
83
+ });
84
+ if (response.status === 201) {
85
+ return await response.text();
86
+ }
87
+ throw new WalletInstanceAttestationIssuingError("Unable to obtain wallet instance attestation from wallet provider", `Response code: ${response.status}`);
88
+ }
89
+ }
90
+ //# sourceMappingURL=issuing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["decode","decodeJwt","verify","verifyJwt","SignJWT","thumbprint","JWK","WalletInstanceAttestationRequestJwt","uuid","WalletInstanceAttestationIssuingError","Issuing","constructor","walletProviderBaseUrl","getAttestationRequestToSign","jwk","parsedJwk","parse","keyThumbprint","publicKey","kid","walletInstanceAttestationRequest","iss","sub","jti","v4","type","cnf","setProtectedHeader","alg","typ","setIssuedAt","setExpirationTime","toSign","getAttestation","attestationRequest","signature","appFetch","arguments","length","undefined","fetch","signedAttestationRequest","appendSignature","decodedRequest","parsedRequest","payload","header","protectedHeader","tokenUrl","URL","href","requestBody","grant_type","assertion","response","method","headers","body","JSON","stringify","status","text"],"sourceRoot":"../../../src","sources":["wallet-instance-attestation/issuing.ts"],"mappings":"AAAA,SAASA,MAAM,IAAIC,SAAS,QAAQ,6BAA6B;AACjE,SAASC,MAAM,IAAIC,SAAS,QAAQ,6BAA6B;AACjE,SAASC,OAAO,EAAEC,UAAU,QAAQ,6BAA6B;AACjE,SAASC,GAAG,QAAQ,cAAc;AAClC,SAASC,mCAAmC,QAAQ,SAAS;AAC7D,OAAOC,IAAI,MAAM,mBAAmB;AACpC,SAASC,qCAAqC,QAAQ,iBAAiB;AAEvE,OAAO,MAAMC,OAAO,CAAC;EAGnBC,WAAWA,CAACC,qBAA6B,EAAE;IACzC,IAAI,CAACA,qBAAqB,GAAGA,qBAAqB;EACpD;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE,MAAMC,2BAA2BA,CAACC,GAAQ,EAAmB;IAC3D,MAAMC,SAAS,GAAGT,GAAG,CAACU,KAAK,CAACF,GAAG,CAAC;IAChC,MAAMG,aAAa,GAAG,MAAMZ,UAAU,CAACU,SAAS,CAAC;IACjD,MAAMG,SAAS,GAAG;MAAE,GAAGH,SAAS;MAAEI,GAAG,EAAEF;IAAc,CAAC;IAEtD,MAAMG,gCAAgC,GAAG,IAAIhB,OAAO,CAAC;MACnDiB,GAAG,EAAEJ,aAAa;MAClBK,GAAG,EAAE,IAAI,CAACV,qBAAqB;MAC/BW,GAAG,EAAG,GAAEf,IAAI,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AQ,CAACI,KAAK,CAACQ,QAAQ,EAAE;MAC9CO,MAAM,EAAE,MAAM;MACdC,OAAO,EAAE;QACP,cAAc,EAAE;MAClB,CAAC;MACDC,IAAI,EAAEC,IAAI,CAACC,SAAS,CAACR,WAAW;IAClC,CAAC,CAAC;IAEF,IAAIG,QAAQ,CAACM,MAAM,KAAK,GAAG,EAAE;MAC3B,OAAO,MAAMN,QAAQ,CAACO,IAAI,CAAC,CAAC;IAC9B;IAEA,MAAM,IAAIpD,qCAAqC,CAC7C,mEAAmE,EAClE,kBAAiB6C,QAAQ,CAACM,MAAO,EACpC,CAAC;EACH;AACF"}
@@ -0,0 +1,55 @@
1
+ import { JWK } from "../utils/jwk";
2
+ import * as z from "zod";
3
+ const UnixTime = z.number().min(0).max(2147483647000);
4
+ const Jwt = z.object({
5
+ header: z.object({
6
+ alg: z.string(),
7
+ kid: z.string(),
8
+ typ: z.string(),
9
+ x5c: z.array(z.string()).optional(),
10
+ trust_chain: z.array(z.string()).optional()
11
+ }),
12
+ payload: z.object({
13
+ iss: z.string(),
14
+ sub: z.string(),
15
+ iat: UnixTime,
16
+ exp: UnixTime,
17
+ cnf: z.object({
18
+ jwk: JWK
19
+ })
20
+ })
21
+ });
22
+ export const WalletInstanceAttestationRequestJwt = z.object({
23
+ header: z.intersection(Jwt.shape.header, z.object({
24
+ typ: z.literal("var+jwt")
25
+ })),
26
+ payload: z.intersection(Jwt.shape.payload, z.object({
27
+ jti: z.string(),
28
+ type: z.literal("WalletInstanceAttestationRequest")
29
+ }))
30
+ });
31
+ export const WalletInstanceAttestationJwt = z.object({
32
+ header: z.intersection(Jwt.shape.header, z.object({
33
+ typ: z.literal("va+jwt")
34
+ })),
35
+ payload: z.intersection(Jwt.shape.payload, z.object({
36
+ type: z.literal("WalletInstanceAttestation"),
37
+ policy_uri: z.string().url(),
38
+ tos_uri: z.string().url(),
39
+ logo_uri: z.string().url(),
40
+ asc: z.string(),
41
+ authorization_endpoint: z.string().url(),
42
+ response_types_supported: z.array(z.string()),
43
+ vp_formats_supported: z.object({
44
+ jwt_vp_json: z.object({
45
+ alg_values_supported: z.array(z.string())
46
+ }),
47
+ jwt_vc_json: z.object({
48
+ alg_values_supported: z.array(z.string())
49
+ })
50
+ }),
51
+ request_object_signing_alg_values_supported: z.array(z.string()),
52
+ presentation_definition_uri_supported: z.boolean()
53
+ }))
54
+ });
55
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["JWK","z","UnixTime","number","min","max","Jwt","object","header","alg","string","kid","typ","x5c","array","optional","trust_chain","payload","iss","sub","iat","exp","cnf","jwk","WalletInstanceAttestationRequestJwt","intersection","shape","literal","jti","type","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_alg_values_supported","presentation_definition_uri_supported","boolean"],"sourceRoot":"../../../src","sources":["wallet-instance-attestation/types.ts"],"mappings":"AAAA,SAASA,GAAG,QAAQ,cAAc;AAClC,OAAO,KAAKC,CAAC,MAAM,KAAK;AAExB,MAAMC,QAAQ,GAAGD,CAAC,CAACE,MAAM,CAAC,CAAC,CAACC,GAAG,CAAC,CAAC,CAAC,CAACC,GAAG,CAAC,aAAa,CAAC;AAGrD,MAAMC,GAAG,GAAGL,CAAC,CAACM,MAAM,CAAC;EACnBC,MAAM,EAAEP,CAAC,CAACM,MAAM,CAAC;IACfE,GAAG,EAAER,CAAC,CAACS,MAAM,CAAC,CAAC;IACfC,GAAG,EAAEV,CAAC,CAACS,MAAM,CAAC,CAAC;IACfE,GAAG,EAAEX,CAAC,CAACS,MAAM,CAAC,CAAC;IACfG,GAAG,EAAEZ,CAAC,CAACa,KAAK,CAACb,CAAC,CAACS,MAAM,CAAC,CAAC,CAAC,CAACK,QAAQ,CAAC,CAAC;IACnCC,WAAW,EAAEf,CAAC,CAACa,KAAK,CAACb,CAAC,CAACS,MAAM,CAAC,CAAC,C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,CAAC,CAAC0B,OAAO,CAAC,2BAA2B,CAAC;IAC5CI,UAAU,EAAE9B,CAAC,CAACS,MAAM,CAAC,CAAC,CAACsB,GAAG,CAAC,CAAC;IAC5BC,OAAO,EAAEhC,CAAC,CAACS,MAAM,CAAC,CAAC,CAACsB,GAAG,CAAC,CAAC;IACzBE,QAAQ,EAAEjC,CAAC,CAACS,MAAM,CAAC,CAAC,CAACsB,GAAG,CAAC,CAAC;IAC1BG,GAAG,EAAElC,CAAC,CAACS,MAAM,CAAC,CAAC;IACf0B,sBAAsB,EAAEnC,CAAC,CAACS,MAAM,CAAC,CAAC,CAACsB,GAAG,CAAC,CAAC;IACxCK,wBAAwB,EAAEpC,CAAC,CAACa,KAAK,CAACb,CAAC,CAACS,MAAM,CAAC,CAAC,CAAC;IAC7C4B,oBAAoB,EAAErC,CAAC,CAACM,MAAM,CAAC;MAC7BgC,WAAW,EAAEtC,CAAC,CAACM,MAAM,CAAC;QACpBiC,oBAAoB,EAAEvC,CAAC,CAACa,KAAK,CAACb,CAAC,CAACS,MAAM,CAAC,CAAC;MAC1C,CAAC,CAAC;MACF+B,WAAW,EAAExC,CAAC,CAACM,MAAM,CAAC;QACpBiC,oBAAoB,EAAEvC,CAAC,CAACa,KAAK,CAACb,CAAC,CAACS,MAAM,CAAC,CAAC;MAC1C,CAAC;IACH,CAAC,CAAC;IACFgC,2CAA2C,EAAEzC,CAAC,CAACa,KAAK,CAACb,CAAC,CAACS,MAAM,CAAC,CAAC,CAAC;IAChEiC,qCAAqC,EAAE1C,CAAC,CAAC2C,OAAO,CAAC;EACnD,CAAC,CACH;AACF,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import * as PID from "./pid";
2
+ import * as WalletInstanceAttestation from "./wallet-instance-attestation";
3
+ export declare function multiply(a: number, b: number): Promise<number>;
4
+ export { PID, WalletInstanceAttestation };
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,yBAAyB,MAAM,+BAA+B,CAAC;AAE3E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAE9D;AAED,OAAO,EAAE,GAAG,EAAE,yBAAyB,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import * as SdJwt from "./sd-jwt";
2
+ export { SdJwt };
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pid/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { Disclosure, SdJwt4VC } from "../../sd-jwt/types";
2
+ import { PID } from "./types";
3
+ export declare function pidFromToken(sdJwt: SdJwt4VC, disclosures: Disclosure[]): PID;
4
+ //# sourceMappingURL=converters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../../../src/pid/sd-jwt/converters.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAE9B,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,GAAG,CAqB5E"}