Skip to content

Commit

Permalink
normalize mnemonic to NFKD
Browse files Browse the repository at this point in the history
  • Loading branch information
heropan committed Dec 9, 2021
1 parent d4cc194 commit bbc29ff
Show file tree
Hide file tree
Showing 50 changed files with 21,359 additions and 12,955 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 11)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
set(CMAKE_VERBOSE_MAKEFILE OFF)
include(ProjectDefaults)
include(DistPackage)
include(AddSubModule)
Expand Down
15 changes: 12 additions & 3 deletions Interface/IMasterWalletManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,18 @@ namespace Elastos {
virtual ~IMasterWalletManager() noexcept {}

/**
* Generate a mnemonic by random entropy. We support English, Chinese, French, Italian, Japanese, and
* Spanish 6 types of mnemonic currently.
* @param language specify mnemonic language.
* Generate a mnemonic by random entropy.
* @param language specify mnemonic language. We support language below
* ChineseSimplified,
* ChineseTraditional,
* Czech,
* English,
* French,
* Italian,
* Japanese,
* Korean,
* Portuguese,
* Spanish
* @param wordCount value can only be one of {12, 15, 18, 21, 24}.
* @return a random mnemonic.
*/
Expand Down
18 changes: 9 additions & 9 deletions SDK/Account/Account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <Common/ByteStream.h>
#include <WalletCore/Base58.h>
#include <WalletCore/AES.h>
#include <WalletCore/BIP39.h>
#include <WalletCore/Mnemonic.h>
#include <WalletCore/CoinInfo.h>
#include <WalletCore/HDKeychain.h>
#include <WalletCore/Key.h>
Expand Down Expand Up @@ -217,7 +217,7 @@ namespace Elastos {
"Too much signers");

bytes_t xprv;
uint512 seed = BIP39::DeriveSeed(mnemonic, passphrase);
uint512 seed = Mnemonic::DeriveSeed(mnemonic, passphrase);
UInt512 ethseed = *(UInt512 *) seed.begin();
BREthereumAccount account = createAccountWithBIP32Seed(ethseed);
BRKey pubkey = accountGetPrimaryAddressPublicKey(account);
Expand Down Expand Up @@ -268,7 +268,7 @@ namespace Elastos {

Account::Account(const std::string &path, const std::string &mnemonic, const std::string &passphrase,
const std::string &payPasswd, bool singleAddress) {
uint512 seed = BIP39::DeriveSeed(mnemonic, passphrase);
uint512 seed = Mnemonic::DeriveSeed(mnemonic, passphrase);
UInt512 ethseed = *(UInt512 *) seed.begin();
BREthereumAccount account = createAccountWithBIP32Seed(ethseed);
BRKey pubkey = accountGetPrimaryAddressPublicKey(account);
Expand Down Expand Up @@ -368,7 +368,7 @@ namespace Elastos {

if (!json.HasPassPhrase() && !json.Mnemonic().empty() &&
(json.GetSeed().empty() || json.GetETHSCPrimaryPubKey().empty())) {
uint512 seed = BIP39::DeriveSeed(json.Mnemonic(), "");
uint512 seed = Mnemonic::DeriveSeed(json.Mnemonic(), "");
SupportETHSC(seed, payPasswd);
}
}
Expand Down Expand Up @@ -472,7 +472,7 @@ namespace Elastos {
if (!_localstore->Readonly()) {
ErrorChecker::CheckPassword(newPassword, "New");

uint512 seed = BIP39::DeriveSeed(mnemonic, passphrase);
uint512 seed = Mnemonic::DeriveSeed(mnemonic, passphrase);
HDSeed hdseed(seed.bytes());
HDKeychain rootkey(hdseed.getExtendedKey(true));
std::string xPubKey = Base58::CheckEncode(rootkey.getChild("44'/0'/0'").getPublic().extkey());
Expand Down Expand Up @@ -908,7 +908,7 @@ namespace Elastos {

_localstore->SetHasPassPhrase(!passphrase.empty());

HDSeed seed(BIP39::DeriveSeed(mnemonic, passphrase).bytes());
HDSeed seed(Mnemonic::DeriveSeed(mnemonic, passphrase).bytes());
rootkey = HDKeychain(seed.getExtendedKey(true));

_localstore->SetPassPhrase("");
Expand Down Expand Up @@ -958,7 +958,7 @@ namespace Elastos {
bytes = AES::DecryptCCM(_localstore->GetMnemonic(), payPasswd);
mnemonic = std::string((char *) &bytes[0], bytes.size());
}
uint512 seed = BIP39::DeriveSeed(mnemonic, "");
uint512 seed = Mnemonic::DeriveSeed(mnemonic, "");
// save in GenerateSeed()
SupportETHSC(seed, payPasswd);
} else {
Expand Down Expand Up @@ -989,7 +989,7 @@ namespace Elastos {

bool Account::VerifyPrivateKey(const std::string &mnemonic, const std::string &passphrase) const {
if (!_localstore->Readonly()) {
HDSeed seed(BIP39::DeriveSeed(mnemonic, passphrase).bytes());
HDSeed seed(Mnemonic::DeriveSeed(mnemonic, passphrase).bytes());
HDKeychain rootkey = HDKeychain(seed.getExtendedKey(true));

HDKeychain xpub = rootkey.getChild("44'/0'/0'").getPublic();
Expand All @@ -1009,7 +1009,7 @@ namespace Elastos {
bytes_t bytes = AES::DecryptCCM(_localstore->GetMnemonic(), payPasswd);
std::string mnemonic((char *) &bytes[0], bytes.size());

uint512 seed = BIP39::DeriveSeed(mnemonic, passphrase);
uint512 seed = Mnemonic::DeriveSeed(mnemonic, passphrase);
HDSeed hdseed(seed.bytes());
HDKeychain rootkey = HDKeychain(hdseed.getExtendedKey(true));

Expand Down
4 changes: 2 additions & 2 deletions SDK/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ endforeach()

set(SPVSDK_SOURCE_FILES ${BRETH_SOURCE_FILES_REMOVE_TEST} ${SPVSDK_SOURCE_FILES})

set(SPVSDK_DEPENDS boost libressl libfruit libsqlite json libspdlog secp256k1)
set(LIBS boost_filesystem boost_system boost_thread crypto ssl fruit sqlite3 spdlog)
set(SPVSDK_DEPENDS boost libressl libfruit libsqlite json libspdlog secp256k1 libutf8proc)
set(LIBS boost_filesystem boost_system boost_thread crypto ssl fruit sqlite3 spdlog utf8proc)
if(ANDROID)
set(LIBS ${LIBS} log)
else()
Expand Down
2 changes: 1 addition & 1 deletion SDK/Common/ElementSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Elastos {
template<class T>
class ElementSet {
public:
typedef struct {
typedef struct _TCompare {
bool operator() (const T &x, const T &y) const {
return x->GetHash() < y->GetHash();
}
Expand Down
1 change: 0 additions & 1 deletion SDK/Ethereum/EthereumClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "EthereumClient.h"
#include "Common/Log.h"
#include "Common/ErrorChecker.h"
#include "WalletCore/WordLists/English.h"

namespace Elastos {
namespace ElaWallet {
Expand Down
5 changes: 2 additions & 3 deletions SDK/Implement/MasterWallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,8 @@ namespace Elastos {

}

std::string MasterWallet::GenerateMnemonic(const std::string &language, const std::string &rootPath,
Mnemonic::WordCount wordCount) {
return Mnemonic(boost::filesystem::path(rootPath)).Create(language, wordCount);
std::string MasterWallet::GenerateMnemonic(const std::string &language, Mnemonic::WordCount wordCount) {
return Mnemonic::Create(language, wordCount);
}

void MasterWallet::RemoveLocalStore() {
Expand Down
3 changes: 1 addition & 2 deletions SDK/Implement/MasterWallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ namespace Elastos {

public: //override from IMasterWallet

static std::string GenerateMnemonic(const std::string &language, const std::string &rootPath,
Mnemonic::WordCount wordCount = Mnemonic::WordCount::WORDS_12);
static std::string GenerateMnemonic(const std::string &language, Mnemonic::WordCount wordCount = Mnemonic::WordCount::WORDS_12);

virtual std::string GetID() const;

Expand Down
8 changes: 3 additions & 5 deletions SDK/Implement/MasterWalletManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ namespace Elastos {
ArgInfo("wordCount: {}", wordCount);

Mnemonic::WordCount count = Mnemonic::WordCount(wordCount);
std::string mnemonic = MasterWallet::GenerateMnemonic(language, _rootPath, count);
std::string mnemonic = MasterWallet::GenerateMnemonic(language, count);

ArgInfo("r => *");
return mnemonic;
Expand Down Expand Up @@ -217,8 +217,7 @@ namespace Elastos {
return _masterWalletMap[masterWalletID];
}

Mnemonic m(_rootPath);
ErrorChecker::CheckLogic(!m.Validate(mnemonic), Error::Mnemonic, "Invalid mnemonic");
ErrorChecker::CheckLogic(!Mnemonic::Validate(mnemonic), Error::Mnemonic, "Invalid mnemonic");

time_t now = time(NULL);
MasterWallet *masterWallet = new MasterWallet(masterWalletID, mnemonic, phrasePassword, payPassword,
Expand Down Expand Up @@ -507,8 +506,7 @@ namespace Elastos {
return _masterWalletMap[masterWalletID];
}

Mnemonic m(_rootPath);
ErrorChecker::CheckLogic(!m.Validate(mnemonic), Error::Mnemonic, "Invalid mnemonic");
ErrorChecker::CheckLogic(!Mnemonic::Validate(mnemonic), Error::Mnemonic, "Invalid mnemonic");

MasterWallet *masterWallet = new MasterWallet(masterWalletID, mnemonic, phrasePassword, payPassword,
singleAddress, _p2pEnable, ConfigPtr(new Config(*_config)),
Expand Down
2 changes: 1 addition & 1 deletion SDK/Wallet/UTXO.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace Elastos {
typedef boost::shared_ptr<UTXO> UTXOPtr;
typedef std::vector<UTXOPtr> UTXOArray;

typedef struct {
typedef struct _UTXOCompare {
bool operator() (const UTXOPtr &x, const UTXOPtr &y) const {
if (x->Hash() == y->Hash()) {
return x->Index() < y->Index();
Expand Down
2 changes: 1 addition & 1 deletion SDK/WalletCore/Address.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace Elastos {
};

typedef boost::shared_ptr<Address> AddressPtr;
typedef struct {
typedef struct _AddressCompare {
bool operator() (const AddressPtr &x, const AddressPtr &y) const {
return *x < *y;
}
Expand Down
159 changes: 0 additions & 159 deletions SDK/WalletCore/BIP39.cpp

This file was deleted.

Loading

0 comments on commit bbc29ff

Please sign in to comment.