@pagopa/io-react-native-wallet 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. package/lib/commonjs/index.js +9 -1
  2. package/lib/commonjs/index.js.map +1 -1
  3. package/lib/commonjs/pid/issuing.js +28 -0
  4. package/lib/commonjs/pid/issuing.js.map +1 -1
  5. package/lib/commonjs/pid/metadata.js +51 -0
  6. package/lib/commonjs/pid/metadata.js.map +1 -0
  7. package/lib/commonjs/pid/sd-jwt/index.js +2 -1
  8. package/lib/commonjs/pid/sd-jwt/index.js.map +1 -1
  9. package/lib/commonjs/rp/__test__/index.test.js +3 -5
  10. package/lib/commonjs/rp/__test__/index.test.js.map +1 -1
  11. package/lib/commonjs/rp/index.js +165 -15
  12. package/lib/commonjs/rp/index.js.map +1 -1
  13. package/lib/commonjs/rp/types.js +13 -1
  14. package/lib/commonjs/rp/types.js.map +1 -1
  15. package/lib/commonjs/sd-jwt/__test__/index.test.js +119 -0
  16. package/lib/commonjs/sd-jwt/__test__/index.test.js.map +1 -0
  17. package/lib/commonjs/sd-jwt/index.js +84 -4
  18. package/lib/commonjs/sd-jwt/index.js.map +1 -1
  19. package/lib/commonjs/sd-jwt/types.js +9 -0
  20. package/lib/commonjs/sd-jwt/types.js.map +1 -1
  21. package/lib/commonjs/sd-jwt/verifier.js +7 -5
  22. package/lib/commonjs/sd-jwt/verifier.js.map +1 -1
  23. package/lib/commonjs/utils/errors.js +76 -1
  24. package/lib/commonjs/utils/errors.js.map +1 -1
  25. package/lib/module/index.js +5 -1
  26. package/lib/module/index.js.map +1 -1
  27. package/lib/module/pid/issuing.js +30 -2
  28. package/lib/module/pid/issuing.js.map +1 -1
  29. package/lib/module/pid/metadata.js +43 -0
  30. package/lib/module/pid/metadata.js.map +1 -0
  31. package/lib/module/pid/sd-jwt/index.js +3 -3
  32. package/lib/module/pid/sd-jwt/index.js.map +1 -1
  33. package/lib/module/rp/__test__/index.test.js +3 -5
  34. package/lib/module/rp/__test__/index.test.js.map +1 -1
  35. package/lib/module/rp/index.js +168 -18
  36. package/lib/module/rp/index.js.map +1 -1
  37. package/lib/module/rp/types.js +11 -0
  38. package/lib/module/rp/types.js.map +1 -1
  39. package/lib/module/sd-jwt/__test__/index.test.js +118 -0
  40. package/lib/module/sd-jwt/__test__/index.test.js.map +1 -0
  41. package/lib/module/sd-jwt/index.js +83 -3
  42. package/lib/module/sd-jwt/index.js.map +1 -1
  43. package/lib/module/sd-jwt/types.js +10 -0
  44. package/lib/module/sd-jwt/types.js.map +1 -1
  45. package/lib/module/sd-jwt/verifier.js +8 -6
  46. package/lib/module/sd-jwt/verifier.js.map +1 -1
  47. package/lib/module/utils/errors.js +71 -0
  48. package/lib/module/utils/errors.js.map +1 -1
  49. package/lib/typescript/{index.d.ts → src/index.d.ts} +3 -1
  50. package/lib/typescript/src/index.d.ts.map +1 -0
  51. package/lib/typescript/src/pid/index.d.ts.map +1 -0
  52. package/lib/typescript/{pid → src/pid}/issuing.d.ts +9 -0
  53. package/lib/typescript/src/pid/issuing.d.ts.map +1 -0
  54. package/lib/typescript/src/pid/metadata.d.ts +528 -0
  55. package/lib/typescript/src/pid/metadata.d.ts.map +1 -0
  56. package/lib/typescript/src/pid/sd-jwt/converters.d.ts.map +1 -0
  57. package/lib/typescript/{pid → src/pid}/sd-jwt/index.d.ts +1 -1
  58. package/lib/typescript/src/pid/sd-jwt/index.d.ts.map +1 -0
  59. package/lib/typescript/src/pid/sd-jwt/types.d.ts.map +1 -0
  60. package/lib/typescript/src/rp/__test__/index.test.d.ts.map +1 -0
  61. package/lib/typescript/src/rp/index.d.ts +89 -0
  62. package/lib/typescript/src/rp/index.d.ts.map +1 -0
  63. package/lib/typescript/{rp → src/rp}/types.d.ts +71 -47
  64. package/lib/typescript/{rp → src/rp}/types.d.ts.map +1 -1
  65. package/lib/typescript/src/sd-jwt/__test__/converters.test.d.ts.map +1 -0
  66. package/lib/typescript/src/sd-jwt/__test__/index.test.d.ts +2 -0
  67. package/lib/typescript/src/sd-jwt/__test__/index.test.d.ts.map +1 -0
  68. package/lib/typescript/src/sd-jwt/__test__/types.test.d.ts.map +1 -0
  69. package/lib/typescript/src/sd-jwt/converters.d.ts.map +1 -0
  70. package/lib/typescript/{sd-jwt → src/sd-jwt}/index.d.ts +22 -2
  71. package/lib/typescript/src/sd-jwt/index.d.ts.map +1 -0
  72. package/lib/typescript/{sd-jwt → src/sd-jwt}/types.d.ts +12 -0
  73. package/lib/typescript/src/sd-jwt/types.d.ts.map +1 -0
  74. package/lib/typescript/src/sd-jwt/verifier.d.ts +3 -0
  75. package/lib/typescript/src/sd-jwt/verifier.d.ts.map +1 -0
  76. package/lib/typescript/src/utils/dpop.d.ts.map +1 -0
  77. package/lib/typescript/{utils → src/utils}/errors.d.ts +41 -0
  78. package/lib/typescript/src/utils/errors.d.ts.map +1 -0
  79. package/lib/typescript/src/utils/jwk.d.ts.map +1 -0
  80. package/lib/typescript/src/wallet-instance-attestation/index.d.ts.map +1 -0
  81. package/lib/typescript/src/wallet-instance-attestation/issuing.d.ts.map +1 -0
  82. package/lib/typescript/{wallet-instance-attestation → src/wallet-instance-attestation}/types.d.ts +8 -8
  83. package/lib/typescript/{wallet-instance-attestation → src/wallet-instance-attestation}/types.d.ts.map +1 -1
  84. package/package.json +7 -5
  85. package/src/index.ts +13 -1
  86. package/src/pid/issuing.ts +38 -1
  87. package/src/pid/metadata.ts +46 -0
  88. package/src/pid/sd-jwt/index.ts +7 -4
  89. package/src/rp/__test__/index.test.ts +5 -9
  90. package/src/rp/index.ts +208 -24
  91. package/src/rp/types.ts +16 -0
  92. package/src/sd-jwt/__test__/index.test.ts +171 -0
  93. package/src/sd-jwt/index.ts +84 -7
  94. package/src/sd-jwt/types.ts +13 -0
  95. package/src/sd-jwt/verifier.ts +5 -7
  96. package/src/utils/errors.ts +81 -0
  97. package/lib/typescript/index.d.ts.map +0 -1
  98. package/lib/typescript/pid/index.d.ts.map +0 -1
  99. package/lib/typescript/pid/issuing.d.ts.map +0 -1
  100. package/lib/typescript/pid/sd-jwt/converters.d.ts.map +0 -1
  101. package/lib/typescript/pid/sd-jwt/index.d.ts.map +0 -1
  102. package/lib/typescript/pid/sd-jwt/types.d.ts.map +0 -1
  103. package/lib/typescript/rp/__test__/index.test.d.ts.map +0 -1
  104. package/lib/typescript/rp/index.d.ts +0 -43
  105. package/lib/typescript/rp/index.d.ts.map +0 -1
  106. package/lib/typescript/sd-jwt/__test__/converters.test.d.ts.map +0 -1
  107. package/lib/typescript/sd-jwt/__test__/types.test.d.ts.map +0 -1
  108. package/lib/typescript/sd-jwt/converters.d.ts.map +0 -1
  109. package/lib/typescript/sd-jwt/index.d.ts.map +0 -1
  110. package/lib/typescript/sd-jwt/types.d.ts.map +0 -1
  111. package/lib/typescript/sd-jwt/verifier.d.ts +0 -3
  112. package/lib/typescript/sd-jwt/verifier.d.ts.map +0 -1
  113. package/lib/typescript/utils/dpop.d.ts.map +0 -1
  114. package/lib/typescript/utils/errors.d.ts.map +0 -1
  115. package/lib/typescript/utils/jwk.d.ts.map +0 -1
  116. package/lib/typescript/wallet-instance-attestation/index.d.ts.map +0 -1
  117. package/lib/typescript/wallet-instance-attestation/issuing.d.ts.map +0 -1
  118. /package/lib/typescript/{pid → src/pid}/index.d.ts +0 -0
  119. /package/lib/typescript/{pid → src/pid}/sd-jwt/converters.d.ts +0 -0
  120. /package/lib/typescript/{pid → src/pid}/sd-jwt/types.d.ts +0 -0
  121. /package/lib/typescript/{rp → src/rp}/__test__/index.test.d.ts +0 -0
  122. /package/lib/typescript/{sd-jwt → src/sd-jwt}/__test__/converters.test.d.ts +0 -0
  123. /package/lib/typescript/{sd-jwt → src/sd-jwt}/__test__/types.test.d.ts +0 -0
  124. /package/lib/typescript/{sd-jwt → src/sd-jwt}/converters.d.ts +0 -0
  125. /package/lib/typescript/{utils → src/utils}/dpop.d.ts +0 -0
  126. /package/lib/typescript/{utils → src/utils}/jwk.d.ts +0 -0
  127. /package/lib/typescript/{wallet-instance-attestation → src/wallet-instance-attestation}/index.d.ts +0 -0
  128. /package/lib/typescript/{wallet-instance-attestation → src/wallet-instance-attestation}/issuing.d.ts +0 -0
@@ -1,5 +1,4 @@
1
- import { decode as decodeJwt } from "../../sd-jwt";
2
- import { verify as verifyJwt } from "../../sd-jwt";
1
+ import { decode as decodeJwt, verify as verifyJwt } from "../../sd-jwt";
3
2
  import { pidFromToken } from "./converters";
4
3
  import { SdJwt4VC } from "../../sd-jwt/types";
5
4
 
@@ -21,8 +20,9 @@ import { SdJwt4VC } from "../../sd-jwt/types";
21
20
  export function decode(token) {
22
21
  let {
23
22
  sdJwt,
24
- disclosures
23
+ disclosures: disclosuresWithOriginal
25
24
  } = decodeJwt(token, SdJwt4VC);
25
+ const disclosures = disclosuresWithOriginal.map(d => d.decoded);
26
26
  const pid = pidFromToken(sdJwt, disclosures);
27
27
  return {
28
28
  pid,
@@ -1 +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"}
1
+ {"version":3,"names":["decode","decodeJwt","verify","verifyJwt","pidFromToken","SdJwt4VC","token","sdJwt","disclosures","disclosuresWithOriginal","map","d","decoded","pid","publicKey","payload","cnf","jwk","PID"],"sourceRoot":"../../../../src","sources":["pid/sd-jwt/index.ts"],"mappings":"AAAA,SAASA,MAAM,IAAIC,SAAS,EAAEC,MAAM,IAAIC,SAAS,QAAQ,cAAc;AAEvE,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,WAAW,EAAEC;EAAwB,CAAC,GAAGR,SAAS,CAC7DK,KAAK,EACLD,QACF,CAAC;EACD,MAAMG,WAAW,GAAGC,uBAAuB,CAACC,GAAG,CAAEC,CAAC,IAAKA,CAAC,CAACC,OAAO,CAAC;EACjE,MAAMC,GAAG,GAAGT,YAAY,CAACG,KAAK,EAAEC,WAAW,CAAC;EAE5C,OAAO;IAAEK,GAAG;IAAEN,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,MAAMM,OAAO,GAAGZ,MAAM,CAACM,KAAK,CAAC;EAC7B,MAAMQ,SAAS,GAAGF,OAAO,CAACL,KAAK,CAACQ,OAAO,CAACC,GAAG,CAACC,GAAG;EAC/C,MAAMd,SAAS,CAACG,KAAK,EAAEQ,SAAS,EAAET,QAAQ,CAAC;EAE3C,OAAOO,OAAO;AAChB;;AAWA;AACA;AACA;;AAGA,SAASM,GAAG,QAAQ,SAAS"}
@@ -1,16 +1,14 @@
1
1
  import { RelyingPartySolution } from "..";
2
2
  import { AuthRequestDecodeError } from "../../utils/errors";
3
- const walletInstanceAttestation = "eyJhbGciOiJFUzI1NiIsImtpZCI6IjV0NVlZcEJoTi1FZ0lFRUk1aVV6cjZyME1SMDJMblZRME9tZWttTktjalkiLCJ0cnVzdF9jaGFpbiI6WyJleUpoYkdjaU9pSkZVei4uLjZTMEEiLCJleUpoYkdjaU9pSkZVei4uLmpKTEEiLCJleUpoYkdjaU9pSkZVei4uLkg5Z3ciXSwidHlwIjoidmErand0IiwieDVjIjpbIk1JSUJqRENDIC4uLiBYRmVoZ0tRQT09Il19.eyJpc3MiOiJodHRwczovL3dhbGxldC1wcm92aWRlci5leGFtcGxlLm9yZyIsInN1YiI6InZiZVhKa3NNNDV4cGh0QU5uQ2lHNm1DeXVVNGpmR056b3BHdUt2b2dnOWMiLCJ0eXBlIjoiV2FsbGV0SW5zdGFuY2VBdHRlc3RhdGlvbiIsInBvbGljeV91cmkiOiJodHRwczovL3dhbGxldC1wcm92aWRlci5leGFtcGxlLm9yZy9wcml2YWN5X3BvbGljeSIsInRvc191cmkiOiJodHRwczovL3dhbGxldC1wcm92aWRlci5leGFtcGxlLm9yZy9pbmZvX3BvbGljeSIsImxvZ29fdXJpIjoiaHR0cHM6Ly93YWxsZXQtcHJvdmlkZXIuZXhhbXBsZS5vcmcvbG9nby5zdmciLCJhc2MiOiJodHRwczovL3dhbGxldC1wcm92aWRlci5leGFtcGxlLm9yZy9Mb0EvYmFzaWMiLCJjbmYiOnsiandrIjp7ImNydiI6IlAtMjU2Iiwia3R5IjoiRUMiLCJ4IjoiNEhOcHRJLXhyMnBqeVJKS0dNbno0V21kblFEX3VKU3E0Ujk1Tmo5OGI0NCIsInkiOiJMSVpuU0IzOXZGSmhZZ1MzazdqWEU0cjMtQ29HRlF3WnRQQklScXBObHJnIiwia2lkIjoidmJlWEprc000NXhwaHRBTm5DaUc2bUN5dVU0amZHTnpvcEd1S3ZvZ2c5YyJ9fSwiYXV0aG9yaXphdGlvbl9lbmRwb2ludCI6ImV1ZGl3OiIsInJlc3BvbnNlX3R5cGVzX3N1cHBvcnRlZCI6WyJ2cF90b2tlbiJdLCJ2cF9mb3JtYXRzX3N1cHBvcnRlZCI6eyJqd3RfdnBfanNvbiI6eyJhbGdfdmFsdWVzX3N1cHBvcnRlZCI6WyJFUzI1NiJdfSwiand0X3ZjX2pzb24iOnsiYWxnX3ZhbHVlc19zdXBwb3J0ZWQiOlsiRVMyNTYiXX19LCJyZXF1ZXN0X29iamVjdF9zaWduaW5nX2FsZ192YWx1ZXNfc3VwcG9ydGVkIjpbIkVTMjU2Il0sInByZXNlbnRhdGlvbl9kZWZpbml0aW9uX3VyaV9zdXBwb3J0ZWQiOmZhbHNlLCJpYXQiOjE2ODcyODExOTUsImV4cCI6MTY4NzI4ODM5NX0.OTuPik6p3o9j6VOx-uCyxRvHwoh1pDiiZcBQFNQt2uE3dK-8izGNflJVETi_uhGSZOf25Enkq-UvEin9NrbJNw";
4
- const rp = new RelyingPartySolution("http://rp.example", walletInstanceAttestation);
5
3
  describe("decodeAuthRequestQR", () => {
6
4
  it("should return authentication request URL", async () => {
7
5
  const qrcode = "ZXVkaXc6Ly9hdXRob3JpemU/Y2xpZW50X2lkPWh0dHBzOi8vdmVyaWZpZXIuZXhhbXBsZS5vcmcmcmVxdWVzdF91cmk9aHR0cHM6Ly92ZXJpZmllci5leGFtcGxlLm9yZy9yZXF1ZXN0X3VyaQ==";
8
- const result = rp.decodeAuthRequestQR(qrcode);
9
- expect(result).toEqual("https://verifier.example.org/request_uri");
6
+ const result = RelyingPartySolution.decodeAuthRequestQR(qrcode);
7
+ expect(result.requestURI).toEqual("https://verifier.example.org/request_uri");
10
8
  });
11
9
  it("should throw exception with invalid QR", async () => {
12
10
  const qrcode = "aHR0cDovL2dvb2dsZS5pdA==";
13
- expect(() => rp.decodeAuthRequestQR(qrcode)).toThrowError(AuthRequestDecodeError);
11
+ expect(() => RelyingPartySolution.decodeAuthRequestQR(qrcode)).toThrowError(AuthRequestDecodeError);
14
12
  });
15
13
  });
16
14
  //# sourceMappingURL=index.test.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["RelyingPartySolution","AuthRequestDecodeError","walletInstanceAttestation","rp","describe","it","qrcode","result","decodeAuthRequestQR","expect","toEqual","toThrowError"],"sourceRoot":"../../../../src","sources":["rp/__test__/index.test.ts"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,IAAI;AACzC,SAASC,sBAAsB,QAAQ,oBAAoB;AAE3D,MAAMC,yBAAyB,GAC7B,qhDAAqhD;AACvhD,MAAMC,EAAE,GAAG,IAAIH,oBAAoB,CACjC,mBAAmB,EACnBE,yBACF,CAAC;AACDE,QAAQ,CAAC,qBAAqB,EAAE,MAAM;EACpCC,EAAE,CAAC,0CAA0C,EAAE,YAAY;IACzD,MAAMC,MAAM,GACV,sJAAsJ;IACxJ,MAAMC,MAAM,GAAGJ,EAAE,CAACK,mBAAmB,CAACF,MAAM,CAAC;IAC7CG,MAAM,CAACF,MAAM,CAAC,CAACG,OAAO,CAAC,0CAA0C,CAAC;EACpE,CAAC,CAAC;EACFL,EAAE,CAAC,wCAAwC,EAAE,YAAY;IACvD,MAAMC,MAAM,GAAG,0BAA0B;IACzCG,MAAM,CAAC,MAAMN,EAAE,CAACK,mBAAmB,CAACF,MAAM,CAAC,CAAC,CAACK,YAAY,CACvDV,sBACF,CAAC;EACH,CAAC,CAAC;AACJ,CAAC,CAAC"}
1
+ {"version":3,"names":["RelyingPartySolution","AuthRequestDecodeError","describe","it","qrcode","result","decodeAuthRequestQR","expect","requestURI","toEqual","toThrowError"],"sourceRoot":"../../../../src","sources":["rp/__test__/index.test.ts"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,IAAI;AACzC,SAASC,sBAAsB,QAAQ,oBAAoB;AAE3DC,QAAQ,CAAC,qBAAqB,EAAE,MAAM;EACpCC,EAAE,CAAC,0CAA0C,EAAE,YAAY;IACzD,MAAMC,MAAM,GACV,sJAAsJ;IACxJ,MAAMC,MAAM,GAAGL,oBAAoB,CAACM,mBAAmB,CAACF,MAAM,CAAC;IAC/DG,MAAM,CAACF,MAAM,CAACG,UAAU,CAAC,CAACC,OAAO,CAC/B,0CACF,CAAC;EACH,CAAC,CAAC;EACFN,EAAE,CAAC,wCAAwC,EAAE,YAAY;IACvD,MAAMC,MAAM,GAAG,0BAA0B;IACzCG,MAAM,CAAC,MAAMP,oBAAoB,CAACM,mBAAmB,CAACF,MAAM,CAAC,CAAC,CAACM,YAAY,CACzET,sBACF,CAAC;EACH,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -1,7 +1,8 @@
1
- import { AuthRequestDecodeError, IoWalletError } from "../utils/errors";
2
- import { decode as decodeJwt, decodeBase64, sha256ToBase64, SignJWT } from "@pagopa/io-react-native-jwt";
3
- import { RequestObject, RpEntityConfiguration } from "./types";
1
+ import { AuthRequestDecodeError, IoWalletError, NoSuitableKeysFoundInEntityConfiguration } from "../utils/errors";
2
+ import { decode as decodeJwt, decodeBase64, sha256ToBase64, SignJWT, EncryptJwe, verify } from "@pagopa/io-react-native-jwt";
3
+ import { QRCodePayload, RequestObject, RpEntityConfiguration } from "./types";
4
4
  import uuid from "react-native-uuid";
5
+ import { disclose } from "../sd-jwt";
5
6
  export class RelyingPartySolution {
6
7
  constructor(relyingPartyBaseUrl, walletInstanceAttestation) {
7
8
  let appFetch = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : fetch;
@@ -18,18 +19,23 @@ export class RelyingPartySolution {
18
19
  * @returns The authentication request url
19
20
  *
20
21
  */
21
- decodeAuthRequestQR(qrcode) {
22
- try {
23
- const decoded = decodeBase64(qrcode);
24
- const decodedUrl = new URL(decoded);
25
- const requestUri = decodedUrl.searchParams.get("request_uri");
26
- if (requestUri) {
27
- return requestUri;
28
- } else {
29
- throw new AuthRequestDecodeError("Unable to obtain request_uri from QR code", `${decodedUrl}`);
30
- }
31
- } catch {
32
- throw new AuthRequestDecodeError("Unable to decode QR code authentication request url", qrcode);
22
+ static decodeAuthRequestQR(qrcode) {
23
+ const decoded = decodeBase64(qrcode);
24
+ const decodedUrl = new URL(decoded);
25
+ const protocol = decodedUrl.protocol;
26
+ const resource = decodedUrl.hostname;
27
+ const requestURI = decodedUrl.searchParams.get("request_uri");
28
+ const clientId = decodedUrl.searchParams.get("client_id");
29
+ const result = QRCodePayload.safeParse({
30
+ protocol,
31
+ resource,
32
+ requestURI,
33
+ clientId
34
+ });
35
+ if (result.success) {
36
+ return result.data;
37
+ } else {
38
+ throw new AuthRequestDecodeError(result.error.message, `${decodedUrl}`);
33
39
  }
34
40
  }
35
41
  /**
@@ -57,14 +63,16 @@ export class RelyingPartySolution {
57
63
 
58
64
  /**
59
65
  * Obtain the Request Object for RP authentication
66
+ * @see https://italia.github.io/eudi-wallet-it-docs/versione-corrente/en/relying-party-solution.html
60
67
  *
61
- * @function
68
+ * @async @function
62
69
  * @param signedWalletInstanceDPoP JWT of the Wallet Instance Attestation DPoP
63
70
  *
64
71
  * @returns The Request Object JWT
72
+ * @throws {NoSuitableKeysFoundInEntityConfiguration} When the Request Object is signed with a key not listed in RP's entity configuration
65
73
  *
66
74
  */
67
- async getRequestObject(signedWalletInstanceDPoP) {
75
+ async getRequestObject(signedWalletInstanceDPoP, entity) {
68
76
  const decodedJwtDPop = await decodeJwt(signedWalletInstanceDPoP);
69
77
  const requestUri = decodedJwtDPop.payload.htu;
70
78
  const response = await this.appFetch(requestUri, {
@@ -76,7 +84,24 @@ export class RelyingPartySolution {
76
84
  });
77
85
  if (response.status === 200) {
78
86
  const responseText = await response.text();
79
- const responseJwt = await decodeJwt(responseText);
87
+ const responseJwt = decodeJwt(responseText);
88
+
89
+ // verify token signature according to RP's entity configuration
90
+ // to ensure the request object is authentic
91
+ {
92
+ const pubKey = entity.payload.jwks.keys.find(_ref => {
93
+ let {
94
+ kid
95
+ } = _ref;
96
+ return kid === responseJwt.protectedHeader.kid;
97
+ });
98
+ if (!pubKey) {
99
+ throw new NoSuitableKeysFoundInEntityConfiguration("Request Object signature verification");
100
+ }
101
+ await verify(responseText, pubKey);
102
+ }
103
+
104
+ // parse request object it has the expected shape by specification
80
105
  const requestObj = RequestObject.parse({
81
106
  header: responseJwt.protectedHeader,
82
107
  payload: responseJwt.payload
@@ -86,6 +111,131 @@ export class RelyingPartySolution {
86
111
  throw new IoWalletError(`Unable to obtain Request Object. Response code: ${response.status}`);
87
112
  }
88
113
 
114
+ /**
115
+ * Prepare the Verified Presentation token for a received request object in the context of an authorization request flow.
116
+ * The presentation is prepared by disclosing data from provided credentials, according to requested claims
117
+ * Each Verified Credential come along with the claims the user accepts to disclose from it.
118
+ *
119
+ * The returned token is unsigned (sign should be apply by the caller).
120
+ *
121
+ * @todo accept more than a Verified Credential
122
+ *
123
+ * @param requestObj The incoming request object, which the requirements for the requested authorization
124
+ * @param presentation The Verified Credential containing user data along with the list of claims to be disclosed.
125
+ * @returns The unsigned Verified Presentation token
126
+ * @throws {ClaimsNotFoundBetweenDislosures} If the Verified Credential does not contain one or more requested claims.
127
+ *
128
+ */
129
+ async prepareVpToken(requestObj, _ref2) {
130
+ let [vc, claims] = _ref2;
131
+ // this throws if vc cannot satisfy all the requested claims
132
+ const {
133
+ token: vp,
134
+ paths
135
+ } = await disclose(vc, claims);
136
+
137
+ // TODO: [SIW-359] check all requeste claims of the requestedObj are satisfied
138
+
139
+ const vp_token = new SignJWT({
140
+ vp
141
+ }).setAudience(requestObj.payload.response_uri).setExpirationTime("1h").setProtectedHeader({
142
+ typ: "JWT",
143
+ alg: "ES256"
144
+ }).toSign();
145
+ const [definition_id, vc_scope] = requestObj.payload.scope;
146
+ const presentation_submission = {
147
+ definition_id,
148
+ id: `${uuid.v4()}`,
149
+ descriptor_map: paths.map(p => ({
150
+ id: vc_scope,
151
+ path: `$.vp_token.${p.path}`,
152
+ format: "vc+sd-jwt"
153
+ }))
154
+ };
155
+ return {
156
+ vp_token,
157
+ presentation_submission
158
+ };
159
+ }
160
+
161
+ /**
162
+ * Compose and send an Authorization Response in the context of an authorization request flow.
163
+ *
164
+ * @todo MUST add presentation_submission
165
+ *
166
+ * @param requestObj The incoming request object, which the requirements for the requested authorization
167
+ * @param vp_token The signed Verified Presentation token with data to send.
168
+ * @param presentation_submission
169
+ * @param entity The RP entity configuration
170
+ * @returns The response from the RP
171
+ * @throws {IoWalletError} if the submission fails.
172
+ * @throws {NoSuitableKeysFoundInEntityConfiguration} If entity do not contain any public key
173
+ *
174
+ */
175
+ async sendAuthorizationResponse(requestObj, vp_token, presentation_submission, entity) {
176
+ // the request is an unsigned jws without iss, aud, exp
177
+ // https://openid.net/specs/openid-4-verifiable-presentations-1_0.html#name-signed-and-encrypted-respon
178
+ const jwk = this.choosePublicKeyToEncrypt(entity);
179
+ const enc = this.getEncryptionAlgByJwk(jwk);
180
+ const authzResponsePayload = JSON.stringify({
181
+ state: requestObj.payload.state,
182
+ presentation_submission,
183
+ vp_token
184
+ });
185
+ const encrypted = await new EncryptJwe(authzResponsePayload, {
186
+ alg: jwk.alg,
187
+ enc
188
+ }).encrypt(jwk);
189
+ const formBody = new URLSearchParams({
190
+ response: encrypted
191
+ });
192
+ const response = await this.appFetch(requestObj.payload.response_uri, {
193
+ method: "POST",
194
+ headers: {
195
+ "Content-Type": "application/x-www-form-urlencoded"
196
+ },
197
+ body: formBody.toString()
198
+ });
199
+ if (response.status === 200) {
200
+ return response.text();
201
+ }
202
+ throw new IoWalletError(`Unable to send Authorization Response. Response code: ${response.status}`);
203
+ }
204
+
205
+ /**
206
+ * Select a public key from those provided by the RP.
207
+ * Keys with algorithm "RSA-OAEP-256" or "RSA-OAEP" are expected, the firsts to be preferred.
208
+ *
209
+ * @param entity The RP entity configuration
210
+ * @returns A suitable public key with its compatible encryption algorithm
211
+ * @throws {NoSuitableKeysFoundInEntityConfiguration} If entity do not contain any public key suitable for encrypting
212
+ */
213
+ choosePublicKeyToEncrypt(entity) {
214
+ // Look for keys using "RSA-OAEP-256", and pick a random one
215
+ const [usingRsa256] = entity.payload.jwks.keys.filter(k => typeof k.alg === "string" && k.alg === "RSA-OAEP-256");
216
+ if (usingRsa256) {
217
+ return usingRsa256;
218
+ }
219
+
220
+ // Look for keys using "RSA-OAEP", and pick a random one
221
+ const [usingRsa] = entity.payload.jwks.keys.filter(k => typeof k.alg === "string" && k.alg === "RSA-OAEP");
222
+ if (usingRsa) {
223
+ return usingRsa;
224
+ }
225
+
226
+ // No suitable key has been found
227
+ throw new NoSuitableKeysFoundInEntityConfiguration("Encrypt with RP public key");
228
+ }
229
+ getEncryptionAlgByJwk(_ref3) {
230
+ let {
231
+ alg
232
+ } = _ref3;
233
+ if (alg === "RSA-OAEP-256") return "A256CBC-HS512";
234
+ if (alg === "RSA-OAEP") return "A128CBC-HS256";
235
+ const _ = alg;
236
+ throw new Error(`Invalid jwk algorithm: ${_}`);
237
+ }
238
+
89
239
  /**
90
240
  * Obtain the relying party entity configuration.
91
241
  */
@@ -1 +1 @@
1
- {"version":3,"names":["AuthRequestDecodeError","IoWalletError","decode","decodeJwt","decodeBase64","sha256ToBase64","SignJWT","RequestObject","RpEntityConfiguration","uuid","RelyingPartySolution","constructor","relyingPartyBaseUrl","walletInstanceAttestation","appFetch","arguments","length","undefined","fetch","decodeAuthRequestQR","qrcode","decoded","decodedUrl","URL","requestUri","searchParams","get","getUnsignedWalletInstanceDPoP","walletInstanceAttestationJwk","authRequestUrl","jti","v4","htm","htu","ath","setProtectedHeader","alg","jwk","typ","setIssuedAt","setExpirationTime","toSign","getRequestObject","signedWalletInstanceDPoP","decodedJwtDPop","payload","response","method","headers","Authorization","DPoP","status","responseText","text","responseJwt","requestObj","parse","header","protectedHeader","getEntityConfiguration","wellKnownUrl","href"],"sourceRoot":"../../../src","sources":["rp/index.ts"],"mappings":"AAAA,SAASA,sBAAsB,EAAEC,aAAa,QAAQ,iBAAiB;AACvE,SACEC,MAAM,IAAIC,SAAS,EACnBC,YAAY,EACZC,cAAc,EACdC,OAAO,QACF,6BAA6B;AACpC,SAASC,aAAa,EAAEC,qBAAqB,QAAQ,SAAS;AAE9D,OAAOC,IAAI,MAAM,mBAAmB;AAGpC,OAAO,MAAMC,oBAAoB,CAAC;EAKhCC,WAAWA,CACTC,mBAA2B,EAC3BC,yBAAiC,EAEjC;IAAA,IADAC,QAA8B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGG,KAAK;IAEtC,IAAI,CAACN,mBAAmB,GAAGA,mBAAmB;IAC9C,IAAI,CAACC,yBAAyB,GAAGA,yBAAyB;IAC1D,IAAI,CAACC,QAAQ,GAAGA,QAAQ;EAC1B;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEK,mBAAmBA,CAACC,MAAc,EAAU;IAC1C,IAAI;MACF,MAAMC,OAAO,GAAGjB,YAAY,CAACgB,MAAM,CAAC;MACpC,MAAME,UAAU,GAAG,IAAIC,GAAG,CAACF,OAAO,CAAC;MACnC,MAAMG,UAAU,GAAGF,UAAU,CAACG,YAAY,CAACC,GAAG,CAAC,aAAa,CAAC;MAC7D,IAAIF,UAAU,EAAE;QACd,OAAOA,UAAU;MACnB,CAAC,MAAM;QACL,MAAM,IAAIxB,sBAAsB,CAC9B,2CAA2C,EAC1C,GAAEsB,UAAW,EAChB,CAAC;MACH;IACF,CAAC,CAAC,MAAM;MACN,MAAM,IAAItB,sBAAsB,CAC9B,qDAAqD,EACrDoB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AW,CAACI,eAAe;QACnCb,OAAO,EAAES,WAAW,CAACT;MACvB,CAAC,CAAC;MACF,OAAOU,UAAU;IACnB;IAEA,MAAM,IAAItD,aAAa,CACpB,mDAAkD6C,QAAQ,CAACK,MAAO,EACrE,CAAC;EACH;;EAEA;AACF;AACA;EACE,MAAMQ,sBAAsBA,CAAA,EAAmC;IAC7D,MAAMC,YAAY,GAAG,IAAIrC,GAAG,CAC1B,gCAAgC,EAChC,IAAI,CAACX,mBACP,CAAC,CAACiD,IAAI;IAEN,MAAMf,QAAQ,GAAG,MAAM,IAAI,CAAChC,QAAQ,CAAC8C,YAAY,EAAE;MACjDb,MAAM,EAAE;IACV,CAAC,CAAC;IAEF,IAAID,QAAQ,CAACK,MAAM,KAAK,GAAG,EAAE;MAC3B,MAAMC,YAAY,GAAG,MAAMN,QAAQ,CAACO,IAAI,CAAC,CAAC;MAC1C,MAAMC,WAAW,GAAG,MAAMnD,SAAS,CAACiD,YAAY,CAAC;MACjD,OAAO5C,qBAAqB,CAACgD,KAAK,CAAC;QACjCC,MAAM,EAAEH,WAAW,CAACI,eAAe;QACnCb,OAAO,EAAES,WAAW,CAACT;MACvB,CAAC,CAAC;IACJ;IAEA,MAAM,IAAI5C,aAAa,CACpB,4DAA2D6C,QAAQ,CAACK,MAAO,EAC9E,CAAC;EACH;AACF"}
1
+ {"version":3,"names":["AuthRequestDecodeError","IoWalletError","NoSuitableKeysFoundInEntityConfiguration","decode","decodeJwt","decodeBase64","sha256ToBase64","SignJWT","EncryptJwe","verify","QRCodePayload","RequestObject","RpEntityConfiguration","uuid","disclose","RelyingPartySolution","constructor","relyingPartyBaseUrl","walletInstanceAttestation","appFetch","arguments","length","undefined","fetch","decodeAuthRequestQR","qrcode","decoded","decodedUrl","URL","protocol","resource","hostname","requestURI","searchParams","get","clientId","result","safeParse","success","data","error","message","getUnsignedWalletInstanceDPoP","walletInstanceAttestationJwk","authRequestUrl","jti","v4","htm","htu","ath","setProtectedHeader","alg","jwk","typ","setIssuedAt","setExpirationTime","toSign","getRequestObject","signedWalletInstanceDPoP","entity","decodedJwtDPop","requestUri","payload","response","method","headers","Authorization","DPoP","status","responseText","text","responseJwt","pubKey","jwks","keys","find","_ref","kid","protectedHeader","requestObj","parse","header","prepareVpToken","_ref2","vc","claims","token","vp","paths","vp_token","setAudience","response_uri","definition_id","vc_scope","scope","presentation_submission","id","descriptor_map","map","p","path","format","sendAuthorizationResponse","choosePublicKeyToEncrypt","enc","getEncryptionAlgByJwk","authzResponsePayload","JSON","stringify","state","encrypted","encrypt","formBody","URLSearchParams","body","toString","usingRsa256","filter","k","usingRsa","_ref3","_","Error","getEntityConfiguration","wellKnownUrl","href"],"sourceRoot":"../../../src","sources":["rp/index.ts"],"mappings":"AAAA,SACEA,sBAAsB,EACtBC,aAAa,EACbC,wCAAwC,QACnC,iBAAiB;AACxB,SACEC,MAAM,IAAIC,SAAS,EACnBC,YAAY,EACZC,cAAc,EACdC,OAAO,EACPC,UAAU,EACVC,MAAM,QACD,6BAA6B;AACpC,SACEC,aAAa,EACbC,aAAa,EACbC,qBAAqB,QAEhB,SAAS;AAEhB,OAAOC,IAAI,MAAM,mBAAmB;AAEpC,SAASC,QAAQ,QAAQ,WAAW;AAEpC,OAAO,MAAMC,oBAAoB,CAAC;EAKhCC,WAAWA,CACTC,mBAA2B,EAC3BC,yBAAiC,EAEjC;IAAA,IADAC,QAA8B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGG,KAAK;IAEtC,IAAI,CAACN,mBAAmB,GAAGA,mBAAmB;IAC9C,IAAI,CAACC,yBAAyB,GAAGA,yBAAyB;IAC1D,IAAI,CAACC,QAAQ,GAAGA,QAAQ;EAC1B;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE,OAAOK,mBAAmBA,CAACC,MAAc,EAAiB;IACxD,MAAMC,OAAO,GAAGrB,YAAY,CAACoB,MAAM,CAAC;IACpC,MAAME,UAAU,G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ration = z.object({
60
60
  authority_hints: z.array(z.string())
61
61
  })
62
62
  });
63
+ export const QRCodePayload = z.object({
64
+ protocol: z.literal("eudiw:"),
65
+ resource: z.string(),
66
+ // TODO: refine to known paths using literals
67
+ clientId: z.string(),
68
+ requestURI: z.string()
69
+ });
70
+
71
+ /**
72
+ * A pair that associate a tokenized Verified Credential with the claims presented or requested to present.
73
+ */
63
74
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["JWK","UnixTime","z","RequestObject","object","header","typ","literal","alg","string","kid","trust_chain","array","payload","iss","iat","exp","state","nonce","response_uri","response_type","response_mode","client_id","client_id_scheme","scope","RpEntityConfiguration","sub","jwks","keys","metadata","wallet_relying_party","application_type","client_name","contacts","federation_entity","organization_name","homepage_uri","policy_uri","logo_uri","authority_hints"],"sourceRoot":"../../../src","sources":["rp/types.ts"],"mappings":"AAAA,SAASA,GAAG,QAAQ,cAAc;AAClC,SAASC,QAAQ,QAAQ,iBAAiB;AAC1C,OAAO,KAAKC,CAAC,MAAM,KAAK;AAGxB,OAAO,MAAMC,aAAa,GAAGD,CAAC,CAACE,MAAM,CAAC;EACpCC,MAAM,EAAEH,CAAC,CAACE,MAAM,CAAC;IACfE,GAAG,EAAEJ,CAAC,CAACK,OAAO,CAAC,KAAK,CAAC;IACrBC,GAAG,EAAEN,CAAC,CAACO,MAAM,CAAC,CAAC;IACfC,GAAG,EAAER,CAAC,CAACO,MAAM,CAAC,CAAC;IACfE,WAAW,EAAET,CAAC,CAACU,KAAK,CAACV,CAAC,CAACO,MAAM,CAAC,CAAC;EACjC,CAAC,CAAC;EACFI,OAAO,EAAEX,CAAC,CAACE,MAAM,CAAC;IAChBU,GAAG,EAAEZ,CAAC,CAACO,MAAM,CAAC,CAAC;IACfM,GAAG,EAAEd,QAAQ;IACbe,GAAG,EAAEf,QAAQ;IACbgB,KAAK,EAAEf,CAAC,CAACO,MAAM,CAAC,CAAC;IACjBS,KAAK,EAAEhB,CAAC,CAACO,MA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QACvBkB,IAAI,EAAEzB,CAAC,CAACE,MAAM,CAAC;UACbwB,IAAI,EAAE1B,CAAC,CAACU,KAAK,CAACZ,GAAG;QACnB,CAAC,CAAC;QACFiC,QAAQ,EAAE/B,CAAC,CAACU,KAAK,CAACV,CAAC,CAACO,MAAM,CAAC,CAAC;MAC9B,CAAC,CAAC;MACFyB,iBAAiB,EAAEhC,CAAC,CAACE,MAAM,CAAC;QAC1B+B,iBAAiB,EAAEjC,CAAC,CAACO,MAAM,CAAC,CAAC;QAC7B2B,YAAY,EAAElC,CAAC,CAACO,MAAM,CAAC,CAAC;QACxB4B,UAAU,EAAEnC,CAAC,CAACO,MAAM,CAAC,CAAC;QACtB6B,QAAQ,EAAEpC,CAAC,CAACO,MAAM,CAAC,CAAC;QACpBwB,QAAQ,EAAE/B,CAAC,CAACU,KAAK,CAACV,CAAC,CAACO,MAAM,CAAC,CAAC;MAC9B,CAAC;IACH,CAAC,CAAC;IACF8B,eAAe,EAAErC,CAAC,CAACU,KAAK,CAACV,CAAC,CAACO,MAAM,CAAC,CAAC;EACrC,CAAC;AACH,CAAC,CAAC"}
1
+ {"version":3,"names":["JWK","UnixTime","z","RequestObject","object","header","typ","literal","alg","string","kid","trust_chain","array","payload","iss","iat","exp","state","nonce","response_uri","response_type","response_mode","client_id","client_id_scheme","scope","RpEntityConfiguration","sub","jwks","keys","metadata","wallet_relying_party","application_type","client_name","contacts","federation_entity","organization_name","homepage_uri","policy_uri","logo_uri","authority_hints","QRCodePayload","protocol","resource","clientId","requestURI"],"sourceRoot":"../../../src","sources":["rp/types.ts"],"mappings":"AAAA,SAASA,GAAG,QAAQ,cAAc;AAClC,SAASC,QAAQ,QAAQ,iBAAiB;AAC1C,OAAO,KAAKC,CAAC,MAAM,KAAK;AAGxB,OAAO,MAAMC,aAAa,GAAGD,CAAC,CAACE,MAAM,CAAC;EACpCC,MAAM,EAAEH,CAAC,CAACE,MAAM,CAAC;IACfE,GAAG,EAAEJ,CAAC,CAACK,OAAO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O,CAAC,QAAQ,CAAC;EAC7BmC,QAAQ,EAAExC,CAAC,CAACO,MAAM,CAAC,CAAC;EAAE;EACtBkC,QAAQ,EAAEzC,CAAC,CAACO,MAAM,CAAC,CAAC;EACpBmC,UAAU,EAAE1C,CAAC,CAACO,MAAM,CAAC;AACvB,CAAC,CAAC;;AAEF;AACA;AACA"}
@@ -0,0 +1,118 @@
1
+ import { decode, disclose } from "../index";
2
+ import { encodeBase64, decodeBase64 } from "@pagopa/io-react-native-jwt";
3
+ import { SdJwt4VC } from "../types";
4
+
5
+ // Examples from https://www.ietf.org/id/draft-terbu-sd-jwt-vc-02.html#name-example-4
6
+ // but adapted to adhere to format declared in https://italia.github.io/eudi-wallet-it-docs/versione-corrente/en/pid-eaa-data-model.html#id2
7
+ // In short, the token is a Frankenstein composed as follows:
8
+ // - the header is taken from the italian specification, with kid and alg valued according to the signing keys
9
+ // - disclosures are taken from the SD-JWT-4-VC standard
10
+ // - payload is taken from the italian specification, but _sd are compiled with:
11
+ // - "address" is used as verification._sd
12
+ // - all others disclosures are in claims._sd
13
+ const token = "eyJ0eXAiOiJ2YytzZC1qd3QiLCJhbGciOiJFUzI1NiIsImtpZCI6ImIxODZlYTBjMTkyNTc5MzA5N2JmMDFiOGEyODlhNDVmIiwidHJ1c3RfY2hhaW4iOlsiTkVoUmRFUnBZbmxIWTNNNVdsZFdUV1oyYVVobSAuLi4iLCJleUpoYkdjaU9pSlNVekkxTmlJc0ltdHBaQ0k2IC4uLiIsIklrSllkbVp5Ykc1b1FVMTFTRkl3TjJGcVZXMUIgLi4uIl19.eyJpc3MiOiJodHRwczovL2V4YW1wbGUuY29tL2lzc3VlciIsInN1YiI6Ik56YkxzWGg4dURDY2Q3bm9XWEZaQWZIa3hac1JHQzlYcy4uLiIsImp0aSI6InVybjp1dWlkOjZjNWMwYTQ5LWI1ODktNDMxZC1iYWU3LTIxOTEyMmE5ZWMyYyIsImlhdCI6MTU0MTQ5MzcyNCwiZXhwIjoxNTQxNDkz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3hKUVpJQ2VpVVF3WTlRcXhJIiwianN1OXlWdWx3UVFsaEZsTV8zSmx6TWFTRnpnbGhRRzBEcGZheVF3TFVLNCJdfX0sIl9zZF9hbGciOiJzaGEtMjU2In0";
15
+ const signature = "8wwSHCd47wCgzRYXvvPTTRXGS-hk9V8jRzy7WSjRBTZxSHxJkGOSWwBVAA-kpJ-IvQS7699aLWxIMqAvr34sOA";
16
+ const signed = `${unsigned}.${signature}`;
17
+ const tokenizedDisclosures = ["WyIyR0xDNDJzS1F2ZUNmR2ZyeU5STjl3IiwgImdpdmVuX25hbWUiLCAiSm9obiJd", "WyJlbHVWNU9nM2dTTklJOEVZbnN4QV9BIiwgImZhbWlseV9uYW1lIiwgIkRvZSJd", "WyI2SWo3dE0tYTVpVlBHYm9TNXRtdlZBIiwgImVtYWlsIiwgImpvaG5kb2VAZXhhbXBsZS5jb20iXQ", "WyJlSThaV205UW5LUHBOUGVOZW5IZGhRIiwgInBob25lX251bWJlciIsICIrMS0yMDItNTU1LTAxMDEiXQ", "WyJBSngtMDk1VlBycFR0TjRRTU9xUk9BIiwgImJpcnRoZGF0ZSIsICIxOTQwLTAxLTAxIl0", "WyJQYzMzSk0yTGNoY1VfbEhnZ3ZfdWZRIiwgImlzX292ZXJfMTgiLCB0cnVlXQ", "WyJHMDJOU3JRZmpGWFE3SW8wOXN5YWpBIiwgImlzX292ZXJfMjEiLCB0cnVlXQ", "WyJsa2x4RjVqTVlsR1RQVW92TU5JdkNBIiwgImlzX292ZXJfNjUiLCB0cnVlXQ", "WyJRZ19PNjR6cUF4ZTQxMmExMDhpcm9BIiwgImFkZHJlc3MiLCB7InN0cmVldF9hZGRyZXNzIjogIjEyMyBNYWluIFN0IiwgImxvY2FsaXR5IjogIkFueXRvd24iLCAicmVnaW9uIjogIkFueXN0YXRlIiwgImNvdW50cnkiOiAiVVMifV0"];
18
+ const sdJwt = {
19
+ header: {
20
+ typ: "vc+sd-jwt",
21
+ alg: "ES256",
22
+ kid: "b186ea0c1925793097bf01b8a289a45f",
23
+ trust_chain: ["NEhRdERpYnlHY3M5WldWTWZ2aUhm ...", "eyJhbGciOiJSUzI1NiIsImtpZCI6 ...", "IkJYdmZybG5oQU11SFIwN2FqVW1B ..."]
24
+ },
25
+ payload: {
26
+ iss: "https://example.com/issuer",
27
+ sub: "NzbLsXh8uDCcd7noWXFZAfHkxZsRGC9Xs...",
28
+ jti: "urn:uuid:6c5c0a49-b589-431d-bae7-219122a9ec2c",
29
+ iat: 1541493724,
30
+ exp: 1541493724,
31
+ status: "https://example.com/status",
32
+ cnf: {
33
+ jwk: {
34
+ kty: "RSA",
35
+ use: "sig",
36
+ n: "1Ta-sE",
37
+ e: "AQAB",
38
+ kid: "YhNFS3YnC9tjiCaivhWLVUJ3AxwGGz_98uRFaqMEEs"
39
+ }
40
+ },
41
+ type: "PersonIdentificationData",
42
+ verified_claims: {
43
+ verification: {
44
+ _sd: ["JzYjH4svliH0R3PyEMfeZu6Jt69u5qehZo7F7EPYlSE"],
45
+ trust_framework: "eidas",
46
+ assurance_level: "high"
47
+ },
48
+ claims: {
49
+ _sd: ["09vKrJMOlyTWM0sjpu_pdOBVBQ2M1y3KhpH515nXkpY", "2rsjGbaC0ky8mT0pJrPioWTq0_daw1sX76poUlgCwbI", "EkO8dhW0dHEJbvUHlE_VCeuC9uRELOieLZhh7XbUTtA", "IlDzIKeiZdDwpqpK6ZfbyphFvz5FgnWa-sN6wqQXCiw", "PorFbpKuVu6xymJagvkFsFXAbRoc2JGlAUA2BA4o7cI", "TGf4oLbgwd5JQaHyKVQZU9UdGE0w5rtDsrZzfUaomLo", "jdrTE8YcbY4EifugihiAe_BPekxJQZICeiUQwY9QqxI", "jsu9yVulwQQlhFlM_3JlzMaSFzglhQG0DpfayQwLUK4"]
50
+ }
51
+ },
52
+ _sd_alg: "sha-256"
53
+ }
54
+ };
55
+
56
+ // In the very same order than tokenizedDisclosures
57
+ const disclosures = [["2GLC42sKQveCfGfryNRN9w", "given_name", "John"], ["eluV5Og3gSNII8EYnsxA_A", "family_name", "Doe"], ["6Ij7tM-a5iVPGboS5tmvVA", "email", "johndoe@example.com"], ["eI8ZWm9QnKPpNPeNenHdhQ", "phone_number", "+1-202-555-0101"], ["AJx-095VPrpTtN4QMOqROA", "birthdate", "1940-01-01"], ["Pc33JM2LchcU_lHggv_ufQ", "is_over_18", true], ["G02NSrQfjFXQ7Io09syajA", "is_over_21", true], ["lklxF5jMYlGTPUovMNIvCA", "is_over_65", true], ["Qg_O64zqAxe412a108iroA", "address", {
58
+ street_address: "123 Main St",
59
+ locality: "Anytown",
60
+ region: "Anystate",
61
+ country: "US"
62
+ }]];
63
+ it("Ensures example data correctness", () => {
64
+ expect(JSON.parse(decodeBase64(encodeBase64(JSON.stringify(sdJwt.header))))).toEqual(sdJwt.header);
65
+ expect([signed, ...tokenizedDisclosures].join("~")).toBe(token);
66
+ });
67
+ describe("decode", () => {
68
+ it("should decode a valid token", () => {
69
+ const result = decode(token, SdJwt4VC);
70
+ expect(result).toEqual({
71
+ sdJwt,
72
+ disclosures: disclosures.map((decoded, i) => ({
73
+ decoded,
74
+ encoded: tokenizedDisclosures[i]
75
+ }))
76
+ });
77
+ });
78
+ });
79
+ describe("disclose", () => {
80
+ it("should encode a valid sdjwt (one claim)", async () => {
81
+ const result = await disclose(token, ["given_name"]);
82
+ const expected = {
83
+ token: `${signed}~WyIyR0xDNDJzS1F2ZUNmR2ZyeU5STjl3IiwgImdpdmVuX25hbWUiLCAiSm9obiJd`,
84
+ paths: [{
85
+ claim: "given_name",
86
+ path: "verified_claims.claims._sd[7]"
87
+ }]
88
+ };
89
+ expect(result).toEqual(expected);
90
+ });
91
+ it("should encode a valid sdjwt (no claims)", async () => {
92
+ const result = await disclose(token, []);
93
+ const expected = {
94
+ token: `${signed}`,
95
+ paths: []
96
+ };
97
+ expect(result).toEqual(expected);
98
+ });
99
+ it("should encode a valid sdjwt (multiple claims)", async () => {
100
+ const result = await disclose(token, ["given_name", "email"]);
101
+ const expected = {
102
+ token: `${signed}~WyIyR0xDNDJzS1F2ZUNmR2ZyeU5STjl3IiwgImdpdmVuX25hbWUiLCAiSm9obiJd~WyI2SWo3dE0tYTVpVlBHYm9TNXRtdlZBIiwgImVtYWlsIiwgImpvaG5kb2VAZXhhbXBsZS5jb20iXQ`,
103
+ paths: [{
104
+ claim: "given_name",
105
+ path: "verified_claims.claims._sd[7]"
106
+ }, {
107
+ claim: "email",
108
+ path: "verified_claims.verification._sd[0]"
109
+ }]
110
+ };
111
+ expect(result).toEqual(expected);
112
+ });
113
+ it("should fail on unknown claim", async () => {
114
+ const fn = async () => disclose(token, ["unknown"]);
115
+ await expect(fn()).rejects.toEqual(expect.any(Error));
116
+ });
117
+ });
118
+ //# sourceMappingURL=index.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["decode","disclose","encodeBase64","decodeBase64","SdJwt4VC","token","unsigned","signature","signed","tokenizedDisclosures","sdJwt","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","disclosures","street_address","locality","region","country","it","expect","JSON","parse","stringify","toEqual","join","toBe","describe","result","map","decoded","i","encoded","expected","paths","claim","path","fn","rejects","any","Error"],"sourceRoot":"../../../../src","sources":["sd-jwt/__test__/index.test.ts"],"mappings":"AAAA,SAASA,MAAM,EAAEC,QAAQ,QAAQ,UAAU;AAE3C,SAASC,YAAY,EAAEC,YAAY,QAAQ,6BAA6B;AACxE,SAASC,QAAQ,QAAQ,UAAU;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,KAAK,GACT,kvEAAkvE;AAEpvE,MAAMC,QAAQ,GACZ,87CAA87C;AAEh8C,MAAMC,SAAS,GACb,wFAAwF;AAE1F,MAAMC,MAAM,GAAI,GAAEF,QAAS,IAAGC,SAAU,EAAC;AAEzC,MAAME,oBAAoB,GAAG,CAC3B,kEAAkE,EAClE,kEAAkE,E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D,MAAMsC,MAAM,CAACiB,EAAE,CAAC,CAAC,CAAC,CAACC,OAAO,CAACd,OAAO,CAACJ,MAAM,CAACmB,GAAG,CAACC,KAAK,CAAC,CAAC;EACvD,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -1,8 +1,18 @@
1
1
  import { decode as decodeJwt } from "@pagopa/io-react-native-jwt";
2
2
  import { verify as verifyJwt } from "@pagopa/io-react-native-jwt";
3
+ import { sha256ToBase64 } from "@pagopa/io-react-native-jwt";
3
4
  import { decodeBase64 } from "@pagopa/io-react-native-jwt";
4
- import { Disclosure } from "./types";
5
+ import { Disclosure, SdJwt4VC } from "./types";
5
6
  import { verifyDisclosure } from "./verifier";
7
+ import { ClaimsNotFoundBetweenDislosures, ClaimsNotFoundInToken } from "../utils/errors";
8
+ const decodeDisclosure = encoded => {
9
+ const decoded = Disclosure.parse(JSON.parse(decodeBase64(encoded)));
10
+ return {
11
+ decoded,
12
+ encoded
13
+ };
14
+ };
15
+
6
16
  /**
7
17
  * Decode a given SD-JWT with Disclosures to get the parsed SD-JWT object they define.
8
18
  * It ensures provided data is in a valid shape.
@@ -35,13 +45,80 @@ export const decode = (token, schema) => {
35
45
  // get disclosures as list of triples
36
46
  // validate each triple
37
47
  // throw a validation error if at least one fails to parse
38
- const disclosures = rawDisclosures.map(decodeBase64).map(e => JSON.parse(e)).map(e => Disclosure.parse(e));
48
+ const disclosures = rawDisclosures.map(decodeDisclosure);
39
49
  return {
40
50
  sdJwt,
41
51
  disclosures
42
52
  };
43
53
  };
44
54
 
55
+ /**
56
+ * Select disclosures from a given SD-JWT with Disclosures.
57
+ * Claims relate with disclosures by their name.
58
+ *
59
+ * @function
60
+ * @param token The encoded token that represents a valid sd-jwt for verifiable credentials
61
+ * @param claims The list of claims to be disclosed
62
+ *
63
+ * @throws {ClaimsNotFoundBetweenDislosures} When one or more claims does not relate to any discloure.
64
+ * @throws {ClaimsNotFoundInToken} When one or more claims are not contained in the SD-JWT token.
65
+ * @returns The encoded token with only the requested disclosures, along with the path each claim can be found on the SD-JWT token
66
+ *
67
+ */
68
+ export const disclose = async (token, claims) => {
69
+ const [rawSdJwt, ...rawDisclosures] = token.split("~");
70
+ const {
71
+ sdJwt,
72
+ disclosures
73
+ } = decode(token, SdJwt4VC);
74
+
75
+ // for each claim, return the path on which they are located in the SD-JWT token
76
+ const paths = await Promise.all(claims.map(async claim => {
77
+ const disclosure = disclosures.find(_ref => {
78
+ let {
79
+ decoded: [, name]
80
+ } = _ref;
81
+ return name === claim;
82
+ });
83
+
84
+ // check every claim represents a known disclosure
85
+ if (!disclosure) {
86
+ throw new ClaimsNotFoundBetweenDislosures(claim);
87
+ }
88
+ const hash = await sha256ToBase64(disclosure.encoded);
89
+
90
+ // _sd is defined in verified_claims.claims and verified_claims.verification
91
+ // we must look into both
92
+ if (sdJwt.payload.verified_claims.claims._sd.includes(hash)) {
93
+ const index = sdJwt.payload.verified_claims.claims._sd.indexOf(hash);
94
+ return {
95
+ claim,
96
+ path: `verified_claims.claims._sd[${index}]`
97
+ };
98
+ } else if (sdJwt.payload.verified_claims.verification._sd.includes(hash)) {
99
+ const index = sdJwt.payload.verified_claims.verification._sd.indexOf(hash);
100
+ return {
101
+ claim,
102
+ path: `verified_claims.verification._sd[${index}]`
103
+ };
104
+ }
105
+ throw new ClaimsNotFoundInToken(claim);
106
+ }));
107
+ const filteredDisclosures = rawDisclosures.filter(d => {
108
+ const {
109
+ decoded: [, name]
110
+ } = decodeDisclosure(d);
111
+ return claims.includes(name);
112
+ });
113
+
114
+ // compose the final disclosed token
115
+ const disclosedToken = [rawSdJwt, ...filteredDisclosures].join("~");
116
+ return {
117
+ token: disclosedToken,
118
+ paths
119
+ };
120
+ };
121
+
45
122
  /**
46
123
  * Verify a given SD-JWT with Disclosures
47
124
  * Same as {@link decode} plus:
@@ -69,6 +146,9 @@ export const verify = async (token, publicKey, schema) => {
69
146
  //Check disclosures in sd-jwt
70
147
  const claims = [...decoded.sdJwt.payload.verified_claims.verification._sd, ...decoded.sdJwt.payload.verified_claims.claims._sd];
71
148
  await Promise.all(decoded.disclosures.map(async disclosure => await verifyDisclosure(disclosure, claims)));
72
- return decoded;
149
+ return {
150
+ sdJwt: decoded.sdJwt,
151
+ disclosures: decoded.disclosures.map(d => d.decoded)
152
+ };
73
153
  };
74
154
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["decode","decodeJwt","verify","verifyJwt","decodeBase64","Disclosure","verifyDisclosure","token","schema","slice","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;AACpC,SAASC,gBAAgB,QAAQ,YAAY;AAG7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMN,MAAM,GAAGA,CACpBO,KAAa,EACbC,MAAS,KAC4C;EACrD;EACA,IAAID,KAAK,CAACE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;IAC3BF,KAAK,GAAGA,KAAK,CAACE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;EAC5B;EACA,MAAM,CAACC,QAAQ,GAAG,EAAE,EAAE,GAAGC,cAAc,CAAC,GAAGJ,KAAK,CAACK,KAAK,CAAC,GAAG,CAAC;;EAE3D;EACA;EACA,MAAMC,UAAU,GAAGZ,SAAS,CAACS,QAAQ,CAAC;EACtC,MAAMI,KAAK,GAAGN,MAAM,CAACO,KAAK,CAAC;IACzBC,MAAM,EAAEH,UAAU,CAACI,eAAe;IAClCC,OAAO,EAAEL,UAAU,CAACK;EACtB,CAAC,CAAC;;EAEF;EACA;EACA;EACA,MAAMC,WAAW,GAAGR,cAAc,CAC/BS,GAAG,CAAChB,YAAY,CAAC,CACjBgB,GAAG,CAAEC,CAAC,IAAKC,IAAI,CAACP,KAAK,CAACM,CAAC,CAAC,CAAC,CACzBD,GAAG,CAAEC,CAAC,IAAKhB,UAAU,CAACU,KAAK,CAACM,CAAC,CAAC,CAAC;EAElC,OAAO;IAAEP,KAAK;IAAEK;EAAY,CAAC;AAC/B,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMjB,MAAM,GAAG,MAAAA,CACpBK,KAAa,EACbgB,SAAc,EACdf,MAAS,KACqD;EAC9D;EACA,MAAM,CAACE,QAAQ,GAAG,EAAE,CAAC,GAAGH,KAAK,CAACK,KAAK,CAAC,GAAG,CAAC;EACxC,MAAMY,OAAO,GAAGxB,MAAM,CAACO,KAAK,EAAEC,MAAM,CAAC;;EAErC;EACA,MAAML,SAAS,CAACO,QAAQ,EAAEa,SAAS,CAAC;;EAEpC;EACA,MAAME,MAAM,GAAG,CACb,GAAGD,OAAO,CAACV,KAAK,CAACI,OAAO,CAACQ,eAAe,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,MAAMzB,gBAAgB,CAACyB,UAAU,EAAEN,MAAM,CACjE,CACF,CAAC;EAED,OAAOD,OAAO;AAChB,CAAC"}
1
+ {"version":3,"names":["decode","decodeJwt","verify","verifyJwt","sha256ToBase64","decodeBase64","Disclosure","SdJwt4VC","verifyDisclosure","ClaimsNotFoundBetweenDislosures","ClaimsNotFoundInToken","decodeDisclosure","encoded","decoded","parse","JSON","token","schema","slice","rawSdJwt","rawDisclosures","split","decodedJwt","sdJwt","header","protectedHeader","payload","disclosures","map","disclose","claims","paths","Promise","all","claim","disclosure","find","_ref","name","hash","verified_claims","_sd","includes","index","indexOf","path","verification","filteredDisclosures","filter","d","disclosedToken","join","publicKey"],"sourceRoot":"../../../src","sources":["sd-jwt/index.ts"],"mappings":"AAEA,SAASA,MAAM,IAAIC,SAAS,QAAQ,6BAA6B;AACjE,SAASC,MAAM,IAAIC,SAAS,QAAQ,6BAA6B;AACjE,SAASC,cAAc,QAAQ,6BAA6B;AAE5D,SAASC,YAAY,QAAQ,6BAA6B;AAC1D,SAASC,UAAU,EAAEC,QAAQ,QAAoC,SAAS;AAC1E,SAASC,gBAAgB,QAAQ,YAAY;AAE7C,SACEC,+BAA+B,EAC/BC,qBAAqB,QAChB,iBAAiB;AAExB,MAAMC,gBAAgB,GAAIC,OAAe,IAA4B;EACnE,MAAMC,OAAO,GAAGP,UAAU,CAACQ,KAAK,CAACC,IAAI,CAACD,KAAK,CAACT,YAAY,CAACO,OAAO,CAAC,CAAC,CAAC;EACnE,OAAO;IAAEC,OAAO;IAAED;EAAQ,CAAC;AAC7B,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMZ,MAAM,GAAGA,CACpBgB,KAAa,EACbC,MAAS,KAIN;EACH;EACA,IAAID,KAAK,CAACE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;IAC3BF,KAAK,GAAGA,KAAK,CAACE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;EAC5B;EACA,MAAM,CAACC,QAAQ,GAAG,EAAE,EAAE,GAAGC,cAAc,CAAC,GAAGJ,KAAK,CAACK,KAAK,CAAC,GAAG,CAAC;;EAE3D;EACA;EACA,MAAMC,UAAU,GAAGrB,SAAS,CAACkB,QAAQ,CAAC;EACtC,MAAMI,KAAK,GAAGN,M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