@cruxpay/rn-sdk
v0.0.4
Published
CruxPay React Native SDK
Downloads
7
Readme
Using bundled version in React Native
After installing @cruxpay/rn-sdk
, you will need to
- Install and link
react-native-get-random-values
which works as a polyfill for the global crypto.getRandomValues - Next, you will have to install and link
@react-native-community/async-storage
so that you can use the RNLocalStorage implementation ofstorage.StorageService
as shown below.
// RNLocalStorage.js
import { CruxPay } from "@cruxpay/rn-sdk/dist/cruxpay-sdk-rn";
import AsyncStorage from "@react-native-community/async-storage";
class RNLocalStorage extends CruxPay.storage.StorageService {
setItem = async (key, value) => AsyncStorage.setItem(key, value);
getItem = async (key) => AsyncStorage.getItem(key);
}
export {RNLocalStorage};
- You can then use the sdk by providing an instance of
RNLocalStorage
as storage option and importingreact-native-get-random-values
before importingdist/cruxpay-sdk-rn.js
(the bundled version of installed sdk)
import 'react-native-get-random-values'; // NOTE: necessary to imported first so that it can polyfill global crypto.getRandomValues
import {CruxPay} from "@cruxpay/rn-sdk/dist/cruxpay-sdk-rn"; // NOTE: this is from dist folder
import {RNLocalStorage} from "./RNLocalStorage";
const storage = new RNLocalStorage();
let cruxClientOptions = {
getEncryptionKey: () => 'fookey',
walletClientName: 'cruxdev',
storage: storage
}
const cruxClient = new CruxPay.CruxClient(cruxClientOptions);
cruxClient.init().then(() => {
console.log('CruxClient initialized');
}).catch((err) => {
console.log('CruxClient error', err);
})
Using bundled version in React Native
After installing @cruxpay/rn-sdk
, you will need to
- Install rn-nodeify which allows you to use node builtins in React Native.
npm install --save-dev rn-nodefiy
- Hack the specific builtins required via:
./node_modules/.bin/rn-nodeify --install "process,path,crypto,assert,stream,events,url,vm" —hack @cruxpay/rn-sdk
- Next, you will have to install and link
@react-native-community/async-storage
so that you can use the RNLocalStorage implementation ofstorage.StorageService
as shown below.
npm install --save @react-native-community/async-storage
react-native link @react-native-community/async-storage
// RNLocalStorage.js
import { CruxPay } from "@cruxpay/rn-sdk";
import AsyncStorage from "@react-native-community/async-storage";
class RNLocalStorage extends CruxPay.storage.StorageService {
setItem = async (key, value) => AsyncStorage.setItem(key, value);
getItem = async (key) => AsyncStorage.getItem(key);
}
export {RNLocalStorage};
- You can then use the sdk by providing an instance of
RNLocalStorage
as storage option and importingshim.js
before importing@cruxpay/rn-sdk
import './shim.js'; // NOTE: necessary to imported first so that it can polyfill the node builtins
import {CruxPay} from "@cruxpay/rn-sdk";
import {RNLocalStorage} from "./RNLocalStorage";
let cruxClientOptions = {
getEncryptionKey: () => 'fookey',
walletClientName: 'cruxdev',
storage: new RNLocalStorage()
}
const cruxClient = new CruxPay.CruxClient(cruxClientOptions);
cruxClient.init().then(() => {
console.log('CruxClient initialized');
}).catch((err) => {
console.log('CruxClient error', err);
})
Refer to the documentation at @cruxprotocol/js-sdk