Skip to content

Commit 40f703a

Browse files
CopilotManAnRuck
andcommitted
Replace react-native-sha256 with expo-crypto for SHA256 hashing
Co-authored-by: ManAnRuck <[email protected]>
1 parent 97e5754 commit 40f703a

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"expo-application": "~6.0.1",
3333
"expo-build-properties": "~0.13.3",
3434
"expo-constants": "^17.0.8",
35+
"expo-crypto": "^15.0.7",
3536
"expo-dev-client": "~5.0.20",
3637
"expo-device": "~7.0.3",
3738
"expo-linking": "~7.0.5",
@@ -59,7 +60,6 @@
5960
"react-native-reanimated": "~3.16.1",
6061
"react-native-safe-area-context": "4.12.0",
6162
"react-native-screens": "~4.4.0",
62-
"react-native-sha256": "^1.4.10",
6363
"react-native-svg": "15.8.0",
6464
"recoil": "^0.7.7",
6565
"speakingurl": "^14.0.1",

src/api/apollo/Auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import AsyncStorage from "@react-native-async-storage/async-storage";
88
import { ApolloLink } from "@apollo/client";
99
import { setContext } from "apollo-link-context";
1010
import { jwtDecode } from "jwt-decode";
11-
import { sha256 } from "react-native-sha256";
11+
import { digestStringAsync, CryptoDigestAlgorithm } from "expo-crypto";
1212
import DeviceInfo from "react-native-device-info";
1313

1414
interface JwtObject {
@@ -40,7 +40,7 @@ export const authLinkMiddleware = setContext(async (_, { headers }) => {
4040
}
4141
}
4242
// No (valid) Token present - login
43-
const deviceHash = await sha256(await DeviceInfo.getUniqueId());
43+
const deviceHash = await digestStringAsync(CryptoDigestAlgorithm.SHA256, await DeviceInfo.getUniqueId());
4444
const phoneHash = await AsyncStorage.getItem("auth_phoneHash");
4545
const newHeaders = {
4646
...headers,

src/screens/Verification/Code.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useContext, useEffect } from "react";
22
import styled from "styled-components/native";
33
import { Keyboard, Alert, Dimensions, ActivityIndicator, KeyboardAvoidingView } from "react-native";
4-
import { sha256 } from "react-native-sha256";
4+
import { digestStringAsync, CryptoDigestAlgorithm } from "expo-crypto";
55
import AsyncStorage from "@react-native-async-storage/async-storage";
66
import Description from "./Components/Description";
77
import CodeInput from "./Components/CodeInput";
@@ -55,7 +55,7 @@ export const SmsCodeInputScreen: React.FC = () => {
5555
const onChangeCode = async (newCode: string) => {
5656
setCode(newCode);
5757
if (newCode.length === 6) {
58-
const phoneNumberHash = await sha256(phoneNumber);
58+
const phoneNumberHash = await digestStringAsync(CryptoDigestAlgorithm.SHA256, phoneNumber);
5959
const res = await requestVerification({
6060
variables: {
6161
code: newCode,

yarn.lock

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3466,7 +3466,7 @@ [email protected]:
34663466
resolved "https://registry.yarnpkg.com/base-64/-/base-64-0.1.0.tgz#780a99c84e7d600260361511c4877613bf24f6bb"
34673467
integrity sha512-Y5gU45svrR5tI2Vt/X9GPd3L0HNIKzGu202EjxrXMpuc2V2CiKgemAbUUsqYmZJvPtCXoUKjNZwBJzsNScUbXA==
34683468

3469-
base64-js@^1.2.3, base64-js@^1.3.1, base64-js@^1.5.1:
3469+
base64-js@^1.2.3, base64-js@^1.3.0, base64-js@^1.3.1, base64-js@^1.5.1:
34703470
version "1.5.1"
34713471
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
34723472
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==
@@ -5028,6 +5028,13 @@ expo-constants@^17.0.8, expo-constants@~17.0.5, expo-constants@~17.0.8:
50285028
"@expo/config" "~10.0.11"
50295029
"@expo/env" "~0.4.2"
50305030

5031+
expo-crypto@^15.0.7:
5032+
version "15.0.7"
5033+
resolved "https://registry.yarnpkg.com/expo-crypto/-/expo-crypto-15.0.7.tgz#0d06a621ddbcfdcfbcb9961462ee227b52a4f73b"
5034+
integrity sha512-FUo41TwwGT2e5rA45PsjezI868Ch3M6wbCZsmqTWdF/hr+HyPcrp1L//dsh/hsrsyrQdpY/U96Lu71/wXePJeg==
5035+
dependencies:
5036+
base64-js "^1.3.0"
5037+
50315038
expo-dev-client@~5.0.20:
50325039
version "5.0.20"
50335040
resolved "https://registry.yarnpkg.com/expo-dev-client/-/expo-dev-client-5.0.20.tgz#349a6251d1d63c3142ad5232be653038b5c6cf15"
@@ -8228,11 +8235,6 @@ react-native-screens@~4.4.0:
82288235
react-freeze "^1.0.0"
82298236
warn-once "^0.1.0"
82308237

8231-
react-native-sha256@^1.4.10:
8232-
version "1.4.10"
8233-
resolved "https://registry.yarnpkg.com/react-native-sha256/-/react-native-sha256-1.4.10.tgz#b4c9990430849ee29a00dfd606fd92f08e003dc7"
8234-
integrity sha512-x12owcA1jQZ1GMUX2xg2+4IOVJciZChcyNvolt6IjLdAFtu1tttDF9aHsCTW1J1SbLGSoYCo/UTAoNZay/YAsg==
8235-
82368238
82378239
version "15.8.0"
82388240
resolved "https://registry.yarnpkg.com/react-native-svg/-/react-native-svg-15.8.0.tgz#9b5fd4f5cf5675197b3f4cbfcc77c215de2b9502"

0 commit comments

Comments
 (0)