Exemple #1
0
CExtPubKey DecodeExtPubKey(const std::string& str)
{
    CExtPubKey key;
    std::vector<unsigned char> data;
    if (DecodeBase58Check(str, data)) {
        const std::vector<unsigned char>& prefix = Params().Base58Prefix(CChainParams::EXT_PUBLIC_KEY);
        if (data.size() == BIP32_EXTKEY_SIZE + prefix.size() && std::equal(prefix.begin(), prefix.end(), data.begin())) {
            key.Decode(data.data() + prefix.size());
        }
    }
    return key;
}
bool WalletBatch::WriteOfflineXPubKey(const CExtPubKey& offline_xpub)
{
    std::vector<unsigned char> vxpub;
    vxpub.resize(BIP32_EXTKEY_SIZE);
    offline_xpub.Encode(&vxpub[0]);
    return WriteIC(std::string("offlinexpub"), vxpub);
}
CAccountHD::CAccountHD(CExtPubKey accountKey_, boost::uuids::uuid seedID, AccountType type)
: CAccount()
, m_SeedID(seedID)
, m_nIndex(accountKey_.nChild)
{
    m_Type = type;

    //Random key - not actually used, but written to disk to avoid unnecessary complexity in serialisation code
    accountKeyPriv.GetMutableKey().MakeNewKey(true);
    primaryChainKeyPriv.GetMutableKey().MakeNewKey(true);
    changeChainKeyPriv.GetMutableKey().MakeNewKey(true);

    //NB! The change keys will be wrong here for read only witness accounts, but it doesn't matter because we only need to match one of the two keys to be able to tell it is ours.
    accountKey_.Derive(primaryChainKeyPub, 0);  //a/0
    accountKey_.Derive(changeChainKeyPub, 1);  //a/1
    m_readOnly = true;
}
Exemple #4
0
std::string EncodeExtPubKey(const CExtPubKey& key)
{
    std::vector<unsigned char> data = Params().Base58Prefix(CChainParams::EXT_PUBLIC_KEY);
    size_t size = data.size();
    data.resize(size + BIP32_EXTKEY_SIZE);
    key.Encode(data.data() + size);
    std::string ret = EncodeBase58Check(data);
    return ret;
}