Ost React Native Wallet SDK is the official Ost Wallet SDK for react-native platform. The SDK is a mobile application development SDK that enables developers to integrate the functionality of a non-custodial crypto-wallet into consumer applications.
Ost React Native Wallet SDK...
- Safely generates and stores keys on the user's mobile device
- Signs ethereum transactions and data as defined by contracts using EIP-1077
- Enables users to recover access to their Brand Tokens in case the user loses their authorized device
- Installing React-native SDK
- Migrating to another version
- SDK Usage
- Getter Methods
- Ost JSON APIs
- Quick Start Guide - Ost Macro Workflows
- Intermediate Usage - Ost Wallet SDK UI
- Advance Usage - Ost Wallet Core Workflow APIs
- Known Issues
- Install React Native and create a react-native project
Follow this official react-native getting started guide to install react native and create a react-native project
- Install Ost React Native SDK in your project The sdk needs following peer dependencies:
npm install --save lodash.merge
npm install --save eventemitter3
npm install --save bignumber.js
Run following command in your react-native project root
npm install --save @ostdotcom/ost-wallet-sdk-react-native
- Linking the Ost React Native SDK with your project
react-native link @ostdotcom/ost-wallet-sdk-react-native
If you decide to change the SDK version, please make sure to update the downsteam native SDKs.
For Android, please run:
react-native link
react-native run-android
For iOS, please update the ios/Cartfile
with desired version and run:
carthage update --cache-builds --platform ios
After updating the SDK, please delete ostwalletrnsdk
using the Remove References option and add it back by following this step.
- Initialize the SDK
- Subscribe to events
- Implement
OstWalletWorkFlowCallback
for a workflow - Execute workflow
You must initialize the SDK before using it.
Initialize the SDK in using BASE_URL (Ost Platform endpoint) inside App.js
constructor()
method.
/**
* Initialize wallet sdk
* @param {String} endpoint - Ost Platform endpoint
* @param {function} Callback function with error and success status.
* @public
*/
OstWalletSdk.initialize( endpoint,
(error, success) => {})
Starting version 2.3.1
application can also pass SDK config in the initialize method
If config is passed in
initialize
method, the configs specified inOstWalletSdk.plist
andost-mobilesdk.json
are ignored. It is no longer mandatory to defineost-mobilesdk.json
andOstWalletSdk.plist
files.
let sdkConfig = {
"BLOCK_GENERATION_TIME": 3,
"PIN_MAX_RETRY_COUNT": 3,
"REQUEST_TIMEOUT_DURATION": 60,
"SESSION_BUFFER_TIME": 3600,
"PRICE_POINT_CURRENCY_SYMBOL": "USD",
"USE_SEED_PASSWORD": false,
"NO_OF_SESSIONS_ON_ACTIVATE_USER": 1,
"ENABLE_IOS_DEVICE_RESTORE": false
};
/**
* Initialize wallet sdk
* @param {String} endpoint - Ost Platform endpoint
* @param {Object} config (optional) - SDK Config. Supported from version 2.3.1
* @param {function} callback - A typical node-style, error-first callback.
* @callback params {Object}error , {Boolean} success
* @public
*/
OstWalletSdk.initialize( endpoint, sdkConfig, (error, success) => {
});
In the most top level component (mostly App.js
) import like this:
import { OstWalletSdkEvents, OstWalletSdk, OstWalletSdkUI, OstJsonApi } from '@ostdotcom/ost-wallet-sdk-react-native';
In componentDidMount()
subscribe to OstWalletSdkEvents and in componentWillUnmount()
unsubscribe to OstWalletSdkEvents. Also initialize the SDK in using BASE_URL (Ost Platform endpoint) constructor()
method:
class App extends Component {
constructor() {
super();
OstWalletSdk.initialize(BASE_URL, (error, success) => {
if(error) {
console.warn(error);
}
else {
console.warn(success);
}
});
}
componentDidMount() {
OstWalletSdkEvents.subscribeEvent();
}
componentWillUnmount() {
OstWalletSdkEvents.unsubscribeEvent();
}
}
The SDK provides getter methods that applications can use for various purposes. These methods provide the application with data as available in the device's database. Please refer to Ost Wallet SDK Getter Methods for documentation.
While the getter methods provide application with data stored in device's database, the JSON API methods make API calls to Ost Platform servers. Please refer to Ost JSON API for documentation.
Starting version 2.3.12-beta.1, developers can enable all the Ost wallet features implementing the Ost Macro Workflows.
The setup device workflow establishes trust between the device and Ost Platform. As application is responsible for user authentication, application servers must facilitate this workflow using the server side sdk.
- When this workflow is initiated by the application, the Sdk creates the following keys:
- API key - the key used to sign API requests sent to Ost Platform from the sdk.
- Device key - the user's wallet device key. All device manager operations shall be performed using this key.
- The Sdk asks the application to register the device entity with Ost Platform.
- The application must send the device entity to the application server.
- The application server must then use the server side sdk to register the device with Ost Plaform by using device service's create device Api.
- Once the device is registered by the Ost Platform, the application server must send the response to the mobile application.
- The mobile application must then use the
deviceRegistered
callbacks to provide the response to the Sdk. - The sdk validates the registration by making Api calls to the Ost Plaform.
- Setup device workflow must be initiated on every app launch.
- Setup device workflow must be initiated only after the user has been autheniticated by the application, including cookie based authentication for already logged-in users.
- Each of user’s device creates its own API key and device key.
- User’s Device and API keys are not shared across devices.
- User’s API key & device key are stored in persistent storage on the device and created only if needed.
- The Sdk shall request for device registration only when needed.
registerDevice
shall not be invoked if device is already authorized and sdk is able to make Api calls to Ost Platform.
Please refer to setupDevice
core workflow documentation for implementation details.
Activate User workflow deploys user's wallet on the blockchain and whitelists the user's wallet and enables it to take part in application's brand token economy.
- Deploys user’s contracts
- Device-manager and token-holder contracts
- Set user’s recovery key address, device key address in device-manager contract
- Authorizes session key(s) in token-holder contract
- Whitelists user’s contract in UBT (Utility Brand Token Contract).
- User's recovery key is generated using SCrypt, a password-based key derivation function.
- The ‘password’ provided to this function is a string created by concatenating:
- A prefix provided by application server.
Application server must generate and store prefix for each user, treat it as sensitive and immutable information.
- User’s PIN
- User’s Ost-id
- The salt required for SCrypt is provided by Ost Platform
Please refer to Activate User UI Workflow Documentation for implementation details.
OstWallet Settings is a pre-built UI component available exclusively available in ost-wallet-sdk-react-native
SDK.
It is a wallet settings page that can be used by end-users to perfrom 12 different wallet operations and view their wallet details.
IMPORTANT: This feature requires application to use React Navigation package.
Please refer to OstWallet Settings Documentation for implementation details.
OstRedemption component is a pre-built UI component available exclusively in ost-wallet-sdk-react-native
SDK.
It consist two pages - one displaying redeemable product list and another displaying product details and redemption options. It can be used by end-users to integrate redemption flow into their app.
IMPORTANT: This feature requires application to use React Navigation package.
Please reder to OstRedemption flow Documentation for implementation details.
OstTransactionHelper
is a transaction helper provided by the SDK that creates session keys before performing a transaction if needed. App developers can configure the session creation parameters (session buckets) as per application's need.
Please refer to Ost Transaction Helper Documentation for implementation details.
For quick and easy integration with SDK, developers can use built-in user-interface components which are configurable and support content and theme customization.
Please refer to Ost Wallet SDK UI for documentation.
Ost core workflows API do not use any UI components, thereby giving complete ux control to the developers. The OstWalletSdkUI
also uses Ost core workflows.
Please refer to Ost Core Workflow APIs for documentation.
Starting with Android 9 (API level 28), cleartext support is disabled by default. On the other hand, Ost Wallet Android Sdk leverages on Public Key Pinning to ensure the authenticity of a Ost Platform server's public key used in TLS sessions using TrustKit. As TrustKit can only be inititialized with application's network security configuration, sdk initialization fails. To work-around this issues, application needs to have TrustKit as a dependency and initialize it.
Ost Wallet Sdk uses iOS's Keychain to store user's cryptographic keys. Unfortunately, Keychain doesn't work as expected on iOS-13 Simulators. We request you to kindly test your application on actual iOS-13 device while we continue to look for a workaround.