main: Added signing messages

This commit is contained in:
Nathan Woodburn 2023-07-15 20:58:34 +10:00
parent 91150a2b07
commit 4606eaf8a3
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
2 changed files with 59 additions and 2 deletions

View File

@ -39,8 +39,10 @@
buttonCancel = new Button(); buttonCancel = new Button();
buttonFinalize = new Button(); buttonFinalize = new Button();
groupBoxSign = new GroupBox(); groupBoxSign = new GroupBox();
buttonSign = new Button();
textBoxSignMessage = new TextBox(); textBoxSignMessage = new TextBox();
labelSignMessage = new Label(); labelSignMessage = new Label();
textBoxSignature = new TextBox();
groupBoxManage.SuspendLayout(); groupBoxManage.SuspendLayout();
groupBoxSign.SuspendLayout(); groupBoxSign.SuspendLayout();
SuspendLayout(); SuspendLayout();
@ -151,6 +153,8 @@
// //
// groupBoxSign // groupBoxSign
// //
groupBoxSign.Controls.Add(textBoxSignature);
groupBoxSign.Controls.Add(buttonSign);
groupBoxSign.Controls.Add(textBoxSignMessage); groupBoxSign.Controls.Add(textBoxSignMessage);
groupBoxSign.Controls.Add(labelSignMessage); groupBoxSign.Controls.Add(labelSignMessage);
groupBoxSign.Font = new Font("Segoe UI", 14F, FontStyle.Regular, GraphicsUnit.Point); groupBoxSign.Font = new Font("Segoe UI", 14F, FontStyle.Regular, GraphicsUnit.Point);
@ -161,12 +165,22 @@
groupBoxSign.TabStop = false; groupBoxSign.TabStop = false;
groupBoxSign.Text = "Sign"; 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
// //
textBoxSignMessage.Location = new Point(6, 56); textBoxSignMessage.Location = new Point(6, 56);
textBoxSignMessage.Multiline = true; textBoxSignMessage.Multiline = true;
textBoxSignMessage.Name = "textBoxSignMessage"; textBoxSignMessage.Name = "textBoxSignMessage";
textBoxSignMessage.Size = new Size(744, 195); textBoxSignMessage.Size = new Size(472, 156);
textBoxSignMessage.TabIndex = 1; textBoxSignMessage.TabIndex = 1;
// //
// labelSignMessage // labelSignMessage
@ -178,6 +192,15 @@
labelSignMessage.TabIndex = 0; labelSignMessage.TabIndex = 0;
labelSignMessage.Text = "Message:"; 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 // DomainForm
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
@ -216,5 +239,7 @@
private GroupBox groupBoxSign; private GroupBox groupBoxSign;
private TextBox textBoxSignMessage; private TextBox textBoxSignMessage;
private Label labelSignMessage; private Label labelSignMessage;
private Button buttonSign;
private TextBox textBoxSignature;
} }
} }

View File

@ -37,7 +37,7 @@ namespace FireWalletLite
private void DomainForm_Load(object sender, EventArgs e) private void DomainForm_Load(object sender, EventArgs e)
{ {
if (!File.Exists(Main.dir + "domains.json")) return; if (!File.Exists(Main.dir + "domains.json")) return;
JArray domains = JArray.Parse(File.ReadAllText(Main.dir + "domains.json")); JArray domains = JArray.Parse(File.ReadAllText(Main.dir + "domains.json"));
foreach (JObject domain in domains) foreach (JObject domain in domains)
{ {
@ -238,5 +238,37 @@ namespace FireWalletLite
File.WriteAllText(Main.dir + "domains.json", domains.ToString()); 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();
}
}
} }
} }