From 9dfdfbcfea82b2c2a9dd9445aaf45be328222890 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 12 Jul 2023 10:41:35 -0400 Subject: [PATCH 01/49] Fixed some namespaces and moved some of the class definitions into their own files. Expanded ISignature to contain additional methods that were added recently --- Assets/SequenceSDK/Core/Config.cs | 2 +- Assets/SequenceSDK/Core/Digest.cs | 58 ++++++++++++++ Assets/SequenceSDK/Core/Digest.cs.meta | 11 +++ Assets/SequenceSDK/Core/ICore.cs | 45 +---------- Assets/SequenceSDK/Core/IImageHashable.cs | 80 +------------------ Assets/SequenceSDK/Core/ISignature.cs | 10 ++- Assets/SequenceSDK/Core/Provider.cs | 3 +- Assets/SequenceSDK/Core/SignerSignatures.cs | 42 ++++++++++ .../SequenceSDK/Core/SignerSignatures.cs.meta | 11 +++ Assets/SequenceSDK/Core/Subdigest.cs | 31 +++++++ Assets/SequenceSDK/Core/Subdigest.cs.meta | 11 +++ Assets/SequenceSDK/Core/V2/V2.cs | 21 ++++- Assets/SequenceSDK/Core/Wallet/Wallet.cs | 2 +- .../SequenceSDK/Core/Wallet/WalletProvider.cs | 2 +- 14 files changed, 197 insertions(+), 132 deletions(-) create mode 100644 Assets/SequenceSDK/Core/Digest.cs create mode 100644 Assets/SequenceSDK/Core/Digest.cs.meta create mode 100644 Assets/SequenceSDK/Core/SignerSignatures.cs create mode 100644 Assets/SequenceSDK/Core/SignerSignatures.cs.meta create mode 100644 Assets/SequenceSDK/Core/Subdigest.cs create mode 100644 Assets/SequenceSDK/Core/Subdigest.cs.meta diff --git a/Assets/SequenceSDK/Core/Config.cs b/Assets/SequenceSDK/Core/Config.cs index 366f024e..b9180615 100644 --- a/Assets/SequenceSDK/Core/Config.cs +++ b/Assets/SequenceSDK/Core/Config.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using UnityEngine; using Sequence.Wallet; -namespace Sequence +namespace Sequence.Core { public class WalletContext diff --git a/Assets/SequenceSDK/Core/Digest.cs b/Assets/SequenceSDK/Core/Digest.cs new file mode 100644 index 00000000..eae044e9 --- /dev/null +++ b/Assets/SequenceSDK/Core/Digest.cs @@ -0,0 +1,58 @@ +using System; +using System.Linq; +using System.Numerics; +using System.Text; +using Sequence.ABI; + +namespace Sequence.Core { + public class Digest + { + public byte[] Hash { get; set; } + // Preimage is the preimage of the digest + public byte[] Preimage { get; set; } + + public static Digest NewDigest(params string[] messages) + { + byte[] preimage = Encoding.UTF8.GetBytes(string.Join("", messages)); + return new Digest + { + Hash = SequenceCoder.KeccakHash(preimage), + Preimage = preimage + }; + } + + // Subdigest derives the hash to be signed by the Sequence wallet's signers to validate the digest. + public Subdigest Subdigest(string walletAddress, params BigInteger[] chainID) + { + if (chainID.Length == 0 || chainID[0] == null) + { + chainID = new BigInteger[] { BigInteger.Zero }; + } + + if (chainID[0] == null) + { + chainID[0] = BigInteger.Zero; + } + + byte[] chainIDBytes = chainID[0].ToByteArray(); + Array.Reverse(chainIDBytes); + + byte[] data = new byte[] { 0x19, 0x01 } + .Concat(chainIDBytes) + .Concat(Encoding.UTF8.GetBytes(walletAddress)) + .Concat(this.Hash) + .ToArray(); + + + return new Subdigest + { + Hash = SequenceCoder.ByteArrayToHexString(SequenceCoder.KeccakHash(data)), + Digest = this, + WalletAddress = walletAddress, + ChainID = chainID[0] + }; + } + + + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/Core/Digest.cs.meta b/Assets/SequenceSDK/Core/Digest.cs.meta new file mode 100644 index 00000000..f86acb42 --- /dev/null +++ b/Assets/SequenceSDK/Core/Digest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 75f96a14e004d4a11bccc2b063de497b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/ICore.cs b/Assets/SequenceSDK/Core/ICore.cs index 61834bb0..1a5865d8 100644 --- a/Assets/SequenceSDK/Core/ICore.cs +++ b/Assets/SequenceSDK/Core/ICore.cs @@ -4,7 +4,7 @@ using UnityEngine; -namespace Sequence +namespace Sequence.Core { // Sequence core primitives, inherited from go-sequence v2 // @@ -19,47 +19,4 @@ public interface ICore // DecodeWalletConfig takes a decoded JSON object and returns a WalletConfig. public WalletConfig DecodeWalletConfig(object obj); } - - - public class SignerSignatures - { - //From go-sequence : - //type SignerSignatures map[common.Address]map[common.Hash]SignerSignature - //TODO: address type and hash type - public Dictionary> Data { get; set; } - - public SignerSignatures() - { - Data = new Dictionary>(); - } - - public void Insert(string signerAddress, SignerSignature signature) - { - if(!Data.ContainsKey(signerAddress)) - { - Dictionary value = new Dictionary(); - value.Add(signature.Subdigest.Hash, signature); - Data.Add(signerAddress, value); - } - - } - } - - public class SignerSignature - { - public Subdigest Subdigest { get; set; } - public SignerSignatureType Type { get; set; } - public byte[] Signature { get; set; } - - } - - public enum SignerSignatureType - { - SignerSignatureTypeEIP712, - SignerSignatureTypeEthSign, - SignerSignatureTypeEIP1271 - } - - - } diff --git a/Assets/SequenceSDK/Core/IImageHashable.cs b/Assets/SequenceSDK/Core/IImageHashable.cs index 2a3d345e..df70cd6a 100644 --- a/Assets/SequenceSDK/Core/IImageHashable.cs +++ b/Assets/SequenceSDK/Core/IImageHashable.cs @@ -8,7 +8,7 @@ using System; using System.Linq; -namespace Sequence +namespace Sequence.Core { public interface IImageHashable { @@ -34,82 +34,4 @@ public Digest Approval() return Digest.NewDigest(imageHashApprovalSalt, this.Hash);// Assuming Digest is a valid type and has a constructor accepting the approvalSalt and hashBytes as parameters } } - - public class Subdigest - { - public string Hash { get; set; } - // Digest is the preimage of the subdigest - public Digest Digest { get; set; } - // Wallet is the target wallet of the subdigest, *common.Address in go-sequence - public string WalletAddress { get; set; } - // ChainID is the target chain ID of the subdigest - public BigInteger ChainID { get; set; } - // EthSignPreimage is the preimage of the eth_sign subdigest - public Subdigest EthSignPreimage { get; set; } - - // EthSignSubdigest derives the eth_sign subdigest of a subdigest. - public Subdigest EthSignSubdigest() - { - return new Subdigest - { - //TODO : - Hash = SequenceCoder.ByteArrayToHexString(EthWallet.PrefixedMessage(Encoding.UTF8.GetBytes(this.Hash))), - EthSignPreimage = this - - }; - } - } - - public class Digest - { - public byte[] Hash { get; set; } - // Preimage is the preimage of the digest - public byte[] Preimage { get; set; } - - public static Digest NewDigest(params string[] messages) - { - byte[] preimage = Encoding.UTF8.GetBytes(string.Join("", messages)); - return new Digest - { - Hash = SequenceCoder.KeccakHash(preimage), - Preimage = preimage - }; - } - - // Subdigest derives the hash to be signed by the Sequence wallet's signers to validate the digest. - public Subdigest Subdigest(string walletAddress, params BigInteger[] chainID) - { - if (chainID.Length == 0 || chainID[0] == null) - { - chainID = new BigInteger[] { BigInteger.Zero }; - } - - if (chainID[0] == null) - { - chainID[0] = BigInteger.Zero; - } - - byte[] chainIDBytes = chainID[0].ToByteArray(); - Array.Reverse(chainIDBytes); - - byte[] data = new byte[] { 0x19, 0x01 } - .Concat(chainIDBytes) - .Concat(Encoding.UTF8.GetBytes(walletAddress)) - .Concat(this.Hash) - .ToArray(); - - - return new Subdigest - { - Hash = SequenceCoder.ByteArrayToHexString(SequenceCoder.KeccakHash(data)), - Digest = this, - WalletAddress = walletAddress, - ChainID = chainID[0] - }; - } - - - } - - } diff --git a/Assets/SequenceSDK/Core/ISignature.cs b/Assets/SequenceSDK/Core/ISignature.cs index fa21b912..c8f553cd 100644 --- a/Assets/SequenceSDK/Core/ISignature.cs +++ b/Assets/SequenceSDK/Core/ISignature.cs @@ -3,9 +3,9 @@ using System.Numerics; using UnityEngine; using Sequence.Wallet; -using Sequence.Provider; +using Sequence.Core.Provider; -namespace Sequence +namespace Sequence.Core { public interface ISignature { @@ -27,6 +27,12 @@ public interface ISignature RPCProvider provider, List signerSignatures); + // Recover a signature but only using the subdigest + (WalletConfig, BigInteger) RecoverSubdigest(WalletContext context, + Subdigest subdigest, + RPCProvider provider, + List signerSignatures); + // Data is the raw signature data. byte[] Data(); diff --git a/Assets/SequenceSDK/Core/Provider.cs b/Assets/SequenceSDK/Core/Provider.cs index baf7d7a4..366b15e2 100644 --- a/Assets/SequenceSDK/Core/Provider.cs +++ b/Assets/SequenceSDK/Core/Provider.cs @@ -2,9 +2,10 @@ using System.Collections.Generic; using System.Numerics; using System.Threading.Tasks; +using Sequence.Provider; using UnityEngine; -namespace Sequence.Provider +namespace Sequence.Core.Provider { public struct ProviderOption { diff --git a/Assets/SequenceSDK/Core/SignerSignatures.cs b/Assets/SequenceSDK/Core/SignerSignatures.cs new file mode 100644 index 00000000..3f07fcf6 --- /dev/null +++ b/Assets/SequenceSDK/Core/SignerSignatures.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; + +namespace Sequence.Core { + public class SignerSignatures + { + //From go-sequence : + //type SignerSignatures map[common.Address]map[common.Hash]SignerSignature + //TODO: address type and hash type + public Dictionary> Data { get; set; } + + public SignerSignatures() + { + Data = new Dictionary>(); + } + + public void Insert(string signerAddress, SignerSignature signature) + { + if(!Data.ContainsKey(signerAddress)) + { + Dictionary value = new Dictionary(); + value.Add(signature.Subdigest.Hash, signature); + Data.Add(signerAddress, value); + } + + } + } + + public class SignerSignature + { + public Subdigest Subdigest { get; set; } + public SignerSignatureType Type { get; set; } + public byte[] Signature { get; set; } + + } + + public enum SignerSignatureType + { + SignerSignatureTypeEIP712, + SignerSignatureTypeEthSign, + SignerSignatureTypeEIP1271 + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/Core/SignerSignatures.cs.meta b/Assets/SequenceSDK/Core/SignerSignatures.cs.meta new file mode 100644 index 00000000..90b424c9 --- /dev/null +++ b/Assets/SequenceSDK/Core/SignerSignatures.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 25743d247aa184def974ad82d1f4bd90 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/Subdigest.cs b/Assets/SequenceSDK/Core/Subdigest.cs new file mode 100644 index 00000000..80b338fd --- /dev/null +++ b/Assets/SequenceSDK/Core/Subdigest.cs @@ -0,0 +1,31 @@ +using System.Numerics; +using System.Text; +using Sequence.ABI; +using Sequence.Wallet; + +namespace Sequence.Core { + public class Subdigest + { + public string Hash { get; set; } + // Digest is the preimage of the subdigest + public Digest Digest { get; set; } + // Wallet is the target wallet of the subdigest, *common.Address in go-sequence + public string WalletAddress { get; set; } + // ChainID is the target chain ID of the subdigest + public BigInteger ChainID { get; set; } + // EthSignPreimage is the preimage of the eth_sign subdigest + public Subdigest EthSignPreimage { get; set; } + + // EthSignSubdigest derives the eth_sign subdigest of a subdigest. + public Subdigest EthSignSubdigest() + { + return new Subdigest + { + //TODO : + Hash = SequenceCoder.ByteArrayToHexString(EthWallet.PrefixedMessage(Encoding.UTF8.GetBytes(this.Hash))), + EthSignPreimage = this + + }; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/Core/Subdigest.cs.meta b/Assets/SequenceSDK/Core/Subdigest.cs.meta new file mode 100644 index 00000000..d96f043c --- /dev/null +++ b/Assets/SequenceSDK/Core/Subdigest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6d3c38773c8eb40bbb3cf1c07e2d9f1c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/V2.cs b/Assets/SequenceSDK/Core/V2/V2.cs index 15dfd1f4..94923f03 100644 --- a/Assets/SequenceSDK/Core/V2/V2.cs +++ b/Assets/SequenceSDK/Core/V2/V2.cs @@ -1,13 +1,13 @@ -using Sequence.Provider; +using Sequence.Core.Provider; using System; using System.Collections; using System.Collections.Generic; using System.Numerics; using UnityEngine; -using Sequence; +using Sequence.Core; // Sequence v2 core primitives -namespace Sequence.V2 +namespace Sequence.Core.V2 { public class Core : ICore { @@ -398,6 +398,11 @@ public byte[] Data() throw new NotImplementedException(); } + public (WalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + { + throw new NotImplementedException(); + } + public int Threshold() { throw new NotImplementedException(); @@ -421,6 +426,11 @@ public byte[] Data() throw new NotImplementedException(); } + public (WalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + { + throw new NotImplementedException(); + } + public int Threshold() { throw new NotImplementedException(); @@ -444,6 +454,11 @@ public byte[] Data() throw new NotImplementedException(); } + public (WalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + { + throw new NotImplementedException(); + } + public int Threshold() { throw new NotImplementedException(); diff --git a/Assets/SequenceSDK/Core/Wallet/Wallet.cs b/Assets/SequenceSDK/Core/Wallet/Wallet.cs index 63cdde9d..64f1490c 100644 --- a/Assets/SequenceSDK/Core/Wallet/Wallet.cs +++ b/Assets/SequenceSDK/Core/Wallet/Wallet.cs @@ -1,7 +1,7 @@ #define HAS_SPAN #define SECP256K1_LIB -using Sequence.Provider; +using Sequence.Core.Provider; using Sequence.Wallet; using System.Collections.Generic; using System.Numerics; diff --git a/Assets/SequenceSDK/Core/Wallet/WalletProvider.cs b/Assets/SequenceSDK/Core/Wallet/WalletProvider.cs index 4e0917dd..36726abc 100644 --- a/Assets/SequenceSDK/Core/Wallet/WalletProvider.cs +++ b/Assets/SequenceSDK/Core/Wallet/WalletProvider.cs @@ -1,4 +1,4 @@ -using Sequence.Provider; +using Sequence.Core.Provider; using System.Collections; using System.Collections.Generic; using System.Numerics; From 65f0ae7020e68a63715748199ab086dc1e88b503 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 12 Jul 2023 11:37:19 -0400 Subject: [PATCH 02/49] Extracted more classes into their own files. --- Assets/SequenceSDK/Core/ICore.cs | 1 + Assets/SequenceSDK/Core/ISignature.cs | 2 +- Assets/SequenceSDK/Core/V2/V2.cs | 2 +- .../{Config.cs => Wallet/WalletConfig.cs} | 56 +------------------ .../WalletConfig.cs.meta} | 2 +- .../Core/Wallet/WalletConfigSigners.cs | 41 ++++++++++++++ .../Core/Wallet/WalletConfigSigners.cs.meta | 11 ++++ .../SequenceSDK/Core/Wallet/WalletContext.cs | 10 ++++ .../Core/Wallet/WalletContext.cs.meta | 11 ++++ 9 files changed, 78 insertions(+), 58 deletions(-) rename Assets/SequenceSDK/Core/{Config.cs => Wallet/WalletConfig.cs} (57%) rename Assets/SequenceSDK/Core/{Config.cs.meta => Wallet/WalletConfig.cs.meta} (83%) create mode 100644 Assets/SequenceSDK/Core/Wallet/WalletConfigSigners.cs create mode 100644 Assets/SequenceSDK/Core/Wallet/WalletConfigSigners.cs.meta create mode 100644 Assets/SequenceSDK/Core/Wallet/WalletContext.cs create mode 100644 Assets/SequenceSDK/Core/Wallet/WalletContext.cs.meta diff --git a/Assets/SequenceSDK/Core/ICore.cs b/Assets/SequenceSDK/Core/ICore.cs index 1a5865d8..cb5556d3 100644 --- a/Assets/SequenceSDK/Core/ICore.cs +++ b/Assets/SequenceSDK/Core/ICore.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Numerics; using UnityEngine; +using Sequence.Core.Wallet; namespace Sequence.Core diff --git a/Assets/SequenceSDK/Core/ISignature.cs b/Assets/SequenceSDK/Core/ISignature.cs index c8f553cd..d6a4ad10 100644 --- a/Assets/SequenceSDK/Core/ISignature.cs +++ b/Assets/SequenceSDK/Core/ISignature.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Numerics; using UnityEngine; -using Sequence.Wallet; +using Sequence.Core.Wallet; using Sequence.Core.Provider; namespace Sequence.Core diff --git a/Assets/SequenceSDK/Core/V2/V2.cs b/Assets/SequenceSDK/Core/V2/V2.cs index 94923f03..89466898 100644 --- a/Assets/SequenceSDK/Core/V2/V2.cs +++ b/Assets/SequenceSDK/Core/V2/V2.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Numerics; using UnityEngine; -using Sequence.Core; +using Sequence.Core.Wallet; // Sequence v2 core primitives namespace Sequence.Core.V2 diff --git a/Assets/SequenceSDK/Core/Config.cs b/Assets/SequenceSDK/Core/Wallet/WalletConfig.cs similarity index 57% rename from Assets/SequenceSDK/Core/Config.cs rename to Assets/SequenceSDK/Core/Wallet/WalletConfig.cs index b9180615..54f21dbf 100644 --- a/Assets/SequenceSDK/Core/Config.cs +++ b/Assets/SequenceSDK/Core/Wallet/WalletConfig.cs @@ -1,22 +1,6 @@ using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using Sequence.Wallet; -namespace Sequence.Core -{ - - public class WalletContext - { - public string FactoryAddress { get; set; } - public string MainModuleAddress { get; set; } - public string MainModuleUpgradableAddress { get; set; } - public string GuestModuleAddress { get; set; } - - public string UtilsAddress { get; set; } - - } +namespace Sequence.Core.Wallet { public class WalletConfig { public int Threshold { get; set; } @@ -78,42 +62,4 @@ public static bool IsWalletConfigEqual(WalletConfig walletConfigA, WalletConfig } } - - - - public class WalletConfigSigner - { - public byte Weight { get; set; } - public string Address { get; set; } - } - - public class WalletConfigSigners : List - { - public int Len() => Count; - - public bool Less(int i, int j) - { - //TODO: - throw new NotImplementedException(); - } - - public void Swap(int i, int j) - { - WalletConfigSigner temp = this[i]; - this[i] = this[j]; - this[j] = temp; - } - - public (byte, bool) GetWeightByAddress(string address) - { - foreach (WalletConfigSigner signer in this) - { - if (signer.Address == address) - { - return (signer.Weight, true); - } - } - return (0, false); - } - } } \ No newline at end of file diff --git a/Assets/SequenceSDK/Core/Config.cs.meta b/Assets/SequenceSDK/Core/Wallet/WalletConfig.cs.meta similarity index 83% rename from Assets/SequenceSDK/Core/Config.cs.meta rename to Assets/SequenceSDK/Core/Wallet/WalletConfig.cs.meta index 308745cb..286b8830 100644 --- a/Assets/SequenceSDK/Core/Config.cs.meta +++ b/Assets/SequenceSDK/Core/Wallet/WalletConfig.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ebd53cdb4c0d5a24faea21df9616653a +guid: 6a01ec2ee6fd64b529b679d870726b5b MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/SequenceSDK/Core/Wallet/WalletConfigSigners.cs b/Assets/SequenceSDK/Core/Wallet/WalletConfigSigners.cs new file mode 100644 index 00000000..e9ec9c0f --- /dev/null +++ b/Assets/SequenceSDK/Core/Wallet/WalletConfigSigners.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; + +namespace Sequence.Core.Wallet { + + public class WalletConfigSigner + { + public byte Weight { get; set; } + public string Address { get; set; } + } + + public class WalletConfigSigners : List + { + public int Len() => Count; + + public bool Less(int i, int j) + { + //TODO: + throw new NotImplementedException(); + } + + public void Swap(int i, int j) + { + WalletConfigSigner temp = this[i]; + this[i] = this[j]; + this[j] = temp; + } + + public (byte, bool) GetWeightByAddress(string address) + { + foreach (WalletConfigSigner signer in this) + { + if (signer.Address == address) + { + return (signer.Weight, true); + } + } + return (0, false); + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/Core/Wallet/WalletConfigSigners.cs.meta b/Assets/SequenceSDK/Core/Wallet/WalletConfigSigners.cs.meta new file mode 100644 index 00000000..cdcf1696 --- /dev/null +++ b/Assets/SequenceSDK/Core/Wallet/WalletConfigSigners.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4af8ace4c03344502a9c8b7cc019eb08 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/Wallet/WalletContext.cs b/Assets/SequenceSDK/Core/Wallet/WalletContext.cs new file mode 100644 index 00000000..a3cfe07f --- /dev/null +++ b/Assets/SequenceSDK/Core/Wallet/WalletContext.cs @@ -0,0 +1,10 @@ +namespace Sequence.Core.Wallet { + public class WalletContext + { + public string FactoryAddress { get; set; } + public string MainModuleAddress { get; set; } + public string MainModuleUpgradableAddress { get; set; } + public string GuestModuleAddress { get; set; } + public string UtilsAddress { get; set; } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/Core/Wallet/WalletContext.cs.meta b/Assets/SequenceSDK/Core/Wallet/WalletContext.cs.meta new file mode 100644 index 00000000..9f0b70db --- /dev/null +++ b/Assets/SequenceSDK/Core/Wallet/WalletContext.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 96c914cd5a8414c0a9f8469bb1234001 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 8e0faa573a3bc714a972662e7de70ceb72b5ffa1 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 12 Jul 2023 14:29:49 -0400 Subject: [PATCH 03/49] Rename class to match go-sequence --- .../Core/{Wallet/WalletConfig.cs => Config.cs} | 17 +++++++++-------- .../WalletConfig.cs.meta => Config.cs.meta} | 2 +- Assets/SequenceSDK/Core/ICore.cs | 2 +- Assets/SequenceSDK/Core/ISignature.cs | 4 ++-- Assets/SequenceSDK/Core/V2/V2.cs | 16 ++++++++-------- Assets/SequenceSDK/Core/Wallet/Wallet.cs | 7 ++++--- 6 files changed, 25 insertions(+), 23 deletions(-) rename Assets/SequenceSDK/Core/{Wallet/WalletConfig.cs => Config.cs} (67%) rename Assets/SequenceSDK/Core/{Wallet/WalletConfig.cs.meta => Config.cs.meta} (83%) diff --git a/Assets/SequenceSDK/Core/Wallet/WalletConfig.cs b/Assets/SequenceSDK/Core/Config.cs similarity index 67% rename from Assets/SequenceSDK/Core/Wallet/WalletConfig.cs rename to Assets/SequenceSDK/Core/Config.cs index 54f21dbf..84d43fec 100644 --- a/Assets/SequenceSDK/Core/Wallet/WalletConfig.cs +++ b/Assets/SequenceSDK/Core/Config.cs @@ -1,12 +1,13 @@ using System; +using Sequence.Core.Wallet; -namespace Sequence.Core.Wallet { - public class WalletConfig +namespace Sequence.Core { + public class Config { public int Threshold { get; set; } public WalletConfigSigners Signers { get; set; } - public static string AddressFromWalletConfig(WalletConfig walletConfig, WalletContext context) + public static string AddressFromWalletConfig(Config walletConfig, WalletContext context) { ImageHash imageHash = ImageHashOfWalletConfig(walletConfig); @@ -22,19 +23,19 @@ public static string AddressFromImageHash(string imageHash, WalletContext contex } - public static ImageHash ImageHashOfWalletConfig(WalletConfig walletConfig) + public static ImageHash ImageHashOfWalletConfig(Config walletConfig) { throw new NotImplementedException(); } - private static byte[] ImageHashOfWalletConfigBytes(WalletConfig walletConfig) + private static byte[] ImageHashOfWalletConfigBytes(Config walletConfig) { throw new NotImplementedException(); } - public static bool SortWalletConfig(WalletConfig walletConfig) + public static bool SortWalletConfig(Config walletConfig) { WalletConfigSigners signers = walletConfig.Signers; signers.Sort(); // Sort the signers @@ -51,12 +52,12 @@ public static bool SortWalletConfig(WalletConfig walletConfig) return true; } - public static bool IsWalletConfigUsable(WalletConfig walletConfig) + public static bool IsWalletConfigUsable(Config walletConfig) { throw new NotImplementedException(); } - public static bool IsWalletConfigEqual(WalletConfig walletConfigA, WalletConfig walletConfigB) + public static bool IsWalletConfigEqual(Config walletConfigA, Config walletConfigB) { throw new NotImplementedException(); } diff --git a/Assets/SequenceSDK/Core/Wallet/WalletConfig.cs.meta b/Assets/SequenceSDK/Core/Config.cs.meta similarity index 83% rename from Assets/SequenceSDK/Core/Wallet/WalletConfig.cs.meta rename to Assets/SequenceSDK/Core/Config.cs.meta index 286b8830..308745cb 100644 --- a/Assets/SequenceSDK/Core/Wallet/WalletConfig.cs.meta +++ b/Assets/SequenceSDK/Core/Config.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6a01ec2ee6fd64b529b679d870726b5b +guid: ebd53cdb4c0d5a24faea21df9616653a MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/SequenceSDK/Core/ICore.cs b/Assets/SequenceSDK/Core/ICore.cs index cb5556d3..d2775901 100644 --- a/Assets/SequenceSDK/Core/ICore.cs +++ b/Assets/SequenceSDK/Core/ICore.cs @@ -18,6 +18,6 @@ public interface ICore public ISignature DecodeSignature(byte[] data); // DecodeWalletConfig takes a decoded JSON object and returns a WalletConfig. - public WalletConfig DecodeWalletConfig(object obj); + public Config DecodeWalletConfig(object obj); } } diff --git a/Assets/SequenceSDK/Core/ISignature.cs b/Assets/SequenceSDK/Core/ISignature.cs index d6a4ad10..28feb1b6 100644 --- a/Assets/SequenceSDK/Core/ISignature.cs +++ b/Assets/SequenceSDK/Core/ISignature.cs @@ -20,7 +20,7 @@ public interface ISignature // If chainID is not provided, provider must be provided. // If provider is not provided, EIP-1271 signatures are assumed to be valid. // If signerSignatures is provided, it will be populated with the valid signer signatures of this signature. - (WalletConfig, BigInteger) Recover(WalletContext context, + (Config, BigInteger) Recover(WalletContext context, Digest digest, string walletAddress, BigInteger chainId, @@ -28,7 +28,7 @@ public interface ISignature List signerSignatures); // Recover a signature but only using the subdigest - (WalletConfig, BigInteger) RecoverSubdigest(WalletContext context, + (Config, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures); diff --git a/Assets/SequenceSDK/Core/V2/V2.cs b/Assets/SequenceSDK/Core/V2/V2.cs index 89466898..00c16d40 100644 --- a/Assets/SequenceSDK/Core/V2/V2.cs +++ b/Assets/SequenceSDK/Core/V2/V2.cs @@ -162,7 +162,7 @@ private ISignatureTree DecodeSignatureTree(byte[] data) //Wallet Config - public WalletConfig DecodeWalletConfig(object obj) + public Config DecodeWalletConfig(object obj) { if (!(obj is Dictionary objectMap)) { @@ -186,7 +186,7 @@ public WalletConfig DecodeWalletConfig(object obj) IWalletConfigTree tree = DecodeWalletConfigTree(treeDict); - return new WalletConfig + return new Config { }; @@ -393,12 +393,12 @@ public byte[] Data() throw new NotImplementedException(); } - public (WalletConfig, BigInteger) Recover(WalletContext context, Digest digest, string walletAddress, BigInteger chainId, RPCProvider provider, List signerSignatures) + public (Config, BigInteger) Recover(WalletContext context, Digest digest, string walletAddress, BigInteger chainId, RPCProvider provider, List signerSignatures) { throw new NotImplementedException(); } - public (WalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + public (Config, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) { throw new NotImplementedException(); } @@ -421,12 +421,12 @@ public byte[] Data() throw new NotImplementedException(); } - public (WalletConfig, BigInteger) Recover(WalletContext context, Digest digest, string walletAddress, BigInteger chainId, RPCProvider provider, List signerSignatures) + public (Config, BigInteger) Recover(WalletContext context, Digest digest, string walletAddress, BigInteger chainId, RPCProvider provider, List signerSignatures) { throw new NotImplementedException(); } - public (WalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + public (Config, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) { throw new NotImplementedException(); } @@ -449,12 +449,12 @@ public byte[] Data() throw new NotImplementedException(); } - public (WalletConfig, BigInteger) Recover(WalletContext context, Digest digest, string walletAddress, BigInteger chainId, RPCProvider provider, List signerSignatures) + public (Config, BigInteger) Recover(WalletContext context, Digest digest, string walletAddress, BigInteger chainId, RPCProvider provider, List signerSignatures) { throw new NotImplementedException(); } - public (WalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + public (Config, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) { throw new NotImplementedException(); } diff --git a/Assets/SequenceSDK/Core/Wallet/Wallet.cs b/Assets/SequenceSDK/Core/Wallet/Wallet.cs index 64f1490c..5d5d330a 100644 --- a/Assets/SequenceSDK/Core/Wallet/Wallet.cs +++ b/Assets/SequenceSDK/Core/Wallet/Wallet.cs @@ -5,6 +5,7 @@ using Sequence.Wallet; using System.Collections.Generic; using System.Numerics; +using Sequence.Core; namespace Sequence.Core.Wallet { @@ -32,7 +33,7 @@ public class WalletOptions { // Config is the wallet multi-sig configuration. Note: the first config of any wallet // before it is deployed is used to derive it's the account address of the wallet. - public WalletConfig Config { get; set; } + public Config Config { get; set; } // Context is the WalletContext of deployed wallet-contract modules for the Smart Wallet. // NOTE: if a WalletContext is not provided, then `SequenceContext()` value is used. public WalletContext Context { get; set; } = Wallet.sequenceContextV2; @@ -49,7 +50,7 @@ public class Wallet public WalletContext context { get; set; } - public WalletConfig config { get; set; } + public Config config { get; set; } public List signers { get; set; } //EOA signers public RPCProvider provider { get; set; } //eth provider @@ -64,7 +65,7 @@ public class Wallet // Without Relayer - public Wallet(WalletContext context, WalletConfig config, List signers, RPCProvider provider, string address, bool skipSortSigners, BigInteger chainID) + public Wallet(WalletContext context, Config config, List signers, RPCProvider provider, string address, bool skipSortSigners, BigInteger chainID) { this.context = context; this.config = config; From 949859af221c5f5efe9da0a67c5eecae2c1b9031 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 12 Jul 2023 15:22:04 -0400 Subject: [PATCH 04/49] Added missing interface methods and a missing interface --- Assets/SequenceSDK/Core/ISignature.cs | 7 ++++- .../SequenceSDK/Core/Wallet/IWalletConfig.cs | 26 +++++++++++++++++++ .../Core/Wallet/IWalletConfig.cs.meta | 11 ++++++++ Assets/SequenceSDK/Core/Wallet/Wallet.cs | 2 +- 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 Assets/SequenceSDK/Core/Wallet/IWalletConfig.cs create mode 100644 Assets/SequenceSDK/Core/Wallet/IWalletConfig.cs.meta diff --git a/Assets/SequenceSDK/Core/ISignature.cs b/Assets/SequenceSDK/Core/ISignature.cs index 28feb1b6..e1dd2c0c 100644 --- a/Assets/SequenceSDK/Core/ISignature.cs +++ b/Assets/SequenceSDK/Core/ISignature.cs @@ -33,8 +33,13 @@ public interface ISignature RPCProvider provider, List signerSignatures); + // Reduce returns an equivalent optimized signature. + ISignature Reduce(Subdigest subdigest); + + // Join joins two signatures into one. + ISignature Join(Subdigest subdigest, ISignature otherSignature); + // Data is the raw signature data. byte[] Data(); - } } \ No newline at end of file diff --git a/Assets/SequenceSDK/Core/Wallet/IWalletConfig.cs b/Assets/SequenceSDK/Core/Wallet/IWalletConfig.cs new file mode 100644 index 00000000..35597249 --- /dev/null +++ b/Assets/SequenceSDK/Core/Wallet/IWalletConfig.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using Sequence.Core; + +namespace Sequence.Core.Wallet { + public interface IWalletConfig + { + // ImageHash is the digest of the object. + ImageHash ImageHash(); + + // Threshold is the minimum signing weight required for a signature to be valid. + UInt16 Threshold(); + + // Checkpoint is the nonce of the wallet configuration. + UInt32 Checkpoint(); + + // Signers is the set of signers in the wallet configuration. + Dictionary Signers(); + + // SignersWeight is the total weight of the signers passed to the function according to the wallet configuration. + UInt16 SignersWeight(string[] signers); + + // IsUsable checks if it's possible to construct signatures that meet threshold. + bool IsUsable(); + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/Core/Wallet/IWalletConfig.cs.meta b/Assets/SequenceSDK/Core/Wallet/IWalletConfig.cs.meta new file mode 100644 index 00000000..9f5ca88d --- /dev/null +++ b/Assets/SequenceSDK/Core/Wallet/IWalletConfig.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 477de92971e2942738d1f37287504938 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/Wallet/Wallet.cs b/Assets/SequenceSDK/Core/Wallet/Wallet.cs index 5d5d330a..a5efbf3f 100644 --- a/Assets/SequenceSDK/Core/Wallet/Wallet.cs +++ b/Assets/SequenceSDK/Core/Wallet/Wallet.cs @@ -51,7 +51,7 @@ public class Wallet public WalletContext context { get; set; } public Config config { get; set; } - public List signers { get; set; } //EOA signers + public List signers { get; set; } // signers public RPCProvider provider { get; set; } //eth provider public WalletProvider walletProvider { get; set; } From 58138fde799b6c85908be22707798ad60ea59edd Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 12 Jul 2023 15:46:41 -0400 Subject: [PATCH 05/49] Made an Address datatype to make code more readable. Note that a string and an Address can be implicitly converted between one and another. This means that an instance of the Address class is not necessarily a valid Ethereum address. --- Assets/SequenceSDK/Ethereum/ABI/ABI.cs | 5 ++++- .../Ethereum/ABI/Coders/AddressCoder.cs | 11 +++++++++- .../SequenceSDK/Ethereum/ABI/SequenceCoder.cs | 5 +++-- Assets/SequenceSDK/Ethereum/Address.meta | 8 ++++++++ .../SequenceSDK/Ethereum/Address/Address.cs | 20 +++++++++++++++++++ .../Ethereum/Address/Address.cs.meta | 11 ++++++++++ .../SequenceSDK/Ethereum/Contract/Contract.cs | 12 +++++------ .../SequenceSDK/Ethereum/Tests/ERC20Tests.cs | 8 ++++---- .../SequenceSDK/Ethereum/Tests/ERC721Tests.cs | 20 +++++++++---------- .../Ethereum/Tests/OwnableTests.cs | 6 +++--- .../Ethereum/Tests/SequenceEthClientTests.cs | 4 ++-- .../Ethereum/Transaction/GasLimitEstimator.cs | 4 ++-- .../SequenceSDK/Ethereum/Wallet/EthWallet.cs | 4 ++-- Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs | 2 +- 14 files changed, 86 insertions(+), 34 deletions(-) create mode 100644 Assets/SequenceSDK/Ethereum/Address.meta create mode 100644 Assets/SequenceSDK/Ethereum/Address/Address.cs create mode 100644 Assets/SequenceSDK/Ethereum/Address/Address.cs.meta diff --git a/Assets/SequenceSDK/Ethereum/ABI/ABI.cs b/Assets/SequenceSDK/Ethereum/ABI/ABI.cs index 44dbc18a..0fa1c575 100644 --- a/Assets/SequenceSDK/Ethereum/ABI/ABI.cs +++ b/Assets/SequenceSDK/Ethereum/ABI/ABI.cs @@ -222,9 +222,12 @@ public static ABIType GetParameterType(object param) { return ABIType.NUMBER; } + else if (param.GetType() == typeof(Address)) + { + return ABIType.ADDRESS; + } else if (param.GetType() == typeof(string)) { - //TODO: make address a custom type if (((string)param).IsAddress()) { return ABIType.ADDRESS; diff --git a/Assets/SequenceSDK/Ethereum/ABI/Coders/AddressCoder.cs b/Assets/SequenceSDK/Ethereum/ABI/Coders/AddressCoder.cs index 8d31c136..be333533 100644 --- a/Assets/SequenceSDK/Ethereum/ABI/Coders/AddressCoder.cs +++ b/Assets/SequenceSDK/Ethereum/ABI/Coders/AddressCoder.cs @@ -60,7 +60,16 @@ public string EncodeToString(object value) { try { - string address = (string)value; + string address; + // We can't explicitly cast an Address to a string, but we can implicitly cast it + if (value.GetType() == typeof(Address)) + { + address = (Address)value; + }else + { + address = (string)value; + } + if (address.StartsWith("0x")) { address = address.Remove(0, 2); diff --git a/Assets/SequenceSDK/Ethereum/ABI/SequenceCoder.cs b/Assets/SequenceSDK/Ethereum/ABI/SequenceCoder.cs index e5c3c499..6fb6a3a2 100644 --- a/Assets/SequenceSDK/Ethereum/ABI/SequenceCoder.cs +++ b/Assets/SequenceSDK/Ethereum/ABI/SequenceCoder.cs @@ -4,6 +4,7 @@ using Org.BouncyCastle.Crypto.Digests; using Sequence.Extensions; using UnityEngine; +using Sequence; namespace Sequence.ABI { @@ -60,8 +61,8 @@ public static string AddressChecksum(string address) } catch (Exception ex) { - Debug.LogError($"Error computing checksum address: {ex.Message}"); - return string.Empty; + Debug.LogError($"Error computing checksum address({address}): {ex.Message}"); + return address; } } diff --git a/Assets/SequenceSDK/Ethereum/Address.meta b/Assets/SequenceSDK/Ethereum/Address.meta new file mode 100644 index 00000000..a0782f51 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Address.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5fc5a42cee792458297f7e2cf2bead18 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Ethereum/Address/Address.cs b/Assets/SequenceSDK/Ethereum/Address/Address.cs new file mode 100644 index 00000000..a1f66a33 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Address/Address.cs @@ -0,0 +1,20 @@ +using Sequence.ABI; + +namespace Sequence { + public class Address { + public readonly string Value; + + public Address(string value) { + Value = value; + } + + public static implicit operator Address(string value) { + return new Address(value); + } + + public static implicit operator string(Address address) + { + return address.Value; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/Ethereum/Address/Address.cs.meta b/Assets/SequenceSDK/Ethereum/Address/Address.cs.meta new file mode 100644 index 00000000..7782fc21 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Address/Address.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4cc63f83611544e478d60ff9d6143e24 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Ethereum/Contract/Contract.cs b/Assets/SequenceSDK/Ethereum/Contract/Contract.cs index dc09b7ca..58e7685a 100644 --- a/Assets/SequenceSDK/Ethereum/Contract/Contract.cs +++ b/Assets/SequenceSDK/Ethereum/Contract/Contract.cs @@ -32,7 +32,7 @@ public CallContractFunctionTransactionCreator CallFunction(string functionSignat string callData = ABI.ABI.Pack(functionSignature, functionArgs); return async (IEthClient client, ContractCall contractCallInfo) => { - GasLimitEstimator estimator = new GasLimitEstimator(client, contractCallInfo.fromAddress); + GasLimitEstimator estimator = new GasLimitEstimator(client, contractCallInfo.from); var transactionCreator = estimator.BuildTransactionCreator(this.address, callData, contractCallInfo.value, contractCallInfo.gasPrice); EthTransaction transaction = await transactionCreator(); @@ -65,12 +65,12 @@ public async Task GetEventLog(string eventName, BigInteger blockNumber) public class ContractCall { - public string fromAddress; + public Address from; public BigInteger value; public BigInteger gasPrice; public BigInteger gasLimit; - public ContractCall(string fromAddress, BigInteger? value = null, BigInteger? gasPrice = null, BigInteger? gasLimit = null) + public ContractCall(Address from, BigInteger? value = null, BigInteger? gasPrice = null, BigInteger? gasLimit = null) { if (value == null) { @@ -85,9 +85,9 @@ public ContractCall(string fromAddress, BigInteger? value = null, BigInteger? ga gasLimit = BigInteger.Zero; } - if (!fromAddress.IsAddress()) + if (!from.Value.IsAddress()) { - throw new ArgumentOutOfRangeException(nameof(fromAddress)); + throw new ArgumentOutOfRangeException(nameof(from)); } if (value < 0) { @@ -102,7 +102,7 @@ public ContractCall(string fromAddress, BigInteger? value = null, BigInteger? ga throw new ArgumentOutOfRangeException(nameof(gasLimit)); } - this.fromAddress = fromAddress; + this.from = from; this.value = (BigInteger)value; this.gasPrice = (BigInteger)gasPrice; this.gasLimit = (BigInteger)gasLimit; diff --git a/Assets/SequenceSDK/Ethereum/Tests/ERC20Tests.cs b/Assets/SequenceSDK/Ethereum/Tests/ERC20Tests.cs index ae67e1c2..4b4ef9a6 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/ERC20Tests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/ERC20Tests.cs @@ -65,7 +65,7 @@ public async Task TestERC20Queries() Assert.AreEqual((BigInteger)18, decimals); string owner = await token.Owner(client); - Assert.AreEqual(wallet1.GetAddress(), SequenceCoder.AddressChecksum(owner)); + Assert.AreEqual(wallet1.GetAddress().Value, SequenceCoder.AddressChecksum(owner)); } catch (Exception ex) { @@ -329,17 +329,17 @@ public async Task TestOwner() try { string owner = await token.Owner(client); - Assert.AreEqual(wallet1.GetAddress(), SequenceCoder.AddressChecksum(owner)); + Assert.AreEqual(wallet1.GetAddress().Value, SequenceCoder.AddressChecksum(owner)); TransactionReceipt receipt = await token.TransferOwnership(wallet2.GetAddress()) .SendTransactionMethodAndWaitForReceipt(wallet1, client); owner = await token.Owner(client); - Assert.AreEqual(wallet2.GetAddress(), SequenceCoder.AddressChecksum(owner)); + Assert.AreEqual(wallet2.GetAddress().Value, SequenceCoder.AddressChecksum(owner)); receipt = await token.TransferOwnership(wallet1.GetAddress()) .SendTransactionMethodAndWaitForReceipt(wallet2, client); owner = await token.Owner(client); - Assert.AreEqual(wallet1.GetAddress(), SequenceCoder.AddressChecksum(owner)); + Assert.AreEqual(wallet1.GetAddress().Value, SequenceCoder.AddressChecksum(owner)); } catch (Exception ex) { diff --git a/Assets/SequenceSDK/Ethereum/Tests/ERC721Tests.cs b/Assets/SequenceSDK/Ethereum/Tests/ERC721Tests.cs index 8df137ae..b8a251dd 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/ERC721Tests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/ERC721Tests.cs @@ -62,7 +62,7 @@ public async Task TestERC721BasicQueries() Assert.AreEqual(BigInteger.Zero, balance); string owner = await token.Owner(client); - Assert.AreEqual(wallet1.GetAddress(), SequenceCoder.AddressChecksum(owner)); + Assert.AreEqual(wallet1.GetAddress().Value, SequenceCoder.AddressChecksum(owner)); } catch (Exception ex) { @@ -92,7 +92,7 @@ public async Task TestERC721Mint() BigInteger balance = await token.BalanceOf(client, wallet1.GetAddress()); Assert.AreEqual((BigInteger)1, balance); string owner = await token.OwnerOf(client, tokenId1); - Assert.AreEqual(wallet1.GetAddress(), SequenceCoder.AddressChecksum(owner)); + Assert.AreEqual(wallet1.GetAddress().Value, SequenceCoder.AddressChecksum(owner)); string tokenUri = await token.TokenURI(client, tokenId1); Assert.AreEqual(baseUri + tokenId1, tokenUri); @@ -102,7 +102,7 @@ public async Task TestERC721Mint() balance = await autoIncrementingToken.BalanceOf(client, wallet1.GetAddress()); Assert.AreEqual((BigInteger)1, balance); owner = await autoIncrementingToken.OwnerOf(client, tokenId1); - Assert.AreEqual(wallet1.GetAddress(), SequenceCoder.AddressChecksum(owner)); + Assert.AreEqual(wallet1.GetAddress().Value, SequenceCoder.AddressChecksum(owner)); tokenUri = await autoIncrementingToken.TokenURI(client, tokenId1); Assert.AreEqual(baseUri + tokenId1, tokenUri); @@ -122,7 +122,7 @@ private async Task TestBurn(ERC721 token) BigInteger balance = await token.BalanceOf(client, wallet1.GetAddress()); Assert.AreEqual((BigInteger)1, balance); string owner = await token.OwnerOf(client, tokenId1); - Assert.AreEqual(wallet1.GetAddress(), SequenceCoder.AddressChecksum(owner)); + Assert.AreEqual(wallet1.GetAddress().Value, SequenceCoder.AddressChecksum(owner)); string tokenUri = await token.TokenURI(client, tokenId1); Assert.AreEqual(baseUri + tokenId1, tokenUri); } @@ -176,7 +176,7 @@ public async Task TestTransfer() balance = await token.BalanceOf(client, wallet2.GetAddress()); Assert.AreEqual(BigInteger.Zero, balance); string owner = await token.OwnerOf(client, tokenId1); - Assert.AreEqual(wallet1.GetAddress(), SequenceCoder.AddressChecksum(owner)); + Assert.AreEqual(wallet1.GetAddress().Value, SequenceCoder.AddressChecksum(owner)); // Transfer token receipt = await token.TransferFrom(wallet1.GetAddress(), wallet2.GetAddress(), tokenId1) @@ -186,7 +186,7 @@ public async Task TestTransfer() balance = await token.BalanceOf(client, wallet2.GetAddress()); Assert.AreEqual(BigInteger.One, balance); owner = await token.OwnerOf(client, tokenId1); - Assert.AreEqual(wallet2.GetAddress(), SequenceCoder.AddressChecksum(owner)); + Assert.AreEqual(wallet2.GetAddress().Value, SequenceCoder.AddressChecksum(owner)); } catch (Exception ex) { @@ -210,7 +210,7 @@ public async Task TestTransfer() TransactionReceipt receipt = await token.Approve(wallet1.GetAddress(), tokenId1) .SendTransactionMethodAndWaitForReceipt(wallet2, client); string approved = await token.GetApproved(client, tokenId1); - Assert.AreEqual(wallet1.GetAddress(), SequenceCoder.AddressChecksum(approved)); + Assert.AreEqual(wallet1.GetAddress().Value, SequenceCoder.AddressChecksum(approved)); // Transfer token receipt = await token.SafeTransferFrom(wallet2.GetAddress(), wallet1.GetAddress(), tokenId1, "something random".ToByteArray()) @@ -220,7 +220,7 @@ public async Task TestTransfer() balance = await token.BalanceOf(client, wallet2.GetAddress()); Assert.AreEqual(BigInteger.Zero, balance); string owner = await token.OwnerOf(client, tokenId1); - Assert.AreEqual(wallet1.GetAddress(), SequenceCoder.AddressChecksum(owner)); + Assert.AreEqual(wallet1.GetAddress().Value, SequenceCoder.AddressChecksum(owner)); await TestBurn(token); } @@ -246,13 +246,13 @@ public async Task TestApproval() BigInteger balance = await token.BalanceOf(client, wallet1.GetAddress()); Assert.AreEqual((BigInteger)3, balance); string owner = await token.OwnerOf(client, tokenId1); - Assert.AreEqual(wallet1.GetAddress(), SequenceCoder.AddressChecksum(owner)); + Assert.AreEqual(wallet1.GetAddress().Value, SequenceCoder.AddressChecksum(owner)); // Give approval for one token receipt = await token.Approve(wallet2.GetAddress(), tokenId1) .SendTransactionMethodAndWaitForReceipt(wallet1, client); string approved = await token.GetApproved(client, tokenId1); - Assert.AreEqual(wallet2.GetAddress(), SequenceCoder.AddressChecksum(approved)); + Assert.AreEqual(wallet2.GetAddress().Value, SequenceCoder.AddressChecksum(approved)); bool isApprovedForAll = await token.IsApprovedForAll(client, wallet1.GetAddress(), wallet2.GetAddress()); Assert.IsFalse(isApprovedForAll); diff --git a/Assets/SequenceSDK/Ethereum/Tests/OwnableTests.cs b/Assets/SequenceSDK/Ethereum/Tests/OwnableTests.cs index 1d1e0139..c33642aa 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/OwnableTests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/OwnableTests.cs @@ -46,17 +46,17 @@ public async Task TestOwner() try { string owner = await ownable.Owner(client); - Assert.AreEqual(wallet1.GetAddress(), SequenceCoder.AddressChecksum(owner)); + Assert.AreEqual(wallet1.GetAddress().Value, SequenceCoder.AddressChecksum(owner)); TransactionReceipt receipt = await ownable.TransferOwnership(wallet2.GetAddress()) .SendTransactionMethodAndWaitForReceipt(wallet1, client); owner = await ownable.Owner(client); - Assert.AreEqual(wallet2.GetAddress(), SequenceCoder.AddressChecksum(owner)); + Assert.AreEqual(wallet2.GetAddress().Value, SequenceCoder.AddressChecksum(owner)); receipt = await ownable.TransferOwnership(wallet1.GetAddress()) .SendTransactionMethodAndWaitForReceipt(wallet2, client); owner = await ownable.Owner(client); - Assert.AreEqual(wallet1.GetAddress(), SequenceCoder.AddressChecksum(owner)); + Assert.AreEqual(wallet1.GetAddress().Value, SequenceCoder.AddressChecksum(owner)); receipt = await ownable.RenounceOwnership() .SendTransactionMethodAndWaitForReceipt(wallet1, client); diff --git a/Assets/SequenceSDK/Ethereum/Tests/SequenceEthClientTests.cs b/Assets/SequenceSDK/Ethereum/Tests/SequenceEthClientTests.cs index 262c71a6..27f1d72a 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/SequenceEthClientTests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/SequenceEthClientTests.cs @@ -350,13 +350,13 @@ public async Task TestTransactionByHash() { Assert.AreEqual(nonce, transaction.nonce.HexStringToBigInteger()); Assert.AreEqual(gasPrice, transaction.gasPrice.HexStringToBigInteger()); Assert.AreEqual(gasLimit, transaction.gas.HexStringToBigInteger()); - Assert.AreEqual(wallet2.GetAddress(), SequenceCoder.AddressChecksum(transaction.to)); + Assert.AreEqual(wallet2.GetAddress().Value, SequenceCoder.AddressChecksum(transaction.to)); Assert.AreEqual(value, transaction.value.HexStringToBigInteger()); Assert.AreEqual(data.EnsureHexPrefix(), transaction.input); Assert.AreEqual(v, transaction.v); Assert.AreEqual(r, transaction.r); Assert.AreEqual(s, transaction.s); - Assert.AreEqual(wallet1.GetAddress(), SequenceCoder.AddressChecksum(transaction.from)); + Assert.AreEqual(wallet1.GetAddress().Value, SequenceCoder.AddressChecksum(transaction.from)); await client.WaitForTransactionReceipt(result); // Not waiting for the transaction to process will cause the next tests to fail as they would be submitting a duplicate transaction } diff --git a/Assets/SequenceSDK/Ethereum/Transaction/GasLimitEstimator.cs b/Assets/SequenceSDK/Ethereum/Transaction/GasLimitEstimator.cs index a9b7418b..b15487f4 100644 --- a/Assets/SequenceSDK/Ethereum/Transaction/GasLimitEstimator.cs +++ b/Assets/SequenceSDK/Ethereum/Transaction/GasLimitEstimator.cs @@ -8,11 +8,11 @@ namespace Sequence.Transactions { public class GasLimitEstimator { IEthClient client; - string wallet; + Address wallet; public delegate Task TransactionCreator(); - public GasLimitEstimator(IEthClient client, string wallet) { + public GasLimitEstimator(IEthClient client, Address wallet) { this.client = client; this.wallet = wallet; } diff --git a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs index 334dcf29..b309a126 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs @@ -19,7 +19,7 @@ public class EthWallet : IWallet { public ECPrivKey privKey; public ECPubKey pubKey; - private string address; + private Address address; /// /// Initializes a new instance of the class with a randomly generated private key. @@ -56,7 +56,7 @@ private string GenerateAddress() return PubkeyToAddress(publicKeyBytes64); } - public string GetAddress() + public Address GetAddress() { if (address == null) { diff --git a/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs b/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs index df4f9cd7..426e884a 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs @@ -12,7 +12,7 @@ namespace Sequence.Wallet { public interface IWallet { - public string GetAddress(); + public Address GetAddress(); public Task GetBalance(IEthClient client); public Task GetNonce(IEthClient client); public (string v, string r, string s) SignTransaction(byte[] message, string chainId); From b889bdffa53a7eedf3edc013c3e686c916833def Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 12 Jul 2023 16:46:40 -0400 Subject: [PATCH 06/49] No more implicit conversions from string to Address; you must now use the constructor. This allows us to guarantee that an Address is a valid Ethereum address --- .../SequenceSDK/Ethereum/Address/Address.cs | 20 ++++++++++++++----- .../SequenceSDK/Ethereum/Wallet/EthWallet.cs | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Assets/SequenceSDK/Ethereum/Address/Address.cs b/Assets/SequenceSDK/Ethereum/Address/Address.cs index a1f66a33..2381adb8 100644 --- a/Assets/SequenceSDK/Ethereum/Address/Address.cs +++ b/Assets/SequenceSDK/Ethereum/Address/Address.cs @@ -1,20 +1,30 @@ -using Sequence.ABI; +using System; +using Sequence.Extensions; namespace Sequence { public class Address { public readonly string Value; + /// + /// Caution: this constructor will throw an exception if you supply an invalid address string + /// + /// public Address(string value) { + if (!value.IsAddress()) + { + throw new ArgumentOutOfRangeException(nameof(value)); + } Value = value; } - public static implicit operator Address(string value) { - return new Address(value); - } - public static implicit operator string(Address address) { return address.Value; } + + public override string ToString() + { + return Value; + } } } \ No newline at end of file diff --git a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs index b309a126..f0024d4b 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs @@ -60,7 +60,7 @@ public Address GetAddress() { if (address == null) { - address = GenerateAddress(); + address = new Address(GenerateAddress()); } return address; } From bb65a178180be5225677ce5d78d05b1ee34be929 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 12 Jul 2023 17:01:23 -0400 Subject: [PATCH 07/49] Use Address type instead of string in Sequence integration --- Assets/SequenceSDK/Core/ISignature.cs | 2 +- Assets/SequenceSDK/Core/SignerSignatures.cs | 6 ++-- Assets/SequenceSDK/Core/V2/V2.cs | 36 +++++++++++++++++-- .../SequenceSDK/Core/Wallet/IWalletConfig.cs | 4 +-- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Assets/SequenceSDK/Core/ISignature.cs b/Assets/SequenceSDK/Core/ISignature.cs index e1dd2c0c..bee227a0 100644 --- a/Assets/SequenceSDK/Core/ISignature.cs +++ b/Assets/SequenceSDK/Core/ISignature.cs @@ -22,7 +22,7 @@ public interface ISignature // If signerSignatures is provided, it will be populated with the valid signer signatures of this signature. (Config, BigInteger) Recover(WalletContext context, Digest digest, - string walletAddress, + Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures); diff --git a/Assets/SequenceSDK/Core/SignerSignatures.cs b/Assets/SequenceSDK/Core/SignerSignatures.cs index 3f07fcf6..2f3e3c0b 100644 --- a/Assets/SequenceSDK/Core/SignerSignatures.cs +++ b/Assets/SequenceSDK/Core/SignerSignatures.cs @@ -6,14 +6,14 @@ public class SignerSignatures //From go-sequence : //type SignerSignatures map[common.Address]map[common.Hash]SignerSignature //TODO: address type and hash type - public Dictionary> Data { get; set; } + public Dictionary> Data { get; set; } public SignerSignatures() { - Data = new Dictionary>(); + Data = new Dictionary>(); } - public void Insert(string signerAddress, SignerSignature signature) + public void Insert(Address signerAddress, SignerSignature signature) { if(!Data.ContainsKey(signerAddress)) { diff --git a/Assets/SequenceSDK/Core/V2/V2.cs b/Assets/SequenceSDK/Core/V2/V2.cs index 00c16d40..941500fc 100644 --- a/Assets/SequenceSDK/Core/V2/V2.cs +++ b/Assets/SequenceSDK/Core/V2/V2.cs @@ -393,7 +393,12 @@ public byte[] Data() throw new NotImplementedException(); } - public (Config, BigInteger) Recover(WalletContext context, Digest digest, string walletAddress, BigInteger chainId, RPCProvider provider, List signerSignatures) + public ISignature Join(Subdigest subdigest, ISignature otherSignature) + { + throw new NotImplementedException(); + } + + public (Config, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) { throw new NotImplementedException(); } @@ -403,6 +408,11 @@ public byte[] Data() throw new NotImplementedException(); } + public ISignature Reduce(Subdigest subdigest) + { + throw new NotImplementedException(); + } + public int Threshold() { throw new NotImplementedException(); @@ -421,7 +431,12 @@ public byte[] Data() throw new NotImplementedException(); } - public (Config, BigInteger) Recover(WalletContext context, Digest digest, string walletAddress, BigInteger chainId, RPCProvider provider, List signerSignatures) + public ISignature Join(Subdigest subdigest, ISignature otherSignature) + { + throw new NotImplementedException(); + } + + public (Config, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) { throw new NotImplementedException(); } @@ -431,6 +446,11 @@ public byte[] Data() throw new NotImplementedException(); } + public ISignature Reduce(Subdigest subdigest) + { + throw new NotImplementedException(); + } + public int Threshold() { throw new NotImplementedException(); @@ -449,7 +469,12 @@ public byte[] Data() throw new NotImplementedException(); } - public (Config, BigInteger) Recover(WalletContext context, Digest digest, string walletAddress, BigInteger chainId, RPCProvider provider, List signerSignatures) + public ISignature Join(Subdigest subdigest, ISignature otherSignature) + { + throw new NotImplementedException(); + } + + public (Config, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) { throw new NotImplementedException(); } @@ -459,6 +484,11 @@ public byte[] Data() throw new NotImplementedException(); } + public ISignature Reduce(Subdigest subdigest) + { + throw new NotImplementedException(); + } + public int Threshold() { throw new NotImplementedException(); diff --git a/Assets/SequenceSDK/Core/Wallet/IWalletConfig.cs b/Assets/SequenceSDK/Core/Wallet/IWalletConfig.cs index 35597249..6ba019c1 100644 --- a/Assets/SequenceSDK/Core/Wallet/IWalletConfig.cs +++ b/Assets/SequenceSDK/Core/Wallet/IWalletConfig.cs @@ -15,10 +15,10 @@ public interface IWalletConfig UInt32 Checkpoint(); // Signers is the set of signers in the wallet configuration. - Dictionary Signers(); + Dictionary Signers(); // SignersWeight is the total weight of the signers passed to the function according to the wallet configuration. - UInt16 SignersWeight(string[] signers); + UInt16 SignersWeight(Address[] signers); // IsUsable checks if it's possible to construct signatures that meet threshold. bool IsUsable(); From 499db4ced5bf8ba677ec943bae1eb31cde083519 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 12 Jul 2023 17:07:43 -0400 Subject: [PATCH 08/49] Created Sequence.Core.Signature namespace --- Assets/SequenceSDK/Core/Config.cs | 1 + Assets/SequenceSDK/Core/ICore.cs | 2 +- Assets/SequenceSDK/Core/Signature.meta | 8 ++++++++ Assets/SequenceSDK/Core/{ => Signature}/Digest.cs | 3 ++- Assets/SequenceSDK/Core/{ => Signature}/Digest.cs.meta | 0 Assets/SequenceSDK/Core/{ => Signature}/IImageHashable.cs | 2 +- .../Core/{ => Signature}/IImageHashable.cs.meta | 0 Assets/SequenceSDK/Core/{ => Signature}/ISignature.cs | 2 +- .../SequenceSDK/Core/{ => Signature}/ISignature.cs.meta | 0 .../SequenceSDK/Core/{ => Signature}/SignerSignatures.cs | 2 +- .../Core/{ => Signature}/SignerSignatures.cs.meta | 0 Assets/SequenceSDK/Core/{ => Signature}/Subdigest.cs | 3 ++- Assets/SequenceSDK/Core/{ => Signature}/Subdigest.cs.meta | 0 Assets/SequenceSDK/Core/V2/V2.cs | 1 + Assets/SequenceSDK/Core/Wallet/IWalletConfig.cs | 2 +- 15 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 Assets/SequenceSDK/Core/Signature.meta rename Assets/SequenceSDK/Core/{ => Signature}/Digest.cs (97%) rename Assets/SequenceSDK/Core/{ => Signature}/Digest.cs.meta (100%) rename Assets/SequenceSDK/Core/{ => Signature}/IImageHashable.cs (97%) rename Assets/SequenceSDK/Core/{ => Signature}/IImageHashable.cs.meta (100%) rename Assets/SequenceSDK/Core/{ => Signature}/ISignature.cs (98%) rename Assets/SequenceSDK/Core/{ => Signature}/ISignature.cs.meta (100%) rename Assets/SequenceSDK/Core/{ => Signature}/SignerSignatures.cs (97%) rename Assets/SequenceSDK/Core/{ => Signature}/SignerSignatures.cs.meta (100%) rename Assets/SequenceSDK/Core/{ => Signature}/Subdigest.cs (96%) rename Assets/SequenceSDK/Core/{ => Signature}/Subdigest.cs.meta (100%) diff --git a/Assets/SequenceSDK/Core/Config.cs b/Assets/SequenceSDK/Core/Config.cs index 84d43fec..f716dde9 100644 --- a/Assets/SequenceSDK/Core/Config.cs +++ b/Assets/SequenceSDK/Core/Config.cs @@ -1,5 +1,6 @@ using System; using Sequence.Core.Wallet; +using Sequence.Core.Signature; namespace Sequence.Core { public class Config diff --git a/Assets/SequenceSDK/Core/ICore.cs b/Assets/SequenceSDK/Core/ICore.cs index d2775901..702053e9 100644 --- a/Assets/SequenceSDK/Core/ICore.cs +++ b/Assets/SequenceSDK/Core/ICore.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Numerics; using UnityEngine; -using Sequence.Core.Wallet; +using Sequence.Core.Signature; namespace Sequence.Core diff --git a/Assets/SequenceSDK/Core/Signature.meta b/Assets/SequenceSDK/Core/Signature.meta new file mode 100644 index 00000000..b5f661bb --- /dev/null +++ b/Assets/SequenceSDK/Core/Signature.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b1411c01dfa034c2f96db90a28006f8b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/Digest.cs b/Assets/SequenceSDK/Core/Signature/Digest.cs similarity index 97% rename from Assets/SequenceSDK/Core/Digest.cs rename to Assets/SequenceSDK/Core/Signature/Digest.cs index eae044e9..94f84797 100644 --- a/Assets/SequenceSDK/Core/Digest.cs +++ b/Assets/SequenceSDK/Core/Signature/Digest.cs @@ -4,7 +4,8 @@ using System.Text; using Sequence.ABI; -namespace Sequence.Core { +namespace Sequence.Core.Signature +{ public class Digest { public byte[] Hash { get; set; } diff --git a/Assets/SequenceSDK/Core/Digest.cs.meta b/Assets/SequenceSDK/Core/Signature/Digest.cs.meta similarity index 100% rename from Assets/SequenceSDK/Core/Digest.cs.meta rename to Assets/SequenceSDK/Core/Signature/Digest.cs.meta diff --git a/Assets/SequenceSDK/Core/IImageHashable.cs b/Assets/SequenceSDK/Core/Signature/IImageHashable.cs similarity index 97% rename from Assets/SequenceSDK/Core/IImageHashable.cs rename to Assets/SequenceSDK/Core/Signature/IImageHashable.cs index df70cd6a..ac048b12 100644 --- a/Assets/SequenceSDK/Core/IImageHashable.cs +++ b/Assets/SequenceSDK/Core/Signature/IImageHashable.cs @@ -8,7 +8,7 @@ using System; using System.Linq; -namespace Sequence.Core +namespace Sequence.Core.Signature { public interface IImageHashable { diff --git a/Assets/SequenceSDK/Core/IImageHashable.cs.meta b/Assets/SequenceSDK/Core/Signature/IImageHashable.cs.meta similarity index 100% rename from Assets/SequenceSDK/Core/IImageHashable.cs.meta rename to Assets/SequenceSDK/Core/Signature/IImageHashable.cs.meta diff --git a/Assets/SequenceSDK/Core/ISignature.cs b/Assets/SequenceSDK/Core/Signature/ISignature.cs similarity index 98% rename from Assets/SequenceSDK/Core/ISignature.cs rename to Assets/SequenceSDK/Core/Signature/ISignature.cs index bee227a0..0abbe900 100644 --- a/Assets/SequenceSDK/Core/ISignature.cs +++ b/Assets/SequenceSDK/Core/Signature/ISignature.cs @@ -5,7 +5,7 @@ using Sequence.Core.Wallet; using Sequence.Core.Provider; -namespace Sequence.Core +namespace Sequence.Core.Signature { public interface ISignature { diff --git a/Assets/SequenceSDK/Core/ISignature.cs.meta b/Assets/SequenceSDK/Core/Signature/ISignature.cs.meta similarity index 100% rename from Assets/SequenceSDK/Core/ISignature.cs.meta rename to Assets/SequenceSDK/Core/Signature/ISignature.cs.meta diff --git a/Assets/SequenceSDK/Core/SignerSignatures.cs b/Assets/SequenceSDK/Core/Signature/SignerSignatures.cs similarity index 97% rename from Assets/SequenceSDK/Core/SignerSignatures.cs rename to Assets/SequenceSDK/Core/Signature/SignerSignatures.cs index 2f3e3c0b..727baf7b 100644 --- a/Assets/SequenceSDK/Core/SignerSignatures.cs +++ b/Assets/SequenceSDK/Core/Signature/SignerSignatures.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Sequence.Core { +namespace Sequence.Core.Signature { public class SignerSignatures { //From go-sequence : diff --git a/Assets/SequenceSDK/Core/SignerSignatures.cs.meta b/Assets/SequenceSDK/Core/Signature/SignerSignatures.cs.meta similarity index 100% rename from Assets/SequenceSDK/Core/SignerSignatures.cs.meta rename to Assets/SequenceSDK/Core/Signature/SignerSignatures.cs.meta diff --git a/Assets/SequenceSDK/Core/Subdigest.cs b/Assets/SequenceSDK/Core/Signature/Subdigest.cs similarity index 96% rename from Assets/SequenceSDK/Core/Subdigest.cs rename to Assets/SequenceSDK/Core/Signature/Subdigest.cs index 80b338fd..343e6e4d 100644 --- a/Assets/SequenceSDK/Core/Subdigest.cs +++ b/Assets/SequenceSDK/Core/Signature/Subdigest.cs @@ -3,7 +3,8 @@ using Sequence.ABI; using Sequence.Wallet; -namespace Sequence.Core { +namespace Sequence.Core.Signature +{ public class Subdigest { public string Hash { get; set; } diff --git a/Assets/SequenceSDK/Core/Subdigest.cs.meta b/Assets/SequenceSDK/Core/Signature/Subdigest.cs.meta similarity index 100% rename from Assets/SequenceSDK/Core/Subdigest.cs.meta rename to Assets/SequenceSDK/Core/Signature/Subdigest.cs.meta diff --git a/Assets/SequenceSDK/Core/V2/V2.cs b/Assets/SequenceSDK/Core/V2/V2.cs index 941500fc..029df973 100644 --- a/Assets/SequenceSDK/Core/V2/V2.cs +++ b/Assets/SequenceSDK/Core/V2/V2.cs @@ -5,6 +5,7 @@ using System.Numerics; using UnityEngine; using Sequence.Core.Wallet; +using Sequence.Core.Signature; // Sequence v2 core primitives namespace Sequence.Core.V2 diff --git a/Assets/SequenceSDK/Core/Wallet/IWalletConfig.cs b/Assets/SequenceSDK/Core/Wallet/IWalletConfig.cs index 6ba019c1..626e3a78 100644 --- a/Assets/SequenceSDK/Core/Wallet/IWalletConfig.cs +++ b/Assets/SequenceSDK/Core/Wallet/IWalletConfig.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using Sequence.Core; +using Sequence.Core.Signature; namespace Sequence.Core.Wallet { public interface IWalletConfig From 1729bdb4e39f8b1f0b7443c59cfe6994652ddc89 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Thu, 13 Jul 2023 12:10:34 -0400 Subject: [PATCH 09/49] Extract classes and interfaces from V2.cs into their own files, directories, and namespaces as appropriate. --- Assets/SequenceSDK/Core/ICore.cs | 4 +- Assets/SequenceSDK/Core/V2/ISignatureTree.cs | 18 + .../Core/V2/ISignatureTree.cs.meta | 11 + .../SequenceSDK/Core/V2/IWalletConfigTree.cs | 25 + .../Core/V2/IWalletConfigTree.cs.meta | 11 + Assets/SequenceSDK/Core/V2/Signature.meta | 8 + .../Core/V2/Signature/ChainedSignature.cs | 49 ++ .../V2/Signature/ChainedSignature.cs.meta | 11 + .../Core/V2/Signature/NoChainIDSignature.cs | 49 ++ .../V2/Signature/NoChainIDSignature.cs.meta | 11 + .../Core/V2/Signature/RegularSignature.cs | 52 ++ .../V2/Signature/RegularSignature.cs.meta | 11 + .../Core/V2/Signature/SignatureDecoder.cs | 30 + .../V2/Signature/SignatureDecoder.cs.meta | 11 + .../Core/V2/Signature/SignatureTreeDecoder.cs | 124 +++++ .../V2/Signature/SignatureTreeDecoder.cs.meta | 11 + .../SequenceSDK/Core/V2/Signature/Tree.meta | 8 + .../Tree/SignatureTreeAddressLeaf.cs | 20 + .../Tree/SignatureTreeAddressLeaf.cs.meta | 11 + .../Tree/SignatureTreeDynamicSignatureLeaf.cs | 29 + .../SignatureTreeDynamicSignatureLeaf.cs.meta | 11 + .../Tree/SignatureTreeECDSASignatureLeaf.cs | 28 + .../SignatureTreeECDSASignatureLeaf.cs.meta | 11 + .../Signature/Tree/SignatureTreeNestedLeaf.cs | 21 + .../Tree/SignatureTreeNestedLeaf.cs.meta | 11 + .../V2/Signature/Tree/SignatureTreeNode.cs | 20 + .../Signature/Tree/SignatureTreeNode.cs.meta | 11 + .../Signature/Tree/SignatureTreeNodeLeaf.cs | 19 + .../Tree/SignatureTreeNodeLeaf.cs.meta | 11 + .../Tree/SignatureTreeSubdigestLeaf.cs | 19 + .../Tree/SignatureTreeSubdigestLeaf.cs.meta | 11 + Assets/SequenceSDK/Core/V2/V2.cs | 522 +----------------- Assets/SequenceSDK/Core/V2/Wallet.meta | 8 + .../Core/V2/Wallet/ConfigTree.meta | 8 + .../ConfigTree/WalletConfigTreeAddressLeaf.cs | 38 ++ .../WalletConfigTreeAddressLeaf.cs.meta | 11 + .../ConfigTree/WalletConfigTreeNestedLeaf.cs | 39 ++ .../WalletConfigTreeNestedLeaf.cs.meta | 11 + .../Wallet/ConfigTree/WalletConfigTreeNode.cs | 38 ++ .../ConfigTree/WalletConfigTreeNode.cs.meta | 11 + .../ConfigTree/WalletConfigTreeNodeLeaf.cs | 37 ++ .../WalletConfigTreeNodeLeaf.cs.meta | 11 + .../WalletConfigTreeSubdigestLeaf.cs | 37 ++ .../WalletConfigTreeSubdigestLeaf.cs.meta | 11 + .../Core/V2/Wallet/WalletConfig.cs | 57 ++ .../Core/V2/Wallet/WalletConfig.cs.meta | 11 + .../Core/V2/Wallet/WalletConfigTreeDecoder.cs | 92 +++ .../V2/Wallet/WalletConfigTreeDecoder.cs.meta | 11 + 48 files changed, 1127 insertions(+), 503 deletions(-) create mode 100644 Assets/SequenceSDK/Core/V2/ISignatureTree.cs create mode 100644 Assets/SequenceSDK/Core/V2/ISignatureTree.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/IWalletConfigTree.cs create mode 100644 Assets/SequenceSDK/Core/V2/IWalletConfigTree.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Signature.meta create mode 100644 Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs create mode 100644 Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs create mode 100644 Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs create mode 100644 Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Signature/SignatureDecoder.cs create mode 100644 Assets/SequenceSDK/Core/V2/Signature/SignatureDecoder.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Signature/SignatureTreeDecoder.cs create mode 100644 Assets/SequenceSDK/Core/V2/Signature/SignatureTreeDecoder.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Signature/Tree.meta create mode 100644 Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeAddressLeaf.cs create mode 100644 Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeAddressLeaf.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeDynamicSignatureLeaf.cs create mode 100644 Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeDynamicSignatureLeaf.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeECDSASignatureLeaf.cs create mode 100644 Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeECDSASignatureLeaf.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNestedLeaf.cs create mode 100644 Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNestedLeaf.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNode.cs create mode 100644 Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNode.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNodeLeaf.cs create mode 100644 Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNodeLeaf.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeSubdigestLeaf.cs create mode 100644 Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeSubdigestLeaf.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Wallet.meta create mode 100644 Assets/SequenceSDK/Core/V2/Wallet/ConfigTree.meta create mode 100644 Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeAddressLeaf.cs create mode 100644 Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeAddressLeaf.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNestedLeaf.cs create mode 100644 Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNestedLeaf.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNode.cs create mode 100644 Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNode.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNodeLeaf.cs create mode 100644 Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNodeLeaf.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeSubdigestLeaf.cs create mode 100644 Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeSubdigestLeaf.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs create mode 100644 Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Wallet/WalletConfigTreeDecoder.cs create mode 100644 Assets/SequenceSDK/Core/V2/Wallet/WalletConfigTreeDecoder.cs.meta diff --git a/Assets/SequenceSDK/Core/ICore.cs b/Assets/SequenceSDK/Core/ICore.cs index 702053e9..dce145ad 100644 --- a/Assets/SequenceSDK/Core/ICore.cs +++ b/Assets/SequenceSDK/Core/ICore.cs @@ -3,7 +3,7 @@ using System.Numerics; using UnityEngine; using Sequence.Core.Signature; - +using Sequence.Core.Wallet; namespace Sequence.Core { @@ -18,6 +18,6 @@ public interface ICore public ISignature DecodeSignature(byte[] data); // DecodeWalletConfig takes a decoded JSON object and returns a WalletConfig. - public Config DecodeWalletConfig(object obj); + public IWalletConfig DecodeWalletConfig(object obj); } } diff --git a/Assets/SequenceSDK/Core/V2/ISignatureTree.cs b/Assets/SequenceSDK/Core/V2/ISignatureTree.cs new file mode 100644 index 00000000..715898f4 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/ISignatureTree.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using Sequence.Core.Provider; +using Sequence.Core.Signature; +using Sequence.Core.Wallet; + + +namespace Sequence.Core.V2 +{ + public interface ISignatureTree + { + (IWalletConfigTree, BigInteger) Recover(WalletContext context, + Subdigest subdigest, + RPCProvider provider, + List signerSignatures); + } +} diff --git a/Assets/SequenceSDK/Core/V2/ISignatureTree.cs.meta b/Assets/SequenceSDK/Core/V2/ISignatureTree.cs.meta new file mode 100644 index 00000000..be0637f2 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/ISignatureTree.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 53093becf4a0943afae2b76267dcb47e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/IWalletConfigTree.cs b/Assets/SequenceSDK/Core/V2/IWalletConfigTree.cs new file mode 100644 index 00000000..acec401a --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/IWalletConfigTree.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Numerics; +using Sequence.Core.Signature; +using UnityEngine; + +namespace Sequence.Core.V2 +{ + public interface IWalletConfigTree + { + ImageHash ImageHash(); + BigInteger MaxWeight(); + Dictionary ReadSignersIntoMap(); + BigInteger UnverifiedWeight(Dictionary signers); + ISignatureTree BuildSignatureTree(Dictionary signerSignatures); + } + + public struct SignerSignature + { + public string SignerAddress { get; set; } + public SignerSignatureType Type { get; set; } + public byte[] Signature { get; set; } + } +} diff --git a/Assets/SequenceSDK/Core/V2/IWalletConfigTree.cs.meta b/Assets/SequenceSDK/Core/V2/IWalletConfigTree.cs.meta new file mode 100644 index 00000000..22d8e518 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/IWalletConfigTree.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a12badc9e6f4d461494b5917c9cb0d26 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Signature.meta b/Assets/SequenceSDK/Core/V2/Signature.meta new file mode 100644 index 00000000..4801a463 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0d2352dfe94fc463ba3fbb875b05b4ec +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs b/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs new file mode 100644 index 00000000..4ac61dca --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs @@ -0,0 +1,49 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System; +using System.Numerics; +using Sequence.Core.Signature; +using Sequence.Core.Wallet; +using Sequence.Core.Provider; + +namespace Sequence.Core.V2.Signature +{ + public class ChainedSignature : ISignature + { + public BigInteger Checkpoint() + { + throw new NotImplementedException(); + } + + public byte[] Data() + { + throw new NotImplementedException(); + } + + public ISignature Join(Subdigest subdigest, ISignature otherSignature) + { + throw new NotImplementedException(); + } + + public (Config, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) + { + throw new NotImplementedException(); + } + + public (Config, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + { + throw new NotImplementedException(); + } + + public ISignature Reduce(Subdigest subdigest) + { + throw new NotImplementedException(); + } + + public int Threshold() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs.meta b/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs.meta new file mode 100644 index 00000000..2455820f --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 94a8c989ccb414fa78eb6895b06b6e0f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs b/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs new file mode 100644 index 00000000..f7abf721 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs @@ -0,0 +1,49 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System; +using System.Numerics; +using Sequence.Core.Signature; +using Sequence.Core.Wallet; +using Sequence.Core.Provider; + +namespace Sequence.Core.V2.Signature +{ + public class NoChainIDSignature : ISignature + { + public BigInteger Checkpoint() + { + throw new NotImplementedException(); + } + + public byte[] Data() + { + throw new NotImplementedException(); + } + + public ISignature Join(Subdigest subdigest, ISignature otherSignature) + { + throw new NotImplementedException(); + } + + public (Config, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) + { + throw new NotImplementedException(); + } + + public (Config, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + { + throw new NotImplementedException(); + } + + public ISignature Reduce(Subdigest subdigest) + { + throw new NotImplementedException(); + } + + public int Threshold() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs.meta b/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs.meta new file mode 100644 index 00000000..9880a047 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e82c4f370817144cf8cf7d30e677f184 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs b/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs new file mode 100644 index 00000000..6d25f2d0 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs @@ -0,0 +1,52 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System; +using System.Numerics; +using Sequence.Core.Signature; +using Sequence.Core.Wallet; +using Sequence.Core.Provider; + +namespace Sequence.Core.V2.Signature +{ + public class RegularSignature : ISignature + { + public bool IsRegular { get; set; } + public ISignatureTree Tree { get; set; } + + public BigInteger Checkpoint() + { + throw new NotImplementedException(); + } + + public byte[] Data() + { + throw new NotImplementedException(); + } + + public ISignature Join(Subdigest subdigest, ISignature otherSignature) + { + throw new NotImplementedException(); + } + + public (Config, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) + { + throw new NotImplementedException(); + } + + public (Config, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + { + throw new NotImplementedException(); + } + + public ISignature Reduce(Subdigest subdigest) + { + throw new NotImplementedException(); + } + + public int Threshold() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs.meta b/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs.meta new file mode 100644 index 00000000..e6a6b8cc --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7048cc86e8c7d425caec8b8b3a8fe03b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Signature/SignatureDecoder.cs b/Assets/SequenceSDK/Core/V2/Signature/SignatureDecoder.cs new file mode 100644 index 00000000..e69fa0ee --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/SignatureDecoder.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Sequence.Core.V2.Signature +{ + public static class SignatureDecoder + { + public static RegularSignature DecodeRegularSignature(byte[] data) + { + if (data == null || data.Length == 0) + { + throw new ArgumentOutOfRangeException(nameof(data)); + } + + throw new NotImplementedException(); + } + + public static NoChainIDSignature DecodeNoChainIDSignature(byte[] data) + { + throw new NotImplementedException(); + } + + public static ChainedSignature DecodeChainedSignature(byte[] data) + { + throw new NotImplementedException(); + } + } +} diff --git a/Assets/SequenceSDK/Core/V2/Signature/SignatureDecoder.cs.meta b/Assets/SequenceSDK/Core/V2/Signature/SignatureDecoder.cs.meta new file mode 100644 index 00000000..8d016620 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/SignatureDecoder.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 116dccf1de94e469ca01caa147d38c5c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Signature/SignatureTreeDecoder.cs b/Assets/SequenceSDK/Core/V2/Signature/SignatureTreeDecoder.cs new file mode 100644 index 00000000..1b0d7314 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/SignatureTreeDecoder.cs @@ -0,0 +1,124 @@ +using System; +using Sequence.Core.V2.Signature.Tree; + +namespace Sequence.Core.V2.Signature +{ + internal static class SignatureTreeDecoder + { + private enum SignatureLeafType + { + ECDSASignature = 0, + Address = 1, + DynamicSignature = 2, + Node = 3, + Branch = 4, + Subdigest = 5, + Nested = 6 + } + + internal static ISignatureTree DecodeSignatureTree(byte[] data) + { + ISignatureTree tree = null; + + while (data.Length != 0) + { + ISignatureTree leaf = null; + string err = null; + + switch (data[0]) + { + case (byte)SignatureLeafType.ECDSASignature: + (leaf, err) = DecodeSignatureTreeECDSASignatureLeaf(ref data); + if (err != null) + throw new Exception($"unable to decode ecdsa signature leaf: {err}"); + break; + + case (byte)SignatureLeafType.Address: + (leaf, err) = DecodeSignatureTreeAddressLeaf(ref data); + if (err != null) + throw new Exception($"unable to decode address leaf: {err}"); + break; + + case (byte)SignatureLeafType.DynamicSignature: + (leaf, err) = DecodeSignatureTreeDynamicSignatureLeaf(ref data); + if (err != null) + throw new Exception($"unable to decode dynamic signature leaf: {err}"); + break; + + case (byte)SignatureLeafType.Node: + (leaf, err) = DecodeSignatureTreeNodeLeaf(ref data); + if (err != null) + throw new Exception($"unable to decode node leaf: {err}"); + break; + + case (byte)SignatureLeafType.Branch: + (leaf, err) = DecodeSignatureTreeBranchLeaf(ref data); + if (err != null) + throw new Exception($"unable to decode branch leaf: {err}"); + break; + + case (byte)SignatureLeafType.Subdigest: + (leaf, err) = DecodeSignatureTreeSubdigestLeaf(ref data); + if (err != null) + throw new Exception($"unable to decode subdigest leaf: {err}"); + break; + + case (byte)SignatureLeafType.Nested: + (leaf, err) = DecodeSignatureTreeNestedLeaf(ref data); + if (err != null) + throw new Exception($"unable to decode nested leaf: {err}"); + break; + + default: + throw new Exception($"unknown signature leaf type {data[0]}"); + } + + if (tree == null) + { + tree = leaf; + } + else + { + tree = new SignatureTreeNode { left = tree, right = leaf }; + } + } + + return tree; + } + + private static (ISignatureTree leaf, string err) DecodeSignatureTreeNestedLeaf(ref byte[] data) + { + throw new NotImplementedException(); + } + + private static (ISignatureTree leaf, string err) DecodeSignatureTreeSubdigestLeaf(ref byte[] data) + { + throw new NotImplementedException(); + } + + private static (ISignatureTree leaf, string err) DecodeSignatureTreeBranchLeaf(ref byte[] data) + { + throw new NotImplementedException(); + } + + private static (ISignatureTree leaf, string err) DecodeSignatureTreeNodeLeaf(ref byte[] data) + { + throw new NotImplementedException(); + } + + private static (ISignatureTree leaf, string err) DecodeSignatureTreeDynamicSignatureLeaf(ref byte[] data) + { + throw new NotImplementedException(); + } + + private static (ISignatureTree leaf, string err) DecodeSignatureTreeAddressLeaf(ref byte[] data) + { + throw new NotImplementedException(); + } + + private static (ISignatureTree leaf, string err) DecodeSignatureTreeECDSASignatureLeaf(ref byte[] data) + { + throw new NotImplementedException(); + } + } +} diff --git a/Assets/SequenceSDK/Core/V2/Signature/SignatureTreeDecoder.cs.meta b/Assets/SequenceSDK/Core/V2/Signature/SignatureTreeDecoder.cs.meta new file mode 100644 index 00000000..3f0aab90 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/SignatureTreeDecoder.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cf6f1ef34489943a983b36bece91f1da +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree.meta b/Assets/SequenceSDK/Core/V2/Signature/Tree.meta new file mode 100644 index 00000000..a13b3fbe --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c208de457d215455eaaa9c85b5a2e2da +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeAddressLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeAddressLeaf.cs new file mode 100644 index 00000000..0f77bba5 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeAddressLeaf.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using Sequence.Core.Provider; +using Sequence.Core.Signature; +using Sequence.Core.Wallet; + +namespace Sequence.Core.V2.Signature.Tree +{ + public class SignatureTreeAddressLeaf : ISignatureTree + { + public int weight; + public string address; + + public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + { + throw new NotImplementedException(); + } + } +} diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeAddressLeaf.cs.meta b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeAddressLeaf.cs.meta new file mode 100644 index 00000000..8be64474 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeAddressLeaf.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8bf7c8b9930574b3e9de9e8d041b7a4b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeDynamicSignatureLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeDynamicSignatureLeaf.cs new file mode 100644 index 00000000..1e8f50ed --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeDynamicSignatureLeaf.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using Sequence.Core.Provider; +using Sequence.Core.Signature; +using Sequence.Core.Wallet; + +namespace Sequence.Core.V2.Signature.Tree +{ + public class SignatureTreeDynamicSignatureLeaf : ISignatureTree + { + private enum DynamicSignatureType : byte + { + DynamicSignatureTypeEIP712 = 1, + DynamicSignatureTypeEthSign = 2, + DynamicSignatureTypeEIP1271 = 3 + } + + public int weight; + public string address; + private DynamicSignatureType type; + public byte[] signature; + + public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + { + throw new NotImplementedException(); + } + } +} diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeDynamicSignatureLeaf.cs.meta b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeDynamicSignatureLeaf.cs.meta new file mode 100644 index 00000000..85cadd19 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeDynamicSignatureLeaf.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 76211bc1fd5464be09ddb03c2f0987e7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeECDSASignatureLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeECDSASignatureLeaf.cs new file mode 100644 index 00000000..ac3d9d28 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeECDSASignatureLeaf.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using Sequence.Core.Provider; +using Sequence.Core.Signature; +using Sequence.Core.Wallet; + +namespace Sequence.Core.V2.Signature.Tree +{ + public class SignatureTreeECDSASignatureLeaf : ISignatureTree + { + private enum ECDSASignatureType + { + ECDSASignatureTypeEIP712 = 1, + ECDSASignatureTypeEthSign = 2 + } + + public static int SignatureLength = 0; + public int weight; + private ECDSASignatureType type; + public byte[] signature = new byte[SignatureLength]; + + public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + { + throw new NotImplementedException(); + } + } +} diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeECDSASignatureLeaf.cs.meta b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeECDSASignatureLeaf.cs.meta new file mode 100644 index 00000000..a4c41f00 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeECDSASignatureLeaf.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 83a1fdbc3ef6a4deab9594c99c37f1df +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNestedLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNestedLeaf.cs new file mode 100644 index 00000000..077e53a0 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNestedLeaf.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using Sequence.Core.Provider; +using Sequence.Core.Signature; +using Sequence.Core.Wallet; + +namespace Sequence.Core.V2.Signature.Tree +{ + public class SignatureTreeNestedLeaf : ISignatureTree + { + public int weight; + public int threshold; + public ISignatureTree tree; + + public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + { + throw new NotImplementedException(); + } + } +} diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNestedLeaf.cs.meta b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNestedLeaf.cs.meta new file mode 100644 index 00000000..d8d4d1d7 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNestedLeaf.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e661c1feb2a5545b586b38f6e9aba127 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNode.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNode.cs new file mode 100644 index 00000000..73efda0a --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNode.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using Sequence.Core.Provider; +using Sequence.Core.Signature; +using Sequence.Core.Wallet; + +namespace Sequence.Core.V2.Signature.Tree +{ + public class SignatureTreeNode : ISignatureTree + { + public ISignatureTree left; + public ISignatureTree right; + + public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + { + throw new NotImplementedException(); + } + } +} diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNode.cs.meta b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNode.cs.meta new file mode 100644 index 00000000..7a9a1811 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b4efbbcd6c01a44cdac2214f7a658d3a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNodeLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNodeLeaf.cs new file mode 100644 index 00000000..a8713634 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNodeLeaf.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using Sequence.Core.Provider; +using Sequence.Core.Signature; +using Sequence.Core.Wallet; + +namespace Sequence.Core.V2.Signature.Tree +{ + public class SignatureTreeNodeLeaf : ISignatureTree + { + public ImageHash imageHash { get; set; } + + public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + { + throw new NotImplementedException(); + } + } +} diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNodeLeaf.cs.meta b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNodeLeaf.cs.meta new file mode 100644 index 00000000..826d533d --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNodeLeaf.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6b5839882b000426eaf465dd221d473e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeSubdigestLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeSubdigestLeaf.cs new file mode 100644 index 00000000..9320f1cd --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeSubdigestLeaf.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using Sequence.Core.Provider; +using Sequence.Core.Signature; +using Sequence.Core.Wallet; + +namespace Sequence.Core.V2.Signature.Tree +{ + public class SignatureTreeSubdigestLeaf : ISignatureTree + { + public Subdigest subdigest { get; set; } + + public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + { + throw new NotImplementedException(); + } + } +} diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeSubdigestLeaf.cs.meta b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeSubdigestLeaf.cs.meta new file mode 100644 index 00000000..3de0ebfc --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeSubdigestLeaf.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 093945c2fa2644fb98b0a1161567ee37 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/V2.cs b/Assets/SequenceSDK/Core/V2/V2.cs index 029df973..c0be4dc0 100644 --- a/Assets/SequenceSDK/Core/V2/V2.cs +++ b/Assets/SequenceSDK/Core/V2/V2.cs @@ -6,6 +6,8 @@ using UnityEngine; using Sequence.Core.Wallet; using Sequence.Core.Signature; +using Sequence.Core.V2.Signature; +using Sequence.Core.V2.Wallet; // Sequence v2 core primitives namespace Sequence.Core.V2 @@ -15,6 +17,14 @@ public class Core : ICore public static readonly string nestedLeafImageHashPrefix = "Sequence nested config:\n"; public static readonly string subdigestLeafImageHashPrefix = "Sequence static digest:\n"; + public enum SignatureType + { + Legacy = 0, + Regular = 1, + NoChainID = 2, + Chained = 3 + } + //Signatures public ISignature DecodeSignature(byte[] data) { @@ -27,155 +37,33 @@ public ISignature DecodeSignature(byte[] data) { case SignatureType.Legacy: case SignatureType.Regular: - return DecodeRegularSignature(data); + return SignatureDecoder.DecodeRegularSignature(data); case SignatureType.NoChainID: - return DecodeNoChainIDSignature(data); + return SignatureDecoder.DecodeNoChainIDSignature(data); case SignatureType.Chained: - return DecodeChainedSignature(data); + return SignatureDecoder.DecodeChainedSignature(data); default: throw new ArgumentException($"Unknown signature type {data[0]}"); } } - - public static RegularSignature DecodeRegularSignature(byte[] data) - { - throw new NotImplementedException(); - } - - public static NoChainIDSignature DecodeNoChainIDSignature(byte[] data) - { - throw new NotImplementedException(); - } - - public static ChainedSignature DecodeChainedSignature(byte[] data) - { - throw new NotImplementedException(); - } - - private ISignatureTree DecodeSignatureTree(byte[] data) - { - ISignatureTree tree = null; - - while (data.Length != 0) - { - ISignatureTree leaf = null; - string err = null; - - switch (data[0]) - { - case (byte)SignatureLeafType.ECDSASignature: - (leaf, err) = DecodeSignatureTreeECDSASignatureLeaf(ref data); - if (err != null) - throw new Exception($"unable to decode ecdsa signature leaf: {err}"); - break; - - case (byte)SignatureLeafType.Address: - (leaf, err) = DecodeSignatureTreeAddressLeaf(ref data); - if (err != null) - throw new Exception($"unable to decode address leaf: {err}"); - break; - - case (byte)SignatureLeafType.DynamicSignature: - (leaf, err) = DecodeSignatureTreeDynamicSignatureLeaf(ref data); - if (err != null) - throw new Exception($"unable to decode dynamic signature leaf: {err}"); - break; - - case (byte)SignatureLeafType.Node: - (leaf, err) = DecodeSignatureTreeNodeLeaf(ref data); - if (err != null) - throw new Exception($"unable to decode node leaf: {err}"); - break; - - case (byte)SignatureLeafType.Branch: - (leaf, err) = DecodeSignatureTreeBranchLeaf(ref data); - if (err != null) - throw new Exception($"unable to decode branch leaf: {err}"); - break; - - case (byte)SignatureLeafType.Subdigest: - (leaf, err) = DecodeSignatureTreeSubdigestLeaf(ref data); - if (err != null) - throw new Exception($"unable to decode subdigest leaf: {err}"); - break; - - case (byte)SignatureLeafType.Nested: - (leaf, err) = DecodeSignatureTreeNestedLeaf(ref data); - if (err != null) - throw new Exception($"unable to decode nested leaf: {err}"); - break; - - default: - throw new Exception($"unknown signature leaf type {data[0]}"); - } - - if (tree == null) - { - tree = leaf; - } - else - { - tree = new SignatureTreeNode { left = tree, right = leaf }; - } - } - - return tree; - } - - private (ISignatureTree leaf, string err) DecodeSignatureTreeNestedLeaf(ref byte[] data) - { - throw new NotImplementedException(); - } - - private (ISignatureTree leaf, string err) DecodeSignatureTreeSubdigestLeaf(ref byte[] data) - { - throw new NotImplementedException(); - } - - private (ISignatureTree leaf, string err) DecodeSignatureTreeBranchLeaf(ref byte[] data) - { - throw new NotImplementedException(); - } - - private (ISignatureTree leaf, string err) DecodeSignatureTreeNodeLeaf(ref byte[] data) - { - throw new NotImplementedException(); - } - - private (ISignatureTree leaf, string err) DecodeSignatureTreeDynamicSignatureLeaf(ref byte[] data) - { - throw new NotImplementedException(); - } - - private (ISignatureTree leaf, string err) DecodeSignatureTreeAddressLeaf(ref byte[] data) - { - throw new NotImplementedException(); - } - - private (ISignatureTree leaf, string err) DecodeSignatureTreeECDSASignatureLeaf(ref byte[] data) - { - throw new NotImplementedException(); - } - - //Wallet Config - public Config DecodeWalletConfig(object obj) + public IWalletConfig DecodeWalletConfig(object obj) { if (!(obj is Dictionary objectMap)) { throw new ArgumentException("Wallet config must be an object"); } - if (!objectMap.TryGetValue("threshold", out object thresholdObj) || !(thresholdObj is int threshold)) + if (!objectMap.TryGetValue("threshold", out object thresholdObj) || !(thresholdObj is UInt16 threshold)) { throw new ArgumentException("Missing required 'threshold' property"); } - if (!objectMap.TryGetValue("checkpoint", out object checkpointObj) || !(checkpointObj is int checkpoint)) + if (!objectMap.TryGetValue("checkpoint", out object checkpointObj) || !(checkpointObj is UInt32 checkpoint)) { throw new ArgumentException("Missing required 'checkpoint' property"); } @@ -185,382 +73,14 @@ public Config DecodeWalletConfig(object obj) throw new ArgumentException("Missing required 'tree' property"); } - IWalletConfigTree tree = DecodeWalletConfigTree(treeDict); + IWalletConfigTree tree = WalletConfigTreeDecoder.Decode(treeDict); - return new Config + return new WalletConfig { - + threshold = threshold, + checkpoint = checkpoint, + tree = tree, }; } - - public static IWalletConfigTree DecodeWalletConfigTree(object obj) - { - if (obj is not Dictionary objectDict) - { - throw new ArgumentException("Wallet config tree must be an object"); - } - - if (HasKeys(objectDict, new string[] { "left", "right" })) - { - return DecodeWalletConfigTreeNode(objectDict); - } - else if (HasKeys(objectDict, new string[] { "weight", "address" })) - { - return DecodeWalletConfigTreeAddressLeaf(objectDict); - } - else if (HasKeys(objectDict, new string[] { "node" })) - { - return DecodeWalletConfigTreeNodeLeaf(objectDict); - } - else if (HasKeys(objectDict, new string[] { "weight", "threshold", "tree" })) - { - return DecodeWalletConfigTreeNestedLeaf(objectDict); - } - else if (HasKeys(objectDict, new string[] { "subdigest" })) - { - return DecodeWalletConfigTreeSubdigestLeaf(objectDict); - } - else - { - throw new ArgumentException("Unknown wallet config tree type"); - } - } - - private static bool HasKeys(Dictionary objectDict, string[] type) - { - throw new NotImplementedException(); - } - - private static WalletConfigTreeNode DecodeWalletConfigTreeNode(Dictionary obj) - { - var node = new WalletConfigTreeNode(); - node.Left = DecodeWalletConfigTree(obj["left"]); - node.Right = DecodeWalletConfigTree(obj["right"]); - return node; - } - - private static WalletConfigTreeAddressLeaf DecodeWalletConfigTreeAddressLeaf(Dictionary obj) - { - return new WalletConfigTreeAddressLeaf - { - Weight = obj["weight"].ToString(), - Address = obj["address"].ToString() - }; - } - - private static WalletConfigTreeNodeLeaf DecodeWalletConfigTreeNodeLeaf(Dictionary obj) - { - return new WalletConfigTreeNodeLeaf - { - Node = DecodeWalletConfigTree(obj["node"]) - }; - } - - private static WalletConfigTreeNestedLeaf DecodeWalletConfigTreeNestedLeaf(Dictionary obj) - { - return new WalletConfigTreeNestedLeaf - { - Weight = obj["weight"].ToString(), - Threshold = Convert.ToUInt16(obj["threshold"]), - Tree = DecodeWalletConfigTree(obj["tree"]) - }; - - } - private static WalletConfigTreeSubdigestLeaf DecodeWalletConfigTreeSubdigestLeaf(Dictionary obj) - { - return new WalletConfigTreeSubdigestLeaf - { - Subdigest = obj["subdigest"].ToString() - }; - } - - - } - - public enum ECDSASignatureType - { - ECDSASignatureTypeEIP712 = 1, - ECDSASignatureTypeEthSign = 2 - } - public enum DynamicSignatureType : byte - { - DynamicSignatureTypeEIP712 = 1, - DynamicSignatureTypeEthSign = 2, - DynamicSignatureTypeEIP1271 = 3 - } - - public interface ISignatureTree - { - (WalletConfigTree, BigInteger) Recover(WalletContext context, - Subdigest subdigest, - RPCProvider provider, - List signerSignatures); - } - - - - public class SignatureTreeNode : ISignatureTree - { - public ISignatureTree left; - public ISignatureTree right; - - public (WalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) - { - throw new NotImplementedException(); - } - } - - public class SignatureTreeECDSASignatureLeaf : ISignatureTree - { - public static int SignatureLength = 0;//Length - public int weight; - public ECDSASignatureType type; - public byte[] signature = new byte[SignatureLength]; - - public (WalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) - { - throw new NotImplementedException(); - } - } - - public class SignatureTreeAddressLeaf : ISignatureTree - { - public int weight; - public string address; - - public (WalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) - { - throw new NotImplementedException(); - } - } - - public class SignatureTreeDynamicSignatureLeaf : ISignatureTree - { - public int weight; - public string address; - public DynamicSignatureType type; - public byte[] signature; - - public (WalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) - { - throw new NotImplementedException(); - } - } - - public class signatureTreeNodeLeaf : ISignatureTree - { - public ImageHash imageHash { get; set; } - - public (WalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) - { - throw new NotImplementedException(); - } - } - public class SignatureTreeSubdigestLeaf : ISignatureTree - { - public Subdigest subdigest { get; set; } - - public (WalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) - { - throw new NotImplementedException(); - } - } - - public class SignatureTreeNestedLeaf : ISignatureTree - { - public int weight; - public int threshold; - public ISignatureTree tree; - - public (WalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) - { - throw new NotImplementedException(); - } - } - - - public class RegularSignature : ISignature - { - public bool IsRegular { get; set; } - public ISignatureTree Tree { get; set; } - - public BigInteger Checkpoint() - { - throw new NotImplementedException(); - } - - public byte[] Data() - { - throw new NotImplementedException(); - } - - public ISignature Join(Subdigest subdigest, ISignature otherSignature) - { - throw new NotImplementedException(); - } - - public (Config, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) - { - throw new NotImplementedException(); - } - - public (Config, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) - { - throw new NotImplementedException(); - } - - public ISignature Reduce(Subdigest subdigest) - { - throw new NotImplementedException(); - } - - public int Threshold() - { - throw new NotImplementedException(); - } } - - public class NoChainIDSignature : ISignature - { - public BigInteger Checkpoint() - { - throw new NotImplementedException(); - } - - public byte[] Data() - { - throw new NotImplementedException(); - } - - public ISignature Join(Subdigest subdigest, ISignature otherSignature) - { - throw new NotImplementedException(); - } - - public (Config, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) - { - throw new NotImplementedException(); - } - - public (Config, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) - { - throw new NotImplementedException(); - } - - public ISignature Reduce(Subdigest subdigest) - { - throw new NotImplementedException(); - } - - public int Threshold() - { - throw new NotImplementedException(); - } - } - - public class ChainedSignature : ISignature - { - public BigInteger Checkpoint() - { - throw new NotImplementedException(); - } - - public byte[] Data() - { - throw new NotImplementedException(); - } - - public ISignature Join(Subdigest subdigest, ISignature otherSignature) - { - throw new NotImplementedException(); - } - - public (Config, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) - { - throw new NotImplementedException(); - } - - public (Config, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) - { - throw new NotImplementedException(); - } - - public ISignature Reduce(Subdigest subdigest) - { - throw new NotImplementedException(); - } - - public int Threshold() - { - throw new NotImplementedException(); - } - } - public struct SignerSignature - { - public string SignerAddress { get; set; } - public SignerSignatureType Type { get; set; } - public byte[] Signature { get; set; } - } - - public enum SignatureType - { - Legacy = 0, - Regular = 1, - NoChainID = 2, - Chained = 3 - } - public enum SignatureLeafType - { - ECDSASignature = 0, - Address = 1, - DynamicSignature = 2, - Node = 3, - Branch = 4, - Subdigest = 5, - Nested = 6 - } - - //WalletConfig - - public class WalletConfigTree : IWalletConfigTree - { - - } - - - - - - public interface IWalletConfigTree { } - - public class WalletConfigTreeNode : IWalletConfigTree - { - public IWalletConfigTree Left { get; set; } - public IWalletConfigTree Right { get; set; } - } - - public class WalletConfigTreeAddressLeaf : IWalletConfigTree - { - public string Weight { get; set; } - public string Address { get; set; } - } - - public class WalletConfigTreeNodeLeaf : IWalletConfigTree - { - public IWalletConfigTree Node { get; set; } - } - - public class WalletConfigTreeNestedLeaf : IWalletConfigTree - { - public string Weight { get; set; } - public ushort Threshold { get; set; } - public IWalletConfigTree Tree { get; set; } - } - - public class WalletConfigTreeSubdigestLeaf : IWalletConfigTree - { - public string Subdigest { get; set; } - } - - } \ No newline at end of file diff --git a/Assets/SequenceSDK/Core/V2/Wallet.meta b/Assets/SequenceSDK/Core/V2/Wallet.meta new file mode 100644 index 00000000..febf534e --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Wallet.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 05e53ced852e94f309d549a536ebbb8e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree.meta b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree.meta new file mode 100644 index 00000000..174d4b1e --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 30f0560cbd820417ab105af9f4ba204e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeAddressLeaf.cs b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeAddressLeaf.cs new file mode 100644 index 00000000..b7d116de --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeAddressLeaf.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using Sequence.Core.Signature; + +namespace Sequence.Core.V2.Wallet.ConfigTree +{ + public class WalletConfigTreeAddressLeaf : IWalletConfigTree + { + public string Weight { get; set; } + public string Address { get; set; } + + public ISignatureTree BuildSignatureTree(Dictionary signerSignatures) + { + throw new NotImplementedException(); + } + + public ImageHash ImageHash() + { + throw new NotImplementedException(); + } + + public BigInteger MaxWeight() + { + throw new NotImplementedException(); + } + + public Dictionary ReadSignersIntoMap() + { + throw new NotImplementedException(); + } + + public BigInteger UnverifiedWeight(Dictionary signers) + { + throw new NotImplementedException(); + } + } +} diff --git a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeAddressLeaf.cs.meta b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeAddressLeaf.cs.meta new file mode 100644 index 00000000..28de9938 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeAddressLeaf.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6d0bcea822a4e41a5861186e05da1b2b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNestedLeaf.cs b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNestedLeaf.cs new file mode 100644 index 00000000..7b8ba6f1 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNestedLeaf.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using Sequence.Core.Signature; + +namespace Sequence.Core.V2.Wallet.ConfigTree +{ + public class WalletConfigTreeNestedLeaf : IWalletConfigTree + { + public string Weight { get; set; } + public ushort Threshold { get; set; } + public IWalletConfigTree Tree { get; set; } + + public ISignatureTree BuildSignatureTree(Dictionary signerSignatures) + { + throw new NotImplementedException(); + } + + public ImageHash ImageHash() + { + throw new NotImplementedException(); + } + + public BigInteger MaxWeight() + { + throw new NotImplementedException(); + } + + public Dictionary ReadSignersIntoMap() + { + throw new NotImplementedException(); + } + + public BigInteger UnverifiedWeight(Dictionary signers) + { + throw new NotImplementedException(); + } + } +} diff --git a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNestedLeaf.cs.meta b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNestedLeaf.cs.meta new file mode 100644 index 00000000..474e5759 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNestedLeaf.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 934d0cac6218143d7a3a8a6cb3ff02fd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNode.cs b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNode.cs new file mode 100644 index 00000000..a009592c --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNode.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using Sequence.Core.Signature; + +namespace Sequence.Core.V2.Wallet.ConfigTree +{ + public class WalletConfigTreeNode : IWalletConfigTree + { + public IWalletConfigTree Left { get; set; } + public IWalletConfigTree Right { get; set; } + + public ISignatureTree BuildSignatureTree(Dictionary signerSignatures) + { + throw new NotImplementedException(); + } + + public ImageHash ImageHash() + { + throw new NotImplementedException(); + } + + public BigInteger MaxWeight() + { + throw new NotImplementedException(); + } + + public Dictionary ReadSignersIntoMap() + { + throw new NotImplementedException(); + } + + public BigInteger UnverifiedWeight(Dictionary signers) + { + throw new NotImplementedException(); + } + } +} diff --git a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNode.cs.meta b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNode.cs.meta new file mode 100644 index 00000000..a01d508a --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f400a64922599432a94b16eccf1be028 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNodeLeaf.cs b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNodeLeaf.cs new file mode 100644 index 00000000..ed44648a --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNodeLeaf.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using Sequence.Core.Signature; + +namespace Sequence.Core.V2.Wallet.ConfigTree +{ + public class WalletConfigTreeNodeLeaf : IWalletConfigTree + { + public IWalletConfigTree Node { get; set; } + + public ISignatureTree BuildSignatureTree(Dictionary signerSignatures) + { + throw new NotImplementedException(); + } + + public ImageHash ImageHash() + { + throw new NotImplementedException(); + } + + public BigInteger MaxWeight() + { + throw new NotImplementedException(); + } + + public Dictionary ReadSignersIntoMap() + { + throw new NotImplementedException(); + } + + public BigInteger UnverifiedWeight(Dictionary signers) + { + throw new NotImplementedException(); + } + } +} diff --git a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNodeLeaf.cs.meta b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNodeLeaf.cs.meta new file mode 100644 index 00000000..f89c3717 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNodeLeaf.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 023782122d8924588a468c84f55fbfe7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeSubdigestLeaf.cs b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeSubdigestLeaf.cs new file mode 100644 index 00000000..75d7079a --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeSubdigestLeaf.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using Sequence.Core.Signature; + +namespace Sequence.Core.V2.Wallet.ConfigTree +{ + public class WalletConfigTreeSubdigestLeaf : IWalletConfigTree + { + public string Subdigest { get; set; } + + public ISignatureTree BuildSignatureTree(Dictionary signerSignatures) + { + throw new NotImplementedException(); + } + + public ImageHash ImageHash() + { + throw new NotImplementedException(); + } + + public BigInteger MaxWeight() + { + throw new NotImplementedException(); + } + + public Dictionary ReadSignersIntoMap() + { + throw new NotImplementedException(); + } + + public BigInteger UnverifiedWeight(Dictionary signers) + { + throw new NotImplementedException(); + } + } +} diff --git a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeSubdigestLeaf.cs.meta b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeSubdigestLeaf.cs.meta new file mode 100644 index 00000000..228753cb --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeSubdigestLeaf.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9ca3dcd583e444f2398782223669b33f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs b/Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs new file mode 100644 index 00000000..cfd8e8a6 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Numerics; +using Sequence.Core.Signature; +using Sequence.Core.Wallet; +using UnityEngine; + +namespace Sequence.Core.V2.Wallet +{ + [System.Serializable] + public class WalletConfig : IWalletConfig + { + public UInt16 threshold; + public UInt32 checkpoint; + public IWalletConfigTree tree; + + public uint Checkpoint() + { + return checkpoint; + } + + public ImageHash ImageHash() + { + throw new NotImplementedException(); + } + + public bool IsUsable() + { + throw new NotImplementedException(); + } + + public Dictionary Signers() + { + var signers = tree.ReadSignersIntoMap(); + return signers; + } + + public ushort SignersWeight(Address[] signers) + { + Dictionary signersMap = new Dictionary(); + int signersLength = signers.Length; + for (int i = 0; i < signersLength; i++) + { + signersMap[signers[i]] = 0; + } + + BigInteger weight = tree.UnverifiedWeight(signersMap); + return (UInt16)weight; + } + + public ushort Threshold() + { + return threshold; + } + } +} diff --git a/Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs.meta b/Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs.meta new file mode 100644 index 00000000..09fe30de --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9bd38de48489a48c7ba5fe5b9a0c7f54 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Wallet/WalletConfigTreeDecoder.cs b/Assets/SequenceSDK/Core/V2/Wallet/WalletConfigTreeDecoder.cs new file mode 100644 index 00000000..b550fa70 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Wallet/WalletConfigTreeDecoder.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Sequence.Core.V2.Wallet.ConfigTree; + +namespace Sequence.Core.V2.Wallet +{ + public static class WalletConfigTreeDecoder + { + public static IWalletConfigTree Decode(object obj) + { + if (obj is not Dictionary objectDict) + { + throw new ArgumentException("Wallet config tree must be an object"); + } + + if (HasKeys(objectDict, new string[] { "left", "right" })) + { + return DecodeWalletConfigTreeNode(objectDict); + } + else if (HasKeys(objectDict, new string[] { "weight", "address" })) + { + return DecodeWalletConfigTreeAddressLeaf(objectDict); + } + else if (HasKeys(objectDict, new string[] { "node" })) + { + return DecodeWalletConfigTreeNodeLeaf(objectDict); + } + else if (HasKeys(objectDict, new string[] { "weight", "threshold", "tree" })) + { + return DecodeWalletConfigTreeNestedLeaf(objectDict); + } + else if (HasKeys(objectDict, new string[] { "subdigest" })) + { + return DecodeWalletConfigTreeSubdigestLeaf(objectDict); + } + else + { + throw new ArgumentException("Unknown wallet config tree type"); + } + } + + private static bool HasKeys(Dictionary objectDict, string[] type) + { + throw new NotImplementedException(); + } + + private static WalletConfigTreeNode DecodeWalletConfigTreeNode(Dictionary obj) + { + var node = new WalletConfigTreeNode(); + node.Left = Decode(obj["left"]); + node.Right = Decode(obj["right"]); + return node; + } + + private static WalletConfigTreeAddressLeaf DecodeWalletConfigTreeAddressLeaf(Dictionary obj) + { + return new WalletConfigTreeAddressLeaf + { + Weight = obj["weight"].ToString(), + Address = obj["address"].ToString() + }; + } + + private static WalletConfigTreeNodeLeaf DecodeWalletConfigTreeNodeLeaf(Dictionary obj) + { + return new WalletConfigTreeNodeLeaf + { + Node = Decode(obj["node"]) + }; + } + + private static WalletConfigTreeNestedLeaf DecodeWalletConfigTreeNestedLeaf(Dictionary obj) + { + return new WalletConfigTreeNestedLeaf + { + Weight = obj["weight"].ToString(), + Threshold = Convert.ToUInt16(obj["threshold"]), + Tree = Decode(obj["tree"]) + }; + + } + private static WalletConfigTreeSubdigestLeaf DecodeWalletConfigTreeSubdigestLeaf(Dictionary obj) + { + return new WalletConfigTreeSubdigestLeaf + { + Subdigest = obj["subdigest"].ToString() + }; + } + } +} diff --git a/Assets/SequenceSDK/Core/V2/Wallet/WalletConfigTreeDecoder.cs.meta b/Assets/SequenceSDK/Core/V2/Wallet/WalletConfigTreeDecoder.cs.meta new file mode 100644 index 00000000..f4cde5b4 --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Wallet/WalletConfigTreeDecoder.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a29cf355b2a724ae497ee14f7fd5af6b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 47bc86516642d872b8a876f134cc360dba42f39c Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Thu, 13 Jul 2023 14:58:30 -0400 Subject: [PATCH 10/49] Wallet configs as IImageHashables --- Assets/SequenceSDK/Core/Signature/IImageHashable.cs | 3 +-- .../Core/V2/Wallet/ConfigTree/WalletConfigTreeAddressLeaf.cs | 2 +- .../Core/V2/Wallet/ConfigTree/WalletConfigTreeNestedLeaf.cs | 2 +- .../Core/V2/Wallet/ConfigTree/WalletConfigTreeNode.cs | 2 +- .../Core/V2/Wallet/ConfigTree/WalletConfigTreeNodeLeaf.cs | 2 +- .../Core/V2/Wallet/ConfigTree/WalletConfigTreeSubdigestLeaf.cs | 2 +- Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs | 2 +- 7 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Assets/SequenceSDK/Core/Signature/IImageHashable.cs b/Assets/SequenceSDK/Core/Signature/IImageHashable.cs index ac048b12..8f45945b 100644 --- a/Assets/SequenceSDK/Core/Signature/IImageHashable.cs +++ b/Assets/SequenceSDK/Core/Signature/IImageHashable.cs @@ -23,8 +23,7 @@ public class ImageHash // Preimage is the ImageHashable with this ImageHash, // in go-sequence : // Preimage ImageHashable - //TODO: If Preimage is set to type IImageHashable, would it be a cyclic definition? Preimage is set to byte[] for now, will modify it accordingly - public byte[] Preimage { get; set; } + public IImageHashable[] Preimage { get; set; } public static string imageHashApprovalSalt = SequenceCoder.KeccakHash("SetImageHash(bytes32 imageHash)"); diff --git a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeAddressLeaf.cs b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeAddressLeaf.cs index b7d116de..b3d486f3 100644 --- a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeAddressLeaf.cs +++ b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeAddressLeaf.cs @@ -5,7 +5,7 @@ namespace Sequence.Core.V2.Wallet.ConfigTree { - public class WalletConfigTreeAddressLeaf : IWalletConfigTree + public class WalletConfigTreeAddressLeaf : IWalletConfigTree, IImageHashable { public string Weight { get; set; } public string Address { get; set; } diff --git a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNestedLeaf.cs b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNestedLeaf.cs index 7b8ba6f1..294159c0 100644 --- a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNestedLeaf.cs +++ b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNestedLeaf.cs @@ -5,7 +5,7 @@ namespace Sequence.Core.V2.Wallet.ConfigTree { - public class WalletConfigTreeNestedLeaf : IWalletConfigTree + public class WalletConfigTreeNestedLeaf : IWalletConfigTree, IImageHashable { public string Weight { get; set; } public ushort Threshold { get; set; } diff --git a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNode.cs b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNode.cs index a009592c..6271d546 100644 --- a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNode.cs +++ b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNode.cs @@ -5,7 +5,7 @@ namespace Sequence.Core.V2.Wallet.ConfigTree { - public class WalletConfigTreeNode : IWalletConfigTree + public class WalletConfigTreeNode : IWalletConfigTree, IImageHashable { public IWalletConfigTree Left { get; set; } public IWalletConfigTree Right { get; set; } diff --git a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNodeLeaf.cs b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNodeLeaf.cs index ed44648a..c13bec0e 100644 --- a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNodeLeaf.cs +++ b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeNodeLeaf.cs @@ -5,7 +5,7 @@ namespace Sequence.Core.V2.Wallet.ConfigTree { - public class WalletConfigTreeNodeLeaf : IWalletConfigTree + public class WalletConfigTreeNodeLeaf : IWalletConfigTree, IImageHashable { public IWalletConfigTree Node { get; set; } diff --git a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeSubdigestLeaf.cs b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeSubdigestLeaf.cs index 75d7079a..27404664 100644 --- a/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeSubdigestLeaf.cs +++ b/Assets/SequenceSDK/Core/V2/Wallet/ConfigTree/WalletConfigTreeSubdigestLeaf.cs @@ -5,7 +5,7 @@ namespace Sequence.Core.V2.Wallet.ConfigTree { - public class WalletConfigTreeSubdigestLeaf : IWalletConfigTree + public class WalletConfigTreeSubdigestLeaf : IWalletConfigTree, IImageHashable { public string Subdigest { get; set; } diff --git a/Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs b/Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs index cfd8e8a6..ac0cbbd2 100644 --- a/Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs +++ b/Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs @@ -9,7 +9,7 @@ namespace Sequence.Core.V2.Wallet { [System.Serializable] - public class WalletConfig : IWalletConfig + public class WalletConfig : IWalletConfig, IImageHashable { public UInt16 threshold; public UInt32 checkpoint; From 81005f243cf0f113231ca1cfe85efd2fd15ae492 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Thu, 13 Jul 2023 15:57:29 -0400 Subject: [PATCH 11/49] Added Hash datatype - a byte[] with a fixed length of 32. Digest.cs implementation --- Assets/SequenceSDK/Core/Hash.cs | 43 +++++++++++++++++++ Assets/SequenceSDK/Core/Hash.cs.meta | 11 +++++ Assets/SequenceSDK/Core/Signature/Digest.cs | 27 +++++++++--- .../Core/Signature/IImageHashable.cs | 10 ++--- .../Ethereum/Extensions/ByteArrayExtension.cs | 24 +++++++++++ .../Extensions/ByteArrayExtension.cs.meta | 11 +++++ 6 files changed, 115 insertions(+), 11 deletions(-) create mode 100644 Assets/SequenceSDK/Core/Hash.cs create mode 100644 Assets/SequenceSDK/Core/Hash.cs.meta create mode 100644 Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtension.cs create mode 100644 Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtension.cs.meta diff --git a/Assets/SequenceSDK/Core/Hash.cs b/Assets/SequenceSDK/Core/Hash.cs new file mode 100644 index 00000000..97a3dc55 --- /dev/null +++ b/Assets/SequenceSDK/Core/Hash.cs @@ -0,0 +1,43 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Sequence.Extensions; + +namespace Sequence.Core +{ + public class Hash + { + public static readonly int HashLength = 32; + byte[] Value; + + public Hash() + { + Value = new byte[HashLength]; + } + + public Hash(byte[] b) + { + int length = Mathf.Min(HashLength, b.Length); + Value = new byte[HashLength]; + for (int i = 0; i < length; i++) + { + Value[i] = b[i]; + } + } + + public static implicit operator byte[](Hash hash) + { + return hash.Value; + } + + public static implicit operator string(Hash hash) + { + return hash.ToString(); + } + + public override string ToString() + { + return Value.ByteArrayToHexString(); + } + } +} diff --git a/Assets/SequenceSDK/Core/Hash.cs.meta b/Assets/SequenceSDK/Core/Hash.cs.meta new file mode 100644 index 00000000..ea84b626 --- /dev/null +++ b/Assets/SequenceSDK/Core/Hash.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b3d67240d9ba34aa6b4173c0e58c1cb6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/Signature/Digest.cs b/Assets/SequenceSDK/Core/Signature/Digest.cs index 94f84797..84c9a320 100644 --- a/Assets/SequenceSDK/Core/Signature/Digest.cs +++ b/Assets/SequenceSDK/Core/Signature/Digest.cs @@ -1,14 +1,16 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using Sequence.ABI; +using Sequence.Extensions; namespace Sequence.Core.Signature { public class Digest { - public byte[] Hash { get; set; } + public Hash Hash { get; set; } // Preimage is the preimage of the digest public byte[] Preimage { get; set; } @@ -17,11 +19,28 @@ public static Digest NewDigest(params string[] messages) byte[] preimage = Encoding.UTF8.GetBytes(string.Join("", messages)); return new Digest { - Hash = SequenceCoder.KeccakHash(preimage), + Hash = new Hash(SequenceCoder.KeccakHash(preimage)), Preimage = preimage }; } + public (ImageHash, Exception) ApprovedImageHash() + { + byte[] approvalSalt = ImageHash.ApprovalSalt.ToByteArray(); + int approvalSaltLength = approvalSalt.Length; + if (!Preimage.HasPrefix(approvalSalt) || + Preimage.Length != approvalSaltLength + Hash.HashLength) + { + return (null, new Exception($"Preimage {Preimage.ByteArrayToHexString()} of {Hash} is not an image hash approval")); + } + + byte[] hashBytes = Preimage.AsSpan(approvalSaltLength).ToArray(); + return (new ImageHash() + { + Hash = new Hash(hashBytes), + }, null);; + } + // Subdigest derives the hash to be signed by the Sequence wallet's signers to validate the digest. public Subdigest Subdigest(string walletAddress, params BigInteger[] chainID) { @@ -41,7 +60,7 @@ public Subdigest Subdigest(string walletAddress, params BigInteger[] chainID) byte[] data = new byte[] { 0x19, 0x01 } .Concat(chainIDBytes) .Concat(Encoding.UTF8.GetBytes(walletAddress)) - .Concat(this.Hash) + .Concat((IEnumerable)Hash) .ToArray(); @@ -53,7 +72,5 @@ public Subdigest Subdigest(string walletAddress, params BigInteger[] chainID) ChainID = chainID[0] }; } - - } } \ No newline at end of file diff --git a/Assets/SequenceSDK/Core/Signature/IImageHashable.cs b/Assets/SequenceSDK/Core/Signature/IImageHashable.cs index 8f45945b..90c49bbb 100644 --- a/Assets/SequenceSDK/Core/Signature/IImageHashable.cs +++ b/Assets/SequenceSDK/Core/Signature/IImageHashable.cs @@ -19,18 +19,16 @@ public interface IImageHashable // Used for type safety and preimage recovery. public class ImageHash { - public string Hash { get; set; } - // Preimage is the ImageHashable with this ImageHash, - // in go-sequence : - // Preimage ImageHashable + public Hash Hash { get; set; } + // Preimage is the ImageHashable with this ImageHash public IImageHashable[] Preimage { get; set; } - public static string imageHashApprovalSalt = SequenceCoder.KeccakHash("SetImageHash(bytes32 imageHash)"); + public static readonly string ApprovalSalt = SequenceCoder.KeccakHash("SetImageHash(bytes32 imageHash)"); public Digest Approval() { - return Digest.NewDigest(imageHashApprovalSalt, this.Hash);// Assuming Digest is a valid type and has a constructor accepting the approvalSalt and hashBytes as parameters + return Digest.NewDigest(ApprovalSalt, Hash.ToString()); } } } diff --git a/Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtension.cs b/Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtension.cs new file mode 100644 index 00000000..30869b5c --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtension.cs @@ -0,0 +1,24 @@ +using System; +using System.Numerics; +using System.Text; + +namespace Sequence.Extensions +{ + public static class ByteArrayExtensions + { + public static string ByteArrayToHexString(this byte[] byteArray) + { + StringBuilder hexBuilder = new StringBuilder(byteArray.Length * 2); + for (int i = 0; i < byteArray.Length; i++) + { + hexBuilder.Append(byteArray[i].ToString("X2")); + } + string hexString = hexBuilder.ToString(); + return "0x" + hexString; + } + + public static bool HasPrefix(this byte[] b, byte[] prefix) { + return b.AsSpan().StartsWith(prefix); + } + } +} diff --git a/Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtension.cs.meta b/Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtension.cs.meta new file mode 100644 index 00000000..98c7780d --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtension.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3b8061a2862864d298a69951d88d69f5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 8808ba2a32de555368786d0d6b592e385e441009 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Fri, 14 Jul 2023 10:55:11 -0400 Subject: [PATCH 12/49] Subdigest.cs implemented --- Assets/SequenceSDK/Core/Hash.cs | 12 +++---- Assets/SequenceSDK/Core/Signature/Digest.cs | 6 ++-- .../Core/Signature/IImageHashable.cs | 4 ++- .../SequenceSDK/Core/Signature/Subdigest.cs | 25 +++++++++------ .../Ethereum/Extensions/ByteArrayExtension.cs | 31 +++++++++++++----- .../Tests/ByteArrayExtensionsTests.cs | 32 +++++++++++++++++++ .../Tests/ByteArrayExtensionsTests.cs.meta | 11 +++++++ .../Ethereum/Tests/SequenceEthClientTests.cs | 2 +- 8 files changed, 95 insertions(+), 28 deletions(-) create mode 100644 Assets/SequenceSDK/Ethereum/Tests/ByteArrayExtensionsTests.cs create mode 100644 Assets/SequenceSDK/Ethereum/Tests/ByteArrayExtensionsTests.cs.meta diff --git a/Assets/SequenceSDK/Core/Hash.cs b/Assets/SequenceSDK/Core/Hash.cs index 97a3dc55..07471d45 100644 --- a/Assets/SequenceSDK/Core/Hash.cs +++ b/Assets/SequenceSDK/Core/Hash.cs @@ -8,26 +8,26 @@ namespace Sequence.Core public class Hash { public static readonly int HashLength = 32; - byte[] Value; + public byte[] Bytes { get; private set; } public Hash() { - Value = new byte[HashLength]; + Bytes = new byte[HashLength]; } public Hash(byte[] b) { int length = Mathf.Min(HashLength, b.Length); - Value = new byte[HashLength]; + Bytes = new byte[HashLength]; for (int i = 0; i < length; i++) { - Value[i] = b[i]; + Bytes[i] = b[i]; } } public static implicit operator byte[](Hash hash) { - return hash.Value; + return hash.Bytes; } public static implicit operator string(Hash hash) @@ -37,7 +37,7 @@ public static implicit operator string(Hash hash) public override string ToString() { - return Value.ByteArrayToHexString(); + return Bytes.ByteArrayToHexStringWithPrefix(); } } } diff --git a/Assets/SequenceSDK/Core/Signature/Digest.cs b/Assets/SequenceSDK/Core/Signature/Digest.cs index 84c9a320..72f3e1e5 100644 --- a/Assets/SequenceSDK/Core/Signature/Digest.cs +++ b/Assets/SequenceSDK/Core/Signature/Digest.cs @@ -31,7 +31,7 @@ public static Digest NewDigest(params string[] messages) if (!Preimage.HasPrefix(approvalSalt) || Preimage.Length != approvalSaltLength + Hash.HashLength) { - return (null, new Exception($"Preimage {Preimage.ByteArrayToHexString()} of {Hash} is not an image hash approval")); + return (null, new Exception($"Preimage {Preimage.ByteArrayToHexStringWithPrefix()} of {Hash} is not an image hash approval")); } byte[] hashBytes = Preimage.AsSpan(approvalSaltLength).ToArray(); @@ -66,9 +66,9 @@ public Subdigest Subdigest(string walletAddress, params BigInteger[] chainID) return new Subdigest { - Hash = SequenceCoder.ByteArrayToHexString(SequenceCoder.KeccakHash(data)), + Hash = new Hash(SequenceCoder.KeccakHash(data)), Digest = this, - WalletAddress = walletAddress, + WalletAddress = new Address(walletAddress), ChainID = chainID[0] }; } diff --git a/Assets/SequenceSDK/Core/Signature/IImageHashable.cs b/Assets/SequenceSDK/Core/Signature/IImageHashable.cs index 90c49bbb..1c390329 100644 --- a/Assets/SequenceSDK/Core/Signature/IImageHashable.cs +++ b/Assets/SequenceSDK/Core/Signature/IImageHashable.cs @@ -20,11 +20,13 @@ public interface IImageHashable public class ImageHash { public Hash Hash { get; set; } - // Preimage is the ImageHashable with this ImageHash + + // Preimage is the ImageHashable with this ImageHash, null if unknown. public IImageHashable[] Preimage { get; set; } public static readonly string ApprovalSalt = SequenceCoder.KeccakHash("SetImageHash(bytes32 imageHash)"); + // Approval derives the digest that must be signed to approve the ImageHash for subsequent signatures. public Digest Approval() { diff --git a/Assets/SequenceSDK/Core/Signature/Subdigest.cs b/Assets/SequenceSDK/Core/Signature/Subdigest.cs index 343e6e4d..663b792f 100644 --- a/Assets/SequenceSDK/Core/Signature/Subdigest.cs +++ b/Assets/SequenceSDK/Core/Signature/Subdigest.cs @@ -1,31 +1,38 @@ +using System; using System.Numerics; using System.Text; using Sequence.ABI; +using Sequence.Extensions; using Sequence.Wallet; namespace Sequence.Core.Signature { public class Subdigest { - public string Hash { get; set; } - // Digest is the preimage of the subdigest + public Hash Hash { get; set; } + // Digest is the preimage of the subdigest, null if unknown. public Digest Digest { get; set; } - // Wallet is the target wallet of the subdigest, *common.Address in go-sequence - public string WalletAddress { get; set; } - // ChainID is the target chain ID of the subdigest + // Wallet is the target wallet of the subdigest, null if unknown. + public Address WalletAddress { get; set; } + // ChainID is the target chain ID of the subdigest, null if unknown. public BigInteger ChainID { get; set; } - // EthSignPreimage is the preimage of the eth_sign subdigest + // EthSignPreimage is the preimage of the eth_sign subdigest, null if unknown. public Subdigest EthSignPreimage { get; set; } // EthSignSubdigest derives the eth_sign subdigest of a subdigest. public Subdigest EthSignSubdigest() { + byte[] messagePrefix = Encoding.UTF8.GetBytes("\x19Ethereum Signed Message:\n"); + byte[] messageLength = Encoding.UTF8.GetBytes(Hash.Bytes.Length.ToString()); + byte[] message = Hash.Bytes; + + byte[] concatenatedBytes = ByteArrayExtensions.ConcatenateByteArrays(messagePrefix, messageLength, message); + + byte[] keccak256Hash = SequenceCoder.KeccakHash(concatenatedBytes); return new Subdigest { - //TODO : - Hash = SequenceCoder.ByteArrayToHexString(EthWallet.PrefixedMessage(Encoding.UTF8.GetBytes(this.Hash))), + Hash = new Hash(keccak256Hash), EthSignPreimage = this - }; } } diff --git a/Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtension.cs b/Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtension.cs index 30869b5c..a512ed76 100644 --- a/Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtension.cs +++ b/Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtension.cs @@ -1,24 +1,39 @@ using System; using System.Numerics; using System.Text; +using Sequence.ABI; namespace Sequence.Extensions { public static class ByteArrayExtensions { - public static string ByteArrayToHexString(this byte[] byteArray) + public static string ByteArrayToHexStringWithPrefix(this byte[] byteArray) { - StringBuilder hexBuilder = new StringBuilder(byteArray.Length * 2); - for (int i = 0; i < byteArray.Length; i++) - { - hexBuilder.Append(byteArray[i].ToString("X2")); - } - string hexString = hexBuilder.ToString(); - return "0x" + hexString; + return "0x" + SequenceCoder.ByteArrayToHexString(byteArray); } public static bool HasPrefix(this byte[] b, byte[] prefix) { return b.AsSpan().StartsWith(prefix); } + + public static byte[] ConcatenateByteArrays(params byte[][] arrays) + { + int totalLength = 0; + int numberOfArrays = arrays.Length; + for (int i = 0; i < numberOfArrays; i++) + { + totalLength += arrays[i].Length; + } + + int offset = 0; + byte[] result = new byte[totalLength]; + for (int i = 0; i < numberOfArrays; i++) + { + int length = arrays[i].Length; + Buffer.BlockCopy(arrays[i], 0, result, offset, length); + offset += length; + } + return result; + } } } diff --git a/Assets/SequenceSDK/Ethereum/Tests/ByteArrayExtensionsTests.cs b/Assets/SequenceSDK/Ethereum/Tests/ByteArrayExtensionsTests.cs new file mode 100644 index 00000000..308a432d --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/ByteArrayExtensionsTests.cs @@ -0,0 +1,32 @@ +using System.Collections; +using System.Collections.Generic; +using NUnit.Framework; +using UnityEngine; +using Sequence.Extensions; + +public class ByteArrayExtensionsTests +{ + private static readonly string[][] concatenateByteArrayTestCases = new string[][] + { + new string[] {"cow"}, + new string[] {"cow", "horse", "chicken"}, + new string[] {"cow", "turkey", "chicken", "horse", "duck", "pigs,", "and some goats"}, + }; + + [TestCaseSource("concatenateByteArrayTestCases")] + public void TestConcatenateByteArrays(params string[] values) + { + byte[] expected = string.Join("", values).ToByteArray(); + + int elements = values.Length; + byte[][] byteArrays = new byte[elements][]; + for (int i = 0; i < elements; i++) + { + byteArrays[i] = values[i].ToByteArray(); + } + + byte[] concatenated = ByteArrayExtensions.ConcatenateByteArrays(byteArrays); + + Assert.AreEqual(expected, concatenated); + } +} diff --git a/Assets/SequenceSDK/Ethereum/Tests/ByteArrayExtensionsTests.cs.meta b/Assets/SequenceSDK/Ethereum/Tests/ByteArrayExtensionsTests.cs.meta new file mode 100644 index 00000000..690534b0 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/ByteArrayExtensionsTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d5ea34db7fb8f4b1a8971de41748b88a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Ethereum/Tests/SequenceEthClientTests.cs b/Assets/SequenceSDK/Ethereum/Tests/SequenceEthClientTests.cs index 27f1d72a..0d0889e9 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/SequenceEthClientTests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/SequenceEthClientTests.cs @@ -412,7 +412,7 @@ public async Task TestWaitForTransactionReceipt() // Note: for methods with optional parameters, we must still specify a value for each parameter // This is because the tests are created reflexively and would otherwise throw an exception - private static object[] errorCases = { + private static readonly object[] errorCases = { new object[] { nameof(SequenceEthClient.BalanceAt), new object[] { validAddress, "latest" } }, new object[] { nameof(SequenceEthClient.BlockByHash), new object[] { "some hash" } }, new object[] { nameof(SequenceEthClient.BlockByNumber), new object[] { "latest" } }, From f1a5bbb7b506f2be4d9976cbf400f15b16d0e126 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Fri, 14 Jul 2023 11:24:19 -0400 Subject: [PATCH 13/49] Don't use Linq in Digest.cs --- Assets/SequenceSDK/Core/Signature/Digest.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Assets/SequenceSDK/Core/Signature/Digest.cs b/Assets/SequenceSDK/Core/Signature/Digest.cs index 72f3e1e5..651b5b4f 100644 --- a/Assets/SequenceSDK/Core/Signature/Digest.cs +++ b/Assets/SequenceSDK/Core/Signature/Digest.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Numerics; using System.Text; using Sequence.ABI; @@ -42,7 +41,7 @@ public static Digest NewDigest(params string[] messages) } // Subdigest derives the hash to be signed by the Sequence wallet's signers to validate the digest. - public Subdigest Subdigest(string walletAddress, params BigInteger[] chainID) + public Subdigest Subdigest(Address wallet, params BigInteger[] chainID) { if (chainID.Length == 0 || chainID[0] == null) { @@ -57,18 +56,18 @@ public Subdigest Subdigest(string walletAddress, params BigInteger[] chainID) byte[] chainIDBytes = chainID[0].ToByteArray(); Array.Reverse(chainIDBytes); - byte[] data = new byte[] { 0x19, 0x01 } - .Concat(chainIDBytes) - .Concat(Encoding.UTF8.GetBytes(walletAddress)) - .Concat((IEnumerable)Hash) - .ToArray(); + byte[] data = ByteArrayExtensions.ConcatenateByteArrays( + new byte[] { 0x19, 0x01 }, + chainIDBytes, + wallet.Value.ToByteArray(), + Hash); return new Subdigest { Hash = new Hash(SequenceCoder.KeccakHash(data)), Digest = this, - WalletAddress = new Address(walletAddress), + WalletAddress = new Address(wallet), ChainID = chainID[0] }; } From 32a7d92f6860d85a6b3fc202aaf7437d5283aabb Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Fri, 14 Jul 2023 14:51:58 -0400 Subject: [PATCH 14/49] Updated ISignature and SignerSignature implementations --- .../SequenceSDK/Core/Signature/ISignature.cs | 7 ++++--- .../Core/Signature/SignerSignatures.cs | 19 +++++++------------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Assets/SequenceSDK/Core/Signature/ISignature.cs b/Assets/SequenceSDK/Core/Signature/ISignature.cs index 0abbe900..5b5a2637 100644 --- a/Assets/SequenceSDK/Core/Signature/ISignature.cs +++ b/Assets/SequenceSDK/Core/Signature/ISignature.cs @@ -4,13 +4,14 @@ using UnityEngine; using Sequence.Core.Wallet; using Sequence.Core.Provider; +using System; namespace Sequence.Core.Signature { public interface ISignature { // Threshold is the minimum signing weight required for a signature to be valid. - int Threshold(); + UInt16 Threshold(); // Checkpoint is the nonce of the wallet configuration that the signature applies to. BigInteger Checkpoint(); @@ -20,7 +21,7 @@ public interface ISignature // If chainID is not provided, provider must be provided. // If provider is not provided, EIP-1271 signatures are assumed to be valid. // If signerSignatures is provided, it will be populated with the valid signer signatures of this signature. - (Config, BigInteger) Recover(WalletContext context, + (IWalletConfig, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, @@ -28,7 +29,7 @@ public interface ISignature List signerSignatures); // Recover a signature but only using the subdigest - (Config, BigInteger) RecoverSubdigest(WalletContext context, + (IWalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures); diff --git a/Assets/SequenceSDK/Core/Signature/SignerSignatures.cs b/Assets/SequenceSDK/Core/Signature/SignerSignatures.cs index 727baf7b..9c3780dc 100644 --- a/Assets/SequenceSDK/Core/Signature/SignerSignatures.cs +++ b/Assets/SequenceSDK/Core/Signature/SignerSignatures.cs @@ -3,25 +3,21 @@ namespace Sequence.Core.Signature { public class SignerSignatures { - //From go-sequence : - //type SignerSignatures map[common.Address]map[common.Hash]SignerSignature - //TODO: address type and hash type - public Dictionary> Data { get; set; } + public Dictionary> Data { get; set; } public SignerSignatures() { - Data = new Dictionary>(); + Data = new Dictionary>(); } - public void Insert(Address signerAddress, SignerSignature signature) + public void Insert(Address signer, SignerSignature signature) { - if(!Data.ContainsKey(signerAddress)) + if(!Data.ContainsKey(signer)) { - Dictionary value = new Dictionary(); - value.Add(signature.Subdigest.Hash, signature); - Data.Add(signerAddress, value); + Dictionary value = new Dictionary(); + Data[signer] = value; } - + Data[signer][signature.Subdigest.Hash] = signature; } } @@ -30,7 +26,6 @@ public class SignerSignature public Subdigest Subdigest { get; set; } public SignerSignatureType Type { get; set; } public byte[] Signature { get; set; } - } public enum SignerSignatureType From 4f63ca7f22c2df4316c1ad10ccb815ef60d91698 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Fri, 14 Jul 2023 15:56:56 -0400 Subject: [PATCH 15/49] Moved Network.cs out of Wallet.cs. Removed Sequence.Core.Provider namespace - opting for Sequence.Core instead. --- Assets/SequenceSDK/Core/Network.cs | 25 +++++++++++++++++++ Assets/SequenceSDK/Core/Network.cs.meta | 11 ++++++++ Assets/SequenceSDK/Core/Provider.cs | 2 +- Assets/SequenceSDK/Core/Relayer.cs | 20 +++++++++++++++ Assets/SequenceSDK/Core/Relayer.cs.meta | 11 ++++++++ .../SequenceSDK/Core/Signature/ISignature.cs | 2 +- Assets/SequenceSDK/Core/V2/ISignatureTree.cs | 2 +- .../Core/V2/Signature/ChainedSignature.cs | 8 +++--- .../Core/V2/Signature/NoChainIDSignature.cs | 8 +++--- .../Core/V2/Signature/RegularSignature.cs | 8 +++--- .../Tree/SignatureTreeAddressLeaf.cs | 4 +-- .../Tree/SignatureTreeDynamicSignatureLeaf.cs | 4 +-- .../Tree/SignatureTreeECDSASignatureLeaf.cs | 2 +- .../Signature/Tree/SignatureTreeNestedLeaf.cs | 4 +-- .../V2/Signature/Tree/SignatureTreeNode.cs | 2 +- .../Signature/Tree/SignatureTreeNodeLeaf.cs | 4 +-- .../Tree/SignatureTreeSubdigestLeaf.cs | 4 +-- Assets/SequenceSDK/Core/V2/V2.cs | 2 +- Assets/SequenceSDK/Core/Wallet/Wallet.cs | 22 +--------------- .../SequenceSDK/Core/Wallet/WalletProvider.cs | 2 +- 20 files changed, 97 insertions(+), 50 deletions(-) create mode 100644 Assets/SequenceSDK/Core/Network.cs create mode 100644 Assets/SequenceSDK/Core/Network.cs.meta create mode 100644 Assets/SequenceSDK/Core/Relayer.cs create mode 100644 Assets/SequenceSDK/Core/Relayer.cs.meta diff --git a/Assets/SequenceSDK/Core/Network.cs b/Assets/SequenceSDK/Core/Network.cs new file mode 100644 index 00000000..5014b511 --- /dev/null +++ b/Assets/SequenceSDK/Core/Network.cs @@ -0,0 +1,25 @@ +using System; +using System.Numerics; + +namespace Sequence.Core +{ + public class NetworkConfig + { + public string Name { get; set; } + public BigInteger ChainID { get; set; } + public string ENSAddress { get; set; } + + public string RpcURL { get; set; } + public RPCProvider Provider; + + public string RelayerURL { get; set; } // optional, one of the these should be set + public Relayer Relayer { get; set; } + + public string IndexerURL { get; set; } + + public bool IsDefaultChain { get; set; } + public bool IsAuthChain { get; set; } + + public string SequenceAPIURL { get; set; } + } +} diff --git a/Assets/SequenceSDK/Core/Network.cs.meta b/Assets/SequenceSDK/Core/Network.cs.meta new file mode 100644 index 00000000..4a1e7466 --- /dev/null +++ b/Assets/SequenceSDK/Core/Network.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 59a98a972d19247ca8113eb7763dac8c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/Provider.cs b/Assets/SequenceSDK/Core/Provider.cs index 366b15e2..d8d1e101 100644 --- a/Assets/SequenceSDK/Core/Provider.cs +++ b/Assets/SequenceSDK/Core/Provider.cs @@ -5,7 +5,7 @@ using Sequence.Provider; using UnityEngine; -namespace Sequence.Core.Provider +namespace Sequence.Core { public struct ProviderOption { diff --git a/Assets/SequenceSDK/Core/Relayer.cs b/Assets/SequenceSDK/Core/Relayer.cs new file mode 100644 index 00000000..67c11fca --- /dev/null +++ b/Assets/SequenceSDK/Core/Relayer.cs @@ -0,0 +1,20 @@ +using System; +using Sequence.Transactions; +using Sequence.Core.Wallet; +using System.Numerics; + +namespace Sequence.Core +{ + public interface Relayer + { + RPCProvider GetProvider(); + + EthTransaction[] EstimateGasLimits(IWalletConfig walletConfig, WalletContext walletContext, params EthTransaction[] transactions); + + BigInteger GetNonce(IWalletConfig walletConfig, WalletContext walletContext, BigInteger space, BigInteger blockNumber); + + //(string, EthTransaction, TransactionReceipt, Exception) Relay(SignedTransactions signedTransactions); + + TransactionReceipt Wait(string transactionID, float maxWaitTime = -1); + } +} diff --git a/Assets/SequenceSDK/Core/Relayer.cs.meta b/Assets/SequenceSDK/Core/Relayer.cs.meta new file mode 100644 index 00000000..93e3c846 --- /dev/null +++ b/Assets/SequenceSDK/Core/Relayer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e2e631b8b98664392b800a0c7d2d6570 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/Signature/ISignature.cs b/Assets/SequenceSDK/Core/Signature/ISignature.cs index 5b5a2637..146d7ae4 100644 --- a/Assets/SequenceSDK/Core/Signature/ISignature.cs +++ b/Assets/SequenceSDK/Core/Signature/ISignature.cs @@ -3,7 +3,7 @@ using System.Numerics; using UnityEngine; using Sequence.Core.Wallet; -using Sequence.Core.Provider; +using Sequence.Core; using System; namespace Sequence.Core.Signature diff --git a/Assets/SequenceSDK/Core/V2/ISignatureTree.cs b/Assets/SequenceSDK/Core/V2/ISignatureTree.cs index 715898f4..8a502bbd 100644 --- a/Assets/SequenceSDK/Core/V2/ISignatureTree.cs +++ b/Assets/SequenceSDK/Core/V2/ISignatureTree.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Numerics; -using Sequence.Core.Provider; +using Sequence.Core; using Sequence.Core.Signature; using Sequence.Core.Wallet; diff --git a/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs b/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs index 4ac61dca..10c220d7 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs @@ -5,7 +5,7 @@ using System.Numerics; using Sequence.Core.Signature; using Sequence.Core.Wallet; -using Sequence.Core.Provider; +using Sequence.Core; namespace Sequence.Core.V2.Signature { @@ -26,12 +26,12 @@ public ISignature Join(Subdigest subdigest, ISignature otherSignature) throw new NotImplementedException(); } - public (Config, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) + public (IWalletConfig, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) { throw new NotImplementedException(); } - public (Config, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + public (IWalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) { throw new NotImplementedException(); } @@ -41,7 +41,7 @@ public ISignature Reduce(Subdigest subdigest) throw new NotImplementedException(); } - public int Threshold() + public UInt16 Threshold() { throw new NotImplementedException(); } diff --git a/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs b/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs index f7abf721..3d285ec2 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs @@ -5,7 +5,7 @@ using System.Numerics; using Sequence.Core.Signature; using Sequence.Core.Wallet; -using Sequence.Core.Provider; +using Sequence.Core; namespace Sequence.Core.V2.Signature { @@ -26,12 +26,12 @@ public ISignature Join(Subdigest subdigest, ISignature otherSignature) throw new NotImplementedException(); } - public (Config, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) + public (IWalletConfig, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) { throw new NotImplementedException(); } - public (Config, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + public (IWalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) { throw new NotImplementedException(); } @@ -41,7 +41,7 @@ public ISignature Reduce(Subdigest subdigest) throw new NotImplementedException(); } - public int Threshold() + public UInt16 Threshold() { throw new NotImplementedException(); } diff --git a/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs b/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs index 6d25f2d0..1faf95fe 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs @@ -5,7 +5,7 @@ using System.Numerics; using Sequence.Core.Signature; using Sequence.Core.Wallet; -using Sequence.Core.Provider; +using Sequence.Core; namespace Sequence.Core.V2.Signature { @@ -29,12 +29,12 @@ public ISignature Join(Subdigest subdigest, ISignature otherSignature) throw new NotImplementedException(); } - public (Config, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) + public (IWalletConfig, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) { throw new NotImplementedException(); } - public (Config, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + public (IWalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) { throw new NotImplementedException(); } @@ -44,7 +44,7 @@ public ISignature Reduce(Subdigest subdigest) throw new NotImplementedException(); } - public int Threshold() + public UInt16 Threshold() { throw new NotImplementedException(); } diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeAddressLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeAddressLeaf.cs index 0f77bba5..187b4fac 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeAddressLeaf.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeAddressLeaf.cs @@ -1,7 +1,7 @@ -using System; +using System; using System.Collections.Generic; using System.Numerics; -using Sequence.Core.Provider; +using Sequence.Core; using Sequence.Core.Signature; using Sequence.Core.Wallet; diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeDynamicSignatureLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeDynamicSignatureLeaf.cs index 1e8f50ed..2013bb4c 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeDynamicSignatureLeaf.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeDynamicSignatureLeaf.cs @@ -1,7 +1,7 @@ -using System; +using System; using System.Collections.Generic; using System.Numerics; -using Sequence.Core.Provider; +using Sequence.Core; using Sequence.Core.Signature; using Sequence.Core.Wallet; diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeECDSASignatureLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeECDSASignatureLeaf.cs index ac3d9d28..db0501c0 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeECDSASignatureLeaf.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeECDSASignatureLeaf.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Numerics; -using Sequence.Core.Provider; +using Sequence.Core; using Sequence.Core.Signature; using Sequence.Core.Wallet; diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNestedLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNestedLeaf.cs index 077e53a0..12d01ab4 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNestedLeaf.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNestedLeaf.cs @@ -1,7 +1,7 @@ -using System; +using System; using System.Collections.Generic; using System.Numerics; -using Sequence.Core.Provider; +using Sequence.Core; using Sequence.Core.Signature; using Sequence.Core.Wallet; diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNode.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNode.cs index 73efda0a..5769be4c 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNode.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNode.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Numerics; -using Sequence.Core.Provider; +using Sequence.Core; using Sequence.Core.Signature; using Sequence.Core.Wallet; diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNodeLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNodeLeaf.cs index a8713634..c98c6a35 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNodeLeaf.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNodeLeaf.cs @@ -1,7 +1,7 @@ -using System; +using System; using System.Collections.Generic; using System.Numerics; -using Sequence.Core.Provider; +using Sequence.Core; using Sequence.Core.Signature; using Sequence.Core.Wallet; diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeSubdigestLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeSubdigestLeaf.cs index 9320f1cd..78d24cfb 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeSubdigestLeaf.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeSubdigestLeaf.cs @@ -1,7 +1,7 @@ -using System; +using System; using System.Collections.Generic; using System.Numerics; -using Sequence.Core.Provider; +using Sequence.Core; using Sequence.Core.Signature; using Sequence.Core.Wallet; diff --git a/Assets/SequenceSDK/Core/V2/V2.cs b/Assets/SequenceSDK/Core/V2/V2.cs index c0be4dc0..829da93d 100644 --- a/Assets/SequenceSDK/Core/V2/V2.cs +++ b/Assets/SequenceSDK/Core/V2/V2.cs @@ -1,4 +1,4 @@ -using Sequence.Core.Provider; +using Sequence.Core; using System; using System.Collections; using System.Collections.Generic; diff --git a/Assets/SequenceSDK/Core/Wallet/Wallet.cs b/Assets/SequenceSDK/Core/Wallet/Wallet.cs index a5efbf3f..a3275cec 100644 --- a/Assets/SequenceSDK/Core/Wallet/Wallet.cs +++ b/Assets/SequenceSDK/Core/Wallet/Wallet.cs @@ -1,7 +1,7 @@ #define HAS_SPAN #define SECP256K1_LIB -using Sequence.Core.Provider; +using Sequence.Core; using Sequence.Wallet; using System.Collections.Generic; using System.Numerics; @@ -9,26 +9,6 @@ namespace Sequence.Core.Wallet { - - public class NetworkConfig - { - public string Name { get; set; } - public BigInteger ChainID { get; set; } - public string ENSAddress { get; set; } - public string RpcURL { get; set; } -/* public ethrpc.Provider Provider { get; set; } - public string RelayerURL { get; set; } - public Relayer Relayer { get; set; }*/ - public string IndexerURL { get; set; } - // public Indexer Indexer { get; set; } - public bool IsDefaultChain { get; set; } - public bool IsAuthChain { get; set; } - public string SequenceAPIURL { get; set; } - } - - - - //================================================ public class WalletOptions { // Config is the wallet multi-sig configuration. Note: the first config of any wallet diff --git a/Assets/SequenceSDK/Core/Wallet/WalletProvider.cs b/Assets/SequenceSDK/Core/Wallet/WalletProvider.cs index 36726abc..f4016b20 100644 --- a/Assets/SequenceSDK/Core/Wallet/WalletProvider.cs +++ b/Assets/SequenceSDK/Core/Wallet/WalletProvider.cs @@ -1,4 +1,4 @@ -using Sequence.Core.Provider; +using Sequence.Core; using System.Collections; using System.Collections.Generic; using System.Numerics; From 2b1d34208c9e0818dc4ca37ca0a30352c2635514 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Tue, 18 Jul 2023 11:16:34 -0400 Subject: [PATCH 16/49] Fix some data types --- Assets/SequenceSDK/Core/Provider.cs | 14 +++++------ Assets/SequenceSDK/Core/Relayer.cs | 2 +- .../SequenceSDK/Core/Signature/ISignature.cs | 5 ++-- .../Core/V2/Signature/ChainedSignature.cs | 7 +++--- .../Core/V2/Signature/NoChainIDSignature.cs | 7 +++--- .../Core/V2/Signature/RegularSignature.cs | 23 +++++++++++++++---- 6 files changed, 37 insertions(+), 21 deletions(-) diff --git a/Assets/SequenceSDK/Core/Provider.cs b/Assets/SequenceSDK/Core/Provider.cs index d8d1e101..e22f577d 100644 --- a/Assets/SequenceSDK/Core/Provider.cs +++ b/Assets/SequenceSDK/Core/Provider.cs @@ -22,7 +22,7 @@ public class RPCProvider { // Logger logger; string nodeURL; - HttpRpcClient httpClient; + IEthClient client; public RPCProvider(string _nodeURL) @@ -33,18 +33,18 @@ public RPCProvider(string _nodeURL) public RPCProvider(string _nodeURL, ProviderOption options) { nodeURL = _nodeURL; - httpClient = new HttpRpcClient(_nodeURL); + client = new SequenceEthClient(_nodeURL); } - public void SetHTTPClient(HttpRpcClient _httpClient) + public void SetHTTPClient(IEthClient client) { - httpClient = _httpClient; + this.client = client; } - public async Task Send(string payload) + public async Task ChainID() { - //? - await httpClient.SendRequest(payload); + string chainId = await client.ChainID(); + return BigInteger.Parse(chainId); } } diff --git a/Assets/SequenceSDK/Core/Relayer.cs b/Assets/SequenceSDK/Core/Relayer.cs index 67c11fca..ff14991d 100644 --- a/Assets/SequenceSDK/Core/Relayer.cs +++ b/Assets/SequenceSDK/Core/Relayer.cs @@ -13,7 +13,7 @@ public interface Relayer BigInteger GetNonce(IWalletConfig walletConfig, WalletContext walletContext, BigInteger space, BigInteger blockNumber); - //(string, EthTransaction, TransactionReceipt, Exception) Relay(SignedTransactions signedTransactions); + //(string, EthTransaction, TransactionReceipt) Relay(SignedTransactions signedTransactions); TransactionReceipt Wait(string transactionID, float maxWaitTime = -1); } diff --git a/Assets/SequenceSDK/Core/Signature/ISignature.cs b/Assets/SequenceSDK/Core/Signature/ISignature.cs index 146d7ae4..66e005ac 100644 --- a/Assets/SequenceSDK/Core/Signature/ISignature.cs +++ b/Assets/SequenceSDK/Core/Signature/ISignature.cs @@ -5,6 +5,7 @@ using Sequence.Core.Wallet; using Sequence.Core; using System; +using System.Threading.Tasks; namespace Sequence.Core.Signature { @@ -14,14 +15,14 @@ public interface ISignature UInt16 Threshold(); // Checkpoint is the nonce of the wallet configuration that the signature applies to. - BigInteger Checkpoint(); + UInt32 Checkpoint(); // Recover derives the wallet configuration that the signature applies to. // Also returns the signature's weight. // If chainID is not provided, provider must be provided. // If provider is not provided, EIP-1271 signatures are assumed to be valid. // If signerSignatures is provided, it will be populated with the valid signer signatures of this signature. - (IWalletConfig, BigInteger) Recover(WalletContext context, + Task<(IWalletConfig, BigInteger)> Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, diff --git a/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs b/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs index 10c220d7..4d6dec91 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs @@ -6,12 +6,13 @@ using Sequence.Core.Signature; using Sequence.Core.Wallet; using Sequence.Core; +using System.Threading.Tasks; namespace Sequence.Core.V2.Signature { public class ChainedSignature : ISignature { - public BigInteger Checkpoint() + public uint Checkpoint() { throw new NotImplementedException(); } @@ -26,7 +27,7 @@ public ISignature Join(Subdigest subdigest, ISignature otherSignature) throw new NotImplementedException(); } - public (IWalletConfig, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) + public Task<(IWalletConfig, BigInteger)> Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) { throw new NotImplementedException(); } @@ -41,7 +42,7 @@ public ISignature Reduce(Subdigest subdigest) throw new NotImplementedException(); } - public UInt16 Threshold() + public ushort Threshold() { throw new NotImplementedException(); } diff --git a/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs b/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs index 3d285ec2..49eb8df0 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs @@ -6,12 +6,13 @@ using Sequence.Core.Signature; using Sequence.Core.Wallet; using Sequence.Core; +using System.Threading.Tasks; namespace Sequence.Core.V2.Signature { public class NoChainIDSignature : ISignature { - public BigInteger Checkpoint() + public uint Checkpoint() { throw new NotImplementedException(); } @@ -26,7 +27,7 @@ public ISignature Join(Subdigest subdigest, ISignature otherSignature) throw new NotImplementedException(); } - public (IWalletConfig, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) + public Task<(IWalletConfig, BigInteger)> Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) { throw new NotImplementedException(); } @@ -41,7 +42,7 @@ public ISignature Reduce(Subdigest subdigest) throw new NotImplementedException(); } - public UInt16 Threshold() + public ushort Threshold() { throw new NotImplementedException(); } diff --git a/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs b/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs index 1faf95fe..a39d4b00 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs @@ -6,17 +6,20 @@ using Sequence.Core.Signature; using Sequence.Core.Wallet; using Sequence.Core; +using System.Threading.Tasks; namespace Sequence.Core.V2.Signature { public class RegularSignature : ISignature { public bool IsRegular { get; set; } + private UInt16 threshold; + private UInt32 checkpoint; public ISignatureTree Tree { get; set; } - public BigInteger Checkpoint() + public UInt32 Checkpoint() { - throw new NotImplementedException(); + return checkpoint; } public byte[] Data() @@ -29,9 +32,19 @@ public ISignature Join(Subdigest subdigest, ISignature otherSignature) throw new NotImplementedException(); } - public (IWalletConfig, BigInteger) Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) + public async Task<(IWalletConfig, BigInteger)> Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) { - throw new NotImplementedException(); + if (chainId == null) + { + if (provider == null) + { + throw new ArgumentException("Provider is required if chain Id is not specified"); + } + + chainId = await provider.ChainID(); + } + + return RecoverSubdigest(context, digest.Subdigest(wallet, chainId), provider, signerSignatures); } public (IWalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) @@ -46,7 +59,7 @@ public ISignature Reduce(Subdigest subdigest) public UInt16 Threshold() { - throw new NotImplementedException(); + return threshold; } } } \ No newline at end of file From 836388b397d0e38930ce0c4af11a9a4d9d345dd3 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Tue, 18 Jul 2023 15:49:35 -0400 Subject: [PATCH 17/49] RegularSignature.cs implementation. Added ToByteArray extension methods for bool, UInt16, and UInt32 - added unit tests for these extensions. --- .../SequenceSDK/Core/Signature/ISignature.cs | 4 +- Assets/SequenceSDK/Core/V2/ISignatureTree.cs | 7 ++- .../Core/V2/Signature/ChainedSignature.cs | 4 +- .../Core/V2/Signature/NoChainIDSignature.cs | 4 +- .../Core/V2/Signature/RegularSignature.cs | 56 +++++++++++++++++-- .../Tree/SignatureTreeAddressLeaf.cs | 22 +++++++- .../Tree/SignatureTreeDynamicSignatureLeaf.cs | 22 +++++++- .../Tree/SignatureTreeECDSASignatureLeaf.cs | 22 +++++++- .../Signature/Tree/SignatureTreeNestedLeaf.cs | 22 +++++++- .../V2/Signature/Tree/SignatureTreeNode.cs | 22 +++++++- .../Signature/Tree/SignatureTreeNodeLeaf.cs | 22 +++++++- .../Tree/SignatureTreeSubdigestLeaf.cs | 22 +++++++- Assets/SequenceSDK/Core/V2/V2.cs | 7 +-- .../Core/V2/Wallet/WalletConfig.cs | 7 +++ .../Ethereum/Extensions/BoolExtensions.cs | 12 ++++ ...tension.cs.meta => BoolExtensions.cs.meta} | 2 +- ...rayExtension.cs => ByteArrayExtensions.cs} | 0 .../Extensions/ByteArrayExtensions.cs.meta | 11 ++++ .../Ethereum/Extensions/UInt16Extensions.cs | 20 +++++++ .../Extensions/UInt16Extensions.cs.meta | 11 ++++ .../Ethereum/Extensions/UInt32Extensions.cs | 22 ++++++++ .../Extensions/UInt32Extensions.cs.meta | 11 ++++ .../Ethereum/Tests/BoolExtensionsTests.cs | 14 +++++ .../Tests/BoolExtensionsTests.cs.meta | 11 ++++ .../Ethereum/Tests/UInt16ExtensionsTests.cs | 17 ++++++ .../Tests/UInt16ExtensionsTests.cs.meta | 11 ++++ .../Ethereum/Tests/UInt32ExtensionsTests.cs | 17 ++++++ .../Tests/UInt32ExtensionsTests.cs.meta | 11 ++++ 28 files changed, 386 insertions(+), 27 deletions(-) create mode 100644 Assets/SequenceSDK/Ethereum/Extensions/BoolExtensions.cs rename Assets/SequenceSDK/Ethereum/Extensions/{ByteArrayExtension.cs.meta => BoolExtensions.cs.meta} (83%) rename Assets/SequenceSDK/Ethereum/Extensions/{ByteArrayExtension.cs => ByteArrayExtensions.cs} (100%) create mode 100644 Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtensions.cs.meta create mode 100644 Assets/SequenceSDK/Ethereum/Extensions/UInt16Extensions.cs create mode 100644 Assets/SequenceSDK/Ethereum/Extensions/UInt16Extensions.cs.meta create mode 100644 Assets/SequenceSDK/Ethereum/Extensions/UInt32Extensions.cs create mode 100644 Assets/SequenceSDK/Ethereum/Extensions/UInt32Extensions.cs.meta create mode 100644 Assets/SequenceSDK/Ethereum/Tests/BoolExtensionsTests.cs create mode 100644 Assets/SequenceSDK/Ethereum/Tests/BoolExtensionsTests.cs.meta create mode 100644 Assets/SequenceSDK/Ethereum/Tests/UInt16ExtensionsTests.cs create mode 100644 Assets/SequenceSDK/Ethereum/Tests/UInt16ExtensionsTests.cs.meta create mode 100644 Assets/SequenceSDK/Ethereum/Tests/UInt32ExtensionsTests.cs create mode 100644 Assets/SequenceSDK/Ethereum/Tests/UInt32ExtensionsTests.cs.meta diff --git a/Assets/SequenceSDK/Core/Signature/ISignature.cs b/Assets/SequenceSDK/Core/Signature/ISignature.cs index 66e005ac..a398b7ff 100644 --- a/Assets/SequenceSDK/Core/Signature/ISignature.cs +++ b/Assets/SequenceSDK/Core/Signature/ISignature.cs @@ -27,13 +27,13 @@ public interface ISignature Address wallet, BigInteger chainId, RPCProvider provider, - List signerSignatures); + params SignerSignatures[] signerSignatures); // Recover a signature but only using the subdigest (IWalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, - List signerSignatures); + params SignerSignatures[] signerSignatures); // Reduce returns an equivalent optimized signature. ISignature Reduce(Subdigest subdigest); diff --git a/Assets/SequenceSDK/Core/V2/ISignatureTree.cs b/Assets/SequenceSDK/Core/V2/ISignatureTree.cs index 8a502bbd..d9d5344a 100644 --- a/Assets/SequenceSDK/Core/V2/ISignatureTree.cs +++ b/Assets/SequenceSDK/Core/V2/ISignatureTree.cs @@ -13,6 +13,11 @@ public interface ISignatureTree (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, - List signerSignatures); + params SignerSignatures[] signerSignatures); + + ISignatureTree Reduce(); + ISignatureTree Join(ISignatureTree otherSignatureTree); + ImageHash ReduceImageHash(); + byte[] Data(); } } diff --git a/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs b/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs index 4d6dec91..04e0e19d 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/ChainedSignature.cs @@ -27,12 +27,12 @@ public ISignature Join(Subdigest subdigest, ISignature otherSignature) throw new NotImplementedException(); } - public Task<(IWalletConfig, BigInteger)> Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) + public Task<(IWalletConfig, BigInteger)> Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, params SignerSignatures[] signerSignatures) { throw new NotImplementedException(); } - public (IWalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + public (IWalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, params SignerSignatures[] signerSignatures) { throw new NotImplementedException(); } diff --git a/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs b/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs index 49eb8df0..6c28081d 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs @@ -27,12 +27,12 @@ public ISignature Join(Subdigest subdigest, ISignature otherSignature) throw new NotImplementedException(); } - public Task<(IWalletConfig, BigInteger)> Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) + public Task<(IWalletConfig, BigInteger)> Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, params SignerSignatures[] signerSignatures) { throw new NotImplementedException(); } - public (IWalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + public (IWalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, params SignerSignatures[] signerSignatures) { throw new NotImplementedException(); } diff --git a/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs b/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs index a39d4b00..d4acf507 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs @@ -7,6 +7,8 @@ using Sequence.Core.Wallet; using Sequence.Core; using System.Threading.Tasks; +using Sequence.Core.V2.Wallet; +using Sequence.Extensions; namespace Sequence.Core.V2.Signature { @@ -17,6 +19,14 @@ public class RegularSignature : ISignature private UInt32 checkpoint; public ISignatureTree Tree { get; set; } + public RegularSignature(bool isRegular, UInt16 threshold, UInt32 checkpoint, ISignatureTree tree) + { + this.IsRegular = isRegular; + this.threshold = threshold; + this.checkpoint = checkpoint; + this.Tree = tree; + } + public UInt32 Checkpoint() { return checkpoint; @@ -24,15 +34,42 @@ public UInt32 Checkpoint() public byte[] Data() { - throw new NotImplementedException(); + byte[] data = new byte[0]; + if (this.IsRegular) + { + data = this.IsRegular.ToByteArray(); + } + data = ByteArrayExtensions.ConcatenateByteArrays( + data, + this.threshold.ToByteArray(), + this.checkpoint.ToByteArray(), + this.Tree.Data()); + return data; } public ISignature Join(Subdigest subdigest, ISignature otherSignature) { - throw new NotImplementedException(); + if (!(otherSignature is RegularSignature other)) + { + throw new ArgumentException($"{nameof(otherSignature)} Expected RegularSignature, got {otherSignature.GetType()}"); + } + + if (this.threshold != other.threshold) + { + throw new ArgumentOutOfRangeException($"Threshold mismatch: {this.threshold} != {other.threshold}"); + } + + if (this.checkpoint != other.checkpoint) + { + throw new ArgumentOutOfRangeException($"Checkpoint mismatch: {this.checkpoint} != {other.checkpoint}"); + } + + ISignatureTree tree = this.Tree.Join(other.Tree); + + return new RegularSignature(this.IsRegular, this.threshold, this.checkpoint, tree); } - public async Task<(IWalletConfig, BigInteger)> Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, List signerSignatures) + public async Task<(IWalletConfig, BigInteger)> Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, params SignerSignatures[] signerSignatures) { if (chainId == null) { @@ -47,14 +84,21 @@ public ISignature Join(Subdigest subdigest, ISignature otherSignature) return RecoverSubdigest(context, digest.Subdigest(wallet, chainId), provider, signerSignatures); } - public (IWalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + public (IWalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, params SignerSignatures[] signerSignatures) { - throw new NotImplementedException(); + if (signerSignatures == null) + { + signerSignatures = new SignerSignatures[0]; + } + + (IWalletConfigTree tree, BigInteger weight) = this.Tree.Recover(context, subdigest, provider, signerSignatures); + + return (new WalletConfig(this.threshold, this.checkpoint, tree), weight); } public ISignature Reduce(Subdigest subdigest) { - throw new NotImplementedException(); + return new RegularSignature(this.IsRegular, this.threshold, this.checkpoint, this.Tree.Reduce()); } public UInt16 Threshold() diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeAddressLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeAddressLeaf.cs index 187b4fac..b85e9210 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeAddressLeaf.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeAddressLeaf.cs @@ -12,7 +12,27 @@ public class SignatureTreeAddressLeaf : ISignatureTree public int weight; public string address; - public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + public byte[] Data() + { + throw new NotImplementedException(); + } + + public ISignatureTree Join(ISignatureTree otherSignatureTree) + { + throw new NotImplementedException(); + } + + public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, params SignerSignatures[] signerSignatures) + { + throw new NotImplementedException(); + } + + public ISignatureTree Reduce() + { + throw new NotImplementedException(); + } + + public ImageHash ReduceImageHash() { throw new NotImplementedException(); } diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeDynamicSignatureLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeDynamicSignatureLeaf.cs index 2013bb4c..dbec103f 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeDynamicSignatureLeaf.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeDynamicSignatureLeaf.cs @@ -21,7 +21,27 @@ private enum DynamicSignatureType : byte private DynamicSignatureType type; public byte[] signature; - public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, params SignerSignatures[] signerSignatures) + { + throw new NotImplementedException(); + } + + public ISignatureTree Reduce() + { + throw new NotImplementedException(); + } + + public ISignatureTree Join(ISignatureTree otherSignatureTree) + { + throw new NotImplementedException(); + } + + public ImageHash ReduceImageHash() + { + throw new NotImplementedException(); + } + + public byte[] Data() { throw new NotImplementedException(); } diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeECDSASignatureLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeECDSASignatureLeaf.cs index cf21cdb6..a6a5d4ac 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeECDSASignatureLeaf.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeECDSASignatureLeaf.cs @@ -19,7 +19,27 @@ private enum ECDSASignatureType private ECDSASignatureType type; public byte[] signature = new byte[SignatureLength]; - public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, params SignerSignatures[] signerSignatures) + { + throw new NotImplementedException(); + } + + public ISignatureTree Reduce() + { + throw new NotImplementedException(); + } + + public ISignatureTree Join(ISignatureTree otherSignatureTree) + { + throw new NotImplementedException(); + } + + public ImageHash ReduceImageHash() + { + throw new NotImplementedException(); + } + + public byte[] Data() { throw new NotImplementedException(); } diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNestedLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNestedLeaf.cs index 12d01ab4..60e3e31c 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNestedLeaf.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNestedLeaf.cs @@ -13,7 +13,27 @@ public class SignatureTreeNestedLeaf : ISignatureTree public int threshold; public ISignatureTree tree; - public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + public byte[] Data() + { + throw new NotImplementedException(); + } + + public ISignatureTree Join(ISignatureTree otherSignatureTree) + { + throw new NotImplementedException(); + } + + public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, params SignerSignatures[] signerSignatures) + { + throw new NotImplementedException(); + } + + public ISignatureTree Reduce() + { + throw new NotImplementedException(); + } + + public ImageHash ReduceImageHash() { throw new NotImplementedException(); } diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNode.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNode.cs index 5769be4c..c3b95217 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNode.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNode.cs @@ -12,7 +12,27 @@ public class SignatureTreeNode : ISignatureTree public ISignatureTree left; public ISignatureTree right; - public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + public byte[] Data() + { + throw new NotImplementedException(); + } + + public ISignatureTree Join(ISignatureTree otherSignatureTree) + { + throw new NotImplementedException(); + } + + public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, params SignerSignatures[] signerSignatures) + { + throw new NotImplementedException(); + } + + public ISignatureTree Reduce() + { + throw new NotImplementedException(); + } + + public ImageHash ReduceImageHash() { throw new NotImplementedException(); } diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNodeLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNodeLeaf.cs index c98c6a35..e5e38065 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNodeLeaf.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeNodeLeaf.cs @@ -11,7 +11,27 @@ public class SignatureTreeNodeLeaf : ISignatureTree { public ImageHash imageHash { get; set; } - public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + public byte[] Data() + { + throw new NotImplementedException(); + } + + public ISignatureTree Join(ISignatureTree otherSignatureTree) + { + throw new NotImplementedException(); + } + + public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, params SignerSignatures[] signerSignatures) + { + throw new NotImplementedException(); + } + + public ISignatureTree Reduce() + { + throw new NotImplementedException(); + } + + public ImageHash ReduceImageHash() { throw new NotImplementedException(); } diff --git a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeSubdigestLeaf.cs b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeSubdigestLeaf.cs index 78d24cfb..f6aedb90 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeSubdigestLeaf.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/Tree/SignatureTreeSubdigestLeaf.cs @@ -11,7 +11,27 @@ public class SignatureTreeSubdigestLeaf : ISignatureTree { public Subdigest subdigest { get; set; } - public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, List signerSignatures) + public byte[] Data() + { + throw new NotImplementedException(); + } + + public ISignatureTree Join(ISignatureTree otherSignatureTree) + { + throw new NotImplementedException(); + } + + public (IWalletConfigTree, BigInteger) Recover(WalletContext context, Subdigest subdigest, RPCProvider provider, params SignerSignatures[] signerSignatures) + { + throw new NotImplementedException(); + } + + public ISignatureTree Reduce() + { + throw new NotImplementedException(); + } + + public ImageHash ReduceImageHash() { throw new NotImplementedException(); } diff --git a/Assets/SequenceSDK/Core/V2/V2.cs b/Assets/SequenceSDK/Core/V2/V2.cs index 829da93d..9504bdd3 100644 --- a/Assets/SequenceSDK/Core/V2/V2.cs +++ b/Assets/SequenceSDK/Core/V2/V2.cs @@ -75,12 +75,7 @@ public IWalletConfig DecodeWalletConfig(object obj) IWalletConfigTree tree = WalletConfigTreeDecoder.Decode(treeDict); - return new WalletConfig - { - threshold = threshold, - checkpoint = checkpoint, - tree = tree, - }; + return new WalletConfig(threshold, checkpoint, tree); } } } \ No newline at end of file diff --git a/Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs b/Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs index dad80652..ec038599 100644 --- a/Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs +++ b/Assets/SequenceSDK/Core/V2/Wallet/WalletConfig.cs @@ -15,6 +15,13 @@ public class WalletConfig : IWalletConfig, IImageHashable public UInt32 checkpoint; public IWalletConfigTree tree; + public WalletConfig(UInt16 threshold, UInt32 checkpoint, IWalletConfigTree tree) + { + this.threshold = threshold; + this.checkpoint = checkpoint; + this.tree = tree; + } + public uint Checkpoint() { return checkpoint; diff --git a/Assets/SequenceSDK/Ethereum/Extensions/BoolExtensions.cs b/Assets/SequenceSDK/Ethereum/Extensions/BoolExtensions.cs new file mode 100644 index 00000000..6d6db4c2 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Extensions/BoolExtensions.cs @@ -0,0 +1,12 @@ +using System; + +namespace Sequence.Extensions +{ + public static class BoolExtensions + { + public static byte[] ToByteArray(this bool value) + { + return BitConverter.GetBytes(value); + } + } +} diff --git a/Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtension.cs.meta b/Assets/SequenceSDK/Ethereum/Extensions/BoolExtensions.cs.meta similarity index 83% rename from Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtension.cs.meta rename to Assets/SequenceSDK/Ethereum/Extensions/BoolExtensions.cs.meta index 98c7780d..fdf4258f 100644 --- a/Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtension.cs.meta +++ b/Assets/SequenceSDK/Ethereum/Extensions/BoolExtensions.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3b8061a2862864d298a69951d88d69f5 +guid: 3242cd477cc0849e8891bb359b362cfc MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtension.cs b/Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtensions.cs similarity index 100% rename from Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtension.cs rename to Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtensions.cs diff --git a/Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtensions.cs.meta b/Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtensions.cs.meta new file mode 100644 index 00000000..cba5e42a --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Extensions/ByteArrayExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: badbc0f0a07dd4f4cbf58499e2e8ea5a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Ethereum/Extensions/UInt16Extensions.cs b/Assets/SequenceSDK/Ethereum/Extensions/UInt16Extensions.cs new file mode 100644 index 00000000..a4db70c9 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Extensions/UInt16Extensions.cs @@ -0,0 +1,20 @@ +using System; +namespace Sequence.Extensions +{ + public static class UInt16Extensions + { + /// + /// Convert value to a byte[] using Big-Endian encoding + /// + /// + /// + public static byte[] ToByteArray(this UInt16 value) + { + byte[] byteArray = new byte[2]; + byteArray[0] = (byte)(value >> 8); + byteArray[1] = (byte)value; + + return byteArray; + } + } +} diff --git a/Assets/SequenceSDK/Ethereum/Extensions/UInt16Extensions.cs.meta b/Assets/SequenceSDK/Ethereum/Extensions/UInt16Extensions.cs.meta new file mode 100644 index 00000000..5b6b646d --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Extensions/UInt16Extensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 70197a7feea1d4db08520057f0b6fe2d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Ethereum/Extensions/UInt32Extensions.cs b/Assets/SequenceSDK/Ethereum/Extensions/UInt32Extensions.cs new file mode 100644 index 00000000..4ef70ca6 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Extensions/UInt32Extensions.cs @@ -0,0 +1,22 @@ +using System; +namespace Sequence.Extensions +{ + public static class UInt32Extensions + { + /// + /// Convert value to a byte[] using Big-Endian encoding + /// + /// + /// + public static byte[] ToByteArray(this UInt32 value) + { + byte[] byteArray = new byte[4]; + byteArray[0] = (byte)(value >> 24); + byteArray[1] = (byte)(value >> 16); + byteArray[2] = (byte)(value >> 8); + byteArray[3] = (byte)value; + + return byteArray; + } + } +} diff --git a/Assets/SequenceSDK/Ethereum/Extensions/UInt32Extensions.cs.meta b/Assets/SequenceSDK/Ethereum/Extensions/UInt32Extensions.cs.meta new file mode 100644 index 00000000..26554105 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Extensions/UInt32Extensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4d8359937e4b94bdca4c581b54947d3c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Ethereum/Tests/BoolExtensionsTests.cs b/Assets/SequenceSDK/Ethereum/Tests/BoolExtensionsTests.cs new file mode 100644 index 00000000..746e3c03 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/BoolExtensionsTests.cs @@ -0,0 +1,14 @@ +using NUnit.Framework; +using Sequence.Extensions; + +public class BoolExtensionsTests +{ + [TestCase(true, new byte[] { 1 })] + [TestCase(false, new byte[] { 0 })] + public void TestToByteArray(bool value, byte[] expected) + { + byte[] byteArray = value.ToByteArray(); + + Assert.AreEqual(expected, byteArray); + } +} diff --git a/Assets/SequenceSDK/Ethereum/Tests/BoolExtensionsTests.cs.meta b/Assets/SequenceSDK/Ethereum/Tests/BoolExtensionsTests.cs.meta new file mode 100644 index 00000000..fa651419 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/BoolExtensionsTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 680fb9d6dbc574e75a734cbb2ca5e0b0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Ethereum/Tests/UInt16ExtensionsTests.cs b/Assets/SequenceSDK/Ethereum/Tests/UInt16ExtensionsTests.cs new file mode 100644 index 00000000..c2b309a1 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/UInt16ExtensionsTests.cs @@ -0,0 +1,17 @@ +using System; +using NUnit.Framework; +using Sequence.Extensions; + +public class UInt16ExtensionsTests +{ + [TestCase((UInt16)0x0000, new byte[] { 0x00, 0x00 })] + [TestCase((UInt16)0x1234, new byte[] { 0x12, 0x34 })] + [TestCase((UInt16)0xABCD, new byte[] { 0xAB, 0xCD })] + [TestCase((UInt16)0xFFFF, new byte[] { 0xFF, 0xFF })] + public void TestToByteArray(UInt16 value, byte[] expected) + { + byte[] byteArray = value.ToByteArray(); + + Assert.AreEqual(expected, byteArray); + } +} diff --git a/Assets/SequenceSDK/Ethereum/Tests/UInt16ExtensionsTests.cs.meta b/Assets/SequenceSDK/Ethereum/Tests/UInt16ExtensionsTests.cs.meta new file mode 100644 index 00000000..e150d85a --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/UInt16ExtensionsTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d0d17c2e165bd4d06948b024949e9ec0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Ethereum/Tests/UInt32ExtensionsTests.cs b/Assets/SequenceSDK/Ethereum/Tests/UInt32ExtensionsTests.cs new file mode 100644 index 00000000..f317f729 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/UInt32ExtensionsTests.cs @@ -0,0 +1,17 @@ +using System; +using NUnit.Framework; +using Sequence.Extensions; + +public class UInt32ExtensionsTests +{ + [TestCase((UInt32)0x00000000, new byte[] { 0x00, 0x00, 0x00, 0x00 })] + [TestCase((UInt32)0x12345678, new byte[] { 0x12, 0x34, 0x56, 0x78 })] + [TestCase((UInt32)0xAABBCCDD, new byte[] { 0xAA, 0xBB, 0xCC, 0xDD })] + [TestCase((UInt32)0xFFFFFFFF, new byte[] { 0xFF, 0xFF, 0xFF, 0xFF })] + public void TestToByteArray(UInt32 value, byte[] expected) + { + byte[] byteArray = value.ToByteArray(); + + Assert.AreEqual(expected, byteArray); + } +} diff --git a/Assets/SequenceSDK/Ethereum/Tests/UInt32ExtensionsTests.cs.meta b/Assets/SequenceSDK/Ethereum/Tests/UInt32ExtensionsTests.cs.meta new file mode 100644 index 00000000..38603306 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/UInt32ExtensionsTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 25e0f4380aaa143639ac01d8f6e0e335 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 32422229ded8ed0d6956f3d7a5382ce1541fd5b0 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Tue, 18 Jul 2023 15:55:21 -0400 Subject: [PATCH 18/49] Moved extensions tests to a nested folder. --- Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests.meta | 8 ++++++++ .../Tests/{ => ExtensionsTests}/BoolExtensionsTests.cs | 0 .../{ => ExtensionsTests}/BoolExtensionsTests.cs.meta | 0 .../{ => ExtensionsTests}/ByteArrayExtensionsTests.cs | 0 .../ByteArrayExtensionsTests.cs.meta | 0 .../Tests/{ => ExtensionsTests}/UInt16ExtensionsTests.cs | 0 .../{ => ExtensionsTests}/UInt16ExtensionsTests.cs.meta | 0 .../Tests/{ => ExtensionsTests}/UInt32ExtensionsTests.cs | 0 .../{ => ExtensionsTests}/UInt32ExtensionsTests.cs.meta | 0 9 files changed, 8 insertions(+) create mode 100644 Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests.meta rename Assets/SequenceSDK/Ethereum/Tests/{ => ExtensionsTests}/BoolExtensionsTests.cs (100%) rename Assets/SequenceSDK/Ethereum/Tests/{ => ExtensionsTests}/BoolExtensionsTests.cs.meta (100%) rename Assets/SequenceSDK/Ethereum/Tests/{ => ExtensionsTests}/ByteArrayExtensionsTests.cs (100%) rename Assets/SequenceSDK/Ethereum/Tests/{ => ExtensionsTests}/ByteArrayExtensionsTests.cs.meta (100%) rename Assets/SequenceSDK/Ethereum/Tests/{ => ExtensionsTests}/UInt16ExtensionsTests.cs (100%) rename Assets/SequenceSDK/Ethereum/Tests/{ => ExtensionsTests}/UInt16ExtensionsTests.cs.meta (100%) rename Assets/SequenceSDK/Ethereum/Tests/{ => ExtensionsTests}/UInt32ExtensionsTests.cs (100%) rename Assets/SequenceSDK/Ethereum/Tests/{ => ExtensionsTests}/UInt32ExtensionsTests.cs.meta (100%) diff --git a/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests.meta b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests.meta new file mode 100644 index 00000000..fe8d05ef --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ce2f5e6d96b514fd5b93b831b662eab3 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Ethereum/Tests/BoolExtensionsTests.cs b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/BoolExtensionsTests.cs similarity index 100% rename from Assets/SequenceSDK/Ethereum/Tests/BoolExtensionsTests.cs rename to Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/BoolExtensionsTests.cs diff --git a/Assets/SequenceSDK/Ethereum/Tests/BoolExtensionsTests.cs.meta b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/BoolExtensionsTests.cs.meta similarity index 100% rename from Assets/SequenceSDK/Ethereum/Tests/BoolExtensionsTests.cs.meta rename to Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/BoolExtensionsTests.cs.meta diff --git a/Assets/SequenceSDK/Ethereum/Tests/ByteArrayExtensionsTests.cs b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/ByteArrayExtensionsTests.cs similarity index 100% rename from Assets/SequenceSDK/Ethereum/Tests/ByteArrayExtensionsTests.cs rename to Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/ByteArrayExtensionsTests.cs diff --git a/Assets/SequenceSDK/Ethereum/Tests/ByteArrayExtensionsTests.cs.meta b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/ByteArrayExtensionsTests.cs.meta similarity index 100% rename from Assets/SequenceSDK/Ethereum/Tests/ByteArrayExtensionsTests.cs.meta rename to Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/ByteArrayExtensionsTests.cs.meta diff --git a/Assets/SequenceSDK/Ethereum/Tests/UInt16ExtensionsTests.cs b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/UInt16ExtensionsTests.cs similarity index 100% rename from Assets/SequenceSDK/Ethereum/Tests/UInt16ExtensionsTests.cs rename to Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/UInt16ExtensionsTests.cs diff --git a/Assets/SequenceSDK/Ethereum/Tests/UInt16ExtensionsTests.cs.meta b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/UInt16ExtensionsTests.cs.meta similarity index 100% rename from Assets/SequenceSDK/Ethereum/Tests/UInt16ExtensionsTests.cs.meta rename to Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/UInt16ExtensionsTests.cs.meta diff --git a/Assets/SequenceSDK/Ethereum/Tests/UInt32ExtensionsTests.cs b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/UInt32ExtensionsTests.cs similarity index 100% rename from Assets/SequenceSDK/Ethereum/Tests/UInt32ExtensionsTests.cs rename to Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/UInt32ExtensionsTests.cs diff --git a/Assets/SequenceSDK/Ethereum/Tests/UInt32ExtensionsTests.cs.meta b/Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/UInt32ExtensionsTests.cs.meta similarity index 100% rename from Assets/SequenceSDK/Ethereum/Tests/UInt32ExtensionsTests.cs.meta rename to Assets/SequenceSDK/Ethereum/Tests/ExtensionsTests/UInt32ExtensionsTests.cs.meta From f2ed9428d39dad60d22296444c14790c79d2726b Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 19 Jul 2023 10:52:54 -0400 Subject: [PATCH 19/49] NoChainIDSignature.cs implementation --- .../SequenceSDK/Core/Signature/ISignature.cs | 1 + .../Core/Signature/SignatureType.cs | 20 ++++++++ .../Core/Signature/SignatureType.cs.meta | 11 +++++ .../Core/V2/Signature/NoChainIDSignature.cs | 46 +++++++++++++++---- .../Core/V2/Signature/RegularSignature.cs | 19 ++------ .../SignatureJoinParameterValidators.cs | 35 ++++++++++++++ .../SignatureJoinParameterValidators.cs.meta | 11 +++++ 7 files changed, 118 insertions(+), 25 deletions(-) create mode 100644 Assets/SequenceSDK/Core/Signature/SignatureType.cs create mode 100644 Assets/SequenceSDK/Core/Signature/SignatureType.cs.meta create mode 100644 Assets/SequenceSDK/Core/V2/Signature/SignatureJoinParameterValidators.cs create mode 100644 Assets/SequenceSDK/Core/V2/Signature/SignatureJoinParameterValidators.cs.meta diff --git a/Assets/SequenceSDK/Core/Signature/ISignature.cs b/Assets/SequenceSDK/Core/Signature/ISignature.cs index a398b7ff..6fcb5185 100644 --- a/Assets/SequenceSDK/Core/Signature/ISignature.cs +++ b/Assets/SequenceSDK/Core/Signature/ISignature.cs @@ -6,6 +6,7 @@ using Sequence.Core; using System; using System.Threading.Tasks; +using Sequence.Core.V2; namespace Sequence.Core.Signature { diff --git a/Assets/SequenceSDK/Core/Signature/SignatureType.cs b/Assets/SequenceSDK/Core/Signature/SignatureType.cs new file mode 100644 index 00000000..3a3baa51 --- /dev/null +++ b/Assets/SequenceSDK/Core/Signature/SignatureType.cs @@ -0,0 +1,20 @@ +using System; + +namespace Sequence.Core.Signature +{ + public enum SignatureType : UInt32 + { + Legacy = 0, + Regular = 1, + NoChainID = 2, + Chained = 3 + } + + public static class SignatureTypeExtensions + { + public static byte[] ToByteArray(this SignatureType value) + { + return new byte[] { (byte)value }; + } + } +} diff --git a/Assets/SequenceSDK/Core/Signature/SignatureType.cs.meta b/Assets/SequenceSDK/Core/Signature/SignatureType.cs.meta new file mode 100644 index 00000000..39f22e72 --- /dev/null +++ b/Assets/SequenceSDK/Core/Signature/SignatureType.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 71bc5c39c2789419f96ef629ea617800 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs b/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs index 6c28081d..09a97435 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/NoChainIDSignature.cs @@ -5,46 +5,74 @@ using System.Numerics; using Sequence.Core.Signature; using Sequence.Core.Wallet; -using Sequence.Core; +using Sequence.Extensions; using System.Threading.Tasks; +using Sequence.Core.V2.Wallet; namespace Sequence.Core.V2.Signature { public class NoChainIDSignature : ISignature { + private UInt16 threshold; + private UInt32 checkpoint; + public ISignatureTree Tree { get; set; } + + public NoChainIDSignature(UInt16 threshold, UInt32 checkpoint, ISignatureTree tree) + { + this.threshold = threshold; + this.checkpoint = checkpoint; + this.Tree = tree; + } + public uint Checkpoint() { - throw new NotImplementedException(); + return this.checkpoint; } public byte[] Data() { - throw new NotImplementedException(); + byte[] data = ByteArrayExtensions.ConcatenateByteArrays( + SignatureType.NoChainID.ToByteArray(), + this.threshold.ToByteArray(), + this.checkpoint.ToByteArray(), + this.Tree.Data()); + return data; } public ISignature Join(Subdigest subdigest, ISignature otherSignature) { - throw new NotImplementedException(); + NoChainIDSignature other = SignatureJoinParameterValidator.ValidateParameters(this, otherSignature); + + ISignatureTree tree = this.Tree.Join(other.Tree); + + return new NoChainIDSignature(this.threshold, this.checkpoint, tree); } - public Task<(IWalletConfig, BigInteger)> Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, params SignerSignatures[] signerSignatures) + public async Task<(IWalletConfig, BigInteger)> Recover(WalletContext context, Digest digest, Address wallet, BigInteger chainId, RPCProvider provider, params SignerSignatures[] signerSignatures) { - throw new NotImplementedException(); + return RecoverSubdigest(context, digest.Subdigest(wallet), provider, signerSignatures); } public (IWalletConfig, BigInteger) RecoverSubdigest(WalletContext context, Subdigest subdigest, RPCProvider provider, params SignerSignatures[] signerSignatures) { - throw new NotImplementedException(); + if (signerSignatures == null) + { + signerSignatures = new SignerSignatures[0]; + } + + (IWalletConfigTree tree, BigInteger weight) = this.Tree.Recover(context, subdigest, provider, signerSignatures[0]); + + return (new WalletConfig(this.threshold, this.checkpoint, tree), weight); } public ISignature Reduce(Subdigest subdigest) { - throw new NotImplementedException(); + return new NoChainIDSignature(this.threshold, this.checkpoint, this.Tree.Reduce()); } public ushort Threshold() { - throw new NotImplementedException(); + return this.threshold; } } } \ No newline at end of file diff --git a/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs b/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs index d4acf507..8f9ce2b8 100644 --- a/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs +++ b/Assets/SequenceSDK/Core/V2/Signature/RegularSignature.cs @@ -37,7 +37,7 @@ public byte[] Data() byte[] data = new byte[0]; if (this.IsRegular) { - data = this.IsRegular.ToByteArray(); + data = SignatureType.Regular.ToByteArray(); } data = ByteArrayExtensions.ConcatenateByteArrays( data, @@ -49,20 +49,7 @@ public byte[] Data() public ISignature Join(Subdigest subdigest, ISignature otherSignature) { - if (!(otherSignature is RegularSignature other)) - { - throw new ArgumentException($"{nameof(otherSignature)} Expected RegularSignature, got {otherSignature.GetType()}"); - } - - if (this.threshold != other.threshold) - { - throw new ArgumentOutOfRangeException($"Threshold mismatch: {this.threshold} != {other.threshold}"); - } - - if (this.checkpoint != other.checkpoint) - { - throw new ArgumentOutOfRangeException($"Checkpoint mismatch: {this.checkpoint} != {other.checkpoint}"); - } + RegularSignature other = SignatureJoinParameterValidator.ValidateParameters(this, otherSignature); ISignatureTree tree = this.Tree.Join(other.Tree); @@ -91,7 +78,7 @@ public ISignature Join(Subdigest subdigest, ISignature otherSignature) signerSignatures = new SignerSignatures[0]; } - (IWalletConfigTree tree, BigInteger weight) = this.Tree.Recover(context, subdigest, provider, signerSignatures); + (IWalletConfigTree tree, BigInteger weight) = this.Tree.Recover(context, subdigest, provider, signerSignatures[0]); return (new WalletConfig(this.threshold, this.checkpoint, tree), weight); } diff --git a/Assets/SequenceSDK/Core/V2/Signature/SignatureJoinParameterValidators.cs b/Assets/SequenceSDK/Core/V2/Signature/SignatureJoinParameterValidators.cs new file mode 100644 index 00000000..8692e6de --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/SignatureJoinParameterValidators.cs @@ -0,0 +1,35 @@ +using System; +using Sequence.Core.Signature; + +namespace Sequence.Core.V2.Signature +{ + public static class SignatureJoinParameterValidator + { + /// + /// Throws an exception if otherSignature is not of type T or if the threshold and/or checkpoint don't match between each signature + /// + /// + /// + /// + /// + public static T ValidateParameters(T signature, ISignature otherSignature) where T : ISignature + { + if (!(otherSignature is T other)) + { + throw new ArgumentException($"{nameof(otherSignature)} Expected {typeof(T)}, got {otherSignature.GetType()}"); + } + + if (signature.Threshold() != other.Threshold()) + { + throw new ArgumentOutOfRangeException($"Threshold mismatch: {signature.Threshold()} != {other.Threshold()}"); + } + + if (signature.Checkpoint() != other.Checkpoint()) + { + throw new ArgumentOutOfRangeException($"Checkpoint mismatch: {signature.Checkpoint()} != {other.Checkpoint()}"); + } + + return other; + } + } +} diff --git a/Assets/SequenceSDK/Core/V2/Signature/SignatureJoinParameterValidators.cs.meta b/Assets/SequenceSDK/Core/V2/Signature/SignatureJoinParameterValidators.cs.meta new file mode 100644 index 00000000..a123bb0c --- /dev/null +++ b/Assets/SequenceSDK/Core/V2/Signature/SignatureJoinParameterValidators.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3cfab538266a64bbe99b496b2993f202 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 560e4942e78d6be3d48bcdc5309963d62b333c04 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 19 Jul 2023 15:39:30 -0400 Subject: [PATCH 20/49] Added base datatypes --- Assets/SequenceSDK/WaaS.meta | 8 ++++ Assets/SequenceSDK/WaaS/DataTypes.meta | 8 ++++ Assets/SequenceSDK/WaaS/DataTypes/Page.cs | 31 +++++++++++++++ .../SequenceSDK/WaaS/DataTypes/Page.cs.meta | 11 ++++++ .../WaaS/DataTypes/ParameterTypes.meta | 8 ++++ Assets/SequenceSDK/WaaS/DataTypes/Partner.cs | 26 +++++++++++++ .../WaaS/DataTypes/Partner.cs.meta | 11 ++++++ .../WaaS/DataTypes/PartnerWallet.cs | 23 +++++++++++ .../WaaS/DataTypes/PartnerWallet.cs.meta | 11 ++++++ .../WaaS/DataTypes/PartnerWalletConfig.cs | 23 +++++++++++ .../DataTypes/PartnerWalletConfig.cs.meta | 11 ++++++ .../WaaS/DataTypes/ReturnTypes.meta | 8 ++++ Assets/SequenceSDK/WaaS/DataTypes/SortBy.cs | 13 +++++++ .../SequenceSDK/WaaS/DataTypes/SortBy.cs.meta | 11 ++++++ .../SequenceSDK/WaaS/DataTypes/SortOrder.cs | 31 +++++++++++++++ .../WaaS/DataTypes/SortOrder.cs.meta | 11 ++++++ .../SequenceSDK/WaaS/DataTypes/Transaction.cs | 39 +++++++++++++++++++ .../WaaS/DataTypes/Transaction.cs.meta | 11 ++++++ Assets/SequenceSDK/WaaS/SequenceWaaS.asmdef | 16 ++++++++ .../SequenceSDK/WaaS/SequenceWaaS.asmdef.meta | 7 ++++ 20 files changed, 318 insertions(+) create mode 100644 Assets/SequenceSDK/WaaS.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/Page.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/Page.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/Partner.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/Partner.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/PartnerWallet.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/PartnerWallet.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/PartnerWalletConfig.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/PartnerWalletConfig.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/SortBy.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/SortBy.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/SortOrder.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/SortOrder.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/SequenceWaaS.asmdef create mode 100644 Assets/SequenceSDK/WaaS/SequenceWaaS.asmdef.meta diff --git a/Assets/SequenceSDK/WaaS.meta b/Assets/SequenceSDK/WaaS.meta new file mode 100644 index 00000000..7cab5d5e --- /dev/null +++ b/Assets/SequenceSDK/WaaS.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1069fc1088e1745789f1291ce196d3df +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/WaaS/DataTypes.meta b/Assets/SequenceSDK/WaaS/DataTypes.meta new file mode 100644 index 00000000..48efbb50 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 750009df1e3044d8885ef68776944af5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/WaaS/DataTypes/Page.cs b/Assets/SequenceSDK/WaaS/DataTypes/Page.cs new file mode 100644 index 00000000..ad1c2a03 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/Page.cs @@ -0,0 +1,31 @@ +using System.Collections; +using System.Collections.Generic; +using JetBrains.Annotations; +using UnityEngine; + +namespace Sequence.WaaS +{ + [System.Serializable] + public class Page + { + public uint? pageSize { get; private set; } + public uint? page { get; private set; } + public uint? totalRecords { get; private set; } + [CanBeNull] public string column { get; private set; } + [CanBeNull] public object before { get; private set; } + [CanBeNull] public object after { get; private set; } + [CanBeNull] public SortBy[] sort { get; private set; } + + public Page(uint? pageSize = null, uint? page = null, uint? totalRecords = null, string column = null, object before = null, object after = null, SortBy[] sort = null) + { + this.pageSize = pageSize; + this.page = page; + this.totalRecords = totalRecords; + this.column = column; + this.before = before; + this.after = after; + this.sort = sort; + } + } + +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/Page.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/Page.cs.meta new file mode 100644 index 00000000..7389e630 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/Page.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ebc06d09850e44e3d8e9b2a43e1fb832 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes.meta b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes.meta new file mode 100644 index 00000000..7ec3ddf8 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 84da926b93b7a4a2185a95bf20cb12ee +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/WaaS/DataTypes/Partner.cs b/Assets/SequenceSDK/WaaS/DataTypes/Partner.cs new file mode 100644 index 00000000..3f6cc9b0 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/Partner.cs @@ -0,0 +1,26 @@ +using System.Collections; +using System.Collections.Generic; +using JetBrains.Annotations; +using UnityEngine; + +namespace Sequence.WaaS +{ + [System.Serializable] + public class Partner + { + public uint id { get; private set; } + public string name; + public string jwtAlg { get; private set; } + [CanBeNull] private string jwtSecret; + public string jwtPublic { get; private set; } + + public Partner(uint id, string name, string jwtAlg, string jwtSecret = null, string jwtPublic = null) + { + this.id = id; + this.name = name; + this.jwtAlg = jwtAlg; + this.jwtSecret = jwtSecret; + this.jwtPublic = jwtPublic; + } + } +} diff --git a/Assets/SequenceSDK/WaaS/DataTypes/Partner.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/Partner.cs.meta new file mode 100644 index 00000000..2239eb8e --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/Partner.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e2248d4a8a3d54260a65a2d9badb0151 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/WaaS/DataTypes/PartnerWallet.cs b/Assets/SequenceSDK/WaaS/DataTypes/PartnerWallet.cs new file mode 100644 index 00000000..60997d17 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/PartnerWallet.cs @@ -0,0 +1,23 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Sequence.WaaS +{ + [System.Serializable] + public class PartnerWallet + { + public uint id { get; private set; } + public uint partnerId { get; private set; } + public uint walletIndex { get; private set; } + public string walletAddress { get; private set; } + + public PartnerWallet(uint id, uint partnerId, uint walletIndex, string walletAddress) + { + this.id = id; + this.partnerId = partnerId; + this.walletIndex = walletIndex; + this.walletAddress = walletAddress; + } + } +} diff --git a/Assets/SequenceSDK/WaaS/DataTypes/PartnerWallet.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/PartnerWallet.cs.meta new file mode 100644 index 00000000..1c538344 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/PartnerWallet.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c59321cda4de04ae0bf8e0cd71f46cc7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/WaaS/DataTypes/PartnerWalletConfig.cs b/Assets/SequenceSDK/WaaS/DataTypes/PartnerWalletConfig.cs new file mode 100644 index 00000000..04af2943 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/PartnerWalletConfig.cs @@ -0,0 +1,23 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Sequence.WaaS +{ + [System.Serializable] + public class PartnerWalletConfig + { + public uint id { get; private set; } + public uint partnerId { get; private set; } + public string address { get; private set; } + public string config { get; private set; } + + public PartnerWalletConfig(uint id, uint partnerId, string address, string config) + { + this.id = id; + this.partnerId = partnerId; + this.address = address; + this.config = config; + } + } +} diff --git a/Assets/SequenceSDK/WaaS/DataTypes/PartnerWalletConfig.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/PartnerWalletConfig.cs.meta new file mode 100644 index 00000000..98737cdc --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/PartnerWalletConfig.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: de1cd82ab1eff45c393b5d5941284eb2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes.meta b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes.meta new file mode 100644 index 00000000..3a4199a8 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cf5fb2d428e184a489d2ea553b02a3ff +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/WaaS/DataTypes/SortBy.cs b/Assets/SequenceSDK/WaaS/DataTypes/SortBy.cs new file mode 100644 index 00000000..6873c0b0 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/SortBy.cs @@ -0,0 +1,13 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Sequence.WaaS +{ + [System.Serializable] + public class SortBy + { + public string column { get; private set; } + public SortOrder order { get; private set; } + } +} diff --git a/Assets/SequenceSDK/WaaS/DataTypes/SortBy.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/SortBy.cs.meta new file mode 100644 index 00000000..f91a7cd5 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/SortBy.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cd8a832416a6c4e7184a4578d60a6c32 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/WaaS/DataTypes/SortOrder.cs b/Assets/SequenceSDK/WaaS/DataTypes/SortOrder.cs new file mode 100644 index 00000000..4ebab346 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/SortOrder.cs @@ -0,0 +1,31 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Sequence.WaaS +{ + public class SortOrder + { + public static string Descending = "DESC"; + public static string Ascending = "ASC"; + + public string Value { get; private set; } + + public SortOrder(bool ascending) + { + if (ascending) + { + Value = Ascending; + } + else + { + Value = Descending; + } + } + + public static implicit operator string(SortOrder order) + { + return order.Value; + } + } +} diff --git a/Assets/SequenceSDK/WaaS/DataTypes/SortOrder.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/SortOrder.cs.meta new file mode 100644 index 00000000..a259877f --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/SortOrder.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 99e1b5b85598649d1804c8fd42a5fcdb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs b/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs new file mode 100644 index 00000000..e55347bc --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs @@ -0,0 +1,39 @@ +using System.Collections; +using System.Collections.Generic; +using System.Numerics; +using JetBrains.Annotations; +using UnityEngine; + +namespace Sequence.WaaS +{ + [System.Serializable] + public class Transaction + { + public uint chainId; + public string from; + public string to; + public string autoGas; + public BigInteger? nonce; + [CanBeNull] public string value; + [CanBeNull] public string calldata; + [CanBeNull] public string tokenAddress; + [CanBeNull] public string tokenAmount; + [CanBeNull] public string[] tokenIds; + [CanBeNull] public string[] tokenAmounts; + + public Transaction(uint chainId, string from, string to, string autoGas = null, BigInteger? nonce = null, string value = null, string calldata = null, string tokenAddress = null, string tokenAmount = null, string[] tokenIds = null, string[] tokenAmounts = null) + { + this.chainId = chainId; + this.from = from; + this.to = to; + this.autoGas = autoGas; + this.nonce = nonce; + this.value = value; + this.calldata = calldata; + this.tokenAddress = tokenAddress; + this.tokenAmount = tokenAmount; + this.tokenIds = tokenIds; + this.tokenAmounts = tokenAmounts; + } + } +} diff --git a/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs.meta new file mode 100644 index 00000000..52d2b529 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 662b4bdee6cf74c0488bdbf46932388d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/WaaS/SequenceWaaS.asmdef b/Assets/SequenceSDK/WaaS/SequenceWaaS.asmdef new file mode 100644 index 00000000..421af19b --- /dev/null +++ b/Assets/SequenceSDK/WaaS/SequenceWaaS.asmdef @@ -0,0 +1,16 @@ +{ + "name": "SequenceWaaS", + "rootNamespace": "", + "references": [ + "GUID:f7fd4ba36aabd1d499450c174865e70b" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/SequenceWaaS.asmdef.meta b/Assets/SequenceSDK/WaaS/SequenceWaaS.asmdef.meta new file mode 100644 index 00000000..3ffc4b5e --- /dev/null +++ b/Assets/SequenceSDK/WaaS/SequenceWaaS.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 4e0a798abbda240658187632ae443a67 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From 3a2dafe49d8daf655b1701c2d3aad8f5d29a7fda Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 19 Jul 2023 16:55:05 -0400 Subject: [PATCH 21/49] Added remaining data types --- Assets/SequenceSDK/WaaS/DataTypes/Page.cs | 13 ++++------ .../AddPartnerWalletSignerArgs.cs | 13 ++++++++++ .../AddPartnerWalletSignerArgs.cs.meta | 3 +++ .../ParameterTypes/CreatePartnerArgs.cs | 22 ++++++++++++++++ .../ParameterTypes/CreatePartnerArgs.cs.meta | 3 +++ .../CreatePartnerWalletConfigArgs.cs | 17 +++++++++++++ .../CreatePartnerWalletConfigArgs.cs.meta | 3 +++ .../ParameterTypes/CreateWalletArgs.cs | 13 ++++++++++ .../ParameterTypes/CreateWalletArgs.cs.meta | 3 +++ .../DeployPartnerParentWalletArgs.cs | 15 +++++++++++ .../DeployPartnerParentWalletArgs.cs.meta | 3 +++ .../ParameterTypes/DeployWalletArgs.cs | 15 +++++++++++ .../ParameterTypes/DeployWalletArgs.cs.meta | 3 +++ .../ParameterTypes/GetWalletAddressArgs.cs | 13 ++++++++++ .../GetWalletAddressArgs.cs.meta | 3 +++ .../IsValidMessageSignatureArgs.cs | 19 ++++++++++++++ .../IsValidMessageSignatureArgs.cs.meta | 3 +++ .../ListPartnerWalletSignersArgs.cs | 13 ++++++++++ .../ListPartnerWalletSignersArgs.cs.meta | 3 +++ .../ParameterTypes/PartnerWalletConfigArgs.cs | 13 ++++++++++ .../PartnerWalletConfigArgs.cs.meta | 3 +++ .../ParameterTypes/PartnerWalletsArgs.cs | 15 +++++++++++ .../ParameterTypes/PartnerWalletsArgs.cs.meta | 3 +++ .../RemovePartnerWalletSignerArgs.cs | 13 ++++++++++ .../RemovePartnerWalletSignerArgs.cs.meta | 3 +++ .../ParameterTypes/SendTransactionArgs.cs | 13 ++++++++++ .../SendTransactionArgs.cs.meta | 3 +++ .../SendTransactionBatchArgs.cs | 13 ++++++++++ .../SendTransactionBatchArgs.cs.meta | 3 +++ .../ParameterTypes/SignMessageArgs.cs | 17 +++++++++++++ .../ParameterTypes/SignMessageArgs.cs.meta | 3 +++ .../ParameterTypes/UpdatePartnerArgs.cs | 21 ++++++++++++++++ .../ParameterTypes/UpdatePartnerArgs.cs.meta | 3 +++ .../DataTypes/ParameterTypes/WalletsArgs.cs | 13 ++++++++++ .../ParameterTypes/WalletsArgs.cs.meta | 3 +++ Assets/SequenceSDK/WaaS/DataTypes/Partner.cs | 7 ++---- .../WaaS/DataTypes/PartnerWalletSigner.cs | 25 +++++++++++++++++++ .../DataTypes/PartnerWalletSigner.cs.meta | 3 +++ .../AddPartnerWalletSignerReturn.cs | 8 ++++++ .../AddPartnerWalletSignerReturn.cs.meta | 3 +++ .../ReturnTypes/CreatePartnerReturn.cs | 8 ++++++ .../ReturnTypes/CreatePartnerReturn.cs.meta | 3 +++ .../CreatePartnerWalletConfigReturn.cs | 8 ++++++ .../CreatePartnerWalletConfigReturn.cs.meta | 3 +++ .../ReturnTypes/CreateWalletReturn.cs | 8 ++++++ .../ReturnTypes/CreateWalletReturn.cs.meta | 3 +++ .../DeployPartnerParentWalletReturn.cs | 9 +++++++ .../DeployPartnerParentWalletReturn.cs.meta | 3 +++ .../ReturnTypes/DeployWalletReturn.cs | 9 +++++++ .../ReturnTypes/DeployWalletReturn.cs.meta | 3 +++ .../ReturnTypes/GetWalletAddressReturn.cs | 8 ++++++ .../GetWalletAddressReturn.cs.meta | 3 +++ .../IsValidMessageSignatureReturn.cs | 8 ++++++ .../IsValidMessageSignatureReturn.cs.meta | 3 +++ .../ListPartnerWalletSignersReturn.cs | 8 ++++++ .../ListPartnerWalletSignersReturn.cs.meta | 3 +++ .../ReturnTypes/PartnerWalletConfigReturn.cs | 8 ++++++ .../PartnerWalletConfigReturn.cs.meta | 3 +++ .../ReturnTypes/PartnerWalletsReturn.cs | 9 +++++++ .../ReturnTypes/PartnerWalletsReturn.cs.meta | 3 +++ .../RemovePartnerWalletSignerReturn.cs | 8 ++++++ .../RemovePartnerWalletSignerReturn.cs.meta | 3 +++ .../ReturnTypes/SendTransactionBatchReturn.cs | 8 ++++++ .../SendTransactionBatchReturn.cs.meta | 3 +++ .../ReturnTypes/SendTransactionReturn.cs | 8 ++++++ .../ReturnTypes/SendTransactionReturn.cs.meta | 3 +++ .../ReturnTypes/SignMessageReturn.cs | 8 ++++++ .../ReturnTypes/SignMessageReturn.cs.meta | 3 +++ .../ReturnTypes/UpdatePartnerReturn.cs | 8 ++++++ .../ReturnTypes/UpdatePartnerReturn.cs.meta | 3 +++ .../DataTypes/ReturnTypes/WalletsReturn.cs | 9 +++++++ .../ReturnTypes/WalletsReturn.cs.meta | 3 +++ .../SequenceSDK/WaaS/DataTypes/Transaction.cs | 13 +++++----- 73 files changed, 541 insertions(+), 20 deletions(-) create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/AddPartnerWalletSignerArgs.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/AddPartnerWalletSignerArgs.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreatePartnerArgs.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreatePartnerArgs.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreatePartnerWalletConfigArgs.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreatePartnerWalletConfigArgs.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreateWalletArgs.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreateWalletArgs.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/DeployPartnerParentWalletArgs.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/DeployPartnerParentWalletArgs.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/DeployWalletArgs.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/DeployWalletArgs.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/GetWalletAddressArgs.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/GetWalletAddressArgs.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/IsValidMessageSignatureArgs.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/IsValidMessageSignatureArgs.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/ListPartnerWalletSignersArgs.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/ListPartnerWalletSignersArgs.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/PartnerWalletConfigArgs.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/PartnerWalletConfigArgs.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/PartnerWalletsArgs.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/PartnerWalletsArgs.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/RemovePartnerWalletSignerArgs.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/RemovePartnerWalletSignerArgs.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SendTransactionArgs.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SendTransactionArgs.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SendTransactionBatchArgs.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SendTransactionBatchArgs.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SignMessageArgs.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SignMessageArgs.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/UpdatePartnerArgs.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/UpdatePartnerArgs.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/WalletsArgs.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/WalletsArgs.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/PartnerWalletSigner.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/PartnerWalletSigner.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/AddPartnerWalletSignerReturn.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/AddPartnerWalletSignerReturn.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreatePartnerReturn.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreatePartnerReturn.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreatePartnerWalletConfigReturn.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreatePartnerWalletConfigReturn.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreateWalletReturn.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreateWalletReturn.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/DeployPartnerParentWalletReturn.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/DeployPartnerParentWalletReturn.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/DeployWalletReturn.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/DeployWalletReturn.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/GetWalletAddressReturn.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/GetWalletAddressReturn.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/IsValidMessageSignatureReturn.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/IsValidMessageSignatureReturn.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/ListPartnerWalletSignersReturn.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/ListPartnerWalletSignersReturn.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/PartnerWalletConfigReturn.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/PartnerWalletConfigReturn.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/PartnerWalletsReturn.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/PartnerWalletsReturn.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/RemovePartnerWalletSignerReturn.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/RemovePartnerWalletSignerReturn.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SendTransactionBatchReturn.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SendTransactionBatchReturn.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SendTransactionReturn.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SendTransactionReturn.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SignMessageReturn.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SignMessageReturn.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/UpdatePartnerReturn.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/UpdatePartnerReturn.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/WalletsReturn.cs create mode 100644 Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/WalletsReturn.cs.meta diff --git a/Assets/SequenceSDK/WaaS/DataTypes/Page.cs b/Assets/SequenceSDK/WaaS/DataTypes/Page.cs index ad1c2a03..ee27b7ed 100644 --- a/Assets/SequenceSDK/WaaS/DataTypes/Page.cs +++ b/Assets/SequenceSDK/WaaS/DataTypes/Page.cs @@ -1,7 +1,4 @@ -using System.Collections; -using System.Collections.Generic; -using JetBrains.Annotations; -using UnityEngine; + namespace Sequence.WaaS { @@ -11,10 +8,10 @@ public class Page public uint? pageSize { get; private set; } public uint? page { get; private set; } public uint? totalRecords { get; private set; } - [CanBeNull] public string column { get; private set; } - [CanBeNull] public object before { get; private set; } - [CanBeNull] public object after { get; private set; } - [CanBeNull] public SortBy[] sort { get; private set; } + public string column { get; private set; } + public object before { get; private set; } + public object after { get; private set; } + public SortBy[] sort { get; private set; } public Page(uint? pageSize = null, uint? page = null, uint? totalRecords = null, string column = null, object before = null, object after = null, SortBy[] sort = null) { diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/AddPartnerWalletSignerArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/AddPartnerWalletSignerArgs.cs new file mode 100644 index 00000000..3c25c050 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/AddPartnerWalletSignerArgs.cs @@ -0,0 +1,13 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class AddPartnerWalletSignerArgs + { + public PartnerWalletSigner signer; + + public AddPartnerWalletSignerArgs(PartnerWalletSigner signer) + { + this.signer = signer; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/AddPartnerWalletSignerArgs.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/AddPartnerWalletSignerArgs.cs.meta new file mode 100644 index 00000000..233a784a --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/AddPartnerWalletSignerArgs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 07a50d7d83f140f1aec15f215b876608 +timeCreated: 1689797883 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreatePartnerArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreatePartnerArgs.cs new file mode 100644 index 00000000..5a3c8961 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreatePartnerArgs.cs @@ -0,0 +1,22 @@ + + +namespace Sequence.WaaS +{ + [System.Serializable] + public class CreatePartnerArgs + { + public string name { get; private set; } + public string jwtAlg { get; private set; } + private string jwtSecret; + public string jwtPublic { get; private set; } + + + public CreatePartnerArgs(string name, string jwtAlg, string jwtSecret = null, string jwtPublic = null) + { + this.jwtSecret = jwtSecret; + this.name = name; + this.jwtAlg = jwtAlg; + this.jwtPublic = jwtPublic; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreatePartnerArgs.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreatePartnerArgs.cs.meta new file mode 100644 index 00000000..749eaf28 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreatePartnerArgs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 659dcfdc164041eb9d5a65217c819967 +timeCreated: 1689796467 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreatePartnerWalletConfigArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreatePartnerWalletConfigArgs.cs new file mode 100644 index 00000000..9d256449 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreatePartnerWalletConfigArgs.cs @@ -0,0 +1,17 @@ + + +namespace Sequence.WaaS +{ + [System.Serializable] + public class CreatePartnerWalletConfigArgs + { + public uint partnerId; + public string config; + + public CreatePartnerWalletConfigArgs(uint partnerId, string config) + { + this.partnerId = partnerId; + this.config = config; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreatePartnerWalletConfigArgs.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreatePartnerWalletConfigArgs.cs.meta new file mode 100644 index 00000000..636ad5e7 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreatePartnerWalletConfigArgs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1dc1d7985d1c4bb39890b2d3d21efcc4 +timeCreated: 1689797237 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreateWalletArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreateWalletArgs.cs new file mode 100644 index 00000000..6bc54585 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreateWalletArgs.cs @@ -0,0 +1,13 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class CreateWalletArgs + { + public uint accountIndex; + + public CreateWalletArgs(uint accountIndex) + { + this.accountIndex = accountIndex; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreateWalletArgs.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreateWalletArgs.cs.meta new file mode 100644 index 00000000..3408c97d --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/CreateWalletArgs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7531bfb26fdd4ec5bb890c04d9a215c0 +timeCreated: 1689798454 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/DeployPartnerParentWalletArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/DeployPartnerParentWalletArgs.cs new file mode 100644 index 00000000..9aaca998 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/DeployPartnerParentWalletArgs.cs @@ -0,0 +1,15 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class DeployPartnerParentWalletArgs + { + public uint partnerId; + public uint chainId; + + public DeployPartnerParentWalletArgs(uint partnerId, uint chainId) + { + this.partnerId = partnerId; + this.chainId = chainId; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/DeployPartnerParentWalletArgs.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/DeployPartnerParentWalletArgs.cs.meta new file mode 100644 index 00000000..cfb68970 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/DeployPartnerParentWalletArgs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6c78adc912de4f28885fe83bb6255126 +timeCreated: 1689797580 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/DeployWalletArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/DeployWalletArgs.cs new file mode 100644 index 00000000..b2127340 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/DeployWalletArgs.cs @@ -0,0 +1,15 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class DeployWalletArgs + { + public uint chainId; + public uint accountIndex; + + public DeployWalletArgs(uint chainId, uint accountIndex) + { + this.chainId = chainId; + this.accountIndex = accountIndex; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/DeployWalletArgs.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/DeployWalletArgs.cs.meta new file mode 100644 index 00000000..4700e254 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/DeployWalletArgs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 471e0ad37f0a48ae8f60f55251975668 +timeCreated: 1689798589 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/GetWalletAddressArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/GetWalletAddressArgs.cs new file mode 100644 index 00000000..cdd62a76 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/GetWalletAddressArgs.cs @@ -0,0 +1,13 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class GetWalletAddressArgs + { + public uint accountIndex; + + public GetWalletAddressArgs(uint accountIndex) + { + this.accountIndex = accountIndex; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/GetWalletAddressArgs.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/GetWalletAddressArgs.cs.meta new file mode 100644 index 00000000..54ba8289 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/GetWalletAddressArgs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ae19ed70b57547e1ab769665404356f5 +timeCreated: 1689798520 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/IsValidMessageSignatureArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/IsValidMessageSignatureArgs.cs new file mode 100644 index 00000000..c8b56f12 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/IsValidMessageSignatureArgs.cs @@ -0,0 +1,19 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class IsValidMessageSignatureArgs + { + public string chainId; + public string walletAddress; + public string message; + public string signature; + + public IsValidMessageSignatureArgs(string chainId, string walletAddress, string message, string signature) + { + this.chainId = chainId; + this.walletAddress = walletAddress; + this.message = message; + this.signature = signature; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/IsValidMessageSignatureArgs.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/IsValidMessageSignatureArgs.cs.meta new file mode 100644 index 00000000..f498d445 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/IsValidMessageSignatureArgs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7dd325280ac24f2bbf4d8b6140a541b4 +timeCreated: 1689798928 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/ListPartnerWalletSignersArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/ListPartnerWalletSignersArgs.cs new file mode 100644 index 00000000..e9eb9218 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/ListPartnerWalletSignersArgs.cs @@ -0,0 +1,13 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class ListPartnerWalletSignersArgs + { + public uint partnerId; + + public ListPartnerWalletSignersArgs(uint partnerId) + { + this.partnerId = partnerId; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/ListPartnerWalletSignersArgs.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/ListPartnerWalletSignersArgs.cs.meta new file mode 100644 index 00000000..d65640a7 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/ListPartnerWalletSignersArgs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 46a3bf52144a46fb9b8cf31e6594c368 +timeCreated: 1689798226 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/PartnerWalletConfigArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/PartnerWalletConfigArgs.cs new file mode 100644 index 00000000..b73c2c5b --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/PartnerWalletConfigArgs.cs @@ -0,0 +1,13 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class PartnerWalletConfigArgs + { + public uint partnerId; + + public PartnerWalletConfigArgs(uint partnerId) + { + this.partnerId = partnerId; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/PartnerWalletConfigArgs.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/PartnerWalletConfigArgs.cs.meta new file mode 100644 index 00000000..d782b6f1 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/PartnerWalletConfigArgs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0ab0efc3f52e412bb8c0a772e64d09d9 +timeCreated: 1689797410 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/PartnerWalletsArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/PartnerWalletsArgs.cs new file mode 100644 index 00000000..cbe2dc93 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/PartnerWalletsArgs.cs @@ -0,0 +1,15 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class PartnerWalletsArgs + { + public uint partnerId; + public Page page; + + public PartnerWalletsArgs(uint partnerId, Page page = null) + { + this.partnerId = partnerId; + this.page = page; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/PartnerWalletsArgs.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/PartnerWalletsArgs.cs.meta new file mode 100644 index 00000000..51fee39e --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/PartnerWalletsArgs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 47c1201d88564347a1b7510d892cb5a9 +timeCreated: 1689798318 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/RemovePartnerWalletSignerArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/RemovePartnerWalletSignerArgs.cs new file mode 100644 index 00000000..47297f82 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/RemovePartnerWalletSignerArgs.cs @@ -0,0 +1,13 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class RemovePartnerWalletSignerArgs + { + public PartnerWalletSigner signer; + + public RemovePartnerWalletSignerArgs(PartnerWalletSigner signer) + { + this.signer = signer; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/RemovePartnerWalletSignerArgs.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/RemovePartnerWalletSignerArgs.cs.meta new file mode 100644 index 00000000..c53b53b0 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/RemovePartnerWalletSignerArgs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 04e5b821fdfe42dba6b517bce782b3e7 +timeCreated: 1689797948 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SendTransactionArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SendTransactionArgs.cs new file mode 100644 index 00000000..297d219a --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SendTransactionArgs.cs @@ -0,0 +1,13 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class SendTransactionArgs + { + public Transaction tx; + + public SendTransactionArgs(Transaction tx) + { + this.tx = tx; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SendTransactionArgs.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SendTransactionArgs.cs.meta new file mode 100644 index 00000000..e1f8be22 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SendTransactionArgs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: dc0489a2093e4a789677c33f98cee127 +timeCreated: 1689799075 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SendTransactionBatchArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SendTransactionBatchArgs.cs new file mode 100644 index 00000000..03e7fa84 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SendTransactionBatchArgs.cs @@ -0,0 +1,13 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class SendTransactionBatchArgs + { + public Transaction[] txs; + + public SendTransactionBatchArgs(params Transaction[] txs) + { + this.txs = txs; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SendTransactionBatchArgs.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SendTransactionBatchArgs.cs.meta new file mode 100644 index 00000000..a6799537 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SendTransactionBatchArgs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fe5e026d21d9451b82871430c140dc8d +timeCreated: 1689799172 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SignMessageArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SignMessageArgs.cs new file mode 100644 index 00000000..48c34700 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SignMessageArgs.cs @@ -0,0 +1,17 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class SignMessageArgs + { + public uint chainId; + public string accountAddress; + public string message; + + public SignMessageArgs(uint chainId, string accountAddress, string message) + { + this.chainId = chainId; + this.accountAddress = accountAddress; + this.message = message; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SignMessageArgs.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SignMessageArgs.cs.meta new file mode 100644 index 00000000..6595b429 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SignMessageArgs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0dbd012ff1514e218d83e71cbf6affd6 +timeCreated: 1689798785 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/UpdatePartnerArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/UpdatePartnerArgs.cs new file mode 100644 index 00000000..9409b2d1 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/UpdatePartnerArgs.cs @@ -0,0 +1,21 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class UpdatePartnerArgs + { + public uint partnerId { get; private set; } + public string name { get; private set; } + public string jwtAlg { get; private set; } + private string jwtSecret; + public string jwtPublic { get; private set; } + + public UpdatePartnerArgs(uint partnerId, string name, string jwtAlg, string jwtSecret = null, string jwtPublic = null) + { + this.name = name; + this.partnerId = partnerId; + this.jwtAlg = jwtAlg; + this.jwtSecret = jwtSecret; + this.jwtPublic = jwtPublic; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/UpdatePartnerArgs.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/UpdatePartnerArgs.cs.meta new file mode 100644 index 00000000..d0a8015d --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/UpdatePartnerArgs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9b2f0ac4270c49eaa9fc49af9cdff6a5 +timeCreated: 1689797003 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/WalletsArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/WalletsArgs.cs new file mode 100644 index 00000000..5a5c3c23 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/WalletsArgs.cs @@ -0,0 +1,13 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class WalletsArgs + { + public Page page; + + public WalletsArgs(Page page = null) + { + this.page = page; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/WalletsArgs.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/WalletsArgs.cs.meta new file mode 100644 index 00000000..d10ebb03 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/WalletsArgs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 666023b458b542148a75687354207469 +timeCreated: 1689798708 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/Partner.cs b/Assets/SequenceSDK/WaaS/DataTypes/Partner.cs index 3f6cc9b0..3b0e6c7d 100644 --- a/Assets/SequenceSDK/WaaS/DataTypes/Partner.cs +++ b/Assets/SequenceSDK/WaaS/DataTypes/Partner.cs @@ -1,7 +1,4 @@ -using System.Collections; -using System.Collections.Generic; -using JetBrains.Annotations; -using UnityEngine; + namespace Sequence.WaaS { @@ -11,7 +8,7 @@ public class Partner public uint id { get; private set; } public string name; public string jwtAlg { get; private set; } - [CanBeNull] private string jwtSecret; + private string jwtSecret; public string jwtPublic { get; private set; } public Partner(uint id, string name, string jwtAlg, string jwtSecret = null, string jwtPublic = null) diff --git a/Assets/SequenceSDK/WaaS/DataTypes/PartnerWalletSigner.cs b/Assets/SequenceSDK/WaaS/DataTypes/PartnerWalletSigner.cs new file mode 100644 index 00000000..2e2bc91a --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/PartnerWalletSigner.cs @@ -0,0 +1,25 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class PartnerWalletSigner + { + public uint number; + public uint partnerId; + public string address; + public string url; + public bool passThroughCredentials; + public bool isSequenceGuard; + public string authToken; + + public PartnerWalletSigner(uint number, uint partnerId, string address, string url, bool passThroughCredentials, bool isSequenceGuard, string authToken) + { + this.number = number; + this.partnerId = partnerId; + this.address = address; + this.url = url; + this.passThroughCredentials = passThroughCredentials; + this.isSequenceGuard = isSequenceGuard; + this.authToken = authToken; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/PartnerWalletSigner.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/PartnerWalletSigner.cs.meta new file mode 100644 index 00000000..28f78d26 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/PartnerWalletSigner.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7fd904caad3b4139992fcc66ab0a2b1c +timeCreated: 1689797757 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/AddPartnerWalletSignerReturn.cs b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/AddPartnerWalletSignerReturn.cs new file mode 100644 index 00000000..b119ab57 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/AddPartnerWalletSignerReturn.cs @@ -0,0 +1,8 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class AddPartnerWalletSignerReturn + { + // Empty return + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/AddPartnerWalletSignerReturn.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/AddPartnerWalletSignerReturn.cs.meta new file mode 100644 index 00000000..9d796f36 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/AddPartnerWalletSignerReturn.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 56649611c24e44748406b0f5efaf7d4f +timeCreated: 1689797919 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreatePartnerReturn.cs b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreatePartnerReturn.cs new file mode 100644 index 00000000..e26b063a --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreatePartnerReturn.cs @@ -0,0 +1,8 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class CreatePartnerReturn + { + public Partner partner; + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreatePartnerReturn.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreatePartnerReturn.cs.meta new file mode 100644 index 00000000..6c9f9969 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreatePartnerReturn.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 428eeee16903458db487e0523e01fa13 +timeCreated: 1689796908 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreatePartnerWalletConfigReturn.cs b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreatePartnerWalletConfigReturn.cs new file mode 100644 index 00000000..2bb29b8c --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreatePartnerWalletConfigReturn.cs @@ -0,0 +1,8 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class CreatePartnerWalletConfigReturn + { + // Empty return + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreatePartnerWalletConfigReturn.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreatePartnerWalletConfigReturn.cs.meta new file mode 100644 index 00000000..0e7b2796 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreatePartnerWalletConfigReturn.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 38d7334ff84d43ffa4901838b8eceefc +timeCreated: 1689797313 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreateWalletReturn.cs b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreateWalletReturn.cs new file mode 100644 index 00000000..c5942fdd --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreateWalletReturn.cs @@ -0,0 +1,8 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class CreateWalletReturn + { + public string address; + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreateWalletReturn.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreateWalletReturn.cs.meta new file mode 100644 index 00000000..98cf0171 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/CreateWalletReturn.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: af6c28197f6e40529ae5cf15f438b2c0 +timeCreated: 1689798489 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/DeployPartnerParentWalletReturn.cs b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/DeployPartnerParentWalletReturn.cs new file mode 100644 index 00000000..a84dd270 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/DeployPartnerParentWalletReturn.cs @@ -0,0 +1,9 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class DeployPartnerParentWalletReturn + { + public string address; + public string txnHash; + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/DeployPartnerParentWalletReturn.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/DeployPartnerParentWalletReturn.cs.meta new file mode 100644 index 00000000..c311e4fc --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/DeployPartnerParentWalletReturn.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 35a6e3fdf9ec43bbbbbd7f025dcff09f +timeCreated: 1689797629 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/DeployWalletReturn.cs b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/DeployWalletReturn.cs new file mode 100644 index 00000000..24eb9142 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/DeployWalletReturn.cs @@ -0,0 +1,9 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class DeployWalletReturn + { + public string address; + public string txnHash; + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/DeployWalletReturn.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/DeployWalletReturn.cs.meta new file mode 100644 index 00000000..ee44730e --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/DeployWalletReturn.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c6647da6244648e28c5bcd3a1006450c +timeCreated: 1689798633 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/GetWalletAddressReturn.cs b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/GetWalletAddressReturn.cs new file mode 100644 index 00000000..e72d3c48 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/GetWalletAddressReturn.cs @@ -0,0 +1,8 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class GetWalletAddressReturn + { + public string address; + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/GetWalletAddressReturn.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/GetWalletAddressReturn.cs.meta new file mode 100644 index 00000000..f6ee8ba7 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/GetWalletAddressReturn.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c534888604dc44f6b2e69c175322c8b2 +timeCreated: 1689798550 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/IsValidMessageSignatureReturn.cs b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/IsValidMessageSignatureReturn.cs new file mode 100644 index 00000000..8938d037 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/IsValidMessageSignatureReturn.cs @@ -0,0 +1,8 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class IsValidMessageSignatureReturn + { + public bool isValid; + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/IsValidMessageSignatureReturn.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/IsValidMessageSignatureReturn.cs.meta new file mode 100644 index 00000000..bbf6b8e5 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/IsValidMessageSignatureReturn.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6e7f3824d3b14ba0a7c7ea56994d7043 +timeCreated: 1689798992 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/ListPartnerWalletSignersReturn.cs b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/ListPartnerWalletSignersReturn.cs new file mode 100644 index 00000000..1cb1cbe4 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/ListPartnerWalletSignersReturn.cs @@ -0,0 +1,8 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class ListPartnerWalletSignersReturn + { + public PartnerWalletSigner[] signers; + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/ListPartnerWalletSignersReturn.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/ListPartnerWalletSignersReturn.cs.meta new file mode 100644 index 00000000..9280a80c --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/ListPartnerWalletSignersReturn.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0b1719a7799546c78ae858cb213fa58b +timeCreated: 1689798287 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/PartnerWalletConfigReturn.cs b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/PartnerWalletConfigReturn.cs new file mode 100644 index 00000000..015016ff --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/PartnerWalletConfigReturn.cs @@ -0,0 +1,8 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class PartnerWalletConfigReturn + { + public string config; + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/PartnerWalletConfigReturn.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/PartnerWalletConfigReturn.cs.meta new file mode 100644 index 00000000..5cc10775 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/PartnerWalletConfigReturn.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7d02a1900e634ab59c0f8e2e2c71efa6 +timeCreated: 1689797501 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/PartnerWalletsReturn.cs b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/PartnerWalletsReturn.cs new file mode 100644 index 00000000..5e5a1e1f --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/PartnerWalletsReturn.cs @@ -0,0 +1,9 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class PartnerWalletsReturn + { + public PartnerWallet[] wallets; + public Page page; + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/PartnerWalletsReturn.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/PartnerWalletsReturn.cs.meta new file mode 100644 index 00000000..b5a2386b --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/PartnerWalletsReturn.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 98768dd498ef4bab8352476d7c8d2f1f +timeCreated: 1689798386 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/RemovePartnerWalletSignerReturn.cs b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/RemovePartnerWalletSignerReturn.cs new file mode 100644 index 00000000..59524aea --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/RemovePartnerWalletSignerReturn.cs @@ -0,0 +1,8 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class RemovePartnerWalletSignerReturn + { + // Empty return + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/RemovePartnerWalletSignerReturn.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/RemovePartnerWalletSignerReturn.cs.meta new file mode 100644 index 00000000..b0fb8bd9 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/RemovePartnerWalletSignerReturn.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: afd2ced3ae694cf39f83af6d5bbd7bdb +timeCreated: 1689797983 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SendTransactionBatchReturn.cs b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SendTransactionBatchReturn.cs new file mode 100644 index 00000000..a82809c0 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SendTransactionBatchReturn.cs @@ -0,0 +1,8 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class SendTransactionBatchReturn + { + public string txHash; + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SendTransactionBatchReturn.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SendTransactionBatchReturn.cs.meta new file mode 100644 index 00000000..b91c04c8 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SendTransactionBatchReturn.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0456ca3a1c694f29906ce745f6fbd7d2 +timeCreated: 1689799217 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SendTransactionReturn.cs b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SendTransactionReturn.cs new file mode 100644 index 00000000..a5a5c2b1 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SendTransactionReturn.cs @@ -0,0 +1,8 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class SendTransactionReturn + { + public string txHash; + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SendTransactionReturn.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SendTransactionReturn.cs.meta new file mode 100644 index 00000000..5f1e3aad --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SendTransactionReturn.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b7b51ca05a1748edb70291d2e16adb67 +timeCreated: 1689799137 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SignMessageReturn.cs b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SignMessageReturn.cs new file mode 100644 index 00000000..ef1d03cd --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SignMessageReturn.cs @@ -0,0 +1,8 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class SignMessageReturn + { + public string signature; + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SignMessageReturn.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SignMessageReturn.cs.meta new file mode 100644 index 00000000..1b3016bd --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/SignMessageReturn.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 924cd321fa484da1a11cb82fc5a71d68 +timeCreated: 1689798896 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/UpdatePartnerReturn.cs b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/UpdatePartnerReturn.cs new file mode 100644 index 00000000..40f5b52b --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/UpdatePartnerReturn.cs @@ -0,0 +1,8 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class UpdatePartnerReturn + { + public Partner partner; + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/UpdatePartnerReturn.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/UpdatePartnerReturn.cs.meta new file mode 100644 index 00000000..8bb5cb27 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/UpdatePartnerReturn.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8d8ccfd9520347eab511c2350209f262 +timeCreated: 1689797178 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/WalletsReturn.cs b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/WalletsReturn.cs new file mode 100644 index 00000000..987a6a04 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/WalletsReturn.cs @@ -0,0 +1,9 @@ +namespace Sequence.WaaS +{ + [System.Serializable] + public class WalletsReturn + { + public PartnerWallet[] wallets; + public Page page; + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/WalletsReturn.cs.meta b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/WalletsReturn.cs.meta new file mode 100644 index 00000000..a8440951 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/WalletsReturn.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 04f583ac29444ea2b5323eac67700c09 +timeCreated: 1689798736 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs b/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs index e55347bc..2ced5d12 100644 --- a/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs +++ b/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs @@ -1,7 +1,6 @@ using System.Collections; using System.Collections.Generic; using System.Numerics; -using JetBrains.Annotations; using UnityEngine; namespace Sequence.WaaS @@ -14,12 +13,12 @@ public class Transaction public string to; public string autoGas; public BigInteger? nonce; - [CanBeNull] public string value; - [CanBeNull] public string calldata; - [CanBeNull] public string tokenAddress; - [CanBeNull] public string tokenAmount; - [CanBeNull] public string[] tokenIds; - [CanBeNull] public string[] tokenAmounts; + public string value; + public string calldata; + public string tokenAddress; + public string tokenAmount; + public string[] tokenIds; + public string[] tokenAmounts; public Transaction(uint chainId, string from, string to, string autoGas = null, BigInteger? nonce = null, string value = null, string calldata = null, string tokenAddress = null, string tokenAmount = null, string[] tokenIds = null, string[] tokenAmounts = null) { From 62e6a4cb9d114233fa8b33f18767710c9a4b1a1a Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 2 Aug 2023 14:53:09 -0400 Subject: [PATCH 22/49] Added IWallet interface --- Assets/SequenceSDK/WaaS/IWallet.cs | 56 +++++++++++++++++++++++++ Assets/SequenceSDK/WaaS/IWallet.cs.meta | 3 ++ 2 files changed, 59 insertions(+) create mode 100644 Assets/SequenceSDK/WaaS/IWallet.cs create mode 100644 Assets/SequenceSDK/WaaS/IWallet.cs.meta diff --git a/Assets/SequenceSDK/WaaS/IWallet.cs b/Assets/SequenceSDK/WaaS/IWallet.cs new file mode 100644 index 00000000..ec87480b --- /dev/null +++ b/Assets/SequenceSDK/WaaS/IWallet.cs @@ -0,0 +1,56 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Sequence.WaaS; + +namespace SequenceSDK.WaaS +{ + public interface IWallet + { + public Task CreatePartner(CreatePartnerArgs args, + Dictionary headers = null); + + public Task UpdatePartner(UpdatePartnerArgs args, + Dictionary headers = null); + + public Task CreatePartnerWalletConfig(CreatePartnerWalletConfigArgs args, + Dictionary headers = null); + + public Task PartnerWalletConfig(PartnerWalletConfigArgs args, + Dictionary headers = null); + + public Task DeployPartnerParentWallet(DeployPartnerParentWalletArgs args, + Dictionary headers = null); + + public Task AddPartnerWalletSigner(AddPartnerWalletSignerArgs args, + Dictionary headers = null); + + public Task RemovePartnerWalletSigner(RemovePartnerWalletSignerArgs args, + Dictionary headers = null); + + public Task ListPartnerWalletSigners(ListPartnerWalletSignersArgs args, + Dictionary headers = null); + + public Task PartnerWallets(PartnerWalletsArgs args, + Dictionary headers = null); + + public Task CreateWallet(CreateWalletArgs args, Dictionary headers = null); + + public Task GetWalletAddress(GetWalletAddressArgs args, + Dictionary headers = null); + + public Task DeployWallet(DeployWalletArgs args, Dictionary headers = null); + + public Task Wallets(WalletsArgs args, Dictionary headers = null); + + public Task SignMessage(SignMessageArgs args, Dictionary headers = null); + + public Task IsValidMessageSignature(IsValidMessageSignatureArgs args, + Dictionary headers = null); + + public Task SendTransaction(SendTransactionArgs args, + Dictionary headers = null); + + public Task SendTransactionBatch(SendTransactionBatchArgs args, + Dictionary headers = null); + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/IWallet.cs.meta b/Assets/SequenceSDK/WaaS/IWallet.cs.meta new file mode 100644 index 00000000..d3351a47 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/IWallet.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9374bb0ac08e4f5eb643aea0dda88231 +timeCreated: 1691001266 \ No newline at end of file From 03433e4e94b531c452d0ac566e58ace033c06355 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 2 Aug 2023 15:47:17 -0400 Subject: [PATCH 23/49] Added an adapter between the IWallet defined in SequenceEthereum and the IWallet defined in SequenceWaaS. The adapter implements SequenceEthereum-IWallet using SequenceWaaS-IWallet as a dependency. Implemented the GetAddress adapter - note that since SequenceWaaS and SequenceEthereum have a different concept of what a wallet is, some of SequenceEthereum-IWallet may need to be modified slightly. For example: when implementing GetAddress, I've added an optional parameter to the method to specify the accountIndex as SequenceWaaS wallets can have multiple accounts/addresses while SequenceEthereum wallets have only one. --- .../SequenceSDK/Ethereum/Wallet/EthWallet.cs | 8 +- Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs | 2 +- .../SequenceSDK/WaaS/WaaSToWalletAdapter.cs | 86 +++++++++++++++++++ .../WaaS/WaaSToWalletAdapter.cs.meta | 3 + 4 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs create mode 100644 Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs.meta diff --git a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs index ef185b27..1f6268b7 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs @@ -12,6 +12,7 @@ using System.Numerics; using System.Threading.Tasks; using Sequence.Utils; +using UnityEngine; namespace Sequence.Wallet { @@ -56,8 +57,13 @@ private string GenerateAddress() return PubkeyToAddress(publicKeyBytes64); } - public Address GetAddress() + public Address GetAddress(uint accountIndex = 0) { + if (accountIndex != 0) + { + Debug.LogWarning("EthWallet has no concept of accountIndex. There is only one Address/account per EthWallet."); + } + if (address == null) { address = new Address(GenerateAddress()); diff --git a/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs b/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs index 426e884a..360b7e53 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs @@ -12,7 +12,7 @@ namespace Sequence.Wallet { public interface IWallet { - public Address GetAddress(); + public Address GetAddress(uint accountIndex = 0); public Task GetBalance(IEthClient client); public Task GetNonce(IEthClient client); public (string v, string r, string s) SignTransaction(byte[] message, string chainId); diff --git a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs new file mode 100644 index 00000000..8c5f8353 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs @@ -0,0 +1,86 @@ +using System.Collections.Generic; +using System.Numerics; +using System.Threading.Tasks; +using Sequence; +using Sequence.Provider; +using Sequence.WaaS; + +namespace SequenceSDK.WaaS +{ + public class WaaSToWalletAdapter : Sequence.Wallet.IWallet + { + private IWallet _wallet; + private Dictionary _walletAddressesByAccountIndex; + + private WaaSToWalletAdapter(IWallet wallet, Dictionary walletAddressesByAccountIndex) + { + _wallet = wallet; + _walletAddressesByAccountIndex = walletAddressesByAccountIndex; + } + + public static async Task CreateAsync(IWallet wallet, uint[] accountIndexes) + { + var walletAddressesByAccountIndex = new Dictionary(); + int accounts = accountIndexes.Length; + + for (int i = 0; i < accounts; i++) + { + var addressReturn = + await wallet.GetWalletAddress(new GetWalletAddressArgs(accountIndexes[i])); + walletAddressesByAccountIndex[accountIndexes[i]] = new Address(addressReturn.address); + } + + return new WaaSToWalletAdapter(wallet, walletAddressesByAccountIndex); + } + + public Address GetAddress(uint accountIndex = 0) + { + return _walletAddressesByAccountIndex[accountIndex]; + } + + public Task GetBalance(IEthClient client) + { + throw new System.NotImplementedException(); + } + + public Task GetNonce(IEthClient client) + { + throw new System.NotImplementedException(); + } + + public (string v, string r, string s) SignTransaction(byte[] message, string chainId) + { + throw new System.NotImplementedException(); + } + + public Task SendRawTransaction(IEthClient client, string signedTransactionData) + { + throw new System.NotImplementedException(); + } + + public Task SendRawTransactionAndWaitForReceipt(IEthClient client, string signedTransactionData) + { + throw new System.NotImplementedException(); + } + + public string SignMessage(byte[] message) + { + throw new System.NotImplementedException(); + } + + public string SignMessage(string message) + { + throw new System.NotImplementedException(); + } + + public bool IsValidSignature(string signature, string message) + { + throw new System.NotImplementedException(); + } + + public string Recover(string message, string signature) + { + throw new System.NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs.meta b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs.meta new file mode 100644 index 00000000..8af44b61 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 93a7d81ec3e94fdfa16022575ce72d9a +timeCreated: 1691002444 \ No newline at end of file From 7724479b49edf7c5e0b7ba2dab437e6629071f51 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Thu, 3 Aug 2023 08:56:42 -0400 Subject: [PATCH 24/49] Removed unneeded code, reducing network requests needed to send a contract transaction --- .../SequenceSDK/Ethereum/Contract/ContractTransactionSender.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Assets/SequenceSDK/Ethereum/Contract/ContractTransactionSender.cs b/Assets/SequenceSDK/Ethereum/Contract/ContractTransactionSender.cs index fbb7b106..7e5e93b5 100644 --- a/Assets/SequenceSDK/Ethereum/Contract/ContractTransactionSender.cs +++ b/Assets/SequenceSDK/Ethereum/Contract/ContractTransactionSender.cs @@ -20,7 +20,6 @@ public static async Task SendTransactionMethod( string functionName, params object[] functionArgs) { - BigInteger nonce = await wallet.GetNonce(client); ContractCall callingInfo = new ContractCall(wallet.GetAddress(), value); EthTransaction transaction = await contract.CallFunction(functionName, functionArgs)(client, callingInfo); string signedTransaction = transaction.SignAndEncodeTransaction(wallet); From b3869966a1fba7ad595496750fa4462c4c594e96 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Thu, 3 Aug 2023 08:57:11 -0400 Subject: [PATCH 25/49] Fully removed code that had been commented out --- Assets/SequenceSDK/Ethereum/Signer/EthSignature.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/SequenceSDK/Ethereum/Signer/EthSignature.cs b/Assets/SequenceSDK/Ethereum/Signer/EthSignature.cs index 3850e7e7..25de41d1 100644 --- a/Assets/SequenceSDK/Ethereum/Signer/EthSignature.cs +++ b/Assets/SequenceSDK/Ethereum/Signer/EthSignature.cs @@ -71,8 +71,8 @@ public static (string v, string r, string s) SignAndReturnVRS(byte[] hashedMessa signature.WriteToSpanCompact(sigHash64, out recId); signature.Deconstruct(out r, out s, out recId); BigInteger v = recId + chainId * 2 + 35; - R = r.ToBytes();//new BigInteger(1, r.ToBytes()).ToByteArrayUnsigned(); - S = s.ToBytes();//new BigInteger(1, s.ToBytes()).ToByteArrayUnsigned(); + R = r.ToBytes(); + S = s.ToBytes(); V = v.BigIntegerToHexString(); return GetSignatureForTransaction(); From e67a42860da222b8f1d505f6252e7994abb3969f Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Thu, 3 Aug 2023 09:17:41 -0400 Subject: [PATCH 26/49] Added an additional method implementation to WaaSToWalletAdapter.cs and ripped System.Linq out of another class. --- .../SequenceSDK/Ethereum/Tests/WalletTests.cs | 4 +- .../Ethereum/Utils/GenericHelpers.cs | 58 +++++++++++++++++++ .../Ethereum/Utils/GenericHelpers.cs.meta | 3 + .../SequenceSDK/Ethereum/Wallet/EthWallet.cs | 47 +++------------ Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs | 49 +++++++++++++--- .../SequenceSDK/Ethereum/Wallet/SignerTest.cs | 5 +- .../Ethereum/Wallet/TransactionSender.cs | 5 +- .../SequenceSDK/WaaS/WaaSToWalletAdapter.cs | 22 ++----- 8 files changed, 123 insertions(+), 70 deletions(-) create mode 100644 Assets/SequenceSDK/Ethereum/Utils/GenericHelpers.cs create mode 100644 Assets/SequenceSDK/Ethereum/Utils/GenericHelpers.cs.meta diff --git a/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs b/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs index 312028d5..ed6db38d 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs @@ -221,7 +221,7 @@ public void TestWalletRandom() } [Test] - public void TestWalletSignMessage() + public async Task TestWalletSignMessage() { EthWallet wallet = new EthWallet(); @@ -231,7 +231,7 @@ public void TestWalletSignMessage() string sig = wallet.SignMessage("hi"); Assert.NotNull(sig); - bool valid = wallet.IsValidSignature(sig, "hi"); + bool valid = await wallet.IsValidSignature(sig, "hi"); Assert.IsTrue(valid); } diff --git a/Assets/SequenceSDK/Ethereum/Utils/GenericHelpers.cs b/Assets/SequenceSDK/Ethereum/Utils/GenericHelpers.cs new file mode 100644 index 00000000..74b74fb6 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Utils/GenericHelpers.cs @@ -0,0 +1,58 @@ +using System; + +namespace SequenceSDK.Ethereum.Utils +{ + public static class GenericHelpers + { + public static T[] Take(this T[] source, int count) + { + if (source == null) + { + throw new ArgumentNullException(nameof(source)); + } + + if (count < 0) + { + throw new ArgumentOutOfRangeException(nameof(count), "Count must not be negative."); + } + + int actualCount = Math.Min(source.Length, count); + T[] result = new T[actualCount]; + + for (int i = 0; i < actualCount; i++) + { + result[i] = source[i]; + } + + return result; + } + + public static bool SequenceEqual(this T[] first, T[] second) + { + if (first == null) + { + throw new ArgumentNullException(nameof(first)); + } + + if (second == null) + { + throw new ArgumentNullException(nameof(second)); + } + + if (first.Length != second.Length) + { + return false; + } + + for (int i = 0; i < first.Length; i++) + { + if (!Equals(first[i], second[i])) + { + return false; + } + } + + return true; + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/Ethereum/Utils/GenericHelpers.cs.meta b/Assets/SequenceSDK/Ethereum/Utils/GenericHelpers.cs.meta new file mode 100644 index 00000000..9fff706d --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Utils/GenericHelpers.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3c1bdca7130945a59686db2b340e47eb +timeCreated: 1691067840 \ No newline at end of file diff --git a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs index 1f6268b7..7c1e1e53 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs @@ -54,7 +54,7 @@ private string GenerateAddress() Array.Copy(publickeyBytes, 1, publicKeyBytes64, 0, 64); - return PubkeyToAddress(publicKeyBytes64); + return IWallet.PubkeyToAddress(publicKeyBytes64); } public Address GetAddress(uint accountIndex = 0) @@ -170,15 +170,15 @@ public string SignByteArray(string privateKey, byte[] byteArray) /// The signature to verify. /// The message that was signed. /// true if the signature is valid, false otherwise. - public bool IsValidSignature(string signature, string message) + public async Task IsValidSignature(string signature, string message, uint accountIndex = 0, string chainId = "") { byte[] messagePrefix = PrefixedMessage(Encoding.UTF8.GetBytes(message)); byte[] hashedMessage = SequenceCoder.KeccakHash(messagePrefix); - SecpRecoverableECDSASignature recoverble = EthSignature.GetSignature(signature); + SecpRecoverableECDSASignature recoverable = EthSignature.GetSignature(signature); - if (recoverble != null) + if (recoverable != null) { - SecpECDSASignature sig = recoverble.ToSignature(); + SecpECDSASignature sig = recoverable.ToSignature(); return pubKey.SigVerify(sig, hashedMessage); } @@ -186,29 +186,6 @@ public bool IsValidSignature(string signature, string message) return false; } - /// - /// Recovers the Ethereum address from a message and its signature. - /// - /// The message that was signed. - /// The signature of the message. - /// The Ethereum address as a string. - public string Recover(string message, string signature) - { - byte[] messagePrefix = PrefixedMessage(Encoding.UTF8.GetBytes(message)); - byte[] hashedMessage = SequenceCoder.KeccakHash(messagePrefix); - - SecpRecoverableECDSASignature recoverble = EthSignature.GetSignature(signature); - ECPubKey _pubkey; - var ctx = Context.Instance; - ECPubKey.TryRecover(ctx, recoverble, hashedMessage, out _pubkey); - - byte[] publickeyBytes = _pubkey.ToBytes(false); - byte[] publicKeyBytes64 = new byte[64]; - Array.Copy(publickeyBytes, 1, publicKeyBytes64, 0, 64); //trim extra 0 at the beginning... - - return PubkeyToAddress(publicKeyBytes64); - } - /// /// Adds the Ethereum Signed Message prefix to a message. /// @@ -219,19 +196,9 @@ public static byte[] PrefixedMessage(byte[] message) return IWallet.PrefixedMessage(message); } - /// - /// Converts a public key to an Ethereum address. - /// - /// The public key byte array. - /// The Ethereum address derived from the public key. - private string PubkeyToAddress(byte[] pubkey) + public string Recover(string message, string signature) { - string hashed = SequenceCoder.ByteArrayToHexString(SequenceCoder.KeccakHash(pubkey)); - int length = hashed.Length; - string address = hashed.Substring(length - 40); - - address = SequenceCoder.AddressChecksum(address); - return address; + return IWallet.Recover(message, signature); } } } diff --git a/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs b/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs index 360b7e53..388815fe 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs @@ -1,11 +1,15 @@ +using System; using System.Collections; using System.Collections.Generic; -using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; +using NBitcoin.Secp256k1; using Sequence.ABI; +using Sequence.Extensions; using Sequence.Provider; +using Sequence.Signer; +using SequenceSDK.Ethereum.Utils; using UnityEngine; namespace Sequence.Wallet @@ -13,8 +17,6 @@ namespace Sequence.Wallet public interface IWallet { public Address GetAddress(uint accountIndex = 0); - public Task GetBalance(IEthClient client); - public Task GetNonce(IEthClient client); public (string v, string r, string s) SignTransaction(byte[] message, string chainId); public Task SendRawTransaction(IEthClient client, string signedTransactionData); public Task SendRawTransactionAndWaitForReceipt(IEthClient client, string signedTransactionData); @@ -48,8 +50,12 @@ public interface IWallet /// /// The signature to verify. /// The message that was signed. + /// + /// /// true if the signature is valid, false otherwise. - public bool IsValidSignature(string signature, string message); + public Task IsValidSignature(string signature, string message, uint accountIndex = 0, string chainId = ""); + + /// /// Recovers the Ethereum address from a message and its signature. @@ -57,8 +63,37 @@ public interface IWallet /// The message that was signed. /// The signature of the message. /// The Ethereum address as a string. - public string Recover(string message, string signature); + public static string Recover(string message, string signature) + { + byte[] messagePrefix = PrefixedMessage(Encoding.UTF8.GetBytes(message)); + byte[] hashedMessage = SequenceCoder.KeccakHash(messagePrefix); + + SecpRecoverableECDSASignature recoverble = EthSignature.GetSignature(signature); + ECPubKey _pubkey; + var ctx = Context.Instance; + ECPubKey.TryRecover(ctx, recoverble, hashedMessage, out _pubkey); + + byte[] publickeyBytes = _pubkey.ToBytes(false); + byte[] publicKeyBytes64 = new byte[64]; + Array.Copy(publickeyBytes, 1, publicKeyBytes64, 0, 64); //trim extra 0 at the beginning... + + return PubkeyToAddress(publicKeyBytes64); + } + /// + /// Converts a public key to an Ethereum address. + /// + /// The public key byte array. + /// The Ethereum address derived from the public key. + internal static string PubkeyToAddress(byte[] pubkey) + { + string hashed = SequenceCoder.ByteArrayToHexString(SequenceCoder.KeccakHash(pubkey)); + int length = hashed.Length; + string address = hashed.Substring(length - 40); + + address = SequenceCoder.AddressChecksum(address); + return address; + } /// /// Adds the Ethereum Signed Message prefix to a message. @@ -68,11 +103,11 @@ public interface IWallet public static byte[] PrefixedMessage(byte[] message) { // https://eips.ethereum.org/EIPS/eip-191 - byte[] message191 = SequenceCoder.HexStringToByteArray("19").Concat(Encoding.UTF8.GetBytes("Ethereum Signed Message:\n")).ToArray(); + byte[] message191 = ByteArrayExtensions.ConcatenateByteArrays(SequenceCoder.HexStringToByteArray("19"), Encoding.UTF8.GetBytes("Ethereum Signed Message:\n")); byte[] messageLen = Encoding.UTF8.GetBytes((message.Length).ToString()); if (!message.Take(message191.Length).SequenceEqual(message191)) { - message = (message191.Concat(messageLen).ToArray()).Concat((message)).ToArray(); + message = ByteArrayExtensions.ConcatenateByteArrays(message191, messageLen, message); } return message; diff --git a/Assets/SequenceSDK/Ethereum/Wallet/SignerTest.cs b/Assets/SequenceSDK/Ethereum/Wallet/SignerTest.cs index 112d4cd1..baaf977d 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/SignerTest.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/SignerTest.cs @@ -11,6 +11,7 @@ using Nethereum.Web3; using Nethereum.Util; using System.Collections.Generic; +using System.Threading.Tasks; using Nethereum.Signer; using Nethereum.Hex.HexConvertors.Extensions; using Nethereum.ABI.Encoders; @@ -19,7 +20,7 @@ public class SignerTest : MonoBehaviour { - private void Start() + private async Task Start() { EthWallet wallet = new EthWallet("b3c503217dbb0fae8950dadf73e2f500e968abddb95e22306ba95bbc7301cc01"); @@ -45,7 +46,7 @@ private void Start() string sig = wallet.SignMessage(testMessage); Debug.Log("signature: " + sig); - bool valid = wallet.IsValidSignature(sig, "this is a test"); + bool valid = await wallet.IsValidSignature(sig, "this is a test"); Debug.Log("isValid? :" + valid); //Recover diff --git a/Assets/SequenceSDK/Ethereum/Wallet/TransactionSender.cs b/Assets/SequenceSDK/Ethereum/Wallet/TransactionSender.cs index 546d8876..cee01c91 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/TransactionSender.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/TransactionSender.cs @@ -12,8 +12,9 @@ public static async Task SendTransaction(this IWallet fromWallet, IEthCl if (gasLimit == null) { GasLimitEstimator estimator = new GasLimitEstimator(client, fromWallet.GetAddress()); transaction = await estimator.BuildTransactionCreator(to, data, value, gasPrice)(); - }else { - BigInteger nonce = await fromWallet.GetNonce(client); + }else + { + BigInteger nonce = await client.NonceAt(fromWallet.GetAddress()); transaction = new EthTransaction(nonce, (BigInteger)gasPrice, (BigInteger)gasLimit, to, (BigInteger)value, data, chainId); } string tx = transaction.SignAndEncodeTransaction(fromWallet); diff --git a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs index 8c5f8353..32f2caee 100644 --- a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs +++ b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs @@ -4,6 +4,7 @@ using Sequence; using Sequence.Provider; using Sequence.WaaS; +using System; namespace SequenceSDK.WaaS { @@ -38,16 +39,6 @@ public Address GetAddress(uint accountIndex = 0) return _walletAddressesByAccountIndex[accountIndex]; } - public Task GetBalance(IEthClient client) - { - throw new System.NotImplementedException(); - } - - public Task GetNonce(IEthClient client) - { - throw new System.NotImplementedException(); - } - public (string v, string r, string s) SignTransaction(byte[] message, string chainId) { throw new System.NotImplementedException(); @@ -73,14 +64,11 @@ public string SignMessage(string message) throw new System.NotImplementedException(); } - public bool IsValidSignature(string signature, string message) - { - throw new System.NotImplementedException(); - } - - public string Recover(string message, string signature) + public async Task IsValidSignature(string signature, string message, uint accountIndex, string chainId) { - throw new System.NotImplementedException(); + var args = new IsValidMessageSignatureArgs(chainId, GetAddress(accountIndex), message, signature); + var result = await _wallet.IsValidMessageSignature(args); + return result.isValid; } } } \ No newline at end of file From a6c8057ee818461a0f7b02d0592b6d1923484e76 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Mon, 14 Aug 2023 16:56:38 -0400 Subject: [PATCH 27/49] Allow inclusion of chain Id when signing messages --- .../SequenceSDK/Ethereum/Tests/WalletTests.cs | 15 +++++++++++ .../SequenceSDK/Ethereum/Wallet/EthWallet.cs | 25 +++++++++++++++---- Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs | 4 +-- .../SequenceSDK/WaaS/WaaSToWalletAdapter.cs | 4 +-- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs b/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs index ed6db38d..c8d88477 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs @@ -235,6 +235,21 @@ public async Task TestWalletSignMessage() Assert.IsTrue(valid); } + [Test] + public async Task TestWalletSignMessageWithChainId() + { + EthWallet wallet = new EthWallet(); + + string address = wallet.GetAddress(); + Assert.NotNull(address); + + string sig = wallet.SignMessage("hi", "1"); + Assert.NotNull(sig); + + bool valid = await wallet.IsValidSignature(sig, "hi", chainId: "1"); + Assert.IsTrue(valid); + } + [Test] public void TestWalletSignMessageExistingPrefix() { diff --git a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs index 7c1e1e53..02313567 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs @@ -11,6 +11,7 @@ using System; using System.Numerics; using System.Threading.Tasks; +using Sequence.Extensions; using Sequence.Utils; using UnityEngine; @@ -116,8 +117,12 @@ public async Task SendRawTransactionAndWaitForReceipt(IEthCl /// /// The message to sign as a byte array. /// The signature as a string. - public string SignMessage(byte[] message) + public string SignMessage(byte[] message, byte[] chainId = null) { + if (chainId != null && chainId.Length > 0) + { + message = ByteArrayExtensions.ConcatenateByteArrays(message, chainId); + } byte[] message32 = SequenceCoder.KeccakHash(PrefixedMessage(message)); return EthSignature.Sign(message32, privKey); } @@ -128,10 +133,15 @@ public string SignMessage(byte[] message) /// /// The message to sign as a string. /// The signature as a string. - public string SignMessage(string message) + public string SignMessage(string message, string chainId = null) { byte[] messageBytes = Encoding.UTF8.GetBytes(message); - return SignMessage(messageBytes); + byte[] chainIdBytes = null; + if (chainId != null) + { + chainIdBytes = Encoding.UTF8.GetBytes(chainId); + } + return SignMessage(messageBytes, chainIdBytes); } /// @@ -140,7 +150,7 @@ public string SignMessage(string message) /// The private key as a hexadecimal string. /// The message to sign as a string. /// The signature as a string. - public string SignMessage(string privateKey, string message) + public string SignMessageWithPrivateKey(string privateKey, string message) { byte[] message32 = new byte[32]; message32 = SequenceCoder.KeccakHash(PrefixedMessage(Encoding.UTF8.GetBytes(message))); @@ -172,7 +182,12 @@ public string SignByteArray(string privateKey, byte[] byteArray) /// true if the signature is valid, false otherwise. public async Task IsValidSignature(string signature, string message, uint accountIndex = 0, string chainId = "") { - byte[] messagePrefix = PrefixedMessage(Encoding.UTF8.GetBytes(message)); + byte[] messageBytes = Encoding.UTF8.GetBytes(message); + if (chainId != null && chainId.Length > 0) + { + messageBytes = ByteArrayExtensions.ConcatenateByteArrays(messageBytes, Encoding.UTF8.GetBytes(chainId)); + } + byte[] messagePrefix = PrefixedMessage(messageBytes); byte[] hashedMessage = SequenceCoder.KeccakHash(messagePrefix); SecpRecoverableECDSASignature recoverable = EthSignature.GetSignature(signature); diff --git a/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs b/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs index 388815fe..f7072b82 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs @@ -36,14 +36,14 @@ public interface IWallet /// /// The message to sign as a byte array. /// The signature as a string. - public string SignMessage(byte[] message); + public string SignMessage(byte[] message, byte[] chainId = null); /// /// Signs a message with the wallet's private key. /// /// The message to sign as a string. /// The signature as a string. - public string SignMessage(string message); + public string SignMessage(string message, string chainId = null); /// /// Verifies the validity of a signature for a given message. diff --git a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs index 32f2caee..e0a32534 100644 --- a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs +++ b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs @@ -54,12 +54,12 @@ public Task SendRawTransactionAndWaitForReceipt(IEthClient c throw new System.NotImplementedException(); } - public string SignMessage(byte[] message) + public string SignMessage(byte[] message, byte[] chainId = null) { throw new System.NotImplementedException(); } - public string SignMessage(string message) + public string SignMessage(string message, string chainId = null) { throw new System.NotImplementedException(); } From e0581e3bb9143333aba5e0b343dd64343f66a364 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Tue, 15 Aug 2023 08:31:30 -0400 Subject: [PATCH 28/49] Sign messages as async method so that I could write the adapters for them --- .../SequenceSDK/Ethereum/Tests/WalletTests.cs | 16 ++++++------- .../SequenceSDK/Ethereum/Wallet/EthWallet.cs | 4 ++-- Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs | 4 ++-- .../SequenceSDK/Ethereum/Wallet/SignerTest.cs | 2 +- .../SequenceSDK/WaaS/WaaSToWalletAdapter.cs | 23 +++++++++++++++---- 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs b/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs index c8d88477..13f4da14 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs @@ -228,7 +228,7 @@ public async Task TestWalletSignMessage() string address = wallet.GetAddress(); Assert.NotNull(address); - string sig = wallet.SignMessage("hi"); + string sig = await wallet.SignMessage("hi"); Assert.NotNull(sig); bool valid = await wallet.IsValidSignature(sig, "hi"); @@ -243,7 +243,7 @@ public async Task TestWalletSignMessageWithChainId() string address = wallet.GetAddress(); Assert.NotNull(address); - string sig = wallet.SignMessage("hi", "1"); + string sig = await wallet.SignMessage("hi", "1"); Assert.NotNull(sig); bool valid = await wallet.IsValidSignature(sig, "hi", chainId: "1"); @@ -251,7 +251,7 @@ public async Task TestWalletSignMessageWithChainId() } [Test] - public void TestWalletSignMessageExistingPrefix() + public async Task TestWalletSignMessageExistingPrefix() { EthWallet wallet = new EthWallet("b3c503217dbb0fae8950dadf73e2f500e968abddb95e22306ba95bbc7301cc01"); CollectionAssert.AreEqual(SequenceCoder.HexStringToByteArray("b3c503217dbb0fae8950dadf73e2f500e968abddb95e22306ba95bbc7301cc01"), wallet.privKey.sec.ToBytes()); @@ -262,13 +262,13 @@ public void TestWalletSignMessageExistingPrefix() byte[] _19 = SequenceCoder.HexStringToByteArray("19"); byte[] testMessage = Encoding.ASCII.GetBytes("Ethereum Signed Message:\n" +"this is a test".Length + "this is a test"); testMessage = _19.Concat(testMessage).ToArray(); - string sig = wallet.SignMessage(testMessage); + string sig = await wallet.SignMessage(testMessage); Assert.AreEqual("0x45c666ac1fc5faae5639014d2c163c1ac4863fb78a4bd23c3785f7db99cf553666191da4cad5968d018287e784ceabc7f5565b5375a4b7e35cba897d0b666f0f1b", sig); } [Test] - public void TestWalletSignMessageFromPrivateKey() + public async Task TestWalletSignMessageFromPrivateKey() { EthWallet wallet = new EthWallet("b3c503217dbb0fae8950dadf73e2f500e968abddb95e22306ba95bbc7301cc01"); @@ -280,14 +280,14 @@ public void TestWalletSignMessageFromPrivateKey() byte[] testMessage = Encoding.ASCII.GetBytes("this is a test"); - string sig = wallet.SignMessage(testMessage); + string sig = await wallet.SignMessage(testMessage); Assert.AreEqual("0x45c666ac1fc5faae5639014d2c163c1ac4863fb78a4bd23c3785f7db99cf553666191da4cad5968d018287e784ceabc7f5565b5375a4b7e35cba897d0b666f0f1b", sig); } [Test] - public void TestWalletSignAndRecover() + public async Task TestWalletSignAndRecover() { EthWallet wallet = new EthWallet("b3c503217dbb0fae8950dadf73e2f500e968abddb95e22306ba95bbc7301cc01"); CollectionAssert.AreEqual(SequenceCoder.HexStringToByteArray("b3c503217dbb0fae8950dadf73e2f500e968abddb95e22306ba95bbc7301cc01"), wallet.privKey.sec.ToBytes()); @@ -298,7 +298,7 @@ public void TestWalletSignAndRecover() byte[] testMessage = Encoding.ASCII.GetBytes("this is a test"); - string sig = wallet.SignMessage(testMessage); + string sig = await wallet.SignMessage(testMessage); string recoveredAddr = wallet.Recover("this is a test", sig); diff --git a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs index 02313567..2c2aa292 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs @@ -117,7 +117,7 @@ public async Task SendRawTransactionAndWaitForReceipt(IEthCl /// /// The message to sign as a byte array. /// The signature as a string. - public string SignMessage(byte[] message, byte[] chainId = null) + public async Task SignMessage(byte[] message, byte[] chainId = null) { if (chainId != null && chainId.Length > 0) { @@ -133,7 +133,7 @@ public string SignMessage(byte[] message, byte[] chainId = null) /// /// The message to sign as a string. /// The signature as a string. - public string SignMessage(string message, string chainId = null) + public Task SignMessage(string message, string chainId = null) { byte[] messageBytes = Encoding.UTF8.GetBytes(message); byte[] chainIdBytes = null; diff --git a/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs b/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs index f7072b82..b5641967 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs @@ -36,14 +36,14 @@ public interface IWallet /// /// The message to sign as a byte array. /// The signature as a string. - public string SignMessage(byte[] message, byte[] chainId = null); + public Task SignMessage(byte[] message, byte[] chainId = null); /// /// Signs a message with the wallet's private key. /// /// The message to sign as a string. /// The signature as a string. - public string SignMessage(string message, string chainId = null); + public Task SignMessage(string message, string chainId = null); /// /// Verifies the validity of a signature for a given message. diff --git a/Assets/SequenceSDK/Ethereum/Wallet/SignerTest.cs b/Assets/SequenceSDK/Ethereum/Wallet/SignerTest.cs index baaf977d..90536690 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/SignerTest.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/SignerTest.cs @@ -43,7 +43,7 @@ private async Task Start() byte[] testMessage = Encoding.ASCII.GetBytes("this is a test"); - string sig = wallet.SignMessage(testMessage); + string sig = await wallet.SignMessage(testMessage); Debug.Log("signature: " + sig); bool valid = await wallet.IsValidSignature(sig, "this is a test"); diff --git a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs index e0a32534..c40a6a9f 100644 --- a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs +++ b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs @@ -5,6 +5,8 @@ using Sequence.Provider; using Sequence.WaaS; using System; +using Sequence.ABI; +using Sequence.Extensions; namespace SequenceSDK.WaaS { @@ -54,14 +56,27 @@ public Task SendRawTransactionAndWaitForReceipt(IEthClient c throw new System.NotImplementedException(); } - public string SignMessage(byte[] message, byte[] chainId = null) + public async Task SignMessage(byte[] message, byte[] chainId = null) { - throw new System.NotImplementedException(); + string messageString = SequenceCoder.HexStringToHumanReadable(SequenceCoder.ByteArrayToHexString(message)); + string chainIdString = + SequenceCoder.HexStringToHumanReadable(SequenceCoder.ByteArrayToHexString(chainId)); + + return await SignMessage(messageString, chainIdString); } - public string SignMessage(string message, string chainId = null) + public async Task SignMessage(string message, string chainId = null) { - throw new System.NotImplementedException(); + if (uint.TryParse(chainId, out uint chain)) + { + SignMessageArgs args = new SignMessageArgs(chain, GetAddress(), message); + var result = await _wallet.SignMessage(args); + return result.signature; + } + else + { + throw new ArgumentException($"{nameof(chainId)} must be parseable to an {typeof(uint)}, given: {chainId}"); + } } public async Task IsValidSignature(string signature, string message, uint accountIndex, string chainId) From d325fd0926079dc8eb5d1751e8a119aa3aa64984 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Tue, 15 Aug 2023 13:33:52 -0400 Subject: [PATCH 29/49] Added base WaaSWallet implementation - still requires constructor, but it is not yet clear where the wallet address (which as I understand will be used in auth) comes from --- Assets/SequenceSDK/WaaS/HttpClient.cs | 61 ++++++++++++++ Assets/SequenceSDK/WaaS/HttpClient.cs.meta | 3 + Assets/SequenceSDK/WaaS/WaaSWallet.cs | 97 ++++++++++++++++++++++ Assets/SequenceSDK/WaaS/WaaSWallet.cs.meta | 3 + 4 files changed, 164 insertions(+) create mode 100644 Assets/SequenceSDK/WaaS/HttpClient.cs create mode 100644 Assets/SequenceSDK/WaaS/HttpClient.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/WaaSWallet.cs create mode 100644 Assets/SequenceSDK/WaaS/WaaSWallet.cs.meta diff --git a/Assets/SequenceSDK/WaaS/HttpClient.cs b/Assets/SequenceSDK/WaaS/HttpClient.cs new file mode 100644 index 00000000..d409b115 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/HttpClient.cs @@ -0,0 +1,61 @@ +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using JetBrains.Annotations; +using Newtonsoft.Json; +using Sequence.Provider; +using UnityEngine; +using UnityEngine.Networking; + +namespace SequenceSDK.WaaS +{ + public class HttpClient + { + private readonly string _url; + private Dictionary _defaultHeaders; + + public HttpClient(string url, string partnerId, string wallet) + { + this._url = url; + this._defaultHeaders = new Dictionary(); + this._defaultHeaders["partner_id"] = partnerId; + this._defaultHeaders["wallet"] = wallet; + } + + public async Task SendRequest(T args, [CanBeNull] Dictionary headers = null) + { + string requestJson = JsonConvert.SerializeObject(args); + UnityWebRequest request = UnityWebRequest.Post(_url, requestJson); + request.SetRequestHeader("Content-Type", "application/json"); + request.SetRequestHeader("Accept", "application/json"); + request.method = UnityWebRequest.kHttpVerbPOST; + + if (headers == null) + { + headers = _defaultHeaders; + } + + foreach (string key in headers.Keys) + { + request.SetRequestHeader(key, headers[key]); + } + + await request.SendWebRequest(); + + if (request.error != null || request.result != UnityWebRequest.Result.Success) + { + Debug.Log($"Error sending request to {_url} with args {args}: {request.error}"); + request.Dispose(); + return default; + } + else + { + byte[] results = request.downloadHandler.data; + var responseJson = Encoding.UTF8.GetString(results); + T2 result = JsonConvert.DeserializeObject(responseJson); + request.Dispose(); + return result; + } + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/HttpClient.cs.meta b/Assets/SequenceSDK/WaaS/HttpClient.cs.meta new file mode 100644 index 00000000..f35b968c --- /dev/null +++ b/Assets/SequenceSDK/WaaS/HttpClient.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 908f66a3a95e4949b0b87bd7ffc90763 +timeCreated: 1692105075 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/WaaSWallet.cs b/Assets/SequenceSDK/WaaS/WaaSWallet.cs new file mode 100644 index 00000000..b7a69189 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/WaaSWallet.cs @@ -0,0 +1,97 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Sequence; +using Sequence.WaaS; + +namespace SequenceSDK.WaaS +{ + public class WaaSWallet : IWallet + { + private HttpClient _httpClient; + + public Task CreatePartner(CreatePartnerArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest(args, headers); + } + + public Task UpdatePartner(UpdatePartnerArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest(args, headers); + } + + public Task CreatePartnerWalletConfig(CreatePartnerWalletConfigArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest(args, headers); + } + + public Task PartnerWalletConfig(PartnerWalletConfigArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest(args, headers); + } + + public Task DeployPartnerParentWallet(DeployPartnerParentWalletArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest(args, headers); + } + + public Task AddPartnerWalletSigner(AddPartnerWalletSignerArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest(args, headers); + } + + public Task RemovePartnerWalletSigner(RemovePartnerWalletSignerArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest(args, headers); + } + + public Task ListPartnerWalletSigners(ListPartnerWalletSignersArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest(args, headers); + } + + public Task PartnerWallets(PartnerWalletsArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest(args, headers); + } + + public Task CreateWallet(CreateWalletArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest(args, headers); + } + + public Task GetWalletAddress(GetWalletAddressArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest(args, headers); + } + + public Task DeployWallet(DeployWalletArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest(args, headers); + } + + public Task Wallets(WalletsArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest(args, headers); + } + + public Task SignMessage(SignMessageArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest(args, headers); + } + + public Task IsValidMessageSignature(IsValidMessageSignatureArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest(args, headers); + } + + public Task SendTransaction(SendTransactionArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest(args, headers); + } + + public Task SendTransactionBatch(SendTransactionBatchArgs args, Dictionary headers = null) + { + return _httpClient.SendRequest(args, headers); + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/WaaSWallet.cs.meta b/Assets/SequenceSDK/WaaS/WaaSWallet.cs.meta new file mode 100644 index 00000000..eaa3390f --- /dev/null +++ b/Assets/SequenceSDK/WaaS/WaaSWallet.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ccddaf66dce94c7eb4dcd85880e98a3f +timeCreated: 1692104890 \ No newline at end of file From 2b3305b53f8ffe3fa833ee38e988777f8dc3302a Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 16 Aug 2023 14:16:18 -0400 Subject: [PATCH 30/49] Create WaaSWallet using JWT --- .../ReturnTypes/GetWalletAddressReturn.cs | 5 +++ Assets/SequenceSDK/WaaS/HttpClient.cs | 9 +++-- Assets/SequenceSDK/WaaS/JwtHelper.cs | 40 +++++++++++++++++++ Assets/SequenceSDK/WaaS/JwtHelper.cs.meta | 3 ++ Assets/SequenceSDK/WaaS/WaaSWallet.cs | 14 ++++++- 5 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 Assets/SequenceSDK/WaaS/JwtHelper.cs create mode 100644 Assets/SequenceSDK/WaaS/JwtHelper.cs.meta diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/GetWalletAddressReturn.cs b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/GetWalletAddressReturn.cs index e72d3c48..8a7d030e 100644 --- a/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/GetWalletAddressReturn.cs +++ b/Assets/SequenceSDK/WaaS/DataTypes/ReturnTypes/GetWalletAddressReturn.cs @@ -4,5 +4,10 @@ namespace Sequence.WaaS public class GetWalletAddressReturn { public string address; + + public GetWalletAddressReturn(string address) + { + this.address = address; + } } } \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/HttpClient.cs b/Assets/SequenceSDK/WaaS/HttpClient.cs index d409b115..e263aa88 100644 --- a/Assets/SequenceSDK/WaaS/HttpClient.cs +++ b/Assets/SequenceSDK/WaaS/HttpClient.cs @@ -14,12 +14,15 @@ public class HttpClient private readonly string _url; private Dictionary _defaultHeaders; - public HttpClient(string url, string partnerId, string wallet) + public HttpClient(string url) { this._url = url; this._defaultHeaders = new Dictionary(); - this._defaultHeaders["partner_id"] = partnerId; - this._defaultHeaders["wallet"] = wallet; + } + + public void AddDefaultHeader(string key, string value) + { + this._defaultHeaders[key] = value; } public async Task SendRequest(T args, [CanBeNull] Dictionary headers = null) diff --git a/Assets/SequenceSDK/WaaS/JwtHelper.cs b/Assets/SequenceSDK/WaaS/JwtHelper.cs new file mode 100644 index 00000000..e610944a --- /dev/null +++ b/Assets/SequenceSDK/WaaS/JwtHelper.cs @@ -0,0 +1,40 @@ +using System; +using Sequence; +using UnityEngine; + +namespace SequenceSDK.WaaS +{ + public static class JwtHelper + { + [Serializable] + private class JwtPayload + { + public int partner_id; + public string wallet; + } + + public static Address GetWalletAddressFromJwt(string jwtToken) + { + string[] parts = jwtToken.Split('.'); + if (parts.Length != 3) + { + throw new ArgumentException("Invalid JWT format"); + } + + byte[] payloadBytes = Convert.FromBase64String(parts[1]); + string payloadJson = System.Text.Encoding.UTF8.GetString(payloadBytes); + + JwtPayload payload; + try + { + payload = JsonUtility.FromJson(payloadJson); + } + catch (Exception ex) + { + throw new Exception("JWT payload decoding failed: " + ex.Message); + } + + return new Address(payload.wallet); + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/JwtHelper.cs.meta b/Assets/SequenceSDK/WaaS/JwtHelper.cs.meta new file mode 100644 index 00000000..89a587e8 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/JwtHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4232ed06fe74437182e8443f8c18bd42 +timeCreated: 1692208523 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/WaaSWallet.cs b/Assets/SequenceSDK/WaaS/WaaSWallet.cs index b7a69189..044399b6 100644 --- a/Assets/SequenceSDK/WaaS/WaaSWallet.cs +++ b/Assets/SequenceSDK/WaaS/WaaSWallet.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Threading.Tasks; +using NUnit.Framework.Internal; using Sequence; using Sequence.WaaS; @@ -8,7 +9,15 @@ namespace SequenceSDK.WaaS public class WaaSWallet : IWallet { private HttpClient _httpClient; - + private Address _address; + + public WaaSWallet(HttpClient client, string jwt) + { + this._httpClient = client; + this._address = JwtHelper.GetWalletAddressFromJwt(jwt); + this._httpClient.AddDefaultHeader("Authorization", $"Bearer {jwt}"); + } + public Task CreatePartner(CreatePartnerArgs args, Dictionary headers = null) { return _httpClient.SendRequest(args, headers); @@ -61,7 +70,8 @@ public Task CreateWallet(CreateWalletArgs args, Dictionary GetWalletAddress(GetWalletAddressArgs args, Dictionary headers = null) { - return _httpClient.SendRequest(args, headers); + GetWalletAddressReturn result = new GetWalletAddressReturn(this._address.Value); + return Task.FromResult(result); } public Task DeployWallet(DeployWalletArgs args, Dictionary headers = null) From 566aa05097459ade44eb92a9cff33f4e60d0df3a Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 16 Aug 2023 16:26:41 -0400 Subject: [PATCH 31/49] Fixed namespaces for WaaS. Added URL for WaaS service. Added tests for getting wallet addressfrom jwt and fixed implementation --- .../{Tests.asmdef => SequenceTests.asmdef} | 3 ++- ....asmdef.meta => SequenceTests.asmdef.meta} | 0 Assets/SequenceSDK/WaaS/HttpClient.cs | 7 +++---- Assets/SequenceSDK/WaaS/IWallet.cs | 2 +- Assets/SequenceSDK/WaaS/JwtHelper.cs | 21 ++++++++++++++++--- Assets/SequenceSDK/WaaS/Tests.meta | 3 +++ .../SequenceSDK/WaaS/Tests/JwtHelperTests.cs | 20 ++++++++++++++++++ .../WaaS/Tests/JwtHelperTests.cs.meta | 3 +++ Assets/SequenceSDK/WaaS/Tests/Tests.asmref | 3 +++ .../SequenceSDK/WaaS/Tests/Tests.asmref.meta | 7 +++++++ .../SequenceSDK/WaaS/WaaSToWalletAdapter.cs | 2 +- Assets/SequenceSDK/WaaS/WaaSWallet.cs | 2 +- 12 files changed, 62 insertions(+), 11 deletions(-) rename Assets/SequenceSDK/Ethereum/Tests/{Tests.asmdef => SequenceTests.asmdef} (86%) rename Assets/SequenceSDK/Ethereum/Tests/{Tests.asmdef.meta => SequenceTests.asmdef.meta} (100%) create mode 100644 Assets/SequenceSDK/WaaS/Tests.meta create mode 100644 Assets/SequenceSDK/WaaS/Tests/JwtHelperTests.cs create mode 100644 Assets/SequenceSDK/WaaS/Tests/JwtHelperTests.cs.meta create mode 100644 Assets/SequenceSDK/WaaS/Tests/Tests.asmref create mode 100644 Assets/SequenceSDK/WaaS/Tests/Tests.asmref.meta diff --git a/Assets/SequenceSDK/Ethereum/Tests/Tests.asmdef b/Assets/SequenceSDK/Ethereum/Tests/SequenceTests.asmdef similarity index 86% rename from Assets/SequenceSDK/Ethereum/Tests/Tests.asmdef rename to Assets/SequenceSDK/Ethereum/Tests/SequenceTests.asmdef index 8ca88cb5..e4e5b009 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/Tests.asmdef +++ b/Assets/SequenceSDK/Ethereum/Tests/SequenceTests.asmdef @@ -4,7 +4,8 @@ "references": [ "GUID:27619889b8ba8c24980f49ee34dbb44a", "GUID:0acc523941302664db1f4e527237feb3", - "GUID:f7fd4ba36aabd1d499450c174865e70b" + "GUID:f7fd4ba36aabd1d499450c174865e70b", + "GUID:4e0a798abbda240658187632ae443a67" ], "includePlatforms": [ "Editor" diff --git a/Assets/SequenceSDK/Ethereum/Tests/Tests.asmdef.meta b/Assets/SequenceSDK/Ethereum/Tests/SequenceTests.asmdef.meta similarity index 100% rename from Assets/SequenceSDK/Ethereum/Tests/Tests.asmdef.meta rename to Assets/SequenceSDK/Ethereum/Tests/SequenceTests.asmdef.meta diff --git a/Assets/SequenceSDK/WaaS/HttpClient.cs b/Assets/SequenceSDK/WaaS/HttpClient.cs index e263aa88..88f87832 100644 --- a/Assets/SequenceSDK/WaaS/HttpClient.cs +++ b/Assets/SequenceSDK/WaaS/HttpClient.cs @@ -7,16 +7,15 @@ using UnityEngine; using UnityEngine.Networking; -namespace SequenceSDK.WaaS +namespace Sequence.WaaS { public class HttpClient { - private readonly string _url; + private readonly string _url = "https://next-api.sequence.app/rpc/Wallet"; private Dictionary _defaultHeaders; - public HttpClient(string url) + public HttpClient() { - this._url = url; this._defaultHeaders = new Dictionary(); } diff --git a/Assets/SequenceSDK/WaaS/IWallet.cs b/Assets/SequenceSDK/WaaS/IWallet.cs index ec87480b..f55a2106 100644 --- a/Assets/SequenceSDK/WaaS/IWallet.cs +++ b/Assets/SequenceSDK/WaaS/IWallet.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using Sequence.WaaS; -namespace SequenceSDK.WaaS +namespace Sequence.WaaS { public interface IWallet { diff --git a/Assets/SequenceSDK/WaaS/JwtHelper.cs b/Assets/SequenceSDK/WaaS/JwtHelper.cs index e610944a..d648225d 100644 --- a/Assets/SequenceSDK/WaaS/JwtHelper.cs +++ b/Assets/SequenceSDK/WaaS/JwtHelper.cs @@ -1,8 +1,10 @@ using System; +using System.Text; +using System.Web; using Sequence; using UnityEngine; -namespace SequenceSDK.WaaS +namespace Sequence.WaaS { public static class JwtHelper { @@ -21,8 +23,9 @@ public static Address GetWalletAddressFromJwt(string jwtToken) throw new ArgumentException("Invalid JWT format"); } - byte[] payloadBytes = Convert.FromBase64String(parts[1]); - string payloadJson = System.Text.Encoding.UTF8.GetString(payloadBytes); + string payloadBase64 = PadToBase64(parts[1]); + byte[] payloadBytes = Convert.FromBase64String(payloadBase64); + string payloadJson = Encoding.UTF8.GetString(payloadBytes); JwtPayload payload; try @@ -36,5 +39,17 @@ public static Address GetWalletAddressFromJwt(string jwtToken) return new Address(payload.wallet); } + + private static string PadToBase64(string value) + { + int length = value.Length; + int padLength = 4 - length % 4; + if (padLength < 4) + { + value += new string('=', padLength); + } + + return value; + } } } \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/Tests.meta b/Assets/SequenceSDK/WaaS/Tests.meta new file mode 100644 index 00000000..bc1447f7 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/Tests.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 698b2ff86c874f22b8005416113e63bb +timeCreated: 1692215014 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/Tests/JwtHelperTests.cs b/Assets/SequenceSDK/WaaS/Tests/JwtHelperTests.cs new file mode 100644 index 00000000..78ad1a81 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/Tests/JwtHelperTests.cs @@ -0,0 +1,20 @@ +using NUnit.Framework; +using Sequence; +using Sequence.WaaS; + +namespace Sequence.WaaS.Tests +{ + public class JwtHelperTests + { + [TestCase("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXJ0bmVyX2lkIjoyLCJ3YWxsZXQiOiIweDY2MDI1MDczNGYzMTY0NDY4MWFlMzJkMDViZDdlOGUyOWZlYTI5ZTEifQ.FC8WmaC_hW4svdrs4rxyKcvoekfVYFkFFvGwUOXzcHA", "0x660250734f31644681ae32d05bd7e8e29fea29e1")] + [TestCase("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXJ0bmVyX2lkIjoxLCJ3YWxsZXQiOiIweGE2MDI1MDczNGYzMTY0NDY4MWFlMzJkMDViZDdlOGUyOWZlYTI5ZTEifQ.SgaUaoHJhKwYTNWdMKlKRC_Hj27Kqovv3qI7Ky-TBkg", "0xa60250734f31644681ae32d05bd7e8e29fea29e1")] + [TestCase("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXJ0bmVyX2lkIjoxMDAwMDAsIndhbGxldCI6IjB4YTYwMjUwNzM0ZjMxNjQ0NjgxYWUzMmQwNWJkN2U4ZTI5ZmVhMjllMSJ9.CmBaisrov_AST9tgtfDcO58lh2t63CxAcyd0SUCYIJc", "0xa60250734f31644681ae32d05bd7e8e29fea29e1")] + [TestCase("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXJ0bmVyX2lkIjoyLCJ3YWxsZXQiOiIweDY2MDI1MDczNGYzMTY0NDY4MWFlMzJkMDViZDdlOGUyOWZlYWFhZTEifQ.IAT79FXnsMreAEuC7eGyaW3X-xWnL6Vul9qA1SBU7eA", "0x660250734f31644681ae32d05bd7e8e29feaaae1")] + [TestCase("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXJ0bmVyX2lkIjoxMDAwMDAwMDAwMDAwMDAwMDAsIndhbGxldCI6IjB4NjYwMjUwNzM0ZjMxNjQ0NjgxYWUzMmQwNWJkN2U4ZTI5ZmVhMjllMSJ9.CGAzQj-qT2mwuJ8Z6h9dMf1ubh7bAf17iBH3xRzmLnk", "0x660250734f31644681ae32d05bd7e8e29fea29e1")] + public void TestGetWalletAddressFromJwt(string jwt, string expected) + { + Address result = JwtHelper.GetWalletAddressFromJwt(jwt); + Assert.AreEqual(expected, result.Value); + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/Tests/JwtHelperTests.cs.meta b/Assets/SequenceSDK/WaaS/Tests/JwtHelperTests.cs.meta new file mode 100644 index 00000000..93b12a2a --- /dev/null +++ b/Assets/SequenceSDK/WaaS/Tests/JwtHelperTests.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8c90ce6d5000444c904507c0cb42763e +timeCreated: 1692215027 \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/Tests/Tests.asmref b/Assets/SequenceSDK/WaaS/Tests/Tests.asmref new file mode 100644 index 00000000..f84259e6 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/Tests/Tests.asmref @@ -0,0 +1,3 @@ +{ + "reference": "GUID:e22769e76116a7e4b8fac61caa6c07d7" +} \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/Tests/Tests.asmref.meta b/Assets/SequenceSDK/WaaS/Tests/Tests.asmref.meta new file mode 100644 index 00000000..adc96851 --- /dev/null +++ b/Assets/SequenceSDK/WaaS/Tests/Tests.asmref.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: c5941decd329f485bb9b936611ed57a6 +AssemblyDefinitionReferenceImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs index c40a6a9f..e07c84ce 100644 --- a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs +++ b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs @@ -8,7 +8,7 @@ using Sequence.ABI; using Sequence.Extensions; -namespace SequenceSDK.WaaS +namespace Sequence.WaaS { public class WaaSToWalletAdapter : Sequence.Wallet.IWallet { diff --git a/Assets/SequenceSDK/WaaS/WaaSWallet.cs b/Assets/SequenceSDK/WaaS/WaaSWallet.cs index 044399b6..1bf48070 100644 --- a/Assets/SequenceSDK/WaaS/WaaSWallet.cs +++ b/Assets/SequenceSDK/WaaS/WaaSWallet.cs @@ -4,7 +4,7 @@ using Sequence; using Sequence.WaaS; -namespace SequenceSDK.WaaS +namespace Sequence.WaaS { public class WaaSWallet : IWallet { From 391f6d53588e0dfe29a8cc02443b8af0ebcccdf3 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 16 Aug 2023 16:32:55 -0400 Subject: [PATCH 32/49] Don't require an httpclient to create a WaaSWallet - WaaSWallet can create this as it doesn't need any parameters --- Assets/SequenceSDK/WaaS/WaaSWallet.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Assets/SequenceSDK/WaaS/WaaSWallet.cs b/Assets/SequenceSDK/WaaS/WaaSWallet.cs index 1bf48070..ecaec78a 100644 --- a/Assets/SequenceSDK/WaaS/WaaSWallet.cs +++ b/Assets/SequenceSDK/WaaS/WaaSWallet.cs @@ -1,8 +1,5 @@ using System.Collections.Generic; using System.Threading.Tasks; -using NUnit.Framework.Internal; -using Sequence; -using Sequence.WaaS; namespace Sequence.WaaS { @@ -11,9 +8,9 @@ public class WaaSWallet : IWallet private HttpClient _httpClient; private Address _address; - public WaaSWallet(HttpClient client, string jwt) + public WaaSWallet(string jwt) { - this._httpClient = client; + this._httpClient = new HttpClient(); this._address = JwtHelper.GetWalletAddressFromJwt(jwt); this._httpClient.AddDefaultHeader("Authorization", $"Bearer {jwt}"); } From 0327ef05b13f7b23ba2ff8554d22e5e4d47d897c Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 16 Aug 2023 16:58:14 -0400 Subject: [PATCH 33/49] Modify wallet interface such that signing transactions and sending raw transactions is replaced with send EthTransaction --- .../Ethereum/Contract/ContractDeployer.cs | 3 +-- .../Contract/ContractTransactionSender.cs | 6 ++--- .../SequenceSDK/Ethereum/Tests/WalletTests.cs | 3 +-- .../Ethereum/Transaction/EthTransaction.cs | 2 +- .../SequenceSDK/Ethereum/Wallet/EthWallet.cs | 23 ++++++++++++------- Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs | 6 ++--- .../Ethereum/Wallet/TransactionSender.cs | 3 +-- .../SequenceSDK/WaaS/WaaSToWalletAdapter.cs | 14 ++++------- 8 files changed, 29 insertions(+), 31 deletions(-) diff --git a/Assets/SequenceSDK/Ethereum/Contract/ContractDeployer.cs b/Assets/SequenceSDK/Ethereum/Contract/ContractDeployer.cs index 57b99cdd..5cbcc2f9 100644 --- a/Assets/SequenceSDK/Ethereum/Contract/ContractDeployer.cs +++ b/Assets/SequenceSDK/Ethereum/Contract/ContractDeployer.cs @@ -20,8 +20,7 @@ public static async Task Deploy( BigInteger? gasLimit = null) { EthTransaction deployTransaction = await new GasLimitEstimator(client, wallet.GetAddress()).BuildTransaction(StringExtensions.ZeroAddress, bytecode, 0, gasPrice, gasLimit); - string signedTransaction = deployTransaction.SignAndEncodeTransaction(wallet); - TransactionReceipt receipt = await wallet.SendRawTransactionAndWaitForReceipt(client, signedTransaction); + TransactionReceipt receipt = await wallet.SendTransactionAndWaitForReceipt(client, deployTransaction); return receipt; } } diff --git a/Assets/SequenceSDK/Ethereum/Contract/ContractTransactionSender.cs b/Assets/SequenceSDK/Ethereum/Contract/ContractTransactionSender.cs index 7e5e93b5..6e55fe59 100644 --- a/Assets/SequenceSDK/Ethereum/Contract/ContractTransactionSender.cs +++ b/Assets/SequenceSDK/Ethereum/Contract/ContractTransactionSender.cs @@ -22,8 +22,7 @@ public static async Task SendTransactionMethod( { ContractCall callingInfo = new ContractCall(wallet.GetAddress(), value); EthTransaction transaction = await contract.CallFunction(functionName, functionArgs)(client, callingInfo); - string signedTransaction = transaction.SignAndEncodeTransaction(wallet); - string result = await wallet.SendRawTransaction(client, signedTransaction); + string result = await wallet.SendTransaction(client, transaction); return result; } @@ -47,8 +46,7 @@ public static async Task SendTransactionMethod( BigInteger? value = null) { EthTransaction transaction = await transactionCreator(client, new ContractCall(wallet.GetAddress(), value)); - string signedTransaction = transaction.SignAndEncodeTransaction(wallet); - string result = await wallet.SendRawTransaction(client, signedTransaction); + string result = await wallet.SendTransaction(client, transaction); return result; } diff --git a/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs b/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs index 13f4da14..41a325c0 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs @@ -89,8 +89,7 @@ public async Task TestChain_TransactionTests() string to = "0x1099542D7dFaF6757527146C0aB9E70A967f71C0"; BigInteger value = 12300000000; EthTransaction transaction = await new GasLimitEstimator(client, wallet.GetAddress()).BuildTransaction(to, null, value); - string tx = transaction.SignAndEncodeTransaction(wallet); - string result = await wallet.SendRawTransaction(client, tx); + string result = await wallet.SendTransaction(client, transaction); Assert.IsNotEmpty(result); await client.WaitForTransactionReceipt(result); // Not waiting for the transaction to process will cause the next tests to fail as they would be submitting a duplicate transaction diff --git a/Assets/SequenceSDK/Ethereum/Transaction/EthTransaction.cs b/Assets/SequenceSDK/Ethereum/Transaction/EthTransaction.cs index 58c011de..092fdc9b 100644 --- a/Assets/SequenceSDK/Ethereum/Transaction/EthTransaction.cs +++ b/Assets/SequenceSDK/Ethereum/Transaction/EthTransaction.cs @@ -132,7 +132,7 @@ public static void ValidateParams( } } - public string SignAndEncodeTransaction(IWallet wallet) + public string SignAndEncodeTransaction(EthWallet wallet) { string encoded_signing = this.RLPEncode(); string signingHash = SequenceCoder.KeccakHash(encoded_signing).EnsureHexPrefix(); diff --git a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs index 2c2aa292..5def98dc 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs @@ -12,6 +12,7 @@ using System.Numerics; using System.Threading.Tasks; using Sequence.Extensions; +using Sequence.Transactions; using Sequence.Utils; using UnityEngine; @@ -83,25 +84,31 @@ public async Task GetNonce(IEthClient client) return await client.NonceAt(GetAddress()); } + public Task SendTransaction(IEthClient client, EthTransaction transaction) + { + string signedTransaction = transaction.SignAndEncodeTransaction(this); + return SendRawTransaction(client, signedTransaction); + } + + public async Task SendTransactionAndWaitForReceipt(IEthClient client, EthTransaction transaction) + { + string result = await SendTransaction(client, transaction); + TransactionReceipt receipt = await client.WaitForTransactionReceipt(result); + return receipt; + } + public (string v, string r, string s) SignTransaction(byte[] message, string chainId) { int id = chainId.HexStringToInt(); return EthSignature.SignAndReturnVRS(message, privKey, id); } - public async Task SendRawTransaction(IEthClient client, string signedTransactionData) + private async Task SendRawTransaction(IEthClient client, string signedTransactionData) { string result = await client.SendRawTransaction(signedTransactionData); return result; } - public async Task SendRawTransactionAndWaitForReceipt(IEthClient client, string signedTransactionData) - { - string result = await SendRawTransaction(client, signedTransactionData); - TransactionReceipt receipt = await client.WaitForTransactionReceipt(result); - return receipt; - } - /// /// /// https://docs.ethers.org/v5/api/signer/#Signer-signMessage diff --git a/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs b/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs index b5641967..381bc149 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs @@ -9,6 +9,7 @@ using Sequence.Extensions; using Sequence.Provider; using Sequence.Signer; +using Sequence.Transactions; using SequenceSDK.Ethereum.Utils; using UnityEngine; @@ -17,9 +18,8 @@ namespace Sequence.Wallet public interface IWallet { public Address GetAddress(uint accountIndex = 0); - public (string v, string r, string s) SignTransaction(byte[] message, string chainId); - public Task SendRawTransaction(IEthClient client, string signedTransactionData); - public Task SendRawTransactionAndWaitForReceipt(IEthClient client, string signedTransactionData); + public Task SendTransaction(IEthClient client, EthTransaction transaction); + public Task SendTransactionAndWaitForReceipt(IEthClient client, EthTransaction transaction); /// /// diff --git a/Assets/SequenceSDK/Ethereum/Wallet/TransactionSender.cs b/Assets/SequenceSDK/Ethereum/Wallet/TransactionSender.cs index cee01c91..53ab555f 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/TransactionSender.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/TransactionSender.cs @@ -17,8 +17,7 @@ public static async Task SendTransaction(this IWallet fromWallet, IEthCl BigInteger nonce = await client.NonceAt(fromWallet.GetAddress()); transaction = new EthTransaction(nonce, (BigInteger)gasPrice, (BigInteger)gasLimit, to, (BigInteger)value, data, chainId); } - string tx = transaction.SignAndEncodeTransaction(fromWallet); - string result = await fromWallet.SendRawTransaction(client, tx); + string result = await fromWallet.SendTransaction(client, transaction); return result; } diff --git a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs index e07c84ce..00e9571c 100644 --- a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs +++ b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs @@ -7,6 +7,7 @@ using System; using Sequence.ABI; using Sequence.Extensions; +using Sequence.Transactions; namespace Sequence.WaaS { @@ -41,19 +42,14 @@ public Address GetAddress(uint accountIndex = 0) return _walletAddressesByAccountIndex[accountIndex]; } - public (string v, string r, string s) SignTransaction(byte[] message, string chainId) + public Task SendTransaction(IEthClient client, EthTransaction transaction) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } - public Task SendRawTransaction(IEthClient client, string signedTransactionData) + public Task SendTransactionAndWaitForReceipt(IEthClient client, EthTransaction transaction) { - throw new System.NotImplementedException(); - } - - public Task SendRawTransactionAndWaitForReceipt(IEthClient client, string signedTransactionData) - { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } public async Task SignMessage(byte[] message, byte[] chainId = null) From 8eb3c759253f3dce7a24ce5906ed92a7f80af84a Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Wed, 16 Aug 2023 17:16:29 -0400 Subject: [PATCH 34/49] Finished WaaSToWalletAdapter implementation --- .../Ethereum/Transaction/EthTransaction.cs | 14 +++++++------- Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs | 2 ++ Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs | 13 +++++++++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Assets/SequenceSDK/Ethereum/Transaction/EthTransaction.cs b/Assets/SequenceSDK/Ethereum/Transaction/EthTransaction.cs index 092fdc9b..1ac5512c 100644 --- a/Assets/SequenceSDK/Ethereum/Transaction/EthTransaction.cs +++ b/Assets/SequenceSDK/Ethereum/Transaction/EthTransaction.cs @@ -12,13 +12,13 @@ namespace Sequence.Transactions { public class EthTransaction { - BigInteger Nonce{ get; set; } - BigInteger GasPrice { get; set; } - BigInteger GasLimit { get; set; } - string To { get; set; } - BigInteger Value { get; set; } - string Data { get; set; } - string ChainId { get; set; } + public BigInteger Nonce{ get; private set; } + public BigInteger GasPrice { get; private set; } + public BigInteger GasLimit { get; private set; } + public string To { get; private set; } + public BigInteger Value { get; private set; } + public string Data { get; private set; } + public string ChainId { get; private set; } string V { get; set; } string R { get; set; } diff --git a/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs b/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs index 2ced5d12..3d9bf32d 100644 --- a/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs +++ b/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs @@ -1,6 +1,8 @@ +using System; using System.Collections; using System.Collections.Generic; using System.Numerics; +using Sequence.Transactions; using UnityEngine; namespace Sequence.WaaS diff --git a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs index 00e9571c..bd75f35e 100644 --- a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs +++ b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs @@ -42,14 +42,19 @@ public Address GetAddress(uint accountIndex = 0) return _walletAddressesByAccountIndex[accountIndex]; } - public Task SendTransaction(IEthClient client, EthTransaction transaction) + public async Task SendTransaction(IEthClient client, EthTransaction transaction) { - throw new NotImplementedException(); + Transaction waasTransaction = new Transaction(Convert.ToUInt32(transaction.ChainId), GetAddress(), transaction.To, null, transaction.Nonce, transaction.Value.ToString(), transaction.Data); + SendTransactionArgs args = new SendTransactionArgs(waasTransaction); + SendTransactionReturn result = await _wallet.SendTransaction(args); + return result.txHash; } - public Task SendTransactionAndWaitForReceipt(IEthClient client, EthTransaction transaction) + public async Task SendTransactionAndWaitForReceipt(IEthClient client, EthTransaction transaction) { - throw new NotImplementedException(); + string transactionHash = await SendTransaction(client, transaction); + TransactionReceipt receipt = await client.WaitForTransactionReceipt(transactionHash); + return receipt; } public async Task SignMessage(byte[] message, byte[] chainId = null) From 10ff0402ff7b7fe1f231c28d487b49f31bb3d4aa Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Thu, 17 Aug 2023 13:38:35 -0400 Subject: [PATCH 35/49] Added an end to end test for a basic transfer on the mumbai testnet. Fixed implementation so that the test passes --- .../Ethereum/Provider/IEthClient.cs | 2 +- .../Ethereum/Provider/SequenceEthClient.cs | 6 ++- Assets/SequenceSDK/WaaS/HttpClient.cs | 31 +++++++++++--- .../SequenceSDK/WaaS/Tests/EndToEndTests.cs | 41 +++++++++++++++++++ .../WaaS/Tests/EndToEndTests.cs.meta | 3 ++ .../SequenceSDK/WaaS/WaaSToWalletAdapter.cs | 3 +- Assets/SequenceSDK/WaaS/WaaSWallet.cs | 32 +++++++-------- 7 files changed, 93 insertions(+), 25 deletions(-) create mode 100644 Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs create mode 100644 Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs.meta diff --git a/Assets/SequenceSDK/Ethereum/Provider/IEthClient.cs b/Assets/SequenceSDK/Ethereum/Provider/IEthClient.cs index 1eeb5e8b..c44bf0c3 100644 --- a/Assets/SequenceSDK/Ethereum/Provider/IEthClient.cs +++ b/Assets/SequenceSDK/Ethereum/Provider/IEthClient.cs @@ -197,7 +197,7 @@ public interface IEthClient /// /// /// - Task BalanceAt(string address, string blockNumber); + Task BalanceAt(string address, string blockNumber = null); /// diff --git a/Assets/SequenceSDK/Ethereum/Provider/SequenceEthClient.cs b/Assets/SequenceSDK/Ethereum/Provider/SequenceEthClient.cs index 72cec9ad..3890c667 100644 --- a/Assets/SequenceSDK/Ethereum/Provider/SequenceEthClient.cs +++ b/Assets/SequenceSDK/Ethereum/Provider/SequenceEthClient.cs @@ -42,8 +42,12 @@ private void ThrowIfResponseHasErrors(RpcResponse response) } } - public async Task BalanceAt(string address, string blockNumber) + public async Task BalanceAt(string address, string blockNumber = null) { + if (blockNumber == null) + { + blockNumber = await BlockNumber(); + } RpcResponse response = await _httpRpcClient.SendRequest("eth_getBalance", new object[] { address, blockNumber}); ThrowIfResponseHasErrors(response); string balanceHex = response.result.ToString(); diff --git a/Assets/SequenceSDK/WaaS/HttpClient.cs b/Assets/SequenceSDK/WaaS/HttpClient.cs index 88f87832..10d63574 100644 --- a/Assets/SequenceSDK/WaaS/HttpClient.cs +++ b/Assets/SequenceSDK/WaaS/HttpClient.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; @@ -24,13 +25,17 @@ public void AddDefaultHeader(string key, string value) this._defaultHeaders[key] = value; } - public async Task SendRequest(T args, [CanBeNull] Dictionary headers = null) + public async Task SendRequest(string path, T args, [CanBeNull] Dictionary headers = null) { + string url = _url + "/" + path; string requestJson = JsonConvert.SerializeObject(args); - UnityWebRequest request = UnityWebRequest.Post(_url, requestJson); + UnityWebRequest request = UnityWebRequest.Get(url); request.SetRequestHeader("Content-Type", "application/json"); request.SetRequestHeader("Accept", "application/json"); request.method = UnityWebRequest.kHttpVerbPOST; + byte[] requestData = Encoding.UTF8.GetBytes(requestJson); + request.uploadHandler = new UploadHandlerRaw(requestData); + request.uploadHandler.contentType = "application/json"; if (headers == null) { @@ -42,13 +47,15 @@ public async Task SendRequest(T args, [CanBeNull] Dictionary SendRequest(T args, [CanBeNull] Dictionary SendTransaction(IEthClient client, EthTransaction transaction) { - Transaction waasTransaction = new Transaction(Convert.ToUInt32(transaction.ChainId), GetAddress(), transaction.To, null, transaction.Nonce, transaction.Value.ToString(), transaction.Data); + Transaction waasTransaction = new Transaction((uint)transaction.ChainId.HexStringToInt(), GetAddress(), transaction.To, null, transaction.Nonce, transaction.Value.ToString(), transaction.Data); SendTransactionArgs args = new SendTransactionArgs(waasTransaction); SendTransactionReturn result = await _wallet.SendTransaction(args); return result.txHash; diff --git a/Assets/SequenceSDK/WaaS/WaaSWallet.cs b/Assets/SequenceSDK/WaaS/WaaSWallet.cs index ecaec78a..4d4ef846 100644 --- a/Assets/SequenceSDK/WaaS/WaaSWallet.cs +++ b/Assets/SequenceSDK/WaaS/WaaSWallet.cs @@ -17,52 +17,52 @@ public WaaSWallet(string jwt) public Task CreatePartner(CreatePartnerArgs args, Dictionary headers = null) { - return _httpClient.SendRequest(args, headers); + return _httpClient.SendRequest("CreatePartner", args, headers); } public Task UpdatePartner(UpdatePartnerArgs args, Dictionary headers = null) { - return _httpClient.SendRequest(args, headers); + return _httpClient.SendRequest("UpdatePartner", args, headers); } public Task CreatePartnerWalletConfig(CreatePartnerWalletConfigArgs args, Dictionary headers = null) { - return _httpClient.SendRequest(args, headers); + return _httpClient.SendRequest("CreatePartnerWalletConfig", args, headers); } public Task PartnerWalletConfig(PartnerWalletConfigArgs args, Dictionary headers = null) { - return _httpClient.SendRequest(args, headers); + return _httpClient.SendRequest("PartnerWalletConfig", args, headers); } public Task DeployPartnerParentWallet(DeployPartnerParentWalletArgs args, Dictionary headers = null) { - return _httpClient.SendRequest(args, headers); + return _httpClient.SendRequest("DeployPartnerParentWallet", args, headers); } public Task AddPartnerWalletSigner(AddPartnerWalletSignerArgs args, Dictionary headers = null) { - return _httpClient.SendRequest(args, headers); + return _httpClient.SendRequest("AddPartnerWalletSigner", args, headers); } public Task RemovePartnerWalletSigner(RemovePartnerWalletSignerArgs args, Dictionary headers = null) { - return _httpClient.SendRequest(args, headers); + return _httpClient.SendRequest("RemovePartnerWalletSigner", args, headers); } public Task ListPartnerWalletSigners(ListPartnerWalletSignersArgs args, Dictionary headers = null) { - return _httpClient.SendRequest(args, headers); + return _httpClient.SendRequest("ListPartnerWalletSigners", args, headers); } public Task PartnerWallets(PartnerWalletsArgs args, Dictionary headers = null) { - return _httpClient.SendRequest(args, headers); + return _httpClient.SendRequest("PartnerWallets", args, headers); } public Task CreateWallet(CreateWalletArgs args, Dictionary headers = null) { - return _httpClient.SendRequest(args, headers); + return _httpClient.SendRequest("CreateWallet", args, headers); } public Task GetWalletAddress(GetWalletAddressArgs args, Dictionary headers = null) @@ -73,32 +73,32 @@ public Task GetWalletAddress(GetWalletAddressArgs args, public Task DeployWallet(DeployWalletArgs args, Dictionary headers = null) { - return _httpClient.SendRequest(args, headers); + return _httpClient.SendRequest("DeployWallet", args, headers); } public Task Wallets(WalletsArgs args, Dictionary headers = null) { - return _httpClient.SendRequest(args, headers); + return _httpClient.SendRequest("Wallets", args, headers); } public Task SignMessage(SignMessageArgs args, Dictionary headers = null) { - return _httpClient.SendRequest(args, headers); + return _httpClient.SendRequest("SignMessage", args, headers); } public Task IsValidMessageSignature(IsValidMessageSignatureArgs args, Dictionary headers = null) { - return _httpClient.SendRequest(args, headers); + return _httpClient.SendRequest("IsValidMessageSignature", args, headers); } public Task SendTransaction(SendTransactionArgs args, Dictionary headers = null) { - return _httpClient.SendRequest(args, headers); + return _httpClient.SendRequest("SendTransaction", args, headers); } public Task SendTransactionBatch(SendTransactionBatchArgs args, Dictionary headers = null) { - return _httpClient.SendRequest(args, headers); + return _httpClient.SendRequest("SendTransactionBatch", args, headers); } } } \ No newline at end of file From 77fe1bda74db41e86655eafc550b7affde5b3039 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Thu, 17 Aug 2023 14:05:14 -0400 Subject: [PATCH 36/49] Added another convenience method to TransferEth to make it easier to send basic transfers --- .../Ethereum/Transaction/GasLimitEstimator.cs | 13 ++++++++----- .../Ethereum/Transaction/TransferEth.cs | 14 ++++++++++++++ Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs | 5 +---- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Assets/SequenceSDK/Ethereum/Transaction/GasLimitEstimator.cs b/Assets/SequenceSDK/Ethereum/Transaction/GasLimitEstimator.cs index 7f414bf7..e0cb462d 100644 --- a/Assets/SequenceSDK/Ethereum/Transaction/GasLimitEstimator.cs +++ b/Assets/SequenceSDK/Ethereum/Transaction/GasLimitEstimator.cs @@ -17,7 +17,7 @@ public GasLimitEstimator(IEthClient client, Address wallet) { this.wallet = wallet; } - public TransactionCreator BuildTransactionCreator(string to, string data = null, BigInteger? value = null, BigInteger? gasPrice = null, BigInteger? gasLimit = null) { + public TransactionCreator BuildTransactionCreator(string to, string data = null, BigInteger? value = null, BigInteger? gasPrice = null, BigInteger? gasLimit = null, BigInteger? nonce = null) { return async () => { if (value == null) { @@ -44,17 +44,20 @@ public TransactionCreator BuildTransactionCreator(string to, string data = null, { gasLimit = await client.EstimateGas(call); } + if (nonce == null) + { + nonce = await client.NonceAt(wallet); + } - BigInteger nonce = await client.NonceAt(wallet); string chainId = await client.ChainID(); - EthTransaction transaction = new EthTransaction(nonce, (BigInteger)gasPrice, (BigInteger)gasLimit, to, (BigInteger)value, data, chainId); + EthTransaction transaction = new EthTransaction((BigInteger)nonce, (BigInteger)gasPrice, (BigInteger)gasLimit, to, (BigInteger)value, data, chainId); return transaction; }; } - public async Task BuildTransaction(string to, string data = null, BigInteger? value = null, BigInteger? gasPrice = null, BigInteger? gasLimit = null) + public async Task BuildTransaction(string to, string data = null, BigInteger? value = null, BigInteger? gasPrice = null, BigInteger? gasLimit = null, BigInteger? nonce = null) { - return await BuildTransactionCreator(to, data, value, gasPrice, gasLimit)(); + return await BuildTransactionCreator(to, data, value, gasPrice, gasLimit, nonce)(); } } } \ No newline at end of file diff --git a/Assets/SequenceSDK/Ethereum/Transaction/TransferEth.cs b/Assets/SequenceSDK/Ethereum/Transaction/TransferEth.cs index 45559ae2..e6d04da6 100644 --- a/Assets/SequenceSDK/Ethereum/Transaction/TransferEth.cs +++ b/Assets/SequenceSDK/Ethereum/Transaction/TransferEth.cs @@ -51,6 +51,20 @@ public TransferEth( this.nonce = nonce; } + public static async Task CreateTransaction( + IEthClient client, + IWallet fromWallet, + string toAddress, + BigInteger value, + BigInteger? gasPrice = null, + BigInteger? gasLimit = null, + BigInteger? nonce = null) + { + GasLimitEstimator estimator = new GasLimitEstimator(client, fromWallet.GetAddress()); + EthTransaction transaction = await estimator.BuildTransaction(toAddress, null, value, gasPrice, gasLimit, nonce); + return transaction; + } + /// /// Signs and sends the Eth transfer transaction /// diff --git a/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs b/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs index 791632da..4980728c 100644 --- a/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs +++ b/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs @@ -19,10 +19,7 @@ public async Task TestTransferOnTestnet() new uint[]{0}); IEthClient client = new SequenceEthClient("https://polygon-mumbai-bor.publicnode.com"); - - GasLimitEstimator estimator = new GasLimitEstimator(client, wallet.GetAddress()); - EthTransaction transaction = await - estimator.BuildTransactionCreator("0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f", null, 1)(); + EthTransaction transaction = await TransferEth.CreateTransaction(client, wallet, "0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f", 1); BigInteger startingBalance = await client.BalanceAt("0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f"); BigInteger startingBalance2 = await client.BalanceAt(wallet.GetAddress().Value); From b779ac439ae92ad0314cfaa3bc465a54347bec6b Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Thu, 17 Aug 2023 14:56:51 -0400 Subject: [PATCH 37/49] Create WaaSToWalletAdapter more cleanly --- Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs | 3 +-- Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs | 8 ++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs b/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs index 4980728c..8c8ae600 100644 --- a/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs +++ b/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs @@ -15,8 +15,7 @@ public class EndToEndTests public async Task TestTransferOnTestnet() { Wallet.IWallet wallet = await WaaSToWalletAdapter.CreateAsync(new WaaSWallet( - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXJ0bmVyX2lkIjoyLCJ3YWxsZXQiOiIweDY2MDI1MDczNGYzMTY0NDY4MWFlMzJkMDViZDdlOGUyOWZlYTI5ZTEifQ.FC8WmaC_hW4svdrs4rxyKcvoekfVYFkFFvGwUOXzcHA"), - new uint[]{0}); + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXJ0bmVyX2lkIjoyLCJ3YWxsZXQiOiIweDY2MDI1MDczNGYzMTY0NDY4MWFlMzJkMDViZDdlOGUyOWZlYTI5ZTEifQ.FC8WmaC_hW4svdrs4rxyKcvoekfVYFkFFvGwUOXzcHA")); IEthClient client = new SequenceEthClient("https://polygon-mumbai-bor.publicnode.com"); EthTransaction transaction = await TransferEth.CreateTransaction(client, wallet, "0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f", 1); diff --git a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs index b8bd3287..d5bc68ce 100644 --- a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs +++ b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs @@ -17,6 +17,14 @@ public class WaaSToWalletAdapter : Sequence.Wallet.IWallet private IWallet _wallet; private Dictionary _walletAddressesByAccountIndex; + public static async Task CreateAsync(WaaSWallet wallet) + { + var walletAddressesByAccountIndex = new Dictionary(); + var address = await wallet.GetWalletAddress(null); + walletAddressesByAccountIndex[0] = new Address(address.address); + return new WaaSToWalletAdapter(wallet, walletAddressesByAccountIndex); + } + private WaaSToWalletAdapter(IWallet wallet, Dictionary walletAddressesByAccountIndex) { _wallet = wallet; From ad72d97370f93d25d998e58a1788dbf2722b297a Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Thu, 17 Aug 2023 15:46:07 -0400 Subject: [PATCH 38/49] IWallet support for SendTransactionBatch and SendTransactionBatchAndWaitForReceipts. Added respective tests --- .../SequenceSDK/Ethereum/Tests/WalletTests.cs | 36 +++++++++++ .../Ethereum/Transaction/EthTransaction.cs | 7 +++ .../SequenceSDK/Ethereum/Wallet/EthWallet.cs | 31 ++++++++++ Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs | 4 ++ Assets/SequenceSDK/WaaS/HttpClient.cs | 2 +- .../SequenceSDK/WaaS/Tests/EndToEndTests.cs | 60 ++++++++++++++++++- .../SequenceSDK/WaaS/WaaSToWalletAdapter.cs | 27 +++++++++ 7 files changed, 164 insertions(+), 3 deletions(-) diff --git a/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs b/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs index 41a325c0..dad8f51a 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs @@ -304,6 +304,42 @@ public async Task TestWalletSignAndRecover() Assert.AreEqual(address, recoveredAddr); } + [Test] + public async Task TestSendTransactionBatchAndWaitForReceipts() + { + EthWallet wallet = new EthWallet("0xabc0000000000000000000000000000000000000000000000000000000000001"); + SequenceEthClient client = new SequenceEthClient("http://localhost:8545/"); + string recipient1 = "0x1099542D7dFaF6757527146C0aB9E70A967f71C0"; + string recipient2 = "0x606e6d28e9150D8A3C070AEfB751a2D0C5DB19fa"; + BigInteger startingBalance = await client.BalanceAt(wallet.GetAddress()); + BigInteger startingBalance1 = await client.BalanceAt(recipient1); + BigInteger startingBalance2 = await client.BalanceAt(recipient2); + + EthTransaction transaction1 = await TransferEth.CreateTransaction(client, wallet, recipient1, 1000); + EthTransaction transaction2 = await TransferEth.CreateTransaction(client, wallet, recipient2, 1000); + EthTransaction[] transactions = new EthTransaction[] { transaction1, transaction2 }; + + TransactionReceipt[] receipts = await wallet.SendTransactionBatchAndWaitForReceipts(client, transactions); + + BigInteger endingBalance = await client.BalanceAt(wallet.GetAddress()); + BigInteger endingBalance1 = await client.BalanceAt(recipient1); + BigInteger endingBalance2 = await client.BalanceAt(recipient2); + + Assert.Less(endingBalance, startingBalance); + Assert.Greater(endingBalance1, startingBalance1); + Assert.Greater(endingBalance2, startingBalance2); + } + [Test] + public async Task TestSendTransactionBatchAndWaitForReceipts_emptyBatch() + { + EthWallet wallet = new EthWallet("0xabc0000000000000000000000000000000000000000000000000000000000001"); + SequenceEthClient client = new SequenceEthClient("http://localhost:8545/"); + EthTransaction[] transactions = new EthTransaction[] {}; + + TransactionReceipt[] receipts = await wallet.SendTransactionBatchAndWaitForReceipts(client, transactions); + + Assert.AreEqual(0, receipts.Length); + } } diff --git a/Assets/SequenceSDK/Ethereum/Transaction/EthTransaction.cs b/Assets/SequenceSDK/Ethereum/Transaction/EthTransaction.cs index 1ac5512c..1f030eb0 100644 --- a/Assets/SequenceSDK/Ethereum/Transaction/EthTransaction.cs +++ b/Assets/SequenceSDK/Ethereum/Transaction/EthTransaction.cs @@ -4,6 +4,8 @@ using System.Collections; using System.Collections.Generic; using System.Numerics; +using System.Threading.Tasks; +using Sequence.Provider; using UnityEngine; using Sequence.Wallet; using Sequence.Utils; @@ -143,5 +145,10 @@ public string SignAndEncodeTransaction(EthWallet wallet) string tx = this.RLPEncode(); return tx; } + + public void IncrementNonceBy(int i) + { + this.Nonce += i; + } } } diff --git a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs index 5def98dc..cc034d86 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs @@ -97,6 +97,37 @@ public async Task SendTransactionAndWaitForReceipt(IEthClien return receipt; } + public async Task SendTransactionBatch(IEthClient client, EthTransaction[] transactions) + { + int transactionCount = transactions.Length; + string[] transactionHashes = new string[transactionCount]; + for (int i = 0; i < transactionCount; i++) + { + transactions[i].IncrementNonceBy(i); + transactionHashes[i] = await SendTransaction(client, transactions[i]); + } + + return transactionHashes; + } + + public async Task SendTransactionBatchAndWaitForReceipts(IEthClient client, EthTransaction[] transactions) + { + string[] transactionHashes = await SendTransactionBatch(client, transactions); + int transactionCount = transactions.Length; + if (transactionCount != transactionHashes.Length) + { + throw new SystemException("Invalid system state: didn't receive as many transaction hashes as transactions"); + } + + TransactionReceipt[] receipts = new TransactionReceipt[transactionCount]; + for (int i = 0; i < transactionCount; i++) + { + receipts[i] = await client.WaitForTransactionReceipt(transactionHashes[i]); + } + + return receipts; + } + public (string v, string r, string s) SignTransaction(byte[] message, string chainId) { int id = chainId.HexStringToInt(); diff --git a/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs b/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs index 381bc149..909bbdc7 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs @@ -20,6 +20,10 @@ public interface IWallet public Address GetAddress(uint accountIndex = 0); public Task SendTransaction(IEthClient client, EthTransaction transaction); public Task SendTransactionAndWaitForReceipt(IEthClient client, EthTransaction transaction); + public Task SendTransactionBatch(IEthClient client, EthTransaction[] transactions); + + public Task SendTransactionBatchAndWaitForReceipts(IEthClient client, + EthTransaction[] transactions); /// /// diff --git a/Assets/SequenceSDK/WaaS/HttpClient.cs b/Assets/SequenceSDK/WaaS/HttpClient.cs index 10d63574..162225d9 100644 --- a/Assets/SequenceSDK/WaaS/HttpClient.cs +++ b/Assets/SequenceSDK/WaaS/HttpClient.cs @@ -55,7 +55,7 @@ public async Task SendRequest(string path, T args, [CanBeNull] Dictio if (request.error != null || request.result != UnityWebRequest.Result.Success) { - throw new Exception($"Error sending request to {url} with args {args}: {request.error}"); + throw new Exception($"Error sending request to {url}: {request.error}"); } else { diff --git a/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs b/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs index 8c8ae600..a924cd28 100644 --- a/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs +++ b/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs @@ -1,3 +1,4 @@ +using System; using System.Numerics; using System.Threading.Tasks; using NUnit.Framework; @@ -7,10 +8,10 @@ namespace Sequence.WaaS.Tests { + // Note: these tests use a real testnet. If this test fails, double check the RPC is active and that the sending account has funds + // https://mumbai.polygonscan.com/address/0x660250734f31644681ae32d05bd7e8e29fea29e1 public class EndToEndTests { - // Note: this test uses a real testnet. If this test fails, double check the RPC is active and that the sending account has funds - // https://mumbai.polygonscan.com/address/0x660250734f31644681ae32d05bd7e8e29fea29e1 [Test] public async Task TestTransferOnTestnet() { @@ -33,5 +34,60 @@ public async Task TestTransferOnTestnet() Assert.Greater(endingBalance, startingBalance); Assert.Less(endingBalance2, startingBalance2); } + + [Test] + public async Task TestBatchTransferOnTestnet() + { + Wallet.IWallet wallet = await WaaSToWalletAdapter.CreateAsync(new WaaSWallet( + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXJ0bmVyX2lkIjoyLCJ3YWxsZXQiOiIweDY2MDI1MDczNGYzMTY0NDY4MWFlMzJkMDViZDdlOGUyOWZlYTI5ZTEifQ.FC8WmaC_hW4svdrs4rxyKcvoekfVYFkFFvGwUOXzcHA")); + + IEthClient client = new SequenceEthClient("https://polygon-mumbai-bor.publicnode.com"); + EthTransaction transaction = await TransferEth.CreateTransaction(client, wallet, "0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f", 1); + EthTransaction transaction2 = + await TransferEth.CreateTransaction(client, wallet, "0xc683a014955b75F5ECF991d4502427c8fa1Aa249", 1); + + BigInteger startingBalance = await client.BalanceAt("0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f"); + BigInteger startingBalance2 = await client.BalanceAt(wallet.GetAddress().Value); + BigInteger startingBalance3 = await client.BalanceAt("0xc683a014955b75F5ECF991d4502427c8fa1Aa249"); + + EthTransaction[] transactionBatch = new EthTransaction[] + { + transaction, + transaction2 + }; + + TransactionReceipt[] receipts = await wallet.SendTransactionBatchAndWaitForReceipts(client, transactionBatch); + + BigInteger endingBalance = await client.BalanceAt("0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f"); + BigInteger endingBalance2 = await client.BalanceAt(wallet.GetAddress().Value); + BigInteger endingBalance3 = await client.BalanceAt("0xc683a014955b75F5ECF991d4502427c8fa1Aa249"); + + Debug.Log($"starting balance {startingBalance} ending balance {endingBalance}"); + Debug.Log($"starting balance 2 {startingBalance2} ending balance 2 {endingBalance2}"); + Debug.Log($"starting balance 3 {startingBalance3} ending balance 3 {endingBalance3}"); + Assert.Greater(endingBalance, startingBalance); + Assert.Less(endingBalance2, startingBalance2); + Assert.Greater(endingBalance3, startingBalance3); + } + + [Test] + public async Task TestBatchTransferOnTestnet_emptyBatch() + { + Wallet.IWallet wallet = await WaaSToWalletAdapter.CreateAsync(new WaaSWallet( + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXJ0bmVyX2lkIjoyLCJ3YWxsZXQiOiIweDY2MDI1MDczNGYzMTY0NDY4MWFlMzJkMDViZDdlOGUyOWZlYTI5ZTEifQ.FC8WmaC_hW4svdrs4rxyKcvoekfVYFkFFvGwUOXzcHA")); + IEthClient client = new SequenceEthClient("https://polygon-mumbai-bor.publicnode.com"); + EthTransaction[] transactionBatch = new EthTransaction[]{}; + + try + { + TransactionReceipt[] receipts = + await wallet.SendTransactionBatchAndWaitForReceipts(client, transactionBatch); + Assert.Fail("Expected exception but none was thrown"); + } + catch (Exception ex) + { + Assert.AreEqual("Error sending request to https://next-api.sequence.app/rpc/Wallet/SendTransactionBatch: HTTP/1.1 500 Internal Server Error", ex.Message); + } + } } } \ No newline at end of file diff --git a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs index d5bc68ce..0ba722c5 100644 --- a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs +++ b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs @@ -66,6 +66,33 @@ public async Task SendTransactionAndWaitForReceipt(IEthClien return receipt; } + public async Task SendTransactionBatch(IEthClient client, EthTransaction[] transactions) + { + int transactionCount = transactions.Length; + Transaction[] waasTransactions = new Transaction[transactionCount]; + for (int i = 0; i < transactionCount; i++) + { + waasTransactions[i] = new Transaction((uint)transactions[i].ChainId.HexStringToInt(), GetAddress(), transactions[i].To, null, transactions[i].Nonce, transactions[i].Value.ToString(), transactions[i].Data); + } + + SendTransactionBatchArgs args = new SendTransactionBatchArgs(waasTransactions); + SendTransactionBatchReturn result = await _wallet.SendTransactionBatch(args); + return new string[]{result.txHash}; + } + + public async Task SendTransactionBatchAndWaitForReceipts(IEthClient client, EthTransaction[] transactions) + { + string[] transactionHashes = await SendTransactionBatch(client, transactions); + int transactionCount = transactionHashes.Length; + TransactionReceipt[] receipts = new TransactionReceipt[transactionCount]; + for (int i = 0; i < transactionCount; i++) + { + receipts[i] = await client.WaitForTransactionReceipt(transactionHashes[i]); + } + + return receipts; + } + public async Task SignMessage(byte[] message, byte[] chainId = null) { string messageString = SequenceCoder.HexStringToHumanReadable(SequenceCoder.ByteArrayToHexString(message)); From 2cd3a7c2d904439763ac50c025079d58dd025aeb Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Thu, 17 Aug 2023 15:49:57 -0400 Subject: [PATCH 39/49] Better signature and verification interface --- Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs | 2 +- Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs | 2 +- Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs index cc034d86..6b119e54 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/EthWallet.cs @@ -218,7 +218,7 @@ public string SignByteArray(string privateKey, byte[] byteArray) /// The signature to verify. /// The message that was signed. /// true if the signature is valid, false otherwise. - public async Task IsValidSignature(string signature, string message, uint accountIndex = 0, string chainId = "") + public async Task IsValidSignature(string signature, string message, string chainId = "", uint accountIndex = 0) { byte[] messageBytes = Encoding.UTF8.GetBytes(message); if (chainId != null && chainId.Length > 0) diff --git a/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs b/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs index 909bbdc7..594092db 100644 --- a/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs +++ b/Assets/SequenceSDK/Ethereum/Wallet/IWallet.cs @@ -57,7 +57,7 @@ public Task SendTransactionBatchAndWaitForReceipts(IEthCli /// /// /// true if the signature is valid, false otherwise. - public Task IsValidSignature(string signature, string message, uint accountIndex = 0, string chainId = ""); + public Task IsValidSignature(string signature, string message, string chainId = "", uint accountIndex = 0); diff --git a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs index 0ba722c5..8fc81702 100644 --- a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs +++ b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs @@ -93,7 +93,7 @@ public async Task SendTransactionBatchAndWaitForReceipts(I return receipts; } - public async Task SignMessage(byte[] message, byte[] chainId = null) + public async Task SignMessage(byte[] message, byte[] chainId) { string messageString = SequenceCoder.HexStringToHumanReadable(SequenceCoder.ByteArrayToHexString(message)); string chainIdString = @@ -102,7 +102,7 @@ public async Task SignMessage(byte[] message, byte[] chainId = null) return await SignMessage(messageString, chainIdString); } - public async Task SignMessage(string message, string chainId = null) + public async Task SignMessage(string message, string chainId) { if (uint.TryParse(chainId, out uint chain)) { @@ -116,7 +116,7 @@ public async Task SignMessage(string message, string chainId = null) } } - public async Task IsValidSignature(string signature, string message, uint accountIndex, string chainId) + public async Task IsValidSignature(string signature, string message, string chainId, uint accountIndex = 0) { var args = new IsValidMessageSignatureArgs(chainId, GetAddress(accountIndex), message, signature); var result = await _wallet.IsValidMessageSignature(args); From f2a446e3ad1ba534af7fb97efd7562b889db3ec0 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Thu, 17 Aug 2023 16:46:26 -0400 Subject: [PATCH 40/49] Test waas signing message and checking valid signature. Fixed implementation --- .../SequenceSDK/Ethereum/Tests/WalletTests.cs | 69 ++++++++++++------- .../IsValidMessageSignatureArgs.cs | 4 +- .../ParameterTypes/SignMessageArgs.cs | 8 ++- Assets/SequenceSDK/WaaS/HttpClient.cs | 1 - .../SequenceSDK/WaaS/WaaSToWalletAdapter.cs | 15 ++-- 5 files changed, 56 insertions(+), 41 deletions(-) diff --git a/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs b/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs index dad8f51a..7681d1ca 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using NUnit.Framework; using UnityEngine; -using UnityEngine.TestTools; using Sequence.Wallet; using Sequence.ABI; using Sequence.Provider; @@ -17,6 +16,8 @@ using Sequence.Transactions; using Sequence.Contracts; using Sequence.Utils; +using Sequence.WaaS; +using IWallet = Sequence.Wallet.IWallet; public class EthWalletTests { @@ -28,10 +29,13 @@ public class EthWalletTests const string privKey5 = "0xabc0000000000000000000000000000000000000000000000000000000000006"; //ERC20 Mock - string bytecode_ERC20Mock = "0x608060405234801561001057600080fd5b50610997806100206000396000f3fe608060405234801561001057600080fd5b50600436106100be5760003560e01c80633950935111610076578063a457c2d71161005b578063a457c2d7146102f0578063a9059cbb14610329578063dd62ed3e14610362576100be565b8063395093511461028457806370a08231146102bd576100be565b806323b872dd116100a757806323b872dd1461012a5780632e72102f1461016d578063378934b41461024b576100be565b8063095ea7b3146100c357806318160ddd14610110575b600080fd5b6100fc600480360360408110156100d957600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813516906020013561039d565b604080519115158252519081900360200190f35b6101186103b3565b60408051918252519081900360200190f35b6100fc6004803603606081101561014057600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602081013590911690604001356103b9565b6102496004803603606081101561018357600080fd5b81019060208101813564010000000081111561019e57600080fd5b8201836020820111156101b057600080fd5b803590602001918460208302840111640100000000831117156101d257600080fd5b9193909273ffffffffffffffffffffffffffffffffffffffff8335169260408101906020013564010000000081111561020a57600080fd5b82018360208201111561021c57600080fd5b8035906020019184602083028401116401000000008311171561023e57600080fd5b509092509050610417565b005b6102496004803603604081101561026157600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610509565b6100fc6004803603604081101561029a57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610517565b610118600480360360208110156102d357600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1661055a565b6100fc6004803603604081101561030657600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610582565b6100fc6004803603604081101561033f57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356105c5565b6101186004803603604081101561037857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160200135166105d2565b60006103aa33848461060a565b50600192915050565b60025490565b60006103c68484846106b9565b73ffffffffffffffffffffffffffffffffffffffff841660009081526001602090815260408083203380855292529091205461040d91869161040890866107ac565b61060a565b5060019392505050565b60005b818110156105015785858281811061042e57fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb8585858581811061047357fe5b905060200201356040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b1580156104cd57600080fd5b505af11580156104e1573d6000803e3d6000fd5b505050506040513d60208110156104f757600080fd5b505060010161041a565b505050505050565b6105138282610823565b5050565b33600081815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8716845290915281205490916103aa91859061040890866108e6565b73ffffffffffffffffffffffffffffffffffffffff1660009081526020819052604090205490565b33600081815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8716845290915281205490916103aa91859061040890866107ac565b60006103aa3384846106b9565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260016020908152604080832093909416825291909152205490565b73ffffffffffffffffffffffffffffffffffffffff821661062a57600080fd5b73ffffffffffffffffffffffffffffffffffffffff831661064a57600080fd5b73ffffffffffffffffffffffffffffffffffffffff808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b73ffffffffffffffffffffffffffffffffffffffff82166106d957600080fd5b73ffffffffffffffffffffffffffffffffffffffff831660009081526020819052604090205461070990826107ac565b73ffffffffffffffffffffffffffffffffffffffff808516600090815260208190526040808220939093559084168152205461074590826108e6565b73ffffffffffffffffffffffffffffffffffffffff8084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008282111561081d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f536166654d617468237375623a20554e444552464c4f57000000000000000000604482015290519081900360640190fd5b50900390565b73ffffffffffffffffffffffffffffffffffffffff821661084357600080fd5b60025461085090826108e6565b60025573ffffffffffffffffffffffffffffffffffffffff821660009081526020819052604090205461088390826108e6565b73ffffffffffffffffffffffffffffffffffffffff83166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b60008282018381101561095a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f536166654d617468236164643a204f564552464c4f5700000000000000000000604482015290519081900360640190fd5b939250505056fea26469706673582212201e8282683b3b9580e5722aa29d3e976acdd4cd35c3e88cdd1abb688867d0547a64736f6c63430007040033"; + string bytecode_ERC20Mock = + "0x608060405234801561001057600080fd5b50610997806100206000396000f3fe608060405234801561001057600080fd5b50600436106100be5760003560e01c80633950935111610076578063a457c2d71161005b578063a457c2d7146102f0578063a9059cbb14610329578063dd62ed3e14610362576100be565b8063395093511461028457806370a08231146102bd576100be565b806323b872dd116100a757806323b872dd1461012a5780632e72102f1461016d578063378934b41461024b576100be565b8063095ea7b3146100c357806318160ddd14610110575b600080fd5b6100fc600480360360408110156100d957600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813516906020013561039d565b604080519115158252519081900360200190f35b6101186103b3565b60408051918252519081900360200190f35b6100fc6004803603606081101561014057600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602081013590911690604001356103b9565b6102496004803603606081101561018357600080fd5b81019060208101813564010000000081111561019e57600080fd5b8201836020820111156101b057600080fd5b803590602001918460208302840111640100000000831117156101d257600080fd5b9193909273ffffffffffffffffffffffffffffffffffffffff8335169260408101906020013564010000000081111561020a57600080fd5b82018360208201111561021c57600080fd5b8035906020019184602083028401116401000000008311171561023e57600080fd5b509092509050610417565b005b6102496004803603604081101561026157600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610509565b6100fc6004803603604081101561029a57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610517565b610118600480360360208110156102d357600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1661055a565b6100fc6004803603604081101561030657600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610582565b6100fc6004803603604081101561033f57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356105c5565b6101186004803603604081101561037857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160200135166105d2565b60006103aa33848461060a565b50600192915050565b60025490565b60006103c68484846106b9565b73ffffffffffffffffffffffffffffffffffffffff841660009081526001602090815260408083203380855292529091205461040d91869161040890866107ac565b61060a565b5060019392505050565b60005b818110156105015785858281811061042e57fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb8585858581811061047357fe5b905060200201356040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b1580156104cd57600080fd5b505af11580156104e1573d6000803e3d6000fd5b505050506040513d60208110156104f757600080fd5b505060010161041a565b505050505050565b6105138282610823565b5050565b33600081815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8716845290915281205490916103aa91859061040890866108e6565b73ffffffffffffffffffffffffffffffffffffffff1660009081526020819052604090205490565b33600081815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8716845290915281205490916103aa91859061040890866107ac565b60006103aa3384846106b9565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260016020908152604080832093909416825291909152205490565b73ffffffffffffffffffffffffffffffffffffffff821661062a57600080fd5b73ffffffffffffffffffffffffffffffffffffffff831661064a57600080fd5b73ffffffffffffffffffffffffffffffffffffffff808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b73ffffffffffffffffffffffffffffffffffffffff82166106d957600080fd5b73ffffffffffffffffffffffffffffffffffffffff831660009081526020819052604090205461070990826107ac565b73ffffffffffffffffffffffffffffffffffffffff808516600090815260208190526040808220939093559084168152205461074590826108e6565b73ffffffffffffffffffffffffffffffffffffffff8084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008282111561081d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f536166654d617468237375623a20554e444552464c4f57000000000000000000604482015290519081900360640190fd5b50900390565b73ffffffffffffffffffffffffffffffffffffffff821661084357600080fd5b60025461085090826108e6565b60025573ffffffffffffffffffffffffffffffffffffffff821660009081526020819052604090205461088390826108e6565b73ffffffffffffffffffffffffffffffffffffffff83166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b60008282018381101561095a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f536166654d617468236164643a204f564552464c4f5700000000000000000000604482015290519081900360640190fd5b939250505056fea26469706673582212201e8282683b3b9580e5722aa29d3e976acdd4cd35c3e88cdd1abb688867d0547a64736f6c63430007040033"; + string zeroAddress = "0x0"; BigInteger gasPrice_ERC20Mock = 100; BigInteger gasLimit_ERC20Mock = 30000000; + [Test] public void TestChain_AddressesTests() { @@ -76,7 +80,7 @@ public void TestChain_AddressesTests() } - + [Test] public async Task TestChain_TransactionTests() @@ -88,13 +92,16 @@ public async Task TestChain_TransactionTests() SequenceEthClient client = new SequenceEthClient("http://localhost:8545/"); string to = "0x1099542D7dFaF6757527146C0aB9E70A967f71C0"; BigInteger value = 12300000000; - EthTransaction transaction = await new GasLimitEstimator(client, wallet.GetAddress()).BuildTransaction(to, null, value); + EthTransaction transaction = + await new GasLimitEstimator(client, wallet.GetAddress()).BuildTransaction(to, null, value); string result = await wallet.SendTransaction(client, transaction); Assert.IsNotEmpty(result); - await client.WaitForTransactionReceipt(result); // Not waiting for the transaction to process will cause the next tests to fail as they would be submitting a duplicate transaction + await client + .WaitForTransactionReceipt( + result); // Not waiting for the transaction to process will cause the next tests to fail as they would be submitting a duplicate transaction } - catch(Exception ex) + catch (Exception ex) { Assert.Fail("Expected no exception, but got: " + ex.Message); } @@ -127,16 +134,17 @@ public async Task TestChain_BalanceReducesAfterTransaction() [Test] public async Task TestChain_DeployERC20Mock_Tests() { - + try { SequenceEthClient client = new SequenceEthClient("http://localhost:8545/"); EthWallet wallet = new EthWallet("0xabc0000000000000000000000000000000000000000000000000000000000001"); - TransactionReceipt receipt = await ContractDeployer.Deploy(client, wallet, bytecode_ERC20Mock, gasPrice_ERC20Mock, gasLimit_ERC20Mock); + TransactionReceipt receipt = await ContractDeployer.Deploy(client, wallet, bytecode_ERC20Mock, + gasPrice_ERC20Mock, gasLimit_ERC20Mock); Assert.IsNotNull(receipt.contractAddress); } - catch(Exception ex) + catch (Exception ex) { Assert.Fail("Expected no exception, but got: " + ex.Message); } @@ -151,7 +159,8 @@ public async Task TestChain_ERC20Mock_MockMint_Test() //Deploy First SequenceEthClient client = new SequenceEthClient("http://localhost:8545/"); EthWallet wallet = new EthWallet("0xabc0000000000000000000000000000000000000000000000000000000000001"); - TransactionReceipt receipt = await ContractDeployer.Deploy(client, wallet, bytecode_ERC20Mock, gasPrice_ERC20Mock, gasLimit_ERC20Mock); + TransactionReceipt receipt = await ContractDeployer.Deploy(client, wallet, bytecode_ERC20Mock, + gasPrice_ERC20Mock, gasLimit_ERC20Mock); Assert.IsNotNull(receipt.contractAddress); @@ -168,7 +177,7 @@ public async Task TestChain_ERC20Mock_MockMint_Test() Contract mockERC20 = new Contract(receipt.contractAddress); string result = await mockERC20.SendTransactionMethod(wallet2, client, 0, "mockMint(address , uint256)", - wallet2.GetAddress(), 1); + wallet2.GetAddress(), 1); Assert.IsNotNull(result); } catch (Exception ex) @@ -189,25 +198,30 @@ public void EIP155SigningTxTest() //Example from https://eips.ethereum.org/EIPS/eip-155#parameters //Consider a transaction with nonce = 9, gasprice = 20 * 10**9, startgas = 21000, to = 0x3535353535353535353535353535353535353535, value = 10**18, data='' (empty). //1. Signing data - string expected_signing_data = "0xec098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a764000080018080"; - string encoded_signing_data = EthTransaction.RLPEncode(9, 20000000000, 21000, "0x3535353535353535353535353535353535353535", 1000000000000000000, "", "1"); - CollectionAssert.AreEqual(expected_signing_data,encoded_signing_data); + string expected_signing_data = + "0xec098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a764000080018080"; + string encoded_signing_data = EthTransaction.RLPEncode(9, 20000000000, 21000, + "0x3535353535353535353535353535353535353535", 1000000000000000000, "", "1"); + CollectionAssert.AreEqual(expected_signing_data, encoded_signing_data); //signing hash string expected_signing_hash = "0xdaf5a779ae972f972197303d7b574746c7ef83eadac0f2791ad23db92e4c8e53"; - string sigining_hash = "0x" + SequenceCoder.KeccakHash(expected_signing_data); + string sigining_hash = "0x" + SequenceCoder.KeccakHash(expected_signing_data); CollectionAssert.AreEqual(expected_signing_hash, sigining_hash); //the use of 37 instead of 27. The signed tx would become: - string expected_signed_transaction = "0xf86c098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a76400008025a028ef61340bd939bc2195fe537567866003e1a15d3c71ff63e1590620aa636276a067cbe9d8997f761aecb703304b3800ccf555c9f3dc64214b297fb1966a3b6d83"; + string expected_signed_transaction = + "0xf86c098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a76400008025a028ef61340bd939bc2195fe537567866003e1a15d3c71ff63e1590620aa636276a067cbe9d8997f761aecb703304b3800ccf555c9f3dc64214b297fb1966a3b6d83"; EthWallet wallet = new EthWallet("0x4646464646464646464646464646464646464646464646464646464646464646"); - (string v, string r, string s) = wallet.SignTransaction(SequenceCoder.HexStringToByteArray(expected_signing_hash), "1"); + (string v, string r, string s) = + wallet.SignTransaction(SequenceCoder.HexStringToByteArray(expected_signing_hash), "1"); int id = "1".HexStringToInt(); int vInt = v.HexStringToInt(); Debug.Log(id); Debug.Log(vInt); - string encoded_signed_transaction = EthTransaction.RLPEncode(9, 20000000000, 21000, "0x3535353535353535353535353535353535353535", 1000000000000000000,"", "1", v,r, s); + string encoded_signed_transaction = EthTransaction.RLPEncode(9, 20000000000, 21000, + "0x3535353535353535353535353535353535353535", 1000000000000000000, "", "1", v, r, s); CollectionAssert.AreEqual(expected_signed_transaction, encoded_signed_transaction); } @@ -216,7 +230,7 @@ public void TestWalletRandom() { EthWallet wallet = new EthWallet(); Assert.NotNull(wallet); - + } [Test] @@ -234,18 +248,25 @@ public async Task TestWalletSignMessage() Assert.IsTrue(valid); } - [Test] - public async Task TestWalletSignMessageWithChainId() + private static IEnumerable iWalletTestCases() { - EthWallet wallet = new EthWallet(); + yield return new object[] { new EthWallet() }; + var adapter = WaaSToWalletAdapter.CreateAsync(new WaaSWallet( + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXJ0bmVyX2lkIjoyLCJ3YWxsZXQiOiIweDY2MDI1MDczNGYzMTY0NDY4MWFlMzJkMDViZDdlOGUyOWZlYTI5ZTEifQ.FC8WmaC_hW4svdrs4rxyKcvoekfVYFkFFvGwUOXzcHA")).Result; + yield return new object[] { adapter }; + } + + [TestCaseSource(nameof(iWalletTestCases))] + public async Task TestWalletSignMessageWithChainId(IWallet wallet) + { string address = wallet.GetAddress(); Assert.NotNull(address); - string sig = await wallet.SignMessage("hi", "1"); + string sig = await wallet.SignMessage("hi", "0x89"); Assert.NotNull(sig); - bool valid = await wallet.IsValidSignature(sig, "hi", chainId: "1"); + bool valid = await wallet.IsValidSignature(sig, "hi", chainId: "0x89"); Assert.IsTrue(valid); } diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/IsValidMessageSignatureArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/IsValidMessageSignatureArgs.cs index c8b56f12..ad86c252 100644 --- a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/IsValidMessageSignatureArgs.cs +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/IsValidMessageSignatureArgs.cs @@ -3,12 +3,12 @@ namespace Sequence.WaaS [System.Serializable] public class IsValidMessageSignatureArgs { - public string chainId; + public uint chainId; public string walletAddress; public string message; public string signature; - public IsValidMessageSignatureArgs(string chainId, string walletAddress, string message, string signature) + public IsValidMessageSignatureArgs(uint chainId, string walletAddress, string message, string signature) { this.chainId = chainId; this.walletAddress = walletAddress; diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SignMessageArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SignMessageArgs.cs index 48c34700..55a6f1f2 100644 --- a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SignMessageArgs.cs +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SignMessageArgs.cs @@ -1,16 +1,18 @@ +using UnityEngine.Serialization; + namespace Sequence.WaaS { [System.Serializable] public class SignMessageArgs { public uint chainId; - public string accountAddress; + public string walletAddress; public string message; - public SignMessageArgs(uint chainId, string accountAddress, string message) + public SignMessageArgs(uint chainId, string walletAddress, string message) { this.chainId = chainId; - this.accountAddress = accountAddress; + this.walletAddress = walletAddress; this.message = message; } } diff --git a/Assets/SequenceSDK/WaaS/HttpClient.cs b/Assets/SequenceSDK/WaaS/HttpClient.cs index 162225d9..a43f65d4 100644 --- a/Assets/SequenceSDK/WaaS/HttpClient.cs +++ b/Assets/SequenceSDK/WaaS/HttpClient.cs @@ -66,7 +66,6 @@ public async Task SendRequest(string path, T args, [CanBeNull] Dictio return result; } } - private string ExtractHeaders(UnityWebRequest request) { diff --git a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs index 8fc81702..fd2a2637 100644 --- a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs +++ b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs @@ -104,21 +104,14 @@ public async Task SignMessage(byte[] message, byte[] chainId) public async Task SignMessage(string message, string chainId) { - if (uint.TryParse(chainId, out uint chain)) - { - SignMessageArgs args = new SignMessageArgs(chain, GetAddress(), message); - var result = await _wallet.SignMessage(args); - return result.signature; - } - else - { - throw new ArgumentException($"{nameof(chainId)} must be parseable to an {typeof(uint)}, given: {chainId}"); - } + SignMessageArgs args = new SignMessageArgs((uint)chainId.HexStringToInt(), GetAddress(), message); + var result = await _wallet.SignMessage(args); + return result.signature; } public async Task IsValidSignature(string signature, string message, string chainId, uint accountIndex = 0) { - var args = new IsValidMessageSignatureArgs(chainId, GetAddress(accountIndex), message, signature); + var args = new IsValidMessageSignatureArgs((uint)chainId.HexStringToInt(), GetAddress(accountIndex), message, signature); var result = await _wallet.IsValidMessageSignature(args); return result.isValid; } From cdf2c1cd9d30830f4edc3d742d7abbf8aaf67f4c Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Fri, 18 Aug 2023 08:37:33 -0400 Subject: [PATCH 41/49] Additional signature tests --- Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs b/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs index 7681d1ca..c45d249a 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs @@ -250,23 +250,27 @@ public async Task TestWalletSignMessage() private static IEnumerable iWalletTestCases() { - yield return new object[] { new EthWallet() }; var adapter = WaaSToWalletAdapter.CreateAsync(new WaaSWallet( "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXJ0bmVyX2lkIjoyLCJ3YWxsZXQiOiIweDY2MDI1MDczNGYzMTY0NDY4MWFlMzJkMDViZDdlOGUyOWZlYTI5ZTEifQ.FC8WmaC_hW4svdrs4rxyKcvoekfVYFkFFvGwUOXzcHA")).Result; - yield return new object[] { adapter }; + yield return new object[] { new EthWallet(), "SDK by Horizon" }; + yield return new object[] { adapter, "SDK by Horizon" }; + yield return new object[] { new EthWallet(), "" }; + yield return new object[] { adapter, "" }; + yield return new object[] { new EthWallet(), DecodeABITests.longMultiLineString }; + yield return new object[] { adapter, DecodeABITests.longMultiLineString }; } [TestCaseSource(nameof(iWalletTestCases))] - public async Task TestWalletSignMessageWithChainId(IWallet wallet) + public async Task TestWalletSignMessageWithChainId(IWallet wallet, string message) { string address = wallet.GetAddress(); Assert.NotNull(address); - string sig = await wallet.SignMessage("hi", "0x89"); + string sig = await wallet.SignMessage(message, "0x89"); Assert.NotNull(sig); - bool valid = await wallet.IsValidSignature(sig, "hi", chainId: "0x89"); + bool valid = await wallet.IsValidSignature(sig, message, chainId: "0x89"); Assert.IsTrue(valid); } From 2f6408deca73f37ab4552ad846e7bee89b56081b Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Mon, 21 Aug 2023 11:23:26 -0400 Subject: [PATCH 42/49] Added test for contract interactions and deployment --- .../SequenceSDK/WaaS/Tests/EndToEndTests.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs b/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs index a924cd28..813024df 100644 --- a/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs +++ b/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs @@ -2,6 +2,7 @@ using System.Numerics; using System.Threading.Tasks; using NUnit.Framework; +using Sequence.Contracts; using Sequence.Provider; using Sequence.Transactions; using UnityEngine; @@ -89,5 +90,42 @@ public async Task TestBatchTransferOnTestnet_emptyBatch() Assert.AreEqual("Error sending request to https://next-api.sequence.app/rpc/Wallet/SendTransactionBatch: HTTP/1.1 500 Internal Server Error", ex.Message); } } + + [Test] + public async Task TestContractDeploymentAndInteractions() + { + Wallet.IWallet wallet = await WaaSToWalletAdapter.CreateAsync(new WaaSWallet( + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXJ0bmVyX2lkIjoyLCJ3YWxsZXQiOiIweDY2MDI1MDczNGYzMTY0NDY4MWFlMzJkMDViZDdlOGUyOWZlYTI5ZTEifQ.FC8WmaC_hW4svdrs4rxyKcvoekfVYFkFFvGwUOXzcHA")); + IEthClient client = new SequenceEthClient("https://polygon-mumbai-bor.publicnode.com"); + + BigInteger amount = 100; + + try + { + TransactionReceipt receipt = await ContractDeployer.Deploy(client, wallet, ERC20Tests.bytecode); + string contractAddress = receipt.contractAddress; + Assert.IsNotEmpty(contractAddress); + + ERC20 token = new ERC20(contractAddress); + + BigInteger balance = await token.BalanceOf(client, wallet.GetAddress()); + Assert.AreEqual(BigInteger.Zero, balance); + + string owner = await token.Owner(client); + Assert.AreEqual(wallet.GetAddress().Value, owner); + + receipt = await token.Mint(wallet.GetAddress(), amount) + .SendTransactionMethodAndWaitForReceipt(wallet, client); + + BigInteger supply = await token.TotalSupply(client); + Assert.AreEqual(amount, supply); + BigInteger balance1 = await token.BalanceOf(client, wallet.GetAddress()); + Assert.AreEqual(amount, balance1); + } + catch (Exception ex) + { + Assert.Fail("Expected no exception, but got: " + ex.Message); + } + } } } \ No newline at end of file From 7ae7cde21ab49050766311c61e9af4efcada9588 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Mon, 21 Aug 2023 13:41:43 -0400 Subject: [PATCH 43/49] Don't include nonce when sending WaaS transactions as Marcin recommended --- Assets/SequenceSDK/WaaS/HttpClient.cs | 11 ++++++++++- Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Assets/SequenceSDK/WaaS/HttpClient.cs b/Assets/SequenceSDK/WaaS/HttpClient.cs index a43f65d4..92cdc9b4 100644 --- a/Assets/SequenceSDK/WaaS/HttpClient.cs +++ b/Assets/SequenceSDK/WaaS/HttpClient.cs @@ -14,6 +14,10 @@ public class HttpClient { private readonly string _url = "https://next-api.sequence.app/rpc/Wallet"; private Dictionary _defaultHeaders; + private JsonSerializerSettings serializerSettings = new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Ignore + }; public HttpClient() { @@ -28,7 +32,7 @@ public void AddDefaultHeader(string key, string value) public async Task SendRequest(string path, T args, [CanBeNull] Dictionary headers = null) { string url = _url + "/" + path; - string requestJson = JsonConvert.SerializeObject(args); + string requestJson = JsonConvert.SerializeObject(args, serializerSettings); UnityWebRequest request = UnityWebRequest.Get(url); request.SetRequestHeader("Content-Type", "application/json"); request.SetRequestHeader("Accept", "application/json"); @@ -46,6 +50,11 @@ public async Task SendRequest(string path, T args, [CanBeNull] Dictio { request.SetRequestHeader(key, headers[key]); } + + string method = request.method; + string headersString = ExtractHeaders(request); + string curlCommand = $"curl -X {method} '{url}' {headersString} -d '{requestJson}'"; + Debug.Log("Equivalent curl command: " + curlCommand); request.SendWebRequest(); while (!request.isDone) diff --git a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs index fd2a2637..a000bd48 100644 --- a/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs +++ b/Assets/SequenceSDK/WaaS/WaaSToWalletAdapter.cs @@ -53,7 +53,7 @@ public Address GetAddress(uint accountIndex = 0) public async Task SendTransaction(IEthClient client, EthTransaction transaction) { - Transaction waasTransaction = new Transaction((uint)transaction.ChainId.HexStringToInt(), GetAddress(), transaction.To, null, transaction.Nonce, transaction.Value.ToString(), transaction.Data); + Transaction waasTransaction = new Transaction((uint)transaction.ChainId.HexStringToInt(), GetAddress(), transaction.To, null, null, transaction.Value.ToString(), transaction.Data); SendTransactionArgs args = new SendTransactionArgs(waasTransaction); SendTransactionReturn result = await _wallet.SendTransaction(args); return result.txHash; @@ -72,7 +72,7 @@ public async Task SendTransactionBatch(IEthClient client, EthTransacti Transaction[] waasTransactions = new Transaction[transactionCount]; for (int i = 0; i < transactionCount; i++) { - waasTransactions[i] = new Transaction((uint)transactions[i].ChainId.HexStringToInt(), GetAddress(), transactions[i].To, null, transactions[i].Nonce, transactions[i].Value.ToString(), transactions[i].Data); + waasTransactions[i] = new Transaction((uint)transactions[i].ChainId.HexStringToInt(), GetAddress(), transactions[i].To, null, null, transactions[i].Value.ToString(), transactions[i].Data); } SendTransactionBatchArgs args = new SendTransactionBatchArgs(waasTransactions); From c5f59e01ed9270653b74799cdf3b9d054684cac9 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Tue, 22 Aug 2023 16:13:27 -0400 Subject: [PATCH 44/49] Use 0x0000000000000000000000000000000000000000 as the zero address for WaaS as it errors on 0x0 (which is usually expected). Pre-calculate contract deployment address - WaaS transaction receipts don't expose this. --- .../SequenceSDK/Ethereum/ABI/SequenceCoder.cs | 1 - .../Ethereum/Contract/ContractDeployer.cs | 38 +++++++++++++++++-- .../Ethereum/Tests/ContractDeployerTests.cs | 18 +++++++++ .../Tests/ContractDeployerTests.cs.meta | 3 ++ .../Ethereum/Tests/ERC1155Tests.cs | 4 +- .../SequenceSDK/Ethereum/Tests/ERC20Tests.cs | 4 +- .../SequenceSDK/Ethereum/Tests/ERC721Tests.cs | 8 +++- .../Ethereum/Tests/OwnableTests.cs | 4 +- .../Ethereum/Tests/SequenceEthClientTests.cs | 3 +- .../SequenceSDK/Ethereum/Tests/WalletTests.cs | 8 +++- .../SequenceSDK/WaaS/DataTypes/Transaction.cs | 6 +++ .../SequenceSDK/WaaS/Tests/EndToEndTests.cs | 8 ++-- 12 files changed, 88 insertions(+), 17 deletions(-) create mode 100644 Assets/SequenceSDK/Ethereum/Tests/ContractDeployerTests.cs create mode 100644 Assets/SequenceSDK/Ethereum/Tests/ContractDeployerTests.cs.meta diff --git a/Assets/SequenceSDK/Ethereum/ABI/SequenceCoder.cs b/Assets/SequenceSDK/Ethereum/ABI/SequenceCoder.cs index 4831082a..b8e50761 100644 --- a/Assets/SequenceSDK/Ethereum/ABI/SequenceCoder.cs +++ b/Assets/SequenceSDK/Ethereum/ABI/SequenceCoder.cs @@ -1,6 +1,5 @@ using System; using System.Text; -using System.Text.RegularExpressions; using Org.BouncyCastle.Crypto.Digests; using UnityEngine; using Sequence; diff --git a/Assets/SequenceSDK/Ethereum/Contract/ContractDeployer.cs b/Assets/SequenceSDK/Ethereum/Contract/ContractDeployer.cs index 5cbcc2f9..f489092c 100644 --- a/Assets/SequenceSDK/Ethereum/Contract/ContractDeployer.cs +++ b/Assets/SequenceSDK/Ethereum/Contract/ContractDeployer.cs @@ -1,7 +1,7 @@ -using System.Collections; using System.Collections.Generic; using System.Numerics; using System.Threading.Tasks; +using Sequence.ABI; using Sequence.Provider; using Sequence.Wallet; using UnityEngine; @@ -12,7 +12,7 @@ namespace Sequence.Contracts { public static class ContractDeployer { - public static async Task Deploy( + public static async Task Deploy( IEthClient client, IWallet wallet, string bytecode, @@ -20,8 +20,38 @@ public static async Task Deploy( BigInteger? gasLimit = null) { EthTransaction deployTransaction = await new GasLimitEstimator(client, wallet.GetAddress()).BuildTransaction(StringExtensions.ZeroAddress, bytecode, 0, gasPrice, gasLimit); - TransactionReceipt receipt = await wallet.SendTransactionAndWaitForReceipt(client, deployTransaction); - return receipt; + string preCalculatedContractAddress = CalculateContractAddress(deployTransaction.Nonce, wallet.GetAddress()); + string transactionHash = await wallet.SendTransaction(client, deployTransaction); + TransactionReceipt receipt = await client.WaitForTransactionReceipt(transactionHash); + return new ContractDeploymentResult(transactionHash, preCalculatedContractAddress, receipt); + } + + public static string CalculateContractAddress(BigInteger nonce, string senderAddress) + { + byte[] addressBytes = SequenceCoder.HexStringToByteArray(senderAddress); + byte[] nonceBytes = nonce.ToByteArray(true, true); + List toEncode = new List(); + toEncode.Add(addressBytes); + toEncode.Add(nonceBytes); + byte[] encoded = RLP.RLP.Encode(toEncode); + byte[] hashed = SequenceCoder.KeccakHash(encoded); + string hashedString = SequenceCoder.ByteArrayToHexString(hashed).EnsureHexPrefix(); + return hashedString.Substring(hashedString.Length - 40, 40).EnsureHexPrefix(); + } + } + + public class ContractDeploymentResult + { + public string TransactionHash; + public string PreCalculatedContractAddress; + public TransactionReceipt Receipt; + + public ContractDeploymentResult(string transactionHash, string preCalculatedContractAddress, + TransactionReceipt receipt) + { + this.TransactionHash = transactionHash; + this.PreCalculatedContractAddress = preCalculatedContractAddress; + this.Receipt = receipt; } } } diff --git a/Assets/SequenceSDK/Ethereum/Tests/ContractDeployerTests.cs b/Assets/SequenceSDK/Ethereum/Tests/ContractDeployerTests.cs new file mode 100644 index 00000000..6f66bbd8 --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/ContractDeployerTests.cs @@ -0,0 +1,18 @@ +using System.Numerics; +using NUnit.Framework; +using Sequence.Contracts; +using UnityEditor.VersionControl; + +public class ContractDeployerTests +{ + // Test cases from https://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed + [TestCase(0, "0x6ac7ea33f8831ea9dcc53393aaa88b25a785dbf0", "0xcd234a471b72ba2f1ccf0a70fcaba648a5eecd8d")] + [TestCase(1, "0x6ac7ea33f8831ea9dcc53393aaa88b25a785dbf0", "0x343c43a37d37dff08ae8c4a11544c718abb4fcf8")] + [TestCase(2, "0x6ac7ea33f8831ea9dcc53393aaa88b25a785dbf0", "0xf778b86fa74e846c4f0a1fbd1335fe81c00a0c91")] + [TestCase(3, "0x6ac7ea33f8831ea9dcc53393aaa88b25a785dbf0", "0xfffd933a0bc612844eaf0c6fe3e5b8e9b6c1d19c")] + public void TestCalculateContractAddress(int nonce, string deployerAddress, string expected) + { + string result = ContractDeployer.CalculateContractAddress(nonce, deployerAddress); + Assert.AreEqual(expected, result); + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/Ethereum/Tests/ContractDeployerTests.cs.meta b/Assets/SequenceSDK/Ethereum/Tests/ContractDeployerTests.cs.meta new file mode 100644 index 00000000..092f2e8b --- /dev/null +++ b/Assets/SequenceSDK/Ethereum/Tests/ContractDeployerTests.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7db0950ef45c4942bbe03e17c9220f1a +timeCreated: 1692732752 \ No newline at end of file diff --git a/Assets/SequenceSDK/Ethereum/Tests/ERC1155Tests.cs b/Assets/SequenceSDK/Ethereum/Tests/ERC1155Tests.cs index ff266078..8cc247a7 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/ERC1155Tests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/ERC1155Tests.cs @@ -39,9 +39,11 @@ public async Task _TestDeployERC1155Contract() { try { - TransactionReceipt receipt = await ContractDeployer.Deploy(client, wallet1, bytecode); + ContractDeploymentResult result = await ContractDeployer.Deploy(client, wallet1, bytecode); + TransactionReceipt receipt = result.Receipt; contractAddress = receipt.contractAddress; Assert.IsNotEmpty(contractAddress); + Assert.AreEqual(contractAddress, result.PreCalculatedContractAddress); } catch (Exception ex) { diff --git a/Assets/SequenceSDK/Ethereum/Tests/ERC20Tests.cs b/Assets/SequenceSDK/Ethereum/Tests/ERC20Tests.cs index 1f11d91e..bb13e741 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/ERC20Tests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/ERC20Tests.cs @@ -29,9 +29,11 @@ public async Task _TestDeployERC20Contract() { try { - TransactionReceipt receipt = await ContractDeployer.Deploy(client, wallet1, bytecode); + ContractDeploymentResult result = await ContractDeployer.Deploy(client, wallet1, bytecode); + TransactionReceipt receipt = result.Receipt; contractAddress = receipt.contractAddress; Assert.IsNotEmpty(contractAddress); + Assert.AreEqual(contractAddress, result.PreCalculatedContractAddress); } catch (Exception ex) { diff --git a/Assets/SequenceSDK/Ethereum/Tests/ERC721Tests.cs b/Assets/SequenceSDK/Ethereum/Tests/ERC721Tests.cs index 5e28c342..17ba06db 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/ERC721Tests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/ERC721Tests.cs @@ -35,9 +35,11 @@ public async Task _TestDeployERC721Contract() { try { - TransactionReceipt receipt = await ContractDeployer.Deploy(client, wallet1, bytecode); + ContractDeploymentResult result = await ContractDeployer.Deploy(client, wallet1, bytecode); + TransactionReceipt receipt = result.Receipt; contractAddress = receipt.contractAddress; Assert.IsNotEmpty(contractAddress); + Assert.AreEqual(contractAddress, result.PreCalculatedContractAddress); } catch (Exception ex) { @@ -79,9 +81,11 @@ public async Task TestERC721Mint() try { // Deploy an autoincrementing NFT contract so we can test the other mint function - TransactionReceipt receipt = await ContractDeployer.Deploy(client, wallet1, autoIncrementingIdVersionBytecode); + ContractDeploymentResult result = await ContractDeployer.Deploy(client, wallet1, autoIncrementingIdVersionBytecode); + TransactionReceipt receipt = result.Receipt; string autoIncrementingContractAddress = receipt.contractAddress; Assert.IsNotEmpty(autoIncrementingContractAddress); + Assert.AreEqual(autoIncrementingContractAddress, result.PreCalculatedContractAddress); ERC721 autoIncrementingToken = new ERC721(autoIncrementingContractAddress, autoIncrementingAbi); // Mint an auto incrementing token to random address so that index starts at one like with the other contract diff --git a/Assets/SequenceSDK/Ethereum/Tests/OwnableTests.cs b/Assets/SequenceSDK/Ethereum/Tests/OwnableTests.cs index 0e699adf..9ffcca51 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/OwnableTests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/OwnableTests.cs @@ -29,9 +29,11 @@ public async Task _TestDeployOwnableContract() { try { - TransactionReceipt receipt = await ContractDeployer.Deploy(client, wallet1, bytecode); + ContractDeploymentResult result = await ContractDeployer.Deploy(client, wallet1, bytecode); + TransactionReceipt receipt = result.Receipt; contractAddress = receipt.contractAddress; Assert.IsNotEmpty(contractAddress); + Assert.AreEqual(contractAddress, result.PreCalculatedContractAddress); } catch (Exception ex) { diff --git a/Assets/SequenceSDK/Ethereum/Tests/SequenceEthClientTests.cs b/Assets/SequenceSDK/Ethereum/Tests/SequenceEthClientTests.cs index 356bb30e..ff08fa3d 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/SequenceEthClientTests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/SequenceEthClientTests.cs @@ -156,7 +156,8 @@ public async Task TestCodeAt() { var client = new SequenceEthClient(testnetUrl); var bytecode = ERC20Tests.bytecode; - TransactionReceipt receipt = await ContractDeployer.Deploy(client, wallet1, bytecode); + ContractDeploymentResult result = await ContractDeployer.Deploy(client, wallet1, bytecode); + TransactionReceipt receipt = result.Receipt; var contractAddress = receipt.contractAddress; // expectedDeployedCode is the deployedBytecode from the compiled test ERC20 smart contract var expectedDeployedCode = "0x608060405234801561001057600080fd5b506004361061010b5760003560e01c806370a08231116100a257806395d89b411161007157806395d89b41146102a6578063a457c2d7146102c4578063a9059cbb146102f4578063dd62ed3e14610324578063f2fde38b146103545761010b565b806370a0823114610232578063715018a61461026257806379cc67901461026c5780638da5cb5b146102885761010b565b8063313ce567116100de578063313ce567146101ac57806339509351146101ca57806340c10f19146101fa57806342966c68146102165761010b565b806306fdde0314610110578063095ea7b31461012e57806318160ddd1461015e57806323b872dd1461017c575b600080fd5b610118610370565b6040516101259190611178565b60405180910390f35b61014860048036038101906101439190611233565b610402565b604051610155919061128e565b60405180910390f35b610166610425565b60405161017391906112b8565b60405180910390f35b610196600480360381019061019191906112d3565b61042f565b6040516101a3919061128e565b60405180910390f35b6101b461045e565b6040516101c19190611342565b60405180910390f35b6101e460048036038101906101df9190611233565b610467565b6040516101f1919061128e565b60405180910390f35b610214600480360381019061020f9190611233565b61049e565b005b610230600480360381019061022b919061135d565b6104b4565b005b61024c6004803603810190610247919061138a565b6104c8565b60405161025991906112b8565b60405180910390f35b61026a610510565b005b61028660048036038101906102819190611233565b610524565b005b610290610544565b60405161029d91906113c6565b60405180910390f35b6102ae61056e565b6040516102bb9190611178565b60405180910390f35b6102de60048036038101906102d99190611233565b610600565b6040516102eb919061128e565b60405180910390f35b61030e60048036038101906103099190611233565b610677565b60405161031b919061128e565b60405180910390f35b61033e600480360381019061033991906113e1565b61069a565b60405161034b91906112b8565b60405180910390f35b61036e6004803603810190610369919061138a565b610721565b005b60606003805461037f90611450565b80601f01602080910402602001604051908101604052809291908181526020018280546103ab90611450565b80156103f85780601f106103cd576101008083540402835291602001916103f8565b820191906000526020600020905b8154815290600101906020018083116103db57829003601f168201915b5050505050905090565b60008061040d6107a4565b905061041a8185856107ac565b600191505092915050565b6000600254905090565b60008061043a6107a4565b9050610447858285610975565b610452858585610a01565b60019150509392505050565b60006012905090565b6000806104726107a4565b9050610493818585610484858961069a565b61048e91906114b0565b6107ac565b600191505092915050565b6104a6610c77565b6104b08282610cf5565b5050565b6104c56104bf6107a4565b82610e4b565b50565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b610518610c77565b6105226000611018565b565b610536826105306107a4565b83610975565b6105408282610e4b565b5050565b6000600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60606004805461057d90611450565b80601f01602080910402602001604051908101604052809291908181526020018280546105a990611450565b80156105f65780601f106105cb576101008083540402835291602001916105f6565b820191906000526020600020905b8154815290600101906020018083116105d957829003601f168201915b5050505050905090565b60008061060b6107a4565b90506000610619828661069a565b90508381101561065e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161065590611556565b60405180910390fd5b61066b82868684036107ac565b60019250505092915050565b6000806106826107a4565b905061068f818585610a01565b600191505092915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b610729610c77565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610798576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161078f906115e8565b60405180910390fd5b6107a181611018565b50565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff160361081b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108129061167a565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff160361088a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108819061170c565b60405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258360405161096891906112b8565b60405180910390a3505050565b6000610981848461069a565b90507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81146109fb57818110156109ed576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109e490611778565b60405180910390fd5b6109fa84848484036107ac565b5b50505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1603610a70576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a679061180a565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610adf576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ad69061189c565b60405180910390fd5b610aea8383836110de565b60008060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015610b70576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b679061192e565b60405180910390fd5b8181036000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610c5e91906112b8565b60405180910390a3610c718484846110e3565b50505050565b610c7f6107a4565b73ffffffffffffffffffffffffffffffffffffffff16610c9d610544565b73ffffffffffffffffffffffffffffffffffffffff1614610cf3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610cea9061199a565b60405180910390fd5b565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610d64576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d5b90611a06565b60405180910390fd5b610d70600083836110de565b8060026000828254610d8291906114b0565b92505081905550806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef83604051610e3391906112b8565b60405180910390a3610e47600083836110e3565b5050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610eba576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610eb190611a98565b60405180910390fd5b610ec6826000836110de565b60008060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015610f4c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f4390611b2a565b60405180910390fd5b8181036000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555081600260008282540392505081905550600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610fff91906112b8565b60405180910390a3611013836000846110e3565b505050565b6000600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b505050565b505050565b600081519050919050565b600082825260208201905092915050565b60005b83811015611122578082015181840152602081019050611107565b60008484015250505050565b6000601f19601f8301169050919050565b600061114a826110e8565b61115481856110f3565b9350611164818560208601611104565b61116d8161112e565b840191505092915050565b60006020820190508181036000830152611192818461113f565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006111ca8261119f565b9050919050565b6111da816111bf565b81146111e557600080fd5b50565b6000813590506111f7816111d1565b92915050565b6000819050919050565b611210816111fd565b811461121b57600080fd5b50565b60008135905061122d81611207565b92915050565b6000806040838503121561124a5761124961119a565b5b6000611258858286016111e8565b92505060206112698582860161121e565b9150509250929050565b60008115159050919050565b61128881611273565b82525050565b60006020820190506112a3600083018461127f565b92915050565b6112b2816111fd565b82525050565b60006020820190506112cd60008301846112a9565b92915050565b6000806000606084860312156112ec576112eb61119a565b5b60006112fa868287016111e8565b935050602061130b868287016111e8565b925050604061131c8682870161121e565b9150509250925092565b600060ff82169050919050565b61133c81611326565b82525050565b60006020820190506113576000830184611333565b92915050565b6000602082840312156113735761137261119a565b5b60006113818482850161121e565b91505092915050565b6000602082840312156113a05761139f61119a565b5b60006113ae848285016111e8565b91505092915050565b6113c0816111bf565b82525050565b60006020820190506113db60008301846113b7565b92915050565b600080604083850312156113f8576113f761119a565b5b6000611406858286016111e8565b9250506020611417858286016111e8565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061146857607f821691505b60208210810361147b5761147a611421565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006114bb826111fd565b91506114c6836111fd565b92508282019050808211156114de576114dd611481565b5b92915050565b7f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760008201527f207a65726f000000000000000000000000000000000000000000000000000000602082015250565b60006115406025836110f3565b915061154b826114e4565b604082019050919050565b6000602082019050818103600083015261156f81611533565b9050919050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b60006115d26026836110f3565b91506115dd82611576565b604082019050919050565b60006020820190508181036000830152611601816115c5565b9050919050565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b60006116646024836110f3565b915061166f82611608565b604082019050919050565b6000602082019050818103600083015261169381611657565b9050919050565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b60006116f66022836110f3565b91506117018261169a565b604082019050919050565b60006020820190508181036000830152611725816116e9565b9050919050565b7f45524332303a20696e73756666696369656e7420616c6c6f77616e6365000000600082015250565b6000611762601d836110f3565b915061176d8261172c565b602082019050919050565b6000602082019050818103600083015261179181611755565b9050919050565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b60006117f46025836110f3565b91506117ff82611798565b604082019050919050565b60006020820190508181036000830152611823816117e7565b9050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b60006118866023836110f3565b91506118918261182a565b604082019050919050565b600060208201905081810360008301526118b581611879565b9050919050565b7f45524332303a207472616e7366657220616d6f756e742065786365656473206260008201527f616c616e63650000000000000000000000000000000000000000000000000000602082015250565b60006119186026836110f3565b9150611923826118bc565b604082019050919050565b600060208201905081810360008301526119478161190b565b9050919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b60006119846020836110f3565b915061198f8261194e565b602082019050919050565b600060208201905081810360008301526119b381611977565b9050919050565b7f45524332303a206d696e7420746f20746865207a65726f206164647265737300600082015250565b60006119f0601f836110f3565b91506119fb826119ba565b602082019050919050565b60006020820190508181036000830152611a1f816119e3565b9050919050565b7f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360008201527f7300000000000000000000000000000000000000000000000000000000000000602082015250565b6000611a826021836110f3565b9150611a8d82611a26565b604082019050919050565b60006020820190508181036000830152611ab181611a75565b9050919050565b7f45524332303a206275726e20616d6f756e7420657863656564732062616c616e60008201527f6365000000000000000000000000000000000000000000000000000000000000602082015250565b6000611b146022836110f3565b9150611b1f82611ab8565b604082019050919050565b60006020820190508181036000830152611b4381611b07565b905091905056fea26469706673582212204f5863a5c182fce47d84abd8a2c644c72bf23a527680e14ec57349d38f1cd1a564736f6c63430008110033"; diff --git a/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs b/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs index c45d249a..9c23240c 100644 --- a/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs +++ b/Assets/SequenceSDK/Ethereum/Tests/WalletTests.cs @@ -139,10 +139,12 @@ public async Task TestChain_DeployERC20Mock_Tests() { SequenceEthClient client = new SequenceEthClient("http://localhost:8545/"); EthWallet wallet = new EthWallet("0xabc0000000000000000000000000000000000000000000000000000000000001"); - TransactionReceipt receipt = await ContractDeployer.Deploy(client, wallet, bytecode_ERC20Mock, + ContractDeploymentResult result = await ContractDeployer.Deploy(client, wallet, bytecode_ERC20Mock, gasPrice_ERC20Mock, gasLimit_ERC20Mock); + TransactionReceipt receipt = result.Receipt; Assert.IsNotNull(receipt.contractAddress); + Assert.AreEqual(receipt.contractAddress, result.PreCalculatedContractAddress); } catch (Exception ex) { @@ -159,10 +161,12 @@ public async Task TestChain_ERC20Mock_MockMint_Test() //Deploy First SequenceEthClient client = new SequenceEthClient("http://localhost:8545/"); EthWallet wallet = new EthWallet("0xabc0000000000000000000000000000000000000000000000000000000000001"); - TransactionReceipt receipt = await ContractDeployer.Deploy(client, wallet, bytecode_ERC20Mock, + ContractDeploymentResult deployResult = await ContractDeployer.Deploy(client, wallet, bytecode_ERC20Mock, gasPrice_ERC20Mock, gasLimit_ERC20Mock); + TransactionReceipt receipt = deployResult.Receipt; Assert.IsNotNull(receipt.contractAddress); + Assert.AreEqual(receipt.contractAddress, deployResult.PreCalculatedContractAddress); //Interaction (mock mint) diff --git a/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs b/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs index 3d9bf32d..43c1e96b 100644 --- a/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs +++ b/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs @@ -4,12 +4,14 @@ using System.Numerics; using Sequence.Transactions; using UnityEngine; +using StringExtensions = Sequence.Utils.StringExtensions; namespace Sequence.WaaS { [System.Serializable] public class Transaction { + public static readonly string WaaSZeroAddress = "0x0000000000000000000000000000000000000000"; public uint chainId; public string from; public string to; @@ -26,6 +28,10 @@ public Transaction(uint chainId, string from, string to, string autoGas = null, { this.chainId = chainId; this.from = from; + if (to == StringExtensions.ZeroAddress) + { + to = WaaSZeroAddress; + } this.to = to; this.autoGas = autoGas; this.nonce = nonce; diff --git a/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs b/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs index 813024df..d371a5ab 100644 --- a/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs +++ b/Assets/SequenceSDK/WaaS/Tests/EndToEndTests.cs @@ -90,7 +90,7 @@ public async Task TestBatchTransferOnTestnet_emptyBatch() Assert.AreEqual("Error sending request to https://next-api.sequence.app/rpc/Wallet/SendTransactionBatch: HTTP/1.1 500 Internal Server Error", ex.Message); } } - + [Test] public async Task TestContractDeploymentAndInteractions() { @@ -102,9 +102,9 @@ public async Task TestContractDeploymentAndInteractions() try { - TransactionReceipt receipt = await ContractDeployer.Deploy(client, wallet, ERC20Tests.bytecode); - string contractAddress = receipt.contractAddress; - Assert.IsNotEmpty(contractAddress); + ContractDeploymentResult result = await ContractDeployer.Deploy(client, wallet, ERC20Tests.bytecode); + TransactionReceipt receipt = result.Receipt; + string contractAddress = result.PreCalculatedContractAddress; ERC20 token = new ERC20(contractAddress); From 867ecabb7e71d24e767599ecd1bf6c03982408a2 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Thu, 7 Sep 2023 16:49:17 -0400 Subject: [PATCH 45/49] Added additional debug.log --- Assets/SequenceSDK/Ethereum/Contract/ContractDeployer.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Assets/SequenceSDK/Ethereum/Contract/ContractDeployer.cs b/Assets/SequenceSDK/Ethereum/Contract/ContractDeployer.cs index f489092c..ea8e5bb8 100644 --- a/Assets/SequenceSDK/Ethereum/Contract/ContractDeployer.cs +++ b/Assets/SequenceSDK/Ethereum/Contract/ContractDeployer.cs @@ -36,7 +36,9 @@ public static string CalculateContractAddress(BigInteger nonce, string senderAdd byte[] encoded = RLP.RLP.Encode(toEncode); byte[] hashed = SequenceCoder.KeccakHash(encoded); string hashedString = SequenceCoder.ByteArrayToHexString(hashed).EnsureHexPrefix(); - return hashedString.Substring(hashedString.Length - 40, 40).EnsureHexPrefix(); + string address = hashedString.Substring(hashedString.Length - 40, 40).EnsureHexPrefix(); + Debug.Log($"Deployer {senderAddress}, nonce {nonce} - deployed to {address}"); + return address; } } From f4a6671699754db72d3d36145b71c29ba773619e Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Mon, 18 Dec 2023 10:19:21 -0500 Subject: [PATCH 46/49] Remove extra semicolon --- Assets/SequenceSDK/Core/Signature/Digest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/SequenceSDK/Core/Signature/Digest.cs b/Assets/SequenceSDK/Core/Signature/Digest.cs index 758a9da3..602409ef 100644 --- a/Assets/SequenceSDK/Core/Signature/Digest.cs +++ b/Assets/SequenceSDK/Core/Signature/Digest.cs @@ -38,7 +38,7 @@ public static Digest NewDigest(params string[] messages) return (new ImageHash() { Hash = new Hash(hashBytes), - }, null);; + }, null); } // Subdigest derives the hash to be signed by the Sequence wallet's signers to validate the digest. From d8c4a7fc587007bb248a645c9489eb3f759618c2 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Mon, 18 Dec 2023 10:21:09 -0500 Subject: [PATCH 47/49] Create SignMessageArgs with Chain --- .../WaaS/DataTypes/ParameterTypes/SignMessageArgs.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SignMessageArgs.cs b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SignMessageArgs.cs index 55a6f1f2..7692b08e 100644 --- a/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SignMessageArgs.cs +++ b/Assets/SequenceSDK/WaaS/DataTypes/ParameterTypes/SignMessageArgs.cs @@ -15,5 +15,12 @@ public SignMessageArgs(uint chainId, string walletAddress, string message) this.walletAddress = walletAddress; this.message = message; } + + public SignMessageArgs(Chain chainId, string walletAddress, string message) + { + this.chainId = (uint)chainId; + this.walletAddress = walletAddress; + this.message = message; + } } } \ No newline at end of file From 16f485fae650a1e19cab3339b2de05475e5d050c Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Mon, 18 Dec 2023 10:22:07 -0500 Subject: [PATCH 48/49] Create Transaction with Chain --- .../SequenceSDK/WaaS/DataTypes/Transaction.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs b/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs index 43c1e96b..f5f37646 100644 --- a/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs +++ b/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs @@ -42,5 +42,24 @@ public Transaction(uint chainId, string from, string to, string autoGas = null, this.tokenIds = tokenIds; this.tokenAmounts = tokenAmounts; } + + public Transaction(Chain chainId, string from, string to, string autoGas = null, BigInteger? nonce = null, string value = null, string calldata = null, string tokenAddress = null, string tokenAmount = null, string[] tokenIds = null, string[] tokenAmounts = null) + { + this.chainId = (uint)chainId; + this.from = from; + if (to == StringExtensions.ZeroAddress) + { + to = WaaSZeroAddress; + } + this.to = to; + this.autoGas = autoGas; + this.nonce = nonce; + this.value = value; + this.calldata = calldata; + this.tokenAddress = tokenAddress; + this.tokenAmount = tokenAmount; + this.tokenIds = tokenIds; + this.tokenAmounts = tokenAmounts; + } } } From 7a1682322fc8f2cccf550f2a33fbe2982cdd5713 Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Mon, 18 Dec 2023 10:49:13 -0500 Subject: [PATCH 49/49] Rename vairable in constructor to make it more reader friendly --- .../SequenceSDK/WaaS/DataTypes/Transaction.cs | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs b/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs index f5f37646..c2171ce2 100644 --- a/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs +++ b/Assets/SequenceSDK/WaaS/DataTypes/Transaction.cs @@ -4,6 +4,7 @@ using System.Numerics; using Sequence.Transactions; using UnityEngine; +using UnityEngine.Serialization; using StringExtensions = Sequence.Utils.StringExtensions; namespace Sequence.WaaS @@ -13,8 +14,8 @@ public class Transaction { public static readonly string WaaSZeroAddress = "0x0000000000000000000000000000000000000000"; public uint chainId; - public string from; - public string to; + [FormerlySerializedAs("from")] public string fromAddress; + [FormerlySerializedAs("to")] public string toAddress; public string autoGas; public BigInteger? nonce; public string value; @@ -24,15 +25,15 @@ public class Transaction public string[] tokenIds; public string[] tokenAmounts; - public Transaction(uint chainId, string from, string to, string autoGas = null, BigInteger? nonce = null, string value = null, string calldata = null, string tokenAddress = null, string tokenAmount = null, string[] tokenIds = null, string[] tokenAmounts = null) + public Transaction(uint chainId, string fromAddress, string toAddress, string autoGas = null, BigInteger? nonce = null, string value = null, string calldata = null, string tokenAddress = null, string tokenAmount = null, string[] tokenIds = null, string[] tokenAmounts = null) { this.chainId = chainId; - this.from = from; - if (to == StringExtensions.ZeroAddress) + this.fromAddress = fromAddress; + if (toAddress == StringExtensions.ZeroAddress) { - to = WaaSZeroAddress; + toAddress = WaaSZeroAddress; } - this.to = to; + this.toAddress = toAddress; this.autoGas = autoGas; this.nonce = nonce; this.value = value; @@ -43,15 +44,15 @@ public Transaction(uint chainId, string from, string to, string autoGas = null, this.tokenAmounts = tokenAmounts; } - public Transaction(Chain chainId, string from, string to, string autoGas = null, BigInteger? nonce = null, string value = null, string calldata = null, string tokenAddress = null, string tokenAmount = null, string[] tokenIds = null, string[] tokenAmounts = null) + public Transaction(Chain chainId, string fromAddress, string toAddress, string autoGas = null, BigInteger? nonce = null, string value = null, string calldata = null, string tokenAddress = null, string tokenAmount = null, string[] tokenIds = null, string[] tokenAmounts = null) { this.chainId = (uint)chainId; - this.from = from; - if (to == StringExtensions.ZeroAddress) + this.fromAddress = fromAddress; + if (toAddress == StringExtensions.ZeroAddress) { - to = WaaSZeroAddress; + toAddress = WaaSZeroAddress; } - this.to = to; + this.toAddress = toAddress; this.autoGas = autoGas; this.nonce = nonce; this.value = value;