Skip to content

Commit

Permalink
Merge pull request #20 from trustwallet/master
Browse files Browse the repository at this point in the history
IOS-3972-Merge-latest-upstream-master-3.2.4
  • Loading branch information
Balashov152 authored Jul 7, 2023
2 parents 51e5e6e + 5dee361 commit 5a6d8c6
Show file tree
Hide file tree
Showing 83 changed files with 1,896 additions and 1,427 deletions.
8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ let package = Package(
targets: [
.binaryTarget(
name: "WalletCore",
url: "https://github.com/trustwallet/wallet-core/releases/download/3.1.31/WalletCore.xcframework.zip",
checksum: "e600d3cf08148b8a00beab9a22fe3b301be9620baf4e44fdd7261d5ddcf55107"
url: "https://github.com/trustwallet/wallet-core/releases/download/3.2.1/WalletCore.xcframework.zip",
checksum: "b7f9fe6b5aa1fd216d43f676400c9db6999c6494e0120db73b2afb49dcc1f013"
),
.binaryTarget(
name: "SwiftProtobuf",
url: "https://github.com/trustwallet/wallet-core/releases/download/3.1.31/SwiftProtobuf.xcframework.zip",
checksum: "f12d09ba0aad8b90d36424ee6fc6a8a66878414b8d301ab9e4f715de73308ca3"
url: "https://github.com/trustwallet/wallet-core/releases/download/3.2.1/SwiftProtobuf.xcframework.zip",
checksum: "12bbc92dc2225c661e301cc2826e034fcb69b2a144f8c4ff2e51ce6ccf122124"
)
]
)
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<img src="docs/banner.png" align="center" title="Trust logo">

Trust Wallet Core is an open source, cross-platform, mobile-focused library
Trust Wallet Core is an open-source, cross-platform, mobile-focused library
implementing low-level cryptographic wallet functionality for a high number of blockchains.
It is a core part of the popular [Trust Wallet](https://trustwallet.com), and some other projects.
Most of the code is C++ with a set of strict C interfaces, and idiomatic interfaces for supported languages:
Expand All @@ -26,7 +26,7 @@ For comprehensive documentation, see [developer.trustwallet.com](https://develop

# Supported Blockchains

Wallet Core supports more than **60** blockchains: Bitcoin, Ethereum, BNB, Cosmos, Solana, and most major blockchain platforms.
Wallet Core supports more than **130** blockchains: Bitcoin, Ethereum, BNB, Cosmos, Solana, and most major blockchain platforms.
The full list is [here](docs/registry.md).

# Building
Expand All @@ -40,7 +40,7 @@ If you want to use wallet core in your project follow these instructions.

## Android

Android releases are hosted on [GitHub packages](https://github.com/trustwallet/wallet-core/packages/700258), you need to add GitHub access token to install it. Please checkout [this installation guide](https://developer.trustwallet.com/wallet-core/integration-guide/android-guide#adding-library-dependency) or `build.gradle` from our [android sample](https://github.com/trustwallet/wallet-core/blob/master/samples/android/build.gradle)
Android releases are hosted on [GitHub packages](https://github.com/trustwallet/wallet-core/packages/700258), you need to add GitHub access token to install it. Please check out [this installation guide](https://developer.trustwallet.com/wallet-core/integration-guide/android-guide#adding-library-dependency) or `build.gradle` from our [android sample](https://github.com/trustwallet/wallet-core/blob/master/samples/android/build.gradle)

Don't forget replacing the version in the code with latest: ![GitHub release (latest by date)](https://img.shields.io/github/v/release/trustwallet/wallet-core)

Expand Down Expand Up @@ -100,7 +100,6 @@ Projects using Trust Wallet Core. Add yours too!
[<img src="https://trustwallet.com/assets/images/trust_logotype.svg" alt="Trust Wallet"/>](https://trustwallet.com)

[Coinpaprika](https://coinpaprika.com/)
| [IFWallet](https://www.ifwallet.com/)
| [crypto.com](https://crypto.com)
| [Alice](https://www.alicedapp.com/)
| [Frontier](https://frontier.xyz/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class CoinAddressDerivationTests {
DIGIBYTE -> assertEquals("dgb1qtjgmerfqwdffyf8ghcrkgy52cghsqptynmyswu", address)
ETHEREUM, SMARTCHAIN, POLYGON, OPTIMISM, ZKSYNC, ARBITRUM, ECOCHAIN, AVALANCHECCHAIN, XDAI,
FANTOM, CELO, CRONOSCHAIN, SMARTBITCOINCASH, KUCOINCOMMUNITYCHAIN, BOBA, METIS,
AURORA, EVMOS, MOONRIVER, MOONBEAM, KAVAEVM, KLAYTN, METER, OKXCHAIN, POLYGONZKEVM, SCROLL, CONFLUXESPACE, -> assertEquals("0x8f348F300873Fd5DA36950B2aC75a26584584feE", address)
AURORA, EVMOS, MOONRIVER, MOONBEAM, KAVAEVM, KLAYTN, METER, OKXCHAIN, POLYGONZKEVM, SCROLL,
CONFLUXESPACE, ACALAEVM, OPBNBTESTNET -> assertEquals("0x8f348F300873Fd5DA36950B2aC75a26584584feE", address)
RONIN -> assertEquals("ronin:8f348F300873Fd5DA36950B2aC75a26584584feE", address)
ETHEREUMCLASSIC -> assertEquals("0x078bA3228F3E6C08bEEac9A005de0b7e7089aD1c", address)
GOCHAIN -> assertEquals("0x5940ce4A14210d4Ccd0ac206CE92F21828016aC2", address)
Expand Down Expand Up @@ -94,6 +95,7 @@ class CoinAddressDerivationTests {
HARMONY -> assertEquals("one12fk20wmvgypdkn59n4hq8e3aa5899xfx4vsu09", address)
SOLANA -> assertEquals("2bUBiBNZyD29gP1oV6de7nxowMLoDBtopMMTGgMvjG5m", address)
ALGORAND -> assertEquals("JTJWO524JXIHVPGBDWFLJE7XUIA32ECOZOBLF2QP3V5TQBT3NKZSCG67BQ", address)
ACALA -> assertEquals("25GGezx3LWFQj6HZpYzoWoVzLsHojGtybef3vthC9nd19ms3", address)
KUSAMA -> assertEquals("G9xV2EatmrjRC1FLPexc3ddqNRRzCsAdURU8RFiAAJX6ppY", address)
POLKADOT -> assertEquals("13nN6BGAoJwd7Nw1XxeBCx5YcBXuYnL94Mh7i3xBprqVSsFk", address)
PIVX -> assertEquals("D81AqC8zKma3Cht4TbVuh4jyVVyLkZULCm", address)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.trustwallet.core.app.blockchains

import com.trustwallet.core.app.utils.toHexByteArray
import wallet.core.jni.CoinType
import wallet.core.jni.Curve
import wallet.core.jni.PublicKey
import wallet.core.jni.Purpose
import wallet.core.jni.Derivation

import org.junit.Assert.assertEquals
import org.junit.Test

import wallet.core.jni.PublicKeyType


class TestCoinType {
Expand Down Expand Up @@ -55,4 +57,12 @@ class TestCoinType {
res = CoinType.createFromValue(CoinType.SOLANA.value()).derivationPathWithDerivation(Derivation.SOLANASOLANA).toString()
assertEquals(res, "m/44'/501'/0'/0'")
}

@Test
fun testDeriveAddressFromPublicKeyAndDerivation() {
val publicKey = PublicKey("0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798".toHexByteArray(), PublicKeyType.SECP256K1)

val address = CoinType.BITCOIN.deriveAddressFromPublicKeyAndDerivation(publicKey, Derivation.BITCOINSEGWIT)
assertEquals(address, "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright © 2017-2023 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.

package com.trustwallet.core.app.blockchains.acala

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 TestAcalaAddress {

init {
System.loadLibrary("TrustWalletCore")
}

@Test
fun testAddress() {
val key = PrivateKey("0x9066aa168c379a403becb235c15e7129c133c244e56a757ab07bc369288bcab0".toHexByteArray())
val pubkey = key.publicKeyEd25519
val address = AnyAddress(pubkey, CoinType.ACALA)
assertEquals(address.description(), "269ZCS3WLGydTN8ynhyhZfzJrXkePUcdhwgLQs6TWFs5wVL5")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright © 2017-2023 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.

package com.trustwallet.core.app.blockchains.acala

import com.trustwallet.core.app.utils.Numeric
import com.trustwallet.core.app.utils.toHexBytesInByteString
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.java.AnySigner
import wallet.core.jni.CoinType
import wallet.core.jni.proto.Polkadot

class TestAcalaSigner {

init {
System.loadLibrary("TrustWalletCore")
}

@Test
fun AcalaTransactionSigning() {
val transferCallIndices = Polkadot.CallIndices.newBuilder().apply {
custom = Polkadot.CustomCallIndices.newBuilder().apply {
moduleIndex = 0x0a
methodIndex = 0x00
}.build()
}

val call = Polkadot.Balance.Transfer.newBuilder().apply {
value = "0xe8d4a51000".toHexBytesInByteString() // 1 ACA
toAddress = "25Qqz3ARAvnZbahGZUzV3xpP1bB3eRrupEprK7f2FNbHbvsz"
callIndices = transferCallIndices.build()
}

val acalaGenesisHashStr = "0xfc41b9bd8ef8fe53d58c7ea67c794c7ec9a73daf05e6d54b14ff6342c99ba64c".toHexBytesInByteString()

val input = Polkadot.SigningInput.newBuilder().apply {
genesisHash = acalaGenesisHashStr
blockHash = "0x707ffa05b7dc6cdb6356bd8bd51ff20b2757c3214a76277516080a10f1bc7537".toHexBytesInByteString()
nonce = 0
specVersion = 2170
network = CoinType.ACALA.ss58Prefix()
transactionVersion = 2
privateKey = "9066aa168c379a403becb235c15e7129c133c244e56a757ab07bc369288bcab0".toHexBytesInByteString()
era = Polkadot.Era.newBuilder().apply {
blockNumber = 3893613
period = 64
}.build()
balanceCall = Polkadot.Balance.newBuilder().apply {
transfer = call.build()
}.build()
multiAddress = true
}

val output = AnySigner.sign(input.build(), CoinType.ACALA, Polkadot.SigningOutput.parser())
val encoded = Numeric.toHexString(output.encoded.toByteArray())

// https://acala.subscan.io/extrinsic/3893620-3
val expected = "0x41028400e9590e4d99264a14a85e21e69537e4a64f66a875d38cb8f76b305f41fabe24a900dd54466dffd1e3c80b76013e9459fbdcd17805bd5fdbca0961a643bad1cbd2b7fe005c62c51c18b67f31eb9e61b187a911952fee172ef18402d07c703eec3100d50200000a0000c8c602ded977c56076ae38d98026fa669ca10d6a2b5a0bfc4086ae7668ed1c60070010a5d4e8"
assertEquals(encoded, expected)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright © 2017-2023 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.

package com.trustwallet.core.app.blockchains.acalaevm

import com.trustwallet.core.app.utils.toHexByteArray
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.*

class TestAcalaEVMAddress {

init {
System.loadLibrary("TrustWalletCore")
}

@Test
fun testAddress() {
val key = PrivateKey("828c4c48c2cef521f0251920891ed79e871faa24f64f43cde83d07bc99f8dbf0".toHexByteArray())
val pubkey = key.getPublicKeySecp256k1(false)
val address = AnyAddress(pubkey, CoinType.ACALAEVM)
val expected = AnyAddress("0xe32DC46bfBF78D1eada7b0a68C96903e01418D64", CoinType.ACALAEVM)

assertEquals(address.description(), expected.description())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.java.AnySigner
import wallet.core.jni.*
import wallet.core.jni.Cardano.getByronAddress
import wallet.core.jni.Cardano.getStakingAddress
import wallet.core.jni.Cardano.outputMinAdaAmount
import wallet.core.jni.CoinType.CARDANO
Expand Down Expand Up @@ -75,6 +76,60 @@ class TestCardanoSigning {
assertEquals(Numeric.toHexString(txid.toByteArray()), "0x9b5b15e133cd73ccaa85307d2986aebc846505118a2eb4e6111e6b4b67d1f389");
}

/// Successfully broadcasted:
/// https://cardanoscan.io/transaction/0203ce2c91f59f169a26e9ef91254639d2b7911afac9c7c0ae64539f88ba46a5
@Test
fun testSignTransferFromLegacy() {
val privateKey = PrivateKey("98f266d1aac660179bc2f456033941238ee6b2beb8ed0f9f34c9902816781f5a9903d1d395d6ab887b65ea5e344ef09b449507c21a75f0ce8c59d0ed1c6764eba7f484aa383806735c46fd769c679ee41f8952952036a6e2338ada940b8a91f4e890ca4eb6bec44bf751b5a843174534af64d6ad1f44e0613db78a7018781f5aa151d2997f52059466b715d8eefab30a78b874ae6ef4931fa58bb21ef8ce2423d46f19d0fbf75afb0b9a24e31d533f4fd74cee3b56e162568e8defe37123afc4".toHexByteArray())
var publicKey = privateKey.publicKeyEd25519Cardano
var byronAddress = wallet.core.jni.Cardano.getByronAddress(publicKey)

assertEquals(byronAddress, "Ae2tdPwUPEZ6vkqxSjJxaQYmDxHf5DTnxtZ67pFLJGTb9LTnCGkDP6ca3f8")

val message = Cardano.Transfer.newBuilder()
.setToAddress("addr1q90uh2eawrdc9vaemftgd50l28yrh9lqxtjjh4z6dnn0u7ggasexxdyyk9f05atygnjlccsjsggtc87hhqjna32fpv5qeq96ls")
.setChangeAddress("addr1qx55ymlqemndq8gluv40v58pu76a2tp4mzjnyx8n6zrp2vtzrs43a0057y0edkn8lh9su8vh5lnhs4npv6l9tuvncv8swc7t08")
.setAmount(3_000_000)
.build()
val input = Cardano.SigningInput.newBuilder()
.setTransferMessage(message)
.setTtl(190000000)

input.addPrivateKey(ByteString.copyFrom(privateKey.data()))

val outpoint1 = Cardano.OutPoint.newBuilder()
.setTxHash(ByteString.copyFrom(Numeric.hexStringToByteArray("8316e5007d61fb90652cabb41141972a38b5bc60954d602cf843476aa3f67f63")))
.setOutputIndex(0)
.build()
val utxo1 = Cardano.TxInput.newBuilder()
.setOutPoint(outpoint1)
.setAddress("Ae2tdPwUPEZ6vkqxSjJxaQYmDxHf5DTnxtZ67pFLJGTb9LTnCGkDP6ca3f8")
.setAmount(2_500_000)
.build()
input.addUtxos(utxo1)

val outpoint2 = Cardano.OutPoint.newBuilder()
.setTxHash(ByteString.copyFrom(Numeric.hexStringToByteArray("e29392c59c903fefb905730587d22cae8bda30bd8d9aeec3eca082ae77675946")))
.setOutputIndex(0)
.build()
val utxo2 = Cardano.TxInput.newBuilder()
.setOutPoint(outpoint2)
.setAddress("Ae2tdPwUPEZ6vkqxSjJxaQYmDxHf5DTnxtZ67pFLJGTb9LTnCGkDP6ca3f8")
.setAmount(1_700_000)
.build()
input.addUtxos(utxo2)

val output = AnySigner.sign(input.build(), CARDANO, Cardano.SigningOutput.parser())
assertEquals(output.error, SigningError.OK)

val encoded = output.encoded
assertEquals(Numeric.toHexString(encoded.toByteArray()),
"0x83a400828258208316e5007d61fb90652cabb41141972a38b5bc60954d602cf843476aa3f67f6300825820e29392c59c903fefb905730587d22cae8bda30bd8d9aeec3eca082ae77675946000182825839015fcbab3d70db82b3b9da5686d1ff51c83b97e032e52bd45a6ce6fe7908ec32633484b152fa756444e5fc62128210bc1fd7b8253ec5490b281a002dc6c082583901a9426fe0cee6d01d1fe32af650e1e7b5d52c35d8a53218f3d0861531621c2b1ebdf4f11f96da67fdcb0e1d97a7e778566166be55f193c30f1a000f9ec1021a0002b0bf031a0b532b80a20081825820d163c8c4f0be7c22cd3a1152abb013c855ea614b92201497a568c5d93ceeb41e58406a23ab9267867fbf021c1cb2232bc83d2cdd663d651d22d59b6cddbca5cb106d4db99da50672f69a2309ca8a329a3f9576438afe4538b013de4591a6dfcd4d090281845820d163c8c4f0be7c22cd3a1152abb013c855ea614b92201497a568c5d93ceeb41e58406a23ab9267867fbf021c1cb2232bc83d2cdd663d651d22d59b6cddbca5cb106d4db99da50672f69a2309ca8a329a3f9576438afe4538b013de4591a6dfcd4d095820a7f484aa383806735c46fd769c679ee41f8952952036a6e2338ada940b8a91f441a0f6");

val txid = output.txId
assertEquals(Numeric.toHexString(txid.toByteArray()), "0x0203ce2c91f59f169a26e9ef91254639d2b7911afac9c7c0ae64539f88ba46a5");
}

@Test
fun testSignTransferToken1() {
val toToken = Cardano.TokenAmount.newBuilder()
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,19 @@ class TestWebAuthn {
val result = WebAuthn.getPublicKey(attestationObject).data()
assertEquals(Numeric.toHexString(result), "0x04a620a8cfc88fd062b11eab31663e56cad95278bef612959be214d98779f645b84e7b905b42917570148b0432f99ba21f2e7eebe018cbf837247e38150a89f771")
}

@Test
fun testGetRSValues() {
val signature = Numeric.hexStringToByteArray("0x30440220766589b461a838748708cdf88444b21b1fa52b57d70671b4f9bf60ad14b372ec022020cc439c9c20661bfa39bbea24a900ec1484b2395eb065ead8ef4e273144a57d")
val result = WebAuthn.getRSValues(signature)
assertEquals(Numeric.toHexString(result), "0x766589b461a838748708cdf88444b21b1fa52b57d70671b4f9bf60ad14b372ec20cc439c9c20661bfa39bbea24a900ec1484b2395eb065ead8ef4e273144a57d")
}

@Test
fun testReconstructOriginalMessage() {
val authenticatorData = Numeric.hexStringToByteArray("0x1a70842af8c1feb7133b81e6a160a6a2be45ee057f0eb6d3f7f5126daa202e071d00000000")
val clientDataJSON = Numeric.hexStringToByteArray("0x7b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a224e5549794f5545774d6b45744e554535517930304d6b5a424c546847516a4174517a52474f4441794d3045304f546b30222c226f726967696e223a2268747470733a2f2f747275737477616c6c65742e636f6d227d")
val result = WebAuthn.reconstructOriginalMessage(authenticatorData, clientDataJSON)
assertEquals(Numeric.toHexString(result), "0x3254cdbd677e6e31e75d2135bad0cf56440d7c6b108c141a3509d76ce45c6731")
}
}
2 changes: 1 addition & 1 deletion codegen/lib/kotlin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def self.convert_calling_type_ios(t)
"#{if t.is_nullable then '?' else '' end}.toTwString()"
else
if t.is_enum
"#{if t.is_nullable then '?' else '' end}.value"
"#{if t.is_nullable then '?' else '' end}.nativeValue"
elsif t.is_class
"#{if t.is_nullable then '?' else '' end}.pointer"
else
Expand Down
6 changes: 3 additions & 3 deletions codegen/lib/templates/kotlin/android_enum.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<% has_string = entity.cases.all? { |c| !c.string.nil? } -%>
actual enum class <%= entity.name %>(
@get:JvmName("value")
val value: UInt,
actual val value: UInt,
<% if has_string -%>
actual val stringValue: String,
<% end -%>
Expand Down Expand Up @@ -34,10 +34,10 @@ actual enum class <%= entity.name %>(
<%# Value -%>
<% if entity.cases.any? { |e| !e.value.nil? } -%>

companion object {
actual companion object {
@JvmStatic
@JvmName("createFromValue")
fun fromValue(value: UInt): <%= entity.name %>? =
actual fun fromValue(value: UInt): <%= entity.name %>? =
values().firstOrNull { it.value == value }
}
<% end -%>
Expand Down
5 changes: 5 additions & 0 deletions codegen/lib/templates/kotlin/common_enum.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ expect enum class <%= entity.name %> {
<% end -%>
;

val value: UInt
<% if has_string -%>
val stringValue: String
<% end -%>
Expand All @@ -25,5 +26,9 @@ expect enum class <%= entity.name %> {
<%- end -%>
<%# Value -%>
<% if entity.cases.any? { |e| !e.value.nil? } -%>

companion object {
fun fromValue(value: UInt): <%= entity.name %>?
}
<% end -%>
}
Loading

0 comments on commit 5a6d8c6

Please sign in to comment.