-
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/bitcoin-v2-compiler
- Loading branch information
Showing
192 changed files
with
7,118 additions
and
1,648 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
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
29 changes: 29 additions & 0 deletions
29
...Test/java/com/trustwallet/core/app/blockchains/theopennetwork/TestTheOpenNetworkWallet.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.theopennetwork | ||
|
||
import com.trustwallet.core.app.utils.toHexByteArray | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import wallet.core.jni.PublicKey | ||
import wallet.core.jni.PublicKeyType | ||
import wallet.core.jni.TONWallet | ||
|
||
class TestTheOpenNetworkWallet { | ||
init { | ||
System.loadLibrary("TrustWalletCore") | ||
} | ||
|
||
@Test | ||
fun TheOpenNetworkWalletBuildV4R2StateInit() { | ||
val publicKey = PublicKey("f229a9371fa7c2108b3d90ea22c9be705ff5d0cfeaee9cbb9366ff0171579357".toHexByteArray(), PublicKeyType.ED25519) | ||
val baseWorkchain = 0 | ||
val defaultWalletId = 0x29a9a317 | ||
val stateInit = TONWallet.buildV4R2StateInit(publicKey, baseWorkchain, defaultWalletId) | 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||
assertEquals(stateInit, expected) | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
android/app/src/androidTest/java/com/trustwallet/core/app/utils/TestCryptoBox.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,47 @@ | ||
package com.trustwallet.core.app.utils | ||
|
||
import com.trustwallet.core.app.utils.toHexBytes | ||
import com.trustwallet.core.app.utils.toHex | ||
import org.junit.Assert.* | ||
import org.junit.Test | ||
import wallet.core.jni.* | ||
|
||
class TestCryptoBox { | ||
init { | ||
System.loadLibrary("TrustWalletCore") | ||
} | ||
|
||
@Test | ||
fun testEncryptDecryptEasy() { | ||
val mySecret = CryptoBoxSecretKey() | ||
val myPubkey = mySecret.publicKey | ||
|
||
val otherSecret = CryptoBoxSecretKey() | ||
val otherPubkey = otherSecret.publicKey | ||
|
||
val message = "Well done is better than well said. -Benjamin Franklin" | ||
val encrypted = CryptoBox.encryptEasy(mySecret, otherPubkey, message.toByteArray()) | ||
|
||
// Step 2. Make sure the Box can be decrypted by the other side. | ||
val decrypted = CryptoBox.decryptEasy(otherSecret, myPubkey, encrypted) | ||
assertEquals(decrypted.toString(Charsets.UTF_8), message) | ||
} | ||
|
||
@Test | ||
fun testSecretKeyFromToBytes() { | ||
val secretBytesHex = "0xdd87000d4805d6fbd89ae1352f5e4445648b79d5e901c92aebcb610e9be468e4" | ||
val secretBytes = secretBytesHex.toHexByteArray() | ||
assert(CryptoBoxSecretKey.isValid(secretBytes)) | ||
val secret = CryptoBoxSecretKey(secretBytes) | ||
assertEquals(secret.data().toHex(), secretBytesHex) | ||
} | ||
|
||
@Test | ||
fun testPublicKeyFromToBytes() { | ||
val publicBytesHex = "0xafccabc5b28a8a1fd1cd880516f9c854ae2498d0d1b978b53a59f38e4ae55747" | ||
val publicBytes = publicBytesHex.toHexByteArray() | ||
assert(CryptoBoxPublicKey.isValid(publicBytes)) | ||
val pubkey = CryptoBoxPublicKey(publicBytes) | ||
assertEquals(pubkey.data().toHex(), publicBytesHex) | ||
} | ||
} |
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,40 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
#pragma once | ||
|
||
#include "TWBase.h" | ||
#include "TWCryptoBoxPublicKey.h" | ||
#include "TWCryptoBoxSecretKey.h" | ||
#include "TWData.h" | ||
#include "TWString.h" | ||
|
||
TW_EXTERN_C_BEGIN | ||
|
||
/// `crypto_box` encryption algorithms. | ||
TW_EXPORT_STRUCT | ||
struct TWCryptoBox; | ||
|
||
/// Encrypts message using `my_secret` and `other_pubkey`. | ||
/// The output will have a randomly generated nonce prepended to it. | ||
/// The output will be Overhead + 24 bytes longer than the original. | ||
/// | ||
/// \param mySecret *non-null* pointer to my secret key. | ||
/// \param otherPubkey *non-null* pointer to other's public key. | ||
/// \param message *non-null* pointer to the message to be encrypted. | ||
/// \return *nullable* pointer to the encrypted message with randomly generated nonce prepended to it. | ||
TW_EXPORT_STATIC_METHOD | ||
TWData* _Nonnull TWCryptoBoxEncryptEasy(struct TWCryptoBoxSecretKey* _Nonnull mySecret, struct TWCryptoBoxPublicKey* _Nonnull otherPubkey, TWData* _Nonnull message); | ||
|
||
/// Decrypts box produced by `TWCryptoBoxEncryptEasy`. | ||
/// We assume a 24-byte nonce is prepended to the encrypted text in box. | ||
/// | ||
/// \param mySecret *non-null* pointer to my secret key. | ||
/// \param otherPubkey *non-null* pointer to other's public key. | ||
/// \param encrypted *non-null* pointer to the encrypted message with nonce prepended to it. | ||
/// \return *nullable* pointer to the decrypted message. | ||
TW_EXPORT_STATIC_METHOD | ||
TWData* _Nullable TWCryptoBoxDecryptEasy(struct TWCryptoBoxSecretKey* _Nonnull mySecret, struct TWCryptoBoxPublicKey* _Nonnull otherPubkey, TWData* _Nonnull encrypted); | ||
|
||
TW_EXTERN_C_END |
Oops, something went wrong.