public void BytesToAddresses_ShortMessage()
        {
            // a - TJp6YfcXar2jF1LA3QjmfzfeD26hp9qXNn <- correct version on redstone testnet

            string inputMessage = "a";

            byte[] inputMessageBytes     = Encoding.ASCII.GetBytes(inputMessage);
            List <BitcoinAddress> output = BlockChainDataConversions.BytesToAddresses(RedstoneNetworks.TestNet, inputMessageBytes);

            var expectedOutput = new List <BitcoinAddress> {
                BitcoinAddress.Create("TJp6YfcXar2jF1LA3QjmfzfeD26hp9qXNn")
            };

            /* Worked example
             * // 0x00 - Bitcoin Mainnet
             * // 0x6F - Bitcoin Testnet
             * // 0x41 - Redstone test <----
             * // 0x3c - Redstone main
             *
             * // Literal 'a' is 0x61 hex
             * var keyBytes = new byte[] {0x41, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
             * var algorithm = SHA256.Create();
             * var hash = algorithm.ComputeHash(algorithm.ComputeHash(keyBytes));
             *
             * //First 4 bytes of double SHA256: 15, 146, 165, 196
             * //Need to concatenate them to keyBytes
             *
             * var keyBytes2 = new byte[] {0x41,
             *  0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             *  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             *  134, 212, 83, 7};
             *
             * var finalEncodedAddress = Encoders.Base58.EncodeData(keyBytes2);
             * /*
             * Result should be "TJp6YfcXar2jF1LA3QjmfzfeD26hp9qXNn"
             */

            Assert.Equal(expectedOutput, output);
        }
Esempio n. 2
0
        public void BytesToAddresses_ShortMessage()
        {
            // a - mpMqqfKnF9M2rwk9Ai4RymBqADx6TssFuM <- correct version on testnet
            //     mpMqqfKnF9M2rwk9Ai4RymBqADx6TUnBkb <- incorrect version with 00000000 checksum bytes

            string inputMessage = "a";

            byte[] inputMessageBytes             = Encoding.ASCII.GetBytes(inputMessage);
            List <BitcoinAddress> output         = BlockChainDataConversions.BytesToAddresses(Network.TestNet, inputMessageBytes);
            List <BitcoinAddress> expectedOutput = new List <BitcoinAddress>();

            expectedOutput.Add(BitcoinAddress.Create("mpMqqfKnF9M2rwk9Ai4RymBqADx6TssFuM"));

            /* Worked example
             * // 0x00 - Mainnet
             * // 0x6F - Testnet
             * // 0x?? - Stratis mainnet
             *
             * // Literal 'a' is 0x61 hex
             *
             * var keyBytes = new byte[] {0x6F, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
             * var algorithm = SHA256.Create();
             * var hash = algorithm.ComputeHash(algorithm.ComputeHash(keyBytes));
             *
             * First 4 bytes of double SHA256: 15, 146, 165, 196
             * Need to concatenate them to keyBytes
             *
             * var keyBytes2 = new byte[] {0x6F,
             *  0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             *  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             *  15, 146, 165, 196};
             *
             * var finalEncodedAddress = Encoders.Base58.EncodeData(keyBytes2);
             *
             * Result should be "mpMqqfKnF9M2rwk9Ai4RymBqADx6TssFuM"
             */

            Assert.Equal(expectedOutput, output);
        }