This is the repository for the mobile React Native SDK for Wallet-as-a-Service APIs. It exposes a subset of the WaaS APIs to the mobile developer and, in particular, is required for the completion of MPC operations such as Seed generation and Transaction signing.
For iOS development:
For Android development:
With npm
:
npm install --save @coinbase/waas-sdk-react-native
With yarn
:
yarn add @coinbase/waas-sdk-react-native
In your Android application's settings.gradle
file, make sure to add the following:
include ":android-native", ":android-native:go-internal-sdk", ":android-native:mpc-sdk"
project(':android-native').projectDir = new File(rootProject.projectDir, '../node_modules/@coinbase/waas-sdk-react-native/android-native')
project(':android-native:mpc-sdk').projectDir = new File(rootProject.projectDir, '../node_modules/@coinbase/waas-sdk-react-native/android-native/mpc-sdk')
project(':android-native:go-internal-sdk').projectDir = new File(rootProject.projectDir, '../node_modules/@coinbase/waas-sdk-react-native/android-native/go-internal-sdk')
See index.tsx for the list of supported APIs.
This repository provides an example app that demonstrates how the APIs should be used.
NOTE: An example Cloud API Key json file is at
example/src/.coinbase_cloud_api_key.json
To run the example app, populate, or replace, this file with the Cloud API Key file provided to you by Coinbase.
To run the example app using proxy-mode
:
localhost:8091
.proxyUrl
in the config.json
file accordingly.Proxy Mode
from the Mode Selection screen.To run the example app using direct-mode
:
.coinbase_cloud_api_key.json
file with your personal API credentials.Direct Mode
from the Mode Selection screen.Ensure you have XCode open and run the following from the root directory of the repository:
yarn bootstrap # Install packages for the root and /example directories
yarn example start # Start the Metro server
yarn example ios --simulator "iPhone 14" # Build and start the app on iOS simulator
NOTE: To build an app that depends on the WaaS SDK, you'll also need a compatible version of OpenSSL. You can build the OpenSSL framework by running the following on your Mac from the root of this repository:
yarn ssl-ios
You can alternatively depend on an open-compiled version of OpenSSL, like OpenSSL-Universal, by adding the following to your app's Podfile:
pod "OpenSSL-Universal"
Ensure you have the following Android environment variables set correctly:
ANDROID_HOME
ANDROID_SDK_ROOT="${ANDROID_HOME}"
ANDROID_NDK_HOME="${ANDROID_HOME}/ndk/<insert ndk version>"
ANDROID_NDK_ROOT="${ANDROID_NDK_HOME}"
And then export the following to your PATH
:
export PATH="${ANDROID_HOME}/emulator:${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools:${PATH}"
Run the following from the root directory of the repository:
yarn install # Install packages for the root directory
emulator -avd Pixel_5_API_31 # Use any x86_64 emulator with min SDK version: 30.
yarn example start # Start the Metro server
yarn example android # Build and start the app on Android emulator
By following the above steps, you should be able to run the example app either in proxy-mode or direct-mode based on your preference and setup.
Broadly speaking, there are two possible approaches to using the WaaS SDK:
Of these two approaches, we recommend approach #2, as outlined in the following diagram:
The motivation for placing a proxy server in between your application and the WaaS backends are as follows:
In short, having a proxy server that you control in between your application and the WaaS backends will afford you significantly more control than using the WaaS backends directly in most cases.
The methods from the WaaS SDK which are required to be used for participation in MPC are:
initMPCSdk
bootstrapDevice
getRegistrationData
computeMPCOperation
Users can switch between two distinct operating modes: proxy-mode
and direct-mode
.
Proxy-mode allows the application to connect to the Coinbase WaaS API through a proxy server. The primary features of this mode include:
localhost:8091
. Update this proxyUrl
in the config.json
file.Direct-mode enables the app to connect directly to the Coinbase WaaS API, bypassing the need for a proxy server. Key aspects of this mode are:
.coinbase_cloud_api_key.json
file.We expose a Java 8+, java.util.concurrent.Future
-based SDK for use with Java/Kotlin. An example
app is included in android-native-example/
for more information.
settings.gradle
to not fail on project repos.repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
)To begin, place the android-native
directory relative to your project.
In your settings.gradle
, include the following:
include ':android-native', ':android-native:mpc-sdk', ':android-native:go-internal-sdk'
project(':android-native').projectDir = new File(rootProject.projectDir, '../android-native')
project(':android-native:mpc-sdk').projectDir = new File(rootProject.projectDir, '../android-native/mpc-sdk')
project(':android-native:go-internal-sdk').projectDir = new File(rootProject.projectDir, '../android-native/go-internal-sdk')
Remember to specify the correct relative-location of android-native
.
In your build.gradle
, you should now take dependencies on
implementation project(":android-native")
implementation project(':android-native:mpc-sdk')
implementation project(':android-native:go-internal-sdk')
A demo app of the native SDK is included in android-native/
. Opening this directory with Android Studio should be
sufficient to build and run the app.