@getpara/react-native-wallet 2.0.0-alpha.70 → 2.0.0-alpha.72

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/shim.js CHANGED
@@ -9,7 +9,37 @@ import { Buffer } from '@craftzdog/react-native-buffer';
9
9
  import process from 'process';
10
10
  import 'react-native-url-polyfill/auto';
11
11
  import { TextEncoder, TextDecoder } from 'text-encoding';
12
- import structuredClone from '@ungap/structured-clone';
12
+ let cachedStructuredCloneImpl;
13
+ const resolveStructuredClone = () => {
14
+ if (typeof cachedStructuredCloneImpl !== 'undefined') {
15
+ return cachedStructuredCloneImpl;
16
+ }
17
+ if (typeof globalThis.structuredClone === 'function') {
18
+ cachedStructuredCloneImpl = globalThis.structuredClone.bind(globalThis);
19
+ return cachedStructuredCloneImpl;
20
+ }
21
+ const isHermes = typeof globalThis.HermesInternal === 'object' && globalThis.HermesInternal !== null;
22
+ if (isHermes) {
23
+ // Hermes crashes when @ungap/structured-clone rewires Reflect helpers.
24
+ cachedStructuredCloneImpl = null;
25
+ return cachedStructuredCloneImpl;
26
+ }
27
+ try {
28
+ const maybePolyfill = require('@ungap/structured-clone');
29
+ const polyfill = (maybePolyfill && maybePolyfill.default) || maybePolyfill;
30
+ if (typeof polyfill === 'function') {
31
+ cachedStructuredCloneImpl = polyfill;
32
+ return cachedStructuredCloneImpl;
33
+ }
34
+ }
35
+ catch (err) {
36
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
37
+ console.warn('[Para React Native shim] Failed to load structuredClone polyfill', err);
38
+ }
39
+ }
40
+ cachedStructuredCloneImpl = null;
41
+ return cachedStructuredCloneImpl;
42
+ };
13
43
  const setupProcessPolyfill = () => {
14
44
  if (typeof globalThis.process === 'undefined') {
15
45
  globalThis.process = process;
@@ -238,14 +268,77 @@ const setupTextEncodingPolyfills = () => {
238
268
  globalThis.TextEncoder = TextEncoder;
239
269
  globalThis.TextDecoder = TextDecoder;
240
270
  };
271
+ const setupWindowLocationPolyfill = () => {
272
+ const FALLBACK_HOST = 'para.mobile';
273
+ const FALLBACK_ORIGIN = `https://${FALLBACK_HOST}`;
274
+ const globalScope = globalThis;
275
+ if (!globalScope.window || typeof globalScope.window !== 'object') {
276
+ globalScope.window = globalScope;
277
+ }
278
+ const win = globalScope.window;
279
+ const existingLocation = (win && win.location) || globalScope.location;
280
+ const hasOrigin = existingLocation &&
281
+ typeof existingLocation === 'object' &&
282
+ typeof existingLocation.origin === 'string' &&
283
+ typeof existingLocation.host === 'string';
284
+ if (hasOrigin) {
285
+ if (!globalScope.location) {
286
+ globalScope.location = existingLocation;
287
+ }
288
+ return;
289
+ }
290
+ const fallbackLocation = {
291
+ href: `${FALLBACK_ORIGIN}/`,
292
+ origin: FALLBACK_ORIGIN,
293
+ protocol: 'https:',
294
+ host: FALLBACK_HOST,
295
+ hostname: FALLBACK_HOST,
296
+ port: '',
297
+ pathname: '/',
298
+ };
299
+ const patchedLocation = typeof existingLocation === 'object' && existingLocation !== null
300
+ ? Object.assign({}, fallbackLocation, existingLocation)
301
+ : fallbackLocation;
302
+ win.location = patchedLocation;
303
+ globalScope.location = patchedLocation;
304
+ };
241
305
  const setupStructuredClonePolyfill = () => {
242
- if (typeof globalThis.structuredClone === 'undefined') {
243
- globalThis.structuredClone = structuredClone;
306
+ if (typeof globalThis.structuredClone === 'function') {
307
+ return;
244
308
  }
309
+ const structuredCloneImpl = resolveStructuredClone();
310
+ const safeStructuredClone = (value, options) => {
311
+ if (typeof structuredCloneImpl === 'function') {
312
+ try {
313
+ return structuredCloneImpl(value, options);
314
+ }
315
+ catch (err) {
316
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
317
+ console.warn('[Para React Native shim] structuredClone polyfill failed, falling back to JSON clone', err);
318
+ }
319
+ }
320
+ }
321
+ try {
322
+ return JSON.parse(JSON.stringify(value));
323
+ }
324
+ catch (_err) {
325
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
326
+ console.warn('[Para React Native shim] JSON clone failed, returning original value', _err);
327
+ }
328
+ return value;
329
+ }
330
+ };
331
+ Object.defineProperty(globalThis, 'structuredClone', {
332
+ value: safeStructuredClone,
333
+ configurable: true,
334
+ enumerable: false,
335
+ writable: true,
336
+ });
245
337
  };
246
338
  setupProcessPolyfill();
247
339
  setupBufferPolyfill();
248
340
  setupBase64Polyfills();
341
+ setupWindowLocationPolyfill();
249
342
  setupCryptoPolyfills();
250
343
  setupTextEncodingPolyfills();
251
344
  setupStructuredClonePolyfill();
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@getpara/react-native-wallet",
3
3
  "description": "Para Wallet for React Native",
4
- "version": "2.0.0-alpha.70",
4
+ "version": "2.0.0-alpha.72",
5
5
  "author": "Para Team <hello@getpara.com> (https://getpara.com)",
6
6
  "dependencies": {
7
- "@getpara/core-sdk": "2.0.0-alpha.70",
8
- "@getpara/user-management-client": "2.0.0-alpha.70",
9
- "@getpara/web-sdk": "2.0.0-alpha.70",
7
+ "@getpara/core-sdk": "2.0.0-alpha.72",
8
+ "@getpara/user-management-client": "2.0.0-alpha.72",
9
+ "@getpara/web-sdk": "2.0.0-alpha.72",
10
10
  "@peculiar/webcrypto": "^1.5.0",
11
11
  "@ungap/structured-clone": "1.3.0",
12
12
  "node-forge": "1.3.1",
@@ -93,5 +93,5 @@
93
93
  ]
94
94
  }
95
95
  },
96
- "gitHead": "99d44cff3c68c07dc1cd8c2709b6ca4cd57dca61"
96
+ "gitHead": "abb7dbb2e789d245750db2206afbb1db10e87ff9"
97
97
  }
@@ -2,6 +2,7 @@ require "json"
2
2
 
3
3
  package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
4
  folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
+ new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
5
6
 
6
7
  Pod::Spec.new do |s|
7
8
  s.name = "para-react-native-wallet"
@@ -19,8 +20,9 @@ Pod::Spec.new do |s|
19
20
 
20
21
  s.dependency "React-Core"
21
22
 
22
- # Don't install the dependencies when we run `pod install` in the old architecture.
23
- if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
23
+ if respond_to?(:install_modules_dependencies, true)
24
+ install_modules_dependencies(s)
25
+ elsif new_arch_enabled
24
26
  s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
25
27
  s.pod_target_xcconfig = {
26
28
  "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
@@ -33,4 +35,4 @@ Pod::Spec.new do |s|
33
35
  s.dependency "RCTTypeSafety"
34
36
  s.dependency "ReactCommon/turbomodule/core"
35
37
  end
36
- end
38
+ end
package/src/shim.js CHANGED
@@ -9,7 +9,42 @@ import { Buffer } from '@craftzdog/react-native-buffer';
9
9
  import process from 'process';
10
10
  import 'react-native-url-polyfill/auto';
11
11
  import { TextEncoder, TextDecoder } from 'text-encoding';
12
- import structuredClone from '@ungap/structured-clone';
12
+
13
+ let cachedStructuredCloneImpl;
14
+
15
+ const resolveStructuredClone = () => {
16
+ if (typeof cachedStructuredCloneImpl !== 'undefined') {
17
+ return cachedStructuredCloneImpl;
18
+ }
19
+
20
+ if (typeof globalThis.structuredClone === 'function') {
21
+ cachedStructuredCloneImpl = globalThis.structuredClone.bind(globalThis);
22
+ return cachedStructuredCloneImpl;
23
+ }
24
+
25
+ const isHermes = typeof globalThis.HermesInternal === 'object' && globalThis.HermesInternal !== null;
26
+ if (isHermes) {
27
+ // Hermes crashes when @ungap/structured-clone rewires Reflect helpers.
28
+ cachedStructuredCloneImpl = null;
29
+ return cachedStructuredCloneImpl;
30
+ }
31
+
32
+ try {
33
+ const maybePolyfill = require('@ungap/structured-clone');
34
+ const polyfill = (maybePolyfill && maybePolyfill.default) || maybePolyfill;
35
+ if (typeof polyfill === 'function') {
36
+ cachedStructuredCloneImpl = polyfill;
37
+ return cachedStructuredCloneImpl;
38
+ }
39
+ } catch (err) {
40
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
41
+ console.warn('[Para React Native shim] Failed to load structuredClone polyfill', err);
42
+ }
43
+ }
44
+
45
+ cachedStructuredCloneImpl = null;
46
+ return cachedStructuredCloneImpl;
47
+ };
13
48
 
14
49
  const setupProcessPolyfill = () => {
15
50
  if (typeof globalThis.process === 'undefined') {
@@ -271,15 +306,87 @@ const setupTextEncodingPolyfills = () => {
271
306
  globalThis.TextDecoder = TextDecoder;
272
307
  };
273
308
 
309
+ const setupWindowLocationPolyfill = () => {
310
+ const FALLBACK_HOST = 'para.mobile';
311
+ const FALLBACK_ORIGIN = `https://${FALLBACK_HOST}`;
312
+
313
+ const globalScope = globalThis;
314
+ if (!globalScope.window || typeof globalScope.window !== 'object') {
315
+ globalScope.window = globalScope;
316
+ }
317
+
318
+ const win = globalScope.window;
319
+ const existingLocation = (win && win.location) || globalScope.location;
320
+ const hasOrigin =
321
+ existingLocation &&
322
+ typeof existingLocation === 'object' &&
323
+ typeof existingLocation.origin === 'string' &&
324
+ typeof existingLocation.host === 'string';
325
+
326
+ if (hasOrigin) {
327
+ if (!globalScope.location) {
328
+ globalScope.location = existingLocation;
329
+ }
330
+ return;
331
+ }
332
+
333
+ const fallbackLocation = {
334
+ href: `${FALLBACK_ORIGIN}/`,
335
+ origin: FALLBACK_ORIGIN,
336
+ protocol: 'https:',
337
+ host: FALLBACK_HOST,
338
+ hostname: FALLBACK_HOST,
339
+ port: '',
340
+ pathname: '/',
341
+ };
342
+
343
+ const patchedLocation =
344
+ typeof existingLocation === 'object' && existingLocation !== null
345
+ ? Object.assign({}, fallbackLocation, existingLocation)
346
+ : fallbackLocation;
347
+
348
+ win.location = patchedLocation;
349
+ globalScope.location = patchedLocation;
350
+ };
351
+
274
352
  const setupStructuredClonePolyfill = () => {
275
- if (typeof globalThis.structuredClone === 'undefined') {
276
- globalThis.structuredClone = structuredClone;
353
+ if (typeof globalThis.structuredClone === 'function') {
354
+ return;
277
355
  }
356
+
357
+ const structuredCloneImpl = resolveStructuredClone();
358
+ const safeStructuredClone = (value, options) => {
359
+ if (typeof structuredCloneImpl === 'function') {
360
+ try {
361
+ return structuredCloneImpl(value, options);
362
+ } catch (err) {
363
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
364
+ console.warn('[Para React Native shim] structuredClone polyfill failed, falling back to JSON clone', err);
365
+ }
366
+ }
367
+ }
368
+ try {
369
+ return JSON.parse(JSON.stringify(value));
370
+ } catch (_err) {
371
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
372
+ console.warn('[Para React Native shim] JSON clone failed, returning original value', _err);
373
+ }
374
+ return value;
375
+ }
376
+ };
377
+
378
+ Object.defineProperty(globalThis, 'structuredClone', {
379
+ value: safeStructuredClone,
380
+ configurable: true,
381
+ enumerable: false,
382
+ writable: true,
383
+ });
278
384
  };
279
385
 
280
386
  setupProcessPolyfill();
281
387
  setupBufferPolyfill();
282
388
  setupBase64Polyfills();
389
+ setupWindowLocationPolyfill();
283
390
  setupCryptoPolyfills();
284
391
  setupTextEncodingPolyfills();
285
392
  setupStructuredClonePolyfill();