@pagopa/io-react-native-wallet 0.7.3 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +49 -31
- package/lib/commonjs/credential/index.js +13 -0
- package/lib/commonjs/credential/index.js.map +1 -0
- package/lib/commonjs/credential/issuance/01-start-flow.js +2 -0
- package/lib/commonjs/credential/issuance/01-start-flow.js.map +1 -0
- package/lib/commonjs/credential/issuance/02-evaluate-issuer-trust.js +26 -0
- package/lib/commonjs/credential/issuance/02-evaluate-issuer-trust.js.map +1 -0
- package/lib/commonjs/credential/issuance/03-start-user-authorization.js +119 -0
- package/lib/commonjs/credential/issuance/03-start-user-authorization.js.map +1 -0
- package/lib/commonjs/credential/issuance/04-complete-user-authorization.js +6 -0
- package/lib/commonjs/credential/issuance/04-complete-user-authorization.js.map +1 -0
- package/lib/commonjs/credential/issuance/05-authorize-access.js +63 -0
- package/lib/commonjs/credential/issuance/05-authorize-access.js.map +1 -0
- package/lib/commonjs/credential/issuance/06-obtain-credential.js +128 -0
- package/lib/commonjs/credential/issuance/06-obtain-credential.js.map +1 -0
- package/lib/commonjs/credential/issuance/07-confirm-credential.js +6 -0
- package/lib/commonjs/credential/issuance/07-confirm-credential.js.map +1 -0
- package/lib/commonjs/credential/issuance/const.js +9 -0
- package/lib/commonjs/credential/issuance/const.js.map +1 -0
- package/lib/commonjs/credential/issuance/index.js +34 -0
- package/lib/commonjs/credential/issuance/index.js.map +1 -0
- package/lib/commonjs/credential/presentation/01-start-flow.js +55 -0
- package/lib/commonjs/credential/presentation/01-start-flow.js.map +1 -0
- package/lib/commonjs/credential/presentation/02-evaluate-rp-trust.js +32 -0
- package/lib/commonjs/credential/presentation/02-evaluate-rp-trust.js.map +1 -0
- package/lib/commonjs/credential/presentation/03-get-request-object.js +68 -0
- package/lib/commonjs/credential/presentation/03-get-request-object.js.map +1 -0
- package/lib/commonjs/credential/presentation/04-send-authorization-response.js +139 -0
- package/lib/commonjs/credential/presentation/04-send-authorization-response.js.map +1 -0
- package/lib/commonjs/credential/presentation/index.js +34 -0
- package/lib/commonjs/credential/presentation/index.js.map +1 -0
- package/lib/commonjs/{rp → credential/presentation}/types.js +17 -34
- package/lib/commonjs/credential/presentation/types.js.map +1 -0
- package/lib/commonjs/index.js +10 -61
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/pid/index.js +1 -3
- package/lib/commonjs/pid/index.js.map +1 -1
- package/lib/commonjs/sd-jwt/index.js +1 -1
- package/lib/commonjs/sd-jwt/index.js.map +1 -1
- package/lib/commonjs/sd-jwt/types.js +1 -1
- package/lib/commonjs/sd-jwt/types.js.map +1 -1
- package/lib/commonjs/trust/chain.js +32 -4
- package/lib/commonjs/trust/chain.js.map +1 -1
- package/lib/commonjs/trust/index.js +105 -20
- package/lib/commonjs/trust/index.js.map +1 -1
- package/lib/commonjs/trust/types.js +54 -35
- package/lib/commonjs/trust/types.js.map +1 -1
- package/lib/commonjs/utils/crypto.js +4 -10
- package/lib/commonjs/utils/crypto.js.map +1 -1
- package/lib/commonjs/utils/misc.js +23 -0
- package/lib/commonjs/utils/misc.js.map +1 -0
- package/lib/commonjs/utils/par.js +86 -0
- package/lib/commonjs/utils/par.js.map +1 -0
- package/lib/module/credential/index.js +4 -0
- package/lib/module/credential/index.js.map +1 -0
- package/lib/module/credential/issuance/01-start-flow.js +2 -0
- package/lib/module/credential/issuance/01-start-flow.js.map +1 -0
- package/lib/module/credential/issuance/02-evaluate-issuer-trust.js +19 -0
- package/lib/module/credential/issuance/02-evaluate-issuer-trust.js.map +1 -0
- package/lib/module/credential/issuance/03-start-user-authorization.js +109 -0
- package/lib/module/credential/issuance/03-start-user-authorization.js.map +1 -0
- package/lib/module/credential/issuance/04-complete-user-authorization.js +2 -0
- package/lib/module/credential/issuance/04-complete-user-authorization.js.map +1 -0
- package/lib/module/credential/issuance/05-authorize-access.js +55 -0
- package/lib/module/credential/issuance/05-authorize-access.js.map +1 -0
- package/lib/module/credential/issuance/06-obtain-credential.js +117 -0
- package/lib/module/credential/issuance/06-obtain-credential.js.map +1 -0
- package/lib/module/credential/issuance/07-confirm-credential.js +2 -0
- package/lib/module/credential/issuance/07-confirm-credential.js.map +1 -0
- package/lib/module/credential/issuance/const.js +2 -0
- package/lib/module/credential/issuance/const.js.map +1 -0
- package/lib/module/credential/issuance/index.js +6 -0
- package/lib/module/credential/issuance/index.js.map +1 -0
- package/lib/module/credential/presentation/01-start-flow.js +46 -0
- package/lib/module/credential/presentation/01-start-flow.js.map +1 -0
- package/lib/module/credential/presentation/02-evaluate-rp-trust.js +25 -0
- package/lib/module/credential/presentation/02-evaluate-rp-trust.js.map +1 -0
- package/lib/module/credential/presentation/03-get-request-object.js +60 -0
- package/lib/module/credential/presentation/03-get-request-object.js.map +1 -0
- package/lib/module/credential/presentation/04-send-authorization-response.js +128 -0
- package/lib/module/credential/presentation/04-send-authorization-response.js.map +1 -0
- package/lib/module/credential/presentation/index.js +6 -0
- package/lib/module/credential/presentation/index.js.map +1 -0
- package/lib/module/credential/presentation/types.js +21 -0
- package/lib/module/credential/presentation/types.js.map +1 -0
- package/lib/module/index.js +4 -5
- package/lib/module/index.js.map +1 -1
- package/lib/module/pid/index.js +1 -2
- package/lib/module/pid/index.js.map +1 -1
- package/lib/module/sd-jwt/index.js +1 -1
- package/lib/module/sd-jwt/index.js.map +1 -1
- package/lib/module/sd-jwt/types.js +1 -1
- package/lib/module/sd-jwt/types.js.map +1 -1
- package/lib/module/trust/chain.js +30 -3
- package/lib/module/trust/chain.js.map +1 -1
- package/lib/module/trust/index.js +99 -16
- package/lib/module/trust/index.js.map +1 -1
- package/lib/module/trust/types.js +50 -31
- package/lib/module/trust/types.js.map +1 -1
- package/lib/module/utils/crypto.js +2 -8
- package/lib/module/utils/crypto.js.map +1 -1
- package/lib/module/utils/misc.js +17 -0
- package/lib/module/utils/misc.js.map +1 -0
- package/lib/module/utils/par.js +74 -0
- package/lib/module/utils/par.js.map +1 -0
- package/lib/typescript/credential/index.d.ts +4 -0
- package/lib/typescript/credential/index.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/01-start-flow.d.ts +11 -0
- package/lib/typescript/credential/issuance/01-start-flow.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/02-evaluate-issuer-trust.d.ts +18 -0
- package/lib/typescript/credential/issuance/02-evaluate-issuer-trust.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts +31 -0
- package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts +16 -0
- package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/05-authorize-access.d.ts +26 -0
- package/lib/typescript/credential/issuance/05-authorize-access.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/06-obtain-credential.d.ts +32 -0
- package/lib/typescript/credential/issuance/06-obtain-credential.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/07-confirm-credential.d.ts +11 -0
- package/lib/typescript/credential/issuance/07-confirm-credential.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/const.d.ts +2 -0
- package/lib/typescript/credential/issuance/const.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/index.d.ts +10 -0
- package/lib/typescript/credential/issuance/index.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/01-start-flow.d.ts +20 -0
- package/lib/typescript/credential/presentation/01-start-flow.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/02-evaluate-rp-trust.d.ts +18 -0
- package/lib/typescript/credential/presentation/02-evaluate-rp-trust.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/03-get-request-object.d.ts +25 -0
- package/lib/typescript/credential/presentation/03-get-request-object.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/04-send-authorization-response.d.ts +34 -0
- package/lib/typescript/credential/presentation/04-send-authorization-response.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/index.d.ts +7 -0
- package/lib/typescript/credential/presentation/index.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/types.d.ts +49 -0
- package/lib/typescript/credential/presentation/types.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +4 -5
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/pid/index.d.ts +1 -2
- package/lib/typescript/pid/index.d.ts.map +1 -1
- package/lib/typescript/sd-jwt/index.d.ts +2 -2
- package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
- package/lib/typescript/sd-jwt/types.d.ts +5 -5
- package/lib/typescript/trust/chain.d.ts +12 -3
- package/lib/typescript/trust/chain.d.ts.map +1 -1
- package/lib/typescript/trust/index.d.ts +198 -24
- package/lib/typescript/trust/index.d.ts.map +1 -1
- package/lib/typescript/trust/types.d.ts +1299 -623
- package/lib/typescript/trust/types.d.ts.map +1 -1
- package/lib/typescript/utils/crypto.d.ts +1 -1
- package/lib/typescript/utils/crypto.d.ts.map +1 -1
- package/lib/typescript/utils/dpop.d.ts +2 -2
- package/lib/typescript/utils/misc.d.ts +8 -0
- package/lib/typescript/utils/misc.d.ts.map +1 -0
- package/lib/typescript/utils/par.d.ts +68 -0
- package/lib/typescript/utils/par.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/credential/index.ts +4 -0
- package/src/credential/issuance/01-start-flow.ts +10 -0
- package/src/credential/issuance/02-evaluate-issuer-trust.ts +31 -0
- package/src/credential/issuance/03-start-user-authorization.ts +138 -0
- package/src/credential/issuance/04-complete-user-authorization.ts +17 -0
- package/src/credential/issuance/05-authorize-access.ts +92 -0
- package/src/credential/issuance/06-obtain-credential.ts +179 -0
- package/src/credential/issuance/07-confirm-credential.ts +14 -0
- package/src/credential/issuance/const.ts +2 -0
- package/src/credential/issuance/index.ts +32 -0
- package/src/credential/presentation/01-start-flow.ts +51 -0
- package/src/credential/presentation/02-evaluate-rp-trust.ts +33 -0
- package/src/credential/presentation/03-get-request-object.ts +85 -0
- package/src/credential/presentation/04-send-authorization-response.ts +168 -0
- package/src/credential/presentation/index.ts +26 -0
- package/src/credential/presentation/types.ts +27 -0
- package/src/index.ts +7 -28
- package/src/pid/index.ts +1 -2
- package/src/sd-jwt/index.ts +2 -2
- package/src/sd-jwt/types.ts +1 -1
- package/src/trust/chain.ts +45 -3
- package/src/trust/index.ts +136 -19
- package/src/trust/types.ts +57 -35
- package/src/utils/crypto.ts +2 -8
- package/src/utils/misc.ts +23 -0
- package/src/utils/par.ts +103 -0
- package/lib/commonjs/pid/issuing.js +0 -276
- package/lib/commonjs/pid/issuing.js.map +0 -1
- package/lib/commonjs/rp/__test__/index.test.js +0 -172
- package/lib/commonjs/rp/__test__/index.test.js.map +0 -1
- package/lib/commonjs/rp/index.js +0 -239
- package/lib/commonjs/rp/index.js.map +0 -1
- package/lib/commonjs/rp/types.js.map +0 -1
- package/lib/module/pid/issuing.js +0 -266
- package/lib/module/pid/issuing.js.map +0 -1
- package/lib/module/rp/__test__/index.test.js +0 -168
- package/lib/module/rp/__test__/index.test.js.map +0 -1
- package/lib/module/rp/index.js +0 -228
- package/lib/module/rp/index.js.map +0 -1
- package/lib/module/rp/types.js +0 -36
- package/lib/module/rp/types.js.map +0 -1
- package/lib/typescript/pid/issuing.d.ts +0 -57
- package/lib/typescript/pid/issuing.d.ts.map +0 -1
- package/lib/typescript/rp/__test__/index.test.d.ts +0 -2
- package/lib/typescript/rp/__test__/index.test.d.ts.map +0 -1
- package/lib/typescript/rp/index.d.ts +0 -43
- package/lib/typescript/rp/index.d.ts.map +0 -1
- package/lib/typescript/rp/types.d.ts +0 -122
- package/lib/typescript/rp/types.d.ts.map +0 -1
- package/src/pid/issuing.ts +0 -405
- package/src/rp/__test__/index.test.ts +0 -250
- package/src/rp/index.ts +0 -287
- package/src/rp/types.ts +0 -42
@@ -1,122 +0,0 @@
|
|
1
|
-
import * as z from "zod";
|
2
|
-
export type RequestObject = z.infer<typeof RequestObject>;
|
3
|
-
export declare const RequestObject: z.ZodObject<{
|
4
|
-
header: z.ZodObject<{
|
5
|
-
typ: z.ZodOptional<z.ZodLiteral<"JWT">>;
|
6
|
-
alg: z.ZodString;
|
7
|
-
kid: z.ZodString;
|
8
|
-
trust_chain: z.ZodArray<z.ZodString, "many">;
|
9
|
-
}, "strip", z.ZodTypeAny, {
|
10
|
-
alg: string;
|
11
|
-
kid: string;
|
12
|
-
trust_chain: string[];
|
13
|
-
typ?: "JWT" | undefined;
|
14
|
-
}, {
|
15
|
-
alg: string;
|
16
|
-
kid: string;
|
17
|
-
trust_chain: string[];
|
18
|
-
typ?: "JWT" | undefined;
|
19
|
-
}>;
|
20
|
-
payload: z.ZodObject<{
|
21
|
-
iss: z.ZodString;
|
22
|
-
iat: z.ZodNumber;
|
23
|
-
exp: z.ZodNumber;
|
24
|
-
state: z.ZodString;
|
25
|
-
nonce: z.ZodString;
|
26
|
-
response_uri: z.ZodString;
|
27
|
-
response_type: z.ZodLiteral<"vp_token">;
|
28
|
-
response_mode: z.ZodLiteral<"direct_post.jwt">;
|
29
|
-
client_id: z.ZodString;
|
30
|
-
client_id_scheme: z.ZodLiteral<"entity_id">;
|
31
|
-
scope: z.ZodString;
|
32
|
-
}, "strip", z.ZodTypeAny, {
|
33
|
-
iss: string;
|
34
|
-
iat: number;
|
35
|
-
exp: number;
|
36
|
-
client_id: string;
|
37
|
-
nonce: string;
|
38
|
-
state: string;
|
39
|
-
response_type: "vp_token";
|
40
|
-
response_uri: string;
|
41
|
-
response_mode: "direct_post.jwt";
|
42
|
-
client_id_scheme: "entity_id";
|
43
|
-
scope: string;
|
44
|
-
}, {
|
45
|
-
iss: string;
|
46
|
-
iat: number;
|
47
|
-
exp: number;
|
48
|
-
client_id: string;
|
49
|
-
nonce: string;
|
50
|
-
state: string;
|
51
|
-
response_type: "vp_token";
|
52
|
-
response_uri: string;
|
53
|
-
response_mode: "direct_post.jwt";
|
54
|
-
client_id_scheme: "entity_id";
|
55
|
-
scope: string;
|
56
|
-
}>;
|
57
|
-
}, "strip", z.ZodTypeAny, {
|
58
|
-
header: {
|
59
|
-
alg: string;
|
60
|
-
kid: string;
|
61
|
-
trust_chain: string[];
|
62
|
-
typ?: "JWT" | undefined;
|
63
|
-
};
|
64
|
-
payload: {
|
65
|
-
iss: string;
|
66
|
-
iat: number;
|
67
|
-
exp: number;
|
68
|
-
client_id: string;
|
69
|
-
nonce: string;
|
70
|
-
state: string;
|
71
|
-
response_type: "vp_token";
|
72
|
-
response_uri: string;
|
73
|
-
response_mode: "direct_post.jwt";
|
74
|
-
client_id_scheme: "entity_id";
|
75
|
-
scope: string;
|
76
|
-
};
|
77
|
-
}, {
|
78
|
-
header: {
|
79
|
-
alg: string;
|
80
|
-
kid: string;
|
81
|
-
trust_chain: string[];
|
82
|
-
typ?: "JWT" | undefined;
|
83
|
-
};
|
84
|
-
payload: {
|
85
|
-
iss: string;
|
86
|
-
iat: number;
|
87
|
-
exp: number;
|
88
|
-
client_id: string;
|
89
|
-
nonce: string;
|
90
|
-
state: string;
|
91
|
-
response_type: "vp_token";
|
92
|
-
response_uri: string;
|
93
|
-
response_mode: "direct_post.jwt";
|
94
|
-
client_id_scheme: "entity_id";
|
95
|
-
scope: string;
|
96
|
-
};
|
97
|
-
}>;
|
98
|
-
export type QRCodePayload = z.infer<typeof QRCodePayload>;
|
99
|
-
export declare const QRCodePayload: z.ZodObject<{
|
100
|
-
protocol: z.ZodString;
|
101
|
-
resource: z.ZodString;
|
102
|
-
clientId: z.ZodString;
|
103
|
-
requestURI: z.ZodString;
|
104
|
-
}, "strip", z.ZodTypeAny, {
|
105
|
-
clientId: string;
|
106
|
-
protocol: string;
|
107
|
-
resource: string;
|
108
|
-
requestURI: string;
|
109
|
-
}, {
|
110
|
-
clientId: string;
|
111
|
-
protocol: string;
|
112
|
-
resource: string;
|
113
|
-
requestURI: string;
|
114
|
-
}>;
|
115
|
-
/**
|
116
|
-
* A pair that associate a tokenized Verified Credential with the claims presented or requested to present.
|
117
|
-
*/
|
118
|
-
export type Presentation = [
|
119
|
-
string,
|
120
|
-
string[]
|
121
|
-
];
|
122
|
-
//# sourceMappingURL=types.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/rp/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAC1D,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqBxB,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAC1D,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;EAKxB,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACO,MAAM;IACzB,MAAM,EAAE;CACtB,CAAC"}
|
package/src/pid/issuing.ts
DELETED
@@ -1,405 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
sha256ToBase64,
|
3
|
-
type CryptoContext,
|
4
|
-
SignJWT,
|
5
|
-
thumbprint,
|
6
|
-
} from "@pagopa/io-react-native-jwt";
|
7
|
-
|
8
|
-
import { JWK } from "../utils/jwk";
|
9
|
-
import uuid from "react-native-uuid";
|
10
|
-
import { PidIssuingError } from "../utils/errors";
|
11
|
-
import { createDPopToken } from "../utils/dpop";
|
12
|
-
import { CredentialIssuerEntityConfiguration } from "../trust/types";
|
13
|
-
import * as WalletInstanceAttestation from "../wallet-instance-attestation";
|
14
|
-
import { SdJwt } from ".";
|
15
|
-
import { useEphemeralKey } from "../utils/crypto";
|
16
|
-
|
17
|
-
import * as z from "zod";
|
18
|
-
import { getJwtFromFormPost } from "../utils/decoder";
|
19
|
-
|
20
|
-
// This is a temporary type that will be used for demo purposes only
|
21
|
-
export type CieData = {
|
22
|
-
birthDate: string;
|
23
|
-
fiscalCode: string;
|
24
|
-
name: string;
|
25
|
-
surname: string;
|
26
|
-
};
|
27
|
-
|
28
|
-
export type AuthorizationConf = {
|
29
|
-
accessToken: string;
|
30
|
-
nonce: string;
|
31
|
-
clientId: string;
|
32
|
-
authorizationCode: string;
|
33
|
-
codeVerifier: string;
|
34
|
-
walletProviderBaseUrl: string;
|
35
|
-
};
|
36
|
-
|
37
|
-
export type PidResponse = {
|
38
|
-
credential: string;
|
39
|
-
c_nonce: string;
|
40
|
-
c_nonce_expires_in: number;
|
41
|
-
format: string;
|
42
|
-
};
|
43
|
-
|
44
|
-
type AuthenticationRequestResponse = z.infer<
|
45
|
-
typeof AuthenticationRequestResponse
|
46
|
-
>;
|
47
|
-
const AuthenticationRequestResponse = z.object({
|
48
|
-
code: z.string(),
|
49
|
-
state: z.string(), // TODO: refine to known paths using literals
|
50
|
-
iss: z.string(),
|
51
|
-
});
|
52
|
-
|
53
|
-
const assertionType =
|
54
|
-
"urn:ietf:params:oauth:client-assertion-type:jwt-client-attestation";
|
55
|
-
|
56
|
-
/**
|
57
|
-
* Make a PAR request to the PID issuer and return the response url
|
58
|
-
*/
|
59
|
-
const getPar =
|
60
|
-
({
|
61
|
-
wiaCryptoContext,
|
62
|
-
appFetch = fetch,
|
63
|
-
}: {
|
64
|
-
wiaCryptoContext: CryptoContext;
|
65
|
-
appFetch?: GlobalFetch["fetch"];
|
66
|
-
}) =>
|
67
|
-
async (
|
68
|
-
clientId: string,
|
69
|
-
codeVerifier: string,
|
70
|
-
walletProviderBaseUrl: string,
|
71
|
-
pidProviderEntityConfiguration: CredentialIssuerEntityConfiguration,
|
72
|
-
walletInstanceAttestation: string
|
73
|
-
): Promise<string> => {
|
74
|
-
// Calculate the thumbprint of the public key of the Wallet Instance Attestation.
|
75
|
-
// The PAR request token is signed used the Wallet Instance Attestation key.
|
76
|
-
// The signature can be verified by reading the public key from the key set shippet with the it will ship the Wallet Instance Attestation;
|
77
|
-
// key is matched by its kid, which is supposed to be the thumbprint of its public key.
|
78
|
-
const keyThumbprint = await wiaCryptoContext
|
79
|
-
.getPublicKey()
|
80
|
-
.then(JWK.parse)
|
81
|
-
.then(thumbprint);
|
82
|
-
|
83
|
-
const iss = WalletInstanceAttestation.decode(walletInstanceAttestation)
|
84
|
-
.payload.cnf.jwk.kid;
|
85
|
-
|
86
|
-
const codeChallenge = await sha256ToBase64(codeVerifier);
|
87
|
-
|
88
|
-
const signedJwtForPar = await new SignJWT(wiaCryptoContext)
|
89
|
-
.setProtectedHeader({
|
90
|
-
kid: keyThumbprint,
|
91
|
-
})
|
92
|
-
.setPayload({
|
93
|
-
iss,
|
94
|
-
aud: pidProviderEntityConfiguration.payload.iss,
|
95
|
-
jti: `${uuid.v4()}`,
|
96
|
-
client_assertion_type: assertionType,
|
97
|
-
authorization_details: [
|
98
|
-
{
|
99
|
-
credential_definition: {
|
100
|
-
type: "PersonIdentificationData",
|
101
|
-
},
|
102
|
-
format: "vc+sd-jwt",
|
103
|
-
type: "openid_credential",
|
104
|
-
},
|
105
|
-
],
|
106
|
-
response_type: "code",
|
107
|
-
code_challenge_method: "s256",
|
108
|
-
redirect_uri: walletProviderBaseUrl,
|
109
|
-
state: `${uuid.v4()}`,
|
110
|
-
client_id: clientId,
|
111
|
-
code_challenge: codeChallenge,
|
112
|
-
})
|
113
|
-
.setIssuedAt()
|
114
|
-
.setExpirationTime("1h")
|
115
|
-
.sign();
|
116
|
-
|
117
|
-
const parUrl =
|
118
|
-
pidProviderEntityConfiguration.payload.metadata.openid_credential_issuer
|
119
|
-
.pushed_authorization_request_endpoint;
|
120
|
-
|
121
|
-
const requestBody = {
|
122
|
-
response_type: "code",
|
123
|
-
client_id: clientId,
|
124
|
-
code_challenge: codeChallenge,
|
125
|
-
code_challenge_method: "S256",
|
126
|
-
client_assertion_type: assertionType,
|
127
|
-
client_assertion: walletInstanceAttestation,
|
128
|
-
request: signedJwtForPar,
|
129
|
-
};
|
130
|
-
|
131
|
-
var formBody = new URLSearchParams(requestBody);
|
132
|
-
|
133
|
-
const response = await appFetch(parUrl, {
|
134
|
-
method: "POST",
|
135
|
-
headers: {
|
136
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
137
|
-
},
|
138
|
-
body: formBody.toString(),
|
139
|
-
});
|
140
|
-
|
141
|
-
if (response.status === 201) {
|
142
|
-
const result = await response.json();
|
143
|
-
return result.request_uri;
|
144
|
-
}
|
145
|
-
|
146
|
-
throw new PidIssuingError(
|
147
|
-
`Unable to obtain PAR. Response code: ${await response.text()}`
|
148
|
-
);
|
149
|
-
};
|
150
|
-
|
151
|
-
/**
|
152
|
-
* Make an authorization request
|
153
|
-
*/
|
154
|
-
const getAuthenticationRequest =
|
155
|
-
({ appFetch = fetch }: { appFetch?: GlobalFetch["fetch"] }) =>
|
156
|
-
async (
|
157
|
-
clientId: string,
|
158
|
-
requestUri: string,
|
159
|
-
pidProviderEntityConfiguration: CredentialIssuerEntityConfiguration,
|
160
|
-
cieData: CieData
|
161
|
-
): Promise<AuthenticationRequestResponse> => {
|
162
|
-
const authzRequestEndpoint =
|
163
|
-
pidProviderEntityConfiguration.payload.metadata.openid_credential_issuer
|
164
|
-
.authorization_endpoint;
|
165
|
-
|
166
|
-
/* User's personal data is not supposed to transit in this flow,
|
167
|
-
* but to be provided to the PID issuer directly by its chosen authentication method (CIE).
|
168
|
-
* Being the project in an initial phase, and being we were still unable to fully comply with authentication,
|
169
|
-
* we temporarily provide data from the App's logged user.
|
170
|
-
* */
|
171
|
-
const params = new URLSearchParams({
|
172
|
-
client_id: clientId,
|
173
|
-
request_uri: requestUri,
|
174
|
-
name: cieData.name,
|
175
|
-
surname: cieData.surname,
|
176
|
-
birth_date: cieData.birthDate,
|
177
|
-
fiscal_code: cieData.fiscalCode,
|
178
|
-
});
|
179
|
-
|
180
|
-
const response = await appFetch(authzRequestEndpoint + "?" + params, {
|
181
|
-
method: "GET",
|
182
|
-
});
|
183
|
-
|
184
|
-
if (response.status === 200) {
|
185
|
-
const formData = await response.text();
|
186
|
-
const { decodedJwt } = await getJwtFromFormPost(formData);
|
187
|
-
const parsed = AuthenticationRequestResponse.parse(decodedJwt.payload);
|
188
|
-
return parsed;
|
189
|
-
}
|
190
|
-
|
191
|
-
throw new PidIssuingError(
|
192
|
-
`Unable to obtain Authorization Request. Response code: ${await response.text()}`
|
193
|
-
);
|
194
|
-
};
|
195
|
-
|
196
|
-
/**
|
197
|
-
* Start the issuing flow by generating an authorization request to the PID Provider. Obtain from the PID Provider an access token to be used to complete the issuing flow.
|
198
|
-
*
|
199
|
-
* @param params.wiaCryptoContext The key pair associated with the WIA. Will be use to prove the ownership of the attestation.
|
200
|
-
* @param params.appFetch (optional) Http client
|
201
|
-
* @param walletInstanceAttestation Wallet Instance Attestation token.
|
202
|
-
* @param walletProviderBaseUrl Base url for the Wallet Provider.
|
203
|
-
* @param pidProviderEntityConfiguration The Entity Configuration of the PID Provider, from which discover public endooints.
|
204
|
-
* @param cieData Data red from the CIE login process
|
205
|
-
* @returns The access token along with the values that identify the issuing session.
|
206
|
-
*/
|
207
|
-
export const authorizeIssuing =
|
208
|
-
({
|
209
|
-
wiaCryptoContext,
|
210
|
-
appFetch = fetch,
|
211
|
-
}: {
|
212
|
-
wiaCryptoContext: CryptoContext;
|
213
|
-
appFetch?: GlobalFetch["fetch"];
|
214
|
-
}) =>
|
215
|
-
async (
|
216
|
-
walletInstanceAttestation: string,
|
217
|
-
walletProviderBaseUrl: string,
|
218
|
-
pidProviderEntityConfiguration: CredentialIssuerEntityConfiguration,
|
219
|
-
cieData: CieData
|
220
|
-
): Promise<AuthorizationConf> => {
|
221
|
-
// FIXME: do better
|
222
|
-
const clientId = await wiaCryptoContext.getPublicKey().then((_) => _.kid);
|
223
|
-
const codeVerifier = `${uuid.v4()}`;
|
224
|
-
|
225
|
-
const tokenUrl =
|
226
|
-
pidProviderEntityConfiguration.payload.metadata.openid_credential_issuer
|
227
|
-
.token_endpoint;
|
228
|
-
|
229
|
-
const requestUri = await getPar({ wiaCryptoContext, appFetch })(
|
230
|
-
clientId,
|
231
|
-
codeVerifier,
|
232
|
-
walletProviderBaseUrl,
|
233
|
-
pidProviderEntityConfiguration,
|
234
|
-
walletInstanceAttestation
|
235
|
-
);
|
236
|
-
|
237
|
-
const authenticationRequest = await getAuthenticationRequest({})(
|
238
|
-
clientId,
|
239
|
-
requestUri,
|
240
|
-
pidProviderEntityConfiguration,
|
241
|
-
cieData
|
242
|
-
);
|
243
|
-
|
244
|
-
const authorizationCode = authenticationRequest.code;
|
245
|
-
|
246
|
-
const signedDPop = await useEphemeralKey((ctx) =>
|
247
|
-
createDPopToken(
|
248
|
-
{
|
249
|
-
htm: "POST",
|
250
|
-
htu: tokenUrl,
|
251
|
-
jti: `${uuid.v4()}`,
|
252
|
-
},
|
253
|
-
ctx
|
254
|
-
)
|
255
|
-
);
|
256
|
-
|
257
|
-
const requestBody = {
|
258
|
-
grant_type: "authorization code",
|
259
|
-
client_id: clientId,
|
260
|
-
code: authorizationCode,
|
261
|
-
code_verifier: codeVerifier,
|
262
|
-
client_assertion_type: assertionType,
|
263
|
-
client_assertion: walletInstanceAttestation,
|
264
|
-
redirect_uri: walletProviderBaseUrl,
|
265
|
-
};
|
266
|
-
var formBody = new URLSearchParams(requestBody);
|
267
|
-
|
268
|
-
const response = await appFetch(tokenUrl, {
|
269
|
-
method: "POST",
|
270
|
-
headers: {
|
271
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
272
|
-
DPoP: signedDPop,
|
273
|
-
},
|
274
|
-
body: formBody.toString(),
|
275
|
-
});
|
276
|
-
|
277
|
-
if (response.status === 200) {
|
278
|
-
const { c_nonce, access_token } = await response.json();
|
279
|
-
return {
|
280
|
-
accessToken: access_token,
|
281
|
-
nonce: c_nonce,
|
282
|
-
clientId,
|
283
|
-
codeVerifier,
|
284
|
-
authorizationCode,
|
285
|
-
walletProviderBaseUrl,
|
286
|
-
};
|
287
|
-
}
|
288
|
-
|
289
|
-
throw new PidIssuingError(
|
290
|
-
`Unable to obtain token. Response code: ${await response.text()}`
|
291
|
-
);
|
292
|
-
};
|
293
|
-
|
294
|
-
/**
|
295
|
-
* Return the signed jwt for nonce proof of possession
|
296
|
-
*/
|
297
|
-
const createNonceProof = async (
|
298
|
-
nonce: string,
|
299
|
-
issuer: string,
|
300
|
-
audience: string,
|
301
|
-
ctx: CryptoContext
|
302
|
-
): Promise<string> => {
|
303
|
-
return new SignJWT(ctx)
|
304
|
-
.setPayload({
|
305
|
-
nonce,
|
306
|
-
jwk: await ctx.getPublicKey(),
|
307
|
-
})
|
308
|
-
.setProtectedHeader({
|
309
|
-
type: "openid4vci-proof+jwt",
|
310
|
-
})
|
311
|
-
.setAudience(audience)
|
312
|
-
.setIssuer(issuer)
|
313
|
-
.setIssuedAt()
|
314
|
-
.setExpirationTime("1h")
|
315
|
-
.sign();
|
316
|
-
};
|
317
|
-
|
318
|
-
/**
|
319
|
-
* Complete the issuing flow and get the PID credential.
|
320
|
-
*
|
321
|
-
* @param params.pidCryptoContext The key pair associated with the PID. Will be use to prove the ownership of the credential.
|
322
|
-
* @param params.appFetch (optional) Http client
|
323
|
-
* @param authConf The authorization configuration retrieved with the access token
|
324
|
-
* @returns The PID credential token
|
325
|
-
*/
|
326
|
-
export const getCredential =
|
327
|
-
({
|
328
|
-
pidCryptoContext,
|
329
|
-
appFetch = fetch,
|
330
|
-
}: {
|
331
|
-
pidCryptoContext: CryptoContext;
|
332
|
-
appFetch?: GlobalFetch["fetch"];
|
333
|
-
}) =>
|
334
|
-
async (
|
335
|
-
{ nonce, accessToken, clientId, walletProviderBaseUrl }: AuthorizationConf,
|
336
|
-
pidProviderEntityConfiguration: CredentialIssuerEntityConfiguration
|
337
|
-
): Promise<PidResponse> => {
|
338
|
-
const credentialUrl =
|
339
|
-
pidProviderEntityConfiguration.payload.metadata.openid_credential_issuer
|
340
|
-
.credential_endpoint;
|
341
|
-
|
342
|
-
const signedDPopForPid = await createDPopToken(
|
343
|
-
{
|
344
|
-
htm: "POST",
|
345
|
-
htu: credentialUrl,
|
346
|
-
jti: `${uuid.v4()}`,
|
347
|
-
},
|
348
|
-
pidCryptoContext
|
349
|
-
);
|
350
|
-
|
351
|
-
const signedNonceProof = await createNonceProof(
|
352
|
-
nonce,
|
353
|
-
clientId,
|
354
|
-
walletProviderBaseUrl,
|
355
|
-
pidCryptoContext
|
356
|
-
);
|
357
|
-
|
358
|
-
const requestBody = {
|
359
|
-
credential_definition: JSON.stringify({
|
360
|
-
type: ["PersonIdentificationData"],
|
361
|
-
}),
|
362
|
-
format: "vc+sd-jwt",
|
363
|
-
proof: JSON.stringify({
|
364
|
-
jwt: signedNonceProof,
|
365
|
-
proof_type: "jwt",
|
366
|
-
}),
|
367
|
-
};
|
368
|
-
const formBody = new URLSearchParams(requestBody);
|
369
|
-
|
370
|
-
const response = await appFetch(credentialUrl, {
|
371
|
-
method: "POST",
|
372
|
-
headers: {
|
373
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
374
|
-
DPoP: signedDPopForPid,
|
375
|
-
Authorization: accessToken,
|
376
|
-
},
|
377
|
-
body: formBody.toString(),
|
378
|
-
});
|
379
|
-
|
380
|
-
if (response.status === 200) {
|
381
|
-
const pidResponse = (await response.json()) as PidResponse;
|
382
|
-
await validatePid(pidResponse.credential, pidCryptoContext);
|
383
|
-
return pidResponse;
|
384
|
-
}
|
385
|
-
|
386
|
-
throw new PidIssuingError(
|
387
|
-
`Unable to obtain credential! url=${credentialUrl} status=${
|
388
|
-
response.status
|
389
|
-
} body=${await response.text()}`
|
390
|
-
);
|
391
|
-
};
|
392
|
-
|
393
|
-
const validatePid = async (pidJwt: string, pidCryptoContext: CryptoContext) => {
|
394
|
-
const decoded = SdJwt.decode(pidJwt);
|
395
|
-
const pidKey = await pidCryptoContext.getPublicKey();
|
396
|
-
const holderBindedKey = decoded.sdJwt.payload.cnf.jwk;
|
397
|
-
|
398
|
-
if ((await thumbprint(pidKey)) !== (await thumbprint(holderBindedKey))) {
|
399
|
-
throw new PidIssuingError(
|
400
|
-
`The obtained pid does not seem to be valid according to your configuration. Your PID public key is: ${JSON.stringify(
|
401
|
-
pidKey
|
402
|
-
)} but PID holder binded key is: ${JSON.stringify(holderBindedKey)}`
|
403
|
-
);
|
404
|
-
}
|
405
|
-
};
|