Skip to content

Commit

Permalink
Update NonceTest. #119
Browse files Browse the repository at this point in the history
  • Loading branch information
kPatch committed Dec 11, 2024
1 parent a5ede02 commit fdbc75c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Assets/Sui-Unity-SDK/Tests/ZKLogin/NonceTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.Numerics;
using NUnit.Framework;
using Sui.Cryptography.Ed25519;
using Sui.ZKLogin.SDK;
using UnityEngine;

namespace Sui.Tests.ZkLogin
{
[TestFixture]
public class NonceTest : MonoBehaviour
{
int maxEpoch = 26;
string pkBase64 = "lHezoWY/4pRWe+iajFHw62hQjmVQ6wlL+C8CJxw4bY0=";
string pubKeyBase64Expected = "/CTTrykDrvNxtl0WfBo3Q+H/L9VLJAzwXAJew6cMP70=";

//BigInteger randomness = 91593735651025872471886891147594672981; // too long
//BigInteger randomness = 9159373565102587247;
BigInteger randomness = BigInteger.Parse("91593735651025872471886891147594672981");

/// <summary>
/// PrivateKey:
/// {"schema":"ED25519","privateKey":"lHezoWY/4pRWe+iajFHw62hQjmVQ6wlL+C8CJxw4bY0="}
/// PublicKey:
/// "/CTTrykDrvNxtl0WfBo3Q+H/L9VLJAzwXAJew6cMP70="
/// </summary>
[Test]
public void GenerateNonceTest()
{
PrivateKey pk = new PrivateKey(pkBase64);
string pubKey = pk.PublicKey().KeyBase64;

Assert.AreEqual(pubKeyBase64Expected, pubKey);

string nonce = NonceGenerator.GenerateNonce(
(PublicKey)pk.PublicKey(),
maxEpoch,
randomness
);

string nonceExpected = "LSLuhEjHLSeRvyI26wfPQSjYNbc";
Debug.Log("RAND: LOG: " + randomness);
Assert.AreEqual(nonceExpected, nonce, "RAND: " + randomness.ToString());
}

[Test]
public void ToBigIntBETest()
{
byte[] bytes = { };
BigInteger toBigintBE = NonceGenerator.ToBigIntBE(bytes);
Assert.AreEqual(null, bytes, "BigInteger Valye: " + "[IMPLEMENT]");
}
}
}
2 changes: 2 additions & 0 deletions Assets/Sui-Unity-SDK/Tests/ZKLogin/NonceTest.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fdbc75c

Please sign in to comment.