Ejemplo n.º 1
0
        /*
         *
         * Next Private Key = hash( current public key + seed + currentIndex )
         */
        private Wallet next(byte[] seed)
        {
            byte[] currentIndexByte = BitConverter.GetBytes(currentIndex);

            byte[] beforehash = new byte[keyPair.PublicKey.Length + seed.Length + currentIndexByte.Length];

            System.Buffer.BlockCopy(keyPair.PublicKey, 0, beforehash, 0, keyPair.PublicKey.Length);
            System.Buffer.BlockCopy(seed, 0, beforehash, keyPair.PublicKey.Length, seed.Length);
            System.Buffer.BlockCopy(currentIndexByte, 0, beforehash, keyPair.PublicKey.Length + seed.Length, currentIndexByte.Length);

            byte[] nextPrivKey = Hash.ComputeDoubleSHA256(beforehash);

            byte[] nextPubKeyByte;

            EccService.GenerateKeyFromPrivateKey(nextPrivKey, out nextPubKeyByte);

            KeyPair nextKeyPair = new KeyPair
            {
                PrivateKey = nextPrivKey,
                PublicKey  = nextPubKeyByte,
                Address    = BlockchainUtil.ToAddress(nextPubKeyByte),
            };

            return(new Wallet(nextKeyPair, currentIndex + 1));
        }