• Stars
    star
    307
  • Rank 136,109 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 3 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

โš›๏ธ ๐ŸŒŒ Inter-dimensional Portals for React Native. ๐Ÿ‘ฝ ๐Ÿ––

๐ŸŒŒ react-native-wormhole

A Wormhole allows your โš›๏ธ React Native application to consume components from a remote URL as if it were a local import, enabling them to easily become remotely configurable at runtime!

๐ŸŽฌ Watch the Demo!

โš ๏ธ Implementors must take care to protect their Wormholes from arbitrary code execution. Insufficient protection will put your user's data and device at risk. ๐Ÿ’€ Please see Verification and Signing for more information.

๐Ÿš€ Getting Started

Using Yarn:

yarn add react-native-wormhole

Next, you'll need a component to serve. Let's create a quick project to demonstrate how this works:

mkdir my-new-wormhole
cd my-new-wormhole
yarn init
yarn add --dev @babel/core @babel/cli @babel/preset-env @babel/preset-react

That should be enough. Inside my-new-wormhole/, let's quickly create a simple component:

my-new-wormhole/MyNewWormhole.jsx:

import * as React from 'react';
import { Animated, Alert, TouchableOpacity } from 'react-native';

function CustomButton() {
  return (
    <TouchableOpacity onPress={() => Alert.alert('Hello!')}>
      <Animated.Text children="Click here!" />
    </TouchableOpacity>
  );
}

export default function MyNewWormhole() {
  const message = React.useMemo(() => 'Hello, world!', []);
  return (
    <Animated.View style={{ flex: 1, backgroundColor: 'red' }}>
      <Animated.Text>{message}</Animated.Text>
      <CustomButton />
    </Animated.View>
  );
}

๐Ÿค” What syntax am I allowed to use?

By default, you can use all functionality exported by react and react-native. The only requirement is that you must export default the Component that you wish to have served through the Wormhole.

Now our component needs to be transpiled. Below, we use Babel to convert MyNewWormhole into a format that can be executed at runtime:

npx babel --presets=@babel/preset-env,@babel/preset-react MyNewWormhole.jsx -o MyNewWormhole.js

After doing this, we'll have produced MyNewWormhole.js, which has been expressed in a format that is suitable to serve remotely. If you're unfamiliar with this process, take a quick look through the contents of the generated file to understand how it has changed.

Next, you'd need to serve this file somewhere. For example, you could save it on GitHub, IPFS or on your own local server. To see an example of this, check out the Example Server.

๐Ÿ‘ฎ Security Notice

In production environments, you must serve content using HTTPS to prevent Man in the Middle attacks. Additionally, served content must be signed using public-key encryption to ensure authenticity of the returned source code. A demonstration of this approach using Ethers is shown in the Example App.

Finally, let's render our <App />! For the purpose of this tutorial, let's assume the file is served at https://cawfree.com/MyNewWormhole.jsx:

import * as React from 'react';
import { createWormhole } from 'react-native-wormhole';

const { Wormhole } = createWormhole({
  verify: async () => true,
});

export default function App() {
  return <Wormhole source={{ uri: 'https://cawfree.com/MyNewWormhole.jsx' }} />;
}

And that's everything! Once our component has finished downloading, it'll be mounted and visible on screen. ๐Ÿš€

๐Ÿ”ฉ Configuration

๐ŸŒŽ Global Scope

By default, a Wormhole is only capable of consuming global functionality from two different modules; react and react-native, meaning that only "vanilla" React Native functionality is available. However, it is possible to introduce support for additional modules. In the snippet below, we show how to allow a Wormhole to render a WebView:

const { Wormhole } = createWormhole({
+  global: {
+    require: (moduleId: string) => {
+      if (moduleId === 'react') {
+        return require('react');
+      } else if (moduleId === 'react-native') {
+        return require('react-native');
+      } else if (moduleId === 'react-native-webview') {
+        return require('react-native-webview);
+      }
+      return null;
+    },
+  },
  verify: async () => true,
});

โš ๏ธ Version changes to react, react-native or any other dependencies your Wormholes consume may not be backwards-compatible. It's recommended that APIs serving content to requestors verify the compatibility of the requester version to avoid serving incompatible content. react-native-wormhole is not a package manager!

๐Ÿ” Verification and Signing

Calls to createWormhole must at a minimum provide a verify function, which has the following declaration:

readonly verify: (response: AxiosResponse<string>) => Promise<boolean>;

This property is used to determine the integrity of a response, and is responsible for identifying whether remote content may be trusted for execution. If the async function does not return true, the request is terminated and the content will not be rendered via a Wormhole. In the Example App, we show how content can be signed to determine the authenticity of a response:

+ import { ethers } from 'ethers';
+ import { SIGNER_ADDRESS, PORT } from '@env';

const { Wormhole } = createWormhole({
+  verify: async ({ headers, data }: AxiosResponse) => {
+    const signature = headers['x-csrf-token'];
+    const bytes = ethers.utils.arrayify(signature);
+    const hash = ethers.utils.hashMessage(data);
+    const address = await ethers.utils.recoverAddress(
+      hash,
+      bytes
+    );
+    return address === SIGNER_ADDRESS;
+  },
});

In this implementation, the server is expected to return a HTTP response header x-csrf-token whose value is a signedMessage of the response body. Here, the client computes the expected signing address of the served content using the digest stored in the header.

If the recovered address is not trusted, the script will not be executed.

๐ŸŽ๏ธ Preloading

Making a call to createWormhole() also returns a preload function which can be used to asynchronously cache remote JSX before a Wormhole has been mounted:

const { preload } = createWormhole({ verify: async () => true });

(async () => {
  try {
    await preload('https://cawfree.com/MyNewWormhole.jsx');
  } catch (e) {
    console.error('Failed to preload.');
  }
})();

Wormholes dependent upon the external content will subsequently render immediately if the operation has completed in time. Meanwhile, concurrent requests to the same resource will be deduped.

โœŒ๏ธ License

MIT

More Repositories

1

create-react-native-dapp

Your next Ethereum application starts here. โš›๏ธ ๐Ÿ’ช ๐Ÿฆ„
TypeScript
430
star
2

react-native-webassembly

โš›๏ธ ๐ŸŽ WebAssembly for React Native powered by JSI.
C
274
star
3

react-native-quiet

๐Ÿคซ Quiet for React Native.
JavaScript
173
star
4

react-dark-mode-toggle

๐Ÿฆ‰ A cutesy dark mode toggle button for React.
JavaScript
154
star
5

react-native-segmented-text-input

A wickedly customizable <TextInput /> for React Native. Useful for tags, spellchecking, whatever.
JavaScript
138
star
6

react-native-rough

โš›๏ธโœ๏ธRough.js bindings for that hand-drawn feel.
JavaScript
108
star
7

zk-starter

zero knowledge for those with zero knowledge
Solidity
102
star
8

react-native-openai-jsx

โš›๏ธ ๐Ÿงช ๐Ÿค– Use OpenAI to generate functioning React Native components!
TypeScript
92
star
9

OpenChirp

A reverse-engineered implementation of the Chirp data-over-audio protocol.
Java
83
star
10

react-native-helios

โš›๏ธ A fast, secure, and portable light client for Ethereum dApps.
TypeScript
81
star
11

react-native-twitter-textview

A <TextView/> component for React Native built on top of twitter-text linkification.
JavaScript
71
star
12

web3-react-native

โš›๏ธ Web3 Native Modules for React Native.
JavaScript
62
star
13

react-cola

WebCola for React.
JavaScript
59
star
14

react-native-walletconnect

โš›๏ธ ๐Ÿ‘› WalletConnect for React Native! Zero linking, full awesome. (Android/iOS/Web/Expo)
JavaScript
54
star
15

react-native-blobular

The Man in Blue's awesome Blobular, ported to React Native.
JavaScript
53
star
16

react-native-custom-fonts

Use dynamic fonts specified via a network location, instead of managing them in your native builds!
Java
48
star
17

opensea-arb-nft20

๐Ÿงธ ๐Ÿ’ธ Detects arbitrage opportunities for ERC-721 tokens between OpenSea and NFT20.
JavaScript
47
star
18

react-native-picture-puzzle

โš›๏ธ ๐Ÿงฉ A picture puzzle component.
TypeScript
42
star
19

opensea-floor-looks-rare

๐Ÿงธ ๐Ÿ’ธ Determine the rarity of floor NFTs on OpenSea.
JavaScript
39
star
20

react-native-rotary

๐Ÿ•ฐ๏ธ A <Rotary /> component for React Native.
JavaScript
37
star
21

react-native-basement

๐Ÿญ๐Ÿงโ›ฑ๏ธ๐Ÿ“ฆCache all kinds of remote dependencies.
JavaScript
35
star
22

thegraph-react

โš›๏ธ React bindings for helping build decentralized applications quickly on Ethereum and IPFS using GraphQL.
Java
33
star
23

react-native-sensor-fusion

Robust absolute positioning in React Native.
JavaScript
30
star
24

opensea-submarine

Ping. Ping. Ping.
TypeScript
30
star
25

react-native-apple-scroll-wheel

The iconic scroll wheel that debuted with the original iPod. Now for React Native.
JavaScript
29
star
26

nodejs-mobile-react-native-bridge

A high-level wrapper interface to Node.js for React Native.
JavaScript
29
star
27

sameorigin

๐Ÿค– ๐Ÿงช Masquerade as if you were their own frontend.
TypeScript
26
star
28

react-native-localhost

โš›๏ธ ๐Ÿก Returns the local address of your actual development machine.
JavaScript
25
star
29

react-native-label

๐Ÿฅ‡Apply a label to anything in React Native.
JavaScript
23
star
30

react-native-search-bar-button

๐Ÿ•Š๏ธ Is it a bird? โœˆ๏ธ Is it a plane? No, it's a search-bar-button! โš›๏ธ
JavaScript
22
star
31

react-use-logs

โš›๏ธ ๐Ÿ–จ๏ธ A hierarchy sensitive, middleware-defined console.log for React and React Native. โœจ
TypeScript
21
star
32

react-native-pure-data

๐Ÿ”ˆ โšก Synthesize algorithmic sound at runtime in React Native.
JavaScript
20
star
33

react-native-use-plaid

โš›๏ธ ๐Ÿ’ธ Simple hooks for Plaid open banking on React Native.
TypeScript
20
star
34

Dynamic-Time-Warping

A Dynamic Time Warping (DTW) implementation on Android.
Java
19
star
35

earcut-j

A pure Java implementation of the earcut triangulation library.
Java
19
star
36

react-native-heat-map

A <HeatMap /> Native Module component for React Native.
Java
18
star
37

react-native-webview-modal

โš›๏ธ A WebView <Modal /> component for React Native, where the source content is pre-loaded for speed ๐Ÿ. (iOS/Android/Web/Expo)
JavaScript
18
star
38

react-native-layout-animation-provider

A React Native <Provider/> for synchronizing your LayoutAnimations.
JavaScript
17
star
39

autographed

The self-building, hot-reloading subgraph. The quickest way to start indexing your shit.
TypeScript
16
star
40

crypto-lstm-3

๐Ÿ’ต Using word2vec to predict trends in cryptocurrency.
JavaScript
15
star
41

react-native-pretty-payment

โš›๏ธ ๐Ÿค‘ Super pretty payment inputs for React Native.
TypeScript
15
star
42

use-delegatecash

โš›๏ธ ๐Ÿ’ธ React.js hooks for delegate.cash
TypeScript
14
star
43

otsu

โœ‚๏ธ Otsu's Method for automated thresholding in JavaScript.
JavaScript
13
star
44

pyongyang

โš›๏ธ ๐Ÿ“ฑ The quickest way to utilize web dependencies inside React Native.
JavaScript
13
star
45

react-native-elsewhere

Ridiculously simple React Native thread unblocking.
JavaScript
13
star
46

react-native-twitter-embed

Twitter Embeds for React Native + Expo. (Web/iOS/Android) https://publish.twitter.com/
Java
12
star
47

byth

The behavioural indexer for Ethereum.
Rust
11
star
48

collection-slug

๐Ÿงธ ๐Ÿค– Determine the collection slug for a collection on OpenSea.
TypeScript
11
star
49

redacted

A plugin architecture for React.
JavaScript
11
star
50

react-native-simpler-date-picker

A simple date picker component with a focus on reducing implementation complexity.
JavaScript
11
star
51

nftrarity-chrome

๐Ÿ’ธ ๐Ÿงธ ๐Ÿ“ˆ A Chrome plugin to display the rarity of an NFT inline on OpenSea ๐ŸŒŠ
JavaScript
10
star
52

react-native-elastic-footer

A React Native ScrollView footer with a little give.
JavaScript
9
star
53

react-native-lottie-files-picker

A React Native List that supports the selection of beautiful Lottie Animations sourced by Lottie Files.
JavaScript
9
star
54

react-native-buttered-toast

A customizable toast notification for React Native.
JavaScript
8
star
55

react-native-split-styles

๐Ÿ’… Split StyleSheet keys into dedicated objects to help ease the routing of styles for nested components.
JavaScript
8
star
56

react-native-number-ticker-input

๐Ÿ“Ÿ A customizable numeric input in the style of a ticker.
JavaScript
8
star
57

react-native-splash-generate

Programmatically generates a launch image for all screen densities from a single image source.
JavaScript
8
star
58

react-native-firebase-upload-provider

๐Ÿ“ธ Easily and quickly upload rich media to Firebase Storage.
JavaScript
7
star
59

log-in-as-a-lobster

โš›๏ธ Log In as a Lobster ๐Ÿฆž
TypeScript
7
star
60

ribbon-vg

A hardware accelerated platform independent signed distance vector graphics rendering library.
Java
7
star
61

react-native-drag-to-reveal

โš›๏ธ ๐Ÿ–• You drag, it reveals. (Android/iOS/Web/Expo)
TypeScript
7
star
62

dsfe

๐Ÿ’ช Do some fucking exercise.
TypeScript
6
star
63

hardhat-copy

Pull a smart contract from mainnet onto your local chain.
TypeScript
6
star
64

react-native-unibubbles

An animated floating header component. You probably don't need it. ๐Ÿ˜œ
JavaScript
6
star
65

use-merge

โš›๏ธ ๐Ÿ’ก Simplify the relationships between multiple hooks.
TypeScript
6
star
66

propeteer

๐ŸงธConfig comes in, React comes out.
JavaScript
6
star
67

lottie-mutate

A collection of functions useful for manipulating raw Lottie Animation JSON programatically.
JavaScript
6
star
68

twitch-go

๐ŸŽฎ A Chromebook desktop streaming utility for Twitch.
JavaScript
6
star
69

react-native-simple-date-picker

An idiot-proof date picker for React Native.
JavaScript
6
star
70

nanovgj

A Java implementation of NanoVG.
Java
5
star
71

react-native-animated-look-up-table

Creates a look up table which can be used to interpolate across the results of an arbitrary function.
JavaScript
5
star
72

nifty-inker

๐Ÿฆ„ ๐ŸŽจ a programmatic painter for nifty.ink because i have no talent
TypeScript
5
star
73

react-native-simpleheat

The awesome simpleheat.js, bound to React Native.
JavaScript
5
star
74

react-use-mutator

A React hook for inspecting and mutating shared state without subscribing to render updates.
JavaScript
5
star
75

nftrarityjs

โšก๐Ÿงธโšก A collection of tools for comparing the 1337ness of an NFT.
JavaScript
5
star
76

react-dfd

Dataflow Diagrams for React. ๐Ÿ–‡๏ธ
JavaScript
5
star
77

react-native-uri-box

An extendible React <Component/> which will attempt to render source content consistently, based on the MIME type.
JavaScript
5
star
78

countersoiree

๐Ÿ’ƒ ๐Ÿงช GraphQL for the Ethereum mempool.
TypeScript
4
star
79

react-native-view-evaluator

A React Native <Component /> which can be used to determine the post-layout configuration of a <View />.
JavaScript
4
star
80

react-dataflow

A dataflow execution library for React.
JavaScript
4
star
81

sabrina

โœจ Asynchronous dashboard magic!
JavaScript
4
star
82

RegionView

A simple Android Layout that enables drag and zoom for child Views.
Java
4
star
83

timusoid

Cyclic representations of time.
JavaScript
4
star
84

reuters-dataset

๐Ÿ—ž๏ธ A tool for downloading and parsing Reuters-21578. These are a collection of documents that appeared on Reuters newswire back in 1987.
JavaScript
3
star
85

ethers-url

๐Ÿฆ„ ๐Ÿ”— Convert high level ethers transactions into sharable links!
TypeScript
3
star
86

react-native-cycle-text

A simple React Native component which lets you randomly cycle through an array of text Strings.
JavaScript
3
star
87

autogist

โšก๐Ÿ“„ ๐ŸฅฏA mini Twitter for your pinned repositories.
JavaScript
3
star
88

react-native-windowed-collapsible

A <Collapsible/> component for React Native, with a difference.
JavaScript
3
star
89

react-pretty-ethereum

โš›๏ธ ฮž Render Web3 data models in a user-friendly way.
JavaScript
3
star
90

react-native-modal-provider

A React <Provider /> for managing <Modal />s.
JavaScript
3
star
91

express-cors-anywhere

๐ŸŒ An express middleware for redirecting requests and avoiding CORS errors when hitting cross-origin APIs.
JavaScript
3
star
92

supporting-material

All of the notes, slides and documentation for any public speaking I've had the luck of being invited along to.
JavaScript
3
star
93

rippleware

๐Ÿšฃ A middleware-inspired toolbox that promotes stateful function extensibility.
JavaScript
3
star
94

sofia

Firestore Rules. With variables.
JavaScript
3
star
95

piggyback

๐Ÿฆ„ ๐Ÿค– A replica implementation of an MEV honeypot bot I caught out in the wild.
TypeScript
3
star
96

jovo-babel-project

An example project using Jovo Framework alongside JavaScript ES6.
JavaScript
2
star
97

react-apple-pay-button

... It's an Apple Pay button. For React. ๐Ÿคทโ€โ™€๏ธ
JavaScript
2
star
98

timebuffer

โฒ๏ธ Simple segmentation of timeboxed data handlers.
JavaScript
2
star
99

react-silhouette

Deferred unmounting in React.js.
JavaScript
2
star
100

archimedean-spiral-layout

An algorithm that can be used to place items collision-free within a bounding box that contains obstacles.
JavaScript
2
star