diff --git a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/AccountAddress.cs b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/AccountAddress.cs
index 92671a9..6561ace 100644
--- a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/AccountAddress.cs
+++ b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/AccountAddress.cs
@@ -24,13 +24,15 @@
//
using System;
-using Sui.Utilities;
using System.Text;
using Sui.Cryptography;
using Konscious.Security.Cryptography;
namespace Sui.ZKLogin
{
+ ///
+ /// TODO: Look into where and how this is used in ZK Login TS
+ ///
public class AccountAddress : Accounts.AccountAddress
{
///
@@ -39,22 +41,19 @@ public class AccountAddress : Accounts.AccountAddress
/// The address seed as BigInteger
/// The issuer string
/// Normalized Sui address string
- public Sui.Accounts.AccountAddress ComputeZkLoginAddressFromSeed(long addressSeed, string iss)
+ public Accounts.AccountAddress ComputeZkLoginAddressFromSeed(long addressSeed, string iss)
{
- //TS: bytesToHex(blake2b(tmp, { dkLen: 32 })).slice(0, SUI_ADDRESS_LENGTH * 2),
- //string hex = BitConverter.ToString(bytes);
+ // TS: bytesToHex(blake2b(tmp, { dkLen: 32 })).slice(0, SUI_ADDRESS_LENGTH * 2),
+ // string hex = BitConverter.ToString(bytes);
byte[] addressSeedBytesBigEndian = Utils.ToBigEndianBytes(addressSeed, 32);
// Normalize Google issuer
if (iss == "accounts.google.com")
- {
- iss = "https://accounts.google.com";
- }
+ iss = "https://accounts.google.com"; //TODO: See / ask about implementation for OAuth providers
byte[] addressParamBytes = Encoding.UTF8.GetBytes(iss);
byte[] tmp = new byte[2 + addressSeedBytesBigEndian.Length + addressParamBytes.Length];
-
// Set signature scheme flag
tmp[0] = SignatureSchemeToFlag.ZkLogin;
diff --git a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Bcs.cs b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Bcs.cs
index 167f2dc..acfc3ad 100644
--- a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Bcs.cs
+++ b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Bcs.cs
@@ -4,6 +4,11 @@
namespace Sui.ZKLogin
{
+ ///
+ /// TODO: Complete implementation
+ /// TODO: See if we can just make the ZKLogin Signature class `ISerializable` to that we can just call `serialize` on it.
+ /// TODO: See why this signature looks like this" inputs, maxEpochs, userSignature
+ ///
[JsonObject]
public class ZkLoginSignatureBCS: ISerializable
{
diff --git a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/JwtDecoder.cs b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/JwtDecoder.cs
index b4b8e14..6bbe26b 100644
--- a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/JwtDecoder.cs
+++ b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/JwtDecoder.cs
@@ -1,8 +1,3 @@
-using UnityEngine;
-using System;
-using System.Text;
-using System.Collections.Generic;
-
namespace OpenDive.Utils.Jwt
{
using System;
@@ -10,6 +5,10 @@ namespace OpenDive.Utils.Jwt
using UnityEngine;
using Newtonsoft.Json;
+ ///
+ /// A class to decode JWT tokens.
+ /// TODO: Add unit tests
+ ///
public class JWTDecoder
{
///
diff --git a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/JwtUtils.cs b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/JwtUtils.cs
index cae7f59..189f4d9 100644
--- a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/JwtUtils.cs
+++ b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/JwtUtils.cs
@@ -5,13 +5,6 @@
namespace Sui.ZKLogin
{
-
- //public record Claim
- //{
- // public string Value { get; init; }
- // public int IndexMod4 { get; init; }
- //}
-
///
/// Represents a claim with a base64URL encoded value and its position indicator
///
@@ -29,6 +22,9 @@ public class Claim
public int indexMod4;
}
+ ///
+ /// TODO: Add tests for JWT Utils
+ ///
public class JwtUtils
{
///
@@ -59,11 +55,6 @@ private static int[] Base64UrlCharTo6Bits(string base64UrlChar)
return bits;
}
- //private static int[] Base64UrlStringToBitVector(string base64UrlString)
- //{
- // return base64UrlString.SelectMany(c => Base64UrlCharTo6Bits(c)).ToArray();
- //}
-
///
/// Converts a base64URL encoded string to a bit vector
///
diff --git a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/PublicKey.cs b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/PublicKey.cs
index ad98ce7..d4e13c6 100644
--- a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/PublicKey.cs
+++ b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/PublicKey.cs
@@ -1,14 +1,16 @@
-
namespace Sui.ZKLogin.SDK
{
using System;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
- using UnityEngine;
using Sui.Cryptography;
using Sui.Cryptography.Ed25519;
+ ///
+ /// TODO: Implement ZKLoginPublicKey.
+ /// TODO: See how this is used and whether it can just be extended from the core PublicKey cass
+ ///
public class ZkLoginPublicKey : PublicKey
{
public ZkLoginPublicKey(byte[] public_key) : base(public_key)
diff --git a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/SDK/Address.cs b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/SDK/Address.cs
index 21af72a..9e7f098 100644
--- a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/SDK/Address.cs
+++ b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/SDK/Address.cs
@@ -6,6 +6,11 @@
namespace Sui.ZKLogin.SDK
{
+ ///
+ /// A utility class used to compute A Sui address from the:
+ /// UserSalt, and JWT token values (ClaimName, ClaimValue, Aud, ISS).
+ /// TODO: See how this is implemented / used in ZK Login TS. Can the SDK and outer accout `address` class be reconciled?
+ ///
public static class Address
{
public const int MAX_HEADER_LEN_B64 = 248;
@@ -47,11 +52,9 @@ public static string JwtToAddress(string jwt, string userSalt)
{
LengthChecks(jwt);
- //var payload = JwtDecoder.DecodeJwt(jwt);
JWT decodedJWT = JWTDecoder.DecodeJWT(jwt);
JWTPayload payload = decodedJWT.Payload;
-
if (string.IsNullOrEmpty(payload.Sub) || string.IsNullOrEmpty(payload.Iss) || string.IsNullOrEmpty(payload.Aud))
throw new ArgumentException("Missing jwt data");
@@ -70,13 +73,20 @@ public static string JwtToAddress(string jwt, string userSalt)
});
}
-
public static string ComputeZkLoginAddress(ZkLoginAddressOptions options)
{
var seed = GenAddressSeed(options.UserSalt, options.ClaimName, options.ClaimValue, options.Aud);
return ComputeZkLoginAddressFromSeed(seed, options.Iss);
}
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
private static BigInteger GenAddressSeed(string userSalt, string claimName, string claimValue, string aud)
{
using var sha256 = SHA256.Create();
@@ -114,11 +124,4 @@ public class ZkLoginAddressOptions
public string Iss { get; set; }
public string Aud { get; set; }
}
-
- public class JwtPayload
- {
- public string Sub { get; set; }
- public string Iss { get; set; }
- public string Aud { get; set; }
- }
}
\ No newline at end of file
diff --git a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/SDK/Nonce.cs b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/SDK/Nonce.cs
index 3abb639..5d82d7e 100644
--- a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/SDK/Nonce.cs
+++ b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/SDK/Nonce.cs
@@ -5,6 +5,10 @@
namespace Sui.ZKLogin.SDK
{
+ ///
+ /// TODO: See if there are any issues with using RNGCryptoServiceProvider on mobile or WebGL
+ /// TODO: See how TS implements this. Perhaps we can use a difference source of randomness.
+ ///
public static class NonceGenerator
{
public const int NONCE_LENGTH = 27;
@@ -22,7 +26,7 @@ private static BigInteger ToBigIntBE(byte[] bytes)
public static string GenerateRandomness()
{
byte[] randomBytes = new byte[16];
- // IRVIN: See the impact of using this. TypeScript uses `noble/hashes`
+ // TODO: See the impact of using this. TypeScript uses `noble/hashes`
using (var rng = new RNGCryptoServiceProvider())
{
rng.GetBytes(randomBytes);
@@ -57,9 +61,7 @@ public static string GenerateNonce(PublicKey publicKey, int maxEpoch, BigInteger
string nonce = Base64UrlEncode(Z);
if (nonce.Length != NONCE_LENGTH)
- {
throw new Exception($"Length of nonce {nonce} ({nonce.Length}) is not equal to {NONCE_LENGTH}");
- }
return nonce;
}
@@ -71,9 +73,7 @@ private static byte[] ToPaddedBigEndianBytes(BigInteger value, int length)
Array.Reverse(bytes); // Convert to big-endian
if (bytes.Length > length)
- {
throw new ArgumentException($"Value too large for {length} bytes");
- }
byte[] paddedBytes = new byte[length];
Array.Copy(bytes, 0, paddedBytes, length - bytes.Length, bytes.Length);
diff --git a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/SDK/Poseidon.cs b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/SDK/Poseidon.cs
index 5c5acd0..1756fbd 100644
--- a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/SDK/Poseidon.cs
+++ b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/SDK/Poseidon.cs
@@ -27,7 +27,6 @@ public static class PoseidonHasher
Poseidon16.Hash,
};
-
///
/// Runs Poseidon Hash.
/// The inputs can either be a int, long, or string array.
diff --git a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Signature.cs b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Signature.cs
index c87ee5c..a7b0660 100644
--- a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Signature.cs
+++ b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Signature.cs
@@ -2,7 +2,6 @@
using System.Numerics;
using Unity.Plastic.Newtonsoft.Json;
using OpenDive.BCS;
-using Org.BouncyCastle.Asn1.Ocsp;
using Sui.Cryptography;
namespace Sui.ZKLogin
@@ -33,6 +32,10 @@ namespace Sui.ZKLogin
// }
//}
+ ///
+ /// TODO: Implement ZkLogin Signature.
+ /// TODO: See if it can be extended from the core Signature class.
+ ///
[JsonObject]
public class ZkLoginSignature : ISerializable
{
@@ -44,7 +47,6 @@ public class ZkLoginSignature : ISerializable
//{
// this.SigInputs = inputs;
// this.MaxEpoch = MaxEpoch;
-
//}
[JsonProperty("inputs")]
diff --git a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Utils.cs b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Utils.cs
index a467b74..1084145 100644
--- a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Utils.cs
+++ b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Utils.cs
@@ -1,12 +1,13 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
+using System;
using System.Linq;
using System.Numerics;
-using UnityEngine;
namespace Sui.ZKLogin
{
+ ///
+ /// Utility functions used within ZK Login implementation.
+ /// TODO: See if we have implemented this in the core Utils class. Does it make sense to move it there? (I think so).
+ ///
public static class Utils
{