@pagopa/io-react-native-wallet 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +98 -22
- package/lib/commonjs/index.js +12 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/pid/index.js +3 -8
- package/lib/commonjs/pid/index.js.map +1 -1
- package/lib/commonjs/pid/issuing.js +152 -168
- package/lib/commonjs/pid/issuing.js.map +1 -1
- package/lib/commonjs/pid/metadata.js +28 -25
- package/lib/commonjs/pid/metadata.js.map +1 -1
- package/lib/commonjs/rp/__test__/index.test.js +5 -3
- package/lib/commonjs/rp/__test__/index.test.js.map +1 -1
- package/lib/commonjs/rp/index.js +158 -154
- package/lib/commonjs/rp/index.js.map +1 -1
- package/lib/commonjs/trust/types.js +9 -7
- package/lib/commonjs/trust/types.js.map +1 -1
- package/lib/commonjs/utils/crypto.js +46 -0
- package/lib/commonjs/utils/crypto.js.map +1 -0
- package/lib/commonjs/utils/dpop.js +14 -7
- package/lib/commonjs/utils/dpop.js.map +1 -1
- package/lib/commonjs/wallet-instance-attestation/index.js +3 -3
- package/lib/commonjs/wallet-instance-attestation/issuing.js +50 -60
- package/lib/commonjs/wallet-instance-attestation/issuing.js.map +1 -1
- package/lib/module/index.js +4 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/pid/index.js +1 -1
- package/lib/module/pid/index.js.map +1 -1
- package/lib/module/pid/issuing.js +151 -171
- package/lib/module/pid/issuing.js.map +1 -1
- package/lib/module/pid/metadata.js +28 -25
- package/lib/module/pid/metadata.js.map +1 -1
- package/lib/module/rp/__test__/index.test.js +1 -1
- package/lib/module/rp/__test__/index.test.js.map +1 -1
- package/lib/module/rp/index.js +155 -153
- package/lib/module/rp/index.js.map +1 -1
- package/lib/module/trust/types.js +7 -6
- package/lib/module/trust/types.js.map +1 -1
- package/lib/module/utils/crypto.js +40 -0
- package/lib/module/utils/crypto.js.map +1 -0
- package/lib/module/utils/dpop.js +13 -5
- package/lib/module/utils/dpop.js.map +1 -1
- package/lib/module/wallet-instance-attestation/index.js +2 -2
- package/lib/module/wallet-instance-attestation/index.js.map +1 -1
- package/lib/module/wallet-instance-attestation/issuing.js +48 -58
- package/lib/module/wallet-instance-attestation/issuing.js.map +1 -1
- package/lib/typescript/index.d.ts +4 -3
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/pid/index.d.ts +1 -1
- package/lib/typescript/pid/index.d.ts.map +1 -1
- package/lib/typescript/pid/issuing.d.ts +51 -87
- package/lib/typescript/pid/issuing.d.ts.map +1 -1
- package/lib/typescript/pid/metadata.d.ts +1338 -408
- package/lib/typescript/pid/metadata.d.ts.map +1 -1
- package/lib/typescript/rp/index.d.ts +48 -86
- package/lib/typescript/rp/index.d.ts.map +1 -1
- package/lib/typescript/rp/types.d.ts +413 -57
- package/lib/typescript/rp/types.d.ts.map +1 -1
- package/lib/typescript/sd-jwt/index.d.ts +1 -1
- package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
- package/lib/typescript/trust/types.d.ts +1000 -274
- package/lib/typescript/trust/types.d.ts.map +1 -1
- package/lib/typescript/utils/crypto.d.ts +10 -0
- package/lib/typescript/utils/crypto.d.ts.map +1 -0
- package/lib/typescript/utils/dpop.d.ts +10 -2
- package/lib/typescript/utils/dpop.d.ts.map +1 -1
- package/lib/typescript/wallet-instance-attestation/index.d.ts +2 -2
- package/lib/typescript/wallet-instance-attestation/index.d.ts.map +1 -1
- package/lib/typescript/wallet-instance-attestation/issuing.d.ts +17 -31
- package/lib/typescript/wallet-instance-attestation/issuing.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +5 -3
- package/src/pid/index.ts +1 -1
- package/src/pid/issuing.ts +233 -225
- package/src/pid/metadata.ts +32 -27
- package/src/rp/__test__/index.test.ts +1 -1
- package/src/rp/index.ts +180 -188
- package/src/sd-jwt/index.ts +1 -1
- package/src/trust/types.ts +39 -32
- package/src/utils/crypto.ts +41 -0
- package/src/utils/dpop.ts +17 -7
- package/src/wallet-instance-attestation/index.ts +2 -2
- package/src/wallet-instance-attestation/issuing.ts +55 -62
@@ -1,4 +1,7 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
type CryptoContext,
|
3
|
+
decode as decodeJwt,
|
4
|
+
} from "@pagopa/io-react-native-jwt";
|
2
5
|
import { verify as verifyJwt } from "@pagopa/io-react-native-jwt";
|
3
6
|
import { SignJWT, thumbprint } from "@pagopa/io-react-native-jwt";
|
4
7
|
import { JWK, fixBase64EncodingOnKey } from "../utils/jwk";
|
@@ -6,73 +9,64 @@ import { WalletInstanceAttestationRequestJwt } from "./types";
|
|
6
9
|
import uuid from "react-native-uuid";
|
7
10
|
import { WalletInstanceAttestationIssuingError } from "../utils/errors";
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
)
|
16
|
-
|
17
|
-
this.appFetch = appFetch;
|
18
|
-
}
|
12
|
+
async function getAttestationRequest(
|
13
|
+
wiaCryptoContext: CryptoContext,
|
14
|
+
walletProviderBaseUrl: string
|
15
|
+
): Promise<string> {
|
16
|
+
const jwk = await wiaCryptoContext.getPublicKey();
|
17
|
+
const parsedJwk = JWK.parse(jwk);
|
18
|
+
const keyThumbprint = await thumbprint(parsedJwk);
|
19
|
+
const publicKey = { ...parsedJwk, kid: keyThumbprint };
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
*
|
23
|
-
* @async @function
|
24
|
-
*
|
25
|
-
* @param jwk Public key of the wallet instance
|
26
|
-
*
|
27
|
-
* @returns {string} Wallet Instance Attestation Request to sign
|
28
|
-
*
|
29
|
-
*/
|
30
|
-
async getAttestationRequestToSign(jwk: JWK): Promise<string> {
|
31
|
-
const parsedJwk = JWK.parse(jwk);
|
32
|
-
const keyThumbprint = await thumbprint(parsedJwk);
|
33
|
-
const publicKey = { ...parsedJwk, kid: keyThumbprint };
|
34
|
-
|
35
|
-
const walletInstanceAttestationRequest = new SignJWT({
|
21
|
+
return new SignJWT(wiaCryptoContext)
|
22
|
+
.setPayload({
|
36
23
|
iss: keyThumbprint,
|
37
|
-
aud:
|
24
|
+
aud: walletProviderBaseUrl,
|
38
25
|
jti: `${uuid.v4()}`,
|
39
26
|
nonce: `${uuid.v4()}`,
|
40
27
|
cnf: {
|
41
28
|
jwk: fixBase64EncodingOnKey(publicKey),
|
42
29
|
},
|
43
30
|
})
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
.
|
31
|
+
.setProtectedHeader({
|
32
|
+
kid: publicKey.kid,
|
33
|
+
typ: "wiar+jwt",
|
34
|
+
})
|
35
|
+
.setPayload({
|
36
|
+
iss: keyThumbprint,
|
37
|
+
sub: walletProviderBaseUrl,
|
38
|
+
jti: `${uuid.v4()}`,
|
39
|
+
type: "WalletInstanceAttestationRequest",
|
40
|
+
cnf: {
|
41
|
+
jwk: fixBase64EncodingOnKey(publicKey),
|
42
|
+
},
|
43
|
+
})
|
52
44
|
|
53
|
-
|
54
|
-
|
45
|
+
.setIssuedAt()
|
46
|
+
.setExpirationTime("1h")
|
47
|
+
.sign();
|
48
|
+
}
|
55
49
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
): Promise<string> {
|
73
|
-
const signedAttestationRequest = await
|
74
|
-
|
75
|
-
|
50
|
+
/**
|
51
|
+
* Request a Wallet Instance Attestation (WIA) to the Wallet provider
|
52
|
+
*
|
53
|
+
* @param params.wiaCryptoContext The key pair associated with the WIA. Will be use to prove the ownership of the attestation.
|
54
|
+
* @param params.appFetch (optional) Http client
|
55
|
+
* @param walletProviderBaseUrl Base url for the Wallet Provider
|
56
|
+
* @returns The retrieved Wallet Instance Attestation token
|
57
|
+
*/
|
58
|
+
export const getAttestation =
|
59
|
+
({
|
60
|
+
wiaCryptoContext,
|
61
|
+
appFetch = fetch,
|
62
|
+
}: {
|
63
|
+
wiaCryptoContext: CryptoContext;
|
64
|
+
appFetch?: GlobalFetch["fetch"];
|
65
|
+
}) =>
|
66
|
+
async (walletProviderBaseUrl: string): Promise<string> => {
|
67
|
+
const signedAttestationRequest = await getAttestationRequest(
|
68
|
+
wiaCryptoContext,
|
69
|
+
walletProviderBaseUrl
|
76
70
|
);
|
77
71
|
|
78
72
|
const decodedRequest = decodeJwt(signedAttestationRequest);
|
@@ -84,13 +78,13 @@ export class Issuing {
|
|
84
78
|
|
85
79
|
await verifyJwt(signedAttestationRequest, publicKey);
|
86
80
|
|
87
|
-
const tokenUrl = new URL("token",
|
81
|
+
const tokenUrl = new URL("token", walletProviderBaseUrl).href;
|
88
82
|
const requestBody = {
|
89
83
|
grant_type:
|
90
84
|
"urn:ietf:params:oauth:client-assertion-type:jwt-client-attestation",
|
91
85
|
assertion: signedAttestationRequest,
|
92
86
|
};
|
93
|
-
const response = await
|
87
|
+
const response = await appFetch(tokenUrl, {
|
94
88
|
method: "POST",
|
95
89
|
headers: {
|
96
90
|
"Content-Type": "application/json",
|
@@ -106,5 +100,4 @@ export class Issuing {
|
|
106
100
|
"Unable to obtain wallet instance attestation from wallet provider",
|
107
101
|
`Response code: ${response.status}`
|
108
102
|
);
|
109
|
-
}
|
110
|
-
}
|
103
|
+
};
|