Skip to content

Commit

Permalink
Merge changes from master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
JayceLuong committed Jul 25, 2024
2 parents d1cc7d0 + d43d71a commit 79f5159
Show file tree
Hide file tree
Showing 16 changed files with 634 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ properties.load(project.rootProject.file("local.properties").newDataInputStream(
def SUPPORTED_ARCH = properties.getProperty("arch.processor", "arm64_v8a")
def GROUP_ID = "io.nunchuk.android"
def ARTIFACT_ID = "nativesdk"
def VERSION = "1.1.73"
def VERSION = "1.1.74"

publishing {
publications {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/nunchuk/android/model/BSMSData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.nunchuk.android.model

data class BSMSData(
var version: String = "",
var descriptor: String = "",
var pathRestrictions: String = "",
var firstAddress: String = ""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.nunchuk.android.model

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class DraftRollOverTransaction(
var transaction: Transaction = Transaction(),
var tagIds: Set<Int> = emptySet(),
var collectionIds: Set<Int> = emptySet(),
) : Parcelable
10 changes: 10 additions & 0 deletions src/main/java/com/nunchuk/android/model/PairAmount.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.nunchuk.android.model

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class PairAmount(
var first: Amount = Amount.ZER0,
var second: Amount = Amount.ZER0
) : Parcelable
87 changes: 87 additions & 0 deletions src/main/java/com/nunchuk/android/nativelib/LibNunchukAndroid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import android.nfc.tech.IsoDep
import com.nunchuk.android.exception.NCNativeException
import com.nunchuk.android.model.*
import com.nunchuk.android.model.bridge.WalletBridge
import com.nunchuk.android.type.AddressType
import com.nunchuk.android.type.HealthStatus
import com.nunchuk.android.type.SignerTag
import com.nunchuk.android.type.SignerType
import com.nunchuk.android.type.WalletType

internal const val LIB_NAME = "nunchuk-android"

Expand Down Expand Up @@ -804,6 +806,14 @@ internal class LibNunchukAndroid {
messagesToSign: String,
): String

@Throws(NCNativeException::class)
external fun signHealthCheckMessageTapSignerSignIn(
signer: SingleSigner,
isoDep: IsoDep,
cvc: String,
messagesToSign: String,
): String

@Throws(NCNativeException::class)
external fun signMessageColdCard(derivationPath: String, messagesToSign: String): String

Expand All @@ -816,12 +826,21 @@ internal class LibNunchukAndroid {
@Throws(NCNativeException::class)
external fun getHealthCheckDummyTxMessage(walletId: String, body: String): String

@Throws(NCNativeException::class)
external fun getSignInHealthCheckDummyTxMessage(body: String): String

@Throws(NCNativeException::class)
external fun getDummyTx(walletId: String, message: String): Transaction

@Throws(NCNativeException::class)
external fun getSignInDummyTx(psbt: String): Transaction

@Throws(NCNativeException::class)
external fun getDummyTxByByteArray(walletId: String, fileData: ByteArray): Transaction?

@Throws(NCNativeException::class)
external fun getSignInDummyTxByByteArray(fileData: ByteArray): Transaction?

@Throws(NCNativeException::class)
external fun exportKeystoneDummyTransaction(txToSign: String, density: Int): List<String>

Expand Down Expand Up @@ -1040,6 +1059,74 @@ internal class LibNunchukAndroid {
@Throws(NCNativeException::class)
external fun exportBBQRTransaction(psbt: String, density: Int): List<String>

@Throws(NCNativeException::class)
external fun createSoftwareSignerFromMasterXprv(
name: String,
xprv: String,
isPrimary: Boolean,
replace: Boolean,
): MasterSigner?

@Throws(NCNativeException::class)
external fun isValidXPrv(xprv: String): Boolean

@Throws(NCNativeException::class)
external fun getBip32Path(
walletType: Int,
addressType: Int,
index: Int
): String

@Throws(NCNativeException::class)
external fun parseSignerString(
signerString: String,
): SingleSigner?

@Throws(NCNativeException::class)
external fun estimateRollOverTransactionCount(
walletId: String,
tags: List<CoinTag>,
collections: List<CoinCollection>
): Int

@Throws(NCNativeException::class)
external fun estimateRollOverAmount(
walletId: String,
newWalletId: String,
tags: List<CoinTag>,
collections: List<CoinCollection>,
feeRate: Amount
): PairAmount

@Throws(NCNativeException::class)
external fun draftRollOverTransactions(
walletId: String,
newWalletId: String,
tags: List<CoinTag>,
collections: List<CoinCollection>,
feeRate: Amount
): Array<DraftRollOverTransaction>

@Throws(NCNativeException::class)
external fun createRollOverTransactions(
walletId: String,
newWalletId: String,
tags: List<CoinTag>,
collections: List<CoinCollection>,
feeRate: Amount
): List<Transaction>

@Throws(NCNativeException::class)
external fun exportWalletToPortal(
walletId: String,
): BSMSData?

@Throws(NCNativeException::class)
external fun getAddressIndex(
walletId: String,
address: String,
): Int

companion object {
init {
System.loadLibrary(LIB_NAME)
Expand Down
89 changes: 88 additions & 1 deletion src/main/java/com/nunchuk/android/nativelib/NunchukNativeSdk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,12 @@ class NunchukNativeSdk {
walletType: Int,
addressType: Int,
index: Int,
) = nunchukAndroid.getSignerFromMasterSignerByIndex(masterSignerId, walletType, addressType, index)
) = nunchukAndroid.getSignerFromMasterSignerByIndex(
masterSignerId,
walletType,
addressType,
index
)

@Throws(NCNativeException::class)
fun getSignerFromTapsignerMasterSigner(
Expand Down Expand Up @@ -1036,6 +1041,14 @@ class NunchukNativeSdk {
messagesToSign: String,
) = nunchukAndroid.signHealthCheckMessageTapSigner(isoDep, cvc, signer, messagesToSign)

@Throws(NCNativeException::class)
fun signHealthCheckMessageTapSignerSignIn(
signer: SingleSigner,
isoDep: IsoDep,
cvc: String,
messagesToSign: String,
) = nunchukAndroid.signHealthCheckMessageTapSignerSignIn(signer, isoDep, cvc, messagesToSign)

@Throws(NCNativeException::class)
fun signMessageColdCard(derivationPath: String, messagesToSign: String) =
nunchukAndroid.signMessageColdCard(derivationPath, messagesToSign)
Expand All @@ -1054,9 +1067,17 @@ class NunchukNativeSdk {
@Throws(NCNativeException::class)
fun getDummyTx(walletId: String, message: String) = nunchukAndroid.getDummyTx(walletId, message)

@Throws(NCNativeException::class)
fun getSignInDummyTx(message: String) = nunchukAndroid.getSignInDummyTx(message)

@Throws(NCNativeException::class)
fun getDummyTxByByteArray(walletId: String, fileData: ByteArray) =
nunchukAndroid.getDummyTxByByteArray(walletId, fileData)

@Throws(NCNativeException::class)
fun getSignInDummyTxByByteArray(fileData: ByteArray) =
nunchukAndroid.getSignInDummyTxByByteArray(fileData)

@Throws(NCNativeException::class)
fun exportKeystoneDummyTransaction(txToSign: String, density: Int) =
nunchukAndroid.exportKeystoneDummyTransaction(txToSign, density)
Expand Down Expand Up @@ -1297,4 +1318,70 @@ class NunchukNativeSdk {
@Throws(NCNativeException::class)
fun exportBBQRTransaction(psbt: String, density: Int) =
nunchukAndroid.exportBBQRTransaction(psbt, density)

@Throws(NCNativeException::class)
fun createSoftwareSignerFromMasterXprv(
name: String,
xprv: String,
isPrimary: Boolean,
replace: Boolean,
) = nunchukAndroid.createSoftwareSignerFromMasterXprv(name, xprv, isPrimary, replace)

@Throws(NCNativeException::class)
fun isValidXPrv(xprv: String) = nunchukAndroid.isValidXPrv(xprv)

@Throws(NCNativeException::class)
fun getBip32Path(
walletType: WalletType,
addressType: AddressType,
index: Int
) = nunchukAndroid.getBip32Path(walletType.ordinal, addressType.ordinal, index)

@Throws(NCNativeException::class)
fun parseSignerString(xpub: String) = nunchukAndroid.parseSignerString(xpub)

@Throws(NCNativeException::class)
fun estimateRollOverTransactionCount(
walletId: String,
tags: List<CoinTag>,
collections: List<CoinCollection>
) = nunchukAndroid.estimateRollOverTransactionCount(walletId, tags, collections)

@Throws(NCNativeException::class)
fun estimateRollOverAmount(
walletId: String,
newWalletId: String,
tags: List<CoinTag>,
collections: List<CoinCollection>,
feeRate: Amount
) = nunchukAndroid.estimateRollOverAmount(walletId, newWalletId, tags, collections, feeRate)

@Throws(NCNativeException::class)
fun draftRollOverTransactions(
walletId: String,
newWalletId: String,
tags: List<CoinTag>,
collections: List<CoinCollection>,
feeRate: Amount
) = nunchukAndroid.draftRollOverTransactions(walletId, newWalletId, tags, collections, feeRate)

@Throws(NCNativeException::class)
fun createRollOverTransactions(
walletId: String,
newWalletId: String,
tags: List<CoinTag>,
collections: List<CoinCollection>,
feeRate: Amount
) = nunchukAndroid.createRollOverTransactions(walletId, newWalletId, tags, collections, feeRate)

@Throws(NCNativeException::class)
fun exportWalletToPortal(
walletId: String,
) = nunchukAndroid.exportWalletToPortal(walletId)

@Throws(NCNativeException::class)
fun getAddressIndex(
walletId: String,
address: String,
) = nunchukAndroid.getAddressIndex(walletId, address)
}
3 changes: 2 additions & 1 deletion src/main/java/com/nunchuk/android/type/SignerType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ enum class SignerType {
FOREIGN_SOFTWARE,
NFC,
COLDCARD_NFC,
SERVER
SERVER,
PORTAL_NFC
}
72 changes: 72 additions & 0 deletions src/main/native/deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,26 @@ jobject Deserializer::convert2JCoinStatus(JNIEnv *env, const CoinStatus &status)
return env->CallStaticObjectMethod(clazz, staticMethod, (int) status);
}

jobject Deserializer::convert2JBSMSData(JNIEnv *env, const BSMSData &data) {
syslog(LOG_DEBUG, "[JNI] convert2JBSMSData()");
jclass clazz = env->FindClass("com/nunchuk/android/model/BSMSData");
jmethodID constructor = env->GetMethodID(clazz, "<init>", "()V");
jobject instance = env->NewObject(clazz, constructor);
try {
env->CallVoidMethod(instance, env->GetMethodID(clazz, "setVersion", "(Ljava/lang/String;)V"),
env->NewStringUTF(data.version.c_str()));
env->CallVoidMethod(instance, env->GetMethodID(clazz, "setDescriptor", "(Ljava/lang/String;)V"),
env->NewStringUTF(data.descriptor.c_str()));
env->CallVoidMethod(instance, env->GetMethodID(clazz, "setPathRestrictions", "(Ljava/lang/String;)V"),
env->NewStringUTF(data.path_restrictions.c_str()));
env->CallVoidMethod(instance, env->GetMethodID(clazz, "setFirstAddress", "(Ljava/lang/String;)V"),
env->NewStringUTF(data.first_address.c_str()));
} catch (const std::exception &e) {
syslog(LOG_DEBUG, "[JNI] convert2JSigner error::%s", e.what());
}
return instance;
}

jobject Deserializer::convert2JMasterSigner(JNIEnv *env, const MasterSigner &signer) {
syslog(LOG_DEBUG, "[JNI] convert2JMasterSigner()");
jclass clazz = env->FindClass("com/nunchuk/android/model/MasterSigner");
Expand Down Expand Up @@ -1080,3 +1100,55 @@ Deserializer::convert2JCollectionUnspentOutputs(JNIEnv *env,
return arrayListInstance;
}

jobject Deserializer::convert2JPairAmount(JNIEnv *env, const std::pair<Amount, Amount> &pair) {
syslog(LOG_DEBUG, "[JNI] convert2JPairAmount()");
jclass clazz = env->FindClass("com/nunchuk/android/model/PairAmount");
jmethodID constructor = env->GetMethodID(clazz, "<init>", "()V");
jobject instance = env->NewObject(clazz, constructor);
try {
env->CallVoidMethod(instance, env->GetMethodID(clazz, "setFirst",
"(Lcom/nunchuk/android/model/Amount;)V"),
convert2JAmount(env, pair.first));
env->CallVoidMethod(instance, env->GetMethodID(clazz, "setSecond",
"(Lcom/nunchuk/android/model/Amount;)V"),
convert2JAmount(env, pair.second));
} catch (const std::exception &e) {
syslog(LOG_DEBUG, "[JNI] convert2JPairAmount error::%s", e.what());
}
return instance;
}

jobject Deserializer::convert2JDraftRollOverTransaction(JNIEnv *env, const Transaction &transaction,
const std::vector<int> &tagIds,
const std::vector<int> &collectionIds) {
syslog(LOG_DEBUG, "[JNI] convert2JDraftRollOverTransaction()");
jclass clazz = env->FindClass("com/nunchuk/android/model/DraftRollOverTransaction");
jmethodID constructor = env->GetMethodID(clazz, "<init>", "()V");
jobject instance = env->NewObject(clazz, constructor);
try {
jobject element = convert2JTransaction(env, transaction);
env->CallVoidMethod(instance, env->GetMethodID(clazz, "setTransaction",
"(Lcom/nunchuk/android/model/Transaction;)V"),
element);
env->CallVoidMethod(instance, env->GetMethodID(clazz, "setTagIds", "(Ljava/util/Set;)V"),
convert2JInts(env, tagIds));
env->CallVoidMethod(instance, env->GetMethodID(clazz, "setCollectionIds", "(Ljava/util/Set;)V"),
convert2JInts(env, collectionIds));
} catch (const std::exception &e) {
syslog(LOG_DEBUG, "[JNI] convert2JDraftRollOverTransaction error::%s", e.what());
}
return instance;
}

jobjectArray Deserializer::convert2JDraftRollOverTransactions(JNIEnv *env,
const std::map<std::pair<std::set<int>, std::set<int>>, Transaction> txs) {
syslog(LOG_DEBUG, "[JNI] convert2JDraftRollOverTransactions()");
jclass clazz = env->FindClass("com/nunchuk/android/model/DraftRollOverTransaction");
jobjectArray ret = env->NewObjectArray(txs.size(), clazz, nullptr);
int i = 0;
for (const auto &tx: txs) {
jobject element = convert2JDraftRollOverTransaction(env, tx.second, std::vector<int>(tx.first.first.begin(), tx.first.first.end()), std::vector<int>(tx.first.second.begin(), tx.first.second.end()));
env->SetObjectArrayElement(ret, i++, element);
}
return ret;
}
5 changes: 5 additions & 0 deletions src/main/native/deserializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,10 @@ class Deserializer {

static jobject convert2JCoinStatus(JNIEnv *env, const CoinStatus &status);

static jobject convert2JBSMSData(JNIEnv *env, const BSMSData &data);

static jobject convert2JCollectionUnspentOutputs(JNIEnv *env, const std::vector<std::vector<UnspentOutput>> &outputs);
static jobject convert2JPairAmount(JNIEnv *env, const std::pair<Amount, Amount> &pair);
static jobject convert2JDraftRollOverTransaction(JNIEnv *env, const Transaction &transaction, const std::vector<int> &tagIds, const std::vector<int> &collectionIds);
static jobjectArray convert2JDraftRollOverTransactions(JNIEnv *env, std::map<std::pair<std::set<int>, std::set<int>>, Transaction> txs);
};
2 changes: 1 addition & 1 deletion src/main/native/libnunchuk
Loading

0 comments on commit 79f5159

Please sign in to comment.