Skip to content

Commit 74b2591

Browse files
Tolsihewigovens
authored andcommitted
Waves support (#489)
* Added Curve25519 signing and validation logic * Update include/TrustWalletCore/TWCurve.h Co-Authored-By: hewig <[email protected]> * Added Curve25519 description in trezor-crypto readme * ge25519_p1p1_1 don't collide with ed25519 ge25519_p1p1 now * curve25519 test cases were added * tests fix * Added Waves Blockchain definition * Added Waves Address encoding/decoding with tests * Added Waves Transaction signing * review fixes * Added attachment comment * code quality
1 parent ab2d989 commit 74b2591

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2963
-22
lines changed

android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/CoinAddressDerivationTests.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,6 @@ class CoinAddressDerivationTests {
7979
ARK -> assertEquals("Ac49m5pu5YpMMNgEbSYeZUEpRMHcSK3DfV", address)
8080
MONETARYUNIT -> assertEquals("7W3QRu8FttKzmYtRbXNKopeHweAKWuun2q", address)
8181
RAVENCOIN -> assertEquals("RHoCwPc2FCQqwToYnSiAb3SrCET4zEHsbS", address)
82+
WAVES -> assertEquals("3P63vkaHhyE9pPv9EfsjwGKqmZYcCRHys4n", address)
8283
}
8384
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.trustwallet.core.app.blockchains.waves
2+
3+
import com.trustwallet.core.app.utils.toHex
4+
import com.trustwallet.core.app.utils.toHexByteArray
5+
import org.junit.Assert.assertEquals
6+
import org.junit.Test
7+
import wallet.core.jni.PrivateKey
8+
import wallet.core.jni.PublicKey
9+
import wallet.core.jni.PublicKeyType
10+
import wallet.core.jni.WavesAddress
11+
12+
class TestAddress {
13+
14+
init {
15+
System.loadLibrary("TrustWalletCore")
16+
}
17+
18+
@Test
19+
fun testAddressFromPrivateKey() {
20+
val key = PrivateKey("9864a747e1b97f131fabb6b447296c9b6f0201e79fb3c5356e6c77e89b6a806a".toHexByteArray())
21+
val pubkey = key.getPublicKeyCurve25519()
22+
val address = WavesAddress(pubkey)
23+
24+
assertEquals(pubkey.data().toHex(), "0x559a50cb45a9a8e8d4f83295c354725990164d10bb505275d1a3086c08fb935d".toLowerCase())
25+
assertEquals(address.description(), "3P2uzAzX9XTu1t32GkWw68YFFLwtapWvDds")
26+
}
27+
28+
@Test
29+
fun testAddressFromPublicKey() {
30+
val pubkey = PublicKey("559a50cb45a9a8e8d4f83295c354725990164d10bb505275d1a3086c08fb935d".toHexByteArray(), PublicKeyType.CURVE25519)
31+
val address = WavesAddress(pubkey)
32+
33+
assertEquals(address.description(), "3P2uzAzX9XTu1t32GkWw68YFFLwtapWvDds")
34+
}
35+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.trustwallet.core.app.blockchains.waves
2+
3+
import com.google.protobuf.ByteString
4+
import com.trustwallet.core.app.utils.Numeric
5+
import com.trustwallet.core.app.utils.toHexByteArray
6+
import com.trustwallet.core.app.utils.toHex
7+
import org.junit.Assert.assertEquals
8+
import org.junit.Test
9+
import wallet.core.jni.PrivateKey
10+
import wallet.core.jni.WavesSigner
11+
import wallet.core.jni.proto.Waves
12+
13+
class TestWavesTransactionSigner {
14+
15+
init {
16+
System.loadLibrary("TrustWalletCore")
17+
}
18+
19+
@Test
20+
fun testWavesTransactionSigning() {
21+
val signingInput = Waves.SigningInput.newBuilder()
22+
signingInput.apply {
23+
amount = 100_000_000
24+
amountAsset = "DacnEpaUVFRCYk8Fcd1F3cqUZuT4XG7qW9mRyoZD81zq"
25+
fee = 100_000
26+
feeAsset = "DacnEpaUVFRCYk8Fcd1F3cqUZuT4XG7qW9mRyoZD81zq"
27+
to = "3PPCZQkvdMJpmx7Zrz1cnYsPe9Bt1XT2Ckx"
28+
attachment = ByteString.copyFrom("68656c6c6f".toHexByteArray())
29+
timestamp = 1559146613
30+
publicKey = ByteString.copyFrom("794e8429ddf58353eacab99b4c2b3b71c8c1b5927980db2d6f8db52744dd103d".toHexByteArray())
31+
privateKey = ByteString.copyFrom("68b7a9adb4a655b205f43dac413803785921e22cd7c4d05857b203a62621075f".toHexByteArray())
32+
}
33+
34+
val sign: Waves.SigningOutput = WavesSigner.sign(signingInput.build())
35+
val signBytes = sign.signature
36+
assertEquals(signBytes.toByteArray().toHex(), "0x5d6a77b1fd9b53d9735cd2543ba94215664f2b07d6c7befb081221fcd49f5b6ad6b9ac108582e8d3e74943bdf35fd80d985edf4b4de1fb1c5c427e84d0879f8f")
37+
}
38+
}

coins.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,5 +649,16 @@
649649
"xpub": "xpub",
650650
"xprv": "xprv",
651651
"explorer": "https://ravencoin.network/tx/"
652+
},
653+
{
654+
"id": "waves",
655+
"name": "Waves",
656+
"symbol": "WAVES",
657+
"decimals": 8,
658+
"blockchain": "Waves",
659+
"derivationPath": "m/44'/5741564'/0'/0'/0'",
660+
"curve": "ed25519",
661+
"publicKeyType": "curve25519",
662+
"explorer": "https://wavesexplorer.com/tx/"
652663
}
653664
]

include/TrustWalletCore/TWBlockchain.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ enum TWBlockchain {
3737
TWBlockchainNEO = 22,
3838
TWBlockchainSteem = 23,
3939
TWBlockchainNULS = 24,
40+
TWBlockchainWaves = 25,
4041
};
4142

4243
TW_EXTERN_C_END

include/TrustWalletCore/TWCoinType.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ enum TWCoinType {
7474
TWCoinTypeARK = 111,
7575
TWCoinTypeMonetaryUnit = 31,
7676
TWCoinTypeRavencoin = 175,
77+
TWCoinTypeWaves = 5741564,
7778
};
7879

7980
/// Returns the blockchain for a coin type.

include/TrustWalletCore/TWCurve.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ enum TWCurve {
1515
TWCurveSECP256k1 /* "secp256k1" */,
1616
TWCurveED25519 /* "ed25519" */,
1717
TWCurveED25519Blake2bNano /* "ed25519-blake2b-nano" */,
18+
TWCurveCurve25519 /* "curve25519" */,
1819
TWCurveNIST256p1 /* "nist256p1" */,
1920
};
2021

include/TrustWalletCore/TWPrivateKey.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,26 @@ bool TWPrivateKeyIsValid(TWData *_Nonnull data);
3636
TW_EXPORT_PROPERTY
3737
TWData *_Nonnull TWPrivateKeyData(struct TWPrivateKey *_Nonnull pk);
3838

39-
/// Returns the public key associated with this pirvate key.
39+
/// Returns the public key associated with this private key.
4040
TW_EXPORT_METHOD
4141
struct TWPublicKey *_Nonnull TWPrivateKeyGetPublicKeySecp256k1(struct TWPrivateKey *_Nonnull pk, bool compressed);
4242

43-
/// Returns the public key associated with this pirvate key.
43+
/// Returns the public key associated with this private key.
4444
TW_EXPORT_METHOD
4545
struct TWPublicKey *_Nonnull TWPrivateKeyGetPublicKeyNist256p1(struct TWPrivateKey *_Nonnull pk);
4646

47-
/// Returns the public key associated with this pirvate key.
47+
/// Returns the public key associated with this private key.
4848
TW_EXPORT_METHOD
4949
struct TWPublicKey *_Nonnull TWPrivateKeyGetPublicKeyEd25519(struct TWPrivateKey *_Nonnull pk);
5050

51-
/// Returns the public key associated with this pirvate key.
51+
/// Returns the public key associated with this private key.
5252
TW_EXPORT_METHOD
5353
struct TWPublicKey *_Nonnull TWPrivateKeyGetPublicKeyEd25519Blake2b(struct TWPrivateKey *_Nonnull pk);
5454

55+
/// Returns the public key associated with this private key.
56+
TW_EXPORT_METHOD
57+
struct TWPublicKey *_Nonnull TWPrivateKeyGetPublicKeyCurve25519(struct TWPrivateKey *_Nonnull pk);
58+
5559
/// Signs a digest using ECDSA and given curve.
5660
TW_EXPORT_METHOD
5761
TWData *_Nullable TWPrivateKeySign(struct TWPrivateKey *_Nonnull pk, TWData *_Nonnull digest, enum TWCurve curve);

include/TrustWalletCore/TWPublicKeyType.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum TWPublicKeyType {
1818
TWPublicKeyTypeNIST256p1Extended = 3,
1919
TWPublicKeyTypeED25519 = 4,
2020
TWPublicKeyTypeED25519Blake2b = 5,
21+
TWPublicKeyTypeCURVE25519 = 6,
2122
};
2223

2324
TW_EXTERN_C_END
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright © 2017-2019 Trust Wallet.
2+
//
3+
// This file is part of Trust. The full Trust copyright notice, including
4+
// terms governing use, modification, and redistribution, is contained in the
5+
// file LICENSE at the root of the source code distribution tree.
6+
7+
#pragma once
8+
9+
#include "TWBase.h"
10+
#include "TWData.h"
11+
#include "TWString.h"
12+
13+
TW_EXTERN_C_BEGIN
14+
15+
struct TWPublicKey;
16+
17+
/// Represents an Waves address.
18+
TW_EXPORT_CLASS
19+
struct TWWavesAddress;
20+
21+
/// Compares two addresses for equality.
22+
TW_EXPORT_STATIC_METHOD
23+
bool TWWavesAddressEqual(struct TWWavesAddress *_Nonnull lhs, struct TWWavesAddress *_Nonnull rhs);
24+
25+
/// Determines if the string is a valid address.
26+
TW_EXPORT_STATIC_METHOD
27+
bool TWWavesAddressIsValidString(TWString *_Nonnull string);
28+
29+
/// Creates an address from a string representaion.
30+
TW_EXPORT_STATIC_METHOD
31+
struct TWWavesAddress *_Nullable TWWavesAddressCreateWithString(TWString *_Nonnull string);
32+
33+
/// Creates an address from a public key.
34+
TW_EXPORT_STATIC_METHOD
35+
struct TWWavesAddress *_Nonnull TWWavesAddressCreateWithPublicKey(
36+
struct TWPublicKey *_Nonnull publicKey);
37+
38+
TW_EXPORT_METHOD
39+
void TWWavesAddressDelete(struct TWWavesAddress *_Nonnull address);
40+
41+
/// Returns the address string representation.
42+
TW_EXPORT_PROPERTY
43+
TWString *_Nonnull TWWavesAddressDescription(struct TWWavesAddress *_Nonnull address);
44+
45+
/// Returns the key hash.
46+
TW_EXPORT_PROPERTY
47+
TWData *_Nonnull TWWavesAddressKeyHash(struct TWWavesAddress *_Nonnull address);
48+
49+
TW_EXTERN_C_END

0 commit comments

Comments
 (0)