@oxyhq/core 1.11.12 → 1.11.13

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.
Files changed (125) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/CrossDomainAuth.js +3 -1
  3. package/dist/cjs/HttpService.js +214 -33
  4. package/dist/cjs/OxyServices.base.js +9 -0
  5. package/dist/cjs/OxyServices.js +8 -3
  6. package/dist/cjs/crypto/index.js +3 -1
  7. package/dist/cjs/crypto/keyManager.js +476 -172
  8. package/dist/cjs/crypto/polyfill.js +14 -65
  9. package/dist/cjs/crypto/recoveryPhrase.js +30 -11
  10. package/dist/cjs/crypto/signatureService.js +25 -60
  11. package/dist/cjs/i18n/locales/en-US.json +46 -1
  12. package/dist/cjs/i18n/locales/es-ES.json +46 -1
  13. package/dist/cjs/i18n/locales/locales/en-US.json +46 -1
  14. package/dist/cjs/i18n/locales/locales/es-ES.json +46 -1
  15. package/dist/cjs/index.js +7 -2
  16. package/dist/cjs/mixins/OxyServices.assets.js +9 -4
  17. package/dist/cjs/mixins/OxyServices.auth.js +27 -0
  18. package/dist/cjs/mixins/OxyServices.contacts.js +50 -0
  19. package/dist/cjs/mixins/OxyServices.features.js +0 -11
  20. package/dist/cjs/mixins/OxyServices.fedcm.js +4 -3
  21. package/dist/cjs/mixins/OxyServices.language.js +5 -36
  22. package/dist/cjs/mixins/OxyServices.redirect.js +6 -2
  23. package/dist/cjs/mixins/OxyServices.security.js +13 -2
  24. package/dist/cjs/mixins/OxyServices.user.js +59 -38
  25. package/dist/cjs/mixins/OxyServices.utility.js +19 -43
  26. package/dist/cjs/mixins/index.js +11 -3
  27. package/dist/cjs/utils/accountUtils.js +71 -2
  28. package/dist/cjs/utils/deviceManager.js +5 -36
  29. package/dist/cjs/utils/platformCrypto.js +165 -0
  30. package/dist/cjs/utils/platformCrypto.native.js +123 -0
  31. package/dist/esm/.tsbuildinfo +1 -1
  32. package/dist/esm/CrossDomainAuth.js +3 -1
  33. package/dist/esm/HttpService.js +215 -34
  34. package/dist/esm/OxyServices.base.js +9 -0
  35. package/dist/esm/OxyServices.js +8 -3
  36. package/dist/esm/crypto/index.js +1 -1
  37. package/dist/esm/crypto/keyManager.js +473 -138
  38. package/dist/esm/crypto/polyfill.js +14 -32
  39. package/dist/esm/crypto/recoveryPhrase.js +30 -11
  40. package/dist/esm/crypto/signatureService.js +25 -27
  41. package/dist/esm/i18n/locales/en-US.json +46 -1
  42. package/dist/esm/i18n/locales/es-ES.json +46 -1
  43. package/dist/esm/i18n/locales/locales/en-US.json +46 -1
  44. package/dist/esm/i18n/locales/locales/es-ES.json +46 -1
  45. package/dist/esm/index.js +2 -2
  46. package/dist/esm/mixins/OxyServices.assets.js +9 -4
  47. package/dist/esm/mixins/OxyServices.auth.js +27 -0
  48. package/dist/esm/mixins/OxyServices.contacts.js +47 -0
  49. package/dist/esm/mixins/OxyServices.features.js +0 -11
  50. package/dist/esm/mixins/OxyServices.fedcm.js +4 -3
  51. package/dist/esm/mixins/OxyServices.language.js +5 -3
  52. package/dist/esm/mixins/OxyServices.redirect.js +6 -2
  53. package/dist/esm/mixins/OxyServices.security.js +13 -2
  54. package/dist/esm/mixins/OxyServices.user.js +59 -38
  55. package/dist/esm/mixins/OxyServices.utility.js +19 -10
  56. package/dist/esm/mixins/index.js +11 -3
  57. package/dist/esm/utils/accountUtils.js +67 -1
  58. package/dist/esm/utils/deviceManager.js +5 -3
  59. package/dist/esm/utils/platformCrypto.js +125 -0
  60. package/dist/esm/utils/platformCrypto.native.js +80 -0
  61. package/dist/types/.tsbuildinfo +1 -1
  62. package/dist/types/HttpService.d.ts +47 -3
  63. package/dist/types/OxyServices.base.d.ts +7 -0
  64. package/dist/types/OxyServices.d.ts +36 -3
  65. package/dist/types/crypto/index.d.ts +1 -1
  66. package/dist/types/crypto/keyManager.d.ts +110 -9
  67. package/dist/types/crypto/polyfill.d.ts +3 -1
  68. package/dist/types/crypto/recoveryPhrase.d.ts +31 -7
  69. package/dist/types/crypto/signatureService.d.ts +4 -0
  70. package/dist/types/index.d.ts +4 -3
  71. package/dist/types/mixins/OxyServices.analytics.d.ts +1 -0
  72. package/dist/types/mixins/OxyServices.assets.d.ts +6 -10
  73. package/dist/types/mixins/OxyServices.auth.d.ts +16 -0
  74. package/dist/types/mixins/OxyServices.contacts.d.ts +99 -0
  75. package/dist/types/mixins/OxyServices.developer.d.ts +1 -0
  76. package/dist/types/mixins/OxyServices.devices.d.ts +1 -0
  77. package/dist/types/mixins/OxyServices.features.d.ts +2 -7
  78. package/dist/types/mixins/OxyServices.fedcm.d.ts +1 -0
  79. package/dist/types/mixins/OxyServices.karma.d.ts +1 -0
  80. package/dist/types/mixins/OxyServices.language.d.ts +1 -0
  81. package/dist/types/mixins/OxyServices.location.d.ts +1 -0
  82. package/dist/types/mixins/OxyServices.managedAccounts.d.ts +1 -0
  83. package/dist/types/mixins/OxyServices.payment.d.ts +1 -0
  84. package/dist/types/mixins/OxyServices.popup.d.ts +1 -0
  85. package/dist/types/mixins/OxyServices.privacy.d.ts +1 -0
  86. package/dist/types/mixins/OxyServices.redirect.d.ts +1 -0
  87. package/dist/types/mixins/OxyServices.security.d.ts +1 -0
  88. package/dist/types/mixins/OxyServices.topics.d.ts +1 -0
  89. package/dist/types/mixins/OxyServices.user.d.ts +28 -11
  90. package/dist/types/mixins/OxyServices.utility.d.ts +1 -0
  91. package/dist/types/mixins/index.d.ts +52 -4
  92. package/dist/types/models/interfaces.d.ts +62 -3
  93. package/dist/types/utils/accountUtils.d.ts +41 -1
  94. package/dist/types/utils/platformCrypto.d.ts +87 -0
  95. package/dist/types/utils/platformCrypto.native.d.ts +54 -0
  96. package/package.json +28 -1
  97. package/src/CrossDomainAuth.ts +12 -10
  98. package/src/HttpService.ts +251 -40
  99. package/src/OxyServices.base.ts +10 -0
  100. package/src/OxyServices.ts +9 -4
  101. package/src/crypto/__tests__/keyManager.test.ts +336 -0
  102. package/src/crypto/index.ts +6 -1
  103. package/src/crypto/keyManager.ts +529 -151
  104. package/src/crypto/polyfill.ts +14 -34
  105. package/src/crypto/recoveryPhrase.ts +56 -17
  106. package/src/crypto/signatureService.ts +25 -30
  107. package/src/i18n/locales/en-US.json +46 -1
  108. package/src/i18n/locales/es-ES.json +46 -1
  109. package/src/index.ts +16 -3
  110. package/src/mixins/OxyServices.assets.ts +15 -11
  111. package/src/mixins/OxyServices.auth.ts +28 -0
  112. package/src/mixins/OxyServices.contacts.ts +73 -0
  113. package/src/mixins/OxyServices.features.ts +2 -12
  114. package/src/mixins/OxyServices.fedcm.ts +4 -3
  115. package/src/mixins/OxyServices.language.ts +6 -4
  116. package/src/mixins/OxyServices.redirect.ts +6 -2
  117. package/src/mixins/OxyServices.security.ts +18 -8
  118. package/src/mixins/OxyServices.user.ts +72 -49
  119. package/src/mixins/OxyServices.utility.ts +19 -10
  120. package/src/mixins/index.ts +58 -7
  121. package/src/models/interfaces.ts +65 -3
  122. package/src/utils/accountUtils.ts +82 -2
  123. package/src/utils/deviceManager.ts +7 -4
  124. package/src/utils/platformCrypto.native.ts +101 -0
  125. package/src/utils/platformCrypto.ts +145 -0
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Platform Crypto / Storage — Default Variant (Node.js, Browser, generic bundlers)
3
+ *
4
+ * Provides lazy access to platform-specific crypto and storage modules.
5
+ *
6
+ * # Variants
7
+ *
8
+ * This module ships in two physical variants on disk, selected per consumer
9
+ * by the bundler / runtime:
10
+ *
11
+ * - `platformCrypto.js` — this file. Used by Node.js, Vite, webpack,
12
+ * Rollup, esbuild, and anything that does
13
+ * not match Metro's `*.native.js`
14
+ * source-extension preference.
15
+ * - `platformCrypto.native.js` — sibling file. Picked up automatically by
16
+ * Metro's resolver (which prefers
17
+ * `*.<platform>.js` and `*.native.js` over
18
+ * plain `*.js` when `preferNativePlatform`
19
+ * is true — Expo sets this for all non-web
20
+ * builds).
21
+ *
22
+ * The `package.json#exports` map also declares a `"react-native"` condition
23
+ * pointing at the same `dist/esm/index.js` entry — that entry transitively
24
+ * imports `./platformCrypto`, and Metro's per-file source-extension lookup
25
+ * substitutes the `.native.js` sibling automatically inside `dist/`. This
26
+ * means consumers never have to add resolver shims; Metro Just Works.
27
+ *
28
+ * Both variants expose the EXACT same public API; importers don't need to know
29
+ * which one they got. The variant difference is purely about which underlying
30
+ * native modules each one references:
31
+ *
32
+ * ┌──────────────────┬───────────────────────┬───────────────────────────────┐
33
+ * │ Function │ Default variant │ React Native variant │
34
+ * ├──────────────────┼───────────────────────┼───────────────────────────────┤
35
+ * │ loadNodeCrypto │ `await import('crypto')` (Node built-in) │
36
+ * │ │ │ throws — Node crypto is not │
37
+ * │ │ │ available on Hermes/RN │
38
+ * ├──────────────────┼───────────────────────┼───────────────────────────────┤
39
+ * │ loadExpoCrypto │ throws — expo-crypto │ static `import 'expo-crypto'` │
40
+ * │ │ is not part of a │ │
41
+ * │ │ Node/Vite bundle │ │
42
+ * ├──────────────────┼───────────────────────┼───────────────────────────────┤
43
+ * │ loadSecureStore │ throws (web/Node have │ static `import 'expo-secure-` │
44
+ * │ │ their own storage) │ store' │
45
+ * ├──────────────────┼───────────────────────┼───────────────────────────────┤
46
+ * │ loadAsyncStorage │ throws (web/Node have │ static `import '@react- │
47
+ * │ │ their own storage) │ native-async-storage/...' │
48
+ * ├──────────────────┼───────────────────────┼───────────────────────────────┤
49
+ * │ getRandomBytesRN │ throws (RN-only) │ direct call into expo-crypto │
50
+ * └──────────────────┴───────────────────────┴───────────────────────────────┘
51
+ *
52
+ * Crucially, the default variant references ONLY Node's `'crypto'`. It never
53
+ * mentions `expo-*` or `@react-native-async-storage/*` — so Vite, webpack,
54
+ * esbuild, Rollup, and Node itself can bundle / require it without ever
55
+ * attempting to resolve those RN-only packages.
56
+ *
57
+ * The React Native variant references ONLY the RN packages. It never
58
+ * mentions `'crypto'` — so Metro and Hermes have nothing to choke on.
59
+ *
60
+ * # Why not a single file with dynamic import?
61
+ *
62
+ * A previous iteration used a "bundler-opaque" `new Function('s', 'return
63
+ * import(s)')` trick so a single file could service every platform. It
64
+ * bundled cleanly on Metro but Hermes refused to PARSE the resulting
65
+ * `import()` expression inside a Function-constructor body
66
+ * (`SyntaxError: Invalid expression encountered` at the `(` of `import(`).
67
+ * The platform-extension split is the only approach that lets each runtime
68
+ * see a file containing only specifiers it can understand — no tricks, no
69
+ * runtime parsing risks.
70
+ */
71
+ import { isReactNative } from './platform.js';
72
+ // ---------------------------------------------------------------------------
73
+ // Node `crypto` — Node built-in
74
+ //
75
+ // `await import('crypto')` here is a real, static-from-tsc's-perspective
76
+ // dynamic import. Node ESM, Vite, webpack, and esbuild all resolve it fine.
77
+ // Metro never sees this file because the `.react-native.js` sibling shadows
78
+ // it, so Metro never tries to resolve `'crypto'`.
79
+ // ---------------------------------------------------------------------------
80
+ let cachedNodeCrypto = null;
81
+ export async function loadNodeCrypto() {
82
+ if (cachedNodeCrypto) {
83
+ return cachedNodeCrypto;
84
+ }
85
+ cachedNodeCrypto = await import('node:crypto');
86
+ return cachedNodeCrypto;
87
+ }
88
+ // ---------------------------------------------------------------------------
89
+ // RN-only modules — never called from this variant.
90
+ //
91
+ // These throw a clear error if anything ever reaches them outside RN. In
92
+ // practice every caller gates with `isReactNative()` before calling, so
93
+ // these are belt-and-braces.
94
+ // ---------------------------------------------------------------------------
95
+ function notReactNativeError(module) {
96
+ return new Error(`[oxy.platformCrypto] Tried to load '${module}' outside React Native. This module is only available in a React Native runtime; bundling routed this consumer to the default (Node/web) variant. This indicates a missing platform gate (\`isReactNative()\`) in the calling code.`);
97
+ }
98
+ export async function loadExpoCrypto() {
99
+ if (isReactNative()) {
100
+ // Should be unreachable: when running on RN, Metro / the `react-native`
101
+ // exports condition serves the sibling variant. If we got here, the
102
+ // package-exports map is misconfigured for this host. Throw with a
103
+ // helpful diagnostic rather than fall back to a broken dynamic import.
104
+ throw new Error('[oxy.platformCrypto] React Native runtime resolved the default ' +
105
+ '(non-RN) variant of @oxyhq/core/utils/platformCrypto. Check the ' +
106
+ "consumer's bundler resolution — Metro should pick the sibling " +
107
+ '.react-native.js file via package exports.');
108
+ }
109
+ throw notReactNativeError('expo-crypto');
110
+ }
111
+ export async function loadSecureStore() {
112
+ throw notReactNativeError('expo-secure-store');
113
+ }
114
+ export async function loadAsyncStorage() {
115
+ throw notReactNativeError('@react-native-async-storage/async-storage');
116
+ }
117
+ /**
118
+ * Synchronous random-bytes via `expo-crypto.getRandomBytes`. Only available
119
+ * in the React Native variant. The default variant throws because Node and
120
+ * browsers have their own native CSPRNGs (`crypto.randomBytes` and
121
+ * `crypto.getRandomValues` respectively) — callers should use those.
122
+ */
123
+ export function getRandomBytesRN(_byteCount) {
124
+ throw notReactNativeError('expo-crypto.getRandomBytes (sync)');
125
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Platform Crypto / Storage — React Native Variant
3
+ *
4
+ * Companion to `./platformCrypto.ts`. See the doc-comment at the top of that
5
+ * file for the full design.
6
+ *
7
+ * Metro auto-selects this file in any non-web build (`preferNativePlatform`
8
+ * is `true` for iOS / Android, so `*.native.js` shadows `*.js` during
9
+ * source-extension resolution inside `node_modules/@oxyhq/core/dist/`). On
10
+ * iOS / Android `<base>.ios.js` / `<base>.android.js` would shadow this file
11
+ * if they existed, but they don't — `.native.js` is the shared RN variant.
12
+ *
13
+ * - The default variant references Node's `'crypto'` and would crash Metro
14
+ * if bundled into an RN app.
15
+ * - This variant references the RN-only modules (`expo-crypto`,
16
+ * `expo-secure-store`, `@react-native-async-storage/async-storage`)
17
+ * as static imports, so Metro and Hermes both resolve and parse them
18
+ * cleanly.
19
+ *
20
+ * Both variants expose the same surface; importers don't care which one
21
+ * they got.
22
+ *
23
+ * # Why static imports?
24
+ *
25
+ * Every RN consumer of `@oxyhq/core` already lists or transitively pulls
26
+ * in `expo-crypto`, `expo-secure-store`, and
27
+ * `@react-native-async-storage/async-storage` (they're stable Expo modules
28
+ * present in `services`, `accounts`, `inbox`, and `test-app`). A static
29
+ * import is what Metro wants to see anyway, and Hermes parses it like any
30
+ * other ES module — no `Function`-constructor parser exotic-mode involved.
31
+ *
32
+ * This is also clearer to debug: Metro fails up-front with a normal
33
+ * unresolved-module error if a consumer is missing a peer dep, instead of
34
+ * a confusing runtime throw the first time a code path that needs the
35
+ * module is exercised.
36
+ */
37
+ import * as ExpoCrypto from 'expo-crypto';
38
+ import * as SecureStore from 'expo-secure-store';
39
+ import AsyncStorage from '@react-native-async-storage/async-storage';
40
+ // ---------------------------------------------------------------------------
41
+ // Node `crypto` — never available in RN.
42
+ // ---------------------------------------------------------------------------
43
+ export async function loadNodeCrypto() {
44
+ // Unreachable in practice: every caller gates with `isNodeJS()` before
45
+ // invoking this. If it somehow does fire, throw immediately with a clear
46
+ // diagnostic rather than letting Metro / Hermes attempt to find a
47
+ // non-existent module at runtime.
48
+ throw new Error("[oxy.platformCrypto] Node's built-in 'crypto' module is not available " +
49
+ 'in a React Native runtime. Use the RN-specific helpers ' +
50
+ '(loadExpoCrypto, getRandomBytesRN) or the Web Crypto API (`globalThis.crypto`).');
51
+ }
52
+ // ---------------------------------------------------------------------------
53
+ // expo-crypto — RN cryptographic primitives.
54
+ // ---------------------------------------------------------------------------
55
+ export async function loadExpoCrypto() {
56
+ return ExpoCrypto;
57
+ }
58
+ // ---------------------------------------------------------------------------
59
+ // expo-secure-store — RN keychain / keystore.
60
+ // ---------------------------------------------------------------------------
61
+ export async function loadSecureStore() {
62
+ return SecureStore;
63
+ }
64
+ export async function loadAsyncStorage() {
65
+ // Mirror the shape callers historically used (`module.default.<method>`)
66
+ // so the call sites don't have to know whether the underlying module
67
+ // ships ESM or CJS-with-default.
68
+ const storage = AsyncStorage;
69
+ return {
70
+ default: storage,
71
+ };
72
+ }
73
+ /**
74
+ * Synchronous random-bytes via `expo-crypto.getRandomBytes`. Available
75
+ * synchronously because `expo-crypto` is statically imported by this file
76
+ * — no async initialization race.
77
+ */
78
+ export function getRandomBytesRN(byteCount) {
79
+ return ExpoCrypto.getRandomBytes(byteCount);
80
+ }