@layers/amba-react-native 4.3.0 → 4.3.1
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/README.md +2 -0
- package/dist/index.cjs +56 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +56 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -16,6 +16,8 @@ npm install @layers/amba-react-native @react-native-async-storage/async-storage
|
|
|
16
16
|
npx expo install @layers/amba-react-native @react-native-async-storage/async-storage
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
The SDK installs a secure `crypto.getRandomValues` for you through `react-native-get-random-values`, one of its dependencies; no import is needed. Bare React Native (and Expo SDK 50 to 53 builds) link only the native modules listed in your app's `package.json`, so add it there too (`npm install react-native-get-random-values`, then `npx pod-install`). Expo Go and Expo SDK 54+ builds need nothing.
|
|
20
|
+
|
|
19
21
|
## Configure + first call
|
|
20
22
|
|
|
21
23
|
```tsx
|
package/dist/index.cjs
CHANGED
|
@@ -504,17 +504,71 @@ function mapHttpError(response, rawBody, isJson) {
|
|
|
504
504
|
}
|
|
505
505
|
}
|
|
506
506
|
|
|
507
|
+
//#endregion
|
|
508
|
+
//#region src/secure-random.ts
|
|
509
|
+
/**
|
|
510
|
+
* The production loader. The `require` call must stay a string literal; see
|
|
511
|
+
* the module comment.
|
|
512
|
+
*/
|
|
513
|
+
function loadGetRandomValuesPolyfill() {
|
|
514
|
+
require("react-native-get-random-values");
|
|
515
|
+
}
|
|
516
|
+
function globalObject() {
|
|
517
|
+
return globalThis;
|
|
518
|
+
}
|
|
519
|
+
function currentGetRandomValues() {
|
|
520
|
+
const crypto = globalObject().crypto;
|
|
521
|
+
const grv = crypto?.getRandomValues;
|
|
522
|
+
return crypto && typeof grv === "function" ? grv : null;
|
|
523
|
+
}
|
|
524
|
+
function probe(grv) {
|
|
525
|
+
try {
|
|
526
|
+
const crypto = globalObject().crypto;
|
|
527
|
+
return grv.call(crypto, new Uint8Array(1)) instanceof Uint8Array;
|
|
528
|
+
} catch {
|
|
529
|
+
return false;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
let attempted = false;
|
|
533
|
+
/**
|
|
534
|
+
* Makes `globalThis.crypto.getRandomValues` available when the runtime can
|
|
535
|
+
* supply a secure one. Returns whether it is available afterwards.
|
|
536
|
+
*
|
|
537
|
+
* The polyfill is loaded at most once per JS runtime. A later call still
|
|
538
|
+
* reports true when the app installs a secure implementation itself.
|
|
539
|
+
*/
|
|
540
|
+
function ensureSecureRandom(load = loadGetRandomValuesPolyfill) {
|
|
541
|
+
if (currentGetRandomValues()) return true;
|
|
542
|
+
if (attempted) return false;
|
|
543
|
+
attempted = true;
|
|
544
|
+
const g = globalObject();
|
|
545
|
+
const hadCrypto = Object.prototype.hasOwnProperty.call(g, "crypto");
|
|
546
|
+
const priorCrypto = g.crypto;
|
|
547
|
+
try {
|
|
548
|
+
load();
|
|
549
|
+
} catch {}
|
|
550
|
+
const installed = currentGetRandomValues();
|
|
551
|
+
if (installed && probe(installed)) return true;
|
|
552
|
+
try {
|
|
553
|
+
if (!hadCrypto) delete g.crypto;
|
|
554
|
+
else if (g.crypto === priorCrypto && priorCrypto) delete priorCrypto.getRandomValues;
|
|
555
|
+
else g.crypto = priorCrypto;
|
|
556
|
+
} catch {}
|
|
557
|
+
return false;
|
|
558
|
+
}
|
|
559
|
+
|
|
507
560
|
//#endregion
|
|
508
561
|
//#region src/uuid.ts
|
|
509
562
|
/** Thrown when the runtime has no `crypto.getRandomValues`. */
|
|
510
563
|
var SecureRandomUnavailableError = class extends Error {
|
|
511
564
|
code = "SECURE_RANDOM_UNAVAILABLE";
|
|
512
565
|
constructor() {
|
|
513
|
-
super("Amba needs crypto.getRandomValues to generate identifiers, and this runtime does not provide it.
|
|
566
|
+
super("Amba needs crypto.getRandomValues to generate identifiers, and this runtime does not provide it. The SDK loads react-native-get-random-values for you, and its native module is missing from this build. Add the package to your app's package.json so the native module is linked (Expo: `npx expo install react-native-get-random-values`; bare React Native: `npm install react-native-get-random-values`, then `npx pod-install`) and rebuild the native app. No import is needed.");
|
|
514
567
|
this.name = "SecureRandomUnavailableError";
|
|
515
568
|
}
|
|
516
569
|
};
|
|
517
570
|
function secureGetRandomValues() {
|
|
571
|
+
ensureSecureRandom();
|
|
518
572
|
const crypto = globalThis.crypto;
|
|
519
573
|
const grv = crypto?.getRandomValues;
|
|
520
574
|
if (!crypto || typeof grv !== "function") throw new SecureRandomUnavailableError();
|
|
@@ -3063,7 +3117,7 @@ function delay(ms) {
|
|
|
3063
3117
|
//#endregion
|
|
3064
3118
|
//#region src/index.ts
|
|
3065
3119
|
/** SDK semver — burned in at build time. Bump alongside package.json. */
|
|
3066
|
-
const SDK_VERSION = "4.3.
|
|
3120
|
+
const SDK_VERSION = "4.3.1";
|
|
3067
3121
|
/** The most events held at once; the oldest goes first past it. */
|
|
3068
3122
|
const MAX_HELD_EVENTS = 500;
|
|
3069
3123
|
/**
|