@oxy.so/core 1.8.0 → 1.8.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.
@@ -13,8 +13,23 @@
13
13
  * 2. Node — backed by the built-in `node:crypto` module (`webcrypto`, else
14
14
  * `randomFillSync`). This is what a Node runtime WITHOUT a global WebCrypto
15
15
  * (Node 18 script entrypoints, some embedded hosts) falls back to.
16
- * 3. React Native — `expo-crypto.getRandomBytes` (statically imported via the
17
- * per-platform `platform/crypto` module in `@oxy.so/protocol`).
16
+ * 3. React Native — `expo-crypto.getRandomBytes`, through the dependency-free
17
+ * `@oxy.so/protocol/random` entry.
18
+ *
19
+ * # Evaluation order — this module must import NOTHING that can capture the global
20
+ *
21
+ * `@noble/hashes` 1.x reads `globalThis.crypto` exactly once, when its
22
+ * `crypto.js` is evaluated, and `randomBytes` uses that captured binding for
23
+ * the lifetime of the app. ES imports are evaluated before the importing
24
+ * module's body, so every module this file imports runs BEFORE the shim below
25
+ * is installed. This file used to import `@oxy.so/protocol`'s root entry,
26
+ * which reaches `@noble/curves` → `@noble/hashes` through the envelope signer:
27
+ * on Hermes (no `globalThis.crypto` at startup) noble captured `undefined`
28
+ * before the shim existed, and every identity creation on Android failed with
29
+ * `crypto.getRandomValues must be defined`. Its imports are therefore limited
30
+ * to `buffer` and `@oxy.so/protocol/random`, both free of crypto libraries,
31
+ * and `index.ts` imports this file first. `__tests__/polyfillOrder.test.ts`
32
+ * guards both halves.
18
33
  *
19
34
  * Historically step (2) delegated to `@oxy.so/protocol`'s RN-only
20
35
  * `getRandomBytesRN`, which THROWS on Node — so any Node host lacking a global
@@ -23,7 +38,7 @@
23
38
  */
24
39
  import _cjs_buffer from 'buffer';
25
40
  const { Buffer } = _cjs_buffer;
26
- import { getRandomBytesRN, isNodeJS } from '@oxy.so/protocol';
41
+ import { getRandomBytesRN, isNodeJS } from '@oxy.so/protocol/random';
27
42
  const getGlobalObject = () => {
28
43
  if (typeof globalThis !== 'undefined')
29
44
  return globalThis;
@@ -112,7 +127,7 @@ const cryptoPolyfill = {
112
127
  return array;
113
128
  }
114
129
  // React Native (and any non-Node host without WebCrypto): synchronous
115
- // expo-crypto via @oxy.so/protocol's RN `platform/crypto` variant.
130
+ // expo-crypto via @oxy.so/protocol's RN `platform/random` variant.
116
131
  const bytes = getRandomBytesRN(array.byteLength);
117
132
  const uint8View = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
118
133
  uint8View.set(bytes);
package/dist/esm/index.js CHANGED
@@ -16,7 +16,10 @@
16
16
  * Every export below is NOMINAL — no `export *`, no barrels, no compat shims.
17
17
  * If a symbol does not appear here, it is NOT part of the public API.
18
18
  */
19
- // Ensure crypto polyfills are loaded before anything else
19
+ // Ensure crypto polyfills are loaded before anything else. This MUST stay the
20
+ // first import: `@noble/hashes` captures `globalThis.crypto` when it is
21
+ // evaluated, so the shim has to exist before any module below reaches it (see
22
+ // the evaluation-order note in `./crypto/polyfill`).
20
23
  import './crypto/polyfill.js';
21
24
  // ---------------------------------------------------------------------------
22
25
  // API client