Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
delegationbuilder.cpp
Go to the documentation of this file.
1// Copyright (c) 2020 The Bitcoin developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
6
7#include <avalanche/proof.h>
8#include <avalanche/proofid.h>
9#include <pubkey.h>
10
11#include <key.h>
12
13namespace avalanche {
14
16 const CPubKey &proofMaster,
18 : limitedProofid(ltdProofId), dgid(delegationId) {
19 levels.push_back({proofMaster, {}});
20}
21
23 const CPubKey &proofMaster)
24 : DelegationBuilder(ltdProofId, proofMaster,
25 DelegationId(ltdProofId.computeProofId(proofMaster))) {}
26
28 : DelegationBuilder(p.getLimitedId(), p.getMaster(),
29 DelegationId(p.getId())) {}
30
32 : DelegationBuilder(dg.getLimitedProofId(), dg.getProofMaster(),
33 dg.getId()) {
34 for (auto &l : dg.levels) {
35 levels.back().sig = l.sig;
36 levels.push_back({l.pubkey, {}});
37 }
38}
39
41 const CPubKey &delegatedPubKey) {
42 // Ensures that the private key provided is the one we need.
43 if (levels.back().pubkey != delegatorKey.GetPubKey()) {
44 return false;
45 }
46
47 HashWriter ss{};
48 ss << dgid;
50 auto hash = ss.GetHash();
51
52 if (!delegatorKey.SignSchnorr(hash, levels.back().sig)) {
53 return false;
54 }
55
56 dgid = DelegationId(hash);
57 levels.push_back({delegatedPubKey, {}});
58 return true;
59}
60
62 std::vector<Delegation::Level> dglvls;
63 for (size_t i = 1; i < levels.size(); i++) {
64 dglvls.push_back({levels[i].pubkey, levels[i - 1].sig});
65 }
66
67 return Delegation(limitedProofid, levels[0].pubkey, dgid,
68 std::move(dglvls));
69}
70
71} // namespace avalanche
An encapsulated secp256k1 private key.
Definition key.h:28
An encapsulated public key.
Definition pubkey.h:31
A writer stream (for serialization) that computes a 256-bit hash.
Definition hash.h:99
std::vector< Delegation::Level > levels
bool addLevel(const CKey &delegatorKey, const CPubKey &delegatedPubKey)
DelegationBuilder(const LimitedProofId &ltdProofId, const CPubKey &proofMaster, const DelegationId &delegationId)
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85