コード例 #1
0
        public byte[] GetAddressWallet(TypeNet typeNet)
        {
            byte[] bytesPub64 = PublicKeyShort;

            byte[] computeHash = Sha256Keccak.Hash(bytesPub64);

            //computeHash.ToHexString2();

            byte[] computeHash20 = computeHash.SubArray(11, 21);
            //computeHash20.ToHexString2();
            if (typeNet == TypeNet.Main)
            {
                computeHash20[0] = 65;
            }
            else
            {
                computeHash20[0] = 160;
            }

            //string hexString2 = computeHash20.ToHexString2();

            byte[] secondSha = Sha256.HashTwice(computeHash20);
            byte[] checkSum  = secondSha.SubArray(0, 4);
            //string SecondSHAhexString2 = secondSha.ToHexString2();

            byte[] address = new byte[computeHash20.Length + 4];
            Array.Copy(computeHash20, 0, address, 0, computeHash20.Length);
            Array.Copy(checkSum, 0, address, 21, 4);

            //string hexString = address.ToHexString2();
            //string encode = Base_58.Encode(address);

            return(address);
        }
コード例 #2
0
        private static byte[] signTransaction2Byte(byte[] transaction, byte[] privateKey)
        {
            ECKey       ecKey        = ECKey.FromPrivate(privateKey);
            Transaction transaction1 = Transaction.Parser.ParseFrom(transaction);

            byte[]      rawdata = transaction1.RawData.ToByteArray();
            byte[]      hash    = Sha256Keccak.Hash(rawdata);
            byte[]      sign    = ecKey.GetSignature(hash);
            Transaction clone   = transaction1.Clone();

            clone.Signature.Add(ByteString.CopyFrom(sign));
            return(clone.ToByteArray());
        }
コード例 #3
0
        public static Transaction sign(Transaction transaction, KeyTriple myKey)
        {
            byte[] hash = Sha256Keccak.Hash(transaction.RawData.ToByteArray());
            //	Transaction.Types.Contract listContract = transaction.RawData.Contract;
            //	for (int i = 0; i < listContract.size(); i++)
            //	{
            byte[]     signature = myKey.GetSignature(hash);
            ByteString bsSign    = ByteString.CopyFrom(signature);

            transaction.Signature.Add(bsSign);             //Each contract may be signed with a different private key in the future.
            //	}
            return(transaction);
        }
コード例 #4
0
 public static byte[] GetBlockHash(Block block)
 {
     return(Sha256Keccak.Hash(block.BlockHeader.RawData.ToByteArray()));
 }