react-native-security-suite 0.1.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -2
- package/README.md +40 -3
- package/android/build.gradle +85 -43
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +1 -3
- package/android/src/main/AndroidManifestDeprecated.xml +3 -0
- package/android/src/main/java/com/securitysuite/SecuritySuiteModule.java +202 -0
- package/android/src/main/java/com/securitysuite/SecuritySuitePackage.java +28 -0
- package/android/src/main/java/com/securitysuite/StorageEncryption.java +52 -0
- package/ios/DataHashingMethods.swift +196 -0
- package/ios/SecuritySuite-Bridging-Header.h +1 -0
- package/ios/SecuritySuite.mm +26 -0
- package/ios/SecuritySuite.swift +129 -0
- package/ios/SecuritySuite.xcodeproj/project.pbxproj +13 -17
- package/ios/SecuritySuite.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
- package/ios/SecuritySuite.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/SecuritySuite.xcodeproj/project.xcworkspace/xcuserdata/mohammadnavabi.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/SecuritySuite.xcodeproj/xcuserdata/mohammadnavabi.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/ios/StorageEncryption.swift +81 -0
- package/lib/commonjs/helpers.js +16 -0
- package/lib/commonjs/helpers.js.map +1 -0
- package/lib/commonjs/index.js +158 -6
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/helpers.js +9 -0
- package/lib/module/helpers.js.map +1 -0
- package/lib/module/index.js +147 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/helpers.d.ts +2 -0
- package/lib/typescript/helpers.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +20 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/package.json +54 -33
- package/react-native-security-suite.podspec +18 -2
- package/src/helpers.ts +8 -0
- package/src/index.tsx +203 -3
- package/android/src/main/java/com/reactnativesecuritysuite/SecuritySuiteModule.java +0 -38
- package/android/src/main/java/com/reactnativesecuritysuite/SecuritySuitePackage.java +0 -28
- package/ios/SecuritySuite.m +0 -12
package/lib/commonjs/index.js
CHANGED
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.default = exports.decryptBySharedKey = exports.decrypt = exports.SecureStorage = void 0;
|
|
7
7
|
exports.deviceHasSecurityRisk = deviceHasSecurityRisk;
|
|
8
|
-
|
|
8
|
+
exports.getSharedKey = exports.getPublicKey = exports.getDeviceId = exports.encryptBySharedKey = exports.encrypt = void 0;
|
|
9
9
|
var _reactNative = require("react-native");
|
|
10
|
-
|
|
10
|
+
var _asyncStorage = _interopRequireDefault(require("@react-native-async-storage/async-storage"));
|
|
11
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
12
|
+
var _helpers = require("./helpers");
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
14
|
const LINKING_ERROR = `The package 'react-native-security-suite' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
|
|
12
15
|
ios: "- You have run 'pod install'\n",
|
|
13
16
|
default: ''
|
|
@@ -16,13 +19,162 @@ const SecuritySuite = _reactNative.NativeModules.SecuritySuite ? _reactNative.Na
|
|
|
16
19
|
get() {
|
|
17
20
|
throw new Error(LINKING_ERROR);
|
|
18
21
|
}
|
|
19
|
-
|
|
20
22
|
});
|
|
21
|
-
|
|
23
|
+
const getPublicKey = () => SecuritySuite.getPublicKey();
|
|
24
|
+
exports.getPublicKey = getPublicKey;
|
|
25
|
+
const getSharedKey = serverPublicKey => SecuritySuite.getSharedKey(serverPublicKey);
|
|
26
|
+
exports.getSharedKey = getSharedKey;
|
|
27
|
+
const encryptBySharedKey = input => input && typeof input === 'string' ? SecuritySuite.encrypt(input) : '';
|
|
28
|
+
exports.encryptBySharedKey = encryptBySharedKey;
|
|
29
|
+
const decryptBySharedKey = input => input && typeof input === 'string' ? SecuritySuite.decrypt(input) : '';
|
|
30
|
+
exports.decryptBySharedKey = decryptBySharedKey;
|
|
31
|
+
const getDeviceId = () => new Promise((resolve, reject) => {
|
|
32
|
+
SecuritySuite.getDeviceId((result, error) => {
|
|
33
|
+
if (error !== null) reject(error);else resolve(result);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
exports.getDeviceId = getDeviceId;
|
|
37
|
+
const encrypt = function (input) {
|
|
38
|
+
let hardEncryption = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
39
|
+
let secretKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
if (!input) resolve(input);
|
|
42
|
+
SecuritySuite.storageEncrypt(input, secretKey, hardEncryption, (result, error) => {
|
|
43
|
+
if (error !== null) reject(error);else resolve(result);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
exports.encrypt = encrypt;
|
|
48
|
+
const decrypt = function (input) {
|
|
49
|
+
let hardEncryption = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
50
|
+
let secretKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
if (!input) resolve(input);
|
|
53
|
+
SecuritySuite.storageDecrypt(input, secretKey, hardEncryption, (result, error) => {
|
|
54
|
+
if (error !== null) reject(error);else resolve(result);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
exports.decrypt = decrypt;
|
|
59
|
+
const SecureStorage = {
|
|
60
|
+
setItem: async (key, value) => {
|
|
61
|
+
try {
|
|
62
|
+
const encryptedKey = await encrypt(key, false);
|
|
63
|
+
const encryptedValue = await encrypt(value);
|
|
64
|
+
return _asyncStorage.default.setItem(encryptedKey, encryptedValue);
|
|
65
|
+
} catch (e) {
|
|
66
|
+
return e;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
getItem: async key => {
|
|
70
|
+
try {
|
|
71
|
+
const encryptedKey = await encrypt(key, false);
|
|
72
|
+
const encryptedData = await _asyncStorage.default.getItem(encryptedKey);
|
|
73
|
+
return decrypt(encryptedData ?? '');
|
|
74
|
+
} catch (e) {
|
|
75
|
+
return e;
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
mergeItem: async (key, value) => {
|
|
79
|
+
try {
|
|
80
|
+
const encryptedKey = await encrypt(key, false);
|
|
81
|
+
const encryptedData = await _asyncStorage.default.getItem(encryptedKey);
|
|
82
|
+
const data = await decrypt(encryptedData ?? '');
|
|
83
|
+
if (!(0, _helpers.isJsonString)(data) || !(0, _helpers.isJsonString)(value)) return null;
|
|
84
|
+
const mergedData = await JSON.stringify(_lodash.default.merge(JSON.parse(data), JSON.parse(value)));
|
|
85
|
+
const encryptedValue = await encrypt(mergedData);
|
|
86
|
+
return _asyncStorage.default.setItem(encryptedKey, encryptedValue);
|
|
87
|
+
} catch (e) {
|
|
88
|
+
return e;
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
removeItem: async key => {
|
|
92
|
+
try {
|
|
93
|
+
const encryptedKey = await encrypt(key, false);
|
|
94
|
+
return _asyncStorage.default.removeItem(encryptedKey);
|
|
95
|
+
} catch (e) {
|
|
96
|
+
return e;
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
getAllKeys: async () => {
|
|
100
|
+
try {
|
|
101
|
+
const encryptedKeys = await _asyncStorage.default.getAllKeys();
|
|
102
|
+
return await Promise.all(encryptedKeys.map(async item => {
|
|
103
|
+
const decryptedKey = await decrypt(item, false);
|
|
104
|
+
return decryptedKey ? decryptedKey : item;
|
|
105
|
+
}));
|
|
106
|
+
} catch (e) {
|
|
107
|
+
return e;
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
multiSet: async keyValuePairs => {
|
|
111
|
+
try {
|
|
112
|
+
const encryptedKeyValuePairs = await Promise.all(keyValuePairs.map(async item => {
|
|
113
|
+
if (item.length === 2 && item[0] && item[1]) {
|
|
114
|
+
const encryptedKey = await encrypt(item[0], false);
|
|
115
|
+
const encryptedValue = await encrypt(item[1]);
|
|
116
|
+
return [encryptedKey, encryptedValue];
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}));
|
|
120
|
+
_asyncStorage.default.multiSet(encryptedKeyValuePairs);
|
|
121
|
+
} catch (e) {
|
|
122
|
+
console.error('multiSet error: ', e);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
multiGet: async keys => {
|
|
126
|
+
try {
|
|
127
|
+
if (!Array.isArray(keys)) return null;
|
|
128
|
+
const encryptedKeys = await Promise.all(keys.map(async item => await encrypt(item, false)));
|
|
129
|
+
const encryptedItems = await _asyncStorage.default.multiGet(encryptedKeys);
|
|
130
|
+
return await Promise.all(encryptedItems && encryptedItems.length ? encryptedItems.map(async item => {
|
|
131
|
+
const decryptedKey = await decrypt(item[0], false);
|
|
132
|
+
const decryptedalue = await decrypt(item[1]);
|
|
133
|
+
return [decryptedKey, decryptedalue];
|
|
134
|
+
}) : []);
|
|
135
|
+
} catch (e) {
|
|
136
|
+
return e;
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
multiMerge: async keyValuePairs => {
|
|
140
|
+
try {
|
|
141
|
+
return keyValuePairs.map(async item => {
|
|
142
|
+
if (item.length === 2 && item[0] && item[1]) {
|
|
143
|
+
const encryptedKey = await encrypt(item[0], false);
|
|
144
|
+
const encryptedData = await _asyncStorage.default.getItem(item[0]);
|
|
145
|
+
const data = await decrypt(encryptedData ?? '');
|
|
146
|
+
if (!(0, _helpers.isJsonString)(data) || !(0, _helpers.isJsonString)(item[1])) return null;
|
|
147
|
+
const mergedData = await JSON.stringify(_lodash.default.merge(JSON.parse(data), JSON.parse(item[1])));
|
|
148
|
+
const encryptedValue = await encrypt(mergedData, false);
|
|
149
|
+
return _asyncStorage.default.setItem(encryptedKey, encryptedValue);
|
|
150
|
+
}
|
|
151
|
+
return null;
|
|
152
|
+
});
|
|
153
|
+
} catch (e) {
|
|
154
|
+
return e;
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
multiRemove: async keys => {
|
|
158
|
+
try {
|
|
159
|
+
if (!Array.isArray(keys)) return keys;
|
|
160
|
+
const encryptedKeys = await Promise.all(keys.map(async item => await encrypt(item, false)));
|
|
161
|
+
return _asyncStorage.default.multiRemove(encryptedKeys);
|
|
162
|
+
} catch (e) {
|
|
163
|
+
return e;
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
clear: async () => {
|
|
167
|
+
try {
|
|
168
|
+
return _asyncStorage.default.clear();
|
|
169
|
+
} catch (e) {
|
|
170
|
+
return e;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
exports.SecureStorage = SecureStorage;
|
|
22
175
|
function deviceHasSecurityRisk() {
|
|
23
176
|
return SecuritySuite.deviceHasSecurityRisk();
|
|
24
177
|
}
|
|
25
|
-
|
|
26
178
|
var _default = SecuritySuite;
|
|
27
179
|
exports.default = _default;
|
|
28
180
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["LINKING_ERROR","Platform","select","ios","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_asyncStorage","_interopRequireDefault","_lodash","_helpers","obj","__esModule","default","LINKING_ERROR","Platform","select","ios","SecuritySuite","NativeModules","Proxy","get","Error","getPublicKey","exports","getSharedKey","serverPublicKey","encryptBySharedKey","input","encrypt","decryptBySharedKey","decrypt","getDeviceId","Promise","resolve","reject","result","error","hardEncryption","arguments","length","undefined","secretKey","storageEncrypt","storageDecrypt","SecureStorage","setItem","key","value","encryptedKey","encryptedValue","AsyncStorage","e","getItem","encryptedData","mergeItem","data","isJsonString","mergedData","JSON","stringify","_","merge","parse","removeItem","getAllKeys","encryptedKeys","all","map","item","decryptedKey","multiSet","keyValuePairs","encryptedKeyValuePairs","console","multiGet","keys","Array","isArray","encryptedItems","decryptedalue","multiMerge","multiRemove","clear","deviceHasSecurityRisk","_default"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAAyC,SAAAE,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEzC,MAAMG,aAAa,GAChB,sFAAqF,GACtFC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEJ,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,6CAA6C;AAE/C,MAAMK,aAAa,GAAGC,0BAAa,CAACD,aAAa,GAC7CC,0BAAa,CAACD,aAAa,GAC3B,IAAIE,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACR,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEE,MAAMS,YAAY,GAAGA,CAAA,KAAuBL,aAAa,CAACK,YAAY,CAAC,CAAC;AAACC,OAAA,CAAAD,YAAA,GAAAA,YAAA;AAEzE,MAAME,YAAY,GAAIC,eAAuB,IAClDR,aAAa,CAACO,YAAY,CAACC,eAAe,CAAC;AAACF,OAAA,CAAAC,YAAA,GAAAA,YAAA;AAEvC,MAAME,kBAAkB,GAAIC,KAAa,IAC9CA,KAAK,IAAI,OAAOA,KAAK,KAAK,QAAQ,GAAGV,aAAa,CAACW,OAAO,CAACD,KAAK,CAAC,GAAG,EAAE;AAACJ,OAAA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ts"],"mappings":"AAAA,OAAO,MAAMA,YAAY,GAAIC,KAAa,IAAc;EACtD,IAAI;IACFC,IAAI,CAACC,KAAK,CAACF,KAAK,CAAC;EACnB,CAAC,CAAC,OAAOG,CAAC,EAAE;IACV,OAAO,KAAK;EACd;EACA,OAAO,IAAI;AACb,CAAC"}
|
package/lib/module/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { NativeModules, Platform } from 'react-native';
|
|
2
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
import { isJsonString } from './helpers';
|
|
2
5
|
const LINKING_ERROR = `The package 'react-native-security-suite' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
|
|
3
6
|
ios: "- You have run 'pod install'\n",
|
|
4
7
|
default: ''
|
|
@@ -7,8 +10,151 @@ const SecuritySuite = NativeModules.SecuritySuite ? NativeModules.SecuritySuite
|
|
|
7
10
|
get() {
|
|
8
11
|
throw new Error(LINKING_ERROR);
|
|
9
12
|
}
|
|
10
|
-
|
|
11
13
|
});
|
|
14
|
+
export const getPublicKey = () => SecuritySuite.getPublicKey();
|
|
15
|
+
export const getSharedKey = serverPublicKey => SecuritySuite.getSharedKey(serverPublicKey);
|
|
16
|
+
export const encryptBySharedKey = input => input && typeof input === 'string' ? SecuritySuite.encrypt(input) : '';
|
|
17
|
+
export const decryptBySharedKey = input => input && typeof input === 'string' ? SecuritySuite.decrypt(input) : '';
|
|
18
|
+
export const getDeviceId = () => new Promise((resolve, reject) => {
|
|
19
|
+
SecuritySuite.getDeviceId((result, error) => {
|
|
20
|
+
if (error !== null) reject(error);else resolve(result);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
export const encrypt = function (input) {
|
|
24
|
+
let hardEncryption = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
25
|
+
let secretKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
if (!input) resolve(input);
|
|
28
|
+
SecuritySuite.storageEncrypt(input, secretKey, hardEncryption, (result, error) => {
|
|
29
|
+
if (error !== null) reject(error);else resolve(result);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
export const decrypt = function (input) {
|
|
34
|
+
let hardEncryption = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
35
|
+
let secretKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
if (!input) resolve(input);
|
|
38
|
+
SecuritySuite.storageDecrypt(input, secretKey, hardEncryption, (result, error) => {
|
|
39
|
+
if (error !== null) reject(error);else resolve(result);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
export const SecureStorage = {
|
|
44
|
+
setItem: async (key, value) => {
|
|
45
|
+
try {
|
|
46
|
+
const encryptedKey = await encrypt(key, false);
|
|
47
|
+
const encryptedValue = await encrypt(value);
|
|
48
|
+
return AsyncStorage.setItem(encryptedKey, encryptedValue);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
return e;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
getItem: async key => {
|
|
54
|
+
try {
|
|
55
|
+
const encryptedKey = await encrypt(key, false);
|
|
56
|
+
const encryptedData = await AsyncStorage.getItem(encryptedKey);
|
|
57
|
+
return decrypt(encryptedData ?? '');
|
|
58
|
+
} catch (e) {
|
|
59
|
+
return e;
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
mergeItem: async (key, value) => {
|
|
63
|
+
try {
|
|
64
|
+
const encryptedKey = await encrypt(key, false);
|
|
65
|
+
const encryptedData = await AsyncStorage.getItem(encryptedKey);
|
|
66
|
+
const data = await decrypt(encryptedData ?? '');
|
|
67
|
+
if (!isJsonString(data) || !isJsonString(value)) return null;
|
|
68
|
+
const mergedData = await JSON.stringify(_.merge(JSON.parse(data), JSON.parse(value)));
|
|
69
|
+
const encryptedValue = await encrypt(mergedData);
|
|
70
|
+
return AsyncStorage.setItem(encryptedKey, encryptedValue);
|
|
71
|
+
} catch (e) {
|
|
72
|
+
return e;
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
removeItem: async key => {
|
|
76
|
+
try {
|
|
77
|
+
const encryptedKey = await encrypt(key, false);
|
|
78
|
+
return AsyncStorage.removeItem(encryptedKey);
|
|
79
|
+
} catch (e) {
|
|
80
|
+
return e;
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
getAllKeys: async () => {
|
|
84
|
+
try {
|
|
85
|
+
const encryptedKeys = await AsyncStorage.getAllKeys();
|
|
86
|
+
return await Promise.all(encryptedKeys.map(async item => {
|
|
87
|
+
const decryptedKey = await decrypt(item, false);
|
|
88
|
+
return decryptedKey ? decryptedKey : item;
|
|
89
|
+
}));
|
|
90
|
+
} catch (e) {
|
|
91
|
+
return e;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
multiSet: async keyValuePairs => {
|
|
95
|
+
try {
|
|
96
|
+
const encryptedKeyValuePairs = await Promise.all(keyValuePairs.map(async item => {
|
|
97
|
+
if (item.length === 2 && item[0] && item[1]) {
|
|
98
|
+
const encryptedKey = await encrypt(item[0], false);
|
|
99
|
+
const encryptedValue = await encrypt(item[1]);
|
|
100
|
+
return [encryptedKey, encryptedValue];
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}));
|
|
104
|
+
AsyncStorage.multiSet(encryptedKeyValuePairs);
|
|
105
|
+
} catch (e) {
|
|
106
|
+
console.error('multiSet error: ', e);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
multiGet: async keys => {
|
|
110
|
+
try {
|
|
111
|
+
if (!Array.isArray(keys)) return null;
|
|
112
|
+
const encryptedKeys = await Promise.all(keys.map(async item => await encrypt(item, false)));
|
|
113
|
+
const encryptedItems = await AsyncStorage.multiGet(encryptedKeys);
|
|
114
|
+
return await Promise.all(encryptedItems && encryptedItems.length ? encryptedItems.map(async item => {
|
|
115
|
+
const decryptedKey = await decrypt(item[0], false);
|
|
116
|
+
const decryptedalue = await decrypt(item[1]);
|
|
117
|
+
return [decryptedKey, decryptedalue];
|
|
118
|
+
}) : []);
|
|
119
|
+
} catch (e) {
|
|
120
|
+
return e;
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
multiMerge: async keyValuePairs => {
|
|
124
|
+
try {
|
|
125
|
+
return keyValuePairs.map(async item => {
|
|
126
|
+
if (item.length === 2 && item[0] && item[1]) {
|
|
127
|
+
const encryptedKey = await encrypt(item[0], false);
|
|
128
|
+
const encryptedData = await AsyncStorage.getItem(item[0]);
|
|
129
|
+
const data = await decrypt(encryptedData ?? '');
|
|
130
|
+
if (!isJsonString(data) || !isJsonString(item[1])) return null;
|
|
131
|
+
const mergedData = await JSON.stringify(_.merge(JSON.parse(data), JSON.parse(item[1])));
|
|
132
|
+
const encryptedValue = await encrypt(mergedData, false);
|
|
133
|
+
return AsyncStorage.setItem(encryptedKey, encryptedValue);
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
});
|
|
137
|
+
} catch (e) {
|
|
138
|
+
return e;
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
multiRemove: async keys => {
|
|
142
|
+
try {
|
|
143
|
+
if (!Array.isArray(keys)) return keys;
|
|
144
|
+
const encryptedKeys = await Promise.all(keys.map(async item => await encrypt(item, false)));
|
|
145
|
+
return AsyncStorage.multiRemove(encryptedKeys);
|
|
146
|
+
} catch (e) {
|
|
147
|
+
return e;
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
clear: async () => {
|
|
151
|
+
try {
|
|
152
|
+
return AsyncStorage.clear();
|
|
153
|
+
} catch (e) {
|
|
154
|
+
return e;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
12
158
|
export function deviceHasSecurityRisk() {
|
|
13
159
|
return SecuritySuite.deviceHasSecurityRisk();
|
|
14
160
|
}
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","SecuritySuite","Proxy","get","Error","
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","AsyncStorage","_","isJsonString","LINKING_ERROR","select","ios","default","SecuritySuite","Proxy","get","Error","getPublicKey","getSharedKey","serverPublicKey","encryptBySharedKey","input","encrypt","decryptBySharedKey","decrypt","getDeviceId","Promise","resolve","reject","result","error","hardEncryption","arguments","length","undefined","secretKey","storageEncrypt","storageDecrypt","SecureStorage","setItem","key","value","encryptedKey","encryptedValue","e","getItem","encryptedData","mergeItem","data","mergedData","JSON","stringify","merge","parse","removeItem","getAllKeys","encryptedKeys","all","map","item","decryptedKey","multiSet","keyValuePairs","encryptedKeyValuePairs","console","multiGet","keys","Array","isArray","encryptedItems","decryptedalue","multiMerge","multiRemove","clear","deviceHasSecurityRisk"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AACtD,OAAOC,YAAY,MAAM,2CAA2C;AACpE,OAAOC,CAAC,MAAM,QAAQ;AACtB,SAASC,YAAY,QAAQ,WAAW;AAExC,MAAMC,aAAa,GAChB,sFAAqF,GACtFJ,QAAQ,CAACK,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,6CAA6C;AAE/C,MAAMC,aAAa,GAAGT,aAAa,CAACS,aAAa,GAC7CT,aAAa,CAACS,aAAa,GAC3B,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEL,OAAO,MAAMQ,YAAY,GAAGA,CAAA,KAAuBJ,aAAa,CAACI,YAAY,CAAC,CAAC;AA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,UAAW,MAAM,KAAG,OAO5C,CAAC"}
|
|
@@ -1,3 +1,23 @@
|
|
|
1
1
|
declare const SecuritySuite: any;
|
|
2
|
+
export declare const getPublicKey: () => Promise<string>;
|
|
3
|
+
export declare const getSharedKey: (serverPublicKey: string) => Promise<string>;
|
|
4
|
+
export declare const encryptBySharedKey: (input: string) => Promise<string>;
|
|
5
|
+
export declare const decryptBySharedKey: (input: string) => any;
|
|
6
|
+
export declare const getDeviceId: () => Promise<string>;
|
|
7
|
+
export declare const encrypt: (input: string, hardEncryption?: boolean, secretKey?: null) => Promise<string>;
|
|
8
|
+
export declare const decrypt: (input: string, hardEncryption?: boolean, secretKey?: null) => Promise<string>;
|
|
9
|
+
export declare const SecureStorage: {
|
|
10
|
+
setItem: (key: string, value: string) => Promise<unknown>;
|
|
11
|
+
getItem: (key: string) => Promise<unknown>;
|
|
12
|
+
mergeItem: (key: string, value: string) => Promise<unknown>;
|
|
13
|
+
removeItem: (key: string) => Promise<unknown>;
|
|
14
|
+
getAllKeys: () => Promise<unknown>;
|
|
15
|
+
multiSet: (keyValuePairs: Array<Array<string>>) => Promise<void | string[][]>;
|
|
16
|
+
multiGet: (keys: Array<string>) => Promise<unknown>;
|
|
17
|
+
multiMerge: (keyValuePairs: Array<Array<string>>) => Promise<unknown>;
|
|
18
|
+
multiRemove: (keys: Array<string>) => Promise<unknown>;
|
|
19
|
+
clear: () => Promise<unknown>;
|
|
20
|
+
};
|
|
2
21
|
export declare function deviceHasSecurityRisk(): Promise<boolean>;
|
|
3
22
|
export default SecuritySuite;
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAWA,QAAA,MAAM,aAAa,KASd,CAAC;AAEN,eAAO,MAAM,YAAY,QAAO,QAAQ,MAAM,CAAiC,CAAC;AAEhF,eAAO,MAAM,YAAY,oBAAqB,MAAM,KAAG,QAAQ,MAAM,CACxB,CAAC;AAE9C,eAAO,MAAM,kBAAkB,UAAW,MAAM,KAAG,QAAQ,MAAM,CACO,CAAC;AAEzE,eAAO,MAAM,kBAAkB,UAAW,MAAM,QACwB,CAAC;AAEzE,eAAO,MAAM,WAAW,QAAO,QAAQ,MAAM,CAMzC,CAAC;AAEL,eAAO,MAAM,OAAO,UACX,MAAM,iDAGZ,QAAQ,MAAM,CAab,CAAC;AAEL,eAAO,MAAM,OAAO,UACX,MAAM,iDAGZ,QAAQ,MAAM,CAab,CAAC;AAEL,eAAO,MAAM,aAAa;mBACH,MAAM,SAAS,MAAM;mBASrB,MAAM;qBASJ,MAAM,SAAS,MAAM;sBAepB,MAAM;;8BAsBb,MAAM,MAAM,MAAM,CAAC,CAAC,KAClC,QAAQ,IAAI,GAAG,MAAM,EAAE,EAAE,CAAC;qBAkBN,MAAM,MAAM,CAAC;gCAsBF,MAAM,MAAM,MAAM,CAAC,CAAC;wBAqB5B,MAAM,MAAM,CAAC;;CAoBxC,CAAC;AAEF,wBAAgB,qBAAqB,IAAI,OAAO,CAAC,OAAO,CAAC,CAExD;AAED,eAAe,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-security-suite",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Security
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Security solution for React Native",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
7
7
|
"types": "lib/typescript/index.d.ts",
|
|
@@ -13,34 +13,38 @@
|
|
|
13
13
|
"android",
|
|
14
14
|
"ios",
|
|
15
15
|
"cpp",
|
|
16
|
-
"
|
|
16
|
+
"*.podspec",
|
|
17
17
|
"!lib/typescript/example",
|
|
18
|
-
"!android/build",
|
|
19
18
|
"!ios/build",
|
|
19
|
+
"!android/build",
|
|
20
|
+
"!android/gradle",
|
|
21
|
+
"!android/gradlew",
|
|
22
|
+
"!android/gradlew.bat",
|
|
23
|
+
"!android/local.properties",
|
|
20
24
|
"!**/__tests__",
|
|
21
25
|
"!**/__fixtures__",
|
|
22
|
-
"!**/__mocks__"
|
|
26
|
+
"!**/__mocks__",
|
|
27
|
+
"!**/.*"
|
|
23
28
|
],
|
|
24
29
|
"scripts": {
|
|
25
30
|
"test": "jest",
|
|
26
|
-
"
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
27
32
|
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
28
|
-
"
|
|
33
|
+
"prepack": "bob build",
|
|
29
34
|
"release": "release-it",
|
|
30
35
|
"example": "yarn --cwd example",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
36
|
+
"build:android": "cd example/android && ./gradlew assembleDebug --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a",
|
|
37
|
+
"build:ios": "cd example/ios && xcodebuild -workspace SecuritySuiteExample.xcworkspace -scheme SecuritySuiteExample -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO",
|
|
38
|
+
"bootstrap": "yarn example && yarn install && yarn example pods",
|
|
39
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build"
|
|
33
40
|
},
|
|
34
41
|
"keywords": [
|
|
35
42
|
"react-native",
|
|
36
43
|
"ios",
|
|
37
44
|
"android"
|
|
38
45
|
],
|
|
39
|
-
"repository":
|
|
40
|
-
|
|
41
|
-
"url": "https://github.com/mohamadnavabi/react-native-security-suite.git"
|
|
42
|
-
},
|
|
43
|
-
"author": "Mohammad Navabi <navabifar@gmail.com> (https://mohammadnavabi.ir)",
|
|
46
|
+
"repository": "https://github.com/mohamadnavabi/react-native-security-suite",
|
|
47
|
+
"author": "Mohammad Navabi <navabifar@gmail.com> (https://github.com/mohamadnavabi)",
|
|
44
48
|
"license": "MIT",
|
|
45
49
|
"bugs": {
|
|
46
50
|
"url": "https://github.com/mohamadnavabi/react-native-security-suite/issues"
|
|
@@ -50,30 +54,47 @@
|
|
|
50
54
|
"registry": "https://registry.npmjs.org/"
|
|
51
55
|
},
|
|
52
56
|
"devDependencies": {
|
|
53
|
-
"@commitlint/config-conventional": "^
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
56
|
-
"@
|
|
57
|
-
"@types/
|
|
58
|
-
"@types/
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
57
|
+
"@commitlint/config-conventional": "^17.0.2",
|
|
58
|
+
"@evilmartians/lefthook": "^1.2.2",
|
|
59
|
+
"@react-native-community/eslint-config": "^3.0.2",
|
|
60
|
+
"@release-it/conventional-changelog": "^5.0.0",
|
|
61
|
+
"@types/jest": "^28.1.2",
|
|
62
|
+
"@types/lodash": "^4.14.196",
|
|
63
|
+
"@types/react": "~17.0.21",
|
|
64
|
+
"@types/react-native": "0.70.0",
|
|
65
|
+
"commitlint": "^17.0.2",
|
|
66
|
+
"del-cli": "^5.0.0",
|
|
67
|
+
"eslint": "^8.4.1",
|
|
68
|
+
"eslint-config-prettier": "^8.5.0",
|
|
69
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
70
|
+
"jest": "^28.1.1",
|
|
65
71
|
"pod-install": "^0.1.0",
|
|
66
72
|
"prettier": "^2.0.5",
|
|
67
|
-
"react": "
|
|
68
|
-
"react-native": "0.
|
|
69
|
-
"react-native-builder-bob": "^0.
|
|
70
|
-
"release-it": "^
|
|
71
|
-
"
|
|
73
|
+
"react": "18.2.0",
|
|
74
|
+
"react-native": "0.72.3",
|
|
75
|
+
"react-native-builder-bob": "^0.20.0",
|
|
76
|
+
"release-it": "^15.0.0",
|
|
77
|
+
"turbo": "^1.10.7",
|
|
78
|
+
"typescript": "^5.0.2"
|
|
79
|
+
},
|
|
80
|
+
"resolutions": {
|
|
81
|
+
"@types/react": "17.0.21"
|
|
72
82
|
},
|
|
73
83
|
"peerDependencies": {
|
|
84
|
+
"@react-native-async-storage/async-storage": "*",
|
|
85
|
+
"lodash": "*",
|
|
74
86
|
"react": "*",
|
|
75
87
|
"react-native": "*"
|
|
76
88
|
},
|
|
89
|
+
"peerDependenciesMeta": {
|
|
90
|
+
"@react-native-async-storage/async-storage": {
|
|
91
|
+
"optional": false
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
"engines": {
|
|
95
|
+
"node": ">= 16.0.0"
|
|
96
|
+
},
|
|
97
|
+
"packageManager": "^yarn@1.22.15",
|
|
77
98
|
"jest": {
|
|
78
99
|
"preset": "react-native",
|
|
79
100
|
"modulePathIgnorePatterns": [
|
|
@@ -147,7 +168,7 @@
|
|
|
147
168
|
]
|
|
148
169
|
]
|
|
149
170
|
},
|
|
150
|
-
"
|
|
151
|
-
"
|
|
171
|
+
"dependencies": {
|
|
172
|
+
"@react-native-async-storage/async-storage": "^1.19.0"
|
|
152
173
|
}
|
|
153
174
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require "json"
|
|
2
2
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
|
4
5
|
|
|
5
6
|
Pod::Spec.new do |s|
|
|
6
7
|
s.name = "react-native-security-suite"
|
|
@@ -10,11 +11,26 @@ Pod::Spec.new do |s|
|
|
|
10
11
|
s.license = package["license"]
|
|
11
12
|
s.authors = package["author"]
|
|
12
13
|
|
|
13
|
-
s.platforms = { :ios => "
|
|
14
|
+
s.platforms = { :ios => "11.0" }
|
|
14
15
|
s.source = { :git => "https://github.com/mohamadnavabi/react-native-security-suite.git", :tag => "#{s.version}" }
|
|
15
16
|
|
|
16
17
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
17
|
-
|
|
18
|
+
|
|
18
19
|
s.dependency "React-Core"
|
|
19
20
|
s.dependency "IOSSecuritySuite"
|
|
21
|
+
|
|
22
|
+
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
23
|
+
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
|
|
24
|
+
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
|
|
25
|
+
s.pod_target_xcconfig = {
|
|
26
|
+
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
|
|
27
|
+
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
|
|
28
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
29
|
+
}
|
|
30
|
+
s.dependency "React-Codegen"
|
|
31
|
+
s.dependency "RCT-Folly"
|
|
32
|
+
s.dependency "RCTRequired"
|
|
33
|
+
s.dependency "RCTTypeSafety"
|
|
34
|
+
s.dependency "ReactCommon/turbomodule/core"
|
|
35
|
+
end
|
|
20
36
|
end
|