Skip to content

Commit

Permalink
Merge pull request #5 from pactus-project/pactus
Browse files Browse the repository at this point in the history
Pactus
  • Loading branch information
b00f authored Oct 30, 2024
2 parents 26aa428 + 2e8467f commit acbefb1
Show file tree
Hide file tree
Showing 151 changed files with 4,764 additions and 2,533 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codegen-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:

jobs:
test:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
- name: Lint Dockerfile
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linux-ci-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
permissions:
contents: read
checks: write
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
# Run Rust tests in WASM.
test-wasm:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux-ci-sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ concurrency:
jobs:
build:
if: github.event.pull_request.draft == false && github.event.pull_request.head.repo.fork == false
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linux-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ concurrency:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
if: github.event.pull_request.draft == false
steps:
- 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
11 changes: 2 additions & 9 deletions .github/workflows/linux-sampleapp-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ concurrency:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
if: github.event.pull_request.draft == false
steps:
- 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
2 changes: 1 addition & 1 deletion .github/workflows/wasm-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v3
Expand Down
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/4.0.33/WalletCore.xcframework.zip",
checksum: "2fb8b833047b9697bba6ade66a9bdeede622b2fe0fb7a9b90cb9edb4651ec866"
url: "https://github.com/trustwallet/wallet-core/releases/download/4.1.12/WalletCore.xcframework.zip",
checksum: "1632bbbab1c6a588689eec77a24e1468d9a6746968652cf0a7e669e996c3d24d"
),
.binaryTarget(
name: "SwiftProtobuf",
url: "https://github.com/trustwallet/wallet-core/releases/download/4.0.33/SwiftProtobuf.xcframework.zip",
checksum: "05557735dd607c5a369dc378eb3f299504b880614ef13f136a028ecd320b0e4d"
url: "https://github.com/trustwallet/wallet-core/releases/download/4.1.12/SwiftProtobuf.xcframework.zip",
checksum: "33d80c20428c9db4fcf99d1272ba19655f7c6ee7e5b1809fa8a7e7d4aa1b222b"
)
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,6 @@ class CoinAddressDerivationTests {
TIA -> assertEquals("celestia142j9u5eaduzd7faumygud6ruhdwme98qpwmfv7", address)
NATIVEZETACHAIN -> assertEquals("zeta13u6g7vqgw074mgmf2ze2cadzvkz9snlwywj304", address)
DYDX -> assertEquals("dydx142j9u5eaduzd7faumygud6ruhdwme98qeayaky", address)
PACTUS -> assertEquals("pc1r7ys2g5a4xc2qtm0t4q987m4mvs57w5g0v4pvzg", address)
}
}
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
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2017 Trust Wallet.

package com.trustwallet.core.app.blockchains.pactus

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

init {
System.loadLibrary("TrustWalletCore")
}

@Test
fun testAddress() {
val key = PrivateKey("4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6".toHexByteArray())
val pubkey = key.publicKeyEd25519
val address = AnyAddress(pubkey, CoinType.PACTUS)
val expected = AnyAddress("pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr", CoinType.PACTUS)

assertEquals(pubkey.data().toHex(), "0x95794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa")
assertEquals(address.description(), expected.description())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2017 Trust Wallet.

package com.trustwallet.core.app.blockchains.pactus

import com.google.protobuf.ByteString
import com.trustwallet.core.app.utils.toHexByteArray
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.PrivateKey
import wallet.core.java.AnySigner
import wallet.core.jni.CoinType
import wallet.core.jni.CoinType.PACTUS
import wallet.core.jni.proto.Pactus
import wallet.core.jni.proto.Pactus.SigningOutput
import com.trustwallet.core.app.utils.Numeric
import org.junit.Assert.assertArrayEquals

class TestPactusSigner {

init {
System.loadLibrary("TrustWalletCore")
}

@Test
fun testPactusTransactionSigning() {
val signingInput = Pactus.SigningInput.newBuilder()
signingInput.apply {
privateKey = ByteString.copyFrom(PrivateKey("4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6".toHexByteArray()).data())
transaction = Pactus.TransactionMessage.newBuilder().apply {
lockTime = 0x00030201
fee = 1000
memo = "test"
transfer = Pactus.TransferPayload.newBuilder().apply {
sender = "pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr"
receiver = "pc1r0g22ufzn8qtw0742dmfglnw73e260hep0k3yra"
amount = 20000
}.build()
}.build()
}

val output = AnySigner.sign(signingInput.build(), PACTUS, SigningOutput.parser())

assertEquals(
"0x34cd4656a98f7eb996e83efdc384cefbe3a9c52dca79a99245b4eacc0b0b4311",
Numeric.toHexString(output.transactionId.toByteArray())
)

assertEquals(
"0x50ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd09",
Numeric.toHexString(output.signature.toByteArray())
)

assertEquals(
"0x000101020300e807047465737401037098338e0b6808119dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df21a09c0150ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd0995794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa",
Numeric.toHexString(output.signedTransactionData.toByteArray())
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ impl CoinEntry for {BLOCKCHAIN}Entry {
}

#[inline]
fn parse_address_unchecked(
&self,
_coin: &dyn CoinContext,
address: &str,
) -> AddressResult<Self::Address> {
fn parse_address_unchecked(&self, address: &str) -> AddressResult<Self::Address> {
{BLOCKCHAIN}Address::from_str(address)
}

Expand Down
2 changes: 1 addition & 1 deletion codegen/lib/code_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def render_kotlin_jni_c
def render(file, locals = {})
@locals = locals
path = File.expand_path(file, File.join(File.dirname(__FILE__), 'templates'))
template = ERB.new(File.read(path), nil, '-')
template = ERB.new(File.read(path), trim_mode: '-')
template.result(binding)
end

Expand Down
1 change: 1 addition & 0 deletions docs/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ This list is generated from [./registry.json](../registry.json)
| 14001 | WAX | WAXP | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/wax/info/logo.png" width="32" /> | <http://wax.io> |
| 18000 | Meter | MTR | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/meter/info/logo.png" width="32" /> | <https://meter.io/> |
| 19167 | Flux | FLUX | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/zelcash/info/logo.png" width="32" /> | <https://runonflux.io> |
| 21888 | Pactus | PAC | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/pactus/info/logo.png" width="32" /> | <https://pactus.org> |
| 52752 | Celo | CELO | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/celo/info/logo.png" width="32" /> | <https://celo.org> |
| 59144 | Linea | ETH | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/linea/info/logo.png" width="32" /> | <https://linea.build> |
| 81457 | Blast | ETH | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/blast/info/logo.png" width="32" /> | <https://blast.io> |
Expand Down
2 changes: 2 additions & 0 deletions include/TrustWalletCore/TWBlockchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ enum TWBlockchain {
TWBlockchainInternetComputer = 52,
TWBlockchainNativeEvmos = 53, // Cosmos
TWBlockchainNativeInjective = 54, // Cosmos
TWBlockchainBitcoinCash = 55,
TWBlockchainPactus = 56,
};

TW_EXTERN_C_END
1 change: 1 addition & 0 deletions include/TrustWalletCore/TWCoinType.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ enum TWCoinType {
TWCoinTypeBlast = 81457,
TWCoinTypeBounceBit = 6001,
TWCoinTypeZkLinkNova = 810180,
TWCoinTypePactus = 21888,
// end_of_tw_coin_type_marker_do_not_modify
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,6 @@ class CoinAddressDerivationTests {
Tia -> "celestia142j9u5eaduzd7faumygud6ruhdwme98qpwmfv7"
NativeZetaChain -> "zeta13u6g7vqgw074mgmf2ze2cadzvkz9snlwywj304"
Dydx -> "dydx142j9u5eaduzd7faumygud6ruhdwme98qeayaky"
Pactus -> "pc1r7ys2g5a4xc2qtm0t4q987m4mvs57w5g0v4pvzg"
}
}
Loading

0 comments on commit acbefb1

Please sign in to comment.