Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
feat: update build scripts for pearl-driver-react-native (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
Umair Sarfraz authored Jun 18, 2020
1 parent 54e70fd commit 629019a
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 110 deletions.
1 change: 1 addition & 0 deletions packages/pearl-diver-react-native/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
entangled
android/src/main/jniLibs
iota_common

# OSX
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void doPOW(final String trytes, final int mwm, final Promise promise) {
new GuardedResultAsyncTask<String>(mContext) {
@Override
protected String doInBackgroundGuarded() {
String nonce = Interface.doPOW(trytes, mwm);
String nonce = Interface.iota_pow_trytes(trytes, mwm);
return nonce;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@

#include <stddef.h>

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_
60 changes: 1 addition & 59 deletions packages/pearl-diver-react-native/ios/PearlDiver.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 0 additions & 24 deletions packages/pearl-diver-react-native/ios/bindings.h

This file was deleted.

13 changes: 5 additions & 8 deletions packages/pearl-diver-react-native/scripts/build-android.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 5 additions & 6 deletions packages/pearl-diver-react-native/scripts/build-ios.sh
Original file line number Diff line number Diff line change
@@ -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=$?
Expand Down

0 comments on commit 629019a

Please sign in to comment.