-
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.
[WalletConnect/BNB]: Add support for WalletConnect signing requests (#…
…3632) * [WalletConnect/BNB]: Add `WalletConnectSigner` optional module * [WalletConnect/BNB]: Implement `cosmos_signAmino` handler * TODO fix compilation error * [WalletConnect/BNB]: POC * [WalletConnect/BNB]: Move `TxBuilder` implementation * [WalletConnect/BNB]: Finalize `WalletConnector` in `CoinEntry` * [WalletConnect/BNB]: Add `tw_wallet_connect_request_parse` FFI * [WalletConnect/BNB]: Add `signature` and `signature_json` to Binance::SigningOutput * [WalletConnect/BNB]: Add `TWWalletConnectRequestParse` C FFI * Improve WalletConnect.proto interface * [WalletConnect/BNB]: Add Android test * [WalletConnect/BNB]: Add iOS test * [WalletConnect/BNB]: Update the year in Copyright * [WalletConnect/BNB]: Fix codegen-v2 template * [WalletConnect/BNB]: Minor changes * [CI] Trigger CI * [WalletConnect/BNB]: Fix C++ tests --------- Co-authored-by: Sztergbaum Roman <[email protected]>
- Loading branch information
1 parent
03e5082
commit 8f8a266
Showing
74 changed files
with
1,734 additions
and
863 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
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==\"}") | ||
} | ||
} |
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
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
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,27 @@ | ||
// Copyright © 2017-2024 Trust Wallet. | ||
// | ||
// This file is part of Trust. The full Trust copyright notice, including | ||
// terms governing use, modification, and redistribution, is contained in the | ||
// file LICENSE at the root of the source code distribution tree. | ||
|
||
#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
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,23 @@ | ||
// Copyright © 2017-2024 Trust Wallet. | ||
// | ||
// This file is part of Trust. The full Trust copyright notice, including | ||
// terms governing use, modification, and redistribution, is contained in the | ||
// file LICENSE at the root of the source code distribution tree. | ||
|
||
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
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
Oops, something went wrong.