apps-sdk 1.0.11 → 1.0.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apps-sdk",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -10,8 +10,8 @@
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
12
  "@react-native-async-storage/async-storage": "^1.21.0",
13
+ "crypto-es": "^2.1.0",
13
14
  "expo-constants": "^15.4.5",
14
- "expo-crypto": "^12.8.0",
15
15
  "expo-device": "^5.9.3",
16
16
  "expo-localization": "^14.8.3",
17
17
  "expo-notifications": "^0.23.0",
@@ -1,7 +1,7 @@
1
1
  import * as config from '../../config';
2
2
  import { default as storage } from './Storage';
3
3
  import Session from './Session';
4
- import * as Crypto from 'expo-crypto';
4
+ import CryptoES from "crypto-es";
5
5
 
6
6
  class Networking {
7
7
  constructor() {
@@ -95,12 +95,9 @@ class Networking {
95
95
 
96
96
  if (encrypt) {
97
97
  const secretKey = this.ENCRYPT_KEY;
98
- const encryptedData = await Crypto.digestStringAsync(
99
- Crypto.CryptoDigestAlgorithm.SHA256,
100
- JSON.stringify(data),
101
- { encoding: Crypto.CryptoEncoding.BASE64 }
102
- );
103
- data = { data: encryptedData };
98
+ const iv = CryptoES.lib.WordArray.random(128/8);
99
+ const encryptedData = CryptoES.AES.encrypt(JSON.stringify(data), secretKey, { iv: iv }).toString();
100
+ data = { data: iv.toString(CryptoES.enc.Base64) + '$' + encryptedData };
104
101
  headers['Content-Type'] = 'application/octet-stream';
105
102
  }
106
103
 
@@ -110,12 +107,33 @@ class Networking {
110
107
  headers: headers,
111
108
  body: JSON.stringify(data)
112
109
  });
113
- return await response.json();
110
+ if (encrypt) {
111
+ return await this.decryptData(await response.json());
112
+ } else {
113
+ return await response.json();
114
+ }
114
115
  } catch (error) {
115
116
  console.log(error)
116
117
  }
117
118
  }
118
119
 
120
+ decryptData = async (data) => {
121
+ if (data && data.data) {
122
+ try {
123
+ const decryptedData = await Crypto.digestStringAsync(
124
+ Crypto.CryptoDigestAlgorithm.SHA256,
125
+ data.data,
126
+ { encoding: Crypto.CryptoEncoding.BASE64 }
127
+ );
128
+ return JSON.parse(decryptedData);
129
+ } catch (error) {
130
+ console.error(error);
131
+ return null;
132
+ }
133
+ }
134
+ return data;
135
+ }
136
+
119
137
  setEndpoints(domains) {
120
138
  // domains.events && (config.ENDPOINTS.TRACKING = domains.events);
121
139
  // domains.audiences && (config.ENDPOINTS.SET_ATTRIBUTION = domains.audiences);