@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.
@@ -14,8 +14,23 @@
14
14
  * 2. Node — backed by the built-in `node:crypto` module (`webcrypto`, else
15
15
  * `randomFillSync`). This is what a Node runtime WITHOUT a global WebCrypto
16
16
  * (Node 18 script entrypoints, some embedded hosts) falls back to.
17
- * 3. React Native — `expo-crypto.getRandomBytes` (statically imported via the
18
- * per-platform `platform/crypto` module in `@oxy.so/protocol`).
17
+ * 3. React Native — `expo-crypto.getRandomBytes`, through the dependency-free
18
+ * `@oxy.so/protocol/random` entry.
19
+ *
20
+ * # Evaluation order — this module must import NOTHING that can capture the global
21
+ *
22
+ * `@noble/hashes` 1.x reads `globalThis.crypto` exactly once, when its
23
+ * `crypto.js` is evaluated, and `randomBytes` uses that captured binding for
24
+ * the lifetime of the app. ES imports are evaluated before the importing
25
+ * module's body, so every module this file imports runs BEFORE the shim below
26
+ * is installed. This file used to import `@oxy.so/protocol`'s root entry,
27
+ * which reaches `@noble/curves` → `@noble/hashes` through the envelope signer:
28
+ * on Hermes (no `globalThis.crypto` at startup) noble captured `undefined`
29
+ * before the shim existed, and every identity creation on Android failed with
30
+ * `crypto.getRandomValues must be defined`. Its imports are therefore limited
31
+ * to `buffer` and `@oxy.so/protocol/random`, both free of crypto libraries,
32
+ * and `index.ts` imports this file first. `__tests__/polyfillOrder.test.ts`
33
+ * guards both halves.
19
34
  *
20
35
  * Historically step (2) delegated to `@oxy.so/protocol`'s RN-only
21
36
  * `getRandomBytesRN`, which THROWS on Node — so any Node host lacking a global
@@ -26,7 +41,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
41
  exports.Buffer = void 0;
27
42
  const buffer_1 = require("buffer");
28
43
  Object.defineProperty(exports, "Buffer", { enumerable: true, get: function () { return buffer_1.Buffer; } });
29
- const protocol_1 = require("@oxy.so/protocol");
44
+ const random_1 = require("@oxy.so/protocol/random");
30
45
  const getGlobalObject = () => {
31
46
  if (typeof globalThis !== 'undefined')
32
47
  return globalThis;
@@ -111,12 +126,12 @@ const cryptoPolyfill = {
111
126
  // Node: back the CSPRNG with `node:crypto`. This is the path that matters on
112
127
  // Node runtimes shipping WITHOUT a global WebCrypto — where delegating to
113
128
  // the RN-only expo-crypto stub would throw.
114
- if ((0, protocol_1.isNodeJS)() && fillFromNodeCrypto(array)) {
129
+ if ((0, random_1.isNodeJS)() && fillFromNodeCrypto(array)) {
115
130
  return array;
116
131
  }
117
132
  // React Native (and any non-Node host without WebCrypto): synchronous
118
- // expo-crypto via @oxy.so/protocol's RN `platform/crypto` variant.
119
- const bytes = (0, protocol_1.getRandomBytesRN)(array.byteLength);
133
+ // expo-crypto via @oxy.so/protocol's RN `platform/random` variant.
134
+ const bytes = (0, random_1.getRandomBytesRN)(array.byteLength);
120
135
  const uint8View = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
121
136
  uint8View.set(bytes);
122
137
  return array;
package/dist/cjs/index.js CHANGED
@@ -24,7 +24,10 @@ exports.buildPaginationParams = exports.buildUrl = exports.buildSearchParams = e
24
24
  exports.registrableApex = exports.getAccountColor = exports.formatPublicKeyHandle = exports.getAccountFallbackHandle = exports.getAccountDisplayName = exports.createQuickAccount = exports.buildAccountsArray = exports.updateAvatarVisibility = exports.isDev = exports.consoleSink = exports.resetLoggerConfig = exports.getLoggerConfig = exports.configureLogger = exports.createLogger = exports.logger = exports.normalizeMultilineText = exports.normalizeInlineText = exports.validateAndSanitizeUserInput = exports.isValidObjectId = exports.sanitizeHTML = exports.sanitizeString = exports.isValidFileType = exports.isValidFileSize = exports.isValidDate = exports.isValidURL = exports.isValidUUID = exports.isValidObject = exports.isValidArray = exports.isRequiredBoolean = exports.isRequiredNumber = exports.isRequiredString = exports.DISPLAY_NAME_UNFLANKED_SEPARATOR_SOURCE = exports.DISPLAY_NAME_ORPHANED_MARK_SOURCE = exports.DISPLAY_NAME_DISALLOWED_SOURCE = exports.DISPLAY_NAME_ALLOWED_SCRIPTS = exports.isValidDisplayName = exports.isValidPassword = exports.isValidEmail = exports.DISPLAY_NAME_INVALID_MESSAGE = exports.MAX_DISPLAY_NAME_LENGTH = exports.PASSWORD_REGEX = exports.EMAIL_REGEX = exports.retryAsync = exports.validateRequiredFields = exports.parseHttpErrorBody = exports.isHttpRequestError = exports.handleHttpError = exports.createApiError = exports.ErrorCodes = exports.safeJsonParse = void 0;
25
25
  exports.decideSharedDeviceJoin = exports.createSharedMirroringAuthStateStore = exports.AUTH_STATE_STORAGE_KEY = exports.createMemoryAuthStateStore = exports.createNativeAuthStateStore = exports.createWebAuthStateStore = exports.createAccountDialogController = exports.AccountDialogController = exports.resolveAccountDelegationAccess = exports.canSwitchIntoAccount = exports.isSwitchTargetAccount = exports.showsPrincipalHeaders = exports.buildSwitcherRows = exports.resolveDeviceContext = exports.resolveActiveContext = exports.projectDevicePrincipals = exports.directoryHandle = exports.directoryDisplayName = exports.canActivateContext = exports.accountIdsOf = exports.activeUserOf = exports.activeSessionIdOf = exports.deviceStateToClientSessions = exports.createSessionClient = exports.createSessionClientHost = exports.SessionClient = exports.isAllowedDeviceJoinOrigin = exports.isOfficialWebOrigin = exports.isLoopbackOrigin = exports.consumeOAuthReturnPath = exports.persistOAuthReturnPath = exports.clearOAuthHandshake = exports.readOAuthHandshake = exports.persistOAuthHandshake = exports.canonicalizeOAuthRedirectUri = exports.normalizeOAuthRedirectUri = exports.OXY_OAUTH_RETURN_PATH_STORAGE_KEY = exports.OXY_OAUTH_REDIRECT_URI_STORAGE_KEY = exports.OXY_OAUTH_CODE_VERIFIER_STORAGE_KEY = exports.OXY_OAUTH_STATE_STORAGE_KEY = exports.OXY_AUTHORIZE_URL = exports.DEFAULT_OAUTH_SCOPE = exports.generatePkcePair = exports.generateOAuthState = exports.computeCodeChallenge = exports.buildOAuthAuthorizeUrl = exports.runColdBoot = exports.isOxyRpOrigin = exports.IDENTITY_WEB_ORIGIN = exports.CENTRAL_IDP_APEX = void 0;
26
26
  exports.packageInfo = exports.runSessionColdBoot = exports.OXY_INFERENCE_BASE_URL = exports.OxyInferenceProtocolError = exports.OxyInferenceError = exports.OxyInferenceClient = exports.TOKEN_REFRESH_LEAD_MS = exports.startTokenRefreshScheduler = exports.installAuthRefreshHandler = exports.createAuthRefreshHandler = exports.refreshDeviceSecretArm = exports.refreshPersistedSession = exports.AccountNotOnDeviceError = exports.establishIdentitySession = exports.resolveIdentityPin = exports.IDENTITY_PIN_STORAGE_KEY = exports.identityPinMatches = exports.createMemoryIdentityPinStore = exports.createNativeIdentityPinStore = exports.createWebIdentityPinStore = exports.readLocalDeviceCredential = exports.publishProvenDeviceCredential = exports.normalizeSharedDeviceSessionRead = exports.decideSharedDevicePublish = void 0;
27
- // Ensure crypto polyfills are loaded before anything else
27
+ // Ensure crypto polyfills are loaded before anything else. This MUST stay the
28
+ // first import: `@noble/hashes` captures `globalThis.crypto` when it is
29
+ // evaluated, so the shim has to exist before any module below reaches it (see
30
+ // the evaluation-order note in `./crypto/polyfill`).
28
31
  require("./crypto/polyfill");
29
32
  // ---------------------------------------------------------------------------
30
33
  // API client