Repository navigation
Expand file tree
/
Copy pathSignerTests.cpp
More file actions
45 lines (36 loc) · 1.51 KB
/
Copy pathSignerTests.cpp
File metadata and controls
45 lines (36 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright © 2017-2020 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.
#include "HexCoding.h"
#include "PrivateKey.h"
#include "Nimiq/Address.h"
#include "Nimiq/Signer.h"
#include "Nimiq/Transaction.h"
#include <gtest/gtest.h>
namespace TW::Nimiq {
TEST(NimiqSigner, DerivePublicKey) {
const PrivateKey privateKey(parse_hex("e3cc33575834add098f8487123cd4bca543ee859b3e8cfe624e7e6a97202b756"));
const PublicKey publicKey((privateKey.getPublicKey(TWPublicKeyTypeED25519)));
const auto address = Address(publicKey);
ASSERT_EQ(address.string(), "NQ27 GBAY EVHP HK5X 6JHV JGFJ 5M3H BF4Y G7GD");
}
TEST(NimiqSigner, Sign) {
const PrivateKey privateKey(parse_hex("e3cc33575834add098f8487123cd4bca543ee859b3e8cfe624e7e6a97202b756"));
const auto pubkey = privateKey.getPublicKey(TWPublicKeyTypeED25519);
std::array<uint8_t, 32> pubkeyBytes;
std::copy(pubkey.bytes.begin(), pubkey.bytes.end(), pubkeyBytes.data());
Transaction tx(
pubkeyBytes,
Address("NQ86 2H8F YGU5 RM77 QSN9 LYLH C56A CYYR 0MLA"),
42042042,
1000,
314159
);
Signer signer;
signer.sign(privateKey, tx);
ASSERT_EQ(hex(tx.signature),
"74dc7f6e0ab58a0bf52cc6e8801b0cca132dd4229d9a3e3a3d2f90e4d8f045d981b771bf5fc3851a98f3c617b1a943228f963e910e061808a721cfa0e3cad50b");
}
} // namespace TW::Nimiq