-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
android/src/main/kotlin/africa/ejara/trustdart/coins/ADA.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |