11package com .tsauthentication ;
22
3- import static androidx .work .ListenableWorker .Result .success ;
4-
53import androidx .annotation .NonNull ;
6-
74import com .facebook .react .bridge .Promise ;
85import com .facebook .react .bridge .ReactApplicationContext ;
96import com .facebook .react .bridge .ReactContextBaseJavaModule ;
107import com .facebook .react .bridge .ReactMethod ;
118import com .facebook .react .bridge .WritableMap ;
129import com .facebook .react .bridge .WritableNativeMap ;
1310import com .facebook .react .module .annotations .ReactModule ;
14- import com .transmit .authentication .AuthenticationError ;
11+ import com .transmit .authentication .TSDeviceInfoError ;
12+ import com .transmit .authentication .TSWebAuthnAuthenticationError ;
1513import com .transmit .authentication .AuthenticationResult ;
1614import com .transmit .authentication .RegistrationResult ;
1715import com .transmit .authentication .TSAuthCallback ;
1816import com .transmit .authentication .TSAuthentication ;
17+ import com .transmit .authentication .TSWebAuthnRegistrationError ;
18+ import com .transmit .authentication .network .completereg .DeviceInfo ;
1919
2020import java .util .HashMap ;
2121
@@ -39,9 +39,8 @@ public String getName() {
3939 @ NonNull public void initialize (String clientId , String domain , String baseUrl , Promise promise ) {
4040
4141 if (reactContext .getCurrentActivity () != null ) {
42- TSAuthentication .init (
42+ TSAuthentication .initialize (
4343 reactContext ,
44- baseUrl ,
4544 clientId
4645 );
4746 promise .resolve (true );
@@ -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 ();
85- map .putString (registrationResult .result (), NAME );
79+ map .putString ("result" , registrationResult .result ());
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 ("result" , tsWebAuthnRegistrationError . getEM ());
9285 }
9386 }
9487 );
@@ -97,49 +90,76 @@ 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 ();
109- map .putString (authenticationResult .result (), NAME );
102+ map .putString ("result" , authenticationResult .result ());
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 ("result" , 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 ();
132- map .putString (authenticationResult .result (), NAME );
124+ map .putString ("result" , authenticationResult .result ());
133125 promise .resolve (map );
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 ("result" , tsWebAuthnAuthenticationError .toString ());
139131 }
140132 }
141133 );
142134 }
143135 }
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 ("result" , tsDeviceInfoError .toString ());
154+ }
155+ }
156+ );
157+ }
158+ }
159+
160+ @ ReactMethod
161+ @ NonNull public void isWebAuthnSupported (Promise promise ) {
162+ promise .resolve (TSAuthentication .isWebAuthnSupported ());
163+ }
144164}
145165
0 commit comments