11package com .tsauthentication ;
2-
3- import static androidx .work .ListenableWorker .Result .success ;
4-
52import androidx .annotation .NonNull ;
6-
73import com .facebook .react .bridge .Promise ;
84import com .facebook .react .bridge .ReactApplicationContext ;
95import com .facebook .react .bridge .ReactContextBaseJavaModule ;
106import com .facebook .react .bridge .ReactMethod ;
117import com .facebook .react .bridge .WritableMap ;
128import com .facebook .react .bridge .WritableNativeMap ;
139import com .facebook .react .module .annotations .ReactModule ;
14- import com .transmit .authentication .AuthenticationError ;
10+ import com .transmit .authentication .TSDeviceInfoError ;
11+ import com .transmit .authentication .TSWebAuthnAuthenticationError ;
1512import com .transmit .authentication .AuthenticationResult ;
1613import com .transmit .authentication .RegistrationResult ;
1714import com .transmit .authentication .TSAuthCallback ;
1815import com .transmit .authentication .TSAuthentication ;
16+ import com .transmit .authentication .TSWebAuthnRegistrationError ;
17+ import com .transmit .authentication .network .completereg .DeviceInfo ;
1918
2019import java .util .HashMap ;
2120
@@ -39,7 +38,7 @@ public String getName() {
3938 @ NonNull public void initialize (String clientId , String domain , String baseUrl , Promise promise ) {
4039
4140 if (reactContext .getCurrentActivity () != null ) {
42- TSAuthentication .init (
41+ TSAuthentication .initialize (
4342 reactContext ,
4443 baseUrl ,
4544 clientId
@@ -51,44 +50,38 @@ public String getName() {
5150 // Registration
5251
5352 @ ReactMethod
54- @ NonNull public void register (
53+ @ NonNull public void registerWebAuthn (
5554 String username ,
5655 String displayName ,
5756 Promise promise ) {
57+
5858 if (reactContext .getCurrentActivity () != null ) {
59- TSAuthentication .isPlatformAuthenticatorSupported (
60- reactContext .getCurrentActivity (),
61- new TSAuthCallback <Boolean >() {
62- @ Override
63- public void success (Boolean aBoolean ) {
64- continueRegistration (username , displayName , promise );
65- }
59+ Boolean isSupported = TSAuthentication .isWebAuthnSupported ();
60+ if (!isSupported ) {
61+ promise .reject (new Error ("Unsupported platform" ));
62+ return ;
63+ }
6664
67- @ Override
68- public void error (@ NonNull AuthenticationError authenticationError ) {
69- promise .reject (new Error ("Unsupported platform" ));
70- }
71- }
72- );
65+ continueRegistration (username , displayName , promise );
7366 }
7467 }
68+
7569 private void continueRegistration (String username , String displayName , Promise promise ) {
7670 if (reactContext .getCurrentActivity () != null ) {
77- TSAuthentication .register (
71+ TSAuthentication .registerWebAuthn (
7872 reactContext .getCurrentActivity (),
7973 username ,
8074 displayName ,
81- new TSAuthCallback <RegistrationResult >() {
75+ new TSAuthCallback <RegistrationResult , TSWebAuthnRegistrationError >() {
8276 @ Override
8377 public void success (RegistrationResult registrationResult ) {
8478 WritableMap map = new WritableNativeMap ();
8579 map .putString (registrationResult .result (), NAME );
8680 promise .resolve (map );
8781 }
88-
8982 @ Override
90- public void error (@ NonNull AuthenticationError authenticationError ) {
91- promise .reject (NAME , authenticationError .toString ());
83+ public void error (TSWebAuthnRegistrationError tsWebAuthnRegistrationError ) {
84+ promise .reject (NAME , tsWebAuthnRegistrationError .toString ());
9285 }
9386 }
9487 );
@@ -97,35 +90,34 @@ public void error(@NonNull AuthenticationError authenticationError) {
9790
9891 // Authentication
9992 @ ReactMethod
100- @ NonNull public void authenticate (String username , Promise promise ) {
93+ @ NonNull public void authenticateWebAuthn (String username , Promise promise ) {
10194 if (reactContext .getCurrentActivity () != null ) {
102- TSAuthentication .authenticate (
95+ TSAuthentication .authenticateWebAuthn (
10396 reactContext .getCurrentActivity (),
10497 username ,
105- new TSAuthCallback <AuthenticationResult >() {
98+ new TSAuthCallback <AuthenticationResult , TSWebAuthnAuthenticationError >() {
10699 @ Override
107100 public void success (AuthenticationResult authenticationResult ) {
108101 WritableMap map = new WritableNativeMap ();
109102 map .putString (authenticationResult .result (), NAME );
110103 promise .resolve (map );
111104 }
112-
113105 @ Override
114- public void error (@ NonNull AuthenticationError authenticationError ) {
115- promise .reject (NAME , authenticationError .toString ());
106+ public void error (TSWebAuthnAuthenticationError tsWebAuthnAuthenticationError ) {
107+ promise .reject (NAME , tsWebAuthnAuthenticationError .toString ());
116108 }
117- }
118- );
109+ });
119110 }
120111 }
121112
113+ // Transaction
122114 @ ReactMethod
123- @ NonNull public void signTransaction (String username , Promise promise ) {
115+ @ NonNull public void signTransactionWebAuthn (String username , Promise promise ) {
124116 if (reactContext .getCurrentActivity () != null ) {
125- TSAuthentication .signTransaction (
117+ TSAuthentication .signTransactionWebAuthn (
126118 reactContext .getCurrentActivity (),
127119 username ,
128- new TSAuthCallback <AuthenticationResult >() {
120+ new TSAuthCallback <AuthenticationResult , TSWebAuthnAuthenticationError >() {
129121 @ Override
130122 public void success (AuthenticationResult authenticationResult ) {
131123 WritableMap map = new WritableNativeMap ();
@@ -134,12 +126,40 @@ public void success(AuthenticationResult authenticationResult) {
134126 }
135127
136128 @ Override
137- public void error (@ NonNull AuthenticationError authenticationError ) {
138- promise .reject (NAME , authenticationError .toString ());
129+ public void error (TSWebAuthnAuthenticationError tsWebAuthnAuthenticationError ) {
130+ promise .reject (NAME , tsWebAuthnAuthenticationError .toString ());
131+ }
132+ }
133+ );
134+ }
135+ }
136+
137+ @ ReactMethod
138+ @ NonNull public void getDeviceInfo (Promise promise ) {
139+ if (reactContext .getCurrentActivity () != null ) {
140+ TSAuthentication .getDeviceInfo (
141+ reactContext .getCurrentActivity (),
142+ new TSAuthCallback <DeviceInfo , TSDeviceInfoError >() {
143+ @ Override
144+ public void success (DeviceInfo deviceInfo ) {
145+ WritableMap map = new WritableNativeMap ();
146+ map .putString ("publicKeyId" , deviceInfo .getPublicKeyId ());
147+ map .putString ("publicKey" , deviceInfo .getPublicKey ());
148+ promise .resolve (map );
149+ }
150+
151+ @ Override
152+ public void error (TSDeviceInfoError tsDeviceInfoError ) {
153+ promise .reject (NAME , tsDeviceInfoError .toString ());
139154 }
140155 }
141156 );
142157 }
143158 }
159+
160+ @ ReactMethod
161+ @ NonNull public void isWebAuthnSupported (Promise promise ) {
162+ promise .resolve (TSAuthentication .isWebAuthnSupported ());
163+ }
144164}
145165
0 commit comments