diff --git a/lib/react_native/index.js b/lib/react_native/index.js index 6ae4867c7..773723b06 100644 --- a/lib/react_native/index.js +++ b/lib/react_native/index.js @@ -23,12 +23,21 @@ var buffer_1 = require("buffer"); var pubnub_common_1 = __importDefault(require("../core/pubnub-common")); var networking_1 = __importDefault(require("../networking")); var base64_codec_1 = require("../core/components/base64_codec"); +var text_encoding_utf_8_1 = require("text-encoding-utf-8"); +require("react-native-get-random-values"); var stringify_buffer_keys_1 = require("../core/components/stringify_buffer_keys"); var common_1 = __importDefault(require("../cbor/common")); var web_node_1 = require("../networking/modules/web-node"); var react_native_1 = require("../networking/modules/react_native"); var react_native_2 = __importDefault(require("../file/modules/react-native")); +var webCryptoModule_1 = require("../crypto/modules/WebCryptoModule/webCryptoModule"); global.Buffer = global.Buffer || buffer_1.Buffer; +Object.assign(global, { + TextEncoder: text_encoding_utf_8_1.TextEncoder, + TextDecoder: text_encoding_utf_8_1.TextDecoder, +}); +global.TextEncoder = text_encoding_utf_8_1.TextEncoder; +global.TextDecoder = text_encoding_utf_8_1.TextDecoder; var default_1 = /** @class */ (function (_super) { __extends(default_1, _super); function default_1(setup) { @@ -45,6 +54,15 @@ var default_1 = /** @class */ (function (_super) { }); setup.sdkFamily = 'ReactNative'; setup.ssl = true; + setup.initCryptoModule = function (cryptoConfiguration) { + return new webCryptoModule_1.CryptoModule({ + default: new webCryptoModule_1.LegacyCryptor({ + cipherKey: cryptoConfiguration.cipherKey, + useRandomIVs: cryptoConfiguration.useRandomIVs, + }), + cryptors: [new webCryptoModule_1.AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], + }); + }; _this = _super.call(this, setup) || this; return _this; } diff --git a/package.json b/package.json index bbe92c4e6..dd64ccb9f 100644 --- a/package.json +++ b/package.json @@ -52,8 +52,10 @@ "cbor-js": "^0.1.0", "cbor-sync": "^1.0.4", "lil-uuid": "^0.1.1", + "proxy-agent": "^6.3.0", + "react-native-get-random-values": "^1.10.0", "superagent": "^8.1.2", - "proxy-agent": "^6.3.0" + "text-encoding-utf-8": "^1.0.2" }, "devDependencies": { "@cucumber/cucumber": "^7.3.1", @@ -102,4 +104,4 @@ "engine": { "node": ">=0.8" } -} \ No newline at end of file +} diff --git a/src/react_native/index.js b/src/react_native/index.js index 921477ec3..39469f407 100644 --- a/src/react_native/index.js +++ b/src/react_native/index.js @@ -3,6 +3,8 @@ import { Buffer } from 'buffer'; import PubNubCore from '../core/pubnub-common'; import Networking from '../networking'; import { decode } from '../core/components/base64_codec'; +import { TextDecoder, TextEncoder } from 'text-encoding-utf-8'; +import 'react-native-get-random-values'; import { stringifyBufferKeys } from '../core/components/stringify_buffer_keys'; import Cbor from '../cbor/common'; import { del, get, post, patch } from '../networking/modules/web-node'; @@ -10,9 +12,18 @@ import { getfile, postfile } from '../networking/modules/react_native'; import PubNubFile from '../file/modules/react-native'; import { stringifyBufferKeys } from '../web'; +import { CryptoModule, LegacyCryptor, AesCbcCryptor } from '../crypto/modules/WebCryptoModule/webCryptoModule'; global.Buffer = global.Buffer || Buffer; + +Object.assign(global, { + TextEncoder: TextEncoder, + TextDecoder: TextDecoder, +}); +global.TextEncoder = TextEncoder; +global.TextDecoder = TextDecoder; + export default class extends PubNubCore { constructor(setup) { setup.cbor = new Cbor((arrayBuffer) => stringifyBufferKeys(CborReader.decode(arrayBuffer)), decode); @@ -29,7 +40,15 @@ export default class extends PubNubCore { }); setup.sdkFamily = 'ReactNative'; setup.ssl = true; - + setup.initCryptoModule = (cryptoConfiguration) => { + return new CryptoModule({ + default: new LegacyCryptor({ + cipherKey: cryptoConfiguration.cipherKey, + useRandomIVs: cryptoConfiguration.useRandomIVs, + }), + cryptors: [new AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], + }); + }; super(setup); } }