Skip to content

Commit

Permalink
Updated RN, dependencies, Keyri Android and iOS SDK-s, bridge and typ…
Browse files Browse the repository at this point in the history
…es, fixed example
  • Loading branch information
AndrewKuliahin96 committed Mar 5, 2024
1 parent c2ce316 commit e040135
Show file tree
Hide file tree
Showing 20 changed files with 264 additions and 4,469 deletions.
8 changes: 4 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ dependencies {
// noinspection GradleDynamicVersion
api 'com.facebook.react:react-native:+'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'com.keyri:keyrisdk:4.1.1'
implementation 'com.keyri:scanner:4.1.1'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3"
implementation 'com.keyri:keyrisdk:4.2.4'
implementation 'com.keyri:scanner:4.2.4'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0"
implementation 'androidx.activity:activity-ktx:1.7.2'
implementation("com.squareup.okhttp3:okhttp-urlconnection:4.10.0")
implementation("com.squareup.okhttp3:okhttp-urlconnection:4.12.0")
}
36 changes: 26 additions & 10 deletions android/src/main/java/com/reactnativekeyri/KeyriNativeModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import com.facebook.react.bridge.WritableNativeMap
import com.keyrico.keyrisdk.Keyri
import com.keyrico.keyrisdk.entity.session.Session
import com.keyrico.keyrisdk.exception.DenialException
import com.keyrico.keyrisdk.sec.fraud.enums.EventType
import com.keyrico.keyrisdk.sec.fraud.event.EventType
import com.keyrico.scanner.easyKeyriAuth
import kotlinx.coroutines.*
import org.json.JSONObject
import java.lang.IllegalStateException

class KeyriNativeModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {

Expand Down Expand Up @@ -55,7 +57,7 @@ class KeyriNativeModule(private val reactContext: ReactApplicationContext) : Rea
@ReactMethod
fun initialize(data: ReadableMap, promise: Promise) {
try {
appKey = data.getString("appKey") ?: throw java.lang.IllegalStateException("You need to provide appKey")
appKey = data.getString("appKey") ?: throw IllegalStateException("You need to provide appKey")
publicApiKey = data.takeIf { it.hasKey("publicApiKey") }?.getString("publicApiKey")
serviceEncryptionKey = data.takeIf { it.hasKey("serviceEncryptionKey") }?.getString("serviceEncryptionKey")
blockEmulatorDetection = data.takeIf { it.hasKey("blockEmulatorDetection") }?.getBoolean("blockEmulatorDetection")
Expand Down Expand Up @@ -163,11 +165,12 @@ class KeyriNativeModule(private val reactContext: ReactApplicationContext) : Rea
fun sendEvent(data: ReadableMap, promise: Promise) {
keyriCoroutineScope(promise) {
val publicUserId = data.takeIf { it.hasKey("publicUserId") }?.getString("publicUserId") ?: "ANON"
val eventType = data.getString("eventType")
?: throw java.lang.IllegalStateException("You need to provide eventType")
val eventType = data.getString("eventType") ?: throw IllegalStateException("You need to provide eventType")
val eventMetadata = data.takeIf { it.hasKey("eventMetadata") }?.getString("eventMetadata")
val success = data.getBoolean("success")

val type = EventType.values().first { it.type == eventType }
val jsonMetadata = eventMetadata?.let(::JSONObject)
val type = EventType.custom(eventType, jsonMetadata)

val fingerprintEventResponse = keyri.sendEvent(publicUserId, type, success).getOrThrow()

Expand All @@ -181,6 +184,20 @@ class KeyriNativeModule(private val reactContext: ReactApplicationContext) : Rea
}
}

@ReactMethod
fun createFingerprint(promise: Promise) {
keyriCoroutineScope(promise) {
val fingerprintRequest = keyri.createFingerprint().getOrThrow()

WritableNativeMap().apply {
putString("clientEncryptionKey", fingerprintRequest.clientEncryptionKey)
putString("encryptedPayload", fingerprintRequest.encryptedPayload)
putString("iv", fingerprintRequest.iv)
putString("salt", fingerprintRequest.salt)
}
}
}

@ReactMethod
fun initiateQrSession(sessionId: String, publicUserId: String?, promise: Promise) {
keyriCoroutineScope(promise) {
Expand Down Expand Up @@ -337,7 +354,7 @@ class KeyriNativeModule(private val reactContext: ReactApplicationContext) : Rea
@ReactMethod
fun initializeDefaultConfirmationScreen(payload: String, promise: Promise) {
keyriCoroutineScope(promise) {
val session = activeSession ?: throw java.lang.IllegalStateException("Session not found")
val session = activeSession ?: throw IllegalStateException("Session not found")

val fm = requireNotNull((reactContext.currentActivity as? AppCompatActivity)?.supportFragmentManager)
val result = keyri.initializeDefaultConfirmationScreen(fm, session, payload)
Expand All @@ -358,9 +375,8 @@ class KeyriNativeModule(private val reactContext: ReactApplicationContext) : Rea
fun processLink(data: ReadableMap, promise: Promise) {
keyriCoroutineScope(promise) {
val publicUserId: String? = data.takeIf { it.hasKey("publicUserId") }?.getString("publicUserId")
val url: String = data.getString("url") ?: throw java.lang.IllegalStateException("You need to provide url")
val payload: String = data.getString("payload")
?: throw java.lang.IllegalStateException("You need to provide payload")
val url: String = data.getString("url") ?: throw IllegalStateException("You need to provide url")
val payload: String = data.getString("payload") ?: throw IllegalStateException("You need to provide payload")

val uri = Uri.parse(url)
val fm = requireNotNull((reactContext.currentActivity as? AppCompatActivity)?.supportFragmentManager)
Expand Down Expand Up @@ -391,7 +407,7 @@ class KeyriNativeModule(private val reactContext: ReactApplicationContext) : Rea

private fun finishSession(payload: String, isApproved: Boolean, trustNewBrowser: Boolean = false, promise: Promise) {
keyriCoroutineScope(promise) {
val session = activeSession ?: throw java.lang.IllegalStateException("Session not found")
val session = activeSession ?: throw IllegalStateException("Session not found")

if (isApproved) {
session.confirm(payload, reactContext, trustNewBrowser)
Expand Down
18 changes: 9 additions & 9 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"name": "react-native-keyri-example",
"description": "Example app for react-native-keyri",
"version": "0.0.1",
"version": "0.0.2",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start"
},
"dependencies": {
"@react-navigation/native": "^6.1.9",
"@react-navigation/native-stack": "^6.9.17",
"@react-navigation/native": "^6.1.14",
"@react-navigation/native-stack": "^6.9.22",
"react": "18.2.0",
"react-native": "0.73.3",
"react-native-vision-camera": "^3.7.0",
"react-native": "0.73.5",
"react-native-vision-camera": "^3.9.1",
"react-native-easy-toast": "^2.3.0",
"react-native-keyri": "../",
"react-native-permissions": "^4.0.4",
"react-native-safe-area-context": "^4.8.2",
"react-native-permissions": "^4.1.4",
"react-native-safe-area-context": "^4.9.0",
"react-native-screens": "3.29.0"
},
"devDependencies": {
"@babel/core": "^7.23.7",
"@babel/runtime": "^7.23.8",
"@babel/core": "^7.24.0",
"@babel/runtime": "^7.24.0",
"@types/react-native": "^0.73.0",
"babel-plugin-module-resolver": "^5.0.0",
"metro-react-native-babel-preset": "^0.77.0"
Expand Down
3 changes: 0 additions & 3 deletions example/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ import RootNavigator from './navigation';
import Toast from 'react-native-easy-toast';

import { AppLinkContext, LinkContext } from './context/linking-context';
import { AppSessionContext, SessionContext } from './context/session-context';
import toast from './services/toast';
export default function App() {
return (
<AppLinkContext.Provider value={LinkContext()}>
<AppSessionContext.Provider value={SessionContext()}>
<RootNavigator />
<Toast ref={toast.ref} />
</AppSessionContext.Provider>
</AppLinkContext.Provider>
);
}
29 changes: 0 additions & 29 deletions example/src/context/session-context/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions example/src/navigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
} from '@react-navigation/native-stack';
import DefaultScreen from '../screens/default';
import CustomScreen from '../screens/custom';
import StartScreen from '../screens/start';

export type RootNavigatorParams = {
Start: undefined;
Expand All @@ -22,7 +21,6 @@ const RootNavigator: React.FC<RootNavigatorProps> = () => {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Start" component={StartScreen} options={{ headerShown: false }} />
<Stack.Screen name="Custom" component={CustomScreen} options={{ headerShown: false }} />
<Stack.Screen name="Default" component={DefaultScreen} options={{ headerShown: false }} />
</Stack.Navigator>
Expand Down
42 changes: 0 additions & 42 deletions example/src/screens/custom/custom-styles.ts

This file was deleted.

Loading

0 comments on commit e040135

Please sign in to comment.