Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Milerius authored Aug 17, 2023
2 parents 7a22f89 + 92b701f commit 988b1e5
Show file tree
Hide file tree
Showing 34 changed files with 1,016 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class CoinAddressDerivationTests {
CALLISTO -> assertEquals("0x3E6FFC80745E6669135a76F4A7ce6BCF02436e04", address)
DASH -> assertEquals("XqHiz8EXYbTAtBEYs4pWTHh7ipEDQcNQeT", address)
DIGIBYTE -> assertEquals("dgb1qtjgmerfqwdffyf8ghcrkgy52cghsqptynmyswu", address)
ETHEREUM, SMARTCHAIN, POLYGON, OPTIMISM, ZKSYNC, ARBITRUM, ECOCHAIN, AVALANCHECCHAIN, XDAI,
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,
CONFLUXESPACE, ACALAEVM, OPBNBTESTNET, NEON, BASE -> assertEquals("0x8f348F300873Fd5DA36950B2aC75a26584584feE", address)
CONFLUXESPACE, ACALAEVM, OPBNB, NEON, BASE, LINEA -> assertEquals("0x8f348F300873Fd5DA36950B2aC75a26584584feE", address)
RONIN -> assertEquals("ronin:8f348F300873Fd5DA36950B2aC75a26584584feE", address)
ETHEREUMCLASSIC -> assertEquals("0x078bA3228F3E6C08bEEac9A005de0b7e7089aD1c", address)
GOCHAIN -> assertEquals("0x5940ce4A14210d4Ccd0ac206CE92F21828016aC2", address)
Expand Down Expand Up @@ -145,5 +145,6 @@ class CoinAddressDerivationTests {
AKASH -> assertEquals("akash142j9u5eaduzd7faumygud6ruhdwme98qal870f", address)
NOBLE -> assertEquals("noble142j9u5eaduzd7faumygud6ruhdwme98qc8l3wa", address)
ROOTSTOCK -> assertEquals("0xA2D7065F94F838a3aB9C04D67B312056846424Df", address)
SEI -> assertEquals("sei142j9u5eaduzd7faumygud6ruhdwme98qagm0sj", address)
}
}
5 changes: 4 additions & 1 deletion docs/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ This list is generated from [./registry.json](../registry.json)
| 178 | POA Network | POA | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/poa/info/logo.png" width="32" /> | <https://poa.network> |
| 194 | EOS | EOS | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/eos/info/logo.png" width="32" /> | <http://eos.io> |
| 195 | Tron | TRX | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png" width="32" /> | <https://tron.network> |
| 204 | OpBNB | BNB | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/opbnb/info/logo.png" width="32" /> | <https://opbnb.bnbchain.org/en> |
| 235 | FIO | FIO | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/fio/info/logo.png" width="32" /> | <https://fioprotocol.io> |
| 242 | Nimiq | NIM | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/nimiq/info/logo.png" width="32" /> | <https://nimiq.com> |
| 283 | Algorand | ALGO | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/algorand/info/logo.png" width="32" /> | <https://www.algorand.com/> |
Expand Down Expand Up @@ -84,14 +85,14 @@ This list is generated from [./registry.json](../registry.json)
| 2301 | Qtum | QTUM | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/qtum/info/logo.png" width="32" /> | <https://qtum.org> |
| 2718 | Nebulas | NAS | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/nebulas/info/logo.png" width="32" /> | <https://nebulas.io> |
| 3030 | Hedera | HBAR | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/hedera/info/logo.png" width="32" /> | <https://hedera.com/> |
| 5611 | OpBNB testnet | tBNB | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/opbnb/info/logo.png" width="32" /> | <https://opbnb.bnbchain.org/en> |
| 6060 | GoChain | GO | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/gochain/info/logo.png" width="32" /> | <https://gochain.io> |
| 8453 | Base | ETH | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/base/info/logo.png" width="32" /> | <https://base.mirror.xyz/> |
| 8964 | NULS | NULS | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/nuls/info/logo.png" width="32" /> | <https://nuls.io> |
| 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> |
| 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> |
| 105105 | Stratis | STRAX | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/stratis/info/logo.png" width="32" /> | <https://www.stratisplatform.com/> |
| 534353 | Scroll | ETH | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/scroll/info/logo.png" width="32" /> | <https://scroll.io> |
| 1001088 | Metis | METIS | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/metis/info/logo.png" width="32" /> | <https://www.metis.io/> |
Expand Down Expand Up @@ -121,6 +122,7 @@ This list is generated from [./registry.json](../registry.json)
| 10008217 | Klaytn | KLAY | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/klaytn/info/logo.png" width="32" /> | <https://klaytn.foundation> |
| 10009000 | Avalanche C-Chain | AVAX | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/avalanchec/info/logo.png" width="32" /> | <https://www.avalabs.org/> |
| 10009001 | Evmos | EVMOS | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/evmos/info/logo.png" width="32" /> | <https://evmos.org/> |
| 10042170 | Arbitrum Nova | ETH | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/arbitrumnova/info/logo.png" width="32" /> | <https://nova.arbitrum.io> |
| 10042221 | Arbitrum | ETH | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/arbitrum/info/logo.png" width="32" /> | <https://arbitrum.io> |
| 11000118 | Sommelier | SOMM | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/sommelier/info/logo.png" width="32" /> | <https://www.sommelier.finance/> |
| 12000118 | Fetch AI | FET | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/fetchai/info/logo.png" width="32" /> | <https://fetch.ai/> |
Expand All @@ -130,6 +132,7 @@ This list is generated from [./registry.json](../registry.json)
| 16000118 | Persistence | XPRT | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/persistence/info/logo.png" width="32" /> | <https://persistence.one/> |
| 17000118 | Akash | AKT | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/akash/info/logo.png" width="32" /> | <https://akash.network/> |
| 18000118 | Noble | USDC | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/noble/info/logo.png" width="32" /> | <https://nobleassets.xyz/> |
| 19000118 | Sei | SEI | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/sei/info/logo.png" width="32" /> | <https://sei.io/> |
| 20000118 | Stargaze | STARS | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/stargaze/info/logo.png" width="32" /> | <https://www.stargaze.zone/> |
| 20000714 | BNB Smart Chain | BNB | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/smartchain/info/logo.png" width="32" /> | <https://www.binance.org/en/smartChain> |
| 20009001 | Native Evmos | EVMOS | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/nativeevmos/info/logo.png" width="32" /> | <https://evmos.org/> |
Expand Down
5 changes: 4 additions & 1 deletion include/TrustWalletCore/TWCoinType.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,12 @@ enum TWCoinType {
TWCoinTypeConfluxeSpace = 1030,
TWCoinTypeAcala = 787,
TWCoinTypeAcalaEVM = 10000787,
TWCoinTypeOpBNBtestnet = 5611,
TWCoinTypeOpBNB = 204,
TWCoinTypeNeon = 245022934,
TWCoinTypeBase = 8453,
TWCoinTypeSei = 19000118,
TWCoinTypeArbitrumNova = 10042170,
TWCoinTypeLinea = 59144,
};

/// Returns the blockchain for a coin type.
Expand Down
105 changes: 98 additions & 7 deletions registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,36 @@
"documentation": "https://docs.base.org/"
}
},
{
"id": "linea",
"name": "Linea",
"coinId": 59144,
"symbol": "ETH",
"decimals": 18,
"blockchain": "Ethereum",
"derivation": [
{
"path": "m/44'/60'/0'/0/0"
}
],
"curve": "secp256k1",
"publicKeyType": "secp256k1Extended",
"chainId": "59144",
"addressHasher": "keccak256",
"explorer": {
"url": "https://lineascan.build",
"txPath": "/tx/",
"accountPath": "/address/",
"sampleTx": "0x0c7086f96865f4fcad58d7f3449db7baab9fce2625bcb79e7ea26676aa0d3420",
"sampleAccount": "0xbf71018f716ca6c64b0b12622f87a26b3b86100f"
},
"info": {
"url": "https://linea.build",
"source": "https://github.com/LineaLabs",
"rpc": "https://rpc.linea.build",
"documentation": "https://docs.linea.build"
}
},
{
"id": "ethereum",
"name": "Ethereum",
Expand Down Expand Up @@ -1046,6 +1076,36 @@
"url": "https://nobleassets.xyz/"
}
},
{
"id": "sei",
"name": "Sei",
"displayName": "Sei",
"coinId": 19000118,
"symbol": "SEI",
"decimals": 6,
"blockchain": "Cosmos",
"chainId": "pacific-1",
"derivation": [
{
"path": "m/44'/118'/0'/0/0"
}
],
"curve": "secp256k1",
"publicKeyType": "secp256k1",
"hrp": "sei",
"addressHasher": "sha256ripemd",
"explorer": {
"url": "https://www.mintscan.io/sei",
"txPath": "/txs/",
"accountPath": "/account/",
"sampleTx": "4A2114EE45317439690F3BEA9C8B6CFA11D42CF978F9487754902D372EEB488C",
"sampleAccount": "sei155hqv2rsypqzq0zpjn72frsxx4l6tcmplw63m2"
},
"info": {
"url": "https://sei.io/",
"documentation": "https://docs.sei.io/"
}
},
{
"id": "coreum",
"name": "Coreum",
Expand Down Expand Up @@ -3194,8 +3254,39 @@
"info": {
"url": "https://arbitrum.io",
"source": "https://github.com/OffchainLabs/arbitrum",
"rpc": "https://node.offchainlabs.com:8547",
"documentation": "https://developer.offchainlabs.com"
"rpc": "https://arb1.arbitrum.io/rpc",
"documentation": "https://docs.arbitrum.io/"
}
},
{
"id": "arbitrumnova",
"name": "Arbitrum Nova",
"coinId": 10042170,
"slip44": 60,
"symbol": "ETH",
"decimals": 18,
"blockchain": "Ethereum",
"derivation": [
{
"path": "m/44'/60'/0'/0/0"
}
],
"curve": "secp256k1",
"publicKeyType": "secp256k1Extended",
"chainId": "42170",
"addressHasher": "keccak256",
"explorer": {
"url": "https://nova.arbiscan.io",
"txPath": "/tx/",
"accountPath": "/address/",
"sampleTx": "0xfdfee13848c2d21813c82c53afc9925f31770564c3117477960a81055702c1be",
"sampleAccount": "0x0d0707963952f2fba59dd06f2b425ace40b492fe"
},
"info": {
"url": "https://nova.arbitrum.io",
"source": "https://github.com/OffchainLabs/arbitrum",
"rpc": "https://nova.arbitrum.io/rpc",
"documentation": "https://docs.arbitrum.io/"
}
},
{
Expand Down Expand Up @@ -3992,10 +4083,10 @@
},
{
"id": "opbnb",
"name": "OpBNB testnet",
"coinId": 5611,
"chainId": "5611",
"symbol": "tBNB",
"name": "OpBNB",
"coinId": 204,
"chainId": "204",
"symbol": "BNB",
"decimals": 18,
"blockchain": "Ethereum",
"derivation": [
Expand All @@ -4016,7 +4107,7 @@
"info": {
"url": "https://opbnb.bnbchain.org/en",
"source": "https://github.com/bnb-chain/opbnb",
"rpc": "https://opbnb-testnet-rpc.bnbchain.org",
"rpc": "https://opbnb-mainnet-rpc.bnbchain.org",
"documentation": "https://docs.bnbchain.org/opbnb-docs"
}
},
Expand Down
2 changes: 1 addition & 1 deletion samples/kmp/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("com.trustwallet:wallet-core-kotlin:3.2.9")
implementation("com.trustwallet:wallet-core-kotlin:3.2.12")
}
}
val commonTest by getting {
Expand Down
15 changes: 15 additions & 0 deletions src/Aptos/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,19 @@ void Entry::sign([[maybe_unused]] TWCoinType coin, const TW::Data& dataIn, TW::D
signTemplate<Signer, Proto::SigningInput>(dataIn, dataOut);
}

Data Entry::preImageHashes([[maybe_unused]] TWCoinType coin, const Data& txInputData) const {
return txCompilerTemplate<Proto::SigningInput, TxCompiler::Proto::PreSigningOutput>(
txInputData, [](const auto& input, auto& output) {
output = Signer::preImageHashes(input);
});
}

void Entry::compile([[maybe_unused]] TWCoinType coin, const Data& txInputData, const std::vector<Data>& signatures, const std::vector<PublicKey>& publicKeys, Data& dataOut) const {
dataOut = txCompilerSingleTemplate<Proto::SigningInput, Proto::SigningOutput>(
txInputData, signatures, publicKeys,
[](const auto& input, auto& output, const auto& signature, const auto& publicKey) {
output = Signer::compile(input, signature, publicKey);
});
}

} // namespace TW::Aptos
8 changes: 5 additions & 3 deletions src/Aptos/Entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ namespace TW::Aptos {
/// Note: do not put the implementation here (no matter how simple), to avoid having coin-specific includes in this file
class Entry final : public CoinEntry {
public:
bool validateAddress(TWCoinType coin, const std::string& address, const PrefixVariant& addressPrefix) const;
std::string deriveAddress(TWCoinType coin, const PublicKey& publicKey, TWDerivation derivation, const PrefixVariant& addressPrefix) const;
void sign(TWCoinType coin, const Data& dataIn, Data& dataOut) const;
bool validateAddress(TWCoinType coin, const std::string& address, const PrefixVariant& addressPrefix) const override;
std::string deriveAddress(TWCoinType coin, const PublicKey& publicKey, TWDerivation derivation, const PrefixVariant& addressPrefix) const override;
void sign(TWCoinType coin, const Data& dataIn, Data& dataOut) const override;
Data preImageHashes(TWCoinType coin, const Data& txInputData) const override;
void compile(TWCoinType coin, const Data& txInputData, const std::vector<Data>& signatures, const std::vector<PublicKey>& publicKeys, Data& dataOut) const override;
};

} // namespace TW::Aptos
62 changes: 27 additions & 35 deletions src/Aptos/Signer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,48 +180,29 @@ TransactionPayload registerTokenPayload(const Proto::SigningInput& input) {
return payload;
}

Proto::SigningOutput blindSign(const Proto::SigningInput& input) {
auto output = Proto::SigningOutput();
auto privateKey = PrivateKey(Data(input.private_key().begin(), input.private_key().end()));
auto pubKeyData = privateKey.getPublicKey(TWPublicKeyTypeED25519).bytes;
TransactionBasePtr buildBlindTx(const Proto::SigningInput& input) {
if (nlohmann::json j = nlohmann::json::parse(input.any_encoded(), nullptr, false); j.is_discarded()) {
BCS::Serializer serializer;
auto encodedCall = parse_hex(input.any_encoded());
serializer.add_bytes(begin(encodedCall), end(encodedCall));
auto signature = privateKey.sign(encodedCall, TWCurveED25519);
output.set_raw_txn(encodedCall.data(), encodedCall.size());
output.mutable_authenticator()->set_public_key(pubKeyData.data(), pubKeyData.size());
output.mutable_authenticator()->set_signature(signature.data(), signature.size());
serializer << BCS::uleb128{.value = 0} << pubKeyData << signature;
output.set_encoded(serializer.bytes.data(), serializer.bytes.size());

// clang-format off
nlohmann::json json = {
{"type", "ed25519_signature"},
{"public_key", hexEncoded(pubKeyData)},
{"signature", hexEncoded(signature)}
};
// clang-format on
output.set_json(json.dump());
auto blindBuilder = std::make_unique<BlindBuilder>();
blindBuilder->encodedCallHex(input.any_encoded());
return blindBuilder;
} else {
TransactionBuilder::builder()
.sender(Address(input.sender()))
auto txBuilder = std::make_unique<TransactionBuilder>();
txBuilder->sender(Address(input.sender()))
.sequenceNumber(input.sequence_number())
.payload(EntryFunction::from_json(j))
.maxGasAmount(input.max_gas_amount())
.gasUnitPrice(input.gas_unit_price())
.expirationTimestampSecs(input.expiration_timestamp_secs())
.chainId(static_cast<uint8_t>(input.chain_id()))
.sign(input, output);
.chainId(static_cast<uint8_t>(input.chain_id()));
return txBuilder;
}
return output;
}

Proto::SigningOutput Signer::sign(const Proto::SigningInput& input) {
auto protoOutput = Proto::SigningOutput();
TransactionBasePtr buildTx(const Proto::SigningInput& input) {
if (!input.any_encoded().empty()) {
return blindSign(input);
return buildBlindTx(input);
}

auto nftPayloadFunctor = [](const Proto::NftMessage& nftMessage) {
switch (nftMessage.nft_transaction_payload_case()) {
case Proto::NftMessage::kOfferNft:
Expand Down Expand Up @@ -273,16 +254,27 @@ Proto::SigningOutput Signer::sign(const Proto::SigningInput& input) {
throw std::runtime_error("Transaction payload should be set");
}
};
TransactionBuilder::builder()
.sender(Address(input.sender()))
auto txBuilder = std::make_unique<TransactionBuilder>();
txBuilder->sender(Address(input.sender()))
.sequenceNumber(input.sequence_number())
.payload(payloadFunctor())
.maxGasAmount(input.max_gas_amount())
.gasUnitPrice(input.gas_unit_price())
.expirationTimestampSecs(input.expiration_timestamp_secs())
.chainId(static_cast<uint8_t>(input.chain_id()))
.sign(input, protoOutput);
return protoOutput;
.chainId(static_cast<uint8_t>(input.chain_id()));
return txBuilder;
}

Proto::SigningOutput Signer::sign(const Proto::SigningInput& input) {
return buildTx(input)->sign(input);
}

TxCompiler::Proto::PreSigningOutput Signer::preImageHashes(const Proto::SigningInput& input) {
return buildTx(input)->preImage();
}

Proto::SigningOutput Signer::compile(const Proto::SigningInput& input, const Data& signature, const PublicKey& publicKey) {
return buildTx(input)->compile(signature, publicKey);
}

} // namespace TW::Aptos
Loading

0 comments on commit 988b1e5

Please sign in to comment.