@powersync/react-native 0.0.0-dev-20240722092004 → 0.0.0-dev-20240722121738
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/dist/index.js +87 -1
- package/package.json +9 -8
package/dist/index.js
CHANGED
|
@@ -2487,6 +2487,92 @@ ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes) {
|
|
|
2487
2487
|
}
|
|
2488
2488
|
} (reactNativeBuffer));
|
|
2489
2489
|
|
|
2490
|
+
// This file is based on code from the react-native-get-random-values repository
|
|
2491
|
+
// Source: https://github.com/LinusU/react-native-get-random-values/blob/modern/index.js
|
|
2492
|
+
// Modifications:
|
|
2493
|
+
// - Instead of applying to all global references of crypto, provide a ponyfill export.
|
|
2494
|
+
|
|
2495
|
+
const base64Decode = require('fast-base64-decode');
|
|
2496
|
+
const { NativeModules } = require('react-native');
|
|
2497
|
+
|
|
2498
|
+
class TypeMismatchError extends Error {}
|
|
2499
|
+
class QuotaExceededError extends Error {}
|
|
2500
|
+
|
|
2501
|
+
let warned = false;
|
|
2502
|
+
function insecureRandomValues (array) {
|
|
2503
|
+
if (!warned) {
|
|
2504
|
+
console.warn('Using an insecure random number generator, this should only happen when running in a debugger without support for crypto.getRandomValues');
|
|
2505
|
+
warned = true;
|
|
2506
|
+
}
|
|
2507
|
+
|
|
2508
|
+
for (let i = 0, r; i < array.length; i++) {
|
|
2509
|
+
if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
|
|
2510
|
+
array[i] = (r >>> ((i & 0x03) << 3)) & 0xff;
|
|
2511
|
+
}
|
|
2512
|
+
|
|
2513
|
+
return array
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2516
|
+
/**
|
|
2517
|
+
* @param {number} byteLength
|
|
2518
|
+
* @returns {string}
|
|
2519
|
+
*/
|
|
2520
|
+
function getRandomBase64 (byteLength) {
|
|
2521
|
+
if (NativeModules.RNGetRandomValues) {
|
|
2522
|
+
return NativeModules.RNGetRandomValues.getRandomBase64(byteLength)
|
|
2523
|
+
} else if (NativeModules.ExpoRandom) {
|
|
2524
|
+
// Expo SDK 41-44
|
|
2525
|
+
return NativeModules.ExpoRandom.getRandomBase64String(byteLength)
|
|
2526
|
+
} else if (global.ExpoModules) {
|
|
2527
|
+
// Expo SDK 45+
|
|
2528
|
+
return global.ExpoModules.ExpoRandom.getRandomBase64String(byteLength);
|
|
2529
|
+
} else {
|
|
2530
|
+
throw new Error('Native module not found')
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2534
|
+
/**
|
|
2535
|
+
* @param {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Uint8ClampedArray} array
|
|
2536
|
+
*/
|
|
2537
|
+
function getRandomValues (array) {
|
|
2538
|
+
if (!(array instanceof Int8Array || array instanceof Uint8Array || array instanceof Int16Array || array instanceof Uint16Array || array instanceof Int32Array || array instanceof Uint32Array || array instanceof Uint8ClampedArray)) {
|
|
2539
|
+
throw new TypeMismatchError('Expected an integer array')
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2542
|
+
if (array.byteLength > 65536) {
|
|
2543
|
+
throw new QuotaExceededError('Can only request a maximum of 65536 bytes')
|
|
2544
|
+
}
|
|
2545
|
+
|
|
2546
|
+
// Expo SDK 48+
|
|
2547
|
+
if (global.expo && global.expo.modules && global.expo.modules.ExpoCrypto && global.expo.modules.ExpoCrypto.getRandomValues) {
|
|
2548
|
+
// ExpoCrypto.getRandomValues doesn't return the array
|
|
2549
|
+
global.expo.modules.ExpoCrypto.getRandomValues(array);
|
|
2550
|
+
return array
|
|
2551
|
+
}
|
|
2552
|
+
|
|
2553
|
+
// Calling getRandomBase64 in remote debugging mode leads to the error
|
|
2554
|
+
// "Calling synchronous methods on native modules is not supported in Chrome".
|
|
2555
|
+
// So in that specific case we fall back to just using Math.random().
|
|
2556
|
+
if (isRemoteDebuggingInChrome()) {
|
|
2557
|
+
return insecureRandomValues(array)
|
|
2558
|
+
}
|
|
2559
|
+
|
|
2560
|
+
base64Decode(getRandomBase64(array.byteLength), new Uint8Array(array.buffer, array.byteOffset, array.byteLength));
|
|
2561
|
+
|
|
2562
|
+
return array
|
|
2563
|
+
}
|
|
2564
|
+
|
|
2565
|
+
function isRemoteDebuggingInChrome () {
|
|
2566
|
+
// Remote debugging in Chrome is not supported in bridgeless
|
|
2567
|
+
if ('RN$Bridgeless' in global && RN$Bridgeless === true) {
|
|
2568
|
+
return false
|
|
2569
|
+
}
|
|
2570
|
+
|
|
2571
|
+
return __DEV__ && typeof global.nativeCallSyncHook === 'undefined'
|
|
2572
|
+
}
|
|
2573
|
+
|
|
2574
|
+
var crypto = { getRandomValues };
|
|
2575
|
+
|
|
2490
2576
|
var encoding$3 = {exports: {}};
|
|
2491
2577
|
|
|
2492
2578
|
var encodingIndexes$1 = {exports: {}};
|
|
@@ -6296,7 +6382,7 @@ function webMathRandomBytes(byteLength) {
|
|
|
6296
6382
|
return webByteUtils.fromNumberArray(Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256)));
|
|
6297
6383
|
}
|
|
6298
6384
|
const webRandomBytes = (() => {
|
|
6299
|
-
|
|
6385
|
+
// removed crypto destructuring assingment from globalThis
|
|
6300
6386
|
if (crypto != null && typeof crypto.getRandomValues === 'function') {
|
|
6301
6387
|
return (byteLength) => {
|
|
6302
6388
|
return crypto.getRandomValues(webByteUtils.allocate(byteLength));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/react-native",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20240722121738",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -26,16 +26,13 @@
|
|
|
26
26
|
"@journeyapps/react-native-quick-sqlite": "^1.1.8",
|
|
27
27
|
"react": "*",
|
|
28
28
|
"react-native": "*",
|
|
29
|
-
"@powersync/common": "^0.0.0-dev-
|
|
29
|
+
"@powersync/common": "^0.0.0-dev-20240722121738"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@powersync/common": "0.0.0-dev-
|
|
33
|
-
"@powersync/react": "0.0.0-dev-
|
|
32
|
+
"@powersync/common": "0.0.0-dev-20240722121738",
|
|
33
|
+
"@powersync/react": "0.0.0-dev-20240722121738"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"async-lock": "^1.4.0",
|
|
37
|
-
"bson": "^6.6.0",
|
|
38
|
-
"react-native-fetch-api": "^3.0.0",
|
|
39
36
|
"@craftzdog/react-native-buffer": "^6.0.5",
|
|
40
37
|
"@journeyapps/react-native-quick-sqlite": "^1.1.8",
|
|
41
38
|
"@rollup/plugin-alias": "^5.1.0",
|
|
@@ -43,10 +40,14 @@
|
|
|
43
40
|
"@rollup/plugin-inject": "^5.0.5",
|
|
44
41
|
"@rollup/plugin-json": "^6.1.0",
|
|
45
42
|
"@rollup/plugin-node-resolve": "15.2.3",
|
|
43
|
+
"@rollup/plugin-replace": "^5.0.7",
|
|
46
44
|
"@types/async-lock": "^1.4.0",
|
|
47
|
-
"
|
|
45
|
+
"async-lock": "^1.4.0",
|
|
46
|
+
"bson": "^6.6.0",
|
|
47
|
+
"fast-base64-decode": "^1.0.0",
|
|
48
48
|
"react": "18.2.0",
|
|
49
49
|
"react-native": "0.72.4",
|
|
50
|
+
"react-native-fetch-api": "^3.0.0",
|
|
50
51
|
"rollup": "4.14.3",
|
|
51
52
|
"text-encoding": "^0.7.0",
|
|
52
53
|
"typescript": "^5.5.3",
|