-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3688 from planetarium/fix/private-key-error
fix: private key hex with zero paddings
- Loading branch information
Showing
9 changed files
with
61 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
nekoyume/Assets/Tests/EditMode/Extensions/PrivateKeyExtensionsTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using Libplanet.Common; | ||
using Libplanet.Crypto; | ||
using Nekoyume; | ||
using NUnit.Framework; | ||
|
||
namespace Tests.EditMode.Extensions | ||
{ | ||
public class PrivateKeyExtensionsTest | ||
{ | ||
[Test] | ||
public void ToHexWithZeroPaddings() | ||
{ | ||
const string hexWithZeroPaddings = | ||
"00000102030405060708090a0102030405060708090b0102030405060708090c"; | ||
var privateKey = new PrivateKey(hexWithZeroPaddings); | ||
Assert.AreNotEqual(hexWithZeroPaddings, ByteUtil.Hex(privateKey.ByteArray)); | ||
Assert.Throws<ArgumentOutOfRangeException>(() => new PrivateKey(ByteUtil.Hex(privateKey.ByteArray))); | ||
Assert.AreEqual(hexWithZeroPaddings, privateKey.ToHexWithZeroPaddings()); | ||
Assert.DoesNotThrow(() => new PrivateKey(privateKey.ToHexWithZeroPaddings())); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
nekoyume/Assets/Tests/EditMode/Extensions/PrivateKeyExtensionsTest.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
nekoyume/Assets/_Scripts/Extensions/PrivateKeyExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Libplanet.Common; | ||
using Libplanet.Crypto; | ||
|
||
namespace Nekoyume | ||
{ | ||
public static class PrivateKeyExtensions | ||
{ | ||
public static string ToHexWithZeroPaddings(this PrivateKey privateKey) | ||
{ | ||
var hex = ByteUtil.Hex(privateKey.ByteArray); | ||
return hex.PadLeft(64, '0'); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
nekoyume/Assets/_Scripts/Extensions/PrivateKeyExtensions.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters