Skip to content

Commit

Permalink
MOB-743 #comment implemented sign transaction JS and iOS API
Browse files Browse the repository at this point in the history
  • Loading branch information
shachartransmit committed Dec 13, 2023
1 parent 884b53c commit e3abfd7
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 18 deletions.
4 changes: 2 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ android {

namespace "com.tsauthenticationexample"
defaultConfig {
applicationId "com.tsauthenticationexample"
applicationId "com.transmitsecurity.authsdk-rn-example"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
Expand Down Expand Up @@ -127,4 +127,4 @@ repositories {
maven {
url('https://transmit.jfrog.io/artifactory/transmit-security-gradle-release-local/')
}
}
}
14 changes: 7 additions & 7 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ PODS:
- react-native-ts-authentication (0.1.0):
- RCT-Folly (= 2021.07.22.00)
- React-Core
- TSAuthentication (~> 1.0.1)
- TSAuthentication (~> 1.0.2)
- React-NativeModulesApple (0.72.7):
- hermes-engine
- React-callinvoker
Expand Down Expand Up @@ -492,9 +492,9 @@ PODS:
- RNCAsyncStorage (1.21.0):
- React-Core
- SocketRocket (0.6.1)
- TSAuthentication (1.0.1):
- TSCoreSDK (~> 1.0.12)
- TSCoreSDK (1.0.15)
- TSAuthentication (1.0.2):
- TSCoreSDK (~> 1.0.17)
- TSCoreSDK (1.0.17)
- Yoga (1.14.0)
- YogaKit (1.18.1):
- Yoga (~> 1.14)
Expand Down Expand Up @@ -704,7 +704,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: c49502e5d02112247ee4526bc3ccfc891ae3eb9b
React-jsinspector: 8baadae51f01d867c3921213a25ab78ab4fbcd91
React-logger: 8edc785c47c8686c7962199a307015e2ce9a0e4f
react-native-ts-authentication: d4449c4e1da8901d262adb240cfed1e2c58bc6c4
react-native-ts-authentication: fa1fdbf7f401515476cce2fe7aeb2d49e6affbe5
React-NativeModulesApple: b6868ee904013a7923128892ee4a032498a1024a
React-perflogger: 31ea61077185eb1428baf60c0db6e2886f141a5a
React-RCTActionSheet: 392090a3abc8992eb269ef0eaa561750588fc39d
Expand All @@ -724,8 +724,8 @@ SPEC CHECKSUMS:
ReactCommon: 5f704096ccf7733b390f59043b6fa9cc180ee4f6
RNCAsyncStorage: 618d03a5f52fbccb3d7010076bc54712844c18ef
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
TSAuthentication: 15aadf1ba9458b0542119d7e710512f0dca91dae
TSCoreSDK: f3d664cc802ecfe06a380d8036d8ef5882c4cc94
TSAuthentication: a94a6f2bacf0bc518bf8974e9795b1bd28647d59
TSCoreSDK: c602d0392aef99325911a9c1431903976d64e23a
Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

Expand Down
48 changes: 42 additions & 6 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,51 @@ export default class App extends React.Component<any, State> {
<SafeAreaView style={{ flex: 1 }}>
{
this.state.currentScreen === AppScreen.Home ? (
<HomeScreen onStartAuthentication={this.onStartAuthentication} errorMessage={this.state.errorMessage} />
<HomeScreen onStartAuthentication={this.onStartAuthentication} errorMessage={this.state.errorMessage}
/>
) : (
<LoggedIn username={this.state.username} onLogout={this.onLogout} isNewlyRegistered={this.state.isNewlyRegistered}/>
<LoggedIn
username={this.state.username}
onStartTransaction={this.onStartTransaction}
onLogout={this.onLogout}
isNewlyRegistered={this.state.isNewlyRegistered}
/>
)
}
</SafeAreaView>
);
}

// Transaction Process Handlers

public onStartTransaction = async (rawUsername: string): Promise<void> => {
const username = rawUsername.toLowerCase();
this.setState({ errorMessage: '' });

if (localUserStore.isUserIDStored(username)) {
this.signTransaction(username);
} else {
console.log("User not registered");
this.setState({ errorMessage: 'User not registered' });
}
}

private signTransaction = async (username: string): Promise<void> => {
try {
const response = await TSAuthenticationSDKModule.signTransaction(username);
const accessToken = await this.mockServer.getAccessToken();
const success = await this.mockServer.completeAuthentication(accessToken.token, response.result); // should change???
if (success) {
this.setState({ errorMessage: '' });
console.log("Sign Transaction success");
} else {
this.setState({ errorMessage: 'Sign Transaction failed' });
}
} catch (error: any) {
this.setState({ errorMessage: `${error}` });
}
}

// Authentication Process Handlers

public onStartAuthentication = async (rawUsername: string): Promise<void> => {
Expand Down Expand Up @@ -115,10 +151,10 @@ export default class App extends React.Component<any, State> {
// Navigation

private navigateToAuthenticatedUserScreen = (username: string, isNewRegistration: boolean): void => {
this.setState({
currentScreen: AppScreen.AuthenticatedUser,
username,
isNewlyRegistered: isNewRegistration
this.setState({
currentScreen: AppScreen.AuthenticatedUser,
username,
isNewlyRegistered: isNewRegistration
});
}

Expand Down
2 changes: 1 addition & 1 deletion example/src/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default class HomeScreen extends React.Component<Props, State> {
/>
</View>
)
}
}
}

const styles = StyleSheet.create({
Expand Down
15 changes: 14 additions & 1 deletion example/src/logged-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { View, StyleSheet, Text, Button, TextInput } from 'react-native';
export type Props = {
username: string;
isNewlyRegistered: boolean;
onStartTransaction: (username: string) => void;
onLogout: () => void;
};

Expand All @@ -28,8 +29,9 @@ export default class LoggedIn extends React.Component<Props, State> {
<View style={styles.container}>
<View style={{ marginTop: 20 }} />
<Text style={styles.sectionTitle}>
{`Hello ${this.props.username}. You are authenticated. Your user status is: ${stateText}`}
{`Hello ${this.props.username}. You are authenticated.\nYour user status is:\n ${stateText}`}
</Text>
{this.renderStartSignTransactionButton()}
{this.renderLogoutButton()}
</View>
);
Expand All @@ -45,6 +47,17 @@ export default class LoggedIn extends React.Component<Props, State> {
</View>
)
}

private renderStartSignTransactionButton(): ReactElement {
return (
<View style={{ marginTop: 24 }}>
<Button
title="Start Transaction"
onPress={() => this.props.onStartTransaction(this.props.username)}
/>
</View>
)
}
}

const styles = StyleSheet.create({
Expand Down
2 changes: 2 additions & 0 deletions ios/TsAuthentication.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ @interface RCT_EXTERN_MODULE(TsAuthentication, NSObject)
withRejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(authenticate:(NSString *)username withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(signTransaction:(NSString *)username withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)

+ (BOOL)requiresMainQueueSetup
{
Expand Down
19 changes: 19 additions & 0 deletions ios/TsAuthentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ class TsAuthentication: NSObject {
}
}

@objc(signTransaction:withResolver:withRejecter:)
func signTransaction(
_ username: String,
resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {

runBlockOnMain {
TSAuthentication.shared.signTransaction(username: username) { [weak self] results in
guard let self = self else { return }

switch results {
case .success(let response):
resolve(["result": response.result])
case .failure(let error):
reject(self.kTag, error.localizedDescription, error)
}
}
}
}

// MARK: - Threading

private func runBlockOnMain(_ block: @escaping () -> Void) {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion react-native-ts-authentication.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Pod::Spec.new do |s|
s.platforms = { :ios => "15.0" }
s.source = { :git => "https://github.com/TransmitSecurity/react-native-ts-authentication.git", :tag => "#{s.version}" }

s.dependency 'TSAuthentication', '~> 1.0.1'
s.dependency 'TSAuthentication', '~> 1.0.2'
s.source_files = "ios/**/*.{h,m,mm,swift}"

# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
Expand Down
4 changes: 4 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,9 @@ class AuthenticationSDK implements TSAuthenticationSDKModule {
return TsAuthentication.authenticate(username);
}

signTransaction(username: string): Promise<TSAuthenticationSDK.TSAuthenticationResult> {
return TsAuthentication.signTransaction(username);
}

}
export default new AuthenticationSDK();
9 changes: 9 additions & 0 deletions src/scripts/sign_android_app.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash


# Export the signing certificate in DER format, hash, base64 encode, trim '=' and url encode

keytool -exportcert -alias <your-keystore-alias> -keystore <your-keystore> | openssl sha256 -binary | openssl base64 | sed 's/=//g'| sed s/\\+/-/g | sed s/\\//_/g | sed -E s/=+\$//


.. next - sign the app and try the script

0 comments on commit e3abfd7

Please sign in to comment.