Skip to content

Commit 265a1e3

Browse files
authored
Remove address builder and verifier (#80)
Signed-off-by: turuslan <[email protected]>
1 parent dae964b commit 265a1e3

30 files changed

+129
-473
lines changed

core/crypto/blake2/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
add_library(blake2
77
blake2s.c
88
blake2b.c
9-
blake2b_error.cpp
109
blake2b160.cpp
1110
)
1211
target_link_libraries(blake2

core/crypto/blake2/blake2b160.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,26 @@
99

1010
namespace fc::crypto::blake2b {
1111

12-
fc::outcome::result<Blake2b160Hash> blake2b_160(
13-
gsl::span<const uint8_t> to_hash) {
12+
Blake2b160Hash blake2b_160(gsl::span<const uint8_t> to_hash) {
1413
Blake2b160Hash res{};
15-
if (::blake2b(res.data(),
16-
BLAKE2B160_HASH_LENGTH,
17-
nullptr,
18-
0,
19-
to_hash.data(),
20-
to_hash.size())
21-
!= 0)
22-
return Blake2bError::CANNOT_INIT;
14+
::blake2b(res.data(),
15+
BLAKE2B160_HASH_LENGTH,
16+
nullptr,
17+
0,
18+
to_hash.data(),
19+
to_hash.size());
2320
return res;
2421
}
2522

26-
fc::outcome::result<Blake2b256Hash> blake2b_256(
23+
Blake2b256Hash blake2b_256(
2724
gsl::span<const uint8_t> to_hash) {
2825
Blake2b256Hash res{};
29-
if (::blake2b(res.data(),
30-
BLAKE2B256_HASH_LENGTH,
31-
nullptr,
32-
0,
33-
to_hash.data(),
34-
to_hash.size())
35-
!= 0)
36-
return Blake2bError::CANNOT_INIT;
26+
::blake2b(res.data(),
27+
BLAKE2B256_HASH_LENGTH,
28+
nullptr,
29+
0,
30+
to_hash.data(),
31+
to_hash.size());
3732
return res;
3833
}
3934

core/crypto/blake2/blake2b160.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include "common/blob.hpp"
1212
#include "common/outcome.hpp"
13-
#include "crypto/blake2/blake2b_error.hpp"
1413

1514
namespace fc::crypto::blake2b {
1615

@@ -23,18 +22,16 @@ namespace fc::crypto::blake2b {
2322
/**
2423
* @brief Get blake2b-160 hash
2524
* @param to_hash - data to hash
26-
* @return outcome with hash or error
25+
* @return hash
2726
*/
28-
fc::outcome::result<Blake2b160Hash> blake2b_160(
29-
gsl::span<const uint8_t> to_hash);
27+
Blake2b160Hash blake2b_160(gsl::span<const uint8_t> to_hash);
3028

3129
/**
3230
* @brief Get blake2b-256 hash
3331
* @param to_hash - data to hash
34-
* @return outcome with hash or error
32+
* @return hash
3533
*/
36-
fc::outcome::result<Blake2b256Hash> blake2b_256(
37-
gsl::span<const uint8_t> to_hash);
34+
Blake2b256Hash blake2b_256(gsl::span<const uint8_t> to_hash);
3835

3936
} // namespace fc::crypto::blake2b
4037

core/crypto/blake2/blake2b_error.cpp

Lines changed: 0 additions & 21 deletions
This file was deleted.

core/crypto/blake2/blake2b_error.hpp

Lines changed: 0 additions & 26 deletions
This file was deleted.

core/primitives/address/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@
44
add_library(address
55
address.cpp
66
address_codec.cpp
7-
impl/address_verifier_impl.cpp
8-
impl/address_builder_impl.cpp
97
)
108
target_link_libraries(address
119
Boost::boost
1210
blake2
1311
blob
14-
bls_provider
1512
cbor
1613
outcome
17-
p2p::p2p_secp256k1_provider
1814
)

core/primitives/address/address.cpp

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,49 @@ namespace fc::primitives::address {
4444
[](const BLSPublicKeyHash &v) { return Protocol::BLS; });
4545
}
4646

47-
Address Address::makeFromId(uint64_t id) {
48-
// TODO(turuslan): FIL-118 remove hardcoded TESTNET
49-
return {TESTNET, id};
47+
Address Address::makeFromId(uint64_t id, Network network) {
48+
return {network, id};
5049
}
5150

52-
Address Address::makeActorExecAddress(gsl::span<const uint8_t> data) {
53-
// TODO(turuslan): FIL-118 remove hardcoded TESTNET
54-
return {TESTNET, ActorExecHash{blake2b_160(data).value()}};
51+
Address Address::makeSecp256k1(const Sec256k1PublicKey &public_key,
52+
Network network) {
53+
return {network, Secp256k1PublicKeyHash{blake2b_160(public_key)}};
54+
}
55+
56+
Address Address::makeActorExec(gsl::span<const uint8_t> data,
57+
Network network) {
58+
return {network, ActorExecHash{blake2b_160(data)}};
59+
}
60+
61+
Address Address::makeBls(const BlsPublicKey &public_key, Network network) {
62+
return {network, BLSPublicKeyHash{public_key}};
63+
}
64+
65+
bool Address::verifySyntax(gsl::span<const uint8_t> seed_data) const {
66+
return visit_in_place(
67+
data,
68+
[](uint64_t v) { return true; },
69+
[&seed_data](const Secp256k1PublicKeyHash &v) {
70+
if (seed_data.size() != libp2p::crypto::secp256k1::kPublicKeyLength) {
71+
return false;
72+
}
73+
auto hash = blake2b_160(seed_data);
74+
return std::equal(v.begin(), v.end(), hash.begin());
75+
},
76+
[&seed_data](const ActorExecHash &v) {
77+
auto hash = blake2b_160(seed_data);
78+
return std::equal(v.begin(), v.end(), hash.begin());
79+
},
80+
[&seed_data](const BLSPublicKeyHash &v) {
81+
if (seed_data.size() != std::tuple_size<BlsPublicKey>::value) {
82+
return false;
83+
}
84+
return std::equal(v.begin(), v.end(), seed_data.begin());
85+
});
5586
}
5687

5788
bool operator==(const Address &lhs, const Address &rhs) {
58-
return lhs.network == rhs.network && lhs.getProtocol() == rhs.getProtocol()
89+
return lhs.network == rhs.network
5990
&& lhs.data == rhs.data;
6091
}
6192

core/primitives/address/address.hpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010

1111
#include <boost/variant.hpp>
1212
#include "common/blob.hpp"
13+
#include "crypto/bls/bls_types.hpp"
14+
#include "crypto/secp256k1/secp256k1_provider.hpp"
1315

1416
namespace fc::primitives::address {
17+
using Sec256k1PublicKey = libp2p::crypto::secp256k1::PublicKey;
18+
using BlsPublicKey = crypto::bls::PublicKey;
1519

1620
/**
1721
* @brief Potential errors creating and handling Filecoin addresses
@@ -27,6 +31,9 @@ namespace fc::primitives::address {
2731
*/
2832
enum Network : uint8_t { MAINNET = 0x0, TESTNET = 0x1 };
2933

34+
// TODO(turuslan): FIL-118 remove hardcoded TESTNET
35+
constexpr auto kDefaultNetwork = TESTNET;
36+
3037
/**
3138
* @brief Known Address protocols
3239
*/
@@ -66,9 +73,18 @@ namespace fc::primitives::address {
6673
bool isKeyType() const;
6774

6875
/// id - number assigned to actors in a Filecoin Chain
69-
static Address makeFromId(uint64_t id);
76+
static Address makeFromId(uint64_t id, Network network = kDefaultNetwork);
77+
78+
static Address makeSecp256k1(const Sec256k1PublicKey &public_key,
79+
Network network = kDefaultNetwork);
80+
81+
static Address makeActorExec(gsl::span<const uint8_t> data,
82+
Network network = kDefaultNetwork);
83+
84+
static Address makeBls(const BlsPublicKey &public_key,
85+
Network network = kDefaultNetwork);
7086

71-
static Address makeActorExecAddress(gsl::span<const uint8_t> data);
87+
bool verifySyntax(gsl::span<const uint8_t> seed_data) const;
7288

7389
Network network;
7490
Payload data;

core/primitives/address/address_builder.hpp

Lines changed: 0 additions & 43 deletions
This file was deleted.

core/primitives/address/address_verifier.hpp

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)