This repository has been archived by the owner on Feb 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 451
/
enhance-rn.js
59 lines (51 loc) · 1.66 KB
/
enhance-rn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import AWS from 'aws-sdk/global';
import { NativeModules } from 'react-native';
import * as enhancements from './src';
import BigInteger from './src/BigInteger';
export * from './src';
const { RNAWSCognito } = NativeModules;
Object.keys(enhancements).forEach(key => {
AWS.CognitoIdentityServiceProvider[key] = enhancements[key];
});
BigInteger.prototype.modPow = function nativeModPow(e, m, callback) {
RNAWSCognito.computeModPow({
target: this.toString(16),
value: e.toString(16),
modifier: m.toString(16),
}, (err, result) => {
if (err) {
return callback(new Error(err), null);
}
const bigIntResult = new BigInteger(result, 16);
return callback(null, bigIntResult);
});
};
enhancements.AuthenticationHelper.prototype.calculateS =
function nativeComputeS(xValue, serverBValue, callback) {
RNAWSCognito.computeS({
g: this.g.toString(16),
x: xValue.toString(16),
k: this.k.toString(16),
a: this.smallAValue.toString(16),
b: serverBValue.toString(16),
u: this.UValue.toString(16),
}, (err, result) => {
if (err) {
return callback(new Error(err), null);
}
const bigIntResult = new BigInteger(result, 16);
return callback(null, bigIntResult);
});
return undefined;
};
const libraryVersion = '1.0';
const libraryName = 'aws-amplify';
const originalUserAgent = AWS.util.userAgent;
if (originalUserAgent) {
AWS.util.userAgent = function newUserAgent() {
return `${libraryName}/${libraryVersion} ${originalUserAgent()}`;
};
} else {
const previousUserAgent = AWS.config.customUserAgent || '';
AWS.config.update({ customUserAgent: `${libraryName}/${libraryVersion} ${previousUserAgent}` });
}