Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #61 from kinecosystem/DP-217_error_loading_libsodium
Browse files Browse the repository at this point in the history
DP-217 - initialize native libsodium lazily
  • Loading branch information
yosriz authored Dec 20, 2018
2 parents 0f1031d + 25e1b5c commit f39fcae
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
15 changes: 10 additions & 5 deletions kin-core/src/main/java/kin/core/BackupRestoreImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ class BackupRestoreImpl implements BackupRestore {
private static final int SALT_LENGTH_BYTES = 16;
private static final int HASH_LENGTH_BYTES = 32;
private static final int OUPUT_JSON_INDENT_SPACES = 2;

BackupRestoreImpl() {
//init sodium
NaCl.sodium();
}
private boolean initialized = false;

@Override
@NonNull
public String exportWallet(@NonNull KeyPair keyPair, @NonNull String passphrase)
throws CryptoException {
initIfNeeded();
byte[] saltBytes = generateRandomBytes(SALT_LENGTH_BYTES);

byte[] passphraseBytes = stringToUTF8ByteArray(passphrase);
Expand All @@ -41,10 +38,18 @@ public String exportWallet(@NonNull KeyPair keyPair, @NonNull String passphrase)
return jsonify(keyPair.getAccountId(), salt, seed);
}

private void initIfNeeded() {
if (!initialized) {
NaCl.sodium();
initialized = true;
}
}

@Override
@NonNull
public KeyPair importWallet(@NonNull String exportedJson, @NonNull String passphrase)
throws CryptoException, CorruptedDataException {
initIfNeeded();
AccountJson accountJson = stringify(exportedJson);

byte[] passphraseBytes = stringToUTF8ByteArray(passphrase);
Expand Down
44 changes: 44 additions & 0 deletions run_integ_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
if [ -z "$1" ]
then
echo "Please specify AVD name to test on."
exit 1
fi

git clone https://github.com/kinecosystem/blockchain-ops.git
cd blockchain-ops
git checkout c26afdc168ad378363c63fb44de5a93b3cf24ddf
cd image
./init.sh
cd ../..
~/Library/Android/sdk/tools/emulator -avd $1 &

#wait for emulator
set +e

bootanim=""
failcounter=0
timeout_in_sec=360

until [[ "$bootanim" =~ "stopped" ]]; do
bootanim=`adb -e shell getprop init.svc.bootanim 2>&1 &`
if [[ "$bootanim" =~ "device not found" || "$bootanim" =~ "device offline"
|| "$bootanim" =~ "running" ]]; then
let "failcounter += 1"
echo "Waiting for emulator to start"
if [[ $failcounter -gt timeout_in_sec ]]; then
echo "Timeout ($timeout_in_sec seconds) reached; failed to start emulator"
exit 1
fi
fi
sleep 1
done

echo "Emulator is ready"
#---------------------
./gradlew jacocoTestReport
if [ $? -eq 0 ]; then
open kin-core/build/reports/jacoco/jacocoTestReport/html/index.html
else
echo Build failed!
fi

0 comments on commit f39fcae

Please sign in to comment.