From 4606eaf8a319d99f0134cc1c74c044f34436512a Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Sat, 15 Jul 2023 20:58:34 +1000 Subject: [PATCH 1/2] main: Added signing messages --- FireWalletLite/DomainForm.Designer.cs | 27 ++++++++++++++++++++- FireWalletLite/DomainForm.cs | 34 ++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/FireWalletLite/DomainForm.Designer.cs b/FireWalletLite/DomainForm.Designer.cs index 92bb17d..1c33768 100644 --- a/FireWalletLite/DomainForm.Designer.cs +++ b/FireWalletLite/DomainForm.Designer.cs @@ -39,8 +39,10 @@ buttonCancel = new Button(); buttonFinalize = new Button(); groupBoxSign = new GroupBox(); + buttonSign = new Button(); textBoxSignMessage = new TextBox(); labelSignMessage = new Label(); + textBoxSignature = new TextBox(); groupBoxManage.SuspendLayout(); groupBoxSign.SuspendLayout(); SuspendLayout(); @@ -151,6 +153,8 @@ // // groupBoxSign // + groupBoxSign.Controls.Add(textBoxSignature); + groupBoxSign.Controls.Add(buttonSign); groupBoxSign.Controls.Add(textBoxSignMessage); groupBoxSign.Controls.Add(labelSignMessage); groupBoxSign.Font = new Font("Segoe UI", 14F, FontStyle.Regular, GraphicsUnit.Point); @@ -161,12 +165,22 @@ groupBoxSign.TabStop = false; groupBoxSign.Text = "Sign"; // + // buttonSign + // + buttonSign.Location = new Point(606, 218); + buttonSign.Name = "buttonSign"; + buttonSign.Size = new Size(138, 33); + buttonSign.TabIndex = 2; + buttonSign.Text = "Sign"; + buttonSign.UseVisualStyleBackColor = true; + buttonSign.Click += buttonSign_Click; + // // textBoxSignMessage // textBoxSignMessage.Location = new Point(6, 56); textBoxSignMessage.Multiline = true; textBoxSignMessage.Name = "textBoxSignMessage"; - textBoxSignMessage.Size = new Size(744, 195); + textBoxSignMessage.Size = new Size(472, 156); textBoxSignMessage.TabIndex = 1; // // labelSignMessage @@ -178,6 +192,15 @@ labelSignMessage.TabIndex = 0; labelSignMessage.Text = "Message:"; // + // textBoxSignature + // + textBoxSignature.Location = new Point(484, 56); + textBoxSignature.Multiline = true; + textBoxSignature.Name = "textBoxSignature"; + textBoxSignature.ReadOnly = true; + textBoxSignature.Size = new Size(260, 156); + textBoxSignature.TabIndex = 3; + // // DomainForm // AutoScaleDimensions = new SizeF(7F, 15F); @@ -216,5 +239,7 @@ private GroupBox groupBoxSign; private TextBox textBoxSignMessage; private Label labelSignMessage; + private Button buttonSign; + private TextBox textBoxSignature; } } \ No newline at end of file diff --git a/FireWalletLite/DomainForm.cs b/FireWalletLite/DomainForm.cs index 91ade65..e0c47da 100644 --- a/FireWalletLite/DomainForm.cs +++ b/FireWalletLite/DomainForm.cs @@ -37,7 +37,7 @@ namespace FireWalletLite private void DomainForm_Load(object sender, EventArgs e) { if (!File.Exists(Main.dir + "domains.json")) return; - + JArray domains = JArray.Parse(File.ReadAllText(Main.dir + "domains.json")); foreach (JObject domain in domains) { @@ -238,5 +238,37 @@ namespace FireWalletLite File.WriteAllText(Main.dir + "domains.json", domains.ToString()); } } + + private async void buttonSign_Click(object sender, EventArgs e) + { + if (textBoxSignMessage.Text == "") + { + NotifyForm notify = new NotifyForm("Enter a message to sign"); + notify.ShowDialog(); + notify.Dispose(); + return; + } + string content = "{\"method\": \"signmessagewithname\", \"params\": [\"" + Domain + "\", \"" + textBoxSignMessage.Text + "\"]}"; + string response = await Main.APIPost("", true, content); + Main.AddLog(response); + if (response == "Error") + { + NotifyForm notify = new NotifyForm("Error signing message"); + notify.ShowDialog(); + notify.Dispose(); + return; + } + JObject jObject = JObject.Parse(response); + if (jObject.ContainsKey("result")) + { + textBoxSignature.Text = jObject["result"].ToString(); + } + else + { + NotifyForm notify = new NotifyForm("Error signing message"); + notify.ShowDialog(); + notify.Dispose(); + } + } } } From 5550ce472e338bd1d1531f8f5e1a92912c42f06b Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Sat, 15 Jul 2023 21:06:11 +1000 Subject: [PATCH 2/2] main: Added save signed message --- FireWalletLite/DomainForm.Designer.cs | 21 +++++++++++---------- FireWalletLite/DomainForm.cs | 25 ++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/FireWalletLite/DomainForm.Designer.cs b/FireWalletLite/DomainForm.Designer.cs index 1c33768..d9498cc 100644 --- a/FireWalletLite/DomainForm.Designer.cs +++ b/FireWalletLite/DomainForm.Designer.cs @@ -39,10 +39,10 @@ buttonCancel = new Button(); buttonFinalize = new Button(); groupBoxSign = new GroupBox(); + textBoxSignature = new TextBox(); buttonSign = new Button(); textBoxSignMessage = new TextBox(); labelSignMessage = new Label(); - textBoxSignature = new TextBox(); groupBoxManage.SuspendLayout(); groupBoxSign.SuspendLayout(); SuspendLayout(); @@ -165,6 +165,15 @@ groupBoxSign.TabStop = false; groupBoxSign.Text = "Sign"; // + // textBoxSignature + // + textBoxSignature.Location = new Point(484, 56); + textBoxSignature.Multiline = true; + textBoxSignature.Name = "textBoxSignature"; + textBoxSignature.ReadOnly = true; + textBoxSignature.Size = new Size(260, 156); + textBoxSignature.TabIndex = 3; + // // buttonSign // buttonSign.Location = new Point(606, 218); @@ -182,6 +191,7 @@ textBoxSignMessage.Name = "textBoxSignMessage"; textBoxSignMessage.Size = new Size(472, 156); textBoxSignMessage.TabIndex = 1; + textBoxSignMessage.TextChanged += textBoxSignMessage_TextChanged; // // labelSignMessage // @@ -192,15 +202,6 @@ labelSignMessage.TabIndex = 0; labelSignMessage.Text = "Message:"; // - // textBoxSignature - // - textBoxSignature.Location = new Point(484, 56); - textBoxSignature.Multiline = true; - textBoxSignature.Name = "textBoxSignature"; - textBoxSignature.ReadOnly = true; - textBoxSignature.Size = new Size(260, 156); - textBoxSignature.TabIndex = 3; - // // DomainForm // AutoScaleDimensions = new SizeF(7F, 15F); diff --git a/FireWalletLite/DomainForm.cs b/FireWalletLite/DomainForm.cs index e0c47da..ff2835d 100644 --- a/FireWalletLite/DomainForm.cs +++ b/FireWalletLite/DomainForm.cs @@ -241,6 +241,23 @@ namespace FireWalletLite private async void buttonSign_Click(object sender, EventArgs e) { + if (buttonSign.Text == "Save") + { + SaveFileDialog saveFileDialog = new SaveFileDialog(); + saveFileDialog.Filter = "Text File|*.txt"; + saveFileDialog.Title = "Save Signature"; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + JObject signature = new JObject(); + signature["domain"] = Domain; + signature["message"] = textBoxSignMessage.Text; + signature["signature"] = textBoxSignature.Text; + signature["time"] = DateTime.Now.ToString(); + File.WriteAllText(saveFileDialog.FileName, signature.ToString()); + } + + return; + } if (textBoxSignMessage.Text == "") { NotifyForm notify = new NotifyForm("Enter a message to sign"); @@ -250,7 +267,6 @@ namespace FireWalletLite } string content = "{\"method\": \"signmessagewithname\", \"params\": [\"" + Domain + "\", \"" + textBoxSignMessage.Text + "\"]}"; string response = await Main.APIPost("", true, content); - Main.AddLog(response); if (response == "Error") { NotifyForm notify = new NotifyForm("Error signing message"); @@ -262,13 +278,20 @@ namespace FireWalletLite if (jObject.ContainsKey("result")) { textBoxSignature.Text = jObject["result"].ToString(); + buttonSign.Text = "Save"; } else { + Main.AddLog(response); NotifyForm notify = new NotifyForm("Error signing message"); notify.ShowDialog(); notify.Dispose(); } } + + private void textBoxSignMessage_TextChanged(object sender, EventArgs e) + { + buttonSign.Text = "Sign"; + } } }