Skip to content

Commit

Permalink
Merge pull request #49 from Keyri-Co/feature/update_rn_and_dependencies
Browse files Browse the repository at this point in the history
Feature/update rn and dependencies
  • Loading branch information
AndrewKuliahin96 authored Mar 5, 2024
2 parents b293571 + 17ef49b commit 4585b61
Show file tree
Hide file tree
Showing 59 changed files with 5,242 additions and 9,820 deletions.
86 changes: 4 additions & 82 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,92 +1,14 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2018,
sourceType: 'module',
},
ignorePatterns: ['scripts', 'lib', 'docs', 'example', 'app.plugin.js'],
env: { node: true, es6: true },
plugins: ['@typescript-eslint'],
extends: ['plugin:@typescript-eslint/recommended', '@react-native'],
extends: "prettier",
rules: {
// eslint
'semi': 'off',
'curly': ['warn', 'multi-or-nest', 'consistent'],
'no-mixed-spaces-and-tabs': ['warn', 'smart-tabs'],
'no-async-promise-executor': 'warn',
'require-await': 'warn',
'no-return-await': 'warn',
'no-await-in-loop': 'warn',
'comma-dangle': 'off', // prettier already detects this
'no-restricted-syntax': [
'error',
{
selector: 'TSEnumDeclaration',
message: "Enums have various disadvantages, use TypeScript's union types instead.",
},
],
// prettier
'prettier/prettier': ['warn'],
// typescript
'@typescript-eslint/no-use-before-define': 'off',
curly: ['error', 'multi-line'],
'@typescript-eslint/no-unused-vars': [
'error',
{
vars: 'all',
args: 'after-used',
ignoreRestSiblings: false,
varsIgnorePattern: '^_',
argsIgnorePattern: '^_',
},
],
'@typescript-eslint/explicit-function-return-type': [
'warn',
{
allowExpressions: true,
},
],
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unsafe-assignment': 'error',
// react plugin
'react/no-unescaped-entities': 'off',
// react native plugin
'react-native/no-unused-styles': 'warn',
'react-native/split-platform-components': 'off',
'react-native/no-inline-styles': 'warn',
'react-native/no-color-literals': 'off',
'react-native/no-raw-text': 'off',
'react-native/no-single-element-style-arrays': 'warn',
'@typescript-eslint/strict-boolean-expressions': [
'error',
{
allowString: false,
allowNullableObject: false,
allowNumber: false,
allowNullableBoolean: true,
},
],
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-unnecessary-condition': 'error',

// react hooks
'react-hooks/exhaustive-deps': [
'error',
{
additionalHooks:
'(useDerivedValue|useAnimatedStyle|useAnimatedProps|useWorkletCallback|useFrameProcessor)',
},
{ argsIgnorePattern: '^_', destructuredArrayIgnorePattern: '^_' },
],
},
env: {
node: true,
},
globals: {
_log: 'readonly',
},
};
3 changes: 0 additions & 3 deletions .gitattributes

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
workflow_dispatch:

env:
NODE_VERSION: 16
NODE_VERSION: 18

jobs:
lint:
Expand Down
19 changes: 12 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ DerivedData
*.ipa
*.xcuserstate
project.xcworkspace
ios/.xcode.env.local

# Android/IJ
#
Expand All @@ -40,10 +41,17 @@ project.xcworkspace
.hprof
local.properties
android.iml
*.hprof
.cxx/
*.keystore
!debug.keystore

# Cocoapods
# Ruby / CocoaPods
#
example/ios/Pods
example/vendor/bundle/
# Temporary files created by Metro to check the health of the file watcher
example/.metro-health-check*

# node.js
#
Expand All @@ -53,14 +61,11 @@ yarn-debug.log
yarn-error.log
/package-lock.json

# BUCK
buck-out/
\.buckd/
android/app/libs
android/keystores/debug.keystore

# Expo
.expo/*

# generated by bob
lib/

# testing
example/coverage
1 change: 0 additions & 1 deletion .husky/.npmignore

This file was deleted.

4 changes: 0 additions & 4 deletions .husky/commit-msg

This file was deleted.

4 changes: 0 additions & 4 deletions .husky/pre-commit

This file was deleted.

2 changes: 2 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
arrowParens: 'avoid',
bracketSameLine: true,
quoteProps: 'consistent',
singleQuote: true,
tabWidth: 2,
Expand Down
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source 'https://rubygems.org'

# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby ">= 2.6.10"

gem 'cocoapods', '~> 1.13'
gem 'activesupport', '>= 6.1.7.3', '< 7.1.0'
18 changes: 7 additions & 11 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
buildscript {
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['Keyri_kotlinVersion']

repositories {
google()
mavenCentral()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath("com.android.tools.build:gradle")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
}
}

Expand Down Expand Up @@ -121,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.6.4"
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")
}
10 changes: 4 additions & 6 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Keyri_kotlinVersion=1.8.21
Keyri_minSdkVersion=23
Keyri_compileSdkVersion=33
Keyri_targetSdkVersion=33
compileSdkVersion=33
android.useAndroidX=true
reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
newArchEnabled=false
hermesEnabled=true
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m
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
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
presets: ['module:@react-native/babel-preset'],
};
Loading

0 comments on commit 4585b61

Please sign in to comment.