From a10d423f670d334b614f9e84109ddfe8c0583957 Mon Sep 17 00:00:00 2001 From: RiccardoMolinari95 Date: Thu, 2 Jan 2025 16:43:05 +0100 Subject: [PATCH 1/3] chore: use uuid lib than react-native-uuid --- example/index.js | 1 + example/ios/Podfile.lock | 6 ++++++ example/package.json | 1 + example/src/thunks/pid.ts | 4 ++-- example/src/utils/credential.ts | 6 +++--- example/src/utils/integrity.ts | 4 ++-- example/yarn.lock | 12 ++++++++++++ package.json | 2 +- .../issuance/04-complete-user-authorization.ts | 10 +++++----- src/credential/issuance/05-authorize-access.ts | 6 +++--- src/credential/issuance/06-obtain-credential.ts | 4 ++-- src/credential/issuance/README.md | 4 ++-- src/credential/presentation/03-get-request-object.ts | 4 ++-- .../presentation/04-send-authorization-response.ts | 8 ++++---- src/credential/status/02-status-attestation.ts | 4 ++-- src/utils/crypto.ts | 4 ++-- src/utils/par.ts | 6 +++--- yarn.lock | 10 +++++----- 18 files changed, 58 insertions(+), 38 deletions(-) diff --git a/example/index.js b/example/index.js index 8eab8b25..efaa30fc 100644 --- a/example/index.js +++ b/example/index.js @@ -1,3 +1,4 @@ +import 'react-native-get-random-values'; import { AppRegistry } from "react-native"; import App from "./src/App"; import { name as appName } from "./app.json"; diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 8bc49c57..17755633 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -389,6 +389,8 @@ PODS: - React-jsinspector (0.72.14) - React-logger (0.72.14): - glog + - react-native-get-random-values (1.11.0): + - React-Core - react-native-safe-area-context (4.10.8): - React-Core - react-native-webview (13.10.5): @@ -590,6 +592,7 @@ DEPENDENCIES: - React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`) - React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`) - React-logger (from `../node_modules/react-native/ReactCommon/logger`) + - react-native-get-random-values (from `../node_modules/react-native-get-random-values`) - react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`) - react-native-webview (from `../node_modules/react-native-webview`) - React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`) @@ -688,6 +691,8 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/ReactCommon/jsinspector" React-logger: :path: "../node_modules/react-native/ReactCommon/logger" + react-native-get-random-values: + :path: "../node_modules/react-native-get-random-values" react-native-safe-area-context: :path: "../node_modules/react-native-safe-area-context" react-native-webview: @@ -782,6 +787,7 @@ SPEC CHECKSUMS: React-jsiexecutor: e9a70be9304ef2e66eeebac35710f958b076dc14 React-jsinspector: 275d9f80210f15f0af9a4b7fd5683fab9738e28e React-logger: 8da4802de77a0eb62512396ad6bb1769904c2f0e + react-native-get-random-values: 21325b2244dfa6b58878f51f9aa42821e7ba3d06 react-native-safe-area-context: b7daa1a8df36095a032dff095a1ea8963cb48371 react-native-webview: f1745c33e5278e7c58ff7b8aff48dbb801395269 React-NativeModulesApple: 3107f777453f953906d9ba9dc5f8cbd91a6ef913 diff --git a/example/package.json b/example/package.json index 27d2652b..3a0cf8d8 100644 --- a/example/package.json +++ b/example/package.json @@ -30,6 +30,7 @@ "react": "18.2.0", "react-native": "0.72.14", "react-native-gesture-handler": "^2.18.1", + "react-native-get-random-values": "^1.11.0", "react-native-haptic-feedback": "^2.3.1", "react-native-qrcode-svg": "^6.3.12", "react-native-reanimated": "^3.15.1", diff --git a/example/src/thunks/pid.ts b/example/src/thunks/pid.ts index 29ac0a87..3bd3367a 100644 --- a/example/src/thunks/pid.ts +++ b/example/src/thunks/pid.ts @@ -4,7 +4,7 @@ import { Credential, WalletInstanceAttestation, } from "@pagopa/io-react-native-wallet"; -import uuid from "react-native-uuid"; +import { v4 as uuidv4 } from 'uuid'; import { selectAttestation, shouldRequestAttestationSelector, @@ -194,7 +194,7 @@ export const continuePidFlowThunk = createAppAsyncThunk< const wiaCryptoContext = createCryptoContextFor(WIA_KEYTAG); // Create credential crypto context - const credentialKeyTag = uuid.v4().toString(); + const credentialKeyTag = uuidv4().toString(); await generate(credentialKeyTag); const credentialCryptoContext = createCryptoContextFor(credentialKeyTag); diff --git a/example/src/utils/credential.ts b/example/src/utils/credential.ts index 43d2895e..afec55f3 100644 --- a/example/src/utils/credential.ts +++ b/example/src/utils/credential.ts @@ -2,7 +2,7 @@ import { Credential, createCryptoContextFor, } from "@pagopa/io-react-native-wallet"; -import uuid from "react-native-uuid"; +import { v4 as uuidv4 } from 'uuid'; import { generate } from "@pagopa/io-react-native-crypto"; import appFetch from "../utils/fetch"; import { DPOP_KEYTAG, regenerateCryptoKey } from "../utils/crypto"; @@ -43,7 +43,7 @@ export const getPidCieID = async ({ * Create credential crypto context for the PID * WARNING: The eID keytag must be persisted and later used when requesting a credential which requires a eID presentation */ - const credentialKeyTag = uuid.v4().toString(); + const credentialKeyTag = uuidv4().toString(); await generate(credentialKeyTag); const credentialCryptoContext = createCryptoContextFor(credentialKeyTag); @@ -172,7 +172,7 @@ export const getCredential = async ({ pidCryptoContext: CryptoContext; }): Promise => { // Create credential crypto context - const credentialKeyTag = uuid.v4().toString(); + const credentialKeyTag = uuidv4().toString(); await generate(credentialKeyTag); const credentialCryptoContext = createCryptoContextFor(credentialKeyTag); diff --git a/example/src/utils/integrity.ts b/example/src/utils/integrity.ts index e899f5df..bdf2207b 100644 --- a/example/src/utils/integrity.ts +++ b/example/src/utils/integrity.ts @@ -10,7 +10,7 @@ import { requestIntegrityToken, } from "@pagopa/io-react-native-integrity"; import { Platform } from "react-native"; -import uuid from "react-native-uuid"; +import { v4 as uuidv4 } from 'uuid'; import { addPadding, removePadding } from "@pagopa/io-react-native-jwt"; import { sha256 } from "js-sha256"; import type { IntegrityContext } from "@pagopa/io-react-native-wallet"; @@ -63,7 +63,7 @@ const generateIntegrityHardwareKeyTag = () => return removePadding(key); }, android: async () => { - const keyTag = uuid.v4().toString(); + const keyTag = uuidv4().toString(); await generate(keyTag); return keyTag; }, diff --git a/example/yarn.lock b/example/yarn.lock index 64d1f917..f807251c 100644 --- a/example/yarn.lock +++ b/example/yarn.lock @@ -3442,6 +3442,11 @@ execa@^5.0.0: signal-exit "^3.0.3" strip-final-newline "^2.0.0" +fast-base64-decode@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fast-base64-decode/-/fast-base64-decode-1.0.0.tgz#b434a0dd7d92b12b43f26819300d2dafb83ee418" + integrity sha512-qwaScUgUGBYeDNRnbc/KyllVU88Jk1pRHPStuF/lO7B0/RTRLj7U0lkdTAutlBblY08rwZDff6tNU9cjv6j//Q== + fast-deep-equal@^3.1.3: version "3.1.3" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525" @@ -5437,6 +5442,13 @@ react-native-gesture-handler@^2.12.0, react-native-gesture-handler@^2.18.1: invariant "^2.2.4" prop-types "^15.7.2" +react-native-get-random-values@^1.11.0: + version "1.11.0" + resolved "https://registry.yarnpkg.com/react-native-get-random-values/-/react-native-get-random-values-1.11.0.tgz#1ca70d1271f4b08af92958803b89dccbda78728d" + integrity sha512-4BTbDbRmS7iPdhYLRcz3PGFIpFJBwNZg9g42iwa2P6FOv9vZj/xJc678RZXnLNZzd0qd7Q3CCF6Yd+CU2eoXKQ== + dependencies: + fast-base64-decode "^1.0.0" + react-native-haptic-feedback@^2.0.2, react-native-haptic-feedback@^2.3.1: version "2.3.1" resolved "https://registry.yarnpkg.com/react-native-haptic-feedback/-/react-native-haptic-feedback-2.3.1.tgz#2ef4ac7d4f63ac06bd64b659f509362f127b16e5" diff --git a/package.json b/package.json index b02b3e32..c4d555f3 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,7 @@ "js-sha256": "^0.9.0", "parse-url": "^9.2.0", "react-native-url-polyfill": "^2.0.0", - "react-native-uuid": "^2.0.1", + "uuid": "^11.0.3", "zod": "^3.21.4" } } diff --git a/src/credential/issuance/04-complete-user-authorization.ts b/src/credential/issuance/04-complete-user-authorization.ts index 787f7033..7541086c 100644 --- a/src/credential/issuance/04-complete-user-authorization.ts +++ b/src/credential/issuance/04-complete-user-authorization.ts @@ -15,7 +15,7 @@ import { type CryptoContext, } from "@pagopa/io-react-native-jwt"; import { RequestObject } from "../presentation/types"; -import uuid from "react-native-uuid"; +import { v4 as uuidv4 } from 'uuid'; import { ResponseUriResultShape } from "./types"; import { getJwtFromFormPost } from "../../utils/decoder"; import { AuthorizationError, AuthorizationIdpError } from "./errors"; @@ -169,7 +169,7 @@ export const completeUserAuthorizationWithFormPostJwtMode: CompleteUserAuthoriza }) .setPayload({ vp: walletInstanceAttestation, - jti: uuid.v4().toString(), + jti: uuidv4().toString(), nonce: requestObject.nonce, }) .setIssuedAt() @@ -184,7 +184,7 @@ export const completeUserAuthorizationWithFormPostJwtMode: CompleteUserAuthoriza }) .setPayload({ vp: pid, - jti: uuid.v4().toString(), + jti: uuidv4().toString(), nonce: requestObject.nonce, }) .setIssuedAt() @@ -196,8 +196,8 @@ export const completeUserAuthorizationWithFormPostJwtMode: CompleteUserAuthoriza * is cointaned in the `vp` property of the signed jwt token payload */ const presentationSubmission = { - definition_id: `${uuid.v4()}`, - id: `${uuid.v4()}`, + definition_id: `${uuidv4()}`, + id: `${uuidv4()}`, descriptor_map: [ { id: "PersonIdentificationData", diff --git a/src/credential/issuance/05-authorize-access.ts b/src/credential/issuance/05-authorize-access.ts index d9ea9d97..e1897f61 100644 --- a/src/credential/issuance/05-authorize-access.ts +++ b/src/credential/issuance/05-authorize-access.ts @@ -2,7 +2,7 @@ import { hasStatusOrThrow, type Out } from "../../utils/misc"; import type { EvaluateIssuerTrust } from "./02-evaluate-issuer-trust"; import type { StartUserAuthorization } from "./03-start-user-authorization"; import { createDPopToken } from "../../utils/dpop"; -import uuid from "react-native-uuid"; +import { v4 as uuidv4 } from 'uuid'; import { createPopToken } from "../../utils/pop"; import * as WalletInstanceAttestation from "../../wallet-instance-attestation"; import type { CryptoContext } from "@pagopa/io-react-native-jwt"; @@ -71,14 +71,14 @@ export const authorizeAccess: AuthorizeAccess = async ( { htm: "POST", htu: tokenUrl, - jti: `${uuid.v4()}`, + jti: `${uuidv4()}`, }, dPopCryptoContext ); const signedWiaPoP = await createPopToken( { - jti: `${uuid.v4()}`, + jti: `${uuidv4()}`, aud, iss, }, diff --git a/src/credential/issuance/06-obtain-credential.ts b/src/credential/issuance/06-obtain-credential.ts index 0224edc1..afda1c0c 100644 --- a/src/credential/issuance/06-obtain-credential.ts +++ b/src/credential/issuance/06-obtain-credential.ts @@ -16,7 +16,7 @@ import { } from "../../utils/errors"; import { CredentialResponse } from "./types"; import { createDPopToken } from "../../utils/dpop"; -import uuid from "react-native-uuid"; +import { v4 as uuidv4 } from 'uuid'; export type ObtainCredential = ( issuerConf: Out["issuerConf"], @@ -127,7 +127,7 @@ export const obtainCredential: ObtainCredential = async ( { htm: "POST", htu: credentialUrl, - jti: `${uuid.v4()}`, + jti: `${uuidv4()}`, ath: await sha256ToBase64(accessToken.access_token), }, dPopCryptoContext diff --git a/src/credential/issuance/README.md b/src/credential/issuance/README.md index 2d7e56fb..95c7a435 100644 --- a/src/credential/issuance/README.md +++ b/src/credential/issuance/README.md @@ -108,7 +108,7 @@ const eid = { const eidCryptoContext = createCryptoContextFor(eid.keyTag); // Create credential crypto context -const credentialKeyTag = uuid.v4().toString(); +const credentialKeyTag = uuidv4().toString(); await generate(credentialKeyTag); // Let's assume this function generates a new hardware-backed key pair const credentialCryptoContext = createCryptoContextFor(credentialKeyTag); @@ -244,7 +244,7 @@ const authorizationContext = idpHint.includes("servizicie") * Create credential crypto context for the PID * WARNING: The eID keytag must be persisted and later used when requesting a credential which requires a eID presentation */ -const credentialKeyTag = uuid.v4().toString(); +const credentialKeyTag = uuidv4().toString(); await generate(credentialKeyTag); const credentialCryptoContext = createCryptoContextFor(credentialKeyTag); diff --git a/src/credential/presentation/03-get-request-object.ts b/src/credential/presentation/03-get-request-object.ts index 1df40adc..48458192 100644 --- a/src/credential/presentation/03-get-request-object.ts +++ b/src/credential/presentation/03-get-request-object.ts @@ -1,4 +1,4 @@ -import uuid from "react-native-uuid"; +import { v4 as uuidv4 } from 'uuid'; import { decode as decodeJwt, sha256ToBase64, @@ -41,7 +41,7 @@ export const getRequestObject: GetRequestObject = async ( ) => { const signedWalletInstanceDPoP = await createDPopToken( { - jti: `${uuid.v4()}`, + jti: `${uuidv4()}`, htm: "GET", htu: requestUri, ath: await sha256ToBase64(walletInstanceAttestation), diff --git a/src/credential/presentation/04-send-authorization-response.ts b/src/credential/presentation/04-send-authorization-response.ts index 13d0ba87..c298ad74 100644 --- a/src/credential/presentation/04-send-authorization-response.ts +++ b/src/credential/presentation/04-send-authorization-response.ts @@ -1,5 +1,5 @@ import { EncryptJwe, SignJWT } from "@pagopa/io-react-native-jwt"; -import uuid from "react-native-uuid"; +import { v4 as uuidv4 } from 'uuid'; import * as WalletInstanceAttestation from "../../wallet-instance-attestation"; import type { JWK } from "@pagopa/io-react-native-jwt/lib/typescript/types"; import { NoSuitableKeysFoundInEntityConfiguration } from "./errors"; @@ -79,7 +79,7 @@ const prepareVpToken = async ( }) .setPayload({ vp: vp, - jti: `${uuid.v4()}`, + jti: `${uuidv4()}`, iss, nonce: requestObject.nonce, }) @@ -90,8 +90,8 @@ const prepareVpToken = async ( const vc_scope = requestObject.scope; const presentation_submission = { - definition_id: `${uuid.v4()}`, - id: `${uuid.v4()}`, + definition_id: `${uuidv4()}`, + id: `${uuidv4()}`, descriptor_map: paths.map((p) => ({ id: vc_scope, path: `$.vp_token.${p.path}`, diff --git a/src/credential/status/02-status-attestation.ts b/src/credential/status/02-status-attestation.ts index 5f43cb70..6321008f 100644 --- a/src/credential/status/02-status-attestation.ts +++ b/src/credential/status/02-status-attestation.ts @@ -5,7 +5,7 @@ import { } from "../../utils/misc"; import type { EvaluateIssuerTrust, ObtainCredential } from "../issuance"; import { type CryptoContext, SignJWT } from "@pagopa/io-react-native-jwt"; -import uuid from "react-native-uuid"; +import { v4 as uuidv4 } from 'uuid'; import { StatusAttestationResponse } from "./types"; import { IssuerResponseError, @@ -46,7 +46,7 @@ export const statusAttestation: StatusAttestation = async ( const credentialPop = await new SignJWT(credentialCryptoContext) .setPayload({ aud: statusAttUrl, - jti: uuid.v4().toString(), + jti: uuidv4().toString(), credential_hash: credentialHash, credential_hash_alg: "S256", }) diff --git a/src/utils/crypto.ts b/src/utils/crypto.ts index c0a465c8..6f196ab7 100644 --- a/src/utils/crypto.ts +++ b/src/utils/crypto.ts @@ -4,7 +4,7 @@ import { generate, deleteKey, } from "@pagopa/io-react-native-crypto"; -import uuid from "react-native-uuid"; +import { v4 as uuidv4 } from 'uuid'; import { thumbprint, type CryptoContext } from "@pagopa/io-react-native-jwt"; import { fixBase64EncodingOnKey } from "./jwk"; @@ -58,7 +58,7 @@ export const withEphemeralKey = async ( fn: (ephemeralContext: CryptoContext) => Promise ): Promise => { // Use an ephemeral key to be destroyed after use - const keytag = `ephemeral-${uuid.v4()}`; + const keytag = `ephemeral-${uuidv4()}`; await generate(keytag); const ephemeralContext = createCryptoContextFor(keytag); return fn(ephemeralContext).finally(() => deleteKey(keytag)); diff --git a/src/utils/par.ts b/src/utils/par.ts index e023fd55..32ffe9a0 100644 --- a/src/utils/par.ts +++ b/src/utils/par.ts @@ -3,7 +3,7 @@ import { type CryptoContext, SignJWT, } from "@pagopa/io-react-native-jwt"; -import uuid from "react-native-uuid"; +import { v4 as uuidv4 } from 'uuid'; import * as z from "zod"; import * as WalletInstanceAttestation from "../wallet-instance-attestation"; import { generateRandomAlphaNumericString, hasStatusOrThrow } from "./misc"; @@ -51,7 +51,7 @@ export const makeParRequest = const signedWiaPoP = await createPopToken( { - jti: `${uuid.v4()}`, + jti: `${uuidv4()}`, aud, iss, }, @@ -74,7 +74,7 @@ export const makeParRequest = kid: wiaPublicKey.kid, }) .setPayload({ - jti: `${uuid.v4()}`, + jti: `${uuidv4()}`, aud, response_type: "code", response_mode: responseMode, diff --git a/yarn.lock b/yarn.lock index 9574a384..b177e119 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7408,11 +7408,6 @@ react-native-url-polyfill@^2.0.0: dependencies: whatwg-url-without-unicode "8.0.0-3" -react-native-uuid@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/react-native-uuid/-/react-native-uuid-2.0.1.tgz#ed4e2dfb1683eddb66967eb5dca140dfe1abddb9" - integrity sha512-cptnoIbL53GTCrWlb/+jrDC6tvb7ypIyzbXNJcpR3Vab0mkeaaVd5qnB3f0whXYzS+SMoSQLcUUB0gEWqkPC0g== - react-native@0.72.14: version "0.72.14" resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.72.14.tgz#d69c7bec66716946ea96613813618ba10403f942" @@ -8707,6 +8702,11 @@ utils-merge@1.0.1: resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" integrity sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA== +uuid@^11.0.3: + version "11.0.3" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-11.0.3.tgz#248451cac9d1a4a4128033e765d137e2b2c49a3d" + integrity sha512-d0z310fCWv5dJwnX1Y/MncBAqGMKEzlBb1AOf7z9K8ALnd0utBX/msg/fA0+sbyN1ihbMsLhrBlnl1ak7Wa0rg== + v8-to-istanbul@^9.0.1: version "9.1.0" resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-9.1.0.tgz#1b83ed4e397f58c85c266a570fc2558b5feb9265" From cea9ee32f2b5add1a0dba0a15d0b7d3a5ec84509 Mon Sep 17 00:00:00 2001 From: RiccardoMolinari95 Date: Thu, 2 Jan 2025 16:52:52 +0100 Subject: [PATCH 2/3] chore: fix import --- example/src/thunks/pid.ts | 2 +- example/src/utils/credential.ts | 2 +- example/src/utils/integrity.ts | 2 +- src/credential/issuance/04-complete-user-authorization.ts | 2 +- src/credential/issuance/05-authorize-access.ts | 2 +- src/credential/issuance/06-obtain-credential.ts | 2 +- src/credential/presentation/03-get-request-object.ts | 2 +- src/credential/presentation/04-send-authorization-response.ts | 2 +- src/credential/status/02-status-attestation.ts | 2 +- src/utils/crypto.ts | 2 +- src/utils/par.ts | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/example/src/thunks/pid.ts b/example/src/thunks/pid.ts index 3bd3367a..a56825cb 100644 --- a/example/src/thunks/pid.ts +++ b/example/src/thunks/pid.ts @@ -4,7 +4,7 @@ import { Credential, WalletInstanceAttestation, } from "@pagopa/io-react-native-wallet"; -import { v4 as uuidv4 } from 'uuid'; +import { v4 as uuidv4 } from "uuid"; import { selectAttestation, shouldRequestAttestationSelector, diff --git a/example/src/utils/credential.ts b/example/src/utils/credential.ts index afec55f3..9642da8d 100644 --- a/example/src/utils/credential.ts +++ b/example/src/utils/credential.ts @@ -2,7 +2,7 @@ import { Credential, createCryptoContextFor, } from "@pagopa/io-react-native-wallet"; -import { v4 as uuidv4 } from 'uuid'; +import { v4 as uuidv4 } from "uuid"; import { generate } from "@pagopa/io-react-native-crypto"; import appFetch from "../utils/fetch"; import { DPOP_KEYTAG, regenerateCryptoKey } from "../utils/crypto"; diff --git a/example/src/utils/integrity.ts b/example/src/utils/integrity.ts index bdf2207b..99143890 100644 --- a/example/src/utils/integrity.ts +++ b/example/src/utils/integrity.ts @@ -10,7 +10,7 @@ import { requestIntegrityToken, } from "@pagopa/io-react-native-integrity"; import { Platform } from "react-native"; -import { v4 as uuidv4 } from 'uuid'; +import { v4 as uuidv4 } from "uuid"; import { addPadding, removePadding } from "@pagopa/io-react-native-jwt"; import { sha256 } from "js-sha256"; import type { IntegrityContext } from "@pagopa/io-react-native-wallet"; diff --git a/src/credential/issuance/04-complete-user-authorization.ts b/src/credential/issuance/04-complete-user-authorization.ts index 7541086c..bdd29b7a 100644 --- a/src/credential/issuance/04-complete-user-authorization.ts +++ b/src/credential/issuance/04-complete-user-authorization.ts @@ -15,7 +15,7 @@ import { type CryptoContext, } from "@pagopa/io-react-native-jwt"; import { RequestObject } from "../presentation/types"; -import { v4 as uuidv4 } from 'uuid'; +import { v4 as uuidv4 } from "uuid"; import { ResponseUriResultShape } from "./types"; import { getJwtFromFormPost } from "../../utils/decoder"; import { AuthorizationError, AuthorizationIdpError } from "./errors"; diff --git a/src/credential/issuance/05-authorize-access.ts b/src/credential/issuance/05-authorize-access.ts index e1897f61..e1da3041 100644 --- a/src/credential/issuance/05-authorize-access.ts +++ b/src/credential/issuance/05-authorize-access.ts @@ -2,7 +2,7 @@ import { hasStatusOrThrow, type Out } from "../../utils/misc"; import type { EvaluateIssuerTrust } from "./02-evaluate-issuer-trust"; import type { StartUserAuthorization } from "./03-start-user-authorization"; import { createDPopToken } from "../../utils/dpop"; -import { v4 as uuidv4 } from 'uuid'; +import { v4 as uuidv4 } from "uuid"; import { createPopToken } from "../../utils/pop"; import * as WalletInstanceAttestation from "../../wallet-instance-attestation"; import type { CryptoContext } from "@pagopa/io-react-native-jwt"; diff --git a/src/credential/issuance/06-obtain-credential.ts b/src/credential/issuance/06-obtain-credential.ts index afda1c0c..6d3c8c1d 100644 --- a/src/credential/issuance/06-obtain-credential.ts +++ b/src/credential/issuance/06-obtain-credential.ts @@ -16,7 +16,7 @@ import { } from "../../utils/errors"; import { CredentialResponse } from "./types"; import { createDPopToken } from "../../utils/dpop"; -import { v4 as uuidv4 } from 'uuid'; +import { v4 as uuidv4 } from "uuid"; export type ObtainCredential = ( issuerConf: Out["issuerConf"], diff --git a/src/credential/presentation/03-get-request-object.ts b/src/credential/presentation/03-get-request-object.ts index 48458192..9821b85d 100644 --- a/src/credential/presentation/03-get-request-object.ts +++ b/src/credential/presentation/03-get-request-object.ts @@ -1,4 +1,4 @@ -import { v4 as uuidv4 } from 'uuid'; +import { v4 as uuidv4 } from "uuid"; import { decode as decodeJwt, sha256ToBase64, diff --git a/src/credential/presentation/04-send-authorization-response.ts b/src/credential/presentation/04-send-authorization-response.ts index c298ad74..b877b282 100644 --- a/src/credential/presentation/04-send-authorization-response.ts +++ b/src/credential/presentation/04-send-authorization-response.ts @@ -1,5 +1,5 @@ import { EncryptJwe, SignJWT } from "@pagopa/io-react-native-jwt"; -import { v4 as uuidv4 } from 'uuid'; +import { v4 as uuidv4 } from "uuid"; import * as WalletInstanceAttestation from "../../wallet-instance-attestation"; import type { JWK } from "@pagopa/io-react-native-jwt/lib/typescript/types"; import { NoSuitableKeysFoundInEntityConfiguration } from "./errors"; diff --git a/src/credential/status/02-status-attestation.ts b/src/credential/status/02-status-attestation.ts index 6321008f..7e5ac4b5 100644 --- a/src/credential/status/02-status-attestation.ts +++ b/src/credential/status/02-status-attestation.ts @@ -5,7 +5,7 @@ import { } from "../../utils/misc"; import type { EvaluateIssuerTrust, ObtainCredential } from "../issuance"; import { type CryptoContext, SignJWT } from "@pagopa/io-react-native-jwt"; -import { v4 as uuidv4 } from 'uuid'; +import { v4 as uuidv4 } from "uuid"; import { StatusAttestationResponse } from "./types"; import { IssuerResponseError, diff --git a/src/utils/crypto.ts b/src/utils/crypto.ts index 6f196ab7..4c1886a2 100644 --- a/src/utils/crypto.ts +++ b/src/utils/crypto.ts @@ -4,7 +4,7 @@ import { generate, deleteKey, } from "@pagopa/io-react-native-crypto"; -import { v4 as uuidv4 } from 'uuid'; +import { v4 as uuidv4 } from "uuid"; import { thumbprint, type CryptoContext } from "@pagopa/io-react-native-jwt"; import { fixBase64EncodingOnKey } from "./jwk"; diff --git a/src/utils/par.ts b/src/utils/par.ts index 32ffe9a0..01290347 100644 --- a/src/utils/par.ts +++ b/src/utils/par.ts @@ -3,7 +3,7 @@ import { type CryptoContext, SignJWT, } from "@pagopa/io-react-native-jwt"; -import { v4 as uuidv4 } from 'uuid'; +import { v4 as uuidv4 } from "uuid"; import * as z from "zod"; import * as WalletInstanceAttestation from "../wallet-instance-attestation"; import { generateRandomAlphaNumericString, hasStatusOrThrow } from "./misc"; From 0bf56e31746e7515a6ef8fa7956848da4272ba16 Mon Sep 17 00:00:00 2001 From: RiccardoMolinari95 Date: Fri, 3 Jan 2025 09:35:41 +0100 Subject: [PATCH 3/3] test: fix uuid import in test with jest, created jestSetup file --- jestSetup.js | 9 +++++++++ package.json | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 jestSetup.js diff --git a/jestSetup.js b/jestSetup.js new file mode 100644 index 00000000..4a0a9a2a --- /dev/null +++ b/jestSetup.js @@ -0,0 +1,9 @@ +/** + * Set up of the testing environment + */ + +jest.mock("uuid", () => { + return { + v4: jest.fn(() => "mocked-uuid"), + }; +}); \ No newline at end of file diff --git a/package.json b/package.json index c4d555f3..1a305bd4 100644 --- a/package.json +++ b/package.json @@ -90,6 +90,12 @@ "modulePathIgnorePatterns": [ "/example/node_modules", "/lib/" + ], + "transformIgnorePatterns": [ + "node_modules/(?!(jest-)?@react-native|react-native|uuid)" + ], + "setupFiles": [ + "/jestSetup.js" ] }, "react-native-builder-bob": { @@ -114,4 +120,4 @@ "uuid": "^11.0.3", "zod": "^3.21.4" } -} +} \ No newline at end of file