Skip to content

Commit

Permalink
Fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay committed Jun 15, 2023
2 parents 32c545f + f88bb38 commit 42003af
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import BNB
import BSC
import DOGE
import MATIC
import ADA

import africa.ejara.trustdart.utils.WalletError
import africa.ejara.trustdart.utils.WalletValidateResponse
Expand All @@ -31,6 +32,7 @@ class WalletHandler {
"BSC" to BSC(),
"DOGE" to DOGE(),
"MATIC" to MATIC(),
"ADA" to ADA(),
)
}

Expand Down
52 changes: 52 additions & 0 deletions android/src/main/kotlin/africa/ejara/trustdart/coins/ADA.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import africa.ejara.trustdart.Coin
import africa.ejara.trustdart.Numeric
import africa.ejara.trustdart.utils.toLong
import com.google.protobuf.ByteString
import io.flutter.Log
import wallet.core.jni.CoinType
import wallet.core.jni.HDWallet
import wallet.core.jni.proto.Cardano
import wallet.core.java.AnySigner



class ADA : Coin("ADA", CoinType.CARDANO){

override fun signTransaction(
path: String,
txData: Map<String, Any>,
mnemonic: String,
passphrase: String
): String? {
val wallet = HDWallet(mnemonic, passphrase)
val privateKey = wallet.getKey(coinType, path)
val listOfAllUtxos = mutableListOf<Cardano.TxInput>();
val utxos: List<Map<String, Any>> = txData["utxos"] as List<Map<String, Any>>
val message = Cardano.Transfer.newBuilder()
.setToAddress(txData["receiverAddress"] as String)
.setChangeAddress(txData["senderAddress" ] as String)
.setAmount(txData["amount"]!!.toLong())
.build()
val input = Cardano.SigningInput.newBuilder()
.setTransferMessage(message)
.setTtl(53333333)

input.addPrivateKey(ByteString.copyFrom(privateKey.data()))
for (utx in utxos) {
val outpoint1 = Cardano.OutPoint.newBuilder()
.setTxHash(ByteString.copyFrom(Numeric.hexStringToByteArray(utx["txid"] as String)))
.setOutputIndex(utx["index"]!!.toLong())
.build()
val utxo1 = Cardano.TxInput.newBuilder()
.setOutPoint(outpoint1)
.setAddress(utx["senderAddress"] as String)
.setAmount(utx["amount"]!!.toLong())
.build()
listOfAllUtxos.add(utxo1)
}
input.addAllUtxos(listOfAllUtxos)

val output = AnySigner.sign(input.build(), coinType, Cardano.SigningOutput.parser())
return Numeric.toHexString(output.encoded.toByteArray())
}
}
1 change: 1 addition & 0 deletions example/lib/coins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ List<Coin> coinList = [
Coin(code: 'BSC', path: "m/44'/60'/0'/0/0"),
Coin(code: 'DOGE', path: "m/44'/3'/0'/0/0"),
Coin(code: 'MATIC', path: "m/44'/60'/0'/0/0"),
Coin(code: 'ADA', path: "m/1852'/1815'/0'/0/0"),
];
21 changes: 19 additions & 2 deletions example/lib/operations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ Map<String, dynamic> operations = {
"fees": 5000,
"changeAddress": "D9pvhnWknRza2HTXhY5WT29D4kvYzTZQAF",
},

'MATIC': {
"chainId": "0x89",
"nonce": "0x01",
Expand All @@ -225,6 +224,23 @@ Map<String, dynamic> operations = {
"toAddress": "0xC894F1dCE55358ef44D760d8B1fb3397F5b1c24b",
"amount": "0x3B9ACA00",
},
'ADA': {
"senderAddress":
"addr1q9evp7aqelh4epkacgyeqweqgkvqsl8gdp54mxew5kdvuyhqhuqa6ngy0jrdcnknurcvjgtv4jd84pd7xllgmdz0wtrqgfz5l4",
"receiverAddress":
"addr1qyk022rpw85g7c0f0wuq6zpkakgjwsftmpd99wqjj4xcsjc74pfgs7t76yuehca7hn4pcl37lsl06ccey0epe5sp4lwslxsyrw",
"amount": 40000,
"utxos": [
{
"senderAddress":
"addr1q9evp7aqelh4epkacgyeqweqgkvqsl8gdp54mxew5kdvuyhqhuqa6ngy0jrdcnknurcvjgtv4jd84pd7xllgmdz0wtrqgfz5l4",
"txid":
"76608917328b3768b3985d057e613c7e8f14cb1f27b132a750a363ee64363a57",
"index": 0,
"amount": 16900000,
},
],
}
};

// ignore: inference_failure_on_function_return_type
Expand All @@ -236,7 +252,8 @@ runOperations() async {
print('Here is our mnemonic: \n$mnemonic');

String dondo =
"imitate embody law mammal exotic transfer roof hope price swift ordinary uncle";
"able student evoke travel find shift gasp beauty venture dove valid lounge";
// "imitate embody law mammal exotic transfer roof hope price swift ordinary uncle";
// dondo = "a d f d s e w q t y u l";
bool wallet = await Trustdart.checkMnemonic(dondo);
print(wallet);
Expand Down
5 changes: 5 additions & 0 deletions ios/Classes/WalletHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class WalletHandler {
"BSC" : BSC(),
"DOGE" : DOGE(),
"MATIC" : MATIC(),
"ADA" : ADA()
]

func getCoin(_ coin: String) -> Coin {
Expand All @@ -47,3 +48,7 @@ class WalletHandler {
}






38 changes: 38 additions & 0 deletions ios/Classes/coins/ADA.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
ADA
*/

import WalletCore

class ADA: Coin {
init() {
super.init(name: "ADA", coinType: .cardano)
}

override func signTransaction(path: String, txData: [String : Any], mnemonic: String, passphrase: String) -> String? {
let privateKey = HDWallet(mnemonic: mnemonic, passphrase: passphrase)?.getKey(coin: coinType, derivationPath: path)
let utxos: [[String: Any]] = txData["utxos"] as! [[String: Any]]
var listOfUtxos: [CardanoTxInput] = []

for utx in utxos {
listOfUtxos.append(CardanoTxInput.with {
$0.outPoint.txHash = Data(hexString: (utx["txid"] as! String))!
$0.outPoint.outputIndex = utx["index"] as! UInt64
$0.address = utx["senderAddress"] as! String
$0.amount = utx["amount"] as! UInt64
})
}

var input = CardanoSigningInput.with {
$0.transferMessage.toAddress = txData["receiverAddress"] as! String
$0.transferMessage.changeAddress = txData["senderAddress"] as! String
$0.transferMessage.amount = txData["amount"] as! UInt64
$0.ttl = 53333333
$0.privateKey = [privateKey!.data]
$0.utxos = listOfUtxos
}

let output: CardanoSigningOutput = AnySigner.sign(input: input, coin: .cardano)
return output.encoded.hexString
}
}

0 comments on commit 42003af

Please sign in to comment.