-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmMain.cs
162 lines (132 loc) · 4.7 KB
/
frmMain.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PBPubkeyConverter
{
public partial class frmMain : Form
{
public Dictionary<String, String> PubKeyPrefixes = new Dictionary<String, String>()
{
["xpub"] = "0488b21e",
["ypub"] = "049d7cb2",
["Ypub"] = "0295b43f",
["zpub"] = "04b24746",
["Zpub"] = "02aa7ed3",
["tpub"] = "043587cf",
["upub"] = "044a5262",
["Upub"] = "024289ef",
["vpub"] = "045f1cf6",
["Vpub"] = "02575483",
["drkp"] = "02fe52cc",
["drkv"] = "02fe52f8",
["DRKP"] = "3a805837",
["DRKV"] = "3a8061a0",
["tpub"] = "043587cf",
["tprv"] = "04358394",
["Ltub"] = "019da462",
};
public frmMain()
{
InitializeComponent();
}
/// <summary>
/// xpub = 0488b21e
///
/// </summary>
/// <param name="xpubkey"></param>
/// <param name="newFormat"></param>
/// <returns></returns>
public string ParseNewxPubFormats(string xpubkey, string newFormat = "xpub")
{
try
{
var encoder = new NBitcoin.DataEncoders.Base58CheckEncoder();
var decoded = encoder.DecodeData(xpubkey);
var decoded_2 = decoded.Skip(4).ToArray();
var decoded_3 = StringToByteArray(PubKeyPrefixes[newFormat]).Concat(decoded_2).ToArray();
var encoded = encoder.EncodeData(decoded_3);
return encoded;
}
catch
{
return null;
}
}
public static byte[] StringToByteArray(string hex)
{
return Enumerable.Range(0, hex.Length)
.Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
.ToArray();
}
private void llLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
OpenUrl("https://premium.black");
}
static void OpenUrl(string url)
{
try
{
Process.Start(url);
}
catch
{
// hack because of this: https://github.com/dotnet/corefx/issues/10361
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
url = url.Replace("&", "^&");
var p = Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });
Thread.Sleep(1000);
p.Close();
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Process.Start("xdg-open", url);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Process.Start("open", url);
}
else
{
throw;
}
}
}
private void bnConvert_Click(object sender, EventArgs e)
{
if(!PubKeyPrefixes.ContainsKey(cmbTypes.SelectedItem.ToString()))
{
return;
}
var s = ParseNewxPubFormats(txtPublicKeyIn.Text, cmbTypes.SelectedItem.ToString());
txtConverted.Text = s;
}
private void frmMain_Load(object sender, EventArgs e)
{
if (MessageBox.Show("DISCLAIMER: Please use this tool on your own RISK.\r\nIt can help you, to get your Public Key (xPub) in a different format for PREMIUM BLACK or other services. This tool will be provided \"as-is\" without any warranty about its functionality. But at any time prove the given public key and compare with the one you'll receive from your wallet.\r\nWhen you press on OK you agree with that.", "DISCLAIMER", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
{
this.Close();
return;
}
loadTypes();
cmbTypes.SelectedItem = "xpub";
}
private void loadTypes()
{
foreach(var k in PubKeyPrefixes.OrderBy(a => a.Key))
{
cmbTypes.Items.Add(k.Key);
}
}
}
}