@pagopa/io-react-native-wallet 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/commonjs/client/generated/wallet-provider.js +22 -22
- package/lib/commonjs/client/generated/wallet-provider.js.map +1 -1
- package/lib/commonjs/client/index.js +1 -2
- package/lib/commonjs/client/index.js.map +1 -1
- package/lib/commonjs/credential/issuance/02-evaluate-issuer-trust.js +2 -1
- package/lib/commonjs/credential/issuance/02-evaluate-issuer-trust.js.map +1 -1
- package/lib/commonjs/credential/issuance/03-start-credential-issuance.js +287 -0
- package/lib/commonjs/credential/issuance/03-start-credential-issuance.js.map +1 -0
- package/lib/commonjs/credential/issuance/03-start-user-authorization.js +56 -83
- package/lib/commonjs/credential/issuance/03-start-user-authorization.js.map +1 -1
- package/lib/commonjs/credential/issuance/04-complete-user-authorization.js +88 -0
- package/lib/commonjs/credential/issuance/04-complete-user-authorization.js.map +1 -1
- package/lib/commonjs/credential/issuance/05-authorize-access.js +56 -33
- package/lib/commonjs/credential/issuance/05-authorize-access.js.map +1 -1
- package/lib/commonjs/credential/issuance/06-obtain-credential.js +51 -78
- package/lib/commonjs/credential/issuance/06-obtain-credential.js.map +1 -1
- package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js +21 -44
- package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
- package/lib/commonjs/credential/issuance/index.js +7 -0
- package/lib/commonjs/credential/issuance/index.js.map +1 -1
- package/lib/commonjs/credential/issuance/types.js +28 -0
- package/lib/commonjs/credential/issuance/types.js.map +1 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/pid/sd-jwt/converters.js +5 -9
- package/lib/commonjs/pid/sd-jwt/converters.js.map +1 -1
- package/lib/commonjs/pid/sd-jwt/types.js +3 -3
- package/lib/commonjs/pid/sd-jwt/types.js.map +1 -1
- package/lib/commonjs/sd-jwt/__test__/converters.test.js +1 -1
- package/lib/commonjs/sd-jwt/__test__/converters.test.js.map +1 -1
- package/lib/commonjs/sd-jwt/__test__/index.test.js +30 -43
- package/lib/commonjs/sd-jwt/__test__/index.test.js.map +1 -1
- package/lib/commonjs/sd-jwt/__test__/types.test.js +16 -24
- package/lib/commonjs/sd-jwt/__test__/types.test.js.map +1 -1
- package/lib/commonjs/sd-jwt/index.js +3 -9
- package/lib/commonjs/sd-jwt/index.js.map +1 -1
- package/lib/commonjs/sd-jwt/types.js +11 -16
- package/lib/commonjs/sd-jwt/types.js.map +1 -1
- package/lib/commonjs/trust/types.js +70 -29
- package/lib/commonjs/trust/types.js.map +1 -1
- package/lib/commonjs/utils/auth.js +44 -0
- package/lib/commonjs/utils/auth.js.map +1 -0
- package/lib/commonjs/utils/errors.js +77 -2
- package/lib/commonjs/utils/errors.js.map +1 -1
- package/lib/commonjs/utils/misc.js +34 -1
- package/lib/commonjs/utils/misc.js.map +1 -1
- package/lib/commonjs/utils/par.js +23 -15
- package/lib/commonjs/utils/par.js.map +1 -1
- package/lib/commonjs/utils/pop.js +33 -0
- package/lib/commonjs/utils/pop.js.map +1 -0
- package/lib/commonjs/wallet-instance-attestation/issuing.js +17 -2
- package/lib/commonjs/wallet-instance-attestation/issuing.js.map +1 -1
- package/lib/commonjs/wallet-instance-attestation/types.js +7 -7
- package/lib/commonjs/wallet-instance-attestation/types.js.map +1 -1
- package/lib/module/client/generated/wallet-provider.js +16 -19
- package/lib/module/client/generated/wallet-provider.js.map +1 -1
- package/lib/module/client/index.js +1 -2
- package/lib/module/client/index.js.map +1 -1
- package/lib/module/credential/issuance/02-evaluate-issuer-trust.js +2 -1
- package/lib/module/credential/issuance/02-evaluate-issuer-trust.js.map +1 -1
- package/lib/module/credential/issuance/03-start-credential-issuance.js +276 -0
- package/lib/module/credential/issuance/03-start-credential-issuance.js.map +1 -0
- package/lib/module/credential/issuance/03-start-user-authorization.js +56 -80
- package/lib/module/credential/issuance/03-start-user-authorization.js.map +1 -1
- package/lib/module/credential/issuance/04-complete-user-authorization.js +85 -1
- package/lib/module/credential/issuance/04-complete-user-authorization.js.map +1 -1
- package/lib/module/credential/issuance/05-authorize-access.js +54 -33
- package/lib/module/credential/issuance/05-authorize-access.js.map +1 -1
- package/lib/module/credential/issuance/06-obtain-credential.js +50 -75
- package/lib/module/credential/issuance/06-obtain-credential.js.map +1 -1
- package/lib/module/credential/issuance/07-verify-and-parse-credential.js +21 -44
- package/lib/module/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
- package/lib/module/credential/issuance/index.js +2 -1
- package/lib/module/credential/issuance/index.js.map +1 -1
- package/lib/module/credential/issuance/types.js +18 -0
- package/lib/module/credential/issuance/types.js.map +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/pid/sd-jwt/converters.js +5 -9
- package/lib/module/pid/sd-jwt/converters.js.map +1 -1
- package/lib/module/pid/sd-jwt/types.js +3 -3
- package/lib/module/pid/sd-jwt/types.js.map +1 -1
- package/lib/module/sd-jwt/__test__/converters.test.js +1 -1
- package/lib/module/sd-jwt/__test__/converters.test.js.map +1 -1
- package/lib/module/sd-jwt/__test__/index.test.js +30 -43
- package/lib/module/sd-jwt/__test__/index.test.js.map +1 -1
- package/lib/module/sd-jwt/__test__/types.test.js +16 -24
- package/lib/module/sd-jwt/__test__/types.test.js.map +1 -1
- package/lib/module/sd-jwt/index.js +3 -9
- package/lib/module/sd-jwt/index.js.map +1 -1
- package/lib/module/sd-jwt/types.js +11 -16
- package/lib/module/sd-jwt/types.js.map +1 -1
- package/lib/module/sd-jwt/verifier.js.map +1 -1
- package/lib/module/trust/types.js +70 -29
- package/lib/module/trust/types.js.map +1 -1
- package/lib/module/utils/auth.js +35 -0
- package/lib/module/utils/auth.js.map +1 -0
- package/lib/module/utils/errors.js +71 -0
- package/lib/module/utils/errors.js.map +1 -1
- package/lib/module/utils/misc.js +31 -0
- package/lib/module/utils/misc.js.map +1 -1
- package/lib/module/utils/par.js +24 -16
- package/lib/module/utils/par.js.map +1 -1
- package/lib/module/utils/pop.js +24 -0
- package/lib/module/utils/pop.js.map +1 -0
- package/lib/module/wallet-instance-attestation/issuing.js +17 -2
- package/lib/module/wallet-instance-attestation/issuing.js.map +1 -1
- package/lib/module/wallet-instance-attestation/types.js +7 -7
- package/lib/module/wallet-instance-attestation/types.js.map +1 -1
- package/lib/typescript/client/generated/wallet-provider.d.ts +35 -13
- package/lib/typescript/client/generated/wallet-provider.d.ts.map +1 -1
- package/lib/typescript/client/index.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/01-start-flow.d.ts +1 -0
- package/lib/typescript/credential/issuance/01-start-flow.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/02-evaluate-issuer-trust.d.ts +2 -1
- package/lib/typescript/credential/issuance/02-evaluate-issuer-trust.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/03-start-credential-issuance.d.ts +41 -0
- package/lib/typescript/credential/issuance/03-start-credential-issuance.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts +23 -18
- package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts +24 -12
- package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/05-authorize-access.d.ts +22 -16
- package/lib/typescript/credential/issuance/05-authorize-access.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/06-obtain-credential.d.ts +19 -26
- package/lib/typescript/credential/issuance/06-obtain-credential.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts +10 -15
- package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/index.d.ts +3 -4
- package/lib/typescript/credential/issuance/index.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/types.d.ts +63 -0
- package/lib/typescript/credential/issuance/types.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/types.d.ts +6 -6
- package/lib/typescript/index.d.ts +2 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/pid/sd-jwt/converters.d.ts.map +1 -1
- package/lib/typescript/pid/sd-jwt/types.d.ts +36 -36
- package/lib/typescript/pid/sd-jwt/types.d.ts.map +1 -1
- package/lib/typescript/sd-jwt/index.d.ts +40 -68
- package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
- package/lib/typescript/sd-jwt/types.d.ts +64 -121
- package/lib/typescript/sd-jwt/types.d.ts.map +1 -1
- package/lib/typescript/trust/index.d.ts +150 -48
- package/lib/typescript/trust/index.d.ts.map +1 -1
- package/lib/typescript/trust/types.d.ts +2838 -1740
- package/lib/typescript/trust/types.d.ts.map +1 -1
- package/lib/typescript/utils/auth.d.ts +52 -0
- package/lib/typescript/utils/auth.d.ts.map +1 -0
- package/lib/typescript/utils/errors.d.ts +36 -1
- package/lib/typescript/utils/errors.d.ts.map +1 -1
- package/lib/typescript/utils/integrity.d.ts +1 -1
- package/lib/typescript/utils/misc.d.ts +18 -0
- package/lib/typescript/utils/misc.d.ts.map +1 -1
- package/lib/typescript/utils/par.d.ts +8 -31
- package/lib/typescript/utils/par.d.ts.map +1 -1
- package/lib/typescript/utils/pop.d.ts +26 -0
- package/lib/typescript/utils/pop.d.ts.map +1 -0
- package/lib/typescript/wallet-instance-attestation/issuing.d.ts +2 -1
- package/lib/typescript/wallet-instance-attestation/issuing.d.ts.map +1 -1
- package/lib/typescript/wallet-instance-attestation/types.d.ts +59 -59
- package/lib/typescript/wallet-instance-attestation/types.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/client/generated/wallet-provider.ts +24 -21
- package/src/client/index.ts +3 -8
- package/src/credential/issuance/01-start-flow.ts +1 -0
- package/src/credential/issuance/02-evaluate-issuer-trust.ts +2 -1
- package/src/credential/issuance/03-start-credential-issuance.ts +407 -0
- package/src/credential/issuance/03-start-user-authorization.ts +91 -92
- package/src/credential/issuance/04-complete-user-authorization.ts +114 -13
- package/src/credential/issuance/05-authorize-access.ts +74 -49
- package/src/credential/issuance/06-obtain-credential.ts +77 -111
- package/src/credential/issuance/07-verify-and-parse-credential.ts +30 -67
- package/src/credential/issuance/index.ts +6 -4
- package/src/credential/issuance/types.ts +25 -0
- package/src/index.ts +2 -1
- package/src/pid/sd-jwt/converters.ts +5 -11
- package/src/pid/sd-jwt/types.ts +8 -6
- package/src/sd-jwt/__test__/converters.test.ts +1 -1
- package/src/sd-jwt/__test__/index.test.ts +45 -74
- package/src/sd-jwt/__test__/types.test.ts +21 -33
- package/src/sd-jwt/index.ts +3 -12
- package/src/sd-jwt/types.ts +17 -22
- package/src/trust/types.ts +64 -32
- package/src/utils/auth.ts +37 -0
- package/src/utils/errors.ts +85 -1
- package/src/utils/integrity.ts +1 -1
- package/src/utils/misc.ts +43 -0
- package/src/utils/par.ts +29 -17
- package/src/utils/pop.ts +34 -0
- package/src/wallet-instance-attestation/issuing.ts +39 -2
- package/src/wallet-instance-attestation/types.ts +11 -7
- package/lib/commonjs/credential/issuance/07-confirm-credential.js +0 -6
- package/lib/commonjs/credential/issuance/07-confirm-credential.js.map +0 -1
- package/lib/commonjs/credential/issuance/08-confirm-credential.js +0 -6
- package/lib/commonjs/credential/issuance/08-confirm-credential.js.map +0 -1
- package/lib/module/credential/issuance/07-confirm-credential.js +0 -2
- package/lib/module/credential/issuance/07-confirm-credential.js.map +0 -1
- package/lib/module/credential/issuance/08-confirm-credential.js +0 -2
- package/lib/module/credential/issuance/08-confirm-credential.js.map +0 -1
- package/lib/typescript/credential/issuance/07-confirm-credential.d.ts +0 -11
- package/lib/typescript/credential/issuance/07-confirm-credential.d.ts.map +0 -1
- package/lib/typescript/credential/issuance/08-confirm-credential.d.ts +0 -11
- package/lib/typescript/credential/issuance/08-confirm-credential.d.ts.map +0 -1
- package/src/credential/issuance/07-confirm-credential.ts +0 -14
- package/src/credential/issuance/08-confirm-credential.ts +0 -14
- package/src/sd-jwt/__test__/converters.test.js +0 -24
- package/src/sd-jwt/verifier.js +0 -12
package/src/utils/misc.ts
CHANGED
@@ -25,3 +25,46 @@ export type Out<FN> = FN extends (...args: any[]) => Promise<any>
|
|
25
25
|
: FN extends (...args: any[]) => any
|
26
26
|
? ReturnType<FN>
|
27
27
|
: never;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* TODO [SIW-1310]: replace this function with a cryptographically secure one.
|
31
|
+
* @param size - The size of the string to generate
|
32
|
+
* @returns A random alphanumeric string of the given size
|
33
|
+
*/
|
34
|
+
export const generateRandomAlphaNumericString = (size: number) =>
|
35
|
+
Array.from(Array(size), () =>
|
36
|
+
Math.floor(Math.random() * 36).toString(36)
|
37
|
+
).join("");
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Repeatedly checks a condition function until it returns true,
|
41
|
+
* then resolves the returned promise. If the condition function does not return true
|
42
|
+
* within the specified timeout, the promise is rejected.
|
43
|
+
*
|
44
|
+
* @param conditionFunction - A function that returns a boolean value.
|
45
|
+
* The promise resolves when this function returns true.
|
46
|
+
* @param timeout - An optional timeout in seconds. The promise is rejected if the
|
47
|
+
* condition function does not return true within this time.
|
48
|
+
* @returns A promise that resolves once the conditionFunction returns true or rejects if timed out.
|
49
|
+
*/
|
50
|
+
export const until = (
|
51
|
+
conditionFunction: () => boolean,
|
52
|
+
timeoutSeconds?: number
|
53
|
+
): Promise<void> =>
|
54
|
+
new Promise<void>((resolve, reject) => {
|
55
|
+
const start = Date.now();
|
56
|
+
const poll = () => {
|
57
|
+
if (conditionFunction()) {
|
58
|
+
resolve();
|
59
|
+
} else if (
|
60
|
+
timeoutSeconds !== undefined &&
|
61
|
+
Date.now() - start >= timeoutSeconds * 1000
|
62
|
+
) {
|
63
|
+
reject(new Error("Timeout exceeded"));
|
64
|
+
} else {
|
65
|
+
setTimeout(poll, 400);
|
66
|
+
}
|
67
|
+
};
|
68
|
+
|
69
|
+
poll();
|
70
|
+
});
|
package/src/utils/par.ts
CHANGED
@@ -6,13 +6,12 @@ import {
|
|
6
6
|
import uuid from "react-native-uuid";
|
7
7
|
import * as z from "zod";
|
8
8
|
import * as WalletInstanceAttestation from "../wallet-instance-attestation";
|
9
|
-
import { hasStatus } from "./misc";
|
9
|
+
import { generateRandomAlphaNumericString, hasStatus } from "./misc";
|
10
|
+
import { createPopToken } from "./pop";
|
10
11
|
|
11
12
|
export type AuthorizationDetail = z.infer<typeof AuthorizationDetail>;
|
12
13
|
export const AuthorizationDetail = z.object({
|
13
|
-
|
14
|
-
type: z.string(),
|
15
|
-
}),
|
14
|
+
credential_configuration_id: z.string(),
|
16
15
|
format: z.union([z.literal("vc+sd-jwt"), z.literal("vc+mdoc-cbor")]),
|
17
16
|
type: z.literal("openid_credential"),
|
18
17
|
});
|
@@ -34,7 +33,8 @@ export const makeParRequest =
|
|
34
33
|
async (
|
35
34
|
clientId: string,
|
36
35
|
codeVerifier: string,
|
37
|
-
|
36
|
+
redirectUri: string,
|
37
|
+
responseMode: string,
|
38
38
|
parEndpoint: string,
|
39
39
|
walletInstanceAttestation: string,
|
40
40
|
authorizationDetails: AuthorizationDetails,
|
@@ -48,10 +48,19 @@ export const makeParRequest =
|
|
48
48
|
const iss = WalletInstanceAttestation.decode(walletInstanceAttestation)
|
49
49
|
.payload.cnf.jwk.kid;
|
50
50
|
|
51
|
+
const signedWiaPoP = await createPopToken(
|
52
|
+
{
|
53
|
+
jti: `${uuid.v4()}`,
|
54
|
+
aud,
|
55
|
+
iss,
|
56
|
+
},
|
57
|
+
wiaCryptoContext
|
58
|
+
);
|
59
|
+
|
51
60
|
/** A code challenge is provided so that the PAR is bound
|
52
61
|
to the subsequent authorization code request
|
53
62
|
@see https://datatracker.ietf.org/doc/html/rfc9126#name-request */
|
54
|
-
const codeChallengeMethod = "
|
63
|
+
const codeChallengeMethod = "S256";
|
55
64
|
const codeChallenge = await sha256ToBase64(codeVerifier);
|
56
65
|
|
57
66
|
/** The PAR request token is signed used the Wallet Instance Attestation key.
|
@@ -60,23 +69,26 @@ export const makeParRequest =
|
|
60
69
|
The key is matched by its kid */
|
61
70
|
const signedJwtForPar = await new SignJWT(wiaCryptoContext)
|
62
71
|
.setProtectedHeader({
|
72
|
+
typ: "jwk",
|
63
73
|
kid: wiaPublicKey.kid,
|
64
74
|
})
|
65
75
|
.setPayload({
|
66
|
-
iss,
|
67
|
-
aud,
|
68
76
|
jti: `${uuid.v4()}`,
|
69
|
-
|
70
|
-
authorization_details: authorizationDetails,
|
77
|
+
aud,
|
71
78
|
response_type: "code",
|
72
|
-
|
73
|
-
state: `${uuid.v4()}`,
|
79
|
+
response_mode: responseMode,
|
74
80
|
client_id: clientId,
|
75
|
-
|
81
|
+
iss,
|
82
|
+
state: generateRandomAlphaNumericString(32),
|
76
83
|
code_challenge: codeChallenge,
|
84
|
+
code_challenge_method: codeChallengeMethod,
|
85
|
+
authorization_details: authorizationDetails,
|
86
|
+
redirect_uri: redirectUri,
|
87
|
+
client_assertion_type: assertionType,
|
88
|
+
client_assertion: walletInstanceAttestation + "~" + signedWiaPoP,
|
77
89
|
})
|
78
|
-
.setIssuedAt()
|
79
|
-
.setExpirationTime("
|
90
|
+
.setIssuedAt() //iat is set to now
|
91
|
+
.setExpirationTime("5min")
|
80
92
|
.sign();
|
81
93
|
|
82
94
|
/** The request body for the Pushed Authorization Request */
|
@@ -85,9 +97,9 @@ export const makeParRequest =
|
|
85
97
|
client_id: clientId,
|
86
98
|
code_challenge: codeChallenge,
|
87
99
|
code_challenge_method: "S256",
|
88
|
-
client_assertion_type: assertionType,
|
89
|
-
client_assertion: walletInstanceAttestation,
|
90
100
|
request: signedJwtForPar,
|
101
|
+
client_assertion_type: assertionType,
|
102
|
+
client_assertion: walletInstanceAttestation + "~" + signedWiaPoP,
|
91
103
|
});
|
92
104
|
|
93
105
|
return await appFetch(parEndpoint, {
|
package/src/utils/pop.ts
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
import * as z from "zod";
|
2
|
+
|
3
|
+
import { SignJWT, type CryptoContext } from "@pagopa/io-react-native-jwt";
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Create a signed PoP token
|
7
|
+
*
|
8
|
+
* @param payload The payload to be included in the token.
|
9
|
+
* @param crypto The crypto context that handles the key bound to the DPoP.
|
10
|
+
*
|
11
|
+
* @returns The signed crypto token.
|
12
|
+
*/
|
13
|
+
export const createPopToken = async (
|
14
|
+
payload: PoPPayload,
|
15
|
+
crypto: CryptoContext
|
16
|
+
): Promise<string> => {
|
17
|
+
const kid = await crypto.getPublicKey().then((_) => _.kid);
|
18
|
+
return new SignJWT(crypto)
|
19
|
+
.setPayload(payload)
|
20
|
+
.setProtectedHeader({
|
21
|
+
typ: "jwt-client-attestation-pop",
|
22
|
+
kid,
|
23
|
+
})
|
24
|
+
.setIssuedAt()
|
25
|
+
.setExpirationTime("5min")
|
26
|
+
.sign();
|
27
|
+
};
|
28
|
+
|
29
|
+
export type PoPPayload = z.infer<typeof PoPPayload>;
|
30
|
+
export const PoPPayload = z.object({
|
31
|
+
jti: z.string(),
|
32
|
+
aud: z.string(),
|
33
|
+
iss: z.string(),
|
34
|
+
});
|
@@ -1,9 +1,15 @@
|
|
1
1
|
import { type CryptoContext } from "@pagopa/io-react-native-jwt";
|
2
2
|
import { SignJWT, thumbprint } from "@pagopa/io-react-native-jwt";
|
3
|
+
import { z } from "zod";
|
3
4
|
import { JWK, fixBase64EncodingOnKey } from "../utils/jwk";
|
4
5
|
import { getWalletProviderClient } from "../client";
|
5
6
|
import type { IntegrityContext } from "..";
|
6
|
-
import {
|
7
|
+
import {
|
8
|
+
WalletProviderResponseError,
|
9
|
+
WalletInstanceRevokedError,
|
10
|
+
WalletInstanceNotFoundError,
|
11
|
+
WalletInstanceAttestationIssuingError,
|
12
|
+
} from "../utils/errors";
|
7
13
|
|
8
14
|
/**
|
9
15
|
* Getter for an attestation request. The attestation request is a JWT that will be sent to the Wallet Provider to request a Wallet Instance Attestation.
|
@@ -64,6 +70,8 @@ export async function getAttestationRequest(
|
|
64
70
|
* @param params.appFetch (optional) Http client
|
65
71
|
* @param walletProviderBaseUrl Base url for the Wallet Provider
|
66
72
|
* @returns The retrieved Wallet Instance Attestation token
|
73
|
+
* @throws {WalletInstanceRevokedError} The Wallet Instance was revoked
|
74
|
+
* @throws {WalletInstanceNotFoundError} The Wallet Instance does not exist
|
67
75
|
*/
|
68
76
|
export const getAttestation = async ({
|
69
77
|
wiaCryptoContext,
|
@@ -100,7 +108,36 @@ export const getAttestation = async ({
|
|
100
108
|
assertion: signedAttestationRequest,
|
101
109
|
},
|
102
110
|
})
|
103
|
-
.then((result) => z.string().parse(result))
|
111
|
+
.then((result) => z.string().parse(result))
|
112
|
+
.catch(handleAttestationCreationError);
|
104
113
|
|
105
114
|
return wia;
|
106
115
|
};
|
116
|
+
|
117
|
+
const handleAttestationCreationError = (e: unknown) => {
|
118
|
+
if (!(e instanceof WalletProviderResponseError)) {
|
119
|
+
throw e;
|
120
|
+
}
|
121
|
+
|
122
|
+
if (e.statusCode === 403) {
|
123
|
+
throw new WalletInstanceRevokedError(
|
124
|
+
"Unable to get an attestation for a revoked Wallet Instance",
|
125
|
+
e.claim,
|
126
|
+
e.reason
|
127
|
+
);
|
128
|
+
}
|
129
|
+
|
130
|
+
if (e.statusCode === 404) {
|
131
|
+
throw new WalletInstanceNotFoundError(
|
132
|
+
"Unable to get an attestation for a Wallet Instance that does not exist",
|
133
|
+
e.claim,
|
134
|
+
e.reason
|
135
|
+
);
|
136
|
+
}
|
137
|
+
|
138
|
+
throw new WalletInstanceAttestationIssuingError(
|
139
|
+
`Unable to obtain wallet instance attestation [response status code: ${e.statusCode}]`,
|
140
|
+
e.claim,
|
141
|
+
e.reason
|
142
|
+
);
|
143
|
+
};
|
@@ -60,16 +60,20 @@ export const WalletInstanceAttestationJwt = z.object({
|
|
60
60
|
Jwt.shape.payload,
|
61
61
|
z.object({
|
62
62
|
sub: z.string(),
|
63
|
-
|
63
|
+
aal: z.string(),
|
64
64
|
authorization_endpoint: z.string(),
|
65
65
|
response_types_supported: z.array(z.string()),
|
66
66
|
vp_formats_supported: z.object({
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
"vc+sd-jwt": z
|
68
|
+
.object({
|
69
|
+
"sd-jwt_alg_values": z.array(z.string()),
|
70
|
+
})
|
71
|
+
.optional(),
|
72
|
+
"vp+sd-jwt": z
|
73
|
+
.object({
|
74
|
+
"sd-jwt_alg_values": z.array(z.string()),
|
75
|
+
})
|
76
|
+
.optional(),
|
73
77
|
}),
|
74
78
|
request_object_signing_alg_values_supported: z.array(z.string()),
|
75
79
|
presentation_definition_uri_supported: z.boolean(),
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../../src","sources":["credential/issuance/07-confirm-credential.ts"],"mappings":""}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../../src","sources":["credential/issuance/08-confirm-credential.ts"],"mappings":""}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../../src","sources":["credential/issuance/07-confirm-credential.ts"],"mappings":""}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../../src","sources":["credential/issuance/08-confirm-credential.ts"],"mappings":""}
|
@@ -1,11 +0,0 @@
|
|
1
|
-
import type { ObtainCredential } from "./06-obtain-credential";
|
2
|
-
import type { Out } from "../../utils/misc";
|
3
|
-
/**
|
4
|
-
* The end of the issuing flow.
|
5
|
-
* The User accepted the Credential and it can be stored in the device according to the app implementation preferences.
|
6
|
-
* To be implemented.
|
7
|
-
*
|
8
|
-
* @returns The type of the Credential to be issued and the url of the Issuer
|
9
|
-
*/
|
10
|
-
export type ConfirmCredential = (credential: Out<ObtainCredential>["credential"], format: Out<ObtainCredential>["format"]) => Promise<void>;
|
11
|
-
//# sourceMappingURL=07-confirm-credential.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"07-confirm-credential.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/07-confirm-credential.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,UAAU,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC,YAAY,CAAC,EAC/C,MAAM,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,KACpC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
@@ -1,11 +0,0 @@
|
|
1
|
-
import type { ObtainCredential } from "./06-obtain-credential";
|
2
|
-
import type { Out } from "../../utils/misc";
|
3
|
-
/**
|
4
|
-
* The end of the issuing flow.
|
5
|
-
* The User accepted the Credential and it can be stored in the device according to the app implementation preferences.
|
6
|
-
* To be implemented.
|
7
|
-
*
|
8
|
-
* @returns The type of the Credential to be issued and the url of the Issuer
|
9
|
-
*/
|
10
|
-
export type ConfirmCredential = (credential: Out<ObtainCredential>["credential"], format: Out<ObtainCredential>["format"]) => Promise<void>;
|
11
|
-
//# sourceMappingURL=08-confirm-credential.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"08-confirm-credential.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/08-confirm-credential.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,UAAU,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC,YAAY,CAAC,EAC/C,MAAM,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,KACpC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import type { ObtainCredential } from "./06-obtain-credential";
|
2
|
-
import type { Out } from "../../utils/misc";
|
3
|
-
|
4
|
-
/**
|
5
|
-
* The end of the issuing flow.
|
6
|
-
* The User accepted the Credential and it can be stored in the device according to the app implementation preferences.
|
7
|
-
* To be implemented.
|
8
|
-
*
|
9
|
-
* @returns The type of the Credential to be issued and the url of the Issuer
|
10
|
-
*/
|
11
|
-
export type ConfirmCredential = (
|
12
|
-
credential: Out<ObtainCredential>["credential"],
|
13
|
-
format: Out<ObtainCredential>["format"]
|
14
|
-
) => Promise<void>;
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import type { ObtainCredential } from "./06-obtain-credential";
|
2
|
-
import type { Out } from "../../utils/misc";
|
3
|
-
|
4
|
-
/**
|
5
|
-
* The end of the issuing flow.
|
6
|
-
* The User accepted the Credential and it can be stored in the device according to the app implementation preferences.
|
7
|
-
* To be implemented.
|
8
|
-
*
|
9
|
-
* @returns The type of the Credential to be issued and the url of the Issuer
|
10
|
-
*/
|
11
|
-
export type ConfirmCredential = (
|
12
|
-
credential: Out<ObtainCredential>["credential"],
|
13
|
-
format: Out<ObtainCredential>["format"]
|
14
|
-
) => Promise<void>;
|
@@ -1,24 +0,0 @@
|
|
1
|
-
import { getValueFromDisclosures } from "../converters";
|
2
|
-
const disclosures = [
|
3
|
-
["6w1_soRXFgaHKfpYn3cvfQ", "given_name", "Mario"],
|
4
|
-
["fuNp97Hf3wV6y48y-QZhIg", "birthdate", "1980-10-01"],
|
5
|
-
[
|
6
|
-
"p-9LzyWHZBVDvhXDWkN2xA",
|
7
|
-
"place_of_birth",
|
8
|
-
{ country: "IT", locality: "Rome" },
|
9
|
-
],
|
10
|
-
];
|
11
|
-
describe("getValueFromDisclosures", () => {
|
12
|
-
it("should return correct value for given_name", () => {
|
13
|
-
const success = getValueFromDisclosures(disclosures, "given_name");
|
14
|
-
expect(success).toBe("Mario");
|
15
|
-
});
|
16
|
-
it("should return correct value for place_of_birth", () => {
|
17
|
-
const success = getValueFromDisclosures(disclosures, "place_of_birth");
|
18
|
-
expect(success).toEqual({ country: "IT", locality: "Rome" });
|
19
|
-
});
|
20
|
-
it("should fail", () => {
|
21
|
-
const success = getValueFromDisclosures(disclosures, "given_surname");
|
22
|
-
expect(success).toBeUndefined();
|
23
|
-
});
|
24
|
-
});
|
package/src/sd-jwt/verifier.js
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
import { sha256ToBase64 } from "@pagopa/io-react-native-jwt";
|
2
|
-
import { ValidationFailed } from "../utils/errors";
|
3
|
-
export const verifyDisclosure = async ({ encoded, decoded }, claims) => {
|
4
|
-
let hash = await sha256ToBase64(encoded);
|
5
|
-
if (!claims.includes(hash)) {
|
6
|
-
throw new ValidationFailed(
|
7
|
-
"Validation of disclosure failed",
|
8
|
-
`${decoded}`,
|
9
|
-
"Disclosure hash not found in claims"
|
10
|
-
);
|
11
|
-
}
|
12
|
-
};
|