Skip to content

Commit

Permalink
resolved review
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakeally committed Sep 13, 2023
1 parent 50a0f34 commit e9d7bfc
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 28 deletions.
5 changes: 2 additions & 3 deletions android/src/main/kotlin/africa/ejara/trustdart/Coin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ open class Coin(nameOfCoin: String, typeOfCoin: CoinType) : CoinInterface {
override fun getRawPrivateKey(path: String, mnemonic: String, passphrase: String): ByteArray? {
val wallet = HDWallet(mnemonic, passphrase)
return wallet.getKey(coinType, path).data()
}
}

override fun getPublicKey(path: String, mnemonic: String, passphrase: String): String? {
val wallet = HDWallet(mnemonic, passphrase)
return wallet.getKey(coinType, path).getPublicKeySecp256k1(true).data().base64String()
}

override fun getRawPublicKey(path: String, mnemonic: String, passphrase: String): ByteArray? {
val wallet = HDWallet(mnemonic, passphrase)
return wallet.getKey(coinType, path).getPublicKeySecp256k1(true).data()
Expand Down Expand Up @@ -84,7 +84,6 @@ open class Coin(nameOfCoin: String, typeOfCoin: CoinType) : CoinInterface {
}

override fun multiSignTransaction(
path: String,
txData: Map<String, Any>,
privateKeys: ArrayList<String>
): String? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class TrustdartPlugin : FlutterPlugin, MethodCallHandler {
validator.details.errorMessage,
validator.details.errorDetails
)
}
}
"checkMnemonic" -> {
val mnemonic: String? = call.argument("mnemonic")
val passphrase: String? = call.argument("passphrase")
Expand Down Expand Up @@ -166,19 +166,18 @@ class TrustdartPlugin : FlutterPlugin, MethodCallHandler {
}
"multiSignTransaction" -> {
val coin: String? = call.argument("coin")
val path: String? = call.argument("path")
val txData: Map<String, Any>? = call.argument("txData")
val privateKeys: ArrayList<String>? = call.argument("privateKeys")
var validator = WalletHandler().validate(
WalletError(
WalletHandlerErrorCodes.ArgumentsNull,
"[path], [coin], [privateKeys] and [txData] are required.",
"[coin], [privateKeys] and [txData] are required.",
null
), arrayOf(path, coin, txData, privateKeys)
), arrayOf(coin, txData, privateKeys)
)
if (validator.isValid) {
val txHash = WalletHandler().getCoin(coin)
.multiSignTransaction(path!!, txData!!, privateKeys!!)
.multiSignTransaction(txData!!, privateKeys!!)
validator = WalletHandler().validate(
WalletError(
WalletHandlerErrorCodes.TxHashNull,
Expand Down
3 changes: 1 addition & 2 deletions android/src/main/kotlin/africa/ejara/trustdart/coins/BTC.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import wallet.core.jni.CoinType
import wallet.core.jni.HDWallet
import wallet.core.jni.proto.Bitcoin




class BTC : Coin("BTC", CoinType.BITCOIN) {
Expand Down Expand Up @@ -82,7 +82,6 @@ class BTC : Coin("BTC", CoinType.BITCOIN) {


override fun multiSignTransaction(
path: String,
txData: Map<String, Any>,
privateKeys: ArrayList<String>
): String? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package africa.ejara.trustdart.interfaces

import com.google.protobuf.ByteString

interface CoinInterface {
Expand All @@ -13,7 +13,6 @@ interface CoinInterface {
fun signDataWithPrivateKey(path: String, mnemonic: String, passphrase: String, txData: String): String?
fun signTransaction(path: String, txData: Map<String, Any>, mnemonic: String, passphrase: String): String?
fun multiSignTransaction(
path: String,
txData: Map<String, Any>,
privateKeys: ArrayList<String>
): String?
Expand Down
3 changes: 1 addition & 2 deletions example/lib/operations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ runOperations() async {
bool valid = await Trustdart.validateAddress(
coin.code,
address['legacy']!,
);
);
print([valid]);

bool invalid = await Trustdart.validateAddress(
Expand All @@ -330,7 +330,6 @@ runOperations() async {
String multiTxSign = await Trustdart.multiSignTransaction(
dondo,
coin.code,
coin.path,
operations[coin.code],
operations[coin.code]["privateKeys"]);
print('MultiSig Transaction Check ...');
Expand Down
4 changes: 2 additions & 2 deletions ios/Classes/Coin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Coin: CoinProtocol {
init(name: String, coinType: CoinType){
self.name = name
self.coinType = coinType
}
}

func getName() -> String {
return self.name
Expand Down Expand Up @@ -82,7 +82,7 @@ class Coin: CoinProtocol {



func multiSignTransaction(path: String, txData: [String: Any], privateKeys: [String]) -> String? {
func multiSignTransaction(txData: [String: Any], privateKeys: [String]) -> String? {
let opJson = Utils.objToJson(from: txData)
var signatures = [String]()

Expand Down
9 changes: 4 additions & 5 deletions ios/Classes/SwiftTrustdartPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class SwiftTrustdartPlugin: NSObject, FlutterPlugin {
let wallet = WalletHandler().generateMnemonic(strength: 128, passphrase: call.arguments as! String)
let (isValid, err) = WalletHandler.validate(walletError: WalletError(code: .noWallet, message: "Could not generate wallet", details: nil), wallet)
if isValid {
result(wallet)
result(wallet)
}else {
result(err.details)
}
Expand Down Expand Up @@ -77,21 +77,20 @@ public class SwiftTrustdartPlugin: NSObject, FlutterPlugin {
result(txHash)
}else {
result(err.details)
}
}
}else {
result(err.details)
}

case "multiSignTransaction":
let args = call.arguments as! [String: Any]
let coin: String? = args["coin"] as? String
let path: String? = args["path"] as? String
let txData: [String: Any]? = args["txData"] as? [String: Any]
let privateKeys: [String]? = args["privateKeys"] as? [String]
let (isValid, err) = WalletHandler.validate(walletError: WalletError(code: .argumentsNull, message: "[coin] and [path] are required.", details: nil), coin, path)
let (isValid, err) = WalletHandler.validate(walletError: WalletError(code: .argumentsNull, message: "[coin] are required.", details: nil), coin)

if isValid {
let txHash = WalletHandler().getCoin(coin!).multiSignTransaction(path: path!, txData: txData!, privateKeys: privateKeys ?? [] )
let txHash = WalletHandler().getCoin(coin!).multiSignTransaction(txData: txData!, privateKeys: privateKeys ?? [] )

let (isValid, err) = WalletHandler.validate(walletError: WalletError(code: .txHashNull, message: "Failed to sign transaction.", details: nil), txHash)
if isValid {
Expand Down
4 changes: 2 additions & 2 deletions ios/Classes/coins/BTC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class BTC: Coin {
$0.privateKey = [privateKey!.data]
$0.plan = BitcoinTransactionPlan.with {
$0.amount = txData["amount"] as! Int64
$0.fee = txData["fees"] as! Int64
$0.fee = txData["fees"] as! Int64
$0.change = txData["change"] as! Int64
$0.utxos = unspent
}
Expand All @@ -64,7 +64,7 @@ class BTC: Coin {



override func multiSignTransaction(path: String, txData: [String : Any], privateKeys: [String]) -> String? {
override func multiSignTransaction(txData: [String : Any], privateKeys: [String]) -> String? {
let utxos: [[String: Any]] = txData["utxos"] as! [[String: Any]]
var unspent: [BitcoinUnspentTransaction] = []

Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/protocols/CoinProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ protocol CoinProtocol {
func validateAddress(address: String) -> Bool
func signDataWithPrivateKey(path: String, mnemonic: String, passphrase: String, txData: String) -> String?
func signTransaction(path: String, txData: [String: Any], mnemonic: String, passphrase: String) -> String?
func multiSignTransaction(path: String, txData: [String: Any], privateKeys: [String]) -> String?
func multiSignTransaction(txData: [String: Any], privateKeys: [String]) -> String?

}
6 changes: 2 additions & 4 deletions lib/trustdart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,13 @@ class Trustdart {
}
}

static Future<String> multiSignTransaction(String mnemonic, String coin,
String path, Map txData, List<String>? privateKeys,
[String passphrase = ""]) async {
static Future<String> multiSignTransaction(String coin,
String path, Map txData, List<String>? privateKeys) async {
try {
final String txHash = await _channel.invokeMethod(
'multiSignTransaction', <String, dynamic>{
'coin': coin,
'txData': txData,
'path': path,
'privateKeys': privateKeys
});
return txHash;
Expand Down

0 comments on commit e9d7bfc

Please sign in to comment.