//this class will hold all required code for creating a new wallet from scratch

        public static WalletData NewWallet(String _walletName, String _walletfilePath, string _passCode)
        {
            String     passString = _passCode;
            Keys       KeysClass;
            Boolean    passAcceptable;
            WalletData WalletDataCreate;

            passAcceptable = PasswordManager.CheckPassRequirements(passString);

            if (passAcceptable)
            {
                KeysClass        = KeyManager.GenerateKeySet(_passCode, _walletName);
                WalletDataCreate = new WalletData();
                WalletDataCreate = WalletDataCreate.CreateNewWalletData(KeysClass, _passCode, _walletName);

                return(WalletDataCreate);
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        /*OK, as far as I figured out now we need to do the following:
         * - Step 1: Generate private spend key (SHA 256 hash of passcode + username)
         * - Step 2: Generate private view key (SHA 256 hash of passcode + hash of private spend key)
         * - Step 3: Generate public spend key (ed25519 scalarmult of private spend key)
         * - Step 4: Generate public view key (ed25519 scalarmult of private view key)
         * - Step 5: Add network byte to public spend and view key
         * - Step 6: this 65 byte needs to be hashed with keccak 256
         * - Step 7: Add first 4 bytes from hashed value to the 67 bytes (at the end)
         * - Step 8: Convert the 71 bytes to Base58
         * - Step 9: Maybe we'd like to have one "superkey" which unlocks private spend and view key...who knows
         * - Known bug: prefix
         */
        public static Keys GenerateKeySet(string _passCode, string _walletName)
        {
            Keys keyStorage = new Keys();

            byte[] privateSpendKey = KeyManager.GeneratePrivateSpendKey(_passCode, _walletName);                    //Done
            byte[] privateViewKey  = KeyManager.GeneratePrivateViewKey(_passCode, privateSpendKey);                 //Done
            byte[] publicSpendKey  = KeyManager.GeneratePubSpendKey(privateSpendKey);                               //Done
            byte[] publicViewKey   = KeyManager.GeneratePubViewKey(privateViewKey);                                 //Done
            byte[] networkByte     = KeyManager.StringToByteArray(Config.GetConfiguration().NetworkPreFix);         //Done
            byte[] hashedKey       = KeyManager.HashKeccak256(publicSpendKey, publicViewKey, networkByte);          //Done
            string publicAddress   = KeyManager.ConvertToPubAddressChunked(hashedKey);                              //Done

            //Store the data of the wallet

            keyStorage.StoreKeySet(privateSpendKey, privateViewKey, publicSpendKey, publicViewKey, networkByte, hashedKey, publicAddress, PasswordManager.GenerateSaltedOutputBytes(_passCode), _walletName);

            return(keyStorage);              //Return the public address, the rest we have to store somewhere safe...
        }