Skip to content

Commit

Permalink
Add Zk Login Signature and dummy BCS class. #119
Browse files Browse the repository at this point in the history
  • Loading branch information
kPatch committed Nov 15, 2024
1 parent 7703f28 commit 7ed9207
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 38 deletions.
95 changes: 57 additions & 38 deletions Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Bcs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@
namespace Sui.ZKLogin
{
[JsonObject]
public class ZkLoginSignature: ISerializable
public class ZkLoginSignatureBCS: ISerializable
{
[JsonProperty("inputs")]
public Inputs Inputs { get; set; }

[JsonProperty("maxEpoch")]
public BigInteger MaxEpoch { get; set; }
public ulong MaxEpoch { get; set; }

[JsonProperty("userSignature")]
public BigInteger UserSignature { get; set; }
public byte[] UserSignature { get; set; } // bcs.vector(bcs.u8()),

public void Serialize(Serialization serializer)
{
throw new System.NotImplementedException();
serializer.Serialize(Inputs);
serializer.SerializeU64(MaxEpoch);
serializer.SerializeBytes(UserSignature);
}

public static ISerializable Deserialize(Deserialization deserializer)
Expand All @@ -27,47 +29,64 @@ public static ISerializable Deserialize(Deserialization deserializer)
}
}

[JsonObject]
public class Inputs
{
[JsonProperty("proofPoints")]
public ProofPoints proofPoints { get; set; }
//[JsonObject]
//public class Inputs: ISerializable
//{
// [JsonProperty("proofPoints")]
// public ProofPoints ProofPoints { get; set; }

[JsonProperty("issBase64Details")]
public ZkLoginSignatureInputsClaim IssBase64Details { get; set; }
// [JsonProperty("issBase64Details")]
// public ZkLoginSignatureInputsClaim IssBase64Details { get; set; }

[JsonProperty("headerBase64")]
public BigInteger HeaderBase64 { get; set; }
// [JsonProperty("headerBase64")]
// public BigInteger HeaderBase64 { get; set; }

[JsonProperty("addressSeed")]
public BigInteger AddressSeed { get; set; }
}
// [JsonProperty("addressSeed")]
// public string AddressSeed { get; set; }

[JsonObject]
public class ProofPoints
{
// Sequence input = new Sequence(new string[] { "a", "abc", "def", "ghi" }.ToList().Select(str => new BString(str)).ToArray());
[JsonProperty("a")]
public Sequence A { get; set; } // a: bcs.vector(bcs.string())
// public void Serialize(Serialization serializer)
// {
// serializer.Serialize(ProofPoints);
// serializer.Serialize(IssBase64Details);
// serializer.Serialize(HeaderBase64);
// serializer.SerializeString(AddressSeed);
// }
//}

[JsonProperty("b")]
public Sequence B { get; set; } // b: bcs.vector(bcs.vector(bcs.string())),
//[JsonObject]
//public class ProofPoints: ISerializable
//{
// // Sequence input = new Sequence(new string[] { "a", "abc", "def", "ghi" }.ToList().Select(str => new BString(str)).ToArray());
// [JsonProperty("a")]
// public Sequence A { get; set; } // a: bcs.vector(bcs.string())

[JsonProperty("c")]
public Sequence C { get; set; } // c: bcs.vector(bcs.string()),
}
// [JsonProperty("b")]
// public Sequence B { get; set; } // b: bcs.vector(bcs.vector(bcs.string())),

[JsonObject]
public class ZkLoginSignatureInputsClaim
{
[JsonProperty("value")]
public BigInteger Value { get; set; }
// [JsonProperty("c")]
// public Sequence C { get; set; } // c: bcs.vector(bcs.string()),

[JsonProperty("indexMod4")]
public BigInteger IndexMod4 { get; set; }
}
// public void Serialize(Serialization serializer)
// {
// serializer.Serialize(A);
// serializer.Serialize(B);
// serializer.Serialize(C);
// }
//}

public static class Bcs
{
}
//[JsonObject]
//public class ZkLoginSignatureInputsClaim: ISerializable
//{
// [JsonProperty("value")]
// public string Value { get; set; }

// [JsonProperty("indexMod4")]
// public byte IndexMod4 { get; set; }

// public void Serialize(Serialization serializer)
// {
// serializer.SerializeString(Value);
// serializer.SerializeU8(IndexMod4);
// }
//}
}
166 changes: 166 additions & 0 deletions Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Signature.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
using System;
using System.Numerics;
using Newtonsoft.Json;
using OpenDive.BCS;
using Org.BouncyCastle.Asn1.Ocsp;
using Sui.Cryptography;

namespace Sui.ZKLogin
{
//public class Signature : Sui.Cryptography.Signature
//{
// public Signature(string signature) : base(signature)
// {
// }

// public Signature(byte[] signature) : base(signature)
// {
// }

// public byte[] GetZkLoginSignatureBytes()
// {
// throw new NotImplementedException();
// }

// public string GetZkLoginSignature()
// {
// throw new NotImplementedException();
// }

// public string ParseZkLoginSignature()
// {
// throw new NotImplementedException();
// }
//}

[JsonObject]
public class ZkLoginSignature : ISerializable
{
//private Inputs SigInputs;
//private ulong MaxEpoch;
//private byte[] UserSignature;

//public ZkLoginSignature(Inputs inputs, ulong MaxEpoch, byte[] UserSignature)
//{
// this.SigInputs = inputs;
// this.MaxEpoch = MaxEpoch;

//}

[JsonProperty("inputs")]
public Inputs Inputs { get; set; }

[JsonProperty("maxEpoch")]
public ulong MaxEpoch { get; set; }

[JsonProperty("userSignature")]
public byte[] UserSignature { get; set; } // bcs.vector(bcs.u8()),

public void Serialize(Serialization serializer)
{
serializer.Serialize(Inputs);
serializer.SerializeU64(MaxEpoch);
serializer.SerializeBytes(UserSignature);
}

public static ISerializable Deserialize(Deserialization deserializer)
{
throw new System.NotImplementedException();
}

public static byte[] GetZkLoginSignatureBytes(Inputs inputs, ulong maxEpoch, byte[] userSignature)
{
ZkLoginSignature sig = new ZkLoginSignature();
sig.Inputs = inputs;
sig.MaxEpoch = maxEpoch;
sig.UserSignature = userSignature;

Serialization ser = new Serialization();
sig.Serialize(ser);
byte[] sigBytes = ser.GetBytes();
return sigBytes;
}

public string GetZkLoginSignature(Inputs inputs, ulong maxEpoch, byte[] userSignature)
{
byte[] bytes = GetZkLoginSignatureBytes(inputs, maxEpoch, userSignature);
byte[] signatureBytes = new byte[bytes.Length + 1];
signatureBytes[0] = SignatureSchemeToFlag.ZkLogin;
Buffer.BlockCopy(bytes, 0, signatureBytes, 1, bytes.Length);
return Convert.ToBase64String(signatureBytes);
}

public string ParseZkLoginSignature(string strSignature)
{
byte[] signatureBytes = Convert.FromBase64String(strSignature);
return ParseZkLoginSignature(signatureBytes);
}

public string ParseZkLoginSignature(byte[] signatureBytes)
{
//return ZkLoginSignature.Parse(signatureBytes);
throw new NotImplementedException();
}
}

[JsonObject]
public class Inputs : ISerializable
{
[JsonProperty("proofPoints")]
public ProofPoints ProofPoints { get; set; }

[JsonProperty("issBase64Details")]
public ZkLoginSignatureInputsClaim IssBase64Details { get; set; }

[JsonProperty("headerBase64")]
public BigInteger HeaderBase64 { get; set; }

[JsonProperty("addressSeed")]
public string AddressSeed { get; set; }

public void Serialize(Serialization serializer)
{
serializer.Serialize(ProofPoints);
serializer.Serialize(IssBase64Details);
serializer.Serialize(HeaderBase64);
serializer.SerializeString(AddressSeed);
}
}

[JsonObject]
public class ProofPoints : ISerializable
{
// Sequence input = new Sequence(new string[] { "a", "abc", "def", "ghi" }.ToList().Select(str => new BString(str)).ToArray());
[JsonProperty("a")]
public Sequence A { get; set; } // a: bcs.vector(bcs.string())

[JsonProperty("b")]
public Sequence B { get; set; } // b: bcs.vector(bcs.vector(bcs.string())),

[JsonProperty("c")]
public Sequence C { get; set; } // c: bcs.vector(bcs.string()),

public void Serialize(Serialization serializer)
{
serializer.Serialize(A);
serializer.Serialize(B);
serializer.Serialize(C);
}
}

[JsonObject]
public class ZkLoginSignatureInputsClaim : ISerializable
{
[JsonProperty("value")]
public string Value { get; set; }

[JsonProperty("indexMod4")]
public byte IndexMod4 { get; set; }

public void Serialize(Serialization serializer)
{
serializer.SerializeString(Value);
serializer.SerializeU8(IndexMod4);
}
}
}
11 changes: 11 additions & 0 deletions Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Signature.cs.meta

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

0 comments on commit 7ed9207

Please sign in to comment.