Skip to content

Commit 5bff792

Browse files
Merge pull request #2 from fudgebucket27/feature/code-detect-from-image
Feature/code detect from image
2 parents 5ddb1c3 + 81c94dd commit 5bff792

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

LoopringSmartWalletPassphraseExtractor/LoopringSmartWalletRecoveryPhraseExtractor.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<ItemGroup>
1111
<PackageReference Include="Nethereum.HdWallet" Version="4.15.2" />
1212
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
13+
<PackageReference Include="OpenCvSharp4" Version="4.8.0.20230708" />
14+
<PackageReference Include="OpenCvSharp4.runtime.osx.10.15-x64" Version="4.6.0.20230105" />
15+
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.8.0.20230708" />
1316
</ItemGroup>
1417

1518
</Project>

LoopringSmartWalletPassphraseExtractor/Program.cs

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using LoopringSmartWalletRecoveryPhraseExtractor;
22
using Nethereum.HdWallet;
33
using Newtonsoft.Json;
4+
using OpenCvSharp;
45
using System.Security.Cryptography;
56
using System.Text;
67

@@ -9,22 +10,45 @@ internal class Program
910
private static void Main(string[] args)
1011
{
1112
QrCodeJson qrCodeJson = null;
12-
string loopringMigrationCodeQrText = ""; //the text of your Loopring migration qr code in JSON Format, eg: {"wallet":"0x99","iv":"2IcZe","mnemonic":"uvkZ","ens":"fudgey.loopring.eth","isCounterFactual":false,"register":"61,","type":"LoopringWalletSmart","setting":3232,"salt":"ikq","network":"ETHEREUM"}
13-
while (qrCodeJson == null)
13+
14+
// Path to the image
15+
string imagePath = "";
16+
while (string.IsNullOrEmpty(imagePath))
1417
{
15-
Console.WriteLine("Enter your Loopring Migration QR Code Text in JSON Format: ");
16-
loopringMigrationCodeQrText = Console.ReadLine().Trim(); ;
17-
try
18-
{
19-
qrCodeJson = JsonConvert.DeserializeObject<QrCodeJson>(loopringMigrationCodeQrText);
20-
}
21-
catch (JsonException)
18+
Console.WriteLine("Enter the file path to the QR code image: ");
19+
imagePath = Console.ReadLine().Trim(); ;
20+
}
21+
22+
// Read the image from the file
23+
using Mat image = Cv2.ImRead(imagePath);
24+
25+
// Initialize the QR code detector
26+
QRCodeDetector qrCodeDetector = new QRCodeDetector();
27+
28+
// Detect the QR code
29+
string decodedInfo = qrCodeDetector.DetectAndDecode(image, out Point2f[] points);
30+
31+
// Check if the QR code has been detected
32+
if (points != null && points.Length > 0)
33+
{
34+
// Draw a polygon around the detected QR code
35+
Cv2.Polylines(image, new Point[][] { points.Select(p => p.ToPoint()).ToArray() }, isClosed: true, color: Scalar.Red);
36+
37+
// Display the detected and decoded information
38+
Console.WriteLine("QR Code Detected: " + decodedInfo);
39+
if (decodedInfo.Trim().Length > 0)
2240
{
23-
Console.WriteLine("You have entered invalid Loopring Migration QR Code Text in JSON Format! Try Again...");
41+
qrCodeJson = JsonConvert.DeserializeObject<QrCodeJson>(decodedInfo);
2442
}
2543
}
44+
else
45+
{
46+
Console.WriteLine("QR Code Not Detected. Try a different image...");
47+
return;
48+
}
49+
2650

27-
string loopringAppPassCode = ""; //change this to suit your Loopring passcode
51+
string loopringAppPassCode = "";
2852
while (string.IsNullOrEmpty(loopringAppPassCode))
2953
{
3054
Console.WriteLine("Enter your Loopring Wallet App Passcode: ");
@@ -40,6 +64,7 @@ private static void Main(string[] args)
4064

4165
Console.WriteLine("Press any key to exit:");
4266
Console.ReadKey();
67+
}
4368

4469
static void QRCodeDecrypt(byte[] mnemonic, byte[] iv, byte[] salt, string passphrase)
4570
{
@@ -66,10 +91,10 @@ static void QRCodeDecrypt(byte[] mnemonic, byte[] iv, byte[] salt, string passph
6691
byte[] result = new byte[decryptedBytes.Length - paddingLength];
6792
Array.Copy(decryptedBytes, result, result.Length);
6893
string decryptedMnemonic = Encoding.UTF8.GetString(result);
69-
Console.WriteLine("Your recovery phrase for your owner wallet is: " + decryptedMnemonic);
94+
Console.WriteLine("Your recovery phrase for your owner wallet is: " + Environment.NewLine + decryptedMnemonic);
7095
Wallet wallet = new Wallet(decryptedMnemonic, null);
7196
string walletPrivateKey = BitConverter.ToString(wallet.GetPrivateKey(0)).Replace("-", string.Empty).ToLower();
72-
Console.WriteLine("Your L1 private key for your owner wallet is: " + walletPrivateKey);
97+
Console.WriteLine("Your L1 private key for your owner wallet is: " + Environment.NewLine + walletPrivateKey);
7398

7499
}
75100
catch(Exception)
@@ -80,4 +105,3 @@ static void QRCodeDecrypt(byte[] mnemonic, byte[] iv, byte[] salt, string passph
80105
}
81106
}
82107
}
83-
}

0 commit comments

Comments
 (0)