From 629019ad85daca4ba165379b2c926ba1d9676868 Mon Sep 17 00:00:00 2001 From: Umair Sarfraz Date: Thu, 18 Jun 2020 07:30:27 +0500 Subject: [PATCH] feat: update build scripts for pearl-driver-react-native (#501) --- packages/pearl-diver-react-native/.gitignore | 1 + .../org/iota/PearlDiver/PearlDiverModule.java | 2 +- .../main/java/org/iota/mobile/Interface.java | 5 +- .../Headers/Interface.h | 9 +-- .../pearl-diver-react-native/ios/PearlDiver.m | 60 +------------------ .../pearl-diver-react-native/ios/bindings.h | 24 -------- .../scripts/build-android.sh | 13 ++-- .../scripts/build-ios.sh | 11 ++-- 8 files changed, 15 insertions(+), 110 deletions(-) delete mode 100644 packages/pearl-diver-react-native/ios/bindings.h diff --git a/packages/pearl-diver-react-native/.gitignore b/packages/pearl-diver-react-native/.gitignore index 7455071d8..ad3c6866f 100644 --- a/packages/pearl-diver-react-native/.gitignore +++ b/packages/pearl-diver-react-native/.gitignore @@ -1,5 +1,6 @@ entangled android/src/main/jniLibs +iota_common # OSX # diff --git a/packages/pearl-diver-react-native/android/src/main/java/org/iota/PearlDiver/PearlDiverModule.java b/packages/pearl-diver-react-native/android/src/main/java/org/iota/PearlDiver/PearlDiverModule.java index 9c771e81a..03c49fae9 100644 --- a/packages/pearl-diver-react-native/android/src/main/java/org/iota/PearlDiver/PearlDiverModule.java +++ b/packages/pearl-diver-react-native/android/src/main/java/org/iota/PearlDiver/PearlDiverModule.java @@ -27,7 +27,7 @@ public void doPOW(final String trytes, final int mwm, final Promise promise) { new GuardedResultAsyncTask(mContext) { @Override protected String doInBackgroundGuarded() { - String nonce = Interface.doPOW(trytes, mwm); + String nonce = Interface.iota_pow_trytes(trytes, mwm); return nonce; } diff --git a/packages/pearl-diver-react-native/android/src/main/java/org/iota/mobile/Interface.java b/packages/pearl-diver-react-native/android/src/main/java/org/iota/mobile/Interface.java index 27930320f..3e0d067b5 100644 --- a/packages/pearl-diver-react-native/android/src/main/java/org/iota/mobile/Interface.java +++ b/packages/pearl-diver-react-native/android/src/main/java/org/iota/mobile/Interface.java @@ -3,8 +3,5 @@ public class Interface { static { System.loadLibrary("dummy"); } - public static native String doPOW(String trytes, int mwm); - public static native String generateAddress(String seed, int index, int security); - public static native String generateSignature(String trytes, int index, int security, String bundleHash); - public static native String getDigest(String trytes); + public static native String iota_pow_trytes(String trytes, int mwm); } diff --git a/packages/pearl-diver-react-native/ios/EntangledKit.framework/Headers/Interface.h b/packages/pearl-diver-react-native/ios/EntangledKit.framework/Headers/Interface.h index de4591435..939cd0a0d 100644 --- a/packages/pearl-diver-react-native/ios/EntangledKit.framework/Headers/Interface.h +++ b/packages/pearl-diver-react-native/ios/EntangledKit.framework/Headers/Interface.h @@ -11,13 +11,6 @@ #include -char* iota_checksum(const char* input, const size_t input_length, - const size_t checksum_length); -char* iota_digest(char const* const trytes); -char* iota_pow(const char* trytes, int mwm); -char* iota_sign_address_gen(const char* seed, const int index, - const int security); -char* iota_sign_signature_gen(const char* seed, const int index, - const int security, const char* bundleHash); +char* iota_pow_trytes(const char* trytes, int mwm); #endif // __MOBILE__IOS_INTERFACE_H_ diff --git a/packages/pearl-diver-react-native/ios/PearlDiver.m b/packages/pearl-diver-react-native/ios/PearlDiver.m index 493b0cc95..416b49cb3 100644 --- a/packages/pearl-diver-react-native/ios/PearlDiver.m +++ b/packages/pearl-diver-react-native/ios/PearlDiver.m @@ -9,72 +9,14 @@ @implementation PearlDiver RCT_EXPORT_MODULE(); -// Checksum - -RCT_EXPORT_METHOD(getChecksum:(NSString *)trytes length:(int)length resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) -{ - char * trytesChars = [trytes cStringUsingEncoding:NSUTF8StringEncoding]; - char * checksum = iota_checksum(trytesChars, strlen(trytesChars), length); - memset_s(trytesChars, strlen(trytesChars), 0, strlen(trytesChars)); - resolve([NSString stringWithFormat:@"%s", checksum]); -} - -// Hashing -RCT_EXPORT_METHOD(getDigest:(NSString *)trytes resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) -{ - char * digest = iota_digest([trytes cStringUsingEncoding:NSUTF8StringEncoding]); - resolve([NSString stringWithFormat:@"%s", digest]); -} - // PoW RCT_EXPORT_METHOD(doPOW:(NSString *)trytes minWeightMagnitude:(int)minWeightMagnitude resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ char * trytesChars = [trytes cStringUsingEncoding:NSUTF8StringEncoding]; - char * nonce = iota_pow(trytesChars, minWeightMagnitude); + char * nonce = iota_pow_trytes(trytesChars, minWeightMagnitude); resolve([NSString stringWithFormat:@"%s", nonce]); }); } - -// Single address generation -RCT_EXPORT_METHOD(generateAddress:(NSString *)seed index:(int)index security:(int)security resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) -{ - char * seedChars = [seed cStringUsingEncoding:NSUTF8StringEncoding]; - char * address = iota_sign_address_gen(seedChars, index, security); - memset_s(seedChars, strlen(seedChars), 0, strlen(seedChars)); - resolve([NSString stringWithFormat:@"%s", address]); -} - -// Multi address generation -RCT_EXPORT_METHOD(generateAddresses:(NSString *)seed index:(int)index security:(int)security total:(int)total resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) -{ - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - char * seedChars = [seed cStringUsingEncoding:NSUTF8StringEncoding]; - NSMutableArray * addresses = [NSMutableArray array]; - int i = 0; - int addressIndex = index; - - do { - char * address = iota_sign_address_gen(seedChars, addressIndex, security); - NSString * addressObj = [NSString stringWithFormat:@"%s", address]; - [addresses addObject:addressObj]; - i++; - addressIndex++; - } while (i < total); - memset_s(seedChars, strlen(seedChars), 0, strlen(seedChars)); - resolve(addresses); - }); -} - -// Signature generation -RCT_EXPORT_METHOD(generateSignature:(NSString *)seed index:(int)index security:(int)security bundleHash:(NSString *)bundleHash resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) -{ - char * seedChars = [seed cStringUsingEncoding:NSUTF8StringEncoding]; - char * bundleHashChars = [bundleHash cStringUsingEncoding:NSUTF8StringEncoding]; - char * signature = iota_sign_signature_gen(seedChars, index, security, bundleHashChars); - memset_s(seedChars, strlen(seedChars), 0, strlen(seedChars)); - resolve(@[[NSString stringWithFormat:@"%s", signature]]); -} - @end diff --git a/packages/pearl-diver-react-native/ios/bindings.h b/packages/pearl-diver-react-native/ios/bindings.h deleted file mode 100644 index 7a3d72649..000000000 --- a/packages/pearl-diver-react-native/ios/bindings.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// Created by Rajiv Shah on 4/6/18. -// Copyright © 2018 IOTA Foundation. All rights reserved. -// -#ifndef __MOBILE_INTERFACE_BINDINGS_H_ -#define __MOBILE_INTERFACE_BINDINGS_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - - char* do_pow(const char* trytes, int mwm); - char* generate_address(const char* seed, const size_t index, - const size_t security); - char* generate_signature(const char* seed, const size_t index, - const size_t security, const char* bundleHash); - -#ifdef __cplusplus -} -#endif - -#endif /* bindings_h */ diff --git a/packages/pearl-diver-react-native/scripts/build-android.sh b/packages/pearl-diver-react-native/scripts/build-android.sh index 29d9fec2d..62ea3ce99 100755 --- a/packages/pearl-diver-react-native/scripts/build-android.sh +++ b/packages/pearl-diver-react-native/scripts/build-android.sh @@ -1,25 +1,22 @@ #!/bin/bash out=bazel-bin/mobile/android -entangled_branch=develop +branch=develop -if [ ! -d entangled ]; then - git clone https://github.com/iotaledger/entangled && cd entangled && git submodule update --init --recursive +if [ ! -d iota_common ]; then + git clone https://github.com/iotaledger/iota_common && cd iota_common && git submodule update --init --recursive else - cd entangled + cd iota_common if [ "$1" == "clean" ]; then bazel clean fi - git fetch origin $entangled_branch:latest && git checkout latest && git submodule update --recursive + git fetch origin $branch:latest && git checkout latest && git submodule update --recursive fi fetched=$? if [ $fetched ]; then - # Checkout to previous version as temporary workaround - git checkout 82ae5baa6af24bf55568a5a8aabb91ac601cdfc5 - bazel build -c opt --fat_apk_cpu='armeabi-v7a,arm64-v8a,x86,x86_64' //mobile/android:dummy && echo A | unzip $out/dummy.apk -d $out/dummy && cp -r $out/dummy/lib/ ../android/src/main/jniLibs fi diff --git a/packages/pearl-diver-react-native/scripts/build-ios.sh b/packages/pearl-diver-react-native/scripts/build-ios.sh index 2dba78d4f..6a0ad53fd 100755 --- a/packages/pearl-diver-react-native/scripts/build-ios.sh +++ b/packages/pearl-diver-react-native/scripts/build-ios.sh @@ -1,19 +1,18 @@ #!/bin/bash out=bazel-bin/mobile/ios -pull=26 -branch=iota-js-ios +branch=develop -if [ ! -d entangled ]; then - git clone https://github.com/iotaledger/entangled && cd entangled && git fetch origin pull/$pull/head:$branch && git checkout $branch && git submodule update --init --recursive +if [ ! -d iota_common ]; then + git clone https://github.com/iotaledger/iota_common && cd iota_common && git submodule update --init --recursive else - cd entangled + cd iota_common if [ "$1" == "clean" ]; then bazel clean fi - git fetch origin pull/$pull/head:$branch && git checkout $branch && git submodule update --recursive + git fetch origin $branch:latest && git checkout latest && git submodule update --recursive fi fetched=$?