Skip to content

Commit

Permalink
Merge pull request #3 from autonomy-system/features/encrypt-file
Browse files Browse the repository at this point in the history
Encrypt & Decrypt file
  • Loading branch information
hungqd authored Sep 20, 2022
2 parents edd3354 + 5c903b6 commit 3ab410b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies {
implementation 'io.reactivex.rxjava2:rxjava:2.2.10'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'

implementation('com.github.bitmark-inc:libauk-kotlin:0.2.0') {
implementation('com.github.bitmark-inc:libauk-kotlin:0.2.1') {
exclude group: 'com.google.protobuf'
exclude module: 'jetified-protobuf-java'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import org.web3j.crypto.RawTransaction
import java.io.File
import java.math.BigInteger
import java.util.*

Expand Down Expand Up @@ -63,6 +66,12 @@ class LibAukDartPlugin : FlutterPlugin, MethodCallHandler {
"signTransaction" -> {
signTransaction(call, result)
}
"encryptFile" -> {
encryptFile(call, result)
}
"decryptFile" -> {
decryptFile(call, result)
}
"exportMnemonicWords" -> {
exportMnemonicWords(call, result)
}
Expand Down Expand Up @@ -278,6 +287,44 @@ class LibAukDartPlugin : FlutterPlugin, MethodCallHandler {
.let { disposables.add(it) }
}

private fun encryptFile(call: MethodCall, result: Result) {
val id: String? = call.argument("uuid")
val inputPath: String = call.argument("inputPath") ?: ""
val outputPath: String = call.argument("outputPath") ?: ""
LibAuk.getInstance().getStorage(UUID.fromString(id), context)
.encryptFile(File(inputPath), File(outputPath))
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
val rev: HashMap<String, Any> = HashMap()
rev["error"] = 0
rev["msg"] = "Encrypt file success"
rev["data"] = outputPath
result.success(rev)
}, { error ->
result.error("Encrypt file failed", error.message, error)
}).let { disposables.add(it) }
}

private fun decryptFile(call: MethodCall, result: Result) {
val id: String? = call.argument("uuid")
val inputPath: String = call.argument("inputPath") ?: ""
val outputPath: String = call.argument("outputPath") ?: ""
LibAuk.getInstance().getStorage(UUID.fromString(id), context)
.decryptFile(File(inputPath), File(outputPath))
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
val rev: HashMap<String, Any> = HashMap()
rev["error"] = 0
rev["msg"] = "Decrypt file success"
rev["data"] = outputPath
result.success(rev)
}, { error ->
result.error("Decrypt file failed", error.message, error)
}).let { disposables.add(it) }
}

private fun exportMnemonicWords(call: MethodCall, result: Result) {
val id: String? = call.argument("uuid")
LibAuk.getInstance().getStorage(UUID.fromString(id), context)
Expand Down
24 changes: 24 additions & 0 deletions lib/libauk_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,30 @@ class WalletStorage {
return res["data"];
}

Future<String> encryptFile({
required String inputPath,
required String outputPath,
}) async {
Map res = await _channel.invokeMethod('encryptFile', {
"uuid": uuid,
"inputPath": inputPath,
"outputPath": outputPath,
});
return res["data"];
}

Future<String> decryptFile({
required String inputPath,
required String outputPath,
}) async {
Map res = await _channel.invokeMethod('decryptFile', {
"uuid": uuid,
"inputPath": inputPath,
"outputPath": outputPath,
});
return res["data"];
}

Future<String> exportMnemonicWords() async {
Map res =
await _channel.invokeMethod('exportMnemonicWords', {"uuid": uuid});
Expand Down

0 comments on commit 3ab410b

Please sign in to comment.