-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into s/update-copyright-2024
- Loading branch information
Showing
64 changed files
with
1,685 additions
and
832 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
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
46 changes: 46 additions & 0 deletions
46
...Test/java/com/trustwallet/core/app/blockchains/binance/TestBinanceWalletConnectSigning.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,46 @@ | ||
package com.trustwallet.core.app.blockchains.binance | ||
|
||
import com.google.protobuf.ByteString | ||
import com.trustwallet.core.app.utils.toHexBytes | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import wallet.core.jni.proto.Binance.SigningOutput | ||
import wallet.core.jni.proto.WalletConnect | ||
import wallet.core.jni.* | ||
import wallet.core.jni.CoinType.BINANCE | ||
import wallet.core.java.AnySigner | ||
import wallet.core.jni.proto.Common | ||
|
||
class TestBinanceWalletConnectSigning { | ||
init { | ||
System.loadLibrary("TrustWalletCore") | ||
} | ||
|
||
@Test | ||
fun testSignBinanceTransactionFromWalletConnectRequest() { | ||
// Step 1: Parse a signing request received through WalletConnect. | ||
|
||
val parsingInput = WalletConnect.ParseRequestInput.newBuilder().apply { | ||
method = WalletConnect.Method.CosmosSignAmino | ||
payload = "{\"signerAddress\":\"bnb1grpf0955h0ykzq3ar5nmum7y6gdfl6lxfn46h2\",\"signDoc\":{\"account_number\":\"19\",\"chain_id\":\"chain-bnb\",\"memo\":\"\",\"data\":null,\"msgs\":[{\"inputs\":[{\"address\":\"bnb1grpf0955h0ykzq3ar5nmum7y6gdfl6lxfn46h2\",\"coins\":[{\"amount\":1001000000,\"denom\":\"BNB\"}]}],\"outputs\":[{\"address\":\"bnb13zeh6hs97d5eu2s5qerguhv8ewwue6u4ywa6yf\",\"coins\":[{\"amount\":1001000000,\"denom\":\"BNB\"}]}]}],\"sequence\":\"23\",\"source\":\"1\"}}" | ||
}.build() | ||
|
||
val parsingOutputBytes = WalletConnectRequest.parse(BINANCE, parsingInput.toByteArray()) | ||
val parsingOutput = WalletConnect.ParseRequestOutput.parseFrom(parsingOutputBytes) | ||
|
||
assertEquals(parsingOutput.error, Common.SigningError.OK) | ||
|
||
// Step 2: Set missing fields. | ||
|
||
val signingInput = parsingOutput.binance.toBuilder().apply { | ||
privateKey = ByteString.copyFrom("95949f757db1f57ca94a5dff23314accbe7abee89597bf6a3c7382c84d7eb832".toHexBytes()) | ||
}.build() | ||
|
||
// Step 3: Sign the transaction. | ||
|
||
val output = AnySigner.sign(signingInput, BINANCE, SigningOutput.parser()) | ||
|
||
assertEquals(output.error, Common.SigningError.OK) | ||
assertEquals(output.signatureJson, "{\"pub_key\":{\"type\":\"tendermint/PubKeySecp256k1\",\"value\":\"Amo1kgCI2Yw4iMpoxT38k/RWRgJgbLuH8P5e5TPbOOUC\"},\"signature\":\"PCTHhMa7+Z1U/6uxU+3LbTxKd0k231xypdMolyVvjgYvMg+0dTMC+wqW8IxHWXTSDt/Ronu+7ac1h/WN3JWJdQ==\"}") | ||
} | ||
} |
Binary file not shown.
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,25 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
#pragma once | ||
|
||
#include "TWBase.h" | ||
#include "TWCoinType.h" | ||
#include "TWData.h" | ||
|
||
TW_EXTERN_C_BEGIN | ||
|
||
/// Represents a WalletConnect signing request. | ||
TW_EXPORT_CLASS | ||
struct TWWalletConnectRequest; | ||
|
||
/// Parses the WalletConnect signing request as a `SigningInput`. | ||
/// | ||
/// \param coin The given coin type to plan the transaction for. | ||
/// \param input The serialized data of a `WalletConnect::Proto::ParseRequestInput` proto object. | ||
/// \return The serialized data of `WalletConnect::Proto::ParseRequestOutput` proto object. | ||
TW_EXPORT_STATIC_METHOD | ||
TWData* _Nonnull TWWalletConnectRequestParse(enum TWCoinType coin, TWData* _Nonnull input); | ||
|
||
TW_EXTERN_C_END |
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,21 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
use crate::address::BinanceAddress; | ||
use tw_cosmos_sdk::context::CosmosContext; | ||
use tw_cosmos_sdk::hasher::sha256_hasher::Sha256Hasher; | ||
use tw_cosmos_sdk::private_key::secp256k1::Secp256PrivateKey; | ||
use tw_cosmos_sdk::public_key::secp256k1::Secp256PublicKey; | ||
use tw_cosmos_sdk::signature::secp256k1::Secp256k1Signature; | ||
|
||
pub struct BinanceContext; | ||
|
||
impl CosmosContext for BinanceContext { | ||
type Address = BinanceAddress; | ||
/// Binance Beacon chain uses `sha256` hash. | ||
type TxHasher = Sha256Hasher; | ||
type PrivateKey = Secp256PrivateKey; | ||
type PublicKey = Secp256PublicKey; | ||
type Signature = Secp256k1Signature; | ||
} |
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 |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
pub mod preimager; | ||
pub mod serializer; | ||
pub mod tx_builder; | ||
pub mod wallet_connect; |
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.