-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
15 changed files
with
355 additions
and
168 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...app/src/androidTest/java/com/trustwallet/core/app/blockchains/pactus/TestPactusAddress.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,29 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
package com.trustwallet.core.app.blockchains.pactus | ||
|
||
import com.trustwallet.core.app.utils.toHex | ||
import com.trustwallet.core.app.utils.toHexByteArray | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import wallet.core.jni.* | ||
|
||
class TestPactusAddress { | ||
|
||
init { | ||
System.loadLibrary("TrustWalletCore") | ||
} | ||
|
||
@Test | ||
fun testAddress() { | ||
val key = PrivateKey("4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6".toHexByteArray()) | ||
val pubkey = key.publicKeyEd25519 | ||
val address = AnyAddress(pubkey, CoinType.PACTUS) | ||
val expected = AnyAddress("pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr", CoinType.PACTUS) | ||
|
||
assertEquals(pubkey.data().toHex(), "0x95794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa") | ||
assertEquals(address.description(), expected.description()) | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
.../app/src/androidTest/java/com/trustwallet/core/app/blockchains/pactus/TestPactusSigner.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,63 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
package com.trustwallet.core.app.blockchains.pactus | ||
|
||
import com.google.protobuf.ByteString | ||
import com.trustwallet.core.app.utils.Numeric | ||
import com.trustwallet.core.app.utils.toHexByteArray | ||
import com.trustwallet.core.app.utils.toHexBytes | ||
import com.trustwallet.core.app.utils.toHexBytesInByteString | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import wallet.core.jni.PactusSigner | ||
import wallet.core.jni.proto.Pactus | ||
|
||
class TestPactusSigner { | ||
|
||
init { | ||
System.loadLibrary("TrustWalletCore") | ||
} | ||
|
||
@Test | ||
fun PactusTransactionSigning() { | ||
val privateKey = | ||
"4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6".toHexBytesInByteString() | ||
|
||
val transfer = Pactus.TransferPayload.newBuilder() | ||
.setSender("pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr") | ||
.setReceiver("pc1r0g22ufzn8qtw0742dmfglnw73e260hep0k3yra") | ||
.setAmount(20000) | ||
.build() | ||
|
||
val transaction = Pactus.TransactionMessage.newBuilder() | ||
.setLockTime(0x00030201) | ||
.setFee(1000) | ||
.setMemo("test") | ||
.setTransfer(transfer) | ||
.build() | ||
|
||
val signingInput = Pactus.SigningInput.newBuilder() | ||
.setPrivateKey(privateKey) | ||
.setTransaction(transaction) | ||
.build() | ||
|
||
val output: Pactus.SigningOutput = PactusSigner.sign(signingInput) | ||
|
||
assertEquals( | ||
"34cd4656a98f7eb996e83efdc384cefbe3a9c52dca79a99245b4eacc0b0b4311", | ||
Numeric.toHexString(output.transactionId.toByteArray()) | ||
) | ||
|
||
assertEquals( | ||
"50ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd09", | ||
Numeric.toHexString(output.signature.toByteArray()) | ||
) | ||
|
||
assertEquals( | ||
"000101020300e807047465737401037098338e0b6808119dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df21a09c0150ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd0995794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa", | ||
Numeric.toHexString(output.signedTransactionData.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 |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
// Copyright © 2017 Trust Wallet. | ||
|
||
pub mod transaction_util; | ||
pub mod tx_builder; |
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,42 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
use crate::transaction::payload::TransferPayload; | ||
use crate::transaction::Transaction; | ||
use crate::types::{Address, Amount}; | ||
use std::str::FromStr; | ||
use tw_coin_entry::error::prelude::*; | ||
use tw_proto::Pactus; | ||
|
||
pub struct TxBuilder; | ||
|
||
impl TxBuilder { | ||
pub fn from_proto(input: &Pactus::Proto::SigningInput) -> SigningResult<Transaction> { | ||
match &input.transaction { | ||
None => SigningError::err(SigningErrorType::Error_invalid_params), | ||
Some(trx) => { | ||
let payload = match &trx.payload { | ||
Pactus::Proto::mod_TransactionMessage::OneOfpayload::transfer(pld) => { | ||
let sender = Address::from_str(&pld.sender)?; | ||
let receiver = Address::from_str(&pld.receiver)?; | ||
Box::new(TransferPayload::new(sender, receiver, Amount(pld.amount))) | ||
}, | ||
Pactus::Proto::mod_TransactionMessage::OneOfpayload::bond(_pld) => { | ||
return SigningError::err(SigningErrorType::Error_not_supported) | ||
}, | ||
Pactus::Proto::mod_TransactionMessage::OneOfpayload::None => { | ||
return SigningError::err(SigningErrorType::Error_invalid_params) | ||
}, | ||
}; | ||
|
||
Ok(Transaction::new( | ||
trx.lock_time, | ||
Amount(trx.fee), | ||
trx.memo.to_string(), | ||
payload, | ||
)) | ||
}, | ||
} | ||
} | ||
} |
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
Oops, something went wrong.