diff --git a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Bcs.cs b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Bcs.cs index 96e7716..f135b43 100644 --- a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Bcs.cs +++ b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Bcs.cs @@ -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) @@ -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); + // } + //} } diff --git a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Signature.cs b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Signature.cs new file mode 100644 index 0000000..a8b2fdb --- /dev/null +++ b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Signature.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Signature.cs.meta b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Signature.cs.meta new file mode 100644 index 0000000..2d63f8e --- /dev/null +++ b/Assets/Sui-Unity-SDK/Code/Sui.ZKLogin/Signature.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 21defd90e4a33403d8607f823c08ae2b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: