@moonpay/platform-sdk-react-native 1.16.0 → 1.17.0

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 CHANGED
@@ -23,7 +23,30 @@ Peer dependencies:
23
23
  - `react-native` >= 0.73 (Hermes supported)
24
24
  - `react-native-webview` >= 13
25
25
 
26
- The SDK's crypto layer is pure JavaScript (`@noble` libraries) — no native modules or polyfills required.
26
+ ### Crypto polyfill (required on React Native)
27
+
28
+ The SDK's crypto layer is pure JavaScript (`@noble` libraries), but key exchange needs a cryptographically-secure `crypto.getRandomValues`. React Native (Hermes) has no Web Crypto API, so you must install a polyfill and register it **before** the SDK runs — at your app entry, or a `polyfills.ts` you import first. Without it, the first `getConnection()` fails with a clear error telling you to add one.
29
+
30
+ **Expo** — `expo-crypto` provides a Web-Crypto-compatible `getRandomValues` but does not auto-install it on the global (works in Expo Go):
31
+
32
+ ```ts
33
+ // polyfills.ts — imported first, before the MoonPay SDK
34
+ import * as Crypto from 'expo-crypto';
35
+
36
+ if (typeof globalThis.crypto?.getRandomValues !== 'function') {
37
+ globalThis.crypto = {
38
+ ...globalThis.crypto,
39
+ getRandomValues: (array) => Crypto.getRandomValues(array),
40
+ };
41
+ }
42
+ ```
43
+
44
+ **Bare React Native** — `react-native-get-random-values` installs the global on import:
45
+
46
+ ```ts
47
+ // index.js — first import, before the app
48
+ import 'react-native-get-random-values';
49
+ ```
27
50
 
28
51
  ## Quick start
29
52
 
package/dist/index.cjs CHANGED
@@ -502,7 +502,13 @@ var import_react = require("react");
502
502
  var import_react_native = require("react-native");
503
503
  var import_react_native_webview = __toESM(require("react-native-webview"), 1);
504
504
  var import_jsx_runtime = require("react/jsx-runtime");
505
- function MoonPayFrame({ transport, hidden, style }) {
505
+ var DEFAULT_ORIGIN_WHITELIST = ["https://*", "http://*", "about:srcdoc"];
506
+ function MoonPayFrame({
507
+ transport,
508
+ hidden,
509
+ style,
510
+ webViewProps
511
+ }) {
506
512
  const webViewRef = (0, import_react.useRef)(null);
507
513
  (0, import_react.useEffect)(() => {
508
514
  transport.attachWebView(webViewRef);
@@ -518,13 +524,15 @@ function MoonPayFrame({ transport, hidden, style }) {
518
524
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { style: containerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
519
525
  import_react_native_webview.default,
520
526
  {
521
- ref: webViewRef,
522
- source: { uri: url },
523
- onMessage: handleMessage,
527
+ originWhitelist: DEFAULT_ORIGIN_WHITELIST,
524
528
  allowsInlineMediaPlayback: true,
525
529
  javaScriptEnabled: true,
526
530
  domStorageEnabled: true,
527
- style: { flex: 1 }
531
+ style: { flex: 1 },
532
+ ...webViewProps,
533
+ ref: webViewRef,
534
+ source: { uri: url },
535
+ onMessage: handleMessage
528
536
  }
529
537
  ) });
530
538
  }
@@ -590,6 +598,7 @@ var WebViewTransport = class {
590
598
  };
591
599
 
592
600
  // src/frame-engine.ts
601
+ var CRYPTO_UNAVAILABLE_MESSAGE = "MoonPay SDK: crypto.getRandomValues is unavailable. React Native (Hermes) has no Web Crypto. Install and register a Web Crypto getRandomValues polyfill on the global before using the SDK \u2014 Expo: expo-crypto; bare React Native: react-native-get-random-values. See https://dev.moonpay.com/platform/sdk-reference/react-native/overview.";
593
602
  var FrameSessionDisposedError = class extends Error {
594
603
  constructor() {
595
604
  super("Frame session disposed");
@@ -599,7 +608,11 @@ var FrameSessionDisposedError = class extends Error {
599
608
  function createFrameSession(spec, ctx, props, overrides = {}) {
600
609
  const generated = `${spec.channelPrefix}-${Date.now()}`;
601
610
  const channelId = spec.resolveChannelId ? spec.resolveChannelId(props, generated) : generated;
602
- const keyPair = spec.needsKeyPair ? (0, import_platform_sdk_core3.generateKeyPair)() : void 0;
611
+ let keyPair;
612
+ if (spec.needsKeyPair) {
613
+ if (!(0, import_platform_sdk_core3.isSecureRandomAvailable)()) throw new Error(CRYPTO_UNAVAILABLE_MESSAGE);
614
+ keyPair = (0, import_platform_sdk_core3.generateKeyPair)();
615
+ }
603
616
  const builtUrl = spec.buildUrl ? spec.buildUrl(ctx, props, channelId, keyPair?.publicKey) : (0, import_platform_sdk_core3.buildFrameUrl)(
604
617
  spec.path,
605
618
  { ...spec.buildParams?.(ctx, props, keyPair?.publicKey), channelId },
@@ -1331,7 +1344,8 @@ function MoonPayFrameView({
1331
1344
  props,
1332
1345
  style,
1333
1346
  defaultStyle,
1334
- onEvent
1347
+ onEvent,
1348
+ webViewProps
1335
1349
  }) {
1336
1350
  const { sessionToken, core, frameBaseUrl, theme } = useMoonPayContext();
1337
1351
  const [transport, setTransport] = (0, import_react4.useState)(null);
@@ -1399,15 +1413,15 @@ function MoonPayFrameView({
1399
1413
  applyReactiveProps(spec, reactiveKeys, propsRef.current, appliedRef.current, handle);
1400
1414
  }, [liveKey]);
1401
1415
  if (spec.hidden) {
1402
- return transport ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MoonPayFrame, { transport, hidden: true }) : null;
1416
+ return transport ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MoonPayFrame, { transport, hidden: true, webViewProps }) : null;
1403
1417
  }
1404
1418
  const resolvedStyle = { ...defaultStyle, ...style };
1405
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.View, { style: resolvedStyle, children: transport ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MoonPayFrame, { transport }) : null });
1419
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.View, { style: resolvedStyle, children: transport ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MoonPayFrame, { transport, webViewProps }) : null });
1406
1420
  }
1407
1421
 
1408
1422
  // src/components/add-card.tsx
1409
1423
  var import_jsx_runtime5 = require("react/jsx-runtime");
1410
- function MoonPayAddCard({ onEvent, style }) {
1424
+ function MoonPayAddCard({ onEvent, style, webViewProps }) {
1411
1425
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1412
1426
  MoonPayFrameView,
1413
1427
  {
@@ -1415,7 +1429,8 @@ function MoonPayAddCard({ onEvent, style }) {
1415
1429
  props: {},
1416
1430
  style,
1417
1431
  defaultStyle: { flex: 1 },
1418
- onEvent
1432
+ onEvent,
1433
+ webViewProps
1419
1434
  }
1420
1435
  );
1421
1436
  }
@@ -1426,7 +1441,8 @@ function MoonPayApplePayButton({
1426
1441
  quote,
1427
1442
  externalTransactionId,
1428
1443
  onEvent,
1429
- style
1444
+ style,
1445
+ webViewProps
1430
1446
  }) {
1431
1447
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1432
1448
  MoonPayFrameView,
@@ -1435,14 +1451,15 @@ function MoonPayApplePayButton({
1435
1451
  props: { quote, externalTransactionId },
1436
1452
  style,
1437
1453
  defaultStyle: { height: 48 },
1438
- onEvent
1454
+ onEvent,
1455
+ webViewProps
1439
1456
  }
1440
1457
  );
1441
1458
  }
1442
1459
 
1443
1460
  // src/components/auth.tsx
1444
1461
  var import_jsx_runtime7 = require("react/jsx-runtime");
1445
- function MoonPayAuth({ onEvent, style }) {
1462
+ function MoonPayAuth({ onEvent, style, webViewProps }) {
1446
1463
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1447
1464
  MoonPayFrameView,
1448
1465
  {
@@ -1450,7 +1467,8 @@ function MoonPayAuth({ onEvent, style }) {
1450
1467
  props: {},
1451
1468
  style,
1452
1469
  defaultStyle: { flex: 1 },
1453
- onEvent
1470
+ onEvent,
1471
+ webViewProps
1454
1472
  }
1455
1473
  );
1456
1474
  }
@@ -1461,7 +1479,8 @@ function MoonPayBuyButton({
1461
1479
  quote,
1462
1480
  externalTransactionId,
1463
1481
  onEvent,
1464
- style
1482
+ style,
1483
+ webViewProps
1465
1484
  }) {
1466
1485
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1467
1486
  MoonPayFrameView,
@@ -1470,7 +1489,8 @@ function MoonPayBuyButton({
1470
1489
  props: { quote, externalTransactionId },
1471
1490
  style,
1472
1491
  defaultStyle: { height: 48 },
1473
- onEvent
1492
+ onEvent,
1493
+ webViewProps
1474
1494
  }
1475
1495
  );
1476
1496
  }
@@ -1480,7 +1500,8 @@ var import_jsx_runtime9 = require("react/jsx-runtime");
1480
1500
  function MoonPayBuyFrame({
1481
1501
  quote,
1482
1502
  externalTransactionId,
1483
- onEvent
1503
+ onEvent,
1504
+ webViewProps
1484
1505
  }) {
1485
1506
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1486
1507
  MoonPayFrameView,
@@ -1488,14 +1509,20 @@ function MoonPayBuyFrame({
1488
1509
  spec: buySpec,
1489
1510
  props: { quote, externalTransactionId },
1490
1511
  defaultStyle: {},
1491
- onEvent
1512
+ onEvent,
1513
+ webViewProps
1492
1514
  }
1493
1515
  );
1494
1516
  }
1495
1517
 
1496
1518
  // src/components/challenge.tsx
1497
1519
  var import_jsx_runtime10 = require("react/jsx-runtime");
1498
- function MoonPayChallenge({ url, onEvent, style }) {
1520
+ function MoonPayChallenge({
1521
+ url,
1522
+ onEvent,
1523
+ style,
1524
+ webViewProps
1525
+ }) {
1499
1526
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1500
1527
  MoonPayFrameView,
1501
1528
  {
@@ -1503,14 +1530,20 @@ function MoonPayChallenge({ url, onEvent, style }) {
1503
1530
  props: { url },
1504
1531
  style,
1505
1532
  defaultStyle: { flex: 1 },
1506
- onEvent
1533
+ onEvent,
1534
+ webViewProps
1507
1535
  }
1508
1536
  );
1509
1537
  }
1510
1538
 
1511
1539
  // src/components/connect.tsx
1512
1540
  var import_jsx_runtime11 = require("react/jsx-runtime");
1513
- function MoonPayConnect({ theme, onEvent, style }) {
1541
+ function MoonPayConnect({
1542
+ theme,
1543
+ onEvent,
1544
+ style,
1545
+ webViewProps
1546
+ }) {
1514
1547
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1515
1548
  MoonPayFrameView,
1516
1549
  {
@@ -1518,7 +1551,8 @@ function MoonPayConnect({ theme, onEvent, style }) {
1518
1551
  props: { theme },
1519
1552
  style,
1520
1553
  defaultStyle: { flex: 1 },
1521
- onEvent
1554
+ onEvent,
1555
+ webViewProps
1522
1556
  }
1523
1557
  );
1524
1558
  }
@@ -1527,7 +1561,8 @@ function MoonPayConnect({ theme, onEvent, style }) {
1527
1561
  var import_jsx_runtime12 = require("react/jsx-runtime");
1528
1562
  function MoonPayConnectionCheck({
1529
1563
  skipKyc,
1530
- onEvent
1564
+ onEvent,
1565
+ webViewProps
1531
1566
  }) {
1532
1567
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1533
1568
  MoonPayFrameView,
@@ -1535,20 +1570,37 @@ function MoonPayConnectionCheck({
1535
1570
  spec: connectionCheckSpec,
1536
1571
  props: { skipKyc },
1537
1572
  defaultStyle: {},
1538
- onEvent
1573
+ onEvent,
1574
+ webViewProps
1539
1575
  }
1540
1576
  );
1541
1577
  }
1542
1578
 
1543
1579
  // src/components/connection-reset.tsx
1544
1580
  var import_jsx_runtime13 = require("react/jsx-runtime");
1545
- function MoonPayConnectionReset({ onEvent }) {
1546
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(MoonPayFrameView, { spec: connectionResetSpec, props: {}, defaultStyle: {}, onEvent });
1581
+ function MoonPayConnectionReset({
1582
+ onEvent,
1583
+ webViewProps
1584
+ }) {
1585
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1586
+ MoonPayFrameView,
1587
+ {
1588
+ spec: connectionResetSpec,
1589
+ props: {},
1590
+ defaultStyle: {},
1591
+ onEvent,
1592
+ webViewProps
1593
+ }
1594
+ );
1547
1595
  }
1548
1596
 
1549
1597
  // src/components/customer-export.tsx
1550
1598
  var import_jsx_runtime14 = require("react/jsx-runtime");
1551
- function MoonPayCustomerExport({ onEvent, style }) {
1599
+ function MoonPayCustomerExport({
1600
+ onEvent,
1601
+ style,
1602
+ webViewProps
1603
+ }) {
1552
1604
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1553
1605
  MoonPayFrameView,
1554
1606
  {
@@ -1556,7 +1608,8 @@ function MoonPayCustomerExport({ onEvent, style }) {
1556
1608
  props: {},
1557
1609
  style,
1558
1610
  defaultStyle: { flex: 1 },
1559
- onEvent
1611
+ onEvent,
1612
+ webViewProps
1560
1613
  }
1561
1614
  );
1562
1615
  }
@@ -1567,7 +1620,8 @@ function MoonPayGooglePayButton({
1567
1620
  quote,
1568
1621
  externalTransactionId,
1569
1622
  onEvent,
1570
- style
1623
+ style,
1624
+ webViewProps
1571
1625
  }) {
1572
1626
  return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1573
1627
  MoonPayFrameView,
@@ -1576,7 +1630,8 @@ function MoonPayGooglePayButton({
1576
1630
  props: { quote, externalTransactionId },
1577
1631
  style,
1578
1632
  defaultStyle: { height: 48 },
1579
- onEvent
1633
+ onEvent,
1634
+ webViewProps
1580
1635
  }
1581
1636
  );
1582
1637
  }
@@ -1587,7 +1642,8 @@ function MoonPayWidget({
1587
1642
  quote,
1588
1643
  externalTransactionId,
1589
1644
  onEvent,
1590
- style
1645
+ style,
1646
+ webViewProps
1591
1647
  }) {
1592
1648
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1593
1649
  MoonPayFrameView,
@@ -1596,7 +1652,8 @@ function MoonPayWidget({
1596
1652
  props: { quote, externalTransactionId },
1597
1653
  style,
1598
1654
  defaultStyle: { flex: 1 },
1599
- onEvent
1655
+ onEvent,
1656
+ webViewProps
1600
1657
  }
1601
1658
  );
1602
1659
  }