Skip to content

Commit

Permalink
Merge pull request #9 from Keyri-Co/feature/update_sdks
Browse files Browse the repository at this point in the history
Updated Android and iOS sdk-s, add new createFingerprint method, upda…
  • Loading branch information
AndrewKuliahin96 authored Mar 5, 2024
2 parents 6c354df + 3cdd876 commit bb3b560
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.2.0",
"version": "0.3.0",
"name": "@keyri/cordova-keyri",
"cordova_name": "Cordova Keyri Plugin",
"description": "Cordova Keyri SDK Plugin for QR login",
Expand Down
8 changes: 4 additions & 4 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-keyri"
version="0.2.0">
version="0.3.0">

<name>CordovaKeyri</name>
<description>Cordova Keyri SDK Plugin</description>
Expand All @@ -22,8 +22,8 @@
<js-module src="dist/types.js" name="types"/>

<platform name="android">
<framework src="com.keyri:keyrisdk:4.1.1"/>
<framework src="com.keyri:scanner:4.1.1"/>
<framework src="com.keyri:keyrisdk:4.2.4"/>
<framework src="com.keyri:scanner:4.2.4"/>
<framework src="com.google.code.gson:gson:2.10.1"/>

<source-file src="src/android/com/keyri/cordova/plugin/CordovaKeyri.kt"
Expand Down Expand Up @@ -54,7 +54,7 @@
<source url="https://github.com/CocoaPods/Specs.git"/>
</config>
<pods use-frameworks="true">
<pod name="keyri-pod" spec="~> 4.4.1"/>
<pod name="keyri-pod" spec="~> 4.5.1"/>
</pods>
</podspec>
</platform>
Expand Down
55 changes: 37 additions & 18 deletions src/android/com/keyri/cordova/plugin/CordovaKeyri.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import android.content.Intent
import androidx.fragment.app.FragmentActivity
import com.keyrico.keyrisdk.Keyri
import com.keyrico.keyrisdk.entity.session.Session
import com.keyrico.keyrisdk.sec.fraud.enums.EventType
import com.keyrico.keyrisdk.sec.fraud.event.EventType
import com.google.gson.Gson
import org.apache.cordova.CallbackContext
import org.apache.cordova.CordovaPlugin
Expand Down Expand Up @@ -89,11 +89,14 @@ class CordovaKeyri : CordovaPlugin() {
"sendEvent" -> {
val publicUserId = arguments?.getString(0)
val eventType = arguments?.getString(1)
val success = arguments?.getBoolean(2) ?: true
val eventMetadata = arguments?.getString(2)
val success = arguments?.getBoolean(3) ?: true

sendEvent(publicUserId, eventType, success, callbackContext)
sendEvent(publicUserId, eventType, eventMetadata, success, callbackContext)
}

"createFingerprint" -> createFingerprint(callbackContext)

"initiateQrSession" -> {
val sessionId = arguments?.getString(0)
val publicUserId = arguments?.getString(1)
Expand Down Expand Up @@ -199,7 +202,16 @@ class CordovaKeyri : CordovaPlugin() {
} else {
cordova.getActivity()?.let {
cordova.setActivityResultCallback(this)
easyKeyriAuth(it, AUTH_REQUEST_CODE, appKey, publicApiKey, serviceEncryptionKey, blockEmulatorDetection, payload, publicUserId)
easyKeyriAuth(
it,
AUTH_REQUEST_CODE,
appKey,
publicApiKey,
serviceEncryptionKey,
blockEmulatorDetection,
payload,
publicUserId
)

easyKeyriAuthCallback = callback
} ?: callback.error("initializeDefaultScreen, can't get cordova.getActivity()")
Expand Down Expand Up @@ -285,20 +297,26 @@ class CordovaKeyri : CordovaPlugin() {
}
}

private fun sendEvent(publicUserId: String?, eventType: String?, success: Boolean, callback: CallbackContext) {
private fun sendEvent(publicUserId: String?, eventType: String?, eventMetadata: String?, success: Boolean, callback: CallbackContext) {
keyriCoroutineScope(callback).launch {
val type = EventType.values().firstOrNull { it.type == eventType }
val jsonMetadata = eventMetadata?.let(::JSONObject)
val type = EventType.custom(eventType ?: "visits", jsonMetadata)
val userId = publicUserId ?: "ANON"

if (type == null) {
callback.error("sendEvent, eventType must not be null")
} else {
val userId = publicUserId ?: "ANON"
keyri.sendEvent(userId, type, success).onSuccess { fingerprintResponse ->
callback.success(JSONObject(Gson().toJson(fingerprintResponse)))
}.onFailure {
callback.error("sendEvent, ${it.message}")
}
}
}

keyri.sendEvent(userId, type, success).onSuccess {
callback.success()
}.onFailure {
callback.error("sendEvent, ${it.message}")
}
private fun createFingerprint(callback: CallbackContext) {
keyriCoroutineScope(callback).launch {
keyri.createFingerprint().onSuccess { fingerprintRequest ->
callback.success(JSONObject(Gson().toJson(fingerprintRequest)))
}.onFailure {
callback.error("createFingerprint, ${it.message}")
}
}
}
Expand Down Expand Up @@ -347,9 +365,10 @@ class CordovaKeyri : CordovaPlugin() {
callback.error("initializeDefaultConfirmationScreen, payload must not be null")
} else {
(cordova.getActivity() as? FragmentActivity)?.supportFragmentManager?.let { fm ->
keyri.initializeDefaultConfirmationScreen(fm, requireNotNull(activeSession), payload).onSuccess { authResult ->
callback.success()
}.onFailure {
keyri.initializeDefaultConfirmationScreen(fm, requireNotNull(activeSession), payload)
.onSuccess { authResult ->
callback.success()
}.onFailure {
callback.error("initializeDefaultConfirmationScreen, ${it.message}")
}
} ?: callback.error("initializeDefaultConfirmationScreen, can't get supportFragmentManager")
Expand Down
17 changes: 15 additions & 2 deletions src/iOS/com/keyri/cordova/plugin/CordovaKeyri.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ import Keyri
return
}

let success = command.arguments[2] as? String ?? "true"
let eventMetadata = command.arguments[2] as? String
let success = command.arguments[3] as? String ?? "true"

keyri?.sendEvent(publicUserId: publicUserId, eventType: EventType(rawValue: eventType) ?? .visits, success: Bool(success) ?? true) { result in
keyri?.sendEvent(publicUserId: publicUserId, eventType: EventType.custom(name: eventType, metadata: eventMetadata), success: Bool(success) ?? true) { result in
switch result {
case .success(let fingerprintResponse):
self.processResult(message: fingerprintResponse.asDictionary(), command: command)
Expand All @@ -174,6 +175,18 @@ import Keyri
} ?? sendIsNotInitialized(methodName: "sendEvent", command: command)
}

@objc(createFingerprint)
func createFingerprint(command: CDVInvokedUrlCommand) {
keyri?.createFingerprint() { result in
switch result {
case .success(let fingerprintRequest):
self.processResult(message: fingerprintRequest.asDictionary(), command: command)
case .failure(let error):
self.processError(error: error, command: command)
}
} ?? sendIsNotInitialized(methodName: "createFingerprint", command: command)
}

@objc(initiateQrSession:)
func initiateQrSession(command: CDVInvokedUrlCommand) {
guard let sessionId = command.arguments[0] as? String else {
Expand Down
12 changes: 8 additions & 4 deletions www/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
import {
ProcessLinkOptions,
InitializeKeyriOptions,
SendEventOptions, LoginObject, RegisterObject,
SendEventOptions, LoginObject, RegisterObject, KeyriFingerprintRequest,
} from './types';
import {KeyriFingerprintEventResponse, KeyriSession} from "./types";

Expand Down Expand Up @@ -48,11 +48,15 @@ export class CordovaKeyriPlugin {
};

sendEvent(data: SendEventOptions): Promise<KeyriFingerprintEventResponse> {
return asPromise('sendEvent', [data.publicUserId, data.eventType, String(data.success)]);
return asPromise('sendEvent', [data.publicUserId, data.eventType.name, JSON.stringify(data.eventType.metadata), String(data.success)]);
};

createFingerprint(): Promise<KeyriFingerprintRequest> {
return asPromise('createFingerprint');
};

initiateQrSession(sessionId: string, publicUserId?: string): Promise<KeyriSession> {
return asPromise('initiateQrSession', [sessionId, publicUserId]);
return asPromise('initiateQrSession', [sessionId, publicUserId]);
};

login(publicUserId?: string): Promise<LoginObject> {
Expand Down
70 changes: 59 additions & 11 deletions www/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ export interface KeyriFingerprintEventResponse {
salt: string;
}

export interface KeyriFingerprintRequest {
clientEncryptionKey: string;
encryptedPayload: string;
salt: string;
iv: string;
}

export interface KeyriUserParameters {
base64EncodedData?: string;
}
Expand Down Expand Up @@ -92,15 +99,56 @@ export interface SendEventOptions {
success: boolean;
}

export enum EventType {
Visits = 'visits',
Login = 'login',
Signup = 'signup',
AttachNewDevice = 'attach_new_device',
EmailChange = 'email_change',
ProfileUpdate = 'profile_update',
PasswordReset = 'password_reset',
Withdrawal = 'withdrawal',
Deposit = 'deposit',
Purchase = 'purchase',
export class EventType {
name: string;
metadata?: object;

constructor(name: string, metadata?: object) {
this.name = name;
this.metadata = metadata;
}

static visits(metadata?: object): EventType {
return new EventType('visits', metadata);
}

static login(metadata?: object): EventType {
return new EventType('login', metadata);
}

static signup(metadata?: object): EventType {
return new EventType('signup', metadata);
}

static attachNewDevice(metadata?: object): EventType {
return new EventType('attach_new_device', metadata);
}

static emailChange(metadata?: object): EventType {
return new EventType('email_change', metadata);
}

static profileUpdate(metadata?: object): EventType {
return new EventType('profile_update', metadata);
}

static passwordReset(metadata?: object): EventType {
return new EventType('password_reset', metadata);
}

static withdrawal(metadata?: object): EventType {
return new EventType('withdrawal', metadata);
}

static deposit(metadata?: object): EventType {
return new EventType('deposit', metadata);
}

static purchase(metadata?: object): EventType {
return new EventType('purchase', metadata);
}

static custom(name: string, metadata?: object): EventType {
return new EventType(name, metadata);
}
}

0 comments on commit bb3b560

Please sign in to comment.