2626import com .transmit .authentication .biometrics .TSBiometricsAuthResult ;
2727import com .transmit .authentication .biometrics .TSBiometricsRegistrationError ;
2828import com .transmit .authentication .biometrics .TSBiometricsRegistrationResult ;
29+ import com .transmit .authentication .exceptions .TSAuthenticationInitializeException ;
2930import com .transmit .authentication .network .completereg .DeviceInfo ;
3031
3132import java .util .HashMap ;
@@ -48,23 +49,33 @@ public String getName() {
4849 }
4950
5051 @ ReactMethod
51- @ NonNull public void initialize (String clientId , String domain , String baseUrl , Promise promise ) {
52+ @ NonNull
53+ public void initializeSDK () {
54+ try {
55+ TSAuthentication .initializeSDK (reactContext );
56+ } catch (TSAuthenticationInitializeException e ) {
57+ throw new RuntimeException (e );
58+ }
59+ }
5260
53- if (reactContext .getCurrentActivity () != null ) {
61+ @ ReactMethod
62+ @ NonNull
63+ public void initialize (String clientId , String domain , String baseUrl , Promise promise ) {
5464
65+ if (reactContext .getCurrentActivity () != null ) {
5566 if (domain .length () > 0 ) {
5667 TSAuthentication .initialize (
57- reactContext ,
58- clientId ,
59- baseUrl ,
60- domain
68+ reactContext ,
69+ clientId ,
70+ baseUrl ,
71+ domain
6172 );
6273 } else {
6374 TSAuthentication .initialize (
64- reactContext ,
65- clientId ,
66- baseUrl ,
67- null
75+ reactContext ,
76+ clientId ,
77+ baseUrl ,
78+ null
6879 );
6980 }
7081 promise .resolve (true );
@@ -74,12 +85,13 @@ public String getName() {
7485 // Registration
7586
7687 @ ReactMethod
77- @ NonNull public void registerWebAuthn (
78- String username ,
79- String displayName ,
80- Promise promise ) {
88+ @ NonNull
89+ public void registerWebAuthn (
90+ String username ,
91+ String displayName ,
92+ Promise promise ) {
8193
82- if (reactContext .getCurrentActivity () != null ) {
94+ if (reactContext .getCurrentActivity () != null ) {
8395 Boolean isSupported = TSAuthentication .isWebAuthnSupported ();
8496 if (!isSupported ) {
8597 promise .reject (new Error ("Unsupported platform" ));
@@ -91,32 +103,33 @@ public String getName() {
91103 }
92104
93105 private void continueRegistration (String username , String displayName , Promise promise ) {
94- if (reactContext .getCurrentActivity () != null ) {
106+ if (reactContext .getCurrentActivity () != null ) {
95107 TSAuthentication .registerWebAuthn (
96- reactContext .getCurrentActivity (),
97- username ,
98- displayName ,
99- new TSAuthCallback <RegistrationResult , TSWebAuthnRegistrationError >() {
100- @ Override
101- public void success (RegistrationResult registrationResult ) {
102- WritableMap map = new WritableNativeMap ();
103- map .putString ("result" ,registrationResult .result ());
104- promise .resolve (map );
105- }
106- @ Override
107- public void error ( TSWebAuthnRegistrationError tsWebAuthnRegistrationError ) {
108- promise . reject ( "result" , tsWebAuthnRegistrationError . getErrorMessage ());
109- }
110- }
111- );
108+ reactContext .getCurrentActivity (),
109+ username ,
110+ displayName ,
111+ new TSAuthCallback <RegistrationResult , TSWebAuthnRegistrationError >() {
112+ @ Override
113+ public void success (RegistrationResult registrationResult ) {
114+ WritableMap map = new WritableNativeMap ();
115+ map .putString ("result" , registrationResult .result ());
116+ promise .resolve (map );
117+ }
118+
119+ @ Override
120+ public void error ( TSWebAuthnRegistrationError tsWebAuthnRegistrationError ) {
121+ promise . reject ( "result" , tsWebAuthnRegistrationError . getErrorMessage ());
122+ }
123+ } );
112124 }
113125 }
114126
115127 // Authentication
116128 @ ReactMethod
117- @ NonNull public void authenticateWebAuthn (String username , Promise promise ) {
118- if (reactContext .getCurrentActivity () != null ) {
119- TSAuthentication .authenticateWebAuthn (
129+ @ NonNull
130+ public void authenticateWebAuthn (String username , Promise promise ) {
131+ if (reactContext .getCurrentActivity () != null ) {
132+ TSAuthentication .authenticateWebAuthn (
120133 reactContext .getCurrentActivity (),
121134 username ,
122135 new TSAuthCallback <AuthenticationResult , TSWebAuthnAuthenticationError >() {
@@ -126,68 +139,70 @@ public void success(AuthenticationResult authenticationResult) {
126139 map .putString ("result" , authenticationResult .result ());
127140 promise .resolve (map );
128141 }
142+
129143 @ Override
130144 public void error (TSWebAuthnAuthenticationError tsWebAuthnAuthenticationError ) {
131145 promise .reject ("result" , tsWebAuthnAuthenticationError .toString ());
132146 }
133147 });
134- }
135148 }
149+ }
136150
137151 // Transaction
138152 @ ReactMethod
139- @ NonNull public void signTransactionWebAuthn (String username , Promise promise ) {
140- if (reactContext .getCurrentActivity () != null ) {
153+ @ NonNull
154+ public void signTransactionWebAuthn (String username , Promise promise ) {
155+ if (reactContext .getCurrentActivity () != null ) {
141156 TSAuthentication .signTransactionWebAuthn (
142- reactContext .getCurrentActivity (),
143- username ,
144- new TSAuthCallback <AuthenticationResult , TSWebAuthnAuthenticationError >() {
145- @ Override
146- public void success (AuthenticationResult authenticationResult ) {
147- WritableMap map = new WritableNativeMap ();
148- map .putString ("result" , authenticationResult .result ());
149- promise .resolve (map );
150- }
151-
152- @ Override
153- public void error (TSWebAuthnAuthenticationError tsWebAuthnAuthenticationError ) {
154- promise .reject ("result" , tsWebAuthnAuthenticationError .toString ());
155- }
156- }
157- );
157+ reactContext .getCurrentActivity (),
158+ username ,
159+ new TSAuthCallback <AuthenticationResult , TSWebAuthnAuthenticationError >() {
160+ @ Override
161+ public void success (AuthenticationResult authenticationResult ) {
162+ WritableMap map = new WritableNativeMap ();
163+ map .putString ("result" , authenticationResult .result ());
164+ promise .resolve (map );
165+ }
166+
167+ @ Override
168+ public void error (TSWebAuthnAuthenticationError tsWebAuthnAuthenticationError ) {
169+ promise .reject ("result" , tsWebAuthnAuthenticationError .toString ());
170+ }
171+ });
158172 }
159173 }
160174
161175 // Native Biometrics
162176
163177 @ ReactMethod
164- @ NonNull public void registerNativeBiometrics (String username , Promise promise ) {
165- if (reactContext .getCurrentActivity () != null ) {
178+ @ NonNull
179+ public void registerNativeBiometrics (String username , Promise promise ) {
180+ if (reactContext .getCurrentActivity () != null ) {
166181 TSAuthentication .registerNativeBiometrics (
167- reactContext .getCurrentActivity (),
168- username ,
169- new TSAuthCallback <TSBiometricsRegistrationResult , TSBiometricsRegistrationError >() {
170- @ Override
171- public void success (TSBiometricsRegistrationResult tsBiometricsRegistrationResult ) {
172- WritableMap map = new WritableNativeMap ();
173- map .putString ("publicKeyId" , tsBiometricsRegistrationResult .keyId ());
174- map .putString ("publicKey" , tsBiometricsRegistrationResult .publicKey ());
175- map .putString ("os" , "Android" );
176- promise .resolve (map );
177- }
178-
179- @ Override
180- public void error (TSBiometricsRegistrationError tsBiometricsRegistrationError ) {
181- promise .reject ("result" , tsBiometricsRegistrationError .toString ());
182- }
183- }
184- );
182+ reactContext .getCurrentActivity (),
183+ username ,
184+ new TSAuthCallback <TSBiometricsRegistrationResult , TSBiometricsRegistrationError >() {
185+ @ Override
186+ public void success (TSBiometricsRegistrationResult tsBiometricsRegistrationResult ) {
187+ WritableMap map = new WritableNativeMap ();
188+ map .putString ("publicKeyId" , tsBiometricsRegistrationResult .keyId ());
189+ map .putString ("publicKey" , tsBiometricsRegistrationResult .publicKey ());
190+ map .putString ("os" , "Android" );
191+ promise .resolve (map );
192+ }
193+
194+ @ Override
195+ public void error (TSBiometricsRegistrationError tsBiometricsRegistrationError ) {
196+ promise .reject ("result" , tsBiometricsRegistrationError .toString ());
197+ }
198+ });
185199 }
186200 }
187201
188202 @ ReactMethod
189- @ NonNull public void authenticateNativeBiometrics (String username , String challenge , Promise promise ) {
190- if (reactContext .getCurrentActivity () != null ) {
203+ @ NonNull
204+ public void authenticateNativeBiometrics (String username , String challenge , Promise promise ) {
205+ if (reactContext .getCurrentActivity () != null ) {
191206
192207 AppCompatActivity appCompatActivity = getAppCompatActivity ();
193208 if (appCompatActivity == null ) {
@@ -197,31 +212,29 @@ public void error(TSBiometricsRegistrationError tsBiometricsRegistrationError) {
197212
198213 Map <String , String > biometricsString = getBiometricsStrings ();
199214 BiometricPromptTexts promptTexts = new BiometricPromptTexts (
200- biometricsString .get ("titleTxt" ),
201- biometricsString .get ("subtitleTxt" ),
202- biometricsString .get ("cancelTxt" )
203- );
215+ biometricsString .get ("titleTxt" ),
216+ biometricsString .get ("subtitleTxt" ),
217+ biometricsString .get ("cancelTxt" ));
204218
205219 TSAuthentication .authenticateNativeBiometrics (
206- appCompatActivity ,
207- username ,
208- challenge ,
209- promptTexts ,
210- new TSAuthCallback <TSBiometricsAuthResult , TSBiometricsAuthError >() {
211- @ Override
212- public void success (TSBiometricsAuthResult tsBiometricsAuthResult ) {
213- WritableMap map = new WritableNativeMap ();
214- map .putString ("publicKeyId" , tsBiometricsAuthResult .keyId ());
215- map .putString ("signature" , tsBiometricsAuthResult .signature ());
216- promise .resolve (map );
217- }
218-
219- @ Override
220- public void error (TSBiometricsAuthError tsBiometricsAuthError ) {
221- promise .reject ("result" , tsBiometricsAuthError .toString ());
222- }
223- }
224- );
220+ appCompatActivity ,
221+ username ,
222+ challenge ,
223+ promptTexts ,
224+ new TSAuthCallback <TSBiometricsAuthResult , TSBiometricsAuthError >() {
225+ @ Override
226+ public void success (TSBiometricsAuthResult tsBiometricsAuthResult ) {
227+ WritableMap map = new WritableNativeMap ();
228+ map .putString ("publicKeyId" , tsBiometricsAuthResult .keyId ());
229+ map .putString ("signature" , tsBiometricsAuthResult .signature ());
230+ promise .resolve (map );
231+ }
232+
233+ @ Override
234+ public void error (TSBiometricsAuthError tsBiometricsAuthError ) {
235+ promise .reject ("result" , tsBiometricsAuthError .toString ());
236+ }
237+ });
225238 }
226239 }
227240
@@ -239,7 +252,8 @@ private Map<String, String> getBiometricsStrings() {
239252 Context context = reactContext ;
240253
241254 String titleTxt = getStringResourceByName (context , "BiometricPromptTitle" , "Authenticate with Biometrics" );
242- String subtitleTxt = getStringResourceByName (context , "BiometricPromptSubtitle" , "Use your device biometrics to authenticate." );
255+ String subtitleTxt = getStringResourceByName (context , "BiometricPromptSubtitle" ,
256+ "Use your device biometrics to authenticate." );
243257 String cancelTxt = getStringResourceByName (context , "BiometricPromptCancel" , "Cancel" );
244258
245259 Map <String , String > biometricsStrings = new HashMap <>();
@@ -256,31 +270,31 @@ private String getStringResourceByName(Context context, String resourceName, Str
256270 }
257271
258272 @ ReactMethod
259- @ NonNull public void getDeviceInfo (Promise promise ) {
260- if (reactContext .getCurrentActivity () != null ) {
273+ @ NonNull
274+ public void getDeviceInfo (Promise promise ) {
275+ if (reactContext .getCurrentActivity () != null ) {
261276 TSAuthentication .getDeviceInfo (
262- reactContext .getCurrentActivity (),
263- new TSAuthCallback <DeviceInfo , TSDeviceInfoError >() {
264- @ Override
265- public void success (DeviceInfo deviceInfo ) {
266- WritableMap map = new WritableNativeMap ();
267- map .putString ("publicKeyId" , deviceInfo .getPublicKeyId ());
268- map .putString ("publicKey" , deviceInfo .getPublicKey ());
269- promise .resolve (map );
270- }
271-
272- @ Override
273- public void error (TSDeviceInfoError tsDeviceInfoError ) {
274- promise .reject ("result" , tsDeviceInfoError .toString ());
275- }
276- }
277- );
277+ reactContext .getCurrentActivity (),
278+ new TSAuthCallback <DeviceInfo , TSDeviceInfoError >() {
279+ @ Override
280+ public void success (DeviceInfo deviceInfo ) {
281+ WritableMap map = new WritableNativeMap ();
282+ map .putString ("publicKeyId" , deviceInfo .getPublicKeyId ());
283+ map .putString ("publicKey" , deviceInfo .getPublicKey ());
284+ promise .resolve (map );
285+ }
286+
287+ @ Override
288+ public void error (TSDeviceInfoError tsDeviceInfoError ) {
289+ promise .reject ("result" , tsDeviceInfoError .toString ());
290+ }
291+ });
278292 }
279293 }
280294
281295 @ ReactMethod
282- @ NonNull public void isWebAuthnSupported (Promise promise ) {
296+ @ NonNull
297+ public void isWebAuthnSupported (Promise promise ) {
283298 promise .resolve (TSAuthentication .isWebAuthnSupported ());
284299 }
285300}
286-
0 commit comments