rn-indy-sdk v0.1.11
React Native Indy SDK
React Native Indy SDK wrapper.
Installation
with npm:
$ npm install rn-indy-sdk --save
with Yarn:
$ yarn add rn-indy-sdk
Link (for React Native lower than 0.60)
$ react-native link rn-indy-sdk
Android
See https://github.com/TimoGlastra/ExampleRnIndySDK for an example android react native project that follows this tutorial.
1. Set min SDK version
Make sure there is a min. SDK version setup in android/build.gradle:
buildscript {
ext {
...
minSdkVersion = 21
...
}
}2. Add Sovrin Maven repository
Add Sovrin Maven repository into android/build.gradle:
allprojects {
repositories {
...
maven {
url 'https://repo.sovrin.org/repository/maven-public'
}
...
}
}3. Add JNA library dependency
Add to android/app/build.gradle:
dependencies {
// ...
implementation 'net.java.dev.jna:jna:5.2.0'
// ...
}4. Add Android libindy binaries
Download Android libindy binaries and copy them into android/app/src/main/jniLibs.
- Create
android/app/src/main/jniLibsdirectory in your project - Create subdirectories
arm64-v8a,armeabi-v7a,x86andx86_64insideandroid/app/src/main/jniLibs. - Download the required libindy binaries for your release-channel and version
- with
stablechannel and version1.15.0base url will be https://repo.sovrin.org/android/libindy/stable/1.15.0/ - download the binaries for
arm64,armv7,x86andx86_64, e.g.:libindy_android_arm64_1.15.0.ziplibindy_android_armv7_1.15.0.ziplibindy_android_x86_1.15.0.ziplibindy_android_x86_64_1.15.0.zip
- with
- Extract all downloaded ZIP files and copy
libindy.sofiles to correspondingjniLibsdirectorylibindy_arm64/lib/libindy.sotojniLibs/arm64-v8a/libindy.solibindy_armv7/lib/libindy.sotojniLibs/armeabi-v7a/libindy.solibindy_x86/lib/libindy.sotojniLibs/x86/libindy.solibindy_x86_64/lib/libindy.sotojniLibs/x86_64/libindy.so
- Download the required JNA binaries from the JNA GitHub repo
- libindy version 1.15.0 works with version 5.5.0 of JNA. In this case the base url is: https://github.com/java-native-access/jna/tree/5.5.0/lib/native
- download the binaries for
aarch64,armv7,x86,x86-64, e.g.:android-aarch64.jarandroid-armv7.jarandroid-x86-64.jarandroid-x86.jar
- Extract all downloaded JAR files and copy
libjnidispatch.soto correspondingjniLibsdirectory- You can extract the
.sofile from the jar using thejarcommand. e.g.jar xf android-x86.jar libjnidispatch.sofromandroid-aarch64.jartojniLibs/arm64-v8a/libjnidispatch.solibjnidispatch.sofromandroid-armv7.jartojniLibs/armeabi-v7a/libjnidispatch.solibjnidispatch.sofromandroid-x86.jartojniLibs/x86/libjnidispatch.solibjnidispatch.sofromandroid-x86-64.jartojniLibs/x86_64/libjnidispatch.so
- You can extract the
5. Load indy library
Add the following to MainActivity.java:
//...
import android.os.Bundle;
import android.system.ErrnoException;
import android.system.Os;
import java.io.File;
public class MainActivity extends ReactActivity {
//...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
Os.setenv("EXTERNAL_STORAGE", getExternalFilesDir(null).getAbsolutePath(), true);
System.loadLibrary("indy");
} catch (ErrnoException e) {
e.printStackTrace();
}
}
}iOS
- Install CocoaPods dependencies:
pod install --project-directory=ios/Create
Frameworksfolder in your project'sios/Podsdirectory and copyIndy.frameworkinto that directory.Optional Most projects have
ios/Podsignored in their.gitignore. This is good practice, however this means the framework would need to be added after every clone. To prevent this you can "unignore" the Frameworks directory:
ios/Pods/
!ios/Pods/Frameworks- Add
Indy.frameworkas dependency into your project. Open.xcworkspacefile in Xcode and in your project settings, tab General, section Frameworks, Libraries, and Embedded Content, click on plus. Then select Add Other -> Add files... and navigate toIndy.frameworkfile on your disk.
Beware that the Indy SDK repository does not have the "Build Libraries for Distribution" enabled by default. If that setting is disabled the version of Swift your project uses must be the same as the version of Swift used to compile
Indy.framework. From Swift 5.0 onwards, building the library with that setting enabled will allow to use anIndy.frameworkbuild that is compiled with a different version of Swift as your project. See https://stackoverflow.com/a/63305234/10552895 for more info.
Usage
import indy from 'rn-indy-sdk'
await indy.createWallet({ id: 'wallet-123' }, { key: 'key' })You can see example project here https://github.com/jakubkoci/UseReactNativeIndySdk/. It currently shows only usage on Android.
Known Errors
Add setup of external storage permissions (Android)
I found an error with permission while calling createWallet when I was testing this package:
2020-01-27 16:25:02.300 9955-10044/com.usereactnativeindysdk E/log_panics: thread 'unnamed' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }': libcore/result.rs:945Modify onCreate method in MainActivity of your project where you want to use this library in a following way:
public class MainActivity extends ReactActivity {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
...
File externalFilesDir = getExternalFilesDir(null);
String path = externalFilesDir.getAbsolutePath();
System.out.println("externalFilesDir=" + path);
try {
Os.setenv("EXTERNAL_STORAGE", path, true);
} catch (ErrnoException e) {
e.printStackTrace();
}
...
}
...
}This should resolve the issue with permissions.