@moonpay/platform-sdk-react-native 1.15.2 → 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
@@ -91,6 +91,11 @@ var applePaySpec = {
91
91
  kind: "challenge",
92
92
  payload: msg.payload
93
93
  };
94
+ case "cancelled":
95
+ return {
96
+ kind: "cancelled",
97
+ payload: msg.payload
98
+ };
94
99
  case "error": {
95
100
  const payload = msg.payload;
96
101
  if (payload.code === "quoteExpired") {
@@ -135,6 +140,11 @@ var googlePaySpec = {
135
140
  kind: "challenge",
136
141
  payload: msg.payload
137
142
  };
143
+ case "cancelled":
144
+ return {
145
+ kind: "cancelled",
146
+ payload: msg.payload
147
+ };
138
148
  case "error": {
139
149
  const payload = msg.payload;
140
150
  if (payload.code === "quoteExpired") {
@@ -492,7 +502,13 @@ var import_react = require("react");
492
502
  var import_react_native = require("react-native");
493
503
  var import_react_native_webview = __toESM(require("react-native-webview"), 1);
494
504
  var import_jsx_runtime = require("react/jsx-runtime");
495
- 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
+ }) {
496
512
  const webViewRef = (0, import_react.useRef)(null);
497
513
  (0, import_react.useEffect)(() => {
498
514
  transport.attachWebView(webViewRef);
@@ -508,13 +524,15 @@ function MoonPayFrame({ transport, hidden, style }) {
508
524
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { style: containerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
509
525
  import_react_native_webview.default,
510
526
  {
511
- ref: webViewRef,
512
- source: { uri: url },
513
- onMessage: handleMessage,
527
+ originWhitelist: DEFAULT_ORIGIN_WHITELIST,
514
528
  allowsInlineMediaPlayback: true,
515
529
  javaScriptEnabled: true,
516
530
  domStorageEnabled: true,
517
- style: { flex: 1 }
531
+ style: { flex: 1 },
532
+ ...webViewProps,
533
+ ref: webViewRef,
534
+ source: { uri: url },
535
+ onMessage: handleMessage
518
536
  }
519
537
  ) });
520
538
  }
@@ -580,6 +598,7 @@ var WebViewTransport = class {
580
598
  };
581
599
 
582
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.";
583
602
  var FrameSessionDisposedError = class extends Error {
584
603
  constructor() {
585
604
  super("Frame session disposed");
@@ -589,7 +608,11 @@ var FrameSessionDisposedError = class extends Error {
589
608
  function createFrameSession(spec, ctx, props, overrides = {}) {
590
609
  const generated = `${spec.channelPrefix}-${Date.now()}`;
591
610
  const channelId = spec.resolveChannelId ? spec.resolveChannelId(props, generated) : generated;
592
- 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
+ }
593
616
  const builtUrl = spec.buildUrl ? spec.buildUrl(ctx, props, channelId, keyPair?.publicKey) : (0, import_platform_sdk_core3.buildFrameUrl)(
594
617
  spec.path,
595
618
  { ...spec.buildParams?.(ctx, props, keyPair?.publicKey), channelId },
@@ -1321,7 +1344,8 @@ function MoonPayFrameView({
1321
1344
  props,
1322
1345
  style,
1323
1346
  defaultStyle,
1324
- onEvent
1347
+ onEvent,
1348
+ webViewProps
1325
1349
  }) {
1326
1350
  const { sessionToken, core, frameBaseUrl, theme } = useMoonPayContext();
1327
1351
  const [transport, setTransport] = (0, import_react4.useState)(null);
@@ -1389,15 +1413,15 @@ function MoonPayFrameView({
1389
1413
  applyReactiveProps(spec, reactiveKeys, propsRef.current, appliedRef.current, handle);
1390
1414
  }, [liveKey]);
1391
1415
  if (spec.hidden) {
1392
- 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;
1393
1417
  }
1394
1418
  const resolvedStyle = { ...defaultStyle, ...style };
1395
- 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 });
1396
1420
  }
1397
1421
 
1398
1422
  // src/components/add-card.tsx
1399
1423
  var import_jsx_runtime5 = require("react/jsx-runtime");
1400
- function MoonPayAddCard({ onEvent, style }) {
1424
+ function MoonPayAddCard({ onEvent, style, webViewProps }) {
1401
1425
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1402
1426
  MoonPayFrameView,
1403
1427
  {
@@ -1405,7 +1429,8 @@ function MoonPayAddCard({ onEvent, style }) {
1405
1429
  props: {},
1406
1430
  style,
1407
1431
  defaultStyle: { flex: 1 },
1408
- onEvent
1432
+ onEvent,
1433
+ webViewProps
1409
1434
  }
1410
1435
  );
1411
1436
  }
@@ -1416,7 +1441,8 @@ function MoonPayApplePayButton({
1416
1441
  quote,
1417
1442
  externalTransactionId,
1418
1443
  onEvent,
1419
- style
1444
+ style,
1445
+ webViewProps
1420
1446
  }) {
1421
1447
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1422
1448
  MoonPayFrameView,
@@ -1425,14 +1451,15 @@ function MoonPayApplePayButton({
1425
1451
  props: { quote, externalTransactionId },
1426
1452
  style,
1427
1453
  defaultStyle: { height: 48 },
1428
- onEvent
1454
+ onEvent,
1455
+ webViewProps
1429
1456
  }
1430
1457
  );
1431
1458
  }
1432
1459
 
1433
1460
  // src/components/auth.tsx
1434
1461
  var import_jsx_runtime7 = require("react/jsx-runtime");
1435
- function MoonPayAuth({ onEvent, style }) {
1462
+ function MoonPayAuth({ onEvent, style, webViewProps }) {
1436
1463
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1437
1464
  MoonPayFrameView,
1438
1465
  {
@@ -1440,7 +1467,8 @@ function MoonPayAuth({ onEvent, style }) {
1440
1467
  props: {},
1441
1468
  style,
1442
1469
  defaultStyle: { flex: 1 },
1443
- onEvent
1470
+ onEvent,
1471
+ webViewProps
1444
1472
  }
1445
1473
  );
1446
1474
  }
@@ -1451,7 +1479,8 @@ function MoonPayBuyButton({
1451
1479
  quote,
1452
1480
  externalTransactionId,
1453
1481
  onEvent,
1454
- style
1482
+ style,
1483
+ webViewProps
1455
1484
  }) {
1456
1485
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1457
1486
  MoonPayFrameView,
@@ -1460,7 +1489,8 @@ function MoonPayBuyButton({
1460
1489
  props: { quote, externalTransactionId },
1461
1490
  style,
1462
1491
  defaultStyle: { height: 48 },
1463
- onEvent
1492
+ onEvent,
1493
+ webViewProps
1464
1494
  }
1465
1495
  );
1466
1496
  }
@@ -1470,7 +1500,8 @@ var import_jsx_runtime9 = require("react/jsx-runtime");
1470
1500
  function MoonPayBuyFrame({
1471
1501
  quote,
1472
1502
  externalTransactionId,
1473
- onEvent
1503
+ onEvent,
1504
+ webViewProps
1474
1505
  }) {
1475
1506
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1476
1507
  MoonPayFrameView,
@@ -1478,14 +1509,20 @@ function MoonPayBuyFrame({
1478
1509
  spec: buySpec,
1479
1510
  props: { quote, externalTransactionId },
1480
1511
  defaultStyle: {},
1481
- onEvent
1512
+ onEvent,
1513
+ webViewProps
1482
1514
  }
1483
1515
  );
1484
1516
  }
1485
1517
 
1486
1518
  // src/components/challenge.tsx
1487
1519
  var import_jsx_runtime10 = require("react/jsx-runtime");
1488
- function MoonPayChallenge({ url, onEvent, style }) {
1520
+ function MoonPayChallenge({
1521
+ url,
1522
+ onEvent,
1523
+ style,
1524
+ webViewProps
1525
+ }) {
1489
1526
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1490
1527
  MoonPayFrameView,
1491
1528
  {
@@ -1493,14 +1530,20 @@ function MoonPayChallenge({ url, onEvent, style }) {
1493
1530
  props: { url },
1494
1531
  style,
1495
1532
  defaultStyle: { flex: 1 },
1496
- onEvent
1533
+ onEvent,
1534
+ webViewProps
1497
1535
  }
1498
1536
  );
1499
1537
  }
1500
1538
 
1501
1539
  // src/components/connect.tsx
1502
1540
  var import_jsx_runtime11 = require("react/jsx-runtime");
1503
- function MoonPayConnect({ theme, onEvent, style }) {
1541
+ function MoonPayConnect({
1542
+ theme,
1543
+ onEvent,
1544
+ style,
1545
+ webViewProps
1546
+ }) {
1504
1547
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1505
1548
  MoonPayFrameView,
1506
1549
  {
@@ -1508,7 +1551,8 @@ function MoonPayConnect({ theme, onEvent, style }) {
1508
1551
  props: { theme },
1509
1552
  style,
1510
1553
  defaultStyle: { flex: 1 },
1511
- onEvent
1554
+ onEvent,
1555
+ webViewProps
1512
1556
  }
1513
1557
  );
1514
1558
  }
@@ -1517,7 +1561,8 @@ function MoonPayConnect({ theme, onEvent, style }) {
1517
1561
  var import_jsx_runtime12 = require("react/jsx-runtime");
1518
1562
  function MoonPayConnectionCheck({
1519
1563
  skipKyc,
1520
- onEvent
1564
+ onEvent,
1565
+ webViewProps
1521
1566
  }) {
1522
1567
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1523
1568
  MoonPayFrameView,
@@ -1525,20 +1570,37 @@ function MoonPayConnectionCheck({
1525
1570
  spec: connectionCheckSpec,
1526
1571
  props: { skipKyc },
1527
1572
  defaultStyle: {},
1528
- onEvent
1573
+ onEvent,
1574
+ webViewProps
1529
1575
  }
1530
1576
  );
1531
1577
  }
1532
1578
 
1533
1579
  // src/components/connection-reset.tsx
1534
1580
  var import_jsx_runtime13 = require("react/jsx-runtime");
1535
- function MoonPayConnectionReset({ onEvent }) {
1536
- 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
+ );
1537
1595
  }
1538
1596
 
1539
1597
  // src/components/customer-export.tsx
1540
1598
  var import_jsx_runtime14 = require("react/jsx-runtime");
1541
- function MoonPayCustomerExport({ onEvent, style }) {
1599
+ function MoonPayCustomerExport({
1600
+ onEvent,
1601
+ style,
1602
+ webViewProps
1603
+ }) {
1542
1604
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1543
1605
  MoonPayFrameView,
1544
1606
  {
@@ -1546,7 +1608,8 @@ function MoonPayCustomerExport({ onEvent, style }) {
1546
1608
  props: {},
1547
1609
  style,
1548
1610
  defaultStyle: { flex: 1 },
1549
- onEvent
1611
+ onEvent,
1612
+ webViewProps
1550
1613
  }
1551
1614
  );
1552
1615
  }
@@ -1557,7 +1620,8 @@ function MoonPayGooglePayButton({
1557
1620
  quote,
1558
1621
  externalTransactionId,
1559
1622
  onEvent,
1560
- style
1623
+ style,
1624
+ webViewProps
1561
1625
  }) {
1562
1626
  return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1563
1627
  MoonPayFrameView,
@@ -1566,7 +1630,8 @@ function MoonPayGooglePayButton({
1566
1630
  props: { quote, externalTransactionId },
1567
1631
  style,
1568
1632
  defaultStyle: { height: 48 },
1569
- onEvent
1633
+ onEvent,
1634
+ webViewProps
1570
1635
  }
1571
1636
  );
1572
1637
  }
@@ -1577,7 +1642,8 @@ function MoonPayWidget({
1577
1642
  quote,
1578
1643
  externalTransactionId,
1579
1644
  onEvent,
1580
- style
1645
+ style,
1646
+ webViewProps
1581
1647
  }) {
1582
1648
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1583
1649
  MoonPayFrameView,
@@ -1586,7 +1652,8 @@ function MoonPayWidget({
1586
1652
  props: { quote, externalTransactionId },
1587
1653
  style,
1588
1654
  defaultStyle: { flex: 1 },
1589
- onEvent
1655
+ onEvent,
1656
+ webViewProps
1590
1657
  }
1591
1658
  );
1592
1659
  }