Skip to content

Commit 00f1513

Browse files
committed
fix: address arkana issues
1 parent 0c9d04f commit 00f1513

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

NArk.Abstractions/ArkCash.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Buffers.Binary;
2+
using System.Security.Cryptography;
23
using NArk.Abstractions.Contracts;
34
using NBitcoin;
45
using NBitcoin.DataEncoders;
@@ -8,7 +9,7 @@ namespace NArk.Abstractions;
89

910
public class ArkCash: IDisposable
1011
{
11-
private static readonly byte Version = 0x00;
12+
private const byte Version = 0x00;
1213
private const int PayloadLength = 1 + 32 + 32 + 4;
1314

1415
private const string HrpMainnet = "arkcash";
@@ -53,17 +54,24 @@ public ArkCash(ECPrivKey privKey, ECXOnlyPubKey serverPubkey, Sequence lockTime,
5354
public static ArkCash Generate(ECXOnlyPubKey serverPubkey, Sequence locktime, string? hrp = null)
5455
{
5556
var pk = RandomUtils.GetBytes(32);
56-
if (!ECPrivKey.TryCreate(pk, out var key))
57+
try
5758
{
58-
throw new ArgumentNullException(nameof(key));
59+
if (!ECPrivKey.TryCreate(pk, out var key))
60+
{
61+
throw new InvalidOperationException("Could not generate ArkCash address!");
62+
}
63+
64+
if (hrp is null)
65+
{
66+
return new ArkCash(key, serverPubkey, locktime);
67+
}
68+
69+
return new ArkCash(key, serverPubkey, locktime, hrp);
5970
}
60-
61-
if (hrp is null)
71+
finally
6272
{
63-
return new ArkCash(key, serverPubkey, locktime);
73+
CryptographicOperations.ZeroMemory(pk);
6474
}
65-
66-
return new ArkCash(key, serverPubkey, locktime, hrp);
6775
}
6876

6977
public override string ToString()

0 commit comments

Comments
 (0)