@@ -7,44 +7,60 @@ export * from './src';
77
88const { RNAWSCognito } = NativeModules ;
99
10+ // Store the original functions before overriding
11+ const originalModPow = BigInteger . prototype . modPow ;
12+ const originalCalculateS = src . AuthenticationHelper . prototype . calculateS ;
13+
1014BigInteger . prototype . modPow = function nativeModPow ( e , m , callback ) {
11- RNAWSCognito . computeModPow (
12- {
13- target : this . toString ( 16 ) ,
14- value : e . toString ( 16 ) ,
15- modifier : m . toString ( 16 ) ,
16- } ,
17- ( err , result ) => {
18- if ( err ) {
19- return callback ( new Error ( err ) , null ) ;
15+ // Check if native module is available
16+ if ( RNAWSCognito && RNAWSCognito . computeModPow ) {
17+ RNAWSCognito . computeModPow (
18+ {
19+ target : this . toString ( 16 ) ,
20+ value : e . toString ( 16 ) ,
21+ modifier : m . toString ( 16 ) ,
22+ } ,
23+ ( err , result ) => {
24+ if ( err ) {
25+ return callback ( new Error ( err ) , null ) ;
26+ }
27+ const bigIntResult = new BigInteger ( result , 16 ) ;
28+ return callback ( null , bigIntResult ) ;
2029 }
21- const bigIntResult = new BigInteger ( result , 16 ) ;
22- return callback ( null , bigIntResult ) ;
23- }
24- ) ;
30+ ) ;
31+ } else {
32+ // Fall back to original JavaScript implementation
33+ return originalModPow . call ( this , e , m , callback ) ;
34+ }
2535} ;
2636
2737src . AuthenticationHelper . prototype . calculateS = function nativeComputeS (
2838 xValue ,
2939 serverBValue ,
3040 callback
3141) {
32- RNAWSCognito . computeS (
33- {
34- g : this . g . toString ( 16 ) ,
35- x : xValue . toString ( 16 ) ,
36- k : this . k . toString ( 16 ) ,
37- a : this . smallAValue . toString ( 16 ) ,
38- b : serverBValue . toString ( 16 ) ,
39- u : this . UValue . toString ( 16 ) ,
40- } ,
41- ( err , result ) => {
42- if ( err ) {
43- return callback ( new Error ( err ) , null ) ;
42+ // Check if native module is available
43+ if ( RNAWSCognito && RNAWSCognito . computeS ) {
44+ RNAWSCognito . computeS (
45+ {
46+ g : this . g . toString ( 16 ) ,
47+ x : xValue . toString ( 16 ) ,
48+ k : this . k . toString ( 16 ) ,
49+ a : this . smallAValue . toString ( 16 ) ,
50+ b : serverBValue . toString ( 16 ) ,
51+ u : this . UValue . toString ( 16 ) ,
52+ } ,
53+ ( err , result ) => {
54+ if ( err ) {
55+ return callback ( new Error ( err ) , null ) ;
56+ }
57+ const bigIntResult = new BigInteger ( result , 16 ) ;
58+ return callback ( null , bigIntResult ) ;
4459 }
45- const bigIntResult = new BigInteger ( result , 16 ) ;
46- return callback ( null , bigIntResult ) ;
47- }
48- ) ;
60+ ) ;
61+ } else {
62+ // Fall back to original JavaScript implementation
63+ return originalCalculateS . call ( this , xValue , serverBValue , callback ) ;
64+ }
4965 return undefined ;
5066} ;
0 commit comments