forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from navcoin/factor-out-blsct-wallet
Factor out BLSCT wallet code
- Loading branch information
Showing
10 changed files
with
276 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) 2024 The Navcoin developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <blsct/eip_2333/bls12_381_keygen.h> | ||
#include <blsct/wallet/helpers.h> | ||
|
||
namespace blsct { | ||
uint64_t CalculateViewTag(const MclG1Point& blindingKey, const MclScalar& viewKey) | ||
{ | ||
HashWriter hash{}; | ||
hash << (blindingKey * viewKey); | ||
|
||
return (hash.GetHash().GetUint64(0) & 0xFFFF); | ||
} | ||
|
||
CKeyID CalculateHashId(const MclG1Point& blindingKey, const MclG1Point& spendingKey, const MclScalar& viewKey) | ||
{ | ||
auto t = blindingKey * viewKey; | ||
auto dh = MclG1Point::GetBasePoint() * t.GetHashWithSalt(0).Negate(); | ||
auto D_prime = spendingKey + dh; | ||
|
||
return blsct::PublicKey(D_prime).GetID(); | ||
} | ||
|
||
MclScalar CalculatePrivateSpendingKey(const MclG1Point& blindingKey, const MclScalar& viewKey, const MclScalar& spendingKey, const int64_t& account, const uint64_t& address) | ||
{ | ||
HashWriter string{}; | ||
|
||
string << std::vector<unsigned char>(subAddressHeader.begin(), subAddressHeader.end()); | ||
string << viewKey; | ||
string << account; | ||
string << address; | ||
|
||
MclG1Point t = blindingKey * viewKey; | ||
|
||
return t.GetHashWithSalt(0) + spendingKey + MclScalar(string.GetHash()); | ||
} | ||
|
||
MclG1Point CalculateNonce(const MclG1Point& blindingKey, const MclScalar& viewKey) | ||
{ | ||
return blindingKey * viewKey; | ||
} | ||
|
||
SubAddress DeriveSubAddress(const PrivateKey& viewKey, const PublicKey& spendKey, const SubAddressIdentifier& subAddressId) | ||
{ | ||
return SubAddress(viewKey, spendKey, subAddressId); | ||
} | ||
|
||
MclScalar FromSeedToChildKey(const MclScalar& seed) | ||
{ | ||
return BLS12_381_KeyGen::derive_child_SK(seed, 130); | ||
} | ||
|
||
MclScalar FromChildToTransactionKey(const MclScalar& seed) | ||
{ | ||
return BLS12_381_KeyGen::derive_child_SK(seed, 0); | ||
} | ||
|
||
MclScalar FromChildToBlindingKey(const MclScalar& seed) | ||
{ | ||
return BLS12_381_KeyGen::derive_child_SK(seed, 1); | ||
} | ||
|
||
MclScalar FromChildToTokenKey(const MclScalar& seed) | ||
{ | ||
return BLS12_381_KeyGen::derive_child_SK(seed, 2); | ||
} | ||
|
||
MclScalar FromTransactionToViewKey(const MclScalar& seed) | ||
{ | ||
return BLS12_381_KeyGen::derive_child_SK(seed, 0); | ||
} | ||
|
||
MclScalar FromTransactionToSpendKey(const MclScalar& seed) | ||
{ | ||
return BLS12_381_KeyGen::derive_child_SK(seed, 1); | ||
} | ||
|
||
MclScalar GenRandomSeed() | ||
{ | ||
return BLS12_381_KeyGen::derive_master_SK(MclScalar::Rand(true).GetVch()); | ||
} | ||
} // namespace blsct |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2023 The Navcoin developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef NAVCOIN_BLSCT_WALLET_HELPERS_H | ||
#define NAVCOIN_BLSCT_WALLET_HELPERS_H | ||
|
||
#include <blsct/arith/mcl/mcl.h> | ||
#include <blsct/public_key.h> | ||
#include <blsct/wallet/address.h> | ||
#include <hash.h> | ||
#include <pubkey.h> | ||
|
||
namespace blsct { | ||
uint64_t CalculateViewTag(const MclG1Point& blindingKey, const MclScalar& viewKey); | ||
CKeyID CalculateHashId(const MclG1Point& blindingKey, const MclG1Point& spendingKey, const MclScalar& viewKey); | ||
MclScalar CalculatePrivateSpendingKey(const MclG1Point& blindingKey, const MclScalar& viewKey, const MclScalar& spendingKey, const int64_t& account, const uint64_t& address); | ||
MclG1Point CalculateNonce(const MclG1Point& blindingKey, const MclScalar& viewKey); | ||
SubAddress DeriveSubAddress(const PrivateKey& viewKey, const PublicKey& spendKey, const SubAddressIdentifier& subAddressId); | ||
MclScalar FromSeedToChildKey(const MclScalar& seed); | ||
MclScalar FromChildToTransactionKey(const MclScalar& seed); | ||
MclScalar FromChildToBlindingKey(const MclScalar& seed); | ||
MclScalar FromChildToTokenKey(const MclScalar& seed); | ||
MclScalar FromTransactionToViewKey(const MclScalar& seed); | ||
MclScalar FromTransactionToSpendKey(const MclScalar& seed); | ||
MclScalar GenRandomSeed(); | ||
} // namespace blsct | ||
|
||
#endif // NAVCOIN_BLSCT_WALLET_HELPERS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.