Ejemplo n.º 1
0
        private async Task<string> SignMessage(byte[] message, HDWalletProfile profile)
        {
            uint msgLength = (uint)message.Length;
            uint bytesToCopy = Math.Min(0xff - (uint)profile.DerivationData.Length - sizeof(int), msgLength);

            var messageChunk = new byte[bytesToCopy + sizeof(int)];
            msgLength.ToBytes().CopyTo(messageChunk, 0);

            Array.Copy(message, 0, messageChunk, sizeof(int), bytesToCopy);
            var output = await SendRequestAsync(EthSignMessage.Request(profile.DerivationData, messageChunk, true));

            msgLength -= bytesToCopy;
            uint pos = bytesToCopy;
            while (msgLength > 0 && IsSuccess(output.StatusCode))
            {
                bytesToCopy = Math.Min(0xff, msgLength);
                messageChunk = new byte[bytesToCopy];

                Array.Copy(message, pos, messageChunk, 0, bytesToCopy);
                output = await SendRequestAsync(EthSignMessage.Request(profile.DerivationData, messageChunk, false));

                msgLength -= bytesToCopy;
                pos += bytesToCopy;
            }

            if (IsSuccess(output.StatusCode))
            {
                return EthSignMessage.GetStringSignature(output.Data);
            }

            return null;
        }
Ejemplo n.º 2
0
        private async Task<string> SignTransaction(byte[] rlpEncodedTransaction, HDWalletProfile profile)
        {
            uint txLength = (uint)rlpEncodedTransaction.Length;
            uint bytesToCopy = Math.Min(0xff - (uint)profile.DerivationData.Length, txLength);

            var txChunk = new byte[bytesToCopy];
            Array.Copy(rlpEncodedTransaction, 0, txChunk, 0, bytesToCopy);
            var output = await SendRequestAsync(EthSignTransaction.Request(profile.DerivationData, txChunk, true));

            txLength -= bytesToCopy;
            uint pos = bytesToCopy;
            while (txLength > 0 && IsSuccess(output.StatusCode))
            {
                bytesToCopy = Math.Min(0xff, txLength);
                txChunk = new byte[bytesToCopy];

                Array.Copy(rlpEncodedTransaction, pos, txChunk, 0, bytesToCopy);
                output = await SendRequestAsync(EthSignTransaction.Request(profile.DerivationData, txChunk, false));

                txLength -= bytesToCopy;
                pos += bytesToCopy;
            }

            if (IsSuccess(output.StatusCode))
            {
                return EthSignTransaction.GetSignature(output.Data);
            }

            return null;
        }
Ejemplo n.º 3
0
        private async Task <string> SignMessage(byte[] message, HDWalletProfile profile)
        {
            var output = await SendRequestAsync(EthSignMessage.Request(profile.DerivationIndices, message));

            return(EthSignMessage.GetRLPEncoded(output, message));
        }
Ejemplo n.º 4
0
        private async Task <string> SignTransaction(byte[] rlpEncodedTransaction, HDWalletProfile profile)
        {
            var output = await SendRequestAsync(EthSignTransaction.Request(profile.DerivationIndices, rlpEncodedTransaction));

            return(EthSignTransaction.GetSignature(output));
        }