diff --git a/example/src/App.tsx b/example/src/App.tsx index ee255a1b..1e5b15fb 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -11,8 +11,10 @@ import { } from "react-native"; import { PID, WalletInstanceAttestation } from "@pagopa/io-react-native-wallet"; +import { thumbprint } from "@pagopa/io-react-native-jwt"; const walletProviderBaseUrl = "https://io-d-wallet-it.azurewebsites.net"; +const pidProviderBaseUrl = "https://api.wakala.it/it-pid-provider/"; const pidToken = "eyJhbGciOiJFUzI1NiIsImtpZCI6IjV0NVlZcEJoTi1FZ0lFRUk1aVV6cjZyME1SMDJMblZRME9tZWttTktjalkiLCJ0cnVzdF9jaGFpbiI6W10sInR5cCI6InZjK3NkLWp3dCJ9.eyJzdWIiOiJMeExqRXJNUkd5cTRmb0ZCODh1TUxiVFQ2cS1rUHNITDhNTGktYloyUWRVIiwidmVyaWZpZWRfY2xhaW1zIjp7ImNsYWltcyI6eyJfc2QiOlsiSTllS2R6dk5oQWd1V3pGdFhPMmZiVUNaVWFoUDlwZkVaVXJaamhldGFEYyIsIm85OFVkeV90aVlvZzVJWFVibDVoMnJDSHhLYnljU1c0RDQ4Uno2V3JlejQiLCJaN3Fja1RnUjc0WjM2TFhtaDBXOFV0WkVka0Jta1pzUjVCTzRTenc3ZzY4IiwiMGswYTRoeXgyeWNHQVlITFFpMWJ4UU9MdnUzUUktdmNyYUZOLUFzX3VnMCIsIlZDV1NpY2w4cWcyUEcxN0VTSFN3NVBMdEFCdldYTy1oakR1TURuME5KTjQiLCI1QWJKOVlTRTR6TW9DTUZ6ZW4xMTV2QWtmSjJKc25qMVJ1WDVZb0ZkUzNJIl19LCJ2ZXJpZmljYXRpb24iOnsidHJ1c3RfZnJhbWV3b3JrIjoiZWlkYXMiLCJhc3N1cmFuY2VfbGV2ZWwiOiJoaWdoIiwiX3NkIjpbImZZZUVNcWE5WEFuQXQ0OFdmcVZlejQwSW1jVk1Jc1plYkp4a3F5TmlKcUEiXX19LCJfc2RfYWxnIjoic2hhLT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W5pcXVlX2lkIiwiaWRBTlBSIl0~WyJmdU5wOTdIZjN3VjZ5NDh5LVFaaElnIiwiYmlydGhkYXRlIiwiMTk4MC0xMC0wMSJd~WyJwLTlMenlXSFpCVkR2aFhEV2tOMnhBIiwicGxhY2Vfb2ZfYmlydGgiLHsiY291bnRyeSI6IklUIiwibG9jYWxpdHkiOiJSb21lIn1d~WyI5UnFLdWwzeHh6R2I4X1J1Zm5BSmZRIiwidGF4X2lkX251bWJlciIsIlRJTklULVJTU01SQTgwQTEwSDUwMUEiXQ"; @@ -44,34 +46,118 @@ export default function App() { const getAttestation = async () => { try { - const randomKeyTag = Math.random().toString(36).substr(2, 5); - const publicKey = await generate(randomKeyTag); + // generate Key for Wallet Instance Attestation + const walletInstanceKeyTag = Math.random().toString(36).substr(2, 5); + const walletInstancePublicKey = await generate(walletInstanceKeyTag); const issuingAttestation = new WalletInstanceAttestation.Issuing( walletProviderBaseUrl ); - const attestationRequest = - await issuingAttestation.getAttestationRequestToSign(publicKey); + await issuingAttestation.getAttestationRequestToSign( + walletInstancePublicKey + ); + const signature = await sign(attestationRequest, walletInstanceKeyTag); - const signature = await sign(attestationRequest, randomKeyTag); + // generate Wallet Instance Attestation const instanceAttestation = await issuingAttestation.getAttestation( attestationRequest, signature ); setResult(JSON.stringify(instanceAttestation)); - console.error(instanceAttestation); } catch (e) { console.error(e); showError(e); } }; + + const getPid = async () => { + try { + // generate Key for Wallet Instance Attestation + const walletInstanceKeyTag = Math.random().toString(36).substr(2, 5); + const walletInstancePublicKey = await generate(walletInstanceKeyTag); + const issuingAttestation = new WalletInstanceAttestation.Issuing( + walletProviderBaseUrl + ); + + const attestationRequest = + await issuingAttestation.getAttestationRequestToSign( + walletInstancePublicKey + ); + const signature = await sign(attestationRequest, walletInstanceKeyTag); + + // generate a fresh Wallet Instance Attestation + const instanceAttestation = await issuingAttestation.getAttestation( + attestationRequest, + signature + ); + + // clientId must be the Wallet Instance public key thumbprint + const clientId = await thumbprint(walletInstancePublicKey); + + // Start pid issuing flow + const issuingPID = new PID.Issuing( + pidProviderBaseUrl, + walletProviderBaseUrl, + instanceAttestation, + clientId + ); + + // Generate jwt for PAR wallet instance attestation + const unsignedJwtForPar = await issuingPID.getUnsignedJwtForPar( + walletInstancePublicKey + ); + const parSignature = await sign(unsignedJwtForPar, walletInstanceKeyTag); + + // PAR request + await issuingPID.getPar(unsignedJwtForPar, parSignature); + + // Token request + const authToken = await issuingPID.getAuthToken(); + + // Generate fresh key for PID binding + const pidKeyTag = Math.random().toString(36).substr(2, 5); + const pidKey = await generate(pidKeyTag); + + //Generate nonce proof + const unsignedNonceProof = await issuingPID.getUnsignedNonceProof( + authToken.c_nonce + ); + const nonceProofSignature = await sign(unsignedNonceProof, pidKeyTag); + + // Generate DPoP for PID key + const unsignedDPopForPid = await issuingPID.getUnsignedDPoP(pidKey); + const dPopPidSignature = await sign(unsignedDPopForPid, pidKeyTag); + + // Credential reuqest + const pid = await issuingPID.getCredential( + unsignedDPopForPid, + dPopPidSignature, + unsignedNonceProof, + nonceProofSignature, + authToken.access_token, + { + birthDate: "01/01/1990", + fiscalCode: "AAABBB00A00A000A", + name: "NAME", + surname: "SURNAME", + } + ); + + setResult(JSON.stringify(pid)); + } catch (e) { + console.error(e); + showError(e); + } + }; + return (