BeamMW / beam

Beam: Scalable Confidential Cryptocurrency. Leading the way to Confidential DeFi
https://beam.mw
Apache License 2.0
698 stars 206 forks source link

I want to translate the source code of the wallet part to golang #1347

Closed liuxh-go closed 4 years ago

liuxh-go commented 4 years ago
bool ReadWalletSeed(NoLeak<uintBig>& walletSeed, const po::variables_map& vm, bool generateNew)
    {
        SecString seed;
        WordList phrase;
        if (generateNew)
        {
            LOG_INFO() << kSeedPhraseReadTitle;
            phrase = GeneratePhrase();
        }
        else if (vm.count(cli::SEED_PHRASE))
        {
            auto tempPhrase = vm[cli::SEED_PHRASE].as<string>();
            boost::algorithm::trim_if(tempPhrase, [](char ch) { return ch == ';'; });
            phrase = string_helpers::split(tempPhrase, ';');

            if (phrase.size() != WORD_COUNT
                || (vm.count(cli::IGNORE_DICTIONARY) == 0 && !isValidMnemonic(phrase, language::en)))
            {
                LOG_ERROR() << boost::format(kErrorSeedPhraseInvalid) % tempPhrase;
                return false;
            }
        }
        else
        {
            LOG_ERROR() << kErrorSeedPhraseNotProvided;
            return false;
        }

        auto buf = decodeMnemonic(phrase);
        seed.assign(buf.data(), buf.size());

        walletSeed.V = seed.hash().V;
        return true;
    }

I now have a problem. After using the downloaded wallet program to perform the init operation, I recorded Generated seed phrase in the command line interface, and then took outWalletSeed from the database file.I referenced the code of cli.cpp, then I used the Go language

buf := pbkdf2.Key([]byte(password), []byte(salt), 2048, 512>>3, sha256.New)
hash := sha256.New()
hash.Write(buf)
result := hex.EncodeToString(hash.Sum(nil))

, but the result was The data is different from WalletSeed. How do I calculate WalletSeed?

liuxh-go commented 4 years ago

I have solved the problem of seed, but now I do n’t know how to generate the address from the seed, because I do n’t know C ++ well, so I do n’t understand the conversion algorithm. Can I provide a conversion algorithm?

anatolse commented 4 years ago

please, look at void IWalletDB::get_SbbsWalletID(WalletID& wid, uint64_t ownID) method. The key moment here is that we are using key derivative functions(kdf) to generate all the keys in BEAM (including new kdf). Generation of a new secret key looks like one of kdf->Derive*() methods call. Input data for these methods is a structure KID which holds an integer index(and subindex) and type of the key. So, to create a SBBS address we

  1. Get a kdf (created from master key)
  2. Generate a secret key (sk) with type Key::Type::Bbs
  3. Get public key
  4. Concatenate it with channel number
  5. Serialize it and represent like hex string p.1-3 are done in get_SbbsPeerID

Note, that sbbs address is simply the mean of communication between wallets.

gingervik commented 4 years ago

there is no user's response for 6 months