Skip to content

Commit

Permalink
Merge branch 'master' into fix-aptos-entry-function
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshiotomakan authored Oct 16, 2024
2 parents cd08d33 + e111f03 commit e064eca
Show file tree
Hide file tree
Showing 312 changed files with 4,792 additions and 3,147 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/linux-ci-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ jobs:
./tools/release-size measure-rust > release-report.json
- name: Upload release report
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: release_report
path: release-report.json

# Download previous release report, compare the release binary sizes, and post/update a comment at the Pull Request.
- name: Download previous release report
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false
uses: dawidd6/action-download-artifact@v3
uses: dawidd6/action-download-artifact@v6
with:
commit: ${{github.event.pull_request.base.sha}}
path: previous
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v3
- name: Install system dependencies
run: |
tools/install-sys-dependencies-linux ci
tools/install-sys-dependencies-linux
tools/install-rust-dependencies
- name: Cache internal dependencies
id: internal_cache
Expand Down
9 changes: 1 addition & 8 deletions .github/workflows/linux-sampleapp-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v3
- name: Install system dependencies
run: |
tools/install-sys-dependencies-linux ci
tools/install-sys-dependencies-linux
tools/install-rust-dependencies
- name: Cache internal dependencies
id: internal_cache
Expand Down Expand Up @@ -61,13 +61,6 @@ jobs:
env:
CC: /usr/bin/clang
CXX: /usr/bin/clang++
- name: Build, run, and test devconsole.ts
run: |
cd samples/typescript/devconsole.ts
npm install
npm run build
echo -e "help() \n .exit" | npm run start
npm run test
- name: Install Go
env:
GO_VERSION: 1.19
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CoinAddressDerivationTests {

ETHEREUM, SMARTCHAIN, POLYGON, OPTIMISM, ZKSYNC, ARBITRUM, ARBITRUMNOVA, ECOCHAIN, AVALANCHECCHAIN, XDAI,
FANTOM, CELO, CRONOSCHAIN, SMARTBITCOINCASH, KUCOINCOMMUNITYCHAIN, BOBA, METIS,
AURORA, EVMOS, MOONRIVER, MOONBEAM, KAVAEVM, KLAYTN, METER, OKXCHAIN, POLYGONZKEVM, SCROLL,
AURORA, EVMOS, MOONRIVER, MOONBEAM, KAVAEVM, KAIA, METER, OKXCHAIN, POLYGONZKEVM, SCROLL,
CONFLUXESPACE, ACALAEVM, OPBNB, NEON, BASE, LINEA, GREENFIELD, MANTLE, ZENEON, MANTAPACIFIC,
ZETAEVM, MERLIN, LIGHTLINK, BLAST, BOUNCEBIT, ZKLINKNOVA,
-> assertEquals("0x8f348F300873Fd5DA36950B2aC75a26584584feE", address)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.trustwallet.core.app.blockchains.bitcoin

import com.google.protobuf.ByteString
import com.trustwallet.core.app.utils.Numeric
import com.trustwallet.core.app.utils.toHex
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.java.AnySigner
import wallet.core.jni.BitcoinScript
import wallet.core.jni.BitcoinSigHashType
import wallet.core.jni.CoinType
import wallet.core.jni.CoinType.BITCOIN
import wallet.core.jni.Hash
import wallet.core.jni.PrivateKey
import wallet.core.jni.PublicKey
import wallet.core.jni.PublicKeyType
import wallet.core.jni.proto.Bitcoin
import wallet.core.jni.proto.BitcoinV2
import wallet.core.jni.proto.Common.SigningError

class TestBitcoinPsbt {

init {
System.loadLibrary("TrustWalletCore")
}

@Test
fun testSignThorSwap() {
// Successfully broadcasted tx: https://mempool.space/tx/634a416e82ac710166725f6a4090ac7b5db69687e86b2d2e38dcb3d91c956c32

val privateKey = "f00ffbe44c5c2838c13d2778854ac66b75e04eb6054f0241989e223223ad5e55".toHexBytesInByteString()
val psbt = "70736274ff0100bc0200000001147010db5fbcf619067c1090fec65c131443fbc80fb4aaeebe940e44206098c60000000000ffffffff0360ea000000000000160014f22a703617035ef7f490743d50f26ae08c30d0a70000000000000000426a403d3a474149412e41544f4d3a636f736d6f7331737377797a666d743675396a373437773537753438746778646575393573757a666c6d7175753a303a743a35303e12000000000000160014b139199ec796f36fc42e637f42da8e3e6720aa9d000000000001011f6603010000000000160014b139199ec796f36fc42e637f42da8e3e6720aa9d00000000".toHexBytesInByteString()

val input = BitcoinV2.SigningInput.newBuilder()
.setPsbt(BitcoinV2.Psbt.newBuilder().setPsbt(psbt))
.addPrivateKeys(privateKey)
.build()

val legacyInput = Bitcoin.SigningInput.newBuilder()
.setSigningV2(input)
.build()

val legacyOutput = AnySigner.sign(legacyInput, BITCOIN, Bitcoin.SigningOutput.parser())
val output = legacyOutput.signingResultV2

assertEquals(output.error, SigningError.OK)
assertEquals(
output.psbt.psbt.toByteArray().toHex(),
"0x70736274ff0100bc0200000001147010db5fbcf619067c1090fec65c131443fbc80fb4aaeebe940e44206098c60000000000ffffffff0360ea000000000000160014f22a703617035ef7f490743d50f26ae08c30d0a70000000000000000426a403d3a474149412e41544f4d3a636f736d6f7331737377797a666d743675396a373437773537753438746778646575393573757a666c6d7175753a303a743a35303e12000000000000160014b139199ec796f36fc42e637f42da8e3e6720aa9d000000000001011f6603010000000000160014b139199ec796f36fc42e637f42da8e3e6720aa9d01086c02483045022100b1229a008f20691639767bf925d6b8956ea957ccc633ad6b5de3618733a55e6b02205774d3320489b8a57a6f8de07f561de3e660ff8e587f6ac5422c49020cd4dc9101210306d8c664ea8fd2683eebea1d3114d90e0a5429e5783ba49b80ddabce04ff28f300000000"
)
assertEquals(
output.encoded.toByteArray().toHex(),
"0x02000000000101147010db5fbcf619067c1090fec65c131443fbc80fb4aaeebe940e44206098c60000000000ffffffff0360ea000000000000160014f22a703617035ef7f490743d50f26ae08c30d0a70000000000000000426a403d3a474149412e41544f4d3a636f736d6f7331737377797a666d743675396a373437773537753438746778646575393573757a666c6d7175753a303a743a35303e12000000000000160014b139199ec796f36fc42e637f42da8e3e6720aa9d02483045022100b1229a008f20691639767bf925d6b8956ea957ccc633ad6b5de3618733a55e6b02205774d3320489b8a57a6f8de07f561de3e660ff8e587f6ac5422c49020cd4dc9101210306d8c664ea8fd2683eebea1d3114d90e0a5429e5783ba49b80ddabce04ff28f300000000"
)
assertEquals(
output.txid.toByteArray().toHex(),
"0x634a416e82ac710166725f6a4090ac7b5db69687e86b2d2e38dcb3d91c956c32"
)
}

@Test
fun testPlanThorSwap() {
// Successfully broadcasted tx: https://mempool.space/tx/634a416e82ac710166725f6a4090ac7b5db69687e86b2d2e38dcb3d91c956c32

val privateKey = PrivateKey("f00ffbe44c5c2838c13d2778854ac66b75e04eb6054f0241989e223223ad5e55".toHexBytes())
val publicKey = privateKey.getPublicKeySecp256k1(true)
val psbt = "70736274ff0100bc0200000001147010db5fbcf619067c1090fec65c131443fbc80fb4aaeebe940e44206098c60000000000ffffffff0360ea000000000000160014f22a703617035ef7f490743d50f26ae08c30d0a70000000000000000426a403d3a474149412e41544f4d3a636f736d6f7331737377797a666d743675396a373437773537753438746778646575393573757a666c6d7175753a303a743a35303e12000000000000160014b139199ec796f36fc42e637f42da8e3e6720aa9d000000000001011f6603010000000000160014b139199ec796f36fc42e637f42da8e3e6720aa9d00000000".toHexBytesInByteString()

val input = BitcoinV2.SigningInput.newBuilder()
.setPsbt(BitcoinV2.Psbt.newBuilder().setPsbt(psbt))
.addPublicKeys(ByteString.copyFrom(publicKey.data()))
.build()

val legacyInput = Bitcoin.SigningInput.newBuilder()
.setSigningV2(input)
.build()

val legacyPlan = AnySigner.plan(legacyInput, BITCOIN, Bitcoin.TransactionPlan.parser())
val plan = legacyPlan.planningResultV2

assertEquals(plan.error, SigningError.OK)

assertEquals(plan.getInputs(0).receiverAddress, "bc1qkyu3n8k8jmekl3pwvdl59k5w8enjp25akz2r3z")
assertEquals(plan.getInputs(0).value, 66_406)

// Vault transfer
assertEquals(plan.getOutputs(0).toAddress, "bc1q7g48qdshqd000aysws74pun2uzxrp598gcfum0")
assertEquals(plan.getOutputs(0).value, 60_000)

// OP_RETURN
assertEquals(
plan.getOutputs(1).customScriptPubkey.toByteArray().toHex(),
"0x6a403d3a474149412e41544f4d3a636f736d6f7331737377797a666d743675396a373437773537753438746778646575393573757a666c6d7175753a303a743a3530"
)
assertEquals(plan.getOutputs(1).value, 0)

// Change output
assertEquals(plan.getOutputs(2).toAddress, "bc1qkyu3n8k8jmekl3pwvdl59k5w8enjp25akz2r3z")
assertEquals(plan.getOutputs(2).value, 4_670)

assertEquals(plan.feeEstimate, 1736)
// Please note that `change` in PSBT planning is always 0.
// That's because we aren't able to determine which output is an actual change from PSBT.
assertEquals(plan.change, 0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,21 @@ class TestBitcoinSigning {
p2Wpkh = BitcoinV2.PublicKeyOrHash.newBuilder().setPubkey(publicKey).build()
})

val signingInput = BitcoinV2.SigningInput.newBuilder()
val builder = BitcoinV2.TransactionBuilder.newBuilder()
.setVersion(BitcoinV2.TransactionVersion.V2)
.addPrivateKeys(ByteString.copyFrom(privateKeyData))
.addInputs(utxo0)
.addOutputs(out0)
.addOutputs(changeOutput)
.setInputSelector(BitcoinV2.InputSelector.UseAll)
.setFixedDustThreshold(dustSatoshis)
val signingInput = BitcoinV2.SigningInput.newBuilder()
.setBuilder(builder)
.addPrivateKeys(ByteString.copyFrom(privateKeyData))
.setChainInfo(BitcoinV2.ChainInfo.newBuilder().apply {
p2PkhPrefix = 0
p2ShPrefix = 5
})
.setDangerousUseFixedSchnorrRng(true)
.setFixedDustThreshold(dustSatoshis)
.build()

val legacySigningInput = Bitcoin.SigningInput.newBuilder().apply {
Expand Down Expand Up @@ -256,18 +258,20 @@ class TestBitcoinSigning {
p2Wpkh = BitcoinV2.PublicKeyOrHash.newBuilder().setPubkey(publicKey).build()
})

val signingInput = BitcoinV2.SigningInput.newBuilder()
val builder = BitcoinV2.TransactionBuilder.newBuilder()
.setVersion(BitcoinV2.TransactionVersion.V2)
.addPrivateKeys(ByteString.copyFrom(privateKeyData))
.addInputs(utxo0)
.addOutputs(out0)
.setInputSelector(BitcoinV2.InputSelector.UseAll)
.setFixedDustThreshold(dustSatoshis)
val signingInput = BitcoinV2.SigningInput.newBuilder()
.setBuilder(builder)
.addPrivateKeys(ByteString.copyFrom(privateKeyData))
.setChainInfo(BitcoinV2.ChainInfo.newBuilder().apply {
p2PkhPrefix = 0
p2ShPrefix = 5
})
.setDangerousUseFixedSchnorrRng(true)
.setFixedDustThreshold(dustSatoshis)
.build()

val legacySigningInput = Bitcoin.SigningInput.newBuilder().apply {
Expand Down Expand Up @@ -326,20 +330,22 @@ class TestBitcoinSigning {
p2Wpkh = BitcoinV2.PublicKeyOrHash.newBuilder().setPubkey(publicKey).build()
})

val signingInput = BitcoinV2.SigningInput.newBuilder()
val builder = BitcoinV2.TransactionBuilder.newBuilder()
.setVersion(BitcoinV2.TransactionVersion.V2)
.addPrivateKeys(ByteString.copyFrom(privateKeyData))
.addInputs(utxo0)
.addInputs(utxo1)
.addOutputs(out0)
.addOutputs(changeOutput)
.setInputSelector(BitcoinV2.InputSelector.UseAll)
.setFixedDustThreshold(dustSatoshis)
val signingInput = BitcoinV2.SigningInput.newBuilder()
.setBuilder(builder)
.addPrivateKeys(ByteString.copyFrom(privateKeyData))
.setChainInfo(BitcoinV2.ChainInfo.newBuilder().apply {
p2PkhPrefix = 0
p2ShPrefix = 5
})
.setDangerousUseFixedSchnorrRng(true)
.setFixedDustThreshold(dustSatoshis)
.build()

val legacySigningInput = Bitcoin.SigningInput.newBuilder().apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.trustwallet.core.app.blockchains.bitcoincash

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.BitcoinSigHashType
import wallet.core.jni.CoinType
import wallet.core.jni.proto.Bitcoin
import wallet.core.jni.proto.BitcoinV2
import wallet.core.jni.proto.Common.SigningError

class TestBitcoinCashSigning {

init {
System.loadLibrary("TrustWalletCore")
}

@Test
fun testSignV2P2PKH() {
val privateKey = "7fdafb9db5bc501f2096e7d13d331dc7a75d9594af3d251313ba8b6200f4e384".toHexBytesInByteString()

val utxo1 = BitcoinV2.Input.newBuilder().apply {
outPoint = BitcoinV2.OutPoint.newBuilder().apply {
hash = "e28c2b955293159898e34c6840d99bf4d390e2ee1c6f606939f18ee1e2000d05".toHexBytesInByteString()
vout = 2
}.build()
value = 5151
sighashType = BitcoinSigHashType.ALL.value() + BitcoinSigHashType.FORK.value()
receiverAddress = "bitcoincash:qzhlrcrcne07x94h99thved2pgzdtv8ccujjy73xya"
}

val out1 = BitcoinV2.Output.newBuilder().apply {
value = 600
// Legacy address
toAddress = "1Bp9U1ogV3A14FMvKbRJms7ctyso4Z4Tcx"
}
val changeOutputExplicit = BitcoinV2.Output.newBuilder().apply {
value = 4325
// Legacy address
toAddress = "qz0q3xmg38sr94rw8wg45vujah7kzma3cskxymnw06"
}

val builder = BitcoinV2.TransactionBuilder.newBuilder()
.setVersion(BitcoinV2.TransactionVersion.V1)
.addInputs(utxo1)
.addOutputs(out1)
.addOutputs(changeOutputExplicit)
.setInputSelector(BitcoinV2.InputSelector.UseAll)
.setFixedDustThreshold(546)
.build()

val input = BitcoinV2.SigningInput.newBuilder()
.addPrivateKeys(privateKey)
.setBuilder(builder)
.setChainInfo(BitcoinV2.ChainInfo.newBuilder().apply {
p2PkhPrefix = 0
p2ShPrefix = 5
hrp = "bitcoincash"
})
.build()

val legacyInput = Bitcoin.SigningInput.newBuilder()
.setSigningV2(input)
// `CoinType` must be set to be handled correctly.
.setCoinType(CoinType.BITCOINCASH.value())
.build()

val outputLegacy = AnySigner.sign(legacyInput, CoinType.BITCOINCASH, Bitcoin.SigningOutput.parser())
assertEquals(outputLegacy.error, SigningError.OK)
assert(outputLegacy.hasSigningResultV2())

val output = outputLegacy.signingResultV2
assertEquals(output.error, SigningError.OK)
assertEquals(
Numeric.toHexString(output.encoded.toByteArray()),
"0x0100000001e28c2b955293159898e34c6840d99bf4d390e2ee1c6f606939f18ee1e2000d05020000006b483045022100b70d158b43cbcded60e6977e93f9a84966bc0cec6f2dfd1463d1223a90563f0d02207548d081069de570a494d0967ba388ff02641d91cadb060587ead95a98d4e3534121038eab72ec78e639d02758e7860cdec018b49498c307791f785aa3019622f4ea5bffffffff0258020000000000001976a914769bdff96a02f9135a1d19b749db6a78fe07dc9088ace5100000000000001976a9149e089b6889e032d46e3b915a3392edfd616fb1c488ac00000000"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,14 @@ class TestTheOpenNetworkSigner {
// "This transaction deploys Doge Chatbot contract"
val commentPayload = "te6cckEBAQEANAAAZAAAAABUaGlzIHRyYW5zYWN0aW9uIGRlcGxveXMgRG9nZSBDaGF0Ym90IGNvbnRyYWN0v84vSg=="

val customPayload = TheOpenNetwork.CustomPayload.newBuilder()
.setStateInit(dogeChatbotStateInit)
.setPayload(commentPayload)
.build()

val transfer = TheOpenNetwork.Transfer.newBuilder()
.setDest(dogeChatbotDeployingAddress)
// 0.069 TON
.setAmount(69_000_000)
.setMode(TheOpenNetwork.SendMode.PAY_FEES_SEPARATELY_VALUE or TheOpenNetwork.SendMode.IGNORE_ACTION_PHASE_ERRORS_VALUE)
.setBounceable(false)
.setCustomPayload(customPayload)
.setStateInit(dogeChatbotStateInit)
.setCustomPayload(commentPayload)

val input = TheOpenNetwork.SigningInput.newBuilder()
.setPrivateKey(ByteString.copyFrom(privateKey.data()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TestLiquidStaking {
stake = LiquidStaking.Stake.newBuilder().apply {
amount = "1000000000000000000"
asset = LiquidStaking.Asset.newBuilder().apply {
stakingToken = LiquidStaking.Coin.MATIC
stakingToken = LiquidStaking.Coin.POL
}.build()
}.build()
}
Expand Down
Loading

0 comments on commit e064eca

Please sign in to comment.