From fdbc75c0200af437f7715f4d4680b987f3ea95aa Mon Sep 17 00:00:00 2001 From: Irvin Date: Wed, 11 Dec 2024 20:01:32 +0700 Subject: [PATCH] Update NonceTest. #119 --- .../Sui-Unity-SDK/Tests/ZKLogin/NonceTest.cs | 53 +++++++++++++++++++ .../Tests/ZKLogin/NonceTest.cs.meta | 2 + 2 files changed, 55 insertions(+) create mode 100644 Assets/Sui-Unity-SDK/Tests/ZKLogin/NonceTest.cs create mode 100644 Assets/Sui-Unity-SDK/Tests/ZKLogin/NonceTest.cs.meta diff --git a/Assets/Sui-Unity-SDK/Tests/ZKLogin/NonceTest.cs b/Assets/Sui-Unity-SDK/Tests/ZKLogin/NonceTest.cs new file mode 100644 index 0000000..3fd64cf --- /dev/null +++ b/Assets/Sui-Unity-SDK/Tests/ZKLogin/NonceTest.cs @@ -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"); + + /// + /// PrivateKey: + /// {"schema":"ED25519","privateKey":"lHezoWY/4pRWe+iajFHw62hQjmVQ6wlL+C8CJxw4bY0="} + /// PublicKey: + /// "/CTTrykDrvNxtl0WfBo3Q+H/L9VLJAzwXAJew6cMP70=" + /// + [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]"); + } + } +} \ No newline at end of file diff --git a/Assets/Sui-Unity-SDK/Tests/ZKLogin/NonceTest.cs.meta b/Assets/Sui-Unity-SDK/Tests/ZKLogin/NonceTest.cs.meta new file mode 100644 index 0000000..1931e5f --- /dev/null +++ b/Assets/Sui-Unity-SDK/Tests/ZKLogin/NonceTest.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: b9731e387983040029ac2700b2b787bd \ No newline at end of file