@pagopa/io-react-native-wallet 0.11.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. package/lib/commonjs/client/generated/wallet-provider.js +126 -0
  2. package/lib/commonjs/client/generated/wallet-provider.js.map +1 -0
  3. package/lib/commonjs/client/index.js +40 -0
  4. package/lib/commonjs/client/index.js.map +1 -0
  5. package/lib/commonjs/credential/issuance/02-evaluate-issuer-trust.js +2 -1
  6. package/lib/commonjs/credential/issuance/02-evaluate-issuer-trust.js.map +1 -1
  7. package/lib/commonjs/credential/issuance/03-start-credential-issuance.js +287 -0
  8. package/lib/commonjs/credential/issuance/03-start-credential-issuance.js.map +1 -0
  9. package/lib/commonjs/credential/issuance/03-start-user-authorization.js +56 -83
  10. package/lib/commonjs/credential/issuance/03-start-user-authorization.js.map +1 -1
  11. package/lib/commonjs/credential/issuance/04-complete-user-authorization.js +88 -0
  12. package/lib/commonjs/credential/issuance/04-complete-user-authorization.js.map +1 -1
  13. package/lib/commonjs/credential/issuance/05-authorize-access.js +56 -33
  14. package/lib/commonjs/credential/issuance/05-authorize-access.js.map +1 -1
  15. package/lib/commonjs/credential/issuance/06-obtain-credential.js +51 -78
  16. package/lib/commonjs/credential/issuance/06-obtain-credential.js.map +1 -1
  17. package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js +21 -44
  18. package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
  19. package/lib/commonjs/credential/issuance/index.js +7 -0
  20. package/lib/commonjs/credential/issuance/index.js.map +1 -1
  21. package/lib/commonjs/credential/issuance/types.js +28 -0
  22. package/lib/commonjs/credential/issuance/types.js.map +1 -0
  23. package/lib/commonjs/index.js +10 -1
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/pid/sd-jwt/converters.js +5 -9
  26. package/lib/commonjs/pid/sd-jwt/converters.js.map +1 -1
  27. package/lib/commonjs/pid/sd-jwt/types.js +3 -3
  28. package/lib/commonjs/pid/sd-jwt/types.js.map +1 -1
  29. package/lib/commonjs/sd-jwt/__test__/converters.test.js +1 -1
  30. package/lib/commonjs/sd-jwt/__test__/converters.test.js.map +1 -1
  31. package/lib/commonjs/sd-jwt/__test__/index.test.js +30 -43
  32. package/lib/commonjs/sd-jwt/__test__/index.test.js.map +1 -1
  33. package/lib/commonjs/sd-jwt/__test__/types.test.js +16 -24
  34. package/lib/commonjs/sd-jwt/__test__/types.test.js.map +1 -1
  35. package/lib/commonjs/sd-jwt/index.js +3 -9
  36. package/lib/commonjs/sd-jwt/index.js.map +1 -1
  37. package/lib/commonjs/sd-jwt/types.js +11 -16
  38. package/lib/commonjs/sd-jwt/types.js.map +1 -1
  39. package/lib/commonjs/trust/types.js +70 -29
  40. package/lib/commonjs/trust/types.js.map +1 -1
  41. package/lib/commonjs/utils/auth.js +44 -0
  42. package/lib/commonjs/utils/auth.js.map +1 -0
  43. package/lib/commonjs/utils/errors.js +104 -1
  44. package/lib/commonjs/utils/errors.js.map +1 -1
  45. package/lib/commonjs/utils/integrity.js +2 -0
  46. package/lib/commonjs/utils/integrity.js.map +1 -0
  47. package/lib/commonjs/utils/misc.js +34 -1
  48. package/lib/commonjs/utils/misc.js.map +1 -1
  49. package/lib/commonjs/utils/par.js +23 -15
  50. package/lib/commonjs/utils/par.js.map +1 -1
  51. package/lib/commonjs/utils/pop.js +33 -0
  52. package/lib/commonjs/utils/pop.js.map +1 -0
  53. package/lib/commonjs/wallet-instance/index.js +29 -0
  54. package/lib/commonjs/wallet-instance/index.js.map +1 -0
  55. package/lib/commonjs/wallet-instance-attestation/issuing.js +62 -65
  56. package/lib/commonjs/wallet-instance-attestation/issuing.js.map +1 -1
  57. package/lib/commonjs/wallet-instance-attestation/types.js +8 -8
  58. package/lib/commonjs/wallet-instance-attestation/types.js.map +1 -1
  59. package/lib/module/client/generated/wallet-provider.js +102 -0
  60. package/lib/module/client/generated/wallet-provider.js.map +1 -0
  61. package/lib/module/client/index.js +33 -0
  62. package/lib/module/client/index.js.map +1 -0
  63. package/lib/module/credential/issuance/02-evaluate-issuer-trust.js +2 -1
  64. package/lib/module/credential/issuance/02-evaluate-issuer-trust.js.map +1 -1
  65. package/lib/module/credential/issuance/03-start-credential-issuance.js +276 -0
  66. package/lib/module/credential/issuance/03-start-credential-issuance.js.map +1 -0
  67. package/lib/module/credential/issuance/03-start-user-authorization.js +56 -80
  68. package/lib/module/credential/issuance/03-start-user-authorization.js.map +1 -1
  69. package/lib/module/credential/issuance/04-complete-user-authorization.js +85 -1
  70. package/lib/module/credential/issuance/04-complete-user-authorization.js.map +1 -1
  71. package/lib/module/credential/issuance/05-authorize-access.js +54 -33
  72. package/lib/module/credential/issuance/05-authorize-access.js.map +1 -1
  73. package/lib/module/credential/issuance/06-obtain-credential.js +50 -75
  74. package/lib/module/credential/issuance/06-obtain-credential.js.map +1 -1
  75. package/lib/module/credential/issuance/07-verify-and-parse-credential.js +21 -44
  76. package/lib/module/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
  77. package/lib/module/credential/issuance/index.js +2 -1
  78. package/lib/module/credential/issuance/index.js.map +1 -1
  79. package/lib/module/credential/issuance/types.js +18 -0
  80. package/lib/module/credential/issuance/types.js.map +1 -0
  81. package/lib/module/index.js +3 -1
  82. package/lib/module/index.js.map +1 -1
  83. package/lib/module/pid/sd-jwt/converters.js +5 -9
  84. package/lib/module/pid/sd-jwt/converters.js.map +1 -1
  85. package/lib/module/pid/sd-jwt/types.js +3 -3
  86. package/lib/module/pid/sd-jwt/types.js.map +1 -1
  87. package/lib/module/sd-jwt/__test__/converters.test.js +1 -1
  88. package/lib/module/sd-jwt/__test__/converters.test.js.map +1 -1
  89. package/lib/module/sd-jwt/__test__/index.test.js +30 -43
  90. package/lib/module/sd-jwt/__test__/index.test.js.map +1 -1
  91. package/lib/module/sd-jwt/__test__/types.test.js +16 -24
  92. package/lib/module/sd-jwt/__test__/types.test.js.map +1 -1
  93. package/lib/module/sd-jwt/index.js +3 -9
  94. package/lib/module/sd-jwt/index.js.map +1 -1
  95. package/lib/module/sd-jwt/types.js +11 -16
  96. package/lib/module/sd-jwt/types.js.map +1 -1
  97. package/lib/module/trust/types.js +70 -29
  98. package/lib/module/trust/types.js.map +1 -1
  99. package/lib/module/utils/auth.js +35 -0
  100. package/lib/module/utils/auth.js.map +1 -0
  101. package/lib/module/utils/errors.js +98 -0
  102. package/lib/module/utils/errors.js.map +1 -1
  103. package/lib/module/utils/integrity.js +2 -0
  104. package/lib/module/utils/integrity.js.map +1 -0
  105. package/lib/module/utils/misc.js +31 -0
  106. package/lib/module/utils/misc.js.map +1 -1
  107. package/lib/module/utils/par.js +24 -16
  108. package/lib/module/utils/par.js.map +1 -1
  109. package/lib/module/utils/pop.js +24 -0
  110. package/lib/module/utils/pop.js.map +1 -0
  111. package/lib/module/wallet-instance/index.js +23 -0
  112. package/lib/module/wallet-instance/index.js.map +1 -0
  113. package/lib/module/wallet-instance-attestation/issuing.js +63 -67
  114. package/lib/module/wallet-instance-attestation/issuing.js.map +1 -1
  115. package/lib/module/wallet-instance-attestation/types.js +8 -8
  116. package/lib/module/wallet-instance-attestation/types.js.map +1 -1
  117. package/lib/typescript/client/generated/wallet-provider.d.ts +264 -0
  118. package/lib/typescript/client/generated/wallet-provider.d.ts.map +1 -0
  119. package/lib/typescript/client/index.d.ts +7 -0
  120. package/lib/typescript/client/index.d.ts.map +1 -0
  121. package/lib/typescript/credential/issuance/01-start-flow.d.ts +1 -0
  122. package/lib/typescript/credential/issuance/01-start-flow.d.ts.map +1 -1
  123. package/lib/typescript/credential/issuance/02-evaluate-issuer-trust.d.ts +2 -1
  124. package/lib/typescript/credential/issuance/02-evaluate-issuer-trust.d.ts.map +1 -1
  125. package/lib/typescript/credential/issuance/03-start-credential-issuance.d.ts +41 -0
  126. package/lib/typescript/credential/issuance/03-start-credential-issuance.d.ts.map +1 -0
  127. package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts +23 -18
  128. package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts.map +1 -1
  129. package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts +24 -12
  130. package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts.map +1 -1
  131. package/lib/typescript/credential/issuance/05-authorize-access.d.ts +22 -16
  132. package/lib/typescript/credential/issuance/05-authorize-access.d.ts.map +1 -1
  133. package/lib/typescript/credential/issuance/06-obtain-credential.d.ts +19 -26
  134. package/lib/typescript/credential/issuance/06-obtain-credential.d.ts.map +1 -1
  135. package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts +10 -15
  136. package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts.map +1 -1
  137. package/lib/typescript/credential/issuance/index.d.ts +3 -4
  138. package/lib/typescript/credential/issuance/index.d.ts.map +1 -1
  139. package/lib/typescript/credential/issuance/types.d.ts +63 -0
  140. package/lib/typescript/credential/issuance/types.d.ts.map +1 -0
  141. package/lib/typescript/credential/presentation/types.d.ts +6 -6
  142. package/lib/typescript/index.d.ts +6 -1
  143. package/lib/typescript/index.d.ts.map +1 -1
  144. package/lib/typescript/pid/sd-jwt/converters.d.ts.map +1 -1
  145. package/lib/typescript/pid/sd-jwt/types.d.ts +36 -36
  146. package/lib/typescript/pid/sd-jwt/types.d.ts.map +1 -1
  147. package/lib/typescript/sd-jwt/index.d.ts +40 -68
  148. package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
  149. package/lib/typescript/sd-jwt/types.d.ts +64 -121
  150. package/lib/typescript/sd-jwt/types.d.ts.map +1 -1
  151. package/lib/typescript/trust/index.d.ts +150 -48
  152. package/lib/typescript/trust/index.d.ts.map +1 -1
  153. package/lib/typescript/trust/types.d.ts +2838 -1740
  154. package/lib/typescript/trust/types.d.ts.map +1 -1
  155. package/lib/typescript/utils/auth.d.ts +52 -0
  156. package/lib/typescript/utils/auth.d.ts.map +1 -0
  157. package/lib/typescript/utils/errors.d.ts +48 -0
  158. package/lib/typescript/utils/errors.d.ts.map +1 -1
  159. package/lib/typescript/utils/integrity.d.ts +21 -0
  160. package/lib/typescript/utils/integrity.d.ts.map +1 -0
  161. package/lib/typescript/utils/misc.d.ts +18 -0
  162. package/lib/typescript/utils/misc.d.ts.map +1 -1
  163. package/lib/typescript/utils/par.d.ts +8 -31
  164. package/lib/typescript/utils/par.d.ts.map +1 -1
  165. package/lib/typescript/utils/pop.d.ts +26 -0
  166. package/lib/typescript/utils/pop.d.ts.map +1 -0
  167. package/lib/typescript/wallet-instance/index.d.ts +7 -0
  168. package/lib/typescript/wallet-instance/index.d.ts.map +1 -0
  169. package/lib/typescript/wallet-instance-attestation/issuing.d.ts +17 -4
  170. package/lib/typescript/wallet-instance-attestation/issuing.d.ts.map +1 -1
  171. package/lib/typescript/wallet-instance-attestation/types.d.ts +64 -64
  172. package/lib/typescript/wallet-instance-attestation/types.d.ts.map +1 -1
  173. package/package.json +9 -5
  174. package/src/client/generated/wallet-provider.ts +173 -0
  175. package/src/client/index.ts +53 -0
  176. package/src/credential/issuance/01-start-flow.ts +1 -0
  177. package/src/credential/issuance/02-evaluate-issuer-trust.ts +2 -1
  178. package/src/credential/issuance/03-start-credential-issuance.ts +407 -0
  179. package/src/credential/issuance/03-start-user-authorization.ts +91 -92
  180. package/src/credential/issuance/04-complete-user-authorization.ts +114 -13
  181. package/src/credential/issuance/05-authorize-access.ts +74 -49
  182. package/src/credential/issuance/06-obtain-credential.ts +77 -111
  183. package/src/credential/issuance/07-verify-and-parse-credential.ts +30 -67
  184. package/src/credential/issuance/index.ts +6 -4
  185. package/src/credential/issuance/types.ts +25 -0
  186. package/src/index.ts +8 -0
  187. package/src/pid/sd-jwt/converters.ts +5 -11
  188. package/src/pid/sd-jwt/types.ts +8 -6
  189. package/src/sd-jwt/__test__/converters.test.ts +1 -1
  190. package/src/sd-jwt/__test__/index.test.ts +45 -74
  191. package/src/sd-jwt/__test__/types.test.ts +21 -33
  192. package/src/sd-jwt/index.ts +3 -12
  193. package/src/sd-jwt/types.ts +17 -22
  194. package/src/trust/types.ts +64 -32
  195. package/src/utils/auth.ts +37 -0
  196. package/src/utils/errors.ts +112 -0
  197. package/src/utils/integrity.ts +23 -0
  198. package/src/utils/misc.ts +43 -0
  199. package/src/utils/par.ts +29 -17
  200. package/src/utils/pop.ts +34 -0
  201. package/src/wallet-instance/index.ts +29 -0
  202. package/src/wallet-instance-attestation/issuing.ts +101 -97
  203. package/src/wallet-instance-attestation/types.ts +12 -8
  204. package/lib/commonjs/credential/issuance/07-confirm-credential.js +0 -6
  205. package/lib/commonjs/credential/issuance/07-confirm-credential.js.map +0 -1
  206. package/lib/commonjs/credential/issuance/08-confirm-credential.js +0 -6
  207. package/lib/commonjs/credential/issuance/08-confirm-credential.js.map +0 -1
  208. package/lib/module/credential/issuance/07-confirm-credential.js +0 -2
  209. package/lib/module/credential/issuance/07-confirm-credential.js.map +0 -1
  210. package/lib/module/credential/issuance/08-confirm-credential.js +0 -2
  211. package/lib/module/credential/issuance/08-confirm-credential.js.map +0 -1
  212. package/lib/typescript/credential/issuance/07-confirm-credential.d.ts +0 -11
  213. package/lib/typescript/credential/issuance/07-confirm-credential.d.ts.map +0 -1
  214. package/lib/typescript/credential/issuance/08-confirm-credential.d.ts +0 -11
  215. package/lib/typescript/credential/issuance/08-confirm-credential.d.ts.map +0 -1
  216. package/src/credential/issuance/07-confirm-credential.ts +0 -14
  217. package/src/credential/issuance/08-confirm-credential.ts +0 -14
@@ -1,11 +1,11 @@
1
1
  import type { Out } from "../../utils/misc";
2
2
  import type { EvaluateIssuerTrust } from "./02-evaluate-issuer-trust";
3
- import type { ObtainCredential } from "./06-obtain-credential";
4
3
  import { IoWalletError } from "../../utils/errors";
5
4
  import { SdJwt4VC } from "../../sd-jwt/types";
6
5
  import { verify as verifySdJwt } from "../../sd-jwt";
7
6
  import type { JWK } from "../../utils/jwk";
8
7
  import type { CryptoContext } from "@pagopa/io-react-native-jwt";
8
+ import type { ObtainCredential } from "./06-obtain-credential";
9
9
 
10
10
  export type VerifyAndParseCredential = (
11
11
  issuerConf: Out<EvaluateIssuerTrust>["issuerConf"],
@@ -13,7 +13,6 @@ export type VerifyAndParseCredential = (
13
13
  format: Out<ObtainCredential>["format"],
14
14
  context: {
15
15
  credentialCryptoContext: CryptoContext;
16
- ignoreMissingAttributes?: boolean;
17
16
  }
18
17
  ) => Promise<{ parsedCredential: ParsedCredential }>;
19
18
 
@@ -28,9 +27,8 @@ type ParsedCredential = Record<
28
27
  string /* locale */,
29
28
  string /* value */
30
29
  >
31
- | /* if no i18n is provided */ string;
32
- /** If in defined as mandatory by the Issuer */
33
- mandatory: boolean;
30
+ | /* if no i18n is provided */ string
31
+ | undefined; // Add undefined as a possible value for the name property
34
32
  /** The actual value of the attribute */
35
33
  value: unknown;
36
34
  }
@@ -43,48 +41,34 @@ type DecodedSdJwtCredential = Out<typeof verifySdJwt> & {
43
41
 
44
42
  const parseCredentialSdJwt = (
45
43
  // the list of supported credentials, as defined in the issuer configuration
46
- credentials_supported: Out<EvaluateIssuerTrust>["issuerConf"]["openid_credential_issuer"]["credentials_supported"],
47
- { sdJwt, disclosures }: DecodedSdJwtCredential,
48
- ignoreMissingAttributes: boolean = false
44
+ credentials_supported: Out<EvaluateIssuerTrust>["issuerConf"]["openid_credential_issuer"]["credential_configurations_supported"],
45
+ { sdJwt, disclosures }: DecodedSdJwtCredential
49
46
  ): ParsedCredential => {
50
- // find the definition that matches the received credential's type
51
- // warning: if more then a defintion is found, the first is retrieved
52
- const credentialSubject = credentials_supported.find(
53
- (c) =>
54
- c.format === "vc+sd-jwt" &&
55
- c.credential_definition.type.includes(sdJwt.payload.type)
56
- )?.credential_definition.credentialSubject;
57
-
58
- // the received credential matches no supported credential, throw an exception
47
+ const credentialSubject = credentials_supported[sdJwt.payload.vct];
48
+
59
49
  if (!credentialSubject) {
60
- const expected = credentials_supported
61
- .flatMap((_) => _.credential_definition.type)
62
- .join(", ");
50
+ throw new IoWalletError("Credential type not supported by the issuer");
51
+ }
52
+
53
+ if (credentialSubject.format !== sdJwt.header.typ) {
63
54
  throw new IoWalletError(
64
- `Received credential is of an unknwown type. Expected one of [${expected}], received '${sdJwt.payload.type}', `
55
+ `Received credential is of an unknwown type. Expected one of [${credentialSubject.format}], received '${sdJwt.header.typ}', `
65
56
  );
66
57
  }
67
58
 
68
59
  // transfrom a record { key: value } in an iterable of pairs [key, value]
69
- const attrDefinitions = Object.entries(credentialSubject);
60
+ const attrDefinitions = Object.entries(credentialSubject.claims);
70
61
 
71
- // every mandatory attribute must be present in the credential's disclosures
72
62
  // the key of the attribute defintion must match the disclosure's name
73
63
  const attrsNotInDisclosures = attrDefinitions.filter(
74
- ([attrKey, { mandatory }]) =>
75
- mandatory && !disclosures.some(([, name]) => name === attrKey)
64
+ ([attrKey]) => !disclosures.some(([, name]) => name === attrKey)
76
65
  );
77
66
  if (attrsNotInDisclosures.length > 0) {
78
67
  const missing = attrsNotInDisclosures.map((_) => _[0 /* key */]).join(", ");
79
68
  const received = disclosures.map((_) => _[1 /* name */]).join(", ");
80
- // the rationale of this condition is that we may want to be permissive
81
- // on incomplete credentials in the test phase of the project.
82
- // we might want to be strict once in production, hence remove this condition
83
- if (!ignoreMissingAttributes) {
84
- throw new IoWalletError(
85
- `Some attributes are missing in the credential. Missing: [${missing}], received: [${received}]`
86
- );
87
- }
69
+ throw new IoWalletError(
70
+ `Some attributes are missing in the credential. Missing: [${missing}], received: [${received}]`
71
+ );
88
72
  }
89
73
 
90
74
  // attributes that are defined in the issuer configuration
@@ -126,7 +110,7 @@ const parseCredentialSdJwt = (
126
110
  const undefinedValues = Object.fromEntries(
127
111
  disclosures
128
112
  .filter((_) => !Object.keys(definedValues).includes(_[1]))
129
- .map(([, key, value]) => [key, { value, mandatory: false, name: key }])
113
+ .map(([, key, value]) => [key, { value, name: key }])
130
114
  );
131
115
 
132
116
  return {
@@ -185,7 +169,7 @@ const verifyAndParseCredentialSdJwt: WithFormat<"vc+sd-jwt"> = async (
185
169
  issuerConf,
186
170
  credential,
187
171
  _,
188
- { credentialCryptoContext, ignoreMissingAttributes }
172
+ { credentialCryptoContext }
189
173
  ) => {
190
174
  const decoded = await verifyCredentialSdJwt(
191
175
  credential,
@@ -194,36 +178,23 @@ const verifyAndParseCredentialSdJwt: WithFormat<"vc+sd-jwt"> = async (
194
178
  );
195
179
 
196
180
  const parsedCredential = parseCredentialSdJwt(
197
- issuerConf.openid_credential_issuer.credentials_supported,
198
- decoded,
199
- ignoreMissingAttributes
181
+ issuerConf.openid_credential_issuer.credential_configurations_supported,
182
+ decoded
200
183
  );
201
184
 
202
185
  return { parsedCredential };
203
186
  };
204
187
 
205
- const verifyAndParseCredentialMdoc: WithFormat<"vc+mdoc-cbor"> = async (
206
- _issuerConf,
207
- _credential,
208
- _,
209
- _ctx
210
- ) => {
211
- // TODO: [SIW-686] decode MDOC credentials
212
- throw new Error("verifyAndParseCredentialMdoc not implemented yet");
213
- };
214
-
215
188
  /**
216
- * Verify and parse an encoded credential
217
- *
218
- * @param issuerConf The Issuer configuration
219
- * @param credential The encoded credential
220
- * @param format The format of the credentual
221
- * @param context.credentialCryptoContext The context to access the key the Credential will be bound to
222
- * @param context.ignoreMissingAttributes (optional) Whether to fail if a defined attribute is note present in the credentual. Default: false
189
+ * Verify and parse an encoded credential.
190
+ * @param issuerConf The Issuer configuration returned by {@link evaluateIssuerTrust}
191
+ * @param credential The encoded credential returned by {@link obtainCredential}
192
+ * @param format The format of the credentual returned by {@link obtainCredential}
193
+ * @param context.credentialCryptoContext The crypto context used to obtain the credential in {@link obtainCredential}
223
194
  * @returns A parsed credential with attributes in plain value
224
- * @throws If the credential signature is not verified with the Issuer key set
225
- * @throws If the credential is not bound to the provided user key
226
- * @throws If the credential data fail to parse
195
+ * @throws {IoWalletError} If the credential signature is not verified with the Issuer key set
196
+ * @throws {IoWalletError} If the credential is not bound to the provided user key
197
+ * @throws {IoWalletError} If the credential data fail to parse
227
198
  */
228
199
  export const verifyAndParseCredential: VerifyAndParseCredential = async (
229
200
  issuerConf,
@@ -238,15 +209,7 @@ export const verifyAndParseCredential: VerifyAndParseCredential = async (
238
209
  format,
239
210
  context
240
211
  );
241
- } else if (format === "vc+mdoc-cbor") {
242
- return verifyAndParseCredentialMdoc(
243
- issuerConf,
244
- credential,
245
- format,
246
- context
247
- );
248
212
  }
249
213
 
250
- const _: never = format;
251
- throw new IoWalletError(`Unsupported credential format: ${_}`);
214
+ throw new IoWalletError(`Unsupported credential format: ${format}`);
252
215
  };
@@ -7,7 +7,10 @@ import {
7
7
  startUserAuthorization,
8
8
  type StartUserAuthorization,
9
9
  } from "./03-start-user-authorization";
10
- import { type CompleteUserAuthorization } from "./04-complete-user-authorization";
10
+ import {
11
+ completeUserAuthorizationWithQueryMode,
12
+ type CompleteUserAuthorizationWithQueryMode,
13
+ } from "./04-complete-user-authorization";
11
14
  import { authorizeAccess, type AuthorizeAccess } from "./05-authorize-access";
12
15
  import {
13
16
  obtainCredential,
@@ -17,11 +20,11 @@ import {
17
20
  verifyAndParseCredential,
18
21
  type VerifyAndParseCredential,
19
22
  } from "./07-verify-and-parse-credential";
20
- import type { ConfirmCredential } from "./08-confirm-credential";
21
23
 
22
24
  export {
23
25
  evaluateIssuerTrust,
24
26
  startUserAuthorization,
27
+ completeUserAuthorizationWithQueryMode,
25
28
  authorizeAccess,
26
29
  obtainCredential,
27
30
  verifyAndParseCredential,
@@ -30,9 +33,8 @@ export type {
30
33
  StartFlow,
31
34
  EvaluateIssuerTrust,
32
35
  StartUserAuthorization,
33
- CompleteUserAuthorization,
36
+ CompleteUserAuthorizationWithQueryMode,
34
37
  AuthorizeAccess,
35
38
  ObtainCredential,
36
39
  VerifyAndParseCredential,
37
- ConfirmCredential,
38
40
  };
@@ -0,0 +1,25 @@
1
+ import { AuthorizationDetail } from "../../utils/par";
2
+ import * as z from "zod";
3
+ import { SupportedCredentialFormat } from "./const";
4
+
5
+ export type TokenResponse = z.infer<typeof TokenResponse>;
6
+
7
+ export const TokenResponse = z.object({
8
+ access_token: z.string(),
9
+ authorization_details: z.array(AuthorizationDetail),
10
+ c_nonce: z.string(),
11
+ c_nonce_expires_in: z.number(),
12
+ expires_in: z.number(),
13
+ token_type: z.string(),
14
+ });
15
+
16
+ export type CredentialResponse = z.infer<typeof CredentialResponse>;
17
+
18
+ export const CredentialResponse = z.object({
19
+ c_nonce: z.string(),
20
+ c_nonce_expires_in: z.number(),
21
+ credential: z.string(),
22
+ format: SupportedCredentialFormat,
23
+ });
24
+
25
+ export type ResponseMode = "query" | "form_post.jwt";
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { AuthorizationContext } from "./utils/auth";
2
+ import { fixBase64EncodingOnKey } from "./utils/jwk";
1
3
  // polyfill due to known bugs on URL implementation for react native
2
4
  // https://github.com/facebook/react-native/issues/24428
3
5
  import "react-native-url-polyfill/auto";
@@ -8,17 +10,23 @@ import * as SdJwt from "./sd-jwt";
8
10
  import * as Errors from "./utils/errors";
9
11
  import * as WalletInstanceAttestation from "./wallet-instance-attestation";
10
12
  import * as Trust from "./trust";
13
+ import * as WalletInstance from "./wallet-instance";
11
14
  import { AuthorizationDetail, AuthorizationDetails } from "./utils/par";
12
15
  import { createCryptoContextFor } from "./utils/crypto";
16
+ import type { IntegrityContext } from "./utils/integrity";
13
17
 
14
18
  export {
15
19
  SdJwt,
16
20
  PID,
17
21
  Credential,
18
22
  WalletInstanceAttestation,
23
+ WalletInstance,
19
24
  Errors,
20
25
  Trust,
21
26
  createCryptoContextFor,
22
27
  AuthorizationDetail,
23
28
  AuthorizationDetails,
29
+ fixBase64EncodingOnKey,
24
30
  };
31
+
32
+ export type { IntegrityContext, AuthorizationContext };
@@ -3,24 +3,18 @@ import type { Disclosure, SdJwt4VC } from "../../sd-jwt/types";
3
3
  import { PID } from "./types";
4
4
 
5
5
  export function pidFromToken(sdJwt: SdJwt4VC, disclosures: Disclosure[]): PID {
6
+ const placeOfBirth = getValueFromDisclosures(disclosures, "place_of_birth");
6
7
  return PID.parse({
7
8
  issuer: sdJwt.payload.iss,
8
- issuedAt: new Date(sdJwt.payload.iat * 1000),
9
+ issuedAt: new Date(getValueFromDisclosures(disclosures, "iat") * 1000),
9
10
  expiration: new Date(sdJwt.payload.exp * 1000),
10
- verification: {
11
- trustFramework:
12
- sdJwt.payload.verified_claims.verification.trust_framework,
13
- assuranceLevel:
14
- sdJwt.payload.verified_claims.verification.assurance_level,
15
- evidence: getValueFromDisclosures(disclosures, "evidence"),
16
- },
17
11
  claims: {
18
12
  uniqueId: getValueFromDisclosures(disclosures, "unique_id"),
19
13
  givenName: getValueFromDisclosures(disclosures, "given_name"),
20
14
  familyName: getValueFromDisclosures(disclosures, "family_name"),
21
- birthdate: getValueFromDisclosures(disclosures, "birthdate"),
22
- placeOfBirth: getValueFromDisclosures(disclosures, "place_of_birth"),
23
- taxIdCode: getValueFromDisclosures(disclosures, "tax_id_number"),
15
+ birthDate: getValueFromDisclosures(disclosures, "birth_date"),
16
+ ...(placeOfBirth && placeOfBirth),
17
+ taxIdCode: getValueFromDisclosures(disclosures, "tax_id_code"),
24
18
  },
25
19
  });
26
20
  }
@@ -29,16 +29,18 @@ export const PID = z.object({
29
29
  issuer: z.string(),
30
30
  issuedAt: z.date(),
31
31
  expiration: z.date(),
32
- verification: Verification,
32
+ verification: Verification.optional(),
33
33
  claims: z.object({
34
34
  uniqueId: z.string(),
35
35
  givenName: z.string(),
36
36
  familyName: z.string(),
37
- birthdate: z.string(),
38
- placeOfBirth: z.object({
39
- country: z.string(),
40
- locality: z.string(),
41
- }),
37
+ birthDate: z.string(),
38
+ placeOfBirth: z
39
+ .object({
40
+ country: z.string(),
41
+ locality: z.string(),
42
+ })
43
+ .optional(),
42
44
  taxIdCode: z.string(),
43
45
  }),
44
46
  });
@@ -3,7 +3,7 @@ import { Disclosure } from "../types";
3
3
 
4
4
  const disclosures: Disclosure[] = [
5
5
  ["6w1_soRXFgaHKfpYn3cvfQ", "given_name", "Mario"],
6
- ["fuNp97Hf3wV6y48y-QZhIg", "birthdate", "1980-10-01"],
6
+ ["fuNp97Hf3wV6y48y-QZhIg", "birth_date", "1980-10-01"],
7
7
  [
8
8
  "p-9LzyWHZBVDvhXDWkN2xA",
9
9
  "place_of_birth",
@@ -13,99 +13,70 @@ import { SdJwt4VC } from "../types";
13
13
  // - "address" is used as verification._sd
14
14
  // - all others disclosures are in claims._sd
15
15
  const token =
16
- "eyJ0eXAiOiJ2YytzZC1qd3QiLCJhbGciOiJFUzI1NiIsImtpZCI6ImIxODZlYTBjMTkyNTc5MzA5N2JmMDFiOGEyODlhNDVmIiwidHJ1c3RfY2hhaW4iOlsiTkVoUmRFUnBZbmxIWTNNNVdsZFdUV1oyYVVobSAuLi4iLCJleUpoYkdjaU9pSlNVekkxTmlJc0ltdHBaQ0k2IC4uLiIsIklrSllkbVp5Ykc1b1FVMTFTRkl3TjJGcVZXMUIgLi4uIl19.eyJpc3MiOiJodHRwczovL2V4YW1wbGUuY29tL2lzc3VlciIsInN1YiI6Ik56YkxzWGg4dURDY2Q3bm9XWEZaQWZIa3hac1JHQzlYcy4uLiIsImp0aSI6InVybjp1dWlkOjZjNWMwYTQ5LWI1ODktNDMxZC1iYWU3LTIxOTEyMmE5ZWMyYyIsImlhdCI6MTU0MTQ5MzcyNCwiZXhwIjoxNTQxNDkzNzI0LCJzdGF0dXMiOiJodHRwczovL2V4YW1wbGUuY29tL3N0YXR1cyIsImNuZiI6eyJqd2siOnsia3R5IjoiUlNBIiwidXNlIjoic2lnIiwibiI6IjFUYS1zRSIsImUiOiJBUUFCIiwia2lkIjoiWWhORlMzWW5DOXRqaUNhaXZoV0xWVUozQXh3R0d6Xzk4dVJGYXFNRUVzIn19LCJ0eXBlIjoiUGVyc29uSWRlbnRpZmljYXRpb25EYXRhIiwidmVyaWZpZWRfY2xhaW1zIjp7InZlcmlmaWNhdGlvbiI6eyJfc2QiOlsiSnpZakg0c3ZsaUgwUjNQeUVNZmVadTZKdDY5dTVxZWhabzdGN0VQWWxTRSJdLCJ0cnVzdF9mcmFtZXdvcmsiOiJlaWRhcyIsImFzc3VyYW5jZV9sZXZlbCI6ImhpZ2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ieSI6ImVFaFZ2ZzFKUHFOZDNEVFNhNG1HREdCbHdZNk5QLUVaYkxiTkZYU1h3SWcifX0sImV4cCI6MTc1MTU0NjU3Niwic3RhdHVzIjp7InN0YXR1c19hdHRlc3RhdGlvbiI6eyJjcmVkZW50aWFsX2hhc2hfYWxnIjoic2hhLTI1NiJ9fX0";
20
20
 
21
21
  const signature =
22
- "8wwSHCd47wCgzRYXvvPTTRXGS-hk9V8jRzy7WSjRBTZxSHxJkGOSWwBVAA-kpJ-IvQS7699aLWxIMqAvr34sOA";
22
+ "qXHA2oqr8trX4fGxpxpUft2GX380TM3pzfo1MYAsDjUC8HsODA-4rdRWAvDe2zYP57x4tJU7eiABkd1Kmln9yQ";
23
23
 
24
24
  const signed = `${unsigned}.${signature}`;
25
25
 
26
26
  const tokenizedDisclosures = [
27
- "WyIyR0xDNDJzS1F2ZUNmR2ZyeU5STjl3IiwgImdpdmVuX25hbWUiLCAiSm9obiJd",
28
- "WyJlbHVWNU9nM2dTTklJOEVZbnN4QV9BIiwgImZhbWlseV9uYW1lIiwgIkRvZSJd",
29
- "WyI2SWo3dE0tYTVpVlBHYm9TNXRtdlZBIiwgImVtYWlsIiwgImpvaG5kb2VAZXhhbXBsZS5jb20iXQ",
30
- "WyJlSThaV205UW5LUHBOUGVOZW5IZGhRIiwgInBob25lX251bWJlciIsICIrMS0yMDItNTU1LTAxMDEiXQ",
31
- "WyJBSngtMDk1VlBycFR0TjRRTU9xUk9BIiwgImJpcnRoZGF0ZSIsICIxOTQwLTAxLTAxIl0",
32
- "WyJQYzMzSk0yTGNoY1VfbEhnZ3ZfdWZRIiwgImlzX292ZXJfMTgiLCB0cnVlXQ",
33
- "WyJHMDJOU3JRZmpGWFE3SW8wOXN5YWpBIiwgImlzX292ZXJfMjEiLCB0cnVlXQ",
34
- "WyJsa2x4RjVqTVlsR1RQVW92TU5JdkNBIiwgImlzX292ZXJfNjUiLCB0cnVlXQ",
35
- "WyJRZ19PNjR6cUF4ZTQxMmExMDhpcm9BIiwgImFkZHJlc3MiLCB7InN0cmVldF9hZGRyZXNzIjogIjEyMyBNYWluIFN0IiwgImxvY2FsaXR5IjogIkFueXRvd24iLCAicmVnaW9uIjogIkFueXN0YXRlIiwgImNvdW50cnkiOiAiVVMifV0",
27
+ "WyJrSkRFUDhFYU5URU1CRE9aelp6VDR3IiwidW5pcXVlX2lkIiwiVElOSVQtTFZMREFBODVUNTBHNzAyQiJd",
28
+ "WyJ6SUF5VUZ2UGZJcEUxekJxeEk1aGFRIiwiYmlydGhfZGF0ZSIsIjE5ODUtMTItMTAiXQ",
29
+ "WyJHcjNSM3MyOTBPa1FVbS1ORlR1OTZBIiwidGF4X2lkX2NvZGUiLCJUSU5JVC1MVkxEQUE4NVQ1MEc3MDJCIl0",
30
+ "WyJHeE9SYWxNQWVsZlowZWRGSmpqWVV3IiwiZ2l2ZW5fbmFtZSIsIkFkYSJd",
31
+ "WyJfdlY1UklrbDBJT0VYS290czlrdDF3IiwiZmFtaWx5X25hbWUiLCJMb3ZlbGFjZSJd",
32
+ "WyJDajV0Y2NSNzJKd3J6ZTJUVzRhLXdnIiwiaWF0IiwxNzIwMDEwNTc1XQ",
36
33
  ];
37
34
 
38
35
  const sdJwt = {
39
36
  header: {
37
+ kid: "-F_6Uga8n3VegjY2U7YUHK1zLoaD-NPTc63RMISnLaw",
40
38
  typ: "vc+sd-jwt",
41
39
  alg: "ES256",
42
- kid: "b186ea0c1925793097bf01b8a289a45f",
43
- trust_chain: [
44
- "NEhRdERpYnlHY3M5WldWTWZ2aUhm ...",
45
- "eyJhbGciOiJSUzI1NiIsImtpZCI6 ...",
46
- "IkJYdmZybG5oQU11SFIwN2FqVW1B ...",
47
- ],
48
40
  },
49
41
  payload: {
50
- iss: "https://example.com/issuer",
51
- sub: "NzbLsXh8uDCcd7noWXFZAfHkxZsRGC9Xs...",
52
- jti: "urn:uuid:6c5c0a49-b589-431d-bae7-219122a9ec2c",
53
- iat: 1541493724,
54
- exp: 1541493724,
55
- status: "https://example.com/status",
42
+ _sd: [
43
+ "0q1D5Jmav6pQaEh_J_Fcv_uNNMQIgCyhQOxqlY4l3qU",
44
+ "KCJ-AVNv88d-xj6sUIAOJxFnbUh3rHXDKkIH1lFqbRs",
45
+ "M9lo9YxDNIXrAq2qWeiCA40zpJ_zYfFdR_4AEALcRtU",
46
+ "czgjUk0nqRCswShChCjdS6A1-v47d_qTCSFIvIHhMoI",
47
+ "nGnQr7clm3tfTp8yjL_uHrDSOtzR2PVb8S7GeLdAqBQ",
48
+ "xNIVwlpSsaZ8CJSf0gz5x_75VRWWc6V1mlpejdCrqUs",
49
+ ],
50
+ sub: "216f8946-9ecb-4819-9309-c076f34a7e11",
51
+ _sd_alg: "sha-256",
52
+ vct: "PersonIdentificationData",
53
+ iss: "https://pre.eid.wallet.ipzs.it",
56
54
  cnf: {
57
55
  jwk: {
58
- kty: "RSA",
59
- use: "sig",
60
- n: "1Ta-sE",
61
- e: "AQAB",
62
- kid: "YhNFS3YnC9tjiCaivhWLVUJ3AxwGGz_98uRFaqMEEs",
56
+ kty: "EC",
57
+ crv: "P-256",
58
+ kid: "Rv3W-EiKpvBTyk5yZxvrev-7MDB6SlzUCBo_CQjjddU",
59
+ x: "0Wox7QtyPqByg35MH_XyCcnd5Le-Jm0AXHlUgDBA03Y",
60
+ y: "eEhVvg1JPqNd3DTSa4mGDGBlwY6NP-EZbLbNFXSXwIg",
63
61
  },
64
62
  },
65
- type: "PersonIdentificationData",
66
- verified_claims: {
67
- verification: {
68
- _sd: ["JzYjH4svliH0R3PyEMfeZu6Jt69u5qehZo7F7EPYlSE"],
69
- trust_framework: "eidas",
70
- assurance_level: "high",
71
- },
72
- claims: {
73
- _sd: [
74
- "09vKrJMOlyTWM0sjpu_pdOBVBQ2M1y3KhpH515nXkpY",
75
- "2rsjGbaC0ky8mT0pJrPioWTq0_daw1sX76poUlgCwbI",
76
- "EkO8dhW0dHEJbvUHlE_VCeuC9uRELOieLZhh7XbUTtA",
77
- "IlDzIKeiZdDwpqpK6ZfbyphFvz5FgnWa-sN6wqQXCiw",
78
- "PorFbpKuVu6xymJagvkFsFXAbRoc2JGlAUA2BA4o7cI",
79
- "TGf4oLbgwd5JQaHyKVQZU9UdGE0w5rtDsrZzfUaomLo",
80
- "jdrTE8YcbY4EifugihiAe_BPekxJQZICeiUQwY9QqxI",
81
- "jsu9yVulwQQlhFlM_3JlzMaSFzglhQG0DpfayQwLUK4",
82
- ],
63
+ exp: 1751546576,
64
+ status: {
65
+ status_attestation: {
66
+ credential_hash_alg: "sha-256",
83
67
  },
84
68
  },
85
- _sd_alg: "sha-256",
86
69
  },
87
70
  };
88
71
 
89
72
  // In the very same order than tokenizedDisclosures
90
73
  const disclosures = [
91
- ["2GLC42sKQveCfGfryNRN9w", "given_name", "John"],
92
- ["eluV5Og3gSNII8EYnsxA_A", "family_name", "Doe"],
93
- ["6Ij7tM-a5iVPGboS5tmvVA", "email", "johndoe@example.com"],
94
- ["eI8ZWm9QnKPpNPeNenHdhQ", "phone_number", "+1-202-555-0101"],
95
- ["AJx-095VPrpTtN4QMOqROA", "birthdate", "1940-01-01"],
96
- ["Pc33JM2LchcU_lHggv_ufQ", "is_over_18", true],
97
- ["G02NSrQfjFXQ7Io09syajA", "is_over_21", true],
98
- ["lklxF5jMYlGTPUovMNIvCA", "is_over_65", true],
99
- [
100
- "Qg_O64zqAxe412a108iroA",
101
- "address",
102
- {
103
- street_address: "123 Main St",
104
- locality: "Anytown",
105
- region: "Anystate",
106
- country: "US",
107
- },
108
- ],
74
+ ["kJDEP8EaNTEMBDOZzZzT4w", "unique_id", "TINIT-LVLDAA85T50G702B"],
75
+ ["zIAyUFvPfIpE1zBqxI5haQ", "birth_date", "1985-12-10"],
76
+ ["Gr3R3s290OkQUm-NFTu96A", "tax_id_code", "TINIT-LVLDAA85T50G702B"],
77
+ ["GxORalMAelfZ0edFJjjYUw", "given_name", "Ada"],
78
+ ["_vV5RIkl0IOEXKots9kt1w", "family_name", "Lovelace"],
79
+ ["Cj5tccR72Jwrze2TW4a-wg", "iat", 1720010575],
109
80
  ];
110
81
  it("Ensures example data correctness", () => {
111
82
  expect(
@@ -161,8 +132,8 @@ describe("disclose", () => {
161
132
  it("should encode a valid sdjwt (one claim)", async () => {
162
133
  const result = await disclose(token, ["given_name"]);
163
134
  const expected = {
164
- token: `${signed}~WyIyR0xDNDJzS1F2ZUNmR2ZyeU5STjl3IiwgImdpdmVuX25hbWUiLCAiSm9obiJd`,
165
- paths: [{ claim: "given_name", path: "verified_claims.claims._sd[7]" }],
135
+ token: `${signed}~WyJHeE9SYWxNQWVsZlowZWRGSmpqWVV3IiwiZ2l2ZW5fbmFtZSIsIkFkYSJd`,
136
+ paths: [{ claim: "given_name", path: "verified_claims.claims._sd[3]" }],
166
137
  };
167
138
 
168
139
  expect(result).toEqual(expected);
@@ -176,17 +147,17 @@ describe("disclose", () => {
176
147
  });
177
148
 
178
149
  it("should encode a valid sdjwt (multiple claims)", async () => {
179
- const result = await disclose(token, ["given_name", "email"]);
150
+ const result = await disclose(token, ["iat", "family_name"]);
180
151
  const expected = {
181
- token: `${signed}~WyIyR0xDNDJzS1F2ZUNmR2ZyeU5STjl3IiwgImdpdmVuX25hbWUiLCAiSm9obiJd~WyI2SWo3dE0tYTVpVlBHYm9TNXRtdlZBIiwgImVtYWlsIiwgImpvaG5kb2VAZXhhbXBsZS5jb20iXQ`,
152
+ token: `${signed}~WyJfdlY1UklrbDBJT0VYS290czlrdDF3IiwiZmFtaWx5X25hbWUiLCJMb3ZlbGFjZSJd~WyJDajV0Y2NSNzJKd3J6ZTJUVzRhLXdnIiwiaWF0IiwxNzIwMDEwNTc1XQ`,
182
153
  paths: [
183
154
  {
184
- claim: "given_name",
185
- path: "verified_claims.claims._sd[7]",
155
+ claim: "iat",
156
+ path: "verified_claims.claims._sd[4]",
186
157
  },
187
158
  {
188
- claim: "email",
189
- path: "verified_claims.verification._sd[0]",
159
+ claim: "family_name",
160
+ path: "verified_claims.claims._sd[0]",
190
161
  },
191
162
  ],
192
163
  };
@@ -8,47 +8,35 @@ describe("SdJwt4VC", () => {
8
8
  typ: "vc+sd-jwt",
9
9
  alg: "RS512",
10
10
  kid: "dB67gL7ck3TFiIAf7N6_7SHvqk0MDYMEQcoGGlkUAAw",
11
- trust_chain: [
12
- "NEhRdERpYnlHY3M5WldWTWZ2aUhm ...",
13
- "eyJhbGciOiJSUzI1NiIsImtpZCI6 ...",
14
- "IkJYdmZybG5oQU11SFIwN2FqVW1B ...",
15
- ],
16
11
  },
17
12
  payload: {
18
- iss: "https://pidprovider.example.org",
19
- sub: "NzbLsXh8uDCcd7noWXFZAfHkxZsRGC9Xs...",
20
- jti: "urn:uuid:6c5c0a49-b589-431d-bae7-219122a9ec2c",
21
- iat: 1541493724,
22
- exp: 1541493724,
23
- status: "https://pidprovider.example.org/status",
13
+ _sd: [
14
+ "0q1D5Jmav6pQaEh_J_Fcv_uNNMQIgCyhQOxqlY4l3qU",
15
+ "KCJ-AVNv88d-xj6sUIAOJxFnbUh3rHXDKkIH1lFqbRs",
16
+ "M9lo9YxDNIXrAq2qWeiCA40zpJ_zYfFdR_4AEALcRtU",
17
+ "czgjUk0nqRCswShChCjdS6A1-v47d_qTCSFIvIHhMoI",
18
+ "nGnQr7clm3tfTp8yjL_uHrDSOtzR2PVb8S7GeLdAqBQ",
19
+ "xNIVwlpSsaZ8CJSf0gz5x_75VRWWc6V1mlpejdCrqUs",
20
+ ],
21
+ sub: "216f8946-9ecb-4819-9309-c076f34a7e11",
22
+ _sd_alg: "sha-256",
23
+ vct: "PersonIdentificationData",
24
+ iss: "https://pidprovider.example.com",
24
25
  cnf: {
25
26
  jwk: {
26
- kty: "RSA",
27
- use: "sig",
28
- n: "1Ta-sE …",
29
- e: "AQAB",
30
- kid: "YhNFS3YnC9tjiCaivhWLVUJ3AxwGGz_98uRFaqMEEs",
27
+ kty: "EC",
28
+ crv: "P-256",
29
+ kid: "zEv_qGSL5r0_F67j2dwEgUJmBgbMNSEJ5K_iH1PYc7A",
30
+ x: "0Pj7v_afNp9ETJx11JbYgkI7yQpd0rtiYuo5feuAN2o",
31
+ y: "XB62Um02vHqedkOzSfJ5hdtjPz-zmV9jmWh4sKgdD9o",
31
32
  },
32
33
  },
33
- type: "PersonIdentificationData",
34
- verified_claims: {
35
- verification: {
36
- _sd: ["OGm7ryXgt5Xzlevp-Hu-UTk0a-TxAaPAobqv1pIWMfw"],
37
- trust_framework: "eidas",
38
- assurance_level: "high",
39
- },
40
- claims: {
41
- _sd: [
42
- "8JjozBfovMNvQ3HflmPWy4O19Gpxs61FWHjZebU589E",
43
- "BoMGktW1rbikntw8Fzx_BeL4YbAndr6AHsdgpatFCig",
44
- "CFLGzentGNRFngnLVVQVcoAFi05r6RJUX-rdbLdEfew",
45
- "JU_sTaHCngS32X-0ajHrd1-HCLCkpT5YqgcfQme168w",
46
- "VQI-S1mT1Kxfq2o8J9io7xMMX2MIxaG9M9PeJVqrMcA",
47
- "zVdghcmClMVWlUgGsGpSkCPkEHZ4u9oWj1SlIBlCc1o",
48
- ],
34
+ exp: 1751107255,
35
+ status: {
36
+ status_attestation: {
37
+ credential_hash_alg: "sha-256",
49
38
  },
50
39
  },
51
- _sd_alg: "sha-256",
52
40
  },
53
41
  };
54
42
 
@@ -101,15 +101,9 @@ export const disclose = async (
101
101
 
102
102
  // _sd is defined in verified_claims.claims and verified_claims.verification
103
103
  // we must look into both
104
- if (sdJwt.payload.verified_claims.claims._sd.includes(hash)) {
105
- const index = sdJwt.payload.verified_claims.claims._sd.indexOf(hash);
104
+ if (sdJwt.payload._sd.includes(hash)) {
105
+ const index = sdJwt.payload._sd.indexOf(hash);
106
106
  return { claim, path: `verified_claims.claims._sd[${index}]` };
107
- } else if (
108
- sdJwt.payload.verified_claims.verification._sd.includes(hash)
109
- ) {
110
- const index =
111
- sdJwt.payload.verified_claims.verification._sd.indexOf(hash);
112
- return { claim, path: `verified_claims.verification._sd[${index}]` };
113
107
  }
114
108
 
115
109
  throw new ClaimsNotFoundInToken(claim);
@@ -158,10 +152,7 @@ export const verify = async <S extends z.ZodType<SdJwt4VC>>(
158
152
  await verifyJwt(rawSdJwt, publicKey);
159
153
 
160
154
  //Check disclosures in sd-jwt
161
- const claims = [
162
- ...decoded.sdJwt.payload.verified_claims.verification._sd,
163
- ...decoded.sdJwt.payload.verified_claims.claims._sd,
164
- ];
155
+ const claims = [...decoded.sdJwt.payload._sd];
165
156
 
166
157
  await Promise.all(
167
158
  decoded.disclosures.map(